biocrnpyler.core.GeneralPropensity
- class biocrnpyler.core.GeneralPropensity(propensity_function: str, propensity_species: List[Species], propensity_parameters: List[ParameterEntry])[source]
Bases:
PropensityPropensity with user-defined formula string.
A
GeneralPropensityallows specification of arbitrary kinetic rate laws using a formula string. The formula can reference species and parameters that are validated and tracked.- Parameters:
propensity_function (
str) – Valid mathematical formula as a string (e.g., ‘k*S1*S2’). Must contain all referenced species and parameters.propensity_species (
listofSpecies) – List of Species objects used in the formula. Each species must appear in the propensity_function string.propensity_parameters (
listofParameterEntry) – List of ParameterEntry objects used in the formula. Each parameter name must appear in the propensity_function string.
- Attributes:
propensity_function (
str) – The mathematical formula defining the rate law.name (
str) – Set to ‘general’ for this propensity type.
- Raises:
TypeError – If propensity_species or propensity_parameters contain invalid types.
ValueError – If species or parameters in lists do not appear in the formula.
See also
MassActionMass action kinetics propensity.
HillHill-type propensities.
Notes
The propensity_function string must be a valid mathematical expression that can be parsed by libsbml.parseL3Formula(). It can include:
Arithmetic operators:
+, -, *, /, ^Mathematical functions: exp, log, sin, cos, etc.
Species names (as strings matching their representation)
Parameter names (matching ParameterEntry.parameter_name)
Examples
Create a custom Michaelis-Menten propensity:
>>> S = bcp.Species('S') >>> E = bcp.Species('E') >>> kcat = bcp.ParameterEntry('kcat', 0.1) >>> Km = bcp.ParameterEntry('Km', 10.0) >>> prop = bcp.GeneralPropensity( ... propensity_function='kcat*E*S/(Km + S)', ... propensity_species=[S, E], ... propensity_parameters=[kcat, Km] ... )
Create a custom regulatory function:
>>> X = bcp.Species('X') >>> Y = bcp.Species('Y') >>> k1 = bcp.ParameterEntry('k1', 1.0) >>> k2 = bcp.ParameterEntry('k2', 0.5) >>> prop = bcp.GeneralPropensity( ... propensity_function='k1*X + k2*Y^2', ... propensity_species=[X, Y], ... propensity_parameters=[k1, k2] ... )
Methods
Create SBML kinetic law using the propensity_function string.
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.
Return the propensity function 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(model, sbml_reaction, **kwargs)[source]
Create SBML kinetic law using the propensity_function string.
Translates species and parameter names to SBML identifiers and creates the kinetic law from the formula string.
- Parameters:
model (
libsbml.Model) – SBML model object.sbml_reaction (
libsbml.Reaction) – SBML reaction to add kinetic law to.**kwargs – Additional keyword arguments (unused for GeneralPropensity).
- Returns:
Created SBML kinetic law object.
- Return type:
libsbml.KineticLaw- Raises:
ValueError – If the propensity_function cannot be parsed as valid SBML formula.
- 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