From 89714e26ba231f079e0712162cd8c06e2fa109ec Mon Sep 17 00:00:00 2001 From: dcf1007 Date: Sat, 14 Dec 2019 12:38:45 +0100 Subject: [PATCH] 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 with error "ValueError: invalid literal for int() with base 10: ''" in line 123 ("composition[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number)"). Changing the line to: "composition[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number) if number else 1" fixes that error --- brainpy/composition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brainpy/composition.py b/brainpy/composition.py index 7ff7839..a4caebc 100644 --- a/brainpy/composition.py +++ b/brainpy/composition.py @@ -120,7 +120,7 @@ def parse_formula(formula): raise ValueError("%r does not look like a formula" % (formula,)) composition = PyComposition() for elem, isotope, number in atom_pattern.findall(formula): - composition[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number) + composition[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number) if number else 1 return composition