Applying MENTOS to the ABC model


In [51]:
%reload_ext autoreload
%aimport  mentos 
%autoreload 1
from IPython.display import Image, display
import sys
import pandas as pd
Image('Metabolic-network.JPG')


Out[51]:

The chemical equations for the ABC model are:

$$ \begin{eqnarray} A_{ext} & \overset{\overset{+1}{\rightharpoonup}}{\underset{-1}{\leftharpoondown}} & A \\ A & \overset{\overset{+2}{\rightharpoonup}}{\underset{-2}{\leftharpoondown}} & B \\ A & \overset{\overset{+3}{\rightharpoonup}}{\underset{-3}{\leftharpoondown}} & C \\ B + E & \overset{\overset{+4}{\rightharpoonup}}{\underset{-4}{\leftharpoondown}}& 2D\\ E_{ext} & \overset{\overset{+5}{\rightharpoonup}}{\underset{-5}{\leftharpoondown}} & E \\ 2B & \overset{\overset{+6}{\rightharpoonup}}{\underset{-6}{\leftharpoondown}} & C + F \\ C &\overset{\overset{+7}{\rightharpoonup}}{\underset{-7}{\leftharpoondown}} & D \\ D & \overset{\overset{+8}{\rightharpoonup}}{\underset{-8}{\leftharpoondown}}& D_{ext} \\ F &\overset{\overset{+9}{\rightharpoonup}}{\underset{-9}{\leftharpoondown}} & F_{ext} \\ \end{eqnarray} $$

which can be represented as a Stoichiometric matrix $S_{full}$:

$$ S_{full} = \left[ {\begin{array}{cccccccccc} & R_1 & R_2 & R_3 & R_4 & R_5 & R_6 & R_7 & R_8 & R_9 \\ A & 1 & -1 & -1 & 0 & 0 & 0 & 0 & 0 & 0 \\ B & 0 & 1 & 0 & -1 & 0 & -2 & 0 & 0 & 0 \\ C & 0 & 0 & 1 & 0 & 0 & 1 & -1 & 0 & 0 \\ D & 0 & 0 & 0 & 2 & 0 & 0 & 1 & -1 & 0 \\ E & 0 & 0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 \\ F & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & -1 \\ A_{ext} & -1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ E_{ext} & 0 & 0 & 0 & 0 & -1 & 0 & 0 & 0 & 0 \\ D_{ext} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ F_{ext} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{array}}\right] $$

In [52]:
import escher,os
import cobra
abc_model = cobra.Model('ABC_model')
M = {}
A_ext = cobra.Metabolite('A_ext', compartment='ext')
E_ext = cobra.Metabolite('E_ext', compartment= 'ext')
D_ext = cobra.Metabolite('D_ext', compartment='ext')
F_ext = cobra.Metabolite('F_ext', compartment='ext')
A = cobra.Metabolite('A',compartment='c')
B  = cobra.Metabolite('B',compartment='c')
C  = cobra.Metabolite('C',compartment='c')
D = cobra.Metabolite('D',compartment='c')
E  = cobra.Metabolite('E',compartment='c')
F  = cobra.Metabolite('F',compartment='c')
R_1 = cobra.Reaction('R_1')
R_2 = cobra.Reaction('R_2')
R_3 = cobra.Reaction('R_3')
R_4 = cobra.Reaction('R_4')
R_5 = cobra.Reaction('R_5')
R_6 = cobra.Reaction('R_6')
R_7 = cobra.Reaction('R_7')
R_8 = cobra.Reaction('R_8')
R_9 = cobra.Reaction('R_9')

R_1.add_metabolites({A_ext: -1, A: 1})
R_2.add_metabolites({A:-1, B:1})
R_3.add_metabolites({A:-1, C:1})
R_4.add_metabolites({B:-1, E:-1, D:2})
R_5.add_metabolites({E_ext:-1, E:1})
R_6.add_metabolites({B:-2, C:1,F:1})
R_7.add_metabolites({C:-1,D:1})
R_8.add_metabolites({D:-1, D_ext:1})
R_9.add_metabolites({F:-1, F_ext: 1})

abc_model.add_reactions([R_1, R_2, R_3, R_4, R_5, R_6, R_7, R_8, R_9])
cobra.io.save_json_model(abc_model, 'Mentos/ABC_model.json')
cobra.io.write_sbml_model(abc_model, 'Mentos/ABC_model.sbml')
abc_json = cobra.io.to_json(abc_model)

In [53]:
abc_array = abc_model.to_array_based_model()
abc_array.S


Out[53]:
<10x9 sparse matrix of type '<type 'numpy.float64'>'
	with 20 stored elements in LInked List format>

In [54]:
sys.path.append('')
mets = ['A','B','C','D','E','F','A_ext', 'D_ext', 'E_ext','F_ext']
internal_mets = [m for m in mets if 'ext' not in m]
rxns = ['R_{}'.format(i) for i in range(1,10)]

data = {'R_1': pd.Series({'A':1, 'A_ext': -1}),
       'R_2': pd.Series({'A':-1,'B':1}),
       'R_3': pd.Series({'A':-1,'C':1}),
       'R_4': pd.Series({'B':-1, 'D': 2, 'E': -1}),
       'R_5': pd.Series({'E':1, 'E_ext':-1}),
       'R_6': pd.Series({'B':-2, 'C':1, 'F': 1}),
       'R_7': pd.Series({'C':-1, 'D':1}),
       'R_8': pd.Series({'D': -1, 'D_ext': 1}),
       'R_9': pd.Series({'F':-1, 'F_ext':1})}
fullS = pd.DataFrame(data, columns=rxns, index=mets,dtype='int64').fillna(0)

biomass = fullS.columns.get_loc('R_8')
A_uptake = 0
E_uptake = 4
R = 8.3144598/1000.0 # ideal gas constant
T = 298.15           # standard temperature
n_A = 6.022e23       # Avogadro's number
V = 1e-15            # volume of cell in Liters
c_L = 1e-8           # lower bound of metabolite concentrations
c_U = 1e-3           # upper bound of metabolite concentrations
v_L = -100
v_U = 100
A_ext = 6            # Index of A_ext
E_ext = 8            # Index of E_ext
D_ext = 7            # Index of D_ext
F_ext = 9            # Index of F_ext
A,B,C,D,E,F = range(6)
lambda_x = 0.5
S = fullS.loc[internal_mets].as_matrix() 

m,n = fullS.shape

metab = {}
reactions = {}
true_metab, true_reactions = {},{}
display(fullS)


R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
A 1 -1 -1 0 0 0 0 0 0
B 0 1 0 -1 0 -2 0 0 0
C 0 0 1 0 0 1 -1 0 0
D 0 0 0 2 0 0 1 -1 0
E 0 0 0 -1 1 0 0 0 0
F 0 0 0 0 0 1 0 0 -1
A_ext -1 0 0 0 0 0 0 0 0
D_ext 0 0 0 0 0 0 0 1 0
E_ext 0 0 0 0 -1 0 0 0 0
F_ext 0 0 0 0 0 0 0 0 1

How do we predict metabolite concentrations? First we need to to obtain the chemical potential for each metabolite.

From chemical potential to standard free energy of the reaction

Chemical potential $\vec{\mu}^0$ is the Gibbs energy of formation $\Delta G^0_+$ for each metabolite: $$ \vec{\mu}^0 = \Delta \vec{G^0_+} = \left[ {\begin{array}{cc} A & 4 \\ B & 2 \\ C & 2 \\ D & 0 \\ E & 2 \\ F & 1 \\ \end{array}}\right] $$

Which implies a Change in Standard Gibbs free energy $S^T\vec{\mu}^0 = \Delta G^0$ for each reaction: $$ \Delta \vec{G}^0 = \left[ {\begin{array}{cc} R_1 & 0 \\ R_2 & -2 \\ R_3 & -2 \\ R_4 & -4 \\ R_5 & 0 \\ R_6 & -1 \\ R_7 & -2 \\ R_8 & 0 \\ R_9 & 0 \\ \end{array}}\right] $$


In [67]:
mu0 = pd.Series([4.0,2,2,0,2,1,4,0,2,1], index=mets,dtype='float64')
display(pd.DataFrame(mu0,columns=['$\mu^0$']))
deltaG0 = fullS.T.dot(mu0)
display(pd.DataFrame(deltaG0,columns=['$\Delta G^0$']))


$\mu^0$
A 4
B 2
C 2
D 0
E 2
F 1
A_ext 4
D_ext 0
E_ext 2
F_ext 1
$\Delta G^0$
R_1 0
R_2 -2
R_3 -2
R_4 -4
R_5 0
R_6 -1
R_7 -2
R_8 0
R_9 0

Function definitions for reporting on the ABC model


In [57]:
import pyOpt
from scipy.stats import entropy
import numpy as np
import cvxpy as cvx
import pandas as pd
import numpy as np
import sys, cobra
from IPython.display import display, HTML
#import pandas.core.format as fmt
pd.options.display.float_format = '{:.3g}'.format 
#pd.options.display.float_+ormat = '{:.0f}'.format

pd.options.display.float_format = '{:.3g}'.format

Convex problem formulation for MENTOS

Predicting steady state fluxes of the ABC model

Steady-state fluxes can be predicted from flux balance analysis:

$$\begin{array}{ll} \underset{\vec{\bf v}}{\mbox{maximize}} & v_{biomass} \\ \mbox{subject to} & S\cdot v = 0 \\ & 0 \leq v \leq v_{upper} \\ \end{array}$$

In [58]:
v = cvx.Variable(n)
obj = cvx.Maximize(v[biomass])
constraints = [S*v == 0,
              0 <= v,
              v <= v_U]
prob = cvx.Problem(obj, constraints)
prob.solve(verbose=True)
v.value


ECOS 2.0.4 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  -7.391e+01  -1.292e+03  +1e+03  6e-05  4e-09  1e+00  6e+01    ---    ---    1  1  - |  -  - 
 1  -8.670e+01  -2.376e+02  +2e+02  7e-06  4e-07  3e-01  8e+00  0.8790  3e-03   0  0  0 |  0  0
 2  -9.987e+01  -1.100e+02  +1e+01  5e-07  7e-07  2e-01  5e-01  0.9525  2e-02   0  0  0 |  0  0
 3  -1.000e+02  -1.001e+02  +1e-01  5e-09  1e-08  2e-03  6e-03  0.9890  1e-04   0  0  0 |  0  0
 4  -1.000e+02  -1.000e+02  +1e-03  6e-11  2e-10  2e-05  7e-05  0.9890  1e-04   1  0  0 |  0  0
 5  -1.000e+02  -1.000e+02  +1e-05  6e-13  1e-11  3e-07  7e-07  0.9890  1e-04   1  0  0 |  0  0
 6  -1.000e+02  -1.000e+02  +2e-07  7e-15  4e-13  3e-09  8e-09  0.9890  1e-04   1  0  0 |  0  0

OPTIMAL (within feastol=4.4e-13, reltol=1.5e-09, abstol=1.5e-07).
Runtime: 0.002303 seconds.

Out[58]:
matrix([[ 83.72371537],
        [ 63.84348529],
        [ 19.88023008],
        [ 32.13201818],
        [ 32.13201818],
        [ 15.85573356],
        [ 35.73596364],
        [100.        ],
        [ 15.85573356]])

Minimizing log likelihoods of the ABC model

At steady state, the log likelihood is equal to the difference of the logs of the equilibrium constant $K$ and the mass action ratio $Q$, subject to the boundary conditions

$$\begin{array}{ll} \underset{\log\vec{\bf L}_+, \log\vec{\bf c}}{\mbox{minimize}} & \|\log L_+\|_{2} \\ \mbox{subject to} & \log L_+ = \log K_{eq} - \log Q_r \\ & \log [A_{ext}] = \log c_{upper} \\ & \log [E_{ext}] = \log c_{upper} \\ & \log [D_{ext}] = \log c_{lower} \\ & \log [F_{ext}] = \log c_{lower} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_A \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_B \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_C \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_D \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_E \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_F \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ \end{array}$$

Where,

$$\begin{eqnarray} L_+ & = & \frac{r_+}{r_-} \\ \log K_{eq} & = & -\frac{1}{RT}S^T\cdot\mu^0 \\ \log Q_r & = & S^T\cdot\log c \\ \mu & = & RT\log c + \mu^0 \\ \end{eqnarray}$$

In [59]:
log_c = cvx.Variable(m)                                     # log of the concentrations
log_likelihood = cvx.Variable(n)

log_Q = fullS.as_matrix().T*log_c                              # log of the Reaction quotient
log_K = cvx.Constant(-1.0/(R*T)*deltaG0.as_matrix())           # log of the Equilibrium constnat
mu = R*T*log_c + mu0.values

#obj = cvx.Maximize(cvx.sum_entries(cvx.entr(log_likelihood)))  # entropy of the log likelihoods
obj  = cvx.Minimize(cvx.norm2(log_likelihood))
constraints = [
              log_c[A_ext] == cvx.log(c_U),             # Creating a concentration gradient between A, E and D,F
              log_c[E_ext] == cvx.log(c_U),
              log_c[D_ext] == cvx.log(c_L),
              log_c[F_ext] == cvx.log(c_L),
    
              log_likelihood == log_K - log_Q,          # Thermodynamic constraint
    
              mu[A] >= mu[D_ext] + mu[F_ext],           # Energy sink constraint
              mu[B] >= mu[D_ext] + mu[F_ext],
              mu[C] >= mu[D_ext] + mu[F_ext],
              mu[D] >= mu[D_ext] + mu[F_ext],
              mu[E] >= mu[D_ext] + mu[F_ext],
              mu[F] >= mu[D_ext] + mu[F_ext],
    
              mu[A] <= mu[A_ext] + mu[E_ext],           # Energy barrier constraint
              mu[B] <= mu[A_ext] + mu[E_ext],
              mu[C] <= mu[A_ext] + mu[E_ext],
              mu[D] <= mu[A_ext] + mu[E_ext],
              mu[E] <= mu[A_ext] + mu[E_ext],
              mu[F] <= mu[A_ext] + mu[E_ext],  
              ]
prob = cvx.Problem(obj, constraints)
prob.solve( verbose=True)
display(pd.DataFrame({'$\log c$':np.squeeze(np.asarray(log_c.value))},index=mets))
display(pd.DataFrame({'$\log L_+$':np.squeeze(np.asarray(log_likelihood.value))},index=rxns))


ECOS 2.0.4 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  +0.000e+00  -1.905e+01  +3e+02  8e-02  9e-01  1e+00  2e+01    ---    ---    1  1  - |  -  - 
 1  +2.217e+01  +2.141e+01  +5e+01  1e-02  1e-01  2e+00  4e+00  0.9316  1e-01   1  1  1 |  0  0
 2  +1.067e+01  +1.053e+01  +1e+01  3e-03  2e-02  5e-01  9e-01  0.7978  3e-02   1  1  1 |  0  0
 3  +1.243e+01  +1.235e+01  +1e+01  2e-03  2e-02  4e-01  7e-01  0.4921  6e-01   1  1  1 |  0  0
 4  +1.015e+01  +1.014e+01  +1e+00  3e-04  2e-03  6e-02  9e-02  0.9113  4e-02   1  1  1 |  0  0
 5  +1.017e+01  +1.017e+01  +2e-01  4e-05  3e-04  9e-03  1e-02  0.9283  8e-02   1  1  1 |  0  0
 6  +1.015e+01  +1.015e+01  +2e-03  4e-07  4e-06  1e-04  2e-04  0.9890  1e-04   1  1  1 |  0  0
 7  +1.015e+01  +1.015e+01  +2e-05  5e-09  4e-08  1e-06  2e-06  0.9890  1e-04   1  1  1 |  0  0
 8  +1.015e+01  +1.015e+01  +2e-07  5e-11  5e-10  1e-08  2e-08  0.9888  1e-04   2  1  1 |  0  0
 9  +1.015e+01  +1.015e+01  +5e-09  1e-12  9e-12  2e-10  4e-10  0.9816  1e-04   1  1  1 |  0  0

OPTIMAL (within feastol=8.6e-12, reltol=4.5e-10, abstol=4.6e-09).
Runtime: 0.001156 seconds.

$\log c$
A -13
B -15.2
C -13
D -13.7
E -12.2
F -17.7
A_ext -6.91
D_ext -18.4
E_ext -6.91
F_ext -18.4
$\log L_+$
R_1 6.1
R_2 3.01
R_3 0.803
R_4 1.61
R_5 5.29
R_6 0.702
R_7 1.51
R_8 4.72
R_9 0.702

In [60]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')
reaction_data = dict([(rxns[i], R*T*log_likelihood[i].value) for i in range(len(rxns))])
metabolite_data = (mu0 + R*T*np.squeeze(np.asarray(log_c.value))).to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data, metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[60]:

maximizing entropy of the log likelihoods of the ABC model

At steady state, the log likelihood is equal to the difference of the logs of the equilibrium constant $K$ and the mass action ratio $Q$, subject to the boundary conditions

$$\begin{array}{ll} \underset{\log\vec{\bf L}_+, \log\vec{\bf c}}{\mbox{minimize}} & \sum_j \text{entropy}(\log L_+) \\ \mbox{subject to} & \log L_+ = \log K_{eq} - \log Q_r \\ & \log [A_{ext}] = \log c_{upper} \\ & \log [E_{ext}] = \log c_{upper} \\ & \log [D_{ext}] = \log c_{lower} \\ & \log [F_{ext}] = \log c_{lower} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_A \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_B \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_C \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_D \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_E \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_F \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ \end{array}$$

Where,

$$\begin{eqnarray} L_+ & = & \frac{r_+}{r_-} \\ \log K_{eq} & = & -\frac{1}{RT}S^T\cdot\mu^0 \\ \log Q_r & = & S^T\cdot\log c \\ \mu & = & RT\log c + \mu^0 \\ \end{eqnarray}$$

In [61]:
log_c = cvx.Variable(m)                                     # log of the concentrations
log_likelihood = cvx.Variable(n)

log_Q = fullS.as_matrix().T*log_c                              # log of the Reaction quotient
log_K = cvx.Constant(-1.0/(R*T)*deltaG0.as_matrix())           # log of the Equilibrium constnat
mu = R*T*log_c + mu0.values

obj = cvx.Maximize(cvx.sum_entries(cvx.entr(log_likelihood)))  # entropy of the log likelihoods
#obj  = cvx.Minimize(cvx.norm1(log_likelihood))
constraints = [
              log_c[A_ext] == cvx.log(c_U),             # Creating a concentration gradient between A, E and D,F
              log_c[E_ext] == cvx.log(c_U),
              log_c[D_ext] == cvx.log(c_L),
              log_c[F_ext] == cvx.log(c_L),
    
              log_likelihood == log_K - log_Q,          # Thermodynamic constraint
    
              mu[A] >= mu[D_ext] + mu[F_ext],           # Energy sink constraint
              mu[B] >= mu[D_ext] + mu[F_ext],
              mu[C] >= mu[D_ext] + mu[F_ext],
              mu[D] >= mu[D_ext] + mu[F_ext],
              mu[E] >= mu[D_ext] + mu[F_ext],
              mu[F] >= mu[D_ext] + mu[F_ext],
    
              mu[A] <= mu[A_ext] + mu[E_ext],           # Energy barrier constraint
              mu[B] <= mu[A_ext] + mu[E_ext],
              mu[C] <= mu[A_ext] + mu[E_ext],
              mu[D] <= mu[A_ext] + mu[E_ext],
              mu[E] <= mu[A_ext] + mu[E_ext],
              mu[F] <= mu[A_ext] + mu[E_ext],  
              ]
prob = cvx.Problem(obj, constraints)
prob.solve( verbose=True)
display(pd.DataFrame({'$\log c$':np.squeeze(np.asarray(log_c.value))},index=mets))
display(pd.DataFrame({'$\log L_+$':np.squeeze(np.asarray(log_likelihood.value))},index=rxns))


ECOS 2.0.4 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  +0.000e+00  -2.491e+01  +4e+01  1e+00  1e+00  1e+00  1e+00    ---    ---    0  0  - |  -  - 
 1  +3.747e+01  +1.658e+01  +1e+01  8e-01  1e+00  2e+00  3e-01  0.6740  2e-02   1  1  1 |  0  1
 2  +7.417e+01  +6.189e+01  +5e+00  5e-01  8e-01  4e+00  1e-01  0.7635  1e-01   1  1  1 |  1  0
 3  +6.004e+01  +5.326e+01  +2e+00  3e-01  5e-01  2e+00  6e-02  0.6266  1e-01   1  1  1 |  1  2
 4  +3.342e+01  +3.141e+01  +6e-01  8e-02  2e-01  5e-01  2e-02  0.8209  1e-01   1  1  1 |  1  0
 5  +3.293e+01  +3.231e+01  +2e-01  3e-02  5e-02  2e-01  4e-03  0.7833  1e-01   1  1  1 |  1  1
 6  +3.177e+01  +3.151e+01  +7e-02  1e-02  2e-02  1e-01  2e-03  0.9791  4e-01   1  1  1 |  6  0
 7  +3.102e+01  +3.096e+01  +2e-02  3e-03  6e-03  3e-02  5e-04  0.7833  5e-02   1  1  1 |  2  1
 8  +3.082e+01  +3.080e+01  +5e-03  8e-04  2e-03  9e-03  1e-04  0.7833  6e-02   2  1  1 |  2  1
 9  +3.079e+01  +3.078e+01  +2e-03  3e-04  6e-04  4e-03  4e-05  0.7833  2e-01   1  1  1 |  4  1
10  +3.077e+01  +3.076e+01  +4e-04  7e-05  1e-04  8e-04  1e-05  0.7833  1e-02   1  1  1 |  1  1
11  +3.076e+01  +3.076e+01  +1e-04  3e-05  6e-05  3e-04  4e-06  0.6266  5e-02   2  1  1 |  2  2
12  +3.076e+01  +3.076e+01  +3e-05  7e-06  1e-05  7e-05  9e-07  0.7833  1e-02   2  1  1 |  1  1
13  +3.076e+01  +3.076e+01  +1e-05  3e-06  6e-06  3e-05  3e-07  0.6266  5e-02   1  0  0 |  2  2
14  +3.076e+01  +3.076e+01  +3e-06  6e-07  1e-06  7e-06  8e-08  0.7833  1e-02   1  0  0 |  1  1
15  +3.076e+01  +3.076e+01  +1e-06  3e-07  5e-07  3e-06  3e-08  0.6266  5e-02   2  0  0 |  2  2
16  +3.076e+01  +3.076e+01  +3e-07  6e-08  1e-07  6e-07  7e-09  0.7833  9e-03   1  0  0 |  1  1
17  +3.076e+01  +3.076e+01  +1e-07  2e-08  5e-08  2e-07  3e-09  0.6266  5e-02   1  0  0 |  2  2
18  +3.076e+01  +3.076e+01  +3e-08  5e-09  1e-08  5e-08  6e-10  0.7833  9e-03   0  0  0 |  1  1
19  +3.076e+01  +3.076e+01  +1e-08  2e-09  4e-09  2e-08  2e-10  0.6266  5e-02   0  0  0 |  2  2

OPTIMAL (within feastol=4.1e-09, reltol=3.1e-10, abstol=9.7e-09).
Runtime: 0.001454 seconds.

$\log c$
A -13
B -15.1
C -12.8
D -13.2
E -12.2
F -17.7
A_ext -6.91
D_ext -18.4
E_ext -6.91
F_ext -18.4
$\log L_+$
R_1 6.1
R_2 2.9
R_3 0.621
R_4 0.762
R_5 5.29
R_6 0.718
R_7 1.21
R_8 5.19
R_9 0.718

In [62]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')
reaction_data = dict([(rxns[i], R*T*log_likelihood[i].value) for i in range(len(rxns))])
metabolite_data = (mu0 + R*T*np.squeeze(np.asarray(log_c.value))).to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data, metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[62]:

Compute the reaction bounds from the likelihoods


In [63]:
v_L, v_U = mentos.get_rxn_bounds_from_log_likelihood( np.squeeze(np.asarray(log_likelihood.value)))
v_L, v_U


Out[63]:
(array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]),
 array([ 445.28785722,   17.23116929,    0.86009883,    1.14167213,
         198.17282328,    1.05085328,    2.35929172,  179.04086706,
           1.05085395]))

In [64]:
v = cvx.Variable(n)
obj = cvx.Maximize(v[biomass])
constraints = [S*v == 0,
              v_L <= v,
              v <= v_U]
prob = cvx.Problem(obj, constraints)
prob.solve(verbose=True)
v.value


ECOS 2.0.4 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  -1.229e+02  -1.198e+03  +2e+03  2e-01  4e-09  1e+00  1e+02    ---    ---    1  1  - |  -  - 
 1  +3.914e+01  -8.020e+02  +1e+03  2e-01  2e-06  5e+01  6e+01  0.7453  4e-01   0  0  0 |  0  0
 2  +2.297e-01  -4.242e+01  +7e+01  9e-03  2e-07  2e+00  4e+00  0.9414  6e-03   0  0  0 |  0  0
 3  -2.076e+00  -1.080e+01  +3e+01  1e-03  9e-08  8e-01  2e+00  0.6663  1e-01   0  0  0 |  0  0
 4  -3.816e+00  -6.570e+00  +1e+01  4e-04  5e-08  3e-01  6e-01  0.6977  6e-02   0  0  0 |  0  0
 5  -4.175e+00  -4.715e+00  +2e+00  8e-05  2e-08  5e-02  1e-01  0.8793  9e-02   0  0  0 |  0  0
 6  -4.194e+00  -4.204e+00  +4e-02  2e-06  1e-09  1e-03  2e-03  0.9820  1e-03   0  0  0 |  0  0
 7  -4.194e+00  -4.194e+00  +4e-04  2e-08  3e-11  1e-05  2e-05  0.9890  1e-04   0  0  0 |  0  0
 8  -4.194e+00  -4.194e+00  +4e-05  2e-09  8e-11  1e-06  2e-06  0.9107  2e-03   1  0  0 |  0  0
 9  -4.194e+00  -4.194e+00  +2e-06  2e-09  1e-10  3e-08  9e-08  0.9890  3e-02   1  0  0 |  0  0
10  -4.194e+00  -4.194e+00  +2e-08  2e-10  2e-11  4e-10  1e-09  0.9886  1e-04   1  0  0 |  0  0

OPTIMAL (within feastol=1.7e-10, reltol=4.4e-09, abstol=1.8e-08).
Runtime: 0.001993 seconds.

Out[64]:
matrix([[ 4.10347751],
        [ 3.24337869],
        [ 0.86009883],
        [ 1.14167213],
        [ 1.14167213],
        [ 1.05085328],
        [ 1.9109521 ],
        [ 4.19429636],
        [ 1.05085328]])

In [ ]:

Computing the forward and reverse rates from the likelihood and the flux

From the definition of forward likelihood and net flux:

$$\begin{eqnarray} L_+ &=& \frac{r_{+}}{r_{-}} \\ v &=& r_{+} - r_{-} \\ \end{eqnarray}$$

We can solve for the forward reaction rates $r_{+}$ and $r_{-}$: $$\begin{eqnarray} r_{-} & = & \frac{r_{+}}{L_+} \\ r_{+} - r_{-} & = & v\\ r_{+} - \frac{r_{+}}{L_+} & = & v \\ r_{+}(1 -\frac{1}{L_+}) & = & v \\ r_{+} & = & \frac{v}{1-\frac{1}{L_+}} \\ & = & \frac{L_+v}{L_+ - 1} \\ r_{-} & = & \frac{v}{L_+ - 1} \\ \end{eqnarray}$$


In [65]:
net_flux = np.squeeze(np.asarray(v.value))
forward_likelihood = np.exp(np.squeeze(np.asarray(log_likelihood.value)))
net_flux, forward_likelihood
forward_rate = net_flux*forward_likelihood/(forward_likelihood - 1)
backward_rate = net_flux/(forward_likelihood - 1)
forward_rate - backward_rate


Out[65]:
array([ 4.10347751,  3.24337869,  0.86009883,  1.14167213,  1.14167213,
        1.05085328,  1.9109521 ,  4.19429636,  1.05085328])

Let $r_+ = v(N+1)$ and $r_- = vN$. By definition, the thermodynamic likelihood is equal to ratio of the forward and backward rates, so

$$\begin{eqnarray} \frac{r_+}{r_-} & = & \frac{v(N+1)}{vN} \\ & = & \frac{N+1}{N} \\ & = & 1 + \frac{1}{N} \end{eqnarray}$$

The thermodynamic constraint at steady state is

$$\begin{eqnarray} -\frac{1}{RT}S^T\mu^0 -S^T\log a & = & \log \frac{r_+}{r_-} \\ & = & \log \frac{N+1}{N} \\ \end{eqnarray}$$

In [86]:
reload( mentos)
metab['convex_mentos'] = mentos.generate_metabolite_report( np.squeeze(np.asarray(log_c.value))
                                                             , forward_rate, backward_rate, S, mets, internal_mets, 
                                                             mu0).astype(np.float64)
metab['convex_mentos']['Chemical potential'].to_csv('Mentos/ABC_chemical_potentials.csv',header=True)

true_metab['convex_mentos']= pd.read_csv('ABC_metab_convex_mentos.csv',index_col=0).astype(np.float64)
pd.testing.assert_frame_equal(true_metab['convex_mentos'], metab['convex_mentos'])

mentos.compare_frames(true_metab['convex_mentos'].astype(np.float64),metab['convex_mentos'])


Out[86]:
A B C D E F A_ext D_ext E_ext F_ext
Counts 1.35e+03 165 1.62e+03 1.08e+03 3.02e+03 12 6.02e+05 6 6.02e+05 6
Concentrations 2.24e-06 2.75e-07 2.7e-06 1.8e-06 5.02e-06 2.05e-08 0.001 1e-08 0.001 1e-08
Log Concentrations -13 -15.1 -12.8 -13.2 -12.2 -17.7 -6.91 -18.4 -6.91 -18.4
Standard Chemical potential 4 2 2 0 2 1 4 0 2 1
Chemical potential -28.2 -35.4 -29.8 -32.8 -28.2 -42.9 -13.1 -45.7 -15.1 -44.7
S*forward_rate -1.18 -2.81 1.19 2.79 -0.994 6.4e-07 nan nan nan nan
S*backward_rate -1.18 -2.81 1.19 2.79 -0.994 6.43e-07 nan nan nan nan
S*net_flux -8.88e-16 -3.55e-15 2.06e-11 4.11e-11 -3.55e-15 -2.4e-09 nan nan nan nan

In [76]:
reactions['convex_mentos'] = mentos.generate_rxn_report(mets, log_c, log_Q.value, log_K.value,
                                                         forward_rate, backward_rate, rxns, deltaG0,'R_8')
reactions['convex_mentos']['Delta G'].to_csv(
    'Mentos/ABC_DeltaG.csv',header=True)
reactions['convex_mentos']['Net flux'].to_csv(
    'Mentos/ABC_net_flux.csv',header=True)
reactions['convex_mentos']['Macroscopic Reaction Entropy Production Net Flux'].to_csv(
    'Mentos/ABC_maxent_prod_net_flux.csv',header=True)

true_reactions['convex_mentos']= pd.read_csv('ABC_reactions_convex_mentos.csv',index_col=0)
pd.testing.assert_frame_equal(true_reactions['convex_mentos'], reactions['convex_mentos'])
mentos.compare_frames(true_reactions['convex_mentos'], reactions['convex_mentos'])


Out[76]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
Forward likelihoods 446 18.2 1.86 2.14 199 2.05 3.36 180 2.05
Backward likelihoods 0.00224 0.0549 0.538 0.467 0.00502 0.488 0.298 0.00555 0.488
Delta G -15.1 -7.2 -1.54 -1.89 -13.1 -1.78 -3 -12.9 -1.78
log Q_r -6.1 -2.1 0.186 0.852 -5.29 -0.315 -0.405 -5.19 -0.718
log K_eq -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
Delta G0 0 -2 -2 -4 0 -1 -2 0 0
logK - logQ 6.1 2.9 0.621 0.762 5.29 0.718 1.21 5.19 0.718
logQ - logK -6.1 -2.9 -0.621 -0.762 -5.29 -0.718 -1.21 -5.19 -0.718
Forward Log likelihoods 6.1 2.9 0.621 0.762 5.29 0.718 1.21 5.19 0.718
Backward Log likelihoods -6.1 -2.9 -0.621 -0.762 -5.29 -0.718 -1.21 -5.19 -0.718
Forward probabilities 0.52 0.0213 0.00217 0.0025 0.232 0.00239 0.00392 0.21 0.00239
Backward probabilities 2.61e-06 6.4e-05 0.000627 0.000544 5.85e-06 0.000569 0.000347 6.48e-06 0.000569
Net probabilities 0.52 0.0212 0.00154 0.00195 0.232 0.00182 0.00357 0.21 0.00182
Net likelihoods 446 18.2 1.32 1.67 199 1.56 3.06 180 1.56
Forward rate 4.11 3.43 1.86 2.14 1.15 2.05 2.72 4.22 2.05
Backward rate 0.00922 0.188 1 1 0.00576 1 0.81 0.0234 1
Thermodynamic driving force 446 18.2 1.86 2.14 199 2.05 3.36 180 2.05
Net flux 4.1 3.24 0.86 1.14 1.14 1.05 1.91 4.19 1.05
Forward Entropy Production 0.34 0.0819 0.0133 0.015 0.339 0.0144 0.0217 0.328 0.0144
Backward Entropy Production 3.36e-05 0.000618 0.00462 0.00409 7.05e-05 0.00425 0.00277 7.74e-05 0.00425
Reaction Entropy Production 0.34 0.0825 0.0179 0.0191 0.339 0.0187 0.0245 0.328 0.0187
Microscopic Reaction Entropy Production Rate 1.4 0.281 0.0294 0.0361 0.389 0.0339 0.0613 1.38 0.0339
Microscopic Reaction Entropy Production Net Flux 1.39 0.268 0.0154 0.0218 0.387 0.0196 0.0468 1.37 0.0196
Microscopic Reaction Entropy Production Net Flux Difference 1.39 0.264 0.00747 0.0124 0.387 0.0107 0.0362 1.37 0.0107
Total Entropy Production 1.19 1.19 1.19 1.19 1.19 1.19 1.19 1.19 1.19
Total Microscopic Entropy Production Rate 3.55 3.55 3.55 3.55 3.55 3.55 3.55 3.55 3.55
Macroscopic Reaction Entropy Production Net Flux 1.43 0.346 0.0752 0.0799 1.42 0.0784 0.103 1.37 0.0784
Macroscopic Reaction Entropy Production Net Flux Difference 1.43 0.341 0.0364 0.0456 1.42 0.0427 0.0795 1.37 0.0427
Total Macroscopic Entropy Production Net Flux 4.98 4.98 4.98 4.98 4.98 4.98 4.98 4.98 4.98
Total Macroscopic Entropy Production Net Flux Difference 4.81 4.81 4.81 4.81 4.81 4.81 4.81 4.81 4.81

In [87]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')

reaction_data = reactions['convex_mentos']['Net flux'].to_dict()
metabolite_data = metab['convex_mentos']['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[87]:

Nonconvex formulations of MENTOS

Maximize entropy production for the ABC model

$$ \begin{array}{ll} \underset{\vec{\bf c}, \vec{r}_+,\vec{r}_-}{\mbox{maximize}} & -\sum_i {\mathscr P}_{+i}\log{\mathscr P}_{+i}-\sum_i {\mathscr P}_{-i}\log{\mathscr P}_{-i} \\ \mbox{subject to} & S\cdot(\vec{\bf r}_+-\vec{\bf r}_-) = 0 \\ &\log\vec{\bf r}_+ -\log\vec{\bf r}_-= -\frac{1}{RT}S^T\cdot\vec{\mu}^0 - S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_- = \frac{1}{RT}S^T\cdot\vec{\mu}^0 + S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_+ -\log\vec{\bf L}_- \\ & \vec{v}_{lower}(L_+) \leq \vec{\bf r}_+ -\vec{\bf r}_- \leq \vec{v}_{upper}(L_+) \\ & \vec{\bf r}_+ \geq 0 \\ & \vec{\bf r}_- \geq 0 \\ & \log \left[{\bf A}_{ext}\right] = \log \left[{\bf E}_{ext}\right] = \log c_{upper} \\ & \log \left[{\bf E}_{ext}\right] = \log \left[{\bf D}_{ext}\right] = \log c_{lower} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_A \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_B \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_C \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_D \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_E \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_F \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ \end{array} \\$$

Where

  • $\vec{\bf r}_+,\vec{\bf r}_-$ are decision variables representing the forward and backward rates, respectively.
  • ${\mathscr P}_{+i},{\mathscr P}_{-i}$ are the normalized forward and backward thermodynamic driving forces $\frac{r_{+i}}{r_{-i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ and $\frac{r_{-i}}{r_{+i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$
  • $\vec{\bf c}$ is a decision variable representing the chemical concentrations of each metabolite
  • $S$ is the $m\times n$ stoichiometric matrix of representing $m$ metabolites and $n$ reactions of the model
  • $\vec{\mu}^0$ is the vector of standard chemical potentials
  • $L_+ = \frac{r_+}{r_-}$
  • $L_- = \frac{r_-}{r_+}$
  • $v_{lower}(L) =\min\left(-1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) + 1$
  • $v_{upper}(L) = \max\left(1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) - 1$

Decision variables are emphasized in bold.


In [ ]:
np.minimum(0, driving_force)

In [89]:
import mentos
from IPython.display import HTML
obj = 'maxent_production'
def make_maxent_production_objective( fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U):
    """Maximum entropy of ABC model"""
    def maxent_production(x):
        log_c, \
        forward_rate, backward_rate, \
        log_Q, log_K, \
        forward_likelihood, backward_likelihood, \
        forward_probability, backward_probability, mu, \
        thermodynamic_driving_force, \
        net_flux = mentos.make_variables( x, fullS, mu0, deltaG0, R, T )
        f = entropy(np.append(forward_probability, backward_probability )  ) 
        g = np.concatenate((np.dot(S,net_flux),
                            np.log(forward_rate) - np.log(backward_rate) + log_Q - log_K,
                            [ log_c[A_ext] - np.log(c_U),                 # Creating a concentration gradient between A, E and D,F
                              log_c[E_ext] - np.log(c_U),
                              log_c[D_ext] - np.log(c_L),
                              log_c[F_ext] - np.log(c_L)],
                             [-mu[A] + mu[D_ext] + mu[F_ext],           # Energy sink constraint
                              -mu[B] + mu[D_ext] + mu[F_ext],
                              -mu[C] + mu[D_ext] + mu[F_ext],
                              -mu[D] + mu[D_ext] + mu[F_ext],
                              -mu[E] + mu[D_ext] + mu[F_ext],
                              -mu[F] + mu[D_ext] + mu[F_ext]],
    
                             [ mu[A] - mu[A_ext] - mu[E_ext],           # Energy barrier constraint
                               mu[B] - mu[A_ext] - mu[E_ext],
                               mu[C] - mu[A_ext] - mu[E_ext],
                               mu[D] - mu[A_ext] - mu[E_ext],
                               mu[E] - mu[A_ext] - mu[E_ext],
                               mu[F] - mu[A_ext] - mu[E_ext]],  
                            
                               np.minimum(-1, thermodynamic_driving_force)+ 1 -net_flux,
                               net_flux - np.maximum(1, thermodynamic_driving_force ) - 1))
        
        fail = 0
        return -f, g, fail
    return maxent_production
metab[obj], reactions[obj] = mentos.run_mentos(fullS, S, internal_mets, deltaG0, mu0, 
                                        c_L, c_U, v_L, v_U,
                                        initial_log_c=metab['convex_mentos']['Log Concentrations'].values, 
                                        initial_forward_rate=reactions['convex_mentos']['Forward rate'].values,
                                        initial_backward_rate=reactions['convex_mentos']['Backward rate'].values,
                                        obj=make_maxent_production_objective( fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U),
                                        biomass_rxn='R_8')

true_metab[obj] = pd.read_csv('ABC_metab_{obj}.csv'.format(obj=obj), index_col=0).T

#reactions[obj].to_csv('ABC_reactions_{obj}.csv'.format(obj=obj))
true_reactions[obj] = pd.read_csv('ABC_reactions_{obj}.csv'.format(obj=obj),index_col=0)


display(mentos.compare_frames(true_metab[obj], metab[obj]))
pd.testing.assert_frame_equal(true_metab[obj],metab[obj].astype(np.float64))
pd.testing.assert_frame_equal(true_reactions[obj],reactions[obj])


HTML(mentos.compare_frames(true_reactions[obj],reactions[obj]).to_html())


A B C D E F A_ext D_ext E_ext F_ext
Counts 1.35e+03 184 1.68e+03 1.46e+03 2.3e+03 13 6.02e+05 6 6.02e+05 6
Concentrations 2.24e-06 3.07e-07 2.79e-06 2.43e-06 3.82e-06 2.23e-08 0.001 1e-08 0.001 1e-08
Log Concentrations -13 -15 -12.8 -12.9 -12.5 -17.6 -6.91 -18.4 -6.91 -18.4
Standard Chemical potential 4 2 2 0 2 1 4 0 2 1
Chemical potential -28.2 -35.2 -29.7 -32.1 -28.9 -42.7 -13.1 -45.7 -15.1 -44.7
S*forward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*backward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*net_flux 1.04e-12 -5.98e-12 -3.11e-13 -6.01e-12 -6.98e-08 -5.42e-12 nan nan nan nan
Out[89]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
Forward likelihoods 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Backward likelihoods 0.00224 0.0611 0.557 1 0.00604 0.443 0.387 0.00412 0.448
Delta G -15.1 -6.93 -1.45 -3.34e-06 -13.8 -2.02 -2.35 -13.6 -1.99
log Q_r -6.1 -1.99 0.221 1.61 -5.57 -0.411 -0.142 -5.49 -0.804
log K_eq -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
Delta G0 0 -2 -2 -4 0 -1 -2 0 0
logK - logQ 6.1 2.79 0.586 1.35e-06 5.57 0.815 0.949 5.49 0.804
logQ - logK -6.1 -2.79 -0.586 -1.35e-06 -5.57 -0.815 -0.949 -5.49 -0.804
Forward Log likelihoods 6.1 2.79 0.586 1.56e-06 5.11 0.815 0.949 5.49 0.804
Backward Log likelihoods -6.1 -2.79 -0.586 -1.56e-06 -5.11 -0.815 -0.949 -5.49 -0.804
Forward probabilities 0.505 0.0185 0.00203 0.00113 0.187 0.00256 0.00292 0.274 0.00253
Backward probabilities 2.54e-06 6.92e-05 0.00063 0.00113 6.84e-06 0.000501 0.000438 4.67e-06 0.000507
Net probabilities 0.505 0.0184 0.0014 3.54e-09 0.187 0.00205 0.00248 0.274 0.00202
Net likelihoods 446 16.3 1.24 3.12e-06 166 1.82 2.19 243 1.79
Forward rate 3.71 2.96 2.07 3.75 5.83e-06 2.5 3.77 2.32 2.52
Backward rate 0.00831 0.181 1.15 3.75 3.52e-08 1.11 1.46 0.00956 1.13
Thermodynamic driving force 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Net flux 3.7 2.78 0.916 5.86e-06 5.79e-06 1.39 2.31 2.31 1.39
Forward Entropy Production 0.345 0.0739 0.0126 0.00768 0.314 0.0153 0.0171 0.355 0.0151
Backward Entropy Production 3.27e-05 0.000663 0.00464 0.00768 8.13e-05 0.00381 0.00339 5.73e-05 0.00384
Reaction Entropy Production 0.345 0.0745 0.0172 0.0154 0.314 0.0191 0.0204 0.355 0.019
Microscopic Reaction Entropy Production Rate 1.28 0.219 0.0314 0.0577 1.83e-06 0.0423 0.0692 0.822 0.0424
Microscopic Reaction Entropy Production Net Flux 1.28 0.207 0.0158 9e-08 1.82e-06 0.0265 0.0472 0.819 0.0264
Microscopic Reaction Entropy Production Net Flux Difference 1.28 0.204 0.00729 1.2e-13 1.82e-06 0.0159 0.0315 0.819 0.0157
Total Entropy Production 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18
Total Microscopic Entropy Production Rate 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42
Macroscopic Reaction Entropy Production Net Flux 0.796 0.172 0.0398 0.0354 0.724 0.044 0.0472 0.819 0.0438
Macroscopic Reaction Entropy Production Net Flux Difference 0.796 0.169 0.0184 4.72e-08 0.724 0.0264 0.0315 0.819 0.026
Total Macroscopic Entropy Production Net Flux 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72
Total Macroscopic Entropy Production Net Flux Difference 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61

In [65]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')

reaction_data = reactions[obj]['Net flux'].to_dict()
metabolite_data = metab[obj]['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[65]:

Minimize entropy production for the ABC model

$$ \begin{array}{ll} \underset{\vec{\bf c}, \vec{r}_+,\vec{r}_-}{\mbox{minimize}} & -\sum_i {\mathscr P}_{+i}\log{\mathscr P}_{+i}-\sum_i {\mathscr P}_{-i}\log{\mathscr P}_{-i} \\ \mbox{subject to} & S\cdot(\vec{\bf r}_+-\vec{\bf r}_-) = 0 \\ &\log\vec{\bf r}_+ -\log\vec{\bf r}_-= -\frac{1}{RT}S^T\cdot\vec{\mu}^0 - S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_- = \frac{1}{RT}S^T\cdot\vec{\mu}^0 + S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_+ -\log\vec{\bf L}_- \\ & \vec{v}_{lower}(L_+) \leq \vec{\bf r}_+ -\vec{\bf r}_- \leq \vec{v}_{upper}(L_+) \\ & \vec{\bf r}_+ \geq 0 \\ & \vec{\bf r}_- \geq 0 \\ & \log \left[{\bf A}_{ext}\right] = \log \left[{\bf E}_{ext}\right] = \log c_{upper} \\ & \log \left[{\bf E}_{ext}\right] = \log \left[{\bf D}_{ext}\right] = \log c_{lower} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_A \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_B \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_C \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_D \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_E \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_F \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ \end{array} \\$$

Where

  • $\vec{\bf r}_+,\vec{\bf r}_-$ are decision variables representing the forward and backward rates, respectively.
  • ${\mathscr P}_{+i},{\mathscr P}_{-i}$ are the normalized forward and backward thermodynamic driving forces $\frac{r_{+i}}{r_{-i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ and $\frac{r_{-i}}{r_{+i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$
  • $\vec{\bf c}$ is a decision variable representing the chemical concentrations of each metabolite
  • $S$ is the $m\times n$ stoichiometric matrix of representing $m$ metabolites and $n$ reactions of the model
  • $\vec{\mu}^0$ is the vector of standard chemical potentials
  • $L_+ = \frac{r_+}{r_-}$
  • $L_- = \frac{r_-}{r_+}$
  • $v_{lower}(L) =\min\left(-1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) + 1$
  • $v_{upper}(L) = \max\left(1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) - 1$

Decision variables are emphasized in bold.


In [91]:
from IPython.display import HTML
obj = 'minent_production'
def make_minent_production_objective( fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U):
    """Minimum entropy of ABC model"""
    def minent_production(x):
        log_c, \
        forward_rate, backward_rate, \
        log_Q, log_K, \
        forward_likelihood, backward_likelihood, \
        forward_probability, backward_probability, mu, \
        thermodynamic_driving_force, \
        net_flux = mentos.make_variables( x, fullS, mu0, deltaG0, R, T )
        f = entropy(np.append(forward_probability, backward_probability )  ) 
        g = np.concatenate((np.dot(S,net_flux),
                            np.log(forward_rate) - np.log(backward_rate) + log_Q - log_K,
                            [ log_c[A_ext] - np.log(c_U),                 # Creating a concentration gradient between A, E and D,F
                              log_c[E_ext] - np.log(c_U),
                              log_c[D_ext] - np.log(c_L),
                              log_c[F_ext] - np.log(c_L)],
                             [-mu[A] + mu[D_ext] + mu[F_ext],           # Energy sink constraint
                              -mu[B] + mu[D_ext] + mu[F_ext],
                              -mu[C] + mu[D_ext] + mu[F_ext],
                              -mu[D] + mu[D_ext] + mu[F_ext],
                              -mu[E] + mu[D_ext] + mu[F_ext],
                              -mu[F] + mu[D_ext] + mu[F_ext]],
    
                             [ mu[A] - mu[A_ext] - mu[E_ext],           # Energy barrier constraint
                               mu[B] - mu[A_ext] - mu[E_ext],
                               mu[C] - mu[A_ext] - mu[E_ext],
                               mu[D] - mu[A_ext] - mu[E_ext],
                               mu[E] - mu[A_ext] - mu[E_ext],
                               mu[F] - mu[A_ext] - mu[E_ext]],  
                            
                               np.minimum(-1, thermodynamic_driving_force)+ 1 -net_flux,
                               net_flux - np.maximum(1, thermodynamic_driving_force ) - 1))
        
        fail = 0
        return f, g, fail
    return minent_production
metab[obj], reactions[obj] = mentos.run_mentos(fullS, S, internal_mets, deltaG0, mu0, 
                                        c_L, c_U, v_L, v_U,
                                        initial_log_c=metab['convex_mentos']['Log Concentrations'].values, 
                                        initial_forward_rate=reactions['convex_mentos']['Forward rate'].values,
                                        initial_backward_rate=reactions['convex_mentos']['Backward rate'].values,
                                        obj=make_maxent_production_objective( fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U),
                                        biomass_rxn='R_8')
true_metab[obj] = pd.read_csv('ABC_metab_{}.csv'.format(obj), index_col=0)
true_reactions[obj] = pd.read_csv('ABC_reactions_{}.csv'.format(obj),index_col=0)

display(mentos.compare_frames(true_metab[obj], metab[obj]))
pd.testing.assert_frame_equal(true_metab[obj].astype(np.float64),metab[obj].astype(np.float64))
pd.testing.assert_frame_equal(true_reactions[obj],reactions[obj])


HTML(mentos.compare_frames(true_reactions[obj],reactions[obj]).to_html())


A B C D E F A_ext D_ext E_ext F_ext
Counts 1.35e+03 184 1.68e+03 1.46e+03 2.3e+03 13 6.02e+05 6 6.02e+05 6
Concentrations 2.24e-06 3.07e-07 2.79e-06 2.43e-06 3.82e-06 2.23e-08 0.001 1e-08 0.001 1e-08
Log Concentrations -13 -15 -12.8 -12.9 -12.5 -17.6 -6.91 -18.4 -6.91 -18.4
Standard Chemical potential 4 2 2 0 2 1 4 0 2 1
Chemical potential -28.2 -35.2 -29.7 -32.1 -28.9 -42.7 -13.1 -45.7 -15.1 -44.7
S*forward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*backward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*net_flux 1.04e-12 -5.98e-12 -3.11e-13 -6.01e-12 -6.98e-08 -5.42e-12 nan nan nan nan
Out[91]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
Forward likelihoods 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Backward likelihoods 0.00224 0.0611 0.557 1 0.00604 0.443 0.387 0.00412 0.448
Delta G -15.1 -6.93 -1.45 -3.34e-06 -13.8 -2.02 -2.35 -13.6 -1.99
log Q_r -6.1 -1.99 0.221 1.61 -5.57 -0.411 -0.142 -5.49 -0.804
log K_eq -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
Delta G0 0 -2 -2 -4 0 -1 -2 0 0
logK - logQ 6.1 2.79 0.586 1.35e-06 5.57 0.815 0.949 5.49 0.804
logQ - logK -6.1 -2.79 -0.586 -1.35e-06 -5.57 -0.815 -0.949 -5.49 -0.804
Forward Log likelihoods 6.1 2.79 0.586 1.56e-06 5.11 0.815 0.949 5.49 0.804
Backward Log likelihoods -6.1 -2.79 -0.586 -1.56e-06 -5.11 -0.815 -0.949 -5.49 -0.804
Forward probabilities 0.505 0.0185 0.00203 0.00113 0.187 0.00256 0.00292 0.274 0.00253
Backward probabilities 2.54e-06 6.92e-05 0.00063 0.00113 6.84e-06 0.000501 0.000438 4.67e-06 0.000507
Net probabilities 0.505 0.0184 0.0014 3.54e-09 0.187 0.00205 0.00248 0.274 0.00202
Net likelihoods 446 16.3 1.24 3.12e-06 166 1.82 2.19 243 1.79
Forward rate 3.71 2.96 2.07 3.75 5.83e-06 2.5 3.77 2.32 2.52
Backward rate 0.00831 0.181 1.15 3.75 3.52e-08 1.11 1.46 0.00956 1.13
Thermodynamic driving force 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Net flux 3.7 2.78 0.916 5.86e-06 5.79e-06 1.39 2.31 2.31 1.39
Forward Entropy Production 0.345 0.0739 0.0126 0.00768 0.314 0.0153 0.0171 0.355 0.0151
Backward Entropy Production 3.27e-05 0.000663 0.00464 0.00768 8.13e-05 0.00381 0.00339 5.73e-05 0.00384
Reaction Entropy Production 0.345 0.0745 0.0172 0.0154 0.314 0.0191 0.0204 0.355 0.019
Microscopic Reaction Entropy Production Rate 1.28 0.219 0.0314 0.0577 1.83e-06 0.0423 0.0692 0.822 0.0424
Microscopic Reaction Entropy Production Net Flux 1.28 0.207 0.0158 9e-08 1.82e-06 0.0265 0.0472 0.819 0.0264
Microscopic Reaction Entropy Production Net Flux Difference 1.28 0.204 0.00729 1.2e-13 1.82e-06 0.0159 0.0315 0.819 0.0157
Total Entropy Production 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18
Total Microscopic Entropy Production Rate 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42
Macroscopic Reaction Entropy Production Net Flux 0.796 0.172 0.0398 0.0354 0.724 0.044 0.0472 0.819 0.0438
Macroscopic Reaction Entropy Production Net Flux Difference 0.796 0.169 0.0184 4.72e-08 0.724 0.0264 0.0315 0.819 0.026
Total Macroscopic Entropy Production Net Flux 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72
Total Macroscopic Entropy Production Net Flux Difference 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61

In [92]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')

reaction_data = reactions[obj]['Net flux'].to_dict()
metabolite_data = metab[obj]['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[92]:

Maximize microscopic entropy production net flux difference for the ABC model

$$ \begin{array}{ll} \underset{\vec{\bf r}_+,\vec{\bf r}_-, \vec{\bf c}}{\mbox{maximize}} & -\sum_j{\mathscr P}_{+j}\log({\mathscr P}_{+j})v_{j} + \sum_j{\mathscr P}_{-j}\log({\mathscr P}_{-j})v_{j} \\ \mbox{subject to} & S\cdot(\vec{\bf r}_+-\vec{\bf r}_-) = 0 \\ &\log\vec{\bf r}_+ -\log\vec{\bf r}_-= -\frac{1}{RT}S^T\cdot\vec{\mu}^0 - S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_- = \frac{1}{RT}S^T\cdot\vec{\mu}^0 + S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_+ -\log\vec{\bf L}_- \\ & \vec{v}_{lower}(L_+) \leq \vec{\bf r}_+ -\vec{\bf r}_- \leq \vec{v}_{upper}(L_+) \\ & \vec{\bf r}_+ \geq 0 \\ & \vec{\bf r}_- \geq 0 \\ & \log \left[{\bf A}_{ext}\right] = \log \left[{\bf E}_{ext}\right] = \log c_{upper} \\ & \log \left[{\bf E}_{ext}\right] = \log \left[{\bf D}_{ext}\right] = \log c_{lower} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_A \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_B \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_C \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_D \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_E \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_F \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ \end{array} \\$$

Where

\begin{itemize} \item $\vec{\bf r}_+,\vec{\bf r}_-$ are decision variables representing the forward and backward rates, respectively. \item ${\mathscr P}_{+i},{\mathscr P}_{-i}$ are the normalized forward and backward thermodynamic driving forces $\frac{r_{+i}}{r_{-i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ and $\frac{r_{-i}}{r_{+i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ \item $\vec{\bf c}$ is a decision variable representing the chemical concentrations of each metabolite \item $S$ is the $m\times n$ stoichiometric matrix of representing $m$ metabolites and $n$ reactions of the model \item $\vec{\mu}^0$ is the vector of standard chemical potentials \item $L_+ = \frac{r_+}{r_-}$ \item $L_- = \frac{r_-}{r_+}$ \item $v_{lower}(L) =\min\left(-1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) + 1$ \item $v_{upper}(L) = \max\left(1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) - 1$ \end{itemize}

Decision variables are emphasized in bold.


In [93]:
obj = 'micro_maxent_production_net_flux_diff'
def make_micro_maxent_production_net_flux_diff_objective(fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U):
    def micro_maxent_production_net_flux_diff(x):
        """Maximize product of microscopic entropy production and net_flux of the ABC model"""
        log_c, \
        forward_rate, backward_rate, \
        log_Q, log_K, \
        forward_likelihood, backward_likelihood, \
        forward_probability, backward_probability, mu, \
        thermodynamic_driving_force, \
        net_flux = mentos.make_variables( x, fullS, mu0, deltaG0, R, T )
        f = -np.sum( np.log(forward_probability)*forward_probability*net_flux
                    - np.log(backward_probability)*backward_probability*net_flux)
        g = np.concatenate((np.dot(S,net_flux),
                            np.log(forward_rate) - np.log(backward_rate) + log_Q - log_K,
                            [ log_c[A_ext] - np.log(c_U),                 # Creating a concentration gradient between A, E and D,F
                              log_c[E_ext] - np.log(c_U),
                              log_c[D_ext] - np.log(c_L),
                              log_c[F_ext] - np.log(c_L)],
                             [-mu[A] + mu[D_ext] + mu[F_ext],           # Energy sink constraint
                              -mu[B] + mu[D_ext] + mu[F_ext],
                              -mu[C] + mu[D_ext] + mu[F_ext],
                              -mu[D] + mu[D_ext] + mu[F_ext],
                              -mu[E] + mu[D_ext] + mu[F_ext],
                              -mu[F] + mu[D_ext] + mu[F_ext]],
    
                             [ mu[A] - mu[A_ext] - mu[E_ext],           # Energy barrier constraint
                               mu[B] - mu[A_ext] - mu[E_ext],
                               mu[C] - mu[A_ext] - mu[E_ext],
                               mu[D] - mu[A_ext] - mu[E_ext],
                               mu[E] - mu[A_ext] - mu[E_ext],
                               mu[F] - mu[A_ext] - mu[E_ext]],  
                            
                              np.minimum(-1, thermodynamic_driving_force)+ 1 -net_flux,
                               net_flux - np.maximum(1, thermodynamic_driving_force ) - 1))
        
        fail = 0
        return -f, g, fail
    return micro_maxent_production_net_flux_diff
metab[obj], reactions[obj] = mentos.run_mentos(fullS, S, internal_mets, deltaG0, mu0, 
                                        c_L, c_U, v_L, v_U,
                                        initial_log_c=metab['convex_mentos']['Log Concentrations'].values, 
                                        initial_forward_rate=reactions['convex_mentos']['Forward rate'].values,
                                        initial_backward_rate=reactions['convex_mentos']['Backward rate'].values,
                                        obj=make_maxent_production_objective( fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U),
                                        biomass_rxn='R_8')

#metab[obj].to_csv('ABC_metab_{}.csv'.format(obj))
#reactions[obj].to_csv('ABC_reactions_{obj}.csv'.format(obj=obj))

#display(metab[obj].T)
#HTML(reactions[obj].T.to_html())
true_metab[obj] = pd.read_csv('ABC_metab_{}.csv'.format(obj), index_col=0).astype(np.float64)
true_reactions[obj] = pd.read_csv('ABC_reactions_{}.csv'.format(obj),index_col=0)

display(mentos.compare_frames(true_metab[obj], metab[obj]))
pd.testing.assert_frame_equal(true_metab[obj],metab[obj].astype(np.float64))
pd.testing.assert_frame_equal(true_reactions[obj],reactions[obj])


HTML(mentos.compare_frames(true_reactions[obj],reactions[obj]).to_html())


A B C D E F A_ext D_ext E_ext F_ext
Counts 1.35e+03 184 1.68e+03 1.46e+03 2.3e+03 13 6.02e+05 6 6.02e+05 6
Concentrations 2.24e-06 3.07e-07 2.79e-06 2.43e-06 3.82e-06 2.23e-08 0.001 1e-08 0.001 1e-08
Log Concentrations -13 -15 -12.8 -12.9 -12.5 -17.6 -6.91 -18.4 -6.91 -18.4
Standard Chemical potential 4 2 2 0 2 1 4 0 2 1
Chemical potential -28.2 -35.2 -29.7 -32.1 -28.9 -42.7 -13.1 -45.7 -15.1 -44.7
S*forward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*backward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*net_flux 1.04e-12 -5.98e-12 -3.11e-13 -6.01e-12 -6.98e-08 -5.42e-12 nan nan nan nan
Out[93]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
Forward likelihoods 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Backward likelihoods 0.00224 0.0611 0.557 1 0.00604 0.443 0.387 0.00412 0.448
Delta G -15.1 -6.93 -1.45 -3.34e-06 -13.8 -2.02 -2.35 -13.6 -1.99
log Q_r -6.1 -1.99 0.221 1.61 -5.57 -0.411 -0.142 -5.49 -0.804
log K_eq -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
Delta G0 0 -2 -2 -4 0 -1 -2 0 0
logK - logQ 6.1 2.79 0.586 1.35e-06 5.57 0.815 0.949 5.49 0.804
logQ - logK -6.1 -2.79 -0.586 -1.35e-06 -5.57 -0.815 -0.949 -5.49 -0.804
Forward Log likelihoods 6.1 2.79 0.586 1.56e-06 5.11 0.815 0.949 5.49 0.804
Backward Log likelihoods -6.1 -2.79 -0.586 -1.56e-06 -5.11 -0.815 -0.949 -5.49 -0.804
Forward probabilities 0.505 0.0185 0.00203 0.00113 0.187 0.00256 0.00292 0.274 0.00253
Backward probabilities 2.54e-06 6.92e-05 0.00063 0.00113 6.84e-06 0.000501 0.000438 4.67e-06 0.000507
Net probabilities 0.505 0.0184 0.0014 3.54e-09 0.187 0.00205 0.00248 0.274 0.00202
Net likelihoods 446 16.3 1.24 3.12e-06 166 1.82 2.19 243 1.79
Forward rate 3.71 2.96 2.07 3.75 5.83e-06 2.5 3.77 2.32 2.52
Backward rate 0.00831 0.181 1.15 3.75 3.52e-08 1.11 1.46 0.00956 1.13
Thermodynamic driving force 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Net flux 3.7 2.78 0.916 5.86e-06 5.79e-06 1.39 2.31 2.31 1.39
Forward Entropy Production 0.345 0.0739 0.0126 0.00768 0.314 0.0153 0.0171 0.355 0.0151
Backward Entropy Production 3.27e-05 0.000663 0.00464 0.00768 8.13e-05 0.00381 0.00339 5.73e-05 0.00384
Reaction Entropy Production 0.345 0.0745 0.0172 0.0154 0.314 0.0191 0.0204 0.355 0.019
Microscopic Reaction Entropy Production Rate 1.28 0.219 0.0314 0.0577 1.83e-06 0.0423 0.0692 0.822 0.0424
Microscopic Reaction Entropy Production Net Flux 1.28 0.207 0.0158 9e-08 1.82e-06 0.0265 0.0472 0.819 0.0264
Microscopic Reaction Entropy Production Net Flux Difference 1.28 0.204 0.00729 1.2e-13 1.82e-06 0.0159 0.0315 0.819 0.0157
Total Entropy Production 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18
Total Microscopic Entropy Production Rate 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42
Macroscopic Reaction Entropy Production Net Flux 0.796 0.172 0.0398 0.0354 0.724 0.044 0.0472 0.819 0.0438
Macroscopic Reaction Entropy Production Net Flux Difference 0.796 0.169 0.0184 4.72e-08 0.724 0.0264 0.0315 0.819 0.026
Total Macroscopic Entropy Production Net Flux 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72
Total Macroscopic Entropy Production Net Flux Difference 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61

In [22]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')

reaction_data = reactions[obj]['Net flux'].to_dict()
metabolite_data = metab[obj]['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[22]:

Maximize microscopic entropy production net flux for the ABC model

$$ \begin{array}{ll} \underset{\vec{\bf r}_+,\vec{\bf r}_-, \vec{\bf c}}{\mbox{maximize}} & -\sum_j{\mathscr P}_{+j}\log({\mathscr P}_{+j})v_{j} - \sum_j{\mathscr P}_{-j}\log({\mathscr P}_{-j})v_{j} \\ \mbox{subject to} & S\cdot(\vec{\bf r}_+-\vec{\bf r}_-) = 0 \\ &\log\vec{\bf r}_+ -\log\vec{\bf r}_-= -\frac{1}{RT}S^T\cdot\vec{\mu}^0 - S^T\cdot\log\vec{\bf a} \\ %% & \log\vec{\bf L}_- = \frac{1}{RT}S^T\cdot\vec{\mu}^0 + S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_+ -\log\vec{\bf L}_- \\ & \vec{v}_{lower}(L_+) \leq \vec{\bf r}_+ -\vec{\bf r}_- \leq \vec{v}_{upper}(L_+) \\ & \vec{\bf r}_+ \geq 0 \\ & \vec{\bf r}_- \geq 0 \\ & \log \left[{\bf A}_{ext}\right] = \log \left[{\bf E}_{ext}\right] = \log c_{upper} \\ & \log \left[{\bf E}_{ext}\right] = \log \left[{\bf D}_{ext}\right] = \log c_{lower} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_A \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_B \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_C \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_D \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_E \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_F \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ \end{array} \\$$

Where

\begin{itemize} \item $\vec{\bf r}_+,\vec{\bf r}_-$ are decision variables representing the forward and backward rates, respectively. \item ${\mathscr P}_{+i},{\mathscr P}_{-i}$ are the normalized forward and backward thermodynamic driving forces $\frac{r_{+i}}{r_{-i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ and $\frac{r_{-i}}{r_{+i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ \item $\vec{\bf c}$ is a decision variable representing the chemical concentrations of each metabolite \item $S$ is the $m\times n$ stoichiometric matrix of representing $m$ metabolites and $n$ reactions of the model \item $\vec{\mu}^0$ is the vector of standard chemical potentials \item $L_+ = \frac{r_+}{r_-}$ \item $L_- = \frac{r_-}{r_+}$ \item $v_{lower}(L) =\min\left(-1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) + 1$ \item $v_{upper}(L) = \max\left(1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) - 1$ \end{itemize}

Decision variables are emphasized in bold.


In [94]:
obj = 'micro_maxent_production_net_flux'
def make_micro_maxent_production_net_flux_objective(fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U):
    def micro_maxent_production_net_flux(x):
        """Maximize product of microscopic entropy production and net_flux of the ABC model"""
        log_c, \
        forward_rate, backward_rate, \
        log_Q, log_K, \
        forward_likelihood, backward_likelihood, \
        forward_probability, backward_probability, mu, \
        thermodynamic_driving_force, \
        net_flux = mentos.make_variables( x, fullS, mu0, deltaG0, R, T )
        f = -np.sum( np.log(forward_probability)*forward_probability*net_flux
                    + np.log(backward_probability)*backward_probability*net_flux)
        g = np.concatenate((np.dot(S,net_flux),
                            np.log(forward_rate) - np.log(backward_rate) + log_Q - log_K,
                            [ log_c[A_ext] - np.log(c_U),                 # Creating a concentration gradient between A, E and D,F
                              log_c[E_ext] - np.log(c_U),
                              log_c[D_ext] - np.log(c_L),
                              log_c[F_ext] - np.log(c_L)],
                             [-mu[A] + mu[D_ext] + mu[F_ext],           # Energy sink constraint
                              -mu[B] + mu[D_ext] + mu[F_ext],
                              -mu[C] + mu[D_ext] + mu[F_ext],
                              -mu[D] + mu[D_ext] + mu[F_ext],
                              -mu[E] + mu[D_ext] + mu[F_ext],
                              -mu[F] + mu[D_ext] + mu[F_ext]],
    
                             [ mu[A] - mu[A_ext] - mu[E_ext],           # Energy barrier constraint
                               mu[B] - mu[A_ext] - mu[E_ext],
                               mu[C] - mu[A_ext] - mu[E_ext],
                               mu[D] - mu[A_ext] - mu[E_ext],
                               mu[E] - mu[A_ext] - mu[E_ext],
                               mu[F] - mu[A_ext] - mu[E_ext]],  
                            
                              np.minimum(-1, thermodynamic_driving_force)+ 1 -net_flux,
                               net_flux - np.maximum(1, thermodynamic_driving_force ) - 1))
        
        fail = 0
        return -f, g, fail
    return micro_maxent_production_net_flux
metab[obj], reactions[obj] = mentos.run_mentos(fullS, S, internal_mets, deltaG0, mu0, 
                                        c_L, c_U, v_L, v_U,
                                        initial_log_c=metab['convex_mentos']['Log Concentrations'].values, 
                                        initial_forward_rate=reactions['convex_mentos']['Forward rate'].values,
                                        initial_backward_rate=reactions['convex_mentos']['Backward rate'].values,
                                        obj=make_maxent_production_objective( fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U),
                                        biomass_rxn='R_8')
#metab[obj].to_csv('ABC_metab_{}.csv'.format(obj))
#reactions[obj].to_csv('ABC_reactions_{obj}.csv'.format(obj=obj))

#display(metab[obj].T)
#HTML(reactions[obj].T.to_html())
true_metab[obj] = pd.read_csv('ABC_metab_{}.csv'.format(obj), index_col=0).astype(np.float64)
true_reactions[obj] = pd.read_csv('ABC_reactions_{}.csv'.format(obj),index_col=0)

display(mentos.compare_frames(true_metab[obj], metab[obj]))
pd.testing.assert_frame_equal(true_metab[obj],metab[obj].astype(np.float64))
pd.testing.assert_frame_equal(true_reactions[obj],reactions[obj])


HTML(mentos.compare_frames(true_reactions[obj],reactions[obj]).to_html())


A B C D E F A_ext D_ext E_ext F_ext
Counts 1.35e+03 184 1.68e+03 1.46e+03 2.3e+03 13 6.02e+05 6 6.02e+05 6
Concentrations 2.24e-06 3.07e-07 2.79e-06 2.43e-06 3.82e-06 2.23e-08 0.001 1e-08 0.001 1e-08
Log Concentrations -13 -15 -12.8 -12.9 -12.5 -17.6 -6.91 -18.4 -6.91 -18.4
Standard Chemical potential 4 2 2 0 2 1 4 0 2 1
Chemical potential -28.2 -35.2 -29.7 -32.1 -28.9 -42.7 -13.1 -45.7 -15.1 -44.7
S*forward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*backward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*net_flux 1.04e-12 -5.98e-12 -3.11e-13 -6.01e-12 -6.98e-08 -5.42e-12 nan nan nan nan
Out[94]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
Forward likelihoods 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Backward likelihoods 0.00224 0.0611 0.557 1 0.00604 0.443 0.387 0.00412 0.448
Delta G -15.1 -6.93 -1.45 -3.34e-06 -13.8 -2.02 -2.35 -13.6 -1.99
log Q_r -6.1 -1.99 0.221 1.61 -5.57 -0.411 -0.142 -5.49 -0.804
log K_eq -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
Delta G0 0 -2 -2 -4 0 -1 -2 0 0
logK - logQ 6.1 2.79 0.586 1.35e-06 5.57 0.815 0.949 5.49 0.804
logQ - logK -6.1 -2.79 -0.586 -1.35e-06 -5.57 -0.815 -0.949 -5.49 -0.804
Forward Log likelihoods 6.1 2.79 0.586 1.56e-06 5.11 0.815 0.949 5.49 0.804
Backward Log likelihoods -6.1 -2.79 -0.586 -1.56e-06 -5.11 -0.815 -0.949 -5.49 -0.804
Forward probabilities 0.505 0.0185 0.00203 0.00113 0.187 0.00256 0.00292 0.274 0.00253
Backward probabilities 2.54e-06 6.92e-05 0.00063 0.00113 6.84e-06 0.000501 0.000438 4.67e-06 0.000507
Net probabilities 0.505 0.0184 0.0014 3.54e-09 0.187 0.00205 0.00248 0.274 0.00202
Net likelihoods 446 16.3 1.24 3.12e-06 166 1.82 2.19 243 1.79
Forward rate 3.71 2.96 2.07 3.75 5.83e-06 2.5 3.77 2.32 2.52
Backward rate 0.00831 0.181 1.15 3.75 3.52e-08 1.11 1.46 0.00956 1.13
Thermodynamic driving force 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Net flux 3.7 2.78 0.916 5.86e-06 5.79e-06 1.39 2.31 2.31 1.39
Forward Entropy Production 0.345 0.0739 0.0126 0.00768 0.314 0.0153 0.0171 0.355 0.0151
Backward Entropy Production 3.27e-05 0.000663 0.00464 0.00768 8.13e-05 0.00381 0.00339 5.73e-05 0.00384
Reaction Entropy Production 0.345 0.0745 0.0172 0.0154 0.314 0.0191 0.0204 0.355 0.019
Microscopic Reaction Entropy Production Rate 1.28 0.219 0.0314 0.0577 1.83e-06 0.0423 0.0692 0.822 0.0424
Microscopic Reaction Entropy Production Net Flux 1.28 0.207 0.0158 9e-08 1.82e-06 0.0265 0.0472 0.819 0.0264
Microscopic Reaction Entropy Production Net Flux Difference 1.28 0.204 0.00729 1.2e-13 1.82e-06 0.0159 0.0315 0.819 0.0157
Total Entropy Production 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18
Total Microscopic Entropy Production Rate 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42
Macroscopic Reaction Entropy Production Net Flux 0.796 0.172 0.0398 0.0354 0.724 0.044 0.0472 0.819 0.0438
Macroscopic Reaction Entropy Production Net Flux Difference 0.796 0.169 0.0184 4.72e-08 0.724 0.0264 0.0315 0.819 0.026
Total Macroscopic Entropy Production Net Flux 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72
Total Macroscopic Entropy Production Net Flux Difference 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61

In [71]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')

reaction_data = reactions[obj]['Net flux'].to_dict()
metabolite_data = metab[obj]['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[71]:

Maximize microscopic entropy production rate for the ABC model

$$ \begin{array}{ll} \underset{\vec{\bf r}_+,\vec{\bf r}_-,\vec{\bf c}}{\mbox{maximize}} & -\sum_j{\mathscr P}_{+j}\log({\mathscr P}_{+j})r_{+j} - \sum_j{\mathscr P}_{-j}\log({\mathscr P}_{-j})r_{-j} \\ \mbox{subject to} & S\cdot(\vec{\bf r}_+-\vec{\bf r}_-) = 0 \\ &\log\vec{\bf r}_+ -\log\vec{\bf r}_-= -\frac{1}{RT}S^T\cdot\vec{\mu}^0 - S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_- = \frac{1}{RT}S^T\cdot\vec{\mu}^0 + S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_+ -\log\vec{\bf L}_- \\ & \vec{v}_{lower}(L_+) \leq \vec{\bf r}_+ -\vec{\bf r}_- \leq \vec{v}_{upper}(L_+) \\ & \vec{\bf r}_+ \geq 0 \\ & \vec{\bf r}_- \geq 0 \\ & \log \left[{\bf A}_{ext}\right] = \log \left[{\bf E}_{ext}\right] = \log c_{upper} \\ & \log \left[{\bf E}_{ext}\right] = \log \left[{\bf D}_{ext}\right] = \log c_{lower} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_A \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_B \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_C \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_D \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_E \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_F \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ \end{array} \\$$

Where

\begin{itemize} \item $\vec{\bf r}_+,\vec{\bf r}_-$ are decision variables representing the forward and backward rates, respectively. \item ${\mathscr P}_{+i},{\mathscr P}_{-i}$ are the normalized forward and backward thermodynamic driving forces $\frac{r_{+i}}{r_{-i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ and $\frac{r_{-i}}{r_{+i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ \item $\vec{\bf c}$ is a decision variable representing the chemical concentrations of each metabolite \item $S$ is the $m\times n$ stoichiometric matrix of representing $m$ metabolites and $n$ reactions of the model \item $\vec{\mu}^0$ is the vector of standard chemical potentials \item $L_+ = \frac{r_+}{r_-}$ \item $L_- = \frac{r_-}{r_+}$ \item $v_{lower}(L) =\min\left(-1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) + 1$ \item $v_{upper}(L) = \max\left(1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) - 1$ \end{itemize}

Decision variables are emphasized in bold.


In [95]:
obj = 'micro_maxent_production_rate'
def make_micro_maxent_production_rate_objective(fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U):
    def micro_maxent_production_rate(x):
        """Maximize product of microscopic entropy production and rate of the ABC model"""
        log_c, \
        forward_rate, backward_rate, \
        log_Q, log_K, \
        forward_likelihood, backward_likelihood, \
        forward_probability, backward_probability, mu, \
        thermodynamic_driving_force, \
        net_flux = mentos.make_variables( x, fullS, mu0, deltaG0, R, T )
        f = -np.sum( np.log(forward_probability)*forward_probability*forward_rate
                    + np.log(backward_probability)*backward_probability*backward_rate)
        g = np.concatenate((np.dot(S,net_flux),
                            np.log(forward_rate) - np.log(backward_rate) + log_Q - log_K,
                            [ log_c[A_ext] - np.log(c_U),                 # Creating a concentration gradient between A, E and D,F
                              log_c[E_ext] - np.log(c_U),
                              log_c[D_ext] - np.log(c_L),
                              log_c[F_ext] - np.log(c_L)],
                             [-mu[A] + mu[D_ext] + mu[F_ext],           # Energy sink constraint
                              -mu[B] + mu[D_ext] + mu[F_ext],
                              -mu[C] + mu[D_ext] + mu[F_ext],
                              -mu[D] + mu[D_ext] + mu[F_ext],
                              -mu[E] + mu[D_ext] + mu[F_ext],
                              -mu[F] + mu[D_ext] + mu[F_ext]],
    
                             [ mu[A] - mu[A_ext] - mu[E_ext],           # Energy barrier constraint
                               mu[B] - mu[A_ext] - mu[E_ext],
                               mu[C] - mu[A_ext] - mu[E_ext],
                               mu[D] - mu[A_ext] - mu[E_ext],
                               mu[E] - mu[A_ext] - mu[E_ext],
                               mu[F] - mu[A_ext] - mu[E_ext]],  
                            
                              np.minimum(-1, thermodynamic_driving_force)+ 1 -net_flux,
                               net_flux - np.maximum(1, thermodynamic_driving_force ) - 1))
        
        fail = 0
        return -f, g, fail
    return micro_maxent_production_rate
metab[obj], reactions[obj] = mentos.run_mentos(fullS, S, internal_mets, deltaG0, mu0, 
                                        c_L, c_U, v_L, v_U,
                                        initial_log_c=metab['convex_mentos']['Log Concentrations'].values, 
                                        initial_forward_rate=reactions['convex_mentos']['Forward rate'].values,
                                        initial_backward_rate=reactions['convex_mentos']['Backward rate'].values,
                                        obj=make_maxent_production_objective( fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U),
                                        biomass_rxn='R_8')
#metab[obj].to_csv('ABC_metab_{}.csv'.format(obj))
#reactions[obj].to_csv('ABC_reactions_{obj}.csv'.format(obj=obj))

#display(metab[obj].T)
#HTML(reactions[obj].T.to_html())
true_metab[obj] = pd.read_csv('ABC_metab_{}.csv'.format(obj), index_col=0).astype(np.float64)
true_reactions[obj] = pd.read_csv('ABC_reactions_{}.csv'.format(obj),index_col=0)

display(mentos.compare_frames(true_metab[obj], metab[obj]))
pd.testing.assert_frame_equal(true_metab[obj],metab[obj].astype(np.float64))
pd.testing.assert_frame_equal(true_reactions[obj],reactions[obj])


HTML(mentos.compare_frames(true_reactions[obj],reactions[obj]).to_html())


A B C D E F A_ext D_ext E_ext F_ext
Counts 1.35e+03 184 1.68e+03 1.46e+03 2.3e+03 13 6.02e+05 6 6.02e+05 6
Concentrations 2.24e-06 3.07e-07 2.79e-06 2.43e-06 3.82e-06 2.23e-08 0.001 1e-08 0.001 1e-08
Log Concentrations -13 -15 -12.8 -12.9 -12.5 -17.6 -6.91 -18.4 -6.91 -18.4
Standard Chemical potential 4 2 2 0 2 1 4 0 2 1
Chemical potential -28.2 -35.2 -29.7 -32.1 -28.9 -42.7 -13.1 -45.7 -15.1 -44.7
S*forward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*backward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*net_flux 1.04e-12 -5.98e-12 -3.11e-13 -6.01e-12 -6.98e-08 -5.42e-12 nan nan nan nan
Out[95]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
Forward likelihoods 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Backward likelihoods 0.00224 0.0611 0.557 1 0.00604 0.443 0.387 0.00412 0.448
Delta G -15.1 -6.93 -1.45 -3.34e-06 -13.8 -2.02 -2.35 -13.6 -1.99
log Q_r -6.1 -1.99 0.221 1.61 -5.57 -0.411 -0.142 -5.49 -0.804
log K_eq -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
Delta G0 0 -2 -2 -4 0 -1 -2 0 0
logK - logQ 6.1 2.79 0.586 1.35e-06 5.57 0.815 0.949 5.49 0.804
logQ - logK -6.1 -2.79 -0.586 -1.35e-06 -5.57 -0.815 -0.949 -5.49 -0.804
Forward Log likelihoods 6.1 2.79 0.586 1.56e-06 5.11 0.815 0.949 5.49 0.804
Backward Log likelihoods -6.1 -2.79 -0.586 -1.56e-06 -5.11 -0.815 -0.949 -5.49 -0.804
Forward probabilities 0.505 0.0185 0.00203 0.00113 0.187 0.00256 0.00292 0.274 0.00253
Backward probabilities 2.54e-06 6.92e-05 0.00063 0.00113 6.84e-06 0.000501 0.000438 4.67e-06 0.000507
Net probabilities 0.505 0.0184 0.0014 3.54e-09 0.187 0.00205 0.00248 0.274 0.00202
Net likelihoods 446 16.3 1.24 3.12e-06 166 1.82 2.19 243 1.79
Forward rate 3.71 2.96 2.07 3.75 5.83e-06 2.5 3.77 2.32 2.52
Backward rate 0.00831 0.181 1.15 3.75 3.52e-08 1.11 1.46 0.00956 1.13
Thermodynamic driving force 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Net flux 3.7 2.78 0.916 5.86e-06 5.79e-06 1.39 2.31 2.31 1.39
Forward Entropy Production 0.345 0.0739 0.0126 0.00768 0.314 0.0153 0.0171 0.355 0.0151
Backward Entropy Production 3.27e-05 0.000663 0.00464 0.00768 8.13e-05 0.00381 0.00339 5.73e-05 0.00384
Reaction Entropy Production 0.345 0.0745 0.0172 0.0154 0.314 0.0191 0.0204 0.355 0.019
Microscopic Reaction Entropy Production Rate 1.28 0.219 0.0314 0.0577 1.83e-06 0.0423 0.0692 0.822 0.0424
Microscopic Reaction Entropy Production Net Flux 1.28 0.207 0.0158 9e-08 1.82e-06 0.0265 0.0472 0.819 0.0264
Microscopic Reaction Entropy Production Net Flux Difference 1.28 0.204 0.00729 1.2e-13 1.82e-06 0.0159 0.0315 0.819 0.0157
Total Entropy Production 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18
Total Microscopic Entropy Production Rate 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42
Macroscopic Reaction Entropy Production Net Flux 0.796 0.172 0.0398 0.0354 0.724 0.044 0.0472 0.819 0.0438
Macroscopic Reaction Entropy Production Net Flux Difference 0.796 0.169 0.0184 4.72e-08 0.724 0.0264 0.0315 0.819 0.026
Total Macroscopic Entropy Production Net Flux 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72
Total Macroscopic Entropy Production Net Flux Difference 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61

In [73]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')

reaction_data = reactions[obj]['Net flux'].to_dict()
metabolite_data = metab[obj]['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[73]:

Maximize macroscopic entropy production net flux for the ABC model

$$ \begin{array}{ll} \underset{\vec{\bf r}_+,\vec{\bf r}_-,\vec{\bf c}}{\mbox{maximize}} & - \sum_j\left({\mathscr P}_{+j}\log({\mathscr P}_{+j}) + {\mathscr P}_{-j}\log({\mathscr P}_{-j})\right)\cdot v_{growth} \\ \mbox{subject to} & S\cdot(\vec{\bf r}_+-\vec{\bf r}_-) = 0 \\ &\log\vec{\bf r}_+ -\log\vec{\bf r}_-= -\frac{1}{RT}S^T\cdot\vec{\mu}^0 - S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_- = \frac{1}{RT}S^T\cdot\vec{\mu}^0 + S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_+ -\log\vec{\bf L}_- \\ & \vec{v}_{lower}(L_+) \leq \vec{\bf r}_+ -\vec{\bf r}_- \leq \vec{v}_{upper}(L_+) \\ & \vec{\bf r}_+ \geq 0 \\ & \vec{\bf r}_- \geq 0 \\ & \log \left[{\bf A}_{ext}\right] = \log \left[{\bf E}_{ext}\right] = \log c_{upper} \\ & \log \left[{\bf E}_{ext}\right] = \log \left[{\bf D}_{ext}\right] = \log c_{lower} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_A \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_B \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_C \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_D \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_E \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_F \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ \end{array} \\$$

Where

\begin{itemize} \item $\vec{\bf r}_+,\vec{\bf r}_-$ are decision variables representing the forward and backward rates, respectively. \item ${\mathscr P}_{+i},{\mathscr P}_{-i}$ are the normalized forward and backward thermodynamic driving forces $\frac{r_{+i}}{r_{-i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ and $\frac{r_{-i}}{r_{+i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ \item $\vec{\bf c}$ is a decision variable representing the chemical concentrations of each metabolite \item $S$ is the $m\times n$ stoichiometric matrix of representing $m$ metabolites and $n$ reactions of the model \item $\vec{\mu}^0$ is the vector of standard chemical potentials \item $L_+ = \frac{r_+}{r_-}$ \item $L_- = \frac{r_-}{r_+}$ \item $v_{lower}(L) =\min\left(-1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) + 1$ \item $v_{upper}(L) = \max\left(1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) - 1$ \end{itemize}

Decision variables are emphasized in bold.


In [96]:
obj = 'macro_maxent_production_net_flux'
def make_macro_maxent_production_net_flux_objective(fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U, biomass):
    def macro_maxent_production_net_flux(x):
        """Maximize product of macroscopic entropy production and net_flux of the ABC model"""
        log_c, \
        forward_rate, backward_rate, \
        log_Q, log_K, \
        forward_likelihood, backward_likelihood, \
        forward_probability, backward_probability, mu, \
        thermodynamic_driving_force, \
        net_flux = mentos.make_variables( x, fullS, mu0, deltaG0, R, T )
        f = -np.sum( np.log(forward_probability)*forward_probability*net_flux[biomass]
                    + np.log(backward_probability)*backward_probability*net_flux[biomass])
        g = np.concatenate((np.dot(S,net_flux),
                            np.log(forward_rate) - np.log(backward_rate) + log_Q - log_K,
                            [ log_c[A_ext] - np.log(c_U),                 # Creating a concentration gradient between A, E and D,F
                              log_c[E_ext] - np.log(c_U),
                              log_c[D_ext] - np.log(c_L),
                              log_c[F_ext] - np.log(c_L)],
                             [-mu[A] + mu[D_ext] + mu[F_ext],           # Energy sink constraint
                              -mu[B] + mu[D_ext] + mu[F_ext],
                              -mu[C] + mu[D_ext] + mu[F_ext],
                              -mu[D] + mu[D_ext] + mu[F_ext],
                              -mu[E] + mu[D_ext] + mu[F_ext],
                              -mu[F] + mu[D_ext] + mu[F_ext]],
    
                             [ mu[A] - mu[A_ext] - mu[E_ext],           # Energy barrier constraint
                               mu[B] - mu[A_ext] - mu[E_ext],
                               mu[C] - mu[A_ext] - mu[E_ext],
                               mu[D] - mu[A_ext] - mu[E_ext],
                               mu[E] - mu[A_ext] - mu[E_ext],
                               mu[F] - mu[A_ext] - mu[E_ext]],  
                            
                              np.minimum(-1, thermodynamic_driving_force)+ 1 -net_flux,
                               net_flux - np.maximum(1, thermodynamic_driving_force ) - 1))
        
        fail = 0
        return -f, g, fail
    return macro_maxent_production_net_flux
metab[obj], reactions[obj] = mentos.run_mentos(fullS, S, internal_mets, deltaG0, mu0, 
                                        c_L, c_U, v_L, v_U,
                                        initial_log_c=metab['convex_mentos']['Log Concentrations'].values, 
                                        initial_forward_rate=reactions['convex_mentos']['Forward rate'].values,
                                        initial_backward_rate=reactions['convex_mentos']['Backward rate'].values,
                                        obj=make_maxent_production_objective( fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U),
                                        biomass_rxn='R_8')
#metab[obj].to_csv('ABC_metab_{}.csv'.format(obj))
#reactions[obj].to_csv('ABC_reactions_{obj}.csv'.format(obj=obj))

#display(metab[obj].T)
#HTML(reactions[obj].T.to_html())
true_metab[obj] = pd.read_csv('ABC_metab_{}.csv'.format(obj), index_col=0).astype(np.float64)
true_reactions[obj] = pd.read_csv('ABC_reactions_{}.csv'.format(obj),index_col=0)

display(mentos.compare_frames(true_metab[obj], metab[obj]))
pd.testing.assert_frame_equal(true_metab[obj],metab[obj].astype(np.float64))
pd.testing.assert_frame_equal(true_reactions[obj],reactions[obj])


HTML(mentos.compare_frames(true_reactions[obj],reactions[obj]).to_html())


A B C D E F A_ext D_ext E_ext F_ext
Counts 1.35e+03 184 1.68e+03 1.46e+03 2.3e+03 13 6.02e+05 6 6.02e+05 6
Concentrations 2.24e-06 3.07e-07 2.79e-06 2.43e-06 3.82e-06 2.23e-08 0.001 1e-08 0.001 1e-08
Log Concentrations -13 -15 -12.8 -12.9 -12.5 -17.6 -6.91 -18.4 -6.91 -18.4
Standard Chemical potential 4 2 2 0 2 1 4 0 2 1
Chemical potential -28.2 -35.2 -29.7 -32.1 -28.9 -42.7 -13.1 -45.7 -15.1 -44.7
S*forward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*backward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*net_flux 1.04e-12 -5.98e-12 -3.11e-13 -6.01e-12 -6.98e-08 -5.42e-12 nan nan nan nan
Out[96]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
Forward likelihoods 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Backward likelihoods 0.00224 0.0611 0.557 1 0.00604 0.443 0.387 0.00412 0.448
Delta G -15.1 -6.93 -1.45 -3.34e-06 -13.8 -2.02 -2.35 -13.6 -1.99
log Q_r -6.1 -1.99 0.221 1.61 -5.57 -0.411 -0.142 -5.49 -0.804
log K_eq -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
Delta G0 0 -2 -2 -4 0 -1 -2 0 0
logK - logQ 6.1 2.79 0.586 1.35e-06 5.57 0.815 0.949 5.49 0.804
logQ - logK -6.1 -2.79 -0.586 -1.35e-06 -5.57 -0.815 -0.949 -5.49 -0.804
Forward Log likelihoods 6.1 2.79 0.586 1.56e-06 5.11 0.815 0.949 5.49 0.804
Backward Log likelihoods -6.1 -2.79 -0.586 -1.56e-06 -5.11 -0.815 -0.949 -5.49 -0.804
Forward probabilities 0.505 0.0185 0.00203 0.00113 0.187 0.00256 0.00292 0.274 0.00253
Backward probabilities 2.54e-06 6.92e-05 0.00063 0.00113 6.84e-06 0.000501 0.000438 4.67e-06 0.000507
Net probabilities 0.505 0.0184 0.0014 3.54e-09 0.187 0.00205 0.00248 0.274 0.00202
Net likelihoods 446 16.3 1.24 3.12e-06 166 1.82 2.19 243 1.79
Forward rate 3.71 2.96 2.07 3.75 5.83e-06 2.5 3.77 2.32 2.52
Backward rate 0.00831 0.181 1.15 3.75 3.52e-08 1.11 1.46 0.00956 1.13
Thermodynamic driving force 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Net flux 3.7 2.78 0.916 5.86e-06 5.79e-06 1.39 2.31 2.31 1.39
Forward Entropy Production 0.345 0.0739 0.0126 0.00768 0.314 0.0153 0.0171 0.355 0.0151
Backward Entropy Production 3.27e-05 0.000663 0.00464 0.00768 8.13e-05 0.00381 0.00339 5.73e-05 0.00384
Reaction Entropy Production 0.345 0.0745 0.0172 0.0154 0.314 0.0191 0.0204 0.355 0.019
Microscopic Reaction Entropy Production Rate 1.28 0.219 0.0314 0.0577 1.83e-06 0.0423 0.0692 0.822 0.0424
Microscopic Reaction Entropy Production Net Flux 1.28 0.207 0.0158 9e-08 1.82e-06 0.0265 0.0472 0.819 0.0264
Microscopic Reaction Entropy Production Net Flux Difference 1.28 0.204 0.00729 1.2e-13 1.82e-06 0.0159 0.0315 0.819 0.0157
Total Entropy Production 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18
Total Microscopic Entropy Production Rate 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42
Macroscopic Reaction Entropy Production Net Flux 0.796 0.172 0.0398 0.0354 0.724 0.044 0.0472 0.819 0.0438
Macroscopic Reaction Entropy Production Net Flux Difference 0.796 0.169 0.0184 4.72e-08 0.724 0.0264 0.0315 0.819 0.026
Total Macroscopic Entropy Production Net Flux 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72
Total Macroscopic Entropy Production Net Flux Difference 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61

In [76]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')

reaction_data = reactions[obj]['Net flux'].to_dict()
metabolite_data = metab[obj]['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[76]:

Maximize macroscopic entropy production net flux difference for the ABC model

$$ \begin{array}{ll} \underset{\vec{\bf r}_+,\vec{\bf r}_-,\vec{\bf c}}{\mbox{maximize}} & - \sum_j\left({\mathscr P}_{+j}\log({\mathscr P}_{+j}) - {\mathscr P}_{-j}\log({\mathscr P}_{-j})\right)\cdot v_{growth} \\ \mbox{subject to} & S\cdot(\vec{\bf r}_+-\vec{\bf r}_-) = 0 \\ &\log\vec{\bf r}_+ -\log\vec{\bf r}_-= -\frac{1}{RT}S^T\cdot\vec{\mu}^0 - S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_- = \frac{1}{RT}S^T\cdot\vec{\mu}^0 + S^T\cdot\log\vec{\bf c} \\ %% & \log\vec{\bf L}_+ -\log\vec{\bf L}_- \\ & \vec{v}_{lower}(L_+) \leq \vec{\bf r}_+ -\vec{\bf r}_- \leq \vec{v}_{upper}(L_+) \\ & \vec{\bf r}_+ \geq 0 \\ & \vec{\bf r}_- \geq 0 \\ & \log \left[{\bf A}_{ext}\right] = \log \left[{\bf E}_{ext}\right] = \log c_{upper} \\ & \log \left[{\bf E}_{ext}\right] = \log \left[{\bf D}_{ext}\right] = \log c_{lower} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_A \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_B \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_C \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_D \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_E \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ & \mu_{D_{ext}} + \mu_{F_{ext}} \leq \mu_F \leq \mu_{A_{ext}} + \mu_{E_{ext}} \\ \end{array} \\$$

Where

\begin{itemize} \item $\vec{\bf r}_+,\vec{\bf r}_-$ are decision variables representing the forward and backward rates, respectively. \item ${\mathscr P}_{+i},{\mathscr P}_{-i}$ are the normalized forward and backward thermodynamic driving forces $\frac{r_{+i}}{r_{-i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ and $\frac{r_{-i}}{r_{+i}}\left(\sum_j\frac{r_{+j}}{r_{-j}} + \frac{r_{-j}}{r_{+j}}\right)^{-1}$ \item $\vec{\bf c}$ is a decision variable representing the chemical concentrations of each metabolite \item $S$ is the $m\times n$ stoichiometric matrix of representing $m$ metabolites and $n$ reactions of the model \item $\vec{\mu}^0$ is the vector of standard chemical potentials \item $L_+ = \frac{r_+}{r_-}$ \item $L_- = \frac{r_-}{r_+}$ \item $v_{lower}(L) =\min\left(-1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) + 1$ \item $v_{upper}(L) = \max\left(1,\text{sign}(\log L)\cdot L^{\text{sign}(\log L)}\right) - 1$ \end{itemize}

Decision variables are emphasized in bold.


In [97]:
obj = 'macro_maxent_production_net_flux'
def make_macro_maxent_production_net_flux_diff_objective(fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U, biomass):
    def macro_maxent_production_net_flux_diff(x):
        """Maximize product of macroscopic entropy production and net_flux difference of the ABC model"""
        log_c, \
        forward_rate, backward_rate, \
        log_Q, log_K, \
        forward_likelihood, backward_likelihood, \
        forward_probability, backward_probability, mu, \
        thermodynamic_driving_force, \
        net_flux = mentos.make_variables( x, fullS, mu0, deltaG0, R, T )
        f = -np.sum( np.log(forward_probability)*forward_probability*net_flux[biomass]
                    - np.log(backward_probability)*backward_probability*net_flux[biomass])
        g = np.concatenate((np.dot(S,net_flux),
                            np.log(forward_rate) - np.log(backward_rate) + log_Q - log_K,
                            [ log_c[A_ext] - np.log(c_U),                 # Creating a concentration gradient between A, E and D,F
                              log_c[E_ext] - np.log(c_U),
                              log_c[D_ext] - np.log(c_L),
                              log_c[F_ext] - np.log(c_L)],
                             [-mu[A] + mu[D_ext] + mu[F_ext],           # Energy sink constraint
                              -mu[B] + mu[D_ext] + mu[F_ext],
                              -mu[C] + mu[D_ext] + mu[F_ext],
                              -mu[D] + mu[D_ext] + mu[F_ext],
                              -mu[E] + mu[D_ext] + mu[F_ext],
                              -mu[F] + mu[D_ext] + mu[F_ext]],
    
                             [ mu[A] - mu[A_ext] - mu[E_ext],           # Energy barrier constraint
                               mu[B] - mu[A_ext] - mu[E_ext],
                               mu[C] - mu[A_ext] - mu[E_ext],
                               mu[D] - mu[A_ext] - mu[E_ext],
                               mu[E] - mu[A_ext] - mu[E_ext],
                               mu[F] - mu[A_ext] - mu[E_ext]],  
                            
                              np.minimum(-1, thermodynamic_driving_force)+ 1 -net_flux,
                               net_flux - np.maximum(1, thermodynamic_driving_force ) - 1))
        
        fail = 0
        return -f, g, fail
    return macro_maxent_production_net_flux_diff
metab[obj], reactions[obj] = mentos.run_mentos(fullS, S, internal_mets, deltaG0, mu0, 
                                        c_L, c_U, v_L, v_U,
                                        initial_log_c=metab['convex_mentos']['Log Concentrations'].values, 
                                        initial_forward_rate=reactions['convex_mentos']['Forward rate'].values,
                                        initial_backward_rate=reactions['convex_mentos']['Backward rate'].values,
                                        obj=make_maxent_production_objective( fullS, S, mu0, deltaG0, R, T, c_L, c_U,v_L, v_U),
                                        biomass_rxn='R_8')
#metab[obj].to_csv('ABC_metab_{}.csv'.format(obj))
#reactions[obj].to_csv('ABC_reactions_{obj}.csv'.format(obj=obj))

#display(metab[obj].T)
#HTML(reactions[obj].T.to_html())
true_metab[obj] = pd.read_csv('ABC_metab_{}.csv'.format(obj), index_col=0).astype(np.float64)
true_reactions[obj] = pd.read_csv('ABC_reactions_{}.csv'.format(obj),index_col=0)

display(mentos.compare_frames(true_metab[obj], metab[obj]))
pd.testing.assert_frame_equal(true_metab[obj],metab[obj].astype(np.float64))
pd.testing.assert_frame_equal(true_reactions[obj],reactions[obj])


HTML(mentos.compare_frames(true_reactions[obj],reactions[obj]).to_html())


A B C D E F A_ext D_ext E_ext F_ext
Counts 1.35e+03 184 1.68e+03 1.46e+03 2.3e+03 13 6.02e+05 6 6.02e+05 6
Concentrations 2.24e-06 3.07e-07 2.79e-06 2.43e-06 3.82e-06 2.23e-08 0.001 1e-08 0.001 1e-08
Log Concentrations -13 -15 -12.8 -12.9 -12.5 -17.6 -6.91 -18.4 -6.91 -18.4
Standard Chemical potential 4 2 2 0 2 1 4 0 2 1
Chemical potential -28.2 -35.2 -29.7 -32.1 -28.9 -42.7 -13.1 -45.7 -15.1 -44.7
S*forward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*backward_rate -1.32 -5.79 0.797 8.96 -3.75 -0.0223 nan nan nan nan
S*net_flux 1.04e-12 -5.98e-12 -3.11e-13 -6.01e-12 -6.98e-08 -5.42e-12 nan nan nan nan
Out[97]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
Forward likelihoods 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Backward likelihoods 0.00224 0.0611 0.557 1 0.00604 0.443 0.387 0.00412 0.448
Delta G -15.1 -6.93 -1.45 -3.34e-06 -13.8 -2.02 -2.35 -13.6 -1.99
log Q_r -6.1 -1.99 0.221 1.61 -5.57 -0.411 -0.142 -5.49 -0.804
log K_eq -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
Delta G0 0 -2 -2 -4 0 -1 -2 0 0
logK - logQ 6.1 2.79 0.586 1.35e-06 5.57 0.815 0.949 5.49 0.804
logQ - logK -6.1 -2.79 -0.586 -1.35e-06 -5.57 -0.815 -0.949 -5.49 -0.804
Forward Log likelihoods 6.1 2.79 0.586 1.56e-06 5.11 0.815 0.949 5.49 0.804
Backward Log likelihoods -6.1 -2.79 -0.586 -1.56e-06 -5.11 -0.815 -0.949 -5.49 -0.804
Forward probabilities 0.505 0.0185 0.00203 0.00113 0.187 0.00256 0.00292 0.274 0.00253
Backward probabilities 2.54e-06 6.92e-05 0.00063 0.00113 6.84e-06 0.000501 0.000438 4.67e-06 0.000507
Net probabilities 0.505 0.0184 0.0014 3.54e-09 0.187 0.00205 0.00248 0.274 0.00202
Net likelihoods 446 16.3 1.24 3.12e-06 166 1.82 2.19 243 1.79
Forward rate 3.71 2.96 2.07 3.75 5.83e-06 2.5 3.77 2.32 2.52
Backward rate 0.00831 0.181 1.15 3.75 3.52e-08 1.11 1.46 0.00956 1.13
Thermodynamic driving force 446 16.4 1.8 1 166 2.26 2.58 243 2.23
Net flux 3.7 2.78 0.916 5.86e-06 5.79e-06 1.39 2.31 2.31 1.39
Forward Entropy Production 0.345 0.0739 0.0126 0.00768 0.314 0.0153 0.0171 0.355 0.0151
Backward Entropy Production 3.27e-05 0.000663 0.00464 0.00768 8.13e-05 0.00381 0.00339 5.73e-05 0.00384
Reaction Entropy Production 0.345 0.0745 0.0172 0.0154 0.314 0.0191 0.0204 0.355 0.019
Microscopic Reaction Entropy Production Rate 1.28 0.219 0.0314 0.0577 1.83e-06 0.0423 0.0692 0.822 0.0424
Microscopic Reaction Entropy Production Net Flux 1.28 0.207 0.0158 9e-08 1.82e-06 0.0265 0.0472 0.819 0.0264
Microscopic Reaction Entropy Production Net Flux Difference 1.28 0.204 0.00729 1.2e-13 1.82e-06 0.0159 0.0315 0.819 0.0157
Total Entropy Production 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18 1.18
Total Microscopic Entropy Production Rate 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42 2.42
Macroscopic Reaction Entropy Production Net Flux 0.796 0.172 0.0398 0.0354 0.724 0.044 0.0472 0.819 0.0438
Macroscopic Reaction Entropy Production Net Flux Difference 0.796 0.169 0.0184 4.72e-08 0.724 0.0264 0.0315 0.819 0.026
Total Macroscopic Entropy Production Net Flux 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72 2.72
Total Macroscopic Entropy Production Net Flux Difference 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61 2.61

In [98]:
#import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')

reaction_data = reactions[obj]['Net flux'].to_dict()
metabolite_data = metab[obj]['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[98]:

Comparing the predictions of alternative objective functions


In [113]:
import os, re
nonchar = re.compile('[^a-zA-Z0-9]')
for obj in reactions:
    print(obj)
    if not os.path.exists(obj):
        os.makedirs(obj)
    for col in reactions[obj].columns:
        filename = nonchar.sub('_',col)
        print("\t{}".format(filename))
        reactions[obj][col].to_csv('{obj}/reaction_{col}.tsv'.format(obj=obj,col=filename), sep='\t', header=True)


micro_maxent_production_rate
	Forward_likelihoods
	Backward_likelihoods
	Delta_G
	log_Q_r
	log_K_eq
	Delta_G0
	logK___logQ
	logQ___logK
	Forward_Log_likelihoods
	Backward_Log_likelihoods
	Forward_probabilities
	Backward_probabilities
	Net_probabilities
	Net_likelihoods
	Forward_rate
	Backward_rate
	Thermodynamic_driving_force
	Net_flux
	Forward_Entropy_Production
	Backward_Entropy_Production
	Reaction_Entropy_Production
	Microscopic_Reaction_Entropy_Production_Rate
	Microscopic_Reaction_Entropy_Production_Net_Flux
	Microscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Entropy_Production
	Total_Microscopic_Entropy_Production_Rate
	Macroscopic_Reaction_Entropy_Production_Net_Flux
	Macroscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Macroscopic_Entropy_Production_Net_Flux
	Total_Macroscopic_Entropy_Production_Net_Flux_Difference
minent_production
	Forward_likelihoods
	Backward_likelihoods
	Delta_G
	log_Q_r
	log_K_eq
	Delta_G0
	logK___logQ
	logQ___logK
	Forward_Log_likelihoods
	Backward_Log_likelihoods
	Forward_probabilities
	Backward_probabilities
	Net_probabilities
	Net_likelihoods
	Forward_rate
	Backward_rate
	Thermodynamic_driving_force
	Net_flux
	Forward_Entropy_Production
	Backward_Entropy_Production
	Reaction_Entropy_Production
	Microscopic_Reaction_Entropy_Production_Rate
	Microscopic_Reaction_Entropy_Production_Net_Flux
	Microscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Entropy_Production
	Total_Microscopic_Entropy_Production_Rate
	Macroscopic_Reaction_Entropy_Production_Net_Flux
	Macroscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Macroscopic_Entropy_Production_Net_Flux
	Total_Macroscopic_Entropy_Production_Net_Flux_Difference
micro_maxent_production_net_flux
	Forward_likelihoods
	Backward_likelihoods
	Delta_G
	log_Q_r
	log_K_eq
	Delta_G0
	logK___logQ
	logQ___logK
	Forward_Log_likelihoods
	Backward_Log_likelihoods
	Forward_probabilities
	Backward_probabilities
	Net_probabilities
	Net_likelihoods
	Forward_rate
	Backward_rate
	Thermodynamic_driving_force
	Net_flux
	Forward_Entropy_Production
	Backward_Entropy_Production
	Reaction_Entropy_Production
	Microscopic_Reaction_Entropy_Production_Rate
	Microscopic_Reaction_Entropy_Production_Net_Flux
	Microscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Entropy_Production
	Total_Microscopic_Entropy_Production_Rate
	Macroscopic_Reaction_Entropy_Production_Net_Flux
	Macroscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Macroscopic_Entropy_Production_Net_Flux
	Total_Macroscopic_Entropy_Production_Net_Flux_Difference
maxent_production
	Forward_likelihoods
	Backward_likelihoods
	Delta_G
	log_Q_r
	log_K_eq
	Delta_G0
	logK___logQ
	logQ___logK
	Forward_Log_likelihoods
	Backward_Log_likelihoods
	Forward_probabilities
	Backward_probabilities
	Net_probabilities
	Net_likelihoods
	Forward_rate
	Backward_rate
	Thermodynamic_driving_force
	Net_flux
	Forward_Entropy_Production
	Backward_Entropy_Production
	Reaction_Entropy_Production
	Microscopic_Reaction_Entropy_Production_Rate
	Microscopic_Reaction_Entropy_Production_Net_Flux
	Microscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Entropy_Production
	Total_Microscopic_Entropy_Production_Rate
	Macroscopic_Reaction_Entropy_Production_Net_Flux
	Macroscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Macroscopic_Entropy_Production_Net_Flux
	Total_Macroscopic_Entropy_Production_Net_Flux_Difference
macro_maxent_production_net_flux
	Forward_likelihoods
	Backward_likelihoods
	Delta_G
	log_Q_r
	log_K_eq
	Delta_G0
	logK___logQ
	logQ___logK
	Forward_Log_likelihoods
	Backward_Log_likelihoods
	Forward_probabilities
	Backward_probabilities
	Net_probabilities
	Net_likelihoods
	Forward_rate
	Backward_rate
	Thermodynamic_driving_force
	Net_flux
	Forward_Entropy_Production
	Backward_Entropy_Production
	Reaction_Entropy_Production
	Microscopic_Reaction_Entropy_Production_Rate
	Microscopic_Reaction_Entropy_Production_Net_Flux
	Microscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Entropy_Production
	Total_Microscopic_Entropy_Production_Rate
	Macroscopic_Reaction_Entropy_Production_Net_Flux
	Macroscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Macroscopic_Entropy_Production_Net_Flux
	Total_Macroscopic_Entropy_Production_Net_Flux_Difference
micro_maxent_production_net_flux_diff
	Forward_likelihoods
	Backward_likelihoods
	Delta_G
	log_Q_r
	log_K_eq
	Delta_G0
	logK___logQ
	logQ___logK
	Forward_Log_likelihoods
	Backward_Log_likelihoods
	Forward_probabilities
	Backward_probabilities
	Net_probabilities
	Net_likelihoods
	Forward_rate
	Backward_rate
	Thermodynamic_driving_force
	Net_flux
	Forward_Entropy_Production
	Backward_Entropy_Production
	Reaction_Entropy_Production
	Microscopic_Reaction_Entropy_Production_Rate
	Microscopic_Reaction_Entropy_Production_Net_Flux
	Microscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Entropy_Production
	Total_Microscopic_Entropy_Production_Rate
	Macroscopic_Reaction_Entropy_Production_Net_Flux
	Macroscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Macroscopic_Entropy_Production_Net_Flux
	Total_Macroscopic_Entropy_Production_Net_Flux_Difference
convex_mentos
	Forward_likelihoods
	Backward_likelihoods
	Delta_G
	log_Q_r
	log_K_eq
	Delta_G0
	logK___logQ
	logQ___logK
	Forward_Log_likelihoods
	Backward_Log_likelihoods
	Forward_probabilities
	Backward_probabilities
	Net_probabilities
	Net_likelihoods
	Forward_rate
	Backward_rate
	Thermodynamic_driving_force
	Net_flux
	Forward_Entropy_Production
	Backward_Entropy_Production
	Reaction_Entropy_Production
	Microscopic_Reaction_Entropy_Production_Rate
	Microscopic_Reaction_Entropy_Production_Net_Flux
	Microscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Entropy_Production
	Total_Microscopic_Entropy_Production_Rate
	Macroscopic_Reaction_Entropy_Production_Net_Flux
	Macroscopic_Reaction_Entropy_Production_Net_Flux_Difference
	Total_Macroscopic_Entropy_Production_Net_Flux
	Total_Macroscopic_Entropy_Production_Net_Flux_Difference

In [110]:
pd.Series.to_csv?

In [112]:
import os, re
nonchar = re.compile('[^a-zA-Z0-9]')
for obj in metab:
    print(obj)
    if not os.path.exists(obj):
        os.makedirs(obj)
    for col in metab[obj].columns:
        filename = nonchar.sub('_',col)
        print("\t{}".format(filename))
        metab[obj][col].to_csv('{obj}/metab_{col}.tsv'.format(obj=obj,col=filename), sep='\t',header=True)


micro_maxent_production_rate
	Counts
	Concentrations
	Log_Concentrations
	Standard_Chemical_potential
	Chemical_potential
	S_forward_rate
	S_backward_rate
	S_net_flux
minent_production
	Counts
	Concentrations
	Log_Concentrations
	Standard_Chemical_potential
	Chemical_potential
	S_forward_rate
	S_backward_rate
	S_net_flux
micro_maxent_production_net_flux
	Counts
	Concentrations
	Log_Concentrations
	Standard_Chemical_potential
	Chemical_potential
	S_forward_rate
	S_backward_rate
	S_net_flux
maxent_production
	Counts
	Concentrations
	Log_Concentrations
	Standard_Chemical_potential
	Chemical_potential
	S_forward_rate
	S_backward_rate
	S_net_flux
macro_maxent_production_net_flux
	Counts
	Concentrations
	Log_Concentrations
	Standard_Chemical_potential
	Chemical_potential
	S_forward_rate
	S_backward_rate
	S_net_flux
micro_maxent_production_net_flux_diff
	Counts
	Concentrations
	Log_Concentrations
	Standard_Chemical_potential
	Chemical_potential
	S_forward_rate
	S_backward_rate
	S_net_flux
convex_mentos
	Counts
	Concentrations
	Log_Concentrations
	Standard_Chemical_potential
	Chemical_potential
	S_forward_rate
	S_backward_rate
	S_net_flux

In [80]:
pmetabolites = pd.Panel.from_dict({'micro_maxent_production_net_flux':metab['micro_maxent_production_net_flux'],
                                 'macro_maxent_production_net_flux':metab['macro_maxent_production_net_flux']},orient='minor')
preactions = pd.Panel.from_dict({'micro_maxent_production_net_flux':reactions['micro_maxent_production_net_flux'],
                                 'macro_maxent_production_net_flux':reactions['macro_maxent_production_net_flux']},orient='minor')
HTML(preactions.swapaxes(1,0).to_frame(filter_observations=False).xs(
                                     'Net flux',level='major', drop_level=False).to_html())


Out[80]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
major minor
Net flux macro_maxent_production_net_flux 28.8 23.1 5.63 23.1 23.1 1.05e-14 5.63 51.9 3.74e-12
micro_maxent_production_net_flux 31.7 27.2 4.53 21.2 21.2 2.97 7.51 49.9 2.97

In [81]:
reactions = pd.Panel.from_dict(reactions,orient='minor')
HTML(preactions.swapaxes(1,0).to_frame(filter_observations=False).to_html())


Out[81]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
major minor
Forward likelihoods macro_maxent_production_net_flux 446 22.1 4.77 22.1 199 1 4.63 50.9 1
micro_maxent_production_net_flux 446 26.2 3.53 20.2 199 1.97 6.51 48.9 1.97
Backward likelihoods macro_maxent_production_net_flux 0.00224 0.0452 0.21 0.0452 0.00502 1 0.216 0.0197 1
micro_maxent_production_net_flux 0.00224 0.0382 0.283 0.0495 0.00502 0.507 0.154 0.0204 0.507
Delta G macro_maxent_production_net_flux -15.1 -7.68 -3.87 -7.68 -13.1 -4.94 -3.8 -9.74 0.000101
micro_maxent_production_net_flux -15.1 -8.09 -3.13 -7.45 -13.1 -1.68 -4.64 -9.64 -1.68
log Q_r macro_maxent_production_net_flux -6.1 -2.29 -0.756 -1.48 -5.29 -1.59 -0.727 -3.93 4.09e-05
micro_maxent_production_net_flux -6.1 -2.46 -0.456 -1.39 -5.29 -0.275 -1.07 -3.89 -0.678
log K_eq macro_maxent_production_net_flux -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
micro_maxent_production_net_flux -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
Delta G0 macro_maxent_production_net_flux 0 -2 -2 -4 0 -1 -2 0 0
micro_maxent_production_net_flux 0 -2 -2 -4 0 -1 -2 0 0
logK - logQ macro_maxent_production_net_flux 6.1 3.1 1.56 3.1 5.29 1.99 1.53 3.93 -4.09e-05
micro_maxent_production_net_flux 6.1 3.26 1.26 3.01 5.29 0.678 1.87 3.89 0.678
logQ - logK macro_maxent_production_net_flux -6.1 -3.1 -1.56 -3.1 -5.29 -1.99 -1.53 -3.93 4.09e-05
micro_maxent_production_net_flux -6.1 -3.26 -1.26 -3.01 -5.29 -0.678 -1.87 -3.89 -0.678
Forward Log likelihoods macro_maxent_production_net_flux 6.1 3.1 1.56 3.1 5.29 2.78e-09 1.53 3.93 5.92e-13
micro_maxent_production_net_flux 6.1 3.26 1.26 3.01 5.29 0.678 1.87 3.89 0.678
Backward Log likelihoods macro_maxent_production_net_flux -6.1 -3.1 -1.56 -3.1 -5.29 -2.78e-09 -1.53 -3.93 -5.92e-13
micro_maxent_production_net_flux -6.1 -3.26 -1.26 -3.01 -5.29 -0.678 -1.87 -3.89 -0.678
Forward probabilities macro_maxent_production_net_flux 0.591 0.0293 0.00632 0.0293 0.264 0.00133 0.00614 0.0674 0.00133
micro_maxent_production_net_flux 0.59 0.0346 0.00467 0.0267 0.263 0.00261 0.0086 0.0647 0.00261
Backward probabilities macro_maxent_production_net_flux 2.97e-06 5.99e-05 0.000278 5.99e-05 6.65e-06 0.00133 0.000286 2.61e-05 0.00133
micro_maxent_production_net_flux 2.96e-06 5.06e-05 0.000374 6.54e-05 6.64e-06 0.000671 0.000203 2.7e-05 0.000671
Net probabilities macro_maxent_production_net_flux 0.591 0.0293 0.00605 0.0293 0.264 7.38e-12 0.00586 0.0674 1.57e-15
micro_maxent_production_net_flux 0.59 0.0345 0.0043 0.0267 0.263 0.00193 0.0084 0.0647 0.00193
Net likelihoods macro_maxent_production_net_flux 446 22.1 4.56 22.1 199 5.57e-09 4.42 50.8 1.18e-12
micro_maxent_production_net_flux 446 26.1 3.25 20.2 199 1.46 6.35 48.9 1.46
Forward rate macro_maxent_production_net_flux 28.8 24.2 7.13 24.2 23.2 3.78e-06 7.18 52.9 6.32
micro_maxent_production_net_flux 31.8 28.2 6.32 22.3 21.3 6.03 8.87 51 6.03
Backward rate macro_maxent_production_net_flux 0.0646 1.09 1.49 1.09 0.117 3.78e-06 1.55 1.04 6.32
micro_maxent_production_net_flux 0.0712 1.08 1.79 1.1 0.107 3.06 1.36 1.04 3.06
Thermodynamic driving force macro_maxent_production_net_flux 446 22.1 4.77 22.1 199 1 4.63 50.9 1
micro_maxent_production_net_flux 446 26.2 3.53 20.2 199 1.97 6.51 48.9 1.97
Net flux macro_maxent_production_net_flux 28.8 23.1 5.63 23.1 23.1 1.05e-14 5.63 51.9 3.74e-12
micro_maxent_production_net_flux 31.7 27.2 4.53 21.2 21.2 2.97 7.51 49.9 2.97
Forward Entropy Production macro_maxent_production_net_flux 0.311 0.103 0.032 0.103 0.352 0.00878 0.0313 0.182 0.00878
micro_maxent_production_net_flux 0.311 0.116 0.0251 0.0968 0.351 0.0155 0.0409 0.177 0.0155
Backward Entropy Production macro_maxent_production_net_flux 3.78e-05 0.000583 0.00227 0.000583 7.93e-05 0.00878 0.00233 0.000275 0.00878
micro_maxent_production_net_flux 3.77e-05 0.0005 0.00295 0.00063 7.91e-05 0.0049 0.00173 0.000284 0.0049
Reaction Entropy Production macro_maxent_production_net_flux 0.311 0.104 0.0343 0.104 0.352 0.0176 0.0336 0.182 0.0176
micro_maxent_production_net_flux 0.311 0.117 0.028 0.0974 0.351 0.0204 0.0426 0.177 0.0204
Microscopic Reaction Entropy Production Rate macro_maxent_production_net_flux 8.95 2.51 0.232 2.51 8.17 6.64e-08 0.228 9.62 0.111
micro_maxent_production_net_flux 9.89 3.29 0.164 2.16 7.49 0.109 0.365 9.03 0.109
Microscopic Reaction Entropy Production Net Flux macro_maxent_production_net_flux 8.93 2.41 0.193 2.41 8.13 1.85e-16 0.189 9.44 6.57e-14
micro_maxent_production_net_flux 9.86 3.17 0.127 2.07 7.46 0.0606 0.32 8.86 0.0606
Microscopic Reaction Entropy Production Net Flux Difference macro_maxent_production_net_flux 8.93 2.38 0.168 2.38 8.13 4.37e-25 0.163 9.42 3.3e-26
micro_maxent_production_net_flux 9.86 3.15 0.1 2.04 7.45 0.0315 0.294 8.83 0.0315
Total Entropy Production macro_maxent_production_net_flux 1.16 1.16 1.16 1.16 1.16 1.16 1.16 1.16 1.16
micro_maxent_production_net_flux 1.17 1.17 1.17 1.17 1.17 1.17 1.17 1.17 1.17
Total Microscopic Entropy Production Rate macro_maxent_production_net_flux 31.7 31.7 31.7 31.7 31.7 31.7 31.7 31.7 31.7
micro_maxent_production_net_flux 32 32 32 32 32 32 32 32 32
Macroscopic Reaction Entropy Production Net Flux macro_maxent_production_net_flux 16.1 5.4 1.78 5.4 18.2 0.911 1.74 9.44 0.911
micro_maxent_production_net_flux 15.5 5.83 1.4 4.86 17.5 1.02 2.13 8.86 1.02
Macroscopic Reaction Entropy Production Net Flux Difference macro_maxent_production_net_flux 16.1 5.34 1.54 5.34 18.2 2.15e-09 1.5 9.42 4.58e-13
micro_maxent_production_net_flux 15.5 5.78 1.1 4.8 17.5 0.529 1.96 8.83 0.529
Total Macroscopic Entropy Production Net Flux macro_maxent_production_net_flux 59.9 59.9 59.9 59.9 59.9 59.9 59.9 59.9 59.9
micro_maxent_production_net_flux 58.2 58.2 58.2 58.2 58.2 58.2 58.2 58.2 58.2
Total Macroscopic Entropy Production Net Flux Difference macro_maxent_production_net_flux 57.5 57.5 57.5 57.5 57.5 57.5 57.5 57.5 57.5
micro_maxent_production_net_flux 56.6 56.6 56.6 56.6 56.6 56.6 56.6 56.6 56.6

In [82]:
HTML(pmetabolites.swapaxes(1,0).to_frame(filter_observations=False).to_html())


Out[82]:
A B C D E F A_ext D_ext E_ext F_ext
major minor
Counts macro_maxent_production_net_flux 1.35e+03 136 633 306 3.02e+03 6 6.02e+05 6 6.02e+05 6
micro_maxent_production_net_flux 1.35e+03 115 855 294 3.02e+03 11 6.02e+05 6 6.02e+05 6
Concentrations macro_maxent_production_net_flux 2.24e-06 2.27e-07 1.05e-06 5.09e-07 5.02e-06 1e-08 0.001 1e-08 0.001 1e-08
micro_maxent_production_net_flux 2.24e-06 1.92e-07 1.42e-06 4.89e-07 5.02e-06 1.97e-08 0.001 1e-08 0.001 1e-08
Log Concentrations macro_maxent_production_net_flux -13 -15.3 -13.8 -14.5 -12.2 -18.4 -6.91 -18.4 -6.91 -18.4
micro_maxent_production_net_flux -13 -15.5 -13.5 -14.5 -12.2 -17.7 -6.91 -18.4 -6.91 -18.4
Standard Chemical potential macro_maxent_production_net_flux 4 2 2 0 2 1 4 0 2 1
micro_maxent_production_net_flux 4 2 2 0 2 1 4 0 2 1
Chemical potential macro_maxent_production_net_flux -28.2 -35.9 -32.1 -35.9 -28.2 -44.7 -13.1 -45.7 -15.1 -44.7
micro_maxent_production_net_flux -28.2 -36.3 -31.4 -36 -28.2 -43 -13.1 -45.7 -15.1 -44.7
S*forward_rate macro_maxent_production_net_flux -2.52 -7.81e-06 -0.0566 2.7 -0.978 -6.32 nan nan nan nan
micro_maxent_production_net_flux -2.8 -6.15 3.49 2.53 -0.997 6.46e-13 nan nan nan nan
S*backward_rate macro_maxent_production_net_flux -2.52 -7.81e-06 -0.0566 2.7 -0.978 -6.32 nan nan nan nan
micro_maxent_production_net_flux -2.8 -6.15 3.49 2.53 -0.997 6.46e-13 nan nan nan nan
S*net_flux macro_maxent_production_net_flux -1.74e-11 1.11e-10 -4.07e-12 -2.18e-10 5.58e-11 -3.73e-12 nan nan nan nan
micro_maxent_production_net_flux -3.55e-15 -7.11e-15 1.78e-15 7.11e-15 -3.55e-15 0 nan nan nan nan

Note that


In [158]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')
reaction_data = reactions['micro_maxent_production_rate']['Net flux'].to_dict()
metabolite_data = metab['micro_maxent_production_rate']['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[158]:

In [231]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')
reaction_data = reactions['analytic_mentos']['Net flux'].to_dict()
metabolite_data = metab['convex_mentos']['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[231]:

In [168]:
import escher,os
abc_dir = 'Mentos/ABC'
map_name = os.path.join(abc_dir,'ABC_map.json')
model_name = os.path.join(abc_dir,'ABC_model.json')

reaction_data = reactions['macro_maxent_production_net_flux']['Delta G'].to_dict()
metabolite_data = metab['macro_maxent_production_net_flux']['Chemical potential'].to_dict()
builder = escher.Builder(map_json=map_name, model_json=model_name, 
                         reaction_data=reaction_data,metabolite_data=metabolite_data)
builder.display_in_notebook(menu='zoom')


Out[168]:

In [242]:
pmetabolites = pd.Panel.from_dict(metabolites,orient='minor')
preactions = pd.Panel.from_dict(reactions, orient='minor')
display(preactions['Forward likelihoods'].add_prefix('L_f '))
display(preactions['Backward likelihoods'].add_prefix('L_b '))
display(preactions['Entropy'].add_prefix('Entropy '))
display(pmetabolites['Concentrations'].add_prefix('Conc '))
display(pmetabolites['Counts'].add_prefix('Count '))


L_f L1 L_f L2 L_f MaxEnt L_f MaxEntL2
R_1 119 97.4 63 63.2
R_2 53.1 43.2 56.6 56.6
R_3 1 2.25 7.28 7.21
R_4 1 10.4 51 50.8
R_5 1 10.4 51 50.8
R_6 1 2.04 3.48 3.45
R_7 1 4.6 9.95 9.99
R_8 4.22e+03 497 110 110
R_9 1 2.04 3.48 3.45
L_b L1 L_b L2 L_b MaxEnt L_b MaxEntL2
R_1 0.00841 0.0103 0.503 0.32
R_2 0.0188 0.0231 0.615 0.406
R_3 1 0.443 0.799 0.609
R_4 1 0.0962 0.8 0.58
R_5 1 0.0962 0.8 0.58
R_6 1 0.491 0.603 0.46
R_7 1 0.218 0.597 0.395
R_8 0.000237 0.00201 0.333 0.238
R_9 1 0.491 0.603 0.46
Entropy L1 Entropy L2 Entropy MaxEnt Entropy MaxEntL2
R_1 -569 -446 -260 -261
R_2 -211 -163 -228 -228
R_3 -1.66e-19 -1.47 -14.3 -13.9
R_4 -7.01e-18 -24.1 -200 -199
R_5 -2.52e-18 -24.1 -200 -199
R_6 -1.37e-17 -1.1 -4.03 -3.93
R_7 -2.95e-18 -6.68 -22.6 -22.6
R_8 -3.52e+04 -3.09e+03 -517 -519
R_9 -6.79e-18 -1.1 -4.03 -3.93
Conc L1 Conc L2 Conc MaxEnt Conc MaxEntL2
A 8.41e-06 1.03e-05 1.59e-05 1.58e-05
B 3.55e-07 5.32e-07 6.29e-07 6.26e-07
C 1.88e-05 1.02e-05 4.89e-06 4.92e-06
D 4.22e-05 4.97e-06 1.1e-06 1.1e-06
E 0.001 9.62e-05 1.96e-05 1.97e-05
F 1e-08 2.04e-08 3.48e-08 3.45e-08
A_ext 0.001 0.001 0.001 0.001
D_ext 1e-08 1e-08 1e-08 1e-08
E_ext 0.001 0.001 0.001 0.001
F_ext 1e-08 1e-08 1e-08 1e-08
Count L1 Count L2 Count MaxEnt Count MaxEntL2
A 5061 6179 9565 9534
B 213 320 378 377
C 11341 6140 2945 2962
D 25413 2993 663 664
E 602199 57912 11802 11848
F 6 12 20 20
A_ext 602199 602199 602200 602200
D_ext 6 6 6 6
E_ext 602200 602199 602200 602200
F_ext 6 6 6 6

In [151]:
pmetabolites = pd.Panel.from_dict(metab,orient='minor')
preactions = pd.Panel.from_dict(reactions,orient='minor')
HTML(preactions.swapaxes(1,0).to_frame(filter_observations=False).to_html())


Out[151]:
R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 R_9
major minor
Forward likelihoods analytic_mentos 12.9 37.5 10.6 41.3 41.3 14 9.88 369 14
macro_maxent_production_net_flux 65.7 68.6 61.7 69.9 69.9 1.05 1.73 71.5 64
macro_maxent_production_net_flux_diff 65.7 68.6 61.7 69.9 69.9 1.05 1.73 71.5 64
macro_maxent_production_rate 65.7 68.6 61.7 69.9 69.9 1.05 1.73 71.5 64
maxent_production 66 69.2 61.4 69.7 69.7 64.5 1.74 71.2 1.01
micro_maxent_production_net_flux 88.1 87.4 2.02 41.3 41.3 1 30.5 92.5 1
micro_maxent_production_net_flux_diff 86.3 85.5 2.23 42.5 42.5 1.09 28.4 91.8 1.09
micro_maxent_production_rate 614 40.9 3.07 964 974 1 122 2.18 1
minent_production 1.09 3.55 0.0325 0.0126 0.0126 28.3 1.05 1.36e+07 28.1
Backward likelihoods analytic_mentos 0.0773 0.0267 0.094 0.0242 0.0242 0.0713 0.101 0.00271 0.0713
macro_maxent_production_net_flux 0.0152 0.0146 0.0162 0.0143 0.0143 0.957 0.577 0.014 0.0156
macro_maxent_production_net_flux_diff 0.0152 0.0146 0.0162 0.0143 0.0143 0.957 0.577 0.014 0.0156
macro_maxent_production_rate 0.0152 0.0146 0.0162 0.0143 0.0143 0.957 0.577 0.014 0.0156
maxent_production 0.0152 0.0145 0.0163 0.0143 0.0143 0.0155 0.575 0.014 0.988
micro_maxent_production_net_flux 0.0113 0.0114 0.494 0.0242 0.0242 0.996 0.0328 0.0108 0.996
micro_maxent_production_net_flux_diff 0.0116 0.0117 0.448 0.0235 0.0235 0.92 0.0352 0.0109 0.917
micro_maxent_production_rate 0.00163 0.0244 0.326 0.00104 0.00103 1 0.00819 0.458 1
minent_production 0.921 0.282 30.8 79.4 79.4 0.0353 0.953 7.37e-08 0.0356
Delta G analytic_mentos -6.35 -8.98 -5.86 -9.22 -9.22 -6.55 -5.68 -14.7 -6.55
macro_maxent_production_net_flux -10.4 -10.5 -10.2 -10.5 -10.5 -0.11 -1.36 -10.6 -10.3
macro_maxent_production_net_flux_diff -10.4 -10.5 -10.2 -10.5 -10.5 -0.11 -1.36 -10.6 -10.3
macro_maxent_production_rate -10.4 -10.5 -10.2 -10.5 -10.5 -0.11 -1.36 -10.6 -10.3
maxent_production -10.4 -10.5 -10.2 -10.5 -10.5 -10.3 -1.37 -10.6 -0.0307
micro_maxent_production_net_flux -11.1 -11.1 -1.75 -9.22 -9.22 -0.00876 -8.47 -11.2 -0.00885
micro_maxent_production_net_flux_diff -11.1 -11 -1.99 -9.3 -9.3 -0.207 -8.3 -11.2 -0.215
micro_maxent_production_rate -15.9 -9.2 -2.78 -17 -17.1 -1.09e-06 -11.9 -1.94 -1.14e-06
minent_production -0.204 -3.14 8.5 10.8 10.8 -8.29 -0.12 -40.7 -8.27
log Q_r analytic_mentos -2.56 -2.82 -1.56 -2.11 -3.72 -2.24 -1.48 -5.91 -2.64
macro_maxent_production_net_flux -4.19 -3.42 -3.32 -2.63 -4.25 0.359 0.258 -4.27 -4.16
macro_maxent_production_net_flux_diff -4.19 -3.42 -3.32 -2.63 -4.25 0.359 0.258 -4.27 -4.16
macro_maxent_production_rate -4.19 -3.42 -3.32 -2.63 -4.25 0.359 0.258 -4.27 -4.16
maxent_production -4.19 -3.43 -3.31 -2.63 -4.24 -3.76 0.253 -4.27 -0.0124
micro_maxent_production_net_flux -4.48 -3.66 0.103 -2.11 -3.72 0.4 -2.61 -4.53 -0.00357
micro_maxent_production_net_flux_diff -4.46 -3.64 0.00484 -2.14 -3.75 0.32 -2.54 -4.52 -0.0866
micro_maxent_production_rate -6.42 -2.91 -0.314 -5.26 -6.88 0.403 -4 -0.781 -4.61e-07
minent_production -0.0824 -0.46 4.23 5.99 4.37 -2.94 0.758 -16.4 -3.34
log K_eq analytic_mentos -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
macro_maxent_production_net_flux -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
macro_maxent_production_net_flux_diff -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
macro_maxent_production_rate -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
maxent_production -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
micro_maxent_production_net_flux -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
micro_maxent_production_net_flux_diff -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
micro_maxent_production_rate -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
minent_production -0 0.807 0.807 1.61 -0 0.403 0.807 -0 -0
Delta G0 analytic_mentos 0 -2 -2 -4 0 -1 -2 0 0
macro_maxent_production_net_flux 0 -2 -2 -4 0 -1 -2 0 0
macro_maxent_production_net_flux_diff 0 -2 -2 -4 0 -1 -2 0 0
macro_maxent_production_rate 0 -2 -2 -4 0 -1 -2 0 0
maxent_production 0 -2 -2 -4 0 -1 -2 0 0
micro_maxent_production_net_flux 0 -2 -2 -4 0 -1 -2 0 0
micro_maxent_production_net_flux_diff 0 -2 -2 -4 0 -1 -2 0 0
micro_maxent_production_rate 0 -2 -2 -4 0 -1 -2 0 0
minent_production 0 -2 -2 -4 0 -1 -2 0 0
logK - logQ analytic_mentos 2.56 3.62 2.36 3.72 3.72 2.64 2.29 5.91 2.64
macro_maxent_production_net_flux 4.19 4.23 4.12 4.25 4.25 0.0443 0.549 4.27 4.16
macro_maxent_production_net_flux_diff 4.19 4.23 4.12 4.25 4.25 0.0443 0.549 4.27 4.16
macro_maxent_production_rate 4.19 4.23 4.12 4.25 4.25 0.0443 0.549 4.27 4.16
maxent_production 4.19 4.24 4.12 4.24 4.24 4.17 0.554 4.27 0.0124
micro_maxent_production_net_flux 4.48 4.47 0.704 3.72 3.72 0.00353 3.42 4.53 0.00357
micro_maxent_production_net_flux_diff 4.46 4.45 0.802 3.75 3.75 0.0835 3.35 4.52 0.0866
micro_maxent_production_rate 6.42 3.71 1.12 6.87 6.88 4.4e-07 4.8 0.781 4.61e-07
minent_production 0.0824 1.27 -3.43 -4.37 -4.37 3.34 0.0483 16.4 3.34
logQ - logK analytic_mentos -2.56 -3.62 -2.36 -3.72 -3.72 -2.64 -2.29 -5.91 -2.64
macro_maxent_production_net_flux -4.19 -4.23 -4.12 -4.25 -4.25 -0.0443 -0.549 -4.27 -4.16
macro_maxent_production_net_flux_diff -4.19 -4.23 -4.12 -4.25 -4.25 -0.0443 -0.549 -4.27 -4.16
macro_maxent_production_rate -4.19 -4.23 -4.12 -4.25 -4.25 -0.0443 -0.549 -4.27 -4.16
maxent_production -4.19 -4.24 -4.12 -4.24 -4.24 -4.17 -0.554 -4.27 -0.0124
micro_maxent_production_net_flux -4.48 -4.47 -0.704 -3.72 -3.72 -0.00353 -3.42 -4.53 -0.00357
micro_maxent_production_net_flux_diff -4.46 -4.45 -0.802 -3.75 -3.75 -0.0835 -3.35 -4.52 -0.0866
micro_maxent_production_rate -6.42 -3.71 -1.12 -6.87 -6.88 -4.4e-07 -4.8 -0.781 -4.61e-07
minent_production -0.0824 -1.27 3.43 4.37 4.37 -3.34 -0.0483 -16.4 -3.34
Forward Log likelihoods analytic_mentos 2.56 3.62 2.36 3.72 3.72 2.64 2.29 5.91 2.64
macro_maxent_production_net_flux 4.19 4.23 4.12 4.25 4.25 0.0443 0.549 4.27 4.16
macro_maxent_production_net_flux_diff 4.19 4.23 4.12 4.25 4.25 0.0443 0.549 4.27 4.16
macro_maxent_production_rate 4.19 4.23 4.12 4.25 4.25 0.0443 0.549 4.27 4.16
maxent_production 4.19 4.24 4.12 4.24 4.24 4.17 0.554 4.27 0.0124
micro_maxent_production_net_flux 4.48 4.47 0.704 3.72 3.72 0.00353 3.42 4.53 0.00357
micro_maxent_production_net_flux_diff 4.46 4.45 0.802 3.75 3.75 0.0835 3.35 4.52 0.0866
micro_maxent_production_rate 6.42 3.71 1.12 6.87 6.88 4.4e-07 4.8 0.781 4.61e-07
minent_production 0.0824 1.27 -3.43 -4.37 -4.37 3.34 0.0483 16.4 3.34
Backward Log likelihoods analytic_mentos -2.56 -3.62 -2.36 -3.72 -3.72 -2.64 -2.29 -5.91 -2.64
macro_maxent_production_net_flux -4.19 -4.23 -4.12 -4.25 -4.25 -0.0443 -0.549 -4.27 -4.16
macro_maxent_production_net_flux_diff -4.19 -4.23 -4.12 -4.25 -4.25 -0.0443 -0.549 -4.27 -4.16
macro_maxent_production_rate -4.19 -4.23 -4.12 -4.25 -4.25 -0.0443 -0.549 -4.27 -4.16
maxent_production -4.19 -4.24 -4.12 -4.24 -4.24 -4.17 -0.554 -4.27 -0.0124
micro_maxent_production_net_flux -4.48 -4.47 -0.704 -3.72 -3.72 -0.00353 -3.42 -4.53 -0.00357
micro_maxent_production_net_flux_diff -4.46 -4.45 -0.802 -3.75 -3.75 -0.0835 -3.35 -4.52 -0.0866
micro_maxent_production_rate -6.42 -3.71 -1.12 -6.87 -6.88 -4.4e-07 -4.8 -0.781 -4.61e-07
minent_production -0.0824 -1.27 3.43 4.37 4.37 -3.34 -0.0483 -16.4 -3.34
Forward probabilities analytic_mentos 0.0235 0.068 0.0193 0.0749 0.0749 0.0254 0.0179 0.67 0.0254
macro_maxent_production_net_flux 0.138 0.144 0.13 0.147 0.147 0.0022 0.00364 0.15 0.135
macro_maxent_production_net_flux_diff 0.138 0.144 0.13 0.147 0.147 0.0022 0.00364 0.15 0.135
macro_maxent_production_rate 0.138 0.144 0.13 0.147 0.147 0.0022 0.00364 0.15 0.135
maxent_production 0.139 0.145 0.129 0.146 0.146 0.135 0.00366 0.15 0.00213
micro_maxent_production_net_flux 0.227 0.225 0.00522 0.107 0.107 0.00259 0.0785 0.239 0.00259
micro_maxent_production_net_flux_diff 0.225 0.223 0.00581 0.111 0.111 0.00283 0.074 0.239 0.00284
micro_maxent_production_rate 0.225 0.015 0.00113 0.354 0.357 0.000367 0.0448 0.000801 0.000367
minent_production 8.01e-08 2.62e-07 2.39e-09 9.29e-10 9.29e-10 2.09e-06 7.74e-08 1 2.07e-06
Backward probabilities analytic_mentos 0.00014 4.84e-05 0.00017 4.4e-05 4.4e-05 0.000129 0.000184 4.92e-06 0.000129
macro_maxent_production_net_flux 3.2e-05 3.06e-05 3.41e-05 3.01e-05 3.01e-05 0.00201 0.00121 2.94e-05 3.28e-05
macro_maxent_production_net_flux_diff 3.2e-05 3.06e-05 3.41e-05 3.01e-05 3.01e-05 0.00201 0.00121 2.94e-05 3.28e-05
macro_maxent_production_rate 3.2e-05 3.06e-05 3.41e-05 3.01e-05 3.01e-05 0.00201 0.00121 2.94e-05 3.28e-05
maxent_production 3.18e-05 3.04e-05 3.42e-05 3.01e-05 3.01e-05 3.26e-05 0.00121 2.95e-05 0.00207
micro_maxent_production_net_flux 2.93e-05 2.95e-05 0.00128 6.24e-05 6.24e-05 0.00257 8.47e-05 2.79e-05 0.00257
micro_maxent_production_net_flux_diff 3.02e-05 3.05e-05 0.00117 6.12e-05 6.13e-05 0.0024 9.17e-05 2.84e-05 0.00239
micro_maxent_production_rate 5.98e-07 8.97e-06 0.00012 3.81e-07 3.77e-07 0.000367 3.01e-06 0.000168 0.000367
minent_production 6.79e-08 2.08e-08 2.27e-06 5.85e-06 5.85e-06 2.6e-09 7.02e-08 5.44e-15 2.62e-09
Net probabilities analytic_mentos 0.0233 0.0679 0.0191 0.0749 0.0749 0.0253 0.0177 0.67 0.0253
macro_maxent_production_net_flux 0.138 0.144 0.13 0.147 0.147 0.000186 0.00243 0.15 0.135
macro_maxent_production_net_flux_diff 0.138 0.144 0.13 0.147 0.147 0.000186 0.00243 0.15 0.135
macro_maxent_production_rate 0.138 0.144 0.13 0.147 0.147 0.000186 0.00243 0.15 0.135
maxent_production 0.139 0.145 0.129 0.146 0.146 0.135 0.00245 0.149 5.21e-05
micro_maxent_production_net_flux 0.227 0.225 0.00394 0.106 0.106 1.82e-05 0.0785 0.239 1.84e-05
micro_maxent_production_net_flux_diff 0.225 0.223 0.00464 0.111 0.111 0.000436 0.0739 0.239 0.000452
micro_maxent_production_rate 0.225 0.015 0.00101 0.354 0.357 3.23e-10 0.0448 0.000633 3.39e-10
minent_production 1.22e-08 2.41e-07 -2.27e-06 -5.85e-06 -5.85e-06 2.09e-06 7.13e-09 1 2.07e-06
Net likelihoods analytic_mentos 12.9 37.4 10.5 41.3 41.3 14 9.78 369 14
macro_maxent_production_net_flux 65.7 68.6 61.7 69.9 69.9 0.0886 1.15 71.5 64
macro_maxent_production_net_flux_diff 65.7 68.6 61.7 69.9 69.9 0.0886 1.15 71.5 64
macro_maxent_production_rate 65.7 68.6 61.7 69.9 69.9 0.0886 1.15 71.5 64
maxent_production 66 69.1 61.4 69.7 69.7 64.4 1.17 71.2 0.0248
micro_maxent_production_net_flux 88.1 87.4 1.53 41.3 41.3 0.00707 30.4 92.5 0.00714
micro_maxent_production_net_flux_diff 86.3 85.5 1.78 42.5 42.5 0.167 28.4 91.8 0.174
micro_maxent_production_rate 614 40.9 2.74 964 974 8.8e-07 122 1.73 9.22e-07
minent_production 0.165 3.27 -30.8 -79.3 -79.4 28.3 0.0967 1.36e+07 28.1
Forward rate analytic_mentos 90.7 65.6 21.9 32.9 32.9 17.1 39.8 100 17.1
macro_maxent_production_net_flux 65.2 36.6 28.7 36.4 36.4 2.19 67 101 0.0964
macro_maxent_production_net_flux_diff 65.2 36.6 28.7 36.4 36.4 2.19 67 101 0.0964
macro_maxent_production_rate 65.2 36.6 28.7 36.4 36.4 2.19 67 101 0.0964
maxent_production 66.4 30.7 35.7 29.5 29.5 0.619 84 95.2 49.4
micro_maxent_production_net_flux 101 101 0.00159 34.2 34.2 9.45e+03 34.5 101 9.35e+03
micro_maxent_production_net_flux_diff 101 101 0.00155 34.1 34.1 416 34.6 101 402
micro_maxent_production_rate 100 0.119 148 0.0898 0.0898 3e+04 101 184 2.86e+04
minent_production 500 55.1 0.000321 0.000323 0.000322 20.5 420 19.7 20.5
Backward rate analytic_mentos 7.01 1.75 2.06 0.798 0.798 1.22 4.02 0.272 1.22
macro_maxent_production_net_flux 0.992 0.533 0.465 0.52 0.52 2.1 38.7 1.42 0.00151
macro_maxent_production_net_flux_diff 0.992 0.533 0.465 0.52 0.52 2.1 38.7 1.42 0.00151
macro_maxent_production_rate 0.992 0.533 0.465 0.52 0.52 2.1 38.7 1.42 0.00151
maxent_production 1.01 0.444 0.582 0.422 0.422 0.0096 48.3 1.34 48.8
micro_maxent_production_net_flux 1.15 1.16 0.000788 0.827 0.827 9.42e+03 1.13 1.09 9.32e+03
micro_maxent_production_net_flux_diff 1.17 1.18 0.000694 0.802 0.803 383 1.22 1.1 368
micro_maxent_production_rate 0.163 0.00291 48.3 9.31e-05 9.22e-05 3e+04 0.824 84.5 2.86e+04
minent_production 461 15.5 0.00989 0.0256 0.0256 0.725 400 1.46e-06 0.73
Net flux analytic_mentos 83.7 63.8 19.9 32.1 32.1 15.9 35.7 100 15.9
macro_maxent_production_net_flux 64.3 36 28.2 35.8 35.8 0.0949 28.3 100 0.0949
macro_maxent_production_net_flux_diff 64.3 36 28.2 35.8 35.8 0.0949 28.3 100 0.0949
macro_maxent_production_rate 64.3 36 28.2 35.8 35.8 0.0949 28.3 100 0.0949
maxent_production 65.4 30.3 35.1 29 29 0.609 35.8 93.8 0.609
micro_maxent_production_net_flux 100 100 0.000806 33.3 33.3 33.3 33.3 100 33.3
micro_maxent_production_net_flux_diff 100 100 0.000854 33.3 33.3 33.3 33.3 100 33.3
micro_maxent_production_rate 99.9 0.116 99.8 0.0897 0.0897 0.0132 99.8 100 0.0132
minent_production 39.6 39.6 -0.00956 -0.0253 -0.0253 19.8 19.8 19.7 19.8
Forward Entropy Production analytic_mentos 0.0881 0.183 0.0762 0.194 0.194 0.0934 0.0721 0.268 0.0934
macro_maxent_production_net_flux 0.274 0.279 0.265 0.282 0.282 0.0134 0.0204 0.285 0.27
macro_maxent_production_net_flux_diff 0.274 0.279 0.265 0.282 0.282 0.0134 0.0204 0.285 0.27
macro_maxent_production_rate 0.274 0.279 0.265 0.282 0.282 0.0134 0.0204 0.285 0.27
maxent_production 0.274 0.28 0.264 0.281 0.281 0.271 0.0205 0.284 0.0131
micro_maxent_production_net_flux 0.337 0.336 0.0274 0.239 0.239 0.0154 0.2 0.342 0.0154
micro_maxent_production_net_flux_diff 0.336 0.334 0.0299 0.244 0.244 0.0166 0.193 0.342 0.0167
micro_maxent_production_rate 0.336 0.0631 0.00764 0.368 0.368 0.0029 0.139 0.00571 0.0029
minent_production 1.31e-06 3.96e-06 4.75e-08 1.93e-08 1.93e-08 2.73e-05 1.27e-06 1.87e-05 2.71e-05
Backward Entropy Production analytic_mentos 0.00124 0.000481 0.00148 0.000441 0.000441 0.00116 0.00158 6.01e-05 0.00116
macro_maxent_production_net_flux 0.000331 0.000319 0.00035 0.000313 0.000313 0.0125 0.00815 0.000307 0.000339
macro_maxent_production_net_flux_diff 0.000331 0.000319 0.00035 0.000313 0.000313 0.0125 0.00815 0.000307 0.000339
macro_maxent_production_rate 0.000331 0.000319 0.00035 0.000313 0.000313 0.0125 0.00815 0.000307 0.000339
maxent_production 0.00033 0.000316 0.000352 0.000313 0.000313 0.000337 0.00811 0.000308 0.0128
micro_maxent_production_net_flux 0.000305 0.000308 0.0085 0.000604 0.000604 0.0153 0.000794 0.000292 0.0153
micro_maxent_production_net_flux_diff 0.000314 0.000317 0.00789 0.000594 0.000594 0.0145 0.000852 0.000297 0.0144
micro_maxent_production_rate 8.57e-06 0.000104 0.00108 5.63e-06 5.58e-06 0.0029 3.82e-05 0.00146 0.0029
minent_production 1.12e-06 3.68e-07 2.95e-05 7.05e-05 7.05e-05 5.14e-08 1.16e-06 1.79e-13 5.18e-08
Reaction Entropy Production analytic_mentos 0.0893 0.183 0.0777 0.195 0.195 0.0946 0.0737 0.269 0.0946
macro_maxent_production_net_flux 0.274 0.28 0.265 0.282 0.282 0.0259 0.0286 0.285 0.27
macro_maxent_production_net_flux_diff 0.274 0.28 0.265 0.282 0.282 0.0259 0.0286 0.285 0.27
macro_maxent_production_rate 0.274 0.28 0.265 0.282 0.282 0.0259 0.0286 0.285 0.27
maxent_production 0.274 0.281 0.265 0.282 0.282 0.271 0.0286 0.284 0.0259
micro_maxent_production_net_flux 0.337 0.336 0.0359 0.239 0.239 0.0307 0.201 0.342 0.0307
micro_maxent_production_net_flux_diff 0.336 0.335 0.0378 0.244 0.244 0.0311 0.194 0.342 0.0311
micro_maxent_production_rate 0.336 0.0632 0.00872 0.368 0.368 0.00581 0.139 0.00717 0.00581
minent_production 2.43e-06 4.33e-06 2.95e-05 7.05e-05 7.06e-05 2.74e-05 2.42e-06 1.87e-05 2.72e-05
Microscopic Reaction Entropy Production Rate analytic_mentos 8 12 1.68 6.39 6.39 1.6 2.87 26.9 1.6
macro_maxent_production_net_flux 17.8 10.2 7.6 10.2 10.2 0.0556 1.69 28.9 0.026
macro_maxent_production_net_flux_diff 17.8 10.2 7.6 10.2 10.2 0.0556 1.69 28.9 0.026
macro_maxent_production_rate 17.8 10.2 7.6 10.2 10.2 0.0556 1.69 28.9 0.026
maxent_production 18.2 8.6 9.44 8.29 8.29 0.167 2.12 27 1.27
micro_maxent_production_net_flux 34.1 34 5.04e-05 8.15 8.15 290 6.89 34.6 287
micro_maxent_production_net_flux_diff 34 33.8 5.18e-05 8.32 8.32 12.4 6.66 34.6 12
micro_maxent_production_rate 33.6 0.0075 1.18 0.033 0.033 174 14 1.18 166
minent_production 0.00117 0.000224 2.92e-07 1.8e-06 1.81e-06 0.000561 0.000995 0.00037 0.000557
Microscopic Reaction Entropy Production Net Flux analytic_mentos 7.48 11.7 1.54 6.25 6.25 1.5 2.63 26.9 1.5
macro_maxent_production_net_flux 17.6 10.1 7.49 10.1 10.1 0.00246 0.81 28.5 0.0256
macro_maxent_production_net_flux_diff 17.6 10.1 7.49 10.1 10.1 0.00246 0.81 28.5 0.0256
macro_maxent_production_rate 17.6 10.1 7.49 10.1 10.1 0.00246 0.81 28.5 0.0256
maxent_production 17.9 8.49 9.3 8.18 8.18 0.165 1.02 26.7 0.0158
micro_maxent_production_net_flux 33.7 33.6 2.89e-05 7.97 7.97 1.02 6.69 34.2 1.02
micro_maxent_production_net_flux_diff 33.6 33.5 3.23e-05 8.15 8.14 1.04 6.45 34.2 1.04
micro_maxent_production_rate 33.6 0.00733 0.871 0.033 0.033 7.65e-05 13.9 0.717 7.65e-05
minent_production 9.61e-05 0.000172 -2.83e-07 -1.78e-06 -1.78e-06 0.000542 4.8e-05 0.00037 0.000538
Microscopic Reaction Entropy Production Net Flux Difference analytic_mentos 7.27 11.6 1.49 6.22 6.22 1.46 2.52 26.8 1.46
macro_maxent_production_net_flux 17.6 10.1 7.47 10.1 10.1 9.13e-05 0.348 28.4 0.0256
macro_maxent_production_net_flux_diff 17.6 10.1 7.47 10.1 10.1 9.13e-05 0.348 28.4 0.0256
macro_maxent_production_rate 17.6 10.1 7.47 10.1 10.1 9.13e-05 0.348 28.4 0.0256
maxent_production 17.9 8.47 9.27 8.16 8.16 0.165 0.443 26.6 0.000164
micro_maxent_production_net_flux 33.6 33.6 1.52e-05 7.93 7.93 0.00301 6.63 34.2 0.00304
micro_maxent_production_net_flux_diff 33.5 33.4 1.88e-05 8.11 8.1 0.0718 6.39 34.2 0.0745
micro_maxent_production_rate 33.6 0.00731 0.655 0.033 0.033 2.94e-11 13.9 0.425 3.08e-11
minent_production 7.43e-06 0.000142 2.82e-07 1.78e-06 1.78e-06 0.00054 2.18e-06 0.00037 0.000536
Total Entropy Production analytic_mentos 1.27 1.27 1.27 1.27 1.27 1.27 1.27 1.27 1.27
macro_maxent_production_net_flux 1.99 1.99 1.99 1.99 1.99 1.99 1.99 1.99 1.99
macro_maxent_production_net_flux_diff 1.99 1.99 1.99 1.99 1.99 1.99 1.99 1.99 1.99
macro_maxent_production_rate 1.99 1.99 1.99 1.99 1.99 1.99 1.99 1.99 1.99
maxent_production 1.99 1.99 1.99 1.99 1.99 1.99 1.99 1.99 1.99
micro_maxent_production_net_flux 1.79 1.79 1.79 1.79 1.79 1.79 1.79 1.79 1.79
micro_maxent_production_net_flux_diff 1.8 1.8 1.8 1.8 1.8 1.8 1.8 1.8 1.8
micro_maxent_production_rate 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3
minent_production 0.000253 0.000253 0.000253 0.000253 0.000253 0.000253 0.000253 0.000253 0.000253
Total Microscopic Entropy Production Rate analytic_mentos 65.7 65.7 65.7 65.7 65.7 65.7 65.7 65.7 65.7
macro_maxent_production_net_flux 84.7 84.7 84.7 84.7 84.7 84.7 84.7 84.7 84.7
macro_maxent_production_net_flux_diff 84.7 84.7 84.7 84.7 84.7 84.7 84.7 84.7 84.7
macro_maxent_production_rate 84.7 84.7 84.7 84.7 84.7 84.7 84.7 84.7 84.7
maxent_production 80 80 80 80 80 80 80 80 80
micro_maxent_production_net_flux 126 126 126 126 126 126 126 126 126
micro_maxent_production_net_flux_diff 126 126 126 126 126 126 126 126 126
micro_maxent_production_rate 49.1 49.1 49.1 49.1 49.1 49.1 49.1 49.1 49.1
minent_production 0.00176 0.00176 0.00176 0.00176 0.00176 0.00176 0.00176 0.00176 0.00176
Macroscopic Reaction Entropy Production Net Flux analytic_mentos 8.93 18.3 7.77 19.5 19.5 9.46 7.37 26.9 9.46
macro_maxent_production_net_flux 27.4 28 26.5 28.2 28.2 2.59 2.86 28.5 27
macro_maxent_production_net_flux_diff 27.4 28 26.5 28.2 28.2 2.59 2.86 28.5 27
macro_maxent_production_rate 27.4 28 26.5 28.2 28.2 2.59 2.86 28.5 27
maxent_production 25.7 26.3 24.8 26.4 26.4 25.4 2.69 26.7 2.43
micro_maxent_production_net_flux 33.7 33.6 3.59 23.9 23.9 3.07 20.1 34.2 3.07
micro_maxent_production_net_flux_diff 33.6 33.5 3.78 24.4 24.4 3.11 19.4 34.2 3.11
micro_maxent_production_rate 33.6 6.32 0.872 36.8 36.8 0.581 13.9 0.717 0.581
minent_production 4.8e-05 8.55e-05 0.000583 0.00139 0.00139 0.00054 4.79e-05 0.00037 0.000537
Macroscopic Reaction Entropy Production Net Flux Difference analytic_mentos 8.68 18.2 7.47 19.4 19.4 9.23 7.05 26.8 9.23
macro_maxent_production_net_flux 27.3 27.9 26.5 28.1 28.1 0.0962 1.23 28.4 27
macro_maxent_production_net_flux_diff 27.3 27.9 26.5 28.1 28.1 0.0962 1.23 28.4 27
macro_maxent_production_rate 27.3 27.9 26.5 28.1 28.1 0.0962 1.23 28.4 27
maxent_production 25.7 26.3 24.8 26.4 26.4 25.4 1.16 26.6 0.0252
micro_maxent_production_net_flux 33.6 33.6 1.89 23.8 23.8 0.00904 19.9 34.2 0.00913
micro_maxent_production_net_flux_diff 33.5 33.4 2.2 24.3 24.3 0.215 19.2 34.2 0.224
micro_maxent_production_rate 33.6 6.3 0.656 36.8 36.8 2.23e-07 13.9 0.425 2.34e-07
minent_production 3.71e-06 7.1e-05 -0.000582 -0.00139 -0.00139 0.000538 2.17e-06 0.00037 0.000535
Total Macroscopic Entropy Production Net Flux analytic_mentos 127 127 127 127 127 127 127 127 127
macro_maxent_production_net_flux 199 199 199 199 199 199 199 199 199
macro_maxent_production_net_flux_diff 199 199 199 199 199 199 199 199 199
macro_maxent_production_rate 199 199 199 199 199 199 199 199 199
maxent_production 187 187 187 187 187 187 187 187 187
micro_maxent_production_net_flux 179 179 179 179 179 179 179 179 179
micro_maxent_production_net_flux_diff 180 180 180 180 180 180 180 180 180
micro_maxent_production_rate 130 130 130 130 130 130 130 130 130
minent_production 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005
Total Macroscopic Entropy Production Net Flux Difference analytic_mentos 125 125 125 125 125 125 125 125 125
macro_maxent_production_net_flux 195 195 195 195 195 195 195 195 195
macro_maxent_production_net_flux_diff 195 195 195 195 195 195 195 195 195
macro_maxent_production_rate 195 195 195 195 195 195 195 195 195
maxent_production 183 183 183 183 183 183 183 183 183
micro_maxent_production_net_flux 171 171 171 171 171 171 171 171 171
micro_maxent_production_net_flux_diff 172 172 172 172 172 172 172 172 172
micro_maxent_production_rate 128 128 128 128 128 128 128 128 128
minent_production -0.00185 -0.00185 -0.00185 -0.00185 -0.00185 -0.00185 -0.00185 -0.00185 -0.00185

When the network is in steady state, the concentrations of the internal metabolites do not change. Therefore $$ \frac{d\vec{c}}{dt} = S\cdot\vec{v} = 0$$ where $\vec{c}$ are the concentrations of the internal metabolites, and $\vec{v}$ are the steady state fluxes, and $S$ is the stoichiometric matrix that only includes internal metabolites.

$$ S\cdot\vec{v} = \left[ {\begin{array}{cccccccccc} & R_1 & R_2 & R_3 & R_4 & R_5 & R_6 & R_7 & R_8 & R_9 \\ A & 1 & -1 & -1 & 0 & 0 & 0 & 0 & 0 & 0 \\ B & 0 & 1 & 0 & -1 & 0 & -2 & 0 & 0 & 0 \\ C & 0 & 0 & 1 & 0 & 0 & 1 & -1 & 0 & 0 \\ D & 0 & 0 & 0 & 2 & 0 & 0 & 1 & -1 & 0 \\ E & 0 & 0 & 0 & -1 & 1 & 0 & 0 & 0 & 0 \\ F & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & -1 \\ \end{array}}\right]\cdot\left[ {\begin{array}{c} v_1 \\ v_2 \\ v_3 \\ v_4 \\ v_5 \\ v_6 \\ v_7 \\ v_8 \\ v_9 \\ \end{array}}\right] = 0 $$

Given a set of initial conditions, we can find the optimal growth rate by solving the following optimization problem: $$\max_v( v_{growth} )$$ $$\mbox{Subject to:}$$ $$\begin{eqnarray} & S\cdot v & = 0 \\ \|v\|_1 \leq 1\\ \end{eqnarray}$$


In [115]:
from cvxpy import *
S = fullS.loc[internal_mets].as_matrix()
m,n = S.shape
v = Variable(n)
growth = v[7]

prob = Problem( 
    Maximize( growth ), 
        [    S*v  == 0,
        norm1(v) <= 1])
prob.solve()
print("status: {}".format( prob.status))
print("Optimal value: {}".format( prob.value))
print("Optimal var: \n", )
reactions['Fluxes'] = pd.DataFrame(v.value, index=rxns)
display(reactions[['Net probabilities', 'Fluxes']])
reactions['Net probabilities'].sum()


status: optimal
Optimal value: 0.333333333084465
Optimal var: 

Net probabilities Fluxes
R_1 0.175 0.107
R_2 0.156 0.0481
R_3 0.0183 0.0593
R_4 0.14 0.167
R_5 0.14 0.167
R_6 0.00832 -0.0593
R_7 0.0267 -1.82e-11
R_8 0.306 0.333
R_9 0.00832 -0.0593
Out[115]:
0.9774654589762839

In [ ]: