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 = 3
sizeStates = 9
sizeConstants = 18
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_constants[0] = "EGF in component EGF (dimensionless)"
    legend_constants[1] = "pro_EGFR in component pro_EGFR (dimensionless)"
    legend_states[0] = "EGFR in component EGFR (dimensionless)"
    legend_states[1] = "EGF_EGFR in component EGF_EGFR (dimensionless)"
    legend_constants[2] = "k2_EGF_EGFR in component model_parameters (first_order_rate_constant)"
    legend_constants[3] = "k1_EGF_EGFR in component model_parameters (first_order_rate_constant)"
    legend_constants[4] = "EGFR_turnover in component model_parameters (first_order_rate_constant)"
    legend_constants[5] = "k1_EGFR_phosphorylation in component model_parameters (first_order_rate_constant)"
    legend_states[2] = "pEGFR in component pEGFR (dimensionless)"
    legend_states[3] = "pEGFR_Akt in component pEGFR_Akt (dimensionless)"
    legend_states[4] = "Akt in component Akt (dimensionless)"
    legend_constants[6] = "k1_pEGFR_degradation in component model_parameters (first_order_rate_constant)"
    legend_constants[7] = "k1_Akt_phosphorylation in component model_parameters (first_order_rate_constant)"
    legend_constants[8] = "k1_pEGFR_Akt in component model_parameters (first_order_rate_constant)"
    legend_constants[9] = "k2_pEGFR_Akt in component model_parameters (first_order_rate_constant)"
    legend_states[5] = "pAkt in component pAkt (dimensionless)"
    legend_constants[10] = "k1_pAkt_dephosphorylation in component model_parameters (first_order_rate_constant)"
    legend_states[6] = "S6 in component S6 (dimensionless)"
    legend_states[7] = "pAkt_S6 in component pAkt_S6 (dimensionless)"
    legend_constants[11] = "k1_pAkt_S6 in component model_parameters (first_order_rate_constant)"
    legend_constants[12] = "k2_pAkt_S6 in component model_parameters (first_order_rate_constant)"
    legend_constants[13] = "k1_S6_phosphorylation in component model_parameters (first_order_rate_constant)"
    legend_states[8] = "pS6 in component pS6 (dimensionless)"
    legend_constants[14] = "k1_pS6_dephosphorylation in component model_parameters (first_order_rate_constant)"
    legend_algebraic[0] = "pEGFR_total in component pEGFR_total (dimensionless)"
    legend_constants[15] = "pEGFR_scalefactor in component pEGFR_total (dimensionless)"
    legend_algebraic[1] = "pAkt_total in component pAkt_total (dimensionless)"
    legend_constants[16] = "pAkt_scalefactor in component pAkt_total (dimensionless)"
    legend_algebraic[2] = "pS6_total in component pS6_total (dimensionless)"
    legend_constants[17] = "pS6_scalefactor in component pS6_total (dimensionless)"
    legend_rates[0] = "d/dt EGFR in component EGFR (dimensionless)"
    legend_rates[1] = "d/dt EGF_EGFR in component EGF_EGFR (dimensionless)"
    legend_rates[2] = "d/dt pEGFR in component pEGFR (dimensionless)"
    legend_rates[3] = "d/dt pEGFR_Akt in component pEGFR_Akt (dimensionless)"
    legend_rates[4] = "d/dt Akt in component Akt (dimensionless)"
    legend_rates[5] = "d/dt pAkt in component pAkt (dimensionless)"
    legend_rates[7] = "d/dt pAkt_S6 in component pAkt_S6 (dimensionless)"
    legend_rates[6] = "d/dt S6 in component S6 (dimensionless)"
    legend_rates[8] = "d/dt pS6 in component pS6 (dimensionless)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    constants[0] = 30.0
    constants[1] = 6.81902e4
    states[0] = 6.81902e4
    states[1] = 0.0
    constants[2] = 4.07490e-2
    constants[3] = 6.73816e-3
    constants[4] = 1.06386129269658e-4
    constants[5] = 1.92391e-2
    states[2] = 0.0
    states[3] = 0.0
    states[4] = 4.33090e-2
    constants[6] = 9.97194e-2
    constants[7] = 3.05684e-2
    constants[8] = 1.55430e-5
    constants[9] = 5.17473e-3
    states[5] = 0.0
    constants[10] = 3.27962e-2
    states[6] = 3.54317e0
    states[7] = 0.0
    constants[11] = 2.10189e-6
    constants[12] = 5.17940e-15
    constants[13] = 1.21498e-3
    states[8] = 0.0
    constants[14] = 1.13102e-3
    constants[15] = 1.81735e-4
    constants[16] = 6.00588e1
    constants[17] = 4.98862e4
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    rates[0] = (constants[2]*states[1]+constants[4]*(constants[1]-states[0]))-constants[3]*constants[0]*states[0]
    rates[1] = constants[3]*constants[0]*states[0]-(constants[2]*states[1]+constants[5]*states[1])
    rates[2] = (constants[5]*states[1]+constants[7]*states[3]+constants[9]*states[3])-(constants[6]*states[2]+constants[8]*states[2]*states[4])
    rates[3] = constants[8]*states[2]*states[4]-(constants[9]*states[3]+constants[7]*states[3])
    rates[4] = (constants[9]*states[3]+constants[10]*states[5])-constants[8]*states[2]*states[4]
    rates[5] = (constants[7]*states[3]+constants[12]*states[7]+constants[13]*states[7])-(constants[10]*states[5]+constants[11]*states[5]*states[6])
    rates[7] = constants[11]*states[5]*states[6]-(constants[12]*states[7]+constants[13]*states[7])
    rates[6] = (constants[12]*states[7]+constants[14]*states[8])-constants[11]*states[5]*states[6]
    rates[8] = constants[13]*states[7]-constants[14]*states[8]
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[0] = (states[2]+states[3])*constants[15]
    algebraic[1] = (states[5]+states[7])*constants[16]
    algebraic[2] = states[8]*constants[17]
    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)