From 615108ab570c6f60269b321d828c69382b881c0e Mon Sep 17 00:00:00 2001 From: "Robert B. Young" Date: Tue, 3 Mar 2026 11:24:50 +1030 Subject: [PATCH 1/2] Fix divide-by-zero in aromaticity index calculation --- corems/molecular_formula/calc/MolecularFormulaCalc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/corems/molecular_formula/calc/MolecularFormulaCalc.py b/corems/molecular_formula/calc/MolecularFormulaCalc.py index a1de8c71..471f89ba 100644 --- a/corems/molecular_formula/calc/MolecularFormulaCalc.py +++ b/corems/molecular_formula/calc/MolecularFormulaCalc.py @@ -560,7 +560,7 @@ def _calc_aromaticity_index_mod(self): ) ai_d = ai_es["C"] - (0.5 * ai_es["O"]) - ai_es["N"] - ai_es["S"] - ai = ai_n / ai_d + ai = ai_n / ai_d if ai_d != 0 else 0 if ai < 0: ai = 0 @@ -601,7 +601,7 @@ def _calc_aromaticity_index(self): ) ai_d = ai_es["C"] - (ai_es["O"]) - ai_es["N"] - ai_es["S"] - ai = ai_n / ai_d + ai = ai_n / ai_d if ai_d != 0 else 0 if ai < 0: ai = 0 From ecca748b9d13b077987596ba4fc76bd8d9e06dd3 Mon Sep 17 00:00:00 2001 From: "Robert B. Young" Date: Wed, 4 Mar 2026 09:26:22 +1030 Subject: [PATCH 2/2] Generalize aromaticity index guard to cover ai_n <= 0 and ai_d <= 0 Per Koch and Dittmar (2006), if either the numerator or denominator is non-positive, the aromaticity index should be 0. This is more general than only guarding against ai_d == 0 (divide-by-zero) and correctly handles all cases where AI is physically meaningless. Co-Authored-By: Claude Opus 4.6 --- .../calc/MolecularFormulaCalc.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/corems/molecular_formula/calc/MolecularFormulaCalc.py b/corems/molecular_formula/calc/MolecularFormulaCalc.py index 471f89ba..cfe11c8e 100644 --- a/corems/molecular_formula/calc/MolecularFormulaCalc.py +++ b/corems/molecular_formula/calc/MolecularFormulaCalc.py @@ -560,12 +560,12 @@ def _calc_aromaticity_index_mod(self): ) ai_d = ai_es["C"] - (0.5 * ai_es["O"]) - ai_es["N"] - ai_es["S"] - ai = ai_n / ai_d if ai_d != 0 else 0 - - if ai < 0: + if ai_n <= 0 or ai_d <= 0: ai = 0 - if ai > 1: - ai = 1 + else: + ai = ai_n / ai_d + if ai > 1: + ai = 1 return ai @@ -601,12 +601,12 @@ def _calc_aromaticity_index(self): ) ai_d = ai_es["C"] - (ai_es["O"]) - ai_es["N"] - ai_es["S"] - ai = ai_n / ai_d if ai_d != 0 else 0 - - if ai < 0: + if ai_n <= 0 or ai_d <= 0: ai = 0 - if ai > 1: - ai = 1 + else: + ai = ai_n / ai_d + if ai > 1: + ai = 1 return ai