add python interface with optional numpy support for lammps_gather_bonds()
unit tests are included
This commit is contained in:
@ -15,6 +15,17 @@ try:
|
||||
except:
|
||||
pass
|
||||
|
||||
has_full=False
|
||||
try:
|
||||
machine=None
|
||||
if 'LAMMPS_MACHINE_NAME' in os.environ:
|
||||
machine=os.environ['LAMMPS_MACHINE_NAME']
|
||||
lmp=lammps(name=machine)
|
||||
has_full = lmp.has_style("atom","full")
|
||||
lmp.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
import numpy
|
||||
NUMPY_INSTALLED = True
|
||||
@ -32,6 +43,14 @@ class PythonNumpy(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
del self.lmp
|
||||
|
||||
def checkBond(self, vals, btype, batom1, batom2):
|
||||
if ((vals[1] == batom1 and vals[2] == batom2)
|
||||
or (vals[1] == batom2 and vals[2] == batom1)):
|
||||
self.assertEqual(vals[0], btype)
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def testLammpsPointer(self):
|
||||
self.assertEqual(type(self.lmp.lmp), c_void_p)
|
||||
|
||||
@ -148,6 +167,50 @@ class PythonNumpy(unittest.TestCase):
|
||||
self.assertTrue((x[1] == (1.0, 1.0, 1.5)).all())
|
||||
self.assertEqual(len(v), 2)
|
||||
|
||||
@unittest.skipIf(not has_full,"Gather bonds test")
|
||||
def testGatherBond_newton_on(self):
|
||||
self.lmp.command('shell cd ' + os.environ['TEST_INPUT_DIR'])
|
||||
self.lmp.command("newton on on")
|
||||
self.lmp.file("in.fourmol")
|
||||
self.lmp.command("run 0 post no")
|
||||
bonds = self.lmp.numpy.gather_bonds()
|
||||
self.assertEqual(len(bonds),24)
|
||||
count = 0
|
||||
for bond in bonds:
|
||||
count += self.checkBond(bond, 5, 1, 2)
|
||||
count += self.checkBond(bond, 3, 1, 3)
|
||||
count += self.checkBond(bond, 2, 3, 4)
|
||||
count += self.checkBond(bond, 2, 3, 5)
|
||||
count += self.checkBond(bond, 1, 6, 3)
|
||||
count += self.checkBond(bond, 3, 6, 8)
|
||||
count += self.checkBond(bond, 4, 6, 7)
|
||||
count += self.checkBond(bond, 5, 8, 9)
|
||||
count += self.checkBond(bond, 5, 27, 28)
|
||||
count += self.checkBond(bond, 5, 29, 27)
|
||||
self.assertEqual(count,10)
|
||||
|
||||
@unittest.skipIf(not has_full,"Gather bonds test")
|
||||
def testGatherBond_newton_off(self):
|
||||
self.lmp.command('shell cd ' + os.environ['TEST_INPUT_DIR'])
|
||||
self.lmp.command("newton off off")
|
||||
self.lmp.file("in.fourmol")
|
||||
self.lmp.command("run 0 post no")
|
||||
bonds = self.lmp.numpy.gather_bonds()
|
||||
self.assertEqual(len(bonds),24)
|
||||
count = 0
|
||||
for bond in bonds:
|
||||
count += self.checkBond(bond, 5, 1, 2)
|
||||
count += self.checkBond(bond, 3, 1, 3)
|
||||
count += self.checkBond(bond, 2, 3, 4)
|
||||
count += self.checkBond(bond, 2, 3, 5)
|
||||
count += self.checkBond(bond, 1, 6, 3)
|
||||
count += self.checkBond(bond, 3, 6, 8)
|
||||
count += self.checkBond(bond, 4, 6, 7)
|
||||
count += self.checkBond(bond, 5, 8, 9)
|
||||
count += self.checkBond(bond, 5, 27, 28)
|
||||
count += self.checkBond(bond, 5, 29, 27)
|
||||
self.assertEqual(count,10)
|
||||
|
||||
def testNeighborListSimple(self):
|
||||
self.lmp.commands_string("""
|
||||
units lj
|
||||
|
||||
Reference in New Issue
Block a user