dft.operators
Kohn-Sham operator and tiny-grid numerical references.
import mlx_atomistic.dft.operators
Classes
Section titled “Classes”DavidsonDiagonalizer
Section titled “DavidsonDiagonalizer”class DavidsonDiagonalizer def __init__(config: EigensolverConfig = EigensolverConfig(), preconditioner: KineticPreconditioner = KineticPreconditioner())Small block Davidson-style eigensolver.
The dense reference path is still used for tiny grids. Above that cutoff, this applies a conservative preconditioned residual iteration that avoids building the dense Hamiltonian.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
config | EigensolverConfig | EigensolverConfig() | |
preconditioner | KineticPreconditioner | KineticPreconditioner() |
Methods
def solve(operator: KohnShamOperator, *, n_orbitals: int, initial_orbitals: mx.array | None = None) -> DiagonalizationResultSolve for the lowest occupied orbitals.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
operator | KohnShamOperator | The KohnShamOperator to diagonalize. | |
n_orbitals | int | Number of occupied orbitals to solve for. | |
initial_orbitals | mx.array | None | None | Optional starting orbital stack; None uses a deterministic random guess. Defaults to None. |
Returns
DiagonalizationResult— ADiagonalizationResultfor the lowestn_orbitalsstates (dense reference below the fallback size, preconditioned iteration above).
DenseHamiltonianReference
Section titled “DenseHamiltonianReference”class DenseHamiltonianReference def __init__(operator: KohnShamOperator)Explicit dense Hamiltonian for tiny-grid validation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
operator | KohnShamOperator |
Methods
diagonalize
Section titled “diagonalize”def diagonalize(n_orbitals: int) -> DiagonalizationResultDiagonalize the dense reference matrix.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
n_orbitals | int | Number of lowest eigenpairs to return. |
Returns
DiagonalizationResult— ADiagonalizationResultwith the lowestn_orbitalseigenpairs (orthonormalized).
matrix
Section titled “matrix”def matrix() -> np.ndarrayBuild the dense matrix by applying the operator to basis vectors.
Returns
np.ndarray— The Hermitized dense Hamiltonian, shape(grid.size, grid.size).
matvec
Section titled “matvec”def matvec(orbital: mx.array) -> mx.arrayApply the dense matrix to a single orbital.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbital | mx.array | A single real-space orbital of shape grid.shape. |
Returns
mx.array—H ψas a grid-shaped array.
DiagonalizationResult
Section titled “DiagonalizationResult”class DiagonalizationResult def __init__(eigenvalues: mx.array, orbitals: mx.array, residuals: mx.array, orthonormality_error: float, iterations: int, converged: bool, metadata: dict = dict())Small eigenproblem result bundle.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
eigenvalues | mx.array | ||
orbitals | mx.array | ||
residuals | mx.array | ||
orthonormality_error | float | ||
iterations | int | ||
converged | bool | ||
metadata | dict | dict() |
Methods
to_dict
Section titled “to_dict”def to_dict() -> dictReturn a JSON-safe summary.
Returns
dict— The eigenvalues, residuals, orthonormality error, iteration count, convergence flag, and metadata as a JSON-serializable dict.
EigensolverConfig
Section titled “EigensolverConfig”class EigensolverConfig def __init__(max_iterations: int = 16, tolerance: float = 1e-06, max_subspace_size: int = 12, dense_fallback_size: int = 512)Configuration for iterative Kohn-Sham eigensolvers.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
max_iterations | int | 16 | |
tolerance | float | 1e-06 | |
max_subspace_size | int | 12 | |
dense_fallback_size | int | 512 |
KineticPreconditioner
Section titled “KineticPreconditioner”class KineticPreconditioner def __init__(shift: float = 0.5)Simple reciprocal-space kinetic preconditioner.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
shift | float | 0.5 |
Methods
def apply(residual: mx.array, operator: KohnShamOperator) -> mx.arrayApply 1 / (0.5|G+k|² + shift) to a residual.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
residual | mx.array | A real-space residual to precondition. | |
operator | KohnShamOperator | The KohnShamOperator supplying the grid and k-point. |
Returns
mx.array— The preconditioned residual, same shape asresidual.
KohnShamOperator
Section titled “KohnShamOperator”class KohnShamOperator def __init__(grid: RealSpaceGrid, local_potential: mx.array, density: mx.array, hartree: mx.array, xc_potential: mx.array, effective_potential: mx.array, nonlocal_operator: NonlocalPseudopotentialOperator | None = None, kpoint: tuple[float, float, float] = (0.0, 0.0, 0.0))Kohn-Sham Hamiltonian operator for a fixed density and local potential.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
grid | RealSpaceGrid | ||
local_potential | mx.array | ||
density | mx.array | ||
hartree | mx.array | ||
xc_potential | mx.array | ||
effective_potential | mx.array | ||
nonlocal_operator | NonlocalPseudopotentialOperator | None | None | |
kpoint | tuple[float, float, float] | (0.0, 0.0, 0.0) |
Methods
apply_hamiltonian
Section titled “apply_hamiltonian”def apply_hamiltonian(orbitals: mx.array) -> mx.arrayApply H = T + V_eff.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital(s); a single orbital of shape grid.shape or a stack (n_orbitals, *grid.shape). |
Returns
mx.array—H ψ(kinetic + effective local + any nonlocal term), same shape asorbitals.
apply_hartree_xc_potential
Section titled “apply_hartree_xc_potential”def apply_hartree_xc_potential(orbitals: mx.array) -> mx.arrayApply only the Hartree plus exchange-correlation potential.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital(s); a single orbital of shape grid.shape or a stack (n_orbitals, *grid.shape). |
Returns
mx.array—(V_H + V_xc) · ψ, same shape asorbitals.
apply_kinetic
Section titled “apply_kinetic”def apply_kinetic(orbitals: mx.array) -> mx.arrayApply only the kinetic part.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital(s); a single orbital of shape grid.shape or a stack (n_orbitals, *grid.shape). |
Returns
mx.array—T ψat this operator’s k-point, same shape asorbitals.
apply_local_potential
Section titled “apply_local_potential”def apply_local_potential(orbitals: mx.array) -> mx.arrayApply only the external local potential.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital(s); a single orbital of shape grid.shape or a stack (n_orbitals, *grid.shape). |
Returns
mx.array—V_local · ψ, same shape asorbitals.
from_density
Section titled “from_density”def from_density(grid: RealSpaceGrid, local_potential: mx.array, density: mx.array, *, xc_functional: ExchangeCorrelationFunctional | None = None, density_floor: float = 1e-12, nonlocal_operator: NonlocalPseudopotentialOperator | None = None, kpoint: Sequence[float] | None = None) -> KohnShamOperatorBuild an operator from ρ and a local potential.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
grid | RealSpaceGrid | Real-space grid defining the FFT mesh. | |
local_potential | mx.array | External local (ionic) potential on the grid, shape grid.shape. | |
density | mx.array | Electron density ρ on the grid, shape grid.shape. | |
xc_functional | ExchangeCorrelationFunctional | None | None | Exchange-correlation functional; None uses LDAExchangeCorrelation. Defaults to None. |
density_floor | float | 1e-12 | Lower clamp on the density for XC numerical stability. Defaults to 1e-12. |
nonlocal_operator | NonlocalPseudopotentialOperator | None | None | Optional nonlocal pseudopotential operator. Defaults to None. |
kpoint | Sequence[float] | None | None | Optional Bloch k-point; None uses Γ. Defaults to None. |
Returns
KohnShamOperator— AKohnShamOperatorwith the Hartree, XC, and effective potentials precomputed.
rayleigh_quotients
Section titled “rayleigh_quotients”def rayleigh_quotients(orbitals: mx.array) -> mx.arrayReturn <ψᵢ|H|ψᵢ>/<ψᵢ|ψᵢ> for each orbital.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital stack (n_orbitals, *grid.shape). |
Returns
mx.array— The per-orbital Rayleigh quotients (energy estimates), shape(n_orbitals,).
SubspaceDiagonalizer
Section titled “SubspaceDiagonalizer”class SubspaceDiagonalizer def __init__(max_iterations: int = 8, tolerance: float = 1e-06)Operator-backed Rayleigh-Ritz diagonalizer for tiny prototype grids.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
max_iterations | int | 8 | |
tolerance | float | 1e-06 |
Methods
def solve(operator: KohnShamOperator, *, n_orbitals: int) -> DiagonalizationResultSolve the occupied subspace.
For this milestone the implementation intentionally uses the explicit tiny-grid reference matrix as the Rayleigh-Ritz space. The public solver boundary lets us replace this with an iterative Davidson path later.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
operator | KohnShamOperator | The KohnShamOperator to diagonalize. | |
n_orbitals | int | Number of occupied orbitals to solve for. |
Returns
DiagonalizationResult— ADiagonalizationResultfor the lowestn_orbitalsstates.
Functions
Section titled “Functions”apply_hamiltonian
Section titled “apply_hamiltonian”def apply_hamiltonian(orbitals: mx.array, effective_potential: mx.array, grid: RealSpaceGrid) -> mx.arrayApply T + V_eff using an explicit effective potential.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital(s); a single orbital of shape grid.shape or a stack (n_orbitals, *grid.shape). | |
effective_potential | mx.array | Combined local effective potential on the grid, shape grid.shape. | |
grid | RealSpaceGrid | Real-space grid defining the FFT mesh. |
Returns
mx.array—(T + V_eff) ψ, same shape asorbitals.
apply_hartree_xc_potential
Section titled “apply_hartree_xc_potential”def apply_hartree_xc_potential(orbitals: mx.array, hartree: mx.array, xc_potential: mx.array) -> mx.arrayApply Hartree plus exchange-correlation potential to orbitals.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital(s); a single orbital of shape grid.shape or a stack (n_orbitals, *grid.shape). | |
hartree | mx.array | Hartree potential on the grid, shape grid.shape. | |
xc_potential | mx.array | Exchange-correlation potential on the grid, shape grid.shape. |
Returns
mx.array— The product(V_H + V_xc) · ψ, same shape asorbitals.
apply_kinetic
Section titled “apply_kinetic”def apply_kinetic(orbitals: mx.array, grid: RealSpaceGrid, *, kpoint: Sequence[float] | None = None) -> mx.arrayApply the plane-wave kinetic operator -1/2 ∇².
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital(s); a single orbital of shape grid.shape or a stack (n_orbitals, *grid.shape). | |
grid | RealSpaceGrid | Real-space grid defining the FFT mesh. | |
kpoint | Sequence[float] | None | None | Optional k-point 3-vector added to the reciprocal-grid G-vectors; None uses the Γ point. Defaults to None. |
Returns
mx.array— The kinetic operator applied toorbitals, same shape asorbitals.
apply_local_potential
Section titled “apply_local_potential”def apply_local_potential(orbitals: mx.array, local_potential: mx.array) -> mx.arrayApply a local multiplicative potential to orbitals.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital(s); a single orbital of shape grid.shape or a stack (n_orbitals, *grid.shape). | |
local_potential | mx.array | Local potential on the grid, shape grid.shape. |
Returns
mx.array— The elementwise productV · ψ, same shape asorbitals.
orbital_residuals
Section titled “orbital_residuals”def orbital_residuals(orbitals: mx.array, operator: KohnShamOperator, eigenvalues: mx.array | None = None) -> mx.arrayReturn ||Hψᵢ - εᵢψᵢ|| for each orbital.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital stack (n_orbitals, *grid.shape). | |
operator | KohnShamOperator | The KohnShamOperator supplying H. | |
eigenvalues | mx.array | None | None | Optional per-orbital eigenvalues εᵢ; None uses the Rayleigh quotients. Defaults to None. |
Returns
mx.array— The per-orbital residual norms, shape(n_orbitals,).
orthonormality_error
Section titled “orthonormality_error”def orthonormality_error(orbitals: mx.array, grid: RealSpaceGrid) -> floatReturn max absolute overlap error from the identity matrix.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
orbitals | mx.array | Real-space orbital stack (n_orbitals, *grid.shape). | |
grid | RealSpaceGrid | Real-space grid; its dv weights the overlap integral. |
Returns
float— The maximum absolute deviation of the overlap matrix⟨ψᵢ|ψⱼ⟩from the identity.