Module errors that collects all exceptions.
This commit is contained in:
@ -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))
|
||||
|
16
pygmx/errors.py
Normal file
16
pygmx/errors.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""Exceptions of the pygmx package."""
|
||||
|
||||
|
||||
class InvalidMagicException(Exception): pass
|
||||
|
||||
|
||||
class InvalidIndexException(Exception): pass
|
||||
|
||||
|
||||
class UnknownLenError(Exception): pass
|
||||
|
||||
|
||||
class FileTypeError(Exception): pass
|
||||
|
||||
|
||||
class XTCError(Exception): pass
|
@ -11,7 +11,8 @@ import os
|
||||
from utility cimport *
|
||||
from math cimport *
|
||||
from fileio cimport *
|
||||
from gromacs.reader import InvalidIndexException, InvalidMagicException, INDEX_MAGIC, SubscriptableReader, XTCFrame
|
||||
from .gromacs.reader import INDEX_MAGIC, SubscriptableReader, XTCFrame
|
||||
from .errors import InvalidIndexException, InvalidMagicException, XTCError
|
||||
|
||||
|
||||
cdef extern from "gromacs/fileio/xtcio.h":
|
||||
@ -67,9 +68,6 @@ cdef array get_xtc_index(t_fileio *fio):
|
||||
return cache[:-1]
|
||||
|
||||
|
||||
class XTCError(Exception): pass
|
||||
|
||||
|
||||
cdef class XTCReader:
|
||||
cdef:
|
||||
t_fileio *fio
|
||||
|
Reference in New Issue
Block a user