Skip to content

Commit

Permalink
Merge branch 'develop' into issue-1725-DX-type-double
Browse files Browse the repository at this point in the history
  • Loading branch information
orbeckst committed Jan 21, 2018
2 parents 07d1d61 + 5a06075 commit b09278c
Show file tree
Hide file tree
Showing 41 changed files with 424 additions and 169 deletions.
159 changes: 159 additions & 0 deletions benchmarks/benchmarks/analysis/psa.py
@@ -0,0 +1,159 @@
from __future__ import division, absolute_import, print_function

import MDAnalysis
import numpy as np

try:
from MDAnalysis.analysis import psa
except:
pass

class PSA_sqnormBench(object):
"""Benchmarks for MDAnalysis.analysis.psa.
sqnorm
"""

params = ([2,3,4],
[100,1000,10000],
[None, 0, 1, -1])

# num_cols is equivalent to dimensions
# num_rows is equivalent to i.e., num atoms
param_names = ['num_cols',
'num_rows',
'axis']

def setup(self, num_cols, num_rows, axis):
np.random.seed(170089)
self.v = np.random.rand(num_rows, num_cols)

def time_sqnorm(self, num_cols, num_rows, axis):
"""Benchmark sqnorm in psa module
"""
psa.sqnorm(v=self.v, axis=axis)

class PSA_get_msd_matrixBench(object):
"""Benchmarks for MDAnalysis.analysis.psa.
get_msd_matrix
"""

params = ([10,100,1000],
[5,25,50])

# since the function is defined to work with
# 3N dimension data sets, we will restrict
# benchmarks to that dimensionality
param_names = ['time_steps',
'n_atoms']

def setup(self, time_steps, n_atoms):
np.random.seed(170089)
self.P = np.random.rand(time_steps,
n_atoms,
3)
np.random.seed(971132)
self.Q = np.random.rand(time_steps,
n_atoms,
3)

def time_get_msd_matrix(self, time_steps, n_atoms):
"""Benchmark for get_msd_matrix in psa module
"""
# only default argument for axis is benchmarked
psa.get_msd_matrix(P=self.P,
Q=self.Q,
axis=None)

class PSA_get_coord_axesBench(object):
"""Benchmarks for MDAnalysis.analysis.psa.
get_coord_axes
"""

params = ([10,100,1000],
[5, 25, 50])

param_names = ['time_steps',
'n_atoms']

def setup(self, time_steps, n_atoms):
np.random.seed(170089)
# only using condensed path input
# data structure for now
self.path = np.random.rand(time_steps,
n_atoms * 3)

def time_get_coord_axes(self, time_steps, n_atoms):
"""Benchmark get_coord_axes in psa module
"""
psa.get_coord_axes(path=self.path)

class PSA_get_path_metric_funcBench(object):
"""Benchmark for MDAnalysis.analysis.psa.
get_path_metric_func
"""

params = (['hausdorff',
'weighted_average_hausdorff',
'average_hausdorff',
'hausdorff_neighbors',
'discrete_frechet'])

param_names = ['path_metric']

def time_get_path_metric_func(self, path_metric):
"""Benchmark for get_path_metric_func in psa
module
"""
psa.get_path_metric_func(name=path_metric)

class PSA_metricBench(object):
"""Benchmarks for the various path metric calculations
in the psa module.
"""

params = ([10,100,200],
[5,25,50])

param_names = ['time_steps',
'n_atoms']

def setup(self, time_steps, n_atoms):
np.random.seed(170089)
self.P = np.random.rand(time_steps,
n_atoms,
3)
np.random.seed(971132)
self.Q = np.random.rand(time_steps,
n_atoms,
3)

def time_hausdorff(self, time_steps, n_atoms):
"""Benchmark for hausdorff() in psa module.
"""
psa.hausdorff(P=self.P,
Q=self.Q)

def time_hausdorff_wavg(self, time_steps, n_atoms):
"""Benchmark for hausdorff_wavg() in psa module.
"""
psa.hausdorff_wavg(P=self.P,
Q=self.Q)

def time_hausdorff_avg(self, time_steps, n_atoms):
"""Benchmark for hausdorff_avg() in psa module.
"""
psa.hausdorff_avg(P=self.P,
Q=self.Q)


def time_hausdorff_neighbors(self, time_steps, n_atoms):
"""Benchmark for hausdorff_neighbors() in psa module.
"""
psa.hausdorff_neighbors(P=self.P,
Q=self.Q)

def time_discrete_frechet(self, time_steps, n_atoms):
"""Benchmark for discrete_frechet() in psa module.
"""
psa.discrete_frechet(P=self.P,
Q=self.Q)
8 changes: 5 additions & 3 deletions package/CHANGELOG
Expand Up @@ -26,8 +26,6 @@ Enhancements
* Python versions 3.4 and upwards are now supported (Issue #260)
* add low level lib.formats.libdcd module for reading/writing DCD (PR #1372)
* replace old DCD reader with a Python 3 ready DCD reader (Issue #659)
* The TPR parser populate the `moltypes` topology attribute and
the `moltype` selection keyword is added (Issue #1555)
* about 20% speed improvements for GNM analysis. (PR #1579)
* added support for Tinker TXYZ and ARC files
* libmdaxdr and libdcd classes can now be pickled (PR #1680)
Expand All @@ -38,9 +36,13 @@ Enhancements
* use gridDataFormats >= 0.4.0 for new 'type' kwarg in
analysis.density.Density.export() to enable writing DX files
compatible with (buggy) PyMOL (#1725)

* The TPR parser populate the `moltypes` and `molnums` topology attributes;
the `moltype` and `molnum` selection keyword are added
(Issue #1555, PR #1578)

Deprecations
* HydrogenBondAnalysis detect_hydrogens=heuristic is marked for deprecation in 1.0
* timeseries keyword format is replaced by order. The format keyword is marked for deprecation in 1.0

Fixes
* Fixed analysis.psa.dist_mat_to_vec not returning int values (Issue #1507)
Expand Down
14 changes: 7 additions & 7 deletions package/MDAnalysis/analysis/align.py
Expand Up @@ -74,30 +74,30 @@
>>> ref = mda.Universe(PDB_small)
>>> mobile = mda.Universe(PSF,DCD)
>>> rmsd(mobile.atoms.CA.positions, ref.atoms.CA.positions)
>>> rmsd(mobile.select_atoms('name CA').positions, ref.select_atoms('name CA').positions)
16.282308620224068
Note that in this example translations have not been removed. In order
to look at the pure rotation one needs to superimpose the centres of
mass (or geometry) first:
>>> rmsd(mobile.atoms.CA.positions, ref.atoms.CA.positions, center=True)
>>> rmsd(mobile.select_atoms('name CA').positions, ref.select_atoms('name CA').positions, center=True)
12.639693690256898
This has only done a translational superposition. If you want to also do a
rotational superposition use the superposition keyword. This will calculate a
minimized RMSD between the reference and mobile structure.
>>> rmsd(mobile.atoms.CA.positions, ref.atoms.CA.positions,
>>> rmsd(mobile.select_atoms('name CA').positions, ref.select_atoms('name CA').positions,
>>> superposition=True)
6.8093965864717951
The rotation matrix that superimposes *mobile* on *ref* while
minimizing the CA-RMSD is obtained with the :func:`rotation_matrix`
function ::
>>> mobile0 = mobile.atoms.CA.positions - mobile.atoms.center_of_mass()
>>> ref0 = ref.atoms.CA.positions - ref.atoms.center_of_mass()
>>> mobile0 = mobile.select_atoms('name CA').positions - mobile.atoms.center_of_mass()
>>> ref0 = ref.select_atoms('name CA').positions - ref.atoms.center_of_mass()
>>> R, rmsd = align.rotation_matrix(mobile0, ref0)
>>> print rmsd
6.8093965864717951
Expand All @@ -108,9 +108,9 @@
Putting all this together one can superimpose all of *mobile* onto *ref*::
>>> mobile.atoms.translate(-mobile.atoms.CA.center_of_mass())
>>> mobile.atoms.translate(-mobile.select_atoms('name CA').center_of_mass())
>>> mobile.atoms.rotate(R)
>>> mobile.atoms.translate(ref.atoms.CA.center_of_mass())
>>> mobile.atoms.translate(ref.select_atoms('name CA').center_of_mass())
>>> mobile.atoms.write("mobile_on_ref.pdb")
Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/encore/bootstrap.py
Expand Up @@ -152,6 +152,6 @@ def get_ensemble_bootstrap_samples(ensemble,
size=ensemble.trajectory.timeseries().shape[1])
ensembles.append(
mda.Universe(ensemble.filename,
ensemble.trajectory.timeseries(format='fac')[indices,:,:],
ensemble.trajectory.timeseries(order='fac')[indices,:,:],
format=mda.coordinates.memory.MemoryReader))
return ensembles
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/encore/clustering/cluster.py
Expand Up @@ -205,7 +205,7 @@ def cluster(ensembles,
args += [(d,) for d in distance_matrix]
else:
for merged_ensemble in merged_ensembles:
coordinates = merged_ensemble.trajectory.timeseries(format="fac")
coordinates = merged_ensemble.trajectory.timeseries(order="fac")

# Flatten coordinate matrix into n_frame x n_coordinates
coordinates = np.reshape(coordinates,
Expand Down
10 changes: 5 additions & 5 deletions package/MDAnalysis/analysis/encore/confdistmatrix.py
Expand Up @@ -97,7 +97,7 @@ def conformational_distance_matrix(ensemble,

# framesn: number of frames
framesn = len(ensemble.trajectory.timeseries(
ensemble.select_atoms(selection), format='fac'))
ensemble.select_atoms(selection), order='fac'))

# Prepare metadata recarray
if metadata:
Expand All @@ -122,7 +122,7 @@ def conformational_distance_matrix(ensemble,

rmsd_coordinates = ensemble.trajectory.timeseries(
ensemble.select_atoms(selection),
format='fac')
order='fac')

if pairwise_align:
if superimposition_selection:
Expand All @@ -132,7 +132,7 @@ def conformational_distance_matrix(ensemble,

fitting_coordinates = ensemble.trajectory.timeseries(
ensemble.select_atoms(subset_selection),
format='fac')
order='fac')
else:
fitting_coordinates = None

Expand Down Expand Up @@ -313,7 +313,7 @@ def get_distance_matrix(ensemble,
TriangularMatrix(
size=ensemble.trajectory.timeseries(
ensemble.select_atoms(selection),
format='fac').shape[0],
order='fac').shape[0],
loadfile=load_matrix)
logging.info(" Done!")
for key in confdistmatrix.metadata.dtype.names:
Expand All @@ -324,7 +324,7 @@ def get_distance_matrix(ensemble,
if not confdistmatrix.size == \
ensemble.trajectory.timeseries(
ensemble.select_atoms(selection),
format='fac').shape[0]:
order='fac').shape[0]:
logging.error(
"ERROR: The size of the loaded matrix and of the ensemble"
" do not match")
Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/encore/covariance.py
Expand Up @@ -205,7 +205,7 @@ def covariance_matrix(ensemble,
# Extract coordinates from ensemble
coordinates = ensemble.trajectory.timeseries(
ensemble.select_atoms(selection),
format='fac')
order='fac')

# Flatten coordinate matrix into n_frame x n_coordinates
coordinates = np.reshape(coordinates, (coordinates.shape[0], -1))
Expand Down
Expand Up @@ -203,7 +203,7 @@ def reduce_dimensionality(ensembles,
args += [(d,) for d in distance_matrix]
else:
for merged_ensemble in merged_ensembles:
coordinates = merged_ensemble.trajectory.timeseries(format="fac")
coordinates = merged_ensemble.trajectory.timeseries(order="fac")

# Flatten coordinate matrix into n_frame x n_coordinates
coordinates = np.reshape(coordinates,
Expand Down
12 changes: 6 additions & 6 deletions package/MDAnalysis/analysis/encore/similarity.py
Expand Up @@ -335,9 +335,9 @@ def clustering_ensemble_similarity(cc, ens1, ens1_id, ens2, ens2_id,
the clustering ensemble similarity method
"""
ens1_coordinates = ens1.trajectory.timeseries(ens1.select_atoms(selection),
format='fac')
order='fac')
ens2_coordinates = ens2.trajectory.timeseries(ens2.select_atoms(selection),
format='fac')
order='fac')
tmpA = np.array([np.where(c.metadata['ensemble_membership'] == ens1_id)[
0].shape[0] / float(ens1_coordinates.shape[0]) for
c in cc])
Expand Down Expand Up @@ -693,7 +693,7 @@ def prepare_ensembles_for_convergence_increasing_window(ensemble,
"""

ens_size = ensemble.trajectory.timeseries(ensemble.select_atoms(selection),
format='fac').shape[0]
order='fac').shape[0]

rest_slices = ens_size // window_size
residuals = ens_size % window_size
Expand All @@ -708,7 +708,7 @@ def prepare_ensembles_for_convergence_increasing_window(ensemble,
for s,sl in enumerate(slices_n[:-1]):
tmp_ensembles.append(mda.Universe(
ensemble.filename,
ensemble.trajectory.timeseries(format='fac')
ensemble.trajectory.timeseries(order='fac')
[slices_n[s]:slices_n[s + 1], :, :],
format=MemoryReader))

Expand Down Expand Up @@ -889,7 +889,7 @@ def hes(ensembles,
xs.append(np.average(
ensembles_list[i][t].trajectory.timeseries(
e_orig.select_atoms(selection),
format=('fac')),
order=('fac')),
axis=0).flatten())
sigmas.append(covariance_matrix(ensembles_list[i][t],
weights=weights[i],
Expand All @@ -916,7 +916,7 @@ def hes(ensembles,
for e, w in zip(ensembles, weights):
# Extract coordinates from each ensemble
coordinates_system = e.trajectory.timeseries(e.select_atoms(selection),
format='fac')
order='fac')

# Average coordinates in each system
xs.append(np.average(coordinates_system, axis=0).flatten())
Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/encore/utils.py
Expand Up @@ -403,6 +403,6 @@ def merge_universes(universes):

return mda.Universe(
universes[0].filename,
np.concatenate(tuple([e.trajectory.timeseries(format='fac') for e in universes]),
np.concatenate(tuple([e.trajectory.timeseries(order='fac') for e in universes]),
axis=0),
format=MemoryReader)
1 change: 0 additions & 1 deletion package/MDAnalysis/analysis/leaflet.py
Expand Up @@ -78,7 +78,6 @@

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


class LeafletFinder(object):
Expand Down

0 comments on commit b09278c

Please sign in to comment.