def test_magmom(self): symprec = 1e-5 cell = get_unitcell_from_phonopy_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)
def test_magmom(self): symprec = 1e-5 cell = get_unitcell_from_phonopy_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)
def test_read_pwscf(self): cell, pp_filenames = read_pwscf("NaCl-pwscf.in") cell_ref = get_unitcell_from_phonopy_yaml("NaCl-pwscf.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)
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 = get_unitcell_from_phonopy_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)
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 = get_unitcell_from_phonopy_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)
def test_read_pwscf(self): 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 = get_unitcell_from_phonopy_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)
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 = get_unitcell_from_phonopy_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)
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 = get_unitcell_from_phonopy_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)
def test_get_map_operations(self): symprec = 1e-5 cell = get_unitcell_from_phonopy_yaml("../NaCl.yaml") scell = get_supercell(cell, np.diag([2, 2, 2]), symprec=symprec) symmetry = Symmetry(scell, symprec=symprec) map_ops_cmp = [ 0, 2, 51, 53, 8, 1, 65, 98, 3, 14, 34, 24, 76, 69, 54, 110, 576, 198, 229, 208, 201, 192, 210, 294, 5, 67, 36, 57, 18, 90, 23, 114, 0, 9, 1, 96, 6, 323, 98, 326, 3, 42, 17, 293, 16, 130, 99, 337, 192, 194, 202, 199, 205, 196, 200, 193, 12, 5, 30, 108, 37, 128, 291, 302 ] start = time.time() symmetry._set_map_operations() end = time.time() # print(end - start) map_ops = symmetry.get_map_operations() self.assertTrue((map_ops_cmp == map_ops).all())
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 = get_unitcell_from_phonopy_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)
def test_get_map_operations(self): symprec = 1e-5 cell = get_unitcell_from_phonopy_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())
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 = get_unitcell_from_phonopy_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)
def test_get_map_operations(self): symprec = 1e-5 cell = get_unitcell_from_phonopy_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())
def setUp(self): filename = "POSCAR.yaml" self._cell = get_unitcell_from_phonopy_yaml(filename)
def setUp(self): filename = os.path.join("..", "NaCl.yaml") self._cell = get_unitcell_from_phonopy_yaml( os.path.join(data_dir, filename))
def setUp(self): filename = "../NaCl.yaml" self._cell = get_unitcell_from_phonopy_yaml(os.path.join(data_dir,filename))
def setUp(self): filename = "../NaCl.yaml" self._cell = get_unitcell_from_phonopy_yaml(filename)