Loading...
Searching...
No Matches
eonc::BondBoost Class Reference

Functionality relying on the conjugate gradients algorithm. More...

#include <BondBoost.h>

Public Member Functions

 BondBoost (Matter *matt, const Parameters &params)
 Constructor to be used when a structure is minimized.
 ~BondBoost ()
 Destructor.
void initialize ()
void advance ()
 Advance the equilibration / boost schedule by one MD step.
double boost ()
 Evaluate the current bias potential and write bias forces.
long scheduleStep () const
 Equilibration counter (starts at 1). Used to test the per-step schedule.

Private Member Functions

long rmdSteps () const
Matrix< double, Eigen::Dynamic, 1 > Rmdsteps ()
 Measure all tagged-atom bond lengths for the equilibration phase.
long BondSelect ()
 Select bonds within cutoff distance for boosting.
double Booststeps ()
 Compute bias potential and forces for bond-boost hyperdynamics.

Private Attributes

long nAtoms {0}
 Number of free coordinates.
Mattermatter
 Pointer to atom object outside the scope of the class.
const Parametersparameters
 Reference to a structure outside the scope of the class containing runtime parameters.
std::vector< long > BAList
std::vector< long > RAList
std::vector< long > TABAList
std::vector< long > BBAList
std::vector< double > Epsr_Q
Matrix< double, Eigen::Dynamic, 1 > TABLList
Matrix< double, Eigen::Dynamic, 1 > EBBLList
Matrix< double, Eigen::Dynamic, 1 > CBBLList
long nBAs {0}
long nRAs {0}
long nTABs {0}
long nReg {0}
long nBBs {0}
eonc::log::Scoped log

Detailed Description

Functionality relying on the conjugate gradients algorithm.

The object is capable of minimizing an Matter object or modified forces being passed in.

Definition at line 25 of file BondBoost.h.

Constructor & Destructor Documentation

◆ BondBoost()

BondBoost::BondBoost ( Matter * matt,
const Parameters & params )

Constructor to be used when a structure is minimized.

Parameters
[in]*matterPointer to the Matter object to be relaxed.
[in]parametersReference to the Parameter object containing the runtime parameters.

Definition at line 25 of file BondBoost.cpp.

26 : matter{matt},
27 parameters{params} {
28 nAtoms = matter->numberOfAtoms();
29}
const Parameters & parameters
Reference to a structure outside the scope of the class containing runtime parameters.
Definition BondBoost.h:53
Matter * matter
Pointer to atom object outside the scope of the class.
Definition BondBoost.h:51
long nAtoms
Number of free coordinates.
Definition BondBoost.h:50

◆ ~BondBoost()

BondBoost::~BondBoost ( )
default

Destructor.

Member Function Documentation

◆ advance()

void BondBoost::advance ( )

Advance the equilibration / boost schedule by one MD step.

Call once per physical step. boost() does not move the schedule.

Definition at line 92 of file BondBoost.cpp.

92 {
93 const long RMDS = rmdSteps();
94 if (nReg <= RMDS) {
95 // Equilibration: sample bond lengths once per MD step.
96 Matrix<double, Eigen::Dynamic, 1> TABL_tmp = Rmdsteps();
97 TABLList = TABLList + (1.0 / RMDS) * TABL_tmp;
98 nReg++;
99 if (nReg == RMDS + 1) {
100 nBBs = BondSelect();
101 }
102 return;
103 }
104 if (nReg == RMDS + 1) {
105 nBBs = BondSelect();
106 }
107 nReg++;
108}
long BondSelect()
Select bonds within cutoff distance for boosting.
Matrix< double, Eigen::Dynamic, 1 > Rmdsteps()
Measure all tagged-atom bond lengths for the equilibration phase.
Matrix< double, Eigen::Dynamic, 1 > TABLList
Definition BondBoost.h:61
long rmdSteps() const
Definition BondBoost.cpp:87

◆ BondSelect()

long BondBoost::BondSelect ( )
private

Select bonds within cutoff distance for boosting.

Definition at line 240 of file BondBoost.cpp.

240 {
241 const double qCutoff = parameters.hyperdynamics_options.qcut;
242
243 // Count bonds within cutoff
244 long nSelected = 0;
245 for (long i = 0; i < nTABs; i++) {
246 if (TABLList(i, 0) <= qCutoff) {
247 nSelected++;
248 }
249 }
250
251 EBBLList.setZero(nSelected, 1);
252 BBAList.resize(2 * nSelected);
253 long count = 0;
254 for (long i = 0; i < nTABs; i++) {
255 if (TABLList(i, 0) <= qCutoff) {
256 EBBLList(count, 0) = TABLList(i, 0);
257 BBAList[2 * count] = TABAList[2 * i];
258 BBAList[2 * count + 1] = TABAList[2 * i + 1];
259 count++;
260 }
261 }
262 return nSelected;
263}
Matrix< double, Eigen::Dynamic, 1 > EBBLList
Definition BondBoost.h:62
std::vector< long > BBAList
Definition BondBoost.h:58
std::vector< long > TABAList
Definition BondBoost.h:57

◆ boost()

double BondBoost::boost ( )

Evaluate the current bias potential and write bias forces.

Safe to call from a force evaluation; does not increment nReg.

Definition at line 110 of file BondBoost.cpp.

110 {
111 const long RMDS = rmdSteps();
112 if (nReg <= RMDS) {
113 return 0.0;
114 }
115 // RMDS == 0 and a caller that never advance()s still has to select bonds
116 // on the first evaluation; SafeHyper / ParallelReplica call advance()
117 // first and reach BondSelect there.
118 if (nBBs == 0) {
119 nBBs = BondSelect();
120 }
121 Epsr_Q.resize(nBBs);
122 CBBLList.setZero(nBBs, 1);
123 const double biasPot = Booststeps();
124 Epsr_Q.clear();
125 return biasPot;
126}
double Booststeps()
Compute bias potential and forces for bond-boost hyperdynamics.
std::vector< double > Epsr_Q
Definition BondBoost.h:59
Matrix< double, Eigen::Dynamic, 1 > CBBLList
Definition BondBoost.h:63

◆ Booststeps()

double BondBoost::Booststeps ( )
private

Compute bias potential and forces for bond-boost hyperdynamics.

Returns the bias potential energy contribution.

Definition at line 130 of file BondBoost.cpp.

130 {
131 const double QRR = parameters.hyperdynamics_options.qrr;
132 const double PRR = parameters.hyperdynamics_options.prr;
133 const double DVMAX = parameters.hyperdynamics_options.dvmax;
134 const double nBBsD = static_cast<double>(nBBs);
135
136 AtomMatrix addForces(nBBs, 3);
137 AtomMatrix TADF(nAtoms, 3);
138 addForces.setZero();
139 TADF.setZero();
140
141 // Measure current bond lengths
142 for (long i = 0; i < nBBs; i++) {
143 CBBLList(i, 0) = matter->distance(BBAList[2 * i], BBAList[2 * i + 1]);
144 }
145
146 // Compute strain parameters and find maximum
147 double epsrMax = 0.0;
148 for (long i = 0; i < nBBs; i++) {
149 Epsr_Q[i] = (CBBLList(i, 0) - EBBLList(i, 0)) / EBBLList(i, 0) / QRR;
150 if (std::abs(Epsr_Q[i]) >= epsrMax) {
151 epsrMax = std::abs(Epsr_Q[i]);
152 }
153 }
154
155 // Envelope function A(eps_max)
156 double A_eps = (1.0 - epsrMax * epsrMax) * (1.0 - epsrMax * epsrMax) /
157 (1.0 - PRR * PRR * epsrMax * epsrMax);
158
159 // Sum of individual bias potentials
160 double sumV = 0.0;
161 if (epsrMax < 1.0) {
162 for (long i = 0; i < nBBs; i++) {
163 sumV += DVMAX * (1.0 - Epsr_Q[i] * Epsr_Q[i]) / nBBsD;
164 }
165 } else {
166 A_eps = 0.0;
167 }
168
169 double boostFact = A_eps * sumV;
170
171 // Compute bias forces per bond, accumulate on atoms
172 for (long i = 0; i < nBBs; i++) {
173 double dforce = 0.0;
174 double fact1 =
175 2.0 * A_eps * DVMAX * Epsr_Q[i] / QRR / EBBLList(i, 0) / nBBsD;
176
177 if (std::abs(Epsr_Q[i]) < epsrMax) {
178 dforce = fact1;
179 } else {
180 // Bond at maximum strain: additional envelope derivative
181 double fTmp1 = 1.0 - PRR * PRR * Epsr_Q[i] * Epsr_Q[i];
182 double fTmp2 = 1.0 - Epsr_Q[i] * Epsr_Q[i];
183 double fact2 = 2.0 * fTmp2 * Epsr_Q[i] *
184 (2.0 * fTmp1 - PRR * PRR * fTmp2) / QRR / EBBLList(i, 0) /
185 fTmp1 / fTmp1;
186 dforce = fact1 + sumV * fact2;
187 }
188
189 long a1 = BBAList[2 * i];
190 long a2 = BBAList[2 * i + 1];
191 double R = CBBLList(i, 0);
192
193 for (int j = 0; j < 3; j++) {
194 double rij = matter->pdistance(a1, a2, j);
195 double fij = rij / R * dforce;
196 addForces(i, j) = fij;
197 TADF(a1, j) += fij;
198 TADF(a2, j) -= fij;
199 }
200 }
201
202 // Apply free-atom mask and set bias forces
203 AtomMatrix biasForces = TADF.array() * matter->getFree().array();
204 matter->setBiasForces(biasForces);
205 return boostFact;
206}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37

◆ initialize()

void BondBoost::initialize ( )

Definition at line 33 of file BondBoost.cpp.

33 {
34 nBBs = 0;
35 nReg = 1;
36
37 const std::string &balString =
38 parameters.hyperdynamics_options.boost_atom_list;
39 auto atoms = eonc::helpers::split_string_int(balString, ",");
40
41 if (balString == "all" || atoms.empty()) {
42 QUILL_LOG_DEBUG(log, "boost all atoms that are set free\n");
43 nBAs = matter->numberOfFreeAtoms();
44 nRAs = nAtoms - nBAs;
45 BAList.resize(nBAs);
46 RAList.resize(nRAs);
47 long k = 0;
48 for (long i = 0; i < nAtoms; i++) {
49 if (!matter->getFixed(i)) {
50 BAList[k++] = i;
51 }
52 }
53 } else {
54 QUILL_LOG_DEBUG(log, "boost the following selected atoms:");
55 for (size_t i = 0; i < atoms.size(); i++) {
56 QUILL_LOG_DEBUG(log, "{} ", atoms[i]);
57 }
58 QUILL_LOG_DEBUG(log, "\n");
59 nBAs = static_cast<long>(atoms.size());
60 nRAs = nAtoms - nBAs;
61 BAList.resize(nBAs);
62 RAList.resize(nRAs);
63 for (long i = 0; i < nBAs; i++) {
64 BAList[i] = atoms[i];
65 }
66 }
67
68 // Build rest-atoms list (atoms not in BAList)
69 long count = 0;
70 for (long i = 0; i < nAtoms; i++) {
71 bool isBoosted = std::any_of(BAList.begin(), BAList.end(),
72 [i](long ba) { return ba == i; });
73 if (!isBoosted) {
74 RAList[count++] = i;
75 }
76 }
77 if (count != nRAs) {
78 QUILL_LOG_DEBUG(log, "Error: nRestAtoms does not equal counted number!\n");
79 }
80
81 nTABs = nBAs * (nBAs - 1) / 2 + nBAs * nRAs;
82 TABAList.resize(2 * nTABs);
83 TABLList.setZero(nTABs, 1);
84 QUILL_LOG_DEBUG(log, "BondBoost Used !\n");
85}
eonc::log::Scoped log
Definition BondBoost.h:69
std::vector< long > BAList
Definition BondBoost.h:55
std::vector< long > RAList
Definition BondBoost.h:56
std::vector< int > split_string_int(std::string s, std::string delim)

◆ Rmdsteps()

Matrix< double, Eigen::Dynamic, 1 > BondBoost::Rmdsteps ( )
private

Measure all tagged-atom bond lengths for the equilibration phase.

Definition at line 209 of file BondBoost.cpp.

209 {
210 Matrix<double, Eigen::Dynamic, 1> bondLengths(nTABs, 1);
211 long count = 0;
212
213 // Boost-atom pairs
214 for (long i = 0; i < nBAs; i++) {
215 for (long j = i + 1; j < nBAs; j++) {
216 bondLengths(count, 0) = matter->distance(BAList[i], BAList[j]);
217 TABAList[2 * count] = BAList[i];
218 TABAList[2 * count + 1] = BAList[j];
219 count++;
220 }
221 }
222
223 // Boost-atom to rest-atom pairs
224 for (long i = 0; i < nBAs; i++) {
225 for (long j = 0; j < nRAs; j++) {
226 bondLengths(count, 0) = matter->distance(BAList[i], RAList[j]);
227 TABAList[2 * count] = BAList[i];
228 TABAList[2 * count + 1] = RAList[j];
229 count++;
230 }
231 }
232
233 if (count != nTABs) {
234 QUILL_LOG_DEBUG(log, "Total involved bond count does not match expected\n");
235 }
236 return bondLengths;
237}

◆ rmdSteps()

long BondBoost::rmdSteps ( ) const
private

Definition at line 87 of file BondBoost.cpp.

87 {
88 return static_cast<long>(parameters.hyperdynamics_options.rmd_time /
89 parameters.dynamics_options.time_step);
90}

◆ scheduleStep()

long eonc::BondBoost::scheduleStep ( ) const
inlinenodiscard

Equilibration counter (starts at 1). Used to test the per-step schedule.

Definition at line 43 of file BondBoost.h.

43{ return nReg; }

Member Data Documentation

◆ BAList

std::vector<long> eonc::BondBoost::BAList
private

Definition at line 55 of file BondBoost.h.

◆ BBAList

std::vector<long> eonc::BondBoost::BBAList
private

Definition at line 58 of file BondBoost.h.

◆ CBBLList

Matrix<double, Eigen::Dynamic, 1> eonc::BondBoost::CBBLList
private

Definition at line 63 of file BondBoost.h.

◆ EBBLList

Matrix<double, Eigen::Dynamic, 1> eonc::BondBoost::EBBLList
private

Definition at line 62 of file BondBoost.h.

◆ Epsr_Q

std::vector<double> eonc::BondBoost::Epsr_Q
private

Definition at line 59 of file BondBoost.h.

◆ log

eonc::log::Scoped eonc::BondBoost::log
private

Definition at line 69 of file BondBoost.h.

◆ matter

Matter* eonc::BondBoost::matter
private
Initial value:
{
nullptr}

Pointer to atom object outside the scope of the class.

Definition at line 51 of file BondBoost.h.

51 {
52 nullptr};

◆ nAtoms

long eonc::BondBoost::nAtoms {0}
private

Number of free coordinates.

Definition at line 50 of file BondBoost.h.

50{0};

◆ nBAs

long eonc::BondBoost::nBAs {0}
private

Definition at line 64 of file BondBoost.h.

64{0};

◆ nBBs

long eonc::BondBoost::nBBs {0}
private

Definition at line 68 of file BondBoost.h.

68{0};

◆ nRAs

long eonc::BondBoost::nRAs {0}
private

Definition at line 65 of file BondBoost.h.

65{0};

◆ nReg

long eonc::BondBoost::nReg {0}
private

Definition at line 67 of file BondBoost.h.

67{0};

◆ nTABs

long eonc::BondBoost::nTABs {0}
private

Definition at line 66 of file BondBoost.h.

66{0};

◆ parameters

const Parameters& eonc::BondBoost::parameters
private

Reference to a structure outside the scope of the class containing runtime parameters.

Definition at line 53 of file BondBoost.h.

◆ RAList

std::vector<long> eonc::BondBoost::RAList
private

Definition at line 56 of file BondBoost.h.

◆ TABAList

std::vector<long> eonc::BondBoost::TABAList
private

Definition at line 57 of file BondBoost.h.

◆ TABLList

Matrix<double, Eigen::Dynamic, 1> eonc::BondBoost::TABLList
private

Definition at line 61 of file BondBoost.h.


The documentation for this class was generated from the following files: