def instantiate(): ''' returns four objects: p: the parameter dictionary r: reaction rates m: model object s: simulator ''' p = parameters.Parameters() r = reactionrates.Reactions() m = model.PETC2014(p, r) s = modelbase.Simulator(m) print('Created a virtual organism. Experiment ready to run') return p, r, m, s
m.add_algebraicModule(feq, 'rapidEq', ['A'], ['X', 'Y']) # constant influx to the pool A m.set_rate('v0', lambda p: p.v0) m.set_stoichiometry('v0', {'A': 1}) # mass-action outflux from the pool A # note that rate expression depends on variable Y! def v2(p, y): return p.k2 * y m.set_rate('v2', v2, 'Y') m.set_stoichiometry('v2', {'A': -1}) # use the AlgmSimulate class to get access to the variables X and Y s = modelbase.Simulator(m) s.timeCourse(np.linspace(0, 100, 1000), np.zeros(1)) #a = s.getVar([0]) #xy = np.array([eqm.getConcentrations(np.array([z])) for z in a]) #plt.figure() #plt.plot(s.getT(),a) #plt.plot(s.getT(),xy) #plt.draw() #plt.show() plt.figure() plt.plot(s.getT(), s.getY()) plt.legend(m.allCpdNames()) plt.draw_if_interactive()
y0 = Test.set_initconc_cpd_labelpos(y0d) y0[Test.cpdIdDict['Glc6P100000']] = 30e-3 Test.par.update(PPP_model.par2) # Berthon1993 parameters, see PPPmodel # time simulation begin = 0 end = 300 * 60 steps = 10000 T = np.linspace(begin, end, steps) s = modelbase.Simulator(Test) s.integrator.linear_solver = 'SPGMR' s.integrator.atol = 1e-15 s.integrator.rtol = 1e-15 import time start_time = time.time() s.timeCourse(T, y0) print("--- %s seconds ---" % (time.time() - start_time)) # plot plt.plot(s.getT() / 60, s.getVarByName('Glc6P100000') * 1000, label='Glc6P-C1') plt.plot(s.getT() / 60, s.getVarByName('Glc6P001000') * 5 * 1000,