Skip to content

Reading a bz2 compressed PSF file fails #2232

@orbeckst

Description

@orbeckst

Expected behavior

I should be able to read a bzip2 compressed file with any of the parsers, in particular the PSF parser.

Actual behavior

Under Python 3, the PSF parser fails on a bzip2 compressed file with

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-90d681257701> in <module>
----> 1 u = mda.Universe(RNA_PSF)

/Volumes/Data/oliver/Biop/Projects/Methods/MDAnalysis/mdanalysis/package/MDAnalysis/core/universe.py in __init__(self, *args, **kwargs)
    290                 try:
    291                     with parser(self.filename) as p:
--> 292                         self._topology = p.parse(**kwargs)
    293                 except (IOError, OSError) as err:
    294                     # There are 2 kinds of errors that might be raised here:

/Volumes/Data/oliver/Biop/Projects/Methods/MDAnalysis/mdanalysis/package/MDAnalysis/topology/PSFParser.py in parse(self, **kwargs)
    130                 next(psffile)
    131             logger.debug("PSF file {0}: format {1}"
--> 132                          "".format(psffile.name, self._format))
    133
    134             # Atoms first and mandatory

AttributeError: 'BZ2File' object has no attribute 'name'

Apparently, under Python 3, the file-like object provided by bz2 does not have a name attribute; the patch https://bugs.python.org/issue24258 never made it into Python 3.6+.

We missed testing bz2 in #336.

Code to reproduce the behavior

import MDAnalysis as mda
from MDAnalysis.tests.datafiles import PSF

# create bz2-compressed file
import bz2

PSFBZ2 = "adk.psf.bz2"
with open(PSFBZ2, "wb") as out:
   buf = bz2.compress(open(PSF, "rb").read())
   out.write(buf)

u = mda.Universe(PSFBZ2)

Currently version of MDAnalysis

  • 0.19.3-dev (develop)
  • 3.6.6
  • macOS 10.12.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions