Skip to content

Commit b5c1bd6

Browse files
committed
added parallel result collection
1 parent a093ed4 commit b5c1bd6

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

basicrta/cluster.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ def _single_residue(self, adir, process=False):
5353
result = None
5454
return result
5555

56+
def _single_result(self, adir):
57+
result = self._single_residue(adir)
58+
residue = adir.split('/')[-1]
59+
self.residues[residue] = result
60+
61+
5662
def reprocess(self, nproc=1):
5763
"""Rerun processing and clustering on :class:`Gibbs` data.
5864
@@ -77,7 +83,7 @@ def reprocess(self, nproc=1):
7783
except KeyboardInterrupt:
7884
pass
7985

80-
def collect_results(self):
86+
def collect_results(self, nproc=1):
8187
"""Collect names of results for each residue in the `basicrta-{cutoff}`
8288
directory in a dictionary stored in :attr:`ProcessProtein.results`.
8389
"""
@@ -87,13 +93,19 @@ def collect_results(self):
8793
sorted_inds = (np.array([int(adir.split('/')[-1][1:]) for adir in dirs])
8894
.argsort())
8995
dirs = dirs[sorted_inds]
90-
try:
91-
for adir in tqdm(dirs, desc='collecting results'):
92-
result = self._single_residue(adir)
93-
residue = adir.split('/')[-1]
94-
self.residues[residue] = result
95-
except KeyboardInterrupt:
96-
pass
96+
with (Pool(nproc, initializer=tqdm.set_lock,
97+
initargs=(Lock(),)) as p):
98+
try:
99+
for _ in tqdm(p.istarmap(self._single_result, dirs),
100+
total=len(dirs), position=0,
101+
desc='overall progress'):
102+
pass
103+
#for adir in tqdm(dirs, desc='collecting results'):
104+
# result = self._single_residue(adir)
105+
# residue = adir.split('/')[-1]
106+
# self.residues[residue] = result
107+
except KeyboardInterrupt:
108+
pass
97109

98110
def get_taus(self):
99111
r"""Get :math:`\tau` and 95\% confidence interval bounds for the slowest

0 commit comments

Comments
 (0)