Loading...
Searching...
No Matches
TestJob.cpp
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
12#include "eon/TestJob.h"
13#include "eon/HelperFunctions.h"
14#include "eon/Matter.h"
15#include "eon/Potential.h"
16
17#include "magic_enum/magic_enum.hpp"
18#include <array>
19#include <cmath>
20#include <fstream>
21#include <stdexcept>
22#include <string>
23
24namespace eonc {
25
26namespace {
27struct PotRef {
28 const char *tag;
29 eonc::PotType type;
30 double energy;
31 double max_force;
32};
33} // namespace
34
35std::vector<std::string> TestJob::run() {
38 return {"results.dat"};
39}
40
42 // Historical saddle self-test needs reactant_test.con / displacement_test.con
43 // which the tree does not ship. Keep the hook.
44}
45
47 const std::array<PotRef, 8> cases{{
48 {"lj", eonc::PotType::LJ, -1475.984331, 2.007213},
49 {"emt", eonc::PotType::EMT, 46.086312, 0.357493},
50 {"edip", eonc::PotType::EDIP, -1033.250950, 7.080115},
51 {"tersoff_si", eonc::PotType::TERSOFF_SI, -1035.809985, 11.145002},
52 {"sw_si", eonc::PotType::SW_SI, -1449.795645, 2.530904},
53 {"lenosky_si", eonc::PotType::LENOSKY_SI, -1410.679106, 2.320168},
54 {"eam_al", eonc::PotType::EAM_AL, -1206.825825, 0.000246},
55 {"tip4p", eonc::PotType::TIP4P, 4063.865115, 73.655248},
56 }};
57
58 std::ofstream out("results.dat");
59 for (const auto &c : cases) {
60 try {
61 const double de = getEnergyDiff(c.tag, c.energy);
62 if (std::abs(de) > tolerance) {
63 out << "FAIL " << c.tag << " energy_diff " << de << "\n";
64 continue;
65 }
66 const double df = getForceDiff(c.tag, c.max_force);
67 if (std::abs(df) > tolerance) {
68 out << "FAIL " << c.tag << " force_diff " << df << "\n";
69 continue;
70 }
71 out << "OK " << c.tag << "\n";
72 } catch (const std::exception &e) {
73 out << "SKIP " << c.tag << " " << e.what() << "\n";
74 }
75 }
76}
77
78double TestJob::getEnergyDiff(const std::string &potTag, double refEnergy) {
79 auto type = magic_enum::enum_cast<eonc::PotType>(
80 potTag, magic_enum::case_insensitive);
81 if (!type) {
82 throw std::invalid_argument("unknown pot " + potTag);
83 }
86 auto potHandle = eonc::helpers::makePotential(*type, p);
87 Matter pos(potHandle, p);
88 if (!eonc::io::io_ok(pos.con2matter(std::string("pos_test.con")))) {
89 throw std::runtime_error("no pos_test.con");
90 }
91 return pos.getPotentialEnergy() - refEnergy;
92}
93
94double TestJob::getForceDiff(const std::string &potTag, double refForce) {
95 auto type = magic_enum::enum_cast<eonc::PotType>(
96 potTag, magic_enum::case_insensitive);
97 if (!type) {
98 throw std::invalid_argument("unknown pot " + potTag);
99 }
100 Parameters p = params;
102 auto potHandle = eonc::helpers::makePotential(*type, p);
103 Matter pos(potHandle, p);
104 if (!eonc::io::io_ok(pos.con2matter(std::string("pos_test.con")))) {
105 throw std::runtime_error("no pos_test.con");
106 }
107 return pos.maxForce() - refForce;
108}
109
110} // namespace eonc
Parameters params
Definition Job.h:58
double getPotentialEnergy() const
Definition Matter.cpp:554
io::IoStatus con2matter(std::string filename)
Definition Matter.h:256
double maxForce(void) const
Definition Matter.cpp:685
double tolerance
Definition TestJob.h:31
void checkPotentials()
Definition TestJob.cpp:46
void checkFullSearch()
Definition TestJob.cpp:41
double getEnergyDiff(const std::string &potTag, double refEnergy)
Definition TestJob.cpp:78
std::vector< std::string > run()
Virtual run; used solely for dynamic dispatch.
Definition TestJob.cpp:35
double getForceDiff(const std::string &potTag, double refForce)
Definition TestJob.cpp:94
std::shared_ptr< Potential > makePotential(const Parameters &params)
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
RAII resource manager for the ARTn C library with global synchronization.
static potential_options_t & potential_options(Parameters &p)