99
107
c If DFT get part of the exact exchange defined
102
109
if (use_theory.eq.'dft') xfac = bgj_kfac()
112
jfac(ifld) = 0.0d0 ! used in update_rhs_shfock()
113
kfac(ifld) = -1.0d0*xfac ! used in update_rhs_shfock()
114
c if (ga_nodeid().eq.0) then
115
c write(*,144) ifld,jfac(ifld),kfac(ifld)
116
c 144 format('(j,k)(',i3,')=(',f15.8,',',f15.8,')')
104
120
c Integral initialization
106
c call int_init(rtdb,1,basis)
107
c call schwarz_init(geom,basis)
121
call int_init(rtdb,1,basis)
122
call schwarz_init(geom,basis)
108
123
call hnd_giao_init(basis,1)
109
124
call scf_get_fock_param(rtdb,tol2e)
111
125
status = rtdb_parallel(.true.)
113
126
c Get Unperturbed MO vectors and eigenvalues
114
127
c First allocate some memory for occupation numbers and eigenvalues
116
128
if (.not. bas_numbf(basis,nbf)) call
117
129
& errquit('giao_b1: could not get nbf',0, BASIS_ERR)
118
130
if (.not. ma_push_get(mt_dbl,2*nbf,'occ num',l_occ,k_occ)) call
119
131
& errquit('giao_b1: ma_push_get failed k_occ',0,MA_ERR)
120
132
if (.not. ma_push_get(mt_dbl,2*nbf,'eigenval',l_eval,k_eval)) call
121
133
& errquit('giao_b1: ma_push_get failed k_eval',0,MA_ERR)
122
call hnd_prp_vec_read(rtdb,geom,basis,nbf,nclosed,nopen,
123
& nvirt,scftyp,vectors,dbl_mb(k_occ),
124
& dbl_mb(k_eval),nmo)
135
call hnd_prp_vec_read(rtdb,geom,basis, ! in : handles
136
& nbf, ! out: nr basis functions
137
& nclosed,nopen,nvirt, ! out: occupation numbers
138
& scftyp, ! out: type calc
139
& vectors, ! out: MO vectors
140
& dbl_mb(k_occ), ! out: occupations
141
& dbl_mb(k_eval), ! out: DFT energies
144
call get_nocc(rtdb, ! in : rtdb handle
145
& nocc, ! out: nr occupations
146
& npol, ! out: nr of polarization
147
& nclosed,! in : nr closed shells
148
& nopen, ! in : nr open shells
149
& nvirt, ! in : nr virtual MOs
150
& scftyp, ! in : string = UHF or RHF
151
& ntot) ! out: sum_{i,npol} nocc(i)*nvirt(i)
153
if (ga_nodeid().eq.0) then
154
write(*,10) nocc(1) ,nocc(2),
155
& nopen(1) ,nopen(2),
156
& nclosed(1),nclosed(2),
157
& nvirt(1) ,nvirt(2),scftyp,ntot
158
10 format('giao_b1_mov: nocc =(',i3,',',i3,') ',
159
& 'nopen=(',i3,',',i3,') ',
160
& 'nclos=(',i3,',',i3,') ',
161
& 'nvirt=(',i3,',',i3,') ',
162
& 'scftyp=',a,' ntot=',i3)
126
165
c Get Unperturbed Density Matrix
128
call hnd_prp_get_dens(rtdb,geom,basis,g_dens,ndens,scftyp,
129
& nclosed,nopen,nvirt)
167
call hnd_prp_get_dens(rtdb,geom,basis, ! in : handles
168
& g_dens,ndens, ! out: electron density
169
& scftyp, ! in : type calc
170
& nclosed,nopen,nvirt) ! in : occupations numbers
172
c if (ga_nodeid().eq.0) then
173
c write(*,21) npol,nocc(1) ,nocc(2),
174
c & nopen(1) ,nopen(2),
175
c & nclosed(1),nclosed(2),
176
c & nvirt(1) ,nvirt(2),scftyp,ntot
177
c 21 format('npol=',i3,' nocc =(',i3,',',i3,') ',
178
c & 'nopen=(',i3,',',i3,') ',
179
c & 'nclos=(',i3,',',i3,') ',
180
c & 'nvirt=(',i3,',',i3,') ',
181
c & 'scftyp=',a,' ntot=',i3)
131
184
if (debug) write (luout,*) 'unpertubed MOs and Pmat assembled'
133
c Error exit if scftyp equals UHF (= ROHF)
135
if (scftyp.eq.'UHF') then
136
if (ga_nodeid().eq.0) write(luout,7000)
137
call errquit('giao_b1: incompatible SCF type for Response',
141
186
c Create U matrix of dimension (nbf,nmo,3) and zero
142
187
c Use ahi for dimension and ahi array for chunking/blocking
150
if (.not.nga_create(MT_DBL,3,ahi,'U matrix',alo,g_u)) call
195
if (.not.nga_create(MT_DBL,3,ahi,'U matrix',alo,g_u(ispin))) call
151
196
& errquit('giao_b1: nga_create failed g_u',0,GA_ERR)
197
call ga_zero(g_u(ispin))
198
enddo ! end-loop-ispin
154
200
c Construction of right-hand side CPHF
155
201
c Create CPHF array of proper dimension : (nocc*nvirt,3)
157
if(.not.ga_create(MT_DBL,nclosed(1)*nvirt(1),3,'RHS',-1,-1,g_rhs))
202
ndata=2 ! 1st subspace corresponds to g_b,
203
c ! 2nd subspace corresponds to sol (if exists)
204
if (.not. rtdb_put(rtdb,'cphf2-aores:ndata',
205
& mt_int, 1,ndata)) call
206
$ errquit('fiao_b1: failed to write skew ', 0, RTDB_ERR)
207
if(.not.ga_create(MT_DBL,ntot,ndata*ndir,
208
& 'RHS',-1,-1,g_rhs))
158
209
& call errquit('giao_b1: ga_create failed g_rhs',0,GA_ERR)
159
210
call ga_zero(g_rhs)
161
c NGA dimension arrays for copying will be the same every time
162
c Also third NGA dimension for any of the three dimensional
163
c arrays will be the same everytime (running from 1 to 3)
164
c So, lets define them once and for all in blo and bhi
167
bhi(1) = nclosed(1)*nvirt(1)
171
c Get S10 in GA and transform to MO set (virt,occ)
179
if (.not.nga_create(MT_DBL,3,ahi,'s10 matrix',alo,g_s10)) call
180
& errquit('giao_b1: nga_create failed g_s01',0,GA_ERR)
182
call int_giao_1ega(basis,basis,g_s10,'s10',origin,
184
call giao_aotomo(g_s10,vectors(1),nclosed,nvirt,1,3,nbf)
186
if (debug) write (luout,*) 'S10 done'
188
c while we are calculating integrals, let's also determine
189
c the 'half' overlap derivative, used later in the calling
192
call ga_zero(g_sket1)
193
call int_giao_1ega(basis,basis,g_sket1,'srxRb',origin,
196
if (debug) write (luout,*) 'S1-ket done'
198
c g_sket1 will not be used further here. It is one of the
199
c output results of this routine.
200
c Broceed with the computation of the B-field perturbed
204
c ga_rhs(a,i) = ga_rhs(a,i) - e(i) * S10(a,i)
205
c Scale (occ,virt) block g_s10 with - (minus) eigenvalues
207
alo(1) = nclosed(1)+1
211
do iocc = 1, nclosed(1)
214
call nga_scale_patch(g_s10,alo,ahi,-dbl_mb(k_eval+iocc-1))
216
if (.not.ma_pop_stack(l_eval)) call
217
& errquit('giao_b1: ma_pop_stack failed k_eval',0,MA_ERR)
218
if (.not.ma_pop_stack(l_occ)) call
219
& errquit('giao_b1: ma_pop_stack failed k_occ',0,MA_ERR)
222
c alo(1) and ahi(1) the same as before
226
call nga_copy_patch('n',g_s10,alo,ahi,g_rhs,blo,bhi)
228
if (debug) write (luout,*) 'S10 to Umat done'
230
c Construct occ-occ part of the three U matrices
231
c Occ-occ blocks for each field direction are defined as -1/2 S10
232
c Scale (occ,occ) block g_s10 with -1/2 and add to g_u
234
c alo(2) and ahi(2) will stay as 1 and nclosed(1) for a while
238
call nga_scale_patch(g_s10,alo,ahi,-0.5d0)
239
call nga_copy_patch('n',g_s10,alo,ahi,g_u,alo,ahi)
241
if (debug) write (luout,*) 'S10 in occ-occ done'
212
c if (ga_nodeid().eq.0)
213
c & write(*,*) 'FA-BEF update_rhs_eS10'
215
c if (ga_nodeid().eq.0) then
216
c write(*,70) nocc(1) ,nocc(2),
217
c & nvirt(1) ,nvirt(2),npol,nbf,nmo
218
c 70 format('BEF-update_rhs_eS10 nocc =(',i5,',',i5,') ',
219
c & 'nvirt=(',i5,',',i5,') ',
220
c & '(npol,nbf,nmo)=(',i3,',',i3,',',i3,')')
223
call update_rhs_eS10(
227
& dbl_mb(k_eval),!in : energy values
228
& vectors, !in : MO vectors
229
& nocc, !in : nr. occupied MOs
230
& nvirt, !in : nr. unoccupied MOs
231
& npol, !in : nr. polarizations
232
& nbf, !in : nr. basis functions
234
& basis, !in : basis handle
235
& debug) !in : logical var for debugging
238
if (ga_nodeid().eq.0)
239
& write(*,*) 'FA-AFT update_rhs_eS10'
240
if (ga_nodeid().eq.0)
241
& write(*,*) '---- g_rhs-AFT-eS10-------- START'
243
if (ga_nodeid().eq.0)
244
& write(*,*) '---- g_rhs-AFT-eS10-------- END'
245
if (ga_nodeid().eq.0)
246
& write(*,*) '---- g_u-AFT-eS10-------- START'
248
call ga_print(g_u(ispin))
249
enddo ! end-loop-ispin
250
if (ga_nodeid().eq.0)
251
& write(*,*) '---- g_u-AFT-eS10-------- END'
252
if (ga_nodeid().eq.0)
253
& write(*,*) '---- g_sket1-AFT-eS10-------- START'
254
call ga_print(g_sket1)
255
if (ga_nodeid().eq.0)
256
& write(*,*) '---- g_sket1-AFT-eS10-------- END'
243
260
c We also need the occupied-occupied contribution of g_u
244
261
c contributing to the first order density matrix. As this block does
245
262
c not change during the CPHF we can calculate it once and subtract
246
263
c it from the RHS. We will reuse g_s10 as scratch space.
255
if (.not.nga_create(MT_DBL,3,clo,'Fock matrix',chi,g_fock)) call
256
& errquit('giao_b1: nga_create failed g_fock',0,GA_ERR)
257
if (.not.nga_create(MT_DBL,3,clo,'D10 matrix',chi,g_d1)) call
258
& errquit('giao_b1: nga_create failed g_d1',0,GA_ERR)
275
c Create "perturbed density matrix" for closed-closed g_u block
279
kfac(ifld) = -1.0d0*xfac
289
call nga_matmul_patch('n','n',1.0d0,0.0d0,vectors(1),blo,bhi,
290
& g_u,alo,ahi,g_s10,dlo,dhi)
295
c Minus sign as we subtract it from the RHS as we do not include
298
call nga_matmul_patch('n','t',-1.0d0,0.0d0,vectors(1),blo,bhi,
299
& g_s10,alo,ahi,g_d1,clo,chi)
302
c Build "first order fock matrix"
304
if (use_theory.eq.'dft') then
305
if(.not. rtdb_put(rtdb,'bgj:xc_active', MT_LOG, 1, .true.))
306
$ call errquit('hess_cphf: rtdb_put of xc_active failed',0,
308
if(.not. rtdb_put(rtdb,'fock_xc:calc_type', MT_INT, 1, 2))
309
$ call errquit('hess_cphf: rtdb_put of calc_type failed',0,
311
if(.not. rtdb_put(rtdb,'fock_j:derfit', MT_LOG, 1, .false.))
312
$ call errquit('hess_cphf: rtdb_put of j_derfit failed',0,
315
c call shell_fock_build(geom, basis, 0, 3,
316
c $ jfac, kfac,tol2e, g_d1, g_fock,.false.)
317
c if(use_theory.eq.'dft') then
318
c if (.not. rtdb_put(rtdb, 'fock_xc:calc_type', mt_int, 1, 0))
319
c $ call errquit('giaox: rtdb_put failed',0,RTDB_ERR)
265
call get_d1_giao_b1(g_d1, ! out:
267
& vectors,! in : MO vectors
268
& nocc, ! in : nr. occ shells
269
& npol, ! in : nr. polarizations
270
& nbf, ! in : nr. basis functions
271
& nmo, ! in : nr. MOs
272
& debug) ! in : =.true. for debugging
275
if (ga_nodeid().eq.0)
276
& write(*,*) '------- g_d1-aft-get_d1 ---- START'
278
if (ga_nodeid().eq.0)
279
& write(*,*) '------- g_d1-aft-get_d1 ---- END'
281
c if (ga_nodeid().eq.0)
282
c & write(*,*) 'FA-BEF update_rhs_shfock'
283
c if (ga_nodeid().eq.0) then
284
c write(*,71) nocc(1) ,nocc(2),
285
c & nvirt(1) ,nvirt(2),npol,nbf,nmo
286
c 71 format('BEF-update_rhs_shfock =(',i5,',',i5,') ',
287
c & 'nvirt=(',i5,',',i5,') ',
288
c & '(npol,nbf,nmo)=(',i3,',',i3,',',i3,')')
324
c Note: Just the exchange: jfac = 0.d0 (see above)
326
if (.not.cam_exch) then
327
call shell_fock_build(geom, basis, 0, 3,
328
$ jfac, kfac, tol2e, g_d1, g_fock, .false.)
330
call shell_fock_build_cam(geom, basis, 0, 3,
331
$ jfac, kfac, tol2e, g_d1, g_fock, .false.)
334
if(use_theory.eq.'dft') then
335
if (.not. rtdb_put(rtdb, 'fock_xc:calc_type', mt_int, 1, 0))
336
$ call errquit('giaox: rtdb_put failed',0,RTDB_ERR)
341
c Transform to the occ-virt MO basis and add to RHS
353
call nga_matmul_patch('n','n',2.0d0,0.0d0,
355
$ vectors(1),alo,ahi,
359
clo(2) = nclosed(1)+1
364
blo(1) = nclosed(1)+1
372
call nga_matmul_patch('t','n',1.0d0,0.0d0,
373
$ vectors(1), blo,bhi,
377
bhi(1) = nclosed(1)*nvirt(1)
380
call nga_add_patch(1.0d0,g_rhs,blo,bhi,1.0d0,g_fock,clo,chi,
383
! call nga_print_patch(g_fock,clo,chi,1)
387
c Cleanup of g_d1 and g_fock, not needed for now
291
call update_rhs_shfock(
292
& g_rhs, ! in/out: RHS used for cphf2/3
294
& vectors,! in : MO vectors
295
& rtdb, ! in : rtdb handle
296
& geom, ! in : geom handle
297
& basis, ! in : basis handle
298
& jfac, ! in : exch factors
299
& kfac, ! in : exch factors
300
& tol2e, ! in : tolerance coeff
301
& nocc, ! in : nr. occ shells
302
& nvirt, ! in : nr. virt shells
303
& npol, ! in : nr. polarizations
304
& nbf, ! in : nr. basis functions
305
& nmo, ! in : nr. MOs
306
& debug) ! in : =.true. for debugging
309
if (ga_nodeid().eq.0)
310
& write(*,*) 'FA-AFT update_rhs_shfock'
311
if (ga_nodeid().eq.0)
312
& write(*,*) '---- g_rhs-AFT-shfock-------- START'
314
if (ga_nodeid().eq.0)
315
& write(*,*) '---- g_rhs-AFT-shfock-------- END'
389
318
if (.not.ga_destroy(g_d1)) call
390
319
& errquit('giao_b1: ga_destroy failed g_d1',0,GA_ERR)
391
if (.not.ga_destroy(g_fock)) call
392
& errquit('giao_b1: ga_destroy failed g_fock',0,GA_ERR)
394
321
if (debug) write (luout,*) 'S10 Fockop done'
396
c Get H10 in GA, reusing g_s10 array
399
call int_giao_1ega(basis,basis,g_s10,'l10',origin,
401
call int_giao_1ega(basis,basis,g_s10,'tv10',origin,
404
c Get external and cosmo bq contribution
409
if(geom_extbq_on()) nextbq = geom_extbq_ncenter()
410
nbq = nextbq ! external bq's
412
if (rtdb_get(rtdb,'cosmo:nefc',mt_int,1,ncosbq))
413
& nbq = ncosbq ! cosmo bq's
415
if (nextbq.gt.0.and.ncosbq.gt.0)
416
& nbq = nextbq + ncosbq ! tally up cosmo and external bqs
418
c if (ga_nodeid().eq.0) write(6,*) "nbq: ", nbq
420
call int_giao_1ega(basis,basis,g_s10,'bq10',origin,
424
c ga_rhs(a,i) = ga_rhs(a,i) + H10(a,i)
425
c Transform H10 to MO and add to g_rhs
427
call giao_aotomo(g_s10,vectors(1),nclosed,nvirt,1,3,nbf)
428
alo(1) = nclosed(1)+1
322
c if (ga_nodeid().eq.0)
323
c & write(*,*) 'FA-BEF update_rhs_threeAOints'
325
call update_rhs_threeAOints(
326
& g_rhs, ! in/out: RHS used for cphf2/3
327
& vectors,! in : MO vectors
328
& rtdb, ! in : rtdb handle
329
& basis, ! in : basis handle
330
& nocc, ! in : nr occ shells
331
& nvirt, ! in : nr virt shells
332
& npol, ! in : nr. polarizations
333
& nbf, ! in : nr. basis functions
334
& nmo, ! in : nr. MOs
335
& debug) ! in : logical for debugging
338
if (ga_nodeid().eq.0)
339
& write(*,*) 'FA-AFT update_rhs_threeAOints'
340
if (ga_nodeid().eq.0)
341
& write(*,*) '---- g_rhs-AFT-threeAOints-------- START'
343
if (ga_nodeid().eq.0)
344
& write(*,*) '---- g_rhs-AFT-threeAOints-------- END'
347
call update_rhs_fock2e(
349
& vectors,! in : MO vectors
350
& rtdb, ! in : rtdb handle
351
& basis, ! in : basis handle
352
& geom, ! in : geom handle
353
& g_dens, ! in : e-density
354
& nocc, ! in : nr. occ shells
355
& nvirt, ! in : nr. virt shells
356
& npol, ! in : nr. polarizations
357
& nbf, ! in : nr. basis functions
358
& nmo, ! in : nr. MOs
359
& xfac, ! in : exchange factor
360
& tol2e, ! in : tolerance coeff.
361
& debug) ! in : logical for debugging
435
bhi(1) = nclosed(1)*nvirt(1)
438
call nga_add_patch(1.0d0,g_rhs,blo,bhi,1.0d0,g_s10,alo,ahi,
441
c Cleanup g_s10 as we do not need it right now
443
if (.not.ga_destroy(g_s10)) call
444
& errquit('giao_b1: ga_destroy failed g_s10',0,GA_ERR)
446
if (debug) write (luout,*) 'H10 to Umat done'
448
c Remaining term is Perturbed (GIAO) two-electron term times
449
c Unperturbed density Calculate Sum(r,s) D0(r,s) * G10(m,n,r,s) in
458
if (.not.nga_create(MT_DBL,3,ahi,'Fock matrix',alo,g_fock)) call
459
& errquit('giao_b1: nga_create failed g_fock',0,GA_ERR)
461
if(use_theory.eq.'dft') then
463
if (.not. rtdb_put(rtdb, 'fock_xc:calc_type', mt_int, 1, ifld))
464
$ call errquit('giao_b1: rtdb_put failed',0,RTDB_ERR)
466
if (debug) write (luout,*) 'calling new_giao_2e'
467
c call new_giao_2e(geom, basis, nbf, tol2e, g_dens, g_fock, xfac)
468
call new_giao_2e(geom, basis, nbf, tol2e, g_dens, g_fock, xfac,1) ! FA-restricted calc
469
if (debug) write (luout,*) 'done new_giao_2e'
470
if(use_theory.eq.'dft') then
472
if (.not. rtdb_put(rtdb, 'fock_xc:calc_type', mt_int, 1, ifld))
473
$ call errquit('giao_b1: rtdb_put failed',0,RTDB_ERR)
474
if(.not. rtdb_put(rtdb,'bgj:xc_active', MT_LOG, 1, .false.))
475
$ call errquit('giao_b1: rtdb_put of xc_active failed',0,
479
c Transform to MO basis and add to right-hand-side
481
call giao_aotomo(g_fock,vectors(1),nclosed,nvirt,1,3,nbf)
482
alo(1) = nclosed(1)+1
488
call nga_add_patch(1.0d0,g_rhs,blo,bhi,1.0d0,g_fock,alo,ahi,
490
if (.not.ga_destroy(g_fock)) call
491
& errquit('giao_b1: ga_destroy failed g_fock',0,GA_ERR)
492
call nga_scale_patch(g_rhs,blo,bhi,-4.0d0)
494
if (debug) write (luout,*) 'D00 GIAO Fock terms done'
371
call nga_scale_patch(g_rhs,blo,bhi,-4.0d0)
372
else if (npol.eq.2) then
373
call nga_scale_patch(g_rhs,blo,bhi,-2.0d0)
377
if (ga_nodeid().eq.0)
378
& write(*,*) 'FA-AFT update_rhs_fock2e'
379
if (ga_nodeid().eq.0)
380
& write(*,*) '---- g_rhs-AFT-fock2e-------- START'
382
if (ga_nodeid().eq.0)
383
& write(*,*) '---- g_rhs-AFT-fock2e-------- END'
386
call util_file_name(lbl_cphfaoresp,
387
& .false.,.false.,aorespfilename)
389
if (.not. dft_CPHF1_read( ! file exists and read g_rhs guess
390
& aorespfilename,! in: filename
391
& npol, ! in: nr polarization
392
& nocc, ! in: nr occupied MOs
393
& nvirt, ! in: nr virtual MOs
394
& 1, ! in: nr. components
395
& g_rhs, ! in: (ntot,3) GA matrix
396
& g_rhs_im, ! in: dummy
397
& .false.)) ! in: =T if (RE,IM) =F if RE
401
if (.not. rtdb_put(rtdb,'cphf2-aores:guess',
402
& mt_log, 1,.true.)) call
403
$ errquit('giao_b1: failed to write skew ', 0, RTDB_ERR)
407
if (ga_nodeid().eq.0)
408
& write(*,*) '---- g_rhs-AFT-readfile-------- START'
410
if (ga_nodeid().eq.0)
411
& write(*,*) '---- g_rhs-AFT-readfile-------- END'
414
c if (ga_nodeid().eq.0)
415
c & write(*,*) 'COMPUTE cphf giao_b1 data ...'
496
417
c Write ga_rhs to disk
498
418
call util_file_name('cphf_rhs',.true.,.true.,cphf_rhs)
499
419
call util_file_name('cphf_sol',.true.,.true.,cphf_sol)
500
420
if(.not.file_write_ga(cphf_rhs,g_rhs)) call errquit
501
421
$ ('giao_b1: could not write cphf_rhs',0, DISK_ERR)
506
423
c Call the CPHF routine
508
425
c We do need to tell the CPHF that the density is skew symmetric.
509
426
c Done via rtdb, put cphf:skew .false. on rtdb and later remove it.
511
427
if (.not. rtdb_put(rtdb, 'cphf:skew', mt_log, 1,.false.)) call
512
428
$ errquit('giao_b1: failed to write skew ', 0, RTDB_ERR)
514
429
if (debug) write (luout,*) 'calling cphf'
516
430
if (.not.cphf2(rtdb)) call errquit
517
431
$ ('giao_b1: failure in cphf ',0, RTDB_ERR)
519
432
if (.not. rtdb_delete(rtdb, 'cphf:skew')) call
520
433
$ errquit('giao_b1: rtdb_delete failed ', 0, RTDB_ERR)
522
434
if (debug) write (luout,*) 'cphf done'
524
436
c Occ-virt blocks are the solution pieces of the CPHF
525
437
c Read solution vector from disk and put solutions in U matrices
527
438
call ga_zero(g_rhs)
528
439
if(.not.file_read_ga(cphf_sol,g_rhs)) call errquit
529
$ ('giao_b1: could not read cphf_rhs',0, DISK_ERR)
530
call nga_copy_patch('n',g_rhs,blo,bhi,g_u,alo,ahi)
532
if (.not.ga_destroy(g_rhs)) call
533
& errquit('giao_b1: ga_destroy failed g_rhs',0,GA_ERR)
535
c From U matrices, generate the perturbed density matrices D1x,y,z
537
c D1 = 2[(C1*C0+) - (C0*C1+)]
545
if (.not.nga_create(MT_DBL,3,ahi,'D10 matrix',alo,g_d1)) call
546
& errquit('giao_b1: nga_create failed g_d1',0,GA_ERR)
576
call nga_matmul_patch('n','n',1.0d0,0.0d0,vectors(1),blo,bhi,
577
& g_u,alo,ahi,g_d1,dlo,dhi)
578
call nga_copy_patch('n',g_d1,dlo,dhi,g_vecB1,dlo,dhi)
580
c This patch of g_vecB1 now has the perturbed MO
581
c coefficients. let's print them for debug purposes:
583
if (.false.) then ! change .false. to debug to print them
584
write (luout,*) 'giao_b1: perturbed C, direction ',ifld
585
call nga_print_patch(g_vecB1,dlo,dhi,1)
590
if (.not.ga_destroy(g_u)) call
591
& errquit('giao_b1: ga_destroy failed g_u',0,GA_ERR)
592
if (.not.ga_destroy(g_d1)) call
593
& errquit('giao_b1: ga_destroy failed g_d1',0,GA_ERR)
594
if (.not.ga_destroy(vectors(1))) call
595
& errquit('giao_b1: ga_destroy failed vectors',0,GA_ERR)
596
if (.not.ga_destroy(g_dens(1))) call
440
$ ('giao_b1: could not read cphf_rhs',0, DISK_ERR)
443
if (ga_nodeid().eq.0)
444
& write(*,*) '---- g_rhs-BEF-write2file------- START'
446
if (ga_nodeid().eq.0)
447
& write(*,*) '---- g_rhs-BEF-write2file-------- END'
450
call util_file_name(lbl_cphfaoresp,
451
& .false.,.false.,aorespfilename)
453
status=dft_CPHF1_write(
454
& aorespfilename,! in: filename
455
& npol, ! in: nr polarization
456
& nocc, ! in: nr occupied MOs
457
& nvirt, ! in: nr virtual MOs
458
& 1, ! in: nr. components
459
& g_rhs, ! in: (ntot,3) GA matrix
460
& g_rhs_im, ! in: dummy
461
& .false.) ! in: =T if (RE,IM) =F if RE
463
c 000000000000 move 2nd subspace to 1st 00000 START
467
call ga_copy_patch('n',g_rhs,1,ntot,m1,m2,
468
$ g_rhs,1,ntot,1 ,ndir)
469
c 000000000000 move 2nd subspace to 1st 00000 END
470
c if (ga_nodeid().eq.0)
471
c & write(*,*) 'FA-BEF get_vecB1_opt2'
475
& g_rhs, ! in : g_rhs vector (occ-virt of g_u)
476
& g_u, ! in : occ-occ of g_u
477
& vectors, ! in : MO vectors
478
& nbf, ! in : nr. basis functions
479
& nmo, ! in : nr. MOs
480
& npol, ! in : nr polarizations
481
& nocc, ! in : nr. occupied MOs
482
& nvirt, ! in : nr. virtual MOs
483
& debug) ! in : = .true. allow debugging
485
c if (ga_nodeid().eq.0)
486
c & write(*,*) 'FA-AFT get_vecB1_opt2'
489
if (ga_nodeid().eq.0)
490
& write(*,*) '------- g_vecB1-gb1-nw ---- START'
492
call ga_print(g_vecB1(ispin))
494
if (ga_nodeid().eq.0)
495
& write(*,*) '------- g_vecB1-gb1-nw ---- END'
499
if (.not.ga_destroy(g_u(ispin))) call
500
& errquit('giao_b1: ga_destroy failed vectors',0,GA_ERR)
501
if (.not.ga_destroy(vectors(ispin))) call
502
& errquit('giao_b1: ga_destroy failed vectors',0,GA_ERR)
505
if (.not.ga_destroy(g_dens(ispin))) call
597
506
& errquit('giao_b1: ga_destroy failed g_dens',0,GA_ERR)
599
if (debug) write (luout,*) 'Perturbed C and Pmat done'
602
c At this point, we don't need to terminate the integrals.
603
c They were terminated by the cphf.
507
enddo ! end-loop-ispin
508
c RHS arrays are no longer needed
509
if (.not.ga_destroy(g_rhs)) call
510
& errquit('fiao_f1: ga_destroy failed g_rhs',0,GA_ERR)
609
514
7000 format(/,10x,'B-field perturbed MOs cannot be calculated for',