polymerist.polymers.smidgelib.smidgewrite

Automata for reading SMIDGE strings into their graph representations

Attributes

LOGGER

Classes

SMIDGEWriterRegister

Information accessed by machine states during the SMIDGE writing process

SMIDGEWriterState

Abstract base for automaton states used in writing MID graphs to SMIDGE strings

CheckIsVisitedNode

Read a node index off the stack and check if it has already been visited

VisitNode

Visit a node, check if it has predecessors, and mark it as visited

WriteNode

Add an entry for the current node to the output tokens

WriteEdge

Add an entry for the current edge to the output tokens

DetermineNodeSuccessors

Determine branching and next-node behavior

PushNodeSuccessor

Add a nodes DFS successor to the traversal stack

UpdateNodeSuccessors

Remove any node with no successors from the DFS traversal map

BranchStart

Mark position of branch point in stack for backtrack

BranchEnd

Mark the end of a branch

SMIDGEWriter

Register machine for translating SMIDGE strings to and from monomer graphs

Module Contents

polymerist.polymers.smidgelib.smidgewrite.LOGGER
class polymerist.polymers.smidgelib.smidgewrite.SMIDGEWriterRegister[source]

Information accessed by machine states during the SMIDGE writing process

monograph: polymerist.polymers.monographs.MonomerGraph
bond_info: polymerist.polymers.smidgelib.smidgebonds.MonomerGraphBondInfo
tokens: list[int] = []
curr_idx: int = 0
visited: set
node_stack: list[int] = []
successors: dict[int, list[int]]
predecessors: dict[int, int]
finished: bool = False
property prev_idx: int | None

The index of the precursor to the currently active node

property node_successors: list[int]

The nodes which follow the current node in the DFS traversal (could be empty)

class polymerist.polymers.smidgelib.smidgewrite.SMIDGEWriterState[source]

Bases: abc.ABC

Abstract base for automaton states used in writing MID graphs to SMIDGE strings

state_action(register: SMIDGEWriterRegister) SMIDGEWriterState[source]
abstractmethod transition(register: SMIDGEWriterRegister) SMIDGEWriterState[source]

Define which states should follow the current one based on input

class polymerist.polymers.smidgelib.smidgewrite.CheckIsVisitedNode[source]

Bases: SMIDGEWriterState

Read a node index off the stack and check if it has already been visited

state_action(register: SMIDGEWriterRegister) SMIDGEWriterState[source]
transition(register: SMIDGEWriterRegister) SMIDGEWriterState[source]

Define which states should follow the current one based on input

class polymerist.polymers.smidgelib.smidgewrite.VisitNode[source]

Bases: SMIDGEWriterState

Visit a node, check if it has predecessors, and mark it as visited

state_action(register: SMIDGEWriterRegister) SMIDGEWriterState[source]
transition(register: SMIDGEWriterRegister) SMIDGEWriterState[source]

Define which states should follow the current one based on input

class polymerist.polymers.smidgelib.smidgewrite.WriteNode[source]

Bases: SMIDGEWriterState

Add an entry for the current node to the output tokens

state_action(register: SMIDGEWriterRegister) SMIDGEWriterState[source]
transition(register: SMIDGEWriterRegister) SMIDGEWriterState[source]

Define which states should follow the current one based on input

class polymerist.polymers.smidgelib.smidgewrite.WriteEdge[source]

Bases: SMIDGEWriterState

Add an entry for the current edge to the output tokens

state_action(register: SMIDGEWriterRegister) SMIDGEWriterState[source]
transition(register: SMIDGEWriterRegister) SMIDGEWriterState[source]

Define which states should follow the current one based on input

class polymerist.polymers.smidgelib.smidgewrite.DetermineNodeSuccessors[source]

Bases: SMIDGEWriterState

Determine branching and next-node behavior

transition(register: SMIDGEWriterRegister) SMIDGEWriterState[source]

Define which states should follow the current one based on input

class polymerist.polymers.smidgelib.smidgewrite.PushNodeSuccessor[source]

Bases: SMIDGEWriterState

Add a nodes DFS successor to the traversal stack

state_action(register: SMIDGEWriterRegister) SMIDGEWriterState[source]
transition(register: SMIDGEWriterRegister) SMIDGEWriterState[source]

Define which states should follow the current one based on input

class polymerist.polymers.smidgelib.smidgewrite.UpdateNodeSuccessors[source]

Bases: SMIDGEWriterState

Remove any node with no successors from the DFS traversal map

state_action(register: SMIDGEWriterRegister) SMIDGEWriterState[source]
transition(register: SMIDGEWriterRegister) SMIDGEWriterState[source]

Define which states should follow the current one based on input

class polymerist.polymers.smidgelib.smidgewrite.BranchStart[source]

Bases: SMIDGEWriterState

Mark position of branch point in stack for backtrack

state_action(register: SMIDGEWriterRegister) SMIDGEWriterState[source]
transition(register: SMIDGEWriterRegister) SMIDGEWriterState[source]

Define which states should follow the current one based on input

class polymerist.polymers.smidgelib.smidgewrite.BranchEnd[source]

Bases: SMIDGEWriterState

Mark the end of a branch

state_action(register: SMIDGEWriterRegister) SMIDGEWriterState[source]
transition(register: SMIDGEWriterRegister) SMIDGEWriterState[source]

Define which states should follow the current one based on input

class polymerist.polymers.smidgelib.smidgewrite.SMIDGEWriter[source]

Register machine for translating SMIDGE strings to and from monomer graphs

state: SMIDGEWriterState
write_smidge_connected_component(monograph: polymerist.polymers.monographs.MonomerGraph, start_node_idx: int | None = None) polymerist.polymers.monographs.MonomerGraph[source]

Parse a single connected component of a monomer graph into a SMIDGE string

write_smidge(monograph: polymerist.polymers.monographs.MonomerGraph, start_node_idxs: int | Sequence[int] | None = None) str[source]

Parse all connected components of a monograph into a complete SMIDGE string