diff --git a/src/read_data.cpp b/src/read_data.cpp index e8eb90dcb1..4eb04d460f 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -52,7 +52,7 @@ using namespace LAMMPS_NS; #define MAXBODY 32 // max # of lines in one body // customize for new sections -#define NSECTIONS 25 // change when add to header::section_keywords +#define NSECTIONS 26 // change when add to header::section_keywords enum{NONE,APPEND,VALUE,MERGE}; @@ -440,6 +440,7 @@ void ReadData::command(int narg, char **arg) else n = static_cast (LB_FACTOR * atom->natoms / comm->nprocs); atom->allocate_type_arrays(); + atom->allocate_type_labels(); atom->deallocate_topology(); // allocate atom arrays to N, rounded up by AtomVec->DELTA @@ -712,6 +713,10 @@ void ReadData::command(int narg, char **arg) if (firstpass) impropercoeffs(1); else skip_lines(nimpropertypes); + } else if (strcmp(keyword,"Atom Type Labels") == 0) { + if (firstpass) atomtypelabels(); + else skip_lines(ntypes); + } else error->all(FLERR,fmt::format("Unknown identifier in data file: {}", keyword)); @@ -939,7 +944,8 @@ void ReadData::header(int firstpass) "Dihedral Coeffs","Improper Coeffs", "BondBond Coeffs","BondAngle Coeffs","MiddleBondTorsion Coeffs", "EndBondTorsion Coeffs","AngleTorsion Coeffs", - "AngleAngleTorsion Coeffs","BondBond13 Coeffs","AngleAngle Coeffs"}; + "AngleAngleTorsion Coeffs","BondBond13 Coeffs","AngleAngle Coeffs", + "Atom Type Labels"}; // skip 1st line of file @@ -1901,6 +1907,31 @@ void ReadData::impropercoeffs(int which) delete [] original; } +/* ---------------------------------------------------------------------- */ + +void ReadData::atomtypelabels() +{ + int n; + char *next; + char *buf = new char[ntypes*MAXLINE]; + + int eof = comm->read_lines_from_file(fp,ntypes,MAXLINE,buf); + if (eof) error->all(FLERR,"Unexpected end of data file"); + + char *typelabel = new char[MAXLINE]; + for (int i = 0; i < ntypes; i++) { + next = strchr(buf,'\n'); + *next = '\0'; + sscanf(buf,"%*d %s",typelabel); + n = strlen(typelabel) + 1; + delete [] atom->atomtypelabel[i]; + atom->atomtypelabel[i] = new char[n]; + strcpy(atom->atomtypelabel[i],typelabel); + buf = next + 1; + } + delete [] typelabel; +} + /* ---------------------------------------------------------------------- read fix section, pass lines to fix to process n = index of fix diff --git a/src/read_data.h b/src/read_data.h index 84c098635a..c8547dbd35 100644 --- a/src/read_data.h +++ b/src/read_data.h @@ -106,6 +106,7 @@ class ReadData : protected Pointers { void anglecoeffs(int); void dihedralcoeffs(int); void impropercoeffs(int); + void atomtypelabels(); void fix(int, char *); };