Module errors that collects all exceptions.

This commit is contained in:
Niels Müller
2016-06-07 16:19:39 +02:00
parent 0033cede6d
commit 9c00242e2c
3 changed files with 36 additions and 4 deletions

View File

@ -5,3 +5,21 @@ Python wrapper for the gromacs library.
from .tpxio import TPXReader
from .xtcio import XTCReader
# from .enxio import EDRFile
from .errors import FileTypeError
from .gromacs.reader import index_filename_for_xtc
FILE_EXTENSIONS = {
'xtc': XTCReader,
'tpr': TPXReader
}
def open(filename):
"""Open a supported gromacs file with the appropiate reader."""
ext = filename.split('.')[-1]
if ext in FILE_EXTENSIONS:
if ext in ['xtc']:
indexfile = index_filename_for_xtc(filename)
return FILE_EXTENSIONS[ext](filename, indexfile)
else:
raise FileTypeError('Filetype {} not supported by pygmx.'.format(ext))