add unit tests for library interface function lammps_extract_pair() and python equivalent
This commit is contained in:
@ -418,7 +418,7 @@ TEST_F(LibraryProperties, global)
|
|||||||
EXPECT_EQ(map_style, Atom::MAP_ARRAY);
|
EXPECT_EQ(map_style, Atom::MAP_ARRAY);
|
||||||
EXPECT_NE(sametag, nullptr);
|
EXPECT_NE(sametag, nullptr);
|
||||||
|
|
||||||
auto *tags = (tagint *)lammps_extract_atom(lmp, "id");
|
auto *tags = (tagint *)lammps_extract_atom(lmp, "id");
|
||||||
const tagint sometags[] = {1, 5, 10, 15, 20};
|
const tagint sometags[] = {1, 5, 10, 15, 20};
|
||||||
for (const auto &sometag : sometags) {
|
for (const auto &sometag : sometags) {
|
||||||
int idx = lammps_map_atom(lmp, (const void *)&sometag);
|
int idx = lammps_map_atom(lmp, (const void *)&sometag);
|
||||||
@ -467,6 +467,54 @@ TEST_F(LibraryProperties, global)
|
|||||||
EXPECT_EQ(map_style, Atom::MAP_ARRAY);
|
EXPECT_EQ(map_style, Atom::MAP_ARRAY);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TEST_F(LibraryProperties, pair1)
|
||||||
|
{
|
||||||
|
if (!verbose) ::testing::internal::CaptureStdout();
|
||||||
|
lammps_command(lmp, "region box block 0 1 0 1 0 1");
|
||||||
|
lammps_command(lmp, "create_box 3 box");
|
||||||
|
lammps_command(lmp, "mass * 1.0");
|
||||||
|
lammps_command(lmp, "pair_style lj/cut 3.0");
|
||||||
|
lammps_command(lmp, "pair_coeff 1 1 1.0 1.0");
|
||||||
|
lammps_command(lmp, "pair_coeff 2 2 1.5 2.0");
|
||||||
|
lammps_command(lmp, "pair_coeff 3 3 1.0 3.0");
|
||||||
|
lammps_command(lmp, "run 0 post no");
|
||||||
|
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||||
|
EXPECT_EQ(lammps_extract_pair_dimension(lmp, "epsilon"), 2);
|
||||||
|
EXPECT_EQ(lammps_extract_pair_dimension(lmp, "sigma"), 2);
|
||||||
|
EXPECT_EQ(lammps_extract_pair_dimension(lmp, "cut_coul"), -1);
|
||||||
|
auto **sigma = (double **)lammps_extract_pair(lmp, "sigma");
|
||||||
|
EXPECT_DOUBLE_EQ(sigma[1][1], 1.0);
|
||||||
|
EXPECT_DOUBLE_EQ(sigma[2][2], 2.0);
|
||||||
|
EXPECT_DOUBLE_EQ(sigma[3][3], 3.0);
|
||||||
|
EXPECT_DOUBLE_EQ(sigma[1][2], sqrt(2.0));
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(LibraryProperties, pair2)
|
||||||
|
{
|
||||||
|
if (!lammps_has_style(lmp, "pair", "coul/streitz")) GTEST_SKIP();
|
||||||
|
if (!verbose) ::testing::internal::CaptureStdout();
|
||||||
|
lammps_command(lmp, "units metal");
|
||||||
|
lammps_command(lmp, "atom_style charge");
|
||||||
|
lammps_command(lmp, "region box block 0 1 0 1 0 1");
|
||||||
|
lammps_command(lmp, "create_box 2 box");
|
||||||
|
lammps_command(lmp, "mass * 1.0");
|
||||||
|
lammps_command(lmp, "pair_style coul/streitz 12.0 wolf 0.31");
|
||||||
|
lammps_command(lmp, "pair_coeff * * AlO.streitz Al O");
|
||||||
|
lammps_command(lmp, "run 0 post no");
|
||||||
|
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||||
|
EXPECT_EQ(lammps_extract_pair_dimension(lmp, "chi"), 1);
|
||||||
|
EXPECT_EQ(lammps_extract_pair_dimension(lmp, "scale"), 2);
|
||||||
|
EXPECT_EQ(lammps_extract_pair_dimension(lmp, "cut_coul"), 0);
|
||||||
|
EXPECT_DOUBLE_EQ(*((double *)lammps_extract_pair(lmp, "cut_coul")), 12.0);
|
||||||
|
auto *chi = (double *)lammps_extract_pair(lmp, "chi");
|
||||||
|
EXPECT_DOUBLE_EQ(chi[1], 0.0);
|
||||||
|
EXPECT_FLOAT_EQ(chi[2], 5.484763);
|
||||||
|
auto **scale = (double **)lammps_extract_pair(lmp, "scale");
|
||||||
|
EXPECT_DOUBLE_EQ(scale[1][1], 1.0);
|
||||||
|
EXPECT_DOUBLE_EQ(scale[1][2], 1.0);
|
||||||
|
EXPECT_DOUBLE_EQ(scale[2][2], 1.0);
|
||||||
|
};
|
||||||
|
|
||||||
TEST_F(LibraryProperties, neighlist)
|
TEST_F(LibraryProperties, neighlist)
|
||||||
{
|
{
|
||||||
if (!lammps_has_style(lmp, "pair", "sw")) GTEST_SKIP();
|
if (!lammps_has_style(lmp, "pair", "sw")) GTEST_SKIP();
|
||||||
|
|||||||
@ -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 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 LMP_TYPE_VECTOR, LMP_SIZE_VECTOR, LMP_SIZE_ROWS, LMP_SIZE_COLS
|
||||||
from lammps import LAMMPS_DOUBLE_2D, LAMMPS_AUTODETECT
|
from lammps import LAMMPS_DOUBLE_2D, LAMMPS_AUTODETECT
|
||||||
|
import math
|
||||||
|
|
||||||
has_manybody=False
|
has_manybody=False
|
||||||
try:
|
try:
|
||||||
@ -15,6 +16,17 @@ try:
|
|||||||
except:
|
except:
|
||||||
pass
|
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):
|
class PythonCommand(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -666,6 +678,49 @@ create_atoms 1 single &
|
|||||||
self.lmp.command("balance 0.1 rcb")
|
self.lmp.command("balance 0.1 rcb")
|
||||||
self.assertEqual(self.lmp.extract_global("procgrid"), None)
|
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):
|
def test_create_atoms(self):
|
||||||
self.lmp.command("boundary f p m")
|
self.lmp.command("boundary f p m")
|
||||||
self.lmp.command("region box block 0 10 0 10 0 10")
|
self.lmp.command("region box block 0 10 0 10 0 10")
|
||||||
|
|||||||
Reference in New Issue
Block a user