Skip to content

Commit 39c8e20

Browse files
author
Hagen Neugebauer
committed
Overload get_dispersion for atom-wise energies
-added a typedef for TRVector
1 parent 3895196 commit 39c8e20

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

include/dftd_dispersion.h

+28
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,34 @@ extern int get_dispersion(
7171
double *GRAD
7272
);
7373

74+
/**
75+
* @brief Wrapper to handle the evaluation of dispersion energy and derivatives.
76+
*
77+
* This function calculates the atom-wise dispersion energy and gradients
78+
* for the given molecular geometry, considering only the atoms specified
79+
* in `realIdx`.
80+
*
81+
* @param mol Molecular geometry.
82+
* @param realIdx List for real atoms excluding ghost/non atoms.
83+
* @param charge Molecular charge.
84+
* @param par DFT-D4 parameters.
85+
* @param d4 Base D4 dispersion model.
86+
* @param cutoff Real-space cutoffs for CN and dispersion.
87+
* @param energies atom-wise dispersion energies (inout).
88+
* @param GRAD Dispersion gradient (inout).
89+
* @return Exit status.
90+
*/
91+
extern int get_dispersion(
92+
const TMolecule &mol,
93+
const TIVector &realIdx,
94+
int charge,
95+
const TD4Model &d4,
96+
const dparam &par,
97+
TCutoff cutoff,
98+
TRVector &energies,
99+
double *GRAD
100+
);
101+
74102
/**
75103
* @brief Wrapper to handle the evaluation of dispersion energy and derivatives.
76104
*

include/dftd_matrix.h

+1
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,6 @@ template <class T> class TMatrix {
231231
};
232232

233233
typedef TVector<int> TIVector;
234+
typedef TVector<double> TRVector;
234235

235236
} // namespace dftd4

src/dftd_dispersion.cpp

+30-7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,36 @@ int get_dispersion(
5959
double &energy,
6060
double *GRAD
6161
) {
62+
63+
int info{0};
64+
65+
int nat = realIdx.Max() + 1;
66+
67+
TRVector energies; // atom-wise energies
68+
info = get_dispersion(mol, realIdx, charge, d4, par, cutoff, energies, GRAD);
69+
70+
if (info != EXIT_SUCCESS) return info;
71+
72+
// sum up atom-wise energies
73+
for (int i = 0; i != nat; i++) {
74+
energy += energies(i);
75+
}
76+
77+
energies.DelVec();
78+
79+
return EXIT_SUCCESS;
80+
}
81+
82+
int get_dispersion(
83+
const TMolecule &mol,
84+
const TIVector &realIdx,
85+
const int charge,
86+
const TD4Model &d4,
87+
const dparam &par,
88+
const TCutoff cutoff,
89+
TRVector &energies,
90+
double *GRAD
91+
) {
6292
// setup variables
6393
int info{0};
6494
bool lmbd = (par.s9 != 0.0);
@@ -137,7 +167,6 @@ int get_dispersion(
137167

138168
TVector<double> dEdcn;
139169
TVector<double> dEdq;
140-
TVector<double> energies;
141170
energies.NewVector(nat);
142171
if (lgrad) {
143172
dEdcn.NewVector(nat);
@@ -242,12 +271,6 @@ int get_dispersion(
242271
dEdcn.DelVec();
243272
dEdq.DelVec();
244273

245-
// sum up atom-wise energies
246-
for (int i = 0; i != nat; i++) {
247-
energy += energies(i);
248-
}
249-
energies.DelVec();
250-
251274
// write to input gradient
252275
if (lgrad) {
253276
for (int i = 0, ii = 0; i != mol.NAtoms; i++) {

0 commit comments

Comments
 (0)