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 = 58
sizeStates = 12
sizeConstants = 60
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 (gas_constant_units)"
    legend_constants[1] = "T in component membrane (kelvin)"
    legend_constants[2] = "F in component membrane (faradays_constant_units)"
    legend_algebraic[53] = "dV_dt in component membrane (mV_per_ms)"
    legend_constants[3] = "Cm in component membrane (uF_per_mm2)"
    legend_algebraic[3] = "I_st in component membrane (uA_per_mm2)"
    legend_algebraic[14] = "i_Na in component fast_sodium_current (uA_per_mm2)"
    legend_algebraic[26] = "i_Ca_L in component L_type_Ca_channel (uA_per_mm2)"
    legend_algebraic[29] = "i_K in component time_dependent_potassium_current (uA_per_mm2)"
    legend_algebraic[52] = "i_NaCa in component Na_Ca_exchanger (uA_per_mm2)"
    legend_algebraic[34] = "i_K1 in component time_independent_potassium_current (uA_per_mm2)"
    legend_algebraic[37] = "i_Kp in component plateau_potassium_current (uA_per_mm2)"
    legend_algebraic[38] = "i_p_Ca in component sarcolemmal_calcium_pump (uA_per_mm2)"
    legend_algebraic[40] = "i_Na_b in component sodium_background_current (uA_per_mm2)"
    legend_algebraic[42] = "i_Ca_b in component calcium_background_current (uA_per_mm2)"
    legend_algebraic[44] = "i_NaK in component sodium_potassium_pump (uA_per_mm2)"
    legend_algebraic[51] = "i_ns_Ca in component non_specific_calcium_activated_current (uA_per_mm2)"
    legend_constants[4] = "stimPeriod in component membrane (dimensionless)"
    legend_constants[5] = "stimDuration in component membrane (dimensionless)"
    legend_constants[6] = "stimCurrent in component membrane (dimensionless)"
    legend_algebraic[10] = "E_Na in component fast_sodium_current (mV)"
    legend_constants[7] = "g_Na in component fast_sodium_current (mS_per_mm2)"
    legend_states[1] = "Nai in component ionic_concentrations (mM)"
    legend_constants[8] = "Nao in component ionic_concentrations (mM)"
    legend_states[2] = "m in component fast_sodium_current_m_gate (dimensionless)"
    legend_states[3] = "h in component fast_sodium_current_h_gate (dimensionless)"
    legend_states[4] = "j in component fast_sodium_current_j_gate (dimensionless)"
    legend_algebraic[0] = "alpha_m in component fast_sodium_current_m_gate (per_ms)"
    legend_algebraic[7] = "beta_m in component fast_sodium_current_m_gate (per_ms)"
    legend_algebraic[1] = "alpha_h in component fast_sodium_current_h_gate (per_ms)"
    legend_algebraic[8] = "beta_h in component fast_sodium_current_h_gate (per_ms)"
    legend_algebraic[2] = "alpha_j in component fast_sodium_current_j_gate (per_ms)"
    legend_algebraic[9] = "beta_j in component fast_sodium_current_j_gate (per_ms)"
    legend_algebraic[23] = "i_CaCa in component L_type_Ca_channel (uA_per_mm2)"
    legend_algebraic[25] = "i_CaK in component L_type_Ca_channel (uA_per_mm2)"
    legend_algebraic[24] = "i_CaNa in component L_type_Ca_channel (uA_per_mm2)"
    legend_constants[9] = "gamma_Nai in component L_type_Ca_channel (dimensionless)"
    legend_constants[10] = "gamma_Nao in component L_type_Ca_channel (dimensionless)"
    legend_constants[11] = "gamma_Ki in component L_type_Ca_channel (dimensionless)"
    legend_constants[12] = "gamma_Ko in component L_type_Ca_channel (dimensionless)"
    legend_algebraic[17] = "I_CaCa in component L_type_Ca_channel (uA_per_mm2)"
    legend_algebraic[21] = "I_CaK in component L_type_Ca_channel (uA_per_mm2)"
    legend_algebraic[20] = "I_CaNa in component L_type_Ca_channel (uA_per_mm2)"
    legend_constants[13] = "P_Ca in component L_type_Ca_channel (mm_per_ms)"
    legend_constants[14] = "P_Na in component L_type_Ca_channel (mm_per_ms)"
    legend_constants[15] = "P_K in component L_type_Ca_channel (mm_per_ms)"
    legend_constants[16] = "gamma_Cai in component L_type_Ca_channel (dimensionless)"
    legend_constants[17] = "gamma_Cao in component L_type_Ca_channel (dimensionless)"
    legend_states[5] = "Cai in component ionic_concentrations (mM)"
    legend_constants[18] = "Cao in component ionic_concentrations (mM)"
    legend_constants[19] = "Ko in component ionic_concentrations (mM)"
    legend_states[6] = "Ki in component ionic_concentrations (mM)"
    legend_states[7] = "d in component L_type_Ca_channel_d_gate (dimensionless)"
    legend_states[8] = "f in component L_type_Ca_channel_f_gate (dimensionless)"
    legend_algebraic[22] = "f_Ca in component L_type_Ca_channel_f_Ca_gate (dimensionless)"
    legend_algebraic[15] = "alpha_d in component L_type_Ca_channel_d_gate (per_ms)"
    legend_algebraic[18] = "beta_d in component L_type_Ca_channel_d_gate (per_ms)"
    legend_algebraic[4] = "d_infinity in component L_type_Ca_channel_d_gate (dimensionless)"
    legend_algebraic[11] = "tau_d in component L_type_Ca_channel_d_gate (ms)"
    legend_algebraic[16] = "alpha_f in component L_type_Ca_channel_f_gate (per_ms)"
    legend_algebraic[19] = "beta_f in component L_type_Ca_channel_f_gate (per_ms)"
    legend_algebraic[5] = "f_infinity in component L_type_Ca_channel_f_gate (dimensionless)"
    legend_algebraic[12] = "tau_f in component L_type_Ca_channel_f_gate (ms)"
    legend_constants[20] = "Km_Ca in component L_type_Ca_channel_f_Ca_gate (mM)"
    legend_constants[21] = "g_K_max in component time_dependent_potassium_current (mS_per_mm2)"
    legend_constants[54] = "g_K in component time_dependent_potassium_current (mS_per_mm2)"
    legend_algebraic[27] = "E_K in component time_dependent_potassium_current (mV)"
    legend_constants[22] = "PR_NaK in component time_dependent_potassium_current (dimensionless)"
    legend_states[9] = "X in component time_dependent_potassium_current_X_gate (dimensionless)"
    legend_algebraic[28] = "Xi in component time_dependent_potassium_current_Xi_gate (dimensionless)"
    legend_algebraic[6] = "alpha_X in component time_dependent_potassium_current_X_gate (per_ms)"
    legend_algebraic[13] = "beta_X in component time_dependent_potassium_current_X_gate (per_ms)"
    legend_algebraic[30] = "E_K1 in component time_independent_potassium_current (mV)"
    legend_constants[23] = "g_K1_max in component time_independent_potassium_current (mS_per_mm2)"
    legend_constants[55] = "g_K1 in component time_independent_potassium_current (mS_per_mm2)"
    legend_algebraic[33] = "K1_infinity in component time_independent_potassium_current_K1_gate (dimensionless)"
    legend_algebraic[31] = "alpha_K1 in component time_independent_potassium_current_K1_gate (per_ms)"
    legend_algebraic[32] = "beta_K1 in component time_independent_potassium_current_K1_gate (per_ms)"
    legend_algebraic[35] = "E_Kp in component plateau_potassium_current (mV)"
    legend_constants[24] = "g_Kp in component plateau_potassium_current (mS_per_mm2)"
    legend_algebraic[36] = "Kp in component plateau_potassium_current (dimensionless)"
    legend_constants[25] = "K_mpCa in component sarcolemmal_calcium_pump (mM)"
    legend_constants[26] = "I_pCa in component sarcolemmal_calcium_pump (uA_per_mm2)"
    legend_constants[27] = "g_Nab in component sodium_background_current (mS_per_mm2)"
    legend_algebraic[39] = "E_NaN in component sodium_background_current (mV)"
    legend_constants[28] = "g_Cab in component calcium_background_current (mS_per_mm2)"
    legend_algebraic[41] = "E_CaN in component calcium_background_current (mV)"
    legend_constants[29] = "I_NaK in component sodium_potassium_pump (uA_per_mm2)"
    legend_algebraic[43] = "f_NaK in component sodium_potassium_pump (dimensionless)"
    legend_constants[30] = "K_mNai in component sodium_potassium_pump (mM)"
    legend_constants[31] = "K_mKo in component sodium_potassium_pump (mM)"
    legend_constants[56] = "sigma in component sodium_potassium_pump (dimensionless)"
    legend_algebraic[48] = "i_ns_Na in component non_specific_calcium_activated_current (uA_per_mm2)"
    legend_algebraic[50] = "i_ns_K in component non_specific_calcium_activated_current (uA_per_mm2)"
    legend_constants[32] = "P_ns_Ca in component non_specific_calcium_activated_current (mm_per_ms)"
    legend_algebraic[47] = "I_ns_Na in component non_specific_calcium_activated_current (uA_per_mm2)"
    legend_algebraic[49] = "I_ns_K in component non_specific_calcium_activated_current (uA_per_mm2)"
    legend_constants[33] = "K_m_ns_Ca in component non_specific_calcium_activated_current (mM)"
    legend_algebraic[46] = "Vns in component non_specific_calcium_activated_current (mV)"
    legend_algebraic[45] = "EnsCa in component non_specific_calcium_activated_current (mV)"
    legend_constants[34] = "K_NaCa in component Na_Ca_exchanger (uA_per_mm2)"
    legend_constants[35] = "K_mNa in component Na_Ca_exchanger (mM)"
    legend_constants[36] = "K_mCa in component Na_Ca_exchanger (mM)"
    legend_constants[37] = "K_sat in component Na_Ca_exchanger (dimensionless)"
    legend_constants[38] = "eta in component Na_Ca_exchanger (dimensionless)"
    legend_algebraic[54] = "i_rel in component calcium_fluxes_in_the_SR (mM_per_ms)"
    legend_algebraic[55] = "i_up in component calcium_fluxes_in_the_SR (mM_per_ms)"
    legend_algebraic[56] = "i_leak in component calcium_fluxes_in_the_SR (mM_per_ms)"
    legend_algebraic[57] = "i_tr in component calcium_fluxes_in_the_SR (mM_per_ms)"
    legend_constants[59] = "G_rel in component calcium_fluxes_in_the_SR (per_ms)"
    legend_constants[57] = "G_rel_peak in component calcium_fluxes_in_the_SR (per_ms)"
    legend_constants[39] = "G_rel_max in component calcium_fluxes_in_the_SR (per_ms)"
    legend_constants[40] = "tau_on in component calcium_fluxes_in_the_SR (ms)"
    legend_constants[41] = "tau_off in component calcium_fluxes_in_the_SR (ms)"
    legend_constants[42] = "t_CICR in component calcium_fluxes_in_the_SR (ms)"
    legend_constants[43] = "tau_tr in component calcium_fluxes_in_the_SR (ms)"
    legend_constants[44] = "K_mrel in component calcium_fluxes_in_the_SR (mM)"
    legend_constants[45] = "K_mup in component calcium_fluxes_in_the_SR (mM)"
    legend_constants[58] = "K_leak in component calcium_fluxes_in_the_SR (per_ms)"
    legend_constants[46] = "I_up in component calcium_fluxes_in_the_SR (mM_per_ms)"
    legend_constants[47] = "Ca_NSR_max in component calcium_fluxes_in_the_SR (mM)"
    legend_constants[48] = "delta_Ca_i2 in component calcium_fluxes_in_the_SR (mM)"
    legend_constants[49] = "delta_Ca_ith in component calcium_fluxes_in_the_SR (mM)"
    legend_states[10] = "Ca_JSR in component ionic_concentrations (mM)"
    legend_states[11] = "Ca_NSR in component ionic_concentrations (mM)"
    legend_constants[50] = "Am in component ionic_concentrations (per_mm)"
    legend_constants[51] = "V_myo in component ionic_concentrations (dimensionless)"
    legend_constants[52] = "V_JSR in component ionic_concentrations (dimensionless)"
    legend_constants[53] = "V_NSR in component ionic_concentrations (dimensionless)"
    legend_rates[0] = "d/dt V in component membrane (mV)"
    legend_rates[2] = "d/dt m in component fast_sodium_current_m_gate (dimensionless)"
    legend_rates[3] = "d/dt h in component fast_sodium_current_h_gate (dimensionless)"
    legend_rates[4] = "d/dt j in component fast_sodium_current_j_gate (dimensionless)"
    legend_rates[7] = "d/dt d in component L_type_Ca_channel_d_gate (dimensionless)"
    legend_rates[8] = "d/dt f in component L_type_Ca_channel_f_gate (dimensionless)"
    legend_rates[9] = "d/dt X in component time_dependent_potassium_current_X_gate (dimensionless)"
    legend_rates[1] = "d/dt Nai in component ionic_concentrations (mM)"
    legend_rates[5] = "d/dt Cai in component ionic_concentrations (mM)"
    legend_rates[6] = "d/dt Ki in component ionic_concentrations (mM)"
    legend_rates[10] = "d/dt Ca_JSR in component ionic_concentrations (mM)"
    legend_rates[11] = "d/dt Ca_NSR in component ionic_concentrations (mM)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    states[0] = -84.624
    constants[0] = 8.3145e3
    constants[1] = 310.0
    constants[2] = 96845.0
    constants[3] = 0.01
    constants[4] = 1e3
    constants[5] = 0.5
    constants[6] = 0.5
    constants[7] = 0.16
    states[1] = 10.0
    constants[8] = 140.0
    states[2] = 0.0
    states[3] = 1.0
    states[4] = 1.0
    constants[9] = 0.75
    constants[10] = 0.75
    constants[11] = 0.75
    constants[12] = 0.75
    constants[13] = 5.4e-6
    constants[14] = 6.75e-9
    constants[15] = 1.93e-9
    constants[16] = 1.0
    constants[17] = 0.34
    states[5] = 0.12e-3
    constants[18] = 1.8
    constants[19] = 5.4
    states[6] = 145.0
    states[7] = 0.0
    states[8] = 1.0
    constants[20] = 0.6e-3
    constants[21] = 2.82e-3
    constants[22] = 0.01833
    states[9] = 0.0
    constants[23] = 7.5e-3
    constants[24] = 1.83e-4
    constants[25] = 0.5e-3
    constants[26] = 1.15e-2
    constants[27] = 1.41e-5
    constants[28] = 3.016e-5
    constants[29] = 1.5e-2
    constants[30] = 10.0
    constants[31] = 1.5
    constants[32] = 1.75e-9
    constants[33] = 1.2e-3
    constants[34] = 20.0
    constants[35] = 87.5
    constants[36] = 1.38
    constants[37] = 0.1
    constants[38] = 0.35
    constants[39] = 60.0
    constants[40] = 2.0
    constants[41] = 2.0
    constants[42] = 0.0
    constants[43] = 180.0
    constants[44] = 0.8e-3
    constants[45] = 0.92e-3
    constants[46] = 0.005
    constants[47] = 15.0
    constants[48] = 0.0
    constants[49] = 0.18e-3
    states[10] = 1.8
    states[11] = 1.8
    constants[50] = 200
    constants[51] = 0.68
    constants[52] = 0.0048
    constants[53] = 0.0552
    constants[54] = constants[21]*(power(constants[19]/5.40000, 1.0/2))
    constants[55] = constants[23]*(power(constants[19]/5.40000, 1.0/2))
    constants[56] = (1.00000/7.00000)*(exp(constants[8]/67.3000)-1.00000)
    constants[57] = custom_piecewise([less(constants[48] , constants[49]), 0.00000 , True, constants[39]])
    constants[58] = constants[46]/constants[47]
    constants[59] = constants[57]*((constants[48]-constants[49])/((constants[44]+constants[48])-constants[49]))*(1.00000-exp(-(constants[42]/constants[40])))*exp(-(constants[42]/constants[41]))
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    algebraic[0] = (0.320000*(states[0]+47.1300))/(1.00000-exp(-0.100000*(states[0]+47.1300)))
    algebraic[7] = 0.0800000*exp(-states[0]/11.0000)
    rates[2] = algebraic[0]*(1.00000-states[2])-algebraic[7]*states[2]
    algebraic[1] = custom_piecewise([less(states[0] , -40.0000), 0.135000*exp((80.0000+states[0])/-6.80000) , True, 0.00000])
    algebraic[8] = custom_piecewise([less(states[0] , -40.0000), 3.56000*exp(0.0790000*states[0])+310000.*exp(0.350000*states[0]) , True, 1.00000/(0.130000*(1.00000+exp((states[0]+10.6600)/-11.1000)))])
    rates[3] = algebraic[1]*(1.00000-states[3])-algebraic[8]*states[3]
    algebraic[2] = custom_piecewise([less(states[0] , -40.0000), (-127140.*exp(0.244400*states[0])-3.47400e-05*exp(-0.0439100*states[0]))*((states[0]+37.7800)/(1.00000+exp(0.311000*(states[0]+79.2300)))) , True, 0.00000])
    algebraic[9] = custom_piecewise([less(states[0] , -40.0000), (0.121200*exp(-0.0105200*states[0]))/(1.00000+exp(-0.137800*(states[0]+40.1400))) , True, (0.300000*exp(-2.53500e-07*states[0]))/(1.00000+exp(-0.100000*(states[0]+32.0000)))])
    rates[4] = algebraic[2]*(1.00000-states[4])-algebraic[9]*states[4]
    algebraic[6] = (7.19000e-05*(states[0]+30.0000))/(1.00000-exp(-0.148000*(states[0]+30.0000)))
    algebraic[13] = (0.000131000*(states[0]+30.0000))/(-1.00000+exp(0.0687000*(states[0]+30.0000)))
    rates[9] = algebraic[6]*(1.00000-states[9])-algebraic[13]*states[9]
    algebraic[4] = 1.00000/(1.00000+exp(-((states[0]+10.0000)/6.24000)))
    algebraic[11] = algebraic[4]*((1.00000-exp(-((states[0]+10.0000)/6.24000)))/(0.0350000*(states[0]+10.0000)))
    algebraic[15] = algebraic[4]/algebraic[11]
    algebraic[18] = (1.00000-algebraic[4])/algebraic[11]
    rates[7] = algebraic[15]*(1.00000-states[7])-algebraic[18]*states[7]
    algebraic[5] = 1.00000/(1.00000+exp((states[0]+35.0600)/8.60000))+0.600000/(1.00000+exp((50.0000-states[0])/20.0000))
    algebraic[12] = 1.00000/(0.0197000*exp(-(power(0.0337000*(states[0]+10.0000), 2.00000)))+0.0200000)
    algebraic[16] = algebraic[5]/algebraic[12]
    algebraic[19] = (1.00000-algebraic[5])/algebraic[12]
    rates[8] = algebraic[16]*(1.00000-states[8])-algebraic[19]*states[8]
    algebraic[27] = ((constants[0]*constants[1])/constants[2])*log((constants[19]+constants[22]*constants[8])/(states[6]+constants[22]*states[1]))
    algebraic[28] = 1.00000/(1.00000+exp((states[0]-56.2600)/32.1000))
    algebraic[29] = constants[54]*(power(states[9], 2.00000))*algebraic[28]*(states[0]-algebraic[27])
    algebraic[30] = ((constants[0]*constants[1])/constants[2])*log(constants[19]/states[6])
    algebraic[31] = 1.02000/(1.00000+exp(0.238500*((states[0]-algebraic[30])-59.2150)))
    algebraic[32] = (0.491240*exp(0.0803200*((states[0]+5.47600)-algebraic[30]))+exp(0.0617500*(states[0]-(algebraic[30]+594.310))))/(1.00000+exp(-0.514300*((states[0]-algebraic[30])+4.75300)))
    algebraic[33] = algebraic[31]/(algebraic[31]+algebraic[32])
    algebraic[34] = constants[55]*algebraic[33]*(states[0]-algebraic[30])
    algebraic[35] = algebraic[30]
    algebraic[36] = 1.00000/(1.00000+exp((7.48800-states[0])/5.98000))
    algebraic[37] = constants[24]*algebraic[36]*(states[0]-algebraic[35])
    algebraic[43] = 1.00000/((1.00000+0.124500*exp(-0.100000*((states[0]*constants[2])/(constants[0]*constants[1]))))+0.0365000*constants[56]*exp(-((states[0]*constants[2])/(constants[0]*constants[1]))))
    algebraic[44] = constants[29]*algebraic[43]*(1.00000/(1.00000+power(constants[30]/states[1], 1.50000)))*(constants[19]/(constants[19]+constants[31]))
    algebraic[21] = constants[15]*(power(1.00000, 2.00000))*((states[0]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*((constants[11]*states[6]*exp((1.00000*states[0]*constants[2])/(constants[0]*constants[1]))-constants[12]*constants[19])/(exp((1.00000*states[0]*constants[2])/(constants[0]*constants[1]))-1.00000))
    algebraic[22] = 1.00000/(1.00000+power(states[5]/constants[20], 2.00000))
    algebraic[25] = states[7]*states[8]*algebraic[22]*algebraic[21]
    algebraic[45] = ((constants[0]*constants[1])/constants[2])*log((constants[19]+constants[8])/(states[6]+states[1]))
    algebraic[46] = states[0]-algebraic[45]
    algebraic[49] = constants[32]*(power(1.00000, 2.00000))*((algebraic[46]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*((constants[11]*states[6]*exp((1.00000*algebraic[46]*constants[2])/(constants[0]*constants[1]))-constants[12]*constants[19])/(exp((1.00000*algebraic[46]*constants[2])/(constants[0]*constants[1]))-1.00000))
    algebraic[50] = algebraic[49]*(1.00000/(1.00000+power(constants[33]/states[5], 3.00000)))
    rates[6] = -(algebraic[25]+algebraic[29]+algebraic[34]+algebraic[37]+algebraic[50]+-(algebraic[44]*2.00000))*(constants[50]/(constants[51]*constants[2]))
    algebraic[10] = ((constants[0]*constants[1])/constants[2])*log(constants[8]/states[1])
    algebraic[14] = constants[7]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[10])
    algebraic[52] = constants[34]*(1.00000/(power(constants[35], 3.00000)+power(constants[8], 3.00000)))*(1.00000/(constants[36]+constants[18]))*(1.00000/(1.00000+constants[37]*exp((constants[38]-1.00000)*states[0]*(constants[2]/(constants[0]*constants[1])))))*(exp(constants[38]*states[0]*(constants[2]/(constants[0]*constants[1])))*(power(states[1], 3.00000))*constants[18]-exp((constants[38]-1.00000)*states[0]*(constants[2]/(constants[0]*constants[1])))*(power(constants[8], 3.00000))*states[5])
    algebraic[39] = algebraic[10]
    algebraic[40] = constants[27]*(states[0]-algebraic[39])
    algebraic[20] = constants[14]*(power(1.00000, 2.00000))*((states[0]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*((constants[9]*states[1]*exp((1.00000*states[0]*constants[2])/(constants[0]*constants[1]))-constants[10]*constants[8])/(exp((1.00000*states[0]*constants[2])/(constants[0]*constants[1]))-1.00000))
    algebraic[24] = states[7]*states[8]*algebraic[22]*algebraic[20]
    algebraic[47] = constants[32]*(power(1.00000, 2.00000))*((algebraic[46]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*((constants[9]*states[1]*exp((1.00000*algebraic[46]*constants[2])/(constants[0]*constants[1]))-constants[10]*constants[8])/(exp((1.00000*algebraic[46]*constants[2])/(constants[0]*constants[1]))-1.00000))
    algebraic[48] = algebraic[47]*(1.00000/(1.00000+power(constants[33]/states[5], 3.00000)))
    rates[1] = -(algebraic[14]+algebraic[24]+algebraic[40]+algebraic[48]+algebraic[52]*3.00000+algebraic[44]*3.00000)*(constants[50]/(constants[51]*constants[2]))
    algebraic[3] = custom_piecewise([less( voi % constants[4] , constants[5]), constants[6] , True, 0.00000])
    algebraic[17] = constants[13]*(power(2.00000, 2.00000))*((states[0]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*((constants[16]*states[5]*exp((2.00000*states[0]*constants[2])/(constants[0]*constants[1]))-constants[17]*constants[18])/(exp((2.00000*states[0]*constants[2])/(constants[0]*constants[1]))-1.00000))
    algebraic[23] = states[7]*states[8]*algebraic[22]*algebraic[17]
    algebraic[26] = algebraic[23]+algebraic[25]+algebraic[24]
    algebraic[38] = constants[26]*(states[5]/(constants[25]+states[5]))
    algebraic[41] = ((constants[0]*constants[1])/(2.00000*constants[2]))*log(constants[18]/states[5])
    algebraic[42] = constants[28]*(states[0]-algebraic[41])
    algebraic[51] = algebraic[48]+algebraic[50]
    algebraic[53] = (algebraic[3]-(algebraic[14]+algebraic[26]+algebraic[29]+algebraic[34]+algebraic[37]+algebraic[52]+algebraic[38]+algebraic[40]+algebraic[42]+algebraic[44]+algebraic[51]))/constants[3]
    rates[0] = algebraic[53]
    algebraic[54] = constants[59]*(states[10]-states[5])
    algebraic[55] = constants[46]*(states[5]/(states[5]+constants[45]))
    algebraic[56] = constants[58]*states[11]
    rates[5] = -((algebraic[23]+algebraic[38]+algebraic[42])-algebraic[52])*(constants[50]/(2.00000*constants[51]*constants[2]))+algebraic[54]*(constants[52]/constants[51])+(algebraic[56]-algebraic[55])*(constants[53]/constants[51])
    algebraic[57] = (states[11]-states[10])/constants[43]
    rates[10] = -(algebraic[54]-algebraic[57]*(constants[53]/constants[52]))
    rates[11] = -((algebraic[56]+algebraic[57])-algebraic[55])
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[0] = (0.320000*(states[0]+47.1300))/(1.00000-exp(-0.100000*(states[0]+47.1300)))
    algebraic[7] = 0.0800000*exp(-states[0]/11.0000)
    algebraic[1] = custom_piecewise([less(states[0] , -40.0000), 0.135000*exp((80.0000+states[0])/-6.80000) , True, 0.00000])
    algebraic[8] = custom_piecewise([less(states[0] , -40.0000), 3.56000*exp(0.0790000*states[0])+310000.*exp(0.350000*states[0]) , True, 1.00000/(0.130000*(1.00000+exp((states[0]+10.6600)/-11.1000)))])
    algebraic[2] = custom_piecewise([less(states[0] , -40.0000), (-127140.*exp(0.244400*states[0])-3.47400e-05*exp(-0.0439100*states[0]))*((states[0]+37.7800)/(1.00000+exp(0.311000*(states[0]+79.2300)))) , True, 0.00000])
    algebraic[9] = custom_piecewise([less(states[0] , -40.0000), (0.121200*exp(-0.0105200*states[0]))/(1.00000+exp(-0.137800*(states[0]+40.1400))) , True, (0.300000*exp(-2.53500e-07*states[0]))/(1.00000+exp(-0.100000*(states[0]+32.0000)))])
    algebraic[6] = (7.19000e-05*(states[0]+30.0000))/(1.00000-exp(-0.148000*(states[0]+30.0000)))
    algebraic[13] = (0.000131000*(states[0]+30.0000))/(-1.00000+exp(0.0687000*(states[0]+30.0000)))
    algebraic[4] = 1.00000/(1.00000+exp(-((states[0]+10.0000)/6.24000)))
    algebraic[11] = algebraic[4]*((1.00000-exp(-((states[0]+10.0000)/6.24000)))/(0.0350000*(states[0]+10.0000)))
    algebraic[15] = algebraic[4]/algebraic[11]
    algebraic[18] = (1.00000-algebraic[4])/algebraic[11]
    algebraic[5] = 1.00000/(1.00000+exp((states[0]+35.0600)/8.60000))+0.600000/(1.00000+exp((50.0000-states[0])/20.0000))
    algebraic[12] = 1.00000/(0.0197000*exp(-(power(0.0337000*(states[0]+10.0000), 2.00000)))+0.0200000)
    algebraic[16] = algebraic[5]/algebraic[12]
    algebraic[19] = (1.00000-algebraic[5])/algebraic[12]
    algebraic[27] = ((constants[0]*constants[1])/constants[2])*log((constants[19]+constants[22]*constants[8])/(states[6]+constants[22]*states[1]))
    algebraic[28] = 1.00000/(1.00000+exp((states[0]-56.2600)/32.1000))
    algebraic[29] = constants[54]*(power(states[9], 2.00000))*algebraic[28]*(states[0]-algebraic[27])
    algebraic[30] = ((constants[0]*constants[1])/constants[2])*log(constants[19]/states[6])
    algebraic[31] = 1.02000/(1.00000+exp(0.238500*((states[0]-algebraic[30])-59.2150)))
    algebraic[32] = (0.491240*exp(0.0803200*((states[0]+5.47600)-algebraic[30]))+exp(0.0617500*(states[0]-(algebraic[30]+594.310))))/(1.00000+exp(-0.514300*((states[0]-algebraic[30])+4.75300)))
    algebraic[33] = algebraic[31]/(algebraic[31]+algebraic[32])
    algebraic[34] = constants[55]*algebraic[33]*(states[0]-algebraic[30])
    algebraic[35] = algebraic[30]
    algebraic[36] = 1.00000/(1.00000+exp((7.48800-states[0])/5.98000))
    algebraic[37] = constants[24]*algebraic[36]*(states[0]-algebraic[35])
    algebraic[43] = 1.00000/((1.00000+0.124500*exp(-0.100000*((states[0]*constants[2])/(constants[0]*constants[1]))))+0.0365000*constants[56]*exp(-((states[0]*constants[2])/(constants[0]*constants[1]))))
    algebraic[44] = constants[29]*algebraic[43]*(1.00000/(1.00000+power(constants[30]/states[1], 1.50000)))*(constants[19]/(constants[19]+constants[31]))
    algebraic[21] = constants[15]*(power(1.00000, 2.00000))*((states[0]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*((constants[11]*states[6]*exp((1.00000*states[0]*constants[2])/(constants[0]*constants[1]))-constants[12]*constants[19])/(exp((1.00000*states[0]*constants[2])/(constants[0]*constants[1]))-1.00000))
    algebraic[22] = 1.00000/(1.00000+power(states[5]/constants[20], 2.00000))
    algebraic[25] = states[7]*states[8]*algebraic[22]*algebraic[21]
    algebraic[45] = ((constants[0]*constants[1])/constants[2])*log((constants[19]+constants[8])/(states[6]+states[1]))
    algebraic[46] = states[0]-algebraic[45]
    algebraic[49] = constants[32]*(power(1.00000, 2.00000))*((algebraic[46]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*((constants[11]*states[6]*exp((1.00000*algebraic[46]*constants[2])/(constants[0]*constants[1]))-constants[12]*constants[19])/(exp((1.00000*algebraic[46]*constants[2])/(constants[0]*constants[1]))-1.00000))
    algebraic[50] = algebraic[49]*(1.00000/(1.00000+power(constants[33]/states[5], 3.00000)))
    algebraic[10] = ((constants[0]*constants[1])/constants[2])*log(constants[8]/states[1])
    algebraic[14] = constants[7]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[10])
    algebraic[52] = constants[34]*(1.00000/(power(constants[35], 3.00000)+power(constants[8], 3.00000)))*(1.00000/(constants[36]+constants[18]))*(1.00000/(1.00000+constants[37]*exp((constants[38]-1.00000)*states[0]*(constants[2]/(constants[0]*constants[1])))))*(exp(constants[38]*states[0]*(constants[2]/(constants[0]*constants[1])))*(power(states[1], 3.00000))*constants[18]-exp((constants[38]-1.00000)*states[0]*(constants[2]/(constants[0]*constants[1])))*(power(constants[8], 3.00000))*states[5])
    algebraic[39] = algebraic[10]
    algebraic[40] = constants[27]*(states[0]-algebraic[39])
    algebraic[20] = constants[14]*(power(1.00000, 2.00000))*((states[0]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*((constants[9]*states[1]*exp((1.00000*states[0]*constants[2])/(constants[0]*constants[1]))-constants[10]*constants[8])/(exp((1.00000*states[0]*constants[2])/(constants[0]*constants[1]))-1.00000))
    algebraic[24] = states[7]*states[8]*algebraic[22]*algebraic[20]
    algebraic[47] = constants[32]*(power(1.00000, 2.00000))*((algebraic[46]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*((constants[9]*states[1]*exp((1.00000*algebraic[46]*constants[2])/(constants[0]*constants[1]))-constants[10]*constants[8])/(exp((1.00000*algebraic[46]*constants[2])/(constants[0]*constants[1]))-1.00000))
    algebraic[48] = algebraic[47]*(1.00000/(1.00000+power(constants[33]/states[5], 3.00000)))
    algebraic[3] = custom_piecewise([less( voi % constants[4] , constants[5]), constants[6] , True, 0.00000])
    algebraic[17] = constants[13]*(power(2.00000, 2.00000))*((states[0]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*((constants[16]*states[5]*exp((2.00000*states[0]*constants[2])/(constants[0]*constants[1]))-constants[17]*constants[18])/(exp((2.00000*states[0]*constants[2])/(constants[0]*constants[1]))-1.00000))
    algebraic[23] = states[7]*states[8]*algebraic[22]*algebraic[17]
    algebraic[26] = algebraic[23]+algebraic[25]+algebraic[24]
    algebraic[38] = constants[26]*(states[5]/(constants[25]+states[5]))
    algebraic[41] = ((constants[0]*constants[1])/(2.00000*constants[2]))*log(constants[18]/states[5])
    algebraic[42] = constants[28]*(states[0]-algebraic[41])
    algebraic[51] = algebraic[48]+algebraic[50]
    algebraic[53] = (algebraic[3]-(algebraic[14]+algebraic[26]+algebraic[29]+algebraic[34]+algebraic[37]+algebraic[52]+algebraic[38]+algebraic[40]+algebraic[42]+algebraic[44]+algebraic[51]))/constants[3]
    algebraic[54] = constants[59]*(states[10]-states[5])
    algebraic[55] = constants[46]*(states[5]/(states[5]+constants[45]))
    algebraic[56] = constants[58]*states[11]
    algebraic[57] = (states[11]-states[10])/constants[43]
    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)