dft.gga
PBE GGA exchange-correlation with an autodiff-derived potential.
The defining idea: a GGA energy is E_xc = ∫ ε(ρ, ∇ρ) dr, and its potential is
the functional derivative v_xc = δE_xc/δρ = ∂ε/∂ρ - ∇·(∂ε/∂∇ρ). The gradient
term is the part that is famously error-prone to hand-derive. Here we write only
the energy density and obtain v_xc from mx.grad of the total energy — the
autodiff machinery reconstructs the divergence term automatically, provided the
density gradient is built with a differentiable (MLX-native) FFT.
import mlx_atomistic.dft.gga
Classes
Section titled “Classes”PBEExchangeCorrelation
Section titled “PBEExchangeCorrelation”class PBEExchangeCorrelation def __init__(name: str = 'pbe-gga')PBE GGA exchange-correlation; v_xc is the autodiff functional derivative.
The uniform-gas correlation baseline reuses the PZ81 parameterization already in the package (true PBE uses PW92; the difference is sub-mHa and the baseline is swappable).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | str | 'pbe-gga' |
Methods
evaluate
Section titled “evaluate”def evaluate(density: mx.array, grid: RealSpaceGrid | None = None, *, density_floor: float = 1e-12) -> XCResultEvaluate the PBE GGA exchange-correlation energy density, potential, and total energy.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
density | mx.array | Electron density rho sampled on the grid. | |
grid | RealSpaceGrid | None | None | Real-space grid; required for GGA to evaluate the density gradient. Defaults to None. |
density_floor | float | 1e-12 | Lower clamp applied to the density for numerical stability. Defaults to 1e-12. |
Returns
XCResult— AnXCResultwith the energy density, potential, and total energy.
Raises
ValueError— IfgridisNone(a grid is required for GGA).
Functions
Section titled “Functions”density_gradient
Section titled “density_gradient”def density_gradient(rho: mx.array, grid: RealSpaceGrid) -> mx.arrayReturn ∇ρ (shape (3, *grid.shape)) via reciprocal-space differentiation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rho | mx.array | ||
grid | RealSpaceGrid |
Returns
mx.array