Skip to content

Commit

Permalink
ENH: support GROMACS pathlib
Browse files Browse the repository at this point in the history
* the creation of a `Universe` object involving
GROMACS formats should now accept `pathlib`
objects as requested in MDAnalysisgh-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
  • Loading branch information
tylerjereddy committed Nov 22, 2022
1 parent 497f45e commit b811f97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package/MDAnalysis/coordinates/XDR.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions testsuite/MDAnalysisTests/coordinates/test_xdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

0 comments on commit b811f97

Please sign in to comment.