Skip to content

Commit 55ffafb

Browse files
authored
Overload important functions for compatibility (#37)
1 parent b225eb6 commit 55ffafb

10 files changed

+305
-92
lines changed

.vscode/c_cpp_properties.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"/opt/software/openblas/**",
8+
"/opt/software/lapack/**"
9+
],
10+
"defines": [],
11+
"compilerPath": "/usr/bin/gcc",
12+
"cStandard": "c17",
13+
"cppStandard": "gnu++17",
14+
"intelliSenseMode": "linux-gcc-x64"
15+
}
16+
],
17+
"version": 4
18+
}

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
This project is a port of the [`dftd4`](https://github.com/dftd4/dftd4) project
77
to C++ and provides the D4(EEQ)-ATM method.
88

9-
**NOTE:** This branch contains some adaptations for compatibility with the ORCA Quantum Chemistry program. This inludes some renaming of variables and functions, and, most notably, the handling of ghost atoms.
10-
119
## Building This Project
1210

1311
This project is build with `meson`, to setup and perform a build run:

app/main.cpp

+1-12
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,6 @@ int main(int argc, char **argv) {
163163
dftd4::TCutoff cutoff;
164164
dftd4::TD4Model d4;
165165

166-
// masking (nothing excluded)
167-
dftd4::TVector<int> realIdx;
168-
realIdx.NewVec(mol.NAtoms);
169-
int nat = 0;
170-
for (int i = 0; i != mol.NAtoms; i++) {
171-
realIdx(i) = nat;
172-
nat++;
173-
}
174-
175166
// analytical gradient
176167
double *d4grad;
177168
if (lgrad) {
@@ -183,9 +174,7 @@ int main(int argc, char **argv) {
183174
d4grad = nullptr;
184175
}
185176

186-
info = dftd4::get_dispersion(
187-
mol, realIdx, charge, d4, par, cutoff, energy, d4grad
188-
);
177+
info = dftd4::get_dispersion(mol, charge, d4, par, cutoff, energy, d4grad);
189178
if (info != EXIT_SUCCESS) return info;
190179

191180
// Print results

include/dftd_dispersion.h

+37-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@
2727

2828
namespace dftd4 {
2929

30+
/**
31+
* @brief Container for DFT-D4 damping parameters.
32+
*
33+
* @param s6 C6 damping parameter. Usually 1.
34+
* @param s8 C8 damping parameter.
35+
* @param s10 C10 damping parameter. Always 0 currently.
36+
* @param s9 ATM (three-body) damping parameter. Usually 1.
37+
* @param a1 Becke-Johnson damping parameter.
38+
* @param a2 Becke-Johnson damping parameter.
39+
* @param alp ATM (three-body) damping parameter. Usually 16.
40+
*/
3041
class dparam {
3142
public:
3243
double s6;
@@ -42,7 +53,32 @@ class dparam {
4253
* @brief Wrapper to handle the evaluation of dispersion energy and derivatives.
4354
*
4455
* @param mol Molecular geometry.
45-
* @param realIdx List for real atoms excluding ghost/non atoms
56+
* @param charge Molecular charge.
57+
* @param par DFT-D4 parameters.
58+
* @param d4 Base D4 dispersion model.
59+
* @param cutoff Real-space cutoffs for CN and dispersion.
60+
* @param energy Dispersion energy (inout).
61+
* @param GRAD Dispersion gradient (inout).
62+
* @return Exit status.
63+
*/
64+
extern int get_dispersion(
65+
const TMolecule &mol,
66+
int charge,
67+
const TD4Model &d4,
68+
const dparam &par,
69+
TCutoff cutoff,
70+
double &energy,
71+
double *GRAD
72+
);
73+
74+
/**
75+
* @brief Wrapper to handle the evaluation of dispersion energy and derivatives.
76+
*
77+
* This function calculates the dispersion energy and gradients for the given
78+
* molecular geometry, considering only the atoms specified in `realIdx`.
79+
*
80+
* @param mol Molecular geometry.
81+
* @param realIdx List for real atoms excluding ghost/non atoms.
4682
* @param charge Molecular charge.
4783
* @param par DFT-D4 parameters.
4884
* @param d4 Base D4 dispersion model.

include/dftd_eeq.h

+38
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,44 @@
2727

2828
namespace dftd4 {
2929

30+
/**
31+
* Get the EEQ charges for a given molecule.
32+
*
33+
* @param mol The molecule object
34+
* @param dist The distance matrix
35+
* @param charge The total charge of the molecule
36+
* @param cutoff The cutoff for the EEQ coordination number
37+
* @param q The EEQ charges
38+
* @param dqdr The derivative of the EEQ charges
39+
* @param lgrad Flag for the gradient
40+
*
41+
* @return 0 if successful, 1 otherwise
42+
*/
43+
extern int get_charges(
44+
const TMolecule &mol,
45+
const TMatrix<double> &dist,
46+
int charge,
47+
double cutoff,
48+
TVector<double> &q,
49+
TMatrix<double> &dqdr,
50+
bool lgrad
51+
);
52+
53+
/**
54+
* Get the EEQ charges for a given molecule for the atoms specified by the
55+
* indices in `realIdx`.
56+
*
57+
* @param mol The molecule object
58+
* @param realIdx The real atom indices (for excluding dummy atoms)
59+
* @param dist The distance matrix
60+
* @param charge The total charge of the molecule
61+
* @param cutoff The cutoff for the EEQ coordination number
62+
* @param q The EEQ charges
63+
* @param dqdr The derivative of the EEQ charges
64+
* @param lgrad Flag for the gradient
65+
*
66+
* @return 0 if successful, 1 otherwise
67+
*/
3068
extern int get_charges(
3169
const TMolecule &mol,
3270
const TIVector &realIdx,

include/dftd_ncoord.h

+63-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace dftd4 {
3232
* Calculate all distance pairs and store in matrix.
3333
*
3434
* @param mol Molecule object.
35-
* @param realIdx List for real atoms excluding ghost/non atoms
35+
* @param realIdx List for real atoms excluding ghost/non atoms.
3636
* @param dist Distance matrix (inout).
3737
* @return Exit status.
3838
*/
@@ -42,11 +42,23 @@ extern int calc_distances(
4242
TMatrix<double> &dist
4343
);
4444

45+
/**
46+
* Initialize real indices to all atoms in the molecule.
47+
*
48+
* @param nat Number of atoms in the molecule.
49+
* @param realIdx Vector to store the real indices.
50+
* @return void
51+
*/
52+
void initializeRealIdx(int nat, TVector<int> &realIdx);
53+
54+
///////////////////////////////////////////////////////////////////////////////
55+
///////////////////////////////////////////////////////////////////////////////
56+
4557
/**
4658
* Wrapper for error function coordination number.
4759
*
4860
* @param mol Molecule object.
49-
* @param realIdx List for real atoms excluding ghost/non atoms
61+
* @param realIdx List for real atoms excluding ghost/non atoms.
5062
* @param dist Distance matrix.
5163
* @param cn Vector of coordination numbers.
5264
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
@@ -64,11 +76,31 @@ extern int get_ncoord_erf(
6476
bool lgrad = false
6577
);
6678

79+
/**
80+
* Wrapper for error function coordination number.
81+
*
82+
* @param mol Molecule object.
83+
* @param dist Distance matrix.
84+
* @param cn Vector of coordination numbers.
85+
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
86+
* @param dcndr Derivative of coordination number.
87+
* @param lgrad Flag for gradient computation.
88+
* @return Exit status.
89+
*/
90+
extern int get_ncoord_erf(
91+
const TMolecule &mol,
92+
const TMatrix<double> &dist,
93+
double cutoff,
94+
TVector<double> &cn,
95+
TMatrix<double> &dcndr,
96+
bool lgrad = false
97+
);
98+
6799
/**
68100
* Calculate error function coordination number.
69101
*
70102
* @param mol Molecule object.
71-
* @param realIdx List for real atoms excluding ghost/non atoms
103+
* @param realIdx List for real atoms excluding ghost/non atoms.
72104
* @param dist Distance matrix.
73105
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
74106
* @param cn Vector of coordination numbers.
@@ -87,7 +119,7 @@ extern int ncoord_erf(
87119
* w.r.t. nuclear coordinates.
88120
*
89121
* @param mol Molecule object.
90-
* @param realIdx List for real atoms excluding ghost/non atoms
122+
* @param realIdx List for real atoms excluding ghost/non atoms.
91123
* @param dist Distance matrix.
92124
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
93125
* @param cn Vector of coordination numbers.
@@ -103,11 +135,14 @@ extern int dncoord_erf(
103135
TMatrix<double> &dcndr
104136
);
105137

138+
///////////////////////////////////////////////////////////////////////////////
139+
///////////////////////////////////////////////////////////////////////////////
140+
106141
/**
107142
* Wrapper for error function coordination number for DFT-D4.
108143
*
109144
* @param mol Molecule object.
110-
* @param realIdx List for real atoms excluding ghost/non atoms
145+
* @param realIdx List for real atoms excluding ghost/non atoms.
111146
* @param dist Distance matrix.
112147
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
113148
* @param cn Vector of coordination numbers.
@@ -123,11 +158,29 @@ extern int get_ncoord_d4(
123158
bool lgrad = false
124159
);
125160

161+
/**
162+
* Wrapper for error function coordination number for DFT-D4.
163+
*
164+
* @param mol Molecule object.
165+
* @param dist Distance matrix.
166+
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
167+
* @param cn Vector of coordination numbers.
168+
* @return Exit status.
169+
*/
170+
extern int get_ncoord_d4(
171+
const TMolecule &mol,
172+
const TMatrix<double> &dist,
173+
double cutoff,
174+
TVector<double> &cn,
175+
TMatrix<double> &dcndr,
176+
bool lgrad = false
177+
);
178+
126179
/**
127180
* Calculate covalent coordination number for DFT-D4.
128181
*
129182
* @param mol Molecule object.
130-
* @param realIdx List for real atoms excluding ghost/non atoms
183+
* @param realIdx List for real atoms excluding ghost/non atoms.
131184
* @param dist Distance matrix.
132185
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
133186
* @param cn Vector of coordination numbers.
@@ -146,7 +199,7 @@ extern int ncoord_d4(
146199
* w.r.t. nuclear coordinates
147200
*
148201
* @param mol Molecule object.
149-
* @param realIdx List for real atoms excluding ghost/non atoms
202+
* @param realIdx List for real atoms excluding ghost/non atoms.
150203
* @param dist Distance matrix.
151204
* @param cutoff Real-space cutoff (default: @see {dftd_cutoff.h}).
152205
* @param cn Vector of coordination numbers.
@@ -162,6 +215,9 @@ extern int dncoord_d4(
162215
TMatrix<double> &dcndr
163216
);
164217

218+
///////////////////////////////////////////////////////////////////////////////
219+
///////////////////////////////////////////////////////////////////////////////
220+
165221
/**
166222
* Error function counting function for coordination number contributions.
167223
*

scripts/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Scripts
22

33
Scripts for creating the ORCA source files. This mainly concatenates the corresponding files and adds headers and footers. Execute within the `scripts` directory.
4+
This is only useful for ORCA developers.

src/dftd_dispersion.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@
3434

3535
namespace dftd4 {
3636

37+
int get_dispersion(
38+
const TMolecule &mol,
39+
const int charge,
40+
const TD4Model &d4,
41+
const dparam &par,
42+
const TCutoff cutoff,
43+
double &energy,
44+
double *GRAD
45+
) {
46+
TVector<int> realIdx;
47+
initializeRealIdx(mol.NAtoms, realIdx);
48+
49+
return get_dispersion(mol, realIdx, charge, d4, par, cutoff, energy, GRAD);
50+
}
51+
3752
int get_dispersion(
3853
const TMolecule &mol,
3954
const TIVector &realIdx,

src/dftd_eeq.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ static const double pi = 3.1415926535897932384626433832795029;
129129
static const double sqrtpi = std::sqrt(pi);
130130
static const double sqrt2pi = std::sqrt(2.0 / pi);
131131

132+
int get_charges(
133+
const TMolecule &mol,
134+
const TMatrix<double> &dist,
135+
const int charge,
136+
const double cutoff,
137+
TVector<double> &q,
138+
TMatrix<double> &dqdr,
139+
bool lgrad
140+
) {
141+
TIVector realIdx;
142+
initializeRealIdx(mol.NAtoms, realIdx);
143+
144+
return get_charges(mol, realIdx, dist, charge, cutoff, q, dqdr, lgrad);
145+
};
146+
132147
int get_charges(
133148
const TMolecule &mol,
134149
const TIVector &realIdx,

0 commit comments

Comments
 (0)