Пример #1
0
 def test_chemical_symbols(self):
     basis = StructureFactory().ase_bulk('Fe', cubic=True)
     basis[0] = 'Ni'
     neigh = basis.get_neighbors(num_neighbors=1)
     self.assertEqual(neigh.chemical_symbols[0, 0], 'Fe')
     self.assertEqual(neigh.chemical_symbols[1, 0], 'Ni')
     vacancy = StructureFactory().ase_bulk('Fe', cubic=True).repeat(4)
     del vacancy[0]
     neigh = vacancy.get_neighbors(num_neighbors=None, cutoff_radius=3)
     self.assertEqual(neigh.chemical_symbols[0, -1], 'v')
Пример #2
0
 def test_centrosymmetry(self):
     structure = StructureFactory().ase_bulk('Fe').repeat(4)
     cs = structure.get_neighbors(num_neighbors=8).centrosymmetry
     self.assertAlmostEqual(cs.max(), 0)
     self.assertAlmostEqual(cs.min(), 0)
     structure.positions += 0.01 * (
         2 * np.random.random(structure.positions.shape) - 1)
     neigh = structure.get_neighbors(num_neighbors=8)
     self.assertGreater(neigh.centrosymmetry.min(), 0)
     self.assertTrue(
         np.allclose(
             neigh.centrosymmetry,
             structure.analyse.pyscal_centro_symmetry(num_neighbors=8)))
Пример #3
0
 def test_get_shells_flattened(self):
     structure = StructureFactory().ase.bulk('Al', cubic=True).repeat(2)
     del structure[0]
     r = structure.cell[0, 0] * 0.49
     neigh = structure.get_neighbors(cutoff_radius=r,
                                     num_neighbors=None,
                                     mode='flattened')
     self.assertEqual(len(np.unique(neigh.shells)), 1)
     self.assertEqual(len(neigh.shells), 360)
     self.assertEqual(len(np.unique(neigh.get_local_shells())), 1)
     self.assertEqual(len(neigh.get_local_shells()), 360)
     self.assertEqual(len(np.unique(neigh.get_global_shells())), 1)
     self.assertEqual(len(neigh.get_global_shells()), 360)
     neigh = structure.get_neighbors(cutoff_radius=r, num_neighbors=None)
     self.assertEqual(len(np.unique(neigh.flattened.shells)), 1)
     self.assertEqual(len(neigh.flattened.shells), 360)
Пример #4
0
 def test_numbers_of_neighbors(self):
     basis = StructureFactory().ase.bulk('Al', cubic=True).repeat(2)
     del basis[0]
     neigh = basis.get_neighbors(num_neighbors=None,
                                 cutoff_radius=0.45 * basis.cell[0, 0])
     n, c = np.unique(neigh.numbers_of_neighbors, return_counts=True)
     self.assertEqual(n.tolist(), [11, 12])
     self.assertEqual(c.tolist(), [12, 19])
Пример #5
0
 def test_atom_numbers(self):
     structure = StructureFactory().ase.bulk('Al', cubic=True).repeat(2)
     del structure[0]
     r = structure.cell[0, 0] * 0.49
     neigh = structure.get_neighbors(cutoff_radius=r,
                                     num_neighbors=None,
                                     mode='filled')
     n = len(structure)
     self.assertEqual(neigh.atom_numbers.sum(), int(n * (n - 1) / 2 * 12))
     neigh = structure.get_neighbors(cutoff_radius=r,
                                     num_neighbors=None,
                                     mode='ragged')
     for i, (a, d) in enumerate(zip(neigh.atom_numbers, neigh.distances)):
         self.assertEqual(np.sum(a - len(d) * [i]), 0)
     neigh = structure.get_neighbors(cutoff_radius=r,
                                     num_neighbors=None,
                                     mode='flattened')
     labels, counts = np.unique(np.unique(neigh.atom_numbers,
                                          return_counts=True)[1],
                                return_counts=True)
     self.assertEqual(labels.tolist(), [11, 12])
     self.assertEqual(counts.tolist(), [12, 19])
Пример #6
0
 def test_get_distances_flattened(self):
     structure = StructureFactory().ase.bulk('Al', cubic=True).repeat(2)
     del structure[0]
     r = structure.cell[0, 0] * 0.49
     neigh = structure.get_neighbors(cutoff_radius=r,
                                     num_neighbors=None,
                                     mode='flattened')
     self.assertAlmostEqual(np.std(neigh.distances), 0)
     self.assertEqual(len(neigh.distances), 360)
     self.assertEqual(neigh.vecs.shape, (
         360,
         3,
     ))
Пример #7
0
 def test_get_all_pairs(self):
     structure = StructureFactory().ase_bulk('Fe').repeat(4)
     neigh = structure.get_neighbors(num_neighbors=8)
     for n in [2, 4, 6]:
         pairs = neigh._get_all_possible_pairs(n)
         self.assertEqual(
             (np.prod(np.arange(int(n / 2)) * 2 + 1), int(n / 2), 2),
             pairs.shape)
         for i in range(2**(n - 2)):
             a = np.sort(np.random.choice(np.arange(n), 2, replace=False))
             self.assertEqual(np.sum(np.all(a == pairs, axis=-1)),
                              np.prod(np.arange(int((n - 1) / 2)) * 2 + 1))
     self.assertEqual(
         np.ptp(
             np.unique(neigh._get_all_possible_pairs(6),
                       return_counts=True)[1]), 0)
Пример #8
0
 def test_modes(self):
     basis = StructureFactory().ase.bulk('Al', cubic=True)
     neigh = basis.get_neighbors()
     self.assertTrue(neigh.mode == 'filled')
     with self.assertRaises(KeyError):
         neigh = basis.get_neighbors(mode='random_key')