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
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ Changes
* removes deprecated `as_Universe` function from MDAnalysis.core.universe,
as a result :class:`MDAnalysis.analysis.leaflet.LeafletFinder` now only
accepts Universes for its `universe` argument (Issue #2920)
* deprecated Python escape sequence usage has been fixed in our test suite,
and the test suite will now raise an error for this usage of `\` (PR #2885)
* deprecated NumPy type aliases have been replaced with their actual types
(see upstream NumPy PR 14882), and our pytest configuration will raise an
error for any violation when testing with development NumPy builds
Expand Down
21 changes: 12 additions & 9 deletions package/MDAnalysis/analysis/data/filenames.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations.
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#
"""Analysis data files
r"""Analysis data files
===================

:mod:`MDAnalysis.analysis.data` contains data files that are used as part of
analysis. These can be experimental or theoretical data. Files are stored
inside the package and made accessible via variables in
:mod:`MDAnalysis.analysis.data.filenames`. These variables are documented
below, including references to the literature and where they are used
inside :mod:`MDAnalysis.analysis`.
below, including references to the literature and where they are used inside
:mod:`MDAnalysis.analysis`.

Data files
----------

.. data:: Rama_ref

Reference Ramachandran histogram for :class:`MDAnalysis.analysis.dihedrals.Ramachandran`.
The data were calculated on a data set of 500 PDB structures taken from [Lovell2003]_.
This is a numpy array in the :math:`\phi` and :math:`psi` backbone dihedral angles.
Reference Ramachandran histogram for
:class:`MDAnalysis.analysis.dihedrals.Ramachandran`. The data were
calculated on a data set of 500 PDB structures taken from [Lovell2003]_.
This is a numpy array in the :math:`\phi` and :math:`\psi` backbone dihedral
angles.

Load and plot it with ::

Expand All @@ -55,8 +57,9 @@
.. data:: Janin_ref

Reference Janin histogram for :class:`MDAnalysis.analysis.dihedrals.Janin`.
The data were calculated on a data set of 500 PDB structures taken from [Lovell2003]_.
This is a numpy array in the :math:`\chi_1` and :math:`chi_2` sidechain dihedral angles.
The data were calculated on a data set of 500 PDB structures taken from
[Lovell2003]_. This is a numpy array in the :math:`\chi_1` and
:math:`\chi_2` sidechain dihedral angles.

Load and plot it with ::

Expand All @@ -73,7 +76,7 @@
"""

__all__ = [
"Rama_ref", "Janin_ref" # reference plots for Ramachandran and Janin classes
"Rama_ref", "Janin_ref", # reference plots for Ramachandran and Janin classes
]

from pkg_resources import resource_filename
Expand Down
9 changes: 5 additions & 4 deletions package/MDAnalysis/analysis/dihedrals.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class Ramachandran(AnalysisBase):

.. versionchanged:: 1.0.0
added c_name, n_name, ca_name, and check_protein keyword arguments

"""

def __init__(self, atomgroup, c_name='C', n_name='N', ca_name='CA',
Expand Down Expand Up @@ -422,8 +423,8 @@ def _conclude(self):
def plot(self, ax=None, ref=False, **kwargs):
"""Plots data into standard Ramachandran plot.

Each time step in :attr:`Ramachandran.angles` is plotted onto
the same graph.
Each time step in :attr:`Ramachandran.angles` is plotted onto the same
graph.

Parameters
----------
Expand Down Expand Up @@ -468,8 +469,8 @@ def plot(self, ax=None, ref=False, **kwargs):


class Janin(Ramachandran):
r"""Calculate :math:`\chi_1` and :math:`\chi_2` dihedral angles of
selected residues.
r"""Calculate :math:`\chi_1` and :math:`\chi_2` dihedral angles of selected
residues.

:math:`\chi_1` and :math:`\chi_2` angles will be calculated for each residue
corresponding to `atomgroup` for each time step in the trajectory. A
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ def __init__(self, elem_list=None, centroid=None, idn=None, metadata=None):
if metadata:
for name, data in metadata.items():
if len(data) != self.size:
raise TypeError("Size of metadata having label \"{0}\"\
is not equal to the number of cluster elmements".format(name))
raise TypeError('Size of metadata having label "{0}"'
'is not equal to the number of cluster '
'elements'.format(name))
self.add_metadata(name, data)

def __iter__(self):
Expand All @@ -119,8 +120,8 @@ def __len__(self):

def add_metadata(self, name, data):
if len(data) != self.size:
raise TypeError("Size of metadata is not equal to the number of\
cluster elmements")
raise TypeError("Size of metadata is not equal to the number of"
"cluster elmements")
self.metadata[name] = np.array(data)

def __repr__(self):
Expand Down Expand Up @@ -192,8 +193,9 @@ def __init__(self, elements=None, metadata=None):
centroids = np.unique(elements_array)
for i in centroids:
if elements[i] != i:
raise ValueError("element {0}, which is a centroid, doesn't \
belong to its own cluster".format(elements[i]))
raise ValueError("element {0}, which is a centroid, doesn't "
"belong to its own cluster".format(
elements[i]))
for c in centroids:
this_metadata = {}
this_array = np.where(elements_array == c)
Expand Down
6 changes: 3 additions & 3 deletions package/MDAnalysis/analysis/encore/confdistmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def conformational_distance_matrix(ensemble,
# Initialize workers. Simple worker doesn't perform fitting,
# fitter worker does.
indices = trm_indices((0, 0), (framesn - 1, framesn - 1))
Parallel(n_jobs=n_jobs, verbose=verbose, require='sharedmem',
Parallel(n_jobs=n_jobs, verbose=verbose, require='sharedmem',
max_nbytes=max_nbytes)(delayed(conf_dist_function)(
np.int64(element),
rmsd_coordinates,
Expand Down Expand Up @@ -247,8 +247,8 @@ def set_rmsd_matrix_elements(tasks, coords, rmsdmat, weights, fit_coords=None,
rotated_i.astype(np.float64), translated_j.astype(np.float64),
coords[j].shape[0], weights, sumweights)
else:
raise TypeError("Both fit_coords and fit_weights must be specified \
if one of them is given")
raise TypeError("Both fit_coords and fit_weights must be specified "
"if one of them is given")


def get_distance_matrix(ensemble,
Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/encore/covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def shrinkage_covariance_estimator( coordinates,
xmkt = np.average(x, axis=1)

# Call maximum likelihood estimator (note the additional column)
sample = ml_covariance_estimator(np.hstack([x, xmkt[:, np.newaxis]]), 0) \
sample = ml_covariance_estimator(np.hstack([x, xmkt[:, np.newaxis]]), 0)\
* (t-1)/float(t)

# Split covariance matrix into components
Expand Down
76 changes: 40 additions & 36 deletions package/MDAnalysis/analysis/encore/similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,30 +469,33 @@ def gen_kde_pdfs(embedded_space, ensemble_assignment, nensembles,
def dimred_ensemble_similarity(kde1, resamples1, kde2, resamples2,
ln_P1_exp_P1=None, ln_P2_exp_P2=None,
ln_P1P2_exp_P1=None, ln_P1P2_exp_P2=None):
"""
Calculate the Jensen-Shannon divergence according the the
Dimensionality reduction method. In this case, we have continuous
probability densities, this we need to integrate over the measurable
space. The aim is to first calculate the Kullback-Liebler divergence, which
is defined as:
r"""Calculate the Jensen-Shannon divergence according the Dimensionality
reduction method.

In this case, we have continuous probability densities, this we need to
integrate over the measurable space. The aim is to first calculate the
Kullback-Liebler divergence, which is defined as:

.. math::
D_{KL}(P(x) || Q(x)) = \\int_{-\\infty}^{\\infty}P(x_i) ln(P(x_i)/Q(x_i)) = \\langle{}ln(P(x))\\rangle{}_P - \\langle{}ln(Q(x))\\rangle{}_P

where the :math:`\\langle{}.\\rangle{}_P` denotes an expectation calculated
D_{KL}(P(x) || Q(x)) =
\int_{-\infty}^{\infty}P(x_i) ln(P(x_i)/Q(x_i)) =
\langle{}ln(P(x))\rangle{}_P - \langle{}ln(Q(x))\rangle{}_P

where the :math:`\langle{}.\rangle{}_P` denotes an expectation calculated
under the distribution P. We can, thus, just estimate the expectation
values of the components to get an estimate of dKL.
Since the Jensen-Shannon distance is actually more complex, we need to
estimate four expectation values:
values of the components to get an estimate of dKL. Since the
Jensen-Shannon distance is actually more complex, we need to estimate four
expectation values:

.. math::
\\langle{}log(P(x))\\rangle{}_P
\langle{}log(P(x))\rangle{}_P

\\langle{}log(Q(x))\\rangle{}_Q
\langle{}log(Q(x))\rangle{}_Q

\\langle{}log(0.5*(P(x)+Q(x)))\\rangle{}_P
\langle{}log(0.5*(P(x)+Q(x)))\rangle{}_P

\\langle{}log(0.5*(P(x)+Q(x)))\\rangle{}_Q
\langle{}log(0.5*(P(x)+Q(x)))\rangle{}_Q

Parameters
----------
Expand All @@ -512,22 +515,22 @@ def dimred_ensemble_similarity(kde1, resamples1, kde2, resamples2,
calculate the expected values according to 'Q' as detailed before.

ln_P1_exp_P1 : float or None
Use this value for :math:`\\langle{}log(P(x))\\rangle{}_P`; if None,
Use this value for :math:`\langle{}log(P(x))\rangle{}_P`; if ``None``,
calculate it instead

ln_P2_exp_P2 : float or None
Use this value for :math:`\\langle{}log(Q(x))\\rangle{}_Q`; if
None, calculate it instead
Use this value for :math:`\langle{}log(Q(x))\rangle{}_Q`; if
``None``, calculate it instead

ln_P1P2_exp_P1 : float or None
Use this value for
:math:`\\langle{}log(0.5*(P(x)+Q(x)))\\rangle{}_P`;
if None, calculate it instead
:math:`\langle{}log(0.5*(P(x)+Q(x)))\rangle{}_P`;
if ``None``, calculate it instead

ln_P1P2_exp_P2 : float or None
Use this value for
:math:`\\langle{}log(0.5*(P(x)+Q(x)))\\rangle{}_Q`;
if None, calculate it instead
:math:`\langle{}log(0.5*(P(x)+Q(x)))\rangle{}_Q`;
if ``None``, calculate it instead

Returns
-------
Expand Down Expand Up @@ -720,11 +723,10 @@ def hes(ensembles,
estimate_error=False,
bootstrapping_samples=100,
calc_diagonal=False):
"""
r"""Calculates the Harmonic Ensemble Similarity (HES) between ensembles.

Calculates the Harmonic Ensemble Similarity (HES) between ensembles using
the symmetrized version of Kullback-Leibler divergence as described
in [Tiberti2015]_.
The HES is calculated with the symmetrized version of Kullback-Leibler
divergence as described in [Tiberti2015]_.

Parameters
----------
Expand Down Expand Up @@ -766,13 +768,13 @@ def hes(ensembles,
symmetrized version of Kullback-Leibler divergence defined as:

.. math::
D_{KL}(P(x) || Q(x)) = \\int_{-\\infty}^{\\infty}P(x_i)
ln(P(x_i)/Q(x_i)) = \\langle{}ln(P(x))\\rangle{}_P -
\\langle{}ln(Q(x))\\rangle{}_P
D_{KL}(P(x) || Q(x)) =
\int_{-\infty}^{\infty}P(x_i) ln(P(x_i)/Q(x_i)) =
\langle{}ln(P(x))\rangle{}_P - \langle{}ln(Q(x))\rangle{}_P


where the :math:`\\langle{}.\\rangle{}_P` denotes an expectation
calculated under the distribution P.
where the :math:`\langle{}.\rangle{}_P` denotes an expectation
calculated under the distribution :math:`P`.

For each ensemble, the mean conformation is estimated as the average over
the ensemble, and the covariance matrix is calculated by default using a
Expand Down Expand Up @@ -802,16 +804,17 @@ def hes(ensembles,
[ 38279683.95892926 0. ]]


You can use the align=True option to align the ensembles first. This will
You can use the ``align=True`` option to align the ensembles first. This will
align everything to the current timestep in the first ensemble. Note that
this changes the ens1 and ens2 objects:
this changes the ``ens1`` and ``ens2`` objects:

>>> print(encore.hes([ens1, ens2], align=True)[0])
[[ 0. 6880.34140106]
[ 6880.34140106 0. ]]

Alternatively, for greater flexibility in how the alignment should be done
you can call use an AlignTraj object manually:
you can call use an :class:`~MDAnalysis.analysis.align.AlignTraj` object
manually:

>>> from MDAnalysis.analysis import align
>>> align.AlignTraj(ens1, ens1, select="name CA", in_memory=True).run()
Expand All @@ -820,9 +823,10 @@ def hes(ensembles,
[[ 0. 7032.19607004]
[ 7032.19607004 0. ]]


.. versionchanged:: 1.0.0
hes doesn't accept the *details* argument anymore, it always returns the
details of the calculation instead, in the form of a dictionary
``hes`` doesn't accept the `details` argument anymore, it always returns
the details of the calculation instead, in the form of a dictionary

"""

Expand Down
4 changes: 2 additions & 2 deletions package/MDAnalysis/analysis/encore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def __str__(self):


class ParallelCalculation(object):
"""
r"""
Generic parallel calculation class. Can use arbitrary functions,
arguments to functions and kwargs to functions.

Expand Down Expand Up @@ -279,7 +279,7 @@ def worker(self, q, results):
results.put((i, self.functions[i](*self.args[i], **self.kwargs[i])))

def run(self):
"""
r"""
Run parallel calculation.

Returns
Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/gnm.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def run(self, start=None, stop=None, step=None):


class closeContactGNMAnalysis(GNMAnalysis):
"""GNMAnalysis only using close contacts.
r"""GNMAnalysis only using close contacts.

This is a version of the GNM where the Kirchoff matrix is
constructed from the close contacts between individual atoms
Expand Down
Loading