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 = 62
sizeStates = 31
sizeConstants = 70
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 (ms)"
    legend_states[0] = "V in component membrane (mV)"
    legend_constants[0] = "R in component membrane (gas_constant_units)"
    legend_constants[1] = "T in component membrane (kelvin)"
    legend_constants[2] = "F in component membrane (faradays_constant_units)"
    legend_algebraic[15] = "i_Na in component fast_sodium_current (uA_per_mm2)"
    legend_algebraic[19] = "i_Ca_L_Ca in component L_type_Ca_channel (uA_per_mm2)"
    legend_algebraic[21] = "i_Ca_L_K in component L_type_Ca_channel (uA_per_mm2)"
    legend_algebraic[25] = "i_K in component time_dependent_potassium_current (uA_per_mm2)"
    legend_algebraic[31] = "i_K1 in component time_independent_potassium_current (uA_per_mm2)"
    legend_algebraic[35] = "i_NaCa in component Na_Ca_exchanger (uA_per_mm2)"
    legend_algebraic[34] = "i_Kp in component plateau_potassium_current (uA_per_mm2)"
    legend_algebraic[36] = "i_p_Ca in component sarcolemmal_calcium_pump (uA_per_mm2)"
    legend_algebraic[38] = "i_Na_b in component sodium_background_current (uA_per_mm2)"
    legend_algebraic[40] = "i_Ca_b in component calcium_background_current (uA_per_mm2)"
    legend_algebraic[43] = "i_NaK in component sodium_potassium_pump (uA_per_mm2)"
    legend_algebraic[60] = "i_ns_Ca in component non_specific_calcium_activated_current (uA_per_mm2)"
    legend_constants[3] = "Cm in component membrane (uF_per_mm2)"
    legend_algebraic[6] = "I_stim in component membrane (uA_per_mm2)"
    legend_constants[4] = "stim_start in component membrane (ms)"
    legend_constants[5] = "stim_end in component membrane (ms)"
    legend_constants[6] = "stim_period in component membrane (ms)"
    legend_constants[7] = "stim_duration in component membrane (ms)"
    legend_constants[8] = "stim_amplitude in component membrane (uA_per_mm2)"
    legend_algebraic[13] = "E_Na in component fast_sodium_current (mV)"
    legend_constants[9] = "g_Na in component fast_sodium_current (mS_per_mm2)"
    legend_states[1] = "Nai in component ionic_concentrations (mM)"
    legend_constants[10] = "Nao in component ionic_concentrations (mM)"
    legend_states[2] = "m in component fast_sodium_current_m_gate (dimensionless)"
    legend_states[3] = "h in component fast_sodium_current_h_gate (dimensionless)"
    legend_states[4] = "j in component fast_sodium_current_j_gate (dimensionless)"
    legend_algebraic[0] = "alpha_m in component fast_sodium_current_m_gate (per_ms)"
    legend_algebraic[7] = "beta_m in component fast_sodium_current_m_gate (per_ms)"
    legend_algebraic[1] = "alpha_h in component fast_sodium_current_h_gate (per_ms)"
    legend_algebraic[8] = "beta_h in component fast_sodium_current_h_gate (per_ms)"
    legend_algebraic[2] = "alpha_j in component fast_sodium_current_j_gate (per_ms)"
    legend_algebraic[9] = "beta_j in component fast_sodium_current_j_gate (per_ms)"
    legend_constants[11] = "P_Ca in component L_type_Ca_channel (mm_per_ms)"
    legend_constants[12] = "P_K in component L_type_Ca_channel (mm_per_ms)"
    legend_algebraic[20] = "p_k in component L_type_Ca_channel (mm_per_ms)"
    legend_constants[13] = "i_Ca_L_Ca_half in component L_type_Ca_channel (uA_per_mm2)"
    legend_algebraic[17] = "i_Ca_L_Ca_max in component L_type_Ca_channel (uA_per_mm2)"
    legend_states[5] = "O in component L_type_Ca_channel (dimensionless)"
    legend_states[6] = "O_Ca in component L_type_Ca_channel (dimensionless)"
    legend_algebraic[3] = "alpha in component L_type_Ca_channel (per_ms)"
    legend_algebraic[10] = "beta in component L_type_Ca_channel (per_ms)"
    legend_algebraic[18] = "gamma in component L_type_Ca_channel (per_ms)"
    legend_algebraic[14] = "alpha_a in component L_type_Ca_channel (per_ms)"
    legend_algebraic[16] = "beta_b in component L_type_Ca_channel (per_ms)"
    legend_constants[14] = "a in component L_type_Ca_channel (dimensionless)"
    legend_constants[15] = "b in component L_type_Ca_channel (dimensionless)"
    legend_constants[16] = "g in component L_type_Ca_channel (per_ms)"
    legend_constants[17] = "f in component L_type_Ca_channel (per_ms)"
    legend_constants[18] = "g_ in component L_type_Ca_channel (per_ms)"
    legend_constants[19] = "f_ in component L_type_Ca_channel (per_ms)"
    legend_constants[20] = "omega in component L_type_Ca_channel (per_ms)"
    legend_states[7] = "C0 in component L_type_Ca_channel (dimensionless)"
    legend_states[8] = "C1 in component L_type_Ca_channel (dimensionless)"
    legend_states[9] = "C2 in component L_type_Ca_channel (dimensionless)"
    legend_states[10] = "C3 in component L_type_Ca_channel (dimensionless)"
    legend_states[11] = "C4 in component L_type_Ca_channel (dimensionless)"
    legend_states[12] = "C_Ca0 in component L_type_Ca_channel (dimensionless)"
    legend_states[13] = "C_Ca1 in component L_type_Ca_channel (dimensionless)"
    legend_states[14] = "C_Ca2 in component L_type_Ca_channel (dimensionless)"
    legend_states[15] = "C_Ca3 in component L_type_Ca_channel (dimensionless)"
    legend_states[16] = "C_Ca4 in component L_type_Ca_channel (dimensionless)"
    legend_states[17] = "Ca_SS in component calcium_subsystem (mM)"
    legend_constants[21] = "Cao in component ionic_concentrations (mM)"
    legend_states[18] = "Ko in component ionic_concentrations (mM)"
    legend_states[19] = "Ki in component ionic_concentrations (mM)"
    legend_states[20] = "y in component L_type_Ca_channel_y_gate (dimensionless)"
    legend_algebraic[4] = "y_infinity in component L_type_Ca_channel_y_gate (dimensionless)"
    legend_algebraic[11] = "tau_y in component L_type_Ca_channel_y_gate (ms)"
    legend_algebraic[22] = "g_K in component time_dependent_potassium_current (mS_per_mm2)"
    legend_constants[22] = "g_K_max in component time_dependent_potassium_current (mS_per_mm2)"
    legend_algebraic[23] = "E_K in component time_dependent_potassium_current (mV)"
    legend_constants[23] = "P_NaK in component time_dependent_potassium_current (dimensionless)"
    legend_states[21] = "X in component time_dependent_potassium_current_X_gate (dimensionless)"
    legend_algebraic[24] = "Xi in component time_dependent_potassium_current_Xi_gate (dimensionless)"
    legend_algebraic[5] = "alpha_X in component time_dependent_potassium_current_X_gate (per_ms)"
    legend_algebraic[12] = "beta_X in component time_dependent_potassium_current_X_gate (per_ms)"
    legend_algebraic[27] = "E_K1 in component time_independent_potassium_current (mV)"
    legend_algebraic[26] = "g_K1 in component time_independent_potassium_current (mS_per_mm2)"
    legend_constants[24] = "g_K1_max in component time_independent_potassium_current (mS_per_mm2)"
    legend_algebraic[30] = "K1_infinity in component time_independent_potassium_current_K1_gate (dimensionless)"
    legend_algebraic[28] = "alpha_K1 in component time_independent_potassium_current_K1_gate (per_ms)"
    legend_algebraic[29] = "beta_K1 in component time_independent_potassium_current_K1_gate (per_ms)"
    legend_algebraic[32] = "E_Kp in component plateau_potassium_current (mV)"
    legend_constants[25] = "g_Kp in component plateau_potassium_current (mS_per_mm2)"
    legend_algebraic[33] = "Kp in component plateau_potassium_current (dimensionless)"
    legend_constants[26] = "k_NaCa in component Na_Ca_exchanger (uA_per_mm2)"
    legend_constants[27] = "K_mNa in component Na_Ca_exchanger (mM)"
    legend_constants[28] = "K_mCa in component Na_Ca_exchanger (mM)"
    legend_constants[29] = "k_sat in component Na_Ca_exchanger (dimensionless)"
    legend_constants[30] = "eta in component Na_Ca_exchanger (dimensionless)"
    legend_states[22] = "Cai in component calcium_subsystem (mM)"
    legend_constants[31] = "K_mpCa in component sarcolemmal_calcium_pump (mM)"
    legend_constants[32] = "I_pCa in component sarcolemmal_calcium_pump (uA_per_mm2)"
    legend_constants[33] = "g_Nab in component sodium_background_current (mS_per_mm2)"
    legend_algebraic[37] = "E_NaN in component sodium_background_current (mV)"
    legend_constants[34] = "g_Cab in component calcium_background_current (mS_per_mm2)"
    legend_algebraic[39] = "E_CaN in component calcium_background_current (mV)"
    legend_constants[35] = "I_NaK in component sodium_potassium_pump (uA_per_mm2)"
    legend_algebraic[41] = "f_NaK in component sodium_potassium_pump (dimensionless)"
    legend_constants[36] = "K_mNai in component sodium_potassium_pump (mM)"
    legend_constants[37] = "K_mKo in component sodium_potassium_pump (mM)"
    legend_constants[66] = "sigma in component sodium_potassium_pump (dimensionless)"
    legend_algebraic[52] = "i_ns_Na in component non_specific_calcium_activated_current (uA_per_mm2)"
    legend_algebraic[58] = "i_ns_K in component non_specific_calcium_activated_current (uA_per_mm2)"
    legend_algebraic[49] = "I_ns_Na in component non_specific_calcium_activated_current (uA_per_mm2)"
    legend_algebraic[56] = "I_ns_K in component non_specific_calcium_activated_current (uA_per_mm2)"
    legend_constants[38] = "K_m_ns_Ca in component non_specific_calcium_activated_current (mM)"
    legend_constants[39] = "P_ns_Ca in component non_specific_calcium_activated_current (mm_per_ms)"
    legend_algebraic[45] = "EnsCa in component non_specific_calcium_activated_current (mV)"
    legend_algebraic[47] = "VnsCa in component non_specific_calcium_activated_current (mV)"
    legend_constants[40] = "Am in component calcium_subsystem (per_mm)"
    legend_constants[41] = "V_myo in component calcium_subsystem (dimensionless)"
    legend_algebraic[42] = "RyR_open in component calcium_subsystem (dimensionless)"
    legend_states[23] = "P_O1 in component calcium_subsystem (dimensionless)"
    legend_states[24] = "P_O2 in component calcium_subsystem (dimensionless)"
    legend_states[25] = "P_C1 in component calcium_subsystem (dimensionless)"
    legend_states[26] = "P_C2 in component calcium_subsystem (dimensionless)"
    legend_constants[42] = "v1 in component calcium_subsystem (per_ms)"
    legend_constants[43] = "v2 in component calcium_subsystem (per_ms)"
    legend_constants[44] = "v3 in component calcium_subsystem (mM_per_ms)"
    legend_constants[45] = "nCa in component calcium_subsystem (dimensionless)"
    legend_constants[46] = "mCa in component calcium_subsystem (dimensionless)"
    legend_constants[47] = "k_a_plus in component calcium_subsystem (per_mM4_per_ms)"
    legend_constants[48] = "k_a_minus in component calcium_subsystem (per_ms)"
    legend_constants[49] = "k_b_plus in component calcium_subsystem (per_mM3_per_ms)"
    legend_constants[50] = "k_b_minus in component calcium_subsystem (per_ms)"
    legend_constants[51] = "k_c_plus in component calcium_subsystem (per_ms)"
    legend_constants[52] = "k_c_minus in component calcium_subsystem (per_ms)"
    legend_constants[53] = "k_htrpn_plus in component calcium_subsystem (per_mM_per_ms)"
    legend_constants[54] = "k_htrpn_minus in component calcium_subsystem (per_ms)"
    legend_constants[55] = "k_ltrpn_plus in component calcium_subsystem (per_mM_per_ms)"
    legend_constants[56] = "k_ltrpn_minus in component calcium_subsystem (per_ms)"
    legend_constants[57] = "tau_tr in component calcium_subsystem (ms)"
    legend_states[27] = "Ca_JSR in component calcium_subsystem (mM)"
    legend_states[28] = "Ca_NSR in component calcium_subsystem (mM)"
    legend_constants[69] = "V_JSR in component calcium_subsystem (dimensionless)"
    legend_constants[68] = "V_NSR in component calcium_subsystem (dimensionless)"
    legend_constants[67] = "V_SS in component calcium_subsystem (dimensionless)"
    legend_constants[58] = "K_mup in component calcium_subsystem (mM)"
    legend_constants[59] = "K_mCMDN in component calcium_subsystem (mM)"
    legend_constants[60] = "K_mCSQN in component calcium_subsystem (mM)"
    legend_constants[61] = "tau_xfer in component calcium_subsystem (ms)"
    legend_constants[62] = "HTRPN_tot in component calcium_subsystem (mM)"
    legend_constants[63] = "LTRPN_tot in component calcium_subsystem (mM)"
    legend_states[29] = "HTRPNCa in component calcium_subsystem (mM)"
    legend_states[30] = "LTRPNCa in component calcium_subsystem (mM)"
    legend_constants[64] = "CSQN_tot in component calcium_subsystem (mM)"
    legend_constants[65] = "CMDN_tot in component calcium_subsystem (mM)"
    legend_algebraic[61] = "Bi in component calcium_subsystem (dimensionless)"
    legend_algebraic[53] = "B_SS in component calcium_subsystem (dimensionless)"
    legend_algebraic[54] = "B_JSR in component calcium_subsystem (dimensionless)"
    legend_algebraic[44] = "J_rel in component calcium_subsystem (mM_per_ms)"
    legend_algebraic[46] = "J_leak in component calcium_subsystem (mM_per_ms)"
    legend_algebraic[48] = "J_up in component calcium_subsystem (mM_per_ms)"
    legend_algebraic[50] = "J_tr in component calcium_subsystem (mM_per_ms)"
    legend_algebraic[51] = "J_xfer in component calcium_subsystem (mM_per_ms)"
    legend_algebraic[59] = "J_trpn in component calcium_subsystem (mM_per_ms)"
    legend_algebraic[55] = "J_htrpn in component calcium_subsystem (mM_per_ms)"
    legend_algebraic[57] = "J_ltrpn in component calcium_subsystem (mM_per_ms)"
    legend_rates[0] = "d/dt V in component membrane (mV)"
    legend_rates[2] = "d/dt m in component fast_sodium_current_m_gate (dimensionless)"
    legend_rates[3] = "d/dt h in component fast_sodium_current_h_gate (dimensionless)"
    legend_rates[4] = "d/dt j in component fast_sodium_current_j_gate (dimensionless)"
    legend_rates[7] = "d/dt C0 in component L_type_Ca_channel (dimensionless)"
    legend_rates[8] = "d/dt C1 in component L_type_Ca_channel (dimensionless)"
    legend_rates[9] = "d/dt C2 in component L_type_Ca_channel (dimensionless)"
    legend_rates[10] = "d/dt C3 in component L_type_Ca_channel (dimensionless)"
    legend_rates[11] = "d/dt C4 in component L_type_Ca_channel (dimensionless)"
    legend_rates[5] = "d/dt O in component L_type_Ca_channel (dimensionless)"
    legend_rates[12] = "d/dt C_Ca0 in component L_type_Ca_channel (dimensionless)"
    legend_rates[13] = "d/dt C_Ca1 in component L_type_Ca_channel (dimensionless)"
    legend_rates[14] = "d/dt C_Ca2 in component L_type_Ca_channel (dimensionless)"
    legend_rates[15] = "d/dt C_Ca3 in component L_type_Ca_channel (dimensionless)"
    legend_rates[16] = "d/dt C_Ca4 in component L_type_Ca_channel (dimensionless)"
    legend_rates[6] = "d/dt O_Ca in component L_type_Ca_channel (dimensionless)"
    legend_rates[20] = "d/dt y in component L_type_Ca_channel_y_gate (dimensionless)"
    legend_rates[21] = "d/dt X in component time_dependent_potassium_current_X_gate (dimensionless)"
    legend_rates[25] = "d/dt P_C1 in component calcium_subsystem (dimensionless)"
    legend_rates[23] = "d/dt P_O1 in component calcium_subsystem (dimensionless)"
    legend_rates[24] = "d/dt P_O2 in component calcium_subsystem (dimensionless)"
    legend_rates[26] = "d/dt P_C2 in component calcium_subsystem (dimensionless)"
    legend_rates[29] = "d/dt HTRPNCa in component calcium_subsystem (mM)"
    legend_rates[30] = "d/dt LTRPNCa in component calcium_subsystem (mM)"
    legend_rates[22] = "d/dt Cai in component calcium_subsystem (mM)"
    legend_rates[17] = "d/dt Ca_SS in component calcium_subsystem (mM)"
    legend_rates[27] = "d/dt Ca_JSR in component calcium_subsystem (mM)"
    legend_rates[28] = "d/dt Ca_NSR in component calcium_subsystem (mM)"
    legend_rates[1] = "d/dt Nai in component ionic_concentrations (mM)"
    legend_rates[19] = "d/dt Ki in component ionic_concentrations (mM)"
    legend_rates[18] = "d/dt Ko in component ionic_concentrations (mM)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    states[0] = -84.1638
    constants[0] = 8.3145e3
    constants[1] = 310
    constants[2] = 9.6845e4
    constants[3] = 0.01
    constants[4] = 100
    constants[5] = 10100
    constants[6] = 500
    constants[7] = 1
    constants[8] = 0.516289
    constants[9] = 0.128
    states[1] = 10.2042
    constants[10] = 140
    states[2] = 0.0328302
    states[3] = 0.988354
    states[4] = 0.99254
    constants[11] = 33.75e-6
    constants[12] = 1e-9
    constants[13] = -4.58e-3
    states[5] = 9.84546e-21
    states[6] = 0
    constants[14] = 2
    constants[15] = 2
    constants[16] = 2
    constants[17] = 0.3
    constants[18] = 0
    constants[19] = 0
    constants[20] = 0.01
    states[7] = 0.997208
    states[8] = 6.38897e-5
    states[9] = 1.535e-9
    states[10] = 1.63909e-14
    states[11] = 6.56337e-20
    states[12] = 2.72826e-3
    states[13] = 6.99215e-7
    states[14] = 6.71989e-11
    states[15] = 2.87031e-15
    states[16] = 4.59752e-20
    states[17] = 1.36058e-4
    constants[21] = 1.8
    states[18] = 5.4
    states[19] = 143.727
    states[20] = 0.998983
    constants[22] = 0.001128
    constants[23] = 0.01833
    states[21] = 0.000928836
    constants[24] = 7.5e-3
    constants[25] = 8.28e-5
    constants[26] = 50
    constants[27] = 87.5
    constants[28] = 1.38
    constants[29] = 0.1
    constants[30] = 0.35
    states[22] = 9.94893e-11
    constants[31] = 0.5e-3
    constants[32] = 1.15e-2
    constants[33] = 1.41e-5
    constants[34] = 6.032e-5
    constants[35] = 0.013
    constants[36] = 10
    constants[37] = 1.5
    constants[38] = 1.2e-3
    constants[39] = 1.75e-9
    constants[40] = 546.69
    constants[41] = 0.92
    states[23] = 1.19168e-3
    states[24] = 6.30613e-9
    states[25] = 0.762527
    states[26] = 0.236283
    constants[42] = 1.8
    constants[43] = 0.58e-4
    constants[44] = 1.8e-3
    constants[45] = 4
    constants[46] = 3
    constants[47] = 1.215e10
    constants[48] = 0.1425
    constants[49] = 4.05e7
    constants[50] = 1.93
    constants[51] = 0.018
    constants[52] = 0.0008
    constants[53] = 20
    constants[54] = 0.066e-3
    constants[55] = 40
    constants[56] = 0.04
    constants[57] = 34.48
    states[27] = 1.17504
    states[28] = 1.243891
    constants[58] = 0.5e-3
    constants[59] = 2.38e-3
    constants[60] = 0.8
    constants[61] = 3.125
    constants[62] = 0.14
    constants[63] = 0.07
    states[29] = 0.13598
    states[30] = 0.00635
    constants[64] = 15
    constants[65] = 0.05
    constants[66] = (1.00000/7.00000)*(exp(constants[10]/67.3000)-1.00000)
    constants[67] = 5.82800e-05*constants[41]
    constants[68] = 0.0810000*constants[41]
    constants[69] = 0.00464000*constants[41]
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    rates[5] = constants[17]*states[11]-constants[16]*states[5]
    rates[6] = constants[19]*states[16]-constants[18]*states[6]
    rates[25] = -constants[47]*(power(states[17], constants[45]))*states[25]+constants[48]*states[23]
    rates[23] = (constants[47]*(power(states[17], constants[45]))*states[25]-(constants[48]*states[23]+constants[49]*(power(states[17], constants[46]))*states[23]+constants[51]*states[23]))+constants[50]*states[24]+constants[52]*states[26]
    rates[24] = constants[49]*(power(states[17], constants[46]))*states[23]-constants[50]*states[24]
    rates[26] = constants[51]*states[23]-constants[52]*states[26]
    algebraic[0] = (0.320000*(states[0]+47.1300))/(1.00000-exp(-0.100000*(states[0]+47.1300)))
    algebraic[7] = 0.0800000*exp(-states[0]/11.0000)
    rates[2] = algebraic[0]*(1.00000-states[2])-algebraic[7]*states[2]
    algebraic[1] = custom_piecewise([less(states[0] , -40.0000), 0.135000*exp((80.0000+states[0])/-6.80000) , True, 0.00000])
    algebraic[8] = custom_piecewise([less(states[0] , -40.0000), 3.56000*exp(0.0790000*states[0])+310000.*exp(0.350000*states[0]) , True, 1.00000/(0.130000*(1.00000+exp((states[0]+10.6600)/-11.1000)))])
    rates[3] = algebraic[1]*(1.00000-states[3])-algebraic[8]*states[3]
    algebraic[2] = custom_piecewise([less(states[0] , -40.0000), ((-127140.*exp(0.244400*states[0])-3.47400e-05*exp(-0.0439100*states[0]))*(states[0]+37.7800))/(1.00000+exp(0.311000*(states[0]+79.2300))) , True, 0.00000])
    algebraic[9] = custom_piecewise([less(states[0] , -40.0000), (0.121200*exp(-0.0105200*states[0]))/(1.00000+exp(-0.137800*(states[0]+40.1400))) , True, (0.300000*exp(-2.53500e-07*states[0]))/(1.00000+exp(-0.100000*(states[0]+32.0000)))])
    rates[4] = algebraic[2]*(1.00000-states[4])-algebraic[9]*states[4]
    algebraic[4] = 1.00000/(1.00000+exp((states[0]+55.0000)/7.50000))+0.100000/(1.00000+exp((-states[0]+21.0000)/6.00000))
    algebraic[11] = 20.0000+600.000/(1.00000+exp((states[0]+30.0000)/9.50000))
    rates[20] = (algebraic[4]-states[20])/algebraic[11]
    algebraic[5] = (7.19000e-05*(states[0]+30.0000))/(1.00000-exp(-0.148000*(states[0]+30.0000)))
    algebraic[12] = (0.000131000*(states[0]+30.0000))/(-1.00000+exp(0.0687000*(states[0]+30.0000)))
    rates[21] = algebraic[5]*(1.00000-states[21])-algebraic[12]*states[21]
    algebraic[3] = 0.400000*exp((states[0]+12.0000)/10.0000)
    algebraic[10] = 0.0500000*exp((states[0]+12.0000)/-13.0000)
    algebraic[18] = (0.187500*states[17])/1.00000
    rates[7] = (algebraic[10]*states[8]+constants[20]*states[12])-(4.00000*algebraic[3]+algebraic[18])*states[7]
    rates[8] = (4.00000*algebraic[3]*states[7]+2.00000*algebraic[10]*states[9]+(constants[20]/constants[15])*states[13])-(algebraic[10]+3.00000*algebraic[3]+algebraic[18]*constants[14])*states[8]
    rates[9] = (3.00000*algebraic[3]*states[8]+3.00000*algebraic[10]*states[10]+(constants[20]/(power(constants[15], 2.00000)))*states[14])-(algebraic[10]*2.00000+2.00000*algebraic[3]+algebraic[18]*(power(constants[14], 2.00000)))*states[9]
    rates[10] = (2.00000*algebraic[3]*states[9]+4.00000*algebraic[10]*states[11]+(constants[20]/(power(constants[15], 3.00000)))*states[15])-(algebraic[10]*3.00000+algebraic[3]+algebraic[18]*(power(constants[14], 3.00000)))*states[10]
    rates[11] = (algebraic[3]*states[10]+constants[16]*states[5]+(constants[20]/(power(constants[15], 4.00000)))*states[16])-(algebraic[10]*4.00000+constants[17]+algebraic[18]*(power(constants[14], 4.00000)))*states[11]
    algebraic[14] = algebraic[3]*constants[14]
    algebraic[16] = algebraic[10]/constants[15]
    rates[12] = (algebraic[16]*states[13]+algebraic[18]*states[7])-(4.00000*algebraic[14]+constants[20])*states[12]
    rates[13] = (4.00000*algebraic[14]*states[12]+2.00000*algebraic[16]*states[14]+algebraic[18]*constants[14]*states[8])-(algebraic[16]+3.00000*algebraic[14]+constants[20]/constants[15])*states[13]
    rates[14] = (3.00000*algebraic[14]*states[13]+3.00000*algebraic[16]*states[15]+algebraic[18]*(power(constants[14], 2.00000))*states[9])-(algebraic[16]*2.00000+2.00000*algebraic[14]+constants[20]/(power(constants[15], 2.00000)))*states[14]
    rates[15] = (2.00000*algebraic[14]*states[14]+4.00000*algebraic[16]*states[16]+algebraic[18]*(power(constants[14], 3.00000))*states[10])-(algebraic[16]*3.00000+algebraic[14]+constants[20]/(power(constants[15], 3.00000)))*states[15]
    rates[16] = (algebraic[14]*states[15]+constants[18]*states[6]+algebraic[18]*(power(constants[14], 4.00000))*states[11])-(algebraic[16]*4.00000+constants[19]+constants[20]/(power(constants[15], 4.00000)))*states[16]
    algebraic[46] = constants[43]*(states[28]-states[22])
    algebraic[48] = (constants[44]*(power(states[22], 2.00000)))/(power(constants[58], 2.00000)+power(states[22], 2.00000))
    algebraic[50] = (states[28]-states[27])/constants[57]
    rates[28] = ((algebraic[48]-algebraic[46])*constants[41])/constants[68]-(algebraic[50]*constants[69])/constants[68]
    algebraic[55] = constants[53]*states[22]*(constants[62]-states[29])-constants[54]*states[29]
    rates[29] = algebraic[55]
    algebraic[17] = (((constants[11]*4.00000*states[0]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*(0.00100000*exp((2.00000*states[0]*constants[2])/(constants[0]*constants[1]))-0.341000*constants[21]))/(exp((2.00000*states[0]*constants[2])/(constants[0]*constants[1]))-1.00000)
    algebraic[19] = algebraic[17]*states[20]*(states[5]+states[6])
    algebraic[53] = 1.00000/(1.00000+(constants[65]*constants[59])/(power(constants[59]+states[17], 2.00000)))
    algebraic[42] = states[23]+states[24]
    algebraic[44] = constants[42]*algebraic[42]*(states[27]-states[17])
    algebraic[51] = (states[17]-states[22])/constants[61]
    rates[17] = algebraic[53]*(((algebraic[44]*constants[69])/constants[67]-(algebraic[51]*constants[41])/constants[67])-(algebraic[19]*constants[40])/(2.00000*constants[67]*constants[2]))
    algebraic[54] = 1.00000/(1.00000+(constants[64]*constants[60])/(power(constants[60]+states[27], 2.00000)))
    rates[27] = algebraic[54]*(algebraic[50]-algebraic[44])
    algebraic[13] = ((constants[0]*constants[1])/constants[2])*log(constants[10]/states[1])
    algebraic[15] = constants[9]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[13])
    algebraic[35] = ((((((constants[26]*1.00000)/(power(constants[27], 3.00000)+power(constants[10], 3.00000)))*1.00000)/(constants[28]+constants[21]))*1.00000)/(1.00000+constants[29]*exp(((constants[30]-1.00000)*states[0]*constants[2])/(constants[0]*constants[1]))))*(exp((constants[30]*states[0]*constants[2])/(constants[0]*constants[1]))*(power(states[1], 3.00000))*constants[21]-exp(((constants[30]-1.00000)*states[0]*constants[2])/(constants[0]*constants[1]))*(power(constants[10], 3.00000))*states[22])
    algebraic[37] = algebraic[13]
    algebraic[38] = constants[33]*(states[0]-algebraic[37])
    algebraic[41] = 1.00000/(1.00000+0.124500*exp((-0.100000*states[0]*constants[2])/(constants[0]*constants[1]))+0.0365000*constants[66]*exp((-states[0]*constants[2])/(constants[0]*constants[1])))
    algebraic[43] = (((constants[35]*algebraic[41]*1.00000)/(1.00000+power(constants[36]/states[1], 1.50000)))*states[18])/(states[18]+constants[37])
    algebraic[45] = ((constants[0]*constants[1])/constants[2])*log((states[18]+constants[10])/(states[19]+states[1]))
    algebraic[47] = states[0]-algebraic[45]
    algebraic[49] = (((constants[39]*(power(1.00000, 2.00000))*algebraic[47]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*(0.750000*states[1]*exp((algebraic[47]*constants[2])/(constants[0]*constants[1]))-0.750000*constants[10]))/(exp((algebraic[47]*constants[2])/(constants[0]*constants[1]))-1.00000)
    algebraic[52] = (algebraic[49]*1.00000)/(1.00000+power(constants[38]/states[22], 3.00000))
    rates[1] = (-(algebraic[15]+algebraic[38]+algebraic[52]+algebraic[35]*3.00000+algebraic[43]*3.00000)*constants[40])/(constants[41]*constants[2])
    algebraic[57] = constants[55]*states[22]*(constants[63]-states[30])-constants[56]*states[30]
    rates[30] = algebraic[57]
    algebraic[20] = constants[12]/(1.00000+algebraic[17]/constants[13])
    algebraic[21] = (((algebraic[20]*states[20]*(states[5]+states[6])*states[0]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*(states[19]*exp((states[0]*constants[2])/(constants[0]*constants[1]))-states[18]))/(exp((states[0]*constants[2])/(constants[0]*constants[1]))-1.00000)
    algebraic[22] = constants[22]*(power(states[18]/5.40000, 1.0/2))
    algebraic[23] = ((constants[0]*constants[1])/constants[2])*log((states[18]+constants[23]*constants[10])/(states[19]+constants[23]*states[1]))
    algebraic[24] = 1.00000/(1.00000+exp((states[0]-56.2600)/32.1000))
    algebraic[25] = algebraic[22]*algebraic[24]*(power(states[21], 2.00000))*(states[0]-algebraic[23])
    algebraic[27] = ((constants[0]*constants[1])/constants[2])*log(states[18]/states[19])
    algebraic[26] = constants[24]*(power(states[18]/5.40000, 1.0/2))
    algebraic[28] = 1.02000/(1.00000+exp(0.238500*((states[0]-algebraic[27])-59.2150)))
    algebraic[29] = (0.491240*(exp(0.0803200*((states[0]+5.47600)-algebraic[27]))+exp(0.0617500*(states[0]-(algebraic[27]+594.310)))))/(1.00000+exp(-0.514300*((states[0]-algebraic[27])+4.75300)))
    algebraic[30] = algebraic[28]/(algebraic[28]+algebraic[29])
    algebraic[31] = algebraic[26]*algebraic[30]*(states[0]-algebraic[27])
    algebraic[32] = algebraic[27]
    algebraic[33] = 1.00000/(1.00000+exp((7.48800-states[0])/5.98000))
    algebraic[34] = constants[25]*algebraic[33]*(states[0]-algebraic[32])
    algebraic[56] = (((constants[39]*(power(1.00000, 2.00000))*algebraic[47]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*(0.750000*states[19]*exp((algebraic[47]*constants[2])/(constants[0]*constants[1]))-0.750000*states[18]))/(exp((algebraic[47]*constants[2])/(constants[0]*constants[1]))-1.00000)
    algebraic[58] = (algebraic[56]*1.00000)/(1.00000+power(constants[38]/states[22], 3.00000))
    rates[19] = (-(algebraic[21]+algebraic[25]+algebraic[31]+algebraic[34]+algebraic[58]+-algebraic[43]*2.00000)*constants[40])/(constants[41]*constants[2])
    rates[18] = ((algebraic[21]+algebraic[25]+algebraic[31]+algebraic[34]+algebraic[58]+-algebraic[43]*2.00000)*constants[40])/(constants[41]*constants[2])
    algebraic[36] = (constants[32]*states[22])/(constants[31]+states[22])
    algebraic[39] = ((constants[0]*constants[1])/(2.00000*constants[2]))*log(constants[21]/states[22])
    algebraic[40] = constants[34]*(states[0]-algebraic[39])
    algebraic[60] = algebraic[52]+algebraic[58]
    algebraic[6] = custom_piecewise([greater_equal(voi , constants[4]) & less_equal(voi , constants[5]) & less_equal((voi-constants[4])-floor((voi-constants[4])/constants[6])*constants[6] , constants[7]), constants[8] , True, 0.00000])
    rates[0] = (algebraic[6]-(algebraic[15]+algebraic[19]+algebraic[21]+algebraic[25]+algebraic[35]+algebraic[31]+algebraic[34]+algebraic[36]+algebraic[38]+algebraic[40]+algebraic[43]+algebraic[60]))/constants[3]
    algebraic[61] = 1.00000/(1.00000+(constants[65]*constants[59])/(power(constants[59]+states[22], 2.00000)))
    algebraic[59] = algebraic[55]+algebraic[57]
    rates[22] = algebraic[61]*((algebraic[46]+algebraic[51])-(algebraic[48]+algebraic[59]+(((algebraic[40]-2.00000*algebraic[35])+algebraic[36])*constants[40])/(2.00000*constants[41]*constants[2])))
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[0] = (0.320000*(states[0]+47.1300))/(1.00000-exp(-0.100000*(states[0]+47.1300)))
    algebraic[7] = 0.0800000*exp(-states[0]/11.0000)
    algebraic[1] = custom_piecewise([less(states[0] , -40.0000), 0.135000*exp((80.0000+states[0])/-6.80000) , True, 0.00000])
    algebraic[8] = custom_piecewise([less(states[0] , -40.0000), 3.56000*exp(0.0790000*states[0])+310000.*exp(0.350000*states[0]) , True, 1.00000/(0.130000*(1.00000+exp((states[0]+10.6600)/-11.1000)))])
    algebraic[2] = custom_piecewise([less(states[0] , -40.0000), ((-127140.*exp(0.244400*states[0])-3.47400e-05*exp(-0.0439100*states[0]))*(states[0]+37.7800))/(1.00000+exp(0.311000*(states[0]+79.2300))) , True, 0.00000])
    algebraic[9] = custom_piecewise([less(states[0] , -40.0000), (0.121200*exp(-0.0105200*states[0]))/(1.00000+exp(-0.137800*(states[0]+40.1400))) , True, (0.300000*exp(-2.53500e-07*states[0]))/(1.00000+exp(-0.100000*(states[0]+32.0000)))])
    algebraic[4] = 1.00000/(1.00000+exp((states[0]+55.0000)/7.50000))+0.100000/(1.00000+exp((-states[0]+21.0000)/6.00000))
    algebraic[11] = 20.0000+600.000/(1.00000+exp((states[0]+30.0000)/9.50000))
    algebraic[5] = (7.19000e-05*(states[0]+30.0000))/(1.00000-exp(-0.148000*(states[0]+30.0000)))
    algebraic[12] = (0.000131000*(states[0]+30.0000))/(-1.00000+exp(0.0687000*(states[0]+30.0000)))
    algebraic[3] = 0.400000*exp((states[0]+12.0000)/10.0000)
    algebraic[10] = 0.0500000*exp((states[0]+12.0000)/-13.0000)
    algebraic[18] = (0.187500*states[17])/1.00000
    algebraic[14] = algebraic[3]*constants[14]
    algebraic[16] = algebraic[10]/constants[15]
    algebraic[46] = constants[43]*(states[28]-states[22])
    algebraic[48] = (constants[44]*(power(states[22], 2.00000)))/(power(constants[58], 2.00000)+power(states[22], 2.00000))
    algebraic[50] = (states[28]-states[27])/constants[57]
    algebraic[55] = constants[53]*states[22]*(constants[62]-states[29])-constants[54]*states[29]
    algebraic[17] = (((constants[11]*4.00000*states[0]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*(0.00100000*exp((2.00000*states[0]*constants[2])/(constants[0]*constants[1]))-0.341000*constants[21]))/(exp((2.00000*states[0]*constants[2])/(constants[0]*constants[1]))-1.00000)
    algebraic[19] = algebraic[17]*states[20]*(states[5]+states[6])
    algebraic[53] = 1.00000/(1.00000+(constants[65]*constants[59])/(power(constants[59]+states[17], 2.00000)))
    algebraic[42] = states[23]+states[24]
    algebraic[44] = constants[42]*algebraic[42]*(states[27]-states[17])
    algebraic[51] = (states[17]-states[22])/constants[61]
    algebraic[54] = 1.00000/(1.00000+(constants[64]*constants[60])/(power(constants[60]+states[27], 2.00000)))
    algebraic[13] = ((constants[0]*constants[1])/constants[2])*log(constants[10]/states[1])
    algebraic[15] = constants[9]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[13])
    algebraic[35] = ((((((constants[26]*1.00000)/(power(constants[27], 3.00000)+power(constants[10], 3.00000)))*1.00000)/(constants[28]+constants[21]))*1.00000)/(1.00000+constants[29]*exp(((constants[30]-1.00000)*states[0]*constants[2])/(constants[0]*constants[1]))))*(exp((constants[30]*states[0]*constants[2])/(constants[0]*constants[1]))*(power(states[1], 3.00000))*constants[21]-exp(((constants[30]-1.00000)*states[0]*constants[2])/(constants[0]*constants[1]))*(power(constants[10], 3.00000))*states[22])
    algebraic[37] = algebraic[13]
    algebraic[38] = constants[33]*(states[0]-algebraic[37])
    algebraic[41] = 1.00000/(1.00000+0.124500*exp((-0.100000*states[0]*constants[2])/(constants[0]*constants[1]))+0.0365000*constants[66]*exp((-states[0]*constants[2])/(constants[0]*constants[1])))
    algebraic[43] = (((constants[35]*algebraic[41]*1.00000)/(1.00000+power(constants[36]/states[1], 1.50000)))*states[18])/(states[18]+constants[37])
    algebraic[45] = ((constants[0]*constants[1])/constants[2])*log((states[18]+constants[10])/(states[19]+states[1]))
    algebraic[47] = states[0]-algebraic[45]
    algebraic[49] = (((constants[39]*(power(1.00000, 2.00000))*algebraic[47]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*(0.750000*states[1]*exp((algebraic[47]*constants[2])/(constants[0]*constants[1]))-0.750000*constants[10]))/(exp((algebraic[47]*constants[2])/(constants[0]*constants[1]))-1.00000)
    algebraic[52] = (algebraic[49]*1.00000)/(1.00000+power(constants[38]/states[22], 3.00000))
    algebraic[57] = constants[55]*states[22]*(constants[63]-states[30])-constants[56]*states[30]
    algebraic[20] = constants[12]/(1.00000+algebraic[17]/constants[13])
    algebraic[21] = (((algebraic[20]*states[20]*(states[5]+states[6])*states[0]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*(states[19]*exp((states[0]*constants[2])/(constants[0]*constants[1]))-states[18]))/(exp((states[0]*constants[2])/(constants[0]*constants[1]))-1.00000)
    algebraic[22] = constants[22]*(power(states[18]/5.40000, 1.0/2))
    algebraic[23] = ((constants[0]*constants[1])/constants[2])*log((states[18]+constants[23]*constants[10])/(states[19]+constants[23]*states[1]))
    algebraic[24] = 1.00000/(1.00000+exp((states[0]-56.2600)/32.1000))
    algebraic[25] = algebraic[22]*algebraic[24]*(power(states[21], 2.00000))*(states[0]-algebraic[23])
    algebraic[27] = ((constants[0]*constants[1])/constants[2])*log(states[18]/states[19])
    algebraic[26] = constants[24]*(power(states[18]/5.40000, 1.0/2))
    algebraic[28] = 1.02000/(1.00000+exp(0.238500*((states[0]-algebraic[27])-59.2150)))
    algebraic[29] = (0.491240*(exp(0.0803200*((states[0]+5.47600)-algebraic[27]))+exp(0.0617500*(states[0]-(algebraic[27]+594.310)))))/(1.00000+exp(-0.514300*((states[0]-algebraic[27])+4.75300)))
    algebraic[30] = algebraic[28]/(algebraic[28]+algebraic[29])
    algebraic[31] = algebraic[26]*algebraic[30]*(states[0]-algebraic[27])
    algebraic[32] = algebraic[27]
    algebraic[33] = 1.00000/(1.00000+exp((7.48800-states[0])/5.98000))
    algebraic[34] = constants[25]*algebraic[33]*(states[0]-algebraic[32])
    algebraic[56] = (((constants[39]*(power(1.00000, 2.00000))*algebraic[47]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*(0.750000*states[19]*exp((algebraic[47]*constants[2])/(constants[0]*constants[1]))-0.750000*states[18]))/(exp((algebraic[47]*constants[2])/(constants[0]*constants[1]))-1.00000)
    algebraic[58] = (algebraic[56]*1.00000)/(1.00000+power(constants[38]/states[22], 3.00000))
    algebraic[36] = (constants[32]*states[22])/(constants[31]+states[22])
    algebraic[39] = ((constants[0]*constants[1])/(2.00000*constants[2]))*log(constants[21]/states[22])
    algebraic[40] = constants[34]*(states[0]-algebraic[39])
    algebraic[60] = algebraic[52]+algebraic[58]
    algebraic[6] = custom_piecewise([greater_equal(voi , constants[4]) & less_equal(voi , constants[5]) & less_equal((voi-constants[4])-floor((voi-constants[4])/constants[6])*constants[6] , constants[7]), constants[8] , True, 0.00000])
    algebraic[61] = 1.00000/(1.00000+(constants[65]*constants[59])/(power(constants[59]+states[22], 2.00000)))
    algebraic[59] = algebraic[55]+algebraic[57]
    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)