151 {
152 const int nat = static_cast<int>(pos.size()) / 3;
153 const double alpha = A > 0.0 ? A : 1.0;
154 const double scale = mu > 0.0 ? mu : 1.0;
155 const double r_bond = std::min(rcut, 1.35 * r_nn);
156 const double r_cov = 0.5 * r_nn;
157 auto mic = [&](int i, int j) {
158 Eigen::Vector3d dr = pos.segment<3>(3 * i) - pos.segment<3>(3 * j);
160 return dr;
161 };
162 std::vector<std::vector<int>> nb(static_cast<size_t>(nat));
163 const double r_pair = (kind == "swart") ? rcut : r_bond;
164 for (int i = 0; i < nat; ++i) {
165 for (int j = i + 1; j < nat; ++j) {
166 const Eigen::Vector3d rij = mic(i, j);
167 const double r = rij.norm();
168 if (r >= r_pair || r < 1.0e-14) {
169 continue;
170 }
171 double k = 0.0;
172 if (kind == "schlegel") {
173 const double den = std::max(r - 0.45 * r_nn, 0.15);
174 k = scale * 1.734 / (den * den * den);
175 } else if (kind == "fischer") {
176 k = scale * 0.3601 * std::exp(-1.944 * (r - r_cov));
177 } else {
178 k = scale *
lindhRho(r, r_nn, alpha);
179 if (kind == "swart") {
181 }
182 }
184 if (r < r_bond) {
185 nb[static_cast<size_t>(i)].push_back(j);
186 nb[static_cast<size_t>(j)].push_back(i);
187 }
188 }
189 }
190 for (int j = 0; j < nat; ++j) {
191 const auto &nbr = nb[static_cast<size_t>(j)];
192 for (size_t a = 0; a < nbr.size(); ++a) {
193 for (size_t b = a + 1; b < nbr.size(); ++b) {
194 const int i = nbr[a];
195 const int k = nbr[b];
196 const Eigen::Vector3d ri = pos.segment<3>(3 * i);
197 const Eigen::Vector3d rj = pos.segment<3>(3 * j);
198 const Eigen::Vector3d rk = pos.segment<3>(3 * k);
199 Eigen::Vector3d g[3];
200 Eigen::Vector3d rji = ri - rj;
201 Eigen::Vector3d rjk = rk - rj;
205 continue;
206 }
207 const double rij = rji.norm();
208 const double rkj = rjk.norm();
209 double kang = 0.16 * scale;
210 if (kind == "fischer") {
211 kang =
212 scale *
213 (0.089 + 0.11 * std::pow(r_cov * r_cov, -0.42) *
214 std::exp(-0.44 * ((rij - r_cov) + (rkj - r_cov))));
215 } else if (kind == "lindh_full" || kind == "swart") {
216 kang = 0.15 * scale *
lindhRho(rij, r_nn, alpha) *
218 if (kind == "swart") {
220 }
221 }
222 const int atoms[3] = {i, j, k};
224 }
225 }
226 }
227 for (int j = 0; j < nat; ++j) {
228 const auto &nj = nb[static_cast<size_t>(j)];
229 for (int k : nj) {
230 if (k <= j) {
231 continue;
232 }
233 const auto &nk = nb[static_cast<size_t>(k)];
234 for (int i : nj) {
235 if (i == k) {
236 continue;
237 }
238 for (int l : nk) {
239 if (l == j || l == i) {
240 continue;
241 }
242 Eigen::Vector3d rijv = pos.segment<3>(3 * i) - pos.segment<3>(3 * j);
243 Eigen::Vector3d rkjv = pos.segment<3>(3 * k) - pos.segment<3>(3 * j);
244 Eigen::Vector3d rklv = pos.segment<3>(3 * k) - pos.segment<3>(3 * l);
248 const Eigen::Vector3d rj = pos.segment<3>(3 * j);
249 Eigen::Vector3d g[4];
250 if (!
torsionGrads(rj + rijv, rj, rj + rkjv, rj + rkjv - rklv, g)) {
251 continue;
252 }
253 const double rij = rijv.norm();
254 const double rjk = rkjv.norm();
255 const double rkl = rklv.norm();
256 double ktor = 0.01 * scale;
257 if (kind == "fischer") {
258 ktor = 0.0015 * scale;
259 } else if (kind == "lindh_full" || kind == "swart") {
260 ktor = 0.005 * scale *
lindhRho(rij, r_nn, alpha) *
262 if (kind == "swart") {
265 }
266 }
267 const int atoms[4] = {i, j, k, l};
269 }
270 }
271 }
272 }
273}
virtual void minimumImage(Eigen::Ref< Eigen::Vector3d >) const
bool angleGrads(const Eigen::Vector3d &ri, const Eigen::Vector3d &rj, const Eigen::Vector3d &rk, Eigen::Vector3d g[3])
Wilson (B) rows for the valence angle (i{-}j{-}k) ((j) central).
double lindhRho(double r, double r_nn, double alpha)
void addPairBlock(Eigen::MatrixXd &P, int i, int j, const Eigen::Vector3d &rij, double k_par, double k_perp)
bool torsionGrads(const Eigen::Vector3d &ri, const Eigen::Vector3d &rj, const Eigen::Vector3d &rk, const Eigen::Vector3d &rl, Eigen::Vector3d g[4])
Wilson (B) rows for the torsion (i{-}j{-}k{-}l).
void addScalarInternal(Eigen::MatrixXd &P, const int *atoms, const Eigen::Vector3d *g, int n_atoms, double k)
Rank-1 update for a scalar internal.
double swartScreen(double r, double r_nn)