Skip to content

Commit

Permalink
Merge branch 'develop' into persistence_axes
Browse files Browse the repository at this point in the history
  • Loading branch information
ss62171 authored Mar 13, 2020
2 parents 05950ca + 9740d80 commit f4ee126
Show file tree
Hide file tree
Showing 19 changed files with 860 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cache:
environment:
global:
CONDA_CHANNELS: conda-forge
CONDA_DEPENDENCIES: pip setuptools wheel cython mock six biopython networkx joblib matplotlib scipy vs2015_runtime pytest mmtf-python GridDataFormats hypothesis pytest-cov codecov
CONDA_DEPENDENCIES: pip setuptools wheel cython mock six biopython networkx joblib matplotlib scipy vs2015_runtime pytest mmtf-python GridDataFormats hypothesis pytest-cov codecov chemfiles
PIP_DEPENDENCIES: gsd==1.9.3 duecredit parmed
DEBUG: "False"
MINGW_64: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ env:
- SETUP_CMD="${PYTEST_FLAGS}"
- BUILD_CMD="pip install -e package/ && (cd testsuite/ && python setup.py build)"
- CONDA_MIN_DEPENDENCIES="mmtf-python mock six biopython networkx cython matplotlib scipy griddataformats hypothesis gsd codecov"
- CONDA_DEPENDENCIES="${CONDA_MIN_DEPENDENCIES} seaborn>=0.7.0 clustalw=2.1 netcdf4 scikit-learn joblib>=0.12"
- CONDA_DEPENDENCIES="${CONDA_MIN_DEPENDENCIES} seaborn>=0.7.0 clustalw=2.1 netcdf4 scikit-learn joblib>=0.12 chemfiles"
- CONDA_CHANNELS='biobuilds conda-forge'
- CONDA_CHANNEL_PRIORITY=True
- PIP_DEPENDENCIES="duecredit parmed"
Expand Down Expand Up @@ -66,7 +66,7 @@ matrix:
INSTALL_HOLE="false"

- env: NAME="python 2.7"
PYTHON_VERSION=2.7
PYTHON_VERSION=2.7
CODECOV="true"
NUMPY_VERSION=1.16
SETUP_CMD="${PYTEST_FLAGS} --cov=MDAnalysis"
Expand Down
6 changes: 4 additions & 2 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ Chronological list of authors
2020
- Charlie Cook
- Yuanyu Chang
- Guillaume Fraux
- Ivan Hristov
- Michael Quevillon
- Hao Tian
- Hugo MacDermott-Opeskin
- Anshul Angaria


- Shubham Sharma
- Yuxuan Zhuang
- Abhishek Shandilya

External code
-------------
Expand Down
14 changes: 13 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ The rules for this file:
mm/dd/yy richardjgowers, kain88-de, lilyminium, p-j-smith, bdice, joaomcteixeira,
PicoCentauri, davidercruz, jbarnoud, RMeli, IAlibay, mtiberti, CCook96,
Yuan-Yu, xiki-tempula, HTian1997, Iv-Hristov, hmacdope, AnshulAngaria,
ss62171
ss62171, Luthaf, yuxuanzhuang, abhishandy

* 0.21.0

Fixes
* Fixed the deprecation warning from `collections` library in `flatten_dict`
(Issue #2605)
* Fixed test for the `save_paths` and `load` methods of :class:`PSAnalysis`
(Issue #2593)
* Fixes outdated :class:`TRJReader` documentation on random frame access
(Issue #2398)
* Fixed mda.Merge for Universes without coordinates (Issue #2470)(PR #2580)
* PCA(align=True) now correctly aligns the trajectory and computes the
correct means and covariance matrix (Issue #2561)
Expand Down Expand Up @@ -59,8 +65,11 @@ Fixes
argument. The directives parsed into bonds, angles, impropers, and dihedrals now
match TPRParser. (PR #2408)
* Added parmed to setup.py
* Fixed example docs for polymer persistence length (#2582)
* Added missing selection module to leaflet.py (Issue #2612)

Enhancements
* Added ability to use Chemfiles as a trajectory reader backend (PR #1862)
* New analysis.hole2 module for HOLE interfacing. Contains a function (hole)
for running HOLE on singular PDB files and class (HoleAnalysis) for
trajectories (PR #2523)
Expand Down Expand Up @@ -96,6 +105,9 @@ Enhancements
* PersistenceLength.plot() now create new axes if current axes not provided (Issue #2590)

Changes
* Removed deprecated :meth:`PersistenceLength.perform_fit` (Issue #2596)
* Changed :meth:`PSAnalysis.generate_paths` keywords `store` and `filename`
defaults to `False` and `None` (Issue #2593)
* Removed `format` keyword from :meth:`MemoryReader.timeseries` (Issue #1453,
#2443)
* Deprecated :class:`LAMMPSDataConverter` has now been removed (Issue #2564)
Expand Down
5 changes: 3 additions & 2 deletions package/MDAnalysis/analysis/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@

from .. import core
from . import distances
from .. import selections

from ..due import due, Doi

Expand Down Expand Up @@ -174,7 +175,7 @@ def _get_graph(self):
# only try distance array
try:
adj = distances.contact_matrix(coord, cutoff=self.cutoff, returntype="numpy", box=box)
except ValueError:
except ValueError: # pragma: no cover
warnings.warn('N x N matrix too big, use sparse=True or sparse=None', category=UserWarning,
stacklevel=2)
raise
Expand All @@ -186,7 +187,7 @@ def _get_graph(self):
try:
# this works for small-ish systems and depends on system memory
adj = distances.contact_matrix(coord, cutoff=self.cutoff, returntype="numpy", box=box)
except ValueError:
except ValueError: # pragma: no cover
# but use a sparse matrix method for larger systems for memory reasons
warnings.warn(
'N x N matrix too big - switching to sparse matrix method (works fine, but is currently rather '
Expand Down
16 changes: 7 additions & 9 deletions package/MDAnalysis/analysis/polymer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@
# so we can select the chains by using the .fragments attribute
chains = u.atoms.fragments
# select only the backbone atoms for each chain
backbones = [chain.select_atoms('not name O* H') for chain in chains]
backbones = [chain.select_atoms('not name O* H*') for chain in chains]
# sort the chains, removing any non-backbone atoms
sorted_backbones = [polymer.sort_backbone(bb) for bb in backbones]
lp = polymer.PersistenceLength(sorted_backbones)
persistence_length = polymer.PersistenceLength(sorted_backbones)
# Run the analysis, this will average over all polymer chains
# and all timesteps in trajectory
lp = lp.run()
print('The persistence length is: {}'.format(lp.pl))
persistence_length = persistence_length.run()
print('The persistence length is: {}'.format(persistence_length.lp))
# always check the visualisation of this:
lp.plot()
persistence_length.plot()
"""
from __future__ import division, absolute_import
Expand Down Expand Up @@ -189,6 +189,8 @@ class PersistenceLength(AnalysisBase):
.. versionadded:: 0.13.0
.. versionchanged:: 0.20.0
The run method now automatically performs the exponential fit
.. versionchanged:: 1.0.0
Deprecated :meth:`PersistenceLength.perform_fit` has now been removed.
"""
def __init__(self, atomgroups, **kwargs):
super(PersistenceLength, self).__init__(
Expand Down Expand Up @@ -240,10 +242,6 @@ def _calc_bond_length(self):
bs.append(b)
self.lb = np.mean(bs)

def perform_fit(self):
warnings.warn("perform_fit is now called automatically from run",
DeprecationWarning)

def _perform_fit(self):
"""Fit the results to an exponential decay"""
try:
Expand Down
42 changes: 13 additions & 29 deletions package/MDAnalysis/analysis/psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
cite_module=True)
del Doi


def get_path_metric_func(name):
"""Selects a path metric function by name.
Expand Down Expand Up @@ -835,7 +836,6 @@ def __init__(self, universe, reference, select='name CA',
self.path = None
self.natoms = None


def fit_to_reference(self, filename=None, prefix='', postfix='_fit',
rmsdfile=None, targetdir=os.path.curdir,
weights=None, tol_mass=0.1):
Expand Down Expand Up @@ -894,7 +894,6 @@ def fit_to_reference(self, filename=None, prefix='', postfix='_fit',
aligntrj.save(rmsdfile)
return MDAnalysis.Universe(self.top_name, self.newtrj_name)


def to_path(self, fitted=False, select=None, flat=False):
r"""Generates a coordinate time series from the fitted universe
trajectory.
Expand Down Expand Up @@ -947,7 +946,6 @@ def to_path(self, fitted=False, select=None, flat=False):
else:
return np.array([atoms.positions for _ in frames])


def run(self, align=False, filename=None, postfix='_fit', rmsdfile=None,
targetdir=os.path.curdir, weights=None, tol_mass=0.1,
flat=False):
Expand Down Expand Up @@ -1018,7 +1016,6 @@ def run(self, align=False, filename=None, postfix='_fit', rmsdfile=None,
self.path = self.to_path(fitted=align, flat=flat)
return self.top_name, self.newtrj_name


def get_num_atoms(self):
"""Return the number of atoms used to construct the :class:`Path`.
Expand Down Expand Up @@ -1103,7 +1100,6 @@ def __init__(self, npaths, i, j):
# Set by self.getHausdorffPair
self.hausdorff_pair = {'frames' : (None, None), 'distance' : None}


def _dvec_idx(self, i, j):
"""Convert distance matrix indices (in the upper triangle) to the index
of the corresponding distance vector.
Expand All @@ -1127,7 +1123,6 @@ def _dvec_idx(self, i, j):
"""
return (self.npaths*i) + j - (i+2)*(i+1)/2


def compute_nearest_neighbors(self, P,Q, N=None):
"""Generates Hausdorff nearest neighbor lists of *frames* (by index) and
*distances* for *this* pair of paths corresponding to distance matrix
Expand Down Expand Up @@ -1155,7 +1150,6 @@ def compute_nearest_neighbors(self, P,Q, N=None):
self.nearest_neighbors['frames'] = hn['frames']
self.nearest_neighbors['distances'] = hn['distances']


def find_hausdorff_pair(self):
r"""Find the Hausdorff pair (of frames) for *this* pair of paths.
Expand Down Expand Up @@ -1183,7 +1177,6 @@ def find_hausdorff_pair(self):
self.hausdorff_pair['frames'] = nn_idx_Q[max_nn_idx_Q], max_nn_idx_Q
self.hausdorff_pair['distance'] = max_nn_dist_Q


def get_nearest_neighbors(self, frames=True, distances=True):
"""Returns the nearest neighbor frame indices, distances, or both, for
each path in *this* :class:`PSAPair`.
Expand Down Expand Up @@ -1403,9 +1396,8 @@ def __init__(self, universes, reference=None, select='name CA',
self._NN = None # (distance vector order) list of all nearest neighbors
self._psa_pairs = None # (distance vector order) list of all PSAPairs


def generate_paths(self, align=False, filename='fitted', infix='', weights=None,
tol_mass=False, ref_frame=None, flat=False, save=True, store=True):
def generate_paths(self, align=False, filename=None, infix='', weights=None,
tol_mass=False, ref_frame=None, flat=False, save=True, store=False):
"""Generate paths, aligning each to reference structure if necessary.
Parameters
Expand All @@ -1424,12 +1416,12 @@ def generate_paths(self, align=False, filename='fitted', infix='', weights=None,
``None`` weigh each atom equally. If a float array of the same
length as the selected AtomGroup is provided, use each element of
the `array_like` as a weight for the corresponding atom in the
AtomGroup.
AtomGroup [``None``]
tol_mass : float
Reject match if the atomic masses for matched atoms differ by more
than *tol_mass*
than *tol_mass* [``False``]
ref_frame : int
frame index to select frame from *reference*
frame index to select frame from *reference* [``None``]
flat : bool
represent :attr:`Path.path` as a 2D (|2D|) :class:`numpy.ndarray`;
if ``False`` then :attr:`Path.path` is a 3D (|3D|)
Expand Down Expand Up @@ -1459,6 +1451,11 @@ def generate_paths(self, align=False, filename='fitted', infix='', weights=None,
.. versionchanged:: 0.17.0
Deprecated keyword `mass_weighted` was removed.
.. versionchanged:: 1.0.0
Defaults for the `store` and `filename` keywords have been changed
from `True` and `fitted` to `False` and `None` respectively. These
now match the docstring documented defaults.
"""
if ref_frame is None:
ref_frame = self.ref_frame
Expand Down Expand Up @@ -1487,7 +1484,6 @@ def generate_paths(self, align=False, filename='fitted', infix='', weights=None,
if store:
self.save_paths(filename=filename)


def run(self, **kwargs):
"""Perform path similarity analysis on the trajectories to compute
the distance matrix.
Expand Down Expand Up @@ -1590,7 +1586,6 @@ def run_pairs_analysis(self, **kwargs):
self._HP.append(pp.get_hausdorff_pair())
self.D = D


def save_paths(self, filename=None):
"""Save fitted :attr:`PSAnalysis.paths` to numpy compressed npz files.
Expand Down Expand Up @@ -1627,7 +1622,6 @@ def save_paths(self, filename=None):
cPickle.dump(self.path_names, output)
return filename


def load(self):
"""Load fitted paths specified by 'psa_path-names.pkl' in
:attr:`PSAnalysis.targetdir`.
Expand All @@ -1642,13 +1636,12 @@ def load(self):
if not os.path.exists(self._paths_pkl):
raise NoDataError("Fitted trajectories cannot be loaded; save file" +
"{0} does not exist.".format(self._paths_pkl))
self.path_names = np.load(self._paths_pkl)
self.path_names = np.load(self._paths_pkl, allow_pickle=True)
self.paths = [np.load(pname) for pname in self.path_names]
if os.path.exists(self._labels_pkl):
self.labels = np.load(self._labels_pkl)
self.labels = np.load(self._labels_pkl, allow_pickle=True)
logger.info("Loaded paths from %r", self._paths_pkl)


def plot(self, filename=None, linkage='ward', count_sort=False,
distance_sort=False, figsize=4.5, labelsize=12):
"""Plot a clustered distance matrix.
Expand Down Expand Up @@ -1769,7 +1762,6 @@ def plot(self, filename=None, linkage='ward', count_sort=False,

return Z, dgram, dist_matrix_clus


def plot_annotated_heatmap(self, filename=None, linkage='ward', \
count_sort=False, distance_sort=False, \
figsize=8, annot_size=6.5):
Expand Down Expand Up @@ -1893,7 +1885,6 @@ def plot_annotated_heatmap(self, filename=None, linkage='ward', \

return Z, dgram, dist_matrix_clus


def plot_nearest_neighbors(self, filename=None, idx=0, \
labels=('Path 1', 'Path 2'), figsize=4.5, \
multiplot=False, aspect_ratio=1.75, \
Expand Down Expand Up @@ -1999,7 +1990,6 @@ def plot_nearest_neighbors(self, filename=None, idx=0, \

return ax


def cluster(self, dist_mat=None, method='ward', count_sort=False, \
distance_sort=False, no_plot=False, no_labels=True, \
color_threshold=4):
Expand Down Expand Up @@ -2091,7 +2081,6 @@ def _get_plot_obj_locs(self):

return dgram_loc, hmap_loc, cbar_loc


def get_num_atoms(self):
"""Return the number of atoms used to construct the :class:`Path` instances in
:class:`PSA`.
Expand All @@ -2111,7 +2100,6 @@ def get_num_atoms(self):
"No path data; do 'PSAnalysis.generate_paths()' first.")
return self.natoms


def get_num_paths(self):
"""Return the number of paths in :class:`PSA`.
Expand All @@ -2129,7 +2117,6 @@ def get_num_paths(self):
"No path data; do 'PSAnalysis.generate_paths()' first.")
return self.npaths


def get_paths(self):
"""Return the paths in :class:`PSA`.
Expand All @@ -2149,7 +2136,6 @@ def get_paths(self):
"No path data; do 'PSAnalysis.generate_paths()' first.")
return self.paths


def get_pairwise_distances(self, vectorform=False, checks=False):
"""Return the distance matrix (or vector) of pairwise path distances.
Expand Down Expand Up @@ -2180,7 +2166,6 @@ def get_pairwise_distances(self, vectorform=False, checks=False):
else:
return self.D


@property
def psa_pairs(self):
"""The list of :class:`PSAPair` instances for each pair of paths.
Expand Down Expand Up @@ -2210,7 +2195,6 @@ def psa_pairs(self):
" 'PSAnalysis.run_pairs_analysis()' first.")
return self._psa_pairs


@property
def hausdorff_pairs(self):
"""The Hausdorff pair for each (unique) pairs of paths.
Expand Down
6 changes: 0 additions & 6 deletions package/MDAnalysis/coordinates/TRJ.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@
* The trajectory does not contain time information so we simply set
the time step to 1 ps (or the user could provide it as kwarg *dt*)
* **No direct access of frames is implemented, only iteration through
the trajectory.**
* Trajectories with fewer than 4 atoms probably fail to be read (BUG).
* If the trajectory contains exactly *one* atom then it is always
Expand Down Expand Up @@ -204,9 +201,6 @@ class TRJReader(base.ReaderBase):
be set by passing the `dt` keyword argument to the constructor; it
is assumed to be in ps. The default value is 1 ps.
Functionality is currently limited to simple iteration over the
trajectory.
.. _AMBER TRJ format: http://ambermd.org/formats.html#trajectory
.. versionchanged:: 0.11.0
Expand Down
Loading

0 comments on commit f4ee126

Please sign in to comment.