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 = 81
sizeStates = 20
sizeConstants = 160
from math import *
from numpy import *

def createLegends():
    legend_states = [""] * sizeStates
    legend_rates = [""] * sizeStates
    legend_algebraic = [""] * sizeAlgebraic
    legend_voi = ""
    legend_constants = [""] * sizeConstants
    legend_algebraic[75] = "sum_g_syn_e_s in component synaptic_coupling (nanoS)"
    legend_constants[0] = "g_syn_e_1_2 in component synaptic_coupling (nanoS)"
    legend_constants[1] = "g_syn_e_1_3 in component synaptic_coupling (nanoS)"
    legend_constants[2] = "g_syn_e_1_4 in component synaptic_coupling (nanoS)"
    legend_constants[3] = "g_syn_e_1_5 in component synaptic_coupling (nanoS)"
    legend_constants[4] = "g_syn_e_2_1 in component synaptic_coupling (nanoS)"
    legend_constants[5] = "g_syn_e_2_3 in component synaptic_coupling (nanoS)"
    legend_constants[6] = "g_syn_e_2_4 in component synaptic_coupling (nanoS)"
    legend_constants[7] = "g_syn_e_2_5 in component synaptic_coupling (nanoS)"
    legend_constants[8] = "g_syn_e_3_1 in component synaptic_coupling (nanoS)"
    legend_constants[9] = "g_syn_e_3_2 in component synaptic_coupling (nanoS)"
    legend_constants[10] = "g_syn_e_3_4 in component synaptic_coupling (nanoS)"
    legend_constants[11] = "g_syn_e_3_5 in component synaptic_coupling (nanoS)"
    legend_constants[12] = "g_syn_e_4_1 in component synaptic_coupling (nanoS)"
    legend_constants[13] = "g_syn_e_4_2 in component synaptic_coupling (nanoS)"
    legend_constants[14] = "g_syn_e_4_3 in component synaptic_coupling (nanoS)"
    legend_constants[15] = "g_syn_e_4_5 in component synaptic_coupling (nanoS)"
    legend_constants[16] = "g_syn_e_5_1 in component synaptic_coupling (nanoS)"
    legend_constants[17] = "g_syn_e_5_2 in component synaptic_coupling (nanoS)"
    legend_constants[18] = "g_syn_e_5_3 in component synaptic_coupling (nanoS)"
    legend_constants[19] = "g_syn_e_5_4 in component synaptic_coupling (nanoS)"
    legend_algebraic[38] = "s in component synaptic_input (dimensionless)"
    legend_algebraic[47] = "s in component synaptic_input (dimensionless)"
    legend_algebraic[56] = "s in component synaptic_input (dimensionless)"
    legend_algebraic[65] = "s in component synaptic_input (dimensionless)"
    legend_algebraic[74] = "s in component synaptic_input (dimensionless)"
    legend_voi = "time in component environment (millisecond)"
    legend_states[0] = "V in component membrane (millivolt)"
    legend_constants[20] = "C in component membrane (picoF)"
    legend_constants[21] = "i_app in component membrane (picoA)"
    legend_algebraic[34] = "i_NaP in component persistent_sodium_current (picoA)"
    legend_algebraic[16] = "i_Na in component fast_sodium_current (picoA)"
    legend_algebraic[32] = "i_K in component potassium_current (picoA)"
    legend_algebraic[35] = "i_L in component leakage_current (picoA)"
    legend_algebraic[36] = "i_tonic_e in component tonic_current (picoA)"
    legend_algebraic[76] = "i_syn_e in component synaptic_input (picoA)"
    legend_constants[22] = "E_Na in component fast_sodium_current (millivolt)"
    legend_constants[23] = "g_Na in component fast_sodium_current (nanoS)"
    legend_algebraic[0] = "m_infinity in component fast_sodium_current_m_gate (dimensionless)"
    legend_states[1] = "n in component fast_sodium_current_n_gate (dimensionless)"
    legend_constants[24] = "theta_m in component fast_sodium_current_m_gate (millivolt)"
    legend_constants[25] = "sigma_m in component fast_sodium_current_m_gate (millivolt)"
    legend_algebraic[1] = "n_infinity in component fast_sodium_current_n_gate (dimensionless)"
    legend_algebraic[17] = "tau_n in component fast_sodium_current_n_gate (millisecond)"
    legend_constants[26] = "tau_n_max in component fast_sodium_current_n_gate (millisecond)"
    legend_constants[27] = "theta_n in component fast_sodium_current_n_gate (millivolt)"
    legend_constants[28] = "sigma_n in component fast_sodium_current_n_gate (millivolt)"
    legend_constants[29] = "g_K in component potassium_current (nanoS)"
    legend_constants[30] = "E_K in component potassium_current (millivolt)"
    legend_states[2] = "n in component potassium_current_n_gate (dimensionless)"
    legend_algebraic[2] = "n_infinity in component potassium_current_n_gate (dimensionless)"
    legend_algebraic[18] = "tau_n in component potassium_current_n_gate (millisecond)"
    legend_constants[31] = "tau_n_max in component potassium_current_n_gate (millisecond)"
    legend_constants[32] = "theta_n in component potassium_current_n_gate (millivolt)"
    legend_constants[33] = "sigma_n in component potassium_current_n_gate (millivolt)"
    legend_constants[34] = "g_NaP in component persistent_sodium_current (nanoS)"
    legend_algebraic[33] = "m_infinity in component persistent_sodium_current_m_gate (dimensionless)"
    legend_states[3] = "h in component persistent_sodium_current_h_gate (dimensionless)"
    legend_constants[35] = "theta_m in component persistent_sodium_current_m_gate (millivolt)"
    legend_constants[36] = "sigma_m in component persistent_sodium_current_m_gate (millivolt)"
    legend_algebraic[3] = "h_infinity in component persistent_sodium_current_h_gate (dimensionless)"
    legend_algebraic[19] = "tau_h in component persistent_sodium_current_h_gate (millisecond)"
    legend_constants[37] = "tau_h_max in component persistent_sodium_current_h_gate (millisecond)"
    legend_constants[38] = "theta_h in component persistent_sodium_current_h_gate (millivolt)"
    legend_constants[39] = "sigma_h in component persistent_sodium_current_h_gate (millivolt)"
    legend_constants[40] = "g_L in component leakage_current (nanoS)"
    legend_constants[41] = "E_L in component leakage_current (millivolt)"
    legend_constants[42] = "E_syn_e in component tonic_current (millivolt)"
    legend_constants[43] = "g_tonic_e in component tonic_current (nanoS)"
    legend_algebraic[37] = "s_infinity in component synaptic_input (dimensionless)"
    legend_constants[44] = "kr in component synaptic_input (dimensionless)"
    legend_constants[45] = "tau_s in component synaptic_input (millisecond)"
    legend_constants[46] = "sigma_s in component synaptic_input (millivolt)"
    legend_constants[47] = "theta_s in component synaptic_input (millivolt)"
    legend_voi = "time in component environment (millisecond)"
    legend_states[4] = "V in component membrane (millivolt)"
    legend_constants[48] = "C in component membrane (picoF)"
    legend_constants[49] = "i_app in component membrane (picoA)"
    legend_algebraic[43] = "i_NaP in component persistent_sodium_current (picoA)"
    legend_algebraic[40] = "i_Na in component fast_sodium_current (picoA)"
    legend_algebraic[41] = "i_K in component potassium_current (picoA)"
    legend_algebraic[44] = "i_L in component leakage_current (picoA)"
    legend_algebraic[45] = "i_tonic_e in component tonic_current (picoA)"
    legend_algebraic[77] = "i_syn_e in component synaptic_input (picoA)"
    legend_constants[50] = "E_Na in component fast_sodium_current (millivolt)"
    legend_constants[51] = "g_Na in component fast_sodium_current (nanoS)"
    legend_algebraic[39] = "m_infinity in component fast_sodium_current_m_gate (dimensionless)"
    legend_states[5] = "n in component fast_sodium_current_n_gate (dimensionless)"
    legend_constants[52] = "theta_m in component fast_sodium_current_m_gate (millivolt)"
    legend_constants[53] = "sigma_m in component fast_sodium_current_m_gate (millivolt)"
    legend_algebraic[4] = "n_infinity in component fast_sodium_current_n_gate (dimensionless)"
    legend_algebraic[20] = "tau_n in component fast_sodium_current_n_gate (millisecond)"
    legend_constants[54] = "tau_n_max in component fast_sodium_current_n_gate (millisecond)"
    legend_constants[55] = "theta_n in component fast_sodium_current_n_gate (millivolt)"
    legend_constants[56] = "sigma_n in component fast_sodium_current_n_gate (millivolt)"
    legend_constants[57] = "g_K in component potassium_current (nanoS)"
    legend_constants[58] = "E_K in component potassium_current (millivolt)"
    legend_states[6] = "n in component potassium_current_n_gate (dimensionless)"
    legend_algebraic[5] = "n_infinity in component potassium_current_n_gate (dimensionless)"
    legend_algebraic[21] = "tau_n in component potassium_current_n_gate (millisecond)"
    legend_constants[59] = "tau_n_max in component potassium_current_n_gate (millisecond)"
    legend_constants[60] = "theta_n in component potassium_current_n_gate (millivolt)"
    legend_constants[61] = "sigma_n in component potassium_current_n_gate (millivolt)"
    legend_constants[62] = "g_NaP in component persistent_sodium_current (nanoS)"
    legend_algebraic[42] = "m_infinity in component persistent_sodium_current_m_gate (dimensionless)"
    legend_states[7] = "h in component persistent_sodium_current_h_gate (dimensionless)"
    legend_constants[63] = "theta_m in component persistent_sodium_current_m_gate (millivolt)"
    legend_constants[64] = "sigma_m in component persistent_sodium_current_m_gate (millivolt)"
    legend_algebraic[6] = "h_infinity in component persistent_sodium_current_h_gate (dimensionless)"
    legend_algebraic[22] = "tau_h in component persistent_sodium_current_h_gate (millisecond)"
    legend_constants[65] = "tau_h_max in component persistent_sodium_current_h_gate (millisecond)"
    legend_constants[66] = "theta_h in component persistent_sodium_current_h_gate (millivolt)"
    legend_constants[67] = "sigma_h in component persistent_sodium_current_h_gate (millivolt)"
    legend_constants[68] = "g_L in component leakage_current (nanoS)"
    legend_constants[69] = "E_L in component leakage_current (millivolt)"
    legend_constants[70] = "E_syn_e in component tonic_current (millivolt)"
    legend_constants[71] = "g_tonic_e in component tonic_current (nanoS)"
    legend_algebraic[46] = "s_infinity in component synaptic_input (dimensionless)"
    legend_constants[72] = "kr in component synaptic_input (dimensionless)"
    legend_constants[73] = "tau_s in component synaptic_input (millisecond)"
    legend_constants[74] = "sigma_s in component synaptic_input (millivolt)"
    legend_constants[75] = "theta_s in component synaptic_input (millivolt)"
    legend_voi = "time in component environment (millisecond)"
    legend_states[8] = "V in component membrane (millivolt)"
    legend_constants[76] = "C in component membrane (picoF)"
    legend_constants[77] = "i_app in component membrane (picoA)"
    legend_algebraic[52] = "i_NaP in component persistent_sodium_current (picoA)"
    legend_algebraic[49] = "i_Na in component fast_sodium_current (picoA)"
    legend_algebraic[50] = "i_K in component potassium_current (picoA)"
    legend_algebraic[53] = "i_L in component leakage_current (picoA)"
    legend_algebraic[54] = "i_tonic_e in component tonic_current (picoA)"
    legend_algebraic[78] = "i_syn_e in component synaptic_input (picoA)"
    legend_constants[78] = "E_Na in component fast_sodium_current (millivolt)"
    legend_constants[79] = "g_Na in component fast_sodium_current (nanoS)"
    legend_algebraic[48] = "m_infinity in component fast_sodium_current_m_gate (dimensionless)"
    legend_states[9] = "n in component fast_sodium_current_n_gate (dimensionless)"
    legend_constants[80] = "theta_m in component fast_sodium_current_m_gate (millivolt)"
    legend_constants[81] = "sigma_m in component fast_sodium_current_m_gate (millivolt)"
    legend_algebraic[7] = "n_infinity in component fast_sodium_current_n_gate (dimensionless)"
    legend_algebraic[23] = "tau_n in component fast_sodium_current_n_gate (millisecond)"
    legend_constants[82] = "tau_n_max in component fast_sodium_current_n_gate (millisecond)"
    legend_constants[83] = "theta_n in component fast_sodium_current_n_gate (millivolt)"
    legend_constants[84] = "sigma_n in component fast_sodium_current_n_gate (millivolt)"
    legend_constants[85] = "g_K in component potassium_current (nanoS)"
    legend_constants[86] = "E_K in component potassium_current (millivolt)"
    legend_states[10] = "n in component potassium_current_n_gate (dimensionless)"
    legend_algebraic[8] = "n_infinity in component potassium_current_n_gate (dimensionless)"
    legend_algebraic[24] = "tau_n in component potassium_current_n_gate (millisecond)"
    legend_constants[87] = "tau_n_max in component potassium_current_n_gate (millisecond)"
    legend_constants[88] = "theta_n in component potassium_current_n_gate (millivolt)"
    legend_constants[89] = "sigma_n in component potassium_current_n_gate (millivolt)"
    legend_constants[90] = "g_NaP in component persistent_sodium_current (nanoS)"
    legend_algebraic[51] = "m_infinity in component persistent_sodium_current_m_gate (dimensionless)"
    legend_states[11] = "h in component persistent_sodium_current_h_gate (dimensionless)"
    legend_constants[91] = "theta_m in component persistent_sodium_current_m_gate (millivolt)"
    legend_constants[92] = "sigma_m in component persistent_sodium_current_m_gate (millivolt)"
    legend_algebraic[9] = "h_infinity in component persistent_sodium_current_h_gate (dimensionless)"
    legend_algebraic[25] = "tau_h in component persistent_sodium_current_h_gate (millisecond)"
    legend_constants[93] = "tau_h_max in component persistent_sodium_current_h_gate (millisecond)"
    legend_constants[94] = "theta_h in component persistent_sodium_current_h_gate (millivolt)"
    legend_constants[95] = "sigma_h in component persistent_sodium_current_h_gate (millivolt)"
    legend_constants[96] = "g_L in component leakage_current (nanoS)"
    legend_constants[97] = "E_L in component leakage_current (millivolt)"
    legend_constants[98] = "E_syn_e in component tonic_current (millivolt)"
    legend_constants[99] = "g_tonic_e in component tonic_current (nanoS)"
    legend_algebraic[55] = "s_infinity in component synaptic_input (dimensionless)"
    legend_constants[100] = "kr in component synaptic_input (dimensionless)"
    legend_constants[101] = "tau_s in component synaptic_input (millisecond)"
    legend_constants[102] = "sigma_s in component synaptic_input (millivolt)"
    legend_constants[103] = "theta_s in component synaptic_input (millivolt)"
    legend_voi = "time in component environment (millisecond)"
    legend_states[12] = "V in component membrane (millivolt)"
    legend_constants[104] = "C in component membrane (picoF)"
    legend_constants[105] = "i_app in component membrane (picoA)"
    legend_algebraic[61] = "i_NaP in component persistent_sodium_current (picoA)"
    legend_algebraic[58] = "i_Na in component fast_sodium_current (picoA)"
    legend_algebraic[59] = "i_K in component potassium_current (picoA)"
    legend_algebraic[62] = "i_L in component leakage_current (picoA)"
    legend_algebraic[63] = "i_tonic_e in component tonic_current (picoA)"
    legend_algebraic[79] = "i_syn_e in component synaptic_input (picoA)"
    legend_constants[106] = "E_Na in component fast_sodium_current (millivolt)"
    legend_constants[107] = "g_Na in component fast_sodium_current (nanoS)"
    legend_algebraic[57] = "m_infinity in component fast_sodium_current_m_gate (dimensionless)"
    legend_states[13] = "n in component fast_sodium_current_n_gate (dimensionless)"
    legend_constants[108] = "theta_m in component fast_sodium_current_m_gate (millivolt)"
    legend_constants[109] = "sigma_m in component fast_sodium_current_m_gate (millivolt)"
    legend_algebraic[10] = "n_infinity in component fast_sodium_current_n_gate (dimensionless)"
    legend_algebraic[26] = "tau_n in component fast_sodium_current_n_gate (millisecond)"
    legend_constants[110] = "tau_n_max in component fast_sodium_current_n_gate (millisecond)"
    legend_constants[111] = "theta_n in component fast_sodium_current_n_gate (millivolt)"
    legend_constants[112] = "sigma_n in component fast_sodium_current_n_gate (millivolt)"
    legend_constants[113] = "g_K in component potassium_current (nanoS)"
    legend_constants[114] = "E_K in component potassium_current (millivolt)"
    legend_states[14] = "n in component potassium_current_n_gate (dimensionless)"
    legend_algebraic[11] = "n_infinity in component potassium_current_n_gate (dimensionless)"
    legend_algebraic[27] = "tau_n in component potassium_current_n_gate (millisecond)"
    legend_constants[115] = "tau_n_max in component potassium_current_n_gate (millisecond)"
    legend_constants[116] = "theta_n in component potassium_current_n_gate (millivolt)"
    legend_constants[117] = "sigma_n in component potassium_current_n_gate (millivolt)"
    legend_constants[118] = "g_NaP in component persistent_sodium_current (nanoS)"
    legend_algebraic[60] = "m_infinity in component persistent_sodium_current_m_gate (dimensionless)"
    legend_states[15] = "h in component persistent_sodium_current_h_gate (dimensionless)"
    legend_constants[119] = "theta_m in component persistent_sodium_current_m_gate (millivolt)"
    legend_constants[120] = "sigma_m in component persistent_sodium_current_m_gate (millivolt)"
    legend_algebraic[12] = "h_infinity in component persistent_sodium_current_h_gate (dimensionless)"
    legend_algebraic[28] = "tau_h in component persistent_sodium_current_h_gate (millisecond)"
    legend_constants[121] = "tau_h_max in component persistent_sodium_current_h_gate (millisecond)"
    legend_constants[122] = "theta_h in component persistent_sodium_current_h_gate (millivolt)"
    legend_constants[123] = "sigma_h in component persistent_sodium_current_h_gate (millivolt)"
    legend_constants[124] = "g_L in component leakage_current (nanoS)"
    legend_constants[125] = "E_L in component leakage_current (millivolt)"
    legend_constants[126] = "E_syn_e in component tonic_current (millivolt)"
    legend_constants[127] = "g_tonic_e in component tonic_current (nanoS)"
    legend_algebraic[64] = "s_infinity in component synaptic_input (dimensionless)"
    legend_constants[128] = "kr in component synaptic_input (dimensionless)"
    legend_constants[129] = "tau_s in component synaptic_input (millisecond)"
    legend_constants[130] = "sigma_s in component synaptic_input (millivolt)"
    legend_constants[131] = "theta_s in component synaptic_input (millivolt)"
    legend_voi = "time in component environment (millisecond)"
    legend_states[16] = "V in component membrane (millivolt)"
    legend_constants[132] = "C in component membrane (picoF)"
    legend_constants[133] = "i_app in component membrane (picoA)"
    legend_algebraic[70] = "i_NaP in component persistent_sodium_current (picoA)"
    legend_algebraic[67] = "i_Na in component fast_sodium_current (picoA)"
    legend_algebraic[68] = "i_K in component potassium_current (picoA)"
    legend_algebraic[71] = "i_L in component leakage_current (picoA)"
    legend_algebraic[72] = "i_tonic_e in component tonic_current (picoA)"
    legend_algebraic[80] = "i_syn_e in component synaptic_input (picoA)"
    legend_constants[134] = "E_Na in component fast_sodium_current (millivolt)"
    legend_constants[135] = "g_Na in component fast_sodium_current (nanoS)"
    legend_algebraic[66] = "m_infinity in component fast_sodium_current_m_gate (dimensionless)"
    legend_states[17] = "n in component fast_sodium_current_n_gate (dimensionless)"
    legend_constants[136] = "theta_m in component fast_sodium_current_m_gate (millivolt)"
    legend_constants[137] = "sigma_m in component fast_sodium_current_m_gate (millivolt)"
    legend_algebraic[13] = "n_infinity in component fast_sodium_current_n_gate (dimensionless)"
    legend_algebraic[29] = "tau_n in component fast_sodium_current_n_gate (millisecond)"
    legend_constants[138] = "tau_n_max in component fast_sodium_current_n_gate (millisecond)"
    legend_constants[139] = "theta_n in component fast_sodium_current_n_gate (millivolt)"
    legend_constants[140] = "sigma_n in component fast_sodium_current_n_gate (millivolt)"
    legend_constants[141] = "g_K in component potassium_current (nanoS)"
    legend_constants[142] = "E_K in component potassium_current (millivolt)"
    legend_states[18] = "n in component potassium_current_n_gate (dimensionless)"
    legend_algebraic[14] = "n_infinity in component potassium_current_n_gate (dimensionless)"
    legend_algebraic[30] = "tau_n in component potassium_current_n_gate (millisecond)"
    legend_constants[143] = "tau_n_max in component potassium_current_n_gate (millisecond)"
    legend_constants[144] = "theta_n in component potassium_current_n_gate (millivolt)"
    legend_constants[145] = "sigma_n in component potassium_current_n_gate (millivolt)"
    legend_constants[146] = "g_NaP in component persistent_sodium_current (nanoS)"
    legend_algebraic[69] = "m_infinity in component persistent_sodium_current_m_gate (dimensionless)"
    legend_states[19] = "h in component persistent_sodium_current_h_gate (dimensionless)"
    legend_constants[147] = "theta_m in component persistent_sodium_current_m_gate (millivolt)"
    legend_constants[148] = "sigma_m in component persistent_sodium_current_m_gate (millivolt)"
    legend_algebraic[15] = "h_infinity in component persistent_sodium_current_h_gate (dimensionless)"
    legend_algebraic[31] = "tau_h in component persistent_sodium_current_h_gate (millisecond)"
    legend_constants[149] = "tau_h_max in component persistent_sodium_current_h_gate (millisecond)"
    legend_constants[150] = "theta_h in component persistent_sodium_current_h_gate (millivolt)"
    legend_constants[151] = "sigma_h in component persistent_sodium_current_h_gate (millivolt)"
    legend_constants[152] = "g_L in component leakage_current (nanoS)"
    legend_constants[153] = "E_L in component leakage_current (millivolt)"
    legend_constants[154] = "E_syn_e in component tonic_current (millivolt)"
    legend_constants[155] = "g_tonic_e in component tonic_current (nanoS)"
    legend_algebraic[73] = "s_infinity in component synaptic_input (dimensionless)"
    legend_constants[156] = "kr in component synaptic_input (dimensionless)"
    legend_constants[157] = "tau_s in component synaptic_input (millisecond)"
    legend_constants[158] = "sigma_s in component synaptic_input (millivolt)"
    legend_constants[159] = "theta_s in component synaptic_input (millivolt)"
    legend_rates[0] = "d/dt V in component membrane (millivolt)"
    legend_rates[1] = "d/dt n in component fast_sodium_current_n_gate (dimensionless)"
    legend_rates[2] = "d/dt n in component potassium_current_n_gate (dimensionless)"
    legend_rates[3] = "d/dt h in component persistent_sodium_current_h_gate (dimensionless)"
    legend_rates[4] = "d/dt V in component membrane (millivolt)"
    legend_rates[5] = "d/dt n in component fast_sodium_current_n_gate (dimensionless)"
    legend_rates[6] = "d/dt n in component potassium_current_n_gate (dimensionless)"
    legend_rates[7] = "d/dt h in component persistent_sodium_current_h_gate (dimensionless)"
    legend_rates[8] = "d/dt V in component membrane (millivolt)"
    legend_rates[9] = "d/dt n in component fast_sodium_current_n_gate (dimensionless)"
    legend_rates[10] = "d/dt n in component potassium_current_n_gate (dimensionless)"
    legend_rates[11] = "d/dt h in component persistent_sodium_current_h_gate (dimensionless)"
    legend_rates[12] = "d/dt V in component membrane (millivolt)"
    legend_rates[13] = "d/dt n in component fast_sodium_current_n_gate (dimensionless)"
    legend_rates[14] = "d/dt n in component potassium_current_n_gate (dimensionless)"
    legend_rates[15] = "d/dt h in component persistent_sodium_current_h_gate (dimensionless)"
    legend_rates[16] = "d/dt V in component membrane (millivolt)"
    legend_rates[17] = "d/dt n in component fast_sodium_current_n_gate (dimensionless)"
    legend_rates[18] = "d/dt n in component potassium_current_n_gate (dimensionless)"
    legend_rates[19] = "d/dt h in component persistent_sodium_current_h_gate (dimensionless)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    constants[0] = 0.10
    constants[1] = 0.10
    constants[2] = 0.10
    constants[3] = 0.10
    constants[4] = 0.10
    constants[5] = 0.10
    constants[6] = 0.10
    constants[7] = 0.10
    constants[8] = 0.10
    constants[9] = 0.10
    constants[10] = 0.10
    constants[11] = 0.10
    constants[12] = 0.10
    constants[13] = 0.10
    constants[14] = 0.10
    constants[15] = 0.10
    constants[16] = 0.10
    constants[17] = 0.10
    constants[18] = 0.10
    constants[19] = 0.10
    states[0] = -50.0
    constants[20] = 21.0
    constants[21] = 0.0
    constants[22] = 50.0
    constants[23] = 28.0
    states[1] = 0.01
    constants[24] = -34.0
    constants[25] = -5.0
    constants[26] = 10.0
    constants[27] = -29.0
    constants[28] = -4.0
    constants[29] = 11.2
    constants[30] = -85.0
    states[2] = 0.01
    constants[31] = 10.0
    constants[32] = -29.0
    constants[33] = -4.0
    constants[34] = 2.8
    states[3] = 0.46
    constants[35] = -40.0
    constants[36] = -6.0
    constants[37] = 10000.0
    constants[38] = -48.0
    constants[39] = 6.0
    constants[40] = 2.8
    constants[41] = -57.5
    constants[42] = 0.0
    constants[43] = 0.0
    constants[44] = 1.0
    constants[45] = 5.0
    constants[46] = -5.0
    constants[47] = -10.0
    states[4] = -50.0
    constants[48] = 21.0
    constants[49] = 0.0
    constants[50] = 50.0
    constants[51] = 28.0
    states[5] = 0.01
    constants[52] = -34.0
    constants[53] = -5.0
    constants[54] = 10.0
    constants[55] = -29.0
    constants[56] = -4.0
    constants[57] = 11.2
    constants[58] = -85.0
    states[6] = 0.01
    constants[59] = 10.0
    constants[60] = -29.0
    constants[61] = -4.0
    constants[62] = 2.8
    states[7] = 0.46
    constants[63] = -40.0
    constants[64] = -6.0
    constants[65] = 10000.0
    constants[66] = -48.0
    constants[67] = 6.0
    constants[68] = 2.8
    constants[69] = -57.5
    constants[70] = 0.0
    constants[71] = 0.0
    constants[72] = 1.0
    constants[73] = 5.0
    constants[74] = -5.0
    constants[75] = -10.0
    states[8] = -50.0
    constants[76] = 21.0
    constants[77] = 0.0
    constants[78] = 50.0
    constants[79] = 28.0
    states[9] = 0.01
    constants[80] = -34.0
    constants[81] = -5.0
    constants[82] = 10.0
    constants[83] = -29.0
    constants[84] = -4.0
    constants[85] = 11.2
    constants[86] = -85.0
    states[10] = 0.01
    constants[87] = 10.0
    constants[88] = -29.0
    constants[89] = -4.0
    constants[90] = 2.8
    states[11] = 0.46
    constants[91] = -40.0
    constants[92] = -6.0
    constants[93] = 10000.0
    constants[94] = -48.0
    constants[95] = 6.0
    constants[96] = 2.8
    constants[97] = -57.5
    constants[98] = 0.0
    constants[99] = 0.0
    constants[100] = 1.0
    constants[101] = 5.0
    constants[102] = -5.0
    constants[103] = -10.0
    states[12] = -50.0
    constants[104] = 21.0
    constants[105] = 0.0
    constants[106] = 50.0
    constants[107] = 28.0
    states[13] = 0.01
    constants[108] = -34.0
    constants[109] = -5.0
    constants[110] = 10.0
    constants[111] = -29.0
    constants[112] = -4.0
    constants[113] = 11.2
    constants[114] = -85.0
    states[14] = 0.01
    constants[115] = 10.0
    constants[116] = -29.0
    constants[117] = -4.0
    constants[118] = 2.8
    states[15] = 0.46
    constants[119] = -40.0
    constants[120] = -6.0
    constants[121] = 10000.0
    constants[122] = -48.0
    constants[123] = 6.0
    constants[124] = 2.8
    constants[125] = -57.5
    constants[126] = 0.0
    constants[127] = 0.0
    constants[128] = 1.0
    constants[129] = 5.0
    constants[130] = -5.0
    constants[131] = -10.0
    states[16] = -50.0
    constants[132] = 21.0
    constants[133] = 0.0
    constants[134] = 50.0
    constants[135] = 28.0
    states[17] = 0.01
    constants[136] = -34.0
    constants[137] = -5.0
    constants[138] = 10.0
    constants[139] = -29.0
    constants[140] = -4.0
    constants[141] = 11.2
    constants[142] = -85.0
    states[18] = 0.01
    constants[143] = 10.0
    constants[144] = -29.0
    constants[145] = -4.0
    constants[146] = 2.8
    states[19] = 0.46
    constants[147] = -40.0
    constants[148] = -6.0
    constants[149] = 10000.0
    constants[150] = -48.0
    constants[151] = 6.0
    constants[152] = 2.8
    constants[153] = -57.5
    constants[154] = 0.0
    constants[155] = 0.0
    constants[156] = 1.0
    constants[157] = 5.0
    constants[158] = -5.0
    constants[159] = -10.0
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    algebraic[1] = 1.00000/(1.00000+exp((states[0]-constants[27])/constants[28]))
    algebraic[17] = constants[26]/cosh((states[0]-constants[27])/(2.00000*constants[28]))
    rates[1] = (algebraic[1]-states[1])/algebraic[17]
    algebraic[2] = 1.00000/(1.00000+exp((states[0]-constants[32])/constants[33]))
    algebraic[18] = constants[31]/cosh((states[0]-constants[32])/(2.00000*constants[33]))
    rates[2] = (algebraic[2]-states[2])/algebraic[18]
    algebraic[3] = 1.00000/(1.00000+exp((states[0]-constants[38])/constants[39]))
    algebraic[19] = constants[37]/cosh((states[0]-constants[38])/(2.00000*constants[39]))
    rates[3] = (algebraic[3]-states[3])/algebraic[19]
    algebraic[4] = 1.00000/(1.00000+exp((states[4]-constants[55])/constants[56]))
    algebraic[20] = constants[54]/cosh((states[4]-constants[55])/(2.00000*constants[56]))
    rates[5] = (algebraic[4]-states[5])/algebraic[20]
    algebraic[5] = 1.00000/(1.00000+exp((states[4]-constants[60])/constants[61]))
    algebraic[21] = constants[59]/cosh((states[4]-constants[60])/(2.00000*constants[61]))
    rates[6] = (algebraic[5]-states[6])/algebraic[21]
    algebraic[6] = 1.00000/(1.00000+exp((states[4]-constants[66])/constants[67]))
    algebraic[22] = constants[65]/cosh((states[4]-constants[66])/(2.00000*constants[67]))
    rates[7] = (algebraic[6]-states[7])/algebraic[22]
    algebraic[7] = 1.00000/(1.00000+exp((states[8]-constants[83])/constants[84]))
    algebraic[23] = constants[82]/cosh((states[8]-constants[83])/(2.00000*constants[84]))
    rates[9] = (algebraic[7]-states[9])/algebraic[23]
    algebraic[8] = 1.00000/(1.00000+exp((states[8]-constants[88])/constants[89]))
    algebraic[24] = constants[87]/cosh((states[8]-constants[88])/(2.00000*constants[89]))
    rates[10] = (algebraic[8]-states[10])/algebraic[24]
    algebraic[9] = 1.00000/(1.00000+exp((states[8]-constants[94])/constants[95]))
    algebraic[25] = constants[93]/cosh((states[8]-constants[94])/(2.00000*constants[95]))
    rates[11] = (algebraic[9]-states[11])/algebraic[25]
    algebraic[10] = 1.00000/(1.00000+exp((states[12]-constants[111])/constants[112]))
    algebraic[26] = constants[110]/cosh((states[12]-constants[111])/(2.00000*constants[112]))
    rates[13] = (algebraic[10]-states[13])/algebraic[26]
    algebraic[11] = 1.00000/(1.00000+exp((states[12]-constants[116])/constants[117]))
    algebraic[27] = constants[115]/cosh((states[12]-constants[116])/(2.00000*constants[117]))
    rates[14] = (algebraic[11]-states[14])/algebraic[27]
    algebraic[12] = 1.00000/(1.00000+exp((states[12]-constants[122])/constants[123]))
    algebraic[28] = constants[121]/cosh((states[12]-constants[122])/(2.00000*constants[123]))
    rates[15] = (algebraic[12]-states[15])/algebraic[28]
    algebraic[13] = 1.00000/(1.00000+exp((states[16]-constants[139])/constants[140]))
    algebraic[29] = constants[138]/cosh((states[16]-constants[139])/(2.00000*constants[140]))
    rates[17] = (algebraic[13]-states[17])/algebraic[29]
    algebraic[14] = 1.00000/(1.00000+exp((states[16]-constants[144])/constants[145]))
    algebraic[30] = constants[143]/cosh((states[16]-constants[144])/(2.00000*constants[145]))
    rates[18] = (algebraic[14]-states[18])/algebraic[30]
    algebraic[15] = 1.00000/(1.00000+exp((states[16]-constants[150])/constants[151]))
    algebraic[31] = constants[149]/cosh((states[16]-constants[150])/(2.00000*constants[151]))
    rates[19] = (algebraic[15]-states[19])/algebraic[31]
    algebraic[33] = 1.00000/(1.00000+exp((states[0]-constants[35])/constants[36]))
    algebraic[34] = constants[34]*algebraic[33]*states[3]*(states[0]-constants[22])
    algebraic[0] = 1.00000/(1.00000+exp((states[0]-constants[24])/constants[25]))
    algebraic[16] = constants[23]*algebraic[0]**3.00000*(1.00000-states[1])*(states[0]-constants[22])
    algebraic[32] = constants[29]*states[2]**4.00000*(states[0]-constants[30])
    algebraic[35] = constants[40]*(states[0]-constants[41])
    algebraic[36] = constants[43]*(states[0]-constants[42])
    algebraic[37] = 1.00000/(1.00000+exp((states[0]-constants[47])/constants[46]))
    algebraic = rootfind_0(voi, constants, states, algebraic)
    algebraic[46] = 1.00000/(1.00000+exp((states[4]-constants[75])/constants[74]))
    algebraic = rootfind_1(voi, constants, states, algebraic)
    algebraic[55] = 1.00000/(1.00000+exp((states[8]-constants[103])/constants[102]))
    algebraic = rootfind_2(voi, constants, states, algebraic)
    algebraic[64] = 1.00000/(1.00000+exp((states[12]-constants[131])/constants[130]))
    algebraic = rootfind_3(voi, constants, states, algebraic)
    algebraic[73] = 1.00000/(1.00000+exp((states[16]-constants[159])/constants[158]))
    algebraic = rootfind_4(voi, constants, states, algebraic)
    algebraic[75] = constants[0]*algebraic[38]+constants[1]*algebraic[38]+constants[2]*algebraic[38]+constants[3]*algebraic[38]+constants[4]*algebraic[47]+constants[5]*algebraic[47]+constants[6]*algebraic[47]+constants[7]*algebraic[47]+constants[8]*algebraic[56]+constants[9]*algebraic[56]+constants[10]*algebraic[56]+constants[11]*algebraic[56]+constants[12]*algebraic[65]+constants[13]*algebraic[65]+constants[14]*algebraic[65]+constants[15]*algebraic[65]+constants[16]*algebraic[74]+constants[17]*algebraic[74]+constants[18]*algebraic[74]+constants[19]*algebraic[74]
    algebraic[76] = algebraic[75]*(states[0]-constants[42])
    rates[0] = (-(algebraic[34]+algebraic[16]+algebraic[32]+algebraic[35]+algebraic[36]+algebraic[76])+constants[21])/constants[20]
    algebraic[42] = 1.00000/(1.00000+exp((states[4]-constants[63])/constants[64]))
    algebraic[43] = constants[62]*algebraic[42]*states[7]*(states[4]-constants[50])
    algebraic[39] = 1.00000/(1.00000+exp((states[4]-constants[52])/constants[53]))
    algebraic[40] = constants[51]*algebraic[39]**3.00000*(1.00000-states[5])*(states[4]-constants[50])
    algebraic[41] = constants[57]*states[6]**4.00000*(states[4]-constants[58])
    algebraic[44] = constants[68]*(states[4]-constants[69])
    algebraic[45] = constants[71]*(states[4]-constants[70])
    algebraic[77] = algebraic[75]*(states[4]-constants[70])
    rates[4] = (-(algebraic[43]+algebraic[40]+algebraic[41]+algebraic[44]+algebraic[45]+algebraic[77])+constants[49])/constants[48]
    algebraic[51] = 1.00000/(1.00000+exp((states[8]-constants[91])/constants[92]))
    algebraic[52] = constants[90]*algebraic[51]*states[11]*(states[8]-constants[78])
    algebraic[48] = 1.00000/(1.00000+exp((states[8]-constants[80])/constants[81]))
    algebraic[49] = constants[79]*algebraic[48]**3.00000*(1.00000-states[9])*(states[8]-constants[78])
    algebraic[50] = constants[85]*states[10]**4.00000*(states[8]-constants[86])
    algebraic[53] = constants[96]*(states[8]-constants[97])
    algebraic[54] = constants[99]*(states[8]-constants[98])
    algebraic[78] = algebraic[75]*(states[8]-constants[98])
    rates[8] = (-(algebraic[52]+algebraic[49]+algebraic[50]+algebraic[53]+algebraic[54]+algebraic[78])+constants[77])/constants[76]
    algebraic[60] = 1.00000/(1.00000+exp((states[12]-constants[119])/constants[120]))
    algebraic[61] = constants[118]*algebraic[60]*states[15]*(states[12]-constants[106])
    algebraic[57] = 1.00000/(1.00000+exp((states[12]-constants[108])/constants[109]))
    algebraic[58] = constants[107]*algebraic[57]**3.00000*(1.00000-states[13])*(states[12]-constants[106])
    algebraic[59] = constants[113]*states[14]**4.00000*(states[12]-constants[114])
    algebraic[62] = constants[124]*(states[12]-constants[125])
    algebraic[63] = constants[127]*(states[12]-constants[126])
    algebraic[79] = algebraic[75]*(states[12]-constants[126])
    rates[12] = (-(algebraic[61]+algebraic[58]+algebraic[59]+algebraic[62]+algebraic[63]+algebraic[79])+constants[105])/constants[104]
    algebraic[69] = 1.00000/(1.00000+exp((states[16]-constants[147])/constants[148]))
    algebraic[70] = constants[146]*algebraic[69]*states[19]*(states[16]-constants[134])
    algebraic[66] = 1.00000/(1.00000+exp((states[16]-constants[136])/constants[137]))
    algebraic[67] = constants[135]*algebraic[66]**3.00000*(1.00000-states[17])*(states[16]-constants[134])
    algebraic[68] = constants[141]*states[18]**4.00000*(states[16]-constants[142])
    algebraic[71] = constants[152]*(states[16]-constants[153])
    algebraic[72] = constants[155]*(states[16]-constants[154])
    algebraic[80] = algebraic[75]*(states[16]-constants[154])
    rates[16] = (-(algebraic[70]+algebraic[67]+algebraic[68]+algebraic[71]+algebraic[72]+algebraic[80])+constants[133])/constants[132]
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[1] = 1.00000/(1.00000+exp((states[0]-constants[27])/constants[28]))
    algebraic[17] = constants[26]/cosh((states[0]-constants[27])/(2.00000*constants[28]))
    algebraic[2] = 1.00000/(1.00000+exp((states[0]-constants[32])/constants[33]))
    algebraic[18] = constants[31]/cosh((states[0]-constants[32])/(2.00000*constants[33]))
    algebraic[3] = 1.00000/(1.00000+exp((states[0]-constants[38])/constants[39]))
    algebraic[19] = constants[37]/cosh((states[0]-constants[38])/(2.00000*constants[39]))
    algebraic[4] = 1.00000/(1.00000+exp((states[4]-constants[55])/constants[56]))
    algebraic[20] = constants[54]/cosh((states[4]-constants[55])/(2.00000*constants[56]))
    algebraic[5] = 1.00000/(1.00000+exp((states[4]-constants[60])/constants[61]))
    algebraic[21] = constants[59]/cosh((states[4]-constants[60])/(2.00000*constants[61]))
    algebraic[6] = 1.00000/(1.00000+exp((states[4]-constants[66])/constants[67]))
    algebraic[22] = constants[65]/cosh((states[4]-constants[66])/(2.00000*constants[67]))
    algebraic[7] = 1.00000/(1.00000+exp((states[8]-constants[83])/constants[84]))
    algebraic[23] = constants[82]/cosh((states[8]-constants[83])/(2.00000*constants[84]))
    algebraic[8] = 1.00000/(1.00000+exp((states[8]-constants[88])/constants[89]))
    algebraic[24] = constants[87]/cosh((states[8]-constants[88])/(2.00000*constants[89]))
    algebraic[9] = 1.00000/(1.00000+exp((states[8]-constants[94])/constants[95]))
    algebraic[25] = constants[93]/cosh((states[8]-constants[94])/(2.00000*constants[95]))
    algebraic[10] = 1.00000/(1.00000+exp((states[12]-constants[111])/constants[112]))
    algebraic[26] = constants[110]/cosh((states[12]-constants[111])/(2.00000*constants[112]))
    algebraic[11] = 1.00000/(1.00000+exp((states[12]-constants[116])/constants[117]))
    algebraic[27] = constants[115]/cosh((states[12]-constants[116])/(2.00000*constants[117]))
    algebraic[12] = 1.00000/(1.00000+exp((states[12]-constants[122])/constants[123]))
    algebraic[28] = constants[121]/cosh((states[12]-constants[122])/(2.00000*constants[123]))
    algebraic[13] = 1.00000/(1.00000+exp((states[16]-constants[139])/constants[140]))
    algebraic[29] = constants[138]/cosh((states[16]-constants[139])/(2.00000*constants[140]))
    algebraic[14] = 1.00000/(1.00000+exp((states[16]-constants[144])/constants[145]))
    algebraic[30] = constants[143]/cosh((states[16]-constants[144])/(2.00000*constants[145]))
    algebraic[15] = 1.00000/(1.00000+exp((states[16]-constants[150])/constants[151]))
    algebraic[31] = constants[149]/cosh((states[16]-constants[150])/(2.00000*constants[151]))
    algebraic[33] = 1.00000/(1.00000+exp((states[0]-constants[35])/constants[36]))
    algebraic[34] = constants[34]*algebraic[33]*states[3]*(states[0]-constants[22])
    algebraic[0] = 1.00000/(1.00000+exp((states[0]-constants[24])/constants[25]))
    algebraic[16] = constants[23]*algebraic[0]**3.00000*(1.00000-states[1])*(states[0]-constants[22])
    algebraic[32] = constants[29]*states[2]**4.00000*(states[0]-constants[30])
    algebraic[35] = constants[40]*(states[0]-constants[41])
    algebraic[36] = constants[43]*(states[0]-constants[42])
    algebraic[37] = 1.00000/(1.00000+exp((states[0]-constants[47])/constants[46]))
    algebraic = rootfind_0(voi, constants, states, algebraic)
    algebraic[46] = 1.00000/(1.00000+exp((states[4]-constants[75])/constants[74]))
    algebraic = rootfind_1(voi, constants, states, algebraic)
    algebraic[55] = 1.00000/(1.00000+exp((states[8]-constants[103])/constants[102]))
    algebraic = rootfind_2(voi, constants, states, algebraic)
    algebraic[64] = 1.00000/(1.00000+exp((states[12]-constants[131])/constants[130]))
    algebraic = rootfind_3(voi, constants, states, algebraic)
    algebraic[73] = 1.00000/(1.00000+exp((states[16]-constants[159])/constants[158]))
    algebraic = rootfind_4(voi, constants, states, algebraic)
    algebraic[75] = constants[0]*algebraic[38]+constants[1]*algebraic[38]+constants[2]*algebraic[38]+constants[3]*algebraic[38]+constants[4]*algebraic[47]+constants[5]*algebraic[47]+constants[6]*algebraic[47]+constants[7]*algebraic[47]+constants[8]*algebraic[56]+constants[9]*algebraic[56]+constants[10]*algebraic[56]+constants[11]*algebraic[56]+constants[12]*algebraic[65]+constants[13]*algebraic[65]+constants[14]*algebraic[65]+constants[15]*algebraic[65]+constants[16]*algebraic[74]+constants[17]*algebraic[74]+constants[18]*algebraic[74]+constants[19]*algebraic[74]
    algebraic[76] = algebraic[75]*(states[0]-constants[42])
    algebraic[42] = 1.00000/(1.00000+exp((states[4]-constants[63])/constants[64]))
    algebraic[43] = constants[62]*algebraic[42]*states[7]*(states[4]-constants[50])
    algebraic[39] = 1.00000/(1.00000+exp((states[4]-constants[52])/constants[53]))
    algebraic[40] = constants[51]*algebraic[39]**3.00000*(1.00000-states[5])*(states[4]-constants[50])
    algebraic[41] = constants[57]*states[6]**4.00000*(states[4]-constants[58])
    algebraic[44] = constants[68]*(states[4]-constants[69])
    algebraic[45] = constants[71]*(states[4]-constants[70])
    algebraic[77] = algebraic[75]*(states[4]-constants[70])
    algebraic[51] = 1.00000/(1.00000+exp((states[8]-constants[91])/constants[92]))
    algebraic[52] = constants[90]*algebraic[51]*states[11]*(states[8]-constants[78])
    algebraic[48] = 1.00000/(1.00000+exp((states[8]-constants[80])/constants[81]))
    algebraic[49] = constants[79]*algebraic[48]**3.00000*(1.00000-states[9])*(states[8]-constants[78])
    algebraic[50] = constants[85]*states[10]**4.00000*(states[8]-constants[86])
    algebraic[53] = constants[96]*(states[8]-constants[97])
    algebraic[54] = constants[99]*(states[8]-constants[98])
    algebraic[78] = algebraic[75]*(states[8]-constants[98])
    algebraic[60] = 1.00000/(1.00000+exp((states[12]-constants[119])/constants[120]))
    algebraic[61] = constants[118]*algebraic[60]*states[15]*(states[12]-constants[106])
    algebraic[57] = 1.00000/(1.00000+exp((states[12]-constants[108])/constants[109]))
    algebraic[58] = constants[107]*algebraic[57]**3.00000*(1.00000-states[13])*(states[12]-constants[106])
    algebraic[59] = constants[113]*states[14]**4.00000*(states[12]-constants[114])
    algebraic[62] = constants[124]*(states[12]-constants[125])
    algebraic[63] = constants[127]*(states[12]-constants[126])
    algebraic[79] = algebraic[75]*(states[12]-constants[126])
    algebraic[69] = 1.00000/(1.00000+exp((states[16]-constants[147])/constants[148]))
    algebraic[70] = constants[146]*algebraic[69]*states[19]*(states[16]-constants[134])
    algebraic[66] = 1.00000/(1.00000+exp((states[16]-constants[136])/constants[137]))
    algebraic[67] = constants[135]*algebraic[66]**3.00000*(1.00000-states[17])*(states[16]-constants[134])
    algebraic[68] = constants[141]*states[18]**4.00000*(states[16]-constants[142])
    algebraic[71] = constants[152]*(states[16]-constants[153])
    algebraic[72] = constants[155]*(states[16]-constants[154])
    algebraic[80] = algebraic[75]*(states[16]-constants[154])
    return algebraic

initialGuess0 = None
def rootfind_0(voi, constants, states, algebraic):
    """Calculate value of algebraic variable for DAE"""
    from scipy.optimize import fsolve
    global initialGuess0
    if (initialGuess0 == None): initialGuess0 = 0.1
    if not iterable(voi):
        algebraic[38] = fsolve(residualSN_0, initialGuess0, args=(algebraic, voi, constants, states), xtol=1E-6, warning=False)
        initialGuess0 = algebraic[38]
    else:
        for (i,t) in enumerate(voi):
            algebraic[38][i] = fsolve(residualSN_0, initialGuess0, args=(algebraic[:,i], voi[i], constants, states[:,i]), xtol=1E-6, warning=False)
            initialGuess0 = algebraic[38][i]
    return algebraic

def residualSN_0(algebraicCandidate, algebraic, voi, constants, states):
    algebraic[38] = algebraicCandidate
    return (algebraic[38]) - (((1.00000-algebraic[38])*algebraic[37]--(constants[44]*algebraic[38]))/constants[45])

initialGuess1 = None
def rootfind_1(voi, constants, states, algebraic):
    """Calculate value of algebraic variable for DAE"""
    from scipy.optimize import fsolve
    global initialGuess1
    if (initialGuess1 == None): initialGuess1 = 0.1
    if not iterable(voi):
        algebraic[47] = fsolve(residualSN_1, initialGuess1, args=(algebraic, voi, constants, states), xtol=1E-6, warning=False)
        initialGuess1 = algebraic[47]
    else:
        for (i,t) in enumerate(voi):
            algebraic[47][i] = fsolve(residualSN_1, initialGuess1, args=(algebraic[:,i], voi[i], constants, states[:,i]), xtol=1E-6, warning=False)
            initialGuess1 = algebraic[47][i]
    return algebraic

def residualSN_1(algebraicCandidate, algebraic, voi, constants, states):
    algebraic[47] = algebraicCandidate
    return (algebraic[47]) - (((1.00000-algebraic[47])*algebraic[46]--(constants[72]*algebraic[47]))/constants[73])

initialGuess2 = None
def rootfind_2(voi, constants, states, algebraic):
    """Calculate value of algebraic variable for DAE"""
    from scipy.optimize import fsolve
    global initialGuess2
    if (initialGuess2 == None): initialGuess2 = 0.1
    if not iterable(voi):
        algebraic[56] = fsolve(residualSN_2, initialGuess2, args=(algebraic, voi, constants, states), xtol=1E-6, warning=False)
        initialGuess2 = algebraic[56]
    else:
        for (i,t) in enumerate(voi):
            algebraic[56][i] = fsolve(residualSN_2, initialGuess2, args=(algebraic[:,i], voi[i], constants, states[:,i]), xtol=1E-6, warning=False)
            initialGuess2 = algebraic[56][i]
    return algebraic

def residualSN_2(algebraicCandidate, algebraic, voi, constants, states):
    algebraic[56] = algebraicCandidate
    return (algebraic[56]) - (((1.00000-algebraic[56])*algebraic[55]--(constants[100]*algebraic[56]))/constants[101])

initialGuess3 = None
def rootfind_3(voi, constants, states, algebraic):
    """Calculate value of algebraic variable for DAE"""
    from scipy.optimize import fsolve
    global initialGuess3
    if (initialGuess3 == None): initialGuess3 = 0.1
    if not iterable(voi):
        algebraic[65] = fsolve(residualSN_3, initialGuess3, args=(algebraic, voi, constants, states), xtol=1E-6, warning=False)
        initialGuess3 = algebraic[65]
    else:
        for (i,t) in enumerate(voi):
            algebraic[65][i] = fsolve(residualSN_3, initialGuess3, args=(algebraic[:,i], voi[i], constants, states[:,i]), xtol=1E-6, warning=False)
            initialGuess3 = algebraic[65][i]
    return algebraic

def residualSN_3(algebraicCandidate, algebraic, voi, constants, states):
    algebraic[65] = algebraicCandidate
    return (algebraic[65]) - (((1.00000-algebraic[65])*algebraic[64]--(constants[128]*algebraic[65]))/constants[129])

initialGuess4 = None
def rootfind_4(voi, constants, states, algebraic):
    """Calculate value of algebraic variable for DAE"""
    from scipy.optimize import fsolve
    global initialGuess4
    if (initialGuess4 == None): initialGuess4 = 0.1
    if not iterable(voi):
        algebraic[74] = fsolve(residualSN_4, initialGuess4, args=(algebraic, voi, constants, states), xtol=1E-6, warning=False)
        initialGuess4 = algebraic[74]
    else:
        for (i,t) in enumerate(voi):
            algebraic[74][i] = fsolve(residualSN_4, initialGuess4, args=(algebraic[:,i], voi[i], constants, states[:,i]), xtol=1E-6, warning=False)
            initialGuess4 = algebraic[74][i]
    return algebraic

def residualSN_4(algebraicCandidate, algebraic, voi, constants, states):
    algebraic[74] = algebraicCandidate
    return (algebraic[74]) - (((1.00000-algebraic[74])*algebraic[73]--(constants[156]*algebraic[74]))/constants[157])

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)