Loading...
Searching...
No Matches
HessianJob.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/HessianJob.h"
13#include "eon/BaseStructures.h"
14#include "eon/EonLogger.h"
15#include "eon/HelperFunctions.h"
16#include "eon/Hessian.h"
17#include "eon/JobResult.h"
18#include "eon/Matter.h"
19#include "eon/MobileAtoms.h"
20#include "eon/PotRegistry.h"
21#include "eon/Potential.h"
22
23#include <filesystem>
24#include <format>
25#include <fstream>
26#include <stdexcept>
27#include <string>
28
29namespace eonc {
30
31std::vector<std::string> HessianJob::run(void) {
32 std::string matter_in = eonc::helpers::getRelevantFile("pos.con");
33
34 std::vector<std::string> returnFiles;
35
36 auto matter = std::make_unique<Matter>(pot, params);
37
38 if (!eonc::io::io_ok(matter->con2matter(matter_in))) {
39 EONC_LOG_CRITICAL("Failed to load {}", matter_in);
40 throw std::runtime_error("failed to load " + matter_in);
41 }
42
43 Hessian hessian(params, matter.get());
44
45 // [Hessian] phva_atoms = PHVA mobile/active set (displaced in FD). free/fixed
46 // is the optimizer mask; resolveMobileAtoms intersects the list with free.
47 const VectorXi mobile = eonc::resolveMobileAtoms(
48 matter.get(), params.hessian_options().phva_atoms);
49 const bool no_mobile = mobile.size() == 0;
50 bool freqs_ok = false;
51 bool modes_ok = false;
52 if (!no_mobile) {
53 const VectorXd freqs = hessian.getFreqs(matter.get(), mobile);
54 freqs_ok = freqs.size() > 0;
55 if (freqs_ok && params.hessian_options().write_modes) {
56 modes_ok = writeNormalModes(*matter, mobile, freqs, hessian.getModes(),
57 "modes.con");
58 if (!modes_ok) {
59 EONC_LOG_ERROR("[Hessian] failed to write modes.con");
60 }
61 }
62 }
63
64 std::string results_file("results.dat");
65 returnFiles.push_back(results_file);
66
67 const auto status =
70 status, params.potential_options().potential,
71 PotRegistry::get().total_force_calls(), false, 0.0);
72 env.job_type = "hessian";
73 env.extras.emplace_back("force_calls", static_cast<double>(env.force_calls));
74 env.writeResultsDat(results_file);
75 if (std::filesystem::exists("hessian.dat")) {
76 returnFiles.push_back("hessian.dat");
77 }
78 if (modes_ok) {
79 returnFiles.push_back("modes.con");
80 }
81
82 return returnFiles;
83}
84
85} // namespace eonc
#define EONC_LOG_ERROR(...)
Definition EonLogger.h:261
#define EONC_LOG_CRITICAL(...)
Definition EonLogger.h:267
std::vector< std::string > run(void) override
Virtual run; used solely for dynamic dispatch.
const MatrixXd & getModes() const noexcept
Eigenvectors of the mass-weighted Hessian, one column per eigenvalue of getFreqs(),...
Definition Hessian.h:58
VectorXd getFreqs(Matter *matterIn, const VectorXi &atomsIn)
Definition Hessian.cpp:102
std::shared_ptr< Potential > pot
Definition Job.h:63
Parameters params
Definition Job.h:58
static PotRegistry & get() noexcept
Process-lifetime singleton.
std::string getRelevantFile(std::string filename)
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
RAII resource manager for the ARTn C library with global synchronization.
VectorXi resolveMobileAtoms(const Matter *matter, const std::string &atomList)
PHVA-class mobile set for FD Hessian and matrix-free Krylov (Lanczos / Davidson).
bool writeNormalModes(Matter &matter, const VectorXi &atoms, const VectorXd &eigenvalues, const MatrixXd &modes, const std::string &path)
Writes one frame of matter per mode to path, the mode as the displacements section and mode_eigenvalu...
Definition Hessian.cpp:775
static JobResultEnvelope fromMinimization(RunStatus status, PotType pot, std::uint64_t fcalls, bool hasE, double energy)
Definition JobResult.h:101