Skip to content

Commit

Permalink
reorder parallel insty results
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmkrieger committed Dec 17, 2024
1 parent 1a1db6d commit fcb14c3
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions prody/proteins/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5156,7 +5156,7 @@ def calcProteinInteractionsTrajectory(self, atoms, trajectory=None, filename=Non
atoms_copy = atoms.copy()
protein = atoms_copy.protein

def analyseFrame(j0, frame0, interactions_all, interactions_nb):
def analyseFrame(j0, frame0, interactions_all, interactions_nb, j0_list):
LOGGER.info('Frame: {0}'.format(j0))
atoms_copy.setCoords(frame0.getCoords())

Expand Down Expand Up @@ -5184,13 +5184,17 @@ def analyseFrame(j0, frame0, interactions_all, interactions_nb):
interactions_nb[5].append(len(hydrophobic))
interactions_nb[6].append(len(Disulfide_Bonds))

j0_list.append(j0)

if max_proc == 1:
interactions_all = []
interactions_all.extend(interactions_traj)
interactions_nb = []
interactions_nb.extend(interactions_nb_traj)
j0_list = []
for j0, frame0 in enumerate(traj, start=start_frame):
analyseFrame(j0, frame0, interactions_all, interactions_nb)
analyseFrame(j0, frame0, interactions_all, interactions_nb,
j0_list)
else:
with mp.Manager() as manager:
interactions_all = manager.list()
Expand All @@ -5200,15 +5204,17 @@ def analyseFrame(j0, frame0, interactions_all, interactions_nb):
interactions_nb.extend([manager.list() for _ in interactions_nb_traj])

j0 = start_frame
j0_list = manager.list()
while j0 < traj.numConfs()+start_frame:

processes = []
for _ in range(max_proc):
frame0 = traj[j0-start_frame]

p = mp.Process(target=analyseFrame, args=(j0, frame0,
interactions_all,
interactions_nb))
interactions_all,
interactions_nb,
j0_list))
p.start()
processes.append(p)

Expand All @@ -5221,6 +5227,13 @@ def analyseFrame(j0, frame0, interactions_all, interactions_nb):

interactions_all = [entry[:] for entry in interactions_all]
interactions_nb = [entry[:] for entry in interactions_nb]
j0_list = [entry for entry in j0_list]

ids = np.argsort(j0_list)
interactions_all = [list(np.array(interactions_type, dtype=object)[ids])
for interactions_type in interactions_all]
interactions_nb = [list(np.array(interactions_type, dtype=object)[ids])
for interactions_type in interactions_nb]

self._atoms = atoms
self._traj = trajectory
Expand Down

0 comments on commit fcb14c3

Please sign in to comment.