torch_nl_n2

torch_sim.neighbors.torch_nl.torch_nl_n2(positions, cell, pbc, cutoff, system_idx, self_interaction=False)[source]

Compute the neighbor list for a set of atomic structures using a naive neighbor search before applying a strict cutoff.

This implementation uses a naive O(N²) neighbor search which can be slow for large systems but is simple and works reliably for small to medium systems.

Positions are wrapped into the primary cell internally for the search; the returned shifts_idx are corrected so they remain valid for the original (unwrapped) input positions. The input tensor is never modified.

Parameters:
  • positions (torch.Tensor [n_atom, 3]) – Cartesian positions (may be unwrapped).

  • cell (torch.Tensor [n_systems, 3, 3]) – Unit cell vectors.

  • pbc (torch.Tensor [n_systems, 3] bool) – A tensor indicating the periodic boundary conditions to apply.

  • cutoff (torch.Tensor) – The cutoff radius used for the neighbor search.

  • system_idx (torch.Tensor [n_atom,] torch.long) – A tensor containing the index of the structure to which each atom belongs.

  • self_interaction (bool, optional) – A flag to indicate whether to keep the center atoms as their own neighbors. Default is False.

Returns:

mapping (torch.Tensor [2, n_neighbors]):

Pairs of atom indices; mapping[0] are central atoms, mapping[1] are neighbors.

system_mapping (torch.Tensor [n_neighbors]):

System assignment for each pair.

shifts_idx (torch.Tensor [n_neighbors, 3]):

Cell shift indices valid for the original input positions.

Return type:

tuple[Tensor, Tensor, Tensor]

References