Skip to content

Latest commit

 

History

History
3482 lines (2503 loc) · 152 KB

all.md

File metadata and controls

3482 lines (2503 loc) · 152 KB

view on npm

Classes

ArrayHelper

A static class containing helper functions for array-related tasks.

Atom

A class representing an atom.

CanvasWrapper

A class wrapping a canvas element.

Drawer

The main class of the application representing the smiles drawer

Edge

A class representing an edge.

Graph

A class representing the molecular graph.

Line

A class representing a line.

MathHelper

A static class containing helper functions for math-related tasks.

Ring

A class representing a ring.

RingConnection

A class representing a ring connection.

SSSR

A class encapsulating the functionality to find the smallest set of smallest rings in a graph.

Vector2

A class representing a 2D vector.

Vertex

A class representing a vertex.

ArrayHelper

A static class containing helper functions for array-related tasks.

Kind: global class

ArrayHelper.clone(arr) ⇒ *

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

Kind: static method of ArrayHelper
Returns: * - A clone of the array or object.

Param Type Description
arr * The array or object to be cloned.

ArrayHelper.equals(arrA, arrB) ⇒ Boolean

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

Kind: static method of ArrayHelper
Returns: Boolean - A boolean indicating whether or not the two arrays contain the same elements.

Param Type Description
arrA Array An array.
arrB Array An array.

ArrayHelper.print(arr) ⇒ String

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.

Kind: static method of ArrayHelper
Returns: String - A string representation of the array.

Param Type Description
arr [ 'Array' ].<Object> An array.
arr[].id * If the array contains an object with the property 'id', the properties value is printed. Else, the array elements value is printend.

ArrayHelper.each(arr, callback)

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

Kind: static method of ArrayHelper

Param Type Description
arr Array An array.
callback function The callback function that is called for each element.

ArrayHelper.get(arr, property, value) ⇒ *

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

Kind: static method of ArrayHelper
Returns: * - The array element matching the value.

Param 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.

ArrayHelper.contains(arr, options) ⇒ Boolean

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.

Kind: static method of ArrayHelper
Returns: Boolean - A boolean whether or not the array contains a value.

Param Type Description
arr Array An array.
options Object See method description.
options.value * The value for which to check.
[options.property] String The property on which to check.
[options.func] function A custom property function.

ArrayHelper.intersection(arrA, arrB) ⇒ Array

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

Kind: static method of ArrayHelper
Returns: Array - The intersecting vlaues.

Param Type Description
arrA Array An array.
arrB Array An array.

ArrayHelper.unique(arr) ⇒ Array

Returns an array of unique elements contained in an array.

Kind: static method of ArrayHelper
Returns: Array - An array of unique elements contained within the array supplied as an argument.

Param Type Description
arr Array An array.

ArrayHelper.count(arr, value) ⇒ Number

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

Kind: static method of ArrayHelper
Returns: Number - The number of occurences of a value in the array.

Param Type Description
arr Array An array.
value * A value to be counted.

ArrayHelper.toggle(arr, value) ⇒ Array

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.

Kind: static method of ArrayHelper
Returns: Array - The toggled array.

Param Type Description
arr Array An array.
value * A value to be toggled.

ArrayHelper.remove(arr, value) ⇒ Array

Remove a value from an array.

Kind: static method of ArrayHelper
Returns: Array - A new array with the element with a given value removed.

Param Type Description
arr Array An array.
value * A value to be removed.

ArrayHelper.removeUnique(arr, value) ⇒ Array

Remove a value from an array with unique values.

Kind: static method of ArrayHelper
Returns: Array - An array with the element with a given value removed.

Param Type Description
arr Array An array.
value * A value to be removed.

ArrayHelper.removeAll(arrA, arrB) ⇒ Array

Remove all elements contained in one array from another array.

Kind: static method of ArrayHelper
Returns: Array - The filtered array.

Param Type Description
arrA Array The array to be filtered.
arrB Array The array containing elements that will be removed from the other array.

ArrayHelper.merge(arrA, arrB) ⇒ Array

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

Kind: static method of ArrayHelper
Returns: Array - The merged array.

Param Type Description
arrA Array An array.
arrB Array An array.

ArrayHelper.containsAll(arrA, arrB) ⇒ Boolean

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

Kind: static method of ArrayHelper
Returns: Boolean - A boolean indicating whether or not both array contain the same elements.

Param Type Description
arrA Array An array.
arrB Array An array.

ArrayHelper.sortByAtomicNumberDesc(arr) ⇒ [ 'Array' ].<Object>

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

Kind: static method of ArrayHelper
Returns: [ 'Array' ].<Object> - The array sorted by atomic number. Example of an array entry: { atomicNumber: 2, vertexId: 5 }.

Param Type Description
arr [ 'Array' ].<Object> An array of vertex ids with their associated atomic numbers.
arr[].vertexId Number A vertex id.
arr[].atomicNumber String The atomic number associated with the vertex id.

ArrayHelper.deepCopy(arr) ⇒ Array

Copies a an n-dimensional array.

Kind: static method of ArrayHelper
Returns: Array - The copy.

Param Type Description
arr Array The array to be copied.

Atom

A class representing an atom.

Kind: global class
Properties

Name Type Description
element String The element symbol of this atom. Single-letter symbols are always uppercase. Examples: H, C, F, Br, Si, ...
drawExplicit Boolean A boolean indicating whether or not this atom is drawn explicitly (for example, a carbon atom). This overrides the default behaviour.
ringbonds [ 'Array' ].<Object> An array containing the ringbond ids and bond types as specified in the original SMILE.
branchBond String The branch bond as defined in the SMILES.
ringbonds[].id Number The ringbond id as defined in the SMILES.
ringbonds[].bondType String The bond type of the ringbond as defined in the SMILES.
rings [ 'Array' ].<Number> The ids of rings which contain this atom.
bondType String The bond type associated with this array. Examples: -, =, #, ...
isBridge Boolean A boolean indicating whether or not this atom is part of a bridge in a bridged ring (contained by the largest ring).
isBridgeNode Boolean A boolean indicating whether or not this atom is a bridge node (a member of the largest ring in a bridged ring which is connected to a bridge-atom).
originalRings [ 'Array' ].<Number> Used to back up rings when they are replaced by a bridged ring.
bridgedRing Number The id of the bridged ring if the atom is part of a bridged ring.
anchoredRings [ 'Array' ].<Number> The ids of the rings that are anchored to this atom. The centers of anchored rings are translated when this atom is translated.
bracket Object If this atom is defined as a bracket atom in the original SMILES, this object contains all the bracket information. Example: { hcount: {Number}, charge: ['--', '-', '+', '++'], isotope: {Number} }.
plane Number Specifies on which "plane" the atoms is in stereochemical deptictions (-1 back, 0 middle, 1 front).
attachedPseudoElements [ 'Array' ].<Object> A map with containing information for pseudo elements or concatinated elements. The key is comprised of the element symbol and the hydrogen count.
attachedPseudoElement[].element String The element symbol.
attachedPseudoElement[].count Number The number of occurences that match the key.
attachedPseudoElement[].hyrogenCount Number The number of hydrogens attached to each atom matching the key.
hasAttachedPseudoElements Boolean A boolean indicating whether or not this attom will be drawn with an attached pseudo element or concatinated elements.
isDrawn Boolean A boolean indicating whether or not this atom is drawn. In contrast to drawExplicit, the bond is drawn neither.
isConnectedToRing Boolean A boolean indicating whether or not this atom is directly connected (but not a member of) a ring.
neighbouringElements [ 'Array' ].<String> An array containing the element symbols of neighbouring atoms.
isPartOfAromaticRing Boolean A boolean indicating whether or not this atom is part of an explicitly defined aromatic ring. Example: c1ccccc1.
bondCount Number The number of bonds in which this atom is participating.
chirality String The chirality of this atom if it is a stereocenter (R or S).
priority Number The priority of this atom acording to the CIP rules, where 0 is the highest priority.
mainChain Boolean A boolean indicating whether or not this atom is part of the main chain (used for chirality).
hydrogenDirection String The direction of the hydrogen, either up or down. Only for stereocenters with and explicit hydrogen.
subtreeDepth Number The depth of the subtree coming from a stereocenter.

new Atom(element, [bondType])

The constructor of the class Atom.

Param Type Default Description
element String The one-letter code of the element.
[bondType] String '-' The type of the bond associated with this atom.

atom.addNeighbouringElement(element)

Adds a neighbouring element to this atom.

Kind: instance method of Atom

Param Type Description
element String A string representing an element.

atom.attachPseudoElement(element, previousElement, [hydrogenCount], [charge])

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

Kind: instance method of Atom

Param Type 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 0 The number of hydrogens for the element.
[charge] Number 0 The charge for the element.

atom.getAttachedPseudoElements() ⇒ Object

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

Kind: instance method of Atom
Returns: Object - The sorted attached pseudo elements.

atom.getAttachedPseudoElementsCount() ⇒ Number

Returns the number of attached pseudo elements.

Kind: instance method of Atom
Returns: Number - The number of attached pseudo elements.

atom.isHeteroAtom() ⇒ Boolean

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

Kind: instance method of Atom
Returns: Boolean - A boolean indicating whether this atom is a heteroatom.

atom.addAnchoredRing(ringId)

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.

Kind: instance method of Atom

Param Type Description
ringId Number A ring id.

atom.getRingbondCount() ⇒ Number

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

Kind: instance method of Atom
Returns: Number - The number of ringbonds this atom is connected to.

atom.backupRings()

Backs up the current rings.

Kind: instance method of Atom

atom.restoreRings()

Restores the most recent backed up rings.

Kind: instance method of Atom

atom.haveCommonRingbond(atomA, atomB) ⇒ Boolean

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.

Kind: instance method of Atom
Returns: Boolean - A boolean indicating whether or not two atoms share a common ringbond.

Param Type Description
atomA Atom An atom.
atomB Atom An atom.

atom.neighbouringElementsEqual(arr) ⇒ Boolean

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

Kind: instance method of Atom
Returns: Boolean - A boolean indicating whether or not the neighbours match the supplied array of elements.

Param Type Description
arr [ 'Array' ].<String> An array containing all the elements that are neighbouring this atom. E.g. ['C', 'O', 'O', 'N']

atom.getAtomicNumber() ⇒ Number

Get the atomic number of this atom.

Kind: instance method of Atom
Returns: Number - The atomic number of this atom.

atom.getMaxBonds() ⇒ Number

Get the maximum number of bonds for this atom.

Kind: instance method of Atom
Returns: Number - The maximum number of bonds of this atom.

Atom.maxBonds

A map mapping element symbols to their maximum bonds.

Kind: static property of Atom

Atom.atomicNumbers

A map mapping element symbols to the atomic number.

Kind: static property of Atom

Atom.mass

A map mapping element symbols to the atomic mass.

Kind: static property of Atom

CanvasWrapper

A class wrapping a canvas element.

Kind: global class
Properties

Name Type Description
canvas HTMLElement The HTML element for the canvas associated with this CanvasWrapper instance.
ctx CanvasRenderingContext2D The CanvasRenderingContext2D of the canvas associated with this CanvasWrapper instance.
colors Object The colors object as defined in the SmilesDrawer options.
opts Object The SmilesDrawer options.
drawingWidth Number The width of the canvas.
drawingHeight Number The height of the canvas.
offsetX Number The horizontal offset required for centering the drawing.
offsetY Number The vertical offset required for centering the drawing.
fontLarge Number The large font size in pt.
fontSmall Number The small font size in pt.

new CanvasWrapper(target, theme, options)

The constructor for the class CanvasWrapper.

Param Type Description
target String | HTMLElement The canvas id or the canvas HTMLElement.
theme Object A theme from the smiles drawer options.
options Object The smiles drawer options object.

canvasWrapper.updateSize(width, height)

Update the width and height of the canvas

Kind: instance method of CanvasWrapper

Param Type
width Number
height Number

canvasWrapper.setTheme(theme)

Sets a provided theme.

Kind: instance method of CanvasWrapper

Param Type Description
theme Object A theme from the smiles drawer options.

canvasWrapper.scale(vertices)

Scale the canvas based on vertex positions.

Kind: instance method of CanvasWrapper

Param Type Description
vertices [ 'Array' ].<Vertex> An array of vertices containing the vertices associated with the current molecule.

canvasWrapper.reset()

Resets the transform of the canvas.

Kind: instance method of CanvasWrapper

canvasWrapper.getColor(key) ⇒ String

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

Kind: instance method of CanvasWrapper
Returns: String - A color hex value.

Param Type Description
key String The color key in the theme (e.g. C, N, BACKGROUND, ...).

canvasWrapper.drawCircle(x, y, radius, color, [fill], [debug], [debugText])

Draws a circle to a canvas context.

Kind: instance method of CanvasWrapper

Param Type 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 true Whether to fill or stroke the circle.
[debug] Boolean false Draw in debug mode.
[debugText] String '' A debug message.

canvasWrapper.drawLine(line, [dashed], [alpha])

Draw a line to a canvas.

Kind: instance method of CanvasWrapper

Param Type Default Description
line Line A line.
[dashed] Boolean false Whether or not the line is dashed.
[alpha] Number 1.0 The alpha value of the color.

canvasWrapper.drawWedge(line, width)

Draw a wedge on the canvas.

Kind: instance method of CanvasWrapper

Param Type Default Description
line Line A line.
width Number 1 The wedge width.

canvasWrapper.drawDashedWedge(line)

Draw a dashed wedge on the canvas.

Kind: instance method of CanvasWrapper

Param Type Description
line Line A line.

canvasWrapper.drawDebugText(x, y, text)

Draws a debug text message at a given position

Kind: instance method of CanvasWrapper

Param Type Description
x Number The x coordinate.
y Number The y coordinate.
text String The debug text.

canvasWrapper.drawBall(x, y, elementName)

Draw a ball to the canvas.

Kind: instance method of CanvasWrapper

Param 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).

canvasWrapper.drawPoint(x, y, elementName)

Draw a point to the canvas.

Kind: instance method of CanvasWrapper

Param 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).

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

Draw a text to the canvas.

Kind: instance method of CanvasWrapper

Param 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.
attachedPseudoElement.element String The element symbol.
attachedPseudoElement.count Number The number of occurences that match the key.
attachedPseudoElement.hyrogenCount Number The number of hydrogens attached to each atom matching the key.

canvasWrapper.getChargeText(charge) ⇒ String

Translate the integer indicating the charge to the appropriate text.

Kind: instance method of CanvasWrapper
Returns: String - A string representing a charge.

Param Type Description
charge Number The integer indicating the charge.

canvasWrapper.drawDebugPoint(x, y, [debugText], [color])

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

Kind: instance method of CanvasWrapper

Param Type Default Description
x Number The x coordinate.
y Number The y coordindate.
[debugText] String '' A string.
[color] String '#f00' A color in hex form.

canvasWrapper.drawAromaticityRing(ring)

Draws a ring inside a provided ring, indicating aromaticity.

Kind: instance method of CanvasWrapper

Param Type Description
ring Ring A ring.

canvasWrapper.clear()

Clear the canvas.

Kind: instance method of CanvasWrapper

Drawer

The main class of the application representing the smiles drawer

Kind: global class
Properties

Name Type Description
graph Graph The graph associated with this SmilesDrawer.Drawer instance.
ringIdCounter Number An internal counter to keep track of ring ids.
ringConnectionIdCounter Number An internal counter to keep track of ring connection ids.
canvasWrapper CanvasWrapper The CanvasWrapper associated with this SmilesDrawer.Drawer instance.
totalOverlapScore Number The current internal total overlap score.
defaultOptions Object The default options.
opts Object The merged options.
theme Object The current theme.

new Drawer(options)

The constructor for the class SmilesDrawer.

Param Type Description
options Object An object containing custom values for different options. It is merged with the default options.

drawer.extend()

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

Kind: instance method of Drawer

drawer.draw(data, target, themeName, infoOnly)

Draws the parsed smiles data to a canvas element.

Kind: instance method of Drawer

Param 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.

drawer.edgeRingCount(edgeId) ⇒ Number

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

Kind: instance method of Drawer
Returns: Number - The number of rings the provided edge is part of.

Param Type Description
edgeId Number The id of an edge.

drawer.getBridgedRings() ⇒ [ 'Array' ].<Ring>

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

Kind: instance method of Drawer
Returns: [ 'Array' ].<Ring> - An array containing all bridged rings associated with this molecule.

drawer.getFusedRings() ⇒ [ 'Array' ].<Ring>

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

Kind: instance method of Drawer
Returns: [ 'Array' ].<Ring> - An array containing all fused rings associated with this molecule.

drawer.getSpiros() ⇒ [ 'Array' ].<Ring>

Returns an array containing all spiros associated with this molecule.

Kind: instance method of Drawer
Returns: [ 'Array' ].<Ring> - An array containing all spiros associated with this molecule.

drawer.printRingInfo() ⇒ String

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)

Kind: instance method of Drawer
Returns: String - A string as described in the method description.

drawer.rotateDrawing()

Rotates the drawing to make the widest dimension horizontal.

Kind: instance method of Drawer

drawer.getTotalOverlapScore() ⇒ Number

Returns the total overlap score of the current molecule.

Kind: instance method of Drawer
Returns: Number - The overlap score.

drawer.getRingCount() ⇒ Number

Returns the ring count of the current molecule.

Kind: instance method of Drawer
Returns: Number - The ring count.

drawer.hasBridgedRing() ⇒ Boolean

Checks whether or not the current molecule a bridged ring.

Kind: instance method of Drawer
Returns: Boolean - A boolean indicating whether or not the current molecule a bridged ring.

drawer.getHeavyAtomCount() ⇒ Number

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

Kind: instance method of Drawer
Returns: Number - The heavy atom count.

drawer.getMolecularFormula() ⇒ String

Returns the molecular formula of the loaded molecule as a string.

Kind: instance method of Drawer
Returns: String - The molecular formula.

drawer.getRingbondType(vertexA, vertexB) ⇒ String | null

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.

Kind: instance method of Drawer
Returns: String | null - Returns the ringbond type or null, if the two supplied vertices are not connected by a ringbond.

Param Type Description
vertexA Vertex A vertex.
vertexB Vertex A vertex.

drawer.initRings()

Initializes rings and ringbonds for the current molecule.

Kind: instance method of Drawer

drawer.getBridgedRingRings(ringId) ⇒ [ 'Array' ].<Number>

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

Kind: instance method of Drawer
Returns: [ 'Array' ].<Number> - An array containing all ring ids of rings part of a bridged ring system.

Param Type Description
ringId Number A ring id.

drawer.isPartOfBridgedRing(ringId) ⇒ Boolean

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

Kind: instance method of Drawer
Returns: Boolean - A boolean indicating whether or not the supplied ring (by id) is part of a bridged ring system.

Param Type Description
ringId Number A ring id.

drawer.createBridgedRing(ringIds, sourceVertexId) ⇒ Ring

Creates a bridged ring.

Kind: instance method of Drawer
Returns: Ring - The bridged ring.

Param 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.

drawer.areVerticesInSameRing(vertexA, vertexB) ⇒ Boolean

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

Kind: instance method of Drawer
Returns: Boolean - A boolean indicating whether or not the two vertices are in the same ring.

Param Type Description
vertexA Vertex A vertex.
vertexB Vertex A vertex.

drawer.getCommonRings(vertexA, vertexB) ⇒ [ 'Array' ].<Number>

Returns an array of ring ids shared by both vertices.

Kind: instance method of Drawer
Returns: [ 'Array' ].<Number> - An array of ids of rings shared by the two vertices.

Param Type Description
vertexA Vertex A vertex.
vertexB Vertex A vertex.

drawer.getLargestOrAromaticCommonRing(vertexA, vertexB) ⇒ Ring | null

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

Kind: instance method of Drawer
Returns: Ring | null - If an aromatic common ring exists, that ring, else the largest (non-aromatic) ring, else null.

Param Type Description
vertexA Vertex A vertex.
vertexB Vertex A vertex.

drawer.getVerticesAt(position, radius, excludeVertexId) ⇒ [ 'Array' ].<Number>

Returns an array of vertices positioned at a specified location.

Kind: instance method of Drawer
Returns: [ 'Array' ].<Number> - An array containing vertex ids in a given location.

Param 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.

drawer.getClosestVertex(vertex) ⇒ Vertex

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

Kind: instance method of Drawer
Returns: Vertex - The closest vertex.

Param Type Description
vertex Vertex The vertex of which to find the closest other vertex.

drawer.addRing(ring) ⇒ Number

Add a ring to this representation of a molecule.

Kind: instance method of Drawer
Returns: Number - The ring id of the new ring.

Param Type Description
ring Ring A new ring.

drawer.removeRing(ringId)

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

Kind: instance method of Drawer

Param Type Description
ringId Number A ring id.

drawer.getRing(ringId) ⇒ Ring

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.

Kind: instance method of Drawer
Returns: Ring - A ring associated with the current molecule.

Param Type Description
ringId Number A ring id.

drawer.addRingConnection(ringConnection) ⇒ Number

Add a ring connection to this representation of a molecule.

Kind: instance method of Drawer
Returns: Number - The ring connection id of the new ring connection.

Param Type Description
ringConnection RingConnection A new ringConnection.

drawer.removeRingConnection(ringConnectionId)

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

Kind: instance method of Drawer

Param Type Description
ringConnectionId Number A ring connection id.

drawer.removeRingConnectionsBetween(vertexIdA, vertexIdB)

Removes all ring connections between two vertices.

Kind: instance method of Drawer

Param Type Description
vertexIdA Number A vertex id.
vertexIdB Number A vertex id.

drawer.getRingConnection(id) ⇒ RingConnection

Get a ring connection with a given id.

Kind: instance method of Drawer
Returns: RingConnection - The ring connection with the specified id.

Param Type
id Number

drawer.getRingConnections(ringId, ringIds) ⇒ [ 'Array' ].<Number>

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

Kind: instance method of Drawer
Returns: [ 'Array' ].<Number> - An array of ring connection ids.

Param Type Description
ringId Number A ring id.
ringIds [ 'Array' ].<Number> An array of ring ids.

drawer.getOverlapScore() ⇒ Object

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.

Kind: instance method of Drawer
Returns: Object - 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 }, ... ] }

drawer.chooseSide(vertexA, vertexB, sides) ⇒ Object

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.

Kind: instance method of Drawer
Returns: Object - 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 }

Param 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.

drawer.setRingCenter(ring)

Sets the center for a ring.

Kind: instance method of Drawer

Param Type Description
ring Ring A ring.

drawer.getSubringCenter(ring, vertex) ⇒ Vector2

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

Kind: instance method of Drawer
Returns: Vector2 - The center of the subring that containing the vertex.

Param Type Description
ring Ring A bridged ring.
vertex Vertex A vertex.

drawer.drawEdges(debug)

Draw the actual edges as bonds to the canvas.

Kind: instance method of Drawer

Param Type Description
debug Boolean A boolean indicating whether or not to draw debug helpers.

drawer.drawEdge(edgeId, debug)

Draw the an edge as a bonds to the canvas.

Kind: instance method of Drawer

Param Type Description
edgeId Number An edge id.
debug Boolean A boolean indicating whether or not to draw debug helpers.

drawer.drawVertices(debug)

Draws the vertices representing atoms to the canvas.

Kind: instance method of Drawer

Param Type Description
debug Boolean A boolean indicating whether or not to draw debug messages to the canvas.

drawer.position()

Position the vertices according to their bonds and properties.

Kind: instance method of Drawer

drawer.backupRingInformation()

Stores the current information associated with rings.

Kind: instance method of Drawer

drawer.restoreRingInformation()

Restores the most recently backed up information associated with rings.

Kind: instance method of Drawer

drawer.createRing(ring, [center], [startVertex], [previousVertex], [previousVertex])

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

Kind: instance method of Drawer

Param Type Default Description
ring Ring The ring to position.
[center] Vector2 | null The center of the ring to be created.
[startVertex] Vertex | null The first vertex to be positioned inside the ring.
[previousVertex] Vertex | null The last vertex that was positioned.
[previousVertex] Boolean 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.

drawer.rotateSubtree(vertexId, parentVertexId, angle, center)

Rotate an entire subtree by an angle around a center.

Kind: instance method of Drawer

Param 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.

drawer.getSubtreeOverlapScore(vertexId, parentVertexId, vertexOverlapScores) ⇒ Object

Gets the overlap score of a subtree.

Kind: instance method of Drawer
Returns: Object - 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() }.

Param 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.

drawer.getCurrentCenterOfMass() ⇒ Vector2

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

Kind: instance method of Drawer
Returns: Vector2 - The current center of mass.

drawer.getCurrentCenterOfMassInNeigbourhood(vec, [r]) ⇒ Vector2

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

Kind: instance method of Drawer
Returns: Vector2 - The current center of mass.

Param Type Default Description
vec Vector2 The point at which to look for neighbours.
[r] Number currentBondLength*2.0 The radius of vertices to include.

drawer.resolvePrimaryOverlaps()

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

Kind: instance method of Drawer

drawer.resolveSecondaryOverlaps(scores)

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

Kind: instance method of Drawer

Param Type Description
scores [ 'Array' ].<Object> An array of objects sorted descending by score.
scores[].id Number A vertex id.
scores[].score Number The overlap score associated with the vertex id.

drawer.getLastVertexWithAngle(vertexId) ⇒ Vertex

Get the last non-null or 0 angle vertex.

Kind: instance method of Drawer
Returns: Vertex - The last vertex with an angle that was not 0 or null.

Param Type Description
vertexId Number A vertex id.

drawer.createNextBond(vertex, [previousVertex], [angle], [originShortest], [skipPositioning])

Positiones the next vertex thus creating a bond.

Kind: instance method of Drawer

Param Type Default Description
vertex Vertex A vertex.
[previousVertex] Vertex The previous vertex which has been positioned.
[angle] Number 0.0 The (global) angle of the vertex.
[originShortest] Boolean false Whether the origin is the shortest subtree in the branch.
[skipPositioning] Boolean false Whether or not to skip positioning and just check the neighbours.

drawer.getCommonRingbondNeighbour(vertex) ⇒ Number | null

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

Kind: instance method of Drawer
Returns: Number | null - The id of a vertex sharing the edge that is the common bond of two rings with the vertex provided or null, if none.

Param Type Description
vertex Vertex A vertex.

drawer.isPointInRing(vec) ⇒ Boolean

Check if a vector is inside any ring.

Kind: instance method of Drawer
Returns: Boolean - A boolean indicating whether or not the point (vector) is inside any of the rings associated with the current molecule.

Param Type Description
vec Vector2 A vector.

drawer.isEdgeInRing(edge) ⇒ Boolean

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

Kind: instance method of Drawer
Returns: Boolean - A boolean indicating whether or not the edge is part of a ring.

Param Type Description
edge Edge An edge.

drawer.isEdgeRotatable(edge) ⇒ Boolean

Check whether or not an edge is rotatable.

Kind: instance method of Drawer
Returns: Boolean - A boolean indicating whether or not the edge is rotatable.

Param Type Description
edge Edge An edge.

drawer.isRingAromatic(ring) ⇒ Boolean

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

Kind: instance method of Drawer
Returns: Boolean - A boolean indicating whether or not a ring is implicitly defined as aromatic.

Param Type Description
ring Ring A ring.

drawer.getEdgeNormals(edge) ⇒ [ 'Array' ].<Vector2>

Get the normals of an edge.

Kind: instance method of Drawer
Returns: [ 'Array' ].<Vector2> - An array containing two vectors, representing the normals.

Param Type Description
edge Edge An edge.

drawer.getNonRingNeighbours(vertexId) ⇒ [ 'Array' ].<Vertex>

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

Kind: instance method of Drawer
Returns: [ 'Array' ].<Vertex> - An array of vertices.

Param Type Description
vertexId Number A vertex id.

drawer.annotateStereochemistry()

Annotaed stereochemistry information for visualization.

Kind: instance method of Drawer

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

Kind: instance method of Drawer

Param 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.

drawer.initPseudoElements()

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

Kind: instance method of Drawer

Edge

A class representing an edge.

Kind: global class
Properties

Name Type Default Description
id Number The id of this edge.
sourceId Number The id of the source vertex.
targetId Number The id of the target vertex.
weight Number The weight of this edge. That is, the degree of the bond (single bond = 1, double bond = 2, etc).
bondType String '-' The bond type of this edge.
isPartOfAromaticRing Boolean false Whether or not this edge is part of an aromatic ring.
center Boolean false Wheter or not the bond is centered. For example, this affects straight double bonds.
wedge String '' Wedge direction. Either '', 'up' or 'down'

new Edge(sourceId, targetId, [weight])

The constructor for the class Edge.

Param Type Default Description
sourceId Number A vertex id.
targetId Number A vertex id.
[weight] Number 1 The weight of the edge.

edge.setBondType(bondType)

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

Kind: instance method of Edge

Param Type
bondType String

Edge.bonds ⇒ Object

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

Kind: static property of Edge
Returns: Object - The object containing the map.

Graph

A class representing the molecular graph.

Kind: global class
Properties

Name Type Description
vertices [ 'Array' ].<Vertex> The vertices of the graph.
edges [ 'Array' ].<Edge> The edges of this graph.
vertexIdsToEdgeId Object A map mapping vertex ids to the edge between the two vertices. The key is defined as vertexAId + '_' + vertexBId.
isometric Boolean A boolean indicating whether or not the SMILES associated with this graph is isometric.

new Graph(parseTree, [isomeric])

The constructor of the class Graph.

Param Type Default Description
parseTree Object A SMILES parse tree.
[isomeric] Boolean false A boolean specifying whether or not the SMILES is isomeric.

graph._init(node, parentVertexId, isBranch)

PRIVATE FUNCTION. Initializing the graph from the parse tree.

Kind: instance method of Graph

Param Type Default Description
node Object The current node in the parse tree.
parentVertexId Number 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).

graph.clear()

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

Kind: instance method of Graph

graph.addVertex(vertex) ⇒ Number

Add a vertex to the graph.

Kind: instance method of Graph
Returns: Number - The vertex id of the new vertex.

Param Type Description
vertex Vertex A new vertex.

graph.addEdge(edge) ⇒ Number

Add an edge to the graph.

Kind: instance method of Graph
Returns: Number - The edge id of the new edge.

Param Type Description
edge Edge A new edge.

graph.getEdge(vertexIdA, vertexIdB) ⇒ Edge | null

Returns the edge between two given vertices.

Kind: instance method of Graph
Returns: Edge | null - The edge or, if no edge can be found, null.

Param Type Description
vertexIdA Number A vertex id.
vertexIdB Number A vertex id.

graph.getEdges(vertexId) ⇒ [ 'Array' ].<Number>

Returns the ids of edges connected to a vertex.

Kind: instance method of Graph
Returns: [ 'Array' ].<Number> - An array containing the ids of edges connected to the vertex.

Param Type Description
vertexId Number A vertex id.

graph.hasEdge(vertexIdA, vertexIdB) ⇒ Boolean

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

Kind: instance method of Graph
Returns: Boolean - A boolean indicating whether or not two vertices are connected by an edge.

Param Type Description
vertexIdA Number A vertex id.
vertexIdB Number A vertex id.

graph.getVertexList() ⇒ [ 'Array' ].<Number>

Returns an array containing the vertex ids of this graph.

Kind: instance method of Graph
Returns: [ 'Array' ].<Number> - An array containing all vertex ids of this graph.

graph.getEdgeList() ⇒ [ 'Array' ].<Array>

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

Kind: instance method of Graph
Returns: [ 'Array' ].<Array> - An array containing source, target arrays of this graphs edges. Example: [ [ 2, 5 ], [ 6, 9 ] ].

graph.getAdjacencyMatrix() ⇒ [ 'Array' ].<Array>

Get the adjacency matrix of the graph.

Kind: instance method of Graph
Returns: [ 'Array' ].<Array> - The adjancency matrix of the molecular graph.

graph.getComponentsAdjacencyMatrix() ⇒ [ 'Array' ].<Array>

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

Kind: instance method of Graph
Returns: [ 'Array' ].<Array> - The adjancency matrix of the molecular graph with all bridges removed.

graph.getSubgraphAdjacencyMatrix(vertexIds) ⇒ [ 'Array' ].<Array>

Get the adjacency matrix of a subgraph.

Kind: instance method of Graph
Returns: [ 'Array' ].<Array> - The adjancency matrix of the subgraph.

Param Type Description
vertexIds [ 'Array' ].<Number> An array containing the vertex ids contained within the subgraph.

graph.getDistanceMatrix() ⇒ [ 'Array' ].<Array>

Get the distance matrix of the graph.

Kind: instance method of Graph
Returns: [ 'Array' ].<Array> - The distance matrix of the graph.

graph.getSubgraphDistanceMatrix(vertexIds) ⇒ [ 'Array' ].<Array>

Get the distance matrix of a subgraph.

Kind: instance method of Graph
Returns: [ 'Array' ].<Array> - The distance matrix of the subgraph.

Param Type Description
vertexIds [ 'Array' ].<Number> An array containing the vertex ids contained within the subgraph.

graph.getAdjacencyList() ⇒ [ 'Array' ].<Array>

Get the adjacency list of the graph.

Kind: instance method of Graph
Returns: [ 'Array' ].<Array> - The adjancency list of the graph.

graph.getSubgraphAdjacencyList(vertexIds) ⇒ [ 'Array' ].<Array>

Get the adjacency list of a subgraph.

Kind: instance method of Graph
Returns: [ 'Array' ].<Array> - The adjancency list of the subgraph.

Param Type Description
vertexIds [ 'Array' ].<Number> An array containing the vertex ids contained within the subgraph.

graph.getBridges() ⇒ [ 'Array' ].<Number>

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

Kind: instance method of Graph
Returns: [ 'Array' ].<Number> - An array containing the edge ids of the bridges.

graph.traverseBF(startVertexId, callback)

Traverses the graph in breadth-first order.

Kind: instance method of Graph

Param Type Description
startVertexId Number The id of the starting vertex.
callback function The callback function to be called on every vertex.

graph.getTreeDepth(vertexId, parentVertexId) ⇒ Number

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

Kind: instance method of Graph
Returns: Number - The depth of the sub-tree.

Param Type Description
vertexId Number A vertex id.
parentVertexId Number The id of a neighbouring vertex.

graph.traverseTree(vertexId, parentVertexId, callback, [maxDepth], [ignoreFirst], [depth], [visited])

Traverse a sub-tree in the graph.

Kind: instance method of Graph

Param Type 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 Number.MAX_SAFE_INTEGER The maximum depth of the recursion.
[ignoreFirst] Boolean false Whether or not to ignore the starting vertex supplied as vertexId in the callback.
[depth] Number 1 The current depth in the tree.
[visited] Uint8Array An array holding a flag on whether or not a node has been visited.

graph.kkLayout(vertexIds, center, startVertexId, ring)

Positiones the (sub)graph using Kamada and Kawais algorithm for drawing general undirected graphs. https://pdfs.semanticscholar.org/b8d3/bca50ccc573c5cb99f7d201e8acce6618f04.pdf There are undocumented layout parameters. They are undocumented for a reason, so be very careful.

Kind: instance method of Graph

Param 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.

graph._bridgeDfs()

PRIVATE FUNCTION used by getBridges().

Kind: instance method of Graph

Graph.getConnectedComponents(adjacencyMatrix) ⇒ [ 'Array' ].<Set>

Returns the connected components of the graph.

Kind: static method of Graph
Returns: [ 'Array' ].<Set> - Connected components as sets.

Param Type Description
adjacencyMatrix [ 'Array' ].<Array> An adjacency matrix.

Graph.getConnectedComponentCount(adjacencyMatrix) ⇒ Number

Returns the number of connected components for the graph.

Kind: static method of Graph
Returns: Number - The number of connected components of the supplied graph.

Param Type Description
adjacencyMatrix [ 'Array' ].<Array> An adjacency matrix.

Graph._ccCountDfs()

PRIVATE FUNCTION used by getConnectedComponentCount().

Kind: static method of Graph

Graph._ccGetDfs()

PRIVATE FUNCTION used by getConnectedComponents().

Kind: static method of Graph

Line

A class representing a line.

Kind: global class
Properties

Name Type Description
from Vector2 The Vector2 defining the start of the line.
to Vector2 The Vector2 defining the end of the line.
elementFrom String The element symbol associated with the start of the line.
elementTo String The element symbol associated with the end of the line.
chiralFrom Boolean A boolean indicating whether or not the source atom is a chiral center.
chiralTo Boolean A boolean indicating whether or tno the target atom is a chiral center.

new Line([from], [to], [elementFrom], [elementTo], [chiralFrom], [chiralTo])

The constructor for the class Line.

Param Type Default Description
[from] Vector2 new Vector2(0, 0) A vector marking the beginning of the line.
[to] Vector2 new Vector2(0, 0) A vector marking the end of the line.
[elementFrom] string null A one-letter representation of the element associated with the vector marking the beginning of the line.
[elementTo] string null A one-letter representation of the element associated with the vector marking the end of the line.
[chiralFrom] Boolean false Whether or not the from atom is a chiral center.
[chiralTo] Boolean false Whether or not the to atom is a chiral center.

line.clone() ⇒ Line

Clones this line and returns the clone.

Kind: instance method of Line
Returns: Line - A clone of this line.

line.getLength() ⇒ Number

Returns the length of this line.

Kind: instance method of Line
Returns: Number - The length of this line.

line.getAngle() ⇒ Number

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

Kind: instance method of Line
Returns: Number - The angle in radians.

line.getRightVector() ⇒ Vector2

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

Kind: instance method of Line
Returns: Vector2 - The right vector.

line.getLeftVector() ⇒ Vector2

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

Kind: instance method of Line
Returns: Vector2 - The left vector.

line.getRightElement() ⇒ String

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

Kind: instance method of Line
Returns: String - The element associated with the right vector.

line.getLeftElement() ⇒ String

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

Kind: instance method of Line
Returns: String - The element associated with the left vector.

line.getRightChiral() ⇒ Boolean

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

Kind: instance method of Line
Returns: Boolean - Whether or not the atom associated with the right vector is a chiral center.

line.getLeftChiral() ⇒ Boolean

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

Kind: instance method of Line
Returns: Boolean - Whether or not the atom associated with the left vector is a chiral center.

line.setRightVector(x, y) ⇒ Line

Set the value of the right vector.

Kind: instance method of Line
Returns: Line - This line.

Param Type Description
x Number The x value.
y Number The y value.

line.setLeftVector(x, y) ⇒ Line

Set the value of the left vector.

Kind: instance method of Line
Returns: Line - This line.

Param Type Description
x Number The x value.
y Number The y value.

line.rotateToXAxis() ⇒ Line

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

Kind: instance method of Line
Returns: Line - This line.

line.rotate(theta) ⇒ Line

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

Kind: instance method of Line
Returns: Line - This line.

Param Type Description
theta Number The angle (in radians) to rotate the line.

line.shortenFrom(by) ⇒ Line

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

Kind: instance method of Line
Returns: Line - This line.

Param Type Description
by Number The length in pixels to shorten the vector by.

line.shortenTo(by) ⇒ Line

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

Kind: instance method of Line
Returns: Line - This line.

Param Type Description
by Number The length in pixels to shorten the vector by.

line.shortenRight(by) ⇒ Line

Shorten the right side.

Kind: instance method of Line
Returns: Line - Returns itself.

Param Type Description
by Number The length in pixels to shorten the vector by.

line.shortenLeft(by) ⇒ Line

Shorten the left side.

Kind: instance method of Line
Returns: Line - Returns itself.

Param Type Description
by Number The length in pixels to shorten the vector by.

line.shorten(by) ⇒ Line

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

Kind: instance method of Line
Returns: Line - This line.

Param Type Description
by Number The length in pixels to shorten the vector by.

MathHelper

A static class containing helper functions for math-related tasks.

Kind: global class

MathHelper.radFactor

The factor to convert degrees to radians.

Kind: static property of MathHelper

MathHelper.degFactor

The factor to convert radians to degrees.

Kind: static property of MathHelper

MathHelper.twoPI

Two times PI.

Kind: static property of MathHelper

MathHelper.round(value, decimals) ⇒ Number

Rounds a value to a given number of decimals.

Kind: static method of MathHelper
Returns: Number - A number rounded to a given number of decimals.

Param Type Description
value Number A number.
decimals Number The number of decimals.

MathHelper.meanAngle(arr) ⇒ Number

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

Kind: static method of MathHelper
Returns: Number - The mean angle in radians.

Param Type Description
arr [ 'Array' ].<Number> An array containing angles (in radians).

MathHelper.innerAngle(n) ⇒ Number

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

Kind: static method of MathHelper
Returns: Number - The inner angle of a given regular polygon.

Param Type Description
n Number Number of sides of a regular polygon.

MathHelper.polyCircumradius(s, n) ⇒ Number

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

Kind: static method of MathHelper
Returns: Number - The circumradius of the regular polygon.

Param Type Description
s Number The side length of the regular polygon.
n Number The number of sides.

MathHelper.apothem(r, n) ⇒ Number

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

Kind: static method of MathHelper
Returns: Number - The apothem of a n-sided polygon based on its radius.

Param Type Description
r Number The radius.
n Number The number of edges of the regular polygon.

MathHelper.centralAngle(n) ⇒ Number

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

Kind: static method of MathHelper
Returns: Number - The central angle of the n-sided polygon in radians.

Param Type Description
n Number The number of sides of the regular polygon.

MathHelper.toDeg(rad) ⇒ Number

Convertes radians to degrees.

Kind: static method of MathHelper
Returns: Number - The angle in degrees.

Param Type Description
rad Number An angle in radians.

MathHelper.toRad(deg) ⇒ Number

Converts degrees to radians.

Kind: static method of MathHelper
Returns: Number - The angle in radians.

Param Type Description
deg Number An angle in degrees.

MathHelper.parityOfPermutation(arr) ⇒ Number

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

Kind: static method of MathHelper
Returns: Number - The parity of the permutation (1 or -1), where 1 means even and -1 means odd.

Param Type Description
arr Array | Uint8Array An array containing the permutation.

Ring

A class representing a ring.

Kind: global class
Properties

Name Type Description
id Number The id of this ring.
members [ 'Array' ].<Number> An array containing the vertex ids of the ring members.
edges [ 'Array' ].<Number> An array containing the edge ids of the edges between the ring members.
insiders [ 'Array' ].<Number> An array containing the vertex ids of the vertices contained within the ring if it is a bridged ring.
neighbours [ 'Array' ].<Number> An array containing the ids of neighbouring rings.
positioned Boolean A boolean indicating whether or not this ring has been positioned.
center Vector2 The center of this ring.
rings [ 'Array' ].<Ring> The rings contained within this ring if this ring is bridged.
isBridged Boolean A boolean whether or not this ring is bridged.
isPartOfBridged Boolean A boolean whether or not this ring is part of a bridge ring.
isSpiro Boolean A boolean whether or not this ring is part of a spiro.
isFused Boolean A boolean whether or not this ring is part of a fused ring.
centralAngle Number The central angle of this ring.
canFlip Boolean A boolean indicating whether or not this ring allows flipping of attached vertices to the inside of the ring.

new Ring(members)

The constructor for the class Ring.

Param Type Description
members [ 'Array' ].<Number> An array containing the vertex ids of the members of the ring to be created.

ring.clone() ⇒ Ring

Clones this ring and returns the clone.

Kind: instance method of Ring
Returns: Ring - A clone of this ring.

ring.getSize() ⇒ Number

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

Kind: instance method of Ring
Returns: Number - The size (number of members) of this ring.

ring.getPolygon(vertices) ⇒ [ 'Array' ].<Vector2>

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

Kind: instance method of Ring
Returns: [ 'Array' ].<Vector2> - An array of the positional vectors of the ring members.

Param Type Description
vertices [ 'Array' ].<Vertex> An array of vertices representing the current molecule.

ring.getAngle() ⇒ Number

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

Kind: instance method of Ring
Returns: Number - The angle in radians.

ring.eachMember(vertices, callback, startVertexId, previousVertexId)

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

Kind: instance method of Ring

Param 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).

ring.getOrderedNeighbours(ringConnections) ⇒ [ 'Array' ].<Object>

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

Kind: instance method of Ring
Returns: [ 'Array' ].<Object> - An array of neighbouring rings sorted by ring size. Example: { n: 5, neighbour: 1 }.

Param Type Description
ringConnections [ 'Array' ].<RingConnection> An array of ring connections associated with the current molecule.

ring.isBenzeneLike(vertices) ⇒ Boolean

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

Kind: instance method of Ring
Returns: Boolean - A boolean indicating whether or not this ring is an implicitly defined benzene-like.

Param Type Description
vertices [ 'Array' ].<Vertex> An array of vertices associated with the current molecule.

ring.getDoubleBondCount(vertices) ⇒ Number

Get the number of double bonds inside this ring.

Kind: instance method of Ring
Returns: Number - The number of double bonds inside this ring.

Param Type Description
vertices [ 'Array' ].<Vertex> An array of vertices associated with the current molecule.

ring.contains(vertexId) ⇒ Boolean

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

Kind: instance method of Ring
Returns: Boolean - A boolean indicating whether or not this ring contains a member with the given vertex id.

Param Type Description
vertexId Number A vertex id.

RingConnection

A class representing a ring connection.

Kind: global class
Properties

Name Type Description
id Number The id of this ring connection.
firstRingId Number A ring id.
secondRingId Number A ring id.
vertices [ 'Set' ].<Number> A set containing the vertex ids participating in the ring connection.

new RingConnection(firstRing, secondRing)

The constructor for the class RingConnection.

Param Type Description
firstRing Ring A ring.
secondRing Ring A ring.

ringConnection.addVertex(vertexId)

Adding a vertex to the ring connection.

Kind: instance method of RingConnection

Param Type Description
vertexId Number A vertex id.

ringConnection.updateOther(ringId, otherRingId)

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

Kind: instance method of RingConnection

Param 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.

ringConnection.containsRing(ringId) ⇒ Boolean

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

Kind: instance method of RingConnection
Returns: Boolean - A boolean indicating whether or not a ring with a given id participates in this ring connection.

Param Type Description
ringId Number A ring id.

ringConnection.isBridge(vertices) ⇒ Boolean

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

Kind: instance method of RingConnection
Returns: Boolean - A boolean indicating whether or not this ring connection is a bridge.

Param Type Description
vertices [ 'Array' ].<Vertex> The array of vertices associated with the current molecule.

RingConnection.isBridge(ringConnections, vertices, firstRingId, secondRingId) ⇒ Boolean

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

Kind: static method of RingConnection
Returns: Boolean - A boolean indicating whether or not two rings ar connected by a bridged bond.

Param 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.

RingConnection.getNeighbours(ringConnections, ringId) ⇒ [ 'Array' ].<Number>

Retruns the neighbouring rings of a given ring.

Kind: static method of RingConnection
Returns: [ 'Array' ].<Number> - An array of ring ids of neighbouring rings.

Param Type Description
ringConnections [ 'Array' ].<RingConnection> An array of ring connections containing ring connections associated with the current molecule.
ringId Number A ring id.

RingConnection.getVertices(ringConnections, firstRingId, secondRingId) ⇒ [ 'Array' ].<Number>

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

Kind: static method of RingConnection
Returns: [ 'Array' ].<Number> - An array of vertex ids associated with the ring connection.

Param 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.

SSSR

A class encapsulating the functionality to find the smallest set of smallest rings in a graph.

Kind: global class

SSSR.getRings(graph, [experimental]) ⇒ [ 'Array' ].<Array>

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

Kind: static method of SSSR
Returns: [ 'Array' ].<Array> - An array containing arrays, each representing a ring from the smallest set of smallest rings in the group.

Param Type Default Description
graph Graph A Graph object.
[experimental] Boolean false Whether or not to use experimental SSSR.

SSSR.matrixToString(matrix) ⇒ String

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

Kind: static method of SSSR
Returns: String - A string representing the matrix.

Param Type Description
matrix [ 'Array' ].<Array> A 2D array.

SSSR.getPathIncludedDistanceMatrices(adjacencyMatrix) ⇒ Object

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

Kind: static method of SSSR
Returns: Object - The path-included distance matrices. { p1, p2 }

Param Type Description
adjacencyMatrix [ 'Array' ].<Array> An adjacency matrix.

SSSR.getRingCandidates(d, pe, pe_prime) ⇒ [ 'Array' ].<Array>

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

Kind: static method of SSSR
Returns: [ 'Array' ].<Array> - The ring candidates.

Param 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.

SSSR.getSSSR(c, d, adjacencyMatrix, pe, pe_prime, arrBondCount, arrRingCount, nsssr) ⇒ [ 'Array' ].<Set>

Searches the candidates for the smallest set of smallest rings.

Kind: static method of SSSR
Returns: [ 'Array' ].<Set> - The smallest set of smallest rings.

Param 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.

SSSR.getEdgeCount(adjacencyMatrix) ⇒ Number

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

Kind: static method of SSSR
Returns: Number - The number of edges in the graph defined by the adjacency matrix.

Param Type Description
adjacencyMatrix [ 'Array' ].<Array> An adjacency matrix.

SSSR.getEdgeList(adjacencyMatrix) ⇒ [ 'Array' ].<Array>

Returns an edge list constructed form an adjacency matrix.

Kind: static method of SSSR
Returns: [ 'Array' ].<Array> - An edge list. E.g. [ [ 0, 1 ], ..., [ 16, 2 ] ]

Param Type Description
adjacencyMatrix [ 'Array' ].<Array> An adjacency matrix.

SSSR.bondsToAtoms(bonds) ⇒ [ 'Set' ].<Number>

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

Kind: static method of SSSR
Returns: [ 'Set' ].<Number> - An array of vertices.

Param Type Description
bonds Array An array of bonds. A bond is defined as [ sourceVertexId, targetVertexId ].

SSSR.getBondCount(atoms, adjacencyMatrix) ⇒ Number

Returns the number of bonds within a set of atoms.

Kind: static method of SSSR
Returns: Number - The number of bonds in a set of atoms.

Param Type Description
atoms [ 'Set' ].<Number> An array of atom ids.
adjacencyMatrix [ 'Array' ].<Array> An adjacency matrix.

SSSR.pathSetsContain(pathSets, pathSet, bonds, allBonds, arrBondCount, arrRingCount) ⇒ Boolean

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

Kind: static method of SSSR
Returns: Boolean - A boolean indicating whether or not a give path is contained within a set.

Param 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.

SSSR.areSetsEqual(setA, setB) ⇒ Boolean

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

Kind: static method of SSSR
Returns: Boolean - A boolean indicating whether or not the two sets are equal.

Param Type Description
setA [ 'Set' ].<Number> A set.
setB [ 'Set' ].<Number> A set.

SSSR.isSupersetOf(setA, setB) ⇒ Boolean

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

Kind: static method of SSSR
Returns: Boolean - A boolean indicating whether or not setB is a superset of setA.

Param Type Description
setA [ 'Set' ].<Number> A set.
setB [ 'Set' ].<Number> A set.

Vector2

A class representing a 2D vector.

Kind: global class
Properties

Name Type Description
x Number The x component of the vector.
y Number The y component of the vector.

new Vector2(x, y)

The constructor of the class Vector2.

Param Type Description
x Number | Vector2 The initial x coordinate value or, if the single argument, a Vector2 object.
y Number The initial y coordinate value.

vector2.clone() ⇒ Vector2

Clones this vector and returns the clone.

Kind: instance method of Vector2
Returns: Vector2 - The clone of this vector.

vector2.toString() ⇒ String

Returns a string representation of this vector.

Kind: instance method of Vector2
Returns: String - A string representation of this vector.

vector2.add(vec) ⇒ Vector2

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

Kind: instance method of Vector2
Returns: Vector2 - Returns itself.

Param Type Description
vec Vector2 Another vector.

vector2.subtract(vec) ⇒ Vector2

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

Kind: instance method of Vector2
Returns: Vector2 - Returns itself.

Param Type Description
vec Vector2 Another vector.

vector2.divide(scalar) ⇒ Vector2

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

Kind: instance method of Vector2
Returns: Vector2 - Returns itself.

Param Type Description
scalar Number The scalar.

vector2.multiply(v) ⇒ Vector2

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

Kind: instance method of Vector2
Returns: Vector2 - Returns itself.

Param Type Description
v Vector2 A vector.

vector2.multiplyScalar(scalar) ⇒ Vector2

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

Kind: instance method of Vector2
Returns: Vector2 - Returns itself.

Param Type Description
scalar Number The scalar.

vector2.invert() ⇒ Vector2

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

Kind: instance method of Vector2
Returns: Vector2 - Returns itself.

vector2.angle() ⇒ Number

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

Kind: instance method of Vector2
Returns: Number - The angle in radians.

vector2.distance(vec) ⇒ Number

Returns the euclidean distance between this vector and another vector.

Kind: instance method of Vector2
Returns: Number - The euclidean distance between the two vectors.

Param Type Description
vec Vector2 A vector.

vector2.distanceSq(vec) ⇒ Number

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).

Kind: instance method of Vector2
Returns: Number - The squared euclidean distance of the two vectors.

Param Type Description
vec Vector2 Another vector.

vector2.clockwise(vec) ⇒ Number

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.

Kind: instance method of Vector2
Returns: Number - 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.

Param Type Description
vec Vector2 Another vector.

vector2.relativeClockwise(center, vec) ⇒ Number

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.

Kind: instance method of Vector2
Returns: Number - 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.

Param Type Description
center Vector2 The central vector.
vec Vector2 Another vector.

vector2.rotate(angle) ⇒ Vector2

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

Kind: instance method of Vector2
Returns: Vector2 - Returns itself.

Param Type Description
angle Number The angle in radians to rotate the vector.

vector2.rotateAround(angle, vec) ⇒ Vector2

Rotates this vector around another vector.

Kind: instance method of Vector2
Returns: Vector2 - Returns itself.

Param Type Description
angle Number The angle in radians to rotate the vector.
vec Vector2 The vector which is used as the rotational center.

vector2.rotateTo(vec, center, [offsetAngle]) ⇒ Vector2

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.

Kind: instance method of Vector2
Returns: Vector2 - Returns itself.

Param Type Default Description
vec Vector2 The vector to rotate this vector to.
center Vector2 The rotational center.
[offsetAngle] Number 0.0 An additional amount of radians to rotate the vector.

vector2.rotateAwayFrom(vec, center, angle)

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

Kind: instance method of Vector2

Param 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.

vector2.getRotateAwayFromAngle(vec, center, angle) ⇒ Number

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

Kind: instance method of Vector2
Returns: Number - The angle in radians.

Param 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.

vector2.getRotateTowardsAngle(vec, center, angle) ⇒ Number

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

Kind: instance method of Vector2
Returns: Number - The angle in radians.

Param 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.

vector2.getRotateToAngle(vec, center) ⇒ Number

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

Kind: instance method of Vector2
Returns: Number - The angle between this vector and another vector around a center of rotation in radians.

Param Type Description
vec Vector2 Another vector.
center Vector2 The center of rotation.

vector2.isInPolygon(polygon) ⇒ Boolean

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

Kind: instance method of Vector2
Returns: Boolean - A boolean indicating whether or not this vector is within a polygon.

Param Type Description
polygon [ 'Array' ].<Vector2> An array of vectors spanning the polygon.

vector2.length() ⇒ Number

Returns the length of this vector.

Kind: instance method of Vector2
Returns: Number - The length of this vector.

vector2.lengthSq() ⇒ Number

Returns the square of the length of this vector.

Kind: instance method of Vector2
Returns: Number - The square of the length of this vector.

vector2.normalize() ⇒ Vector2

Normalizes this vector.

Kind: instance method of Vector2
Returns: Vector2 - Returns itself.

vector2.normalized() ⇒ Vector2

Returns a normalized copy of this vector.

Kind: instance method of Vector2
Returns: Vector2 - A normalized copy of this vector.

vector2.whichSide(vecA, vecB) ⇒ Number

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

Kind: instance method of Vector2
Returns: Number - A number indicating the side of this vector, given a line spanned by two other vectors.

Param Type Description
vecA Vector2 A vector.
vecB Vector2 A vector.

vector2.sameSideAs(vecA, vecB, vecC) ⇒ Boolean

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

Kind: instance method of Vector2
Returns: Boolean - Returns a boolean indicating whether or not this vector is on the same side as another vector.

Param 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.

Vector2.add(vecA, vecB) ⇒ Vector2

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

Kind: static method of Vector2
Returns: Vector2 - Returns the sum of two vectors.

Param Type Description
vecA Vector2 A summand.
vecB Vector2 A summand.

Vector2.subtract(vecA, vecB) ⇒ Vector2

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

Kind: static method of Vector2
Returns: Vector2 - Returns the difference of two vectors.

Param Type Description
vecA Vector2 The minuend.
vecB Vector2 The subtrahend.

Vector2.multiply(vecA, vecB) ⇒ Vector2

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

Kind: static method of Vector2
Returns: Vector2 - Returns the product of two vectors.

Param Type Description
vecA Vector2 A vector.
vecB Vector2 A vector.

Vector2.multiplyScalar(vec, scalar) ⇒ Vector2

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

Kind: static method of Vector2
Returns: Vector2 - Returns the product of two vectors.

Param Type Description
vec Vector2 A vector.
scalar Number A scalar.

Vector2.midpoint(vecA, vecB) ⇒ Vector2

Returns the midpoint of a line spanned by two vectors.

Kind: static method of Vector2
Returns: Vector2 - The midpoint of the line spanned by two vectors.

Param Type Description
vecA Vector2 A vector spanning the line.
vecB Vector2 A vector spanning the line.

Vector2.normals(vecA, vecB) ⇒ [ 'Array' ].<Vector2>

Returns the normals of a line spanned by two vectors.

Kind: static method of Vector2
Returns: [ 'Array' ].<Vector2> - An array containing the two normals, each represented by a vector.

Param Type Description
vecA Vector2 A vector spanning the line.
vecB Vector2 A vector spanning the line.

Vector2.units(vecA, vecB) ⇒ [ 'Array' ].<Vector2>

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

Kind: static method of Vector2
Returns: [ 'Array' ].<Vector2> - An array containing the two unit vectors.

Param Type Description
vecA Vector2 A vector spanning the line.
vecB Vector2 A vector spanning the line.

Vector2.divide(vecA, vecB) ⇒ Vector2

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

Kind: static method of Vector2
Returns: Vector2 - The fraction of the two vectors.

Param Type Description
vecA Vector2 The dividend.
vecB Vector2 The divisor.

Vector2.divideScalar(vecA, s) ⇒ Vector2

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

Kind: static method of Vector2
Returns: Vector2 - The fraction of the two vectors.

Param Type Description
vecA Vector2 The dividend.
s Number The scalar.

Vector2.dot(vecA, vecB) ⇒ Number

Returns the dot product of two vectors.

Kind: static method of Vector2
Returns: Number - The dot product of two vectors.

Param Type Description
vecA Vector2 A vector.
vecB Vector2 A vector.

Vector2.angle(vecA, vecB) ⇒ Number

Returns the angle between two vectors.

Kind: static method of Vector2
Returns: Number - The angle between two vectors in radians.

Param Type Description
vecA Vector2 A vector.
vecB Vector2 A vector.

Vector2.threePointangle(vecA, vecB, vecC) ⇒ Number

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

Kind: static method of Vector2
Returns: Number - The angle in radians.

Param Type Description
vecA Vector2 A vector.
vecB Vector2 A (central) vector.
vecC Vector2 A vector.

Vector2.scalarProjection(vecA, vecB) ⇒ Number

Returns the scalar projection of a vector on another vector.

Kind: static method of Vector2
Returns: Number - The scalar component.

Param Type Description
vecA Vector2 The vector to be projected.
vecB Vector2 The vector to be projection upon.

Vector2.averageDirection(vecs) ⇒ Vector2

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

Kind: static method of Vector2
Returns: Vector2 - The resulting vector (normalized).

Param Type Description
vecs Array An array containing vectors.

Vertex

A class representing a vertex.

Kind: global class
Properties

Name Type Description
id Number The id of this vertex.
value Atom The atom associated with this vertex.
position Vector2 The position of this vertex.
previousPosition Vector2 The position of the previous vertex.
parentVertexId Number | null The id of the previous vertex.
children [ 'Array' ].<Number> The ids of the children of this vertex.
spanningTreeChildren [ 'Array' ].<Number> The ids of the children of this vertex as defined in the spanning tree defined by the SMILES.
edges [ 'Array' ].<Number> The ids of edges associated with this vertex.
positioned Boolean A boolean indicating whether or not this vertex has been positioned.
angle Number The angle of this vertex.
dir Number The direction of this vertex.
neighbourCount Number The number of neighbouring vertices.
neighbours [ 'Array' ].<Number> The vertex ids of neighbouring vertices.
neighbouringElements [ 'Array' ].<String> The element symbols associated with neighbouring vertices.
forcePositioned Boolean A boolean indicating whether or not this vertex was positioned using a force-based approach.

new Vertex(value, [x], [y])

The constructor for the class Vertex.

Param Type Default Description
value Atom The value associated with this vertex.
[x] Number 0 The initial x coordinate of the positional vector of this vertex.
[y] Number 0 The initial y coordinate of the positional vector of this vertex.

vertex.setPosition(x, y)

Set the 2D coordinates of the vertex.

Kind: instance method of Vertex

Param Type Description
x Number The x component of the coordinates.
y Number The y component of the coordinates.

vertex.setPositionFromVector(v)

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

Kind: instance method of Vertex

Param Type Description
v Vector2 A 2D vector.

vertex.addChild(vertexId)

Add a child vertex id to this vertex.

Kind: instance method of Vertex

Param Type Description
vertexId Number The id of a vertex to be added as a child to this vertex.

vertex.addRingbondChild(vertexId, ringbondIndex)

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.

Kind: instance method of Vertex

Param 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.

vertex.setParentVertexId(parentVertexId)

Set the vertex id of the parent.

Kind: instance method of Vertex

Param Type Description
parentVertexId Number The parents vertex id.

vertex.isTerminal() ⇒ Boolean

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.

Kind: instance method of Vertex
Returns: Boolean - A boolean indicating whether or not this vertex is terminal.

vertex.clone() ⇒ Vertex

Clones this vertex and returns the clone.

Kind: instance method of Vertex
Returns: Vertex - A clone of this vertex.

vertex.equals(vertex) ⇒ Boolean

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

Kind: instance method of Vertex
Returns: Boolean - A boolean indicating whether or not the two vertices have the same id.

Param Type Description
vertex Vertex The vertex to check.

vertex.getAngle([referenceVector], [returnAsDegrees]) ⇒ Number

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.

Kind: instance method of Vertex
Returns: Number - The angle of this vertex.

Param Type Default Description
[referenceVector] Vector2 The reference vector.
[returnAsDegrees] Boolean false If true, returns angle in degrees, else in radians.

vertex.getTextDirection(vertices) ⇒ String

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

Kind: instance method of Vertex
Returns: String - The suggested direction of the text.

Param Type Description
vertices [ 'Array' ].<Vertex> The array of vertices for the current molecule.

vertex.getNeighbours([vertexId]) ⇒ [ 'Array' ].<Number>

Returns an array of ids of neighbouring vertices.

Kind: instance method of Vertex
Returns: [ 'Array' ].<Number> - An array containing the ids of neighbouring vertices.

Param Type Default Description
[vertexId] Number If a value is supplied, the vertex with this id is excluded from the returned indices.

vertex.getDrawnNeighbours(vertices) ⇒ [ 'Array' ].<Number>

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

Kind: instance method of Vertex
Returns: [ 'Array' ].<Number> - An array containing the ids of neighbouring vertices that will be drawn.

Param Type Description
vertices [ 'Array' ].<Vertex> An array containing the vertices associated with the current molecule.

vertex.getNeighbourCount() ⇒ Number

Returns the number of neighbours of this vertex.

Kind: instance method of Vertex
Returns: Number - The number of neighbours.

vertex.getSpanningTreeNeighbours([vertexId]) ⇒ [ 'Array' ].<Number>

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

Kind: instance method of Vertex
Returns: [ 'Array' ].<Number> - An array containing the ids of the neighbouring vertices.

Param Type Default Description
[vertexId] Number If supplied, the vertex with this id is excluded from the array returned.

vertex.getNextInRing(vertices, ringId, previousVertexId) ⇒ Number

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

Kind: instance method of Vertex
Returns: Number - The id of the next vertex in the ring.

Param 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.