Loading...
Searching...
No Matches
HelperFunctions.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#include "Eigen.h"
14#include "GeometryAnalysis.h"
15#include "Matter.h"
16#include "Parameters.h"
17#include "RandomNumbers.h"
18#include <optional>
19#include <string>
20#include <string_view>
21#include <vector>
22
23namespace eonc {
24
25/* Collection of supporting functions that handle arrays of doubles as vectors
26 * and different random number generators */
27namespace helpers {
28
29inline constexpr double pi = 3.14159265358979323846;
30
32 const AtomMatrix v1,
33 const AtomMatrix v2); // return orthogonal component of v1 from v2
34bool relaxMatter(Matter &matter, const Parameters &params, bool quiet = false,
35 bool writeMovie = false, bool checkpoint = false,
36 std::string prefixMovie = std::string(),
37 std::string prefixCheckpoint = std::string(),
38 std::vector<readcon::ConFrame> *outFrames = nullptr);
39void getTime(double *real, double *user, double *sys);
40bool existsFile(std::string filename); // does filename exist
45std::optional<std::string> enterJobDirectory(std::string_view jobPath);
49bool stageReturnLog(std::string_view logHome, std::string_view name);
50std::string
51getRelevantFile(std::string filename); // return filename containing _checkpoint
52 // or _passed if such a file exists
53VectorXd loadMasses(std::string filename, int nAtoms);
54AtomMatrix loadMode(FILE *modeFile, int nAtoms);
55AtomMatrix loadMode(std::string filename, int nAtoms);
56// Load displacement.con, or synthesize initial + scale * unit(direction.dat)
57// (issue #79). scale is saddle_search.displace_magnitude (default 0.1).
58// Fixed-atom rows are always restored from initial. Returns false if neither
59// displacement nor mode file is usable, or mode has zero norm when
60// synthesizing.
61bool loadOrSynthesizeDisplacement(Matter &target, const Matter &initial,
62 const std::string &displacementPath,
63 const std::string &modePath, double scale);
64// Client-side epicenter kick for listed_atoms / random / last_atom /
65// least_coordinated / not_fcc_hcp_coordinated. Copies initial into
66// target, displaces free atoms within displace_radius of the picked
67// epicenter by a Gaussian of stddev displace_magnitude, and writes the
68// unit mode when modeOut is non-null. Returns false for displace_type
69// load (caller uses loadOrSynthesizeDisplacement) or an unknown type.
70bool applyClientDisplacement(Matter &target, const Matter &initial,
71 const Parameters &params, AtomMatrix *modeOut);
73void saveMode(FILE *modeFile, std::shared_ptr<Matter> matter, AtomMatrix mode);
74void saveMode(const std::string &filename, std::shared_ptr<Matter> matter,
75 AtomMatrix mode);
76std::vector<int> split_string_int(std::string s, std::string delim);
77
81std::optional<std::string_view> convergenceMetricLabel(std::string_view metric);
85void requireKnownConvergenceMetric(std::string_view metric,
86 std::string_view context);
87
88} // namespace helpers
89
90} // namespace eonc
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
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...
constexpr double pi
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)
RAII resource manager for the ARTn C library with global synchronization.