Skip to content

Graph Matrices

James Dillon edited this page Jun 12, 2017 · 1 revision

Graph Matrices

A molecule is a chemical graph comprised of nodes (atoms) and edges (bonds) that can be represented numerically in matrix format. Functions to compute the graph matrices of a molecule are provided by the Molecules.topology.matrix module.

Table of Contents

Adjacency Matrix

The adjacency matrix (Molecules.topology.matrix.adjacency) is a square matrix of a hydrogen suppressed graph indicating pairs of adjacent atoms as 1 and non-adjacent atoms as 0.

Example 1

var molecule = Molecules.load.smiles('CC(O)(C)C');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);

//      C1 C2 O3 C4 C5
// C1 [ 0, 1, 0, 0, 0 ]
// C2 [ 1, 0, 1, 1, 1 ]
// O3 [ 0, 1, 0, 0, 0 ]
// C4 [ 0, 1, 0, 0, 0 ]
// C5 [ 0, 1, 0, 0, 0 ]

Example 2

var molecule = Molecules.load.smiles('c1ccccc1');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);

//      c1 c2 c3 c4 c5 c6
// c1 [ 0, 1, 0, 0, 0, 1 ]
// c2 [ 1, 0, 1, 0, 0, 0 ]
// c3 [ 0, 1, 0, 1, 0, 0 ]
// c4 [ 0, 0, 1, 0, 1, 0 ]
// c5 [ 0, 0, 0, 1, 0, 1 ]
// c6 [ 1, 0, 0, 0, 1, 0 ]

Example 3

var molecule = Molecules.load.smiles('NC(C)C(O)=O');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);

//      N1 C2 C3 C4 O5 O6
// N1 [ 0, 1, 0, 0, 0, 0 ]
// C2 [ 1, 0, 1, 1, 0, 0 ]
// C3 [ 0, 1, 0, 0, 0, 0 ]
// C4 [ 0, 1, 0, 0, 1, 1 ]
// O5 [ 0, 0, 0, 1, 0, 0 ]
// O6 [ 0, 0, 0, 1, 0, 0 ]

Back to Top

Degree Matrix

The degree matrix (Molecules.topology.matrix.degree) is a square matrix of a hydrogen suppressed graph that describes the total number of bonds of each atom along the matrix diagonal. The degree matrix is computed from the adjacency matrix of a chemical graph.

Example 1

var molecule = Molecules.load.smiles('CC(O)(C)C');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var degreeMatrix    = Molecules.topology.matrix.degree(adjacencyMatrix);

//      C1 C2 O3 C4 C5
// C1 [ 1, 0, 0, 0, 0 ]
// C2 [ 0, 4, 0, 0, 0 ]
// O3 [ 0, 0, 1, 0, 0 ]
// C4 [ 0, 0, 0, 1, 0 ]
// C5 [ 0, 0, 0, 0, 1 ]

Example 2

var molecule = Molecules.load.smiles('c1ccccc1');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var degreeMatrix    = Molecules.topology.matrix.degree(molecule);

//      c1 c2 c3 c4 c5 c6
// c1 [ 2, 0, 0, 0, 0, 0 ]
// c2 [ 0, 2, 0, 0, 0, 0 ]
// c3 [ 0, 0, 2, 0, 0, 0 ]
// c4 [ 0, 0, 0, 2, 0, 0 ]
// c5 [ 0, 0, 0, 0, 2, 0 ]
// c6 [ 0, 0, 0, 0, 0, 2 ]

Example 3

var molecule = Molecules.load.smiles('NC(C)C(O)=O');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var degreeMatrix    = Molecules.topology.matrix.degree(molecule);

//      N1 C2 C3 C4 O5 O6
// N1 [ 1, 0, 0, 0, 0, 0 ]
// C2 [ 0, 3, 0, 0, 0, 0 ]
// C3 [ 0, 0, 1, 0, 0, 0 ]
// C4 [ 0, 0, 0, 3, 0, 0 ]
// O5 [ 0, 0, 0, 0, 1, 0 ]
// O6 [ 0, 0, 0, 0, 0, 1 ]

Back to Top

Distance Matrix

The distance matrix (Molecules.topology.matrix.distance) is a square matrix of a hydrogen suppressed graph that describes the minimum number of bonds (distance), that separate a pair of atoms. The distance matrix is computed from the adjacency matrix of a chemical graph.

Example 1

var molecule = Molecules.load.smiles('CC(O)(C)C');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var distanceMatrix  = Molecules.topology.matrix.distance(adjacencyMatrix);

//      C1 C2 O3 C4 C5
// C1 [ 0, 1, 2, 2, 2 ]
// C2 [ 1, 0, 1, 1, 1 ]
// O3 [ 2, 1, 0, 2, 2 ]
// C4 [ 2, 1, 2, 0, 2 ]
// C5 [ 2, 1, 2, 2, 0 ]

Example 2

var molecule = Molecules.load.smiles('c1ccccc1');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var distanceMatrix  = Molecules.topology.matrix.distance(adjacencyMatrix);

//      c1 c2 c3 c4 c5 c6
// c1 [ 0, 1, 2, 3, 2, 1 ]
// c2 [ 1, 0, 1, 2, 3, 2 ]
// c3 [ 2, 1, 0, 1, 2, 3 ]
// c4 [ 3, 2, 1, 0, 1, 2 ]
// c5 [ 2, 3, 2, 1, 0, 1 ]
// c6 [ 1, 2, 3, 2, 1, 0 ]

Example 3

var molecule = Molecules.load.smiles('NC(C)C(O)=O');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var distanceMatrix  = Molecules.topology.matrix.distance(adjacencyMatrix);

//      N1 C2 C3 C4 O5 O6
// N1 [ 0, 1, 2, 2, 3, 3 ]
// C2 [ 1, 0, 1, 1, 2, 2 ]
// C3 [ 2, 1, 0, 2, 3, 3 ]
// C4 [ 2, 1, 2, 0, 1, 1 ]
// O5 [ 3, 2, 3, 1, 0, 2 ]
// O6 [ 3, 2, 3, 1, 2, 0 ]

Back to Top

Laplacian Matrix

The Laplacian matrix (Molecules.topology.matrix.laplacian) is a square matrix of a hydrogen suppressed graph. The Laplacian matrix is computed from the adjacency matrix and degree matrix of a chemical graph.

Example 1

var molecule = Molecules.load.smiles('CC(O)(C)C');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var degreeMatrix    = Molecules.topology.matrix.degree(adjacencyMatrix);
var laplacianMatrix = Molecules.topology.matrix.laplacian(adjacencyMatrix, degreeMatrix);

//      C1  C2  O3  C4  C5
// C1 [  1, -1,  0,  0,  0 ]
// C2 [ -1,  4, -1, -1, -1 ]
// O3 [  0, -1,  1,  0,  0 ]
// C4 [  0, -1,  0,  1,  0 ]
// C5 [  0, -1,  0,  0,  1 ]

Example 2

var molecule = Molecules.load.smiles('c1ccccc1');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var degreeMatrix    = Molecules.topology.matrix.degree(adjacencyMatrix);
var laplacianMatrix = Molecules.topology.matrix.laplacian(adjacencyMatrix, degreeMatrix);

//      c1  c2  c3  c4  c5  c6
// c1 [  2, -1,  0,  0,  0, -1 ]
// c2 [ -1,  2, -1,  0,  0,  0 ]
// c3 [  0, -1,  2, -1,  0,  0 ]
// c4 [  0,  0, -1,  2, -1,  0 ]
// c5 [  0,  0,  0, -1,  2, -1 ]
// c6 [ -1,  0,  0,  0, -1,  2 ]

Example 3

var molecule = Molecules.load.smiles('NC(C)C(O)=O');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var degreeMatrix    = Molecules.topology.matrix.degree(adjacencyMatrix);
var laplacianMatrix = Molecules.topology.matrix.laplacian(adjacencyMatrix, degreeMatrix);

//      N1  C2  C3  C4  O5  O6
// N1 [  1, -1,  0,  0,  0,  0 ]
// C2 [ -1,  3, -1, -1,  0,  0 ]
// C3 [  0, -1,  1,  0,  0,  0 ]
// C4 [  0, -1,  0,  3, -1, -1 ]
// O5 [  0,  0,  0, -1,  1,  0 ]
// O6 [  0,  0,  0, -1,  0,  1 ]

Back to Top

Randic Matrix

The Randic matrix (Molecules.topology.matrix.randic) is a square matrix of a hydrogen suppressed graph. The Randic matrix is computed from the adjacency matrix and degree matrix of a chemical graph.

Example 1

var molecule = Molecules.load.smiles('CC(O)(C)C');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var degreeMatrix    = Molecules.topology.matrix.degree(adjacencyMatrix);
var randicMatrix    = Molecules.topology.matrix.randic(adjacencyMatrix, degreeMatrix);

//      C1   C2   O3   C4   C5
// C1 [ 0.0, 0.5, 0.0, 0.0, 0.0 ]
// C2 [ 0.5, 0.0, 0.5, 0.5, 0.5 ]
// O3 [ 0.0, 0.5, 0.0, 0.0, 0.0 ]
// C4 [ 0.0, 0.5, 0.0, 0.0, 0.0 ]
// C5 [ 0.0, 0.5, 0.0, 0.0, 0.0 ]

Example 2

var molecule = Molecules.load.smiles('c1ccccc1');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var degreeMatrix    = Molecules.topology.matrix.degree(adjacencyMatrix);
var randicMatrix    = Molecules.topology.matrix.randic(adjacencyMatrix, degreeMatrix);

//      c1   c2   c3   c4   c5   c6
// c1 [ 0.0, 0.5, 0.0, 0.0, 0.0, 0.5 ]
// c2 [ 0.5, 0.0, 0.5, 0.0, 0.0, 0.0 ]
// c3 [ 0.0, 0.5, 0.0, 0.5, 0.0, 0.0 ]
// c4 [ 0.0, 0.0, 0.5, 0.0, 0.5, 0.0 ]
// c5 [ 0.0, 0.0, 0.0, 0.5, 0.0, 0.5 ]
// c6 [ 0.5, 0.0, 0.0, 0.0, 0.5, 0.0 ]

Example 3

var molecule = Molecules.load.smiles('NC(C)C(O)=O');
var adjacencyMatrix = Molecules.topology.matrix.adjacency(molecule);
var degreeMatrix    = Molecules.topology.matrix.degree(adjacencyMatrix);
var randicMatrix    = Molecules.topology.matrix.randic(adjacencyMatrix, degreeMatrix);

//       N1    C2    C3    C4    O5    O6
// N1 [ 0.00, 0.57, 0.00, 0.00, 0.00, 0.00 ]
// C2 [ 0.57, 0.00, 0.57, 0.33, 0.00, 0.00 ]
// C3 [ 0.00, 0.57, 0.00, 0.00, 0.00, 0.00 ]
// C4 [ 0.00, 0.33, 0.00, 0.00, 0.57, 0.57 ]
// O5 [ 0.00, 0.00, 0.00, 0.57, 0.00, 0.00 ]
// O6 [ 0.00, 0.00, 0.00, 0.57, 0.00, 0.00 ]

Back to Top

Reciprocal Matrix

The reciprocal matrix (Molecules.topology.matrix.reciprocal) is a square matrix of a hydrogen suppressed graph. The reciprocal matrix is computed from the distance matrix of a chemical graph.

Example 1

var molecule = Molecules.load.smiles('CC(O)(C)C');
var adjacencyMatrix  = Molecules.topology.matrix.adjacency(molecule);
var distanceMatrix   = Molecules.topology.matrix.distance(adjacencyMatrix);
var reciprocalMatrix = Molecules.topology.matrix.reciprocal(distanceMatrix);

//      C1   C2   O3   C4   C5
// C1 [ 0.0, 1.0, 0.5, 0.5, 0.5 ]
// C2 [ 1.0, 0.0, 1.0, 1.0, 1.0 ]
// O3 [ 0.5, 1.0, 0.0, 0.5, 0.5 ]
// C4 [ 0.5, 1.0, 0.5, 0.0, 0.5 ]
// C5 [ 0.5, 1.0, 0.5, 0.5, 0.0 ]

Example 2

var molecule = Molecules.load.smiles('c1ccccc1');
var adjacencyMatrix  = Molecules.topology.matrix.adjacency(molecule);
var distanceMatrix   = Molecules.topology.matrix.distance(adjacencyMatrix);
var reciprocalMatrix = Molecules.topology.matrix.reciprocal(distanceMatrix);

//       c1    c2    c3    c4    c5    c6
// c1 [ 0.00, 1.00, 0.50, 0.33, 0.50, 1.00 ]
// c2 [ 1.00, 0.00, 1.00, 0.50, 0.33, 0.50 ]
// c3 [ 0.50, 1.00, 0.00, 1.00, 0.50, 0.33 ]
// c4 [ 0.33, 0.50, 1.00, 0.00, 1.00, 0.50 ]
// c5 [ 0.50, 0.33, 0.50, 1.00, 0.00, 1.00 ]
// c6 [ 1.00, 0.50, 0.33, 0.50, 1.00, 0.00 ]

Example 3

var molecule = Molecules.load.smiles('NC(C)C(O)=O');
var adjacencyMatrix  = Molecules.topology.matrix.adjacency(molecule);
var distanceMatrix   = Molecules.topology.matrix.distance(adjacencyMatrix);
var reciprocalMatrix = Molecules.topology.matrix.reciprocal(distanceMatrix);

//       N1    C2    C3    C4    O5    O6
// N1 [ 0.00, 1.00, 0.50, 0.50, 0.33, 0.33 ]
// C2 [ 1.00, 0.00, 1.00, 1.00, 0.50, 0.50 ]
// C3 [ 0.50, 1.00, 0.00, 0.50, 0.33, 0.33 ]
// C4 [ 0.50, 1.00, 0.50, 0.00, 1.00, 1.00 ]
// O5 [ 0.33, 0.50, 0.33, 1.00, 0.00, 0.50 ]
// O6 [ 0.33, 0.50, 0.33, 1.00, 0.50, 0.00 ]

Back to Top