direct support for coeff commands

pair_coeff, bond_coeff, angle_coeff, dihedral_coeff, improper_coeff
This commit is contained in:
Jacob Gissinger
2021-01-25 20:08:25 -05:00
parent c7215b54be
commit 5d2e3b3ecb
6 changed files with 80 additions and 23 deletions

View File

@ -659,6 +659,32 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag)
strcpy(str,str2); strcpy(str,str2);
} }
/* ----------------------------------------------------------------------
substitute type labels with numeric value
reallocate str to hold expanded version if necessary
if type already starts with a number, do not modify
------------------------------------------------------------------------- */
void Input::readtype(char *&str, int mode)
{
if (isdigit(str[0])) return;
if (!atom->labelmapflag) error->all(FLERR,fmt::format("Invalid type {}",str));
int type,max,max2;
std::string labelstr;
char typechar[256];
labelstr = str;
type = atom->lmap->find(labelstr,mode);
if (type == -1) error->all(FLERR,fmt::format("Invalid type {}",str));
sprintf(typechar,"%d",type);
max = strlen(str) + 1;
max2 = strlen(typechar) + 1;
if (max2 > max) reallocate(str,max,max2);
strcpy(str,typechar);
}
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
return number of triple quotes in line return number of triple quotes in line
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
@ -1303,6 +1329,7 @@ void Input::angle_coeff()
error->all(FLERR,"Angle_coeff command before angle_style is defined"); error->all(FLERR,"Angle_coeff command before angle_style is defined");
if (atom->avec->angles_allow == 0) if (atom->avec->angles_allow == 0)
error->all(FLERR,"Angle_coeff command when no angles allowed"); error->all(FLERR,"Angle_coeff command when no angles allowed");
readtype(arg[0],atom->lmap->ANGLE);
force->angle->coeff(narg,arg); force->angle->coeff(narg,arg);
} }
@ -1344,6 +1371,7 @@ void Input::bond_coeff()
error->all(FLERR,"Bond_coeff command before bond_style is defined"); error->all(FLERR,"Bond_coeff command before bond_style is defined");
if (atom->avec->bonds_allow == 0) if (atom->avec->bonds_allow == 0)
error->all(FLERR,"Bond_coeff command when no bonds allowed"); error->all(FLERR,"Bond_coeff command when no bonds allowed");
readtype(arg[0],atom->lmap->BOND);
force->bond->coeff(narg,arg); force->bond->coeff(narg,arg);
} }
@ -1447,6 +1475,7 @@ void Input::dihedral_coeff()
error->all(FLERR,"Dihedral_coeff command before dihedral_style is defined"); error->all(FLERR,"Dihedral_coeff command before dihedral_style is defined");
if (atom->avec->dihedrals_allow == 0) if (atom->avec->dihedrals_allow == 0)
error->all(FLERR,"Dihedral_coeff command when no dihedrals allowed"); error->all(FLERR,"Dihedral_coeff command when no dihedrals allowed");
readtype(arg[0],atom->lmap->DIHEDRAL);
force->dihedral->coeff(narg,arg); force->dihedral->coeff(narg,arg);
} }
@ -1524,6 +1553,7 @@ void Input::improper_coeff()
error->all(FLERR,"Improper_coeff command before improper_style is defined"); error->all(FLERR,"Improper_coeff command before improper_style is defined");
if (atom->avec->impropers_allow == 0) if (atom->avec->impropers_allow == 0)
error->all(FLERR,"Improper_coeff command when no impropers allowed"); error->all(FLERR,"Improper_coeff command when no impropers allowed");
readtype(arg[0],atom->lmap->IMPROPER);
force->improper->coeff(narg,arg); force->improper->coeff(narg,arg);
} }
@ -1701,6 +1731,8 @@ void Input::pair_coeff()
error->all(FLERR,"Pair_coeff command before simulation box is defined"); error->all(FLERR,"Pair_coeff command before simulation box is defined");
if (force->pair == nullptr) if (force->pair == nullptr)
error->all(FLERR,"Pair_coeff command before pair_style is defined"); error->all(FLERR,"Pair_coeff command before pair_style is defined");
readtype(arg[0],atom->lmap->ATOM);
readtype(arg[1],atom->lmap->ATOM);
force->pair->coeff(narg,arg); force->pair->coeff(narg,arg);
} }

View File

@ -38,6 +38,7 @@ class Input : protected Pointers {
char *one(const std::string&); // process a single command char *one(const std::string&); // process a single command
void substitute(char *&, char *&, int &, int &, int); void substitute(char *&, char *&, int &, int &, int);
// substitute for variables in a string // substitute for variables in a string
void readtype(char *&, int); // substitute type label with numeric type
void write_echo(const std::string &); // send text to active echo file pointers void write_echo(const std::string &); // send text to active echo file pointers
protected: protected:

View File

@ -148,27 +148,27 @@ void LabelMap::create_lmap2lmap(LabelMap *lmap2, int mode)
{ {
if (mode == ATOM) if (mode == ATOM)
for (int i = 0; i < natomtypes; i++) for (int i = 0; i < natomtypes; i++)
lmap2lmap.atom[i] = find(typelabel[i],lmap2->typelabel, lmap2lmap.atom[i] = search(typelabel[i],lmap2->typelabel,
lmap2->natomtypes); lmap2->natomtypes);
if (mode == BOND) if (mode == BOND)
for (int i = 0; i < nbondtypes; i++) for (int i = 0; i < nbondtypes; i++)
lmap2lmap.bond[i] = find(btypelabel[i],lmap2->btypelabel, lmap2lmap.bond[i] = search(btypelabel[i],lmap2->btypelabel,
lmap2->nbondtypes); lmap2->nbondtypes);
if (mode == ANGLE) if (mode == ANGLE)
for (int i = 0; i < nangletypes; i++) for (int i = 0; i < nangletypes; i++)
lmap2lmap.angle[i] = find(atypelabel[i],lmap2->atypelabel, lmap2lmap.angle[i] = search(atypelabel[i],lmap2->atypelabel,
lmap2->nangletypes); lmap2->nangletypes);
if (mode == DIHEDRAL) if (mode == DIHEDRAL)
for (int i = 0; i < ndihedraltypes; i++) for (int i = 0; i < ndihedraltypes; i++)
lmap2lmap.dihedral[i] = find(dtypelabel[i],lmap2->dtypelabel, lmap2lmap.dihedral[i] = search(dtypelabel[i],lmap2->dtypelabel,
lmap2->ndihedraltypes); lmap2->ndihedraltypes);
if (mode == IMPROPER) if (mode == IMPROPER)
for (int i = 0; i < nimpropertypes; i++) for (int i = 0; i < nimpropertypes; i++)
lmap2lmap.improper[i] = find(itypelabel[i],lmap2->itypelabel, lmap2lmap.improper[i] = search(itypelabel[i],lmap2->itypelabel,
lmap2->nimpropertypes); lmap2->nimpropertypes);
} }
@ -199,11 +199,34 @@ int LabelMap::find_or_create(std::string mylabel, std::vector<std::string> &labe
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
find integer type given a type label return numeric type given a type label
return -1 if type not yet defined return -1 if type not yet defined
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
int LabelMap::find(std::string mylabel, std::vector<std::string> labels, int ntypes) int LabelMap::find(std::string mylabel, int mode)
{
if (mode == ATOM)
return search(mylabel,typelabel,natomtypes);
if (mode == BOND)
return search(mylabel,btypelabel,nbondtypes);
if (mode == ANGLE)
return search(mylabel,atypelabel,nangletypes);
if (mode == DIHEDRAL)
return search(mylabel,dtypelabel,ndihedraltypes);
if (mode == IMPROPER)
return search(mylabel,itypelabel,nimpropertypes);
}
/* ----------------------------------------------------------------------
get index+1 given vector of strings
return -1 if type not yet defined
------------------------------------------------------------------------- */
int LabelMap::search(std::string mylabel, std::vector<std::string> labels, int ntypes)
{ {
for (int i = 0; i < ntypes; i++) for (int i = 0; i < ntypes; i++)
if (labels[i] == mylabel) return i+1; if (labels[i] == mylabel) return i+1;

View File

@ -46,7 +46,8 @@ class LabelMap : protected Pointers {
void merge_lmap(class LabelMap *, int); // copy another lmap into this one void merge_lmap(class LabelMap *, int); // copy another lmap into this one
void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps
int find_or_create(std::string, std::vector<std::string> &, int); // look up type or create new type int find_or_create(std::string, std::vector<std::string> &, int); // look up type or create new type
int find(std::string, std::vector<std::string>, int); // look up type index int find(std::string, int); // find numeric type of type label
int search(std::string, std::vector<std::string>, int); // look up type index
// input/output for atom class label map // input/output for atom class label map

View File

@ -729,7 +729,7 @@ void Molecule::types(char *line)
typestr = values.next_string(); typestr = values.next_string();
if (!isdigit(typestr[0])) { if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Types section in molecule file"); if (!atom->labelmapflag) error->one(FLERR,"Invalid Types section in molecule file");
type[iatom] = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes); type[iatom] = atom->lmap->find(typestr,atom->lmap->ATOM);
if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file"); if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file");
} else type[iatom] = utils::inumeric(FLERR,typestr.c_str(),false,lmp); } else type[iatom] = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
type[iatom] += toffset; type[iatom] += toffset;
@ -942,7 +942,7 @@ void Molecule::bonds(int flag, char *line)
typestr = values.next_string(); typestr = values.next_string();
if (!isdigit(typestr[0])) { if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in molecule file"); if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in molecule file");
itype = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes); itype = atom->lmap->find(typestr,atom->lmap->BOND);
if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file"); if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file");
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
atom1 = values.next_tagint(); atom1 = values.next_tagint();
@ -1016,7 +1016,7 @@ void Molecule::angles(int flag, char *line)
typestr = values.next_string(); typestr = values.next_string();
if (!isdigit(typestr[0])) { if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in molecule file"); if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in molecule file");
itype = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes); itype = atom->lmap->find(typestr,atom->lmap->ANGLE);
if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file"); if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file");
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
atom1 = values.next_tagint(); atom1 = values.next_tagint();
@ -1106,7 +1106,7 @@ void Molecule::dihedrals(int flag, char *line)
typestr = values.next_string(); typestr = values.next_string();
if (!isdigit(typestr[0])) { if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in molecule file"); if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in molecule file");
itype = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes); itype = atom->lmap->find(typestr,atom->lmap->DIHEDRAL);
if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file"); if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file");
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
atom1 = values.next_tagint(); atom1 = values.next_tagint();
@ -1211,7 +1211,7 @@ void Molecule::impropers(int flag, char *line)
typestr = values.next_string(); typestr = values.next_string();
if (!isdigit(typestr[0])) { if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in molecule file"); if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in molecule file");
itype = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes); itype = atom->lmap->find(typestr,atom->lmap->IMPROPER);
if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file"); if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file");
} else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp);
atom1 = values.next_tagint(); atom1 = values.next_tagint();

View File

@ -4541,19 +4541,19 @@ int Variable::labelmap_function(char *word, char *contents, Tree **tree,
std::string typestr = contents; std::string typestr = contents;
if (strcmp(word,"label") == 0) { if (strcmp(word,"label") == 0) {
value = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes); value = atom->lmap->find(typestr,atom->lmap->ATOM);
} else if (strcmp(word,"blabel") == 0) { } else if (strcmp(word,"blabel") == 0) {
value = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes); value = atom->lmap->find(typestr,atom->lmap->BOND);
} else if (strcmp(word,"alabel") == 0) { } else if (strcmp(word,"alabel") == 0) {
value = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes); value = atom->lmap->find(typestr,atom->lmap->ANGLE);
} else if (strcmp(word,"dlabel") == 0) { } else if (strcmp(word,"dlabel") == 0) {
value = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes); value = atom->lmap->find(typestr,atom->lmap->DIHEDRAL);
} else if (strcmp(word,"ilabel") == 0) { } else if (strcmp(word,"ilabel") == 0) {
value = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes); value = atom->lmap->find(typestr,atom->lmap->IMPROPER);
} }
if (value == -1) if (value == -1)