Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
link_ax2wdg_kwargs: dictionary of named arguments, optional
named arguments for the function :any:`_link_ax_w_pos_2_nglwidget`, which is the one that internally
provides the interactivity. Non-expert users can safely ignore this option.
Returns
--------
iwd : :obj:`nglview.NGLWidget`
"""
# Create ngl_viewer widget
if widget is None:
iwd = _nglview.show_mdtraj(geom)
else:
iwd = widget
if clear_lines == True:
[ax.lines.pop() for ii in range(len(ax.lines))]
# Plot the path on top of it
if plot_path:
ax.plot(positions[:,0], positions[:,1], '-g', lw=3)
# Link the axes widget with the ngl widget
ax_wdg = _link_ax_w_pos_2_nglwidget(ax,
positions,
iwd,
**link_ax2wdg_kwargs
)
# somehow returning the ax_wdg messes the displaying of both widgets
def visualize_sample(sample, geom,
ax,
plot_path=False,
clear_lines=True,
widget=None,
**link_ax2wdg_kwargs
):
r"""
TODO
"""
# Create ngl_viewer widget
if widget is None:
iwd = _nglview.show_mdtraj(geom)
else:
iwd = widget
if clear_lines == True:
[ax.lines.pop() for ii in range(len(ax.lines))]
# Plot the path on top of it
if plot_path:
ax.plot(sample[:,0], sample[:,1], '-g', lw=3)
# Link the axes widget with the ngl widget
_link_ax_w_pos_2_nglwidget(ax,
sample,
iwd,
**link_ax2wdg_kwargs
)
return iwd
ngl_wdg : an already instantiated widget to add the geom, default is None
n_small : if the geometry has less than n_small residues, force a "ball and stick" represenation
:return: :nglview.widget object
"""
if isinstance(geom, str):
geom = _md.load(geom)
if ngl_wdg is None:
if geom is None:
ngl_wdg = _nglview.NGLWidget()
else:
ngl_wdg = _nglview.show_mdtraj(geom)
else:
ngl_wdg.add_trajectory(geom)
# Let' some customization take place
## Do we need a ball+stick representation?
if geom is not None:
if geom.top.n_residues < n_small:
for ic in range(len(ngl_wdg._ngl_component_ids)):
# TODO FIND OUT WHY THIS FAILS FOR THE LAST REPRESENTATION
#print("removing reps for component",ic)
ngl_wdg.remove_cartoon(component=ic)
ngl_wdg.clear_representations(component=ic)
ngl_wdg.add_ball_and_stick(component=ic)
return ngl_wdg