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 = 44 sizeStates = 11 sizeConstants = 72 from math import * from numpy import * def createLegends(): legend_states = [""] * sizeStates legend_rates = [""] * sizeStates legend_algebraic = [""] * sizeAlgebraic legend_voi = "" legend_constants = [""] * sizeConstants legend_voi = "time in component environment (millisecond)" legend_algebraic[3] = "SOVFThick in component sarcomere_geometry (dimensionless)" legend_algebraic[4] = "SOVFThin in component sarcomere_geometry (dimensionless)" legend_algebraic[0] = "sovr_ze in component sarcomere_geometry (micrometre)" legend_algebraic[1] = "sovr_cle in component sarcomere_geometry (micrometre)" legend_algebraic[2] = "len_sovr in component sarcomere_geometry (micrometre)" legend_constants[0] = "len_thin in component model_parameters (micrometre)" legend_constants[1] = "len_thick in component model_parameters (micrometre)" legend_constants[2] = "len_hbare in component model_parameters (micrometre)" legend_states[0] = "SL in component normalised_active_and_passive_force (micrometre)" legend_states[1] = "TRPNCaL in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_states[2] = "TRPNCaH in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_algebraic[7] = "dTRPNCaL in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)" legend_algebraic[10] = "dTRPNCaH in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)" legend_algebraic[12] = "kn_pT in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)" legend_algebraic[18] = "kp_nT in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)" legend_constants[58] = "H in component Ca_binding_to_troponin_to_thin_filament_regulation (micromolar)" legend_constants[61] = "H_cons in component Ca_binding_to_troponin_to_thin_filament_regulation (micromolar)" legend_constants[62] = "konT in component Ca_binding_to_troponin_to_thin_filament_regulation (second_order_rate_constant)" legend_constants[56] = "koffLT in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)" legend_constants[57] = "koffHT in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)" legend_constants[3] = "Qkon in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_constants[4] = "Qkoff in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_constants[5] = "Qkn_p in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_constants[6] = "Qkp_n in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_constants[7] = "kon in component Ca_binding_to_troponin_to_thin_filament_regulation (second_order_rate_constant)" legend_constants[8] = "koffL in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)" legend_constants[9] = "koffH in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)" legend_constants[10] = "perm50 in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_constants[11] = "nperm in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_constants[12] = "kn_p in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)" legend_constants[13] = "kp_n in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)" legend_constants[14] = "koffmod in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_algebraic[6] = "Tropreg in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_algebraic[9] = "permtot in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_algebraic[15] = "inprmt in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_constants[15] = "pH in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_constants[16] = "m in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_constants[17] = "kdHCa in component Ca_binding_to_troponin_to_thin_filament_regulation (micromolar)" legend_constants[18] = "TmpC in component model_parameters (kelvin)" legend_constants[19] = "Cai in component model_parameters (micromolar)" legend_constants[63] = "fappT in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)" legend_algebraic[16] = "gappT in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)" legend_algebraic[20] = "hfT in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)" legend_constants[65] = "hbT in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)" legend_algebraic[23] = "gxbT in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)" legend_constants[20] = "fapp in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)" legend_constants[21] = "gapp in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)" legend_constants[22] = "hf in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)" legend_constants[23] = "hb in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)" legend_constants[24] = "gxb in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)" legend_constants[25] = "gslmod in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_algebraic[19] = "hfmd in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[64] = "hbmd in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[26] = "hfmdc in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[27] = "hbmdc in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[28] = "sigmap in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[29] = "sigman in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[30] = "xbmodsp in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[31] = "Qfapp in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[32] = "Qgapp in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[33] = "Qhf in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[34] = "Qhb in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[35] = "Qgxb in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_algebraic[22] = "gxbmd in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_algebraic[13] = "gapslmd in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)" legend_constants[36] = "x_0 in component model_parameters (micrometre)" legend_states[3] = "xXBpostr in component mean_strain_of_strongly_bound_states (micrometre)" legend_states[4] = "xXBprer in component mean_strain_of_strongly_bound_states (micrometre)" legend_states[5] = "XBpostr in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_states[6] = "XBprer in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_algebraic[32] = "dXBpostr in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)" legend_algebraic[27] = "dXBprer in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)" legend_constants[66] = "alpha1_plus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)" legend_algebraic[24] = "alpha2_plus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)" legend_algebraic[25] = "alpha3_plus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)" legend_algebraic[26] = "alpha1_minus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)" legend_constants[68] = "alpha2_minus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)" legend_algebraic[29] = "alpha3_minus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)" legend_constants[37] = "kMgATP in component regulation_and_crossbridge_cycling_state_equations (micromolar2)" legend_constants[38] = "kdADP in component regulation_and_crossbridge_cycling_state_equations (micromolar)" legend_constants[39] = "xPi_cons in component regulation_and_crossbridge_cycling_state_equations (micromolar)" legend_constants[40] = "MgATP_cons in component regulation_and_crossbridge_cycling_state_equations (micromolar)" legend_algebraic[28] = "fxbT in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)" legend_states[7] = "N_NoXB in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_states[8] = "P_NoXB in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_states[9] = "P in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_algebraic[21] = "N in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_constants[41] = "MgADP_cons in component regulation_and_crossbridge_cycling_state_equations (micromolar)" legend_constants[42] = "xPi in component regulation_and_crossbridge_cycling_state_equations (micromolar)" legend_constants[43] = "MgATP in component regulation_and_crossbridge_cycling_state_equations (micromolar)" legend_constants[44] = "MgADP in component regulation_and_crossbridge_cycling_state_equations (micromolar)" legend_algebraic[33] = "dxXBpostr in component mean_strain_of_strongly_bound_states (micrometre_per_millisecond)" legend_algebraic[34] = "dxXBprer in component mean_strain_of_strongly_bound_states (micrometre_per_millisecond)" legend_constants[45] = "xPsi in component mean_strain_of_strongly_bound_states (dimensionless)" legend_algebraic[31] = "dutyprer in component mean_strain_of_strongly_bound_states (dimensionless)" legend_algebraic[30] = "dutypostr in component mean_strain_of_strongly_bound_states (dimensionless)" legend_constants[59] = "dSL in component normalised_active_and_passive_force (micrometre_per_millisecond)" legend_constants[70] = "SSXBpostr in component normalised_active_and_passive_force (dimensionless)" legend_constants[69] = "SSXBprer in component normalised_active_and_passive_force (dimensionless)" legend_algebraic[14] = "ppforce in component normalised_active_and_passive_force (unit_normalised_force)" legend_algebraic[8] = "ppforce_t in component normalised_active_and_passive_force (unit_normalised_force)" legend_algebraic[11] = "ppforce_c in component normalised_active_and_passive_force (unit_normalised_force)" legend_constants[60] = "preload in component normalised_active_and_passive_force (unit_normalised_force)" legend_algebraic[17] = "afterload in component normalised_active_and_passive_force (unit_normalised_force)" legend_states[10] = "intf in component normalised_active_and_passive_force (unit_normalised_force_millisecond)" legend_constants[46] = "SL_c in component normalised_active_and_passive_force (micrometre)" legend_constants[47] = "SLrest in component normalised_active_and_passive_force (micrometre)" legend_constants[48] = "SLset in component normalised_active_and_passive_force (micrometre)" legend_constants[49] = "PCon_t in component normalised_active_and_passive_force (unit_normalised_force)" legend_constants[50] = "PExp_t in component normalised_active_and_passive_force (per_micrometre)" legend_constants[51] = "PCon_c in component normalised_active_and_passive_force (unit_normalised_force)" legend_constants[52] = "PExp_c in component normalised_active_and_passive_force (per_micrometre)" legend_constants[53] = "KSE in component normalised_active_and_passive_force (unit_normalised_force_per_micrometre)" legend_constants[67] = "fxb in component normalised_active_and_passive_force (first_order_rate_constant)" legend_constants[54] = "SEon in component normalised_active_and_passive_force (dimensionless)" legend_algebraic[5] = "F_active in component normalised_active_and_passive_force (unit_normalised_force)" legend_algebraic[35] = "FrSBXB in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (dimensionless)" legend_algebraic[36] = "dFrSBXB in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (first_order_rate_constant)" legend_algebraic[38] = "dsovr_ze in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micrometre_per_millisecond)" legend_algebraic[39] = "dsovr_cle in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micrometre_per_millisecond)" legend_algebraic[40] = "dlen_sovr in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micrometre_per_millisecond)" legend_algebraic[41] = "dSOVFThick in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (first_order_rate_constant)" legend_algebraic[42] = "dSOVFThin in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (first_order_rate_constant)" legend_constants[55] = "Trop_conc in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micromolar)" legend_algebraic[37] = "TropTot in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micromolar)" legend_algebraic[43] = "dTropTot in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micromolar_per_millisecond)" legend_rates[1] = "d/dt TRPNCaL in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_rates[2] = "d/dt TRPNCaH in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)" legend_rates[7] = "d/dt N_NoXB in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_rates[8] = "d/dt P_NoXB in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_rates[9] = "d/dt P in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_rates[6] = "d/dt XBprer in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_rates[5] = "d/dt XBpostr in component regulation_and_crossbridge_cycling_state_equations (dimensionless)" legend_rates[4] = "d/dt xXBprer in component mean_strain_of_strongly_bound_states (micrometre)" legend_rates[3] = "d/dt xXBpostr in component mean_strain_of_strongly_bound_states (micrometre)" legend_rates[0] = "d/dt SL in component normalised_active_and_passive_force (micrometre)" legend_rates[10] = "d/dt intf in component normalised_active_and_passive_force (unit_normalised_force_millisecond)" return (legend_states, legend_algebraic, legend_voi, legend_constants) def initConsts(): constants = [0.0] * sizeConstants; states = [0.0] * sizeStates; constants[0] = 1.2 constants[1] = 1.65 constants[2] = 0.1 states[0] = 2.2 states[1] = 0.0147730085063734 states[2] = 0.13066096561522 constants[3] = 1.5 constants[4] = 1.3 constants[5] = 1.6 constants[6] = 1.6 constants[7] = 0.05 constants[8] = 0.25 constants[9] = 0.025 constants[10] = 0.5 constants[11] = 15 constants[12] = 0.5 constants[13] = 0.05 constants[14] = 1 constants[15] = 7.15 constants[16] = 1 constants[17] = 2e-2 constants[18] = 299 constants[19] = 200.0 constants[20] = 0.5 constants[21] = 0.07 constants[22] = 2 constants[23] = 0.4 constants[24] = 0.07 constants[25] = 6 constants[26] = 5 constants[27] = 0 constants[28] = 8 constants[29] = 1 constants[30] = 0.2 constants[31] = 6.25 constants[32] = 2.5 constants[33] = 6.25 constants[34] = 6.25 constants[35] = 6.25 constants[36] = 0.007 states[3] = 0.00700005394873882 states[4] = 3.41212828972468e-8 states[5] = 1.81017564383744e-6 states[6] = 3.0494964880038e-7 constants[37] = 15400e6 constants[38] = 4 constants[39] = 2e3 constants[40] = 5e3 states[7] = 0.999999959256274 states[8] = 4.07437173988636e-8 states[9] = 0.999997834540066 constants[41] = 36 constants[42] = 2e3 constants[43] = 5e3 constants[44] = 36.3 constants[45] = 2 states[10] = -4.5113452510363e-6 constants[46] = 2.25 constants[47] = 1.85 constants[48] = 1.9 constants[49] = 0.002 constants[50] = 10 constants[51] = 0.02 constants[52] = 70 constants[53] = 1 constants[54] = 1 constants[55] = 70 constants[56] = constants[8]*constants[14]*(power(constants[4], (constants[18]-310.000)/10.0000)) constants[57] = constants[9]*constants[14]*(power(constants[4], (constants[18]-310.000)/10.0000)) constants[58] = 1.00000e+07*(power(10.0000, -constants[15])) constants[59] = 0.00000 constants[60] = (fabs(constants[48]-constants[47])/(constants[48]-constants[47]))*constants[49]*(exp(constants[50]*fabs(constants[48]-constants[47]))-1.00000) constants[61] = 1.00000e+07*(power(10.0000, -7.15000)) constants[71] = constants[59] constants[62] = ((power(constants[17], constants[16])+power(constants[61], constants[16]))/(power(constants[17], constants[16])+power(constants[58], constants[16])))*constants[7]*(power(constants[3], (constants[18]-310.000)/10.0000)) constants[63] = constants[20]*constants[30]*(power(constants[31], (constants[18]-310.000)/10.0000)) constants[64] = 1.00000 constants[65] = constants[23]*constants[64]*constants[30]*(power(constants[34], (constants[18]-310.000)/10.0000)) constants[66] = constants[63] constants[67] = ((constants[38]*constants[20]*constants[22]*constants[24])/constants[40])/((((constants[21]/constants[39])*constants[23])/constants[61])*constants[37]) constants[68] = (((((constants[58]*constants[65])/constants[61])*(constants[38]+constants[41]))/constants[41])*constants[44])/(constants[38]+constants[44]) constants[69] = (constants[67]*constants[23]+constants[24]*constants[20]+constants[65]*constants[20])/(constants[22]*constants[24]+constants[23]*constants[21]+constants[24]*constants[21]+constants[67]*constants[23]+constants[24]*constants[20]+constants[23]*constants[20]+constants[67]*constants[21]+constants[20]*constants[22]+constants[67]*constants[23]) constants[70] = (constants[20]*constants[22]+constants[67]*constants[21]+constants[67]*constants[23])/(constants[22]*constants[24]+constants[23]*constants[21]+constants[24]*constants[21]+constants[67]*constants[23]+constants[24]*constants[20]+constants[23]*constants[20]+constants[67]*constants[21]+constants[20]*constants[22]+constants[67]*constants[23]) return (states, constants) def computeRates(voi, states, constants): rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic rates[0] = constants[71] algebraic[7] = constants[62]*constants[19]*(1.00000-states[1])-constants[56]*states[1] rates[1] = algebraic[7] algebraic[10] = constants[62]*constants[19]*(1.00000-states[2])-constants[57]*states[2] rates[2] = algebraic[10] algebraic[8] = ((states[0]-constants[47])/fabs(states[0]-constants[47]))*constants[49]*(exp(constants[50]*fabs(states[0]-constants[47]))-1.00000) algebraic[11] = custom_piecewise([greater(states[0] , constants[46]), constants[51]*(exp(constants[52]*fabs(states[0]-constants[46]))-1.00000) , True, 0.00000]) algebraic[14] = algebraic[8]+algebraic[11] algebraic[17] = custom_piecewise([equal(constants[54] , 1.00000), constants[53]*(constants[48]-states[0]) , True, 0.00000]) algebraic[0] = custom_piecewise([less(constants[1]/2.00000 , states[0]/2.00000), constants[1]/2.00000 , True, states[0]/2.00000]) algebraic[1] = custom_piecewise([greater(states[0]/2.00000-(states[0]-constants[0]) , constants[2]/2.00000), states[0]/2.00000-(states[0]-constants[0]) , True, constants[2]/2.00000]) algebraic[2] = algebraic[0]-algebraic[1] algebraic[3] = (algebraic[2]*2.00000)/(constants[1]-constants[2]) algebraic[5] = (algebraic[3]*(states[3]*states[5]+states[4]*states[6]))/(constants[36]*constants[70]) rates[10] = (constants[60]+algebraic[17])-(algebraic[14]+algebraic[5]) algebraic[4] = algebraic[2]/constants[0] algebraic[6] = (1.00000-algebraic[4])*states[1]+algebraic[4]*states[2] algebraic[9] = power(fabs(1.00000/(1.00000+power(constants[10]/algebraic[6], constants[11]))), 1.0/2) algebraic[12] = constants[12]*algebraic[9]*(power(constants[5], (constants[18]-310.000)/10.0000)) algebraic[15] = custom_piecewise([less(1.00000/algebraic[9] , 100.000), 1.00000/algebraic[9] , True, 100.000]) algebraic[18] = constants[13]*algebraic[15]*(power(constants[6], (constants[18]-310.000)/10.0000)) rates[7] = algebraic[18]*states[8]-algebraic[12]*states[7] rates[8] = algebraic[12]*states[7]-algebraic[18]*states[8] algebraic[21] = 1.00000-(states[9]+states[6]+states[5]) rates[9] = algebraic[12]*algebraic[21]-(algebraic[18]+constants[66])*states[9] algebraic[19] = exp((-states[4]/fabs(states[4]))*constants[26]*(power(states[4]/constants[36], 2.00000))) algebraic[20] = constants[22]*algebraic[19]*constants[30]*(power(constants[33], (constants[18]-310.000)/10.0000)) algebraic[24] = algebraic[20] algebraic[13] = 1.00000+(1.00000-algebraic[3])*constants[25] algebraic[16] = constants[21]*algebraic[13]*constants[30]*(power(constants[32], (constants[18]-310.000)/10.0000)) algebraic[26] = (constants[42]*algebraic[16])/constants[39] algebraic[27] = (constants[66]*states[9]+constants[68]*states[5])-(algebraic[26]+algebraic[24])*states[6] rates[6] = algebraic[27] algebraic[22] = custom_piecewise([less(states[3] , constants[36]), exp(constants[28]*(power((constants[36]-states[3])/constants[36], 2.00000))) , True, exp(constants[29]*(power((states[3]-constants[36])/constants[36], 2.00000)))]) algebraic[23] = constants[24]*algebraic[22]*constants[30]*(power(constants[35], (constants[18]-310.000)/10.0000)) algebraic[25] = (((constants[43]*algebraic[23])/constants[40])*(constants[38]+constants[41]))/(constants[38]+constants[44]) algebraic[28] = ((constants[38]*constants[63]*algebraic[20]*algebraic[23])/constants[40])/((((algebraic[16]/constants[39])*constants[65])/constants[61])*constants[37]) algebraic[29] = algebraic[28] algebraic[32] = (algebraic[29]*states[9]+algebraic[24]*states[6])-(constants[68]+algebraic[25])*states[5] rates[5] = algebraic[32] algebraic[31] = (algebraic[29]*constants[68]+algebraic[25]*constants[66]+constants[68]*constants[66])/(constants[66]*algebraic[24]+algebraic[29]*algebraic[26]+algebraic[29]*algebraic[24]+algebraic[29]*constants[68]+algebraic[25]*constants[66]+constants[68]*constants[66]+algebraic[24]*algebraic[25]+algebraic[29]*algebraic[26]+algebraic[25]*algebraic[26]) algebraic[34] = constants[59]/2.00000+(constants[45]/algebraic[31])*(-constants[66]*states[4]+constants[68]*(states[3]-(constants[36]+states[4]))) rates[4] = algebraic[34] algebraic[30] = (constants[66]*algebraic[24]+algebraic[29]*algebraic[26]+algebraic[29]*algebraic[24])/(constants[66]*algebraic[24]+algebraic[29]*algebraic[26]+algebraic[29]*algebraic[24]+algebraic[29]*constants[68]+algebraic[25]*constants[66]+constants[68]*constants[66]+algebraic[24]*algebraic[25]+algebraic[29]*algebraic[26]+algebraic[25]*algebraic[26]) algebraic[33] = constants[59]/2.00000+(constants[45]/algebraic[30])*algebraic[24]*((states[4]+constants[36])-states[3]) rates[3] = algebraic[33] return(rates) def computeAlgebraic(constants, states, voi): algebraic = array([[0.0] * len(voi)] * sizeAlgebraic) states = array(states) voi = array(voi) algebraic[7] = constants[62]*constants[19]*(1.00000-states[1])-constants[56]*states[1] algebraic[10] = constants[62]*constants[19]*(1.00000-states[2])-constants[57]*states[2] algebraic[8] = ((states[0]-constants[47])/fabs(states[0]-constants[47]))*constants[49]*(exp(constants[50]*fabs(states[0]-constants[47]))-1.00000) algebraic[11] = custom_piecewise([greater(states[0] , constants[46]), constants[51]*(exp(constants[52]*fabs(states[0]-constants[46]))-1.00000) , True, 0.00000]) algebraic[14] = algebraic[8]+algebraic[11] algebraic[17] = custom_piecewise([equal(constants[54] , 1.00000), constants[53]*(constants[48]-states[0]) , True, 0.00000]) algebraic[0] = custom_piecewise([less(constants[1]/2.00000 , states[0]/2.00000), constants[1]/2.00000 , True, states[0]/2.00000]) algebraic[1] = custom_piecewise([greater(states[0]/2.00000-(states[0]-constants[0]) , constants[2]/2.00000), states[0]/2.00000-(states[0]-constants[0]) , True, constants[2]/2.00000]) algebraic[2] = algebraic[0]-algebraic[1] algebraic[3] = (algebraic[2]*2.00000)/(constants[1]-constants[2]) algebraic[5] = (algebraic[3]*(states[3]*states[5]+states[4]*states[6]))/(constants[36]*constants[70]) algebraic[4] = algebraic[2]/constants[0] algebraic[6] = (1.00000-algebraic[4])*states[1]+algebraic[4]*states[2] algebraic[9] = power(fabs(1.00000/(1.00000+power(constants[10]/algebraic[6], constants[11]))), 1.0/2) algebraic[12] = constants[12]*algebraic[9]*(power(constants[5], (constants[18]-310.000)/10.0000)) algebraic[15] = custom_piecewise([less(1.00000/algebraic[9] , 100.000), 1.00000/algebraic[9] , True, 100.000]) algebraic[18] = constants[13]*algebraic[15]*(power(constants[6], (constants[18]-310.000)/10.0000)) algebraic[21] = 1.00000-(states[9]+states[6]+states[5]) algebraic[19] = exp((-states[4]/fabs(states[4]))*constants[26]*(power(states[4]/constants[36], 2.00000))) algebraic[20] = constants[22]*algebraic[19]*constants[30]*(power(constants[33], (constants[18]-310.000)/10.0000)) algebraic[24] = algebraic[20] algebraic[13] = 1.00000+(1.00000-algebraic[3])*constants[25] algebraic[16] = constants[21]*algebraic[13]*constants[30]*(power(constants[32], (constants[18]-310.000)/10.0000)) algebraic[26] = (constants[42]*algebraic[16])/constants[39] algebraic[27] = (constants[66]*states[9]+constants[68]*states[5])-(algebraic[26]+algebraic[24])*states[6] algebraic[22] = custom_piecewise([less(states[3] , constants[36]), exp(constants[28]*(power((constants[36]-states[3])/constants[36], 2.00000))) , True, exp(constants[29]*(power((states[3]-constants[36])/constants[36], 2.00000)))]) algebraic[23] = constants[24]*algebraic[22]*constants[30]*(power(constants[35], (constants[18]-310.000)/10.0000)) algebraic[25] = (((constants[43]*algebraic[23])/constants[40])*(constants[38]+constants[41]))/(constants[38]+constants[44]) algebraic[28] = ((constants[38]*constants[63]*algebraic[20]*algebraic[23])/constants[40])/((((algebraic[16]/constants[39])*constants[65])/constants[61])*constants[37]) algebraic[29] = algebraic[28] algebraic[32] = (algebraic[29]*states[9]+algebraic[24]*states[6])-(constants[68]+algebraic[25])*states[5] algebraic[31] = (algebraic[29]*constants[68]+algebraic[25]*constants[66]+constants[68]*constants[66])/(constants[66]*algebraic[24]+algebraic[29]*algebraic[26]+algebraic[29]*algebraic[24]+algebraic[29]*constants[68]+algebraic[25]*constants[66]+constants[68]*constants[66]+algebraic[24]*algebraic[25]+algebraic[29]*algebraic[26]+algebraic[25]*algebraic[26]) algebraic[34] = constants[59]/2.00000+(constants[45]/algebraic[31])*(-constants[66]*states[4]+constants[68]*(states[3]-(constants[36]+states[4]))) algebraic[30] = (constants[66]*algebraic[24]+algebraic[29]*algebraic[26]+algebraic[29]*algebraic[24])/(constants[66]*algebraic[24]+algebraic[29]*algebraic[26]+algebraic[29]*algebraic[24]+algebraic[29]*constants[68]+algebraic[25]*constants[66]+constants[68]*constants[66]+algebraic[24]*algebraic[25]+algebraic[29]*algebraic[26]+algebraic[25]*algebraic[26]) algebraic[33] = constants[59]/2.00000+(constants[45]/algebraic[30])*algebraic[24]*((states[4]+constants[36])-states[3]) algebraic[35] = (states[5]+states[6])/(constants[70]+constants[69]) algebraic[36] = (algebraic[32]+algebraic[27])/(constants[70]+constants[69]) algebraic[37] = constants[55]*((1.00000-algebraic[4])*states[1]+algebraic[4]*(algebraic[35]*states[2]+(1.00000-algebraic[35])*states[1])) algebraic[38] = custom_piecewise([less(states[0] , constants[1]), -0.500000*constants[59] , True, 0.00000]) algebraic[39] = custom_piecewise([greater(2.00000*constants[0]-states[0] , constants[2]), -0.500000*constants[59] , True, 0.00000]) algebraic[40] = algebraic[38]-algebraic[39] algebraic[41] = (2.00000*algebraic[40])/(constants[1]-constants[2]) algebraic[42] = algebraic[40]/constants[0] algebraic[43] = constants[55]*(-algebraic[42]*states[1]+(1.00000-algebraic[4])*algebraic[7]+algebraic[42]*(algebraic[35]*states[2]+(1.00000-algebraic[35])*states[1])+algebraic[4]*((algebraic[36]*states[2]+algebraic[35]*algebraic[10]+(1.00000-algebraic[35])*algebraic[7])-algebraic[36]*states[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)