Navigation Menu

Skip to content

Commit

Permalink
working on XYZ reader
Browse files Browse the repository at this point in the history
  • Loading branch information
apryor6 committed May 6, 2017
1 parent ab1414b commit 06f7f05
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Qt/PRISM-GUI.pro.user
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.2.1, 2017-05-05T08:28:19. -->
<!-- Written by QtCreator 4.2.1, 2017-05-05T22:00:55. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
11 changes: 11 additions & 0 deletions SI100.XYZ
@@ -0,0 +1,11 @@
one unit cell of 100 silicon
5.43 5.43 5.43
14 0.0000 0.0000 0.0000 1.0 0.076
14 2.7150 2.7150 0.0000 1.0 0.076
14 1.3575 4.0725 1.3575 1.0 0.076
14 4.0725 1.3575 1.3575 1.0 0.076
14 2.7150 0.0000 2.7150 1.0 0.076
14 0.0000 2.7150 2.7150 1.0 0.076
14 1.3575 1.3575 4.0725 1.0 0.076
14 4.0725 4.0725 4.0725 1.0 0.076
-1
10 changes: 10 additions & 0 deletions SRT.XYZ
@@ -0,0 +1,10 @@
one unit cell of strontium titanate
3.9051 3.9051 3.9051
38 0 0 0 1.0 0.08
8 1.95255 1.95255 0 1.0 0.08
22 1.95255 1.95255 1.95255 1.0 0.08
8 1.95255 0 1.95255 1.0 0.08
8 0 1.95255 1.95255 1.0 0.08
-1


75 changes: 75 additions & 0 deletions include/atom.h
Expand Up @@ -56,5 +56,80 @@ namespace PRISM{
return atoms;
};

inline std::vector<atom> readAtoms_XYZ(const std::string& filename){
std::vector<atom> atoms;
std::ifstream f(filename);
if (!f)throw std::runtime_error("Unable to open file.\n");
std::string line;
std::string token;
size_t line_num = 0;
size_t atom_count = 0;
if (!std::getline(f,line)) throw std::runtime_error("Error reading comment line.\n");
if (!std::getline(f,line)) throw std::runtime_error("Error reading unit cell params.\n");
double a,b,c; // unit cell params
{
std::stringstream ss(line);
if (!(ss >> a))
throw std::domain_error(
"Bad input data for unit cell dimension a.\n");
if (!(ss >> b))
throw std::domain_error(
"Bad input data for unit cell dimension a.\n");
if (!(ss >> c))
throw std::domain_error(
"Bad input data for unit cell dimension a.\n");
}
std::cout << "Unit cell a, b, c = " << a << ", " << b << ", " << c << std::endl;
while (std::getline(f, line)) {
line = line.substr(line.find_first_not_of(" "));

if (line=="-1"){
break;
} else {
std::cout << "line = " << line << std::endl;
}
{
std::string test("-1\n");
if (test == "-1")std::cout<<"yes\n";
std::cout << test << std::endl;
std::cout << line << std::endl;
std::cout << test.size() << std::endl;
std::cout << line.size() << std::endl;
}
++atom_count;
++line_num;
std::cout << "atom_count = " << atom_count << " line = " << line << std::endl;
}
// double tx, ty, tz;
// size_t tspecies;
// std::stringstream ss(line);
// if (!(ss >> tx))
// throw std::domain_error(
// "Bad input data for X. The txt file should continue 4 comma separated values per line (x,y,z,species).\n");
// if (ss.peek() == ',')ss.ignore();
// if (!(ss >> ty))
// throw std::domain_error(
// "Bad input data for Y. The txt file should continue 4 comma separated values per line (x,y,z,species).\n");
// if (ss.peek() == ',')ss.ignore();
// if (!(ss >> tz))
// throw std::domain_error(
// "Bad input data for Z. The txt file should continue 4 comma separated values per line (x,y,z,species).\n");
// if (ss.peek() == ',')ss.ignore();
// if (!(ss >> tspecies))
// throw std::domain_error(
// "Bad input data for atomic species. The txt file should continue 4 comma separated values per line (x,y,z,species).\n");
// if (ss.peek() == ',')ss.ignore();
// atoms.emplace_back(atom{tx, ty, tz, tspecies});
// }
// if (atom_count == 0) {
// std::domain_error("Bad input data. No atoms were found in this file.\n");
// } else {
// std::cout << "extracted " << atom_count << " atoms from " << line_num << " lines in " << filename
// << std::endl;
// }

return atoms;
};

}
#endif //PRISM_ATOM_H
3 changes: 2 additions & 1 deletion include/params.h
Expand Up @@ -134,7 +134,8 @@ namespace PRISM{
pixelSize[0] /= (T)imageSize[0];
pixelSize[1] /= (T)imageSize[1];
try {
atoms = readAtoms(meta.filename_atoms);
// atoms = readAtoms(meta.filename_atoms);
atoms = readAtoms_XYZ(meta.filename_atoms);
}
catch (const std::runtime_error &e) {
std::cout << "PRISM: Error opening " << meta.filename_atoms << std::endl;
Expand Down

0 comments on commit 06f7f05

Please sign in to comment.