Merge branch 'develop' into pair_d3

This commit is contained in:
Axel Kohlmeyer
2025-01-14 16:05:29 -05:00
1000 changed files with 35345 additions and 27449 deletions

View File

@ -233,3 +233,34 @@ TEST_F(LibraryObjects, expand)
EXPECT_THAT((char *)ptr, StrEq("'xx_$(4+5)_$(PI) ${one}-${two}-${three}'"));
lammps_free(ptr);
}
TEST_F(LibraryObjects, eval)
{
lammps_get_last_error_message(lmp, nullptr, 1);
::testing::internal::CaptureStdout();
lammps_commands_string(lmp, "region box1 block 0 10 0 5 -0.5 0.5\n"
"lattice fcc 0.8\n"
"create_box 1 box1\n"
"create_atoms 1 box\n"
"mass * 1.0\n"
"pair_style lj/cut 4.0\n"
"pair_coeff * * 1.0 1.0\n"
"variable t equal 15.0\n"
"velocity all create 1.5 532656\n"
"fix 1 all nve\n"
"run 0 post no\n");
lammps_command(lmp, "variable one index 1 2 3 4");
lammps_command(lmp, "variable two equal 2");
std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output;
ASSERT_EQ(lammps_has_error(lmp), 0);
EXPECT_DOUBLE_EQ(lammps_eval(lmp, "4+5"), 9.0);
EXPECT_EQ(lammps_has_error(lmp), 0);
EXPECT_DOUBLE_EQ(lammps_eval(lmp, "v_one / 2.0"), 0.5);
EXPECT_EQ(lammps_has_error(lmp), 0);
EXPECT_DOUBLE_EQ(lammps_eval(lmp, "count(all)"), 36.0);
EXPECT_EQ(lammps_has_error(lmp), 0);
EXPECT_DOUBLE_EQ(lammps_eval(lmp, "pe"), -3.9848867644689534);
EXPECT_EQ(lammps_has_error(lmp), 0);
}

View File

@ -405,7 +405,7 @@ TEST_F(SimpleCommandsTest, Units)
END_HIDE_OUTPUT();
ASSERT_THAT(lmp->update->unit_style, StrEq("lj"));
TEST_FAILURE(".*ERROR: Illegal units command.*", command("units unknown"););
TEST_FAILURE(".*ERROR: Unknown units style unknown.*", command("units unknown"););
}
#if defined(LMP_PLUGIN)

View File

@ -140,8 +140,8 @@ TEST_F(VariableTest, CreateDelete)
command("variable ten1 universe 1 2 3 4");
command("variable ten2 uloop 4");
command("variable ten3 uloop 4 pad");
command("variable ten4 vector [0,1,2,3,5,7,11]");
command("variable ten5 vector [0.5,1.25]");
command("variable ten4 vector [0,1, 2,3, 5,7,11]");
command("variable ten5 vector [ 0.5, 1.25 ]");
command("variable dummy index 0");
command("variable file equal is_file(MYFILE)");
command("variable iswin equal is_os(^Windows)");
@ -323,13 +323,13 @@ TEST_F(VariableTest, Expressions)
BEGIN_HIDE_OUTPUT();
command("variable one index 1");
command("variable two equal 2");
command("variable three equal v_one+v_two");
command("variable three equal v_one + v_two");
command("variable four equal PI");
command("variable five equal version");
command("variable six equal XXX");
command("variable seven equal -v_one");
command("variable eight equal v_three-0.5");
command("variable nine equal v_two*(v_one+v_three)");
command("variable nine equal v_two * (v_one+v_three)");
command("variable ten equal (1.0/v_two)^2");
command("variable eleven equal v_three%2");
command("variable twelve equal 1==2");
@ -341,7 +341,7 @@ TEST_F(VariableTest, Expressions)
command("variable ten8 equal 1|^0");
command("variable ten9 equal v_one-v_ten9");
command("variable ten10 internal 100.0");
command("variable ten11 equal (1!=1)+(2<1)+(2<=1)+(1>2)+(1>=2)+(1&&0)+(0||0)+(1|^1)+10^0");
command("variable ten11 equal (1 != 1)+(2 < 1)+(2<=1)+(1>2)+(1>=2)+(1&&0)+(0||0)+(1|^1)+10^0");
command("variable ten12 equal yes+no+on+off+true+false");
command("variable err1 equal v_one/v_ten7");
command("variable err2 equal v_one%v_ten7");
@ -350,7 +350,7 @@ TEST_F(VariableTest, Expressions)
command("variable vec2 vector v_vec1*0.5");
command("variable vec3 equal v_vec2[3]");
command("variable vec4 vector '[1, 5, 2.5, -10, -5, 20, 120, 4, 3, 3]'");
command("variable sort vector sort(v_vec4)");
command("variable sort vector sort(v_vec4 )");
command("variable rsrt vector rsort(v_vec4)");
command("variable max2 equal sort(v_vec4)[2]");
command("variable rmax equal rsort(v_vec4)[1]");

View File

@ -0,0 +1,89 @@
---
lammps_version: 19 Nov 2024
tags: generated
date_generated: Fri Jan 10 13:54:41 2025
epsilon: 2.5e-13
skip_tests:
prerequisites: ! |
atom full
angle mwlc
pre_commands: ! ""
post_commands: ! ""
input_file: in.fourmol
angle_style: mwlc
angle_coeff: ! |
* 6.0 0.6 15.0 300.0
equilibrium: 4 3.141592653589793 3.141592653589793 3.141592653589793 3.141592653589793
extract: ! |
k1 1
k2 1
mu 1
temp 1
natoms: 29
init_energy: 115.97311255470154
init_stress: ! |2-
1.0785144954758131e+01 -5.1561329771224154e+00 -5.6290119776357184e+00 1.7509753155291005e+01 8.4620050528315804e+00 5.4460179571966592e+00
init_forces: ! |2
1 2.0049292277552344e+00 -3.4967838538707023e+00 -7.7679149207041780e+00
2 5.2379550897725657e-01 4.2410446627574743e+00 3.4103186723411198e+00
3 -2.6364713466403744e+00 1.7646356480410195e+00 6.7422761915790446e+00
4 5.9780828166032607e-01 -1.0977711474862293e+00 -1.2762851805838284e+00
5 2.7519993963547762e-02 -1.3655215729181727e+00 -4.0557483263144212e-01
6 -1.4407532935169898e-01 -1.5931923885520087e+00 -1.8663167177332292e+00
7 -4.1794796128320089e-01 4.1379756743889873e-01 -9.9274508603132139e-02
8 8.6885282425298183e-01 2.9273693794680500e-01 3.9875384936490477e+00
9 -7.4989162989673552e-01 1.9120936074864758e-02 1.6480002237326197e-01
10 4.5851731938743301e+00 5.1383619725146579e-01 -7.8986229128522627e+00
11 -1.3361238263371962e+00 -1.6154590769980759e+00 1.3132946273952864e+00
12 -9.8353444089007258e-01 5.7660344986117273e-01 -1.6760444984003993e+00
13 4.8213326840430115e-02 7.5476102608997231e-02 9.7662630040726750e-01
14 1.7020627463903515e-01 -4.9418713351985666e-02 -6.9510195676192543e-02
15 5.7466130382222369e-01 -3.0791486600816609e-01 9.0601148952989252e-01
16 -5.6604535775268596e+00 5.0708111379184277e+00 1.7013150451815964e+00
17 2.5273381761407760e+00 -3.4420010207137852e+00 1.8573629247281453e+00
18 2.0828420935010161e-01 2.1765636018344789e+00 -8.8331994782253780e+00
19 -2.5502877667816710e+00 -3.1771408888391202e+00 3.7828819753880119e+00
20 2.3420035574315694e+00 1.0005772870046410e+00 5.0503175028373661e+00
21 2.2520112617177057e+00 2.8191460010961373e+00 -8.4251146760580085e+00
22 -4.0101778142198494e+00 -2.7341370977288624e+00 2.9783951433938527e+00
23 1.7581665525021437e+00 -8.5008903367275068e-02 5.4467195326641562e+00
24 -1.9792115156439898e+00 7.6933124498060685e+00 -4.5803031378051688e+00
25 -1.5876110942732853e+00 -5.3190980720841390e+00 8.6990568523236744e-01
26 3.5668226099172751e+00 -2.3742143777219300e+00 3.7103974525728014e+00
27 -1.0535801895693373e+00 8.6490680045193269e+00 -2.9461596365031912e+00
28 -2.3037157984215133e+00 -5.1714048596555164e+00 1.2013129729191907e-01
29 3.3572959879908506e+00 -3.4776631448638109e+00 2.8260283392112724e+00
run_energy: 115.88929660500146
run_stress: ! |2-
1.0741962021125900e+01 -5.1494210571452070e+00 -5.5925409639806976e+00 1.7499135911989786e+01 8.4401379697723158e+00 5.4365488644723161e+00
run_forces: ! |2
1 2.0024084967323734e+00 -3.4852712888973301e+00 -7.7681384109278948e+00
2 5.1802520314744682e-01 4.2290273746409701e+00 3.4156643023763298e+00
3 -2.6176139409651311e+00 1.7481727755506558e+00 6.7276571726932186e+00
4 5.9646423832275675e-01 -1.0896302596160039e+00 -1.2658946496090273e+00
5 2.0626395368878558e-02 -1.3553597325783064e+00 -4.0428709993242351e-01
6 -1.5043849290340794e-01 -1.6020934387436645e+00 -1.8709909377854954e+00
7 -4.1644858135120844e-01 4.1712949378864117e-01 -1.0014611176127630e-01
8 8.7761514222742898e-01 2.9932822072179732e-01 3.9914298835888857e+00
9 -7.5185528312840066e-01 1.9244616790871305e-02 1.6542886887136499e-01
10 4.5736254271229742e+00 4.9828467262363496e-01 -7.8986022120685373e+00
11 -1.3323136450232624e+00 -1.6103729207690813e+00 1.3097303435864336e+00
12 -1.0040757700004965e+00 5.7836875530999343e-01 -1.6448472694236678e+00
13 4.8392108795294986e-02 7.7447222505411639e-02 9.6494421976551426e-01
14 1.8086042252760026e-01 -5.1422366669672037e-02 -7.3717779732260791e-02
15 5.8324025586810402e-01 -3.0468600966273196e-01 8.9577956208287191e-01
16 -5.6548207755179911e+00 5.0752603376691656e+00 1.6979261789431477e+00
17 2.5263087987770385e+00 -3.4434274526643489e+00 1.8580639393328193e+00
18 2.1733330742608858e-01 2.1830182266117371e+00 -8.8242777257965024e+00
19 -2.5415995943828809e+00 -3.1730376716173803e+00 3.7883421709467422e+00
20 2.3242662869567923e+00 9.9001944500564321e-01 5.0359355548497611e+00
21 2.2580025853773256e+00 2.8068061574356138e+00 -8.4373139893370634e+00
22 -4.0070465500208554e+00 -2.7223210888728504e+00 2.9888102357206301e+00
23 1.7490439646435296e+00 -8.4485068562763388e-02 5.4485037536164329e+00
24 -1.9860712475490458e+00 7.7098710540424751e+00 -4.5855114458364374e+00
25 -1.5787959452376497e+00 -5.3290411597315357e+00 8.7215941857315382e-01
26 3.5648671927866955e+00 -2.3808298943109389e+00 3.7133520272632836e+00
27 -1.0631738916816893e+00 8.6588340987013801e+00 -2.9324082303496679e+00
28 -2.2973201808293515e+00 -5.1771902142248960e+00 1.1264225202087563e-01
29 3.3604940725110408e+00 -3.4816438844764841e+00 2.8197659783287921e+00
...

View File

@ -105,6 +105,11 @@ if(Python_EXECUTABLE)
set_tests_properties(PythonPyLammps PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}")
endif()
add_test(NAME PythonCmdWrapper
COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-cmdwrapper.py -v
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
set_tests_properties(PythonCmdWrapper PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}")
add_test(NAME PythonFormats
COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-formats.py -v
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})

View File

@ -0,0 +1,97 @@
import os,unittest
from lammps import lammps
try:
import numpy
NUMPY_INSTALLED = True
except ImportError:
NUMPY_INSTALLED = False
@unittest.skipIf(not NUMPY_INSTALLED, "numpy is not available")
class PythonCmdWrapper(unittest.TestCase):
def setUp(self):
machine = None
if 'LAMMPS_MACHINE_NAME' in os.environ:
machine=os.environ['LAMMPS_MACHINE_NAME']
self.lmp = lammps(name=machine, cmdargs=['-nocite', '-log','none', '-echo', 'screen'])
self.lmp.cmd.units("lj")
self.lmp.cmd.atom_style("atomic")
self.lmp.cmd.atom_modify("map array")
if 'LAMMPS_CMAKE_CACHE' in os.environ:
self.cmake_cache = {}
with open(os.environ['LAMMPS_CMAKE_CACHE'], 'r') as f:
for line in f:
line = line.strip()
if not line or line.startswith('#') or line.startswith('//'): continue
parts = line.split('=')
key, value_type = parts[0].split(':')
if len(parts) > 1:
value = parts[1]
if value_type == "BOOL":
value = (value.upper() == "ON")
else:
value = None
self.cmake_cache[key] = value
def tearDown(self):
self.lmp.close()
del self.lmp
def test_version(self):
self.assertGreaterEqual(self.lmp.version(), 20200824)
def test_create_atoms(self):
self.lmp.cmd.region("box block", 0, 2, 0, 2, 0, 2)
self.lmp.cmd.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)
self.assertEqual(self.lmp.extract_global("natoms"), 2)
pos = self.lmp.numpy.extract_atom("x")
self.assertEqual(pos.shape[0], 2)
numpy.testing.assert_array_equal(pos[0], tuple(x[0:3]))
numpy.testing.assert_array_equal(pos[1], tuple(x[3:6]))
def test_thermo_capture(self):
self.lmp.cmd.lattice("fcc", 0.8442),
self.lmp.cmd.region("box block", 0, 4, 0, 4, 0, 4)
self.lmp.cmd.create_box(1, "box")
self.lmp.cmd.create_atoms(1, "box")
self.lmp.cmd.mass(1, 1.0)
self.lmp.cmd.velocity("all create", 1.44, 87287, "loop geom")
self.lmp.cmd.pair_style("lj/cut", 2.5)
self.lmp.cmd.pair_coeff(1, 1, 1.0, 1.0, 2.5)
self.lmp.cmd.neighbor(0.3, "bin")
self.lmp.cmd.neigh_modify("delay 0 every 20 check no")
self.lmp.cmd.fix("1 all nve")
current_run = {}
def append_thermo_data(lmp):
for k, v in lmp.last_thermo().items():
current_run.setdefault(k, []).append(v)
# thermo data is only captured during a run if PYTHON package is enabled
# without it, it will only capture the final thermo at completion
nvalues = 1
if self.lmp.has_package("PYTHON"):
self.lmp.cmd.fix("myfix", "all", "python/invoke", 10, "end_of_step", append_thermo_data)
nvalues = 2
self.lmp.cmd.run(10)
append_thermo_data(self.lmp)
for k in ('Step', 'Temp', 'E_pair', 'E_mol', 'TotEng', 'Press'):
self.assertIn(k, current_run)
self.assertEqual(len(current_run[k]), nvalues)
if __name__ == "__main__":
unittest.main()

View File

@ -538,6 +538,27 @@ create_atoms 1 single &
expanded = self.lmp.expand("'xx_$(4+5)_$(PI) ${one}-${two}-${three}'")
self.assertEqual(expanded, "'xx_$(4+5)_$(PI) ${one}-${two}-${three}'")
def test_eval(self):
self.lmp.commands_string(
"""region box1 block 0 10 0 5 -0.5 0.5
lattice fcc 0.8
create_box 1 box1
create_atoms 1 box
mass * 1.0
pair_style lj/cut 4.0
pair_coeff * * 1.0 1.0
variable t equal 15.0
velocity all create 1.5 532656
fix 1 all nve
run 0 post no""")
self.lmp.command("variable one index 1 2 3 4")
self.lmp.command("variable two equal 2")
self.assertEqual(self.lmp.eval("4+5"), 9.0)
self.assertEqual(self.lmp.eval("v_one / 2.0"), 0.5)
self.assertEqual(self.lmp.eval("count(all)"), 36.0)
self.assertEqual(self.lmp.eval("pe"), -3.9848867644689534)
def test_get_thermo(self):
self.lmp.command("units lj")
self.lmp.command("atom_style atomic")

View File

@ -1073,7 +1073,7 @@ TEST(Utils, timespec2seconds_mmfraction)
TEST(Utils, timespec2seconds_invalid)
{
ASSERT_DOUBLE_EQ(utils::timespec2seconds("2:aa:45"), -1.0);
ASSERT_THROW(utils::timespec2seconds("2:aa:45"), TokenizerException);
}
TEST(Utils, date2num)