Пример #1
0
    def closest(self, atom_type, reference, n=1, exclude=False, only=False):
        '''
        If n=1: return the number in the xyz matrix of the atom of atom_type
        which is the closest to a reference atom in a geometry.
        If n>1, return a list of the n closest atoms of atom_type, which are
        closest to the reference atom.

        Arguments:
            atom_type:      atom number or symbol of the atoms whose number
                            in the xyz matrix
                            must be returned
            reference:      number of the reference atom in the xyz matrix
            n:              number of atoms to return
            exclude:        exclude these atoms
            only:           limit search to these atoms
        '''
        # If search is not restricted, look for any atom.
        if not only:
            only = range(self.size)
        atom_type = utils.anum(atom_type)
        distances = self.distance_matrix[reference]
        out = [
            np.where(distances == d)[0][0] for d in sorted(distances)
            if self.numbers[np.where(distances == d)[0][0]] == atom_type
            and np.where(distances == d)[0][0] != reference and np.where(
                distances == d)[0][0] in only
        ]
        if exclude:
            out = [o for o in out if o not in exclude]
        if n > 1:
            return out[:n]
        elif n == 1:
            return out[0]
Пример #2
0
    def closest(self, atom_type, reference, n=1, exclude=False, only=False):
        '''
        If n=1: return the number in the xyz matrix of the atom of atom_type
        which is the closest to a reference atom in a geometry.
        If n>1, return a list of the n closest atoms of atom_type, which are
        closest to the reference atom.

        Arguments:
            atom_type:      atom number or symbol of the atoms whose number
                            in the xyz matrix
                            must be returned
            reference:      number of the reference atom in the xyz matrix
            n:              number of atoms to return
            exclude:        exclude these atoms
            only:           limit search to these atoms
        '''
        # If search is not restricted, look for any atom.
        if not only:
            only = range(self.size)
        atom_type = utils.anum(atom_type)
        distances = self.distance_matrix[reference]
        out = [np.where(distances == d)[0][0] for d in sorted(distances)
               if self.numbers[np.where(distances == d)[0][0]] == atom_type
               and np.where(distances == d)[0][0] != reference
               and np.where(distances == d)[0][0] in only]
        if exclude:
            out = [o for o in out if o not in exclude]
        if n > 1:
            return out[:n]
        elif n == 1:
            return out[0]
Пример #3
0
 def __getitem__(self, i):
     '''both Stoichio['C'] and Stoichio[6] will yield the number
     of carbon atoms'''
     try:
         return self._array[utils.anum(i)]
     # What happens if the number of Hf atoms is requested,
     # but only atoms up to Cl are included?
     except IndexError:
         return 0
Пример #4
0
 def __getitem__(self, i):
     '''both Stoichio['C'] and Stoichio[6] will yield the number
     of carbon atoms'''
     try:
         return self._array[utils.anum(i)]
     # What happens if the number of Hf atoms is requested,
     # but only atoms up to Cl are included?
     except IndexError:
         return 0
Пример #5
0
 def from_string(cls, string, ignore_header=False):
     ''' handles both symbols and numbers,
     take three last cols and first col'''
     atoms = []
     coordinates = []
     for i, l in enumerate(string.strip().split('\n')):
         if ignore_header and i < 2:
             continue
         split = l.split()
         atoms.append(utils.anum(split[0]))
         coordinates.append(
             np.array(map(float, split[-3:])) * units.angstrom)
     return cls.from_Molecule(mol.Molecule(atoms, coordinates))
Пример #6
0
 def from_string(cls, string, ignore_header=False):
     ''' handles both symbols and numbers,
     take three last cols and first col'''
     atoms = []
     coordinates = []
     for i, l in enumerate(string.strip().split('\n')):
         if ignore_header and i < 2:
             continue
         split = l.split()
         atoms.append(utils.anum(split[0]))
         coordinates.append(np.array(map(float, split[-3:]))
                            * units.angstrom)
     return cls.from_Molecule(mol.Molecule(atoms, coordinates))
Пример #7
0
 def _atomstr(self, z):
     '''print things like 'C6' based on the atom number (z) or even
     the atom symbol'''
     try:
         n = self._array[utils.anum(z)]
     except:
         n = 0
     if n:
         if n > 1:
             return '%s%i' % (utils.asym(z).upper(), n)
         elif n == 1:
             return '%s' % utils.asym(z).upper()
     else:
         return ''
Пример #8
0
 def _atomstr(self, z):
     '''print things like 'C6' based on the atom number (z) or even
     the atom symbol'''
     try:
         n = self._array[utils.anum(z)]
     except:
         n = 0
     if n:
         if n > 1:
             return '%s%i' % (utils.asym(z).upper(), n)
         elif n == 1:
             return '%s' % utils.asym(z).upper()
     else:
         return ''
Пример #9
0
 def atoms(self, at):
     '''return the indices of the atoms with the given atom number or symbol'''
     atom_type = utils.anum(at)
     return numpy.where(self.numbers == atom_type)[0]
Пример #10
0
 def atoms(self, at):
     '''return the indices of the atoms with the given atom number or symbol'''
     atom_type = utils.anum(at)
     return numpy.where(self.numbers == atom_type)[0]
Пример #11
0
def _convert(atom):
    try:
        return mg.HasAtomNumber(utils.anum(atom))
    except:
        return atom