Skip to content

Commit d61715f

Browse files
Refactor: Move charge models to new multicharge namespace (#42)
Refactoring to prepare integration of EEQ-BC model - move charge models to new multicharge namespace - create ChargeModel base class - make EEQ model a derived class from ChargeModel --------- Co-authored-by: Marvin Friede <[email protected]>
1 parent 8a966c0 commit d61715f

File tree

5 files changed

+435
-327
lines changed

5 files changed

+435
-327
lines changed

include/dftd_eeq.h

Lines changed: 142 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -25,95 +25,151 @@
2525
#include "dftd_geometry.h"
2626
#include "dftd_matrix.h"
2727

28-
namespace dftd4 {
28+
namespace multicharge {
29+
using dftd4::TIVector;
30+
using dftd4::TVector;
31+
using dftd4::TMatrix;
32+
using dftd4::TMolecule;
2933

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-
*/
68-
extern int get_charges(
69-
const TMolecule &mol,
70-
const TIVector &realIdx,
71-
const TMatrix<double> &dist,
72-
int charge,
73-
double cutoff,
74-
TVector<double> &q,
75-
TMatrix<double> &dqdr,
76-
bool lgrad
77-
);
34+
class ChargeModel
35+
{
36+
public:
37+
// Constructor
38+
ChargeModel();
39+
// Virtual destructor
40+
virtual ~ChargeModel() {}
7841

79-
extern int get_vrhs(
80-
const TMolecule &mol,
81-
const TIVector &realIdx,
82-
const int &charge,
83-
const TVector<double> &cn,
84-
TVector<double> &Xvec,
85-
TVector<double> &dXvec,
86-
bool lgrad
87-
);
42+
/**
43+
* Get the EEQ charges for a given molecule.
44+
*
45+
* @param mol The molecule object
46+
* @param dist The distance matrix
47+
* @param charge The total charge of the molecule
48+
* @param cutoff The cutoff for the EEQ coordination number
49+
* @param q The EEQ charges
50+
* @param dqdr The derivative of the EEQ charges
51+
* @param lgrad Flag for the gradient
52+
*
53+
* @return 0 if successful, 1 otherwise
54+
*/
55+
int get_charges(
56+
const TMolecule &mol,
57+
const TMatrix<double> &dist,
58+
int charge,
59+
double cutoff,
60+
TVector<double> &q,
61+
TMatrix<double> &dqdr,
62+
bool lgrad
63+
);
64+
65+
/**
66+
* Get the EEQ charges for a given molecule for the atoms specified by the
67+
* indices in `realIdx`.
68+
*
69+
* @param mol The molecule object
70+
* @param realIdx The real atom indices (for excluding dummy atoms)
71+
* @param dist The distance matrix
72+
* @param charge The total charge of the molecule
73+
* @param cutoff The cutoff for the EEQ coordination number
74+
* @param q The EEQ charges
75+
* @param dqdr The derivative of the EEQ charges
76+
* @param lgrad Flag for the gradient
77+
*
78+
* @return 0 if successful, 1 otherwise
79+
*/
80+
int get_charges(
81+
const TMolecule &mol,
82+
const TIVector &realIdx,
83+
const TMatrix<double> &dist,
84+
int charge,
85+
double cutoff,
86+
TVector<double> &q,
87+
TMatrix<double> &dqdr,
88+
bool lgrad
89+
);
8890

89-
extern int get_amat_0d(
90-
const TMolecule &mol,
91-
const TIVector &realIdx,
92-
const TMatrix<double> &dist,
93-
TMatrix<double> &Amat
94-
);
91+
int eeq_chrgeq(
92+
const TMolecule &mol,
93+
const TIVector &realIdx,
94+
const TMatrix<double> &dist,
95+
const int &charge,
96+
const TVector<double> &cn,
97+
TVector<double> &qvec,
98+
TMatrix<double> &dcndr,
99+
TMatrix<double> &dqdr,
100+
bool lgrad = false,
101+
bool lverbose = false
102+
);
103+
104+
virtual int get_vrhs(
105+
const TMolecule &mol,
106+
const TIVector &realIdx,
107+
const int &charge,
108+
const TVector<double> &cn,
109+
TVector<double> &Xvec,
110+
TVector<double> &dXvec,
111+
bool lgrad
112+
) const = 0;
95113

96-
extern int get_damat_0d(
97-
const TMolecule &mol,
98-
const TIVector &realIdx,
99-
const TMatrix<double> &dist,
100-
const TVector<double> &q,
101-
const TMatrix<double> &Amat,
102-
TMatrix<double> &dAmat,
103-
TMatrix<double> &atrace
104-
);
114+
// Calculate the Coulomb matrix
115+
virtual int get_amat_0d(
116+
const TMolecule &mol,
117+
const TIVector &realIdx,
118+
const TMatrix<double> &dist,
119+
TMatrix<double> &Amat
120+
) const = 0;
121+
122+
// Calculate the Coulomb matrix derivatives
123+
virtual int get_damat_0d(
124+
const TMolecule &mol,
125+
const TIVector &realIdx,
126+
const TMatrix<double> &dist,
127+
const TVector<double> &q,
128+
const TMatrix<double> &Amat,
129+
TMatrix<double> &dAmat,
130+
TMatrix<double> &atrace
131+
) const = 0;
132+
133+
};
105134

106-
extern int eeq_chrgeq(
107-
const TMolecule &mol,
108-
const TIVector &realIdx,
109-
const TMatrix<double> &dist,
110-
const int &charge,
111-
const TVector<double> &cn,
112-
TVector<double> &qvec,
113-
TMatrix<double> &dcndr,
114-
TMatrix<double> &dqdr,
115-
bool lgrad = false,
116-
bool lverbose = false
117-
);
135+
// Derived class for EEQ charge model
136+
class EEQModel : public ChargeModel {
137+
public:
138+
const double* xi; // Element-specific electronegativity
139+
const double* gam; // Element-specific chemical hardnesses
140+
const double* kappa; // Element-specific CN scaling constant
141+
const double* alp; // Element-specific atomic radii
142+
143+
EEQModel();
144+
145+
int get_vrhs(
146+
const TMolecule &mol,
147+
const TIVector &realIdx,
148+
const int &charge,
149+
const TVector<double> &cn,
150+
TVector<double> &Xvec,
151+
TVector<double> &dXvec,
152+
bool lgrad
153+
) const override;
154+
155+
// Calculate the Coulomb matrix
156+
int get_amat_0d(
157+
const TMolecule &mol,
158+
const TIVector &realIdx,
159+
const TMatrix<double> &dist,
160+
TMatrix<double> &Amat
161+
) const override;
162+
163+
// Calculate the Coulomb matrix derivatives
164+
int get_damat_0d(
165+
const TMolecule &mol,
166+
const TIVector &realIdx,
167+
const TMatrix<double> &dist,
168+
const TVector<double> &q,
169+
const TMatrix<double> &Amat,
170+
TMatrix<double> &dAmat,
171+
TMatrix<double> &atrace
172+
) const override;
173+
};
118174

119-
} // namespace dftd4
175+
} // namespace multicharge

include/dftd_multicharge_param.h

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/* This file is part of cpp-d4.
2+
*
3+
* Copyright (C) 2019 Sebastian Ehlert, Marvin Friede
4+
*
5+
* cpp-d4 is free software: you can redistribute it and/or modify it under
6+
* the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* cpp-d4 is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with cpp-d4. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
/*
20+
Electronegativity equilibration (EEQ) model
21+
This file contains the model parameters
22+
*/
23+
24+
#pragma once
25+
26+
namespace multicharge_param {
27+
28+
namespace eeq {
29+
30+
constexpr int MAXELEMENT = 104; // 103 + dummy
31+
32+
// Element-specific electronegativity for the EEQ charges.
33+
static const double xi[MAXELEMENT]{
34+
+0.00000000, // dummy
35+
+1.23695041, +1.26590957, +0.54341808, +0.99666991, +1.26691604, +1.40028282,
36+
+1.55819364, +1.56866440, +1.57540015, +1.15056627, +0.55936220, +0.72373742,
37+
+1.12910844, +1.12306840, +1.52672442, +1.40768172, +1.48154584, +1.31062963,
38+
+0.40374140, +0.75442607, +0.76482096, +0.98457281, +0.96702598, +1.05266584,
39+
+0.93274875, +1.04025281, +0.92738624, +1.07419210, +1.07900668, +1.04712861,
40+
+1.15018618, +1.15388455, +1.36313743, +1.36485106, +1.39801837, +1.18695346,
41+
+0.36273870, +0.58797255, +0.71961946, +0.96158233, +0.89585296, +0.81360499,
42+
+1.00794665, +0.92613682, +1.09152285, +1.14907070, +1.13508911, +1.08853785,
43+
+1.11005982, +1.12452195, +1.21642129, +1.36507125, +1.40340000, +1.16653482,
44+
+0.34125098, +0.58884173, +0.68441115, +0.56999999, +0.56999999, +0.56999999,
45+
+0.56999999, +0.56999999, +0.56999999, +0.56999999, +0.56999999, +0.56999999,
46+
+0.56999999, +0.56999999, +0.56999999, +0.56999999, +0.56999999, +0.87936784,
47+
+1.02761808, +0.93297476, +1.10172128, +0.97350071, +1.16695666, +1.23997927,
48+
+1.18464453, +1.14191734, +1.12334192, +1.01485321, +1.12950808, +1.30804834,
49+
+1.33689961, +1.27465977, +1.06598299, +0.68184178, +1.04581665, +1.09888688,
50+
+1.07206461, +1.09821942, +1.10900303, +1.01039812, +1.00095966, +1.11003303,
51+
+1.16831853, +1.00887482, +1.05928842, +1.07672363, +1.11308426, +1.14340090,
52+
+1.13714110,
53+
};
54+
55+
// Element-specific chemical hardnesses for the EEQ charges.
56+
static const double gam[MAXELEMENT]{
57+
+0.00000000, // dummy
58+
-0.35015861, +1.04121227, +0.09281243, +0.09412380, +0.26629137, +0.19408787,
59+
+0.05317918, +0.03151644, +0.32275132, +1.30996037, +0.24206510, +0.04147733,
60+
+0.11634126, +0.13155266, +0.15350650, +0.15250997, +0.17523529, +0.28774450,
61+
+0.42937314, +0.01896455, +0.07179178, -0.01121381, -0.03093370, +0.02716319,
62+
-0.01843812, -0.15270393, -0.09192645, -0.13418723, -0.09861139, +0.18338109,
63+
+0.08299615, +0.11370033, +0.19005278, +0.10980677, +0.12327841, +0.25345554,
64+
+0.58615231, +0.16093861, +0.04548530, -0.02478645, +0.01909943, +0.01402541,
65+
-0.03595279, +0.01137752, -0.03697213, +0.08009416, +0.02274892, +0.12801822,
66+
-0.02078702, +0.05284319, +0.07581190, +0.09663758, +0.09547417, +0.07803344,
67+
+0.64913257, +0.15348654, +0.05054344, +0.11000000, +0.11000000, +0.11000000,
68+
+0.11000000, +0.11000000, +0.11000000, +0.11000000, +0.11000000, +0.11000000,
69+
+0.11000000, +0.11000000, +0.11000000, +0.11000000, +0.11000000, -0.02786741,
70+
+0.01057858, -0.03892226, -0.04574364, -0.03874080, -0.03782372, -0.07046855,
71+
+0.09546597, +0.21953269, +0.02522348, +0.15263050, +0.08042611, +0.01878626,
72+
+0.08715453, +0.10500484, +0.10034731, +0.15801991, -0.00071039, -0.00170887,
73+
-0.00133327, -0.00104386, -0.00094936, -0.00111390, -0.00125257, -0.00095936,
74+
-0.00102814, -0.00104450, -0.00112666, -0.00101529, -0.00059592, -0.00012585,
75+
-0.00140896,
76+
};
77+
78+
// Element-specific CN scaling constant for the EEQ charges.
79+
static const double kappa[MAXELEMENT]{
80+
+0.00000000, // dummy
81+
+0.04916110, +0.10937243, -0.12349591, -0.02665108, -0.02631658, +0.06005196,
82+
+0.09279548, +0.11689703, +0.15704746, +0.07987901, -0.10002962, -0.07712863,
83+
-0.02170561, -0.04964052, +0.14250599, +0.07126660, +0.13682750, +0.14877121,
84+
-0.10219289, -0.08979338, -0.08273597, -0.01754829, -0.02765460, -0.02558926,
85+
-0.08010286, -0.04163215, -0.09369631, -0.03774117, -0.05759708, +0.02431998,
86+
-0.01056270, -0.02692862, +0.07657769, +0.06561608, +0.08006749, +0.14139200,
87+
-0.05351029, -0.06701705, -0.07377246, -0.02927768, -0.03867291, -0.06929825,
88+
-0.04485293, -0.04800824, -0.01484022, +0.07917502, +0.06619243, +0.02434095,
89+
-0.01505548, -0.03030768, +0.01418235, +0.08953411, +0.08967527, +0.07277771,
90+
-0.02129476, -0.06188828, -0.06568203, -0.11000000, -0.11000000, -0.11000000,
91+
-0.11000000, -0.11000000, -0.11000000, -0.11000000, -0.11000000, -0.11000000,
92+
-0.11000000, -0.11000000, -0.11000000, -0.11000000, -0.11000000, -0.03585873,
93+
-0.03132400, -0.05902379, -0.02827592, -0.07606260, -0.02123839, +0.03814822,
94+
+0.02146834, +0.01580538, -0.00894298, -0.05864876, -0.01817842, +0.07721851,
95+
+0.07936083, +0.05849285, +0.00013506, -0.00020631, +0.00473118, +0.01590519,
96+
+0.00369763, +0.00417543, +0.00706682, +0.00488679, +0.00505103, +0.00710682,
97+
+0.00463050, +0.00387799, +0.00296795, +0.00400648, +0.00548481, +0.01350400,
98+
+0.00675380,
99+
};
100+
101+
static const double alp[MAXELEMENT]{
102+
+0.00000000, // dummy
103+
+0.55159092, +0.66205886, +0.90529132, +1.51710827, +2.86070364, +1.88862966,
104+
+1.32250290, +1.23166285, +1.77503721, +1.11955204, +1.28263182, +1.22344336,
105+
+1.70936266, +1.54075036, +1.38200579, +2.18849322, +1.36779065, +1.27039703,
106+
+1.64466502, +1.58859404, +1.65357953, +1.50021521, +1.30104175, +1.46301827,
107+
+1.32928147, +1.02766713, +1.02291377, +0.94343886, +1.14881311, +1.47080755,
108+
+1.76901636, +1.98724061, +2.41244711, +2.26739524, +2.95378999, +1.20807752,
109+
+1.65941046, +1.62733880, +1.61344972, +1.63220728, +1.60899928, +1.43501286,
110+
+1.54559205, +1.32663678, +1.37644152, +1.36051851, +1.23395526, +1.65734544,
111+
+1.53895240, +1.97542736, +1.97636542, +2.05432381, +3.80138135, +1.43893803,
112+
+1.75505957, +1.59815118, +1.76401732, +1.63999999, +1.63999999, +1.63999999,
113+
+1.63999999, +1.63999999, +1.63999999, +1.63999999, +1.63999999, +1.63999999,
114+
+1.63999999, +1.63999999, +1.63999999, +1.63999999, +1.63999999, +1.47055223,
115+
+1.81127084, +1.40189963, +1.54015481, +1.33721475, +1.57165422, +1.04815857,
116+
+1.78342098, +2.79106396, +1.78160840, +2.47588882, +2.37670734, +1.76613217,
117+
+2.66172302, +2.82773085, +1.04059593, +0.60550051, +1.22262145, +1.28736399,
118+
+1.44431317, +1.29032833, +1.41009404, +1.25501213, +1.15181468, +1.42010424,
119+
+1.43955530, +1.28565237, +1.35017463, +1.33011749, +1.30745135, +1.26526071,
120+
+1.34071499,
121+
};
122+
123+
} // namespace eeq
124+
125+
} // namespace multicharge_param

src/dftd_dispersion.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ int get_dispersion(
107107
TMatrix<double> dcndr; // derivative of D4-CN
108108
TMatrix<double> dqdr; // derivative of partial charges
109109
TVector<double> gradient; // derivative of dispersion energy
110+
multicharge::EEQModel chrg_model; // Charge model
110111

111112
cn.NewVector(nat);
112113
q.NewVector(nat);
@@ -117,7 +118,7 @@ int get_dispersion(
117118
}
118119

119120
// calculate partial charges from EEQ model
120-
info = get_charges(mol, realIdx, dist, charge, cutoff.cn_eeq, q, dqdr, lgrad);
121+
info = chrg_model.get_charges(mol, realIdx, dist, charge, cutoff.cn_eeq, q, dqdr, lgrad);
121122
if (info != EXIT_SUCCESS) return info;
122123

123124
// get the D4 coordination number

0 commit comments

Comments
 (0)