31 std::string reactant_passed =
33 std::vector<std::string> returnFiles;
35 auto matter_cur = std::make_unique<Matter>(
pot,
params);
36 auto matter_hop = std::make_unique<Matter>(
pot,
params);
38 QUILL_LOG_CRITICAL(
log,
"Failed to load {}", reactant_passed);
39 throw std::runtime_error(
"failed to load " + reactant_passed);
42 long nstep =
params.global_optimization_options.steps;
43 AtomMatrix rat_t(matter_cur->numberOfAtoms(), 3);
47 QUILL_LOG_DEBUG(
log,
"\nBeginning minima hopping of {}",
48 reactant_passed.c_str());
50 QUILL_LOG_TRACE_L1(
log,
"fcalls= {}", matter_cur->getForceCalls());
51 QUILL_LOG_TRACE_L1(
log,
"epot= {:24.15E}", matter_cur->getPotentialEnergy());
53 matter_cur->relax(
false,
params.debug_options.write_movies,
54 params.main_options.checkpoint,
"min",
"matter_cur");
55 QUILL_LOG_DEBUG(
log,
"converged {}", (converged) ?
"TRUE" :
"FALSE");
58 earr.push_back(matter_cur->getPotentialEnergy());
59 *matter_hop = *matter_cur;
61 for (
long istep = 1; istep <= nstep; istep++) {
67 analyze(*matter_cur, *matter_hop);
70 if (matter_cur->getPotentialEnergy() <
71 params.global_optimization_options.target_energy)
74 for (
size_t i = 0; i <
earr.size(); i++) {
79 earrim1 =
earr[i - 1];
81 earrfile << std::format(
"{:5} {:15.5f} {:15.5f} {:15.5f} ", i + 1,
95 size_t jlo =
hunt(epot);
96 QUILL_LOG_TRACE_L1(
log,
"REZA: {}", jlo);
97 if (std::abs(epot -
earr[jlo]) <
98 params.structure_comparison_options.energy_difference) {
105 matter_cur = matter_hop;
109 "new lowest: nlmin, epot_hop, dE {:7d} {:15.5f} {:10.5f}",
110 1, epot_hop, epot_hop -
earr[0]);
119 "ERROR: new minimum is neither accepted nor rejected: client stops.");
120 throw std::runtime_error(
121 "[Global Optimization] new minimum is neither accepted nor rejected");
130 double epot, epot_hop;
133 if (std::abs(epot_hop - epot) <
134 params.structure_comparison_options.energy_difference) {
156 QUILL_LOG_CRITICAL(
log,
157 "ERROR: client does not know what to do with ekin.");
158 QUILL_LOG_CRITICAL(
log,
"ERROR: client stops in applyMoveFeedbackMD.");
159 throw std::runtime_error(std::format(
160 "[Global Optimization] unknown hoppingResult: {}",
hoppingResult));
197 double temp = (2.0 * ekin_p /
params.constants.kB);
198 double dt =
params.dynamics_options.time_step;
200 "{:15.5f} {:15.5f} {:11} {:12.2f} {}{} {:5} {:5}", epot_hop,
212 if (
params.global_optimization_options.decision_method ==
"npew") {
215 }
else if (
params.global_optimization_options.decision_method ==
221 log,
"ERROR: accept/reject method not specified. client stops.");
222 throw std::invalid_argument(
223 std::format(
"[Global Optimization] unknown decision_method: {}",
224 params.global_optimization_options.decision_method));
245 double deltaE = eTrial - eCurrent;
246 double kB = 8.6173324e-5;
252 p = std::exp(-deltaE /
params.main_options.temperature * kB);
265 matter_hop = matter_cur;
267 if (
params.global_optimization_options.move_method ==
"md") {
270 }
else if (
params.global_optimization_options.move_method ==
"random") {
276 matter_hop.
relax(
true,
params.debug_options.write_movies,
277 params.main_options.checkpoint,
"min",
"matter_hop");
278 QUILL_LOG_DEBUG(
log,
"converged {}", (converged) ?
"TRUE" :
"FALSE");
288 displacement.setZero();
291 for (
int i = 0; i < num; i++) {
292 double disp =
params.basin_hopping_options.displacement;
294 for (
int j = 0; j < 3; j++) {
295 if (
params.basin_hopping_options.displacement_distribution ==
298 }
else if (
params.basin_hopping_options.displacement_distribution ==
303 QUILL_LOG_CRITICAL(
log,
"Unknown displacement_distribution");
304 throw std::invalid_argument(std::format(
305 "[Global Optimization] unknown displacement_distribution: {}",
306 params.basin_hopping_options.displacement_distribution));
316 double ekinc, epot, etot, epot0, etot0;
317 auto dyn = std::make_unique<Dynamics>(&matter,
params);
324 size_t nummax = 0, nummin = 0;
325 double enmin1 = 0.0, enmin2 = 0.0, en0000 = 0.0;
326 double econs_max = -1.E100, econs_min = 1.E100, devcon;
327 bool md_presumably_escaped =
false;
328 QUILL_LOG_DEBUG(
log,
"MD {:5d} {:20.10E} {:15.5E} {:15.5E} ", 0,
329 epot - epot0, ekinc, etot - etot0);
331 for (
int imd = 1; imd <= nmd; imd++) {
334 dyn->velocityVerlet();
338 en0000 = epot - epot0;
339 if (enmin1 > enmin2 && enmin1 > en0000)
341 if (enmin1 < enmin2 && enmin1 < en0000)
343 QUILL_LOG_TRACE_L1(
log,
344 "MD {:5d} {:15.5f} {:15.5f} {:12.2E} {:4} {:4}",
345 imd, epot - epot0, ekinc, etot - etot0, nummax, nummin);
346 econs_max = std::max(econs_max, ekinc + epot);
347 econs_min = std::min(econs_min, ekinc + epot);
348 if (nummin >=
static_cast<size_t>(
mdmin)) {
349 if (nummax != nummin)
350 QUILL_LOG_WARNING(
log,
"WARNING: iproc,nummin,nummax {} {}", nummin,
352 md_presumably_escaped =
true;
356 devcon = econs_max - econs_min;
357 if (md_presumably_escaped) {
359 if (devcon /
ekin < 2.E-3) {
360 params.dynamics_options.time_step *= 1.1;
362 params.dynamics_options.time_step /= 1.1;
365 QUILL_LOG_DEBUG(
log,
"TOO MANY MD STEPS ");
366 params.dynamics_options.time_step *= 2.0;
372 double tt1, tt2, tt3, vtot[3];
382 vat(iat, 0) = (tt1 - 0.5) * 2.0;
383 vat(iat, 1) = (tt2 - 0.5) * 2.0;
384 vat(iat, 2) = (tt3 - 0.5) * 2.0;
385 vtot[0] += vat(iat, 0);
386 vtot[1] += vat(iat, 1);
387 vtot[2] += vat(iat, 2);
389 QUILL_LOG_DEBUG(
log,
"Linear momentum {:15.5E} {:15.5E} {:15.5E} ",
390 vtot[0], vtot[1], vtot[2]);
395 vat(iat, 0) -= vtot[0];
396 vat(iat, 1) -= vtot[1];
397 vat(iat, 2) -= vtot[2];
402 double kB =
params.constants.kB;
403 double kinT = (2.0 * kinE / nFreeCoords / kB);
404 double temperature = (2.0 *
ekin / kB);
421 size_t jlo, jlo_insert;
425 QUILL_LOG_DEBUG(
log,
"JLO= {} {:10.5f} ", jlo, std::abs(epot -
earr[jlo]));
428 if (!(std::abs(epot -
earr[jlo]) <
429 params.structure_comparison_options.energy_difference)) {
432 if (epot >
earr[jlo])
434 earr.insert(
earr.begin() + jlo_insert, 1, epot);
443 for (jlo = 0; jlo <
earr.size(); jlo++)
444 if (epot <
earr[jlo])
446 if (jlo ==
earr.size())
448 de = std::abs(epot -
earr[jlo]);
450 if (std::abs(epot -
earr[jlo - 1]) < de)
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
std::vector< std::string > run(void)
Virtual run; used solely for dynamic dispatch.
std::vector< double > earr
void analyze(Matter &, Matter &)
std::string hoppingResult
void decisionStep(Matter &, Matter &)
void examineEscape(Matter &, Matter &)
void hoppingStep(long, Matter &, Matter &)
std::string decisionResult
void applyDecisionFeedback(void)
void randomMove(Matter &)
void acceptRejectNPEW(Matter &, Matter &)
void acceptRejectBoltzmann(Matter &, Matter &)
void applyMoveFeedbackMD(void)
std::shared_ptr< Potential > pot
double getPotentialEnergy() const
long getForceCalls() const
void setVelocities(const AtomMatrix &v)
long int numberOfAtoms() const
bool relax(bool quiet=false, bool writeMovie=false, bool checkpoint=false, std::string prefixMovie=std::string(), std::string prefixCheckpoint=std::string(), bool retainMovieFrames=false)
long int numberOfFreeAtoms() const
void setPositions(const AtomMatrix &pos)
double getKineticEnergy() const
const AtomMatrix & getPositions() const
int getFixed(long int atom) const
1 if every Cartesian axis of the atom is fixed, else 0.
std::string getRelevantFile(std::string filename)
double gaussRandom(double avg, double std)
constexpr bool io_ok(IoStatus s) noexcept
quill::Logger * traceback() noexcept
Get or create the "_traceback" logger for traceback logging.