Skip to content

ENH: expose TPR box dimensions through timestep#5377

Open
iamtanmaybaranwal wants to merge 2 commits intoMDAnalysis:developfrom
iamtanmaybaranwal:enh-tpr-box-vectors
Open

ENH: expose TPR box dimensions through timestep#5377
iamtanmaybaranwal wants to merge 2 commits intoMDAnalysis:developfrom
iamtanmaybaranwal:enh-tpr-box-vectors

Conversation

@iamtanmaybaranwal
Copy link
Copy Markdown

@iamtanmaybaranwal iamtanmaybaranwal commented May 6, 2026

When a Universe is created directly from a TPR file, u.dimensions previously returned None because box information was extracted but discarded during TPR reading.

This change reads box vectors from the TPRReader, converts them from nanometres to Angstroms, converts triclinic vectors into MDAnalysis dimensions format, and stores them in ts.dimensions.

Tests were added to verify dimensions are populated correctly.

Closes #5375

Fixes #5375

Changes made in this Pull Request:

  • Read box vectors from TPR files in TPRReader.
  • Convert triclinic box vectors into MDAnalysis dimensions format.
  • Store dimensions in ts.dimensions.
  • Add regression tests for TPR dimensions handling.
  • Add changelog entry for the fix.

LLM / AI generated code disclosure

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

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

When a Universe is created directly from a TPR file,
u.dimensions previously returned None because box information
was extracted but discarded during TPR reading.

This change reads box vectors from the TPRReader, converts them
from nanometres to Angstroms, converts triclinic vectors into
MDAnalysis dimensions format, and stores them in ts.dimensions.

Tests were added to verify dimensions are populated correctly.

Closes MDAnalysis#5375
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5377   +/-   ##
========================================
  Coverage    93.85%   93.85%           
========================================
  Files          182      182           
  Lines        22505    22508    +3     
  Branches      3200     3200           
========================================
+ Hits         21121    21124    +3     
  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.

Copy link
Copy Markdown
Member

@tylerjereddy tylerjereddy left a comment

Choose a reason for hiding this comment

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

I added some initial comments. Some more info on the LLM/AI usage would be good, currently it just reads:

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

and my review comments suggest that things haven't been checked carefully by a human yet.

Comment thread package/CHANGELOG
Fixes
* TPRReader now exposes box dimensions when loading TPR files
as coordinates-only Universes, fixing missing `Universe.dimensions`
values. (Issue #5375, PR #27)
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.

what is PR 27?

)


class TestTPRBoxVectors:
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.

shouldn't this testing live in the coordinate namespace since the "coordinates-only Universe" is emphasized and the changes are made in package/MDAnalysis/coordinates/TPR.py?

tpr_utils.extract_box_info(data, th.fver)
box_info = tpr_utils.extract_box_info(data, th.fver)
# box vectors are stored in nm
box_angstrom = np.array(box_info.size) * 10.0
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.

the unit handling needs some discussion/consideration, per Irfan's comments at: #5374 (comment)

I think I may open yet another issue about this, because the matter is actually a bit complex/confusing at the moment


u = mda.Universe(TPR)

assert u.dimensions is not None
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.

This test case is not well thought out -- it serves no value whatsoever alongside the one below, since they use the same TPR and this just checks that the attribute is not None...


def test_tpr_only_dimensions_shape(self):
import MDAnalysis as mda
from MDAnalysisTests.datafiles import TPR
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.

This pattern of scoping imports inside functions like this is a hallmark of LLM/AI usage, and not really checking the work very carefully.

We do generally expect contributions to review work carefully, whether they use an LLM or not.


u = mda.Universe(TPR)

assert u.dimensions.shape == (6,)
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.

We expect testing to be a bit more thorough than this:

  1. check the actual values make sense--could easily break things while retaining the correct shape
  2. probably check some different TPR files/box types in a parametrized test

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.

ENH: support reading box vectors from TPR files

2 participants