SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
Public Member Functions | Static Public Member Functions | List of all members
SSAGES::ReadFile Class Reference

Utility class to read file. More...

#include <ReadFile.h>

Public Member Functions

 ReadFile ()
 Constructor.
 
 ~ReadFile ()
 Deconstructor.
 

Static Public Member Functions

static std::vector< std::array< double, 4 > > ReadXYZ (std::string FileName)
 Read xyz file. More...
 

Detailed Description

Utility class to read file.

Simple utility class to read in a trajectory file.

Supported file types:

Definition at line 42 of file ReadFile.h.

Member Function Documentation

◆ ReadXYZ()

static std::vector<std::array<double,4> > SSAGES::ReadFile::ReadXYZ ( std::string  FileName)
inlinestatic

Read xyz file.

Parameters
FileNameName 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 66 of file ReadFile.h.

67  {
68  std::vector<std::array<double,4>> refcoord;
69  int numatoms = 0;
70  std::string comments = "";
71  std::ifstream infile;
72  infile.open(FileName, std::ios::in);
73  if(!infile.is_open())
74  {
75  throw std::runtime_error("ReadFile.h: File " + FileName + " does not exist.");
76  }
77 
78  std::string line;
79  std::getline(infile, line); // Get number of atoms
80 
81  try
82  {
83  numatoms = std::stoi(line);
84  }
85  catch (const std::invalid_argument&)
86  {
87  throw std::runtime_error("ReadFile.h: Invalid number of atoms defined in File.");
88  }
89  if(numatoms <= 0)
90  {
91  throw std::runtime_error("ReadFile.h: Must be more than 0 atoms defined in File.");
92  }
93 
94  refcoord.resize(numatoms);
95 
96  std::getline(infile, comments); // Get comments
97 
98  int i = 0;
99  std::array<double,4> row;
100  while(infile >> row[0] >> row[1] >> row[2] >> row[3])
101  {
102  if(i < numatoms) refcoord[i] = row;
103  i++;
104  }
105  if(i != numatoms)
106  {
107  throw std::runtime_error(
108  "ReadFile: Header specified " + std::to_string(numatoms) +
109  " atoms, but read in " + std::to_string(i) + ". " +
110  "Check the format of " + FileName + "."
111  );
112  }
113 
114  return refcoord;
115  }

Referenced by SSAGES::RMSDCV::Initialize().

Here is the caller graph for this function:

The documentation for this class was generated from the following file: