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 = 5
sizeStates = 13
sizeConstants = 45
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 (minute)"
legend_states[0] = "r in component r (dimensionless)"
legend_algebraic[0] = "c1 in component c1 (dimensionless)"
legend_states[1] = "c2 in component c2 (dimensionless)"
legend_constants[0] = "L in component model_parameters (nanomolar)"
legend_constants[1] = "kt in component model_parameters (first_order_rate_constant)"
legend_constants[2] = "kxR0 in component model_parameters (first_order_rate_constant)"
legend_constants[3] = "k_minusx in component model_parameters (first_order_rate_constant)"
legend_constants[4] = "KDL in component model_parameters (nanomolar)"
legend_constants[5] = "ke in component model_parameters (first_order_rate_constant)"
legend_algebraic[1] = "e_PI3K in component e_PI3K (dimensionless)"
legend_constants[6] = "kappa_PI3K in component e_PI3K (dimensionless)"
legend_constants[7] = "alpha_PI3K in component e_PI3K (dimensionless)"
legend_states[2] = "m_3PI in component m_3PI (dimensionless)"
legend_constants[8] = "k_3PI in component m_3PI (first_order_rate_constant)"
legend_algebraic[2] = "e_GEF in component e_GEF (dimensionless)"
legend_constants[9] = "K_GR in component e_GEF (dimensionless)"
legend_constants[10] = "K_GP in component e_GEF (dimensionless)"
legend_states[3] = "f_GEF in component f_GEF (dimensionless)"
legend_states[4] = "m_Ras in component m_Ras (dimensionless)"
legend_constants[11] = "k_Ras in component m_Ras (first_order_rate_constant)"
legend_constants[12] = "gamma in component m_Ras (dimensionless)"
legend_states[5] = "x1 in component x1 (dimensionless)"
legend_constants[13] = "kd_x1 in component x1 (first_order_rate_constant)"
legend_constants[14] = "KM_x11 in component model_parameters (dimensionless)"
legend_constants[15] = "KM_x12 in component model_parameters (dimensionless)"
legend_states[6] = "y in component y (dimensionless)"
legend_algebraic[3] = "yp in component yp (dimensionless)"
legend_states[7] = "x2 in component x2 (dimensionless)"
legend_constants[16] = "kd_x2 in component x2 (first_order_rate_constant)"
legend_constants[17] = "K_x2 in component x2 (dimensionless)"
legend_constants[18] = "KM_x21 in component model_parameters (dimensionless)"
legend_constants[19] = "KM_x22 in component model_parameters (dimensionless)"
legend_constants[20] = "Vmax_yph1_KM_yph1 in component y (first_order_rate_constant)"
legend_constants[21] = "KM_yph1 in component model_parameters (dimensionless)"
legend_constants[22] = "KM_yph2 in component model_parameters (dimensionless)"
legend_constants[23] = "Vmax_x11_KM_x11 in component model_parameters (first_order_rate_constant)"
legend_constants[24] = "Vmax_x21_KM_x21 in component model_parameters (first_order_rate_constant)"
legend_states[8] = "ypp in component ypp (dimensionless)"
legend_constants[25] = "Vmax_yph2_KM_yph2 in component ypp (first_order_rate_constant)"
legend_constants[26] = "KM_y1 in component model_parameters (dimensionless)"
legend_constants[27] = "KM_y2 in component model_parameters (dimensionless)"
legend_constants[28] = "Vmax_x12_KM_x12 in component model_parameters (first_order_rate_constant)"
legend_constants[29] = "Vmax_x22_KM_x22 in component model_parameters (first_order_rate_constant)"
legend_states[9] = "z in component z (dimensionless)"
legend_algebraic[4] = "zp in component zp (dimensionless)"
legend_constants[30] = "Vmax_zph1_KM_zph1 in component z (first_order_rate_constant)"
legend_constants[31] = "Vmax_y1_KM_y1 in component z (first_order_rate_constant)"
legend_constants[32] = "KM_zph1 in component model_parameters (dimensionless)"
legend_constants[33] = "KM_zph2 in component model_parameters (dimensionless)"
legend_states[10] = "zpp in component zpp (dimensionless)"
legend_states[11] = "e_ph in component e_ph (dimensionless)"
legend_constants[34] = "Vmax_zph2_KM_zph2 in component zpp (first_order_rate_constant)"
legend_constants[35] = "Vmax_y2_KM_y2 in component zpp (first_order_rate_constant)"
legend_constants[36] = "n in component f_GEF (dimensionless)"
legend_constants[37] = "Kf in component f_GEF (dimensionless)"
legend_constants[38] = "Zf in component f_GEF (dimensionless)"
legend_constants[39] = "k_FB_f in component f_GEF (first_order_rate_constant)"
legend_states[12] = "w in component w (dimensionless)"
legend_constants[40] = "kd_w in component w (first_order_rate_constant)"
legend_constants[41] = "k_FB_ph in component e_ph (first_order_rate_constant)"
legend_constants[42] = "p in component e_ph (dimensionless)"
legend_constants[43] = "Wph in component e_ph (dimensionless)"
legend_constants[44] = "Kph in component e_ph (dimensionless)"
legend_rates[0] = "d/dt r in component r (dimensionless)"
legend_rates[1] = "d/dt c2 in component c2 (dimensionless)"
legend_rates[2] = "d/dt m_3PI in component m_3PI (dimensionless)"
legend_rates[4] = "d/dt m_Ras in component m_Ras (dimensionless)"
legend_rates[5] = "d/dt x1 in component x1 (dimensionless)"
legend_rates[7] = "d/dt x2 in component x2 (dimensionless)"
legend_rates[6] = "d/dt y in component y (dimensionless)"
legend_rates[8] = "d/dt ypp in component ypp (dimensionless)"
legend_rates[9] = "d/dt z in component z (dimensionless)"
legend_rates[10] = "d/dt zpp in component zpp (dimensionless)"
legend_rates[3] = "d/dt f_GEF in component f_GEF (dimensionless)"
legend_rates[12] = "d/dt w in component w (dimensionless)"
legend_rates[11] = "d/dt e_ph in component e_ph (dimensionless)"
return (legend_states, legend_algebraic, legend_voi, legend_constants)
def initConsts():
constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
states[0] = 0.5
states[1] = 0.0
constants[0] = 1.0
constants[1] = 0.005
constants[2] = 0.3
constants[3] = 0.07
constants[4] = 1.5
constants[5] = 0.2
constants[6] = 0.3
constants[7] = 80.0
states[2] = 0.0
constants[8] = 1.0
constants[9] = 495.0
constants[10] = 5.09
states[3] = 1.0
states[4] = 0.0
constants[11] = 1.0
constants[12] = 0.1
states[5] = 0.0
constants[13] = 0.745
constants[14] = 30.3
constants[15] = 45.5
states[6] = 1.0
states[7] = 0.0
constants[16] = 2.85
constants[17] = 6.77
constants[18] = 21.6
constants[19] = 15.7
constants[20] = 4.40
constants[21] = 44.0
constants[22] = 12.7
constants[23] = 1.18
constants[24] = 0.405
states[8] = 0.0
constants[25] = 6.77
constants[26] = 31.9
constants[27] = 8.81
constants[28] = 4.71
constants[29] = 2.41
states[9] = 1.0
constants[30] = 0.451
constants[31] = 11.8
constants[32] = 14.0
constants[33] = 31.5
states[10] = 0.0
states[11] = 1.0
constants[34] = 0.228
constants[35] = 31.9
constants[36] = 1.03
constants[37] = 3.76
constants[38] = 0.272
constants[39] = 0.976
states[12] = 0.0
constants[40] = 0.0333
constants[41] = 2.34
constants[42] = 1.98
constants[43] = 0.385
constants[44] = 4.64
return (states, constants)
def computeRates(voi, states, constants):
rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
rates[3] = -constants[39]*(((power(states[10], constants[36]))/(power(constants[38], constants[36])+power(states[10], constants[36])))*states[3]-(1.00000/constants[37])*(1.00000-states[3]))
rates[12] = constants[40]*(states[10]-states[12])
rates[11] = constants[41]*((power(states[12], constants[42]))/(power(constants[43], constants[42])+power(states[12], constants[42]))-(1.00000/constants[44])*(states[11]-1.00000))
algebraic[0] = (constants[0]*states[0])/constants[4]
rates[0] = (power(1.00000+constants[0]/constants[4], -1.00000))*(constants[1]*(1.00000-(states[0]+algebraic[0]))+2.00000*(constants[3]*states[1]-constants[2]*(power(algebraic[0], 2.00000))))
rates[1] = constants[2]*(power(algebraic[0], 2.00000))-(constants[3]+constants[5])*states[1]
algebraic[1] = ((1.00000+constants[6]+2.00000*constants[7]*states[1])-power(power(1.00000+constants[6]+2.00000*constants[7]*states[1], 2.00000), 1.0/2))/2.00000
rates[2] = constants[8]*(algebraic[1]-states[2])
algebraic[2] = ((constants[9]*states[1]+constants[10]*states[2])/(1.00000+constants[9]*states[1]+constants[10]*states[2]))*states[3]
rates[4] = constants[11]*((1.00000+constants[12])*algebraic[2]-(1.00000+constants[12]*algebraic[2])*states[4])
algebraic[3] = 1.00000-(states[6]+states[8])
rates[5] = constants[13]*(states[4]-states[5]/(1.00000+states[6]/constants[14]+algebraic[3]/constants[15]))
rates[7] = constants[16]*(((1.00000+constants[17])*states[2])/(1.00000+constants[17]*states[2])-states[7]/(1.00000+states[6]/constants[18]+algebraic[3]/constants[19]))
rates[6] = (constants[20]*algebraic[3])/(1.00000+algebraic[3]/constants[21]+states[8]/constants[22])-((constants[23]*states[5]*states[6])/(1.00000+states[6]/constants[14]+algebraic[3]/constants[15])+(constants[24]*states[7]*states[6])/(1.00000+states[6]/constants[18]+algebraic[3]/constants[19]))
algebraic[4] = 1.00000-(states[9]+states[10])
rates[8] = ((constants[28]*states[5]*algebraic[3])/(1.00000+states[6]/constants[14]+algebraic[3]/constants[15])+(constants[29]*states[7]*algebraic[3])/(1.00000+states[6]/constants[18]+algebraic[3]/constants[19]))-((constants[25]*states[8])/((1.00000+states[9]/constants[26]+algebraic[4]/constants[15])*(1.00000+algebraic[3]/constants[21])+states[8]/constants[22]))
rates[9] = (constants[30]*states[11]*algebraic[4])/(1.00000+algebraic[4]/constants[32]+states[10]/constants[33])-(constants[31]*states[8])/(1.00000+states[9]/constants[26]+algebraic[4]/constants[27])
rates[10] = (constants[35]*algebraic[4])/(1.00000+states[9]/constants[26]+algebraic[4]/constants[27])-(constants[34]*states[11]*states[10])/(1.00000+algebraic[4]/constants[32]+states[10]/constants[33])
return(rates)
def computeAlgebraic(constants, states, voi):
algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
states = array(states)
voi = array(voi)
algebraic[0] = (constants[0]*states[0])/constants[4]
algebraic[1] = ((1.00000+constants[6]+2.00000*constants[7]*states[1])-power(power(1.00000+constants[6]+2.00000*constants[7]*states[1], 2.00000), 1.0/2))/2.00000
algebraic[2] = ((constants[9]*states[1]+constants[10]*states[2])/(1.00000+constants[9]*states[1]+constants[10]*states[2]))*states[3]
algebraic[3] = 1.00000-(states[6]+states[8])
algebraic[4] = 1.00000-(states[9]+states[10])
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)
