Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
6a75d39
Adds basic framework for reading NCRST files
Sep 2, 2018
5a88100
Removing unused imports
Sep 2, 2018
8b7dbd5
Major updates to NCRST reader
Sep 4, 2018
0c457ce
Try/except instead of it statements + docstring changes
Sep 5, 2018
d245e33
64 bit offset check
Sep 7, 2018
33cbe3e
Merge branch 'develop' into NCrestart
May 28, 2019
b420032
Need to check things
May 28, 2019
08bb2b1
Merge branch 'develop' into NCrestart
Aug 2, 2019
7676741
Some changes
Aug 5, 2019
a382762
Merge branch 'develop' into NCrestart
IAlibay Aug 5, 2019
df24168
Exception + Minor docs update
IAlibay Aug 6, 2019
93f2edb
More exceptions + start on tests
IAlibay Aug 6, 2019
78e92d0
More inpcrd changes and tests
IAlibay Aug 7, 2019
474ab59
Error type change
IAlibay Aug 7, 2019
e5d7cb6
Changes to match initial PR 2326
IAlibay Aug 16, 2019
cee802c
Merge branch 'develop' into NCrestart
IAlibay Aug 19, 2019
2554ff0
Swapping to ValueErrors
IAlibay Aug 19, 2019
8cc8161
Update _verify_units and typos
IAlibay Aug 19, 2019
5277cd0
Merge branch 'develop' into NCrestart
IAlibay Dec 29, 2019
f9d2ab5
Merge branch 'MDAnalysis:develop' into NCrestart
IAlibay Nov 30, 2022
bcc58c8
Update INPCRD.py
IAlibay Nov 30, 2022
30a2b12
working commit
jeremyleung521 Apr 16, 2025
e2e0455
test for NCRST
jeremyleung521 Apr 17, 2025
d6627c7
changelog + authors
jeremyleung521 Apr 17, 2025
c5988e6
Merge branch 'develop' of github.com:mdanalysis/mdanalysis into ncrst…
jeremyleung521 Apr 17, 2025
fb0d2e9
lint test_netcdf.py
jeremyleung521 Apr 17, 2025
0f27fc4
small code cleanup of TRJ.py
jeremyleung521 Apr 17, 2025
eb83b42
small formatting in CHANGELOG
jeremyleung521 Apr 17, 2025
eb7ba03
Merge branch 'develop' into ncrst-reader
jeremyleung521 Apr 19, 2025
50eb893
Merge branch 'develop' of github.com:mdanalysis/mdanalysis into ncrst…
jeremyleung521 May 22, 2025
abfb5a7
Merge branch 'pr/3942' into ncrst-reader
jeremyleung521 May 22, 2025
d98ebab
working, failing ExceptionWarning Tests
jeremyleung521 May 22, 2025
37b7e1e
cleanup
jeremyleung521 May 22, 2025
736db88
make NCRST work
jeremyleung521 May 27, 2025
2ab9fe1
typo in SingleFrameReaderBase
jeremyleung521 May 27, 2025
14daa07
Merge branch 'ncrst-reader' of github.com:jeremyleung521/MDAnalysis i…
jeremyleung521 May 27, 2025
5bf1ce0
Revert "typo in SingleFrameReaderBase"
jeremyleung521 May 27, 2025
614f9f6
black lint
jeremyleung521 May 27, 2025
bf68954
Reapply "typo in SingleFrameReaderBase"
jeremyleung521 May 27, 2025
264215f
black lint
jeremyleung521 May 27, 2025
01234f1
Merge branch 'develop' of github.com:jeremyleung521/MDAnalysis into n…
jeremyleung521 Jun 12, 2025
6613a27
fix tests
jeremyleung521 Jun 12, 2025
4dcbf2f
Merge branch 'develop' of github.com:mdanalysis/mdanalysis into ncrst…
jeremyleung521 Jun 26, 2025
eca17ab
fix docstring
jeremyleung521 Jun 26, 2025
aac6b8a
Merge branch 'develop' of github.com:mdanalysis/mdanalysis into ncrst…
jeremyleung521 Jul 22, 2025
b44df73
typo and doc-links fix
jeremyleung521 Jul 22, 2025
32848f4
doc update
jeremyleung521 Jul 22, 2025
9262e75
n_frames now read during init
jeremyleung521 Jul 22, 2025
ec8fd95
update tests
jeremyleung521 Jul 22, 2025
444ece0
lint for test_netcdf.py
jeremyleung521 Jul 22, 2025
921bc34
Merge branch 'develop' into ncrst-reader
yuxuanzhuang Aug 5, 2025
fbcf292
Merge branch 'develop' into ncrst-reader
jeremyleung521 Aug 7, 2025
1e4aba1
Merge branch 'develop' into ncrst-reader
jeremyleung521 Oct 13, 2025
44f5dd4
bump PR to v2.11.0
jeremyleung521 Oct 13, 2025
a52a573
Enhancements
jeremyleung521 Oct 13, 2025
3ac1abd
Merge branch 'develop' into ncrst-reader
jeremyleung521 Oct 14, 2025
d66dc43
Merge branch 'develop' into ncrst-reader
jeremyleung521 Oct 16, 2025
ab2c6c9
Merge branch 'develop' into ncrst-reader
jeremyleung521 Oct 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ Chronological list of authors
- Abdulrahman Elbanna
- Tulga-Erdene Sodjargal
- Gareth Elliott
- Marc Schuh
- Jeremy M.G. Leung


External code
-------------

Expand Down
5 changes: 4 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The rules for this file:
-------------------------------------------------------------------------------
??/??/?? IAlibay, orbeckst, BHM-Bob, TRY-ER, Abdulrahman-PROG, pbuslaev,
yuxuanzhuang, yuyuan871111, tanishy7777, jpkrowe, tulga-rdn,
Gareth-elliott, hmacdope, jeremyleung521
Gareth-elliott, hmacdope, tylerjereddy, cbouy, jeremyleung521

* 2.10.0

Expand All @@ -41,6 +41,9 @@ Fixes
Enhancements
* Allow NCDF reader to read Amber Restart Files with extension `.ncrst`
(Issue #5030, PR #5031)
* Added `TemplateInferrer` and `RDKitInferrer` dataclasses to the
`RDKitInferring` module to be used by the RDKit converter. (PR #4305)
* Improve speed of GROMOS11 (TRC) reader (Issue #5079, PR #5080)
* Improve parsing of topology information from LAMMPS dump files to allow
reading of mass, charge and element attributes. (Issue #3449, PR #4995)
* Added timestep support for XDR writers and readers (Issue #4905, PR #4908)
Expand Down
15 changes: 8 additions & 7 deletions package/MDAnalysis/coordinates/INPCRD.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#


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

AMBER_ can write :ref:`ASCII restart<ascii-restart>` ("inpcrd") and
Expand Down Expand Up @@ -76,7 +76,7 @@
.. Links

.. _AMBER: http://ambermd.org
.. _AMBER INPCRD FORMAT: http://ambermd.org/formats.html#restart
.. _AMBER INPCRD FORMAT: https://ambermd.org/FileFormats.php#restart
.. _AMBER netcdf: http://ambermd.org/netcdf/nctraj.xhtml
.. _NetCDF: http://www.unidata.ucar.edu/software/netcdf

Expand All @@ -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
.. versionchanged: 2.10.0
Now automatically detects files with .rst7 extension.

"""
Expand Down Expand Up @@ -158,7 +158,7 @@ class NCRSTReader(base.SingleFrameReaderBase, NCDFMixin):
"""Reader for `AMBER NETCDF format`_ (version 1.0 rev C) restart files.

This reader is a :class:`SingleFrameReaderBase` adaptation of the
:class:`NCDFReader` AMBER NETCDF trajectory reader.
:class:`~MDAnalysis.coordinates.TRJ.NCDFReader` AMBER NETCDF trajectory reader.

AMBER binary restart files are automatically recognised by the file
extensions ".ncrst", ".ncrestrt", and ".ncrst7".
Expand All @@ -181,7 +181,8 @@ class NCRSTReader(base.SingleFrameReaderBase, NCDFMixin):
``[0,0,0,0,0,0]``).

Support for the *mmap* keyword is available as detailed
in :class:`NCDFReader` and :mod:`scipy.io.netcdf.netcdf_file`. The use of
in :class:`~MDAnalysis.coordinates.TRJ.NCDFReader` and
:mod:`scipy.io.netcdf.netcdf_file`. The use of
``mmap=True`` leads to around a 2x read speed improvement in a ~ 1 million
atom system (AMBER STMV benchmark). As per the :class:`NCDFReader`, the
default behaviour is ``mmap=None``, which means that the default behaviour
Expand All @@ -201,8 +202,8 @@ class NCRSTReader(base.SingleFrameReaderBase, NCDFMixin):

See Also
--------
:class:`NCDFReader`
:class:`NCDFWriter`
:class:`~MDAnalysis.coordinates.TRJ.NCDFReader`
:class:`~MDAnalysis.coordinates.TRJ.NCDFWriter`


.. versionadded: 2.10.0
Expand Down
17 changes: 0 additions & 17 deletions package/MDAnalysis/coordinates/TRJ.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,23 +435,6 @@ def _check_conventions(self, n_atoms=None):
"information".format(file_format, self.filename))
raise ValueError(errmsg) from None

# try:
# self.n_frames = self.trjfile.dimensions['frame']
# # example trajectory when read with scipy.io.netcdf has
# # dimensions['frame'] == None (indicating a record dimension that
# # can grow) whereas if read with netCDF4 I get
# # len(dimensions['frame']) == 10: in any case, we need to get
# # the number of frames from somewhere such as the time variable:
# if self.n_frames is None:
# self.n_frames = self.trjfile.variables['coordinates'].shape[0]
# except KeyError:
# if self.is_restart:
# self.n_frames = 1
# else:
# errmsg = ("NCDF {file_format} {self.filename} does not contain "
# "frame information").format
# raise ValueError(errmsg) from None

try:
self.remarks = self.trjfile.title
except AttributeError:
Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/coordinates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class can choose an appropriate reader automatically.
| | | | velocities). Module :mod:`MDAnalysis.coordinates.TRJ`|
+---------------+-----------+-------+------------------------------------------------------+
| AMBER | ncrst, | r | binary (NetCDF) restart file |
| | ncrestrt, | | Module :mod:`MDAnalysis.coordinates.INPCRD |
| | ncrestrt, | | Module :mod:`MDAnalysis.coordinates.INPCRD` |
| | ncrst7 | | |
+---------------+-----------+-------+------------------------------------------------------+
| Brookhaven | pdb/ent | r/w | a relaxed PDB format (as used in MD simulations) |
Expand Down
21 changes: 0 additions & 21 deletions testsuite/MDAnalysisTests/coordinates/test_ncrst.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,6 @@ def test_positions_resid42(self, universe):
assert_almost_equal(expected, ag.positions, self.prec)


# def test_velocities(self, universe, selstr, expected):
# ag = universe.select_atoms(selstr)
# assert_almost_equal(expected, ag.velocities, self.prec)
#
# def test_forces(self, universe, selstr, expected):
# ag = universe.select_atoms(selstr)
# # We convert from kj back to the original kcal value
# assert_almost_equal(expected, ag.forces * 4.184, self.prec)


class _NCRSTGenerator(object):
"""A basic modular ncrst writer based on :class:`NCDFWriter`"""

Expand Down Expand Up @@ -293,17 +283,6 @@ def test_not_implemented_errors(self, tmpdir, key, value):
with pytest.raises(NotImplementedError):
NCRSTReader(params["filename"])

# @pytest.mark.parametrize('value', [
# 'time', 'coordinates', 'spatial',
# 'velocities', 'forces'
# ])
# def test_scale_factor(self, tmpdir, value):
# params = self.gen_params(key='scale_factor', value=value)
# with tmpdir.as_cwd():
# self.create_ncrst(params)
# with pytest.raises(NotImplementedError):
# NCRSTReader(params['filename'])

def test_conventionversion_warn(self, tmpdir):
params = self.gen_params(key="ConventionVersion", value="2.0")
with tmpdir.as_cwd():
Expand Down
156 changes: 78 additions & 78 deletions testsuite/MDAnalysisTests/coordinates/test_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,70 +390,70 @@ def test_warn_user_no_time_information(self, u):
u2 = mda.Universe(CPPTRAJ_TRAJ_TOP, CPPTRAJ_TRAJ)


# class TestNCDFReader5(object):
# """NCRST Restart File with positions and forces, exported by CPPTRAJ.
#
# Contributed by Jeremy M. G. Leung
# """
#
# prec = 6
#
# @pytest.fixture(scope="class")
# def u(self):
# return mda.Universe(PRMNCRST, TRJNCRST)
#
# def test_positions(self, u):
# """Check positions on first frame"""
# u.trajectory[0]
# ref_1 = np.array(
# [
# [-1.1455358, -2.0177484, -0.55771565],
# [-0.19042611, -2.2511053, -1.0282656],
# [0.53238064, -1.5778863, -0.56737846],
# ],
# dtype=np.float64,
# )
# assert_almost_equal(ref_1, u.atoms.positions[:3], self.prec)
#
# def test_velocities(self, u):
# """Check forces on first frame"""
# u.trajectory[0]
# ref_1 = np.array(
# [
# [11.86471367, 31.22108269, -4.03538418],
# [7.36676359, -4.68035316, 1.78124952],
# [12.86675262, 1.39324546, -14.97190762],
# ],
# dtype=np.float64,
# )
# assert_almost_equal(ref_1, u.atoms.velocities[:3], self.prec)
#
# def test_forces(self, u):
# """Check forces on first frame"""
# u.trajectory[0]
# ref_1 = np.array(
# [
# [-9.7262249, -0.37627634, -24.79876137],
# [-32.43384552, 37.47783279, -12.45422745],
# [24.10939026, -19.80618095, -17.09523582],
# ],
# dtype=np.float64,
# )
# assert_almost_equal(ref_1, u.atoms.forces[:3], self.prec)
#
# def test_time(self, u):
# """Check time on first frame"""
# ref = 5.0
# assert_almost_equal(ref, u.trajectory[0].time, self.prec)
#
# def test_dt(self, u):
# """Default 1.0 fs"""
# ref = 1.0
# assert_almost_equal(ref, u.trajectory.dt, self.prec)
# assert_almost_equal(ref, u.trajectory.ts.dt, self.prec)
#
# def test_box(self, u):
# assert u.trajectory[0].dimensions is None
class TestNCDFReader5(object):
"""NCRST Restart File with positions and forces, exported by CPPTRAJ.

Contributed by Jeremy M. G. Leung
"""

prec = 6

@pytest.fixture(scope="class")
def u(self):
return mda.Universe(PRMNCRST, TRJNCRST)

def test_positions(self, u):
"""Check positions on first frame"""
u.trajectory[0]
ref_1 = np.array(
[
[-1.1455358, -2.0177484, -0.55771565],
[-0.19042611, -2.2511053, -1.0282656],
[0.53238064, -1.5778863, -0.56737846],
],
dtype=np.float64,
)
assert_almost_equal(ref_1, u.atoms.positions[:3], self.prec)

def test_velocities(self, u):
"""Check forces on first frame"""
u.trajectory[0]
ref_1 = np.array(
[
[11.86471367, 31.22108269, -4.03538418],
[7.36676359, -4.68035316, 1.78124952],
[12.86675262, 1.39324546, -14.97190762],
],
dtype=np.float64,
)
assert_almost_equal(ref_1, u.atoms.velocities[:3], self.prec)

def test_forces(self, u):
"""Check forces on first frame"""
u.trajectory[0]
ref_1 = np.array(
[
[ -2.32462358, -0.0899322 , -5.9270463 ],
[ -7.7518754 , 8.95741653, -2.97663188],
[ 5.76228237, -4.73379087, -4.0858593 ],
],
dtype=np.float64,
)
assert_almost_equal(ref_1, u.atoms.forces[:3], self.prec)

def test_time(self, u):
"""Check time on first frame"""
ref = 5.0
assert_almost_equal(ref, u.trajectory[0].time, self.prec)

def test_dt(self, u):
"""Default 1.0 fs"""
ref = 1.0
assert_almost_equal(ref, u.trajectory.dt, self.prec)
assert_almost_equal(ref, u.trajectory.ts.dt, self.prec)

def test_box(self, u):
assert u.trajectory[0].dimensions is None


class _NCDFGenerator(object):
Expand Down Expand Up @@ -853,20 +853,20 @@ def _test_write_trajectory(self, universe, outfile):
# See http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.dtypes.html
# and https://github.com/MDAnalysis/mdanalysis/pull/503
with netcdf_file(outfile, "r") as dataset:
coords = dataset.variables["coordinates"][...]
time = dataset.variables["time"][...]
assert_equal(
coords[:].dtype.name,
np.dtype(np.float32).name,
err_msg="ncdf coord output not float32 "
"but {}".format(coords[:].dtype),
)
assert_equal(
time[:].dtype.name,
np.dtype(np.float32).name,
err_msg="ncdf time output not float32 "
"but {}".format(time[:].dtype),
)
coords = dataset.variables["coordinates"]
time = dataset.variables["time"]
assert_equal(
coords[:].dtype.name,
np.dtype(np.float32).name,
err_msg="ncdf coord output not float32 "
"but {}".format(coords[:].dtype),
)
assert_equal(
time[:].dtype.name,
np.dtype(np.float32).name,
err_msg="ncdf time output not float32 "
"but {}".format(time[:].dtype),
)

def test_write_trajectory_netCDF4(self, universe, outfile):
pytest.importorskip("netCDF4")
Expand Down
Loading