How to use the nglview.show_mdtraj function in nglview

To help you get started, we’ve selected a few nglview examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github markovmodel / molPX / projX / visualize.py View on Github external
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
github markovmodel / molPX / projX / api.py View on Github external
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
github markovmodel / molPX / molpx / visualize.py View on Github external
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

nglview

IPython widget to interactively view molecular structures and trajectories.

MIT
Latest version published 8 months ago

Package Health Score

75 / 100
Full package analysis

Similar packages