def __init__(self, parameter_values=None, volume=1.0): # Initialize the model. gillespy.Model.__init__(self, name="simple1", volume=volume) # Parameters k1 = gillespy.Parameter(name='k1', expression=0.03) self.add_parameter(k1) # Species r1 = gillespy.Species(name='r1', initial_value=100) self.add_species(r1) r2 = gillespy.Species(name='r2', initial_value=100) self.add_species(r2) # Reactions rxn1 = gillespy.Reaction(name='r1d', reactants={r1: 2}, products={}, rate=k1) self.add_reaction(rxn1) rxn2 = gillespy.Reaction(name='r2d', reactants={r2: 2}, products={}, propensity_function='k1/2 * r2*(r2-1)/vol') self.add_reaction(rxn2)
def __init__(self, parameter_values=None): # Initialize the model. gillespy.Model.__init__(self, name="simple1") # Parameters k1 = gillespy.Parameter(name='k1', expression=parameter_values[0]) k2 = gillespy.Parameter(name='k2', expression=parameter_values[1]) k3 = gillespy.Parameter(name='k3', expression=parameter_values[2]) self.add_parameter([k1, k2, k3]) # Species S1 = gillespy.Species(name='S1', initial_value=100) S2 = gillespy.Species(name='S2', initial_value=0) self.add_species([S1, S2]) # Reactions rxn1 = gillespy.Reaction(name='S1 production', reactants={}, products={S1: 1}, rate=k1) rxn2 = gillespy.Reaction(name='dimer formation', reactants={S1: 2}, products={S2: 1}, rate=k2) rxn3 = gillespy.Reaction(name='dimer degradation', reactants={S2: 1}, products={}, rate=k3) self.add_reaction([rxn1, rxn2, rxn3]) self.timespan(np.linspace(0, 100, 101))
def __init__(self, concentration_model): gillespy.Model.__init__(self, name="Markevich2004_MAPK_phosphoRandomElementary") for s in concentration_model.listOfSpecies: self.add_species(gillespy.Species(name=s, initial_value=int(concentration_model.listOfSpecies[s].initial_value))) for p in concentration_model.listOfParameters: self.add_parameter(concentration_model.listOfParameters[p]) #for r in concentration_model.listOfReactions: # self.add_reaction(concentration_model.listOfReactions[r]) new_rxns = [] for rname in concentration_model.listOfReactions: r = concentration_model.listOfReactions[rname] #print r.propensity_function rxns = r.propensity_function.replace('cell * ','').replace('(','').replace(')','').split('-') #print rxns, r.reactants, r.products r1 = gillespy.Reaction(name=r.name, reactants=r.reactants, products=r.products, propensity_function = rxns[0]) new_rxns.append(r1) if len(rxns) > 1: r2 = gillespy.Reaction(name=r.name+'__reverse', reactants=r.products, products=r.reactants, propensity_function = rxns[1]) new_rxns.append(r2) self.add_reaction(new_rxns)
def _translate_species(model, y0=None): # Error check if y0 and len(y0) != len(model.species): raise Exception("len(y0) must equal len(model.species)") species_list = len(model.species) * [None] for i, sp in enumerate(model.species): val = 0. if y0: val = y0[i] else: for ic in model.initial_conditions: if str(ic[0]) == str(sp): val = np.round(ic[1].value) species_list[i] = gillespy.Species(name="__s%d" % i, initial_value=val) return species_list
def __init__(self, mu=10.0,kappa=10.0,ka=1e7,kd=0.01,gamma_m=0.02, gamma_p=0.02): # Initialize the model. gillespy.Model.__init__(self, name="GRN") # Parameters NA = 6.022e23 V = 37e-15 mu = gillespy.Parameter(name='mu', expression=mu) kappa = gillespy.Parameter(name='kappa', expression=kappa) ka = gillespy.Parameter(name='ka', expression=ka/(NA*V)) kd = gillespy.Parameter(name='kd', expression=kd) gamma_m = gillespy.Parameter(name='gamma_m', expression=gamma_m) gamma_p = gillespy.Parameter(name='gamma_p', expression=gamma_p) self.add_parameter([mu,kappa,ka,kd,gamma_m,gamma_p]) # Species G_f = gillespy.Species(name='G_f', initial_value=1) G_o = gillespy.Species(name='G_o', initial_value=0) mRNA = gillespy.Species(name='mRNA', initial_value=0) P = gillespy.Species(name='P', initial_value=0) self.add_species([G_f,G_o,mRNA,P]) # Reactions rxn1 = gillespy.Reaction(name = 'R1',reactants={G_f:1,P:1}, products = {G_o:1}, rate=ka) rxn2 = gillespy.Reaction(name = 'R2',reactants={mRNA:1}, products = {mRNA:1,P:1}, rate=kappa) rxn3 = gillespy.Reaction(name = 'R3',reactants={G_f:1}, products = {G_f:1,mRNA:1},rate=mu) rxn4 = gillespy.Reaction(name = 'R4',reactants={mRNA:1}, products = {}, rate=gamma_m) rxn5 = gillespy.Reaction(name = 'R5',reactants={P:1}, products = {}, rate=gamma_p) rxn6 = gillespy.Reaction(name = 'R6',reactants={G_o:1}, products = {G_f:1,P:1}, rate=kd) self.add_reaction([rxn1,rxn2,rxn3,rxn4,rxn5,rxn6]) self.tspan=numpy.linspace(0,3600,1000)
def __init__(self, parameter_values=None): # Initialize the model. gillespy.Model.__init__(self, name="simple1") # Parameters k1 = gillespy.Parameter(name='k1', expression=0.3) self.add_parameter(k1) # Species S = gillespy.Species(name='S', initial_value=100) self.add_species(S) # Reactions rxn1 = gillespy.Reaction(name='S degradation', reactants={S: 1}, products={}, rate=k1) self.add_reaction(rxn1) self.timespan(np.linspace(0, 20, 101))
def convert(filename, modelName = None, gillespy_model=None): try: import libsbml except ImportError: raise ImportError('libsbml is required to convert SBML files for GillesPy.') document = libsbml.readSBML(filename) errors = [] errorCount = document.getNumErrors() if errorCount > 0: for i in range(errorCount): error = document.getError(i) converterCode = 0 converterCode = -10 errors.append(["SBML {0}, code {1}, line {2}: {3}".format(error.getSeverityAsString(), error.getErrorId(), error.getLine(), error.getMessage()), converterCode]) if min([code for error, code in errors] + [0]) < 0: return None, errors model = document.getModel() numOfTabs = 0 if modelName == None: modelName = model.getName() if gillespy_model==None: gillespy_model = gillespy.Model(name = modelName) gillespy_model.units = "concentration" for i in range(model.getNumSpecies()): species = model.getSpecies(i) if species.getId() == 'EmptySet': errors.append(["EmptySet species detected in model on line {0}. EmptySet is not an explicit species in gillespy".format(species.getLine()), 0]) continue name = species.getId() if species.isSetInitialAmount(): value = species.getInitialAmount() elif species.isSetInitialConcentration(): value = species.getInitialConcentration() else: rule = model.getRule(species.getId()) if rule: msg = "" if rule.isAssignment(): msg = "assignment " elif rule.isRate(): msg = "rate " elif rule.isAlgebraic(): msg = "algebraic " msg += "rule" errors.append(["Species '{0}' does not have any initial conditions. Associated {1} '{2}' found, but {1}s are not supported in gillespy. Assuming initial condition 0".format(species.getId(), msg, rule.getId()), 0]) else: errors.append(["Species '{0}' does not have any initial conditions or rules. Assuming initial condition 0".format(species.getId()), 0]) value = 0 if value < 0.0: errors.append(["Species '{0}' has negative initial condition ({1}). gillespy does not support negative initial conditions. Assuming initial condition 0".format(species.getId(), value), -5]) value = 0 gillespySpecies = gillespy.Species(name = name, initial_value = value) gillespy_model.add_species([gillespySpecies]) for i in range(model.getNumParameters()): parameter=model.getParameter(i) name=parameter.getId() value=parameter.getValue() gillespyParameter = gillespy.Parameter(name = name, expression = value) gillespy_model.add_parameter([gillespyParameter]) for i in range(model.getNumCompartments()): compartment=model.getCompartment(i) name=compartment.getId() value=compartment.getSize() gillespyParameter = gillespy.Parameter(name = name, expression = value) gillespy_model.add_parameter([gillespyParameter]) #local parameters for i in range(model.getNumReactions()): reaction = model.getReaction(i) kineticLaw = reaction.getKineticLaw() for j in range(kineticLaw.getNumParameters()): parameter = kineticLaw.getParameter(j) name = parameter.getId() value = parameter.getValue() gillespyParameter = gillespy.Parameter(name = name, expression = value) gillespy_model.add_parameter([gillespyParameter]) #reactions for i in range(model.getNumReactions()): reaction = model.getReaction(i) name = reaction.getId() reactants = {} products = {} for j in range(reaction.getNumReactants()): species = reaction.getReactant(j) if species.getSpecies() == "EmptySet": errors.append(["EmptySet species detected as reactant in reaction '{0}' on line {1}. EmptySet is not an explicit species in gillespy".format(reaction.getId(), species.getLine()), 0]) else: reactants[species.getSpecies()] = species.getStoichiometry() #get products for j in range(reaction.getNumProducts()): species=reaction.getProduct(j) if species.getSpecies() == "EmptySet": errors.append(["EmptySet species detected as product in reaction '{0}' on line {1}. EmptySet is not an explicit species in gillespy".format(reaction.getId(), species.getLine()), 0]) else: products[species.getSpecies()] = species.getStoichiometry() #propensity kineticLaw = reaction.getKineticLaw() propensity = kineticLaw.getFormula() gillespyReaction = gillespy.Reaction(name = name, reactants = reactants, products = products, propensity_function = propensity) gillespy_model.add_reaction([gillespyReaction]) for i in range(model.getNumRules()): rule = model.getRule(i) t = [] if rule.isCompartmentVolume(): t.append('compartment') if rule.isParameter(): t.append('parameter') elif rule.isAssignment(): t.append('assignment') elif rule.isRate(): t.append('rate') elif rule.isAlgebraic(): t.append('algebraic') if len(t) > 0: t[0] = t[0].capitalize() msg = ", ".join(t) msg += " rule" else: msg = "Rule" errors.append(["{0} '{1}' found on line '{2}' with equation '{3}'. gillespy does not support SBML Rules".format(msg, rule.getId(), rule.getLine(), libsbml.formulaToString(rule.getMath())), -5]) for i in range(model.getNumCompartments()): compartment = model.getCompartment(i) errors.append(["Compartment '{0}' found on line '{1}' with volume '{2}' and dimension '{3}'. gillespy assumes a single well-mixed, reaction volume".format(compartment.getId(), compartment.getLine(), compartment.getVolume(), compartment.getSpatialDimensions()), -5]) for i in range(model.getNumConstraints()): constraint = model.getConstraint(i) errors.append(["Constraint '{0}' found on line '{1}' with equation '{2}'. gillespy does not support SBML Constraints".format(constraint.getId(), constraint.getLine(), libsbml.formulaToString(constraint.getMath())), -5]) for i in range(model.getNumEvents()): event = model.getEvent(i) errors.append(["Event '{0}' found on line '{1}' with trigger equation '{2}'. gillespy does not support SBML Events".format(event.getId(), event.getLine(), libsbml.formulaToString(event.getTrigger().getMath())), -5]) for i in range(model.getNumFunctionDefinitions()): function = model.getFunctionDefinition(i) errors.append(["Function '{0}' found on line '{1}' with equation '{2}'. gillespy does not support SBML Function Definitions".format(function.getId(), function.getLine(), libsbml.formulaToString(function.getMath())), -5]) return gillespy_model, errors
def __init__(self, parameter_values=param, initial_values=y0in, bmalko='None', AVPcells=20, VIPcells=20): """ """ assert AVPcells+VIPcells==40, \ "Total cells involved in signaling !=40." kav = 1 # equal strength of VIP and AVP sv = 1000 #system volume gsp.Model.__init__(self, name="gonze60", volume=sv) self.timespan(np.linspace(0, 7 * period, 7 * 4 * 24 + 1)) # set up kos, bmalkos avpbmalko = '1*' avpbmalko_ic = 1. vipbmalko = '1*' vipbmalko_ic = 1. bmalko_v1 = '0.05*' # set up kos if bmalko == 'AVP': avpbmalko = bmalko_v1 avpbmalko_ic = 0.05 elif bmalko == 'VIP': vipbmalko = bmalko_v1 vipbmalko_ic = 0.05 elif bmalko == 'AVPVIP': vipbmalko = bmalko_v1 avpbmalko = bmalko_v1 avpbmalko_ic = 0.05 vipbmalko_ic = 0.05 # For identical v2 pnames = [ 'v1', 'K1', 'n', 'v2', 'K2', 'k3', 'v4', 'K4', 'k5', 'v6', 'K6', 'k7', 'v8', 'K8', 'vc', 'Kc', 'K', 'L' ] v1 = gsp.Parameter(name=pnames[0], expression=parameter_values[0]) K1 = gsp.Parameter(name=pnames[1], expression=parameter_values[1]) n = gsp.Parameter(name=pnames[2], expression=parameter_values[2]) v2 = gsp.Parameter(name=pnames[3], expression=parameter_values[3]) K2 = gsp.Parameter(name=pnames[4], expression=parameter_values[4]) k3 = gsp.Parameter(name=pnames[5], expression=parameter_values[5]) v4 = gsp.Parameter(name=pnames[6], expression=parameter_values[6]) K4 = gsp.Parameter(name=pnames[7], expression=parameter_values[7]) k5 = gsp.Parameter(name=pnames[8], expression=parameter_values[8]) v6 = gsp.Parameter(name=pnames[9], expression=parameter_values[9]) K6 = gsp.Parameter(name=pnames[10], expression=parameter_values[10]) k7 = gsp.Parameter(name=pnames[11], expression=parameter_values[11]) v8 = gsp.Parameter(name=pnames[12], expression=parameter_values[12]) K8 = gsp.Parameter(name=pnames[13], expression=parameter_values[13]) vc = gsp.Parameter(name=pnames[14], expression=parameter_values[14]) Kc = gsp.Parameter(name=pnames[15], expression=parameter_values[15]) K = gsp.Parameter(name=pnames[16], expression=parameter_values[16]) L = gsp.Parameter(name=pnames[17], expression=parameter_values[17]) self.add_parameter([ v1, K1, n, v2, K2, k3, v4, K4, k5, v6, K6, k7, v8, K8, vc, Kc, K, L ]) # add all states as a dictionary NAVcells = 20 state_dict = OrderedDict() avpcoupling = '0' for cellidx in range(AVPcells): co = cellidx * 4 # first compartment: AVP state_dict['X1' + str(cellidx)] = gsp.Species( name="X1" + str(cellidx), initial_value=int(initial_values[0 + co] * sv)) state_dict['Y1' + str(cellidx)] = gsp.Species( name="Y1" + str(cellidx), initial_value=int(initial_values[1 + co] * sv)) state_dict['Z1' + str(cellidx)] = gsp.Species( name="Z1" + str(cellidx), initial_value=int(initial_values[2 + co] * sv)) state_dict['A1' + str(cellidx)] = gsp.Species( name="A1" + str(cellidx), initial_value=int(avpbmalko_ic * initial_values[3 + co] * sv)) avpcoupling += '+A1' + str(cellidx) vipcoupling = '0' for cellidx in range(VIPcells): co = cellidx * 4 + AVPcells * 4 # second compartment: VIP state_dict['X2' + str(cellidx)] = gsp.Species( name="X2" + str(cellidx), initial_value=int(initial_values[0 + co] * sv)) state_dict['Y2' + str(cellidx)] = gsp.Species( name="Y2" + str(cellidx), initial_value=int(initial_values[1 + co] * sv)) state_dict['Z2' + str(cellidx)] = gsp.Species( name="Z2" + str(cellidx), initial_value=int(initial_values[2 + co] * sv)) state_dict['V2' + str(cellidx)] = gsp.Species( name="V2" + str(cellidx), initial_value=int(vipbmalko_ic * initial_values[3 + co] * sv)) vipcoupling += "+V2" + str(cellidx) for cellidx in range(NAVcells): co = cellidx * 3 + AVPcells * 4 + VIPcells * 4 # third compartment: Nothing state_dict['X3' + str(cellidx)] = gsp.Species( name="X3" + str(cellidx), initial_value=int(initial_values[0 + co] * sv)) state_dict['Y3' + str(cellidx)] = gsp.Species( name="Y3" + str(cellidx), initial_value=int(initial_values[1 + co] * sv)) state_dict['Z3' + str(cellidx)] = gsp.Species( name="Z3" + str(cellidx), initial_value=int(initial_values[2 + co] * sv)) sd = state_dict self.add_species(sd.values()) kav = str(kav) ka = kav + '/(' + kav + '+1.)' kv = '1/(' + kav + '+1.)' coupling_str = '('+ka+'*('+avpcoupling+')/(20*vol) +'+\ kv+'*('+vipcoupling+')/(20*vol))' # generate all rxns that are common to AVP cells for cellindex in range(AVPcells): ci = str(cellindex) rxn1 = gsp.Reaction(name = 'X1'+ci+'_production', reactants = {}, products = {sd['X1'+ci]:1}, propensity_function = avpbmalko+'vol*v1*K1*K1*K1*K1/(K1*K1*K1*K1 +'+\ '(Z1'+ci+'/vol)*(Z1'+ci+'/vol)*(Z1'+ci+\ '/vol)*(Z1'+ci+'/vol))') rxn2 = gsp.Reaction(name = 'X1'+ci+'_degradation', reactants = {sd['X1'+ci]:1}, products = {}, propensity_function = 'vol*v2*(X1'+ci+'/vol)/(K2+X1'+\ ci+'/vol)') rxn3 = gsp.Reaction(name='X1' + ci + '_coupling', reactants={}, products={sd['X1' + ci]: 1}, propensity_function='vol*vc*K*(' + coupling_str + ')/(Kc +K*' + coupling_str + ')') rxn4 = gsp.Reaction(name='Y1' + ci + '_production', reactants={sd['X1' + ci]: 1}, products={ sd['Y1' + ci]: 1, sd['X1' + ci]: 1 }, rate=k3) rxn5 = gsp.Reaction(name = 'Y1'+ci+'_degradation', reactants = {sd['Y1'+ci]:1}, products = {}, propensity_function = 'vol*v4*(Y1'+ci+'/vol)/(K4+Y1'+\ ci+'/vol)') rxn6 = gsp.Reaction(name='Z1' + ci + '_production', reactants={sd['Y1' + ci]: 1}, products={ sd['Z1' + ci]: 1, sd['Y1' + ci]: 1 }, rate=k5) rxn7 = gsp.Reaction(name = 'Z1'+ci+'_degradation', reactants = {sd['Z1'+ci]:1}, products = {}, propensity_function = 'vol*v6*(Z1'+ci+'/vol)/(K6+Z1'+\ ci+'/vol)') rxn8 = gsp.Reaction(name='A1' + ci + '_production', reactants={sd['X1' + ci]: 1}, products={ sd['X1' + ci]: 1, sd['A1' + ci]: 1 }, rate=k7) rxn9 = gsp.Reaction(name = 'A1'+ci+'_degradation', reactants = {sd['A1'+ci]:1}, products = {}, propensity_function = 'vol*v8*(A1'+ci+'/vol)/(K8+A1'+\ ci+'/vol)') self.add_reaction( [rxn1, rxn2, rxn3, rxn4, rxn5, rxn6, rxn7, rxn8, rxn9]) # generate all rxns that are common to VIP cells for cellindex in range(VIPcells): ci = str(cellindex) rxn1 = gsp.Reaction(name = 'X2'+ci+'_production', reactants = {}, products = {sd['X2'+ci]:1}, propensity_function = vipbmalko+'vol*v1*K1*K1*K1*K1/(K1*K1*K1*K1 +'+\ '(Z2'+ci+'/vol)*(Z2'+ci+'/vol)*(Z2'+ci+\ '/vol)*(Z2'+ci+'/vol))') rxn2 = gsp.Reaction(name = 'X2'+ci+'_degradation', reactants = {sd['X2'+ci]:1}, products = {}, propensity_function = 'vol*v2*(X2'+ci+'/vol)/(K2+X2'+\ ci+'/vol)') rxn3 = gsp.Reaction(name='X2' + ci + '_coupling', reactants={}, products={sd['X2' + ci]: 1}, propensity_function='vol*vc*K*(' + coupling_str + ')/(Kc +K*' + coupling_str + ')') rxn4 = gsp.Reaction(name='Y2' + ci + '_production', reactants={sd['X2' + ci]: 1}, products={ sd['Y2' + ci]: 1, sd['X2' + ci]: 1 }, rate=k3) rxn5 = gsp.Reaction(name = 'Y2'+ci+'_degradation', reactants = {sd['Y2'+ci]:1}, products = {}, propensity_function = 'vol*v4*(Y2'+ci+'/vol)/(K4+Y2'+\ ci+'/vol)') rxn6 = gsp.Reaction(name='Z2' + ci + '_production', reactants={sd['Y2' + ci]: 1}, products={ sd['Z2' + ci]: 1, sd['Y2' + ci]: 1 }, rate=k5) rxn7 = gsp.Reaction(name = 'Z2'+ci+'_degradation', reactants = {sd['Z2'+ci]:1}, products = {}, propensity_function = 'vol*v6*(Z2'+ci+'/vol)/(K6+Z2'+\ ci+'/vol)') rxn8 = gsp.Reaction(name='V2' + ci + '_production', reactants={sd['X2' + ci]: 1}, products={ sd['X2' + ci]: 1, sd['V2' + ci]: 1 }, rate=k7) rxn9 = gsp.Reaction(name = 'V2'+ci+'_degradation', reactants = {sd['V2'+ci]:1}, products = {}, propensity_function = 'vol*v8*(V2'+ci+'/vol)/(K8+V2'+\ ci+'/vol)') self.add_reaction( [rxn1, rxn2, rxn3, rxn4, rxn5, rxn6, rxn7, rxn8, rxn9]) # generate all rxns that are common to NAV cells for cellindex in range(NAVcells): ci = str(cellindex) rxn1 = gsp.Reaction(name = 'X3'+ci+'_production', reactants = {}, products = {sd['X3'+ci]:1}, propensity_function = 'vol*v1*K1*K1*K1*K1/(K1*K1*K1*K1 +'+\ '(Z3'+ci+'/vol)*(Z3'+ci+'/vol)*(Z3'+ci+\ '/vol)*(Z3'+ci+'/vol))') rxn2 = gsp.Reaction(name = 'X3'+ci+'_degradation', reactants = {sd['X3'+ci]:1}, products = {}, propensity_function = 'vol*v2*(X3'+ci+'/vol)/(K2+X3'+\ ci+'/vol)') rxn3 = gsp.Reaction(name='X3' + ci + '_coupling', reactants={}, products={sd['X3' + ci]: 1}, propensity_function='vol*vc*K*(' + coupling_str + ')/(Kc +K*' + coupling_str + ')') rxn4 = gsp.Reaction(name='Y3' + ci + '_production', reactants={sd['X3' + ci]: 1}, products={ sd['Y3' + ci]: 1, sd['X3' + ci]: 1 }, rate=k3) rxn5 = gsp.Reaction(name = 'Y3'+ci+'_degradation', reactants = {sd['Y3'+ci]:1}, products = {}, propensity_function = 'vol*v4*(Y3'+ci+'/vol)/(K4+Y3'+\ ci+'/vol)') rxn6 = gsp.Reaction(name='Z3' + ci + '_production', reactants={sd['Y3' + ci]: 1}, products={ sd['Z3' + ci]: 1, sd['Y3' + ci]: 1 }, rate=k5) rxn7 = gsp.Reaction(name = 'Z3'+ci+'_degradation', reactants = {sd['Z3'+ci]:1}, products = {}, propensity_function = 'vol*v6*(Z3'+ci+'/vol)/(K6+Z3'+\ ci+'/vol)') self.add_reaction([rxn1, rxn2, rxn3, rxn4, rxn5, rxn6, rxn7])
def __init__(self, param=param, volume=0.5, timespan=np.linspace(0, 15, 15. / period * 48)): """ """ gillespy.Model.__init__(self, name="oregonator", volume=volume) self.timespan(timespan) # ============================================= # Define model species, initial values, parameters, and volume # ============================================= # Parameter values for this biochemical system are given in # concentration units. However, stochastic systems must use population # values. For example, a concentration unit of 0.5mol/(L*s) # is multiplied by a volume unit, to get a population/s rate # constant. Thus, for our non-mass action reactions, we include the # parameter "vol" in order to convert population units to concentration # units. Volume here = 300. c1x1 = gillespy.Parameter(name='c1x1', expression=param[0]) c2 = gillespy.Parameter(name='c2', expression=param[1]) c3x2 = gillespy.Parameter(name='c3x2', expression=param[2]) c4 = gillespy.Parameter(name='c4', expression=param[3] * 2) c5x3 = gillespy.Parameter(name='c5x3', expression=param[4]) self.add_parameter([c1x1, c2, c3x2, c4, c5x3]) # Species # Initial values of each species (concentration converted to pop.) Y1 = gillespy.Species(name='Y1', initial_value=int(y0in[0] * volume)) Y2 = gillespy.Species(name='Y2', initial_value=int(y0in[1] * volume)) Y3 = gillespy.Species(name='Y3', initial_value=int(y0in[2] * volume)) self.add_species([Y1, Y2, Y3]) rxn1 = gillespy.Reaction(name='Y2_to_Y1', reactants={Y2: 1}, products={Y1: 1}, rate=c1x1) rxn2 = gillespy.Reaction(name='Y1_Y2_2_deg', reactants={ Y1: 1, Y2: 1 }, products={}, rate=c2) rxn3 = gillespy.Reaction(name='Y1_Y3_form', reactants={Y1: 1}, products={ Y1: 2, Y3: 1 }, rate=c3x2) rxn4 = gillespy.Reaction(name='Y1_deg', reactants={Y1: 2}, products={Y1: 1}, rate=c4) rxn5 = gillespy.Reaction(name='Y3_to_Y2', reactants={Y3: 1}, products={Y2: 1}, rate=c5x3) self.add_reaction([rxn1, rxn2, rxn3, rxn4, rxn5])
def __init__(self, **kwargs): modelType = self.json_data["modelType"] species = self.json_data["species"] parameters = self.json_data["parameters"] reactions = self.json_data["reactions"] maxTime = self.json_data["maxTime"] if maxTime is None: maxTime = 100 increment = self.json_data["increment"] if increment is None: increment = 1 gillespy.Model.__init__(self, name=self.json_data["name"]) parameterByName = dict() for parameter in parameters: if parameter['name'] in kwargs: parameterByName[parameter['name']] = gillespy.Parameter( name=parameter['name'], expression=kwargs[parameter['name']]) else: parameterByName[parameter['name']] = gillespy.Parameter( name=parameter['name'], expression=parameter['value']) self.add_parameter(parameterByName[parameter['name']]) speciesByName = dict() for specie in species: speciesByName[specie['name']] = gillespy.Species( name=specie['name'], initial_value=specie['initialCondition']) self.add_species(speciesByName[specie['name']]) for reaction in reactions: inReactants = dict() for reactant in reaction['reactants']: if reactant['specie'] not in inReactants: inReactants[reactant['specie']] = 0 inReactants[reactant['specie']] += reactant['stoichiometry'] inProducts = dict() for product in reaction['products']: if product['specie'] not in inProducts: inProducts[product['specie']] = 0 inProducts[product['specie']] += product['stoichiometry'] reactants = dict([(speciesByName[reactant[0]], reactant[1]) for reactant in inReactants.items()]) products = dict([(speciesByName[product[0]], product[1]) for product in inProducts.items()]) if (reaction['type'] == 'custom'): self.add_reaction( gillespy.Reaction( name=reaction['name'], reactants=reactants, products=products, propensity_function=reaction['equation'])) else: self.add_reaction( gillespy.Reaction(name=reaction['name'], reactants=reactants, products=products, rate=parameterByName[reaction['rate']])) self.timespan( numpy.concatenate( (numpy.arange(maxTime / increment) * increment, [maxTime])))
def __init__(self, param=[0.05, 1.0, 4.0, 0.05, 1.0, 0.05, 1.0, 0.1, 2.0], volume = 200, timespan = np.linspace(0,500,501), IC = np.array([0.65609071,0.85088331]) ): """ """ gillespy.Model.__init__(self, name="tyson-2-state", volume=volume) self.timespan(timespan) # ============================================= # Define model species, initial values, parameters, and volume # ============================================= # Parameter values for this biochemical system are given in # concentration units. However, stochastic systems must use population # values. For example, a concentration unit of 0.5mol/(L*s) # is multiplied by a volume unit, to get a population/s rate # constant. Thus, for our non-mass action reactions, we include the # parameter "vol" in order to convert population units to concentration # units. Volume here = 300. k1 = gillespy.Parameter(name='k1', expression = param[0]) Kd = gillespy.Parameter(name='Kd', expression = param[1]) P = gillespy.Parameter(name='P', expression = param[2]) kdx = gillespy.Parameter(name='kdx', expression = param[3]) ksy = gillespy.Parameter(name='ksy', expression = param[4]) kdy = gillespy.Parameter(name='kdy', expression = param[5]) k2 = gillespy.Parameter(name='k2', expression = param[6]) Km = gillespy.Parameter(name='Km', expression = param[7]) KI = gillespy.Parameter(name='KI', expression = param[8]) volm = gillespy.Parameter(name='volume', expression = volume) self.add_parameter([k1, Kd, P, kdx, ksy, kdy, k2, Km, KI, volm]) # Species # Initial values of each species (concentration converted to pop.) X = gillespy.Species(name='X', initial_value=int(IC[0]*volume)) Y = gillespy.Species(name='Y', initial_value=int(IC[1]*volume)) self.add_species([X, Y]) # ============================================= # Define the reactions within the model # ============================================= # creation of X: rxn1 = gillespy.Reaction(name = 'X production', reactants = {}, products = {X:1}, propensity_function = 'volume*(k1*pow(Kd,P))/(pow(Kd,P)+pow(Y,P)/pow(volume,P))') # degradadation of X: rxn2 = gillespy.Reaction(name = 'X degradation', reactants = {X:1}, products = {}, rate = kdx) # creation of Y: rxn3 = gillespy.Reaction(name = 'Y production', reactants = {X:1}, products = {X:1, Y:1}, rate = ksy) # degradation of Y: rxn4 = gillespy.Reaction(name = 'Y degradation', reactants = {Y:1}, products = {}, rate = kdy) # nonlinear Y term: rxn5 = gillespy.Reaction(name = 'Y nonlin', reactants = {Y:1}, products = {}, propensity_function = 'volume*(Y/volume)/(Km + (Y/volume)+KI*(Y*Y)/(volume*volume))') self.add_reaction([rxn1,rxn2,rxn3,rxn4,rxn5])
def __init__(self, timespan, parameter_values): system_volume = 300 # system volume gillespy.Model.__init__(self, name="tyson-2-state", volume=system_volume) self.timespan(np.linspace(0, timespan - 1, timespan)) # ============================================= # Define model species, initial values, parameters, and volume # ============================================= # Parameter values for this biochemical system are given in # concentration units. However, stochastic systems must use population # values. For example, a concentration unit of 0.5mol/(L*s) # is multiplied by a volume unit, to get a population/s rate # constant. Thus, for our non-mass action reactions, we include the # parameter "vol" in order to convert population units to concentration # units. kt = gillespy.Parameter( name='kt', expression=parameter_values["kt"]) # expression=20.0) kd = gillespy.Parameter( name='kd', expression=parameter_values["kd"]) # expression=1.0) a0 = gillespy.Parameter( name='a0', expression=parameter_values["a0"]) # expression=0.005) a1 = gillespy.Parameter( name='a1', expression=parameter_values["a1"]) # expression=0.05) a2 = gillespy.Parameter( name='a2', expression=parameter_values["a2"]) # expression=0.1) kdx = gillespy.Parameter( name='kdx', expression=parameter_values["kdx"]) # expression=1.0) self.add_parameter([kt, kd, a0, a1, a2, kdx]) # Species # Initial values of each species (concentration converted to pop.) X = gillespy.Species(name='X', initial_value=int(0.65609071 * system_volume)) Y = gillespy.Species(name='Y', initial_value=int(0.85088331 * system_volume)) self.add_species([X, Y]) # ============================================= # Define the reactions within the model # ============================================= # creation of X: rxn1 = gillespy.Reaction( name='X production', reactants={}, products={X: 1}, propensity_function='vol*1/(1+(Y*Y/((vol*vol))))') # degradadation of X: rxn2 = gillespy.Reaction(name='X degradation', reactants={X: 1}, products={}, rate=kdx) # creation of Y: rxn3 = gillespy.Reaction(name='Y production', reactants={X: 1}, products={ X: 1, Y: 1 }, rate=kt) # degradation of Y: rxn4 = gillespy.Reaction(name='Y degradation', reactants={Y: 1}, products={}, rate=kd) # nonlinear Y term: rxn5 = gillespy.Reaction( name='Y nonlin', reactants={Y: 1}, products={}, propensity_function='Y/(a0 + a1*(Y/vol)+a2*Y*Y/(vol*vol))') self.add_reaction([rxn1, rxn2, rxn3, rxn4, rxn5])