Defects, surfaces and diffusion

Vacancy formation energy

Remove one atom from an fcc Al supercell, relax the surrounding atoms and compute the vacancy formation energy, checking its convergence with the supercell size.

Category
Defects, surfaces and diffusion
APIs used
ase.build.bulkAtoms.repeatase.optimize.BFGSscf_must_conv
Script
vacancy_formation.py

The formation energy of point defects is a basic quantity in the study of diffusion, radiation damage and phase stability of alloys. The vacancy formation energy Ef is obtained from the total energies of the perfect crystal (N atoms) and of the supercell with one atom removed (N−1 atoms).

Ef=Evac(N−1)−N−1NEperfect(N)

The removed atom is assumed to go to a reservoir with the energy per atom of the bulk (the chemical potential). The supercell is enlarged to check that Ef converges and the interaction between vacancies is small. Since the cost of Advance/OF-DFT, which uses a kinetic energy functional, grows almost linearly with the number of atoms, large supercells are easy to handle.

vacancy_formation.pyDownload
"""
Advance/OF-DFT example: vacancy formation energy of fcc Al.

    E_f = E(N-1 atoms, with vacancy) - (N-1)/N * E(N atoms, perfect)

The supercell size is increased to check the convergence of E_f,
and the atoms around the vacancy are relaxed with an ASE optimizer.

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

import time

from ase.build import bulk
from ase.optimize import BFGS

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"

A_LAT = 4.05  # lattice constant of fcc Al (Angstrom)


def make_calc(label):
    return AOFDFTCalculator(
        console       = False,
        logging_file  = f"{label}.log",
        kin_type      = "AS26",
        kin_model     = "Crystal26",
        vps_dir       = VPS_DIR,
        pao_dir       = PAO_DIR,
        scf_must_conv = True,  # stop if the SCF does not converge
    )


print(" size  N  | E_f unrelaxed | E_f relaxed |  time")
for n in (3, 4, 5):
    t0 = time.perf_counter()

    # perfect supercell: n x n x n primitive cells (n^3 atoms)
    perfect = bulk("Al", "fcc", a=A_LAT).repeat((n, n, n))
    perfect.calc = make_calc(f"al_perfect_{n}")
    e_perfect = perfect.get_potential_energy()
    n_atoms = len(perfect)

    # remove one atom -> vacancy
    vacancy = perfect.copy()
    del vacancy[0]
    vacancy.calc = make_calc(f"al_vacancy_{n}")
    e_unrelaxed = vacancy.get_potential_energy()

    # relax the atomic positions (the cell is kept fixed)
    BFGS(vacancy, logfile=f"al_vacancy_{n}_opt.log").run(fmax=0.05)
    e_relaxed = vacancy.get_potential_energy()

    ef_unrelaxed = e_unrelaxed - (n_atoms - 1) / n_atoms * e_perfect
    ef_relaxed   = e_relaxed   - (n_atoms - 1) / n_atoms * e_perfect
    print(f" {n}x{n}x{n} {n_atoms:4d} | {ef_unrelaxed:10.3f} eV | {ef_relaxed:8.3f} eV "
          f"| {time.perf_counter() - t0:5.0f} s", flush=True)

Example output

Results with v1.0.0 (Crystal26).

text
 size  N  | E_f unrelaxed | E_f relaxed |  time
 3x3x3   27 |      0.848 eV |    0.827 eV |   141 s
 4x4x4   64 |      0.851 eV |    0.823 eV |   296 s
 5x5x5  125 |      0.852 eV |    0.823 eV |   980 s

The relaxed Ef is the same for the 64-atom and 125-atom supercells (and within 0.004 eV for 27 atoms), so it is converged with respect to the supercell size. The relaxation of the atoms around the vacancy lowers Ef by 0.02 - 0.03 eV.

Notes

  • bulk("Al", "fcc", a=A_LAT) is the one-atom primitive cell, and repeat((n, n, n)) makes a supercell of n3 atoms. Use bulk(..., cubic=True) for the cubic unit cell with 4 atoms.
  • The vacancy is made on a copy (perfect.copy()), so the original perfect keeps its calculator and results.
  • The cell is kept fixed and only the atomic positions are relaxed. To include the volume relaxation, use the cell filter shown in Stress tensor and cell optimization.
  • With scf_must_conv=True the script stops when an SCF calculation does not converge, so an unconverged energy cannot enter Ef.
  • Ef is a small difference between large total energies. Use the same lattice constant and the same settings (cutoff energy etc.) for the perfect and defective supercells.