Skip to content

BUG: use base units for TPR x/v parsing#5374

Open
tylerjereddy wants to merge 1 commit intoMDAnalysis:developfrom
tylerjereddy:treddy_issue_5373
Open

BUG: use base units for TPR x/v parsing#5374
tylerjereddy wants to merge 1 commit intoMDAnalysis:developfrom
tylerjereddy:treddy_issue_5373

Conversation

@tylerjereddy
Copy link
Copy Markdown
Member

@tylerjereddy tylerjereddy commented May 3, 2026

LLM / AI generated code disclosure

No AI/LLMs used here.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.85%. Comparing base (9358d7a) to head (c620345).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5374   +/-   ##
========================================
  Coverage    93.85%   93.85%           
========================================
  Files          182      182           
  Lines        22505    22507    +2     
  Branches      3200     3200           
========================================
+ Hits         21121    21123    +2     
  Misses         922      922           
  Partials       462      462           

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

* Fixes MDAnalysisgh-5373.

* TPR position/velocity parsing was accidentally using
native instead of base units--regression testing and source
code was adjusted accordingly.
Copy link
Copy Markdown
Member

@BradyAJohnston BradyAJohnston left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
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.

Thanks so much for doing this @tylerjereddy ! Couple of things.

self.ts._pos = np.asarray(
tpr_utils.ndo_rvec(data, th.natoms), dtype=np.float32
)
self.convert_pos_from_native(self.ts._pos)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you need to wrap it around self.convert_units like we do here https://github.com/MDAnalysis/mdanalysis/blob/develop/package%2FMDAnalysis%2Fcoordinates%2FGRO.py#L255

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I noticed that. However, its use does need motivating with a regression test that fails without it, which wasn't immediately obvious to me since we don't write TPR files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also, GROWriter __init__ has:

        convert_units : bool (optional)
            units are converted to the MDAnalysis base format; [``True``]

but farther down it has:

        if self.convert_units:
            # Convert back to nm from Angstroms,
            # Not inplace because AtomGroup is not a copy
            positions = self.convert_pos_to_native(positions, inplace=False)

so while the default behavior makes sense, the docs are garbled--basically wrong, right? Should it even be "allowed" to write with A units for GRO?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we know if dimensions setting also needs fixing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

On the latest version of this feature branch,

import MDAnalysis as mda
from MDAnalysisTests.datafiles import TPR, XTC

u = mda.Universe(TPR, XTC)
print(u.dimensions)
u = mda.Universe(TPR)
print(u.dimensions)
u = mda.Universe(TPR, TPR)
print(u.dimensions)

produces:

[80.017006 80.017006 80.017006 60.       60.       90.      ]
None
None

That looks like more like a feature request than the same category of bug, so scope might be argued. I'd probably suggest a separate issue for that one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That sounds good - I was mostly just looking at other single file readers and checking what they were doing. If we don't have to, that works.

Copy link
Copy Markdown
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.

I'll put the convert unit thing as a request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: TPR coordinate/velocity parsing uses wrong units

3 participants