Skip to content

Conversation

p-j-smith
Copy link
Member

@p-j-smith p-j-smith commented Oct 8, 2025

Fixes #5111

Changes made in this Pull Request:

  • selection keywords can now be used as residues names. The keyword must be escaped, e.g. u.select_atoms("resname \\water")
  • add tests for selecting residues named 'protein'. Add test to check u.select_atoms("resname protein") still raises a SelectionError
  • update documentation on selection keywords to show how to escape selection keywords

Note, this does mean that any keyword can be escaped - not just 'protein', 'water', etc. But it seemed like the simplest solution.

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!)

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.


📚 Documentation preview 📚: https://mdanalysis--5119.org.readthedocs.build/en/5119/

@p-j-smith p-j-smith requested a review from Copilot October 8, 2025 23:17
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR allows using selection keywords (like 'protein', 'water') as residue names by implementing an escape mechanism with backslashes. Users can now select residues named after keywords by escaping them (e.g., resname \\protein).

  • Implemented escape mechanism for selection keywords using backslash prefix
  • Added comprehensive tests for the new functionality
  • Updated documentation to explain the escape syntax

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
package/MDAnalysis/core/selection.py Added escape mechanism by removing backslash prefix from tokens
testsuite/MDAnalysisTests/core/test_atomselections.py Added tests for escaped keyword usage and error cases
package/doc/sphinx/source/documentation_pages/selections.rst Updated documentation to explain escape syntax
package/CHANGELOG Added changelog entry for the fix

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

codecov bot commented Oct 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.89%. Comparing base (519ac56) to head (d56aeb9).
⚠️ Report is 28 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5119   +/-   ##
========================================
  Coverage    93.88%   93.89%           
========================================
  Files          180      180           
  Lines        22422    22447   +25     
  Branches      3186     3188    +2     
========================================
+ Hits         21052    21077   +25     
  Misses         902      902           
  Partials       468      468           

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

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@IAlibay IAlibay merged commit 9ccde9b into develop Oct 12, 2025
23 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.

Water selection keyword interferes with using water as a residue name

2 participants