Skip to content

feat: pbc in neighbour lists, fix duplicate pairs in the RDF fallback, and speed up get_neighbors ~2.x+ - #423

Merged
Atilaac merged 3 commits into
mainfrom
feat/neighbor-list-pbc-and-performance
Sep 3, 2026
Merged

feat: pbc in neighbour lists, fix duplicate pairs in the RDF fallback, and speed up get_neighbors ~2.x+#423
Atilaac merged 3 commits into
mainfrom
feat/neighbor-list-pbc-and-performance

Conversation

@Atilaac

@Atilaac Atilaac commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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.

…, 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.
@github-actions github-actions Bot added the type: feature Changelog: new feature or performance improvement → bumps minor version label Sep 2, 2026
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.78571% with 37 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
amorphouspy/src/amorphouspy/atoms/neighbors.py 86.59% 37 Missing ⚠️

📢 Thoughts on this report? Let us know!

Changing this to 0.0 to make it more physically motivated
@Atilaac Atilaac added the integration Tag a PR with this to run integration tests label Sep 3, 2026
@Atilaac
Atilaac merged commit f752d24 into main Sep 3, 2026
11 checks passed
@Atilaac
Atilaac deleted the feat/neighbor-list-pbc-and-performance branch September 3, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration Tag a PR with this to run integration tests type: feature Changelog: new feature or performance improvement → bumps minor version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant