# Molecular visualization software in Jupyter (IPython) Notebooks

Jupyter notebooks have always been a great way for me to create high-quality graphs, and write code.

The features also continue to improve with packages such as Jupyter Lab, and now Jupyter Books, which continue to improve the environment and capabilities of the Jupyter ecosystem.

However, I've never had any luck visualizing 3d structures such as xyz files in Jupyter Notebook.

What packages can be used to visualize 3d structures in Jupyter (IPython)?

Please list any pros/cons, and a link to further documentation/installation instructions. A simple example of some code would also be appreciated.

• It's probably still a bit early, but a similar question should eventually be asked about Pluto notebooks that have recently begun to be used with Julia. – Tyberius Sep 15 '20 at 20:13

### 3Dmol.js

I highly recommend 3Dmol.js through the py3dmol extension.

3Dmol.js is an object-oriented, WebGL based JavaScript library for online molecular visualization - No Java required! With 3Dmol.js, you can add beautifully rendered molecular visualizations to your web applications. Features include:

• support for pdb, sdf, mol2, xyz, and cube formats
• parallelized molecular surface computation
• sphere, stick, line, cross, cartoon, and surface styles
• atom property based selection and styling
• labels
• clickable interactivity with molecular data
• geometric shapes including spheres and arrows

3Dmol.js supports XYZ, CIF, PDB, MMTF, .. a huge variety of file formats, including volumetric data such as Gaussian Cube files, VASP, etc.

Some examples:

• The Kulik group also has a nice function that makes using 3dmol.js easier for different file formats. For example, in that notebook xyz files can be easily visualized with view_xyz(filename,w=700,h=700), multiple geometries can also be viewed at once, with control over column and row dimensions. – Cody Aldaz Oct 18 '20 at 23:31

### NGLVIEW

I discovered it very recently when I was using MDAnalysis to play with molecular dynamic trajectories. Therefore, I am not able to write about pros/cons.

From the site:

An IPython/Jupyter widget to interactively view molecular structures and trajectories. Utilizes the embeddable NGL Viewer for rendering. Support for showing data from the file-system, RCSB PDB, simpletraj and from objects of analysis libraries mdtraj, pytraj, mdanalysis, ParmEd, rdkit, ase, HTMD, biopython, cctbx, pyrosetta, schrodinger's Structure

• Good start. I'll have to try this next time I use molecular dynamics. I Wish they supported xyz files tho. – Cody Aldaz Sep 15 '20 at 19:45
• @CodyAldaz You can display xyz trajectory files in a roundabout way. Use mdanalysis to load it first and then display the resulting mdanalysis Universe object using nglviewer. – void life Sep 16 '20 at 15:57
• @voidlife Wow great insight! Do you do a lot of MD calculations? I haven't seen you around on this site yet, but we're pretty new (entered Public Beta in May 2020). We'd love to see you here more often!! – Nike Dattani Sep 21 '20 at 18:56
• @NikeDattani haha yeah. I'm working in this area for my masters. I think I found this question through the HNQ, I hadn't seen this site before or else I'd have joined :). – void life Sep 22 '20 at 17:00

I second nglview for any kind of molecular visualization, it's fast and works well with large simulations.

For atomistic visualization of crystal structures (e.g. small-cell inorganic crystals), Crystal Toolkit has a nice Jupyter integration that is closely integrated into pymatgen. This option is intended for people doing materials science and who want direct, literal visualizations of the Python objects they're working with, e.g. unit cells, specific defined bonds, charge density isosurfaces, color-coding by site properties, etc.

(As a disclaimer, I develop Crystal Toolkit, a work-in-progress with more docs coming soon, but I'm happy to answer questions.)

• Thank you +1, I would be interested to see more about crystal toolkit. – Cody Aldaz Sep 25 '20 at 0:54