From c18a3694733348c6a3315ed9a166e6ab54b54588 Mon Sep 17 00:00:00 2001 From: sebastiankloth Date: Tue, 3 May 2022 15:15:12 +0200 Subject: [PATCH] Fixed index reader --- mdevaluate/__init__.py | 6 ++++++ mdevaluate/reader.py | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mdevaluate/__init__.py b/mdevaluate/__init__.py index 6600f5d..91bfcc9 100644 --- a/mdevaluate/__init__.py +++ b/mdevaluate/__init__.py @@ -53,6 +53,12 @@ def open(directory='', topology='*.tpr', trajectory='*.xtc', cached=False, if top_glob is not None and len(top_glob) == 1: top_file, = top_glob logger.info('Loading topology: {}'.format(top_file)) + if index_file is not None: + index_glob = glob(os.path.join(directory, index_file), recursive=True) + if index_glob is not None: + index_file = index_glob[0] + else: + index_file = None else: raise FileNotFoundError('Topology file could not be identified.') diff --git a/mdevaluate/reader.py b/mdevaluate/reader.py index 692c547..d48da27 100755 --- a/mdevaluate/reader.py +++ b/mdevaluate/reader.py @@ -56,7 +56,7 @@ def open_with_mdanalysis(topology, trajectory, cached=False, index_file=None): raise WrongTopologyError('Topology file should end with ".tpr" or ".gro"') indices = None if index_file: - indices = load_indices(indexfile) + indices = load_indices(index_file) atms = atoms.Atoms( np.stack((uni.atoms.resids, uni.atoms.resnames, uni.atoms.names), axis=1), @@ -67,10 +67,10 @@ def open_with_mdanalysis(topology, trajectory, cached=False, index_file=None): group_re = re.compile('\[ ([-+\w]+) \]') -def load_indices(indexfile): +def load_indices(index_file): indices = {} index_array = None - with open(indexfile) as idx_file: + with open(index_file) as idx_file: for line in idx_file: m = group_re.search(line) if m is not None: