Skip to content
Merged
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
3 changes: 3 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ Enhancements
* Improve the distance search in water bridge analysis with capped_distance (PR #2480)

Changes
* Removes the `nproc` keyword from
:class:`Waterdynamics.HydrogenBondLifetimes` as the multiprocessing functionality
did not work in some cases(Issues #2511).
* Added `min_mass` parameter to `guess_hydrogens` function in `HydrogenBondAnalysis`
set to 0.9 by default (Issue #2472)
* Removes `save()` function from contacts, diffusionmap, hole, LinearDensity,
Expand Down
92 changes: 12 additions & 80 deletions package/MDAnalysis/analysis/waterdynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,6 @@
from six.moves import range, zip_longest

import numpy as np
import multiprocessing

import MDAnalysis.analysis.hbonds
from MDAnalysis.lib.log import ProgressMeter

Expand Down Expand Up @@ -501,22 +499,21 @@ class HydrogenBondLifetimes(object):
frame where analysis ends
dtmax : int
Maximum dt size, `dtmax` < `tf` or it will crash.
nproc : int
Number of processors to use, by default is 1.


.. versionadded:: 0.11.0
.. versionchanged:: 1.0.0
The ``nproc`` keyword was removed as it linked to a portion of code that
may have failed in some cases.
"""

def __init__(self, universe, selection1, selection2, t0, tf, dtmax,
nproc=1):
def __init__(self, universe, selection1, selection2, t0, tf, dtmax):
self.universe = universe
self.selection1 = selection1
self.selection2 = selection2
self.t0 = t0
self.tf = tf - 1
self.dtmax = dtmax
self.nproc = nproc
self.timeseries = None

def _getC_i(self, HBP, t0, t):
Expand Down Expand Up @@ -633,82 +630,17 @@ def _getGraphics(self, HBP, t0, tf, maxdt):
a.append(fix)
return a

def _HBA(self, ts, conn, universe, selAtom1, selAtom2,
verbose=False):
"""
Main function for calculate C_i and C_c in parallel.
"""
finalGetResidue1 = selAtom1
finalGetResidue2 = selAtom2
frame = ts.frame
h = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis(universe,
finalGetResidue1,
finalGetResidue2,
distance=3.5,
angle=120.0,
start=frame - 1,
stop=frame)
while True:
try:
h.run(verbose=verbose)
break
except:
print("error")
print("trying again")
sys.stdout.flush()
sys.stdout.flush()
conn.send(h.timeseries[0])
conn.close()

def run(self, **kwargs):
"""Analyze trajectory and produce timeseries"""
h_list = []
i = 0
if (self.nproc > 1):
while i < len(self.universe.trajectory):
jobs = []
k = i
for j in range(self.nproc):
# start
print("ts=", i + 1)
if i >= len(self.universe.trajectory):
break
conn_parent, conn_child = multiprocessing.Pipe(False)
while True:
try:
# new thread
jobs.append(
(multiprocessing.Process(
target=self._HBA,
args=(self.universe.trajectory[i],
conn_child, self.universe,
self.selection1, self.selection2,)),
conn_parent))
break
except:
print("error in jobs.append")
jobs[j][0].start()
i = i + 1

for j in range(self.nproc):
if k >= len(self.universe.trajectory):
break
rec01 = jobs[j][1]
received = rec01.recv()
h_list.append(received)
jobs[j][0].join()
k += 1
self.timeseries = self._getGraphics(
h_list, 0, self.tf - 1, self.dtmax)
else:
h_list = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis(self.universe,
self.selection1,
self.selection2,
distance=3.5,
angle=120.0)
h_list.run(**kwargs)
self.timeseries = self._getGraphics(
h_list.timeseries, self.t0, self.tf, self.dtmax)
h_list = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis(self.universe,
self.selection1,
self.selection2,
distance=3.5,
angle=120.0)
h_list.run(**kwargs)
self.timeseries = self._getGraphics(h_list.timeseries, self.t0,
self.tf, self.dtmax)


class WaterOrientationalRelaxation(object):
Expand Down