4.1.1. Protocols¶
In Python a protocol is a specification for structural subtyping (static duck-typing), e.g., see https://www.python.org/dev/peps/pep-0544/. This is very similar to what is called a “concept” in C++, e.g., see https://en.wikipedia.org/wiki/Concept_(generic_programming). Python for example has the Iterator protocol that specifies how to implement objects one can iterate over.
This page describes protocols in MØD that are implemented by several classes in the Python interface. Note that these classes are not real types, but merely serves as a documentation device.
- class mod.protocols.Graph¶
The undirected graph protocol.
In addition to the following elements, a graph is also equality comparable.
- vertices¶
(Read-only) An iterable of all vertices in the graph.
- Type:
- class Vertex¶
A descriptor of either a vertex in a graph, or a null vertex.
Besides the operations below, descriptors are
equality comparable,
totally ordered, and
hashable
- __init__()¶
Constructs a null descriptor.
- id¶
(Read-only) The index of the vertex. A non-negative number. The IDs are not guaranteed in general to be consequtive. See the documentation for concrete graphs for sepcific additional guarantees.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- graph¶
(Read-only) The graph the vertex belongs to.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- degree¶
(Read-only) The degree of the vertex.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- incidentEdges¶
(Read-only) A range of incident edges to this vertex.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- class Edge¶
A descriptor of either an edge in a graph, or a null edge.
Besides the operations below, descriptors are
equality comparable, and
totally ordered
- __init__()¶
Constructs a null descriptor.
- graph¶
(Read-only) The graph the edge belongs to.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- source¶
(Read-only) The source vertex of the edge.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- target¶
(Read-only) The target vertex of the edge.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- class VertexRange¶
An iterable of all vertices in the graph.
- class EdgeRange¶
An iterable of all edges in the graph.
- class IncidentEdgeRange¶
An iterable of all edges incident to a specific vertex in the graph.
- class mod.protocols.LabelledGraph¶
An extension of the
Graph
protocol, with access to label information on vertices and edges.- class Vertex¶
An extension of the
Graph.Vertex
protocol.- stringLabel¶
(Read-only) The string label of the vertex.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- atomId¶
(Read-only) The atom ID of the vertex.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- isotope¶
(Read-only) The isotope of the vertex.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- charge¶
(Read-only) The charge of the vertex.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- printStereo()¶
- printStereo(p)
Print the stereo configuration for the vertex.
- Parameters:
p (GraphPrinter) – the printing options used for the depiction.
- Returns:
the name of the PDF-file that will be compiled in post-processing.
- Return type:
- Raises:
LogicError
if it is a null descriptor.
- class Edge¶
An extension of the
Graph.Edge
protocol.- stringLabel¶
(Read-only) The string label of the edge.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- bondType¶
(Read-only) The bond type of the edge.
- Type:
- Raises:
LogicError
if it is a null descriptor.
- class mod.protocols.VertexMap¶
The protocol implemented by classes that represent a map of vertices from a domain
Graph
to a codomainGraph
.- __getitem__(v)¶
- Parameters:
v (Graph.Vertex) – the vertex to return the image of.
- Returns:
the image of the given domain vertex. May return a null vertex if the map is partial.
- Return type:
- Raises:
LogicError
ifv
is a null vertex.- Raises:
LogicError
ifv
does not belong to the domain graph for the map.
- inverse(v)¶
- Parameters:
v (Graph.Vertex) – the codomain vertex to return the domain vertex for.
- Returns:
the domain vertex that maps to the given codomain vertex. May return a null vertex if non exist.
- Return type:
- Raises:
LogicError
ifv
is a null vertex.- Raises:
LogicError
ifv
does not belong to the codomain graph for the map.