我目前正在使用SciPy.integrate.ode在Python中实现复杂的微生物食品网.我需要能够轻松地将物种和反应添加到系统中,所以我必须编写一些非常通用的代码.我的方案看起来像这样:
class Reaction(object):
def __init__(self):
#stuff common to all reactions
def __getReactionRate(self, **kwargs):
raise NotImplementedError
... Reaction subclasses that
... implement specific types of reactions
class Species(object):
def __init__(self, reactionsDict):
self.reactionsDict = reactionsDict
#reactionsDict looks like {'ReactionName':reactionObject, ...}
#stuff common to all species
def sumOverAllReactionsForThisSpecies(self, **kwargs):
#loop over all the reactions and return the
#cumulative change in the concentrations of all solutes
...Species subclasses where for each species
... are defined and passed to the superclass constructor
class …Run Code Online (Sandbox Code Playgroud)