def atoms2bandstructure(atoms, parser, args): cell = atoms.get_cell() calc = atoms.calc bzkpts = calc.get_bz_k_points() ibzkpts = calc.get_ibz_k_points() efermi = calc.get_fermi_level() nibz = len(ibzkpts) nspins = 1 + int(calc.get_spin_polarized()) eps = np.array([[calc.get_eigenvalues(kpt=k, spin=s) for k in range(nibz)] for s in range(nspins)]) if not args.quiet: print('Spins, k-points, bands: {}, {}, {}'.format(*eps.shape)) if bzkpts is None: if ibzkpts is None: raise ValueError('Cannot find any k-point data') else: path_kpts = ibzkpts else: try: size, offset = get_monkhorst_pack_size_and_offset(bzkpts) except ValueError: path_kpts = ibzkpts else: if not args.quiet: print('Interpolating from Monkhorst-Pack grid (size, offset):') print(size, offset) if args.path is None: err = 'Please specify a path!' try: cs = crystal_structure_from_cell(cell) except ValueError: err += ('\nASE cannot automatically ' 'recognize this crystal structure') else: from ase.dft.kpoints import special_paths kptpath = special_paths[cs] err += ('\nIt looks like you have a {} crystal structure.' '\nMaybe you want its special path:' ' {}'.format(cs, kptpath)) parser.error(err) bz2ibz = calc.get_bz_to_ibz_map() path_kpts = bandpath(args.path, atoms.cell, args.points).kpts icell = atoms.get_reciprocal_cell() eps = monkhorst_pack_interpolate(path_kpts, eps.transpose(1, 0, 2), icell, bz2ibz, size, offset) eps = eps.transpose(1, 0, 2) special_points = get_special_points(cell) path = BandPath(atoms.cell, kpts=path_kpts, special_points=special_points) return BandStructure(path, eps, reference=efermi)
def test_interpolate(): import numpy as np from ase.dft.kpoints import monkhorst_pack_interpolate eps = [0, 1, 2] path = [[0, 0, 0], [-0.25, 0, 0]] bz2ibz = [0, 1, 1, 2] x = monkhorst_pack_interpolate(path, eps, np.eye(3), bz2ibz, [2, 2, 1], [0.25, 0.25, 0]) print(x) assert abs(x - [0, 0.5]).max() < 1e-10
def main(args, parser): atoms = read(args.calculation) cell = atoms.get_cell() calc = atoms.calc bzkpts = calc.get_bz_k_points() ibzkpts = calc.get_ibz_k_points() efermi = calc.get_fermi_level() nibz = len(ibzkpts) nspins = 1 + int(calc.get_spin_polarized()) eps = np.array([[calc.get_eigenvalues(kpt=k, spin=s) for k in range(nibz)] for s in range(nspins)]) if not args.quiet: print('Spins, k-points, bands: {}, {}, {}'.format(*eps.shape)) try: size, offset = get_monkhorst_pack_size_and_offset(bzkpts) except ValueError: path = ibzkpts else: if not args.quiet: print('Interpolating from Monkhorst-Pack grid (size, offset):') print(size, offset) if args.path is None: err = 'Please specify a path!' try: cs = crystal_structure_from_cell(cell) except ValueError: err += ('\nGPAW cannot autimatically ' 'recognize this crystal structure') else: from ase.dft.kpoints import special_paths kptpath = special_paths[cs] err += ('\nIt looks like you have a {} crystal structure.' '\nMaybe you want its special path:' ' {}'.format(cs, kptpath)) parser.error(err) bz2ibz = calc.get_bz_to_ibz_map() path = bandpath(args.path, atoms.cell, args.points)[0] icell = atoms.get_reciprocal_cell() eps = monkhorst_pack_interpolate(path, eps.transpose(1, 0, 2), icell, bz2ibz, size, offset) eps = eps.transpose(1, 0, 2) emin, emax = (float(e) for e in args.range) bs = BandStructure(atoms.cell, path, eps, reference=efermi) bs.plot(emin=emin, emax=emax)
import numpy as np from ase.dft.kpoints import monkhorst_pack_interpolate eps = [0, 1, 2] path = [[0, 0, 0], [-0.25, 0, 0]] bz2ibz = [0, 1, 1, 2] x = monkhorst_pack_interpolate(path, eps, np.eye(3), bz2ibz, [2, 2, 1], [0.25, 0.25, 0]) print(x) assert abs(x - [0, 0.5]).max() < 1e-10