Skip to content

Conversation

@PardhavMaradani
Copy link

@PardhavMaradani PardhavMaradani commented Dec 22, 2025

Fixes #5183

Changes made in this Pull Request:

  • Added a current frame iterator for streamed trajectories
    • The iterator is created when the frames array has a single value that is same as the current frame
    • This enables passing current frame to an analysis class run method as .run(frames=[u.trajectory.frame])
  • Added a current frame access
    • This allows access like u.trajectory[u.trajectory.frame] to get current timestep
    • This enables analysis classes (like RMSD, AverageStructure) to use current frame as a ref_frame (in their __init__ method)

This PR allows us to do something like the following:

import MDAnalysis as mda
from MDAnalysis.analysis.dssp import DSSP

top = "/tmp/imd-workshop-2025/workshop/sample_simulation/GROMACS/input/start.gro"
u = mda.Universe(top, "imd://localhost:8889")
_dssp = DSSP(u)
for i in range(5):
    ts = u.trajectory.ts
    print(ts.data, ts.frame)
    run = _dssp.run(frames=[ts.frame])
    print("".join(run.results.dssp[0]))
    u.trajectory.next()

Here is a sample output of the per-frame analysis above:

{'time': 14.76, 'dt': 0.002, 'step': 7380} 0
-E--HHHHHHHHHH-----HHHE-HHHHHHHHHHHH--E---EEE-----EEE----E------E-------------EHHHHH----HHHHHHHHHHH-----HHH-HHHHHH------HHHH-----
{'time': 14.8, 'dt': 0.002, 'step': 7400} 1
-E--HHHHHHHHHH-----HHHE-HHHHHHHHHHHH--E---EEE-----EEE----EE-----E-------------EHHHH-----HHHHHHHHHHH----HHHH-HHHHHH------HHHH-----
{'time': 14.84, 'dt': 0.002, 'step': 7420} 2
-E--HHHHHHHHHH-----HHHE-HHHHHHHHHHHH--E---EEE-----EEE----EE-----E-------------EHHHH-----HHHHHHHHHH-----HHHH-HHHHHH------HHHH-----
{'time': 14.88, 'dt': 0.002, 'step': 7440} 3
-E--HHHHHHHHHH-----HHHE-HHHHHHHHHHH---E---EEE-----EEE----EE-----E-------------EHHHH-----HHHHHHHHHHH----HHHH-HHHHHH---------------
{'time': 14.92, 'dt': 0.002, 'step': 7460} 4
-E--HHHHHHHHHH-----HHHE-HHHHHHHHHHH---E---EEE-----EEE----EE-----E-------------EHHHHH----HHHHHHHHHHHH---HHHH-HHHHHH------HHH------

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--5184.org.readthedocs.build/en/5184/

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.

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.74%. Comparing base (9fb8b0a) to head (4948f40).

Files with missing lines Patch % Lines
package/MDAnalysis/coordinates/base.py 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5184      +/-   ##
===========================================
+ Coverage    92.72%   92.74%   +0.01%     
===========================================
  Files          180      180              
  Lines        22472    22491      +19     
  Branches      3188     3192       +4     
===========================================
+ Hits         20838    20860      +22     
+ Misses        1176     1174       -2     
+ Partials       458      457       -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.

@BradyAJohnston
Copy link
Member

This seems like a good idea to me - but I would defer to those more experienced with MDA & streaming as for why this approach maybe wasn't already taken.

@orbeckst
Copy link
Member

I’m away from most of work (and open source) and won’t get to reviewing until the new year. But please let this not halt any discussions here!

* This enables analysis classes to use current frame as reference in `__init__`
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.

Support per-frame analysis by AnalysisBase-based classes for streamed trajectories

3 participants