예제 #1
0
파일: mutate.py 프로젝트: lightislost/sagar
def _is_close_in_radius(lattice, p1, p2, radius):
    # 截断圆对应的半径大于距离,说明两点在圆内,需要删除:返回True
    # 因为周期性边界条件,首先将原始胞沿着x,y,z三个方向得到27个位置坐标

    # TODO: 扩胞为3x3x3是不必要的,可以根据radius和lattice选择性扩胞,
    # 若lattice的边或顶点在半径以内才需要选择向该方向扩胞
    symprec = 1e-5

    trans = numpy.array([i for i in product([-1, 0, 1], repeat=3)])
    all_p1 = numpy.array(p1) + trans
    car_p2 = frac_to_car(lattice, p2)
    for each_p1 in all_p1:
        car_p1 = frac_to_car(lattice, each_p1)
        if radius - distance(car_p1, car_p2) > symprec:
            return True
            break
    return False
예제 #2
0
    def test_perturb(self):
        lattice = numpy.copy(self.lattice)
        si_sites = [[(-0.125, -0.125, -0.125), "Si"],
                    [(0.125, 0.125, 0.125), "Si"]]

        og_si_sites = copy.deepcopy(si_sites)
        mcell = MutableCell(lattice, sites=si_sites)
        perturb(mcell, distance=0.01)
        self.assertEqual(len(mcell._sites), 2)

        for i in range(2):
            og_frac_pos = numpy.array(og_si_sites[i][0])
            og_car_pos = frac_to_car(lattice, og_frac_pos)

            new_frac_pos = numpy.array(mcell._sites[i][0])
            new_car_pos = frac_to_car(lattice, new_frac_pos)

            numpy.testing.assert_almost_equal(
                distance(og_car_pos, new_car_pos), 0.01)
예제 #3
0
 def test_distance(self):
     p1 = (0, 0, 0)
     p2 = (0, 3, 4)
     self.assertEqual(distance(p1, p2), 5.0)