Skip to content

Fix neighborlist for skewed cells#976

Merged
zerothi merged 2 commits intozerothi:mainfrom
pfebrer:fix_neighbors
Mar 3, 2026
Merged

Fix neighborlist for skewed cells#976
zerothi merged 2 commits intozerothi:mainfrom
pfebrer:fix_neighbors

Conversation

@pfebrer
Copy link
Contributor

@pfebrer pfebrer commented Mar 2, 2026

This PR fixes a bug that @ialcon brought up for non-orthogonal cells with the neighbor finder.

Essentially, the algorithm assumes that if you are exactly at the center of a bin you can only access atoms within the same bin. This is clearly not the case in skewed cells when not being careful. Essentially, something like this was happening:

1000109419

@zerothi could you finish the PR (e.g. pre-commit stuff)? I'm abroad on a limited data plan and I don't want to use it to download pre-commit and friends 😄

)

# Required bin size along vector i due to its relation with j
required_bin_size = 2 * max_R / np.sin(alpha)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'm just thinking that probably it is not needed to change bin_size to start with 1. We can substitute the 2 here for the bin_size argument for axis i.

Although personally I think it is unnecessary to explain to the users why it starts with 2, and starting with 1 seems simpler to explain/understand. This is something that you added, so up to you to decide :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, simpler. Needed another fix in one of the tests.

@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 51.72414% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.66%. Comparing base (947b52b) to head (cfd3a14).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/sisl/geom/_neighbors/tests/test_finder.py 0.00% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #976      +/-   ##
==========================================
- Coverage   86.67%   86.66%   -0.02%     
==========================================
  Files         412      412              
  Lines       54375    54368       -7     
==========================================
- Hits        47131    47117      -14     
- Misses       7244     7251       +7     

☔ View full report in Codecov by Sentry.
📢 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.

@zerothi zerothi merged commit 7c690d8 into zerothi:main Mar 3, 2026
11 of 13 checks passed
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.

2 participants