diff --git a/package/AUTHORS b/package/AUTHORS index 973f1dd794..38090a9334 100644 --- a/package/AUTHORS +++ b/package/AUTHORS @@ -270,6 +270,7 @@ Chronological list of authors 2026 - Mohammad Ayaan - Khushi Phougat + - Suriya Sureshkumar External code ------------- diff --git a/package/MDAnalysis/coordinates/GSD.py b/package/MDAnalysis/coordinates/GSD.py index 8212037e92..8874df048a 100644 --- a/package/MDAnalysis/coordinates/GSD.py +++ b/package/MDAnalysis/coordinates/GSD.py @@ -128,7 +128,10 @@ def _reopen(self): self.open_trajectory() def _read_frame(self, frame): + # Convert numpy integer types to Python int for gsd compatibility + # GSD's HOOMDTrajectory only accepts Python int, not np.int64 try: + frame = int(frame) myframe = self._file[frame] except IndexError: raise IOError from None diff --git a/testsuite/MDAnalysisTests/coordinates/test_gsd.py b/testsuite/MDAnalysisTests/coordinates/test_gsd.py index 102b8391df..e547855046 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_gsd.py +++ b/testsuite/MDAnalysisTests/coordinates/test_gsd.py @@ -22,6 +22,7 @@ # import os +import numpy as np import pytest from numpy.testing import assert_almost_equal @@ -73,3 +74,29 @@ def test_gsd_dimensions(self, GSD_U): def test_gsd_data_step(self, GSD_U): assert GSD_U.trajectory[0].data["step"] == 0 assert GSD_U.trajectory[1].data["step"] == 500 + + def test_gsd_numpy_int_indexing(self, GSD_U): + """Test that GSDReader accepts numpy integer types (Issue #5224). + + The parallelization framework generates frame indices as np.int64, + but GSD's HOOMDTrajectory only accepts Python int. This test ensures + the reader properly converts numpy scalar integers. + """ + # Test with np.int64 (most common from numpy arrays) + ts = GSD_U.trajectory[np.int64(0)] + assert ts.frame == 0 + + # Test with negative indexing + ts = GSD_U.trajectory[np.int64(-1)] + assert ts.frame == 1 + + # Test with other numpy integer types + ts = GSD_U.trajectory[np.int32(1)] + assert ts.frame == 1 + + # Directly test _read_frame with numpy integers to ensure coverage + ts = GSD_U.trajectory._read_frame(np.int64(0)) + assert ts.frame == 0 + + ts = GSD_U.trajectory._read_frame(np.int32(1)) + assert ts.frame == 1 \ No newline at end of file diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 2a2f236924..7440fda165 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -1058,7 +1058,6 @@ def test_persistent_offsets_readonly(self, tmpdir, trajectory): def test_offset_lock_created(self, traj): assert os.path.exists(XDR.offsets_filename(traj, ending="lock")) - class TestXTCReader_offsets(_GromacsReader_offsets): __test__ = True filename = XTC