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 = 73
sizeStates = 31
sizeConstants = 102
from math import *
from numpy import *

def createLegends():
    legend_states = [""] * sizeStates
    legend_rates = [""] * sizeStates
    legend_algebraic = [""] * sizeAlgebraic
    legend_voi = ""
    legend_constants = [""] * sizeConstants
    legend_constants[0] = "Aca_IC50_IKr in component acacetin (uM)"
    legend_constants[1] = "Aca_IC50_IKs in component acacetin (uM)"
    legend_constants[2] = "Aca_IC50_Ito in component acacetin (uM)"
    legend_constants[3] = "Aca_hill_IKr in component acacetin (dimensionless)"
    legend_constants[4] = "Aca_hill_IKs in component acacetin (dimensionless)"
    legend_constants[5] = "Aca_hill_Ito in component acacetin (dimensionless)"
    legend_constants[6] = "conc in component acacetin (uM)"
    legend_constants[62] = "fKr in component acacetin (dimensionless)"
    legend_constants[63] = "fKs in component acacetin (dimensionless)"
    legend_constants[64] = "fto in component acacetin (dimensionless)"
    legend_constants[7] = "af in component af (dimensionless)"
    legend_constants[8] = "Aj_nj in component cell (um2)"
    legend_constants[9] = "BCa in component calcium (mM)"
    legend_constants[10] = "CSQN in component calcium (mM)"
    legend_states[0] = "Ca_SRi in component calcium (mM)"
    legend_states[1] = "Ca_SRss in component calcium (mM)"
    legend_states[2] = "Ca_i in component calcium (mM)"
    legend_states[3] = "Ca_ss in component calcium (mM)"
    legend_constants[11] = "DCa in component calcium (m2_per_s_times_1e_minus_9)"
    legend_constants[12] = "DCaSR in component calcium (m2_per_s_times_1e_minus_9)"
    legend_constants[13] = "F in component phys (C_per_mmol)"
    legend_algebraic[44] = "ICaL in component ical (pA)"
    legend_algebraic[46] = "ICap in component icap (pA)"
    legend_algebraic[48] = "INaCa in component inaca (pA)"
    legend_algebraic[55] = "I_tot in component calcium (pA)"
    legend_algebraic[54] = "IbCa in component ibca (pA)"
    legend_algebraic[50] = "JCa in component calcium (kat_times_1e_minus_15)"
    legend_algebraic[66] = "JCass in component calcium (kat_times_1e_minus_15)"
    legend_algebraic[64] = "JSRCaSS in component calcium (kat_times_1e_minus_15)"
    legend_algebraic[49] = "JSRCai in component calcium (kat_times_1e_minus_15)"
    legend_algebraic[0] = "JSRCaleaki in component calcium (kat_times_1e_minus_15)"
    legend_algebraic[19] = "JSRCaleakss in component calcium (kat_times_1e_minus_15)"
    legend_algebraic[45] = "J_SERCASR in component serca (kat_times_1e_minus_15)"
    legend_algebraic[61] = "J_SERCASRss in component serca (kat_times_1e_minus_15)"
    legend_algebraic[47] = "J_bulkSERCA in component serca (kat_times_1e_minus_15)"
    legend_algebraic[63] = "J_bulkSERCAss in component serca (kat_times_1e_minus_15)"
    legend_algebraic[31] = "Jj_nj in component calcium (kat_times_1e_minus_15)"
    legend_algebraic[43] = "Jreli in component ryr (kat_times_1e_minus_15)"
    legend_algebraic[59] = "Jrelss in component ryr (kat_times_1e_minus_15)"
    legend_constants[14] = "KdBCa in component calcium (mM)"
    legend_constants[15] = "KdCSQN in component calcium (mM)"
    legend_constants[16] = "KdSLhigh in component calcium (mM)"
    legend_constants[17] = "KdSLlow in component calcium (mM)"
    legend_constants[18] = "SLhigh in component calcium (mM)"
    legend_constants[19] = "SLlow in component calcium (mM)"
    legend_constants[66] = "VSRi in component cell (um3)"
    legend_constants[67] = "VSRss in component cell (um3)"
    legend_constants[65] = "Vnj in component cell (um3)"
    legend_constants[93] = "Vss in component cell (um3)"
    legend_algebraic[35] = "calcium_Ca_SRi_beta in component calcium (dimensionless)"
    legend_algebraic[36] = "calcium_Ca_SRss_beta in component calcium (dimensionless)"
    legend_algebraic[39] = "calcium_Ca_i_beta in component calcium (dimensionless)"
    legend_algebraic[40] = "calcium_Ca_ss_beta in component calcium (dimensionless)"
    legend_constants[68] = "dx2 in component cell (um2)"
    legend_constants[20] = "kSRleak in component calcium (mS_per_uF)"
    legend_constants[69] = "scaling in component calcium (dimensionless)"
    legend_voi = "time in component engine (ms)"
    legend_constants[21] = "xj_nj in component cell (um)"
    legend_constants[22] = "Cm in component cell (pF)"
    legend_constants[23] = "Vi in component cell (um3)"
    legend_constants[24] = "dx in component cell (um)"
    legend_constants[25] = "duration in component engine (ms)"
    legend_constants[26] = "offset in component engine (ms)"
    legend_algebraic[42] = "pace in component engine (dimensionless)"
    legend_constants[27] = "period in component engine (ms)"
    legend_algebraic[53] = "ECa in component nernst (mV)"
    legend_states[4] = "V in component membrane (mV)"
    legend_constants[70] = "gbCa in component ibca (mS_per_uF)"
    legend_algebraic[68] = "ENa in component nernst (mV)"
    legend_algebraic[69] = "IbNa in component ibna (pA)"
    legend_constants[71] = "gbNa in component ibna (mS_per_uF)"
    legend_constants[28] = "ErL in component ical (mV)"
    legend_states[5] = "d in component ical (dimensionless)"
    legend_states[6] = "f in component ical (dimensionless)"
    legend_states[7] = "fca in component ical (dimensionless)"
    legend_constants[72] = "gCaL in component ical (mS_per_uF)"
    legend_algebraic[1] = "ical_d_a in component ical (ms)"
    legend_algebraic[20] = "ical_d_inf in component ical (dimensionless)"
    legend_algebraic[32] = "ical_d_tau in component ical (ms)"
    legend_algebraic[2] = "ical_f_inf in component ical (dimensionless)"
    legend_algebraic[21] = "ical_f_tau in component ical (ms)"
    legend_algebraic[3] = "ical_fca_inf in component ical (dimensionless)"
    legend_constants[29] = "ical_fca_tau in component ical (ms)"
    legend_constants[30] = "icapbar in component icap (A_per_F)"
    legend_constants[31] = "kmcap in component icap (mM)"
    legend_algebraic[56] = "EK in component nernst (mV)"
    legend_algebraic[58] = "IK1 in component ik1 (pA)"
    legend_constants[73] = "gK1 in component ik1 (mS_per_uF)"
    legend_algebraic[60] = "IKr in component ikr (pA)"
    legend_constants[74] = "gKr in component ikr (mS_per_uF)"
    legend_algebraic[4] = "ikr_xr_a in component ikr (mS_per_uF)"
    legend_algebraic[22] = "ikr_xr_b in component ikr (mS_per_uF)"
    legend_algebraic[33] = "ikr_xr_inf in component ikr (dimensionless)"
    legend_algebraic[37] = "ikr_xr_tau in component ikr (ms)"
    legend_states[8] = "xr in component ikr (dimensionless)"
    legend_algebraic[62] = "IKs in component iks (pA)"
    legend_constants[75] = "gKs in component iks (mS_per_uF)"
    legend_algebraic[5] = "iks_xs_a in component iks (mS_per_uF)"
    legend_algebraic[23] = "iks_xs_b in component iks (mS_per_uF)"
    legend_algebraic[34] = "iks_xs_inf in component iks (dimensionless)"
    legend_algebraic[38] = "iks_xs_tau in component iks (ms)"
    legend_states[9] = "xs in component iks (dimensionless)"
    legend_states[10] = "BC in component ikur (dimensionless)"
    legend_states[11] = "BO in component ikur (dimensionless)"
    legend_constants[76] = "FRT in component phys (per_mV)"
    legend_algebraic[65] = "IKur in component ikur (pA)"
    legend_constants[32] = "KC in component ikur (m3_per_s_per_mol_times_1e6)"
    legend_constants[33] = "KO in component ikur (m3_per_s_per_mol_times_1e6)"
    legend_constants[34] = "K_Q10 in component ikur (dimensionless)"
    legend_constants[35] = "LC in component ikur (mS_per_uF)"
    legend_constants[36] = "LO in component ikur (mS_per_uF)"
    legend_constants[77] = "ZKC in component ikur (dimensionless)"
    legend_constants[78] = "ZKO in component ikur (dimensionless)"
    legend_constants[37] = "ZLC in component ikur (dimensionless)"
    legend_constants[79] = "ZLO in component ikur (dimensionless)"
    legend_states[12] = "a in component ikur (dimensionless)"
    legend_constants[80] = "gKur in component ikur (mS_per_uF)"
    legend_states[13] = "i in component ikur (dimensionless)"
    legend_algebraic[6] = "ikur_a_inf in component ikur (dimensionless)"
    legend_algebraic[24] = "ikur_a_tau in component ikur (ms)"
    legend_algebraic[7] = "ikur_i_inf in component ikur (dimensionless)"
    legend_algebraic[25] = "ikur_i_tau in component ikur (ms)"
    legend_states[14] = "BA in component ina (dimensionless)"
    legend_states[15] = "BI in component ina (dimensionless)"
    legend_algebraic[70] = "INa in component ina (pA)"
    legend_constants[81] = "drug_Ka in component ina (m3_per_s_per_mol_times_1e6)"
    legend_constants[82] = "drug_Ki in component ina (m3_per_s_per_mol_times_1e6)"
    legend_constants[38] = "drug_La in component ina (mS_per_uF)"
    legend_constants[39] = "drug_Li in component ina (mS_per_uF)"
    legend_constants[40] = "drug_concen in component ina (uM)"
    legend_constants[41] = "gNa in component ina (mS_per_uF)"
    legend_states[16] = "h in component ina (dimensionless)"
    legend_algebraic[8] = "ina_h_alpha in component ina (mS_per_uF)"
    legend_algebraic[26] = "ina_h_beta in component ina (mS_per_uF)"
    legend_algebraic[9] = "ina_j_alpha in component ina (mS_per_uF)"
    legend_algebraic[27] = "ina_j_beta in component ina (mS_per_uF)"
    legend_algebraic[10] = "ina_m_alpha in component ina (mS_per_uF)"
    legend_algebraic[28] = "ina_m_beta in component ina (mS_per_uF)"
    legend_constants[83] = "ina_m_shift in component ina (mV)"
    legend_states[17] = "j in component ina (dimensionless)"
    legend_states[18] = "m in component ina (dimensionless)"
    legend_constants[42] = "Ca_o in component ion (mM)"
    legend_states[19] = "Na_i in component sodium (mM)"
    legend_constants[43] = "Na_o in component ion (mM)"
    legend_constants[44] = "gammalr in component inaca (dimensionless)"
    legend_constants[45] = "kmcalr in component inaca (mM)"
    legend_constants[46] = "kmnalr in component inaca (mM)"
    legend_constants[47] = "knacalr in component inaca (A_per_F)"
    legend_constants[48] = "ksatlr in component inaca (dimensionless)"
    legend_constants[84] = "scaling in component inaca (dimensionless)"
    legend_algebraic[52] = "INaK in component inak (pA)"
    legend_constants[85] = "I_bar in component inak (A_per_F)"
    legend_constants[49] = "K_o in component ion (mM)"
    legend_algebraic[51] = "fnak in component inak (dimensionless)"
    legend_constants[50] = "kmko in component inak (mM)"
    legend_constants[51] = "kmnai in component inak (mM)"
    legend_constants[86] = "sigma in component inak (dimensionless)"
    legend_algebraic[67] = "Ito in component ito (pA)"
    legend_constants[87] = "gto in component ito (mS_per_uF)"
    legend_algebraic[11] = "ito_r_inf in component ito (dimensionless)"
    legend_constants[88] = "ito_r_shift in component ito (mV)"
    legend_algebraic[29] = "ito_r_tau in component ito (ms)"
    legend_algebraic[12] = "ito_s_inf in component ito (dimensionless)"
    legend_algebraic[30] = "ito_s_tau in component ito (ms)"
    legend_states[20] = "r in component ito (dimensionless)"
    legend_states[21] = "s in component ito (dimensionless)"
    legend_constants[52] = "i_diff in component membrane (pA)"
    legend_algebraic[71] = "i_ion in component membrane (pA)"
    legend_algebraic[72] = "i_stim in component stimulus (pA)"
    legend_states[22] = "K_i in component potassium (mM)"
    legend_constants[53] = "R in component phys (J_per_mol_per_K)"
    legend_constants[54] = "T in component phys (kelvin)"
    legend_algebraic[41] = "RyRSRCai in component ryr (dimensionless)"
    legend_algebraic[57] = "RyRSRCass in component ryr (dimensionless)"
    legend_states[23] = "a_i in component ryr (dimensionless)"
    legend_states[24] = "a_ss in component ryr (dimensionless)"
    legend_states[25] = "c_i in component ryr (dimensionless)"
    legend_states[26] = "c_ss in component ryr (dimensionless)"
    legend_constants[89] = "fRyr in component ryr (dimensionless)"
    legend_constants[94] = "nui in component ryr (m3_per_s_times_1e_minus_15)"
    legend_constants[100] = "nuss in component ryr (m3_per_s_times_1e_minus_15)"
    legend_states[27] = "o_i in component ryr (dimensionless)"
    legend_states[28] = "o_ss in component ryr (dimensionless)"
    legend_algebraic[13] = "ryr_a_i_inf in component ryr (dimensionless)"
    legend_constants[95] = "ryr_a_i_tau in component ryr (ms)"
    legend_algebraic[14] = "ryr_a_ss_inf in component ryr (dimensionless)"
    legend_constants[96] = "ryr_a_ss_tau in component ryr (ms)"
    legend_algebraic[15] = "ryr_c_i_inf in component ryr (dimensionless)"
    legend_constants[97] = "ryr_c_i_tau in component ryr (ms)"
    legend_algebraic[16] = "ryr_c_ss_inf in component ryr (dimensionless)"
    legend_constants[98] = "ryr_c_ss_tau in component ryr (ms)"
    legend_algebraic[17] = "ryr_o_i_inf in component ryr (dimensionless)"
    legend_constants[55] = "ryr_o_i_tau in component ryr (ms)"
    legend_algebraic[18] = "ryr_o_ss_inf in component ryr (dimensionless)"
    legend_constants[56] = "ryr_o_ss_tau in component ryr (ms)"
    legend_constants[90] = "scaling in component ryr (dimensionless)"
    legend_constants[91] = "tau_scaling in component ryr (dimensionless)"
    legend_states[29] = "SERCACa in component serca (mM)"
    legend_states[30] = "SERCACass in component serca (mM)"
    legend_constants[57] = "cpumps in component serca (mM)"
    legend_constants[58] = "k1 in component serca (per_mM2_per_ms)"
    legend_constants[59] = "k2 in component serca (mS_per_uF)"
    legend_constants[60] = "k3 in component serca (per_mM2_per_ms)"
    legend_constants[61] = "k4 in component serca (mS_per_uF)"
    legend_constants[92] = "scaling in component serca (dimensionless)"
    legend_constants[99] = "amplitude in component stimulus (A_per_F)"
    legend_rates[0] = "d/dt Ca_SRi in component calcium (mM)"
    legend_rates[1] = "d/dt Ca_SRss in component calcium (mM)"
    legend_rates[2] = "d/dt Ca_i in component calcium (mM)"
    legend_rates[3] = "d/dt Ca_ss in component calcium (mM)"
    legend_rates[5] = "d/dt d in component ical (dimensionless)"
    legend_rates[6] = "d/dt f in component ical (dimensionless)"
    legend_rates[7] = "d/dt fca in component ical (dimensionless)"
    legend_rates[8] = "d/dt xr in component ikr (dimensionless)"
    legend_rates[9] = "d/dt xs in component iks (dimensionless)"
    legend_rates[10] = "d/dt BC in component ikur (dimensionless)"
    legend_rates[11] = "d/dt BO in component ikur (dimensionless)"
    legend_rates[12] = "d/dt a in component ikur (dimensionless)"
    legend_rates[13] = "d/dt i in component ikur (dimensionless)"
    legend_rates[14] = "d/dt BA in component ina (dimensionless)"
    legend_rates[15] = "d/dt BI in component ina (dimensionless)"
    legend_rates[16] = "d/dt h in component ina (dimensionless)"
    legend_rates[17] = "d/dt j in component ina (dimensionless)"
    legend_rates[18] = "d/dt m in component ina (dimensionless)"
    legend_rates[20] = "d/dt r in component ito (dimensionless)"
    legend_rates[21] = "d/dt s in component ito (dimensionless)"
    legend_rates[4] = "d/dt V in component membrane (mV)"
    legend_rates[22] = "d/dt K_i in component potassium (mM)"
    legend_rates[23] = "d/dt a_i in component ryr (dimensionless)"
    legend_rates[24] = "d/dt a_ss in component ryr (dimensionless)"
    legend_rates[25] = "d/dt c_i in component ryr (dimensionless)"
    legend_rates[26] = "d/dt c_ss in component ryr (dimensionless)"
    legend_rates[27] = "d/dt o_i in component ryr (dimensionless)"
    legend_rates[28] = "d/dt o_ss in component ryr (dimensionless)"
    legend_rates[29] = "d/dt SERCACa in component serca (mM)"
    legend_rates[30] = "d/dt SERCACass in component serca (mM)"
    legend_rates[19] = "d/dt Na_i in component sodium (mM)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    constants[0] = 32.4
    constants[1] = 81.4
    constants[2] = 9.3
    constants[3] = 0.9
    constants[4] = 0.8
    constants[5] = 0.9
    constants[6] = 1e-14
    constants[7] = 0.0
    constants[8] = 2.49232441199999994e+03
    constants[9] = 0.024
    constants[10] = 6.7
    states[0] = 9.89241162100000015e-01
    states[1] = 9.77916803700000004e-01
    states[2] = 1.40313306500000005e-04
    states[3] = 1.31359510499999994e-04
    constants[11] = 0.78
    constants[12] = 0.044
    constants[13] = 96.4867
    constants[14] = 0.00238
    constants[15] = 0.8
    constants[16] = 0.013
    constants[17] = 1.1
    constants[18] = 13.0
    constants[19] = 165.0
    constants[20] = 6e-06
    constants[21] = 0.8225
    constants[22] = 100.0
    constants[23] = 13668.0
    constants[24] = 1.625
    constants[25] = 0.5
    constants[26] = 100.0
    constants[27] = 1000.0
    states[4] = -7.71325583600000044e+01
    constants[28] = 65.0
    states[5] = 2.26716127700000005e-04
    states[6] = 9.35421288100000026e-01
    states[7] = 7.27082366600000030e-01
    constants[29] = 2.0
    constants[30] = 0.275
    constants[31] = 0.0005
    states[8] = 1.57418133000000000e-03
    states[9] = 2.22597964100000011e-02
    states[10] = 3.06272282199999992e-15
    states[11] = 2.35547751699999996e-16
    constants[32] = 2.47871658999999998e-03
    constants[33] = 1.94459589999999990e-04
    constants[34] = 3.0
    constants[35] = 2.86367149999999988e-04
    constants[36] = 2.90998690000000002e-04
    constants[37] = 8.37073022689999946e-01
    states[12] = 2.41788180099999987e-04
    states[13] = 9.51727886399999945e-01
    states[14] = 0.0
    states[15] = 0.0
    constants[38] = 0.1
    constants[39] = 0.01
    constants[40] = 0.0
    constants[41] = 7.8
    states[16] = 9.16842028100000039e-01
    states[17] = 9.38018356399999975e-01
    states[18] = 5.63181991600000039e-03
    constants[42] = 1.8
    states[19] = 1.03039701200000007e+01
    constants[43] = 140.0
    constants[44] = 0.35
    constants[45] = 1.38
    constants[46] = 87.5
    constants[47] = 1600.0
    constants[48] = 0.1
    constants[49] = 5.4
    constants[50] = 1.5
    constants[51] = 10.0
    states[20] = 1.22370601099999997e-02
    states[21] = 8.84913984200000003e-01
    constants[52] = 0.0
    states[22] = 1.31867138000000011e+02
    constants[53] = 8.3143
    constants[54] = 310.0
    states[23] = 2.97721944299999985e-01
    states[24] = 1.41927157299999995e-01
    states[25] = 9.79023869800000002e-01
    states[26] = 9.57197650200000028e-01
    states[27] = 3.66799927299999980e-04
    states[28] = 4.56694440999999974e-04
    constants[55] = 5.0
    constants[56] = 5.0
    states[29] = 9.58584701999999969e-03
    states[30] = 9.38694111799999974e-03
    constants[57] = 0.04
    constants[58] = 7500.0
    constants[59] = 4.68749999999999983e-04
    constants[60] = 2.31481500000000001e-03
    constants[61] = 0.0075
    constants[62] = 1.00000-1.00000/(1.00000+power(constants[0]/constants[6], constants[3]))
    constants[63] = 1.00000-1.00000/(1.00000+power(constants[1]/constants[6], constants[4]))
    constants[64] = 1.00000-1.00000/(1.00000+power(constants[2]/constants[6], constants[5]))
    constants[65] = 6.00000*2531.00
    constants[66] = 2.00000*57.0000
    constants[67] = 2.00000*80.0000
    constants[68] = constants[24]*constants[24]
    constants[69] = custom_piecewise([equal(constants[7] , 1.00000), 1.50000 , True, 1.00000])
    constants[70] = 1.40000*0.00113100
    constants[71] = 0.800000*0.000674438
    constants[72] = (0.129400*0.750000)*(custom_piecewise([equal(constants[7] , 1.00000), 0.350000 , True, 1.00000]))
    constants[73] = 0.0900000*(custom_piecewise([equal(constants[7] , 1.00000), 2.10000 , True, 1.00000]))
    constants[74] = 0.800000*0.0294118
    constants[75] = (0.800000*0.129412)*(custom_piecewise([equal(constants[7] , 1.00000), 2.00000 , True, 1.00000]))
    constants[76] = (constants[13]/constants[53])/constants[54]
    constants[77] = -0.327024
    constants[78] = -0.257320
    constants[79] = -0.0128016
    constants[80] = (0.00639800*0.900000)*(custom_piecewise([equal(constants[7] , 1.00000), 0.500000 , True, 1.00000]))
    constants[81] = 0.100000/1000.00
    constants[82] = 0.100000/1000.00
    constants[83] = custom_piecewise([equal(constants[7] , 1.00000), 1.60000 , True, 0.00000])
    constants[84] = custom_piecewise([equal(constants[7] , 1.00000), 1.40000 , True, 1.00000])
    constants[85] = 1.40000*0.599339
    constants[86] = (exp(constants[43]/67.3000)-1.00000)/7.00000
    constants[87] = (0.754710*0.196200)*(custom_piecewise([equal(constants[7] , 1.00000), 0.350000 , True, 1.00000]))
    constants[88] = custom_piecewise([equal(constants[7] , 1.00000), 16.0000 , True, 0.00000])
    constants[89] = custom_piecewise([equal(constants[7] , 1.00000), 2.50000 , True, 0.00000])
    constants[90] = custom_piecewise([equal(constants[7] , 1.00000), 3.00000 , True, 1.00000])
    constants[91] = custom_piecewise([equal(constants[7] , 1.00000), 2.70000 , True, 1.00000])
    constants[92] = custom_piecewise([equal(constants[7] , 1.00000), 0.600000 , True, 1.00000])
    constants[101] = 0.00000
    constants[93] = 2.00000*49.9232
    constants[94] = 0.00100000*constants[65]
    constants[95] = 250.000*constants[91]
    constants[96] = 250.000*constants[91]
    constants[97] = (2.00000*15.0000)*constants[91]
    constants[98] = 15.0000*constants[91]
    constants[99] = -80.0000
    constants[100] = 0.625000*constants[93]
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    rates[22] = constants[101]
    rates[10] = ((((constants[32]*exp((-constants[77]*states[4])*constants[76]))*constants[6])*states[13])*(1.00000-states[12]))*((1.00000-states[11])-states[10])-(constants[35]*states[10])*exp((-constants[37]*states[4])*constants[76])
    rates[11] = ((((constants[33]*exp((-constants[78]*states[4])*constants[76]))*constants[6])*states[13])*states[12])*((1.00000-states[11])-states[10])-(constants[36]*states[11])*exp((-constants[79]*states[4])*constants[76])
    rates[14] = ((((constants[81]*constants[40])*(power(states[18], 3.00000)))*states[16])*states[17])*((1.00000-states[14])-states[15])-constants[38]*states[14]
    rates[15] = ((constants[82]*constants[40])*(1.00000-states[16]))*((1.00000-states[14])-states[15])-constants[39]*states[15]
    algebraic[3] = 1.00000/(1.00000+states[3]/0.000350000)
    rates[7] = (algebraic[3]-states[7])/constants[29]
    algebraic[13] = 0.505000-0.427000/(1.00000+exp(((2000.00*states[2])*(1.00000+constants[89])-0.290000)/0.0820000))
    rates[23] = (algebraic[13]-states[23])/constants[95]
    algebraic[14] = 0.505000-0.427000/(1.00000+exp(((1000.00*states[3])*(1.00000+constants[89])-0.290000)/0.0820000))
    rates[24] = (algebraic[14]-states[24])/constants[96]
    algebraic[15] = 1.00000/(1.00000+exp(((2000.00*states[2])*(1.00000+constants[89])-(states[23]+0.0200000))/0.0100000))
    rates[25] = (algebraic[15]-states[25])/constants[97]
    algebraic[16] = 1.00000/(1.00000+exp(((1000.00*states[3])*(1.00000+constants[89])-(states[24]+0.0200000))/0.0100000))
    rates[26] = (algebraic[16]-states[26])/constants[98]
    algebraic[17] = 1.00000-1.00000/(1.00000+exp(((2000.00*states[2])*(1.00000+constants[89])-(states[23]+0.220000))/0.0300000))
    rates[27] = (algebraic[17]-states[27])/constants[55]
    algebraic[18] = 1.00000-1.00000/(1.00000+exp(((1000.00*states[3])*(1.00000+constants[89])-(states[24]+0.220000))/0.0300000))
    rates[28] = (algebraic[18]-states[28])/constants[56]
    algebraic[2] = exp(-(states[4]+28.0000)/6.90000)/(1.00000+exp(-(states[4]+28.0000)/6.90000))
    algebraic[21] = ((1.50000*2.00000)*3.00000)/(0.0197000*exp(-(power(0.0337000, 2.00000))*(power(states[4]+10.0000, 2.00000)))+0.0200000)
    rates[6] = (algebraic[2]-states[6])/algebraic[21]
    algebraic[6] = 1.00000/(1.00000+exp(-(states[4]+5.52000)/8.60000))
    algebraic[24] = (((45.6667/(1.00000+exp((states[4]+11.2306)/11.5255))+4.26754)*(0.262186/(1.00000+exp((states[4]+35.8658)/-3.87511))+0.291755))*1.00000)/constants[34]
    rates[12] = (algebraic[6]-states[12])/algebraic[24]
    algebraic[7] = 0.524240/(1.00000+exp((states[4]+15.1142)/7.56702))+0.458078
    algebraic[25] = (2328.00/(1.00000+exp((states[4]-9.43500)/3.58270))+1739.14)/constants[34]
    rates[13] = (algebraic[7]-states[13])/algebraic[25]
    algebraic[8] = custom_piecewise([greater_equal(states[4] , -40.0000), 0.00000 , True, 0.135000*exp((states[4]+80.0000)/-6.80000)])
    algebraic[26] = custom_piecewise([greater_equal(states[4] , -40.0000), 1.00000/(0.130000*(1.00000+exp((states[4]+10.6600)/-11.1000))) , True, 3.56000*exp(0.0790000*states[4])+310000.*exp(0.350000*states[4])])
    rates[16] = algebraic[8]*(1.00000-states[16])-algebraic[26]*states[16]
    algebraic[9] = custom_piecewise([greater_equal(states[4] , -40.0000), 0.00000 , True, ((-127140.*exp(0.244400*states[4])-3.47400e-05*exp(-0.0439100*states[4]))*(states[4]+37.7800))/(1.00000+exp(0.311000*(states[4]+79.2300)))])
    algebraic[27] = custom_piecewise([greater_equal(states[4] , -40.0000), (0.300000*exp(-2.53500e-07*states[4]))/(1.00000+exp(-0.100000*(states[4]+32.0000))) , True, (0.121200*exp(-0.0105200*states[4]))/(1.00000+exp(-0.137800*(states[4]+40.1400)))])
    rates[17] = algebraic[9]*(1.00000-states[17])-algebraic[27]*states[17]
    algebraic[10] = custom_piecewise([less(fabs((states[4]-constants[83])+47.1300) , 1.00000e-10), 3.20000 , True, (0.320000*((states[4]-constants[83])+47.1300))/(1.00000-exp(-0.100000*((states[4]-constants[83])+47.1300)))])
    algebraic[28] = 0.0800000*exp(-(states[4]-constants[83])/11.0000)
    rates[18] = algebraic[10]*(1.00000-states[18])-algebraic[28]*states[18]
    algebraic[11] = 1.00000/(1.00000+exp(((states[4]-constants[88])-1.00000)/-11.0000))
    algebraic[29] = 3.50000*exp(-((states[4]-constants[88])/30.0000)*2.00000)+1.50000
    rates[20] = (algebraic[11]-states[20])/algebraic[29]
    algebraic[12] = 1.00000/(1.00000+exp((states[4]+40.5000)/11.5000))
    algebraic[30] = 25.6350*exp(-((states[4]+52.4500)/15.8827)*2.00000)+14.1400
    rates[21] = (algebraic[12]-states[21])/algebraic[30]
    algebraic[20] = 1.00000/(1.00000+exp((states[4]+10.0000)/-8.00000))
    algebraic[1] = 1.00000/(1.00000+exp((states[4]+10.0000)/-6.24000))
    algebraic[32] = custom_piecewise([less(fabs(states[4]+10.0000) , 1.00000e-10), algebraic[1]*4.57900 , True, (algebraic[1]*(1.00000-exp((states[4]+10.0000)/-6.24000)))/(0.0350000*(states[4]+10.0000))])
    rates[5] = (algebraic[20]-states[5])/algebraic[32]
    algebraic[33] = 1.00000/(1.00000+exp((states[4]+14.1000)/-6.50000))
    algebraic[4] = custom_piecewise([less(fabs(states[4]+14.1000) , 1.00000e-10), 0.00150000 , True, (0.000300000*(states[4]+14.1000))/(1.00000-exp((states[4]+14.1000)/-5.00000))])
    algebraic[22] = custom_piecewise([less(fabs(states[4]-3.33280) , 1.00000e-10), 0.000378361 , True, (7.38980e-05*(states[4]-3.33280))/(exp((states[4]-3.33280)/5.12370)-1.00000)])
    algebraic[37] = 1.00000/(algebraic[4]+algebraic[22])
    rates[8] = (algebraic[33]-states[8])/algebraic[37]
    algebraic[34] = power(1.00000/(1.00000+exp((states[4]-19.9000)/-12.7000)), 1.0/2)
    algebraic[5] = custom_piecewise([less(fabs(states[4]-19.9000) , 1.00000e-10), 0.000680000 , True, (4.00000e-05*(states[4]-19.9000))/(1.00000-exp((states[4]-19.9000)/-17.0000))])
    algebraic[23] = custom_piecewise([less(fabs(states[4]-19.9000) , 1.00000e-10), 0.000315000 , True, (3.50000e-05*(states[4]-19.9000))/(exp((states[4]-19.9000)/9.00000)-1.00000)])
    algebraic[38] = 0.500000/(algebraic[5]+algebraic[23])
    rates[9] = (algebraic[34]-states[9])/algebraic[38]
    algebraic[0] = (((0.500000*constants[69])*constants[20])*(states[0]-states[2]))*constants[65]
    algebraic[45] = (((constants[92]*0.750000)*((-constants[60]*(power(states[0], 2.00000)))*(constants[57]-states[29])+constants[61]*states[29]))*constants[65])*2.00000
    algebraic[41] = 1.00000-1.00000/(1.00000+exp((states[0]-0.300000)/0.100000))
    algebraic[43] = ((((constants[90]*constants[94])*states[27])*states[25])*algebraic[41])*(states[0]-states[2])
    algebraic[49] = (algebraic[45]-algebraic[0])-algebraic[43]
    algebraic[35] = 1.00000/(1.00000+(constants[10]*constants[15])/(power(states[0]+constants[15], 2.00000)))
    rates[0] = (1000.00*algebraic[35])*(constants[12]*(((states[1]-2.00000*states[0])+states[0])/constants[68]+(states[0]-states[1])/((2.00000*3.00000)*constants[68]))+algebraic[49]/constants[66])
    algebraic[47] = (((constants[92]*0.750000)*((constants[58]*(power(states[2], 2.00000)))*(constants[57]-states[29])-constants[59]*states[29]))*constants[65])*2.00000
    rates[29] = (-algebraic[45]+algebraic[47])/constants[65]
    algebraic[31] = (((2.50000*constants[11])*constants[8])/constants[21])*(states[3]-states[2])
    algebraic[50] = ((-algebraic[47]+algebraic[0])+algebraic[43])+algebraic[31]
    algebraic[39] = 1.00000/(1.00000+(constants[9]*constants[14])/(power(states[2]+constants[14], 2.00000)))
    rates[2] = (algebraic[50]/constants[65])*algebraic[39]
    algebraic[19] = (((0.500000*constants[69])*constants[20])*(states[1]-states[3]))*constants[93]
    algebraic[61] = (((constants[92]*0.750000)*((-constants[60]*(power(states[1], 2.00000)))*(constants[57]-states[30])+constants[61]*states[30]))*constants[93])*2.00000
    algebraic[57] = 1.00000-1.00000/(1.00000+exp((states[1]-0.300000)/0.100000))
    algebraic[59] = ((((constants[90]*constants[100])*states[28])*states[26])*algebraic[57])*(states[1]-states[3])
    algebraic[64] = (algebraic[61]-algebraic[19])-algebraic[59]
    algebraic[36] = 1.00000/(1.00000+(constants[10]*constants[15])/(power(states[1]+constants[15], 2.00000)))
    rates[1] = (1000.00*algebraic[36])*(constants[12]*(((states[1]-2.00000*states[1])+states[0])/constants[68]+(states[1]-states[0])/((2.00000*4.00000)*constants[68]))+algebraic[64]/constants[67])
    algebraic[63] = (((constants[92]*0.750000)*((constants[58]*(power(states[3], 2.00000)))*(constants[57]-states[30])-constants[59]*states[30]))*constants[93])*2.00000
    rates[30] = (-algebraic[61]+algebraic[63])/constants[93]
    algebraic[44] = (((((1.33333*constants[22])*constants[72])*states[5])*states[6])*states[7])*(states[4]-constants[28])
    algebraic[46] = (((1.26000*constants[22])*constants[30])*states[3])/(states[3]+constants[31])
    algebraic[48] = ((((((1.40000*constants[84])*constants[22])*constants[47])/(power(constants[46], 3.00000)+power(constants[43], 3.00000)))/(constants[45]+constants[42]))/(1.00000+constants[48]*exp(((constants[44]-1.00000)*states[4])*constants[76])))*(((power(states[19], 3.00000))*constants[42])*exp((states[4]*constants[44])*constants[76])-((power(constants[43], 3.00000))*states[3])*exp((states[4]*(constants[44]-1.00000))*constants[76]))
    algebraic[53] = 13.3500*log(constants[42]/states[2])
    algebraic[54] = ((1.00000*constants[22])*constants[70])*(states[4]-algebraic[53])
    algebraic[55] = ((-algebraic[44]-algebraic[54])-algebraic[46])+2.00000*algebraic[48]
    algebraic[66] = ((-algebraic[31]+algebraic[19])-algebraic[63])+algebraic[59]
    algebraic[40] = 1.00000/(((1.00000+(constants[19]*constants[17])/(power(states[3]+constants[17], 2.00000)))+(constants[18]*constants[16])/(power(states[3]+constants[16], 2.00000)))+(constants[9]*constants[14])/(power(states[3]+constants[14], 2.00000)))
    rates[3] = algebraic[40]*(algebraic[66]/constants[93]+algebraic[55]/((2.00000*constants[93])*constants[13]))
    algebraic[68] = 26.7100*log(constants[43]/states[19])
    algebraic[69] = ((1.70000*constants[22])*constants[71])*(states[4]-algebraic[68])
    algebraic[70] = (((((constants[41]*(power(states[18], 3.00000)))*states[16])*states[17])*(states[4]-algebraic[68]))*constants[22])*((1.00000-states[14])-states[15])
    algebraic[51] = 1.00000/((1.00000+0.124500*exp((-0.100000*states[4])*constants[76]))+(0.0365000*constants[86])*exp(-states[4]*constants[76]))
    algebraic[52] = (((((1.28000*constants[22])*constants[85])*algebraic[51])*constants[49])/(constants[49]+constants[50]))/(1.00000+power(constants[51]/states[19], 4.00000))
    rates[19] = (((-3.00000*algebraic[52]-3.00000*algebraic[48])-algebraic[69])-algebraic[70])/(constants[13]*constants[23])
    algebraic[56] = 26.7100*log(constants[49]/states[22])
    algebraic[58] = ((constants[22]*constants[73])*(states[4]-algebraic[56]))/(1.00000+exp(0.0700000*(states[4]+80.0000)))
    algebraic[60] = ((((constants[22]*constants[62])*constants[74])*states[8])*(states[4]-algebraic[56]))/(1.00000+exp((states[4]+15.0000)/22.4000))
    algebraic[62] = ((((constants[22]*constants[63])*constants[75])*states[9])*states[9])*(states[4]-algebraic[56])
    algebraic[65] = (((((constants[22]*constants[80])*(4.51280+1.89977/(1.00000+exp((states[4]-20.5232)/-8.26597))))*((1.00000-states[11])-states[10]))*states[12])*states[13])*(states[4]-algebraic[56])
    algebraic[67] = (((((1.05000*constants[64])*constants[22])*constants[87])*states[20])*states[21])*(states[4]-algebraic[56])
    algebraic[71] = (((((((((((algebraic[70])+algebraic[67])+algebraic[65])+algebraic[60])+algebraic[62])+algebraic[44])+algebraic[58])+algebraic[69])+algebraic[54])+algebraic[48])+algebraic[52])+algebraic[46]
    algebraic[42] = custom_piecewise([less((voi-constants[26])-constants[27]*floor((voi-constants[26])/constants[27]) , constants[25]), 1.00000 , True, 0.00000])
    algebraic[72] = (constants[22]*algebraic[42])*constants[99]
    rates[4] = -((algebraic[71]+algebraic[72])+constants[52])/constants[22]
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[3] = 1.00000/(1.00000+states[3]/0.000350000)
    algebraic[13] = 0.505000-0.427000/(1.00000+exp(((2000.00*states[2])*(1.00000+constants[89])-0.290000)/0.0820000))
    algebraic[14] = 0.505000-0.427000/(1.00000+exp(((1000.00*states[3])*(1.00000+constants[89])-0.290000)/0.0820000))
    algebraic[15] = 1.00000/(1.00000+exp(((2000.00*states[2])*(1.00000+constants[89])-(states[23]+0.0200000))/0.0100000))
    algebraic[16] = 1.00000/(1.00000+exp(((1000.00*states[3])*(1.00000+constants[89])-(states[24]+0.0200000))/0.0100000))
    algebraic[17] = 1.00000-1.00000/(1.00000+exp(((2000.00*states[2])*(1.00000+constants[89])-(states[23]+0.220000))/0.0300000))
    algebraic[18] = 1.00000-1.00000/(1.00000+exp(((1000.00*states[3])*(1.00000+constants[89])-(states[24]+0.220000))/0.0300000))
    algebraic[2] = exp(-(states[4]+28.0000)/6.90000)/(1.00000+exp(-(states[4]+28.0000)/6.90000))
    algebraic[21] = ((1.50000*2.00000)*3.00000)/(0.0197000*exp(-(power(0.0337000, 2.00000))*(power(states[4]+10.0000, 2.00000)))+0.0200000)
    algebraic[6] = 1.00000/(1.00000+exp(-(states[4]+5.52000)/8.60000))
    algebraic[24] = (((45.6667/(1.00000+exp((states[4]+11.2306)/11.5255))+4.26754)*(0.262186/(1.00000+exp((states[4]+35.8658)/-3.87511))+0.291755))*1.00000)/constants[34]
    algebraic[7] = 0.524240/(1.00000+exp((states[4]+15.1142)/7.56702))+0.458078
    algebraic[25] = (2328.00/(1.00000+exp((states[4]-9.43500)/3.58270))+1739.14)/constants[34]
    algebraic[8] = custom_piecewise([greater_equal(states[4] , -40.0000), 0.00000 , True, 0.135000*exp((states[4]+80.0000)/-6.80000)])
    algebraic[26] = custom_piecewise([greater_equal(states[4] , -40.0000), 1.00000/(0.130000*(1.00000+exp((states[4]+10.6600)/-11.1000))) , True, 3.56000*exp(0.0790000*states[4])+310000.*exp(0.350000*states[4])])
    algebraic[9] = custom_piecewise([greater_equal(states[4] , -40.0000), 0.00000 , True, ((-127140.*exp(0.244400*states[4])-3.47400e-05*exp(-0.0439100*states[4]))*(states[4]+37.7800))/(1.00000+exp(0.311000*(states[4]+79.2300)))])
    algebraic[27] = custom_piecewise([greater_equal(states[4] , -40.0000), (0.300000*exp(-2.53500e-07*states[4]))/(1.00000+exp(-0.100000*(states[4]+32.0000))) , True, (0.121200*exp(-0.0105200*states[4]))/(1.00000+exp(-0.137800*(states[4]+40.1400)))])
    algebraic[10] = custom_piecewise([less(fabs((states[4]-constants[83])+47.1300) , 1.00000e-10), 3.20000 , True, (0.320000*((states[4]-constants[83])+47.1300))/(1.00000-exp(-0.100000*((states[4]-constants[83])+47.1300)))])
    algebraic[28] = 0.0800000*exp(-(states[4]-constants[83])/11.0000)
    algebraic[11] = 1.00000/(1.00000+exp(((states[4]-constants[88])-1.00000)/-11.0000))
    algebraic[29] = 3.50000*exp(-((states[4]-constants[88])/30.0000)*2.00000)+1.50000
    algebraic[12] = 1.00000/(1.00000+exp((states[4]+40.5000)/11.5000))
    algebraic[30] = 25.6350*exp(-((states[4]+52.4500)/15.8827)*2.00000)+14.1400
    algebraic[20] = 1.00000/(1.00000+exp((states[4]+10.0000)/-8.00000))
    algebraic[1] = 1.00000/(1.00000+exp((states[4]+10.0000)/-6.24000))
    algebraic[32] = custom_piecewise([less(fabs(states[4]+10.0000) , 1.00000e-10), algebraic[1]*4.57900 , True, (algebraic[1]*(1.00000-exp((states[4]+10.0000)/-6.24000)))/(0.0350000*(states[4]+10.0000))])
    algebraic[33] = 1.00000/(1.00000+exp((states[4]+14.1000)/-6.50000))
    algebraic[4] = custom_piecewise([less(fabs(states[4]+14.1000) , 1.00000e-10), 0.00150000 , True, (0.000300000*(states[4]+14.1000))/(1.00000-exp((states[4]+14.1000)/-5.00000))])
    algebraic[22] = custom_piecewise([less(fabs(states[4]-3.33280) , 1.00000e-10), 0.000378361 , True, (7.38980e-05*(states[4]-3.33280))/(exp((states[4]-3.33280)/5.12370)-1.00000)])
    algebraic[37] = 1.00000/(algebraic[4]+algebraic[22])
    algebraic[34] = power(1.00000/(1.00000+exp((states[4]-19.9000)/-12.7000)), 1.0/2)
    algebraic[5] = custom_piecewise([less(fabs(states[4]-19.9000) , 1.00000e-10), 0.000680000 , True, (4.00000e-05*(states[4]-19.9000))/(1.00000-exp((states[4]-19.9000)/-17.0000))])
    algebraic[23] = custom_piecewise([less(fabs(states[4]-19.9000) , 1.00000e-10), 0.000315000 , True, (3.50000e-05*(states[4]-19.9000))/(exp((states[4]-19.9000)/9.00000)-1.00000)])
    algebraic[38] = 0.500000/(algebraic[5]+algebraic[23])
    algebraic[0] = (((0.500000*constants[69])*constants[20])*(states[0]-states[2]))*constants[65]
    algebraic[45] = (((constants[92]*0.750000)*((-constants[60]*(power(states[0], 2.00000)))*(constants[57]-states[29])+constants[61]*states[29]))*constants[65])*2.00000
    algebraic[41] = 1.00000-1.00000/(1.00000+exp((states[0]-0.300000)/0.100000))
    algebraic[43] = ((((constants[90]*constants[94])*states[27])*states[25])*algebraic[41])*(states[0]-states[2])
    algebraic[49] = (algebraic[45]-algebraic[0])-algebraic[43]
    algebraic[35] = 1.00000/(1.00000+(constants[10]*constants[15])/(power(states[0]+constants[15], 2.00000)))
    algebraic[47] = (((constants[92]*0.750000)*((constants[58]*(power(states[2], 2.00000)))*(constants[57]-states[29])-constants[59]*states[29]))*constants[65])*2.00000
    algebraic[31] = (((2.50000*constants[11])*constants[8])/constants[21])*(states[3]-states[2])
    algebraic[50] = ((-algebraic[47]+algebraic[0])+algebraic[43])+algebraic[31]
    algebraic[39] = 1.00000/(1.00000+(constants[9]*constants[14])/(power(states[2]+constants[14], 2.00000)))
    algebraic[19] = (((0.500000*constants[69])*constants[20])*(states[1]-states[3]))*constants[93]
    algebraic[61] = (((constants[92]*0.750000)*((-constants[60]*(power(states[1], 2.00000)))*(constants[57]-states[30])+constants[61]*states[30]))*constants[93])*2.00000
    algebraic[57] = 1.00000-1.00000/(1.00000+exp((states[1]-0.300000)/0.100000))
    algebraic[59] = ((((constants[90]*constants[100])*states[28])*states[26])*algebraic[57])*(states[1]-states[3])
    algebraic[64] = (algebraic[61]-algebraic[19])-algebraic[59]
    algebraic[36] = 1.00000/(1.00000+(constants[10]*constants[15])/(power(states[1]+constants[15], 2.00000)))
    algebraic[63] = (((constants[92]*0.750000)*((constants[58]*(power(states[3], 2.00000)))*(constants[57]-states[30])-constants[59]*states[30]))*constants[93])*2.00000
    algebraic[44] = (((((1.33333*constants[22])*constants[72])*states[5])*states[6])*states[7])*(states[4]-constants[28])
    algebraic[46] = (((1.26000*constants[22])*constants[30])*states[3])/(states[3]+constants[31])
    algebraic[48] = ((((((1.40000*constants[84])*constants[22])*constants[47])/(power(constants[46], 3.00000)+power(constants[43], 3.00000)))/(constants[45]+constants[42]))/(1.00000+constants[48]*exp(((constants[44]-1.00000)*states[4])*constants[76])))*(((power(states[19], 3.00000))*constants[42])*exp((states[4]*constants[44])*constants[76])-((power(constants[43], 3.00000))*states[3])*exp((states[4]*(constants[44]-1.00000))*constants[76]))
    algebraic[53] = 13.3500*log(constants[42]/states[2])
    algebraic[54] = ((1.00000*constants[22])*constants[70])*(states[4]-algebraic[53])
    algebraic[55] = ((-algebraic[44]-algebraic[54])-algebraic[46])+2.00000*algebraic[48]
    algebraic[66] = ((-algebraic[31]+algebraic[19])-algebraic[63])+algebraic[59]
    algebraic[40] = 1.00000/(((1.00000+(constants[19]*constants[17])/(power(states[3]+constants[17], 2.00000)))+(constants[18]*constants[16])/(power(states[3]+constants[16], 2.00000)))+(constants[9]*constants[14])/(power(states[3]+constants[14], 2.00000)))
    algebraic[68] = 26.7100*log(constants[43]/states[19])
    algebraic[69] = ((1.70000*constants[22])*constants[71])*(states[4]-algebraic[68])
    algebraic[70] = (((((constants[41]*(power(states[18], 3.00000)))*states[16])*states[17])*(states[4]-algebraic[68]))*constants[22])*((1.00000-states[14])-states[15])
    algebraic[51] = 1.00000/((1.00000+0.124500*exp((-0.100000*states[4])*constants[76]))+(0.0365000*constants[86])*exp(-states[4]*constants[76]))
    algebraic[52] = (((((1.28000*constants[22])*constants[85])*algebraic[51])*constants[49])/(constants[49]+constants[50]))/(1.00000+power(constants[51]/states[19], 4.00000))
    algebraic[56] = 26.7100*log(constants[49]/states[22])
    algebraic[58] = ((constants[22]*constants[73])*(states[4]-algebraic[56]))/(1.00000+exp(0.0700000*(states[4]+80.0000)))
    algebraic[60] = ((((constants[22]*constants[62])*constants[74])*states[8])*(states[4]-algebraic[56]))/(1.00000+exp((states[4]+15.0000)/22.4000))
    algebraic[62] = ((((constants[22]*constants[63])*constants[75])*states[9])*states[9])*(states[4]-algebraic[56])
    algebraic[65] = (((((constants[22]*constants[80])*(4.51280+1.89977/(1.00000+exp((states[4]-20.5232)/-8.26597))))*((1.00000-states[11])-states[10]))*states[12])*states[13])*(states[4]-algebraic[56])
    algebraic[67] = (((((1.05000*constants[64])*constants[22])*constants[87])*states[20])*states[21])*(states[4]-algebraic[56])
    algebraic[71] = (((((((((((algebraic[70])+algebraic[67])+algebraic[65])+algebraic[60])+algebraic[62])+algebraic[44])+algebraic[58])+algebraic[69])+algebraic[54])+algebraic[48])+algebraic[52])+algebraic[46]
    algebraic[42] = custom_piecewise([less((voi-constants[26])-constants[27]*floor((voi-constants[26])/constants[27]) , constants[25]), 1.00000 , True, 0.00000])
    algebraic[72] = (constants[22]*algebraic[42])*constants[99]
    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)