| 1 | // | 
|---|
| 2 | // nuclear.cc | 
|---|
| 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 | #ifdef __GNUG__ | 
|---|
| 29 | #pragma implementation | 
|---|
| 30 | #endif | 
|---|
| 31 |  | 
|---|
| 32 | #include <util/misc/math.h> | 
|---|
| 33 |  | 
|---|
| 34 | #include <chemistry/qc/cints/int1e.h> | 
|---|
| 35 | #include <chemistry/qc/cints/macros.h> | 
|---|
| 36 |  | 
|---|
| 37 | using namespace sc; | 
|---|
| 38 |  | 
|---|
| 39 | void Int1eCints::nuclear(int sh1, int sh2) | 
|---|
| 40 | { | 
|---|
| 41 | zero_buffers_(); | 
|---|
| 42 | compute_doublet_info_(sh1, sh2); | 
|---|
| 43 |  | 
|---|
| 44 | int maxam1 = int_shell1_->max_am(); | 
|---|
| 45 | int minam1 = int_shell1_->min_am(); | 
|---|
| 46 | int maxam2 = int_shell2_->max_am(); | 
|---|
| 47 | int minam2 = int_shell2_->min_am(); | 
|---|
| 48 |  | 
|---|
| 49 | if (maxam1 != minam1 || maxam2 != minam2) { | 
|---|
| 50 | // fail(); | 
|---|
| 51 | nuclear_full_general_(); | 
|---|
| 52 | } | 
|---|
| 53 | else { | 
|---|
| 54 | nuclear_full_general_(); | 
|---|
| 55 | } | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 |  | 
|---|
| 59 | void Int1eCints::nuclear_full_general_() | 
|---|
| 60 | { | 
|---|
| 61 | int maxam1 = int_shell1_->max_am(); | 
|---|
| 62 | int maxam2 = int_shell2_->max_am(); | 
|---|
| 63 | int z1weight = 1; | 
|---|
| 64 | int y1weight = maxam1 + 1; | 
|---|
| 65 | int x1weight = y1weight * y1weight; | 
|---|
| 66 | int z2weight = 1; | 
|---|
| 67 | int y2weight = maxam2 + 1; | 
|---|
| 68 | int x2weight = y2weight * y2weight; | 
|---|
| 69 |  | 
|---|
| 70 | /* See if need to transform to spherical harmonics */ | 
|---|
| 71 | bool need_cart2sph_transform = false; | 
|---|
| 72 | if (int_shell1_->has_pure() || | 
|---|
| 73 | int_shell2_->has_pure()) | 
|---|
| 74 | need_cart2sph_transform = true; | 
|---|
| 75 |  | 
|---|
| 76 | /* See if contraction quartets need to be resorted into a shell quartet */ | 
|---|
| 77 | bool need_sort_to_shell_doublet = false; | 
|---|
| 78 | int num_gen_shells = 0; | 
|---|
| 79 | if (int_shell1_->ncontraction() > 1) | 
|---|
| 80 | num_gen_shells++; | 
|---|
| 81 | if (int_shell2_->ncontraction() > 1) | 
|---|
| 82 | num_gen_shells++; | 
|---|
| 83 | if (maxam1 + maxam2 && num_gen_shells >= 1) | 
|---|
| 84 | need_sort_to_shell_doublet = true; | 
|---|
| 85 |  | 
|---|
| 86 | /* Determine where integrals need to go at each stage */ | 
|---|
| 87 | if (need_sort_to_shell_doublet) { | 
|---|
| 88 | prim_ints_ = cart_ints_; | 
|---|
| 89 | if (need_cart2sph_transform) | 
|---|
| 90 | contr_doublets_ = sphharm_ints_; | 
|---|
| 91 | else | 
|---|
| 92 | contr_doublets_ = cart_ints_; | 
|---|
| 93 | shell_doublet_ = target_ints_buffer_; | 
|---|
| 94 | } | 
|---|
| 95 | else { | 
|---|
| 96 | if (need_cart2sph_transform) { | 
|---|
| 97 | prim_ints_ = cart_ints_; | 
|---|
| 98 | contr_doublets_ = target_ints_buffer_; | 
|---|
| 99 | shell_doublet_ = target_ints_buffer_; | 
|---|
| 100 | } | 
|---|
| 101 | else { | 
|---|
| 102 | prim_ints_ = target_ints_buffer_; | 
|---|
| 103 | shell_doublet_ = target_ints_buffer_; | 
|---|
| 104 | } | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | /* Begin loops over primitives. */ | 
|---|
| 108 | for (int p1=0; p1<int_shell1_->nprimitive(); p1++) { | 
|---|
| 109 | double a1 = int_shell1_->exponent(p1); | 
|---|
| 110 | for (int p2=0; p2<int_shell2_->nprimitive(); p2++) { | 
|---|
| 111 | double a2 = int_shell2_->exponent(p2); | 
|---|
| 112 |  | 
|---|
| 113 | double gamma = a1+a2; | 
|---|
| 114 | double oog = 1.0/gamma; | 
|---|
| 115 | double over_pf = exp(-a1*a2*doublet_info_.AB2*oog)*sqrt(M_PI*oog)*M_PI*oog; | 
|---|
| 116 |  | 
|---|
| 117 | double P[3], PA[3], PB[3], PC[3]; | 
|---|
| 118 | for(int xyz=0; xyz<3; xyz++) { | 
|---|
| 119 | P[xyz] = (a1*doublet_info_.A[xyz] + a2*doublet_info_.B[xyz])*oog; | 
|---|
| 120 | PA[xyz] = P[xyz] - doublet_info_.A[xyz]; | 
|---|
| 121 | PB[xyz] = P[xyz] - doublet_info_.B[xyz]; | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | if (bs1_->molecule() != bs2_->molecule()) { | 
|---|
| 125 | //          fail(); | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | int natom = bs1_->ncenter(); | 
|---|
| 129 | for(int atom=0; atom<natom; atom++) { | 
|---|
| 130 | // if charge is 0 - skip to the next one | 
|---|
| 131 | double Z = bs1_->molecule()->charge(atom); | 
|---|
| 132 | if (Z == 0.0) | 
|---|
| 133 | continue; | 
|---|
| 134 | PC[0] = P[0] - bs1_->r(atom,0); | 
|---|
| 135 | PC[1] = P[1] - bs1_->r(atom,1); | 
|---|
| 136 | PC[2] = P[2] - bs1_->r(atom,2); | 
|---|
| 137 | AI_OSrecurs_(AI0_,PA,PB,PC,gamma,maxam1,maxam2); | 
|---|
| 138 |  | 
|---|
| 139 | /*--- contract each buffer into appropriate location ---*/ | 
|---|
| 140 | double *ints_buf = prim_ints_; | 
|---|
| 141 | for (int gc1=0; gc1<int_shell1_->ncontraction(); gc1++) { | 
|---|
| 142 | double norm1 = int_shell1_->coefficient_unnorm(gc1,p1); | 
|---|
| 143 | int am1 = int_shell1_->am(gc1); | 
|---|
| 144 | for (int gc2=0; gc2<int_shell2_->ncontraction(); gc2++) { | 
|---|
| 145 | double norm2 = int_shell2_->coefficient_unnorm(gc2,p2); | 
|---|
| 146 | int am2 = int_shell2_->am(gc2); | 
|---|
| 147 | double total_pf = over_pf * norm1 * norm2 * Z; | 
|---|
| 148 |  | 
|---|
| 149 | int k1,l1,m1,k2,l2,m2; | 
|---|
| 150 | FOR_CART(k1,l1,m1,am1) | 
|---|
| 151 | int ind1 = k1*x1weight + l1*y1weight + m1*z1weight; | 
|---|
| 152 | FOR_CART(k2,l2,m2,am2) | 
|---|
| 153 | int ind2 = k2*x2weight + l2*y2weight + m2*z2weight; | 
|---|
| 154 | *(ints_buf++) -= AI0_[ind1][ind2][0] * total_pf; | 
|---|
| 155 | END_FOR_CART | 
|---|
| 156 | END_FOR_CART | 
|---|
| 157 |  | 
|---|
| 158 | } | 
|---|
| 159 | } | 
|---|
| 160 | } | 
|---|
| 161 | } | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | if (need_cart2sph_transform) | 
|---|
| 165 | transform_contrquartets_(prim_ints_,contr_doublets_); | 
|---|
| 166 |  | 
|---|
| 167 | if (need_sort_to_shell_doublet) | 
|---|
| 168 | sort_contrdoublets_to_shelldoublet_(contr_doublets_,shell_doublet_); | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 |  | 
|---|
| 172 | void Int1eCints::nuclear_sameam_general_() | 
|---|
| 173 | { | 
|---|
| 174 | int tam1 = int_shell1_->am(0); | 
|---|
| 175 | int tam2 = int_shell2_->am(0); | 
|---|
| 176 | int z1weight = 1; | 
|---|
| 177 | int y1weight = tam1 + 1; | 
|---|
| 178 | int x1weight = y1weight * y1weight; | 
|---|
| 179 | int z2weight = 1; | 
|---|
| 180 | int y2weight = tam2 + 1; | 
|---|
| 181 | int x2weight = y2weight * y2weight; | 
|---|
| 182 |  | 
|---|
| 183 | /* Begin loops over primitives. */ | 
|---|
| 184 | for (int p1=0; p1<int_shell1_->nprimitive(); p1++) { | 
|---|
| 185 | double a1 = int_shell1_->exponent(p1); | 
|---|
| 186 | for (int p2=0; p2<int_shell2_->nprimitive(); p2++) { | 
|---|
| 187 | double a2 = int_shell2_->exponent(p2); | 
|---|
| 188 |  | 
|---|
| 189 | double gamma = a1+a2; | 
|---|
| 190 | double oog = 1.0/gamma; | 
|---|
| 191 | double over_pf = exp(-a1*a2*doublet_info_.AB2*oog)*sqrt(M_PI*oog)*M_PI*oog; | 
|---|
| 192 |  | 
|---|
| 193 | double P[3], PA[3], PB[3], PC[3]; | 
|---|
| 194 | for(int xyz=0; xyz<3; xyz++) { | 
|---|
| 195 | P[xyz] = (a1*doublet_info_.A[xyz] + a2*doublet_info_.B[xyz])*oog; | 
|---|
| 196 | PA[xyz] = P[xyz] - doublet_info_.A[xyz]; | 
|---|
| 197 | PB[xyz] = P[xyz] - doublet_info_.B[xyz]; | 
|---|
| 198 | } | 
|---|
| 199 |  | 
|---|
| 200 | if (bs1_->molecule() != bs2_->molecule()) { | 
|---|
| 201 | //          fail(); | 
|---|
| 202 | } | 
|---|
| 203 |  | 
|---|
| 204 | int natom = bs1_->ncenter(); | 
|---|
| 205 | for(int atom=0; atom<natom; atom++) { | 
|---|
| 206 | // if charge is 0 - skip to the next one | 
|---|
| 207 | double Z = bs1_->molecule()->charge(atom); | 
|---|
| 208 | if (Z == 0.0) | 
|---|
| 209 | continue; | 
|---|
| 210 | PC[0] = P[0] - bs1_->r(atom,0); | 
|---|
| 211 | PC[1] = P[1] - bs1_->r(atom,1); | 
|---|
| 212 | PC[2] = P[2] - bs1_->r(atom,2); | 
|---|
| 213 | AI_OSrecurs_(AI0_,PA,PB,PC,gamma,tam1,tam2); | 
|---|
| 214 |  | 
|---|
| 215 | /*--- contract each buffer into appropriate location ---*/ | 
|---|
| 216 | double *ints_buf = cart_ints_; | 
|---|
| 217 | for (int gc1=0; gc1<int_shell1_->ncontraction(); gc1++) { | 
|---|
| 218 | double norm1 = int_shell1_->coefficient_unnorm(gc1,p1); | 
|---|
| 219 | for (int gc2=0; gc2<int_shell2_->ncontraction(); gc2++) { | 
|---|
| 220 | double norm2 = int_shell2_->coefficient_unnorm(gc2,p2); | 
|---|
| 221 | double total_pf = over_pf * norm1 * norm2 * Z; | 
|---|
| 222 |  | 
|---|
| 223 | int k1,l1,m1,k2,l2,m2; | 
|---|
| 224 | FOR_CART(k1,l1,m1,tam1) | 
|---|
| 225 | int ind1 = k1*x1weight + l1*y1weight + m1*z1weight; | 
|---|
| 226 | FOR_CART(k2,l2,m2,tam2) | 
|---|
| 227 | int ind2 = k2*x2weight + l2*y2weight + m2*z2weight; | 
|---|
| 228 | *ints_buf -= AI0_[ind1][ind2][0] * total_pf; | 
|---|
| 229 | ints_buf++; | 
|---|
| 230 | END_FOR_CART | 
|---|
| 231 | END_FOR_CART | 
|---|
| 232 |  | 
|---|
| 233 | } | 
|---|
| 234 | } | 
|---|
| 235 | } | 
|---|
| 236 | } | 
|---|
| 237 | } | 
|---|
| 238 |  | 
|---|
| 239 | /*---------------------------------------------------------------------- | 
|---|
| 240 | transform to spherical harmonics and/or resort to the target ordering | 
|---|
| 241 | ----------------------------------------------------------------------*/ | 
|---|
| 242 |  | 
|---|
| 243 | /*--- sort to the target ordering ---*/ | 
|---|
| 244 | double *source_ints_buf = cart_ints_; | 
|---|
| 245 | double *target_ints_buf = target_ints_buffer_; | 
|---|
| 246 | int target_bf1_offset = 0; | 
|---|
| 247 | int target_bf2_offset = 0; | 
|---|
| 248 | int nbf2 = int_shell2_->nfunction(); | 
|---|
| 249 | for (int gc1=0; gc1<int_shell1_->ncontraction(); gc1++) { | 
|---|
| 250 | int tsize1 = INT_NCART_NN(tam1); | 
|---|
| 251 | for (int gc2=0; gc2<int_shell2_->ncontraction(); gc2++) { | 
|---|
| 252 | int tsize2 = INT_NCART_NN(tam2); | 
|---|
| 253 |  | 
|---|
| 254 | int k1,l1,m1,k2,l2,m2; | 
|---|
| 255 | int bf1 = 0; | 
|---|
| 256 | FOR_CART(k1,l1,m1,tam1) | 
|---|
| 257 | double *target_ints_buf = target_ints_buffer_ + (target_bf1_offset+bf1)*nbf2 + | 
|---|
| 258 | target_bf2_offset; | 
|---|
| 259 | FOR_CART(k2,l2,m2,tam2) | 
|---|
| 260 | *(target_ints_buf++) = *(source_ints_buf++); | 
|---|
| 261 | END_FOR_CART | 
|---|
| 262 | bf1++; | 
|---|
| 263 | END_FOR_CART | 
|---|
| 264 | target_bf2_offset += tsize2; | 
|---|
| 265 | } | 
|---|
| 266 | target_bf1_offset += tsize1; | 
|---|
| 267 | } | 
|---|
| 268 | } | 
|---|
| 269 |  | 
|---|
| 270 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 271 |  | 
|---|
| 272 | // Local Variables: | 
|---|
| 273 | // mode: c++ | 
|---|
| 274 | // c-file-style: "CLJ" | 
|---|
| 275 | // End: | 
|---|