kappybara.rule#

Functions

kinetic_to_stochastic_on_rate([k_on, ...])

Convert a kinetic on-rate constant to a stochastic one.

Classes

KappaRule(left, right, stochastic_rate)

Standard Kappa rule with left-hand side, right-hand side, and rate.

KappaRuleBimolecular(left, right, ...)

Bimolecular Kappa rule.

KappaRuleUnimolecular(left, right, ...)

Unimolecular Kappa rule that acts within a single component.

Rule()

Abstract base class for all rule types.

class kappybara.rule.KappaRule(left, right, stochastic_rate)[source]#

Standard Kappa rule with left-hand side, right-hand side, and rate.

Parameters:
left#

Left-hand side pattern.

Type:

kappybara.pattern.Pattern

right#

Right-hand side pattern.

Type:

kappybara.pattern.Pattern

stochastic_rate#

Rate expression for the rule.

Type:

kappybara.algebra.Expression

classmethod from_kappa(kappa_str)[source]#

Parse a single Kappa rule from string.

Parameters:

kappa_str (str) – Kappa rule string.

Returns:

Parsed rule.

Raises:

AssertionError – If the string represents more than one rule.

Return type:

Self

property kappa_str: str#

The rule representation in Kappa format.

Returns:

Kappa string representation of the rule.

left: Pattern#
classmethod list_from_kappa(kappa_str)[source]#

Parse Kappa string into a list of rules.

Note

Forward-reverse rules (with “<->”) represent two rules.

Parameters:

kappa_str (str) – Kappa rule string.

Returns:

List of parsed rules.

Return type:

list[Self]

n_embeddings(mixture)[source]#

Count embeddings in the mixture.

Note

This doesn’t do any symmetry correction, though System applies this correction when calculating rule reactivities.

Parameters:

mixture (Mixture) – Current mixture state.

Returns:

Number of ways to embed all rule components.

Return type:

int

property n_symmetries: int#

The number of distinct automorphisms of the graph containing both left- and right-hand side agents, augmented with edges between positionally corresponding agents. For example, if a rule looks like “l1(…), l2(…) -> r1(…), r2(…)”, this method draws artifical edges between l1 and r1, and between l2 and r2, then returns the number of symmetries of the resulting graph by counting how many ways it can be mapped onto itself.

Returns:

The number of symmetries exhibited by the rule.

rate(system)[source]#

Evaluate the stochastic rate expression.

Parameters:

system (System) – System containing variables for rate evaluation.

Returns:

Evaluated rate value.

Return type:

float

reactivity(system)[source]#

Calculate the total reactivity of this rule in the given system.

Parameters:

system (System) – System containing the mixture and parameters.

Returns:

Product of number of embeddings and reaction rate, accounting for rule symmetry.

Return type:

float

right: Pattern#
select(mixture)[source]#

Select agents in the mixture and specify the update.

Note

Can change the internal states of agents in the mixture but records everything else in the MixtureUpdate.

Parameters:

mixture (ComponentMixture) – Current mixture state.

Returns:

MixtureUpdate specifying the transformation, or None for invalid match.

Return type:

MixtureUpdate | None

stochastic_rate: Expression#
class kappybara.rule.KappaRuleBimolecular(left, right, stochastic_rate)[source]#

Bimolecular Kappa rule.

Parameters:
component_weights#

Cache of embedding weights per component.

property kappa_str: str#

The rule representation in Kappa format.

Returns:

Kappa string representation with bimolecular rate syntax.

n_embeddings(mixture)[source]#

Count embeddings in the mixture.

Parameters:

mixture (ComponentMixture) – Current mixture state.

Returns:

Total number of valid bimolecular embeddings.

Return type:

int

select(mixture)[source]#

Select agents in the mixture and specify the update.

Note

n_embeddings must be called before this method so that the component_weights cache is up-to-date.

Parameters:

mixture (ComponentMixture) – Current mixture state.

Returns:

MixtureUpdate specifying the transformation, or None for invalid match.

Return type:

MixtureUpdate | None

class kappybara.rule.KappaRuleUnimolecular(left, right, stochastic_rate)[source]#

Unimolecular Kappa rule that acts within a single component.

Parameters:
component_weights#

Cache of embedding weights per component.

property kappa_str: str#

Get the rule representation in Kappa format.

Returns:

Kappa string representation with unimolecular rate syntax.

n_embeddings(mixture)[source]#

Count embeddings in the mixture.

Parameters:

mixture (ComponentMixture) – Current mixture state.

Returns:

Total number of valid embeddings across all components.

Return type:

int

select(mixture)[source]#

Select agents in the mixture and specify the update.

Note

n_embeddings must be called before this method so that the component_weights cache is up-to-date.

Parameters:

mixture (ComponentMixture) – Current mixture state.

Returns:

MixtureUpdate specifying the transformation, or None for invalid match.

Return type:

MixtureUpdate | None

class kappybara.rule.Rule[source]#

Abstract base class for all rule types.

abstract n_embeddings(mixture)[source]#

Count the number of ways this rule can be applied to the mixture.

Parameters:

mixture (Mixture) – Current mixture state.

Returns:

Number of valid embeddings for this rule.

Return type:

int

abstract rate(system)[source]#

Get the stochastic rate of the rule.

Parameters:

system (System) – System containing parameters for rate evaluation.

Returns:

Stochastic rate constant.

Return type:

float

reactivity(system)[source]#

Calculate the total reactivity of this rule in the given system.

Parameters:

system (System) – System containing the mixture and parameters.

Returns:

Product of number of embeddings and reaction rate.

Return type:

float

abstract select(mixture)[source]#

Select agents in the mixture and specify the update.

Note

Don’t modify anything in mixture directly except for changing internal sites of agents. A null event is represented by returning None.

Parameters:

mixture (Mixture) – Current mixture state.

Returns:

MixtureUpdate specifying the transformation, or None for null event.

Return type:

MixtureUpdate | None

kappybara.rule.kinetic_to_stochastic_on_rate(k_on=1000000000.0, volume=1, molecularity=2)[source]#

Convert a kinetic on-rate constant to a stochastic one.

Parameters:
  • k_on (float) – Kinetic on-rate constant.

  • volume (float) – Reaction volume.

  • molecularity (int) – Number of reactants.

Returns:

Stochastic rate constant.

Return type:

float