begin unfeaturing multiple label maps feature
This commit is contained in:
76
src/atom.cpp
76
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();
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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++;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user