Drawer

SmilesDrawer. Drawer

The main class of the application representing the smiles drawer

Constructor

new Drawer(options)

Source:
Properties:
Name Type Description
graph SmilesDrawer.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 SmilesDrawer.CanvasWrapper

The SmilesDrawer.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.

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

addRing(ring) → {Number}

Source:

Add a ring to this representation of a molecule.

Parameters:
Name Type Description
ring SmilesDrawer.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 SmilesDrawer.RingConnection

A new ringConnection.

Returns:

The ring connection id of the new ring connection.

Type
Number

areVerticesInSameRing(vertexA, vertexB) → {Boolean}

Source:

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

Parameters:
Name Type Description
vertexA SmilesDrawer.Vertex

A vertex.

vertexB SmilesDrawer.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 SmilesDrawer.Vertex

A vertex.

vertexB SmilesDrawer.Vertex

A vertex.

sides Array.<SmilesDrawer.Vector2>

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

Returns:

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

Type
Object

createBridgedRing(ringIds, sourceVertexId) → {SmilesDrawer.Ring}

Source:

Creates a bridged ring.

Parameters:
Name Type Description
ringIds Array.<Number>

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

sourceVertexId Number

The vertex id to start the bridged ring discovery from.

Returns:

The bridged ring.

Type
SmilesDrawer.Ring

createNextBond(vertex, previousVertex, ringOrAngle, dir, skipPositioningopt)

Source:

Positiones the next vertex thus creating a bond.

Parameters:
Name Type Attributes Default Description
vertex SmilesDrawer.Vertex

A vertex.

previousVertex SmilesDrawer.Vertex

The previous vertex which has been positioned.

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

skipPositioning Boolean <optional>
false

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

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

Source:

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

Parameters:
Name Type Attributes Default Description
ring SmilesDrawer.Ring

The ring to position.

center SmilesDrawer.Vector2 | null <optional>
null

The center of the ring to be created.

startVertex SmilesDrawer.Vertex | null <optional>
null

The first vertex to be positioned inside the ring.

previousVertex SmilesDrawer.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.

drawEdge(edgeId, debug)

Source:

Draw the an edge as a bonds to the canvas.

Parameters:
Name Type Description
edgeId Number

An edge id.

debug Boolean

A boolean indicating whether or not to draw debug helpers.

drawEdges(debug)

Source:

Draw the actual edges as bonds to the canvas.

Parameters:
Name Type Description
debug Boolean

A boolean indicating whether or not to draw debug helpers.

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.

getBondCount(vertex) → {Number}

Source:

Gets the number of bonds of a vertex.

Parameters:
Name Type Description
vertex SmilesDrawer.Vertex

A vertex.

Returns:

The number of bonds the vertex participates in.

Type
Number

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

Source:

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

Parameters:
Name Type Description
ringId Number

A ring id.

Returns:

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

Type
Array.<Number>

getBridgedRings() → {Array.<SmilesDrawer.Ring>}

Source:

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

Returns:

An array containing all bridged rings associated with this molecule.

Type
Array.<SmilesDrawer.Ring>

getClosestVertex(vertex) → {SmilesDrawer.Vertex}

Source:

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

Parameters:
Name Type Description
vertex SmilesDrawer.Vertex

The vertex of which to find the closest other vertex.

Returns:

The closest vertex.

Type
SmilesDrawer.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 SmilesDrawer.Vertex

A vertex.

Returns:

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

Type
Number | null

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

Source:

Returns an array of ring ids shared by both vertices.

Parameters:
Name Type Description
vertexA SmilesDrawer.Vertex

A vertex.

vertexB SmilesDrawer.Vertex

A vertex.

Returns:

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

Type
Array.<Number>

getCurrentCenterOfMass() → {SmilesDrawer.Vector2}

Source:

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

Returns:

The current center of mass.

Type
SmilesDrawer.Vector2

getCurrentCenterOfMassInNeigbourhood(vec, ropt) → {SmilesDrawer.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 SmilesDrawer.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
SmilesDrawer.Vector2

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

Source:

Get the normals of an edge.

Parameters:
Name Type Description
edge SmilesDrawer.Edge

An edge.

Returns:

An array containing two vectors, representing the normals.

Type
Array.<SmilesDrawer.Vector2>

getFusedRings() → {Array.<SmilesDrawer.Ring>}

Source:

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

Returns:

An array containing all fused rings associated with this molecule.

Type
Array.<SmilesDrawer.Ring>

getHeavyAtomCount() → {Number}

Source:

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

Returns:

The heavy atom count.

Type
Number

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

Source:

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

Parameters:
Name Type Description
vertexA SmilesDrawer.Vertex

A vertex.

vertexB SmilesDrawer.Vertex

A vertex.

Returns:

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

Type
SmilesDrawer.Ring | null

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

Source:

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

Parameters:
Name Type Description
vertexId Number

A vertex id.

Returns:

An array of vertices.

Type
Array.<SmilesDrawer.Vertex>

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) → {SmilesDrawer.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
SmilesDrawer.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 SmilesDrawer.Vertex

A vertex.

vertexB SmilesDrawer.Vertex

A vertex.

Returns:

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

Type
String | null

getRingConnection(id) → {SmilesDrawer.RingConnection}

Source:

Get a ring connection with a given id.

Parameters:
Name Type Description
id Number
Returns:

The ring connection with the specified id.

Type
SmilesDrawer.RingConnection

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

Source:

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

Parameters:
Name Type Description
ringId Number

A ring id.

ringIds Array.<Number>

An array of ring ids.

Returns:

An array of ring connection ids.

Type
Array.<Number>

getRingCount() → {Number}

Source:

Returns the ring count of the current molecule.

Returns:

The ring count.

Type
Number

getSpiros() → {Array.<SmilesDrawer.Ring>}

Source:

Returns an array containing all spiros associated with this molecule.

Returns:

An array containing all spiros associated with this molecule.

Type
Array.<SmilesDrawer.Ring>

getSubringCenter(ring, vertex) → {SmilesDrawer.Vector2}

Source:

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

Parameters:
Name Type Description
ring SmilesDrawer.Ring

A bridged ring.

vertex SmilesDrawer.Vertex

A vertex.

Returns:

The center of the subring that containing the vertex.

Type
SmilesDrawer.Vector2

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

Source:

Gets the overlap score of a subtree.

Parameters:
Name Type Description
vertexId Number

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

parentVertexId Number

A vertex id in the previous direction of the subtree.

vertexOverlapScores Array.<Number>

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

Returns:

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

Type
Object

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.<Number>}

Source:

Returns an array of vertices positioned at a specified location.

Parameters:
Name Type Description
position SmilesDrawer.Vector2

The position to search for vertices.

radius Number

The radius within to search.

excludeVertexId Number

A vertex id to be excluded from the search results.

Returns:

An array containing vertex ids in a given location.

Type
Array.<Number>

hasBridgedRing() → {Boolean}

Source:

Checks whether or not the current molecule a bridged ring.

Returns:

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

Type
Boolean

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.

isEdgeInRing(edge) → {Boolean}

Source:

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

Parameters:
Name Type Description
edge SmilesDrawer.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 SmilesDrawer.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 SmilesDrawer.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 SmilesDrawer.Ring

A ring.

Returns:

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

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)

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

An array of objects sorted descending by score.

Properties
Name Type Description
id Number

A vertex id.

score Number

The overlap score associated with the vertex id.

restoreRingInformation()

Source:

Restores the most recently backed up information associated with rings.

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 SmilesDrawer.Vector2

The rotational center.

setRingCenter(ring)

Source:

Sets the center for a ring.

Parameters:
Name Type Description
ring SmilesDrawer.Ring

A ring.

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.