SmilesDrawer

SmilesDrawer

The main class of the application representing the smiles drawer

Constructor

new SmilesDrawer(options)

Source:

The constructor for the class SmilesDrawer.

Parameters:
Name Type Description
options object

An object containing custom values for different options. It is merged with the default options.

Methods

(static) apply(options, themeNameopt)

Source:

Applies the smiles drawer draw function to each canvas element that has a smiles string in the data-smiles attribute.

Parameters:
Name Type Attributes Default Description
options objects

SmilesDrawer options.

themeName string <optional>
'light'

The theme to apply.

(static) clean(smiles) → {string}

Source:

Cleans a SMILES string (removes non-valid characters)

Parameters:
Name Type Description
smiles string

A SMILES string.

Returns:

The clean SMILES string.

Type
string

(static) parse(smiles, successCallback, errorCallback)

Source:

Parses the entered smiles string.

Parameters:
Name Type Description
smiles string

A SMILES string.

successCallback function

A callback that is called on success with the parse tree.

errorCallback function

A callback that is called with the error object on error.

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

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

areConnected(vertexIdA, vertexIdA) → {boolean}

Source:

Checks whether or not two vertices are connected.

Parameters:
Name Type Description
vertexIdA number

A vertex id.

vertexIdA number

A vertex id.

Returns:

A boolean indicating whether or not two vertices are connected.

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

backupRingInformation()

Source:

Stores the current information associated with rings.

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

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

clearPositions()

Source:

Reset the positions of rings and vertices. The previous positions will be backed up.

createBridgedRing(ringIds, sourceVertexId) → {Ring}

Source:

Creates a bridged ring.

Parameters:
Name Type Description
ringIds array

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, previousVertex, ringOrAngle, dir)

Source:

Positiones the next vertex thus creating a bond.

Parameters:
Name Type Description
vertex Vertex

A vertex.

previousVertex Vertex

The previous vertex which has been positioned.

ringOrAngle ring | number

Either a ring or a number. If the vertex is connected to a ring, it is positioned based on the ring center and thus the ring is supplied. If the vertex is not in a ring, an angle (in radians) is supplied.

dir number

Either 1 or -1 to break ties (if no angle can be elucidated.

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.

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.

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.

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.

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

extend()

Source:

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

forceLayout(vertices, center, startVertexId, ring)

Source:

Applies a force-based layout to a set of provided vertices.

Parameters:
Name Type Description
vertices array

An array containing vertices 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.

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

getBridgedRingRings(ringId) → {array}

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

getBridgedRings() → {array}

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

getClosestEndpointVertex(vertex) → {Vertex}

Source:

Returns the closest vertex (connected as well as unconnected), which is an endpoint.

Parameters:
Name Type Description
vertex Vertex

The vertex of which to find the closest other vertex.

Returns:

The closest endpoint vertex.

Type
Vertex

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

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}

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

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

getEdgeNormals(edge) → {array}

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

getEdgeWeight(vertexIdA, vertexIdB) → {number|null}

Source:

Returns the weight of the edge between two given vertices.

Parameters:
Name Type Description
vertexIdA number

A vertex id.

vertexIdB number

A vertex id.

Returns:

The weight of the edge or, if no edge can be found, null.

Type
number | null

getFusedRings() → {array}

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

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

getNonRingNeighbours(vertexId) → {array}

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

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

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

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

getRingConnections(ringId, ringIds) → {array}

Source:

Get the ring connections associated with a ring, the ring connections between two rings or the ring connections between one ring and multiple other rings.

Parameters:
Name Type Default Description
ringId number

A ring id.

ringIds number | array | null null

A ring id, an array of ring ids or null.

Returns:

An array of ring connection ids.

Type
array

getRingCount() → {number}

Source:

Returns the ring count of the current molecule.

Returns:

The ring count.

Type
number

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

Source:

Returns the smallest ring shared by the two vertices.

Parameters:
Name Type Description
vertexA Vertex

A vertex.

vertexB Vertex

A vertex.

Returns:

If a smallest common ring exists, that ring, else null.

Type
Ring | null

getSpiros() → {array}

Source:

Returns an array containing all spiros associated with this molecule.

Returns:

An array containing all spiros associated with this molecule.

Type
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 the provided vertex.

Type
Vector2

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

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

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

Returns:

The overlap score of the subtree.

Type
number

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

getVerticesAt(position, radius, excludeVertexId) → {array}

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

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

initGraph(node, parentVertexId, isBranch)

Source:

Initializes the graph (vertices and edges) based on the tree supplied by the smiles parser.

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

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.

isEdgeInAromaticRing(edge) → {boolean}

Source:

Checks whether or not an edge is part of an explicit aromatic ring (lower case smiles).

Parameters:
Name Type Description
edge Edge

An edge.

Returns:

A boolean indicating whether or not the vertex is part of an explicit aromatic ring.

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

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

isRingConnection(vertexIdA, vertexIdB) → {boolean}

Source:

Check whether or not the two vertices specified span a bond which is a ring connection (fused rings).

Parameters:
Name Type Description
vertexIdA number

A vertex id.

vertexIdB number

A vertex id.

Returns:

Returns a boolean indicating whether or not the two vertices specify a ringbond.

Type
boolean

position()

Source:

Position the vertices according to their bonds and properties.

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); Insiders Count (the number of vertices contained within a bridged ring)

Returns:

A string as described in the method description.

Type
string

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.

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

An array of objects sorted descending by score. An object is in the form of { id: 0, score: 22 }.

restorePositions()

Source:

Restore the positions backed up during the last clearPositions() call.

restoreRingInformation()

Source:

Restores the most recently backed up information associated with rings.

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.

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

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>
null

The maximum depth of the recursion. If null, there is no limit.

ignoreFirst boolean <optional>
false

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