Graph

Graph

A class representing the molecular graph.

Constructor

new Graph(parseTree, isomericopt)

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

The vertices of the graph.

edges Array.<Edge>

The edges of this graph.

atomIdxToVertexId Array.<Number>

A map mapping atom indices to vertex ids.

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.

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, parentVertexIdnullable, isBranch)

Source:

PRIVATE FUNCTION. Initializing the graph from the parse tree.

Parameters:
Name Type Attributes Default Description
node Object

The current node in the parse tree.

parentVertexId Number <nullable>
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).

addEdge(edge) → {Number}

Source:

Add an edge to the graph.

Parameters:
Name Type Description
edge 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 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) → {Edge|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
Edge | 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.<Number>}

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

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>

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

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) → {Boolean}

Source:

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

Parameters:
Name Type Description
vertexIdA Number

A vertex id.

vertexIdB Number

A vertex id.

Returns:

A boolean indicating whether or not two vertices are connected by an edge.

Type
Boolean

kkLayout(vertexIds, 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 There are undocumented layout parameters. They are undocumented for a reason, so be very careful.

Parameters:
Name 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.

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.

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

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

The maximum depth of the recursion.

ignoreFirst Boolean <optional>
false

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

depth Number <optional>
1

The current depth in the tree.

visited Uint8Array <optional>
null

An array holding a flag on whether or not a node has been visited.