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 = 25
sizeStates = 7
sizeConstants = 30
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] = "concentration in component Subtilin (nM)"
    legend_constants[1] = "RNA1 in component SpeciesInitialConcentrations (nM)"
    legend_constants[2] = "RNA2 in component SpeciesInitialConcentrations (nM)"
    legend_constants[3] = "spaK in component SpeciesInitialConcentrations (nM)"
    legend_constants[4] = "spaR in component SpeciesInitialConcentrations (nM)"
    legend_constants[5] = "spaKactive in component SpeciesInitialConcentrations (nM)"
    legend_constants[6] = "spaRactive in component SpeciesInitialConcentrations (nM)"
    legend_constants[7] = "GFP in component SpeciesInitialConcentrations (nM)"
    legend_constants[29] = "JRNA in component Template_Promoter_Constitutive (nM_per_s)"
    legend_algebraic[4] = "JGain in component RNA1_interface (nM_per_s)"
    legend_algebraic[0] = "J in component Template_RxR1P1 (nM_per_s)"
    legend_algebraic[11] = "J in component Template_ProteinCDS (nM_per_s)"
    legend_algebraic[18] = "J in component Template_RxR2P1 (nM_per_s)"
    legend_algebraic[15] = "J in component Template_RxR1P1 (nM_per_s)"
    legend_algebraic[13] = "J in component Template_RxR1P1 (nM_per_s)"
    legend_algebraic[14] = "J in component Template_RxR2P1 (nM_per_s)"
    legend_algebraic[19] = "JGain in component spaK_interface (nM_per_s)"
    legend_algebraic[16] = "J in component Template_RxR1P1 (nM_per_s)"
    legend_algebraic[20] = "JGain in component spaKactive_interface (nM_per_s)"
    legend_algebraic[5] = "J in component Template_ProteinCDS (nM_per_s)"
    legend_algebraic[17] = "J in component Template_RxR1P1 (nM_per_s)"
    legend_algebraic[21] = "J in component Template_RxR1P1 (nM_per_s)"
    legend_algebraic[22] = "JGain in component spaR_interface (nM_per_s)"
    legend_algebraic[23] = "J in component Template_RxR1P1 (nM_per_s)"
    legend_algebraic[24] = "JGain in component spaRactive_interface (nM_per_s)"
    legend_algebraic[2] = "JRNA in component Template_Promoter_Inductive (nM_per_s)"
    legend_algebraic[9] = "JGain in component RNA2_interface (nM_per_s)"
    legend_algebraic[6] = "J in component Template_RxR1P1 (nM_per_s)"
    legend_algebraic[7] = "J in component Template_ProteinCDS (nM_per_s)"
    legend_algebraic[12] = "JGain in component GFP_interface (nM_per_s)"
    legend_algebraic[10] = "J in component Template_RxR1P1 (nM_per_s)"
    legend_constants[8] = "cellVolume in component Chassis_Bacillus (femtoliter)"
    legend_voi = "time in component Time (second)"
    legend_constants[9] = "k in component Bugbuster_Promoter1 (PoPs)"
    legend_states[0] = "concentration in component Template_Species (nM)"
    legend_constants[10] = "kDecay in component Bioenvironment_Degradation_BugbusterRNA1 (per_s)"
    legend_algebraic[1] = "RNARiPs in component Template_RBS (RiPsInAttoMoles)"
    legend_constants[11] = "k in component Bugbuster_RBS_spaR (RiPs)"
    legend_algebraic[8] = "RNARiPs in component Template_RBS (RiPsInAttoMoles)"
    legend_constants[12] = "k in component Bugbuster_RBS_spaK (RiPs)"
    legend_states[1] = "concentration in component Template_Species (nM)"
    legend_constants[13] = "kDecay in component Bioenvironment_Degradation_spaK (per_s)"
    legend_constants[14] = "k in component Bioenvironment_RxR2P1_spaKActivation (per_nM_per_s)"
    legend_states[2] = "concentration in component Template_Species (nM)"
    legend_constants[15] = "k in component Bioenvironment_Dephosphorylation_spaKactive (per_s)"
    legend_constants[16] = "kDecay in component Bioenvironment_Degradation_spaKactive (per_s)"
    legend_states[3] = "concentration in component Template_Species (nM)"
    legend_constants[17] = "kDecay in component Bioenvironment_Degradation_spaR (per_s)"
    legend_constants[18] = "k in component Bioenvironment_RxR2P1_spaRActivation (per_nM_per_s)"
    legend_states[4] = "concentration in component Template_Species (nM)"
    legend_constants[19] = "k in component Bioenvironment_Dephosphorylation_spaRactive (per_s)"
    legend_constants[20] = "kDecay in component Bioenvironment_Degradation_spaRactive (per_s)"
    legend_constants[21] = "k in component Bugbuster_Promoter2 (PoPs)"
    legend_constants[22] = "n in component Bugbuster_Promoter2 (dimensionless)"
    legend_constants[23] = "Km in component Bugbuster_Promoter2 (nM)"
    legend_states[5] = "concentration in component Template_Species (nM)"
    legend_constants[24] = "kDecay in component Bioenvironment_Degradation_BugbusterRNA2 (per_s)"
    legend_algebraic[3] = "RNARiPs in component Template_RBS (RiPsInAttoMoles)"
    legend_constants[25] = "k in component Bugbuster_RBS_GFP (RiPs)"
    legend_states[6] = "concentration in component Template_Species (nM)"
    legend_constants[26] = "kDecay in component Bioenvironment_Degradation_GFP (per_s)"
    legend_constants[27] = "avogadrosConstant in component Template_Promoter_Constitutive (per_mole)"
    legend_constants[28] = "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)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    constants[0] = 1000
    constants[1] = 0
    constants[2] = 0
    constants[3] = 0
    constants[4] = 0
    constants[5] = 0
    constants[6] = 0
    constants[7] = 0
    constants[8] = 1
    constants[9] = 0.04
    constants[10] = 0.0058
    constants[11] = 0.1
    constants[12] = 0.1818
    constants[13] = 0.0012
    constants[14] = 1e-4
    constants[15] = 0.1
    constants[16] = 0.0012
    constants[17] = 0.0012
    constants[18] = 1e-4
    constants[19] = 0.1
    constants[20] = 0.0012
    constants[21] = 0.04
    constants[22] = 2
    constants[23] = 320
    constants[24] = 0.0058
    constants[25] = 0.145
    constants[26] = 0.0012
    constants[27] = 6.0221415e23
    constants[28] = 6.0221415e23
    constants[29] = constants[9]*1.00000e+09/(constants[8]*1.00000e-15*constants[27])
    states[0] = constants[1]
    states[1] = constants[3]
    states[2] = constants[5]
    states[3] = constants[4]
    states[4] = constants[6]
    states[5] = constants[2]
    states[6] = constants[7]
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    algebraic[0] = constants[10]*states[0]
    algebraic[4] = constants[29]-algebraic[0]
    rates[0] = algebraic[4]
    algebraic[2] = constants[21]*states[4]**constants[22]/(constants[23]**constants[22]+states[4]**constants[22])*1.00000e+09/(constants[8]*1.00000e-15*constants[28])
    algebraic[6] = constants[24]*states[5]
    algebraic[9] = algebraic[2]-algebraic[6]
    rates[5] = algebraic[9]
    algebraic[3] = 1.00000e+09*constants[25]*states[5]*constants[8]*1.00000e-15
    algebraic[7] = 1.00000e+06*algebraic[3]/constants[8]
    algebraic[10] = constants[26]*states[6]
    algebraic[12] = algebraic[7]-algebraic[10]
    rates[6] = algebraic[12]
    algebraic[8] = 1.00000e+09*constants[12]*states[0]*constants[8]*1.00000e-15
    algebraic[11] = 1.00000e+06*algebraic[8]/constants[8]
    algebraic[18] = states[2]*states[3]*constants[18]
    algebraic[15] = constants[15]*states[2]
    algebraic[13] = constants[13]*states[1]
    algebraic[14] = constants[0]*states[1]*constants[14]
    algebraic[19] = algebraic[11]+algebraic[18]+algebraic[15]-(algebraic[14]+algebraic[13])
    rates[1] = algebraic[19]
    algebraic[16] = constants[16]*states[2]
    algebraic[20] = algebraic[14]-algebraic[16]+algebraic[15]+algebraic[18]
    rates[2] = algebraic[20]
    algebraic[1] = 1.00000e+09*constants[11]*states[0]*constants[8]*1.00000e-15
    algebraic[5] = 1.00000e+06*algebraic[1]/constants[8]
    algebraic[17] = constants[17]*states[3]
    algebraic[21] = constants[19]*states[4]
    algebraic[22] = algebraic[5]+algebraic[21]-(algebraic[17]+algebraic[18])
    rates[3] = algebraic[22]
    algebraic[23] = constants[20]*states[4]
    algebraic[24] = algebraic[18]-algebraic[23]+algebraic[21]
    rates[4] = algebraic[24]
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[0] = constants[10]*states[0]
    algebraic[4] = constants[29]-algebraic[0]
    algebraic[2] = constants[21]*states[4]**constants[22]/(constants[23]**constants[22]+states[4]**constants[22])*1.00000e+09/(constants[8]*1.00000e-15*constants[28])
    algebraic[6] = constants[24]*states[5]
    algebraic[9] = algebraic[2]-algebraic[6]
    algebraic[3] = 1.00000e+09*constants[25]*states[5]*constants[8]*1.00000e-15
    algebraic[7] = 1.00000e+06*algebraic[3]/constants[8]
    algebraic[10] = constants[26]*states[6]
    algebraic[12] = algebraic[7]-algebraic[10]
    algebraic[8] = 1.00000e+09*constants[12]*states[0]*constants[8]*1.00000e-15
    algebraic[11] = 1.00000e+06*algebraic[8]/constants[8]
    algebraic[18] = states[2]*states[3]*constants[18]
    algebraic[15] = constants[15]*states[2]
    algebraic[13] = constants[13]*states[1]
    algebraic[14] = constants[0]*states[1]*constants[14]
    algebraic[19] = algebraic[11]+algebraic[18]+algebraic[15]-(algebraic[14]+algebraic[13])
    algebraic[16] = constants[16]*states[2]
    algebraic[20] = algebraic[14]-algebraic[16]+algebraic[15]+algebraic[18]
    algebraic[1] = 1.00000e+09*constants[11]*states[0]*constants[8]*1.00000e-15
    algebraic[5] = 1.00000e+06*algebraic[1]/constants[8]
    algebraic[17] = constants[17]*states[3]
    algebraic[21] = constants[19]*states[4]
    algebraic[22] = algebraic[5]+algebraic[21]-(algebraic[17]+algebraic[18])
    algebraic[23] = constants[20]*states[4]
    algebraic[24] = algebraic[18]-algebraic[23]+algebraic[21]
    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)