Loading...
Searching...
No Matches
JobResult.h
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#pragma once
13
14#include "BaseStructures.h"
15
16#include <cstdint>
17#include <format>
18#include <fstream>
19#include <sstream>
20#include <stdexcept>
21#include <string>
22#include <utility>
23#include <vector>
24
25#include "magic_enum/magic_enum.hpp"
26
27namespace eonc {
28
33 std::string job_type;
35 std::string status_text;
36 std::string potential_type;
37 std::int64_t random_seed{-1};
38 std::uint64_t force_calls{0};
39 double potential_energy{0.0};
40 bool has_energy{false};
44 bool has_saddle{false};
45 bool has_reactant{false};
46 bool has_product{false};
47 std::vector<std::pair<std::string, double>> extras;
48 std::vector<std::pair<std::string, std::string>> tags;
49
50 std::string toString() const {
51 std::ostringstream out;
52 out << status_code << " termination_reason\n";
53 if (!status_text.empty()) {
54 out << status_text << " termination_reason_text\n";
55 }
56 if (!job_type.empty()) {
57 out << job_type << " job_type\n";
58 }
59 if (!potential_type.empty()) {
60 out << potential_type << " potential_type\n";
61 }
62 if (random_seed >= 0) {
63 out << random_seed << " random_seed\n";
64 }
65 out << force_calls << " total_force_calls\n";
66 if (has_energy) {
67 out << std::format("{:.12e} potential_energy\n", potential_energy);
68 }
69 if (has_saddle) {
70 out << std::format("{:.12e} potential_energy_saddle\n",
72 }
73 if (has_reactant) {
74 out << std::format("{:.12e} potential_energy_reactant\n",
76 }
77 if (has_product) {
78 out << std::format("{:.12e} potential_energy_product\n",
80 }
81 for (const auto &kv : extras) {
82 out << std::format("{:.12e} {}\n", kv.second, kv.first);
83 }
84 for (const auto &kv : tags) {
85 out << kv.second << " " << kv.first << "\n";
86 }
87 return out.str();
88 }
89
90 void writeResultsDat(const std::string &path) const {
91 std::ofstream out(path, std::ios::binary);
92 if (!out) {
93 throw std::runtime_error("JobResultEnvelope: cannot open " + path);
94 }
95 out << toString();
96 if (!out) {
97 throw std::runtime_error("JobResultEnvelope: write failed for " + path);
98 }
99 }
100
102 std::uint64_t fcalls, bool hasE,
103 double energy) {
105 e.job_type = "minimization";
106 e.status_code = static_cast<int>(status);
107 e.status_text = std::string(magic_enum::enum_name<RunStatus>(status));
108 e.potential_type = std::string(magic_enum::enum_name<PotType>(pot));
109 e.force_calls = fcalls;
110 e.has_energy = hasE;
111 e.potential_energy = energy;
112 return e;
113 }
114};
115
116} // namespace eonc
RAII resource manager for the ARTn C library with global synchronization.
In-memory JobResult scalars.
Definition JobResult.h:32
std::vector< std::pair< std::string, double > > extras
Definition JobResult.h:47
std::uint64_t force_calls
Definition JobResult.h:38
double potential_energy_product
Definition JobResult.h:43
std::vector< std::pair< std::string, std::string > > tags
Definition JobResult.h:48
std::string potential_type
Definition JobResult.h:36
void writeResultsDat(const std::string &path) const
Definition JobResult.h:90
std::string status_text
Definition JobResult.h:35
double potential_energy_reactant
Definition JobResult.h:42
std::string toString() const
Definition JobResult.h:50
std::int64_t random_seed
Definition JobResult.h:37
static JobResultEnvelope fromMinimization(RunStatus status, PotType pot, std::uint64_t fcalls, bool hasE, double energy)
Definition JobResult.h:101