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 = 105
sizeStates = 22
sizeConstants = 90
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[11] = "I_Stim in component membrane (uA)"
    legend_algebraic[0] = "stim_period in component membrane (ms)"
    legend_constants[4] = "stim_duration in component membrane (ms)"
    legend_constants[5] = "stim_amplitude in component membrane (uA)"
    legend_algebraic[24] = "i_Na in component pandit_sodium_current (uA)"
    legend_algebraic[26] = "i_t in component pandit_Ca_independent_transient_outward_K_current (uA)"
    legend_algebraic[27] = "i_ss in component pandit_steady_state_outward_K_current (uA)"
    legend_algebraic[31] = "i_f in component pandit_hyperpolarisation_activated_current (uA)"
    legend_algebraic[28] = "i_K1 in component pandit_inward_rectifier (uA)"
    legend_algebraic[32] = "i_B_Na in component pandit_background_currents (uA)"
    legend_algebraic[33] = "i_B_K in component pandit_background_currents (uA)"
    legend_algebraic[34] = "i_NaK in component pandit_sodium_potassium_pump (uA)"
    legend_algebraic[84] = "I_LCC in component convert_hinch (uA)"
    legend_algebraic[85] = "I_NaCa in component convert_hinch (uA)"
    legend_algebraic[86] = "I_pCa in component convert_hinch (uA)"
    legend_algebraic[87] = "I_CaB in component convert_hinch (uA)"
    legend_algebraic[20] = "FVRT in component membrane (dimensionless)"
    legend_algebraic[21] = "FVRT_Ca in component membrane (dimensionless)"
    legend_constants[6] = "V_myo in component cell_geometry (um3)"
    legend_constants[7] = "V_SR in component cell_geometry (um3)"
    legend_constants[8] = "V_myo_uL in component cell_geometry (uL)"
    legend_constants[9] = "V_SR_uL in component cell_geometry (uL)"
    legend_algebraic[23] = "E_Na in component pandit_sodium_current (mV)"
    legend_constants[10] = "g_Na in component pandit_sodium_current (mSi)"
    legend_constants[79] = "g_Na_endo in component pandit_sodium_current (mSi)"
    legend_states[1] = "Na_i in component intracellular_ion_concentrations (mM)"
    legend_constants[11] = "Na_o in component pandit_standard_ionic_concentrations (mM)"
    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[1] = "m_infinity in component sodium_current_m_gate (dimensionless)"
    legend_algebraic[12] = "tau_m in component sodium_current_m_gate (ms)"
    legend_algebraic[2] = "h_infinity in component sodium_current_h_gate (dimensionless)"
    legend_algebraic[13] = "tau_h in component sodium_current_h_gate (ms)"
    legend_algebraic[3] = "j_infinity in component sodium_current_j_gate (dimensionless)"
    legend_algebraic[14] = "tau_j in component sodium_current_j_gate (ms)"
    legend_algebraic[25] = "E_K in component pandit_Ca_independent_transient_outward_K_current (mV)"
    legend_constants[12] = "g_t in component pandit_Ca_independent_transient_outward_K_current (mSi)"
    legend_constants[80] = "g_t_endo in component pandit_Ca_independent_transient_outward_K_current (mSi)"
    legend_constants[13] = "a_endo in component pandit_Ca_independent_transient_outward_K_current (dimensionless)"
    legend_constants[14] = "b_endo in component pandit_Ca_independent_transient_outward_K_current (dimensionless)"
    legend_constants[15] = "K_o in component pandit_standard_ionic_concentrations (mM)"
    legend_states[5] = "K_i in component intracellular_ion_concentrations (mM)"
    legend_states[6] = "r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)"
    legend_states[7] = "s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)"
    legend_states[8] = "s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)"
    legend_algebraic[15] = "tau_r in component Ca_independent_transient_outward_K_current_r_gate (ms)"
    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 (ms)"
    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 (ms)"
    legend_algebraic[6] = "s_slow_infinity in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)"
    legend_constants[16] = "g_ss in component pandit_steady_state_outward_K_current (mSi)"
    legend_states[9] = "r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)"
    legend_states[10] = "s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)"
    legend_algebraic[18] = "tau_r_ss in component steady_state_outward_K_current_r_ss_gate (ms)"
    legend_algebraic[7] = "r_ss_infinity in component steady_state_outward_K_current_r_ss_gate (dimensionless)"
    legend_constants[81] = "tau_s_ss in component steady_state_outward_K_current_s_ss_gate (ms)"
    legend_algebraic[8] = "s_ss_infinity in component steady_state_outward_K_current_s_ss_gate (dimensionless)"
    legend_constants[17] = "g_K1 in component pandit_inward_rectifier (mSi)"
    legend_algebraic[29] = "i_f_Na in component pandit_hyperpolarisation_activated_current (uA)"
    legend_algebraic[30] = "i_f_K in component pandit_hyperpolarisation_activated_current (uA)"
    legend_constants[18] = "g_f in component pandit_hyperpolarisation_activated_current (mSi)"
    legend_constants[19] = "f_Na in component pandit_hyperpolarisation_activated_current (dimensionless)"
    legend_constants[82] = "f_K in component pandit_hyperpolarisation_activated_current (dimensionless)"
    legend_states[11] = "y in component hyperpolarisation_activated_current_y_gate (dimensionless)"
    legend_algebraic[19] = "tau_y in component hyperpolarisation_activated_current_y_gate (ms)"
    legend_algebraic[9] = "y_infinity in component hyperpolarisation_activated_current_y_gate (dimensionless)"
    legend_constants[20] = "g_B_Na in component pandit_background_currents (mSi)"
    legend_constants[21] = "g_B_K in component pandit_background_currents (mSi)"
    legend_constants[22] = "i_NaK_max in component pandit_sodium_potassium_pump (uA)"
    legend_constants[23] = "K_m_K in component pandit_sodium_potassium_pump (mM)"
    legend_constants[24] = "K_m_Na in component pandit_sodium_potassium_pump (mM)"
    legend_constants[83] = "sigma in component pandit_sodium_potassium_pump (dimensionless)"
    legend_constants[25] = "Ca_o in component pandit_standard_ionic_concentrations (mM)"
    legend_constants[26] = "g_D in component hinch_CaRU (um3_per_ms)"
    legend_constants[27] = "J_R in component hinch_CaRU (um3_per_ms)"
    legend_constants[28] = "J_L in component hinch_CaRU (um3_per_ms)"
    legend_constants[29] = "N in component hinch_CaRU (dimensionless)"
    legend_states[12] = "Ca_i in component intracellular_ion_concentrations (mM)"
    legend_states[13] = "Ca_SR in component intracellular_ion_concentrations (mM)"
    legend_algebraic[63] = "I_RyR in component RyR_current (mM_per_ms)"
    legend_algebraic[72] = "I_LCC in component LCC_current (mM_per_ms)"
    legend_algebraic[44] = "C_oc in component DS_Calcium_Concentrations (mM)"
    legend_algebraic[42] = "C_co in component DS_Calcium_Concentrations (mM)"
    legend_constants[30] = "V_L in component CaRU_Transitions (mV)"
    legend_constants[31] = "del_VL in component CaRU_Transitions (mV)"
    legend_constants[32] = "phi_L in component CaRU_Transitions (dimensionless)"
    legend_constants[33] = "t_L in component CaRU_Transitions (ms)"
    legend_constants[34] = "tau_L in component CaRU_Transitions (ms)"
    legend_constants[84] = "t_R in component CaRU_Transitions (ms)"
    legend_constants[35] = "tau_R in component CaRU_Transitions (ms)"
    legend_constants[36] = "phi_R in component CaRU_Transitions (dimensionless)"
    legend_constants[37] = "theta_R in component CaRU_Transitions (dimensionless)"
    legend_constants[38] = "K_RyR in component CaRU_Transitions (mM)"
    legend_constants[39] = "K_L in component CaRU_Transitions (mM)"
    legend_constants[40] = "a in component CaRU_Transitions (dimensionless)"
    legend_constants[41] = "b in component CaRU_Transitions (dimensionless)"
    legend_constants[42] = "c in component CaRU_Transitions (dimensionless)"
    legend_constants[43] = "d in component CaRU_Transitions (dimensionless)"
    legend_algebraic[35] = "expVL in component CaRU_Transitions (dimensionless)"
    legend_algebraic[36] = "alpha_p in component CaRU_Transitions (per_ms)"
    legend_constants[87] = "alpha_m in component CaRU_Transitions (per_ms)"
    legend_algebraic[45] = "beta_poc in component CaRU_Transitions (per_ms)"
    legend_algebraic[37] = "beta_pcc in component CaRU_Transitions (per_ms)"
    legend_constants[89] = "beta_m in component CaRU_Transitions (per_ms)"
    legend_algebraic[43] = "epsilon_pco in component CaRU_Transitions (per_ms)"
    legend_algebraic[38] = "epsilon_pcc in component CaRU_Transitions (per_ms)"
    legend_algebraic[39] = "epsilon_m in component CaRU_Transitions (per_ms)"
    legend_algebraic[46] = "mu_poc in component CaRU_Transitions (per_ms)"
    legend_algebraic[40] = "mu_pcc in component CaRU_Transitions (per_ms)"
    legend_algebraic[47] = "mu_moc in component CaRU_Transitions (per_ms)"
    legend_algebraic[41] = "mu_mcc in component CaRU_Transitions (per_ms)"
    legend_algebraic[10] = "C_cc in component DS_Calcium_Concentrations (mM)"
    legend_algebraic[22] = "C_oo in component DS_Calcium_Concentrations (mM)"
    legend_algebraic[51] = "J_Loo in component LCC_and_RyR_fluxes (um3_mM_per_ms)"
    legend_algebraic[50] = "J_Loc in component LCC_and_RyR_fluxes (um3_mM_per_ms)"
    legend_algebraic[48] = "J_Rco in component LCC_and_RyR_fluxes (um3_mM_per_ms)"
    legend_algebraic[49] = "J_Roo in component LCC_and_RyR_fluxes (um3_mM_per_ms)"
    legend_algebraic[52] = "denom in component CaRU_states (per_ms3)"
    legend_algebraic[53] = "y_oc in component CaRU_states (dimensionless)"
    legend_algebraic[54] = "y_co in component CaRU_states (dimensionless)"
    legend_algebraic[55] = "y_oo in component CaRU_states (dimensionless)"
    legend_algebraic[56] = "y_cc in component CaRU_states (dimensionless)"
    legend_algebraic[58] = "y_ci in component CaRU_states (dimensionless)"
    legend_algebraic[61] = "y_oi in component CaRU_states (dimensionless)"
    legend_algebraic[64] = "y_ic in component CaRU_states (dimensionless)"
    legend_algebraic[67] = "y_io in component CaRU_states (dimensionless)"
    legend_algebraic[70] = "y_ii in component CaRU_states (dimensionless)"
    legend_algebraic[59] = "r_1 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[62] = "r_2 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[65] = "r_3 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[68] = "r_4 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[71] = "r_5 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[73] = "r_6 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[75] = "r_7 in component CaRU_reduced_states (per_ms)"
    legend_algebraic[77] = "r_8 in component CaRU_reduced_states (per_ms)"
    legend_states[14] = "z_1 in component CaRU_reduced_states (dimensionless)"
    legend_states[15] = "z_2 in component CaRU_reduced_states (dimensionless)"
    legend_states[16] = "z_3 in component CaRU_reduced_states (dimensionless)"
    legend_algebraic[79] = "z_4 in component CaRU_reduced_states (dimensionless)"
    legend_algebraic[57] = "J_R1 in component RyR_current (um3_mM_per_ms)"
    legend_algebraic[60] = "J_R3 in component RyR_current (um3_mM_per_ms)"
    legend_algebraic[66] = "J_L1 in component LCC_current (um3_mM_per_ms)"
    legend_algebraic[69] = "J_L2 in component LCC_current (um3_mM_per_ms)"
    legend_constants[44] = "K_mNa in component hinch_Na_Ca_Exchanger (mM)"
    legend_constants[45] = "K_mCa in component hinch_Na_Ca_Exchanger (mM)"
    legend_constants[46] = "eta in component hinch_Na_Ca_Exchanger (dimensionless)"
    legend_constants[47] = "k_sat in component hinch_Na_Ca_Exchanger (dimensionless)"
    legend_constants[48] = "g_NCX in component hinch_Na_Ca_Exchanger (mM_per_ms)"
    legend_algebraic[74] = "I_NaCa in component hinch_Na_Ca_Exchanger (mM_per_ms)"
    legend_constants[49] = "g_SERCA in component hinch_SERCA (mM_per_ms)"
    legend_constants[50] = "K_SERCA in component hinch_SERCA (mM)"
    legend_algebraic[76] = "I_SERCA in component hinch_SERCA (mM_per_ms)"
    legend_constants[51] = "g_pCa in component hinch_Sarcolemmal_Ca_pump (mM_per_ms)"
    legend_constants[52] = "K_mpCa in component hinch_Sarcolemmal_Ca_pump (mM)"
    legend_algebraic[78] = "I_pCa in component hinch_Sarcolemmal_Ca_pump (mM_per_ms)"
    legend_algebraic[80] = "E_Ca in component hinch_Background_Ca_current (mV)"
    legend_constants[53] = "g_CaB in component hinch_Background_Ca_current (mM_per_mV_ms)"
    legend_algebraic[81] = "I_CaB in component hinch_Background_Ca_current (mM_per_ms)"
    legend_constants[54] = "g_SRl in component hinch_SR_Ca_leak_current (per_ms)"
    legend_algebraic[82] = "I_SR in component hinch_SR_Ca_leak_current (mM_per_ms)"
    legend_constants[55] = "k_CMDN in component hinch_calmodulin_Ca_buffer (mM)"
    legend_constants[56] = "B_CMDN in component hinch_calmodulin_Ca_buffer (mM)"
    legend_algebraic[83] = "beta_CMDN in component hinch_calmodulin_Ca_buffer (dimensionless)"
    legend_algebraic[88] = "I_RyR in component convert_hinch (mM_per_ms)"
    legend_states[17] = "z in component niederer_tropomyosin (dimensionless)"
    legend_algebraic[95] = "z_max in component niederer_tropomyosin (dimensionless)"
    legend_constants[57] = "k_on in component niederer_troponin (per_mM_ms)"
    legend_constants[58] = "k_Ref_off in component niederer_troponin (per_ms)"
    legend_constants[59] = "gamma_trpn in component niederer_troponin (dimensionless)"
    legend_constants[60] = "Ca_TRPN_Max in component niederer_troponin (mM)"
    legend_constants[61] = "alpha_0 in component niederer_tropomyosin (per_ms)"
    legend_constants[62] = "alpha_r1 in component niederer_tropomyosin (per_ms)"
    legend_constants[63] = "alpha_r2 in component niederer_tropomyosin (per_ms)"
    legend_constants[64] = "n_Rel in component niederer_tropomyosin (dimensionless)"
    legend_constants[65] = "K_z in component niederer_tropomyosin (dimensionless)"
    legend_constants[66] = "n_Hill in component niederer_tropomyosin (dimensionless)"
    legend_constants[67] = "Ca_50ref in component niederer_tropomyosin (mM)"
    legend_constants[68] = "z_p in component niederer_tropomyosin (dimensionless)"
    legend_constants[69] = "beta_1 in component niederer_tropomyosin (dimensionless)"
    legend_algebraic[93] = "Ca_50 in component niederer_tropomyosin (mM)"
    legend_algebraic[94] = "Ca_TRPN_50 in component niederer_tropomyosin (mM)"
    legend_constants[85] = "K_2 in component niederer_tropomyosin (per_ms)"
    legend_constants[88] = "K_1 in component niederer_tropomyosin (per_ms)"
    legend_algebraic[97] = "alpha_Tm in component niederer_tropomyosin (per_ms)"
    legend_algebraic[89] = "beta_Tm in component niederer_tropomyosin (per_ms)"
    legend_constants[70] = "beta_0 in component niederer_filament_overlap (dimensionless)"
    legend_algebraic[96] = "Ca_b in component intracellular_ion_concentrations (mM)"
    legend_algebraic[91] = "lambda in component niederer_Myofilaments (dimensionless)"
    legend_algebraic[104] = "I_TRPN in component niederer_troponin (mM_per_ms)"
    legend_states[18] = "TRPN in component intracellular_ion_concentrations (mM)"
    legend_algebraic[103] = "k_off in component niederer_troponin (per_ms)"
    legend_algebraic[102] = "Tension in component niederer_Cross_Bridges (N_per_mm2)"
    legend_constants[71] = "T_ref in component niederer_length_independent_tension (N_per_mm2)"
    legend_algebraic[90] = "ExtensionRatio in component niederer_Myofilaments (dimensionless)"
    legend_constants[86] = "dExtensionRatiodt in component niederer_Myofilaments (per_ms)"
    legend_algebraic[92] = "lambda_prev in component niederer_Myofilaments (dimensionless)"
    legend_algebraic[98] = "overlap in component niederer_filament_overlap (dimensionless)"
    legend_algebraic[99] = "T_Base in component niederer_length_independent_tension (N_per_mm2)"
    legend_algebraic[100] = "T_0 in component niederer_isometric_tension (N_per_mm2)"
    legend_algebraic[101] = "Q in component niederer_Cross_Bridges (dimensionless)"
    legend_constants[72] = "a in component niederer_Cross_Bridges (dimensionless)"
    legend_states[19] = "Q_1 in component niederer_Cross_Bridges (dimensionless)"
    legend_states[20] = "Q_2 in component niederer_Cross_Bridges (dimensionless)"
    legend_states[21] = "Q_3 in component niederer_Cross_Bridges (dimensionless)"
    legend_constants[73] = "A_1 in component niederer_Cross_Bridges (dimensionless)"
    legend_constants[74] = "A_2 in component niederer_Cross_Bridges (dimensionless)"
    legend_constants[75] = "A_3 in component niederer_Cross_Bridges (dimensionless)"
    legend_constants[76] = "alpha_1 in component niederer_Cross_Bridges (per_ms)"
    legend_constants[77] = "alpha_2 in component niederer_Cross_Bridges (per_ms)"
    legend_constants[78] = "alpha_3 in component niederer_Cross_Bridges (per_ms)"
    legend_rates[0] = "d/dt V in component membrane (mV)"
    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 r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)"
    legend_rates[7] = "d/dt s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)"
    legend_rates[8] = "d/dt s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)"
    legend_rates[9] = "d/dt r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)"
    legend_rates[10] = "d/dt s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)"
    legend_rates[11] = "d/dt y in component hyperpolarisation_activated_current_y_gate (dimensionless)"
    legend_rates[14] = "d/dt z_1 in component CaRU_reduced_states (dimensionless)"
    legend_rates[15] = "d/dt z_2 in component CaRU_reduced_states (dimensionless)"
    legend_rates[16] = "d/dt z_3 in component CaRU_reduced_states (dimensionless)"
    legend_rates[17] = "d/dt z in component niederer_tropomyosin (dimensionless)"
    legend_rates[19] = "d/dt Q_1 in component niederer_Cross_Bridges (dimensionless)"
    legend_rates[20] = "d/dt Q_2 in component niederer_Cross_Bridges (dimensionless)"
    legend_rates[21] = "d/dt Q_3 in component niederer_Cross_Bridges (dimensionless)"
    legend_rates[1] = "d/dt Na_i in component intracellular_ion_concentrations (mM)"
    legend_rates[5] = "d/dt K_i in component intracellular_ion_concentrations (mM)"
    legend_rates[18] = "d/dt TRPN in component intracellular_ion_concentrations (mM)"
    legend_rates[12] = "d/dt Ca_i in component intracellular_ion_concentrations (mM)"
    legend_rates[13] = "d/dt Ca_SR in component intracellular_ion_concentrations (mM)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    states[0] = -78.8
    constants[0] = 8314.5
    constants[1] = 295
    constants[2] = 96487
    constants[3] = 0.0001
    constants[4] = 10
    constants[5] = -0.6e-3
    constants[6] = 25.85e3
    constants[7] = 2.098e3
    constants[8] = 25.85e-6
    constants[9] = 2.098e-6
    constants[10] = 0.8e-3
    states[1] = 11.28
    constants[11] = 140
    states[2] = 0.0054828
    states[3] = 0.6095126
    states[4] = 0.60876276
    constants[12] = 0.035e-3
    constants[13] = 0.583
    constants[14] = 0.417
    constants[15] = 5.4
    states[5] = 138.7225
    states[6] = 0.002542
    states[7] = 0.8823
    states[8] = 0.42756
    constants[16] = 0.007e-3
    states[9] = 0.0033545
    states[10] = 0.266596
    constants[17] = 0.024e-3
    constants[18] = 0.00145e-3
    constants[19] = 0.2
    states[11] = 0.0026369
    constants[20] = 0.00008015e-3
    constants[21] = 0.000138e-3
    constants[22] = 0.95e-4
    constants[23] = 1.5
    constants[24] = 10
    constants[25] = 1.2
    constants[26] = 0.065
    constants[27] = 0.02
    constants[28] = 9.13e-4
    constants[29] = 50000
    states[12] = 0.00011423
    states[13] = 721.96e-3
    constants[30] = -2
    constants[31] = 7
    constants[32] = 2.35
    constants[33] = 1
    constants[34] = 650
    constants[35] = 2.43
    constants[36] = 0.05
    constants[37] = 0.012
    constants[38] = 41e-3
    constants[39] = 0.22e-3
    constants[40] = 0.0625
    constants[41] = 14
    constants[42] = 0.01
    constants[43] = 100
    states[14] = 0.98794
    states[15] = 0.00887
    states[16] = 0.003156
    constants[44] = 87.5
    constants[45] = 1380e-3
    constants[46] = 0.35
    constants[47] = 0.1
    constants[48] = 38.5e-3
    constants[49] = 0.45e-3
    constants[50] = 0.5e-3
    constants[51] = 0.0035e-3
    constants[52] = 0.5e-3
    constants[53] = 2.6875e-8
    constants[54] = 1.8951e-5
    constants[55] = 2.382e-3
    constants[56] = 50e-3
    states[17] = 0.020023
    constants[57] = 100
    constants[58] = 0.2
    constants[59] = 2
    constants[60] = 70e-3
    constants[61] = 8e-3
    constants[62] = 2e-3
    constants[63] = 1.75e-3
    constants[64] = 3
    constants[65] = 0.15
    constants[66] = 3
    constants[67] = 1.05e-3
    constants[68] = 0.85
    constants[69] = -4
    constants[70] = 4.9
    states[18] = 0.0661796
    constants[71] = 56.2
    constants[72] = 0.35
    states[19] = 0
    states[20] = 0
    states[21] = 0
    constants[73] = -29
    constants[74] = 138
    constants[75] = 129
    constants[76] = 0.03
    constants[77] = 0.13
    constants[78] = 0.625
    constants[79] = 1.33000*constants[10]
    constants[80] = 0.464700*constants[12]
    constants[81] = 2100.00
    constants[82] = 1.00000-constants[19]
    constants[83] = (exp(constants[11]/67.3000)-1.00000)/7.00000
    constants[84] = 1.17000*constants[33]
    constants[85] = ((constants[63]*(power(constants[68], constants[64])))/(power(constants[68], constants[64])+power(constants[65], constants[64])))*(1.00000-(constants[64]*(power(constants[65], constants[64])))/(power(constants[68], constants[64])+power(constants[65], constants[64])))
    constants[86] = 0.00000
    constants[87] = constants[32]/constants[33]
    constants[88] = (constants[63]*(power(constants[68], constants[64]-1.00000))*constants[64]*(power(constants[65], constants[64])))/(power(power(constants[68], constants[64])+power(constants[65], constants[64]), 2.00000))
    constants[89] = constants[36]/constants[84]
    return (states, constants)

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