Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to read XDR offsets is a fatal error #1893

Closed
richardjgowers opened this issue May 8, 2018 · 5 comments · Fixed by #2611
Closed

Failing to read XDR offsets is a fatal error #1893

richardjgowers opened this issue May 8, 2018 · 5 comments · Fixed by #2611

Comments

@richardjgowers
Copy link
Member

Sometimes loading xdr offsets fails.

  File "/home/user/miniconda2/envs/env/lib/python2.7/site-packages/MDAnalysis/coordinates/XDR.py", line 84, in read_numpy_offsets
    return {k: v for k, v in six.iteritems(np.load(filename))}
  File "/home/user/miniconda2/envs/env/lib/python2.7/site-packages/numpy/lib/npyio.py", line 429, in load
    "Failed to interpret file %s as a pickle" % repr(file))
IOError: Failed to interpret file '/host/user/dir/files/.file.xtc_offsets.npz' as a pickle

This shouldn't cause the entire file loading process to fail. It should be possible wrap offset loading in a try/except to regenerate the offsets if needed

@orbeckst
Copy link
Member

orbeckst commented May 8, 2018

If we put in an try/except then we should also spit out a error warning message with as much detail about the file as we can so that we might have a chance to figure out why this is happening.

@lilyminium
Copy link
Member

For now, does deleting the offset file fix this by forcing offsets to regenerate?

@orbeckst
Copy link
Member

orbeckst commented Nov 7, 2019

I am saying yes (until someone proves me wrong) – this should always work.

@zemanj
Copy link
Member

zemanj commented Nov 7, 2019

Better workaround: IIRC XDRBaseReader has a refresh_offsets kwarg which forces the reader to regenerate frame offsets.

@orbeckst
Copy link
Member

orbeckst commented Nov 9, 2019

You're correct @zemanj , MDAnalysis.coordinates.XDR.XDRBaseReader and therefore the XTCReader and TRRReader have refresh_offsets so one can just do

u = mda.Universe(data.TPR, data.XTC, refresh_offsets=True)

as demonstrated here by monitoring the last-modified time of the offset file:

>>> import MDAnalysis as mda; from MDAnalysis.tests import datafiles as data
>>> import os
>>> u = mda.Universe(data.TPR, data.XTC)
>>> offset_file = mda.coordinates.XDR.offsets_filename(u.trajectory.filename)
>>> print(offset_file)
~/anaconda3/envs/mda3/lib/python3.6/site-packages/MDAnalysisTests/data/.adk_oplsaa.xtc_offsets.npz
>>> print(os.path.getmtime(offset_file))
1573257681.0
>>> # load again: nothing changes
>>> u = mda.Universe(data.TPR, data.XTC)
>>> print(os.path.getmtime(offset_file))
1573257681.0
>>> # refresh: offset file is modified
>>> u = mda.Universe(data.TPR, data.XTC, refresh_offsets=True)
>>> print(os.path.getmtime(offset_file))
1573257862.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants