Commit f0d9458c authored by Lee-Ping Wang's avatar Lee-Ping Wang
Browse files

Check for presence of gzip and bz2 modules

parent 8e656070
...@@ -31,8 +31,16 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. ...@@ -31,8 +31,16 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
__author__ = "Peter Eastman" __author__ = "Peter Eastman"
__version__ = "1.0" __version__ = "1.0"
import bz2 try:
import gzip import bz2
have_bz2 = True
except: have_bz2 = False
try:
import gzip
have_gzip = True
except: have_gzip = False
import simtk.openmm as mm import simtk.openmm as mm
import simtk.unit as unit import simtk.unit as unit
import math import math
...@@ -71,8 +79,12 @@ class StateDataReporter(object): ...@@ -71,8 +79,12 @@ class StateDataReporter(object):
# Detect the desired compression scheme from the filename extension # Detect the desired compression scheme from the filename extension
# and open all files unbuffered # and open all files unbuffered
if file.endswith('.gz'): if file.endswith('.gz'):
if not have_gzip:
raise RuntimeError("Cannpt write .gz file because Python could not import gzip library")
self._out = gzip.GzipFile(fileobj=open(file, 'wb', 0)) self._out = gzip.GzipFile(fileobj=open(file, 'wb', 0))
elif file.endswith('.bz2'): elif file.endswith('.bz2'):
if not have_bz2:
raise RuntimeError("Cannpt write .bz2 file because Python could not import bz2 library")
self._out = bz2.BZ2File(file, 'w', 0) self._out = bz2.BZ2File(file, 'w', 0)
else: else:
self._out = open(file, 'w', 0) self._out = open(file, 'w', 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment