pd#
Functions
|
Create a planar diagram from condensed PD code (e.g., |
|
Create a planar diagram from PD notation. |
Serialize a planar diagram to condensed PD notation. |
|
Serialize a planar diagram to PD notation. |
- from_pd_notation(text, node_type=<class 'str'>, oriented=False, **attr)#
Create a planar diagram from PD notation.
Supports Mathematica, KnotInfo, and Topoly variants. Nodes default to
'a','b','c',...
ifnode_type is str
; otherwise integers are used in order of appearance.- Parameters:
text (str) – PD notation string (mixed styles allowed; auto-detected).
node_type (type | Any) – Use
str
fora,b,c,...
labels (default), or a different marker to keep integers.oriented (bool) – Whether to create an oriented diagram (not implemented yet).
**attr (Any) – Diagram attributes to set (e.g., name, framing).
- Returns:
PlanarDiagram – Parsed diagram.
- Raises:
NotImplementedError – If
oriented=True
(placeholder).ValueError – If the PD string is malformed or arcs are not paired.
- Return type:
Examples
>>> s = "V[1,2,3], X[2,3,4,5]" >>> d = from_pd_notation(s) >>> isinstance(d, PlanarDiagram) True
- to_pd_notation(k)#
Serialize a planar diagram to PD notation.
Output uses abbreviations inferred by node type:
X[...,...,...,...]
for crossings andV[...]
for vertices. Arc ids are assigned by enumerating unique arcs as they appear.- Parameters:
k (PlanarDiagram) – Diagram to serialize.
- Returns:
str – PD notation string.
- Return type:
str
Examples
>>> from knotpy.classes.planardiagram import PlanarDiagram >>> d = PlanarDiagram() >>> d.add_vertices_from(["a","b"]) >>> d.set_arc((("a",0),("b",0))) >>> out = to_pd_notation(d) >>> out.startswith("V[") or out.startswith("X[") True
- to_condensed_pd_notation(k)#
Serialize a planar diagram to condensed PD notation.
- Constraints:
At most 50 arcs (since we label arcs with single letters).
Diagram must contain only vertices and crossings.
No vertex may have degree 4 (ambiguity with crossings).
- Parameters:
k (PlanarDiagram) – Diagram to serialize.
- Returns:
str – Space-separated tokens of arc letters per node (CCW).
- Raises:
ValueError – If constraints are violated.
- Return type:
str
- from_condensed_pd_notation(text, node_type=<class 'str'>, oriented=False, **attr)#
Create a planar diagram from condensed PD code (e.g.,
"abc bcde ..."
).Each token is a node’s incident arcs in CCW order; 4 letters →
X
(crossing), otherwiseV
(vertex). Arc labels must be single characters and paired globally.- Parameters:
text (str) – Condensed PD code as space-separated tokens.
node_type (type | Any) – Use
str
fora,b,c,...
labels (default), else integers.oriented (bool) – Whether to create an oriented diagram (not implemented yet).
**attr (Any) – Diagram attributes to set.
- Returns:
PlanarDiagram – Parsed diagram.
- Raises:
NotImplementedError – If
oriented=True
(placeholder).ValueError – If token parsing fails.
- Return type: