Molecule: Representation#

This module contains a class for the representation of important molecular information.

Example

>>> import torch
>>> from tad_mctc.molecule.container import Mol
>>>
>>> numbers = torch.tensor([14, 1, 1, 1, 1])
>>> positions = torch.tensor([
...     [+0.00000000000000, +0.00000000000000, +0.00000000000000],
...     [+1.61768389755830, +1.61768389755830, -1.61768389755830],
...     [-1.61768389755830, -1.61768389755830, -1.61768389755830],
...     [+1.61768389755830, -1.61768389755830, +1.61768389755830],
...     [-1.61768389755830, +1.61768389755830, +1.61768389755830],
... ])
>>> mol = Mol(numbers, positions)
class tad_mctc.molecule.container.Mol(numbers, positions, charge=0, name=None, device=None, dtype=None)[source]#

Representation of a molecule.

property charge#

Charge of the molecule.

checks()[source]#

Check all variables for consistency.

Raises:

RuntimeError – Wrong device or shape errors.

clear_cache()[source]#

Clear the cross-instance caches of all memoized methods.

com()[source]#

Calculate the center of mass of the molecule.

Returns:

Center of mass.

Return type:

Tensor

distances()[source]#

Calculate the distance matrix from the positions.

Warning

Memoization for this method creates a cache that stores the distances across all instances.

Returns:

Distance matrix.

Return type:

Tensor

enn(cutoff=25.0)[source]#

Calculate the nuclear repulsion energy.

Warning

Memoization for this method creates a cache that stores the nuclear repulsion energy across all instances.

Parameters:

cutoff (Tensor | float | int | None, optional) – Cutoff distance for the nuclear repulsion energy. Defaults to 25.0.

Returns:

Nuclear repulsion energy.

Return type:

Tensor

classmethod from_path(path, ftype=None, name=None, device=None, dtype=None, dtype_int=torch.int64)[source]#

Create a molecule from a file.

Parameters:
  • path (PathLike) – Path to the file.

  • ftype (str | None, optional) – File type. Defaults to None. If None, the file type is determined from the file extension.

  • name (str | None, optional) – Name of the molecule. Defaults to None.

  • device (torch.device | None, optional) – Device to store the tensor on. Defaults to None.

  • dtype (torch.dtype | None, optional) – Floating point data type of the tensor. Defaults to None.

  • dtype_int (torch.dtype, optional) – Integer data type of the tensor. Defaults to torch.long.

Returns:

Molecule.

Return type:

Mol

mass(atomic_units=False)[source]#

Calculate the total mass of the molecule.

Returns:

Total mass.

Return type:

Tensor

property name#

Name of the molecule.

property numbers#

Atomic numbers of the molecule.

property positions#

(..., nat, 3)).

Type:

Cartesian coordinates of all atoms (shape

sum_formula()[source]#

Calculate the sum formula of the molecule.

Returns:

Sum formula.

Return type:

str