2424#include " dftd_damping.h"
2525#include " dftd_dispersion.h"
2626#include " dftd_geometry.h"
27- #include " dftd_model.h"
2827#include " dftd_matrix.h"
28+ #include " dftd_model.h"
2929#include " dftd_readxyz.h"
3030
3131class 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+ }
3637 }
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 ();
4350 }
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- }
5051
51- private:
52- std::vector<std::string> args;
52+ private:
53+ std::vector<std::string> args;
5354};
5455
5556void dftd4_citation () {
@@ -125,13 +126,17 @@ int main(int argc, char **argv) {
125126 help ();
126127 exit (EXIT_FAILURE);
127128 }
129+
128130 // setup the argparser from the commandline
129131 argparser args (argc, argv);
132+
130133 // check for help flag first
131134 if (args.getflag (" -h" ) || args.getflag (" --help" )) {
132135 help ();
133136 exit (EXIT_SUCCESS);
134137 }
138+
139+ // get other flags
135140 if (args.getflag (" -v" ) || args.getflag (" --verbose" )) { lverbose = true ; }
136141 if (args.getflag (" -g" ) || args.getflag (" --grad" )) { lgrad = true ; }
137142 if (args.getflag (" --func" )) {
@@ -149,10 +154,46 @@ int main(int argc, char **argv) {
149154 dftd4::TCutoff cutoff;
150155 dftd4::TD4Model d4;
151156
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+ }
154165
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+ }
156197
157198 mol.FreeMemory ();
158199
0 commit comments