Generate xtc index in pygmx.open if necessary.

This commit is contained in:
Niels Müller
2016-06-13 11:34:33 +02:00
parent cabd68f287
commit cd562c269a

View File

@ -2,11 +2,14 @@
Python wrapper for the gromacs library. Python wrapper for the gromacs library.
""" """
import os
from .tpxio import TPXReader from .tpxio import TPXReader
from .xtcio import XTCReader from .xtcio import XTCReader
# from .enxio import EDRFile # from .enxio import EDRFile
from .errors import FileTypeError from .errors import FileTypeError
from .gromacs.reader import index_filename_for_xtc from .gromacs.reader import index_filename_for_xtc
from .gromacs.xtcindex import index_xtcfile
FILE_EXTENSIONS = { FILE_EXTENSIONS = {
'xtc': XTCReader, 'xtc': XTCReader,
@ -20,6 +23,11 @@ def open(filename):
if ext in FILE_EXTENSIONS: if ext in FILE_EXTENSIONS:
if ext in ['xtc']: if ext in ['xtc']:
indexfile = index_filename_for_xtc(filename) indexfile = index_filename_for_xtc(filename)
if not os.path.exists(indexfile):
print('Gneerating Index for xtc file. This may take a while...')
index_xtcfile(filename)
return FILE_EXTENSIONS[ext](filename, indexfile) return FILE_EXTENSIONS[ext](filename, indexfile)
else:
return FILE_EXTENSIONS[ext](filename)
else: else:
raise FileTypeError('Filetype {} not supported by pygmx.'.format(ext)) raise FileTypeError('Filetype {} not supported by pygmx.'.format(ext))