92 std::cout <<
"Reading the current box configuration from lammps data file " << configFileName << std::endl;
94 std::cout <<
"Reading the reference box configuration from lammps data file " << configFileName << std::endl;
95 std::ifstream file(configFileName);
98 std::cerr <<
"ERROR: " << configFileName <<
" could not be opened for reading!" << std::endl;
103 auto hasEnding = [](
const std::string& fullString,
const std::string& ending) ->
bool {
104 return fullString.size() >= ending.size() &&
105 fullString.compare(fullString.size() - ending.size(), ending.size(), ending) == 0;
108 if (hasEnding(configFileName,
".lmp")) {
111 std::cerr <<
"ERROR: Expecting file with extension .lmp!" << std::endl;
129 int numberOfAtomTypes = 0;
130 std::unordered_map<int, std::string> typeToSpecies;
132 while (std::getline(file, line)) {
134 std::string loweredLine = line;
135 std::transform(loweredLine.begin(), loweredLine.end(), loweredLine.begin(), ::tolower);
138 if (loweredLine.find(
"atoms") != std::string::npos && (std::stringstream(line) >> numAtoms) ) {
142 MY_ERROR(
"Error: Number of particles in file does not equal to that of BoxConfiguration");
145 else if (loweredLine.find(
"atom types") != std::string::npos) {
146 std::istringstream ss(line);
147 ss >> numberOfAtomTypes;
150 else if (loweredLine.find(
"xlo xhi") != std::string::npos) {
151 std::istringstream ss(line);
155 box(0, 0) = xhi - xlo;
158 }
else if (loweredLine.find(
"ylo yhi") != std::string::npos) {
159 std::istringstream ss(line);
163 box(1, 1) = yhi - ylo;
166 }
else if (loweredLine.find(
"zlo zhi") != std::string::npos) {
167 std::istringstream ss(line);
171 box(2, 2) = zhi - zlo;
177 else if (loweredLine.find(
"masses") != std::string::npos) {
178 int massLinesRead = 0;
181 while (std::getline(file, line)) {
183 if (line.empty() || line.find_first_not_of(
" \t\r\n") == std::string::npos)
191 std::istringstream ss(line);
197 std::getline(ss, comment);
199 std::string speciesName =
"Unknown";
202 size_t hashPos = comment.find(
'#');
203 if (hashPos != std::string::npos) {
204 speciesName = comment.substr(hashPos + 1);
206 speciesName.erase(0, speciesName.find_first_not_of(
" \t"));
207 speciesName.erase(speciesName.find_last_not_of(
" \t\r\n") + 1);
210 typeToSpecies[type] = speciesName;
212 if (++massLinesRead >= numberOfAtomTypes)
218 else if (loweredLine.find(
"atoms") != std::string::npos) {
220 while (std::getline(file, line)) {
221 if (line.empty() || line.find_first_not_of(
" \t\r\n") == std::string::npos)
231 std::istringstream ss(line);
234 if (!(ss >>
id >> type >> x >> y >> z))
235 MY_ERROR(
"ERROR: Coordinate of particle " + std::to_string(i));
237 int idxFlagx= 0;
int idxFlagy= 0;
int idxFlagz= 0;
238 int tmpx, tmpy, tmpz;
239 if (ss >> tmpx >> tmpy >> tmpz) {
248 "Species in the reference configuration do not match with those in the "
249 "current configuration");
262 std::getline(file, line);
271 pbc = Eigen::Vector3i::Zero();
278 int numberOfPaddings{0};
279 std::vector<double> reference_coordinatesOfPaddings,coordinatesOfPaddings;
280 std::vector<std::string> speciesOfPaddings;
281 std::vector<int> masterOfPaddings;
293 reference_coordinatesOfPaddings,
294 coordinatesOfPaddings,
308 config_ptr->
species.push_back(*it);
310 if (numberOfPaddings)
312 if (referenceAndFinal) config_ptr->coordinates.at(
Reference).bottomRows(numberOfPaddings)=
313 *
new Eigen::Map<MatrixXd> (reference_coordinatesOfPaddings.data(),numberOfPaddings,
DIM);
314 config_ptr->coordinates.at(
Current).bottomRows(numberOfPaddings)=
315 *
new Eigen::Map<MatrixXd> (coordinatesOfPaddings.data(),numberOfPaddings,
DIM);
316 for (
auto it= speciesOfPaddings.begin();it!= speciesOfPaddings.end();it++)
317 config_ptr->species.push_back(*it);
int nbl_create_paddings(int const numberOfParticles, double const cutoff, double const *reference_cell, double const *cell, int const *PBC, double const *reference_coordinates, double const *coordinates, const std::vector< std::string > &speciesCode, int &numberOfPaddings, std::vector< double > &reference_coordinatesOfPaddings, std::vector< double > &coordinatesOfPaddings, std::vector< std::string > &speciesCodeOfPaddings, std::vector< int > &masterOfPaddings, int referenceAndFinal)