simplify Molecule::check_attributes()

This commit is contained in:
Axel Kohlmeyer
2022-08-13 16:56:53 -04:00
parent 1de66a82de
commit f592e3184e
9 changed files with 42 additions and 55 deletions

View File

@ -131,7 +131,7 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) :
if (atom->molecular == Atom::TEMPLATE && onemols != atom->avec->onemols) if (atom->molecular == Atom::TEMPLATE && onemols != atom->avec->onemols)
error->all(FLERR, "Fix pour molecule template ID must be same as atom style template ID"); error->all(FLERR, "Fix pour molecule template ID must be same as atom style template ID");
onemols[i]->check_attributes(0); onemols[i]->check_attributes();
// fix pour uses geoemetric center of molecule for insertion // fix pour uses geoemetric center of molecule for insertion

View File

@ -177,7 +177,7 @@ FixGCMC::FixGCMC(LAMMPS *lmp, int narg, char **arg) :
if (atom->molecular == Atom::TEMPLATE && onemols != atom->avec->onemols) if (atom->molecular == Atom::TEMPLATE && onemols != atom->avec->onemols)
error->all(FLERR,"Fix gcmc molecule template ID must be same " error->all(FLERR,"Fix gcmc molecule template ID must be same "
"as atom_style template ID"); "as atom_style template ID");
onemols[imol]->check_attributes(0); onemols[imol]->check_attributes();
} }
if (charge_flag && atom->q == nullptr) if (charge_flag && atom->q == nullptr)

View File

@ -153,7 +153,7 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) :
if (atom->molecular == Atom::TEMPLATE && onemols != atom->avec->onemols) if (atom->molecular == Atom::TEMPLATE && onemols != atom->avec->onemols)
error->all(FLERR,"Fix widom molecule template ID must be same " error->all(FLERR,"Fix widom molecule template ID must be same "
"as atom_style template ID"); "as atom_style template ID");
onemols[imol]->check_attributes(0); onemols[imol]->check_attributes();
} }
if (charge_flag && atom->q == nullptr) if (charge_flag && atom->q == nullptr)

View File

@ -471,8 +471,8 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) :
open(files[i]); open(files[i]);
onemol = atom->molecules[unreacted_mol[i]]; onemol = atom->molecules[unreacted_mol[i]];
twomol = atom->molecules[reacted_mol[i]]; twomol = atom->molecules[reacted_mol[i]];
onemol->check_attributes(0); onemol->check_attributes();
twomol->check_attributes(0); twomol->check_attributes();
get_molxspecials(); get_molxspecials();
read(i); read(i);
fclose(fp); fclose(fp);

View File

@ -299,7 +299,7 @@ void CreateAtoms::command(int narg, char **arg)
if (onemol->tag_require && !atom->tag_enable) if (onemol->tag_require && !atom->tag_enable)
error->all(FLERR, "Create_atoms molecule has atom IDs, but system does not"); error->all(FLERR, "Create_atoms molecule has atom IDs, but system does not");
onemol->check_attributes(0); onemol->check_attributes();
// use geometric center of molecule for insertion // use geometric center of molecule for insertion
// molecule random number generator, different for each proc // molecule random number generator, different for each proc

View File

@ -117,7 +117,7 @@ FixDeposit::FixDeposit(LAMMPS *lmp, int narg, char **arg) :
if (atom->molecular == Atom::TEMPLATE && onemols != atom->avec->onemols) if (atom->molecular == Atom::TEMPLATE && onemols != atom->avec->onemols)
error->all(FLERR,"Fix deposit molecule template ID must be same " error->all(FLERR,"Fix deposit molecule template ID must be same "
"as atom_style template ID"); "as atom_style template ID");
onemols[i]->check_attributes(0); onemols[i]->check_attributes();
// fix deposit uses geoemetric center of molecule for insertion // fix deposit uses geoemetric center of molecule for insertion

View File

@ -1671,26 +1671,17 @@ int Molecule::findfragment(const char *name)
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
error check molecule attributes and topology against system settings error check molecule attributes and topology against system settings
flag = 0, just check this molecule
flag = 1, check all molecules in set, this is 1st molecule in set
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void Molecule::check_attributes(int flag) void Molecule::check_attributes()
{ {
int n = 1;
if (flag) n = nset;
int imol = atom->find_molecule(id);
for (int i = imol; i < imol+n; i++) {
Molecule *onemol = atom->molecules[imol];
// check per-atom attributes of molecule // check per-atom attributes of molecule
// warn if not a match // warn if not a match
int mismatch = 0; int mismatch = 0;
if (onemol->qflag && !atom->q_flag) mismatch = 1; if (qflag && !atom->q_flag) mismatch = 1;
if (onemol->radiusflag && !atom->radius_flag) mismatch = 1; if (radiusflag && !atom->radius_flag) mismatch = 1;
if (onemol->rmassflag && !atom->rmass_flag) mismatch = 1; if (rmassflag && !atom->rmass_flag) mismatch = 1;
if (mismatch && me == 0) if (mismatch && me == 0)
error->warning(FLERR,"Molecule attributes do not match system attributes"); error->warning(FLERR,"Molecule attributes do not match system attributes");
@ -1698,38 +1689,31 @@ void Molecule::check_attributes(int flag)
// for all atom styles, check nbondtype,etc // for all atom styles, check nbondtype,etc
mismatch = 0; mismatch = 0;
if (atom->nbondtypes < onemol->nbondtypes) mismatch = 1; if (atom->nbondtypes < nbondtypes) mismatch = 1;
if (atom->nangletypes < onemol->nangletypes) mismatch = 1; if (atom->nangletypes < nangletypes) mismatch = 1;
if (atom->ndihedraltypes < onemol->ndihedraltypes) mismatch = 1; if (atom->ndihedraltypes < ndihedraltypes) mismatch = 1;
if (atom->nimpropertypes < onemol->nimpropertypes) mismatch = 1; if (atom->nimpropertypes < nimpropertypes) mismatch = 1;
if (mismatch) if (mismatch) error->all(FLERR,"Molecule topology type exceeds system topology type");
error->all(FLERR,"Molecule topology type exceeds system topology type");
// for molecular atom styles, check bond_per_atom,etc + maxspecial // for molecular atom styles, check bond_per_atom,etc + maxspecial
// do not check for atom style template, since nothing stored per atom // do not check for atom style template, since nothing stored per atom
if (atom->molecular == Atom::MOLECULAR) { if (atom->molecular == Atom::MOLECULAR) {
if (atom->avec->bonds_allow && if (atom->avec->bonds_allow && atom->bond_per_atom < bond_per_atom) mismatch = 1;
atom->bond_per_atom < onemol->bond_per_atom) mismatch = 1; if (atom->avec->angles_allow && atom->angle_per_atom < angle_per_atom) mismatch = 1;
if (atom->avec->angles_allow && if (atom->avec->dihedrals_allow && atom->dihedral_per_atom < dihedral_per_atom) mismatch = 1;
atom->angle_per_atom < onemol->angle_per_atom) mismatch = 1; if (atom->avec->impropers_allow && atom->improper_per_atom < improper_per_atom) mismatch = 1;
if (atom->avec->dihedrals_allow && if (atom->maxspecial < maxspecial) mismatch = 1;
atom->dihedral_per_atom < onemol->dihedral_per_atom) mismatch = 1;
if (atom->avec->impropers_allow &&
atom->improper_per_atom < onemol->improper_per_atom) mismatch = 1;
if (atom->maxspecial < onemol->maxspecial) mismatch = 1;
if (mismatch) if (mismatch) error->all(FLERR,"Molecule topology/atom exceeds system topology/atom");
error->all(FLERR,"Molecule topology/atom exceeds system topology/atom");
} }
// warn if molecule topology defined but no special settings // warn if molecule topology defined but no special settings
if (onemol->bondflag && !onemol->specialflag) if (bondflag && !specialflag)
if (me == 0) error->warning(FLERR,"Molecule has bond topology but no special bond settings"); if (me == 0) error->warning(FLERR,"Molecule has bond topology but no special bond settings");
} }
}
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
init all data structures to empty init all data structures to empty

View File

@ -125,7 +125,7 @@ class Molecule : protected Pointers {
void compute_com(); void compute_com();
void compute_inertia(); void compute_inertia();
int findfragment(const char *); int findfragment(const char *);
void check_attributes(int); void check_attributes();
private: private:
int me; int me;

View File

@ -866,7 +866,10 @@ void ReadData::command(int narg, char **arg)
// insure nbondtypes,etc are still consistent with template molecules, // insure nbondtypes,etc are still consistent with template molecules,
// in case data file re-defined them // in case data file re-defined them
if (atom->molecular == Atom::TEMPLATE) atom->avec->onemols[0]->check_attributes(1); if (atom->molecular == Atom::TEMPLATE) {
int nset = MAX(1, atom->avec->onemols[0]->nset);
for (int i = 0; i < nset; ++i) atom->avec->onemols[i]->check_attributes();
}
// if adding atoms, migrate atoms to new processors // if adding atoms, migrate atoms to new processors
// use irregular() b/c box size could have changed dramaticaly // use irregular() b/c box size could have changed dramaticaly