Types of Calculators

Types of Calculators#

Calculators: Types#

All calculator types for the extended tight-binding models (xTB).

Besides the basic energy calculator, different calculator types utilize different methods for differentiation, i.e., analytical, numerical, or automatic differentiation (autograd). The central Calculator class inherits from all types, i.e., it provides the energy and properties via automatic, analytical, and numerical differentiation.

The available methods of the specific types can be checked with:

from dxtb.calculators import AutogradCalculator

print(AutogradCalculator.implemented_properties)

Since automatic differentiation is the main mode for derivative calculations, all methods are available. The same is true for numerical differentiation, which can be used for testing and debugging purposes. Only a few properties are implemented with analytical differentiation. The syntax for calling the methods is as follows:

  • Automatic differentiation: calc.forces(positions)

  • Analytical differentiation: calc.forces_analytical(positions)

  • Numerical differentiation: calc.forces_numerical(positions)

Calculators: AD#

Using the get_ methods will automatically select automatic differentiation when multiple methods are available.

Note that most properties require Jacobians instead of vector-Jacobian products (VJP), which can be calculated row-by-row using the standard torch.autograd.grad() function with unit vectors in the VJP (see here) or using torch.func’s function transforms (e.g., torch.func.jacrev()). The selection can be made with the use_functorch keyword argument.

While using functorch is faster, it is sometimes less stable and does not work if we need to differentiate for multiple properties at once (e.g., Hessian and dipole moment for IR spectra). Hence, the default is use_functorch=False.