How to use the nglview.TextStructure 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 pyiron / pyiron / pyiron / atomistics / structure / atoms.py View on Github external
raise ImportError("The package nglview needs to be installed for the plot3d() function!")
        if custom_array is not None:
            warnings.warn('custom_array is deprecated. Use scalar_field instead', DeprecationWarning)
            scalar_field = custom_array
        if custom_3darray is not None:
            warnings.warn('custom_3darray is deprecated. Use vector_field instead', DeprecationWarning)
            vector_field = custom_3darray
        # Always visualize the parent basis
        parent_basis = self.get_parent_basis()
        if select_atoms is None:
            select_atoms = np.array(len(parent_basis)*[True])
        else:
            select_atoms = np.array(select_atoms)
            if scalar_field is not None:
                scalar_field = scalar_field[select_atoms]
        struct = nglview.TextStructure(self._ngl_write_structure(parent_basis.get_chemical_symbols()[select_atoms],
                                                                 self.positions[select_atoms], self.cell, scalar_field=scalar_field))
        view = nglview.NGLWidget(struct)
        if spacefill:
            if color_scheme is None and scalar_field is not None:
                color_scheme = 'occupancy'
            elif color_scheme is None:
                color_scheme = 'element'
            #view.add_spacefill(radius_type='vdw', color_scheme=color_scheme, radius=particle_size)
            for elem, num in set(list(zip(parent_basis.get_chemical_symbols(), parent_basis.get_atomic_numbers()))):
                view.add_spacefill(selection='#'+elem, radius_type='vdw', color_scheme='element', radius=particle_size*(0.2+0.1*np.sqrt(num)))
            # view.add_spacefill(radius=1.0)
            view.remove_ball_and_stick()
        else:
            view.add_ball_and_stick()
        if show_cell:
            if parent_basis.cell is not None:
github MolSSI / QCElemental / qcelemental / models / molecule.py View on Github external
-------
        nglview.NGLWidget
            A nglview view of the molecule

        """
        if not which_import("nglview", return_bool=True):
            raise ModuleNotFoundError(
                f"Python module nglwview not found. Solve by installing it: `conda install -c conda-forge nglview`"
            )  # pragma: no cover

        import nglview as nv  # type: ignore

        if ngl_kwargs is None:
            ngl_kwargs = {}

        structure = nv.TextStructure(self.to_string("nglview-sdf"), ext="sdf")
        widget = nv.NGLWidget(structure, **ngl_kwargs)
        return widget
github pyiron / pyiron / pyiron / atomistics / structure / atoms.py View on Github external
Returns:
    
        """
        try:  # If the graphical packages are not available, the GUI will not work.
            import nglview
        except ImportError:
            raise ImportError("The package nglview needs to be installed for the plot3d() function!")
        # Always visualize the parent basis
        parent_basis = self.get_parent_basis()
        if select_atoms is None:
            select_atoms = np.array(len(parent_basis)*[True])
        else:
            select_atoms = np.array(select_atoms)
            if custom_array is not None:
                custom_array = custom_array[select_atoms]
        struct = nglview.TextStructure(self._ngl_write_structure(parent_basis.get_chemical_symbols()[select_atoms],
                                                                 self.positions[select_atoms], self.cell, custom_array=custom_array))
        view = nglview.NGLWidget(struct)
        if spacefill:
            if color_scheme is None and custom_array is not None:
                color_scheme = 'occupancy'
            elif color_scheme is None:
                color_scheme = 'element'
            view.add_spacefill(radius_type='vdw', color_scheme=color_scheme, radius=particle_size)
            # view.add_spacefill(radius=1.0)
            view.remove_ball_and_stick()
        else:
            view.add_ball_and_stick()
        if show_cell:
            if parent_basis.cell is not None:
                view.add_unitcell()
        if custom_3darray is not None:

nglview

IPython widget to interactively view molecular structures and trajectories.

MIT
Latest version published 28 days ago

Package Health Score

81 / 100
Full package analysis

Similar packages