Skip to content

Commit

Permalink
pdb hack
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwoods2 committed Apr 19, 2024
1 parent 73acc9b commit c6bbc2e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions package/MDAnalysis/coordinates/PDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@
from ..topology.core import guess_atom_element
from ..exceptions import NoDataError

try:
import s3fs
except ImportError:
HAS_S3FS = False
else:
HAS_S3FS = True


logger = logging.getLogger("MDAnalysis.coordinates.PBD")

Expand Down Expand Up @@ -267,6 +274,12 @@ def __init__(self, filename, **kwargs):
frame numbers.
"""
super(PDBReader, self).__init__(filename, **kwargs)

if HAS_S3FS:
if isinstance(filename, s3fs.S3File):
self.filename = filename
self._s3fs = filename.fs
self._fname = filename.bucket + "/" + filename.key

try:
self.n_atoms = kwargs['n_atoms']
Expand Down Expand Up @@ -368,8 +381,12 @@ def Writer(self, filename, **kwargs):
def _reopen(self):
# Pretend the current TS is -1 (in 0 based) so "next" is the
# 0th frame
self.close()
self._pdbfile = util.anyopen(self.filename, 'rb')
if HAS_S3FS:
if isinstance(self._pdbfile, s3fs.S3File):
self._pdbfile = s3fs.S3File(self._s3fs, self._fname)
self._pdbfile = util.anyopen(self._pdbfile, 'rb')
else:
self._pdbfile = util.anyopen(self.filename, 'rb')
self.ts.frame = -1

def _read_next_timestep(self, ts=None):
Expand Down

0 comments on commit c6bbc2e

Please sign in to comment.