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 = 106
sizeStates = 22
sizeConstants = 93
from math import *
from numpy import *

def createLegends():
    legend_states = [""] * sizeStates
    legend_rates = [""] * sizeStates
    legend_algebraic = [""] * sizeAlgebraic
    legend_voi = ""
    legend_constants = [""] * sizeConstants
    legend_voi = "time in component environment (ms)"
    legend_states[0] = "V in component membrane (mV)"
    legend_constants[0] = "R in component membrane (mJ_per_mole_K)"
    legend_constants[1] = "T in component membrane (kelvin)"
    legend_constants[2] = "F in component membrane (C_per_mole)"
    legend_constants[3] = "Cm in component membrane (uF)"
    legend_algebraic[0] = "I_Stim in component membrane (uA)"
    legend_constants[4] = "stim_period in component membrane (ms)"
    legend_constants[5] = "stim_duration in component membrane (ms)"
    legend_constants[6] = "stim_amplitude in component membrane (uA)"
    legend_algebraic[25] = "i_Na in component sodium_current (nanoA)"
    legend_algebraic[27] = "i_t in component Ca_independent_transient_outward_K_current (nanoA)"
    legend_algebraic[28] = "i_ss in component steady_state_outward_K_current (nanoA)"
    legend_algebraic[32] = "i_f in component hyperpolarisation_activated_current (nanoA)"
    legend_algebraic[29] = "i_K1 in component inward_rectifier (nanoA)"
    legend_algebraic[33] = "i_B_Na in component background_currents (nanoA)"
    legend_algebraic[35] = "i_B_K in component background_currents (nanoA)"
    legend_algebraic[21] = "i_NaK in component sodium_potassium_pump (uA)"
    legend_algebraic[105] = "I_LCC in component convert_hinch (uA)"
    legend_algebraic[38] = "I_NaCa in component convert_hinch (uA)"
    legend_algebraic[41] = "I_pCa in component convert_hinch (uA)"
    legend_algebraic[44] = "I_CaB in component convert_hinch (uA)"
    legend_algebraic[11] = "FVRT in component membrane (dimensionless)"
    legend_algebraic[20] = "FVRT_Ca in component membrane (dimensionless)"
    legend_constants[7] = "V_myo in component cell_geometry (um3)"
    legend_constants[8] = "V_SR in component cell_geometry (um3)"
    legend_constants[9] = "V_myo_uL in component cell_geometry (uL)"
    legend_constants[10] = "V_SR_uL in component cell_geometry (uL)"
    legend_algebraic[104] = "I_LCC in component LCC_current (mM_per_ms)"
    legend_algebraic[37] = "I_NaCa in component Na_Ca_Exchanger (mM_per_ms)"
    legend_algebraic[40] = "I_pCa in component Sarcolemmal_Ca_pump (mM_per_ms)"
    legend_algebraic[43] = "I_CaB in component Background_Ca_current (mM_per_ms)"
    legend_algebraic[100] = "I_RyR in component RyR_current (mM_per_ms)"
    legend_algebraic[101] = "I_RyR in component convert_hinch (mM_per_ms)"
    legend_constants[11] = "i_NaK_max in component sodium_potassium_pump (uA)"
    legend_constants[12] = "K_m_K in component sodium_potassium_pump (mM)"
    legend_constants[13] = "K_m_Na in component sodium_potassium_pump (mM)"
    legend_constants[82] = "sigma in component sodium_potassium_pump (dimensionless)"
    legend_constants[14] = "K_o in component standard_ionic_concentrations (millimolar)"
    legend_constants[15] = "Na_o in component standard_ionic_concentrations (millimolar)"
    legend_states[1] = "Na_i in component intracellular_ion_concentrations (mM)"
    legend_states[2] = "Ca_i in component intracellular_ion_concentrations (mM)"
    legend_states[3] = "Ca_SR in component intracellular_ion_concentrations (mM)"
    legend_states[4] = "K_i in component intracellular_ion_concentrations (mM)"
    legend_states[5] = "TRPN in component intracellular_ion_concentrations (mM)"
    legend_algebraic[30] = "i_f_Na in component hyperpolarisation_activated_current (nanoA)"
    legend_algebraic[31] = "i_f_K in component hyperpolarisation_activated_current (nanoA)"
    legend_algebraic[39] = "I_SERCA in component SERCA (mM_per_ms)"
    legend_algebraic[45] = "I_SR in component SR_Ca_leak_current (mM_per_ms)"
    legend_algebraic[23] = "Ca_b in component intracellular_ion_concentrations (mM)"
    legend_constants[16] = "Ca_TRPN_Max in component troponin (mM)"
    legend_algebraic[61] = "J_TRPN in component troponin (mM_per_ms)"
    legend_algebraic[46] = "beta_CMDN in component calmodulin_Ca_buffer (dimensionless)"
    legend_algebraic[24] = "E_Na in component sodium_current (millivolt)"
    legend_constants[17] = "g_Na in component sodium_current (microS)"
    legend_constants[83] = "g_Na_endo in component sodium_current (microS)"
    legend_states[6] = "m in component sodium_current_m_gate (dimensionless)"
    legend_states[7] = "h in component sodium_current_h_gate (dimensionless)"
    legend_states[8] = "j in component sodium_current_j_gate (dimensionless)"
    legend_algebraic[26] = "E_K in component Ca_independent_transient_outward_K_current (millivolt)"
    legend_constants[18] = "g_t in component Ca_independent_transient_outward_K_current (microS)"
    legend_constants[84] = "g_t_endo in component Ca_independent_transient_outward_K_current (microS)"
    legend_constants[19] = "a_endo in component Ca_independent_transient_outward_K_current (dimensionless)"
    legend_constants[20] = "b_endo in component Ca_independent_transient_outward_K_current (dimensionless)"
    legend_states[9] = "r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)"
    legend_states[10] = "s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)"
    legend_states[11] = "s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)"
    legend_constants[21] = "g_ss in component steady_state_outward_K_current (microS)"
    legend_states[12] = "r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)"
    legend_states[13] = "s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)"
    legend_constants[22] = "g_K1 in component inward_rectifier (microS)"
    legend_constants[23] = "g_f in component hyperpolarisation_activated_current (microS)"
    legend_constants[24] = "f_Na in component hyperpolarisation_activated_current (dimensionless)"
    legend_constants[85] = "f_K in component hyperpolarisation_activated_current (dimensionless)"
    legend_states[14] = "y in component hyperpolarisation_activated_current_y_gate (dimensionless)"
    legend_algebraic[36] = "i_B in component background_currents (nanoA)"
    legend_algebraic[34] = "i_B_Ca in component background_currents (nanoA)"
    legend_constants[25] = "g_B_Na in component background_currents (microS)"
    legend_constants[26] = "g_B_Ca in component background_currents (microS)"
    legend_constants[27] = "g_B_K in component background_currents (microS)"
    legend_constants[28] = "E_Ca in component background_currents (millivolt)"
    legend_constants[29] = "Ca_o in component standard_ionic_concentrations (millimolar)"
    legend_constants[30] = "g_D in component CaRU (um3_per_ms)"
    legend_constants[31] = "J_R in component CaRU (um3_per_ms)"
    legend_constants[32] = "J_L in component CaRU (um3_per_ms)"
    legend_constants[33] = "N in component CaRU (dimensionless)"
    legend_constants[34] = "K_mNa in component Na_Ca_Exchanger (mM)"
    legend_constants[35] = "K_mCa in component Na_Ca_Exchanger (mM)"
    legend_constants[36] = "eta in component Na_Ca_Exchanger (dimensionless)"
    legend_constants[37] = "k_sat in component Na_Ca_Exchanger (dimensionless)"
    legend_constants[38] = "g_NCX in component Na_Ca_Exchanger (mM_per_ms)"
    legend_constants[39] = "g_SERCA in component SERCA (mM_per_ms)"
    legend_constants[40] = "K_SERCA in component SERCA (mM)"
    legend_constants[41] = "g_pCa in component Sarcolemmal_Ca_pump (mM_per_ms)"
    legend_constants[42] = "K_mpCa in component Sarcolemmal_Ca_pump (mM)"
    legend_algebraic[42] = "E_Ca in component Background_Ca_current (mV)"
    legend_constants[43] = "g_CaB in component Background_Ca_current (mM_per_mV_ms)"
    legend_constants[44] = "g_SRl in component SR_Ca_leak_current (per_ms)"
    legend_constants[45] = "k_CMDN in component calmodulin_Ca_buffer (mM)"
    legend_constants[46] = "B_CMDN in component calmodulin_Ca_buffer (mM)"
    legend_states[15] = "z in component tropomyosin (dimensionless)"
    legend_algebraic[54] = "z_max in component tropomyosin (dimensionless)"
    legend_constants[47] = "k_on in component troponin (per_mM_per_ms)"
    legend_constants[48] = "k_Ref_off in component troponin (per_ms)"
    legend_constants[49] = "gamma_trpn in component troponin (dimensionless)"
    legend_constants[50] = "alpha_0 in component tropomyosin (per_ms)"
    legend_constants[51] = "alpha_r1 in component tropomyosin (per_ms)"
    legend_constants[52] = "alpha_r2 in component tropomyosin (per_ms)"
    legend_constants[53] = "n_Rel in component tropomyosin (dimensionless)"
    legend_constants[54] = "K_z in component tropomyosin (dimensionless)"
    legend_constants[55] = "n_Hill in component tropomyosin (dimensionless)"
    legend_constants[56] = "Ca_50ref in component tropomyosin (mM)"
    legend_constants[57] = "z_p in component tropomyosin (dimensionless)"
    legend_constants[58] = "beta_1 in component tropomyosin (dimensionless)"
    legend_algebraic[51] = "Ca_50 in component tropomyosin (mM)"
    legend_algebraic[52] = "Ca_TRPN_50 in component tropomyosin (mM)"
    legend_constants[86] = "K_2 in component tropomyosin (per_ms)"
    legend_constants[90] = "K_1 in component tropomyosin (per_ms)"
    legend_algebraic[53] = "alpha_Tm in component tropomyosin (per_ms)"
    legend_algebraic[47] = "beta_Tm in component tropomyosin (per_ms)"
    legend_constants[59] = "beta_0 in component filament_overlap (dimensionless)"
    legend_algebraic[49] = "lambda in component Myofilaments (dimensionless)"
    legend_algebraic[60] = "k_off in component troponin (per_ms)"
    legend_algebraic[59] = "Tension in component Cross_Bridges (N_per_mm2)"
    legend_constants[60] = "T_ref in component length_independent_tension (N_per_mm2)"
    legend_algebraic[48] = "ExtensionRatio in component Myofilaments (dimensionless)"
    legend_constants[87] = "dExtensionRatiodt in component Myofilaments (per_ms)"
    legend_algebraic[50] = "lambda_prev in component Myofilaments (dimensionless)"
    legend_algebraic[55] = "overlap in component filament_overlap (dimensionless)"
    legend_algebraic[56] = "T_Base in component length_independent_tension (N_per_mm2)"
    legend_algebraic[57] = "T_0 in component isometric_tension (N_per_mm2)"
    legend_algebraic[58] = "Q in component Cross_Bridges (dimensionless)"
    legend_constants[61] = "a in component Cross_Bridges (dimensionless)"
    legend_states[16] = "Q_1 in component Cross_Bridges (dimensionless)"
    legend_states[17] = "Q_2 in component Cross_Bridges (dimensionless)"
    legend_states[18] = "Q_3 in component Cross_Bridges (dimensionless)"
    legend_constants[62] = "A_1 in component Cross_Bridges (dimensionless)"
    legend_constants[63] = "A_2 in component Cross_Bridges (dimensionless)"
    legend_constants[64] = "A_3 in component Cross_Bridges (dimensionless)"
    legend_constants[65] = "alpha_1 in component Cross_Bridges (per_ms)"
    legend_constants[66] = "alpha_2 in component Cross_Bridges (per_ms)"
    legend_constants[67] = "alpha_3 in component Cross_Bridges (per_ms)"
    legend_algebraic[1] = "m_infinity in component sodium_current_m_gate (dimensionless)"
    legend_algebraic[12] = "tau_m in component sodium_current_m_gate (second)"
    legend_algebraic[2] = "h_infinity in component sodium_current_h_gate (dimensionless)"
    legend_algebraic[13] = "tau_h in component sodium_current_h_gate (second)"
    legend_algebraic[3] = "j_infinity in component sodium_current_j_gate (dimensionless)"
    legend_algebraic[14] = "tau_j in component sodium_current_j_gate (second)"
    legend_algebraic[15] = "tau_r in component Ca_independent_transient_outward_K_current_r_gate (second)"
    legend_algebraic[4] = "r_infinity in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)"
    legend_algebraic[16] = "tau_s_endo in component Ca_independent_transient_outward_K_current_s_gate (second)"
    legend_algebraic[5] = "s_infinity in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)"
    legend_algebraic[17] = "tau_s_slow_endo in component Ca_independent_transient_outward_K_current_s_slow_gate (second)"
    legend_algebraic[6] = "s_slow_infinity in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)"
    legend_algebraic[18] = "tau_r_ss in component steady_state_outward_K_current_r_ss_gate (second)"
    legend_algebraic[7] = "r_ss_infinity in component steady_state_outward_K_current_r_ss_gate (dimensionless)"
    legend_constants[88] = "tau_s_ss in component steady_state_outward_K_current_s_ss_gate (second)"
    legend_algebraic[8] = "s_ss_infinity in component steady_state_outward_K_current_s_ss_gate (dimensionless)"
    legend_algebraic[19] = "tau_y in component hyperpolarisation_activated_current_y_gate (second)"
    legend_algebraic[9] = "y_infinity in component hyperpolarisation_activated_current_y_gate (dimensionless)"
    legend_algebraic[81] = "C_oc in component DS_Calcium_Concentrations (mM)"
    legend_algebraic[79] = "C_co in component DS_Calcium_Concentrations (mM)"
    legend_constants[68] = "V_L in component CaRU_Transitions (mV)"
    legend_constants[69] = "del_VL in component CaRU_Transitions (mV)"
    legend_constants[70] = "phi_L in component CaRU_Transitions (dimensionless)"
    legend_constants[71] = "t_L in component CaRU_Transitions (ms)"
    legend_constants[72] = "tau_L in component CaRU_Transitions (ms)"
    legend_constants[89] = "t_R in component CaRU_Transitions (ms)"
    legend_constants[73] = "tau_R in component CaRU_Transitions (ms)"
    legend_constants[74] = "phi_R in component CaRU_Transitions (dimensionless)"
    legend_constants[75] = "theta_R in component CaRU_Transitions (dimensionless)"
    legend_constants[76] = "K_RyR in component CaRU_Transitions (mM)"
    legend_constants[77] = "K_L in component CaRU_Transitions (mM)"
    legend_constants[78] = "a in component CaRU_Transitions (dimensionless)"
    legend_constants[79] = "b in component CaRU_Transitions (dimensionless)"
    legend_constants[80] = "c in component CaRU_Transitions (dimensionless)"
    legend_constants[81] = "d in component CaRU_Transitions (dimensionless)"
    legend_algebraic[62] = "expVL in component CaRU_Transitions (dimensionless)"
    legend_algebraic[63] = "alpha_p in component CaRU_Transitions (per_ms)"
    legend_constants[91] = "alpha_m in component CaRU_Transitions (per_ms)"
    legend_algebraic[82] = "beta_poc in component CaRU_Transitions (per_ms)"
    legend_algebraic[64] = "beta_pcc in component CaRU_Transitions (per_ms)"
    legend_constants[92] = "beta_m in component CaRU_Transitions (per_ms)"
    legend_algebraic[80] = "epsilon_pco in component CaRU_Transitions (per_ms)"
    legend_algebraic[65] = "epsilon_pcc in component CaRU_Transitions (per_ms)"
    legend_algebraic[66] = "epsilon_m in component CaRU_Transitions (per_ms)"
    legend_algebraic[83] = "mu_poc in component CaRU_Transitions (per_ms)"
    legend_algebraic[67] = "mu_pcc in component CaRU_Transitions (per_ms)"
    legend_algebraic[84] = "mu_moc in component CaRU_Transitions (per_ms)"
    legend_algebraic[68] = "mu_mcc in component CaRU_Transitions (per_ms)"
    legend_algebraic[85] = "denom in component CaRU_states (per_ms3)"
    legend_algebraic[86] = "y_oc in component CaRU_states (dimensionless)"
    legend_algebraic[87] = "y_co in component CaRU_states (dimensionless)"
    legend_algebraic[88] = "y_oo in component CaRU_states (dimensionless)"
    legend_algebraic[90] = "y_cc in component CaRU_states (dimensionless)"
    legend_algebraic[69] = "y_ci in component CaRU_states (dimensionless)"
    legend_algebraic[70] = "y_oi in component CaRU_states (dimensionless)"
    legend_algebraic[71] = "y_ic in component CaRU_states (dimensionless)"
    legend_algebraic[72] = "y_io in component CaRU_states (dimensionless)"
    legend_algebraic[92] = "y_ii in component CaRU_states (dimensionless)"
    legend_algebraic[93] = "r_1 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[95] = "r_2 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[73] = "r_3 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[74] = "r_4 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[97] = "r_5 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[75] = "r_6 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[76] = "r_7 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[77] = "r_8 in component CaRU_reduced_states (per_ms)"
    legend_states[19] = "z_1 in component CaRU_reduced_states (dimensionless)"
    legend_states[20] = "z_2 in component CaRU_reduced_states (dimensionless)"
    legend_states[21] = "z_3 in component CaRU_reduced_states (dimensionless)"
    legend_algebraic[78] = "z_4 in component CaRU_reduced_states (dimensionless)"
    legend_algebraic[10] = "C_cc in component DS_Calcium_Concentrations (mM)"
    legend_algebraic[22] = "C_oo in component DS_Calcium_Concentrations (mM)"
    legend_algebraic[96] = "J_Loo in component LCC_and_RyR_fluxes (um3_mM_per_ms)"
    legend_algebraic[94] = "J_Loc in component LCC_and_RyR_fluxes (um3_mM_per_ms)"
    legend_algebraic[89] = "J_Rco in component LCC_and_RyR_fluxes (um3_mM_per_ms)"
    legend_algebraic[91] = "J_Roo in component LCC_and_RyR_fluxes (um3_mM_per_ms)"
    legend_algebraic[98] = "J_R1 in component RyR_current (um3_mM_per_ms)"
    legend_algebraic[99] = "J_R3 in component RyR_current (um3_mM_per_ms)"
    legend_algebraic[102] = "J_L1 in component LCC_current (um3_mM_per_ms)"
    legend_algebraic[103] = "J_L2 in component LCC_current (um3_mM_per_ms)"
    legend_rates[0] = "d/dt V in component membrane (mV)"
    legend_rates[1] = "d/dt Na_i in component intracellular_ion_concentrations (mM)"
    legend_rates[4] = "d/dt K_i in component intracellular_ion_concentrations (mM)"
    legend_rates[5] = "d/dt TRPN in component intracellular_ion_concentrations (mM)"
    legend_rates[2] = "d/dt Ca_i in component intracellular_ion_concentrations (mM)"
    legend_rates[3] = "d/dt Ca_SR in component intracellular_ion_concentrations (mM)"
    legend_rates[15] = "d/dt z in component tropomyosin (dimensionless)"
    legend_rates[16] = "d/dt Q_1 in component Cross_Bridges (dimensionless)"
    legend_rates[17] = "d/dt Q_2 in component Cross_Bridges (dimensionless)"
    legend_rates[18] = "d/dt Q_3 in component Cross_Bridges (dimensionless)"
    legend_rates[6] = "d/dt m in component sodium_current_m_gate (dimensionless)"
    legend_rates[7] = "d/dt h in component sodium_current_h_gate (dimensionless)"
    legend_rates[8] = "d/dt j in component sodium_current_j_gate (dimensionless)"
    legend_rates[9] = "d/dt r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)"
    legend_rates[10] = "d/dt s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)"
    legend_rates[11] = "d/dt s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)"
    legend_rates[12] = "d/dt r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)"
    legend_rates[13] = "d/dt s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)"
    legend_rates[14] = "d/dt y in component hyperpolarisation_activated_current_y_gate (dimensionless)"
    legend_rates[19] = "d/dt z_1 in component CaRU_reduced_states (dimensionless)"
    legend_rates[20] = "d/dt z_2 in component CaRU_reduced_states (dimensionless)"
    legend_rates[21] = "d/dt z_3 in component CaRU_reduced_states (dimensionless)"
    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] = 1e3
    constants[5] = 10
    constants[6] = -0.6e-3
    constants[7] = 25.85e3
    constants[8] = 2.098e3
    constants[9] = 25.85e-6
    constants[10] = 2.098e-6
    constants[11] = 0.95e-4
    constants[12] = 1.5
    constants[13] = 10
    constants[14] = 5.4
    constants[15] = 140
    states[1] = 10.73519
    states[2] = 0.00007901351
    states[3] = 700.0e-3
    states[4] = 139.2751
    states[5] = 0.067593139865
    constants[16] = 70e-3
    constants[17] = 0.8
    states[6] = 0.004164108
    states[7] = 0.6735613
    states[8] = 0.6729362
    constants[18] = 0.035
    constants[19] = 0.583
    constants[20] = 0.417
    states[9] = 0.002191519
    states[10] = 0.9842542
    states[11] = 0.6421196
    constants[21] = 0.007
    states[12] = 0.002907171
    states[13] = 0.3142767
    constants[22] = 0.024
    constants[23] = 0.00145
    constants[24] = 0.2
    states[14] = 0.003578708
    constants[25] = 0.00008015
    constants[26] = 0.0000324
    constants[27] = 0.000138
    constants[28] = 65
    constants[29] = 1.2
    constants[30] = 0.065
    constants[31] = 0.02
    constants[32] = 9.13e-4
    constants[33] = 50000
    constants[34] = 87.5
    constants[35] = 1.38
    constants[36] = 0.35
    constants[37] = 0.1
    constants[38] = 38.5e-3
    constants[39] = 0.45e-3
    constants[40] = 0.5e-3
    constants[41] = 0.0035e-3
    constants[42] = 0.5e-3
    constants[43] = 2.6875e-8
    constants[44] = 1.8951e-5
    constants[45] = 2.382e-3
    constants[46] = 50e-3
    states[15] = 0.014417937837
    constants[47] = 100
    constants[48] = 0.2
    constants[49] = 2
    constants[50] = 8e-3
    constants[51] = 2e-3
    constants[52] = 1.75e-3
    constants[53] = 3
    constants[54] = 0.15
    constants[55] = 3
    constants[56] = 1.05e-3
    constants[57] = 0.85
    constants[58] = -4
    constants[59] = 4.9
    constants[60] = 56.2
    constants[61] = 0.35
    states[16] = 0
    states[17] = 0
    states[18] = 0
    constants[62] = -29
    constants[63] = 138
    constants[64] = 129
    constants[65] = 0.03
    constants[66] = 0.13
    constants[67] = 0.625
    constants[68] = -2
    constants[69] = 7
    constants[70] = 2.35
    constants[71] = 1
    constants[72] = 650
    constants[73] = 2.43
    constants[74] = 0.05
    constants[75] = 0.012
    constants[76] = 41e-3
    constants[77] = 0.22e-3
    constants[78] = 0.0625
    constants[79] = 14
    constants[80] = 0.01
    constants[81] = 100
    states[19] = 0.98859
    states[20] = 0.0087302
    states[21] = 0.0026566
    constants[82] = (exp(constants[15]/67.3000)-1.00000)/7.00000
    constants[83] = 1.33000*constants[17]
    constants[84] = 0.464700*constants[18]
    constants[85] = 1.00000-constants[24]
    constants[86] = ((constants[52]*(power(constants[57], constants[53])))/(power(constants[57], constants[53])+power(constants[54], constants[53])))*(1.00000-(constants[53]*(power(constants[54], constants[53])))/(power(constants[57], constants[53])+power(constants[54], constants[53])))
    constants[87] = 0.00000
    constants[88] = 2.10000
    constants[89] = 1.17000*constants[71]
    constants[90] = (constants[52]*(power(constants[57], constants[53]-1.00000))*constants[53]*(power(constants[54], constants[53])))/(power(power(constants[57], constants[53])+power(constants[54], constants[53]), 2.00000))
    constants[91] = constants[70]/constants[71]
    constants[92] = constants[74]/constants[89]
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    rates[16] = constants[62]*constants[87]-constants[65]*states[16]
    rates[17] = constants[63]*constants[87]-constants[66]*states[17]
    rates[18] = constants[64]*constants[87]-constants[67]*states[18]
    algebraic[8] = 1.00000/(1.00000+exp((states[0]+87.5000)/10.3000))
    rates[13] = ((algebraic[8]-states[13])/constants[88])*0.00100000
    algebraic[1] = 1.00000/(1.00000+exp((states[0]+45.0000)/-6.50000))
    algebraic[12] = 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[6] = ((algebraic[1]-states[6])/algebraic[12])*0.00100000
    algebraic[2] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000))
    algebraic[13] = 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[7] = ((algebraic[2]-states[7])/algebraic[13])*0.00100000
    algebraic[3] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000))
    algebraic[14] = 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[8] = ((algebraic[3]-states[8])/algebraic[14])*0.00100000
    algebraic[15] = 1.00000/(45.1600*exp(0.0357700*(states[0]+50.0000))+98.9000*exp(-0.100000*(states[0]+38.0000)))
    algebraic[4] = 1.00000/(1.00000+exp((states[0]+10.6000)/-11.4200))
    rates[9] = ((algebraic[4]-states[9])/algebraic[15])*0.00100000
    algebraic[16] = 0.550000*exp(-(power((states[0]+70.0000)/25.0000, 2.00000)))+0.0490000
    algebraic[5] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410))
    rates[10] = ((algebraic[5]-states[10])/algebraic[16])*0.00100000
    algebraic[17] = 3.30000*exp(((-(states[0]+70.0000)/30.0000)*(states[0]+70.0000))/30.0000)+0.0490000
    algebraic[6] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410))
    rates[11] = ((algebraic[6]-states[11])/algebraic[17])*0.00100000
    algebraic[18] = 10.0000/(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]+11.5000)/-11.8200))
    rates[12] = ((algebraic[7]-states[12])/algebraic[18])*0.00100000
    algebraic[19] = 1.00000/(0.118850*exp((states[0]+80.0000)/28.3700)+0.562300*exp((states[0]+80.0000)/-14.1900))
    algebraic[9] = 1.00000/(1.00000+exp((states[0]+138.600)/10.4800))
    rates[14] = ((algebraic[9]-states[14])/algebraic[19])*0.00100000
    algebraic[0] = custom_piecewise([greater_equal(voi-floor(voi/constants[4])*constants[4] , 0.00000) & less_equal(voi-floor(voi/constants[4])*constants[4] , constants[5]), constants[6] , True, 0.00000])
    algebraic[26] = ((constants[0]*constants[1])/constants[2])*log(constants[14]/states[4])
    algebraic[27] = constants[84]*states[9]*(constants[19]*states[10]+constants[20]*states[11])*(states[0]-algebraic[26])
    algebraic[28] = constants[21]*states[12]*states[13]*(states[0]-algebraic[26])
    algebraic[29] = ((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[26]+76.7700))/-17.0000))+(constants[22]*(states[0]-(algebraic[26]+1.73000)))/((1.00000+exp((1.61300*constants[2]*(states[0]-(algebraic[26]+1.73000)))/(constants[0]*constants[1])))*(1.00000+exp((constants[14]-0.998800)/-0.124000)))
    algebraic[35] = constants[27]*(states[0]-algebraic[26])
    algebraic[21] = (((((constants[11]*1.00000)/(1.00000+0.124500*exp((-0.100000*states[0]*constants[2])/(constants[0]*constants[1]))+0.0365000*constants[82]*exp((-states[0]*constants[2])/(constants[0]*constants[1]))))*constants[14])/(constants[14]+constants[12]))*1.00000)/(1.00000+power(constants[13]/states[1], 4.00000))
    algebraic[31] = constants[23]*states[14]*constants[85]*(states[0]-algebraic[26])
    rates[4] = (-(algebraic[0]+algebraic[28]*0.00100000+algebraic[35]*0.00100000+algebraic[27]*0.00100000+algebraic[29]*0.00100000+algebraic[31]*0.00100000+algebraic[21]*-2.00000)*1.00000)/(constants[9]*constants[2])
    algebraic[24] = ((constants[0]*constants[1])/constants[2])*log(constants[15]/states[1])
    algebraic[25] = constants[83]*(power(states[6], 3.00000))*states[7]*states[8]*(states[0]-algebraic[24])
    algebraic[33] = constants[25]*(states[0]-algebraic[24])
    algebraic[11] = (constants[2]*states[0])/(constants[0]*constants[1])
    algebraic[37] = (constants[38]*(exp(constants[36]*algebraic[11])*(power(states[1], 3.00000))*constants[29]-exp((constants[36]-1.00000)*algebraic[11])*(power(constants[15], 3.00000))*states[2]))/((power(constants[15], 3.00000)+power(constants[34], 3.00000))*(constants[29]+constants[35])*(1.00000+constants[37]*exp((constants[36]-1.00000)*algebraic[11])))
    algebraic[38] = algebraic[37]*constants[9]*constants[2]
    algebraic[30] = constants[23]*states[14]*constants[24]*(states[0]-algebraic[24])
    rates[1] = (-(algebraic[25]*0.00100000+algebraic[33]*0.00100000+algebraic[38]*3.00000+algebraic[21]*3.00000+algebraic[30]*0.00100000)*1.00000)/(constants[9]*constants[2])
    algebraic[23] = constants[16]-states[5]
    algebraic[48] = custom_piecewise([greater(voi , 300000.), 1.00000 , True, 1.00000])
    algebraic[49] = custom_piecewise([greater(algebraic[48] , 0.800000) & less_equal(algebraic[48] , 1.15000), algebraic[48] , greater(algebraic[48] , 1.15000), 1.15000 , True, 0.800000])
    algebraic[51] = constants[56]*(1.00000+constants[58]*(algebraic[49]-1.00000))
    algebraic[52] = (algebraic[51]*constants[16])/(algebraic[51]+(constants[48]/constants[47])*(1.00000-((1.00000+constants[59]*(algebraic[49]-1.00000))*0.500000)/constants[49]))
    algebraic[53] = constants[50]*(power(algebraic[23]/algebraic[52], constants[55]))
    algebraic[47] = constants[51]+(constants[52]*(power(states[15], constants[53]-1.00000)))/(power(states[15], constants[53])+power(constants[54], constants[53]))
    rates[15] = algebraic[53]*(1.00000-states[15])-algebraic[47]*states[15]
    algebraic[55] = 1.00000+constants[59]*(algebraic[49]-1.00000)
    algebraic[54] = (constants[50]/(power(algebraic[52]/constants[16], constants[55]))-constants[86])/(constants[51]+constants[90]+constants[50]/(power(algebraic[52]/constants[16], constants[55])))
    algebraic[56] = (constants[60]*states[15])/algebraic[54]
    algebraic[57] = algebraic[56]*algebraic[55]
    algebraic[58] = states[16]+states[17]+states[18]
    algebraic[59] = custom_piecewise([less(algebraic[58] , 0.00000), (algebraic[57]*(constants[61]*algebraic[58]+1.00000))/(1.00000-algebraic[58]) , True, (algebraic[57]*(1.00000+(constants[61]+2.00000)*algebraic[58]))/(1.00000+algebraic[58])])
    algebraic[60] = custom_piecewise([greater(1.00000-algebraic[59]/(constants[49]*constants[60]) , 0.100000), constants[48]*(1.00000-algebraic[59]/(constants[49]*constants[60])) , True, constants[48]*0.100000])
    algebraic[61] = (constants[16]-states[5])*algebraic[60]-states[2]*states[5]*constants[47]
    rates[5] = algebraic[61]
    algebraic[20] = 2.00000*algebraic[11]
    algebraic[81] = custom_piecewise([greater(fabs(algebraic[20]) , 1.00000e-09), (states[2]+((constants[32]/constants[30])*constants[29]*algebraic[20]*exp(-algebraic[20]))/(1.00000-exp(-algebraic[20])))/(1.00000+((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(-algebraic[20]))) , True, (states[2]+(constants[32]/constants[30])*constants[29])/(1.00000+constants[32]/constants[30])])
    algebraic[83] = (power(algebraic[81], 2.00000)+constants[80]*(power(constants[76], 2.00000)))/(constants[73]*(power(algebraic[81], 2.00000)+power(constants[76], 2.00000)))
    algebraic[67] = (power(states[2], 2.00000)+constants[80]*(power(constants[76], 2.00000)))/(constants[73]*(power(states[2], 2.00000)+power(constants[76], 2.00000)))
    algebraic[62] = exp((states[0]-constants[68])/constants[69])
    algebraic[63] = algebraic[62]/(constants[71]*(algebraic[62]+1.00000))
    algebraic[64] = (power(states[2], 2.00000))/(constants[89]*(power(states[2], 2.00000)+power(constants[76], 2.00000)))
    algebraic[82] = (power(algebraic[81], 2.00000))/(constants[89]*(power(algebraic[81], 2.00000)+power(constants[76], 2.00000)))
    algebraic[85] = (algebraic[63]+constants[91])*((constants[91]+constants[92]+algebraic[82])*(constants[92]+algebraic[64])+algebraic[63]*(constants[92]+algebraic[82]))
    algebraic[86] = (algebraic[63]*constants[92]*(algebraic[63]+constants[91]+constants[92]+algebraic[64]))/algebraic[85]
    algebraic[90] = (constants[91]*constants[92]*(constants[91]+algebraic[63]+constants[92]+algebraic[82]))/algebraic[85]
    algebraic[93] = algebraic[86]*algebraic[83]+algebraic[90]*algebraic[67]
    algebraic[84] = (constants[75]*constants[81]*(power(algebraic[81], 2.00000)+constants[80]*(power(constants[76], 2.00000))))/(constants[73]*(constants[81]*(power(algebraic[81], 2.00000))+constants[80]*(power(constants[76], 2.00000))))
    algebraic[68] = (constants[75]*constants[81]*(power(states[2], 2.00000)+constants[80]*(power(constants[76], 2.00000))))/(constants[73]*(constants[81]*(power(states[2], 2.00000))+constants[80]*(power(constants[76], 2.00000))))
    algebraic[95] = (algebraic[63]*algebraic[84]+constants[91]*algebraic[68])/(algebraic[63]+constants[91])
    algebraic[65] = (states[2]*(algebraic[62]+constants[78]))/(constants[72]*constants[77]*(algebraic[62]+1.00000))
    algebraic[76] = (constants[91]*algebraic[65])/(algebraic[63]+constants[91])
    algebraic[66] = (constants[79]*(algebraic[62]+constants[78]))/(constants[72]*(constants[79]*algebraic[62]+constants[78]))
    algebraic[77] = algebraic[66]
    algebraic[78] = ((1.00000-states[19])-states[20])-states[21]
    rates[20] = (algebraic[93]*states[19]-(algebraic[95]+algebraic[76])*states[20])+algebraic[77]*algebraic[78]
    algebraic[79] = (states[2]+(constants[31]/constants[30])*states[3])/(1.00000+constants[31]/constants[30])
    algebraic[80] = (algebraic[79]*(algebraic[62]+constants[78]))/(constants[72]*constants[77]*(algebraic[62]+1.00000))
    algebraic[87] = (constants[91]*(algebraic[64]*(constants[91]+constants[92]+algebraic[82])+algebraic[82]*algebraic[63]))/algebraic[85]
    algebraic[97] = algebraic[87]*algebraic[80]+algebraic[90]*algebraic[65]
    algebraic[75] = algebraic[66]
    rates[19] = -(algebraic[93]+algebraic[97])*states[19]+algebraic[95]*states[20]+algebraic[75]*states[21]
    algebraic[73] = (constants[92]*algebraic[67])/(constants[92]+algebraic[64])
    algebraic[74] = algebraic[68]
    rates[21] = (algebraic[97]*states[19]-(algebraic[75]+algebraic[73])*states[21])+algebraic[74]*algebraic[78]
    algebraic[88] = (algebraic[63]*(algebraic[82]*(algebraic[63]+constants[92]+algebraic[64])+algebraic[64]*constants[91]))/algebraic[85]
    algebraic[89] = (constants[31]*(states[3]-states[2]))/(1.00000+constants[31]/constants[30])
    algebraic[91] = custom_piecewise([greater(fabs(algebraic[20]) , 1.00000e-05), (constants[31]*((states[3]-states[2])+(((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(-algebraic[20])))*(states[3]-constants[29]*exp(-algebraic[20]))))/(1.00000+constants[31]/constants[30]+((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(-algebraic[20]))) , True, (constants[31]*((states[3]-states[2])+(((constants[32]/constants[30])*1.00000e-05)/(1.00000-exp(-1.00000e-05)))*(states[3]-constants[29]*exp(-1.00000e-05))))/(1.00000+constants[31]/constants[30]+((constants[32]/constants[30])*1.00000e-05)/(1.00000-exp(-1.00000e-05)))])
    algebraic[98] = algebraic[88]*algebraic[91]+algebraic[89]*algebraic[87]
    algebraic[99] = (algebraic[89]*algebraic[64])/(constants[92]+algebraic[64])
    algebraic[100] = ((states[19]*algebraic[98]+states[21]*algebraic[99])*constants[33])/constants[7]
    algebraic[101] = 1.50000*algebraic[100]
    algebraic[39] = (constants[39]*(power(states[2], 2.00000)))/(power(constants[40], 2.00000)+power(states[2], 2.00000))
    algebraic[45] = constants[44]*(states[3]-states[2])
    rates[3] = (constants[9]/constants[10])*((-algebraic[101]+algebraic[39])-algebraic[45])
    algebraic[32] = algebraic[30]+algebraic[31]
    algebraic[96] = custom_piecewise([greater(fabs(algebraic[20]) , 1.00000e-05), (((constants[32]*algebraic[20])/(1.00000-exp(-algebraic[20])))*((constants[29]*exp(-algebraic[20])-states[2])+(constants[31]/constants[30])*(constants[29]*exp(-algebraic[20])-states[3])))/(1.00000+constants[31]/constants[30]+((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(algebraic[20]))) , True, (((constants[32]*1.00000e-05)/(1.00000-exp(-1.00000e-05)))*((constants[29]*exp(-1.00000e-05)-states[2])+(constants[31]/constants[30])*(constants[29]*exp(-1.00000e-05)-states[3])))/(1.00000+constants[31]/constants[30]+((constants[32]/constants[30])*1.00000e-05)/(1.00000-exp(-1.00000e-05)))])
    algebraic[94] = custom_piecewise([greater(fabs(algebraic[20]) , 1.00000e-05), (((constants[32]*algebraic[20])/(1.00000-exp(-algebraic[20])))*(constants[29]*exp(-algebraic[20])-states[2]))/(1.00000+((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(-algebraic[20]))) , True, (((constants[32]*1.00000e-05)/(1.00000-exp(-1.00000e-05)))*(constants[29]*exp(-1.00000e-05)-states[2]))/(1.00000+((constants[32]/constants[30])*1.00000e-05)/(1.00000-exp(-1.00000e-05)))])
    algebraic[102] = algebraic[96]*algebraic[88]+algebraic[94]*algebraic[86]
    algebraic[103] = (algebraic[94]*algebraic[63])/(algebraic[63]+constants[91])
    algebraic[104] = ((states[19]*algebraic[102]+states[20]*algebraic[103])*constants[33])/constants[7]
    algebraic[105] = -1.50000*algebraic[104]*2.00000*constants[9]*constants[2]
    algebraic[40] = (constants[41]*states[2])/(constants[42]+states[2])
    algebraic[41] = algebraic[40]*2.00000*constants[9]*constants[2]
    algebraic[42] = ((constants[0]*constants[1])/(2.00000*constants[2]))*log(constants[29]/states[2])
    algebraic[43] = constants[43]*(algebraic[42]-states[0])
    algebraic[44] = -algebraic[43]*2.00000*constants[9]*constants[2]
    rates[0] = -(algebraic[25]*0.00100000+algebraic[27]*0.00100000+algebraic[28]*0.00100000+algebraic[32]*0.00100000+algebraic[29]*0.00100000+algebraic[33]*0.00100000+algebraic[35]*0.00100000+algebraic[21]+algebraic[0]+algebraic[44]+algebraic[38]+algebraic[41]+algebraic[105])/constants[3]
    algebraic[46] = power(1.00000+(constants[45]*constants[46])/(power(constants[45]+states[2], 2.00000)), -1.00000)
    rates[2] = algebraic[46]*(((algebraic[101]-algebraic[39])+algebraic[45]+algebraic[61])-(-2.00000*algebraic[38]+algebraic[41]+algebraic[44]+algebraic[105])/(2.00000*constants[9]*constants[2]))
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[8] = 1.00000/(1.00000+exp((states[0]+87.5000)/10.3000))
    algebraic[1] = 1.00000/(1.00000+exp((states[0]+45.0000)/-6.50000))
    algebraic[12] = 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[2] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000))
    algebraic[13] = 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[3] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000))
    algebraic[14] = 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[15] = 1.00000/(45.1600*exp(0.0357700*(states[0]+50.0000))+98.9000*exp(-0.100000*(states[0]+38.0000)))
    algebraic[4] = 1.00000/(1.00000+exp((states[0]+10.6000)/-11.4200))
    algebraic[16] = 0.550000*exp(-(power((states[0]+70.0000)/25.0000, 2.00000)))+0.0490000
    algebraic[5] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410))
    algebraic[17] = 3.30000*exp(((-(states[0]+70.0000)/30.0000)*(states[0]+70.0000))/30.0000)+0.0490000
    algebraic[6] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410))
    algebraic[18] = 10.0000/(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]+11.5000)/-11.8200))
    algebraic[19] = 1.00000/(0.118850*exp((states[0]+80.0000)/28.3700)+0.562300*exp((states[0]+80.0000)/-14.1900))
    algebraic[9] = 1.00000/(1.00000+exp((states[0]+138.600)/10.4800))
    algebraic[0] = custom_piecewise([greater_equal(voi-floor(voi/constants[4])*constants[4] , 0.00000) & less_equal(voi-floor(voi/constants[4])*constants[4] , constants[5]), constants[6] , True, 0.00000])
    algebraic[26] = ((constants[0]*constants[1])/constants[2])*log(constants[14]/states[4])
    algebraic[27] = constants[84]*states[9]*(constants[19]*states[10]+constants[20]*states[11])*(states[0]-algebraic[26])
    algebraic[28] = constants[21]*states[12]*states[13]*(states[0]-algebraic[26])
    algebraic[29] = ((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[26]+76.7700))/-17.0000))+(constants[22]*(states[0]-(algebraic[26]+1.73000)))/((1.00000+exp((1.61300*constants[2]*(states[0]-(algebraic[26]+1.73000)))/(constants[0]*constants[1])))*(1.00000+exp((constants[14]-0.998800)/-0.124000)))
    algebraic[35] = constants[27]*(states[0]-algebraic[26])
    algebraic[21] = (((((constants[11]*1.00000)/(1.00000+0.124500*exp((-0.100000*states[0]*constants[2])/(constants[0]*constants[1]))+0.0365000*constants[82]*exp((-states[0]*constants[2])/(constants[0]*constants[1]))))*constants[14])/(constants[14]+constants[12]))*1.00000)/(1.00000+power(constants[13]/states[1], 4.00000))
    algebraic[31] = constants[23]*states[14]*constants[85]*(states[0]-algebraic[26])
    algebraic[24] = ((constants[0]*constants[1])/constants[2])*log(constants[15]/states[1])
    algebraic[25] = constants[83]*(power(states[6], 3.00000))*states[7]*states[8]*(states[0]-algebraic[24])
    algebraic[33] = constants[25]*(states[0]-algebraic[24])
    algebraic[11] = (constants[2]*states[0])/(constants[0]*constants[1])
    algebraic[37] = (constants[38]*(exp(constants[36]*algebraic[11])*(power(states[1], 3.00000))*constants[29]-exp((constants[36]-1.00000)*algebraic[11])*(power(constants[15], 3.00000))*states[2]))/((power(constants[15], 3.00000)+power(constants[34], 3.00000))*(constants[29]+constants[35])*(1.00000+constants[37]*exp((constants[36]-1.00000)*algebraic[11])))
    algebraic[38] = algebraic[37]*constants[9]*constants[2]
    algebraic[30] = constants[23]*states[14]*constants[24]*(states[0]-algebraic[24])
    algebraic[23] = constants[16]-states[5]
    algebraic[48] = custom_piecewise([greater(voi , 300000.), 1.00000 , True, 1.00000])
    algebraic[49] = custom_piecewise([greater(algebraic[48] , 0.800000) & less_equal(algebraic[48] , 1.15000), algebraic[48] , greater(algebraic[48] , 1.15000), 1.15000 , True, 0.800000])
    algebraic[51] = constants[56]*(1.00000+constants[58]*(algebraic[49]-1.00000))
    algebraic[52] = (algebraic[51]*constants[16])/(algebraic[51]+(constants[48]/constants[47])*(1.00000-((1.00000+constants[59]*(algebraic[49]-1.00000))*0.500000)/constants[49]))
    algebraic[53] = constants[50]*(power(algebraic[23]/algebraic[52], constants[55]))
    algebraic[47] = constants[51]+(constants[52]*(power(states[15], constants[53]-1.00000)))/(power(states[15], constants[53])+power(constants[54], constants[53]))
    algebraic[55] = 1.00000+constants[59]*(algebraic[49]-1.00000)
    algebraic[54] = (constants[50]/(power(algebraic[52]/constants[16], constants[55]))-constants[86])/(constants[51]+constants[90]+constants[50]/(power(algebraic[52]/constants[16], constants[55])))
    algebraic[56] = (constants[60]*states[15])/algebraic[54]
    algebraic[57] = algebraic[56]*algebraic[55]
    algebraic[58] = states[16]+states[17]+states[18]
    algebraic[59] = custom_piecewise([less(algebraic[58] , 0.00000), (algebraic[57]*(constants[61]*algebraic[58]+1.00000))/(1.00000-algebraic[58]) , True, (algebraic[57]*(1.00000+(constants[61]+2.00000)*algebraic[58]))/(1.00000+algebraic[58])])
    algebraic[60] = custom_piecewise([greater(1.00000-algebraic[59]/(constants[49]*constants[60]) , 0.100000), constants[48]*(1.00000-algebraic[59]/(constants[49]*constants[60])) , True, constants[48]*0.100000])
    algebraic[61] = (constants[16]-states[5])*algebraic[60]-states[2]*states[5]*constants[47]
    algebraic[20] = 2.00000*algebraic[11]
    algebraic[81] = custom_piecewise([greater(fabs(algebraic[20]) , 1.00000e-09), (states[2]+((constants[32]/constants[30])*constants[29]*algebraic[20]*exp(-algebraic[20]))/(1.00000-exp(-algebraic[20])))/(1.00000+((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(-algebraic[20]))) , True, (states[2]+(constants[32]/constants[30])*constants[29])/(1.00000+constants[32]/constants[30])])
    algebraic[83] = (power(algebraic[81], 2.00000)+constants[80]*(power(constants[76], 2.00000)))/(constants[73]*(power(algebraic[81], 2.00000)+power(constants[76], 2.00000)))
    algebraic[67] = (power(states[2], 2.00000)+constants[80]*(power(constants[76], 2.00000)))/(constants[73]*(power(states[2], 2.00000)+power(constants[76], 2.00000)))
    algebraic[62] = exp((states[0]-constants[68])/constants[69])
    algebraic[63] = algebraic[62]/(constants[71]*(algebraic[62]+1.00000))
    algebraic[64] = (power(states[2], 2.00000))/(constants[89]*(power(states[2], 2.00000)+power(constants[76], 2.00000)))
    algebraic[82] = (power(algebraic[81], 2.00000))/(constants[89]*(power(algebraic[81], 2.00000)+power(constants[76], 2.00000)))
    algebraic[85] = (algebraic[63]+constants[91])*((constants[91]+constants[92]+algebraic[82])*(constants[92]+algebraic[64])+algebraic[63]*(constants[92]+algebraic[82]))
    algebraic[86] = (algebraic[63]*constants[92]*(algebraic[63]+constants[91]+constants[92]+algebraic[64]))/algebraic[85]
    algebraic[90] = (constants[91]*constants[92]*(constants[91]+algebraic[63]+constants[92]+algebraic[82]))/algebraic[85]
    algebraic[93] = algebraic[86]*algebraic[83]+algebraic[90]*algebraic[67]
    algebraic[84] = (constants[75]*constants[81]*(power(algebraic[81], 2.00000)+constants[80]*(power(constants[76], 2.00000))))/(constants[73]*(constants[81]*(power(algebraic[81], 2.00000))+constants[80]*(power(constants[76], 2.00000))))
    algebraic[68] = (constants[75]*constants[81]*(power(states[2], 2.00000)+constants[80]*(power(constants[76], 2.00000))))/(constants[73]*(constants[81]*(power(states[2], 2.00000))+constants[80]*(power(constants[76], 2.00000))))
    algebraic[95] = (algebraic[63]*algebraic[84]+constants[91]*algebraic[68])/(algebraic[63]+constants[91])
    algebraic[65] = (states[2]*(algebraic[62]+constants[78]))/(constants[72]*constants[77]*(algebraic[62]+1.00000))
    algebraic[76] = (constants[91]*algebraic[65])/(algebraic[63]+constants[91])
    algebraic[66] = (constants[79]*(algebraic[62]+constants[78]))/(constants[72]*(constants[79]*algebraic[62]+constants[78]))
    algebraic[77] = algebraic[66]
    algebraic[78] = ((1.00000-states[19])-states[20])-states[21]
    algebraic[79] = (states[2]+(constants[31]/constants[30])*states[3])/(1.00000+constants[31]/constants[30])
    algebraic[80] = (algebraic[79]*(algebraic[62]+constants[78]))/(constants[72]*constants[77]*(algebraic[62]+1.00000))
    algebraic[87] = (constants[91]*(algebraic[64]*(constants[91]+constants[92]+algebraic[82])+algebraic[82]*algebraic[63]))/algebraic[85]
    algebraic[97] = algebraic[87]*algebraic[80]+algebraic[90]*algebraic[65]
    algebraic[75] = algebraic[66]
    algebraic[73] = (constants[92]*algebraic[67])/(constants[92]+algebraic[64])
    algebraic[74] = algebraic[68]
    algebraic[88] = (algebraic[63]*(algebraic[82]*(algebraic[63]+constants[92]+algebraic[64])+algebraic[64]*constants[91]))/algebraic[85]
    algebraic[89] = (constants[31]*(states[3]-states[2]))/(1.00000+constants[31]/constants[30])
    algebraic[91] = custom_piecewise([greater(fabs(algebraic[20]) , 1.00000e-05), (constants[31]*((states[3]-states[2])+(((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(-algebraic[20])))*(states[3]-constants[29]*exp(-algebraic[20]))))/(1.00000+constants[31]/constants[30]+((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(-algebraic[20]))) , True, (constants[31]*((states[3]-states[2])+(((constants[32]/constants[30])*1.00000e-05)/(1.00000-exp(-1.00000e-05)))*(states[3]-constants[29]*exp(-1.00000e-05))))/(1.00000+constants[31]/constants[30]+((constants[32]/constants[30])*1.00000e-05)/(1.00000-exp(-1.00000e-05)))])
    algebraic[98] = algebraic[88]*algebraic[91]+algebraic[89]*algebraic[87]
    algebraic[99] = (algebraic[89]*algebraic[64])/(constants[92]+algebraic[64])
    algebraic[100] = ((states[19]*algebraic[98]+states[21]*algebraic[99])*constants[33])/constants[7]
    algebraic[101] = 1.50000*algebraic[100]
    algebraic[39] = (constants[39]*(power(states[2], 2.00000)))/(power(constants[40], 2.00000)+power(states[2], 2.00000))
    algebraic[45] = constants[44]*(states[3]-states[2])
    algebraic[32] = algebraic[30]+algebraic[31]
    algebraic[96] = custom_piecewise([greater(fabs(algebraic[20]) , 1.00000e-05), (((constants[32]*algebraic[20])/(1.00000-exp(-algebraic[20])))*((constants[29]*exp(-algebraic[20])-states[2])+(constants[31]/constants[30])*(constants[29]*exp(-algebraic[20])-states[3])))/(1.00000+constants[31]/constants[30]+((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(algebraic[20]))) , True, (((constants[32]*1.00000e-05)/(1.00000-exp(-1.00000e-05)))*((constants[29]*exp(-1.00000e-05)-states[2])+(constants[31]/constants[30])*(constants[29]*exp(-1.00000e-05)-states[3])))/(1.00000+constants[31]/constants[30]+((constants[32]/constants[30])*1.00000e-05)/(1.00000-exp(-1.00000e-05)))])
    algebraic[94] = custom_piecewise([greater(fabs(algebraic[20]) , 1.00000e-05), (((constants[32]*algebraic[20])/(1.00000-exp(-algebraic[20])))*(constants[29]*exp(-algebraic[20])-states[2]))/(1.00000+((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(-algebraic[20]))) , True, (((constants[32]*1.00000e-05)/(1.00000-exp(-1.00000e-05)))*(constants[29]*exp(-1.00000e-05)-states[2]))/(1.00000+((constants[32]/constants[30])*1.00000e-05)/(1.00000-exp(-1.00000e-05)))])
    algebraic[102] = algebraic[96]*algebraic[88]+algebraic[94]*algebraic[86]
    algebraic[103] = (algebraic[94]*algebraic[63])/(algebraic[63]+constants[91])
    algebraic[104] = ((states[19]*algebraic[102]+states[20]*algebraic[103])*constants[33])/constants[7]
    algebraic[105] = -1.50000*algebraic[104]*2.00000*constants[9]*constants[2]
    algebraic[40] = (constants[41]*states[2])/(constants[42]+states[2])
    algebraic[41] = algebraic[40]*2.00000*constants[9]*constants[2]
    algebraic[42] = ((constants[0]*constants[1])/(2.00000*constants[2]))*log(constants[29]/states[2])
    algebraic[43] = constants[43]*(algebraic[42]-states[0])
    algebraic[44] = -algebraic[43]*2.00000*constants[9]*constants[2]
    algebraic[46] = power(1.00000+(constants[45]*constants[46])/(power(constants[45]+states[2], 2.00000)), -1.00000)
    algebraic[10] = states[2]
    algebraic[22] = custom_piecewise([greater(fabs(algebraic[20]) , 1.00000e-09), (states[2]+(constants[31]/constants[30])*states[3]+((constants[32]/constants[30])*constants[29]*algebraic[20]*exp(-algebraic[20]))/(1.00000-exp(-algebraic[20])))/(1.00000+constants[31]/constants[30]+((constants[32]/constants[30])*algebraic[20])/(1.00000-exp(-algebraic[20]))) , True, (states[2]+(constants[31]/constants[30])*states[3]+(constants[32]/constants[30])*constants[29])/(1.00000+constants[31]/constants[30]+constants[32]/constants[30])])
    algebraic[34] = constants[26]*(states[0]-constants[28])
    algebraic[36] = algebraic[33]+algebraic[34]+algebraic[35]
    algebraic[50] = algebraic[48]
    algebraic[69] = constants[91]/(algebraic[63]+constants[91])
    algebraic[70] = algebraic[63]/(algebraic[63]+constants[91])
    algebraic[71] = constants[92]/(algebraic[64]+constants[92])
    algebraic[72] = algebraic[64]/(algebraic[64]+constants[92])
    algebraic[92] = (((((((1.00000-algebraic[86])-algebraic[87])-algebraic[88])-algebraic[90])-algebraic[69])-algebraic[71])-algebraic[70])-algebraic[72]
    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)