kups.core.neighborlist.cell_list
¶
Efficient O(N) neighbor list using spatial hashing with cell lists.
CellListNeighborList
¶
Efficient O(N) 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, achieving linear scaling with system size.
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. The fully-periodic path
is byte-identical to the original (gated at trace time on all(periodic))
so PBC kernels see no overhead.
Complexity: O(N) for well-distributed particles where cutoff << box size. 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. |
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
- On non-periodic axes positions must lie inside
[0, L)in real coordinates (the caller's invariant; out-of-range positions are silently routed to the OOB bin)
Example
Source code in src/kups/core/neighborlist/cell_list.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 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 | |
CellListSelector
¶
Selector for the cell-list algorithm.
Calls the raw spatial-hash candidate emission, then replicates per image
multiplicity when max(cutoff/perp) > 0.5.
Source code in src/kups/core/neighborlist/cell_list.py
IsCellListParams
¶
Bases: Protocol
Protocol for parameters required by CellListNeighborList.