1
subroutine update_rhs_fock2e(
3
& vectors,! in : MO vectors
4
& rtdb, ! in : rtdb handle
5
& basis, ! in : basis handle
6
& geom, ! in : geom handle
7
& g_dens, ! in : e-density
8
& nocc, ! in : nr. occ shells
9
& nvirt, ! in : nr. virt shells
10
& npol, ! in : nr. polarizations
11
& nbf, ! in : nr. basis functions
13
& xfac, ! in : exchange factor
14
& tol2e, ! in : tolerance coeff.
15
& debug) ! in : logical for debugging
17
c Author : Fredy W. Aquino
19
c Note.- Modified from original aoresponse source code
20
c for extension to spin-unrestricted case
21
c original aoresponse source code was written by
22
c J. Autschbach and appears on nwchem-devtrunk (date:03-02-12)
23
c --> Experimental (not published yet)
28
#include "mafdecls.fh"
36
integer rtdb,basis,geom
38
integer vectors(npol),g_dens(3)
39
integer ifld,ndir,nbf,nmo,disp,shift,
40
& nocc(npol),nvirt(npol)
41
double precision tol2e,xfac
42
integer alo(3), ahi(3),
45
external new_giao_2e,giao_aotomo
46
ndir=3 ! = nr directions (x,y,z)
47
c Remaining term is Perturbed (GIAO) two-electron term times
48
c Unperturbed density Calculate Sum(r,s) D0(r,s) * G10(m,n,r,s) in
56
if (.not.nga_create(MT_DBL,ndir,ahi,'Fock matrix',
58
& errquit('giao_b1: nga_create failed g_fock',0,GA_ERR)
60
if(use_theory.eq.'dft') then
62
if (.not. rtdb_put(rtdb,'fock_xc:calc_type',mt_int,1,ifld))
63
$ call errquit('giao_b1: rtdb_put failed',0,RTDB_ERR)
66
call new_giao_2e(geom,basis,nbf,tol2e,
67
& g_dens, ! in: e-denstiy
68
& g_fock, ! out: fock matrix
72
if(use_theory.eq.'dft') then
74
if (.not. rtdb_put(rtdb, 'fock_xc:calc_type', mt_int, 1, ifld))
75
$ call errquit('giao_b1: rtdb_put failed',0,RTDB_ERR)
76
if(.not. rtdb_put(rtdb,'bgj:xc_active', MT_LOG, 1, .false.))
77
$ call errquit('giao_b1: rtdb_put of xc_active failed',0,
81
c Transform to MO basis and add to right-hand-side
82
call giao_aotomo(g_fock,vectors,nocc,nvirt,npol,ndir,nbf)
85
alo(1) = nocc(ispin)+1
91
shift=nocc(1)*nvirt(1)*(ispin-1)
93
bhi(1) = shift+nocc(ispin)*nvirt(ispin)
96
call nga_add_patch(1.0d0, g_rhs,blo,bhi,
97
& 1.0d0,g_fock,alo,ahi,
99
enddo ! end-loop-ispin
101
if (ga_nodeid().eq.0)
102
& write(*,*) '------- g_fock2e-nw ---- START'
103
call ga_print(g_fock)
104
if (ga_nodeid().eq.0)
105
& write(*,*) '------- g_fock2e-nw ---- END'
107
if (.not.ga_destroy(g_fock)) call
108
& errquit('giao_b1: ga_destroy failed g_fock',0,GA_ERR)
112
subroutine update_rhs_shfock(g_rhs, ! in/out: RHS used for cphf2/3
114
& vectors,! in : MO vectors
115
& rtdb, ! in : rtdb handle
116
& geom, ! in : geom handle
117
& basis, ! in : basis handle
118
& jfac, ! in : exch factors
119
& kfac, ! in : exch factors
120
& tol2e, ! in : tolerance coeff
121
& nocc, ! in : nr occ shells
122
& nvirt, ! in : nr vir shells
123
& npol, ! in : nr. polarizations
124
& nbf, ! in : nr. basis functions
125
& nmo, ! in : nr. MOs
126
& debug) ! in : =.true. for debugging
128
c Purpose: Updating g_rhs with g_fock from shell_fock_build()
129
c Author : Fredy W. Aquino
131
c Note.- Modified from original aoresponse source code
132
c for extension to spin-unrestricted case
133
c original aoresponse source code was written by
134
c J. Autschbach and appears on nwchem-devtrunk (date:03-02-12)
136
c --> Experimental (not published yet)
139
#include "errquit.fh"
141
#include "mafdecls.fh"
151
& g_d1,g_d2,g_fock,g_s10
152
integer geom,basis,rtdb
153
integer npol,disp,ndens,ispin
154
integer vectors(npol),nocc(npol),nvirt(npol)
155
integer ifld,ndir,nbf,nmo,shift
156
integer alo(3), ahi(3),
160
double precision jfac(12),kfac(12),tol2e
161
external shell_fock_build,
162
& shell_fock_build_cam,
163
& add_fock ! located in hnd_shift_zora.F
164
ndir=3 ! nr directions (x,y,z)
165
c -------- Creating g_d2 ---------------START
166
c Note.- g_d2 =(g_d1 g_d1)
174
if (.not.nga_create(MT_DBL,3,clo,'g_d2 matrix',
176
& call errquit('gprelim_fock: nga_create failed g_d2',
193
call nga_copy_patch('n',g_d1,blo,bhi,
195
enddo ! end-loop-ispin
196
c -------- Creating g_d2 ---------------END
197
c Build "first order fock matrix"
198
if (use_theory.eq.'dft') then
199
if(.not. rtdb_put(rtdb,'bgj:xc_active', MT_LOG, 1, .true.))
200
$ call errquit('hess_cphf: rtdb_put of xc_active failed',0,
202
if(.not. rtdb_put(rtdb,'fock_xc:calc_type', MT_INT, 1, 2))
203
$ call errquit('hess_cphf: rtdb_put of calc_type failed',0,
205
if(.not. rtdb_put(rtdb,'fock_j:derfit', MT_LOG, 1, .false.))
206
$ call errquit('hess_cphf: rtdb_put of j_derfit failed',0,
215
if (.not.nga_create(MT_DBL,3,clo,'Fock matrix',chi,g_fock)) call
216
& errquit('giao_b1: nga_create failed g_fock',0,GA_ERR)
218
c if (ga_nodeid().eq.0)
219
c & write(*,*) 'cam_exch=',cam_exch
221
c Note: Just the exchange: jfac = 0.d0 (see above)
222
if (.not.cam_exch) then
224
call shell_fock_build(geom, basis,0,ndir*npol*2,
232
call shell_fock_build_cam(geom, basis,0,ndir*npol*2,
240
c if (ga_nodeid().eq.0) then
241
c write(*,70) nocc(1) ,nocc(2),
242
c & nvirt(1) ,nvirt(2),npol,nbf,nmo
243
c 70 format('BEF_add_fock:: nocc =(',i5,',',i5,') ',
244
c & 'nvirt=(',i5,',',i5,') ',
245
c & '(npol,nbf,nmo)=(',i3,',',i3,',',i3,')')
250
if (ga_nodeid().eq.0)
251
& write(*,*) '------- g_fock-nw ---- START'
252
call ga_print(g_fock)
253
if (ga_nodeid().eq.0)
254
& write(*,*) '------- g_fock-nw ---- END'
256
if(use_theory.eq.'dft') then
257
if (.not. rtdb_put(rtdb, 'fock_xc:calc_type', mt_int, 1, 0))
258
$ call errquit('giaox: rtdb_put failed',0,RTDB_ERR)
260
c Note.- add_fock() is defined in hnd_gshift_zora.F
262
call add_fock(g_rhs, ! out: accumulated rhs expression
263
& g_fock, ! in: Fock-term
264
& vectors, ! in: MO coeffs
265
& nbf, ! in: nr. basis functions
266
& nmo, ! in: nr. MOs (occ+virt)
267
& npol, ! in: nr. of polarizations
268
& nocc, ! in: nr. occ MOs
269
& nvirt) ! in: nr. virtual MOs
272
if (ga_nodeid().eq.0)
273
& write(*,*) '---- g_rhs-AFT-shfock-inside-- START'
275
if (ga_nodeid().eq.0)
276
& write(*,*) '---- g_rhs-AFT-shfock-inside--- END'
278
if (.not.ga_destroy(g_d2)) call
279
& errquit('giao_b1: ga_destroy failed g_fock',0,GA_ERR)
280
if (.not.ga_destroy(g_fock)) call
281
& errquit('giao_b1: ga_destroy failed g_fock',0,GA_ERR)
285
subroutine get_d1_giao_b1(g_d1, ! out:
287
& vectors,! in : MO vectors
288
& nocc, ! in : nr. occ shells
289
& npol, ! in : nr. polarizations
290
& nbf, ! in : nr. basis functions
291
& nmo, ! in : nr. MOs
292
& debug) ! in : =.true. for debugging
294
c Purpose: get_d1 in giao_b1_movecs()
295
c Author : Fredy W. Aquino
297
c Note.- Modified from original aoresponse source code
298
c for extension to spin-unrestricted case
299
c original aoresponse source code was written by
300
c J. Autschbach and appears on nwchem-devtrunk (date:03-02-12)
301
c --> Experimental (not published yet)
304
#include "errquit.fh"
306
#include "mafdecls.fh"
312
integer vectors(npol),nocc(npol),
314
integer ifld,ndir,nbf,nmo,disp
315
integer alo(3), ahi(3),
320
ndir=3 ! nr directions (x,y,z)
327
if (.not.nga_create(MT_DBL,3,ahi,'s10 matrix',alo,g_s10)) call
328
& errquit('giao_b1: nga_create failed g_s01',0,GA_ERR)
335
if (.not.nga_create(MT_DBL,3,clo,'D10 matrix',chi,g_d1)) call
336
& errquit('giao_b1: nga_create failed g_d1',0,GA_ERR)
351
disp=ndir*(ispin-1) ! for (clo,chi)
352
c Create "perturbed density matrix" for closed-closed g_u block
364
if (ga_nodeid().eq.0) then
366
& alo(1),ahi(1),alo(2),ahi(2),
368
& blo(1),bhi(1),blo(2),bhi(2),
370
& dlo(1),dhi(1),dlo(2),dhi(2),
372
17 format('1(',i3,')::alo-ahi=(',i3,',',i3,',',
373
& i3,',',i3,',',i3,',',i3,') ',
374
& 'blo-bhi=(',i3,',',i3,',',
375
& i3,',',i3,',',i3,',',i3,') ',
376
& 'dlo-dhi=(',i3,',',i3,',',
377
& i3,',',i3,',',i3,',',i3,') ')
380
call nga_matmul_patch('n','n',1.0d0,0.0d0,
381
& vectors(ispin),blo,bhi,
382
& g_u(ispin) ,alo,ahi,
387
ahi(2) = nbf ! nmo fix lindep 05-02-12
393
c Minus sign as we subtract it from the RHS as we do not include
396
if (ga_nodeid().eq.0) then
398
& alo(1),ahi(1),alo(2),ahi(2),
400
& blo(1),bhi(1),blo(2),bhi(2),
402
& clo(1),chi(1),clo(2),chi(2),
404
16 format('2(',i3,')::alo-ahi=(',i3,',',i3,',',
405
& i3,',',i3,',',i3,',',i3,') ',
406
& 'blo-bhi=(',i3,',',i3,',',
407
& i3,',',i3,',',i3,',',i3,') ',
408
& 'clo-chi=(',i3,',',i3,',',
409
& i3,',',i3,',',i3,',',i3,') ')
412
call nga_matmul_patch('n','t',-1.0d0,0.0d0,
413
& vectors(ispin),blo,bhi,
415
& g_d1,clo,chi) ! nbf x nbf for (dir,ispin)
416
enddo ! end-loop-ifld
417
enddo ! end-loop-ispin
418
if (.not.ga_destroy(g_s10)) call
419
& errquit('giao_b1: ga_destroy failed g_s10',0,GA_ERR)
423
subroutine update_rhs_threeAOints(
424
& g_rhs, ! in/out: RHS used for cphf2/3
425
& vectors,! in : MO vectors
426
& rtdb, ! in : rtdb handle
427
& basis, ! in : basis handle
428
& nocc, ! in : nr occ shells
429
& nvirt, ! in : nr virt shells
430
& npol, ! in : nr. polarizations
431
& nbf, ! in : nr. basis functions
432
& nmo, ! in : nr. MOs
433
& debug) ! in : logical for debugging
435
c Author : Fredy W. Aquino
437
c Note.- Modified from original aoresponse source code
438
c for extension to spin-unrestricted case
439
c original aoresponse source code was written by
440
c J. Autschbach and appears on nwchem-devtrunk (date:03-02-12)
441
c --> Experimental (not published yet)
444
#include "errquit.fh"
446
#include "mafdecls.fh"
457
integer g_rhs,g_s10,g_s10_1,vectors(npol)
459
integer nocc(npol),nvirt(npol),disp,shift,ispin
460
integer ifld,ndir,nbf,nmo
461
integer alo(3),ahi(3),
463
integer nbq,nextbq,ncosbq ! for COSMO (adding solvent effects)
467
double precision origin(3)
468
data origin/0d0,0d0,0d0/
470
c external geom_extbq_ncenter
471
c Current CPHF does not handle symmetry
472
c Making C1 geometry and store it on rtdb
474
ndir=3 ! nr directions (x,y,z)
475
c Get H10 in GA, reusing g_s10 array
482
if (.not.nga_create(MT_DBL,3,ahi,'s10 matrix',
484
& call errquit('gprelim_fock: nga_create failed g_s10_1',
486
call ga_zero(g_s10_1)
488
if (.not.nga_create(MT_DBL,3,ahi,'s10 matrix',
490
& call errquit('gprelim_fock: nga_create failed g_s10',
493
call int_giao_1ega(basis,basis,
494
& g_s10_1,'l10', ! out: g_s10
496
call int_giao_1ega(basis,basis,
497
& g_s10_1,'tv10', ! out: g_s10 updated
500
c Get external and cosmo bq contribution
504
if(geom_extbq_on()) nextbq = geom_extbq_ncenter()
505
nbq = nextbq ! external bq's
506
if (rtdb_get(rtdb,'cosmo:nefc',mt_int,1,ncosbq))
507
& nbq = ncosbq ! cosmo bq's
508
if (nextbq.gt.0.and.ncosbq.gt.0)
509
& nbq = nextbq + ncosbq ! tally up cosmo and external bqs
511
c if (ga_nodeid().eq.0) write(6,*) "nbq: ", nbq
513
call int_giao_1ega(basis,basis,
514
& g_s10_1,'bq10', ! out
517
c --------- g_s10_1 --> g_s10 --------- START
519
bhi(1) = nbf ! nmo fix lindep 05-02-12
521
bhi(2) = nbf ! nmo fix lindep 05-02-12
527
ahi(1) = nbf ! nmo fix lindep 05-02-12
529
ahi(2) = nbf ! nmo fix lindep 05-02-12
532
call nga_copy_patch('n',g_s10_1,blo,bhi,
534
enddo ! end-loop-ispin
535
c --------- g_s10_1 --> g_s10 --------- END
536
if (.not.ga_destroy(g_s10_1)) call
537
& errquit('giao_b1: ga_destroy failed g_s10',0,GA_ERR)
539
c ga_rhs(a,i) = ga_rhs(a,i) + H10(a,i)
540
c Transform H10 to MO and add to g_rhs
541
call giao_aotomo(g_s10,vectors,nocc,nvirt,npol,ndir,nbf)
544
alo(1) = nocc(ispin)+1
550
shift=nocc(1)*nvirt(1)*(ispin-1)
552
bhi(1) = shift+nocc(ispin)*nvirt(ispin)
555
call nga_add_patch(1.0d0,g_rhs,blo,bhi,
556
& 1.0d0,g_s10,alo,ahi,
558
enddo ! end-loop-ispin
559
c if (ga_nodeid().eq.0)
560
c & write(*,*) '------- g_s10-nw ---- START'
561
c call ga_print(g_s10)
562
c if (ga_nodeid().eq.0)
563
c & write(*,*) '------- g_s10-nw ---- END'
565
c Cleanup g_s10 as we do not need it right now
566
if (.not.ga_destroy(g_s10)) call
567
& errquit('giao_b1: ga_destroy failed g_s10',0,GA_ERR)
571
subroutine update_rhs_eS10(
575
& eval, !in : energy values
576
& vectors,!in : MO vectors
577
& nocc, !in : nr. occupied MOs
578
& nvirt, !in : nr. unoccupied MOs
579
& npol, !in : nr. polarizations
580
& nbf, !in : nr. basis functions
582
& basis, !in : basis handle
583
& debug) !in : logical var for debugging
585
c Author : Fredy W. Aquino
587
c Note.- Modified from original aoresponse source code
588
c for extension to spin-unrestricted case
589
c original aoresponse source code was written by
590
c J. Autschbach and appears on nwchem-devtrunk (date:03-02-12)
591
c --> Experimental (not published yet)
594
#include "errquit.fh"
596
#include "mafdecls.fh"
608
integer vectors(npol)
609
integer nocc(npol),nvirt(npol),
610
& iocc,disp,disp1,ispin,
615
double precision eval(nmo*npol),toscl
616
integer g_rhs,g_u(npol),g_s10,g_s10_1,g_sket1
617
double precision origin(3)
618
data origin/0d0,0d0,0d0/
622
c Current CPHF does not handle symmetry
623
c Making C1 geometry and store it on rtdb
625
ndir=3 ! nr. directions (x,y,z)
626
c NGA dimension arrays for copying will be the same every time
627
c Also third NGA dimension for any of the three dimensional
628
c arrays will be the same everytime (running from 1 to 3)
629
c So, lets define them once and for all in blo and bhi
630
c Get S10 in GA and transform to MO set (virt,occ)
637
if (.not.nga_create(MT_DBL,3,ahi,'s10 matrix',alo,g_s10_1)) call
638
& errquit('giao_b1: nga_create failed g_s01',0,GA_ERR)
639
call ga_zero(g_s10_1)
641
if (.not.nga_create(MT_DBL,3,ahi,'s10 matrix',
643
& call errquit('gprelim_fock: nga_create failed g_s10',
646
call int_giao_1ega(basis,basis,
647
& g_s10_1,'s10', ! out: g_s10 FA-LBL-B
649
c -------- create g_s10 --------------- START
651
bhi(1) = nbf ! nmo fix-lindep 05-02-12
653
bhi(2) = nbf ! nmo fix-lindep 05-02-12
659
ahi(1) = nbf ! nmo fix-lindep 05-02-12
661
ahi(2) = nbf ! nmo fix-lindep 05-02-12
664
call nga_copy_patch('n',g_s10_1,blo,bhi,
666
enddo ! end-loop-ispin
667
if (.not.ga_destroy(g_s10_1)) call
668
& errquit('giao_b1: ga_destroy failed vectors',0,GA_ERR)
669
c -------- create g_s10 --------------- END
670
c After giao_aotomo valid dim(g_s10): nmo x nmo
671
call giao_aotomo(g_s10,vectors,nocc,nvirt,npol,ndir,nbf)
672
if (debug) write (luout,*) 'S10 done'
673
c while we are calculating integrals, let's also determine
674
c the 'half' overlap derivative, used later in the calling
676
call ga_zero(g_sket1)
677
call int_giao_1ega(basis,basis,
678
& g_sket1,'srxRb', ! out: g_sket1 FA-LBL-A
680
if (debug) write (luout,*) 'S1-ket done'
681
c g_sket1 will not be used further here. It is one of the
682
c output results of this routine.
683
c Broceed with the computation of the B-field perturbed
686
c ga_rhs(a,i) = ga_rhs(a,i) - e(i) * S10(a,i)
687
c Scale (occ,virt) block g_s10 with - (minus) eigenvalues
689
alo(1) = nocc(ispin)+1
699
c disp = nmo*(ispin-1)
700
disp = nbf*(ispin-1) ! fix-lindep 05-02-12
701
do iocc=1,nocc(ispin)
704
toscl =-eval(disp+iocc)
705
call nga_scale_patch(g_s10,alo,ahi,toscl)
706
enddo ! end-loop-iocc
708
c alo(1) and ahi(1) the same as before
711
shift=nocc(1)*nvirt(1)*(ispin-1)
713
bhi(1) = shift+nocc(ispin)*nvirt(ispin)
716
call nga_copy_patch('n',g_s10,alo,ahi,
719
c Construct occ-occ part of the three U matrices
720
c Occ-occ blocks for each field direction are defined as -1/2 S10
721
c Scale (occ,occ) block g_s10 with -1/2 and add to g_u
722
c alo(2) and ahi(2) will stay as 1 and nclosed(1) for a while
725
call nga_scale_patch(g_s10,alo,ahi,-0.5d0)
726
call nga_copy_patch('n',g_s10 ,alo,ahi,
727
& g_u(ispin),clo,chi)
728
enddo ! end-loop-ispin
729
if (debug) write (luout,*) 'S10 in occ-occ done'
730
if (.not.ga_destroy(g_s10)) call
731
& errquit('giao_b1: ga_destroy failed vectors',0,GA_ERR)