Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, atoms, xsize=500, ysize=500):
import nglview
import nglview.color
from ipywidgets import Dropdown, FloatSlider, IntSlider, HBox, VBox
self.atoms = atoms
if isinstance(atoms[0], Atoms):
# Assume this is a trajectory or struct list
self.view = nglview.show_asetraj(atoms)
self.frm = IntSlider(value=0, min=0, max=len(atoms) - 1)
self.frm.observe(self._update_frame)
self.struct = atoms[0]
else:
# Assume this is just a single structure
self.view = nglview.show_ase(atoms)
self.struct = atoms
self.frm = None
self.colors = {}
self.view._remote_call('setSize', target='Widget',
args=['%dpx' % (xsize,), '%dpx' % (ysize,)])
self.view.add_unitcell()
self.view.add_spacefill()
self.view.remove_ball_and_stick()
self.view.camera = 'orthographic'
use value >1 to make animation faster
default=1
center_of_mass (bool):
Returns:
animation: nglview IPython widget
"""
if not self.status.finished:
raise ValueError("This job can't be animated until it is finished")
try:
import nglview
except ImportError:
raise ImportError("The animate() function requires the package nglview to be installed")
animation = nglview.show_asetraj(self.trajectory(stride=stride, center_of_mass=center_of_mass))
if spacefill:
animation.add_spacefill(radius_type='vdw', scale=0.5, radius=particle_size)
animation.remove_ball_and_stick()
else:
animation.add_ball_and_stick()
if show_cell:
if self.structure.cell is not None:
animation.add_unitcell()
return animation
use value >1 to make animation faster
default=1
center_of_mass (bool):
Returns:
animation: nglview IPython widget
"""
try:
import nglview
except ImportError:
raise ImportError(
"The animate() function requires the package nglview to be installed"
)
animation = nglview.show_asetraj(
self.trajectory(stride=stride, center_of_mass=center_of_mass)
)
if spacefill:
animation.add_spacefill(radius_type="vdw", scale=0.5, radius=particle_size)
animation.remove_ball_and_stick()
else:
animation.add_ball_and_stick()
if show_cell:
if self.structure.cell is not None:
animation.add_unitcell()
return animation
if self.nma.masses3 is not None:
mode /= np.sqrt(self.nma.masses3)
mode /= np.linalg.norm(mode)
positions = np.zeros((frames,len(symbols),3))
for frame in range(frames):
factor = amplitude*np.sin(2*np.pi*float(frame)/frames)
positions[frame] = coordinates + factor*mode.reshape((-1,3))
try:
import nglview
except ImportError:
raise ImportError("The animate_nma_mode() function requires the package nglview to be installed")
animation = nglview.show_asetraj(Trajectory(positions,self.structure))
if spacefill:
animation.add_spacefill(radius_type='vdw', scale=0.5, radius=particle_size)
animation.remove_ball_and_stick()
else:
animation.add_ball_and_stick()
return animation