Python API#

Python API for the DFT-D3 dispersion model

Library interface#

Wrapper around the C-API of the s-dftd3 shared library. It provides the definition the basic interface to the library for most further integration in other Python frameworks.

The classes defined here allow a more Pythonic usage of the API object provided by the library in actual workflows than the low-level access provided in the CFFI generated wrappers.

Structure#

class dftd3.interface.Structure(numbers: ndarray, positions: ndarray, lattice: ndarray | None = None, periodic: ndarray | None = None)[source]#

Represents a wrapped structure object in s-dftd3. The molecular structure data object has a fixed number of atoms and immutable atomic identifiers

Example

>>> from dftd3.interface import Structure
>>> import numpy as np
>>> mol = Structure(
...     positions=np.array([
...         [+0.00000000000000, +0.00000000000000, -0.73578586109551],
...         [+1.44183152868459, +0.00000000000000, +0.36789293054775],
...         [-1.44183152868459, +0.00000000000000, +0.36789293054775],
...     ]),
...     numbers = np.array([8, 1, 1]),
... )
...
>>> len(mol)
3
Raises:

ValueError – on invalid input, like incorrect shape / type of the passed arrays

update(positions: ndarray, lattice: ndarray | None = None) None[source]#

Update coordinates and lattice parameters, both provided in atomic units (Bohr). The lattice update is optional also for periodic structures.

Generally, only the cartesian coordinates and the lattice parameters can be updated, every other modification, boundary condition, atomic types or number of atoms requires the complete reconstruction of the object.

Raises:

ValueError – on invalid input, like incorrect shape / type of the passed arrays

DispersionModel#

class dftd3.interface.DispersionModel(numbers: ndarray, positions: ndarray, lattice: ndarray | None = None, periodic: ndarray | None = None)[source]#

Contains the required information to evaluate all dispersion related properties, like C6 coefficients. It also manages an instance of the geometry it was constructed for to ensure that the dispersion model is always used with the correct structure input.

get_dispersion(param: DampingParam, grad: bool) dict[source]#

Perform actual evaluation of the dispersion correction

get_hessian(param: DampingParam) dict[source]#

Evaluate the analytical second derivatives of the dispersion energy with respect to the nuclear coordinates.

The hessian is returned as a symmetric 3*n by 3*n matrix in Hartree per Bohr squared, using the index convention 3*i + c for the Cartesian component c of atom i.

get_pairwise_dispersion(param: DampingParam) dict[source]#

Evaluate pairwise representation of the dispersion energy

set_ewald_summation(rank: int = 0, tolerance: float = 0.0, kcut: float = 0.0, mesh: int = 0) None[source]#

Evaluate the two-body dispersion energy by summation over the reciprocal lattice, which removes the truncation error of the real space summation.

Requires three-dimensional periodic boundary conditions and a damping function with a known reciprocal space representation, currently the rational and the zero damping function. The two-body realspace cutoff is ignored once this is enabled.

Non-positive arguments select the respective default, a vanishing rank derives the rank of the expansion from the tolerance and a vanishing reciprocal cutoff derives it from the damping radii.

The mesh selects how the reciprocal space sum is evaluated. Zero derives a particle mesh from the reciprocal cutoff, which scales as O(N log N) and is the default. A positive value interpolates the structure factors on a mesh of that many points per direction, rounded up to a power of two, and a negative value sums over the reciprocal lattice directly, which is exact but scales quadratically with the number of atoms.

set_ghost_atoms(ghost_atoms) None[source]#

Disable dispersion contributions from selected atoms.

set_realspace_cutoff(disp2: float, disp3: float, cn: float, width2: float = 0.0, width3: float = 0.0)[source]#

Set realspace cutoff for evaluation of interactions

set_work_partition(part: int, nparts: int) None[source]#

Assign an externally managed part of the interaction loops to this model.

Parts are zero based, summing the results of all parts reproduces the complete calculation. Structure dependent quantities are evaluated for the full system on every part, only the pairwise, three-body and reciprocal space loops are partitioned.

The MPI aware entry points of the C API are not bound here, binding a communicator would make mpi4py a dependency. Distribute the parts yourself and reduce the results.

DampingParam#

class dftd3.interface.DampingParam(**kwargs)[source]#

Abstract base class for damping parameters, representing a parametrization of a DFT-D3 method.

The damping parameters contained in the object are immutable. To change the parametrization, a new object must be created. Furthermore, the object is opaque to the user and the contained data cannot be accessed directly.

There are two main ways provided to generate a new damping parameter object:

  1. a method name is passed to the constructor, the library will load the required data from the s-dftd3 shared library.

  2. all required parameters are passed to the constructor and the library will generate an object from the given parameters.

Note

Mixing of the two methods is not allowed to avoid partial initialization of any created objects. Users who need full control over the creation of the object should use the second method.

RationalDampingParam#

class dftd3.interface.RationalDampingParam(**kwargs)[source]#

Rational damping function for DFT-D3. The original scheme was proposed by Becke and Johnson[1][2][3] and implemented in a slightly adjusted form using only the C8/C6 ratio in the critical for DFT-D3.[4] The rational damping scheme has the advantage of damping the dispersion energy to finite value, rather than removing it at short distances.

Note

The zero damping function is retained for the three-body contributions from the ATM term.

ZeroDampingParam#

class dftd3.interface.ZeroDampingParam(**kwargs)[source]#

Original DFT-D3 damping function,[5] based on a variant proposed by Chai and Head-Gordon.[6] Since it is damping the dispersion energy to zero at short distances it is usually called zero damping scheme for simplicity. However, due to this short-range limit of the dispersion energy a repulsive contribution to the gradient can arise, which is considered artificial.[4]

ModifiedRationalDampingParam#

class dftd3.interface.ModifiedRationalDampingParam(**kwargs)[source]#

Modified version of the rational damping parameters. The functional form of the damping function is unmodified with respect to the original rational damping scheme. However, for a number of functionals new parameters were introduced.:footcite:smith2016

This constructor allows to automatically load the reparameterized damping function from the library rather than the original one. Providing a full parameter set is functionally equivalent to using the RationalDampingParam constructor.

ModifiedZeroDampingParam#

class dftd3.interface.ModifiedZeroDampingParam(**kwargs)[source]#

Modified zero damping function for DFT-D3.[7] This scheme adds an additional offset parameter to the zero damping scheme of the original DFT-D3.

Note

This damping function is identical to zero damping for bet=0.0.

OptimizedPowerDampingParam#

class dftd3.interface.OptimizedPowerDampingParam(**kwargs)[source]#

Optimized power version of the rational damping parameters.[8] The functional form of the damping function is modified by adding an additional zero-damping like power function.

This constructor allows to automatically load the reparameterized damping function from the library rather than the original one. Providing the parameter bet=0 is equivalent to using rational the RationalDampingParam constructor.

CSODampingParam#

class dftd3.interface.CSODampingParam(**kwargs)[source]#

CSO (C6-scaled only) damping function.[9] Reformulation of the D3(Becke-Johnson) dispersion correction using only C6 dispersion coefficients with a sigmoidal interpolation function.

This constructor allows to automatically load the parameterized damping function from the library. Only eight functionals are parametrized with this scheme.

ZDampingParam#

class dftd3.interface.ZDampingParam(**kwargs)[source]#

Z damping function for DFT-D3, based on the atomic-number damping form proposed for XDM(Z).

No dedicated D3(Z) parameters are available; the internal parameter loader uses XDM(Z) values for the supported functionals.

GeometricCounterpoise#

class dftd3.interface.GeometricCounterpoise(numbers: ndarray, positions: ndarray, lattice: ndarray | None = None, periodic: ndarray | None = None, method: str | None = None, basis: str | None = None)[source]#

Contains the required information to evaluate the counterpoise correction for a given geometry. The counterpoise correction is a method to correct the interaction energy in a supermolecular calculation for the basis set superposition error (BSSE).

get_counterpoise(grad: bool) dict[source]#

Evaluate the counterpoise corrected interaction energy

get_hessian() dict[source]#

Evaluate the analytical second derivatives of the counterpoise energy with respect to the nuclear coordinates.

The hessian is returned as a symmetric 3*n by 3*n matrix in Hartree per Bohr squared, using the index convention 3*i + c for the Cartesian component c of atom i.

set_realspace_cutoff(bas: float, srb: float)[source]#

Set realspace cutoff for evaluation of interactions

set_work_partition(part: int, nparts: int) None[source]#

Assign an externally managed part of the interaction loops to these parameters.

Parts are zero based, summing the results of all parts reproduces the complete calculation.

The MPI aware entry points of the C API are not bound here, binding a communicator would make mpi4py a dependency. Distribute the parts yourself and reduce the results.

QCSchema support#

Note

For more information on using the DFT-D3 with QCSchema input see dftd3.qcschema.

ASE support#

Note

For more information on using the DFT-D3 as ASE calculator see dftd3.ase.

PySCF support#

Note

For more information on integrating DFT-D3 with PySCF see dftd3.pyscf.

Literature#