Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: simplifying the function readXYZ #36

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/bulkTUM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down 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 Expand Up @@ -504,7 +504,7 @@ int tum3::updateRMSDatom(std::vector<std::vector<int>> 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
//
Expand Down Expand Up @@ -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 {
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
35 changes: 19 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;
return yCloud;
HaoZeke marked this conversation as resolved.
Show resolved Hide resolved
}

// --------
// 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,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 <double>
// numbers
tokens = gen::tokenizer(line);
numbers = gen::tokenizerDouble(line);

std::cout
<< "I am here at." << nop << "\n";
HaoZeke marked this conversation as resolved.
Show resolved Hide resolved
// Skip whitespace
if (tokens.size() == 0) {
continue;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down