Loading...
Searching...
No Matches
eonc::ReplicaDynamicsJob Class Referenceabstract

Base class for replica dynamics jobs (TAD, SafeHyper). More...

#include <ReplicaDynamicsJob.h>

Inheritance diagram for eonc::ReplicaDynamicsJob:

Public Member Functions

 ~ReplicaDynamicsJob () override=default
std::vector< std::string > run () override
 Virtual run; used solely for dynamic dispatch.
std::shared_ptr< MatterrunFromMatter (std::shared_ptr< Matter > initial)
 Matter-first entry: seed geometry, skip con2matter load.
 Job (std::unique_ptr< Parameters > parameters)
 Job (std::shared_ptr< Potential > potPassed, const Parameters &parameters)
Public Member Functions inherited from eonc::Job
 Job (std::unique_ptr< Parameters > parameters)
 Job (std::shared_ptr< Potential > potPassed, const Parameters &parameters)
virtual ~Job ()=default
JobType getType ()

Protected Member Functions

bool checkState (Matter *current, Matter *reactant)
 Minimize a copy of current and compare to reactant.
long refine (const std::vector< std::shared_ptr< Matter > > &buff, Matter *reactant)
 Binary search for the transition frame in a snapshot buffer.
void dephase ()
 Dephase the trajectory to ensure thermal independence.
void saveData (int status)
 Write results.dat and structure con files.
virtual void initExtra ()
 Create any extra matter objects needed by the subclass.
virtual int dynamics ()=0
 The accelerated dynamics loop. Returns status (1 = transition, 0 = none).
virtual void reportResults ()
 Post-dynamics logging (override for job-specific messages).

Protected Attributes

std::shared_ptr< Mattercurrent
std::shared_ptr< Matterreactant
std::shared_ptr< Mattersaddle
std::shared_ptr< Matterproduct
std::shared_ptr< MatterfinalState
std::shared_ptr< MatterfinalStateTmp
bool metaStateFlag {false}
bool newStateFlag {false}
size_t minimizeFCalls {0}
size_t mdFCalls {0}
size_t dephaseFCalls {0}
size_t refineFCalls {0}
long transitionStep {0}
double time {0.0}
double minCorrectedTime {1.0e200}
double transitionTime {0.0}
std::vector< std::string > returnFiles
eonc::log::Scoped log
Protected Attributes inherited from eonc::Job
JobType jtype
Parameters params
std::shared_ptr< Potentialpot

Detailed Description

Base class for replica dynamics jobs (TAD, SafeHyper).

Provides shared infrastructure: state checking via minimize-and-compare, binary search refinement of transition times, dephasing, and results I/O. Subclasses implement initExtra() for job-specific matter objects and dynamics() for the accelerated MD loop.

Definition at line 29 of file ReplicaDynamicsJob.h.

Constructor & Destructor Documentation

◆ ~ReplicaDynamicsJob()

eonc::ReplicaDynamicsJob::~ReplicaDynamicsJob ( )
overridedefault

Member Function Documentation

◆ checkState()

bool ReplicaDynamicsJob::checkState ( Matter * current,
Matter * reactant )
protected

Minimize a copy of current and compare to reactant.

Returns true if a transition (new state) was detected.

Definition at line 67 of file ReplicaDynamicsJob.cpp.

67 {
68 Matter tmp(pot, params);
69 tmp = *curr;
70 tmp.relax(true);
71 return !tmp.compare(*react);
72}
std::shared_ptr< Potential > pot
Definition Job.h:55
Parameters params
Definition Job.h:54

◆ dephase()

void ReplicaDynamicsJob::dephase ( )
protected

Dephase the trajectory to ensure thermal independence.

Definition at line 93 of file ReplicaDynamicsJob.cpp.

93 {
94 long DephaseSteps =
95 static_cast<long>(params.parallel_replica_options.dephase_time /
96 params.dynamics_options.time_step);
97 Dynamics dephaseDynamics(current.get(), params);
98 QUILL_LOG_DEBUG(log, "Dephasing for {:.2f} fs",
99 params.parallel_replica_options.dephase_time *
100 params.constants.timeUnit);
101
102 long step = 0, loop = 0;
103
104 while (step < DephaseSteps) {
105 long dephaseBufferLength = DephaseSteps - step;
106 loop++;
107 std::vector<std::shared_ptr<Matter>> dephaseBuffer(dephaseBufferLength);
108
109 for (long i = 0; i < dephaseBufferLength; i++) {
110 dephaseBuffer[i] = std::make_shared<Matter>(pot, params);
111 dephaseDynamics.oneStep();
112 *dephaseBuffer[i] = *current;
113 }
114
115 bool transitionFlag = checkState(current.get(), reactant.get());
116
117 if (transitionFlag) {
118 long dephaseRefineStep = refine(dephaseBuffer, reactant.get());
119 QUILL_LOG_DEBUG(log, "loop = {}; dephase refine step = {}", loop,
120 dephaseRefineStep);
121 long ts = dephaseRefineStep - 1;
122 ts = (ts > 0) ? ts : 0;
123 QUILL_LOG_DEBUG(
124 log,
125 "Dephasing warning: in a new state, inverse the momentum and restart "
126 "from step {}",
127 step + ts);
128 *current = *dephaseBuffer[ts];
129 AtomMatrix velocity = current->getVelocities();
130 velocity = velocity * (-1);
131 current->setVelocities(velocity);
132 step = step + ts;
133 } else {
134 step = step + dephaseBufferLength;
135 QUILL_LOG_TRACE_L1(log, "Successful dephasing for {} steps", step);
136 }
137
138 if ((params.parallel_replica_options.dephase_loop_stop) &&
139 (loop > params.parallel_replica_options.dephase_loop_max)) {
140 QUILL_LOG_DEBUG(
141 log,
142 "Reach dephase loop maximum, stop dephasing! Dephased for {} steps",
143 step);
144 break;
145 }
146 QUILL_LOG_DEBUG(log, "Successfully Dephased for {:.2f} fs",
147 step * params.dynamics_options.time_step *
148 params.constants.timeUnit);
149 }
150}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
long refine(const std::vector< std::shared_ptr< Matter > > &buff, Matter *reactant)
Binary search for the transition frame in a snapshot buffer.
std::shared_ptr< Matter > reactant
std::shared_ptr< Matter > current
bool checkState(Matter *current, Matter *reactant)
Minimize a copy of current and compare to reactant.

◆ dynamics()

virtual int eonc::ReplicaDynamicsJob::dynamics ( )
protectedpure virtual

The accelerated dynamics loop. Returns status (1 = transition, 0 = none).

Implemented in eonc::SafeHyperJob, eonc::TADJob, SafeHyperJob, and TADJob.

◆ initExtra()

virtual void eonc::ReplicaDynamicsJob::initExtra ( )
inlineprotectedvirtual

Create any extra matter objects needed by the subclass.

Reimplemented in eonc::TADJob, and TADJob.

Definition at line 85 of file ReplicaDynamicsJob.h.

85{}

◆ Job() [1/2]

eonc::Job::Job ( std::shared_ptr< Potential > potPassed,
const Parameters & parameters )
inline

Definition at line 63 of file Job.h.

64 : jtype{parameters.main_options.job},
65 params{parameters},
66 pot{potPassed} {}
JobType jtype
Definition Job.h:53
struct eonc::Parameters::main_options_t main_options

◆ Job() [2/2]

eonc::Job::Job ( std::unique_ptr< Parameters > parameters)
inline

Definition at line 58 of file Job.h.

59 : jtype{parameters->main_options.job},
60 params{*std::move(parameters)},
61 pot{helpers::makePotential(params.potential_options.potential,
62 params)} {}
std::shared_ptr< Potential > makePotential(const Parameters &params)

◆ refine()

long ReplicaDynamicsJob::refine ( const std::vector< std::shared_ptr< Matter > > & buff,
Matter * reactant )
protected

Binary search for the transition frame in a snapshot buffer.

Definition at line 74 of file ReplicaDynamicsJob.cpp.

75 {
76 QUILL_LOG_TRACE_L1(log, "Refining transition time.");
77
78 long lo = 0;
79 long hi = static_cast<long>(buff.size()) - 1;
80
81 while ((hi - lo) > 1) {
82 long mid = lo + (hi - lo) / 2;
83 if (!checkState(buff[mid].get(), react)) {
84 lo = mid;
85 } else {
86 hi = mid;
87 }
88 }
89
90 return (lo + hi) / 2 + 1;
91}
quill::Logger * get() noexcept
Get or create the default "combi" logger.
Definition EonLogger.h:44

◆ reportResults()

virtual void eonc::ReplicaDynamicsJob::reportResults ( )
inlineprotectedvirtual

Post-dynamics logging (override for job-specific messages).

Reimplemented in eonc::SafeHyperJob, eonc::TADJob, SafeHyperJob, and TADJob.

Definition at line 91 of file ReplicaDynamicsJob.h.

91{}

◆ run()

std::vector< std::string > ReplicaDynamicsJob::run ( )
overridevirtual

Virtual run; used solely for dynamic dispatch.

Implements eonc::Job.

Definition at line 22 of file ReplicaDynamicsJob.cpp.

22 {
23 auto seed = std::make_shared<Matter>(pot, params);
24 std::string reactantFilename =
25 eonc::helpers::getRelevantFile(params.main_options.conFilename);
26 if (!eonc::io::io_ok(seed->con2matter(reactantFilename))) {
27 QUILL_LOG_CRITICAL(log, "Failed to load {}", reactantFilename);
28 throw std::runtime_error("failed to load " + reactantFilename);
29 }
30 (void)runFromMatter(std::move(seed));
31 return returnFiles;
32}
std::vector< std::string > returnFiles
std::shared_ptr< Matter > runFromMatter(std::shared_ptr< Matter > initial)
Matter-first entry: seed geometry, skip con2matter load.
std::string getRelevantFile(std::string filename)
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38

◆ runFromMatter()

std::shared_ptr< Matter > ReplicaDynamicsJob::runFromMatter ( std::shared_ptr< Matter > initial)

Matter-first entry: seed geometry, skip con2matter load.

Returns final trajectory Matter (current).

Definition at line 35 of file ReplicaDynamicsJob.cpp.

35 {
36 if (!initial) {
37 throw std::runtime_error("runFromMatter: initial Matter is null");
38 }
39 current = initial;
40 current->setPotential(pot);
41 reactant = std::make_shared<Matter>(pot, params);
42 saddle = std::make_shared<Matter>(pot, params);
43 product = std::make_shared<Matter>(pot, params);
44 finalState = std::make_shared<Matter>(pot, params);
45 finalStateTmp = std::make_shared<Matter>(pot, params);
46
48 time = 0.0;
49
50 QUILL_LOG_DEBUG(log, "Minimizing initial reactant");
51 {
52 eonc::ForceCallTimer timer(minimizeFCalls);
53 *reactant = *current;
54 reactant->relax();
55 }
56
57 initExtra();
58
59 int status = dynamics();
60
61 saveData(status);
63
64 return current;
65}
std::shared_ptr< Matter > saddle
std::shared_ptr< Matter > product
virtual int dynamics()=0
The accelerated dynamics loop. Returns status (1 = transition, 0 = none).
std::shared_ptr< Matter > finalState
virtual void initExtra()
Create any extra matter objects needed by the subclass.
virtual void reportResults()
Post-dynamics logging (override for job-specific messages).
void saveData(int status)
Write results.dat and structure con files.
std::shared_ptr< Matter > finalStateTmp

◆ saveData()

void ReplicaDynamicsJob::saveData ( int status)
protected

Write results.dat and structure con files.

Definition at line 152 of file ReplicaDynamicsJob.cpp.

152 {
153 std::string resultsFilename("results.dat");
154 returnFiles.push_back(resultsFilename);
155 size_t totalFCalls = minimizeFCalls + mdFCalls + dephaseFCalls + refineFCalls;
156
157 {
158 std::ofstream out(resultsFilename, std::ios::binary);
159 if (out) {
160 out << std::format(
161 "{} potential_type\n",
162 magic_enum::enum_name<PotType>(params.potential_options.potential));
163 out << std::format("{} random_seed\n", params.main_options.randomSeed);
164 out << std::format("{:f} potential_energy_reactant\n",
165 reactant->getPotentialEnergy());
166 out << std::format("{} total_force_calls\n", totalFCalls);
167 out << std::format("{} force_calls_dephase\n", dephaseFCalls);
168 out << std::format("{} force_calls_dynamics\n", mdFCalls);
169 out << std::format("{} force_calls_minimize\n", minimizeFCalls);
170 out << std::format("{} force_calls_refine\n", refineFCalls);
171 out << std::format("{} transition_found\n", (newStateFlag) ? 1 : 0);
172
173 if (newStateFlag) {
174 out << std::format("{:e} transition_time_s\n",
175 minCorrectedTime * 1.0e-15 *
176 params.constants.timeUnit);
177 out << std::format("{:f} potential_energy_product\n",
178 product->getPotentialEnergy());
179 out << std::format("{:f} moved_distance\n",
180 product->distanceTo(*reactant));
181 }
182
183 out << std::format("{:e} simulation_time_s\n",
184 time * 1.0e-15 * params.constants.timeUnit);
185 out << std::format("{:f} speedup\n",
186 time / params.dynamics_options.steps /
187 params.dynamics_options.time_step);
188 }
189 }
190
191 std::string reactantFilename("reactant.con");
192 returnFiles.push_back(reactantFilename);
193 if (!eonc::io::io_ok(reactant->matter2con(reactantFilename))) {
194 QUILL_LOG_ERROR(log, "Failed to write {}", reactantFilename);
195 }
196
197 if (newStateFlag) {
198 std::string productFilename("product.con");
199 returnFiles.push_back(productFilename);
200 if (!eonc::io::io_ok(product->matter2con(productFilename))) {
201 QUILL_LOG_ERROR(log, "Failed to write {}", productFilename);
202 }
203
204 if (params.parallel_replica_options.refine_transition) {
205 std::string saddleFilename("saddle.con");
206 returnFiles.push_back(saddleFilename);
207 if (!eonc::io::io_ok(saddle->matter2con(saddleFilename))) {
208 QUILL_LOG_ERROR(log, "Failed to write {}", saddleFilename);
209 }
210 }
211 }
212}

Member Data Documentation

◆ current

std::shared_ptr<Matter> eonc::ReplicaDynamicsJob::current
protected

Definition at line 40 of file ReplicaDynamicsJob.h.

◆ dephaseFCalls

size_t eonc::ReplicaDynamicsJob::dephaseFCalls {0}
protected

Definition at line 54 of file ReplicaDynamicsJob.h.

54{0};

◆ finalState

std::shared_ptr<Matter> eonc::ReplicaDynamicsJob::finalState
protected

Definition at line 44 of file ReplicaDynamicsJob.h.

◆ finalStateTmp

std::shared_ptr<Matter> eonc::ReplicaDynamicsJob::finalStateTmp
protected

Definition at line 45 of file ReplicaDynamicsJob.h.

◆ log

eonc::log::Scoped eonc::ReplicaDynamicsJob::log
protected

Definition at line 64 of file ReplicaDynamicsJob.h.

◆ mdFCalls

size_t eonc::ReplicaDynamicsJob::mdFCalls {0}
protected

Definition at line 53 of file ReplicaDynamicsJob.h.

53{0};

◆ metaStateFlag

bool eonc::ReplicaDynamicsJob::metaStateFlag {false}
protected

Definition at line 48 of file ReplicaDynamicsJob.h.

48{false};

◆ minCorrectedTime

double eonc::ReplicaDynamicsJob::minCorrectedTime {1.0e200}
protected

Definition at line 60 of file ReplicaDynamicsJob.h.

60{1.0e200};

◆ minimizeFCalls

size_t eonc::ReplicaDynamicsJob::minimizeFCalls {0}
protected

Definition at line 52 of file ReplicaDynamicsJob.h.

52{0};

◆ newStateFlag

bool eonc::ReplicaDynamicsJob::newStateFlag {false}
protected

Definition at line 49 of file ReplicaDynamicsJob.h.

49{false};

◆ product

std::shared_ptr<Matter> eonc::ReplicaDynamicsJob::product
protected

Definition at line 43 of file ReplicaDynamicsJob.h.

◆ reactant

std::shared_ptr<Matter> eonc::ReplicaDynamicsJob::reactant
protected

Definition at line 41 of file ReplicaDynamicsJob.h.

◆ refineFCalls

size_t eonc::ReplicaDynamicsJob::refineFCalls {0}
protected

Definition at line 55 of file ReplicaDynamicsJob.h.

55{0};

◆ returnFiles

std::vector<std::string> eonc::ReplicaDynamicsJob::returnFiles
protected

Definition at line 63 of file ReplicaDynamicsJob.h.

◆ saddle

std::shared_ptr<Matter> eonc::ReplicaDynamicsJob::saddle
protected

Definition at line 42 of file ReplicaDynamicsJob.h.

◆ time

double eonc::ReplicaDynamicsJob::time {0.0}
protected

Definition at line 59 of file ReplicaDynamicsJob.h.

59{0.0};

◆ transitionStep

long eonc::ReplicaDynamicsJob::transitionStep {0}
protected

Definition at line 58 of file ReplicaDynamicsJob.h.

58{0};

◆ transitionTime

double eonc::ReplicaDynamicsJob::transitionTime {0.0}
protected

Definition at line 61 of file ReplicaDynamicsJob.h.

61{0.0};

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