Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions spatialpy/core/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,20 @@ def __init__(self, name=None, reactants=None, products=None, propensity_function
if reactants is not None:
for r in reactants:
rtype = type(r).__name__
if rtype == 'Species':
self.reactants[r.name] = reactants[r]
name = r.name if rtype == 'Species' else r
if name in self.reactants:
self.reactants[name] += reactants[r]
else:
self.reactants[r] = reactants[r]

self.reactants[name] = reactants[r]
if products is not None:
for p in products:
rtype = type(p).__name__
if rtype == 'Species':
self.products[p.name] = products[p]
ptype = type(p).__name__
name = p.name if ptype == 'Species' else p
if name in self.products:
self.products[name] += products[p]
else:
self.products[p] = products[p]
self.products[name] = products[p]

if self.marate is not None:
rtype = type(self.marate).__name__
Expand Down Expand Up @@ -343,7 +345,10 @@ def add_product(self, species, stoichiometry):
except TypeError as err:
raise ReactionError(f"Failed to validate product. Reason given: {err}") from err

self.products[name] = stoichiometry
if name in self.products:
self.products[name] += stoichiometry
else:
self.products[name] = stoichiometry

def add_reactant(self, species, stoichiometry):
"""
Expand All @@ -362,7 +367,10 @@ def add_reactant(self, species, stoichiometry):
except TypeError as err:
raise ReactionError(f"Failed to validate reactant. Reason given: {err}") from err

self.reactants[name] = stoichiometry
if name in self.reactants:
self.reactants[name] += stoichiometry
else:
self.reactants[name] = stoichiometry
if self.massaction and self.type == "mass-action":
self._create_mass_action()

Expand Down