PlanarDiagram

Classes for working with planar diagram notation of knot diagrams.

See individual class documentation for more details.

API documentation

class pyknotid.representations.planardiagram.Crossing(a=None, b=None, c=None, d=None)[source]

Bases: list

A single crossing in a planar diagram. Each PlanarDiagram is a list of these.

Parameters:
  • a (int or None) – The first entry in the list of lines meeting at this Crossing.
  • b (int or None) – The second entry in the list of lines meeting at this Crossing.
  • c (int or None) – The third entry in the list of lines meeting at this Crossing.
  • d (int or None) – The fourth entry in the list of lines meeting at this Crossing.
as_mathematica()[source]

Get a string of mathematica code that can represent the Crossing in mathematica’s knot library.

The mathematica code won’t be valid if any lines of self are None.

Return type:str
components()[source]

Returns a de-duplicated list of lines intersecting at this Crossing.

Return type:list
update_line_number(old, new)[source]

Replaces all instances of the given line number in self.

Parameters:
  • old (int) – The old line number
  • new (int) – The number to replace it with
valid()[source]

True if all intersecting lines are not None.

class pyknotid.representations.planardiagram.PlanarDiagram(crossings='')[source]

Bases: list

A class for containing and manipulating planar diagrams.

Just provides convenient display and conversion methods for now. In the future, will support simplification.

Shorthand input may be of the form X_1,4,2,5 X_3,6,4,1 X_5,2,6,3. This is (should be?) the same as returned by repr.

Parameters:crossings (array-like or string or GaussCode) – The list of crossings in the diagram, which will be converted to an internal planar diagram representation. Currently these are mostly converted via a GaussCode instance, so in addition to the shorthand any array-like supported by GaussCode may be used.
as_mathematica()[source]

Returns a mathematica code representation of self, usable in the mathematica knot tools.

as_networkx()[source]

Get a networkx graph representing the planar diagram, where each node is a crossing and each edge is an arc. This is a non-directed non-multi graph; where two arcs join the same crossing, they are represented as a single edge, but information about duplicates is returned alongside the graph.

Returns:
  • g (Graph) – The networkx graph
  • duplicates (list) – A list of tuples representing nodes joined by multiple edges.
  • heights (dict) – A dictionary of (start, end, arc_number) graph edges, containing the start and end height of each edge.
  • first_edge (tuple) – The first edge in the graph, including (start, end, arc_number).
as_networkx_extended()[source]

(internal use only) Returns a networkx Graph along with extra information about the crossings.

as_spherogram()[source]

Get a planar diagram class from the Spherogram module, which can be used to access SnapPy’s manifold tools.

This method requires that spherogram and SnapPy are installed.

pyknotid.representations.planardiagram.index_height(index)[source]

Returns the height based on the index of the crossing in an entry of a planar diagram; the 0th and 2nd indices are under crossings, and the 1st and 3rd are over crossings.

pyknotid.representations.planardiagram.shorthand_to_crossings(s)[source]

Takes a planar diagram shorthand string, and returns a list of :class:`Crossing`s.