Esempio n. 1
0
    def assign_unique_types(self, from_attr='element'):
        """Assign unique :attr:`TypeAtom.type`\s to each `TypeAtom` in \
            `TypeAtoms` from an existing unique atom attribute.

        .. versionchanged:: 0.3.11

           Now accepts a keyword argument `from_attr`.

        The assignment of unique :attr:`TypeAtom.type`\s is performed
        by mapping an existing atom attribute (default: element)
        to a unique integer, starting at 1.

        Parameters
        ----------
        from_attr : :class:`~python:str`
            An existing atom attribute used to generate an attribute
            mapping that maps the attribute to a unique atom
            :attr:`~TypeAtom.type`.

        """
        attrlist = [getattr(atom, from_attr) for atom in self]
        attrmap = \
            {attr: i for i, attr in enumerate(dedupe(attrlist), start=1)}
        self.mapatomattr(from_attr, 'type', attrmap)
Esempio n. 2
0
 def atoms(self):
     """`Atoms` :class:`python:set` in `Bonds`."""
     atoms = []
     [atoms.extend(bond.atoms) for bond in self]
     atoms = dedupe(atoms, key=attrgetter('id'))
     return sknano.core.atoms.StructureAtoms(list(atoms))
Esempio n. 3
0
 def atoms(self):
     """`Atoms` :class:`python:set` in `Bonds`."""
     atoms = []
     [atoms.extend(bond.atoms) for bond in self]
     atoms = dedupe(atoms, key=attrgetter('id'))
     return sknano.core.atoms.StructureAtoms(list(atoms))
Esempio n. 4
0
def test1():
    lst = [1, 2, 2, 3, 4, 50, 50, 4, 5]
    assert_equal(list(dedupe(lst)), [1, 2, 3, 4, 50, 5])