forked from lijiext/lammps
add single test to angle_style, add support for equilibrium data
This commit is contained in:
parent
47e4da4903
commit
08ee1cb4fa
|
@ -766,3 +766,152 @@ TEST(AngleStyle, omp) {
|
|||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
};
|
||||
|
||||
TEST(AngleStyle, single) {
|
||||
const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite" };
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
// create a LAMMPS instance with standard settings to detect the number of atom types
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
LAMMPS *lmp = init_lammps(argc,argv,test_config);
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
if (!lmp) {
|
||||
std::cerr << "One or more prerequisite styles are not available "
|
||||
"in this LAMMPS configuration:\n";
|
||||
for (auto& prerequisite : test_config.prerequisites) {
|
||||
std::cerr << prerequisite.first << "_style "
|
||||
<< prerequisite.second << "\n";
|
||||
}
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
// gather some information and skip if unsupported
|
||||
int nangletypes = lmp->atom->nangletypes;
|
||||
int molecular = lmp->atom->molecular;
|
||||
if (molecular != 1) {
|
||||
std::cerr << "Only simple molecular atom styles are supported\n";
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
cleanup_lammps(lmp,test_config);
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
// utility lambda to improve readability
|
||||
auto command = [&](const std::string & line) {
|
||||
lmp->input->one(line.c_str());
|
||||
};
|
||||
|
||||
// now start over
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("clear");
|
||||
command("variable newton_bond delete");
|
||||
command("variable newton_bond index on");
|
||||
|
||||
command("variable input_dir index " + INPUT_FOLDER);
|
||||
|
||||
for (auto& pre_command : test_config.pre_commands) {
|
||||
command(pre_command);
|
||||
}
|
||||
|
||||
command("atom_style molecular");
|
||||
command("units ${units}");
|
||||
command("boundary p p p");
|
||||
command("newton ${newton_pair} ${newton_bond}");
|
||||
command("special_bonds lj/coul "
|
||||
"${bond_factor} ${angle_factor} ${dihedral_factor}");
|
||||
|
||||
command("atom_modify map array");
|
||||
command("region box block -10.0 10.0 -10.0 10.0 -10.0 10.0 units box");
|
||||
|
||||
char buf[10];
|
||||
std::string cmd("create_box 1 box");
|
||||
cmd += " angle/types ";
|
||||
snprintf(buf,10,"%d",nangletypes);
|
||||
cmd += buf;
|
||||
cmd += " extra/angle/per/atom 2";
|
||||
cmd += " extra/special/per/atom 2";
|
||||
command(cmd);
|
||||
|
||||
command("pair_style zero 8.0");
|
||||
command("pair_coeff * *");
|
||||
|
||||
command("angle_style " + test_config.angle_style);
|
||||
Angle *angle = lmp->force->angle;
|
||||
|
||||
for (auto& angle_coeff : test_config.angle_coeff) {
|
||||
command("angle_coeff " + angle_coeff);
|
||||
}
|
||||
|
||||
// create (only) three atoms and one angle
|
||||
command("mass * 1.0");
|
||||
command("create_atoms 1 single 5.0 -0.75 0.4 units box");
|
||||
command("create_atoms 1 single 5.5 0.25 -0.1 units box");
|
||||
command("create_atoms 1 single 5.0 0.75 0.4 units box");
|
||||
command("create_bonds single/angle 1 1 2 3");
|
||||
|
||||
for (auto& post_command : test_config.post_commands) {
|
||||
command(post_command);
|
||||
}
|
||||
|
||||
command("run 0 post no");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
int idx1 = lmp->atom->map(1);
|
||||
int idx2 = lmp->atom->map(2);
|
||||
int idx3 = lmp->atom->map(3);
|
||||
double epsilon = test_config.epsilon;
|
||||
double eangle[4], esingle[4];
|
||||
|
||||
eangle[0] = angle->energy;
|
||||
esingle[0] = angle->single(1, idx1, idx2, idx3);
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("displace_atoms all random 0.5 0.5 0.5 23456");
|
||||
command("run 0 post no");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
idx1 = lmp->atom->map(1);
|
||||
idx2 = lmp->atom->map(2);
|
||||
idx3 = lmp->atom->map(3);
|
||||
eangle[1] = angle->energy;
|
||||
esingle[1] = angle->single(1, idx1, idx2, idx3);
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("displace_atoms all random 0.5 0.5 0.5 456963");
|
||||
command("run 0 post no");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
idx1 = lmp->atom->map(1);
|
||||
idx2 = lmp->atom->map(2);
|
||||
idx3 = lmp->atom->map(3);
|
||||
eangle[2] = angle->energy;
|
||||
esingle[2] = angle->single(1, idx1, idx2, idx3);
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("displace_atoms all random 0.5 0.5 0.5 9726532");
|
||||
command("run 0 post no");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
idx1 = lmp->atom->map(1);
|
||||
idx2 = lmp->atom->map(2);
|
||||
idx3 = lmp->atom->map(3);
|
||||
eangle[3] = angle->energy;
|
||||
esingle[3] = angle->single(1, idx1, idx2, idx3);
|
||||
|
||||
ErrorStats stats;
|
||||
EXPECT_FP_LE_WITH_EPS(eangle[0], esingle[0], epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(eangle[1], esingle[1], epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(eangle[2], esingle[2], epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(eangle[3], esingle[3], epsilon);
|
||||
if (print_stats)
|
||||
std::cerr << "single_energy stats:" << stats << std::endl;
|
||||
|
||||
int i = 0;
|
||||
for (auto &dist : test_config.equilibrium)
|
||||
EXPECT_NEAR(dist,angle->equilibrium_angle(++i),0.00001);
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
cleanup_lammps(lmp,test_config);
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
|
|
@ -778,7 +778,7 @@ TEST(BondStyle, single) {
|
|||
if (!lmp) {
|
||||
std::cerr << "One or more prerequisite styles are not available "
|
||||
"in this LAMMPS configuration:\n";
|
||||
for (auto prerequisite : test_config.prerequisites) {
|
||||
for (auto& prerequisite : test_config.prerequisites) {
|
||||
std::cerr << prerequisite.first << "_style "
|
||||
<< prerequisite.second << "\n";
|
||||
}
|
||||
|
@ -801,8 +801,6 @@ TEST(BondStyle, single) {
|
|||
lmp->input->one(line.c_str());
|
||||
};
|
||||
|
||||
Bond *bond = lmp->force->bond;
|
||||
|
||||
// now start over
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("clear");
|
||||
|
@ -838,9 +836,9 @@ TEST(BondStyle, single) {
|
|||
command("pair_coeff * *");
|
||||
|
||||
command("bond_style " + test_config.bond_style);
|
||||
bond = lmp->force->bond;
|
||||
Bond *bond = lmp->force->bond;
|
||||
|
||||
for (auto bond_coeff : test_config.bond_coeff) {
|
||||
for (auto& bond_coeff : test_config.bond_coeff) {
|
||||
command("bond_coeff " + bond_coeff);
|
||||
}
|
||||
|
||||
|
@ -1020,6 +1018,10 @@ TEST(BondStyle, single) {
|
|||
if (print_stats)
|
||||
std::cerr << "single_energy stats:" << stats << std::endl;
|
||||
|
||||
int i = 0;
|
||||
for (auto &dist : test_config.equilibrium)
|
||||
EXPECT_NEAR(dist,bond->equilibrium_distance(++i),0.00001);
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
cleanup_lammps(lmp,test_config);
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
lammps_version: 5 May 2020
|
||||
date_generated: Tue May 19 19:19:41 202
|
||||
date_generated: Thu May 28 22:02:50 202
|
||||
epsilon: 2.5e-13
|
||||
prerequisites: ! |
|
||||
atom full
|
||||
|
@ -14,6 +14,7 @@ angle_coeff: ! |
|
|||
2 46.1 111.3 0.0 0.000
|
||||
3 40.0 120.0 35.0 2.410
|
||||
4 33.0 108.5 30.0 2.163
|
||||
equilibrium: 1.92161 1.94255 2.0944 1.89368
|
||||
extract: ! ""
|
||||
natoms: 29
|
||||
init_energy: 85.4248638845977
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
lammps_version: 5 May 2020
|
||||
date_generated: Tue May 19 19:00:35 202
|
||||
date_generated: Thu May 28 22:02:43 202
|
||||
epsilon: 2.5e-13
|
||||
prerequisites: ! |
|
||||
atom full
|
||||
|
@ -14,6 +14,7 @@ angle_coeff: ! |
|
|||
2 45.0 111.0
|
||||
3 50.0 120.0
|
||||
4 100.0 108.5
|
||||
equilibrium: 1.92161 1.93732 2.0944 1.89368
|
||||
extract: ! ""
|
||||
natoms: 29
|
||||
init_energy: 41.530817896491
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
lammps_version: 5 May 2020
|
||||
date_generated: Mon May 18 18:18:26 202
|
||||
epsilon: 1.0e-14
|
||||
date_generated: Thu May 28 22:02:55 202
|
||||
epsilon: 1e-14
|
||||
prerequisites: ! |
|
||||
atom full
|
||||
angle zero
|
||||
|
@ -14,6 +14,7 @@ angle_coeff: ! |
|
|||
2 111
|
||||
3 120
|
||||
4 108.5
|
||||
equilibrium: 1.92161 1.93732 2.0944 1.89368
|
||||
extract: ! ""
|
||||
natoms: 29
|
||||
init_energy: 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
lammps_version: 5 May 2020
|
||||
date_generated: Mon May 18 18:18:26 202
|
||||
epsilon: 1.0e-13
|
||||
date_generated: Thu May 28 22:04:42 202
|
||||
epsilon: 1e-13
|
||||
prerequisites: ! |
|
||||
atom full
|
||||
bond class2
|
||||
|
@ -15,6 +15,7 @@ bond_coeff: ! |
|
|||
3 1.3 299.67 -501.77 679.81
|
||||
4 1.2 345.00 -691.89 844.60
|
||||
5 0.97 532.50 -1282.90 2004.76
|
||||
equilibrium: 1.42 1.1 1.3 1.2 0.97
|
||||
extract: ! |
|
||||
r0 1
|
||||
natoms: 29
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
lammps_version: 5 May 2020
|
||||
date_generated: Mon May 18 18:18:26 202
|
||||
date_generated: Thu May 28 22:04:14 202
|
||||
epsilon: 2.5e-13
|
||||
prerequisites: ! |
|
||||
atom full
|
||||
|
@ -15,7 +15,8 @@ bond_coeff: ! |
|
|||
3 350.0 1.3
|
||||
4 650.0 1.2
|
||||
5 450.0 1.0
|
||||
extract: !
|
||||
equilibrium: 1.5 1.1 1.3 1.2 1
|
||||
extract: ! |
|
||||
kappa 1
|
||||
r0 1
|
||||
natoms: 29
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
lammps_version: 5 May 2020
|
||||
date_generated: Mon May 18 18:18:26 202
|
||||
date_generated: Thu May 28 22:04:30 202
|
||||
epsilon: 2.5e-13
|
||||
prerequisites: ! |
|
||||
atom full
|
||||
|
@ -16,6 +16,7 @@ bond_coeff: ! |
|
|||
3 morse 7000.0 0.2 1.3
|
||||
4 harmonic 650.0 1.2
|
||||
5 harmonic 450.0 1.0
|
||||
equilibrium: 1.5 1.1 1.3 1.2 1
|
||||
extract: ! ""
|
||||
natoms: 29
|
||||
init_energy: 4.63957309438403
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
lammps_version: 5 May 2020
|
||||
date_generated: Mon May 18 18:18:26 202
|
||||
date_generated: Thu May 28 22:04:25 202
|
||||
epsilon: 2.5e-13
|
||||
prerequisites: ! |
|
||||
atom full
|
||||
|
@ -15,6 +15,7 @@ bond_coeff: ! |
|
|||
3 7000.0 0.2 1.3
|
||||
4 7500.0 0.4 1.2
|
||||
5 7000.0 0.3 1.0
|
||||
equilibrium: 1.5 1.1 1.3 1.2 1
|
||||
extract: ! |
|
||||
r0 1
|
||||
natoms: 29
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
lammps_version: 5 May 2020
|
||||
date_generated: Mon May 18 18:18:26 202
|
||||
epsilon: 1.0e-14
|
||||
date_generated: Thu May 28 22:03:25 202
|
||||
epsilon: 1e-14
|
||||
prerequisites: ! |
|
||||
atom full
|
||||
bond zero
|
||||
|
@ -15,6 +15,7 @@ bond_coeff: ! |
|
|||
3 1.3
|
||||
4 1.2
|
||||
5 1.0
|
||||
equilibrium: 1.5 1.1 1.3 1.2 1
|
||||
extract: ! |
|
||||
r0 1
|
||||
natoms: 29
|
||||
|
|
Loading…
Reference in New Issue