Link¶
Class for dealing with multiple curves as a link. Link
provides methods for topological manipulation and calculations on
multiple curves.
API documentation¶
-
class
pyknotid.spacecurves.link.
Link
(lines, verbose=True)[source]¶ Bases:
object
Class for holding the vertices of multiple lines, providing helper methods for convenient manipulation and analysis.
The data is stored internally as multiple :class:`Knot`s.
Parameters: - lines (list of nx3 array-like or Knots) – List with the points of each line.
- verbose (bool) – Whether to print information during processing. Defaults to True.
-
arclength
(include_closures=True)[source]¶ Returns the sum of arclengths of the lines.
Parameters: include_closures (bool) – Whether to include the distance between the final and first points of each line. Defaults to True.
-
classmethod
from_periodic_lines
(lines, shape, perturb=True)[source]¶ Returns a
Link
instance in which the lines have been unwrapped through the periodic boundaries.Parameters: - line (list) – A list of the Nx3 vectors of points in the lines
- shape (array-like) – The x, y, z distances of the periodic boundary
- perturb (bool) – If True, translates and rotates the knot to avoid any lattice problems.
-
gauss_code
(**kwargs)[source]¶ Returns a
GaussCode
instance representing the crossings of the knot.The GaussCode instance is cached internally. If you want to recalculate it (e.g. to get an unsimplified version if you have simplified it), you should pass recalculate=True.
This method passes kwargs directly to
raw_crossings()
, see the documentation of that function for all options.
-
linking_number
(**kwargs)[source]¶ Returns the linking number of the lines in the Link, the sum of signed crossings between them, ignoring crossings of a line with itself.
-
octree_simplify
(runs=1, plot=False, rotate=True, obey_knotting=False, **kwargs)[source]¶ Simplifies the curves via the octree reduction of :module:`pyknotid.simplify.octree`.
Parameters: - runs (int) – The number of times to run the octree simplification. Defaults to 1.
- plot (bool) – Whether to plot the curve after each run. Defaults to False.
- rotate (bool) – Whether to rotate the space curve before each run. Defaults to True as this can make things much faster.
- obey_knotting (bool) – Whether to not let the line pass through itself. Defaults to False - knotting of individual components will be ignored! This is much faster than the alternative.
:param kwargs are passed to the
pyknotid.simplify.octree.OctreeCell
: :param constructor.:
-
plot
(mode='vispy', clf=True, colours=None, **kwargs)[source]¶ Plots all the lines. See
pyknotid.visualise.plot_line()
for full documentation.
-
raw_crossings
(mode='use_max_jump', only_with_other_lines=True, include_closures=True, recalculate=False, try_cython=True)[source]¶ Returns the crossings in the diagram of the projection of the space curve into its z=0 plane.
The crossings will be calculated the first time this function is called, then cached until an operation that would change the list (e.g. rotation, or changing
self.points
).Multiple modes are available (see parameters) - you should be aware of this because different modes may be vastly slower or faster depending on the type of line.
Parameters: - mode (str, optional) – One of
'count_every_jump'
and'use_max_jump'
. In the former case, walking along the line uses information about the length of every step. In the latter, it guesses that all steps have the same length as the maximum step length. The optimal choice depends on the data, but is usually'use_max_jump'
, which is the default. - only_with_other_lines (bool) – If True, ignores self-crossings (i.e. the knot type of the loops) and returns only a list of crossings between the loops. Defaults to True
- include_closures (bool, optional) – Whether to include crossings with the lines joining their start and end points. Defaults to True.
- recalculate (bool, optional) – Whether to force a recalculation of the crossing positions. Defaults to False.
- try_cython (bool, optional) – Whether to try to use a cython implementation of crossing finding. This will make no difference if the cython could not be loaded, in which case python is already used automatically. Defaults to True.
Returns: The raw array of floats representing crossings, of the form [[line_index, other_index, +-1, +-1], …], where the line_index and other_index are in arclength parameterised by integers for each vertex and linearly interpolated, and the +-1 represent over/under and clockwise/anticlockwise respectively.
Return type: array-like
- mode (str, optional) – One of
-
rotate
(angles=None)[source]¶ Rotates all the points of each line of self by the given angle in each axis.
Parameters: angles (array-like) – Rotation angles about x, y and z axes. If None, random angles are used. Defaults to None.
-
smooth
(*args, **kwargs)[source]¶ Smooths each of the x, y and z components of each of self.lines by convolving with a window of the given type and size.
kwargs are passed straight to
pyknotid.spacecurves.spacecurve.SpaceCurve.smooth()
.
-
translate
(vector, lines=None)[source]¶ Translate all points in some or all lines of self.
Parameters: - vector (array-like) – The x, y, z translation distances
- lines (list or int) – The list of line indices to which the translation should be applied. Defaults to None, which applies the translation to all the lines of self. If an integer is supplied, only the line with this index is translated.