From 22cca93603fed52fd82b9fb59a7a0237b19838f1 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Oct 2020 17:34:08 -0400 Subject: [PATCH] Add tests for neighbor list API --- python/lammps.py | 2 +- unittest/python/python-commands.py | 43 ++++++++++++++++++++++++++++++ unittest/python/python-numpy.py | 43 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/python/lammps.py b/python/lammps.py index 1f38dd7772..2e7b9ab86f 100644 --- a/python/lammps.py +++ b/python/lammps.py @@ -1587,7 +1587,7 @@ class lammps(object): """ if idx < 0: return None - return NeighList(self.lmp, idx) + return NeighList(self, idx) # ------------------------------------------------------------------------- diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index 0b853a207e..6bd5a2a247 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -85,6 +85,49 @@ create_atoms 1 single & natoms = self.lmp.get_natoms() self.assertEqual(natoms,2) + def testNeighborList(self): + self.lmp.command("units lj") + self.lmp.command("atom_style atomic") + self.lmp.command("atom_modify map array") + self.lmp.command("boundary f f f") + self.lmp.command("region box block 0 2 0 2 0 2") + self.lmp.command("create_box 1 box") + + x = [ + 1.0, 1.0, 1.0, + 1.0, 1.0, 1.5 + ] + + types = [1, 1] + + self.assertEqual(self.lmp.create_atoms(2, id=None, type=types, x=x), 2) + nlocal = self.lmp.extract_global("nlocal") + self.assertEqual(nlocal, 2) + + self.lmp.command("mass 1 1.0") + self.lmp.command("velocity all create 3.0 87287") + self.lmp.command("pair_style lj/cut 2.5") + self.lmp.command("pair_coeff 1 1 1.0 1.0 2.5") + self.lmp.command("neighbor 0.1 bin") + self.lmp.command("neigh_modify every 20 delay 0 check no") + + self.lmp.command("run 0") + + self.assertEqual(self.lmp.find_pair_neighlist("lj/cut"), 0) + nlist = self.lmp.get_neighlist(0) + self.assertEqual(len(nlist), 2) + atom_i, numneigh_i, neighbors_i = nlist[0] + atom_j, numneigh_j, _ = nlist[1] + + self.assertEqual(atom_i, 0) + self.assertEqual(atom_j, 1) + + self.assertEqual(numneigh_i, 1) + self.assertEqual(numneigh_j, 0) + + self.assertEqual(1, neighbors_i[0]) + + ############################## if __name__ == "__main__": unittest.main() diff --git a/unittest/python/python-numpy.py b/unittest/python/python-numpy.py index 3c8ff9f512..46794590f4 100644 --- a/unittest/python/python-numpy.py +++ b/unittest/python/python-numpy.py @@ -135,5 +135,48 @@ class PythonNumpy(unittest.TestCase): self.assertTrue((x[1] == (1.0, 1.0, 1.5)).all()) self.assertEqual(len(v), 2) + def testNeighborList(self): + self.lmp.command("units lj") + self.lmp.command("atom_style atomic") + self.lmp.command("atom_modify map array") + self.lmp.command("boundary f f f") + self.lmp.command("region box block 0 2 0 2 0 2") + self.lmp.command("create_box 1 box") + + x = [ + 1.0, 1.0, 1.0, + 1.0, 1.0, 1.5 + ] + + types = [1, 1] + + self.assertEqual(self.lmp.create_atoms(2, id=None, type=types, x=x), 2) + nlocal = self.lmp.extract_global("nlocal") + self.assertEqual(nlocal, 2) + + self.lmp.command("mass 1 1.0") + self.lmp.command("velocity all create 3.0 87287") + self.lmp.command("pair_style lj/cut 2.5") + self.lmp.command("pair_coeff 1 1 1.0 1.0 2.5") + self.lmp.command("neighbor 0.1 bin") + self.lmp.command("neigh_modify every 20 delay 0 check no") + + self.lmp.command("run 0") + + self.assertEqual(self.lmp.find_pair_neighlist("lj/cut"), 0) + nlist = self.lmp.numpy.get_neighlist(0) + self.assertEqual(len(nlist), 2) + atom_i, neighbors_i = nlist[0] + atom_j, neighbors_j = nlist[1] + + self.assertEqual(atom_i, 0) + self.assertEqual(atom_j, 1) + + self.assertEqual(len(neighbors_i), 1) + self.assertEqual(len(neighbors_j), 0) + + self.assertIn(1, neighbors_i) + self.assertNotIn(0, neighbors_j) + if __name__ == "__main__": unittest.main()