From cf48a576fa118b114cae051d24355b3e6e3e92a3 Mon Sep 17 00:00:00 2001 From: Hannah Pollak Date: Tue, 16 Mar 2021 17:36:04 +0000 Subject: [PATCH 01/46] add boxdimensions.py --- .../transformations/boxdimensions.py | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 package/MDAnalysis/transformations/boxdimensions.py diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py new file mode 100644 index 00000000000..2c167a005cb --- /dev/null +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -0,0 +1,78 @@ +# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 +# +# MDAnalysis --- https://www.mdanalysis.org +# Copyright (c) 2006-2017 The MDAnalysis Development Team and contributors +# (see the file AUTHORS for the full list of names) +# +# Released under the GNU Public Licence, v2 or any higher version +# +# Please cite your use of MDAnalysis in published work: +# +# R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler, +# D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein. +# MDAnalysis: A Python package for the rapid analysis of molecular dynamics +# simulations. In S. Benthall and S. Rostrup editors, Proceedings of the 15th +# Python in Science Conference, pages 102-109, Austin, TX, 2016. SciPy. +# doi: 10.25080/majora-629e541a-00e +# +# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein. +# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. +# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 +# + +"""\ +Set box dimensions --- :mod: `MDAnalysis.transformations.boxdimensions` +======================================================================= + +Set dimensions of the simulatopn box to a constant vector across all timesteps. + + +..autocalss:: setdimensions +""" +import numpy as np + +class setdimensions(object): + """ + Set simulation box dimensions. + + Timestep dimensions are modified in place. + + Example + ------- + + e.g. set simulation box dimensions to a vector containing unit cell + dimensions [*a*, *b*, *c*, *alpha*, *beta*, *gamma*], lengths *a*, + *b*, *c* are in the MDAnalysis length unit (Å), and angles are in degrees. + + dim = [2, 2, 2, 90, 90, 90] + transform = mda.transformations.boxdimensions.setdimensions(dim) + u.trajectorz.add_transformations(transform) + + Parameters + ---------- + dimensions: array-like + vector that contains unit cell lengths and angles. + Expected shapes are (6, 0) or (1, 6) + + Returns + ------- + MDAnalysis.coordinates.base.Timestep + """ + + def __init__(self, dimensions): + self.dimensions = dimensions + + try: + self.dimensions = np.asarray(self.dimensions, np.float32) + if self.dimensions.shape != (6, ) and \ + self.dimensions.shape != (1, 6): + raise ValueError(f'{self.dimensions} are not valid box dimensions') + self.dimensions = self.dimensions.reshape(6, ) + except ValueError: + raise ValueError(f'{self.dimensions} are not valid box dimensions') + + def __call__(self, ts): + ts.dimensions = self.dimensions + return ts + From d63aca2d19ef765d3df03287a19040e491147c52 Mon Sep 17 00:00:00 2001 From: Hannah Pollak Date: Tue, 16 Mar 2021 17:37:18 +0000 Subject: [PATCH 02/46] write .gitignore --- package/MDAnalysis/transformations/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 package/MDAnalysis/transformations/.gitignore diff --git a/package/MDAnalysis/transformations/.gitignore b/package/MDAnalysis/transformations/.gitignore new file mode 100644 index 00000000000..0e1465fa221 --- /dev/null +++ b/package/MDAnalysis/transformations/.gitignore @@ -0,0 +1,4 @@ +.spyproject/* +../analysis/spyproject/* +../analysis/rmsn.py + From 8488cfd2e414a90454854b63ff9200863693d9fa Mon Sep 17 00:00:00 2001 From: Hannah Pollak Date: Tue, 16 Mar 2021 19:45:42 +0000 Subject: [PATCH 03/46] add tests for boxdimensions transformation --- .../transformations/test_boxdimensions.py | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 testsuite/MDAnalysisTests/transformations/test_boxdimensions.py diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py new file mode 100644 index 00000000000..639bb47a8ea --- /dev/null +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -0,0 +1,72 @@ +#-*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8 +# +# MDAnalysis --- https://www.mdanalysis.org +# Copyright (c) 2006-2017 The MDAnalysis Development Team and contributors +# (see the file AUTHORS for the full list of names) +# +# Released under the GNU Public Licence, v2 or any higher version +# +# Please cite your use of MDAnalysis in published work: +# +# R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler, +# D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein. +# MDAnalysis: A Python package for the rapid analysis of molecular dynamics +# simulations. In S. Benthall and S. Rostrup editors, Proceedings of the 15th +# Python in Science Conference, pages 102-109, Austin, TX, 2016. SciPy. +# doi: 10.25080/majora-629e541a-00e +# +# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein. +# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. +# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 +# + +import numpy as np +import pytest +from numpy.testing import assert_array_almost_equal + +import MDAnalysis as mdanalysis +from MDAnalysis.transformations import boxdimensions +from MDAnalysisTests import make_Universe + +@pytest.fixture() +def boxdimensions_universes(): + # create Universe objects for tests + ref_u = make_Universe(trajectory=True) + new_u = ref_u + return ref_u, new_u + +def test_boxdimensions_dims(boxdimensions_universes): + ref_u, new_u = boxdimensions_universes + ref = ref_u.trajectory.ts + new_dims = np.float32([2, 2, 2, 90, 90, 90]) + ref.dimensions = new_dims + new = boxdimensions.setdimensions(new_dims)(new_u.trajectory.ts) + assert_array_almost_equal(ref.dimensions, new.dimensions, decimal=6) + +@pytest.mark.parametrize('dim_vector', ( + [1, 1, 1, 90, 90], + [1, 1, 1, 1, 90, 90, 90], + ['a', 'b', 'c', 'd', 'e', 'f'], + np.array([1, 1, 1, 90, 90]), + np.array([1, 1, 1, 1, 90, 90, 90]), + np.array([[1], [1], [90], [90], [90]]), + np.array(['a', 'b', 'c', 'd', 'e', 'f']), + 111, + 'abcd') +) + +def test_dimensions_vector(boxdimensions_universes, dim_vector): + # wrong box dimension vector size + ts = boxdimensions_universes[0].trajectory.ts + with pytest.raises(ValueError): + boxdimensions.setdimensions(dim_vector)(ts) + +def test_dimensions_transformations_api(boxdimensions_universes): + # test if transformation workes with on-the-fly transformations API + ref_u, new_u = boxdimensions_universes + ref = ref_u.trajectory.ts + new_dims = np.float32([2, 2, 2, 90, 90, 90]) + ref.dimensions = new_dims + new = boxdimensions.setdimensions(new_dims)(new_u.trajectory.ts) + assert_array_almost_equal(ref.dimensions, new.dimensions, decimal=6) From 09276f506018923239e44e4deaafaec5d5b4a85f Mon Sep 17 00:00:00 2001 From: Hannah Pollak Date: Tue, 16 Mar 2021 19:46:37 +0000 Subject: [PATCH 04/46] update .gitignore --- package/MDAnalysis/transformations/.gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/package/MDAnalysis/transformations/.gitignore b/package/MDAnalysis/transformations/.gitignore index 0e1465fa221..5ec2900d5fa 100644 --- a/package/MDAnalysis/transformations/.gitignore +++ b/package/MDAnalysis/transformations/.gitignore @@ -1,4 +1,2 @@ .spyproject/* -../analysis/spyproject/* -../analysis/rmsn.py From 3f3d1e7e6a0e31603e161da54e3fceadd64bf928 Mon Sep 17 00:00:00 2001 From: Hannah Pollak Date: Tue, 16 Mar 2021 19:53:30 +0000 Subject: [PATCH 05/46] change naming of dimensions setting class to SetDimensions add bodims.py to transformations/__init__.py --- package/MDAnalysis/transformations/__init__.py | 1 + package/MDAnalysis/transformations/boxdimensions.py | 2 +- .../MDAnalysisTests/transformations/test_boxdimensions.py | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package/MDAnalysis/transformations/__init__.py b/package/MDAnalysis/transformations/__init__.py index 91083fff18b..ba7c8233f30 100644 --- a/package/MDAnalysis/transformations/__init__.py +++ b/package/MDAnalysis/transformations/__init__.py @@ -130,3 +130,4 @@ def wrapped(ts): from .positionaveraging import PositionAverager from .fit import fit_translation, fit_rot_trans from .wrap import wrap, unwrap +from .boxdimensions import SetDimensions diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 2c167a005cb..0a062cc57e0 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -32,7 +32,7 @@ """ import numpy as np -class setdimensions(object): +class SetDimensions(object): """ Set simulation box dimensions. diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index 639bb47a8ea..23f3c504ed8 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -26,7 +26,7 @@ from numpy.testing import assert_array_almost_equal import MDAnalysis as mdanalysis -from MDAnalysis.transformations import boxdimensions +from MDAnalysis.transformations import SetDimensions from MDAnalysisTests import make_Universe @pytest.fixture() @@ -41,7 +41,7 @@ def test_boxdimensions_dims(boxdimensions_universes): ref = ref_u.trajectory.ts new_dims = np.float32([2, 2, 2, 90, 90, 90]) ref.dimensions = new_dims - new = boxdimensions.setdimensions(new_dims)(new_u.trajectory.ts) + new = SetDimensions(new_dims)(new_u.trajectory.ts) assert_array_almost_equal(ref.dimensions, new.dimensions, decimal=6) @pytest.mark.parametrize('dim_vector', ( @@ -60,7 +60,7 @@ def test_dimensions_vector(boxdimensions_universes, dim_vector): # wrong box dimension vector size ts = boxdimensions_universes[0].trajectory.ts with pytest.raises(ValueError): - boxdimensions.setdimensions(dim_vector)(ts) + SetDimensions(dim_vector)(ts) def test_dimensions_transformations_api(boxdimensions_universes): # test if transformation workes with on-the-fly transformations API @@ -68,5 +68,5 @@ def test_dimensions_transformations_api(boxdimensions_universes): ref = ref_u.trajectory.ts new_dims = np.float32([2, 2, 2, 90, 90, 90]) ref.dimensions = new_dims - new = boxdimensions.setdimensions(new_dims)(new_u.trajectory.ts) + new = SetDimensions(new_dims)(new_u.trajectory.ts) assert_array_almost_equal(ref.dimensions, new.dimensions, decimal=6) From 97e5d43aa8026611ee2abcfee0a6455b07b9d9f7 Mon Sep 17 00:00:00 2001 From: Hannah Pollak Date: Tue, 16 Mar 2021 20:13:12 +0000 Subject: [PATCH 06/46] add changes to CHANGELOG --- package/CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package/CHANGELOG b/package/CHANGELOG index 3d2a64b41ee..23a37699469 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -84,6 +84,8 @@ Fixes * Fix syntax warning over comparison of literals using is (Issue #3066) Enhancements + * Introduce possibility for setting box dimensions for all timesteps in + trajectory (Issue #2691) * Adds preliminary support for the ppc64le platform with minimal dependencies (Issue #3127, PR #3149) * Caches can now undergo central validation at the Universe level, opening From f115d5441efc31c815c22db15b011ed187e41a31 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Tue, 16 Mar 2021 20:23:02 +0000 Subject: [PATCH 07/46] Delete .gitignore --- package/MDAnalysis/transformations/.gitignore | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 package/MDAnalysis/transformations/.gitignore diff --git a/package/MDAnalysis/transformations/.gitignore b/package/MDAnalysis/transformations/.gitignore deleted file mode 100644 index 5ec2900d5fa..00000000000 --- a/package/MDAnalysis/transformations/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.spyproject/* - From 0beee174eff1cbe6bfa1f9b6025665463e5fd65c Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Fri, 19 Mar 2021 09:02:35 +0000 Subject: [PATCH 08/46] Update boxdimensions.py --- package/MDAnalysis/transformations/boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 0a062cc57e0..ec7cd13fb10 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -25,7 +25,7 @@ Set box dimensions --- :mod: `MDAnalysis.transformations.boxdimensions` ======================================================================= -Set dimensions of the simulatopn box to a constant vector across all timesteps. +Set dimensions of the simulation box to a constant vector across all timesteps. ..autocalss:: setdimensions From 7b9a36491a6fe30b643ea51ce001ca5c7f8d893d Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Fri, 19 Mar 2021 09:02:59 +0000 Subject: [PATCH 09/46] Update boxdimensions.py --- package/MDAnalysis/transformations/boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index ec7cd13fb10..328a24f8923 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -32,7 +32,7 @@ """ import numpy as np -class SetDimensions(object): +class SetDimensions: """ Set simulation box dimensions. From 64cc339de9080c8c3cd2786a0e4d0687070ab98f Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Fri, 19 Mar 2021 09:03:39 +0000 Subject: [PATCH 10/46] Update boxdimensions.py --- package/MDAnalysis/transformations/boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 328a24f8923..fe3d695f1d5 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -47,7 +47,7 @@ class SetDimensions: dim = [2, 2, 2, 90, 90, 90] transform = mda.transformations.boxdimensions.setdimensions(dim) - u.trajectorz.add_transformations(transform) + u.trajectory.add_transformations(transform) Parameters ---------- From 0d950613924d94fcbd4cb800174a4c646c7fe118 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Fri, 19 Mar 2021 09:08:16 +0000 Subject: [PATCH 11/46] Update boxdimensions.py --- package/MDAnalysis/transformations/boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index fe3d695f1d5..80811496a02 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -68,7 +68,7 @@ def __init__(self, dimensions): if self.dimensions.shape != (6, ) and \ self.dimensions.shape != (1, 6): raise ValueError(f'{self.dimensions} are not valid box dimensions') - self.dimensions = self.dimensions.reshape(6, ) + self.dimensions = self.dimensions.reshape(6, ) except ValueError: raise ValueError(f'{self.dimensions} are not valid box dimensions') From 552a7a48b55dbbc0610e49d240c9aa4c0c63dbb5 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Fri, 19 Mar 2021 09:23:17 +0000 Subject: [PATCH 12/46] Update boxdimensions.py correct formatting --- .../transformations/boxdimensions.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 80811496a02..88e924f6acf 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -32,19 +32,20 @@ """ import numpy as np + class SetDimensions: """ Set simulation box dimensions. - + Timestep dimensions are modified in place. - + Example ------- - + e.g. set simulation box dimensions to a vector containing unit cell dimensions [*a*, *b*, *c*, *alpha*, *beta*, *gamma*], lengths *a*, *b*, *c* are in the MDAnalysis length unit (Å), and angles are in degrees. - + dim = [2, 2, 2, 90, 90, 90] transform = mda.transformations.boxdimensions.setdimensions(dim) u.trajectory.add_transformations(transform) @@ -59,20 +60,20 @@ class SetDimensions: ------- MDAnalysis.coordinates.base.Timestep """ - + def __init__(self, dimensions): self.dimensions = dimensions - + try: self.dimensions = np.asarray(self.dimensions, np.float32) if self.dimensions.shape != (6, ) and \ self.dimensions.shape != (1, 6): - raise ValueError(f'{self.dimensions} are not valid box dimensions') + raise ValueError('{} are not valid box dimensions'.format( + self.dimensions)) self.dimensions = self.dimensions.reshape(6, ) except ValueError: raise ValueError(f'{self.dimensions} are not valid box dimensions') - + def __call__(self, ts): ts.dimensions = self.dimensions return ts - From dfabf94954d927a71972cb2a1e649d340bd9190a Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Fri, 19 Mar 2021 09:26:34 +0000 Subject: [PATCH 13/46] Update test_boxdimensions.py correct formatting --- .../MDAnalysisTests/transformations/test_boxdimensions.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index 23f3c504ed8..0763f162c77 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -29,6 +29,7 @@ from MDAnalysis.transformations import SetDimensions from MDAnalysisTests import make_Universe + @pytest.fixture() def boxdimensions_universes(): # create Universe objects for tests @@ -36,6 +37,7 @@ def boxdimensions_universes(): new_u = ref_u return ref_u, new_u + def test_boxdimensions_dims(boxdimensions_universes): ref_u, new_u = boxdimensions_universes ref = ref_u.trajectory.ts @@ -43,7 +45,8 @@ def test_boxdimensions_dims(boxdimensions_universes): ref.dimensions = new_dims new = SetDimensions(new_dims)(new_u.trajectory.ts) assert_array_almost_equal(ref.dimensions, new.dimensions, decimal=6) - + + @pytest.mark.parametrize('dim_vector', ( [1, 1, 1, 90, 90], [1, 1, 1, 1, 90, 90, 90], @@ -56,12 +59,14 @@ def test_boxdimensions_dims(boxdimensions_universes): 'abcd') ) + def test_dimensions_vector(boxdimensions_universes, dim_vector): # wrong box dimension vector size ts = boxdimensions_universes[0].trajectory.ts with pytest.raises(ValueError): SetDimensions(dim_vector)(ts) + def test_dimensions_transformations_api(boxdimensions_universes): # test if transformation workes with on-the-fly transformations API ref_u, new_u = boxdimensions_universes From 5ef27c89b38764171c5c4a28fb87bb0a49d3305e Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Fri, 19 Mar 2021 09:27:59 +0000 Subject: [PATCH 14/46] Update boxdimensions.py change formatting --- package/MDAnalysis/transformations/boxdimensions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 88e924f6acf..2535877b3fb 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -68,8 +68,7 @@ def __init__(self, dimensions): self.dimensions = np.asarray(self.dimensions, np.float32) if self.dimensions.shape != (6, ) and \ self.dimensions.shape != (1, 6): - raise ValueError('{} are not valid box dimensions'.format( - self.dimensions)) + raise ValueError(f'{self.dimensions} are not valid box dimensions') self.dimensions = self.dimensions.reshape(6, ) except ValueError: raise ValueError(f'{self.dimensions} are not valid box dimensions') From 4d3cf1755db2701d3473b6e76bda8743462007df Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 29 Mar 2021 09:58:49 +0100 Subject: [PATCH 15/46] Update package/MDAnalysis/transformations/boxdimensions.py Co-authored-by: Lily Wang <31115101+lilyminium@users.noreply.github.com> --- package/MDAnalysis/transformations/boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 2535877b3fb..7ee3e321b07 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -28,7 +28,7 @@ Set dimensions of the simulation box to a constant vector across all timesteps. -..autocalss:: setdimensions +..autoclass:: SetDimensions """ import numpy as np From 6ce9ab1f6e75df694de9d00f8e2f624e6e9a296d Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 29 Mar 2021 10:01:36 +0100 Subject: [PATCH 16/46] Update testsuite/MDAnalysisTests/transformations/test_boxdimensions.py Co-authored-by: Lily Wang <31115101+lilyminium@users.noreply.github.com> --- testsuite/MDAnalysisTests/transformations/test_boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index 0763f162c77..76865fc9d02 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -68,7 +68,7 @@ def test_dimensions_vector(boxdimensions_universes, dim_vector): def test_dimensions_transformations_api(boxdimensions_universes): - # test if transformation workes with on-the-fly transformations API + # test if transformation works with on-the-fly transformations API ref_u, new_u = boxdimensions_universes ref = ref_u.trajectory.ts new_dims = np.float32([2, 2, 2, 90, 90, 90]) From 4408a0924d76c6bafbaab1f316bc2a5f7cd64d9f Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 29 Mar 2021 11:03:15 +0100 Subject: [PATCH 17/46] Update boxdimensions.py --- .../transformations/boxdimensions.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 7ee3e321b07..83a8c697ee7 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -28,12 +28,12 @@ Set dimensions of the simulation box to a constant vector across all timesteps. -..autoclass:: SetDimensions +..autoclass:: setdimensions """ import numpy as np -class SetDimensions: +class setdimensions: """ Set simulation box dimensions. @@ -46,9 +46,11 @@ class SetDimensions: dimensions [*a*, *b*, *c*, *alpha*, *beta*, *gamma*], lengths *a*, *b*, *c* are in the MDAnalysis length unit (Å), and angles are in degrees. - dim = [2, 2, 2, 90, 90, 90] - transform = mda.transformations.boxdimensions.setdimensions(dim) - u.trajectory.add_transformations(transform) + .. code-block:: python + + dim = [2, 2, 2, 90, 90, 90] + transform = mda.transformations.boxdimensions.setdimensions(dim) + u.trajectory.add_transformations(transform) Parameters ---------- @@ -58,7 +60,7 @@ class SetDimensions: Returns ------- - MDAnalysis.coordinates.base.Timestep + :class:`~MDAnalysis.coordinates.base.Timestep` object """ def __init__(self, dimensions): @@ -66,12 +68,13 @@ def __init__(self, dimensions): try: self.dimensions = np.asarray(self.dimensions, np.float32) - if self.dimensions.shape != (6, ) and \ - self.dimensions.shape != (1, 6): - raise ValueError(f'{self.dimensions} are not valid box dimensions') - self.dimensions = self.dimensions.reshape(6, ) except ValueError: raise ValueError(f'{self.dimensions} are not valid box dimensions') + try: + self.dimensions = self.dimensions.reshape(6, ) + except ValueError: + raise ValueError(f'Box dimensions array must be convertible into shape (6, )') + def __call__(self, ts): ts.dimensions = self.dimensions From e33499e8a00767b48b932af27245f98ce61169ac Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 29 Mar 2021 11:21:38 +0100 Subject: [PATCH 18/46] Update test_boxdimensions.py --- .../transformations/test_boxdimensions.py | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index 76865fc9d02..8e180a83b06 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -26,25 +26,22 @@ from numpy.testing import assert_array_almost_equal import MDAnalysis as mdanalysis -from MDAnalysis.transformations import SetDimensions +from MDAnalysis.transformations import setdimensions from MDAnalysisTests import make_Universe @pytest.fixture() -def boxdimensions_universes(): +def boxdimensions_universe(): # create Universe objects for tests - ref_u = make_Universe(trajectory=True) - new_u = ref_u - return ref_u, new_u + new_u = make_Universe(trajectory=True) + return new_u -def test_boxdimensions_dims(boxdimensions_universes): - ref_u, new_u = boxdimensions_universes - ref = ref_u.trajectory.ts +def test_boxdimensions_dims(boxdimensions_universe): + new_u = boxdimensions_universe new_dims = np.float32([2, 2, 2, 90, 90, 90]) - ref.dimensions = new_dims - new = SetDimensions(new_dims)(new_u.trajectory.ts) - assert_array_almost_equal(ref.dimensions, new.dimensions, decimal=6) + new = setdimensions(new_dims)(new_u.trajectory.ts) + assert_array_almost_equal(new_dims, new.dimensions, decimal=6) @pytest.mark.parametrize('dim_vector', ( @@ -60,18 +57,18 @@ def test_boxdimensions_dims(boxdimensions_universes): ) -def test_dimensions_vector(boxdimensions_universes, dim_vector): +def test_dimensions_vector(boxdimensions_universe, dim_vector): # wrong box dimension vector size - ts = boxdimensions_universes[0].trajectory.ts + ts = boxdimensions_universe.trajectory.ts with pytest.raises(ValueError): - SetDimensions(dim_vector)(ts) + detdimensions(dim_vector) -def test_dimensions_transformations_api(boxdimensions_universes): +def test_dimensions_transformations_api(boxdimensions_universe): # test if transformation works with on-the-fly transformations API - ref_u, new_u = boxdimensions_universes - ref = ref_u.trajectory.ts + new_u = boxdimensions_universe new_dims = np.float32([2, 2, 2, 90, 90, 90]) - ref.dimensions = new_dims - new = SetDimensions(new_dims)(new_u.trajectory.ts) - assert_array_almost_equal(ref.dimensions, new.dimensions, decimal=6) + transform = setdimensions + new_u.trajectory.add_transformations(transform) + for ts in new_u.trajectory: + assert_array_almost_equal(new_dims, new_u.dimensions, decimal=6) From 5281cb142202746b72a64deece55e4d4e78305f0 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 29 Mar 2021 11:22:43 +0100 Subject: [PATCH 19/46] Update __init__.py --- package/MDAnalysis/transformations/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/__init__.py b/package/MDAnalysis/transformations/__init__.py index ba7c8233f30..f7b82555897 100644 --- a/package/MDAnalysis/transformations/__init__.py +++ b/package/MDAnalysis/transformations/__init__.py @@ -130,4 +130,4 @@ def wrapped(ts): from .positionaveraging import PositionAverager from .fit import fit_translation, fit_rot_trans from .wrap import wrap, unwrap -from .boxdimensions import SetDimensions +from .boxdimensions import setdimensions From 835283cff5d0bd6af4301c0832cefbd3823a42df Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 29 Mar 2021 11:30:43 +0100 Subject: [PATCH 20/46] Update CHANGELOG --- package/CHANGELOG | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 23a37699469..d27d5e0baa9 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -84,8 +84,8 @@ Fixes * Fix syntax warning over comparison of literals using is (Issue #3066) Enhancements - * Introduce possibility for setting box dimensions for all timesteps in - trajectory (Issue #2691) + * Add `setdimensions` transformation class for setting constant + box dimensions for all timesteps in trajectory (Issue #2691) * Adds preliminary support for the ppc64le platform with minimal dependencies (Issue #3127, PR #3149) * Caches can now undergo central validation at the Universe level, opening From 7cc725b1c4a72c23934f192a84019e9cdabd032b Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 29 Mar 2021 11:38:46 +0100 Subject: [PATCH 21/46] Add boxdimensions.rst to documentation_pages --- .../documentation_pages/transformations/boxdimensions.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst diff --git a/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst b/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst new file mode 100644 index 00000000000..ac2e4417349 --- /dev/null +++ b/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst @@ -0,0 +1,2 @@ +.. automodule:: MDAnalysis.transformations.boxdimensions + From e6b310936e7c4b26201b4d8e5ad16c021b96f667 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 29 Mar 2021 11:47:00 +0100 Subject: [PATCH 22/46] Delete boxdimensions.rst --- .../documentation_pages/transformations/boxdimensions.rst | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst diff --git a/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst b/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst deleted file mode 100644 index ac2e4417349..00000000000 --- a/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst +++ /dev/null @@ -1,2 +0,0 @@ -.. automodule:: MDAnalysis.transformations.boxdimensions - From ded63d3e0939ac86d586983dab0679a3773d2de7 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 29 Mar 2021 12:01:30 +0100 Subject: [PATCH 23/46] Update boxdimensions.py --- package/MDAnalysis/transformations/boxdimensions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 83a8c697ee7..414be15965f 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -73,8 +73,8 @@ def __init__(self, dimensions): try: self.dimensions = self.dimensions.reshape(6, ) except ValueError: - raise ValueError(f'Box dimensions array must be convertible into shape (6, )') - + raise ValueError('Box dimensions array must be convertible into \ +shape (6, )') def __call__(self, ts): ts.dimensions = self.dimensions From 100e3e4aaa5ed0c273a8b5320245b0896ca9ff5a Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 29 Mar 2021 14:35:05 +0100 Subject: [PATCH 24/46] Update test_boxdimensions.py --- .../MDAnalysisTests/transformations/test_boxdimensions.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index 8e180a83b06..91c8b79a4d2 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -1,4 +1,4 @@ -#-*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- +# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8 # # MDAnalysis --- https://www.mdanalysis.org @@ -55,8 +55,6 @@ def test_boxdimensions_dims(boxdimensions_universe): 111, 'abcd') ) - - def test_dimensions_vector(boxdimensions_universe, dim_vector): # wrong box dimension vector size ts = boxdimensions_universe.trajectory.ts From 7d0fed3496c334a9310a4737d20f35daae58a052 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 13:26:44 +0100 Subject: [PATCH 25/46] Update test_boxdimensions.py --- testsuite/MDAnalysisTests/transformations/test_boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index 91c8b79a4d2..8b162df60f4 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -59,7 +59,7 @@ def test_dimensions_vector(boxdimensions_universe, dim_vector): # wrong box dimension vector size ts = boxdimensions_universe.trajectory.ts with pytest.raises(ValueError): - detdimensions(dim_vector) + setdimensions(dim_vector) def test_dimensions_transformations_api(boxdimensions_universe): From 73d1a0be0e6b5c56e8c3537d04b346c972f8d877 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 13:33:27 +0100 Subject: [PATCH 26/46] Add boxdimensions.rst to documentation_pages --- .../documentation_pages/transformations/boxdimensions.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst diff --git a/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst b/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst new file mode 100644 index 00000000000..ac2e4417349 --- /dev/null +++ b/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst @@ -0,0 +1,2 @@ +.. automodule:: MDAnalysis.transformations.boxdimensions + From ffae4f4923ff82cdca03d67a6f046dd4a8d5bdaf Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 13:41:09 +0100 Subject: [PATCH 27/46] Update boxdimensions.rst --- .../source/documentation_pages/transformations/boxdimensions.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst b/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst index ac2e4417349..e40789ae657 100644 --- a/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst +++ b/package/doc/sphinx/source/documentation_pages/transformations/boxdimensions.rst @@ -1,2 +1 @@ .. automodule:: MDAnalysis.transformations.boxdimensions - From 6274d88d27cf2699d2a5260383cbd1386f8de193 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 17:33:18 +0100 Subject: [PATCH 28/46] Update boxdimensions.py --- package/MDAnalysis/transformations/boxdimensions.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 414be15965f..da68f9216d6 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -69,12 +69,13 @@ def __init__(self, dimensions): try: self.dimensions = np.asarray(self.dimensions, np.float32) except ValueError: - raise ValueError(f'{self.dimensions} are not valid box dimensions') + raise ValueError(f'{self.dimensions} cannot be converted into\ +np.float32 numpy.ndarray') try: self.dimensions = self.dimensions.reshape(6, ) except ValueError: - raise ValueError('Box dimensions array must be convertible into \ -shape (6, )') + raise ValueError(f'{self.dimensions} array does not have valid box\ +dimension shape') def __call__(self, ts): ts.dimensions = self.dimensions From a823c23e6afa29e60c0ec678b6a0abad2fccc374 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 17:36:35 +0100 Subject: [PATCH 29/46] Update test_boxdimensions.py --- .../transformations/test_boxdimensions.py | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index 8b162df60f4..14436ee9faf 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -44,22 +44,32 @@ def test_boxdimensions_dims(boxdimensions_universe): assert_array_almost_equal(new_dims, new.dimensions, decimal=6) -@pytest.mark.parametrize('dim_vector', ( +@pytest.mark.parametrize('dim_vector_shapes', ( [1, 1, 1, 90, 90], [1, 1, 1, 1, 90, 90, 90], - ['a', 'b', 'c', 'd', 'e', 'f'], + np.array([[1], [1], [90], [90], [90]]), np.array([1, 1, 1, 90, 90]), np.array([1, 1, 1, 1, 90, 90, 90]), - np.array([[1], [1], [90], [90], [90]]), + [1, 1, 1, 90, 90], + 111909090) + ) +def test_dimensions_vector(boxdimensions_universes, dim_vector_shapes): + # wrong box dimension vector shape + ts = boxdimensions_universes[0].trajectory.ts + with pytest.raises(ValueError, match='valid box dimension shape'): + setdimensions(dim_vector_shapes)(ts) + + +@pytest.mark.parametrize('dim_vector_forms_dtypes', ( + ['a', 'b', 'c', 'd', 'e', 'f'], np.array(['a', 'b', 'c', 'd', 'e', 'f']), - 111, 'abcd') -) -def test_dimensions_vector(boxdimensions_universe, dim_vector): - # wrong box dimension vector size - ts = boxdimensions_universe.trajectory.ts - with pytest.raises(ValueError): - setdimensions(dim_vector) + ) +def test_dimensions_vector_asarray(boxdimensions_universes, dim_vector_forms_dtypes): + # box dimension input type not convertible into array + ts = boxdimensions_universes[0].trajectory.ts + with pytest.raises(ValueError, match='cannot be converted'): + setdimensions(dim_vector_forms_dtypes)(ts) def test_dimensions_transformations_api(boxdimensions_universe): From d406e3cb006346d19a58849a2f7c90a4bec39d01 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 17:47:52 +0100 Subject: [PATCH 30/46] Update package/MDAnalysis/transformations/boxdimensions.py Co-authored-by: Irfan Alibay --- package/MDAnalysis/transformations/boxdimensions.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index da68f9216d6..f80d6c7e4f9 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -69,8 +69,9 @@ def __init__(self, dimensions): try: self.dimensions = np.asarray(self.dimensions, np.float32) except ValueError: - raise ValueError(f'{self.dimensions} cannot be converted into\ -np.float32 numpy.ndarray') + errmsg = (f"{self.dimensions} cannot be converted into " + "np.float32 numpy.ndarray") + raise ValueError(errmsg) try: self.dimensions = self.dimensions.reshape(6, ) except ValueError: From 53369ad4042692425e3fdbdc455b8e9a6ca9e7a9 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 17:51:44 +0100 Subject: [PATCH 31/46] Update test_boxdimensions.py --- .../MDAnalysisTests/transformations/test_boxdimensions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index 14436ee9faf..fd6b9576ab2 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -65,7 +65,8 @@ def test_dimensions_vector(boxdimensions_universes, dim_vector_shapes): np.array(['a', 'b', 'c', 'd', 'e', 'f']), 'abcd') ) -def test_dimensions_vector_asarray(boxdimensions_universes, dim_vector_forms_dtypes): +def test_dimensions_vector_asarray(boxdimensions_universes, + dim_vector_forms_dtypes): # box dimension input type not convertible into array ts = boxdimensions_universes[0].trajectory.ts with pytest.raises(ValueError, match='cannot be converted'): From f2cbf8fe95f71c2c3217057aded3ad8fc38647e1 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 17:58:13 +0100 Subject: [PATCH 32/46] Update boxdimensions.py --- package/MDAnalysis/transformations/boxdimensions.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index f80d6c7e4f9..9db44a31738 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -69,14 +69,15 @@ def __init__(self, dimensions): try: self.dimensions = np.asarray(self.dimensions, np.float32) except ValueError: - errmsg = (f"{self.dimensions} cannot be converted into " - "np.float32 numpy.ndarray") + errmsg = (f'{self.dimensions} cannot be converted into ' + 'np.float32 numpy.ndarray') raise ValueError(errmsg) try: self.dimensions = self.dimensions.reshape(6, ) except ValueError: - raise ValueError(f'{self.dimensions} array does not have valid box\ -dimension shape') + errmsg = (f'{self.dimensions} array does not have valid box ' + 'dimension shape') + raise ValueError(errmsg) def __call__(self, ts): ts.dimensions = self.dimensions From 2d908ae92028abbfc1bf94c9b467a8a2e1a5027f Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 22:07:58 +0100 Subject: [PATCH 33/46] Update package/MDAnalysis/transformations/boxdimensions.py Co-authored-by: Lily Wang <31115101+lilyminium@users.noreply.github.com> --- package/MDAnalysis/transformations/boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 9db44a31738..c45d1752d9b 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -54,7 +54,7 @@ class setdimensions: Parameters ---------- - dimensions: array-like + dimensions: iterable of floats vector that contains unit cell lengths and angles. Expected shapes are (6, 0) or (1, 6) From 669acf246e3c5a62361d096837c3bb9596845465 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 22:12:20 +0100 Subject: [PATCH 34/46] Update package/MDAnalysis/transformations/boxdimensions.py Co-authored-by: Lily Wang <31115101+lilyminium@users.noreply.github.com> --- package/MDAnalysis/transformations/boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index c45d1752d9b..e8acdb5b969 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -28,7 +28,7 @@ Set dimensions of the simulation box to a constant vector across all timesteps. -..autoclass:: setdimensions +.. autoclass:: setdimensions """ import numpy as np From 3c3e3501a568fbb0a05008823cc8bcd5b609cc12 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 22:22:24 +0100 Subject: [PATCH 35/46] Create boxdimensions.py --- package/MDAnalysis/transformations/boxdimensions.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index e8acdb5b969..d5810f55374 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -28,12 +28,12 @@ Set dimensions of the simulation box to a constant vector across all timesteps. -.. autoclass:: setdimensions +..autoclass:: set_dimensions """ import numpy as np -class setdimensions: +class set_dimensions: """ Set simulation box dimensions. @@ -49,7 +49,7 @@ class setdimensions: .. code-block:: python dim = [2, 2, 2, 90, 90, 90] - transform = mda.transformations.boxdimensions.setdimensions(dim) + transform = mda.transformations.boxdimensions.set_dimensions(dim) u.trajectory.add_transformations(transform) Parameters @@ -76,7 +76,10 @@ def __init__(self, dimensions): self.dimensions = self.dimensions.reshape(6, ) except ValueError: errmsg = (f'{self.dimensions} array does not have valid box ' - 'dimension shape') + 'dimension shape.\nSimulation box dimensions are ' + 'given by an float array of shape (6, ), ' + ' containing 3 lengths and 3 angles: ' + '[a, b, c, alpha, beta, gamma]' raise ValueError(errmsg) def __call__(self, ts): From d485bce45ce6d5d88fb075da16e5ae011c9a116e Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 22:25:00 +0100 Subject: [PATCH 36/46] Update __init__.py --- package/MDAnalysis/transformations/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/__init__.py b/package/MDAnalysis/transformations/__init__.py index f7b82555897..7fd56d2eab6 100644 --- a/package/MDAnalysis/transformations/__init__.py +++ b/package/MDAnalysis/transformations/__init__.py @@ -130,4 +130,4 @@ def wrapped(ts): from .positionaveraging import PositionAverager from .fit import fit_translation, fit_rot_trans from .wrap import wrap, unwrap -from .boxdimensions import setdimensions +from .boxdimensions import set_dimensions From 47b874f17a25aea9169b802c01cf3b8cff44264a Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 22:26:07 +0100 Subject: [PATCH 37/46] Update CHANGELOG --- package/CHANGELOG | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index db9879efc86..d6359f816ba 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -17,7 +17,7 @@ The rules for this file: lilyminium, daveminh, jbarnoud, yuxuanzhuang, VOD555, ianmkenney, calcraven,xiki-tempula, mieczyslaw, manuel.nuno.melo, PicoCentauri, hanatok, rmeli, aditya-kamath, tirkarthi, LeonardoBarneschi, hejamu, - biogen98 + biogen98, hp115 * 2.0.0 @@ -87,7 +87,7 @@ Fixes * Fix syntax warning over comparison of literals using is (Issue #3066) Enhancements - * Add `setdimensions` transformation class for setting constant + * Add `set_dimensions` transformation class for setting constant box dimensions for all timesteps in trajectory (Issue #2691) * Added a ValueError raised when not given a gridcenter while providing grid dimensions to DensityAnalysis, also added From fa1d031179f1b8a18d15358351201c7c4066224a Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 22:29:36 +0100 Subject: [PATCH 38/46] Update trajectory_transformations.rst --- .../source/documentation_pages/trajectory_transformations.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/package/doc/sphinx/source/documentation_pages/trajectory_transformations.rst b/package/doc/sphinx/source/documentation_pages/trajectory_transformations.rst index 9662f687442..4d885cb0c45 100644 --- a/package/doc/sphinx/source/documentation_pages/trajectory_transformations.rst +++ b/package/doc/sphinx/source/documentation_pages/trajectory_transformations.rst @@ -233,4 +233,5 @@ Currently implemented transformations ./transformations/positionaveraging ./transformations/fit ./transformations/wrap + ./transformations/boxdimensions From 3593369b433a59dc51a3c0298679eb034119fd22 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Mon, 5 Apr 2021 22:41:06 +0100 Subject: [PATCH 39/46] Update test_boxdimensions.py --- .../transformations/test_boxdimensions.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index fd6b9576ab2..0a45ed3c295 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -26,7 +26,7 @@ from numpy.testing import assert_array_almost_equal import MDAnalysis as mdanalysis -from MDAnalysis.transformations import setdimensions +from MDAnalysis.transformations import set_dimensions from MDAnalysisTests import make_Universe @@ -38,10 +38,9 @@ def boxdimensions_universe(): def test_boxdimensions_dims(boxdimensions_universe): - new_u = boxdimensions_universe new_dims = np.float32([2, 2, 2, 90, 90, 90]) - new = setdimensions(new_dims)(new_u.trajectory.ts) - assert_array_almost_equal(new_dims, new.dimensions, decimal=6) + new = set_dimensions(new_dims)(boxdimensions_universe.trajectory.ts) + assert_array_almost_equal(new.dimensions, new_dims, decimal=6) @pytest.mark.parametrize('dim_vector_shapes', ( @@ -53,11 +52,11 @@ def test_boxdimensions_dims(boxdimensions_universe): [1, 1, 1, 90, 90], 111909090) ) -def test_dimensions_vector(boxdimensions_universes, dim_vector_shapes): +def test_dimensions_vector(boxdimensions_universe, dim_vector_shapes): # wrong box dimension vector shape ts = boxdimensions_universes[0].trajectory.ts with pytest.raises(ValueError, match='valid box dimension shape'): - setdimensions(dim_vector_shapes)(ts) + set_dimensions(dim_vector_shapes)(ts) @pytest.mark.parametrize('dim_vector_forms_dtypes', ( @@ -65,19 +64,19 @@ def test_dimensions_vector(boxdimensions_universes, dim_vector_shapes): np.array(['a', 'b', 'c', 'd', 'e', 'f']), 'abcd') ) -def test_dimensions_vector_asarray(boxdimensions_universes, +def test_dimensions_vector_asarray(boxdimensions_universe, dim_vector_forms_dtypes): # box dimension input type not convertible into array ts = boxdimensions_universes[0].trajectory.ts with pytest.raises(ValueError, match='cannot be converted'): - setdimensions(dim_vector_forms_dtypes)(ts) + set_dimensions(dim_vector_forms_dtypes)(ts) def test_dimensions_transformations_api(boxdimensions_universe): # test if transformation works with on-the-fly transformations API - new_u = boxdimensions_universe new_dims = np.float32([2, 2, 2, 90, 90, 90]) - transform = setdimensions - new_u.trajectory.add_transformations(transform) + transform = set_dimensions(new_dims) + boxdimensions_universe.trajectory.add_transformations(transform) for ts in new_u.trajectory: - assert_array_almost_equal(new_dims, new_u.dimensions, decimal=6) + assert_array_almost_equal(boxdimensions_universe.dimensions, + new_dims, decimal=6) From 31d62028faf07ae70b6edcc90c402a0ac5f43c8c Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Tue, 6 Apr 2021 07:53:31 +0100 Subject: [PATCH 40/46] Update package/MDAnalysis/transformations/boxdimensions.py Co-authored-by: Lily Wang <31115101+lilyminium@users.noreply.github.com> --- package/MDAnalysis/transformations/boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index d5810f55374..2f8749b1ff0 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -79,7 +79,7 @@ def __init__(self, dimensions): 'dimension shape.\nSimulation box dimensions are ' 'given by an float array of shape (6, ), ' ' containing 3 lengths and 3 angles: ' - '[a, b, c, alpha, beta, gamma]' + '[a, b, c, alpha, beta, gamma]') raise ValueError(errmsg) def __call__(self, ts): From ab037d9b99218e08e3f49f54552756ebf4819e7c Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Tue, 6 Apr 2021 07:55:41 +0100 Subject: [PATCH 41/46] Update test_boxdimensions.py --- testsuite/MDAnalysisTests/transformations/test_boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index 0a45ed3c295..3bb49b41429 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -78,5 +78,5 @@ def test_dimensions_transformations_api(boxdimensions_universe): transform = set_dimensions(new_dims) boxdimensions_universe.trajectory.add_transformations(transform) for ts in new_u.trajectory: - assert_array_almost_equal(boxdimensions_universe.dimensions, + assert_array_almost_equal(boxdimensions_universe.dimensions, new_dims, decimal=6) From c8a0225078bd864ddfde879344c35ce979ee27be Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Tue, 6 Apr 2021 08:53:13 +0100 Subject: [PATCH 42/46] Update test_boxdimensions.py --- testsuite/MDAnalysisTests/transformations/test_boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index 3bb49b41429..bc82294c533 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -77,6 +77,6 @@ def test_dimensions_transformations_api(boxdimensions_universe): new_dims = np.float32([2, 2, 2, 90, 90, 90]) transform = set_dimensions(new_dims) boxdimensions_universe.trajectory.add_transformations(transform) - for ts in new_u.trajectory: + for ts in boxdimensions_universe.trajectory: assert_array_almost_equal(boxdimensions_universe.dimensions, new_dims, decimal=6) From aa75ced44fc7d2003ca42392f92d359c8fa9ef90 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Tue, 6 Apr 2021 09:22:52 +0100 Subject: [PATCH 43/46] Update test_boxdimensions.py --- .../transformations/test_boxdimensions.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py index bc82294c533..f85ee564a58 100644 --- a/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py +++ b/testsuite/MDAnalysisTests/transformations/test_boxdimensions.py @@ -39,8 +39,9 @@ def boxdimensions_universe(): def test_boxdimensions_dims(boxdimensions_universe): new_dims = np.float32([2, 2, 2, 90, 90, 90]) - new = set_dimensions(new_dims)(boxdimensions_universe.trajectory.ts) - assert_array_almost_equal(new.dimensions, new_dims, decimal=6) + set_dimensions(new_dims)(boxdimensions_universe.trajectory.ts) + assert_array_almost_equal(boxdimensions_universe.dimensions, + new_dims, decimal=6) @pytest.mark.parametrize('dim_vector_shapes', ( @@ -54,7 +55,7 @@ def test_boxdimensions_dims(boxdimensions_universe): ) def test_dimensions_vector(boxdimensions_universe, dim_vector_shapes): # wrong box dimension vector shape - ts = boxdimensions_universes[0].trajectory.ts + ts = boxdimensions_universe.trajectory.ts with pytest.raises(ValueError, match='valid box dimension shape'): set_dimensions(dim_vector_shapes)(ts) @@ -67,7 +68,7 @@ def test_dimensions_vector(boxdimensions_universe, dim_vector_shapes): def test_dimensions_vector_asarray(boxdimensions_universe, dim_vector_forms_dtypes): # box dimension input type not convertible into array - ts = boxdimensions_universes[0].trajectory.ts + ts = boxdimensions_universe.trajectory.ts with pytest.raises(ValueError, match='cannot be converted'): set_dimensions(dim_vector_forms_dtypes)(ts) From 6eb75b45e6058f74f40a8d4cb6f63735fad07ef6 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Tue, 6 Apr 2021 15:02:12 +0100 Subject: [PATCH 44/46] Update package/MDAnalysis/transformations/boxdimensions.py Co-authored-by: Lily Wang <31115101+lilyminium@users.noreply.github.com> --- package/MDAnalysis/transformations/boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 2f8749b1ff0..42b66372f28 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -22,7 +22,7 @@ # """\ -Set box dimensions --- :mod: `MDAnalysis.transformations.boxdimensions` +Set box dimensions --- :mod:`MDAnalysis.transformations.boxdimensions` ======================================================================= Set dimensions of the simulation box to a constant vector across all timesteps. From a3bfd0d126d0ae84bba977665d307f39d8f9fdf7 Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Tue, 6 Apr 2021 15:02:27 +0100 Subject: [PATCH 45/46] Update package/MDAnalysis/transformations/boxdimensions.py Co-authored-by: Lily Wang <31115101+lilyminium@users.noreply.github.com> --- package/MDAnalysis/transformations/boxdimensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/transformations/boxdimensions.py b/package/MDAnalysis/transformations/boxdimensions.py index 42b66372f28..5a6569caa90 100644 --- a/package/MDAnalysis/transformations/boxdimensions.py +++ b/package/MDAnalysis/transformations/boxdimensions.py @@ -28,7 +28,7 @@ Set dimensions of the simulation box to a constant vector across all timesteps. -..autoclass:: set_dimensions +.. autoclass:: set_dimensions """ import numpy as np From c50c6044b2ec21985b518d4d13b745bdc6fd9e1d Mon Sep 17 00:00:00 2001 From: hp115 <77673542+hp115@users.noreply.github.com> Date: Tue, 6 Apr 2021 15:09:34 +0100 Subject: [PATCH 46/46] Update AUTHORS --- package/AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/package/AUTHORS b/package/AUTHORS index 00076883aa4..a69d977da5b 100644 --- a/package/AUTHORS +++ b/package/AUTHORS @@ -158,6 +158,7 @@ Chronological list of authors - Henrik Jäger - Jan Stevens - Orion Cohen + - Hannah Pollak External code -------------