force unique labels in data file

note: not possible to create duplicate label in a second data file (if duplicate, assigns to existing label)
still need to enforce unique labels when using labelmap command
This commit is contained in:
Jacob Gissinger
2021-11-07 01:01:41 -04:00
parent 3fc47a9366
commit 5bc399c22b
2 changed files with 36 additions and 19 deletions

View File

@ -242,30 +242,47 @@ int LabelMap::search(const std::string &mylabel,
}
/* ----------------------------------------------------------------------
check if all types have been assigned a type label
check that all types have been assigned a unique type label
------------------------------------------------------------------------- */
int LabelMap::is_complete(int mode)
{
int i,j;
if (mode == Atom::ATOM)
for (int i = 0; i < natomtypes; i++)
if (typelabel[i].empty()) return 0;
for (i = 0; i < natomtypes; i++) {
if (typelabel[i].empty()) return 0;
for (j = i+1; j < natomtypes; j++)
if (typelabel[i] == typelabel[j]) return 0;
}
if (force->bond && mode == Atom::BOND)
for (int i = 0; i < nbondtypes; i++)
for (i = 0; i < nbondtypes; i++) {
if (btypelabel[i].empty()) return 0;
for (j = i+1; j < nbondtypes; j++)
if (btypelabel[i] == btypelabel[j]) return 0;
}
if (force->angle && mode == Atom::ANGLE)
for (int i = 0; i < nangletypes; i++)
for (i = 0; i < nangletypes; i++) {
if (atypelabel[i].empty()) return 0;
for (j = i+1; j < nangletypes; j++)
if (atypelabel[i] == atypelabel[j]) return 0;
}
if (force->dihedral && mode == Atom::DIHEDRAL)
for (int i = 0; i < ndihedraltypes; i++)
for (i = 0; i < ndihedraltypes; i++) {
if (dtypelabel[i].empty()) return 0;
for (j = i+1; j < ndihedraltypes; j++)
if (dtypelabel[i] == dtypelabel[j]) return 0;
}
if (force->improper && mode == Atom::IMPROPER)
for (int i = 0; i < nimpropertypes; i++)
for (i = 0; i < nimpropertypes; i++) {
if (itypelabel[i].empty()) return 0;
for (j = i+1; j < nimpropertypes; j++)
if (itypelabel[i] == itypelabel[j]) return 0;
}
return 1;
}

View File

@ -1304,7 +1304,7 @@ void ReadData::atoms()
if (eof) error->all(FLERR,"Unexpected end of data file");
if (tlabelflag && !lmap->is_complete(Atom::ATOM))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
atom->data_atoms(nchunk,buffer,id_offset,mol_offset,toffset,
shiftflag,shift,tlabelflag,lmap->lmap2lmap.atom);
nread += nchunk;
@ -1422,7 +1422,7 @@ void ReadData::bonds(int firstpass)
if (eof) error->all(FLERR,"Unexpected end of data file");
if (blabelflag && !lmap->is_complete(Atom::BOND))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
atom->data_bonds(nchunk,buffer,count,id_offset,boffset,
blabelflag,lmap->lmap2lmap.bond);
nread += nchunk;
@ -1500,7 +1500,7 @@ void ReadData::angles(int firstpass)
if (eof) error->all(FLERR,"Unexpected end of data file");
if (alabelflag && !lmap->is_complete(Atom::ANGLE))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
atom->data_angles(nchunk,buffer,count,id_offset,aoffset,
alabelflag,lmap->lmap2lmap.angle);
nread += nchunk;
@ -1578,7 +1578,7 @@ void ReadData::dihedrals(int firstpass)
if (eof) error->all(FLERR,"Unexpected end of data file");
if (dlabelflag && !lmap->is_complete(Atom::DIHEDRAL))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
atom->data_dihedrals(nchunk,buffer,count,id_offset,doffset,
dlabelflag,lmap->lmap2lmap.dihedral);
nread += nchunk;
@ -1656,7 +1656,7 @@ void ReadData::impropers(int firstpass)
if (eof) error->all(FLERR,"Unexpected end of data file");
if (ilabelflag && !lmap->is_complete(Atom::IMPROPER))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
atom->data_impropers(nchunk,buffer,count,id_offset,ioffset,
ilabelflag,lmap->lmap2lmap.improper);
nread += nchunk;
@ -1853,7 +1853,7 @@ void ReadData::mass()
if (eof) error->all(FLERR,"Unexpected end of data file");
if (tlabelflag && !lmap->is_complete(Atom::ATOM))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
char *original = buf;
for (int i = 0; i < ntypes; i++) {
@ -1877,7 +1877,7 @@ void ReadData::paircoeffs()
if (tlabelflag && !lmap->is_complete(Atom::ATOM))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
char *original = buf;
for (int i = 0; i < ntypes; i++) {
@ -1908,7 +1908,7 @@ void ReadData::pairIJcoeffs()
if (tlabelflag && !lmap->is_complete(Atom::ATOM))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
char *original = buf;
for (i = 0; i < ntypes; i++)
@ -1939,7 +1939,7 @@ void ReadData::bondcoeffs()
if (blabelflag && !lmap->is_complete(Atom::BOND))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
char *original = buf;
for (int i = 0; i < nbondtypes; i++) {
@ -1968,7 +1968,7 @@ void ReadData::anglecoeffs(int which)
if (alabelflag && !lmap->is_complete(Atom::ANGLE))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
char *original = buf;
for (int i = 0; i < nangletypes; i++) {
@ -2001,7 +2001,7 @@ void ReadData::dihedralcoeffs(int which)
if (dlabelflag && !lmap->is_complete(Atom::DIHEDRAL))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
char *original = buf;
for (int i = 0; i < ndihedraltypes; i++) {
@ -2041,7 +2041,7 @@ void ReadData::impropercoeffs(int which)
if (ilabelflag && !lmap->is_complete(Atom::IMPROPER))
error->all(FLERR,"Label map is incomplete. "
"All types must be assigned a type label.");
"All types must be assigned a unique type label.");
char *original = buf;
for (int i = 0; i < nimpropertypes; i++) {