Atomic charges and spin

Atom-wise eigenvalues and occupations

Write and read the eigenvalues, occupations and orbital coefficients of the eigenvalue problems that AOF-DFT solves for each atom.

Category
Atomic charges and spin
APIs used
wavefunc_filee_fermi
Script
atomic_levels.py

Whereas Kohn-Sham DFT solves one eigenvalue problem for the whole system, AOF-DFT solves a small eigenvalue problem for each atom and determines the occupations with a Fermi energy common to all atoms (see Technology). With wavefunc_file, the eigenvalues, occupations and expansion coefficients of the pseudo-atomic orbitals are written to a file.

atomic_levels.pyDownload
"""
Advance/OF-DFT example: eigenvalues and occupations of the atom-wise eigenvalue problems.

AOF-DFT solves a small eigenvalue problem for each atom. `wavefunc_file` writes the
eigenvalues (Hartree), occupations and coefficients of the pseudo-atomic orbitals.

Copyright (C) 2026 AdvanceSoft Corporation, All rights reserved.
"""

import re

from ase.build import bulk
from ase.units import Hartree

from aofdft.calculator import AOFDFTCalculator

VPS_DIR = "path/to/DFT_DATA19_AS/VPS"  # edit these two paths for your environment
PAO_DIR = "path/to/DFT_DATA19_AS/PAO"

WF_FILE = "gaas_wavefunc.txt"


def read_levels(filename):
    """
    Read eigenvalues and occupations from the wave-function file.

    Returns:
        blocks (list[dict]): for each atom and spin, {"index", "element", "spin", "energies", "occupations"}
    """
    head   = re.compile(r"^Atom\s+index=\s*(\d+)\s+element=\s*(\w+)\s+spin=\s*(\d+)")
    blocks = []
    with open(filename, encoding="utf-8") as f:
        for line in f:
            if m := head.match(line):
                blocks.append({"index": int(m.group(1)), "element": m.group(2), "spin": int(m.group(3))})
            elif line.strip().startswith("Energy"):
                blocks[-1]["energies"] = [float(x) for x in line.split()[1:]]
            elif line.strip().startswith("Occup."):
                blocks[-1]["occupations"] = [float(x) for x in line.split()[1:]]
    return blocks


atoms = bulk("GaAs", crystalstructure="zincblende", a=5.65, cubic=True)  # 8 atoms

atoms.calc = AOFDFTCalculator(
    console       = False,
    logging_file  = "gaas.log",
    wavefunc_file = WF_FILE,  # eigenvalues, occupations and coefficients for each atom
    kin_type      = "AS26",
    kin_model     = "Crystal26",
    vps_dir       = VPS_DIR,
    pao_dir       = PAO_DIR,
)
atoms.get_potential_energy()

e_fermi = atoms.calc.e_fermi  # eV
print(f"Fermi energy: {e_fermi:.4f} eV\n")

# all atoms of an element are equivalent in this crystal: print the first one of each element
shown = set()
for block in read_levels(WF_FILE):
    if block["element"] in shown:
        continue
    shown.add(block["element"])

    print(f"atom {block['index']} ({block['element']}), spin {block['spin']}")
    print(f"  {'level':>5s} {'E - E_F (eV)':>13s} {'occupation':>11s}")
    for n, (energy, occ) in enumerate(zip(block["energies"], block["occupations"]), start=1):
        print(f"  {n:5d} {energy * Hartree - e_fermi:13.4f} {occ:11.5f}")

Example of the output file

text
[ Wave-Functions of AOF-DFT ]

Atom  index=    1  element= Ga  spin= 1
  ==================================================
                     1         2         3         4
   Energy     -0.26727  -0.18950  -0.18950  -0.18950
   Occup.      1.83972   0.38048   0.38048   0.38048
  --------------------------------------------------
   1 s         1.00000   0.00000   0.00000  -0.00000
   2 px       -0.00000   0.22209   0.95651  -0.18913
   2 py       -0.00000   0.66889  -0.29060  -0.68420
   2 pz        0.00000  -0.70941   0.02544  -0.70434
  ==================================================

Atom  index=    2  element= As  spin= 1
  ==================================================
                     1         2         3         4
   Energy     -0.36295  -0.21874  -0.21874  -0.21874
   Occup.      1.99854   1.00676   1.00676   1.00676
  --------------------------------------------------
   1 s         1.00000   0.00000   0.00000  -0.00000
   2 px       -0.00000   0.02940   0.99946  -0.01444
   2 py        0.00000  -0.70787   0.01061  -0.70627
   2 pz        0.00000  -0.70573   0.03099   0.70780
  ==================================================

This is the part for the first two atoms of the file written for a GaAs crystal (cubic cell, 8 atoms). The script reads the file and prints the levels of the first atom of each element relative to the Fermi energy:

text
Fermi energy: -5.9447 eV

atom 1 (Ga), spin 1
  level  E - E_F (eV)  occupation
      1       -1.3280     1.83972
      2        0.7882     0.38048
      3        0.7882     0.38048
      4        0.7882     0.38048
atom 2 (As), spin 1
  level  E - E_F (eV)  occupation
      1       -3.9316     1.99854
      2       -0.0075     1.00676
      3       -0.0075     1.00676
      4       -0.0075     1.00676

For both Ga and As, the level derived from the s orbital lies well below the Fermi energy, with an occupation close to 2 (1.84 for Ga, 2.00 for As). The triply degenerate levels derived from the p orbitals are partially occupied.

Reading the file

  • One block is written for each atom (and for each spin in spin-polarized calculations).
  • In this crystal all atoms of an element are equivalent and have the same levels and occupations, so the script prints one atom per element.
  • The cell is the cubic cell of GaAs (8 atoms). With v1.0.0 the results change when the cell has a short period, as the primitive cell (2 atoms) does.
  • The Energy row lists the eigenvalues in Hartree and the Occup. row the occupation of each level.
  • The matrix below holds the coefficients of each eigenstate expanded in the pseudo-atomic orbitals.
  • These are levels localized on the atoms. They do not correspond to the band structure or density of states of Kohn-Sham DFT.
  • The Fermi energy is available in eV from calc.e_fermi. The script converts the eigenvalues to eV and prints them relative to the Fermi energy.