Graph

SmilesDrawer. Graph

A class representing the molecular graph.

Constructor

new Graph(parseTree, isomericopt)

Source:
Properties:
Name Type Description
vertices Array.<SmilesDrawer.Vertex>

The vertices of the graph.

edges Array.<SmilesDrawer.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.

elementCount Object

A map associating element symbols with the number of occurences in this graph.

isometric Boolean

A boolean indicating whether or not the SMILES associated with this graph is isometric.

The constructor of the class Graph.

Parameters:
Name Type Attributes Default Description
parseTree Object

A SMILES parse tree.

isomeric Boolean <optional>
false

A boolean specifying whether or not the SMILES is isomeric.

Methods

(static) _ccCountDfs()

Source:

PRIVATE FUNCTION used by getConnectedComponentCount().

(static) _ccGetDfs()

Source:

PRIVATE FUNCTION used by getConnectedComponents().

(static) getConnectedComponentCount(adjacencyMatrix) → {Number}

Source:

Returns the number of connected components for the graph.

Parameters:
Name Type Description
adjacencyMatrix Array.<Array>

An adjacency matrix.

Returns:

The number of connected components of the supplied graph.

Type
Number

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

Source:

Returns the connected components of the graph.

Parameters:
Name Type Description
adjacencyMatrix Array.<Array>

An adjacency matrix.

Returns:

Connected components as sets.

Type
Array.<Set>

_bridgeDfs()

Source:

PRIVATE FUNCTION used by getBridges().

_init(node, parentVertexId, isBranch)

Source:

PRIVATE FUNCTION. Initializing the graph from the parse tree.

Parameters:
Name Type Default Description
node Object

The current node in the parse tree.

parentVertexId Number null

The id of the previous vertex.

isBranch Boolean false

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

_initInfos()

Source:

PRIVATE FUNCTION. Initializes element counts etc.

addEdge(edge) → {Number}

Source:

Add an edge to the graph.

Parameters:
Name Type Description
edge SmilesDrawer.Edge

A new edge.

Returns:

The edge id of the new edge.

Type
Number

addVertex(vertex) → {Number}

Source:

Add a vertex to the graph.

Parameters:
Name Type Description
vertex SmilesDrawer.Vertex

A new vertex.

Returns:

The vertex id of the new vertex.

Type
Number

clear()

Source:

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

getAdjacencyList() → {Array.<Array>}

Source:

Get the adjacency list of the graph.

Returns:

The adjancency list of the graph.

Type
Array.<Array>

getAdjacencyMatrix() → {Array.<Array>}

Source:

Get the adjacency matrix of the graph.

Returns:

The adjancency matrix of the molecular graph.

Type
Array.<Array>

getBridges() → {Array.<Number>}

Source:

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

Returns:

An array containing the edge ids of the bridges.

Type
Array.<Number>

getComponentsAdjacencyMatrix() → {Array.<Array>}

Source:

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

Returns:

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

Type
Array.<Array>

getDistanceMatrix() → {Array.<Array>}

Source:

Get the distance matrix of the graph.

Returns:

The distance matrix of the graph.

Type
Array.<Array>

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

Source:

Returns the edge between two given vertices.

Parameters:
Name Type Description
vertexIdA Number

A vertex id.

vertexIdB Number

A vertex id.

Returns:

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

Type
Number | null

getEdgeList() → {Array.<Array>}

Source:

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

Returns:

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

Type
Array.<Array>

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

Source:

Returns the ids of edges connected to a vertex.

Parameters:
Name Type Description
vertexId Number

A vertex id.

Returns:

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

Type
Array.<Array>

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

Source:

Get the adjacency list of a subgraph.

Parameters:
Name Type Description
vertexIds Array.<Number>

An array containing the vertex ids contained within the subgraph.

Returns:

The adjancency list of the subgraph.

Type
Array.<Array>

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

Source:

Get the adjacency matrix of a subgraph.

Parameters:
Name Type Description
vertexIds Array.<Number>

An array containing the vertex ids contained within the subgraph.

Returns:

The adjancency matrix of the subgraph.

Type
Array.<Array>

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

Source:

Get the distance matrix of a subgraph.

Parameters:
Name Type Description
vertexIds Array.<Number>

An array containing the vertex ids contained within the subgraph.

Returns:

The distance matrix of the subgraph.

Type
Array.<Array>

getVertexList() → {Array.<Number>}

Source:

Returns an array containing the vertex ids of this graph.

Returns:

An array containing all vertex ids of this graph.

Type
Array.<Number>

hasEdge(vertexIdA, vertexIdB) → {Number|null}

Source:

Returns the edge between two given vertices.

Parameters:
Name Type Description
vertexIdA Number

A vertex id.

vertexIdB Number

A vertex id.

Returns:

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

Type
Number | null

kkLayout(vertexIds, outAdditionallyPositioned, center, startVertexId, ring)

Source:

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

Parameters:
Name Type Description
vertexIds Array.<Number>

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

outAdditionallyPositioned Array.<Array>

Vertices connected to the bridged ring which were also positioned. Include the ring vertex id they are attached to in the form: [ [ vertexId, ringVertexId ] ].

center SmilesDrawer.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 SmilesDrawer.Ring

The bridged ring associated with this force-based layout.

traverseBF(startVertexId, callback)

Source:

Traverses the graph in breadth-first order.

Parameters:
Name Type Description
startVertexId Number

The id of the starting vertex.

callback function

The callback function to be called on every vertex.