示例#1
0
    def compute_bonds(self, symbols, mapper=None, bond_extra=0.45):
        """
        Update bonds based on radii and an extra factor (in atomic units).

        .. code-block:: Python

            symbols = universe.atom['symbol']
            mapper = {'C': 2.0}    # atomic units - Bohr
            bond_extra = 0.2       # ditto
            # updates universe.atom_two['bond']
            universe.atom_two.compute_bonds(symbols, mapper, bond_extra)

        Args:
            symbols: Series of symbols from the atom table (e.g. uni.atom['symbol'])
            mapper (dict): Dictionary of symbol, radii pairs (see note below)
            bond_extra (float): Extra additive factor to include when computing bonds

        Note:
            If the mapper is none, or is missing data, the computation will use
            default covalent radii available in :class:`~exa.relational.isotope`.
        """
        if mapper is None:
            mapper = symbol_to_radius()
        elif not all(symbol in mapper for symbol in symbols.unique()):
            sym2rad = symbol_to_radius()
            for symbol in symbols.unique():
                if symbol not in mapper:
                    mapper[symbol] = sym2rad[symbol]
        # Note that the mapper is transformed here, but the same name is used...
        mapper = symbols.astype(str).map(mapper)
        radius0 = self['atom0'].map(mapper)
        radius1 = self['atom1'].map(mapper)
        mbl = radius0 + radius1 + bond_extra
        self['bond'] = self['distance'] <= mbl
示例#2
0
    def _custom_traits(self):
        '''
        Create creates for the atomic size (using the covalent radius) and atom
        colors (using the common `Jmol`_ color scheme). Note that that data is
        present in the static data (see :mod:`~exa.relational.isotope`).

        .. _Jmol: http://jmol.sourceforge.net/jscolors/
        '''
        self._set_categories()
        grps = self.groupby('frame')
        symbols = grps.apply(lambda g: g['symbol'].cat.codes.values)    # Pass integers rather than string symbols
        symbols = Unicode(symbols.to_json(orient='values')).tag(sync=True)
        symmap = {i: v for i, v in enumerate(self['symbol'].cat.categories)}
        sym2rad = symbol_to_radius()
        radii = sym2rad[self['symbol'].unique()]
        radii = Dict({i: radii[v] for i, v in symmap.items()}).tag(sync=True)  # (Int) symbol radii
        sym2col = symbol_to_color()
        colors = sym2col[self['symbol'].unique()]    # Same thing for colors
        colors = Dict({i: colors[v] for i, v in symmap.items()}).tag(sync=True)
        try:
            atom_set = grps.apply(lambda g: g['set'].values).to_json(orient='values')
            atom_set = Unicode(atom_set).tag(sync=True)
        except KeyError:
            atom_set = Unicode().tag(sync=True)
        # Note that position traits (atom_x, atom_y, atom_z) are created automatically
        # since we have defined _traits = ['x', 'y', 'z'] above.
        return {'atom_symbols': symbols, 'atom_radii': radii, 'atom_colors': colors,
                'atom_set': atom_set}
示例#3
0
    def _custom_traits(self):
        """
        Create creates for the atomic size (using the covalent radius) and atom
        colors (using the common `Jmol`_ color scheme). Note that that data is
        present in the static data (see :mod:`~exa.relational.isotope`).

        .. _Jmol: http://jmol.sourceforge.net/jscolors/
        """
        self._set_categories()
        kwargs = {}
        grps = self.cardinal_groupby()
        symbols = grps.apply(lambda g: g['symbol'].cat.codes.values)    # Pass integers rather than string symbols
        kwargs['atom_symbols'] = Unicode(symbols.to_json(orient='values')).tag(sync=True)
        symmap = {i: v for i, v in enumerate(self['symbol'].cat.categories)}
        sym2rad = symbol_to_radius()
        radii = sym2rad[self['symbol'].unique()]
        kwargs['atom_radii'] = Dict({i: radii[v] for i, v in symmap.items()}).tag(sync=True)  # (Int) symbol radii
        sym2col = symbol_to_color()
        colors = sym2col[self['symbol'].unique()]    # Same thing for colors
        kwargs['atom_colors'] = Dict({i: colors[v] for i, v in symmap.items()}).tag(sync=True)
        return kwargs