[ck2cti] Partial support for scientific notation in stoichiometric coefficients
This won't work for positive exponents, because the '+' will still be interpreted as a delimiter between terms of the reaction expression.
This commit is contained in:
parent
6d5b7999de
commit
94f1b35b79
2 changed files with 11 additions and 10 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
END
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue