"""
Advance/OF-DFT example: SCF calculation of diamond Si (total energy and forces).

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

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"

# 1) build the structure with ASE: the cubic cell of diamond Si (8 atoms)
atoms = bulk("Si", crystalstructure="diamond", a=5.43, cubic=True)

# 2) attach the calculator
atoms.calc = AOFDFTCalculator(
    kin_type  = "AS26",         # deep-learned kinetic energy functional AdvanceSoft26
    kin_model = "Crystal26",    # pre-trained model for crystals
    vps_dir   = VPS_DIR,        # pseudopotentials
    pao_dir   = PAO_DIR,        # pseudo-atomic orbitals
    e_cut     = 150 * Hartree,  # cutoff energy of the density grid (in eV)
)

# 3) the SCF calculation runs when a property is requested
energy = atoms.get_potential_energy()  # eV
forces = atoms.get_forces()            # eV/Angstrom

print(f"Total energy : {energy:.6f} eV")
print(f"Fermi energy : {atoms.calc.e_fermi:.4f} eV")
print("Forces on atoms (eV/Angstrom):")
print(forces)
