Location: BG_GPCR_M2_reduced @ 11c2bfce41f9 / BG_GPCR_B1AR_reduced.py

Author:
Shelley Fong <s.fong@auckland.ac.nz>
Date:
2021-12-03 10:26:09+13:00
Desc:
Init
Permanent Source URI:
https://models.cellml.org/workspace/7dd/rawfile/11c2bfce41f9ce7654eaf5658c8bc5cdc6f2fb31/BG_GPCR_B1AR_reduced.py

# Size of variable arrays:
sizeAlgebraic = 60
sizeStates = 21
sizeConstants = 66
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_algebraic[0] = "q_L_B1_init in component environment (fmol)"
    legend_constants[0] = "q_RB1_init in component environment (fmol)"
    legend_constants[1] = "q_Gs_init in component environment (fmol)"
    legend_constants[2] = "q_RB1_Gs_init in component environment (fmol)"
    legend_constants[3] = "q_L_RB1_init in component environment (fmol)"
    legend_constants[4] = "q_L_RB1_Gs_init in component environment (fmol)"
    legend_constants[5] = "q_Gsa_GTP_init in component environment (fmol)"
    legend_constants[6] = "q_Gsbetagamma_init in component environment (fmol)"
    legend_constants[7] = "q_Gsa_GDP_init in component environment (fmol)"
    legend_constants[8] = "q_Pi_init in component environment (fmol)"
    legend_constants[9] = "q_RB1_aby_init in component environment (fmol)"
    legend_constants[10] = "q_RB1_abyT_init in component environment (fmol)"
    legend_constants[11] = "q_L_RB1_aby_init in component environment (fmol)"
    legend_constants[12] = "q_L_RB1_abyT_init in component environment (fmol)"
    legend_constants[13] = "q_GTP_init in component environment (fmol)"
    legend_constants[14] = "q_GDP_init in component environment (fmol)"
    legend_constants[15] = "q_RB1_tag_init in component environment (fmol)"
    legend_constants[16] = "q_L_RB1_tag_init in component environment (fmol)"
    legend_constants[17] = "q_RB1_GRKArr_init in component environment (fmol)"
    legend_constants[18] = "q_L_RB1_GRKArr_init in component environment (fmol)"
    legend_constants[19] = "q_GRKArr_init in component environment (fmol)"
    legend_constants[20] = "stimSt in component environment (second)"
    legend_constants[21] = "stimDur in component environment (second)"
    legend_constants[22] = "tR in component environment (second)"
    legend_constants[23] = "stimMag in component environment (fmol)"
    legend_constants[24] = "stimHolding in component environment (fmol)"
    legend_constants[64] = "m in component environment (fmol_per_sec)"
    legend_algebraic[1] = "q_L_B1 in component environment (fmol)"
    legend_algebraic[2] = "q_RB1 in component environment (fmol)"
    legend_algebraic[3] = "q_Gs in component environment (fmol)"
    legend_algebraic[4] = "q_RB1_Gs in component environment (fmol)"
    legend_algebraic[5] = "q_L_RB1 in component environment (fmol)"
    legend_algebraic[6] = "q_L_RB1_Gs in component environment (fmol)"
    legend_algebraic[7] = "q_Gsa_GTP in component environment (fmol)"
    legend_algebraic[8] = "q_Gsbetagamma in component environment (fmol)"
    legend_algebraic[9] = "q_Gsa_GDP in component environment (fmol)"
    legend_algebraic[10] = "q_Pi in component environment (fmol)"
    legend_algebraic[11] = "q_RB1_aby in component environment (fmol)"
    legend_algebraic[12] = "q_RB1_abyT in component environment (fmol)"
    legend_algebraic[13] = "q_L_RB1_aby in component environment (fmol)"
    legend_algebraic[14] = "q_L_RB1_abyT in component environment (fmol)"
    legend_algebraic[16] = "q_GTP in component environment (fmol)"
    legend_algebraic[17] = "q_GDP in component environment (fmol)"
    legend_algebraic[18] = "q_RB1_tag in component environment (fmol)"
    legend_algebraic[19] = "q_L_RB1_tag in component environment (fmol)"
    legend_algebraic[20] = "q_RB1_GRKArr in component environment (fmol)"
    legend_algebraic[21] = "q_L_RB1_GRKArr in component environment (fmol)"
    legend_algebraic[24] = "q_GRKArr in component environment (fmol)"
    legend_states[0] = "q_L_B1 in component GPCR_B1AR (fmol)"
    legend_states[1] = "q_RB1 in component GPCR_B1AR (fmol)"
    legend_states[2] = "q_Gs in component GPCR_B1AR (fmol)"
    legend_states[3] = "q_RB1_Gs in component GPCR_B1AR (fmol)"
    legend_states[4] = "q_L_RB1 in component GPCR_B1AR (fmol)"
    legend_states[5] = "q_L_RB1_Gs in component GPCR_B1AR (fmol)"
    legend_states[6] = "q_Gsa_GTP in component GPCR_B1AR (fmol)"
    legend_states[7] = "q_Gsbetagamma in component GPCR_B1AR (fmol)"
    legend_states[8] = "q_Gsa_GDP in component GPCR_B1AR (fmol)"
    legend_states[9] = "q_Pi in component GPCR_B1AR (fmol)"
    legend_states[10] = "q_RB1_aby in component GPCR_B1AR (fmol)"
    legend_states[11] = "q_RB1_abyT in component GPCR_B1AR (fmol)"
    legend_states[12] = "q_L_RB1_aby in component GPCR_B1AR (fmol)"
    legend_states[13] = "q_L_RB1_abyT in component GPCR_B1AR (fmol)"
    legend_states[14] = "q_GTP in component GPCR_B1AR (fmol)"
    legend_states[15] = "q_GDP in component GPCR_B1AR (fmol)"
    legend_states[16] = "q_RB1_tag in component GPCR_B1AR (fmol)"
    legend_states[17] = "q_L_RB1_tag in component GPCR_B1AR (fmol)"
    legend_states[18] = "q_RB1_GRKArr in component GPCR_B1AR (fmol)"
    legend_states[19] = "q_L_RB1_GRKArr in component GPCR_B1AR (fmol)"
    legend_states[20] = "q_GRKArr in component GPCR_B1AR (fmol)"
    legend_algebraic[22] = "conserv_R_T in component environment (fmol)"
    legend_algebraic[23] = "conserv_L_T in component environment (fmol)"
    legend_algebraic[15] = "conserv_G_T in component environment (fmol)"
    legend_constants[65] = "total_R_init in component environment (fmol)"
    legend_constants[25] = "kappa_C_B1 in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[26] = "kappa_R_B1 in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[27] = "kappa_L_B1 in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[28] = "kappa_Doff1_Gs in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[29] = "kappa_Ton1_Gs in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[30] = "kappa_Act1_Gs in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[31] = "kappa_Doff2_Gs in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[32] = "kappa_Ton2_Gs in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[33] = "kappa_Act2_Gs in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[34] = "kappa_Hyd_Gs in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[35] = "kappa_Reassoc_Gs in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[36] = "kappa_PiPhos in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[37] = "kappa_InternRB1 in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[38] = "kappa_InternL_RB1 in component GPCR_B1AR_parameters (fmol_per_sec)"
    legend_constants[39] = "K_L_B1 in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[40] = "K_RB1 in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[41] = "K_Gs in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[42] = "K_RB1_Gs in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[43] = "K_L_RB1 in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[44] = "K_L_RB1_Gs in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[45] = "K_Gsa_GTP in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[46] = "K_Gsbetagamma in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[47] = "K_Gsa_GDP in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[48] = "K_Pi in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[49] = "K_RB1_aby in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[50] = "K_RB1_abyT in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[51] = "K_L_RB1_aby in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[52] = "K_L_RB1_abyT in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[53] = "K_GTP in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[54] = "K_GDP in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[55] = "K_RB1_tag in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[56] = "K_L_RB1_tag in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[57] = "K_RB1_GRKArr in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[58] = "K_L_RB1_GRKArr in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[59] = "K_GRKArr in component GPCR_B1AR_parameters (per_fmol)"
    legend_constants[60] = "R in component constants (J_per_K_per_mol)"
    legend_constants[61] = "T in component constants (kelvin)"
    legend_algebraic[25] = "mu_L_B1 in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[26] = "mu_RB1 in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[27] = "mu_Gs in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[28] = "mu_RB1_Gs in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[29] = "mu_L_RB1 in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[30] = "mu_L_RB1_Gs in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[31] = "mu_Gsa_GTP in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[32] = "mu_Gsbetagamma in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[33] = "mu_Gsa_GDP in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[34] = "mu_Pi in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[35] = "mu_RB1_aby in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[36] = "mu_RB1_abyT in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[37] = "mu_L_RB1_aby in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[38] = "mu_L_RB1_abyT in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[39] = "mu_GTP in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[40] = "mu_GDP in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[41] = "mu_RB1_tag in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[42] = "mu_L_RB1_tag in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[43] = "mu_RB1_GRKArr in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[44] = "mu_L_RB1_GRKArr in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[45] = "mu_GRKArr in component GPCR_B1AR (J_per_mol)"
    legend_algebraic[46] = "v_C_B1 in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[47] = "v_R_B1 in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[48] = "v_L_B1 in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[49] = "v_Doff1_Gs in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[50] = "v_Ton1_Gs in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[51] = "v_Act1_Gs in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[52] = "v_Doff2_Gs in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[53] = "v_Ton2_Gs in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[54] = "v_Act2_Gs in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[55] = "v_Hyd_Gs in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[57] = "v_Reassoc_Gs in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[58] = "v_PiPhos in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[56] = "v_InternRB1 in component GPCR_B1AR (fmol_per_sec)"
    legend_algebraic[59] = "v_InternL_RB1 in component GPCR_B1AR (fmol_per_sec)"
    legend_constants[62] = "v_Rsynthesis in component GPCR_B1AR (fmol_per_sec)"
    legend_constants[63] = "F in component constants (C_per_mol)"
    legend_rates[0] = "d/dt q_L_B1 in component GPCR_B1AR (fmol)"
    legend_rates[1] = "d/dt q_RB1 in component GPCR_B1AR (fmol)"
    legend_rates[2] = "d/dt q_Gs in component GPCR_B1AR (fmol)"
    legend_rates[3] = "d/dt q_RB1_Gs in component GPCR_B1AR (fmol)"
    legend_rates[4] = "d/dt q_L_RB1 in component GPCR_B1AR (fmol)"
    legend_rates[5] = "d/dt q_L_RB1_Gs in component GPCR_B1AR (fmol)"
    legend_rates[6] = "d/dt q_Gsa_GTP in component GPCR_B1AR (fmol)"
    legend_rates[7] = "d/dt q_Gsbetagamma in component GPCR_B1AR (fmol)"
    legend_rates[8] = "d/dt q_Gsa_GDP in component GPCR_B1AR (fmol)"
    legend_rates[9] = "d/dt q_Pi in component GPCR_B1AR (fmol)"
    legend_rates[10] = "d/dt q_RB1_aby in component GPCR_B1AR (fmol)"
    legend_rates[11] = "d/dt q_RB1_abyT in component GPCR_B1AR (fmol)"
    legend_rates[12] = "d/dt q_L_RB1_aby in component GPCR_B1AR (fmol)"
    legend_rates[13] = "d/dt q_L_RB1_abyT in component GPCR_B1AR (fmol)"
    legend_rates[14] = "d/dt q_GTP in component GPCR_B1AR (fmol)"
    legend_rates[15] = "d/dt q_GDP in component GPCR_B1AR (fmol)"
    legend_rates[16] = "d/dt q_RB1_tag in component GPCR_B1AR (fmol)"
    legend_rates[17] = "d/dt q_L_RB1_tag in component GPCR_B1AR (fmol)"
    legend_rates[18] = "d/dt q_RB1_GRKArr in component GPCR_B1AR (fmol)"
    legend_rates[19] = "d/dt q_L_RB1_GRKArr in component GPCR_B1AR (fmol)"
    legend_rates[20] = "d/dt q_GRKArr in component GPCR_B1AR (fmol)"
    return (legend_states, legend_algebraic, legend_voi, legend_constants)

def initConsts():
    constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
    constants[0] = 4.579e3
    constants[1] = 14.55400000
    constants[2] = 0e-18
    constants[3] = 0e-18
    constants[4] = 1e-18
    constants[5] = 0.02
    constants[6] = 0.02
    constants[7] = 0.02
    constants[8] = 570
    constants[9] = 1e-18
    constants[10] = 1e-18
    constants[11] = 1e-18
    constants[12] = 1e-18
    constants[13] = 2.2
    constants[14] = 1.1
    constants[15] = 1e-18
    constants[16] = 1e-18
    constants[17] = 1e-18
    constants[18] = 1e-18
    constants[19] = 1
    constants[20] = 3.1e-9
    constants[21] = 0.5e-8
    constants[22] = 0.3e-9
    constants[23] = 1e2
    constants[24] = 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
    states[19] = 1e-16
    states[20] = 1e-16
    constants[25] = 3.55104e-07
    constants[26] = 3.92263e-08
    constants[27] = 9.8476e-12
    constants[28] = 1.07607e-08
    constants[29] = 6.57198
    constants[30] = 1.05152e+08
    constants[31] = 6.32683e-07
    constants[32] = 386.403
    constants[33] = 6.18244e+09
    constants[34] = 2.56611e-07
    constants[35] = 1.75828e+19
    constants[36] = 6.8884e-08
    constants[37] = 0.00771991
    constants[38] = 0.453896
    constants[39] = 0.923369
    constants[40] = 9.29346e+13
    constants[41] = 2.56065e-05
    constants[42] = 2.70147e+12
    constants[43] = 8.4131e+14
    constants[44] = 4.59468e+10
    constants[45] = 90626.8
    constants[46] = 0.000840544
    constants[47] = 6.91864e-17
    constants[48] = 4.75979e+13
    constants[49] = 304.694
    constants[50] = 4.42329e-09
    constants[51] = 5.18226
    constants[52] = 7.52318e-11
    constants[53] = 0.422011
    constants[54] = 0.000257738
    constants[55] = 3.06684e-21
    constants[56] = 5.21612e-23
    constants[57] = 3.76556e-16
    constants[58] = 6.4045e-18
    constants[59] = 3.56927e+25
    constants[60] = 8.31
    constants[61] = 310
    constants[62] = 1e-2
    constants[63] = 96485
    constants[64] = constants[23]/constants[22]
    constants[65] = constants[0]+constants[2]+constants[3]+constants[4]+constants[9]+constants[10]+constants[11]+constants[12]+constants[15]+constants[16]+constants[17]+constants[18]
    return (states, constants)

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

def computeAlgebraic(constants, states, voi):
    algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
    states = array(states)
    voi = array(voi)
    algebraic[0] = custom_piecewise([less(voi , constants[20]) & greater(voi , constants[20]-constants[22]), constants[24]+constants[64]*((voi-constants[20])+constants[22]) , greater_equal(voi , constants[20]) & less(voi , constants[20]+constants[21]), constants[23]+constants[24] , less(voi , constants[20]+constants[22]+constants[21]) & greater_equal(voi , constants[20]+constants[21]), constants[24]+-constants[64]*(((voi-constants[20])-constants[22])-constants[21]) , True, constants[24]])
    algebraic[1] = states[0]+algebraic[0]
    algebraic[25] = constants[60]*constants[61]*log(constants[39]*algebraic[1])
    algebraic[2] = states[1]+constants[0]
    algebraic[26] = constants[60]*constants[61]*log(constants[40]*algebraic[2])
    algebraic[5] = states[4]+constants[3]
    algebraic[29] = constants[60]*constants[61]*log(constants[43]*algebraic[5])
    algebraic[48] = constants[27]*exp((algebraic[26]+algebraic[25])/(constants[60]*constants[61]))-exp(algebraic[29]/(constants[60]*constants[61]))
    algebraic[3] = states[2]+constants[1]
    algebraic[27] = constants[60]*constants[61]*log(constants[41]*algebraic[3])
    algebraic[4] = states[3]+constants[2]
    algebraic[28] = constants[60]*constants[61]*log(constants[42]*algebraic[4])
    algebraic[46] = constants[25]*exp((algebraic[26]+algebraic[27])/(constants[60]*constants[61]))-exp(algebraic[28]/(constants[60]*constants[61]))
    algebraic[11] = states[10]+constants[9]
    algebraic[35] = constants[60]*constants[61]*log(constants[49]*algebraic[11])
    algebraic[17] = states[15]+constants[14]
    algebraic[40] = constants[60]*constants[61]*log(constants[54]*algebraic[17])
    algebraic[49] = constants[28]*(exp(algebraic[28]/(constants[60]*constants[61]))-exp((algebraic[35]+algebraic[40])/(constants[60]*constants[61])))
    algebraic[6] = states[5]+constants[4]
    algebraic[30] = constants[60]*constants[61]*log(constants[44]*algebraic[6])
    algebraic[47] = constants[26]*exp((algebraic[29]+algebraic[27])/(constants[60]*constants[61]))-exp(algebraic[30]/(constants[60]*constants[61]))
    algebraic[12] = states[11]+constants[10]
    algebraic[36] = constants[60]*constants[61]*log(constants[50]*algebraic[12])
    algebraic[16] = states[14]+constants[13]
    algebraic[39] = constants[60]*constants[61]*log(constants[53]*algebraic[16])
    algebraic[50] = constants[29]*(exp((algebraic[35]+algebraic[39])/(constants[60]*constants[61]))-exp(algebraic[36]/(constants[60]*constants[61])))
    algebraic[7] = states[6]+constants[5]
    algebraic[31] = constants[60]*constants[61]*log(constants[45]*algebraic[7])
    algebraic[8] = states[7]+constants[6]
    algebraic[32] = constants[60]*constants[61]*log(constants[46]*algebraic[8])
    algebraic[18] = states[16]+constants[15]
    algebraic[41] = constants[60]*constants[61]*log(constants[55]*algebraic[18])
    algebraic[51] = constants[30]*(exp(algebraic[36]/(constants[60]*constants[61]))-exp((algebraic[31]+algebraic[32]+algebraic[41])/(constants[60]*constants[61])))
    algebraic[13] = states[12]+constants[11]
    algebraic[37] = constants[60]*constants[61]*log(constants[51]*algebraic[13])
    algebraic[52] = constants[31]*(exp(algebraic[30]/(constants[60]*constants[61]))-exp((algebraic[37]+algebraic[40])/(constants[60]*constants[61])))
    algebraic[14] = states[13]+constants[12]
    algebraic[38] = constants[60]*constants[61]*log(constants[52]*algebraic[14])
    algebraic[53] = constants[32]*(exp((algebraic[37]+algebraic[39])/(constants[60]*constants[61]))-exp(algebraic[38]/(constants[60]*constants[61])))
    algebraic[19] = states[17]+constants[16]
    algebraic[42] = constants[60]*constants[61]*log(constants[56]*algebraic[19])
    algebraic[54] = constants[33]*(exp(algebraic[38]/(constants[60]*constants[61]))-exp((algebraic[31]+algebraic[32]+algebraic[42])/(constants[60]*constants[61])))
    algebraic[9] = states[8]+constants[7]
    algebraic[33] = constants[60]*constants[61]*log(constants[47]*algebraic[9])
    algebraic[10] = states[9]+constants[8]
    algebraic[34] = constants[60]*constants[61]*log(constants[48]*algebraic[10])
    algebraic[55] = constants[34]*(exp(algebraic[31]/(constants[60]*constants[61]))-exp((algebraic[33]+algebraic[34])/(constants[60]*constants[61])))
    algebraic[20] = states[18]+constants[17]
    algebraic[43] = constants[60]*constants[61]*log(constants[57]*algebraic[20])
    algebraic[24] = states[20]+constants[19]
    algebraic[45] = constants[60]*constants[61]*log(constants[59]*algebraic[24])
    algebraic[56] = 1.00000*constants[37]*(exp((algebraic[41]+algebraic[45])/(constants[60]*constants[61]))-exp(algebraic[43]/(constants[60]*constants[61])))
    algebraic[57] = constants[35]*(exp((algebraic[33]+algebraic[32])/(constants[60]*constants[61]))-exp(algebraic[27]/(constants[60]*constants[61])))
    algebraic[58] = constants[36]*(exp((algebraic[40]+algebraic[34])/(constants[60]*constants[61]))-exp(algebraic[39]/(constants[60]*constants[61])))
    algebraic[21] = states[19]+constants[18]
    algebraic[44] = constants[60]*constants[61]*log(constants[58]*algebraic[21])
    algebraic[59] = 1.00000*constants[38]*(exp((algebraic[42]+algebraic[45])/(constants[60]*constants[61]))-exp(algebraic[44]/(constants[60]*constants[61])))
    algebraic[15] = algebraic[3]+algebraic[4]+algebraic[6]+algebraic[7]+algebraic[9]+algebraic[11]+algebraic[12]+algebraic[13]+algebraic[14]
    algebraic[22] = algebraic[2]+algebraic[4]+algebraic[5]+algebraic[6]+algebraic[11]+algebraic[12]+algebraic[13]+algebraic[14]+algebraic[18]+algebraic[19]+algebraic[20]+algebraic[21]
    algebraic[23] = algebraic[1]+algebraic[5]+algebraic[6]+algebraic[13]+algebraic[14]+algebraic[19]+algebraic[21]
    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, 1e-8, 500)

    # Construct ODE object to solve
    r = ode(computeRates)
    r.set_integrator('vode', method='bdf', atol=1e-06, rtol=1e-06, max_step=1e-12)
    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)