Fixed index reader
This commit is contained in:
parent
6c54848105
commit
c18a369473
@ -53,6 +53,12 @@ def open(directory='', topology='*.tpr', trajectory='*.xtc', cached=False,
|
|||||||
if top_glob is not None and len(top_glob) == 1:
|
if top_glob is not None and len(top_glob) == 1:
|
||||||
top_file, = top_glob
|
top_file, = top_glob
|
||||||
logger.info('Loading topology: {}'.format(top_file))
|
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:
|
else:
|
||||||
raise FileNotFoundError('Topology file could not be identified.')
|
raise FileNotFoundError('Topology file could not be identified.')
|
||||||
|
|
||||||
|
@ -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"')
|
raise WrongTopologyError('Topology file should end with ".tpr" or ".gro"')
|
||||||
indices = None
|
indices = None
|
||||||
if index_file:
|
if index_file:
|
||||||
indices = load_indices(indexfile)
|
indices = load_indices(index_file)
|
||||||
|
|
||||||
atms = atoms.Atoms(
|
atms = atoms.Atoms(
|
||||||
np.stack((uni.atoms.resids, uni.atoms.resnames, uni.atoms.names), axis=1),
|
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]+) \]')
|
group_re = re.compile('\[ ([-+\w]+) \]')
|
||||||
|
|
||||||
def load_indices(indexfile):
|
def load_indices(index_file):
|
||||||
indices = {}
|
indices = {}
|
||||||
index_array = None
|
index_array = None
|
||||||
with open(indexfile) as idx_file:
|
with open(index_file) as idx_file:
|
||||||
for line in idx_file:
|
for line in idx_file:
|
||||||
m = group_re.search(line)
|
m = group_re.search(line)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user