[ase-users] Open trajectories from tarfile
Peterson, Andrew
andrew_peterson at brown.edu
Fri Dec 16 15:27:58 CET 2016
I have a large number of trajectories contained in a tarfile, e.g.,
trajectories.tar.gz:
subdir1/
1.traj
2.traj
...
I was expecting that I could open a trajectory without writing the
extracted file out to disk with something like this:
import tarfile
from ase import io
tf = tarfile.open('trajectories.tar.gz')
f = tf.extractfile('subdir1/2.traj')
traj = io.Trajectory(f)
Note that in the above, f is a file-like object and f.closed is False. But
if I try that, I get the below error. It appears to be traced back to
something in numpy. I know that this is a rather non-typical use-case --
but does anyone know of a workaround or a solution to this apparent bug?
File "<stdin>", line 1, in <module>
File "repositories/ase/ase/io/trajectory.py", line 46, in Trajectory
return TrajectoryReader(filename)
File "repositories/ase/ase/io/trajectory.py", line 222, in __init__
self._open(filename)
File "repositories/ase/ase/io/trajectory.py", line 227, in _open
self.backend = ulmopen(filename, 'r')
File "repositories/ase/ase/io/ulm.py", line 73, in ulmopen
return Reader(filename, index or 0)
File "repositories/ase/ase/io/ulm.py", line 334, in __init__
self._offsets) = read_header(fd)
File "repositories/ase/ase/io/ulm.py", line 312, in read_header
version, nitems, pos0 = readints(fd, 3)
File "repositories/ase/ase/io/ulm.py", line 101, in readints
a = np.fromfile(fd, np.int64, n)
IOError: first argument must be an open file
Andy
--
Andrew Peterson
Assistant Professor
Brown University School of Engineering
Barus & Holley 247
184 Hope Street
Providence, RI 02912
(401) 863-2153
http://brown.edu/go/catalyst
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20161216/d0b44f4b/attachment-0001.html>
More information about the ase-users
mailing list