biocrnpyler.core.Propensity

class biocrnpyler.core.Propensity[source]

Bases: object

Base class for reaction propensity functions in BioCRNpyler.

Propensities define the rate laws for chemical reactions in a CRN. Different propensity types implement different kinetic models such as mass action, Hill functions, and custom formulas. Propensities can be deterministic (ODE) or stochastic (Gillespie).

Attributes:
  • propensity_dict (dict) – Dictionary with ‘species’ and ‘parameters’ keys storing the species and parameters used in the propensity function.

  • name (str or None) – Name identifier for the propensity type.

See also

MassAction

Mass action kinetics propensity.

GeneralPropensity

Custom formula propensity.

Hill

Base class for Hill-type propensities.

Notes

This is an abstract base class that should be subclassed to implement specific propensity types. Subclasses must implement:

The propensity_dict structure:

  • ‘species’: {<name>: Species object, …}

  • ‘parameters’: {<name>: Parameter or number, …}

Methods

create_kinetic_law

Create SBML kinetic law for a reaction.

from_dict

Create a propensity from a dictionary.

get_available_propensities

Get all available propensity subclasses.

is_valid_propensity

Check if an object is a valid Propensity subclass instance.

pretty_print

Generate human-readable string representation of propensity.

pretty_print_parameters

Generate formatted string of all propensity parameters.

pretty_print_rate

Generate human-readable rate formula string.

__eq__(other)[source]

Test equality between propensities.

Parameters:

other (Propensity) – Other propensity to compare with.

Returns:

True if propensities have the same class and propensity_dict.

Return type:

bool

create_kinetic_law(reaction, reverse_reaction, stochastic, **kwargs)[source]

Create SBML kinetic law for a reaction.

Parameters:
  • reaction (libsbml.Reaction) – SBML reaction object to add kinetic law to.

  • reverse_reaction (bool) – If True, creates kinetic law for reverse direction.

  • stochastic (bool) – If True, uses stochastic propensity formulation.

  • **kwargs – Additional arguments (e.g., crn_reaction, model).

Returns:

Created SBML kinetic law object.

Return type:

libsbml.KineticLaw

Raises:

NotImplementedError – Must be implemented by subclasses.

classmethod from_dict(propensity_dict)[source]

Create a propensity from a dictionary.

Parameters:

propensity_dict (dict) – Dictionary with ‘parameters’ and ‘species’ keys containing parameter and species values.

Returns:

New instance of the propensity class.

Return type:

Propensity

static get_available_propensities() Set[source]

Get all available propensity subclasses.

Returns:

Set of all Propensity subclass types available in BioCRNpyler.

Return type:

set

Examples

>>> propensities = bcp.Propensity.get_available_propensities()
>>> bcp.MassAction in propensities
True
property is_reversible

Whether the propensity represents a reversible reaction.

Default is False. Subclasses override this for reversible kinetics.

Type:

bool

static is_valid_propensity(propensity_type) bool[source]

Check if an object is a valid Propensity subclass instance.

Recursively checks all subclasses of Propensity to determine if the given object is a valid propensity type.

Parameters:

propensity_type (object) – Object to check for Propensity validity.

Returns:

True if propensity_type is an instance of Propensity or any of its subclasses, False otherwise.

Return type:

bool

Examples

>>> prop = bcp.MassAction(k_forward=100.0)
>>> bcp.Propensity.is_valid_propensity(prop)
True
>>> bcp.Propensity.is_valid_propensity("not a propensity")
False
property k_forward

Forward rate constant.

Raises:

NotImplementedError – Must be implemented by subclasses that use rate constants.

Type:

Float

property k_reverse

Reverse rate constant for reversible reactions.

Raises:

NotImplementedError – Must be implemented by subclasses that use rate constants.

Type:

Float or None

pretty_print(show_parameters=True, **kwargs)[source]

Generate human-readable string representation of propensity.

Parameters:
  • show_parameters (bool, default True) – If True, includes parameter values in output.

  • **kwargs – Additional keyword arguments passed to formatting methods.

Returns:

Formatted string showing rate formula and optionally parameters.

Return type:

str

pretty_print_parameters(show_keys=True, **kwargs)[source]

Generate formatted string of all propensity parameters.

Parameters:
  • show_keys (bool, default True) – If True, shows search and found keys for ModelParameter objects (useful for debugging parameter lookup).

  • **kwargs – Additional formatting keyword arguments.

Returns:

Formatted string listing all parameters and their values.

Return type:

str

pretty_print_rate(**kwargs)[source]

Generate human-readable rate formula string.

Parameters:

**kwargs – Formatting keyword arguments (e.g., reaction, stochastic).

Returns:

Formatted rate formula string.

Return type:

str

Raises:

NotImplementedError – Must be implemented by subclasses.

property species: List

All species used in the propensity function.

Type:

List of Species