kups.core.neighborlist.cell_list
¶
Efficient O(N) neighbor list using spatial hashing with cell lists.
CellListLookup
¶
Bases: Protocol
Cached occupant lookup, independent of any per-particle payload type.
Source code in src/kups/core/neighborlist/cell_list.py
CellListNeighborList
¶
Neighbor list using spatial hashing with cell lists.
This is the recommended implementation when the cutoff is much smaller than the box size. It divides space into a grid of cells and only checks pairs in neighboring cells.
Honors the cell's per-axis periodic mask: stencil offsets that cross a
non-periodic face are routed to an out-of-bounds bin (no key matches), and
minimum-image shifts are zero on non-periodic axes.
cache optionally supplies an initialized CellListCache for the
current particles and cutoff. It retains occupant slots and neighboring
cells between calls; accepted moves must update it along with the particles.
Rebuild it when the cell, cutoff, or particle row layout changes.
Without a cache, the same grid algorithm joins particle and query cell hashes.
Candidate storage is O(N) for well-distributed particles at fixed density and cutoff. Uncached lookup sorts cell hashes; cached lookup gathers slots. Efficiency improves as cutoff/box ratio decreases.
Attributes:
| Name | Type | Description |
|---|---|---|
avg_candidates |
Capacity[int]
|
Capacity for candidate pair storage (from cell list). |
avg_edges |
Capacity[int]
|
Capacity for final edge array. |
cells |
Capacity[int]
|
Capacity for cell hash table (grows with box_size³/cutoff³). |
avg_image_candidates |
Capacity[int]
|
Capacity for image candidate pairs. |
cutoffs |
Table[SystemId, Array]
|
Per-system cutoff distances used by this neighbor list. |
cache |
CellListLookup | None
|
Current cell occupants, or |
Algorithm
- Partition space into grid cells of size ~cutoff
- Hash each particle to its cell
- For each particle, check only neighboring 27 cells (3D)
- Filter candidates by actual distance
When to use
- When cutoff/box_size << 1 (cutoff much smaller than box)
- Typically cutoff/box < 0.3 for good efficiency
- Nonperiodic outliers remain searchable in boundary bins; many outliers can increase the candidate count.
Example
Source code in src/kups/core/neighborlist/cell_list.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
selector(query_size, systems)
¶
Build the candidate selector shared by graph and pair evaluation.
Source code in src/kups/core/neighborlist/cell_list.py
CellListSelector
¶
Selector for the cell-list algorithm.
Joins cell hashes, or reads occupants from an optional initialized cache,
then replicates per image multiplicity when max(cutoff/perp) > 0.5.
Set promise_unique_cells when the caller guarantees at least three cells
along every periodic axis,
so each query's stencil cells are already distinct; this skips the
per-query cell deduplication in the uncached lookup.
Source code in src/kups/core/neighborlist/cell_list.py
IsCellListParams
¶
Bases: Protocol
Protocol for parameters required by CellListNeighborList.
Source code in src/kups/core/neighborlist/cell_list.py
assign_cells(positions, system, active, bins, max_cells, cell)
¶
Fold fractional positions and assign active rows to global cell ids.
max_cells is the allocated cell capacity per system, which may exceed
its bin count. Inactive rows use the sentinel len(bins) * max_cells.
Open-boundary outliers share the edge bins; their unfolded coordinates
remain available for exact distance filtering.
Source code in src/kups/core/neighborlist/cell_list.py
cell_hash(coordinate, num_cells)
¶
Hash folded fractional coordinates into row-major cell bins.
Coordinates outside nonperiodic faces are assigned to the boundary bins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coordinate
|
Array
|
Fractional coordinates, folded on periodic axes, |
required |
num_cells
|
Array
|
Per-axis bin counts broadcastable to |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Row-major bin ids of shape |
Source code in src/kups/core/neighborlist/cell_list.py
cell_stencil(dim)
¶
All 3**dim neighbor-cell offsets in {-1, 0, 1}**dim, (3**dim, dim).
Source code in src/kups/core/neighborlist/cell_list.py
neighbor_cells(cells, bins, max_cells, cell, *, width=27, promise_unique=False)
¶
Distinct neighboring cells using the unit cell's boundary rules.
max_cells is the allocated capacity per system. Invalid or duplicate
entries use the sentinel len(bins) * max_cells.