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 = 55
sizeStates = 19
sizeConstants = 59
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] = "q_RB1_inactive_init in component environment (fmol)"
    legend_constants[1] = "q_L_RB1_inactive_init in component environment (fmol)"
    legend_algebraic[0] = "q_LB1_init in component environment (fmol)"
    legend_constants[2] = "q_RB1_init in component environment (fmol)"
    legend_constants[3] = "q_Gs_init in component environment (fmol)"
    legend_constants[4] = "q_RB1_Gs_init in component environment (fmol)"
    legend_constants[5] = "q_L_RB1_init in component environment (fmol)"
    legend_constants[6] = "q_L_RB1_Gs_init in component environment (fmol)"
    legend_constants[7] = "q_Gsa_GTP_init in component environment (fmol)"
    legend_constants[8] = "q_Gsbetagamma_init in component environment (fmol)"
    legend_constants[9] = "q_Gsa_GDP_init in component environment (fmol)"
    legend_constants[10] = "q_GTP_init in component environment (fmol)"
    legend_constants[11] = "q_GDP_init in component environment (fmol)"
    legend_constants[12] = "q_Pi_init in component environment (fmol)"
    legend_constants[13] = "q_RB1_tag_init in component environment (fmol)"
    legend_constants[14] = "q_L_RB1_tag_init in component environment (fmol)"
    legend_constants[15] = "q_RB1_GRKArr_init in component environment (fmol)"
    legend_constants[16] = "q_L_RB1_GRKArr_init in component environment (fmol)"
    legend_constants[17] = "q_GRKArr_init in component environment (fmol)"
    legend_constants[18] = "stimSt in component environment (second)"
    legend_constants[19] = "stimDur in component environment (second)"
    legend_constants[20] = "tR in component environment (second)"
    legend_constants[21] = "stimMag in component environment (fmol)"
    legend_constants[22] = "stimHolding in component environment (fmol)"
    legend_constants[57] = "m in component environment (fmol_per_sec)"
    legend_algebraic[1] = "q_RB1_inactive in component environment (fmol)"
    legend_algebraic[2] = "q_L_RB1_inactive in component environment (fmol)"
    legend_algebraic[3] = "q_LB1 in component environment (fmol)"
    legend_algebraic[4] = "q_RB1 in component environment (fmol)"
    legend_algebraic[5] = "q_Gs in component environment (fmol)"
    legend_algebraic[6] = "q_RB1_Gs in component environment (fmol)"
    legend_algebraic[7] = "q_L_RB1 in component environment (fmol)"
    legend_algebraic[8] = "q_L_RB1_Gs in component environment (fmol)"
    legend_algebraic[9] = "q_Gsa_GTP in component environment (fmol)"
    legend_algebraic[10] = "q_Gsbetagamma in component environment (fmol)"
    legend_algebraic[11] = "q_Gsa_GDP in component environment (fmol)"
    legend_algebraic[13] = "q_GTP in component environment (fmol)"
    legend_algebraic[14] = "q_GDP in component environment (fmol)"
    legend_algebraic[15] = "q_Pi in component environment (fmol)"
    legend_algebraic[16] = "q_RB1_tag in component environment (fmol)"
    legend_algebraic[17] = "q_L_RB1_tag in component environment (fmol)"
    legend_algebraic[18] = "q_RB1_GRKArr in component environment (fmol)"
    legend_algebraic[19] = "q_L_RB1_GRKArr in component environment (fmol)"
    legend_algebraic[22] = "q_GRKArr in component environment (fmol)"
    legend_states[0] = "q_RB1_inactive in component GPCR_B1AR_reduced (fmol)"
    legend_states[1] = "q_L_RB1_inactive in component GPCR_B1AR_reduced (fmol)"
    legend_states[2] = "q_LB1 in component GPCR_B1AR_reduced (fmol)"
    legend_states[3] = "q_RB1 in component GPCR_B1AR_reduced (fmol)"
    legend_states[4] = "q_Gs in component GPCR_B1AR_reduced (fmol)"
    legend_states[5] = "q_RB1_Gs in component GPCR_B1AR_reduced (fmol)"
    legend_states[6] = "q_L_RB1 in component GPCR_B1AR_reduced (fmol)"
    legend_states[7] = "q_L_RB1_Gs in component GPCR_B1AR_reduced (fmol)"
    legend_states[8] = "q_Gsa_GTP in component GPCR_B1AR_reduced (fmol)"
    legend_states[9] = "q_Gsbetagamma in component GPCR_B1AR_reduced (fmol)"
    legend_states[10] = "q_Gsa_GDP in component GPCR_B1AR_reduced (fmol)"
    legend_states[11] = "q_GTP in component GPCR_B1AR_reduced (fmol)"
    legend_states[12] = "q_GDP in component GPCR_B1AR_reduced (fmol)"
    legend_states[13] = "q_Pi in component GPCR_B1AR_reduced (fmol)"
    legend_states[14] = "q_RB1_tag in component GPCR_B1AR_reduced (fmol)"
    legend_states[15] = "q_L_RB1_tag in component GPCR_B1AR_reduced (fmol)"
    legend_states[16] = "q_RB1_GRKArr in component GPCR_B1AR_reduced (fmol)"
    legend_states[17] = "q_L_RB1_GRKArr in component GPCR_B1AR_reduced (fmol)"
    legend_states[18] = "q_GRKArr in component GPCR_B1AR_reduced (fmol)"
    legend_algebraic[20] = "conserv_R_T in component environment (fmol)"
    legend_algebraic[21] = "conserv_L_T in component environment (fmol)"
    legend_algebraic[12] = "conserv_G_T in component environment (fmol)"
    legend_constants[58] = "total_R_init in component environment (fmol)"
    legend_constants[23] = "kappa_Rswitch_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[24] = "kappa_LRswitch_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[25] = "kappa_C_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[26] = "kappa_R_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[27] = "kappa_L_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[28] = "kappa_L_actR in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[29] = "kappa_Act1_Gs in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[30] = "kappa_Act2_Gs in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[31] = "kappa_Hyd_Gs in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[32] = "kappa_Reassoc_Gs in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[33] = "kappa_InternR_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[34] = "kappa_InternLR_B1 in component GPCR_B1AR_reduced_parameters (fmol_per_sec)"
    legend_constants[35] = "K_RB1_inactive in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[36] = "K_L_RB1_inactive in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[37] = "K_LB1 in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[38] = "K_RB1 in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[39] = "K_Gs in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[40] = "K_RB1_Gs in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[41] = "K_L_RB1 in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[42] = "K_L_RB1_Gs in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[43] = "K_Gsa_GTP in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[44] = "K_Gsbetagamma in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[45] = "K_Gsa_GDP in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[46] = "K_GTP in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[47] = "K_GDP in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[48] = "K_Pi in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[49] = "K_RB1_tag in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[50] = "K_L_RB1_tag in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[51] = "K_RB1_GRKArr in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[52] = "K_L_RB1_GRKArr in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[53] = "K_GRKArr in component GPCR_B1AR_reduced_parameters (per_fmol)"
    legend_constants[54] = "R in component constants (J_per_K_per_mol)"
    legend_constants[55] = "T in component constants (kelvin)"
    legend_algebraic[23] = "mu_RB1_inactive in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[24] = "mu_L_RB1_inactive in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[25] = "mu_LB1 in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[26] = "mu_RB1 in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[27] = "mu_Gs in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[28] = "mu_RB1_Gs in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[29] = "mu_L_RB1 in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[30] = "mu_L_RB1_Gs in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[31] = "mu_Gsa_GTP in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[32] = "mu_Gsbetagamma in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[33] = "mu_Gsa_GDP in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[34] = "mu_GTP in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[35] = "mu_GDP in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[36] = "mu_Pi in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[37] = "mu_RB1_tag in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[38] = "mu_L_RB1_tag in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[39] = "mu_RB1_GRKArr in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[40] = "mu_L_RB1_GRKArr in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[41] = "mu_GRKArr in component GPCR_B1AR_reduced (J_per_mol)"
    legend_algebraic[42] = "v_Rswitch_B1 in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[43] = "v_LRswitch_B1 in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[44] = "v_C_B1 in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[45] = "v_R_B1 in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[46] = "v_L_B1 in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[48] = "v_L_actR in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[47] = "v_Act1_Gs in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[49] = "v_Act2_Gs in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[50] = "v_Hyd_Gs in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[53] = "v_Reassoc_Gs in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[51] = "v_InternR_B1 in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[54] = "v_InternLR_B1 in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_algebraic[52] = "v_Rsynthesis in component GPCR_B1AR_reduced (fmol_per_sec)"
    legend_constants[56] = "F in component constants (C_per_mol)"
    legend_rates[0] = "d/dt q_RB1_inactive in component GPCR_B1AR_reduced (fmol)"
    legend_rates[1] = "d/dt q_L_RB1_inactive in component GPCR_B1AR_reduced (fmol)"
    legend_rates[2] = "d/dt q_LB1 in component GPCR_B1AR_reduced (fmol)"
    legend_rates[3] = "d/dt q_RB1 in component GPCR_B1AR_reduced (fmol)"
    legend_rates[4] = "d/dt q_Gs in component GPCR_B1AR_reduced (fmol)"
    legend_rates[5] = "d/dt q_RB1_Gs in component GPCR_B1AR_reduced (fmol)"
    legend_rates[6] = "d/dt q_L_RB1 in component GPCR_B1AR_reduced (fmol)"
    legend_rates[7] = "d/dt q_L_RB1_Gs in component GPCR_B1AR_reduced (fmol)"
    legend_rates[8] = "d/dt q_Gsa_GTP in component GPCR_B1AR_reduced (fmol)"
    legend_rates[9] = "d/dt q_Gsbetagamma in component GPCR_B1AR_reduced (fmol)"
    legend_rates[10] = "d/dt q_Gsa_GDP in component GPCR_B1AR_reduced (fmol)"
    legend_rates[11] = "d/dt q_GTP in component GPCR_B1AR_reduced (fmol)"
    legend_rates[12] = "d/dt q_GDP in component GPCR_B1AR_reduced (fmol)"
    legend_rates[13] = "d/dt q_Pi in component GPCR_B1AR_reduced (fmol)"
    legend_rates[14] = "d/dt q_RB1_tag in component GPCR_B1AR_reduced (fmol)"
    legend_rates[15] = "d/dt q_L_RB1_tag in component GPCR_B1AR_reduced (fmol)"
    legend_rates[16] = "d/dt q_RB1_GRKArr in component GPCR_B1AR_reduced (fmol)"
    legend_rates[17] = "d/dt q_L_RB1_GRKArr in component GPCR_B1AR_reduced (fmol)"
    legend_rates[18] = "d/dt q_GRKArr in component GPCR_B1AR_reduced (fmol)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    constants[0] = 0.0004579000e0
    constants[1] = 1e-18
    constants[2] = 1e-18
    constants[3] = 0.1455400000
    constants[4] = 1e-18
    constants[5] = 1e-18
    constants[6] = 1e-18
    constants[7] = 0.01
    constants[8] = 0.02
    constants[9] = 0.01
    constants[10] = 2.2
    constants[11] = 1.1
    constants[12] = 570
    constants[13] = 1e-18
    constants[14] = 1e-18
    constants[15] = 1e-18
    constants[16] = 1e-18
    constants[17] = 1e-3
    constants[18] = 2.5
    constants[19] = 5e-1
    constants[20] = 5e0
    constants[21] = 1e1
    constants[22] = 1e-8
    states[0] = 1e-16
    states[1] = 1e-16
    states[2] = 1e-16
    states[3] = 1e-16
    states[4] = 1e-16
    states[5] = 1e-16
    states[6] = 1e-16
    states[7] = 1e-16
    states[8] = 1e-16
    states[9] = 1e-16
    states[10] = 1e-16
    states[11] = 1e-16
    states[12] = 1e-16
    states[13] = 1e-16
    states[14] = 1e-16
    states[15] = 1e-16
    states[16] = 1e-16
    states[17] = 1e-16
    states[18] = 1e-16
    constants[23] = 1036.38
    constants[24] = 1.83921e-07
    constants[25] = 891573
    constants[26] = 1.58222e+06
    constants[27] = 0
    constants[28] = 52417.5
    constants[29] = 0.000610519
    constants[30] = 0.576677
    constants[31] = 0.0661821
    constants[32] = 8.60273e-06
    constants[33] = 0.00230556
    constants[34] = 2.17775
    constants[35] = 28.0492
    constants[36] = 1.58056e+11
    constants[37] = 0.0574759
    constants[38] = 0.280492
    constants[39] = 0.00337913
    constants[40] = 1.07597
    constants[41] = 0.158056
    constants[42] = 0.00113911
    constants[43] = 0.00878478
    constants[44] = 736.699
    constants[45] = 161.34
    constants[46] = 823.314
    constants[47] = 3.61368e-10
    constants[48] = 7.91408e-11
    constants[49] = 0.500146
    constants[50] = 0.000529497
    constants[51] = 1.26086e-05
    constants[52] = 1.33485e-08
    constants[53] = 732843
    constants[54] = 8.31
    constants[55] = 310
    constants[56] = 96485
    constants[57] = constants[21]/constants[20]
    constants[58] = constants[0]+constants[1]+constants[2]+constants[4]+constants[5]+constants[6]
    return (states, constants)

def computeRates(voi, states, constants):
    rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
    algebraic[2] = states[1]+constants[1]
    algebraic[24] = constants[54]*constants[55]*log(constants[36]*algebraic[2])
    algebraic[7] = states[6]+constants[5]
    algebraic[29] = constants[54]*constants[55]*log(constants[41]*algebraic[7])
    algebraic[43] = constants[24]*(exp(algebraic[24]/(constants[54]*constants[55]))-exp(algebraic[29]/(constants[54]*constants[55])))
    algebraic[1] = states[0]+constants[0]
    algebraic[23] = constants[54]*constants[55]*log(constants[35]*algebraic[1])
    algebraic[0] = custom_piecewise([less(voi , constants[18]) & greater(voi , constants[18]-constants[20]), constants[22]+constants[57]*((voi-constants[18])+constants[20]) , greater_equal(voi , constants[18]) & less(voi , constants[18]+constants[19]), constants[21]+constants[22] , less_equal(voi , constants[18]+constants[20]+constants[19]) & greater_equal(voi , constants[18]+constants[19]), constants[22]+-constants[57]*(((voi-constants[18])-constants[20])-constants[19]) , True, constants[22]])
    algebraic[3] = states[2]+algebraic[0]
    algebraic[25] = constants[54]*constants[55]*log(constants[37]*algebraic[3])
    algebraic[46] = constants[27]*(exp((algebraic[23]+algebraic[25])/(constants[54]*constants[55]))-exp(algebraic[24]/(constants[54]*constants[55])))
    rates[1] = -algebraic[43]+algebraic[46]
    algebraic[4] = states[3]+constants[2]
    algebraic[26] = constants[54]*constants[55]*log(constants[38]*algebraic[4])
    algebraic[5] = states[4]+constants[3]
    algebraic[27] = constants[54]*constants[55]*log(constants[39]*algebraic[5])
    algebraic[6] = states[5]+constants[4]
    algebraic[28] = constants[54]*constants[55]*log(constants[40]*algebraic[6])
    algebraic[44] = constants[25]*(exp((algebraic[26]+algebraic[27])/(constants[54]*constants[55]))-exp(algebraic[28]/(constants[54]*constants[55])))
    algebraic[9] = states[8]+constants[7]
    algebraic[31] = constants[54]*constants[55]*log(constants[43]*algebraic[9])
    algebraic[10] = states[9]+constants[8]
    algebraic[32] = constants[54]*constants[55]*log(constants[44]*algebraic[10])
    algebraic[13] = states[11]+constants[10]
    algebraic[34] = constants[54]*constants[55]*log(constants[46]*algebraic[13])
    algebraic[14] = states[12]+constants[11]
    algebraic[35] = constants[54]*constants[55]*log(constants[47]*algebraic[14])
    algebraic[16] = states[14]+constants[13]
    algebraic[37] = constants[54]*constants[55]*log(constants[49]*algebraic[16])
    algebraic[47] = constants[29]*(exp((algebraic[28]+algebraic[34])/(constants[54]*constants[55]))-exp((algebraic[31]+algebraic[32]+algebraic[37]+algebraic[35])/(constants[54]*constants[55])))
    rates[5] = algebraic[44]-algebraic[47]
    algebraic[48] = constants[28]*(exp((algebraic[26]+algebraic[25])/(constants[54]*constants[55]))-exp(algebraic[29]/(constants[54]*constants[55])))
    rates[2] = -algebraic[46]-algebraic[48]
    algebraic[42] = constants[23]*(exp(algebraic[23]/(constants[54]*constants[55]))-exp(algebraic[26]/(constants[54]*constants[55])))
    rates[3] = (algebraic[42]-algebraic[44])-algebraic[48]
    algebraic[8] = states[7]+constants[6]
    algebraic[30] = constants[54]*constants[55]*log(constants[42]*algebraic[8])
    algebraic[45] = constants[26]*(exp((algebraic[29]+algebraic[27])/(constants[54]*constants[55]))-exp(algebraic[30]/(constants[54]*constants[55])))
    rates[6] = (algebraic[43]-algebraic[45])+algebraic[48]
    algebraic[17] = states[15]+constants[14]
    algebraic[38] = constants[54]*constants[55]*log(constants[50]*algebraic[17])
    algebraic[49] = constants[30]*(exp((algebraic[30]+algebraic[34])/(constants[54]*constants[55]))-exp((algebraic[31]+algebraic[32]+algebraic[38]+algebraic[35])/(constants[54]*constants[55])))
    rates[7] = algebraic[45]-algebraic[49]
    rates[11] = -algebraic[47]-algebraic[49]
    rates[12] = algebraic[47]+algebraic[49]
    algebraic[52] = algebraic[42]+algebraic[48]
    rates[0] = (-algebraic[42]-algebraic[46])+0.00000*algebraic[52]
    algebraic[11] = states[10]+constants[9]
    algebraic[33] = constants[54]*constants[55]*log(constants[45]*algebraic[11])
    algebraic[15] = states[13]+constants[12]
    algebraic[36] = constants[54]*constants[55]*log(constants[48]*algebraic[15])
    algebraic[50] = constants[31]*(exp(algebraic[31]/(constants[54]*constants[55]))-exp((algebraic[33]+algebraic[36])/(constants[54]*constants[55])))
    rates[8] = (algebraic[47]+algebraic[49])-algebraic[50]
    rates[13] = algebraic[50]
    algebraic[18] = states[16]+constants[15]
    algebraic[39] = constants[54]*constants[55]*log(constants[51]*algebraic[18])
    algebraic[22] = states[18]+constants[17]
    algebraic[41] = constants[54]*constants[55]*log(constants[53]*algebraic[22])
    algebraic[51] = constants[33]*(exp((algebraic[37]+algebraic[41])/(constants[54]*constants[55]))-exp(algebraic[39]/(constants[54]*constants[55])))
    rates[14] = algebraic[47]-algebraic[51]
    rates[16] = algebraic[51]
    algebraic[53] = constants[32]*(exp((algebraic[33]+algebraic[32])/(constants[54]*constants[55]))-exp(algebraic[27]/(constants[54]*constants[55])))
    rates[4] = (-algebraic[44]-algebraic[45])+algebraic[53]
    rates[9] = (algebraic[47]+algebraic[49])-algebraic[53]
    rates[10] = algebraic[50]-algebraic[53]
    algebraic[19] = states[17]+constants[16]
    algebraic[40] = constants[54]*constants[55]*log(constants[52]*algebraic[19])
    algebraic[54] = constants[34]*(exp((algebraic[38]+algebraic[41])/(constants[54]*constants[55]))-exp(algebraic[40]/(constants[54]*constants[55])))
    rates[15] = algebraic[49]-algebraic[54]
    rates[17] = algebraic[54]
    rates[18] = -algebraic[51]-algebraic[54]
    return(rates)

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[2] = states[1]+constants[1]
    algebraic[24] = constants[54]*constants[55]*log(constants[36]*algebraic[2])
    algebraic[7] = states[6]+constants[5]
    algebraic[29] = constants[54]*constants[55]*log(constants[41]*algebraic[7])
    algebraic[43] = constants[24]*(exp(algebraic[24]/(constants[54]*constants[55]))-exp(algebraic[29]/(constants[54]*constants[55])))
    algebraic[1] = states[0]+constants[0]
    algebraic[23] = constants[54]*constants[55]*log(constants[35]*algebraic[1])
    algebraic[0] = custom_piecewise([less(voi , constants[18]) & greater(voi , constants[18]-constants[20]), constants[22]+constants[57]*((voi-constants[18])+constants[20]) , greater_equal(voi , constants[18]) & less(voi , constants[18]+constants[19]), constants[21]+constants[22] , less_equal(voi , constants[18]+constants[20]+constants[19]) & greater_equal(voi , constants[18]+constants[19]), constants[22]+-constants[57]*(((voi-constants[18])-constants[20])-constants[19]) , True, constants[22]])
    algebraic[3] = states[2]+algebraic[0]
    algebraic[25] = constants[54]*constants[55]*log(constants[37]*algebraic[3])
    algebraic[46] = constants[27]*(exp((algebraic[23]+algebraic[25])/(constants[54]*constants[55]))-exp(algebraic[24]/(constants[54]*constants[55])))
    algebraic[4] = states[3]+constants[2]
    algebraic[26] = constants[54]*constants[55]*log(constants[38]*algebraic[4])
    algebraic[5] = states[4]+constants[3]
    algebraic[27] = constants[54]*constants[55]*log(constants[39]*algebraic[5])
    algebraic[6] = states[5]+constants[4]
    algebraic[28] = constants[54]*constants[55]*log(constants[40]*algebraic[6])
    algebraic[44] = constants[25]*(exp((algebraic[26]+algebraic[27])/(constants[54]*constants[55]))-exp(algebraic[28]/(constants[54]*constants[55])))
    algebraic[9] = states[8]+constants[7]
    algebraic[31] = constants[54]*constants[55]*log(constants[43]*algebraic[9])
    algebraic[10] = states[9]+constants[8]
    algebraic[32] = constants[54]*constants[55]*log(constants[44]*algebraic[10])
    algebraic[13] = states[11]+constants[10]
    algebraic[34] = constants[54]*constants[55]*log(constants[46]*algebraic[13])
    algebraic[14] = states[12]+constants[11]
    algebraic[35] = constants[54]*constants[55]*log(constants[47]*algebraic[14])
    algebraic[16] = states[14]+constants[13]
    algebraic[37] = constants[54]*constants[55]*log(constants[49]*algebraic[16])
    algebraic[47] = constants[29]*(exp((algebraic[28]+algebraic[34])/(constants[54]*constants[55]))-exp((algebraic[31]+algebraic[32]+algebraic[37]+algebraic[35])/(constants[54]*constants[55])))
    algebraic[48] = constants[28]*(exp((algebraic[26]+algebraic[25])/(constants[54]*constants[55]))-exp(algebraic[29]/(constants[54]*constants[55])))
    algebraic[42] = constants[23]*(exp(algebraic[23]/(constants[54]*constants[55]))-exp(algebraic[26]/(constants[54]*constants[55])))
    algebraic[8] = states[7]+constants[6]
    algebraic[30] = constants[54]*constants[55]*log(constants[42]*algebraic[8])
    algebraic[45] = constants[26]*(exp((algebraic[29]+algebraic[27])/(constants[54]*constants[55]))-exp(algebraic[30]/(constants[54]*constants[55])))
    algebraic[17] = states[15]+constants[14]
    algebraic[38] = constants[54]*constants[55]*log(constants[50]*algebraic[17])
    algebraic[49] = constants[30]*(exp((algebraic[30]+algebraic[34])/(constants[54]*constants[55]))-exp((algebraic[31]+algebraic[32]+algebraic[38]+algebraic[35])/(constants[54]*constants[55])))
    algebraic[52] = algebraic[42]+algebraic[48]
    algebraic[11] = states[10]+constants[9]
    algebraic[33] = constants[54]*constants[55]*log(constants[45]*algebraic[11])
    algebraic[15] = states[13]+constants[12]
    algebraic[36] = constants[54]*constants[55]*log(constants[48]*algebraic[15])
    algebraic[50] = constants[31]*(exp(algebraic[31]/(constants[54]*constants[55]))-exp((algebraic[33]+algebraic[36])/(constants[54]*constants[55])))
    algebraic[18] = states[16]+constants[15]
    algebraic[39] = constants[54]*constants[55]*log(constants[51]*algebraic[18])
    algebraic[22] = states[18]+constants[17]
    algebraic[41] = constants[54]*constants[55]*log(constants[53]*algebraic[22])
    algebraic[51] = constants[33]*(exp((algebraic[37]+algebraic[41])/(constants[54]*constants[55]))-exp(algebraic[39]/(constants[54]*constants[55])))
    algebraic[53] = constants[32]*(exp((algebraic[33]+algebraic[32])/(constants[54]*constants[55]))-exp(algebraic[27]/(constants[54]*constants[55])))
    algebraic[19] = states[17]+constants[16]
    algebraic[40] = constants[54]*constants[55]*log(constants[52]*algebraic[19])
    algebraic[54] = constants[34]*(exp((algebraic[38]+algebraic[41])/(constants[54]*constants[55]))-exp(algebraic[40]/(constants[54]*constants[55])))
    algebraic[12] = algebraic[5]+algebraic[6]+algebraic[8]+algebraic[9]+algebraic[11]
    algebraic[20] = algebraic[1]+algebraic[2]+algebraic[4]+algebraic[6]+algebraic[7]+algebraic[8]+algebraic[16]+algebraic[17]+algebraic[18]+algebraic[19]
    algebraic[21] = algebraic[2]+algebraic[3]+algebraic[7]+algebraic[8]+algebraic[17]+algebraic[19]
    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)
Source
Derived from workspace BG_GPCR_B1AR_reduced at changeset 5ff72e51dee7.
Collaboration
To begin collaborating on this work, please use your git client and issue this command:
License
The terms of use/license for this work is unspecified.