Generated Code
The following is python code generated by the CellML API from this CellML file. (Back to language selection)
The raw code is available.
# Size of variable arrays:
sizeAlgebraic = 26
sizeStates = 8
sizeConstants = 35
from math import *
from numpy import *
def createLegends():
legend_states = [""] * sizeStates
legend_rates = [""] * sizeStates
legend_algebraic = [""] * sizeAlgebraic
legend_voi = ""
legend_constants = [""] * sizeConstants
legend_constants[0] = "RNA_Device1 in component SpeciesInitialConcentrations (nM)"
legend_constants[1] = "TF in component SpeciesInitialConcentrations (nM)"
legend_constants[2] = "TFS in component SpeciesInitialConcentrations (nM)"
legend_constants[3] = "RNA_Device2 in component SpeciesInitialConcentrations (nM)"
legend_constants[4] = "IC in component SpeciesInitialConcentrations (nM)"
legend_constants[5] = "PhzS in component SpeciesInitialConcentrations (nM)"
legend_constants[6] = "PhzM in component SpeciesInitialConcentrations (nM)"
legend_constants[7] = "PYO in component SpeciesInitialConcentrations (nM)"
legend_constants[34] = "JRNA in component Template_Promoter_Constitutive (nM_per_s)"
legend_algebraic[6] = "JGain in component RNA_Device1_interface (nM_per_s)"
legend_algebraic[0] = "J in component Template_RxR1P1 (nM_per_s)"
legend_algebraic[7] = "J in component Template_ProteinCDS (nM_per_s)"
legend_algebraic[12] = "J in component Template_RxR1P1 (nM_per_s)"
legend_algebraic[17] = "J in component Template_RxR2P1Rev (nM_per_s)"
legend_algebraic[22] = "JGain in component TF_interface (nM_per_s)"
legend_constants[8] = "concentration in component S (nM)"
legend_algebraic[25] = "JGain in component TFS_interface (nM_per_s)"
legend_algebraic[23] = "J in component Template_RxR1P1 (nM_per_s)"
legend_algebraic[2] = "JRNA in component Template_Promoter_Inductive (nM_per_s)"
legend_algebraic[13] = "JGain in component RNA_Device2_interface (nM_per_s)"
legend_algebraic[8] = "J in component Template_RxR1P1 (nM_per_s)"
legend_algebraic[9] = "J in component Template_ProteinCDS (nM_per_s)"
legend_algebraic[18] = "JGain in component PhzM_interface (nM_per_s)"
legend_algebraic[14] = "J in component Template_RxR1P1 (nM_per_s)"
legend_constants[9] = "concentration in component PCA (nM)"
legend_algebraic[4] = "J in component Template_RxR1P1MM (nM_per_s)"
legend_algebraic[19] = "JGain in component IC_interface (nM_per_s)"
legend_algebraic[10] = "J in component Template_RxR1P1 (nM_per_s)"
legend_algebraic[15] = "J in component Template_RxR1P1MM (nM_per_s)"
legend_algebraic[11] = "J in component Template_ProteinCDS (nM_per_s)"
legend_algebraic[20] = "JGain in component PhzS_interface (nM_per_s)"
legend_algebraic[16] = "J in component Template_RxR1P1 (nM_per_s)"
legend_algebraic[24] = "JGain in component PYO_interface (nM_per_s)"
legend_algebraic[21] = "J in component Template_RxR1P1 (nM_per_s)"
legend_constants[10] = "cellVolume in component Chassis_EColi (femtoliter)"
legend_voi = "time in component Time (second)"
legend_constants[11] = "k in component ElectrEcoBluDevice1_Promoter (PoPs)"
legend_states[0] = "concentration in component Template_Species (nM)"
legend_constants[12] = "kDecay in component Bioenvironment_Degradation_ElectrEcoBluDevice1RNA (per_s)"
legend_algebraic[1] = "RNARiPs in component Template_RBS (RiPsInAttoMoles)"
legend_constants[13] = "k in component ElectrEcoBluDevice1_RBS (RiPs)"
legend_states[1] = "concentration in component Template_Species (nM)"
legend_constants[14] = "kDecay in component Bioenvironment_Degradation_TF (per_s)"
legend_constants[15] = "kf in component Bioenvironment_RxR2P1Rev_TFSFormation (per_nM_per_s)"
legend_constants[16] = "kb in component Bioenvironment_RxR2P1Rev_TFSFormation (per_s)"
legend_states[2] = "concentration in component Template_Species (nM)"
legend_constants[17] = "kDecay in component Bioenvironment_Degradation_TFS (per_s)"
legend_constants[18] = "k in component ElectrEcoBluDevice2_Promoter (PoPs)"
legend_constants[19] = "Km in component ElectrEcoBluDevice2_Promoter (nM)"
legend_constants[20] = "n in component ElectrEcoBluDevice2_Promoter (dimensionless)"
legend_states[3] = "concentration in component Template_Species (nM)"
legend_constants[21] = "kDecay in component Bioenvironment_Degradation_ElectrEcoBluDevice2RNA (per_s)"
legend_algebraic[3] = "RNARiPs in component Template_RBS (RiPsInAttoMoles)"
legend_constants[22] = "k in component ElectrEcoBluDevice2_RBS_PhzM (RiPs)"
legend_algebraic[5] = "RNARiPs in component Template_RBS (RiPsInAttoMoles)"
legend_constants[23] = "k in component ElectrEcoBluDevice2_RBS_PhzS (RiPs)"
legend_states[4] = "concentration in component Template_Species (nM)"
legend_constants[24] = "kDecay in component Bioenvironment_Degradation_PhzM (per_s)"
legend_constants[25] = "k in component Bioenvironment_RxR1P1MM_ICFormation (per_s)"
legend_constants[26] = "Km in component Bioenvironment_RxR1P1MM_ICFormation (nM)"
legend_states[5] = "concentration in component Template_Species (nM)"
legend_constants[27] = "kDecay in component Bioenvironment_Degradation_IC (per_s)"
legend_states[6] = "concentration in component Template_Species (nM)"
legend_constants[28] = "kDecay in component Bioenvironment_Degradation_PhzS (per_s)"
legend_constants[29] = "k in component Bioenvironment_RxR1P1MM_PYOFormation (per_s)"
legend_constants[30] = "Km in component Bioenvironment_RxR1P1MM_PYOFormation (nM)"
legend_states[7] = "concentration in component Template_Species (nM)"
legend_constants[31] = "kDecay in component Bioenvironment_Degradation_PYO (per_s)"
legend_constants[32] = "avogadrosConstant in component Template_Promoter_Constitutive (per_mole)"
legend_constants[33] = "avogadrosConstant in component Template_Promoter_Inductive (per_mole)"
legend_rates[0] = "d/dt concentration in component Template_Species (nM)"
legend_rates[1] = "d/dt concentration in component Template_Species (nM)"
legend_rates[2] = "d/dt concentration in component Template_Species (nM)"
legend_rates[3] = "d/dt concentration in component Template_Species (nM)"
legend_rates[4] = "d/dt concentration in component Template_Species (nM)"
legend_rates[5] = "d/dt concentration in component Template_Species (nM)"
legend_rates[6] = "d/dt concentration in component Template_Species (nM)"
legend_rates[7] = "d/dt concentration in component Template_Species (nM)"
return (legend_states, legend_algebraic, legend_voi, legend_constants)
def initConsts():
constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
constants[0] = 0
constants[1] = 8621
constants[2] = 0
constants[3] = 0
constants[4] = 0
constants[5] = 0
constants[6] = 0
constants[7] = 0
constants[8] = 5000
constants[9] = 2
constants[10] = 1
constants[11] = 1.085
constants[12] = 0.05
constants[13] = 1.4
constants[14] = 5.8e-3
constants[15] = 1e3
constants[16] = 4e6
constants[17] = 3.851e-4
constants[18] = 89
constants[19] = 15000
constants[20] = 1
constants[21] = 8e-6
constants[22] = 40
constants[23] = 1
constants[24] = 8e-1
constants[25] = 0.2
constants[26] = 0.1
constants[27] = 5e-5
constants[28] = 8e-1
constants[29] = 1
constants[30] = 0.1
constants[31] = 5e-1
constants[32] = 6.0221415e23
constants[33] = 6.0221415e23
constants[34] = constants[11]*1.00000e+09/(constants[10]*1.00000e-15*constants[32])
states[0] = constants[0]
states[1] = constants[1]
states[2] = constants[2]
states[3] = constants[3]
states[4] = constants[6]
states[5] = constants[4]
states[6] = constants[5]
states[7] = constants[7]
return (states, constants)
def computeRates(voi, states, constants):
rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
algebraic[0] = constants[12]*states[0]
algebraic[6] = constants[34]-algebraic[0]
rates[0] = algebraic[6]
algebraic[2] = constants[18]*states[2]**constants[20]/(constants[19]**constants[20]+states[2]**constants[20])*1.00000e+09/(constants[10]*1.00000e-15*constants[33])
algebraic[8] = constants[21]*states[3]
algebraic[13] = algebraic[2]-algebraic[8]
rates[3] = algebraic[13]
algebraic[3] = 1.00000e+09*constants[22]*states[3]*constants[10]*1.00000e-15
algebraic[9] = 1.00000e+06*algebraic[3]/constants[10]
algebraic[14] = constants[24]*states[4]
algebraic[18] = algebraic[9]-algebraic[14]
rates[4] = algebraic[18]
algebraic[4] = constants[25]*states[4]*constants[9]/(constants[9]+constants[26])
algebraic[10] = constants[27]*states[5]
algebraic[15] = constants[29]*states[6]*states[5]/(states[5]+constants[30])
algebraic[19] = algebraic[4]-algebraic[10]-algebraic[15]
rates[5] = algebraic[19]
algebraic[5] = 1.00000e+09*constants[23]*states[3]*constants[10]*1.00000e-15
algebraic[11] = 1.00000e+06*algebraic[5]/constants[10]
algebraic[16] = constants[28]*states[6]
algebraic[20] = algebraic[11]-algebraic[16]
rates[6] = algebraic[20]
algebraic[1] = 1.00000e+09*constants[13]*states[0]*constants[10]*1.00000e-15
algebraic[7] = 1.00000e+06*algebraic[1]/constants[10]
algebraic[12] = constants[14]*states[1]
algebraic[17] = states[1]*constants[8]*constants[15]-constants[16]*states[2]
algebraic[22] = algebraic[7]-algebraic[12]-algebraic[17]
rates[1] = algebraic[22]
algebraic[21] = constants[31]*states[7]
algebraic[24] = algebraic[15]-algebraic[21]
rates[7] = algebraic[24]
algebraic[23] = constants[17]*states[2]
algebraic[25] = algebraic[17]-algebraic[23]
rates[2] = algebraic[25]
return(rates)
def computeAlgebraic(constants, states, voi):
algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
states = array(states)
voi = array(voi)
algebraic[0] = constants[12]*states[0]
algebraic[6] = constants[34]-algebraic[0]
algebraic[2] = constants[18]*states[2]**constants[20]/(constants[19]**constants[20]+states[2]**constants[20])*1.00000e+09/(constants[10]*1.00000e-15*constants[33])
algebraic[8] = constants[21]*states[3]
algebraic[13] = algebraic[2]-algebraic[8]
algebraic[3] = 1.00000e+09*constants[22]*states[3]*constants[10]*1.00000e-15
algebraic[9] = 1.00000e+06*algebraic[3]/constants[10]
algebraic[14] = constants[24]*states[4]
algebraic[18] = algebraic[9]-algebraic[14]
algebraic[4] = constants[25]*states[4]*constants[9]/(constants[9]+constants[26])
algebraic[10] = constants[27]*states[5]
algebraic[15] = constants[29]*states[6]*states[5]/(states[5]+constants[30])
algebraic[19] = algebraic[4]-algebraic[10]-algebraic[15]
algebraic[5] = 1.00000e+09*constants[23]*states[3]*constants[10]*1.00000e-15
algebraic[11] = 1.00000e+06*algebraic[5]/constants[10]
algebraic[16] = constants[28]*states[6]
algebraic[20] = algebraic[11]-algebraic[16]
algebraic[1] = 1.00000e+09*constants[13]*states[0]*constants[10]*1.00000e-15
algebraic[7] = 1.00000e+06*algebraic[1]/constants[10]
algebraic[12] = constants[14]*states[1]
algebraic[17] = states[1]*constants[8]*constants[15]-constants[16]*states[2]
algebraic[22] = algebraic[7]-algebraic[12]-algebraic[17]
algebraic[21] = constants[31]*states[7]
algebraic[24] = algebraic[15]-algebraic[21]
algebraic[23] = constants[17]*states[2]
algebraic[25] = algebraic[17]-algebraic[23]
return algebraic
def solve_model():
"""Solve model with ODE solver"""
from scipy.integrate import ode
# Initialise constants and state variables
(init_states, constants) = initConsts()
# Set timespan to solve over
voi = linspace(0, 10, 500)
# Construct ODE object to solve
r = ode(computeRates)
r.set_integrator('vode', method='bdf', atol=1e-06, rtol=1e-06, max_step=1)
r.set_initial_value(init_states, voi[0])
r.set_f_params(constants)
# Solve model
states = array([[0.0] * len(voi)] * sizeStates)
states[:,0] = init_states
for (i,t) in enumerate(voi[1:]):
if r.successful():
r.integrate(t)
states[:,i+1] = r.y
else:
break
# Compute algebraic variables
algebraic = computeAlgebraic(constants, states, voi)
return (voi, states, algebraic)
def plot_model(voi, states, algebraic):
"""Plot variables against variable of integration"""
import pylab
(legend_states, legend_algebraic, legend_voi, legend_constants) = createLegends()
pylab.figure(1)
pylab.plot(voi,vstack((states,algebraic)).T)
pylab.xlabel(legend_voi)
pylab.legend(legend_states + legend_algebraic, loc='best')
pylab.show()
if __name__ == "__main__":
(voi, states, algebraic) = solve_model()
plot_model(voi, states, algebraic)
