43 Eigen::MatrixXd deriv = Eigen::MatrixXd::Zero(natoms, 3);
55 for (
Index a = 0; a < natoms; ++a) {
56 double Za =
static_cast<double>(mol[a].getNuccharge());
57 const Eigen::Vector3d& Ra = mol[a].
getPos();
58 Eigen::Vector3d sum = Eigen::Vector3d::Zero();
59 for (
Index b = 0; b < natoms; ++b) {
63 double Zb =
static_cast<double>(mol[b].getNuccharge());
64 const Eigen::Vector3d& Rb = mol[b].
getPos();
65 Eigen::Vector3d Rab_vec = Ra - Rb;
66 double Rab = Rab_vec.norm();
67 sum += Za * Zb * Rab_vec / (Rab * Rab * Rab);
69 deriv.row(a) = -sum.transpose();
81 std::vector<Eigen::MatrixXd> tensor =
83 Eigen::VectorXd d(n_aux_bf);
84 for (
Index p = 0; p < n_aux_bf; ++p) {
85 d(p) = (density.array() * tensor[p].array()).sum();
95 aocoulomb.
Fill(auxbasis);
96 const Eigen::MatrixXd&
V = aocoulomb.
Matrix();
97 Eigen::VectorXd c =
V.ldlt().solve(d);
101 std::vector<ThreeCenterDerivative> d3c =
103 std::vector<AOMatrixDerivative> dV =
111 Eigen::MatrixXd grad = Eigen::MatrixXd::Zero(natoms, 3);
112 for (
Index a = 0; a < natoms; ++a) {
113 for (
Index xyz = 0; xyz < 3; ++xyz) {
115 for (
Index p = 0; p < n_aux_bf; ++p) {
116 term1 += c(p) * (density.array() * d3c[a][xyz][p].array()).sum();
118 double term2 = 0.5 * c.dot(dV[a][xyz] * c);
119 grad(a, xyz) = term1 - term2;
130 Index nocc = occ_mo_coeffs.cols();
132 std::vector<Eigen::MatrixXd> tensor =
136 aocoulomb.
Fill(auxbasis);
137 const Eigen::MatrixXd&
V = aocoulomb.
Matrix();
138 Eigen::LDLT<Eigen::MatrixXd> V_ldlt(
V);
140 std::vector<ThreeCenterDerivative> d3c =
142 std::vector<AOMatrixDerivative> dV =
145 Eigen::MatrixXd grad = Eigen::MatrixXd::Zero(natoms, 3);
170 std::vector<std::vector<Eigen::VectorXd>> c_ij(
171 nocc, std::vector<Eigen::VectorXd>(nocc));
172 for (
Index i = 0; i < nocc; ++i) {
173 for (
Index j = 0; j < nocc; ++j) {
174 Eigen::VectorXd d(n_aux_bf);
175 for (
Index p = 0; p < n_aux_bf; ++p) {
176 d(p) = occ_mo_coeffs.col(i).dot(tensor[p] * occ_mo_coeffs.col(j));
178 c_ij[i][j] = V_ldlt.solve(d);
182 for (
Index a = 0; a < natoms; ++a) {
183 for (
Index xyz = 0; xyz < 3; ++xyz) {
184 double energy_term = 0.0;
185 double metric_term = 0.0;
186 for (
Index i = 0; i < nocc; ++i) {
187 for (
Index j = 0; j < nocc; ++j) {
188 const Eigen::VectorXd& c = c_ij[i][j];
189 Eigen::VectorXd dd(n_aux_bf);
190 for (
Index p = 0; p < n_aux_bf; ++p) {
192 occ_mo_coeffs.col(i).dot(d3c[a][xyz][p] * occ_mo_coeffs.col(j));
194 energy_term += c.dot(dd);
195 metric_term += c.dot(dV[a][xyz] * c);
201 grad(a, xyz) = -2.0 * (energy_term - 0.5 * metric_term);