@@ -25,7 +25,7 @@ The constructed tree contains subtrees `fluxes` (with the reaction-defining
2525constraints), and a single constraint `objective` thad describes the objective
2626function of the model.
2727"""
28- function fbc_model_constraints (model:: A.AbstractFBCModel )
28+ function fbc_flux_balance_constraints (model:: A.AbstractFBCModel )
2929 rxns = Symbol .(A. reactions (model))
3030 mets = Symbol .(A. metabolites (model))
3131 lbs, ubs = A. bounds (model)
@@ -34,7 +34,7 @@ function fbc_model_constraints(model::A.AbstractFBCModel)
3434 obj = A. objective (model)
3535
3636 return C. ConstraintTree (
37- :fluxes ^ C. variables (keys = rxns , bounds = zip (lbs, ubs)) *
37+ :fluxes ^ C. variables (keys = reactions , bounds = zip (lbs, ubs)) *
3838 :flux_stoichiometry ^ C. ConstraintTree (
3939 met => C. Constraint (
4040 value = C. LinearValue (SparseArrays. sparse (row)),
@@ -45,4 +45,38 @@ function fbc_model_constraints(model::A.AbstractFBCModel)
4545 )
4646end
4747
48- export fbc_model_constraints
48+ export fbc_flux_balance_constraints
49+
50+ """
51+ $(TYPEDSIGNATURES)
52+
53+ TODO
54+ """
55+ function fbc_log_concentration_constraints (
56+ model:: A.AbstractFBCModel ;
57+ concentration_bound = _ -> nothing ,
58+ )
59+ rxns = Symbol .(A. reations (model))
60+ mets = Symbol .(A. metabolites (model))
61+ stoi = A. stoichiometry (model)
62+
63+ constraints =
64+ :log_concentrations ^ C. variables (keys = mets, bounds = concentration_bound .(mets)) +
65+ :reactant_log_concentrations ^ C. variables (keys = rxns)
66+
67+ cs = C. ConstraintTree ()
68+
69+ for (midx, ridx, coeff) in zip (findnz (stoi)... )
70+ rid = rxns[ridx]
71+ value = constraints. log_concentrations[mets[midx]] * coeff
72+ if haskey (cs, rid)
73+ cs[rid]. value += value
74+ else
75+ cs[rid] = C. Constraint (; value)
76+ end
77+ end
78+
79+ return constraints * :concentration_stoichiometry ^ cs
80+ end
81+
82+ export fbc_log_concentration_constraints
0 commit comments