Atomic charges and spin
Spin-polarized calculation (bcc Fe)
Run a spin-polarized calculation for ferromagnetic bcc Fe and get the spin of each atom and the total magnetic moment.
For a collinear spin-polarized calculation, set spin_type="polarized" and give the initial spin of each atom in atoms.arrays["spin"]. After the SCF calculation the same array holds the calculated spins.
"""
Advance/OF-DFT example: spin-polarized calculation of bcc Fe.
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"
atoms = bulk("Fe", "bcc", a=2.87).repeat((3, 3, 3)) # 3x3x3 primitive cells, 27 atoms
# initial spin of each atom
atoms.arrays["spin"] = [1.0] * len(atoms)
atoms.calc = AOFDFTCalculator(
console = False,
logging_file = "fe_spin.log",
kin_type = "AS26",
kin_model = "Crystal26",
vps_dir = VPS_DIR,
pao_dir = PAO_DIR,
e_cut = 180 * Hartree,
spin_type = "polarized", # collinear spin-polarized calculation
scf_style = "magnetic", # SCF preset for magnetic systems
)
atoms.get_potential_energy()
calc = atoms.calc
# after the SCF, atoms.arrays["spin"] holds the calculated spin of each atom
spins = atoms.arrays["spin"]
print(f"Spin of each atom : {spins.min():.4f} ... {spins.max():.4f}")
print(f"Total magnetic moment : {calc.total_magmom:.4f} ({calc.total_magmom / len(atoms):.4f} per atom)")
print(f"Absolute magnetic moment : {calc.absolute_magmom:.4f}")
Example output
Results with v1.0.0 (Crystal26).
Spin of each atom : 1.8832 ... 1.8832
Total magnetic moment : 50.8454 (1.8832 per atom)
Absolute magnetic moment : 50.8454
All 27 atoms have the same spin.
Notes
- The cell is a 3×3×3 repetition of the bcc primitive cell (27 atoms). With v1.0.0 the results change when the cell has a short period.
- The initial spins are given as a list over all atoms. Without them the SCF may converge to a non-magnetic solution, so always set them for magnetic materials.
scf_style="magnetic"is recommended for magnetic systems. It is selected automatically whenkin_modelis a crystal model andspin_type="polarized".calc.total_magmomis the total magnetic moment (integral of the spin density) andcalc.absolute_magmomthe absolute magnetic moment (integral of its absolute value). For an antiferromagnet the former is zero and the latter finite.- The spin of each atom comes from the Mulliken analysis: the difference between the numbers of up and down electrons.
- The case study Analysis of Fe reports a spin of 2.00 per atom from a calculation with a smearing width of 0.01 Hartree. This example uses a different width, the default of 0.02 Hartree.
- For the spatial distribution, see Visualizing the spin density.
Version 1.0 supports collinear spin only. Non-collinear spin and spin-orbit coupling are planned for future versions.