brainpy icon indicating copy to clipboard operation
brainpy copied to clipboard

Update composition.py

Open dcf1007 opened this issue 5 years ago • 1 comments

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

dcf1007 avatar Dec 14 '19 11:12 dcf1007

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.

mobiusklein avatar Dec 14 '19 17:12 mobiusklein