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
7 changes: 6 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ Enhancements
convert between a parmed.Structure and MDAnalysis Universe (PR #2404)

Changes
* Removes; `save_table()` from :class:`HydrogenBondAnalysis`,
`save_results()` from :class:`HydrogenBondAutoCorrel`, and
`save_results()`/`filename`/`store` from :class:`PSAnalysis`. Also sets
the deprecation of `hbonds/hbond_analysis.py` to v1.0 (Issues #1745,
#2486, #2487, #2491, #2492).
* Removes the `format` and `skip` keywords from :meth:`DCDReader.timeseries`
(Issue #2443)
* `fullgroup` selection has now been removed (#268)
Expand All @@ -89,7 +94,7 @@ Changes
is "-" (Issue #2448, PR #2457)

Deprecations
* analysis.hbonds.HydrogenBondAnalysis will be deprecated in 1.0
* analysis.hbonds.HydrogenBondAnalysis is deprecated in 1.0 (remove in 2.0)

09/05/19 IAlibay, richardjgowers

Expand Down
49 changes: 11 additions & 38 deletions package/MDAnalysis/analysis/hbonds/hbond_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
:Copyright: GNU Public License v3

..Warning:
This module will be deprecated in version 1.0.
This module is deprecated and will be removed in version 2.0.
Please use :mod:`MDAnalysis.analysis.hydrogenbonds.hbond_analysis` instead.

Given a :class:`~MDAnalysis.core.universe.Universe` (simulation
Expand Down Expand Up @@ -321,7 +321,7 @@ class HydrogenBondAnalysis_OtherFF(HydrogenBondAnalysis):
"""
from __future__ import division, absolute_import
import six
from six.moves import range, zip, map, cPickle
from six.moves import range, zip

import warnings
import logging
Expand All @@ -334,17 +334,18 @@ class HydrogenBondAnalysis_OtherFF(HydrogenBondAnalysis):
from MDAnalysis.lib.log import ProgressMeter
from MDAnalysis.lib.NeighborSearch import AtomNeighborSearch
from MDAnalysis.lib import distances
from MDAnalysis.lib.util import deprecate


logger = logging.getLogger('MDAnalysis.analysis.hbonds')

warnings.warn(
"This module will be deprecated in version 1.0."
"This module is deprecated as of MDAnalysis version 1.0."
"It will be removed in MDAnalysis version 2.0"
"Please use MDAnalysis.analysis.hydrogenbonds.hbond_analysis instead.",
category=DeprecationWarning
)


class HydrogenBondAnalysis(base.AnalysisBase):
"""Perform a hydrogen bond analysis

Expand Down Expand Up @@ -380,6 +381,10 @@ class HydrogenBondAnalysis(base.AnalysisBase):
.. versionchanged:: 0.7.6
DEFAULT_DONORS/ACCEPTORS is now embedded in a dict to switch between
default values for different force fields.

.. versionchanged:: 1.0.0
``save_table()`` method has been removed. You can use ``np.save()`` or
``cPickle.dump()`` on :attr:`HydrogenBondAnalysis.table` instead.
"""

# use tuple(set()) here so that one can just copy&paste names from the
Expand Down Expand Up @@ -567,7 +572,8 @@ def __init__(self, universe, selection1='protein', selection2='all', selection1_
super(HydrogenBondAnalysis, self).__init__(universe.trajectory, **kwargs)

warnings.warn(
"This class will be deprecated in version 1.0."
"This class is deprecated as of MDAnalysis version 1.0 and will "
"be removed in version 2.0."
"Please use MDAnalysis.analysis.hydrogenbonds.hbond_analysis.HydrogenBondAnalysis instead.",
category=DeprecationWarning
)
Expand Down Expand Up @@ -1120,12 +1126,6 @@ def _reformat_hb(hb, atomformat="{0[0]!s}{0[1]!s}:{0[2]!s}"):
In 0.16.1, donor and acceptor are stored as a tuple(resname,
resid, atomid). In 0.16.0 and earlier they were stored as a string.

.. deprecated:: 1.0
This is a compatibility layer so that we can provide the same output
in timeseries as before. However, for 1.0 we should make timeseries
just return _timeseries, i.e., change the format of timeseries to
the un-ambiguous representation provided in _timeseries.

"""
return (hb[:2]
+ [atomformat.format(hb[2]), atomformat.format(hb[3])]
Expand Down Expand Up @@ -1171,33 +1171,6 @@ def generate_table(self):
self.table = out.view(np.recarray)
logger.debug("HBond: Stored results as table with %(num_records)d entries.", vars())

@deprecate(release="0.19.0", remove="1.0.0",
message="You can instead use ``np.save(filename, "
"HydrogendBondAnalysis.table)``.")
def save_table(self, filename="hbond_table.pickle"):
"""Saves :attr:`~HydrogenBondAnalysis.table` to a pickled file.

If :attr:`~HydrogenBondAnalysis.table` does not exist yet,
:meth:`generate_table` is called first.

Parameters
----------
filename : str (optional)
path to the filename

Example
-------
Load with ::

import cPickle
table = cPickle.load(open(filename))

"""
if self.table is None:
self.generate_table()
with open(filename, 'w') as f:
cPickle.dump(self.table, f, protocol=cPickle.HIGHEST_PROTOCOL)

def _has_timeseries(self):
has_timeseries = self._timeseries is not None
if not has_timeseries:
Expand Down
30 changes: 6 additions & 24 deletions package/MDAnalysis/analysis/hbonds/hbond_autocorrel.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@

from MDAnalysis.lib.log import ProgressMeter
from MDAnalysis.lib.distances import capped_distance, calc_angles, calc_bonds
from MDAnalysis.lib.util import deprecate
from MDAnalysis.core.groups import requires

from MDAnalysis.due import due, Doi
Expand Down Expand Up @@ -285,6 +284,11 @@ class HydrogenBondAutoCorrel(object):
Within each run, the number of frames to analyse [50]
pbc : bool, optional
Whether to consider periodic boundaries in calculations [``True``]

..versionchanged: 1.0.0
``save_results()`` method was removed. You can instead use ``np.savez()``
on :attr:`HydrogenBondAutoCorrel.solution['time']` and
:attr:`HydrogenBondAutoCorrel.solution['results']` instead.
"""

def __init__(self, universe,
Expand Down Expand Up @@ -426,7 +430,7 @@ def _single_run(self, start, stop):
# 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)

hidx, aidx = np.transpose(pair)


Expand Down Expand Up @@ -481,28 +485,6 @@ def _single_run(self, start, stop):

return results

@deprecate(release="0.19.0", remove="1.0.0",
message="You can instead use "
"``np.savez(filename, time=HydrogenBondAutoCorrel.solution['time'], "
"results=HydrogenBondAutoCorrel.solution['results'])``.")
def save_results(self, filename='hbond_autocorrel'):
"""Saves the results to a numpy zipped array (.npz, see np.savez)

This can be loaded using np.load(filename)

Parameters
----------
filename : str, optional
The desired filename [hbond_autocorrel]

"""
if self.solution['results'] is not None:
np.savez(filename, time=self.solution['time'],
results=self.solution['results'])
else:
raise ValueError(
"Results have not been generated, use the run method first")

def solve(self, p_guess=None):
"""Fit results to an multi exponential decay and integrate to find
characteristic time
Expand Down
83 changes: 11 additions & 72 deletions package/MDAnalysis/analysis/psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,14 @@

int, frame index to select frame from :attr:`Path.u_reference`

.. attribute:: filename

string, name of file to store calculated distance matrix
(:attr:`PSAnalysis.D`)

.. attribute:: paths

list of :class:`numpy.ndarray` objects representing the set/ensemble of
fitted trajectories

.. attribute:: D

string, name of file to store calculated distance matrix
(:attr:`PSAnalysis.D`)
:class:`numpy.ndarray` whichs store calculated distance matrix


.. Markup definitions
Expand Down Expand Up @@ -1287,6 +1281,10 @@ class PSAnalysis(object):
alignment of the original trajectories to a reference structure.

.. versionadded:: 0.8

.. versionchanged:: 1.0.0
``save_result()`` method has been removed. You can use ``np.save()`` on
:attr:`PSAnalysis.D` instead.
"""
def __init__(self, universes, reference=None, ref_select='name CA',
ref_frame=0, path_select=None, labels=None,
Expand Down Expand Up @@ -1509,31 +1507,15 @@ def run(self, **kwargs):
``trajectory[start:stop:step]`` [``None``]
stop : int
step : int
store : bool
if ``True`` then writes :attr:`PSAnalysis.D` to text and
compressed npz (numpy) files [``True``]

.. deprecated:: 0.19.0
`store` will be removed together with :meth:`save_results` in 1.0.0.

filename : str
string, filename to save :attr:`PSAnalysis.D`

.. deprecated:: 0.19.0
`filename` will be removed together with :meth:`save_results` in 1.0.0.

.. versionchanged:: 1.0.0
`store` and `filename` have been removed.

"""
metric = kwargs.pop('metric', 'hausdorff')
start = kwargs.pop('start', None)
stop = kwargs.pop('stop', None)
step = kwargs.pop('step', None)
# DEPRECATED 0.19.0: remove in 1.0
if 'store' in kwargs:
warnings.warn("PSAnalysis.run(): 'store' was deprecated in 0.19.0 "
"and will be removed in 1.0",
category=DeprecationWarning)
store = kwargs.pop('store', True)

if isinstance(metric, string_types):
metric_func = get_path_metric_func(str(metric))
Expand All @@ -1549,16 +1531,6 @@ def run(self, **kwargs):
D[i,j] = metric_func(P, Q)
D[j,i] = D[i,j]
self.D = D
if store:
# DEPRECATED 0.19.0: remove in 1.0
if 'filename' in kwargs:
warnings.warn("PSAnalysis.run(): 'filename' was deprecated in "
"0.19.0 and will be removed in 1.0",
category=DeprecationWarning)
filename = kwargs.pop('filename', metric)
if not isinstance(metric, string_types):
filename = 'custom_metric'
self.save_result(filename=filename)

def run_pairs_analysis(self, **kwargs):
"""Perform PSA Hausdorff (nearest neighbor) pairs analysis on all unique
Expand Down Expand Up @@ -1618,38 +1590,6 @@ def run_pairs_analysis(self, **kwargs):
self._HP.append(pp.get_hausdorff_pair())
self.D = D

@deprecate(release="0.19.0", remove="1.0.0",
message="You can save the distance matrix :attr:`D` to a numpy "
"file with ``np.save(filename, PSAnalysis.D)``.")
def save_result(self, filename=None):
"""Save distance matrix :attr:`PSAnalysis.D` to a numpy compressed npz
file and text file.

The data are saved with :func:`numpy.savez_compressed` and
:func:`numpy.savetxt` in the directory specified by
:attr:`PSAnalysis.targetdir`.

Parameters
----------
filename : str
specifies filename [``None``]

Returns
-------
filename : str

"""
filename = filename or 'psa_distances'
head = os.path.join(self.targetdir, self.datadirs['distance_matrices'])
outfile = os.path.join(head, filename)
if self.D is None:
raise NoDataError("Distance matrix has not been calculated yet")
np.save(outfile + '.npy', self.D)
np.savetxt(outfile + '.dat', self.D)
logger.info("Wrote distance matrix to file %r.npz", outfile)
logger.info("Wrote distance matrix to file %r.dat", outfile)
return filename


def save_paths(self, filename=None):
"""Save fitted :attr:`PSAnalysis.paths` to numpy compressed npz files.
Expand Down Expand Up @@ -1756,7 +1696,7 @@ def plot(self, filename=None, linkage='ward', count_sort=False,

if self.D is None:
raise ValueError(
"No distance data; do 'PSAnalysis.run(store=True)' first.")
"No distance data; do 'PSAnalysis.run()' first.")
npaths = len(self.D)
dist_matrix = self.D

Expand Down Expand Up @@ -1907,7 +1847,7 @@ def plot_annotated_heatmap(self, filename=None, linkage='ward', \

if self.D is None:
raise ValueError(
"No distance data; do 'PSAnalysis.run(store=True)' first.")
"No distance data; do 'PSAnalysis.run()' first.")
dist_matrix = self.D

Z, dgram = self.cluster(method=linkage, \
Expand Down Expand Up @@ -2215,8 +2155,7 @@ def get_pairwise_distances(self, vectorform=False, checks=False):

Note
----
Must run :meth:`PSAnalysis.run` with ``store=True`` prior to
calling this method.
Must run :meth:`PSAnalysis.run` prior to calling this method.

Parameters
----------
Expand All @@ -2234,7 +2173,7 @@ def get_pairwise_distances(self, vectorform=False, checks=False):
"""
if self.D is None:
raise ValueError(
"No distance data; do 'PSAnalysis.run(store=True)' first.")
"No distance data; do 'PSAnalysis.run()' first.")
if vectorform:
return spatial.distance.squareform(self.D, force='tovector',
checks=checks)
Expand Down
3 changes: 2 additions & 1 deletion testsuite/MDAnalysisTests/analysis/test_hbonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations.
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#
# Note: to be removed with MDAnalysis.analysis.hbonds.hbond_analysis in 2.0

from __future__ import print_function, absolute_import


Expand Down Expand Up @@ -78,7 +80,6 @@ def h(self, universe):
kw = self.kwargs.copy()
# kw.update(kwargs)
h = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis(universe, **kw)
# remove in 1.0
if kw['detect_hydrogens'] == 'heuristic':
with pytest.warns(DeprecationWarning):
h.run(verbose=False)
Expand Down
Loading