| 1 | // | 
|---|
| 2 | // overlap.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::overlap(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 | overlap_full_general_(); | 
|---|
| 51 | } | 
|---|
| 52 | else { | 
|---|
| 53 | overlap_full_general_(); | 
|---|
| 54 | } | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 | void Int1eCints::overlap_full_general_() | 
|---|
| 59 | { | 
|---|
| 60 | int maxam1 = int_shell1_->max_am(); | 
|---|
| 61 | int maxam2 = int_shell2_->max_am(); | 
|---|
| 62 |  | 
|---|
| 63 | /* See if need to transform to spherical harmonics */ | 
|---|
| 64 | bool need_cart2sph_transform = false; | 
|---|
| 65 | if (int_shell1_->has_pure() || | 
|---|
| 66 | int_shell2_->has_pure()) | 
|---|
| 67 | need_cart2sph_transform = true; | 
|---|
| 68 |  | 
|---|
| 69 | /* See if contraction quartets need to be resorted into a shell quartet */ | 
|---|
| 70 | bool need_sort_to_shell_doublet = false; | 
|---|
| 71 | int num_gen_shells = 0; | 
|---|
| 72 | if (int_shell1_->ncontraction() > 1) | 
|---|
| 73 | num_gen_shells++; | 
|---|
| 74 | if (int_shell2_->ncontraction() > 1) | 
|---|
| 75 | num_gen_shells++; | 
|---|
| 76 | if (maxam1 + maxam2 && num_gen_shells >= 1) | 
|---|
| 77 | need_sort_to_shell_doublet = true; | 
|---|
| 78 |  | 
|---|
| 79 | /* Determine where integrals need to go at each stage */ | 
|---|
| 80 | if (need_sort_to_shell_doublet) { | 
|---|
| 81 | prim_ints_ = cart_ints_; | 
|---|
| 82 | if (need_cart2sph_transform) | 
|---|
| 83 | contr_doublets_ = sphharm_ints_; | 
|---|
| 84 | else | 
|---|
| 85 | contr_doublets_ = cart_ints_; | 
|---|
| 86 | shell_doublet_ = target_ints_buffer_; | 
|---|
| 87 | } | 
|---|
| 88 | else { | 
|---|
| 89 | if (need_cart2sph_transform) { | 
|---|
| 90 | prim_ints_ = cart_ints_; | 
|---|
| 91 | contr_doublets_ = target_ints_buffer_; | 
|---|
| 92 | shell_doublet_ = target_ints_buffer_; | 
|---|
| 93 | } | 
|---|
| 94 | else { | 
|---|
| 95 | prim_ints_ = target_ints_buffer_; | 
|---|
| 96 | shell_doublet_ = target_ints_buffer_; | 
|---|
| 97 | } | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | /* Begin loops over primitives. */ | 
|---|
| 101 | for (int p1=0; p1<int_shell1_->nprimitive(); p1++) { | 
|---|
| 102 | double a1 = int_shell1_->exponent(p1); | 
|---|
| 103 | for (int p2=0; p2<int_shell2_->nprimitive(); p2++) { | 
|---|
| 104 | double a2 = int_shell2_->exponent(p2); | 
|---|
| 105 |  | 
|---|
| 106 | double gamma = a1+a2; | 
|---|
| 107 | double oog = 1.0/gamma; | 
|---|
| 108 | double over_pf = exp(-a1*a2*doublet_info_.AB2*oog)*sqrt(M_PI*oog)*M_PI*oog; | 
|---|
| 109 |  | 
|---|
| 110 | double P[3], PA[3], PB[3], PC[3]; | 
|---|
| 111 | for(int xyz=0; xyz<3; xyz++) { | 
|---|
| 112 | P[xyz] = (a1*doublet_info_.A[xyz] + a2*doublet_info_.B[xyz])*oog; | 
|---|
| 113 | PA[xyz] = P[xyz] - doublet_info_.A[xyz]; | 
|---|
| 114 | PB[xyz] = P[xyz] - doublet_info_.B[xyz]; | 
|---|
| 115 | } | 
|---|
| 116 |  | 
|---|
| 117 | OI_OSrecurs_(OIX_,OIY_,OIZ_,PA,PB,gamma,maxam1,maxam2); | 
|---|
| 118 |  | 
|---|
| 119 | /*--- contract each buffer into appropriate location ---*/ | 
|---|
| 120 | double *ints_buf = prim_ints_; | 
|---|
| 121 | for (int gc1=0; gc1<int_shell1_->ncontraction(); gc1++) { | 
|---|
| 122 | double norm1 = int_shell1_->coefficient_unnorm(gc1,p1); | 
|---|
| 123 | int am1 = int_shell1_->am(gc1); | 
|---|
| 124 | for (int gc2=0; gc2<int_shell2_->ncontraction(); gc2++) { | 
|---|
| 125 | double norm2 = int_shell2_->coefficient_unnorm(gc2,p2); | 
|---|
| 126 | int am2 = int_shell2_->am(gc2); | 
|---|
| 127 | double total_pf = over_pf * norm1 * norm2; | 
|---|
| 128 |  | 
|---|
| 129 | int k1,l1,m1,k2,l2,m2; | 
|---|
| 130 | FOR_CART(k1,l1,m1,am1) | 
|---|
| 131 | FOR_CART(k2,l2,m2,am2) | 
|---|
| 132 | *(ints_buf++) += OIX_[k1][k2] * OIY_[l1][l2] * OIZ_[m1][m2] * total_pf; | 
|---|
| 133 | END_FOR_CART | 
|---|
| 134 | END_FOR_CART | 
|---|
| 135 |  | 
|---|
| 136 | } | 
|---|
| 137 | } | 
|---|
| 138 | } | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 | if (need_cart2sph_transform) | 
|---|
| 142 | transform_contrquartets_(prim_ints_,contr_doublets_); | 
|---|
| 143 |  | 
|---|
| 144 | if (need_sort_to_shell_doublet) | 
|---|
| 145 | sort_contrdoublets_to_shelldoublet_(contr_doublets_,shell_doublet_); | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 |  | 
|---|
| 149 | void Int1eCints::overlap_sameam_general_() | 
|---|
| 150 | { | 
|---|
| 151 | int tam1 = int_shell1_->am(0); | 
|---|
| 152 | int tam2 = int_shell2_->am(0); | 
|---|
| 153 |  | 
|---|
| 154 | /* Begin loops over primitives. */ | 
|---|
| 155 | for (int p1=0; p1<int_shell1_->nprimitive(); p1++) { | 
|---|
| 156 | double a1 = int_shell1_->exponent(p1); | 
|---|
| 157 | for (int p2=0; p2<int_shell2_->nprimitive(); p2++) { | 
|---|
| 158 | double a2 = int_shell2_->exponent(p2); | 
|---|
| 159 |  | 
|---|
| 160 | double gamma = a1+a2; | 
|---|
| 161 | double oog = 1.0/gamma; | 
|---|
| 162 | double over_pf = exp(-a1*a2*doublet_info_.AB2*oog)*sqrt(M_PI*oog)*M_PI*oog; | 
|---|
| 163 |  | 
|---|
| 164 | double P[3], PA[3], PB[3], PC[3]; | 
|---|
| 165 | for(int xyz=0; xyz<3; xyz++) { | 
|---|
| 166 | P[xyz] = (a1*doublet_info_.A[xyz] + a2*doublet_info_.B[xyz])*oog; | 
|---|
| 167 | PA[xyz] = P[xyz] - doublet_info_.A[xyz]; | 
|---|
| 168 | PB[xyz] = P[xyz] - doublet_info_.B[xyz]; | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 | OI_OSrecurs_(OIX_,OIY_,OIZ_,PA,PB,gamma,tam1,tam2); | 
|---|
| 172 |  | 
|---|
| 173 | /*--- contract each buffer into appropriate location ---*/ | 
|---|
| 174 | double *ints_buf = cart_ints_; | 
|---|
| 175 | for (int gc1=0; gc1<int_shell1_->ncontraction(); gc1++) { | 
|---|
| 176 | double norm1 = int_shell1_->coefficient_unnorm(gc1,p1); | 
|---|
| 177 | for (int gc2=0; gc2<int_shell2_->ncontraction(); gc2++) { | 
|---|
| 178 | double norm2 = int_shell2_->coefficient_unnorm(gc2,p2); | 
|---|
| 179 | double total_pf = over_pf * norm1 * norm2; | 
|---|
| 180 |  | 
|---|
| 181 | int k1,l1,m1,k2,l2,m2; | 
|---|
| 182 | FOR_CART(k1,l1,m1,tam1) | 
|---|
| 183 | FOR_CART(k2,l2,m2,tam2) | 
|---|
| 184 | *(ints_buf++) += OIX_[k1][k2] * OIY_[l1][l2] * OIZ_[m1][m2] * total_pf; | 
|---|
| 185 | END_FOR_CART | 
|---|
| 186 | END_FOR_CART | 
|---|
| 187 |  | 
|---|
| 188 | } | 
|---|
| 189 | } | 
|---|
| 190 | } | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 | /*---------------------------------------------------------------------- | 
|---|
| 194 | transform to spherical harmonics and/or resort to the target ordering | 
|---|
| 195 | ----------------------------------------------------------------------*/ | 
|---|
| 196 |  | 
|---|
| 197 | /*--- sort to the target ordering ---*/ | 
|---|
| 198 | double *source_ints_buf = cart_ints_; | 
|---|
| 199 | double *target_ints_buf = target_ints_buffer_; | 
|---|
| 200 | int target_bf1_offset = 0; | 
|---|
| 201 | int target_bf2_offset = 0; | 
|---|
| 202 | int nbf2 = int_shell2_->nfunction(); | 
|---|
| 203 | for (int gc1=0; gc1<int_shell1_->ncontraction(); gc1++) { | 
|---|
| 204 | int tsize1 = INT_NCART_NN(tam1); | 
|---|
| 205 | for (int gc2=0; gc2<int_shell2_->ncontraction(); gc2++) { | 
|---|
| 206 | int tsize2 = INT_NCART_NN(tam2); | 
|---|
| 207 |  | 
|---|
| 208 | int k1,l1,m1,k2,l2,m2; | 
|---|
| 209 | int bf1 = 0; | 
|---|
| 210 | FOR_CART(k1,l1,m1,tam1) | 
|---|
| 211 | double *target_ints_buf = target_ints_buffer_ + (target_bf1_offset+bf1)*nbf2 + | 
|---|
| 212 | target_bf2_offset; | 
|---|
| 213 | FOR_CART(k2,l2,m2,tam2) | 
|---|
| 214 | *(target_ints_buf++) = *(source_ints_buf++); | 
|---|
| 215 | END_FOR_CART | 
|---|
| 216 | bf1++; | 
|---|
| 217 | END_FOR_CART | 
|---|
| 218 | target_bf2_offset += tsize2; | 
|---|
| 219 | } | 
|---|
| 220 | target_bf1_offset += tsize1; | 
|---|
| 221 | } | 
|---|
| 222 | } | 
|---|
| 223 |  | 
|---|
| 224 |  | 
|---|
| 225 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 226 |  | 
|---|
| 227 | // Local Variables: | 
|---|
| 228 | // mode: c++ | 
|---|
| 229 | // c-file-style: "CLJ" | 
|---|
| 230 | // End: | 
|---|