Пример #1
0
    def find_unique_ions(self):
        """ Generate a unique set of the ions, fix duplicates """
        ions = dict()

        to_remove = set()

        for ion1 in self.ions:
            if ion1 not in to_remove:
                for ion2 in self.ions:
                    if ion1 != ion2:
                        dr, _ = self.ions.least_mirror(ion1.position,
                                                       ion2.position)

                        if dr < 0.01:
                            print ion1, ion2
                            to_remove.add(ion2)

        return AtomsView([atom for atom in self.ions if atom not in to_remove],
                         self.ions.lattice)
Пример #2
0
    def parse_ions(self):
        self.ions_type = None

        if 'POSITIONS_ABS' in self.blocks:
            self.ions_type = 'POSITIONS_ABS'
            self.basis = numpy.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                      [0.0, 0.0, 1.0]])
        elif 'POSITIONS_FRAC' in self.blocks:
            self.ions_type = 'POSITIONS_FRAC'
            self.basis = self.lattice

        if self.ions_type is None:
            return

        convert = False  # Dont convert frac to cart
        if self.ions_type == 'POSITIONS_FRAC':
            convert = True

        atoms = []

        index_counter = Counter()

        self.ions_units = None
        for line in self.blocks[self.ions_type]:  # Include positions frac
            lsplit = line.split()

            if len(lsplit) == 4:
                s, x, y, z = lsplit
                position = (float(x), float(y), float(z))

                sl = s.split(":")

                species = sl[0]

                # Atoms are 1-indexed to match castep.
                index_counter[species] += 1
                index = index_counter[species]

                if len(sl) > 1:
                    label = sl[1]
                else:
                    label = species

                if convert:
                    position = numpy.dot(self.basis.T, position)

                atoms.append(Atom(species, index, position, label))

            elif len(lsplit) == 1:
                self.ions_units = lsplit[0]

        if self.ions_units is None:
            self.ions_units = 'ang'

        # If we've converted, change the basis
        if convert:
            self.ions_type = 'POSITIONS_ABS'
            self.basis = numpy.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                                      [0.0, 0.0, 1.0]])

        self.ions = AtomsView(atoms, self.lattice)