pykappa.mixture

Functions

group_by_isomorphism(components)

Group components by isomorphism.

neighborhood(agents, radius)

Get all agents within a distance radius of the given agents.

Classes

Edge(site1, site2)

Represents bonds between sites.

Mixture([patterns, track_components])

A collection of agents and their connections.

MixtureUpdate([agents_to_add, ...])

Specifies changes to be applied to a mixture.

class pykappa.mixture.Edge(site1, site2)[source]

Represents bonds between sites. Edge(x, y) equals Edge(y, x).

Parameters:
site1: Site
site2: Site
class pykappa.mixture.Mixture(patterns=None, track_components=False)[source]

A collection of agents and their connections.

Optionally tracks connected components, enabled via enable_component_tracking().

Parameters:
  • patterns (Iterable[Pattern] | None)

  • track_components (bool)

agents

Indexed set of all agents in the mixture.

Type:

pykappa.utils.IndexedSet[pykappa.pattern.Agent]

_components

Indexed set of components if enabled, else None.

Type:

pykappa.utils.IndexedSet[pykappa.pattern.Component] | None

_embeddings

Cache of embeddings for tracked components.

Type:

dict[pykappa.pattern.Component, pykappa.utils.IndexedSet[pykappa.pattern.Embedding]]

_max_embedding_width

Maximum diameter of tracked components.

Type:

int

add(component)[source]

Add a component to the mixture.

Parameters:

component (Component)

Return type:

None

agents: IndexedSet[Agent]
apply_update(update)[source]

Apply a collection of changes to the mixture.

Parameters:

update (MixtureUpdate)

Return type:

None

property component_tracking: bool

Whether connected components are being tracked.

property components: IndexedSet[Component]
embeddings(component)[source]

Get embeddings of a tracked component (not accounting for symmetries).

Raises:

KeyError – If component is not being tracked.

Parameters:

component (Component)

Return type:

IndexedSet[Embedding]

embeddings_in_component(match_pattern, mixture_component)[source]

Get embeddings of a pattern within a specific component.

Parameters:
Return type:

IndexedSet[Embedding]

enable_component_tracking()[source]

Turn on connected-component tracking for this mixture.

Return type:

None

classmethod from_kappa(patterns)[source]

Create a mixture from Kappa pattern strings and counts.

Parameters:

patterns (dict[str, int]) – Dictionary mapping pattern strings to copy counts.

Return type:

Self

instantiate(pattern, n_copies=1)[source]

Add instances of a pattern to the mixture.

Parameters:
  • pattern (Pattern | str) – Pattern to instantiate, or Kappa string.

  • n_copies (int) – Number of copies to create.

Raises:

AssertionError – If pattern is underspecified.

Return type:

None

property kappa_str: str

The mixture in Kappa format with %init declarations.

remove(component)[source]

Remove a component from the mixture.

Parameters:

component (Component)

Return type:

None

track_component(component)[source]

Start tracking embeddings of a component.

Parameters:

component (Component)

class pykappa.mixture.MixtureUpdate(agents_to_add=<factory>, agents_to_remove=<factory>, edges_to_add=<factory>, edges_to_remove=<factory>, agents_changed=<factory>)[source]

Specifies changes to be applied to a mixture.

Parameters:
  • agents_to_add (set[Agent])

  • agents_to_remove (set[Agent])

  • edges_to_add (set[Edge])

  • edges_to_remove (set[Edge])

  • agents_changed (set[Agent])

agents_changed: set[Agent]
agents_to_add: set[Agent]
agents_to_remove: set[Agent]
connect_sites(site1, site2)[source]

Specify to create an edge between two sites. If the sites are bound to other sites, indicates to remove those edges.

Parameters:
Return type:

None

create_agent(agent)[source]

Create a new agent based on a template (sites will be emptied).

Parameters:

agent (Agent)

Return type:

Agent

disconnect_site(site)[source]

Specify that a site should be unbound.

Parameters:

site (Site)

Return type:

None

edges_to_add: set[Edge]
edges_to_remove: set[Edge]
register_changed_agent(agent)[source]

Register an agent as having internal state changes.

Parameters:

agent (Agent)

Return type:

None

remove_agent(agent)[source]

Specify to remove an agent and its edges from the mixture.

Parameters:

agent (Agent)

Return type:

None

property touched_after: set[Agent]

The agents that will be changed or added after this update.

property touched_before: set[Agent]

The agents that will be changed or removed by this update.

pykappa.mixture.group_by_isomorphism(components)[source]

Group components by isomorphism.

Returns:

Dictionary mapping representative components to lists of isomorphic components.

Parameters:

components (Iterable[Component])

Return type:

dict[Component, list[Component]]

pykappa.mixture.neighborhood(agents, radius)[source]

Get all agents within a distance radius of the given agents.

Parameters:
  • agents (Iterable[Agent])

  • radius (int)

Return type:

set[Agent]