Loading...
Searching...
No Matches
HelperFunctions.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/HelperFunctions.h"
13#include "eon/EonLogger.h"
14#include "eon/EpiCenters.h"
15#include "eon/ExactReduction.h"
18#include "eon/Optimizer.h"
19#include "eon/Parameters.h"
20#include "eon/SafeMath.h"
21
22#include <cassert>
23#include <cerrno>
24#include <chrono>
25#include <cmath>
26#include <cstring>
27#include <ctime>
28#include <filesystem>
29#include <format>
30#include <fstream>
31#include <iostream>
32#include <memory>
33#include <sstream>
34#include <stdexcept>
35#include <utility>
36
37#ifndef _WIN32
38#include <sys/resource.h>
39#include <sys/time.h>
40#endif
41// Vector functions.
42// Make v1 orthogonal to v2
44 const AtomMatrix v2) {
45 return v1 - matDot(v1, v2) * eonc::safemath::safe_normalized(v2);
46}
47
48void eonc::helpers::getTime(double *real, double *user, double *sys) {
49 using namespace std::chrono;
50 auto now = steady_clock::now();
51 if (real) {
52 *real = duration<double>(now.time_since_epoch()).count();
53 }
54
55#ifdef _WIN32
56 if (user)
57 *user = 0.0;
58 if (sys)
59 *sys = 0.0;
60#else
61 struct rusage r_usage;
62 if (getrusage(RUSAGE_SELF, &r_usage) != 0) {
63 EONC_LOG_WARNING("problem getting usage info: {}", strerror(errno));
64 }
65 if (user) {
66 *user = static_cast<double>(r_usage.ru_utime.tv_sec) +
67 static_cast<double>(r_usage.ru_utime.tv_usec) / 1e6;
68 }
69 if (sys) {
70 *sys = static_cast<double>(r_usage.ru_stime.tv_sec) +
71 static_cast<double>(r_usage.ru_stime.tv_usec) / 1e6;
72 }
73#endif
74}
75
76bool eonc::helpers::existsFile(std::string filename) {
77 return std::filesystem::exists(filename);
78}
79
80std::optional<std::string>
81eonc::helpers::enterJobDirectory(std::string_view jobPath) {
82 try {
83 std::filesystem::current_path(std::filesystem::path{jobPath});
84 } catch (const std::filesystem::filesystem_error &err) {
85 return std::string{err.what()};
86 }
87 return std::nullopt;
88}
89
90bool eonc::helpers::stageReturnLog(std::string_view logHome,
91 std::string_view name) {
92 namespace fs = std::filesystem;
93 if (name.empty() || name == "." || name == ".." ||
94 name.find('/') != std::string_view::npos ||
95 name.find('\\') != std::string_view::npos) {
96 return false;
97 }
98 const fs::path dest{std::string{name}};
99 std::error_code ec;
100 const bool destFile = fs::is_regular_file(dest, ec);
101 if (logHome.empty()) {
102 return destFile;
103 }
104 const fs::path src = fs::path{std::string{logHome}} / dest.filename();
105 ec.clear();
106 if (!fs::is_regular_file(src, ec)) {
107 return destFile;
108 }
109 ec.clear();
110 if (destFile && fs::equivalent(src, dest, ec)) {
111 return true;
112 }
113 ec.clear();
114 fs::copy_file(src, dest, fs::copy_options::overwrite_existing, ec);
115 if (ec) {
116 EONC_LOG_ERROR("stageReturnLog: cannot copy {} to {}: {}", src.string(),
117 dest.string(), ec.message());
118 return fs::is_regular_file(dest);
119 }
120 return true;
121}
122
123std::string eonc::helpers::getRelevantFile(std::string filename) {
124 const auto dot = filename.rfind('.');
125 const std::string prefix =
126 (dot == std::string::npos) ? filename : filename.substr(0, dot);
127 const std::string postfix =
128 (dot == std::string::npos) ? std::string{} : filename.substr(dot);
129 std::string filenameRelevant = prefix + "_cp" + postfix;
130 if (existsFile(filenameRelevant)) {
131 return filenameRelevant;
132 }
133 filenameRelevant = prefix + "_in" + postfix;
134 if (existsFile(filenameRelevant)) {
135 return filenameRelevant;
136 }
137 return filename;
138}
139
140VectorXd eonc::helpers::loadMasses(std::string filename, int nAtoms) {
141 std::ifstream massFile(filename.c_str());
142 if (!massFile.is_open()) {
143 EONC_LOG_CRITICAL("File {} was not found", filename);
144 throw std::runtime_error(std::format("cannot open {}", filename));
145 }
146
147 VectorXd masses(nAtoms);
148 for (int i = 0; i < nAtoms; i++) {
149 double mass;
150 if (!(massFile >> mass)) {
151 EONC_LOG_CRITICAL("Error reading {}", filename);
152 throw std::runtime_error(
153 std::format("{} ended after {} of {} masses", filename, i, nAtoms));
154 }
155 masses(i) = mass;
156 }
157
158 massFile.close();
159
160 return masses;
161}
162
163AtomMatrix eonc::helpers::loadMode(FILE *modeFile, int nAtoms) {
164 AtomMatrix mode;
165 mode.resize(nAtoms, 3);
166 mode.setZero();
167 for (int i = 0; i < nAtoms; i++) {
168 if (fscanf(modeFile, "%lf %lf %lf", &mode(i, 0), &mode(i, 1),
169 &mode(i, 2)) != 3) {
170 EONC_LOG_CRITICAL("Mode file ended after {} of {} atoms", i, nAtoms);
171 throw std::runtime_error(
172 std::format("mode file ended after {} of {} atoms", i, nAtoms));
173 }
174 }
175 return mode;
176}
177
178AtomMatrix eonc::helpers::loadMode(std::string filename, int nAtoms) {
179 // Unique FILE* with RAII cleanup
180 auto closer = [](FILE *f) {
181 if (f)
182 std::fclose(f);
183 };
184 std::unique_ptr<FILE, decltype(closer)> modeFile(
185 std::fopen(filename.c_str(), "rb"), closer);
186 if (!modeFile) {
187 EONC_LOG_CRITICAL("File {} was not found", filename);
188 throw std::runtime_error(std::format("cannot open {}", filename));
189 }
190 return loadMode(modeFile.get(), nAtoms);
191}
192
194 Matter &target, const Matter &initial, const std::string &displacementPath,
195 const std::string &modePath, double scale) {
196 if (eonc::io::io_ok(target.con2matter(displacementPath))) {
197 if (target.numberOfAtoms() != initial.numberOfAtoms()) {
198 EONC_LOG_ERROR("{} holds {} atoms, the initial structure has {}",
199 displacementPath, target.numberOfAtoms(),
200 initial.numberOfAtoms());
201 return false;
202 }
203 // displacement.con may carry stale fixed-atom coordinates from a prior run.
204 // It also usually has sequential column-5 ids; keep the reactant's.
205 const AtomMatrix &initPos = initial.getPositions();
206 AtomMatrix pos = target.getPositionsCopy();
207 const long n = initial.numberOfAtoms();
208 std::vector<long> fileMap(static_cast<size_t>(n));
209 for (long i = 0; i < n; i++) {
210 if (initial.getFixed(i)) {
211 pos.row(i) = initPos.row(i);
212 }
213 target.setAtomIndex(i, initial.getAtomIndex(i));
214 fileMap[static_cast<size_t>(i)] = initial.mapFileRow(i);
215 }
216 target.setFileToMatter(std::move(fileMap));
217 target.setPositions(pos);
218 return true;
219 }
220 if (!existsFile(modePath)) {
221 return false;
222 }
223 AtomMatrix mode =
224 loadMode(modePath, static_cast<int>(initial.numberOfAtoms()));
225 const double norm = mode.norm();
226 if (!(norm > 0.0)) {
227 return false;
228 }
229 mode *= (scale / norm);
230 target = initial;
231 AtomMatrix pos = initial.getPositionsCopy();
232 pos += mode;
233 const AtomMatrix &initPos = initial.getPositions();
234 const long n = initial.numberOfAtoms();
235 for (long i = 0; i < n; i++) {
236 if (initial.getFixed(i)) {
237 pos.row(i) = initPos.row(i);
238 }
239 }
240 target.setPositions(pos);
241 EONC_LOG_INFO("Synthesized displacement from pos.con + scale {:.6g} * unit "
242 "mode in {} (missing {})",
243 scale, modePath, displacementPath);
244 return true;
245}
246
248 const Matter &initial,
249 const Parameters &params,
250 AtomMatrix *modeOut) {
251 using namespace eonc::EpiCenters;
252 const auto &opt = params.saddle_search_options();
253 const std::string &dtype = opt.displace_type;
254 if (dtype == DISP_LOAD) {
255 return false;
256 }
257
258 long epicenter = -1;
259 const double cutoff = params.structure_comparison_options().neighbor_cutoff;
260 if (dtype == DISP_LISTED_ATOMS) {
261 epicenter = listedAtomEpiCenter(&initial, opt.displace_atom_list);
262 } else if (dtype == DISP_RANDOM) {
263 epicenter = randomFreeAtomEpiCenter(&initial);
264 } else if (dtype == DISP_LAST_ATOM) {
265 epicenter = lastAtom(&initial);
266 } else if (dtype == DISP_MIN_COORDINATED) {
267 epicenter = minCoordinatedEpiCenter(&initial, cutoff);
268 } else if (dtype == DISP_NOT_FCC_OR_HCP) {
269 epicenter = cnaEpiCenter(&initial, cutoff);
270 } else {
271 return false;
272 }
273
274 target = initial;
275 const long n = initial.numberOfAtoms();
276 const double radius = opt.displace_radius;
277 const double mag = opt.displace_magnitude;
278 AtomMatrix pos = initial.getPositionsCopy();
279 AtomMatrix mode = AtomMatrix::Zero(n, 3);
280 for (long i = 0; i < n; ++i) {
281 if (initial.getFixed(i)) {
282 continue;
283 }
284 const double dist = (i == epicenter) ? 0.0 : initial.distance(epicenter, i);
285 if (dist <= radius) {
286 for (int a = 0; a < 3; ++a) {
287 mode(i, a) = eonc::rng::gaussRandom(0.0, mag);
288 }
289 }
290 }
291 const double norm = mode.norm();
292 if (norm > 0.0) {
293 pos += mode;
294 mode /= norm;
295 } else if (epicenter >= 0 && epicenter < n && !initial.getFixed(epicenter)) {
296 mode(epicenter, 0) = 1.0;
297 pos(epicenter, 0) += mag;
298 }
299 target.setPositions(pos);
300 if (modeOut != nullptr) {
301 *modeOut = std::move(mode);
302 }
303 return true;
304}
305
306void eonc::helpers::saveMode(FILE *modeFile, std::shared_ptr<Matter> matter,
307 AtomMatrix mode) {
308 const AtomMatrix free = matter->getFree();
309 long const nAtoms = matter->numberOfAtoms();
310 for (long i = 0; i < nAtoms; ++i) {
311 fprintf(modeFile, "%.17g\t%.17g\t%.17g\n", free(i, 0) * mode(i, 0),
312 free(i, 1) * mode(i, 1), free(i, 2) * mode(i, 2));
313 }
314 return;
315}
316
317void eonc::helpers::saveMode(const std::string &filename,
318 std::shared_ptr<Matter> matter, AtomMatrix mode) {
319 std::ofstream out(filename);
320 if (!out)
321 return;
322 const AtomMatrix free = matter->getFree();
323 long const nAtoms = matter->numberOfAtoms();
324 for (long i = 0; i < nAtoms; ++i) {
325 out << std::format("{:.17g}\t{:.17g}\t{:.17g}\n", free(i, 0) * mode(i, 0),
326 free(i, 1) * mode(i, 1), free(i, 2) * mode(i, 2));
327 }
328}
329
330std::vector<int> eonc::helpers::split_string_int(std::string s,
331 std::string delim) {
332 std::vector<int> list;
333 if (s.empty())
334 return list;
335
336 size_t start = 0;
337 size_t end = s.find_first_of(delim);
338 while (start < s.size()) {
339 auto token = s.substr(start, end - start);
340 if (!token.empty()) {
341 try {
342 list.push_back(std::stoi(token));
343 } catch (const std::exception &) {
344 return {}; // Parse error
345 }
346 }
347 if (end == std::string::npos)
348 break;
349 start = end + 1;
350 end = s.find_first_of(delim, start);
351 }
352 return list;
353}
354
355std::optional<std::string_view>
357 if (metric == "max_atom") {
358 return "Max atom force";
359 }
360 if (metric == "max_component") {
361 return "Max force comp";
362 }
363 if (metric == "norm") {
364 return "||Force||";
365 }
366 if (metric == "rms") {
367 return "RMS force";
368 }
369 return std::nullopt;
370}
371
373 std::string_view context) {
374 if (convergenceMetricLabel(metric)) {
375 return;
376 }
377 throw std::invalid_argument(
378 std::format("{} unknown convergence_metric: {}", context, metric));
379}
380
381namespace {
382class MatterObjectiveFunction : public eonc::ObjectiveFunction {
383 eonc::Matter &m_matter; // non-owning reference, avoids copy
384public:
385 MatterObjectiveFunction(eonc::Matter &mat,
386 const eonc::Parameters &parametersPassed)
387 : eonc::ObjectiveFunction(parametersPassed),
388 m_matter{mat} {
390 params.optimizer_options().convergence_metric, "[Matter]");
391 }
392 ~MatterObjectiveFunction() = default;
393 double getEnergy() { return m_matter.getPotentialEnergy(); }
394 VectorXd getGradient(bool fdstep = false) {
395 return -m_matter.getForcesFreeV();
396 }
397 void setPositions(const VectorXd &x) { m_matter.setPositionsFreeV(x); }
398 VectorXd getPositions() { return m_matter.getPositionsFreeV(); }
399 int degreesOfFreedom() { return 3 * m_matter.numberOfFreeAtoms(); }
400 bool isConverged() {
401 return getConvergence() < params.optimizer_options().converged_force;
402 }
403 double getConvergence() {
404 if (params.optimizer_options().convergence_metric == "norm") {
405 return eonc::exact::norm(m_matter.getForcesFreeV());
406 } else if (params.optimizer_options().convergence_metric == "rms") {
407 const VectorXd f = m_matter.getForcesFreeV();
408 const auto n = f.size();
409 return n > 0 ? eonc::exact::norm(f) / std::sqrt(static_cast<double>(n))
410 : 0.0;
411 } else if (params.optimizer_options().convergence_metric == "max_atom") {
412 return m_matter.maxForce();
413 } else if (params.optimizer_options().convergence_metric ==
414 "max_component") {
415 return m_matter.getForces().cwiseAbs().maxCoeff();
416 } else {
417 EONC_LOG_CRITICAL("{} Unknown opt_convergence_metric: {}", "[Matter]",
418 params.optimizer_options().convergence_metric);
419 throw std::invalid_argument(
420 std::format("[Matter] unknown convergence_metric: {}",
421 params.optimizer_options().convergence_metric));
422 }
423 }
424 VectorXd difference(const VectorXd &a, const VectorXd &b) {
425 return m_matter.pbcV(a - b);
426 }
427 VectorXd getMasses() const override {
428 const auto all = m_matter.getMasses();
429 const auto mask = m_matter.getFree();
430 VectorXd out(m_matter.numberOfFreeAtoms());
431 long k = 0;
432 for (long i = 0; i < m_matter.numberOfAtoms(); ++i) {
433 if (mask.row(i).sum() > 0.5) {
434 out[k++] = all[i];
435 }
436 }
437 return out;
438 }
439 bool getPeriodic() const override { return m_matter.getPeriodic(); }
440 void minimumImage(Eigen::Ref<Eigen::Vector3d> dr) const override {
441 AtomMatrix m(1, 3);
442 m.row(0) = dr.transpose();
443 m = m_matter.pbc(m);
444 dr = m.row(0).transpose();
445 }
446};
447} // namespace
448
449bool eonc::helpers::relaxMatter(Matter &matter, const Parameters &params,
450 bool quiet, bool writeMovie, bool checkpoint,
451 std::string prefixMovie,
452 std::string prefixCheckpoint,
453 std::vector<readcon::ConFrame> *outFrames) {
454 eonc::log::Scoped m_log;
455 auto objf = std::make_shared<MatterObjectiveFunction>(matter, params);
457 objf, params.optimizer_options().method, params);
458
459 std::ostringstream min;
460 min << prefixMovie;
461 std::string minDatFilename = prefixMovie + ".dat";
462 auto write_movie_frame = [&](uint64_t frameIndex, bool append,
463 double stepSize) {
465 metadata.frame_index = frameIndex;
466 metadata.energy = matter.getPotentialEnergy();
467 metadata.scalars.push_back({"step_size", stepSize});
468 metadata.scalars.push_back({"convergence", objf->getConvergence()});
469 if (outFrames) {
470 outFrames->push_back(eonc::io::matterToConFrame(matter, &metadata));
471 }
472 if (writeMovie) {
473 if (!eonc::io::io_ok(matter.matter2con(min.str(), append, &metadata))) {
474 QUILL_LOG_WARNING(m_log, "Failed to write movie frame {}", min.str());
475 }
476 }
477
479 std::ofstream minDat(minDatFilename,
480 append ? (std::ios::binary | std::ios::app)
481 : std::ios::binary);
482 if (minDat) {
483 if (!append) {
484 minDat << "iteration\tstep_size\tconvergence\tenergy\n";
485 }
486 minDat << std::format("{}\t{:.5e}\t{:.5e}\t{:.6f}\n", frameIndex,
487 stepSize, objf->getConvergence(),
488 matter.getPotentialEnergy());
489 }
490 }
491 };
492 if (writeMovie || outFrames) {
493 write_movie_frame(0, false, 0.0);
494 }
495
496 int iteration = 0;
497 if (!quiet) {
498 QUILL_LOG_DEBUG(m_log, "{} {:10s} {:14s} {:18s} {:13s}\n", "[Matter]",
499 "Iter", "Step size",
501 "Energy");
502 QUILL_LOG_DEBUG(m_log, "{} {:10} {:14.5e} {:18.5e} {:13.5f}\n",
503 "[Matter]", iteration, 0.0, objf->getConvergence(),
504 matter.getPotentialEnergy());
505 }
506
507 while (!objf->isConverged() &&
508 iteration < params.optimizer_options().max_iterations) {
509 matter.pollCancel("relax");
510
511 AtomMatrix pos = matter.getPositions();
512
513 optim->step(params.optimizer_options().max_move);
514 iteration++;
515
516 double stepSize =
517 eonc::geometry::maxAtomMotion(matter.pbc(matter.getPositions() - pos));
518
519 if (!quiet) {
520 QUILL_LOG_DEBUG(m_log, "{} {:10} {:14.5e} {:18.5e} {:13.5f}",
521 "[Matter]", iteration, stepSize, objf->getConvergence(),
522 matter.getPotentialEnergy());
523 }
524
525 if (writeMovie || outFrames) {
526 write_movie_frame(static_cast<uint64_t>(iteration), true, stepSize);
527 }
528
529 if (checkpoint) {
530 std::ostringstream chk;
531 chk << prefixCheckpoint << "_cp";
532 if (!eonc::io::io_ok(matter.matter2con(chk.str(), false))) {
533 QUILL_LOG_WARNING(m_log, "Failed to write checkpoint {}", chk.str());
534 }
535 }
536 }
537
538 if (iteration == 0) {
539 if (!quiet) {
540 QUILL_LOG_DEBUG(m_log, "{} {:10} {:14.5e} {:18.5e} {:13.5f}",
541 "[Matter]", iteration, 0.0, objf->getConvergence(),
542 matter.getPotentialEnergy());
543 }
544 }
545 return objf->isConverged();
546}
double matDot(const AtomMatrix &a, const AtomMatrix &b)
SIMD-optimized dot product for contiguous Eigen matrices.
Definition Eigen.h:50
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
#define EONC_LOG_ERROR(...)
Definition EonLogger.h:328
#define EONC_LOG_WARNING(...)
Definition EonLogger.h:322
#define EONC_LOG_INFO(...)
Definition EonLogger.h:316
#define EONC_LOG_CRITICAL(...)
Definition EonLogger.h:334
The optimizer class is used to serve as an abstract class for all optimizers, as well as to call an o...
void pollCancel(const char *site) const
Definition Matter.h:349
const AtomMatrix & getPositions() const
Definition Matter.cpp:378
VectorXd getForcesFreeV() const
Definition Matter.cpp:512
void setPositions(const AtomMatrix &pos)
Definition Matter.cpp:420
AtomMatrix getFree() const
Definition Matter.cpp:799
bool getPeriodic() const noexcept
Definition Matter.h:338
void setPositionsFreeV(const VectorXd &pos)
Definition Matter.cpp:451
long int numberOfAtoms() const
Definition Matter.cpp:343
AtomMatrix pbc(const AtomMatrix &diff) const
Definition Matter.cpp:943
VectorXd getPositionsFreeV() const
Definition Matter.cpp:415
void setAtomIndex(long int atom, std::int64_t index)
Definition Matter.cpp:963
VectorXd pbcV(const VectorXd &diff) const
Definition Matter.cpp:950
Eigen::Matrix< double, Eigen::Dynamic, 1 > getMasses() const
Definition Matter.cpp:846
double distance(long index1, long index2) const
Definition Matter.cpp:518
double getPotentialEnergy() const
Definition Matter.cpp:624
long mapFileRow(long file_row) const
Map a CON file-order row onto the Matter row after matter_order.
Definition Matter.h:318
long int numberOfFreeAtoms() const
Definition Matter.cpp:653
AtomMatrix getPositionsCopy() const
Definition Matter.cpp:380
std::int64_t getAtomIndex(long int atom) const
.con column-5 index (pre-grouping); public for I/O / bindings.
Definition Matter.cpp:959
const AtomMatrix & getForces() const
Definition Matter.cpp:482
void setFileToMatter(std::vector< long > map)
Definition Matter.h:325
io::IoStatus matter2con(std::string filename, bool append=false, const io::ConFrameMetadata *metadata=nullptr)
Definition Matter.h:293
int getFixed(long int atom) const
1 if every Cartesian axis of the atom is fixed, else 0.
Definition Matter.cpp:575
io::IoStatus con2matter(std::string filename)
Definition Matter.h:281
double maxForce(void) const
Definition Matter.cpp:780
const saddle_search_options_t & saddle_search_options() const
const debug_options_t & debug_options() const
const structure_comparison_options_t & structure_comparison_options() const
const optimizer_options_t & optimizer_options() const
const char DISP_RANDOM[]
Definition EpiCenters.h:24
long lastAtom(const Matter *matter)
const char DISP_LISTED_ATOMS[]
Definition EpiCenters.h:25
const char DISP_NOT_FCC_OR_HCP[]
Definition EpiCenters.h:21
const char DISP_MIN_COORDINATED[]
Definition EpiCenters.h:22
long cnaEpiCenter(const Matter *matter, double neighborCutoff)
const char DISP_LOAD[]
Definition EpiCenters.h:20
const char DISP_LAST_ATOM[]
Definition EpiCenters.h:23
long randomFreeAtomEpiCenter(const Matter *matter)
long listedAtomEpiCenter(const Matter *matter, const std::vector< long > &atomList)
long minCoordinatedEpiCenter(const Matter *matter, double neighborCutoff)
double norm(const Eigen::MatrixBase< A > &x)
sqrt of the correctly rounded squared norm; IEEE sqrt is itself correctly rounded,...
double maxAtomMotion(const AtomMatrix v1)
std::unique_ptr< Optimizer > mkOptim(std::shared_ptr< ObjectiveFunction > a_objf, OptType a_otype, const Parameters &a_params)
Definition Optimizer.cpp:55
VectorXd loadMasses(std::string filename, int nAtoms)
bool applyClientDisplacement(Matter &target, const Matter &initial, const Parameters &params, AtomMatrix *modeOut)
bool relaxMatter(Matter &matter, const Parameters &params, bool quiet=false, bool writeMovie=false, bool checkpoint=false, std::string prefixMovie=std::string(), std::string prefixCheckpoint=std::string(), std::vector< readcon::ConFrame > *outFrames=nullptr)
std::string getRelevantFile(std::string filename)
bool loadOrSynthesizeDisplacement(Matter &target, const Matter &initial, const std::string &displacementPath, const std::string &modePath, double scale)
AtomMatrix loadMode(FILE *modeFile, int nAtoms)
void saveMode(FILE *modeFile, std::shared_ptr< Matter > matter, AtomMatrix mode)
Write a mode; constrained axes are emitted as 0.
std::optional< std::string_view > convergenceMetricLabel(std::string_view metric)
Display label for a force-convergence metric, or nullopt when the name is none of the four the optimi...
std::vector< int > split_string_int(std::string s, std::string delim)
bool stageReturnLog(std::string_view logHome, std::string_view name)
Copy name from logHome into the current directory when that file is not already this directory's copy...
void requireKnownConvergenceMetric(std::string_view metric, std::string_view context)
Throws std::invalid_argument naming context when metric is unrecognized.
std::optional< std::string > enterJobDirectory(std::string_view jobPath)
Enter jobPath as the working directory.
void getTime(double *real, double *user, double *sys)
AtomMatrix makeOrthogonal(const AtomMatrix v1, const AtomMatrix v2)
bool existsFile(std::string filename)
readcon::ConFrame matterToConFrame(Matter &m, const ConFrameMetadata *metadata)
Build a single stamped ConFrame from Matter (same builder as matter2con).
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
double gaussRandom(double avg, double std)
RAII resource manager for the ARTn C library with global synchronization.
std::optional< uint64_t > frame_index
Definition ConFileIO.h:72
std::vector< ConMetadataValue > scalars
Definition ConFileIO.h:79
std::optional< double > energy
Definition ConFileIO.h:73
RAII helper for class-scoped logging.
Definition EonLogger.h:238