Giter Site home page Giter Site logo

molecules's Introduction

molecules.js

A chemical graph theory library for JavaScript. Latest demo of molecules.js + d3.js here.

Features

  • Import molecules encoded with SMILES chemical line notation.
  • Compute various graph matrices of a molecule (e.g. adjacency, degree, distance, Laplacian, Randic, reciprocal).
  • Compute several topological indices of a molecule (e.g. Balaban, Harary, Hyper-Wiener, Randic, Wiener).
  • Visualize molecules with d3.js force directed graphs.

Imgur

Getting Started

The Molecules module contains the primary functions for loading, saving, computing graph matrices and computing topological indices.

var Molecules = require('molecules.js');

Introduction

A molecule is a graph comprised of nodes (atoms) and edges (bonds). In molecules.js a molecule is an object with the following schema:

molecule = {
   id : Number,
   name : String,
   atoms : Object,
   bonds : Object,
   properties : {
       mass : Number,
       formula : Object
   } 
}

Loading Molecules

// Create a molecule by parsing a SMILES string 
var molecule = Molecules.load.smiles('NCC(O)O');
// Import a molecule from a JSON file
var molecule = Molecules.load.json(url);

Saving Molecules

// Convert a molecule to JSON format
var data = Molecules.save.json(molecule);
// Convert a molecule to a d3 graph object
var graph = Molecules.save.d3(molecule);

Graph Matrices

// Load a molecule of ethanol ('CCO')
var ethanol = Molecules.load.smiles('CCO');

Adjacency Matrix

// Compute the adjacency matrix of ethanol
var adjacencyMatrix = Molecules.topology.matrix.adjacency(ethanol);

//     C  C  O 
// C [ 0, 1, 0 ]
// C [ 1, 0, 1 ]
// O [ 0, 1, 0 ]

Distance Matrix

// Use the adjacency matrix to compute the distance matrix
var distanceMatrix = Molecules.topology.matrix.distance(adjacencyMatrix);

//     C  C  O
// C [ 0, 1, 2 ]
// C [ 1, 0, 1 ]
// O [ 2, 1, 0 ]

Degree Matrix

// Use the adjacency matrix to compute the degree matrix
var degreeMatrix = Molecules.topology.matrix.degree(adjacencyMatrix);

//     C  C  O
// C [ 1, 0, 0 ] 
// C [ 0, 2, 0 ]
// O [ 0, 0, 1 ]

Reciprocal Matrix

// Use the distance matrix to compute the reciprocal matrix
var reciprocalMatrix = Molecules.topology.matrix.reciprocal(distanceMatrix);

//      C    C    O
// C [ 0.0, 1.0, 0.5 ]
// C [ 1.0, 0.0, 1.0 ]
// C [ 0.5, 1.0, 0.0 ]

Laplacian Matrix

// Use the adjacency and degree matrix to compute the Laplacian matrix
var laplacianMatrix = Molecules.topology.matrix.laplacian(adjacencyMatrix, degreeMatrix);

//      C   C   O
// C [  1, -1,  0 ]
// C [ -1,  2, -1 ]
// C [  0, -1,  1 ]

Randic Matrix

// Use the adjacency and degree matrix to compute the Randic matrix
var randicMatrix = Molecules.topology.matrix.randic(adjacencyMatrix, degreeMatrix);

//       C      C      O
// C [ 0.000, 0.707, 0.000 ]
// C [ 0.707, 0.000, 0.707 ]
// O [ 0.000, 0.707, 0.000 ]

Topological Indices

// Load a molecule of ethanol ('CCO')
var ethanol = Molecules.load.smiles('CCO');

// Compute the following graph matrices
var adjacencyMatrix  = Molecules.topology.matrix.adjacency(ethanol);
var distanceMatrix   = Molecules.topology.matrix.distance(adjacencyMatrix);
var degreeMatrix     = Molecules.topology.matrix.degree(adjacencyMatrix);
var reciprocalMatrix = Molecules.topology.matrix.reciprocal(distanceMatrix);
var randicMatrix     = Molecules.topology.matrix.randic(adjacencyMatrix, degreeMatrix);

Wiener Index

// Use the distance matrix to compute the Wiener index
var wienerIndex = Molecules.topology.index.wiener(distanceMatrix);

// 4.0

Hyper-Wiener Index

// Use the distance matrix to compute the Hyper-Wiener index
var hyperwienerIndex = Molecules.topology.index.hyperwiener(distanceMatrix);

// 5.0

Harary Index

// Use the reciprocal matrix to compute the Harary index
var hararyIndex = Molecules.topology.index.harary(reciprocalMatrix);

// 2.5

Balaban Index

// Use the distance matrix to compute the Balaban index
var balabanIndex = Molecules.topology.index.balaban(distanceMatrix);

// 1.632993

Randic Index

// Use the Randic matrix to compute the Randic index
var randicIndex = Molecules.topology.index.randic(randicMatrix);

// 1.414213

molecules's People

Contributors

chemplexity avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

molecules's Issues

Smiles parser fails

c1ccccc1[C@]2(C(=O)N(C)C(N)=[NH+]2)c3cc(ccc3)-c4ccc(cc4)OC

Uncaught TypeError: Cannot read property 'output' of undefined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.