Utility class to read file.
More...
#include <ReadFile.h>
|
static std::vector< std::array
< double, 4 > > | ReadXYZ (std::string FileName) |
| Read xyz file. More...
|
|
Utility class to read file.
Simple utility class to read in a trajectory file.
Supported file types:
Definition at line 44 of file ReadFile.h.
static std::vector<std::array<double,4> > SSAGES::ReadFile::ReadXYZ |
( |
std::string |
FileName | ) |
|
|
inlinestatic |
Read xyz file.
- Parameters
-
FileName | Name of xyz file to read in. |
- Returns
- Vector containing information stored in file.
Read in a xyz file. The information will be returned as a vector of 4-element arrays. Each array corresponds to one atom and stores the following information: atom-ID, x-coordinate, y-coordinate, z-coordinate.
Definition at line 70 of file ReadFile.h.
72 std::vector<std::array<double,4>> refcoord;
74 std::string comments =
"";
76 infile.open(FileName, std::ios::in);
78 throw std::runtime_error(
"File " + FileName +
" does not exist.");
82 std::getline(infile, ignore);
84 numatoms = std::atoi(ignore.c_str());
86 throw std::runtime_error(
"Must be more than 0 atoms or invalid number atoms defined.");
88 refcoord.resize(numatoms);
90 std::getline(infile, comments);
97 std::getline(infile,line);
98 std::istringstream iss(line);
99 if (!(iss >> refcoord[i][0] >> refcoord[i][1] >> refcoord[i][2] >> refcoord[i][3]))
100 throw std::runtime_error(
"Bad file format for " + FileName +
" for atom " + std::to_string(i+1));
104 if(std::getline(infile, line) && !line.empty())
105 throw std::runtime_error(
"Bad end line, possibly too many atoms defined.");
108 throw std::runtime_error(
"Number atoms specified does not match number of atoms defined");
The documentation for this class was generated from the following file: