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

#include <SafeHyperJob.h>

Inheritance diagram for eonc::SafeHyperJob:

Public Member Functions

 ~SafeHyperJob ()=default
Public Member Functions inherited from eonc::ReplicaDynamicsJob
 ~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 ()

Private Member Functions

int dynamics () override
 The accelerated dynamics loop. Returns status (1 = transition, 0 = none).
void reportResults () override
 Post-dynamics logging (override for job-specific messages).

Private Attributes

double transitionPot {0.0}
std::vector< double > timeBuffer
std::vector< double > biasBuffer

Additional Inherited Members

Protected Member Functions inherited from eonc::ReplicaDynamicsJob
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.
Protected Attributes inherited from eonc::ReplicaDynamicsJob
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

Definition at line 19 of file SafeHyperJob.h.

Constructor & Destructor Documentation

◆ ~SafeHyperJob()

eonc::SafeHyperJob::~SafeHyperJob ( )
default

Member Function Documentation

◆ dynamics()

int SafeHyperJob::dynamics ( )
overrideprivatevirtual

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

Implements eonc::ReplicaDynamicsJob.

Definition at line 31 of file SafeHyperJob.cpp.

31 {
32 bool transitionFlag = false, recordFlag = true, stopFlag = false,
33 firstTransitFlag = false;
34 long nFreeCoord = reactant->numberOfFreeAtoms() * 3;
35 long mdBufferLength;
36 long step = 0, refineStep, newStateStep = 0;
37 long nCheck = 0, nRecord = 0, nBoost = 0, nState = 0;
38 long StateCheckInterval, RecordInterval;
39 double kinE, kinT, avgT, varT;
40 double kB = params.constants.kB;
41 double correctedTime = 0.0, sumCorrectedTime = 0.0, firstTransitionTime = 0.0;
42 double Temp = 0.0, sumT = 0.0, sumT2 = 0.0;
43 double sumboost = 0.0, boost = 1.0, boostPotential = 0.0;
44 double transitionTime_current = 0.0, transitionTime_pre = 0.0;
45 AtomMatrix velocity;
46
47 minCorrectedTime = 1.0e200;
48 StateCheckInterval =
49 static_cast<long>(params.parallel_replica_options.state_check_interval /
50 params.dynamics_options.time_step);
51 RecordInterval =
52 static_cast<long>(params.parallel_replica_options.record_interval /
53 params.dynamics_options.time_step);
54 Temp = params.main_options.temperature;
56
57 mdBufferLength = static_cast<long>(StateCheckInterval / RecordInterval);
58 std::vector<std::shared_ptr<Matter>> mdBuffer(mdBufferLength);
59 for (long i = 0; i < mdBufferLength; i++) {
60 mdBuffer[i] = std::make_shared<Matter>(pot, params);
61 }
62 timeBuffer.resize(mdBufferLength);
63 biasBuffer.resize(mdBufferLength);
64
65 Dynamics safeHyper(current.get(), params);
66 BondBoost bondBoost(current.get(), params);
67
68 if (params.hyperdynamics_options.bias_potential ==
70 bondBoost.initialize();
71 }
72
73 safeHyper.setThermalVelocity();
74
75 {
76 eonc::ForceCallTimer timer(dephaseFCalls);
77 dephase();
78 }
79
80 QUILL_LOG_DEBUG(
81 log,
82 "Starting MD run\nTemperature: {:.2f} Kelvin\n"
83 "Total Simulation Time: {:.2f} fs\nTime Step: {:.2f} fs\nTotal Steps: {}",
84 Temp,
85 params.dynamics_options.steps * params.dynamics_options.time_step *
86 params.constants.timeUnit,
87 params.dynamics_options.time_step * params.constants.timeUnit,
88 params.dynamics_options.steps);
89 QUILL_LOG_DEBUG(log, "MD buffer length: {}", mdBufferLength);
90
91 long tenthSteps = params.dynamics_options.steps / 10;
92 if (tenthSteps == 0) {
93 tenthSteps = params.dynamics_options.steps;
94 }
95
96 while (!stopFlag) {
97 if ((params.hyperdynamics_options.bias_potential ==
99 !newStateFlag) {
100 bondBoost.advance();
101 boostPotential = bondBoost.boost();
102 QUILL_LOG_TRACE_L1(log, "step= {} , boost = {:.5f}", step,
103 boostPotential);
104 boost = std::exp(boostPotential / kB / Temp);
105 time += params.dynamics_options.time_step * boost;
106 if (boost > 1.0) {
107 sumboost += boost;
108 nBoost++;
109 }
110 }
111
112 kinE = current->getKineticEnergy();
113 kinT = (2.0 * kinE / nFreeCoord / kB);
114 sumT += kinT;
115 sumT2 += kinT * kinT;
116 QUILL_LOG_TRACE_L1(log, "steps = {:10} temp = {:10.5f}", step, kinT);
117
118 safeHyper.oneStep();
119 mdFCalls++;
120
121 nCheck++;
122 step++;
123 QUILL_LOG_TRACE_L1(log, "step = {:4}, time = {:10.4f}", step, time);
124
125 if (params.parallel_replica_options.refine_transition && recordFlag &&
126 !newStateFlag) {
127 if (nCheck % RecordInterval == 0) {
128 *mdBuffer[nRecord] = *current;
129 timeBuffer[nRecord] = time;
130 biasBuffer[nRecord] = boostPotential;
131 nRecord++;
132 }
133 }
134
135 if ((nCheck == StateCheckInterval) && !newStateFlag) {
136 nCheck = 0;
137 nRecord = 0;
138 {
139 eonc::ForceCallTimer timer(minimizeFCalls);
140 transitionFlag = checkState(current.get(), reactant.get());
141 }
142 if (transitionFlag) {
143 nState++;
144 QUILL_LOG_DEBUG(log, "New State {}: ", nState);
147 newStateStep = step;
148 transitionStep = newStateStep;
149 firstTransitFlag = 1;
150 }
151 }
152
153 if (transitionFlag) {
154 QUILL_LOG_TRACE_L1(log, "Refining transition time.");
155 {
156 eonc::ForceCallTimer timer(refineFCalls);
157 refineStep = refine(mdBuffer, reactant.get());
158 }
159
161 newStateStep - StateCheckInterval + refineStep * RecordInterval;
162 transitionTime_current = timeBuffer[refineStep];
163 transitionTime = transitionTime_current - transitionTime_pre;
164 transitionTime_pre = transitionTime_current;
165 transitionPot = biasBuffer[refineStep];
166 correctedTime =
167 transitionTime * std::exp((-1) * transitionPot / kB / Temp);
168 sumCorrectedTime += correctedTime;
169 if (nState == 1) {
170 firstTransitionTime = transitionTime;
171 }
172
173 *current = *mdBuffer[refineStep - 1];
174 velocity = current->getVelocities();
175 velocity = velocity * (-1);
176 current->setVelocities(velocity);
177
178 if (correctedTime < minCorrectedTime) {
179 minCorrectedTime = correctedTime;
180 *saddle = *mdBuffer[refineStep];
182 }
183 QUILL_LOG_DEBUG(log,
184 "tranisitonTime= {:.3e} s, biasPot= {:.3f} eV, "
185 "correctedTime= {:.3e} s, "
186 "sumCorrectedTime= {:.3e} s, minCorTime= {:.3e} s",
187 transitionTime * 1e-15 * params.constants.timeUnit,
189 correctedTime * 1e-15 * params.constants.timeUnit,
190 sumCorrectedTime * 1e-15 * params.constants.timeUnit,
191 minCorrectedTime * 1.0e-15 * params.constants.timeUnit);
192
193 transitionFlag = false;
194 }
195
196 if (firstTransitFlag && sumCorrectedTime > firstTransitionTime) {
197 stopFlag = true;
198 newStateFlag = true;
199 }
200
201 if ((step % tenthSteps == 0) || (step == params.dynamics_options.steps)) {
202 double maxAtomDistance = current->perAtomNorm(*reactant);
203 QUILL_LOG_DEBUG(
204 log, "progress: {:.0f}%, max displacement: {:.3f}, step {} / {}",
205 static_cast<double>(100.0 * step / params.dynamics_options.steps),
206 maxAtomDistance, step, params.dynamics_options.steps);
207 }
208
209 // Honor dynamics step budget (parity with TADJob); without this the
210 // loop only exits on a confidence-gated transition and can run forever.
211 if (step >= params.dynamics_options.steps) {
212 stopFlag = true;
213 }
214 }
215
216 avgT = sumT / step;
217 varT = sumT2 / step - avgT * avgT;
218
219 if (nBoost > 0) {
220 QUILL_LOG_DEBUG(log,
221 "Temperature : Average = {:.6f} ; Stddev = {:.6f} ; "
222 "Factor = {:.6f}; Boost = {:.6f}",
223 avgT, std::sqrt(varT), varT / avgT / avgT * nFreeCoord / 2,
224 sumboost / nBoost);
225 } else {
226 QUILL_LOG_DEBUG(
227 log,
228 "Temperature : Average = {:.6f} ; Stddev = {:.6f} ; Factor = {:.6f}",
229 avgT, std::sqrt(varT), varT / avgT / avgT * nFreeCoord / 2);
230 }
231 if (std::isfinite(avgT) == 0) {
232 QUILL_LOG_DEBUG(log, "Infinite average temperature, something went wrong!");
233 newStateFlag = false;
234 }
235
236 // finalState is only filled on transition; keep product valid otherwise.
237 if (newStateFlag && finalState) {
239 } else if (current) {
240 *product = *current;
241 }
242
243 if (newStateFlag) {
244 return 1;
245 } else {
246 return 0;
247 }
248}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
static const char BOND_BOOST[]
Definition BondBoost.h:77
std::shared_ptr< Potential > pot
Definition Job.h:55
Parameters params
Definition Job.h:54
void dephase()
Dephase the trajectory to ensure thermal independence.
std::shared_ptr< Matter > saddle
std::shared_ptr< Matter > product
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 > finalState
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.
std::shared_ptr< Matter > finalStateTmp
std::vector< double > timeBuffer
std::vector< double > biasBuffer

◆ reportResults()

void SafeHyperJob::reportResults ( )
overrideprivatevirtual

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

Reimplemented from eonc::ReplicaDynamicsJob.

Definition at line 19 of file SafeHyperJob.cpp.

19 {
20 if (newStateFlag) {
21 QUILL_LOG_DEBUG(log, "Transition time: {:.2e} s",
22 minCorrectedTime * 1.0e-15 * params.constants.timeUnit);
23 } else {
24 QUILL_LOG_DEBUG(log,
25 "No new state was found in {} dynamics steps ({:.3e} s)",
26 params.dynamics_options.steps,
27 time * 1.0e-15 * params.constants.timeUnit);
28 }
29}

Member Data Documentation

◆ biasBuffer

std::vector<double> eonc::SafeHyperJob::biasBuffer
private

Definition at line 30 of file SafeHyperJob.h.

◆ timeBuffer

std::vector<double> eonc::SafeHyperJob::timeBuffer
private

Definition at line 29 of file SafeHyperJob.h.

◆ transitionPot

double eonc::SafeHyperJob::transitionPot {0.0}
private

Definition at line 28 of file SafeHyperJob.h.

28{0.0};

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