Skip to content

Conversation

@rishinamdev17
Copy link

@rishinamdev17 rishinamdev17 commented Dec 30, 2025

Fixes #1736

Changes made in this Pull Request:

  • Added a test for cylindrical distance-based atom selections (cylayer) using PeriodicKDTree
  • Ensured the KDTree-based distance search produces the same results as the selection engine
  • Covers periodic boundary conditions for cylindrical selections

PR Checklist

  • Issue raised/referenced?
  • Tests updated/added?
  • Documentation updated/added? (not required for test-only change)
  • package/CHANGELOG file updated? (not required for test-only change)
  • Is your name in package/AUTHORS? (optional for small contributions)

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.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello there first time contributor! Welcome to the MDAnalysis community! We ask that all contributors abide by our Code of Conduct and that first time contributors introduce themselves on GitHub Discussions so we can get to know you. You can learn more about participating here. Please also add yourself to package/AUTHORS as part of this PR.

@BradyAJohnston
Copy link
Member

Hi @rishinamdev17 - we can't review this PR at all given the tests are currently failing. Please look into ensuring the tests are passing (ideally you wouldn't open a new PR for a new test that doesn't pass to begin with).

@rishinamdev17
Copy link
Author

hi @BradyAJohnston
Thanks for the feedback — I’ve been debugging this further and the failure is coming from the selection parser itself rather than the KDTree logic.

The cylayer selection appears to internally route through PointSelection and expects additional tokens (cutoff) that aren’t obvious from the public API, which results in a float(None) error even with valid-looking syntax like cylayer … index 0.

I don’t want to force a workaround without understanding the intended grammar, so I’m pausing further changes until I get clarification on the correct cylayer selection form to use for this test. Happy to update once advised.

@BradyAJohnston
Copy link
Member

You are not currently using cylayer properly as it expects a selection to use as the COG. Please read the documentation:

selects all atoms within a cylindric layer centered in the center of geometry (COG) of a given selection, e.g. cylayer 5 10 10 -8 protein selects the center of geometry of protein, and creates a cylindrical layer of inner radius 5, external radius 10 centered on the COG. In z, the cylinder extends from 10 above the COG to 8 below. Positive values for zMin, or negative ones for zMax, are allowed.

@codecov
Copy link

codecov bot commented Jan 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.72%. Comparing base (9fb8b0a) to head (b7c3bb6).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5194      +/-   ##
===========================================
- Coverage    92.72%   92.72%   -0.01%     
===========================================
  Files          180      180              
  Lines        22472    22474       +2     
  Branches      3188     3189       +1     
===========================================
+ Hits         20838    20839       +1     
- Misses        1176     1177       +1     
  Partials       458      458              

☔ 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.

@rishinamdev17
Copy link
Author

Thanks for your patience @BradyAJohnston !!
I’m still tracking down the remaining Black formatting failure locally. The cylayer selection logic now looks correct following your guidance, and I’m aligning my local Black setup with the project configuration so the final CI check passes. I’ll push an update shortly.

assert_equal(
u.atoms[:3].chiralities, np.array(["", chirality, ""], dtype="U1")
)
assert_equal(u.atoms[:3].chiralities, np.array(["", chirality, ""], dtype="U1"))
Copy link
Member

Choose a reason for hiding this comment

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

Are all these unrelated whitespace changes really needed?

Copy link
Author

Choose a reason for hiding this comment

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

Those whitespace changes are unrelated to my test. I'll revert them and keep the PR focused only on the cylayer test.

from MDAnalysis import SelectionError, SelectionWarning
from MDAnalysis.core.selection import Parser
from MDAnalysis.lib.distances import distance_array
from MDAnalysis.lib.pkdtree import PeriodicKDTree
Copy link
Member

Choose a reason for hiding this comment

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

Where is this being used?

Copy link
Author

Choose a reason for hiding this comment

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

Yes you are right!! that import is no lomger needed after simplifying the test and I have removed it..

def universe():
u = mda.Universe(PSF, DCD)
u.dimensions = np.array([100.0, 100.0, 100.0, 90.0, 90.0, 90.0])
return u
Copy link
Member

Choose a reason for hiding this comment

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

Creating a fixture for use in a single test case seems a bit much, especially when you're repeating the setting of dimensions below anyway.

Copy link
Author

Choose a reason for hiding this comment

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

I have combined the universe setup into the test and removed the duplicate dimensions setting.

@BradyAJohnston
Copy link
Member

There are still a lot of formatting changes that should be undone. The test you have also now created no longer really tests what you set out to do - it is just testing the parsing of a selection and not that it matches against using the PeriodicKDTree.

@orbeckst
Copy link
Member

orbeckst commented Jan 6, 2026

@BradyAJohnston thanks for moving the PR along. I assigned it to you, given that you're already doing the work of the PR shepherd. Thank you!

@Aryaman-Chaudhri
Copy link

Hi @rishinamdev17 , I noticed you are struggling with black , you might want to look into CONTRIBUTING.md.

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.

write a test for cylindrical selections tokens using the periodic kdtree

5 participants