[Instanton] mode rate with pi_planes > 0: the planes and rate at each temperature, and with pi_recrossing_parents > 0 the transmission factor on the top plane and k_RPMD = kappa k_PI-QTST.
hSaddle and the band in pathQ are in the instanton's mass-weighted coordinates over the free atoms, measured from the reactant; saddle is aligned to the reactant. Appends results.dat keys for the last (lowest) temperature to extras and returns the files written.
171 {
175 const Embedding emb(reactant);
176 const VectorXd qSaddle = emb.toQ(reactant, saddle);
177 const double qNorm = qSaddle.norm();
178 if (!(qNorm > 0.0)) {
179 throw std::runtime_error("piqtst: the saddle sits on the reactant");
180 }
181 const VectorXd lineDir = qSaddle / qNorm;
182
183
184
185
186 VectorXd dir = lineDir;
187 std::string chosen = "line";
188 if (o.pi_direction == "mode") {
189 const Eigen::SelfAdjointEigenSolver<MatrixXd> es(
190 0.5 * (hSaddle + hSaddle.transpose()));
191 if (es.info() == Eigen::Success && es.eigenvalues()(0) < 0.0) {
192 VectorXd v = es.eigenvectors().col(0);
193 if (v.dot(lineDir) < 0.0) {
194 v = -v;
195 }
196 if (v.dot(lineDir) >= 0.5) {
197 dir = v;
198 chosen = "mode";
199 } else {
201 "rad with the reactant-saddle line; planes follow "
202 "the line",
203 std::acos(v.dot(lineDir)));
204 }
205 } else {
207 "negative eigenvalue; planes follow the line");
208 }
209 }
210 if (emb.freeAtoms.size() ==
static_cast<size_t>(
reactant.numberOfAtoms()) &&
213 "fixed in the reactant's frame and a rotation of the "
214 "cluster moves the centroid between them");
215 }
216 const double sStar = dir.dot(qSaddle);
217 const long nPlanes = o.pi_planes;
218 const double s0 = -o.pi_reactant_extent * sStar;
219 std::vector<double> sPlanes;
220 for (long j = 0; j < nPlanes; ++j) {
221 sPlanes.push_back(s0 + (sStar - s0) * static_cast<double>(j) /
222 static_cast<double>(nPlanes - 1));
223 }
224
227 c.masses.resize(static_cast<size_t>(c.atoms));
228 c.numbers.resize(static_cast<size_t>(c.atoms));
229 c.free.assign(static_cast<size_t>(3 * c.atoms), 0);
230 const VectorXi z =
reactant.getAtomicNrs();
231 for (long i = 0; i < c.atoms; ++i) {
232 c.masses[
static_cast<size_t>(i)] =
reactant.getMass(i);
233 c.numbers[static_cast<size_t>(i)] = z(i);
234 }
235 for (const long i : emb.freeAtoms) {
236 for (int a = 0; a < 3; ++a) {
237 c.free[static_cast<size_t>(3 * i + a)] = 1;
238 }
239 }
240 c.reference = flatten(
reactant.getPositions());
241 c.direction = emb.full(dir);
244 c.box = cell.data();
245
246
247
248 std::vector<double> bandS;
249 for (const auto &q : pathQ) {
250 bandS.push_back(dir.dot(q));
251 }
252 auto seed = [&](double s) -> VectorXd {
253 for (size_t k = 0; k + 1 < pathQ.size(); ++k) {
254 const double lo = bandS[k];
255 const double hi = bandS[k + 1];
256 if ((lo <= s && s <= hi) || (hi <= s && s <= lo)) {
257 const double t = hi != lo ? (s - lo) / (hi - lo) : 0.0;
258 return emb.cartesian(c.reference,
259 (1.0 - t) * pathQ[k] + t * pathQ[k + 1]);
260 }
261 }
262 return emb.cartesian(c.reference, (s / sStar) * qSaddle);
263 };
264
265 const double vReactant = Matter(reactant).getPotentialEnergy();
266 const double vSaddle = Matter(saddle).getPotentialEnergy();
267 double effective = std::numeric_limits<double>::quiet_NaN();
268 for (const auto &kv : extras) {
269 if (kv.first == "barrier_effective_instanton") {
270 effective = kv.second;
271 }
272 }
273 EONC_LOG_INFO(
"[Instanton] piqtst: {} planes from s = {:.4f} to s* = {:.4f} "
274 "amu^0.5 A along the {}, {} beads, {} + {} steps of {:.4g} fs",
275 nPlanes, s0, sStar, chosen == "mode" ? "unstable mode" : "line",
276 o.pi_beads, o.pi_equilibration_steps, o.pi_sampling_steps,
277 o.pi_time_step);
278
279 const std::string tableFile = "rate_piqtst.dat";
280 std::ofstream table(tableFile);
281 if (!table) {
282 throw std::runtime_error("piqtst: cannot write " + tableFile);
283 }
284 const bool kappaOn = o.pi_recrossing_parents > 0;
285 if (kappaOn && o.pi_thermostat == "piglet") {
287 "take pile; RPMD needs the ring polymer's own "
288 "distribution, which piglet does not sample");
289 }
290 table << "# T_K s_amu05A dF_ds_eV_per_amu05A dF_ds_error F_eV F_error_eV "
291 "spread_max_A";
292 if (kappaOn) {
293 table << " kappa kappa_error ln_k_rpmd_s ln_k_rpmd_s_error";
294 }
295 table << '\n';
296 table << std::setprecision(10);
297 std::vector<std::string> files{tableFile};
298
299 std::vector<double> sorted = temperatures;
300 std::sort(sorted.begin(), sorted.end(), std::greater<>());
302 for (size_t ti = 0; ti < sorted.size(); ++ti) {
303 const double t = sorted[ti];
304 const bool last = ti + 1 == sorted.size();
308 so.equilibration = o.pi_equilibration_steps;
309 so.production = o.pi_sampling_steps;
310 so.blocks = 10;
311 so.ring.beads = o.pi_beads;
312 so.ring.temperature = t;
315 so.ring.dt = o.pi_time_step / timeUnit;
316 so.ring.thermostat = o.pi_thermostat == "piglet"
319 so.ring.pileTau = o.pi_pile_tau / timeUnit;
320 so.ring.pileScale = o.pi_pile_scale;
321 so.ring.gleFile = o.pi_gle_file;
322 so.ring.seed = static_cast<std::uint64_t>(o.pi_seed);
323 so.seed = seed;
324 const std::vector<Plane> planes =
scan(pot, c, so);
326 const double lnPerSecond = r.logRate - logSecond;
327
329 double lnRpmd = std::numeric_limits<double>::quiet_NaN();
330 double lnRpmdError = std::numeric_limits<double>::quiet_NaN();
331 if (kappaOn) {
333 ro.
s = planes.back().s;
334 ro.equilibration = o.pi_equilibration_steps;
335 ro.parents = o.pi_recrossing_parents;
336 ro.spacing = o.pi_recrossing_spacing;
337 ro.children = o.pi_recrossing_children;
338 ro.steps = std::lround(o.pi_recrossing_time / o.pi_time_step);
339 ro.ring = so.ring;
340 ro.seed = seed;
342 if (kappa.plateau > 0.0) {
343 lnRpmd = lnPerSecond + std::log(kappa.plateau);
344 lnRpmdError =
345 std::hypot(r.logRateError, kappa.plateauError / kappa.plateau);
346 } else {
348 "factor {:.4g} +- {:.2g} is not positive; ln k_RPMD "
349 "is undefined (raise pi_recrossing_parents)",
350 t, kappa.plateau, kappa.plateauError);
351 }
352 EONC_LOG_INFO(
"[Instanton] piqtst {:.4g} K: transmission factor "
353 "kappa = {:.4f} +- {:.4f} from {} trajectories, "
354 "ln(k_RPMD s) = {:.4f} +- {:.4f}",
355 t, kappa.plateau, kappa.plateauError, kappa.trajectories,
356 lnRpmd, lnRpmdError);
357 std::vector<std::string> curveFiles;
358 if (last) {
359 curveFiles.push_back("kappa_piqtst.dat");
360 }
361 if (sorted.size() > 1) {
362 curveFiles.push_back("kappa_piqtst_" + kelvinTag(t) + ".dat");
363 }
364 for (const auto &file : curveFiles) {
365 std::ofstream curve(file);
366 if (!curve) {
367 throw std::runtime_error("piqtst: cannot write " + file);
368 }
369 curve << "# t_fs kappa\n" << std::setprecision(10);
370 for (size_t i = 0; i < kappa.time.size(); ++i) {
371 curve << kappa.time[i] * timeUnit << ' ' << kappa.kappa[i] << '\n';
372 }
373 files.push_back(file);
374 }
375 }
376
377 std::vector<std::string> conFiles;
378 if (last) {
379 conFiles.push_back("piqtst_planes.con");
380 }
381 if (sorted.size() > 1) {
382 conFiles.push_back("piqtst_planes_" + kelvinTag(t) + ".con");
383 }
384 for (size_t j = 0; j < planes.size(); ++j) {
385 const Plane &p = planes[j];
386 double largest = 0.0;
387 for (const double sp : p.spread) {
388 largest = std::max(largest, sp);
389 }
390 table << t << ' ' << p.s << ' ' << p.meanForce << ' ' << p.meanForceError
391 << ' ' << p.freeEnergy << ' ' << p.freeEnergyError << ' '
392 << largest;
393 if (kappaOn) {
394 table << ' ' << kappa.plateau << ' ' << kappa.plateauError << ' '
395 << lnRpmd << ' ' << lnRpmdError;
396 }
397 table << '\n';
398 Matter frame(reactant);
400 for (long i = 0; i < c.atoms; ++i) {
401 for (int a = 0; a < 3; ++a) {
402 pos(i, a) = p.centroid(3 * i + a);
403 }
404 }
405 frame.setPositions(pos);
406 io::ConFrameMetadata meta;
407 meta.frame_index = static_cast<uint64_t>(j);
408 meta.write_con_forces = false;
409 meta.spreads = p.spread;
410 meta.scalars = {{"piqtst_temperature_K", t},
411 {"piqtst_s", p.s},
412 {"piqtst_dF_ds", p.meanForce},
413 {"piqtst_dF_ds_error", p.meanForceError},
414 {"piqtst_F", p.freeEnergy},
415 {"piqtst_F_error", p.freeEnergyError},
416 {"beads", static_cast<double>(o.pi_beads)},
417 {"spread_max", largest}};
418 for (const auto &file : conFiles) {
419 if (!
io::io_ok(frame.matter2con(file, j > 0, &meta))) {
420 throw std::runtime_error("piqtst: cannot write " + file);
421 }
422 }
423 }
424 for (const auto &file : conFiles) {
425 files.push_back(file);
426 }
427
428 const Plane &top = planes.back();
429 EONC_LOG_INFO(
"[Instanton] piqtst {:.4g} K: free-energy barrier {:.5f} "
430 "+- {:.5f} eV (classical {:.5f} eV, instanton effective "
431 "{:.5f} eV), ln(k s) = {:.4f} +- {:.4f}",
432 t, r.barrier, r.barrierError, vSaddle - vReactant, effective,
433 lnPerSecond, r.logRateError);
434 if (!(r.barrier > 0.0)) {
436 "against the lowest plane before it; s* is no barrier "
437 "on the centroid free energy",
438 t, r.barrier);
439 }
440 if (r.firstPlaneHeight < 5.0) {
442 "{:.3g} kT above the reactant minimum of F; the "
443 "reactant integral is cut there (raise "
444 "pi_reactant_extent)",
445 t, r.firstPlaneHeight);
446 }
447 if (std::abs(top.meanForce) > 3.0 * top.meanForceError) {
449 "plane is {:.4g} +- {:.2g} eV / (amu^0.5 A); the "
450 "maximum of F is not at s*",
451 t, top.meanForce, top.meanForceError);
452 }
453 if (!last) {
454 continue;
455 }
456 extras.emplace_back("piqtst_temperature_K", t);
457 extras.emplace_back("piqtst_planes", static_cast<double>(nPlanes));
458 extras.emplace_back("piqtst_beads", static_cast<double>(o.pi_beads));
459 extras.emplace_back("piqtst_s_star", sStar);
460 extras.emplace_back("piqtst_dF_ds_star", top.meanForce);
461 extras.emplace_back("piqtst_dF_ds_star_error", top.meanForceError);
462 extras.emplace_back("piqtst_first_plane_kT", r.firstPlaneHeight);
463 extras.emplace_back("barrier_piqtst", r.barrier);
464 extras.emplace_back("barrier_piqtst_error", r.barrierError);
465 extras.emplace_back("rate_piqtst", std::exp(lnPerSecond));
466 extras.emplace_back("rate_piqtst_log", lnPerSecond);
467 extras.emplace_back("rate_piqtst_log_error", r.logRateError);
468 if (kappaOn) {
469 extras.emplace_back("piqtst_kappa", kappa.plateau);
470 extras.emplace_back("piqtst_kappa_error", kappa.plateauError);
471 extras.emplace_back("rate_rpmd", std::exp(lnRpmd));
472 extras.emplace_back("rate_rpmd_log", lnRpmd);
473 extras.emplace_back("rate_rpmd_log_error", lnRpmdError);
474 }
475 }
476 return files;
477}
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
#define EONC_LOG_WARNING(...)
#define EONC_LOG_INFO(...)
const instanton_options_t & instanton_options() const
const constants_t & constants() const
constexpr bool io_ok(IoStatus s) noexcept
Recrossing recrossing(Potential &pot, const Coordinate &c, const RecrossingOptions &o)
Bennett-Chandler transmission at s*: parents sampled with the centroid held on the plane under PILE,...
std::vector< Plane > scan(Potential &pot, const Coordinate &c, const ScanOptions &o)
Samples one ring per plane and integrates the mean force.
Rate rate(const std::vector< Plane > &planes, double beta)
k = (1/2) sqrt(2 / (pi beta)) exp(-beta F(s*)) / int_{s_0}^{s*} exp(-beta F(s)) ds,...
void validateOptions(const instanton_options_t &o)
Throws std::invalid_argument on an inconsistent [Instanton] pi_* key.
constexpr double kTimeUnitSeconds
One unit of time, sqrt(amu Angstrom^2 / eV), in seconds.
constexpr double kHbar
hbar in eV^0.5 amu^0.5 Angstrom, correctly rounded from the exact SI values (h = 6....
constexpr double kBoltzmann
Boltzmann constant in eV / K, correctly rounded from the exact 1.380649e-23 J / K.
double s
The dividing plane s*, amu^0.5 Angstrom.
std::vector< double > planes
Plane positions in amu^0.5 Angstrom, ascending.