Skip to content

Commit 6673d85

Browse files
committed
cleanup mmdf
1 parent 7f3c756 commit 6673d85

13 files changed

+170
-185
lines changed

docs/src/examples/02c-constraint-modifications.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ model = load_model("e_coli_core.json")
5151

5252
import ConstraintTrees as C
5353

54-
ctmodel = fbc_model_constraints(model)
54+
ctmodel = fbc_flux_balance_constraints(model)
5555

5656
fermentation = ctmodel.fluxes.EX_ac_e.value + ctmodel.fluxes.EX_etoh_e.value
5757

docs/src/examples/03-parsimonious-flux-balance.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ model |> parsimonious_flux_balance_analysis(Clarabel.Optimizer; settings = [sile
5353
# Alternatively, you can construct your own constraint tree model with
5454
# the quadratic objective (this approach is much more flexible).
5555
56-
ctmodel = fbc_model_constraints(model)
56+
ctmodel = fbc_flux_balance_constraints(model)
5757
ctmodel *= :l2objective^squared_sum_value(ctmodel.fluxes)
5858
ctmodel.objective.bound = 0.3 # set growth rate # TODO currently breaks
5959
@@ -88,7 +88,7 @@ minimize_metabolic_adjustment(ref_sol, Clarabel.Optimizer; settings = [silence])
8888
# Alternatively, you can construct your own constraint tree model with
8989
# the quadratic objective (this approach is much more flexible).
9090
91-
ctmodel = fbc_model_constraints(model)
91+
ctmodel = fbc_flux_balance_constraints(model)
9292
ctmodel *=
9393
:minoxphospho^squared_sum_error_value(
9494
ctmodel.fluxes,

docs/src/examples/05-enzyme-constrained-models.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ ec_solution = enzyme_constrained_flux_balance_analysis(
140140
import ConstraintTrees as C
141141

142142
# create basic flux model
143-
m = fbc_model_constraints(model)
143+
m = fbc_flux_balance_constraints(model)
144144

145145
# create enzyme variables
146146
m += :enzymes^gene_product_variables(model)

docs/src/examples/07-loopless-models.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ sol = loopless_flux_balance_analysis(model; optimizer = GLPK.Optimizer)
6161
# not use the convenience function), let's build a loopless model from scratch.
6262

6363
# First, build a normal flux balance model
64-
m = fbc_model_constraints(model)
64+
m = fbc_flux_balance_constraints(model)
6565

6666
# Next, find all internal reactions, and their associated indices for use later
6767
internal_reactions = [

docs/src/examples/08-community-models.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ model = load_model("e_coli_core.json")
5151
# because it is easier to build the model explicitly than rely on an opaque
5252
# one-shot function.
5353

54-
ecoli1 = fbc_model_constraints(model)
55-
ecoli2 = fbc_model_constraints(model)
54+
ecoli1 = fbc_flux_balance_constraints(model)
55+
ecoli2 = fbc_flux_balance_constraints(model)
5656

5757
# Since the models are joined through their individual exchange reactions to an
5858
# environmental exchange reactionq, we need to identify all possible exchange

src/builders/fbc.jl

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The constructed tree contains subtrees `fluxes` (with the reaction-defining
2525
constraints), and a single constraint `objective` thad describes the objective
2626
function 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
)
4646
end
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

src/builders/mmdf.jl

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/frontend/balance.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Compute an optimal objective-optimizing solution of the given `model`.
2222
Most arguments are forwarded to [`optimized_constraints`](@ref).
2323
2424
Returns a tree with the optimization solution of the same shape as
25-
given by [`fbc_model_constraints`](@ref).
25+
given by [`fbc_flux_balance_constraints`](@ref).
2626
"""
2727
function flux_balance_analysis(model::A.AbstractFBCModel, optimizer; kwargs...)
28-
constraints = fbc_model_constraints(model)
28+
constraints = fbc_flux_balance_constraints(model)
2929
optimized_constraints(
3030
constraints;
3131
objective = constraints.objective.value,

src/frontend/enzyme_constrained.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function enzyme_constrained_flux_balance_analysis(
5555
optimizer,
5656
settings = [],
5757
)
58-
constraints = fbc_model_constraints(model)
58+
constraints = fbc_flux_balance_constraints(model)
5959

6060
# might be nice to omit some conditionally (e.g. slash the direction if one
6161
# kcat is nothing)

src/frontend/loopless.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function loopless_flux_balance_analysis(
4545
optimizer,
4646
)
4747

48-
m = fbc_model_constraints(model)
48+
m = fbc_flux_balance_constraints(model)
4949

5050
# find all internal reactions
5151
internal_reactions = [

0 commit comments

Comments
 (0)