# Size of variable arrays: sizeAlgebraic = 70 sizeStates = 18 sizeConstants = 49 from math import * from numpy import * def createLegends(): legend_states = [""] * sizeStates legend_rates = [""] * sizeStates legend_algebraic = [""] * sizeAlgebraic legend_voi = "" legend_constants = [""] * sizeConstants legend_voi = "time in component environment (second)" legend_states[0] = "Vm in component Membrane (volt)" legend_algebraic[51] = "i_CaL in component i_CaL (A_per_F)" legend_algebraic[57] = "i_K1 in component i_K1 (A_per_F)" legend_algebraic[58] = "i_f in component i_f (A_per_F)" legend_algebraic[48] = "i_Na in component i_Na (A_per_F)" legend_algebraic[52] = "i_Kr in component i_Kr (A_per_F)" legend_algebraic[53] = "i_Ks in component i_Ks (A_per_F)" legend_algebraic[64] = "i_to in component i_to (A_per_F)" legend_algebraic[63] = "i_PCa in component i_PCa (A_per_F)" legend_algebraic[61] = "i_NaK in component i_NaK (A_per_F)" legend_algebraic[62] = "i_NaCa in component i_NaCa (A_per_F)" legend_algebraic[60] = "i_b_Ca in component i_b_Ca (A_per_F)" legend_algebraic[59] = "i_b_Na in component i_b_Na (A_per_F)" legend_algebraic[10] = "E_Na in component electric_potentials (volt)" legend_constants[46] = "E_K in component electric_potentials (volt)" legend_algebraic[25] = "E_Ks in component electric_potentials (volt)" legend_algebraic[39] = "E_Ca in component electric_potentials (volt)" legend_constants[0] = "R in component model_parameters (joule_per_mole_kelvin)" legend_constants[1] = "T in component model_parameters (kelvin)" legend_constants[2] = "F in component model_parameters (coulomb_per_mole)" legend_states[1] = "Nai in component sodium_dynamics (millimolar)" legend_constants[3] = "Nao in component model_parameters (millimolar)" legend_states[2] = "Cai in component calcium_dynamics (millimolar)" legend_constants[4] = "Cao in component model_parameters (millimolar)" legend_constants[5] = "Ki in component model_parameters (millimolar)" legend_constants[6] = "Ko in component model_parameters (millimolar)" legend_constants[7] = "PkNa in component electric_potentials (dimensionless)" legend_constants[8] = "g_Na in component i_Na (S_per_F)" legend_states[3] = "m in component i_Na_m_gate (dimensionless)" legend_states[4] = "h in component i_Na_h_gate (dimensionless)" legend_states[5] = "j in component i_Na_j_gate (dimensionless)" legend_algebraic[0] = "m_inf in component i_Na_m_gate (dimensionless)" legend_algebraic[40] = "tau_m in component i_Na_m_gate (second)" legend_algebraic[15] = "alpha_m in component i_Na_m_gate (dimensionless)" legend_algebraic[30] = "beta_m in component i_Na_m_gate (dimensionless)" legend_algebraic[1] = "h_inf in component i_Na_h_gate (dimensionless)" legend_algebraic[16] = "alpha_h in component i_Na_h_gate (dimensionless)" legend_algebraic[31] = "beta_h in component i_Na_h_gate (dimensionless)" legend_algebraic[41] = "tau_h in component i_Na_h_gate (second)" legend_algebraic[2] = "j_inf in component i_Na_j_gate (dimensionless)" legend_algebraic[17] = "alpha_j in component i_Na_j_gate (dimensionless)" legend_algebraic[32] = "beta_j in component i_Na_j_gate (dimensionless)" legend_algebraic[42] = "tau_j in component i_Na_j_gate (second)" legend_constants[9] = "g_CaL in component i_CaL (metre_cube_per_F_per_s)" legend_states[6] = "d in component i_CaL_d_gate (dimensionless)" legend_states[7] = "f1 in component i_CaL_f1_gate (dimensionless)" legend_states[8] = "f2 in component i_CaL_f2_gate (dimensionless)" legend_states[9] = "fCa in component i_CaL_fCa_gate (dimensionless)" legend_algebraic[3] = "d_infinity in component i_CaL_d_gate (dimensionless)" legend_algebraic[49] = "tau_d in component i_CaL_d_gate (second)" legend_algebraic[18] = "alpha_d in component i_CaL_d_gate (dimensionless)" legend_algebraic[33] = "beta_d in component i_CaL_d_gate (dimensionless)" legend_algebraic[43] = "gamma_d in component i_CaL_d_gate (dimensionless)" legend_algebraic[4] = "f1_inf in component i_CaL_f1_gate (dimensionless)" legend_algebraic[34] = "tau_f1 in component i_CaL_f1_gate (second)" legend_algebraic[19] = "constf1 in component i_CaL_f1_gate (dimensionless)" legend_algebraic[5] = "f2_inf in component i_CaL_f2_gate (dimensionless)" legend_algebraic[20] = "tau_f2 in component i_CaL_f2_gate (second)" legend_constants[47] = "constf2 in component i_CaL_f2_gate (dimensionless)" legend_algebraic[50] = "constfCa in component i_CaL_fCa_gate (dimensionless)" legend_algebraic[6] = "alpha_fCa in component i_CaL_fCa_gate (dimensionless)" legend_algebraic[21] = "beta_fCa in component i_CaL_fCa_gate (dimensionless)" legend_algebraic[35] = "gamma_fCa in component i_CaL_fCa_gate (dimensionless)" legend_algebraic[44] = "fCa_inf in component i_CaL_fCa_gate (dimensionless)" legend_constants[10] = "tau_fCa in component i_CaL_fCa_gate (second)" legend_constants[11] = "g_Kr in component i_Kr (S_per_F)" legend_states[10] = "Xr1 in component i_Kr_Xr1_gate (dimensionless)" legend_states[11] = "Xr2 in component i_Kr_Xr2_gate (dimensionless)" legend_algebraic[7] = "Xr1_inf in component i_Kr_Xr1_gate (dimensionless)" legend_algebraic[22] = "alpha_Xr1 in component i_Kr_Xr1_gate (dimensionless)" legend_algebraic[36] = "beta_Xr1 in component i_Kr_Xr1_gate (dimensionless)" legend_algebraic[45] = "tau_Xr1 in component i_Kr_Xr1_gate (second)" legend_constants[12] = "L0 in component i_Kr_Xr1_gate (dimensionless)" legend_constants[48] = "V_half in component i_Kr_Xr1_gate (millivolt)" legend_constants[13] = "Q in component i_Kr_Xr1_gate (dimensionless)" legend_algebraic[8] = "Xr2_infinity in component i_Kr_Xr2_gate (dimensionless)" legend_algebraic[23] = "alpha_Xr2 in component i_Kr_Xr2_gate (dimensionless)" legend_algebraic[37] = "beta_Xr2 in component i_Kr_Xr2_gate (dimensionless)" legend_algebraic[46] = "tau_Xr2 in component i_Kr_Xr2_gate (second)" legend_constants[14] = "g_Ks in component i_Ks (S_per_F)" legend_states[12] = "Xs in component i_Ks_Xs_gate (dimensionless)" legend_algebraic[9] = "Xs_infinity in component i_Ks_Xs_gate (dimensionless)" legend_algebraic[24] = "alpha_Xs in component i_Ks_Xs_gate (dimensionless)" legend_algebraic[38] = "beta_Xs in component i_Ks_Xs_gate (dimensionless)" legend_algebraic[47] = "tau_Xs in component i_Ks_Xs_gate (second)" legend_constants[15] = "g_K1 in component i_K1 (S_per_F)" legend_algebraic[56] = "XK1_inf in component i_K1 (dimensionless)" legend_algebraic[54] = "alpha_K1 in component i_K1 (dimensionless)" legend_algebraic[55] = "beta_K1 in component i_K1 (dimensionless)" legend_constants[16] = "g_f in component i_f (S_per_F)" legend_constants[17] = "E_f in component i_f (volt)" legend_states[13] = "Xf in component i_f_Xf_gate (dimensionless)" legend_algebraic[11] = "Xf_infinity in component i_f_Xf_gate (dimensionless)" legend_algebraic[26] = "tau_Xf in component i_f_Xf_gate (second)" legend_constants[18] = "g_b_Na in component i_b_Na (S_per_F)" legend_constants[19] = "g_b_Ca in component i_b_Ca (S_per_F)" legend_constants[20] = "Km_K in component i_NaK (millimolar)" legend_constants[21] = "Km_Na in component i_NaK (millimolar)" legend_constants[22] = "PNaK in component i_NaK (A_per_F)" legend_constants[23] = "kNaCa in component i_NaCa (A_per_F)" legend_constants[24] = "alpha in component i_NaCa (dimensionless)" legend_constants[25] = "gamma in component i_NaCa (dimensionless)" legend_constants[26] = "Ksat in component i_NaCa (dimensionless)" legend_constants[27] = "KmCa in component i_NaCa (millimolar)" legend_constants[28] = "KmNai in component i_NaCa (millimolar)" legend_constants[29] = "g_PCa in component i_PCa (A_per_F)" legend_constants[30] = "KPCa in component i_PCa (millimolar)" legend_constants[31] = "g_to in component i_to (S_per_F)" legend_states[14] = "q in component i_to_q_gate (dimensionless)" legend_states[15] = "r in component i_to_r_gate (dimensionless)" legend_algebraic[12] = "q_inf in component i_to_q_gate (dimensionless)" legend_algebraic[27] = "tau_q in component i_to_q_gate (second)" legend_algebraic[13] = "r_inf in component i_to_r_gate (dimensionless)" legend_algebraic[28] = "tau_r in component i_to_r_gate (second)" legend_constants[32] = "Cm in component model_parameters (farad)" legend_constants[33] = "Vc in component model_parameters (micrometre_cube)" legend_constants[34] = "V_SR in component model_parameters (micrometre_cube)" legend_states[16] = "Ca_SR in component calcium_dynamics (millimolar)" legend_constants[35] = "a_rel in component calcium_dynamics (millimolar_per_second)" legend_constants[36] = "b_rel in component calcium_dynamics (millimolar)" legend_constants[37] = "c_rel in component calcium_dynamics (millimolar_per_second)" legend_states[17] = "g in component calcium_dynamics (dimensionless)" legend_constants[38] = "tau_g in component calcium_dynamics (second)" legend_algebraic[14] = "g_inf in component calcium_dynamics (dimensionless)" legend_constants[39] = "Kup in component calcium_dynamics (millimolar)" legend_constants[40] = "Buf_C in component calcium_dynamics (millimolar)" legend_constants[41] = "Buf_SR in component calcium_dynamics (millimolar)" legend_constants[42] = "Kbuf_C in component calcium_dynamics (millimolar)" legend_constants[43] = "Kbuf_SR in component calcium_dynamics (millimolar)" legend_algebraic[68] = "Cai_bufc in component calcium_dynamics (dimensionless)" legend_algebraic[69] = "Ca_SR_bufSR in component calcium_dynamics (dimensionless)" legend_constants[44] = "VmaxUp in component calcium_dynamics (millimolar_per_second)" legend_algebraic[29] = "const2 in component calcium_dynamics (dimensionless)" legend_constants[45] = "V_leak in component calcium_dynamics (per_second)" legend_algebraic[65] = "i_rel in component calcium_dynamics (millimolar_per_second)" legend_algebraic[66] = "i_up in component calcium_dynamics (millimolar_per_second)" legend_algebraic[67] = "i_leak in component calcium_dynamics (millimolar_per_second)" legend_rates[0] = "d/dt Vm in component Membrane (volt)" legend_rates[3] = "d/dt m in component i_Na_m_gate (dimensionless)" legend_rates[4] = "d/dt h in component i_Na_h_gate (dimensionless)" legend_rates[5] = "d/dt j in component i_Na_j_gate (dimensionless)" legend_rates[6] = "d/dt d in component i_CaL_d_gate (dimensionless)" legend_rates[7] = "d/dt f1 in component i_CaL_f1_gate (dimensionless)" legend_rates[8] = "d/dt f2 in component i_CaL_f2_gate (dimensionless)" legend_rates[9] = "d/dt fCa in component i_CaL_fCa_gate (dimensionless)" legend_rates[10] = "d/dt Xr1 in component i_Kr_Xr1_gate (dimensionless)" legend_rates[11] = "d/dt Xr2 in component i_Kr_Xr2_gate (dimensionless)" legend_rates[12] = "d/dt Xs in component i_Ks_Xs_gate (dimensionless)" legend_rates[13] = "d/dt Xf in component i_f_Xf_gate (dimensionless)" legend_rates[14] = "d/dt q in component i_to_q_gate (dimensionless)" legend_rates[15] = "d/dt r in component i_to_r_gate (dimensionless)" legend_rates[1] = "d/dt Nai in component sodium_dynamics (millimolar)" legend_rates[17] = "d/dt g in component calcium_dynamics (dimensionless)" legend_rates[2] = "d/dt Cai in component calcium_dynamics (millimolar)" legend_rates[16] = "d/dt Ca_SR 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] = -0.068733823452164 constants[0] = 8.314472 constants[1] = 310 constants[2] = 96485.3415 states[1] = 14.4424010544424 constants[3] = 151 states[2] = 4.49232909234503e-5 constants[4] = 1.8 constants[5] = 150 constants[6] = 5.4 constants[7] = 0.03 constants[8] = 6646.185 states[3] = 0.141183142078492 states[4] = 0.642108593994587 states[5] = 0.173566329483423 constants[9] = 8.635702e-5 states[6] = 0.000127632520741878 states[7] = 0.98038400433601 states[8] = 0.999953006710394 states[9] = 0.997346890768643 constants[10] = 0.002 constants[11] = 29.8667 states[10] = 0.0257889110986083 states[11] = 0.405046678739985 constants[12] = 0.025 constants[13] = 2.3 constants[14] = 2.041 states[12] = 0.0447460799149437 constants[15] = 19.1925 constants[16] = 30.10312 constants[17] = -0.017 states[13] = 0.0607988713874682 constants[18] = 0.9 constants[19] = 0.69264 constants[20] = 1 constants[21] = 40 constants[22] = 1.4731392 constants[23] = 2450 constants[24] = 2.8571432 constants[25] = 0.35 constants[26] = 0.1 constants[27] = 1.38 constants[28] = 87.5 constants[29] = 0.4125 constants[30] = 0.0005 constants[31] = 59.8077 states[14] = 0.776163826643278 states[15] = 0.000503296941001262 constants[32] = 7.86671e-11 constants[33] = 7012 constants[34] = 465.2 states[16] = 0.149980051221604 constants[35] = 16.464 constants[36] = 0.25 constants[37] = 8.232 states[17] = 1 constants[38] = 0.002 constants[39] = 0.00025 constants[40] = 0.25 constants[41] = 10 constants[42] = 0.001 constants[43] = 0.3 constants[44] = 0.22 constants[45] = 0.00044444 constants[46] = ((constants[0]*constants[1])/constants[2])*log(constants[6]/constants[5]) constants[47] = 2.00000 constants[48] = 1000.00*(((-constants[0]*constants[1])/(constants[2]*constants[13]))*log((power(1.00000+constants[4]/2.60000, 4.00000))/(constants[12]*(power(1.00000+constants[4]/0.580000, 4.00000))))-0.0190000) return (states, constants) def computeRates(voi, states, constants): rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic algebraic[5] = 0.330000+0.670000/(1.00000+exp((states[0]*1000.00+31.2260)/4.00000)) algebraic[20] = ((600.000*exp(-(power(states[0]*1000.00+25.0000, 2.00000))/170.000)+(31.0000/(1.00000+exp((25.0000-states[0]*1000.00)/10.0000))+16.0000/(1.00000+exp((30.0000+states[0]*1000.00)/10.0000))))*constants[47])/1000.00 rates[8] = (algebraic[5]-states[8])/algebraic[20] algebraic[11] = 1.00000/(1.00000+exp((states[0]*1000.00+77.8500)/5.00000)) algebraic[26] = (1900.00/(1.00000+exp((states[0]*1000.00+15.0000)/10.0000)))/1000.00 rates[13] = (algebraic[11]-states[13])/algebraic[26] algebraic[12] = 1.00000/(1.00000+exp((states[0]*1000.00+53.0000)/13.0000)) algebraic[27] = (6.06000+39.1020/(0.570000*exp(-0.0800000*(states[0]*1000.00+44.0000))+0.0650000*exp(0.100000*(states[0]*1000.00+45.9300))))/1000.00 rates[14] = (algebraic[12]-states[14])/algebraic[27] algebraic[13] = 1.00000/(1.00000+exp(-(states[0]*1000.00-22.3000)/18.7500)) algebraic[28] = (2.75352+14.4052/(1.03700*exp(0.0900000*(states[0]*1000.00+30.6100))+0.369000*exp(-0.120000*(states[0]*1000.00+23.8400))))/1000.00 rates[15] = (algebraic[13]-states[15])/algebraic[28] algebraic[14] = custom_piecewise([less_equal(states[2] , 0.000350000), 1.00000/(1.00000+power(states[2]/0.000350000, 6.00000)) , True, 1.00000/(1.00000+power(states[2]/0.000350000, 16.0000))]) algebraic[29] = custom_piecewise([greater(algebraic[14] , states[17]) & greater(states[0] , -0.0600000), 0.00000 , True, 1.00000]) rates[17] = (algebraic[29]*(algebraic[14]-states[17]))/constants[38] algebraic[4] = 1.00000/(1.00000+exp((states[0]*1000.00+25.2260)/3.00000)) algebraic[19] = custom_piecewise([greater(algebraic[4]-states[7] , 0.00000), 1.00000+1433.00*(states[2]-50.0000*1.00000e-06) , True, 1.00000]) algebraic[34] = ((20.0000+(1102.50*exp(-(power((power(states[0]*1000.00+27.0000, 2.00000))/15.0000, 2.00000)))+(200.000/(1.00000+exp((13.0000-states[0]*1000.00)/10.0000))+180.000/(1.00000+exp((30.0000+states[0]*1000.00)/10.0000)))))*algebraic[19])/1000.00 rates[7] = (algebraic[4]-states[7])/algebraic[34] algebraic[0] = 1.00000/(power(1.00000+exp((-states[0]*1000.00-34.1000)/5.90000), 1.00000/3.00000)) algebraic[15] = 1.00000/(1.00000+exp((-states[0]*1000.00-60.0000)/5.00000)) algebraic[30] = 0.100000/(1.00000+exp((states[0]*1000.00+35.0000)/5.00000))+0.100000/(1.00000+exp((states[0]*1000.00-50.0000)/200.000)) algebraic[40] = (1.00000*(algebraic[15]*algebraic[30]))/1000.00 rates[3] = (algebraic[0]-states[3])/algebraic[40] algebraic[1] = 1.00000/(power(1.00000+exp((states[0]*1000.00+72.1000)/5.70000), 1.0/2)) algebraic[16] = custom_piecewise([less(states[0] , -0.0400000), 0.0570000*exp(-(states[0]*1000.00+80.0000)/6.80000) , True, 0.00000]) algebraic[31] = custom_piecewise([less(states[0] , -0.0400000), 2.70000*exp(0.0790000*(states[0]*1000.00))+3.10000*((power(10.0000, 5.00000))*exp(0.348500*(states[0]*1000.00))) , True, 0.770000/(0.130000*(1.00000+exp((states[0]*1000.00+10.6600)/-11.1000)))]) algebraic[41] = custom_piecewise([less(states[0] , -0.0400000), 1.50000/((algebraic[16]+algebraic[31])*1000.00) , True, 2.54200/1000.00]) rates[4] = (algebraic[1]-states[4])/algebraic[41] algebraic[2] = 1.00000/(power(1.00000+exp((states[0]*1000.00+72.1000)/5.70000), 1.0/2)) algebraic[17] = custom_piecewise([less(states[0] , -0.0400000), ((-25428.0*exp(0.244400*(states[0]*1000.00))-6.94800*((power(10.0000, -6.00000))*exp(-0.0439100*(states[0]*1000.00))))*(states[0]*1000.00+37.7800))/(1.00000+exp(0.311000*(states[0]*1000.00+79.2300))) , True, 0.00000]) algebraic[32] = custom_piecewise([less(states[0] , -0.0400000), (0.0242400*exp(-0.0105200*(states[0]*1000.00)))/(1.00000+exp(-0.137800*(states[0]*1000.00+40.1400))) , True, (0.600000*exp(0.0570000*(states[0]*1000.00)))/(1.00000+exp(-0.100000*(states[0]*1000.00+32.0000)))]) algebraic[42] = 7.00000/((algebraic[17]+algebraic[32])*1000.00) rates[5] = (algebraic[2]-states[5])/algebraic[42] algebraic[7] = 1.00000/(1.00000+exp((constants[48]-states[0]*1000.00)/4.90000)) algebraic[22] = 450.000/(1.00000+exp((-45.0000-states[0]*1000.00)/10.0000)) algebraic[36] = 6.00000/(1.00000+exp((30.0000+states[0]*1000.00)/11.5000)) algebraic[45] = (1.00000*(algebraic[22]*algebraic[36]))/1000.00 rates[10] = (algebraic[7]-states[10])/algebraic[45] algebraic[8] = 1.00000/(1.00000+exp((states[0]*1000.00+88.0000)/50.0000)) algebraic[23] = 3.00000/(1.00000+exp((-60.0000-states[0]*1000.00)/20.0000)) algebraic[37] = 1.12000/(1.00000+exp((-60.0000+states[0]*1000.00)/20.0000)) algebraic[46] = (1.00000*(algebraic[23]*algebraic[37]))/1000.00 rates[11] = (algebraic[8]-states[11])/algebraic[46] algebraic[9] = 1.00000/(1.00000+exp((-states[0]*1000.00-20.0000)/16.0000)) algebraic[24] = 1100.00/(power(1.00000+exp((-10.0000-states[0]*1000.00)/6.00000), 1.0/2)) algebraic[38] = 1.00000/(1.00000+exp((-60.0000+states[0]*1000.00)/20.0000)) algebraic[47] = (1.00000*(algebraic[24]*algebraic[38]))/1000.00 rates[12] = (algebraic[9]-states[12])/algebraic[47] algebraic[3] = 1.00000/(1.00000+exp(-(states[0]*1000.00+5.98600)/7.00000)) algebraic[18] = 0.250000+1.40000/(1.00000+exp((-states[0]*1000.00-35.0000)/13.0000)) algebraic[33] = 1.40000/(1.00000+exp((states[0]*1000.00+5.00000)/5.00000)) algebraic[43] = 1.00000/(1.00000+exp((-states[0]*1000.00+50.0000)/20.0000)) algebraic[49] = ((algebraic[18]*algebraic[33]+algebraic[43])*1.00000)/1000.00 rates[6] = (algebraic[3]-states[6])/algebraic[49] algebraic[6] = 1.00000/(1.00000+power(states[2]/0.000600000, 8.00000)) algebraic[21] = 0.100000/(1.00000+exp((states[2]-0.000900000)/0.000100000)) algebraic[35] = 0.300000/(1.00000+exp((states[2]-0.000750000)/0.000800000)) algebraic[44] = (algebraic[6]+(algebraic[21]+algebraic[35]))/1.31560 algebraic[50] = custom_piecewise([greater(states[0] , -0.0600000) & greater(algebraic[44] , states[9]), 0.00000 , True, 1.00000]) rates[9] = (algebraic[50]*(algebraic[44]-states[9]))/constants[10] algebraic[10] = ((constants[0]*constants[1])/constants[2])*log(constants[3]/states[1]) algebraic[48] = constants[8]*((power(states[3], 3.00000))*(states[4]*(states[5]*(states[0]-algebraic[10])))) algebraic[61] = ((((constants[22]*constants[6])/(constants[6]+constants[20]))*states[1])/(states[1]+constants[21]))/(1.00000+(0.124500*exp((-0.100000*(states[0]*constants[2]))/(constants[0]*constants[1]))+0.0353000*exp((-states[0]*constants[2])/(constants[0]*constants[1])))) algebraic[62] = (constants[23]*(exp((constants[25]*(states[0]*constants[2]))/(constants[0]*constants[1]))*((power(states[1], 3.00000))*constants[4])-exp(((constants[25]-1.00000)*(states[0]*constants[2]))/(constants[0]*constants[1]))*((power(constants[3], 3.00000))*(states[2]*constants[24]))))/((power(constants[28], 3.00000)+power(constants[3], 3.00000))*((constants[27]+constants[4])*(1.00000+constants[26]*exp(((constants[25]-1.00000)*(states[0]*constants[2]))/(constants[0]*constants[1]))))) algebraic[59] = constants[18]*(states[0]-algebraic[10]) rates[1] = (-constants[32]*(algebraic[48]+(algebraic[59]+(3.00000*algebraic[61]+3.00000*algebraic[62]))))/(constants[2]*(constants[33]*1.00000e-18)) algebraic[51] = ((((constants[9]*(4.00000*(states[0]*(power(constants[2], 2.00000)))))/(constants[0]*constants[1]))*(states[2]*exp((2.00000*(states[0]*constants[2]))/(constants[0]*constants[1]))-0.341000*constants[4]))/(exp((2.00000*(states[0]*constants[2]))/(constants[0]*constants[1]))-1.00000))*(states[6]*(states[7]*(states[8]*states[9]))) algebraic[54] = 3.91000/(1.00000+exp(0.594200*((states[0]*1000.00-constants[46]*1000.00)-200.000))) algebraic[55] = (-1.50900*exp(0.000200000*((states[0]*1000.00-constants[46]*1000.00)+100.000))+exp(0.588600*((states[0]*1000.00-constants[46]*1000.00)-10.0000)))/(1.00000+exp(0.454700*(states[0]*1000.00-constants[46]*1000.00))) algebraic[56] = algebraic[54]/(algebraic[54]+algebraic[55]) algebraic[57] = constants[15]*(algebraic[56]*((states[0]-constants[46])*(power(constants[6]/5.40000, 1.0/2)))) algebraic[58] = constants[16]*(states[13]*(states[0]-constants[17])) algebraic[52] = constants[11]*((states[0]-constants[46])*(states[10]*(states[11]*(power(constants[6]/5.40000, 1.0/2))))) algebraic[25] = ((constants[0]*constants[1])/constants[2])*log((constants[6]+constants[7]*constants[3])/(constants[5]+constants[7]*states[1])) algebraic[53] = constants[14]*((states[0]-algebraic[25])*((power(states[12], 2.00000))*(1.00000+0.600000/(1.00000+power((3.80000*1.00000e-05)/states[2], 1.40000))))) algebraic[64] = constants[31]*((states[0]-constants[46])*(states[14]*states[15])) algebraic[63] = (constants[29]*states[2])/(states[2]+constants[30]) algebraic[39] = ((0.500000*(constants[0]*constants[1]))/constants[2])*log(constants[4]/states[2]) algebraic[60] = constants[19]*(states[0]-algebraic[39]) rates[0] = -(algebraic[57]+(algebraic[64]+(algebraic[52]+(algebraic[53]+(algebraic[51]+(algebraic[61]+(algebraic[48]+(algebraic[62]+(algebraic[63]+(algebraic[58]+(algebraic[59]+algebraic[60]))))))))))) algebraic[68] = 1.00000/(1.00000+(constants[40]*constants[42])/(power(states[2]+constants[42], 2.00000))) algebraic[65] = (constants[37]+(constants[35]*(power(states[16], 2.00000)))/(power(constants[36], 2.00000)+power(states[16], 2.00000)))*(states[6]*(states[17]*0.0556000)) algebraic[66] = constants[44]/(1.00000+(power(constants[39], 2.00000))/(power(states[2], 2.00000))) algebraic[67] = (states[16]-states[2])*constants[45] rates[2] = algebraic[68]*(((algebraic[67]-algebraic[66])+algebraic[65])-(((algebraic[51]+(algebraic[60]+algebraic[63]))-2.00000*algebraic[62])*constants[32])/(2.00000*(constants[33]*(constants[2]*1.00000e-18)))) algebraic[69] = 1.00000/(1.00000+(constants[41]*constants[43])/(power(states[16]+constants[43], 2.00000))) rates[16] = ((algebraic[69]*constants[33])/constants[34])*(algebraic[66]-(algebraic[65]+algebraic[67])) return(rates) def computeAlgebraic(constants, states, voi): algebraic = array([[0.0] * len(voi)] * sizeAlgebraic) states = array(states) voi = array(voi) algebraic[5] = 0.330000+0.670000/(1.00000+exp((states[0]*1000.00+31.2260)/4.00000)) algebraic[20] = ((600.000*exp(-(power(states[0]*1000.00+25.0000, 2.00000))/170.000)+(31.0000/(1.00000+exp((25.0000-states[0]*1000.00)/10.0000))+16.0000/(1.00000+exp((30.0000+states[0]*1000.00)/10.0000))))*constants[47])/1000.00 algebraic[11] = 1.00000/(1.00000+exp((states[0]*1000.00+77.8500)/5.00000)) algebraic[26] = (1900.00/(1.00000+exp((states[0]*1000.00+15.0000)/10.0000)))/1000.00 algebraic[12] = 1.00000/(1.00000+exp((states[0]*1000.00+53.0000)/13.0000)) algebraic[27] = (6.06000+39.1020/(0.570000*exp(-0.0800000*(states[0]*1000.00+44.0000))+0.0650000*exp(0.100000*(states[0]*1000.00+45.9300))))/1000.00 algebraic[13] = 1.00000/(1.00000+exp(-(states[0]*1000.00-22.3000)/18.7500)) algebraic[28] = (2.75352+14.4052/(1.03700*exp(0.0900000*(states[0]*1000.00+30.6100))+0.369000*exp(-0.120000*(states[0]*1000.00+23.8400))))/1000.00 algebraic[14] = custom_piecewise([less_equal(states[2] , 0.000350000), 1.00000/(1.00000+power(states[2]/0.000350000, 6.00000)) , True, 1.00000/(1.00000+power(states[2]/0.000350000, 16.0000))]) algebraic[29] = custom_piecewise([greater(algebraic[14] , states[17]) & greater(states[0] , -0.0600000), 0.00000 , True, 1.00000]) algebraic[4] = 1.00000/(1.00000+exp((states[0]*1000.00+25.2260)/3.00000)) algebraic[19] = custom_piecewise([greater(algebraic[4]-states[7] , 0.00000), 1.00000+1433.00*(states[2]-50.0000*1.00000e-06) , True, 1.00000]) algebraic[34] = ((20.0000+(1102.50*exp(-(power((power(states[0]*1000.00+27.0000, 2.00000))/15.0000, 2.00000)))+(200.000/(1.00000+exp((13.0000-states[0]*1000.00)/10.0000))+180.000/(1.00000+exp((30.0000+states[0]*1000.00)/10.0000)))))*algebraic[19])/1000.00 algebraic[0] = 1.00000/(power(1.00000+exp((-states[0]*1000.00-34.1000)/5.90000), 1.00000/3.00000)) algebraic[15] = 1.00000/(1.00000+exp((-states[0]*1000.00-60.0000)/5.00000)) algebraic[30] = 0.100000/(1.00000+exp((states[0]*1000.00+35.0000)/5.00000))+0.100000/(1.00000+exp((states[0]*1000.00-50.0000)/200.000)) algebraic[40] = (1.00000*(algebraic[15]*algebraic[30]))/1000.00 algebraic[1] = 1.00000/(power(1.00000+exp((states[0]*1000.00+72.1000)/5.70000), 1.0/2)) algebraic[16] = custom_piecewise([less(states[0] , -0.0400000), 0.0570000*exp(-(states[0]*1000.00+80.0000)/6.80000) , True, 0.00000]) algebraic[31] = custom_piecewise([less(states[0] , -0.0400000), 2.70000*exp(0.0790000*(states[0]*1000.00))+3.10000*((power(10.0000, 5.00000))*exp(0.348500*(states[0]*1000.00))) , True, 0.770000/(0.130000*(1.00000+exp((states[0]*1000.00+10.6600)/-11.1000)))]) algebraic[41] = custom_piecewise([less(states[0] , -0.0400000), 1.50000/((algebraic[16]+algebraic[31])*1000.00) , True, 2.54200/1000.00]) algebraic[2] = 1.00000/(power(1.00000+exp((states[0]*1000.00+72.1000)/5.70000), 1.0/2)) algebraic[17] = custom_piecewise([less(states[0] , -0.0400000), ((-25428.0*exp(0.244400*(states[0]*1000.00))-6.94800*((power(10.0000, -6.00000))*exp(-0.0439100*(states[0]*1000.00))))*(states[0]*1000.00+37.7800))/(1.00000+exp(0.311000*(states[0]*1000.00+79.2300))) , True, 0.00000]) algebraic[32] = custom_piecewise([less(states[0] , -0.0400000), (0.0242400*exp(-0.0105200*(states[0]*1000.00)))/(1.00000+exp(-0.137800*(states[0]*1000.00+40.1400))) , True, (0.600000*exp(0.0570000*(states[0]*1000.00)))/(1.00000+exp(-0.100000*(states[0]*1000.00+32.0000)))]) algebraic[42] = 7.00000/((algebraic[17]+algebraic[32])*1000.00) algebraic[7] = 1.00000/(1.00000+exp((constants[48]-states[0]*1000.00)/4.90000)) algebraic[22] = 450.000/(1.00000+exp((-45.0000-states[0]*1000.00)/10.0000)) algebraic[36] = 6.00000/(1.00000+exp((30.0000+states[0]*1000.00)/11.5000)) algebraic[45] = (1.00000*(algebraic[22]*algebraic[36]))/1000.00 algebraic[8] = 1.00000/(1.00000+exp((states[0]*1000.00+88.0000)/50.0000)) algebraic[23] = 3.00000/(1.00000+exp((-60.0000-states[0]*1000.00)/20.0000)) algebraic[37] = 1.12000/(1.00000+exp((-60.0000+states[0]*1000.00)/20.0000)) algebraic[46] = (1.00000*(algebraic[23]*algebraic[37]))/1000.00 algebraic[9] = 1.00000/(1.00000+exp((-states[0]*1000.00-20.0000)/16.0000)) algebraic[24] = 1100.00/(power(1.00000+exp((-10.0000-states[0]*1000.00)/6.00000), 1.0/2)) algebraic[38] = 1.00000/(1.00000+exp((-60.0000+states[0]*1000.00)/20.0000)) algebraic[47] = (1.00000*(algebraic[24]*algebraic[38]))/1000.00 algebraic[3] = 1.00000/(1.00000+exp(-(states[0]*1000.00+5.98600)/7.00000)) algebraic[18] = 0.250000+1.40000/(1.00000+exp((-states[0]*1000.00-35.0000)/13.0000)) algebraic[33] = 1.40000/(1.00000+exp((states[0]*1000.00+5.00000)/5.00000)) algebraic[43] = 1.00000/(1.00000+exp((-states[0]*1000.00+50.0000)/20.0000)) algebraic[49] = ((algebraic[18]*algebraic[33]+algebraic[43])*1.00000)/1000.00 algebraic[6] = 1.00000/(1.00000+power(states[2]/0.000600000, 8.00000)) algebraic[21] = 0.100000/(1.00000+exp((states[2]-0.000900000)/0.000100000)) algebraic[35] = 0.300000/(1.00000+exp((states[2]-0.000750000)/0.000800000)) algebraic[44] = (algebraic[6]+(algebraic[21]+algebraic[35]))/1.31560 algebraic[50] = custom_piecewise([greater(states[0] , -0.0600000) & greater(algebraic[44] , states[9]), 0.00000 , True, 1.00000]) algebraic[10] = ((constants[0]*constants[1])/constants[2])*log(constants[3]/states[1]) algebraic[48] = constants[8]*((power(states[3], 3.00000))*(states[4]*(states[5]*(states[0]-algebraic[10])))) algebraic[61] = ((((constants[22]*constants[6])/(constants[6]+constants[20]))*states[1])/(states[1]+constants[21]))/(1.00000+(0.124500*exp((-0.100000*(states[0]*constants[2]))/(constants[0]*constants[1]))+0.0353000*exp((-states[0]*constants[2])/(constants[0]*constants[1])))) algebraic[62] = (constants[23]*(exp((constants[25]*(states[0]*constants[2]))/(constants[0]*constants[1]))*((power(states[1], 3.00000))*constants[4])-exp(((constants[25]-1.00000)*(states[0]*constants[2]))/(constants[0]*constants[1]))*((power(constants[3], 3.00000))*(states[2]*constants[24]))))/((power(constants[28], 3.00000)+power(constants[3], 3.00000))*((constants[27]+constants[4])*(1.00000+constants[26]*exp(((constants[25]-1.00000)*(states[0]*constants[2]))/(constants[0]*constants[1]))))) algebraic[59] = constants[18]*(states[0]-algebraic[10]) algebraic[51] = ((((constants[9]*(4.00000*(states[0]*(power(constants[2], 2.00000)))))/(constants[0]*constants[1]))*(states[2]*exp((2.00000*(states[0]*constants[2]))/(constants[0]*constants[1]))-0.341000*constants[4]))/(exp((2.00000*(states[0]*constants[2]))/(constants[0]*constants[1]))-1.00000))*(states[6]*(states[7]*(states[8]*states[9]))) algebraic[54] = 3.91000/(1.00000+exp(0.594200*((states[0]*1000.00-constants[46]*1000.00)-200.000))) algebraic[55] = (-1.50900*exp(0.000200000*((states[0]*1000.00-constants[46]*1000.00)+100.000))+exp(0.588600*((states[0]*1000.00-constants[46]*1000.00)-10.0000)))/(1.00000+exp(0.454700*(states[0]*1000.00-constants[46]*1000.00))) algebraic[56] = algebraic[54]/(algebraic[54]+algebraic[55]) algebraic[57] = constants[15]*(algebraic[56]*((states[0]-constants[46])*(power(constants[6]/5.40000, 1.0/2)))) algebraic[58] = constants[16]*(states[13]*(states[0]-constants[17])) algebraic[52] = constants[11]*((states[0]-constants[46])*(states[10]*(states[11]*(power(constants[6]/5.40000, 1.0/2))))) algebraic[25] = ((constants[0]*constants[1])/constants[2])*log((constants[6]+constants[7]*constants[3])/(constants[5]+constants[7]*states[1])) algebraic[53] = constants[14]*((states[0]-algebraic[25])*((power(states[12], 2.00000))*(1.00000+0.600000/(1.00000+power((3.80000*1.00000e-05)/states[2], 1.40000))))) algebraic[64] = constants[31]*((states[0]-constants[46])*(states[14]*states[15])) algebraic[63] = (constants[29]*states[2])/(states[2]+constants[30]) algebraic[39] = ((0.500000*(constants[0]*constants[1]))/constants[2])*log(constants[4]/states[2]) algebraic[60] = constants[19]*(states[0]-algebraic[39]) algebraic[68] = 1.00000/(1.00000+(constants[40]*constants[42])/(power(states[2]+constants[42], 2.00000))) algebraic[65] = (constants[37]+(constants[35]*(power(states[16], 2.00000)))/(power(constants[36], 2.00000)+power(states[16], 2.00000)))*(states[6]*(states[17]*0.0556000)) algebraic[66] = constants[44]/(1.00000+(power(constants[39], 2.00000))/(power(states[2], 2.00000))) algebraic[67] = (states[16]-states[2])*constants[45] algebraic[69] = 1.00000/(1.00000+(constants[41]*constants[43])/(power(states[16]+constants[43], 2.00000))) 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)