Added option to ignore timestamps when loading xtc indexfiles.

This commit is contained in:
Niels Müller
2017-06-30 14:34:57 +02:00
parent 2f1d2e8451
commit edc1bd759a
2 changed files with 7 additions and 7 deletions

View File

@ -21,7 +21,7 @@ FILE_EXTENSIONS = {
}
def open(filename):
def open(filename, ignore_index_timestamps=False):
"""Open a supported gromacs file. Currently supported file formats: tpr, xtc."""
ext = filename.split('.')[-1]
if ext in FILE_EXTENSIONS:
@ -30,7 +30,7 @@ def open(filename):
if not os.path.exists(indexfile):
print('Generating Index for xtc file. This may take a while...')
index_xtcfile(filename)
return FILE_EXTENSIONS[ext](filename, indexfile)
return FILE_EXTENSIONS[ext](filename, indexfile, ignore_timestamps=ignore_index_timestamps)
else:
return FILE_EXTENSIONS[ext](filename)
else:

View File

@ -115,7 +115,7 @@ cdef class XTCReader:
self._cache = get_xtc_index(self.fio)
self.has_cache = True
def load_cache(self, indexfile):
def load_cache(self, indexfile, ignore_time=False):
xtc_stat = os.stat(self.filename)
c_time = int(xtc_stat.st_ctime)
@ -127,9 +127,9 @@ cdef class XTCReader:
if unpacker.unpack_hyper() != INDEX_MAGIC:
raise InvalidMagicException
if unpacker.unpack_hyper() != c_time:
if unpacker.unpack_hyper() != c_time and not ignore_time:
raise InvalidIndexException
if unpacker.unpack_hyper() != m_time:
if unpacker.unpack_hyper() != m_time and not ignore_time:
raise InvalidIndexException
if unpacker.unpack_hyper() != size:
raise InvalidIndexException
@ -149,7 +149,7 @@ cdef class XTCReader:
self.has_cache = False
self.has_times = False
def __init__(self, filename, indexfile=None, make_cache=False):
def __init__(self, filename, indexfile=None, make_cache=False, ignore_timestamps=False):
if isinstance(filename, str):
self.filename = filename
filename = filename.encode()
@ -173,7 +173,7 @@ cdef class XTCReader:
if indexfile is not None:
try:
self.load_cache(indexfile)
self.load_cache(indexfile, ignore_time=ignore_timestamps)
except InvalidIndexException:
if make_cache:
pass