Skip to content

Building a calculation¤

One builder captures every choice as a value: the system, the functional, and the grid/Coulomb/spin/mesh/dispersion specs. See All of dftax for the tour.

dftax.ks.energy.KS ¤

The Kohn-Sham total energy as a differentiable function of the density matrix.

P has shape (nspin, nao, nao): one channel holding the total density for a closed shell, α and β channels for a spin-polarized system.

__abstractclassvars__ class-attribute ¤

Build an immutable unordered collection of unique elements.

__abstractmethods__ class-attribute ¤

Build an immutable unordered collection of unique elements.

__abstractvars__ class-attribute ¤

Build an immutable unordered collection of unique elements.

__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 ¤
__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.

__init__(system: Molecule | System | object, xc: XCFunctional, *, grid: Becke | Points | tuple | None = None, coulomb: ExactSpec | DFSpec | None = None, spin: int | None = None, mesh: MeshSpec | None = None, dispersion: D3BJSpec | None = None) ¤

Build the energy functional.

Parameters:

Name Type Description Default
system Molecule | System | object

a :class:~dftax.system.molecule.Molecule, a PySCF Mole, a :class:System, or a periodic :class:~dftax.pbc.cell.Cell.

required
xc XCFunctional

the exchange-correlation functional, e.g. PBE().

required
grid Becke | Points | tuple | None

the quadrature: a :func:~dftax.grid.becke spec (the default), a (coords, weights) tuple, or a :func:~dftax.grid.points spec. A Cell takes :func:~dftax.pbc.build.uniform.

None
coulomb ExactSpec | DFSpec | None

:func:~dftax.ks.terms.df (the default) or :func:~dftax.ks.terms.exact; a :class:System defaults to exact().

None
spin int | None

number of unpaired electrons, 2S. None takes the system's value and solves a closed shell restricted; an explicit value, 0 included, solves spin-polarized.

None
mesh MeshSpec | None

a :func:~dftax.ks.shard.mesh spec to divide the quadrature and the density-fitting tensor over devices; None runs on one device.

None
dispersion D3BJSpec | None

a :func:~dftax.energy.d3.d3bj or :func:~dftax.energy.d4.d4 spec, added to the total energy.

None

Raises:

Type Description
ValueError

spin inconsistent with the number of electrons.

NotImplementedError

coulomb, mesh or dispersion with a Cell.

Example
ks = KS(mol, PBE0(), grid=becke(75, 302), coulomb=df(chunk=None))
e_xc(P: Float[Array, 'nspin nao nao']) -> Scalar ¤

Exchange-correlation energy ∫ ε_xc ρ (DFT part only).

electronic(P: Float[Array, 'nspin nao nao']) -> Scalar ¤

Electronic energy Tr(P_tot·Hcore) + E_J + a_x·E_x^exact + E_xc.

total(P: Float[Array, 'nspin nao nao']) -> Scalar ¤

Total KS energy (electronic + nuclear repulsion + dispersion).

energy_and_fock(P: Float[Array, 'nspin nao nao'], idempotent: bool = True) -> tuple[Scalar, Float[Array, 'nspin nao nao']] ¤

Total energy and Fock matrix sym(∂E/∂P) for one density, computed together at about the cost of one.

Parameters:

Name Type Description Default
P Float[Array, 'nspin nao nao']

density matrix, (nspin, nao, nao).

required
idempotent bool

whether P has integer occupations (False under smearing).

True

Returns:

Type Description
tuple[Scalar, Float[Array, 'nspin nao nao']]

(E, F), with F of the shape of P.

energy_and_grad_orbitals(Cs, idempotent: bool = True) ¤

Total energy and its gradient with respect to the occupied orbitals.

Parameters:

Name Type Description Default
Cs tuple[Array, ...]

occupied orbital coefficients per spin channel, each (nao, nocc_σ).

required
idempotent bool

as in :meth:energy_and_fock.

True

Returns:

Name Type Description
E Array

the total energy (Hartree).

grads tuple[Array, ...]

grads[σ] = ∂E/∂C_σ = 2 F_σ C_σ diag(w_σ), with w from :meth:occupations.

occupations() ¤

Occupation numbers of the occupied orbitals per channel: 2 for a closed shell, 1 per spin channel.

density(P: Float[Array, 'nspin nao nao']) -> tuple[Float[Array, ng], Float[Array, 'ng 3']] ¤

Total electron density and its gradient on the grid from P.

dftax.energy.d3.d3bj(method: str | None = None, *, atm: bool = False) -> D3BJSpec ¤

Grimme's D3 dispersion correction with Becke-Johnson damping (S. Grimme, S. Ehrlich and L. Goerigk, J. Comput. Chem. 32, 1456 (2011)).

Pass the result as KS(..., dispersion=d3bj()).

Parameters:

Name Type Description Default
method str | None

name of the damping-parameter set, e.g. "pbe0"; None takes the set of the functional the KS is built with.

None
atm bool

add the Axilrod-Teller-Muto three-body term (s9 = 1).

False

dftax.energy.d4.d4(method: str | None = None, *, atm: bool = False) -> D4Spec ¤

Grimme's charge-dependent D4 dispersion correction (E. Caldeweyher et al., J. Chem. Phys. 150, 154122 (2019)).

Pass the result as KS(..., dispersion=d4()).

Parameters:

Name Type Description Default
method str | None

name of the damping-parameter set, e.g. "pbe0"; None takes the set of the functional the KS is built with.

None
atm bool

add the Axilrod-Teller-Muto three-body term (s9 = 1). The parameter sets were fitted with it, and the reference D4 (dftd4) includes it by default; atm=False is the two-body energy.

False

dftax.system.molecule.Molecule ¤

A molecular system: atoms, geometry, charge/spin, and a basis name.

__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

__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

nelectron property ¤

Total electron count (sum of Z minus the total charge).

__init__(symbols: list[str], coords_bohr: np.ndarray, basis: str, charge: int = 0, spin: int = 0, spherical: bool = False) ¤
from_xyz(atom: str, basis: str, *, unit: str = 'angstrom', charge: int = 0, spin: int = 0, spherical: bool = False) -> Molecule classmethod ¤

Build from a PySCF-style atom string (Angstrom by default).

atom_coords() -> np.ndarray ¤

Nuclear coordinates in Bohr, shape (n_atoms, 3).

atom_charges() -> np.ndarray ¤

Nuclear charges (atomic numbers), shape (n_atoms,).

dftax.ks.energy.System ¤

A system given by its built basis, for callers that construct the basis themselves.

Attributes:

Name Type Description
basis

the orbital basis.

coords

nuclear coordinates (Bohr), (natom, 3).

charges

nuclear charges, (natom,).

nelec

number of electrons.

spin

number of unpaired electrons, 2S; the spin argument of :class:KS overrides it.

__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

spin 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

__delattr__(name) ¤
__eq__(other) ¤
__hash__() ¤
__init__(basis: BasisData, coords: Array, charges: Array, nelec: int, spin: int = 0) -> None ¤
__repr__() ¤
__setattr__(name, value) ¤