Skip to main content

dftax

A differentiable Kohn-Sham DFT engine in pure JAX.

PyPI Python License CI Nightly Docs

dftax writes Kohn-Sham DFT (integrals, quadrature grid, exchange-correlation, the SCF loop) as a single differentiable JAX program. Once the energy is one autodiff-traceable function, the derivatives quantum chemistry cares about are just calls to jax.grad. Forces are −∂E/∂R; the Fock matrix is sym(∂E/∂P), so no exchange-correlation potential is coded by hand; response properties are higher derivatives of the same function.

forces(mol, xc, res)         # −∂E/∂R    nuclear forces
hessian(mol, xc)             # ∂²E/∂R²   vibrational frequencies
polarizability(mol, xc)      # −∂²E/∂F²
alchemical_deriv(mol, xc)    # ∂E/∂Z

Converged quantities are differentiated through the SCF fixed point (CPHF), so a gradient of a converged calculation costs one linear solve rather than an unrolled solver. And because it is ordinary JAX, the whole engine jits, vmaps over geometries, and runs on GPU; a DFT calculation drops into a training loop or an end-to-end functional fit like any other differentiable block.

Molecules and crystals: periodic cells run with GTH pseudopotentials in a Gaussian basis (at the Gamma point or on a k-mesh) or in plane waves, with forces and the stress tensor by the same autodiff.

The runtime carries no libcint, libxc, or Maple: basis sets come from the Basis Set Exchange at setup, the molecular grid is built natively, and PySCF appears only as a test-time reference (and, for periodic cells, as the source of the GTH table files, which are GPL-2.0 and not shipped here).

Installation

pip install dftax            # CPU
pip install dftax[cuda12]    # + CUDA-12 jaxlib (Linux GPU)
pip install dftax[periodic]  # + the GTH tables for periodic cells

Quick start

import jax
jax.config.update("jax_enable_x64", True)   # DFT energies want float64

from dftax import KS, Molecule, scf
from dftax.energy.xc import PBE   # or functional("..."): LDA, PBE0, B3LYP,
                                  # CAM-B3LYP, wB97X(-V), wB97M-V, r2SCAN

mol = Molecule.from_xyz("O 0 0 0; H 0.757 0.587 0; H -0.757 0.587 0", "sto-3g")
res = scf(KS(mol, PBE()))            # DIIS SCF -> KSResult
print(res.e_tot, res.converged)     # total energy (Ha), convergence flag

KS(system, xc, *, grid=, coulomb=, spin=, mesh=, dispersion=) assembles the energy functional; the verbs scf, newton, roks, and minimize solve it, and forces, dipole, polarizability, and the rest read properties from it. Every choice is a value passed to the builder, not a global flag: a nonzero spin (given as 2S) runs the spin-polarized α/β path, dispersion=d3bj() or d4() adds a dispersion correction, scf(ks, accel=adiis()) accelerates hard SCF cases, and scf(ks, smearing=fermi()) gives fractional occupations and the Mermin free energy for metallic or degenerate systems.

Periodic systems

import numpy as np
from dftax import KS, fermi, forces, scf
from dftax.energy.xc import LDA
from dftax.pbc import Cell, kmesh, kpoint_ks, planewaves, scf_pw, stress, uniform

a = 0.5 * 5.431 * np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]])   # Angstrom
cell = Cell.from_xyz("Si 0 0 0; Si 1.358 1.358 1.358", a,
                     basis="gth-dzvp", pseudo="gth-pade")
grid = uniform(mesh=(21, 21, 21))

res = scf(KS(cell, LDA(), grid=grid))                                  # Gaussian, Gamma
res = scf(kpoint_ks(cell, LDA(), grid=grid, kpts=kmesh(4, 4, 4)))      # Gaussian, k-mesh
F, sigma = forces(cell, LDA(), res, grid=grid), stress(cell, LDA(), res, grid=grid)

res = scf_pw(cell, LDA(), planewaves(15.0), kpts=kmesh(4, 4, 4),
             smearing=fermi(sigma=0.001))                              # plane waves
F, sigma = forces(cell, LDA(), res), stress(cell, LDA(), res)

The Gaussian engine reproduces PySCF's periodic code (same basis, potential and grid) to 1e-8 Ha or better, from two-atom cells to 72-atom quartz; the plane waves reproduce GPAW's band gaps, forces, stresses and silicon's equation of state with the same potentials. The record is scripts/pbc/BASELINES.md; the guide is Periodic systems.

Scaling up

The exact 4-center ERI is O(N⁴): the small-system reference the rest is checked against. From there each backend is one more value on the builder. Density fitting (df(...)) takes the Coulomb cost to O(N³); streaming holds the tensors at O(N²) memory; Schwarz screening trims the per-iteration work; and mesh=mesh() shards the grid and the density-fitting tensor across GPUs. Every collective differentiates, so SCF, minimization, and forces run unchanged.

from dftax import KS, df, mesh, scf
from dftax.energy.xc import PBE0

scf(KS(mol, PBE0(), coulomb=df("def2-universal-jkfit"), mesh=mesh()))

The same mesh spans several nodes: launch the script once per node and call distributed() first, and the auxiliary slabs shard across every GPU of the allocation (scripts/gpu/distributed.sbatch is a working template).

Accuracy

Against PySCF on water / sto-3g (see scripts/bench/BENCHMARKS.md):

functional |ΔE| vs PySCF
LDA 2e-11 (≈ machine)
B3LYP 2e-9 (≈ machine)
PBE 1.5e-5
PBE0 1.1e-5

LDA, PBE, B3LYP and PBE0 reproduce libxc to machine precision (an earlier ~1e-5 Ha PBE gap traced to one truncated constant, now exact). The later rungs were ported against their references directly: r2SCAN matches libxc to ~1e-9, ωB97X-V (including its VV10 term) matches a full PySCF solve to ~2e-13 on matched grids, ωB97M-V matches libxc pointwise to machine precision and a full PySCF solve to ~1e-10, and the D3(BJ)/D4 dispersion models match tad-dftd3/tad-dftd4 to machine precision. Analytic forces match finite differences to about 4e-8 Ha/Bohr, the CPHF polarizability matches finite-field to about 1e-4, and vibrational frequencies match PySCF to a few cm⁻¹.

Limitations

  • Orbital bases run up to i shells (l=6), i.e. through cc-pV5Z/6Z; use the density-fitting backend at those sizes (the exact 4-center path is correct but impractically slow there, as in conventional codes).
  • The materialized exact-ERI path hits a GPU memory ceiling near nao ≈ 70; use density fitting (the default, with a device-aware memory policy), streaming, and screening at scale (exact-exchange compute stays O(N⁴) regardless).
  • VV10 (ωB97X-V) needs the materialized XC grid: the pair quadrature does not stream or shard yet.
  • GPU correctness is validated interactively on an A100 rather than in CPU CI, and large-N GPU throughput is not yet benchmarked.
  • Periodic cells: GTH pseudopotentials only (no all-electron), LDA and GGA (no hybrids), closed-shell k-points and plane waves (spin-polarized only at the Gamma point in the Gaussian basis).

Documentation

Docs, tutorials, and executed example notebooks live at https://andresguzco.github.io/dftax/; the same examples are runnable scripts under examples/.

See also

dftax builds on Equinox and Optax, and shares ground with other differentiable electronic-structure codes: MESS and D4FT (in JAX), DQC (PyTorch), and PySCFad. It leans on PySCF as its test-time reference and aims to be a good neighbor to it, not a replacement.

Citation

@software{dftax,
  author  = {Guzm{\'a}n-Cordero, Andr{\'e}s},
  title   = {dftax: a differentiable Kohn-Sham DFT engine in JAX},
  url     = {https://github.com/andresguzco/dftax},
  version = {0.10.0},
  year    = {2026},
}

License

Apache-2.0.

Metadata

Release files for dftax 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dftax 0.10.0
File Size Uploaded Provenance Actions
dftax-0.10.0.tar.gz 1.9 MB With provenance Details for dftax-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dftax 0.10.0
File Interpreter ABI Platform Actions
dftax-0.10.0-py3-none-any.whl Python 3 none any Details for dftax-0.10.0-py3-none-any.whl

Total release size: 3.5 MB

Release files / dftax-0.10.0.tar.gz

Download URL dftax-0.10.0.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
1c78cbfdcff221a0392290f8e3ad94914c6c3ecfde5f29440c6b676ec4c2c72c
BLAKE2b-256 checksum
How to use checksums
5caa66cddcaeb57369b3ea3995a91d0907b23691221561c174f10c77a1ad21df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / dftax-0.10.0-py3-none-any.whl

Download URL dftax-0.10.0-py3-none-any.whl
Size 1.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
1e8fde0977321e92b73c7ca6582d51d861d8a7e0a3d7042ca1627b7d89c56513
BLAKE2b-256 checksum
How to use checksums
14edc413ddffc90f22b21637212b544c2ab3dd6b627b73128db0e976d99438ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for dftax 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dftax-0.10.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page