add unit tests for library interface function lammps_extract_pair() and python equivalent
This commit is contained in:
@ -3,6 +3,7 @@ import sys,os,unittest,ctypes
|
||||
from lammps import lammps, LMP_VAR_ATOM, LMP_STYLE_GLOBAL, LMP_STYLE_LOCAL
|
||||
from lammps import LMP_TYPE_VECTOR, LMP_SIZE_VECTOR, LMP_SIZE_ROWS, LMP_SIZE_COLS
|
||||
from lammps import LAMMPS_DOUBLE_2D, LAMMPS_AUTODETECT
|
||||
import math
|
||||
|
||||
has_manybody=False
|
||||
try:
|
||||
@ -15,6 +16,17 @@ try:
|
||||
except:
|
||||
pass
|
||||
|
||||
has_streitz=False
|
||||
try:
|
||||
machine=None
|
||||
if 'LAMMPS_MACHINE_NAME' in os.environ:
|
||||
machine=os.environ['LAMMPS_MACHINE_NAME']
|
||||
lmp=lammps(name=machine)
|
||||
has_streitz = lmp.has_style("pair","coul/streitz")
|
||||
lmp.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
class PythonCommand(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -666,6 +678,49 @@ create_atoms 1 single &
|
||||
self.lmp.command("balance 0.1 rcb")
|
||||
self.assertEqual(self.lmp.extract_global("procgrid"), None)
|
||||
|
||||
def test_extract_pair1(self):
|
||||
self.lmp.command("region box block 0 1 0 1 0 1")
|
||||
self.lmp.command("create_box 3 box")
|
||||
self.lmp.command("mass * 1.0")
|
||||
self.lmp.command("pair_style lj/cut 3.0")
|
||||
self.lmp.command("pair_coeff 1 1 1.0 1.0")
|
||||
self.lmp.command("pair_coeff 2 2 1.5 2.0")
|
||||
self.lmp.command("pair_coeff 3 3 1.0 3.0")
|
||||
self.lmp.command("run 0 post no")
|
||||
self.assertEqual(self.lmp.extract_pair_dimension("epsilon"), 2)
|
||||
self.assertEqual(self.lmp.extract_pair_dimension("sigma"), 2)
|
||||
self.assertEqual(self.lmp.extract_pair_dimension("cut_coul"), None)
|
||||
sigma = self.lmp.extract_pair("sigma")
|
||||
self.assertEqual(sigma[1][1], 1.0)
|
||||
self.assertEqual(sigma[2][2], 2.0)
|
||||
self.assertEqual(sigma[3][3], 3.0)
|
||||
self.assertEqual(sigma[1][2], math.sqrt(2.0))
|
||||
|
||||
@unittest.skipIf(not has_streitz, "Pair extract for coul/streitz test")
|
||||
def test_extract_pair2(self):
|
||||
self.lmp.command("units metal")
|
||||
self.lmp.command("atom_style charge")
|
||||
self.lmp.command("region box block 0 1 0 1 0 1")
|
||||
self.lmp.command("create_box 2 box")
|
||||
self.lmp.command("mass * 1.0")
|
||||
self.lmp.command("pair_style coul/streitz 12.0 wolf 0.31")
|
||||
self.lmp.command("pair_coeff * * AlO.streitz Al O")
|
||||
self.lmp.command("run 0 post no")
|
||||
|
||||
self.assertEqual(self.lmp.extract_pair_dimension("chi"), 1)
|
||||
self.assertEqual(self.lmp.extract_pair_dimension("scale"), 2)
|
||||
self.assertEqual(self.lmp.extract_pair_dimension("cut_coul"), 0)
|
||||
self.assertEqual(self.lmp.extract_pair_dimension("epsilon"), None)
|
||||
|
||||
self.assertEqual(self.lmp.extract_pair("cut_coul"), 12.0)
|
||||
self.assertEqual(self.lmp.extract_pair("chi"), [0.0, 0.0, 5.484763])
|
||||
scale = self.lmp.extract_pair("scale")
|
||||
self.assertEqual(scale[0][0], 0.0);
|
||||
self.assertEqual(scale[0][1], 0.0);
|
||||
self.assertEqual(scale[1][1], 1.0);
|
||||
self.assertEqual(scale[1][2], 1.0);
|
||||
self.assertEqual(scale[2][2], 1.0);
|
||||
|
||||
def test_create_atoms(self):
|
||||
self.lmp.command("boundary f p m")
|
||||
self.lmp.command("region box block 0 10 0 10 0 10")
|
||||
|
||||
Reference in New Issue
Block a user