Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
unique_species.append(species)
zs.extend([len(unique_species)] * len(tuple(g)))
for site in structure:
if hasattr(site, 'magmom'):
magmoms.append(site.magmom)
elif site.is_ordered and hasattr(site.specie, 'spin'):
magmoms.append(site.specie.spin)
else:
magmoms.append(0)
# For now, we are setting magmom to zero. (Taken from INCAR class)
cell = latt, positions, zs, magmoms
# TODO: what about this shift?
mapping, grid = spglib.get_ir_reciprocal_mesh(mesh, cell, is_shift=[0, 0, 0])
# exit()
# get the kpoints for the grid
if isym == -1:
kpts = []
weights = []
all_labels = []
for gp in grid:
kpts.append(gp.astype(float) / mesh)
weights.append(float(1))
all_labels.append("")
elif isym == 0:
# time reversal symmetry: k and -k are equivalent
kpts = []
weights = []
all_labels = []
def get_ir_reciprocal_mesh(self, mesh, is_shift=np.zeros(3, dtype='intc'), is_time_reversal=True, symprec=1e-5):
"""
Args:
mesh:
is_shift:
is_time_reversal:
symprec:
Returns:
"""
mapping, mesh_points = spglib.get_ir_reciprocal_mesh(mesh=mesh, cell=self, is_shift=is_shift,
is_time_reversal=is_time_reversal, symprec=symprec)
return mapping, mesh_points
Args:
mesh:
is_shift:
Return: named tuple with the following attributes:
ibz:
nibz
weights:
bz:
nbz
grid:
"""
import spglib as spg
mesh = np.array(mesh)
mapping, grid = spg.get_ir_reciprocal_mesh(mesh, self.cell,
is_shift=is_shift, is_time_reversal=self.has_timrev, symprec=self.symprec)
uniq, weights = np.unique(mapping, return_counts=True)
weights = np.asarray(weights, dtype=np.float) / len(grid)
nkibz = len(uniq)
ibz = grid[uniq] / mesh
if self.verbose:
print("Number of ir-kpoints: %d" % nkibz)
kshift = 0.0 if is_shift is None else 0.5 * np.asarray(is_shift)
bz = (grid + kshift) / mesh
# All k-points and mapping to ir-grid points
bz2ibz = np.empty(len(bz), dtype=np.int)
for i, (ir_gp_id, gp) in enumerate(zip(mapping, grid)):
inds = np.where(uniq == ir_gp_id)
nonzero = [i for i in kpts[:, i] if abs(i) > 1e-5]
if len(nonzero) != len(kpts):
# gamma centered
if not nonzero:
mesh.append(1)
else:
m = np.abs(np.round(1/np.array(nonzero)))
mesh.append(int(max(m)))
shift.append(0)
else:
# Monk
m = np.abs(np.round(0.5/np.array(nonzero)))
mesh.append(int(max(m)))
shift.append(1)
mapping, grid = spglib.get_ir_reciprocal_mesh(
np.array(mesh), self._cell, is_shift=shift, symprec=self._symprec)
mapping = list(mapping)
grid = (np.array(grid) + np.array(shift) * (0.5, 0.5, 0.5)) / mesh
weights = []
mapped = defaultdict(int)
for k in kpoints:
for i, g in enumerate(grid):
if np.allclose(pbc_diff(k, g), (0, 0, 0), atol=atol):
mapped[tuple(g)] += 1
weights.append(mapping.count(mapping[i]))
break
if (len(mapped) != len(set(mapping))) or (
not all([v == 1 for v in mapped.values()])):
raise ValueError("Unable to find 1:1 corresponding between input "
"kpoints and irreducible grid!")
return [w/sum(weights) for w in weights]
num_ir_kpt = len(np.unique(mapping))
print("[get_ir_reciprocal_mesh]")
print(" Number of irreducible k-points of primitive silicon with")
print(" 11x11x11 Monkhorst-Pack mesh is %d (56)." % num_ir_kpt)
print('')
mapping, grid = spglib.get_ir_reciprocal_mesh([8, 8, 8],
rutile,
is_shift=[1, 1, 1])
num_ir_kpt = len(np.unique(mapping))
print("[get_ir_reciprocal_mesh]")
print(" Number of irreducible k-points of Rutile with")
print(" 8x8x8 Monkhorst-Pack mesh is %d (40)." % num_ir_kpt)
print('')
mapping, grid = spglib.get_ir_reciprocal_mesh([9, 9, 8],
MgB2,
is_shift=[0, 0, 1])
num_ir_kpt = len(np.unique(mapping))
print("[get_ir_reciprocal_mesh]")
print(" Number of irreducible k-points of MgB2 with")
print(" 9x9x8 Monkhorst-Pack mesh is %s (48)." % num_ir_kpt)
print('')
show_lattice(niggli_lattice)
print(" Reduced lattice")
show_lattice(reduced_lattice)
print('')
mapping, grid = spglib.get_ir_reciprocal_mesh([11, 11, 11],
silicon_prim,
is_shift=[0, 0, 0])
num_ir_kpt = len(np.unique(mapping))
print("[get_ir_reciprocal_mesh]")
print(" Number of irreducible k-points of primitive silicon with")
print(" 11x11x11 Monkhorst-Pack mesh is %d (56)." % num_ir_kpt)
print('')
mapping, grid = spglib.get_ir_reciprocal_mesh([8, 8, 8],
rutile,
is_shift=[1, 1, 1])
num_ir_kpt = len(np.unique(mapping))
print("[get_ir_reciprocal_mesh]")
print(" Number of irreducible k-points of Rutile with")
print(" 8x8x8 Monkhorst-Pack mesh is %d (40)." % num_ir_kpt)
print('')
mapping, grid = spglib.get_ir_reciprocal_mesh([9, 9, 8],
MgB2,
is_shift=[0, 0, 1])
num_ir_kpt = len(np.unique(mapping))
print("[get_ir_reciprocal_mesh]")
print(" Number of irreducible k-points of MgB2 with")
print(" 9x9x8 Monkhorst-Pack mesh is %s (48)." % num_ir_kpt)
print('')
def __init__(self, structure, mesh, is_shift, has_timrev):
"""
Args:
structure
mesh
is_shift
has_timrev
"""
import spglib as spg
self.mesh = np.array(mesh)
self.is_shift = is_shift
self.has_timrev = has_timrev
cell = (structure.lattice.matrix, structure.frac_coords, structure.atomic_numbers)
mapping, self.grid = spg.get_ir_reciprocal_mesh(self.mesh, cell,
is_shift=self.is_shift, is_time_reversal=self.has_timrev, symprec=_SPGLIB_SYMPREC)
uniq, self.weights = np.unique(mapping, return_counts=True)
self.weights = np.asarray(self.weights, dtype=np.float) / len(self.grid)
self.nibz = len(uniq)
self.kshift = [0., 0., 0.] if is_shift is None else 0.5 * np.asarray(is_shift)
self.ibz = (self.grid[uniq] + self.kshift) / self.mesh
self.bz = (self.grid + self.kshift) / self.mesh
self.nbz = len(self.bz)
# All k-points and mapping to ir-grid points.
# FIXME This is slow.
self.bz2ibz = np.empty(len(self.bz), dtype=np.int)
for ik_bz, ir_gp_id in enumerate(mapping):
inds = np.where(uniq == ir_gp_id)
assert len(inds) == 1