Skip to content

dft.potentials

Toy DFT potentials and energy helpers.

import mlx_atomistic.dft.potentials

class LocalGaussianPseudopotential
def __init__(centers: Sequence[Sequence[float]], amplitudes: Sequence[float] | float, widths: Sequence[float] | float)

Simple periodic local Gaussian pseudopotential for toy SCF examples.

Parameters

NameTypeDefaultDescription
centersSequence[Sequence[float]]
amplitudesSequence[float] | float
widthsSequence[float] | float

Methods

def field(grid: RealSpaceGrid) -> mx.array

Evaluate the local potential on a real-space grid.

Parameters

NameTypeDefaultDescription
gridRealSpaceGridReal-space grid to sample the potential on.

Returns

  • mx.array — The summed Gaussian local potential on the grid, shape grid.shape.
def apply_kinetic(orbital: mx.array, grid: RealSpaceGrid) -> mx.array

Apply the plane-wave kinetic operator -1/2 ∇² to one orbital.

Parameters

NameTypeDefaultDescription
orbitalmx.arrayA single real-space orbital, shape grid.shape.
gridRealSpaceGridReal-space grid defining the FFT mesh.

Returns

  • mx.array — The kinetic operator applied to the orbital (real part), shape grid.shape.
def density_from_normalized_orbitals(orbitals: mx.array, grid: RealSpaceGrid, *, occupations: Sequence[float]) -> mx.array

Build a density after normalizing orbitals.

Parameters

NameTypeDefaultDescription
orbitalsmx.arrayReal-space orbital stack (n_orbitals, *grid.shape).
gridRealSpaceGridReal-space grid defining the FFT mesh.
occupationsSequence[float]Per-orbital occupation numbers.

Returns

  • mx.array — The electron density ρ = Σᵢ fᵢ |ψᵢ|² on the grid, shape grid.shape.
def electron_count(density: mx.array, grid: RealSpaceGrid) -> mx.array

Integrate a density over the real-space grid.

Parameters

NameTypeDefaultDescription
densitymx.arrayElectron density ρ on the grid, shape grid.shape.
gridRealSpaceGridReal-space grid; its dv weights the integral.

Returns

  • mx.array — The scalar integrated electron count ∫ρ dr.
def energy_decomposition(orbitals: mx.array, density: mx.array, local_potential: mx.array, grid: RealSpaceGrid, *, occupations: Sequence[float], density_floor: float = 1e-12, xc_functional: ExchangeCorrelationFunctional | None = None) -> dict[str, mx.array]

Return core toy-DFT energy terms.

Parameters

NameTypeDefaultDescription
orbitalsmx.arrayReal-space occupied orbital(s).
densitymx.arrayElectron density ρ on the grid, shape grid.shape.
local_potentialmx.arrayExternal local potential on the grid, shape grid.shape.
gridRealSpaceGridReal-space grid; its dv weights the integrals.
occupationsSequence[float]Per-orbital occupation numbers.
density_floorfloat1e-12Lower clamp on the density for XC stability. Defaults to 1e-12.
xc_functionalExchangeCorrelationFunctional | NoneNoneExchange-correlation functional; None uses DiracExchange. Defaults to None.

Returns

  • dict[str, mx.array] — A dict of energy terms — kinetic, local, hartree, xc, total (plus exchange/correlation when the functional exposes them).
def hartree_potential(density: mx.array, grid: RealSpaceGrid) -> mx.array

Solve the periodic Hartree potential for ρ with the G = 0 term removed.

Parameters

NameTypeDefaultDescription
densitymx.arrayElectron density ρ on the grid, shape grid.shape.
gridRealSpaceGridReal-space grid defining the FFT mesh.

Returns

  • mx.array — The real-space Hartree potential V_H, shape grid.shape (the G = 0 term is dropped against a neutralizing background).
def kinetic_energy(orbitals: mx.array, grid: RealSpaceGrid, *, occupations: Sequence[float]) -> mx.array

Return the occupied one-particle kinetic energy.

Parameters

NameTypeDefaultDescription
orbitalsmx.arrayReal-space orbital(s); a single orbital of shape grid.shape or a stack (n_orbitals, *grid.shape).
gridRealSpaceGridReal-space grid; its dv weights the integral.
occupationsSequence[float]Per-orbital occupation numbers.

Returns

  • mx.array — The scalar occupied kinetic energy Σᵢ fᵢ ⟨ψᵢ|T|ψᵢ⟩.
def lda_exchange_energy_potential(density: mx.array, grid: RealSpaceGrid | None = None, *, density_floor: float = 1e-12) -> tuple[mx.array, mx.array]

Return Dirac LDA exchange energy and potential for an unpolarized density.

Parameters

NameTypeDefaultDescription
densitymx.arrayElectron density ρ on the grid, shape grid.shape.
gridRealSpaceGrid | NoneNoneReal-space grid providing the integration weight dv; None uses unit weight. Defaults to None.
density_floorfloat1e-12Lower clamp on the density for numerical stability. Defaults to 1e-12.

Returns

  • tuple[mx.array, mx.array] — An (energy, potential) tuple: the scalar exchange energy and the exchange potential on the grid.
def local_pseudopotential_forces(density: mx.array, grid: RealSpaceGrid, pseudopotential: LocalGaussianPseudopotential) -> mx.array

Return Hellmann-Feynman forces on local Gaussian centers.

The local energy is ∫ρ(r)V_loc(r; R_I)dr. This computes -∂E/∂R_I for the Gaussian center coordinates.

Parameters

NameTypeDefaultDescription
densitymx.arrayElectron density ρ on the grid, shape grid.shape.
gridRealSpaceGridReal-space grid; its dv weights the integral.
pseudopotentialLocalGaussianPseudopotentialThe LocalGaussianPseudopotential whose centers feel the force.

Returns

  • mx.array — The force on each Gaussian center, shape (n_centers, 3).