refactor to use read_data local lmap
also add errors to enforce order of read_data sections
This commit is contained in:
15
doc/src/Errors_messages.rst
Normal file → Executable file
15
doc/src/Errors_messages.rst
Normal file → Executable file
@ -5860,6 +5860,12 @@ Doc page with :doc:`WARNING messages <Errors_warnings>`
|
||||
*Must not have multiple fixes change box parameter ...*
|
||||
Self-explanatory.
|
||||
|
||||
*Must read Angle Type Labels before Angles*
|
||||
An Angle Type Labels section of a data file must come before the Angles section.
|
||||
|
||||
*Must read Atom Type Labels before Atoms*
|
||||
An Atom Type Labels section of a data file must come before the Atoms section.
|
||||
|
||||
*Must read Atoms before Angles*
|
||||
The Atoms section of a data file must come before an Angles section.
|
||||
|
||||
@ -5890,6 +5896,15 @@ Doc page with :doc:`WARNING messages <Errors_warnings>`
|
||||
The Atoms section of a data file must come before a Velocities
|
||||
section.
|
||||
|
||||
*Must read Bond Type Labels before Bonds*
|
||||
A Bond Type Labels section of a data file must come before the Bonds section.
|
||||
|
||||
*Must read Dihedral Type Labels before Dihedrals*
|
||||
An Dihedral Type Labels section of a data file must come before the Dihedrals section.
|
||||
|
||||
*Must read Improper Type Labels before Impropers*
|
||||
An Improper Type Labels section of a data file must come before the Impropers section.
|
||||
|
||||
*Must re-specify non-restarted pair style (xxx) after read_restart*
|
||||
For pair styles, that do not store their settings in a restart file,
|
||||
it must be defined with a new 'pair_style' command after read_restart.
|
||||
|
||||
37
src/label_map.cpp
Normal file → Executable file
37
src/label_map.cpp
Normal file → Executable file
@ -78,6 +78,43 @@ void LabelMap::allocate_type_labels()
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
copy lmap1 to lmap2
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void LabelMap::copy_lmap(LabelMap *lmap1, LabelMap *lmap2)
|
||||
{
|
||||
int ncopy;
|
||||
|
||||
ncopy = min(lmap1->natomtypes, lmap2->natomtypes);
|
||||
for (int i = 0; i < ncopy; i++)
|
||||
lmap2->typelabel[i] = lmap1->typelabel[i];
|
||||
|
||||
if (force->bond) {
|
||||
ncopy = min(lmap1->nbondtypes, lmap2->nbondtypes);
|
||||
for (int i = 0; i < ncopy; i++)
|
||||
lmap1->btypelabel[i] = lmap2->btypelabel[i];
|
||||
}
|
||||
|
||||
if (force->angle) {
|
||||
ncopy = min(lmap1->nangletypes, lmap2->nangletypes);
|
||||
for (int i = 0; i < ncopy; i++)
|
||||
lmap1->atypelabel[i] = lmap2->atypelabel[i];
|
||||
}
|
||||
|
||||
if (force->dihedral) {
|
||||
ncopy = min(lmap1->ndihedraltypes, lmap2->ndihedraltypes);
|
||||
for (int i = 0; i < ncopy; i++)
|
||||
lmap1->dtypelabel[i] = lmap2->dtypelabel[i];
|
||||
}
|
||||
|
||||
if (force->improper) {
|
||||
ncopy = min(lmap1->nimpropertypes, lmap2->nimpropertypes);
|
||||
for (int i = 0; i < ncopy; i++)
|
||||
lmap1->itypelabel[i] = lmap2->itypelabel[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
find integer type given a type label
|
||||
return -1 if type not yet defined
|
||||
|
||||
1
src/label_map.h
Normal file → Executable file
1
src/label_map.h
Normal file → Executable file
@ -29,6 +29,7 @@ class LabelMap : protected Pointers {
|
||||
~LabelMap();
|
||||
|
||||
void allocate_type_labels();
|
||||
void copy_lmap(class LabelMap *, class LabelMap *);
|
||||
int find_type(char *, char **, int);
|
||||
|
||||
protected:
|
||||
|
||||
68
src/read_data.cpp
Normal file → Executable file
68
src/read_data.cpp
Normal file → Executable file
@ -490,6 +490,18 @@ void ReadData::command(int narg, char **arg)
|
||||
domain->set_local_box();
|
||||
}
|
||||
|
||||
// allocate space for type label map
|
||||
|
||||
if (firstpass) {
|
||||
lmap = new LabelMap(lmp);
|
||||
lmap->natomtypes = ntypes;
|
||||
lmap->nbondtypes = nbondtypes;
|
||||
lmap->nangletypes = nangletypes;
|
||||
lmap->ndihedraltypes = ndihedraltypes;
|
||||
lmap->nimpropertypes = nimpropertypes;
|
||||
lmap->allocate_type_labels();
|
||||
}
|
||||
|
||||
// customize for new sections
|
||||
// read rest of file in free format
|
||||
|
||||
@ -715,28 +727,47 @@ void ReadData::command(int narg, char **arg)
|
||||
else skip_lines(nimpropertypes);
|
||||
|
||||
} else if (strcmp(keyword,"Atom Type Labels") == 0) {
|
||||
if (firstpass) typelabels(atom->lmap->typelabel,ntypes);
|
||||
else skip_lines(ntypes);
|
||||
if (firstpass) {
|
||||
if (atomflag == 1)
|
||||
error->all(FLERR,"Must read Atom Type Labels before Atoms");
|
||||
typelabels(lmap->typelabel,ntypes);
|
||||
} else skip_lines(ntypes);
|
||||
|
||||
} else if (strcmp(keyword,"Bond Type Labels") == 0) {
|
||||
if (nbondtypes)
|
||||
if (firstpass) typelabels(atom->lmap->btypelabel,nbondtypes);
|
||||
else skip_lines(nbondtypes);
|
||||
if (nbondtypes) {
|
||||
if (firstpass) {
|
||||
if (bondflag == 1)
|
||||
error->all(FLERR,"Must read Bond Type Labels before Bonds");
|
||||
typelabels(lmap->btypelabel,nbondtypes);
|
||||
} else skip_lines(nbondtypes);
|
||||
}
|
||||
|
||||
} else if (strcmp(keyword,"Angle Type Labels") == 0) {
|
||||
if (nangletypes)
|
||||
if (firstpass) typelabels(atom->lmap->atypelabel,nangletypes);
|
||||
else skip_lines(nangletypes);
|
||||
if (nangletypes) {
|
||||
if (firstpass) {
|
||||
if (angleflag == 1)
|
||||
error->all(FLERR,"Must read Angle Type Labels before Angles");
|
||||
typelabels(lmap->atypelabel,nangletypes);
|
||||
} else skip_lines(nangletypes);
|
||||
}
|
||||
|
||||
} else if (strcmp(keyword,"Dihedral Type Labels") == 0) {
|
||||
if (ndihedraltypes)
|
||||
if (firstpass) typelabels(atom->lmap->dtypelabel,ndihedraltypes);
|
||||
else skip_lines(ndihedraltypes);
|
||||
if (ndihedraltypes) {
|
||||
if (firstpass) {
|
||||
if (dihedralflag == 1)
|
||||
error->all(FLERR,"Must read Dihedral Type Labels before Dihedrals");
|
||||
typelabels(lmap->dtypelabel,ndihedraltypes);
|
||||
} else skip_lines(ndihedraltypes);
|
||||
}
|
||||
|
||||
} else if (strcmp(keyword,"Improper Type Labels") == 0) {
|
||||
if (nimpropertypes)
|
||||
if (firstpass) typelabels(atom->lmap->itypelabel,nimpropertypes);
|
||||
else skip_lines(nimpropertypes);
|
||||
if (nimpropertypes) {
|
||||
if (firstpass) {
|
||||
if (improperflag == 1)
|
||||
error->all(FLERR,"Must read Improper Type Labels before Impropers");
|
||||
typelabels(lmap->itypelabel,nimpropertypes);
|
||||
} else skip_lines(nimpropertypes);
|
||||
}
|
||||
|
||||
} else error->all(FLERR,fmt::format("Unknown identifier in data file: {}",
|
||||
keyword));
|
||||
@ -1949,6 +1980,15 @@ void ReadData::typelabels(std::vector<std::string> &mytypelabel, int myntypes)
|
||||
buf = next + 1;
|
||||
}
|
||||
delete [] typelabel;
|
||||
|
||||
// if first data file, assign this label map to atom class
|
||||
// else, determine mapping to let labels override numeric types
|
||||
|
||||
if (addflag == NONE) {
|
||||
lmap->copy_lmap(lmap,atom->lmap);
|
||||
} else {
|
||||
; // get lmap2lmap mapping. ...in progress...
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
24
src/read_data.h
Normal file → Executable file
24
src/read_data.h
Normal file → Executable file
@ -55,6 +55,10 @@ class ReadData : protected Pointers {
|
||||
bigint nbodies;
|
||||
class AtomVecBody *avec_body;
|
||||
|
||||
// type labels
|
||||
|
||||
class LabelMap *lmap;
|
||||
|
||||
// box info
|
||||
|
||||
double boxlo[3],boxhi[3];
|
||||
@ -398,6 +402,26 @@ E: Must define improper_style before AngleAngle Coeffs
|
||||
Must use an improper_style command before reading a data file that
|
||||
defines AngleAngle Coeffs.
|
||||
|
||||
E: Must read Atom Type Labels before Atoms
|
||||
|
||||
An Atom Type Labels section of a data file must come before the Atoms section.
|
||||
|
||||
E: Must read Bond Type Labels before Bonds
|
||||
|
||||
A Bond Type Labels section of a data file must come before the Bonds section.
|
||||
|
||||
E: Must read Angle Type Labels before Angles
|
||||
|
||||
An Angle Type Labels section of a data file must come before the Angles section.
|
||||
|
||||
E: Must read Dihedral Type Labels before Dihedrals
|
||||
|
||||
An Dihedral Type Labels section of a data file must come before the Dihedrals section.
|
||||
|
||||
E: Must read Improper Type Labels before Impropers
|
||||
|
||||
An Improper Type Labels section of a data file must come before the Impropers section.
|
||||
|
||||
E: Unknown identifier in data file: %s
|
||||
|
||||
A section of the data file cannot be read by LAMMPS.
|
||||
|
||||
Reference in New Issue
Block a user