Applications
Comparison with Kohn-Sham DFT by OpenMX
Use the bundled CustomOpenMX class to run Kohn-Sham DFT with the same pseudopotentials and basis as AOF-DFT and compare the results.
Advance/OF-DFT includes CustomOpenMX, a class that runs Kohn-Sham DFT calculations with OpenMX from ASE. Parameters of AOFDFTCalculator (pseudopotentials, pseudo-atomic orbitals, basis sets, XC functional, ...) passed as aofdft_params are converted automatically to the corresponding OpenMX keywords. It is useful for checking the accuracy of AOF-DFT on your own systems.
To run this script, OpenMX must be installed separately and the openmx command must be in PATH. OpenMX is not included in this product.
"""
Advance/OF-DFT example: compare AOF-DFT with Kohn-Sham DFT by OpenMX.
`CustomOpenMX` runs OpenMX with the same pseudopotentials, pseudo-atomic orbitals
and basis sets as AOFDFTCalculator. OpenMX must be installed separately and the
`openmx` command must be found in PATH.
Copyright (C) 2026 AdvanceSoft Corporation, All rights reserved.
"""
import numpy as np
from ase.build import bulk
from aofdft.calculator import AOFDFTCalculator, CustomOpenMX
VPS_DIR = "path/to/DFT_DATA19_AS/VPS" # edit these two paths for your environment
PAO_DIR = "path/to/DFT_DATA19_AS/PAO"
# parameters shared by both calculators
aofdft_params = {
"console" : False,
"kin_type" : "AS26",
"kin_model": "Crystal26",
"vps_dir" : VPS_DIR,
"pao_dir" : PAO_DIR,
}
# 1) AOF-DFT: one process with num_threads threads (cubic cell of Si, 8 atoms)
aof = bulk("Si", crystalstructure="diamond", a=5.43, cubic=True)
aof.calc = AOFDFTCalculator(logging_file="si_aofdft.log", num_threads=4, **aofdft_params)
e_aof = aof.get_potential_energy()
rho_aof = aof.calc.rho.detach().cpu().numpy()
# 2) KS-DFT by OpenMX, on the same FFT grid: num_process MPI processes
ks = bulk("Si", crystalstructure="diamond", a=5.43, cubic=True)
ks.calc = CustomOpenMX(
aofdft_params = aofdft_params, # converted to the OpenMX keywords
label = "omx_si", # working directory
command = "mpirun -np ${NP} openmx", # ${NP} is replaced with num_process
num_process = 4, # number of MPI processes
kpts = 3.5, # k-point density
)
e_ks = ks.get_potential_energy()
rho_ks = ks.calc.rho # numpy.ndarray of shape (n_rho, na, nb, nc)
print(f"Fermi energy : AOF-DFT {aof.calc.e_fermi:8.4f} eV, KS-DFT {ks.calc.e_fermi:8.4f} eV")
print(f"SCF steps of KS-DFT: {ks.calc.scf_steps}")
# 3) normalized mean absolute error of the electron density
if rho_ks.shape == rho_aof.shape:
nmae = np.abs(rho_aof[0] - rho_ks[0]).sum() / np.abs(rho_ks[0]).sum()
print(f"Normalized MAE of the electron density: {nmae * 100.0:.2f} %")
else:
print(f"Grids are different: AOF-DFT {rho_aof.shape}, KS-DFT {rho_ks.shape}")
Example output
Results with v1.0.0 (Crystal26) and OpenMX 3.9.
Fermi energy : AOF-DFT -4.1663 eV, KS-DFT -3.0448 eV
SCF steps of KS-DFT: 12
Normalized MAE of the electron density: 7.60 %
The FFT grid is 56×56×56 for both AOF-DFT and OpenMX, so the electron densities are compared directly. The input and output files of OpenMX are created in the folder omx_si.
Parallel execution
AOF-DFT and OpenMX are parallelized in different ways and are set up differently.
| Item | AOF-DFT (AOFDFTCalculator) | OpenMX (CustomOpenMX) |
|---|---|---|
| Parallelization | threads within one process | MPI processes |
| Setting | num_threads (number of threads) | num_process (number of processes) |
| Cores in use | number of threads | number of processes × threads per process |
| In the script above | 4 threads (4 cores) | 4 processes × 1 thread (4 cores) |
OpenMX is started as a separate program with the command line given by command; ${NP} in it is replaced with num_process.
The number of threads actually used also depends on the environment variables OMP_NUM_THREADS and MKL_NUM_THREADS, which are often set in job scripts.
- The number of threads per process of OpenMX is decided by
MKL_NUM_THREADS(when OpenMX is linked with the threaded MKL). It is 1 if the variable is not set.num_threadsandOMP_NUM_THREADShave no effect on OpenMX. - The number of threads of AOF-DFT is taken in the order of priority
num_threads→MKL_NUM_THREADS→OMP_NUM_THREADS→ the default of PyTorch (usually all physical cores of the machine).
Keep the following points in mind when choosing the settings.
- With
num_threadsgiven, the number of threads of AOF-DFT does not depend on the environment variables. Setting it is the safe choice on a shared machine. - Keep the number of processes times the number of threads within the number of available cores.
To use the OpenMP threads of OpenMX as well, set command="openmx" and give the numbers of processes and threads with the mpi argument of ASE (for example mpi={"processes": 2, "threads": 2}). num_process is not used then, and the standard output of OpenMX is printed to the screen.
For threads and GPUs in AOF-DFT, see GPUs and OpenMP threads.
Notes
- The cell is the cubic cell of Si (8 atoms). With v1.0.0, the results of AOF-DFT change when the cell has a short period, as the primitive cell (2 atoms) does. The results of KS-DFT do not depend on the choice of the cell.
- The OpenMX keywords converted from
aofdft_paramscan be checked in the input fileomx_si/omx_si.dat. In this example the basis isSi7.0-s1p1d1, the pseudopotential isSi_PBE19, the cutoff energy is 300 Ry (150 Hartree) and the electronic temperature is 6315.5 K (0.02 Hartree). - If OpenMX could not be run (for example because
openmxormpirunis not found), the error isPropertyNotImplementedError: energy not present in this calculation. Look for the cause in the standard error output and in the.logfile of the working folder. kptsis the k-point density. Other keywords accepted by the ASEOpenMXcalculator can be given as well.labelis the name of the working folder where the OpenMX input and output files are created.- The
rhoproperty ofCustomOpenMXreturns a NumPy array with the same shape(n_rho, na, nb, nc)asAOFDFTCalculator.rho. When the grids coincide, the densities can be compared directly. - The script evaluates the normalized mean absolute error (normalized MAE) of the electron density, the metric used in the accuracy benchmarks.
- Properties such as
e_fermi,total_energyandscf_stepsare also available.