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 = 64
sizeStates = 19
sizeConstants = 73
from math import *
from numpy import *

def createLegends():
    legend_states = [""] * sizeStates
    legend_rates = [""] * sizeStates
    legend_algebraic = [""] * sizeAlgebraic
    legend_voi = ""
    legend_constants = [""] * sizeConstants
    legend_voi = "t in component environment (ms)"
    legend_constants[0] = "R in component environment (mJ_per_mole_kelvin)"
    legend_constants[1] = "T in component environment (kelvin)"
    legend_constants[2] = "F in component environment (coulomb_per_mole)"
    legend_constants[64] = "V_tau in component environment (mV)"
    legend_constants[3] = "Ca_o in component environment (mM)"
    legend_constants[4] = "Na_o in component environment (mM)"
    legend_constants[5] = "K_o in component environment (mM)"
    legend_constants[6] = "dia in component environment (cm)"
    legend_constants[61] = "vol_cyt in component environment (pl)"
    legend_constants[57] = "vol_pmu in component environment (pl)"
    legend_constants[7] = "fr_cyt in component environment (dimensionless)"
    legend_algebraic[0] = "V in component Membrane (mV)"
    legend_algebraic[1] = "VD in component Membrane (dimensionless)"
    legend_constants[8] = "C_sp in component Membrane (pF_per_sqcm)"
    legend_states[0] = "Ca_i in component Cytosol (mM)"
    legend_states[1] = "Na_i in component Cytosol (mM)"
    legend_states[2] = "K_i in component Cytosol (mM)"
    legend_constants[68] = "anoff in component Membrane (mM)"
    legend_algebraic[3] = "V_Ca in component Membrane (dimensionless)"
    legend_algebraic[5] = "V_Na in component Membrane (dimensionless)"
    legend_algebraic[7] = "V_K in component Membrane (dimensionless)"
    legend_constants[66] = "A_pmu in component Membrane (sqcm)"
    legend_constants[63] = "SVR_pmu in component Membrane (per_cm)"
    legend_constants[9] = "svr in component Membrane (dimensionless)"
    legend_constants[69] = "C_m in component Membrane (pF)"
    legend_constants[10] = "atp in component Cytosol (mM)"
    legend_algebraic[63] = "J_Ca in component calcium_dynamics (mM_per_ms)"
    legend_algebraic[62] = "J_Na in component sodium_dynamics (mM_per_ms)"
    legend_algebraic[45] = "J_K in component potassium_dynamics (mM_per_ms)"
    legend_algebraic[61] = "J_ca in component calcium_dynamics (mM_per_ms)"
    legend_algebraic[20] = "I_CaL in component L_type_Ca_channel (pA)"
    legend_algebraic[21] = "I_CaT in component T_type_Ca_channel (pA)"
    legend_algebraic[22] = "I_CaHVA in component HVA_Ca_channel (pA)"
    legend_algebraic[49] = "I_pmca in component PMCA (pA)"
    legend_algebraic[59] = "I_xm in component Membrane_NaCa (pA)"
    legend_algebraic[16] = "J_calb in component calcium_buffer_dynamics (mM_per_ms)"
    legend_algebraic[18] = "J_cam in component calcium_buffer_dynamics (mM_per_ms)"
    legend_algebraic[24] = "I_Na in component transient_Na_channel (pA)"
    legend_algebraic[25] = "I_Nalk in component Leak_Na_channel (pA)"
    legend_algebraic[26] = "I_NaHCN in component HCN_channel (pA)"
    legend_algebraic[42] = "I_nk in component sodium_pump (pA)"
    legend_algebraic[36] = "I_K in component potassium_dynamics (pA)"
    legend_algebraic[29] = "I_Ksk in component SK_K_channel (pA)"
    legend_algebraic[31] = "I_Kdr in component DR_K_channel (pA)"
    legend_algebraic[33] = "I_Ka in component Atype_K_channel (pA)"
    legend_algebraic[35] = "I_Kir in component IR_K_channel (pA)"
    legend_algebraic[27] = "I_KHCN in component HCN_channel (pA)"
    legend_states[3] = "Calb in component calcium_buffer_dynamics (mM)"
    legend_states[4] = "Cam in component calcium_buffer_dynamics (mM)"
    legend_constants[11] = "Calbtot in component calcium_buffer_dynamics (mM)"
    legend_constants[12] = "Camtot in component calcium_buffer_dynamics (mM)"
    legend_algebraic[15] = "CaCalb in component calcium_buffer_dynamics (mM)"
    legend_algebraic[17] = "CaCam in component calcium_buffer_dynamics (mM)"
    legend_constants[13] = "kcal_1 in component calcium_buffer_dynamics (per_mM_ms)"
    legend_constants[14] = "kcal_2 in component calcium_buffer_dynamics (per_ms)"
    legend_algebraic[9] = "kcam_cb in component calcium_buffer_dynamics (per_ms)"
    legend_constants[15] = "kcam_cd in component calcium_buffer_dynamics (per_ms)"
    legend_algebraic[11] = "kcam_nb in component calcium_buffer_dynamics (per_ms)"
    legend_constants[16] = "kcam_nd in component calcium_buffer_dynamics (per_ms)"
    legend_algebraic[13] = "alpha_cam in component calcium_buffer_dynamics (per_ms)"
    legend_algebraic[14] = "beta_cam in component calcium_buffer_dynamics (per_ms)"
    legend_states[5] = "m_cal in component L_type_Ca_channel (dimensionless)"
    legend_algebraic[19] = "h_cal in component L_type_Ca_channel (dimensionless)"
    legend_constants[17] = "g_cal in component L_type_Ca_channel (pA_per_mM)"
    legend_states[6] = "m_cat in component T_type_Ca_channel (dimensionless)"
    legend_states[7] = "h_cat in component T_type_Ca_channel (dimensionless)"
    legend_constants[18] = "g_cat in component T_type_Ca_channel (pA_per_mM)"
    legend_states[8] = "m_cah in component HVA_Ca_channel (dimensionless)"
    legend_states[9] = "h_cah in component HVA_Ca_channel (dimensionless)"
    legend_constants[19] = "g_cah in component HVA_Ca_channel (pA_per_mM)"
    legend_constants[20] = "g_na in component transient_Na_channel (pA_per_mM)"
    legend_algebraic[23] = "O_na in component transient_Na_channel (dimensionless)"
    legend_states[10] = "m_na in component transient_Na_channel (dimensionless)"
    legend_states[11] = "h_na in component transient_Na_channel (dimensionless)"
    legend_constants[21] = "A_mna in component transient_Na_channel (per_ms)"
    legend_constants[22] = "B_mna in component transient_Na_channel (per_ms)"
    legend_constants[23] = "A_hna in component transient_Na_channel (per_ms)"
    legend_constants[24] = "B_hna in component transient_Na_channel (per_ms)"
    legend_constants[25] = "za_mna in component transient_Na_channel (dimensionless)"
    legend_constants[26] = "zb_mna in component transient_Na_channel (dimensionless)"
    legend_constants[27] = "za_hna in component transient_Na_channel (dimensionless)"
    legend_constants[28] = "zb_hna in component transient_Na_channel (dimensionless)"
    legend_constants[29] = "g_nalk in component Leak_Na_channel (pA_per_mM)"
    legend_constants[30] = "g_nahcn in component HCN_channel (pA_per_mM)"
    legend_states[12] = "O_hcn in component HCN_channel (dimensionless)"
    legend_constants[31] = "g_khcn in component HCN_channel (pA_per_mM)"
    legend_algebraic[8] = "kf_hcn in component HCN_channel (per_ms)"
    legend_algebraic[12] = "kr_hcn in component HCN_channel (per_ms)"
    legend_algebraic[2] = "kf_free in component HCN_channel (per_ms)"
    legend_algebraic[4] = "kr_free in component HCN_channel (per_ms)"
    legend_algebraic[6] = "kf_bnd in component HCN_channel (per_ms)"
    legend_algebraic[10] = "kr_bnd in component HCN_channel (per_ms)"
    legend_constants[67] = "P_c in component HCN_channel (dimensionless)"
    legend_constants[70] = "P_o in component HCN_channel (dimensionless)"
    legend_constants[32] = "cAMP in component HCN_channel (mM)"
    legend_algebraic[28] = "O_sk in component SK_K_channel (dimensionless)"
    legend_constants[33] = "g_ksk in component SK_K_channel (pA_per_mM)"
    legend_algebraic[30] = "O_kdr in component DR_K_channel (dimensionless)"
    legend_states[13] = "m_kdr in component DR_K_channel (dimensionless)"
    legend_constants[34] = "g_kdr in component DR_K_channel (pA_per_mV)"
    legend_algebraic[32] = "O_ka in component Atype_K_channel (dimensionless)"
    legend_states[14] = "p_ka in component Atype_K_channel (dimensionless)"
    legend_states[15] = "q_ka in component Atype_K_channel (dimensionless)"
    legend_constants[35] = "g_ka in component Atype_K_channel (pA_per_mV)"
    legend_algebraic[34] = "O_kir in component IR_K_channel (dimensionless)"
    legend_constants[36] = "g_kir in component IR_K_channel (pA_per_mV)"
    legend_algebraic[37] = "Na_eff in component sodium_pump (mM)"
    legend_states[16] = "y_nk in component sodium_pump (dimensionless)"
    legend_algebraic[40] = "alpha_nk in component sodium_pump (per_ms)"
    legend_algebraic[46] = "beta_nk in component sodium_pump (per_ms)"
    legend_algebraic[38] = "P_E1Snk in component sodium_pump (dimensionless)"
    legend_algebraic[41] = "P_E2Snk in component sodium_pump (dimensionless)"
    legend_algebraic[39] = "P_E1Dnk in component sodium_pump (dimensionless)"
    legend_algebraic[43] = "P_E2Dnk in component sodium_pump (dimensionless)"
    legend_constants[58] = "k_1nk in component sodium_pump (per_ms)"
    legend_constants[37] = "k_2nk in component sodium_pump (per_ms)"
    legend_constants[38] = "k_3nk in component sodium_pump (per_ms)"
    legend_constants[39] = "k_4nk in component sodium_pump (per_ms)"
    legend_constants[40] = "K_nknai in component sodium_pump (mM)"
    legend_constants[41] = "K_nknao in component sodium_pump (mM)"
    legend_constants[42] = "K_nkki in component sodium_pump (mM)"
    legend_constants[43] = "K_nkko in component sodium_pump (mM)"
    legend_constants[44] = "k_nk in component sodium_pump (pA)"
    legend_states[17] = "y_pc in component PMCA (dimensionless)"
    legend_algebraic[44] = "K_pmca in component PMCA (pA)"
    legend_constants[59] = "k_1pc in component PMCA (per_ms)"
    legend_constants[45] = "k_2pc in component PMCA (per_ms)"
    legend_constants[46] = "k_3pc in component PMCA (per_ms)"
    legend_constants[47] = "k_4pc in component PMCA (per_ms)"
    legend_algebraic[48] = "P_E1Spc in component PMCA (dimensionless)"
    legend_constants[60] = "P_E2Spc in component PMCA (dimensionless)"
    legend_algebraic[50] = "P_E1pc in component PMCA (dimensionless)"
    legend_constants[62] = "P_E2pc in component PMCA (dimensionless)"
    legend_algebraic[52] = "alpha_pc in component PMCA (per_ms)"
    legend_constants[65] = "beta_pc in component PMCA (per_ms)"
    legend_algebraic[47] = "K_pci in component PMCA (mM)"
    legend_constants[48] = "K_pco in component PMCA (mM)"
    legend_constants[49] = "k_pmca in component PMCA (dimensionless)"
    legend_constants[72] = "P_E2Dxm in component Membrane_NaCa (dimensionless)"
    legend_algebraic[53] = "P_E1Dxm in component Membrane_NaCa (dimensionless)"
    legend_algebraic[51] = "P_E1Sxm in component Membrane_NaCa (dimensionless)"
    legend_constants[71] = "P_E2Sxm in component Membrane_NaCa (dimensionless)"
    legend_algebraic[54] = "k_1xm in component Membrane_NaCa (per_ms)"
    legend_algebraic[55] = "k_2xm in component Membrane_NaCa (per_ms)"
    legend_algebraic[56] = "k_3xm in component Membrane_NaCa (per_ms)"
    legend_algebraic[58] = "k_4xm in component Membrane_NaCa (per_ms)"
    legend_algebraic[60] = "beta_xm in component Membrane_NaCa (per_ms)"
    legend_algebraic[57] = "alpha_xm in component Membrane_NaCa (per_ms)"
    legend_constants[50] = "K_xmnai in component Membrane_NaCa (mM)"
    legend_constants[51] = "K_xmnao in component Membrane_NaCa (mM)"
    legend_constants[52] = "K_xmcai in component Membrane_NaCa (mM)"
    legend_constants[53] = "K_xmcao in component Membrane_NaCa (mM)"
    legend_constants[54] = "delta_xmca in component Membrane_NaCa (dimensionless)"
    legend_constants[55] = "delta_xmna in component Membrane_NaCa (dimensionless)"
    legend_states[18] = "y_xm in component Membrane_NaCa (dimensionless)"
    legend_constants[56] = "k_xm in component Membrane_NaCa (pA_ms)"
    legend_rates[0] = "d/dt Ca_i in component Cytosol (mM)"
    legend_rates[1] = "d/dt Na_i in component Cytosol (mM)"
    legend_rates[2] = "d/dt K_i in component Cytosol (mM)"
    legend_rates[3] = "d/dt Calb in component calcium_buffer_dynamics (mM)"
    legend_rates[4] = "d/dt Cam in component calcium_buffer_dynamics (mM)"
    legend_rates[5] = "d/dt m_cal in component L_type_Ca_channel (dimensionless)"
    legend_rates[6] = "d/dt m_cat in component T_type_Ca_channel (dimensionless)"
    legend_rates[7] = "d/dt h_cat in component T_type_Ca_channel (dimensionless)"
    legend_rates[8] = "d/dt m_cah in component HVA_Ca_channel (dimensionless)"
    legend_rates[9] = "d/dt h_cah in component HVA_Ca_channel (dimensionless)"
    legend_rates[10] = "d/dt m_na in component transient_Na_channel (dimensionless)"
    legend_rates[11] = "d/dt h_na in component transient_Na_channel (dimensionless)"
    legend_rates[12] = "d/dt O_hcn in component HCN_channel (dimensionless)"
    legend_rates[13] = "d/dt m_kdr in component DR_K_channel (dimensionless)"
    legend_rates[14] = "d/dt p_ka in component Atype_K_channel (dimensionless)"
    legend_rates[15] = "d/dt q_ka in component Atype_K_channel (dimensionless)"
    legend_rates[16] = "d/dt y_nk in component sodium_pump (dimensionless)"
    legend_rates[17] = "d/dt y_pc in component PMCA (dimensionless)"
    legend_rates[18] = "d/dt y_xm in component Membrane_NaCa (dimensionless)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    constants[0] = 8314.472
    constants[1] = 310.15
    constants[2] = 96485.30929
    constants[3] = 1.8
    constants[4] = 137
    constants[5] = 5.4
    constants[6] = 30e-4
    constants[7] = 1
    constants[8] = 0.9e6
    states[0] = 0.00015
    states[1] = 6
    states[2] = 140
    constants[9] = 6
    constants[10] = 2
    states[3] = 0.0011
    states[4] = 0.0487
    constants[11] = 0.002
    constants[12] = 0.0489
    constants[13] = 10
    constants[14] = 2e-3
    constants[15] = 0.003
    constants[16] = 3
    states[5] = 0.0004
    constants[17] = 1158.2
    states[6] = 0.1099
    states[7] = 0.5716
    constants[18] = 10
    states[8] = 0.3021
    states[9] = 0.454
    constants[19] = 78.5
    constants[20] = 395.14
    states[10] = 0.0758
    states[11] = 0.2272
    constants[21] = 1.9651
    constants[22] = 0.0424
    constants[23] = 9.566e-5
    constants[24] = 0.5296
    constants[25] = 1.7127
    constants[26] = 1.5581
    constants[27] = -2.4317
    constants[28] = -1.1868
    constants[29] = 0.0039
    constants[30] = 3
    states[12] = 0
    constants[31] = 10
    constants[32] = 1e-5
    constants[33] = 15
    states[13] = 0.0043
    constants[34] = 10
    states[14] = 0.2577
    states[15] = 0.827
    constants[35] = 0.2234
    constants[36] = 5
    states[16] = 0.555
    constants[37] = 0.04
    constants[38] = 0.01
    constants[39] = 0.165
    constants[40] = 4.05
    constants[41] = 69.8
    constants[42] = 32.88
    constants[43] = 0.258
    constants[44] = 200
    states[17] = 0.001
    constants[45] = 0.001
    constants[46] = 0.001
    constants[47] = 1
    constants[48] = 2
    constants[49] = 10
    constants[50] = 8.75
    constants[51] = 87.5
    constants[52] = 0.00138
    constants[53] = 1.38
    constants[54] = 0.68
    constants[55] = 0.32
    states[18] = 0.343
    constants[56] = 25
    constants[57] = ((( pi*(power(constants[6], 3.00000)))/6.00000)*1.00000e+09)/(1.00000*1.00000*1.00000)
    constants[58] = 0.370000/(1.00000+0.0940000/constants[10])
    constants[59] = 1.00000/(1.00000+0.100000/constants[10])
    constants[60] = 1.00000/(1.00000+constants[48]/constants[3])
    constants[61] = constants[7]*constants[57]
    constants[62] = 1.00000-constants[60]
    constants[63] = constants[9]/constants[6]
    constants[64] = (constants[0]*constants[1])/constants[2]
    constants[65] = constants[45]*constants[60]+constants[47]*constants[62]
    constants[66] = (constants[63]*constants[57]*0.00100000*0.00100000*0.00100000)/1.00000
    constants[67] = 1.00000/(1.00000+constants[32]/0.00116300)
    constants[68] = (((-52.3100*constants[8]*constants[66])/(constants[2]*constants[61])-2.00000*(0.000150000-constants[3]))-(6.00000-constants[4]))-(140.000-constants[5])
    constants[69] = constants[8]*constants[66]
    constants[70] = 1.00000/(1.00000+constants[32]/1.45000e-05)
    constants[71] = 1.00000/(1.00000+(constants[53]/constants[3])*(1.00000+power(constants[4]/constants[51], 3.00000)))
    constants[72] = 1.00000/(1.00000+(power(constants[51]/constants[4], 3.00000))*(1.00000+constants[3]/constants[53]))
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    algebraic[0] = ((constants[2]*constants[61])/(constants[8]*constants[66]))*((((states[2]-constants[5])+2.00000*(states[0]-constants[3])+states[1])-constants[4])+constants[68])
    rates[5] = (1.00000/(1.00000+exp(-(algebraic[0]+15.0000)/7.00000))-states[5])/(10.0000*exp(-(power((algebraic[0]+86.4000)/23.2000, 2.00000)))+0.943000)
    rates[6] = (1.00000/(1.00000+exp(-(algebraic[0]+63.0000)/1.50000))-states[6])/(65.0000*exp(-(power((algebraic[0]+68.0000)/6.00000, 2.00000)))+12.0000)
    rates[7] = (1.00000/(1.00000+exp((algebraic[0]+76.2000)/3.00000))-states[7])/(50.0000*exp(-(power((algebraic[0]+72.0000)/10.0000, 2.00000)))+10.0000)
    rates[8] = (1.00000/(1.00000+exp(-(algebraic[0]+10.0000)/10.0000))-states[8])/(0.100000*exp(-(power((algebraic[0]+62.0000)/13.0000, 2.00000)))+0.0500000)
    rates[9] = (1.00000/(1.00000+exp((algebraic[0]+48.0000)/5.00000))-states[9])/(0.500000*exp(-(power((algebraic[0]+55.6000)/18.0000, 2.00000)))+0.500000)
    rates[13] = (1.00000/(1.00000+exp(-(algebraic[0]+25.0000)/12.0000))-states[13])/(18.0000/(1.00000+exp((algebraic[0]+39.0000)/8.00000))+1.00000)
    rates[14] = (1.00000/(1.00000+exp(-(algebraic[0]+43.0000)/24.0000))-states[14])/(2.00000*exp(-(power((algebraic[0]+50.0000)/23.4500, 2.00000)))+1.10000)
    rates[15] = (1.00000/(1.00000+exp((algebraic[0]+56.0000)/8.00000))-states[15])/20.0000
    algebraic[1] = algebraic[0]/constants[64]
    rates[10] = constants[21]*exp(constants[25]*algebraic[1])*(1.00000-states[10])-constants[22]*exp(-constants[26]*algebraic[1])*states[10]
    rates[11] = constants[23]*exp(constants[27]*algebraic[1])*(1.00000-states[11])-constants[24]*exp(-constants[28]*algebraic[1])*states[11]
    algebraic[2] = 0.00600000/(1.00000+exp((algebraic[0]+87.7000)/6.45000))
    algebraic[6] = 0.0268000/(1.00000+exp((algebraic[0]+94.2000)/13.3000))
    algebraic[8] = algebraic[2]*constants[67]+algebraic[6]*(1.00000-constants[67])
    algebraic[4] = 0.0800000/(1.00000+exp(-(algebraic[0]+51.7000)/7.00000))
    algebraic[10] = 0.0800000/(1.00000+exp(-(algebraic[0]+35.5000)/7.00000))
    algebraic[12] = algebraic[4]*constants[70]+algebraic[10]*(1.00000-constants[70])
    rates[12] = algebraic[8]*(1.00000-states[12])-algebraic[12]*states[12]
    algebraic[15] = constants[11]-states[3]
    algebraic[16] = constants[13]*states[3]*states[0]-constants[14]*algebraic[15]
    rates[3] = -algebraic[16]
    algebraic[17] = constants[12]-states[4]
    algebraic[9] = 12000.0*(power(states[0], 2.00000))
    algebraic[11] = 3.70000e+06*(power(states[0], 2.00000))
    algebraic[13] = algebraic[9]*algebraic[11]*(1.00000/(algebraic[9]+constants[16])+1.00000/(constants[15]+constants[16]))
    algebraic[14] = constants[15]*constants[16]*(1.00000/(algebraic[9]+constants[16])+1.00000/(constants[15]+constants[16]))
    algebraic[18] = algebraic[13]*states[4]-algebraic[14]*algebraic[17]
    rates[4] = -algebraic[18]
    algebraic[38] = 1.00000/(1.00000+(constants[40]/states[1])*(1.00000+states[2]/constants[42]))
    algebraic[37] = constants[4]*exp(-0.820000*algebraic[1])
    algebraic[41] = 1.00000/(1.00000+(constants[41]/algebraic[37])*(1.00000+constants[5]/constants[43]))
    algebraic[42] = constants[44]*(constants[58]*algebraic[38]*states[16]-constants[37]*algebraic[41]*(1.00000-states[16]))*1.00000
    algebraic[7] = log(constants[5]/states[2])
    algebraic[28] = (power(states[0], 4.20000))/(power(0.000350000, 4.20000)+power(states[0], 4.20000))
    algebraic[29] = (constants[33]*algebraic[28]*(power(states[2]*constants[5], 1.0/2))*sinh(0.500000*(algebraic[1]-algebraic[7])))/(sinh(0.500000*algebraic[1])/(0.500000*algebraic[1]))
    algebraic[30] = power(states[13], 3.00000)
    algebraic[31] = constants[34]*algebraic[30]*(algebraic[0]-algebraic[7]*constants[64])
    algebraic[32] = (power(states[14], 3.00000))*states[15]
    algebraic[33] = constants[35]*algebraic[32]*(algebraic[0]-algebraic[7]*constants[64])
    algebraic[34] = 1.00000/(1.00000+exp((algebraic[0]+90.0000)/12.1000))
    algebraic[35] = constants[36]*algebraic[34]*(algebraic[0]-algebraic[7]*constants[64])
    algebraic[27] = (constants[31]*states[12]*(power(states[2]*constants[5], 1.0/2))*sinh(0.500000*(algebraic[1]-algebraic[7])))/(sinh(0.500000*algebraic[1])/(0.500000*algebraic[1]))
    algebraic[36] = algebraic[29]+algebraic[27]+algebraic[33]+algebraic[31]+algebraic[35]
    algebraic[45] = (-1.00000/(constants[2]*constants[61]))*(algebraic[36]-2.00000*algebraic[42])
    rates[2] = algebraic[45]
    algebraic[39] = 1.00000/(1.00000+(constants[42]/states[2])*(1.00000+states[1]/constants[40]))
    algebraic[40] = constants[58]*algebraic[38]+constants[38]*algebraic[39]
    algebraic[43] = 1.00000/(1.00000+(constants[43]/constants[5])*(1.00000+algebraic[37]/constants[41]))
    algebraic[46] = constants[37]*algebraic[41]+constants[39]*algebraic[43]
    rates[16] = algebraic[46]*(1.00000-states[16])-algebraic[40]*states[16]
    algebraic[47] = (173.600/(1.00000+algebraic[17]/5.00000e-05)+6.40000)*1.00000e-05
    algebraic[48] = 1.00000/(1.00000+algebraic[47]/states[0])
    algebraic[50] = 1.00000-algebraic[48]
    algebraic[52] = constants[59]*algebraic[48]+constants[46]*algebraic[50]
    rates[17] = constants[65]*(1.00000-states[17])-algebraic[52]*states[17]
    algebraic[55] = 1.00000*exp((1.00000-constants[54])*algebraic[1])
    algebraic[58] = 1.00000*exp(-constants[55]*algebraic[1])
    algebraic[60] = algebraic[55]*constants[71]+algebraic[58]*constants[72]
    algebraic[53] = 1.00000/(1.00000+(power(constants[50]/states[1], 3.00000))*(1.00000+states[0]/constants[52]))
    algebraic[51] = 1.00000/(1.00000+(constants[52]/states[0])*(1.00000+power(states[1]/constants[50], 3.00000)))
    algebraic[54] = 1.00000*exp(-constants[54]*algebraic[1])
    algebraic[56] = 1.00000*exp((1.00000-constants[55])*algebraic[1])
    algebraic[57] = algebraic[54]*algebraic[51]+algebraic[56]*algebraic[53]
    rates[18] = algebraic[60]*(1.00000-states[18])-algebraic[57]*states[18]
    algebraic[59] = constants[56]*(algebraic[56]*algebraic[53]*states[18]-algebraic[58]*constants[72]*(1.00000-states[18]))
    algebraic[5] = log(constants[4]/states[1])
    algebraic[23] = (power(states[10], 3.00000))*states[11]
    algebraic[24] = (constants[20]*algebraic[23]*(power(states[1]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[1]-algebraic[5])))/(sinh(0.500000*algebraic[1])/(0.500000*algebraic[1]))
    algebraic[25] = (constants[29]*(power(states[1]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[1]-algebraic[5])))/(sinh(0.500000*algebraic[1])/(0.500000*algebraic[1]))
    algebraic[26] = (constants[30]*states[12]*(power(states[1]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[1]-algebraic[5])))/(sinh(0.500000*algebraic[1])/(0.500000*algebraic[1]))
    algebraic[62] = (-1.00000/(constants[2]*constants[61]))*(3.00000*algebraic[42]+3.00000*algebraic[59]+algebraic[24]+algebraic[25]+algebraic[26])
    rates[1] = algebraic[62]
    algebraic[3] = 0.500000*log(constants[3]/states[0])
    algebraic[19] = 0.000450000/(0.000450000+states[0])
    algebraic[20] = (constants[17]*states[5]*algebraic[19]*(power(states[0]*constants[3], 1.0/2))*sinh(algebraic[1]-algebraic[3]))/(sinh(algebraic[1])/algebraic[1])
    algebraic[21] = (constants[18]*states[6]*states[7]*(power(states[0]*constants[3], 1.0/2))*sinh(algebraic[1]-algebraic[3]))/(sinh(algebraic[1])/algebraic[1])
    algebraic[22] = (constants[19]*states[8]*states[9]*(power(states[0]*constants[3], 1.0/2))*sinh(algebraic[1]-algebraic[3]))/(sinh(algebraic[1])/algebraic[1])
    algebraic[44] = constants[49]*((10.5600*algebraic[17])/(algebraic[17]+5.00000e-05)+1.20000)
    algebraic[49] = algebraic[44]*(constants[59]*algebraic[48]*states[17]-constants[45]*constants[60]*(1.00000-states[17]))*1.00000
    algebraic[61] = (-1.00000/(2.00000*constants[2]*constants[61]))*((algebraic[20]+algebraic[21]+algebraic[22]+2.00000*algebraic[49])-2.00000*algebraic[59])
    algebraic[63] = algebraic[61]-(algebraic[16]+4.00000*algebraic[18])
    rates[0] = algebraic[63]
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[0] = ((constants[2]*constants[61])/(constants[8]*constants[66]))*((((states[2]-constants[5])+2.00000*(states[0]-constants[3])+states[1])-constants[4])+constants[68])
    algebraic[1] = algebraic[0]/constants[64]
    algebraic[2] = 0.00600000/(1.00000+exp((algebraic[0]+87.7000)/6.45000))
    algebraic[6] = 0.0268000/(1.00000+exp((algebraic[0]+94.2000)/13.3000))
    algebraic[8] = algebraic[2]*constants[67]+algebraic[6]*(1.00000-constants[67])
    algebraic[4] = 0.0800000/(1.00000+exp(-(algebraic[0]+51.7000)/7.00000))
    algebraic[10] = 0.0800000/(1.00000+exp(-(algebraic[0]+35.5000)/7.00000))
    algebraic[12] = algebraic[4]*constants[70]+algebraic[10]*(1.00000-constants[70])
    algebraic[15] = constants[11]-states[3]
    algebraic[16] = constants[13]*states[3]*states[0]-constants[14]*algebraic[15]
    algebraic[17] = constants[12]-states[4]
    algebraic[9] = 12000.0*(power(states[0], 2.00000))
    algebraic[11] = 3.70000e+06*(power(states[0], 2.00000))
    algebraic[13] = algebraic[9]*algebraic[11]*(1.00000/(algebraic[9]+constants[16])+1.00000/(constants[15]+constants[16]))
    algebraic[14] = constants[15]*constants[16]*(1.00000/(algebraic[9]+constants[16])+1.00000/(constants[15]+constants[16]))
    algebraic[18] = algebraic[13]*states[4]-algebraic[14]*algebraic[17]
    algebraic[38] = 1.00000/(1.00000+(constants[40]/states[1])*(1.00000+states[2]/constants[42]))
    algebraic[37] = constants[4]*exp(-0.820000*algebraic[1])
    algebraic[41] = 1.00000/(1.00000+(constants[41]/algebraic[37])*(1.00000+constants[5]/constants[43]))
    algebraic[42] = constants[44]*(constants[58]*algebraic[38]*states[16]-constants[37]*algebraic[41]*(1.00000-states[16]))*1.00000
    algebraic[7] = log(constants[5]/states[2])
    algebraic[28] = (power(states[0], 4.20000))/(power(0.000350000, 4.20000)+power(states[0], 4.20000))
    algebraic[29] = (constants[33]*algebraic[28]*(power(states[2]*constants[5], 1.0/2))*sinh(0.500000*(algebraic[1]-algebraic[7])))/(sinh(0.500000*algebraic[1])/(0.500000*algebraic[1]))
    algebraic[30] = power(states[13], 3.00000)
    algebraic[31] = constants[34]*algebraic[30]*(algebraic[0]-algebraic[7]*constants[64])
    algebraic[32] = (power(states[14], 3.00000))*states[15]
    algebraic[33] = constants[35]*algebraic[32]*(algebraic[0]-algebraic[7]*constants[64])
    algebraic[34] = 1.00000/(1.00000+exp((algebraic[0]+90.0000)/12.1000))
    algebraic[35] = constants[36]*algebraic[34]*(algebraic[0]-algebraic[7]*constants[64])
    algebraic[27] = (constants[31]*states[12]*(power(states[2]*constants[5], 1.0/2))*sinh(0.500000*(algebraic[1]-algebraic[7])))/(sinh(0.500000*algebraic[1])/(0.500000*algebraic[1]))
    algebraic[36] = algebraic[29]+algebraic[27]+algebraic[33]+algebraic[31]+algebraic[35]
    algebraic[45] = (-1.00000/(constants[2]*constants[61]))*(algebraic[36]-2.00000*algebraic[42])
    algebraic[39] = 1.00000/(1.00000+(constants[42]/states[2])*(1.00000+states[1]/constants[40]))
    algebraic[40] = constants[58]*algebraic[38]+constants[38]*algebraic[39]
    algebraic[43] = 1.00000/(1.00000+(constants[43]/constants[5])*(1.00000+algebraic[37]/constants[41]))
    algebraic[46] = constants[37]*algebraic[41]+constants[39]*algebraic[43]
    algebraic[47] = (173.600/(1.00000+algebraic[17]/5.00000e-05)+6.40000)*1.00000e-05
    algebraic[48] = 1.00000/(1.00000+algebraic[47]/states[0])
    algebraic[50] = 1.00000-algebraic[48]
    algebraic[52] = constants[59]*algebraic[48]+constants[46]*algebraic[50]
    algebraic[55] = 1.00000*exp((1.00000-constants[54])*algebraic[1])
    algebraic[58] = 1.00000*exp(-constants[55]*algebraic[1])
    algebraic[60] = algebraic[55]*constants[71]+algebraic[58]*constants[72]
    algebraic[53] = 1.00000/(1.00000+(power(constants[50]/states[1], 3.00000))*(1.00000+states[0]/constants[52]))
    algebraic[51] = 1.00000/(1.00000+(constants[52]/states[0])*(1.00000+power(states[1]/constants[50], 3.00000)))
    algebraic[54] = 1.00000*exp(-constants[54]*algebraic[1])
    algebraic[56] = 1.00000*exp((1.00000-constants[55])*algebraic[1])
    algebraic[57] = algebraic[54]*algebraic[51]+algebraic[56]*algebraic[53]
    algebraic[59] = constants[56]*(algebraic[56]*algebraic[53]*states[18]-algebraic[58]*constants[72]*(1.00000-states[18]))
    algebraic[5] = log(constants[4]/states[1])
    algebraic[23] = (power(states[10], 3.00000))*states[11]
    algebraic[24] = (constants[20]*algebraic[23]*(power(states[1]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[1]-algebraic[5])))/(sinh(0.500000*algebraic[1])/(0.500000*algebraic[1]))
    algebraic[25] = (constants[29]*(power(states[1]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[1]-algebraic[5])))/(sinh(0.500000*algebraic[1])/(0.500000*algebraic[1]))
    algebraic[26] = (constants[30]*states[12]*(power(states[1]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[1]-algebraic[5])))/(sinh(0.500000*algebraic[1])/(0.500000*algebraic[1]))
    algebraic[62] = (-1.00000/(constants[2]*constants[61]))*(3.00000*algebraic[42]+3.00000*algebraic[59]+algebraic[24]+algebraic[25]+algebraic[26])
    algebraic[3] = 0.500000*log(constants[3]/states[0])
    algebraic[19] = 0.000450000/(0.000450000+states[0])
    algebraic[20] = (constants[17]*states[5]*algebraic[19]*(power(states[0]*constants[3], 1.0/2))*sinh(algebraic[1]-algebraic[3]))/(sinh(algebraic[1])/algebraic[1])
    algebraic[21] = (constants[18]*states[6]*states[7]*(power(states[0]*constants[3], 1.0/2))*sinh(algebraic[1]-algebraic[3]))/(sinh(algebraic[1])/algebraic[1])
    algebraic[22] = (constants[19]*states[8]*states[9]*(power(states[0]*constants[3], 1.0/2))*sinh(algebraic[1]-algebraic[3]))/(sinh(algebraic[1])/algebraic[1])
    algebraic[44] = constants[49]*((10.5600*algebraic[17])/(algebraic[17]+5.00000e-05)+1.20000)
    algebraic[49] = algebraic[44]*(constants[59]*algebraic[48]*states[17]-constants[45]*constants[60]*(1.00000-states[17]))*1.00000
    algebraic[61] = (-1.00000/(2.00000*constants[2]*constants[61]))*((algebraic[20]+algebraic[21]+algebraic[22]+2.00000*algebraic[49])-2.00000*algebraic[59])
    algebraic[63] = algebraic[61]-(algebraic[16]+4.00000*algebraic[18])
    return algebraic

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)