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 = 11 sizeConstants = 21 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] = "inhibitor in component inhibitor (dimensionless)" legend_constants[2] = "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_states[2] = "EGFR_i in component EGFR_i (dimensionless)" legend_constants[3] = "EGF_binding_kb in component model_parameters (first_order_rate_constant)" legend_constants[4] = "EGF_binding_kf in component model_parameters (first_order_rate_constant)" legend_constants[5] = "inhibitor_binding_kb in component model_parameters (first_order_rate_constant)" legend_constants[6] = "inhibitor_binding_kf in component model_parameters (first_order_rate_constant)" legend_constants[7] = "EGFR_turnover in component model_parameters (first_order_rate_constant)" legend_states[3] = "EGF_EGFR_i in component EGF_EGFR_i (dimensionless)" legend_constants[8] = "k1_EGFR_phosphorylation in component model_parameters (first_order_rate_constant)" legend_states[4] = "pEGFR in component pEGFR (dimensionless)" legend_states[5] = "pEGFR_Akt in component pEGFR_Akt (dimensionless)" legend_states[6] = "Akt in component Akt (dimensionless)" legend_constants[9] = "k1_pEGFR_degradation in component model_parameters (first_order_rate_constant)" legend_constants[10] = "k1_Akt_phosphorylation in component model_parameters (first_order_rate_constant)" legend_constants[11] = "k1_pEGFR_Akt in component model_parameters (first_order_rate_constant)" legend_constants[12] = "k2_pEGFR_Akt in component model_parameters (first_order_rate_constant)" legend_states[7] = "pAkt in component pAkt (dimensionless)" legend_constants[13] = "k1_pAkt_dephosphorylation in component model_parameters (first_order_rate_constant)" legend_states[8] = "S6 in component S6 (dimensionless)" legend_states[9] = "pAkt_S6 in component pAkt_S6 (dimensionless)" legend_constants[14] = "k1_pAkt_S6 in component model_parameters (first_order_rate_constant)" legend_constants[15] = "k2_pAkt_S6 in component model_parameters (first_order_rate_constant)" legend_constants[16] = "k1_S6_phosphorylation in component model_parameters (first_order_rate_constant)" legend_states[10] = "pS6 in component pS6 (dimensionless)" legend_constants[17] = "k1_pS6_dephosphorylation in component model_parameters (first_order_rate_constant)" legend_algebraic[0] = "pEGFR_total in component pEGFR_total (dimensionless)" legend_constants[18] = "pEGFR_scalefactor in component pEGFR_total (dimensionless)" legend_algebraic[1] = "pAkt_total in component pAkt_total (dimensionless)" legend_constants[19] = "pAkt_scalefactor in component pAkt_total (dimensionless)" legend_algebraic[2] = "pS6_total in component pS6_total (dimensionless)" legend_constants[20] = "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 EGFR_i in component EGFR_i (dimensionless)" legend_rates[3] = "d/dt EGF_EGFR_i in component EGF_EGFR_i (dimensionless)" legend_rates[4] = "d/dt pEGFR in component pEGFR (dimensionless)" legend_rates[5] = "d/dt pEGFR_Akt in component pEGFR_Akt (dimensionless)" legend_rates[6] = "d/dt Akt in component Akt (dimensionless)" legend_rates[7] = "d/dt pAkt in component pAkt (dimensionless)" legend_rates[9] = "d/dt pAkt_S6 in component pAkt_S6 (dimensionless)" legend_rates[8] = "d/dt S6 in component S6 (dimensionless)" legend_rates[10] = "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] = 15.0 constants[2] = 6.81902e-4 states[0] = 68190.000000002 states[1] = 0.0 states[2] = 0.0 constants[3] = 4.07490e-2 constants[4] = 6.73816e-3 constants[5] = 5.25097e-5 constants[6] = 2.434663e-5 constants[7] = 1.06386129269658e-4 states[3] = 0.0 constants[8] = 1.92391e-2 states[4] = 0.0 states[5] = 0.0 states[6] = 4.33090e-2 constants[9] = 9.97194e-2 constants[10] = 3.05684e-2 constants[11] = 1.55430e-5 constants[12] = 5.17473e-3 states[7] = 0.0 constants[13] = 3.27962e-2 states[8] = 3.54317e0 states[9] = 0.0 constants[14] = 2.10189e-6 constants[15] = 5.17940e-15 constants[16] = 1.21498e-3 states[10] = 0.0 constants[17] = 1.13102e-3 constants[18] = 1.81735e-4 constants[19] = 6.00588e1 constants[20] = 4.98862e4 return (states, constants) def computeRates(voi, states, constants): rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic rates[0] = (constants[3]*states[1]+constants[5]*states[2]+constants[7]*(constants[2]-states[0]))-(constants[4]*constants[0]*states[0]+constants[6]*constants[1]*states[0]) rates[1] = (constants[4]*constants[0]*states[0]+constants[5]*states[3])-(constants[3]*states[1]+constants[6]*constants[1]*states[1]+constants[8]*states[1]) rates[2] = (constants[3]*states[3]+constants[6]*constants[1]*states[0])-(constants[4]*constants[0]*states[2]+constants[5]*states[2]+constants[7]*states[2]) rates[3] = (constants[4]*constants[0]*states[2]+constants[6]*constants[1]*states[1])-(constants[3]*states[3]+constants[5]*states[3]) rates[4] = (constants[8]*states[1]+constants[10]*states[5]+constants[12]*states[5])-(constants[9]*states[4]+constants[11]*states[4]*states[6]) rates[5] = constants[11]*states[4]*states[6]-(constants[12]*states[5]+constants[10]*states[5]) rates[6] = (constants[12]*states[5]+constants[13]*states[7])-constants[11]*states[4]*states[6] rates[7] = (constants[10]*states[5]+constants[15]*states[9]+constants[16]*states[9])-(constants[13]*states[7]+constants[14]*states[7]*states[8]) rates[9] = constants[14]*states[7]*states[8]-(constants[15]*states[9]+constants[16]*states[9]) rates[8] = (constants[15]*states[9]+constants[17]*states[10])-constants[14]*states[7]*states[8] rates[10] = constants[16]*states[9]-constants[17]*states[10] return(rates) def computeAlgebraic(constants, states, voi): algebraic = array([[0.0] * len(voi)] * sizeAlgebraic) states = array(states) voi = array(voi) algebraic[0] = (states[4]+states[5])*constants[18] algebraic[1] = (states[7]+states[9])*constants[19] algebraic[2] = states[10]*constants[20] 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)