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 = 71 sizeStates = 31 sizeConstants = 87 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[70] = "I_inter_myo in component I_inter (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[84] = "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[85] = "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[86] = "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 (nanoA_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 (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 (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[49] = "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[45] = "fb in component SERCA2a_pump (dimensionless)" legend_algebraic[47] = "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[52] = "J_tr in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)" legend_algebraic[51] = "J_xfer in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)" legend_algebraic[60] = "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[54] = "J_HTRPNCa in component intracellular_and_SR_Ca_fluxes (millimolar_per_second)" legend_algebraic[58] = "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 (per_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 (per_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 (micro_litre)" legend_constants[60] = "V_JSR in component intracellular_ion_concentrations (micro_litre)" legend_constants[61] = "V_NSR in component intracellular_ion_concentrations (micro_litre)" legend_constants[62] = "V_SS in component intracellular_ion_concentrations (micro_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[62] = "beta_i in component intracellular_ion_concentrations (dimensionless)" legend_algebraic[55] = "beta_SS in component intracellular_ion_concentrations (dimensionless)" legend_algebraic[56] = "beta_JSR in component intracellular_ion_concentrations (dimensionless)" legend_algebraic[44] = "V_fibro in component membrane_fibro (millivolt)" legend_constants[69] = "Cm in component membrane_fibro (microF)" legend_algebraic[67] = "I_b in component I_b (nanoA)" legend_algebraic[50] = "I_Kir in component I_Kir (nanoA)" legend_algebraic[65] = "I_Shkr in component I_Shkr (nanoA)" legend_algebraic[69] = "I_inter_fibro in component I_inter (nanoA)" legend_states[24] = "VmReal in component membrane_fibro (millivolt)" legend_constants[70] = "GKir in component I_Kir (microS)" legend_constants[71] = "aKir in component I_Kir (dimensionless)" legend_constants[72] = "bKir in component I_Kir (dimensionless)" legend_algebraic[46] = "EK in component I_Kir (millivolt)" legend_algebraic[48] = "OKir in component I_Kir (dimensionless)" legend_constants[73] = "PShkr in component I_Shkr (microlitre_per_second)" legend_states[25] = "C0ShkrReal in component I_Shkr (dimensionless)" legend_states[26] = "C1ShkrReal in component I_Shkr (dimensionless)" legend_states[27] = "C2ShkrReal in component I_Shkr (dimensionless)" legend_states[28] = "C3ShkrReal in component I_Shkr (dimensionless)" legend_states[29] = "C4ShkrReal in component I_Shkr (dimensionless)" legend_states[30] = "OShkrReal in component I_Shkr (dimensionless)" legend_algebraic[53] = "C0Shkr in component I_Shkr (dimensionless)" legend_algebraic[57] = "C1Shkr in component I_Shkr (dimensionless)" legend_algebraic[59] = "C2Shkr in component I_Shkr (dimensionless)" legend_algebraic[61] = "C3Shkr in component I_Shkr (dimensionless)" legend_algebraic[63] = "C4Shkr in component I_Shkr (dimensionless)" legend_algebraic[64] = "OShkr in component I_Shkr (dimensionless)" legend_algebraic[66] = "kv in component I_Shkr (per_second)" legend_algebraic[68] = "k_v in component I_Shkr (per_second)" legend_constants[74] = "kv0 in component I_Shkr (per_second)" legend_constants[75] = "zv in component I_Shkr (dimensionless)" legend_constants[76] = "k_v0 in component I_Shkr (per_second)" legend_constants[77] = "z_v in component I_Shkr (dimensionless)" legend_constants[78] = "ko in component I_Shkr (per_second)" legend_constants[79] = "k_o in component I_Shkr (per_second)" legend_constants[80] = "Gb in component I_b (microS)" legend_constants[81] = "Eb in component I_b (millivolt)" legend_constants[82] = "R_mf in component I_inter (ohm)" legend_constants[83] = "number_of_fibroblasts in component I_inter (dimensionless)" 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)" legend_rates[24] = "d/dt VmReal in component membrane_fibro (millivolt)" legend_rates[25] = "d/dt C0ShkrReal in component I_Shkr (dimensionless)" legend_rates[26] = "d/dt C1ShkrReal in component I_Shkr (dimensionless)" legend_rates[27] = "d/dt C2ShkrReal in component I_Shkr (dimensionless)" legend_rates[28] = "d/dt C3ShkrReal in component I_Shkr (dimensionless)" legend_rates[29] = "d/dt C4ShkrReal in component I_Shkr (dimensionless)" legend_rates[30] = "d/dt OShkrReal in component I_Shkr (dimensionless)" 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] = 0.01 constants[5] = 10 constants[6] = 1 constants[7] = 0.001 constants[8] = -5 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.00000056 constants[61] = 0.00000504 constants[62] = 0.000000012 constants[63] = 0.00238 constants[64] = 0.8 constants[65] = 0.00015 constants[66] = 0.05 constants[67] = 15 constants[68] = 10 constants[69] = 4.5e-6 states[24] = -80.00 constants[70] = 1e-3 constants[71] = 0.94 constants[72] = 1.26 constants[73] = 5.4e-9 states[25] = 9.11e-1 states[26] = 8.57e-2 states[27] = 3.02e-3 states[28] = 4.74e-5 states[29] = 2.79e-7 states[30] = 0 constants[74] = 30 constants[75] = 1.28 constants[76] = 2 constants[77] = -1.53 constants[78] = 77 constants[79] = 18 constants[80] = 6.9e-6 constants[81] = 0 constants[82] = 100e6 constants[83] = 1 constants[84] = 2.10000 constants[85] = 1.00000-constants[21] constants[86] = (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]/1.00000, constants[40]))*states[20]+constants[35]*states[18] rates[18] = (constants[34]*(power(states[5]/1.00000, constants[40]))*states[20]-(constants[35]*states[18]+constants[36]*(power(states[5]/1.00000, constants[41]))*states[18]+constants[38]*states[18]))+constants[37]*states[19]+constants[39]*states[21] rates[19] = constants[36]*(power(states[5]/1.00000, 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[84] 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[86]*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[85]*(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[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[32] = constants[20]*states[16]*constants[21]*(states[0]-algebraic[25]) algebraic[36] = constants[22]*(states[0]-algebraic[25]) rates[1] = (-(algebraic[26]+algebraic[36]+algebraic[42]*3.00000+algebraic[40]*3.00000+algebraic[32])*1.00000)/(constants[59]*constants[2]) algebraic[45] = power(states[17]/constants[42], constants[47]) algebraic[47] = power(states[23]/constants[43], constants[48]) algebraic[49] = (constants[46]*(constants[44]*algebraic[45]-constants[45]*algebraic[47]))/(1.00000+algebraic[45]+algebraic[47]) algebraic[52] = (states[23]-states[22])/constants[49] rates[23] = (algebraic[49]*constants[59])/constants[61]-(algebraic[52]*constants[60])/constants[61] 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[43] = constants[33]*(states[18]+states[19])*(states[22]-states[5]) algebraic[51] = (states[5]-states[17])/constants[50] algebraic[55] = 1.00000/(1.00000+(constants[66]*constants[63])/(power(constants[63]+states[5], 2.00000))) rates[5] = algebraic[55]*(((algebraic[43]*constants[60])/constants[62]-(algebraic[51]*constants[59])/constants[62])-(algebraic[27]*1.00000)/(2.00000*constants[62]*constants[2])) algebraic[56] = 1.00000/(1.00000+(constants[67]*constants[64])/(power(constants[64]+states[22], 2.00000))) rates[22] = algebraic[56]*(algebraic[52]-algebraic[43]) algebraic[41] = (constants[29]*states[17])/(states[17]+0.000400000) algebraic[35] = ((0.500000*constants[0]*constants[1])/constants[2])*log(constants[25]/states[17]) algebraic[37] = constants[23]*(states[0]-algebraic[35]) algebraic[54] = constants[55]*states[17]*(constants[53]-constants[51])-constants[56]*constants[51] algebraic[58] = constants[57]*states[17]*(constants[54]-constants[52])-constants[58]*constants[52] algebraic[60] = algebraic[54]+algebraic[58] algebraic[62] = 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[62]*(algebraic[51]-(algebraic[49]+algebraic[60]+(((algebraic[37]-2.00000*algebraic[42])+algebraic[41])*1.00000)/(2.00000*constants[59]*constants[2]))) algebraic[63] = custom_piecewise([less(states[29] , 0.00000), 0.00000 , greater(states[29] , 1.00000), 1.00000 , True, states[29]]) algebraic[64] = custom_piecewise([less(states[30] , 0.00000), 0.00000 , greater(states[30] , 1.00000), 1.00000 , True, states[30]]) rates[30] = constants[78]*algebraic[63]-constants[79]*algebraic[64] algebraic[53] = custom_piecewise([less(states[25] , 0.00000), 0.00000 , greater(states[25] , 1.00000), 1.00000 , True, states[25]]) algebraic[57] = custom_piecewise([less(states[26] , 0.00000), 0.00000 , greater(states[26] , 1.00000), 1.00000 , True, states[26]]) algebraic[44] = custom_piecewise([less(fabs(states[24]) , 1.00000e-07), 1.00000e-07 , True, states[24]]) algebraic[66] = constants[74]*exp((algebraic[44]*constants[75]*constants[2])/(constants[0]*constants[1])) algebraic[68] = constants[76]*exp((algebraic[44]*constants[77]*constants[2])/(constants[0]*constants[1])) rates[25] = algebraic[68]*algebraic[57]-4.00000*algebraic[66]*algebraic[53] algebraic[59] = custom_piecewise([less(states[27] , 0.00000), 0.00000 , greater(states[27] , 1.00000), 1.00000 , True, states[27]]) rates[26] = (2.00000*algebraic[68]*algebraic[59]+4.00000*algebraic[66]*algebraic[53])-(3.00000*algebraic[66]+algebraic[68])*algebraic[57] algebraic[61] = custom_piecewise([less(states[28] , 0.00000), 0.00000 , greater(states[28] , 1.00000), 1.00000 , True, states[28]]) rates[27] = (3.00000*algebraic[68]*algebraic[61]+3.00000*algebraic[66]*algebraic[57])-(2.00000*algebraic[66]+2.00000*algebraic[68])*algebraic[59] rates[28] = (4.00000*algebraic[68]*algebraic[63]+2.00000*algebraic[66]*algebraic[59])-(algebraic[66]+3.00000*algebraic[68])*algebraic[61] rates[29] = (constants[79]*algebraic[64]+algebraic[66]*algebraic[61])-(constants[78]+4.00000*algebraic[68])*algebraic[63] algebraic[67] = constants[80]*(algebraic[44]-constants[81]) algebraic[46] = ((constants[0]*constants[1])/constants[2])*log(constants[17]/states[10]) algebraic[48] = 1.00000/(constants[71]+exp((constants[72]*(algebraic[44]-algebraic[46])*constants[2])/(constants[0]*constants[1]))) algebraic[50] = constants[70]*algebraic[48]*(power(constants[17]*0.00100000, 1.0/2))*(algebraic[44]-algebraic[46]) algebraic[65] = (((constants[73]*algebraic[64]*algebraic[44]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*(states[10]-constants[17]*exp((-algebraic[44]*constants[2])/(constants[0]*constants[1]))))/(1.00000-exp((-algebraic[44]*constants[2])/(constants[0]*constants[1]))) algebraic[69] = (1.00000e+06*(algebraic[44]-states[0]))/constants[82] rates[24] = -(algebraic[50]+algebraic[65]+algebraic[67]+algebraic[69])/constants[69] algebraic[34] = algebraic[32]+algebraic[33] algebraic[39] = algebraic[36]+algebraic[37]+algebraic[38] 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[70] = -1.00000*algebraic[69]*constants[83] rates[0] = -(algebraic[26]+algebraic[27]+algebraic[29]+algebraic[30]+algebraic[34]+algebraic[31]+algebraic[39]+algebraic[40]+algebraic[42]+algebraic[41]+algebraic[13]+algebraic[70])/constants[3] 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[86]*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[85]*(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[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[32] = constants[20]*states[16]*constants[21]*(states[0]-algebraic[25]) algebraic[36] = constants[22]*(states[0]-algebraic[25]) algebraic[45] = power(states[17]/constants[42], constants[47]) algebraic[47] = power(states[23]/constants[43], constants[48]) algebraic[49] = (constants[46]*(constants[44]*algebraic[45]-constants[45]*algebraic[47]))/(1.00000+algebraic[45]+algebraic[47]) algebraic[52] = (states[23]-states[22])/constants[49] 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[43] = constants[33]*(states[18]+states[19])*(states[22]-states[5]) algebraic[51] = (states[5]-states[17])/constants[50] algebraic[55] = 1.00000/(1.00000+(constants[66]*constants[63])/(power(constants[63]+states[5], 2.00000))) algebraic[56] = 1.00000/(1.00000+(constants[67]*constants[64])/(power(constants[64]+states[22], 2.00000))) algebraic[41] = (constants[29]*states[17])/(states[17]+0.000400000) algebraic[35] = ((0.500000*constants[0]*constants[1])/constants[2])*log(constants[25]/states[17]) algebraic[37] = constants[23]*(states[0]-algebraic[35]) algebraic[54] = constants[55]*states[17]*(constants[53]-constants[51])-constants[56]*constants[51] algebraic[58] = constants[57]*states[17]*(constants[54]-constants[52])-constants[58]*constants[52] algebraic[60] = algebraic[54]+algebraic[58] algebraic[62] = 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))) algebraic[63] = custom_piecewise([less(states[29] , 0.00000), 0.00000 , greater(states[29] , 1.00000), 1.00000 , True, states[29]]) algebraic[64] = custom_piecewise([less(states[30] , 0.00000), 0.00000 , greater(states[30] , 1.00000), 1.00000 , True, states[30]]) algebraic[53] = custom_piecewise([less(states[25] , 0.00000), 0.00000 , greater(states[25] , 1.00000), 1.00000 , True, states[25]]) algebraic[57] = custom_piecewise([less(states[26] , 0.00000), 0.00000 , greater(states[26] , 1.00000), 1.00000 , True, states[26]]) algebraic[44] = custom_piecewise([less(fabs(states[24]) , 1.00000e-07), 1.00000e-07 , True, states[24]]) algebraic[66] = constants[74]*exp((algebraic[44]*constants[75]*constants[2])/(constants[0]*constants[1])) algebraic[68] = constants[76]*exp((algebraic[44]*constants[77]*constants[2])/(constants[0]*constants[1])) algebraic[59] = custom_piecewise([less(states[27] , 0.00000), 0.00000 , greater(states[27] , 1.00000), 1.00000 , True, states[27]]) algebraic[61] = custom_piecewise([less(states[28] , 0.00000), 0.00000 , greater(states[28] , 1.00000), 1.00000 , True, states[28]]) algebraic[67] = constants[80]*(algebraic[44]-constants[81]) algebraic[46] = ((constants[0]*constants[1])/constants[2])*log(constants[17]/states[10]) algebraic[48] = 1.00000/(constants[71]+exp((constants[72]*(algebraic[44]-algebraic[46])*constants[2])/(constants[0]*constants[1]))) algebraic[50] = constants[70]*algebraic[48]*(power(constants[17]*0.00100000, 1.0/2))*(algebraic[44]-algebraic[46]) algebraic[65] = (((constants[73]*algebraic[64]*algebraic[44]*(power(constants[2], 2.00000)))/(constants[0]*constants[1]))*(states[10]-constants[17]*exp((-algebraic[44]*constants[2])/(constants[0]*constants[1]))))/(1.00000-exp((-algebraic[44]*constants[2])/(constants[0]*constants[1]))) algebraic[69] = (1.00000e+06*(algebraic[44]-states[0]))/constants[82] algebraic[34] = algebraic[32]+algebraic[33] algebraic[39] = algebraic[36]+algebraic[37]+algebraic[38] 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[70] = -1.00000*algebraic[69]*constants[83] 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)