Solvers and results¤
Five verbs over one built functional, one result type: scf (DIIS, with
optional accel=adiis() far-from-convergence extrapolation and
smearing=fermi() fractional occupations reporting the Mermin free energy),
newton (trust-region second order on orbital rotations, saddle-robust
Steihaug-Toint steps), roks (its shared-orbital restricted open-shell
variant), minimize (direct orbital optimization with any optax
optimizer), and gdm (direct minimization by L-BFGS over occupied-virtual
rotations, evaluated through the occupied orbitals). implicit_density exposes the converged density as a
differentiable function of the functional (CPHF via custom_vjp).
All solvers (and scf_batched) take a guess=: an initial-density spec
from core / sad / minao / sap, or an explicit (nspin, nao, nao)
density array for warm restarts. The guess changes the iteration count, never
the converged fixed point. The default is minao(); the core Hamiltonian is
the fallback for a raw System (no element identities) or an element the
minimal basis does not reach.
dftax.ks.scf.scf(ks: KS, *, max_iter: int = 128, e_tol: float = 1e-08, d_tol: float = 1e-06, diis_space: int = 8, lindep_thresh: float = 1e-07, level_shift: float = 0.0, guess: GuessSpec | Array | None = None, accel: ADIISSpec | None = None, smearing: FermiSpec | None = None, verbose: bool = False) -> KSResult
¤
Solve the Kohn-Sham equations self-consistently.
Restricted (nspin = 1) and spin-polarized (nspin = 2) systems use
the same call; DIIS on the commutator FPS - SPF accelerates the
iterations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ks
|
KS
|
the energy functional, from :class: |
required |
max_iter
|
int
|
maximum number of iterations. |
128
|
e_tol
|
float
|
convergence threshold on the change of the total energy (Ha).
Density-fitted energies carry a floating-point noise of about
|
1e-08
|
d_tol
|
float
|
convergence threshold on the norm of the commutator, the
orbital gradient. PySCF's convention is |
1e-06
|
diis_space
|
int
|
number of previous iterations DIIS extrapolates over. |
8
|
lindep_thresh
|
float
|
overlap eigenvalues below this are dropped from the orthonormal basis (removes linear dependencies). |
1e-07
|
level_shift
|
float
|
shift (Ha) added to the virtual orbital energies during
the iterations; damps oscillations at the cost of slower
convergence. The returned |
0.0
|
guess
|
GuessSpec | Array | None
|
initial density: :func: |
None
|
accel
|
ADIISSpec | None
|
:func: |
None
|
smearing
|
FermiSpec | None
|
:func: |
None
|
verbose
|
bool
|
print the energy and commutator norm at every iteration. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
KSResult
|
class: |
KSResult
|
issued) when |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
ValueError
|
|
Example
res = scf(KS(mol, PBE()), guess=sad())
res.e_tot, res.converged, res.P[0]
dftax.ks.scf.adiis(*, space: int = 8, switch: float = 0.1) -> ADIISSpec
¤
ADIIS acceleration for :func:scf (Hu and Yang, J. Chem. Phys. 132,
054109 (2010)).
ADIIS minimizes a model of the energy over the previous densities and
Fock matrices, which does not overshoot from a poor start; while the
commutator norm is below switch the iterations use DIIS instead. Use
it when plain DIIS oscillates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
int
|
number of previous iterations kept, for ADIIS and DIIS alike. |
8
|
switch
|
float
|
commutator norm below which DIIS takes over. |
0.1
|
Example
res = scf(ks, accel=adiis())
res = scf(ks, accel=adiis(switch=1e-2))
dftax.ks.scf.fermi(*, sigma: float = 0.01) -> FermiSpec
¤
Fermi-Dirac smearing of the SCF occupations.
Occupations are f_i = w / (1 + exp((eps_i - mu) / sigma)), with the
chemical potential mu fixed per spin channel by the electron count.
Use it for small-gap systems, where integer occupations do not converge.
e_tot is then the free energy E - sigma·S, whose gradient is the
force; KSResult.ts holds sigma·S, so e_tot + ts is the
Kohn-Sham energy and e_tot + 0.5·ts estimates the sigma -> 0
energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
float
|
smearing width in Hartree (0.01 Ha ~ 3160 K electronic temperature; typical range 0.001 to 0.02). |
0.01
|
Example
res = scf(ks, smearing=fermi(sigma=0.005))
dftax.ks.minimize.minimize(ks: KS, optimizer: optax.GradientTransformation | None = None, *, max_steps: int = 2000, g_tol: float = 1e-06, check_every: int = 10, Z0: Array | tuple | None = None, guess: GuessSpec | Array | None = None, verbose: bool = False) -> KSResult
¤
Minimize the KS energy directly over orthonormalized coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ks
|
KS
|
the built :class: |
required |
optimizer
|
GradientTransformation | None
|
any |
None
|
max_steps
|
int
|
optimizer step budget. |
2000
|
g_tol
|
float
|
stop when the global gradient norm falls below this. |
1e-06
|
check_every
|
int
|
host-side convergence checks happen every this many steps
(each check blocks on the device), so the reported |
10
|
Z0
|
Array | tuple | None
|
optional initial coefficient guess, one |
None
|
guess
|
GuessSpec | Array | None
|
alternative to |
None
|
verbose
|
bool
|
print per-step energy and gradient norm. |
False
|
Example
res = minimize(ks) # optax.adam(0.3)
res = minimize(ks, optax.chain(
optax.clip_by_global_norm(1.0), optax.adam(0.1)), g_tol=1e-7)
dftax.ks.gdm.gdm(ks: KS, *, max_iter: int = 200, e_tol: float = 1e-08, d_tol: float = 1e-06, history: int = 20, max_step: float = 0.5, gap_floor: float = 0.05, lindep_thresh: float = 1e-07, guess: GuessSpec | jax.Array | None = None, orbital_xc: bool = True, verbose: bool = False) -> KSResult
¤
Minimize the KS energy over orbital rotations (restricted and spin-polarized alike).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ks
|
KS
|
the built :class: |
required |
max_iter
|
int
|
budget of energy evaluations (each is one Fock build). |
200
|
e_tol
|
float
|
convergence threshold on the energy change of an accepted
step (Ha); same meaning and floor as in :func: |
1e-08
|
d_tol
|
float
|
convergence threshold on the commutator norm, measured exactly
as :func: |
1e-06
|
history
|
int
|
L-BFGS memory depth. |
20
|
max_step
|
float
|
largest rotation angle (rad) any one step may take. |
0.5
|
gap_floor
|
float
|
smallest orbital-energy gap (Ha) the preconditioner uses, which keeps it positive where the current orbitals are not in aufbau order. |
0.05
|
lindep_thresh
|
float
|
overlap-eigenvalue cutoff for the orthonormalizer. |
1e-07
|
guess
|
GuessSpec | Array | None
|
as for :func: |
None
|
orbital_xc
|
bool
|
evaluate through the occupied orbitals
(:meth: |
True
|
verbose
|
bool
|
print every energy evaluation. |
False
|
n_iter of the result counts energy evaluations, the unit that costs.
dftax.ks.newton.newton(ks: KS, *, max_iter: int = 64, g_tol: float = 1e-06, e_tol: float = 1e-10, cg_iters: int = 32, trust: float = 0.4, guess: GuessSpec | Array | None = None, verbose: bool = False) -> KSResult
¤
Second-order SCF (trust-region Newton on orbital rotations).
Converges quadratically near a minimum and handles densities that DIIS
and ADIIS limit-cycle on (small-gap transition metals, stretched bonds).
One Newton iteration costs a CG solve of Hessian-vector products, each
the price of a couple of Fock builds, so for benign systems
:func:~dftax.ks.scf.scf is faster; reach for this when robustness is
the constraint, typically warm-started from a stalled SCF density
(newton(ks, guess=res.P)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ks
|
KS
|
the built :class: |
required |
max_iter
|
int
|
maximum Newton iterations. |
64
|
g_tol
|
float
|
convergence threshold on the orbital-gradient norm. |
1e-06
|
e_tol
|
float
|
convergence threshold on the energy change (Ha). |
1e-10
|
cg_iters
|
int
|
CG iterations for the Newton step (Hessian-vector solves). |
32
|
trust
|
float
|
initial trust radius on the rotation norm (radians); halved on an uphill proposal, doubled (capped at 1) on success. |
0.4
|
guess
|
GuessSpec | Array | None
|
initial density, same forms as :func: |
None
|
verbose
|
bool
|
print per-iteration energy / gradient norm. |
False
|
Example
res = scf(ks, max_iter=200) # limit-cycles on a hard case
res = newton(ks, guess=res.P) # quadratic cleanup
dftax.ks.newton.roks(ks: KS, *, max_iter: int = 64, g_tol: float = 1e-06, e_tol: float = 1e-10, cg_iters: int = 32, trust: float = 0.4, guess: GuessSpec | Array | None = None, verbose: bool = False) -> KSResult
¤
Restricted open-shell Kohn-Sham, solved by trust-region Newton.
Both spin channels share one set of spatial orbitals (α fills the first
nocc[0], β the first nocc[1]), so the result has no spin
contamination. ks must be spin-polarized (spin != 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ks
|
KS
|
a spin-polarized :class: |
required |
max_iter
|
int
|
maximum Newton iterations. |
64
|
g_tol
|
float
|
convergence threshold on the orbital-gradient norm. |
1e-06
|
e_tol
|
float
|
convergence threshold on the energy change (Ha). |
1e-10
|
cg_iters
|
int
|
conjugate-gradient iterations per Newton step. |
32
|
trust
|
float
|
initial trust radius on the rotation norm (rad). |
0.4
|
guess
|
GuessSpec | Array | None
|
initial density, as in :func: |
None
|
verbose
|
bool
|
print the energy and gradient norm at every iteration. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
KSResult
|
class: |
KSResult
|
channels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Example
res = roks(KS(mol, PBE(), spin=2)) # triplet
dftax.ks.scf.KSResult
¤
Result of a Kohn-Sham solve (:func:scf, :func:~dftax.ks.gdm.gdm,
:func:~dftax.ks.newton.newton, :func:~dftax.ks.minimize.minimize).
Orbital and density arrays have a leading spin axis: nspin = 1 for a
closed shell (P[0] is the total density), nspin = 2 (α, β) for a
spin-polarized system.
Attributes:
| Name | Type | Description |
|---|---|---|
e_tot |
total energy (Ha), including nuclear repulsion and dispersion;
under smearing, the free energy |
|
e_elec |
electronic energy (Ha), |
|
converged |
whether the convergence thresholds were met. |
|
n_iter |
number of iterations taken. |
|
nocc |
occupied orbitals per spin channel. |
|
mo_energy |
orbital energies (Ha), |
|
mo_coeff |
orbital coefficients in the AO basis, |
|
P |
density matrix, |
|
ts |
entropy term |
__annotations__
class-attribute
¤
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
__dataclass_fields__
class-attribute
¤
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
__dataclass_params__
class-attribute
¤
__dict__
class-attribute
¤
Read-only proxy of a mapping.
__doc__
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__firstlineno__
class-attribute
¤
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer iteral.
int('0b100', base=0) 4
__match_args__
class-attribute
¤
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
__module__
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__static_attributes__
class-attribute
¤
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
__weakref__
property
¤
list of weak references to the object
ts
class-attribute
¤
Convert a string or number to a floating-point number, if possible.
__eq__(other)
¤
__init__(e_tot: float, e_elec: float, converged: bool, n_iter: int, nocc: tuple[int, ...], mo_energy: Float[Array, 'nspin nmo'], mo_coeff: Float[Array, 'nspin nao nmo'], P: Float[Array, 'nspin nao nao'], ts: float = 0.0) -> None
¤
__repr__()
¤
dftax.ks.implicit.implicit_density(ks: KS)
¤
Converged closed-shell density P* for the assembled functional ks,
differentiable w.r.t. ks (and hence anything it was assembled from) by implicit
differentiation of the SCF fixed point. Restricted (closed-shell) only.
Initial guesses¤
dftax.ks.guess.core() -> CoreSpec
¤
Initial guess from the core Hamiltonian: the lowest eigenvectors of
hcore, without electron repulsion.
The simplest and weakest guess; :func:~dftax.ks.scf.scf falls back to
it when the default :func:minao guess cannot be built.
dftax.ks.guess.sad() -> SADSpec
¤
Superposition of atomic densities, each from a spherically averaged atomic Hartree-Fock calculation in the molecule's basis.
dftax.ks.guess.minao(basis: str = 'sto-3g') -> MinAOSpec
¤
Superposition of atomic densities projected from a minimal basis.
Per unique element, tabulated ground-state occupations are placed on the
minimal-basis AOs and projected onto the computational basis through the
cross overlap. Cheaper than :func:sad (no atomic solves), nearly as good.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
basis
|
str
|
minimal basis holding the atomic ground states, any Basis Set
Exchange name with one shell per occupied |
'sto-3g'
|
dftax.ks.guess.sap(fit: str = 'sap_helfem_large', *, grid: Becke | None = None) -> SAPSpec
¤
Superposition of atomic potentials: the first Fock matrix is
T + Σ_A V_A with fitted atomic potentials V_A (S. Lehtola, J.
Chem. Theory Comput. 15, 1593 (2019)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
str
|
the potential fit, a Basis Set Exchange name
( |
'sap_helfem_large'
|
grid
|
Becke | None
|
quadrature for the potential matrix, a
:func: |
None
|