From cd562c269ace8fb6744ee6cc68eb525ab68dc7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=BCller?= Date: Mon, 13 Jun 2016 11:34:33 +0200 Subject: [PATCH] Generate xtc index in pygmx.open if necessary. --- pygmx/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pygmx/__init__.py b/pygmx/__init__.py index aeab992..cae07ab 100644 --- a/pygmx/__init__.py +++ b/pygmx/__init__.py @@ -2,11 +2,14 @@ Python wrapper for the gromacs library. """ +import os + from .tpxio import TPXReader from .xtcio import XTCReader # from .enxio import EDRFile from .errors import FileTypeError from .gromacs.reader import index_filename_for_xtc +from .gromacs.xtcindex import index_xtcfile FILE_EXTENSIONS = { 'xtc': XTCReader, @@ -20,6 +23,11 @@ def open(filename): if ext in FILE_EXTENSIONS: if ext in ['xtc']: 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) + else: + return FILE_EXTENSIONS[ext](filename) else: raise FileTypeError('Filetype {} not supported by pygmx.'.format(ext))