From 3b6a06fcf53da95d2f2f246aec27b7e97aa3684e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 6 Sep 2022 18:18:44 -0400 Subject: [PATCH] small behavior tweaks for inputs without labelmap, add warnings about type offsets --- src/molecule.cpp | 8 ++++++++ src/read_data.cpp | 13 +++++++++++-- src/utils.cpp | 4 +++- unittest/commands/test_labelmap.cpp | 11 ++++++++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/molecule.cpp b/src/molecule.cpp index 00c4d962af..3ec2a22757 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -115,6 +115,14 @@ Molecule::Molecule(LAMMPS *lmp, int narg, char **arg, int &index) : index = iarg; + if (atom->labelmapflag && + ((toffset > 0) || (boffset > 0) || (aoffset > 0) || (doffset > 0) || (ioffset > 0))) { + if (comm->me == 0) + error->warning(FLERR, + "Using molecule command with type offsets and a labelmap. " + "Offsets will be only applied to numeric types and not to type labels"); + } + // last molecule if have scanned all args if (iarg == narg) diff --git a/src/read_data.cpp b/src/read_data.cpp index a880ae83f6..2e3dd82c72 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -337,8 +337,17 @@ void ReadData::command(int narg, char **arg) error->all(FLERR, "Cannot use read_data without add keyword after simulation box is defined"); if (!domain->box_exist && addflag) error->all(FLERR, "Cannot use read_data add before simulation box is defined"); - if (offsetflag && addflag == NONE) - error->all(FLERR, "Cannot use read_data offset without add keyword"); + if (offsetflag) { + if (addflag == NONE) { + error->all(FLERR, "Cannot use read_data offset without add keyword"); + } else { + if (atom->labelmapflag) { + if (comm->me == 0) + error->warning(FLERR, "Using read_data offset with a labelmap. Offsets will be only " + "applied to numeric types and not to type labels"); + } + } + } if (shiftflag && addflag == NONE) error->all(FLERR, "Cannot use read_data shift without add keyword"); if (addflag != NONE && diff --git a/src/utils.cpp b/src/utils.cpp index cd4c0892d1..f0e37424a2 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -777,7 +777,9 @@ static const char *labeltypes[] = {"Atom", "Bond", "Angle", "Dihedral", "Imprope char *utils::expand_type(const char *file, int line, const std::string &str, int mode, LAMMPS *lmp) { if (!lmp) return nullptr; - const std::string typestr = utils::utf8_subst(str); + if (!lmp->atom->labelmapflag) return nullptr; + + const std::string typestr = utils::utf8_subst(utils::trim(str)); if (is_type(typestr) == 1) { if (!lmp->atom->labelmapflag) lmp->error->all(file, line, "{} type string {} cannot be used without a labelmap", diff --git a/unittest/commands/test_labelmap.cpp b/unittest/commands/test_labelmap.cpp index 1f2b599550..f847beba13 100644 --- a/unittest/commands/test_labelmap.cpp +++ b/unittest/commands/test_labelmap.cpp @@ -56,6 +56,7 @@ TEST_F(LabelMapTest, Atoms) { EXPECT_EQ(atom->natoms, 0); EXPECT_EQ(domain->box_exist, 0); + EXPECT_EQ(atom->labelmapflag, 0); ASSERT_EQ(atom->lmap, nullptr); TEST_FAILURE(".*ERROR: Labelmap command before simulation box is.*", command("labelmap atom 3 C1");); @@ -66,8 +67,8 @@ TEST_F(LabelMapTest, Atoms) END_HIDE_OUTPUT(); EXPECT_EQ(domain->box_exist, 1); EXPECT_EQ(atom->lmap, nullptr); - TEST_FAILURE(".*ERROR: Atom type string C1 cannot be used without a labelmap.*", - utils::expand_type(FLERR, "C1", Atom::ATOM, lmp);); + EXPECT_EQ(atom->labelmapflag, 0); + EXPECT_EQ(utils::expand_type(FLERR, "C1", Atom::ATOM, lmp), nullptr); BEGIN_HIDE_OUTPUT(); command("labelmap atom 2 N1"); @@ -77,6 +78,7 @@ TEST_F(LabelMapTest, Atoms) command("mass N1 2.0"); command("mass H1 4.0"); END_HIDE_OUTPUT(); + EXPECT_EQ(atom->labelmapflag, 1); ASSERT_NE(atom->lmap, nullptr); EXPECT_FALSE(atom->lmap->is_complete(Atom::ATOM)); EXPECT_DOUBLE_EQ(atom->mass[1], 1.0); @@ -182,6 +184,7 @@ TEST_F(LabelMapTest, Topology) EXPECT_EQ(atom->ndihedrals, 0); EXPECT_EQ(atom->nimpropers, 0); EXPECT_EQ(domain->box_exist, 0); + EXPECT_EQ(atom->labelmapflag, 0); ASSERT_EQ(atom->lmap, nullptr); TEST_FAILURE(".*ERROR: Labelmap command before simulation box is.*", command("labelmap atom 3 C1");); @@ -192,6 +195,7 @@ TEST_F(LabelMapTest, Topology) command("create_box 2 box bond/types 3 angle/types 2 dihedral/types 1 improper/types 1"); command("labelmap atom 1 C1"); END_HIDE_OUTPUT(); + EXPECT_EQ(atom->labelmapflag, 1); ASSERT_NE(atom->lmap, nullptr); EXPECT_FALSE(atom->lmap->is_complete(Atom::ATOM)); EXPECT_FALSE(atom->lmap->is_complete(Atom::BOND)); @@ -233,7 +237,8 @@ TEST_F(LabelMapTest, Topology) command("labelmap clear"); command("labelmap atom 1 C1"); END_HIDE_OUTPUT(); - EXPECT_NE(atom->lmap, nullptr); + EXPECT_EQ(atom->labelmapflag, 1); + ASSERT_NE(atom->lmap, nullptr); EXPECT_FALSE(atom->lmap->is_complete(Atom::ATOM)); EXPECT_FALSE(atom->lmap->is_complete(Atom::BOND)); EXPECT_FALSE(atom->lmap->is_complete(Atom::ANGLE));