From d439ae74a1c31cc04f521e196e0d0cf21d181bd6 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 6 Oct 2020 00:03:45 -0500 Subject: [PATCH 1/9] Use intersphinx reference to MDAnalysis stable. --- doc/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index c32ea2825..93f0bdb4d 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -310,7 +310,7 @@ 'hoomd': ('https://hoomd-blue.readthedocs.io/en/stable/', None), 'gsd': ('https://gsd.readthedocs.io/en/stable/', None), 'garnett': ('https://garnett.readthedocs.io/en/stable/', None), - 'MDAnalysis': ('https://docs.mdanalysis.org/1.0.0', None), + 'MDAnalysis': ('https://docs.mdanalysis.org/stable', None), 'ovito': ('https://www.ovito.org/docs/current/python/', None), } From 839b53e947cd940628ca2fc46bac5cceb61b199a Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 6 Oct 2020 19:28:29 -0500 Subject: [PATCH 2/9] Throw invalid_argument in constructor instead of runtime_error. --- cpp/locality/NeighborList.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/locality/NeighborList.cc b/cpp/locality/NeighborList.cc index 327e2747f..9b861ac39 100644 --- a/cpp/locality/NeighborList.cc +++ b/cpp/locality/NeighborList.cc @@ -34,12 +34,12 @@ NeighborList::NeighborList(unsigned int num_bonds, const unsigned int* query_poi { index = query_point_index[i]; if (index < last_index) - throw std::runtime_error("NeighborList query_point_index must be sorted."); + throw std::invalid_argument("NeighborList query_point_index must be sorted."); if (index >= m_num_query_points) - throw std::runtime_error( + throw std::invalid_argument( "NeighborList query_point_index values must be less than num_query_points."); if (point_index[i] >= m_num_points) - throw std::runtime_error("NeighborList point_index values must be less than num_points."); + throw std::invalid_argument("NeighborList point_index values must be less than num_points."); m_neighbors(i, 0) = index; m_neighbors(i, 1) = point_index[i]; m_weights[i] = weights[i]; From 9c49a804da22390abc0c5eadd7aeb1e114f692da Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 6 Oct 2020 19:28:42 -0500 Subject: [PATCH 3/9] Add num_query_points and num_points properties to nlist. --- freud/locality.pyx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/freud/locality.pyx b/freud/locality.pyx index 40bc9e637..bad7768fb 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -639,6 +639,23 @@ cdef class NeighborList: R"""Returns the number of bonds stored in this object.""" return self.thisptr.getNumBonds() + @property + def num_query_points(self): + """Returns the number of query points. + + All query point indices must be less than this value. + """ + + return self.thisptr.getNumQueryPoints() + + @property + def num_points(self): + """Returns the number of points. + + All point indices are less than this value. + """ + return self.thisptr.getNumPoints() + def find_first_index(self, unsigned int i): R"""Returns the lowest bond index corresponding to a query particle with an index :math:`\geq i`. From da45c43772526b4cf303eeb2d68a01e5c064c127 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 6 Oct 2020 19:50:49 -0500 Subject: [PATCH 4/9] Catch ValueError in tests. --- tests/test_locality_NeighborList.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_locality_NeighborList.py b/tests/test_locality_NeighborList.py index fa693a072..599303e84 100644 --- a/tests/test_locality_NeighborList.py +++ b/tests/test_locality_NeighborList.py @@ -151,17 +151,17 @@ def test_from_arrays(self): npt.assert_equal(nlist.segments, nlist2.segments) # too few reference particles - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): freud.locality.NeighborList.from_arrays( 3, 4, query_point_indices, point_indices, distances) # too few target particles - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): freud.locality.NeighborList.from_arrays( 4, 3, query_point_indices, point_indices, distances) # query particles not sorted - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): freud.locality.NeighborList.from_arrays( 4, 4, point_indices, query_point_indices, distances) From 88c90f9984af186367f84d55ebf5dcd7a64c867e Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 6 Oct 2020 19:51:04 -0500 Subject: [PATCH 5/9] Add test for num_query_points and num_points. --- tests/test_locality_NeighborList.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_locality_NeighborList.py b/tests/test_locality_NeighborList.py index 599303e84..74ffa1ae1 100644 --- a/tests/test_locality_NeighborList.py +++ b/tests/test_locality_NeighborList.py @@ -249,6 +249,23 @@ def test_ordering_distance(self): self.assertEqual(tuples, sorted_tuples) + def test_num_points(self): + query_point_indices = [0, 0, 1, 2, 3] + point_indices = [1, 2, 3, 0, 0] + distances = np.ones(len(query_point_indices)) + + # test num_query_points and num_points when built from arrays + nlist = freud.locality.NeighborList.from_arrays( + 42, 99, query_point_indices, point_indices, distances) + self.assertEqual(nlist.num_query_points, 42) + self.assertEqual(nlist.num_points, 99) + + # test num_query_points and num_points when built from a query + nlist = self.nq.query(self.nq.points[:-1], + self.query_args).toNeighborList() + self.assertEqual(nlist.num_query_points, len(self.nq.points)-1) + self.assertEqual(nlist.num_points, len(self.nq.points)) + if __name__ == '__main__': unittest.main() From c41c8930fca848193daf1b1a65f2d2c0bf2aebbb Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 6 Oct 2020 20:05:30 -0500 Subject: [PATCH 6/9] Update changelog/credits. --- ChangeLog.md | 4 ++++ doc/source/reference/credits.rst | 1 + 2 files changed, 5 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 796addbd9..1ec783c47 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -8,6 +8,10 @@ and this project adheres to ### Added * The Box class has a method `contains` to determine particle membership in a box. +* NeighborList class exposes `num_points` and `num_query_points` attributes. + +### Changed +* NeighborList raises a `ValueError` instead of a `RuntimeError` if provided invalid constructor arguments. ### Fixed * Source distributions now include Cython source files. diff --git a/doc/source/reference/credits.rst b/doc/source/reference/credits.rst index 4740d3612..f37af1b05 100644 --- a/doc/source/reference/credits.rst +++ b/doc/source/reference/credits.rst @@ -107,6 +107,7 @@ Bradley Dice - **Lead developer** * Fixed GaussianDensity normalization in 2D systems. * Prevented GaussianDensity from computing 3D systems after it has computed 2D systems. * Contributed code, design, and testing for ``DiffractionPattern`` class. +* Added ``num_query_points`` and ``num_points`` attributes to NeighborList class. Eric Harper, University of Michigan - **Former lead developer** From 79d46727b828325379e064676bda88b77500c661 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 6 Oct 2020 20:06:56 -0500 Subject: [PATCH 7/9] Remove extra newline. --- freud/locality.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/freud/locality.pyx b/freud/locality.pyx index bad7768fb..08425ebec 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -645,7 +645,6 @@ cdef class NeighborList: All query point indices must be less than this value. """ - return self.thisptr.getNumQueryPoints() @property From 474a98af539000750d6712097fadbbc9b7079601 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 6 Oct 2020 20:07:23 -0500 Subject: [PATCH 8/9] Match docstring. --- freud/locality.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freud/locality.pyx b/freud/locality.pyx index 08425ebec..991ff2ea0 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -643,7 +643,7 @@ cdef class NeighborList: def num_query_points(self): """Returns the number of query points. - All query point indices must be less than this value. + All query point indices are less than this value. """ return self.thisptr.getNumQueryPoints() From 7b0b061c2281f1330d9de89684cd1f7ca2ab0143 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 6 Oct 2020 20:13:25 -0500 Subject: [PATCH 9/9] Fix docstrings to match conventions. --- freud/locality.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freud/locality.pyx b/freud/locality.pyx index 991ff2ea0..9bc814504 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -641,7 +641,7 @@ cdef class NeighborList: @property def num_query_points(self): - """Returns the number of query points. + """unsigned int: The number of query points. All query point indices are less than this value. """ @@ -649,7 +649,7 @@ cdef class NeighborList: @property def num_points(self): - """Returns the number of points. + """unsigned int: The number of points. All point indices are less than this value. """