brainpy
brainpy copied to clipboard
Update composition.py
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
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.