strict_nl¶
- torch_sim.neighbors.strict_nl(cutoff, positions, cell, mapping, batch_mapping, shifts_idx)[source]¶
Apply a strict cutoff to the neighbor list defined in the mapping.
This function filters the neighbor list based on a specified cutoff distance. It computes the squared distances between pairs of positions and retains only those pairs that are within the cutoff distance. The function also accounts for periodic boundary conditions by applying cell shifts when necessary.
- Parameters:
cutoff (float) – The maximum distance for considering two atoms as neighbors. This value is used to filter the neighbor pairs based on their distances.
positions (Tensor) – A tensor of shape (n_atoms, 3) representing the positions of the atoms.
cell (Tensor) – Unit cell vectors according to the row vector convention, i.e. [[a1, a2, a3], [b1, b2, b3], [c1, c2, c3]].
mapping (Tensor) – A tensor of shape (2, n_pairs) that specifies pairs of indices in positions for which to compute distances.
batch_mapping (Tensor) – A tensor that maps the shifts to the corresponding cells, used in conjunction with shifts_idx to compute the correct periodic shifts.
shifts_idx (Tensor) – A tensor of shape (n_shifts, 3) representing the indices for shifts to apply to the distances for periodic boundary conditions.
- Returns:
- A tuple containing:
mapping (torch.Tensor): A filtered tensor of shape (2, n_filtered_pairs) with pairs of indices that are within the cutoff distance.
mapping_batch (torch.Tensor): A tensor of shape (n_filtered_pairs,) that maps the filtered pairs to their corresponding batches.
shifts_idx (torch.Tensor): A tensor of shape (n_filtered_pairs, 3) containing the periodic shift indices for the filtered pairs.
- Return type:
Notes
The function computes the squared distances to avoid the computational cost of taking square roots, which is unnecessary for comparison.
If no cell shifts are needed (i.e., for non-periodic systems), the function directly computes the squared distances between the positions.
References