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 = 30
sizeStates = 18
sizeConstants = 33
from math import *
from numpy import *

def createLegends():
    legend_states = [""] * sizeStates
    legend_rates = [""] * sizeStates
    legend_algebraic = [""] * sizeAlgebraic
    legend_voi = ""
    legend_constants = [""] * sizeConstants
    legend_voi = "time in component environment (second)"
    legend_states[0] = "q_ATP in component environment (fmol)"
    legend_states[1] = "q_AC in component environment (fmol)"
    legend_states[2] = "q_cAMP in component environment (fmol)"
    legend_states[3] = "q_AC_ATP in component environment (fmol)"
    legend_states[4] = "q_FSK in component environment (fmol)"
    legend_states[5] = "q_FSK_AC in component environment (fmol)"
    legend_states[6] = "q_FSK_AC_ATP in component environment (fmol)"
    legend_states[7] = "q_Gsa_GTP in component environment (fmol)"
    legend_states[8] = "q_Gsa_GTP_AC in component environment (fmol)"
    legend_states[9] = "q_Gsa_GTP_AC_ATP in component environment (fmol)"
    legend_states[10] = "q_PDE in component environment (fmol)"
    legend_states[11] = "q_PDEinh in component environment (fmol)"
    legend_states[12] = "q_PDE_cAMP in component environment (fmol)"
    legend_states[13] = "q_IBMX in component environment (fmol)"
    legend_states[14] = "q_five_AMP in component environment (fmol)"
    legend_states[15] = "q_Gia_GTP in component environment (fmol)"
    legend_states[16] = "q_ACinh in component environment (fmol)"
    legend_states[17] = "q_PPi in component environment (fmol)"
    legend_algebraic[18] = "v_1a in component cAMP (fmol_per_sec)"
    legend_algebraic[19] = "v_1b in component cAMP (fmol_per_sec)"
    legend_algebraic[20] = "v_2a in component cAMP (fmol_per_sec)"
    legend_algebraic[21] = "v_2b in component cAMP (fmol_per_sec)"
    legend_algebraic[22] = "v_3a in component cAMP (fmol_per_sec)"
    legend_algebraic[23] = "v_3b in component cAMP (fmol_per_sec)"
    legend_algebraic[24] = "v_4a in component cAMP (fmol_per_sec)"
    legend_algebraic[26] = "v_4b in component cAMP (fmol_per_sec)"
    legend_algebraic[28] = "v_5 in component cAMP (fmol_per_sec)"
    legend_algebraic[25] = "v_6 in component cAMP (fmol_per_sec)"
    legend_algebraic[27] = "v_7 in component cAMP (fmol_per_sec)"
    legend_algebraic[29] = "v_GiAC in component cAMP (fmol_per_sec)"
    legend_constants[0] = "kappa_1a in component cAMP_parameters (fmol_per_sec)"
    legend_constants[1] = "kappa_1b in component cAMP_parameters (fmol_per_sec)"
    legend_constants[2] = "kappa_2a in component cAMP_parameters (fmol_per_sec)"
    legend_constants[3] = "kappa_2b in component cAMP_parameters (fmol_per_sec)"
    legend_constants[4] = "kappa_3a in component cAMP_parameters (fmol_per_sec)"
    legend_constants[5] = "kappa_3b in component cAMP_parameters (fmol_per_sec)"
    legend_constants[6] = "kappa_4a in component cAMP_parameters (fmol_per_sec)"
    legend_constants[7] = "kappa_4b in component cAMP_parameters (fmol_per_sec)"
    legend_constants[8] = "kappa_5 in component cAMP_parameters (fmol_per_sec)"
    legend_constants[9] = "kappa_6 in component cAMP_parameters (fmol_per_sec)"
    legend_constants[10] = "kappa_7 in component cAMP_parameters (fmol_per_sec)"
    legend_constants[11] = "kappa_GiAC in component cAMP_parameters (fmol_per_sec)"
    legend_constants[12] = "K_ATP in component cAMP_parameters (per_fmol)"
    legend_constants[13] = "K_cAMP in component cAMP_parameters (per_fmol)"
    legend_constants[14] = "K_AC in component cAMP_parameters (per_fmol)"
    legend_constants[15] = "K_AC_ATP in component cAMP_parameters (per_fmol)"
    legend_constants[16] = "K_Gsa_GTP_AC in component cAMP_parameters (per_fmol)"
    legend_constants[17] = "K_Gsa_GTP_AC_ATP in component cAMP_parameters (per_fmol)"
    legend_constants[18] = "K_FSK_AC in component cAMP_parameters (per_fmol)"
    legend_constants[19] = "K_FSK_AC_ATP in component cAMP_parameters (per_fmol)"
    legend_constants[20] = "K_PDE in component cAMP_parameters (per_fmol)"
    legend_constants[21] = "K_PDE_cAMP in component cAMP_parameters (per_fmol)"
    legend_constants[22] = "K_five_AMP in component cAMP_parameters (per_fmol)"
    legend_constants[23] = "K_IBMX in component cAMP_parameters (per_fmol)"
    legend_constants[24] = "K_PDEinh in component cAMP_parameters (per_fmol)"
    legend_constants[25] = "K_Gsa_GTP in component cAMP_parameters (per_fmol)"
    legend_constants[26] = "K_FSK in component cAMP_parameters (per_fmol)"
    legend_constants[27] = "K_Gia_GTP in component cAMP_parameters (per_fmol)"
    legend_constants[28] = "K_ACinh in component cAMP_parameters (per_fmol)"
    legend_constants[29] = "K_PPi in component cAMP_parameters (per_fmol)"
    legend_constants[30] = "R in component constants (J_per_K_per_mol)"
    legend_constants[31] = "T in component constants (kelvin)"
    legend_algebraic[0] = "mu_ATP in component cAMP (J_per_mol)"
    legend_algebraic[1] = "mu_cAMP in component cAMP (J_per_mol)"
    legend_algebraic[2] = "mu_AC in component cAMP (J_per_mol)"
    legend_algebraic[3] = "mu_AC_ATP in component cAMP (J_per_mol)"
    legend_algebraic[4] = "mu_Gsa_GTP_AC in component cAMP (J_per_mol)"
    legend_algebraic[5] = "mu_Gsa_GTP_AC_ATP in component cAMP (J_per_mol)"
    legend_algebraic[6] = "mu_FSK_AC in component cAMP (J_per_mol)"
    legend_algebraic[7] = "mu_FSK_AC_ATP in component cAMP (J_per_mol)"
    legend_algebraic[8] = "mu_PDE in component cAMP (J_per_mol)"
    legend_algebraic[9] = "mu_PDE_cAMP in component cAMP (J_per_mol)"
    legend_algebraic[10] = "mu_five_AMP in component cAMP (J_per_mol)"
    legend_algebraic[11] = "mu_IBMX in component cAMP (J_per_mol)"
    legend_algebraic[12] = "mu_PDEinh in component cAMP (J_per_mol)"
    legend_algebraic[13] = "mu_Gsa_GTP in component cAMP (J_per_mol)"
    legend_algebraic[14] = "mu_FSK in component cAMP (J_per_mol)"
    legend_algebraic[15] = "mu_Gia_GTP in component cAMP (J_per_mol)"
    legend_algebraic[16] = "mu_ACinh in component cAMP (J_per_mol)"
    legend_algebraic[17] = "mu_PPi in component cAMP (J_per_mol)"
    legend_constants[32] = "F in component constants (C_per_mol)"
    legend_rates[0] = "d/dt q_ATP in component environment (fmol)"
    legend_rates[1] = "d/dt q_AC in component environment (fmol)"
    legend_rates[3] = "d/dt q_AC_ATP in component environment (fmol)"
    legend_rates[2] = "d/dt q_cAMP in component environment (fmol)"
    legend_rates[4] = "d/dt q_FSK in component environment (fmol)"
    legend_rates[5] = "d/dt q_FSK_AC in component environment (fmol)"
    legend_rates[6] = "d/dt q_FSK_AC_ATP in component environment (fmol)"
    legend_rates[7] = "d/dt q_Gsa_GTP in component environment (fmol)"
    legend_rates[8] = "d/dt q_Gsa_GTP_AC in component environment (fmol)"
    legend_rates[9] = "d/dt q_Gsa_GTP_AC_ATP in component environment (fmol)"
    legend_rates[12] = "d/dt q_PDE_cAMP in component environment (fmol)"
    legend_rates[10] = "d/dt q_PDE in component environment (fmol)"
    legend_rates[13] = "d/dt q_IBMX in component environment (fmol)"
    legend_rates[11] = "d/dt q_PDEinh in component environment (fmol)"
    legend_rates[14] = "d/dt q_five_AMP in component environment (fmol)"
    legend_rates[15] = "d/dt q_Gia_GTP in component environment (fmol)"
    legend_rates[16] = "d/dt q_ACinh in component environment (fmol)"
    legend_rates[17] = "d/dt q_PPi in component environment (fmol)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    states[0] = 190
    states[1] = 1.889E-03
    states[2] = 3.212E-02
    states[3] = 1e-18
    states[4] = 3.8e-5
    states[5] = 1e-18
    states[6] = 1e-18
    states[7] = 9.519E-04
    states[8] = 1e-18
    states[9] = 1e-18
    states[10] = 1.482E-03
    states[11] = 1e-18
    states[12] = 1e-18
    states[13] = 3.80E-06
    states[14] = 1e-18
    states[15] = 4.81E-04
    states[16] = 1e-18
    states[17] = 1e-18
    constants[0] = 9.47329e+06
    constants[1] = 0.00197793
    constants[2] = 176000
    constants[3] = 0.047492
    constants[4] = 5.07667e+08
    constants[5] = 5.9031e-17
    constants[6] = 36084.5
    constants[7] = 0.138787
    constants[8] = 751.564
    constants[9] = 556.617
    constants[10] = 160555
    constants[11] = 685.521
    constants[12] = 9.19362e-06
    constants[13] = 0.0102598
    constants[14] = 9.02358
    constants[15] = 2.93942
    constants[16] = 52.2258
    constants[17] = 5.20284
    constants[18] = 0.181058
    constants[19] = 0.0492449
    constants[20] = 2.28256
    constants[21] = 1.04728
    constants[22] = 0.0102598
    constants[23] = 0.01642
    constants[24] = 38.679
    constants[25] = 0.420618
    constants[26] = 1.32565e-05
    constants[27] = 0.013661
    constants[28] = 42.4053
    constants[29] = 2.60488e-05
    constants[30] = 8.31
    constants[31] = 310
    constants[32] = 96485
    return (states, constants)

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

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