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

HydrogenBondAnalysis, and automation (linked to issue #197) #225

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
86 changes: 86 additions & 0 deletions mdpow/analysis/hbond.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# MDPOW: hbond.py
# 2022 Cade Duckworth

#Review and update old docs

import pandas as pd

Check warning on line 6 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L6

Added line #L6 was not covered by tests

from MDAnalysis.analysis.hydrogenbonds.hbond_analysis import HydrogenBondAnalysis as HBA

Check warning on line 8 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L8

Added line #L8 was not covered by tests

from mdpow.analysis.ensemble import Ensemble, EnsembleAtomGroup, EnsembleAnalysis

Check warning on line 10 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L10

Added line #L10 was not covered by tests

import logging

Check warning on line 12 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L12

Added line #L12 was not covered by tests

logger = logging.getLogger('mdpow.analysis.hbond')

Check warning on line 14 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L14

Added line #L14 was not covered by tests

class HBondAnalysis(EnsembleAnalysis):

Check warning on line 16 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L16

Added line #L16 was not covered by tests
"""Analyzes potential hydrogen bonds of solute from a single
:class:`~mdpow.analysis.ensemble.Ensemble` .
:keywords:
*solute*
single :class:`~mdpow.analysis.ensemble.EnsembleAtomGroup`
selected by resname provided for Universe. Selections must be from the same
:class:`~mdpow.analysis.ensemble.Ensemble` .
Data is returned in a :class:`pandas.DataFrame` with observations sorted by
solvent, interaction, lambda, frame, donor index,
hydrogen index, acceptor index, distance, angle.
.. ruberic:: Example
Typical Workflow::
ens = Ensemble(dirname='Mol', solvents=('water', 'octanol'),
interactions=('Coulomb', 'VDW'))
solute = ens.select_atoms('resname UNK')
hb = HBondAnalysis(solute, acceptors_sel='resname UNK', d_a_cutoff=2.5)
hb.run(start=0, stop=1000, step=10)

HydrogenBondAnalysis
numpy array results format:
<frame>, <donor index (0-based)>,
<hydrogen index (0-based)>,
<acceptor index (0-based)>,
<distance>, <angle>

HydrogenBondAnalysis
:keywords:
acceptors_sel=None
donors_sel=None
hydrogens_sel=None
d_h_cutoff=1.2
d_a_cutoff=3.0
d_h_a_angle_cutoff=150
update_selections=True

https://docs.mdanalysis.org/stable/documentation_pages/analysis/hydrogenbonds.html

***NEED TO REFINE THIS AND ADD MORE DETAIL***
"""

def __init__(self, solute: EnsembleAtomGroup, **kwargs):
super(HBondAnalysis, self).__init__(solute.ensemble)
self._solute = solute
self.hb_kwargs = kwargs

Check warning on line 60 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L57-L60

Added lines #L57 - L60 were not covered by tests

def _prepare_ensemble(self):
self._col = ['solvent', 'interaction',

Check warning on line 63 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L62-L63

Added lines #L62 - L63 were not covered by tests
'lambda', 'time', 'frame',
'donor index', 'hydrogen index',
'acceptor index', 'distance', 'angle']
self.results = pd.DataFrame(columns=self._col)

Check warning on line 67 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L67

Added line #L67 was not covered by tests
self._res_dict = {key: [] for key in self._col}

def _single_universe(self):
solute = self._solute[self._key]
hb = HBA(universe=self._solute.ensemble[self._key], **self.hb_kwargs)
hb.run(verbose=True, start=self.start, stop=self.stop, step=self.step)
results = hb.results.hbonds

Check warning on line 74 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L70-L74

Added lines #L70 - L74 were not covered by tests

for h in results:
self._time = self._system.trajectory[int(h[0])].time
result = [self._key[0], self._key[1],self._key[2],

Check warning on line 78 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L77-L78

Added lines #L77 - L78 were not covered by tests
self._time, int(h[0]), int(h[1]),
int(h[2]), int(h[3]), h[4], h[5]]
for i in range(len(self._col)):
self._res_dict[self._col[i]].append(result[i])

Check warning on line 82 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L82

Added line #L82 was not covered by tests

def _conclude_ensemble(self):

Check warning on line 84 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L84

Added line #L84 was not covered by tests
for k in self._col:
self.results[k] = self._res_dict[k]

Check warning on line 86 in mdpow/analysis/hbond.py

View check run for this annotation

Codecov / codecov/patch

mdpow/analysis/hbond.py#L86

Added line #L86 was not covered by tests
Loading