diff --git a/interfaces/python/ck2cti.py b/interfaces/python/ck2cti.py index 6ae0da007..9416f779a 100755 --- a/interfaces/python/ck2cti.py +++ b/interfaces/python/ck2cti.py @@ -809,11 +809,12 @@ def fortFloat(s): return float(s) def isnumberlike(text): - """ Returns true if `text` contains only the digits 0-9 and '.' """ - for char in text: - if not char.isdigit() and char != '.': - return False - return True + """ Returns true if `text` can be interpreted as a floating point number. """ + try: + float(text) + return True + except ValueError: + return False def get_index(seq, value): """ @@ -1070,10 +1071,10 @@ class Parser(object): for term in expression.split('+'): term = term.strip() - if isnumberlike(term[0]): + if term[0].isdigit() or term[0] == '.': # This allows for for non-unity stoichiometric coefficients, e.g. # 2A=B+C or .85A+.15B=>C - j = [i for i,c in enumerate(term) if not isnumberlike(c)][0] + j = [i for i in range(len(term)) if isnumberlike(term[:i])][-1] if term[:j].isdigit(): stoichiometry = int(term[:j]) else: diff --git a/test/data/soot.inp b/test/data/soot.inp index e7a6712b2..681426312 100644 --- a/test/data/soot.inp +++ b/test/data/soot.inp @@ -14,10 +14,10 @@ END ! ! REACTIONS -C6H5+BIN5=>.9846153846BIN5+.0153846154BIN6+ 1.0769H2+H .562E+13 .500 .0 +C6H5+BIN5=>.9846153846BIN5+1.53846154E-2BIN6+ 1.0769H2+H .562E+13 .500 .0 A1C2HJ2+BIN5=>.9794871795BIN5+.0205128205BIN6+ .7692H2+H .510E+13 .500 .0 C10H7J1+BIN5=>.9743589744BIN5+.0256410256BIN6+ 1.4615H2+H .472E+13 .500 .0 -C10H7J2+BIN5=>.9743589744BIN5+.0256410256BIN6+ 1.4615H2+H .472E+13 .500 .0 +C10H7J2+BIN5=>9.743589744E-1BIN5+.0256410256BIN6+ 1.4615H2+H .472E+13 .500 .0 A2CH2-1+BIN5=>.9717948718BIN5+.0282051282BIN6+ 2.3077H2+H .456E+13 .500 .0 A2CH2-2+BIN5=>.9717948718BIN5+.0282051282BIN6+ 2.3077H2+H .456E+13 .500 .0 -END \ No newline at end of file +END