small behavior tweaks for inputs without labelmap, add warnings about type offsets

This commit is contained in:
Axel Kohlmeyer
2022-09-06 18:18:44 -04:00
parent 1a5a509c1d
commit 3b6a06fcf5
4 changed files with 30 additions and 6 deletions

View File

@ -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)

View File

@ -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)
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 &&

View File

@ -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",

View File

@ -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));