Skip to content

Conversation

@schuhmc
Copy link
Contributor

@schuhmc schuhmc commented Jul 9, 2025

Fixes #5079

The GROMOS11 trajectory reader written by @JoStoe was merged in #4292 (see issue #4291 )

The performance in the current state is very slow

Changes made in this Pull Request:

  • Use seek to skip over the POSITIONRED block when creating the Universe
  • Prevent calling strip() on the same line multiple times
  • Improved reading speed of the POSITIONRED block by using a buffer and processing with numpy.fromstring()
  • Pre-allocate numpy arrays instead of reading into list() and calling numpy.asarray()
  • Add the GROMOS11 reader to the benchmark set
  • Add a test with a trajectory containing inconsistent whitespace

All-in-all this provides a significant speed boost. Internal testing showed the following speed increase when loading and iterating over a 1 GB trajectory of 2000 frames:

Before these changes: 86.97 s +/- 1.13 s (n=10)
With changes in this PR: 42.05 s +/- 0.66 s (n=10)
Speed improvement -51.6%

On the newly added benchmark the following speed improvement was measured:
traj_reader.TrajReaderCreation.time_reads: 5.339 ms -> 3.579 ms (-33.0%)
traj_reader.TrajReaderIteration.time_strides: 7.642 ms -> 4.524 ms (-40.8%)

(Note that the benchmark trajectories are very small which reduces the impact on the TrajReaderCreation.time_reads benchmark. Based on testing on larger trajectories, the time for the Universe creation is reduced by 70-80% if the file has consistent block sizes)

Most of the speed improvement comes from the skipping over the POSITIONRED block, meaning that it is not necessary to read the full trajectory upon universe creation.
However, note that when the size of the POSITIONRED block is not consistent (whitespace), the speed is impacted.

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

I don't think that the documentation needs to be 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--5080.org.readthedocs.build/en/5080/

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 Jul 9, 2025

Codecov Report

❌ Patch coverage is 96.05263% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.63%. Comparing base (b113fd5) to head (61b590a).
⚠️ Report is 46 commits behind head on develop.

Files with missing lines Patch % Lines
package/MDAnalysis/coordinates/TRC.py 96.05% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5080   +/-   ##
========================================
  Coverage    93.62%   93.63%           
========================================
  Files          177      177           
  Lines        22001    22033   +32     
  Branches      3114     3115    +1     
========================================
+ Hits         20599    20631   +32     
- Misses         947      948    +1     
+ Partials       455      454    -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
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.

Looks really good! Thank you for your contribution. Great work.

I only have a few optional comments. If you want to address them, please let us know how much time you need. If you don't want to address them please say so, too, and then we can merge right away.

EDIT: Please run black over TRC.py and check all the other files that you touched. We won't merge until the linter is also happy.

@orbeckst orbeckst self-assigned this Jul 9, 2025
@schuhmc
Copy link
Contributor Author

schuhmc commented Jul 10, 2025

Thank you for the valuable feedback @orbeckst !

I implemented the requested changes where possible (see comments). The linters also seem happy now.
I also added tests for trajectories with too many/few positions.

From my side this should be ready to merge.

@orbeckst orbeckst merged commit c3289d8 into MDAnalysis:develop Jul 11, 2025
23 checks passed
@orbeckst
Copy link
Member

Thank you @schuhmc , very nice contribution! 🎉

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.

GROMOS11 reader is slow

2 participants