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 = 4
sizeConstants = 26
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] = "R_des in component R_des (micromolar)"
    legend_constants[24] = "K_plus in component model_parameters (per_micromolar_per_second)"
    legend_states[1] = "C_cyto in component C_cyto (micromolar)"
    legend_constants[0] = "n_i in component model_parameters (dimensionless)"
    legend_constants[1] = "K_act in component model_parameters (micromolar)"
    legend_constants[2] = "n_a in component model_parameters (dimensionless)"
    legend_constants[3] = "K_minus in component model_parameters (per_second)"
    legend_constants[4] = "K_1 in component model_parameters (per_second)"
    legend_constants[5] = "b in component model_parameters (per_second)"
    legend_algebraic[2] = "I_ra in component I_ra (micromolar)"
    legend_constants[6] = "Ca_tot in component model_parameters (micromolar)"
    legend_constants[7] = "alpha in component model_parameters (dimensionless)"
    legend_constants[8] = "V_MP in component model_parameters (micromolar_per_second)"
    legend_constants[9] = "n_p in component model_parameters (dimensionless)"
    legend_constants[10] = "K_p in component model_parameters (micromolar)"
    legend_algebraic[0] = "I_rable in component I_rable (micromolar)"
    legend_states[2] = "IP3 in component IP3 (micromolar)"
    legend_constants[11] = "K_IP in component model_parameters (micromolar)"
    legend_constants[25] = "V_PLC in component V_PLC (micromolar)"
    legend_algebraic[1] = "V_3K in component V_3K (micromolar)"
    legend_algebraic[3] = "V_5P in component V_5P (micromolar)"
    legend_constants[12] = "V_plc in component model_parameters (micromolar_per_second)"
    legend_constants[13] = "gamma in component model_parameters (dimensionless)"
    legend_constants[14] = "V_k in component model_parameters (micromolar_per_second)"
    legend_constants[15] = "K_k in component model_parameters (micromolar)"
    legend_constants[16] = "n_d in component model_parameters (dimensionless)"
    legend_constants[17] = "K_d in component model_parameters (micromolar)"
    legend_states[3] = "IP4 in component IP4 (micromolar)"
    legend_constants[18] = "V_p1 in component model_parameters (micromolar_per_second)"
    legend_constants[19] = "K_p1 in component model_parameters (micromolar)"
    legend_constants[20] = "K_p2 in component model_parameters (micromolar)"
    legend_algebraic[4] = "V_15P in component V_15P (micromolar)"
    legend_constants[21] = "k in component model_parameters (per_second)"
    legend_constants[22] = "V_p2 in component model_parameters (micromolar_per_second)"
    legend_constants[23] = "K_inh in component model_parameters (micromolar)"
    legend_rates[0] = "d/dt R_des in component R_des (micromolar)"
    legend_rates[1] = "d/dt C_cyto in component C_cyto (micromolar)"
    legend_rates[2] = "d/dt IP3 in component IP3 (micromolar)"
    legend_rates[3] = "d/dt IP4 in component IP4 (micromolar)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    states[0] = 0.1
    states[1] = 0.1
    constants[0] = 4
    constants[1] = 0.56
    constants[2] = 3
    constants[3] = 0.5
    constants[4] = 2.57
    constants[5] = 7e-4
    constants[6] = 80
    constants[7] = 0.1
    constants[8] = 4
    constants[9] = 2
    constants[10] = 0.35
    states[2] = 0.1
    constants[11] = 1
    constants[12] = 1.3
    constants[13] = 0.2
    constants[14] = 0.5
    constants[15] = 1
    constants[16] = 2
    constants[17] = 0.3
    states[3] = 0.1
    constants[18] = 5
    constants[19] = 10
    constants[20] = 2
    constants[21] = 0.01
    constants[22] = 0.2
    constants[23] = 0.15
    constants[24] = constants[3]/(power(constants[23], constants[0]))
    constants[25] = constants[13]*constants[12]*1.00000
    return (states, constants)

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

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[0] = ((1.00000-states[0])*states[2])/(constants[11]+states[2])
    algebraic[2] = (algebraic[0]*1.00000)/(1.00000+power(constants[1]/states[1], constants[2]))
    algebraic[1] = constants[14]*(states[2]/(constants[15]+states[2]))*((power(states[1], constants[16]))/(power(constants[17], constants[16])+power(states[1], constants[16])))*1.00000
    algebraic[3] = constants[18]*1.00000*(states[2]/(constants[19]*(1.00000+states[3]/constants[20])+states[2]))
    algebraic[4] = (constants[22]*1.00000*states[3])/(constants[20]*(1.00000+states[2]/constants[19])+states[3])
    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)