Loading...
Searching...
No Matches
eonc::StructureComparisonJob Class Reference

#include <StructureComparisonJob.h>

Inheritance diagram for eonc::StructureComparisonJob:

Public Member Functions

 StructureComparisonJob (std::unique_ptr< Parameters > parameters, Runtime &rt)
 ~StructureComparisonJob (void)=default
std::vector< std::string > run (void) override
 Virtual run; used solely for dynamic dispatch.
Public Member Functions inherited from eonc::Job
void adoptRuntime (std::unique_ptr< Runtime > rt)
 Take ownership of a Runtime previously passed as Runtime&.
 Job (std::unique_ptr< Parameters > parameters, Runtime &rt)
 Borrow: caller keeps Runtime alive (CLI stack / Python Session).
 Job (std::unique_ptr< Parameters > parameters, std::unique_ptr< Runtime > rt)
 Own a Runtime (one-shot makeJob / rvalue).
 Job (std::unique_ptr< Parameters > parameters)
 Own a default-constructed Runtime.
 Job (std::shared_ptr< Potential > potPassed, const Parameters &parameters)
virtual ~Job ()=default
JobType getType ()
PotRegistry & pots () noexcept
void releasePotential ()
 Drop the Potential so on_destroyed is recorded before Runtime dies.

Additional Inherited Members

Protected Attributes inherited from eonc::Job
JobType jtype
Parameters params
std::unique_ptr< Runtime > owned_runtime_
 Non-null when this Job owns the composition root (one-shot makeJob).
Runtime * runtime_
 Always valid: either owned_runtime_.get() or a caller-owned Runtime.
std::shared_ptr< Potential > pot

Detailed Description

Definition at line 19 of file StructureComparisonJob.h.

Constructor & Destructor Documentation

◆ StructureComparisonJob()

eonc::StructureComparisonJob::StructureComparisonJob ( std::unique_ptr< Parameters > parameters,
Runtime & rt )
inline

Definition at line 21 of file StructureComparisonJob.h.

22 : Job(std::move(parameters), rt) {}
Job(std::unique_ptr< Parameters > parameters, Runtime &rt)
Borrow: caller keeps Runtime alive (CLI stack / Python Session).
Definition Job.h:76

◆ ~StructureComparisonJob()

eonc::StructureComparisonJob::~StructureComparisonJob ( void )
default

Member Function Documentation

◆ run()

std::vector< std::string > eonc::StructureComparisonJob::run ( void )
overridevirtual

Virtual run; used solely for dynamic dispatch.

Implements eonc::Job.

Definition at line 27 of file StructureComparisonJob.cpp.

27 {
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}
#define EONC_LOG_CRITICAL(...)
Definition EonLogger.h:267
std::shared_ptr< Potential > pot
Definition Job.h:63
Parameters params
Definition Job.h:58
std::string getRelevantFile(std::string filename)
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38

The documentation for this class was generated from the following files: