def remove_by_cons(self, species, cons_law, debug = False):
"""Remove a species using a conservation law.
First replace removed_species in the conservation law with their expression.
Then use the conservation expression to write the species
concentration as function of the remaining species.
:Example:
>>> from crnpy.crn import CRN, from_react_strings
>>> net = from_react_strings(["E + S (k_1)<->(k1) C", "C ->(k2) E + P"])
>>> net.qss("C")
>>> net.reactions
(r0_r1: E + S ->(k1*k2/(k2 + k_1)) E + P,)
>>> net.removed_species
(('C', E*S*k1/(k2 + k_1)),)
>>> cl = ConsLaw("E + C", "etot")
>>> net.remove_by_cons("E", cl)
>>> net.reactions
(r0_r1: S ->(etot*k1*k2/(S*k1 + k2 + k_1)) P,)
References:
Tonello et al. (2016), On the elimination of intermediate species in chemical reaction networks.
"""
conservation = cons_law.expression
if debug:
print("Removed species: {}".format(self.removed_species))
print("Conservation: {}".format(conservation))
for variable, expr in self.removed_species:
if debug:
print("Replacing {} with {}".format(variable, expr))
conservation = conservation.subs(variable, expr)
if debug:
print("Found {}".format(conservation))
print
# The next is quicker, but not always applicable
#conservation = (conservation / sp.Symbol(species)).cancel()
#exp = cons_law.constant / conservation
exp = sp.solve(conservation - cons_law.constant, sp.Symbol(species))[0]
# remove species
self.remove_constant(species, expr = exp)
if debug: print("Remove by Conservation: added to removed_species {}".format(self.removed_species))
评论列表
文章目录