eOn 3.2.0
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
StructureComparisonJob.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/StructureComparisonJob.h
"
13
#include "
eon/BaseStructures.h
"
14
#include "
eon/EonLogger.h
"
15
#include "
eon/HelperFunctions.h
"
16
#include "
eon/Matter.h
"
17
#include "magic_enum/magic_enum.hpp"
18
19
#include <cmath>
20
#include <format>
21
#include <fstream>
22
#include <limits>
23
#include <stdexcept>
24
25
namespace
eonc
{
26
27
std::vector<std::string>
StructureComparisonJob::run
() {
28
std::vector<std::string> returnFiles;
29
const
std::string file1 =
eonc::helpers::getRelevantFile
(
"matter1.con"
);
30
const
std::string file2 =
eonc::helpers::getRelevantFile
(
"matter2.con"
);
31
32
auto
matter1 = std::make_unique<Matter>(
pot
,
params
);
33
if
(!
eonc::io::io_ok
(matter1->con2matter(file1))) {
34
EONC_LOG_CRITICAL
(
"Failed to load {}"
, file1);
35
throw
std::runtime_error(
"failed to load "
+ file1);
36
}
37
auto
matter2 = std::make_unique<Matter>(
pot
,
params
);
38
if
(!
eonc::io::io_ok
(matter2->con2matter(file2))) {
39
EONC_LOG_CRITICAL
(
"Failed to load {}"
, file2);
40
throw
std::runtime_error(
"failed to load "
+ file2);
41
}
42
43
// Matter::compare can translate the left operand. Probe on a copy.
44
Matter
probe(*matter1);
45
const
bool
match = probe.
compare
(
46
*matter2,
params
.structure_comparison_options().indistinguishable_atoms);
47
48
double
distance = std::numeric_limits<double>::quiet_NaN();
49
double
perAtom = std::numeric_limits<double>::quiet_NaN();
50
if
(matter1->numberOfAtoms() == matter2->numberOfAtoms()) {
51
distance = matter1->distanceTo(*matter2);
52
perAtom = matter1->perAtomNorm(*matter2);
53
}
54
55
const
double
e1 = matter1->getPotentialEnergy();
56
const
double
e2 = matter2->getPotentialEnergy();
57
58
const
std::string resultsFilename(
"results.dat"
);
59
std::ofstream out(resultsFilename, std::ios::binary);
60
if
(!out) {
61
EONC_LOG_CRITICAL
(
"Failed to open {}"
, resultsFilename);
62
throw
std::runtime_error(
"failed to open "
+ resultsFilename);
63
}
64
out << std::format(
"{} termination_reason\n"
,
65
static_cast<
int
>
(
RunStatus::GOOD
));
66
out << std::format(
"{} termination_reason_text\n"
,
67
magic_enum::enum_name<RunStatus>(
RunStatus::GOOD
));
68
out <<
"structure_comparison job_type\n"
;
69
out << std::format(
"{} match\n"
, match ? 1 : 0);
70
out << std::format(
"{:.12f} distance\n"
, distance);
71
out << std::format(
"{:.12f} per_atom_norm\n"
, perAtom);
72
out << std::format(
"{:.12f} energy_1\n"
, e1);
73
out << std::format(
"{:.12f} energy_2\n"
, e2);
74
out << std::format(
"{:.12f} energy_abs_diff\n"
, std::abs(e1 - e2));
75
out.close();
76
if
(!out) {
77
throw
std::runtime_error(
"failed to write "
+ resultsFilename);
78
}
79
returnFiles.push_back(resultsFilename);
80
return
returnFiles;
81
}
82
83
}
// namespace eonc
BaseStructures.h
EonLogger.h
EONC_LOG_CRITICAL
#define EONC_LOG_CRITICAL(...)
Definition
EonLogger.h:267
HelperFunctions.h
Matter.h
StructureComparisonJob.h
eonc::Job::pot
std::shared_ptr< Potential > pot
Definition
Job.h:63
eonc::Job::params
Parameters params
Definition
Job.h:58
eonc::Matter
Definition
Matter.h:90
eonc::Matter::compare
bool compare(const Matter &matter, bool indistinguishable=false)
Definition
Matter.cpp:184
eonc::StructureComparisonJob::run
std::vector< std::string > run(void) override
Virtual run; used solely for dynamic dispatch.
Definition
StructureComparisonJob.cpp:27
eonc::helpers::getRelevantFile
std::string getRelevantFile(std::string filename)
Definition
HelperFunctions.cpp:122
eonc::io::io_ok
constexpr bool io_ok(IoStatus s) noexcept
Definition
ConFileIO.h:38
eonc
RAII resource manager for the ARTn C library with global synchronization.
Definition
ARTnSaddleSearch.cpp:23
eonc::RunStatus::GOOD
@ GOOD
Definition
BaseStructures.h:117
client
StructureComparisonJob.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf