biocrnpyler.core.Propensity
- class biocrnpyler.core.Propensity[source]
Bases:
objectBase 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 (
strorNone) – Name identifier for the propensity type.
See also
MassActionMass action kinetics propensity.
GeneralPropensityCustom formula propensity.
HillBase class for Hill-type propensities.
Notes
This is an abstract base class that should be subclassed to implement specific propensity types. Subclasses must implement:
create_kinetic_law: Generate SBML kinetic lawpretty_print_rate: Human-readable rate formula
The
propensity_dictstructure:‘species’: {<name>: Species object, …}
‘parameters’: {<name>: Parameter or number, …}
Methods
Create SBML kinetic law for a reaction.
Create a propensity from a dictionary.
Get all available propensity subclasses.
Check if an object is a valid Propensity subclass instance.
Generate human-readable string representation of propensity.
Generate formatted string of all propensity parameters.
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:
- 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_typeis 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, defaultTrue) – 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, defaultTrue) – 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