begin unfeaturing multiple label maps feature

This commit is contained in:
Jacob Gissinger
2022-08-09 01:01:31 -04:00
parent 8c8084a027
commit 363b80f85c
10 changed files with 49 additions and 86 deletions

View File

@ -226,8 +226,7 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp)
// type labels // type labels
nlmap = 0; lmap = nullptr;
lmaps = nullptr;
// custom atom arrays // custom atom arrays
@ -348,8 +347,7 @@ Atom::~Atom()
// delete label maps // delete label maps
for (int i = 0; i < nlmap; i++) delete lmaps[i]; memory->sfree(lmap);
memory->sfree(lmaps);
// delete per-type arrays // delete per-type arrays
@ -1166,7 +1164,7 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset,
if (mol_offset) molecule[nlocal-1] += mol_offset; if (mol_offset) molecule[nlocal-1] += mol_offset;
if (!isdigit(typestr[0])) { if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Atoms section in data file"); if (!atom->labelmapflag) error->one(FLERR,"Invalid Atoms section in data file");
type[nlocal-1] = find_label(typestr,Atom::ATOM); type[nlocal-1] = lmap->find(typestr,Atom::ATOM);
if (type[nlocal-1] == -1) error->one(FLERR,"Invalid Atoms section in data file"); if (type[nlocal-1] == -1) error->one(FLERR,"Invalid Atoms section in data file");
} else { } else {
type[nlocal-1] = utils::inumeric(FLERR,typestr.c_str(),true,lmp); type[nlocal-1] = utils::inumeric(FLERR,typestr.c_str(),true,lmp);
@ -1254,7 +1252,7 @@ void Atom::data_bonds(int n, char *buf, int *count, tagint id_offset,
} }
if (!isdigit(typestr[0])) { if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in data file"); if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in data file");
itype = find_label(typestr,Atom::BOND); itype = lmap->find(typestr,Atom::BOND);
if (itype == -1) error->one(FLERR,"Invalid Bonds section in data file"); if (itype == -1) error->one(FLERR,"Invalid Bonds section in data file");
} else { } else {
itype = utils::inumeric(FLERR,typestr,true,lmp); itype = utils::inumeric(FLERR,typestr,true,lmp);
@ -1333,7 +1331,7 @@ void Atom::data_angles(int n, char *buf, int *count, tagint id_offset,
} }
if (!isdigit(typestr[0])) { if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in data file"); if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in data file");
itype = find_label(typestr,Atom::ANGLE); itype = lmap->find(typestr,Atom::ANGLE);
if (itype == -1) error->one(FLERR,"Invalid Angles section in data file"); if (itype == -1) error->one(FLERR,"Invalid Angles section in data file");
} else { } else {
itype = utils::inumeric(FLERR,typestr,true,lmp); itype = utils::inumeric(FLERR,typestr,true,lmp);
@ -1428,7 +1426,7 @@ void Atom::data_dihedrals(int n, char *buf, int *count, tagint id_offset,
} }
if (!isdigit(typestr[0])) { if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in data file"); if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in data file");
itype = find_label(typestr,Atom::DIHEDRAL); itype = lmap->find(typestr,Atom::DIHEDRAL);
if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in data file"); if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in data file");
} else { } else {
itype = utils::inumeric(FLERR,typestr,true,lmp); itype = utils::inumeric(FLERR,typestr,true,lmp);
@ -1539,7 +1537,7 @@ void Atom::data_impropers(int n, char *buf, int *count, tagint id_offset,
} }
if (!isdigit(typestr[0])) { if (!isdigit(typestr[0])) {
if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in data file"); if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in data file");
itype = find_label(typestr,Atom::IMPROPER); itype = lmap->find(typestr,Atom::IMPROPER);
if (itype == -1) error->one(FLERR,"Invalid Impropers section in data file"); if (itype == -1) error->one(FLERR,"Invalid Impropers section in data file");
} else { } else {
itype = utils::inumeric(FLERR,typestr,true,lmp); itype = utils::inumeric(FLERR,typestr,true,lmp);
@ -1814,7 +1812,7 @@ void Atom::set_mass(const char *file, int line, int /*narg*/, char **arg)
if (!isdigit(arg[0][0]) && arg[0][0] != '*') { if (!isdigit(arg[0][0]) && arg[0][0] != '*') {
std::string typestr(arg[0]); std::string typestr(arg[0]);
int itype = find_label(typestr,Atom::ATOM); int itype = lmap->find(typestr,Atom::ATOM);
if (itype == -1) error->all(file,line,"Invalid type for mass set"); if (itype == -1) error->all(file,line,"Invalid type for mass set");
mass[itype] = utils::numeric(FLERR,arg[1],false,lmp); mass[itype] = utils::numeric(FLERR,arg[1],false,lmp);
mass_setflag[itype] = 1; mass_setflag[itype] = 1;
@ -2062,54 +2060,20 @@ void Atom::add_molecule_atom(Molecule *onemol, int iatom, int ilocal, tagint off
allocate space for type label map allocate space for type label map
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
int Atom::add_label_map(const std::string &mapID) void Atom::add_label_map(const std::string &mapID)
{ {
labelmapflag = 1; labelmapflag = 1;
lmaps = (LabelMap **) lmap = (LabelMap *)
memory->srealloc(lmaps,(nlmap+1)*sizeof(LabelMap *), memory->srealloc(lmap,sizeof(LabelMap *),
"atom::lmaps"); "atom::lmap");
lmaps[nlmap] = new LabelMap(lmp); lmap = new LabelMap(lmp);
lmaps[nlmap]->id = mapID; if (mapID != "") lmap->id = mapID;
lmaps[nlmap]->natomtypes = ntypes; lmap->natomtypes = ntypes;
lmaps[nlmap]->nbondtypes = nbondtypes; lmap->nbondtypes = nbondtypes;
lmaps[nlmap]->nangletypes = nangletypes; lmap->nangletypes = nangletypes;
lmaps[nlmap]->ndihedraltypes = ndihedraltypes; lmap->ndihedraltypes = ndihedraltypes;
lmaps[nlmap]->nimpropertypes = nimpropertypes; lmap->nimpropertypes = nimpropertypes;
lmaps[nlmap]->allocate_type_labels(); lmap->allocate_type_labels();
nlmap++;
return nlmap - 1;
}
/* ----------------------------------------------------------------------
find label, first parsing prefix for label map-ID
return -1 if does not exist
------------------------------------------------------------------------- */
int Atom::find_label(const std::string &label, int mode)
{
// check for auxiliary map prefix
std::string::size_type pos = label.find("::");
if (pos != std::string::npos) {
int ilmap = find_labelmap(label.substr(0,pos));
if (ilmap == -1) return -1;
auto slabel = label.substr(pos+2);
return lmaps[ilmap]->find(slabel,mode);
}
return lmaps[0]->find(label,mode);
}
/* ----------------------------------------------------------------------
find first label map in set with ID
return -1 if does not exist
------------------------------------------------------------------------- */
int Atom::find_labelmap(const std::string &id)
{
for (int ilmap = 0; ilmap < nlmap; ilmap++)
if (id == lmaps[ilmap]->id) return ilmap;
return -1;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------

View File

@ -256,8 +256,7 @@ class Atom : protected Pointers {
// type label maps // type label maps
int nlmap; class LabelMap *lmap;
class LabelMap **lmaps;
// extra peratom info in restart file destined for fix & diag // extra peratom info in restart file destined for fix & diag
@ -356,9 +355,7 @@ class Atom : protected Pointers {
int find_molecule(char *); int find_molecule(char *);
void add_molecule_atom(class Molecule *, int, int, tagint); void add_molecule_atom(class Molecule *, int, int, tagint);
int add_label_map(const std::string &mapID = ""); void add_label_map(const std::string &mapID = "");
int find_label(const std::string &, int);
int find_labelmap(const std::string &);
void first_reorder(); void first_reorder();
virtual void sort(); virtual void sort();

View File

@ -1822,7 +1822,7 @@ void AtomVec::write_data(FILE *fp, int n, double **buf)
if (cols == 0) { if (cols == 0) {
if (atom->types_style == Atom::LABELS && if (atom->types_style == Atom::LABELS &&
atom->peratom[mdata_atom.index[nn]].name == "type") { atom->peratom[mdata_atom.index[nn]].name == "type") {
fmt::print(fp," {}",atom->lmaps[0]->typelabel[ubuf(buf[i][j++]).i-1]); fmt::print(fp," {}",atom->lmap->typelabel[ubuf(buf[i][j++]).i-1]);
continue; continue;
} }
fmt::print(fp, " {}", ubuf(buf[i][j++]).i); fmt::print(fp, " {}", ubuf(buf[i][j++]).i);
@ -2036,7 +2036,7 @@ void AtomVec::write_bond(FILE *fp, int n, tagint **buf, int index)
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
typestr = std::to_string(buf[i][0]); typestr = std::to_string(buf[i][0]);
if (atom->types_style == Atom::LABELS) if (atom->types_style == Atom::LABELS)
typestr = atom->lmaps[0]->btypelabel[buf[i][0]-1]; typestr = atom->lmap->btypelabel[buf[i][0]-1];
fmt::print(fp, "{} {} {} {}\n", index, typestr, buf[i][1], buf[i][2]); fmt::print(fp, "{} {} {} {}\n", index, typestr, buf[i][1], buf[i][2]);
index++; index++;
} }
@ -2102,7 +2102,7 @@ void AtomVec::write_angle(FILE *fp, int n, tagint **buf, int index)
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
typestr = std::to_string(buf[i][0]); typestr = std::to_string(buf[i][0]);
if (atom->types_style == Atom::LABELS) if (atom->types_style == Atom::LABELS)
typestr = atom->lmaps[0]->atypelabel[buf[i][0]-1]; typestr = atom->lmap->atypelabel[buf[i][0]-1];
fmt::print(fp, "{} {} {} {} {}\n", index, fmt::print(fp, "{} {} {} {} {}\n", index,
typestr, buf[i][1], buf[i][2], buf[i][3]); typestr, buf[i][1], buf[i][2], buf[i][3]);
index++; index++;
@ -2167,7 +2167,7 @@ void AtomVec::write_dihedral(FILE *fp, int n, tagint **buf, int index)
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
typestr = std::to_string(buf[i][0]); typestr = std::to_string(buf[i][0]);
if (atom->types_style == Atom::LABELS) if (atom->types_style == Atom::LABELS)
typestr = atom->lmaps[0]->dtypelabel[buf[i][0]-1]; typestr = atom->lmap->dtypelabel[buf[i][0]-1];
fmt::print(fp, "{} {} {} {} {} {}\n", index, typestr, fmt::print(fp, "{} {} {} {} {} {}\n", index, typestr,
buf[i][1], buf[i][2], buf[i][3], buf[i][4]); buf[i][1], buf[i][2], buf[i][3], buf[i][4]);
index++; index++;
@ -2232,7 +2232,7 @@ void AtomVec::write_improper(FILE *fp, int n, tagint **buf, int index)
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
typestr = std::to_string(buf[i][0]); typestr = std::to_string(buf[i][0]);
if (atom->types_style == Atom::LABELS) if (atom->types_style == Atom::LABELS)
typestr = atom->lmaps[0]->itypelabel[buf[i][0]-1]; typestr = atom->lmap->itypelabel[buf[i][0]-1];
fmt::print(fp, "{} {} {} {} {} {}\n", index, typestr, fmt::print(fp, "{} {} {} {} {} {}\n", index, typestr,
buf[i][1], buf[i][2], buf[i][3], buf[i][4]); buf[i][1], buf[i][2], buf[i][3], buf[i][4]);
index++; index++;

View File

@ -730,7 +730,7 @@ int Input::readtype(char *&str, int mode)
char typechar[256]; char typechar[256];
std::string labelstr(str); std::string labelstr(str);
type = atom->find_label(labelstr,mode); type = atom->lmap->find(labelstr,mode);
if (type == -1) error->all(FLERR,fmt::format("Invalid type {}",str)); if (type == -1) error->all(FLERR,fmt::format("Invalid type {}",str));
sprintf(typechar,"%d",type); sprintf(typechar,"%d",type);
@ -1632,20 +1632,20 @@ void Input::labelmap()
if (!atom->labelmapflag) atom->add_label_map(); if (!atom->labelmapflag) atom->add_label_map();
int ilmap = 0;
std::string mapid; std::string mapid;
for (int i = 1; i < narg; i++) { for (int i = 1; i < narg; i++) {
if (strcmp(arg[i],"mapID") == 0) { if (strcmp(arg[i],"mapID") == 0) {
mapid = arg[i+1]; mapid = arg[i+1];
ilmap = atom->find_labelmap(mapid);
if (ilmap == -1) ilmap = atom->add_label_map(mapid);
if (narg > i+2) error->all(FLERR,"Illegal labelmap command"); if (narg > i+2) error->all(FLERR,"Illegal labelmap command");
if (atom->lmap->id == "") atom->lmap->id == mapid;
else if (atom->lmap->id != mapid)
error->all(FLERR,"Labelmap ID {} does not match existing ID {}",mapid,atom->lmap->id);
narg = narg - 2; narg = narg - 2;
break; break;
} }
i++; i++;
} }
atom->lmaps[ilmap]->modify_lmap(narg,arg); atom->lmap->modify_lmap(narg,arg);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -21,6 +21,7 @@
#include "domain.h" #include "domain.h"
#include "error.h" #include "error.h"
#include "force.h" #include "force.h"
#include "label_map.h"
#include "math_extra.h" #include "math_extra.h"
#include "math_eigen.h" #include "math_eigen.h"
#include "memory.h" #include "memory.h"
@ -737,7 +738,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->find_label(typestr,Atom::ATOM); type[iatom] = atom->lmap->find(typestr,Atom::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;
@ -959,7 +960,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->find_label(typestr,Atom::BOND); itype = atom->lmap->find(typestr,Atom::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();
@ -1033,7 +1034,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->find_label(typestr,Atom::ANGLE); itype = atom->lmap->find(typestr,Atom::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();
@ -1124,7 +1125,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->find_label(typestr,Atom::DIHEDRAL); itype = atom->lmap->find(typestr,Atom::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();
@ -1228,7 +1229,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->find_label(typestr,Atom::IMPROPER); itype = atom->lmap->find(typestr,Atom::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

@ -2109,8 +2109,8 @@ void ReadData::typelabels(int mode)
// determine mapping to let labels override numeric types // determine mapping to let labels override numeric types
// valid operations for first or subsequent data files // valid operations for first or subsequent data files
atom->lmaps[0]->merge_lmap(lmap,mode); atom->lmap->merge_lmap(lmap,mode);
lmap->create_lmap2lmap(atom->lmaps[0],mode); lmap->create_lmap2lmap(atom->lmap,mode);
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------

View File

@ -893,7 +893,7 @@ void ReadRestart::type_arrays()
} else if (flag == LABELMAP) { } else if (flag == LABELMAP) {
read_int(); read_int();
atom->add_label_map(); atom->add_label_map();
atom->lmaps[0]->read_restart(fp); atom->lmap->read_restart(fp);
} else error->all(FLERR, } else error->all(FLERR,
"Invalid flag in type arrays section of restart file"); "Invalid flag in type arrays section of restart file");

View File

@ -24,6 +24,7 @@
#include "group.h" #include "group.h"
#include "info.h" #include "info.h"
#include "input.h" #include "input.h"
#include "label_map.h"
#include "library.h" #include "library.h"
#include "lmppython.h" #include "lmppython.h"
#include "math_const.h" #include "math_const.h"
@ -4405,19 +4406,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->find_label(typestr,Atom::ATOM); value = atom->lmap->find(typestr,Atom::ATOM);
} else if (strcmp(word,"blabel") == 0) { } else if (strcmp(word,"blabel") == 0) {
value = atom->find_label(typestr,Atom::BOND); value = atom->lmap->find(typestr,Atom::BOND);
} else if (strcmp(word,"alabel") == 0) { } else if (strcmp(word,"alabel") == 0) {
value = atom->find_label(typestr,Atom::ANGLE); value = atom->lmap->find(typestr,Atom::ANGLE);
} else if (strcmp(word,"dlabel") == 0) { } else if (strcmp(word,"dlabel") == 0) {
value = atom->find_label(typestr,Atom::DIHEDRAL); value = atom->lmap->find(typestr,Atom::DIHEDRAL);
} else if (strcmp(word,"ilabel") == 0) { } else if (strcmp(word,"ilabel") == 0) {
value = atom->find_label(typestr,Atom::IMPROPER); value = atom->lmap->find(typestr,Atom::IMPROPER);
} }
if (value == -1) if (value == -1)

View File

@ -197,7 +197,7 @@ void WriteData::write(const std::string &file)
if (me == 0) { if (me == 0) {
header(); header();
if (lmapflag && atom->labelmapflag) atom->lmaps[0]->write_data(fp); if (lmapflag && atom->labelmapflag) atom->lmap->write_data(fp);
type_arrays(); type_arrays();
if (coeffflag) force_fields(); if (coeffflag) force_fields();
} }

View File

@ -526,7 +526,7 @@ void WriteRestart::type_arrays()
if (atom->mass) write_double_vec(MASS,atom->ntypes,&atom->mass[1]); if (atom->mass) write_double_vec(MASS,atom->ntypes,&atom->mass[1]);
if (atom->labelmapflag) { if (atom->labelmapflag) {
write_int(LABELMAP,atom->labelmapflag); write_int(LABELMAP,atom->labelmapflag);
atom->lmaps[0]->write_restart(fp); atom->lmap->write_restart(fp);
} }
// -1 flag signals end of type arrays // -1 flag signals end of type arrays