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 = 42
sizeStates = 15
sizeConstants = 45
from math import *
from numpy import *

def createLegends():
    legend_states = [""] * sizeStates
    legend_rates = [""] * sizeStates
    legend_algebraic = [""] * sizeAlgebraic
    legend_voi = ""
    legend_constants = [""] * sizeConstants
    legend_voi = "time in component environment (second)"
    legend_states[0] = "V in component membrane (millivolt)"
    legend_constants[0] = "R in component membrane (joule_per_kilomole_kelvin)"
    legend_constants[1] = "T in component membrane (kelvin)"
    legend_constants[2] = "F in component membrane (coulomb_per_mole)"
    legend_constants[3] = "C in component membrane (microF)"
    legend_constants[39] = "RTONF in component membrane (millivolt)"
    legend_algebraic[23] = "i_f in component hyperpolarising_activated_current (nanoA)"
    legend_algebraic[25] = "i_K in component time_dependent_potassium_current (nanoA)"
    legend_algebraic[26] = "i_K1 in component time_independent_potassium_current (nanoA)"
    legend_algebraic[27] = "i_Na_b in component sodium_background_current (nanoA)"
    legend_algebraic[29] = "i_Ca_b in component calcium_background_current (nanoA)"
    legend_algebraic[30] = "i_p in component sodium_potassium_pump (nanoA)"
    legend_algebraic[31] = "i_NaCa in component Na_Ca_exchanger (nanoA)"
    legend_algebraic[33] = "i_Na in component fast_sodium_current (nanoA)"
    legend_algebraic[40] = "i_Caf in component second_inward_current (nanoA)"
    legend_algebraic[20] = "i_fNa in component hyperpolarising_activated_current (nanoA)"
    legend_algebraic[0] = "E_Na in component hyperpolarising_activated_current (millivolt)"
    legend_algebraic[9] = "E_K in component hyperpolarising_activated_current (millivolt)"
    legend_algebraic[22] = "i_fK in component hyperpolarising_activated_current (nanoA)"
    legend_constants[4] = "g_f_Na in component hyperpolarising_activated_current (microS)"
    legend_constants[5] = "g_f_K in component hyperpolarising_activated_current (microS)"
    legend_constants[6] = "Km_f in component hyperpolarising_activated_current (millimolar)"
    legend_states[1] = "Kc in component extracellular_potassium_concentration (millimolar)"
    legend_states[2] = "Ki in component intracellular_potassium_concentration (millimolar)"
    legend_states[3] = "Nai in component intracellular_sodium_concentration (millimolar)"
    legend_constants[7] = "Nao in component extracellular_sodium_concentration (millimolar)"
    legend_states[4] = "y in component hyperpolarising_activated_current_y_gate (dimensionless)"
    legend_algebraic[1] = "alpha_y in component hyperpolarising_activated_current_y_gate (per_second)"
    legend_algebraic[10] = "beta_y in component hyperpolarising_activated_current_y_gate (per_second)"
    legend_algebraic[24] = "I_K in component time_dependent_potassium_current (nanoA)"
    legend_constants[8] = "i_K_max in component time_dependent_potassium_current (nanoA)"
    legend_states[5] = "x in component time_dependent_potassium_current_x_gate (dimensionless)"
    legend_algebraic[2] = "alpha_x in component time_dependent_potassium_current_x_gate (per_second)"
    legend_algebraic[11] = "beta_x in component time_dependent_potassium_current_x_gate (per_second)"
    legend_constants[9] = "g_K1 in component time_independent_potassium_current (microS)"
    legend_constants[10] = "Km_K1 in component time_independent_potassium_current (millimolar)"
    legend_constants[11] = "g_Nab in component sodium_background_current (microS)"
    legend_algebraic[28] = "E_Ca in component calcium_background_current (millivolt)"
    legend_constants[12] = "g_Cab in component calcium_background_current (microS)"
    legend_states[6] = "Cai in component intracellular_calcium_concentration (millimolar)"
    legend_constants[13] = "Cao in component extracellular_calcium_concentration (millimolar)"
    legend_constants[14] = "I_p in component sodium_potassium_pump (nanoA)"
    legend_constants[15] = "K_mK in component sodium_potassium_pump (millimolar)"
    legend_constants[16] = "K_mNa in component sodium_potassium_pump (millimolar)"
    legend_constants[17] = "n_NaCa in component Na_Ca_exchanger (dimensionless)"
    legend_constants[18] = "K_NaCa in component Na_Ca_exchanger (nanoA)"
    legend_constants[19] = "d_NaCa in component Na_Ca_exchanger (dimensionless)"
    legend_constants[20] = "gamma in component Na_Ca_exchanger (dimensionless)"
    legend_constants[21] = "g_Na in component fast_sodium_current (microS)"
    legend_algebraic[32] = "E_mh in component fast_sodium_current (millivolt)"
    legend_states[7] = "m in component fast_sodium_current_m_gate (dimensionless)"
    legend_states[8] = "h in component fast_sodium_current_h_gate (dimensionless)"
    legend_algebraic[12] = "alpha_m in component fast_sodium_current_m_gate (per_second)"
    legend_algebraic[17] = "beta_m in component fast_sodium_current_m_gate (per_second)"
    legend_constants[22] = "delta_m in component fast_sodium_current_m_gate (millivolt)"
    legend_algebraic[3] = "E0_m in component fast_sodium_current_m_gate (millivolt)"
    legend_algebraic[4] = "alpha_h in component fast_sodium_current_h_gate (per_second)"
    legend_algebraic[13] = "beta_h in component fast_sodium_current_h_gate (per_second)"
    legend_algebraic[34] = "i_siCa in component second_inward_current (nanoA)"
    legend_algebraic[35] = "i_siK in component second_inward_current (nanoA)"
    legend_algebraic[37] = "i_siNa in component second_inward_current (nanoA)"
    legend_constants[23] = "P_si in component second_inward_current (nanoA_per_millimolar)"
    legend_states[9] = "d in component second_inward_current_d_gate (dimensionless)"
    legend_states[10] = "f in component second_inward_current_f_gate (dimensionless)"
    legend_states[11] = "f2 in component second_inward_current_f2_gate (dimensionless)"
    legend_algebraic[14] = "alpha_d in component second_inward_current_d_gate (per_second)"
    legend_algebraic[18] = "beta_d in component second_inward_current_d_gate (per_second)"
    legend_constants[24] = "delta_d in component second_inward_current_d_gate (millivolt)"
    legend_algebraic[5] = "E0_d in component second_inward_current_d_gate (millivolt)"
    legend_algebraic[15] = "alpha_f in component second_inward_current_f_gate (per_second)"
    legend_algebraic[19] = "beta_f in component second_inward_current_f_gate (per_second)"
    legend_constants[25] = "delta_f in component second_inward_current_f_gate (millivolt)"
    legend_algebraic[6] = "E0_f in component second_inward_current_f_gate (millivolt)"
    legend_constants[26] = "alpha_f2 in component second_inward_current_f2_gate (per_second)"
    legend_algebraic[7] = "beta_f2 in component second_inward_current_f2_gate (per_second)"
    legend_constants[27] = "K_mf2 in component second_inward_current_f2_gate (millimolar)"
    legend_constants[28] = "radius in component intracellular_sodium_concentration (millimetre)"
    legend_constants[29] = "length in component intracellular_sodium_concentration (millimetre)"
    legend_constants[30] = "V_e_ratio in component intracellular_sodium_concentration (dimensionless)"
    legend_constants[40] = "V_Cell in component intracellular_sodium_concentration (millimetre3)"
    legend_constants[41] = "Vi in component intracellular_sodium_concentration (millimetre3)"
    legend_constants[43] = "V_up in component intracellular_calcium_concentration (millimetre3)"
    legend_constants[44] = "V_rel in component intracellular_calcium_concentration (millimetre3)"
    legend_algebraic[36] = "i_up in component intracellular_calcium_concentration (nanoA)"
    legend_algebraic[38] = "i_tr in component intracellular_calcium_concentration (nanoA)"
    legend_algebraic[41] = "i_rel in component intracellular_calcium_concentration (nanoA)"
    legend_states[12] = "Ca_up in component intracellular_calcium_concentration (millimolar)"
    legend_states[13] = "Ca_rel in component intracellular_calcium_concentration (millimolar)"
    legend_constants[31] = "Ca_up_max in component intracellular_calcium_concentration (millimolar)"
    legend_constants[32] = "K_mCa in component intracellular_calcium_concentration (millimolar)"
    legend_states[14] = "p in component intracellular_calcium_concentration (dimensionless)"
    legend_algebraic[16] = "alpha_p in component intracellular_calcium_concentration (per_second)"
    legend_algebraic[21] = "beta_p in component intracellular_calcium_concentration (per_second)"
    legend_algebraic[8] = "E0_p in component intracellular_calcium_concentration (millivolt)"
    legend_constants[33] = "tau_up in component intracellular_calcium_concentration (second)"
    legend_constants[34] = "tau_rep in component intracellular_calcium_concentration (second)"
    legend_constants[35] = "tau_rel in component intracellular_calcium_concentration (second)"
    legend_constants[36] = "rCa in component intracellular_calcium_concentration (dimensionless)"
    legend_constants[42] = "V_e in component extracellular_potassium_concentration (millimetre3)"
    legend_constants[37] = "Kb in component extracellular_potassium_concentration (millimolar)"
    legend_algebraic[39] = "i_mK in component extracellular_potassium_concentration (nanoA)"
    legend_constants[38] = "pf in component extracellular_potassium_concentration (per_second)"
    legend_rates[0] = "d/dt V in component membrane (millivolt)"
    legend_rates[4] = "d/dt y in component hyperpolarising_activated_current_y_gate (dimensionless)"
    legend_rates[5] = "d/dt x in component time_dependent_potassium_current_x_gate (dimensionless)"
    legend_rates[7] = "d/dt m in component fast_sodium_current_m_gate (dimensionless)"
    legend_rates[8] = "d/dt h in component fast_sodium_current_h_gate (dimensionless)"
    legend_rates[9] = "d/dt d in component second_inward_current_d_gate (dimensionless)"
    legend_rates[10] = "d/dt f in component second_inward_current_f_gate (dimensionless)"
    legend_rates[11] = "d/dt f2 in component second_inward_current_f2_gate (dimensionless)"
    legend_rates[3] = "d/dt Nai in component intracellular_sodium_concentration (millimolar)"
    legend_rates[14] = "d/dt p in component intracellular_calcium_concentration (dimensionless)"
    legend_rates[12] = "d/dt Ca_up in component intracellular_calcium_concentration (millimolar)"
    legend_rates[13] = "d/dt Ca_rel in component intracellular_calcium_concentration (millimolar)"
    legend_rates[6] = "d/dt Cai in component intracellular_calcium_concentration (millimolar)"
    legend_rates[1] = "d/dt Kc in component extracellular_potassium_concentration (millimolar)"
    legend_rates[2] = "d/dt Ki in component intracellular_potassium_concentration (millimolar)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    states[0] = -50
    constants[0] = 8314.472
    constants[1] = 310
    constants[2] = 96485.3415
    constants[3] = 0.000027
    constants[4] = 0.06
    constants[5] = 0.06
    constants[6] = 45
    states[1] = 3
    states[2] = 140
    states[3] = 7.5
    constants[7] = 140
    states[4] = 0.0822
    constants[8] = 0.8
    states[5] = 0.225
    constants[9] = 0.0075
    constants[10] = 10
    constants[11] = 0.0007
    constants[12] = 0.0001
    states[6] = 5.6e-5
    constants[13] = 2
    constants[14] = 0.5
    constants[15] = 1
    constants[16] = 40
    constants[17] = 3
    constants[18] = 0.00002
    constants[19] = 0.0001
    constants[20] = 0.5
    constants[21] = 0.0125
    states[7] = 0.0365
    states[8] = 0.1969
    constants[22] = 1e-5
    constants[23] = 0.12
    states[9] = 0
    states[10] = 0.9997
    states[11] = 0.5765
    constants[24] = 0.0001
    constants[25] = 0.0001
    constants[26] = 10
    constants[27] = 0.0005
    constants[28] = 0.008
    constants[29] = 0.11
    constants[30] = 0.1
    states[12] = 1.98
    states[13] = 0.55
    constants[31] = 5
    constants[32] = 0.002
    states[14] = 0.237
    constants[33] = 0.005
    constants[34] = 0.2
    constants[35] = 0.01
    constants[36] = 2
    constants[37] = 3
    constants[38] = 1
    constants[39] = (constants[0]*constants[1])/constants[2]
    constants[40] = 3.14159*(power(constants[28], 2.00000))*constants[29]
    constants[41] = constants[40]*(1.00000-constants[30])
    constants[42] = constants[40]*constants[30]
    constants[43] = constants[41]*0.0500000
    constants[44] = constants[41]*0.0200000
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    algebraic[7] = (states[6]*constants[26])/constants[27]
    rates[11] = constants[26]-states[11]*(constants[26]+algebraic[7])
    algebraic[1] = 0.0200000*exp(-states[0]/18.0000)
    algebraic[10] = 19.5000*exp(states[0]/19.0000)
    rates[4] = algebraic[1]*(1.00000-states[4])-algebraic[10]*states[4]
    algebraic[2] = 2.10000*exp(states[0]/28.0000)
    algebraic[11] = 0.960000*exp(-states[0]/24.0000)
    rates[5] = algebraic[2]*(1.00000-states[5])-algebraic[11]*states[5]
    algebraic[4] = 20.0000*exp(-0.125000*(states[0]+75.0000))
    algebraic[13] = 2000.00/(320.000*exp(-0.100000*(states[0]+75.0000))+1.00000)
    rates[8] = algebraic[4]*(1.00000-states[8])-algebraic[13]*states[8]
    algebraic[3] = states[0]+41.0000
    algebraic[12] = custom_piecewise([less(fabs(algebraic[3]) , constants[22]), 2000.00 , True, (200.000*algebraic[3])/(1.00000-exp(-0.100000*algebraic[3]))])
    algebraic[17] = 8000.00*exp(-0.0560000*(states[0]+66.0000))
    rates[7] = algebraic[12]*(1.00000-states[7])-algebraic[17]*states[7]
    algebraic[5] = (states[0]+24.0000)-5.00000
    algebraic[14] = custom_piecewise([less(fabs(algebraic[5]) , constants[24]), 120.000 , True, (30.0000*algebraic[5])/(1.00000-exp((-1.00000*algebraic[5])/4.00000))])
    algebraic[18] = custom_piecewise([less(fabs(algebraic[5]) , constants[24]), 120.000 , True, (12.0000*algebraic[5])/(exp(algebraic[5]/10.0000)-1.00000)])
    rates[9] = algebraic[14]*(1.00000-states[9])-algebraic[18]*states[9]
    algebraic[6] = states[0]+34.0000
    algebraic[15] = custom_piecewise([less(fabs(algebraic[6]) , constants[25]), 25.0000 , True, (6.25000*algebraic[6])/(exp(algebraic[6]/4.00000)-1.00000)])
    algebraic[19] = 50.0000/(1.00000+exp((-1.00000*(states[0]+34.0000))/4.00000))
    rates[10] = algebraic[15]*(1.00000-states[10])-algebraic[19]*states[10]
    algebraic[8] = (states[0]+34.0000)--30.0000
    algebraic[16] = (0.625000*algebraic[8])/(exp(algebraic[8]/4.00000)-1.00000)
    algebraic[21] = 5.00000/(1.00000+exp((-1.00000*algebraic[8])/4.00000))
    rates[14] = algebraic[16]*(1.00000-states[14])-algebraic[21]*states[14]
    algebraic[0] = constants[39]*log(constants[7]/states[3])
    algebraic[27] = constants[11]*(states[0]-algebraic[0])
    algebraic[30] = (((constants[14]*states[1])/(constants[15]+states[1]))*states[3])/(constants[16]+states[3])
    algebraic[31] = (constants[18]*(exp((constants[20]*(constants[17]-2.00000)*states[0])/constants[39])*(power(states[3], constants[17]))*constants[13]-exp(((constants[20]-1.00000)*(constants[17]-2.00000)*states[0])/constants[39])*(power(constants[7], constants[17]))*states[6]))/((1.00000+constants[19]*(states[6]*(power(constants[7], constants[17]))+constants[13]*(power(states[3], constants[17]))))*(1.00000+states[6]/0.00690000))
    algebraic[32] = constants[39]*log((constants[7]+0.120000*states[1])/(states[3]+0.120000*states[2]))
    algebraic[33] = constants[21]*(power(states[7], 3.00000))*states[8]*(states[0]-algebraic[32])
    algebraic[20] = (((power(states[4], 2.00000))*states[1])/(states[1]+constants[6]))*constants[4]*(states[0]-algebraic[0])
    algebraic[37] = ((0.0100000*constants[23]*(states[0]-50.0000))/(constants[39]*(1.00000-exp((-1.00000*(states[0]-50.0000))/constants[39]))))*(states[3]*exp(50.0000/constants[39])-constants[7]*exp((-1.00000*(states[0]-50.0000))/constants[39]))*states[9]*states[10]*states[11]
    rates[3] = (-1.00000*(algebraic[33]+algebraic[27]+algebraic[20]+algebraic[37]+algebraic[30]*3.00000+(algebraic[31]*constants[17])/(constants[17]-2.00000)))/(1.00000*constants[41]*constants[2])
    algebraic[36] = ((2.00000*1.00000*constants[41]*constants[2])/(1.00000*constants[33]*constants[31]))*states[6]*(constants[31]-states[12])
    algebraic[38] = ((2.00000*1.00000*constants[44]*constants[2])/(1.00000*constants[34]))*states[14]*(states[12]-states[13])
    rates[12] = (1.00000*(algebraic[36]-algebraic[38]))/(2.00000*1.00000*constants[43]*constants[2])
    algebraic[24] = (constants[8]*(states[2]-states[1]*exp(-states[0]/25.0000)))/140.000
    algebraic[25] = states[5]*algebraic[24]
    algebraic[9] = constants[39]*log(states[1]/states[2])
    algebraic[26] = (((constants[9]*states[1])/(states[1]+constants[10]))*(states[0]-algebraic[9]))/(1.00000+exp((((states[0]+10.0000)-algebraic[9])*2.00000)/constants[39]))
    algebraic[22] = (((power(states[4], 2.00000))*states[1])/(states[1]+constants[6]))*constants[5]*(states[0]-algebraic[9])
    algebraic[35] = ((0.0100000*constants[23]*(states[0]-50.0000))/(constants[39]*(1.00000-exp((-1.00000*(states[0]-50.0000))/constants[39]))))*(states[2]*exp(50.0000/constants[39])-states[1]*exp((-1.00000*(states[0]-50.0000))/constants[39]))*states[9]*states[10]*states[11]
    algebraic[39] = (algebraic[26]+algebraic[25]+algebraic[22]+algebraic[35])-2.00000*algebraic[30]
    rates[1] = -constants[38]*(states[1]-constants[37])+(1.00000*algebraic[39])/(1.00000*constants[42]*constants[2])
    rates[2] = (-1.00000*algebraic[39])/(1.00000*constants[41]*constants[2])
    algebraic[23] = algebraic[20]+algebraic[22]
    algebraic[28] = 0.500000*constants[39]*log(constants[13]/states[6])
    algebraic[29] = constants[12]*(states[0]-algebraic[28])
    algebraic[34] = ((4.00000*constants[23]*(states[0]-50.0000))/(constants[39]*(1.00000-exp((-1.00000*(states[0]-50.0000)*2.00000)/constants[39]))))*(states[6]*exp(100.000/constants[39])-constants[13]*exp((-2.00000*(states[0]-50.0000))/constants[39]))*states[9]*states[10]*states[11]
    algebraic[40] = algebraic[34]+algebraic[35]+algebraic[37]
    rates[0] = -(algebraic[23]+algebraic[25]+algebraic[26]+algebraic[27]+algebraic[29]+algebraic[30]+algebraic[31]+algebraic[33]+algebraic[40])/constants[3]
    algebraic[41] = (((2.00000*1.00000*constants[44]*constants[2])/(1.00000*constants[35]))*states[13]*(power(states[6], constants[36])))/(power(states[6], constants[36])+power(constants[32], constants[36]))
    rates[13] = (1.00000*(algebraic[38]-algebraic[41]))/(2.00000*1.00000*constants[44]*constants[2])
    rates[6] = (-1.00000*((((algebraic[34]+algebraic[29])-(2.00000*algebraic[31])/(constants[17]-2.00000))-algebraic[41])+algebraic[36]))/(2.00000*1.00000*constants[41]*constants[2])
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[7] = (states[6]*constants[26])/constants[27]
    algebraic[1] = 0.0200000*exp(-states[0]/18.0000)
    algebraic[10] = 19.5000*exp(states[0]/19.0000)
    algebraic[2] = 2.10000*exp(states[0]/28.0000)
    algebraic[11] = 0.960000*exp(-states[0]/24.0000)
    algebraic[4] = 20.0000*exp(-0.125000*(states[0]+75.0000))
    algebraic[13] = 2000.00/(320.000*exp(-0.100000*(states[0]+75.0000))+1.00000)
    algebraic[3] = states[0]+41.0000
    algebraic[12] = custom_piecewise([less(fabs(algebraic[3]) , constants[22]), 2000.00 , True, (200.000*algebraic[3])/(1.00000-exp(-0.100000*algebraic[3]))])
    algebraic[17] = 8000.00*exp(-0.0560000*(states[0]+66.0000))
    algebraic[5] = (states[0]+24.0000)-5.00000
    algebraic[14] = custom_piecewise([less(fabs(algebraic[5]) , constants[24]), 120.000 , True, (30.0000*algebraic[5])/(1.00000-exp((-1.00000*algebraic[5])/4.00000))])
    algebraic[18] = custom_piecewise([less(fabs(algebraic[5]) , constants[24]), 120.000 , True, (12.0000*algebraic[5])/(exp(algebraic[5]/10.0000)-1.00000)])
    algebraic[6] = states[0]+34.0000
    algebraic[15] = custom_piecewise([less(fabs(algebraic[6]) , constants[25]), 25.0000 , True, (6.25000*algebraic[6])/(exp(algebraic[6]/4.00000)-1.00000)])
    algebraic[19] = 50.0000/(1.00000+exp((-1.00000*(states[0]+34.0000))/4.00000))
    algebraic[8] = (states[0]+34.0000)--30.0000
    algebraic[16] = (0.625000*algebraic[8])/(exp(algebraic[8]/4.00000)-1.00000)
    algebraic[21] = 5.00000/(1.00000+exp((-1.00000*algebraic[8])/4.00000))
    algebraic[0] = constants[39]*log(constants[7]/states[3])
    algebraic[27] = constants[11]*(states[0]-algebraic[0])
    algebraic[30] = (((constants[14]*states[1])/(constants[15]+states[1]))*states[3])/(constants[16]+states[3])
    algebraic[31] = (constants[18]*(exp((constants[20]*(constants[17]-2.00000)*states[0])/constants[39])*(power(states[3], constants[17]))*constants[13]-exp(((constants[20]-1.00000)*(constants[17]-2.00000)*states[0])/constants[39])*(power(constants[7], constants[17]))*states[6]))/((1.00000+constants[19]*(states[6]*(power(constants[7], constants[17]))+constants[13]*(power(states[3], constants[17]))))*(1.00000+states[6]/0.00690000))
    algebraic[32] = constants[39]*log((constants[7]+0.120000*states[1])/(states[3]+0.120000*states[2]))
    algebraic[33] = constants[21]*(power(states[7], 3.00000))*states[8]*(states[0]-algebraic[32])
    algebraic[20] = (((power(states[4], 2.00000))*states[1])/(states[1]+constants[6]))*constants[4]*(states[0]-algebraic[0])
    algebraic[37] = ((0.0100000*constants[23]*(states[0]-50.0000))/(constants[39]*(1.00000-exp((-1.00000*(states[0]-50.0000))/constants[39]))))*(states[3]*exp(50.0000/constants[39])-constants[7]*exp((-1.00000*(states[0]-50.0000))/constants[39]))*states[9]*states[10]*states[11]
    algebraic[36] = ((2.00000*1.00000*constants[41]*constants[2])/(1.00000*constants[33]*constants[31]))*states[6]*(constants[31]-states[12])
    algebraic[38] = ((2.00000*1.00000*constants[44]*constants[2])/(1.00000*constants[34]))*states[14]*(states[12]-states[13])
    algebraic[24] = (constants[8]*(states[2]-states[1]*exp(-states[0]/25.0000)))/140.000
    algebraic[25] = states[5]*algebraic[24]
    algebraic[9] = constants[39]*log(states[1]/states[2])
    algebraic[26] = (((constants[9]*states[1])/(states[1]+constants[10]))*(states[0]-algebraic[9]))/(1.00000+exp((((states[0]+10.0000)-algebraic[9])*2.00000)/constants[39]))
    algebraic[22] = (((power(states[4], 2.00000))*states[1])/(states[1]+constants[6]))*constants[5]*(states[0]-algebraic[9])
    algebraic[35] = ((0.0100000*constants[23]*(states[0]-50.0000))/(constants[39]*(1.00000-exp((-1.00000*(states[0]-50.0000))/constants[39]))))*(states[2]*exp(50.0000/constants[39])-states[1]*exp((-1.00000*(states[0]-50.0000))/constants[39]))*states[9]*states[10]*states[11]
    algebraic[39] = (algebraic[26]+algebraic[25]+algebraic[22]+algebraic[35])-2.00000*algebraic[30]
    algebraic[23] = algebraic[20]+algebraic[22]
    algebraic[28] = 0.500000*constants[39]*log(constants[13]/states[6])
    algebraic[29] = constants[12]*(states[0]-algebraic[28])
    algebraic[34] = ((4.00000*constants[23]*(states[0]-50.0000))/(constants[39]*(1.00000-exp((-1.00000*(states[0]-50.0000)*2.00000)/constants[39]))))*(states[6]*exp(100.000/constants[39])-constants[13]*exp((-2.00000*(states[0]-50.0000))/constants[39]))*states[9]*states[10]*states[11]
    algebraic[40] = algebraic[34]+algebraic[35]+algebraic[37]
    algebraic[41] = (((2.00000*1.00000*constants[44]*constants[2])/(1.00000*constants[35]))*states[13]*(power(states[6], constants[36])))/(power(states[6], constants[36])+power(constants[32], constants[36]))
    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)