xnn.common.data.grid_pairs#

The unique pairs of an orthorhombic periodic cell from a grid of cells, on the GPU (or on the CPU, one lane per program, through xnn.common.cpu_kernels).

The cell is divided into at least 2 SPAN + 1 cells per axis, each at least the cutoff over SPAN wide, so every pair within the cutoff joins an atom to one of the (2 SPAN + 1)^3 cells around it, and in exactly one image (SPAN 1 on a GPU, 2 on a CPU where the grid allows: fewer candidates in smaller cells). One program per atom walks those cells twice: first to count its partners of higher index, then to write them at its offset in the prefix sum of the counts. The pairs come out sorted by their first atom, in the same order in every run, with no atomic adds and no host read but the total. A cell too small for the grid, with every edge over the cutoff, is searched without one: each atom against every atom of higher index (a GPU).

Functions

all_pairs_staged(pos, cutoff, lengths, cap)

grid_pairs_staged() for an orthorhombic cell with every edge over twice cutoff and no room for a grid: every pair tested (a few thousand atoms).

grid_pairs(pos, cutoff, lengths, shape[, ...])

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

grid_pairs_staged(pos, cutoff, lengths, ...)

The pairs i < k within cutoff from one search on the CPU (xnn.common.cpu_kernels): each atom's partners in cap slots of its own, with the index of their image among the 27 shifts of -1, 0, 1 per axis ((s_x + 1) 9 + (s_y + 1) 3 + s_z + 1, the displacement pos[k] - pos[i] + shift * lengths).

grid_shape(lengths, cutoff[, span])

The cells per axis of a grid over an orthorhombic cell with edges lengths: as many as fit at least cutoff / span wide, or None with fewer than 2 span + 1 on an axis.