1 #if defined(__CVERSION__) /* THE C VERSION OF THE HEADERS */
2 /*-*-mode: C; c-indentation-style: "bsd"; c-basic-offset: 4; -*-*/
3 /* The variables, structures and functions related to computation
4    of functional and their derivatives.
5    (c) Pawel Salek, pawsa@theochem.kth.se. 2001.07.13
6 
7    NOTE1: the derivatives are computed with respect to the density,
8    and SQUARE of the density gradient. This is a choice. It stems from
9    the fact that the factors involved in the derivative vector
10    distribution depend on the square of the density gradient.
11 
12    NOTE2: C version is included once per file, Fortran version -
13    multiple times.
14 */
15 #ifndef _FUNCTIONALS_H_
16 #define _FUNCTIONALS_H_
17 
18 #if !defined(M_PI)
19 #define M_PI		3.14159265358979323846
20 #endif
21 
22 typedef double real;
23 
24 /* FirstDrv: matrix of first order derivatives with respect to two
25  * parameters: density rho and SQUARE of the gradient of density grho.
26  * zeta_i = |\nabla\rho_i|�
27  * mu     = |\nabla\rho_\alpha||\nabla\rho_\beta|
28  */
29 typedef struct {
30     real df1000;  /* d/drho F     */
31     real df0100;
32     real df0010;  /* d/zeta F     */
33     real df0001;
34     real df00001;
35 } FunFirstFuncDrv;
36 
37 /* SecondFuncDrv: this structure is used by functional derivative
38  * evaluation procedures. Do not include "triplet" transformation.
39  */
40 typedef struct {
41     real df1000;  /* d/drho_alpha F               */
42     real df0100;  /* d/drho_beta F                */
43     real df0010;  /* d/|zeta_alpha| F             */
44     real df0001;  /* d/|zeta_beta| F              */
45     real df00001;
46     real df2000;  /* d/drho_alpha^2 F             */
47     real df1100;  /* d/(drho_alpha drho_beta) F   */
48     real df1010;  /* d/drho_alpha d/dzeta_alpha F */
49     real df1001;  /* d/drho_alpha d/dzeta_beta F  */
50     real df10001;
51     real df0200;  /* d/drho_beta^2 F              */
52     real df0110;  /* d/drho_beta d/dzeta_alpha F  */
53     real df0101;  /* d/drho_beta d/dzeta_beta F   */
54     real df01001;
55     real df0020;  /* d/dzeta_alpha^2 F          */
56     real df0011;  /* d2/dzeta_a zeta_b F          */
57     real df00101;
58     real df0002;  /* d/dzeta_beta^2 F             */
59     real df00011;
60     real df00002;
61 } FunSecondFuncDrv;
62 
63 
64 /* ThirdFuncDrv: matrix of third derivatives with respect to five
65    parameters: density rho_alpha and SQUARE of the density gradient
66    zeta.  and mu.
67 */
68 
69 typedef struct {
70     real df1000;   /* d/drho F          */
71     real df0100;
72     real df0010;   /* d/|zeta| F        */
73     real df0001;
74     real df00001;
75 
76     real df2000;  /* d/drho_alpha^2 F             */
77     real df1100;  /* d/(drho_alpha drho_beta) F   */
78     real df1010;  /* d/drho_alpha d/dzeta_alpha F */
79     real df1001;  /* d/drho_alpha d/dzeta_beta F  */
80     real df10001;
81     real df0200;  /* d/drho_beta^2 F              */
82     real df0110;  /* d/drho_beta d/dzeta_alpha F  */
83     real df0101;  /* d/drho_beta d/dzeta_beta F   */
84     real df01001;
85     real df0020;  /* d/dzeta_alpha^2 F          */
86     real df0011;  /* d2/dzeta_a zeta_b F          */
87     real df00101;
88     real df0002;  /* d/dzeta_beta^2 F             */
89     real df00011;
90     real df00002;
91 
92     real df3000;
93     real df2100;
94     real df2010;
95     real df2001;
96     real df20001;
97     real df1200;
98     real df1110;
99     real df1101;
100     real df11001;
101     real df1020;
102     real df1011;
103     real df10101;
104     real df1002;
105     real df10011;
106     real df10002;
107     real df0300;
108     real df0210;
109     real df0201;
110     real df02001;
111     real df0120;
112     real df0111;
113     real df01101;
114     real df0102;
115     real df01011;
116     real df01002;
117     real df0030;
118     real df0021;
119     real df00201;
120     real df0012;
121     real df00111;
122     real df00102;
123     real df0003;
124     real df00021;
125     real df00012;
126     real df00003;
127 } FunThirdFuncDrv;
128 
129 
130 typedef struct {
131 
132   /* First order derivatives with respect to all 5 variables */
133 
134     real df1000;
135     real df0100;
136     real df0010;
137     real df0001;
138     real df00001;
139 
140   /* Second order mixed derivatives with respect to all 5 variables */
141 
142     real df2000;
143     real df1100;
144     real df1010;
145     real df1001;
146     real df10001;
147     real df0200;
148     real df0110;
149     real df0101;
150     real df01001;
151     real df0020;
152     real df0011;
153     real df00101;
154     real df0002;
155     real df00011;
156     real df00002;
157 
158   /* Third order mixed derivatives with respect to all 5 variables */
159 
160     real df3000;
161     real df2100;
162     real df2010;
163     real df2001;
164     real df20001;
165     real df1200;
166     real df1110;
167     real df1101;
168     real df11001;
169     real df1020;
170     real df1011;
171     real df10101;
172     real df1002;
173     real df10011;
174     real df10002;
175     real df0300;
176     real df0210;
177     real df0201;
178     real df02001;
179     real df0120;
180     real df0111;
181     real df01101;
182     real df0102;
183     real df01011;
184     real df01002;
185     real df0030;
186     real df0021;
187     real df00201;
188     real df0012;
189     real df00111;
190     real df00102;
191     real df0003;
192     real df00021;
193     real df00012;
194     real df00003;
195 
196   /* Fourth order mixed derivatives with respect to all 5 variables */
197 
198     real df4000;
199     real df3100;
200     real df3010;
201     real df3001;
202     real df30001;
203     real df2200;
204     real df2110;
205     real df2101;
206     real df21001;
207     real df2020;
208     real df2011;
209     real df20101;
210     real df2002;
211     real df20011;
212     real df20002;
213     real df1300;
214     real df1210;
215     real df1201;
216     real df12001;
217     real df1120;
218     real df1111;
219     real df11101;
220     real df1102;
221     real df11011;
222     real df11002;
223     real df1030;
224     real df1021;
225     real df10201;
226     real df1012;
227     real df10111;
228     real df10102;
229     real df1003;
230     real df10021;
231     real df10012;
232     real df10003;
233     real df0400;
234     real df0310;
235     real df0301;
236     real df03001;
237     real df0220;
238     real df0211;
239     real df02101;
240     real df0202;
241     real df02011;
242     real df02002;
243     real df0130;
244     real df0121;
245     real df01201;
246     real df0112;
247     real df01111;
248     real df01102;
249     real df0103;
250     real df01021;
251     real df01012;
252     real df01003;
253     real df0040;
254     real df0031;
255     real df00301;
256     real df0022;
257     real df00211;
258     real df00202;
259     real df0013;
260     real df00121;
261     real df00112;
262     real df00103;
263     real df0004;
264     real df00031;
265     real df00022;
266     real df00013;
267     real df00004;
268 } FunFourthFuncDrv;
269 
270 
271 typedef struct Functional_ Functional;
272 
273 enum FunError { FUN_OK, FUN_UNKNOWN, FUN_CONF_ERROR };
274 enum FunError fun_select_by_name(const char *conf_string);
275 extern Functional *selected_func;
276 extern integer (*fun_printf)(const char *fmt, ...);
277 extern void (*fun_set_hf_weight)(real w);
278 extern real (*fun_get_hf_weight)(void);
279 extern void (*fun_set_mp2_weight)(real w);
280 extern real (*fun_get_mp2_weight)(void);
281 extern void (*fun_set_cam_param)(integer cnt, const real *w, const real *b);
282 
283 /* FunDensProp structure contains properties of the density that are
284    needed for functional evaluation and possibly other purposes.
285 */
286 typedef struct FunDensProp_ {
287     real rhoa,  rhob;
288     real grada, gradb; /* norms of the density gradient, not squares */
289     real gradab;       /* scalar product of grada and gradb */
290     /* real current[3] or something may come in the future :-) */
291 } FunDensProp;
292 
293 /* EnergyFunc: the function returning the energy for given densities
294    and gradients. Note that some functionals(like LYP) depend explicitely
295    on separately alpha and beta densities
296 */
297 typedef integer (*IsGGAFunc)(void);
298 typedef integer (*ReadInputFunc)(const char* conf_string);
299 typedef void (*ReportFunc)(void);
300 typedef real (*EnergyFunc)(const FunDensProp* dens_prop);
301 typedef void (*FirstOrderFun)(FunFirstFuncDrv *ds, real factor,
302                               const FunDensProp* dns_prp);
303 
304 typedef void (*SecondOrderFun)(FunSecondFuncDrv *ds, real factor,
305                                const FunDensProp* dens_prop);
306 
307 typedef void (*ThirdOrderFun)(FunThirdFuncDrv *ds, real factor,
308                               const FunDensProp* dens_prop);
309 typedef void (*FourthOrderFun)(FunFourthFuncDrv *ds, real factor,
310                                const FunDensProp *dens_prop);
311 
312 struct Functional_ {
313     const char* name; /* descriptive functional name (usually 5 characters) */
314     IsGGAFunc       is_gga;
315     integer         highest_tested_resp_order;
316     ReadInputFunc   read;
317     ReportFunc      report;
318    /* Only unrestricted implementations are needed. A benchmark for
319      * a CO molecule with 28 basis function reveals a 4% time difference.
320      * This difference will only decrease for larger systems. */
321     EnergyFunc      func;
322     FirstOrderFun   first;
323     SecondOrderFun  second;
324     ThirdOrderFun   third;
325     FourthOrderFun  fourth;
326 };
327 
328 void drv1_clear(FunFirstFuncDrv* gga);  /* set all components to 0 */
329 void drv2_clear(FunSecondFuncDrv* gga); /* set all components to 0 */
330 void drv3_clear(FunThirdFuncDrv* gga);  /* set all components to 0 */
331 void drv4_clear(FunFourthFuncDrv* gga); /* set all components to 0 */
332 
333 /* The list of functionals */
334 /* sorted list of generic functionals */
335 extern Functional BeckeFunctional;
336 extern Functional mBeckeFunctional;
337 extern Functional B86xFunctional;
338 extern Functional B86mxFunctional;
339 extern Functional B97Functional;
340 extern Functional B97_dFunctional;
341 extern Functional B97_1Functional;
342 extern Functional B97_2Functional;
343 extern Functional B97_3Functional;
344 extern Functional B97_KFunctional;
345 extern Functional Example2Functional;
346 extern Functional ExampleFunctional;
347 extern Functional DK87xFunctional;
348 extern Functional f14Functional;
349 extern Functional G96xFunctional;
350 extern Functional KTxFunctional;
351 extern Functional LB94Functional;
352 extern Functional LG93xFunctional;
353 extern Functional LRC95xFunctional;
354 extern Functional LYPFunctional;
355 extern Functional LYPrFunctional;
356 extern Functional HCTHFunctional;
357 extern Functional HCTH93Functional;
358 extern Functional HCTH93mFunctional;
359 extern Functional HCTH120Functional;
360 extern Functional HCTH147Functional;
361 extern Functional HCTH407Functional;
362 extern Functional HCTH407pFunctional;
363 extern Functional OPTXFunctional;
364 extern Functional mPWxFunctional;
365 extern Functional P86cFunctional;
366 extern Functional PW86xFunctional;
367 extern Functional PW91xFunctional;
368 extern Functional PW91x2Functional;
369 extern Functional PW91cFunctional;
370 extern Functional PW91ncFunctional;
371 extern Functional PW92cFunctional;
372 extern Functional PW92acFunctional;
373 extern Functional PZ81Functional;
374 extern Functional PBEcFunctional;
375 extern Functional PBExFunctional;
376 extern Functional mPBExFunctional;
377 extern Functional rCAM_B3LYPFunctional;
378 extern Functional RPBExFunctional;
379 extern Functional revPBExFunctional;
380 extern Functional SlaterFunctional;
381 extern Functional VWN3Functional;
382 extern Functional VWN5Functional;
383 extern Functional VWNIFunctional;
384 extern Functional VWN3IFunctional;
385 extern Functional VWNFunctional;
386 extern Functional XAlphaFunctional;
387 extern Functional WignerFunctional;
388 extern Functional WL90cFunctional;
389 
390 /* sorted list of mixed functionals */
391 extern Functional B2PLYPFunctional;
392 extern Functional B2TPLYPFunctional;
393 extern Functional MPW2PLYPFunctional;
394 extern Functional MPW2KPLYPFunctional;
395 extern Functional B2GPPLYPFunctional;
396 extern Functional B2PIPLYPFunctional;
397 extern Functional PBE0DHFunctional;
398 extern Functional B3LYPFunctional;
399 extern Functional B3LYPgFunctional;
400 extern Functional B3LYPGaussFunctional;
401 extern Functional B3P86Functional;
402 extern Functional B3P86gFunctional;
403 extern Functional B3PW91Functional;
404 extern Functional B1LYPFunctional;
405 extern Functional B1PW91Functional;
406 extern Functional BHandHFunctional;
407 extern Functional BHandHLYPFunctional;
408 extern Functional B86VWNFunctional;
409 extern Functional B86LYPFunctional;
410 extern Functional B86P86Functional;
411 extern Functional B86PW91Functional;
412 extern Functional BVWNFunctional;
413 extern Functional BLYPFunctional;
414 extern Functional BP86Functional;
415 extern Functional BPW91Functional;
416 extern Functional BWFunctional;
417 extern Functional BFWFunctional;
418 extern Functional Camb3lypFunctional;
419 extern Functional Cam_b3lypFunctional;
420 extern Functional CombineFunctional;
421 extern Functional DBLYPFunctional;
422 extern Functional DBP86Functional;
423 extern Functional DBPW91Functional;
424 extern Functional EDF1Functional;
425 extern Functional EDF2Functional;
426 extern Functional GGAKeyFunctional;
427 extern Functional G96VWNFunctional;
428 extern Functional G96LYPFunctional;
429 extern Functional G96P86Functional;
430 extern Functional G96PW91Functional;
431 extern Functional G961LYPFunctional;
432 extern Functional KMLYPFunctional;
433 extern Functional KT1Functional;
434 extern Functional KT2Functional;
435 extern Functional KT3Functional;
436 extern Functional LDAFunctional;
437 extern Functional LG1LYPFunctional;
438 extern Functional OVWNFunctional;
439 extern Functional OLYPFunctional;
440 extern Functional OP86Functional;
441 extern Functional OPW91Functional;
442 extern Functional mPWVWNFunctional;
443 extern Functional mPWLYPFunctional;
444 extern Functional mPWP86Functional;
445 extern Functional mPWPW91Functional;
446 extern Functional mPW91Functional;
447 extern Functional mPW1PW91Functional;
448 extern Functional mPW3PW91Functional;
449 extern Functional mPW1KFunctional;
450 extern Functional mPW1NFunctional;
451 extern Functional mPW1SFunctional;
452 extern Functional PBE0Functional;
453 extern Functional PBE0PBEFunctional;
454 extern Functional PBE1PBEFunctional;
455 extern Functional PBEFunctional;
456 extern Functional PBEPBEFunctional;
457 extern Functional RPBEFunctional;
458 extern Functional revPBEFunctional;
459 extern Functional mPBEFunctional;
460 extern Functional PW91Functional;
461 extern Functional PW91VWNFunctional;
462 extern Functional PW91LYPFunctional;
463 extern Functional PW91P86Functional;
464 extern Functional PW91PW91Functional;
465 extern Functional SVWN3Functional;
466 extern Functional SVWN5Functional;
467 extern Functional XLYPFunctional;
468 extern Functional X3LYPFunctional;
469 
470 /* the list of the functionals */
471 extern Functional* available_functionals[];
472 
473 extern integer fun_true(void);
474 extern integer fun_false(void);
475 /* fortran (and not only) functional stub routines */
476 void dftlistfuncs_(void);
477 integer dft_isgga_(void);
478 integer dft_isgga__(void);
479 
480 #endif /* _FUNCTIONALS_H_ */
481 #else /* THE FORTRAN VERSION OF THE HEADERS; out of date as of 20021120 */
482 
483       LOGICAL DFT_ISGGA
484       EXTERNAL DFT_ISGGA
485 c     The derivatives with respect to rho and zeta
486       INTEGER FR0, FZ0, FRR, FRZ, FZZ, FRRR, FRRZ, FRZZ, FZZZ
487       INTEGER DERVS1, DERVS2, DERVS3
488       PARAMETER(FR0=1,  FZ0=2,   FRR=3,  FRZ=4)
489       PARAMETER(FZZ=5,  FRRR=6,  FRRZ=7, FRZZ=8, FZZZ=9)
490       PARAMETER(DERVS1=3, DERVS2=5, DERVS3=9)
491 
492 c     The derivatives are a vector that can be declared as
493 c     DIMENSION DRVS(DERVS3)
494 c     where 3 stands for the functional derivative order.
495 c     Second order derivatives can be declared as
496 c     DIMENSION DRVS(DERVS2)
497 c     etc.
498 c     The derivatives can be accessed as DRVS(F1000), DRVS(F0010) etc.
499 c
500       INTEGER F1000, F0010, F2000, F1100, F1010, F1001, F0020
501       INTEGER F3000, F2100, F2010, F1110, F2001
502       INTEGER F1020, F0120, F0030, F1011, F0021
503       INTEGER FUN_DERVS1, FUN_DERVS2, FUN_DERVS3
504       PARAMETER(F1000=1, F0010=2, F2000=3, F1100=4, F1010=5, F1001=6)
505       PARAMETER(F0020=7)
506       PARAMETER(F3000=8, F2100=9, F2010=10,F1110=11,F2001=12)
507       PARAMETER(F1020=13,F0120=14,F0030=15,F1011=16,F0021=17)
508       PARAMETER(FUN_DERVS1=2, FUN_DERVS2=7, FUN_DERVS3=17)
509 #endif /* __CVERSION__ */
510