8 #ifndef SWOOSE_REFERENCEDATAFORTESTS_H
9 #define SWOOSE_REFERENCEDATAFORTESTS_H
11 #include "../Files/tests_file_location.h"
20 using ForcesCollection = Eigen::Matrix<double, Eigen::Dynamic, 3, Eigen::RowMajor>;
22 namespace ReferenceDataForTests {
24 inline std::vector<double> parseReferenceEnergies() {
25 std::vector<double> energies;
27 std::ifstream indata(reference_energies_file);
28 if (!indata.is_open()) {
29 throw std::runtime_error(
"The file containing the reference energies for the tests could not be opened.");
33 while (line.empty()) {
34 std::getline(indata, line);
37 while (!line.empty()) {
38 std::list<int> listForOneAtom;
39 std::regex rgx(
"\\s+");
40 std::sregex_token_iterator iter(line.begin(), line.end(), rgx, -1);
41 std::sregex_token_iterator end;
46 double value = std::stod(*iter);
47 energies.push_back(value);
49 std::getline(indata, line);
55 inline std::vector<ForcesCollection> parseReferenceForces(std::string filename,
int nStruct,
int nAtoms) {
56 std::vector<Swoose::ForcesCollection> forces;
57 for (
int i = 0; i < nStruct; ++i) {
58 ForcesCollection f(nAtoms, 3);
62 std::ifstream indata(filename);
63 if (!indata.is_open()) {
64 throw std::runtime_error(
"The file containing the reference forces for the tests could not be opened.");
68 while (line.empty()) {
69 std::getline(indata, line);
72 while (!line.empty()) {
73 std::list<int> listForOneAtom;
74 std::regex rgx(
"\\s+");
75 std::sregex_token_iterator iter(line.begin(), line.end(), rgx, -1);
76 std::sregex_token_iterator end;
81 int structureIndex = std::stoi(*iter++);
82 int atomIndex = std::stoi(*iter++);
83 int dimension = std::stoi(*iter++);
84 double value = std::stod(*iter++);
86 forces.at(structureIndex)(atomIndex, dimension) = value;
88 std::getline(indata, line);
98 #endif // SWOOSE_REFERENCEDATAFORTESTS_H