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 = 56
sizeStates = 14
sizeConstants = 43
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 (millisecond)"
    legend_states[0] = "Vm_n in component Vm_n (millivolt)"
    legend_algebraic[0] = "i_app in component Vm_n (nanoA_per_cm2)"
    legend_constants[0] = "Cm in component Vm_n (microF_per_cm2)"
    legend_constants[1] = "t0 in component Vm_n (millisecond)"
    legend_constants[2] = "t1 in component Vm_n (millisecond)"
    legend_algebraic[36] = "i_NaT in component i_NaT (nanoA_per_cm2)"
    legend_algebraic[38] = "i_NaP in component i_NaP (nanoA_per_cm2)"
    legend_algebraic[40] = "i_leakNa in component i_leakNa (nanoA_per_cm2)"
    legend_algebraic[25] = "i_KDR in component i_KDR (nanoA_per_cm2)"
    legend_algebraic[26] = "i_KA in component i_KA (nanoA_per_cm2)"
    legend_algebraic[27] = "i_leakK in component i_leakK (nanoA_per_cm2)"
    legend_algebraic[8] = "i_leakf in component i_leakf (nanoA_per_cm2)"
    legend_algebraic[34] = "i_NaKATPase_n in component i_NaKATPase_n (nanoA_per_cm2)"
    legend_algebraic[37] = "J_NaT in component i_NaT (picomole_per_cm2_millisecond)"
    legend_constants[3] = "gNaT in component i_NaT (microS_per_cm2)"
    legend_constants[4] = "F in component model_parameters (coulomb_per_mole)"
    legend_algebraic[35] = "ENa_n in component electric_potentials (millivolt)"
    legend_states[1] = "m in component i_NaT_m_gate (dimensionless)"
    legend_states[2] = "h in component i_NaT_h_gate (dimensionless)"
    legend_algebraic[1] = "alpha_m in component i_NaT_m_gate (per_millisecond)"
    legend_algebraic[9] = "beta_m in component i_NaT_m_gate (per_millisecond)"
    legend_algebraic[2] = "alpha_h in component i_NaT_h_gate (per_millisecond)"
    legend_algebraic[10] = "beta_h in component i_NaT_h_gate (per_millisecond)"
    legend_algebraic[39] = "J_NaP in component i_NaP (picomole_per_cm2_millisecond)"
    legend_constants[5] = "gNaP in component i_NaP (microS_per_cm2)"
    legend_states[3] = "m in component i_NaP_m_gate (dimensionless)"
    legend_states[4] = "h in component i_NaP_h_gate (dimensionless)"
    legend_algebraic[3] = "alpha_m in component i_NaP_m_gate (per_millisecond)"
    legend_algebraic[11] = "beta_m in component i_NaP_m_gate (per_millisecond)"
    legend_constants[6] = "tau_activation in component i_NaP_m_gate (millisecond)"
    legend_algebraic[4] = "alpha_h in component i_NaP_h_gate (per_millisecond)"
    legend_algebraic[12] = "beta_h in component i_NaP_h_gate (per_millisecond)"
    legend_algebraic[22] = "J_KDR in component i_KDR (picomole_per_cm2_millisecond)"
    legend_constants[7] = "gKDR in component i_KDR (microS_per_cm2)"
    legend_algebraic[21] = "EK_n in component electric_potentials (millivolt)"
    legend_states[5] = "n in component i_KDR_n_gate (dimensionless)"
    legend_algebraic[5] = "alpha_n in component i_KDR_n_gate (per_millisecond)"
    legend_algebraic[13] = "beta_n in component i_KDR_n_gate (per_millisecond)"
    legend_algebraic[23] = "J_KA in component i_KA (picomole_per_cm2_millisecond)"
    legend_constants[8] = "gKA in component i_KA (microS_per_cm2)"
    legend_states[6] = "m in component i_KA_m_gate (dimensionless)"
    legend_states[7] = "h in component i_KA_h_gate (dimensionless)"
    legend_algebraic[6] = "alpha_m in component i_KA_m_gate (per_millisecond)"
    legend_algebraic[14] = "beta_m in component i_KA_m_gate (per_millisecond)"
    legend_algebraic[7] = "alpha_h in component i_KA_h_gate (per_millisecond)"
    legend_algebraic[15] = "beta_h in component i_KA_h_gate (per_millisecond)"
    legend_algebraic[33] = "J_NaKATPase_n in component i_NaKATPase_n (picomole_per_cm2_millisecond)"
    legend_constants[9] = "I_NaKATPase_n_max in component i_NaKATPase_n (picomole_per_cm2_millisecond)"
    legend_constants[10] = "KmNa in component model_parameters (millimolar)"
    legend_constants[11] = "KmK in component model_parameters (millimolar)"
    legend_algebraic[32] = "Nan in component ion_concentrations (millimolar)"
    legend_algebraic[18] = "Ko in component ion_concentrations (millimolar)"
    legend_algebraic[41] = "J_leakNa in component i_leakNa (picomole_per_cm2_millisecond)"
    legend_constants[12] = "gleakNa in component i_leakNa (microS_per_cm2)"
    legend_algebraic[24] = "J_leakK in component i_leakK (picomole_per_cm2_millisecond)"
    legend_constants[13] = "gleakK in component i_leakK (microS_per_cm2)"
    legend_constants[14] = "gleakf in component i_leakf (microS_per_cm2)"
    legend_constants[15] = "Ef_n in component electric_potentials (millivolt)"
    legend_algebraic[50] = "Vm_g in component Vm_g (millivolt)"
    legend_algebraic[31] = "ENa_g in component electric_potentials (millivolt)"
    legend_algebraic[19] = "EK_g in component electric_potentials (millivolt)"
    legend_algebraic[49] = "ECl_g in component electric_potentials (millivolt)"
    legend_algebraic[45] = "ENBC_g in component electric_potentials (millivolt)"
    legend_constants[16] = "gNa in component J_Na (microS_per_cm2)"
    legend_constants[17] = "gK in component J_K (microS_per_cm2)"
    legend_constants[18] = "gCl in component model_parameters (microS_per_cm2)"
    legend_constants[19] = "gNBC in component J_NBC (microS_per_cm2)"
    legend_algebraic[29] = "J_NaKATPase_g in component J_NaKATPase_g (picomole_per_cm2_millisecond)"
    legend_algebraic[51] = "J_Na in component J_Na (picomole_per_cm2_millisecond)"
    legend_algebraic[52] = "J_K in component J_K (picomole_per_cm2_millisecond)"
    legend_constants[20] = "I_NaKATPase_g_max in component J_NaKATPase_g (picomole_per_cm2_millisecond)"
    legend_algebraic[28] = "Nag in component ion_concentrations (millimolar)"
    legend_algebraic[53] = "J_NBC in component J_NBC (picomole_per_cm2_millisecond)"
    legend_algebraic[48] = "J_NKCC1 in component J_NKCC1 (picomole_per_cm2_millisecond)"
    legend_constants[21] = "gNKCC1 in component J_NKCC1 (microS_per_cm2)"
    legend_constants[40] = "Psi in component model_parameters (millivolt)"
    legend_algebraic[30] = "Nao in component ion_concentrations (millimolar)"
    legend_constants[22] = "P_Ko in component ion_concentrations (millimolar)"
    legend_algebraic[17] = "Kg in component ion_concentrations (millimolar)"
    legend_algebraic[47] = "Clo in component ion_concentrations (millimolar)"
    legend_algebraic[46] = "Clg in component ion_concentrations (millimolar)"
    legend_states[8] = "N_Nag in component N_Nag (nanomole_per_cm2)"
    legend_algebraic[55] = "dN_Nag_dt in component N_Nag (nanomole_per_cm2_millisecond)"
    legend_states[9] = "N_Kg in component N_Kg (nanomole_per_cm2)"
    legend_algebraic[54] = "dN_Kg_dt in component N_Kg (nanomole_per_cm2_millisecond)"
    legend_states[10] = "wg in component wg (micrometre)"
    legend_constants[23] = "Lp in component model_parameters (cm_per_second_millimolar)"
    legend_constants[24] = "Xg in component model_parameters (millimolar_micrometre)"
    legend_algebraic[43] = "HCO3o in component ion_concentrations (millimolar)"
    legend_algebraic[44] = "HCO3g in component ion_concentrations (millimolar)"
    legend_algebraic[16] = "wo in component wo (micrometre)"
    legend_constants[25] = "P_wo in component model_parameters (micrometre)"
    legend_constants[26] = "P_wg in component model_parameters (micrometre)"
    legend_states[11] = "N_Nao in component N_Nao (nanomole_per_cm2)"
    legend_states[12] = "N_Ko in component N_Ko (nanomole_per_cm2)"
    legend_states[13] = "N_HCO3o in component N_HCO3o (nanomole_per_cm2)"
    legend_algebraic[20] = "Kn in component ion_concentrations (millimolar)"
    legend_algebraic[42] = "Cln in component ion_concentrations (millimolar)"
    legend_constants[27] = "P_Vm_g in component ion_concentrations (millivolt)"
    legend_constants[39] = "P_Clo in component ion_concentrations (millimolar)"
    legend_constants[28] = "P_Cln in component ion_concentrations (millimolar)"
    legend_constants[41] = "P_Clg in component ion_concentrations (millimolar)"
    legend_constants[29] = "P_Nan in component ion_concentrations (millimolar)"
    legend_constants[30] = "P_Nao in component ion_concentrations (millimolar)"
    legend_constants[31] = "P_Nag in component ion_concentrations (millimolar)"
    legend_constants[32] = "P_Kn in component ion_concentrations (millimolar)"
    legend_constants[33] = "P_Kg in component ion_concentrations (millimolar)"
    legend_constants[42] = "P_HCO3g in component ion_concentrations (millimolar)"
    legend_constants[34] = "P_HCO3o in component ion_concentrations (millimolar)"
    legend_constants[35] = "P_wn in component ion_concentrations (micrometre)"
    legend_constants[36] = "rho in component model_parameters (dimensionless)"
    legend_constants[37] = "R in component model_parameters (joule_per_mole_kelvin)"
    legend_constants[38] = "T in component model_parameters (kelvin)"
    legend_rates[0] = "d/dt Vm_n in component Vm_n (millivolt)"
    legend_rates[1] = "d/dt m in component i_NaT_m_gate (dimensionless)"
    legend_rates[2] = "d/dt h in component i_NaT_h_gate (dimensionless)"
    legend_rates[3] = "d/dt m in component i_NaP_m_gate (dimensionless)"
    legend_rates[4] = "d/dt h in component i_NaP_h_gate (dimensionless)"
    legend_rates[5] = "d/dt n in component i_KDR_n_gate (dimensionless)"
    legend_rates[6] = "d/dt m in component i_KA_m_gate (dimensionless)"
    legend_rates[7] = "d/dt h in component i_KA_h_gate (dimensionless)"
    legend_rates[8] = "d/dt N_Nag in component N_Nag (nanomole_per_cm2)"
    legend_rates[9] = "d/dt N_Kg in component N_Kg (nanomole_per_cm2)"
    legend_rates[10] = "d/dt wg in component wg (micrometre)"
    legend_rates[11] = "d/dt N_Nao in component N_Nao (nanomole_per_cm2)"
    legend_rates[12] = "d/dt N_Ko in component N_Ko (nanomole_per_cm2)"
    legend_rates[13] = "d/dt N_HCO3o in component N_HCO3o (nanomole_per_cm2)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    states[0] = -70
    constants[0] = 1
    constants[1] = 100
    constants[2] = 700
    constants[3] = 5000
    constants[4] = 9.649e4
    states[1] = 0.005
    states[2] = 0.9961
    constants[5] = 150
    states[3] = 0.0129
    states[4] = 0.9718
    constants[6] = 6
    constants[7] = 5000
    states[5] = 0.0012
    constants[8] = 1000
    states[6] = 0.1193
    states[7] = 0.1205
    constants[9] = 0.0289
    constants[10] = 10
    constants[11] = 1.5
    constants[12] = 20
    constants[13] = 66.06
    constants[14] = 10
    constants[15] = -70
    constants[16] = 100.0
    constants[17] = 1696.0
    constants[18] = 50
    constants[19] = 80
    constants[20] = 0.1151
    constants[21] = 2
    constants[22] = 3
    states[8] = 0.75
    states[9] = 5
    states[10] = 0.05
    constants[23] = 2e-8
    constants[24] = 8.45
    constants[25] = 0.025
    constants[26] = 0.05
    states[11] = 3.65
    states[12] = 0.075
    states[13] = 0.375
    constants[27] = -85
    constants[28] = 50
    constants[29] = 10
    constants[30] = 146
    constants[31] = 15
    constants[32] = 130
    constants[33] = 100
    constants[34] = 15
    constants[35] = 0.05
    constants[36] = 0.5975
    constants[37] = 8.315
    constants[38] = 300
    constants[39] = (constants[30]+constants[22])-constants[34]
    constants[40] = (1000.00*constants[37]*constants[38])/constants[4]
    constants[41] = constants[39]*exp(constants[27]/constants[40])
    constants[42] = constants[34]*(power((constants[30]/constants[31])*exp(constants[27]/constants[40]), 1.0/2))
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    algebraic[1] = (0.320000*(-states[0]-51.9000))/(exp(-(0.250000*states[0]+12.9750))-1.00000)
    algebraic[9] = (0.280000*(states[0]+24.8900))/(exp(0.200000*states[0]+4.97800)-1.00000)
    rates[1] = algebraic[1]*(1.00000-states[1])-algebraic[9]*states[1]
    algebraic[2] = 0.128000*exp(-(0.0560000*states[0]+2.94000))
    algebraic[10] = 4.00000/(exp(-(0.200000*states[0]+6.00000))+1.00000)
    rates[2] = algebraic[2]*(1.00000-states[2])-algebraic[10]*states[2]
    algebraic[3] = ((1.00000/constants[6])*1.00000)/(exp(-(0.143000*states[0]+5.67000))+1.00000)
    algebraic[11] = ((1.00000/constants[6])*exp(-(0.143000*states[0]+5.67000)))/(exp(-(0.143000*states[0]+5.67000))+1.00000)
    rates[3] = algebraic[3]*(1.00000-states[3])-algebraic[11]*states[3]
    algebraic[4] = 5.12000e-08*exp(-(0.0560000*states[0]+2.94000))
    algebraic[12] = 1.60000e-06/(exp(-(0.200000*states[0]+8.00000))+1.00000)
    rates[4] = algebraic[4]*(1.00000-states[4])-algebraic[12]*states[4]
    algebraic[5] = (0.0160000*(-states[0]-34.9000))/(exp(-(0.200000*states[0]+6.98000))-1.00000)
    algebraic[13] = 0.250000*exp(-(0.0250000*states[0]+1.25000))
    rates[5] = algebraic[5]*(1.00000-states[5])-algebraic[13]*states[5]
    algebraic[6] = (0.0200000*(-states[0]-56.9000))/(exp(-(0.100000*states[0]+5.69000))-1.00000)
    algebraic[14] = (0.0175000*(states[0]+29.9000))/(exp(0.100000*states[0]+2.99000)-1.00000)
    rates[6] = algebraic[6]*(1.00000-states[6])-algebraic[14]*states[6]
    algebraic[7] = 0.0160000*exp(-(0.0560000*states[0]+4.61000))
    algebraic[15] = 0.500000/(exp(-(0.200000*states[0]+11.9800))+1.00000)
    rates[7] = algebraic[7]*(1.00000-states[7])-algebraic[15]*states[7]
    algebraic[0] = custom_piecewise([greater_equal(voi , constants[1]) & less_equal(voi , constants[2]), 3500.00 , True, 0.00000])
    algebraic[32] = ((constants[35]*constants[29]+constants[26]*constants[31]+constants[25]*constants[30])-(states[11]+states[8]))/constants[35]
    algebraic[16] = (constants[26]+constants[25])-states[10]
    algebraic[30] = states[11]/algebraic[16]
    algebraic[35] = constants[40]*log(algebraic[30]/algebraic[32])
    algebraic[36] = constants[3]*(power(states[1], 3.00000))*states[2]*(states[0]-algebraic[35])
    algebraic[38] = constants[5]*(power(states[3], 2.00000))*states[4]*(states[0]-algebraic[35])
    algebraic[40] = constants[12]*(states[0]-algebraic[35])
    algebraic[18] = states[12]/algebraic[16]
    algebraic[20] = ((constants[35]*constants[32]+constants[26]*constants[33]+constants[25]*constants[22])-(states[12]+states[9]))/constants[35]
    algebraic[21] = constants[40]*log(algebraic[18]/algebraic[20])
    algebraic[25] = constants[7]*(power(states[5], 2.00000))*(states[0]-algebraic[21])
    algebraic[26] = constants[8]*(power(states[6], 2.00000))*states[7]*(states[0]-algebraic[21])
    algebraic[27] = constants[13]*(states[0]-algebraic[21])
    algebraic[8] = constants[14]*(states[0]-constants[15])
    algebraic[33] = (((constants[9]*(power(algebraic[32], 1.50000)))/(power(algebraic[32], 1.50000)+power(constants[10], 1.50000)))*algebraic[18])/(algebraic[18]+constants[11])
    algebraic[34] = algebraic[33]*constants[4]
    rates[0] = (0.00100000*(-(algebraic[36]+algebraic[38]+algebraic[40]+algebraic[25]+algebraic[26]+algebraic[27]+algebraic[8]+algebraic[34])+algebraic[0]))/constants[0]
    algebraic[28] = states[8]/states[10]
    algebraic[17] = states[9]/states[10]
    algebraic[44] = ((constants[26]*constants[42]+constants[25]*constants[34])-states[13])/states[10]
    algebraic[46] = (algebraic[28]+algebraic[17])-(algebraic[44]+(constants[36]*constants[24])/states[10])
    algebraic[42] = ((constants[28]+algebraic[32])-constants[29])+(algebraic[20]-constants[32])
    algebraic[47] = ((constants[26]*constants[41]+constants[25]*constants[39]+constants[35]*constants[28])-(states[10]*algebraic[46]+constants[35]*algebraic[42]))/algebraic[16]
    algebraic[43] = states[13]/algebraic[16]
    rates[10] = 10.0000*constants[23]*((algebraic[28]+algebraic[17]+algebraic[46]+algebraic[44]+constants[24]/states[10])-(algebraic[30]+algebraic[18]+algebraic[47]+algebraic[43]))
    algebraic[29] = (((constants[20]*(power(algebraic[28], 1.50000)))/(power(algebraic[28], 1.50000)+power(constants[10], 1.50000)))*algebraic[18])/(algebraic[18]+constants[11])
    algebraic[31] = constants[40]*log(algebraic[30]/algebraic[28])
    algebraic[19] = constants[40]*log(algebraic[18]/algebraic[17])
    algebraic[49] = -1.00000*constants[40]*log(algebraic[47]/algebraic[46])
    algebraic[45] = -constants[40]*log((algebraic[30]/algebraic[28])*(power(algebraic[43]/algebraic[44], 2.00000)))
    algebraic[50] = (constants[16]*algebraic[31]+constants[17]*algebraic[19]+constants[18]*algebraic[49]+constants[19]*algebraic[45])/(constants[16]+constants[17]+constants[18]+constants[19])-(constants[4]*algebraic[29])/(constants[16]+constants[17]+constants[18]+constants[19])
    algebraic[52] = (constants[17]*(algebraic[50]-algebraic[19]))/constants[4]
    algebraic[48] = custom_piecewise([greater(algebraic[18] , constants[22]), (((power(algebraic[18]-constants[22], 10.0000))/(power(algebraic[18]-constants[22], 10.0000)+power(0.0300000, 10.0000)))*constants[40]*constants[21]*log((((algebraic[18]/algebraic[17])*algebraic[30])/algebraic[28])*(power(algebraic[47]/algebraic[46], 2.00000))))/constants[4] , True, 0.00000])
    algebraic[54] = 0.0100000*(-algebraic[52]+2.00000*algebraic[29]+algebraic[48])
    rates[9] = algebraic[54]
    algebraic[37] = (constants[3]*(power(states[1], 3.00000))*states[2]*(states[0]-algebraic[35]))/constants[4]
    algebraic[39] = (constants[5]*(power(states[3], 2.00000))*states[4]*(states[0]-algebraic[35]))/constants[4]
    algebraic[41] = (constants[12]*(states[0]-algebraic[35]))/constants[4]
    rates[12] = -0.0100000*(algebraic[37]+algebraic[39]+algebraic[41]+3.00000*algebraic[33])-algebraic[54]
    algebraic[53] = (constants[19]*(algebraic[50]-algebraic[45]))/constants[4]
    rates[13] = -0.0100000*2.00000*algebraic[53]
    algebraic[51] = (constants[16]*(algebraic[50]-algebraic[31]))/constants[4]
    algebraic[55] = 0.0100000*((-algebraic[51]-3.00000*algebraic[29])+algebraic[48]+algebraic[53])
    rates[8] = algebraic[55]
    rates[11] = 0.0100000*((3.00000*algebraic[33]+algebraic[37]+algebraic[39]+algebraic[41])-100.000*algebraic[55])
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[1] = (0.320000*(-states[0]-51.9000))/(exp(-(0.250000*states[0]+12.9750))-1.00000)
    algebraic[9] = (0.280000*(states[0]+24.8900))/(exp(0.200000*states[0]+4.97800)-1.00000)
    algebraic[2] = 0.128000*exp(-(0.0560000*states[0]+2.94000))
    algebraic[10] = 4.00000/(exp(-(0.200000*states[0]+6.00000))+1.00000)
    algebraic[3] = ((1.00000/constants[6])*1.00000)/(exp(-(0.143000*states[0]+5.67000))+1.00000)
    algebraic[11] = ((1.00000/constants[6])*exp(-(0.143000*states[0]+5.67000)))/(exp(-(0.143000*states[0]+5.67000))+1.00000)
    algebraic[4] = 5.12000e-08*exp(-(0.0560000*states[0]+2.94000))
    algebraic[12] = 1.60000e-06/(exp(-(0.200000*states[0]+8.00000))+1.00000)
    algebraic[5] = (0.0160000*(-states[0]-34.9000))/(exp(-(0.200000*states[0]+6.98000))-1.00000)
    algebraic[13] = 0.250000*exp(-(0.0250000*states[0]+1.25000))
    algebraic[6] = (0.0200000*(-states[0]-56.9000))/(exp(-(0.100000*states[0]+5.69000))-1.00000)
    algebraic[14] = (0.0175000*(states[0]+29.9000))/(exp(0.100000*states[0]+2.99000)-1.00000)
    algebraic[7] = 0.0160000*exp(-(0.0560000*states[0]+4.61000))
    algebraic[15] = 0.500000/(exp(-(0.200000*states[0]+11.9800))+1.00000)
    algebraic[0] = custom_piecewise([greater_equal(voi , constants[1]) & less_equal(voi , constants[2]), 3500.00 , True, 0.00000])
    algebraic[32] = ((constants[35]*constants[29]+constants[26]*constants[31]+constants[25]*constants[30])-(states[11]+states[8]))/constants[35]
    algebraic[16] = (constants[26]+constants[25])-states[10]
    algebraic[30] = states[11]/algebraic[16]
    algebraic[35] = constants[40]*log(algebraic[30]/algebraic[32])
    algebraic[36] = constants[3]*(power(states[1], 3.00000))*states[2]*(states[0]-algebraic[35])
    algebraic[38] = constants[5]*(power(states[3], 2.00000))*states[4]*(states[0]-algebraic[35])
    algebraic[40] = constants[12]*(states[0]-algebraic[35])
    algebraic[18] = states[12]/algebraic[16]
    algebraic[20] = ((constants[35]*constants[32]+constants[26]*constants[33]+constants[25]*constants[22])-(states[12]+states[9]))/constants[35]
    algebraic[21] = constants[40]*log(algebraic[18]/algebraic[20])
    algebraic[25] = constants[7]*(power(states[5], 2.00000))*(states[0]-algebraic[21])
    algebraic[26] = constants[8]*(power(states[6], 2.00000))*states[7]*(states[0]-algebraic[21])
    algebraic[27] = constants[13]*(states[0]-algebraic[21])
    algebraic[8] = constants[14]*(states[0]-constants[15])
    algebraic[33] = (((constants[9]*(power(algebraic[32], 1.50000)))/(power(algebraic[32], 1.50000)+power(constants[10], 1.50000)))*algebraic[18])/(algebraic[18]+constants[11])
    algebraic[34] = algebraic[33]*constants[4]
    algebraic[28] = states[8]/states[10]
    algebraic[17] = states[9]/states[10]
    algebraic[44] = ((constants[26]*constants[42]+constants[25]*constants[34])-states[13])/states[10]
    algebraic[46] = (algebraic[28]+algebraic[17])-(algebraic[44]+(constants[36]*constants[24])/states[10])
    algebraic[42] = ((constants[28]+algebraic[32])-constants[29])+(algebraic[20]-constants[32])
    algebraic[47] = ((constants[26]*constants[41]+constants[25]*constants[39]+constants[35]*constants[28])-(states[10]*algebraic[46]+constants[35]*algebraic[42]))/algebraic[16]
    algebraic[43] = states[13]/algebraic[16]
    algebraic[29] = (((constants[20]*(power(algebraic[28], 1.50000)))/(power(algebraic[28], 1.50000)+power(constants[10], 1.50000)))*algebraic[18])/(algebraic[18]+constants[11])
    algebraic[31] = constants[40]*log(algebraic[30]/algebraic[28])
    algebraic[19] = constants[40]*log(algebraic[18]/algebraic[17])
    algebraic[49] = -1.00000*constants[40]*log(algebraic[47]/algebraic[46])
    algebraic[45] = -constants[40]*log((algebraic[30]/algebraic[28])*(power(algebraic[43]/algebraic[44], 2.00000)))
    algebraic[50] = (constants[16]*algebraic[31]+constants[17]*algebraic[19]+constants[18]*algebraic[49]+constants[19]*algebraic[45])/(constants[16]+constants[17]+constants[18]+constants[19])-(constants[4]*algebraic[29])/(constants[16]+constants[17]+constants[18]+constants[19])
    algebraic[52] = (constants[17]*(algebraic[50]-algebraic[19]))/constants[4]
    algebraic[48] = custom_piecewise([greater(algebraic[18] , constants[22]), (((power(algebraic[18]-constants[22], 10.0000))/(power(algebraic[18]-constants[22], 10.0000)+power(0.0300000, 10.0000)))*constants[40]*constants[21]*log((((algebraic[18]/algebraic[17])*algebraic[30])/algebraic[28])*(power(algebraic[47]/algebraic[46], 2.00000))))/constants[4] , True, 0.00000])
    algebraic[54] = 0.0100000*(-algebraic[52]+2.00000*algebraic[29]+algebraic[48])
    algebraic[37] = (constants[3]*(power(states[1], 3.00000))*states[2]*(states[0]-algebraic[35]))/constants[4]
    algebraic[39] = (constants[5]*(power(states[3], 2.00000))*states[4]*(states[0]-algebraic[35]))/constants[4]
    algebraic[41] = (constants[12]*(states[0]-algebraic[35]))/constants[4]
    algebraic[53] = (constants[19]*(algebraic[50]-algebraic[45]))/constants[4]
    algebraic[51] = (constants[16]*(algebraic[50]-algebraic[31]))/constants[4]
    algebraic[55] = 0.0100000*((-algebraic[51]-3.00000*algebraic[29])+algebraic[48]+algebraic[53])
    algebraic[22] = (constants[7]*(power(states[5], 2.00000))*(states[0]-algebraic[21]))/constants[4]
    algebraic[23] = (constants[8]*(power(states[6], 2.00000))*states[7]*(states[0]-algebraic[21]))/constants[4]
    algebraic[24] = (constants[13]*(states[0]-algebraic[21]))/constants[4]
    return algebraic

def custom_piecewise(cases):
    """Compute result of a piecewise function"""
    return select(cases[0::2],cases[1::2])

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)