Skip to content

Commit

Permalink
Merge pull request #36 from RuhiRG/fixup
Browse files Browse the repository at this point in the history
ENH: simplifying the function readXYZ
  • Loading branch information
HaoZeke authored Jul 6, 2023
2 parents 13e0104 + 21fe0a0 commit b00eafa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/bulkTUM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<molSys::Point<double>, double>
setCloud; // PointCloud for holding the reference point values
// molSys::PointCloud<molSys::Point<double>, double>
// setCloud; // PointCloud for holding the reference point values
// Variables for rings
std::vector<std::vector<int>> nList; // Neighbour list
std::vector<std::vector<int>> rings; // Rings
Expand All @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down
3 changes: 1 addition & 2 deletions src/include/internal/seams_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ molSys::PointCloud<molSys::Point<double>, double> readLammpsTrjreduced(
std::array<double, 3> coordHigh = std::array<double, 3>{0, 0, 0});

//! Function for reading in atom coordinates from an XYZ file
int readXYZ(std::string filename,
molSys::PointCloud<molSys::Point<double>, double> *yCloud);
molSys::PointCloud<molSys::Point<double>, double> readXYZ(std::string filename);

//! Reads bonds into a vector of vectors from a file with a specific format
std::vector<std::vector<int>> readBonds(std::string filename);
Expand Down
2 changes: 1 addition & 1 deletion src/pntCorrespondence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 17 additions & 16 deletions src/seams_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ std::vector<std::vector<int>> sinp::readBonds(std::string filename) {
/**
* @details Function for reading in an XYZ file
*/
int sinp::readXYZ(std::string filename,
molSys::PointCloud<molSys::Point<double>, double> *yCloud) {
molSys::PointCloud<molSys::Point<double>, double> sinp::readXYZ(std::string filename) {
std::unique_ptr<std::ifstream> xyzFile;
xyzFile = std::make_unique<std::ifstream>(filename);
molSys::PointCloud<molSys::Point<double>, double>
yCloud;
std::string line; // Current line being read in
std::vector<std::string> tokens; // Vector containing word tokens
std::vector<double> numbers; // Vector containing type double numbers
Expand All @@ -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;
throw std::runtime_error("Wrong filepath");
}

// --------
// 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:
Expand All @@ -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

Expand All @@ -111,11 +113,11 @@ 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 <double>
// numbers
tokens = gen::tokenizer(line);
Expand All @@ -134,8 +136,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
Expand Down Expand Up @@ -168,29 +170,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
Expand Down

0 comments on commit b00eafa

Please sign in to comment.