Skip to content
Closed
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ Chronological list of authors
2026
- Mohammad Ayaan
- Khushi Phougat
- Suriya Sureshkumar

External code
-------------
Expand Down
3 changes: 3 additions & 0 deletions package/MDAnalysis/coordinates/GSD.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions testsuite/MDAnalysisTests/coordinates/test_gsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#
import os

import numpy as np
import pytest
from numpy.testing import assert_almost_equal

Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion testsuite/MDAnalysisTests/coordinates/test_xdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading