Skip to content

Commit

Permalink
Merge pull request #2017 from jamesmkrieger/parallel_insty
Browse files Browse the repository at this point in the history
more Parallel InSty fixes
  • Loading branch information
jamesmkrieger authored Dec 28, 2024
2 parents 3019543 + d413ee3 commit 454c40c
Show file tree
Hide file tree
Showing 6 changed files with 19,806 additions and 18,511 deletions.
52 changes: 32 additions & 20 deletions prody/proteins/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,10 @@ def calcSaltBridges(atoms, **kwargs):
distA = kwargs.pop('distA', distSB)

atoms_KRED = atoms.select('protein and ((resname ASP GLU LYS ARG and not backbone and not name OXT NE "C.*" and noh) or (resname HIS HSE HSD HSP and name NE2))')
if atoms_KRED is None:
LOGGER.warn('There are no side chain heavy atoms for residues K, R, E, D and H, so not salt bridges are calculated')
return []

charged_residues = list(set(zip(atoms_KRED.getResnums(), atoms_KRED.getChids())))

LOGGER.info('Calculating salt bridges.')
Expand Down Expand Up @@ -1735,8 +1739,9 @@ def calcInteractionsMultipleFrames(atoms, interaction_type, trajectory, **kwargs
if isinstance(trajectory, Atomic):
trajectory = Ensemble(trajectory)

nfi = trajectory._nfi
trajectory.reset()
if isinstance(trajectory, Trajectory):
nfi = trajectory._nfi
trajectory.reset()
numFrames = trajectory._n_csets

if stop_frame == -1:
Expand All @@ -1745,7 +1750,7 @@ def calcInteractionsMultipleFrames(atoms, interaction_type, trajectory, **kwargs
traj = trajectory[start_frame:stop_frame+1]

atoms_copy = atoms.copy()
def analyseFrame(j0, start_frame, frame0, interactions_all):
def analyseFrame(j0, frame0, interactions_all):
LOGGER.info('Frame: {0}'.format(j0))
atoms_copy.setCoords(frame0.getCoords())
protein = atoms_copy.select('protein')
Expand All @@ -1755,13 +1760,10 @@ def analyseFrame(j0, start_frame, frame0, interactions_all):
if max_proc == 1:
interactions_all = []
for j0, frame0 in enumerate(traj, start=start_frame):
interactions_all.append([])
analyseFrame(j0, start_frame, frame0, interactions_all)
analyseFrame(j0, frame0, interactions_all)
else:
with mp.Manager() as manager:
interactions_all = manager.list()
for j0, frame0 in enumerate(traj, start=start_frame):
interactions_all.append([])

j0 = start_frame
while j0 < traj.numConfs()+start_frame:
Expand All @@ -1770,8 +1772,7 @@ def analyseFrame(j0, start_frame, frame0, interactions_all):
for _ in range(max_proc):
frame0 = traj[j0-start_frame]

p = mp.Process(target=analyseFrame, args=(j0, start_frame,
frame0,
p = mp.Process(target=analyseFrame, args=(j0, frame0,
interactions_all))
p.start()
processes.append(p)
Expand All @@ -1785,7 +1786,8 @@ def analyseFrame(j0, start_frame, frame0, interactions_all):

interactions_all = interactions_all[:]

trajectory._nfi = nfi
if isinstance(trajectory, Trajectory):
trajectory._nfi = nfi

else:
if atoms.numCoordsets() > 1:
Expand All @@ -1796,16 +1798,19 @@ def analyseFrame(i, interactions_all):
interactions = interactions_dic[interaction_type](protein, **kwargs)
interactions_all.append(interactions)

if stop_frame == -1:
stop_frame = atoms.numCoordsets()

if max_proc == 1:
interactions_all = []
for i in range(len(atoms.getCoordsets()[start_frame:stop_frame])):
for i in range(len(atoms.getCoordsets()[start_frame:stop_frame+1])):
analyseFrame(i, interactions_all)
else:
with mp.Manager() as manager:
interactions_all = manager.list()

i = start_frame
while i < len(atoms.getCoordsets()[start_frame:stop_frame]):
while i < len(atoms.getCoordsets()[start_frame:stop_frame+1]):
processes = []
for _ in range(max_proc):
p = mp.Process(target=analyseFrame, args=(i, interactions_all))
Expand Down Expand Up @@ -3127,8 +3132,9 @@ def calcSminaBindingAffinity(atoms, trajectory=None, **kwargs):
if isinstance(trajectory, Atomic):
trajectory = Ensemble(trajectory)

nfi = trajectory._nfi
trajectory.reset()
if isinstance(trajectory, Trajectory):
nfi = trajectory._nfi
trajectory.reset()
numFrames = trajectory._n_csets

if stop_frame == -1:
Expand Down Expand Up @@ -3164,7 +3170,8 @@ def calcSminaBindingAffinity(atoms, trajectory=None, **kwargs):
bindingAffinity.append(data['Affinity'])
data_final.append(data)

trajectory._nfi = nfi
if isinstance(trajectory, Trajectory):
trajectory._nfi = nfi

else:
if atoms.numCoordsets() == 1:
Expand Down Expand Up @@ -5178,9 +5185,10 @@ def calcProteinInteractionsTrajectory(self, atoms, trajectory=None, filename=Non
if isinstance(trajectory, Atomic):
trajectory = Ensemble(trajectory)

#nfi = trajectory._nfi
#trajectory.reset()
#numFrames = trajectory._n_csets
if isinstance(trajectory, Trajectory):
nfi = trajectory._nfi
trajectory.reset()
numFrames = trajectory._n_csets

if stop_frame == -1:
traj = trajectory[start_frame:]
Expand Down Expand Up @@ -5286,6 +5294,9 @@ def analyseFrame(j0, frame0, interactions_all, interactions_nb, j0_list):
with open(str(filename)+'.pkl', 'wb') as f:
pickle.dump(self._interactions_traj, f)
LOGGER.info('File with interactions saved.')

if isinstance(trajectory, Trajectory):
trajectory._nfi = nfi

return interactions_nb

Expand Down Expand Up @@ -5790,8 +5801,9 @@ def calcLigandInteractionsTrajectory(self, atoms, trajectory=None, **kwargs):
if isinstance(trajectory, Atomic):
trajectory = Ensemble(trajectory)

nfi = trajectory._nfi
trajectory.reset()
if isinstance(trajectory, Trajectory):
nfi = trajectory._nfi
trajectory.reset()
numFrames = trajectory._n_csets

if stop_frame == -1:
Expand Down
Binary file added prody/tests/datafiles/2k39_insty.dcd
Binary file not shown.
Loading

0 comments on commit 454c40c

Please sign in to comment.