Skip to content

Fix: Incorrect capped_distance in some triclinic box situations - #5481

Open
BradyAJohnston wants to merge 3 commits into
MDAnalysis:developfrom
BradyAJohnston:fix-4906-triclinic-pbc
Open

BradyAJohnston wants to merge 3 commits into
MDAnalysis:developfrom
BradyAJohnston:fix-4906-triclinic-pbc

Conversation

@BradyAJohnston

Copy link
Copy Markdown
Member

Fixes #4906

In triclinic boxes where both b_x and c_y are non-zero (e.g. truncated octahedra), the nsgrid and pkdtree methods of capped_distance / self_capped_distance miss pairs within the cutoff. This affects bond guessing, selections, etc. Reproduced with the issue's struc.txt and the truncated-octahedron script; both now match bruteforce.

Changes made in this Pull Request:

  • _triclinic_pbc: fix the a-axis wrapping bound, which could leave coordinates just outside the primary image (affects apply_PBC, pkdtree and nsgrid)
  • FastNS.coord2cellxyz: fix the same missing term in the x cell index (as suspected here)
  • FastNS._prepare_box: size grid cells from the box's perpendicular widths, so cells are never thinner than the cutoff
  • Add regression tests for apply_PBC, capped_distance, self_capped_distance and FastNS in skewed boxes

LLM / AI generated code disclosure

LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution: no

I did use Claude to scan through and track down the issue, but I wrote the code and the tests.

PR Checklist

  • Issue raised/referenced?
  • Tests updated/added?
  • Documentation updated/added?
  • package/CHANGELOG file updated?
  • Is your name in package/AUTHORS? (If it is not, add it!)
  • LLM/AI disclosure was updated.

Developers Certificate of Origin

I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.

@BradyAJohnston BradyAJohnston changed the title Fix: #4096: Incorrect capped_distance in some triclinic box situations Fix: Incorrect capped_distance in some triclinic box situations Oct 9, 2026
@read-the-docs-community

read-the-docs-community Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 MDAnalysis | 🛠️ Build #35038979 | 📁 Comparing a3e37a8 against latest (6ae1589)

  🔍 Preview build  

1 file changed
± documentation_pages/analysis/wbridge_analysis.html

@BradyAJohnston

Copy link
Copy Markdown
Member Author

Seems one of the old snapshots is failing but I'm pretty sure they are just incorrectly snapshotted values, looking into it

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.87%. Comparing base (6ae1589) to head (a3e37a8).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5481   +/-   ##
========================================
  Coverage    93.87%   93.87%           
========================================
  Files          184      184           
  Lines        22645    22645           
  Branches      3220     3220           
========================================
  Hits         21257    21257           
  Misses         923      923           
  Partials       465      465           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@IAlibay

IAlibay commented Oct 9, 2026

Copy link
Copy Markdown
Member

This looks great, unfortunately I won't have time to review. I'm going to un-request my review here and pick on someone else ;)

@IAlibay
IAlibay requested review from tylerjereddy and removed request for IAlibay October 9, 2026 11:42

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bugs for distance calculation functions

2 participants