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

Minimum mass for hydrogen guess in HydrogenBondAnalysis #2516

Merged
merged 34 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7af3352
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Aug 7, 2019
51624f3
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Aug 9, 2019
fa7777e
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Aug 13, 2019
94ac6cc
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Aug 20, 2019
80370af
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Sep 5, 2019
36fa2ea
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Sep 10, 2019
5111103
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Oct 2, 2019
ad0c149
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Oct 3, 2019
def7c14
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Oct 16, 2019
2d693e3
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Oct 30, 2019
f7d5bc6
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Nov 21, 2019
64bcae5
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Nov 28, 2019
2e2561e
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Dec 23, 2019
2184e2b
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Jan 14, 2020
de7afcc
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Jan 16, 2020
ff4ed8d
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Jan 17, 2020
c515e89
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Jan 17, 2020
7d27138
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Jan 18, 2020
3c35af0
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Jan 21, 2020
22def6a
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Jan 23, 2020
93413dc
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Jan 24, 2020
8c5dc00
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Feb 1, 2020
ad1766e
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Feb 4, 2020
65e4d66
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Feb 4, 2020
549c1a2
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Feb 6, 2020
f527e62
Merge remote-tracking branch 'upstream/develop' into develop
RMeli Feb 9, 2020
197660a
added minimum hydrogen mass
RMeli Feb 9, 2020
ef8e8ff
added tests for guess_hydrogens
RMeli Feb 9, 2020
48dbfae
changelog
RMeli Feb 9, 2020
b570297
remove assertion from code
RMeli Feb 9, 2020
4417ab0
check exception message
RMeli Feb 9, 2020
46f8a1c
put tests together and fix linter warnings
RMeli Feb 10, 2020
1e5e4b1
use pytest match
RMeli Feb 10, 2020
23cc898
put min_mass check at the end
RMeli Feb 11, 2020
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
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ Enhancements
convert between a parmed.Structure and MDAnalysis Universe (PR #2404)

Changes
* 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,
and rms (Issue #1745).
* Removes; `save_table()` from :class:`HydrogenBondAnalysis`,
Expand Down
19 changes: 15 additions & 4 deletions package/MDAnalysis/analysis/hydrogenbonds/hbond_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"""
from __future__ import absolute_import, division

import numpy as np
import numpy as np

from .. import base
from MDAnalysis.lib.distances import capped_distance, calc_angles
Expand Down Expand Up @@ -234,7 +234,12 @@ def __init__(self, universe, donors_sel=None, hydrogens_sel=None, acceptors_sel=
self.d_h_a_angle = d_h_a_angle_cutoff
self.update_selections = update_selections

def guess_hydrogens(self, selection='all', max_mass=1.1, min_charge=0.3):
def guess_hydrogens(self,
selection='all',
max_mass=1.1,
min_charge=0.3,
min_mass=0.9
):
"""Guesses which hydrogen atoms should be used in the analysis.

Parameters
Expand Down Expand Up @@ -263,14 +268,20 @@ def guess_hydrogens(self, selection='all', max_mass=1.1, min_charge=0.3):
Alternatively, this function may be used to quickly generate a :class:`str` of potential hydrogen atoms involved
in hydrogen bonding. This str may then be modified before being used to set the attribute
:attr:`hydrogens_sel`.

.. versionchanged: 1.0.0
Added `min_mass` parameter to specify minimum mass (Issue #2472)
"""

assert min_mass < max_mass
RMeli marked this conversation as resolved.
Show resolved Hide resolved

ag = self.u.select_atoms(selection)
hydrogens_ag = ag[
np.logical_and(
np.logical_and.reduce((
richardjgowers marked this conversation as resolved.
Show resolved Hide resolved
ag.masses > min_mass,
ag.masses < max_mass,
ag.charges > min_charge
)
))
]

hydrogens_list = np.unique(
Expand Down
49 changes: 49 additions & 0 deletions testsuite/MDAnalysisTests/analysis/test_hydrogenbonds_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,56 @@ def test_guess_donors(self, h):
ref_donors = "(resname TIP3 and name OH2)"
donors = h.guess_donors(selection='all', max_charge=-0.5)
assert donors == ref_donors
class TestHydrogenBondAnalysisTIP3P_GuessHyrdogens_NoTopology(object):
"""
Guess the hydrogen atoms involved in hydrogen bonds using the mass and
partial charge of the atoms.
"""

@staticmethod
@pytest.fixture(scope='class')
def universe():
return MDAnalysis.Universe(waterPSF, waterDCD)

kwargs = {
'donors_sel': None,
'hydrogens_sel': None,
'acceptors_sel': None,
'd_h_cutoff': 1.2,
'd_a_cutoff': 3.0,
'd_h_a_angle_cutoff': 120.0
}

@pytest.fixture(scope='class')
def h(self, universe):
h = HydrogenBondAnalysis(universe, **self.kwargs)
return h

def test_guess_hydrogens(self, h):

ref_hydrogens = "(resname TIP3 and name H1) or (resname TIP3 and name H2)"
hydrogens = h.guess_hydrogens(selection='all')
assert hydrogens == ref_hydrogens

def test_guess_hydrogens_min_mass(self, h):
RMeli marked this conversation as resolved.
Show resolved Hide resolved

hydrogens = h.guess_hydrogens(selection='all', min_mass=1.05)
assert hydrogens == ""

def test_guess_hydrogens_max_mass(self, h):

hydrogens = h.guess_hydrogens(selection='all', max_mass=0.95)
assert hydrogens == ""

def test_guess_hydrogens_min_charge(self, h):

hydrogens = h.guess_hydrogens(selection='all', min_charge=1.0)
assert hydrogens == ""

def test_guess_hydrogens_min_max_mass(self, h):
RMeli marked this conversation as resolved.
Show resolved Hide resolved

with pytest.raises(AssertionError):
hydrogens = h.guess_hydrogens(selection='all', min_mass=1.1, max_mass=0.9)

class TestHydrogenBondAnalysisTIP3PStartStep(object):
"""Uses the same distance and cutoff hydrogen bond criteria as :class:`TestHydrogenBondAnalysisTIP3P` but starting
Expand Down