Conditions (Python)#

raven-toolbox objects in raven_toolbox.conditions.

Functions#

Function

Summary

apply_condition

Apply a parsed condition (or a YAML file path) to model in place.

load_condition

Parse a condition YAML file into a plain dict.

set_reaction_bounds

Set both bounds, bypassing cobra's lb <= ub validator.

Reference#

apply_condition#

apply_condition(model: cobra.Model, condition: dict[str, Any] | str | Path)

Apply a parsed condition (or a YAML file path) to model in place.

Returns the same model object.

Parameters

model : cobra.Model

Model to modify in place.

condition : dict or str or Path

A condition already parsed into a dict, or the path of a condition YAML file that is read with load_condition. The schema is described in the module docstring.

load_condition#

load_condition(path: str | Path)

Parse a condition YAML file into a plain dict.

Parameters

path : str or Path

Path of the YAML file, in the schema described in the module docstring.

Returns

dict

The parsed condition. A file without content gives an empty dict, which apply_condition applies as a condition without steps (as RAVEN parseYAML and applyCondition do).

Raises

FileNotFoundError

If path does not exist.

set_reaction_bounds#

set_reaction_bounds(rxn: cobra.Reaction, lb: float, ub: float)

Set both bounds, bypassing cobra's lb <= ub validator.

Some conditions set an infeasible state with lb > ub (for example to force flux via a sentinel bound), which cobra's setter rejects. When lb > ub, the function writes the private bound attributes of the reaction directly; otherwise it uses rxn.bounds.

Parameters

rxn : cobra.Reaction

Reaction to modify in place.

lb : float

New lower bound.

ub : float

New upper bound.