Python traitlets 模块,List() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用traitlets.List()

项目:notebook-molecular-visualization    作者:Autodesk    | 项目源码 | 文件源码
def _update_atom_colors(colors, atoms, styles):
        """ Updates list of atoms with the given colors. Colors will be translated to hex.

        Args:
            color (List[str]): list of colors for each atom
            atoms (List[moldesign.Atom]): list of atoms to apply the colors to
            styles (dict): old style dictionary
        """
        styles = dict(styles)

        if len(colors) != len(atoms):
            raise ValueError("Number of colors provided does not match number of atoms provided")

        for atom, color in zip(atoms, colors):
            if str(atom.index) in styles:
                styles[str(atom.index)] = dict(styles[str(atom.index)])
            else:
                styles[str(atom.index)] = {}
            styles[str(atom.index)]['color'] = translate_color(color, prefix='#')

        return styles

    # some convenience synonyms
项目:notebook-molecular-visualization    作者:Autodesk    | 项目源码 | 文件源码
def selected_atoms(self):
        """ List[moldesign.Atom]: list of selected atoms
        """
        return [self.mol.atoms[i] for i in self.selected_atom_indices]
项目:notebook-molecular-visualization    作者:Autodesk    | 项目源码 | 文件源码
def set_color(self, colors, atoms=None, save=True):
        """ Set atom colors

        May be called in several different ways:
          - ``set_color(color, atoms=list_of_atoms_or_None)``
                  where all passed atoms are to be colored a single color
          - ``set_color(list_of_colors, atoms=list_of_atoms_or_None)``
                  with a list of colors for each atom
          -  ``set_color(dict_from_atoms_to_colors)``
                  a dictionary that maps atoms to colors
          - ``set_color(f, atoms=list_of_atoms_or_None)``
                 where f is a function that maps atoms to colors

        Args:
            colors (see note for allowable types): list of colors for each atom, or map
               from atoms to colors, or a single color for all atoms
            atoms (List[moldesign.Atom]): list of atoms (if None, assumed to be mol.atoms; ignored
               if a dict is passed for "color")
            save (bool): always color these atoms this way (until self.unset_color is called)

        See Also:
            :method:`GeometryViewer.color_by`` - to automatically color atoms using numerical
               and categorical data
        """
        if hasattr(colors, 'items'):
            atoms, colors = zip(*colors.items())
        elif atoms is None:
            atoms = self.mol.atoms

        if callable(colors):
            colors = map(colors, atoms)
        elif isinstance(colors, basestring) or not hasattr(colors, '__iter__'):
            colors = [colors for atom in atoms]

        for atom,color in zip(atoms, colors):
            c = translate_color(color, '#')
            if save:
                self.atom_colors[atom] = c
            self.styles[str(atom.index)]['color'] = c
        self.send_state('styles')
项目:notebook-molecular-visualization    作者:Autodesk    | 项目源码 | 文件源码
def unset_color(self, atoms=None):
        """ Resets atoms to their default colors

        Args:
            atoms (List[moldesign.Atom]): list of atoms to color (if None, this is applied to
               all atoms)
        """
        if atoms is None:
            atoms = self.mol.atoms

        for atom in atoms:
            self.atom_colors.pop(atom, None)
            self.styles[str(atom.index)].pop('color', None)
        self.send_state('styles')
项目:notebook-molecular-visualization    作者:Autodesk    | 项目源码 | 文件源码
def sphere(self, atoms=None, color=None, opacity=None, radius=None):
        """ Draw as Van der Waals spheres

        Args:
            atoms (List[moldesign.Atom]): atoms to apply this style to
               (if not passed, uses all atoms)
            color (int or str): color as string or RGB hexadecimal
            opacity (float): opacity of the representation (between 0 and 1.0)
            radius (float or Scalar[length]): explicit sphere radii (assumes angstrom if no units);
               default: bondi VDW radii
        """
        return self.set_style('vdw', atoms=atoms, color=color, opacity=opacity, radius=radius)
项目:notebook-molecular-visualization    作者:Autodesk    | 项目源码 | 文件源码
def set_colors(self, colormap):
        """
        Args:
         colormap(Mapping[str,List[Atoms]]): mapping of colors to atoms
        """
        for color, atoms in colormap.items():
            self.set_color(atoms=atoms, color=color)