Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/structure-f…
Browse files Browse the repository at this point in the history
…actor
  • Loading branch information
bdice committed Oct 7, 2020
2 parents bc61716 + ed83bdc commit 3e9066b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions cpp/locality/NeighborList.cc
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Expand Up @@ -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),
}

Expand Down
1 change: 1 addition & 0 deletions doc/source/reference/credits.rst
Expand Up @@ -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**

Expand Down
16 changes: 16 additions & 0 deletions freud/locality.pyx
Expand Up @@ -639,6 +639,22 @@ cdef class NeighborList:
R"""Returns the number of bonds stored in this object."""
return self.thisptr.getNumBonds()

@property
def num_query_points(self):
"""unsigned int: The number of query points.
All query point indices are less than this value.
"""
return self.thisptr.getNumQueryPoints()

@property
def num_points(self):
"""unsigned int: 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`.
Expand Down
23 changes: 20 additions & 3 deletions tests/test_locality_NeighborList.py
Expand Up @@ -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)

Expand Down Expand Up @@ -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()

0 comments on commit 3e9066b

Please sign in to comment.