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/Hessian.h"
16#include "eon/Matter.h"
17#include "eon/MobileAtoms.h"
18#include "eon/PotRegistry.h"
19#include "eon/Potential.h"
20#include "magic_enum/magic_enum.hpp"
21
22#include <filesystem>
23#include <format>
24#include <fstream>
25#include <stdexcept>
26#include <string>
27
28std::vector<std::string> HessianJob::run(void) {
29 std::string matter_in("pos.con");
30
31 std::vector<std::string> returnFiles;
32
33 auto matter = std::make_unique<Matter>(pot, params);
34
35 if (!eonc::io::io_ok(matter->con2matter(matter_in))) {
36 EONC_LOG_CRITICAL("Failed to load {}", matter_in);
37 throw std::runtime_error("failed to load " + matter_in);
38 }
39
40 Hessian hessian(params, matter.get());
41
42 // [Hessian] phva_atoms = PHVA mobile/active set (displaced in FD). free/fixed
43 // is the optimizer mask; resolveMobileAtoms intersects the list with free.
44 const VectorXi mobile =
45 eonc::resolveMobileAtoms(matter.get(), params.hessian_options.phva_atoms);
46 const bool no_mobile = mobile.size() == 0;
47 if (!no_mobile) {
48 hessian.getFreqs(matter.get(), mobile);
49 }
50
51 std::string results_file("results.dat");
52 returnFiles.push_back(results_file);
53
54 std::ofstream out(results_file, std::ios::binary);
55 if (out) {
56 const auto status =
58 out << std::format("{} termination_reason\n", static_cast<int>(status));
59 out << std::format("{} termination_reason_text\n",
60 magic_enum::enum_name<RunStatus>(status));
61 out << "hessian job_type\n";
62 out << std::format("{} force_calls\n",
63 PotRegistry::get().total_force_calls());
64 out << std::format("{} total_force_calls\n",
65 PotRegistry::get().total_force_calls());
66 }
67 if (std::filesystem::exists("hessian.dat")) {
68 returnFiles.push_back("hessian.dat");
69 }
70
71 return returnFiles;
72}
#define EONC_LOG_CRITICAL(...)
Definition EonLogger.h:268
std::vector< std::string > run(void)
Virtual run; used solely for dynamic dispatch.
VectorXd getFreqs(Matter *matterIn, const VectorXi &atomsIn)
Definition Hessian.cpp:99
std::shared_ptr< Potential > pot
Definition Job.h:55
Parameters params
Definition Job.h:54
static PotRegistry & get() noexcept
Process-lifetime singleton.
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
VectorXi resolveMobileAtoms(const Matter *matter, const std::string &atomList)
PHVA-class mobile set for FD Hessian and matrix-free Krylov (Lanczos / Davidson).