Global

Members

atomicNumbers

Source:

A map mapping element symbols to the atomic number.

bonds

Source:

An object mapping the bond type to the number of bonds.

degFactor

Source:

The factor to convert radians to degrees.

mass

Source:

A map mapping element symbols to the atomic mass.

maxBonds

Source:

A map mapping element symbols to their maximum bonds.

radFactor

Source:

The factor to convert degrees to radians.

twoPI

Source:

Two times PI.

Methods

_bridgeDfs()

Source:

PRIVATE FUNCTION used by getBridges().

_ccCountDfs()

Source:

PRIVATE FUNCTION used by getConnectedComponentCount().

_ccGetDfs()

Source:

PRIVATE FUNCTION used by getConnectedComponents().

_init(node, parentVertexId, isBranch)

Source:

PRIVATE FUNCTION. Initializing the graph from the parse tree.

Parameters:
Name Type Default Description
node Object

The current node in the parse tree.

parentVertexId Number null

The id of the previous vertex.

isBranch Boolean false

Whether or not the bond leading to this vertex is a branch bond. Branches are represented by parentheses in smiles (e.g. CC(O)C).

_initInfos()

Source:

PRIVATE FUNCTION. Initializes element counts etc.

add(vec) → {Vector2}

Source:

Add the x and y coordinate values of a vector to the x and y coordinate values of this vector.

Parameters:
Name Type Description
vec Vector2

Another vector.

Returns:

Returns itself.

Type
Vector2

add(vecA, vecB) → {Vector2}

Source:

Adds two vectors and returns the result as a new vector.

Parameters:
Name Type Description
vecA Vector2

A summand.

vecB Vector2

A summand.

Returns:

Returns the sum of two vectors.

Type
Vector2

addAnchoredRing(ringId)

Source:

Defines this atom as the anchor for a ring. When doing repositionings of the vertices and the vertex associated with this atom is moved, the center of this ring is moved as well.

Parameters:
Name Type Description
ringId Number

A ring id.

addChild(vertexId)

Source:

Add a child vertex id to this vertex.

Parameters:
Name Type Description
vertexId Number

The id of a vertex to be added as a child to this vertex.

addEdge(edge) → {Number}

Source:

Add an edge to the graph.

Parameters:
Name Type Description
edge Edge

A new edge.

Returns:

The edge id of the new edge.

Type
Number

addNeighbouringElement(element)

Source:

Adds a neighbouring element to this atom.

Parameters:
Name Type Description
element String

A string representing an element.

addRing(ring) → {Number}

Source:

Add a ring to this representation of a molecule.

Parameters:
Name Type Description
ring Ring

A new ring.

Returns:

The ring id of the new ring.

Type
Number

addRingbondChild(vertexId, ringbondIndex)

Source:

Add a child vertex id to this vertex as the second child of the neighbours array, except this vertex is the first vertex of the SMILE string, then it is added as the first. This is used to get the correct ordering of neighbours for parity calculations. If a hydrogen is implicitly attached to the chiral center, insert as the third child.

Parameters:
Name Type Description
vertexId Number

The id of a vertex to be added as a child to this vertex.

ringbondIndex Number

The index of the ringbond.

addRingConnection(ringConnection) → {Number}

Source:

Add a ring connection to this representation of a molecule.

Parameters:
Name Type Description
ringConnection RingConnection

A new ringConnection.

Returns:

The ring connection id of the new ring connection.

Type
Number

addVertex(vertexId)

Source:

Adding a vertex to the ring connection.

Parameters:
Name Type Description
vertexId Number

A vertex id.

addVertex(vertex) → {Number}

Source:

Add a vertex to the graph.

Parameters:
Name Type Description
vertex Vertex

A new vertex.

Returns:

The vertex id of the new vertex.

Type
Number

angle() → {Number}

Source:

Returns the angle of this vector in relation to the coordinate system.

Returns:

The angle in radians.

Type
Number

angle(vecA, vecB) → {Number}

Source:

Returns the angle between two vectors.

Parameters:
Name Type Description
vecA Vector2

A vector.

vecB Vector2

A vector.

Returns:

The angle between two vectors in radians.

Type
Number

annotateStereochemistry()

Source:

Annotaed stereochemistry information for visualization.

apothem(r, n) → {Number}

Source:

Returns the apothem of a regular n-sided polygon based on its radius.

Parameters:
Name Type Description
r Number

The radius.

n Number

The number of edges of the regular polygon.

Returns:

The apothem of a n-sided polygon based on its radius.

Type
Number

areSetsEqual(setA, setB) → {Boolean}

Source:

Checks whether or not two sets are equal (contain the same elements).

Parameters:
Name Type Description
setA Set.<Number>

A set.

setB Set.<Number>

A set.

Returns:

A boolean indicating whether or not the two sets are equal.

Type
Boolean

areVerticesInSameRing(vertexA, vertexB) → {Boolean}

Source:

Checks whether or not two vertices are in the same ring.

Parameters:
Name Type Description
vertexA Vertex

A vertex.

vertexB Vertex

A vertex.

Returns:

A boolean indicating whether or not the two vertices are in the same ring.

Type
Boolean

attachPseudoElement(element, previousElement, hydrogenCountopt, chargeopt)

Source:

Attaches a pseudo element (e.g. Ac) to the atom.

Parameters:
Name Type Attributes Default Description
element String

The element identifier (e.g. Br, C, ...).

previousElement String

The element that is part of the main chain (not the terminals that are converted to the pseudo element or concatinated).

hydrogenCount Number <optional>
0

The number of hydrogens for the element.

charge Number <optional>
0

The charge for the element.

averageDirection(vecs) → {Vector2}

Source:

Returns the average vector (normalized) of the input vectors.

Parameters:
Name Type Description
vecs Array

An array containing vectors.

Returns:

The resulting vector (normalized).

Type
Vector2

backupRingInformation()

Source:

Stores the current information associated with rings.

backupRings()

Source:

Backs up the current rings.

bondsToAtoms(bonds) → {Set.<Number>}

Source:

Return a set of vertex indices contained in an array of bonds.

Parameters:
Name Type Description
bonds Array

An array of bonds. A bond is defined as [ sourceVertexId, targetVertexId ].

Returns:

An array of vertices.

Type
Set.<Number>

centralAngle(n) → {Number}

Source:

The central angle of a n-sided regular polygon. In radians.

Parameters:
Name Type Description
n Number

The number of sides of the regular polygon.

Returns:

The central angle of the n-sided polygon in radians.

Type
Number

chooseSide(vertexA, vertexB, sides) → {Object}

Source:

When drawing a double bond, choose the side to place the double bond. E.g. a double bond should always been drawn inside a ring.

Parameters:
Name Type Description
vertexA Vertex

A vertex.

vertexB Vertex

A vertex.

sides Array.<Vector2>

An array containing the two normals of the line spanned by the two provided vertices.

Returns:

Returns an object containing the following information: { totalSideCount: Counts the sides of each vertex in the molecule, is an array [ a, b ], totalPosition: Same as position, but based on entire molecule, sideCount: Counts the sides of each neighbour, is an array [ a, b ], position: which side to position the second bond, is 0 or 1, represents the index in the normal array. This is based on only the neighbours anCount: the number of neighbours of vertexA, bnCount: the number of neighbours of vertexB }

Type
Object

clear()

Source:

Clear the canvas.

clear()

Source:

Clears all the elements in this graph (edges and vertices).

clockwise(vec) → {Number}

Source:

Checks whether or not this vector is in a clockwise or counter-clockwise rotational direction compared to another vector in relation to the coordinate system.

Parameters:
Name Type Description
vec Vector2

Another vector.

Returns:

Returns -1, 0 or 1 if the vector supplied as an argument is clockwise, neutral or counter-clockwise respectively to this vector in relation to the coordinate system.

Type
Number

clone(arr) → {*}

Source:

Clone an array or an object. If an object is passed, a shallow clone will be created.

Parameters:
Name Type Description
arr *

The array or object to be cloned.

Returns:

A clone of the array or object.

Type
*

clone() → {Ring}

Source:

Clones this ring and returns the clone.

Returns:

A clone of this ring.

Type
Ring

clone() → {Line}

Source:

Clones this line and returns the clone.

Returns:

A clone of this line.

Type
Line

clone() → {Vector2}

Source:

Clones this vector and returns the clone.

Returns:

The clone of this vector.

Type
Vector2

clone() → {Vertex}

Source:

Clones this vertex and returns the clone.

Returns:

A clone of this vertex.

Type
Vertex

contains(vertexId) → {Boolean}

Source:

Checks whether or not this ring contains a member with a given vertex id.

Parameters:
Name Type Description
vertexId Number

A vertex id.

Returns:

A boolean indicating whether or not this ring contains a member with the given vertex id.

Type
Boolean

contains(arr, options) → {Boolean}

Source:

Checks whether or not an array contains a given value. the options object passed as a second argument can contain three properties. value: The value to be searched for. property: The property that is to be searched for a given value. func: A function that is used as a callback to return either true or false in order to do a custom comparison.

Parameters:
Name Type Description
arr Array

An array.

options Object

See method description.

Properties
Name Type Attributes Description
value *

The value for which to check.

property String <optional>

The property on which to check.

func function <optional>

A custom property function.

Returns:

A boolean whether or not the array contains a value.

Type
Boolean

containsAll(arrA, arrB) → {Boolean}

Source:

Checks whether or not an array contains all the elements of another array, without regard to the order.

Parameters:
Name Type Description
arrA Array

An array.

arrB Array

An array.

Returns:

A boolean indicating whether or not both array contain the same elements.

Type
Boolean

containsRing(ringId) → {Boolean}

Source:

Returns a boolean indicating whether or not a ring with a given id is participating in this ring connection.

Parameters:
Name Type Description
ringId Number

A ring id.

Returns:

A boolean indicating whether or not a ring with a given id participates in this ring connection.

Type
Boolean

count(arr, value) → {Number}

Source:

Count the number of occurences of a value in an array.

Parameters:
Name Type Description
arr Array

An array.

value *

A value to be counted.

Returns:

The number of occurences of a value in the array.

Type
Number

createBridgedRing(ringIds, sourceVertexId) → {Ring}

Source:

Creates a bridged ring.

Parameters:
Name Type Description
ringIds Array.<Number>

An array of ids of rings involved in the bridged ring.

sourceVertexId Number

The vertex id to start the bridged ring discovery from.

Returns:

The bridged ring.

Type
Ring

createNextBond(vertex, previousVertexopt, angleopt, originShortestopt, skipPositioningopt)

Source:

Positiones the next vertex thus creating a bond.

Parameters:
Name Type Attributes Default Description
vertex Vertex

A vertex.

previousVertex Vertex <optional>
null

The previous vertex which has been positioned.

angle Number <optional>
0.0

The (global) angle of the vertex.

originShortest Boolean <optional>
false

Whether the origin is the shortest subtree in the branch.

skipPositioning Boolean <optional>
false

Whether or not to skip positioning and just check the neighbours.

createRing(ring, centeropt, startVertexopt, previousVertexopt, previousVertexopt)

Source:

Creates a new ring, that is, positiones all the vertices inside a ring.

Parameters:
Name Type Attributes Default Description
ring Ring

The ring to position.

center Vector2 | null <optional>
null

The center of the ring to be created.

startVertex Vertex | null <optional>
null

The first vertex to be positioned inside the ring.

previousVertex Vertex | null <optional>
null

The last vertex that was positioned.

previousVertex Boolean <optional>
false

A boolean indicating whether or not this ring was force positioned already - this is needed after force layouting a ring, in order to draw rings connected to it.

deepCopy(arr) → {Array}

Source:

Copies a an n-dimensional array.

Parameters:
Name Type Description
arr Array

The array to be copied.

Returns:

The copy.

Type
Array

distance(vec) → {Number}

Source:

Returns the euclidean distance between this vector and another vector.

Parameters:
Name Type Description
vec Vector2

A vector.

Returns:

The euclidean distance between the two vectors.

Type
Number

distanceSq(vec) → {Number}

Source:

Returns the squared euclidean distance between this vector and another vector. When only the relative distances of a set of vectors are needed, this is is less expensive than using distance(vec).

Parameters:
Name Type Description
vec Vector2

Another vector.

Returns:

The squared euclidean distance of the two vectors.

Type
Number

divide(vecA, vecB) → {Vector2}

Source:

Divides a vector by another vector and returns the result as new vector.

Parameters:
Name Type Description
vecA Vector2

The dividend.

vecB Vector2

The divisor.

Returns:

The fraction of the two vectors.

Type
Vector2

divide(scalar) → {Vector2}

Source:

Divide the x and y coordinate values of this vector by a scalar.

Parameters:
Name Type Description
scalar Number

The scalar.

Returns:

Returns itself.

Type
Vector2

divideScalar(vecA, s) → {Vector2}

Source:

Divides a vector by a scalar and returns the result as new vector.

Parameters:
Name Type Description
vecA Vector2

The dividend.

s Number

The scalar.

Returns:

The fraction of the two vectors.

Type
Vector2

dot(vecA, vecB) → {Number}

Source:

Returns the dot product of two vectors.

Parameters:
Name Type Description
vecA Vector2

A vector.

vecB Vector2

A vector.

Returns:

The dot product of two vectors.

Type
Number

draw(data, target, themeName, infoOnly)

Source:

Draws the parsed smiles data to a canvas element.

Parameters:
Name Type Default Description
data Object

The tree returned by the smiles parser.

target String | HTMLElement

The id of the HTML canvas element the structure is drawn to - or the element itself.

themeName String 'dark'

The name of the theme to use. Built-in themes are 'light' and 'dark'.

infoOnly Boolean false

Only output info on the molecule without drawing anything to the canvas.

drawAromaticityRing(ring)

Source:

Draws a ring inside a provided ring, indicating aromaticity.

Parameters:
Name Type Description
ring Ring

A ring.

drawBall(x, y, elementName)

Source:

Draw a ball to the canvas.

Parameters:
Name Type Description
x Number

The x position of the text.

y Number

The y position of the text.

elementName String

The name of the element (single-letter).

drawCircle(x, y, radius, color, fillopt, debugopt, debugTextopt)

Source:

Draws a circle to a canvas context.

Parameters:
Name Type Attributes Default Description
x Number

The x coordinate of the circles center.

y Number

The y coordinate of the circles center.

radius Number

The radius of the circle

color String

A hex encoded color.

fill Boolean <optional>
true

Whether to fill or stroke the circle.

debug Boolean <optional>
false

Draw in debug mode.

debugText String <optional>
''

A debug message.

drawDashedWedge(line)

Source:

Draw a dashed wedge on the canvas.

Parameters:
Name Type Description
line Line

A line.

drawDebugPoint(x, y, debugTextopt, coloropt)

Source:

Draws a dubug dot at a given coordinate and adds text.

Parameters:
Name Type Attributes Default Description
x Number

The x coordinate.

y Number

The y coordindate.

debugText String <optional>
''

A string.

color String <optional>
'#f00'

A color in hex form.

drawDebugText(x, y, text)

Source:

Draws a debug text message at a given position

Parameters:
Name Type Description
x Number

The x coordinate.

y Number

The y coordinate.

text String

The debug text.

drawEdge(edgeId, debug)

Source:

Draw the an edge as a bonds to the canvas.

Parameters:
Name Type Description
edgeId Number

An edge id.

debug Boolean

A boolean indicating whether or not to draw debug helpers.

drawEdges(debug)

Source:

Draw the actual edges as bonds to the canvas.

Parameters:
Name Type Description
debug Boolean

A boolean indicating whether or not to draw debug helpers.

drawLine(line, dashedopt, alphaopt)

Source:

Draw a line to a canvas.

Parameters:
Name Type Attributes Default Description
line Line

A line.

dashed Boolean <optional>
false

Whether or not the line is dashed.

alpha Number <optional>
1.0

The alpha value of the color.

drawPoint(x, y, elementName)

Source:

Draw a point to the canvas.

Parameters:
Name Type Description
x Number

The x position of the point.

y Number

The y position of the point.

elementName String

The name of the element (single-letter).

drawText(x, y, elementName, hydrogens, direction, isTerminal, charge, isotope, attachedPseudoElement)

Source:

Draw a text to the canvas.

Parameters:
Name Type Description
x Number

The x position of the text.

y Number

The y position of the text.

elementName String

The name of the element (single-letter).

hydrogens Number

The number of hydrogen atoms.

direction String

The direction of the text in relation to the associated vertex.

isTerminal Boolean

A boolean indicating whether or not the vertex is terminal.

charge Number

The charge of the atom.

isotope Number

The isotope number.

attachedPseudoElement Object

A map with containing information for pseudo elements or concatinated elements. The key is comprised of the element symbol and the hydrogen count.

Properties
Name Type Description
element String

The element symbol.

count Number

The number of occurences that match the key.

hyrogenCount Number

The number of hydrogens attached to each atom matching the key.

drawVertices(debug)

Source:

Draws the vertices representing atoms to the canvas.

Parameters:
Name Type Description
debug Boolean

A boolean indicating whether or not to draw debug messages to the canvas.

drawWedge(line, width)

Source:

Draw a wedge on the canvas.

Parameters:
Name Type Default Description
line Line

A line.

width Number 1

The wedge width.

each(arr, callback)

Source:

Run a function for each element in the array. The element is supplied as an argument for the callback function

Parameters:
Name Type Description
arr Array

An array.

callback function

The callback function that is called for each element.

eachMember(vertices, callback, startVertexId, previousVertexId)

Source:

Loops over the members of this ring from a given start position in a direction opposite to the vertex id passed as the previousId.

Parameters:
Name Type Description
vertices Array.<Vertex>

The vertices associated with the current molecule.

callback function

A callback with the current vertex id as a parameter.

startVertexId Number

The vertex id of the start vertex.

previousVertexId Number

The vertex id of the previous vertex (the loop calling the callback function will run in the opposite direction of this vertex).

edgeRingCount(edgeId) → {Number}

Source:

Returns the number of rings this edge is a part of.

Parameters:
Name Type Description
edgeId Number

The id of an edge.

Returns:

The number of rings the provided edge is part of.

Type
Number

equals(vertex) → {Boolean}

Source:

Returns true if this vertex and the supplied vertex both have the same id, else returns false.

Parameters:
Name Type Description
vertex Vertex

The vertex to check.

Returns:

A boolean indicating whether or not the two vertices have the same id.

Type
Boolean

equals(arrA, arrB) → {Boolean}

Source:

Returns a boolean indicating whether or not the two arrays contain the same elements. Only supports 1d, non-nested arrays.

Parameters:
Name Type Description
arrA Array

An array.

arrB Array

An array.

Returns:

A boolean indicating whether or not the two arrays contain the same elements.

Type
Boolean

extend()

Source:

A helper method to extend the default options with user supplied ones.

get(arr, property, value) → {*}

Source:

Return the array element from an array containing objects, where a property of the object is set to a given value.

Parameters:
Name Type Description
arr Array

An array.

property String | Number

A property contained within an object in the array.

value String | Number

The value of the property.

Returns:

The array element matching the value.

Type
*

getAdjacencyList() → {Array.<Array>}

Source:

Get the adjacency list of the graph.

Returns:

The adjancency list of the graph.

Type
Array.<Array>

getAdjacencyMatrix() → {Array.<Array>}

Source:

Get the adjacency matrix of the graph.

Returns:

The adjancency matrix of the molecular graph.

Type
Array.<Array>

getAngle(referenceVectoropt, returnAsDegreesopt) → {Number}

Source:

Returns the angle of this vertexes positional vector. If a reference vector is supplied in relations to this vector, else in relations to the coordinate system.

Parameters:
Name Type Attributes Default Description
referenceVector Vector2 <optional>
null

The reference vector.

returnAsDegrees Boolean <optional>
false

If true, returns angle in degrees, else in radians.

Returns:

The angle of this vertex.

Type
Number

getAngle() → {Number}

Source:

Returns the angle of the line in relation to the coordinate system (the x-axis).

Returns:

The angle in radians.

Type
Number

getAngle() → {Number}

Source:

Returns the angle of this ring in relation to the coordinate system.

Returns:

The angle in radians.

Type
Number

getAtomicNumber() → {Number}

Source:

Get the atomic number of this atom.

Returns:

The atomic number of this atom.

Type
Number

getAttachedPseudoElements() → {Object}

Source:

Returns the attached pseudo elements sorted by hydrogen count (ascending).

Returns:

The sorted attached pseudo elements.

Type
Object

getAttachedPseudoElementsCount() → {Number}

Source:

Returns the number of attached pseudo elements.

Returns:

The number of attached pseudo elements.

Type
Number

getBondCount(vertex) → {Number}

Source:

Gets the number of bonds of a vertex.

Parameters:
Name Type Description
vertex Vertex

A vertex.

Returns:

The number of bonds the vertex participates in.

Type
Number

getBondCount(atoms, adjacencyMatrix) → {Number}

Source:

Returns the number of bonds within a set of atoms.

Parameters:
Name Type Description
atoms Set.<Number>

An array of atom ids.

adjacencyMatrix Array.<Array>

An adjacency matrix.

Returns:

The number of bonds in a set of atoms.

Type
Number

getBridgedRingRings(ringId) → {Array.<Number>}

Source:

Returns all rings connected by bridged bonds starting from the ring with the supplied ring id.

Parameters:
Name Type Description
ringId Number

A ring id.

Returns:

An array containing all ring ids of rings part of a bridged ring system.

Type
Array.<Number>

getBridgedRings() → {Array.<Ring>}

Source:

Returns an array containing the bridged rings associated with this molecule.

Returns:

An array containing all bridged rings associated with this molecule.

Type
Array.<Ring>

getBridges() → {Array.<Number>}

Source:

Returns an array containing the edge ids of bridges. A bridge splits the graph into multiple components when removed.

Returns:

An array containing the edge ids of the bridges.

Type
Array.<Number>

getChargeText(charge) → {String}

Source:

Translate the integer indicating the charge to the appropriate text.

Parameters:
Name Type Description
charge Number

The integer indicating the charge.

Returns:

A string representing a charge.

Type
String

getClosestVertex(vertex) → {Vertex}

Source:

Returns the closest vertex (connected as well as unconnected).

Parameters:
Name Type Description
vertex Vertex

The vertex of which to find the closest other vertex.

Returns:

The closest vertex.

Type
Vertex

getColor(key) → {String}

Source:

Returns the hex code of a color associated with a key from the current theme.

Parameters:
Name Type Description
key String

The color key in the theme (e.g. C, N, BACKGROUND, ...).

Returns:

A color hex value.

Type
String

getCommonRingbondNeighbour(vertex) → {Number|null}

Source:

Gets the vetex sharing the edge that is the common bond of two rings.

Parameters:
Name Type Description
vertex Vertex

A vertex.

Returns:

The id of a vertex sharing the edge that is the common bond of two rings with the vertex provided or null, if none.

Type
Number | null

getCommonRings(vertexA, vertexB) → {Array.<Number>}

Source:

Returns an array of ring ids shared by both vertices.

Parameters:
Name Type Description
vertexA Vertex

A vertex.

vertexB Vertex

A vertex.

Returns:

An array of ids of rings shared by the two vertices.

Type
Array.<Number>

getComponentsAdjacencyMatrix() → {Array.<Array>}

Source:

Get the adjacency matrix of the graph with all bridges removed (thus the components). Thus the remaining vertices are all part of ring systems.

Returns:

The adjancency matrix of the molecular graph with all bridges removed.

Type
Array.<Array>

getConnectedComponentCount(adjacencyMatrix) → {Number}

Source:

Returns the number of connected components for the graph.

Parameters:
Name Type Description
adjacencyMatrix Array.<Array>

An adjacency matrix.

Returns:

The number of connected components of the supplied graph.

Type
Number

getConnectedComponents(adjacencyMatrix) → {Array.<Set>}

Source:

Returns the connected components of the graph.

Parameters:
Name Type Description
adjacencyMatrix Array.<Array>

An adjacency matrix.

Returns:

Connected components as sets.

Type
Array.<Set>

getCurrentCenterOfMass() → {Vector2}

Source:

Returns the current (positioned vertices so far) center of mass.

Returns:

The current center of mass.

Type
Vector2

getCurrentCenterOfMassInNeigbourhood(vec, ropt) → {Vector2}

Source:

Returns the current (positioned vertices so far) center of mass in the neighbourhood of a given position.

Parameters:
Name Type Attributes Default Description
vec Vector2

The point at which to look for neighbours.

r Number <optional>
currentBondLength*2.0

The radius of vertices to include.

Returns:

The current center of mass.

Type
Vector2

getDistanceMatrix() → {Array.<Array>}

Source:

Get the distance matrix of the graph.

Returns:

The distance matrix of the graph.

Type
Array.<Array>

getDoubleBondCount(vertices) → {Number}

Source:

Get the number of double bonds inside this ring.

Parameters:
Name Type Description
vertices Array.<Vertex>

An array of vertices associated with the current molecule.

Returns:

The number of double bonds inside this ring.

Type
Number

getDrawnNeighbours(vertices) → {Array.<Number>}

Source:

Returns an array of ids of neighbouring vertices that will be drawn (vertex.value.isDrawn === true).

Parameters:
Name Type Description
vertices Array.<Vertex>

An array containing the vertices associated with the current molecule.

Returns:

An array containing the ids of neighbouring vertices that will be drawn.

Type
Array.<Number>

getEdge(vertexIdA, vertexIdB) → {Edge|null}

Source:

Returns the edge between two given vertices.

Parameters:
Name Type Description
vertexIdA Number

A vertex id.

vertexIdB Number

A vertex id.

Returns:

The edge or, if no edge can be found, null.

Type
Edge | null

getEdgeCount(adjacencyMatrix) → {Number}

Source:

Returns the number of edges in a graph defined by an adjacency matrix.

Parameters:
Name Type Description
adjacencyMatrix Array.<Array>

An adjacency matrix.

Returns:

The number of edges in the graph defined by the adjacency matrix.

Type
Number

getEdgeList() → {Array.<Array>}

Source:

Returns an array containing source, target arrays of this graphs edges.

Returns:

An array containing source, target arrays of this graphs edges. Example: [ [ 2, 5 ], [ 6, 9 ] ].

Type
Array.<Array>

getEdgeList(adjacencyMatrix) → {Array.<Array>}

Source:

Returns an edge list constructed form an adjacency matrix.

Parameters:
Name Type Description
adjacencyMatrix Array.<Array>

An adjacency matrix.

Returns:

An edge list. E.g. [ [ 0, 1 ], ..., [ 16, 2 ] ]

Type
Array.<Array>

getEdgeNormals(edge) → {Array.<Vector2>}

Source:

Get the normals of an edge.

Parameters:
Name Type Description
edge Edge

An edge.

Returns:

An array containing two vectors, representing the normals.

Type
Array.<Vector2>

getEdges(vertexId) → {Array.<Number>}

Source:

Returns the ids of edges connected to a vertex.

Parameters:
Name Type Description
vertexId Number

A vertex id.

Returns:

An array containing the ids of edges connected to the vertex.

Type
Array.<Number>

getFusedRings() → {Array.<Ring>}

Source:

Returns an array containing all fused rings associated with this molecule.

Returns:

An array containing all fused rings associated with this molecule.

Type
Array.<Ring>

getHeavyAtomCount() → {Number}

Source:

Returns the number of heavy atoms (non-hydrogen) in the current molecule.

Returns:

The heavy atom count.

Type
Number

getLargestOrAromaticCommonRing(vertexA, vertexB) → {Ring|null}

Source:

Returns the aromatic or largest ring shared by the two vertices.

Parameters:
Name Type Description
vertexA Vertex

A vertex.

vertexB Vertex

A vertex.

Returns:

If an aromatic common ring exists, that ring, else the largest (non-aromatic) ring, else null.

Type
Ring | null

getLastVertexWithAngle(vertexId) → {Vertex}

Source:

Get the last non-null or 0 angle vertex.

Parameters:
Name Type Description
vertexId Number

A vertex id.

Returns:

The last vertex with an angle that was not 0 or null.

Type
Vertex

getLeftChiral() → {Boolean}

Source:

Returns whether or not the atom associated with the left vector (the vector with the smaller x value) is a chiral center.

Returns:

Whether or not the atom associated with the left vector is a chiral center.

Type
Boolean

getLeftElement() → {String}

Source:

Returns the element associated with the left vector (the vector with the smaller x value).

Returns:

The element associated with the left vector.

Type
String

getLeftVector() → {Vector2}

Source:

Returns the left vector (the vector with the smaller x value).

Returns:

The left vector.

Type
Vector2

getLength() → {Number}

Source:

Returns the length of this line.

Returns:

The length of this line.

Type
Number

getMaxBonds() → {Number}

Source:

Get the maximum number of bonds for this atom.

Returns:

The maximum number of bonds of this atom.

Type
Number

getNeighbourCount() → {Number}

Source:

Returns the number of neighbours of this vertex.

Returns:

The number of neighbours.

Type
Number

getNeighbours(vertexIdopt) → {Array.<Number>}

Source:

Returns an array of ids of neighbouring vertices.

Parameters:
Name Type Attributes Default Description
vertexId Number <optional>
null

If a value is supplied, the vertex with this id is excluded from the returned indices.

Returns:

An array containing the ids of neighbouring vertices.

Type
Array.<Number>

getNeighbours(ringConnections, ringId) → {Array.<Number>}

Source:

Retruns the neighbouring rings of a given ring.

Parameters:
Name Type Description
ringConnections Array.<RingConnection>

An array of ring connections containing ring connections associated with the current molecule.

ringId Number

A ring id.

Returns:

An array of ring ids of neighbouring rings.

Type
Array.<Number>

getNextInRing(vertices, ringId, previousVertexId) → {Number}

Source:

Gets the next vertex in the ring in opposide direction to the supplied vertex id.

Parameters:
Name Type Description
vertices Array.<Vertex>

The array of vertices for the current molecule.

ringId Number

The id of the ring containing this vertex.

previousVertexId Number

The id of the previous vertex. The next vertex will be opposite from the vertex with this id as seen from this vertex.

Returns:

The id of the next vertex in the ring.

Type
Number

getNonRingNeighbours(vertexId) → {Array.<Vertex>}

Source:

Returns an array of vertices that are neighbouring a vertix but are not members of a ring (including bridges).

Parameters:
Name Type Description
vertexId Number

A vertex id.

Returns:

An array of vertices.

Type
Array.<Vertex>

getOrderedNeighbours(ringConnections) → {Array.<Object>}

Source:

Returns an array containing the neighbouring rings of this ring ordered by ring size.

Parameters:
Name Type Description
ringConnections Array.<RingConnection>

An array of ring connections associated with the current molecule.

Returns:

An array of neighbouring rings sorted by ring size. Example: { n: 5, neighbour: 1 }.

Type
Array.<Object>

getOverlapScore() → {Object}

Source:

Returns the overlap score of the current molecule based on its positioned vertices. The higher the score, the more overlaps occur in the structure drawing.

Returns:

Returns the total overlap score and the overlap score of each vertex sorted by score (higher to lower). Example: { total: 99, scores: [ { id: 0, score: 22 }, ... ] }

Type
Object

getPathIncludedDistanceMatrices(adjacencyMatrix) → {Object}

Source:

Returnes the two path-included distance matrices used to find the sssr.

Parameters:
Name Type Description
adjacencyMatrix Array.<Array>

An adjacency matrix.

Returns:

The path-included distance matrices. { p1, p2 }

Type
Object

getPolygon(vertices) → {Array.<Vector2>}

Source:

Gets the polygon representation (an array of the ring-members positional vectors) of this ring.

Parameters:
Name Type Description
vertices Array.<Vertex>

An array of vertices representing the current molecule.

Returns:

An array of the positional vectors of the ring members.

Type
Array.<Vector2>

getRightChiral() → {Boolean}

Source:

Returns whether or not the atom associated with the right vector (the vector with the larger x value) is a chiral center.

Returns:

Whether or not the atom associated with the right vector is a chiral center.

Type
Boolean

getRightElement() → {String}

Source:

Returns the element associated with the right vector (the vector with the larger x value).

Returns:

The element associated with the right vector.

Type
String

getRightVector() → {Vector2}

Source:

Returns the right vector (the vector with the larger x value).

Returns:

The right vector.

Type
Vector2

getRing(ringId) → {Ring}

Source:

Gets a ring object from the array of rings associated with the current molecule by its id. The ring id is not equal to the index, since rings can be added and removed when processing bridged rings.

Parameters:
Name Type Description
ringId Number

A ring id.

Returns:

A ring associated with the current molecule.

Type
Ring

getRingbondCount() → {Number}

Source:

Returns the number of ringbonds (breaks in rings to generate the MST of the smiles) within this atom is connected to.

Returns:

The number of ringbonds this atom is connected to.

Type
Number

getRingbondType(vertexA, vertexB) → {String|null}

Source:

Returns the type of the ringbond (e.g. '=' for a double bond). The ringbond represents the break in a ring introduced when creating the MST. If the two vertices supplied as arguments are not part of a common ringbond, the method returns null.

Parameters:
Name Type Description
vertexA Vertex

A vertex.

vertexB Vertex

A vertex.

Returns:

Returns the ringbond type or null, if the two supplied vertices are not connected by a ringbond.

Type
String | null

getRingCandidates(d, pe, pe_prime) → {Array.<Array>}

Source:

Get the ring candidates from the path-included distance matrices.

Parameters:
Name Type Description
d Array.<Array>

The distance matrix.

pe Array.<Array>

A matrix containing the shortest paths.

pe_prime Array.<Array>

A matrix containing the shortest paths + one vertex.

Returns:

The ring candidates.

Type
Array.<Array>

getRingConnection(id) → {RingConnection}

Source:

Get a ring connection with a given id.

Parameters:
Name Type Description
id Number
Returns:

The ring connection with the specified id.

Type
RingConnection

getRingConnections(ringId, ringIds) → {Array.<Number>}

Source:

Get the ring connections between a ring and a set of rings.

Parameters:
Name Type Description
ringId Number

A ring id.

ringIds Array.<Number>

An array of ring ids.

Returns:

An array of ring connection ids.

Type
Array.<Number>

getRingCount() → {Number}

Source:

Returns the ring count of the current molecule.

Returns:

The ring count.

Type
Number

getRings(graph) → {Array.<Array>}

Source:

Returns an array containing arrays, each representing a ring from the smallest set of smallest rings in the graph.

Parameters:
Name Type Description
graph Graph

A Graph object.

Returns:

An array containing arrays, each representing a ring from the smallest set of smallest rings in the group.

Type
Array.<Array>

getRotateAwayFromAngle(vec, center, angle) → {Number}

Source:

Returns the angle in radians used to rotate this vector away from a given vector.

Parameters:
Name Type Description
vec Vector2

The vector this one is rotated away from.

center Vector2

The rotational center.

angle Number

The angle by which to rotate.

Returns:

The angle in radians.

Type
Number

getRotateToAngle(vec, center) → {Number}

Source:

Gets the angles between this vector and another vector around a common center of rotation.

Parameters:
Name Type Description
vec Vector2

Another vector.

center Vector2

The center of rotation.

Returns:

The angle between this vector and another vector around a center of rotation in radians.

Type
Number

getRotateTowardsAngle(vec, center, angle) → {Number}

Source:

Returns the angle in radians used to rotate this vector towards a given vector.

Parameters:
Name Type Description
vec Vector2

The vector this one is rotated towards to.

center Vector2

The rotational center.

angle Number

The angle by which to rotate.

Returns:

The angle in radians.

Type
Number

getSize() → {Number}

Source:

Returns the size (number of members) of this ring.

Returns:

The size (number of members) of this ring.

Type
Number

getSpanningTreeNeighbours(vertexIdopt) → {Array.<Number>}

Source:

Returns a list of ids of vertices neighbouring this one in the original spanning tree, excluding the ringbond connections.

Parameters:
Name Type Attributes Default Description
vertexId Number <optional>
null

If supplied, the vertex with this id is excluded from the array returned.

Returns:

An array containing the ids of the neighbouring vertices.

Type
Array.<Number>

getSpiros() → {Array.<Ring>}

Source:

Returns an array containing all spiros associated with this molecule.

Returns:

An array containing all spiros associated with this molecule.

Type
Array.<Ring>

getSSSR(c, d, adjacencyMatrix, pe, pe_prime, arrBondCount, arrRingCount, nsssr) → {Array.<Set>}

Source:

Searches the candidates for the smallest set of smallest rings.

Parameters:
Name Type Description
c Array.<Array>

The candidates.

d Array.<Array>

The distance matrix.

adjacencyMatrix Array.<Array>

An adjacency matrix.

pe Array.<Array>

A matrix containing the shortest paths.

pe_prime Array.<Array>

A matrix containing the shortest paths + one vertex.

arrBondCount Uint16Array

A matrix containing the bond count of each vertex.

arrRingCount Uint16Array

A matrix containing the number of rings associated with each vertex.

nsssr Number

The theoretical number of rings in the graph.

Returns:

The smallest set of smallest rings.

Type
Array.<Set>

getSubgraphAdjacencyList(vertexIds) → {Array.<Array>}

Source:

Get the adjacency list of a subgraph.

Parameters:
Name Type Description
vertexIds Array.<Number>

An array containing the vertex ids contained within the subgraph.

Returns:

The adjancency list of the subgraph.

Type
Array.<Array>

getSubgraphAdjacencyMatrix(vertexIds) → {Array.<Array>}

Source:

Get the adjacency matrix of a subgraph.

Parameters:
Name Type Description
vertexIds Array.<Number>

An array containing the vertex ids contained within the subgraph.

Returns:

The adjancency matrix of the subgraph.

Type
Array.<Array>

getSubgraphDistanceMatrix(vertexIds) → {Array.<Array>}

Source:

Get the distance matrix of a subgraph.

Parameters:
Name Type Description
vertexIds Array.<Number>

An array containing the vertex ids contained within the subgraph.

Returns:

The distance matrix of the subgraph.

Type
Array.<Array>

getSubringCenter(ring, vertex) → {Vector2}

Source:

Gets the center of a ring contained within a bridged ring and containing a given vertex.

Parameters:
Name Type Description
ring Ring

A bridged ring.

vertex Vertex

A vertex.

Returns:

The center of the subring that containing the vertex.

Type
Vector2

getSubtreeOverlapScore(vertexId, parentVertexId, vertexOverlapScores) → {Object}

Source:

Gets the overlap score of a subtree.

Parameters:
Name Type Description
vertexId Number

A vertex id (the root of the sub-tree).

parentVertexId Number

A vertex id in the previous direction of the subtree.

vertexOverlapScores Array.<Number>

An array containing the vertex overlap scores indexed by vertex id.

Returns:

An object containing the total overlap score and the center of mass of the subtree weighted by overlap score { value: 0.2, center: new Vector2() }.

Type
Object

getTextDirection(vertices) → {String}

Source:

Returns the suggested text direction when text is added at the position of this vertex.

Parameters:
Name Type Description
vertices Array.<Vertex>

The array of vertices for the current molecule.

Returns:

The suggested direction of the text.

Type
String

getTotalOverlapScore() → {Number}

Source:

Returns the total overlap score of the current molecule.

Returns:

The overlap score.

Type
Number

getTreeDepth(vertexId, parentVertexId) → {Number}

Source:

Get the depth of a subtree in the direction opposite to the vertex specified as the parent vertex.

Parameters:
Name Type Description
vertexId Number

A vertex id.

parentVertexId Number

The id of a neighbouring vertex.

Returns:

The depth of the sub-tree.

Type
Number

getVertexList() → {Array.<Number>}

Source:

Returns an array containing the vertex ids of this graph.

Returns:

An array containing all vertex ids of this graph.

Type
Array.<Number>

getVertices(ringConnections, firstRingId, secondRingId) → {Array.<Number>}

Source:

Returns an array of vertex ids associated with a given ring connection.

Parameters:
Name Type Description
ringConnections Array.<RingConnection>

An array of ring connections containing ring connections associated with the current molecule.

firstRingId Number

A ring id.

secondRingId Number

A ring id.

Returns:

An array of vertex ids associated with the ring connection.

Type
Array.<Number>

getVerticesAt(position, radius, excludeVertexId) → {Array.<Number>}

Source:

Returns an array of vertices positioned at a specified location.

Parameters:
Name Type Description
position Vector2

The position to search for vertices.

radius Number

The radius within to search.

excludeVertexId Number

A vertex id to be excluded from the search results.

Returns:

An array containing vertex ids in a given location.

Type
Array.<Number>

hasBridgedRing() → {Boolean}

Source:

Checks whether or not the current molecule a bridged ring.

Returns:

A boolean indicating whether or not the current molecule a bridged ring.

Type
Boolean

hasEdge(vertexIdA, vertexIdB) → {Boolean}

Source:

Check whether or not two vertices are connected by an edge.

Parameters:
Name Type Description
vertexIdA Number

A vertex id.

vertexIdB Number

A vertex id.

Returns:

A boolean indicating whether or not two vertices are connected by an edge.

Type
Boolean

haveCommonRingbond(atomA, atomB) → {Boolean}

Source:

Checks whether or not two atoms share a common ringbond id. A ringbond is a break in a ring created when generating the spanning tree of a structure.

Parameters:
Name Type Description
atomA Atom

An atom.

atomB Atom

An atom.

Returns:

A boolean indicating whether or not two atoms share a common ringbond.

Type
Boolean

initPseudoElements()

Source:

Creates pseudo-elements (such as Et, Me, Ac, Bz, ...) at the position of the carbon sets the involved atoms not to be displayed.

initRings()

Source:

Initializes rings and ringbonds for the current molecule.

innerAngle(n) → {Number}

Source:

Returns the inner angle of a n-sided regular polygon.

Parameters:
Name Type Description
n Number

Number of sides of a regular polygon.

Returns:

The inner angle of a given regular polygon.

Type
Number

intersection(arrA, arrB) → {Array}

Source:

Returns an array containing the intersection between two arrays. That is, values that are common to both arrays.

Parameters:
Name Type Description
arrA Array

An array.

arrB Array

An array.

Returns:

The intersecting vlaues.

Type
Array

invert() → {Vector2}

Source:

Inverts this vector. Same as multiply(-1.0).

Returns:

Returns itself.

Type
Vector2

isBenzeneLike(vertices) → {Boolean}

Source:

Check whether this ring is an implicitly defined benzene-like (e.g. C1=CC=CC=C1) with 6 members and 3 double bonds.

Parameters:
Name Type Description
vertices Array.<Vertex>

An array of vertices associated with the current molecule.

Returns:

A boolean indicating whether or not this ring is an implicitly defined benzene-like.

Type
Boolean

isBridge(ringConnections, vertices, firstRingId, secondRingId) → {Boolean}

Source:

Checks whether or not two rings are connected by a bridged bond.

Parameters:
Name Type Description
ringConnections Array.<RingConnection>

An array of ring connections containing the ring connections associated with the current molecule.

vertices Array.<Vertex>

An array of vertices containing the vertices associated with the current molecule.

firstRingId Number

A ring id.

secondRingId Number

A ring id.

Returns:

A boolean indicating whether or not two rings ar connected by a bridged bond.

Type
Boolean

isBridge(vertices) → {Boolean}

Source:

Checks whether or not this ring connection is a bridge in a bridged ring.

Parameters:
Name Type Description
vertices Array.<Vertex>

The array of vertices associated with the current molecule.

Returns:

A boolean indicating whether or not this ring connection is a bridge.

Type
Boolean

isEdgeInRing(edge) → {Boolean}

Source:

Check whether or not an edge is part of a ring.

Parameters:
Name Type Description
edge Edge

An edge.

Returns:

A boolean indicating whether or not the edge is part of a ring.

Type
Boolean

isEdgeRotatable(edge) → {Boolean}

Source:

Check whether or not an edge is rotatable.

Parameters:
Name Type Description
edge Edge

An edge.

Returns:

A boolean indicating whether or not the edge is rotatable.

Type
Boolean

isHeteroAtom() → {Boolean}

Source:

Returns whether this atom is a heteroatom (not C and not H).

Returns:

A boolean indicating whether this atom is a heteroatom.

Type
Boolean

isInPolygon(polygon) → {Boolean}

Source:

Checks whether a vector lies within a polygon spanned by a set of vectors.

Parameters:
Name Type Description
polygon Array.<Vector2>

An array of vectors spanning the polygon.

Returns:

A boolean indicating whether or not this vector is within a polygon.

Type
Boolean

isPartOfBridgedRing(ringId) → {Boolean}

Source:

Checks whether or not a ring is part of a bridged ring.

Parameters:
Name Type Description
ringId Number

A ring id.

Returns:

A boolean indicating whether or not the supplied ring (by id) is part of a bridged ring system.

Type
Boolean

isPointInRing(vec) → {Boolean}

Source:

Check if a vector is inside any ring.

Parameters:
Name Type Description
vec Vector2

A vector.

Returns:

A boolean indicating whether or not the point (vector) is inside any of the rings associated with the current molecule.

Type
Boolean

isRingAromatic(ring) → {Boolean}

Source:

Check whether or not a ring is an implicitly defined aromatic ring (lower case smiles).

Parameters:
Name Type Description
ring Ring

A ring.

Returns:

A boolean indicating whether or not a ring is implicitly defined as aromatic.

Type
Boolean

isSupersetOf(setA, setB) → {Boolean}

Source:

Checks whether or not a set (setA) is a superset of another set (setB).

Parameters:
Name Type Description
setA Set.<Number>

A set.

setB Set.<Number>

A set.

Returns:

A boolean indicating whether or not setB is a superset of setA.

Type
Boolean

isTerminal() → {Boolean}

Source:

Returns true if this vertex is terminal (has no parent or child vertices), otherwise returns false. Always returns true if associated value has property hasAttachedPseudoElements set to true.

Returns:

A boolean indicating whether or not this vertex is terminal.

Type
Boolean

kkLayout(vertexIds, center, startVertexId, ring)

Source:

Positiones the (sub)graph using Kamada and Kawais algorithm for drawing general undirected graphs. https://pdfs.semanticscholar.org/b8d3/bca50ccc573c5cb99f7d201e8acce6618f04.pdf

Parameters:
Name Type Description
vertexIds Array.<Number>

An array containing vertexIds to be placed using the force based layout.

center Vector2

The center of the layout.

startVertexId Number

A vertex id. Should be the starting vertex - e.g. the first to be positioned and connected to a previously place vertex.

ring Ring

The bridged ring associated with this force-based layout.

length() → {Number}

Source:

Returns the length of this vector.

Returns:

The length of this vector.

Type
Number

lengthSq() → {Number}

Source:

Returns the square of the length of this vector.

Returns:

The square of the length of this vector.

Type
Number

matrixToString(matrix) → {String}

Source:

Creates a printable string from a matrix (2D array).

Parameters:
Name Type Description
matrix Array.<Array>

A 2D array.

Returns:

A string representing the matrix.

Type
String

meanAngle(arr) → {Number}

Source:

Returns the means of the angles contained in an array. In radians.

Parameters:
Name Type Description
arr Array.<Number>

An array containing angles (in radians).

Returns:

The mean angle in radians.

Type
Number

merge(arrA, arrB) → {Array}

Source:

Merges two arrays and returns the result. The first array will be appended to the second array.

Parameters:
Name Type Description
arrA Array

An array.

arrB Array

An array.

Returns:

The merged array.

Type
Array

midpoint(vecA, vecB) → {Vector2}

Source:

Returns the midpoint of a line spanned by two vectors.

Parameters:
Name Type Description
vecA Vector2

A vector spanning the line.

vecB Vector2

A vector spanning the line.

Returns:

The midpoint of the line spanned by two vectors.

Type
Vector2

multiply(vecA, vecB) → {Vector2}

Source:

Multiplies two vectors (value by value) and returns the result.

Parameters:
Name Type Description
vecA Vector2

A vector.

vecB Vector2

A vector.

Returns:

Returns the product of two vectors.

Type
Vector2

multiply(v) → {Vector2}

Source:

Multiply the x and y coordinate values of this vector by the values of another vector.

Parameters:
Name Type Description
v Vector2

A vector.

Returns:

Returns itself.

Type
Vector2

multiplyScalar(vec, scalar) → {Vector2}

Source:

Multiplies two vectors (value by value) and returns the result.

Parameters:
Name Type Description
vec Vector2

A vector.

scalar Number

A scalar.

Returns:

Returns the product of two vectors.

Type
Vector2

multiplyScalar(scalar) → {Vector2}

Source:

Multiply the x and y coordinate values of this vector by a scalar.

Parameters:
Name Type Description
scalar Number

The scalar.

Returns:

Returns itself.

Type
Vector2

neighbouringElementsEqual(arr) → {Boolean}

Source:

Check whether or not the neighbouring elements of this atom equal the supplied array.

Parameters:
Name Type Description
arr Array.<String>

An array containing all the elements that are neighbouring this atom. E.g. ['C', 'O', 'O', 'N']

Returns:

A boolean indicating whether or not the neighbours match the supplied array of elements.

Type
Boolean

normalize() → {Vector2}

Source:

Normalizes this vector.

Returns:

Returns itself.

Type
Vector2

normalized() → {Vector2}

Source:

Returns a normalized copy of this vector.

Returns:

A normalized copy of this vector.

Type
Vector2

normals(vecA, vecB) → {Array.<Vector2>}

Source:

Returns the normals of a line spanned by two vectors.

Parameters:
Name Type Description
vecA Vector2

A vector spanning the line.

vecB Vector2

A vector spanning the line.

Returns:

An array containing the two normals, each represented by a vector.

Type
Array.<Vector2>

parityOfPermutation(arr) → {Number}

Source:

Returns the parity of the permutation (1 or -1)

Parameters:
Name Type Description
arr Array | Uint8Array

An array containing the permutation.

Returns:

The parity of the permutation (1 or -1), where 1 means even and -1 means odd.

Type
Number

pathSetsContain(pathSets, pathSet, bonds, allBonds, arrBondCount, arrRingCount) → {Boolean}

Source:

Checks whether or not a given path already exists in an array of paths.

Parameters:
Name Type Description
pathSets Array.<Set>

An array of sets each representing a path.

pathSet Set.<Number>

A set representing a path.

bonds Array.<Array>

The bonds associated with the current path.

allBonds Array.<Array>

All bonds currently associated with rings in the SSSR set.

arrBondCount Uint16Array

A matrix containing the bond count of each vertex.

arrRingCount Uint16Array

A matrix containing the number of rings associated with each vertex.

Returns:

A boolean indicating whether or not a give path is contained within a set.

Type
Boolean

polyCircumradius(s, n) → {Number}

Source:

Returns the circumradius of a n-sided regular polygon with a given side-length.

Parameters:
Name Type Description
s Number

The side length of the regular polygon.

n Number

The number of sides.

Returns:

The circumradius of the regular polygon.

Type
Number

position()

Source:

Position the vertices according to their bonds and properties.

print(arr) → {String}

Source:

Returns a string representation of an array. If the array contains objects with an id property, the id property is printed for each of the elements.

Parameters:
Name Type Description
arr Array.<Object>

An array.

Properties
Name Type Description
id *

If the array contains an object with the property 'id', the properties value is printed. Else, the array elements value is printend.

Returns:

A string representation of the array.

Type
String

printRingInfo() → {String}

Source:

Returns a string containing a semicolon and new-line separated list of ring properties: Id; Members Count; Neighbours Count; IsSpiro; IsFused; IsBridged; Ring Count (subrings of bridged rings)

Returns:

A string as described in the method description.

Type
String

relativeClockwise(center, vec) → {Number}

Source:

Checks whether or not this vector is in a clockwise or counter-clockwise rotational direction compared to another vector in relation to an arbitrary third vector.

Parameters:
Name Type Description
center Vector2

The central vector.

vec Vector2

Another vector.

Returns:

Returns -1, 0 or 1 if the vector supplied as an argument is clockwise, neutral or counter-clockwise respectively to this vector in relation to an arbitrary third vector.

Type
Number

remove(arr, value) → {Array}

Source:

Remove a value from an array.

Parameters:
Name Type Description
arr Array

An array.

value *

A value to be removed.

Returns:

A new array with the element with a given value removed.

Type
Array

removeAll(arrA, arrB) → {Array}

Source:

Remove all elements contained in one array from another array.

Parameters:
Name Type Description
arrA Array

The array to be filtered.

arrB Array

The array containing elements that will be removed from the other array.

Returns:

The filtered array.

Type
Array

removeRing(ringId)

Source:

Removes a ring from the array of rings associated with the current molecule.

Parameters:
Name Type Description
ringId Number

A ring id.

removeRingConnection(ringConnectionId)

Source:

Removes a ring connection from the array of rings connections associated with the current molecule.

Parameters:
Name Type Description
ringConnectionId Number

A ring connection id.

removeRingConnectionsBetween(vertexIdA, vertexIdB)

Source:

Removes all ring connections between two vertices.

Parameters:
Name Type Description
vertexIdA Number

A vertex id.

vertexIdB Number

A vertex id.

removeUnique(arr, value) → {Array}

Source:

Remove a value from an array with unique values.

Parameters:
Name Type Description
arr Array

An array.

value *

A value to be removed.

Returns:

An array with the element with a given value removed.

Type
Array

reset()

Source:

Resets the transform of the canvas.

resolvePrimaryOverlaps()

Source:

Resolve primary (exact) overlaps, such as two vertices that are connected to the same ring vertex.

resolveSecondaryOverlaps(scores)

Source:

Resolve secondary overlaps. Those overlaps are due to the structure turning back on itself.

Parameters:
Name Type Description
scores Array.<Object>

An array of objects sorted descending by score.

Properties
Name Type Description
id Number

A vertex id.

score Number

The overlap score associated with the vertex id.

restoreRingInformation()

Source:

Restores the most recently backed up information associated with rings.

restoreRings()

Source:

Restores the most recent backed up rings.

rotate(theta) → {Line}

Source:

Rotate the line by a given value (in radians). The center of rotation is the left vector.

Parameters:
Name Type Description
theta Number

The angle (in radians) to rotate the line.

Returns:

This line.

Type
Line

rotate(angle) → {Vector2}

Source:

Rotates this vector by a given number of radians around the origin of the coordinate system.

Parameters:
Name Type Description
angle Number

The angle in radians to rotate the vector.

Returns:

Returns itself.

Type
Vector2

rotateAround(angle, vec) → {Vector2}

Source:

Rotates this vector around another vector.

Parameters:
Name Type Description
angle Number

The angle in radians to rotate the vector.

vec Vector2

The vector which is used as the rotational center.

Returns:

Returns itself.

Type
Vector2

rotateAwayFrom(vec, center, angle)

Source:

Rotates the vector away from a specified vector around a center.

Parameters:
Name Type Description
vec Vector2

The vector this one is rotated away from.

center Vector2

The rotational center.

angle Number

The angle by which to rotate.

rotateDrawing()

Source:

Rotates the drawing to make the widest dimension horizontal.

rotateSubtree(vertexId, parentVertexId, angle, center)

Source:

Rotate an entire subtree by an angle around a center.

Parameters:
Name Type Description
vertexId Number

A vertex id (the root of the sub-tree).

parentVertexId Number

A vertex id in the previous direction of the subtree that is to rotate.

angle Number

An angle in randians.

center Vector2

The rotational center.

rotateTo(vec, center, offsetAngleopt) → {Vector2}

Source:

Rotate a vector around a given center to the same angle as another vector (so that the two vectors and the center are in a line, with both vectors on one side of the center), keeps the distance from this vector to the center.

Parameters:
Name Type Attributes Default Description
vec Vector2

The vector to rotate this vector to.

center Vector2

The rotational center.

offsetAngle Number <optional>
0.0

An additional amount of radians to rotate the vector.

Returns:

Returns itself.

Type
Vector2

rotateToXAxis() → {Line}

Source:

Rotates this line to be aligned with the x-axis. The center of rotation is the left vector.

Returns:

This line.

Type
Line

round(value, decimals) → {Number}

Source:

Rounds a value to a given number of decimals.

Parameters:
Name Type Description
value Number

A number.

decimals Number

The number of decimals.

Returns:

A number rounded to a given number of decimals.

Type
Number

sameSideAs(vecA, vecB, vecC) → {Boolean}

Source:

Checks whether or not this vector is on the same side of a line spanned by two vectors as another vector.

Parameters:
Name Type Description
vecA Vector2

A vector spanning the line.

vecB Vector2

A vector spanning the line.

vecC Vector2

A vector to check whether or not it is on the same side as this vector.

Returns:

Returns a boolean indicating whether or not this vector is on the same side as another vector.

Type
Boolean

scalarProjection(vecA, vecB) → {Number}

Source:

Returns the scalar projection of a vector on another vector.

Parameters:
Name Type Description
vecA Vector2

The vector to be projected.

vecB Vector2

The vector to be projection upon.

Returns:

The scalar component.

Type
Number

scale(vertices)

Source:

Scale the canvas based on vertex positions.

Parameters:
Name Type Description
vertices Array.<Vertex>

An array of vertices containing the vertices associated with the current molecule.

setBondType(bondType)

Source:

Set the bond type of this edge. This also sets the edge weight.

Parameters:
Name Type Description
bondType String

setLeftVector(x, y) → {Line}

Source:

Set the value of the left vector.

Parameters:
Name Type Description
x Number

The x value.

y Number

The y value.

Returns:

This line.

Type
Line

setParentVertexId(parentVertexId)

Source:

Set the vertex id of the parent.

Parameters:
Name Type Description
parentVertexId Number

The parents vertex id.

setPosition(x, y)

Source:

Set the 2D coordinates of the vertex.

Parameters:
Name Type Description
x Number

The x component of the coordinates.

y Number

The y component of the coordinates.

setPositionFromVector(v)

Source:

Set the 2D coordinates of the vertex from a Vector2.

Parameters:
Name Type Description
v Vector2

A 2D vector.

setRightVector(x, y) → {Line}

Source:

Set the value of the right vector.

Parameters:
Name Type Description
x Number

The x value.

y Number

The y value.

Returns:

This line.

Type
Line

setRingCenter(ring)

Source:

Sets the center for a ring.

Parameters:
Name Type Description
ring Ring

A ring.

setTheme(theme)

Source:

Sets a provided theme.

Parameters:
Name Type Description
theme Object

A theme from the smiles drawer options.

shorten(by) → {Line}

Source:

Shortens this line from both directions by a given value (in pixels).

Parameters:
Name Type Description
by Number

The length in pixels to shorten the vector by.

Returns:

This line.

Type
Line

shortenFrom(by) → {Line}

Source:

Shortens this line from the "from" direction by a given value (in pixels).

Parameters:
Name Type Description
by Number

The length in pixels to shorten the vector by.

Returns:

This line.

Type
Line

shortenLeft(by) → {Line}

Source:

Shorten the left side.

Parameters:
Name Type Description
by Number

The length in pixels to shorten the vector by.

Returns:

Returns itself.

Type
Line

shortenRight(by) → {Line}

Source:

Shorten the right side.

Parameters:
Name Type Description
by Number

The length in pixels to shorten the vector by.

Returns:

Returns itself.

Type
Line

shortenTo(by) → {Line}

Source:

Shortens this line from the "to" direction by a given value (in pixels).

Parameters:
Name Type Description
by Number

The length in pixels to shorten the vector by.

Returns:

This line.

Type
Line

sortByAtomicNumberDesc(arr) → {Array.<Object>}

Source:

Sort an array of atomic number information. Where the number is indicated as x, x.y, x.y.z, ...

Parameters:
Name Type Description
arr Array.<Object>

An array of vertex ids with their associated atomic numbers.

Properties
Name Type Description
vertexId Number

A vertex id.

atomicNumber String

The atomic number associated with the vertex id.

Returns:

The array sorted by atomic number. Example of an array entry: { atomicNumber: 2, vertexId: 5 }.

Type
Array.<Object>

subtract(vecA, vecB) → {Vector2}

Source:

Subtracts one vector from another and returns the result as a new vector.

Parameters:
Name Type Description
vecA Vector2

The minuend.

vecB Vector2

The subtrahend.

Returns:

Returns the difference of two vectors.

Type
Vector2

subtract(vec) → {Vector2}

Source:

Subtract the x and y coordinate values of a vector from the x and y coordinate values of this vector.

Parameters:
Name Type Description
vec Vector2

Another vector.

Returns:

Returns itself.

Type
Vector2

threePointangle(vecA, vecB, vecC) → {Number}

Source:

Returns the angle between two vectors based on a third vector in between.

Parameters:
Name Type Description
vecA Vector2

A vector.

vecB Vector2

A (central) vector.

vecC Vector2

A vector.

Returns:

The angle in radians.

Type
Number

toDeg(rad) → {Number}

Source:

Convertes radians to degrees.

Parameters:
Name Type Description
rad Number

An angle in radians.

Returns:

The angle in degrees.

Type
Number

toggle(arr, value) → {Array}

Source:

Toggles the value of an array. If a value is not contained in an array, the array returned will contain all the values of the original array including the value. If a value is contained in an array, the array returned will contain all the values of the original array excluding the value.

Parameters:
Name Type Description
arr Array

An array.

value *

A value to be toggled.

Returns:

The toggled array.

Type
Array

toRad(deg) → {Number}

Source:

Converts degrees to radians.

Parameters:
Name Type Description
deg Number

An angle in degrees.

Returns:

The angle in radians.

Type
Number

toString() → {String}

Source:

Returns a string representation of this vector.

Returns:

A string representation of this vector.

Type
String

traverseBF(startVertexId, callback)

Source:

Traverses the graph in breadth-first order.

Parameters:
Name Type Description
startVertexId Number

The id of the starting vertex.

callback function

The callback function to be called on every vertex.

traverseTree(vertexId, parentVertexId, callback, maxDepthopt, ignoreFirstopt, depthopt, visitedopt)

Source:

Traverse a sub-tree in the graph.

Parameters:
Name Type Attributes Default Description
vertexId Number

A vertex id.

parentVertexId Number

A neighbouring vertex.

callback function

The callback function that is called with each visited as an argument.

maxDepth Number <optional>
Number.MAX_SAFE_INTEGER

The maximum depth of the recursion.

ignoreFirst Boolean <optional>
false

Whether or not to ignore the starting vertex supplied as vertexId in the callback.

depth Number <optional>
1

The current depth in the tree.

visited Uint8Array <optional>
null

An array holding a flag on whether or not a node has been visited.

unique(arr) → {Array}

Source:

Returns an array of unique elements contained in an array.

Parameters:
Name Type Description
arr Array

An array.

Returns:

An array of unique elements contained within the array supplied as an argument.

Type
Array

units(vecA, vecB) → {Array.<Vector2>}

Source:

Returns the unit (normalized normal) vectors of a line spanned by two vectors.

Parameters:
Name Type Description
vecA Vector2

A vector spanning the line.

vecB Vector2

A vector spanning the line.

Returns:

An array containing the two unit vectors.

Type
Array.<Vector2>

updateOther(ringId, otherRingId)

Source:

Update the ring id of this ring connection that is not the ring id supplied as the second argument.

Parameters:
Name Type Description
ringId Number

A ring id. The new ring id to be set.

otherRingId Number

A ring id. The id that is NOT to be updated.

updateSize(width, height)

Source:

Update the width and height of the canvas

Parameters:
Name Type Description
width Number
height Number

visitStereochemistry(vertexId, previousVertexId, visited, priority, maxDepth, depth)

Source:
Parameters:
Name Type Description
vertexId Number

The id of a vertex.

previousVertexId Number | null

The id of the parent vertex of the vertex.

visited Uint8Array

An array containing the visited flag for all vertices in the graph.

priority Array

An array of arrays storing the atomic numbers for each level.

maxDepth Number

The maximum depth.

depth Number

The current depth.

whichSide(vecA, vecB) → {Number}

Source:

Calculates which side of a line spanned by two vectors this vector is.

Parameters:
Name Type Description
vecA Vector2

A vector.

vecB Vector2

A vector.

Returns:

A number indicating the side of this vector, given a line spanned by two other vectors.

Type
Number