Dispersion Methods: Base#

Base classes and interfaces for dispersion terms.

class tad_dftd4.dispersion.base.Disp(model='d4', model_kwargs=None, cn_fn=None, cn_fn_kwargs=None, *, device=None, dtype=None)[source]#

Base class for DFT-D dispersion calculations.

Parameters:
calculate(numbers, positions, charge, param, *, cutoff=None, q=None, rcov=None, r4r2=None, rvdw=None)[source]#

Evaluate DFT-D4 dispersion energy for a (batch of) molecule(s).

Parameters:
  • numbers (Tensor) – Atomic numbers for all atoms in the system of shape (..., nat).

  • positions (Tensor) – Cartesian coordinates of all atoms (shape: (..., nat, 3)).

  • charge (Tensor) – Total charge of the system.

  • param (Param) – DFT-D4 damping parameters.

  • model (D4Model | D4SModel | None, optional) – The DFT-D4 dispersion model for the evaluation of the C6 coefficients. Defaults to None, which creates tad_dftd4.model.d4.D4Model.

  • rcov (Tensor | None, optional) – Covalent radii of the atoms in the system. Accepted for backwards compatibility, but the coordination number function now handles radii internally.

  • r4r2 (Tensor | None, optional) – r⁴ over r² expectation values of the atoms in the system. Defaults to None, i.e., default values are used.

  • q (Tensor | None, optional) – Atomic partial charges. Defaults to None, i.e., EEQ charges are calculated using the total charge.

  • cutoff (Cutoff | None, optional) – Collection of real-space cutoffs. Defaults to None, i.e., tad_dftd4.cutoff.Cutoff is initialized with its defaults.

  • counting_function (CountingFunction, optional) – Counting function used for the DFT-D4 coordination number. Defaults to the error function counting function tad_mctc.ncoord.count.erf_count().

  • damping_function (DampingFunction, optional) – Damping function to evaluate distance dependent contributions. Defaults to the Becke-Johnson rational damping function tad_dftd4.damping.rational.rational_damping().

Returns:

Atom-resolved DFT-D4 dispersion energy.

Return type:

Tensor

Raises:
  • ValueError – Shape inconsistencies between numbers, positions, r4r2.

  • RuntimeError – If atomic charges are explicitly provided, but no term requires them.

Parameters:
get_model(numbers)[source]#

Get the DFT-D4 model for the given atomic numbers.

Parameters:

numbers (Tensor) – Atomic numbers of the atoms in the system.

Returns:

The DFT-D4 model initialized with the atomic numbers.

Return type:

ModelInst

Parameters:

numbers (Tensor)

TERMS: ClassVar[list[tuple[type[DispTerm], dict[str, Any] | None]]] = []#

List of dispersion terms to be registered in the constructor.

cn_fn: CNFunc#

Coordination number.

cn_fn_kwargs: dict[str, Any]#

Keyword arguments for the coordination number function.

terms: list[DispTerm]#

List of dispersion terms for which the calculation is performed.

class tad_dftd4.dispersion.base.DispTerm(damping_fn, charge_dependent, *, device=None, dtype=None)[source]#

Base class for all dispersion terms.

Parameters:
  • damping_fn (Damping) – Damping function to be used for the dispersion term.

  • charge_dependent (bool) – Whether the term is charge-dependent, i.e., requires atomic charges for the calculation.

  • device (torch.device, optional) – Device on which the term is calculated.

  • dtype (torch.dtype, optional) – Data type of the term’s tensors.

Parameters:
abstract calculate(numbers, positions, param, cn, model, q, r4r2, rvdw, cutoff)[source]#

Evaluate the energy for the dispersion term.

Parameters:
Return type:

Tensor

charge_dependent: bool#

Whether the term is charge-dependent, i.e., requires atomic charges for the calculation.

damping_fn: Damping#

Damping function to be used for the dispersion term.