Esempio n. 1
0
    def test_magmom(self):
        symprec = 1e-5
        cell = read_cell_yaml(os.path.join(data_dir, "Cr.yaml"))
        symmetry_nonspin = Symmetry(cell, symprec=symprec)
        atom_map_nonspin = symmetry_nonspin.get_map_atoms()
        len_sym_nonspin = len(
            symmetry_nonspin.get_symmetry_operations()['rotations'])

        spin = [1, -1]
        cell_withspin = cell.copy()
        cell_withspin.set_magnetic_moments(spin)
        symmetry_withspin = Symmetry(cell_withspin, symprec=symprec)
        atom_map_withspin = symmetry_withspin.get_map_atoms()
        len_sym_withspin = len(
            symmetry_withspin.get_symmetry_operations()['rotations'])

        broken_spin = [1, -2]
        cell_brokenspin = cell.copy()
        cell_brokenspin = cell.copy()
        cell_brokenspin.set_magnetic_moments(broken_spin)
        symmetry_brokenspin = Symmetry(cell_brokenspin, symprec=symprec)
        atom_map_brokenspin = symmetry_brokenspin.get_map_atoms()
        len_sym_brokenspin = len(
            symmetry_brokenspin.get_symmetry_operations()['rotations'])

        self.assertTrue((atom_map_nonspin == atom_map_withspin).all())
        self.assertFalse((atom_map_nonspin == atom_map_brokenspin).all())
        self.assertTrue(len_sym_nonspin == len_sym_withspin)
        self.assertFalse(len_sym_nonspin == len_sym_brokenspin)
Esempio n. 2
0
def _test_get_supercell_convcell_sio2(convcell_sio2: PhonopyAtoms,
                                      helper_methods,
                                      is_old_style=True):
    smat = np.diag([1, 2, 3])
    fname = "SiO2-123.yaml"
    scell = get_supercell(convcell_sio2, smat, is_old_style=is_old_style)
    cell_ref = read_cell_yaml(os.path.join(data_dir, fname))
    if is_old_style is True:
        helper_methods.compare_cells_with_order(scell, cell_ref)
    else:
        helper_methods.compare_cells(scell, cell_ref)
Esempio n. 3
0
def test_read_pwscf():
    """Test of read_pwscf."""
    cell, pp_filenames = read_pwscf(os.path.join(data_dir, "NaCl-pwscf.in"))
    filename = os.path.join(data_dir, "NaCl-abinit-pwscf.yaml")
    cell_ref = read_cell_yaml(filename)
    assert (np.abs(cell.cell - cell_ref.cell) < 1e-5).all()
    diff_pos = cell.scaled_positions - cell_ref.scaled_positions
    diff_pos -= np.rint(diff_pos)
    assert (np.abs(diff_pos) < 1e-5).all()
    for s, s_r in zip(cell.symbols, cell_ref.symbols):
        assert s == s_r
Esempio n. 4
0
def test_read_vasp():
    """Test read_vasp."""
    cell = read_vasp(os.path.join(data_dir, "..", "POSCAR_NaCl"))
    filename = os.path.join(data_dir, "NaCl-vasp.yaml")
    cell_ref = read_cell_yaml(filename)
    assert (np.abs(cell.cell - cell_ref.cell) < 1e-5).all()
    diff_pos = cell.scaled_positions - cell_ref.scaled_positions
    diff_pos -= np.rint(diff_pos)
    assert (np.abs(diff_pos) < 1e-5).all()
    for s, s_r in zip(cell.symbols, cell_ref.symbols):
        assert s == s_r
Esempio n. 5
0
def test_read_turbomole():
    """Test read_turbomole."""
    cell = read_turbomole(os.path.join(data_dir, "Si-TURBOMOLE-control"))
    filename = os.path.join(data_dir, "Si-TURBOMOLE.yaml")
    cell_ref = read_cell_yaml(filename)
    assert (np.abs(cell.cell - cell_ref.cell) < 1e-5).all()
    diff_pos = cell.scaled_positions - cell_ref.scaled_positions
    diff_pos -= np.rint(diff_pos)
    assert (np.abs(diff_pos) < 1e-5).all()
    for s, s_r in zip(cell.symbols, cell_ref.symbols):
        assert s == s_r
Esempio n. 6
0
def _test_get_supercell_primcell_si(primcell_si: PhonopyAtoms,
                                    helper_methods,
                                    is_old_style=True):
    smat = [[-1, 1, 1], [1, -1, 1], [1, 1, -1]]
    fname = "Si-conv.yaml"
    scell = get_supercell(primcell_si, smat, is_old_style=is_old_style)
    cell_ref = read_cell_yaml(os.path.join(data_dir, fname))
    if is_old_style is True:
        helper_methods.compare_cells_with_order(scell, cell_ref)
    else:
        helper_methods.compare_cells(scell, cell_ref)
Esempio n. 7
0
def test_read_crystal():
    """Test of read_crystal."""
    cell, pp_filenames = read_crystal(os.path.join(data_dir, "Si-CRYSTAL.o"))
    filename = os.path.join(data_dir, "Si-CRYSTAL.yaml")
    cell_ref = read_cell_yaml(filename)
    assert (np.abs(cell.cell - cell_ref.cell) < 1e-5).all()
    diff_pos = cell.scaled_positions - cell_ref.scaled_positions
    diff_pos -= np.rint(diff_pos)
    assert (np.abs(diff_pos) < 1e-5).all()
    for s, s_r in zip(cell.symbols, cell_ref.symbols):
        assert s == s_r
Esempio n. 8
0
 def test_read_cp2k(self):
     cell, _ = read_cp2k(os.path.join(data_dir, "Si-CP2K.inp"))
     cell_ref = read_cell_yaml(os.path.join(data_dir, "Si-CP2K.yaml"))
     self.assertTrue(
         (np.abs(cell.get_cell() - cell_ref.get_cell()) < 1e-5).all())
     diff_pos = (cell.get_scaled_positions()
                 - cell_ref.get_scaled_positions())
     diff_pos -= np.rint(diff_pos)
     self.assertTrue((np.abs(diff_pos) < 1e-5).all())
     for s, s_r in zip(cell.get_chemical_symbols(),
                       cell_ref.get_chemical_symbols()):
         self.assertTrue(s == s_r)
Esempio n. 9
0
def test_parse_wien2k_struct():
    """Test structure parsing."""
    filename_BaGa2 = os.path.join(data_dir, "BaGa2.struct")
    cell, _, _, _ = parse_wien2k_struct(filename_BaGa2)
    filename = os.path.join(data_dir, "BaGa2-wien2k.yaml")
    cell_ref = read_cell_yaml(filename)
    assert (np.abs(cell.cell - cell_ref.cell) < 1e-5).all()
    diff_pos = cell.scaled_positions - cell_ref.scaled_positions
    diff_pos -= np.rint(diff_pos)
    assert (np.abs(diff_pos) < 1e-5).all()
    for s, s_r in zip(cell.symbols, cell_ref.symbols):
        assert s == s_r
Esempio n. 10
0
 def test_read_castep(self):
     cell = read_castep(os.path.join(data_dir, "NaCl-castep.cell"))
     filename = os.path.join(data_dir, "NaCl-castep.yaml")
     cell_ref = read_cell_yaml(filename)
     self.assertTrue(
         (np.abs(cell.get_cell() - cell_ref.get_cell()) < 1e-5).all())
     diff_pos = (cell.get_scaled_positions() -
                 cell_ref.get_scaled_positions())
     diff_pos -= np.rint(diff_pos)
     self.assertTrue((np.abs(diff_pos) < 1e-5).all())
     for s, s_r in zip(cell.get_chemical_symbols(),
                       cell_ref.get_chemical_symbols()):
         self.assertTrue(s == s_r)
Esempio n. 11
0
 def test_read_abinit(self):
     cell = read_abinit(os.path.join(data_dir, "NaCl-abinit.in"))
     filename = os.path.join(data_dir, "NaCl-abinit-pwscf.yaml")
     cell_ref = read_cell_yaml(filename)
     self.assertTrue(
         (np.abs(cell.get_cell() - cell_ref.get_cell()) < 1e-5).all())
     diff_pos = (cell.get_scaled_positions()
                 - cell_ref.get_scaled_positions())
     diff_pos -= np.rint(diff_pos)
     self.assertTrue((np.abs(diff_pos) < 1e-5).all())
     for s, s_r in zip(cell.get_chemical_symbols(),
                       cell_ref.get_chemical_symbols()):
         self.assertTrue(s == s_r)
Esempio n. 12
0
 def test_parse_wien2k_struct(self):
     filename_BaGa2 = os.path.join(data_dir, "BaGa2.struct")
     cell, npts, r0s, rmts = parse_wien2k_struct(filename_BaGa2)
     filename = os.path.join(data_dir, "BaGa2-wien2k.yaml")
     cell_ref = read_cell_yaml(filename)
     self.assertTrue(
         (np.abs(cell.get_cell() - cell_ref.get_cell()) < 1e-5).all())
     diff_pos = (cell.get_scaled_positions() -
                 cell_ref.get_scaled_positions())
     diff_pos -= np.rint(diff_pos)
     self.assertTrue((np.abs(diff_pos) < 1e-5).all())
     for s, s_r in zip(cell.get_chemical_symbols(),
                       cell_ref.get_chemical_symbols()):
         self.assertTrue(s == s_r)
Esempio n. 13
0
 def test_parse_wien2k_struct(self):
     filename_BaGa2 = os.path.join(data_dir, "BaGa2.struct")
     cell, npts, r0s, rmts = parse_wien2k_struct(filename_BaGa2)
     filename = os.path.join(data_dir, "BaGa2-wien2k.yaml")
     cell_ref = read_cell_yaml(filename)
     self.assertTrue(
         (np.abs(cell.get_cell() - cell_ref.get_cell()) < 1e-5).all())
     diff_pos = (cell.get_scaled_positions()
                 - cell_ref.get_scaled_positions())
     diff_pos -= np.rint(diff_pos)
     self.assertTrue((np.abs(diff_pos) < 1e-5).all())
     for s, s_r in zip(cell.get_chemical_symbols(),
                       cell_ref.get_chemical_symbols()):
         self.assertTrue(s == s_r)
Esempio n. 14
0
 def test_read_crystal(self):
     cell, pp_filenames = read_crystal(os.path.join(data_dir,
                                                    "Si-CRYSTAL.o"))
     filename = os.path.join(data_dir, "Si-CRYSTAL.yaml")
     cell_ref = read_cell_yaml(filename)
     self.assertTrue(
         (np.abs(cell.get_cell() - cell_ref.get_cell()) < 1e-5).all())
     diff_pos = (cell.get_scaled_positions()
                 - cell_ref.get_scaled_positions())
     diff_pos -= np.rint(diff_pos)
     self.assertTrue((np.abs(diff_pos) < 1e-5).all())
     for s, s_r in zip(cell.get_chemical_symbols(),
                       cell_ref.get_chemical_symbols()):
         self.assertTrue(s == s_r)
Esempio n. 15
0
 def test_read_turbomole(self):
     cell = read_turbomole(os.path.join(data_dir,
                                        "Si-TURBOMOLE-control"))
     filename = os.path.join(data_dir, "Si-TURBOMOLE.yaml")
     cell_ref = read_cell_yaml(filename)
     self.assertTrue(
         (np.abs(cell.get_cell() - cell_ref.get_cell()) < 1e-5).all())
     diff_pos = (cell.get_scaled_positions()
                 - cell_ref.get_scaled_positions())
     diff_pos -= np.rint(diff_pos)
     self.assertTrue((np.abs(diff_pos) < 1e-5).all())
     for s, s_r in zip(cell.get_chemical_symbols(),
                       cell_ref.get_chemical_symbols()):
         self.assertTrue(s == s_r)
Esempio n. 16
0
def test_watch_GeneralizedRegularGridPoints(ph_tio2: Phonopy, helper_methods):
    """Test for q-points positions obtained from GeneralizedRegularGridPoints."""
    grgp = GeneralizedRegularGridPoints(ph_tio2.unitcell, 10, x_fastest=False)
    tmat = grgp.transformation_matrix
    # direct basis vectors in row vectors
    plat = np.dot(tmat.T, ph_tio2.unitcell.cell)
    # reciprocal basis vectors in row vectors (10 times magnified)
    rec_plat = np.linalg.inv(plat).T * 10
    nums = [
        1,
    ] * len(grgp.qpoints)
    cell = PhonopyAtoms(cell=rec_plat,
                        scaled_positions=grgp.qpoints,
                        numbers=nums)
    yaml_filename = os.path.join(current_dir, "tio2_qpoints.yaml")
    cell_ref = read_cell_yaml(yaml_filename)
    helper_methods.compare_cells(cell, cell_ref)
Esempio n. 17
0
 def test_get_supercell(self):
     for i, (cell, smat, fname) in enumerate(zip(self._cells,
                                                 self._smats,
                                                 self._fnames)):
         scell = get_supercell(cell, smat)
         scell_yaml = read_cell_yaml(os.path.join(data_dir, fname))
         np.testing.assert_allclose(scell.get_cell(), scell_yaml.get_cell(),
                                    atol=1e-5)
         pos = scell.get_scaled_positions()
         pos -= np.rint(pos)
         pos_yaml = scell_yaml.get_scaled_positions()
         pos_yaml -= np.rint(pos_yaml)
         np.testing.assert_allclose(pos, pos_yaml, atol=1e-5)
         np.testing.assert_array_equal(scell.get_atomic_numbers(),
                                       scell_yaml.get_atomic_numbers())
         np.testing.assert_allclose(scell.get_masses(),
                                    scell_yaml.get_masses(),
                                    atol=1e-5)
Esempio n. 18
0
 def test_get_map_operations(self):
     symprec = 1e-5
     cell = read_cell_yaml(os.path.join(data_dir, "..", "NaCl.yaml"))
     scell = get_supercell(cell, np.diag([2, 2, 2]), symprec=symprec)
     symmetry = Symmetry(scell, symprec=symprec)
     # start = time.time()
     symmetry._set_map_operations()
     # end = time.time()
     # print(end - start)
     map_ops = symmetry.get_map_operations()
     map_atoms = symmetry.get_map_atoms()
     positions = scell.get_scaled_positions()
     rotations = symmetry.get_symmetry_operations()['rotations']
     translations = symmetry.get_symmetry_operations()['translations']
     for i, (op_i, atom_i) in enumerate(zip(map_ops, map_atoms)):
         r_pos = np.dot(rotations[op_i], positions[i]) + translations[op_i]
         diff = positions[atom_i] - r_pos
         diff -= np.rint(diff)
         self.assertTrue((diff < symprec).all())
Esempio n. 19
0
    def setUp(self):
        pmat = [[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]
        smat2 = np.eye(3, dtype='intc') * 2
        pmat2 = np.dot(np.linalg.inv(smat2), pmat)
        smat3 = np.eye(3, dtype='intc') * 3
        pmat3 = np.dot(np.linalg.inv(smat3), pmat)

        cell = read_cell_yaml(os.path.join(data_dir, "..", "NaCl.yaml"))
        scell2 = get_supercell(cell, smat2)
        scell3 = get_supercell(cell, smat3)
        n = len(scell3) // 2
        # swap first and last half of atomic order
        indices = [i + n for i in range(n)] + list(range(n))
        scell3_swap = PhonopyAtoms(
            cell=scell3.cell,
            scaled_positions=scell3.scaled_positions[indices],
            numbers=scell3.numbers[indices])
        self._tcell2 = TrimmedCell(pmat2, scell2)
        self._tcell3 = TrimmedCell(
            pmat3,
            scell3_swap,
            positions_to_reorder=self._tcell2.scaled_positions)
Esempio n. 20
0
 def setUp(self):
     self.pmat = [[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]
     self.smat = np.eye(3, dtype='int') * 2
     self.cell = read_cell_yaml(os.path.join(data_dir, "..", "NaCl.yaml"))
     self.scell, self.pcell = _get_supercell_and_primitive(
         self.cell,
         primitive_matrix=self.pmat,
         supercell_matrix=self.smat)
     self.idx = [self.scell.u2u_map[i]
                 for i in self.scell.s2u_map[self.pcell.p2s_map]]
     self.epsilon = np.array([[2.43533967, 0, 0],
                              [0, 2.43533967, 0],
                              [0, 0, 2.43533967]])
     self.borns = np.array([[[1.08875538, 0, 0],
                             [0, 1.08875538, 0],
                             [0, 0, 1.08875538]],
                            [[1.08875538, 0, 0],
                             [0, 1.08875538, 0],
                             [0, 0, 1.08875538]],
                            [[1.08875538, 0, 0],
                             [0, 1.08875538, 0],
                             [0, 0, 1.08875538]],
                            [[1.08875538, 0, 0],
                             [0, 1.08875538, 0],
                             [0, 0, 1.08875538]],
                            [[-1.08875538, 0, 0],
                             [0, -1.08875538, 0],
                             [0, 0, -1.08875538]],
                            [[-1.08875538, 0, 0],
                             [0, -1.08875538, 0],
                             [0, 0, -1.08875538]],
                            [[-1.08875538, 0, 0],
                             [0, -1.08875538, 0],
                             [0, 0, -1.08875538]],
                            [[-1.08875538, 0, 0],
                             [0, -1.08875538, 0],
                             [0, 0, -1.08875538]]])
Esempio n. 21
0
 def setUp(self):
     self._cell = read_cell_yaml(os.path.join(data_dir, "POSCAR.yaml"))
Esempio n. 22
0
 def setUp(self):
     cell = read_cell_yaml(os.path.join(data_dir, "..", "NaCl.yaml"))
     self._pcell = get_primitive(cell, [[0, 0.5, 0.5],
                                        [0.5, 0, 0.5],
                                        [0.5, 0.5, 0]])
Esempio n. 23
0
 def setUp(self):
     filename = os.path.join("..", "NaCl.yaml")
     self._cell = read_cell_yaml(os.path.join(data_dir, filename))
Esempio n. 24
0
def agno2_cell():
    """Return AgNO2 cell (Imm2)."""
    cell = read_cell_yaml(os.path.join(current_dir, "AgNO2_cell.yaml"))
    return cell