dxtb.components.dispersion.DispersionD3#
- class dxtb.components.dispersion.DispersionD3(numbers, param, charge=None, ref_charges='eeq', device=None, dtype=None)[source]#
Bases:
DispersionRepresentation of the DFT-D3(BJ) dispersion correction (
DispersionD3).Methods
Disable the cache.
Enable the cache.
Invalidate the cache to require renewed setup.
Check if the driver is set up and updated.
Returns a copy of the
TensorLikeinstance on the CPU.Obtain cache for storage of settings.
Get D3 dispersion energy.
Calculates nuclear gradient of a classical energy contribution via PyTorch's autograd engine.
Override the device of the class object.
Override the dtype of the class object.
Reset the tensor attributes of the
dxtb.components.base.Componentinstance to their original states or to specified values.Returns a copy of the
TensorLikeinstance on the specified device.Returns a copy of the
TensorLikeinstance with specified floating point type.Update the attributes of the
Componentinstance.Attributes
(..., nat)).Dispersion parameters.
Total charge of the system.
Reference charges for the dispersion model.
Specification of dtypes that the
TensorLikeobject can take.Cache for the interaction.
Whether the cache has been set up.
Shortcut for device and dtype.
The device on which the class object resides.
Floating point dtype used by class object.
Label for the classical contribution.
- Parameters:
numbers (Tensor)
param (Param)
charge (Tensor | None)
ref_charges (Literal['eeq', 'gfn2'])
device (torch.device | None)
dtype (torch.dtype | None)
- cache_is_latest(cvars, tol=None)#
Check if the driver is set up and updated.
- 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:
- get_cache(numbers, ihelp=None, **kwargs)[source]#
Obtain cache for storage of settings.
Settings can be passed as
kwargs. The available optional parameters are the same as intad_dftd3.dftd3(), i.e., “ref”, “rcov”, “rvdw”, and “r4r2”.- Return type:
DispersionD3Cache- Parameters:
numbers (Tensor) – Atomic numbers for all atoms in the system (shape:
(..., nat)).- Returns:
Cache for the D3 dispersion.
- Return type:
DispersionD3Cache
- Parameters:
numbers (Tensor)
ihelp (IndexHelper | None)
kwargs (Any)
- get_energy(positions, cache, **kwargs)[source]#
Get D3 dispersion energy.
- Return type:
- Parameters:
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).cache (ComponentCache) – Dispersion cache containing settings.
- Returns:
Atom-resolved D3 dispersion energy.
- Return type:
Tensor
- Parameters:
positions (Tensor)
cache (ComponentCache)
kwargs (Any)
- get_gradient(energy, positions, grad_outputs=None)#
Calculates nuclear gradient of a classical energy contribution via PyTorch’s autograd engine.
- Return type:
- Parameters:
energy (Tensor) – Energy that will be differentiated.
positions (Tensor) – Nuclear positions. Needs
requires_grad=True.grad_outputs (Tensor | None, optional) – Vector in the vector-Jacobian product. If
None, the vector is initialized to ones.
- Returns:
Nuclear gradient of
energy.- Return type:
Tensor
- Raises:
RuntimeError –
positionstensor does not haverequires_grad=True.- Parameters:
- 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
- reset()#
Reset the tensor attributes of the
dxtb.components.base.Componentinstance to their original states or to specified values.This method iterates through the attributes defined in
__slots__and resets any tensor attributes to a detached clone of their original state. The requires_grad status of each tensor is preserved.- Return type:
Examples
import torch from dxtb.components.base.field import ElectricField ef = ElectricField(field=torch.tensor([0.0, 0.0, 0.0])) ef.reset()
Notes
Only tensor attributes defined in
__slots__are reset. Non-tensor attributes are ignored. Attempting to reset an attribute not defined in__slots__or providing a non-tensor value in kwargs will not raise an error; the method will simply ignore these cases and proceed with the reset operation for valid tensor attributes.
- 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
TensorLikeinstance with specified floating point type. This method creates and returns a new copy of theTensorLikeinstance with the specified dtype.- Return type:
Self- Parameters:
dtype (
torch.dtype) – Floating point type.- Returns:
A copy of the
TensorLikeinstance with the specified dtype.- Return type:
- Parameters:
dtype (dtype)
Notes
If the
TensorLikeinstance has already the desired dtypeSelfwill be returned.
- update(**kwargs)#
Update the attributes of the
Componentinstance.This method updates the attributes of the
Componentinstance based on the provided keyword arguments. Only the attributes defined in__slots__can be updated.- Return type:
- Parameters:
kwargs (dict[str, Any]) – Keyword arguments where keys are attribute names and values are the new values for those attributes. Valid keys are those defined in
__slots__of this class.- Raises:
AttributeError – If any key in kwargs is not an attribute defined in
__slots__.- Parameters:
kwargs (Any)
Examples
import torch from dxtb.components.field import ElectricField ef = ElectricField(field=torch.tensor([0.0, 0.0, 0.0])) ef.update(field=torch.tensor([1.0, 0.0, 0.0]))
- 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, …]
- property cache: ComponentCache | None#
Cache for the interaction.
- charge: Tensor | None#
Total charge of the system.
- label: str#
Label for the classical contribution.
- numbers: Tensor#
(..., nat)).- Type:
Atomic numbers for all atoms in the system (shape
- param: D4Param#
Dispersion parameters.
- ref_charges: Literal['eeq', 'gfn2']#
Reference charges for the dispersion model. This is only required for charge-dependent models.
- Default:
"eeq"