Skip to content

Commit

Permalink
scipy and matplotlib are imported at top in analysis
Browse files Browse the repository at this point in the history
- updated all modules
- removed any code that guards against scipy or matplotlib import
- conforms to style guide https://github.com/MDAnalysis/mdanalysis/wiki/Style-Guide#module-imports-in-mdanalysisanalysis
- fixes MDAnalysis#1159
- fixes MDAnalysis#1361
  • Loading branch information
orbeckst authored and PicoCentauri committed Jan 22, 2019
1 parent 8e52abb commit 4042f28
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
1 change: 0 additions & 1 deletion package/MDAnalysis/analysis/hbonds/hbond_autocorrel.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ def solve(self, p_guess=None):
Initial guess for the leastsq fit, must match the shape of the
expected coefficients
Continuous defition results are fitted to a double exponential with
:func:`scipy.optimize.leastsq`, intermittent definition are fit to a
triple exponential.
Expand Down
4 changes: 4 additions & 0 deletions package/MDAnalysis/analysis/hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@
import matplotlib
import matplotlib.pyplot as plt

import numpy as np
import matplotlib
import matplotlib.pyplot as plt

from MDAnalysis import Universe
from MDAnalysis.exceptions import ApplicationError
from MDAnalysis.lib.util import (which, realpath, asiterable,
Expand Down
33 changes: 19 additions & 14 deletions package/MDAnalysis/analysis/psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@

import numpy as np
from scipy import spatial, cluster
from scipy.spatial.distance import directed_hausdorff
import matplotlib

import warnings
import numbers

import MDAnalysis
import MDAnalysis.analysis.align
from MDAnalysis import NoDataError
Expand Down Expand Up @@ -427,17 +429,25 @@ def hausdorff(P, Q):
Notes
-----
The Hausdorff distance is calculated in a brute force manner from the
distance matrix without further optimizations, essentially following
[Huttenlocher1993]_.
:func:`scipy.spatial.distance.directed_hausdorff` is an optimized
implementation of the early break algorithm of [Taha2015]_; the
latter code is used here to calculate the symmetric Hausdorff
distance with an RMSD metric
implementation of the early break algorithm of [Taha2015]_; note that one
still has to calculate the *symmetric* Hausdorff distance as
`max(directed_hausdorff(P, Q)[0], directed_hausdorff(Q, P)[0])`.
References
----------
.. [Taha2015] A. A. Taha and A. Hanbury. An efficient algorithm for
calculating the exact Hausdorff distance. IEEE Transactions On Pattern
Analysis And Machine Intelligence, 37:2153-63, 2015.
SeeAlso
-------
scipy.spatial.distance.directed_hausdorff
"""
N_p, axis_p = get_coord_axes(P)
N_q, axis_q = get_coord_axes(Q)
Expand Down Expand Up @@ -2017,6 +2027,8 @@ def plot_nearest_neighbors(self, filename=None, idx=0, \

return ax

return ax


def cluster(self, dist_mat=None, method='ward', count_sort=False, \
distance_sort=False, no_plot=False, no_labels=True, \
Expand Down Expand Up @@ -2067,13 +2079,7 @@ def cluster(self, dist_mat=None, method='ward', count_sort=False, \
orig_linewidth = matplotlib.rcParams['lines.linewidth']
matplotlib.rcParams['lines.linewidth'] = 0.5
try:
if dist_mat:
dist_vec = spatial.distance.squareform(dist_mat,
force='tovector',
checks=True)
else:
dist_vec = self.get_pairwise_distances(vectorform=True)
Z = cluster.hierarchy.linkage(dist_vec, method=method)
Z = cluster.hierarchy.linkage(distArray, method=method)
dgram = cluster.hierarchy.dendrogram(
Z, no_labels=no_labels, orientation='left',
count_sort=count_sort, distance_sort=distance_sort,
Expand Down Expand Up @@ -2117,7 +2123,7 @@ def get_num_atoms(self):
Returns
-------
int
the number of atoms in any path
the number of atoms
Note
----
Expand Down Expand Up @@ -2194,8 +2200,7 @@ def get_pairwise_distances(self, vectorform=False, checks=False):
raise ValueError(
"No distance data; do 'PSAnalysis.run(store=True)' first.")
if vectorform:
return spatial.distance.squareform(self.D, force='tovector',
checks=checks)
return spatial.distance.squareform(self.D)
else:
return self.D

Expand Down

0 comments on commit 4042f28

Please sign in to comment.