Loading...
Searching...
No Matches
RingPolymerPotential.h
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
12#pragma once
13
14#include "eon/Potential.h"
15#include "eon/Tunneling.h"
16
17#include <cmath>
18#include <stdexcept>
19#include <utility>
20
21namespace eonc::tunneling {
22
29public:
30 RingPolymerPotential(BatchPotential beads, long nBeads, long dof,
31 double spring, double energyShift,
32 std::vector<double> eta, bool fold, VectorXd modeDir);
33
34 void force(long nAtoms, const double *positions, const int *atomicNrs,
35 double *forces, double *energy, double *variance,
36 const double *box) override;
37
38 void forceBatch(long nSystems, long nAtoms, const double *const *positions,
39 const int *const *atomicNrs, double *const *forces,
40 double *energies, double *variances,
41 const double *const *boxes) override;
42
43 [[nodiscard]] bool supportsBatchEvaluation() const noexcept override {
44 return true;
45 }
46
47 [[nodiscard]] bool requiresIsolatedMoleculeLayout() const noexcept override {
48 return true;
49 }
50
53 [[nodiscard]] bool isThreadSafe() const noexcept override { return false; }
54
55 [[nodiscard]] long structureAtoms() const { return nAtoms_; }
56 [[nodiscard]] long activeBeads() const { return nActive_; }
57 void setPhysicalBath(std::shared_ptr<const PhysicalQuadraticBath> bath) {
58 if (bath && fold_)
59 throw std::invalid_argument("physical bath uses the full ring");
60 if (bath)
61 bath->validate(dof_);
62 physicalBath_ = std::move(bath);
63 }
64
65 void setDiscretization(std::vector<double> weights) {
66 if (!weights.empty()) {
67 if (fold_ || static_cast<long>(weights.size()) != nBeads_) {
68 throw std::invalid_argument(
69 "link weights require one value per full-ring bead");
70 }
71 for (double value : weights) {
72 if (!(value > 0.0) || !std::isfinite(value)) {
73 throw std::invalid_argument(
74 "link weights must be positive and finite");
75 }
76 }
77 }
78 discretization_ = std::move(weights);
79 }
80
81 void packActive(const std::vector<VectorXd> &active, double *positions) const;
82 [[nodiscard]] std::vector<VectorXd> unpack(const double *positions) const;
83 void packMode(const VectorXd &dir, AtomMatrix &mode) const;
84
85private:
86 void fixLayout(long nBeads, long dof, bool fold, const VectorXd &modeDir);
87 [[nodiscard]] double writeForces(const std::vector<VectorXd> &grad,
88 const double *positions,
89 double *forces) const;
90
92 long nBeads_{0};
93 long dof_{0};
94 long nActive_{0};
97 long nAtoms_{0};
98 double spring_{0.0};
99 double energyShift_{0.0};
100 std::vector<double> eta_;
101 std::vector<double> discretization_;
102 std::shared_ptr<const PhysicalQuadraticBath> physicalBath_;
103 bool fold_{false};
104 VectorXd modeDir_;
105};
106
107} // namespace eonc::tunneling
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
Potential(PotType a_ptype)
Production default: construction-scope registry, else PotRegistry::get().
void forceBatch(long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes) override
bool requiresIsolatedMoleculeLayout() const noexcept override
True for molecular QM / non-PBC backends (NWChem socket, ASE ORCA/NWChem, …).
double writeForces(const std::vector< VectorXd > &grad, const double *positions, double *forces) const
bool isThreadSafe() const noexcept override
The bead batch is a caller-supplied function and is not safe to enter from two threads.
void packActive(const std::vector< VectorXd > &active, double *positions) const
bool supportsBatchEvaluation() const noexcept override
Whether this potential supports batched evaluation of N systems in a single call.
std::vector< VectorXd > unpack(const double *positions) const
void packMode(const VectorXd &dir, AtomMatrix &mode) const
void force(long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box) override
void setDiscretization(std::vector< double > weights)
RingPolymerPotential(BatchPotential beads, long nBeads, long dof, double spring, double energyShift, std::vector< double > eta, bool fold, VectorXd modeDir)
void fixLayout(long nBeads, long dof, bool fold, const VectorXd &modeDir)
void setPhysicalBath(std::shared_ptr< const PhysicalQuadraticBath > bath)
std::shared_ptr< const PhysicalQuadraticBath > physicalBath_
std::function< void(const std::vector< VectorXd > &q, std::vector< double > &v, std::vector< VectorXd > &grad)> BatchPotential
V (eV) and dV/dq (eV / (amu^0.5 Angstrom)) at every point of q, all in one call so a potential can sp...
Definition Tunneling.h:238