new utility function "utils::expand_type" to convert type labels to numeric strings

This commit is contained in:
Axel Kohlmeyer
2022-09-05 05:45:31 -04:00
parent e1960bbb9a
commit 75e897b2fe
5 changed files with 91 additions and 5 deletions

View File

@ -63,6 +63,13 @@ TEST_F(LabelMapTest, Atoms)
BEGIN_HIDE_OUTPUT();
command("region box block 0 2 0 2 0 2");
command("create_box 4 box");
END_HIDE_OUTPUT();
EXPECT_EQ(domain->box_exist, 1);
EXPECT_EQ(atom->lmap, nullptr);
TEST_FAILURE(".*ERROR: Type string C1 cannot be used without a labelmap.*",
utils::expand_type(FLERR, "C1", Atom::ATOM, lmp););
BEGIN_HIDE_OUTPUT();
command("labelmap atom 2 N1");
command("labelmap atom 3 O1 4 H1");
command("mass * 1.0");
@ -89,6 +96,22 @@ TEST_F(LabelMapTest, Atoms)
EXPECT_EQ(atom->lmap->find("X", Atom::ATOM), -1);
EXPECT_DOUBLE_EQ(atom->mass[3], 10.0);
EXPECT_EQ(utils::expand_type(FLERR, "1", Atom::ATOM, lmp), nullptr);
EXPECT_EQ(utils::expand_type(FLERR, "*3", Atom::ATOM, lmp), nullptr);
EXPECT_EQ(utils::expand_type(FLERR, "1*2", Atom::ATOM, lmp), nullptr);
EXPECT_EQ(utils::expand_type(FLERR, "*", Atom::ATOM, lmp), nullptr);
EXPECT_EQ(utils::expand_type(FLERR, "**", Atom::ATOM, lmp), nullptr);
EXPECT_EQ(utils::expand_type(FLERR, "1*2*", Atom::ATOM, lmp), nullptr);
auto expanded = utils::expand_type(FLERR, "C1", Atom::ATOM, lmp);
EXPECT_THAT(expanded, StrEq("1"));
delete[] expanded;
expanded = utils::expand_type(FLERR, "O#", Atom::ATOM, lmp);
EXPECT_THAT(expanded, StrEq("3"));
delete[] expanded;
TEST_FAILURE(".*ERROR: Type string XX not found in labelmap.*",
utils::expand_type(FLERR, "XX", Atom::ATOM, lmp););
TEST_FAILURE(".*ERROR: Labelmap atom type 0 must be within 1-4.*",
command("labelmap atom 0 C1"););
TEST_FAILURE(".*ERROR: Labelmap atom type 5 must be within 1-4.*",
@ -238,6 +261,24 @@ TEST_F(LabelMapTest, Topology)
EXPECT_EQ(atom->lmap->find("X", Atom::ATOM), -1);
EXPECT_EQ(atom->lmap->find("N2'-C1\"-N2'", Atom::BOND), -1);
platform::unlink("labelmap_topology.inc");
auto expanded = utils::expand_type(FLERR, "N2'", Atom::ATOM, lmp);
EXPECT_THAT(expanded, StrEq("2"));
delete[] expanded;
expanded = utils::expand_type(FLERR, "[C1][C1]", Atom::BOND, lmp);
EXPECT_THAT(expanded, StrEq("2"));
delete[] expanded;
expanded = utils::expand_type(FLERR, "C1-N2-C1", Atom::ANGLE, lmp);
EXPECT_THAT(expanded, StrEq("1"));
delete[] expanded;
expanded = utils::expand_type(FLERR, "C1-N2-C1-N2", Atom::DIHEDRAL, lmp);
EXPECT_THAT(expanded, StrEq("1"));
delete[] expanded;
expanded = utils::expand_type(FLERR, "C1-N2-C1-N2", Atom::IMPROPER, lmp);
EXPECT_THAT(expanded, StrEq("1"));
delete[] expanded;
TEST_FAILURE(".*ERROR: Type string XX not found in labelmap.*",
utils::expand_type(FLERR, "XX", Atom::BOND, lmp););
}
} // namespace LAMMPS_NS

View File

@ -33,10 +33,10 @@
bool verbose = false;
namespace LAMMPS_NS {
using MathConst::MY_PI;
using ::testing::ContainsRegex;
using ::testing::ExitedWithCode;
using ::testing::StrEq;
using MathConst::MY_PI;
class VariableTest : public LAMMPSTest {
protected:
@ -196,8 +196,10 @@ TEST_F(VariableTest, CreateDelete)
TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable"););
TEST_FAILURE(".*ERROR: Illegal variable index command.*", command("variable dummy index"););
TEST_FAILURE(".*ERROR: Illegal variable delete command: expected 2 arguments but found 3.*", command("variable dummy delete xxx"););
TEST_FAILURE(".*ERROR: Invalid variable loop argument: -1.*", command("variable dummy loop -1"););
TEST_FAILURE(".*ERROR: Illegal variable delete command: expected 2 arguments but found 3.*",
command("variable dummy delete xxx"););
TEST_FAILURE(".*ERROR: Invalid variable loop argument: -1.*",
command("variable dummy loop -1"););
TEST_FAILURE(".*ERROR: Illegal variable loop command.*", command("variable dummy loop 10 1"););
TEST_FAILURE(".*ERROR: Unknown variable keyword: xxx.*", command("variable dummy xxxx"););
TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*",
@ -402,8 +404,9 @@ TEST_F(VariableTest, Functions)
command("print \"$(extract_setting()\""););
TEST_FAILURE(".*ERROR: Invalid extract_setting.. function syntax in variable formula.*",
command("print \"$(extract_setting(one,two))\""););
TEST_FAILURE(".*ERROR: Unknown setting nprocs for extract_setting.. function in variable formula.*",
command("print \"$(extract_setting(nprocs))\""););
TEST_FAILURE(
".*ERROR: Unknown setting nprocs for extract_setting.. function in variable formula.*",
command("print \"$(extract_setting(nprocs))\""););
}
TEST_F(VariableTest, IfCommand)