# Size of variable arrays: sizeAlgebraic = 52 sizeStates = 15 sizeConstants = 71 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_constants[0] = "dCell in component membrane (dimensionless)" legend_constants[49] = "FCell in component membrane (dimensionless)" legend_states[0] = "V in component membrane (millivolt)" legend_constants[1] = "R in component membrane (millijoule_per_mole_kelvin)" legend_constants[2] = "T in component membrane (kelvin)" legend_constants[3] = "F in component membrane (coulomb_per_mole)" legend_constants[54] = "Cm in component membrane (microF)" legend_constants[4] = "CmCentre in component membrane (microF)" legend_constants[5] = "CmPeriphery in component membrane (microF)" legend_algebraic[27] = "i_Na in component sodium_current (nanoA)" legend_algebraic[34] = "i_Ca_L in component L_type_Ca_channel (nanoA)" legend_algebraic[39] = "i_Ca_T in component T_type_Ca_channel (nanoA)" legend_algebraic[40] = "i_to in component four_AP_sensitive_currents (nanoA)" legend_algebraic[41] = "i_sus in component four_AP_sensitive_currents (nanoA)" legend_algebraic[43] = "i_K_r in component rapid_delayed_rectifying_potassium_current (nanoA)" legend_algebraic[44] = "i_K_s in component slow_delayed_rectifying_potassium_current (nanoA)" legend_algebraic[45] = "i_f_Na in component hyperpolarisation_activated_current (nanoA)" legend_algebraic[46] = "i_f_K in component hyperpolarisation_activated_current (nanoA)" legend_algebraic[47] = "i_b_Na in component sodium_background_current (nanoA)" legend_algebraic[49] = "i_b_Ca in component calcium_background_current (nanoA)" legend_algebraic[48] = "i_b_K in component potassium_background_current (nanoA)" legend_algebraic[50] = "i_NaCa in component sodium_calcium_exchanger (nanoA)" legend_algebraic[51] = "i_p in component sodium_potassium_pump (nanoA)" legend_constants[70] = "i_Ca_p in component persistent_calcium_current (nanoA)" legend_constants[55] = "g_Na in component sodium_current (microlitre_per_second)" legend_constants[6] = "g_Na_Centre in component sodium_current (microlitre_per_second)" legend_constants[7] = "g_Na_Periphery in component sodium_current (microlitre_per_second)" legend_constants[50] = "E_Na in component reversal_and_equilibrium_potentials (millivolt)" legend_constants[8] = "Na_o in component ionic_concentrations (millimolar)" legend_states[1] = "m in component sodium_current_m_gate (dimensionless)" legend_algebraic[13] = "h in component sodium_current_h_gate (dimensionless)" legend_algebraic[1] = "m_infinity in component sodium_current_m_gate (dimensionless)" legend_algebraic[14] = "tau_m in component sodium_current_m_gate (second)" legend_algebraic[0] = "F_Na in component sodium_current_h_gate (dimensionless)" legend_states[2] = "h1 in component sodium_current_h_gate (dimensionless)" legend_states[3] = "h2 in component sodium_current_h_gate (dimensionless)" legend_algebraic[2] = "h1_infinity in component sodium_current_h_gate (dimensionless)" legend_algebraic[15] = "h2_infinity in component sodium_current_h_gate (dimensionless)" legend_algebraic[16] = "tau_h1 in component sodium_current_h_gate (second)" legend_algebraic[28] = "tau_h2 in component sodium_current_h_gate (second)" legend_constants[9] = "g_Ca_L_Centre in component L_type_Ca_channel (microS)" legend_constants[10] = "g_Ca_L_Periphery in component L_type_Ca_channel (microS)" legend_constants[56] = "g_Ca_L in component L_type_Ca_channel (microS)" legend_constants[11] = "E_Ca_L in component L_type_Ca_channel (millivolt)" legend_states[4] = "d_L in component L_type_Ca_channel_d_gate (dimensionless)" legend_states[5] = "f_L in component L_type_Ca_channel_f_gate (dimensionless)" legend_algebraic[3] = "alpha_d_L in component L_type_Ca_channel_d_gate (per_second)" legend_algebraic[17] = "beta_d_L in component L_type_Ca_channel_d_gate (per_second)" legend_algebraic[35] = "d_L_infinity in component L_type_Ca_channel_d_gate (dimensionless)" legend_algebraic[29] = "tau_d_L in component L_type_Ca_channel_d_gate (second)" legend_algebraic[4] = "alpha_f_L in component L_type_Ca_channel_f_gate (per_second)" legend_algebraic[18] = "beta_f_L in component L_type_Ca_channel_f_gate (per_second)" legend_algebraic[36] = "f_L_infinity in component L_type_Ca_channel_f_gate (dimensionless)" legend_algebraic[30] = "tau_f_L in component L_type_Ca_channel_f_gate (second)" legend_constants[12] = "g_Ca_T_Centre in component T_type_Ca_channel (microS)" legend_constants[13] = "g_Ca_T_Periphery in component T_type_Ca_channel (microS)" legend_constants[57] = "g_Ca_T in component T_type_Ca_channel (microS)" legend_constants[14] = "E_Ca_T in component T_type_Ca_channel (millivolt)" legend_states[6] = "d_T in component T_type_Ca_channel_d_gate (dimensionless)" legend_states[7] = "f_T in component T_type_Ca_channel_f_gate (dimensionless)" legend_algebraic[5] = "alpha_d_T in component T_type_Ca_channel_d_gate (per_second)" legend_algebraic[19] = "beta_d_T in component T_type_Ca_channel_d_gate (per_second)" legend_algebraic[37] = "d_T_infinity in component T_type_Ca_channel_d_gate (dimensionless)" legend_algebraic[31] = "tau_d_T in component T_type_Ca_channel_d_gate (second)" legend_algebraic[6] = "alpha_f_T in component T_type_Ca_channel_f_gate (per_second)" legend_algebraic[20] = "beta_f_T in component T_type_Ca_channel_f_gate (per_second)" legend_algebraic[38] = "f_T_infinity in component T_type_Ca_channel_f_gate (dimensionless)" legend_algebraic[32] = "tau_f_T in component T_type_Ca_channel_f_gate (second)" legend_constants[15] = "g_to_Centre in component four_AP_sensitive_currents (microS)" legend_constants[16] = "g_to_Periphery in component four_AP_sensitive_currents (microS)" legend_constants[58] = "g_to in component four_AP_sensitive_currents (microS)" legend_constants[17] = "g_sus_Centre in component four_AP_sensitive_currents (microS)" legend_constants[18] = "g_sus_Periphery in component four_AP_sensitive_currents (microS)" legend_constants[59] = "g_sus in component four_AP_sensitive_currents (microS)" legend_constants[51] = "E_K in component reversal_and_equilibrium_potentials (millivolt)" legend_states[8] = "q in component four_AP_sensitive_currents_q_gate (dimensionless)" legend_states[9] = "r in component four_AP_sensitive_currents_r_gate (dimensionless)" legend_algebraic[7] = "q_infinity in component four_AP_sensitive_currents_q_gate (dimensionless)" legend_algebraic[21] = "tau_q in component four_AP_sensitive_currents_q_gate (second)" legend_algebraic[8] = "r_infinity in component four_AP_sensitive_currents_r_gate (dimensionless)" legend_algebraic[22] = "tau_r in component four_AP_sensitive_currents_r_gate (second)" legend_constants[19] = "g_K_r_Centre in component rapid_delayed_rectifying_potassium_current (microS)" legend_constants[20] = "g_K_r_Periphery in component rapid_delayed_rectifying_potassium_current (microS)" legend_constants[60] = "g_K_r in component rapid_delayed_rectifying_potassium_current (microS)" legend_algebraic[42] = "P_a in component rapid_delayed_rectifying_potassium_current (dimensionless)" legend_states[10] = "P_af in component rapid_delayed_rectifying_potassium_current_P_af_gate (dimensionless)" legend_states[11] = "P_as in component rapid_delayed_rectifying_potassium_current_P_as_gate (dimensionless)" legend_states[12] = "P_i in component rapid_delayed_rectifying_potassium_current_P_i_gate (dimensionless)" legend_algebraic[9] = "P_af_infinity in component rapid_delayed_rectifying_potassium_current_P_af_gate (dimensionless)" legend_algebraic[23] = "tau_P_af in component rapid_delayed_rectifying_potassium_current_P_af_gate (second)" legend_algebraic[24] = "P_as_infinity in component rapid_delayed_rectifying_potassium_current_P_as_gate (dimensionless)" legend_algebraic[33] = "tau_P_as in component rapid_delayed_rectifying_potassium_current_P_as_gate (second)" legend_algebraic[10] = "P_i_infinity in component rapid_delayed_rectifying_potassium_current_P_i_gate (dimensionless)" legend_constants[21] = "tau_P_i in component rapid_delayed_rectifying_potassium_current_P_i_gate (second)" legend_constants[22] = "g_K_s_Centre in component slow_delayed_rectifying_potassium_current (microS)" legend_constants[23] = "g_K_s_Periphery in component slow_delayed_rectifying_potassium_current (microS)" legend_constants[61] = "g_K_s in component slow_delayed_rectifying_potassium_current (microS)" legend_constants[52] = "E_K_s in component reversal_and_equilibrium_potentials (millivolt)" legend_states[13] = "xs in component slow_delayed_rectifying_potassium_current_xs_gate (dimensionless)" legend_algebraic[11] = "alpha_xs in component slow_delayed_rectifying_potassium_current_xs_gate (per_second)" legend_algebraic[25] = "beta_xs in component slow_delayed_rectifying_potassium_current_xs_gate (per_second)" legend_constants[24] = "g_f_Na_Centre in component hyperpolarisation_activated_current (microS)" legend_constants[25] = "g_f_Na_Periphery in component hyperpolarisation_activated_current (microS)" legend_constants[62] = "g_f_Na in component hyperpolarisation_activated_current (microS)" legend_constants[26] = "g_f_K_Centre in component hyperpolarisation_activated_current (microS)" legend_constants[27] = "g_f_K_Periphery in component hyperpolarisation_activated_current (microS)" legend_constants[63] = "g_f_K in component hyperpolarisation_activated_current (microS)" legend_states[14] = "y in component hyperpolarisation_activated_current_y_gate (dimensionless)" legend_algebraic[12] = "alpha_y in component hyperpolarisation_activated_current_y_gate (per_second)" legend_algebraic[26] = "beta_y in component hyperpolarisation_activated_current_y_gate (per_second)" legend_constants[28] = "g_b_Na_Centre in component sodium_background_current (microS)" legend_constants[29] = "g_b_Na_Periphery in component sodium_background_current (microS)" legend_constants[64] = "g_b_Na in component sodium_background_current (microS)" legend_constants[30] = "g_b_K_Centre in component potassium_background_current (microS)" legend_constants[31] = "g_b_K_Periphery in component potassium_background_current (microS)" legend_constants[65] = "g_b_K in component potassium_background_current (microS)" legend_constants[32] = "g_b_Ca_Centre in component calcium_background_current (microS)" legend_constants[33] = "g_b_Ca_Periphery in component calcium_background_current (microS)" legend_constants[66] = "g_b_Ca in component calcium_background_current (microS)" legend_constants[53] = "E_Ca in component reversal_and_equilibrium_potentials (millivolt)" legend_constants[34] = "k_NaCa_Centre in component sodium_calcium_exchanger (nanoA)" legend_constants[35] = "k_NaCa_Periphery in component sodium_calcium_exchanger (nanoA)" legend_constants[67] = "k_NaCa in component sodium_calcium_exchanger (nanoA)" legend_constants[36] = "d_NaCa in component sodium_calcium_exchanger (dimensionless)" legend_constants[37] = "gamma_NaCa in component sodium_calcium_exchanger (dimensionless)" legend_constants[38] = "Na_i in component ionic_concentrations (millimolar)" legend_constants[39] = "Ca_i in component ionic_concentrations (millimolar)" legend_constants[40] = "Ca_o in component ionic_concentrations (millimolar)" legend_constants[41] = "K_m_Na in component sodium_potassium_pump (millimolar)" legend_constants[42] = "K_m_K in component sodium_potassium_pump (millimolar)" legend_constants[43] = "i_p_max_Centre in component sodium_potassium_pump (nanoA)" legend_constants[44] = "i_p_max_Periphery in component sodium_potassium_pump (nanoA)" legend_constants[68] = "i_p_max in component sodium_potassium_pump (nanoA)" legend_constants[45] = "K_o in component ionic_concentrations (millimolar)" legend_constants[46] = "i_Ca_p_max_Centre in component persistent_calcium_current (nanoA)" legend_constants[47] = "i_Ca_p_max_Periphery in component persistent_calcium_current (nanoA)" legend_constants[69] = "i_Ca_p_max in component persistent_calcium_current (nanoA)" legend_constants[48] = "K_i in component ionic_concentrations (millimolar)" legend_rates[0] = "d/dt V in component membrane (millivolt)" legend_rates[1] = "d/dt m in component sodium_current_m_gate (dimensionless)" legend_rates[2] = "d/dt h1 in component sodium_current_h_gate (dimensionless)" legend_rates[3] = "d/dt h2 in component sodium_current_h_gate (dimensionless)" legend_rates[4] = "d/dt d_L in component L_type_Ca_channel_d_gate (dimensionless)" legend_rates[5] = "d/dt f_L in component L_type_Ca_channel_f_gate (dimensionless)" legend_rates[6] = "d/dt d_T in component T_type_Ca_channel_d_gate (dimensionless)" legend_rates[7] = "d/dt f_T in component T_type_Ca_channel_f_gate (dimensionless)" legend_rates[8] = "d/dt q in component four_AP_sensitive_currents_q_gate (dimensionless)" legend_rates[9] = "d/dt r in component four_AP_sensitive_currents_r_gate (dimensionless)" legend_rates[10] = "d/dt P_af in component rapid_delayed_rectifying_potassium_current_P_af_gate (dimensionless)" legend_rates[11] = "d/dt P_as in component rapid_delayed_rectifying_potassium_current_P_as_gate (dimensionless)" legend_rates[12] = "d/dt P_i in component rapid_delayed_rectifying_potassium_current_P_i_gate (dimensionless)" legend_rates[13] = "d/dt xs in component slow_delayed_rectifying_potassium_current_xs_gate (dimensionless)" legend_rates[14] = "d/dt y in component hyperpolarisation_activated_current_y_gate (dimensionless)" return (legend_states, legend_algebraic, legend_voi, legend_constants) def initConsts(): constants = [0.0] * sizeConstants; states = [0.0] * sizeStates; constants[0] = 0 states[0] = -39.013558536 constants[1] = 8314 constants[2] = 310 constants[3] = 96845 constants[4] = 2e-5 constants[5] = 6.5e-5 constants[6] = 0 constants[7] = 1.2e-6 constants[8] = 140 states[1] = 0.092361701692 states[2] = 0.015905380261 states[3] = 0.01445216109 constants[9] = 0.0058 constants[10] = 0.0659 constants[11] = 46.4 states[4] = 0.04804900895 states[5] = 0.48779845203 constants[12] = 0.0043 constants[13] = 0.0139 constants[14] = 45 states[6] = 0.42074047435 states[7] = 0.038968420558 constants[15] = 0.00491 constants[16] = 0.03649 constants[17] = 6.65e-5 constants[18] = 0.0114 states[8] = 0.29760539675 states[9] = 0.064402950262 constants[19] = 0.000797 constants[20] = 0.016 states[10] = 0.13034201158 states[11] = 0.46960956028 states[12] = 0.87993375273 constants[21] = 0.002 constants[22] = 0.000518 constants[23] = 0.0104 states[13] = 0.082293827208 constants[24] = 0.000548 constants[25] = 0.0069 constants[26] = 0.000548 constants[27] = 0.0069 states[14] = 0.03889291759 constants[28] = 5.8e-5 constants[29] = 0.000189 constants[30] = 2.52e-5 constants[31] = 8.19e-5 constants[32] = 1.32e-5 constants[33] = 4.3e-5 constants[34] = 2.7e-6 constants[35] = 8.8e-6 constants[36] = 0.0001 constants[37] = 0.5 constants[38] = 8 constants[39] = 0.0001 constants[40] = 2 constants[41] = 5.64 constants[42] = 0.621 constants[43] = 0.0478 constants[44] = 0.16 constants[45] = 5.4 constants[46] = 0 constants[47] = 0 constants[48] = 140 constants[49] = (1.07000*(3.00000*constants[0]-0.100000))/(3.00000*(1.00000+0.774500*exp(-(3.00000*constants[0]-2.05000)/0.295000))) constants[50] = ((constants[1]*constants[2])/constants[3])*log(constants[8]/constants[38]) constants[51] = ((constants[1]*constants[2])/constants[3])*log(constants[45]/constants[48]) constants[52] = ((constants[1]*constants[2])/constants[3])*log((constants[45]+0.120000*constants[8])/(constants[48]+0.120000*constants[38])) constants[53] = ((constants[1]*constants[2])/(2.00000*constants[3]))*log(constants[40]/constants[39]) constants[54] = constants[4]+constants[49]*(constants[5]-constants[4]) constants[55] = constants[6]+constants[49]*(constants[7]-constants[6]) constants[56] = constants[9]+constants[49]*(constants[10]-constants[9]) constants[57] = constants[12]+constants[49]*(constants[13]-constants[12]) constants[58] = constants[15]+constants[49]*(constants[16]-constants[15]) constants[59] = constants[17]+constants[49]*(constants[18]-constants[17]) constants[60] = constants[19]+constants[49]*(constants[20]-constants[19]) constants[61] = constants[22]+constants[49]*(constants[23]-constants[22]) constants[62] = constants[24]+constants[49]*(constants[25]-constants[24]) constants[63] = constants[26]+constants[49]*(constants[27]-constants[26]) constants[64] = constants[28]+constants[49]*(constants[29]-constants[28]) constants[65] = constants[30]+constants[49]*(constants[31]-constants[30]) constants[66] = constants[32]+constants[49]*(constants[33]-constants[32]) constants[67] = constants[34]+constants[49]*(constants[35]-constants[34]) constants[68] = constants[43]+constants[49]*(constants[44]-constants[43]) constants[69] = constants[46]+constants[49]*(constants[47]-constants[46]) constants[70] = (constants[69]*constants[39])/(constants[39]+0.000400000) return (states, constants) def computeRates(voi, states, constants): rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic algebraic[10] = 1.00000/(1.00000+exp((states[0]+18.6000)/10.1000)) rates[12] = (algebraic[10]-states[12])/constants[21] algebraic[1] = power(1.00000/(1.00000+exp(-states[0]/5.46000)), 1.00000/3.00000) algebraic[14] = 0.000624700/(0.832000*exp(-0.335000*(states[0]+56.7000))+0.627000*exp(0.0820000*(states[0]+65.0100)))+4.00000e-05 rates[1] = (algebraic[1]-states[1])/algebraic[14] algebraic[2] = 1.00000/(1.00000+exp((states[0]+66.1000)/6.40000)) algebraic[16] = (3.71700e-06*exp(-0.281500*(states[0]+17.1100)))/(1.00000+0.00373200*exp(-0.342600*(states[0]+37.7600)))+0.000597700 rates[2] = (algebraic[2]-states[2])/algebraic[16] algebraic[7] = 1.00000/(1.00000+exp((states[0]+59.3700)/13.1000)) algebraic[21] = 0.0101000+0.0651700/(0.570000*exp(-0.0800000*(states[0]+49.0000)))+2.40000e-05*exp(0.100000*(states[0]+50.9300)) rates[8] = (algebraic[7]-states[8])/algebraic[21] algebraic[8] = 1.00000/(1.00000+exp(-(states[0]-10.9300)/19.7000)) algebraic[22] = 0.00100000*(2.98000+15.5900/(1.03700*exp(0.0900000*(states[0]+30.6100))+0.369000*exp(-0.120000*(states[0]+23.8400)))) rates[9] = (algebraic[8]-states[9])/algebraic[22] algebraic[9] = 1.00000/(1.00000+exp(-(states[0]+14.2000)/10.6000)) algebraic[23] = 1.00000/(37.2000*exp((states[0]-9.00000)/15.9000)+0.960000*exp(-(states[0]-9.00000)/22.5000)) rates[10] = (algebraic[9]-states[10])/algebraic[23] algebraic[11] = 14.0000/(1.00000+exp(-(states[0]-40.0000)/9.00000)) algebraic[25] = 1.00000*exp(-states[0]/45.0000) rates[13] = algebraic[11]*(1.00000-states[13])-algebraic[25]*states[13] algebraic[12] = 1.00000*exp(-(states[0]+78.9100)/26.6200) algebraic[26] = 1.00000*exp((states[0]+75.1300)/21.2500) rates[14] = algebraic[12]*(1.00000-states[14])-algebraic[26]*states[14] algebraic[15] = algebraic[2] algebraic[28] = (3.18600e-08*exp(-0.621900*(states[0]+18.8000)))/(1.00000+7.18900e-05*exp(-0.668300*(states[0]+34.0700)))+0.00355600 rates[3] = (algebraic[15]-states[3])/algebraic[28] algebraic[24] = algebraic[9] algebraic[33] = 1.00000/(4.20000*exp((states[0]-9.00000)/17.0000)+0.150000*exp(-(states[0]-9.00000)/21.6000)) rates[11] = (algebraic[24]-states[11])/algebraic[33] algebraic[35] = 1.00000/(1.00000+exp(-(states[0]+23.1000)/6.00000)) algebraic[3] = (-28.3800*(states[0]+35.0000))/(exp(-(states[0]+35.0000)/2.50000)-1.00000)-(84.9000*states[0])/(exp(-0.208000*states[0])-1.00000) algebraic[17] = (11.4200*(states[0]-5.00000))/(exp(0.400000*(states[0]-5.00000))-1.00000) algebraic[29] = 2.00000/(algebraic[3]+algebraic[17]) rates[4] = (algebraic[35]-states[4])/algebraic[29] algebraic[36] = 1.00000/(1.00000+exp((states[0]+45.0000)/5.00000)) algebraic[4] = (3.12000*(states[0]+28.0000))/(exp((states[0]+28.0000)/4.00000)-1.00000) algebraic[18] = 25.0000/(1.00000+exp(-(states[0]+28.0000)/4.00000)) algebraic[30] = 1.00000/(algebraic[4]+algebraic[18]) rates[5] = (algebraic[36]-states[5])/algebraic[30] algebraic[37] = 1.00000/(1.00000+exp(-(states[0]+37.0000)/6.80000)) algebraic[5] = 1068.00*exp((states[0]+26.3000)/30.0000) algebraic[19] = 1068.00*exp(-(states[0]+26.3000)/30.0000) algebraic[31] = 1.00000/(algebraic[5]+algebraic[19]) rates[6] = (algebraic[37]-states[6])/algebraic[31] algebraic[38] = 1.00000/(1.00000+exp((states[0]+71.0000)/9.00000)) algebraic[6] = 15.3000*exp(-(states[0]+71.7000)/83.3000) algebraic[20] = 15.0000*exp((states[0]+71.7000)/15.3800) algebraic[32] = 1.00000/(algebraic[6]+algebraic[20]) rates[7] = (algebraic[38]-states[7])/algebraic[32] algebraic[0] = (0.0952000*exp(-0.0630000*(states[0]+34.4000)))/(1.00000+1.66000*exp(-0.225000*(states[0]+63.7000)))+0.0869000 algebraic[13] = (1.00000-algebraic[0])*states[2]+algebraic[0]*states[3] algebraic[27] = ((((constants[55]*(power(states[1], 3.00000))*algebraic[13]*constants[8]*(power(constants[3], 2.00000)))/(constants[1]*constants[2]))*(exp(((states[0]-constants[50])*constants[3])/(constants[1]*constants[2]))-1.00000))/(exp((states[0]*constants[3])/(constants[1]*constants[2]))-1.00000))*states[0] algebraic[34] = constants[56]*(states[5]*states[4]+0.00600000/(1.00000+exp(-(states[0]+14.1000)/6.00000)))*(states[0]-constants[11]) algebraic[39] = constants[57]*states[6]*states[7]*(states[0]-constants[14]) algebraic[40] = constants[58]*states[8]*states[9]*(states[0]-constants[51]) algebraic[41] = constants[59]*states[9]*(states[0]-constants[51]) algebraic[42] = 0.600000*states[10]+0.400000*states[11] algebraic[43] = constants[60]*algebraic[42]*states[12]*(states[0]-constants[51]) algebraic[44] = constants[61]*(power(states[13], 2.00000))*(states[0]-constants[52]) algebraic[45] = constants[62]*states[14]*(states[0]-constants[50]) algebraic[46] = constants[63]*states[14]*(states[0]-constants[51]) algebraic[47] = constants[64]*(states[0]-constants[50]) algebraic[49] = constants[66]*(states[0]-constants[53]) algebraic[48] = constants[65]*(states[0]-constants[51]) algebraic[50] = (constants[67]*((power(constants[38], 3.00000))*constants[40]*exp(0.0374300*states[0]*constants[37])-(power(constants[8], 3.00000))*constants[39]*exp(0.0374000*states[0]*(constants[37]-1.00000))))/(1.00000+constants[36]*(constants[39]*(power(constants[8], 3.00000))+constants[40]*(power(constants[38], 3.00000)))) algebraic[51] = (constants[68]*(power(constants[38]/(constants[41]+constants[38]), 3.00000))*(power(constants[45]/(constants[42]+constants[45]), 2.00000))*1.60000)/(1.50000+exp(-(states[0]+60.0000)/40.0000)) rates[0] = (-1.00000/constants[54])*(algebraic[27]+algebraic[34]+algebraic[39]+algebraic[40]+algebraic[41]+algebraic[43]+algebraic[44]+algebraic[45]+algebraic[46]+algebraic[47]+algebraic[49]+algebraic[48]+algebraic[50]+algebraic[51]+constants[70]) return(rates) def computeAlgebraic(constants, states, voi): algebraic = array([[0.0] * len(voi)] * sizeAlgebraic) states = array(states) voi = array(voi) algebraic[10] = 1.00000/(1.00000+exp((states[0]+18.6000)/10.1000)) algebraic[1] = power(1.00000/(1.00000+exp(-states[0]/5.46000)), 1.00000/3.00000) algebraic[14] = 0.000624700/(0.832000*exp(-0.335000*(states[0]+56.7000))+0.627000*exp(0.0820000*(states[0]+65.0100)))+4.00000e-05 algebraic[2] = 1.00000/(1.00000+exp((states[0]+66.1000)/6.40000)) algebraic[16] = (3.71700e-06*exp(-0.281500*(states[0]+17.1100)))/(1.00000+0.00373200*exp(-0.342600*(states[0]+37.7600)))+0.000597700 algebraic[7] = 1.00000/(1.00000+exp((states[0]+59.3700)/13.1000)) algebraic[21] = 0.0101000+0.0651700/(0.570000*exp(-0.0800000*(states[0]+49.0000)))+2.40000e-05*exp(0.100000*(states[0]+50.9300)) algebraic[8] = 1.00000/(1.00000+exp(-(states[0]-10.9300)/19.7000)) algebraic[22] = 0.00100000*(2.98000+15.5900/(1.03700*exp(0.0900000*(states[0]+30.6100))+0.369000*exp(-0.120000*(states[0]+23.8400)))) algebraic[9] = 1.00000/(1.00000+exp(-(states[0]+14.2000)/10.6000)) algebraic[23] = 1.00000/(37.2000*exp((states[0]-9.00000)/15.9000)+0.960000*exp(-(states[0]-9.00000)/22.5000)) algebraic[11] = 14.0000/(1.00000+exp(-(states[0]-40.0000)/9.00000)) algebraic[25] = 1.00000*exp(-states[0]/45.0000) algebraic[12] = 1.00000*exp(-(states[0]+78.9100)/26.6200) algebraic[26] = 1.00000*exp((states[0]+75.1300)/21.2500) algebraic[15] = algebraic[2] algebraic[28] = (3.18600e-08*exp(-0.621900*(states[0]+18.8000)))/(1.00000+7.18900e-05*exp(-0.668300*(states[0]+34.0700)))+0.00355600 algebraic[24] = algebraic[9] algebraic[33] = 1.00000/(4.20000*exp((states[0]-9.00000)/17.0000)+0.150000*exp(-(states[0]-9.00000)/21.6000)) algebraic[35] = 1.00000/(1.00000+exp(-(states[0]+23.1000)/6.00000)) algebraic[3] = (-28.3800*(states[0]+35.0000))/(exp(-(states[0]+35.0000)/2.50000)-1.00000)-(84.9000*states[0])/(exp(-0.208000*states[0])-1.00000) algebraic[17] = (11.4200*(states[0]-5.00000))/(exp(0.400000*(states[0]-5.00000))-1.00000) algebraic[29] = 2.00000/(algebraic[3]+algebraic[17]) algebraic[36] = 1.00000/(1.00000+exp((states[0]+45.0000)/5.00000)) algebraic[4] = (3.12000*(states[0]+28.0000))/(exp((states[0]+28.0000)/4.00000)-1.00000) algebraic[18] = 25.0000/(1.00000+exp(-(states[0]+28.0000)/4.00000)) algebraic[30] = 1.00000/(algebraic[4]+algebraic[18]) algebraic[37] = 1.00000/(1.00000+exp(-(states[0]+37.0000)/6.80000)) algebraic[5] = 1068.00*exp((states[0]+26.3000)/30.0000) algebraic[19] = 1068.00*exp(-(states[0]+26.3000)/30.0000) algebraic[31] = 1.00000/(algebraic[5]+algebraic[19]) algebraic[38] = 1.00000/(1.00000+exp((states[0]+71.0000)/9.00000)) algebraic[6] = 15.3000*exp(-(states[0]+71.7000)/83.3000) algebraic[20] = 15.0000*exp((states[0]+71.7000)/15.3800) algebraic[32] = 1.00000/(algebraic[6]+algebraic[20]) algebraic[0] = (0.0952000*exp(-0.0630000*(states[0]+34.4000)))/(1.00000+1.66000*exp(-0.225000*(states[0]+63.7000)))+0.0869000 algebraic[13] = (1.00000-algebraic[0])*states[2]+algebraic[0]*states[3] algebraic[27] = ((((constants[55]*(power(states[1], 3.00000))*algebraic[13]*constants[8]*(power(constants[3], 2.00000)))/(constants[1]*constants[2]))*(exp(((states[0]-constants[50])*constants[3])/(constants[1]*constants[2]))-1.00000))/(exp((states[0]*constants[3])/(constants[1]*constants[2]))-1.00000))*states[0] algebraic[34] = constants[56]*(states[5]*states[4]+0.00600000/(1.00000+exp(-(states[0]+14.1000)/6.00000)))*(states[0]-constants[11]) algebraic[39] = constants[57]*states[6]*states[7]*(states[0]-constants[14]) algebraic[40] = constants[58]*states[8]*states[9]*(states[0]-constants[51]) algebraic[41] = constants[59]*states[9]*(states[0]-constants[51]) algebraic[42] = 0.600000*states[10]+0.400000*states[11] algebraic[43] = constants[60]*algebraic[42]*states[12]*(states[0]-constants[51]) algebraic[44] = constants[61]*(power(states[13], 2.00000))*(states[0]-constants[52]) algebraic[45] = constants[62]*states[14]*(states[0]-constants[50]) algebraic[46] = constants[63]*states[14]*(states[0]-constants[51]) algebraic[47] = constants[64]*(states[0]-constants[50]) algebraic[49] = constants[66]*(states[0]-constants[53]) algebraic[48] = constants[65]*(states[0]-constants[51]) algebraic[50] = (constants[67]*((power(constants[38], 3.00000))*constants[40]*exp(0.0374300*states[0]*constants[37])-(power(constants[8], 3.00000))*constants[39]*exp(0.0374000*states[0]*(constants[37]-1.00000))))/(1.00000+constants[36]*(constants[39]*(power(constants[8], 3.00000))+constants[40]*(power(constants[38], 3.00000)))) algebraic[51] = (constants[68]*(power(constants[38]/(constants[41]+constants[38]), 3.00000))*(power(constants[45]/(constants[42]+constants[45]), 2.00000))*1.60000)/(1.50000+exp(-(states[0]+60.0000)/40.0000)) return algebraic def solve_model(): """Solve model with ODE solver""" from scipy.integrate import ode # Initialise constants and state variables (init_states, constants) = initConsts() # Set timespan to solve over voi = linspace(0, 10, 500) # Construct ODE object to solve r = ode(computeRates) r.set_integrator('vode', method='bdf', atol=1e-06, rtol=1e-06, max_step=1) r.set_initial_value(init_states, voi[0]) r.set_f_params(constants) # Solve model states = array([[0.0] * len(voi)] * sizeStates) states[:,0] = init_states for (i,t) in enumerate(voi[1:]): if r.successful(): r.integrate(t) states[:,i+1] = r.y else: break # Compute algebraic variables algebraic = computeAlgebraic(constants, states, voi) return (voi, states, algebraic) def plot_model(voi, states, algebraic): """Plot variables against variable of integration""" import pylab (legend_states, legend_algebraic, legend_voi, legend_constants) = createLegends() pylab.figure(1) pylab.plot(voi,vstack((states,algebraic)).T) pylab.xlabel(legend_voi) pylab.legend(legend_states + legend_algebraic, loc='best') pylab.show() if __name__ == "__main__": (voi, states, algebraic) = solve_model() plot_model(voi, states, algebraic)