Example #1
0
 def test_find_in_coord_list_pbc(self):
     coords = [[0, 0, 0], [0.5, 0.5, 0.5]]
     test_coord = [0.1, 0.1, 0.1]
     self.assertEqual(
         coord.find_in_coord_list_pbc(coords, test_coord).size, 0)
     self.assertEqual(
         coord.find_in_coord_list_pbc(coords, test_coord, atol=0.15)[0], 0)
     test_coord = [0.99, 0.99, 0.99]
     self.assertEqual(
         coord.find_in_coord_list_pbc(coords, test_coord, atol=0.02)[0], 0)
     test_coord = [-0.499, -0.499, -0.499]
     self.assertEqual(
         coord.find_in_coord_list_pbc(coords, test_coord, atol=0.01)[0], 1)
Example #2
0
    def test_subset(self):
        sm = StructureMatcher(ltol=0.2,
                              stol=0.3,
                              angle_tol=5,
                              primitive_cell=False,
                              scale=True,
                              attempt_supercell=False,
                              allow_subset=True)
        l = Lattice.orthorhombic(10, 20, 30)
        s1 = Structure(l, ['Si', 'Si', 'Ag'],
                       [[0, 0, 0.1], [0, 0, 0.2], [.7, .4, .5]])
        s2 = Structure(l, ['Si', 'Ag'], [[0, 0.1, 0], [-.7, .5, .4]])
        result = sm.get_s2_like_s1(s1, s2)

        self.assertEqual(
            len(find_in_coord_list_pbc(result.frac_coords, [0, 0, 0.1])), 1)
        self.assertEqual(
            len(find_in_coord_list_pbc(result.frac_coords, [0.7, 0.4, 0.5])),
            1)

        #test with fewer species in s2
        s1 = Structure(l, ['Si', 'Ag', 'Si'],
                       [[0, 0, 0.1], [0, 0, 0.2], [.7, .4, .5]])
        s2 = Structure(l, ['Si', 'Si'], [[0, 0.1, 0], [-.7, .5, .4]])
        result = sm.get_s2_like_s1(s1, s2)
        mindists = np.min(s1.lattice.get_all_distances(s1.frac_coords,
                                                       result.frac_coords),
                          axis=0)
        self.assertLess(np.max(mindists), 1e-6)

        self.assertEqual(
            len(find_in_coord_list_pbc(result.frac_coords, [0, 0, 0.1])), 1)
        self.assertEqual(
            len(find_in_coord_list_pbc(result.frac_coords, [0.7, 0.4, 0.5])),
            1)

        #test with not enough sites in s1
        #test with fewer species in s2
        s1 = Structure(l, ['Si', 'Ag', 'Cl'],
                       [[0, 0, 0.1], [0, 0, 0.2], [.7, .4, .5]])
        s2 = Structure(l, ['Si', 'Si'], [[0, 0.1, 0], [-.7, .5, .4]])
        self.assertEqual(sm.get_s2_like_s1(s1, s2), None)
    def test_subset(self):
        sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
                              primitive_cell=False, scale=True,
                              attempt_supercell=False,
                              allow_subset=True)
        l = Lattice.orthorhombic(10, 20, 30)
        s1 = Structure(l, ['Si', 'Si', 'Ag'],
                       [[0, 0, 0.1], [0, 0, 0.2], [.7, .4, .5]])
        s2 = Structure(l, ['Si', 'Ag'],
                       [[0, 0.1, 0], [-.7, .5, .4]])
        result = sm.get_s2_like_s1(s1, s2)

        self.assertEqual(len(find_in_coord_list_pbc(result.frac_coords,
                                                    [0, 0, 0.1])), 1)
        self.assertEqual(len(find_in_coord_list_pbc(result.frac_coords,
                                                    [0.7, 0.4, 0.5])), 1)

        # test with fewer species in s2
        s1 = Structure(l, ['Si', 'Ag', 'Si'],
                       [[0, 0, 0.1], [0, 0, 0.2], [.7, .4, .5]])
        s2 = Structure(l, ['Si', 'Si'],
                       [[0, 0.1, 0], [-.7, .5, .4]])
        result = sm.get_s2_like_s1(s1, s2)
        mindists = np.min(s1.lattice.get_all_distances(
            s1.frac_coords, result.frac_coords), axis=0)
        self.assertLess(np.max(mindists), 1e-6)

        self.assertEqual(len(find_in_coord_list_pbc(result.frac_coords,
                                                    [0, 0, 0.1])), 1)
        self.assertEqual(len(find_in_coord_list_pbc(result.frac_coords,
                                                    [0.7, 0.4, 0.5])), 1)

        # test with not enough sites in s1
        # test with fewer species in s2
        s1 = Structure(l, ['Si', 'Ag', 'Cl'],
                       [[0, 0, 0.1], [0, 0, 0.2], [.7, .4, .5]])
        s2 = Structure(l, ['Si', 'Si'],
                       [[0, 0.1, 0], [-.7, .5, .4]])
        self.assertEqual(sm.get_s2_like_s1(s1, s2), None)
Example #4
0
 def get_matching_coord(coord):
     keys = list(coord_to_species.keys())
     coords = np.array(keys)
     for op in self.symmetry_operations:
         c = op.operate(coord)
         inds = find_in_coord_list_pbc(coords,
                                       c,
                                       atol=self._site_tolerance)
         # cant use if inds, because python is dumb and np.array([0]) evaluates
         # to False
         if len(inds):
             return keys[inds[0]]
     return False