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 = 51
sizeStates = 13
sizeConstants = 58
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[48] = "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[49] = "vol_cyt in component environment (pl)"
legend_constants[6] = "vol_pmu in component environment (pl)"
legend_constants[7] = "fr_cyt in component environment (dimensionless)"
legend_states[0] = "V in component Membrane (mV)"
legend_algebraic[0] = "VD in component Membrane (dimensionless)"
legend_constants[8] = "C_sp in component Membrane (pF_per_sqcm)"
legend_states[1] = "Ca_i in component Cytosol (mM)"
legend_states[2] = "Na_i in component Cytosol (mM)"
legend_states[3] = "K_i in component Cytosol (mM)"
legend_algebraic[2] = "V_Ca in component Membrane (dimensionless)"
legend_algebraic[4] = "V_Na in component Membrane (dimensionless)"
legend_algebraic[6] = "V_K in component Membrane (dimensionless)"
legend_constants[55] = "A_pmu in component Membrane (sqcm)"
legend_constants[9] = "SVR_pmu in component Membrane (per_cm)"
legend_algebraic[40] = "J_Ca in component calcium_dynamics (mM_per_ms)"
legend_algebraic[48] = "J_Na in component sodium_dynamics (mM_per_ms)"
legend_algebraic[50] = "J_K in component potassium_dynamics (mM_per_ms)"
legend_constants[10] = "atp in component Cytosol (mM)"
legend_algebraic[39] = "J_ca in component calcium_dynamics (mM_per_ms)"
legend_algebraic[19] = "I_CaL in component L_type_Ca_channel (pA)"
legend_algebraic[34] = "I_pmca in component PMCA (pA)"
legend_algebraic[38] = "I_xm in component NaCa (pA)"
legend_algebraic[15] = "J_calb in component calcium_buffer_dynamics (mM_per_ms)"
legend_algebraic[17] = "J_cam in component calcium_buffer_dynamics (mM_per_ms)"
legend_algebraic[21] = "I_Na in component transient_Na_channel (pA)"
legend_algebraic[22] = "I_Nalk in component Leak_Na_channel (pA)"
legend_algebraic[23] = "I_NaHCN in component HCN_channel (pA)"
legend_algebraic[46] = "I_nk in component sodium_pump (pA)"
legend_algebraic[30] = "I_K in component potassium_dynamics (pA)"
legend_algebraic[25] = "I_Ksk in component SK_K_channel (pA)"
legend_algebraic[27] = "I_Kdr in component DR_K_channel (pA)"
legend_algebraic[29] = "I_Kir in component IR_K_channel (pA)"
legend_states[4] = "Calb in component calcium_buffer_dynamics (mM)"
legend_states[5] = "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[14] = "CaCalb in component calcium_buffer_dynamics (mM)"
legend_algebraic[16] = "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[8] = "kcam_cb in component calcium_buffer_dynamics (per_ms)"
legend_constants[15] = "kcam_cd in component calcium_buffer_dynamics (per_ms)"
legend_algebraic[10] = "kcam_nb in component calcium_buffer_dynamics (per_ms)"
legend_constants[16] = "kcam_nd in component calcium_buffer_dynamics (per_ms)"
legend_algebraic[12] = "alpha_cam in component calcium_buffer_dynamics (per_ms)"
legend_algebraic[13] = "beta_cam in component calcium_buffer_dynamics (per_ms)"
legend_states[6] = "m_cal in component L_type_Ca_channel (dimensionless)"
legend_algebraic[18] = "h_cal in component L_type_Ca_channel (dimensionless)"
legend_constants[17] = "g_cal in component L_type_Ca_channel (pA_per_mM)"
legend_constants[18] = "g_na in component transient_Na_channel (pA_per_mM)"
legend_algebraic[20] = "O_na in component transient_Na_channel (dimensionless)"
legend_states[7] = "m_na in component transient_Na_channel (dimensionless)"
legend_states[8] = "h_na in component transient_Na_channel (dimensionless)"
legend_constants[19] = "A_mna in component transient_Na_channel (per_ms)"
legend_constants[20] = "B_mna in component transient_Na_channel (per_ms)"
legend_constants[21] = "A_hna in component transient_Na_channel (per_ms)"
legend_constants[22] = "B_hna in component transient_Na_channel (per_ms)"
legend_constants[23] = "za_mna in component transient_Na_channel (dimensionless)"
legend_constants[24] = "zb_mna in component transient_Na_channel (dimensionless)"
legend_constants[25] = "za_hna in component transient_Na_channel (dimensionless)"
legend_constants[26] = "zb_hna in component transient_Na_channel (dimensionless)"
legend_constants[27] = "g_nalk in component Leak_Na_channel (pA_per_mM)"
legend_constants[28] = "g_nahcn in component HCN_channel (pA_per_mM)"
legend_states[9] = "O_hcn in component HCN_channel (dimensionless)"
legend_algebraic[7] = "kf_hcn in component HCN_channel (per_ms)"
legend_algebraic[11] = "kr_hcn in component HCN_channel (per_ms)"
legend_algebraic[1] = "kf_free in component HCN_channel (per_ms)"
legend_algebraic[3] = "kr_free in component HCN_channel (per_ms)"
legend_algebraic[5] = "kf_bnd in component HCN_channel (per_ms)"
legend_algebraic[9] = "kr_bnd in component HCN_channel (per_ms)"
legend_constants[50] = "P_c in component HCN_channel (dimensionless)"
legend_constants[51] = "P_o in component HCN_channel (dimensionless)"
legend_constants[29] = "cAMP in component HCN_channel (mM)"
legend_algebraic[24] = "O_sk in component SK_K_channel (dimensionless)"
legend_constants[30] = "g_ksk in component SK_K_channel (pA_per_mM)"
legend_algebraic[26] = "O_kdr in component DR_K_channel (dimensionless)"
legend_states[10] = "m_kdr in component DR_K_channel (dimensionless)"
legend_constants[31] = "g_kdr in component DR_K_channel (nS)"
legend_algebraic[28] = "O_kir in component IR_K_channel (dimensionless)"
legend_constants[32] = "g_kir in component IR_K_channel (nS)"
legend_states[11] = "y_pc in component PMCA (dimensionless)"
legend_algebraic[31] = "K_pmca in component PMCA (pA)"
legend_constants[52] = "k_1pc in component PMCA (per_ms)"
legend_constants[33] = "k_2pc in component PMCA (per_ms)"
legend_constants[34] = "k_3pc in component PMCA (per_ms)"
legend_constants[35] = "k_4pc in component PMCA (per_ms)"
legend_algebraic[33] = "P_E1Spc in component PMCA (dimensionless)"
legend_constants[53] = "P_E2Spc in component PMCA (dimensionless)"
legend_algebraic[35] = "P_E1pc in component PMCA (dimensionless)"
legend_constants[56] = "P_E2pc in component PMCA (dimensionless)"
legend_algebraic[37] = "alpha_pc in component PMCA (per_ms)"
legend_constants[57] = "beta_pc in component PMCA (per_ms)"
legend_algebraic[32] = "K_pci in component PMCA (mM)"
legend_constants[36] = "K_pco in component PMCA (mM)"
legend_constants[37] = "k_pmca in component PMCA (dimensionless)"
legend_constants[38] = "del in component NaCa (dimensionless)"
legend_constants[39] = "k_xm in component NaCa (pA)"
legend_algebraic[36] = "Dr in component NaCa (mM4)"
legend_algebraic[41] = "Na_eff in component sodium_pump (mM)"
legend_states[12] = "y_nk in component sodium_pump (dimensionless)"
legend_algebraic[44] = "alpha_nk in component sodium_pump (per_ms)"
legend_algebraic[49] = "beta_nk in component sodium_pump (per_ms)"
legend_algebraic[42] = "P_E1Snk in component sodium_pump (dimensionless)"
legend_algebraic[45] = "P_E2Snk in component sodium_pump (dimensionless)"
legend_algebraic[43] = "P_E1Dnk in component sodium_pump (dimensionless)"
legend_algebraic[47] = "P_E2Dnk in component sodium_pump (dimensionless)"
legend_constants[54] = "k_1nk in component sodium_pump (per_ms)"
legend_constants[40] = "k_2nk in component sodium_pump (per_ms)"
legend_constants[41] = "k_3nk in component sodium_pump (per_ms)"
legend_constants[42] = "k_4nk in component sodium_pump (per_ms)"
legend_constants[43] = "K_nknai in component sodium_pump (mM)"
legend_constants[44] = "K_nknao in component sodium_pump (mM)"
legend_constants[45] = "K_nkki in component sodium_pump (mM)"
legend_constants[46] = "K_nkko in component sodium_pump (mM)"
legend_constants[47] = "k_nk in component sodium_pump (pA)"
legend_rates[0] = "d/dt V in component Membrane (mV)"
legend_rates[1] = "d/dt Ca_i in component Cytosol (mM)"
legend_rates[2] = "d/dt Na_i in component Cytosol (mM)"
legend_rates[3] = "d/dt K_i in component Cytosol (mM)"
legend_rates[4] = "d/dt Calb in component calcium_buffer_dynamics (mM)"
legend_rates[5] = "d/dt Cam in component calcium_buffer_dynamics (mM)"
legend_rates[6] = "d/dt m_cal in component L_type_Ca_channel (dimensionless)"
legend_rates[7] = "d/dt m_na in component transient_Na_channel (dimensionless)"
legend_rates[8] = "d/dt h_na in component transient_Na_channel (dimensionless)"
legend_rates[9] = "d/dt O_hcn in component HCN_channel (dimensionless)"
legend_rates[10] = "d/dt m_kdr in component DR_K_channel (dimensionless)"
legend_rates[11] = "d/dt y_pc in component PMCA (dimensionless)"
legend_rates[12] = "d/dt y_nk in component sodium_pump (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] = 5
constants[7] = 0.5
states[0] = -49.42
constants[8] = 0.9e6
states[1] = 0.000188
states[2] = 4.6876
states[3] = 126.05893
constants[9] = 1.6667e4
constants[10] = 2
states[4] = 0.0026
states[5] = 0.0222
constants[11] = 0.005
constants[12] = 0.0235
constants[13] = 10
constants[14] = 2e-3
constants[15] = 0.003
constants[16] = 3
states[6] = 0.006271
constants[17] = 2101.2
constants[18] = 907.68
states[7] = 0.0952
states[8] = 0.1848
constants[19] = 1.9651
constants[20] = 0.0424
constants[21] = 9.566e-5
constants[22] = 0.5296
constants[23] = 1.7127
constants[24] = 1.5581
constants[25] = -2.4317
constants[26] = -1.1868
constants[27] = 0.0053
constants[28] = 51.1
states[9] = 0.003
constants[29] = 1e-5
constants[30] = 2.2515
states[10] = 0.0932
constants[31] = 31.237
constants[32] = 13.816
states[11] = 0.483
constants[33] = 0.001
constants[34] = 0.001
constants[35] = 1
constants[36] = 2
constants[37] = 2.233
constants[38] = 0.35
constants[39] = 0.0166
states[12] = 0.6213
constants[40] = 0.04
constants[41] = 0.01
constants[42] = 0.165
constants[43] = 4.05
constants[44] = 69.8
constants[45] = 32.88
constants[46] = 0.258
constants[47] = 1085.7
constants[48] = (constants[0]*constants[1])/constants[2]
constants[49] = constants[7]*constants[6]
constants[50] = 1.00000/(1.00000+constants[29]/0.00116300)
constants[51] = 1.00000/(1.00000+constants[29]/1.45000e-05)
constants[52] = 1.00000/(1.00000+0.100000/constants[10])
constants[53] = 1.00000/(1.00000+constants[36]/constants[3])
constants[54] = 0.370000/(1.00000+0.0940000/constants[10])
constants[55] = (constants[9]*constants[6]*0.00100000*0.00100000*0.00100000)/1.00000
constants[56] = 1.00000-constants[53]
constants[57] = constants[33]*constants[53]+constants[35]*constants[56]
return (states, constants)
def computeRates(voi, states, constants):
rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
rates[6] = (1.00000/(1.00000+exp(-(states[0]+15.0000)/7.00000))-states[6])/(7.68000*exp(-(power((states[0]+65.0000)/17.3300, 2.00000)))+0.723100)
rates[10] = (1.00000/(1.00000+exp(-(states[0]+25.0000)/12.0000))-states[10])/(18.0000/(1.00000+exp((states[0]+39.0000)/8.00000))+1.00000)
algebraic[0] = states[0]/constants[48]
rates[7] = constants[19]*exp(constants[23]*algebraic[0])*(1.00000-states[7])-constants[20]*exp(-constants[24]*algebraic[0])*states[7]
rates[8] = constants[21]*exp(constants[25]*algebraic[0])*(1.00000-states[8])-constants[22]*exp(-constants[26]*algebraic[0])*states[8]
algebraic[1] = 0.00600000/(1.00000+exp((states[0]+87.7000)/6.45000))
algebraic[5] = 0.0268000/(1.00000+exp((states[0]+94.2000)/13.3000))
algebraic[7] = algebraic[1]*constants[50]+algebraic[5]*(1.00000-constants[50])
algebraic[3] = 0.0800000/(1.00000+exp(-(states[0]+51.7000)/7.00000))
algebraic[9] = 0.0800000/(1.00000+exp(-(states[0]+35.5000)/7.00000))
algebraic[11] = algebraic[3]*constants[51]+algebraic[9]*(1.00000-constants[51])
rates[9] = algebraic[7]*(1.00000-states[9])-algebraic[11]*states[9]
algebraic[14] = constants[11]-states[4]
algebraic[15] = constants[13]*states[4]*states[1]-constants[14]*algebraic[14]
rates[4] = -algebraic[15]
algebraic[16] = constants[12]-states[5]
algebraic[8] = 12000.0*(power(states[1], 2.00000))
algebraic[10] = 3.70000e+06*(power(states[1], 2.00000))
algebraic[12] = algebraic[8]*algebraic[10]*(1.00000/(algebraic[8]+constants[16])+1.00000/(constants[15]+constants[16]))
algebraic[13] = constants[15]*constants[16]*(1.00000/(algebraic[8]+constants[16])+1.00000/(constants[15]+constants[16]))
algebraic[17] = algebraic[12]*states[5]-algebraic[13]*algebraic[16]
rates[5] = -algebraic[17]
algebraic[32] = (173.600/(1.00000+algebraic[16]/5.00000e-05)+6.40000)*1.00000e-05
algebraic[33] = 1.00000/(1.00000+algebraic[32]/states[1])
algebraic[35] = 1.00000-algebraic[33]
algebraic[37] = constants[52]*algebraic[33]+constants[34]*algebraic[35]
rates[11] = constants[57]*(1.00000-states[11])-algebraic[37]*states[11]
algebraic[2] = 0.500000*log(constants[3]/states[1])
algebraic[18] = 0.000450000/(0.000450000+states[1])
algebraic[19] = (constants[17]*states[6]*algebraic[18]*(power(states[1]*constants[3], 1.0/2))*sinh(algebraic[0]-algebraic[2]))/(sinh(algebraic[0])/algebraic[0])
algebraic[31] = constants[37]*((10.5600*algebraic[16])/(algebraic[16]+5.00000e-05)+1.20000)
algebraic[34] = algebraic[31]*(constants[52]*algebraic[33]*states[11]-constants[33]*constants[53]*(1.00000-states[11]))*1.00000
algebraic[36] = (1.00000+0.00100000*((power(states[2], 3.00000))*constants[3]+(power(constants[4], 3.00000))*states[1]))*(1.00000+states[1]/0.00690000)
algebraic[38] = (constants[39]*((power(states[2], 3.00000))*constants[3]*exp(constants[38]*algebraic[0])-(power(constants[4], 3.00000))*states[1]*exp((constants[38]-1.00000)*algebraic[0])))/algebraic[36]
algebraic[39] = (-1.00000/(2.00000*constants[2]*constants[49]))*((algebraic[19]+2.00000*algebraic[34])-2.00000*algebraic[38])
algebraic[40] = algebraic[39]-(algebraic[15]+4.00000*algebraic[17])
rates[1] = algebraic[40]
algebraic[4] = log(constants[4]/states[2])
algebraic[20] = (power(states[7], 3.00000))*states[8]
algebraic[21] = (constants[18]*algebraic[20]*(power(states[2]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[0]-algebraic[4])))/(sinh(0.500000*algebraic[0])/(0.500000*algebraic[0]))
algebraic[22] = (constants[27]*(power(states[2]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[0]-algebraic[4])))/(sinh(0.500000*algebraic[0])/(0.500000*algebraic[0]))
algebraic[23] = (constants[28]*states[9]*(power(states[2]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[0]-algebraic[4])))/(sinh(0.500000*algebraic[0])/(0.500000*algebraic[0]))
algebraic[42] = 1.00000/(1.00000+(constants[43]/states[2])*(1.00000+states[3]/constants[45]))
algebraic[41] = constants[4]*exp(-0.820000*algebraic[0])
algebraic[45] = 1.00000/(1.00000+(constants[44]/algebraic[41])*(1.00000+constants[5]/constants[46]))
algebraic[46] = constants[47]*(constants[54]*algebraic[42]*states[12]-constants[40]*algebraic[45]*(1.00000-states[12]))*1.00000
algebraic[48] = (-1.00000/(constants[2]*constants[49]))*(3.00000*algebraic[46]+3.00000*algebraic[38]+algebraic[21]+algebraic[22]+algebraic[23])
rates[2] = algebraic[48]
algebraic[43] = 1.00000/(1.00000+(constants[45]/states[3])*(1.00000+states[2]/constants[43]))
algebraic[44] = constants[54]*algebraic[42]+constants[41]*algebraic[43]
algebraic[47] = 1.00000/(1.00000+(constants[46]/constants[5])*(1.00000+algebraic[41]/constants[44]))
algebraic[49] = constants[40]*algebraic[45]+constants[42]*algebraic[47]
rates[12] = algebraic[49]*(1.00000-states[12])-algebraic[44]*states[12]
algebraic[6] = log(constants[5]/states[3])
algebraic[24] = (power(states[1], 4.20000))/(power(0.000350000, 4.20000)+power(states[1], 4.20000))
algebraic[25] = (constants[30]*algebraic[24]*(power(states[3]*constants[5], 1.0/2))*sinh(0.500000*(algebraic[0]-algebraic[6])))/(sinh(0.500000*algebraic[0])/(0.500000*algebraic[0]))
algebraic[26] = power(states[10], 3.00000)
algebraic[27] = constants[31]*algebraic[26]*(states[0]-algebraic[6]*constants[48])
algebraic[28] = 1.00000/(1.00000+exp((states[0]+85.0000)/12.1000))
algebraic[29] = constants[32]*algebraic[28]*(states[0]-algebraic[6]*constants[48])
algebraic[30] = algebraic[25]+algebraic[27]+algebraic[29]
algebraic[50] = (-1.00000/(constants[2]*constants[49]))*(algebraic[30]-2.00000*algebraic[46])
rates[0] = ((constants[2]*constants[49])/(constants[8]*constants[55]))*(algebraic[48]+algebraic[50]+2.00000*algebraic[40])
rates[3] = algebraic[50]
return(rates)
def computeAlgebraic(constants, states, voi):
algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
states = array(states)
voi = array(voi)
algebraic[0] = states[0]/constants[48]
algebraic[1] = 0.00600000/(1.00000+exp((states[0]+87.7000)/6.45000))
algebraic[5] = 0.0268000/(1.00000+exp((states[0]+94.2000)/13.3000))
algebraic[7] = algebraic[1]*constants[50]+algebraic[5]*(1.00000-constants[50])
algebraic[3] = 0.0800000/(1.00000+exp(-(states[0]+51.7000)/7.00000))
algebraic[9] = 0.0800000/(1.00000+exp(-(states[0]+35.5000)/7.00000))
algebraic[11] = algebraic[3]*constants[51]+algebraic[9]*(1.00000-constants[51])
algebraic[14] = constants[11]-states[4]
algebraic[15] = constants[13]*states[4]*states[1]-constants[14]*algebraic[14]
algebraic[16] = constants[12]-states[5]
algebraic[8] = 12000.0*(power(states[1], 2.00000))
algebraic[10] = 3.70000e+06*(power(states[1], 2.00000))
algebraic[12] = algebraic[8]*algebraic[10]*(1.00000/(algebraic[8]+constants[16])+1.00000/(constants[15]+constants[16]))
algebraic[13] = constants[15]*constants[16]*(1.00000/(algebraic[8]+constants[16])+1.00000/(constants[15]+constants[16]))
algebraic[17] = algebraic[12]*states[5]-algebraic[13]*algebraic[16]
algebraic[32] = (173.600/(1.00000+algebraic[16]/5.00000e-05)+6.40000)*1.00000e-05
algebraic[33] = 1.00000/(1.00000+algebraic[32]/states[1])
algebraic[35] = 1.00000-algebraic[33]
algebraic[37] = constants[52]*algebraic[33]+constants[34]*algebraic[35]
algebraic[2] = 0.500000*log(constants[3]/states[1])
algebraic[18] = 0.000450000/(0.000450000+states[1])
algebraic[19] = (constants[17]*states[6]*algebraic[18]*(power(states[1]*constants[3], 1.0/2))*sinh(algebraic[0]-algebraic[2]))/(sinh(algebraic[0])/algebraic[0])
algebraic[31] = constants[37]*((10.5600*algebraic[16])/(algebraic[16]+5.00000e-05)+1.20000)
algebraic[34] = algebraic[31]*(constants[52]*algebraic[33]*states[11]-constants[33]*constants[53]*(1.00000-states[11]))*1.00000
algebraic[36] = (1.00000+0.00100000*((power(states[2], 3.00000))*constants[3]+(power(constants[4], 3.00000))*states[1]))*(1.00000+states[1]/0.00690000)
algebraic[38] = (constants[39]*((power(states[2], 3.00000))*constants[3]*exp(constants[38]*algebraic[0])-(power(constants[4], 3.00000))*states[1]*exp((constants[38]-1.00000)*algebraic[0])))/algebraic[36]
algebraic[39] = (-1.00000/(2.00000*constants[2]*constants[49]))*((algebraic[19]+2.00000*algebraic[34])-2.00000*algebraic[38])
algebraic[40] = algebraic[39]-(algebraic[15]+4.00000*algebraic[17])
algebraic[4] = log(constants[4]/states[2])
algebraic[20] = (power(states[7], 3.00000))*states[8]
algebraic[21] = (constants[18]*algebraic[20]*(power(states[2]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[0]-algebraic[4])))/(sinh(0.500000*algebraic[0])/(0.500000*algebraic[0]))
algebraic[22] = (constants[27]*(power(states[2]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[0]-algebraic[4])))/(sinh(0.500000*algebraic[0])/(0.500000*algebraic[0]))
algebraic[23] = (constants[28]*states[9]*(power(states[2]*constants[4], 1.0/2))*sinh(0.500000*(algebraic[0]-algebraic[4])))/(sinh(0.500000*algebraic[0])/(0.500000*algebraic[0]))
algebraic[42] = 1.00000/(1.00000+(constants[43]/states[2])*(1.00000+states[3]/constants[45]))
algebraic[41] = constants[4]*exp(-0.820000*algebraic[0])
algebraic[45] = 1.00000/(1.00000+(constants[44]/algebraic[41])*(1.00000+constants[5]/constants[46]))
algebraic[46] = constants[47]*(constants[54]*algebraic[42]*states[12]-constants[40]*algebraic[45]*(1.00000-states[12]))*1.00000
algebraic[48] = (-1.00000/(constants[2]*constants[49]))*(3.00000*algebraic[46]+3.00000*algebraic[38]+algebraic[21]+algebraic[22]+algebraic[23])
algebraic[43] = 1.00000/(1.00000+(constants[45]/states[3])*(1.00000+states[2]/constants[43]))
algebraic[44] = constants[54]*algebraic[42]+constants[41]*algebraic[43]
algebraic[47] = 1.00000/(1.00000+(constants[46]/constants[5])*(1.00000+algebraic[41]/constants[44]))
algebraic[49] = constants[40]*algebraic[45]+constants[42]*algebraic[47]
algebraic[6] = log(constants[5]/states[3])
algebraic[24] = (power(states[1], 4.20000))/(power(0.000350000, 4.20000)+power(states[1], 4.20000))
algebraic[25] = (constants[30]*algebraic[24]*(power(states[3]*constants[5], 1.0/2))*sinh(0.500000*(algebraic[0]-algebraic[6])))/(sinh(0.500000*algebraic[0])/(0.500000*algebraic[0]))
algebraic[26] = power(states[10], 3.00000)
algebraic[27] = constants[31]*algebraic[26]*(states[0]-algebraic[6]*constants[48])
algebraic[28] = 1.00000/(1.00000+exp((states[0]+85.0000)/12.1000))
algebraic[29] = constants[32]*algebraic[28]*(states[0]-algebraic[6]*constants[48])
algebraic[30] = algebraic[25]+algebraic[27]+algebraic[29]
algebraic[50] = (-1.00000/(constants[2]*constants[49]))*(algebraic[30]-2.00000*algebraic[46])
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)
