dxtb.components.base.InteractionList#
- class dxtb.components.base.InteractionList(*components, device=None, dtype=None)[source]#
Bases:
ComponentList[Interaction]List of interactions.
Instantiate a collection of tight-binding components.
- Parameters:
compontents (tuple[Component | None, ...] | list[Component | None]) – List or tuple of compontent classes.
components (list[C])
device (torch.device | None)
dtype (torch.dtype | None)
Note
Duplicate components will be removed automatically.
Methods
Returns a copy of the
TensorLikeinstance on the CPU.Create restart data for individual interactions.
Compute the energy for a list of interactions.
Compute the energy for a list of interactions.
Calculate gradient for a list of interactions.
Obtain an component from the list of components by its class name.
Compute the potential for a list of interactions.
Override the device of the class object.
Override the dtype of the class object.
Reset the attributes of an component object within the list.
Reset tensor attributes to a detached clone of the current state.
Reset the attributes of the 'reset_d4sc' object within the list.
Reset the attributes of the 'reset_efield' object within the list.
Reset the attributes of the 'reset_efield_grad' object within the list.
Reset the attributes of the 'reset_es2' object within the list.
Reset the attributes of the 'reset_es3' object within the list.
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 an interaction object within the list.
Update the attribute of the 'd4sc' object based on the provided arguments in the keyword arguments.
Update the attribute of the 'efield' object based on the provided arguments in the keyword arguments.
Update the attribute of the 'efield_grad' object based on the provided arguments in the keyword arguments.
Update the attribute of the 'es2' object based on the provided arguments in the keyword arguments.
Update the attribute of the 'es3' object based on the provided arguments in the keyword arguments.
Attributes
List of tight-binding component instances.
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.
Alphabetically sorted list of all components labels.
- cpu()#
Returns a copy of the
TensorLikeinstance on the CPU.This method creates and returns a new copy of the
TensorLikeinstance on the CPU.- Returns:
A copy of the
TensorLikeinstance placed on the CPU.- Return type:
- get_cache(numbers, positions, ihelp)[source]#
Create restart data for individual interactions.
- Parameters:
numbers (Tensor) – Atomic numbers for all atoms in the system (shape:
(..., nat)).positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).ihelp (IndexHelper) – Index mapping for the basis set.
- Returns:
Restart data for the interactions.
- Return type:
- get_energy(charges, cache, ihelp)[source]#
Compute the energy for a list of interactions.
- Parameters:
charges (Charges | Tensor) – Collection of charges. Monopolar partial charges are orbital-resolved.
ihelp (IndexHelper) – Index mapping for the basis set.
cache (InteractionListCache) – Restart data for the interaction.
- Returns:
Atom-resolved energy vector for orbital partial charges.
- Return type:
Tensor
- get_energy_as_dict(charges, cache, ihelp)[source]#
Compute the energy for a list of interactions.
- Parameters:
charges (Charges) – Collection of charges. Monopolar partial charges are orbital-resolved.
ihelp (IndexHelper) – Index mapping for the basis set.
cache (InteractionListCache) – Restart data for the interaction.
- Returns:
Energy vector for each orbital partial charge.
- Return type:
Tensor
- get_gradient(charges, positions, cache, ihelp, grad_outputs=None, retain_graph=True, create_graph=None)[source]#
Calculate gradient for a list of interactions.
- Parameters:
charges (Charges) – Collection of charges. Monopolar partial charges are orbital-resolved.
positions (Tensor) – Cartesian coordinates of all atoms (shape:
(..., nat, 3)).cache (InteractionListCache) – Restart data for the interaction.
ihelp (IndexHelper) – Index mapping for the basis set.
grad_outputs (list[Tensor] | tuple[Tensor, ...] | Tensor | None)
retain_graph (bool | None)
create_graph (bool | None)
- Returns:
Nuclear gradient of all interactions.
- Return type:
Tensor
- get_interaction(name)[source]#
Obtain an component from the list of components by its class name.
- Parameters:
name (str) – Name of the component.
- Returns:
Instance of the component as present in the InteractionList.
- Return type:
- Raises:
ValueError – Unknown component name given or component is not in the list.
- get_potential(cache, charges, ihelp)[source]#
Compute the potential for a list of interactions.
- Parameters:
cache (InteractionListCache) – Restart data for the interactions.
charges (Charges) – Collection of charges. Monopolar partial charges are orbital-resolved.
ihelp (IndexHelper) – Index mapping for the basis set.
- Returns:
Potential vector for each orbital partial charge.
- Return type:
Tensor
- override_device(device)#
Override the device of the class object.
Warning
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.- Return type:
None
- override_dtype(dtype)#
Override the dtype of the class object.
Warning
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.- Return type:
None
- reset(name)#
Reset the attributes of an component object within the list.
This method iterates through the components in the list, finds the one with the matching label, and resets any tensor attributes to a detached clone of their original state. The requires_grad status of each tensor is preserved.
- Parameters:
name (str) – The label of the component object to be updated.
- Returns:
The component object with the resetted attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
Examples
import torch from dxtb._src.components.interactions import InteractionList from dxtb._src.components.interactions.external import field as efield ef = efield.new_efield(torch.tensor([0.0, 0.0, 0.0])) ilist = InteractionList(ef) ilist.reset(efield.LABEL_EFIELD)
- reset_all()#
Reset tensor attributes to a detached clone of the current state.
- Return type:
None
- reset_d4sc()[source]#
Reset the attributes of the ‘reset_d4sc’ object within the list.
This method resets any tensor attributes to a detached clone of their original state. The requires_grad status of each tensor is preserved.
- Returns:
The component object with the resetted attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
- reset_efield()[source]#
Reset the attributes of the ‘reset_efield’ object within the list.
This method resets any tensor attributes to a detached clone of their original state. The requires_grad status of each tensor is preserved.
- Returns:
The component object with the resetted attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
- reset_efield_grad()[source]#
Reset the attributes of the ‘reset_efield_grad’ object within the list.
This method resets any tensor attributes to a detached clone of their original state. The requires_grad status of each tensor is preserved.
- Returns:
The component object with the resetted attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
- reset_es2()[source]#
Reset the attributes of the ‘reset_es2’ object within the list.
This method resets any tensor attributes to a detached clone of their original state. The requires_grad status of each tensor is preserved.
- Returns:
The component object with the resetted attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
- reset_es3()[source]#
Reset the attributes of the ‘reset_es3’ object within the list.
This method resets any tensor attributes to a detached clone of their original state. The requires_grad status of each tensor is preserved.
- Returns:
The component object with the resetted attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
- 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”.- Parameters:
device (
torch.device) – Device to which all associated tensors should be moved.dtype (dtype | None)
- Returns:
A copy of the
TensorLikeinstance placed on the specified device.- Return type:
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.- Parameters:
dtype (
torch.dtype) – Floating point type.- Returns:
A copy of the
TensorLikeinstance with the specified dtype.- Return type:
Notes
If the
TensorLikeinstance has already the desired dtypeSelfwill be returned.
- update(name, **kwargs)#
Update the attributes of an interaction object within the list.
This method iterates through the interactions in the list, finds the one with the matching label, and updates its attributes based on the provided arguments.
- Parameters:
- Raises:
ValueError – If no interaction with the given label is found in the list.
- Return type:
C
Examples
import torch from dxtb._src.components.interactions import InteractionList from dxtb._src.components.interactions.field import efield field_vector = torch.tensor([0.0, 0.0, 0.0]) ef = efield.new_efield(field_vector) ilist = InteractionList(ef) new_field_vector = torch.tensor([1.0, 0.0, 0.0]) ilist.update(efield.LABEL_EFIELD, field=new_field_vector)
- update_d4sc(**kwargs)[source]#
Update the attribute of the ‘d4sc’ object based on the provided arguments in the keyword arguments.
- Parameters:
kwargs (dict) – Keyword arguments containing the attributes and their new values to be updated in the component object.
- Returns:
The component object with the updated attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
Examples
See ComponentList.update.
- update_efield(*, field=None)[source]#
Update the attribute of the ‘efield’ object based on the provided arguments in the keyword arguments.
- Parameters:
- Returns:
The component object with the updated attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
Examples
See ComponentList.update.
- update_efield_grad(*, field_grad=None)[source]#
Update the attribute of the ‘efield_grad’ object based on the provided arguments in the keyword arguments.
- Parameters:
- Returns:
The component object with the updated attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
Examples
See ComponentList.update.
- update_es2(**kwargs)[source]#
Update the attribute of the ‘es2’ object based on the provided arguments in the keyword arguments.
- Parameters:
kwargs (dict) – Keyword arguments containing the attributes and their new values to be updated in the component object.
- Returns:
The component object with the updated attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
Examples
See ComponentList.update.
- update_es3(**kwargs)[source]#
Update the attribute of the ‘es3’ object based on the provided arguments in the keyword arguments.
- Parameters:
kwargs (dict) – Keyword arguments containing the attributes and their new values to be updated in the component object.
- Returns:
The component object with the updated attributes.
- Return type:
- Raises:
ValueError – If no component with the given label is found in the list.
Examples
See ComponentList.update.
- 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, …]