pykappa.pattern

Represents Kappa patterns and constituent objects.

class pykappa.pattern.Site(label, state, partner)[source]

A site on an agent with state and binding partner information.

Parameters:
  • label (str)

  • state (str)

  • partner (str | _TypedPartner | int | Site)

property agent: Agent

The agent this site belongs to.

property label: str

Name of the site.

property state: str

Internal state of the site.

property partner: str | _TypedPartner | int | Site

The binding partner.

property kappa_str: str
property bound: bool
class pykappa.pattern.Agent(type, sites)[source]

Represents an agent with a type and collection of sites.

Parameters:
  • type (str)

  • sites (Iterable[Site])

static neighborhood(agents, radius)[source]

Get nearby agents with a deterministic breadth-first traversal order.

Parameters:
  • agents (Iterable[Agent])

  • radius (int)

Return type:

OrderedSet[Agent]

classmethod from_kappa(kappa_str)[source]

Parse a single agent from a Kappa string.

Raises:

AssertionError – If the string doesn’t describe exactly one agent.

Parameters:

kappa_str (str)

Return type:

Self

property type: str

Type name of the agent.

property interface: Mapping[str, Site]

Maps site labels to sites.

property kappa_str
property kappa_str_with_agent_ids: str

Kappa representation prefixed with this agent’s ID.

property neighbors: tuple[Self, ...]

The agents directly connected to this one.

class pykappa.pattern.Embedding(mapping)[source]

A mapping from pattern agents to mixture agents.

Parameters:

mapping (Mapping[Agent, Agent])

class pykappa.pattern.Component(agents)[source]

A set of agents that are all in the same connected component.

Note

Connectedness is not guaranteed statically and must be enforced.

Parameters:

agents (Iterable[Agent])

classmethod from_kappa(kappa_str)[source]

Parse a single component from a Kappa string.

Raises:

AssertionError – If the pattern doesn’t represent exactly one component.

Parameters:

kappa_str (str)

Return type:

Self

property agents: IndexedSetView[Agent]

The agents in this component.

property plot: _ComponentPlot

Return a visualization of this component.

property kappa_str: str
property kappa_str_with_agent_ids: str

Kappa representation with each agent prefixed by its ID.

isomorphic(other)[source]
Parameters:

other (Self)

Return type:

bool

embeddings(other, exact=False)[source]

Find embeddings of self in other.

Parameters:
  • other (Self | Mixture | Iterable[Agent]) – Target to find embeddings in.

  • exact (bool) – If True, finds isomorphisms instead of embeddings.

Return type:

Iterator[Embedding]

isomorphisms(other)[source]

Find bijections which respect links in the site graph.

Checks for bijections ensuring that any internal site state specified in one component exists and is the same in the other.

Note

Handles isomorphism generally, between instantiated components in a mixture and potentially between rule patterns.

Parameters:

other (Self | Mixture)

Return type:

Iterator[Embedding]

property diameter: int

Get the maximum minimum shortest path between any two agents.

class pykappa.pattern.Pattern(agents)[source]

A pattern consisting of multiple agents, some of which may be None (empty slots).

Parameters:

agents (Iterable[Agent | None])

classmethod from_kappa(kappa_str)[source]
Raises:

AssertionError – If the string doesn’t describe exactly one pattern.

Parameters:

kappa_str (str)

Return type:

Self

property agents: tuple[Agent | None, ...]

The agents in this pattern, including None empty slots.

property components: tuple[Component, ...]

The connected components in this pattern.

property kappa_str: str
property kappa_str_with_agent_ids: str

Kappa representation with each agent prefixed by its ID.

n_isomorphisms(other)[source]

Counts the number of bijections which respect links in the site graph.

Note

Runtime is exponential in the number of components; use with caution.

Parameters:

other (Self)

Return type:

int