Constructor
new DrawerBase(options)
- Source:
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. |
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 |
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
annotateStereochemistry()
- Source:
Annotaed stereochemistry information for visualization.
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.<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) → {Ring}
- Source:
Creates a bridged ring.
Parameters:
Name | Type | Description |
---|---|---|
ringIds |
Array.<Number> | An array of ids of rings involved in the bridged ring. |
sourceVertexId |
Number | The vertex id to start the bridged ring discovery from. |
Returns:
The bridged ring.
- Type
- Ring
createNextBond(vertex, previousVertexopt, angleopt, originShortestopt, skipPositioningopt)
- Source:
Positiones the next vertex thus creating a bond.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
vertex |
Vertex | A vertex. |
||
previousVertex |
Vertex |
<optional> |
null
|
The previous vertex which has been positioned. |
angle |
Number |
<optional> |
0.0
|
The (global) angle of the vertex. |
originShortest |
Boolean |
<optional> |
false
|
Whether the origin is the shortest subtree in the branch. |
skipPositioning |
Boolean |
<optional> |
false
|
Whether or not to skip positioning and just check the neighbours. |
createRing(ring, centeropt, startVertexopt, previousVertexopt, previousVertexopt)
- Source:
Creates a new ring, that is, positiones all the vertices inside a ring.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ring |
Ring | The ring to position. |
||
center |
Vector2 | null |
<optional> |
null
|
The center of the ring to be created. |
startVertex |
Vertex | null |
<optional> |
null
|
The first vertex to be positioned inside the ring. |
previousVertex |
Vertex | null |
<optional> |
null
|
The last vertex that was positioned. |
previousVertex |
Boolean |
<optional> |
false
|
A boolean indicating whether or not this ring was force positioned already - this is needed after force layouting a ring, in order to draw rings connected to it. |
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 | HTMLCanvasElement | 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
getBridgedRingRings(ringId) → {Array.<Number>}
- Source:
Returns all rings connected by bridged bonds starting from the ring with the supplied ring id.
Parameters:
Name | Type | Description |
---|---|---|
ringId |
Number | A ring id. |
Returns:
An array containing all ring ids of rings part of a bridged ring system.
- Type
- Array.<Number>
getBridgedRings() → {Array.<Ring>}
- Source:
Returns an array containing the bridged rings associated with this molecule.
Returns:
An array containing all bridged rings associated with this molecule.
- Type
- Array.<Ring>
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.<Number>}
- Source:
Returns an array of ring ids shared by both vertices.
Parameters:
Name | Type | Description |
---|---|---|
vertexA |
Vertex | A vertex. |
vertexB |
Vertex | A vertex. |
Returns:
An array of ids of rings shared by the two vertices.
- Type
- Array.<Number>
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.<Vector2>}
- Source:
Get the normals of an edge.
Parameters:
Name | Type | Description |
---|---|---|
edge |
Edge | An edge. |
Returns:
An array containing two vectors, representing the normals.
- Type
- Array.<Vector2>
getFusedRings() → {Array.<Ring>}
- Source:
Returns an array containing all fused rings associated with this molecule.
Returns:
An array containing all fused rings associated with this molecule.
- Type
- Array.<Ring>
getHeavyAtomCount() → {Number}
- Source:
Returns the number of heavy atoms (non-hydrogen) in the current molecule.
Returns:
The heavy atom count.
- Type
- Number
getLargestOrAromaticCommonRing(vertexA, vertexB) → {Ring|null}
- Source:
Returns the aromatic or largest ring shared by the two vertices.
Parameters:
Name | Type | Description |
---|---|---|
vertexA |
Vertex | A vertex. |
vertexB |
Vertex | A vertex. |
Returns:
If an aromatic common ring exists, that ring, else the largest (non-aromatic) ring, else null.
- Type
- Ring | null
getLastVertexWithAngle(vertexId) → {Vertex}
- Source:
Get the last non-null or 0 angle vertex.
Parameters:
Name | Type | Description |
---|---|---|
vertexId |
Number | A vertex id. |
Returns:
The last vertex with an angle that was not 0 or null.
- Type
- Vertex
getMolecularFormula() → {String}
- Source:
Returns the molecular formula of the loaded molecule as a string.
Returns:
The molecular formula.
- Type
- String
getNonRingNeighbours(vertexId) → {Array.<Vertex>}
- Source:
Returns an array of vertices that are neighbouring a vertix but are not members of a ring (including bridges).
Parameters:
Name | Type | Description |
---|---|---|
vertexId |
Number | A vertex id. |
Returns:
An array of vertices.
- Type
- Array.<Vertex>
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
getRingConnection(id) → {RingConnection}
- Source:
Get a ring connection with a given id.
Parameters:
Name | Type | Description |
---|---|---|
id |
Number |
Returns:
The ring connection with the specified id.
- Type
- RingConnection
getRingConnections(ringId, ringIds) → {Array.<Number>}
- Source:
Get the ring connections between a ring and a set of rings.
Parameters:
Name | Type | Description |
---|---|---|
ringId |
Number | A ring id. |
ringIds |
Array.<Number> | An array of ring ids. |
Returns:
An array of ring connection ids.
- Type
- Array.<Number>
getRingCount() → {Number}
- Source:
Returns the ring count of the current molecule.
Returns:
The ring count.
- Type
- Number
getSpiros() → {Array.<Ring>}
- Source:
Returns an array containing all spiros associated with this molecule.
Returns:
An array containing all spiros associated with this molecule.
- Type
- Array.<Ring>
getSubringCenter(ring, vertex) → {Vector2}
- Source:
Gets the center of a ring contained within a bridged ring and containing a given vertex.
Parameters:
Name | Type | Description |
---|---|---|
ring |
Ring | A bridged ring. |
vertex |
Vertex | A vertex. |
Returns:
The center of the subring that containing the vertex.
- Type
- Vector2
getSubtreeOverlapScore(vertexId, parentVertexId, vertexOverlapScores) → {Object}
- Source:
Gets the overlap score of a subtree.
Parameters:
Name | Type | Description |
---|---|---|
vertexId |
Number | A vertex id (the root of the sub-tree). |
parentVertexId |
Number | A vertex id in the previous direction of the subtree. |
vertexOverlapScores |
Array.<Number> | An array containing the vertex overlap scores indexed by vertex id. |
Returns:
An object containing the total overlap score and the center of mass of the subtree weighted by overlap score { value: 0.2, center: new Vector2() }.
- Type
- Object
getTotalOverlapScore() → {Number}
- Source:
Returns the total overlap score of the current molecule.
Returns:
The overlap score.
- Type
- Number
getVerticesAt(position, radius, excludeVertexId) → {Array.<Number>}
- Source:
Returns an array of vertices positioned at a specified location.
Parameters:
Name | Type | Description |
---|---|---|
position |
Vector2 | The position to search for vertices. |
radius |
Number | The radius within to search. |
excludeVertexId |
Number | A vertex id to be excluded from the search results. |
Returns:
An array containing vertex ids in a given location.
- Type
- Array.<Number>
hasBridgedRing() → {Boolean}
- Source:
Checks whether or not the current molecule a bridged ring.
Returns:
A boolean indicating whether or not the current molecule a bridged ring.
- Type
- Boolean
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 |
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
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
|
restoreRingInformation()
- Source:
Restores the most recently backed up information associated with rings.
rotateDrawing()
- Source:
Rotates the drawing to make the widest dimension horizontal.
rotateSubtree(vertexId, parentVertexId, angle, center)
- Source:
Rotate an entire subtree by an angle around a center.
Parameters:
Name | Type | Description |
---|---|---|
vertexId |
Number | A vertex id (the root of the sub-tree). |
parentVertexId |
Number | A vertex id in the previous direction of the subtree that is to rotate. |
angle |
Number | An angle in randians. |
center |
Vector2 | The rotational center. |
setRingCenter(ring)
- Source:
Sets the center for a ring.
Parameters:
Name | Type | Description |
---|---|---|
ring |
Ring | A ring. |
visitStereochemistry(vertexId, previousVertexId, visited, priority, maxDepth, depth)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
vertexId |
Number | The id of a vertex. |
previousVertexId |
Number | null | The id of the parent vertex of the vertex. |
visited |
Uint8Array | An array containing the visited flag for all vertices in the graph. |
priority |
Array | An array of arrays storing the atomic numbers for each level. |
maxDepth |
Number | The maximum depth. |
depth |
Number | The current depth. |