pykappa.pattern

Classes

Agent(type, sites)

Represents an agent with a type and collection of sites.

Component(agents)

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

Embedding

Dictionary representing a mapping from pattern agents to mixture agents.

Pattern(agents)

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

Site(label, state, partner)

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

SiteType(site_name, agent_name)

class pykappa.pattern.SiteType(site_name, agent_name)
Parameters:
  • site_name (str)

  • agent_name (str)

agent_name: str

Alias for field number 1

site_name: str

Alias for field number 0

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 | SiteType | int | Site)

agent: Agent

The agent this site belongs to (set after initialization)

label: str

Name of the site

state: str

Internal state of the site

partner: str | SiteType | int | Site
property kappa_partner_str: str
property kappa_state_str: str
property kappa_str: str
property undetermined: bool

Check if the site is in a state equivalent to leaving it unnamed in an agent.

property underspecified: bool

Check if a concrete Site can be created from this pattern.

property stated: bool

Check if the site has a specific internal state.

property bound: bool
property coupled: bool

Check if the site is coupled to a specific other site.

embeds_in(other)[source]

Check whether self as a pattern matches other as a concrete site.

Parameters:

other (Self)

Return type:

bool

class pykappa.pattern.Agent(type, sites)[source]

Represents an agent with a type and collection of sites.

Parameters:
  • type (str)

  • sites (Iterable[Site])

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

type: str

Type name of the agent

interface: dict[str, Site]

Maps site labels to Site objects

property kappa_str
property sites: Iterable[Site]
property underspecified: bool

Check if a concrete Agent can be created from this pattern.

property neighbors: list[Self]

The agents directly connected to this one.

property depth_first_traversal: list[Self]

Perform depth-first traversal starting from this agent.

property instantiable: bool
detached()[source]

Create a clone with all sites emptied of partners.

Return type:

Self

isomorphic(other)[source]

Check if two Agents are equivalent locally, ignoring partners.

Note

Doesn’t assume agents of the same type will have the same site signatures.

Parameters:

other (Self)

Return type:

bool

embeds_in(other)[source]

Check whether self as a pattern matches other as a concrete agent.

Parameters:

other (Self)

Return type:

bool

class pykappa.pattern.Embedding[source]

Dictionary representing a mapping from pattern agents to mixture agents.

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 (IndexedSet[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

agents: IndexedSet[Agent]
property kappa_str: str
add(agent)[source]
Parameters:

agent (Agent)

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[dict[Agent, Agent]]

property n_automorphisms: int

Returns the number of automorphisms (i.e. isomorphisms onto itself) of the component.

Note

This uses a cached result, and thus should only be used for static components, i.e. the ones in rules and observables. Do not use this for components in a mixture that can change.

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 (list[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

agents: list[Agent | None]
property components: list[Component]

The connected components in this pattern.

static agents_to_kappa_str(agents)[source]

Convert a collection of agents to Kappa string representation.

Parameters:

agents (Iterable[Agent | None])

Return type:

str

property kappa_str: str
property underspecified: bool

Check if any agents in the pattern are underspecified.

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