diff --git a/src/atom.cpp b/src/atom.cpp index 8a5bacc645..8e8c1a2bb8 100755 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -204,7 +204,7 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) // type labels - lmap = nullptr; + lmaps = nullptr; // custom atom arrays @@ -312,9 +312,10 @@ Atom::~Atom() for (int i = 0; i < nmolecule; i++) delete molecules[i]; memory->sfree(molecules); - // delete label map + // delete label maps - delete lmap; + for (int i = 0; i < nlmap; i++) delete lmaps[i]; + memory->sfree(lmaps); // delete per-type arrays @@ -1989,16 +1990,35 @@ void Atom::add_molecule_atom(Molecule *onemol, int iatom, allocate space for type label map ------------------------------------------------------------------------- */ -void Atom::add_label_map() +void Atom::add_label_map(char *mapID) { labelmapflag = 1; - lmap = new LabelMap(lmp); - lmap->natomtypes = ntypes; - lmap->nbondtypes = nbondtypes; - lmap->nangletypes = nangletypes; - lmap->ndihedraltypes = ndihedraltypes; - lmap->nimpropertypes = nimpropertypes; - lmap->allocate_type_labels(); + 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++; +} + +/* ---------------------------------------------------------------------- + find label, first parsing prefix for label map-ID + return -1 if does not exist +------------------------------------------------------------------------- */ + +int Atom::find_label(std::string label, int mode) +{ + // find label map ... in progress + int ilmap; + ilmap = 0; + + return lmaps[ilmap]->find(label,mode); } /* ---------------------------------------------------------------------- diff --git a/src/atom.h b/src/atom.h index 9947f5aea4..94741261b0 100755 --- a/src/atom.h +++ b/src/atom.h @@ -32,6 +32,7 @@ class Atom : protected Pointers { enum{DOUBLE,INT,BIGINT}; enum{GROW=0,RESTART=1,BORDER=2}; enum{ATOMIC=0,MOLECULAR=1,TEMPLATE=2}; + enum{ATOM=0,BOND=1,ANGLE=2,DIHEDRAL=3,IMPROPER=4}; enum{MAP_NONE=0,MAP_ARRAY=1,MAP_HASH=2,MAP_YES=3}; // atom counts @@ -229,9 +230,10 @@ class Atom : protected Pointers { int nmolecule; class Molecule **molecules; - // type labels + // type label maps - class LabelMap *lmap; + int nlmap; + class LabelMap **lmaps; // extra peratom info in restart file destined for fix & diag @@ -327,7 +329,8 @@ class Atom : protected Pointers { int find_molecule(char *); void add_molecule_atom(class Molecule *, int, int, tagint); - void add_label_map(); + void add_label_map(char *); + int find_label(std::string, int); void first_reorder(); virtual void sort(); diff --git a/src/input.cpp b/src/input.cpp index 8129ed47f8..31cd037e8e 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -678,7 +678,7 @@ void Input::readtype(char *&str, int mode) char typechar[256]; labelstr = str; - type = atom->lmap->find(labelstr,mode); + type = atom->find_label(labelstr,mode); if (type == -1) error->all(FLERR,fmt::format("Invalid type {}",str)); sprintf(typechar,"%d",type); @@ -1332,7 +1332,7 @@ void Input::angle_coeff() error->all(FLERR,"Angle_coeff command before angle_style is defined"); if (atom->avec->angles_allow == 0) error->all(FLERR,"Angle_coeff command when no angles allowed"); - readtype(arg[0],atom->lmap->ANGLE); + readtype(arg[0],atom->ANGLE); force->angle->coeff(narg,arg); } @@ -1374,7 +1374,7 @@ void Input::bond_coeff() error->all(FLERR,"Bond_coeff command before bond_style is defined"); if (atom->avec->bonds_allow == 0) error->all(FLERR,"Bond_coeff command when no bonds allowed"); - readtype(arg[0],atom->lmap->BOND); + readtype(arg[0],atom->BOND); force->bond->coeff(narg,arg); } @@ -1478,7 +1478,7 @@ void Input::dihedral_coeff() error->all(FLERR,"Dihedral_coeff command before dihedral_style is defined"); if (atom->avec->dihedrals_allow == 0) error->all(FLERR,"Dihedral_coeff command when no dihedrals allowed"); - readtype(arg[0],atom->lmap->DIHEDRAL); + readtype(arg[0],atom->DIHEDRAL); force->dihedral->coeff(narg,arg); } @@ -1556,7 +1556,7 @@ void Input::improper_coeff() error->all(FLERR,"Improper_coeff command before improper_style is defined"); if (atom->avec->impropers_allow == 0) error->all(FLERR,"Improper_coeff command when no impropers allowed"); - readtype(arg[0],atom->lmap->IMPROPER); + readtype(arg[0],atom->IMPROPER); force->improper->coeff(narg,arg); } @@ -1593,8 +1593,8 @@ void Input::labelmap() { if (domain->box_exist == 0) error->all(FLERR,"Labelmap command before simulation box is defined"); - if (!atom->labelmapflag) atom->add_label_map(); - atom->lmap->modify_lmap(narg,arg); + if (!atom->labelmapflag) atom->add_label_map(""); + atom->lmaps[0]->modify_lmap(narg,arg); } /* ---------------------------------------------------------------------- */ @@ -1734,8 +1734,8 @@ void Input::pair_coeff() error->all(FLERR,"Pair_coeff command before simulation box is defined"); if (force->pair == nullptr) error->all(FLERR,"Pair_coeff command before pair_style is defined"); - readtype(arg[0],atom->lmap->ATOM); - readtype(arg[1],atom->lmap->ATOM); + readtype(arg[0],atom->ATOM); + readtype(arg[1],atom->ATOM); force->pair->coeff(narg,arg); } diff --git a/src/label_map.cpp b/src/label_map.cpp index 8cd15ed64b..e8ce7ecfc7 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -13,6 +13,7 @@ #include "label_map.h" +#include "atom.h" #include "force.h" #include "memory.h" #include "error.h" @@ -118,23 +119,23 @@ void LabelMap::modify_lmap(int narg, char **arg) void LabelMap::merge_lmap(LabelMap *lmap2, int mode) { - if (mode == ATOM) + if (mode == atom->ATOM) for (int i = 0; i < lmap2->natomtypes; i++) find_or_create(lmap2->typelabel[i],typelabel,natomtypes); - if (mode == BOND) + if (mode == atom->BOND) for (int i = 0; i < lmap2->nbondtypes; i++) find_or_create(lmap2->btypelabel[i],btypelabel,nbondtypes); - if (mode == ANGLE) + if (mode == atom->ANGLE) for (int i = 0; i < lmap2->nangletypes; i++) find_or_create(lmap2->atypelabel[i],atypelabel,nangletypes); - if (mode == DIHEDRAL) + if (mode == atom->DIHEDRAL) for (int i = 0; i < lmap2->ndihedraltypes; i++) find_or_create(lmap2->dtypelabel[i],dtypelabel,ndihedraltypes); - if (mode == IMPROPER) + if (mode == atom->IMPROPER) for (int i = 0; i < lmap2->nimpropertypes; i++) find_or_create(lmap2->itypelabel[i],itypelabel,nimpropertypes); } @@ -146,27 +147,27 @@ void LabelMap::merge_lmap(LabelMap *lmap2, int mode) void LabelMap::create_lmap2lmap(LabelMap *lmap2, int mode) { - if (mode == ATOM) + if (mode == atom->ATOM) for (int i = 0; i < natomtypes; i++) lmap2lmap.atom[i] = search(typelabel[i],lmap2->typelabel, lmap2->natomtypes); - if (mode == BOND) + if (mode == atom->BOND) for (int i = 0; i < nbondtypes; i++) lmap2lmap.bond[i] = search(btypelabel[i],lmap2->btypelabel, lmap2->nbondtypes); - if (mode == ANGLE) + if (mode == atom->ANGLE) for (int i = 0; i < nangletypes; i++) lmap2lmap.angle[i] = search(atypelabel[i],lmap2->atypelabel, lmap2->nangletypes); - if (mode == DIHEDRAL) + if (mode == atom->DIHEDRAL) for (int i = 0; i < ndihedraltypes; i++) lmap2lmap.dihedral[i] = search(dtypelabel[i],lmap2->dtypelabel, lmap2->ndihedraltypes); - if (mode == IMPROPER) + if (mode == atom->IMPROPER) for (int i = 0; i < nimpropertypes; i++) lmap2lmap.improper[i] = search(itypelabel[i],lmap2->itypelabel, lmap2->nimpropertypes); @@ -205,19 +206,19 @@ int LabelMap::find_or_create(std::string mylabel, std::vector &labe int LabelMap::find(std::string mylabel, int mode) { - if (mode == ATOM) + if (mode == atom->ATOM) return search(mylabel,typelabel,natomtypes); - if (mode == BOND) + if (mode == atom->BOND) return search(mylabel,btypelabel,nbondtypes); - if (mode == ANGLE) + if (mode == atom->ANGLE) return search(mylabel,atypelabel,nangletypes); - if (mode == DIHEDRAL) + if (mode == atom->DIHEDRAL) return search(mylabel,dtypelabel,ndihedraltypes); - if (mode == IMPROPER) + if (mode == atom->IMPROPER) return search(mylabel,itypelabel,nimpropertypes); return -1; diff --git a/src/label_map.h b/src/label_map.h index 11c3f19443..402fd210f5 100755 --- a/src/label_map.h +++ b/src/label_map.h @@ -20,9 +20,9 @@ namespace LAMMPS_NS { class LabelMap : protected Pointers { public: - enum{ATOM,BOND,ANGLE,DIHEDRAL,IMPROPER}; int natomtypes,nbondtypes,nangletypes; int ndihedraltypes,nimpropertypes; + std::string id; std::vector typelabel,btypelabel,atypelabel; std::vector dtypelabel,itypelabel; diff --git a/src/molecule.cpp b/src/molecule.cpp index 4c4a3bfba3..0bec25e183 100755 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -20,7 +20,6 @@ #include "domain.h" #include "error.h" #include "force.h" -#include "label_map.h" #include "math_extra.h" #include "math_eigen.h" #include "memory.h" @@ -729,7 +728,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->lmap->find(typestr,atom->lmap->ATOM); + type[iatom] = atom->find_label(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; @@ -942,7 +941,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->lmap->find(typestr,atom->lmap->BOND); + itype = atom->find_label(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(); @@ -1016,7 +1015,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->lmap->find(typestr,atom->lmap->ANGLE); + itype = atom->find_label(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(); @@ -1106,7 +1105,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->lmap->find(typestr,atom->lmap->DIHEDRAL); + itype = atom->find_label(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(); @@ -1211,7 +1210,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->lmap->find(typestr,atom->lmap->IMPROPER); + itype = atom->find_label(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 f493be0977..fd60a2b9b2 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -729,7 +729,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (atomflag == 1) error->all(FLERR,"Must read Atom Type Labels before Atoms"); - typelabels(lmap->typelabel,ntypes,lmap->ATOM); + typelabels(lmap->typelabel,ntypes,atom->ATOM); } else skip_lines(ntypes); } else if (strcmp(keyword,"Bond Type Labels") == 0) { @@ -737,7 +737,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (bondflag == 1) error->all(FLERR,"Must read Bond Type Labels before Bonds"); - typelabels(lmap->btypelabel,nbondtypes,lmap->BOND); + typelabels(lmap->btypelabel,nbondtypes,atom->BOND); } else skip_lines(nbondtypes); } @@ -746,7 +746,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (angleflag == 1) error->all(FLERR,"Must read Angle Type Labels before Angles"); - typelabels(lmap->atypelabel,nangletypes,lmap->ANGLE); + typelabels(lmap->atypelabel,nangletypes,atom->ANGLE); } else skip_lines(nangletypes); } @@ -755,7 +755,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (dihedralflag == 1) error->all(FLERR,"Must read Dihedral Type Labels before Dihedrals"); - typelabels(lmap->dtypelabel,ndihedraltypes,lmap->DIHEDRAL); + typelabels(lmap->dtypelabel,ndihedraltypes,atom->DIHEDRAL); } else skip_lines(ndihedraltypes); } @@ -764,7 +764,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (improperflag == 1) error->all(FLERR,"Must read Improper Type Labels before Impropers"); - typelabels(lmap->itypelabel,nimpropertypes,lmap->IMPROPER); + typelabels(lmap->itypelabel,nimpropertypes,atom->IMPROPER); } else skip_lines(nimpropertypes); } @@ -1974,7 +1974,7 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i char *buf = new char[myntypes*MAXLINE]; labelflag = 1; - if (!atom->labelmapflag) atom->add_label_map(); + if (!atom->labelmapflag) atom->add_label_map(""); int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); @@ -1994,8 +1994,8 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i // determine mapping to let labels override numeric types // valid operations for first or subsequent data files - atom->lmap->merge_lmap(lmap,mode); - lmap->create_lmap2lmap(atom->lmap,mode); + atom->lmaps[0]->merge_lmap(lmap,mode); + lmap->create_lmap2lmap(atom->lmaps[0],mode); } /* ---------------------------------------------------------------------- diff --git a/src/read_restart.cpp b/src/read_restart.cpp index 89994abab5..d3b3f70b4a 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -932,8 +932,8 @@ void ReadRestart::type_arrays() } else if (flag == LABELMAP) { read_int(); - atom->add_label_map(); - atom->lmap->read_restart(fp); + atom->add_label_map(""); + atom->lmaps[0]->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 fdd60de1a0..ddc5365caa 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -24,7 +24,6 @@ #include "info.h" #include "input.h" #include "lmppython.h" -#include "label_map.h" #include "math_const.h" #include "memory.h" #include "modify.h" @@ -4541,19 +4540,19 @@ int Variable::labelmap_function(char *word, char *contents, Tree **tree, std::string typestr = contents; if (strcmp(word,"label") == 0) { - value = atom->lmap->find(typestr,atom->lmap->ATOM); + value = atom->find_label(typestr,atom->ATOM); } else if (strcmp(word,"blabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->BOND); + value = atom->find_label(typestr,atom->BOND); } else if (strcmp(word,"alabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->ANGLE); + value = atom->find_label(typestr,atom->ANGLE); } else if (strcmp(word,"dlabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->DIHEDRAL); + value = atom->find_label(typestr,atom->DIHEDRAL); } else if (strcmp(word,"ilabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->IMPROPER); + value = atom->find_label(typestr,atom->IMPROPER); } if (value == -1) diff --git a/src/write_data.cpp b/src/write_data.cpp index 8088203d5e..4a94f12500 100755 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -186,7 +186,7 @@ void WriteData::write(const std::string &file) if (me == 0) { header(); - if (atom->labelmapflag) atom->lmap->write_data(fp); + if (atom->labelmapflag) atom->lmaps[0]->write_data(fp); type_arrays(); if (coeffflag) force_fields(); } diff --git a/src/write_restart.cpp b/src/write_restart.cpp index f97cdcd966..31ac06db1a 100755 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -523,7 +523,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->lmap->write_restart(fp); + atom->lmaps[0]->write_restart(fp); } // -1 flag signals end of type arrays