def _testBrillouinZone(self, direct_lat, mesh, is_shift): _, grid_address = get_stabilized_reciprocal_mesh(mesh, rotations=[ np.eye( 3, dtype='intc'), ], is_shift=is_shift) rec_lat = np.linalg.inv(direct_lat) bz_grid_address, bz_map = relocate_BZ_grid_address(grid_address, mesh, rec_lat, is_shift=is_shift) qpoints = (grid_address + np.array(is_shift) / 2.0) / mesh bz = BrillouinZone(rec_lat) bz.run(qpoints) sv_all = bz.shortest_qpoints # including BZ boundary duplicates sv = [v[0] for v in sv_all] bz_qpoints = (bz_grid_address + np.array(is_shift) / 2.0) / mesh d2_this = (np.dot(sv, rec_lat.T)**2).sum(axis=1) d2_spglib = (np.dot(bz_qpoints[:np.prod(mesh)], rec_lat.T)**2).sum(axis=1) diff = d2_this - d2_spglib diff -= np.rint(diff) # Following both of two tests are necessary. # Check equivalence of vectors by lattice translation np.testing.assert_allclose(diff, 0, atol=1e-8) # Check being in same (hopefull first) Brillouin zone by their lengths np.testing.assert_allclose(d2_this, d2_spglib, atol=1e-8)
def get_ir_grid_points(mesh, rotations, mesh_shifts=[False, False, False]): grid_mapping_table, grid_address = spg.get_stabilized_reciprocal_mesh( mesh, rotations, is_shift=np.where(mesh_shifts, 1, 0)) (ir_grid_points, ir_grid_weights) = extract_ir_grid_points(grid_mapping_table) return ir_grid_points, ir_grid_weights, grid_address
def _set_ir_qpoints(self, rotations, is_time_reversal=True): grid_mapping_table, grid_address = get_stabilized_reciprocal_mesh( self._mesh, rotations, is_shift=self._is_shift, is_time_reversal=is_time_reversal) shift = np.array(self._is_shift, dtype='intc') * 0.5 if self._fit_in_BZ: self._grid_address = relocate_BZ_grid_address( grid_address, self._mesh, self._rec_lat, is_shift=self._is_shift)[0][:np.prod(self._mesh)] else: self._grid_address = grid_address (self._ir_grid_points, self._ir_weights) = extract_ir_grid_points(grid_mapping_table) self._ir_qpoints = (self._grid_address[self._ir_grid_points] + shift) / self._mesh self._grid_mapping_table = grid_mapping_table
def get_grid_address(mesh): grid_mapping_table, grid_address = spg.get_stabilized_reciprocal_mesh( mesh, [[[1, 0, 0], [0, 1, 0], [0, 0, 1]]], is_time_reversal=False) return grid_address
def _set_ir_qpoints(self, rotations, is_time_reversal=True): grid_mapping_table, grid_address = get_stabilized_reciprocal_mesh( self._mesh, rotations, is_shift=self._is_shift, is_time_reversal=is_time_reversal) shift = np.array(self._is_shift, dtype='intc') * 0.5 if self._fit_in_BZ: self._grid_address = relocate_BZ_grid_address( grid_address, self._mesh, self._rec_lat, is_shift=self._is_shift)[0][:np.prod(self._mesh)] else: self._grid_address = grid_address (self._ir_grid_points, self._ir_weights) = extract_ir_grid_points(grid_mapping_table) self._ir_qpoints = np.array( (self._grid_address[self._ir_grid_points] + shift) / self._mesh, dtype='double', order='C') self._grid_mapping_table = grid_mapping_table
def _testBrillouinZone(self, direct_lat, mesh, is_shift): _, grid_address = get_stabilized_reciprocal_mesh( mesh, rotations=[np.eye(3, dtype='intc'), ], is_shift=is_shift) rec_lat = np.linalg.inv(direct_lat) bz_grid_address, bz_map = relocate_BZ_grid_address( grid_address, mesh, rec_lat, is_shift=is_shift) qpoints = (grid_address + np.array(is_shift) / 2.0) / mesh bz = BrillouinZone(rec_lat) bz.run(qpoints) sv_all = bz.shortest_qpoints # including BZ boundary duplicates sv = [v[0] for v in sv_all] bz_qpoints = (bz_grid_address + np.array(is_shift) / 2.0) / mesh d2_this = (np.dot(sv, rec_lat.T) ** 2).sum(axis=1) d2_spglib = (np.dot(bz_qpoints[:np.prod(mesh)], rec_lat.T) ** 2).sum(axis=1) diff = d2_this - d2_spglib diff -= np.rint(diff) # Following both of two tests are necessary. # Check equivalence of vectors by lattice translation np.testing.assert_allclose(diff, 0, atol=1e-8) # Check being in same (hopefull first) Brillouin zone by their lengths np.testing.assert_allclose(d2_this, d2_spglib, atol=1e-8)
def get_grid_address(mesh, is_time_reversal=False, is_shift=np.zeros(3, dtype='intc'), is_return_map=False): grid_mapping_table, grid_address = spg.get_stabilized_reciprocal_mesh( mesh, [[[1, 0, 0], [0, 1, 0], [0, 0, 1]]], is_time_reversal=is_time_reversal, is_shift=is_shift) if is_return_map: return grid_address, grid_mapping_table else: return grid_address
def get_ir_grid_points(mesh, rotations, mesh_shifts=[False, False, False]): grid_mapping_table, grid_address = spg.get_stabilized_reciprocal_mesh( mesh, rotations, is_shift=np.where(mesh_shifts, 1, 0)) ir_grid_points = np.unique(grid_mapping_table) weights = np.zeros_like(grid_mapping_table) for g in grid_mapping_table: weights[g] += 1 ir_grid_weights = weights[ir_grid_points] return ir_grid_points, ir_grid_weights, grid_address
def set_grid_point(self, grid_point, grid_points2=None, weights2=None): "The grid_point is numbered using the bz scheme" self._grid_point = grid_point if self._grid_address is None: primitive_lattice = np.linalg.inv(self._primitive.get_cell()) self._grid_address, self._bz_map, self._bz_to_pp_map = get_bz_grid_address( self._mesh, primitive_lattice, with_boundary=True, is_bz_map_to_pp=True) if grid_points2 is not None: self._grid_points2 = grid_points2 self._weights2 = weights2 elif not self._is_nosym: symmetry = Symmetry(self._primitive, symprec=self._symprec) qpoint = self._grid_address[grid_point] / np.double(self._mesh) mapping, grid_points = spg.get_stabilized_reciprocal_mesh( self._mesh, symmetry.get_pointgroup_operations(), is_shift=np.zeros(3, dtype='intc'), is_time_reversal=True, qpoints=[qpoint]) grid_points2 = np.unique(mapping) # weight = np.zeros_like(grid_points2) # bz_grid_points2 = np.zeros_like(grid_points2) # for g, grid in enumerate(grid_points2): # weight[g] = len(np.where(grid == mapping)[0]) # bz_grid_points2[g] = np.where(grid == self._bz_to_pp_map)[0][0] # self._grid_points2 = bz_grid_points2 weight_temp = np.bincount(mapping) weight = weight_temp[np.nonzero(weight_temp)] self._grid_points2 = grid_points2 self._weights2 = weight else: self._grid_points2 = np.arange(np.prod(self._mesh)) self._weights2 = np.ones_like(self._grid_points2, dtype="intc")
def set_grid_point(self, grid_point, grid_points2=None, weights2 = None): "The grid_point is numbered using the bz scheme" self._grid_point = grid_point if self._grid_address is None: primitive_lattice = np.linalg.inv(self._primitive.get_cell()) self._grid_address, self._bz_map, self._bz_to_pp_map = get_bz_grid_address( self._mesh, primitive_lattice, with_boundary=True, is_bz_map_to_pp=True) if grid_points2 is not None: self._grid_points2 = grid_points2 self._weights2 = weights2 elif not self._is_nosym: symmetry = Symmetry(self._primitive, symprec=self._symprec) qpoint = self._grid_address[grid_point] / np.double(self._mesh) mapping, grid_points = spg.get_stabilized_reciprocal_mesh(self._mesh, symmetry.get_pointgroup_operations(), is_shift=np.zeros(3, dtype='intc'), is_time_reversal=True, qpoints=[qpoint]) grid_points2 = np.unique(mapping) # weight = np.zeros_like(grid_points2) # bz_grid_points2 = np.zeros_like(grid_points2) # for g, grid in enumerate(grid_points2): # weight[g] = len(np.where(grid == mapping)[0]) # bz_grid_points2[g] = np.where(grid == self._bz_to_pp_map)[0][0] # self._grid_points2 = bz_grid_points2 weight_temp = np.bincount(mapping) weight = weight_temp[np.nonzero(weight_temp)] self._grid_points2 = grid_points2 self._weights2 = weight else: self._grid_points2 = np.arange(np.prod(self._mesh)) self._weights2 = np.ones_like(self._grid_points2, dtype="intc")