xnn.common.data.neighborlist#

Periodic-boundary-aware neighbor list.

Produces, for a single structure, the edge list and the integer periodic image shift per edge within a cutoff. The same routine handles molecular systems (cell=None / no pbc) by simply skipping image enumeration.

The reference implementation here is a clear one (per-structure, brute force over the minimal set of image shifts), correct for both small molecules and dense crystals but quadratic in the number of atoms. When vesin is installed its cell list is used instead, which returns the same edges with the same conventions and is what makes this usable at system sizes where the brute force is not: on 5000 atoms with a 6 A cutoff, 1674 ms becomes 0.6 ms. vesin is optional – without it, or for the cases it cannot express (per-axis periodicity, self-edges), the reference implementation runs unchanged.

Functions

build_neighbor_list(pos, cutoff[, cell, ...])

Build a periodic-boundary-aware neighbor list for a single structure.

cell_grid(pos, cutoff[, cell, pbc])

The grid unique_pairs() searches: an orthorhombic cell, periodic on every axis, with room for at least three cells of cutoff per axis, and positions on a CUDA device with Triton, or on the CPU with at least GRID_CPU_ATOMS atoms where the CPU kernels compile (xnn.common.cpu_kernels; vesin's search is single-threaded).

half_list(pos, cutoff[, cell, pbc])

vesin's half neighbor list: every pair within cutoff once, in either order, with an atom's own periodic images, as ((i, j), shift); None where vesin does not apply (see unique_pairs()).

nearest_edges(dist, dst, num_nodes, k)

The edges to the k nearest neighbors of every receiving atom.

small_cell(pos, cutoff[, cell, pbc])

The edges of a cell whose pairs grid_pairs() finds without a grid (shape=None): orthorhombic, periodic on every axis, too small for cell_grid() but with every edge over cutoff, and the positions on a CUDA device with Triton.

unique_pairs(pos, cutoff[, cell, pbc, half])

Every pair within cutoff once, as (i, k, shift) with i < k, sorted by i.