dxtb.IndexHelper#
- class dxtb.IndexHelper(unique_angular, angular, atom_to_unique, ushells_to_unique, ushells_per_unique, shells_to_ushell, shells_per_atom, shell_index, shells_to_atom, orbitals_per_shell, orbital_index, orbitals_to_shell, batch_mode, device=None, dtype=torch.int64, *, store=None, **_)[source]#
Bases:
TensorLikeIndex helper for basis set.
Methods
Returns a copy of the
TensorLikeinstance on the CPU.Construct an index helper instance from atomic numbers and a parametrization.
Construct an index helper instance from atomic numbers and their angular momenta.
Get orbital indices belong to given shell.
Get shell indices belong to given atom.
Mapping of atom index to orbital index, i.e., return indices of orbitals belonging to given atom.
Override the device of the class object.
Override the dtype of the class object.
Reduce orbital-resolved tensor to atom-resolved tensor.
Reduce orbital-resolved tensor to shell-resolved tensor.
Reduce shell-resolved tensor to atom-resolved tensor.
Restore the original index helper after culling.
Spread atom-resolved tensor to orbital-resolved tensor.
Spread atom-resolved tensor to orbital-resolved tensor.
Spread atom-resolved tensor to shell-resolved tensor.
Spread shell-resolved tensor to orbital-resolved tensor.
Spread shell-resolved tensor to orbital-resolved tensor.
Spread unique shell tensor to orbital-resolved tensor.
Spread unique shell tensor to orbital-resolved tensor.
Spread unique shell tensor to shell-resolved tensor.
Spread unique species tensor to atom-resolved tensor.
Spread unique species tensor to orbital-resolved tensor.
Spread unique species tensor to orbital-resolved tensor.
Spread unique species tensor to shell-resolved tensor.
Returns a copy of the
TensorLikeinstance on the specified device.Returns a copy of the
TensorLikeinstance with specified floating point type.Attributes
Angular momenta of all unique shells
Angular momenta for all shells
Mapping of atoms to unique species
Mapping of unique shells to unique species
Number of unique shells per unqiue atoms.
Mapping of shells to unique atoms
Number of shells for each atom
Offset index for starting the next shell block
Mapping of shells to atoms
Number of orbitals for each shell
Offset index for starting the next orbital block
Mapping of orbitals to shells
Whether multiple systems or a single one are handled:
Storage to restore from after culling.
Specification of dtypes that the TensorLike object can take.
Shortcut for device and dtype.
The device on which the class object resides.
Floating point dtype used by class object.
Number of orbitals for each atom.
- Parameters:
unique_angular (Tensor)
angular (Tensor)
atom_to_unique (Tensor)
ushells_to_unique (Tensor)
ushells_per_unique (Tensor)
shells_to_ushell (Tensor)
shells_per_atom (Tensor)
shell_index (Tensor)
shells_to_atom (Tensor)
orbitals_per_shell (Tensor)
orbital_index (Tensor)
orbitals_to_shell (Tensor)
batch_mode (int)
device (torch.device | None)
dtype (torch.dtype)
store (IndexHelperStore | None)
- 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:
- classmethod from_numbers(numbers, par, batch_mode=None, move_to_numbers_device=True)[source]#
Construct an index helper instance from atomic numbers and a parametrization.
Note that this always runs on CPU to avoid inefficient communication between devices. Only the resulting tensors are transfered to the GPU. This is necessary because of complex data look up that is not vectorizable and requires native for-loops. Furthermore, the method frequently uses the
torch.Tensor.item()method, which forces CPU-GPU synchronization because it converts a GPU tensor to a Python scalar.- Return type:
- Parameters:
numbers (Tensor) – Atomic numbers for all atoms in the system (shape:
(..., nat)).par (Param) – Representation of an extended tight-binding model.
batch_mode (int) – Whether multiple systems or a single one are handled:
0: Single system
1: Multiple systems with padding
2: Multiple systems with no padding (conformer ensemble)
move_to_numbers_device (bool) – Move the resulting tensors to the device of the
numberstensor. This should be switched off for GPU calculations that use libcint for integrals as theIndexHelperhas to be on the CPU for this step.
- Returns:
Instance of index helper for given basis set.
- Return type:
- Parameters:
numbers (Tensor)
par (Param | ParamModule)
batch_mode (int | None)
move_to_numbers_device (bool)
- classmethod from_numbers_angular(numbers, angular, batch_mode=None, move_to_numbers_device=True)[source]#
Construct an index helper instance from atomic numbers and their angular momenta. If you are not sure about the angular momenta, use
IndexHelper.from_numbers()instead, which simply takes a parametrization.Note that this always runs on CPU to avoid inefficient communication between devices. Only the resulting tensors are transfered to the GPU. This is necessary because of complex data look up that is not vectorizable and requires native for-loops. Furthermore, the method frequently uses the
torch.Tensor.item()method, which forces CPU-GPU synchronization because it converts a GPU tensor to a Python scalar.- Return type:
- Parameters:
numbers (Tensor) – Atomic numbers for all atoms in the system (shape:
(..., nat)).angular (dict[int, Tensor]) – Map between atomic numbers and angular momenta of all shells.
batch_mode (int) – Whether multiple systems or a single one are handled:
0: Single system
1: Multiple systems with padding
2: Multiple systems with no padding (conformer ensemble)
move_to_numbers_device (bool) – Move the resulting tensors to the device of the
numberstensor. This should be switched off for GPU calculations that use libcint for integrals as theIndexHelperhas to be on the CPU for this step.
- Returns:
Instance of index helper for given basis set.
- Return type:
- Parameters:
- orbital_atom_mapping(idx)[source]#
Mapping of atom index to orbital index, i.e., return indices of orbitals belonging to given atom. The orbital order is given by
IndexHelper.orbitals_to_shell().
- 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
- reduce_orbital_to_atom(x, dim=-1, reduce='sum', extra=False)[source]#
Reduce orbital-resolved tensor to atom-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Orbital-resolved tensor.
dim (int | (int, int)) – Dimension to reduce over, defaults to -1.
reduce (str) – Reduction method, defaults to “sum”.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Atom-resolved tensor.
- Return type:
Tensor
- Parameters:
- reduce_orbital_to_shell(x, dim=-1, reduce='sum', extra=False)[source]#
Reduce orbital-resolved tensor to shell-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Orbital-resolved tensor.
dim (int | (int, int)) – Dimension to reduce over, defaults to -1.
reduce (str) – Reduction method, defaults to “sum”.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Shell-resolved tensor.
- Return type:
Tensor
- Parameters:
- reduce_shell_to_atom(x, dim=-1, reduce='sum', extra=False)[source]#
Reduce shell-resolved tensor to atom-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Shell-resolved tensor
dim (int | (int, int)) – Dimension to reduce over, defaults to -1.
reduce (str) – Reduction method, defaults to “sum”.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Atom-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_atom_to_orbital(x, dim=-1, extra=False)[source]#
Spread atom-resolved tensor to orbital-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Atom-resolved tensor.
dim (int | (int, int)) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Orbital-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_atom_to_orbital_cart(x, dim=-1, extra=False)[source]#
Spread atom-resolved tensor to orbital-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Atom-resolved tensor.
dim (int | (int, int)) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Orbital-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_atom_to_shell(x, dim=-1, extra=False)[source]#
Spread atom-resolved tensor to shell-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Atom-resolved tensor.
dim (int | (int, int)) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Shell-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_shell_to_orbital(x, dim=-1, extra=False)[source]#
Spread shell-resolved tensor to orbital-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Shell-resolved tensor.
dim (int | (int, int)) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Orbital-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_shell_to_orbital_cart(x, dim=-1, extra=False)[source]#
Spread shell-resolved tensor to orbital-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Shell-resolved tensor.
dim (int | (int, int)) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Orbital-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_ushell_to_orbital(x, dim=-1, extra=False)[source]#
Spread unique shell tensor to orbital-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Unique shell tensor.
dim (int | (int, int)) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Orbital-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_ushell_to_orbital_cart(x, dim=-1, extra=False)[source]#
Spread unique shell tensor to orbital-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Unique shell tensor.
dim (int | (int, int)) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Orbital-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_ushell_to_shell(x, dim=-1, extra=False)[source]#
Spread unique shell tensor to shell-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Unique shell tensor.
dim (int | (int, int)) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Shell-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_uspecies_to_atom(x, dim=-1, extra=False)[source]#
Spread unique species tensor to atom-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Unique specie tensor.
dim (int | (int, int)) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Atom-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_uspecies_to_orbital(x, dim=-1, extra=False)[source]#
Spread unique species tensor to orbital-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Unique specie tensor.
dim (int) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Orbital-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_uspecies_to_orbital_cart(x, dim=-1, extra=False)[source]#
Spread unique species tensor to orbital-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Unique specie tensor.
dim (int) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Orbital-resolved tensor.
- Return type:
Tensor
- Parameters:
- spread_uspecies_to_shell(x, dim=-1, extra=False)[source]#
Spread unique species tensor to shell-resolved tensor.
- Return type:
- Parameters:
x (Tensor) – Unique specie tensor.
dim (int | (int, int)) – Dimension to spread over, defaults to -1.
extra (bool) – Tensor to reduce contains a extra dimension of arbitrary size. Defaults to
False.
- Returns:
Shell-resolved tensor.
- Return type:
Tensor
- 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
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.
- property allowed_dtypes: tuple[dtype, ...]#
Specification of dtypes that the TensorLike object can take.
- Returns:
Collection of allowed dtypes the TensorLike object can take.
- Return type:
tuple[torch.dtype, …]
-
batch_mode:
int# Whether multiple systems or a single one are handled:
0: Single system
1: Multiple systems with padding
2: Multiple systems with no padding (conformer ensemble)