add write_data support, for testing
also refactor label map initialization, memory cleanup
This commit is contained in:
@ -36,16 +36,27 @@ LabelMap::~LabelMap()
|
||||
// delete type labels
|
||||
|
||||
typelabel.clear();
|
||||
btypelabel.clear();
|
||||
atypelabel.clear();
|
||||
dtypelabel.clear();
|
||||
itypelabel.clear();
|
||||
|
||||
delete [] lmap2lmap.atom;
|
||||
delete [] lmap2lmap.bond;
|
||||
delete [] lmap2lmap.angle;
|
||||
delete [] lmap2lmap.dihedral;
|
||||
delete [] lmap2lmap.improper;
|
||||
|
||||
if (force->bond) {
|
||||
btypelabel.clear();
|
||||
delete [] lmap2lmap.bond;
|
||||
}
|
||||
|
||||
if (force->angle) {
|
||||
atypelabel.clear();
|
||||
delete [] lmap2lmap.angle;
|
||||
}
|
||||
|
||||
if (force->dihedral) {
|
||||
dtypelabel.clear();
|
||||
delete [] lmap2lmap.dihedral;
|
||||
}
|
||||
|
||||
if (force->improper) {
|
||||
itypelabel.clear();
|
||||
delete [] lmap2lmap.improper;
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -57,40 +68,27 @@ LabelMap::~LabelMap()
|
||||
void LabelMap::allocate_type_labels()
|
||||
{
|
||||
typelabel.resize(natomtypes);
|
||||
for (int i = 0; i < natomtypes; i++)
|
||||
typelabel[i] = fmt::format("{}",i);
|
||||
lmap2lmap.atom = new int[natomtypes];
|
||||
|
||||
if (force->bond) {
|
||||
btypelabel.resize(nbondtypes);
|
||||
for (int i = 0; i < nbondtypes; i++)
|
||||
btypelabel[i] = fmt::format("{}",i);
|
||||
lmap2lmap.bond = new int[nbondtypes];
|
||||
}
|
||||
|
||||
if (force->angle) {
|
||||
atypelabel.resize(nangletypes);
|
||||
for (int i = 0; i < nangletypes; i++)
|
||||
atypelabel[i] = fmt::format("{}",i);
|
||||
lmap2lmap.angle = new int[nangletypes];
|
||||
}
|
||||
|
||||
if (force->dihedral) {
|
||||
dtypelabel.resize(ndihedraltypes);
|
||||
for (int i = 0; i < ndihedraltypes; i++)
|
||||
dtypelabel[i] = fmt::format("{}",i);
|
||||
lmap2lmap.dihedral = new int[ndihedraltypes];
|
||||
}
|
||||
|
||||
if (force->improper) {
|
||||
itypelabel.resize(nimpropertypes);
|
||||
for (int i = 0; i < nimpropertypes; i++)
|
||||
itypelabel[i] = fmt::format("{}",i);
|
||||
lmap2lmap.improper = new int[nimpropertypes];
|
||||
}
|
||||
|
||||
// allocate space for lmap2lmap
|
||||
|
||||
lmap2lmap.atom = new int[natomtypes];
|
||||
lmap2lmap.bond = new int[nbondtypes];
|
||||
lmap2lmap.angle = new int[nangletypes];
|
||||
lmap2lmap.dihedral = new int[ndihedraltypes];
|
||||
lmap2lmap.improper = new int[nimpropertypes];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -174,7 +172,7 @@ void LabelMap::create_lmap2lmap(class LabelMap *lmap2)
|
||||
return numeric type
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int LabelMap::find_or_create(std::string mylabel, std::vector<std::string> labels, int ntypes)
|
||||
int LabelMap::find_or_create(std::string mylabel, std::vector<std::string> &labels, int ntypes)
|
||||
{
|
||||
for (int i = 0; i < ntypes; i++)
|
||||
if (labels[i] == mylabel) return i+1;
|
||||
@ -184,7 +182,7 @@ int LabelMap::find_or_create(std::string mylabel, std::vector<std::string> label
|
||||
// user labels are assumed to be alphanumeric (not a number)
|
||||
|
||||
for (int i = 0; i < ntypes; i++) {
|
||||
if (stoi(labels[i]) != i+1) {
|
||||
if (labels[i].empty()) {
|
||||
labels[i] = mylabel;
|
||||
return i+1;
|
||||
}
|
||||
@ -207,3 +205,38 @@ int LabelMap::find(std::string mylabel, std::vector<std::string> labels, int nty
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
proc 0 writes to data file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void LabelMap::write_data(FILE *fp)
|
||||
{
|
||||
fmt::print(fp,"\nAtom Type Labels\n\n");
|
||||
for (int i = 0; i < natomtypes; i++)
|
||||
fmt::print(fp,"{} {}\n",i+1,typelabel[i]);
|
||||
|
||||
if (force->bond) {
|
||||
fmt::print(fp,"\nBond Type Labels\n\n");
|
||||
for (int i = 0; i < nbondtypes; i++)
|
||||
fmt::print(fp,"{} {}\n",i+1,btypelabel[i]);
|
||||
}
|
||||
|
||||
if (force->angle) {
|
||||
fmt::print(fp,"\nAngle Type Labels\n\n");
|
||||
for (int i = 0; i < nangletypes; i++)
|
||||
fmt::print(fp,"{} {}\n",i+1,atypelabel[i]);
|
||||
}
|
||||
|
||||
if (force->dihedral) {
|
||||
fmt::print(fp,"\nDihedral Type Labels\n\n");
|
||||
for (int i = 0; i < ndihedraltypes; i++)
|
||||
fmt::print(fp,"{} {}\n",i+1,dtypelabel[i]);
|
||||
}
|
||||
|
||||
if (force->improper) {
|
||||
fmt::print(fp,"\nImproper Type Labels\n\n");
|
||||
for (int i = 0; i < nimpropertypes; i++)
|
||||
fmt::print(fp,"{} {}\n",i+1,itypelabel[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user