pykappa.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 pykappa.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:

pykappa.pattern.Pattern

right

Right-hand side pattern.

Type:

pykappa.pattern.Pattern

stochastic_rate

Rate expression for the rule.

Type:

pykappa.expression.Expression

classmethod from_kappa(kappa_str)[source]

Parse a single Kappa rule from string.

Raises:

AssertionError – If the string represents more than one rule.

Parameters:

kappa_str (str)

Return type:

Self

property kappa_str: str

The rule representation in Kappa format.

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)

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)

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.

rate(system)[source]

Evaluate the stochastic rate expression.

Parameters:

system (System)

Return type:

float

reactivity(system)[source]

Calculate the total reactivity of this rule in the given system, i.e. the number of embeddings times the reaction rate, accounting for rule symmetry.

Parameters:

system (System)

Return type:

float

right: Pattern
select(mixture)[source]

Select agents and specify the update (or None for invalid match).

Note

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

Parameters:

mixture (Mixture)

Return type:

MixtureUpdate | None

stochastic_rate: Expression
class pykappa.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.

n_embeddings(mixture)[source]

Count the total number of embeddings in the mixture.

Parameters:

mixture (Mixture)

Return type:

int

select(mixture)[source]

Select agents and specify the update (or None for invalid match).

Note

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

Parameters:

mixture (Mixture)

Return type:

MixtureUpdate | None

class pykappa.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.

n_embeddings(mixture)[source]

Count the total number of embeddings in the mixture.

Parameters:

mixture (Mixture)

Return type:

int

select(mixture)[source]

Select agents and specify the update (or None for invalid match).

Note

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

Parameters:

mixture (Mixture)

Return type:

MixtureUpdate | None

class pykappa.rule.Rule[source]

Abstract base class for all rule types.

abstractmethod n_embeddings(mixture)[source]

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

Parameters:

mixture (Mixture)

Return type:

int

abstractmethod rate(system)[source]

Get the stochastic rate of the rule.

Parameters:

system (System)

Return type:

float

reactivity(system)[source]

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

Parameters:

system (System)

Return type:

float

abstractmethod select(mixture)[source]

Select agents and specify the update (or None for null event).

Parameters:

mixture (Mixture)

Return type:

MixtureUpdate | None

pykappa.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.

Return type:

float