smoment.jl 2.17 KB
Newer Older
1

St. Elmo's avatar
St. Elmo committed
2
"""
3
4
    make_smoment_model(
        model::MetabolicModel;
5
6
7
        reaction_isozymes::Function,
        gene_product_capacity_required::Function,
        total_enzyme_capacity,
St. Elmo's avatar
St. Elmo committed
8
9
    )

10
11
Construct an [`SMomentModel`](@ref) model using the inner `model` and a map of
isozymes.
St. Elmo's avatar
St. Elmo committed
12
"""
13
14
function make_smoment_model(
    model::MetabolicModel;
15
16
    reaction_isozymes::Function,
    gene_product_molar_mass::Function,
17
    total_enzyme_capacity::Float64,
St. Elmo's avatar
St. Elmo committed
18
)
19
20
    columns = Vector{_smoment_column}()
    coupling_row_reaction = Int[]
St. Elmo's avatar
St. Elmo committed
21

22
23
    (lbs, ubs) = bounds(model)
    rids = reactions(model)
St. Elmo's avatar
St. Elmo committed
24

25
26
27
28
29
30
31
32
33
    for i = 1:n_reactions(model)
        isozyme = reaction_isozymes(rids[i])
        if isnothing(isozyme)
            # non-enzymatic reaction (or a totally ignored one)
            push!(columns, _smoment_column(i, 0, 0, lbs[i], ubs[i], 0))
        else
            # pick a new row for "arm reaction" coupling
            coupling_row = length(coupling_row_reaction) + 1
            push!(coupling_row_reaction, i)
St. Elmo's avatar
St. Elmo committed
34

35
36
37
            mw = sum(
                gene_product_molar_mass(gid) * ps for (gid, ps) in isozyme.stoichiometry
            )
St. Elmo's avatar
St. Elmo committed
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
            if min(lbs[i], ubs[i]) < 0 && isozyme.kcat_reverse > _constants.tolerance
                # reaction can run in reverse
                push!(
                    columns,
                    _smoment_column(
                        i,
                        -1,
                        coupling_row,
                        max(-ubs[i], 0),
                        -lbs[i],
                        mw / isozyme.kcat_reverse,
                    ),
                )
            end
St. Elmo's avatar
St. Elmo committed
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
            if min(lbs[i], ubs[i]) > 0 && isozyme.kcat_forward > _constants.tolerance
                # reaction can run forward
                push!(
                    columns,
                    _smoment_column(
                        i,
                        1,
                        coupling_row,
                        max(lbs[i], 0),
                        ubs[i],
                        mw / isozyme.kcat_forward,
                    ),
                )
            end
        end
St. Elmo's avatar
St. Elmo committed
69
70
    end

71
    return SMomentModel(columns, coupling_row_reaction, total_enzyme_capacity, model)
St. Elmo's avatar
St. Elmo committed
72
end