def test_monoclinic(): """Test band structure from different variations of hexagonal cells.""" mc1 = Cell([[1, 0, 0], [0, 1, 0], [0, 0.2, 1]]) par = mc1.cellpar() mc2 = Cell.new(par) mc3 = Cell([[1, 0, 0], [0, 1, 0], [-0.2, 0, 1]]) mc4 = Cell([[1, 0, 0], [-0.2, 1, 0], [0, 0, 1]]) path = 'GYHCEM1AXH1' firsttime = True for cell in [mc1, mc2, mc3, mc4]: a = Atoms(cell=cell, pbc=True) a.cell *= 3 a.calc = FreeElectrons(nvalence=1, kpts={'path': path}) lat = a.cell.get_bravais_lattice() assert lat.name == 'MCL' a.get_potential_energy() bs = a.calc.band_structure() coords, labelcoords, labels = bs.get_labels() assert ''.join(labels) == path e_skn = bs.energies if firsttime: coords1 = coords labelcoords1 = labelcoords e_skn1 = e_skn firsttime = False else: for d in [coords - coords1, labelcoords - labelcoords1, e_skn - e_skn1]: print(abs(d).max()) assert abs(d).max() < 1e-13, d
def test_hex(): """Test band structure from different variations of hexagonal cells.""" firsttime = True for cell in [[[1, 0, 0], [0.5, 3**0.5 / 2, 0], [0, 0, 1]], [[1, 0, 0], [-0.5, 3**0.5 / 2, 0], [0, 0, 1]], [[0.5, -3**0.5 / 2, 0], [0.5, 3**0.5 / 2, 0], [0, 0, 1]]]: a = Atoms(cell=cell, pbc=True) a.cell *= 3 a.calc = FreeElectrons(nvalence=1, kpts={'path': 'GMKG'}) lat = a.cell.get_bravais_lattice() assert lat.name == 'HEX' print(repr(a.cell.get_bravais_lattice())) r = a.cell.reciprocal() k = get_special_points(a.cell)['K'] print(np.dot(k, r)) a.get_potential_energy() bs = a.calc.band_structure() coords, labelcoords, labels = bs.get_labels() assert ''.join(labels) == 'GMKG' e_skn = bs.energies if firsttime: coords1 = coords labelcoords1 = labelcoords e_skn1 = e_skn firsttime = False else: for d in [ coords - coords1, labelcoords - labelcoords1, e_skn - e_skn1 ]: assert abs(d).max() < 1e-13
def test_lattice_bandstructure(testdir, i, lat, figure): xid = '{:02d}.{}'.format(i, lat.variant) path = lat.bandpath(density=10) path.write('path.{}.json'.format(xid)) atoms = Atoms(cell=lat.tocell(), pbc=True) atoms.calc = FreeElectrons(nvalence=0, kpts=path.kpts) bs = calculate_band_structure(atoms, path) bs.write('bs.{}.json'.format(xid)) ax = figure.gca() bs.plot(ax=ax, emin=0, emax=20, filename='fig.{}.png'.format(xid))
def free_electron_band_structure(self, **kwargs): """Return band structure of free electrons for this bandpath. This is for mostly testing.""" from ase import Atoms from ase.calculators.test import FreeElectrons from ase.dft.band_structure import calculate_band_structure atoms = Atoms(cell=self.cell, pbc=True) atoms.calc = FreeElectrons(**kwargs) bs = calculate_band_structure(atoms, path=self) return bs
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 free_electron_band_structure( self, **kwargs) -> 'ase.spectrum.band_structure.BandStructure': """Return band structure of free electrons for this bandpath. Keyword arguments are passed to :class:`~ase.calculators.test.FreeElectrons`. This is for mostly testing and visualization.""" from ase import Atoms from ase.calculators.test import FreeElectrons from ase.spectrum.band_structure import calculate_band_structure atoms = Atoms(cell=self.cell, pbc=True) atoms.calc = FreeElectrons(**kwargs) bs = calculate_band_structure(atoms, path=self) return bs
def test(): ax = plt.gca() for i, lat in enumerate(all_variants()): if lat.ndim == 2: break xid = '{:02d}.{}'.format(i, lat.variant) path = lat.bandpath(density=10) path.write('path.{}.json'.format(xid)) atoms = Atoms(cell=lat.tocell(), pbc=True) atoms.calc = FreeElectrons(nvalence=0, kpts=path.kpts) bs = calculate_band_structure(atoms, path) bs.write('bs.{}.json'.format(xid)) bs.plot(ax=ax, emin=0, emax=20, filename='fig.{}.png'.format(xid)) ax.clear()
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 test_monoclinic(): """Test band structure from different variations of hexagonal cells.""" import numpy as np from ase import Atoms from ase.calculators.test import FreeElectrons from ase.geometry import (crystal_structure_from_cell, cell_to_cellpar, cellpar_to_cell) from ase.dft.kpoints import get_special_points mc1 = [[1, 0, 0], [0, 1, 0], [0, 0.2, 1]] par = cell_to_cellpar(mc1) mc2 = cellpar_to_cell(par) mc3 = [[1, 0, 0], [0, 1, 0], [-0.2, 0, 1]] mc4 = [[1, 0, 0], [-0.2, 1, 0], [0, 0, 1]] path = 'GYHCEM1AXH1' firsttime = True for cell in [mc1, mc2, mc3, mc4]: a = Atoms(cell=cell, pbc=True) a.cell *= 3 a.calc = FreeElectrons(nvalence=1, kpts={'path': path}) cs = crystal_structure_from_cell(a.cell) assert cs == 'monoclinic' r = a.cell.reciprocal() k = get_special_points(a.cell)['H'] print(np.dot(k, r)) a.get_potential_energy() bs = a.calc.band_structure() coords, labelcoords, labels = bs.get_labels() assert ''.join(labels) == path e_skn = bs.energies # bs.plot() if firsttime: coords1 = coords labelcoords1 = labelcoords e_skn1 = e_skn firsttime = False else: for d in [ coords - coords1, labelcoords - labelcoords1, e_skn - e_skn1 ]: print(abs(d).max()) assert abs(d).max() < 1e-13, d
def test_bandstructure(plt): from ase.build import bulk from ase.calculators.test import FreeElectrons from ase.dft.kpoints import special_paths from ase.dft.band_structure import BandStructure a = bulk('Cu') path = special_paths['fcc'] a.calc = FreeElectrons(nvalence=1, kpts={'path': path, 'npoints': 200}) a.get_potential_energy() bs = a.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 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
import matplotlib from ase.build import bulk from ase.calculators.test import FreeElectrons from ase.dft.kpoints import special_paths from ase.dft.band_structure import BandStructure a = bulk('Cu') path = special_paths['fcc'] a.calc = FreeElectrons(nvalence=1, kpts={'path': path, 'npoints': 200}) a.get_potential_energy() bs = a.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' matplotlib.use('Agg', warn=False) bs.plot(emax=10, filename='bs.png')
def _atoms(cell): atoms = Atoms(cell=cell, pbc=True) atoms.calc = FreeElectrons() return atoms
"""Test band structure from different variations of hexagonal cells.""" import numpy as np from ase import Atoms from ase.calculators.test import FreeElectrons from ase.dft.kpoints import get_special_points firsttime = True for cell in [[[1, 0, 0], [0.5, 3**0.5 / 2, 0], [0, 0, 1]], [[1, 0, 0], [-0.5, 3**0.5 / 2, 0], [0, 0, 1]], [[0.5, -3**0.5 / 2, 0], [0.5, 3**0.5 / 2, 0], [0, 0, 1]]]: a = Atoms(cell=cell, pbc=True) a.cell *= 3 a.calc = FreeElectrons(nvalence=1, kpts={'path': 'GMKG'}) lat = a.cell.get_bravais_lattice() assert lat.name == 'HEX' print(repr(a.cell.get_bravais_lattice())) #print(crystal_structure_from_cell(a.cell)) r = a.get_reciprocal_cell() k = get_special_points(a.cell)['K'] print(np.dot(k, r)) a.get_potential_energy() bs = a.calc.band_structure() coords, labelcoords, labels = bs.get_labels() assert ''.join(labels) == 'GMKG' e_skn = bs.energies if firsttime: coords1 = coords labelcoords1 = labelcoords e_skn1 = e_skn firsttime = False else:
from ase import Atoms from ase.calculators.test import FreeElectrons from ase.geometry import crystal_structure_from_cell, cell_to_cellpar, cellpar_to_cell from ase.dft.kpoints import get_special_points mc1 = [[1, 0, 0], [0, 1, 0], [0, 0.2, 1]] par = cell_to_cellpar(mc1) mc2 = cellpar_to_cell(par) mc3 = [[1, 0, 0], [0, 1, 0], [-0.2, 0, 1]] path = 'GYHCEM1AXH1' firsttime = True for cell in [mc1, mc2, mc3]: a = Atoms(cell=cell, pbc=True) a.cell *= 3 a.calc = FreeElectrons(nvalence=1, kpts={'path': path}) print(crystal_structure_from_cell(a.cell)) r = a.get_reciprocal_cell() k = get_special_points(a.cell)['H'] print(np.dot(k, r)) a.get_potential_energy() bs = a.calc.band_structure() coords, labelcoords, labels = bs.get_labels() assert ''.join(labels) == path e_skn = bs.energies # bs.plot() if firsttime: coords1 = coords labelcoords1 = labelcoords e_skn1 = e_skn firsttime = False
from ase.build import bulk from ase.dft.band_structure import calculate_band_structure from ase.io.jsonio import read_json from ase.calculators.test import FreeElectrons atoms = bulk('Au') lat, _ = atoms.cell.bravais() 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') path1 = read_json('path.json') print(bs1) print(path1) assert type(bs1) == type(bs) assert type(path1) == type(bs.path)