From e95294506fecb0f6a7eb910882f82bece08b4827 Mon Sep 17 00:00:00 2001 From: Richard Gowers Date: Mon, 11 Apr 2016 17:29:47 +0100 Subject: [PATCH 01/12] tests for issue #820 --- .../MDAnalysisTests/coordinates/test_gro.py | 27 +++++++++++++++++-- testsuite/MDAnalysisTests/data/grovels.gro | 7 +++++ testsuite/MDAnalysisTests/datafiles.py | 2 ++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 testsuite/MDAnalysisTests/data/grovels.gro diff --git a/testsuite/MDAnalysisTests/coordinates/test_gro.py b/testsuite/MDAnalysisTests/coordinates/test_gro.py index b446f5a6a13..5d4f7f451ee 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_gro.py +++ b/testsuite/MDAnalysisTests/coordinates/test_gro.py @@ -5,11 +5,15 @@ from nose.plugins.attrib import attr from numpy.testing import (assert_equal, assert_almost_equal, dec, - assert_array_almost_equal, assert_raises) + assert_array_almost_equal, assert_raises, + assert_) from unittest import TestCase import tempdir -from MDAnalysisTests.datafiles import (GRO, GRO_velocity, GRO_large) +from MDAnalysisTests.datafiles import ( + GRO, GRO_velocity, GRO_large, + GRO_incomplete_vels, +) from MDAnalysisTests.coordinates.reference import RefAdK from MDAnalysisTests.coordinates.base import BaseTimestepTest @@ -159,6 +163,25 @@ def test_volume(self): err_msg="wrong volume for unitcell (rhombic dodecahedron)") +class TestGROIncompleteVels(object): + def setUp(self): + self.u = mda.Universe(GRO_incomplete_vels) + + def tearDown(self): + del self.u + + def test_load(self): + assert_(len(self.u.atoms) == 4) + + def test_velocities(self): + assert_array_almost_equal(self.u.atoms[0].velocity, + np.array([ 79.56, 124.08, 49.49]), + decimal=3) + assert_array_almost_equal(self.u.atoms[2].velocity, + np.array([0.0, 0.0, 0.0]), + decimal=3) + + class TestGROWriter(TestCase, tempdir.TempDir): def setUp(self): self.universe = mda.Universe(GRO) diff --git a/testsuite/MDAnalysisTests/data/grovels.gro b/testsuite/MDAnalysisTests/data/grovels.gro new file mode 100644 index 00000000000..f2155f9076d --- /dev/null +++ b/testsuite/MDAnalysisTests/data/grovels.gro @@ -0,0 +1,7 @@ +Incomplete velocities +4 + 1248DOPC NC3 1 7.956 12.408 4.949 7.956 12.408 4.949 + 1248DOPC PO4 2 7.736 12.290 4.671 7.956 12.408 4.949 + 1248DOPC GL1 3 7.760 12.150 4.329 + 1248DOPC GL2 4 7.896 11.896 4.235 7.956 12.408 4.949 + 22.28307 22.28307 23.34569 \ No newline at end of file diff --git a/testsuite/MDAnalysisTests/datafiles.py b/testsuite/MDAnalysisTests/datafiles.py index fcd4fc71914..ed292f85e07 100644 --- a/testsuite/MDAnalysisTests/datafiles.py +++ b/testsuite/MDAnalysisTests/datafiles.py @@ -49,6 +49,7 @@ "NUCL", # nucleic acid (PDB) "INC_PDB", # incomplete PDB file (Issue #396) "PDB", "GRO", "XTC", "TRR", "TPR", "GRO_velocity", # Gromacs (AdK) + "GRO_incomplete_vels", "GRO_large", #atom number truncation at > 100,000 particles, Issue 550 "PDB_xvf", "TPR_xvf", "TRR_xvf", # Gromacs coords/veloc/forces (cobrotoxin, OPLS-AA, Gromacs 4.5.5 tpr) "PDB_xlserial", @@ -155,6 +156,7 @@ GRO = resource_filename(__name__, 'data/adk_oplsaa.gro') GRO_velocity = resource_filename(__name__, 'data/sample_velocity_file.gro') +GRO_incomplete_vels = resource_filename(__name__, 'data/grovels.gro') GRO_large = resource_filename(__name__, 'data/bigbox.gro.bz2') PDB = resource_filename(__name__, 'data/adk_oplsaa.pdb') XTC = resource_filename(__name__, 'data/adk_oplsaa.xtc') From cf1e6b6271cc2004d847fd6d62a296a5bcad175f Mon Sep 17 00:00:00 2001 From: Oliver Beckstein Date: Mon, 11 Apr 2016 18:10:53 -0700 Subject: [PATCH 02/12] fix for simple rms.rmsd() (Issue #822) --- package/MDAnalysis/analysis/rms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/analysis/rms.py b/package/MDAnalysis/analysis/rms.py index 00a33d40105..f59b474ef48 100644 --- a/package/MDAnalysis/analysis/rms.py +++ b/package/MDAnalysis/analysis/rms.py @@ -204,7 +204,7 @@ def rmsd(a, b, weights=None, center=False, superposition=False): return qcp.CalcRMSDRotationalMatrix(a.T, b.T, N, None, relative_weights) else: - return np.sqrt(np.sum((a - b) ** 2) / a.size) + return np.sqrt(np.sum((a - b) ** 2) / N) def _process_selection(select): From 06b275b23fa12096e8c95eebeb045ff9d6d5dc81 Mon Sep 17 00:00:00 2001 From: Richard Gowers Date: Mon, 11 Apr 2016 17:45:41 +0100 Subject: [PATCH 03/12] Fixes Issue #820 Added warning to incomplete velocity read --- package/CHANGELOG | 1 + package/MDAnalysis/coordinates/GRO.py | 25 +++++++++++++------ .../MDAnalysisTests/coordinates/test_gro.py | 2 +- testsuite/MDAnalysisTests/data/grovels.gro | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 519419a9e71..78193eec48f 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -42,6 +42,7 @@ Fixes * HEADER and TITLE now appear just once in the PDB. (Issue #741) (PR #761) * MOL2 files without substructure section can now be read (Issue #816) * MOL2 files can be written without substructure section (Issue #816) + * GRO files with an incomplete set of velocities can now be read (Issue #820) Changes diff --git a/package/MDAnalysis/coordinates/GRO.py b/package/MDAnalysis/coordinates/GRO.py index 4ba180fd3bd..8916e0b6961 100644 --- a/package/MDAnalysis/coordinates/GRO.py +++ b/package/MDAnalysis/coordinates/GRO.py @@ -130,12 +130,15 @@ def _read_first_frame(self): # (dependent upon the GRO file precision) first_atomline = grofile.readline() cs = first_atomline[25:].find('.') + 1 - has_velocities = first_atomline[20:].count('.') > 3 + + # Always try, and maybe add them later + velocities = np.zeros((n_atoms, 3), dtype=np.float32) self.ts = ts = self._Timestep(n_atoms, - velocities=has_velocities, **self._ts_kwargs) + missed_vel = False + grofile.seek(0) for pos, line in enumerate(grofile, start=-2): # 2 header lines, 1 box line at end @@ -144,13 +147,19 @@ def _read_first_frame(self): continue if pos < 0: continue - for i in range(3): - ts._pos[pos, i] = float(line[20 + cs*i: 20 + cs*(i+1)]) - if not has_velocities: - continue - for i, j in enumerate(range(3, 6)): - ts._velocities[pos, i] = float(line[20+cs*j:20+cs*(j+1)]) + ts._pos[pos] = [line[20 + cs*i:20 + cs*(i+1)] for i in range(3)] + try: + velocities[pos] = [line[20 + cs*i:20 + cs*(i+1)] for i in range(3, 6)] + except ValueError: + # Remember that we got this error + missed_vel = True + + if np.any(velocities): + ts.velocities = velocities + if missed_vel: + warnings.warn("Not all velocities were present. " + "Unset velocities set to zero.") self.ts.frame = 0 # 0-based frame number diff --git a/testsuite/MDAnalysisTests/coordinates/test_gro.py b/testsuite/MDAnalysisTests/coordinates/test_gro.py index 5d4f7f451ee..cb100fb5cc9 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_gro.py +++ b/testsuite/MDAnalysisTests/coordinates/test_gro.py @@ -171,7 +171,7 @@ def tearDown(self): del self.u def test_load(self): - assert_(len(self.u.atoms) == 4) + assert_equal(len(self.u.atoms), 4) def test_velocities(self): assert_array_almost_equal(self.u.atoms[0].velocity, diff --git a/testsuite/MDAnalysisTests/data/grovels.gro b/testsuite/MDAnalysisTests/data/grovels.gro index f2155f9076d..ff303578e25 100644 --- a/testsuite/MDAnalysisTests/data/grovels.gro +++ b/testsuite/MDAnalysisTests/data/grovels.gro @@ -4,4 +4,4 @@ Incomplete velocities 1248DOPC PO4 2 7.736 12.290 4.671 7.956 12.408 4.949 1248DOPC GL1 3 7.760 12.150 4.329 1248DOPC GL2 4 7.896 11.896 4.235 7.956 12.408 4.949 - 22.28307 22.28307 23.34569 \ No newline at end of file + 22.28307 22.28307 23.34569 From 868fa851407e9eb91f0bb5e51449c951f4d5f4a3 Mon Sep 17 00:00:00 2001 From: Max Linke Date: Tue, 12 Apr 2016 14:03:15 +0200 Subject: [PATCH 04/12] fix rms tests --- .../MDAnalysisTests/analysis/test_rms.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_rms.py b/testsuite/MDAnalysisTests/analysis/test_rms.py index 4fa05ad9813..a9047b8093d 100644 --- a/testsuite/MDAnalysisTests/analysis/test_rms.py +++ b/testsuite/MDAnalysisTests/analysis/test_rms.py @@ -32,25 +32,24 @@ class TestRMSD(object): def __init__(self): shape = (5, 3) - self.a = np.arange(np.prod(shape)).reshape(shape) - self.b = np.arange(np.prod(shape)).reshape(shape) + 1 + # vectors with length one + ones = np.ones(shape) / np.sqrt(3) + self.a = ones * np.arange(1, 6)[:, np.newaxis] + self.b = self.a + ones def test_no_center(self): rmsd = MDAnalysis.analysis.rms.rmsd(self.a, self.b, center=False) - assert_equal(rmsd, 1.0) + assert_almost_equal(rmsd, 1.0) def test_center(self): rmsd = MDAnalysis.analysis.rms.rmsd(self.a, self.b, center=True) - assert_equal(rmsd, 0.0) + assert_almost_equal(rmsd, 0.0) - @staticmethod - def test_list(): - a = [[0, 1, 2], - [3, 4, 5]] - b = [[1, 2, 3], - [4, 5, 6]] - rmsd = MDAnalysis.analysis.rms.rmsd(a, b, center=False) - assert_equal(rmsd, 1.0) + def test_list(self): + rmsd = MDAnalysis.analysis.rms.rmsd(self.a.tolist(), + self.b.tolist(), + center=False) + assert_almost_equal(rmsd, 1.0) @staticmethod def test_superposition(): From 928e88545f9c3f3595cbbeb8389e33030f5cd649 Mon Sep 17 00:00:00 2001 From: Max Linke Date: Tue, 12 Apr 2016 14:19:54 +0200 Subject: [PATCH 05/12] Add more rmsd test I know compare also the results when the superposition theobald algorithm is used. --- .../MDAnalysisTests/analysis/test_rms.py | 59 ++++++++++++++----- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_rms.py b/testsuite/MDAnalysisTests/analysis/test_rms.py index a9047b8093d..89b0985258c 100644 --- a/testsuite/MDAnalysisTests/analysis/test_rms.py +++ b/testsuite/MDAnalysisTests/analysis/test_rms.py @@ -18,9 +18,10 @@ from six.moves import range import MDAnalysis -import MDAnalysis.analysis.rms +import MDAnalysis as mda +from MDAnalysis.analysis import rms, align -from numpy.testing import TestCase, assert_almost_equal, assert_equal, raises +from numpy.testing import TestCase, assert_almost_equal, raises, assert_ import numpy as np import os @@ -37,28 +38,39 @@ def __init__(self): self.a = ones * np.arange(1, 6)[:, np.newaxis] self.b = self.a + ones + self.u = mda.Universe(PSF, DCD) + self.u2 = mda.Universe(PSF, DCD) + + self.p_first = self.u.select_atoms('protein') + self.p_last = self.u2.select_atoms('protein') + + def setUp(self): + self.u.trajectory[2] + self.u2.trajectory[-2] + # reset coordinates + self.u.trajectory[0] + self.u2.trajectory[-1] + def test_no_center(self): - rmsd = MDAnalysis.analysis.rms.rmsd(self.a, self.b, center=False) + rmsd = rms.rmsd(self.a, self.b, center=False) assert_almost_equal(rmsd, 1.0) def test_center(self): - rmsd = MDAnalysis.analysis.rms.rmsd(self.a, self.b, center=True) + rmsd = rms.rmsd(self.a, self.b, center=True) assert_almost_equal(rmsd, 0.0) def test_list(self): - rmsd = MDAnalysis.analysis.rms.rmsd(self.a.tolist(), - self.b.tolist(), - center=False) + rmsd = rms.rmsd(self.a.tolist(), + self.b.tolist(), + center=False) assert_almost_equal(rmsd, 1.0) - @staticmethod - def test_superposition(): - u = MDAnalysis.Universe(PSF, DCD) - bb = u.atoms.select_atoms('backbone') + def test_superposition(self): + bb = self.u.atoms.select_atoms('backbone') a = bb.positions.copy() - u.trajectory[-1] + self.u.trajectory[-1] b = bb.positions.copy() - rmsd = MDAnalysis.analysis.rms.rmsd(a, b, superposition=True) + rmsd = rms.rmsd(a, b, superposition=True) assert_almost_equal(rmsd, 6.820321761927005) @staticmethod @@ -66,12 +78,29 @@ def test_superposition(): def test_unequal_shape(): a = np.ones((4, 3)) b = np.ones((5, 3)) - MDAnalysis.analysis.rms.rmsd(a, b) + rms.rmsd(a, b) @raises(ValueError) def test_wrong_weights(self): w = np.ones(2) - MDAnalysis.analysis.rms.rmsd(self.a, self.b, w) + rms.rmsd(self.a, self.b, w) + + def test_with_superposition_smaller(self): + A = self.p_first.positions + B = self.p_last.positions + rmsd = rms.rmsd(A, B) + rmsd_superposition = rms.rmsd(A, B, center=True, superposition=True) + print(rmsd, rmsd_superposition) + # by design the super positioned rmsd is smaller + assert_(rmsd > rmsd_superposition) + + def test_with_superposition_equal(self): + align.alignto(self.p_first, self.p_last) + A = self.p_first.positions + B = self.p_last.positions + rmsd = rms.rmsd(A, B) + rmsd_superposition = rms.rmsd(A, B, center=True, superposition=True) + assert_almost_equal(rmsd, rmsd_superposition) class TestRMSF(TestCase): From d0723776953feedb9a784d75f63e8598cf37ba91 Mon Sep 17 00:00:00 2001 From: Max Linke Date: Tue, 12 Apr 2016 15:01:27 +0200 Subject: [PATCH 06/12] update changelog --- package/CHANGELOG | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 519419a9e71..172a3b752d5 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -28,7 +28,7 @@ Metadata API Changes * rmsd doesn't superimpose by default anymore. The superposition - is controlled by the 'superposition' keyword now. (see issue #562) + is controlled by the 'superposition' keyword now. (see issue #562, #822) Enhancements @@ -36,8 +36,8 @@ Enhancements * Added read-only property giving Universe init kwargs (Issue #292) Fixes - - * change_release now finds number and dev (Issue #776) + + * change_release now finds number and dev (Issue #776) * test_shear_from_matrix doesn't fail for MKL builds anymore (Issue #757) * HEADER and TITLE now appear just once in the PDB. (Issue #741) (PR #761) * MOL2 files without substructure section can now be read (Issue #816) From 3f1f36d5c05f1026078a82a4a856462472c57500 Mon Sep 17 00:00:00 2001 From: Richard Gowers Date: Tue, 12 Apr 2016 10:18:16 +0100 Subject: [PATCH 07/12] Removed some use of deprecated methods --- package/MDAnalysis/__init__.py | 4 +- package/MDAnalysis/analysis/align.py | 14 +-- package/MDAnalysis/analysis/contacts.py | 4 +- package/MDAnalysis/analysis/density.py | 12 +-- package/MDAnalysis/analysis/gnm.py | 4 +- package/MDAnalysis/analysis/helanal.py | 4 +- package/MDAnalysis/analysis/nuclinfo.py | 10 +- package/MDAnalysis/analysis/rms.py | 4 +- package/MDAnalysis/coordinates/CRD.py | 2 +- package/MDAnalysis/coordinates/PDBQT.py | 2 +- package/MDAnalysis/coordinates/PQR.py | 2 +- package/MDAnalysis/core/AtomGroup.py | 99 ++++++++++++------- package/MDAnalysis/lib/NeighborSearch.py | 39 ++++---- .../visualization/streamlines_3D.py | 6 +- 14 files changed, 116 insertions(+), 90 deletions(-) diff --git a/package/MDAnalysis/__init__.py b/package/MDAnalysis/__init__.py index 648fd8b845d..ab5b551d6a8 100644 --- a/package/MDAnalysis/__init__.py +++ b/package/MDAnalysis/__init__.py @@ -84,14 +84,14 @@ Calculate the CA end-to-end distance (in angstroem):: >>> import numpy as np - >>> coord = ca.coordinates() + >>> coord = ca.positions >>> v = coord[-1] - coord[0] # last Ca minus first one >>> np.sqrt(np.dot(v, v,)) 10.938133 Define a function eedist(): >>> def eedist(atoms): - ... coord = atoms.coordinates() + ... coord = atoms.positions ... v = coord[-1] - coord[0] ... return sqrt(dot(v, v,)) ... diff --git a/package/MDAnalysis/analysis/align.py b/package/MDAnalysis/analysis/align.py index d548ef820fe..227752bd52a 100644 --- a/package/MDAnalysis/analysis/align.py +++ b/package/MDAnalysis/analysis/align.py @@ -217,8 +217,8 @@ def rotation_matrix(a, b, weights=None): :meth:`MDAnalysis.core.AtomGroup.AtomGroup.rotate` to generate a rotated selection, e.g. :: - >>> R = rotation_matrix(A.select_atoms('backbone').coordinates(), - >>> B.select_atoms('backbone').coordinates())[0] + >>> R = rotation_matrix(A.select_atoms('backbone').positions, + >>> B.select_atoms('backbone').positions)[0] >>> A.atoms.rotate(R) >>> A.atoms.write("rotated.pdb") @@ -356,8 +356,8 @@ def alignto(mobile, reference, select="all", mass_weighted=False, ref_com = ref_atoms.center_of_geometry() mobile_com = mobile_atoms.center_of_geometry() - ref_coordinates = ref_atoms.coordinates() - ref_com - mobile_coordinates = mobile_atoms.coordinates() - mobile_com + ref_coordinates = ref_atoms.positions - ref_com + mobile_coordinates = mobile_atoms.positions - mobile_com old_rmsd = rms.rmsd(mobile_coordinates, ref_coordinates) @@ -494,10 +494,10 @@ def rms_fit_trj(traj, reference, select='all', filename=None, rmsdfile=None, pre # reference centre of mass system ref_com = ref_atoms.center_of_mass() - ref_coordinates = ref_atoms.coordinates() - ref_com + ref_coordinates = ref_atoms.positions - ref_com # allocate the array for selection atom coords - traj_coordinates = traj_atoms.coordinates().copy() + traj_coordinates = traj_atoms.positions.copy() # RMSD timeseries nframes = len(frames) @@ -516,7 +516,7 @@ def rms_fit_trj(traj, reference, select='all', filename=None, rmsdfile=None, pre # shift coordinates for rotation fitting # selection is updated with the time frame x_com = traj_atoms.center_of_mass().astype(np.float32) - traj_coordinates[:] = traj_atoms.coordinates() - x_com + traj_coordinates[:] = traj_atoms.positions - x_com # Need to transpose coordinates such that the coordinate array is # 3xN instead of Nx3. Also qcp requires that the dtype be float64 diff --git a/package/MDAnalysis/analysis/contacts.py b/package/MDAnalysis/analysis/contacts.py index f768a67552e..9f1b4afb5ff 100644 --- a/package/MDAnalysis/analysis/contacts.py +++ b/package/MDAnalysis/analysis/contacts.py @@ -606,7 +606,7 @@ def __init__(self, *args, **kwargs): # compute reference contacts dref = MDAnalysis.lib.distances.distance_array( - self.references[0].coordinates(), self.references[1].coordinates()) + self.references[0].positions, self.references[1].positions) self.qref = self.qarray(dref) self.nref = self.qref.sum() @@ -682,7 +682,7 @@ def run(self, store=True, force=False, start=0, stop=None, step=1, **kwargs): for ts in self.universe.trajectory[start:stop:step]: frame = ts.frame # use pre-allocated distance array to save a little bit of time - MDAnalysis.lib.distances.distance_array(A.coordinates(), B.coordinates(), result=self.d) + MDAnalysis.lib.distances.distance_array(A.positions, B.positions, result=self.d) self.qarray(self.d, out=self.q) n1, q1 = self.qN(self.q, out=self._qtmp) self.qavg += self.q diff --git a/package/MDAnalysis/analysis/density.py b/package/MDAnalysis/analysis/density.py index a58edced141..a694ac977f9 100644 --- a/package/MDAnalysis/analysis/density.py +++ b/package/MDAnalysis/analysis/density.py @@ -466,7 +466,7 @@ def current_coordinates(): group = u.select_atoms(atomselection) def current_coordinates(): - return group.coordinates() + return group.positions coord = current_coordinates() logger.info("Selected {0:d} atoms out of {1:d} atoms ({2!s}) from {3:d} total.".format(coord.shape[0], len(u.select_atoms(atomselection)), atomselection, len(u.atoms))) @@ -596,14 +596,14 @@ def notwithin_coordinates(cutoff=cutoff): ns_w = NS.AtomNeighborSearch(solvent) # build kd-tree on solvent (N_w > N_protein) solvation_shell = ns_w.search_list(protein, cutoff) # solvent within CUTOFF of protein group = MDAnalysis.core.AtomGroup.AtomGroup(set_solvent - set(solvation_shell)) # bulk - return group.coordinates() + return group.positions else: def notwithin_coordinates(cutoff=cutoff): # acts as ' WITHIN OF ' # must update every time step ns_w = NS.AtomNeighborSearch(solvent) # build kd-tree on solvent (N_w > N_protein) group = ns_w.search_list(protein, cutoff) # solvent within CUTOFF of protein - return group.coordinates() + return group.positions else: # slower distance matrix based (calculate all with all distances first) dist = np.zeros((len(solvent), len(protein)), dtype=np.float64) @@ -616,8 +616,8 @@ def notwithin_coordinates(cutoff=cutoff): aggregatefunc = np.any def notwithin_coordinates(cutoff=cutoff): - s_coor = solvent.coordinates() - p_coor = protein.coordinates() + s_coor = solvent.positions + p_coor = protein.positions # Does water i satisfy d[i,j] > r for ALL j? d = MDAnalysis.analysis.distances.distance_array(s_coor, p_coor, box=box, result=dist) return s_coor[aggregatefunc(compare(d, cutoff), axis=1)] @@ -751,7 +751,7 @@ def __init__(self, pdb, delta=1.0, atomselection='resname HOH and name O', """ u = MDAnalysis.as_Universe(pdb) group = u.select_atoms(atomselection) - coord = group.coordinates() + coord = group.positions logger.info("Selected {0:d} atoms ({1!s}) out of {2:d} total.".format(coord.shape[0], atomselection, len(u.atoms))) smin = np.min(coord, axis=0) - padding smax = np.max(coord, axis=0) + padding diff --git a/package/MDAnalysis/analysis/gnm.py b/package/MDAnalysis/analysis/gnm.py index 5f4910b9480..100d516a218 100644 --- a/package/MDAnalysis/analysis/gnm.py +++ b/package/MDAnalysis/analysis/gnm.py @@ -210,7 +210,7 @@ def generate_kirchoff(self): the cutoff. Returns the resulting matrix ''' #ca = self.u.select_atoms(self.selection) - positions = self.ca.coordinates() + positions = self.ca.positions natoms = len(positions) @@ -320,7 +320,7 @@ def __init__(self, universe, selection='protein', cutoff=4.5, ReportVector=None, def generate_kirchoff(self): natoms = len(self.ca.atoms) nresidues = len(self.ca.residues) - positions = self.ca.coordinates() + positions = self.ca.positions [res_positions, grid, low_x, low_y, low_z] = generate_grid(positions, self.cutoff) residue_index_map = [resnum for [resnum, residue] in enumerate(self.ca.residues) for atom in residue] matrix = np.zeros((nresidues, nresidues), "float") diff --git a/package/MDAnalysis/analysis/helanal.py b/package/MDAnalysis/analysis/helanal.py index 8f0cb6b3987..a1e5dbe6c7f 100644 --- a/package/MDAnalysis/analysis/helanal.py +++ b/package/MDAnalysis/analysis/helanal.py @@ -290,7 +290,7 @@ def helanal_trajectory(universe, selection="name CA", start=None, end=None, begi if trajectory.time > finish: break - ca_positions = ca.coordinates() + ca_positions = ca.positions twist, bending_angles, height, rnou, origins, local_helix_axes, local_screw_angles = \ main_loop(ca_positions, ref_axis=ref_axis) @@ -515,7 +515,7 @@ def helanal_main(pdbfile, selection="name CA", start=None, end=None, ref_axis=No logger.info("Analysing %d/%d residues", ca.n_atoms, universe.atoms.n_residues) twist, bending_angles, height, rnou, origins, local_helix_axes, local_screw_angles = \ - main_loop(ca.coordinates(), ref_axis=ref_axis) + main_loop(ca.positions, ref_axis=ref_axis) #TESTED- origins are correct #print current_origin diff --git a/package/MDAnalysis/analysis/nuclinfo.py b/package/MDAnalysis/analysis/nuclinfo.py index 2d878226f73..24d00a3e74c 100644 --- a/package/MDAnalysis/analysis/nuclinfo.py +++ b/package/MDAnalysis/analysis/nuclinfo.py @@ -234,11 +234,11 @@ def phase_cp(universe, seg, i): atom4 = universe.select_atoms(" atom {0!s} {1!s} C3\' ".format(seg, i)) atom5 = universe.select_atoms(" atom {0!s} {1!s} C4\' ".format(seg, i)) - data1 = atom1.coordinates() - data2 = atom2.coordinates() - data3 = atom3.coordinates() - data4 = atom4.coordinates() - data5 = atom5.coordinates() + data1 = atom1.positions + data2 = atom2.positions + data3 = atom3.positions + data4 = atom4.positions + data5 = atom5.positions r0 = (data1 + data2 + data3 + data4 + data5) * (1.0 / 5.0) r1 = data1 - r0 diff --git a/package/MDAnalysis/analysis/rms.py b/package/MDAnalysis/analysis/rms.py index 00a33d40105..f47d29e3fd3 100644 --- a/package/MDAnalysis/analysis/rms.py +++ b/package/MDAnalysis/analysis/rms.py @@ -443,7 +443,7 @@ def run(self, start=None, stop=None, step=None, ref_coordinates_T_64 = ref_coordinates.T.astype(np.float64) # allocate the array for selection atom coords - traj_coordinates = traj_atoms.coordinates().copy() + traj_coordinates = traj_atoms.positions.copy() if self.groupselections_atoms: # Only carry out a rotation if we want to calculate secondary @@ -468,7 +468,7 @@ def run(self, start=None, stop=None, step=None, # shift coordinates for rotation fitting # selection is updated with the time frame x_com = traj_atoms.center_of_mass().astype(np.float32) - traj_coordinates[:] = traj_atoms.coordinates() - x_com + traj_coordinates[:] = traj_atoms.positions - x_com rmsd[k, :2] = ts.frame, trajectory.time diff --git a/package/MDAnalysis/coordinates/CRD.py b/package/MDAnalysis/coordinates/CRD.py index 78ad91443c6..e0a3228b375 100644 --- a/package/MDAnalysis/coordinates/CRD.py +++ b/package/MDAnalysis/coordinates/CRD.py @@ -145,7 +145,7 @@ def write(self, selection, frame=None): frame = 0 # should catch cases when we are analyzing a single PDB (?) atoms = selection.atoms # make sure to use atoms (Issue 46) - coor = atoms.coordinates() # can write from selection == Universe (Issue 49) + coor = atoms.positions # can write from selection == Universe (Issue 49) with util.openany(self.filename, 'w') as self.crd: self._TITLE("FRAME " + str(frame) + " FROM " + str(u.trajectory.filename)) self._TITLE("") diff --git a/package/MDAnalysis/coordinates/PDBQT.py b/package/MDAnalysis/coordinates/PDBQT.py index 7c9205528e7..965c9fed2dc 100644 --- a/package/MDAnalysis/coordinates/PDBQT.py +++ b/package/MDAnalysis/coordinates/PDBQT.py @@ -293,7 +293,7 @@ def write(self, selection, frame=None): self.TITLE("FRAME " + str(frame) + " FROM " + str(u.trajectory.filename)) self.CRYST1(self.convert_dimensions_to_unitcell(u.trajectory.ts)) atoms = selection.atoms # make sure to use atoms (Issue 46) - coor = atoms.coordinates() # can write from selection == Universe (Issue 49) + coor = atoms.positions # can write from selection == Universe (Issue 49) # check if any coordinates are illegal (coordinates are already in Angstroem per package default) if not self.has_valid_coordinates(self.pdb_coor_limits, coor): diff --git a/package/MDAnalysis/coordinates/PQR.py b/package/MDAnalysis/coordinates/PQR.py index 6dba0494f68..e7b286b6f3e 100644 --- a/package/MDAnalysis/coordinates/PQR.py +++ b/package/MDAnalysis/coordinates/PQR.py @@ -231,7 +231,7 @@ def write(self, selection, frame=None): frame = 0 # should catch cases when we are analyzing a single frame(?) atoms = selection.atoms # make sure to use atoms (Issue 46) - coordinates = atoms.coordinates() # can write from selection == Universe (Issue 49) + coordinates = atoms.positions # can write from selection == Universe (Issue 49) if self.convert_units: self.convert_pos_to_native(coordinates) # inplace because coordinates is already a copy diff --git a/package/MDAnalysis/core/AtomGroup.py b/package/MDAnalysis/core/AtomGroup.py index 5d92dca4077..48ba799c232 100644 --- a/package/MDAnalysis/core/AtomGroup.py +++ b/package/MDAnalysis/core/AtomGroup.py @@ -2420,7 +2420,7 @@ def bbox(self, **kwargs): if pbc: x = self.pack_into_box(inplace=False) else: - x = self.coordinates() + x = self.positions return np.array([x.min(axis=0), x.max(axis=0)]) def bsphere(self, **kwargs): @@ -2446,7 +2446,7 @@ def bsphere(self, **kwargs): x = self.pack_into_box(inplace=False) centroid = self.center_of_geometry(pbc=True) else: - x = self.coordinates() + x = self.positions centroid = self.center_of_geometry(pbc=False) R = np.sqrt(np.max(np.sum(np.square(x - centroid), axis=1))) return R, centroid @@ -2590,19 +2590,18 @@ def get_positions(self, ts=None, copy=False, dtype=np.float32): ts = self.universe.trajectory.ts return np.array(ts.positions[self.indices], copy=copy, dtype=dtype) - coordinates = get_positions - """Np array of the coordinates. - - .. SeeAlso:: :attr:`~AtomGroup.positions` and :meth:`~AtomGroup.get_positions` + @deprecate(message="{}; use `positions` property instead".format(_SIXTEEN_DEPRECATION)) + def coordinates(self): + """Np array of the coordinates. - .. deprecated:: 0.7.6 - In new scripts use :meth:`AtomGroup.get_positions` preferrably. - """ - # coordinates() should NOT be removed as it has been used in many scripts, - # MDAnalysis itself, and in the paper + .. SeeAlso:: :attr:`~AtomGroup.positions` and :meth:`~AtomGroup.get_positions` - coordinates = deprecate(coordinates, - message="{}; use `positions` property instead".format(_SIXTEEN_DEPRECATION)) + .. deprecated:: 0.7.6 + In new scripts use :meth:`AtomGroup.get_positions` preferrably. + """ + return self.positions + # coordinates() should NOT be removed as it has been used in many scripts, + # MDAnalysis itself, and in the paper @deprecate(message="{}; use `positions` property instead".format(_SIXTEEN_DEPRECATION)) def set_positions(self, coords, ts=None): @@ -2634,19 +2633,22 @@ def set_positions(self, coords, ts=None): ts = self.universe.trajectory.ts ts.positions[self.indices, :] = coords - positions = property(get_positions, set_positions, - doc=""" - Coordinates of the atoms in the AtomGroup. + @property + def positions(self): + """Coordinates of the atoms in the AtomGroup. - The positions can be changed by assigning an array of the appropriate - shape, i.e. either Nx3 to assign individual coordinates or 3, to assign - the *same* coordinate to all atoms (e.g. ``ag.positions = array([0,0,0])`` - will move all particles to the origin). + The positions can be changed by assigning an array of the appropriate + shape, i.e. either Nx3 to assign individual coordinates or 3, to assign + the *same* coordinate to all atoms (e.g. ``ag.positions = array([0,0,0])`` + will move all particles to the origin). - For more control use the :meth:`~AtomGroup.get_positions` and - :meth:`~AtomGroup.set_positions` methods. + .. versionadded:: 0.7.6 + """ + return self.universe.trajectory.ts.positions[self.indices, :] - .. versionadded:: 0.7.6""") + @positions.setter + def positions(self, coords): + self.universe.trajectory.ts.positions[self.indices, :] = coords @deprecate(message="{}; use `velocities` property instead".format(_SIXTEEN_DEPRECATION)) def get_velocities(self, ts=None, copy=False, dtype=np.float32): @@ -2688,8 +2690,9 @@ def set_velocities(self, v, ts=None): except AttributeError: raise NoDataError("Timestep does not contain velocities") - velocities = property(get_velocities, set_velocities, doc="""\ - numpy array of the velocities of the atoms in the group. + @property + def velocities(self): + """numpy array of the velocities of the atoms in the group. If the trajectory does not contain velocity information then a :exc:`~MDAnalysis.NoDataError` is raised. @@ -2700,7 +2703,18 @@ def set_velocities(self, v, ts=None): and :meth:`set_velocities`. .. versionchanged:: 0.8 Became an attribute. - """) + """ + try: + return self.universe.trajectory.ts.velocities[self.indices] + except (AttributeError, NoDataError): + raise NoDataError("Timestep does not contain velocities") + + @velocities.setter + def velocities(self, new): + try: + self.universe.trajectory.ts.velocities[self.indices] = new + except AttributeError: + raise NoDataError("Timestep does not contain velocities") @deprecate(message="{}; use `forces` property instead".format(_SIXTEEN_DEPRECATION)) def get_forces(self, ts=None, copy=False, dtype=np.float32): @@ -2774,19 +2788,30 @@ def set_forces(self, forces, ts=None): except AttributeError: raise NoDataError("Timestep does not contain forces") - forces = property(get_forces, set_forces, - doc=""" - Forces on the atoms in the AtomGroup. + @property + def forces(self): + """Forces on the atoms in the AtomGroup. + + The forces can be changed by assigning an array of the appropriate + shape, i.e. either Nx3 to assign individual force or 3, to assign + the *same* force to all atoms (e.g. ``ag.forces = array([0,0,0])`` + will set all forces to (0.,0.,0.)). - The forces can be changed by assigning an array of the appropriate - shape, i.e. either Nx3 to assign individual force or 3, to assign - the *same* force to all atoms (e.g. ``ag.forces = array([0,0,0])`` - will set all forces to (0.,0.,0.)). + For more control use the :meth:`~AtomGroup.get_forces` and + :meth:`~AtomGroup.set_forces` methods. - For more control use the :meth:`~AtomGroup.get_forces` and - :meth:`~AtomGroup.set_forces` methods. + .. versionadded:: 0.7.7""" + try: + return self.universe.trajectory.ts.forces[self.indices] + except (AttributeError, NoDataError): + raise NoDataError("Timestep does not contain forces") - .. versionadded:: 0.7.7""") + @forces.setter + def forces(self, new): + try: + self.universe.trajectory.ts.forces[self.indices] = new + except (AttributeError, NoDataError): + raise NoDataError("Timestep does not contain forces") def transform(self, M): r"""Apply homogenous transformation matrix *M* to the coordinates. @@ -5082,7 +5107,7 @@ def Merge(*args): if len(a) == 0: raise ValueError("cannot merge empty AtomGroup") - coords = np.vstack([a.coordinates() for a in args]) + coords = np.vstack([a.positions for a in args]) trajectory = MDAnalysis.coordinates.base.Reader(None) ts = MDAnalysis.coordinates.base.Timestep.from_coordinates(coords) setattr(trajectory, "ts", ts) diff --git a/package/MDAnalysis/lib/NeighborSearch.py b/package/MDAnalysis/lib/NeighborSearch.py index 2a90c65ef5e..5e3fdf82fab 100644 --- a/package/MDAnalysis/lib/NeighborSearch.py +++ b/package/MDAnalysis/lib/NeighborSearch.py @@ -38,33 +38,33 @@ class AtomNeighborSearch(object): def __init__(self, atom_group, bucket_size=10): """ - :Arguments: - *atom_list* - list of atoms (:class: `~MDAnalysis.core.AtomGroup.AtomGroup`) - *bucket_size* + + Parameters + ---------- + atom_list : AtomGroup + list of atoms + bucket_size : int Number of entries in leafs of the KDTree. If you suffer poor performance you can play around with this number. Increasing the `bucket_size` will speed up the construction of the KDTree but slow down the search. """ self.atom_group = atom_group - if not hasattr(atom_group, 'coordinates'): - raise TypeError('atom_group must have a coordinates() method' - '(eq a AtomGroup from a selection)') self.kdtree = KDTree(dim=3, bucket_size=bucket_size) - self.kdtree.set_coords(atom_group.coordinates()) + self.kdtree.set_coords(atom_group.positions) def search(self, atoms, radius, level='A'): """ Return all atoms/residues/segments that are within *radius* of the atoms in *atoms*. - :Arguments: - *atoms* - list of atoms (:class: `~MDAnalysis.core.AtomGroup.AtomGroup`) - *radius* - float. Radius for search in Angstrom. - *level* (optional) + Parameters + ---------- + atoms : AtomGroup + list of atoms + radius : float + Radius for search in Angstrom. + level : str char (A, R, S). Return atoms(A), residues(R) or segments(S) within *radius* of *atoms*. """ @@ -76,13 +76,14 @@ def search(self, atoms, radius, level='A'): return self._index2level(unique_idx, level) def _index2level(self, indices, level): - """ Convert list of atom_indices in a AtomGroup to either the - Atoms or segments/residues containing these atoms. + """Convert list of atom_indices in a AtomGroup to either the + Atoms or segments/residues containing these atoms. - :Arguments: - *indices* + Parameters + ---------- + indices list of atom indices - *level* + level : str char (A, R, S). Return atoms(A), residues(R) or segments(S) within *radius* of *atoms*. """ diff --git a/package/MDAnalysis/visualization/streamlines_3D.py b/package/MDAnalysis/visualization/streamlines_3D.py index dc633339abb..296349fd410 100644 --- a/package/MDAnalysis/visualization/streamlines_3D.py +++ b/package/MDAnalysis/visualization/streamlines_3D.py @@ -42,7 +42,7 @@ def determine_container_limits(coordinate_file_path, trajectory_file_path, buffe container for the system and return these limits.''' universe_object = MDAnalysis.Universe(coordinate_file_path, trajectory_file_path) all_atom_selection = universe_object.select_atoms('all') # select all particles - all_atom_coordinate_array = all_atom_selection.coordinates() + all_atom_coordinate_array = all_atom_selection.positions x_min, x_max, y_min, y_max, z_min, z_max = [ all_atom_coordinate_array[..., 0].min(), all_atom_coordinate_array[..., 0].max(), all_atom_coordinate_array[..., 1].min(), @@ -253,9 +253,9 @@ def produce_coordinate_arrays_single_process(coordinate_file_path, trajectory_fi if ts.frame > end_frame: break # stop here if ts.frame == start_frame: - start_frame_relevant_particle_coordinate_array_xyz = relevant_particles.coordinates() + start_frame_relevant_particle_coordinate_array_xyz = relevant_particles.positions elif ts.frame == end_frame: - end_frame_relevant_particle_coordinate_array_xyz = relevant_particles.coordinates() + end_frame_relevant_particle_coordinate_array_xyz = relevant_particles.positions else: continue return (start_frame_relevant_particle_coordinate_array_xyz, end_frame_relevant_particle_coordinate_array_xyz) From d2aff335938eaaf5a2b11388201de68e222c1f00 Mon Sep 17 00:00:00 2001 From: kain88-de Date: Sun, 17 Apr 2016 23:01:59 +0200 Subject: [PATCH 08/12] fix pos warnings (#828) --- package/MDAnalysis/analysis/hbonds/hbond_analysis.py | 6 +++--- package/MDAnalysis/analysis/nuclinfo.py | 6 +++--- package/MDAnalysis/core/topologyobjects.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package/MDAnalysis/analysis/hbonds/hbond_analysis.py b/package/MDAnalysis/analysis/hbonds/hbond_analysis.py index 6b2b84a0d23..62fb62e041a 100644 --- a/package/MDAnalysis/analysis/hbonds/hbond_analysis.py +++ b/package/MDAnalysis/analysis/hbonds/hbond_analysis.py @@ -916,15 +916,15 @@ def _get_timestep(): def calc_angle(self, d, h, a): """Calculate the angle (in degrees) between two atoms with H at apex.""" - v1 = h.pos - d.pos - v2 = h.pos - a.pos + v1 = h.position - d.position + v2 = h.position - a.position if np.all(v1 == v2): return 0.0 return np.rad2deg(angle(v1, v2)) def calc_eucl_distance(self, a1, a2): """Calculate the Euclidean distance between two atoms. """ - return norm(a2.pos - a1.pos) + return norm(a2.position - a1.position) def generate_table(self): """Generate a normalised table of the results. diff --git a/package/MDAnalysis/analysis/nuclinfo.py b/package/MDAnalysis/analysis/nuclinfo.py index 2d878226f73..26ed2e3b68c 100644 --- a/package/MDAnalysis/analysis/nuclinfo.py +++ b/package/MDAnalysis/analysis/nuclinfo.py @@ -135,7 +135,7 @@ def wc_pair(universe, i, bp, seg1="SYSTEM", seg2="SYSTEM"): wc_dist = universe.select_atoms("(segid {0!s} and resid {1!s} and name {2!s}) " "or (segid {3!s} and resid {4!s} and name {5!s}) " .format(seg1, i, a1, seg2, bp, a2)) - wc = mdamath.norm(wc_dist[0].pos - wc_dist[1].pos) + wc = mdamath.norm(wc_dist[0].position - wc_dist[1].position) return wc @@ -168,7 +168,7 @@ def minor_pair(universe, i, bp, seg1="SYSTEM", seg2="SYSTEM"): c2o2_dist = universe.select_atoms("(segid {0!s} and resid {1!s} and name {2!s}) " "or (segid {3!s} and resid {4!s} and name {5!s})" .format(seg1, i, a1, seg2, bp, a2)) - c2o2 = mdamath.norm(c2o2_dist[0].pos - c2o2_dist[1].pos) + c2o2 = mdamath.norm(c2o2_dist[0].position - c2o2_dist[1].position) return c2o2 @@ -208,7 +208,7 @@ def major_pair(universe, i, bp, seg1="SYSTEM", seg2="SYSTEM"): no_dist = universe.select_atoms("(segid {0!s} and resid {1!s} and name {2!s}) " "or (segid {3!s} and resid {4!s} and name {5!s}) " .format(seg1, i, a1, seg2, bp, a2)) - major = mdamath.norm(no_dist[0].pos - no_dist[1].pos) + major = mdamath.norm(no_dist[0].position - no_dist[1].position) return major diff --git a/package/MDAnalysis/core/topologyobjects.py b/package/MDAnalysis/core/topologyobjects.py index 19b8b642e32..bedc73fcef7 100644 --- a/package/MDAnalysis/core/topologyobjects.py +++ b/package/MDAnalysis/core/topologyobjects.py @@ -1,5 +1,5 @@ # -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- -# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 # # MDAnalysis --- http://www.MDAnalysis.org # Copyright (c) 2006-2015 Naveen Michaud-Agrawal, Elizabeth J. Denning, Oliver Beckstein @@ -230,8 +230,8 @@ def angle(self): .. versionadded:: 0.9.0 """ - a = self[0].pos - self[1].pos - b = self[2].pos - self[1].pos + a = self[0].position - self[1].position + b = self[2].position - self[1].position return np.rad2deg( np.arccos(np.dot(a, b) / (norm(a) * norm(b)))) From 330db1cd7ce9776aa3adbd7d63b5f9245cc53b0f Mon Sep 17 00:00:00 2001 From: Richard Gowers Date: Sun, 17 Apr 2016 22:47:33 +0100 Subject: [PATCH 09/12] Removed use of Residue.name and Segment.id --- package/MDAnalysis/core/AtomGroup.py | 26 +++++++++---------- .../MDAnalysisTests/analysis/test_align.py | 8 +++--- .../coordinates/test_coordinates.py | 4 +-- .../MDAnalysisTests/coordinates/test_dcd.py | 20 +++++++------- .../MDAnalysisTests/coordinates/test_gro.py | 4 +-- .../MDAnalysisTests/coordinates/test_pdb.py | 6 ++--- .../MDAnalysisTests/coordinates/test_pqr.py | 8 +++--- .../MDAnalysisTests/coordinates/test_trj.py | 8 +++--- .../MDAnalysisTests/coordinates/test_trz.py | 4 +-- .../MDAnalysisTests/coordinates/test_xdr.py | 12 ++++----- testsuite/MDAnalysisTests/test_atomgroup.py | 20 +++++++------- .../MDAnalysisTests/test_atomselections.py | 2 +- testsuite/MDAnalysisTests/test_distances.py | 22 ++++++++-------- 13 files changed, 72 insertions(+), 72 deletions(-) diff --git a/package/MDAnalysis/core/AtomGroup.py b/package/MDAnalysis/core/AtomGroup.py index 48ba799c232..fc896113cf8 100644 --- a/package/MDAnalysis/core/AtomGroup.py +++ b/package/MDAnalysis/core/AtomGroup.py @@ -69,13 +69,13 @@ The same is mostly true for :class:`Residue` instances although they are derived from :class:`Atom` instances: all :class:`Atom` objects with the same :attr:`Atom.resid` are bundled into a single :class:`Residue` with -:class:`Residue.id` = *resid*. This means that just changing, say, the residue +:class:`Residue.resid` = *resid*. This means that just changing, say, the residue name with a command such as :: >>> r = u.select_atoms("resid 99").residues[0] >>> print(r) - >>> r.name = "UNK" + >>> r.resname = "UNK" >>> print(r) >>> rnew = u.select_atoms("resid 99").residues[0] @@ -1907,7 +1907,7 @@ def set_resids(self, resid): If *resid* is a sequence of the same length as the :class:`AtomGroup` then each :attr:`Atom.resid` is set to the corresponding value together - with the :attr:`Residue.id` of the residue the atom belongs to. If + with the :attr:`Residue.resid` of the residue the atom belongs to. If *value* is neither of length 1 (or a scalar) nor of the length of the :class:`AtomGroup` then a :exc:`ValueError` is raised. @@ -1987,7 +1987,7 @@ def set_resnames(self, resname): If *resname* is a sequence of the same length as the :class:`AtomGroup` then each :attr:`Atom.resname` is set to the corresponding value together - with the :attr:`Residue.name` of the residue the atom belongs to. If + with the :attr:`Residue.resname` of the residue the atom belongs to. If *value* is neither of length 1 (or a scalar) nor of the length of the :class:`AtomGroup` then a :exc:`ValueError` is raised. @@ -2012,7 +2012,7 @@ def set_segids(self, segid): If *segid* is a sequence of the same length as the :class:`AtomGroup` then each :attr:`Atom.segid` is set to the corresponding value together - with the :attr:`Segment.id` of the residue the atom belongs to. If + with the :attr:`Segment.segid` of the residue the atom belongs to. If *value* is neither of length 1 (or a scalar) nor of the length of the :class:`AtomGroup` then a :exc:`ValueError` is raised. @@ -3524,9 +3524,9 @@ class Residue(AtomGroup): - ``r['name']`` or ``r[id]`` - returns the atom corresponding to that name :Data: - :attr:`Residue.name` + :attr:`Residue.resname` Three letter residue name. - :attr:`Residue.id` + :attr:`Residue.resid` Numeric (integer) resid, taken from the topology. :attr:`Residue.resnum` Numeric canonical residue id (e.g. as used in the PDB structure). @@ -3763,7 +3763,7 @@ def resnames(self): .. versionchanged:: 0.11.0 Now a property and returns array of length `len(self)` """ - return np.array([r.name for r in self.residues]) + return np.array([r.resname for r in self.residues]) @property @warn_residue_property @@ -3801,7 +3801,7 @@ def set_resids(self, resid): If *resid* is a sequence of the same length as the :class:`ResidueGroup` then each :attr:`Atom.resid` is set to the corresponding value together - with the :attr:`Residue.id` of the residue the atom belongs to. If + with the :attr:`Residue.resid` of the residue the atom belongs to. If *value* is neither of length 1 (or a scalar) nor of the length of the :class:`AtomGroup` then a :exc:`ValueError` is raised. @@ -3870,7 +3870,7 @@ def set_resnames(self, resname): If *resname* is a sequence of the same length as the :class:`ResidueGroup` then each :attr:`Atom.resname` is set to the corresponding value together - with the :attr:`Residue.name` of the residue the atom belongs to. If + with the :attr:`Residue.resname` of the residue the atom belongs to. If *value* is neither of length 1 (or a scalar) nor of the length of the :class:`AtomGroup` then a :exc:`ValueError` is raised. @@ -3975,7 +3975,7 @@ def __getattr__(self, attr): # There can be multiple residues with the same name r = [] for res in self.residues: - if (res.name == attr): + if (res.resname == attr): r.append(res) if (len(r) == 0): return super(Segment, self).__getattr__(attr) @@ -4060,7 +4060,7 @@ def set_segids(self, segid): If *segid* is a sequence of the same length as the :class:`SegmentGroup` then each :attr:`Atom.segid` is set to the corresponding value together - with the :attr:`Segment.id` of the segment the atom belongs to. If + with the :attr:`Segment.segid` of the segment the atom belongs to. If *value* is neither of length 1 (or a scalar) nor of the length of the :class:`AtomGroup` then a :exc:`ValueError` is raised. @@ -4088,7 +4088,7 @@ def set_segids(self, segid): def __getattr__(self, attr): if attr.startswith('s') and attr[1].isdigit(): attr = attr[1:] # sNxxx only used for python, the name is stored without s-prefix - seglist = [segment for segment in self.segments if segment.name == attr] + seglist = [segment for segment in self.segments if segment.segid == attr] if len(seglist) == 0: return super(SegmentGroup, self).__getattr__(attr) if len(seglist) > 1: diff --git a/testsuite/MDAnalysisTests/analysis/test_align.py b/testsuite/MDAnalysisTests/analysis/test_align.py index 48ffae3f30d..f2ab293e20b 100644 --- a/testsuite/MDAnalysisTests/analysis/test_align.py +++ b/testsuite/MDAnalysisTests/analysis/test_align.py @@ -87,9 +87,9 @@ def tearDown(self): def test_rmsd(self): self.universe.trajectory[0] # ensure first frame bb = self.universe.select_atoms('backbone') - first_frame = bb.coordinates(copy=True) + first_frame = bb.positions self.universe.trajectory[-1] - last_frame = bb.coordinates() + last_frame = bb.positions assert_almost_equal(rms.rmsd(first_frame, first_frame), 0.0, 5, err_msg="error: rmsd(X,X) should be 0") # rmsd(A,B) = rmsd(B,A) should be exact but spurious failures in the @@ -121,8 +121,8 @@ def test_rms_fit_trj(self): def _assert_rmsd(self, fitted, frame, desired): fitted.trajectory[frame] - rmsd = rms.rmsd(self.reference.atoms.coordinates(), - fitted.atoms.coordinates(), superposition=True) + rmsd = rms.rmsd(self.reference.atoms.positions, + fitted.atoms.positions, superposition=True) assert_almost_equal(rmsd, desired, decimal=5, err_msg="frame {0:d} of fit does not have " "expected RMSD".format(frame)) diff --git a/testsuite/MDAnalysisTests/coordinates/test_coordinates.py b/testsuite/MDAnalysisTests/coordinates/test_coordinates.py index 6daa6d5755f..059e55949e2 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_coordinates.py +++ b/testsuite/MDAnalysisTests/coordinates/test_coordinates.py @@ -123,12 +123,12 @@ def test_frame_numbering(self): def test_frame(self): self.trajectory[0] - coord0 = self.universe.atoms.coordinates().copy() + coord0 = self.universe.atoms.positions.copy() # forward to frame where we repeat original dcd again: # dcd:0..97 crd:98 dcd:99..196 self.trajectory[99] assert_array_equal( - self.universe.atoms.coordinates(), coord0, + self.universe.atoms.positions, coord0, "coordinates at frame 1 and 100 should be the same!") def test_time(self): diff --git a/testsuite/MDAnalysisTests/coordinates/test_dcd.py b/testsuite/MDAnalysisTests/coordinates/test_dcd.py index 7c08f4a7bae..5d681ca040b 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_dcd.py +++ b/testsuite/MDAnalysisTests/coordinates/test_dcd.py @@ -226,8 +226,8 @@ def test_single_frame(self): w = mda.Universe(PSF, self.outfile) assert_equal(w.trajectory.n_frames, 1, "single frame trajectory has wrong number of frames") - assert_almost_equal(w.atoms.coordinates(), - u.atoms.coordinates(), + assert_almost_equal(w.atoms.positions, + u.atoms.positions, 3, err_msg="coordinates do not match") @@ -242,8 +242,8 @@ def test_with_statement(self): assert_equal(w.trajectory.n_frames, 1, "with_statement: single frame trajectory has wrong " "number of frames") - assert_almost_equal(w.atoms.coordinates(), - u.atoms.coordinates(), + assert_almost_equal(w.atoms.positions, + u.atoms.positions, 3, err_msg="with_statement: coordinates do not match") @@ -287,8 +287,8 @@ def test_issue59(self): dcd.trajectory.rewind() assert_array_almost_equal( - xtc.atoms.coordinates(), - dcd.atoms.coordinates(), + xtc.atoms.positions, + dcd.atoms.positions, 3, err_msg="XTC -> DCD: DCD coordinates are messed up (Issue 59)") @@ -304,16 +304,16 @@ def test_OtherWriter(self): dcd.trajectory.rewind() assert_array_almost_equal( - dcd.atoms.coordinates(), - xtc.atoms.coordinates(), + dcd.atoms.positions, + xtc.atoms.positions, 2, err_msg="DCD -> XTC: coordinates are messed up (frame {0:d})".format( dcd.trajectory.frame)) xtc.trajectory[3] dcd.trajectory[3] assert_array_almost_equal( - dcd.atoms.coordinates(), - xtc.atoms.coordinates(), + dcd.atoms.positions, + xtc.atoms.positions, 2, err_msg="DCD -> XTC: coordinates are messed up (frame {0:d})".format( dcd.trajectory.frame)) diff --git a/testsuite/MDAnalysisTests/coordinates/test_gro.py b/testsuite/MDAnalysisTests/coordinates/test_gro.py index b446f5a6a13..188e3713e16 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_gro.py +++ b/testsuite/MDAnalysisTests/coordinates/test_gro.py @@ -184,8 +184,8 @@ def tearDown(self): def test_writer(self): self.universe.atoms.write(self.outfile) u = mda.Universe(self.outfile) - assert_almost_equal(u.atoms.coordinates(), - self.universe.atoms.coordinates(), self.prec, + assert_almost_equal(u.atoms.positions, + self.universe.atoms.positions, self.prec, err_msg="Writing GRO file with GROWriter does " "not reproduce original coordinates") diff --git a/testsuite/MDAnalysisTests/coordinates/test_pdb.py b/testsuite/MDAnalysisTests/coordinates/test_pdb.py index d4705fc0011..a081d42a7be 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_pdb.py +++ b/testsuite/MDAnalysisTests/coordinates/test_pdb.py @@ -185,8 +185,8 @@ def test_writer(self): "Test writing from a single frame PDB file to a PDB file." "" self.universe.atoms.write(self.outfile) u = mda.Universe(PSF, self.outfile, permissive=True) - assert_almost_equal(u.atoms.coordinates(), - self.universe.atoms.coordinates(), self.prec, + assert_almost_equal(u.atoms.positions, + self.universe.atoms.positions, self.prec, err_msg="Writing PDB file with PrimitivePDBWriter " "does not reproduce original coordinates") @@ -215,7 +215,7 @@ def test_write_single_frame_AtomGroup(self): assert_equal(u2.trajectory.n_frames, 1, err_msg="Output PDB should only contain a single frame") - assert_almost_equal(u2.atoms.coordinates(), u.atoms.coordinates(), + assert_almost_equal(u2.atoms.positions, u.atoms.positions, self.prec, err_msg="Written coordinates do not " "agree with original coordinates from frame %d" % u.trajectory.frame) diff --git a/testsuite/MDAnalysisTests/coordinates/test_pqr.py b/testsuite/MDAnalysisTests/coordinates/test_pqr.py index a8c463a5e5b..05bdc317867 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_pqr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_pqr.py @@ -61,8 +61,8 @@ def test_writer_noChainID(self): self.universe.atoms.write(self.outfile) u = mda.Universe(self.outfile) assert_equal(u.segments.segids[0], 'SYSTEM') - assert_almost_equal(u.atoms.coordinates(), - self.universe.atoms.coordinates(), self.prec, + assert_almost_equal(u.atoms.positions, + self.universe.atoms.positions, self.prec, err_msg="Writing PQR file with PQRWriter does " "not reproduce original coordinates") assert_almost_equal(u.atoms.charges, self.universe.atoms.charges, @@ -78,8 +78,8 @@ def test_write_withChainID(self): self.universe.atoms.write(self.outfile) u = mda.Universe(self.outfile) assert_equal(u.segments.segids[0], 'A') - assert_almost_equal(u.atoms.coordinates(), - self.universe.atoms.coordinates(), self.prec, + assert_almost_equal(u.atoms.positions, + self.universe.atoms.positions, self.prec, err_msg="Writing PQR file with PQRWriter does " "not reproduce original coordinates") assert_almost_equal(u.atoms.charges, self.universe.atoms.charges, diff --git a/testsuite/MDAnalysisTests/coordinates/test_trj.py b/testsuite/MDAnalysisTests/coordinates/test_trj.py index 33050aa4d21..d163b39447e 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_trj.py +++ b/testsuite/MDAnalysisTests/coordinates/test_trj.py @@ -52,8 +52,8 @@ def test_initial_frame_is_0(self): def test_starts_with_first_frame(self): """Test that coordinate arrays are filled as soon as the trajectory has been opened.""" - assert_(np.any(self.universe.atoms.coordinates() > 0), - "Reader does not populate coordinates() right away.") + assert_(np.any(self.universe.atoms.positions > 0), + "Reader does not populate positions right away.") def test_rewind(self): trj = self.universe.trajectory @@ -63,8 +63,8 @@ def test_rewind(self): "failed to forward to frame 2 (frameindex 2)") trj.rewind() assert_equal(trj.ts.frame, 0, "failed to rewind to first frame") - assert_(np.any(self.universe.atoms.coordinates() > 0), - "Reader does not populate coordinates() after rewinding.") + assert_(np.any(self.universe.atoms.positions > 0), + "Reader does not populate positions after rewinding.") def test_full_slice(self): trj_iter = self.universe.trajectory[:] diff --git a/testsuite/MDAnalysisTests/coordinates/test_trz.py b/testsuite/MDAnalysisTests/coordinates/test_trz.py index 6029578ea51..97a15a440b4 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_trz.py +++ b/testsuite/MDAnalysisTests/coordinates/test_trz.py @@ -240,8 +240,8 @@ def test_write_trajectory(self): u_ag = mda.Universe(self.outfile) - assert_array_almost_equal(self.ag.coordinates(), - u_ag.atoms.coordinates(), + assert_array_almost_equal(self.ag.positions, + u_ag.atoms.positions, self.prec, err_msg="Writing AtomGroup timestep failed.") diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 3cda447b8df..dc24e9e87f7 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -155,7 +155,7 @@ def test_coordinates(self): ca = U.select_atoms('name CA and resid 122') # low precision match (2 decimals in A, 3 in nm) because the above are # the trr coords - assert_array_almost_equal(ca.coordinates(), ca_Angstrom, 2, + assert_array_almost_equal(ca.positions, ca_Angstrom, 2, err_msg="coords of Ca of resid 122 do not " "match for frame 3") @@ -231,8 +231,8 @@ def test_Writer(self): assert_equal(u.trajectory.n_frames, 2) # prec = 6: TRR test fails; here I am generous and take self.prec = # 3... - assert_almost_equal(u.atoms.coordinates(), - self.universe.atoms.coordinates(), self.prec) + assert_almost_equal(u.atoms.positions, + self.universe.atoms.positions, self.prec) @dec.slow def test_EOFraisesIOErrorEIO(self): @@ -337,7 +337,7 @@ def test_coordinates(self): ca = U.select_atoms('name CA and resid 122') # low precision match because we also look at the trr: only 3 decimals # in nm in xtc! - assert_array_almost_equal(ca.coordinates(), ca_nm, 3, + assert_array_almost_equal(ca.positions, ca_nm, 3, err_msg="native coords of Ca of resid 122 " "do not match for frame 3 with " "convert_units=False") @@ -532,8 +532,8 @@ def _single_frame(self, filename): assert_equal(w.trajectory.n_frames, 1, "single frame trajectory has wrong number of frames") assert_almost_equal( - w.atoms.coordinates(), - u.atoms.coordinates(), + w.atoms.positions, + u.atoms.positions, self.prec, err_msg="coordinates do not match for {0!r}".format(filename)) diff --git a/testsuite/MDAnalysisTests/test_atomgroup.py b/testsuite/MDAnalysisTests/test_atomgroup.py index c242f26bda8..8d095a24c2b 100644 --- a/testsuite/MDAnalysisTests/test_atomgroup.py +++ b/testsuite/MDAnalysisTests/test_atomgroup.py @@ -316,7 +316,7 @@ def test_center_of_mass(self): def test_coordinates(self): assert_array_almost_equal( - self.ag.coordinates()[1000:2000:200], + self.ag.positions[1000:2000:200], np.array([[3.94543672, -12.4060812, -7.26820087], [13.21632767, 5.879035, -14.67914867], [12.07735443, -9.00604534, 4.09301519], @@ -580,7 +580,7 @@ def test_packintobox(self): # Provide arbitrary box ag.pack_into_box(box=np.array([5., 5., 5.], dtype=np.float32)) assert_array_almost_equal( - ag.coordinates(), + ag.positions, np.array([[3.94543672, 2.5939188, 2.73179913], [3.21632767, 0.879035, 0.32085133], [2.07735443, 0.99395466, 4.09301519], @@ -788,7 +788,7 @@ def test_positions(self): pos = ag.positions + 3.14 ag.positions = pos # should work - assert_almost_equal(ag.coordinates(), pos, + assert_almost_equal(ag.positions, pos, err_msg="failed to update atoms 12:42 position " "to new position") @@ -802,7 +802,7 @@ def test_set_positions(self): ag = self.universe.select_atoms("bynum 12:42") pos = ag.get_positions() + 3.14 ag.set_positions(pos) - assert_almost_equal(ag.coordinates(), pos, + assert_almost_equal(ag.positions, pos, err_msg="failed to update atoms 12:42 position " "to new position") @@ -1531,7 +1531,7 @@ def universe_from_tmp(self): def test_write_atoms(self): self.universe.atoms.write(self.outfile) u2 = self.universe_from_tmp() - assert_array_almost_equal(self.universe.atoms.coordinates(), u2.atoms.coordinates(), self.precision, + assert_array_almost_equal(self.universe.atoms.positions, u2.atoms.positions, self.precision, err_msg="atom coordinate mismatch between original and {0!s} file".format(self.ext)) def test_write_empty_atomgroup(self): @@ -1544,7 +1544,7 @@ def test_write_selection(self): u2 = self.universe_from_tmp() CA2 = u2.select_atoms('all') # check EVERYTHING, otherwise we might get false positives! assert_equal(len(u2.atoms), len(CA.atoms), "written CA selection does not match original selection") - assert_almost_equal(CA2.coordinates(), CA.coordinates(), self.precision, + assert_almost_equal(CA2.positions, CA.positions, self.precision, err_msg="CA coordinates do not agree with original") def test_write_Residue(self): @@ -1553,7 +1553,7 @@ def test_write_Residue(self): u2 = self.universe_from_tmp() G2 = u2.select_atoms('all') # check EVERYTHING, otherwise we might get false positives! assert_equal(len(u2.atoms), len(G.atoms), "written R206 Residue does not match original ResidueGroup") - assert_almost_equal(G2.coordinates(), G.coordinates(), self.precision, + assert_almost_equal(G2.positions, G.positions, self.precision, err_msg="Residue R206 coordinates do not agree with original") def test_write_ResidueGroup(self): @@ -1562,7 +1562,7 @@ def test_write_ResidueGroup(self): u2 = self.universe_from_tmp() G2 = u2.select_atoms('all') # check EVERYTHING, otherwise we might get false positives! assert_equal(len(u2.atoms), len(G.atoms), "written LEU ResidueGroup does not match original ResidueGroup") - assert_almost_equal(G2.coordinates(), G.coordinates(), self.precision, + assert_almost_equal(G2.positions, G.positions, self.precision, err_msg="ResidueGroup LEU coordinates do not agree with original") def test_write_Segment(self): @@ -1571,7 +1571,7 @@ def test_write_Segment(self): u2 = self.universe_from_tmp() G2 = u2.select_atoms('all') # check EVERYTHING, otherwise we might get false positives! assert_equal(len(u2.atoms), len(G.atoms), "written s4AKE segment does not match original segment") - assert_almost_equal(G2.coordinates(), G.coordinates(), self.precision, + assert_almost_equal(G2.positions, G.positions, self.precision, err_msg="segment s4AKE coordinates do not agree with original") def test_write_Universe(self): @@ -1581,7 +1581,7 @@ def test_write_Universe(self): W.close() u2 = self.universe_from_tmp() assert_equal(len(u2.atoms), len(U.atoms), "written 4AKE universe does not match original universe in size") - assert_almost_equal(u2.atoms.coordinates(), U.atoms.coordinates(), self.precision, + assert_almost_equal(u2.atoms.positions, U.atoms.positions, self.precision, err_msg="written universe 4AKE coordinates do not agree with original") diff --git a/testsuite/MDAnalysisTests/test_atomselections.py b/testsuite/MDAnalysisTests/test_atomselections.py index 1b610a5578c..73a21feb91b 100644 --- a/testsuite/MDAnalysisTests/test_atomselections.py +++ b/testsuite/MDAnalysisTests/test_atomselections.py @@ -139,7 +139,7 @@ def test_atom(self): assert_equal(len(sel), 1) assert_equal(sel.resnames, ['GLY']) assert_array_almost_equal( - sel.coordinates(), + sel.positions, np.array([[20.38685226, -3.44224262, -5.92158318]], dtype=np.float32)) diff --git a/testsuite/MDAnalysisTests/test_distances.py b/testsuite/MDAnalysisTests/test_distances.py index fe78bb4e61e..87d92d47a19 100644 --- a/testsuite/MDAnalysisTests/test_distances.py +++ b/testsuite/MDAnalysisTests/test_distances.py @@ -106,9 +106,9 @@ def tearDown(self): def test_simple(self): U = self.universe self.trajectory.rewind() - x0 = U.atoms.coordinates(copy=True) + x0 = U.atoms.positions self.trajectory[10] - x1 = U.atoms.coordinates(copy=True) + x1 = U.atoms.positions d = MDAnalysis.lib.distances.distance_array(x0, x1, backend=self.backend) assert_equal(d.shape, (3341, 3341), "wrong shape (should be (Natoms,Natoms))") assert_almost_equal(d.min(), 0.11981228170520701, self.prec, @@ -119,9 +119,9 @@ def test_simple(self): def test_outarray(self): U = self.universe self.trajectory.rewind() - x0 = U.atoms.coordinates(copy=True) + x0 = U.atoms.positions self.trajectory[10] - x1 = U.atoms.coordinates(copy=True) + x1 = U.atoms.positions natoms = len(U.atoms) d = np.zeros((natoms, natoms), np.float64) MDAnalysis.lib.distances.distance_array(x0, x1, result=d, backend=self.backend) @@ -135,9 +135,9 @@ def test_periodic(self): # boring with the current dcd as that has no PBC U = self.universe self.trajectory.rewind() - x0 = U.atoms.coordinates(copy=True) + x0 = U.atoms.positions self.trajectory[10] - x1 = U.atoms.coordinates(copy=True) + x1 = U.atoms.positions d = MDAnalysis.lib.distances.distance_array(x0, x1, box=U.coord.dimensions, backend=self.backend) assert_equal(d.shape, (3341, 3341), "should be square matrix with Natoms entries") @@ -173,7 +173,7 @@ def tearDown(self): def test_simple(self): U = self.universe self.trajectory.rewind() - x0 = U.atoms.coordinates(copy=True) + x0 = U.atoms.positions d = MDAnalysis.lib.distances.self_distance_array(x0, backend=self.backend) N = 3341 * (3341 - 1) / 2 assert_equal(d.shape, (N,), "wrong shape (should be (Natoms*(Natoms-1)/2,))") @@ -185,7 +185,7 @@ def test_simple(self): def test_outarray(self): U = self.universe self.trajectory.rewind() - x0 = U.atoms.coordinates(copy=True) + x0 = U.atoms.positions natoms = len(U.atoms) N = natoms * (natoms - 1) / 2 d = np.zeros((N,), np.float64) @@ -200,7 +200,7 @@ def test_periodic(self): # boring with the current dcd as that has no PBC U = self.universe self.trajectory.rewind() - x0 = U.atoms.coordinates(copy=True) + x0 = U.atoms.positions natoms = len(U.atoms) N = natoms * (natoms - 1) / 2 d = MDAnalysis.lib.distances.self_distance_array(x0, box=U.coord.dimensions, @@ -575,7 +575,7 @@ def test_ortho_PBC(self): from MDAnalysis.lib.distances import apply_PBC U = MDAnalysis.Universe(PSF, DCD) - atoms = U.atoms.coordinates() + atoms = U.atoms.positions box1 = np.array([2.5, 2.5, 3.5], dtype=np.float32) box2 = np.array([2.5, 2.5, 3.5, 90., 90., 90.], dtype=np.float32) @@ -592,7 +592,7 @@ def test_tric_PBC(self): from MDAnalysis.lib.distances import apply_PBC U = MDAnalysis.Universe(TRIC) - atoms = U.atoms.coordinates() + atoms = U.atoms.positions box1 = U.dimensions box2 = MDAnalysis.coordinates.core.triclinic_vectors(box1) From 6131849525aca63ef0f91efce5a822476815676a Mon Sep 17 00:00:00 2001 From: Richard Gowers Date: Sun, 17 Apr 2016 22:50:53 +0100 Subject: [PATCH 10/12] fixup --- testsuite/MDAnalysisTests/coordinates/test_gro.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_gro.py b/testsuite/MDAnalysisTests/coordinates/test_gro.py index cb100fb5cc9..4eceacc5cd3 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_gro.py +++ b/testsuite/MDAnalysisTests/coordinates/test_gro.py @@ -6,7 +6,7 @@ from nose.plugins.attrib import attr from numpy.testing import (assert_equal, assert_almost_equal, dec, assert_array_almost_equal, assert_raises, - assert_) + ) from unittest import TestCase import tempdir From 66115e11e4f6de705abc6dac3dd1f5f00e6437b6 Mon Sep 17 00:00:00 2001 From: John Detlefs Date: Thu, 14 Apr 2016 18:30:17 -0700 Subject: [PATCH 11/12] Updated rms.py and tests to account for weighting Updated tests to check weighting with superposition --- package/CHANGELOG | 6 ++--- package/MDAnalysis/analysis/rms.py | 6 ++++- testsuite/CHANGELOG | 4 +-- .../MDAnalysisTests/analysis/test_rms.py | 26 +++++++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 172a3b752d5..0bdc95804a1 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -13,8 +13,8 @@ The rules for this file: * release numbers follow "Semantic Versioning" http://semver.org ------------------------------------------------------------------------------ -??/??/16 jandom, abhinavgupta94, orbeckst, kain88-de, hainm, jdetle, jbarnoud, - dotsdl, richardjgowers +??/??/16 jandom, abhinavgupta94, orbeckst, kain88-de, hainm, jbarnoud, + dotsdl, richardjgowers, jdetle * 0.15.0 @@ -36,7 +36,7 @@ Enhancements * Added read-only property giving Universe init kwargs (Issue #292) Fixes - + * rmsd now returns proper value when given array of weights (Issue #814) * change_release now finds number and dev (Issue #776) * test_shear_from_matrix doesn't fail for MKL builds anymore (Issue #757) * HEADER and TITLE now appear just once in the PDB. (Issue #741) (PR #761) diff --git a/package/MDAnalysis/analysis/rms.py b/package/MDAnalysis/analysis/rms.py index f59b474ef48..1c7ce0e3bee 100644 --- a/package/MDAnalysis/analysis/rms.py +++ b/package/MDAnalysis/analysis/rms.py @@ -204,7 +204,11 @@ def rmsd(a, b, weights=None, center=False, superposition=False): return qcp.CalcRMSDRotationalMatrix(a.T, b.T, N, None, relative_weights) else: - return np.sqrt(np.sum((a - b) ** 2) / N) + if weights is not None: + return np.sqrt(np.sum(relative_weights[:, np.newaxis] + * (( a - b ) ** 2)) / N) + else: + return np.sqrt(np.sum((a - b) ** 2) / N) def _process_selection(select): diff --git a/testsuite/CHANGELOG b/testsuite/CHANGELOG index 007cd57f07d..6553c35edc4 100644 --- a/testsuite/CHANGELOG +++ b/testsuite/CHANGELOG @@ -13,9 +13,9 @@ Also see https://github.com/MDAnalysis/mdanalysis/wiki/MDAnalysisTests and https://github.com/MDAnalysis/mdanalysis/wiki/UnitTests ------------------------------------------------------------------------------ -??/??/16 orbeckst, jbarnoud, pedrishi, fiona-naughton +??/??/16 orbeckst, jbarnoud, pedrishi, fiona-naughton, jdetle * 0.15.0 - + - Added test for weighted rmsd (issue #814) - metadata update: link download_url to GitHub releases so that Depsy recognizes contributors (issue #749) and added @richardjgowers as maintainer diff --git a/testsuite/MDAnalysisTests/analysis/test_rms.py b/testsuite/MDAnalysisTests/analysis/test_rms.py index 89b0985258c..56a9feb7f6a 100644 --- a/testsuite/MDAnalysisTests/analysis/test_rms.py +++ b/testsuite/MDAnalysisTests/analysis/test_rms.py @@ -73,6 +73,32 @@ def test_superposition(self): rmsd = rms.rmsd(a, b, superposition=True) assert_almost_equal(rmsd, 6.820321761927005) + def test_weights(self): + weights = np.zeros(len(self.a)) + weights[0] = 1 + weights[1] = 1 + weighted = rms.rmsd(self.a, self.b, weights=weights) + firstCoords = rms.rmsd(self.a[:2], self.b[:2]) + assert_almost_equal(weighted, firstCoords) + + def test_weights_and_superposition_1(self): + weights = np.ones(len(self.u.trajectory[0])) + weighted = rms.rmsd(self.u.trajectory[0], self.u.trajectory[1], + weights=weights, superposition=True) + firstCoords = rms.rmsd(self.u.trajectory[0], self.u.trajectory[1], + superposition=True) + assert_almost_equal(weighted, firstCoords, decimal=5) + + def test_weights_and_superposition_2(self): + weights = np.zeros(len(self.u.trajectory[0])) + weights[:100] = 1 + weighted = rms.rmsd(self.u.trajectory[0], self.u.trajectory[-1], + weights=weights, superposition=True) + firstCoords = rms.rmsd(self.u.trajectory[0][:100], self.u.trajectory[-1][:100], + superposition=True) + #very close to zero, change significant decimal places to 5 + assert_almost_equal(weighted, firstCoords, decimal = 5) + @staticmethod @raises(ValueError) def test_unequal_shape(): From 6a47ed73a5f69fa6de65a316af050179c267e167 Mon Sep 17 00:00:00 2001 From: Richard Gowers Date: Mon, 18 Apr 2016 10:57:40 +0100 Subject: [PATCH 12/12] Deprecation warnings now only appear once per deprecated feature --- package/MDAnalysis/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/__init__.py b/package/MDAnalysis/__init__.py index 648fd8b845d..eca7daed8d4 100644 --- a/package/MDAnalysis/__init__.py +++ b/package/MDAnalysis/__init__.py @@ -162,7 +162,7 @@ del logging # DeprecationWarnings are loud by default -warnings.simplefilter('always', DeprecationWarning) +warnings.simplefilter('once', DeprecationWarning) from . import units