From b811f979bbbe9159ba2adadf264e899ff8850e66 Mon Sep 17 00:00:00 2001 From: Tyler Reddy Date: Mon, 21 Nov 2022 20:20:38 -0700 Subject: [PATCH] ENH: support GROMACS pathlib * the creation of a `Universe` object involving GROMACS formats should now accept `pathlib` objects as requested in gh-2497; resolving that issue entirely is a separate matter, this branch focuses only on the GROMACS format and only if you proceed via the public `Universe` creation API * probably could make it work in Cython directly, though I'm not convinced we need to do that for this part of the fix at least, and we probably should still support strings as well of course --- package/MDAnalysis/coordinates/XDR.py | 2 +- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/package/MDAnalysis/coordinates/XDR.py b/package/MDAnalysis/coordinates/XDR.py index c374c310c26..1bd37002009 100644 --- a/package/MDAnalysis/coordinates/XDR.py +++ b/package/MDAnalysis/coordinates/XDR.py @@ -145,7 +145,7 @@ def __init__(self, filename, convert_units=True, sub=None, super(XDRBaseReader, self).__init__(filename, convert_units=convert_units, **kwargs) - self._xdr = self._file(self.filename) + self._xdr = self._file(str(self.filename)) self._sub = sub if self._sub is not None: diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 236db03cbda..2c9cd22e8f0 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -29,6 +29,7 @@ from os.path import split import shutil import subprocess +from pathlib import Path from numpy.testing import (assert_equal, assert_almost_equal, @@ -904,3 +905,14 @@ class TestTRRReader_offsets(_GromacsReader_offsets): 9155712, 10300176 ]) _reader = mda.coordinates.TRR.TRRReader + + +def test_pathlib(): + # regression test for XDR path of + # gh-2497 + top = Path(GRO) + traj = Path(XTC) + u = mda.Universe(top, traj) + # we really only care that pathlib + # object handling worked + assert u.atoms.n_atoms == 47681