Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/barronh/permm
Browse files Browse the repository at this point in the history
Conflicts:
	src/permm/core/Mechanism.py
  • Loading branch information
barronh committed Jun 27, 2019
2 parents 9e7dbed + 73a5305 commit 5f2b03a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/permm/core/Mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ def from_eqns(cls, eqnstr, verbose=0):
"""
Create a mechanism from a KPP-style eqn string
"""
eqnstr = re.compile(r'(?<![;}])\s*\n').sub(r'', eqnstr)
eqnstr = re.compile(r'^//.+?$', re.MULTILINE).sub(r'', eqnstr)
textlines = eqnstr.split('\n')
rxnlines = [l.split(':')[0] for l in textlines if l.strip() != '#EQUATIONS' and l.strip() != '']
rxntxt = '\n'.join(rxnlines)
rxntxt = re.compile(r'[ \t]+').sub(' ', rxntxt)
rxntxt = re.compile('^{(.+?)\.?\s*}', re.M).sub(r' IRR_\1: ', rxntxt)
rxntxt = re.compile('{(.+?)}', re.M).sub('', rxntxt)
rxntxt = re.compile(r'^\s*[<{](.+?)\.?[>}]', re.MULTILINE).sub(r' IRR_\1: ', rxntxt)
rxntxt = re.compile(r'{(.+?)}').sub(r'\1', rxntxt)
rxntxt = 'reaction_list:\n' + rxntxt
from io import StringIO
if verbose > 0:
Expand Down Expand Up @@ -151,9 +153,13 @@ def __call__(self, expr, env = None):
"""
Evaluate string expression in the context of mechanism
species, species groups, reactions, net reactions and processes
expr - string to evaluate
env - optional, global environment that defaults to globals()
"""
if env is None:
env = globals()

try:
return self.variables[expr]
except:
Expand Down

0 comments on commit 5f2b03a

Please sign in to comment.