| 1 | // | 
|---|
| 2 | // macros.h | 
|---|
| 3 | // | 
|---|
| 4 | // Copyright (C) 2001 Edward Valeev | 
|---|
| 5 | // | 
|---|
| 6 | // Author: Edward Valeev <edward.valeev@chemistry.gatech.edu> | 
|---|
| 7 | // Maintainer: EV | 
|---|
| 8 | // | 
|---|
| 9 | // This file is part of the SC Toolkit. | 
|---|
| 10 | // | 
|---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify | 
|---|
| 12 | // it under the terms of the GNU Library General Public License as published by | 
|---|
| 13 | // the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 14 | // any later version. | 
|---|
| 15 | // | 
|---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful, | 
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 19 | // GNU Library General Public License for more details. | 
|---|
| 20 | // | 
|---|
| 21 | // You should have received a copy of the GNU Library General Public License | 
|---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to | 
|---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
| 24 | // | 
|---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7. | 
|---|
| 26 | // | 
|---|
| 27 |  | 
|---|
| 28 | /* True if the integral is nonzero. */ | 
|---|
| 29 | #define INT_NONZERO(x) (((x)< -1.0e-15)||((x)> 1.0e-15)) | 
|---|
| 30 |  | 
|---|
| 31 | /* Computes an index to a Cartesian function within a shell given | 
|---|
| 32 | * am = total angular momentum | 
|---|
| 33 | * i = the exponent of x (i is used twice in the macro--beware side effects) | 
|---|
| 34 | * j = the exponent of y | 
|---|
| 35 | * formula: (am - i + 1)*(am - i)/2 + am - i - j unless i==am, then 0 | 
|---|
| 36 | * The following loop will generate indices in the proper order: | 
|---|
| 37 | *  cartindex = 0; | 
|---|
| 38 | *  for (i=am; i>=0; i--) { | 
|---|
| 39 | *    for (j=am-i; j>=0; j--) { | 
|---|
| 40 | *      do_it_with(cartindex); | 
|---|
| 41 | *      cartindex++; | 
|---|
| 42 | *      } | 
|---|
| 43 | *    } | 
|---|
| 44 | */ | 
|---|
| 45 | #define INT_CARTINDEX(am,i,j) (((i) == (am))? 0 : (((((am) - (i) + 1)*((am) - (i)))>>1) + (am) - (i) - (j))) | 
|---|
| 46 |  | 
|---|
| 47 | /* This sets up the above loop over cartesian exponents as follows | 
|---|
| 48 | * FOR_CART(i,j,k,am) | 
|---|
| 49 | *   Stuff using i,j,k. | 
|---|
| 50 | *   END_FOR_CART | 
|---|
| 51 | */ | 
|---|
| 52 | #define FOR_CART(i,j,k,am) for((i)=(am);(i)>=0;(i)--) {\ | 
|---|
| 53 | for((j)=(am)-(i);(j)>=0;(j)--) \ | 
|---|
| 54 | { (k) = (am) - (i) - (j); | 
|---|
| 55 | #define END_FOR_CART }} | 
|---|
| 56 |  | 
|---|
| 57 | /* This sets up a loop over all of the generalized contractions | 
|---|
| 58 | * and all of the cartesian exponents. | 
|---|
| 59 | * gc is the number of the gen con | 
|---|
| 60 | * index is the index within the current gen con. | 
|---|
| 61 | * i,j,k are the angular momentum for x,y,z | 
|---|
| 62 | * sh is the shell pointer | 
|---|
| 63 | */ | 
|---|
| 64 | #define FOR_GCCART(gc,index,i,j,k,sh)\ | 
|---|
| 65 | for ((gc)=0; (gc)<(sh)->ncon; (gc)++) {\ | 
|---|
| 66 | (index)=0;\ | 
|---|
| 67 | FOR_CART(i,j,k,(sh)->type[gc].am) | 
|---|
| 68 |  | 
|---|
| 69 | #define FOR_GCCART_GS(gc,index,i,j,k,sh)\ | 
|---|
| 70 | for ((gc)=0; (gc)<(sh)->ncontraction(); (gc)++) {\ | 
|---|
| 71 | (index)=0;\ | 
|---|
| 72 | FOR_CART(i,j,k,(sh)->am(gc)) | 
|---|
| 73 |  | 
|---|
| 74 | #define END_FOR_GCCART(index)\ | 
|---|
| 75 | (index)++;\ | 
|---|
| 76 | END_FOR_CART\ | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | #define END_FOR_GCCART_GS(index)\ | 
|---|
| 80 | (index)++;\ | 
|---|
| 81 | END_FOR_CART\ | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | /* These are like the above except no index is kept track of. */ | 
|---|
| 85 | #define FOR_GCCART2(gc,i,j,k,sh)\ | 
|---|
| 86 | for ((gc)=0; (gc)<(sh)->ncon; (gc)++) {\ | 
|---|
| 87 | FOR_CART(i,j,k,(sh)->type[gc].am) | 
|---|
| 88 |  | 
|---|
| 89 | #define END_FOR_GCCART2\ | 
|---|
| 90 | END_FOR_CART\ | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | /* These are used to loop over shells, given the centers structure | 
|---|
| 94 | * and the center index, and shell index. */ | 
|---|
| 95 | #define FOR_SHELLS(c,i,j) for((i)=0;(i)<(c)->n;i++) {\ | 
|---|
| 96 | for((j)=0;(j)<(c)->center[(i)].basis.n;j++) { | 
|---|
| 97 | #define END_FOR_SHELLS }} | 
|---|
| 98 |  | 
|---|
| 99 | /* Computes the number of Cartesian function in a shell given | 
|---|
| 100 | * am = total angular momentum | 
|---|
| 101 | * formula: (am*(am+1))/2 + am+1; | 
|---|
| 102 | */ | 
|---|
| 103 | #define INT_NCART(am) ((am>=0)?((((am)+2)*((am)+1))>>1):0) | 
|---|
| 104 |  | 
|---|
| 105 | /* Like INT_NCART, but only for nonnegative arguments. */ | 
|---|
| 106 | #define INT_NCART_NN(am) ((((am)+2)*((am)+1))>>1) | 
|---|
| 107 |  | 
|---|
| 108 | /* For a given ang. mom., am, with n cartesian functions, compute the | 
|---|
| 109 | * number of cartesian functions for am+1 or am-1 | 
|---|
| 110 | */ | 
|---|
| 111 | #define INT_NCART_DEC(am,n) ((n)-(am)-1) | 
|---|
| 112 | #define INT_NCART_INC(am,n) ((n)+(am)+2) | 
|---|
| 113 |  | 
|---|
| 114 | /* Computes the number of pure angular momentum functions in a shell | 
|---|
| 115 | * given am = total angular momentum | 
|---|
| 116 | */ | 
|---|
| 117 | #define INT_NPURE(am) (2*(am)+1) | 
|---|
| 118 |  | 
|---|
| 119 | /* Computes the number of functions in a shell given | 
|---|
| 120 | * pu = pure angular momentum boolean | 
|---|
| 121 | * am = total angular momentum | 
|---|
| 122 | */ | 
|---|
| 123 | #define INT_NFUNC(pu,am) ((pu)?INT_NPURE(am):INT_NCART(am)) | 
|---|
| 124 |  | 
|---|
| 125 | /* Given a centers pointer and a shell number, this evaluates the | 
|---|
| 126 | * pointer to that shell. */ | 
|---|
| 127 | #define INT_SH(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]]) | 
|---|
| 128 |  | 
|---|
| 129 | /* Given a centers pointer and a shell number, get the angular momentum | 
|---|
| 130 | * of that shell. */ | 
|---|
| 131 | #define INT_SH_AM(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]].type.am) | 
|---|
| 132 |  | 
|---|
| 133 | /* Given a centers pointer and a shell number, get pure angular momentum | 
|---|
| 134 | * boolean for that shell. */ | 
|---|
| 135 | #define INT_SH_PU(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]].type.puream) | 
|---|
| 136 |  | 
|---|
| 137 | /* Given a centers pointer, a center number, and a shell number, | 
|---|
| 138 | * get the angular momentum of that shell. */ | 
|---|
| 139 | #define INT_CE_SH_AM(c,a,s) ((c)->center[(a)].basis.shell[(s)].type.am) | 
|---|
| 140 |  | 
|---|
| 141 | /* Given a centers pointer, a center number, and a shell number, | 
|---|
| 142 | * get pure angular momentum boolean for that shell. */ | 
|---|
| 143 | #define INT_CE_SH_PU(c,a,s) ((c)->center[(a)].basis.shell[(s)].type.puream) | 
|---|
| 144 |  | 
|---|
| 145 | /* Given a centers pointer and a shell number, compute the number | 
|---|
| 146 | * of functions in that shell. */ | 
|---|
| 147 | /* #define INT_SH_NFUNC(c,s) INT_NFUNC(INT_SH_PU(c,s),INT_SH_AM(c,s)) */ | 
|---|
| 148 | #define INT_SH_NFUNC(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]].nfunc) | 
|---|
| 149 |  | 
|---|
| 150 | /* These macros assist in looping over the unique integrals | 
|---|
| 151 | * in a shell quartet.  The exy variables are booleans giving | 
|---|
| 152 | * information about the equivalence between shells x and y.  The nx | 
|---|
| 153 | * variables give the number of functions in each shell, x. The | 
|---|
| 154 | * i,j,k are the current values of the looping indices for shells 1, 2, and 3. | 
|---|
| 155 | * The macros return the maximum index to be included in a summation | 
|---|
| 156 | * over indices 1, 2, 3, and 4. | 
|---|
| 157 | * These macros require canonical integrals.  This requirement comes | 
|---|
| 158 | * from the need that integrals of the shells (1 2|2 1) are not | 
|---|
| 159 | * used.  The integrals (1 2|1 2) must be used with these macros to | 
|---|
| 160 | * get the right nonredundant integrals. | 
|---|
| 161 | */ | 
|---|
| 162 | #define INT_MAX1(n1) ((n1)-1) | 
|---|
| 163 | #define INT_MAX2(e12,i,n2) ((e12)?(i):((n2)-1)) | 
|---|
| 164 | #define INT_MAX3(e13e24,i,n3) ((e13e24)?(i):((n3)-1)) | 
|---|
| 165 | #define INT_MAX4(e13e24,e34,i,j,k,n4) \ | 
|---|
| 166 | ((e34)?(((e13e24)&&((k)==(i)))?(j):(k)) \ | 
|---|
| 167 | :((e13e24)&&((k)==(i)))?(j):(n4)-1) | 
|---|
| 168 | /* A note on integral symmetries: | 
|---|
| 169 | *  There are 15 ways of having equivalent indices. | 
|---|
| 170 | *  There are 8 of these which are important for determining the | 
|---|
| 171 | *  nonredundant integrals (that is there are only 8 ways of counting | 
|---|
| 172 | *  the number of nonredundant integrals in a shell quartet) | 
|---|
| 173 | * Integral type   Integral    Counting Type | 
|---|
| 174 | *     1           (1 2|3 4)      1 | 
|---|
| 175 | *     2           (1 1|3 4)      2 | 
|---|
| 176 | *     3           (1 2|1 4)       ->1 | 
|---|
| 177 | *     4           (1 2|3 1)       ->1 | 
|---|
| 178 | *     5           (1 1|1 4)      3 | 
|---|
| 179 | *     6           (1 1|3 1)       ->2 | 
|---|
| 180 | *     7           (1 2|1 1)       ->5 | 
|---|
| 181 | *     8           (1 1|1 1)      4 | 
|---|
| 182 | *     9           (1 2|2 4)       ->1 | 
|---|
| 183 | *    10           (1 2|3 2)       ->1 | 
|---|
| 184 | *    11           (1 2|3 3)      5 | 
|---|
| 185 | *    12           (1 1|3 3)      6 | 
|---|
| 186 | *    13           (1 2|1 2)      7 | 
|---|
| 187 | *    14           (1 2|2 1)      8    reduces to 7 thru canonicalization | 
|---|
| 188 | *    15           (1 2|2 2)       ->5 | 
|---|
| 189 | */ | 
|---|