# Size of variable arrays: sizeAlgebraic = 41 sizeStates = 27 sizeConstants = 65 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] = "RT in component fixed_parameters (kilojoule_per_mole)" legend_constants[1] = "F in component fixed_parameters (kilojoule_per_mole_per_millivolt)" legend_constants[2] = "dG_C1o in component fixed_parameters (kilojoule_per_mole)" legend_constants[3] = "dG_C3o in component fixed_parameters (kilojoule_per_mole)" legend_constants[4] = "dG_C4o in component fixed_parameters (kilojoule_per_mole)" legend_algebraic[3] = "dG_C1op in component fixed_parameters (kilojoule_per_mole)" legend_algebraic[6] = "dG_C3op in component fixed_parameters (kilojoule_per_mole)" legend_algebraic[7] = "dG_C4op in component fixed_parameters (kilojoule_per_mole)" legend_constants[5] = "dG_F1o in component fixed_parameters (kilojoule_per_mole)" legend_algebraic[0] = "dG_H in component fixed_parameters (kilojoule_per_mole)" legend_constants[6] = "k_dHPI in component fixed_parameters (molar)" legend_constants[7] = "k_dHatp in component fixed_parameters (molar)" legend_constants[8] = "k_dHadp in component fixed_parameters (molar)" legend_constants[9] = "K_DT in component fixed_parameters (molar)" legend_constants[10] = "K_DD in component fixed_parameters (molar)" legend_constants[11] = "K_AK in component fixed_parameters (dimensionless)" legend_constants[12] = "K_CK in component fixed_parameters (per_molar)" legend_constants[13] = "W_c in component fixed_parameters (l_water_per_l_cyto)" legend_constants[14] = "W_x in component fixed_parameters (l_water_per_l_mito)" legend_constants[15] = "W_i in component fixed_parameters (l_water_per_l_mito)" legend_constants[16] = "V_cyto in component fixed_parameters (cyto_per_cell)" legend_constants[17] = "V_mito in component fixed_parameters (mito_per_cell)" legend_constants[61] = "Rm_cyto in component fixed_parameters (mito_per_cyto)" legend_constants[58] = "Rm_cell in component fixed_parameters (mito_per_cell)" legend_constants[63] = "Rc_cell in component fixed_parameters (cyto_per_cell)" legend_constants[18] = "n_A in component fixed_parameters (dimensionless)" legend_constants[19] = "C_tot in component fixed_parameters (molar)" legend_constants[20] = "CR_tot in component fixed_parameters (molar)" legend_constants[21] = "Q_tot in component fixed_parameters (molar)" legend_constants[22] = "NAD_tot in component fixed_parameters (molar)" legend_constants[23] = "pH_C in component fixed_parameters (dimensionless)" legend_constants[59] = "H_c in component fixed_parameters (molar)" legend_constants[24] = "K_c in component fixed_parameters (molar)" legend_constants[25] = "ATP_c in component fixed_parameters (molar)" legend_constants[26] = "AMP_c in component fixed_parameters (molar)" legend_constants[62] = "H_i in component fixed_parameters (molar)" legend_constants[60] = "K_i in component fixed_parameters (molar)" legend_states[0] = "H_x in component dH_x_dt (molar)" legend_states[1] = "deltaPsi in component ddeltaPsi_dt (millivolt)" legend_constants[27] = "k_PI1 in component adjustable_parameters (molar)" legend_constants[28] = "k_PI2 in component adjustable_parameters (molar)" legend_constants[29] = "k_PI3 in component adjustable_parameters (molar)" legend_constants[30] = "k_PI4 in component adjustable_parameters (molar)" legend_constants[31] = "k_PIH in component adjustable_parameters (molar)" legend_constants[32] = "r in component adjustable_parameters (dimensionless)" legend_constants[33] = "X_DH in component adjustable_parameters (mole_per_second_per_l_mito_per_molar)" legend_constants[34] = "X_C1 in component adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_molar)" legend_constants[35] = "X_C3 in component adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_half_molar)" legend_constants[36] = "X_C4 in component adjustable_parameters (mole_per_second_per_l_mito_per_molar)" legend_constants[37] = "X_F1 in component adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_molar)" legend_constants[38] = "X_ANT in component adjustable_parameters (mole_per_second_per_l_mito_per_molar)" legend_constants[39] = "X_PI1 in component adjustable_parameters (mole_per_second_per_l_mito_per_molar)" legend_constants[40] = "X_KH in component adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_molar)" legend_constants[41] = "X_Hle in component adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_millivolt)" legend_constants[42] = "X_K in component adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_millivolt)" legend_constants[43] = "k_mADP in component adjustable_parameters (molar)" legend_constants[44] = "X_AK in component adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_molar)" legend_constants[45] = "X_CK in component adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_molar)" legend_constants[46] = "X_MgA in component adjustable_parameters (mole_per_second_per_l_mito_per_molar_per_molar)" legend_constants[47] = "k_O2 in component adjustable_parameters (molar)" legend_constants[48] = "beta in component adjustable_parameters (molar)" legend_constants[49] = "C_IM in component adjustable_parameters (mole_per_l_mito_per_millivolt)" legend_constants[50] = "X_A in component adjustable_parameters (micron_per_second)" legend_constants[51] = "X_PI2 in component adjustable_parameters (micron_per_second)" legend_constants[52] = "gamma in component adjustable_parameters (per_micron)" legend_algebraic[8] = "NAD_x in component dNAD_x_dt (molar)" legend_states[2] = "NADH_x in component dNADH_x_dt (molar)" legend_algebraic[9] = "QH2_x in component dQH2_x_dt (molar)" legend_states[3] = "Q_x in component dQ_x_dt (molar)" legend_algebraic[10] = "Cred_x in component dCred_x_dt (molar)" legend_states[4] = "Cox_x in component dCox_x_dt (molar)" legend_algebraic[11] = "ATP_fx in component dATP_fx_dt (molar)" legend_states[5] = "ATP_x in component dATP_x_dt (molar)" legend_states[6] = "ATP_mx in component dATP_mx_dt (molar)" legend_algebraic[12] = "ADP_fx in component dADP_fx_dt (molar)" legend_states[7] = "ADP_x in component dADP_x_dt (molar)" legend_states[8] = "ADP_mx in component dADP_mx_dt (molar)" legend_algebraic[19] = "J_DH in component J_DH (mole_per_second_per_l_mito)" legend_algebraic[21] = "J_C1 in component J_C1 (mole_per_second_per_l_mito)" legend_algebraic[22] = "J_C3 in component J_C3 (mole_per_second_per_l_mito)" legend_algebraic[23] = "J_C4 in component J_C4 (mole_per_second_per_l_mito)" legend_algebraic[24] = "J_F1 in component J_F1 (mole_per_second_per_l_mito)" legend_algebraic[32] = "J_PI1 in component J_PI1 (mole_per_second_per_l_mito)" legend_algebraic[38] = "J_KH in component J_KH (mole_per_second_per_l_mito)" legend_algebraic[34] = "J_Hle in component J_Hle (mole_per_second_per_l_mito)" legend_states[9] = "K_x in component dK_x_dt (molar)" legend_algebraic[40] = "J_K in component J_K (mole_per_second_per_l_mito)" legend_states[10] = "Mg_x in component dMg_x_dt (molar)" legend_algebraic[14] = "J_MgATP_x in component J_MgATP_x (mole_per_second_per_l_mito)" legend_algebraic[16] = "J_MgADP_x in component J_MgADP_x (mole_per_second_per_l_mito)" legend_algebraic[27] = "J_ANT in component J_ANT (mole_per_second_per_l_mito)" legend_states[11] = "PI_x in component dPI_x_dt (molar)" legend_algebraic[13] = "ATP_fi in component dATP_fi_dt (molar)" legend_states[12] = "ATP_i in component dATP_i_dt (molar)" legend_states[13] = "ATP_mi in component dATP_mi_dt (molar)" legend_algebraic[15] = "ADP_fi in component dADP_fi_dt (molar)" legend_states[14] = "ADP_i in component dADP_i_dt (molar)" legend_states[15] = "ADP_mi in component dADP_mi_dt (molar)" legend_algebraic[33] = "J_ATP in component J_ATP (mole_per_second_per_l_mito)" legend_algebraic[35] = "J_AKi in component J_AKi (mole_per_second_per_l_mito)" legend_algebraic[31] = "J_ADP in component J_ADP (mole_per_second_per_l_mito)" legend_states[16] = "AMP_i in component dAMP_i_dt (molar)" legend_algebraic[29] = "J_AMP in component J_AMP (mole_per_second_per_l_mito)" legend_algebraic[18] = "J_MgATP_i in component J_MgATP_i (mole_per_second_per_l_mito)" legend_algebraic[20] = "J_MgADP_i in component J_MgADP_i (mole_per_second_per_l_mito)" legend_states[17] = "PI_i in component dPI_i_dt (molar)" legend_algebraic[36] = "J_PI2 in component J_PI2 (mole_per_second_per_l_mito)" legend_states[18] = "Mg_i in component dMg_i_dt (molar)" legend_states[19] = "ATP_c in component dATP_c_dt (molar)" legend_algebraic[37] = "J_AKc in component J_AKc (mole_per_second_per_l_cyto)" legend_constants[64] = "J_AtC in component J_AtC (mole_per_second_per_l_cell)" legend_algebraic[39] = "J_CKc in component J_CKc (mole_per_second_per_l_cyto)" legend_states[20] = "ADP_c in component dADP_c_dt (molar)" legend_states[21] = "AMP_c in component dAMP_c_dt (molar)" legend_states[22] = "ATP_mc in component dATP_mc_dt (molar)" legend_algebraic[4] = "J_MgATP_c in component J_MgATP_c (mole_per_second_per_l_cyto)" legend_states[23] = "ADP_mc in component dADP_mc_dt (molar)" legend_algebraic[5] = "J_MgADP_c in component J_MgADP_c (mole_per_second_per_l_cyto)" legend_states[24] = "PI_c in component dPI_c_dt (molar)" legend_states[25] = "Mg_c in component dMg_c_dt (molar)" legend_states[26] = "PCr_c in component dPCr_c_dt (molar)" legend_algebraic[1] = "ATP_fc in component dATP_fc_dt (molar)" legend_algebraic[2] = "ADP_fc in component dADP_fc_dt (molar)" legend_algebraic[17] = "Cr_c in component dCr_c_dt (molar)" legend_constants[53] = "O2_x in component J_C4 (molar)" legend_constants[54] = "mincon in component J_ANT (molar)" legend_algebraic[25] = "Psi_x in component J_ANT (millivolt)" legend_algebraic[26] = "Psi_i in component J_ANT (millivolt)" legend_algebraic[28] = "H2PIi in component J_PI1 (molar)" legend_algebraic[30] = "H2PIx in component J_PI1 (molar)" legend_constants[55] = "mincond in component J_Hle (millivolt)" legend_constants[56] = "mincond in component J_K (millivolt)" legend_constants[57] = "X_AtC in component J_AtC (mole_per_second_per_l_cell)" legend_rates[0] = "d/dt H_x in component dH_x_dt (molar)" legend_rates[9] = "d/dt K_x in component dK_x_dt (molar)" legend_rates[10] = "d/dt Mg_x in component dMg_x_dt (molar)" legend_rates[2] = "d/dt NADH_x in component dNADH_x_dt (molar)" legend_rates[3] = "d/dt Q_x in component dQ_x_dt (molar)" legend_rates[4] = "d/dt Cox_x in component dCox_x_dt (molar)" legend_rates[5] = "d/dt ATP_x in component dATP_x_dt (molar)" legend_rates[7] = "d/dt ADP_x in component dADP_x_dt (molar)" legend_rates[6] = "d/dt ATP_mx in component dATP_mx_dt (molar)" legend_rates[8] = "d/dt ADP_mx in component dADP_mx_dt (molar)" legend_rates[11] = "d/dt PI_x in component dPI_x_dt (molar)" legend_rates[12] = "d/dt ATP_i in component dATP_i_dt (molar)" legend_rates[14] = "d/dt ADP_i in component dADP_i_dt (molar)" legend_rates[16] = "d/dt AMP_i in component dAMP_i_dt (molar)" legend_rates[13] = "d/dt ATP_mi in component dATP_mi_dt (molar)" legend_rates[15] = "d/dt ADP_mi in component dADP_mi_dt (molar)" legend_rates[17] = "d/dt PI_i in component dPI_i_dt (molar)" legend_rates[18] = "d/dt Mg_i in component dMg_i_dt (molar)" legend_rates[19] = "d/dt ATP_c in component dATP_c_dt (molar)" legend_rates[20] = "d/dt ADP_c in component dADP_c_dt (molar)" legend_rates[21] = "d/dt AMP_c in component dAMP_c_dt (molar)" legend_rates[22] = "d/dt ATP_mc in component dATP_mc_dt (molar)" legend_rates[23] = "d/dt ADP_mc in component dADP_mc_dt (molar)" legend_rates[24] = "d/dt PI_c in component dPI_c_dt (molar)" legend_rates[25] = "d/dt Mg_c in component dMg_c_dt (molar)" legend_rates[26] = "d/dt PCr_c in component dPCr_c_dt (molar)" legend_rates[1] = "d/dt deltaPsi in component ddeltaPsi_dt (millivolt)" return (legend_states, legend_algebraic, legend_voi, legend_constants) def initConsts(): constants = [0.0] * sizeConstants; states = [0.0] * sizeStates; constants[0] = 2.5775 constants[1] = 0.096484 constants[2] = -69.37 constants[3] = -32.53 constants[4] = -122.94 constants[5] = 36.03 constants[6] = 1.7782754100389227e-7 constants[7] = 3.311311214825911e-7 constants[8] = 5.128613839913649e-7 constants[9] = 24e-6 constants[10] = 347e-6 constants[11] = 0.4331 constants[12] = 1.66e9 constants[13] = 0.8425 constants[14] = 0.6514 constants[15] = 0.0724 constants[16] = 0.894 constants[17] = 0.056 constants[18] = 3 constants[19] = 2.7e-3 constants[20] = 42.7e-3 constants[21] = 1.35e-3 constants[22] = 2.97e-3 constants[23] = 7 constants[24] = 0.15 constants[25] = 0 constants[26] = 0 states[0] = 1e-7 states[1] = 166.67 constants[27] = 0.1553e-3 constants[28] = 0.8222e-3 constants[29] = 0.3601e-3 constants[30] = 5.924e-3 constants[31] = 2.542e-4 constants[32] = 4.599 constants[33] = 0.0866 constants[34] = 4.405e3 constants[35] = 4.887 constants[36] = 6.766e-5 constants[37] = 1e3 constants[38] = 8.123e-3 constants[39] = 3.85e5 constants[40] = 5.651e7 constants[41] = 200 constants[42] = 0 constants[43] = 3.5e-6 constants[44] = 1e7 constants[45] = 1e7 constants[46] = 1e7 constants[47] = 1.2e-4 constants[48] = 0.01 constants[49] = 6.75e-6 constants[50] = 85 constants[51] = 327 constants[52] = 5.99 states[2] = 0.0015723 states[3] = 6.75e-4 states[4] = 1.35e-3 states[5] = 0.0026657 states[6] = 0.0026046 states[7] = 0.0073343 states[8] = 0.0054765 states[9] = 0.14661 states[10] = 1.0229e-3 states[11] = 1.72e-4 states[12] = 0.0065339 states[13] = 0.0063812 states[14] = 6.5773e-5 states[15] = 4.8866e-5 states[16] = 2.8837e-7 states[17] = 1.72e-4 states[18] = 0.0010029 states[19] = 0.0081312 states[20] = 6.85e-5 states[21] = 3.0911e-7 states[22] = 0.0079786 states[23] = 5.1958e-5 states[24] = 8.7702e-3 states[25] = 0.001003 states[26] = 23.589e-3 constants[53] = 0 constants[54] = 1e-9 constants[55] = 1e-6 constants[56] = 1e-6 constants[57] = 0 constants[58] = constants[17] constants[59] = 1.00000*(power(10.0000, -constants[23])) constants[60] = constants[24] constants[61] = constants[17]/constants[16] constants[62] = constants[59] constants[63] = constants[16] constants[64] = constants[57] return (states, constants) def computeRates(voi, states, constants): rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic algebraic[1] = states[19]-states[22] algebraic[4] = constants[46]*(algebraic[1]*states[25]-constants[9]*states[22]) rates[22] = algebraic[4]/constants[13] algebraic[2] = states[20]-states[23] algebraic[5] = constants[46]*(algebraic[2]*states[25]-constants[10]*states[23]) rates[23] = algebraic[5]/constants[13] rates[25] = (-algebraic[4]-algebraic[4])/constants[13] algebraic[11] = states[5]-states[6] algebraic[14] = constants[46]*(algebraic[11]*states[10]-constants[9]*states[6]) rates[6] = algebraic[14]/constants[14] algebraic[12] = states[7]-states[8] algebraic[16] = constants[46]*(algebraic[12]*states[10]-constants[10]*states[8]) rates[10] = (-algebraic[16]-algebraic[14])/constants[14] rates[8] = algebraic[16]/constants[14] algebraic[13] = states[12]-states[13] algebraic[18] = constants[46]*(algebraic[13]*states[18]-constants[9]*states[13]) rates[13] = algebraic[18]/constants[15] algebraic[15] = states[14]-states[15] algebraic[20] = constants[46]*(algebraic[15]*states[18]-constants[10]*states[15]) rates[15] = algebraic[20]/constants[15] rates[18] = (-algebraic[20]-algebraic[18])/constants[15] algebraic[8] = constants[22]-states[2] algebraic[19] = (constants[33]*(constants[32]*algebraic[8]-states[2])*(1.00000+states[11]/constants[27]))/(1.00000+states[11]/constants[28]) algebraic[3] = constants[2]-1.00000*constants[0]*log((states[0]/1.00000)*(power(10.0000, 7.00000)), 10) algebraic[0] = constants[1]*states[1]+constants[0]*log(constants[62]/states[0], 10) algebraic[9] = constants[21]-states[3] algebraic[21] = constants[34]*(exp(-(algebraic[3]+4.00000*algebraic[0])/constants[0])*states[2]*states[3]-algebraic[8]*algebraic[9]) rates[2] = (algebraic[19]-algebraic[21])/constants[14] algebraic[6] = constants[3]+2.00000*constants[0]*log((states[0]/1.00000)*(power(10.0000, 7.00000)), 10) algebraic[10] = constants[19]-states[4] algebraic[22] = ((constants[35]*(1.00000+states[11]/constants[29]))/(1.00000+states[11]/constants[30]))*(exp(-((algebraic[6]+4.00000*algebraic[0])-2.00000*constants[1]*states[1])/(2.00000*constants[0]))*states[4]*(power(algebraic[9], 1.0/2))-algebraic[10]*(power(states[3], 1.0/2))) rates[3] = (algebraic[21]-algebraic[22])/constants[14] algebraic[7] = constants[4]-2.00000*constants[0]*log((states[0]/1.00000)*(power(10.0000, 7.00000)), 10) algebraic[23] = custom_piecewise([less(constants[53] , 1.00000e-12), 0.00000 , True, ((((constants[36]*constants[53])/(constants[53]+constants[47]))*algebraic[10])/constants[19])*(exp(-(algebraic[7]+2.00000*algebraic[0])/(2.00000*constants[0]))*algebraic[10]*(power(constants[53], 0.250000))-states[4]*exp((constants[1]*states[1])/constants[0]))]) rates[4] = (2.00000*algebraic[22]-2.00000*algebraic[23])/constants[14] algebraic[24] = constants[37]*(((exp(-(constants[5]-constants[18]*algebraic[0])/constants[0])*constants[10])/constants[9])*states[8]*states[11]-states[6]*1.00000) algebraic[25] = -0.650000*states[1] algebraic[26] = 0.350000*states[1] algebraic[27] = custom_piecewise([greater(algebraic[15] , constants[54]) & greater(algebraic[13] , constants[54]), (constants[38]*(algebraic[15]/(algebraic[15]+algebraic[13]*exp((-constants[1]*algebraic[26])/constants[0]))-algebraic[12]/(algebraic[12]+algebraic[11]*exp((-constants[1]*algebraic[25])/constants[0])))*algebraic[15])/(algebraic[15]+constants[43]) , True, 0.00000]) rates[5] = (algebraic[24]-algebraic[27])/constants[14] rates[7] = (-algebraic[24]+algebraic[27])/constants[14] algebraic[28] = (states[17]*constants[62])/(constants[62]+constants[6]) algebraic[30] = (states[11]*states[0])/(states[0]+constants[6]) algebraic[32] = (constants[39]*(constants[62]*algebraic[28]-states[0]*algebraic[30]))/(algebraic[28]+constants[31]) rates[11] = (-algebraic[24]-algebraic[32])/constants[14] algebraic[33] = constants[52]*constants[50]*(states[19]-states[12]) algebraic[35] = constants[44]*(constants[11]*states[14]*states[14]-states[16]*states[12]) rates[12] = (algebraic[33]+algebraic[27]+algebraic[35])/constants[15] algebraic[31] = constants[52]*constants[50]*(states[20]-states[14]) rates[14] = ((algebraic[31]-algebraic[27])-2.00000*algebraic[35])/constants[15] algebraic[29] = constants[52]*constants[50]*(states[21]-states[16]) rates[16] = (algebraic[29]+algebraic[35])/constants[15] algebraic[36] = constants[52]*constants[51]*(states[24]-states[17]) rates[17] = (-algebraic[32]+algebraic[36])/constants[15] algebraic[37] = constants[44]*(constants[11]*states[20]*states[20]-states[21]*states[19]) rates[21] = (-constants[61]*algebraic[29]+algebraic[37])/constants[13] rates[24] = (-algebraic[36]*constants[61]+constants[64]/constants[63])/constants[13] algebraic[38] = constants[40]*(constants[60]*states[0]-states[9]*constants[62]) algebraic[34] = custom_piecewise([greater(fabs(states[1]) , constants[55]), (constants[41]*states[1]*(constants[62]*exp((constants[1]*states[1])/constants[0])-states[0]))/(exp((constants[1]*states[1])/constants[0])-1.00000) , True, (constants[41]*constants[0]*(constants[62]-states[0]))/constants[1]]) rates[0] = ((states[0]/constants[48])*((((((algebraic[19]-5.00000*algebraic[21])-2.00000*algebraic[22])-4.00000*algebraic[23])+(constants[18]-1.00000)*algebraic[24]+2.00000*algebraic[32])-algebraic[38])+algebraic[34]))/constants[14] algebraic[17] = constants[20]-states[26] algebraic[39] = constants[45]*(constants[12]*states[20]*states[26]*constants[59]-states[19]*algebraic[17]) rates[19] = (((-constants[61]*algebraic[33]+algebraic[37])-constants[64]/constants[63])+algebraic[39])/constants[13] rates[20] = (((-constants[61]*algebraic[31]-2.00000*algebraic[37])+constants[64]/constants[63])-algebraic[39])/constants[13] rates[26] = -algebraic[39]/constants[13] algebraic[40] = custom_piecewise([greater(fabs(states[1]) , constants[56]), (constants[42]*states[1]*(constants[60]*exp((constants[1]*states[1])/constants[0])-states[9]))/(exp((constants[1]*states[1])/constants[0])-1.00000) , True, (constants[42]*constants[0]*(constants[60]-states[9]))/constants[1]]) rates[9] = (algebraic[38]+algebraic[40])/constants[14] rates[1] = (((((4.00000*algebraic[21]+2.00000*algebraic[22]+4.00000*algebraic[23])-constants[18]*algebraic[24])-algebraic[27])-algebraic[34])-algebraic[40])/constants[49] return(rates) def computeAlgebraic(constants, states, voi): algebraic = array([[0.0] * len(voi)] * sizeAlgebraic) states = array(states) voi = array(voi) algebraic[1] = states[19]-states[22] algebraic[4] = constants[46]*(algebraic[1]*states[25]-constants[9]*states[22]) algebraic[2] = states[20]-states[23] algebraic[5] = constants[46]*(algebraic[2]*states[25]-constants[10]*states[23]) algebraic[11] = states[5]-states[6] algebraic[14] = constants[46]*(algebraic[11]*states[10]-constants[9]*states[6]) algebraic[12] = states[7]-states[8] algebraic[16] = constants[46]*(algebraic[12]*states[10]-constants[10]*states[8]) algebraic[13] = states[12]-states[13] algebraic[18] = constants[46]*(algebraic[13]*states[18]-constants[9]*states[13]) algebraic[15] = states[14]-states[15] algebraic[20] = constants[46]*(algebraic[15]*states[18]-constants[10]*states[15]) algebraic[8] = constants[22]-states[2] algebraic[19] = (constants[33]*(constants[32]*algebraic[8]-states[2])*(1.00000+states[11]/constants[27]))/(1.00000+states[11]/constants[28]) algebraic[3] = constants[2]-1.00000*constants[0]*log((states[0]/1.00000)*(power(10.0000, 7.00000)), 10) algebraic[0] = constants[1]*states[1]+constants[0]*log(constants[62]/states[0], 10) algebraic[9] = constants[21]-states[3] algebraic[21] = constants[34]*(exp(-(algebraic[3]+4.00000*algebraic[0])/constants[0])*states[2]*states[3]-algebraic[8]*algebraic[9]) algebraic[6] = constants[3]+2.00000*constants[0]*log((states[0]/1.00000)*(power(10.0000, 7.00000)), 10) algebraic[10] = constants[19]-states[4] algebraic[22] = ((constants[35]*(1.00000+states[11]/constants[29]))/(1.00000+states[11]/constants[30]))*(exp(-((algebraic[6]+4.00000*algebraic[0])-2.00000*constants[1]*states[1])/(2.00000*constants[0]))*states[4]*(power(algebraic[9], 1.0/2))-algebraic[10]*(power(states[3], 1.0/2))) algebraic[7] = constants[4]-2.00000*constants[0]*log((states[0]/1.00000)*(power(10.0000, 7.00000)), 10) algebraic[23] = custom_piecewise([less(constants[53] , 1.00000e-12), 0.00000 , True, ((((constants[36]*constants[53])/(constants[53]+constants[47]))*algebraic[10])/constants[19])*(exp(-(algebraic[7]+2.00000*algebraic[0])/(2.00000*constants[0]))*algebraic[10]*(power(constants[53], 0.250000))-states[4]*exp((constants[1]*states[1])/constants[0]))]) algebraic[24] = constants[37]*(((exp(-(constants[5]-constants[18]*algebraic[0])/constants[0])*constants[10])/constants[9])*states[8]*states[11]-states[6]*1.00000) algebraic[25] = -0.650000*states[1] algebraic[26] = 0.350000*states[1] algebraic[27] = custom_piecewise([greater(algebraic[15] , constants[54]) & greater(algebraic[13] , constants[54]), (constants[38]*(algebraic[15]/(algebraic[15]+algebraic[13]*exp((-constants[1]*algebraic[26])/constants[0]))-algebraic[12]/(algebraic[12]+algebraic[11]*exp((-constants[1]*algebraic[25])/constants[0])))*algebraic[15])/(algebraic[15]+constants[43]) , True, 0.00000]) algebraic[28] = (states[17]*constants[62])/(constants[62]+constants[6]) algebraic[30] = (states[11]*states[0])/(states[0]+constants[6]) algebraic[32] = (constants[39]*(constants[62]*algebraic[28]-states[0]*algebraic[30]))/(algebraic[28]+constants[31]) algebraic[33] = constants[52]*constants[50]*(states[19]-states[12]) algebraic[35] = constants[44]*(constants[11]*states[14]*states[14]-states[16]*states[12]) algebraic[31] = constants[52]*constants[50]*(states[20]-states[14]) algebraic[29] = constants[52]*constants[50]*(states[21]-states[16]) algebraic[36] = constants[52]*constants[51]*(states[24]-states[17]) algebraic[37] = constants[44]*(constants[11]*states[20]*states[20]-states[21]*states[19]) algebraic[38] = constants[40]*(constants[60]*states[0]-states[9]*constants[62]) algebraic[34] = custom_piecewise([greater(fabs(states[1]) , constants[55]), (constants[41]*states[1]*(constants[62]*exp((constants[1]*states[1])/constants[0])-states[0]))/(exp((constants[1]*states[1])/constants[0])-1.00000) , True, (constants[41]*constants[0]*(constants[62]-states[0]))/constants[1]]) algebraic[17] = constants[20]-states[26] algebraic[39] = constants[45]*(constants[12]*states[20]*states[26]*constants[59]-states[19]*algebraic[17]) algebraic[40] = custom_piecewise([greater(fabs(states[1]) , constants[56]), (constants[42]*states[1]*(constants[60]*exp((constants[1]*states[1])/constants[0])-states[9]))/(exp((constants[1]*states[1])/constants[0])-1.00000) , True, (constants[42]*constants[0]*(constants[60]-states[9]))/constants[1]]) 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)