27 std::string reactant_passed =
29 std::vector<std::string> returnFiles;
30 auto matter_cur = std::make_unique<Matter>(
pot,
params);
31 auto matter_hop = std::make_unique<Matter>(
pot,
params);
33 QUILL_LOG_CRITICAL(
log,
"Failed to load {}", reactant_passed);
34 throw std::runtime_error(
"failed to load " + reactant_passed);
37 long nstep =
params.global_optimization_options().steps;
38 AtomMatrix rat_t(matter_cur->numberOfAtoms(), 3);
39 QUILL_LOG_DEBUG(
log,
"\nBeginning minima hopping of {}",
40 reactant_passed.c_str());
41 QUILL_LOG_TRACE_L1(
log,
"fcalls= {}", matter_cur->getForceCalls());
42 QUILL_LOG_TRACE_L1(
log,
"epot= {:24.15E}", matter_cur->getPotentialEnergy());
44 matter_cur->relax(
false,
params.debug_options().write_movies,
45 params.main_options().checkpoint,
"min",
"matter_cur");
46 QUILL_LOG_DEBUG(
log,
"converged {}", (converged) ?
"TRUE" :
"FALSE");
47 earr.push_back(matter_cur->getPotentialEnergy());
48 *matter_hop = *matter_cur;
50 for (
long istep = 1; istep <= nstep; istep++) {
56 analyze(*matter_cur, *matter_hop);
59 if (matter_cur->getPotentialEnergy() <
60 params.global_optimization_options().target_energy)
63 for (
size_t i = 0; i <
earr.size(); i++) {
68 earrim1 =
earr[i - 1];
70 earrfile << std::format(
"{:5} {:15.5f} {:15.5f} {:15.5f} ", i + 1,
82 size_t jlo =
hunt(epot);
83 QUILL_LOG_TRACE_L1(
log,
"REZA: {}", jlo);
84 if (std::abs(epot -
earr[jlo]) <
85 params.structure_comparison_options().energy_difference) {
92 matter_cur = matter_hop;
96 "new lowest: nlmin, epot_hop, dE {:7d} {:15.5f} {:10.5f}",
97 1, epot_hop, epot_hop -
earr[0]);
106 "ERROR: new minimum is neither accepted nor rejected: client stops.");
108 throw std::runtime_error(
109 "[Global Optimization] new minimum is neither accepted nor rejected");
115 double epot, epot_hop;
118 if (std::abs(epot_hop - epot) <
119 params.structure_comparison_options().energy_difference) {
140 QUILL_LOG_CRITICAL(
log,
141 "ERROR: client does not know what to do with ekin.");
142 QUILL_LOG_CRITICAL(
log,
"ERROR: client stops in applyMoveFeedbackMD.");
144 throw std::runtime_error(std::format(
145 "[Global Optimization] unknown hoppingResult: {}",
hoppingResult));
182 double temp = (2.0 * ekin_p /
params.constants().kB);
183 double dt =
params.dynamics_options().time_step;
185 "{:15.5f} {:15.5f} {:11} {:12.2f} {}{} {:5} {:5}", epot_hop,
196 if (
params.global_optimization_options().decision_method ==
"npew") {
198 }
else if (
params.global_optimization_options().decision_method ==
204 log,
"ERROR: accept/reject method not specified. client stops.");
205 throw std::invalid_argument(
206 std::format(
"[Global Optimization] unknown decision_method: {}",
207 params.global_optimization_options().decision_method));
228 double deltaE = eTrial - eCurrent;
229 const double kB =
params.constants().kB;
230 const double T =
params.main_options().temperature;
235 }
else if (!(T > 0.0) || !(kB > 0.0)) {
238 p = std::exp(-deltaE / (kB * T));
251 matter_hop = matter_cur;
253 if (
params.global_optimization_options().move_method ==
"md") {
256 }
else if (
params.global_optimization_options().move_method ==
"random") {
262 matter_hop.
relax(
true,
params.debug_options().write_movies,
263 params.main_options().checkpoint,
"min",
"matter_hop");
264 QUILL_LOG_DEBUG(
log,
"converged {}", (converged) ?
"TRUE" :
"FALSE");
274 displacement.setZero();
277 for (
int i = 0; i < num; i++) {
278 double disp =
params.basin_hopping_options().displacement;
280 for (
int j = 0; j < 3; j++) {
281 if (
params.basin_hopping_options().displacement_distribution ==
284 }
else if (
params.basin_hopping_options().displacement_distribution ==
289 QUILL_LOG_CRITICAL(
log,
"Unknown displacement_distribution");
290 throw std::invalid_argument(std::format(
291 "[Global Optimization] unknown displacement_distribution: {}",
292 params.basin_hopping_options().displacement_distribution));
302 double ekinc, epot, etot, epot0, etot0;
303 auto dyn = std::make_unique<Dynamics>(&matter,
params);
310 size_t nummax = 0, nummin = 0;
311 double enmin1 = 0.0, enmin2 = 0.0, en0000 = 0.0;
312 double econs_max = -1.E100, econs_min = 1.E100, devcon;
313 bool md_presumably_escaped =
false;
314 QUILL_LOG_DEBUG(
log,
"MD {:5d} {:20.10E} {:15.5E} {:15.5E} ", 0,
315 epot - epot0, ekinc, etot - etot0);
317 for (
int imd = 1; imd <= nmd; imd++) {
320 dyn->velocityVerlet();
324 en0000 = epot - epot0;
325 if (enmin1 > enmin2 && enmin1 > en0000)
327 if (enmin1 < enmin2 && enmin1 < en0000)
329 QUILL_LOG_TRACE_L1(
log,
330 "MD {:5d} {:15.5f} {:15.5f} {:12.2E} {:4} {:4}",
331 imd, epot - epot0, ekinc, etot - etot0, nummax, nummin);
332 econs_max = std::max(econs_max, ekinc + epot);
333 econs_min = std::min(econs_min, ekinc + epot);
334 if (nummin >=
static_cast<size_t>(
mdmin)) {
335 if (nummax != nummin)
336 QUILL_LOG_WARNING(
log,
"WARNING: iproc,nummin,nummax {} {}", nummin,
338 md_presumably_escaped =
true;
342 devcon = econs_max - econs_min;
343 if (md_presumably_escaped) {
345 if (devcon /
ekin < 2.E-3) {
351 QUILL_LOG_DEBUG(
log,
"TOO MANY MD STEPS ");
358 double tt1, tt2, tt3, vtot[3];
367 vat(iat, 0) = (tt1 - 0.5) * 2.0;
368 vat(iat, 1) = (tt2 - 0.5) * 2.0;
369 vat(iat, 2) = (tt3 - 0.5) * 2.0;
370 vtot[0] += vat(iat, 0);
371 vtot[1] += vat(iat, 1);
372 vtot[2] += vat(iat, 2);
374 QUILL_LOG_DEBUG(
log,
"Linear momentum {:15.5E} {:15.5E} {:15.5E} ",
375 vtot[0], vtot[1], vtot[2]);
380 vat(iat, 0) -= vtot[0];
381 vat(iat, 1) -= vtot[1];
382 vat(iat, 2) -= vtot[2];
386 if (nFreeCoords <= 0) {
387 throw std::invalid_argument(
"GlobalOptimizationJob::velopt: no free atoms");
390 double kB =
params.constants().kB;
391 double kinT = (2.0 * kinE / nFreeCoords / kB);
393 throw std::runtime_error(
394 "GlobalOptimizationJob::velopt: zero kinetic temperature");
396 double temperature = (2.0 *
ekin / kB);
402 size_t jlo, jlo_insert;
405 QUILL_LOG_DEBUG(
log,
"JLO= {} {:10.5f} ", jlo, std::abs(epot -
earr[jlo]));
406 if (!(std::abs(epot -
earr[jlo]) <
407 params.structure_comparison_options().energy_difference)) {
409 if (epot >
earr[jlo])
411 earr.insert(
earr.begin() + jlo_insert, 1, epot);
420 for (jlo = 0; jlo <
earr.size(); jlo++)
421 if (epot <
earr[jlo])
423 if (jlo ==
earr.size())
425 de = std::abs(epot -
earr[jlo]);
427 if (std::abs(epot -
earr[jlo - 1]) < de)
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
void examineEscape(Matter &, Matter &)
void randomMove(Matter &)
std::vector< double > earr
void decisionStep(Matter &, Matter &)
std::string hoppingResult
void acceptRejectNPEW(Matter &, Matter &)
void analyze(Matter &, Matter &)
std::string decisionResult
void acceptRejectBoltzmann(Matter &, Matter &)
void applyDecisionFeedback(void)
std::vector< std::string > run(void)
Virtual run; used solely for dynamic dispatch.
void hoppingStep(long, Matter &, Matter &)
void applyMoveFeedbackMD(void)
std::shared_ptr< Potential > pot
Set when one Potential is shared across Matters, images, or a caller.
double getKineticEnergy() const
const AtomMatrix & getPositions() 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)
void setPositions(const AtomMatrix &pos)
long int numberOfAtoms() const
long getForceCalls() const
void setVelocities(const AtomMatrix &v)
double getPotentialEnergy() const
long int numberOfFreeAtoms() 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)
constexpr bool io_ok(IoStatus s) noexcept
quill::Logger * traceback() noexcept
Get or create the "_traceback" logger for traceback logging.
double gaussRandom(double avg, double std)
RAII resource manager for the ARTn C library with global synchronization.
static dynamics_options_t & dynamics_options(Parameters &p)