mobiusklein / brainpy

A Python implementation of Baffling Recursive Algorithm for Isotopic distributioN calculations
http://mobiusklein.github.io/brainpy
Apache License 2.0
19 stars 10 forks source link

Update composition.py #1

Open dcf1007 opened 4 years ago

dcf1007 commented 4 years ago

When you have a formula with only 1 atom of the element (let's say H2O or HPO4), the function "parse_formula(formula)" would crash in line 123 composition[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number) with error:

ValueError: invalid literal for int() with base 10: ''

Changing the line to: composition[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number) if number else 1 fixes that error

mobiusklein commented 4 years ago

Thank you again for taking the time to read through and find the solution to your problem. I mention in my comment on #2 that the C-extension parser also has this issue, but would be much harder to fix.

I can merge this PR if you don't plan to use the C extension and would still find this useful.