예제 #1
0
    def check(self, elements=None, limit=0.1, warn=False):
        """
        该方法用于自查对象中的位点是否过近
        若过近则抛出一个warning
        """
        if elements is None:
            origin_cell = self
        else:
            # 选取要check的元素,构建新的胞
            ele_num = [symbol2number(s) for s in elements]
            positions = []
            atoms = []
            for idx, e in enumerate(self.atoms):
                if e in ele_num:
                    positions.append(self.positions[idx])
                    atoms.append(self.atoms[idx])
            origin_cell = self.__class__(self.lattice, positions, atoms)

        mat = numpy.diag([3, 3, 3])
        periodic_cell = origin_cell.extend(mat)
        points = frac_to_car(periodic_cell.lattice, periodic_cell.positions)
        if closest_pair(points) < limit:
            if warn is True:
                import warnings
                warnings.warn(
                    "some atoms are too close(< {:f}), check cell".format(
                        limit), RuntimeWarning)
            return False
        else:
            return True
예제 #2
0
    def check(self, elements=None, limit=0.1, warn=False):
        """
        该方法用于自查对象中的位点是否过近
        若过近则抛出一个warning
        """
        if elements is None:
            mol = self
        else:
            # 选取要check的元素,构建新的胞
            ele_num = [symbol2number(s) for s in elements]
            positions = []
            atoms = []
            for idx, e in enumerate(self.atoms):
                if e in ele_num:
                    positions.append(self.positions[idx])
                    atoms.append(self.atoms[idx])
            mol = self.__class__(positions, atoms)

        points = mol.positions
        if closest_pair(points) < limit:
            if warn is True:
                import warnings
                warnings.warn(
                    "some atoms are too close(< {:f}), check cell".format(
                        limit), RuntimeWarning)
            return False
        else:
            return True
예제 #3
0
 def test_closest_pair(self):
     points = numpy.array([0, 0, 0, 0, 3, 4, 3, 60, 6, 10.1, 10.2,
                           10.3]).reshape((-1, 3))
     self.assertEqual(closest_pair(points), 5)