dxtb.calculators.AnalyticalCalculator#
- class dxtb.calculators.AnalyticalCalculator(numbers, par, *, classical=None, interaction=None, opts=None, cache=None, device=None, dtype=None, **kwargs)[source]#
Bases:
EnergyCalculatorParametrized calculator defining the extended tight-binding model.
This class provides analytical formulas and/or gradients for certain properties.
Instantiate the Calculator object with the following parameters:
- Parameters:
numbers (Tensor) – Atomic numbers for all atoms in the system (shape:
(..., nat)).par (Param) – Representation of an extended tight-binding model (full xTB parametrization). Decides energy contributions.
classical (Sequence[Classical] | None, optional) – Additional classical contributions. Defaults to
None.interaction (Sequence[Interaction] | None, optional) – Additional self-consistent contributions (interactions). Defaults to
None.opts (dict[str, Any] | None, optional) – Calculator options. If
None(default) is given, default options are used automatically.device (torch.device | None, optional) – Device to store the tensor on. If
None(default), the default device is used.dtype (torch.dtype | None, optional) – Data type of the tensor. If
None(default), the data type is inferred.kwargs (Any) – Additional keyword arguments. -
auto_int_level: Automatically set the integral level based onthe parametrization. Defaults to
True. This should only be turned off for testing purposes.timer: Enable the timer. Defaults toFalse. The global timer can also be enabled by setting the environment variableDXTB_TIMERto1.
- Parameters:
numbers (Tensor)
par (Param | ParamModule)
classical (list[Classical] | tuple[Classical] | Classical | None)
interaction (list[Interaction] | tuple[Interaction] | Interaction | None)
cache (CalculatorCache | None)
device (torch.device | None)
dtype (torch.dtype | None)
kwargs (Any)
Methods
Calculate the (Wiberg) bond order matrix.
Calculate the requested properties.
Returns a copy of the
TensorLikeinstance on the CPU.Analytically calculate the electric dipole moment \(\mu\).
Calculate the total energy \(E\) of the system.
Calculate the nuclear forces \(f\) via AD.
Get orbital-resolved Mulliken charges.
Calculate the nuclear forces \(f\) via AD.
Get the named property.
Override the device of the class object.
Override the dtype of the class object.
Reset the calculator to its initial state.
Entry point for performing single point calculations.
Returns a copy of the
TensorLikeinstance on the specified device.Returns a copy of the class instance with specified floating point type.
Attributes
(..., nat)).Cache for storing multiple calculation results.
Calculator configuration.
Classical contributions.
Interactions to minimize in self-consistent iterations.
Integrals for the extended tight-binding model.
Helper class for indexing.
Specification of dtypes that the
TensorLikeobject can take.Shortcut for device and dtype.
The device on which the class object resides.
Floating point dtype used by class object.
Names of implemented methods of the Calculator.
Results container.
- bond_orders(positions, chrg=0, spin=None, **kwargs)#
Calculate the (Wiberg) bond order matrix.
- Return type:
- Parameters:
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).chrg (Tensor | float | int, optional) – Total charge. Defaults to 0.
spin (Tensor | float | int, optional) – Number of unpaired electrons. Defaults to
None.
- Returns:
Bond order matrix.
- Return type:
Tensor
- Parameters:
- calculate(properties, positions, chrg=0, spin=None, **kwargs)[source]#
Calculate the requested properties. This is more of a dispatcher method that calls the appropriate methods of the Calculator.
- Return type:
- Parameters:
properties (list[str]) – List of properties to calculate.
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).chrg (Tensor | float | int, optional) – Total charge. Defaults to 0.
spin (Tensor | float | int, optional) – Number of unpaired electrons. Defaults to
None.
- Parameters:
- cpu()#
Returns a copy of the
TensorLikeinstance on the CPU.This method creates and returns a new copy of the
TensorLikeinstance on the CPU.- Return type:
Self- Returns:
A copy of the
TensorLikeinstance placed on the CPU.- Return type:
- dipole_analytical(positions, chrg=0, spin=None, *_, **kwargs)[source]#
Analytically calculate the electric dipole moment \(\mu\). :rtype:
Tensor\[\mu = \dfrac{\partial E}{\partial F}\]- Parameters:
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).chrg (Tensor | float | int, optional) – Total charge. Defaults to 0.
spin (Tensor | float | int, optional) – Number of unpaired electrons. Defaults to
None.
- Returns:
Electric dipole moment of shape (…, 3).
- Return type:
Tensor
- Parameters:
- energy(positions, chrg=0, spin=None, **kwargs)#
Calculate the total energy \(E\) of the system.
- Return type:
- Parameters:
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).chrg (Tensor | float | int, optional) – Total charge. Defaults to 0.
spin (Tensor | float | int, optional) – Number of unpaired electrons. Defaults to
None.
- Returns:
Total energy of the system (scalar value).
- Return type:
Tensor
- Parameters:
- forces_analytical(positions, chrg=0, spin=None, **kwargs)[source]#
Calculate the nuclear forces \(f\) via AD. :rtype:
Tensor\[f = -\dfrac{\partial E}{\partial R}\]One can calculate the Jacobian either row-by-row using the standard
torch.autograd.grad()with unit vectors in the VJP or usingtorch.func’s function transforms (e.g.,torch.func.jacrev()).Note
Using
torch.func’s function transforms can apparently be only used once. Hence, for example, the Hessian and the dipole derivatives cannot be both calculated with functorch.- Parameters:
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).chrg (Tensor | float | int, optional) – Total charge. Defaults to 0.
spin (Tensor | float | int, optional) – Number of unpaired electrons. Defaults to
None.
- Returns:
Atomic forces of shape
(..., nat, 3).- Return type:
Tensor
- Parameters:
- get_bond_orders(positions, chrg=0, spin=None, **kwargs)#
- get_charges(positions, chrg=0, spin=None, **kwargs)#
Get orbital-resolved Mulliken charges.
- Return type:
- Parameters:
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).chrg (Tensor | float | int, optional) – Total charge. Defaults to 0.
spin (Tensor | float | int | None, optional) – Number of unpaired electrons. Defaults to 0.
**kwargs (Any) – Additional keyword arguments.
- Returns:
Orbital-resolved Mulliken charges of shape
(..., nao).- Return type:
Tensor
- Parameters:
Example
import torch import dxtb dd = {"dtype": torch.double, "device": torch.device("cpu")} numbers = torch.tensor([3, 1], device=dd["device"]) positions = torch.tensor([[0.0, 0.0, 0.0], [0.0, 0.0, 1.5]], **dd) calc = dxtb.calculators.GFN1Calculator(numbers, **dd) charges_nao = calc.get_charges(positions) print(f"Expected shape: {torch.Size([6])}") print(f"Actual shape : {charges_nao.shape}") charges_nat = calc.ihelp.reduce_orbital_to_atom(charges_nao) print(f"Expected shape: {torch.Size([2])}") print(f"Actual shape : {charges_nat.shape}")
- get_coefficients(positions, chrg=0, spin=None, **kwargs)#
- get_density(positions, chrg=0, spin=None, **kwargs)#
- get_dipole(positions, chrg=0, spin=None, **kwargs)#
- get_dipole_deriv(positions, chrg=0, spin=None, **kwargs)#
- get_dipole_derivatives(positions, chrg=0, spin=None, **kwargs)#
- get_dipole_moment(positions, chrg=0, spin=None, **kwargs)#
- get_energy(positions, chrg=0, spin=None, **kwargs)#
- get_forces(positions, chrg=0, spin=None, grad_mode='autograd', **kwargs)#
Calculate the nuclear forces \(f\) via AD. :rtype:
Tensor\[f = -\dfrac{\partial E}{\partial R}\]One can calculate the Jacobian either row-by-row using the standard
torch.autograd.grad()with unit vectors in the VJP or usingtorch.func’s function transforms (e.g.,torch.func.jacrev()).Note
Using
torch.func’s function transforms can apparently be only used once. Hence, for example, the Hessian and the dipole derivatives cannot be both calculated with functorch.- Parameters:
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).chrg (Tensor | float | int, optional) – Total charge. Defaults to 0.
spin (Tensor | float | int, optional) – Number of unpaired electrons. Defaults to
None.grad_mode (Literal, optional) – Specify the mode for gradient calculation. Possible options are:
“autograd” (default): Use PyTorch’s
torch.autograd.grad().“backward”: Use PyTorch’s backward function.
“functorch”: Use functorch’s jacrev.
“row”: Use PyTorch’s autograd row-by-row (unnecessary here).
- Returns:
Atomic forces of shape
(..., nat, 3).- Return type:
Tensor
- Parameters:
- get_frequencies(positions, chrg=0, spin=None, **kwargs)#
- get_hessian(positions, chrg=0, spin=None, **kwargs)#
- get_hyperpolarizability(positions, chrg=0, spin=None, **kwargs)#
- get_ir(positions, chrg=0, spin=None, **kwargs)#
- get_ir_intensities(positions, chrg=0, spin=None, **kwargs)#
- get_iterations(positions, chrg=0, spin=None, **kwargs)#
- get_mo_energies(positions, chrg=0, spin=None, **kwargs)#
- get_mulliken_charges(positions, chrg=0, spin=None, **kwargs)#
- get_normal_modes(positions, chrg=0, spin=None, **kwargs)#
- get_occupation(positions, chrg=0, spin=None, **kwargs)#
- get_pol_deriv(positions, chrg=0, spin=None, **kwargs)#
- get_polarizability(positions, chrg=0, spin=None, **kwargs)#
- get_polarizability_derivatives(positions, chrg=0, spin=None, **kwargs)#
- get_potential(positions, chrg=0, spin=None, **kwargs)#
- get_potential_energy(positions, chrg=0, spin=None, **kwargs)#
- get_property(name, positions, chrg=0, spin=None, allow_calculation=True, return_clone=False, **kwargs)#
Get the named property.
- Return type:
Tensor|VibResult|IRResult|RamanResult|None- Parameters:
name (str) – Name of the property to get.
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).chrg (Tensor | float | int, optional) – Total charge. Defaults to 0.
spin (Tensor | float | int, optional) – Number of unpaired electrons. Defaults to
None.allow_calculation (bool, optional) – If the property is not present, allow its calculation. This does not check if we even allow caching or if the inputs are the same. Use with caution. Defaults to
True.return_clone (bool, optional) – If True, return a clone of the property. Defaults to
False.
- Parameters:
- get_raman(positions, chrg=0, spin=None, **kwargs)#
- get_raman_depol(positions, chrg=0, spin=None, **kwargs)#
- get_raman_intensities(positions, chrg=0, spin=None, **kwargs)#
- get_vibration(positions, chrg=0, spin=None, **kwargs)#
- override_device(device)#
Override the device of the class object. :rtype:
NoneWarning
This does not change the device of the underlying tensors. It only changes the device of the class object. Use with caution.
- Parameters:
device (
torch.device) – Device to override the current device.- Parameters:
device (device)
- Return type:
None
- override_dtype(dtype)#
Override the dtype of the class object. :rtype:
NoneWarning
This does not change the dtype of the underlying tensors. It only changes the dtype of the class object. Use with caution.
- Parameters:
dtype (
torch.dtype) – Floating point dtype to override the current dtype.- Parameters:
dtype (dtype)
- Return type:
None
- singlepoint(positions, chrg=0, spin=None, **kwargs)#
Entry point for performing single point calculations.
- Parameters:
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).chrg (Tensor | float | int, optional) – Total charge. Defaults to 0 (also for batched calculations).
spin (Tensor | float | int, optional) – Number of unpaired electrons. Defaults to 0.
- Parameters:
- to(device=None, dtype=None)#
Returns a copy of the
TensorLikeinstance on the specified device.This method creates and returns a new copy of the
TensorLikeinstance on the specified device “device”.- Return type:
Self- Parameters:
device (
torch.device) – Device to which all associated tensors should be moved.- Returns:
A copy of the
TensorLikeinstance placed on the specified device.- Return type:
- Parameters:
Notes
If the
TensorLikeinstance is already on the desired deviceselfwill be returned.
- type(dtype)#
Returns a copy of the class instance with specified floating point type.
This method overrides the usual approach because the
dxtb.Calculator’s arguments and slots differ significantly. Hence, it is not practical to instantiate a new copy.- Return type:
Self- Parameters:
dtype (torch.dtype) – Floating point type.
- Returns:
A copy of the class instance with the specified dtype.
- Return type:
Self
- Raises:
RuntimeError – If the
__slots__attribute is not set in the class.DtypeError – If the specified dtype is not allowed.
- Parameters:
dtype (dtype)
- property allowed_dtypes: tuple[dtype, ...]#
Specification of dtypes that the
TensorLikeobject can take. Defaults to float types and must be overridden by subclass if float are not allowed. The IndexHelper is an example that should only allow integers.- Returns:
Collection of allowed dtypes the
TensorLikeobject can take.- Return type:
tuple[torch.dtype, …]
- cache: CalculatorCache#
Cache for storing multiple calculation results.
- classicals: ClassicalList#
Classical contributions.
- ihelp: IndexHelper#
Helper class for indexing.
- implemented_properties: list[str] = ['bond_orders', 'energy', 'coefficients', 'charges', 'density', 'iterations', 'mo_energies', 'occupation', 'potential', 'forces', 'dipole']#
Names of implemented methods of the Calculator.
- integrals: Integrals#
Integrals for the extended tight-binding model.
- interactions: InteractionList#
Interactions to minimize in self-consistent iterations.
- numbers: Tensor#
(..., nat)).- Type:
Atomic numbers for all atoms in the system (shape
- opts: Config#
Calculator configuration.
- results: dict[str, Any]#
Results container.