nskinetics.Reaction#
- class nskinetics.Reaction(ID, species_system, kf, kb=0.0, rate_f=None, rate_params=None, reactants=None, products=None, chem_equation=None, stoichiometry=None, exponents=None, is_transport=False, is_multicompartment=False, get_exponents_from_stoich=False, freeze_kf=False, freeze_kb=False, atol=1e-06)[source]#
Bases:
AbstractReactionA complete chemical reaction object that includes kinetic parameters and rate law information.
This class extends AbstractReaction by adding support for reaction rate constants, rate law exponents, reversible/irreversible behavior, and dynamic concentration updates. Includes logic to compute the rate of change in concentrations.
- One and only one of the following must be provided to define stoichiometry:
reactants and products (as dict or list)
chem_equation
stoichiometry
- Parameters:
ID (str) – Identifier for the reaction.
species_system (SpeciesSystem) – System containing the chemical species.
kf (float) – Forward reaction rate constant.
kb (float, optional) – Backward reaction rate constant (defaults to 0 for irreversible reactions).
rate_f (function, optional) – Custom rate function (overrides any value parsed from str chem_equation). Must accept species_concs_vector, rxn_stoichs, rl_exps, reactant_indices, and product_indices as arguments (see Reaction.get_dconcs_dt for example use) and additional keyword arguments for parameters from Reaction.rate_params.
rate_params (dict, optional) – Dictionary of parameters passed as keyword arguments to Reaction.rate_f.
reactants (list or dict, optional) – Reactant species. If dict, keys are species IDs and values are stoichiometric coefficients.
products (list or dict, optional) – Product species. Same format as reactants.
chem_equation (ChemicalEquation, optional) – Equation object defining reaction stoichiometry.
stoichiometry (array-like, optional) – Stoichiometric coefficients for all species.
exponents (array-like, optional) – Rate law exponents for each species (same length as stoichiometry).
get_exponents_from_stoich (bool, optional) – If True, use the absolute value of stoichiometry as the rate law exponents.
freeze_kf (bool, optional) – If True, prevents modification of the forward rate constant, kf.
freeze_kb (bool, optional) – If True, prevents modification of the backward rate constant, kb.
- __init__(ID, species_system, kf, kb=0.0, rate_f=None, rate_params=None, reactants=None, products=None, chem_equation=None, stoichiometry=None, exponents=None, is_transport=False, is_multicompartment=False, get_exponents_from_stoich=False, freeze_kf=False, freeze_kb=False, atol=1e-06)[source]#
Methods
__init__(ID, species_system, kf[, kb, ...])from_equation(ID, chem_equation, species_system)Create a Reaction object from a ChemicalEquation object or string.
Calculate the net rate of change in species concentrations for this reaction, using the current kinetic parameters and species concentrations.
Attributes
- classmethod from_equation(ID, chem_equation, species_system, kf=None, kb=None, rate_f=None, rate_params=None, exponents=None, get_exponents_from_stoich=False, is_transport=False, is_multicompartment=False)[source]#
Create a Reaction object from a ChemicalEquation object or string.
- Parameters:
ID (str) – Identifier for the Reaction.
chem_equation (str or ChemicalEquation) –
Reaction as a string or ChemicalEquation object. String represents the chemical equation and may or may not include kf and kb (if not included, must pass at least kf
– kb defaults to zero – or both kf and kb as arguments).
E.g., “A + B -> C”, “A + B <-> C”, “A + B -> C, kf=20”, “A + B <-> C, kf=20, kb=40.5”.
species_system (SpeciesSystem) – System containing the involved species.
kf (float, optional) – Forward rate constant (overrides any value parsed from str chem_equation).
kb (float, optional) – Backward rate constant (overrides any value parsed from str chem_equation).
rate_f (function, optional) – Custom rate function (overrides any value parsed from str chem_equation). Must accept species_concs_vector, rxn_stoichs, rl_exps, reactant_indices, and product_indices as arguments (see Reaction.get_dconcs_dt for example use) and additional keyword arguments for parameters from Reaction.rate_params.
rate_params (dict, optional) – Dictionary of parameters passed as keyword arguments to Reaction.rate_f. Each parameter value can be a float or 1-d array.
exponents (ndarray, optional) – Rate law exponents.
get_exponents_from_stoich (bool, optional) – Whether to use absolute stoichiometry as rate law exponents.
- Returns:
Instantiated Reaction object.
- Return type:
- get_dconcs_dt()[source]#
Calculate the net rate of change in species concentrations for this reaction, using the current kinetic parameters and species concentrations. If self.species_system.log_transformed is True, returns rate of change of np.log(concentrations) instead.
- Returns:
Change in concentration; or zeros if kf and kb are both zero; or change in log(concentrations) if self.log_transformed is True.
- Return type:
ndarray
- property kb#
The backward reaction rate constant, kf.
- Returns:
Forward reaction rate constant, kb.
- Return type: