diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 5c1f33a305..a5d8b56016 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -41,3 +41,5 @@ c08cb797fd1a2cb45bc0b9e4522cabb15d1f36bd b8fe34b73c9df9330c1608229b2f8cddc6e275b4 #4885 263bbe65047e535fbad981852ad9c7327826f93d +#5446 +a6566f8a86eb3a74521ce7fc3658527224a02fd3 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..c68ab10b86 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# Ensure all line endings for text files are LF (UNIX, Python default) and not CRLF (Windows/DOS default) +* text=auto eol=lf + +# ignore all data files from testsuite/MDAnalysisTests/data/ +testsuite/MDAnalysisTests/data/* -text +testsuite/MDAnalysisTests/data/**/* -text diff --git a/benchmarks/benchmarks/topology.py b/benchmarks/benchmarks/topology.py index 661eeab958..af0c487f0d 100644 --- a/benchmarks/benchmarks/topology.py +++ b/benchmarks/benchmarks/topology.py @@ -1,47 +1,47 @@ -import MDAnalysis -import numpy as np -from MDAnalysis.guesser import DefaultGuesser - -try: - from MDAnalysis.exceptions import NoDataError - from MDAnalysisTests.datafiles import GRO -except: - pass - - -class TopologyGuessBench(object): - """Benchmarks for individual - topology functions - """ - - params = (10, 100, 1000, 10000) - param_names = ["num_atoms"] - - def setup(self, num_atoms): - self.u = MDAnalysis.Universe(GRO) - self.ag = self.u.atoms[:num_atoms] - self.vdwradii = {"H": 1.0, "C": 1.0, "N": 1.0, "O": 1.0, "DUMMY": 1.0} - - def time_guessbonds(self, num_atoms): - """Benchmark for guessing bonds""" - DefaultGuesser(None).guess_bonds( - self.ag, self.ag.positions, box=self.ag.dimensions, vdwradii=self.vdwradii - ) - - -class BondsBench(object): - """ - Benchmarks for getting bonds - """ - - params = (1000, 10000, 100000, 1000000) - param_names = ["num_bonds"] - - def setup(self, num_bonds): - self.u = MDAnalysis.Universe.empty(2 * num_bonds) - bonds = np.arange(2 * num_bonds).reshape(num_bonds, 2) - self.u.add_bonds(bonds) - - def time_bonds(self, num_bonds): - """Benchmark for calculating bonds""" - self.u.bonds +import MDAnalysis +import numpy as np +from MDAnalysis.guesser import DefaultGuesser + +try: + from MDAnalysis.exceptions import NoDataError + from MDAnalysisTests.datafiles import GRO +except: + pass + + +class TopologyGuessBench(object): + """Benchmarks for individual + topology functions + """ + + params = (10, 100, 1000, 10000) + param_names = ["num_atoms"] + + def setup(self, num_atoms): + self.u = MDAnalysis.Universe(GRO) + self.ag = self.u.atoms[:num_atoms] + self.vdwradii = {"H": 1.0, "C": 1.0, "N": 1.0, "O": 1.0, "DUMMY": 1.0} + + def time_guessbonds(self, num_atoms): + """Benchmark for guessing bonds""" + DefaultGuesser(None).guess_bonds( + self.ag, self.ag.positions, box=self.ag.dimensions, vdwradii=self.vdwradii + ) + + +class BondsBench(object): + """ + Benchmarks for getting bonds + """ + + params = (1000, 10000, 100000, 1000000) + param_names = ["num_bonds"] + + def setup(self, num_bonds): + self.u = MDAnalysis.Universe.empty(2 * num_bonds) + bonds = np.arange(2 * num_bonds).reshape(num_bonds, 2) + self.u.add_bonds(bonds) + + def time_bonds(self, num_bonds): + """Benchmark for calculating bonds""" + self.u.bonds diff --git a/mypy.ini b/mypy.ini index d87115bc20..890df75ba1 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,46 +1,46 @@ -[mypy] -ignore_missing_imports = True -exclude = doc/sphinx/source/ - - -[mypy-MDAnalysis.analysis.*] -ignore_errors = True - -[mypy-MDAnalysis.auxiliary.*] -ignore_errors = True - -[mypy-MDAnalysis.converters.*] -ignore_errors = True - -[mypy-MDAnalysis.coordinates.*] -ignore_errors = True - -[mypy-MDAnalysis.core.*] -ignore_errors = True - -[mypy-MDAnalysis.selections.*] -ignore_errors = True - -[mypy-MDAnalysis.tests.*] -ignore_errors = True - -[mypy-MDAnalysis.topology.*] -ignore_errors = True - -[mypy-MDAnalysis.transformations.*] -ignore_errors = True - -[mypy-MDAnalysis.visualization.*] -ignore_errors = True - -[mypy-MDAnalysis.due] -ignore_errors = True - -[mypy-MDAnalysis.exceptions] -ignore_errors = True - -[mypy-MDAnalysis.units] -ignore_errors = True - -[mypy-MDAnalysis.version] -ignore_errors = True +[mypy] +ignore_missing_imports = True +exclude = doc/sphinx/source/ + + +[mypy-MDAnalysis.analysis.*] +ignore_errors = True + +[mypy-MDAnalysis.auxiliary.*] +ignore_errors = True + +[mypy-MDAnalysis.converters.*] +ignore_errors = True + +[mypy-MDAnalysis.coordinates.*] +ignore_errors = True + +[mypy-MDAnalysis.core.*] +ignore_errors = True + +[mypy-MDAnalysis.selections.*] +ignore_errors = True + +[mypy-MDAnalysis.tests.*] +ignore_errors = True + +[mypy-MDAnalysis.topology.*] +ignore_errors = True + +[mypy-MDAnalysis.transformations.*] +ignore_errors = True + +[mypy-MDAnalysis.visualization.*] +ignore_errors = True + +[mypy-MDAnalysis.due] +ignore_errors = True + +[mypy-MDAnalysis.exceptions] +ignore_errors = True + +[mypy-MDAnalysis.units] +ignore_errors = True + +[mypy-MDAnalysis.version] +ignore_errors = True diff --git a/mypy_requirements.txt b/mypy_requirements.txt index b28138e238..2c12274b33 100644 --- a/mypy_requirements.txt +++ b/mypy_requirements.txt @@ -1,2 +1,2 @@ -mypy==0.960 +mypy==0.960 typing_extensions \ No newline at end of file diff --git a/package/CHANGELOG b/package/CHANGELOG index 7141141487..8b35c05178 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -23,6 +23,8 @@ The rules for this file: * 2.11.0 Fixes + * Added `.gitattributes` to enforce LF (\n) as line endings and renormalized + existing files to conform (Issue #5315, PR #5446) * Fix FileLock tests for XTC and TRR: lock file is no longer removed (#5382) * InterRDF now correctly returns bins in parallel (PR #5344) * `Merge()` no longer raises a TypeError on Universes that have a `cmaps` diff --git a/package/MDAnalysis/coordinates/NAMDBIN.py b/package/MDAnalysis/coordinates/NAMDBIN.py index 834ea346ae..c5a05b4948 100644 --- a/package/MDAnalysis/coordinates/NAMDBIN.py +++ b/package/MDAnalysis/coordinates/NAMDBIN.py @@ -1,151 +1,151 @@ -# -*- 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 Lesser GNU Public Licence, v2.1 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 -# - - -"""NAMDBIN files format --- :mod:`MDAnalysis.coordinates.NAMDBIN` -================================================================================ - -Read/Write coordinates in `NAMD double-precision binary format`_ (suffix "coor" or "namdbin"). - -.. _`NAMD double-precision binary format` : https://www.ks.uiuc.edu/Research/namd/2.10/ug/node11.html#SECTION00061500000000000000 - - -Classes -------- - -.. autoclass:: NAMDBINReader - :members: - -.. autoclass:: NAMDBINWriter - :members: - -""" -from struct import pack -import numpy as np - -from . import base -from ..lib import util - - -class NAMDBINReader(base.SingleFrameReaderBase): - """Reader for NAMD binary coordinate files. - - - .. versionadded:: 1.0.0 - """ - - format = ["COOR", "NAMDBIN"] - units = {"length": "Angstrom"} - - def _read_first_frame(self): - # Read header - with open(self.filename, "rb") as namdbin: - self.n_atoms = np.fromfile(namdbin, dtype=np.int32, count=1)[0] - self.ts = self._Timestep(self.n_atoms, **self._ts_kwargs) - self.ts.frame = 0 - coord_double = np.fromfile( - namdbin, dtype=np.float64, count=self.n_atoms * 3 - ) - self.ts._pos[:] = np.array(coord_double, float).reshape( - self.n_atoms, 3 - ) - - @staticmethod - def parse_n_atoms(filename, **kwargs): - with open(filename, "rb") as namdbin: - n_atoms = np.fromfile(namdbin, dtype=np.int32, count=1)[0] - return n_atoms - - def Writer(self, filename, **kwargs): - """Returns a NAMDBINWriter for *filename*. - - Parameters - ---------- - filename: str - filename of the output NAMDBIN file - - Returns - ------- - :class:`NAMDBINWriter` - - """ - return NAMDBINWriter(filename, **kwargs) - - -class NAMDBINWriter(base.WriterBase): - """Writer for NAMD binary coordinate files. - - - Note - ---- - * Does not handle writing to bz2 or gz compressed file types. - - - .. versionadded:: 1.0.0 - """ - - format = ["COOR", "NAMDBIN"] - units = {"time": None, "length": "Angstrom"} - - def __init__(self, filename, n_atoms=None, **kwargs): - """ - Parameters - ---------- - filename : str or :class:`~MDAnalysis.lib.util.NamedStream` - name of the output file or a stream - n_atoms : int - number of atoms for the output coordinate - """ - self.filename = util.filename(filename) - - def _write_next_frame(self, obj): - """Write information associated with ``obj`` at current frame into - trajectory - - - Parameters - ---------- - obj : :class:`~MDAnalysis.core.groups.AtomGroup` or - :class:`~MDAnalysis.core.universe.Universe` - write coordinate information associated with `obj` - - - .. versionchanged:: 1.0.0 - Renamed from `write` to `_write_next_frame`. - .. versionchanged:: 2.0.0 - Deprecated support for Timestep argument has now been removed. - Use AtomGroup or Universe as an input instead. - """ - if hasattr(obj, "atoms"): # AtomGroup or Universe - atoms = obj.atoms - n_atoms = len(atoms) - coor = atoms.positions.reshape(n_atoms * 3) - else: - errmsg = "Input obj is neither an AtomGroup or Universe" - raise TypeError(errmsg) from None - - with util.openany(self.filename, "wb") as namdbin: - # Write NUMATOMS - namdbin.write(pack("i", n_atoms)) - # Write Coordinate - namdbin.write(pack("{:d}d".format(len(coor)), *coor)) +# -*- 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 Lesser GNU Public Licence, v2.1 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 +# + + +"""NAMDBIN files format --- :mod:`MDAnalysis.coordinates.NAMDBIN` +================================================================================ + +Read/Write coordinates in `NAMD double-precision binary format`_ (suffix "coor" or "namdbin"). + +.. _`NAMD double-precision binary format` : https://www.ks.uiuc.edu/Research/namd/2.10/ug/node11.html#SECTION00061500000000000000 + + +Classes +------- + +.. autoclass:: NAMDBINReader + :members: + +.. autoclass:: NAMDBINWriter + :members: + +""" +from struct import pack +import numpy as np + +from . import base +from ..lib import util + + +class NAMDBINReader(base.SingleFrameReaderBase): + """Reader for NAMD binary coordinate files. + + + .. versionadded:: 1.0.0 + """ + + format = ["COOR", "NAMDBIN"] + units = {"length": "Angstrom"} + + def _read_first_frame(self): + # Read header + with open(self.filename, "rb") as namdbin: + self.n_atoms = np.fromfile(namdbin, dtype=np.int32, count=1)[0] + self.ts = self._Timestep(self.n_atoms, **self._ts_kwargs) + self.ts.frame = 0 + coord_double = np.fromfile( + namdbin, dtype=np.float64, count=self.n_atoms * 3 + ) + self.ts._pos[:] = np.array(coord_double, float).reshape( + self.n_atoms, 3 + ) + + @staticmethod + def parse_n_atoms(filename, **kwargs): + with open(filename, "rb") as namdbin: + n_atoms = np.fromfile(namdbin, dtype=np.int32, count=1)[0] + return n_atoms + + def Writer(self, filename, **kwargs): + """Returns a NAMDBINWriter for *filename*. + + Parameters + ---------- + filename: str + filename of the output NAMDBIN file + + Returns + ------- + :class:`NAMDBINWriter` + + """ + return NAMDBINWriter(filename, **kwargs) + + +class NAMDBINWriter(base.WriterBase): + """Writer for NAMD binary coordinate files. + + + Note + ---- + * Does not handle writing to bz2 or gz compressed file types. + + + .. versionadded:: 1.0.0 + """ + + format = ["COOR", "NAMDBIN"] + units = {"time": None, "length": "Angstrom"} + + def __init__(self, filename, n_atoms=None, **kwargs): + """ + Parameters + ---------- + filename : str or :class:`~MDAnalysis.lib.util.NamedStream` + name of the output file or a stream + n_atoms : int + number of atoms for the output coordinate + """ + self.filename = util.filename(filename) + + def _write_next_frame(self, obj): + """Write information associated with ``obj`` at current frame into + trajectory + + + Parameters + ---------- + obj : :class:`~MDAnalysis.core.groups.AtomGroup` or + :class:`~MDAnalysis.core.universe.Universe` + write coordinate information associated with `obj` + + + .. versionchanged:: 1.0.0 + Renamed from `write` to `_write_next_frame`. + .. versionchanged:: 2.0.0 + Deprecated support for Timestep argument has now been removed. + Use AtomGroup or Universe as an input instead. + """ + if hasattr(obj, "atoms"): # AtomGroup or Universe + atoms = obj.atoms + n_atoms = len(atoms) + coor = atoms.positions.reshape(n_atoms * 3) + else: + errmsg = "Input obj is neither an AtomGroup or Universe" + raise TypeError(errmsg) from None + + with util.openany(self.filename, "wb") as namdbin: + # Write NUMATOMS + namdbin.write(pack("i", n_atoms)) + # Write Coordinate + namdbin.write(pack("{:d}d".format(len(coor)), *coor)) diff --git a/package/MDAnalysis/lib/_cutil.pxd b/package/MDAnalysis/lib/_cutil.pxd index 5efc82f6d5..6abd270903 100644 --- a/package/MDAnalysis/lib/_cutil.pxd +++ b/package/MDAnalysis/lib/_cutil.pxd @@ -1,3 +1,3 @@ -cdef float _dot(float *, float *) -cdef void _cross(float *, float *, float *) +cdef float _dot(float *, float *) +cdef void _cross(float *, float *, float *) cdef float _norm(float *) \ No newline at end of file diff --git a/testsuite/MDAnalysisTests/lib/test_augment.py b/testsuite/MDAnalysisTests/lib/test_augment.py index 455e890251..226163f93c 100644 --- a/testsuite/MDAnalysisTests/lib/test_augment.py +++ b/testsuite/MDAnalysisTests/lib/test_augment.py @@ -1,148 +1,148 @@ -# -*- 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 Lesser GNU Public Licence, v2.1 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 os - -import numpy as np -import pytest -from MDAnalysis.lib._augment import augment_coordinates, undo_augment -from MDAnalysis.lib.distances import apply_PBC, transform_StoR -from numpy.testing import assert_almost_equal, assert_equal - -# Find images for several query points, -# here in fractional coordinates -# Every element of qres tuple is (query, images) -qres = ( - ([0.1, 0.5, 0.5], [[1.1, 0.5, 0.5]]), # box face - ([0.5, 0.5, 0.5], []), # box center - ([0.5, -0.1, 0.5], [[0.5, -0.1, 0.5]]), # box face - ( - [0.1, 0.1, 0.5], - [ - [1.1, 0.1, 0.5], - [0.1, 1.1, 0.5], - [1.1, 1.1, 0.5], - ], - ), # box edge - ( - [0.5, -0.1, 1.1], - [ - [0.5, -0.1, 0.1], - [0.5, 0.9, 1.1], - [0.5, -0.1, 1.1], - ], - ), # box edge - ( - [0.1, 0.1, 0.1], - [ - [1.1, 0.1, 0.1], - [0.1, 1.1, 0.1], - [0.1, 0.1, 1.1], - [0.1, 1.1, 1.1], - [1.1, 1.1, 0.1], - [1.1, 0.1, 1.1], - [1.1, 1.1, 1.1], - ], - ), # box vertex - ( - [0.1, -0.1, 1.1], - [ - [1.1, 0.9, 0.1], - [0.1, -0.1, 0.1], - [0.1, 0.9, 1.1], - [0.1, -0.1, 1.1], - [1.1, -0.1, 0.1], - [1.1, 0.9, 1.1], - [1.1, -0.1, 1.1], - ], - ), # box vertex - ( - [2.1, -3.1, 0.1], - [ - [1.1, 0.9, 0.1], - [0.1, -0.1, 0.1], - [0.1, 0.9, 1.1], - [0.1, -0.1, 1.1], - [1.1, -0.1, 0.1], - [1.1, 0.9, 1.1], - [1.1, -0.1, 1.1], - ], - ), # box vertex - ( - [ - [0.1, 0.5, 0.5], - [0.5, -0.1, 0.5], - ], - [ - [1.1, 0.5, 0.5], - [0.5, -0.1, 0.5], - ], - ), # multiple queries -) - - -@pytest.mark.xfail(os.name == "nt", reason="see gh-3248") -@pytest.mark.parametrize( - "b", - ( - np.array([10, 10, 10, 90, 90, 90], dtype=np.float32), - np.array([10, 10, 10, 45, 60, 90], dtype=np.float32), - ), -) -@pytest.mark.parametrize("q, res", qres) -def test_augment(b, q, res): - radius = 1.5 - q = transform_StoR(np.array(q, dtype=np.float32), b) - if q.shape == (3,): - q = q.reshape((1, 3)) - q = apply_PBC(q, b) - aug, mapping = augment_coordinates(q, b, radius) - if aug.size > 0: - aug = np.sort(aug, axis=0) - else: - aug = list() - if len(res) > 0: - cs = transform_StoR(np.array(res, dtype=np.float32), b) - cs = np.sort(cs, axis=0) - else: - cs = list() - assert_almost_equal(aug, cs, decimal=5) - - -@pytest.mark.parametrize( - "b", - ( - np.array([10, 10, 10, 90, 90, 90], dtype=np.float32), - np.array([10, 10, 10, 45, 60, 90], dtype=np.float32), - ), -) -@pytest.mark.parametrize("qres", qres) -def test_undoaugment(b, qres): - radius = 1.5 - q = transform_StoR(np.array(qres[0], dtype=np.float32), b) - if q.shape == (3,): - q = q.reshape((1, 3)) - q = apply_PBC(q, b) - aug, mapping = augment_coordinates(q, b, radius) - for idx, val in enumerate(aug): - imageid = np.asarray([len(q) + idx], dtype=np.intp) - assert_equal(mapping[idx], undo_augment(imageid, mapping, len(q))[0]) +# -*- 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 Lesser GNU Public Licence, v2.1 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 os + +import numpy as np +import pytest +from MDAnalysis.lib._augment import augment_coordinates, undo_augment +from MDAnalysis.lib.distances import apply_PBC, transform_StoR +from numpy.testing import assert_almost_equal, assert_equal + +# Find images for several query points, +# here in fractional coordinates +# Every element of qres tuple is (query, images) +qres = ( + ([0.1, 0.5, 0.5], [[1.1, 0.5, 0.5]]), # box face + ([0.5, 0.5, 0.5], []), # box center + ([0.5, -0.1, 0.5], [[0.5, -0.1, 0.5]]), # box face + ( + [0.1, 0.1, 0.5], + [ + [1.1, 0.1, 0.5], + [0.1, 1.1, 0.5], + [1.1, 1.1, 0.5], + ], + ), # box edge + ( + [0.5, -0.1, 1.1], + [ + [0.5, -0.1, 0.1], + [0.5, 0.9, 1.1], + [0.5, -0.1, 1.1], + ], + ), # box edge + ( + [0.1, 0.1, 0.1], + [ + [1.1, 0.1, 0.1], + [0.1, 1.1, 0.1], + [0.1, 0.1, 1.1], + [0.1, 1.1, 1.1], + [1.1, 1.1, 0.1], + [1.1, 0.1, 1.1], + [1.1, 1.1, 1.1], + ], + ), # box vertex + ( + [0.1, -0.1, 1.1], + [ + [1.1, 0.9, 0.1], + [0.1, -0.1, 0.1], + [0.1, 0.9, 1.1], + [0.1, -0.1, 1.1], + [1.1, -0.1, 0.1], + [1.1, 0.9, 1.1], + [1.1, -0.1, 1.1], + ], + ), # box vertex + ( + [2.1, -3.1, 0.1], + [ + [1.1, 0.9, 0.1], + [0.1, -0.1, 0.1], + [0.1, 0.9, 1.1], + [0.1, -0.1, 1.1], + [1.1, -0.1, 0.1], + [1.1, 0.9, 1.1], + [1.1, -0.1, 1.1], + ], + ), # box vertex + ( + [ + [0.1, 0.5, 0.5], + [0.5, -0.1, 0.5], + ], + [ + [1.1, 0.5, 0.5], + [0.5, -0.1, 0.5], + ], + ), # multiple queries +) + + +@pytest.mark.xfail(os.name == "nt", reason="see gh-3248") +@pytest.mark.parametrize( + "b", + ( + np.array([10, 10, 10, 90, 90, 90], dtype=np.float32), + np.array([10, 10, 10, 45, 60, 90], dtype=np.float32), + ), +) +@pytest.mark.parametrize("q, res", qres) +def test_augment(b, q, res): + radius = 1.5 + q = transform_StoR(np.array(q, dtype=np.float32), b) + if q.shape == (3,): + q = q.reshape((1, 3)) + q = apply_PBC(q, b) + aug, mapping = augment_coordinates(q, b, radius) + if aug.size > 0: + aug = np.sort(aug, axis=0) + else: + aug = list() + if len(res) > 0: + cs = transform_StoR(np.array(res, dtype=np.float32), b) + cs = np.sort(cs, axis=0) + else: + cs = list() + assert_almost_equal(aug, cs, decimal=5) + + +@pytest.mark.parametrize( + "b", + ( + np.array([10, 10, 10, 90, 90, 90], dtype=np.float32), + np.array([10, 10, 10, 45, 60, 90], dtype=np.float32), + ), +) +@pytest.mark.parametrize("qres", qres) +def test_undoaugment(b, qres): + radius = 1.5 + q = transform_StoR(np.array(qres[0], dtype=np.float32), b) + if q.shape == (3,): + q = q.reshape((1, 3)) + q = apply_PBC(q, b) + aug, mapping = augment_coordinates(q, b, radius) + for idx, val in enumerate(aug): + imageid = np.asarray([len(q) + idx], dtype=np.intp) + assert_equal(mapping[idx], undo_augment(imageid, mapping, len(q))[0]) diff --git a/testsuite/MDAnalysisTests/lib/test_log.py b/testsuite/MDAnalysisTests/lib/test_log.py index 541660ca4c..b936dbdf24 100644 --- a/testsuite/MDAnalysisTests/lib/test_log.py +++ b/testsuite/MDAnalysisTests/lib/test_log.py @@ -1,53 +1,53 @@ -# -*- 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 Lesser GNU Public Licence, v2.1 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 warnings -import pytest - -from MDAnalysis.lib.log import ProgressBar - - -class TestProgressBar(object): - - def test_output(self, capsys): - for i in ProgressBar(list(range(10))): - pass - out, err = capsys.readouterr() - expected = "100%|██████████" - actual = err.strip().split("\r")[-1] - assert actual[:15] == expected - - def test_disable(self, capsys): - for i in ProgressBar(list(range(10)), disable=True): - pass - out, err = capsys.readouterr() - expected = "" - actual = err.strip().split("\r")[-1] - assert actual == expected - - def test_verbose_disable(self, capsys): - for i in ProgressBar(list(range(10)), verbose=False): - pass - out, err = capsys.readouterr() - expected = "" - actual = err.strip().split("\r")[-1] - assert actual == expected +# -*- 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 Lesser GNU Public Licence, v2.1 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 warnings +import pytest + +from MDAnalysis.lib.log import ProgressBar + + +class TestProgressBar(object): + + def test_output(self, capsys): + for i in ProgressBar(list(range(10))): + pass + out, err = capsys.readouterr() + expected = "100%|██████████" + actual = err.strip().split("\r")[-1] + assert actual[:15] == expected + + def test_disable(self, capsys): + for i in ProgressBar(list(range(10)), disable=True): + pass + out, err = capsys.readouterr() + expected = "" + actual = err.strip().split("\r")[-1] + assert actual == expected + + def test_verbose_disable(self, capsys): + for i in ProgressBar(list(range(10)), verbose=False): + pass + out, err = capsys.readouterr() + expected = "" + actual = err.strip().split("\r")[-1] + assert actual == expected