Exemple #1
0
 def test_get_nelect(self):
     atoms = CrystalStructure("Pt", BravaisBasis="fcc", a=3.98)
     self.job.structure = atoms
     self.assertEqual(self.job.get_nelect(), 10)
Exemple #2
0
    def test__add__(self):
        cell = np.eye(3) * 10.0
        basis_0 = Atoms(["O"], scaled_positions=[[0.5, 0.5, 0.5]], cell=cell)
        basis_1 = Atoms(["H"],
                        scaled_positions=[[0.75, 0.75, 0.75]],
                        cell=cell)
        basis_2 = Atoms(["H"],
                        scaled_positions=[[0.25, 0.25, 0.25]],
                        cell=cell)
        basis_3 = Atoms(["H", "O", "N"],
                        scaled_positions=[[0.35, 0.35, 0.35], [0., 0., 0.],
                                          [0., 0., 0.1]],
                        cell=cell)

        pse = PeriodicTable()
        pse.add_element("O", "O_up", spin="up")
        o_up = pse.element("O_up")
        basis_4 = Atoms([o_up],
                        scaled_positions=[[0.27, 0.27, 0.27]],
                        cell=np.eye(3) * 20.0)
        b = basis_0 + basis_1
        self.assertEqual(b.get_chemical_formula(), "HO")
        b = basis_0 + basis_1 + basis_2
        self.assertEqual(b.get_chemical_formula(), "H2O")
        b += basis_2
        self.assertEqual(b.get_chemical_formula(), "H3O")
        b = basis_0 + basis_1 + basis_2 + basis_3
        self.assertEqual(b.get_chemical_formula(), "H3NO2")
        self.assertTrue(
            np.array_equal(b.scaled_positions[b.select_index("N")],
                           [[0., 0., 0.1]]))
        self.assertTrue(
            np.allclose(
                b.scaled_positions[b.select_index("H")],
                [[0.75, 0.75, 0.75], [0.25, 0.25, 0.25], [0.35, 0.35, 0.35]]))
        self.assertTrue(
            np.allclose(b.scaled_positions[b.select_index("O")],
                        [[0.5, 0.5, 0.5], [0., 0., 0.]]))
        b.set_repeat([2, 2, 2])
        self.assertEqual(b.get_chemical_formula(), "H24N8O16")
        b += basis_4
        self.assertEqual(b.get_chemical_formula(), "H24N8O16O_up")
        self.assertTrue(
            np.allclose(b.scaled_positions[b.select_index(o_up)],
                        [[0.27, 0.27, 0.27]]))
        COX = self.C2 + Atom("O", position=[0, 0, -2])
        COX += Atom("O", position=[0, 0, -4])
        COX += COX
        n_objects = len(set(COX.get_species_objects()))
        n_species = len(set(COX.get_chemical_elements()))
        self.assertEqual(n_objects, n_species)
        self.assertEqual(n_objects, 2)
        self.assertEqual(n_species, 2)
        basis_Mg = CrystalStructure("Mg",
                                    bravais_basis="fcc",
                                    lattice_constant=4.2)
        basis_O = CrystalStructure("O",
                                   bravais_basis="fcc",
                                   lattice_constant=4.2)
        # basis_O.set_relative()
        basis_O.scaled_positions += [0., 0., 0.5]
        basis = basis_Mg + basis_O
        self.assertEqual(len(basis._tag_list),
                         len(basis_Mg._tag_list) + len(basis_O._tag_list))
        basis.center_coordinates_in_unit_cell()
        self.assertEqual(basis.get_spacegroup()["Number"], 225)
Exemple #3
0
 def test_get_neighbors(self):
     struct = CrystalStructure(elements='Fe', lattice_constants=2.85, bravais_basis='bcc').repeat(10)
     cell = struct.cell.copy()
     cell += np.random.random((3,3))-0.5
     struct.positions += np.random.random((len(struct), 3))-0.5
     struct.set_cell(cell, scale_atoms=True)
     neigh = struct.get_neighbors()
     self.assertAlmostEqual(np.absolute(neigh.distances-np.linalg.norm(neigh.vecs, axis=-1)).max(), 0)
     myself = np.ones_like(neigh.indices)
     myself = myself*np.arange(len(myself))[:,np.newaxis]
     dist = struct.get_distances(myself.flatten(), neigh.indices.flatten(), mic=True)
     self.assertAlmostEqual(np.absolute(dist-neigh.distances.flatten()).max(), 0)
     vecs = struct.get_distances(myself.flatten(), neigh.indices.flatten(), mic=True, vector=True)
     self.assertAlmostEqual(np.absolute(vecs-neigh.vecs.reshape(-1, 3)).max(), 0)
     dist = struct.get_scaled_positions()
     dist = dist[:,np.newaxis,:]-dist[np.newaxis,:,:]
     dist -= np.rint(dist)
     dist = np.einsum('nmi,ij->nmj', dist, struct.cell)
     dist = np.linalg.norm(dist, axis=-1).flatten()
     dist = dist[dist>0]
     self.assertAlmostEqual(neigh.distances.min(), dist.min())
     struct = CrystalStructure(elements='Fe', lattice_constants=2.85, bravais_basis='bcc').repeat(10)
     struct.pbc = False
     cell = struct.cell.copy()
     cell += np.random.random((3,3))-0.5
     struct.set_cell(cell, scale_atoms=True)
     neigh = struct.get_neighbors()
     self.assertAlmostEqual(np.absolute(neigh.distances-np.linalg.norm(neigh.vecs, axis=-1)).max(), 0)
     myself = np.ones_like(neigh.indices)
     myself = myself*np.arange(len(myself))[:,np.newaxis]
     dist = np.linalg.norm(struct.positions[myself]-struct.positions[neigh.indices], axis=-1)
     self.assertAlmostEqual(np.absolute(dist-neigh.distances).max(), 0)
     struct = CrystalStructure(elements='Fe', lattice_constants=2.85, bravais_basis='bcc').repeat(10)
     neigh = struct.get_neighbors()
     self.assertAlmostEqual(np.absolute(neigh.distances-np.linalg.norm(neigh.vecs, axis=-1)).max(), 0)
     self.assertAlmostEqual(neigh.vecs[neigh.shells==1].sum(), 0)
     self.assertAlmostEqual(neigh.vecs[0, neigh.shells[0]==1].sum(), 0)
     struct = CrystalStructure(elements='Fe', lattice_constants=2.85, bravais_basis='bcc')
     neigh = struct.get_neighbors()
     self.assertAlmostEqual(neigh.vecs[neigh.shells==1].sum(), 0)
     struct = CrystalStructure(elements='Al', lattice_constants=4.04, bravais_basis='bcc').repeat(10)
     neigh = struct.get_neighbors()
     self.assertAlmostEqual(np.absolute(neigh.distances-np.linalg.norm(neigh.vecs, axis=-1)).max(), 0)
     self.assertAlmostEqual(neigh.vecs[neigh.shells==1].sum(), 0)
     self.assertAlmostEqual(neigh.vecs[0, neigh.shells[0]==1].sum(), 0)
     struct = CrystalStructure(elements='Al', lattice_constants=4.04, bravais_basis='bcc')
     neigh = struct.get_neighbors()
     self.assertAlmostEqual(np.absolute(neigh.distances-np.linalg.norm(neigh.vecs, axis=-1)).max(), 0)
     self.assertAlmostEqual(neigh.vecs[neigh.shells==1].sum(), 0)
     with self.assertRaises(ValueError):
         struct.get_neighbors(num_neighbors=0)
Exemple #4
0
 def test_get_positions(self):
     basis_Mg = CrystalStructure("Mg",
                                 bravais_basis="fcc",
                                 lattice_constant=4.2)
     self.assertTrue(
         np.array_equal(basis_Mg.positions, basis_Mg.get_positions()))
Exemple #5
0
 def test_get_bonds(self):
     basis = CrystalStructure("Al", bravais_basis="fcc", lattice_constants=4.2).repeat(5)
     neigh = basis.get_neighbors(num_neighbors=20)
     bonds = neigh.get_bonds()
     self.assertTrue(np.array_equal(np.sort(bonds[0]['Al'][0]),
                     np.sort(neigh.indices[0, neigh.shells[0]==1])))