pykappa.system¶
Classes
|
A Kappa system containing agents, rules, observables, and variables for simulation. |
- class pykappa.system.System(mixture=None, rules=None, observables=None, variables=None, tokens=None, monitor=True, seed=None)[source]¶
A Kappa system containing agents, rules, observables, and variables for simulation.
- Parameters:
- classmethod read_ka(filepath, seed=None)[source]¶
Read and parse a Kappa .ka file to create a System.
- Parameters:
filepath (str) – Path to the Kappa file.
seed (int | None) – Random seed for reproducibility.
- Return type:
Self
- classmethod from_ka(ka_str, seed=None)[source]¶
Create a System from a Kappa (.ka style) string.
- Parameters:
ka_str (str) – Kappa language string containing a system definition.
seed (int | None) – Random seed for reproducibility.
- Return type:
Self
- classmethod from_kappa(mixture=None, rules=None, observables=None, variables=None, *args, **kwargs)[source]¶
Create a System from Kappa strings.
- Parameters:
mixture (dict[str, int] | None) – Dictionary mapping agent patterns to initial counts.
rules (Iterable[str] | None) – Iterable of rule strings in Kappa format.
observables (list[str] | dict[str, str] | None) – List of observable expressions or dict mapping names to expressions.
variables (dict[str, str] | None) – Dictionary mapping variable names to expressions.
*args – Additional arguments passed to System constructor.
**kwargs – Additional keyword arguments passed to System constructor.
- Return type:
Self
- observables: dict[str, Expression]¶
Maps observable names to expressions
- variables: dict[str, Expression]¶
Maps variable names to expressions
- time: float¶
Current simulation time
- tokens: dict[str, float]¶
Maps token names to their current values
- tallies: defaultdict[str, dict[str, int]]¶
Tracks rule applications
- property names: dict[str, set[str]]¶
The names of all observables and variables.
- property tallies_str: str¶
A formatted string showing how many times each rule has been applied.
- property kappa_str: str¶
The system representation in Kappa (.ka style) format.
- to_ka(filepath)[source]¶
Write system information to a Kappa file.
- Parameters:
filepath (str)
- Return type:
None
- add_rule(rule, name=None)[source]¶
Add a new rule to the system.
- Parameters:
rule (Rule | str) – Rule object or Kappa string representation.
name (str | None) – Name to assign to the rule. If None, a default name is generated.
- Raises:
AssertionError – If a rule with the given name already exists.
- Return type:
None
- remove_rule(name)[source]¶
Remove a rule by setting its rate to zero.
- Raises:
AssertionError – If the rule already has zero rate.
KeyError – If no rule with the given name exists.
- Parameters:
name (str)
- Return type:
None
- property reactivity: float¶
The total reactivity of the system.
- update_via_kasim(time)[source]¶
Simulate for a given amount of time using KaSim.
Note
KaSim must be installed and in the PATH. Some features are not compatible between PyKappa and KaSim.
- Parameters:
time (float)
- Return type:
None
- kd_table(volume=1.0)[source]¶
Summarize kinetic constants of two-component binding/unbinding rules given volume in liters.
- Parameters:
volume (float)
- Return type:
str
- rule_graph()[source]¶
Visualize a ruleset as a site graph of local transformations.
Solid edges = bond formation; dashed edges = bond breaking. Sites that change state show their transition as
site {old→new}. Creation and degradation are shown as directed edges to/from a sink node.Note
This is a lossy projection that neglects conditions of transformations; multiple rulesets can yield the same graph.
- Return type:
Source