How to use the nglview.show_structure_file 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 SBRG / ssbio / ssbio / protein / structure / structprop.py View on Github external
if not self.structure_file:
            raise ValueError("Structure file not loaded")

        only_chains = ssbio.utils.force_list(only_chains)
        to_show_chains = '( '
        for c in only_chains:
            to_show_chains += ':{} or'.format(c)
        to_show_chains = to_show_chains.strip(' or ')
        to_show_chains += ' )'

        if self.file_type == 'mmtf' or self.file_type == 'mmtf.gz':
            view = nv.NGLWidget()
            view.add_component(self.structure_path)
        else:
            view = nv.show_structure_file(self.structure_path, gui=gui)

        if recolor:
            view.clear_representations()
            if only_chains:
                view.add_cartoon(selection='{} and (not hydrogen)'.format(to_show_chains), color='silver', opacity=opacity)
            else:
                view.add_cartoon(selection='protein', color='silver', opacity=opacity)
        elif only_chains:
            view.clear_representations()
            view.add_cartoon(selection='{} and (not hydrogen)'.format(to_show_chains), color='silver', opacity=opacity)

        return view
github kbsezginel / angstrom / angstrom / visualize / show.py View on Github external
"""
    atoms, coordinates, group_numbers = arrange_molecules(molecules, arrange=arrange, nx=nx, distance=distance)

    # nglview require atom names in all caps to color them properly
    if caps:
        atoms = [name.upper() for name in atoms]

    if save is None:
        temp_pdb_file = tempfile.NamedTemporaryFile(mode='w+', suffix='.pdb')
        write_pdb(temp_pdb_file, atoms, coordinates, group=group_numbers)
        view = nglview.show_structure_file(temp_pdb_file.name)
        temp_pdb_file.close()
    else:
        with open(save, 'w') as save_file:
            write_pdb(save_file, atoms, coordinates, group=group_numbers)
        view = nglview.show_structure_file(save)

    view.camera = camera
    return view
github kbsezginel / angstrom / angstrom / visualize / show.py View on Github external
Returns
    -------
    view
        nglview "view" object.

    """
    atoms, coordinates, group_numbers = arrange_molecules(molecules, arrange=arrange, nx=nx, distance=distance)

    # nglview require atom names in all caps to color them properly
    if caps:
        atoms = [name.upper() for name in atoms]

    if save is None:
        temp_pdb_file = tempfile.NamedTemporaryFile(mode='w+', suffix='.pdb')
        write_pdb(temp_pdb_file, atoms, coordinates, group=group_numbers)
        view = nglview.show_structure_file(temp_pdb_file.name)
        temp_pdb_file.close()
    else:
        with open(save, 'w') as save_file:
            write_pdb(save_file, atoms, coordinates, group=group_numbers)
        view = nglview.show_structure_file(save)

    view.camera = camera
    return view

nglview

IPython widget to interactively view molecular structures and trajectories.

MIT
Latest version published 9 months ago

Package Health Score

75 / 100
Full package analysis

Similar packages