Skip to content

Commit b225eb6

Browse files
committed
Merge ORCA branch
1 parent 2a727c4 commit b225eb6

38 files changed

+1650
-431
lines changed

Diff for: .gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@
3535
/build*/
3636
/install*/
3737
/_*/
38+
39+
# project-specific
40+
/scripts/old/*
41+
/scripts/*.h
42+
/scripts/*.cpp

Diff for: .vscode/settings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"files.associations": {
3+
"cassert": "cpp",
4+
"cmath": "cpp",
5+
"complex": "cpp",
6+
"functional": "cpp",
7+
"iostream": "cpp",
8+
"new": "cpp"
9+
}
10+
}

Diff for: README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# C++ Port of DFT-D4
1+
# C++ Port of DFT-D4 (for ORCA)
22

33
[![License](https://img.shields.io/github/license/dftd4/cpp-d4)](https://github.com/dftd4/cpp-d4/blob/master/COPYING)
44
[![Latest Version](https://img.shields.io/github/v/release/dftd4/cpp-d4)](https://github.com/dftd4/cpp-d4/releases/latest)
55

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+
911
## Building This Project
1012

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

Diff for: app/main.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ 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+
166175
// analytical gradient
167176
double *d4grad;
168177
if (lgrad) {
@@ -174,7 +183,9 @@ int main(int argc, char **argv) {
174183
d4grad = nullptr;
175184
}
176185

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

180191
// Print results
@@ -196,6 +207,7 @@ int main(int argc, char **argv) {
196207
}
197208

198209
mol.FreeMemory();
210+
delete[] d4grad;
199211

200212
return EXIT_SUCCESS;
201213
}

Diff for: app/readxyz.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ void read_xyzfile(const std::string &name, dftd4::TMolecule &mol) {
5656
printf("Error: Input file could not be read.");
5757
exit(EXIT_FAILURE);
5858
}
59-
mol.xyz(i, 0) = x * aatoau;
60-
mol.xyz(i, 1) = y * aatoau;
61-
mol.xyz(i, 2) = z * aatoau;
59+
mol.CC(i, 0) = x * aatoau;
60+
mol.CC(i, 1) = y * aatoau;
61+
mol.CC(i, 2) = z * aatoau;
6262
at = element(sym);
63-
mol.at(i) = at;
63+
mol.ATNO(i) = at;
6464
}
6565

6666
geo.close();

Diff for: include/damping/dftd_atm.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace dftd4 {
2929

3030
extern int get_atm_dispersion(
3131
const TMolecule &mol,
32+
const TIVector &realIdx,
3233
const TMatrix<double> &dist,
3334
double cutoff,
3435
double s9,
@@ -47,6 +48,7 @@ extern int get_atm_dispersion(
4748

4849
extern int get_atm_dispersion_energy(
4950
const TMolecule &mol,
51+
const TIVector &realIdx,
5052
const TMatrix<double> &dist,
5153
double cutoff,
5254
double s9,
@@ -59,6 +61,7 @@ extern int get_atm_dispersion_energy(
5961

6062
extern int get_atm_dispersion_derivs(
6163
const TMolecule &mol,
64+
const TIVector &realIdx,
6265
const TMatrix<double> &dist,
6366
double cutoff,
6467
double s9,

Diff for: include/damping/dftd_rational.h

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern inline double fdmprdr_bj(int n, double r, double c);
3131

3232
extern int get_dispersion2(
3333
const TMolecule &mol,
34+
const TIVector &realIdx,
3435
const TMatrix<double> &dist,
3536
double cutoff,
3637
const dparam &par,
@@ -46,6 +47,7 @@ extern int get_dispersion2(
4647

4748
extern int get_dispersion3(
4849
const TMolecule &mol,
50+
const TIVector &realIdx,
4951
const TMatrix<double> &dist,
5052
double cutoff,
5153
const dparam &par,
@@ -63,6 +65,7 @@ extern int get_dispersion3(
6365

6466
extern int get_dispersion2_energy(
6567
const TMolecule &mol,
68+
const TIVector &realIdx,
6669
const TMatrix<double> &dist,
6770
double cutoff,
6871
const dparam &par,
@@ -72,6 +75,7 @@ extern int get_dispersion2_energy(
7275

7376
extern int get_dispersion2_derivs(
7477
const TMolecule &mol,
78+
const TIVector &realIdx,
7579
const TMatrix<double> &dist,
7680
double cutoff,
7781
const dparam &par,

Diff for: include/dftd_dispersion.h

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class dparam {
4242
* @brief Wrapper to handle the evaluation of dispersion energy and derivatives.
4343
*
4444
* @param mol Molecular geometry.
45+
* @param realIdx List for real atoms excluding ghost/non atoms
4546
* @param charge Molecular charge.
4647
* @param par DFT-D4 parameters.
4748
* @param d4 Base D4 dispersion model.
@@ -52,6 +53,7 @@ class dparam {
5253
*/
5354
extern int get_dispersion(
5455
const TMolecule &mol,
56+
const TIVector &realIdx,
5557
int charge,
5658
const TD4Model &d4,
5759
const dparam &par,

Diff for: include/dftd_eeq.h

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace dftd4 {
2929

3030
extern int get_charges(
3131
const TMolecule &mol,
32+
const TIVector &realIdx,
3233
const TMatrix<double> &dist,
3334
int charge,
3435
double cutoff,
@@ -39,6 +40,7 @@ extern int get_charges(
3940

4041
extern int get_vrhs(
4142
const TMolecule &mol,
43+
const TIVector &realIdx,
4244
const int &charge,
4345
const TVector<double> &cn,
4446
TVector<double> &Xvec,
@@ -48,12 +50,14 @@ extern int get_vrhs(
4850

4951
extern int get_amat_0d(
5052
const TMolecule &mol,
53+
const TIVector &realIdx,
5154
const TMatrix<double> &dist,
5255
TMatrix<double> &Amat
5356
);
5457

5558
extern int get_damat_0d(
5659
const TMolecule &mol,
60+
const TIVector &realIdx,
5761
const TMatrix<double> &dist,
5862
const TVector<double> &q,
5963
const TMatrix<double> &Amat,
@@ -63,6 +67,7 @@ extern int get_damat_0d(
6367

6468
extern int eeq_chrgeq(
6569
const TMolecule &mol,
70+
const TIVector &realIdx,
6671
const TMatrix<double> &dist,
6772
const int &charge,
6873
const TVector<double> &cn,

Diff for: include/dftd_geometry.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ namespace dftd4 {
2525
class TMolecule {
2626
public:
2727
int NAtoms;
28-
TMatrix<double> xyz; // Cartesian Coordinates: (NAtoms x 3)-matrix
29-
TVector<int> at; // atomic numbers
28+
TMatrix<double> CC; // Cartesian Coordinates: (NAtoms x 3)-matrix
29+
TVector<int> ATNO; // atomic numbers
3030

3131
TMolecule() { NAtoms = 0; }
3232
~TMolecule() { FreeMemory(); }
3333

3434
void GetMemory(int NumAt_) {
3535
FreeMemory();
3636
NAtoms = NumAt_;
37-
xyz.New(NAtoms, 3);
38-
at.New(NAtoms);
37+
CC.New(NAtoms, 3);
38+
ATNO.New(NAtoms);
3939
}
4040

41-
void FreeMemory() {
42-
xyz.Delete();
43-
at.Delete();
41+
void FreeMemory(void) {
42+
CC.Delete();
43+
ATNO.Delete();
4444
}
4545
};
4646

Diff for: include/dftd_matrix.h

+22-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ template <class T> class TVector {
6363
p = nullptr;
6464
N = 0;
6565
}
66+
void DelVec(void) { return Delete(); }
67+
6668
void CopyVec(const TVector &v) {
6769
long int mem;
6870
if (N != v.N) {
@@ -73,25 +75,41 @@ template <class T> class TVector {
7375
mem = (long int)N * ElementSize;
7476
std::memcpy(p, v.p, mem);
7577
}
78+
7679
void Init() {
7780
if (p != nullptr) {
7881
long int mem = (long int)N * ElementSize;
7982
std::memset(p, 0, mem);
8083
}
8184
}
8285

83-
void Print(char name[]) {
86+
void Print(const char name[]) {
8487
printf("Vector printed: %s (%d)\n", name, N);
8588
for (int i = 0; i < N; i++) {
8689
printf("%+23.15e\n", p[i]);
8790
}
8891
printf("\n");
8992
}
93+
void PrintInt(const char name[]) {
94+
printf("Vector printed: %s (%d)\n", name, N);
95+
for (int i = 0; i < N; i++) {
96+
printf("%d\n", p[i]);
97+
}
98+
printf("\n");
99+
}
90100

91101
inline T &operator()(int i) { return p[i]; }
92102
inline const T &operator()(int i) const { return p[i]; }
93103
inline T &operator[](int i) { return p[i]; }
94104
inline const T &operator[](int i) const { return p[i]; }
105+
106+
// Max element
107+
T Max() const {
108+
T result = p[0];
109+
for (int i = 0; i < N; ++i)
110+
if (result < p[i]) result = p[i];
111+
return result;
112+
};
95113
};
96114

97115
// Define a normal matrix
@@ -142,6 +160,7 @@ template <class T> class TMatrix {
142160
cols = 0;
143161
p = nullptr;
144162
}
163+
void DelMat(void) { return Delete(); }
145164

146165
void Init() {
147166
long int mem;
@@ -211,4 +230,6 @@ template <class T> class TMatrix {
211230
inline T *operator[](int i) { return p + i * cols; }
212231
};
213232

233+
typedef TVector<int> TIVector;
234+
214235
} // namespace dftd4

Diff for: include/dftd_model.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ static const double wf_default = 6.0;
3434

3535
class TD4Model {
3636
public:
37+
double wf;
3738
double ga;
3839
double gc;
39-
double wf;
4040

4141
explicit TD4Model(
4242
double ga_scale = ga_default,
@@ -48,6 +48,7 @@ class TD4Model {
4848

4949
int weight_references(
5050
const TMolecule &mol,
51+
const TIVector &realIdx,
5152
const TVector<double> &cn,
5253
const TVector<double> &q,
5354
const TMatrix<double> &refq,
@@ -59,6 +60,7 @@ class TD4Model {
5960

6061
int get_atomic_c6(
6162
const TMolecule &mol,
63+
const TIVector &realIdx,
6264
const TMatrix<double> &gwvec,
6365
const TMatrix<double> &dgwdcn,
6466
const TMatrix<double> &dgwdq,
@@ -68,10 +70,17 @@ class TD4Model {
6870
bool lgrad = false
6971
) const;
7072

71-
virtual int set_refq_eeq(const TMolecule &mol, TMatrix<double> &refq) const;
73+
virtual int set_refq_eeq(
74+
const TMolecule &mol,
75+
const TIVector &realIdx,
76+
TMatrix<double> &refq
77+
) const;
7278

73-
virtual int
74-
set_refalpha_eeq(const TMolecule &mol, TMatrix<double> &alpha) const;
79+
virtual int set_refalpha_eeq(
80+
const TMolecule &mol,
81+
const TIVector &realIdx,
82+
TMatrix<double> &alpha
83+
) const;
7584
};
7685

7786
extern inline double trapzd(const double a[23], const double b[23]);

0 commit comments

Comments
 (0)