To import chemview you can write and execute the following code in a cell:
In [4]:
from chemview import enable_notebook, MolecularViewer
enable_notebook()
The function enable_notebook will load the necessary files to display the molecular viewer in the browser. To display a benzene molecule we need at least two pieces of information:
For the scope of this tutorial, the information were extracted from here. You can use chemical package (like mdtraj or chemlab) to read the coordinates of your molecules.
We define the coordinates as a numpy array, the atomic types as a list of strings and the bonds as a list of start, end tuples.
In [19]:
import numpy as np
coordinates = np.array([[0.00, 0.13, 0.00], [0.12, 0.07, 0.00], [0.12,-0.07, 0.00],
[0.00,-0.14, 0.00], [-0.12,-0.07, 0.00],[-0.12, 0.07, 0.00],
[ 0.00, 0.24, 0.00], [ 0.21, 0.12, 0.00], [ 0.21,-0.12, 0.00],
[ 0.00,-0.24, 0.00], [-0.21,-0.12, 0.00],[-0.21, 0.12, 0.00]])
atomic_types = ['C', 'C', 'C', 'C', 'C', 'C', 'H', 'H', 'H', 'H', 'H', 'H']
bonds = [(0, 6), (1, 7), (2, 8), (3, 9), (4, 10), (5, 11),
(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 0)]
We can pass those to the class MolecularViewer and call the method lines to render the molecule as a wireframe:
In [20]:
mv = MolecularViewer(coordinates, topology={'atom_types': atomic_types,
'bonds': bonds})
mv.ball_and_sticks()
mv
You can rotate (left click), pan(right click) and zoom (wheel) to visualize your molecules.