Loading...
Searching...
No Matches
eonc::piqtst Namespace Reference

Classes

struct  Coordinate
 The coordinate s = n . More...
struct  Plane
struct  Rate
struct  Recrossing
struct  RecrossingOptions
struct  ScanOptions

Functions

void integrate (std::vector< Plane > &planes)
 Trapezoid integral of the mean forces, F(s_0) = 0, with errors from independent planes.
std::vector< Plane > scan (Potential &pot, const Coordinate &coordinate, const ScanOptions &options)
 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, the mass-weighted coordinate carrying unit mass, beta in 1 / eV.
Recrossing recrossing (Potential &pot, const Coordinate &coordinate, const RecrossingOptions &options)
 Bennett-Chandler transmission at s*: parents sampled with the centroid held on the plane under PILE, whatever ring.thermostat says, children with Maxwell-Boltzmann ring momenta at beta / P and the plane released, propagated by RPMD.
void validateOptions (const instanton_options_t &o)
 Throws std::invalid_argument on an inconsistent [Instanton] pi_* key.
std::vector< std::string > runAfterInstanton (const Parameters &params, Potential &pot, const Matter &reactant, const Matter &saddle, const MatrixXd &hSaddle, const std::vector< VectorXd > &pathQ, const std::vector< double > &temperatures, std::vector< std::pair< std::string, double > > &extras)
 [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.

Function Documentation

◆ integrate()

void eonc::piqtst::integrate ( std::vector< Plane > & planes)

Trapezoid integral of the mean forces, F(s_0) = 0, with errors from independent planes.

Fills freeEnergy and freeEnergyError.

Definition at line 86 of file PIQTST.cpp.

86 {
87 if (planes.empty()) {
88 return;
89 }
90 const MatrixXd w = trapezoidWeights(planes);
91 VectorXd f(static_cast<long>(planes.size()));
92 for (size_t i = 0; i < planes.size(); ++i) {
93 f(static_cast<long>(i)) = planes[i].meanForce;
94 }
95 const VectorXd errors = forceErrors(planes);
96 const VectorXd values = w * f;
97 for (size_t j = 0; j < planes.size(); ++j) {
98 planes[j].freeEnergy = values(static_cast<long>(j));
99 planes[j].freeEnergyError =
100 propagated(w.row(static_cast<long>(j)).transpose(), errors);
101 }
102}
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, eOnStorageOrder > MatrixXd
Definition Eigen.h:33

◆ rate()

Rate eonc::piqtst::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, the mass-weighted coordinate carrying unit mass, beta in 1 / eV.

The integral is the trapezoid rule over the planes; the last is s*.

Definition at line 213 of file PIQTST.cpp.

213 {
214 const long n = static_cast<long>(planes.size());
215 if (n < 2) {
216 throw std::invalid_argument("piqtst: the rate needs two planes");
217 }
218 if (!(beta > 0.0)) {
219 throw std::invalid_argument("piqtst: the rate needs a positive beta");
220 }
221 const MatrixXd w = trapezoidWeights(planes);
222 const VectorXd errors = forceErrors(planes);
223 Rate r;
224 // The reactant is the lowest F before the dividing plane; s* itself is
225 // the top, and a minimum there is a plane that is no barrier, which the
226 // barrier's sign then shows.
227 const long top = n - 1;
228 double fMin = std::numeric_limits<double>::infinity();
229 for (long j = 0; j < top; ++j) {
230 const double f = planes[static_cast<size_t>(j)].freeEnergy;
231 if (f < fMin) {
232 fMin = f;
233 r.reactant = j;
234 }
235 }
236 const double fTop = planes[static_cast<size_t>(top)].freeEnergy;
237 r.barrier = fTop - fMin;
238 r.barrierError =
239 propagated((w.row(top) - w.row(r.reactant)).transpose(), errors);
240 r.firstPlaneHeight = beta * (planes.front().freeEnergy - fMin);
241
242 // Z = int exp(-beta F) ds by the trapezoid rule, referenced to fMin.
243 VectorXd weight(n);
244 double z = 0.0;
245 for (long j = 0; j < n; ++j) {
246 const double left = j > 0 ? planes[static_cast<size_t>(j)].s -
247 planes[static_cast<size_t>(j - 1)].s
248 : 0.0;
249 const double right = j + 1 < n ? planes[static_cast<size_t>(j + 1)].s -
250 planes[static_cast<size_t>(j)].s
251 : 0.0;
252 weight(j) =
253 0.5 * (left + right) *
254 std::exp(-beta * (planes[static_cast<size_t>(j)].freeEnergy - fMin));
255 z += weight(j);
256 }
257 weight /= z;
258 r.logRate = std::log(0.5 * std::sqrt(2.0 / (std::numbers::pi * beta))) -
259 beta * (fTop - fMin) - std::log(z);
260 const VectorXd gradient =
261 -beta * w.row(top).transpose() + beta * (w.transpose() * weight);
262 r.logRateError = propagated(gradient, errors);
263 return r;
264}

◆ recrossing()

Recrossing eonc::piqtst::recrossing ( Potential & pot,
const Coordinate & coordinate,
const RecrossingOptions & options )

Bennett-Chandler transmission at s*: parents sampled with the centroid held on the plane under PILE, whatever ring.thermostat says, children with Maxwell-Boltzmann ring momenta at beta / P and the plane released, propagated by RPMD.

The centroid velocity along s is sdot = n . M^(1/2) v_centroid. Each child run costs steps + 1 force batches: the first force at the parent's beads, then one per step.

Definition at line 266 of file PIQTST.cpp.

267 {
268 const long dof = 3 * c.atoms;
269 const Axes ax = axes(c);
270 if (o.parents < 2 || o.children < 1 || o.spacing < 1 || o.steps < 4 ||
271 o.equilibration < 0) {
272 throw std::invalid_argument(
273 "piqtst: recrossing needs two parents, one child, a positive "
274 "spacing and four steps");
275 }
276 const VectorXd origin = c.reference + o.s * ax.b;
277 VectorXd start = origin;
278 if (o.seed) {
279 start = o.seed(o.s);
280 if (start.size() != dof) {
281 throw std::invalid_argument("piqtst: a seed has the wrong length");
282 }
283 }
284 // Bennett-Chandler needs parents from the ring polymer's own constrained
285 // Boltzmann distribution. PIGLET's coloured noise samples another one,
286 // tuned for bead averages, so the parents always take PILE.
287 pathintegral::Options parentOptions = o.ring;
288 parentOptions.thermostat = pathintegral::Thermostat::Pile;
289 parentOptions.gleFile.clear();
290 pathintegral::RingPolymer parent(c.atoms, c.masses, c.numbers, c.free,
291 parentOptions);
292 parent.setAllBeads(start.data());
293 parent.setHyperplane(ax.a, origin);
294 for (long step = 0; step < o.equilibration; ++step) {
295 parent.step(pot, c.box, false);
296 }
297
298 // The children draw every normal mode from the free-ring Boltzmann
299 // distribution at beta / P, which PILE's initial momenta are, and carry
300 // their own stream so parent and child noise stay independent.
301 pathintegral::Options childOptions = o.ring;
302 childOptions.thermostat = pathintegral::Thermostat::Pile;
303 childOptions.gleFile.clear();
304 childOptions.seed = o.ring.seed + 0x9E3779B97F4A7C15ULL;
305 pathintegral::RingPolymer child(c.atoms, c.masses, c.numbers, c.free,
306 childOptions);
307
308 const long n = o.steps + 1;
309 // Per parent: sum over children of sdot(0) h(s(t) - s*) at each time,
310 // and of sdot(0) h(sdot(0)).
311 std::vector<VectorXd> numerator(static_cast<size_t>(o.parents),
312 VectorXd::Zero(n));
313 std::vector<double> denominator(static_cast<size_t>(o.parents), 0.0);
314 Recrossing out;
315 for (long p = 0; p < o.parents; ++p) {
316 for (long step = 0; step < o.spacing; ++step) {
317 parent.step(pot, c.box, false);
318 }
319 const std::vector<VectorXd> beads = parent.beads();
320 VectorXd &num = numerator[static_cast<size_t>(p)];
321 double &den = denominator[static_cast<size_t>(p)];
322 for (long k = 0; k < o.children; ++k) {
323 child.setBeads(beads);
324 child.thermalMomenta();
325 std::vector<VectorXd> reversed = child.momenta();
326 const double forward = ax.a.dot(child.centroidVelocity());
327 for (int sign = 0; sign < 2; ++sign) {
328 if (sign == 1) {
329 for (auto &v : reversed) {
330 v = -v;
331 }
332 child.setBeads(beads);
333 child.setMomenta(reversed);
334 }
335 const double sdot = sign == 0 ? forward : -forward;
336 const double flux = sdot > 0.0 ? sdot : 0.0;
337 den += flux;
338 num(0) += flux;
339 for (long i = 1; i < n; ++i) {
340 child.nveStep(pot, c.box);
341 const double s = ax.a.dot(child.centroid() - c.reference);
342 if (s > o.s) {
343 num(i) += sdot;
344 }
345 }
346 ++out.trajectories;
347 }
348 }
349 }
350
351 VectorXd total = VectorXd::Zero(n);
352 double totalDen = 0.0;
353 for (long p = 0; p < o.parents; ++p) {
354 total += numerator[static_cast<size_t>(p)];
355 totalDen += denominator[static_cast<size_t>(p)];
356 }
357 if (!(totalDen > 0.0)) {
358 throw std::runtime_error("piqtst: no child left the plane forward");
359 }
360 out.time.resize(static_cast<size_t>(n));
361 out.kappa.resize(static_cast<size_t>(n));
362 for (long i = 0; i < n; ++i) {
363 out.time[static_cast<size_t>(i)] = static_cast<double>(i) * o.ring.dt;
364 out.kappa[static_cast<size_t>(i)] = total(i) / totalDen;
365 }
366
367 // Plateau numerators per parent, averaged over the last quarter, and the
368 // leave-one-parent-out ratios.
369 const long first = n - 1 - o.steps / 4;
370 const double span = static_cast<double>(n - first);
371 std::vector<double> plateauNum(static_cast<size_t>(o.parents), 0.0);
372 double sumNum = 0.0;
373 for (long p = 0; p < o.parents; ++p) {
374 plateauNum[static_cast<size_t>(p)] =
375 numerator[static_cast<size_t>(p)].tail(n - first).sum() / span;
376 sumNum += plateauNum[static_cast<size_t>(p)];
377 }
378 out.plateau = sumNum / totalDen;
379 const double np = static_cast<double>(o.parents);
380 std::vector<double> leaveOut(static_cast<size_t>(o.parents), 0.0);
381 double meanLeave = 0.0;
382 for (long p = 0; p < o.parents; ++p) {
383 leaveOut[static_cast<size_t>(p)] =
384 (sumNum - plateauNum[static_cast<size_t>(p)]) /
385 (totalDen - denominator[static_cast<size_t>(p)]);
386 meanLeave += leaveOut[static_cast<size_t>(p)];
387 }
388 meanLeave /= np;
389 double var = 0.0;
390 for (const double v : leaveOut) {
391 var += (v - meanLeave) * (v - meanLeave);
392 }
393 out.plateauError = std::sqrt((np - 1.0) / np * var);
394 out.batches = parent.batches() + child.batches();
395 return out;
396}

◆ runAfterInstanton()

std::vector< std::string > eonc::piqtst::runAfterInstanton ( const Parameters & params,
Potential & pot,
const Matter & reactant,
const Matter & saddle,
const MatrixXd & hSaddle,
const std::vector< VectorXd > & pathQ,
const std::vector< double > & temperatures,
std::vector< std::pair< std::string, double > > & extras )

[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.

Definition at line 167 of file PIQTSTJob.cpp.

171 {
172 const auto &o = params.instanton_options();
174 const double timeUnit = params.constants().timeUnit;
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 // The plane normal. The saddle's unstable mode is the dividing surface
184 // the rate is evaluated on; one normal for every plane keeps s a linear
185 // coordinate, so the mean force integrates to its free energy.
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 {
200 EONC_LOG_WARNING("[Instanton] piqtst: the unstable mode makes {:.3f} "
201 "rad with the reactant-saddle line; planes follow "
202 "the line",
203 std::acos(v.dot(lineDir)));
204 }
205 } else {
206 EONC_LOG_WARNING("[Instanton] piqtst: the saddle Hessian has no "
207 "negative eigenvalue; planes follow the line");
208 }
209 }
210 if (emb.freeAtoms.size() == static_cast<size_t>(reactant.numberOfAtoms()) &&
211 !reactant.getPeriodic()) {
212 EONC_LOG_WARNING("[Instanton] piqtst: no atom is fixed; the planes are "
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
225 Coordinate c;
226 c.atoms = reactant.numberOfAtoms();
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);
242 const Matrix3d cell =
243 reactant.getPeriodic() ? reactant.getCell() : Matrix3d::Zero().eval();
244 c.box = cell.data();
245
246 // Seeds: the band where it crosses the plane, else the straight line
247 // through the reactant and the saddle.
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") {
286 EONC_LOG_WARNING("[Instanton] piqtst: the transmission factor's parents "
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<>());
301 const double logSecond = std::log(tunneling::kTimeUnitSeconds);
302 for (size_t ti = 0; ti < sorted.size(); ++ti) {
303 const double t = sorted[ti];
304 const bool last = ti + 1 == sorted.size();
305 const double beta = 1.0 / (tunneling::kBoltzmann * t);
306 ScanOptions so;
307 so.planes = sPlanes;
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;
313 so.ring.kB = tunneling::kBoltzmann;
314 so.ring.hbar = tunneling::kHbar;
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);
325 const Rate r = rate(planes, beta);
326 const double lnPerSecond = r.logRate - logSecond;
327
328 Recrossing kappa;
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;
341 kappa = recrossing(pot, c, ro);
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 {
347 EONC_LOG_WARNING("[Instanton] piqtst {:.4g} K: the transmission "
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);
399 AtomMatrix pos = frame.getPositions();
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)) {
435 EONC_LOG_WARNING("[Instanton] piqtst {:.4g} K: F(s*) is {:.4g} eV "
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) {
441 EONC_LOG_WARNING("[Instanton] piqtst {:.4g} K: the first plane is "
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) {
448 EONC_LOG_WARNING("[Instanton] piqtst {:.4g} K: dF/ds at the saddle "
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
Definition Eigen.h:35
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
#define EONC_LOG_WARNING(...)
Definition EonLogger.h:322
#define EONC_LOG_INFO(...)
Definition EonLogger.h:316
const instanton_options_t & instanton_options() const
const constants_t & constants() const
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
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,...
Definition PIQTST.cpp:266
std::vector< Plane > scan(Potential &pot, const Coordinate &c, const ScanOptions &o)
Samples one ring per plane and integrates the mean force.
Definition PIQTST.cpp:104
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,...
Definition PIQTST.cpp:213
void validateOptions(const instanton_options_t &o)
Throws std::invalid_argument on an inconsistent [Instanton] pi_* key.
Definition PIQTSTJob.cpp:31
constexpr long reactant
constexpr double kTimeUnitSeconds
One unit of time, sqrt(amu Angstrom^2 / eV), in seconds.
Definition Tunneling.h:350
constexpr double kHbar
hbar in eV^0.5 amu^0.5 Angstrom, correctly rounded from the exact SI values (h = 6....
Definition Tunneling.h:39
constexpr double kBoltzmann
Boltzmann constant in eV / K, correctly rounded from the exact 1.380649e-23 J / K.
Definition Tunneling.h:43
The coordinate s = n .
Definition PIQTST.h:42
double s
The dividing plane s*, amu^0.5 Angstrom.
Definition PIQTST.h:125
std::vector< double > planes
Plane positions in amu^0.5 Angstrom, ascending.
Definition PIQTST.h:55

◆ scan()

std::vector< Plane > eonc::piqtst::scan ( Potential & pot,
const Coordinate & coordinate,
const ScanOptions & options )

Samples one ring per plane and integrates the mean force.

One ring is carried from plane to plane: its centroid moves to the next seed and the internal modes keep their state. A step is one force batch over the beads; moving to a plane costs one more, so a plane takes equilibration + production + 1.

Definition at line 104 of file PIQTST.cpp.

105 {
106 const long dof = 3 * c.atoms;
107 const Axes ax = axes(c);
108 const VectorXd &a = ax.a;
109 const VectorXd &b = ax.b;
110 if (o.planes.size() < 2) {
111 throw std::invalid_argument("piqtst: at least two planes are needed");
112 }
113 for (size_t j = 1; j < o.planes.size(); ++j) {
114 if (!(o.planes[j] > o.planes[j - 1])) {
115 throw std::invalid_argument("piqtst: plane positions must ascend");
116 }
117 }
118 if (o.equilibration < 0 || o.production < 2 || o.blocks < 2 ||
119 o.production < o.blocks) {
120 throw std::invalid_argument(
121 "piqtst: sampling needs at least as many steps as blocks, and two "
122 "blocks");
123 }
124 const double aNorm = a.norm();
125 auto seedAt = [&](double s) -> VectorXd {
126 if (o.seed) {
127 VectorXd x = o.seed(s);
128 if (x.size() != dof) {
129 throw std::invalid_argument("piqtst: a seed has the wrong length");
130 }
131 return x;
132 }
133 return c.reference + s * b;
134 };
135
136 pathintegral::RingPolymer ring(c.atoms, c.masses, c.numbers, c.free, o.ring);
137 const long beads = o.ring.beads;
138 const long blockSize = o.production / o.blocks;
139 std::vector<Plane> out;
140 out.reserve(o.planes.size());
141 for (size_t j = 0; j < o.planes.size(); ++j) {
142 const double s = o.planes[j];
143 const VectorXd origin = c.reference + s * b;
144 const VectorXd target = seedAt(s);
145 if (j == 0) {
146 ring.setAllBeads(target.data());
147 } else {
148 const VectorXd shift = target - ring.centroid();
149 std::vector<VectorXd> moved = ring.beads();
150 for (auto &q : moved) {
151 q += shift;
152 }
153 ring.setBeads(moved);
154 }
155 ring.setHyperplane(a, origin);
156
157 const long batches0 = ring.batches();
158 for (long step = 0; step < o.equilibration; ++step) {
159 ring.step(pot, c.box, false);
160 }
161 Plane plane;
162 plane.s = s;
163 plane.centroid = VectorXd::Zero(dof);
164 VectorXd spread2 = VectorXd::Zero(dof);
165 double sum = 0.0;
166 double blockSum = 0.0;
167 std::vector<double> blockMeans;
168 for (long step = 0; step < o.production; ++step) {
169 ring.resetAverages();
170 ring.step(pot, c.box, true);
171 const double fn = ring.meanForce();
172 sum += fn;
173 blockSum += fn;
174 if ((step + 1) % blockSize == 0 &&
175 static_cast<long>(blockMeans.size()) < o.blocks) {
176 blockMeans.push_back(blockSum / static_cast<double>(blockSize));
177 blockSum = 0.0;
178 }
179 const VectorXd centroid = ring.centroid();
180 plane.centroid += centroid;
181 for (const auto &q : ring.beads()) {
182 spread2 += (q - centroid).cwiseAbs2();
183 }
184 }
185 const double steps = static_cast<double>(o.production);
186 plane.centroid /= steps;
187 spread2 /= steps * static_cast<double>(beads);
188 plane.spread.resize(static_cast<size_t>(dof));
189 for (long i = 0; i < dof; ++i) {
190 plane.spread[static_cast<size_t>(i)] = std::sqrt(spread2(i));
191 }
192 const double mean = sum / steps;
193 double blockMean = 0.0;
194 for (const double m : blockMeans) {
195 blockMean += m;
196 }
197 const double nb = static_cast<double>(blockMeans.size());
198 blockMean /= nb;
199 double var = 0.0;
200 for (const double m : blockMeans) {
201 var += (m - blockMean) * (m - blockMean);
202 }
203 var /= nb * (nb - 1.0);
204 plane.meanForce = -mean / aNorm;
205 plane.meanForceError = std::sqrt(var) / aNorm;
206 plane.batches = ring.batches() - batches0;
207 out.push_back(std::move(plane));
208 }
209 integrate(out);
210 return out;
211}
double sum(const double *x, std::size_t n)
Round-to-nearest-even value of the exact sum of x[i].
void integrate(std::vector< Plane > &planes)
Trapezoid integral of the mean forces, F(s_0) = 0, with errors from independent planes.
Definition PIQTST.cpp:86

◆ validateOptions()

void eonc::piqtst::validateOptions ( const instanton_options_t & o)

Throws std::invalid_argument on an inconsistent [Instanton] pi_* key.

Definition at line 31 of file PIQTSTJob.cpp.

31 {
32 if (o.pi_planes < 0) {
33 throw std::invalid_argument("[Instanton] pi_planes must not be negative");
34 }
35 if (o.pi_planes == 0) {
36 return;
37 }
38 if (o.mode != "rate") {
39 throw std::invalid_argument("[Instanton] pi_planes needs mode = rate");
40 }
41 if (o.pi_planes < 2) {
42 throw std::invalid_argument(
43 "[Instanton] pi_planes must be 0 or at least 2");
44 }
45 if (o.pi_beads < 1) {
46 throw std::invalid_argument("[Instanton] pi_beads must be positive");
47 }
48 if (o.pi_equilibration_steps < 0 || o.pi_sampling_steps < 20) {
49 throw std::invalid_argument(
50 "[Instanton] pi_equilibration_steps must not be negative and "
51 "pi_sampling_steps must be at least 20 (ten blocks of two)");
52 }
53 if (!(o.pi_time_step > 0.0) || !(o.pi_pile_tau > 0.0) ||
54 !(o.pi_pile_scale > 0.0)) {
55 throw std::invalid_argument("[Instanton] pi_time_step, pi_pile_tau and "
56 "pi_pile_scale must be positive");
57 }
58 if (o.pi_seed < 0) {
59 throw std::invalid_argument("[Instanton] pi_seed must not be negative");
60 }
61 if (o.pi_thermostat != "pile" && o.pi_thermostat != "piglet") {
62 throw std::invalid_argument(
63 "[Instanton] pi_thermostat must be pile or piglet, not " +
65 }
66 if (o.pi_thermostat == "piglet" && o.pi_beads > 1 && o.pi_gle_file.empty()) {
67 throw std::invalid_argument(
68 "[Instanton] pi_thermostat = piglet needs pi_gle_file");
69 }
70 if (o.pi_direction != "mode" && o.pi_direction != "line") {
71 throw std::invalid_argument(
72 "[Instanton] pi_direction must be mode or line, not " + o.pi_direction);
73 }
74 if (!(o.pi_reactant_extent >= 0.0)) {
75 throw std::invalid_argument(
76 "[Instanton] pi_reactant_extent must not be negative");
77 }
78 if (o.pi_recrossing_parents < 0 || o.pi_recrossing_parents == 1) {
79 throw std::invalid_argument(
80 "[Instanton] pi_recrossing_parents must be 0 or at least 2");
81 }
82 if (o.pi_recrossing_parents == 0) {
83 return;
84 }
86 throw std::invalid_argument("[Instanton] pi_recrossing_children and "
87 "pi_recrossing_spacing must be positive");
88 }
89 if (!(o.pi_recrossing_time >= 4.0 * o.pi_time_step)) {
90 throw std::invalid_argument(
91 "[Instanton] pi_recrossing_time must be at least four pi_time_step");
92 }
93}