The accelerated dynamics loop. Returns status (1 = transition, 0 = none).
41 {
42 bool transitionFlag = false, recordFlag = true, stopFlag = false,
43 firstTransitFlag = false;
44 long nFreeCoord =
reactant->numberOfFreeAtoms() * 3;
45 long mdBufferLength;
46 long step = 0, refineStep, newStateStep = 0;
47 long nCheck = 0, nRecord = 0, nState = 0;
48 long StateCheckInterval, RecordInterval;
49 double kinE, kinT, avgT, varT;
50 double kB =
params.constants.kB;
51 double correctedTime = 0.0;
52 double stopTime = 0.0, sumSimulatedTime = 0.0;
53 double Temp = 0.0, sumT = 0.0, sumT2 = 0.0;
54 double correctionFactor = 1.0;
55 double transitionTime_current = 0.0, transitionTime_previous = 0.0;
56 double delta, minmu, factor, highT, lowT;
57
59
61 lowT =
params.tad_options.low_temperature;
62 highT =
params.main_options.temperature;
63 delta =
params.tad_options.confidence;
64 minmu =
params.tad_options.min_prefactor;
65 factor = std::log(1.0 / delta) / minmu;
66 StateCheckInterval =
67 static_cast<long>(
params.parallel_replica_options.state_check_interval /
68 params.dynamics_options.time_step);
69 RecordInterval =
70 static_cast<long>(
params.parallel_replica_options.record_interval /
71 params.dynamics_options.time_step);
72 Temp =
params.main_options.temperature;
74
75 mdBufferLength = static_cast<long>(StateCheckInterval / RecordInterval);
76 std::vector<std::shared_ptr<Matter>> mdBuffer(mdBufferLength);
77 for (long i = 0; i < mdBufferLength; i++) {
78 mdBuffer[i] = std::make_shared<Matter>(
pot,
params);
79 }
81
83 TAD.setThermalVelocity();
84
85 {
88 }
89
90 QUILL_LOG_DEBUG(
92 "Starting MD run\nTemperature: {:.2f} Kelvin"
93 "Total Simulation Time: {:.2f} fs\nTime Step: {:.2f} fs\nTotal Steps: "
94 "{}\n",
95 Temp,
96 params.dynamics_options.steps *
params.dynamics_options.time_step *
98 params.dynamics_options.time_step *
params.constants.timeUnit,
99 params.dynamics_options.steps);
100 QUILL_LOG_DEBUG(
log,
"MD buffer length: {}", mdBufferLength);
101
102 long tenthSteps =
params.dynamics_options.steps / 10;
103 if (tenthSteps == 0) {
104 tenthSteps =
params.dynamics_options.steps;
105 }
106
107 while (!stopFlag) {
108 kinE =
current->getKineticEnergy();
109 kinT = (2.0 * kinE / nFreeCoord / kB);
110 sumT += kinT;
111 sumT2 += kinT * kinT;
112 QUILL_LOG_TRACE_L1(
log,
"steps = {:10d} temp = {:10.5f} ", step, kinT);
113
116
118 nCheck++;
119 step++;
120 QUILL_LOG_TRACE_L1(
log,
"step = {:4d}, time= {:10.4f}", step,
time);
121
122 if (
params.parallel_replica_options.refine_transition && recordFlag &&
124 if (nCheck % RecordInterval == 0) {
127 nRecord++;
128 }
129 }
130
132 nCheck = 0;
133 nRecord = 0;
134 {
137 }
138 if (transitionFlag) {
139 nState++;
140 QUILL_LOG_DEBUG(
log,
"New State {}: ", nState);
143 newStateStep = step;
145 firstTransitFlag = 1;
146 }
147 }
148
149 if (transitionFlag) {
150 QUILL_LOG_TRACE_L1(
log,
"Refining transition time.");
151 {
154 }
155
157 newStateStep - StateCheckInterval + refineStep * RecordInterval;
158 transitionTime_current =
timeBuffer[refineStep];
160 transitionTime = transitionTime_current - transitionTime_previous;
161 transitionTime_previous = transitionTime_current;
163 QUILL_LOG_DEBUG(
log,
"barrier= {:.3f}",
barrier);
164 correctionFactor = std::exp(
barrier / kB * (1.0 / lowT - 1.0 / highT));
167
168 *
current = *mdBuffer[refineStep - 1];
169 velocity =
current->getVelocities();
170 velocity = velocity * (-1);
171 current->setVelocities(velocity);
172
177 }
179 QUILL_LOG_DEBUG(
181 "tranisitonTime= {:.3e} s, Barrier= {:.3f} eV, correctedTime= {:.3e} "
182 "s, "
183 "SimulatedTime= {:.3e} s, minCorTime= {:.3e} s, stopTime= {:.3e} s",
185 correctedTime * 1e-15 *
params.constants.timeUnit,
186 sumSimulatedTime * 1e-15 *
params.constants.timeUnit,
188 stopTime * 1.0e-15 *
params.constants.timeUnit);
189
190 transitionFlag = false;
191 }
192
193 if (firstTransitFlag && sumSimulatedTime >= stopTime) {
194 stopFlag = true;
196 }
197
198 if ((step % tenthSteps == 0) || (step ==
params.dynamics_options.steps)) {
200 QUILL_LOG_DEBUG(
201 log,
"progress: {:.0f}%, max displacement: {:.3f}, step {}/{}",
202 static_cast<double>(100.0 * step) /
params.dynamics_options.steps,
203 maxAtomDistance, step,
params.dynamics_options.steps);
204 }
205
206 if (step ==
params.dynamics_options.steps) {
207 stopFlag = true;
208 if (firstTransitFlag) {
209 QUILL_LOG_DEBUG(
log,
"Detected one transition");
210 } else {
211 QUILL_LOG_DEBUG(
log,
"Failed to detect any transition");
212 }
213 }
214 }
215
216 avgT = sumT / step;
217 varT = sumT2 / step - avgT * avgT;
218
220 "Temperature : Average = {} ; Stddev = {} ; Factor = {}; "
221 "Average_Boost = {}",
222 avgT, std::sqrt(varT), varT / avgT / avgT * nFreeCoord / 2,
224 if (std::isfinite(avgT) == 0) {
225 QUILL_LOG_DEBUG(
log,
"Infinite average temperature, something went wrong!");
227 }
228
230
232 return 1;
233 } else {
234 return 0;
235 }
236}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
std::shared_ptr< Matter > crossing
std::vector< double > timeBuffer
std::shared_ptr< Potential > pot
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