Skip to content

Commit e2e0455

Browse files
test for NCRST
1 parent 30a2b12 commit e2e0455

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

testsuite/MDAnalysisTests/coordinates/test_netcdf.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
DLP_CONFIG,
4242
CPPTRAJ_TRAJ_TOP,
4343
CPPTRAJ_TRAJ,
44+
PRMNCRST,
45+
TRJNCRST,
4446
)
4547
from MDAnalysisTests.coordinates.test_trj import _TRJReaderTest
4648
from MDAnalysisTests.coordinates.reference import RefVGV, RefTZ2
@@ -389,6 +391,72 @@ def test_warn_user_no_time_information(self, u):
389391
u2 = mda.Universe(CPPTRAJ_TRAJ_TOP, CPPTRAJ_TRAJ)
390392

391393

394+
class TestNCDFReader5(object):
395+
"""NCRST Restart File with positions and forces, exported by CPPTRAJ.
396+
397+
Contributed by Jeremy M. G. Leung
398+
"""
399+
400+
prec = 6
401+
402+
@pytest.fixture(scope="class")
403+
def u(self):
404+
return mda.Universe(PRMNCRST, TRJNCRST)
405+
406+
def test_positions(self, u):
407+
"""Check positions on first frame"""
408+
u.trajectory[0]
409+
ref_1 = np.array(
410+
[
411+
[-1.1455358, -2.0177484, -0.55771565],
412+
[-0.19042611, -2.2511053, -1.0282656],
413+
[ 0.53238064, -1.5778863, -0.56737846],
414+
],
415+
dtype=np.float64,
416+
)
417+
assert_almost_equal(ref_1, u.atoms.positions[:3], self.prec)
418+
419+
def test_velocities(self, u):
420+
"""Check forces on first frame"""
421+
u.trajectory[0]
422+
ref_1 = np.array(
423+
[
424+
[11.86471367, 31.22108269, -4.03538418],
425+
[7.36676359, -4.68035316, 1.78124952],
426+
[12.86675262, 1.39324546, -14.97190762],
427+
],
428+
dtype=np.float64,
429+
)
430+
assert_almost_equal(ref_1, u.atoms.velocities[:3], self.prec)
431+
432+
def test_forces(self, u):
433+
"""Check forces on first frame"""
434+
u.trajectory[0]
435+
ref_1 = np.array(
436+
[
437+
[-9.7262249, -0.37627634, -24.79876137],
438+
[-32.43384552, 37.47783279, -12.45422745],
439+
[24.10939026, -19.80618095, -17.09523582],
440+
],
441+
dtype=np.float64,
442+
)
443+
assert_almost_equal(ref_1, u.atoms.forces[:3], self.prec)
444+
445+
def test_time(self, u):
446+
"""Check time on first frame"""
447+
ref = 5.0
448+
assert_almost_equal(ref, u.trajectory[0].time, self.prec)
449+
450+
def test_dt(self, u):
451+
"""Default 1.0 fs"""
452+
ref = 1.0
453+
assert_almost_equal(ref, u.trajectory.dt, self.prec)
454+
assert_almost_equal(ref, u.trajectory.ts.dt, self.prec)
455+
456+
def test_box(self, u):
457+
assert u.trajectory[0].dimensions is None
458+
459+
392460
class _NCDFGenerator(object):
393461
"""A class for generating abitrary ncdf files and exhaustively test
394462
edge cases which might not be found in the wild"""
Binary file not shown.

testsuite/MDAnalysisTests/datafiles.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@
191191
"CPPTRAJ_TRAJ_TOP",
192192
"CPPTRAJ_TRAJ", # Amber ncdf extracted from CPPTRAJ without time variable
193193
"PRMcs", # Amber (format, Issue 1331)
194-
"PRMNCRST", # Amber ncrst with positions/forces/velocities
194+
"PRMNCRST", # Amber topology for ncrst with positions/forces/velocities
195+
"TRJNCRST", # Amber ncrst with positions/forces/velocties
195196
"PRM_NCBOX",
196197
"TRJ_NCBOX", # Amber parm7 + nc w/ pos/forces/vels/box
197198
"PRMNEGATIVE", # Amber negative ATOMIC_NUMBER (Issue 2306)
@@ -662,6 +663,7 @@
662663
PRMcs = (_data_ref / "Amber/chitosan.prmtop").as_posix()
663664

664665
PRMNCRST = (_data_ref / "Amber/ace_mbondi3.parm7").as_posix()
666+
TRJNCRST = (_data_ref / "Amber/ace_mbondi3.ncrst").as_posix()
665667

666668
PRM_NCBOX = (_data_ref / "Amber/ace_tip3p.parm7").as_posix()
667669
TRJ_NCBOX = (_data_ref / "Amber/ace_tip3p.nc").as_posix()

0 commit comments

Comments
 (0)