Skip to content
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
61 changes: 43 additions & 18 deletions package/MDAnalysis/analysis/hydrogenbonds/wbridge_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def analysis(current, output, u, **kwargs):
from MDAnalysis.lib.distances import calc_angles, capped_distance
from MDAnalysis.lib.NeighborSearch import AtomNeighborSearch

from ..base import AnalysisBase
from ..base import AnalysisBase, ResultsGroup

logger = logging.getLogger("MDAnalysis.analysis.WaterBridgeAnalysis")

Expand Down Expand Up @@ -804,6 +804,16 @@ class WaterBridgeAnalysis(AnalysisBase):
lambda: 1.5, N=1.31, O=1.31, P=1.58, S=1.55 # default value
) # noqa: E741

_analysis_algorithm_is_parallelizable = True

@classmethod
def get_supported_backends(cls):
return (
"serial",
"multiprocessing",
"dask",
)

def __init__(
self,
universe,
Expand Down Expand Up @@ -1951,25 +1961,32 @@ def count_by_time(self, analysis_func=None, **kwargs):
"""
if analysis_func is None:
analysis_func = self._count_by_time_analysis
if self.results.network:
result = []
for time, frame in zip(self.timesteps, self.results.network):
result_dict = defaultdict(int)
self._traverse_water_network(
frame,
[],
analysis_func=analysis_func,
output=result_dict,
link_func=self._full_link,
**kwargs,
)
result.append(
(time, sum([result_dict[key] for key in result_dict]))
)
return result
else:

if not self.results.network:
return None

# --- simple fallback for missing timesteps ---
if self.timesteps is None:
timesteps = range(len(self.results.network))
else:
timesteps = self.timesteps
Comment on lines +1969 to +1972
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be actual timesteps, and not integer indices. Solution would be to save them to results._timesteps and later use them where needed, while adding deprecation warning to self.timesteps alike InterRDS_s's approach.


result = []
for time, frame in zip(timesteps, self.results.network):
result_dict = defaultdict(int)
self._traverse_water_network(
frame,
[],
analysis_func=analysis_func,
output=result_dict,
link_func=self._full_link,
**kwargs,
)
result.append(
(time, sum([result_dict[key] for key in result_dict]))
)
return result

def _timesteps_by_type_analysis(self, current, output, *args, **kwargs):
s1_index, to_index, s1, to_residue, dist, angle = (
self._expand_timeseries(current[0])
Expand Down Expand Up @@ -2152,6 +2169,14 @@ def generate_table(self, output_format=None):
def _conclude(self):
self.results.timeseries = self._generate_timeseries()

def _get_aggregator(self):
return ResultsGroup(
lookup={
"timeseries": ResultsGroup.ndarray_hstack, # Get positions
"network": ResultsGroup.ndarray_hstack, # Get positions
}
)

@property
def network(self):
wmsg = (
Expand Down
11 changes: 11 additions & 0 deletions testsuite/MDAnalysisTests/analysis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from MDAnalysis.analysis.hydrogenbonds.hbond_analysis import (
HydrogenBondAnalysis,
)
from MDAnalysis.analysis.hydrogenbonds.wbridge_analysis import (
WaterBridgeAnalysis,
)
from MDAnalysis.analysis.nucleicacids import NucPairDist
from MDAnalysis.analysis.contacts import Contacts
from MDAnalysis.analysis.density import DensityAnalysis
Expand Down Expand Up @@ -217,3 +220,11 @@ def client_InterRDF_s(request):
@pytest.fixture(scope="module", params=params_for_cls(DistanceMatrix))
def client_DistanceMatrix(request):
return request.param


# MDAnalysis.analysis.hydrogenbonds.wbridge_analysis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?



@pytest.fixture(scope="module", params=params_for_cls(WaterBridgeAnalysis))
def client_WaterBridgeAnalysis(request):
return request.param
Loading
Loading