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]);
105 "ERROR: new minimum is neither accepted nor rejected: client stops.");
106 throw std::runtime_error(
107 "[Global Optimization] new minimum is neither accepted nor rejected");
113 double epot, epot_hop;
116 if (std::abs(epot_hop - epot) <
117 params.structure_comparison_options().energy_difference) {
137 QUILL_LOG_CRITICAL(
log,
138 "ERROR: client does not know what to do with ekin.");
139 QUILL_LOG_CRITICAL(
log,
"ERROR: client stops in applyMoveFeedbackMD.");
140 throw std::runtime_error(std::format(
141 "[Global Optimization] unknown hoppingResult: {}",
hoppingResult));
178 double temp = (2.0 * ekin_p /
params.constants().kB);
179 double dt =
params.dynamics_options().time_step;
181 "{:15.5f} {:15.5f} {:11} {:12.2f} {}{} {:5} {:5}", epot_hop,
192 if (
params.global_optimization_options().decision_method ==
"npew") {
194 }
else if (
params.global_optimization_options().decision_method ==
200 log,
"ERROR: accept/reject method not specified. client stops.");
201 throw std::invalid_argument(
202 std::format(
"[Global Optimization] unknown decision_method: {}",
203 params.global_optimization_options().decision_method));
224 double deltaE = eTrial - eCurrent;
225 const double kB =
params.constants().kB;
226 const double T =
params.main_options().temperature;
231 }
else if (!(T > 0.0) || !(kB > 0.0)) {
234 p = std::exp(-deltaE / (kB * T));
247 matter_hop = matter_cur;
249 if (
params.global_optimization_options().move_method ==
"md") {
252 }
else if (
params.global_optimization_options().move_method ==
"random") {
258 matter_hop.
relax(
true,
params.debug_options().write_movies,
259 params.main_options().checkpoint,
"min",
"matter_hop");
260 QUILL_LOG_DEBUG(
log,
"converged {}", (converged) ?
"TRUE" :
"FALSE");
270 displacement.setZero();
273 for (
int i = 0; i < num; i++) {
274 double disp =
params.basin_hopping_options().displacement;
276 for (
int j = 0; j < 3; j++) {
277 if (
params.basin_hopping_options().displacement_distribution ==
280 }
else if (
params.basin_hopping_options().displacement_distribution ==
285 QUILL_LOG_CRITICAL(
log,
"Unknown displacement_distribution");
286 throw std::invalid_argument(std::format(
287 "[Global Optimization] unknown displacement_distribution: {}",
288 params.basin_hopping_options().displacement_distribution));
298 double ekinc, epot, etot, epot0, etot0;
299 auto dyn = std::make_unique<Dynamics>(&matter,
params);
306 size_t nummax = 0, nummin = 0;
307 double enmin1 = 0.0, enmin2 = 0.0, en0000 = 0.0;
308 double econs_max = -1.E100, econs_min = 1.E100, devcon;
309 bool md_presumably_escaped =
false;
310 QUILL_LOG_DEBUG(
log,
"MD {:5d} {:20.10E} {:15.5E} {:15.5E} ", 0,
311 epot - epot0, ekinc, etot - etot0);
313 for (
int imd = 1; imd <= nmd; imd++) {
316 dyn->velocityVerlet();
320 en0000 = epot - epot0;
321 if (enmin1 > enmin2 && enmin1 > en0000)
323 if (enmin1 < enmin2 && enmin1 < en0000)
325 QUILL_LOG_TRACE_L1(
log,
326 "MD {:5d} {:15.5f} {:15.5f} {:12.2E} {:4} {:4}",
327 imd, epot - epot0, ekinc, etot - etot0, nummax, nummin);
328 econs_max = std::max(econs_max, ekinc + epot);
329 econs_min = std::min(econs_min, ekinc + epot);
330 if (nummin >=
static_cast<size_t>(
mdmin)) {
331 if (nummax != nummin)
332 QUILL_LOG_WARNING(
log,
"WARNING: iproc,nummin,nummax {} {}", nummin,
334 md_presumably_escaped =
true;
338 devcon = econs_max - econs_min;
339 if (md_presumably_escaped) {
341 if (devcon /
ekin < 2.E-3) {
347 QUILL_LOG_DEBUG(
log,
"TOO MANY MD STEPS ");
354 double tt1, tt2, tt3, vtot[3];
363 vat(iat, 0) = (tt1 - 0.5) * 2.0;
364 vat(iat, 1) = (tt2 - 0.5) * 2.0;
365 vat(iat, 2) = (tt3 - 0.5) * 2.0;
366 vtot[0] += vat(iat, 0);
367 vtot[1] += vat(iat, 1);
368 vtot[2] += vat(iat, 2);
370 QUILL_LOG_DEBUG(
log,
"Linear momentum {:15.5E} {:15.5E} {:15.5E} ",
371 vtot[0], vtot[1], vtot[2]);
376 vat(iat, 0) -= vtot[0];
377 vat(iat, 1) -= vtot[1];
378 vat(iat, 2) -= vtot[2];
382 if (nFreeCoords <= 0) {
383 throw std::invalid_argument(
"GlobalOptimizationJob::velopt: no free atoms");
386 double kB =
params.constants().kB;
387 double kinT = (2.0 * kinE / nFreeCoords / kB);
389 throw std::runtime_error(
390 "GlobalOptimizationJob::velopt: zero kinetic temperature");
392 double temperature = (2.0 *
ekin / kB);
398 size_t jlo, jlo_insert;
401 QUILL_LOG_DEBUG(
log,
"JLO= {} {:10.5f} ", jlo, std::abs(epot -
earr[jlo]));
402 if (!(std::abs(epot -
earr[jlo]) <
403 params.structure_comparison_options().energy_difference)) {
405 if (epot >
earr[jlo])
407 earr.insert(
earr.begin() + jlo_insert, 1, epot);
416 for (jlo = 0; jlo <
earr.size(); jlo++)
417 if (epot <
earr[jlo])
419 if (jlo ==
earr.size())
421 de = std::abs(epot -
earr[jlo]);
423 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
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)