Skip to content

Commit b9585c2

Browse files
committed
removed collect_results for efficiency
1 parent 23a732b commit b9585c2

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

basicrta/cluster.py

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,38 @@ class ProcessProtein(object):
2828
:type cutoff: float
2929
"""
3030

31-
def __init__(self, niter, prot, cutoff, gskip):
31+
def __init__(self, niter, prot, cutoff, gskip, taus=None, bars=None):
3232
self.residues = {}
3333
self.niter = niter
3434
self.prot = prot
3535
self.cutoff = cutoff
3636
self.gskip = gskip
37+
self.taus = taus
38+
self.bars = bars
3739

3840
def __getitem__(self, item):
3941
return getattr(self, item)
4042

4143
def _single_residue(self, adir, process=False):
4244
if os.path.exists(f'{adir}/gibbs_{self.niter}.pkl'):
45+
result = f'{adir}/gibbs_{self.niter}.pkl'
4346
try:
4447
result = f'{adir}/gibbs_{self.niter}.pkl'
4548
g = Gibbs().load(result)
4649
if process:
4750
g.gskip = self.gskip
4851
g.process_gibbs()
52+
tau = g.estimate_tau()
4953
except ValueError:
5054
result = None
55+
tau = [0, 0, 0]
5156
else:
52-
print(f'results for {adir} do not exist')
5357
result = None
54-
return result
58+
tau = [0, 0, 0]
5559

56-
def _single_result(self, adir):
57-
result = self._single_residue(adir)
5860
residue = adir.split('/')[-1]
59-
self.residues[residue] = result
60-
61+
setattr(self.residues, 'f{residue}', result)
62+
setattr(self.residues.residue, 'tau', tau)
6163

6264
def reprocess(self, nproc=1):
6365
"""Rerun processing and clustering on :class:`Gibbs` data.
@@ -83,30 +85,6 @@ def reprocess(self, nproc=1):
8385
except KeyboardInterrupt:
8486
pass
8587

86-
def collect_results(self, nproc=1):
87-
"""Collect names of results for each residue in the `basicrta-{cutoff}`
88-
directory in a dictionary stored in :attr:`ProcessProtein.results`.
89-
"""
90-
from glob import glob
91-
92-
dirs = np.array(glob(f'basicrta-{self.cutoff}/?[0-9]*'))
93-
sorted_inds = (np.array([int(adir.split('/')[-1][1:]) for adir in dirs])
94-
.argsort())
95-
dirs = dirs[sorted_inds]
96-
with (Pool(nproc, initializer=tqdm.set_lock,
97-
initargs=(Lock(),)) as p):
98-
try:
99-
for _ in tqdm(p.imap(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
109-
11088
def get_taus(self):
11189
r"""Get :math:`\tau` and 95\% confidence interval bounds for the slowest
11290
process for each residue.
@@ -120,17 +98,20 @@ def get_taus(self):
12098

12199
taus = []
122100
for res in tqdm(self.residues, total=len(self.residues)):
123-
if self.residues[res] is None:
124-
result = [0, 0, 0]
125-
else:
126-
try:
127-
gib = Gibbs().load(self.residues[res])
128-
result = gib.estimate_tau()
129-
except AttributeError:
130-
result = [0, 0, 0]
131-
taus.append(result)
101+
taus.append(res.tau)
102+
#if self.residues[res] is None:
103+
# result = [0, 0, 0]
104+
#else:
105+
# try:
106+
# gib = Gibbs().load(self.residues[res])
107+
# result = gib.estimate_tau()
108+
# except AttributeError:
109+
# result = [0, 0, 0]
110+
#taus.append(result)
132111
taus = np.array(taus)
133112
bars = get_bars(taus)
113+
setattr(self, 'taus', taus[:, 1])
114+
setattr(self, 'bars', bars)
134115
return taus[:, 1], bars
135116

136117
def write_data(self, fname='tausout'):

0 commit comments

Comments
 (0)