mass.util.expressions

Handles generation and manipulation of sympy expressions.

Module Contents

Functions

Keq2k(sympy_expr[, simplify])

Replace 'Keq' symbols with 'kf/kr' in sympy expressions.

k2Keq(sympy_expr[, simplify])

Replace 'kr' symbols with 'kf/Keq' in sympy expressions.

strip_time(sympy_expr)

Strip the time dependency in sympy expressions.

generate_mass_action_rate_expression(reaction[, rate_type])

Generate the mass action rate law for the reaction.

generate_forward_mass_action_rate_expression(reaction)

Generate the forward mass action rate expression for the reaction.

generate_reverse_mass_action_rate_expression(reaction)

Generate the reverse mass action rate expression for the reaction.

generate_mass_action_ratio(reaction)

Generate the mass action ratio for a given reaction.

generate_disequilibrium_ratio(reaction)

Generate the disequilibrium ratio for a given reaction.

create_custom_rate(reaction, custom_rate[, ...])

Create a sympy expression for a given custom rate law.

generate_ode(metabolite)

Generate the ODE for a given metabolite as a sympy expression.

mass.util.expressions.Keq2k(sympy_expr, simplify=False)[source]

Replace 'Keq' symbols with 'kf/kr' in sympy expressions.

Parameters
  • sympy_expr (Basic, dict, or list) – A sympy expression, a list of sympy expressions, or a dictionary with sympy expressions as the values.

  • simplify (bool) – If True then try to simplify the expression after making the substitution. Otherwise leave the expression as is.

Returns

The sympy expression(s) with the substitution made, returned as the same type as the original input.

Return type

Basic, dict, or list

mass.util.expressions.k2Keq(sympy_expr, simplify=False)[source]

Replace 'kr' symbols with 'kf/Keq' in sympy expressions.

Parameters
  • sympy_expr (Basic, dict, or list) – A sympy expression, a list of sympy expressions, or a dictionary with sympy expressions as the values.

  • simplify (bool) – If True then try to simplify the expression after making the substitution. Otherwise leave the expression as is.

Returns

The sympy expression(s) with the substitution made, returned as the same type as the original input.

Return type

Basic, dict, or list

mass.util.expressions.strip_time(sympy_expr)[source]

Strip the time dependency in sympy expressions.

Parameters

sympy_expr (Basic, dict, or list) – A sympy expression, a list of sympy expressions, or a dictionary with sympy expressions as the values.

Returns

The sympy expression(s) with the time dependency removed, returned as the same type as the original input.

Return type

Basic, dict, or list

mass.util.expressions.generate_mass_action_rate_expression(reaction, rate_type=1)[source]

Generate the mass action rate law for the reaction.

Parameters
Returns

The rate law as a sympy expression. If the reaction has no metabolites associated, None will be returned.

Return type

Basic or None

mass.util.expressions.generate_forward_mass_action_rate_expression(reaction, rate_type=1)[source]

Generate the forward mass action rate expression for the reaction.

Parameters
Returns

The forward rate as a sympy expression. If the reaction has no metabolites associated, None will be returned.

Return type

Basic or None

mass.util.expressions.generate_reverse_mass_action_rate_expression(reaction, rate_type=1)[source]

Generate the reverse mass action rate expression for the reaction.

Parameters
Returns

The reverse rate as a sympy expression. If the reaction has no metabolites associated, None will be returned.

Return type

Basic or None

mass.util.expressions.generate_mass_action_ratio(reaction)[source]

Generate the mass action ratio for a given reaction.

Parameters

reaction (MassReaction) – The reaction to generate the mass action ratio for.

Returns

The mass action ratio as a sympy expression.

Return type

Basic

mass.util.expressions.generate_disequilibrium_ratio(reaction)[source]

Generate the disequilibrium ratio for a given reaction.

Parameters

reaction (MassReaction) – The reaction to generate the disequilibrium ratio for.

Returns

The disequilibrium ratio as a sympy expression.

Return type

Basic

mass.util.expressions.create_custom_rate(reaction, custom_rate, custom_parameters=None)[source]

Create a sympy expression for a given custom rate law.

Notes

  • Metabolites must already exist in the MassModel or MassReaction.

  • Default parameters of a MassReaction are automatically taken into account and do not need to be defined as additional custom parameters.

Parameters
  • reaction (MassReaction) – The reaction associated with the custom rate.

  • custom_rate (str) – The custom rate law as a str. The string representation of the custom rate law will be used to create the expression through the sympify() function.

  • custom_parameters (list of str) – The custom parameter(s) of the custom rate law as a list of strings. The string representation of the custom parameters will be used for creation and recognition of the custom parameter symbols in the sympy expression. If None then parameters are assumed to be one or more of the reaction rate or equilibrium constants.

Returns

A sympy expression of the custom rate. If no metabolites are assoicated with the reaction, None will be returned.

Return type

Basic or None

See also

MassReaction.all_parameter_ids

List of default reaction parameters automatically accounted for.

mass.util.expressions.generate_ode(metabolite)[source]

Generate the ODE for a given metabolite as a sympy expression.

Parameters

metabolite (MassMetabolite) – The metabolite to generate the ODE for.

Returns

ode – A sympy expression of the metabolite ODE. If the metabolite is not associated with any reactions, then None will be returned.

Return type

Basic or None