Skip to content

Add no selection option to RMSD analysis class#5296

Open
ollyfutur wants to merge 11 commits intoMDAnalysis:developfrom
ollyfutur:patch-1
Open

Add no selection option to RMSD analysis class#5296
ollyfutur wants to merge 11 commits intoMDAnalysis:developfrom
ollyfutur:patch-1

Conversation

@ollyfutur
Copy link

@ollyfutur ollyfutur commented Mar 9, 2026

Changes made in this Pull Request:

  • MDAnalysis.analysis.rms.RMSD now accepts select=None to prevent any further selection on atomgroup and reference. This is useful e.g. to avoid reordering of the atomgroups.

LLM / AI generated code disclosure

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

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.


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

ollyfutur and others added 5 commits March 9, 2026 17:02
RMSD analysis class now accepts `select=None` to prevent any selection on the provided `atomgroup` and `reference`.
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.83%. Comparing base (9531c6e) to head (a6a4f27).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5296   +/-   ##
========================================
  Coverage    93.82%   93.83%           
========================================
  Files          182      182           
  Lines        22483    22487    +4     
  Branches      3195     3198    +3     
========================================
+ Hits         21095    21101    +6     
+ Misses         925      924    -1     
+ Partials       463      462    -1     

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

@jeremyleung521 jeremyleung521 left a comment

Choose a reason for hiding this comment

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

Just some ideas/suggestions on the implementation. Probably need someone more experienced to approve :)

"select dictionary must contain entries for keys "
"'mobile' and 'reference'."
) from None
elif select is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing that I keep going back and forth in my head is that 'all' and None have so much overlap I'm wondering if it's better to modify 'all' behavior to be like None (no sorting). Maybe someone more experienced should comment on this.

Copy link
Author

Choose a reason for hiding this comment

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

The problem is that it would be inconsistent with the usual atomgroup.select_atoms("all"), which is expected to sort… I think that conceptually None translates better the idea that no operation changes the provided groups.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just read the docs and it's clear that sorting is intended and not just a side effect. So yea, I think None probably is the best way here.

https://docs.mdanalysis.org/2.9.0/documentation_pages/selections.html

Selections always return an [AtomGroup](https://docs.mdanalysis.org/2.9.0/documentation_pages/core/groups.html#MDAnalysis.core.groups.AtomGroup) with atoms sorted according to their index in the topology (this is to ensure that there are not any duplicates, which can happen with complicated selections).

LGTM now.

Copy link
Author

Choose a reason for hiding this comment

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

Reflecting on this, this is how alignto handles it:

.. Warning:: The atom order for `mobile` and `reference` is *only*
preserved when `select` is either "all" or ``None``. In any other case,
a new selection will be made that will sort the resulting AtomGroup by
index and therefore destroy the correspondence between the two groups.
**It is safest not to mix ordered AtomGroups with selection strings.**

So there is a legitimate debate on whether RMSD should or should not adopt a similar behavior.

Copy link
Member

Choose a reason for hiding this comment

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

None provides a unique functionality, i.e., leaving mobile and ref unchanged, so I see much more value in letting them do what @ollyfutur is intending here.

I'd say, the fact that align chooses "all" when selecting None is more a historical accident where None was just used as "default" and an argument could be made to change its behavior for "all". It would be more consistent if "all" behaved like a selection.

(by the way, "all" is not properly documented in https://docs.mdanalysis.org/2.10.0/documentation_pages/selections.html ... )

@orbeckst
Copy link
Member

@ollyfutur could you please raise an issue that we can then reference? I think you're making a good point here. Given that this has some implications for our API and the discussion on behavior of None vs all we should have an issue for it.

This PR can then "fix the issue".

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

I like the change and the code. Please

  • raise an issue that we can reference; describe the problem and the solution in the issue
  • add a bit more documentation

DSSP by porting upstream PyDSSP 0.9.1 fix (Issue #4913)

Enhancements
* Allow `select=None` in `MDAnalysis.analysis.rms.RMSD`
Copy link
Member

Choose a reason for hiding this comment

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

describe succinctly what None does, reference Issue and PR

- `str` -> Any valid string selection
- `dict` -> ``{'mobile':sel1, 'reference':sel2}``
- `tuple` -> ``(sel1, sel2)``
- ``None``
Copy link
Member

Choose a reason for hiding this comment

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

Document what None does.

"select dictionary must contain entries for keys "
"'mobile' and 'reference'."
) from None
elif select is None:
Copy link
Member

Choose a reason for hiding this comment

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

None provides a unique functionality, i.e., leaving mobile and ref unchanged, so I see much more value in letting them do what @ollyfutur is intending here.

I'd say, the fact that align chooses "all" when selecting None is more a historical accident where None was just used as "default" and an argument could be made to change its behavior for "all". It would be more consistent if "all" behaved like a selection.

(by the way, "all" is not properly documented in https://docs.mdanalysis.org/2.10.0/documentation_pages/selections.html ... )

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.

3 participants