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 = 68
sizeStates = 25
sizeConstants = 42
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_constants[4] = "i_stim in component membrane (picoA_per_picoF)"
    legend_algebraic[14] = "i_Na in component fast_sodium_current (picoA_per_picoF)"
    legend_algebraic[34] = "i_K1 in component time_independent_potassium_current (picoA_per_picoF)"
    legend_algebraic[41] = "i_to in component transient_outward_K_current (picoA_per_picoF)"
    legend_algebraic[43] = "i_Kur_d in component ultrarapid_delayed_rectifier_K_current (picoA_per_picoF)"
    legend_algebraic[44] = "i_Kr in component rapid_delayed_rectifier_K_current (picoA_per_picoF)"
    legend_algebraic[45] = "i_Ks in component slow_delayed_rectifier_K_current (picoA_per_picoF)"
    legend_algebraic[46] = "i_Ca in component sarcolemmal_Ca_current (picoA_per_picoF)"
    legend_algebraic[48] = "i_Cl_Ca in component Ca_activated_Cl_current (picoA_per_picoF)"
    legend_algebraic[55] = "i_p_Ca in component Ca_pump_current (picoA_per_picoF)"
    legend_algebraic[50] = "i_NaK in component sodium_potassium_pump (picoA_per_picoF)"
    legend_algebraic[51] = "i_NaCa in component Na_Ca_exchanger_current (picoA_per_picoF)"
    legend_algebraic[52] = "i_B_Na in component background_currents (picoA_per_picoF)"
    legend_algebraic[54] = "i_B_Ca in component background_currents (picoA_per_picoF)"
    legend_algebraic[0] = "E_Na in component fast_sodium_current (millivolt)"
    legend_constants[5] = "g_Na in component fast_sodium_current (nanoS_per_picoF)"
    legend_states[1] = "Na_i in component intracellular_ion_concentrations (millimolar)"
    legend_constants[6] = "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[15] = "beta_m in component fast_sodium_current_m_gate (per_millisecond)"
    legend_algebraic[2] = "alpha_h in component fast_sodium_current_h_gate (per_millisecond)"
    legend_algebraic[16] = "beta_h in component fast_sodium_current_h_gate (per_millisecond)"
    legend_algebraic[3] = "alpha_j in component fast_sodium_current_j_gate (per_millisecond)"
    legend_algebraic[17] = "beta_j in component fast_sodium_current_j_gate (per_millisecond)"
    legend_algebraic[27] = "E_K in component time_independent_potassium_current (millivolt)"
    legend_constants[7] = "g_K1 in component time_independent_potassium_current (nanoS_per_picoF)"
    legend_constants[8] = "K_o in component standard_ionic_concentrations (millimolar)"
    legend_states[5] = "K_i in component intracellular_ion_concentrations (millimolar)"
    legend_constants[9] = "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] = "alpha_oa in component transient_outward_K_current_oa_gate (per_millisecond)"
    legend_algebraic[18] = "beta_oa in component transient_outward_K_current_oa_gate (per_millisecond)"
    legend_algebraic[28] = "tau_oa in component transient_outward_K_current_oa_gate (millisecond)"
    legend_algebraic[35] = "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[19] = "beta_oi in component transient_outward_K_current_oi_gate (per_millisecond)"
    legend_algebraic[29] = "tau_oi in component transient_outward_K_current_oi_gate (millisecond)"
    legend_algebraic[36] = "oi_infinity in component transient_outward_K_current_oi_gate (dimensionless)"
    legend_algebraic[42] = "g_Kur_d 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[20] = "beta_ua in component ultrarapid_delayed_rectifier_K_current_ua_gate (per_millisecond)"
    legend_algebraic[30] = "tau_ua in component ultrarapid_delayed_rectifier_K_current_ua_gate (millisecond)"
    legend_algebraic[37] = "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[21] = "beta_ui in component ultrarapid_delayed_rectifier_K_current_ui_gate (per_millisecond)"
    legend_algebraic[31] = "tau_ui in component ultrarapid_delayed_rectifier_K_current_ui_gate (millisecond)"
    legend_algebraic[38] = "ui_infinity in component ultrarapid_delayed_rectifier_K_current_ui_gate (dimensionless)"
    legend_constants[10] = "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[22] = "beta_xr in component rapid_delayed_rectifier_K_current_xr_gate (per_millisecond)"
    legend_algebraic[32] = "tau_xr in component rapid_delayed_rectifier_K_current_xr_gate (millisecond)"
    legend_algebraic[39] = "xr_infinity in component rapid_delayed_rectifier_K_current_xr_gate (dimensionless)"
    legend_constants[11] = "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[23] = "beta_xs in component slow_delayed_rectifier_K_current_xs_gate (per_millisecond)"
    legend_algebraic[33] = "tau_xs in component slow_delayed_rectifier_K_current_xs_gate (millisecond)"
    legend_algebraic[40] = "xs_infinity in component slow_delayed_rectifier_K_current_xs_gate (dimensionless)"
    legend_constants[12] = "g_Ca in component sarcolemmal_Ca_current (nanoS_per_picoF)"
    legend_states[12] = "Ca_i in component intracellular_ion_concentrations (millimolar)"
    legend_states[13] = "d in component sarcolemmal_Ca_current_d_gate (dimensionless)"
    legend_states[14] = "f in component sarcolemmal_Ca_current_f_gate (dimensionless)"
    legend_states[15] = "f_Ca in component sarcolemmal_Ca_current_f_Ca_gate (dimensionless)"
    legend_algebraic[10] = "d_infinity in component sarcolemmal_Ca_current_d_gate (dimensionless)"
    legend_algebraic[24] = "tau_d in component sarcolemmal_Ca_current_d_gate (millisecond)"
    legend_algebraic[11] = "f_infinity in component sarcolemmal_Ca_current_f_gate (dimensionless)"
    legend_algebraic[25] = "tau_f in component sarcolemmal_Ca_current_f_gate (millisecond)"
    legend_algebraic[12] = "f_Ca_infinity in component sarcolemmal_Ca_current_f_Ca_gate (dimensionless)"
    legend_constants[13] = "tau_f_Ca in component sarcolemmal_Ca_current_f_Ca_gate (millisecond)"
    legend_constants[14] = "g_Cl_Ca in component Ca_activated_Cl_current (nanoS_per_picoF)"
    legend_algebraic[47] = "E_Cl in component Ca_activated_Cl_current (millivolt)"
    legend_algebraic[57] = "Fn in component Ca_release_current_from_JSR (dimensionless)"
    legend_states[16] = "Cl_i in component intracellular_ion_concentrations (millimolar)"
    legend_constants[15] = "Cl_o in component standard_ionic_concentrations (millimolar)"
    legend_constants[16] = "q_Ca in component Ca_activated_Cl_current_q_Ca_gate (dimensionless)"
    legend_algebraic[59] = "q_Ca_infinity in component Ca_activated_Cl_current_q_Ca_gate (dimensionless)"
    legend_constants[17] = "Km_Na_i in component sodium_potassium_pump (millimolar)"
    legend_constants[18] = "Km_K_o in component sodium_potassium_pump (millimolar)"
    legend_constants[19] = "i_NaK_max in component sodium_potassium_pump (picoA_per_picoF)"
    legend_algebraic[49] = "f_NaK in component sodium_potassium_pump (dimensionless)"
    legend_constants[40] = "sigma in component sodium_potassium_pump (dimensionless)"
    legend_constants[20] = "I_NaCa_max in component Na_Ca_exchanger_current (picoA_per_picoF)"
    legend_constants[21] = "K_mNa in component Na_Ca_exchanger_current (millimolar)"
    legend_constants[22] = "K_mCa in component Na_Ca_exchanger_current (millimolar)"
    legend_constants[23] = "K_sat in component Na_Ca_exchanger_current (dimensionless)"
    legend_constants[24] = "Ca_o in component standard_ionic_concentrations (millimolar)"
    legend_constants[25] = "g_B_Na in component background_currents (nanoS_per_picoF)"
    legend_constants[26] = "g_B_Ca in component background_currents (nanoS_per_picoF)"
    legend_algebraic[53] = "E_Ca in component background_currents (millivolt)"
    legend_constants[27] = "i_p_Ca_max in component Ca_pump_current (picoA_per_picoF)"
    legend_algebraic[56] = "i_rel in component Ca_release_current_from_JSR (picoA_per_picoF)"
    legend_constants[28] = "K_rel in component Ca_release_current_from_JSR (per_millisecond)"
    legend_constants[29] = "V_rel in component Ca_release_current_from_JSR (micrometre_3)"
    legend_states[17] = "Ca_rel in component intracellular_ion_concentrations (millimolar)"
    legend_states[18] = "u in component Ca_release_current_from_JSR_u_gate (dimensionless)"
    legend_states[19] = "v in component Ca_release_current_from_JSR_v_gate (dimensionless)"
    legend_states[20] = "w in component Ca_release_current_from_JSR_w_gate (dimensionless)"
    legend_constants[41] = "tau_u in component Ca_release_current_from_JSR_u_gate (millisecond)"
    legend_algebraic[60] = "u_infinity in component Ca_release_current_from_JSR_u_gate (dimensionless)"
    legend_algebraic[61] = "tau_v in component Ca_release_current_from_JSR_v_gate (millisecond)"
    legend_algebraic[63] = "v_infinity in component Ca_release_current_from_JSR_v_gate (dimensionless)"
    legend_algebraic[13] = "tau_w in component Ca_release_current_from_JSR_w_gate (millisecond)"
    legend_algebraic[26] = "w_infinity in component Ca_release_current_from_JSR_w_gate (dimensionless)"
    legend_algebraic[58] = "i_tr in component transfer_current_from_NSR_to_JSR (picoA_per_picoF)"
    legend_constants[30] = "tau_tr in component transfer_current_from_NSR_to_JSR (millisecond)"
    legend_states[21] = "Ca_up in component intracellular_ion_concentrations (millimolar)"
    legend_constants[31] = "I_up_max in component Ca_uptake_current_by_the_NSR (picoA_per_picoF)"
    legend_algebraic[62] = "i_up in component Ca_uptake_current_by_the_NSR (picoA_per_picoF)"
    legend_constants[32] = "K_up in component Ca_uptake_current_by_the_NSR (millimolar)"
    legend_algebraic[65] = "i_up_leak in component Ca_leak_current_by_the_NSR (picoA_per_picoF)"
    legend_constants[33] = "Ca_up_max in component Ca_leak_current_by_the_NSR (millimolar)"
    legend_constants[34] = "CMDN_max in component Ca_buffers (millimolar)"
    legend_constants[35] = "TRPN_max in component Ca_buffers (millimolar)"
    legend_constants[36] = "CSQN_max in component Ca_buffers (millimolar)"
    legend_algebraic[66] = "J_Ca_CMDN in component Ca_buffers (millimolar_per_millisecond)"
    legend_algebraic[67] = "J_Ca_TRPN in component Ca_buffers (millimolar_per_millisecond)"
    legend_algebraic[64] = "J_Ca_CSQN in component Ca_buffers (millimolar_per_millisecond)"
    legend_states[22] = "Ca_CMDN in component Ca_buffers (millimolar)"
    legend_states[23] = "Ca_TRPN in component Ca_buffers (millimolar)"
    legend_states[24] = "Ca_CSQN in component Ca_buffers (millimolar)"
    legend_constants[37] = "V_i in component intracellular_ion_concentrations (micrometre_3)"
    legend_constants[38] = "V_rel in component intracellular_ion_concentrations (micrometre_3)"
    legend_constants[39] = "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[13] = "d/dt d in component sarcolemmal_Ca_current_d_gate (dimensionless)"
    legend_rates[14] = "d/dt f in component sarcolemmal_Ca_current_f_gate (dimensionless)"
    legend_rates[15] = "d/dt f_Ca in component sarcolemmal_Ca_current_f_Ca_gate (dimensionless)"
    legend_rates[18] = "d/dt u in component Ca_release_current_from_JSR_u_gate (dimensionless)"
    legend_rates[19] = "d/dt v in component Ca_release_current_from_JSR_v_gate (dimensionless)"
    legend_rates[20] = "d/dt w in component Ca_release_current_from_JSR_w_gate (dimensionless)"
    legend_rates[22] = "d/dt Ca_CMDN in component Ca_buffers (millimolar)"
    legend_rates[23] = "d/dt Ca_TRPN in component Ca_buffers (millimolar)"
    legend_rates[24] = "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[16] = "d/dt Cl_i in component intracellular_ion_concentrations (millimolar)"
    legend_rates[12] = "d/dt Ca_i in component intracellular_ion_concentrations (millimolar)"
    legend_rates[21] = "d/dt Ca_up in component intracellular_ion_concentrations (millimolar)"
    legend_rates[17] = "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] = -83.53
    constants[0] = 8.3143
    constants[1] = 310.0
    constants[2] = 96.4867
    constants[3] = 100.0
    constants[4] = -2900.0
    constants[5] = 7.8
    states[1] = 11.75
    constants[6] = 140.0
    states[2] = 0.001972
    states[3] = 0.9791
    states[4] = 0.9869
    constants[7] = 0.15
    constants[8] = 5.4
    states[5] = 138.4
    constants[9] = 0.19824
    states[6] = 0.07164
    states[7] = 0.9980
    states[8] = 0.05869
    states[9] = 0.9987
    constants[10] = 0.06984
    states[10] = 0.0000007433
    constants[11] = 0.0561
    states[11] = 0.01791
    constants[12] = 0.24
    states[12] = 0.0001024
    states[13] = 0.000004757
    states[14] = 0.9999
    states[15] = 0.7484
    constants[13] = 2.0
    constants[14] = 0.3
    states[16] = 29.26
    constants[15] = 132.0
    constants[16] = 0.0
    constants[17] = 10.0
    constants[18] = 1.5
    constants[19] = 0.6
    constants[20] = 1600.0
    constants[21] = 87.5
    constants[22] = 1.38
    constants[23] = 0.1
    constants[24] = 1.8
    constants[25] = 0.000674
    constants[26] = 0.00113
    constants[27] = 0.275
    constants[28] = 30.0
    constants[29] = 96.48
    states[17] = 1.502
    states[18] = 0.0
    states[19] = 1.0
    states[20] = 0.9993
    constants[30] = 180.0
    states[21] = 1.502
    constants[31] = 0.005
    constants[32] = 0.00092
    constants[33] = 15.0
    constants[34] = 0.045
    constants[35] = 0.35
    constants[36] = 10.0
    states[22] = 0.001856
    states[23] = 0.007022
    states[24] = 6.432
    constants[37] = 13668.0
    constants[38] = 96.48
    constants[39] = 1109.52
    constants[40] = (1.00000/7.00000)*(exp(constants[6]/67.3000)-1.00000)
    constants[41] = 8.00000
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    algebraic[12] = 0.290000+0.800000*(power(1.00000+exp((states[12]-0.000120000)/6.00000e-05), -1.00000))
    rates[15] = (algebraic[12]-states[15])/constants[13]
    algebraic[1] = 0.320000*((states[0]+47.1300)/(1.00000-exp(-0.100000*(states[0]+47.1300))))
    algebraic[15] = 0.0800000*exp(states[0]/-11.0000)
    rates[2] = algebraic[1]*(1.00000-states[2])-algebraic[15]*states[2]
    algebraic[2] = custom_piecewise([less(states[0] , -40.0000), 0.135000*exp((states[0]+80.0000)/-6.80000) , True, 0.00000])
    algebraic[16] = 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[2]*(1.00000-states[3])-algebraic[16]*states[3]
    algebraic[3] = custom_piecewise([less(states[0] , -40.0000), ((-127140.*exp(0.244400*states[0])-3.47400e-05*exp(-0.0439100*states[0]))/(1.00000+exp(0.311000*(states[0]+79.2300))))*(states[0]+37.7800) , True, 0.00000])
    algebraic[17] = 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[3]*(1.00000-states[4])-algebraic[17]*states[4]
    algebraic[10] = power(1.00000+exp((states[0]+10.0000)/-6.00000), -1.00000)
    algebraic[24] = (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[13] = (algebraic[10]-states[13])/algebraic[24]
    algebraic[11] = power(1.00000+exp((states[0]+24.6000)/6.20000), -1.00000)
    algebraic[25] = 400.000*(power(1.00000+4.50000*exp(-0.000700000*(power(states[0]-9.00000, 2.00000))), -1.00000))
    rates[14] = (algebraic[11]-states[14])/algebraic[25]
    algebraic[13] = (6.00000-6.00000*exp((states[0]-7.90000)/-5.00000))/((1.00000+0.300000*exp((states[0]-7.90000)/-5.00000))*(states[0]-7.90000))
    algebraic[26] = 1.00000-power(1.00000+exp((states[0]-40.0000)/-17.0000), -1.00000)
    rates[20] = (algebraic[26]-states[20])/algebraic[13]
    algebraic[4] = 0.650000*(power(exp((states[0]+18.0000)/-8.50000)+exp((states[0]-16.0000)/-59.0000), -1.00000))
    algebraic[18] = 1.20000*(power(2.20000+exp((states[0]+75.0000)/18.0000), -1.00000))
    algebraic[28] = power(algebraic[4]+algebraic[18], -1.00000)
    algebraic[35] = power(1.00000+exp((states[0]+0.500000)/-10.5000), -(1.00000/3.00000))
    rates[6] = (algebraic[35]-states[6])/algebraic[28]
    algebraic[5] = power(6.20000+exp((states[0]+105.200)/9.85000), -1.00000)
    algebraic[19] = power(7.54000+exp((states[0]-8.89000)/-12.8700), -1.00000)
    algebraic[29] = power(algebraic[5]+algebraic[19], -1.00000)
    algebraic[36] = power(1.00000+exp((states[0]+43.3770)/6.45000), -1.00000)
    rates[7] = (algebraic[36]-states[7])/algebraic[29]
    algebraic[6] = 1.47000*(power(exp((states[0]+33.2000)/-30.6300)+exp((states[0]-27.6000)/-30.6500), -1.00000))
    algebraic[20] = 0.420000*(power(exp((states[0]+26.6400)/2.49000)+exp((states[0]+44.4100)/20.3600), -1.00000))
    algebraic[30] = power(algebraic[6]+algebraic[20], -1.00000)
    algebraic[37] = power(1.00000+exp((states[0]+2.81000)/-9.49000), -(1.00000/3.00000))
    rates[8] = (algebraic[37]-states[8])/algebraic[30]
    algebraic[7] = power(21.0000+exp((states[0]-185.000)/-28.0000), -1.00000)
    algebraic[21] = exp((states[0]-158.000)/16.0000)
    algebraic[31] = power(algebraic[7]+algebraic[21], -1.00000)
    algebraic[38] = power(1.00000+exp((states[0]-99.4500)/27.4800), -1.00000)
    rates[9] = (algebraic[38]-states[9])/algebraic[31]
    algebraic[8] = 0.0400000*((states[0]-248.000)/(1.00000-exp((states[0]-248.000)/-28.0000)))
    algebraic[22] = 0.0280000*((states[0]+163.000)/(exp((states[0]+163.000)/21.0000)-1.00000))
    algebraic[32] = power(algebraic[8]+algebraic[22], -1.00000)
    algebraic[39] = power(1.00000+exp((states[0]+7.65400)/-5.37700), -1.00000)
    rates[10] = (algebraic[39]-states[10])/algebraic[32]
    algebraic[9] = 1.00000e-05*((states[0]+28.5000)/(1.00000-exp((states[0]+28.5000)/-115.000)))
    algebraic[23] = 0.000230000*((states[0]+28.5000)/(exp((states[0]+28.5000)/3.30000)-1.00000))
    algebraic[33] = power(algebraic[9]+algebraic[23], -1.00000)
    algebraic[40] = power(1.00000+exp((states[0]-13.0000)/-12.0000), -0.500000)
    rates[11] = (algebraic[40]-states[11])/algebraic[33]
    algebraic[47] = ((constants[0]*constants[1])/(-1.00000*constants[2]))*log(constants[15]/states[16])
    algebraic[48] = constants[14]*constants[16]*(states[0]-algebraic[47])
    rates[16] = algebraic[48]/(constants[37]*constants[2])
    algebraic[27] = ((constants[0]*constants[1])/constants[2])*log(constants[8]/states[5])
    algebraic[34] = (constants[7]*(states[0]-algebraic[27]))/(1.00000+exp(0.0700000*(states[0]+80.0000)))
    algebraic[41] = constants[9]*(power(states[6], 3.00000))*states[7]*(states[0]-algebraic[27])
    algebraic[42] = 0.00855000+0.0779000/(1.00000+exp((states[0]+11.0000)/-16.0000))
    algebraic[43] = algebraic[42]*(power(states[8], 3.00000))*states[9]*(states[0]-algebraic[27])
    algebraic[44] = constants[10]*states[10]*(0.0700000+0.580000/(1.00000+exp((states[0]+15.0000)/22.4000)))*(states[0]-algebraic[27])
    algebraic[45] = constants[11]*(power(states[11], 2.00000))*(states[0]-algebraic[27])
    algebraic[49] = power(1.00000+0.124500*exp(-0.100000*((constants[2]*states[0])/(constants[0]*constants[1])))+0.0365000*constants[40]*exp(-((constants[2]*states[0])/(constants[0]*constants[1]))), -1.00000)
    algebraic[50] = constants[19]*algebraic[49]*(1.00000/(1.00000+power(constants[17]/states[1], 1.50000)))*(constants[8]/(constants[8]+constants[18]))
    rates[5] = (2.00000*algebraic[50]-(algebraic[34]+algebraic[41]+algebraic[43]+algebraic[44]+algebraic[45]))/(constants[37]*constants[2])
    algebraic[0] = ((constants[0]*constants[1])/constants[2])*log(constants[6]/states[1])
    algebraic[14] = constants[5]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[0])
    algebraic[51] = (constants[20]*(exp((0.350000*constants[2]*states[0])/(constants[0]*constants[1]))*(power(states[1], 3.00000))*constants[24]-exp((-0.650000*constants[2]*states[0])/(constants[0]*constants[1]))*(power(constants[6], 3.00000))*states[12]))/((power(constants[21], 3.00000)+power(constants[6], 3.00000))*(constants[22]+constants[24])*(1.00000+constants[23]*exp((-0.650000*states[0]*constants[2])/(constants[0]*constants[1]))))
    algebraic[52] = constants[25]*(states[0]-algebraic[0])
    rates[1] = (-3.00000*algebraic[50]-(3.00000*algebraic[51]+algebraic[52]+algebraic[14]))/(constants[37]*constants[2])
    algebraic[46] = constants[12]*states[13]*states[14]*states[15]*(states[0]-65.0000)
    algebraic[55] = constants[27]*(states[12]/(0.000500000+states[12]))
    algebraic[53] = ((constants[0]*constants[1])/(2.00000*constants[2]))*log(constants[24]/states[12])
    algebraic[54] = constants[26]*(states[0]-algebraic[53])
    rates[0] = -(algebraic[14]+algebraic[34]+algebraic[41]+algebraic[43]+algebraic[44]+algebraic[45]+algebraic[46]+algebraic[48]+algebraic[55]+algebraic[51]+algebraic[50]+algebraic[52]+algebraic[54]+constants[4])/constants[3]
    rates[24] = 0.480000*states[17]*(1.00000-states[24]/constants[36])-0.400000*(states[24]/constants[36])
    algebraic[56] = constants[28]*(power(states[18], 2.00000))*states[19]*states[20]*(states[17]-states[12])
    algebraic[57] = 1.00000e-12*constants[29]*algebraic[56]-5.00000e-13*((1.00000/(2.00000*constants[2]))*algebraic[46]-(1.00000/(5.00000*constants[2]))*algebraic[51])
    algebraic[60] = power(1.00000+exp((algebraic[57]-3.41750e-13)/-1.36700e-15), -1.00000)
    rates[18] = (algebraic[60]-states[18])/constants[41]
    algebraic[61] = 1.91000+2.09000*(power(1.00000+exp((algebraic[57]-3.41750e-13)/-1.36700e-15), -1.00000))
    algebraic[63] = 1.00000-power(1.00000+exp((algebraic[57]-6.83500e-14)/-1.36700e-15), -1.00000)
    rates[19] = (algebraic[63]-states[19])/algebraic[61]
    rates[22] = 200.000*states[12]*(1.00000-states[22]/constants[34])-0.476000*(states[22]/constants[34])
    algebraic[58] = (states[21]-states[17])/constants[30]
    algebraic[62] = constants[31]/(1.00000+constants[32]/states[12])
    algebraic[65] = constants[31]*(states[21]/constants[33])
    rates[21] = algebraic[62]-(algebraic[65]+algebraic[58]*(constants[38]/constants[39]))
    algebraic[64] = rates[24]
    rates[17] = algebraic[58]-(algebraic[56]+31.0000*algebraic[64])
    rates[23] = 78.4000*states[12]*(1.00000-states[23]/constants[35])-0.392000*(states[23]/constants[35])
    algebraic[66] = rates[22]
    algebraic[67] = rates[23]
    rates[12] = ((2.00000*algebraic[51]-(algebraic[55]+algebraic[46]+algebraic[54]))/(2.00000*constants[37]*constants[2])+(constants[39]*(algebraic[65]-algebraic[62])+algebraic[56]*constants[38])/constants[37])-(constants[35]*algebraic[67]+constants[34]*algebraic[66])
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[12] = 0.290000+0.800000*(power(1.00000+exp((states[12]-0.000120000)/6.00000e-05), -1.00000))
    algebraic[1] = 0.320000*((states[0]+47.1300)/(1.00000-exp(-0.100000*(states[0]+47.1300))))
    algebraic[15] = 0.0800000*exp(states[0]/-11.0000)
    algebraic[2] = custom_piecewise([less(states[0] , -40.0000), 0.135000*exp((states[0]+80.0000)/-6.80000) , True, 0.00000])
    algebraic[16] = 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[3] = custom_piecewise([less(states[0] , -40.0000), ((-127140.*exp(0.244400*states[0])-3.47400e-05*exp(-0.0439100*states[0]))/(1.00000+exp(0.311000*(states[0]+79.2300))))*(states[0]+37.7800) , True, 0.00000])
    algebraic[17] = 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[10] = power(1.00000+exp((states[0]+10.0000)/-6.00000), -1.00000)
    algebraic[24] = (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[11] = power(1.00000+exp((states[0]+24.6000)/6.20000), -1.00000)
    algebraic[25] = 400.000*(power(1.00000+4.50000*exp(-0.000700000*(power(states[0]-9.00000, 2.00000))), -1.00000))
    algebraic[13] = (6.00000-6.00000*exp((states[0]-7.90000)/-5.00000))/((1.00000+0.300000*exp((states[0]-7.90000)/-5.00000))*(states[0]-7.90000))
    algebraic[26] = 1.00000-power(1.00000+exp((states[0]-40.0000)/-17.0000), -1.00000)
    algebraic[4] = 0.650000*(power(exp((states[0]+18.0000)/-8.50000)+exp((states[0]-16.0000)/-59.0000), -1.00000))
    algebraic[18] = 1.20000*(power(2.20000+exp((states[0]+75.0000)/18.0000), -1.00000))
    algebraic[28] = power(algebraic[4]+algebraic[18], -1.00000)
    algebraic[35] = power(1.00000+exp((states[0]+0.500000)/-10.5000), -(1.00000/3.00000))
    algebraic[5] = power(6.20000+exp((states[0]+105.200)/9.85000), -1.00000)
    algebraic[19] = power(7.54000+exp((states[0]-8.89000)/-12.8700), -1.00000)
    algebraic[29] = power(algebraic[5]+algebraic[19], -1.00000)
    algebraic[36] = power(1.00000+exp((states[0]+43.3770)/6.45000), -1.00000)
    algebraic[6] = 1.47000*(power(exp((states[0]+33.2000)/-30.6300)+exp((states[0]-27.6000)/-30.6500), -1.00000))
    algebraic[20] = 0.420000*(power(exp((states[0]+26.6400)/2.49000)+exp((states[0]+44.4100)/20.3600), -1.00000))
    algebraic[30] = power(algebraic[6]+algebraic[20], -1.00000)
    algebraic[37] = power(1.00000+exp((states[0]+2.81000)/-9.49000), -(1.00000/3.00000))
    algebraic[7] = power(21.0000+exp((states[0]-185.000)/-28.0000), -1.00000)
    algebraic[21] = exp((states[0]-158.000)/16.0000)
    algebraic[31] = power(algebraic[7]+algebraic[21], -1.00000)
    algebraic[38] = 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[22] = 0.0280000*((states[0]+163.000)/(exp((states[0]+163.000)/21.0000)-1.00000))
    algebraic[32] = power(algebraic[8]+algebraic[22], -1.00000)
    algebraic[39] = power(1.00000+exp((states[0]+7.65400)/-5.37700), -1.00000)
    algebraic[9] = 1.00000e-05*((states[0]+28.5000)/(1.00000-exp((states[0]+28.5000)/-115.000)))
    algebraic[23] = 0.000230000*((states[0]+28.5000)/(exp((states[0]+28.5000)/3.30000)-1.00000))
    algebraic[33] = power(algebraic[9]+algebraic[23], -1.00000)
    algebraic[40] = power(1.00000+exp((states[0]-13.0000)/-12.0000), -0.500000)
    algebraic[47] = ((constants[0]*constants[1])/(-1.00000*constants[2]))*log(constants[15]/states[16])
    algebraic[48] = constants[14]*constants[16]*(states[0]-algebraic[47])
    algebraic[27] = ((constants[0]*constants[1])/constants[2])*log(constants[8]/states[5])
    algebraic[34] = (constants[7]*(states[0]-algebraic[27]))/(1.00000+exp(0.0700000*(states[0]+80.0000)))
    algebraic[41] = constants[9]*(power(states[6], 3.00000))*states[7]*(states[0]-algebraic[27])
    algebraic[42] = 0.00855000+0.0779000/(1.00000+exp((states[0]+11.0000)/-16.0000))
    algebraic[43] = algebraic[42]*(power(states[8], 3.00000))*states[9]*(states[0]-algebraic[27])
    algebraic[44] = constants[10]*states[10]*(0.0700000+0.580000/(1.00000+exp((states[0]+15.0000)/22.4000)))*(states[0]-algebraic[27])
    algebraic[45] = constants[11]*(power(states[11], 2.00000))*(states[0]-algebraic[27])
    algebraic[49] = power(1.00000+0.124500*exp(-0.100000*((constants[2]*states[0])/(constants[0]*constants[1])))+0.0365000*constants[40]*exp(-((constants[2]*states[0])/(constants[0]*constants[1]))), -1.00000)
    algebraic[50] = constants[19]*algebraic[49]*(1.00000/(1.00000+power(constants[17]/states[1], 1.50000)))*(constants[8]/(constants[8]+constants[18]))
    algebraic[0] = ((constants[0]*constants[1])/constants[2])*log(constants[6]/states[1])
    algebraic[14] = constants[5]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[0])
    algebraic[51] = (constants[20]*(exp((0.350000*constants[2]*states[0])/(constants[0]*constants[1]))*(power(states[1], 3.00000))*constants[24]-exp((-0.650000*constants[2]*states[0])/(constants[0]*constants[1]))*(power(constants[6], 3.00000))*states[12]))/((power(constants[21], 3.00000)+power(constants[6], 3.00000))*(constants[22]+constants[24])*(1.00000+constants[23]*exp((-0.650000*states[0]*constants[2])/(constants[0]*constants[1]))))
    algebraic[52] = constants[25]*(states[0]-algebraic[0])
    algebraic[46] = constants[12]*states[13]*states[14]*states[15]*(states[0]-65.0000)
    algebraic[55] = constants[27]*(states[12]/(0.000500000+states[12]))
    algebraic[53] = ((constants[0]*constants[1])/(2.00000*constants[2]))*log(constants[24]/states[12])
    algebraic[54] = constants[26]*(states[0]-algebraic[53])
    algebraic[56] = constants[28]*(power(states[18], 2.00000))*states[19]*states[20]*(states[17]-states[12])
    algebraic[57] = 1.00000e-12*constants[29]*algebraic[56]-5.00000e-13*((1.00000/(2.00000*constants[2]))*algebraic[46]-(1.00000/(5.00000*constants[2]))*algebraic[51])
    algebraic[60] = power(1.00000+exp((algebraic[57]-3.41750e-13)/-1.36700e-15), -1.00000)
    algebraic[61] = 1.91000+2.09000*(power(1.00000+exp((algebraic[57]-3.41750e-13)/-1.36700e-15), -1.00000))
    algebraic[63] = 1.00000-power(1.00000+exp((algebraic[57]-6.83500e-14)/-1.36700e-15), -1.00000)
    algebraic[58] = (states[21]-states[17])/constants[30]
    algebraic[62] = constants[31]/(1.00000+constants[32]/states[12])
    algebraic[65] = constants[31]*(states[21]/constants[33])
    algebraic[64] = rates[24]
    algebraic[66] = rates[22]
    algebraic[67] = rates[23]
    algebraic[59] = 1.00000-power(1.00000+power(algebraic[57]/1.10000e-10, 3.00000), -1.00000)
    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)