As of version 0.4 chemlab can display molecules interactively in the browser using the package chemview.
from chemlab.notebook import download_molecule, display_molecule
arg = download_molecule("arginine")
display_molecule(arg)
# let's make an arginine box
from chemlab.core import System
from chemlab.notebook import display_system
import numpy as np
copies = []
for i in range(100):
tmp = arg.copy()
tmp.r_array += np.random.random(3) * 3.0
copies.append(tmp)
system = System(copies)
display_system(system)
Thanks to the added interactivity, we can also play trajectory. Fast
from chemlab.notebook import display_trajectory
# Let's scramble those coordinates
frames = system.r_array + np.random.random((100, system.n_atoms, 3))
display_trajectory(system, frames)
(<chemview.widget.TrajectoryControls at 0x7f090af96090>, <chemview.viewer.MolecularViewer at 0x7f090af967d0>)
We can really leverage this feature by downloading and displaying data directly from the web
from chemlab.notebook import load_remote_system, load_remote_trajectory, load_trajectory, display_trajectory
system = load_remote_system("https://github.com/chemlab/chemlab-testdata/raw/master/water.gro")
system.guess_bonds()
t, frames = load_remote_trajectory("https://github.com/chemlab/chemlab-testdata/raw/master/trajout.xtc")
tc, mv = display_trajectory(system, frames)
# Change the speed
tc.fps = 10