source: ThirdParty/mpqc_open/src/lib/chemistry/qc/mbpt/csgrads2pdm.cc@ 72461c

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 72461c was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 9.7 KB
Line 
1//
2// csgrads2pdm.cc
3// based on csgrad.cc
4//
5// Copyright (C) 1996 Limit Point Systems, Inc.
6//
7// Author: Ida Nielsen <ida@kemi.aau.dk>
8// Maintainer: LPS
9//
10// This file is part of the SC Toolkit.
11//
12// The SC Toolkit is free software; you can redistribute it and/or modify
13// it under the terms of the GNU Library General Public License as published by
14// the Free Software Foundation; either version 2, or (at your option)
15// any later version.
16//
17// The SC Toolkit is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU Library General Public License for more details.
21//
22// You should have received a copy of the GNU Library General Public License
23// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
24// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25//
26// The U.S. Government is granted a limited license as per AL 91-7.
27//
28
29#ifdef __GNUC__
30#pragma implementation
31#endif
32
33#include <stdlib.h>
34#include <math.h>
35#include <limits.h>
36
37#include <util/misc/formio.h>
38#include <util/group/message.h>
39#include <chemistry/qc/mbpt/csgrads2pdm.h>
40
41using namespace sc;
42
43CSGradS2PDM::CSGradS2PDM(int mythread_a, int nthread_a,
44 int me_a, int nproc_a,
45 const Ref<ThreadLock> &lock_a,
46 const Ref<GaussianBasisSet> &basis_a,
47 const Ref<TwoBodyDerivInt> &tbintder_a,
48 const double *PHF_a, const double *P2AO_a,
49 int tol_a, int debug_a, int dynamic_a)
50{
51 mythread = mythread_a;
52 nthread = nthread_a;
53 me = me_a;
54 nproc = nproc_a;
55 lock = lock_a;
56 basis = basis_a;
57 tbintder = tbintder_a;
58 PHF = PHF_a;
59 P2AO = P2AO_a;
60 tol = tol_a;
61 debug = debug_a;
62 dynamic = dynamic_a;
63
64 int natom = basis->molecule()->natom();
65 ginter = new double*[natom];
66 ginter[0] = new double[natom*3];
67 hf_ginter = new double*[natom];
68 hf_ginter[0] = new double[natom*3];
69 for (int i=0; i<natom; i++) {
70 ginter[i] = &ginter[0][i*3];
71 hf_ginter[i] = &hf_ginter[0][i*3];
72 for (int j=0; j<3; j++) {
73 ginter[i][j] = 0.0;
74 hf_ginter[i][j] = 0.0;
75 }
76 }
77}
78
79CSGradS2PDM::~CSGradS2PDM()
80{
81 delete[] ginter[0];
82 delete[] ginter;
83 delete[] hf_ginter[0];
84 delete[] hf_ginter;
85}
86
87void
88CSGradS2PDM::accum_contrib(double **sum, double **contribs)
89{
90 int natom = basis->molecule()->natom();
91 for (int i=0; i<natom; i++) {
92 for (int j=0; j<3; j++) {
93 sum[i][j] += contribs[i][j];
94 }
95 }
96}
97
98void
99CSGradS2PDM::accum_mp2_contrib(double **ginter_a)
100{
101 accum_contrib(ginter_a, ginter);
102}
103
104void
105CSGradS2PDM::accum_hf_contrib(double **hf_ginter_a)
106{
107 accum_contrib(hf_ginter_a, hf_ginter);
108}
109
110//////////////////////////////////////////////////////////////
111// Compute (in the AO basis) the contribution to the gradient
112// from the separable part of the two particle density matrix
113//////////////////////////////////////////////////////////////
114void
115CSGradS2PDM::run()
116{
117
118 int P, Q, R, S;
119 int QP, SR;
120 int p, q, r;
121 int np, nq, nr, ns;
122 int p_offset, q_offset, r_offset, s_offset;
123 int bf1, bf2, bf3, bf4;
124 int xyz;
125 int derset;
126 int nshell = basis->nshell();
127 int nbasis = basis->nbasis();
128
129 double *grad_ptr1, *grad_ptr2;
130 double *hf_grad_ptr1, *hf_grad_ptr2;
131 double tmpval;
132 const double *phf_pq, *phf_pr, *phf_ps, *phf_qr, *phf_qs, *phf_rs;
133 const double *p2ao_pq, *p2ao_pr, *p2ao_ps, *p2ao_qr, *p2ao_qs, *p2ao_rs;
134 double k_QP, k_SR, k_QPSR; // factors needed since we loop over nonredund
135 // shell quartets but do redund integrals within
136 // shell quartets when applicable
137 double gamma_factor; // factor multiplying integrals; needed because we
138 // loop over nonredund shell quarters but do redund
139 // integrals within shell quartets when applicable
140 double *gammasym_pqrs; // symmetrized sep. 2PDM
141 double *gammasym_ptr;
142 double *hf_gammasym_pqrs; // HF only versions of gammsym
143 double *hf_gammasym_ptr;
144 const double *integral_ptr;
145 int nfuncmax = basis->max_nfunction_in_shell();
146 const double *intderbuf = tbintder->buffer();
147
148 gammasym_pqrs = new double[nfuncmax*nfuncmax*nfuncmax*nfuncmax];
149 hf_gammasym_pqrs = new double[nfuncmax*nfuncmax*nfuncmax*nfuncmax];
150
151 DerivCenters der_centers;
152
153 int index = 0;
154 int threadindex = 0;
155
156 for (Q=0; Q<nshell; Q++) {
157 nq = basis->shell(Q).nfunction();
158 q_offset = basis->shell_to_function(Q);
159
160 for (S=0; S<=Q; S++) {
161 ns = basis->shell(S).nfunction();
162 s_offset = basis->shell_to_function(S);
163
164 for (R=0; R<=S; R++) {
165 nr = basis->shell(R).nfunction();
166 r_offset = basis->shell_to_function(R);
167 k_SR = (R == S ? 0.5 : 1.0);
168 SR = S*(S+1)/2 + R;
169
170 for (P=0; P<=(S==Q ? R:Q); P++) {
171 // If integral derivative is 0, skip to next P
172 if (tbintder->log2_shell_bound(P,Q,R,S) < tol) continue;
173
174 if (index++%nproc == me && threadindex++%nthread == mythread) {
175 np = basis->shell(P).nfunction();
176 p_offset = basis->shell_to_function(P);
177 k_QP = (P == Q ? 0.5 : 1.0);
178 QP = Q*(Q+1)/2 + P;
179 k_QPSR = (QP == SR ? 0.5 : 1.0);
180 gamma_factor = k_QP*k_SR*k_QPSR;
181
182 // Evaluate derivative integrals
183 tbintder->compute_shell(P,Q,R,S,der_centers);
184
185 //////////////////////////////
186 // Symmetrize sep. 2PDM
187 //////////////////////////////
188 gammasym_ptr = gammasym_pqrs;
189 hf_gammasym_ptr = hf_gammasym_pqrs;
190 for (bf1=0; bf1<np; bf1++) {
191 p = p_offset + bf1;
192 phf_pq = &PHF [p*nbasis + q_offset];
193 p2ao_pq = &P2AO[p*nbasis + q_offset];
194
195 for (bf2=0; bf2<nq; bf2++) {
196 q = q_offset + bf2;
197 phf_pr = &PHF [p*nbasis + r_offset];
198 p2ao_pr = &P2AO[p*nbasis + r_offset];
199 phf_qr = &PHF [q*nbasis + r_offset];
200 p2ao_qr = &P2AO[q*nbasis + r_offset];
201
202 for (bf3=0; bf3<nr; bf3++) {
203 r = r_offset + bf3;
204 phf_ps = &PHF [p*nbasis + s_offset];
205 phf_qs = &PHF [q*nbasis + s_offset];
206 phf_rs = &PHF [r*nbasis + s_offset];
207 p2ao_ps = &P2AO[p*nbasis + s_offset];
208 p2ao_qs = &P2AO[q*nbasis + s_offset];
209 p2ao_rs = &P2AO[r*nbasis + s_offset];
210
211 for (bf4=0; bf4<ns; bf4++) {
212
213 *gammasym_ptr++ = gamma_factor*(
214 4**phf_pq*(*phf_rs + *p2ao_rs)
215 + 4**phf_rs**p2ao_pq
216 - *phf_qs*(*phf_pr + *p2ao_pr)
217 - *phf_qr*(*phf_ps + *p2ao_ps)
218 - *phf_ps**p2ao_qr
219 - *phf_pr**p2ao_qs);
220
221 *hf_gammasym_ptr++ = gamma_factor*(
222 4**phf_pq*(*phf_rs)
223 - *phf_qs*(*phf_pr)
224 - *phf_qr*(*phf_ps));
225
226 phf_ps++;
227 phf_qs++;
228 phf_rs++;
229 p2ao_ps++;
230 p2ao_qs++;
231 p2ao_rs++;
232 } // exit bf4 loop
233 phf_pr++;
234 p2ao_pr++;
235 phf_qr++;
236 p2ao_qr++;
237 } // exit bf3 loop
238 phf_pq++;
239 p2ao_pq++;
240 } // exit bf2 loop
241 } // exit bf1 loop
242
243 ///////////////////////////////////////////////////////////
244 // Contract symmetrized sep 2PDM with integral derivatives
245 ///////////////////////////////////////////////////////////
246 integral_ptr = intderbuf;
247 for (derset=0; derset<der_centers.n(); derset++) {
248
249 for (xyz=0; xyz<3; xyz++) {
250 grad_ptr1 = &ginter[der_centers.atom(derset)][xyz];
251 hf_grad_ptr1 = &hf_ginter[der_centers.atom(derset)][xyz];
252 if (der_centers.has_omitted_center()) {
253 grad_ptr2 = &ginter[der_centers.omitted_atom()][xyz];
254 hf_grad_ptr2 = &hf_ginter[der_centers.omitted_atom()][xyz];
255 }
256
257 gammasym_ptr = gammasym_pqrs;
258 hf_gammasym_ptr = hf_gammasym_pqrs;
259 for (bf1=0; bf1<np; bf1++) {
260 for (bf2=0; bf2<nq; bf2++) {
261 for (bf3=0; bf3<nr; bf3++) {
262 for (bf4=0; bf4<ns; bf4++) {
263 double intval = *integral_ptr++;
264 tmpval = intval * *gammasym_ptr++;
265 *grad_ptr1 += tmpval;
266 *grad_ptr2 -= tmpval;
267 tmpval = intval * *hf_gammasym_ptr++;
268 *hf_grad_ptr1 += tmpval;
269 *hf_grad_ptr2 -= tmpval;
270 } // exit bf4 loop
271 } // exit bf3 loop
272 } // exit bf2 loop
273 } // exit bf1 loop
274 } // exit xyz loop
275 } // exit derset loop
276
277
278 } // exit "if"
279 } // exit P loop
280 } // exit R loop
281 } // exit S loop
282 } // exit Q loop
283
284 delete[] gammasym_pqrs;
285 delete[] hf_gammasym_pqrs;
286
287}
288
289////////////////////////////////////////////////////////////////////////////
290
291// Local Variables:
292// mode: c++
293// c-file-style: "CLJ-CONDENSED"
294// End:
Note: See TracBrowser for help on using the repository browser.