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 = 76 sizeStates = 29 sizeConstants = 86 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 (millisecond)" legend_states[0] = "Vm in component Vm (millivolt)" legend_constants[0] = "Cm in component model_parameters (picoF)" legend_algebraic[31] = "i_CaT in component i_CaT (picoA)" legend_algebraic[14] = "i_CaL in component i_CaL (picoA)" legend_algebraic[49] = "i_f in component i_f (picoA)" legend_algebraic[50] = "i_st in component i_st (picoA)" legend_algebraic[37] = "i_Kr in component i_Kr (picoA)" legend_algebraic[42] = "i_Ks in component i_Ks (picoA)" legend_algebraic[44] = "i_to in component AP_sensitive_currents (picoA)" legend_algebraic[46] = "i_sus in component AP_sensitive_currents (picoA)" legend_algebraic[52] = "i_NaK in component i_NaK (picoA)" legend_algebraic[66] = "i_NaCa in component i_NaCa (picoA)" legend_algebraic[53] = "i_b_Ca in component i_b_Ca (picoA)" legend_algebraic[51] = "i_b_Na in component i_b_Na (picoA)" legend_constants[75] = "E_Na in component electric_potentials (millivolt)" legend_constants[76] = "E_K in component electric_potentials (millivolt)" legend_constants[77] = "E_Ks in component electric_potentials (millivolt)" legend_constants[1] = "R in component model_parameters (joule_per_kilomole_kelvin)" legend_constants[2] = "T in component model_parameters (kelvin)" legend_constants[3] = "F in component model_parameters (coulomb_per_mole)" legend_constants[4] = "Nai in component model_parameters (millimolar)" legend_constants[5] = "Nao in component model_parameters (millimolar)" legend_constants[6] = "Ki in component model_parameters (millimolar)" legend_constants[7] = "Ko in component model_parameters (millimolar)" legend_constants[8] = "E_CaL in component i_CaL (millivolt)" legend_constants[9] = "g_CaL in component i_CaL (nanoS_per_picoF)" legend_states[1] = "Ca_sub in component calcium_dynamics (millimolar)" legend_states[2] = "dL in component i_CaL_dL_gate (dimensionless)" legend_states[3] = "fL in component i_CaL_fL_gate (dimensionless)" legend_states[4] = "fCa in component i_CaL_fCa_gate (dimensionless)" legend_algebraic[0] = "dL_infinity in component i_CaL_dL_gate (dimensionless)" legend_algebraic[45] = "tau_dL in component i_CaL_dL_gate (millisecond)" legend_algebraic[32] = "alpha_dL in component i_CaL_dL_gate (per_millisecond)" legend_algebraic[43] = "beta_dL in component i_CaL_dL_gate (per_millisecond)" legend_algebraic[16] = "adVm in component i_CaL_dL_gate (millivolt)" legend_algebraic[38] = "bdVm in component i_CaL_dL_gate (millivolt)" legend_algebraic[1] = "fL_infinity in component i_CaL_fL_gate (dimensionless)" legend_algebraic[17] = "tau_fL in component i_CaL_fL_gate (millisecond)" legend_constants[10] = "alpha_fCa in component i_CaL_fCa_gate (per_millisecond)" legend_algebraic[2] = "fCa_infinity in component i_CaL_fCa_gate (dimensionless)" legend_algebraic[18] = "tau_fCa in component i_CaL_fCa_gate (millisecond)" legend_constants[11] = "Km_fCa in component i_CaL_fCa_gate (millimolar)" legend_constants[12] = "g_CaT in component i_CaT (nanoS_per_picoF)" legend_constants[13] = "E_CaT in component i_CaT (millivolt)" legend_states[5] = "dT in component i_CaT_dT_gate (dimensionless)" legend_states[6] = "fT in component i_CaT_fT_gate (dimensionless)" legend_algebraic[3] = "dT_infinity in component i_CaT_dT_gate (dimensionless)" legend_algebraic[19] = "tau_dT in component i_CaT_dT_gate (millisecond)" legend_algebraic[4] = "fT_infinity in component i_CaT_fT_gate (dimensionless)" legend_algebraic[20] = "tau_fT in component i_CaT_fT_gate (millisecond)" legend_constants[14] = "g_Kr in component i_Kr (nanoS_per_picoF)" legend_states[7] = "paS in component i_Kr_pa_gate (dimensionless)" legend_states[8] = "paF in component i_Kr_pa_gate (dimensionless)" legend_states[9] = "pi_ in component i_Kr_pi_gate (dimensionless)" legend_algebraic[5] = "pa_infinity in component i_Kr_pa_gate (dimensionless)" legend_algebraic[21] = "tau_paS in component i_Kr_pa_gate (millisecond)" legend_algebraic[22] = "tau_paF in component i_Kr_pa_gate (millisecond)" legend_algebraic[6] = "pi_infinity in component i_Kr_pi_gate (dimensionless)" legend_algebraic[23] = "tau_pi in component i_Kr_pi_gate (millisecond)" legend_constants[15] = "g_Ks in component i_Ks (nanoS_per_picoF)" legend_states[10] = "n in component i_Ks_n_gate (dimensionless)" legend_algebraic[33] = "n_infinity in component i_Ks_n_gate (dimensionless)" legend_algebraic[39] = "tau_n in component i_Ks_n_gate (millisecond)" legend_algebraic[7] = "alpha_n in component i_Ks_n_gate (per_millisecond)" legend_algebraic[24] = "beta_n in component i_Ks_n_gate (per_millisecond)" legend_constants[16] = "g_to in component AP_sensitive_currents (nanoS_per_picoF)" legend_constants[17] = "g_sus in component AP_sensitive_currents (nanoS_per_picoF)" legend_states[11] = "q in component AP_sensitive_currents_q_gate (dimensionless)" legend_states[12] = "r in component AP_sensitive_currents_r_gate (dimensionless)" legend_algebraic[8] = "q_infinity in component AP_sensitive_currents_q_gate (dimensionless)" legend_algebraic[25] = "tau_q in component AP_sensitive_currents_q_gate (millisecond)" legend_algebraic[9] = "r_infinity in component AP_sensitive_currents_r_gate (dimensionless)" legend_algebraic[26] = "tau_r in component AP_sensitive_currents_r_gate (millisecond)" legend_algebraic[47] = "i_f_Na in component i_f (picoA)" legend_algebraic[48] = "i_f_K in component i_f (picoA)" legend_constants[18] = "g_if in component i_f (nanoS_per_picoF)" legend_states[13] = "y in component i_f_y_gate (dimensionless)" legend_algebraic[10] = "y_infinity in component i_f_y_gate (dimensionless)" legend_algebraic[27] = "tau_y in component i_f_y_gate (millisecond)" legend_constants[19] = "VIf_half in component i_f_y_gate (millivolt)" legend_constants[20] = "g_st in component i_st (nanoS_per_picoF)" legend_constants[21] = "E_st in component i_st (millivolt)" legend_states[14] = "qa in component i_st_qa_gate (dimensionless)" legend_states[15] = "qi in component i_st_qi_gate (dimensionless)" legend_algebraic[11] = "qa_infinity in component i_st_qa_gate (dimensionless)" legend_algebraic[40] = "tau_qa in component i_st_qa_gate (millisecond)" legend_algebraic[28] = "alpha_qa in component i_st_qa_gate (per_millisecond)" legend_algebraic[34] = "beta_qa in component i_st_qa_gate (per_millisecond)" legend_algebraic[35] = "qi_infinity in component i_st_qi_gate (dimensionless)" legend_algebraic[41] = "tau_qi in component i_st_qi_gate (millisecond)" legend_algebraic[12] = "alpha_qi in component i_st_qi_gate (per_millisecond)" legend_algebraic[29] = "beta_qi in component i_st_qi_gate (per_millisecond)" legend_constants[22] = "g_b_Na in component i_b_Na (nanoS_per_picoF)" legend_constants[23] = "Km_Kp in component i_NaK (millimolar)" legend_constants[24] = "Km_Nap in component i_NaK (millimolar)" legend_constants[25] = "i_NaK_max in component i_NaK (picoA_per_picoF)" legend_constants[26] = "g_b_Ca in component i_b_Ca (nanoS_per_picoF)" legend_constants[27] = "kNaCa in component i_NaCa (picoA_per_picoF)" legend_algebraic[63] = "x1 in component i_NaCa (dimensionless)" legend_algebraic[59] = "x2 in component i_NaCa (dimensionless)" legend_algebraic[64] = "x3 in component i_NaCa (dimensionless)" legend_algebraic[65] = "x4 in component i_NaCa (dimensionless)" legend_algebraic[54] = "k41 in component i_NaCa (dimensionless)" legend_constants[80] = "k34 in component i_NaCa (dimensionless)" legend_algebraic[62] = "k23 in component i_NaCa (dimensionless)" legend_algebraic[61] = "k21 in component i_NaCa (dimensionless)" legend_algebraic[58] = "k32 in component i_NaCa (dimensionless)" legend_constants[79] = "k43 in component i_NaCa (dimensionless)" legend_algebraic[56] = "k12 in component i_NaCa (dimensionless)" legend_algebraic[57] = "k14 in component i_NaCa (dimensionless)" legend_constants[28] = "Qci in component i_NaCa (dimensionless)" legend_constants[29] = "Qn in component i_NaCa (dimensionless)" legend_constants[30] = "Qco in component i_NaCa (dimensionless)" legend_constants[31] = "K3ni in component i_NaCa (millimolar)" legend_constants[32] = "Kci in component i_NaCa (millimolar)" legend_constants[33] = "K1ni in component i_NaCa (millimolar)" legend_constants[34] = "K2ni in component i_NaCa (millimolar)" legend_constants[35] = "Kcni in component i_NaCa (millimolar)" legend_constants[36] = "K3no in component i_NaCa (millimolar)" legend_constants[37] = "K1no in component i_NaCa (millimolar)" legend_constants[38] = "K2no in component i_NaCa (millimolar)" legend_constants[39] = "Kco in component i_NaCa (millimolar)" legend_constants[78] = "RTOnF in component i_NaCa (millivolt)" legend_algebraic[60] = "do in component i_NaCa (dimensionless)" legend_algebraic[55] = "di in component i_NaCa (dimensionless)" legend_constants[40] = "Cao in component model_parameters (millimolar)" legend_algebraic[67] = "j_SRCarel in component j_SRCarel (millimolar_per_millisecond)" legend_states[16] = "R in component j_SRCarel (dimensionless)" legend_states[17] = "O in component j_SRCarel (dimensionless)" legend_states[18] = "I in component j_SRCarel (dimensionless)" legend_states[19] = "RI in component j_SRCarel (dimensionless)" legend_constants[41] = "ks in component j_SRCarel (per_millisecond)" legend_constants[42] = "MaxSR in component j_SRCarel (dimensionless)" legend_constants[43] = "MinSR in component j_SRCarel (dimensionless)" legend_constants[44] = "EC50_SR in component j_SRCarel (millimolar)" legend_constants[45] = "HSR in component j_SRCarel (dimensionless)" legend_algebraic[30] = "koSRCa in component j_SRCarel (per_millimolar2_millisecond)" legend_algebraic[36] = "kiSRCa in component j_SRCarel (per_millimolar_millisecond)" legend_constants[46] = "koCa in component j_SRCarel (per_millimolar2_millisecond)" legend_constants[47] = "kiCa in component j_SRCarel (per_millimolar_millisecond)" legend_algebraic[13] = "kCaSR in component j_SRCarel (dimensionless)" legend_constants[48] = "kim in component j_SRCarel (per_millisecond)" legend_constants[49] = "kom in component j_SRCarel (per_millisecond)" legend_states[20] = "Ca_jsr in component calcium_dynamics (millimolar)" legend_algebraic[68] = "j_Ca_dif in component intracellular_calcium_fluxes (millimolar_per_millisecond)" legend_algebraic[70] = "j_up in component intracellular_calcium_fluxes (millimolar_per_millisecond)" legend_algebraic[72] = "j_tr in component intracellular_calcium_fluxes (millimolar_per_millisecond)" legend_constants[50] = "tau_dif_Ca in component intracellular_calcium_fluxes (millisecond)" legend_constants[51] = "tau_tr in component intracellular_calcium_fluxes (millisecond)" legend_constants[52] = "P_up in component intracellular_calcium_fluxes (millimolar_per_millisecond)" legend_constants[53] = "K_up in component intracellular_calcium_fluxes (millimolar)" legend_states[21] = "Ca_nsr in component calcium_dynamics (millimolar)" legend_states[22] = "Cai in component calcium_dynamics (millimolar)" legend_constants[54] = "TC_tot in component calcium_buffering (millimolar)" legend_constants[55] = "TMC_tot in component calcium_buffering (millimolar)" legend_constants[56] = "CM_tot in component calcium_buffering (millimolar)" legend_constants[57] = "CQ_tot in component calcium_buffering (millimolar)" legend_algebraic[71] = "delta_fTC in component calcium_buffering (per_millisecond)" legend_algebraic[73] = "delta_fTMC in component calcium_buffering (per_millisecond)" legend_algebraic[69] = "delta_fCMs in component calcium_buffering (per_millisecond)" legend_algebraic[75] = "delta_fCMi in component calcium_buffering (per_millisecond)" legend_algebraic[74] = "delta_fCQ in component calcium_buffering (per_millisecond)" legend_algebraic[15] = "delta_fTMM in component calcium_buffering (per_millisecond)" legend_states[23] = "fTMM in component calcium_buffering (dimensionless)" legend_states[24] = "fCMi in component calcium_buffering (dimensionless)" legend_states[25] = "fCMs in component calcium_buffering (dimensionless)" legend_states[26] = "fTC in component calcium_buffering (dimensionless)" legend_states[27] = "fTMC in component calcium_buffering (dimensionless)" legend_states[28] = "fCQ in component calcium_buffering (dimensionless)" legend_constants[58] = "kf_TC in component calcium_buffering (per_millimolar_millisecond)" legend_constants[59] = "kf_TMM in component calcium_buffering (per_millimolar_millisecond)" legend_constants[60] = "kf_TMC in component calcium_buffering (per_millimolar_millisecond)" legend_constants[61] = "kf_CM in component calcium_buffering (per_millimolar_millisecond)" legend_constants[62] = "kf_CQ in component calcium_buffering (per_millimolar_millisecond)" legend_constants[63] = "kb_TC in component calcium_buffering (per_millisecond)" legend_constants[64] = "kb_TMC in component calcium_buffering (per_millisecond)" legend_constants[65] = "kb_TMM in component calcium_buffering (per_millisecond)" legend_constants[66] = "kb_CM in component calcium_buffering (per_millisecond)" legend_constants[67] = "kb_CQ in component calcium_buffering (per_millisecond)" legend_constants[68] = "Mgi in component model_parameters (millimolar)" legend_constants[84] = "V_i in component model_parameters (picolitre)" legend_constants[83] = "V_jsr in component model_parameters (picolitre)" legend_constants[85] = "V_nsr in component model_parameters (picolitre)" legend_constants[82] = "V_sub in component model_parameters (picolitre)" legend_constants[81] = "V_cell in component model_parameters (picolitre)" legend_constants[69] = "V_jsr_part in component model_parameters (dimensionless)" legend_constants[70] = "V_i_part in component model_parameters (dimensionless)" legend_constants[71] = "V_nsr_part in component model_parameters (dimensionless)" legend_constants[72] = "R_cell in component model_parameters (micrometre)" legend_constants[73] = "L_cell in component model_parameters (micrometre)" legend_constants[74] = "L_sub in component model_parameters (micrometre)" legend_rates[0] = "d/dt Vm in component Vm (millivolt)" legend_rates[2] = "d/dt dL in component i_CaL_dL_gate (dimensionless)" legend_rates[3] = "d/dt fL in component i_CaL_fL_gate (dimensionless)" legend_rates[4] = "d/dt fCa in component i_CaL_fCa_gate (dimensionless)" legend_rates[5] = "d/dt dT in component i_CaT_dT_gate (dimensionless)" legend_rates[6] = "d/dt fT in component i_CaT_fT_gate (dimensionless)" legend_rates[7] = "d/dt paS in component i_Kr_pa_gate (dimensionless)" legend_rates[8] = "d/dt paF in component i_Kr_pa_gate (dimensionless)" legend_rates[9] = "d/dt pi_ in component i_Kr_pi_gate (dimensionless)" legend_rates[10] = "d/dt n in component i_Ks_n_gate (dimensionless)" legend_rates[11] = "d/dt q in component AP_sensitive_currents_q_gate (dimensionless)" legend_rates[12] = "d/dt r in component AP_sensitive_currents_r_gate (dimensionless)" legend_rates[13] = "d/dt y in component i_f_y_gate (dimensionless)" legend_rates[14] = "d/dt qa in component i_st_qa_gate (dimensionless)" legend_rates[15] = "d/dt qi in component i_st_qi_gate (dimensionless)" legend_rates[16] = "d/dt R in component j_SRCarel (dimensionless)" legend_rates[17] = "d/dt O in component j_SRCarel (dimensionless)" legend_rates[18] = "d/dt I in component j_SRCarel (dimensionless)" legend_rates[19] = "d/dt RI in component j_SRCarel (dimensionless)" legend_rates[26] = "d/dt fTC in component calcium_buffering (dimensionless)" legend_rates[27] = "d/dt fTMC in component calcium_buffering (dimensionless)" legend_rates[23] = "d/dt fTMM in component calcium_buffering (dimensionless)" legend_rates[24] = "d/dt fCMi in component calcium_buffering (dimensionless)" legend_rates[25] = "d/dt fCMs in component calcium_buffering (dimensionless)" legend_rates[28] = "d/dt fCQ in component calcium_buffering (dimensionless)" legend_rates[22] = "d/dt Cai in component calcium_dynamics (millimolar)" legend_rates[1] = "d/dt Ca_sub in component calcium_dynamics (millimolar)" legend_rates[21] = "d/dt Ca_nsr in component calcium_dynamics (millimolar)" legend_rates[20] = "d/dt Ca_jsr in component calcium_dynamics (millimolar)" return (legend_states, legend_algebraic, legend_voi, legend_constants) def initConsts(): constants = [0.0] * sizeConstants; states = [0.0] * sizeStates; states[0] = -57.9639346865 constants[0] = 32 constants[1] = 8314.4 constants[2] = 310.15 constants[3] = 96485 constants[4] = 10 constants[5] = 140 constants[6] = 140 constants[7] = 5.4 constants[8] = 45 constants[9] = 0.464 states[1] = 0.000138112560112 states[2] = 0.000584545564405 states[3] = 0.862381249774 states[4] = 0.711395919653 constants[10] = 0.021 constants[11] = 0.00035 constants[12] = 0.1832 constants[13] = 45 states[5] = 0.00504393374639 states[6] = 0.420757825415 constants[14] = 0.08113973 states[7] = 0.453100576739 states[8] = 0.144755091176 states[9] = 0.849409822329 constants[15] = 0.0259 states[10] = 0.0264600410928 constants[16] = 0.252 constants[17] = 0.02 states[11] = 0.694241313965 states[12] = 0.00558131733359 constants[18] = 0.15 states[13] = 0.113643187247 constants[19] = -64 constants[20] = 0.003 constants[21] = 37.4 states[14] = 0.42380243163 states[15] = 0.447294008304 constants[22] = 0.00486 constants[23] = 1.4 constants[24] = 14 constants[25] = 2.88 constants[26] = 0.0006 constants[27] = 187.5 constants[28] = 0.1369 constants[29] = 0.4315 constants[30] = 0 constants[31] = 26.44 constants[32] = 0.0207 constants[33] = 395.3 constants[34] = 2.289 constants[35] = 26.44 constants[36] = 4.663 constants[37] = 1628 constants[38] = 561.4 constants[39] = 3.663 constants[40] = 2 states[16] = 0.688047760973 states[17] = 1.7340201253e-7 states[18] = 7.86181717518e-8 states[19] = 0.311951987007 constants[41] = 250000 constants[42] = 15 constants[43] = 1 constants[44] = 0.45 constants[45] = 2.5 constants[46] = 10 constants[47] = 0.5 constants[48] = 0.005 constants[49] = 0.06 states[20] = 0.316762674605 constants[50] = 0.04 constants[51] = 40 constants[52] = 0.012 constants[53] = 0.0006 states[21] = 1.49348117734 states[22] = 0.000150018670943 constants[54] = 0.031 constants[55] = 0.062 constants[56] = 0.045 constants[57] = 10 states[23] = 0.501049376634 states[24] = 0.0594880901438 states[25] = 0.054381370046 states[26] = 0.0291316176172 states[27] = 0.432694959597 states[28] = 0.273207128393 constants[58] = 88.8 constants[59] = 2.277 constants[60] = 227.7 constants[61] = 227.7 constants[62] = 0.534 constants[63] = 0.446 constants[64] = 0.00751 constants[65] = 0.751 constants[66] = 0.542 constants[67] = 0.445 constants[68] = 2.5 constants[69] = 0.0012 constants[70] = 0.46 constants[71] = 0.0116 constants[72] = 4 constants[73] = 70 constants[74] = 0.02 constants[75] = ((constants[1]*constants[2])/constants[3])*log(constants[5]/constants[4]) constants[76] = ((constants[1]*constants[2])/constants[3])*log(constants[7]/constants[6]) constants[77] = ((constants[1]*constants[2])/constants[3])*log((constants[7]+0.120000*constants[5])/(constants[6]+0.120000*constants[4])) constants[78] = (constants[1]*constants[2])/constants[3] constants[79] = constants[4]/(constants[31]+constants[4]) constants[80] = constants[5]/(constants[36]+constants[5]) constants[81] = 0.00100000* pi*(power(constants[72], 2.00000))*constants[73] constants[82] = 0.00100000*2.00000* pi*constants[74]*(constants[72]-constants[74]/2.00000)*constants[73] constants[83] = constants[69]*constants[81] constants[84] = constants[70]*constants[81]-constants[82] constants[85] = constants[71]*constants[81] return (states, constants) def computeRates(voi, states, constants): rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic algebraic[15] = constants[59]*constants[68]*(1.00000-(states[27]+states[23]))-constants[65]*states[23] rates[23] = algebraic[15] algebraic[1] = 1.00000/(1.00000+exp((states[0]+35.0000)/7.30000)) algebraic[17] = 44.3000+257.100*exp(-(power((states[0]+32.5000)/13.9000, 2.00000))) rates[3] = (algebraic[1]-states[3])/algebraic[17] algebraic[2] = constants[11]/(constants[11]+states[1]) algebraic[18] = algebraic[2]/constants[10] rates[4] = (algebraic[2]-states[4])/algebraic[18] algebraic[3] = 1.00000/(1.00000+exp(-(states[0]+26.3000)/6.00000)) algebraic[19] = 1.00000/(1.06800*exp((states[0]+26.3000)/30.0000)+1.06800*exp(-(states[0]+26.3000)/30.0000)) rates[5] = (algebraic[3]-states[5])/algebraic[19] algebraic[4] = 1.00000/(1.00000+exp((states[0]+61.7000)/5.60000)) algebraic[20] = 1.00000/(0.0153000*exp(-(states[0]+61.7000)/83.3000)+0.0150000*exp((states[0]+61.7000)/15.3800)) rates[6] = (algebraic[4]-states[6])/algebraic[20] algebraic[5] = 1.00000/(1.00000+exp(-(states[0]+23.2000)/10.6000)) algebraic[21] = 0.846554/(0.00420000*exp(states[0]/17.0000)+0.000150000*exp(-states[0]/21.6000)) rates[7] = (algebraic[5]-states[7])/algebraic[21] algebraic[22] = 0.846554/(0.0372000*exp(states[0]/15.9000)+0.000960000*exp(-states[0]/22.5000)) rates[8] = (algebraic[5]-states[8])/algebraic[22] algebraic[6] = 1.00000/(1.00000+exp((states[0]+28.6000)/17.1000)) algebraic[23] = 1.00000/(0.100000*exp(-states[0]/54.6450)+0.656000*exp(states[0]/106.157)) rates[9] = (algebraic[6]-states[9])/algebraic[23] algebraic[8] = 1.00000/(1.00000+exp((states[0]+49.0000)/13.0000)) algebraic[25] = 6.06000+39.1020/(0.570000*exp(-0.0800000*(states[0]+44.0000))+0.0650000*exp(0.100000*(states[0]+45.9300))) rates[11] = (algebraic[8]-states[11])/algebraic[25] algebraic[9] = 1.00000/(1.00000+exp(-(states[0]-19.3000)/15.0000)) algebraic[26] = 2.75352+14.4052/(1.03700*exp(0.0900000*(states[0]+30.6100))+0.369000*exp(-0.120000*(states[0]+23.8400))) rates[12] = (algebraic[9]-states[12])/algebraic[26] algebraic[10] = 1.00000/(1.00000+exp((states[0]-constants[19])/13.5000)) algebraic[27] = 0.716653/(exp(-(states[0]+386.900)/45.3020)+exp((states[0]-73.0800)/19.2310)) rates[13] = (algebraic[10]-states[13])/algebraic[27] algebraic[13] = constants[42]-(constants[42]-constants[43])/(1.00000+power(constants[44]/states[20], constants[45])) algebraic[30] = constants[46]/algebraic[13] algebraic[36] = constants[47]*algebraic[13] rates[16] = (constants[48]*states[19]-algebraic[36]*states[1]*states[16])-(algebraic[30]*(power(states[1], 2.00000))*states[16]-constants[49]*states[17]) rates[17] = (algebraic[30]*(power(states[1], 2.00000))*states[16]-constants[49]*states[17])-(algebraic[36]*states[1]*states[17]-constants[48]*states[18]) rates[18] = (algebraic[36]*states[1]*states[17]-constants[48]*states[18])-(constants[49]*states[18]-algebraic[30]*(power(states[1], 2.00000))*states[19]) rates[19] = (constants[49]*states[18]-algebraic[30]*(power(states[1], 2.00000))*states[19])-(constants[48]*states[19]-algebraic[36]*states[1]*states[16]) algebraic[7] = 0.0140000/(1.00000+exp(-(states[0]-40.0000)/9.00000)) algebraic[24] = 0.00100000*exp(-states[0]/45.0000) algebraic[33] = algebraic[7]/(algebraic[7]+algebraic[24]) algebraic[39] = 1.00000/(algebraic[7]+algebraic[24]) rates[10] = (algebraic[33]-states[10])/algebraic[39] algebraic[11] = 1.00000/(1.00000+exp(-(states[0]+57.0000)/5.00000)) algebraic[28] = 1.00000/(0.150000*exp(-states[0]/11.0000)+0.200000*exp(-states[0]/700.000)) algebraic[34] = 1.00000/(16.0000*exp(states[0]/8.00000)+15.0000*exp(states[0]/50.0000)) algebraic[40] = 1.00000/(algebraic[28]+algebraic[34]) rates[14] = (algebraic[11]-states[14])/algebraic[40] algebraic[12] = 1.00000/(3100.00*exp(states[0]/13.0000)+700.000*exp(states[0]/70.0000)) algebraic[29] = 1.00000/(95.0000*exp(-states[0]/10.0000)+50.0000*exp(-states[0]/700.000))+0.000229000/(1.00000+exp(-states[0]/5.00000)) algebraic[35] = algebraic[12]/(algebraic[12]+algebraic[29]) algebraic[41] = 6.65000/(algebraic[12]+algebraic[29]) rates[15] = (algebraic[35]-states[15])/algebraic[41] algebraic[0] = 1.00000/(1.00000+exp(-(states[0]+13.5000)/6.00000)) algebraic[16] = custom_piecewise([equal(states[0] , -35.0000), -35.0000 , equal(states[0] , 0.00000), 1.00000e-05 , True, states[0]]) algebraic[32] = (-0.0283900*(algebraic[16]+35.0000))/(exp(-(algebraic[16]+35.0000)/2.50000)-1.00000)-(0.0849000*algebraic[16])/(exp(-algebraic[16]/4.80000)-1.00000) algebraic[38] = custom_piecewise([equal(states[0] , 5.00000), 5.00001 , True, states[0]]) algebraic[43] = (0.0114300*(algebraic[38]-5.00000))/(exp((algebraic[38]-5.00000)/2.50000)-1.00000) algebraic[45] = 1.00000/(algebraic[32]+algebraic[43]) rates[2] = (algebraic[0]-states[2])/algebraic[45] algebraic[31] = constants[0]*constants[12]*(states[0]-constants[13])*states[5]*states[6] algebraic[14] = constants[0]*constants[9]*(states[0]-constants[8])*states[2]*states[3]*states[4] algebraic[47] = constants[0]*0.383300*constants[18]*(states[0]-constants[75])*(power(states[13], 2.00000)) algebraic[48] = constants[0]*0.616700*constants[18]*(states[0]-constants[76])*(power(states[13], 2.00000)) algebraic[49] = algebraic[47]+algebraic[48] algebraic[50] = constants[0]*constants[20]*(states[0]-constants[21])*states[14]*states[15] algebraic[37] = constants[0]*constants[14]*(states[0]-constants[76])*(0.600000*states[8]+0.400000*states[7])*states[9] algebraic[42] = constants[0]*constants[15]*(states[0]-constants[77])*(power(states[10], 2.00000)) algebraic[44] = constants[0]*constants[16]*(states[0]-constants[76])*states[11]*states[12] algebraic[46] = constants[0]*constants[17]*(states[0]-constants[76])*states[12] algebraic[52] = (constants[0]*constants[25])/((1.00000+power(constants[23]/constants[7], 1.20000))*(1.00000+power(constants[24]/constants[4], 1.30000))*(1.00000+exp(-((states[0]-constants[75])+120.000)/30.0000))) algebraic[54] = exp((-constants[29]*states[0])/(2.00000*constants[78])) algebraic[60] = 1.00000+(constants[40]/constants[39])*(1.00000+exp((constants[30]*states[0])/constants[78]))+(constants[5]/constants[37])*(1.00000+(constants[5]/constants[38])*(1.00000+constants[5]/constants[36])) algebraic[62] = ((((constants[5]/constants[37])*constants[5])/constants[38])*(1.00000+constants[5]/constants[36])*exp((-constants[29]*states[0])/(2.00000*constants[78])))/algebraic[60] algebraic[61] = ((constants[40]/constants[39])*exp((constants[30]*states[0])/constants[78]))/algebraic[60] algebraic[58] = exp((constants[29]*states[0])/(2.00000*constants[78])) algebraic[63] = algebraic[54]*constants[80]*(algebraic[62]+algebraic[61])+algebraic[61]*algebraic[58]*(constants[79]+algebraic[54]) algebraic[55] = 1.00000+(states[1]/constants[32])*(1.00000+exp((-constants[28]*states[0])/constants[78])+constants[4]/constants[35])+(constants[4]/constants[33])*(1.00000+(constants[4]/constants[34])*(1.00000+constants[4]/constants[31])) algebraic[56] = ((states[1]/constants[32])*exp((-constants[28]*states[0])/constants[78]))/algebraic[55] algebraic[57] = ((((constants[4]/constants[33])*constants[4])/constants[34])*(1.00000+constants[4]/constants[31])*exp((constants[29]*states[0])/(2.00000*constants[78])))/algebraic[55] algebraic[59] = algebraic[58]*constants[79]*(algebraic[57]+algebraic[56])+algebraic[54]*algebraic[56]*(constants[80]+algebraic[58]) algebraic[64] = algebraic[57]*constants[79]*(algebraic[62]+algebraic[61])+algebraic[56]*algebraic[62]*(constants[79]+algebraic[54]) algebraic[65] = algebraic[62]*constants[80]*(algebraic[57]+algebraic[56])+algebraic[57]*algebraic[61]*(constants[80]+algebraic[58]) algebraic[66] = (constants[0]*constants[27]*(algebraic[59]*algebraic[61]-algebraic[63]*algebraic[56]))/(algebraic[63]+algebraic[59]+algebraic[64]+algebraic[65]) algebraic[53] = constants[0]*constants[26]*(states[0]-constants[8]) algebraic[51] = constants[0]*constants[22]*(states[0]-constants[75]) rates[0] = -(algebraic[14]+algebraic[31]+algebraic[49]+algebraic[50]+algebraic[37]+algebraic[42]+algebraic[44]+algebraic[46]+algebraic[52]+algebraic[66]+algebraic[53]+algebraic[51])/constants[0] algebraic[69] = constants[61]*states[1]*(1.00000-states[25])-constants[66]*states[25] rates[25] = algebraic[69] algebraic[67] = constants[41]*states[17]*(states[20]-states[1]) algebraic[68] = (states[1]-states[22])/constants[50] rates[1] = (algebraic[67]*constants[83])/constants[82]-(((algebraic[14]+algebraic[31]+algebraic[53])-2.00000*algebraic[66])/(2.00000*constants[3]*constants[82])+algebraic[68]+constants[56]*algebraic[69]) algebraic[71] = constants[58]*states[22]*(1.00000-states[26])-constants[63]*states[26] rates[26] = algebraic[71] algebraic[70] = constants[52]/(1.00000+constants[53]/states[22]) algebraic[72] = (states[21]-states[20])/constants[51] rates[21] = algebraic[70]-(algebraic[72]*constants[83])/constants[85] algebraic[73] = constants[60]*states[22]*(1.00000-(states[27]+states[23]))-constants[64]*states[27] rates[27] = algebraic[73] algebraic[74] = constants[62]*states[20]*(1.00000-states[28])-constants[67]*states[28] rates[28] = algebraic[74] rates[20] = algebraic[72]-(algebraic[67]+constants[57]*algebraic[74]) algebraic[75] = constants[61]*states[22]*(1.00000-states[24])-constants[66]*states[24] rates[24] = algebraic[75] rates[22] = (algebraic[68]*constants[82]-algebraic[70]*constants[85])/constants[84]-(constants[56]*algebraic[75]+constants[54]*algebraic[71]+constants[55]*algebraic[73]) return(rates) def computeAlgebraic(constants, states, voi): algebraic = array([[0.0] * len(voi)] * sizeAlgebraic) states = array(states) voi = array(voi) algebraic[15] = constants[59]*constants[68]*(1.00000-(states[27]+states[23]))-constants[65]*states[23] algebraic[1] = 1.00000/(1.00000+exp((states[0]+35.0000)/7.30000)) algebraic[17] = 44.3000+257.100*exp(-(power((states[0]+32.5000)/13.9000, 2.00000))) algebraic[2] = constants[11]/(constants[11]+states[1]) algebraic[18] = algebraic[2]/constants[10] algebraic[3] = 1.00000/(1.00000+exp(-(states[0]+26.3000)/6.00000)) algebraic[19] = 1.00000/(1.06800*exp((states[0]+26.3000)/30.0000)+1.06800*exp(-(states[0]+26.3000)/30.0000)) algebraic[4] = 1.00000/(1.00000+exp((states[0]+61.7000)/5.60000)) algebraic[20] = 1.00000/(0.0153000*exp(-(states[0]+61.7000)/83.3000)+0.0150000*exp((states[0]+61.7000)/15.3800)) algebraic[5] = 1.00000/(1.00000+exp(-(states[0]+23.2000)/10.6000)) algebraic[21] = 0.846554/(0.00420000*exp(states[0]/17.0000)+0.000150000*exp(-states[0]/21.6000)) algebraic[22] = 0.846554/(0.0372000*exp(states[0]/15.9000)+0.000960000*exp(-states[0]/22.5000)) algebraic[6] = 1.00000/(1.00000+exp((states[0]+28.6000)/17.1000)) algebraic[23] = 1.00000/(0.100000*exp(-states[0]/54.6450)+0.656000*exp(states[0]/106.157)) algebraic[8] = 1.00000/(1.00000+exp((states[0]+49.0000)/13.0000)) algebraic[25] = 6.06000+39.1020/(0.570000*exp(-0.0800000*(states[0]+44.0000))+0.0650000*exp(0.100000*(states[0]+45.9300))) algebraic[9] = 1.00000/(1.00000+exp(-(states[0]-19.3000)/15.0000)) algebraic[26] = 2.75352+14.4052/(1.03700*exp(0.0900000*(states[0]+30.6100))+0.369000*exp(-0.120000*(states[0]+23.8400))) algebraic[10] = 1.00000/(1.00000+exp((states[0]-constants[19])/13.5000)) algebraic[27] = 0.716653/(exp(-(states[0]+386.900)/45.3020)+exp((states[0]-73.0800)/19.2310)) algebraic[13] = constants[42]-(constants[42]-constants[43])/(1.00000+power(constants[44]/states[20], constants[45])) algebraic[30] = constants[46]/algebraic[13] algebraic[36] = constants[47]*algebraic[13] algebraic[7] = 0.0140000/(1.00000+exp(-(states[0]-40.0000)/9.00000)) algebraic[24] = 0.00100000*exp(-states[0]/45.0000) algebraic[33] = algebraic[7]/(algebraic[7]+algebraic[24]) algebraic[39] = 1.00000/(algebraic[7]+algebraic[24]) algebraic[11] = 1.00000/(1.00000+exp(-(states[0]+57.0000)/5.00000)) algebraic[28] = 1.00000/(0.150000*exp(-states[0]/11.0000)+0.200000*exp(-states[0]/700.000)) algebraic[34] = 1.00000/(16.0000*exp(states[0]/8.00000)+15.0000*exp(states[0]/50.0000)) algebraic[40] = 1.00000/(algebraic[28]+algebraic[34]) algebraic[12] = 1.00000/(3100.00*exp(states[0]/13.0000)+700.000*exp(states[0]/70.0000)) algebraic[29] = 1.00000/(95.0000*exp(-states[0]/10.0000)+50.0000*exp(-states[0]/700.000))+0.000229000/(1.00000+exp(-states[0]/5.00000)) algebraic[35] = algebraic[12]/(algebraic[12]+algebraic[29]) algebraic[41] = 6.65000/(algebraic[12]+algebraic[29]) algebraic[0] = 1.00000/(1.00000+exp(-(states[0]+13.5000)/6.00000)) algebraic[16] = custom_piecewise([equal(states[0] , -35.0000), -35.0000 , equal(states[0] , 0.00000), 1.00000e-05 , True, states[0]]) algebraic[32] = (-0.0283900*(algebraic[16]+35.0000))/(exp(-(algebraic[16]+35.0000)/2.50000)-1.00000)-(0.0849000*algebraic[16])/(exp(-algebraic[16]/4.80000)-1.00000) algebraic[38] = custom_piecewise([equal(states[0] , 5.00000), 5.00001 , True, states[0]]) algebraic[43] = (0.0114300*(algebraic[38]-5.00000))/(exp((algebraic[38]-5.00000)/2.50000)-1.00000) algebraic[45] = 1.00000/(algebraic[32]+algebraic[43]) algebraic[31] = constants[0]*constants[12]*(states[0]-constants[13])*states[5]*states[6] algebraic[14] = constants[0]*constants[9]*(states[0]-constants[8])*states[2]*states[3]*states[4] algebraic[47] = constants[0]*0.383300*constants[18]*(states[0]-constants[75])*(power(states[13], 2.00000)) algebraic[48] = constants[0]*0.616700*constants[18]*(states[0]-constants[76])*(power(states[13], 2.00000)) algebraic[49] = algebraic[47]+algebraic[48] algebraic[50] = constants[0]*constants[20]*(states[0]-constants[21])*states[14]*states[15] algebraic[37] = constants[0]*constants[14]*(states[0]-constants[76])*(0.600000*states[8]+0.400000*states[7])*states[9] algebraic[42] = constants[0]*constants[15]*(states[0]-constants[77])*(power(states[10], 2.00000)) algebraic[44] = constants[0]*constants[16]*(states[0]-constants[76])*states[11]*states[12] algebraic[46] = constants[0]*constants[17]*(states[0]-constants[76])*states[12] algebraic[52] = (constants[0]*constants[25])/((1.00000+power(constants[23]/constants[7], 1.20000))*(1.00000+power(constants[24]/constants[4], 1.30000))*(1.00000+exp(-((states[0]-constants[75])+120.000)/30.0000))) algebraic[54] = exp((-constants[29]*states[0])/(2.00000*constants[78])) algebraic[60] = 1.00000+(constants[40]/constants[39])*(1.00000+exp((constants[30]*states[0])/constants[78]))+(constants[5]/constants[37])*(1.00000+(constants[5]/constants[38])*(1.00000+constants[5]/constants[36])) algebraic[62] = ((((constants[5]/constants[37])*constants[5])/constants[38])*(1.00000+constants[5]/constants[36])*exp((-constants[29]*states[0])/(2.00000*constants[78])))/algebraic[60] algebraic[61] = ((constants[40]/constants[39])*exp((constants[30]*states[0])/constants[78]))/algebraic[60] algebraic[58] = exp((constants[29]*states[0])/(2.00000*constants[78])) algebraic[63] = algebraic[54]*constants[80]*(algebraic[62]+algebraic[61])+algebraic[61]*algebraic[58]*(constants[79]+algebraic[54]) algebraic[55] = 1.00000+(states[1]/constants[32])*(1.00000+exp((-constants[28]*states[0])/constants[78])+constants[4]/constants[35])+(constants[4]/constants[33])*(1.00000+(constants[4]/constants[34])*(1.00000+constants[4]/constants[31])) algebraic[56] = ((states[1]/constants[32])*exp((-constants[28]*states[0])/constants[78]))/algebraic[55] algebraic[57] = ((((constants[4]/constants[33])*constants[4])/constants[34])*(1.00000+constants[4]/constants[31])*exp((constants[29]*states[0])/(2.00000*constants[78])))/algebraic[55] algebraic[59] = algebraic[58]*constants[79]*(algebraic[57]+algebraic[56])+algebraic[54]*algebraic[56]*(constants[80]+algebraic[58]) algebraic[64] = algebraic[57]*constants[79]*(algebraic[62]+algebraic[61])+algebraic[56]*algebraic[62]*(constants[79]+algebraic[54]) algebraic[65] = algebraic[62]*constants[80]*(algebraic[57]+algebraic[56])+algebraic[57]*algebraic[61]*(constants[80]+algebraic[58]) algebraic[66] = (constants[0]*constants[27]*(algebraic[59]*algebraic[61]-algebraic[63]*algebraic[56]))/(algebraic[63]+algebraic[59]+algebraic[64]+algebraic[65]) algebraic[53] = constants[0]*constants[26]*(states[0]-constants[8]) algebraic[51] = constants[0]*constants[22]*(states[0]-constants[75]) algebraic[69] = constants[61]*states[1]*(1.00000-states[25])-constants[66]*states[25] algebraic[67] = constants[41]*states[17]*(states[20]-states[1]) algebraic[68] = (states[1]-states[22])/constants[50] algebraic[71] = constants[58]*states[22]*(1.00000-states[26])-constants[63]*states[26] algebraic[70] = constants[52]/(1.00000+constants[53]/states[22]) algebraic[72] = (states[21]-states[20])/constants[51] algebraic[73] = constants[60]*states[22]*(1.00000-(states[27]+states[23]))-constants[64]*states[27] algebraic[74] = constants[62]*states[20]*(1.00000-states[28])-constants[67]*states[28] algebraic[75] = constants[61]*states[22]*(1.00000-states[24])-constants[66]*states[24] 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)