From 363b80f85cf2e34db6cd7c6a3d777fcfb71c8807 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 9 Aug 2022 01:01:31 -0400 Subject: [PATCH] begin unfeaturing multiple label maps feature --- src/atom.cpp | 76 ++++++++++++------------------------------- src/atom.h | 7 ++-- src/atom_vec.cpp | 10 +++--- src/input.cpp | 10 +++--- src/molecule.cpp | 11 ++++--- src/read_data.cpp | 4 +-- src/read_restart.cpp | 2 +- src/variable.cpp | 11 ++++--- src/write_data.cpp | 2 +- src/write_restart.cpp | 2 +- 10 files changed, 49 insertions(+), 86 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 5b9790bbca..e819c13877 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -226,8 +226,7 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) // type labels - nlmap = 0; - lmaps = nullptr; + lmap = nullptr; // custom atom arrays @@ -348,8 +347,7 @@ Atom::~Atom() // delete label maps - for (int i = 0; i < nlmap; i++) delete lmaps[i]; - memory->sfree(lmaps); + memory->sfree(lmap); // 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 (!isdigit(typestr[0])) { 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"); } else { 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 (!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"); } else { 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 (!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"); } else { 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 (!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"); } else { 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 (!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"); } else { 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] != '*') { 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"); mass[itype] = utils::numeric(FLERR,arg[1],false,lmp); 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 ------------------------------------------------------------------------- */ -int Atom::add_label_map(const std::string &mapID) +void Atom::add_label_map(const std::string &mapID) { labelmapflag = 1; - lmaps = (LabelMap **) - memory->srealloc(lmaps,(nlmap+1)*sizeof(LabelMap *), - "atom::lmaps"); - lmaps[nlmap] = new LabelMap(lmp); - lmaps[nlmap]->id = mapID; - lmaps[nlmap]->natomtypes = ntypes; - lmaps[nlmap]->nbondtypes = nbondtypes; - lmaps[nlmap]->nangletypes = nangletypes; - lmaps[nlmap]->ndihedraltypes = ndihedraltypes; - lmaps[nlmap]->nimpropertypes = nimpropertypes; - lmaps[nlmap]->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; + lmap = (LabelMap *) + memory->srealloc(lmap,sizeof(LabelMap *), + "atom::lmap"); + lmap = new LabelMap(lmp); + if (mapID != "") lmap->id = mapID; + lmap->natomtypes = ntypes; + lmap->nbondtypes = nbondtypes; + lmap->nangletypes = nangletypes; + lmap->ndihedraltypes = ndihedraltypes; + lmap->nimpropertypes = nimpropertypes; + lmap->allocate_type_labels(); } /* ---------------------------------------------------------------------- diff --git a/src/atom.h b/src/atom.h index ef498ff0f0..395f4986d5 100644 --- a/src/atom.h +++ b/src/atom.h @@ -256,8 +256,7 @@ class Atom : protected Pointers { // type label maps - int nlmap; - class LabelMap **lmaps; + class LabelMap *lmap; // extra peratom info in restart file destined for fix & diag @@ -356,9 +355,7 @@ class Atom : protected Pointers { int find_molecule(char *); void add_molecule_atom(class Molecule *, int, int, tagint); - int add_label_map(const std::string &mapID = ""); - int find_label(const std::string &, int); - int find_labelmap(const std::string &); + void add_label_map(const std::string &mapID = ""); void first_reorder(); virtual void sort(); diff --git a/src/atom_vec.cpp b/src/atom_vec.cpp index 85827e6cec..e1eac93990 100644 --- a/src/atom_vec.cpp +++ b/src/atom_vec.cpp @@ -1822,7 +1822,7 @@ void AtomVec::write_data(FILE *fp, int n, double **buf) if (cols == 0) { if (atom->types_style == Atom::LABELS && 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; } 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++) { typestr = std::to_string(buf[i][0]); 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]); index++; } @@ -2102,7 +2102,7 @@ void AtomVec::write_angle(FILE *fp, int n, tagint **buf, int index) for (int i = 0; i < n; i++) { typestr = std::to_string(buf[i][0]); 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, typestr, buf[i][1], buf[i][2], buf[i][3]); index++; @@ -2167,7 +2167,7 @@ void AtomVec::write_dihedral(FILE *fp, int n, tagint **buf, int index) for (int i = 0; i < n; i++) { typestr = std::to_string(buf[i][0]); 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, buf[i][1], buf[i][2], buf[i][3], buf[i][4]); index++; @@ -2232,7 +2232,7 @@ void AtomVec::write_improper(FILE *fp, int n, tagint **buf, int index) for (int i = 0; i < n; i++) { typestr = std::to_string(buf[i][0]); 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, buf[i][1], buf[i][2], buf[i][3], buf[i][4]); index++; diff --git a/src/input.cpp b/src/input.cpp index c241e10035..d4a0310211 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -730,7 +730,7 @@ int Input::readtype(char *&str, int mode) char typechar[256]; 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)); sprintf(typechar,"%d",type); @@ -1632,20 +1632,20 @@ void Input::labelmap() if (!atom->labelmapflag) atom->add_label_map(); - int ilmap = 0; std::string mapid; for (int i = 1; i < narg; i++) { if (strcmp(arg[i],"mapID") == 0) { 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 (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; break; } i++; } - atom->lmaps[ilmap]->modify_lmap(narg,arg); + atom->lmap->modify_lmap(narg,arg); } /* ---------------------------------------------------------------------- */ diff --git a/src/molecule.cpp b/src/molecule.cpp index 63fa74f464..c4d15969ad 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -21,6 +21,7 @@ #include "domain.h" #include "error.h" #include "force.h" +#include "label_map.h" #include "math_extra.h" #include "math_eigen.h" #include "memory.h" @@ -737,7 +738,7 @@ void Molecule::types(char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { 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"); } else type[iatom] = utils::inumeric(FLERR,typestr.c_str(),false,lmp); type[iatom] += toffset; @@ -959,7 +960,7 @@ void Molecule::bonds(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { 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"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1033,7 +1034,7 @@ void Molecule::angles(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { 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"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1124,7 +1125,7 @@ void Molecule::dihedrals(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { 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"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1228,7 +1229,7 @@ void Molecule::impropers(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { 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"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); diff --git a/src/read_data.cpp b/src/read_data.cpp index e3ed3d3efa..3a449056d6 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -2109,8 +2109,8 @@ void ReadData::typelabels(int mode) // determine mapping to let labels override numeric types // valid operations for first or subsequent data files - atom->lmaps[0]->merge_lmap(lmap,mode); - lmap->create_lmap2lmap(atom->lmaps[0],mode); + atom->lmap->merge_lmap(lmap,mode); + lmap->create_lmap2lmap(atom->lmap,mode); } /* ---------------------------------------------------------------------- diff --git a/src/read_restart.cpp b/src/read_restart.cpp index a73927bb9f..e0e9eb3812 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -893,7 +893,7 @@ void ReadRestart::type_arrays() } else if (flag == LABELMAP) { read_int(); atom->add_label_map(); - atom->lmaps[0]->read_restart(fp); + atom->lmap->read_restart(fp); } else error->all(FLERR, "Invalid flag in type arrays section of restart file"); diff --git a/src/variable.cpp b/src/variable.cpp index 77704eea96..b29fb571d8 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -24,6 +24,7 @@ #include "group.h" #include "info.h" #include "input.h" +#include "label_map.h" #include "library.h" #include "lmppython.h" #include "math_const.h" @@ -4405,19 +4406,19 @@ int Variable::labelmap_function(char *word, char *contents, Tree **tree, std::string typestr(contents); 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) { - value = atom->find_label(typestr,Atom::BOND); + value = atom->lmap->find(typestr,Atom::BOND); } 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) { - value = atom->find_label(typestr,Atom::DIHEDRAL); + value = atom->lmap->find(typestr,Atom::DIHEDRAL); } else if (strcmp(word,"ilabel") == 0) { - value = atom->find_label(typestr,Atom::IMPROPER); + value = atom->lmap->find(typestr,Atom::IMPROPER); } if (value == -1) diff --git a/src/write_data.cpp b/src/write_data.cpp index f8612c7072..447399c65f 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -197,7 +197,7 @@ void WriteData::write(const std::string &file) if (me == 0) { header(); - if (lmapflag && atom->labelmapflag) atom->lmaps[0]->write_data(fp); + if (lmapflag && atom->labelmapflag) atom->lmap->write_data(fp); type_arrays(); if (coeffflag) force_fields(); } diff --git a/src/write_restart.cpp b/src/write_restart.cpp index f3a58aad7f..828d9e6057 100644 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -526,7 +526,7 @@ void WriteRestart::type_arrays() if (atom->mass) write_double_vec(MASS,atom->ntypes,&atom->mass[1]); if (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