# Size of variable arrays: sizeAlgebraic = 55 sizeStates = 24 sizeConstants = 72 from math import * from numpy import * def createLegends(): legend_states = [""] * sizeStates legend_rates = [""] * sizeStates legend_algebraic = [""] * sizeAlgebraic legend_voi = "" legend_constants = [""] * sizeConstants legend_voi = "time in component environment (second)" legend_states[0] = "V in component membrane (millivolt)" legend_constants[0] = "R in component membrane (millijoule_per_mole_kelvin)" legend_constants[1] = "T in component membrane (kelvin)" legend_constants[2] = "F in component membrane (coulomb_per_mole)" legend_constants[3] = "Cm in component membrane (microF)" legend_algebraic[26] = "i_Na in component sodium_current (nanoA)" legend_algebraic[27] = "i_Ca_L in component L_type_Ca_channel (nanoA)" legend_algebraic[29] = "i_t in component Ca_independent_transient_outward_K_current (nanoA)" legend_algebraic[30] = "i_ss in component steady_state_outward_K_current (nanoA)" legend_algebraic[34] = "i_f in component hyperpolarisation_activated_current (nanoA)" legend_algebraic[31] = "i_K1 in component inward_rectifier (nanoA)" legend_algebraic[39] = "i_B in component background_currents (nanoA)" legend_algebraic[40] = "i_NaK in component sodium_potassium_pump (nanoA)" legend_algebraic[42] = "i_NaCa in component Na_Ca_ion_exchanger_current (nanoA)" legend_algebraic[41] = "i_Ca_P in component sarcolemmal_calcium_pump_current (nanoA)" legend_algebraic[13] = "i_Stim in component membrane (nanoA)" legend_constants[4] = "stim_start in component membrane (second)" legend_constants[5] = "stim_end in component membrane (second)" legend_constants[6] = "stim_period in component membrane (second)" legend_constants[7] = "stim_duration in component membrane (second)" legend_constants[8] = "stim_amplitude in component membrane (nanoA)" legend_algebraic[25] = "E_Na in component sodium_current (millivolt)" legend_constants[9] = "g_Na in component sodium_current (microS)" legend_states[1] = "Na_i in component intracellular_ion_concentrations (millimolar)" legend_constants[10] = "Na_o in component standard_ionic_concentrations (millimolar)" legend_states[2] = "m in component sodium_current_m_gate (dimensionless)" legend_states[3] = "h in component sodium_current_h_gate (dimensionless)" legend_states[4] = "j in component sodium_current_j_gate (dimensionless)" legend_algebraic[0] = "m_infinity in component sodium_current_m_gate (dimensionless)" legend_algebraic[14] = "tau_m in component sodium_current_m_gate (second)" legend_algebraic[1] = "h_infinity in component sodium_current_h_gate (dimensionless)" legend_algebraic[15] = "tau_h in component sodium_current_h_gate (second)" legend_algebraic[2] = "j_infinity in component sodium_current_j_gate (dimensionless)" legend_algebraic[16] = "tau_j in component sodium_current_j_gate (second)" legend_constants[11] = "g_Ca_L in component L_type_Ca_channel (microS)" legend_constants[12] = "E_Ca_L in component L_type_Ca_channel (millivolt)" legend_states[5] = "Ca_ss in component intracellular_ion_concentrations (millimolar)" legend_states[6] = "d in component L_type_Ca_channel_d_gate (dimensionless)" legend_states[7] = "f_11 in component L_type_Ca_channel_f_11_gate (dimensionless)" legend_states[8] = "f_12 in component L_type_Ca_channel_f_12_gate (dimensionless)" legend_states[9] = "Ca_inact in component L_type_Ca_channel_Ca_inact_gate (dimensionless)" legend_algebraic[3] = "d_infinity in component L_type_Ca_channel_d_gate (dimensionless)" legend_algebraic[17] = "tau_d in component L_type_Ca_channel_d_gate (second)" legend_algebraic[4] = "f_11_infinity in component L_type_Ca_channel_f_11_gate (dimensionless)" legend_algebraic[18] = "tau_f_11 in component L_type_Ca_channel_f_11_gate (second)" legend_algebraic[5] = "f_12_infinity in component L_type_Ca_channel_f_12_gate (dimensionless)" legend_algebraic[19] = "tau_f_12 in component L_type_Ca_channel_f_12_gate (second)" legend_constants[13] = "tau_Ca_inact in component L_type_Ca_channel_Ca_inact_gate (second)" legend_algebraic[6] = "Ca_inact_infinity in component L_type_Ca_channel_Ca_inact_gate (dimensionless)" legend_algebraic[28] = "E_K in component Ca_independent_transient_outward_K_current (millivolt)" legend_constants[14] = "g_t in component Ca_independent_transient_outward_K_current (microS)" legend_constants[15] = "a in component Ca_independent_transient_outward_K_current (dimensionless)" legend_constants[16] = "b in component Ca_independent_transient_outward_K_current (dimensionless)" legend_constants[17] = "K_o in component standard_ionic_concentrations (millimolar)" legend_states[10] = "K_i in component intracellular_ion_concentrations (millimolar)" legend_states[11] = "r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)" legend_states[12] = "s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)" legend_states[13] = "s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)" legend_algebraic[20] = "tau_r in component Ca_independent_transient_outward_K_current_r_gate (second)" legend_algebraic[7] = "r_infinity in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)" legend_algebraic[21] = "tau_s in component Ca_independent_transient_outward_K_current_s_gate (second)" legend_algebraic[8] = "s_infinity in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)" legend_algebraic[22] = "tau_s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (second)" legend_algebraic[9] = "s_slow_infinity in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)" legend_constants[18] = "g_ss in component steady_state_outward_K_current (microS)" legend_states[14] = "r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)" legend_states[15] = "s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)" legend_algebraic[23] = "tau_r_ss in component steady_state_outward_K_current_r_ss_gate (second)" legend_algebraic[10] = "r_ss_infinity in component steady_state_outward_K_current_r_ss_gate (dimensionless)" legend_constants[69] = "tau_s_ss in component steady_state_outward_K_current_s_ss_gate (second)" legend_algebraic[11] = "s_ss_infinity in component steady_state_outward_K_current_s_ss_gate (dimensionless)" legend_constants[19] = "g_K1 in component inward_rectifier (microS)" legend_algebraic[32] = "i_f_Na in component hyperpolarisation_activated_current (nanoA)" legend_algebraic[33] = "i_f_K in component hyperpolarisation_activated_current (nanoA)" legend_constants[20] = "g_f in component hyperpolarisation_activated_current (microS)" legend_constants[21] = "f_Na in component hyperpolarisation_activated_current (dimensionless)" legend_constants[70] = "f_K in component hyperpolarisation_activated_current (dimensionless)" legend_states[16] = "y in component hyperpolarisation_activated_current_y_gate (dimensionless)" legend_algebraic[24] = "tau_y in component hyperpolarisation_activated_current_y_gate (second)" legend_algebraic[12] = "y_infinity in component hyperpolarisation_activated_current_y_gate (dimensionless)" legend_algebraic[36] = "i_B_Na in component background_currents (nanoA)" legend_algebraic[37] = "i_B_Ca in component background_currents (nanoA)" legend_algebraic[38] = "i_B_K in component background_currents (nanoA)" legend_constants[22] = "g_B_Na in component background_currents (microS)" legend_constants[23] = "g_B_Ca in component background_currents (microS)" legend_constants[24] = "g_B_K in component background_currents (microS)" legend_algebraic[35] = "E_Ca in component background_currents (millivolt)" legend_constants[25] = "Ca_o in component standard_ionic_concentrations (millimolar)" legend_states[17] = "Ca_i in component intracellular_ion_concentrations (millimolar)" legend_constants[26] = "i_NaK_max in component sodium_potassium_pump (nanoA)" legend_constants[27] = "K_m_K in component sodium_potassium_pump (millimolar)" legend_constants[28] = "K_m_Na in component sodium_potassium_pump (millimolar)" legend_constants[71] = "sigma in component sodium_potassium_pump (dimensionless)" legend_constants[29] = "i_Ca_P_max in component sarcolemmal_calcium_pump_current (nanoA)" legend_constants[30] = "K_NaCa in component Na_Ca_ion_exchanger_current (millimolar_4)" legend_constants[31] = "d_NaCa in component Na_Ca_ion_exchanger_current (millimolar_4)" legend_constants[32] = "gamma_NaCa in component Na_Ca_ion_exchanger_current (dimensionless)" legend_algebraic[43] = "J_rel in component SR_Ca_release_channel (millimolar_per_second)" legend_constants[33] = "v1 in component SR_Ca_release_channel (per_second)" legend_constants[34] = "k_a_plus in component SR_Ca_release_channel (millimolar4_per_second)" legend_constants[35] = "k_a_minus in component SR_Ca_release_channel (per_second)" legend_constants[36] = "k_b_plus in component SR_Ca_release_channel (millimolar3_per_second)" legend_constants[37] = "k_b_minus in component SR_Ca_release_channel (per_second)" legend_constants[38] = "k_c_plus in component SR_Ca_release_channel (per_second)" legend_constants[39] = "k_c_minus in component SR_Ca_release_channel (per_second)" legend_states[18] = "P_O1 in component SR_Ca_release_channel (dimensionless)" legend_states[19] = "P_O2 in component SR_Ca_release_channel (dimensionless)" legend_states[20] = "P_C1 in component SR_Ca_release_channel (dimensionless)" legend_states[21] = "P_C2 in component SR_Ca_release_channel (dimensionless)" legend_constants[40] = "n in component SR_Ca_release_channel (dimensionless)" legend_constants[41] = "m in component SR_Ca_release_channel (dimensionless)" legend_states[22] = "Ca_JSR in component intracellular_ion_concentrations (millimolar)" legend_algebraic[46] = "J_up in component SERCA2a_pump (millimolar_per_second)" legend_constants[42] = "K_fb in component SERCA2a_pump (millimolar)" legend_constants[43] = "K_rb in component SERCA2a_pump (millimolar)" legend_algebraic[44] = "fb in component SERCA2a_pump (dimensionless)" legend_algebraic[45] = "rb in component SERCA2a_pump (dimensionless)" legend_constants[44] = "Vmaxf in component SERCA2a_pump (millimolar_per_second)" legend_constants[45] = "Vmaxr in component SERCA2a_pump (millimolar_per_second)" legend_constants[46] = "K_SR in component SERCA2a_pump (dimensionless)" legend_constants[47] = "N_fb in component SERCA2a_pump (dimensionless)" legend_constants[48] = "N_rb in component SERCA2a_pump (dimensionless)" legend_states[23] = "Ca_NSR in component intracellular_ion_concentrations (millimolar)" legend_algebraic[48] = "J_tr in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)" legend_algebraic[47] = "J_xfer in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)" legend_algebraic[53] = "J_trpn in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)" legend_constants[49] = "tau_tr in component intracellular_and_SR_Ca_fluxes (second)" legend_constants[50] = "tau_xfer in component intracellular_and_SR_Ca_fluxes (second)" legend_constants[51] = "HTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar)" legend_constants[52] = "LTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar)" legend_algebraic[49] = "J_HTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)" legend_algebraic[52] = "J_LTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)" legend_constants[53] = "HTRPN_tot in component intracellular_and_SR_Ca_fluxes (millimolar)" legend_constants[54] = "LTRPN_tot in component intracellular_and_SR_Ca_fluxes (millimolar)" legend_constants[55] = "k_htrpn_plus in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)" legend_constants[56] = "k_htrpn_minus in component intracellular_and_SR_Ca_fluxes (per_second)" legend_constants[57] = "k_ltrpn_plus in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)" legend_constants[58] = "k_ltrpn_minus in component intracellular_and_SR_Ca_fluxes (per_second)" legend_constants[59] = "V_myo in component intracellular_ion_concentrations (pico_litre)" legend_constants[60] = "V_JSR in component intracellular_ion_concentrations (pico_litre)" legend_constants[61] = "V_NSR in component intracellular_ion_concentrations (pico_litre)" legend_constants[62] = "V_SS in component intracellular_ion_concentrations (pico_litre)" legend_constants[63] = "K_mCMDN in component intracellular_ion_concentrations (millimolar)" legend_constants[64] = "K_mCSQN in component intracellular_ion_concentrations (millimolar)" legend_constants[65] = "K_mEGTA in component intracellular_ion_concentrations (millimolar)" legend_constants[66] = "CMDN_tot in component intracellular_ion_concentrations (millimolar)" legend_constants[67] = "CSQN_tot in component intracellular_ion_concentrations (millimolar)" legend_constants[68] = "EGTA_tot in component intracellular_ion_concentrations (millimolar)" legend_algebraic[54] = "beta_i in component intracellular_ion_concentrations (millimolar)" legend_algebraic[50] = "beta_SS in component intracellular_ion_concentrations (millimolar)" legend_algebraic[51] = "beta_JSR in component intracellular_ion_concentrations (millimolar)" legend_rates[0] = "d/dt V in component membrane (millivolt)" legend_rates[2] = "d/dt m in component sodium_current_m_gate (dimensionless)" legend_rates[3] = "d/dt h in component sodium_current_h_gate (dimensionless)" legend_rates[4] = "d/dt j in component sodium_current_j_gate (dimensionless)" legend_rates[6] = "d/dt d in component L_type_Ca_channel_d_gate (dimensionless)" legend_rates[7] = "d/dt f_11 in component L_type_Ca_channel_f_11_gate (dimensionless)" legend_rates[8] = "d/dt f_12 in component L_type_Ca_channel_f_12_gate (dimensionless)" legend_rates[9] = "d/dt Ca_inact in component L_type_Ca_channel_Ca_inact_gate (dimensionless)" legend_rates[11] = "d/dt r in component Ca_independent_transient_outward_K_current_r_gate (dimensionless)" legend_rates[12] = "d/dt s in component Ca_independent_transient_outward_K_current_s_gate (dimensionless)" legend_rates[13] = "d/dt s_slow in component Ca_independent_transient_outward_K_current_s_slow_gate (dimensionless)" legend_rates[14] = "d/dt r_ss in component steady_state_outward_K_current_r_ss_gate (dimensionless)" legend_rates[15] = "d/dt s_ss in component steady_state_outward_K_current_s_ss_gate (dimensionless)" legend_rates[16] = "d/dt y in component hyperpolarisation_activated_current_y_gate (dimensionless)" legend_rates[20] = "d/dt P_C1 in component SR_Ca_release_channel (dimensionless)" legend_rates[18] = "d/dt P_O1 in component SR_Ca_release_channel (dimensionless)" legend_rates[19] = "d/dt P_O2 in component SR_Ca_release_channel (dimensionless)" legend_rates[21] = "d/dt P_C2 in component SR_Ca_release_channel (dimensionless)" legend_rates[17] = "d/dt Ca_i in component intracellular_ion_concentrations (millimolar)" legend_rates[1] = "d/dt Na_i in component intracellular_ion_concentrations (millimolar)" legend_rates[10] = "d/dt K_i in component intracellular_ion_concentrations (millimolar)" legend_rates[5] = "d/dt Ca_ss in component intracellular_ion_concentrations (millimolar)" legend_rates[22] = "d/dt Ca_JSR in component intracellular_ion_concentrations (millimolar)" legend_rates[23] = "d/dt Ca_NSR in component intracellular_ion_concentrations (millimolar)" return (legend_states, legend_algebraic, legend_voi, legend_constants) def initConsts(): constants = [0.0] * sizeConstants; states = [0.0] * sizeStates; states[0] = -80.50146 constants[0] = 8314.5 constants[1] = 295 constants[2] = 96487 constants[3] = 0.0001 constants[4] = 1 constants[5] = 10 constants[6] = 1 constants[7] = 0.005 constants[8] = -0.6 constants[9] = 0.8 states[1] = 10.73519 constants[10] = 140 states[2] = 0.004164108 states[3] = 0.6735613 states[4] = 0.6729362 constants[11] = 0.031 constants[12] = 65 states[5] = 0.00008737212 states[6] = 0.000002171081 states[7] = 0.9999529 states[8] = 0.9999529 states[9] = 0.9913102 constants[13] = 0.009 constants[14] = 0.035 constants[15] = 0.886 constants[16] = 0.114 constants[17] = 5.4 states[10] = 139.2751 states[11] = 0.002191519 states[12] = 0.9842542 states[13] = 0.6421196 constants[18] = 0.007 states[14] = 0.002907171 states[15] = 0.3142767 constants[19] = 0.024 constants[20] = 0.00145 constants[21] = 0.2 states[16] = 0.003578708 constants[22] = 0.00008015 constants[23] = 0.0000324 constants[24] = 0.000138 constants[25] = 1.2 states[17] = 0.00007901351 constants[26] = 0.08 constants[27] = 1.5 constants[28] = 10 constants[29] = 0.004 constants[30] = 0.000009984 constants[31] = 0.0001 constants[32] = 0.5 constants[33] = 1.8e3 constants[34] = 12.15e12 constants[35] = 576 constants[36] = 4.05e9 constants[37] = 1930 constants[38] = 100 constants[39] = 0.8 states[18] = 0.0004327548 states[19] = 0.000000000606254 states[20] = 0.6348229 states[21] = 0.3647471 constants[40] = 4 constants[41] = 3 states[22] = 0.06607948 constants[42] = 0.000168 constants[43] = 3.29 constants[44] = 0.04 constants[45] = 0.9 constants[46] = 1 constants[47] = 1.2 constants[48] = 1 states[23] = 0.06600742 constants[49] = 0.0005747 constants[50] = 0.0267 constants[51] = 1.394301e-1 constants[52] = 5.1619e-3 constants[53] = 0.14 constants[54] = 0.07 constants[55] = 200000 constants[56] = 0.066 constants[57] = 40000 constants[58] = 40 constants[59] = 0.00000936 constants[60] = 0.000000056 constants[61] = 0.000000504 constants[62] = 0.0000000012 constants[63] = 0.00238 constants[64] = 0.8 constants[65] = 0.00015 constants[66] = 0.05 constants[67] = 15 constants[68] = 10 constants[69] = 2.10000 constants[70] = 1.00000-constants[21] constants[71] = (exp(constants[10]/67.3000)-1.00000)/7.00000 return (states, constants) def computeRates(voi, states, constants): rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic rates[20] = -constants[34]*(power(states[5], constants[40]))*states[20]+constants[35]*states[18] rates[18] = (constants[34]*(power(states[5], constants[40]))*states[20]-(constants[35]*states[18]+constants[36]*(power(states[5], constants[41]))*states[18]+constants[38]*states[18]))+constants[37]*states[19]+constants[39]*states[21] rates[19] = constants[36]*(power(states[5], constants[41]))*states[18]-constants[37]*states[19] rates[21] = constants[38]*states[18]-constants[39]*states[21] algebraic[6] = 1.00000/(1.00000+states[5]/0.0100000) rates[9] = (algebraic[6]-states[9])/constants[13] algebraic[11] = 1.00000/(1.00000+exp((states[0]+87.5000)/10.3000)) rates[15] = (algebraic[11]-states[15])/constants[69] algebraic[0] = 1.00000/(1.00000+exp((states[0]+45.0000)/-6.50000)) algebraic[14] = 0.00136000/((0.320000*(states[0]+47.1300))/(1.00000-exp(-0.100000*(states[0]+47.1300)))+0.0800000*exp(-states[0]/11.0000)) rates[2] = (algebraic[0]-states[2])/algebraic[14] algebraic[1] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000)) algebraic[15] = custom_piecewise([greater_equal(states[0] , -40.0000), 0.000453700*(1.00000+exp(-(states[0]+10.6600)/11.1000)) , True, 0.00349000/(0.135000*exp(-(states[0]+80.0000)/6.80000)+3.56000*exp(0.0790000*states[0])+310000.*exp(0.350000*states[0]))]) rates[3] = (algebraic[1]-states[3])/algebraic[15] algebraic[2] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000)) algebraic[16] = custom_piecewise([greater_equal(states[0] , -40.0000), (0.0116300*(1.00000+exp(-0.100000*(states[0]+32.0000))))/exp(-2.53500e-07*states[0]) , True, 0.00349000/(((states[0]+37.7800)/(1.00000+exp(0.311000*(states[0]+79.2300))))*(-127140.*exp(0.244400*states[0])-3.47400e-05*exp(-0.0439100*states[0]))+(0.121200*exp(-0.0105200*states[0]))/(1.00000+exp(-0.137800*(states[0]+40.1400))))]) rates[4] = (algebraic[2]-states[4])/algebraic[16] algebraic[3] = 1.00000/(1.00000+exp((states[0]+15.3000)/-5.00000)) algebraic[17] = 0.00305000*exp(-0.00450000*(power(states[0]+7.00000, 2.00000)))+0.00105000*exp(-0.00200000*(power(states[0]-18.0000, 2.00000)))+0.000250000 rates[6] = (algebraic[3]-states[6])/algebraic[17] algebraic[4] = 1.00000/(1.00000+exp((states[0]+26.7000)/5.40000)) algebraic[18] = 0.105000*exp(-(power((states[0]+45.0000)/12.0000, 2.00000)))+0.0400000/(1.00000+exp((-states[0]+25.0000)/25.0000))+0.0150000/(1.00000+exp((states[0]+75.0000)/25.0000))+0.00170000 rates[7] = (algebraic[4]-states[7])/algebraic[18] algebraic[5] = 1.00000/(1.00000+exp((states[0]+26.7000)/5.40000)) algebraic[19] = 0.0410000*exp(-(power((states[0]+47.0000)/12.0000, 2.00000)))+0.0800000/(1.00000+exp((states[0]+55.0000)/-5.00000))+0.0150000/(1.00000+exp((states[0]+75.0000)/25.0000))+0.00170000 rates[8] = (algebraic[5]-states[8])/algebraic[19] algebraic[20] = 1.00000/(45.1600*exp(0.0357700*(states[0]+50.0000))+98.9000*exp(-0.100000*(states[0]+38.0000))) algebraic[7] = 1.00000/(1.00000+exp((states[0]+10.6000)/-11.4200)) rates[11] = (algebraic[7]-states[11])/algebraic[20] algebraic[21] = 0.350000*exp(-(power((states[0]+70.0000)/15.0000, 2.00000)))+0.0350000 algebraic[8] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410)) rates[12] = (algebraic[8]-states[12])/algebraic[21] algebraic[22] = 3.70000*exp(-(power((states[0]+70.0000)/30.0000, 2.00000)))+0.0350000 algebraic[9] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410)) rates[13] = (algebraic[9]-states[13])/algebraic[22] algebraic[23] = 10.0000/(45.1600*exp(0.0357700*(states[0]+50.0000))+98.9000*exp(-0.100000*(states[0]+38.0000))) algebraic[10] = 1.00000/(1.00000+exp((states[0]+11.5000)/-11.8200)) rates[14] = (algebraic[10]-states[14])/algebraic[23] algebraic[24] = 1.00000/(0.118850*exp((states[0]+80.0000)/28.3700)+0.562300*exp((states[0]+80.0000)/-14.1900)) algebraic[12] = 1.00000/(1.00000+exp((states[0]+138.600)/10.4800)) rates[16] = (algebraic[12]-states[16])/algebraic[24] algebraic[28] = ((constants[0]*constants[1])/constants[2])*log(constants[17]/states[10]) algebraic[29] = constants[14]*states[11]*(constants[15]*states[12]+constants[16]*states[13])*(states[0]-algebraic[28]) algebraic[30] = constants[18]*states[14]*states[15]*(states[0]-algebraic[28]) algebraic[31] = ((48.0000/(exp((states[0]+37.0000)/25.0000)+exp((states[0]+37.0000)/-25.0000))+10.0000)*0.00100000)/(1.00000+exp((states[0]-(algebraic[28]+76.7700))/-17.0000))+(constants[19]*(states[0]-(algebraic[28]+1.73000)))/((1.00000+exp((1.61300*constants[2]*(states[0]-(algebraic[28]+1.73000)))/(constants[0]*constants[1])))*(1.00000+exp((constants[17]-0.998800)/-0.124000))) algebraic[40] = (((((constants[26]*1.00000)/(1.00000+0.124500*exp((-0.100000*states[0]*constants[2])/(constants[0]*constants[1]))+0.0365000*constants[71]*exp((-states[0]*constants[2])/(constants[0]*constants[1]))))*constants[17])/(constants[17]+constants[27]))*1.00000)/(1.00000+power(constants[28]/states[1], 1.50000)) algebraic[33] = constants[20]*states[16]*constants[70]*(states[0]-algebraic[28]) algebraic[38] = constants[24]*(states[0]-algebraic[28]) rates[10] = (-(algebraic[30]+algebraic[38]+algebraic[29]+algebraic[31]+algebraic[33]+algebraic[40]*-2.00000)*1.00000)/(constants[59]*constants[2]) algebraic[25] = ((constants[0]*constants[1])/constants[2])*log(constants[10]/states[1]) algebraic[26] = constants[9]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[25]) algebraic[27] = constants[11]*states[6]*((0.900000+states[9]/10.0000)*states[7]+(0.100000-states[9]/10.0000)*states[8])*(states[0]-constants[12]) algebraic[32] = constants[20]*states[16]*constants[21]*(states[0]-algebraic[25]) algebraic[34] = algebraic[32]+algebraic[33] algebraic[36] = constants[22]*(states[0]-algebraic[25]) algebraic[35] = ((0.500000*constants[0]*constants[1])/constants[2])*log(constants[25]/states[17]) algebraic[37] = constants[23]*(states[0]-algebraic[35]) algebraic[39] = algebraic[36]+algebraic[37]+algebraic[38] algebraic[42] = (constants[30]*((power(states[1], 3.00000))*constants[25]*exp(0.0374300*states[0]*constants[32])-(power(constants[10], 3.00000))*states[17]*exp(0.0374300*states[0]*(constants[32]-1.00000))))/(1.00000+constants[31]*(states[17]*(power(constants[10], 3.00000))+constants[25]*(power(states[1], 3.00000)))) algebraic[41] = (constants[29]*states[17])/(states[17]+0.000400000) algebraic[13] = custom_piecewise([greater_equal(voi , constants[4]) & less_equal(voi , constants[5]) & less_equal((voi-constants[4])-floor((voi-constants[4])/constants[6])*constants[6] , constants[7]), constants[8] , True, 0.00000]) rates[0] = -(algebraic[26]+algebraic[27]+algebraic[29]+algebraic[30]+algebraic[34]+algebraic[31]+algebraic[39]+algebraic[40]+algebraic[42]+algebraic[41]+algebraic[13])/constants[3] rates[1] = (-(algebraic[26]+algebraic[36]+algebraic[42]*3.00000+algebraic[40]*3.00000+algebraic[32])*1.00000)/(constants[59]*constants[2]) algebraic[44] = power(states[17]/constants[42], constants[47]) algebraic[45] = power(states[23]/constants[43], constants[48]) algebraic[46] = (constants[46]*(constants[44]*algebraic[44]-constants[45]*algebraic[45]))/(1.00000+algebraic[44]+algebraic[45]) algebraic[48] = (states[23]-states[22])/constants[49] rates[23] = (algebraic[46]*constants[59])/constants[61]-(algebraic[48]*constants[60])/constants[61] algebraic[43] = constants[33]*(states[18]+states[19])*(states[22]-states[5]) algebraic[47] = (states[5]-states[17])/constants[50] algebraic[50] = 1.00000/(1.00000+(constants[66]*constants[63])/(power(constants[63]+states[5], 2.00000))) rates[5] = algebraic[50]*(((algebraic[43]*constants[60])/constants[62]-(algebraic[47]*constants[59])/constants[62])-(algebraic[27]*1.00000)/(2.00000*constants[62]*constants[2])) algebraic[51] = 1.00000/(1.00000+(constants[67]*constants[64])/(power(constants[64]+states[22], 2.00000))) rates[22] = algebraic[51]*(algebraic[48]-algebraic[43]) algebraic[49] = constants[55]*states[17]*(constants[53]-constants[51])-constants[56]*constants[51] algebraic[52] = constants[57]*states[17]*(constants[54]-constants[52])-constants[58]*constants[52] algebraic[53] = algebraic[49]+algebraic[52] algebraic[54] = 1.00000/(1.00000+(constants[66]*constants[63])/(power(constants[63]+states[17], 2.00000))+(constants[68]*constants[65])/(power(constants[65]+states[17], 2.00000))) rates[17] = algebraic[54]*(algebraic[47]-(algebraic[46]+algebraic[53]+(((algebraic[37]-2.00000*algebraic[42])+algebraic[41])*1.00000)/(2.00000*constants[59]*constants[2]))) return(rates) def computeAlgebraic(constants, states, voi): algebraic = array([[0.0] * len(voi)] * sizeAlgebraic) states = array(states) voi = array(voi) algebraic[6] = 1.00000/(1.00000+states[5]/0.0100000) algebraic[11] = 1.00000/(1.00000+exp((states[0]+87.5000)/10.3000)) algebraic[0] = 1.00000/(1.00000+exp((states[0]+45.0000)/-6.50000)) algebraic[14] = 0.00136000/((0.320000*(states[0]+47.1300))/(1.00000-exp(-0.100000*(states[0]+47.1300)))+0.0800000*exp(-states[0]/11.0000)) algebraic[1] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000)) algebraic[15] = custom_piecewise([greater_equal(states[0] , -40.0000), 0.000453700*(1.00000+exp(-(states[0]+10.6600)/11.1000)) , True, 0.00349000/(0.135000*exp(-(states[0]+80.0000)/6.80000)+3.56000*exp(0.0790000*states[0])+310000.*exp(0.350000*states[0]))]) algebraic[2] = 1.00000/(1.00000+exp((states[0]+76.1000)/6.07000)) algebraic[16] = custom_piecewise([greater_equal(states[0] , -40.0000), (0.0116300*(1.00000+exp(-0.100000*(states[0]+32.0000))))/exp(-2.53500e-07*states[0]) , True, 0.00349000/(((states[0]+37.7800)/(1.00000+exp(0.311000*(states[0]+79.2300))))*(-127140.*exp(0.244400*states[0])-3.47400e-05*exp(-0.0439100*states[0]))+(0.121200*exp(-0.0105200*states[0]))/(1.00000+exp(-0.137800*(states[0]+40.1400))))]) algebraic[3] = 1.00000/(1.00000+exp((states[0]+15.3000)/-5.00000)) algebraic[17] = 0.00305000*exp(-0.00450000*(power(states[0]+7.00000, 2.00000)))+0.00105000*exp(-0.00200000*(power(states[0]-18.0000, 2.00000)))+0.000250000 algebraic[4] = 1.00000/(1.00000+exp((states[0]+26.7000)/5.40000)) algebraic[18] = 0.105000*exp(-(power((states[0]+45.0000)/12.0000, 2.00000)))+0.0400000/(1.00000+exp((-states[0]+25.0000)/25.0000))+0.0150000/(1.00000+exp((states[0]+75.0000)/25.0000))+0.00170000 algebraic[5] = 1.00000/(1.00000+exp((states[0]+26.7000)/5.40000)) algebraic[19] = 0.0410000*exp(-(power((states[0]+47.0000)/12.0000, 2.00000)))+0.0800000/(1.00000+exp((states[0]+55.0000)/-5.00000))+0.0150000/(1.00000+exp((states[0]+75.0000)/25.0000))+0.00170000 algebraic[20] = 1.00000/(45.1600*exp(0.0357700*(states[0]+50.0000))+98.9000*exp(-0.100000*(states[0]+38.0000))) algebraic[7] = 1.00000/(1.00000+exp((states[0]+10.6000)/-11.4200)) algebraic[21] = 0.350000*exp(-(power((states[0]+70.0000)/15.0000, 2.00000)))+0.0350000 algebraic[8] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410)) algebraic[22] = 3.70000*exp(-(power((states[0]+70.0000)/30.0000, 2.00000)))+0.0350000 algebraic[9] = 1.00000/(1.00000+exp((states[0]+45.3000)/6.88410)) algebraic[23] = 10.0000/(45.1600*exp(0.0357700*(states[0]+50.0000))+98.9000*exp(-0.100000*(states[0]+38.0000))) algebraic[10] = 1.00000/(1.00000+exp((states[0]+11.5000)/-11.8200)) algebraic[24] = 1.00000/(0.118850*exp((states[0]+80.0000)/28.3700)+0.562300*exp((states[0]+80.0000)/-14.1900)) algebraic[12] = 1.00000/(1.00000+exp((states[0]+138.600)/10.4800)) algebraic[28] = ((constants[0]*constants[1])/constants[2])*log(constants[17]/states[10]) algebraic[29] = constants[14]*states[11]*(constants[15]*states[12]+constants[16]*states[13])*(states[0]-algebraic[28]) algebraic[30] = constants[18]*states[14]*states[15]*(states[0]-algebraic[28]) algebraic[31] = ((48.0000/(exp((states[0]+37.0000)/25.0000)+exp((states[0]+37.0000)/-25.0000))+10.0000)*0.00100000)/(1.00000+exp((states[0]-(algebraic[28]+76.7700))/-17.0000))+(constants[19]*(states[0]-(algebraic[28]+1.73000)))/((1.00000+exp((1.61300*constants[2]*(states[0]-(algebraic[28]+1.73000)))/(constants[0]*constants[1])))*(1.00000+exp((constants[17]-0.998800)/-0.124000))) algebraic[40] = (((((constants[26]*1.00000)/(1.00000+0.124500*exp((-0.100000*states[0]*constants[2])/(constants[0]*constants[1]))+0.0365000*constants[71]*exp((-states[0]*constants[2])/(constants[0]*constants[1]))))*constants[17])/(constants[17]+constants[27]))*1.00000)/(1.00000+power(constants[28]/states[1], 1.50000)) algebraic[33] = constants[20]*states[16]*constants[70]*(states[0]-algebraic[28]) algebraic[38] = constants[24]*(states[0]-algebraic[28]) algebraic[25] = ((constants[0]*constants[1])/constants[2])*log(constants[10]/states[1]) algebraic[26] = constants[9]*(power(states[2], 3.00000))*states[3]*states[4]*(states[0]-algebraic[25]) algebraic[27] = constants[11]*states[6]*((0.900000+states[9]/10.0000)*states[7]+(0.100000-states[9]/10.0000)*states[8])*(states[0]-constants[12]) algebraic[32] = constants[20]*states[16]*constants[21]*(states[0]-algebraic[25]) algebraic[34] = algebraic[32]+algebraic[33] algebraic[36] = constants[22]*(states[0]-algebraic[25]) algebraic[35] = ((0.500000*constants[0]*constants[1])/constants[2])*log(constants[25]/states[17]) algebraic[37] = constants[23]*(states[0]-algebraic[35]) algebraic[39] = algebraic[36]+algebraic[37]+algebraic[38] algebraic[42] = (constants[30]*((power(states[1], 3.00000))*constants[25]*exp(0.0374300*states[0]*constants[32])-(power(constants[10], 3.00000))*states[17]*exp(0.0374300*states[0]*(constants[32]-1.00000))))/(1.00000+constants[31]*(states[17]*(power(constants[10], 3.00000))+constants[25]*(power(states[1], 3.00000)))) algebraic[41] = (constants[29]*states[17])/(states[17]+0.000400000) algebraic[13] = custom_piecewise([greater_equal(voi , constants[4]) & less_equal(voi , constants[5]) & less_equal((voi-constants[4])-floor((voi-constants[4])/constants[6])*constants[6] , constants[7]), constants[8] , True, 0.00000]) algebraic[44] = power(states[17]/constants[42], constants[47]) algebraic[45] = power(states[23]/constants[43], constants[48]) algebraic[46] = (constants[46]*(constants[44]*algebraic[44]-constants[45]*algebraic[45]))/(1.00000+algebraic[44]+algebraic[45]) algebraic[48] = (states[23]-states[22])/constants[49] algebraic[43] = constants[33]*(states[18]+states[19])*(states[22]-states[5]) algebraic[47] = (states[5]-states[17])/constants[50] algebraic[50] = 1.00000/(1.00000+(constants[66]*constants[63])/(power(constants[63]+states[5], 2.00000))) algebraic[51] = 1.00000/(1.00000+(constants[67]*constants[64])/(power(constants[64]+states[22], 2.00000))) algebraic[49] = constants[55]*states[17]*(constants[53]-constants[51])-constants[56]*constants[51] algebraic[52] = constants[57]*states[17]*(constants[54]-constants[52])-constants[58]*constants[52] algebraic[53] = algebraic[49]+algebraic[52] algebraic[54] = 1.00000/(1.00000+(constants[66]*constants[63])/(power(constants[63]+states[17], 2.00000))+(constants[68]*constants[65])/(power(constants[65]+states[17], 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)