79 {
81
82 eonc::safemath::safe_normalize_inplace(initialDirection);
84
85
86
89 static_cast<quill::Logger *
>(
log))) {
94 eonc::safemath::safe_normalize_inplace(
direction);
95 for (
long i = 0; i <
nAtoms; ++i) {
98 }
99 }
101 return;
102 }
103
104 long rotations = 0;
106 long forceCallsDimer =
matterDimer->getForceCalls();
107 double curvature = 0.0;
108 double rotationAngle = 0.0;
109 double torque = 0.0;
110
114 rotationalForce.setZero();
115 rotationalForceOld.setZero();
116 rotationalPlaneOld.setZero();
117
119 double lengthRotationalForceOld = 0.0;
120
121
122 bool doneRotating = false;
123 while (!doneRotating) {
125
127 rotationalPlaneOld, lengthRotationalForceOld);
128
129 torque = rotationalForce.norm();
130
131 assert(std::isfinite(torque));
132
133
134 if ((torque >
params.dimer_options().torque_max &&
135 rotations >=
params.dimer_options().rotations_max) ||
136 (torque <
params.dimer_options().torque_max &&
137 torque >=
params.dimer_options().torque_min &&
138 rotations >=
params.dimer_options().rotations_min) ||
139 (torque <
params.dimer_options().torque_min)) {
140 doneRotating = true;
141 }
142
143
144
145 if (!doneRotating) {
148
151
152 double rotForceChange =
153 (rotForce1 - rotForce2) /
params.dimer_options().rotation_angle;
154 double forceDimer = (rotForce1 + rotForce2) / 2.0;
155
156 rotationAngle =
157 atanRatioOrHalfPi(2.0 * forceDimer, rotForceChange) / 2.0 -
158 params.dimer_options().rotation_angle / 2.0;
159
160 if (rotForceChange < 0) {
162 }
163
166 rotations++;
167 }
169 "[DimerRot] ----- --------- ---------------- "
170 "--------- {:9.3e} {:9.3e} {:9.3e} ---------\n",
171 curvature, torque,
173 }
174
177 eonc::safemath::safe_normalize_inplace(
direction);
178 for (
long i = 0; i <
nAtoms; ++i) {
181 }
182 }
187
188 forceCallsCenter =
matterCenter->getForceCalls() - forceCallsCenter;
189 forceCallsDimer =
matterDimer->getForceCalls() - forceCallsDimer;
191}
void determineRotationalPlane(const AtomMatrix &rotationalForce, AtomMatrix &rotationalForceOld, const AtomMatrix &rotationalPlaneOld, double &lengthRotationalForceOld)
Determine rotational plane via conjugate gradient.
double calcRotationalForceReturnCurvature(AtomMatrix &rotationalForce)
Compute rotational force and return curvature along the dimer.
void rotate(double rotationAngle)
Rotate the dimer by the given angle (radians).
eonc::log::FileScoped log
double safe_acos(double x)
std::optional< DimerRotationResult > runAlternativeRotation(DimerRotationBackend backend, const std::shared_ptr< Matter > &matter, const Parameters ¶ms, const std::shared_ptr< Potential > &pot, const AtomMatrix &initialDirection, quill::Logger *log=nullptr)
Run Lanczos, Davidson, or LOR.