In [3]:
from chemview import MolecularViewer
from chemview import enable_notebook
enable_notebook()
import numpy as np
In [4]:
# Drawing a water molecule
mv = MolecularViewer(np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]),
{'atom_types': ['H', 'O', 'H'],
'bonds': [[0, 1], [1, 2]]},
width = 300,
height = 300)
#mv.points()
#mv.lines()
mv.ball_and_sticks()
mv
In [5]:
mv.coordinates = mv.coordinates + 0.01
In [6]:
# We use MDTraj to get a secondary structure
import mdtraj as md
traj = md.load_pdb('2M6K.pdb')
print traj
In [7]:
# We build our version of topology
top = {}
top['atom_types'] = [a.element.symbol for a in traj.topology.atoms]
top['atom_names'] = [a.name for a in traj.topology.atoms]
top['bonds'] = [(a.index, b.index) for a, b in traj.topology.bonds]
top['secondary_structure'] = md.compute_dssp(traj[0])[0]
top['residue_types'] = [r.name for r in traj.topology.residues ]
top['residue_indices'] = [ [a.index for a in r.atoms] for r in traj.topology.residues ]
mv = MolecularViewer(traj.xyz[0], top)
mv.cylinder_and_strand()
#mv.line_ribbon()
#mv.wireframe()
mv
In [8]:
from chemview.widget import TrajectoryControls
tc = TrajectoryControls(traj.n_frames)
def update():
mv.coordinates = traj.xyz[tc.frame]
tc.on_trait_change(update, "frame")
tc.fps = 10
tc