"""
Advance/OF-DFT example: Mulliken charges of each atom.

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

from ase.build import bulk

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 repetitions of the primitive cell (16 atoms)
systems = {
    "SiC (zincblende)": bulk("SiC", crystalstructure="zincblende", a=4.36).repeat((2, 2, 2)),
    # you can add more systems
    # "GaAs (zincblende)": bulk("GaAs", crystalstructure="zincblende", a=5.65).repeat((2, 2, 2)),
}

for name, atoms in systems.items():
    atoms.calc = AOFDFTCalculator(
        console       = False,
        logging_file  = f"{atoms.get_chemical_formula()}.log",
        kin_type      = "AS26",
        kin_model     = "Crystal26",
        vps_dir       = VPS_DIR,
        pao_dir       = PAO_DIR,
        atomic_charge = True,  # default: atomic charges are evaluated after the SCF
    )
    atoms.get_potential_energy()

    # Mulliken charges are stored in the Atoms object (positive = lost electrons)
    charges = atoms.arrays["charge"]

    print(name)
    for atom, q in zip(atoms, charges):
        print(f"  {atom.index:2d} {atom.symbol:2s} {q:+.4f}")
    print(f"  sum = {charges.sum():+.2e}")
