def test_bandstructure(testdir, plt): atoms = bulk('Cu') path = special_paths['fcc'] atoms.calc = FreeElectrons(nvalence=1, kpts={'path': path, 'npoints': 200}) atoms.get_potential_energy() bs = atoms.calc.band_structure() coords, labelcoords, labels = bs.get_labels() print(labels) bs.write('hmm.json') bs = BandStructure.read('hmm.json') coords, labelcoords, labels = bs.get_labels() print(labels) assert ''.join(labels) == 'GXWKGLUWLKUX' bs.plot(emax=10, filename='bs.png')
def band_structure(self): self.calculate() perm = self.parameters.get('perm', self.label) if self.calc.get_spin_polarized(): alpha = np.loadtxt(os.path.join(perm, self.label + '.alpha_band')) beta = np.loadtxt(os.path.join(perm, self.label + '.beta_band')) energies = np.array([alpha[:, 1:], beta[:, 1:]]) * Hartree else: data = np.loadtxt( os.path.join(perm, self.label + '.restricted_band')) energies = data[np.newaxis, :, 1:] * Hartree eref = self.calc.get_fermi_level() if eref is None: eref = 0. return BandStructure(self.parameters.bandpath, energies, eref)
def resolve_band_structure(path, kpts, energies, efermi): """Convert input BandPath along with Siesta outputs into BS object.""" # Right now this function doesn't do much. # # Not sure how the output kpoints in the siesta.bands file are derived. # They appear to be related to the lattice parameter. # # We should verify that they are consistent with our input path, # but since their meaning is unclear, we can't quite do so. # # Also we should perhaps verify the cell. If we had the cell, we # could construct the bandpath from scratch (i.e., pure outputs). from ase.spectrum.band_structure import BandStructure ksn2e = energies skn2e = np.swapaxes(ksn2e, 0, 1) bs = BandStructure(path, skn2e, reference=efermi) return bs
def test_bandstructure_json(testdir): atoms = bulk('Au') lat = atoms.cell.get_bravais_lattice() path = lat.bandpath(npoints=100) atoms.calc = FreeElectrons() bs = calculate_band_structure(atoms, path) bs.write('bs.json') bs.path.write('path.json') bs1 = read_json('bs.json') bs2 = BandStructure.read('bs.json') path1 = read_json('path.json') assert type(bs1) == type(bs) # noqa assert type(bs2) == type(bs) # noqa assert type(path1) == type(bs.path) # noqa
def read_bandstructure(self): if not os.path.isfile(f'{self.label}_band.dat'): return # Construct the higher-resolution bandpath from the *_band.labelinfo.dat file with open(f'{self.label}_band.labelinfo.dat') as fd: flines = fd.readlines() kpts = [] self.atoms.cell.pbc = True for start, end in zip(flines[:-1], flines[1:]): start_label, i_start = start.split()[:2] end_label, i_end = end.split()[:2] kpts += self.atoms.cell.bandpath(start_label + end_label, int(i_end) - int(i_start) + 1).kpts[:-1].tolist() kpts.append([float(x) for x in flines[-1].split()[-3:]]) path = self.parameters.kpoint_path.path special_points = self.parameters.kpoint_path.special_points kpath = BandPath(self.atoms.cell, kpts, path=path, special_points=special_points) # Read in the eigenvalues from the *_band.dat file with open(f'{self.label}_band.dat') as fd: flines = fd.readlines() eigs = [[]] for line in flines[:-1]: splitline = line.strip().split() if len(splitline) == 0: eigs.append([]) else: eigs[-1].append(line.strip().split()[-1]) eigs = np.array(eigs, dtype=float).T # Construct the bandstructure bs = BandStructure(kpath, eigs[np.newaxis, :, :]) self.results['band structure'] = bs
def create_ase_object(objtype, dct): # We just try each object type one after another and instantiate # them manually, depending on which kind it is. # We can formalize this later if it ever becomes necessary. if objtype == 'cell': from ase.cell import Cell dct.pop('pbc', None) # compatibility; we once had pbc obj = Cell(**dct) elif objtype == 'bandstructure': from ase.spectrum.band_structure import BandStructure obj = BandStructure(**dct) elif objtype == 'bandpath': from ase.dft.kpoints import BandPath obj = BandPath(path=dct.pop('labelseq'), **dct) elif objtype == 'atoms': from ase import Atoms obj = Atoms.fromdict(dct) else: raise ValueError('Do not know how to decode object type {} ' 'into an actual object'.format(objtype)) assert obj.ase_objtype == objtype return obj
def test_bandstructure_json(): from ase.build import bulk from ase.spectrum.band_structure import calculate_band_structure, BandStructure from ase.io.jsonio import read_json from ase.calculators.test import FreeElectrons atoms = bulk('Au') lat = atoms.cell.get_bravais_lattice() path = lat.bandpath(npoints=100) atoms.calc = FreeElectrons() bs = calculate_band_structure(atoms, path) bs.write('bs.json') bs.path.write('path.json') bs1 = read_json('bs.json') bs2 = BandStructure.read('bs.json') path1 = read_json('path.json') assert type(bs1) == type(bs) # noqa assert type(bs2) == type(bs) # noqa assert type(path1) == type(bs.path) # noqa
28.6214, 29.1794, 29.1794, 29.6229, 30.5584, 32.8451 ], [ -3.0876, -0.8863, 3.0037, 3.0037, 6.2623, 6.7765, 14.7728, 14.7728, 17.1201, 17.4077, 17.8504, 17.8504, 19.3349, 19.8627, 22.8644, 23.6249, 23.6249, 24.7429, 27.5978, 27.9651, 27.9651, 29.0422, 30.4427, 32.3347 ], [ -2.5785, -1.4744, 2.9437, 2.9437, 6.3021, 6.5565, 15.41, 15.41, 17.2036, 17.2036, 17.7555, 18.0538, 19.0775, 19.1146, 23.7456, 24.5645, 24.5645, 24.9649, 26.8166, 26.8167, 26.9285, 27.9975, 30.8961, 31.8679 ], [ -2.0397, -2.0397, 2.9235, 2.9235, 6.399, 6.3991, 15.775, 15.775, 16.8298, 16.8298, 18.4119, 18.4119, 18.6257, 18.6257, 24.5738, 24.5739, 25.3583, 25.3583, 25.9521, 25.9521, 27.1466, 27.1466, 31.3822, 31.3825 ]]]) # Update to new band structure stuff lattice = atoms.cell.get_bravais_lattice() bandpath = lattice.bandpath('WGX', npoints=30) maxerr = np.abs(bandpath.kpts - kpts).max() assert maxerr < 1e-5 bs = BandStructure(bandpath, energies=energies, reference=ref) bs.plot(emin=-13, filename='vasp_si_bandstructure.png')