feat: pbc in neighbour lists, fix duplicate pairs in the RDF fallback, and speed up get_neighbors ~2.x+ - #423
Merged
Conversation
…, and speed up get_neighbors ~2.x+ ## Why `get_neighbors` and `build_distances` never read `atoms.pbc` — periodicity was applied in all three directions unconditionally. Reachable in production: `load_lammps_dump` doesn't force pbc, so a slab dump written with `ITEM: BOX BOUNDS ff ff pp` was silently analysed as fully periodic. This had no effect on the analysis so far, but I could imagine it leads to some in the future when the user base grows and workflows as well. ## Fixes - **`pbc` honoured per lattice vector**: non-periodic vectors are padded by `2 * cutoff` so no wrapped image can reach; the kernels are unchanged. - **`rdf._compute_distances` non-numba fallback emitted duplicate pairs** when a box edge spanned fewer than three cells. Deleted in favour of the shared path, removing a third copy of the cell-list loop. - Degenerate cells / molecules with no cell raised `SystemError`; `build_distances` raised on 0 atoms and zero volume; NaN coordinates silently vanished under `fastmath`. - Minimum-image warning used perpendicular height (a lower bound), so it fired spuriously on every slab and skewed cell. ## Performance `get_neighbors` **2x+ faster** , from replacing the per-atom Python output loops with one vectorised gather. `build_distances` unchanged (~1.2x). ## Behaviour changes No signature or return-type changes. Fully periodic bulk results are bit-identical. Non- or partially-periodic structures now return different, correct neighbour lists, and NaN coordinates / zero-volume periodic cells raise `ValueError` instead of silently dropping atoms or crashing.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Changing this to 0.0 to make it more physically motivated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
get_neighborsandbuild_distancesnever readatoms.pbc— periodicity was applied in all three directions unconditionally. Reachable in production:load_lammps_dumpdoesn't force pbc, so a slab dump written withITEM: BOX BOUNDS ff ff ppwas silently analysed as fully periodic. This had no effect on the analysis so far, but I could imagine it leads to some in the future when the user base grows and workflows as well.Fixes
pbchonoured per lattice vector: non-periodic vectors are padded by2 * cutoffso no wrapped image can reach; the kernels are unchanged.rdf._compute_distancesnon-numba fallback emitted duplicate pairs when a box edge spanned fewer than three cells. Deleted in favour of the shared path, removing a third copy of the cell-list loop.SystemError;build_distancesraised on 0 atoms and zero volume; NaN coordinates silently vanished underfastmath.Performance
get_neighbors2x+ faster , from replacing the per-atom Python output loops with one vectorised gather.build_distancesunchanged (~1.2x).Behaviour changes
No signature or return-type changes. Fully periodic bulk results are bit-identical. Non- or partially-periodic structures now return different, correct neighbour lists, and NaN coordinates / zero-volume periodic cells raise
ValueErrorinstead of silently dropping atoms or crashing.