torchani.grad#

Wrapper functions that make use of torch.autograd

Computation of forces, hessians, and vibrational frequencies.

Functions

single_point

Calculate properties for a batch of molecules

vibrational_analysis

Computing the vibrational wavenumbers from hessian.

forces_for_training

energies_and_forces

forces

grads

hessians

forces_and_hessians

energies_forces_and_hessians

calc_forces

calc_grads

calc_hessians

calc_forces_and_hessians

torchani.grad.single_point(model, species, coordinates, cell=None, pbc=None, charge=0, forces=False, hessians=False, atomic_energies=False, atomic_charges=False, atomic_charges_grad=False, ensemble_values=False, keep_vars=False)[source]#

Calculate properties for a batch of molecules

This is the main entrypoint of ANI-style models

Parameters:
  • species (Tensor) – An int tensor that stores the atomic numbers of a batch of molecules. Shape is (molecules, 3).

  • coordinates (Tensor) – A float tensor with the coordinates of a batch of molecules. Shape is (molecules, atoms, 3). All ANI models use Angstrom.

  • cell (Tensor | None) – A float tensor with unit cell vectors in its rows. Only use this with PBC. A cell with dimensions 10, 15, 20 (in Angstrom for all ANI models) in the x, y, and z directions is given by torch.tensor([[10., 0., 0.],[0., 15., 0.],[0., 0., 20.]]).

  • pbc (Tensor | None) – A bool tensor that stores whether periodic boundary conditions (PBC) are enabled for the x, y, z directions. pbc=torch.tensor([True, True, True]) fully enables PBC and pbc=None (or torch.tensor([False, False, False])). fully disables it.

  • charge (int) – The total charge of the molecules. Only the scalar 0 is currently supported.

  • forces (bool) – Calculate the associated forces. Shape (molecules, atoms, 3)

  • hessians (bool) – Calculate the hessians. Shape is (molecules, atoms * 3, atoms * 3)

  • atomic_energies (bool) – Perform atomic decoposition of the energies

  • atomic_charges (bool) – Only for models that support it, output atomic charges. Shape (molecules, atoms)

  • atomic_charges_grad (bool) – Only for models that support it, output atomic charge gradients. Shape (molecules, atoms, 3).

  • ensemble_values (bool) – Differentiate values of different models of the ensemble Also output ensemble standard deviation and qbc factors

  • keep_vars (bool) – The output scalars are detached from the graph unless keep_vars=True.

Returns:

Result of the single point calculation. Dictionary that maps strings to various result tensors.

Return type:

Dict[str, Tensor]

torchani.grad.vibrational_analysis(masses, hessian, mode_kind='mdu', unit='cm^-1')[source]#

Computing the vibrational wavenumbers from hessian.

Note that normal modes in many popular software packages such as Gaussian and ORCA are output as mass deweighted normalized (MDN). Normal modes in ASE are output as mass deweighted unnormalized (MDU). Some packages such as Psi4 let ychoose different normalizations. Force constants and reduced masses are calculated as in Gaussian.

mode_kind should be one of: - MWN (mass weighted normalized) - MDU (mass deweighted unnormalized) - MDN (mass deweighted normalized)

MDU modes are not orthogonal, and not normalized, MDN modes are not orthogonal, and normalized. MWN modes are orthonormal, but they correspond to mass weighted cartesian coordinates (x’ = sqrt(m)x).

Imaginary frequencies are output as negative numbers. Very small negative or positive frequencies may correspond to translational, and rotational modes.