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 = 72
sizeStates = 26
sizeConstants = 48
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] = "V in component membrane (millivolt)"
    legend_constants[0] = "R in component membrane (joule_per_mole_kelvin)"
    legend_constants[1] = "T in component membrane (kelvin)"
    legend_constants[2] = "F in component membrane (coulomb_per_millimole)"
    legend_constants[3] = "Cm in component membrane (picoF)"
    legend_algebraic[0] = "i_st in component membrane (picoA)"
    legend_algebraic[29] = "i_Na in component fast_sodium_current (picoA)"
    legend_algebraic[47] = "i_K1 in component time_independent_potassium_current (picoA)"
    legend_algebraic[48] = "i_to in component transient_outward_K_current (picoA)"
    legend_algebraic[49] = "i_Kur in component ultrarapid_delayed_rectifier_K_current (picoA)"
    legend_algebraic[50] = "i_Kr in component rapid_delayed_rectifier_K_current (picoA)"
    legend_algebraic[51] = "i_Ks in component slow_delayed_rectifier_K_current (picoA)"
    legend_algebraic[53] = "i_Ca_L in component L_type_Ca_channel (picoA)"
    legend_algebraic[60] = "i_CaP in component sarcolemmal_calcium_pump_current (picoA)"
    legend_algebraic[55] = "i_NaK in component sodium_potassium_pump (picoA)"
    legend_algebraic[59] = "i_NaCa in component Na_Ca_exchanger_current (picoA)"
    legend_algebraic[56] = "i_B_Na in component background_currents (picoA)"
    legend_algebraic[57] = "i_B_Ca in component background_currents (picoA)"
    legend_algebraic[58] = "i_B_Cl in component background_currents (picoA)"
    legend_algebraic[52] = "i_K_Ach in component i_K_Ach (picoA)"
    legend_constants[4] = "stim_start in component membrane (millisecond)"
    legend_constants[5] = "stim_end in component membrane (millisecond)"
    legend_constants[6] = "stim_period in component membrane (millisecond)"
    legend_constants[7] = "stim_duration in component membrane (millisecond)"
    legend_constants[8] = "stim_amplitude in component membrane (picoA)"
    legend_algebraic[15] = "E_Na in component fast_sodium_current (millivolt)"
    legend_constants[9] = "g_Na in component fast_sodium_current (nanoS_per_picoF)"
    legend_states[1] = "Na_i in component intracellular_ion_concentrations (millimolar)"
    legend_constants[10] = "Na_o in component standard_ionic_concentrations (millimolar)"
    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[1] = "alpha_m in component fast_sodium_current_m_gate (per_millisecond)"
    legend_algebraic[16] = "beta_m in component fast_sodium_current_m_gate (per_millisecond)"
    legend_algebraic[30] = "m_inf in component fast_sodium_current_m_gate (dimensionless)"
    legend_algebraic[39] = "tau_m in component fast_sodium_current_m_gate (millisecond)"
    legend_algebraic[2] = "alpha_h in component fast_sodium_current_h_gate (per_millisecond)"
    legend_algebraic[17] = "beta_h in component fast_sodium_current_h_gate (per_millisecond)"
    legend_algebraic[31] = "h_inf in component fast_sodium_current_h_gate (dimensionless)"
    legend_algebraic[40] = "tau_h in component fast_sodium_current_h_gate (millisecond)"
    legend_algebraic[3] = "alpha_j in component fast_sodium_current_j_gate (per_millisecond)"
    legend_algebraic[18] = "beta_j in component fast_sodium_current_j_gate (per_millisecond)"
    legend_algebraic[32] = "j_inf in component fast_sodium_current_j_gate (dimensionless)"
    legend_algebraic[41] = "tau_j in component fast_sodium_current_j_gate (millisecond)"
    legend_algebraic[38] = "E_K in component time_independent_potassium_current (millivolt)"
    legend_constants[11] = "g_K1 in component time_independent_potassium_current (nanoS_per_picoF)"
    legend_constants[12] = "K_o in component standard_ionic_concentrations (millimolar)"
    legend_states[5] = "K_i in component intracellular_ion_concentrations (millimolar)"
    legend_constants[13] = "g_to in component transient_outward_K_current (nanoS_per_picoF)"
    legend_states[6] = "oa in component transient_outward_K_current_oa_gate (dimensionless)"
    legend_states[7] = "oi in component transient_outward_K_current_oi_gate (dimensionless)"
    legend_algebraic[4] = "tau_oa in component transient_outward_K_current_oa_gate (millisecond)"
    legend_algebraic[19] = "oa_infinity in component transient_outward_K_current_oa_gate (dimensionless)"
    legend_algebraic[5] = "alpha_oi in component transient_outward_K_current_oi_gate (per_millisecond)"
    legend_algebraic[20] = "beta_oi in component transient_outward_K_current_oi_gate (per_millisecond)"
    legend_algebraic[33] = "tau_oi in component transient_outward_K_current_oi_gate (millisecond)"
    legend_algebraic[42] = "oi_infinity in component transient_outward_K_current_oi_gate (dimensionless)"
    legend_constants[14] = "g_Kur in component ultrarapid_delayed_rectifier_K_current (nanoS_per_picoF)"
    legend_states[8] = "ua in component ultrarapid_delayed_rectifier_K_current_ua_gate (dimensionless)"
    legend_states[9] = "ui in component ultrarapid_delayed_rectifier_K_current_ui_gate (dimensionless)"
    legend_algebraic[6] = "alpha_ua in component ultrarapid_delayed_rectifier_K_current_ua_gate (per_millisecond)"
    legend_algebraic[21] = "beta_ua in component ultrarapid_delayed_rectifier_K_current_ua_gate (per_millisecond)"
    legend_algebraic[34] = "tau_ua in component ultrarapid_delayed_rectifier_K_current_ua_gate (millisecond)"
    legend_algebraic[43] = "ua_infinity in component ultrarapid_delayed_rectifier_K_current_ua_gate (dimensionless)"
    legend_algebraic[7] = "alpha_ui in component ultrarapid_delayed_rectifier_K_current_ui_gate (per_millisecond)"
    legend_algebraic[22] = "beta_ui in component ultrarapid_delayed_rectifier_K_current_ui_gate (per_millisecond)"
    legend_algebraic[35] = "tau_ui in component ultrarapid_delayed_rectifier_K_current_ui_gate (millisecond)"
    legend_algebraic[44] = "ui_infinity in component ultrarapid_delayed_rectifier_K_current_ui_gate (dimensionless)"
    legend_constants[15] = "g_Kr in component rapid_delayed_rectifier_K_current (nanoS_per_picoF)"
    legend_states[10] = "xr in component rapid_delayed_rectifier_K_current_xr_gate (dimensionless)"
    legend_algebraic[8] = "alpha_xr in component rapid_delayed_rectifier_K_current_xr_gate (per_millisecond)"
    legend_algebraic[23] = "beta_xr in component rapid_delayed_rectifier_K_current_xr_gate (per_millisecond)"
    legend_algebraic[36] = "tau_xr in component rapid_delayed_rectifier_K_current_xr_gate (millisecond)"
    legend_algebraic[45] = "xr_infinity in component rapid_delayed_rectifier_K_current_xr_gate (dimensionless)"
    legend_constants[16] = "g_Ks in component slow_delayed_rectifier_K_current (nanoS_per_picoF)"
    legend_states[11] = "xs in component slow_delayed_rectifier_K_current_xs_gate (dimensionless)"
    legend_algebraic[9] = "alpha_xs in component slow_delayed_rectifier_K_current_xs_gate (per_millisecond)"
    legend_algebraic[24] = "beta_xs in component slow_delayed_rectifier_K_current_xs_gate (per_millisecond)"
    legend_algebraic[37] = "tau_xs in component slow_delayed_rectifier_K_current_xs_gate (millisecond)"
    legend_algebraic[46] = "xs_infinity in component slow_delayed_rectifier_K_current_xs_gate (dimensionless)"
    legend_constants[17] = "g_K_Ach in component i_K_Ach (nanoS_per_picoF)"
    legend_states[12] = "xa in component i_K_Ach_xa_gate (dimensionless)"
    legend_algebraic[10] = "tau_xa in component i_K_Ach_xa_gate (millisecond)"
    legend_algebraic[25] = "xa_infinity in component i_K_Ach_xa_gate (dimensionless)"
    legend_constants[18] = "g_Ca_L in component L_type_Ca_channel (nanoS_per_picoF)"
    legend_states[13] = "Ca_i in component intracellular_ion_concentrations (millimolar)"
    legend_states[14] = "d in component L_type_Ca_channel_d_gate (dimensionless)"
    legend_states[15] = "f in component L_type_Ca_channel_f_gate (dimensionless)"
    legend_states[16] = "f_Ca in component L_type_Ca_channel_f_Ca_gate (dimensionless)"
    legend_algebraic[11] = "d_infinity in component L_type_Ca_channel_d_gate (dimensionless)"
    legend_algebraic[26] = "tau_d in component L_type_Ca_channel_d_gate (millisecond)"
    legend_algebraic[12] = "f_infinity in component L_type_Ca_channel_f_gate (dimensionless)"
    legend_algebraic[27] = "tau_f in component L_type_Ca_channel_f_gate (millisecond)"
    legend_algebraic[13] = "f_Ca_infinity in component L_type_Ca_channel_f_Ca_gate (dimensionless)"
    legend_constants[43] = "tau_f_Ca in component L_type_Ca_channel_f_Ca_gate (millisecond)"
    legend_constants[19] = "Km_Na_i in component sodium_potassium_pump (millimolar)"
    legend_constants[20] = "Km_K_o in component sodium_potassium_pump (millimolar)"
    legend_constants[21] = "i_NaK_max in component sodium_potassium_pump (picoA_per_picoF)"
    legend_algebraic[54] = "f_NaK in component sodium_potassium_pump (dimensionless)"
    legend_constants[44] = "sigma in component sodium_potassium_pump (dimensionless)"
    legend_constants[22] = "g_B_Na in component background_currents (nanoS_per_picoF)"
    legend_constants[23] = "g_B_Ca in component background_currents (nanoS_per_picoF)"
    legend_constants[24] = "g_B_Cl in component background_currents (nanoS_per_picoF)"
    legend_constants[25] = "Ca_o in component standard_ionic_concentrations (millimolar)"
    legend_states[17] = "Cl_i in component intracellular_ion_concentrations (millimolar)"
    legend_constants[26] = "Cl_o in component standard_ionic_concentrations (millimolar)"
    legend_constants[27] = "I_NaCa_max in component Na_Ca_exchanger_current (picoA_per_picoF)"
    legend_constants[28] = "K_mNa in component Na_Ca_exchanger_current (millimolar)"
    legend_constants[29] = "K_mCa in component Na_Ca_exchanger_current (millimolar)"
    legend_constants[30] = "K_sat in component Na_Ca_exchanger_current (dimensionless)"
    legend_constants[31] = "gamma in component Na_Ca_exchanger_current (dimensionless)"
    legend_constants[32] = "i_CaP_max in component sarcolemmal_calcium_pump_current (picoA_per_picoF)"
    legend_algebraic[61] = "i_rel in component Ca_release_current_from_JSR (millimolar_per_millisecond)"
    legend_algebraic[62] = "Fn in component Ca_release_current_from_JSR (dimensionless)"
    legend_constants[33] = "K_rel in component Ca_release_current_from_JSR (per_millisecond)"
    legend_constants[46] = "V_rel in component intracellular_ion_concentrations (micrometre_3)"
    legend_states[18] = "Ca_rel in component intracellular_ion_concentrations (millimolar)"
    legend_states[19] = "u in component Ca_release_current_from_JSR_u_gate (dimensionless)"
    legend_states[20] = "v in component Ca_release_current_from_JSR_v_gate (dimensionless)"
    legend_states[21] = "w in component Ca_release_current_from_JSR_w_gate (dimensionless)"
    legend_constants[45] = "tau_u in component Ca_release_current_from_JSR_u_gate (millisecond)"
    legend_algebraic[64] = "u_infinity in component Ca_release_current_from_JSR_u_gate (dimensionless)"
    legend_algebraic[65] = "tau_v in component Ca_release_current_from_JSR_v_gate (millisecond)"
    legend_algebraic[68] = "v_infinity in component Ca_release_current_from_JSR_v_gate (dimensionless)"
    legend_algebraic[14] = "tau_w in component Ca_release_current_from_JSR_w_gate (millisecond)"
    legend_algebraic[28] = "w_infinity in component Ca_release_current_from_JSR_w_gate (dimensionless)"
    legend_algebraic[63] = "i_tr in component transfer_current_from_NSR_to_JSR (millimolar_per_millisecond)"
    legend_constants[34] = "tau_tr in component transfer_current_from_NSR_to_JSR (millisecond)"
    legend_states[22] = "Ca_up in component intracellular_ion_concentrations (millimolar)"
    legend_constants[35] = "I_up_max in component Ca_uptake_current_by_the_NSR (millimolar_per_millisecond)"
    legend_algebraic[66] = "i_up in component Ca_uptake_current_by_the_NSR (millimolar_per_millisecond)"
    legend_constants[36] = "K_up in component Ca_uptake_current_by_the_NSR (millimolar)"
    legend_algebraic[69] = "i_up_leak in component Ca_leak_current_by_the_NSR (millimolar_per_millisecond)"
    legend_constants[37] = "Ca_up_max in component Ca_leak_current_by_the_NSR (millimolar)"
    legend_constants[38] = "CMDN_max in component Ca_buffers (millimolar)"
    legend_constants[39] = "TRPN_max in component Ca_buffers (millimolar)"
    legend_constants[40] = "CSQN_max in component Ca_buffers (millimolar)"
    legend_states[23] = "Ca_CMDN in component Ca_buffers (millimolar)"
    legend_states[24] = "Ca_TRPN in component Ca_buffers (millimolar)"
    legend_states[25] = "Ca_CSQN in component Ca_buffers (millimolar)"
    legend_algebraic[70] = "var_CMDN in component Ca_buffers (millimolar)"
    legend_algebraic[71] = "var_TRPN in component Ca_buffers (millimolar)"
    legend_algebraic[67] = "var_CSQN in component Ca_buffers (millimolar)"
    legend_constants[41] = "V_cell in component intracellular_ion_concentrations (micrometre_3)"
    legend_constants[42] = "V_i in component intracellular_ion_concentrations (micrometre_3)"
    legend_constants[47] = "V_up in component intracellular_ion_concentrations (micrometre_3)"
    legend_rates[0] = "d/dt V in component membrane (millivolt)"
    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[6] = "d/dt oa in component transient_outward_K_current_oa_gate (dimensionless)"
    legend_rates[7] = "d/dt oi in component transient_outward_K_current_oi_gate (dimensionless)"
    legend_rates[8] = "d/dt ua in component ultrarapid_delayed_rectifier_K_current_ua_gate (dimensionless)"
    legend_rates[9] = "d/dt ui in component ultrarapid_delayed_rectifier_K_current_ui_gate (dimensionless)"
    legend_rates[10] = "d/dt xr in component rapid_delayed_rectifier_K_current_xr_gate (dimensionless)"
    legend_rates[11] = "d/dt xs in component slow_delayed_rectifier_K_current_xs_gate (dimensionless)"
    legend_rates[12] = "d/dt xa in component i_K_Ach_xa_gate (dimensionless)"
    legend_rates[14] = "d/dt d in component L_type_Ca_channel_d_gate (dimensionless)"
    legend_rates[15] = "d/dt f in component L_type_Ca_channel_f_gate (dimensionless)"
    legend_rates[16] = "d/dt f_Ca in component L_type_Ca_channel_f_Ca_gate (dimensionless)"
    legend_rates[19] = "d/dt u in component Ca_release_current_from_JSR_u_gate (dimensionless)"
    legend_rates[20] = "d/dt v in component Ca_release_current_from_JSR_v_gate (dimensionless)"
    legend_rates[21] = "d/dt w in component Ca_release_current_from_JSR_w_gate (dimensionless)"
    legend_rates[23] = "d/dt Ca_CMDN in component Ca_buffers (millimolar)"
    legend_rates[24] = "d/dt Ca_TRPN in component Ca_buffers (millimolar)"
    legend_rates[25] = "d/dt Ca_CSQN in component Ca_buffers (millimolar)"
    legend_rates[1] = "d/dt Na_i in component intracellular_ion_concentrations (millimolar)"
    legend_rates[5] = "d/dt K_i in component intracellular_ion_concentrations (millimolar)"
    legend_rates[17] = "d/dt Cl_i in component intracellular_ion_concentrations (millimolar)"
    legend_rates[13] = "d/dt Ca_i in component intracellular_ion_concentrations (millimolar)"
    legend_rates[22] = "d/dt Ca_up in component intracellular_ion_concentrations (millimolar)"
    legend_rates[18] = "d/dt Ca_rel in component intracellular_ion_concentrations (millimolar)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    states[0] = -85.53
    constants[0] = 8.3143
    constants[1] = 310
    constants[2] = 96.4867
    constants[3] = 100
    constants[4] = 50
    constants[5] = 50000
    constants[6] = 1000
    constants[7] = 2
    constants[8] = -2000
    constants[9] = 7.8
    states[1] = 11.75
    constants[10] = 140
    states[2] = 1.972e-3
    states[3] = 9.791e-1
    states[4] = 9.869e-1
    constants[11] = 0.036
    constants[12] = 5.4
    states[5] = 138.4
    constants[13] = 0.07104
    states[6] = 7.164e-2
    states[7] = 9.992e-1
    constants[14] = 0.0115
    states[8] = 0.05869
    states[9] = 9.987e-1
    constants[15] = 0.022475
    states[10] = 7.433e-7
    constants[16] = 0.0832
    states[11] = 0.01791
    constants[17] = 0.0065
    states[12] = 1e-5
    constants[18] = 0.255
    states[13] = 1.024e-4
    states[14] = 4.757e-6
    states[15] = 0.9999
    states[16] = 0.7484
    constants[19] = 10
    constants[20] = 1.5
    constants[21] = 0.6
    constants[22] = 1e-5
    constants[23] = 1e-5
    constants[24] = 0.0055
    constants[25] = 1.8
    states[17] = 29.26
    constants[26] = 132
    constants[27] = 1600
    constants[28] = 87.5
    constants[29] = 1.38
    constants[30] = 0.1
    constants[31] = 0.35
    constants[32] = 0.275
    constants[33] = 8
    states[18] = 1.502
    states[19] = 0
    states[20] = 1
    states[21] = 0.9993
    constants[34] = 180
    states[22] = 1.502
    constants[35] = 0.0035
    constants[36] = 6e-4
    constants[37] = 27
    constants[38] = 0.045
    constants[39] = 0.35
    constants[40] = 10
    states[23] = 1.856e-3
    states[24] = 7.022e-3
    states[25] = 6.432
    constants[41] = 20100
    constants[42] = constants[41]*0.680000
    constants[43] = 2.00000
    constants[44] = (1.00000/7.00000)*(exp(constants[10]/67.3000)-1.00000)
    constants[45] = 11.2000
    constants[46] = 0.00480000*constants[41]
    constants[47] = 0.0552000*constants[41]
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    algebraic[13] = 0.290000+0.800000*(power(1.00000+(states[13]-0.000120000)/6.00000e-05, -1.00000))
    rates[16] = (algebraic[13]-states[16])/constants[43]
    algebraic[4] = 0.400000/exp((states[0]-15.0000)/20.0000)
    algebraic[19] = power(1.00000+exp((states[0]-12.0000)/-11.5000), -1.00000/3.00000)
    rates[6] = (algebraic[19]-states[6])/algebraic[4]
    algebraic[10] = 360.000+130.000*(1.00000-exp(-(states[0]+130.000)/50.0000))
    algebraic[25] = 1.00000/(1.00000+exp((-93.0000-states[0])/-15.2000))
    rates[12] = (algebraic[25]-states[12])/algebraic[10]
    algebraic[11] = power(1.00000+exp((-states[0]-2.00000)/5.00000), -1.00000)
    algebraic[26] = custom_piecewise([less(fabs(states[0]+10.0000) , 1.00000e-10), 0.763000 , True, (1.00000-exp((states[0]+10.0000)/-6.24000))/(0.0350000*(states[0]+10.0000)*(1.00000+exp((states[0]+10.0000)/-6.24000)))])
    rates[14] = (algebraic[11]-states[14])/algebraic[26]
    algebraic[12] = 1.00000/(1.00000+exp((states[0]+34.0000)/6.30000))
    algebraic[27] = 400.000/(1.00000+4.50000*exp(-(power((states[0]-9.00000)*0.0265000, 2.00000))))
    rates[15] = (algebraic[12]-states[15])/algebraic[27]
    algebraic[14] = custom_piecewise([less(fabs(states[0]-7.90000) , 1.00000e-10), (6.00000*0.200000)/1.30000 , True, (6.00000*(1.00000-exp(-(states[0]-7.90000)/5.00000)))/((1.00000+0.300000*exp(-(states[0]-7.90000)/5.00000))*1.00000*(states[0]-7.90000))])
    algebraic[28] = 1.00000-power(1.00000+exp(-(states[0]-40.0000)/17.0000), -1.00000)
    rates[21] = (algebraic[28]-states[21])/algebraic[14]
    algebraic[1] = custom_piecewise([equal(states[0] , -47.1300), 3.20000 , True, (0.320000*(states[0]+47.1300))/(1.00000-exp(-0.100000*(states[0]+47.1300)))])
    algebraic[16] = 0.0800000*exp(-states[0]/11.0000)
    algebraic[30] = algebraic[1]/(algebraic[1]+algebraic[16])
    algebraic[39] = 1.00000/(algebraic[1]+algebraic[16])
    rates[2] = (algebraic[30]-states[2])/algebraic[39]
    algebraic[2] = custom_piecewise([less(states[0] , -40.0000), 0.135000*exp((states[0]+80.0000)/-6.80000) , True, 0.00000])
    algebraic[17] = 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[31] = algebraic[2]/(algebraic[2]+algebraic[17])
    algebraic[40] = 1.00000/(algebraic[2]+algebraic[17])
    rates[3] = (algebraic[31]-states[3])/algebraic[40]
    algebraic[3] = 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[18] = 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[32] = algebraic[3]/(algebraic[3]+algebraic[18])
    algebraic[41] = 1.00000/(algebraic[3]+algebraic[18])
    rates[4] = (algebraic[32]-states[4])/algebraic[41]
    algebraic[5] = 1.00000/(1.20000+exp((states[0]+95.2000)/5.85000))
    algebraic[20] = 1.00000/(9.54000+exp((states[0]-48.0000)/-20.0000))
    algebraic[33] = power(algebraic[5]+algebraic[20], -1.00000)
    algebraic[42] = power(1.00000+exp((states[0]+31.0000)/6.45000), -1.00000)
    rates[7] = (algebraic[42]-states[7])/algebraic[33]
    algebraic[6] = 1.47000/(exp((states[0]+33.2000)/-30.6300)+exp((states[0]-27.6000)/-30.6500))
    algebraic[21] = 0.420000/(exp((states[0]+26.6400)/2.49000)+exp((states[0]+44.4100)/20.3600))
    algebraic[34] = power(algebraic[6]+algebraic[21], -1.00000)
    algebraic[43] = power(1.00000+exp((states[0]+2.81000)/-9.49000), -1.00000/3.00000)
    rates[8] = (algebraic[43]-states[8])/algebraic[34]
    algebraic[7] = 1.00000/(21.0000+exp((states[0]-185.000)/-28.0000))
    algebraic[22] = 1.00000*exp((states[0]-158.000)/16.0000)
    algebraic[35] = power(algebraic[7]+algebraic[22], -1.00000)
    algebraic[44] = power(1.00000+exp((states[0]-99.4500)/27.4800), -1.00000)
    rates[9] = (algebraic[44]-states[9])/algebraic[35]
    algebraic[8] = (0.0400000*(states[0]-248.000))/(1.00000-exp((states[0]-248.000)/-28.0000))
    algebraic[23] = (0.0280000*(states[0]+163.000))/(exp((states[0]+163.000)/21.0000)-1.00000)
    algebraic[36] = power(algebraic[8]+algebraic[23], -1.00000)
    algebraic[45] = power(1.00000+exp((states[0]+7.65400)/-5.37700), -1.00000)
    rates[10] = (algebraic[45]-states[10])/algebraic[36]
    algebraic[9] = custom_piecewise([less(fabs(states[0]+28.5000) , 1.00000e-10), 0.00115000 , True, (1.00000e-05*(states[0]+28.5000))/(1.00000-exp((states[0]+28.5000)/-115.000))])
    algebraic[24] = custom_piecewise([less(fabs(states[0]+28.5000) , 1.00000e-10), 0.000759000 , True, (0.000230000*(states[0]+28.5000))/(exp((states[0]+28.5000)/3.30000)-1.00000)])
    algebraic[37] = power(algebraic[9]+algebraic[24], -1.00000)
    algebraic[46] = power(1.00000+exp((states[0]-13.0000)/-12.0000), -0.500000)
    rates[11] = (algebraic[46]-states[11])/algebraic[37]
    algebraic[38] = ((constants[0]*constants[1])/constants[2])*log(constants[12]/states[5])
    algebraic[47] = (constants[3]*constants[11]*(states[0]-algebraic[38]))/(0.660000+exp(0.0780000*((states[0]-algebraic[38])-18.0000)))
    algebraic[48] = constants[3]*constants[13]*(power(states[6], 3.00000))*states[7]*(states[0]-algebraic[38])
    algebraic[49] = constants[3]*constants[14]*(1.00000+3.00000/(1.00000+exp((states[0]-14.0000)/-6.00000)))*(power(states[8], 3.00000))*states[9]*(states[0]-algebraic[38])
    algebraic[50] = constants[3]*constants[15]*states[10]*(states[0]-algebraic[38])*(0.600000+1.00000/(0.500000+0.500000*exp((states[0]+8.00000)/24.4000)))
    algebraic[51] = constants[3]*constants[16]*(power(states[11], 2.00000))*(states[0]-algebraic[38])
    algebraic[54] = power(1.00000+0.124500*exp((-0.100000*constants[2]*states[0])/(constants[0]*constants[1]))+0.0365000*constants[44]*exp((-constants[2]*states[0])/(constants[0]*constants[1])), -1.00000)
    algebraic[55] = (((constants[3]*constants[21]*algebraic[54])/(1.00000+power(constants[19]/states[1], 1.50000)))*constants[12])/(constants[12]+constants[20])
    algebraic[52] = (constants[3]*constants[17]*states[12]*(states[0]-algebraic[38]))/(0.100000+exp(0.0780000*((states[0]-algebraic[38])-65.0000)))
    rates[5] = (2.00000*algebraic[55]-(algebraic[47]+algebraic[48]+algebraic[49]+algebraic[50]+algebraic[51]+algebraic[52]))/(constants[42]*constants[2])
    algebraic[58] = constants[3]*constants[24]*(states[0]-((constants[0]*constants[1])/constants[2])*log(states[17]/constants[26]))
    rates[17] = algebraic[58]/(constants[42]*constants[2])
    algebraic[15] = ((constants[0]*constants[1])/constants[2])*log(constants[10]/states[1])
    algebraic[29] = constants[3]*constants[9]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[15])
    algebraic[59] = (constants[3]*constants[27]*(exp((constants[31]*constants[2]*states[0])/(constants[0]*constants[1]))*(power(states[1], 3.00000))*constants[25]-exp(((constants[31]-1.00000)*constants[2]*states[0])/(constants[0]*constants[1]))*(power(constants[10], 3.00000))*states[13]))/((power(constants[28], 3.00000)+power(constants[10], 3.00000))*(constants[29]+constants[25])*(1.00000+constants[30]*exp(((constants[31]-1.00000)*states[0]*constants[2])/(constants[0]*constants[1]))))
    algebraic[56] = constants[3]*constants[22]*(states[0]-algebraic[15])
    rates[1] = (-3.00000*algebraic[55]-(3.00000*algebraic[59]+algebraic[56]+algebraic[29]))/(constants[42]*constants[2])
    algebraic[0] = 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[53] = constants[3]*constants[18]*states[14]*states[15]*states[16]*(states[0]-60.0000)
    algebraic[60] = (constants[3]*constants[32]*states[13])/(0.000500000+states[13])
    algebraic[57] = constants[3]*constants[23]*(states[0]-((constants[0]*constants[1])/(2.00000*constants[2]))*log(constants[25]/states[13]))
    rates[0] = -(algebraic[29]+algebraic[47]+algebraic[48]+algebraic[49]+algebraic[50]+algebraic[51]+algebraic[56]+algebraic[57]+algebraic[55]+algebraic[60]+algebraic[59]+algebraic[53]+algebraic[0]+algebraic[58]+algebraic[52])/constants[3]
    algebraic[61] = constants[33]*(power(states[19], 2.00000))*states[20]*states[21]*(states[18]-states[13])
    algebraic[62] = 1000.00*(1.00000e-15*constants[46]*algebraic[61]-(1.00000e-15/(2.00000*constants[2]))*(0.500000*algebraic[53]-0.200000*algebraic[59]))
    algebraic[64] = power(1.00000+exp(-(algebraic[62]-3.41750e-13)/1.36700e-15), -1.00000)
    rates[19] = (algebraic[64]-states[19])/constants[45]
    algebraic[67] = 0.480000*states[18]*(1.00000-states[25]/constants[40])-(0.400000*states[25])/constants[40]
    rates[25] = algebraic[67]*constants[40]
    algebraic[63] = (states[22]-states[18])/constants[34]
    rates[18] = (algebraic[63]-algebraic[61])-31.0000*algebraic[67]
    algebraic[65] = 1.91000+2.09000*(power(1.00000+exp(-(algebraic[62]-3.41750e-13)/1.36700e-15), -1.00000))
    algebraic[68] = 1.00000-power(1.00000+exp(-(algebraic[62]-6.83500e-14)/1.36700e-15), -1.00000)
    rates[20] = (algebraic[68]-states[20])/algebraic[65]
    algebraic[66] = constants[35]/(1.00000+constants[36]/states[13])
    algebraic[69] = (constants[35]*states[22])/constants[37]
    rates[22] = algebraic[66]-(algebraic[69]+(algebraic[63]*constants[46])/constants[47])
    algebraic[70] = 200.000*states[13]*(1.00000-states[23]/constants[38])-(0.476000*states[23])/constants[38]
    rates[23] = algebraic[70]*constants[38]
    algebraic[71] = 78.4000*states[13]*(1.00000-states[24]/constants[39])-(0.392000*states[24])/constants[39]
    rates[24] = algebraic[71]*constants[39]
    rates[13] = (((2.00000*algebraic[59]-(algebraic[60]+algebraic[53]+algebraic[57]))/(2.00000*constants[42]*constants[2])+(constants[47]*(algebraic[69]-algebraic[66])+algebraic[61]*constants[46])/constants[42])-constants[39]*algebraic[71])-constants[38]*algebraic[70]
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[13] = 0.290000+0.800000*(power(1.00000+(states[13]-0.000120000)/6.00000e-05, -1.00000))
    algebraic[4] = 0.400000/exp((states[0]-15.0000)/20.0000)
    algebraic[19] = power(1.00000+exp((states[0]-12.0000)/-11.5000), -1.00000/3.00000)
    algebraic[10] = 360.000+130.000*(1.00000-exp(-(states[0]+130.000)/50.0000))
    algebraic[25] = 1.00000/(1.00000+exp((-93.0000-states[0])/-15.2000))
    algebraic[11] = power(1.00000+exp((-states[0]-2.00000)/5.00000), -1.00000)
    algebraic[26] = custom_piecewise([less(fabs(states[0]+10.0000) , 1.00000e-10), 0.763000 , True, (1.00000-exp((states[0]+10.0000)/-6.24000))/(0.0350000*(states[0]+10.0000)*(1.00000+exp((states[0]+10.0000)/-6.24000)))])
    algebraic[12] = 1.00000/(1.00000+exp((states[0]+34.0000)/6.30000))
    algebraic[27] = 400.000/(1.00000+4.50000*exp(-(power((states[0]-9.00000)*0.0265000, 2.00000))))
    algebraic[14] = custom_piecewise([less(fabs(states[0]-7.90000) , 1.00000e-10), (6.00000*0.200000)/1.30000 , True, (6.00000*(1.00000-exp(-(states[0]-7.90000)/5.00000)))/((1.00000+0.300000*exp(-(states[0]-7.90000)/5.00000))*1.00000*(states[0]-7.90000))])
    algebraic[28] = 1.00000-power(1.00000+exp(-(states[0]-40.0000)/17.0000), -1.00000)
    algebraic[1] = custom_piecewise([equal(states[0] , -47.1300), 3.20000 , True, (0.320000*(states[0]+47.1300))/(1.00000-exp(-0.100000*(states[0]+47.1300)))])
    algebraic[16] = 0.0800000*exp(-states[0]/11.0000)
    algebraic[30] = algebraic[1]/(algebraic[1]+algebraic[16])
    algebraic[39] = 1.00000/(algebraic[1]+algebraic[16])
    algebraic[2] = custom_piecewise([less(states[0] , -40.0000), 0.135000*exp((states[0]+80.0000)/-6.80000) , True, 0.00000])
    algebraic[17] = 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[31] = algebraic[2]/(algebraic[2]+algebraic[17])
    algebraic[40] = 1.00000/(algebraic[2]+algebraic[17])
    algebraic[3] = 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[18] = 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[32] = algebraic[3]/(algebraic[3]+algebraic[18])
    algebraic[41] = 1.00000/(algebraic[3]+algebraic[18])
    algebraic[5] = 1.00000/(1.20000+exp((states[0]+95.2000)/5.85000))
    algebraic[20] = 1.00000/(9.54000+exp((states[0]-48.0000)/-20.0000))
    algebraic[33] = power(algebraic[5]+algebraic[20], -1.00000)
    algebraic[42] = power(1.00000+exp((states[0]+31.0000)/6.45000), -1.00000)
    algebraic[6] = 1.47000/(exp((states[0]+33.2000)/-30.6300)+exp((states[0]-27.6000)/-30.6500))
    algebraic[21] = 0.420000/(exp((states[0]+26.6400)/2.49000)+exp((states[0]+44.4100)/20.3600))
    algebraic[34] = power(algebraic[6]+algebraic[21], -1.00000)
    algebraic[43] = power(1.00000+exp((states[0]+2.81000)/-9.49000), -1.00000/3.00000)
    algebraic[7] = 1.00000/(21.0000+exp((states[0]-185.000)/-28.0000))
    algebraic[22] = 1.00000*exp((states[0]-158.000)/16.0000)
    algebraic[35] = power(algebraic[7]+algebraic[22], -1.00000)
    algebraic[44] = power(1.00000+exp((states[0]-99.4500)/27.4800), -1.00000)
    algebraic[8] = (0.0400000*(states[0]-248.000))/(1.00000-exp((states[0]-248.000)/-28.0000))
    algebraic[23] = (0.0280000*(states[0]+163.000))/(exp((states[0]+163.000)/21.0000)-1.00000)
    algebraic[36] = power(algebraic[8]+algebraic[23], -1.00000)
    algebraic[45] = power(1.00000+exp((states[0]+7.65400)/-5.37700), -1.00000)
    algebraic[9] = custom_piecewise([less(fabs(states[0]+28.5000) , 1.00000e-10), 0.00115000 , True, (1.00000e-05*(states[0]+28.5000))/(1.00000-exp((states[0]+28.5000)/-115.000))])
    algebraic[24] = custom_piecewise([less(fabs(states[0]+28.5000) , 1.00000e-10), 0.000759000 , True, (0.000230000*(states[0]+28.5000))/(exp((states[0]+28.5000)/3.30000)-1.00000)])
    algebraic[37] = power(algebraic[9]+algebraic[24], -1.00000)
    algebraic[46] = power(1.00000+exp((states[0]-13.0000)/-12.0000), -0.500000)
    algebraic[38] = ((constants[0]*constants[1])/constants[2])*log(constants[12]/states[5])
    algebraic[47] = (constants[3]*constants[11]*(states[0]-algebraic[38]))/(0.660000+exp(0.0780000*((states[0]-algebraic[38])-18.0000)))
    algebraic[48] = constants[3]*constants[13]*(power(states[6], 3.00000))*states[7]*(states[0]-algebraic[38])
    algebraic[49] = constants[3]*constants[14]*(1.00000+3.00000/(1.00000+exp((states[0]-14.0000)/-6.00000)))*(power(states[8], 3.00000))*states[9]*(states[0]-algebraic[38])
    algebraic[50] = constants[3]*constants[15]*states[10]*(states[0]-algebraic[38])*(0.600000+1.00000/(0.500000+0.500000*exp((states[0]+8.00000)/24.4000)))
    algebraic[51] = constants[3]*constants[16]*(power(states[11], 2.00000))*(states[0]-algebraic[38])
    algebraic[54] = power(1.00000+0.124500*exp((-0.100000*constants[2]*states[0])/(constants[0]*constants[1]))+0.0365000*constants[44]*exp((-constants[2]*states[0])/(constants[0]*constants[1])), -1.00000)
    algebraic[55] = (((constants[3]*constants[21]*algebraic[54])/(1.00000+power(constants[19]/states[1], 1.50000)))*constants[12])/(constants[12]+constants[20])
    algebraic[52] = (constants[3]*constants[17]*states[12]*(states[0]-algebraic[38]))/(0.100000+exp(0.0780000*((states[0]-algebraic[38])-65.0000)))
    algebraic[58] = constants[3]*constants[24]*(states[0]-((constants[0]*constants[1])/constants[2])*log(states[17]/constants[26]))
    algebraic[15] = ((constants[0]*constants[1])/constants[2])*log(constants[10]/states[1])
    algebraic[29] = constants[3]*constants[9]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[15])
    algebraic[59] = (constants[3]*constants[27]*(exp((constants[31]*constants[2]*states[0])/(constants[0]*constants[1]))*(power(states[1], 3.00000))*constants[25]-exp(((constants[31]-1.00000)*constants[2]*states[0])/(constants[0]*constants[1]))*(power(constants[10], 3.00000))*states[13]))/((power(constants[28], 3.00000)+power(constants[10], 3.00000))*(constants[29]+constants[25])*(1.00000+constants[30]*exp(((constants[31]-1.00000)*states[0]*constants[2])/(constants[0]*constants[1]))))
    algebraic[56] = constants[3]*constants[22]*(states[0]-algebraic[15])
    algebraic[0] = 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[53] = constants[3]*constants[18]*states[14]*states[15]*states[16]*(states[0]-60.0000)
    algebraic[60] = (constants[3]*constants[32]*states[13])/(0.000500000+states[13])
    algebraic[57] = constants[3]*constants[23]*(states[0]-((constants[0]*constants[1])/(2.00000*constants[2]))*log(constants[25]/states[13]))
    algebraic[61] = constants[33]*(power(states[19], 2.00000))*states[20]*states[21]*(states[18]-states[13])
    algebraic[62] = 1000.00*(1.00000e-15*constants[46]*algebraic[61]-(1.00000e-15/(2.00000*constants[2]))*(0.500000*algebraic[53]-0.200000*algebraic[59]))
    algebraic[64] = power(1.00000+exp(-(algebraic[62]-3.41750e-13)/1.36700e-15), -1.00000)
    algebraic[67] = 0.480000*states[18]*(1.00000-states[25]/constants[40])-(0.400000*states[25])/constants[40]
    algebraic[63] = (states[22]-states[18])/constants[34]
    algebraic[65] = 1.91000+2.09000*(power(1.00000+exp(-(algebraic[62]-3.41750e-13)/1.36700e-15), -1.00000))
    algebraic[68] = 1.00000-power(1.00000+exp(-(algebraic[62]-6.83500e-14)/1.36700e-15), -1.00000)
    algebraic[66] = constants[35]/(1.00000+constants[36]/states[13])
    algebraic[69] = (constants[35]*states[22])/constants[37]
    algebraic[70] = 200.000*states[13]*(1.00000-states[23]/constants[38])-(0.476000*states[23])/constants[38]
    algebraic[71] = 78.4000*states[13]*(1.00000-states[24]/constants[39])-(0.392000*states[24])/constants[39]
    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)