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 = 93 sizeStates = 24 sizeConstants = 44 from math import * from numpy import * def createLegends(): legend_states = [""] * sizeStates legend_rates = [""] * sizeStates legend_algebraic = [""] * sizeAlgebraic legend_voi = "" legend_constants = [""] * sizeConstants legend_voi = "t in component environment (second)" legend_constants[0] = "R in component environment (J_per_K_per_mol)" legend_constants[1] = "T in component environment (kelvin)" legend_constants[2] = "F in component environment (C_per_mol)" legend_constants[3] = "C_m in component environment (fF)" legend_states[0] = "q_K_o in component environment (fmol)" legend_states[1] = "q_K_i in component environment (fmol)" legend_states[2] = "q_Na_o in component environment (fmol)" legend_states[3] = "q_Na_i in component environment (fmol)" legend_states[4] = "q_H_i in component environment (fmol)" legend_states[5] = "q_MgADP in component environment (fmol)" legend_states[6] = "q_MgATP in component environment (fmol)" legend_states[7] = "q_Pi in component environment (fmol)" legend_states[8] = "q_P7 in component environment (fmol)" legend_states[9] = "q_P14 in component environment (fmol)" legend_states[10] = "q_P15 in component environment (fmol)" legend_states[11] = "q_P1 in component environment (fmol)" legend_states[12] = "q_P2 in component environment (fmol)" legend_states[13] = "q_P3 in component environment (fmol)" legend_states[14] = "q_P4 in component environment (fmol)" legend_states[15] = "q_P5 in component environment (fmol)" legend_states[16] = "q_P6 in component environment (fmol)" legend_states[17] = "q_P10 in component environment (fmol)" legend_states[18] = "q_P11 in component environment (fmol)" legend_states[19] = "q_P12 in component environment (fmol)" legend_states[20] = "q_P13 in component environment (fmol)" legend_states[21] = "q_P8 in component environment (fmol)" legend_states[22] = "q_P9 in component environment (fmol)" legend_algebraic[54] = "v_K_o_NaK in component NaK (fmol_per_sec)" legend_algebraic[47] = "v_K_i_NaK in component NaK (fmol_per_sec)" legend_algebraic[90] = "v_Na_o_NaK in component NaK (fmol_per_sec)" legend_algebraic[69] = "v_Na_i_NaK in component NaK (fmol_per_sec)" legend_algebraic[61] = "v_H_NaK in component NaK (fmol_per_sec)" legend_algebraic[77] = "v_MgADP_NaK in component NaK (fmol_per_sec)" legend_algebraic[70] = "v_MgATP_NaK in component NaK (fmol_per_sec)" legend_algebraic[62] = "v_Pi_NaK in component NaK (fmol_per_sec)" legend_states[23] = "q_mem in component environment (fC)" legend_algebraic[86] = "I_mem_NaK in component NaK (fA)" legend_constants[4] = "kappa_1_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[5] = "kappa_2_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[6] = "kappa_3_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[7] = "kappa_4_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[8] = "kappa_5_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[9] = "kappa_6_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[10] = "kappa_7_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[11] = "kappa_8_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[12] = "kappa_9_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[13] = "kappa_10_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[14] = "kappa_11_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[15] = "kappa_12_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[16] = "kappa_13_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[17] = "kappa_14_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[18] = "kappa_15_NaK in component NaK_parameters (fmol_per_sec)" legend_constants[19] = "K_1_NaK in component NaK_parameters (per_fmol)" legend_constants[20] = "K_2_NaK in component NaK_parameters (per_fmol)" legend_constants[21] = "K_3_NaK in component NaK_parameters (per_fmol)" legend_constants[22] = "K_4_NaK in component NaK_parameters (per_fmol)" legend_constants[23] = "K_5_NaK in component NaK_parameters (per_fmol)" legend_constants[24] = "K_6_NaK in component NaK_parameters (per_fmol)" legend_constants[25] = "K_7_NaK in component NaK_parameters (per_fmol)" legend_constants[26] = "K_8_NaK in component NaK_parameters (per_fmol)" legend_constants[27] = "K_9_NaK in component NaK_parameters (per_fmol)" legend_constants[28] = "K_10_NaK in component NaK_parameters (per_fmol)" legend_constants[29] = "K_11_NaK in component NaK_parameters (per_fmol)" legend_constants[30] = "K_12_NaK in component NaK_parameters (per_fmol)" legend_constants[31] = "K_13_NaK in component NaK_parameters (per_fmol)" legend_constants[32] = "K_14_NaK in component NaK_parameters (per_fmol)" legend_constants[33] = "K_15_NaK in component NaK_parameters (per_fmol)" legend_constants[34] = "K_K_i in component NaK_parameters (per_fmol)" legend_constants[35] = "K_K_o in component NaK_parameters (per_fmol)" legend_constants[36] = "K_Na_i in component NaK_parameters (per_fmol)" legend_constants[37] = "K_Na_o in component NaK_parameters (per_fmol)" legend_constants[38] = "K_MgATP in component NaK_parameters (per_fmol)" legend_constants[39] = "K_MgADP in component NaK_parameters (per_fmol)" legend_constants[40] = "K_Pi in component NaK_parameters (per_fmol)" legend_constants[41] = "K_H in component NaK_parameters (per_fmol)" legend_constants[42] = "zF_5 in component NaK_parameters (C_per_mol)" legend_constants[43] = "zF_8 in component NaK_parameters (C_per_mol)" legend_algebraic[2] = "mu_K_o in component NaK (J_per_mol)" legend_algebraic[3] = "mu_K_i in component NaK (J_per_mol)" legend_algebraic[6] = "mu_Na_o in component NaK (J_per_mol)" legend_algebraic[7] = "mu_Na_i in component NaK (J_per_mol)" legend_algebraic[1] = "mu_H in component NaK (J_per_mol)" legend_algebraic[4] = "mu_MgADP in component NaK (J_per_mol)" legend_algebraic[5] = "mu_MgATP in component NaK (J_per_mol)" legend_algebraic[20] = "mu_P7 in component NaK (J_per_mol)" legend_algebraic[23] = "mu_Pi in component NaK (J_per_mol)" legend_algebraic[13] = "mu_P14 in component NaK (J_per_mol)" legend_algebraic[14] = "mu_P15 in component NaK (J_per_mol)" legend_algebraic[8] = "mu_P1 in component NaK (J_per_mol)" legend_algebraic[15] = "mu_P2 in component NaK (J_per_mol)" legend_algebraic[16] = "mu_P3 in component NaK (J_per_mol)" legend_algebraic[17] = "mu_P4 in component NaK (J_per_mol)" legend_algebraic[18] = "mu_P5 in component NaK (J_per_mol)" legend_algebraic[19] = "mu_P6 in component NaK (J_per_mol)" legend_algebraic[9] = "mu_P10 in component NaK (J_per_mol)" legend_algebraic[10] = "mu_P11 in component NaK (J_per_mol)" legend_algebraic[11] = "mu_P12 in component NaK (J_per_mol)" legend_algebraic[12] = "mu_P13 in component NaK (J_per_mol)" legend_algebraic[21] = "mu_P8 in component NaK (J_per_mol)" legend_algebraic[22] = "mu_P9 in component NaK (J_per_mol)" legend_algebraic[71] = "v_P14 in component NaK (fmol_per_sec)" legend_algebraic[79] = "v_P15 in component NaK (fmol_per_sec)" legend_algebraic[80] = "v_P1 in component NaK (fmol_per_sec)" legend_algebraic[49] = "v_P2 in component NaK (fmol_per_sec)" legend_algebraic[56] = "v_P3 in component NaK (fmol_per_sec)" legend_algebraic[63] = "v_P4 in component NaK (fmol_per_sec)" legend_algebraic[72] = "v_P5 in component NaK (fmol_per_sec)" legend_algebraic[81] = "v_P6 in component NaK (fmol_per_sec)" legend_algebraic[91] = "v_P10 in component NaK (fmol_per_sec)" legend_algebraic[50] = "v_P11 in component NaK (fmol_per_sec)" legend_algebraic[57] = "v_P12 in component NaK (fmol_per_sec)" legend_algebraic[64] = "v_P13 in component NaK (fmol_per_sec)" legend_algebraic[84] = "v_P7 in component NaK (fmol_per_sec)" legend_algebraic[87] = "v_P8 in component NaK (fmol_per_sec)" legend_algebraic[92] = "v_P9 in component NaK (fmol_per_sec)" legend_algebraic[24] = "Af_R1 in component NaK (J_per_mol)" legend_algebraic[39] = "Ar_R1 in component NaK (J_per_mol)" legend_algebraic[40] = "v_R1 in component NaK (fmol_per_sec)" legend_algebraic[25] = "Af_R10 in component NaK (J_per_mol)" legend_algebraic[41] = "Ar_R10 in component NaK (J_per_mol)" legend_algebraic[42] = "v_R10 in component NaK (fmol_per_sec)" legend_algebraic[26] = "Af_R11 in component NaK (J_per_mol)" legend_algebraic[44] = "Ar_R11 in component NaK (J_per_mol)" legend_algebraic[46] = "v_R11 in component NaK (fmol_per_sec)" legend_algebraic[27] = "Af_R12 in component NaK (J_per_mol)" legend_algebraic[51] = "Ar_R12 in component NaK (J_per_mol)" legend_algebraic[53] = "v_R12 in component NaK (fmol_per_sec)" legend_algebraic[28] = "Af_R13 in component NaK (J_per_mol)" legend_algebraic[58] = "Ar_R13 in component NaK (J_per_mol)" legend_algebraic[59] = "v_R13 in component NaK (fmol_per_sec)" legend_algebraic[29] = "Af_R14 in component NaK (J_per_mol)" legend_algebraic[65] = "Ar_R14 in component NaK (J_per_mol)" legend_algebraic[67] = "v_R14 in component NaK (fmol_per_sec)" legend_algebraic[30] = "Af_R15 in component NaK (J_per_mol)" legend_algebraic[73] = "Ar_R15 in component NaK (J_per_mol)" legend_algebraic[75] = "v_R15 in component NaK (fmol_per_sec)" legend_algebraic[31] = "Af_R2 in component NaK (J_per_mol)" legend_algebraic[43] = "Ar_R2 in component NaK (J_per_mol)" legend_algebraic[45] = "v_R2 in component NaK (fmol_per_sec)" legend_algebraic[32] = "Af_R3 in component NaK (J_per_mol)" legend_algebraic[48] = "Ar_R3 in component NaK (J_per_mol)" legend_algebraic[52] = "v_R3 in component NaK (fmol_per_sec)" legend_algebraic[33] = "Af_R4 in component NaK (J_per_mol)" legend_algebraic[55] = "Ar_R4 in component NaK (J_per_mol)" legend_algebraic[60] = "v_R4 in component NaK (fmol_per_sec)" legend_algebraic[34] = "Af_R5 in component NaK (J_per_mol)" legend_algebraic[66] = "Ar_R5 in component NaK (J_per_mol)" legend_algebraic[68] = "v_R5 in component NaK (fmol_per_sec)" legend_algebraic[35] = "Af_R6 in component NaK (J_per_mol)" legend_algebraic[74] = "Ar_R6 in component NaK (J_per_mol)" legend_algebraic[76] = "v_R6 in component NaK (fmol_per_sec)" legend_algebraic[36] = "Af_R7 in component NaK (J_per_mol)" legend_algebraic[78] = "Ar_R7 in component NaK (J_per_mol)" legend_algebraic[82] = "v_R7 in component NaK (fmol_per_sec)" legend_algebraic[37] = "Af_R8 in component NaK (J_per_mol)" legend_algebraic[83] = "Ar_R8 in component NaK (J_per_mol)" legend_algebraic[85] = "v_R8 in component NaK (fmol_per_sec)" legend_algebraic[38] = "Af_R9 in component NaK (J_per_mol)" legend_algebraic[88] = "Ar_R9 in component NaK (J_per_mol)" legend_algebraic[89] = "v_R9 in component NaK (fmol_per_sec)" legend_algebraic[0] = "V_mem in component NaK (volt)" legend_rates[0] = "d/dt q_K_o in component environment (fmol)" legend_rates[1] = "d/dt q_K_i in component environment (fmol)" legend_rates[2] = "d/dt q_Na_o in component environment (fmol)" legend_rates[3] = "d/dt q_Na_i in component environment (fmol)" legend_rates[4] = "d/dt q_H_i in component environment (fmol)" legend_rates[5] = "d/dt q_MgADP in component environment (fmol)" legend_rates[6] = "d/dt q_MgATP in component environment (fmol)" legend_rates[7] = "d/dt q_Pi in component environment (fmol)" legend_rates[23] = "d/dt q_mem in component environment (fC)" legend_rates[8] = "d/dt q_P7 in component environment (fmol)" legend_rates[9] = "d/dt q_P14 in component environment (fmol)" legend_rates[10] = "d/dt q_P15 in component environment (fmol)" legend_rates[11] = "d/dt q_P1 in component environment (fmol)" legend_rates[12] = "d/dt q_P2 in component environment (fmol)" legend_rates[13] = "d/dt q_P3 in component environment (fmol)" legend_rates[14] = "d/dt q_P4 in component environment (fmol)" legend_rates[15] = "d/dt q_P5 in component environment (fmol)" legend_rates[16] = "d/dt q_P6 in component environment (fmol)" legend_rates[17] = "d/dt q_P10 in component environment (fmol)" legend_rates[18] = "d/dt q_P11 in component environment (fmol)" legend_rates[19] = "d/dt q_P12 in component environment (fmol)" legend_rates[20] = "d/dt q_P13 in component environment (fmol)" legend_rates[21] = "d/dt q_P8 in component environment (fmol)" legend_rates[22] = "d/dt q_P9 in component environment (fmol)" return (legend_states, legend_algebraic, legend_voi, legend_constants) def initConsts(): constants = [0.0] * sizeConstants; states = [0.0] * sizeStates; constants[0] = 8.314 constants[1] = 310 constants[2] = 96485 constants[3] = 153400 states[0] = 27.9828 states[1] = 5510 states[2] = 725.48 states[3] = 380 states[4] = 0.0030534 states[5] = 1.33 states[6] = 264.1 states[7] = 15.0898 states[8] = 0.001126432 states[9] = 0.001126432 states[10] = 0.001126432 states[11] = 0.001126432 states[12] = 0.001126432 states[13] = 0.001126432 states[14] = 0.001126432 states[15] = 0.001126432 states[16] = 0.001126432 states[17] = 0.001126432 states[18] = 0.001126432 states[19] = 0.001126432 states[20] = 0.001126432 states[21] = 0.001126432 states[22] = 0.001126432 states[23] = -13039 constants[4] = 28701.2 constants[5] = 1.02749e+06 constants[6] = 36989.9 constants[7] = 110769 constants[8] = 143.043 constants[9] = 0.203578 constants[10] = 73.4728 constants[11] = 70.4896 constants[12] = 19895.6 constants[13] = 1.40388e+06 constants[14] = 7905.94 constants[15] = 6193.15 constants[16] = 0.55667 constants[17] = 6163.37 constants[18] = 1.34489 constants[19] = 1.17033e+06 constants[20] = 8172.83 constants[21] = 228.295 constants[22] = 76.2363 constants[23] = 101.833 constants[24] = 6990.92 constants[25] = 157.403 constants[26] = 494.813 constants[27] = 1.06726e+06 constants[28] = 3781.29 constants[29] = 53.588 constants[30] = 68.4084 constants[31] = 349.31 constants[32] = 105.854 constants[33] = 22775 constants[34] = 0.000123928 constants[35] = 0.455493 constants[36] = 0.00344241 constants[37] = 0.00256511 constants[38] = 0.0445571 constants[39] = 0.204939 constants[40] = 2.00757 constants[41] = 2.00757 constants[42] = -5301.979 constants[43] = -91183.021 return (states, constants) def computeRates(voi, states, constants): rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic algebraic[8] = constants[0]*constants[1]*log(constants[19]*states[11]) algebraic[24] = algebraic[8] algebraic[3] = constants[0]*constants[1]*log(constants[34]*states[1]) algebraic[15] = constants[0]*constants[1]*log(constants[20]*states[12]) algebraic[39] = algebraic[3]+algebraic[15] algebraic[40] = constants[4]*(exp(algebraic[24]/(constants[0]*constants[1]))-exp(algebraic[39]/(constants[0]*constants[1]))) algebraic[31] = algebraic[15] algebraic[16] = constants[0]*constants[1]*log(constants[21]*states[13]) algebraic[43] = algebraic[16]+algebraic[3] algebraic[45] = constants[5]*(exp(algebraic[31]/(constants[0]*constants[1]))-exp(algebraic[43]/(constants[0]*constants[1]))) algebraic[47] = algebraic[40]+algebraic[45] rates[1] = algebraic[47] algebraic[49] = -algebraic[45]+algebraic[40] rates[12] = algebraic[49] algebraic[9] = constants[0]*constants[1]*log(constants[28]*states[17]) algebraic[25] = algebraic[9] algebraic[6] = constants[0]*constants[1]*log(constants[37]*states[2]) algebraic[10] = constants[0]*constants[1]*log(constants[29]*states[18]) algebraic[41] = algebraic[6]+algebraic[10] algebraic[42] = constants[13]*(exp(algebraic[25]/(constants[0]*constants[1]))-exp(algebraic[41]/(constants[0]*constants[1]))) algebraic[2] = constants[0]*constants[1]*log(constants[35]*states[0]) algebraic[26] = algebraic[10]+algebraic[2] algebraic[11] = constants[0]*constants[1]*log(constants[30]*states[19]) algebraic[44] = algebraic[11] algebraic[46] = constants[14]*(exp(algebraic[26]/(constants[0]*constants[1]))-exp(algebraic[44]/(constants[0]*constants[1]))) algebraic[50] = algebraic[42]-algebraic[46] rates[18] = algebraic[50] algebraic[27] = algebraic[11]+algebraic[2] algebraic[12] = constants[0]*constants[1]*log(constants[31]*states[20]) algebraic[51] = algebraic[12] algebraic[53] = constants[15]*(exp(algebraic[27]/(constants[0]*constants[1]))-exp(algebraic[51]/(constants[0]*constants[1]))) algebraic[54] = -algebraic[46]-algebraic[53] rates[0] = algebraic[54] algebraic[7] = constants[0]*constants[1]*log(constants[36]*states[3]) algebraic[32] = algebraic[16]+algebraic[7] algebraic[17] = constants[0]*constants[1]*log(constants[22]*states[14]) algebraic[48] = algebraic[17] algebraic[52] = constants[6]*(exp(algebraic[32]/(constants[0]*constants[1]))-exp(algebraic[48]/(constants[0]*constants[1]))) algebraic[56] = algebraic[45]-algebraic[52] rates[13] = algebraic[56] algebraic[57] = -algebraic[53]+algebraic[46] rates[19] = algebraic[57] algebraic[28] = algebraic[12] algebraic[1] = constants[0]*constants[1]*log(constants[41]*states[4]) algebraic[23] = constants[0]*constants[1]*log(constants[40]*states[7]) algebraic[13] = constants[0]*constants[1]*log(constants[32]*states[9]) algebraic[58] = algebraic[1]+algebraic[23]+algebraic[13] algebraic[59] = constants[16]*(exp(algebraic[28]/(constants[0]*constants[1]))-exp(algebraic[58]/(constants[0]*constants[1]))) algebraic[61] = algebraic[59] rates[4] = algebraic[61] algebraic[62] = algebraic[59] rates[7] = algebraic[62] algebraic[33] = algebraic[17]+algebraic[7] algebraic[18] = constants[0]*constants[1]*log(constants[23]*states[15]) algebraic[55] = algebraic[18] algebraic[60] = constants[7]*(exp(algebraic[33]/(constants[0]*constants[1]))-exp(algebraic[55]/(constants[0]*constants[1]))) algebraic[63] = algebraic[52]-algebraic[60] rates[14] = algebraic[63] algebraic[64] = algebraic[53]-algebraic[59] rates[20] = algebraic[64] algebraic[34] = algebraic[18]+algebraic[7] algebraic[0] = states[23]/constants[3] algebraic[66] = constants[0]*constants[1]*log(constants[24]*states[16])+constants[42]*algebraic[0] algebraic[68] = constants[8]*(exp(algebraic[34]/(constants[0]*constants[1]))-exp(algebraic[66]/(constants[0]*constants[1]))) algebraic[69] = -algebraic[52]-(algebraic[60]+algebraic[68]) rates[3] = algebraic[69] algebraic[5] = constants[0]*constants[1]*log(constants[38]*states[6]) algebraic[29] = algebraic[13]+algebraic[5] algebraic[14] = constants[0]*constants[1]*log(constants[33]*states[10]) algebraic[65] = algebraic[14] algebraic[67] = constants[17]*(exp(algebraic[29]/(constants[0]*constants[1]))-exp(algebraic[65]/(constants[0]*constants[1]))) algebraic[70] = -algebraic[67] rates[6] = algebraic[70] algebraic[71] = -algebraic[67]+algebraic[59] rates[9] = algebraic[71] algebraic[72] = algebraic[60]-algebraic[68] rates[15] = algebraic[72] algebraic[19] = constants[0]*constants[1]*log(constants[24]*states[16]) algebraic[35] = algebraic[19] algebraic[4] = constants[0]*constants[1]*log(constants[39]*states[5]) algebraic[20] = constants[0]*constants[1]*log(constants[25]*states[8]) algebraic[74] = algebraic[20]+algebraic[4] algebraic[76] = constants[9]*(exp(algebraic[35]/(constants[0]*constants[1]))-exp(algebraic[74]/(constants[0]*constants[1]))) algebraic[77] = algebraic[76] rates[5] = algebraic[77] algebraic[30] = algebraic[14] algebraic[73] = algebraic[8] algebraic[75] = constants[18]*(exp(algebraic[30]/(constants[0]*constants[1]))-exp(algebraic[73]/(constants[0]*constants[1]))) algebraic[79] = algebraic[67]-algebraic[75] rates[10] = algebraic[79] algebraic[80] = -algebraic[40]+algebraic[75] rates[11] = algebraic[80] algebraic[81] = algebraic[68]-algebraic[76] rates[16] = algebraic[81] algebraic[36] = algebraic[20] algebraic[21] = constants[0]*constants[1]*log(constants[26]*states[21]) algebraic[78] = algebraic[21] algebraic[82] = constants[10]*(exp(algebraic[36]/(constants[0]*constants[1]))-exp(algebraic[78]/(constants[0]*constants[1]))) algebraic[84] = algebraic[76]-algebraic[82] rates[8] = algebraic[84] algebraic[37] = algebraic[21] algebraic[83] = constants[43]*algebraic[0]+constants[0]*constants[1]*log(constants[37]*states[2])+constants[0]*constants[1]*log(constants[27]*states[22]) algebraic[85] = constants[11]*(exp(algebraic[37]/(constants[0]*constants[1]))-exp(algebraic[83]/(constants[0]*constants[1]))) algebraic[86] = constants[43]*algebraic[85]+constants[42]*algebraic[68] rates[23] = algebraic[86] algebraic[87] = -algebraic[85]+algebraic[82] rates[21] = algebraic[87] algebraic[22] = constants[0]*constants[1]*log(constants[27]*states[22]) algebraic[38] = algebraic[22] algebraic[88] = algebraic[9]+algebraic[6] algebraic[89] = constants[12]*(exp(algebraic[38]/(constants[0]*constants[1]))-exp(algebraic[88]/(constants[0]*constants[1]))) algebraic[90] = algebraic[85]+algebraic[89]+algebraic[42] rates[2] = algebraic[90] algebraic[91] = algebraic[89]-algebraic[42] rates[17] = algebraic[91] algebraic[92] = algebraic[85]-algebraic[89] rates[22] = algebraic[92] return(rates) def computeAlgebraic(constants, states, voi): algebraic = array([[0.0] * len(voi)] * sizeAlgebraic) states = array(states) voi = array(voi) algebraic[8] = constants[0]*constants[1]*log(constants[19]*states[11]) algebraic[24] = algebraic[8] algebraic[3] = constants[0]*constants[1]*log(constants[34]*states[1]) algebraic[15] = constants[0]*constants[1]*log(constants[20]*states[12]) algebraic[39] = algebraic[3]+algebraic[15] algebraic[40] = constants[4]*(exp(algebraic[24]/(constants[0]*constants[1]))-exp(algebraic[39]/(constants[0]*constants[1]))) algebraic[31] = algebraic[15] algebraic[16] = constants[0]*constants[1]*log(constants[21]*states[13]) algebraic[43] = algebraic[16]+algebraic[3] algebraic[45] = constants[5]*(exp(algebraic[31]/(constants[0]*constants[1]))-exp(algebraic[43]/(constants[0]*constants[1]))) algebraic[47] = algebraic[40]+algebraic[45] algebraic[49] = -algebraic[45]+algebraic[40] algebraic[9] = constants[0]*constants[1]*log(constants[28]*states[17]) algebraic[25] = algebraic[9] algebraic[6] = constants[0]*constants[1]*log(constants[37]*states[2]) algebraic[10] = constants[0]*constants[1]*log(constants[29]*states[18]) algebraic[41] = algebraic[6]+algebraic[10] algebraic[42] = constants[13]*(exp(algebraic[25]/(constants[0]*constants[1]))-exp(algebraic[41]/(constants[0]*constants[1]))) algebraic[2] = constants[0]*constants[1]*log(constants[35]*states[0]) algebraic[26] = algebraic[10]+algebraic[2] algebraic[11] = constants[0]*constants[1]*log(constants[30]*states[19]) algebraic[44] = algebraic[11] algebraic[46] = constants[14]*(exp(algebraic[26]/(constants[0]*constants[1]))-exp(algebraic[44]/(constants[0]*constants[1]))) algebraic[50] = algebraic[42]-algebraic[46] algebraic[27] = algebraic[11]+algebraic[2] algebraic[12] = constants[0]*constants[1]*log(constants[31]*states[20]) algebraic[51] = algebraic[12] algebraic[53] = constants[15]*(exp(algebraic[27]/(constants[0]*constants[1]))-exp(algebraic[51]/(constants[0]*constants[1]))) algebraic[54] = -algebraic[46]-algebraic[53] algebraic[7] = constants[0]*constants[1]*log(constants[36]*states[3]) algebraic[32] = algebraic[16]+algebraic[7] algebraic[17] = constants[0]*constants[1]*log(constants[22]*states[14]) algebraic[48] = algebraic[17] algebraic[52] = constants[6]*(exp(algebraic[32]/(constants[0]*constants[1]))-exp(algebraic[48]/(constants[0]*constants[1]))) algebraic[56] = algebraic[45]-algebraic[52] algebraic[57] = -algebraic[53]+algebraic[46] algebraic[28] = algebraic[12] algebraic[1] = constants[0]*constants[1]*log(constants[41]*states[4]) algebraic[23] = constants[0]*constants[1]*log(constants[40]*states[7]) algebraic[13] = constants[0]*constants[1]*log(constants[32]*states[9]) algebraic[58] = algebraic[1]+algebraic[23]+algebraic[13] algebraic[59] = constants[16]*(exp(algebraic[28]/(constants[0]*constants[1]))-exp(algebraic[58]/(constants[0]*constants[1]))) algebraic[61] = algebraic[59] algebraic[62] = algebraic[59] algebraic[33] = algebraic[17]+algebraic[7] algebraic[18] = constants[0]*constants[1]*log(constants[23]*states[15]) algebraic[55] = algebraic[18] algebraic[60] = constants[7]*(exp(algebraic[33]/(constants[0]*constants[1]))-exp(algebraic[55]/(constants[0]*constants[1]))) algebraic[63] = algebraic[52]-algebraic[60] algebraic[64] = algebraic[53]-algebraic[59] algebraic[34] = algebraic[18]+algebraic[7] algebraic[0] = states[23]/constants[3] algebraic[66] = constants[0]*constants[1]*log(constants[24]*states[16])+constants[42]*algebraic[0] algebraic[68] = constants[8]*(exp(algebraic[34]/(constants[0]*constants[1]))-exp(algebraic[66]/(constants[0]*constants[1]))) algebraic[69] = -algebraic[52]-(algebraic[60]+algebraic[68]) algebraic[5] = constants[0]*constants[1]*log(constants[38]*states[6]) algebraic[29] = algebraic[13]+algebraic[5] algebraic[14] = constants[0]*constants[1]*log(constants[33]*states[10]) algebraic[65] = algebraic[14] algebraic[67] = constants[17]*(exp(algebraic[29]/(constants[0]*constants[1]))-exp(algebraic[65]/(constants[0]*constants[1]))) algebraic[70] = -algebraic[67] algebraic[71] = -algebraic[67]+algebraic[59] algebraic[72] = algebraic[60]-algebraic[68] algebraic[19] = constants[0]*constants[1]*log(constants[24]*states[16]) algebraic[35] = algebraic[19] algebraic[4] = constants[0]*constants[1]*log(constants[39]*states[5]) algebraic[20] = constants[0]*constants[1]*log(constants[25]*states[8]) algebraic[74] = algebraic[20]+algebraic[4] algebraic[76] = constants[9]*(exp(algebraic[35]/(constants[0]*constants[1]))-exp(algebraic[74]/(constants[0]*constants[1]))) algebraic[77] = algebraic[76] algebraic[30] = algebraic[14] algebraic[73] = algebraic[8] algebraic[75] = constants[18]*(exp(algebraic[30]/(constants[0]*constants[1]))-exp(algebraic[73]/(constants[0]*constants[1]))) algebraic[79] = algebraic[67]-algebraic[75] algebraic[80] = -algebraic[40]+algebraic[75] algebraic[81] = algebraic[68]-algebraic[76] algebraic[36] = algebraic[20] algebraic[21] = constants[0]*constants[1]*log(constants[26]*states[21]) algebraic[78] = algebraic[21] algebraic[82] = constants[10]*(exp(algebraic[36]/(constants[0]*constants[1]))-exp(algebraic[78]/(constants[0]*constants[1]))) algebraic[84] = algebraic[76]-algebraic[82] algebraic[37] = algebraic[21] algebraic[83] = constants[43]*algebraic[0]+constants[0]*constants[1]*log(constants[37]*states[2])+constants[0]*constants[1]*log(constants[27]*states[22]) algebraic[85] = constants[11]*(exp(algebraic[37]/(constants[0]*constants[1]))-exp(algebraic[83]/(constants[0]*constants[1]))) algebraic[86] = constants[43]*algebraic[85]+constants[42]*algebraic[68] algebraic[87] = -algebraic[85]+algebraic[82] algebraic[22] = constants[0]*constants[1]*log(constants[27]*states[22]) algebraic[38] = algebraic[22] algebraic[88] = algebraic[9]+algebraic[6] algebraic[89] = constants[12]*(exp(algebraic[38]/(constants[0]*constants[1]))-exp(algebraic[88]/(constants[0]*constants[1]))) algebraic[90] = algebraic[85]+algebraic[89]+algebraic[42] algebraic[91] = algebraic[89]-algebraic[42] algebraic[92] = algebraic[85]-algebraic[89] 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)