Skip to content

Commit d8dcfce

Browse files
committed
added ncomp arg to get_taus
1 parent 5b82fae commit d8dcfce

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

basicrta/cluster.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def reprocess(self, nproc=1):
8585
except KeyboardInterrupt:
8686
pass
8787

88-
def get_taus(self):
88+
def get_taus(self, nproc=1):
8989
r"""Get :math:`\tau` and 95\% confidence interval bounds for the slowest
9090
process for each residue.
9191
@@ -96,10 +96,14 @@ def get_taus(self):
9696
"""
9797
from basicrta.util import get_bars
9898

99+
dirs = np.array(glob(f'basicrta-{self.cutoff}/?[0-9]*'))
100+
sorted_inds = (np.array([int(adir.split('/')[-1][1:]) for adir in dirs])
101+
.argsort())
102+
dirs = dirs[sorted_inds]
99103
with (Pool(nproc, initializer=tqdm.set_lock,
100104
initargs=(Lock(),)) as p):
101105
try:
102-
for _ in tqdm(p.istarmap(self._single_residue, inarr),
106+
for _ in tqdm(p.imap(self._single_residue, dirs),
103107
total=len(dirs), position=0,
104108
desc='overall progress'):
105109
pass
@@ -109,15 +113,7 @@ def get_taus(self):
109113
taus = []
110114
for res in tqdm(self.residues, total=len(self.residues)):
111115
taus.append(res.tau)
112-
#if self.residues[res] is None:
113-
# result = [0, 0, 0]
114-
#else:
115-
# try:
116-
# gib = Gibbs().load(self.residues[res])
117-
# result = gib.estimate_tau()
118-
# except AttributeError:
119-
# result = [0, 0, 0]
120-
#taus.append(result)
116+
121117
taus = np.array(taus)
122118
bars = get_bars(taus)
123119
setattr(self, 'taus', taus[:, 1])
@@ -132,7 +128,9 @@ def write_data(self, fname='tausout'):
132128
:param fname: Filename to save data to.
133129
:type fname: str, optional
134130
"""
135-
taus, bars = self.get_taus()
131+
if self.taus is None:
132+
taus, bars = self.get_taus()
133+
136134
keys = self.residues.keys()
137135
residues = np.array([int(res[1:]) for res in keys])
138136
data = np.stack((residues, taus, bars[0], bars[1]))
@@ -148,7 +146,9 @@ def plot_protein(self, **kwargs):
148146
if len(self.residues) == 0:
149147
print('run `collect_residues` then rerun')
150148

151-
taus, bars = self.get_taus()
149+
if self.taus is None:
150+
self.get_taus()
151+
152152
residues = list(self.residues.keys())
153153
residues = [res.split('/')[-1] for res in residues]
154154

@@ -163,7 +163,9 @@ def b_color_structure(self, structure):
163163
r"""Add :math:`\tau` to b-factors in the specified structure. Saves
164164
structure with b-factors to `tau_bcolored.pdb`.
165165
"""
166-
taus, bars = self.get_taus()
166+
if self.taus is None:
167+
taus, bars = self.get_taus()
168+
167169
cis = bars[1]+bars[0]
168170
errs = taus/cis
169171
errs[errs != errs] = 0

0 commit comments

Comments
 (0)