24
24
#include " dftd_damping.h"
25
25
#include " dftd_dispersion.h"
26
26
#include " dftd_geometry.h"
27
- #include " dftd_model.h"
28
27
#include " dftd_matrix.h"
28
+ #include " dftd_model.h"
29
29
#include " dftd_readxyz.h"
30
30
31
31
class argparser {
32
- public:
33
- argparser (int &argc, char **argv) {
34
- for (int i = 1 ; i != argc; i++) {
35
- this ->args .push_back (std::string (argv[i]));
32
+ public:
33
+ argparser (int &argc, char **argv) {
34
+ for (int i = 1 ; i != argc; i++) {
35
+ this ->args .push_back (std::string (argv[i]));
36
+ }
36
37
}
37
- }
38
- const std::string &getopt (const std::string &opt) const {
39
- std::vector<std::string>::const_iterator iter;
40
- iter = find (this ->args .begin (), this ->args .end (), opt);
41
- if (iter != this ->args .end () && ++iter != this ->args .end ()) {
42
- return *iter;
38
+ const std::string &getopt (const std::string &opt) const {
39
+ std::vector<std::string>::const_iterator iter;
40
+ iter = find (this ->args .begin (), this ->args .end (), opt);
41
+ if (iter != this ->args .end () && ++iter != this ->args .end ()) {
42
+ return *iter;
43
+ }
44
+ static const std::string empty (" " );
45
+ return empty;
46
+ }
47
+ bool getflag (const std::string &opt) const {
48
+ return find (this ->args .begin (), this ->args .end (), opt) !=
49
+ this ->args .end ();
43
50
}
44
- static const std::string empty (" " );
45
- return empty;
46
- }
47
- bool getflag (const std::string &opt) const {
48
- return find (this ->args .begin (), this ->args .end (), opt) != this ->args .end ();
49
- }
50
51
51
- private:
52
- std::vector<std::string> args;
52
+ private:
53
+ std::vector<std::string> args;
53
54
};
54
55
55
56
void dftd4_citation () {
@@ -125,13 +126,17 @@ int main(int argc, char **argv) {
125
126
help ();
126
127
exit (EXIT_FAILURE);
127
128
}
129
+
128
130
// setup the argparser from the commandline
129
131
argparser args (argc, argv);
132
+
130
133
// check for help flag first
131
134
if (args.getflag (" -h" ) || args.getflag (" --help" )) {
132
135
help ();
133
136
exit (EXIT_SUCCESS);
134
137
}
138
+
139
+ // get other flags
135
140
if (args.getflag (" -v" ) || args.getflag (" --verbose" )) { lverbose = true ; }
136
141
if (args.getflag (" -g" ) || args.getflag (" --grad" )) { lgrad = true ; }
137
142
if (args.getflag (" --func" )) {
@@ -149,10 +154,46 @@ int main(int argc, char **argv) {
149
154
dftd4::TCutoff cutoff;
150
155
dftd4::TD4Model d4;
151
156
152
- info = dftd4::get_dispersion (mol, charge, d4, par, cutoff, energy, nullptr );
153
- if (info != 0 ) return EXIT_FAILURE;
157
+ // masking (nothing excluded)
158
+ dftd4::TVector<int > realIdx;
159
+ realIdx.NewVec (mol.NAtoms );
160
+ int nat = 0 ;
161
+ for (int i = 0 ; i != mol.NAtoms ; i++) {
162
+ realIdx (i) = nat;
163
+ nat++;
164
+ }
154
165
155
- std::cout << " Dispersion energy: " << energy << " Eh\n " ;
166
+ // analytical gradient
167
+ double *d4grad;
168
+ if (lgrad) {
169
+ d4grad = new double [3 * mol.NAtoms ];
170
+ for (int i = 0 ; i < 3 * mol.NAtoms ; i++) {
171
+ d4grad[i] = 0.0 ;
172
+ }
173
+ } else {
174
+ d4grad = nullptr ;
175
+ }
176
+
177
+ info = dftd4::get_dispersion (mol, charge, d4, par, cutoff, energy, d4grad);
178
+ if (info != EXIT_SUCCESS) return info;
179
+
180
+ // Print results
181
+ printf (" Dispersion energy: %.15e Eh\n " , energy);
182
+
183
+ if (lgrad) {
184
+ printf (" \n Dispersion gradient\n " );
185
+ int count{0 };
186
+ for (int i = 0 ; i < mol.NAtoms ; i++) {
187
+ printf (
188
+ " %3i : %+14.9le %+14.9le %+14.9le\n " ,
189
+ i + 1 ,
190
+ d4grad[count],
191
+ d4grad[count + 1 ],
192
+ d4grad[count + 2 ]
193
+ );
194
+ count = count + 3 ;
195
+ };
196
+ }
156
197
157
198
mol.FreeMemory ();
158
199
0 commit comments