utils
#
General utility functions
Modules:
-
smee
–Differentiably evaluate energies of molecules using SMIRNOFF force fields
Functions:
-
find_exclusions
–Find all excluded interaction pairs and their associated scaling factor.
-
ones_like
–Create a tensor of ones with the same device and type as another tensor.
-
zeros_like
–Create a tensor of zeros with the same device and type as another tensor.
-
tensor_like
–Create a tensor with the same device and type as another tensor.
-
arange_like
–Arange a tensor with the same device and type as another tensor.
-
logsumexp
–Compute the log of the sum of the exponential of the input elements, optionally
-
to_upper_tri_idx
–Converts pairs of 2D indices to 1D indices in an upper triangular matrix that
-
geometric_mean
–Computes the geometric mean of two values 'safely'.
Attributes:
-
EPSILON
–A small epsilon value used to prevent divide by zero errors.
EPSILON
module-attribute
#
A small epsilon value used to prevent divide by zero errors.
find_exclusions
#
find_exclusions(
topology: Topology, v_sites: Optional[VSiteMap] = None
) -> dict[tuple[int, int], ExclusionType]
Find all excluded interaction pairs and their associated scaling factor.
Parameters:
-
topology
(Topology
) –The topology to find the interaction pairs of.
-
v_sites
(Optional[VSiteMap]
, default:None
) –Virtual sites that will be added to the topology.
Returns:
-
A dictionary of the form ``{(atom_idx_1, atom_idx_2
–scale}``.
Source code in smee/utils.py
ones_like
#
Create a tensor of ones with the same device and type as another tensor.
zeros_like
#
Create a tensor of zeros with the same device and type as another tensor.
tensor_like
#
Create a tensor with the same device and type as another tensor.
Source code in smee/utils.py
arange_like
#
Arange a tensor with the same device and type as another tensor.
logsumexp
#
logsumexp(
a: Tensor,
dim: int,
keepdim: bool = False,
b: Tensor | None = None,
return_sign: bool = False,
) -> Tensor | tuple[Tensor, Tensor]
Compute the log of the sum of the exponential of the input elements, optionally with each element multiplied by a scaling factor.
Notes
This should be removed if torch.logsumexp is updated to support scaling factors.
Parameters:
-
a
(Tensor
) –The elements that should be summed over.
-
dim
(int
) –The dimension to sum over.
-
keepdim
(bool
, default:False
) –Whether to keep the summed dimension.
-
b
(Tensor | None
, default:None
) –The scaling factor to multiply each element by.
Returns:
-
Tensor | tuple[Tensor, Tensor]
–The log of the sum of exponential of the a elements.
Source code in smee/utils.py
to_upper_tri_idx
#
Converts pairs of 2D indices to 1D indices in an upper triangular matrix that excludes the diagonal.
Parameters:
-
i
(Tensor
) –A tensor of the indices along the first axis with
shape=(n_pairs,)
. -
j
(Tensor
) –A tensor of the indices along the second axis with
shape=(n_pairs,)
. -
n
(int
) –The size of the matrix.
-
include_diag
(bool
, default:False
) –Whether the diagonal is included in the upper triangular matrix.
Returns:
-
Tensor
–A tensor of the indices in the upper triangular matrix with
shape=(n_pairs * (n_pairs - 1) // 2,)
.
Source code in smee/utils.py
geometric_mean
#
Computes the geometric mean of two values 'safely'.
A small epsilon (smee.utils.EPSILON
) is added when computing the gradient in
cases where the mean is zero to prevent divide by zero errors.
Parameters:
-
eps_a
(Tensor
) –The first value.
-
eps_b
(Tensor
) –The second value.
Returns:
-
Tensor
–The geometric mean of the two values.