tfep.utils.misc.forces_array_to_tensor

tfep.utils.misc.forces_array_to_tensor(forces, distance_unit=None, energy_unit=None, dtype=None)[source]

Helper function to convert the a batch of forces from numpy array to PyTorch tensor.

distance_unit and energy_unit must be passed together. If they are

both None no conversion is performed. If only one of them is None an error is raised.

Parameters:
  • forces (pint.Quantity) – The forces with shape (batch_size, n_atoms, 3) with units.

  • distance_unit (pint.Unit, optional) – The units of distance used in the returned forces. If None, no conversion is performed, and the forces will be in the same units as the input.

  • energy_unit (pint.Unit, optional) – The units of energy used in the returned forces. If None, no conversion is performed, and the energy will be in the same units as the input.

  • dtype (type, optional) – The torch data type to be used for the returned Tensor.

Returns:

forces – The forces with shape (batch_size, n_atoms*3) as a unitless Tensor in units of energy_unit/distance_unit.

Return type:

torch.Tensor

Raises:

ValueError – If only one between distance_unit and energy_unit is passed.