def test_standardize_cell_from_primitive(self): for fname in self._filenames: spgnum = int(fname.split('-')[1]) cell = read_vasp("./data/%s" % fname) if 'distorted' in fname: prim_cell = standardize_cell(cell, to_primitive=True, no_idealize=True, symprec=1e-1) std_cell = standardize_cell(prim_cell, to_primitive=False, no_idealize=True, symprec=1e-1) dataset = get_symmetry_dataset(std_cell, symprec=1e-1) else: prim_cell = standardize_cell(cell, to_primitive=True, no_idealize=True, symprec=1e-5) std_cell = standardize_cell(prim_cell, to_primitive=False, no_idealize=True, symprec=1e-5) dataset = get_symmetry_dataset(std_cell, symprec=1e-5) self.assertEqual(dataset['number'], spgnum, msg=("%s" % fname))
def _test_get_symmetry(self): """ *************************************************************** This test must be executed with spglib compiled with -DSPGTEST. *************************************************************** """ for fname in self._filenames: cell = read_vasp(fname) cell_spin = cell + ([ 1, ] * len(cell[2]), ) if 'distorted' in fname: symprec = 1e-1 else: symprec = 1e-5 dataset = get_symmetry_dataset(cell, symprec=symprec) symmetry = get_symmetry(cell_spin, symprec=symprec) self.assertEqual(len(dataset['rotations']), len(symmetry['rotations']), msg=("%s" % fname)) for r, t in zip(dataset['rotations'], dataset['translations']): found = False for r_, t_ in zip(symmetry['rotations'], symmetry['translations']): if (r == r_).all(): diff = t - t_ diff -= np.rint(diff) if (abs(diff) < symprec).all(): found = True break self.assertTrue(found, msg="%s" % fname)
def test_find_primitive(self): for fname in self._filenames: cell = read_vasp(fname) if 'distorted' in fname: symprec = 1e-1 else: symprec = 1e-5 dataset = get_symmetry_dataset(cell, symprec=symprec) primitive = find_primitive(cell, symprec=symprec) spg_type = get_spacegroup_type(dataset['hall_number']) c = spg_type['international_short'][0] if c in ['A', 'B', 'C', 'I']: multiplicity = 2 elif c == 'F': multiplicity = 4 elif c == 'R': self.assertEqual(spg_type['choice'], 'H') if spg_type['choice'] == 'H': multiplicity = 3 else: # spg_type['choice'] == 'R' multiplicity = 1 else: multiplicity = 1 self.assertEqual(len(dataset['std_types']), len(primitive[2]) * multiplicity, msg=("multi: %d, %s" % (multiplicity, fname)))
def test_get_hall_number_from_symmetry(self): for fname in self._filenames: cell = read_vasp(fname) if 'distorted' in fname: dataset = get_symmetry_dataset(cell, symprec=1e-1) hall_number = get_hall_number_from_symmetry( dataset['rotations'], dataset['translations'], symprec=1e-1) if hall_number != dataset['hall_number']: print("%d != %d in %s" % (hall_number, dataset['hall_number'], fname)) ref_cell = (dataset['std_lattice'], dataset['std_positions'], dataset['std_types']) dataset = get_symmetry_dataset(ref_cell, symprec=1e-5) hall_number = get_hall_number_from_symmetry( dataset['rotations'], dataset['translations'], symprec=1e-5) print("Using refinced cell: %d, %d in %s" % (hall_number, dataset['hall_number'], fname)) else: dataset = get_symmetry_dataset(cell, symprec=1e-5) hall_number = get_hall_number_from_symmetry( dataset['rotations'], dataset['translations'], symprec=1e-5) self.assertEqual( hall_number, dataset['hall_number'], msg=("%d != %d in %s" % (hall_number, dataset['hall_number'], fname)))
def test_get_symmetry_dataset(self): for fname, spgnum, reffname in zip(self._filenames, self._spgnum_ref, self._ref_filenames): cell = read_vasp(fname) if 'distorted' in fname: symprec = 1e-1 else: symprec = 1e-5 dataset = get_symmetry_dataset(cell, symprec=symprec) self.assertEqual(dataset['number'], spgnum, msg=("%s" % fname)) for i in range(spg_to_hall[spgnum - 1], spg_to_hall[spgnum]): dataset = get_symmetry_dataset(cell, hall_number=i, symprec=symprec) self.assertEqual(dataset['hall_number'], i, msg=("%s" % fname)) spg_type = get_spacegroup_type(dataset['hall_number']) self.assertEqual(dataset['international'], spg_type['international_short'], msg=("%s" % fname)) self.assertEqual(dataset['hall'], spg_type['hall_symbol'], msg=("%s" % fname)) self.assertEqual(dataset['choice'], spg_type['choice'], msg=("%s" % fname)) self.assertEqual(dataset['pointgroup'], spg_type['pointgroup_schoenflies'], msg=("%s" % fname)) wyckoffs = dataset['wyckoffs'] with open(reffname) as f: wyckoffs_ref = yaml.load(f)['wyckoffs'] for w, w_ref in zip(wyckoffs, wyckoffs_ref): self.assertEqual(w, w_ref, msg=("%s" % fname))
def test_get_stabilized_reciprocal_mesh(self): for fname in self._filenames: cell = read_vasp("./data/%s" % fname) rotations = get_symmetry_from_database(513)['rotations'] ir_rec_mesh = get_stabilized_reciprocal_mesh(self._mesh, rotations) (mapping_table, grid_address) = ir_rec_mesh data = np.loadtxt(StringIO(result_ir_rec_mesh), dtype='intc') self.assertTrue((data[:, 0] == mapping_table).all()) self.assertTrue((data[:, 1:4] == grid_address).all())
def test_get_symmetry_dataset(self): for fname in self._filenames: spgnum = int(fname.split('-')[1]) cell = read_vasp("./data/%s" % fname) if 'distorted' in fname: dataset = get_symmetry_dataset(cell, symprec=1e-1) else: dataset = get_symmetry_dataset(cell, symprec=1e-5) self.assertEqual(dataset['number'], spgnum)
def test_get_ir_reciprocal_mesh(self): for fname in self._filenames: cell = read_vasp("./data/%s" % fname) ir_rec_mesh = get_ir_reciprocal_mesh(self._mesh, cell) (mapping_table, grid_address) = ir_rec_mesh # for gp, ga in zip(mapping_table, grid_address): # print("%4d %3d %3d %3d" % (gp, ga[0], ga[1], ga[2])) data = np.loadtxt(StringIO(result_ir_rec_mesh), dtype='intc') self.assertTrue((data[:, 0] == mapping_table).all()) self.assertTrue((data[:, 1:4] == grid_address).all())
def test_refine_cell(self): for fname, spgnum in zip(self._filenames, self._spgnum_ref): cell = read_vasp(fname) if 'distorted' in fname: dataset_orig = get_symmetry_dataset(cell, symprec=1e-1) else: dataset_orig = get_symmetry_dataset(cell, symprec=1e-5) ref_cell = (dataset_orig['std_lattice'], dataset_orig['std_positions'], dataset_orig['std_types']) dataset = get_symmetry_dataset(ref_cell, symprec=1e-5) self.assertEqual(dataset['number'], spgnum, msg=("%s" % fname))
def test_get_symmetry(self): for fname in self._filenames: spgnum = int(fname.split('-')[1]) cell = read_vasp("./data/%s" % fname) if 'distorted' in fname: num_sym_dataset = len( get_symmetry_dataset(cell, symprec=1e-1)['rotations']) num_sym = len(get_symmetry(cell, symprec=1e-1)['rotations']) else: num_sym_dataset = len( get_symmetry_dataset(cell, symprec=1e-5)['rotations']) num_sym = len(get_symmetry(cell, symprec=1e-5)['rotations']) self.assertEqual(num_sym_dataset, num_sym)
def test_get_stabilized_reciprocal_mesh(self): file_and_mesh = (["cubic/POSCAR-217", [4, 4, 4]], ["hexagonal/POSCAR-182", [4, 4, 2]]) i = 0 for fname, mesh in file_and_mesh: cell = read_vasp("./data/%s" % fname) rotations = get_symmetry_dataset(cell)['rotations'] ir_rec_mesh = get_stabilized_reciprocal_mesh(mesh, rotations) (mapping_table, grid_address) = ir_rec_mesh data = np.loadtxt(StringIO(result_ir_rec_mesh[i]), dtype='intc') np.testing.assert_equal(data[:, 0], mapping_table) np.testing.assert_equal(data[:, 1:4], grid_address) i += 1
def test_refine_cell(self): for fname in self._filenames: spgnum = int(fname.split('-')[1]) cell = read_vasp("./data/%s" % fname) if 'distorted' in fname: dataset_orig = get_symmetry_dataset(cell, symprec=1e-1) else: dataset_orig = get_symmetry_dataset(cell, symprec=1e-5) ref_cell = (dataset_orig['std_lattice'], dataset_orig['std_positions'], dataset_orig['std_types']) dataset = get_symmetry_dataset(ref_cell, symprec=1e-5) self.assertEqual(dataset['number'], spgnum, msg=("%s" % fname))
def test_standardize_cell_to_primitive(self): for fname, spgnum in zip(self._filenames, self._spgnum_ref): cell = read_vasp(fname) if 'distorted' in fname: symprec = 1e-1 else: symprec = 1e-5 prim_cell = standardize_cell(cell, to_primitive=True, no_idealize=True, symprec=symprec) dataset = get_symmetry_dataset(prim_cell, symprec=symprec) self.assertEqual(dataset['number'], spgnum, msg=("%s" % fname))
def test_get_ir_reciprocal_mesh(self): file_and_mesh = (["cubic/POSCAR-217", [4, 4, 4]], ["hexagonal/POSCAR-182", [4, 4, 2]]) i = 0 for fname, mesh in file_and_mesh: cell = read_vasp("./data/%s" % fname) ir_rec_mesh = get_ir_reciprocal_mesh(mesh, cell) (mapping_table, grid_address) = ir_rec_mesh # for gp, ga in zip(mapping_table, grid_address): # print("%4d %3d %3d %3d" % (gp, ga[0], ga[1], ga[2])) # print("") data = np.loadtxt(StringIO(result_ir_rec_mesh[i]), dtype='intc') np.testing.assert_equal(data[:, 0], mapping_table) np.testing.assert_equal(data[:, 1:4], grid_address) i += 1
def test_change_of_basis(self): for fname in self._filenames: cell = read_vasp(fname) if 'distorted' in fname: symprec = 1e-1 else: symprec = 1e-5 dataset = get_symmetry_dataset(cell, symprec=symprec) std_lat = dataset['std_lattice'] std_pos = dataset['std_positions'] tmat = dataset['transformation_matrix'] orig_shift = dataset['origin_shift'] lat = np.dot(cell[0].T, np.linalg.inv(tmat)) pos = np.dot(cell[1], tmat.T) + orig_shift self._compare(lat, pos, std_lat, std_pos, 2 * symprec)
def test_std_rotation(self): for fname in self._filenames: cell = read_vasp(fname) if 'distorted' in fname: symprec = 1e-1 else: symprec = 1e-5 dataset = get_symmetry_dataset(cell, symprec=symprec) std_lat = dataset['std_lattice'] tmat = dataset['transformation_matrix'] lat = np.dot(cell[0].T, np.linalg.inv(tmat)) lat_rot = np.dot(dataset['std_rotation_matrix'], lat) np.testing.assert_allclose(std_lat, lat_rot.T, atol=symprec, err_msg="%s" % fname)
def setUp(self): identity = np.eye(3, dtype='intc') file_and_mesh = ( [os.path.join(data_dir, "data", "cubic", "POSCAR-217"), [4, 4, 4]], [os.path.join(data_dir, "data", "hexagonal", "POSCAR-182"), [4, 4, 2]]) self.meshes = [] self.cells = [] self.rotations = [] self.grid_addresses = [] for i, (fname, mesh) in enumerate(file_and_mesh): self.meshes.append(mesh) self.cells.append(read_vasp(fname)) self.rotations.append( get_symmetry_dataset(self.cells[i])['rotations']) _, ga = get_stabilized_reciprocal_mesh(mesh, [identity, ]) self.grid_addresses.append(ga)
def test_standardize_cell_and_pointgroup(self): for fname, spgnum in zip(self._filenames, self._spgnum_ref): cell = read_vasp(fname) if 'distorted' in fname: symprec = 1e-1 else: symprec = 1e-5 std_cell = standardize_cell(cell, to_primitive=False, no_idealize=True, symprec=symprec) dataset = get_symmetry_dataset(std_cell, symprec=symprec) self.assertEqual(dataset['number'], spgnum, msg=("%s" % fname)) # The test for point group has to be done after standarization. ptg_symbol, _, _ = get_pointgroup(dataset['rotations']) self.assertEqual(dataset['pointgroup'], ptg_symbol, msg=("%s" % fname))
def setUp(self): self._filenames = [] self._datasets = [] self._cells = [] self._symprecs = [] for d in dirnames: dirname = os.path.join(data_dir, "data", d) filenames = os.listdir(dirname) self._filenames += [os.path.join(dirname, fname) for fname in filenames] for fname in self._filenames: cell = read_vasp(fname) if 'distorted' in fname: symprec = 1e-1 else: symprec = 1e-5 self._datasets.append( get_symmetry_dataset(cell, symprec=symprec)) self._cells.append(cell) self._symprecs.append(symprec)
def test_get_symmetry_dataset(self): for fname in self._filenames: spgnum = int(fname.split('-')[1]) cell = read_vasp("./data/%s" % fname) if 'distorted' in fname: dataset = get_symmetry_dataset(cell, symprec=1e-1) else: dataset = get_symmetry_dataset(cell, symprec=1e-5) self.assertEqual(dataset['number'], spgnum, msg=("%s" % fname)) spg_type = get_spacegroup_type(dataset['hall_number']) self.assertEqual(dataset['international'], spg_type['international_short'], msg=("%s" % fname)) self.assertEqual(dataset['hall'], spg_type['hall_symbol'], msg=("%s" % fname)) self.assertEqual(dataset['choice'], spg_type['choice'], msg=("%s" % fname)) self.assertEqual(dataset['pointgroup'], spg_type['pointgroup_schoenflies'], msg=("%s" % fname))
def test_get_ir_reciprocal_mesh_distortion(self): file_and_mesh = ([ os.path.join(data_dir, "data", "cubic", "POSCAR-217"), [3, 4, 4] ], [ os.path.join(data_dir, "data", "hexagonal", "POSCAR-182"), [3, 5, 1] ]) i = 0 for is_shift in ([0, 0, 0], [0, 1, 0]): for fname, mesh in file_and_mesh: cell = read_vasp(fname) ir_rec_mesh = get_ir_reciprocal_mesh(mesh, cell, is_shift=is_shift) (mapping_table, grid_address) = ir_rec_mesh # for gp, ga in zip(mapping_table, grid_address): # print("%4d %3d %3d %3d" % (gp, ga[0], ga[1], ga[2])) # print("") data = np.loadtxt(StringIO(result_ir_rec_mesh_distortion[i]), dtype='intc') np.testing.assert_equal(data[:, 0], mapping_table) np.testing.assert_equal(data[:, 1:4], grid_address) i += 1
def test_rhomb_prim_agreement_over_settings(self): for fname in self._filenames: cell = read_vasp(fname) symprec = 1e-5 dataset_H = get_symmetry_dataset(cell, symprec=symprec) hall_number_R = dataset_H['hall_number'] + 1 dataset_R = get_symmetry_dataset(cell, hall_number=hall_number_R, symprec=symprec) plat, _, _ = find_primitive(cell) plat_H = np.dot(dataset_H['std_lattice'].T, tmat).T plat_R = dataset_R['std_lattice'] np.testing.assert_allclose(plat, plat_H, atol=1e-5, err_msg="%s" % fname) np.testing.assert_allclose(plat_R, plat_H, atol=1e-5, err_msg="%s" % fname) np.testing.assert_allclose(plat_R, plat, atol=1e-5, err_msg="%s" % fname)
#!/usr/bin/evn python import sys from atoms import Atoms from vasp import read_vasp from pyspglib import spglib import numpy as np def get_magmom(text): magmom = [] for numxmag in text.split(): num, mag = numxmag.split('*') magmom += [float(mag)] * int(num) return magmom def parse_incar(filename): for line in open(filename): for conf in line.split(';'): if 'MAGMOM' in conf: return get_magmom(conf.split('=')[1]) cell = read_vasp(sys.argv[1]) # POSCAR magmoms = parse_incar(sys.argv[2]) # INCAR cell.set_magnetic_moments(magmoms) symmetry = spglib.get_symmetry(cell, symprec=1e-3) print len(symmetry['rotations'])
parser.set_defaults(mesh=None, qpoints=None) parser.add_option("-m", "--mesh", dest="mesh", type="string", help="Mesh numbers") parser.add_option("-q", "--qpoints", dest="qpoints", type="string", help="Stabilizers") (options, args) = parser.parse_args() if options.mesh == None: mesh = [4, 4, 4] else: mesh = [int(x) for x in options.mesh.split()] if options.qpoints == None: qpoints = np.array([[0, 0, 0]], dtype=float) else: qpoints = np.array([float(x) for x in options.qpoints.split()]).reshape(-1, 3) cell = read_vasp(args[0]) mapping_g, grid_point = spglib.get_ir_reciprocal_mesh(mesh, cell) print mapping_g dataset = spglib.get_symmetry_dataset(cell) mapping, grid_point = spglib.get_stabilized_reciprocal_mesh(mesh, dataset["rotations"], qpoints=qpoints) print mapping print "%d / %d" % (np.sum((mapping_g == mapping) * 1), len(mapping)) # for i, m in enumerate(mapping): # print i, grid_point[m]
dest="mesh", type="string", help="Mesh numbers") parser.add_option("-f", dest="filename", type="string", help="Filename of triplets at q") parser.add_option("-g", dest="grid_point", type="int", help="A grid point") (options, args) = parser.parse_args() if options.mesh == None: mesh = [4, 4, 4] else: mesh = [int(x) for x in options.mesh.split()] cell = read_vasp(args[0]) dataset = spglib.get_symmetry_dataset(cell) weights, third_q, grid_points = \ spglib.get_triplets_reciprocal_mesh_at_q(options.grid_point, mesh, dataset['rotations']) if options.filename == None: for i, (w, q) in enumerate(zip(weights, third_q)): if w > 0: print options.grid_point, i, q, w else: triplets_in, weights_in = parse_triplets(options.filename) count = 0 for i, (w, q) in enumerate(zip(weights, third_q)):