Skip to content

Update NCDF Reader to read .ncrst Restart Files #5031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 50 commits into
base: develop
Choose a base branch
from

Conversation

jeremyleung521
Copy link

@jeremyleung521 jeremyleung521 commented Apr 17, 2025

Fixes #5030

Changes made in this Pull Request:

  • Updated NCDF Reader to read Amber .ncrst restart files
  • Added tests to verify that the ncrst file is readed correctly. The test file I used is created from a .nc file already present in MDAnalysisTest
  • Noticed @jpkrowe did not add himself to the changelog, so also added him 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!)

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

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.

@jeremyleung521
Copy link
Author

Turning this PR into a draft for now, because there is a wide-affecting bug with the SingleFrameReaderBase's n_atoms attribute, which is causing things to fail. (#5052) Will wait for that to fix itself before moving forward, as that needs to be fixed for this to be implemented properly.

@orbeckst
Copy link
Member

Now that #5052 has been fixed, would it be worthwhile to rebase the PR and see if can continue?

@jeremyleung521
Copy link
Author

jeremyleung521 commented Jun 26, 2025

Regarding the status of this PR:

  • The MDAnalysis building failure and the n_atoms variable are both fixed. Those commits are merged in.
  • The main code should be done, the old tests from [WIP] Add NCRestart reader #3942 is ported as well
  • I need to fix/re-integrate the tests in test_netcdf.py I wrote for the previous code back into the newer version. Will do this in the next couple weeks.
  • All tests currently passes

+---------------+-----------+-------+------------------------------------------------------+
| AMBER | ncdf, nc | r/w | binary (NetCDF) trajectories are fully supported with|
| | | | optional `netcdf4-python`_ module (coordinates and |
| | | | velocities). Module :mod:`MDAnalysis.coordinates.TRJ`|
+---------------+-----------+-------+------------------------------------------------------+
| AMBER | ncrst, | r | binary (NetCDF) restart file |
| | ncrestrt, | | Module :mod:`MDAnalysis.coordinates.INPCRD |
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| | ncrestrt, | | Module :mod:`MDAnalysis.coordinates.INPCRD |
| | ncrestrt, | | Module :mod:`MDAnalysis.coordinates.INPCRD` |

.. Links

.. _AMBER: http://ambermd.org
.. _AMBER INPCRD FORMAT: http://ambermd.org/formats.html#restart
Copy link
Contributor

Choose a reason for hiding this comment

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

this link is 404 when I accessed it, maybe this one?

https://ambermd.org/FileFormats.php#restart

@@ -22,29 +22,92 @@
#


"""INPCRD structure files in MDAnalysis --- :mod:`MDAnalysis.coordinates.INPCRD`
"""AMBER restart files in MDAnalysis --- :mod:`MDAnalysis.coordinates.INPCRD`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""AMBER restart files in MDAnalysis --- :mod:`MDAnalysis.coordinates.INPCRD`
"""AMBER coordinate/restart files in MDAnalysis --- :mod:`MDAnalysis.coordinates.INPCRD`


See Also
--------
:class:`NCDFReader`
Copy link
Contributor

Choose a reason for hiding this comment

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

Some hyperlinks to classes within this module are not working. You need to use absolute references, for example,

:mod:`MDAnalysis.coordinates.INPCRD`

errmsg = (f"NCDF trajectory {self.filename} does not contain "
f"frame information")
raise ValueError(errmsg) from None
# try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Please clean up the commented-out code or add a comment explaining why it’s being retained.

@@ -102,7 +102,7 @@ class INPReader(base.SingleFrameReaderBase):
* Box information is not read (or checked for).
* Velocities are currently *not supported*.

.. versionchanged: 0.20.0
Copy link
Member

Choose a reason for hiding this comment

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

Why was this changed?

If you have a new change, add a versionchanged BELOW with a summary of user-relevant changes.

Copy link
Author

@jeremyleung521 jeremyleung521 Jul 22, 2025

Choose a reason for hiding this comment

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

That was from a commit from #3942 when @IAlibay was implementing this (which I git cherry-picked). That PR never got merged/completed. I assume it's because 0.20.0 was the newest version back when this was written. I'm simply reusing some of the docstrings he wrote back then for if/when this is finally merged into develop.
https://github.com/MDAnalysis/mdanalysis/pull/3942/files#diff-866fcc034359780910de97ee91a381661555985d630bfe9d34600f254bc1bb2fR105
(Line 105 in INPCRD.py)

If you check the current develop branch, that versionchanged text isn't there.
https://github.com/MDAnalysis/mdanalysis/blob/develop/package/MDAnalysis/coordinates/INPCRD.py#L45

@jeremyleung521 jeremyleung521 marked this pull request as ready for review July 22, 2025 21:21
@orbeckst
Copy link
Member

orbeckst commented Jul 22, 2025 via email

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.

Support for Amber NetCDF Restart Files (.ncrst)
5 participants