Example 3 — Graphene: band structure, phonon bands, DOS
Electronic band structure, phonon bands and electronic DOS of graphene.
Prerequisites: a deMonNano installation + global.json (see the
DeMonNanoPy Quickstart page).
Run with:
python3 example_bs.py
The phonon part is the most expensive: 5x5 supercell finite displacements.
The code below is the full script, split by part. Runnable version: demonnano/examples/example_bs.py.
Setup
Electronic band structure, phonon bands and electronic DOS of graphene: the shared parameters and the graphene geometry. The phonon part is the most expensive: finite displacements on a 5x5 supercell. parameters activates SCC-DFTB with the London dispersion correction (DISP=2) and Fermi smearing (FERMI=50), with a 20x20x1 k-point grid in a PBC cell whose long third vector (100 Angstrom) is the vacuum direction; the graphene sheet is two carbon atoms with periodic boundary conditions. PH_SUPERCELL / PH_KPTS hold the phonon supercell (5, 5, 1) and the reduced k-point grid (20 / 5 = 4), and _save() tightens and saves a figure at 150 dpi.
"""Electronic band structure, phonon bands and electronic DOS of graphene.
Run with:
python3 example_bs.py
The phonon part is the most expensive: finite displacements on a 5x5
supercell.
Requires a deMonNano installation and a global.json file (see the
DeMonNanoPy README).
"""
import copy
import glob
import os
import matplotlib.pyplot as plt
import numpy as np
from ase.atoms import Atoms
import deMonPy
from deMonPy.ase_calculator import DeMonNano
deMonPy.configure_from_file("global.json")
parameters = {
"DEMON_EXECUTABLE": deMonPy.DEMON_EXECUTABLE,
"BASIS": {"PTYPE": "BIO", "SKFILE": deMonPy.DEMON_BASIS},
"DEMON_PARAMETERS": {
"ACTIVE": {
"DFTB": {"SCC": True, "DISP": 2, "FERMI": 50},
"PBC": {
"TYPE": "GENERAL",
"LATTICE": np.array(
[[2.46, 0.0, 0.0], [-1.230000, 2.130422, 0], [0.0, 0.0, 100.0]]
),
"KPTS": [20, 20, 1],
},
},
},
}
# Graphene (model system)
graphene = Atoms(
["C"] * 2,
positions=[
[0.000000, 0.000000, 0.000000],
[1.230000, 0.710000, 0.000000],
],
cell=[
[2.460000, 0.000000, 0.000000],
[-1.230000, 2.130422, 0.000000],
[0.0, 0.0, 100.0],
],
pbc=True,
)
# Phonons: supercell (5, 5, 1) and k-points reduced accordingly (20 / 5 = 4)
PH_SUPERCELL = (5, 5, 1)
PH_KPTS = (4, 4, 1)
def _save(fig, filename):
fig.tight_layout()
if filename:
fig.savefig(filename, dpi=150)
print(f"Figure : {filename}")
Band structure
Electronic band structure along G-M-K-G. deMonNano only computes a uniform N x N x 1 grid, so with N a multiple of 6 the path G-M-K-G goes exactly through grid points: their eigenvalues are used directly (no interpolation, no non-SCF calculation). A single self-consistent run is performed on the N x N x 1 grid (here N=12); the eigenvalues of the grid points along the path are taken from the results, and the band structure is plotted relative to the Fermi level and saved as graphene-bs.png.
def exemple_run_bs():
"""Electronic band structure along G-M-K-G.
deMonNano only computes a uniform N x N x 1 grid. With N a multiple of 6,
the path G-M-K-G goes exactly through grid points: their eigenvalues are
used directly (no interpolation, no non-SCF calculation).
"""
from ase.dft.kpoints import BandPath
from ase.spectrum.band_structure import BandStructure
print("=" * 40)
print(" Electronic band structure : graphene")
N = 12 # N must be a multiple of 6 (the DeMonNanoPy original uses 60)
atoms = graphene.copy()
atoms.calc = DeMonNano(
directory=".run/example-bs", kpts=(N, N, 1), **copy.deepcopy(parameters)
)
atoms.get_potential_energy()
calc = atoms.calc
kpts = calc.get_ibz_k_points()
eigenvalues = calc.results["eigenvalues"] # (nspins, nkpts, nbands), eV
# Path in fractional coordinates: G (0,0) -> M (1/2,0) -> K (1/3,1/3) -> G
n = N // 6
path_kpts = np.array(
[[i / N, 0.0, 0.0] for i in range(3 * n + 1)] # G -> M
+ [[0.5 - j / N, 2 * j / N, 0.0] for j in range(1, n + 1)] # M -> K
+ [[t / N, t / N, 0.0] for t in range(2 * n - 1, -1, -1)] # K -> G
)
index = [np.where(np.abs(kpts - k).max(axis=1) < 1e-4)[0][0] for k in path_kpts]
path = BandPath(
cell=atoms.cell,
kpts=path_kpts,
special_points=atoms.cell.bandpath().special_points,
path="GMKG",
)
bs = BandStructure(path, eigenvalues[:, index, :], reference=calc.get_fermi_level())
bs = bs.subtract_reference() # energies relative to the Fermi level
fig, ax = plt.subplots(figsize=(6.5, 4.5))
bs.plot(ax=ax, emin=-20.0, emax=10.0)
ax.set_ylabel(r"$E - E_F$ (eV)")
_save(fig, "./graphene-bs.png")
Graphene electronic band structure, G-M-K-G path (DeMonNanoPy original example output).
DOS
Electronic density of states with ase.dft.dos.DOS. A second single point is run on a 21x21x1 k-point grid; the DOS helper builds the density of states with a broadening of width=0.5, and the plot, with the energies relative to the Fermi level, is saved as graphene-dos.png.
def example_dos():
"""Electronic density of states with ase.dft.dos.DOS."""
from ase.dft.dos import DOS
print("=" * 40)
print(" Electronic DOS : graphene")
atoms = graphene.copy()
atoms.calc = DeMonNano(
directory=".run/example-dos", kpts=(21, 21, 1), **copy.deepcopy(parameters)
)
atoms.get_potential_energy()
dos = DOS(atoms.calc, width=0.5)
energies = dos.get_energies() # relative to the Fermi level
weights = dos.get_dos()
fig, ax = plt.subplots(figsize=(6.5, 4.5))
ax.plot(energies, weights, color="black")
ax.set_xlim(min(energies), 13.0)
ax.axvline(0.0, color="grey", ls="--")
ax.set_xlabel(r"$E - E_F$ (eV)")
ax.set_ylabel("DOS (states/eV)")
_save(fig, "./graphene-dos.png")
Graphene electronic density of states (DeMonNanoPy original example output).
Phonon bands
Run (or reload from cache) the finite-displacement phonon calculation, then plot the phonon band structure along G-M-K-G. The finite displacements (delta=0.05) are applied on the 5x5x1 supercell with the reduced 4x4x1 k-point grid, and the results are cached in .run/phonon-relaxed so an interrupted run can be resumed; the phonon band structure is plotted over 0-0.25 eV and saved as graphene-phonon-bs.png.
def _phonons():
"""Run (or reload from cache) the finite-displacement phonon calculation."""
from ase.phonons import Phonons
atoms = graphene.copy()
calc = DeMonNano(directory=".run/example-phonon", kpts=PH_KPTS, **copy.deepcopy(parameters))
# An interrupted run leaves empty cache files that ASE treats as "in
# progress": they must be deleted, otherwise the displacement is skipped.
for filename in glob.glob(".run/phonon-relaxed/cache.*.json"):
if os.path.getsize(filename) == 0:
os.remove(filename)
ph = Phonons(atoms, calc, supercell=PH_SUPERCELL, delta=0.05, name=".run/phonon-relaxed")
ph.run()
ph.read(acoustic=True)
return atoms, ph
def example_phonon_bs():
"""Phonon band structure along G-M-K-G."""
print("=" * 40)
print(" Phonon band structure : graphene")
atoms, ph = _phonons()
path = atoms.cell.bandpath("GMKG", npoints=100)
bs = ph.get_band_structure(path)
fig, ax = plt.subplots(figsize=(6.5, 4.5))
bs.plot(ax=ax, emin=0.0, emax=0.25)
ax.set_ylabel("Energy (eV)")
_save(fig, "./graphene-phonon-bs.png")
Graphene phonon band structure, G-M-K-G path (DeMonNanoPy original example output).
Main
Run the three calculations: band structure, phonon bands, then DOS. The figures produced by _save() — graphene-bs.png, graphene-phonon-bs.png and graphene-dos.png — are written in the current directory.
if __name__ == "__main__":
exemple_run_bs()
example_phonon_bs()
example_dos()
Summary
The script computes three properties of graphene with the ASE calculator: the electronic band structure along the G-M-K-G path (eigenvalues of the 12x12x1 grid taken directly), the phonon band structure from finite displacements on a 5x5x1 supercell — the most expensive part — and the electronic density of states. The results are saved as the three figures graphene-bs.png, graphene-phonon-bs.png and graphene-dos.png.