Loading...
Searching...
No Matches
TADJob.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/TADJob.h"
13#include "eon/Dynamics.h"
14#include "eon/ForceCallTimer.h"
15
16#include <cmath>
17
19 crossing = std::make_shared<Matter>(pot, params);
20
21 QUILL_LOG_DEBUG(log, "Temperature Accelerated Dynamics, running");
22 QUILL_LOG_DEBUG(log,
23 "High temperature MD simulation running at {:.2f} K to "
24 "simulate dynamics at {:.2f} K",
25 params.main_options.temperature,
26 params.tad_options.low_temperature);
27}
28
30 if (newStateFlag) {
31 QUILL_LOG_DEBUG(log, "Transition time: {:.2e} s",
32 minCorrectedTime * 1.0e-15 * params.constants.timeUnit);
33 } else {
34 QUILL_LOG_DEBUG(log,
35 "No new state was found in {} dynamics steps ({:.3e} s)",
36 params.dynamics_options.steps,
37 time * 1.0e-15 * params.constants.timeUnit);
38 }
39}
40
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
58 AtomMatrix velocity;
59
60 minCorrectedTime = 1.0e200;
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 }
80 timeBuffer.resize(mdBufferLength);
81
82 Dynamics TAD(current.get(), params);
83 TAD.setThermalVelocity();
84
85 {
87 dephase();
88 }
89
90 QUILL_LOG_DEBUG(
91 log,
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 *
97 params.constants.timeUnit,
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
114 TAD.oneStep();
115 mdFCalls++;
116
117 time += params.dynamics_options.time_step;
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 &&
123 !newStateFlag) {
124 if (nCheck % RecordInterval == 0) {
125 *mdBuffer[nRecord] = *current;
126 timeBuffer[nRecord] = time;
127 nRecord++;
128 }
129 }
130
131 if ((nCheck == StateCheckInterval) && !newStateFlag) {
132 nCheck = 0;
133 nRecord = 0;
134 {
136 transitionFlag = checkState(current.get(), reactant.get());
137 }
138 if (transitionFlag) {
139 nState++;
140 QUILL_LOG_DEBUG(log, "New State {}: ", nState);
143 newStateStep = step;
144 transitionStep = newStateStep;
145 firstTransitFlag = 1;
146 }
147 }
148
149 if (transitionFlag) {
150 QUILL_LOG_TRACE_L1(log, "Refining transition time.");
151 {
153 refineStep = refine(mdBuffer, reactant.get());
154 }
155
157 newStateStep - StateCheckInterval + refineStep * RecordInterval;
158 transitionTime_current = timeBuffer[refineStep];
159 *crossing = *mdBuffer[refineStep];
160 transitionTime = transitionTime_current - transitionTime_previous;
161 transitionTime_previous = transitionTime_current;
162 barrier = crossing->getPotentialEnergy() - reactant->getPotentialEnergy();
163 QUILL_LOG_DEBUG(log, "barrier= {:.3f}", barrier);
164 correctionFactor = std::exp(barrier / kB * (1.0 / lowT - 1.0 / highT));
165 correctedTime = transitionTime * correctionFactor;
166 sumSimulatedTime += transitionTime;
167
168 *current = *mdBuffer[refineStep - 1];
169 velocity = current->getVelocities();
170 velocity = velocity * (-1);
171 current->setVelocities(velocity);
172
173 if (correctedTime < minCorrectedTime) {
174 minCorrectedTime = correctedTime;
175 *saddle = *crossing;
177 }
178 stopTime = factor * std::pow(minCorrectedTime / factor, lowT / highT);
179 QUILL_LOG_DEBUG(
180 log,
181 "tranisitonTime= {:.3e} s, Barrier= {:.3f} eV, correctedTime= {:.3e} "
182 "s, "
183 "SimulatedTime= {:.3e} s, minCorTime= {:.3e} s, stopTime= {:.3e} s",
184 transitionTime * 1e-15 * params.constants.timeUnit, barrier,
185 correctedTime * 1e-15 * params.constants.timeUnit,
186 sumSimulatedTime * 1e-15 * params.constants.timeUnit,
187 minCorrectedTime * 1.0e-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;
195 newStateFlag = true;
196 }
197
198 if ((step % tenthSteps == 0) || (step == params.dynamics_options.steps)) {
199 double maxAtomDistance = current->perAtomNorm(*reactant);
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
219 QUILL_LOG_DEBUG(log,
220 "Temperature : Average = {} ; Stddev = {} ; Factor = {}; "
221 "Average_Boost = {}",
222 avgT, std::sqrt(varT), varT / avgT / avgT * nFreeCoord / 2,
223 minCorrectedTime / step / params.dynamics_options.time_step);
224 if (std::isfinite(avgT) == 0) {
225 QUILL_LOG_DEBUG(log, "Infinite average temperature, something went wrong!");
226 newStateFlag = false;
227 }
228
230
231 if (newStateFlag) {
232 return 1;
233 } else {
234 return 0;
235 }
236}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
void initExtra() override
Create any extra matter objects needed by the subclass.
Definition TADJob.cpp:18
RAII wrapper for tracking force calls over a scope.
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::shared_ptr< Matter > crossing
Definition TADJob.h:27
double barrier
Definition TADJob.h:28
int dynamics() override
The accelerated dynamics loop. Returns status (1 = transition, 0 = none).
Definition TADJob.cpp:41
void reportResults() override
Post-dynamics logging (override for job-specific messages).
Definition TADJob.cpp:29
std::vector< double > timeBuffer
Definition TADJob.h:29