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 = 54
sizeStates = 26
sizeConstants = 69
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 (second)"
    legend_states[0] = "V in component membrane (millivolt)"
    legend_constants[0] = "R in component membrane (millijoule_per_mole_kelvin)"
    legend_constants[1] = "T in component membrane (kelvin)"
    legend_constants[2] = "F in component membrane (coulomb_per_mole)"
    legend_constants[3] = "Cm in component membrane (microF)"
    legend_algebraic[26] = "i_Na in component sodium_current (nanoA)"
    legend_algebraic[27] = "i_Ca_L in component L_type_Ca_channel (nanoA)"
    legend_algebraic[29] = "i_t in component Ca_independent_transient_outward_K_current (nanoA)"
    legend_algebraic[30] = "i_ss in component steady_state_outward_K_current (nanoA)"
    legend_algebraic[34] = "i_f in component hyperpolarisation_activated_current (nanoA)"
    legend_algebraic[31] = "i_K1 in component inward_rectifier (nanoA)"
    legend_algebraic[38] = "i_B in component background_currents (nanoA)"
    legend_algebraic[39] = "i_NaK in component sodium_potassium_pump (nanoA)"
    legend_algebraic[41] = "i_NaCa in component Na_Ca_ion_exchanger_current (nanoA)"
    legend_algebraic[40] = "i_Ca_P in component sarcolemmal_calcium_pump_current (nanoA)"
    legend_algebraic[13] = "i_Stim in component membrane (nanoA)"
    legend_constants[4] = "stim_start in component membrane (second)"
    legend_constants[5] = "stim_end in component membrane (second)"
    legend_constants[6] = "stim_period in component membrane (second)"
    legend_constants[7] = "stim_duration in component membrane (second)"
    legend_constants[8] = "stim_amplitude in component membrane (nanoA)"
    legend_algebraic[25] = "E_Na in component sodium_current (millivolt)"
    legend_constants[9] = "g_Na in component sodium_current (microS)"
    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 sodium_current_m_gate (dimensionless)"
    legend_states[3] = "h in component sodium_current_h_gate (dimensionless)"
    legend_states[4] = "j in component sodium_current_j_gate (dimensionless)"
    legend_algebraic[0] = "m_max in component sodium_current_m_gate (dimensionless)"
    legend_algebraic[14] = "tau_m in component sodium_current_m_gate (second)"
    legend_algebraic[1] = "h_max in component sodium_current_h_gate (dimensionless)"
    legend_algebraic[15] = "tau_h in component sodium_current_h_gate (second)"
    legend_algebraic[2] = "j_max in component sodium_current_j_gate (dimensionless)"
    legend_algebraic[16] = "tau_j in component sodium_current_j_gate (second)"
    legend_constants[11] = "g_Ca_L in component L_type_Ca_channel (microS)"
    legend_constants[12] = "E_Ca_L in component L_type_Ca_channel (millivolt)"
    legend_states[5] = "Ca_ss in component intracellular_ion_concentrations (millimolar)"
    legend_states[6] = "d in component L_type_Ca_channel_d_gate (dimensionless)"
    legend_states[7] = "f_11 in component L_type_Ca_channel_f_11_gate (dimensionless)"
    legend_states[8] = "f_12 in component L_type_Ca_channel_f_12_gate (dimensionless)"
    legend_states[9] = "Ca_inact in component L_type_Ca_channel_Ca_inact_gate (dimensionless)"
    legend_algebraic[3] = "d_max in component L_type_Ca_channel_d_gate (dimensionless)"
    legend_algebraic[17] = "tau_d in component L_type_Ca_channel_d_gate (second)"
    legend_algebraic[4] = "f_11_max in component L_type_Ca_channel_f_11_gate (dimensionless)"
    legend_algebraic[18] = "tau_f_11 in component L_type_Ca_channel_f_11_gate (second)"
    legend_algebraic[5] = "f_12_max in component L_type_Ca_channel_f_12_gate (dimensionless)"
    legend_algebraic[19] = "tau_f_12 in component L_type_Ca_channel_f_12_gate (second)"
    legend_constants[13] = "tau_Ca_inact in component L_type_Ca_channel_Ca_inact_gate (second)"
    legend_algebraic[6] = "Ca_inact_max in component L_type_Ca_channel_Ca_inact_gate (dimensionless)"
    legend_algebraic[28] = "E_K in component Ca_independent_transient_outward_K_current (millivolt)"
    legend_constants[14] = "g_t in component Ca_independent_transient_outward_K_current (microS)"
    legend_constants[15] = "a in component Ca_independent_transient_outward_K_current (dimensionless)"
    legend_constants[16] = "b in component Ca_independent_transient_outward_K_current (dimensionless)"
    legend_constants[17] = "K_o in component standard_ionic_concentrations (millimolar)"
    legend_states[10] = "K_i in component intracellular_ion_concentrations (millimolar)"
    legend_states[11] = "r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)"
    legend_states[12] = "s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)"
    legend_states[13] = "s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)"
    legend_algebraic[20] = "tau_r in component Ca_independent_transient_outward_K_current_r_gate (second)"
    legend_algebraic[7] = "r_max in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)"
    legend_algebraic[21] = "tau_s in component Ca_independent_transient_outward_K_current_s_gate (second)"
    legend_algebraic[8] = "s_max in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)"
    legend_algebraic[22] = "tau_s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (second)"
    legend_algebraic[9] = "s_slow_max in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)"
    legend_constants[18] = "g_ss in component steady_state_outward_K_current (microS)"
    legend_states[14] = "r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)"
    legend_states[15] = "s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)"
    legend_algebraic[23] = "tau_r_ss in component steady_state_outward_K_current_r_ss_gate (second)"
    legend_algebraic[10] = "r_ss_max in component steady_state_outward_K_current_r_ss_gate (dimensionless)"
    legend_constants[66] = "tau_s_ss in component steady_state_outward_K_current_s_ss_gate (second)"
    legend_algebraic[11] = "s_ss_max in component steady_state_outward_K_current_s_ss_gate (dimensionless)"
    legend_constants[19] = "g_K1 in component inward_rectifier (microS)"
    legend_algebraic[32] = "i_f_Na in component hyperpolarisation_activated_current (nanoA)"
    legend_algebraic[33] = "i_f_K in component hyperpolarisation_activated_current (nanoA)"
    legend_constants[20] = "g_f in component hyperpolarisation_activated_current (microS)"
    legend_constants[21] = "f_Na in component hyperpolarisation_activated_current (dimensionless)"
    legend_constants[67] = "f_K in component hyperpolarisation_activated_current (dimensionless)"
    legend_states[16] = "y in component hyperpolarisation_activated_current_y_gate (dimensionless)"
    legend_algebraic[24] = "tau_y in component hyperpolarisation_activated_current_y_gate (second)"
    legend_algebraic[12] = "y_infinity in component hyperpolarisation_activated_current_y_gate (dimensionless)"
    legend_algebraic[35] = "i_B_Na in component background_currents (nanoA)"
    legend_algebraic[36] = "i_B_Ca in component background_currents (nanoA)"
    legend_algebraic[37] = "i_B_K in component background_currents (nanoA)"
    legend_constants[22] = "g_B_Na in component background_currents (microS)"
    legend_constants[23] = "g_B_Ca in component background_currents (microS)"
    legend_constants[24] = "g_B_K in component background_currents (microS)"
    legend_constants[25] = "E_Ca in component background_currents (millivolt)"
    legend_constants[26] = "Ca_o in component standard_ionic_concentrations (millimolar)"
    legend_states[17] = "Ca_i in component intracellular_ion_concentrations (millimolar)"
    legend_constants[27] = "i_NaK_max in component sodium_potassium_pump (nanoA)"
    legend_constants[28] = "K_m_K in component sodium_potassium_pump (millimolar)"
    legend_constants[29] = "K_m_Na in component sodium_potassium_pump (millimolar)"
    legend_constants[68] = "sigma in component sodium_potassium_pump (dimensionless)"
    legend_constants[30] = "i_Ca_P_max in component sarcolemmal_calcium_pump_current (nanoA)"
    legend_constants[31] = "K_NaCa in component Na_Ca_ion_exchanger_current (nanoA_per_millimolar4)"
    legend_constants[32] = "d_NaCa in component Na_Ca_ion_exchanger_current (per_millimolar4)"
    legend_constants[33] = "gamma_NaCa in component Na_Ca_ion_exchanger_current (dimensionless)"
    legend_algebraic[42] = "J_rel in component SR_Ca_release_channel (millimolar_per_second)"
    legend_constants[34] = "v1 in component SR_Ca_release_channel (per_second)"
    legend_constants[35] = "k_a_plus in component SR_Ca_release_channel (per_millimolar4_per_second)"
    legend_constants[36] = "k_a_minus in component SR_Ca_release_channel (per_second)"
    legend_constants[37] = "k_b_plus in component SR_Ca_release_channel (per_millimolar3_per_second)"
    legend_constants[38] = "k_b_minus in component SR_Ca_release_channel (per_second)"
    legend_constants[39] = "k_c_plus in component SR_Ca_release_channel (per_second)"
    legend_constants[40] = "k_c_minus in component SR_Ca_release_channel (per_second)"
    legend_states[18] = "P_O1 in component SR_Ca_release_channel (dimensionless)"
    legend_states[19] = "P_O2 in component SR_Ca_release_channel (dimensionless)"
    legend_states[20] = "P_C1 in component SR_Ca_release_channel (dimensionless)"
    legend_states[21] = "P_C2 in component SR_Ca_release_channel (dimensionless)"
    legend_states[22] = "Ca_JSR in component intracellular_ion_concentrations (millimolar)"
    legend_algebraic[45] = "J_up in component SERCA2a_pump (millimolar_per_second)"
    legend_constants[41] = "K_fb in component SERCA2a_pump (millimolar)"
    legend_constants[42] = "K_rb in component SERCA2a_pump (millimolar)"
    legend_algebraic[43] = "fb in component SERCA2a_pump (dimensionless)"
    legend_algebraic[44] = "rb in component SERCA2a_pump (dimensionless)"
    legend_constants[43] = "Vmaxf in component SERCA2a_pump (millimolar_per_second)"
    legend_constants[44] = "Vmaxr in component SERCA2a_pump (millimolar_per_second)"
    legend_constants[45] = "K_SR in component SERCA2a_pump (dimensionless)"
    legend_constants[46] = "N_fb in component SERCA2a_pump (dimensionless)"
    legend_constants[47] = "N_rb in component SERCA2a_pump (dimensionless)"
    legend_states[23] = "Ca_NSR in component intracellular_ion_concentrations (millimolar)"
    legend_algebraic[47] = "J_tr in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)"
    legend_algebraic[46] = "J_xfer in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)"
    legend_algebraic[52] = "J_trpn in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)"
    legend_constants[48] = "tau_tr in component intracellular_and_SR_Ca_fluxes (second)"
    legend_constants[49] = "tau_xfer in component intracellular_and_SR_Ca_fluxes (second)"
    legend_states[24] = "HTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar)"
    legend_states[25] = "LTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar)"
    legend_algebraic[48] = "J_HTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)"
    legend_algebraic[51] = "J_LTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)"
    legend_constants[50] = "HTRPN_tot in component intracellular_and_SR_Ca_fluxes (millimolar)"
    legend_constants[51] = "LTRPN_tot in component intracellular_and_SR_Ca_fluxes (millimolar)"
    legend_constants[52] = "k_htrpn_plus in component intracellular_and_SR_Ca_fluxes (per_millimolar_per_second)"
    legend_constants[53] = "k_htrpn_minus in component intracellular_and_SR_Ca_fluxes (per_second)"
    legend_constants[54] = "k_ltrpn_plus in component intracellular_and_SR_Ca_fluxes (per_millimolar_per_second)"
    legend_constants[55] = "k_ltrpn_minus in component intracellular_and_SR_Ca_fluxes (per_second)"
    legend_constants[56] = "V_myo in component intracellular_ion_concentrations (micro_litre)"
    legend_constants[57] = "V_JSR in component intracellular_ion_concentrations (micro_litre)"
    legend_constants[58] = "V_NSR in component intracellular_ion_concentrations (micro_litre)"
    legend_constants[59] = "V_SS in component intracellular_ion_concentrations (micro_litre)"
    legend_constants[60] = "K_mCMDN in component intracellular_ion_concentrations (millimolar)"
    legend_constants[61] = "K_mCSQN in component intracellular_ion_concentrations (millimolar)"
    legend_constants[62] = "K_mEGTA in component intracellular_ion_concentrations (millimolar)"
    legend_constants[63] = "CMDN_tot in component intracellular_ion_concentrations (millimolar)"
    legend_constants[64] = "CSQN_tot in component intracellular_ion_concentrations (millimolar)"
    legend_constants[65] = "EGTA_tot in component intracellular_ion_concentrations (millimolar)"
    legend_algebraic[53] = "beta_i in component intracellular_ion_concentrations (dimensionless)"
    legend_algebraic[49] = "beta_SS in component intracellular_ion_concentrations (dimensionless)"
    legend_algebraic[50] = "beta_JSR in component intracellular_ion_concentrations (dimensionless)"
    legend_rates[0] = "d/dt V in component membrane (millivolt)"
    legend_rates[2] = "d/dt m in component sodium_current_m_gate (dimensionless)"
    legend_rates[3] = "d/dt h in component sodium_current_h_gate (dimensionless)"
    legend_rates[4] = "d/dt j in component sodium_current_j_gate (dimensionless)"
    legend_rates[6] = "d/dt d in component L_type_Ca_channel_d_gate (dimensionless)"
    legend_rates[7] = "d/dt f_11 in component L_type_Ca_channel_f_11_gate (dimensionless)"
    legend_rates[8] = "d/dt f_12 in component L_type_Ca_channel_f_12_gate (dimensionless)"
    legend_rates[9] = "d/dt Ca_inact in component L_type_Ca_channel_Ca_inact_gate (dimensionless)"
    legend_rates[11] = "d/dt r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)"
    legend_rates[12] = "d/dt s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)"
    legend_rates[13] = "d/dt s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)"
    legend_rates[14] = "d/dt r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)"
    legend_rates[15] = "d/dt s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)"
    legend_rates[16] = "d/dt y in component hyperpolarisation_activated_current_y_gate (dimensionless)"
    legend_rates[20] = "d/dt P_C1 in component SR_Ca_release_channel (dimensionless)"
    legend_rates[18] = "d/dt P_O1 in component SR_Ca_release_channel (dimensionless)"
    legend_rates[19] = "d/dt P_O2 in component SR_Ca_release_channel (dimensionless)"
    legend_rates[21] = "d/dt P_C2 in component SR_Ca_release_channel (dimensionless)"
    legend_rates[24] = "d/dt HTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar)"
    legend_rates[25] = "d/dt LTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar)"
    legend_rates[17] = "d/dt Ca_i in component intracellular_ion_concentrations (millimolar)"
    legend_rates[1] = "d/dt Na_i in component intracellular_ion_concentrations (millimolar)"
    legend_rates[10] = "d/dt K_i in component intracellular_ion_concentrations (millimolar)"
    legend_rates[5] = "d/dt Ca_ss in component intracellular_ion_concentrations (millimolar)"
    legend_rates[22] = "d/dt Ca_JSR in component intracellular_ion_concentrations (millimolar)"
    legend_rates[23] = "d/dt Ca_NSR 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] = -80.50146
    constants[0] = 8314.5
    constants[1] = 295
    constants[2] = 96487
    constants[3] = 0.0001
    constants[4] = 0.1
    constants[5] = 10
    constants[6] = 1
    constants[7] = 0.005
    constants[8] = -0.6
    constants[9] = 0.8
    states[1] = 10.73519
    constants[10] = 140
    states[2] = 0.004164108
    states[3] = 0.6735613
    states[4] = 0.6729362
    constants[11] = 0.031
    constants[12] = 65
    states[5] = 0.00008737212
    states[6] = 0.000002171081
    states[7] = 0.9999529
    states[8] = 0.9999529
    states[9] = 0.9913102
    constants[13] = 0.009
    constants[14] = 0.035
    constants[15] = 0.886
    constants[16] = 0.114
    constants[17] = 5.4
    states[10] = 139.2751
    states[11] = 0.002191519
    states[12] = 0.9842542
    states[13] = 0.6421196
    constants[18] = 0.007
    states[14] = 0.002907171
    states[15] = 0.3142767
    constants[19] = 0.024
    constants[20] = 0.00145
    constants[21] = 0.2
    states[16] = 0.003578708
    constants[22] = 0.00008015
    constants[23] = 0.0000324
    constants[24] = 0.000138
    constants[25] = 65
    constants[26] = 1.2
    states[17] = 0.00007901351
    constants[27] = 0.08
    constants[28] = 1.5
    constants[29] = 10
    constants[30] = 0.004
    constants[31] = 0.000009984
    constants[32] = 0.0001
    constants[33] = 0.5
    constants[34] = 1.8e3
    constants[35] = 12.15e12
    constants[36] = 576
    constants[37] = 4.05e9
    constants[38] = 1930
    constants[39] = 100
    constants[40] = 0.8
    states[18] = 0.0004327548
    states[19] = 0.000000000606254
    states[20] = 0.6348229
    states[21] = 0.3647471
    states[22] = 0.06607948
    constants[41] = 0.000168
    constants[42] = 3.29
    constants[43] = 0.04
    constants[44] = 0.9
    constants[45] = 1
    constants[46] = 1.2
    constants[47] = 1
    states[23] = 0.06600742
    constants[48] = 0.0005747
    constants[49] = 0.0267
    states[24] = 1.394301e-1
    states[25] = 5.1619e-3
    constants[50] = 0.14
    constants[51] = 0.07
    constants[52] = 200000
    constants[53] = 0.066
    constants[54] = 40000
    constants[55] = 40
    constants[56] = 9.36e-6
    constants[57] = 5.6e-8
    constants[58] = 5.04e-7
    constants[59] = 1.2e-9
    constants[60] = 0.00238
    constants[61] = 0.8
    constants[62] = 0.00015
    constants[63] = 0.05
    constants[64] = 15
    constants[65] = 10
    constants[66] = 2.10000
    constants[67] = 1.00000-constants[21]
    constants[68] = (exp(constants[10]/67.3000)-1.00000)/7.00000
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    rates[20] = -constants[35]*(power(states[5], 4.00000))*states[20]+constants[36]*states[18]
    rates[18] = (constants[35]*(power(states[5], 4.00000))*states[20]-(constants[36]*states[18]+constants[37]*(power(states[5], 3.00000))*states[18]+constants[39]*states[18]))+constants[38]*states[19]+constants[40]*states[21]
    rates[19] = constants[37]*(power(states[5], 3.00000))*states[18]-constants[38]*states[19]
    rates[21] = constants[39]*states[18]-constants[40]*states[21]
    algebraic[6] = 1.00000/(1.00000+states[5]/0.0100000)
    rates[9] = (algebraic[6]-states[9])/constants[13]
    algebraic[11] = 1.00000/(1.00000+exp((states[0]+87.5000)/10.3000))
    rates[15] = (algebraic[11]-states[15])/constants[66]
    algebraic[0] = 1.00000/(1.00000+exp((states[0]+45.0000)/-6.50000))
    algebraic[14] = 0.00136000/((0.320000*(states[0]+47.1300))/(1.00000-exp(-0.100000*(states[0]+47.1300)))+0.0800000*exp(-states[0]/11.0000))
    rates[2] = (algebraic[0]-states[2])/algebraic[14]
    algebraic[1] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000))
    algebraic[15] = custom_piecewise([greater_equal(states[0] , -40.0000), 0.000453700*(1.00000+exp(-(states[0]+10.6600)/11.1000)) , True, 0.00349000/(0.135000*exp(-(states[0]+80.0000)/6.80000)+3.56000*exp(0.0790000*states[0])+310000.*exp(0.350000*states[0]))])
    rates[3] = (algebraic[1]-states[3])/algebraic[15]
    algebraic[2] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000))
    algebraic[16] = custom_piecewise([greater_equal(states[0] , -40.0000), (0.0116300*(1.00000+exp(-0.100000*(states[0]+32.0000))))/exp(-2.53500e-07*states[0]) , True, 0.00349000/(((states[0]+37.7800)/(1.00000+exp(0.311000*(states[0]+79.2300))))*(-127140.*exp(0.244400*states[0])-3.47400e-05*exp(-0.0439100*states[0]))+(0.121200*exp(-0.0105200*states[0]))/(1.00000+exp(-0.137800*(states[0]+40.1400))))])
    rates[4] = (algebraic[2]-states[4])/algebraic[16]
    algebraic[3] = 1.00000/(1.00000+exp((states[0]+15.3000)/-5.00000))
    algebraic[17] = 0.00305000*exp(-0.00450000*(power(states[0]+7.00000, 2.00000)))+0.00105000*exp(-0.00200000*(power(states[0]-18.0000, 2.00000)))+0.000250000
    rates[6] = (algebraic[3]-states[6])/algebraic[17]
    algebraic[4] = 1.00000/(1.00000+exp((states[0]+26.7000)/5.40000))
    algebraic[18] = 0.105000*exp(-(power((states[0]+45.0000)/12.0000, 2.00000)))+0.0400000/(1.00000+exp((-states[0]+25.0000)/25.0000))+0.0150000/(1.00000+exp((states[0]+75.0000)/25.0000))+0.00170000
    rates[7] = (algebraic[4]-states[7])/algebraic[18]
    algebraic[5] = 1.00000/(1.00000+exp((states[0]+26.7000)/5.40000))
    algebraic[19] = 0.0410000*exp(-(power((states[0]+47.0000)/12.0000, 2.00000)))+0.0800000/(1.00000+exp((states[0]+55.0000)/-5.00000))+0.0150000/(1.00000+exp((states[0]+75.0000)/25.0000))+0.00170000
    rates[8] = (algebraic[5]-states[8])/algebraic[19]
    algebraic[20] = 1.00000/(45.1600*exp(0.0357700*(states[0]+50.0000))+98.9000*exp(-0.100000*(states[0]+38.0000)))
    algebraic[7] = 1.00000/(1.00000+exp((states[0]+10.6000)/-11.4200))
    rates[11] = (algebraic[7]-states[11])/algebraic[20]
    algebraic[21] = 0.350000*exp(-(power((states[0]+70.0000)/15.0000, 2.00000)))+0.0350000
    algebraic[8] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410))
    rates[12] = (algebraic[8]-states[12])/algebraic[21]
    algebraic[22] = 3.70000*exp(-(power((states[0]+70.0000)/30.0000, 2.00000)))+0.0350000
    algebraic[9] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410))
    rates[13] = (algebraic[9]-states[13])/algebraic[22]
    algebraic[23] = 10.0000/(45.1600*exp(0.0357700*(states[0]+50.0000))+98.9000*exp(-0.100000*(states[0]+38.0000)))
    algebraic[10] = 1.00000/(1.00000+exp((states[0]+11.5000)/-11.8200))
    rates[14] = (algebraic[10]-states[14])/algebraic[23]
    algebraic[24] = 1.00000/(0.118850*exp((states[0]+80.0000)/28.3700)+0.562300*exp((states[0]+80.0000)/-14.1900))
    algebraic[12] = 1.00000/(1.00000+exp((states[0]+138.600)/10.4800))
    rates[16] = (algebraic[12]-states[16])/algebraic[24]
    algebraic[28] = ((constants[0]*constants[1])/constants[2])*log(constants[17]/states[10])
    algebraic[29] = constants[14]*states[11]*(constants[15]*states[12]+constants[16]*states[13])*(states[0]-algebraic[28])
    algebraic[30] = constants[18]*states[14]*states[15]*(states[0]-algebraic[28])
    algebraic[31] = ((48.0000/(exp((states[0]+37.0000)/25.0000)+exp((states[0]+37.0000)/-25.0000))+10.0000)*0.00100000)/(1.00000+exp((states[0]-(algebraic[28]+76.7700))/-17.0000))+(constants[19]*(states[0]-(algebraic[28]+1.73000)))/((1.00000+exp((1.61300*constants[2]*(states[0]-(algebraic[28]+1.73000)))/(constants[0]*constants[1])))*(1.00000+exp((constants[17]-0.998800)/-0.124000)))
    algebraic[39] = (((constants[27]/(1.00000+0.124500*exp((-0.100000*states[0]*constants[2])/(constants[0]*constants[1]))+0.0365000*constants[68]*exp((-states[0]*constants[2])/(constants[0]*constants[1]))))*constants[17])/(constants[17]+constants[28]))/(1.00000+power(constants[29]/states[1], 1.50000))
    algebraic[33] = constants[20]*states[16]*constants[67]*(states[0]-algebraic[28])
    algebraic[37] = constants[24]*(states[0]-algebraic[28])
    rates[10] = -(algebraic[30]+algebraic[37]+algebraic[29]+algebraic[31]+algebraic[33]+algebraic[39]*-2.00000)/(constants[56]*constants[2])
    algebraic[25] = ((constants[0]*constants[1])/constants[2])*log(constants[10]/states[1])
    algebraic[26] = constants[9]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[25])
    algebraic[27] = constants[11]*states[6]*((0.900000+states[9]/10.0000)*states[7]+(0.100000-states[9]/10.0000)*states[8])*(states[0]-constants[12])
    algebraic[32] = constants[20]*states[16]*constants[21]*(states[0]-algebraic[25])
    algebraic[34] = algebraic[32]+algebraic[33]
    algebraic[35] = constants[22]*(states[0]-algebraic[25])
    algebraic[36] = constants[23]*(states[0]-constants[25])
    algebraic[38] = algebraic[35]+algebraic[36]+algebraic[37]
    algebraic[41] = (constants[31]*((power(states[1], 3.00000))*constants[26]*exp(0.0374300*states[0]*constants[33])-(power(constants[10], 3.00000))*states[17]*exp(0.0374300*states[0]*(constants[33]-1.00000))))/(1.00000+constants[32]*(states[17]*(power(constants[10], 3.00000))+constants[26]*(power(states[1], 3.00000))))
    algebraic[40] = (constants[30]*states[17])/(states[17]+0.000400000)
    algebraic[13] = custom_piecewise([greater_equal(voi , constants[4]) & less_equal(voi , constants[5]) & less_equal((voi-constants[4])-floor((voi-constants[4])/constants[6])*constants[6] , constants[7]), constants[8] , True, 0.00000])
    rates[0] = -(algebraic[26]+algebraic[27]+algebraic[29]+algebraic[30]+algebraic[34]+algebraic[31]+algebraic[38]+algebraic[39]+algebraic[41]+algebraic[40]+algebraic[13])/constants[3]
    rates[1] = -(algebraic[26]+algebraic[35]+algebraic[41]*3.00000+algebraic[39]*3.00000+algebraic[32])/(constants[56]*constants[2])
    algebraic[43] = power(states[17]/constants[41], constants[46])
    algebraic[44] = power(states[23]/constants[42], constants[47])
    algebraic[45] = (constants[45]*(constants[43]*algebraic[43]-constants[44]*algebraic[44]))/(1.00000+algebraic[43]+algebraic[44])
    algebraic[47] = (states[23]-states[22])/constants[48]
    rates[23] = (algebraic[45]*constants[56])/constants[58]-(algebraic[47]*constants[57])/constants[58]
    algebraic[48] = constants[52]*states[17]*(constants[50]-states[24])-constants[53]*states[24]
    rates[24] = algebraic[48]
    algebraic[42] = constants[34]*(states[18]+states[19])*(states[22]-states[5])
    algebraic[46] = (states[5]-states[17])/constants[49]
    algebraic[49] = 1.00000/(1.00000+(constants[63]*constants[60])/(power(constants[60]+states[5], 2.00000)))
    rates[5] = algebraic[49]*(((algebraic[42]*constants[57])/constants[59]-(algebraic[46]*constants[56])/constants[59])-algebraic[27]/(2.00000*constants[59]*constants[2]))
    algebraic[50] = 1.00000/(1.00000+(constants[64]*constants[61])/(power(constants[61]+states[22], 2.00000)))
    rates[22] = algebraic[50]*(algebraic[47]-algebraic[42])
    algebraic[51] = constants[54]*states[17]*(constants[51]-states[25])-constants[55]*states[25]
    rates[25] = algebraic[51]
    algebraic[52] = algebraic[48]+algebraic[51]
    algebraic[53] = 1.00000/(1.00000+(constants[63]*constants[60])/(power(constants[60]+states[17], 2.00000))+(constants[65]*constants[62])/(power(constants[62]+states[17], 2.00000)))
    rates[17] = algebraic[53]*(algebraic[46]-(algebraic[45]+algebraic[52]+((algebraic[36]-2.00000*algebraic[41])+algebraic[40])/(2.00000*constants[56]*constants[2])))
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[6] = 1.00000/(1.00000+states[5]/0.0100000)
    algebraic[11] = 1.00000/(1.00000+exp((states[0]+87.5000)/10.3000))
    algebraic[0] = 1.00000/(1.00000+exp((states[0]+45.0000)/-6.50000))
    algebraic[14] = 0.00136000/((0.320000*(states[0]+47.1300))/(1.00000-exp(-0.100000*(states[0]+47.1300)))+0.0800000*exp(-states[0]/11.0000))
    algebraic[1] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000))
    algebraic[15] = custom_piecewise([greater_equal(states[0] , -40.0000), 0.000453700*(1.00000+exp(-(states[0]+10.6600)/11.1000)) , True, 0.00349000/(0.135000*exp(-(states[0]+80.0000)/6.80000)+3.56000*exp(0.0790000*states[0])+310000.*exp(0.350000*states[0]))])
    algebraic[2] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000))
    algebraic[16] = custom_piecewise([greater_equal(states[0] , -40.0000), (0.0116300*(1.00000+exp(-0.100000*(states[0]+32.0000))))/exp(-2.53500e-07*states[0]) , True, 0.00349000/(((states[0]+37.7800)/(1.00000+exp(0.311000*(states[0]+79.2300))))*(-127140.*exp(0.244400*states[0])-3.47400e-05*exp(-0.0439100*states[0]))+(0.121200*exp(-0.0105200*states[0]))/(1.00000+exp(-0.137800*(states[0]+40.1400))))])
    algebraic[3] = 1.00000/(1.00000+exp((states[0]+15.3000)/-5.00000))
    algebraic[17] = 0.00305000*exp(-0.00450000*(power(states[0]+7.00000, 2.00000)))+0.00105000*exp(-0.00200000*(power(states[0]-18.0000, 2.00000)))+0.000250000
    algebraic[4] = 1.00000/(1.00000+exp((states[0]+26.7000)/5.40000))
    algebraic[18] = 0.105000*exp(-(power((states[0]+45.0000)/12.0000, 2.00000)))+0.0400000/(1.00000+exp((-states[0]+25.0000)/25.0000))+0.0150000/(1.00000+exp((states[0]+75.0000)/25.0000))+0.00170000
    algebraic[5] = 1.00000/(1.00000+exp((states[0]+26.7000)/5.40000))
    algebraic[19] = 0.0410000*exp(-(power((states[0]+47.0000)/12.0000, 2.00000)))+0.0800000/(1.00000+exp((states[0]+55.0000)/-5.00000))+0.0150000/(1.00000+exp((states[0]+75.0000)/25.0000))+0.00170000
    algebraic[20] = 1.00000/(45.1600*exp(0.0357700*(states[0]+50.0000))+98.9000*exp(-0.100000*(states[0]+38.0000)))
    algebraic[7] = 1.00000/(1.00000+exp((states[0]+10.6000)/-11.4200))
    algebraic[21] = 0.350000*exp(-(power((states[0]+70.0000)/15.0000, 2.00000)))+0.0350000
    algebraic[8] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410))
    algebraic[22] = 3.70000*exp(-(power((states[0]+70.0000)/30.0000, 2.00000)))+0.0350000
    algebraic[9] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410))
    algebraic[23] = 10.0000/(45.1600*exp(0.0357700*(states[0]+50.0000))+98.9000*exp(-0.100000*(states[0]+38.0000)))
    algebraic[10] = 1.00000/(1.00000+exp((states[0]+11.5000)/-11.8200))
    algebraic[24] = 1.00000/(0.118850*exp((states[0]+80.0000)/28.3700)+0.562300*exp((states[0]+80.0000)/-14.1900))
    algebraic[12] = 1.00000/(1.00000+exp((states[0]+138.600)/10.4800))
    algebraic[28] = ((constants[0]*constants[1])/constants[2])*log(constants[17]/states[10])
    algebraic[29] = constants[14]*states[11]*(constants[15]*states[12]+constants[16]*states[13])*(states[0]-algebraic[28])
    algebraic[30] = constants[18]*states[14]*states[15]*(states[0]-algebraic[28])
    algebraic[31] = ((48.0000/(exp((states[0]+37.0000)/25.0000)+exp((states[0]+37.0000)/-25.0000))+10.0000)*0.00100000)/(1.00000+exp((states[0]-(algebraic[28]+76.7700))/-17.0000))+(constants[19]*(states[0]-(algebraic[28]+1.73000)))/((1.00000+exp((1.61300*constants[2]*(states[0]-(algebraic[28]+1.73000)))/(constants[0]*constants[1])))*(1.00000+exp((constants[17]-0.998800)/-0.124000)))
    algebraic[39] = (((constants[27]/(1.00000+0.124500*exp((-0.100000*states[0]*constants[2])/(constants[0]*constants[1]))+0.0365000*constants[68]*exp((-states[0]*constants[2])/(constants[0]*constants[1]))))*constants[17])/(constants[17]+constants[28]))/(1.00000+power(constants[29]/states[1], 1.50000))
    algebraic[33] = constants[20]*states[16]*constants[67]*(states[0]-algebraic[28])
    algebraic[37] = constants[24]*(states[0]-algebraic[28])
    algebraic[25] = ((constants[0]*constants[1])/constants[2])*log(constants[10]/states[1])
    algebraic[26] = constants[9]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[25])
    algebraic[27] = constants[11]*states[6]*((0.900000+states[9]/10.0000)*states[7]+(0.100000-states[9]/10.0000)*states[8])*(states[0]-constants[12])
    algebraic[32] = constants[20]*states[16]*constants[21]*(states[0]-algebraic[25])
    algebraic[34] = algebraic[32]+algebraic[33]
    algebraic[35] = constants[22]*(states[0]-algebraic[25])
    algebraic[36] = constants[23]*(states[0]-constants[25])
    algebraic[38] = algebraic[35]+algebraic[36]+algebraic[37]
    algebraic[41] = (constants[31]*((power(states[1], 3.00000))*constants[26]*exp(0.0374300*states[0]*constants[33])-(power(constants[10], 3.00000))*states[17]*exp(0.0374300*states[0]*(constants[33]-1.00000))))/(1.00000+constants[32]*(states[17]*(power(constants[10], 3.00000))+constants[26]*(power(states[1], 3.00000))))
    algebraic[40] = (constants[30]*states[17])/(states[17]+0.000400000)
    algebraic[13] = 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[43] = power(states[17]/constants[41], constants[46])
    algebraic[44] = power(states[23]/constants[42], constants[47])
    algebraic[45] = (constants[45]*(constants[43]*algebraic[43]-constants[44]*algebraic[44]))/(1.00000+algebraic[43]+algebraic[44])
    algebraic[47] = (states[23]-states[22])/constants[48]
    algebraic[48] = constants[52]*states[17]*(constants[50]-states[24])-constants[53]*states[24]
    algebraic[42] = constants[34]*(states[18]+states[19])*(states[22]-states[5])
    algebraic[46] = (states[5]-states[17])/constants[49]
    algebraic[49] = 1.00000/(1.00000+(constants[63]*constants[60])/(power(constants[60]+states[5], 2.00000)))
    algebraic[50] = 1.00000/(1.00000+(constants[64]*constants[61])/(power(constants[61]+states[22], 2.00000)))
    algebraic[51] = constants[54]*states[17]*(constants[51]-states[25])-constants[55]*states[25]
    algebraic[52] = algebraic[48]+algebraic[51]
    algebraic[53] = 1.00000/(1.00000+(constants[63]*constants[60])/(power(constants[60]+states[17], 2.00000))+(constants[65]*constants[62])/(power(constants[62]+states[17], 2.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)