Skip to content

Fix divide-by-zero in aromaticity index calculation#26

Open
robertyoung3 wants to merge 1 commit intoEMSL-Computing:masterfrom
robertyoung3:fix/aromaticity-index-divide-by-zero
Open

Fix divide-by-zero in aromaticity index calculation#26
robertyoung3 wants to merge 1 commit intoEMSL-Computing:masterfrom
robertyoung3:fix/aromaticity-index-divide-by-zero

Conversation

@robertyoung3
Copy link

Summary

  • _calc_ai() and _calc_ai_mod() in MolecularFormulaCalc divide ai_n / ai_d without guarding against ai_d == 0
  • This raises ZeroDivisionError for molecular formulas where C - 0.5*O - N - S (or C - O - N - S for modified AI) equals zero
  • Returns 0 when denominator is zero, consistent with the existing clamping to [0, 1]

Before

ai = ai_n / ai_d

After

ai = ai_n / ai_d if ai_d != 0 else 0

Applied to both _calc_ai() (line 563) and _calc_ai_mod() (line 604).

References

Test plan

  • Verified both methods have the same pattern and same fix
  • A denominator of zero means no aromatic carbon skeleton is possible, so AI = 0 is the correct semantic value

@robertyoung3 robertyoung3 force-pushed the fix/aromaticity-index-divide-by-zero branch from ed6e03e to 615108a Compare March 3, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant