You need to enable JavaScript to run this app. 如何在CBMPy中设置通量比率作为全局约束条件?
优惠活动
大模型
产品
解决方案
定价
更多

如何在CBMPy中设置通量比率作为全局约束条件?

Enforcing Flux Ratio Constraints in CBMPy

Great question! Manually setting fixed bounds only works for specific flux values, but to enforce a fixed ratio between two reaction fluxes across all simulation scenarios, you need to add a linear constraint to your metabolic model. Here's how to implement this for your e_coli_core example:

Step-by-Step Implementation

1. Import the Model and CBMPy

First, load the model as you normally would:

import cbmpy

# Load the E. coli core model
ecoli = cbmpy.CBRead.readSBML3FBC('e_coli_core.xml')

2. Define the Ratio Constraint

You want the flux of R_EX_succ_e (succinate excretion) to be exactly 2 times the flux of R_EX_pyr_e (pyruvate excretion). Mathematically, this translates to:

( R_{EX_succ_e} - 2 \times R_{EX_pyr_e} = 0 )

Use CBMPy's addLinearConstraint() method to add this to the model. This method takes:

  • A unique constraint name
  • A dictionary mapping reaction IDs to their coefficients in the linear equation
  • The constraint type ('=', '>=', or '<')
  • The right-hand side value of the equation
# Add the ratio constraint: R_EX_succ_e = 2 * R_EX_pyr_e
ecoli.addLinearConstraint(
    'succ_pyr_ratio',
    {'R_EX_succ_e': 1.0, 'R_EX_pyr_e': -2.0},
    '=',
    0.0
)

While the ratio constraint enforces the relationship, you might still want to set reasonable bounds for the individual reactions to avoid unrealistic flux values. For example, if you expect pyruvate excretion to be between 0 and 1000:

# Set bounds for pyruvate excretion (adjust as needed)
ecoli.setReactionBounds('R_EX_pyr_e', 0.0, 1000.0)
# Succinate bounds will be automatically constrained by the ratio, but you can set upper limits if needed
ecoli.setReactionBounds('R_EX_succ_e', 0.0, 1000.0)

4. Run FBA and Verify the Ratio

Solve the model and check that the ratio holds:

# Run FBA
cbmpy.doFBA(ecoli)

# Get flux values
solution = ecoli.getReactionValues()

# Print results
print(f"Pyruvate excretion flux: {solution['R_EX_pyr_e']:.2f}")
print(f"Succinate excretion flux: {solution['R_EX_succ_e']:.2f}")
print(f"Ratio (succinate/pyruvate): {solution['R_EX_succ_e']/solution['R_EX_pyr_e']:.2f}")

Handling Range Constraints (If Needed)

If you want the ratio to fall within a range (e.g., 1.8 to 2.2) instead of being exact, add two separate constraints:

# Lower bound: succinate >= 1.8 * pyruvate
ecoli.addLinearConstraint(
    'succ_pyr_ratio_lower',
    {'R_EX_succ_e': 1.0, 'R_EX_pyr_e': -1.8},
    '>=',
    0.0
)

# Upper bound: succinate <= 2.2 * pyruvate
ecoli.addLinearConstraint(
    'succ_pyr_ratio_upper',
    {'R_EX_succ_e': 1.0, 'R_EX_pyr_e': -2.2},
    '<=',
    0.0
)

Key Notes

  • Make sure you understand the direction of your reactions: if excretion fluxes are negative (common in some models, where negative values represent transport out of the cell), adjust the coefficients accordingly. For example, if R_EX_pyr_e = -5 means 5 units excreted, the ratio constraint would still simplify to ( R_{EX_succ_e} - 2R_{EX_pyr_e} = 0 ) (since both fluxes would be negative, their ratio remains positive).
  • Always verify the constraint is correctly applied by checking the solution fluxes after running FBA.

内容的提问来源于stack exchange,提问作者719016

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:09:45