-
Notifications
You must be signed in to change notification settings - Fork 826
Hbond excl fix #3242
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
Hbond excl fix #3242
Changes from all commits
be7b73a
9d990f0
5efe9a1
7f07893
b46b200
42947d9
3004fa8
054117f
898e151
5cd83e1
fde050b
50531d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,7 +115,7 @@ | |
|
|
||
|
|
||
| The keyword **exclusions** allows a tuple of array addresses to be provided, | ||
| (Hidx, Aidx),these pairs of hydrogen-acceptor are then not permitted to be | ||
| (Hidx, Aidx), these pairs of hydrogen-acceptor are then not permitted to be | ||
richardjgowers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| counted as part of the analysis. This could be used to exclude the | ||
| consideration of hydrogen bonds within the same functional group, or to perform | ||
| analysis on strictly intermolecular hydrogen bonding. | ||
|
|
@@ -215,6 +215,7 @@ | |
|
|
||
| from MDAnalysis.lib.log import ProgressBar | ||
| from MDAnalysis.lib.distances import capped_distance, calc_angles, calc_bonds | ||
| from MDAnalysis.lib._cutil import _in2d | ||
| from MDAnalysis.core.groups import requires | ||
|
|
||
| from MDAnalysis.due import due, Doi | ||
|
|
@@ -320,11 +321,13 @@ def __init__(self, universe, | |
| raise ValueError("Donors and Hydrogen groups must be identical " | ||
| "length. Try using `find_hydrogen_donors`.") | ||
|
|
||
| self.exclusions = exclusions | ||
| if self.exclusions: | ||
| if not len(self.exclusions[0]) == len(self.exclusions[1]): | ||
| if exclusions is not None: | ||
| if len(exclusions[0]) != len(exclusions[1]): | ||
| raise ValueError( | ||
| "'exclusion' must be two arrays of identical length") | ||
| self.exclusions = np.column_stack((exclusions[0], exclusions[1])).astype(np.intp) | ||
| else: | ||
| self.exclusions = None | ||
|
|
||
| self.bond_type = bond_type | ||
| if self.bond_type not in ['continuous', 'intermittent']: | ||
|
|
@@ -427,11 +430,10 @@ def _single_run(self, start, stop): | |
| box = self.u.dimensions if self.pbc else None | ||
|
|
||
| # 2d array of all distances | ||
| pair, d = capped_distance(self.h.positions, self.a.positions, max_cutoff=self.d_crit, box=box) | ||
| if self.exclusions: | ||
| # set to above dist crit to exclude | ||
| exclude = np.column_stack((self.exclusions[0], self.exclusions[1])) | ||
| pair = np.delete(pair, np.where(pair==exclude), 0) | ||
| pair = capped_distance(self.h.positions, self.a.positions, max_cutoff=self.d_crit, box=box, | ||
| return_distances=False) | ||
| if self.exclusions is not None: | ||
| pair = pair[~ _in2d(pair, self.exclusions)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised there was no suitable numpy operation for this :/
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The below passes the analysis suite locally without using a custom Cython function. Maybe double check with Richard if his mixture of Cython/C++ is more efficient -- probably any advantage is related to the integer only nature of the data structure? --- a/package/MDAnalysis/analysis/hbonds/hbond_autocorrel.py
+++ b/package/MDAnalysis/analysis/hbonds/hbond_autocorrel.py
@@ -210,6 +210,7 @@ from six import raise_from
import numpy as np
import scipy.optimize
+from scipy.spatial.distance import cdist
import warnings
@@ -433,7 +434,7 @@ class HydrogenBondAutoCorrel(object):
pair = capped_distance(self.h.positions, self.a.positions, max_cutoff=self.d_crit, box=box,
return_distances=False)
if not self.exclusions is None:
- pair = pair[~ _in2d(pair, self.exclusions)]
+ pair = pair[~ (cdist(pair, self.exclusions)==0).any(axis=1)]
hidx, aidx = np.transpose(pair)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use cdist but it's odd to use an O(n2) solution when you can just use a set
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a strong view on it--if this is genuinely a performance-critical part of the code maybe the custom maintenance burden is worth it. |
||
|
|
||
| hidx, aidx = np.transpose(pair) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.