def test_getter_and_ragged(self):
     struct = CrystalStructure(elements='Al',
                               lattice_constants=4,
                               bravais_basis='fcc').repeat(2)
     del struct[0]
     neigh = struct.get_neighbors_by_distance(cutoff_radius=3)
     vecs = neigh.get_vectors(allow_ragged=False)
     distances = neigh.get_distances(allow_ragged=False)
     indices = neigh.get_indices(allow_ragged=False)
     neigh.allow_ragged = False
     self.assertTrue(np.array_equal(neigh.distances, distances))
     self.assertTrue(np.array_equal(neigh.indices, indices))
     self.assertTrue(np.array_equal(neigh.vecs, vecs))
Example #2
0
 def test_getter_and_ragged(self):
     struct = CrystalStructure(elements='Al',
                               lattice_constants=4,
                               bravais_basis='fcc').repeat(2)
     del struct[0]
     neigh = struct.get_neighbors_by_distance(cutoff_radius=3,
                                              mode='filled')
     vecs = neigh.filled.vecs
     distances = neigh.filled.distances
     indices = neigh.filled.indices
     self.assertTrue(np.array_equal(neigh.distances, distances))
     self.assertTrue(np.array_equal(neigh.indices, indices))
     self.assertTrue(np.array_equal(neigh.vecs, vecs))
 def test_allow_ragged(self):
     struct = CrystalStructure(elements='Al',
                               lattice_constants=4,
                               bravais_basis='fcc').repeat(10)
     del struct[0]
     neigh = struct.get_neighbors_by_distance(cutoff_radius=3)
     self.assertTrue(neigh.allow_ragged)
     self.assertTrue(isinstance(neigh.indices, list))
     indices = neigh.indices.copy()
     with self.assertRaises(ValueError):
         neigh.allow_ragged = 'yes'
     neigh.allow_ragged = False
     self.assertTrue(isinstance(neigh.indices, np.ndarray))
     self.assertGreater(len(neigh.indices[0]), len(indices[0]))
     with self.assertRaises(IndexError):
         struct.positions[neigh.indices] = struct.positions[neigh.indices]
     neigh.allow_ragged = True
     self.assertTrue(np.array_equal(neigh.indices[0], indices[0]))
     neigh = struct.get_neighbors(cutoff_radius=3, num_neighbors=None)
     self.assertFalse(neigh.allow_ragged)
     self.assertTrue(isinstance(neigh.indices, np.ndarray))