From df7776699fed3cf89ab508caabebb85f55bd4c4a Mon Sep 17 00:00:00 2001 From: Ruhila S Date: Wed, 5 Jul 2023 23:35:19 +0000 Subject: [PATCH 1/3] ENH: simplifying the function readXYZ --- src/bulkTUM.cpp | 22 ++++++++--------- src/include/internal/seams_input.hpp | 3 +-- src/pntCorrespondence.cpp | 2 +- src/seams_input.cpp | 35 +++++++++++++++------------- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/bulkTUM.cpp b/src/bulkTUM.cpp index 4ea4181..22c1bf0 100644 --- a/src/bulkTUM.cpp +++ b/src/bulkTUM.cpp @@ -202,19 +202,19 @@ int tum3::topoUnitMatchingBulk( dumpAtomTypes.resize(atomTypes.size()); // Change from enum to int for (int i = 0; i < atomTypes.size(); i++) { - if (atomTypes[i] == cage::hc) { + if (atomTypes[i] == cage::iceType::hc) { dumpAtomTypes[i] = 1; } // HC - else if (atomTypes[i] == cage::ddc) { + else if (atomTypes[i] == cage::iceType::ddc) { dumpAtomTypes[i] = 2; } // DDC - else if (atomTypes[i] == cage::mixed) { + else if (atomTypes[i] == cage::iceType::mixed) { dumpAtomTypes[i] = 3; } // mixed rings - else if (atomTypes[i] == cage::pnc) { + else if (atomTypes[i] == cage::iceType::pnc) { dumpAtomTypes[i] = 4; } // pnc - else if (atomTypes[i] == cage::mixed2) { + else if (atomTypes[i] == cage::iceType::mixed2) { dumpAtomTypes[i] = 5; } // shared by pnc and ddc/hc else { @@ -378,8 +378,8 @@ Eigen::MatrixXd tum3::buildRefHC(std::string fileName) { // Eigen::MatrixXd refPnts(12, 3); // Reference point set (Eigen matrix) // Get the reference HC point set - molSys::PointCloud, double> - setCloud; // PointCloud for holding the reference point values + // molSys::PointCloud, double> + // setCloud; // PointCloud for holding the reference point values // Variables for rings std::vector> nList; // Neighbour list std::vector> rings; // Rings @@ -392,7 +392,7 @@ Eigen::MatrixXd tum3::buildRefHC(std::string fileName) { // // read in the XYZ file into the pointCloud setCloud // - sinp::readXYZ(fileName, &setCloud); + auto setCloud = sinp::readXYZ(fileName); // box lengths for (int i = 0; i < 3; i++) { setCloud.box[i] = 50; @@ -452,7 +452,7 @@ Eigen::MatrixXd tum3::buildRefDDC(std::string fileName) { // // read in the XYZ file into the pointCloud setCloud // - sinp::readXYZ(fileName, &setCloud); + setCloud = sinp::readXYZ(fileName); // box lengths for (int i = 0; i < 3; i++) { @@ -504,7 +504,7 @@ int tum3::updateRMSDatom(std::vector> rings, iatom = rings[iring][j]; // Current atom index // Skip for PNC atoms - if (atomTypes[iatom] == cage::pnc || atomTypes[iatom] == cage::mixed2) { + if (atomTypes[iatom] == cage::iceType::pnc || atomTypes[iatom] == cage::iceType::mixed2) { continue; } // Do not update if the atom is a PNC // @@ -730,7 +730,7 @@ int tum3::clusterCages( // If only one cage is in the cluster if (linkedList[i] == i) { // Add to the number of single DDCs - if (cageList[i].type == cage::DoubleDiaC) { + if (cageList[i].type == cage::cageType::DoubleDiaC) { singleDDCs++; } // add to the single DDCs else { diff --git a/src/include/internal/seams_input.hpp b/src/include/internal/seams_input.hpp index c3adf25..0585c9d 100644 --- a/src/include/internal/seams_input.hpp +++ b/src/include/internal/seams_input.hpp @@ -80,8 +80,7 @@ molSys::PointCloud, double> readLammpsTrjreduced( std::array coordHigh = std::array{0, 0, 0}); //! Function for reading in atom coordinates from an XYZ file -int readXYZ(std::string filename, - molSys::PointCloud, double> *yCloud); +molSys::PointCloud, double> readXYZ(std::string filename); //! Reads bonds into a vector of vectors from a file with a specific format std::vector> readBonds(std::string filename); diff --git a/src/pntCorrespondence.cpp b/src/pntCorrespondence.cpp index b64d0ad..afa4051 100644 --- a/src/pntCorrespondence.cpp +++ b/src/pntCorrespondence.cpp @@ -575,7 +575,7 @@ Eigen::MatrixXd pntToPnt::getPointSetCage(ring::strucType type) { // Read in the XYZ file std::string fileName = "templates/hc.xyz"; // - sinp::readXYZ(fileName, &setCloud); + sinp::readXYZ(fileName); int n = setCloud.nop; // Number of points in the reference point set Eigen::MatrixXd pointSet(n, 3); // Output point set for a regular polygon diff --git a/src/seams_input.cpp b/src/seams_input.cpp index f1b3b7a..34cefaf 100644 --- a/src/seams_input.cpp +++ b/src/seams_input.cpp @@ -70,10 +70,11 @@ std::vector> sinp::readBonds(std::string filename) { /** * @details Function for reading in an XYZ file */ -int sinp::readXYZ(std::string filename, - molSys::PointCloud, double> *yCloud) { +molSys::PointCloud, double> sinp::readXYZ(std::string filename) { std::unique_ptr xyzFile; xyzFile = std::make_unique(filename); + molSys::PointCloud, double> + yCloud; std::string line; // Current line being read in std::vector tokens; // Vector containing word tokens std::vector numbers; // Vector containing type double numbers @@ -87,13 +88,13 @@ int sinp::readXYZ(std::string filename, std::cout << "Fatal Error: The file does not exist or you gave the wrong path.\n"; // Throw exception? - return 1; + return yCloud; } // -------- // Before filling up the PointCloud, if the vectors are filled // empty them - *yCloud = molSys::clearPointCloud(yCloud); + //*yCloud = molSys::clearPointCloud(yCloud); // -------- // Format of an XYZ file: @@ -102,6 +103,7 @@ int sinp::readXYZ(std::string filename, // O 43.603500 16.926201 15.215700 // O 39.912601 14.775100 19.379200 if (xyzFile->is_open()) { + // ---------------------------------------------------------- // At this point we know that the XYZ file is open @@ -111,16 +113,18 @@ int sinp::readXYZ(std::string filename, // Skip the comment line std::getline((*xyzFile), line); // Reserve memory for atom coordinates using nop read in - yCloud->pts.reserve(nop); - yCloud->nop = nop; - + yCloud.pts.reserve(nop); + yCloud.nop = nop; // Run this until EOF or you reach the next timestep while (std::getline((*xyzFile), line)) { + // Read in lines and tokenize them into std::string words and // numbers tokens = gen::tokenizer(line); numbers = gen::tokenizerDouble(line); + std::cout + << "I am here at." << nop << "\n"; // Skip whitespace if (tokens.size() == 0) { continue; @@ -134,8 +138,8 @@ int sinp::readXYZ(std::string filename, iPoint.y = std::stod(tokens[2]); iPoint.z = std::stod(tokens[3]); - yCloud->pts.push_back(iPoint); - yCloud->idIndexMap[iPoint.atomID] = yCloud->pts.size() - 1; + yCloud.pts.push_back(iPoint); + yCloud.idIndexMap[iPoint.atomID] = yCloud.pts.size() - 1; iatom++; // Increase index // First point @@ -168,29 +172,28 @@ int sinp::readXYZ(std::string filename, zHi = iPoint.z; } // zHi } // update - } // end of while, looping through lines till EOF // ---------------------------------------------------------- } // End of if file open statement xyzFile->close(); - if (yCloud->pts.size() == 1) { + if (yCloud.pts.size() == 1) { xHi = xLo + 10; yHi = yLo + 10; zHi = zLo + 10; } // for a single point in the system (never happens) // Fill up the box lengths - yCloud->box.push_back(xHi - xLo); - yCloud->box.push_back(yHi - yLo); - yCloud->box.push_back(zHi - zLo); + yCloud.box.push_back(xHi - xLo); + yCloud.box.push_back(yHi - yLo); + yCloud.box.push_back(zHi - zLo); - if (yCloud->pts.size() != yCloud->nop) { + if (yCloud.pts.size() != yCloud.nop) { std::cout << "Atoms didn't get filled in properly.\n"; } - return 0; + return yCloud; } // External Libraries From e033e3c9e97881e289a08bd116012f690adb43ba Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 6 Jul 2023 00:34:06 +0000 Subject: [PATCH 2/3] MAINT: Remove debugging line --- src/seams_input.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/seams_input.cpp b/src/seams_input.cpp index 34cefaf..2d69456 100644 --- a/src/seams_input.cpp +++ b/src/seams_input.cpp @@ -123,8 +123,6 @@ molSys::PointCloud, double> sinp::readXYZ(std::string file tokens = gen::tokenizer(line); numbers = gen::tokenizerDouble(line); - std::cout - << "I am here at." << nop << "\n"; // Skip whitespace if (tokens.size() == 0) { continue; From 21fe0a0e92d77eff417931d31c65e93c46eddafd Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 6 Jul 2023 00:34:33 +0000 Subject: [PATCH 3/3] MAINT: Throw on invalid paths --- src/seams_input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seams_input.cpp b/src/seams_input.cpp index 2d69456..ee86ad1 100644 --- a/src/seams_input.cpp +++ b/src/seams_input.cpp @@ -88,7 +88,7 @@ molSys::PointCloud, double> sinp::readXYZ(std::string file std::cout << "Fatal Error: The file does not exist or you gave the wrong path.\n"; // Throw exception? - return yCloud; + throw std::runtime_error("Wrong filepath"); } // --------