PAModel Objects

class PAModel(Model)

Class representation for a cobra model extended with enzyme kinetics as published in Alter et al. (2021).

Arguments:

  • id_or_model str or Model - String to use as model id, or actual model to base new model on. If a string, it is used as input to load a model from. If a model, a new model object is instantiated with the same properties as the original model (default None).

  • name str, optional - Human-readable string to be model description (default None).

  • p_tot float, optional - Total protein concentration (condition-dependent) (unit g_prot/g_cdw) (default 0.285).

  • senstitivity bool - Boolean value whether or not a sensitivity analysis should be performed during each simulation. This sensitivity analysis will indicate to which extent individual constraints contribute to the objective value. Enzyme sectors (EnzymeSector objects, optional): Information about the different enzyme sectors, including:

    • Active_enzyme: Metabolic active proteins.

    • Transl_enzyme: Enzymes related to translation.

    • Unused_enzymes: Excess enzymes.

    • Custom_enzymes (list): Custom enzyme sectors.

  • configuration Config object, optional - Information about the general configuration of the model, including identifier conventions. Default as defined in the PAModelpy.configuration script for the E.coli iML1515 model.

Attributes:

  • p_tot float - The fraction of biomass allocated to proteins (units: g_prot/g_cdw).

  • reactions DictList - A DictList where the key is the reaction identifier and the value is a Reaction.

  • metabolites DictList - A DictList where the key is the metabolite identifier and the value is a Metabolite.

  • genes DictList - A DictList where the key is the gene identifier and the value is a Gene.

  • name0 DictList - A DictList where the key is the group identifier and the value is a Group.

  • name1 DictList - A DictList where the key is the enzyme identifier and the value is an Enzyme.

  • name2 DictList - A DictList where the key is the enzyme variable identifier and the value is an EnzymeVariable.

  • name3 DictList - A DictList where the key is the catalytic event identifier and the value is a CatalyticEvent.

  • name4 dict - A dictionary containing sector-specific constraints.

  • name5 DictList - A DictList where the key is the sector identifier and the value is an EnzymeSector.

P_TOT_DEFAULT

g_protein/g_cdw

__init__

def __init__(id_or_model: Union[str, "Model", None] = None,
             name: Optional[str] = None,
             p_tot: Optional[float] = Config.P_TOT_DEFAULT,
             sensitivity: bool = True,
             active_sector: Optional[ActiveEnzymeSector] = None,
             translational_sector: Optional[TransEnzymeSector] = None,
             unused_sector: Optional[UnusedEnzymeSector] = None,
             custom_sectors: Union[List, CustomSector] = None,
             configuration=Config)

Constants

add_enzymes

def add_enzymes(enzyme_list: list) -> None

Add new enzymes to a model. Adapted from Cobra.core.model.add_reactions and Cobra.core.model.add_metabolites.

This function will add a DictList of enzymes to the model object and add new variables accordingly. For each enzyme-associated reaction, a constraint in each direction is added to the model. The change is reverted upon exit when using the model as a context.

Arguments:

  • enzyme_list list or Enzyme - A list of Enzyme objects. If it isn’t an iterable container, the enzyme will be placed into a list.

add_sectors

def add_sectors(sectors: List = None)

Adds sector variables to the model and adds these to the total protein constraint.

Arguments:

  • sectors list - A list of PAModelpy.EnzymeSectors to add to the model.

add_sector

def add_sector(sector)

Adds the sector variable for a specific sector to the model and adds this to the total protein constraint. Also stores the sector variables in the model attributes.

Arguments:

  • sector PAModelpy.EnzymeSector - The specific EnzymeSector to add to the model.

add_catalytic_events

def add_catalytic_events(catalytic_events: Optional[Iterable])

Add a new CatalyticEvent to the model. Will add a list of CatalyticEvent variables to the model object using the function defined in the CatalyticEvent object.

Arguments:

  • catalytic_events list or variables.CatalyticEvent - A list of variables.CatalyticEvent objects. If it isn’t an iterable container, the catalytic event will be placed into a list.

add_enzyme_constraints

def add_enzyme_constraints(constraint_list: Optional[list])

Add new enzyme constraints to a model. Will add a list of constraints to the model object and add new constraints accordingly. The change is reverted upon exit when using the model as a context.

Arguments:

  • constraint_list list, str, or constraints.Constraint - A list of constraints.Constraint objects. If it isn’t an iterable container, the constraint will be placed into a list. Also, a string with the constraint id can be provided. A constraint will be created before adding it to the model.

add_sector_constraints

def add_sector_constraints(constraint_list: Optional[list])

Add a new constraint related to a sector to a model. Will add a list of constraints to the model object and add new constraints accordingly. The change is reverted upon exit when using the model as a context.

Arguments:

  • constraint_list list or constraints.Constraint - A list of constraints.Constraint objects. If it isn’t an iterable container, the constraint will be placed into a list.

add_total_protein_constraint

def add_total_protein_constraint(p_tot: Optional[float] = P_TOT_DEFAULT)

Function which adds the total protein constraint to the model. This limits the amount of available enzymes and thus the resulting fluxes.

Notes:

The constraint expression looks like this:

  • ``Etot - sum(E) + E_translprot + E_unusedprot  == p_tot - E_trsn_0 - E_ue_0

Arguments:

  • p_tot float, optional - Fraction of biomass which consists of protein (g_protein/g_cdw). Default is 0.258 (E.coli).

add_reactions

def add_reactions(reaction_list: Iterable[Reaction]) -> None

Add reactions to the model. This method is superimposed upon the cobra.Model.add_reactions() function. As a new feature, it will add constraints to determine the lower and upper bound if a sensitivity analysis should be performed (which is determined by the model attribute: PAModel.sensitivity). Reactions with identifiers identical to a reaction already in the model are ignored. The change is reverted upon exit when using the model as a context.

Arguments:

  • reaction_list list - A list of cobra.Reaction objects.

add_lb_ub_constraints

def add_lb_ub_constraints()

Makes additional constraints for the reaction lower bounds and upperbounds. By adding these constraints the shadow prices of the reaction bounds can be calculated and used in sensitivity analysis

make_lb_ub_constraint

@staticmethod
def make_lb_ub_constraint(m: Optional[Model], rxn: Reaction,
                          lower_bound: float, upper_bound: float)

Adding variables and constraints for the lower and upper bounds of a reaction to a model. When solving the model, shadow prices for the lower and upper bounds will be calculated. This allows for the calculation of sensitivity coefficients. The constraints are formulated as follows:

Notes:

Constraints are formulated as follows:

  • R_ub: R_fwd - R_rev <= UB

  • R_lb: -(R_fwd - R_rev) <= -LB

Arguments:

  • m cobra.Model or PAModelpy.PAModel - The model to which the upper and lower bound constraints and variables should be added.

  • rxn cobra.Reaction - The reaction for which upper and lower bound constraints should be generated.

  • lower_bound float - The value of the lower bound.

  • upper_bound float - The value of the upper bound.

Returns:

  • m cobra.Model or PAModelpy.PAModel - The model with additional constraints and variables for the reactions.

make_enzyme_min_max_constraint

@staticmethod
def make_enzyme_min_max_constraint(m: Optional[Model], enz: Enzyme,
                                   lower_bound: float, upper_bound: float)

Adding variables and constraints for the lower and upper bounds of an enzyme’s concentration to a model. When solving the model, shadow prices for the lower and upper bounds will be calculated. This allows for the calculation of sensitivity coefficients.

Notes:

The constraints are formulated as follows:

  • E_ub: E <= Emax

  • E_lb: -E <= -Emin

Arguments:

  • m cobra.Model or PAModelpy.PAModel - The model to which the upper and lower bound constraints and variables should be added.

  • rxn PAModelpy.Enzyme - The enzyme for which minimal and maximal concentration constraints should be generated.

  • lower_bound float - The value of the lower bound.

  • upper_bound float - The value of the upper bound.

Returns:

  • m cobra.Model or PAModelpy.PAModel - The model with additional constraints and variables for the enzyme’s concentration.

parse_shadow_prices

@staticmethod
def parse_shadow_prices(shadow_prices)

Parse the shadow prices to a DataFrame where each constraint corresponds to a row, and shadow prices and directions are columns.

calculate_csc

def calculate_csc(obj_value, mu, mu_ub, mu_lb, mu_ec_f, mu_ec_b)

Calculate the capacity sensitivity coefficient for all inequality constraints in the model. The sum of all capacity sensitivity coefficients should equal 1 for growth maximization.

Capacity Sensitivity Coefficient Calculation: Capacity Sensitivity Coefficient = constraint_UB * shadowprice / obj_value

Arguments:

  • obj_value float - The objective value of the model.

  • mu DataFrame - Shadow prices for all constraints.

  • mu_ub DataFrame - Shadow prices for the reaction upper bound (UB) constraints.

  • mu_lb DataFrame - Shadow prices for the reaction lower bound (LB) constraints.

  • mu_ec_f DataFrame - Shadow prices for the constraints related to enzymatic catalysis of the forward reaction.

  • mu_ec_b DataFrame - Shadow prices for the constraints related to enzymatic catalysis of the backward reaction.

Returns:

None

Results are saved in the self.capacity_sensitivity_coefficients attribute as a DataFrame.

calculate_esc

def calculate_esc(obj_value, mu_ec_f, mu_ec_b)

Calculate enzyme sensitivity coefficients for the enzyme variables using their primal values, the objective value, and shadow prices according to the following relations:

Enzyme Sensitivity Coefficient Calculation: esc = enzyme_variable.primal * constraint.shadowprice / obj_value

Arguments:

  • obj_value float - The objective value from the most recent optimal solution.

  • mu_ec_f pd.DataFrame - Shadow prices for maximizing enzyme concentrations (forward variables).

  • mu_ec_b pd.DataFrame - Shadow prices for minimizing enzyme concentrations (reverse variables).

Returns:

None

Fills the PAModel.enzyme_sensitivity_coefficients dataframe with the calculated enzyme sensitivity coefficients.

calculate_sum_of_enzymes

def calculate_sum_of_enzymes()

Calculate the sum of all enzyme variables for a feasible solution.

Returns:

  • float - The sum of all enzyme variables in milligrams per gram of cell dry weight per hour (mg/gCDW/h).

change_total_protein_constraint

def change_total_protein_constraint(p_tot)

Change the fraction of biomass that is allocated to active proteins.

Arguments:

  • p_tot float - The new proteome fraction in grams of protein per gram of cell dry weight (g_protein/g_cdw).

change_reaction_bounds

def change_reaction_bounds(rxn_id: str,
                           lower_bound: float = None,
                           upper_bound: float = None)

Change the reaction bounds. If a sensitivity analysis is required, the bounds of the upper and lower bound constraints are adjusted.

Arguments:

  • rxn_id str - The string representing the reaction identifier to change.

  • lower_bound float, optional - The new value for the lower bound of the reaction (default is None).

  • upper_bound float, optional - The new value for the upper bound of the reaction (default is None).

change_enzyme_bounds

def change_enzyme_bounds(enzyme_id: str,
                         lower_bound: float = None,
                         upper_bound: float = None)

Change the enzyme bounds. If the model should be primed for performing a sensitivity analysis, the upper bound of the minimum and maximum enzyme concentration constraints are adjusted.

Arguments:

  • enzyme_id str - The string representing the enzyme identifier to change.

  • lower_bound float, optional - The new value for the minimal enzyme concentration (default is None).

  • upper_bound float, optional - The new value for the maximal enzyme concentration (default is None).

get_enzymes_with_reaction_id

def get_enzymes_with_reaction_id(rxn_id: str)

Return Enzyme objects associated with the reaction identifier through CatalyticEvent objects.

Arguments:

  • rxn_id str - The reaction identifier.

Returns:

  • DictList - A DictList of Enzyme objects associated with the reaction.

get_reactions_with_enzyme_id

def get_reactions_with_enzyme_id(enz_id: str)

Return a list of reaction identifiers associated with the enzyme identifier (EC number) through CatalyticEvent objects.

Arguments:

  • enz_id str - The enzyme identifier (EC number).

Returns:

  • List[str] - A list of reaction identifiers associated with the enzyme.

change_kcat_value

def change_kcat_value(enzyme_id: str, kcats: dict)

Change the turnover number (kcat) of the enzyme for a specific reaction.

Arguments:

  • enzyme_id str - The enzyme identifier.

  • kcats dict - A dictionary with reaction identifiers as keys and kcat values as values. Each kcat value should be a nested dictionary with f (forward) and b (backward) as keys, and the corresponding kcat values as values.

Example:

Example dictionary for the kcat parameter     {'R1': {'f': 10.0, 'b': 5.0}, 'R2': {'f': 7.0, 'b': 3.0}}   

remove_enzymes

def remove_enzymes(
        enzymes: Union[str, Enzyme, List[Union[str, Enzyme]]]) -> None

Remove enzymes from the model.

Arguments:

  • enzymes list, reaction, or str - A list with enzymes (Enzyme), or their IDs, to remove. Enzymes will be placed in a list. Strings will be placed in a list and used to find the enzymes in the model.

Notes:

The change is reverted upon exit when using the model as a context.

remove_reactions

def remove_reactions(reactions: Union[str, Reaction, List[Union[str,
                                                                Reaction]]],
                     remove_orphans: bool = False) -> None

Remove reactions from the model. Inherited from the cobrapy.core.remove_reactions() function.

Arguments:

  • reactions list, reaction, or str - A list with reactions (cobra.Reaction), or their IDs, to remove. Reactions will be placed in a list. Strings will be placed in a list and used to find the reactions in the model.

  • remove_orphans bool, optional - Remove orphaned genes and metabolites from the model as well (default False).

Notes:

The change is reverted upon exit when using the model as a context. Also removes associated CatalyticEvents if they exist.

remove_catalytic_events

def remove_catalytic_events(catalytic_events: Union[
    str, CatalyticEvent, List[Union[str, CatalyticEvent]]],
                            remove_orphans: bool = False) -> None

Remove catalytic events from the model.

Arguments:

  • reactions list, reaction, or str - A list with reactions (cobra.Reaction), or their IDs, to remove. Reactions will be placed in a list. Strings will be placed in a list and used to find the reactions in the model.

  • remove_orphans bool, optional - Remove orphaned genes and metabolites from the model as well (default False).

Notes:

The change is reverted upon exit when using the model as a context.

remove_sectors

def remove_sectors(
    sectors: Union[
        str,
        Sector,
        ActiveEnzymeSector,
        List[Union[str, Sector, ActiveEnzymeSector]],
    ]
) -> None

Remove sections from the model.

Also removes associated CatalyticEvents if they exist.

Arguments:

  • sectors list, sector, or str - A list with sector (PAModelpy.Sector or PAModelpy.ActiveEnzymeSector), or their IDs, to remove. A single sector will be placed in a list. Strings will be placed in a list and used to find the sector in the model.

test

def test(glc_flux: Union[int, float] = 10)

Test the proteome allocation model.

Arguments:

  • glc_flux float, optional - The glucose flux which limits the growth rate (units: mmol_glc/g_cdw/h, default=10).

pfba

def pfba(fraction_of_optimum: float = 1.0,
         proteins: bool = False,
         reactions: bool = True,
         exclude: List["str"] = [],
         objective: Union[Dict, "Objective", None] = None)

Perform pFBA (parsimonious Enzyme Usage Flux Balance Analysis) with a custom objective including:

  • All reactions

  • All proteins

  • All proteins and all reactions.

pFBA [1] adds the minimization of all fluxes to the objective of the model. This approach is motivated by the idea that high fluxes have a higher enzyme turnover, and since producing enzymes is costly, the cell will try to minimize overall flux while still maximizing the original objective function, e.g., the growth rate.

Arguments:

  • fraction_of_optimum float, optional - The fraction of optimum which must be maintained. The original objective reaction is constrained to be greater than the maximal value times the fraction_of_optimum (default 1.0).

  • objective dict or cobra.Model.objective, optional - A desired objective to use during optimization in addition to the pFBA objective. Dictionaries (reaction as the key, coefficient as the value) can be used for linear objectives (default None).

  • proteins bool, optional - Determines whether to include enzyme variables in the pFBA objective.

  • reactions bool, optional - Determines whether to include reaction variables in the pFBA objective.

  • exclude list of reaction ids, optional - Reactions to exclude from the minimization objective.

References:

  • [1] Lewis, N. E., Hixson, K. K., Conrad, T. M., Lerman, J. A., Charusanti, P., Polpitiya, A. D., Palsson, B. O. (2010). Omic data from evolved E. coli are consistent with computed optimal growth from genome-scale models. Molecular Systems Biology, 6, 390. doi:10.1038/msb.2010.47

reset_objective

def reset_objective()

Reseting the objective to the standard biomass maximization objective after pFBA

optimize

def optimize(objective_sense: Optional[str] = None,
             raise_error: bool = False) -> "Solution"

Optimize the model using flux balance analysis. Inherits from the cobra.Model.optimize() function and performs a sensitivity analysis after optimization if this is desired (by setting the PAModel.sensitivity attribute to True).

Arguments:

  • objective_sense {None, 'maximize', 'minimize'}, optional - Whether fluxes should be maximized or minimized. In case of None, the previous direction is used (default None).

  • raise_error bool - If true, raise an OptimizationError if solver status is not optimal (default False).

Returns:

Solution

Notes:

Only the most commonly used parameters are presented here. Additional parameters for cobra.solver may be available and specified with the appropriate keyword argument.

copy

def copy() -> "PAModel"

Provide a partial ‘deepcopy’ of the Model.

Adjusted from cobra.Model.copy().

All the Metabolite, Gene, Reaction, Enzyme, EnzymeVariable, Sector, and CatalyticEvent objects are created anew but in a faster fashion than deepcopy.

Returns:

  • PAModelpy.PAModel - A new model copy.