Skip to content

Commit

Permalink
Merged in cluster_keys (pull request #129)
Browse files Browse the repository at this point in the history
Added test for cluster_keys. Closes #84.

Approved-by: Bradley Dice <bdice@bradleydice.com>
Approved-by: Vyas Ramasubramani <vramasub@umich.edu>
  • Loading branch information
bdice authored and vyasr committed Feb 9, 2018
2 parents 975a00b + bdbd8cd commit e009fb7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions cpp/cluster/Cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Cluster
{
return m_cluster_keys;
}

private:
box::Box m_box; //!< Simulation box the particles belong in
float m_rcut; //!< Maximum r at which points will be counted in the same cluster
Expand Down
31 changes: 27 additions & 4 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import internal

class TestCluster(unittest.TestCase):
def test_basic(self):

def test_cluster_props(self):
Nlattice = 4
Nrep = 5

Expand All @@ -22,13 +23,35 @@ def test_basic(self):
clust.computeClusters(positions)

props = freud.cluster.ClusterProperties(box)
props.computeProperties(positions, clust.getClusterIdx())
props.computeProperties(positions, clust.cluster_idx)

#self.assertEqual(props.getNumClusters(), Ngrid)
self.assertEqual(props.num_clusters, Ngrid)

#self.assertTrue(np.all(props.getClusterSizes() == Nrep))
self.assertTrue(np.all(props.cluster_sizes == Nrep))

def test_cluster_keys(self):
Nlattice = 4
Nrep = 5

positions = []
for _ in range(Nrep):
(box, pos) = internal.make_fcc(Nlattice, Nlattice, Nlattice, noise=1e-2)
positions.append(pos)

# number of grid points (N = Nrep*Ngrid)
Ngrid = positions[-1].shape[0]
positions = np.array(positions).reshape((-1, 3))

clust = freud.cluster.Cluster(box, 0.5)
clust.computeClusters(positions)
clust.computeClusterMembership(np.array(range(Nrep*Ngrid)))

self.assertEqual(len(clust.cluster_keys), Ngrid)

ckeys = np.array(clust.cluster_keys) % Ngrid
check_values = np.arange(Ngrid)[:, np.newaxis].repeat(Nrep, axis=1)

self.assertTrue(np.all(ckeys == check_values))

if __name__ == '__main__':
unittest.main()

0 comments on commit e009fb7

Please sign in to comment.