Applications

Large systems and O(N) scaling

Measure the SCF time for supercells of increasing size and confirm that the cost grows linearly with the number of atoms.

Category
Applications
APIs used
kin_typenum_threadsdevice
Script
large_system.py

The cost of AOF-DFT grows linearly with the number of atoms N. This script measures the SCF time for fcc Pt supercells from 32 to 256 atoms.

large_system.pyDownload
"""
Advance/OF-DFT example: O(N) scaling of the computation time for large systems.

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

import time

import matplotlib.pyplot as plt
import numpy as np
from ase.build import bulk
from numpy.polynomial import Polynomial

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"

# 2x2x2 supercell of fcc Pt (32 atoms) as the building block
base = bulk("Pt", "fcc", a=3.9, cubic=True) * (2, 2, 2)

# 32, 64, 128 and 256 atoms. Larger cells such as (3, 3, 3) = 864 atoms need much more memory.
repeats   = [(1, 1, 1), (2, 1, 1), (2, 2, 1), (2, 2, 2)]
num_atoms = []
times     = []

for repeat in repeats:
    atoms = base * repeat

    atoms.calc = AOFDFTCalculator(
        console      = False,
        logging_file = f"{atoms.get_chemical_formula()}.log",
        kin_type     = "LKT",  # or "TFvW", "AS26"
        vps_dir      = VPS_DIR,
        pao_dir      = PAO_DIR,
    )

    start = time.time()
    atoms.get_potential_energy()
    elapsed = time.time() - start

    num_atoms.append(len(atoms))
    times.append(elapsed)
    print(f"{len(atoms):5d} atoms: {elapsed:8.1f} s")

# linear fit: time = a * N + b
fit = Polynomial.fit(num_atoms, times, deg=1)
n   = np.linspace(0, 1.1 * max(num_atoms), 100)

plt.scatter(num_atoms, times, label="AOF-DFT")
plt.plot(n, fit(n), linestyle="--", label="linear fit")
plt.xlim(0)
plt.ylim(0)
plt.xlabel("Number of atoms")
plt.ylabel("Execution time (s)")
plt.legend()
plt.tight_layout()
plt.savefig("large_system_TimevsN.png", dpi=150)
print("Saved large_system_TimevsN.png")

Example output

text
   32 atoms:     13.5 s
   64 atoms:     24.5 s
  128 atoms:     45.5 s
  256 atoms:    130.1 s
Computation time versus number of atoms obtained with this script (v1.0.0, LKT, 24 CPU threads).
Computation time versus number of atoms obtained with this script (v1.0.0, LKT, 24 CPU threads).

The total time also reflects differences in the number of SCF iterations. The time per iteration is 0.44 s (32 atoms), 0.87 s (64 atoms) and 1.77 s (128 atoms), almost proportional to the number of atoms.

Results for larger systems

The figure is from the case study Large-scale system analysis. Whereas the time of Kohn-Sham DFT grows as O(N³), AOF-DFT scales as O(N) with every kinetic energy functional (Intel Xeon Gold 6330, 56 threads).

Computation time versus number of atoms for fcc Pt supercells (from the case study).
Computation time versus number of atoms for fcc Pt supercells (from the case study).

Notes

  • The script uses the conventional functional "LKT" so that the trend can be checked quickly. Switch to kin_type="AS26", kin_model="Crystal26" to time AdvanceSoft26.
  • Time and memory scale almost linearly with the number of FFT grid points. A GPU (device="cuda") is fast, but mind its memory (on a 24 GB GPU the 256-atom calculation of this example ran out of memory). Beyond a few hundred atoms, a CPU machine with plenty of memory is the safe choice.
  • The total time also depends on the number of SCF iterations. The time per iteration is listed in the Time/sec column of the log file.
  • Set num_threads for your machine (see GPUs and OpenMP threads).