Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more Parallel InSty fixes #2017

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -5159,9 +5166,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 @@ -5267,6 +5275,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 @@ -5771,8 +5782,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
Loading