-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm_pawdij.F90
5700 lines (5105 loc) · 211 KB
/
m_pawdij.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!!****m* ABINIT/m_pawdij
!! NAME
!! m_pawdij
!!
!! FUNCTION
!! This module contains several routines used to compute the PAW pseudopotential
!! strengths Dij. The Dijs define the non-local PAW operator:
!! VNL = Sum_ij [ Dij |pi><pj| ], with pi, pj= projectors
!!
!! COPYRIGHT
!! Copyright (C) 2013-2022 ABINIT group (MT, FJ, BA, JWZ)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!! For the initials of contributors, see ~abinit/doc/developers/contributors.txt.
!!
!! NOTES
!! FOR DEVELOPPERS: in order to preserve the portability of libPAW library,
!! please consult ~abinit/src/??_libpaw/libpaw-coding-rules.txt
!!
!! SOURCE
#include "libpaw.h"
MODULE m_pawdij
USE_DEFS
USE_MSG_HANDLING
USE_MPI_WRAPPERS
USE_MEMORY_PROFILING
use m_paral_atom, only : get_my_atmtab, free_my_atmtab
use m_paw_io, only : pawio_print_ij
use m_pawang, only : pawang_type
use m_pawrad, only : pawrad_type, pawrad_deducer0, simp_gen, nderiv_gen
use m_pawtab, only : pawtab_type
use m_paw_an, only : paw_an_type
use m_paw_ij, only : paw_ij_type, paw_ij_print
use m_pawfgrtab, only : pawfgrtab_type
use m_pawrhoij, only : pawrhoij_type
use m_paw_finegrid, only : pawgylm, pawexpiqr
use m_paw_sphharm, only : slxyzs
implicit none
private
!public procedures.
public :: pawdij ! Dij total
public :: pawdijhartree ! Dij Hartree
public :: pawdijfock ! Dij Fock exact-exchange
public :: pawdijxc ! Dij eXchange-Correlation (using (r,theta,phi) grid)
public :: pawdijxcm ! Dij eXchange-Correlation (using (l,m) moments)
public :: pawdijhat ! Dij^hat (compensation charge contribution)
public :: pawdijnd ! Dij nuclear dipole
public :: pawdijso ! Dij spin-orbit
public :: pawdiju ! Dij DFT+U
public :: pawdiju_euijkl ! Dij DFT+U, using pawrhoij instead of occupancies
public :: pawdijexxc ! Dij local exact-exchange
public :: pawdijfr ! 1st-order frozen Dij
public :: pawpupot ! On-site DFT+U potential
public :: pawxpot ! On-site local exact-exchange potential
public :: symdij ! Symmetrize total Dij or one part of it
public :: symdij_all ! Symmetrize all contributions to Dij
public :: pawdij_gather ! Perform a allgather operation on Dij
public :: pawdij_print_dij ! Print out a Dij matrix
!!***
CONTAINS
!===========================================================
!!***
!----------------------------------------------------------------------
!!****f* m_pawdij/pawdij
!! NAME
!! pawdij
!!
!! FUNCTION
!! Compute the pseudopotential strengths Dij of the PAW non local operator as sum of
!! several contributions. Can compute first-order strenghts Dij for RF calculations.
!! This routine is a driver calling, for each contribution to Dij, a specific
!! routines.
!! Within standard PAW formalism, Dij can be decomposd as follows:
!! Dij = Dij_atomic + Dij_Hartree + Dij_XC + Dij^hat
!! In case of additional approximations, several other terms can appear:
!! Dij_DFT+U, Dij_spin-orbit, Dij_local-exact-exchange, Dij_Fock...
!!
!! INPUTS
!! cplex=1 if no phase is applied (GS), 2 if a exp(-iqr) phase is applied (Response Function at q<>0)
!! enunit=choice for units of output Dij
!! gprimd(3,3)=dimensional primitive translations for reciprocal space
!! [hyb_mixing, hyb_mixing_sr]= -- optional-- mixing factors for the global (resp. screened) XC hybrid functional
!! ipert=index of perturbation (used only for RF calculation ; set ipert<=0 for GS calculations.
!! my_natom=number of atoms treated by current processor
!! natom=total number of atoms in cell
!! nfft=number of real space grid points (for current proc)
!! nfftot=total number of real space grid points
!! nspden=number of spin-density components
!! ntypat=number of types of atoms in unit cell.
!! paw_an(my_natom) <type(paw_an_type)>=paw arrays given on angular mesh
!! paw_ij(my_natom) <type(paw_ij_type)>=paw arrays given on (i,j) channels
!! pawang <type(pawang_type)>=paw angular mesh and related data
!! pawfgrtab(my_natom) <type(pawfgrtab_type)>=atomic data given on fine rectangular grid
!! pawprtvol=control print volume and debugging output for PAW
!! pawrad(ntypat) <type(pawrad_type)>=paw radial mesh and related data
!! pawrhoij(my_natom) <type(pawrhoij_type)>= paw rhoij occupancies and related data
!! pawspnorb=flag: 1 if spin-orbit coupling is activated
!! pawtab(ntypat) <type(pawtab_type)>=paw tabulated starting data
!! pawxcdev=Choice of XC development (0=no dev. (use of angular mesh) ; 1 or 2=dev. on moments)
!! qphon(3)=wavevector of the phonon
!! spnorbscl=scaling factor for spin-orbit coupling
!! ucvol=unit cell volume
!! vtrial(cplex*nfft,nspden)=GS potential on real space grid
!! vxc(cplex*nfft,nspden)=XC potential (Hartree) on real space grid
!! xred(3,my_natom)= reduced atomic coordinates
!! ======== Optional arguments ==============
!! Parallelism over atomic sites:
!! mpi_atmtab(:)=indexes of the atoms treated by current proc
!! comm_atom=MPI communicator over atoms
!! mpi_comm_grid=MPI communicator over real space grid points
!! Application of a potential energy shift on atomic sites:
!! natvshift=number of atomic potential energy shifts (per atom) ; default=0
!! atvshift(natvshift,nsppol,natom)=potential energy shift for lm channel & spin & atom
!! fatvshift=factor that multiplies atvshift
!! Electrons-positron 2-component DFT:
!! electronpositron_calctype=type of calculation for electron-positron 2component-DFT:
!! 0: standard DFT (no positron) ; default value
!! 1: positron in the constant electrons potential
!! 2: electrons in the constant positron potential
!! electronpositron_pawrhoij(my_natom) <type(pawrhoij_type)>=
!! PAW occupation matrix of the "constant" particle(s)
!! (electrons if calctype=1, positron if calctype=2)
!! electronpositron_lmselect(lmmax,my_natom)=
!! Flags selecting the non-zero LM-moments of on-site densities
!! for the "constant" particle(s)
!! (electrons if calctype=1, positron if calctype=2)
!!
!! OUTPUT
!! paw_ij(iatom)%dij(cplex_dij*qphase*lmn2_size,ndij)= total Dij terms (GS calculation, ipert=0)
!! total 1st-order Dij terms (RF ccalc., ipert>0)
!! May be complex if cplex_dij=2
!! dij(:,1) contains Dij^up-up
!! dij(:,2) contains Dij^dn-dn
!! dij(:,3) contains Dij^up-dn (only if nspinor=2)
!! dij(:,4) contains Dij^dn-up (only if nspinor=2)
!! May also compute paw_ij(iatom)%dij0,paw_ij(iatom)%dijhartree,paw_ij(iatom)%dijxc,
!! paw_ij(iatom)%dijxc_hat,paw_ij(iatom)%dijxc_val,
!! paw_ij(iatom)%dijhat,paw_ij(iatom)dijso,
!! paw_ij(iatom)%dijU,paw_ij(iatom)%dijexxc,paw_ij(iatom)%dijfock
!!
!! NOTES
!! Response function calculations:
!! In order to compute first-order Dij, paw_an (resp. paw_ij) datastructures
!! must contain first-order quantities, namely paw_an1 (resp. paw_ij1).
!!
!! SOURCE
subroutine pawdij(cplex,enunit,gprimd,ipert,my_natom,natom,nfft,nfftot,nspden,ntypat,&
& paw_an,paw_ij,pawang,pawfgrtab,pawprtvol,pawrad,pawrhoij,pawspnorb,pawtab,&
& pawxcdev,qphon,spnorbscl,ucvol,charge,vtrial,vxc,xred,&
& electronpositron_calctype,electronpositron_pawrhoij,electronpositron_lmselect,&
& atvshift,fatvshift,natvshift,nucdipmom,&
& mpi_atmtab,comm_atom,mpi_comm_grid,hyb_mixing,hyb_mixing_sr)
!Arguments ---------------------------------------------
!scalars
integer,intent(in) :: cplex,enunit,ipert,my_natom,natom,nfft,nfftot
integer,intent(in) :: nspden,ntypat,pawprtvol,pawspnorb,pawxcdev
integer,optional,intent(in) :: electronpositron_calctype
integer,optional,intent(in) :: comm_atom,mpi_comm_grid,natvshift
real(dp),intent(in) :: spnorbscl,ucvol,charge
real(dp),intent(in),optional ::fatvshift,hyb_mixing,hyb_mixing_sr
type(pawang_type),intent(in) :: pawang
!arrays
integer,optional,target,intent(in) :: mpi_atmtab(:)
logical,optional,intent(in) :: electronpositron_lmselect(:,:)
real(dp),intent(in) :: gprimd(3,3),qphon(3)
real(dp),intent(in) :: vxc(:,:),xred(3,natom)
real(dp),intent(in),target :: vtrial(cplex*nfft,nspden)
real(dp),intent(in),optional :: atvshift(:,:,:)
real(dp),intent(in),optional :: nucdipmom(3,natom)
type(paw_an_type),intent(in) :: paw_an(my_natom)
type(paw_ij_type),target,intent(inout) :: paw_ij(my_natom)
type(pawfgrtab_type),intent(inout) :: pawfgrtab(my_natom)
type(pawrad_type),intent(in) :: pawrad(ntypat)
type(pawrhoij_type),intent(inout) :: pawrhoij(my_natom)
type(pawrhoij_type),intent(in),optional :: electronpositron_pawrhoij(:)
type(pawtab_type),intent(in) :: pawtab(ntypat)
!Local variables ---------------------------------------
!scalars
!Possible algos for PAW+U: 1=using occupation matrix n_i,,2=using PAW matrix rho_ij
integer, parameter :: PAWU_ALGO_1=1,PAWU_ALGO_2=2
integer, parameter :: PAWU_FLL=1,PAWU_AMF=2
integer :: cplex_dij,iatom,iatom_tot,idij,ipositron,itypat,klmn,klmn1,lm_size,lmn2_size
integer :: lpawu,my_comm_atom,my_comm_grid,natvshift_,ndij,nsploop,nsppol
integer :: pawu_algo,pawu_dblec,qphase,usekden,usepawu,usexcnhat
logical :: dij_available,dij_need,dij_prereq
logical :: dij0_available,dij0_need,dij0_prereq
logical :: dijexxc_available,dijexxc_need,dijexxc_prereq
logical :: dijfock_available,dijfock_need,dijfock_prereq
logical :: dijhartree_available,dijhartree_need,dijhartree_prereq
logical :: dijhat_available,dijhat_need,dijhat_prereq
logical :: dijhatfr_available,dijhatfr_need,dijhatfr_prereq
logical :: dijnd_available,dijnd_need,dijnd_prereq
logical :: dijso_available,dijso_need,dijso_prereq
logical :: dijxc_available,dijxc_need,dijxc_prereq
logical :: dijxchat_available,dijxchat_need,dijxchat_prereq
logical :: dijxcval_available,dijxcval_need,dijxcval_prereq
logical :: dijU_available,dijU_need,dijU_prereq
logical :: has_nucdipmom,my_atmtab_allocated
logical :: need_to_print,paral_atom,v_dijhat_allocated
real(dp) :: hyb_mixing_,hyb_mixing_sr_
character(len=500) :: msg
!arrays
integer,pointer :: my_atmtab(:)
logical,allocatable :: lmselect(:)
real(dp),allocatable :: dij0(:),dijhartree(:)
real(dp),allocatable :: dijhat(:,:),dijexxc(:,:),dijfock_cv(:,:),dijfock_vv(:,:),dijpawu(:,:)
real(dp),allocatable :: dijnd(:,:),dijso(:,:),dijxc(:,:),dij_ep(:),dijxchat(:,:),dijxcval(:,:)
real(dp),pointer :: v_dijhat(:,:),vpawu(:,:,:,:),vpawx(:,:,:)
! *************************************************************************
!------------------------------------------------------------------------
!----- Check consistency of arguments
!------------------------------------------------------------------------
! === Check optional arguments ===
hyb_mixing_ =zero ; if(present(hyb_mixing)) hyb_mixing_ =hyb_mixing
hyb_mixing_sr_=zero ; if(present(hyb_mixing_sr)) hyb_mixing_sr_=hyb_mixing_sr
natvshift_=0;if (present(natvshift)) natvshift_=natvshift
if (natvshift_>0) then
if ((.not.present(atvshift)).or.(.not.present(fatvshift))) then
msg='when natvshift>0, atvshift and fatvshift arguments must be present!'
LIBPAW_BUG(msg)
end if
end if
ipositron=0;if (present(electronpositron_calctype)) ipositron=electronpositron_calctype
if (ipositron/=0) then
if ((.not.present(electronpositron_pawrhoij)).or.&
& (.not.present(electronpositron_lmselect))) then
msg='ep_pawrhoij and ep_lmselect must be present for electron-positron calculations!'
LIBPAW_BUG(msg)
end if
end if
has_nucdipmom=present(nucdipmom)
! === Check complex character of arguments ===
if (nspden==4.and.cplex==2) then
msg='nspden=4 probably not compatible with cplex=2!'
LIBPAW_BUG(msg)
end if
if (my_natom>0) then
if (paw_ij(1)%ndij==4.and.paw_ij(1)%cplex_dij/=2) then
msg='invalid cplex size for Dij (4 Dij components)!'
LIBPAW_BUG(msg)
end if
if (paw_ij(1)%qphase/=paw_an(1)%cplex) then
msg='paw_ij()%qphase and paw_an()%cplex must be equal!'
LIBPAW_BUG(msg)
end if
if (ipert<=0.and.paw_ij(1)%qphase/=1) then
msg='qphase must be 1 for GS calculations!'
LIBPAW_BUG(msg)
end if
if (ipert>0.and.paw_ij(1)%qphase/=cplex) then
msg='paw_ij()%qphase must be equal to cplex!'
LIBPAW_BUG(msg)
end if
if (paw_an(1)%has_vxcval>0.and.paw_an(1)%has_vxctau==2) then
msg='kinetic energy density not available for vxc_val!'
LIBPAW_BUG(msg)
end if
end if
!------------------------------------------------------------------------
!----- Initializations
!------------------------------------------------------------------------
!Nothing to do for some perturbations (RF case)
if (ipert==natom+1.or.ipert==natom+10) then
do iatom=1,my_natom
if (paw_ij(iatom)%has_dij==1) paw_ij(iatom)%dij=zero
if (paw_ij(iatom)%has_dij0==1) paw_ij(iatom)%dij0=zero
if (paw_ij(iatom)%has_dijfock==1) paw_ij(iatom)%dijfock=zero
if (paw_ij(iatom)%has_dijhartree==1) paw_ij(iatom)%dijhartree=zero
if (paw_ij(iatom)%has_dijxc==1) paw_ij(iatom)%dijxc=zero
if (paw_ij(iatom)%has_dijhat==1) paw_ij(iatom)%dijhat=zero
if (paw_ij(iatom)%has_dijso==1) paw_ij(iatom)%dijso=zero
if (paw_ij(iatom)%has_dijU==1) paw_ij(iatom)%dijU=zero
if (paw_ij(iatom)%has_dijexxc==1) paw_ij(iatom)%dijexxc=zero
if (paw_ij(iatom)%has_dijxc_hat==1) paw_ij(iatom)%dijxc_hat=zero
if (paw_ij(iatom)%has_dijxc_val==1) paw_ij(iatom)%dijxc_val=zero
end do
return
end if
!Set up parallelism over atoms
paral_atom=(present(comm_atom).and.(my_natom/=natom))
nullify(my_atmtab);if (present(mpi_atmtab)) my_atmtab => mpi_atmtab
my_comm_atom=xpaw_mpi_comm_self;if (present(comm_atom)) my_comm_atom=comm_atom
call get_my_atmtab(my_comm_atom,my_atmtab,my_atmtab_allocated,paral_atom,natom,my_natom_ref=my_natom)
!----- Various initializations
nsppol=1;nsploop=1
if (my_natom>0) then
nsppol=paw_ij(1)%nsppol
nsploop=nsppol;if (paw_ij(1)%ndij==4) nsploop=4
end if
usexcnhat=maxval(pawtab(1:ntypat)%usexcnhat)
my_comm_grid=xpaw_mpi_comm_self;if (present(mpi_comm_grid)) my_comm_grid=mpi_comm_grid
!------ Select potential for Dij^hat computation
v_dijhat_allocated=.false.
if (my_natom>0) then
if ((paw_ij(1)%has_dij==1).or.(paw_ij(1)%has_dijhat==1).or. &
& (paw_ij(1)%has_dijhat==0.and.pawprtvol/=0)) then
if (usexcnhat==0) then
if (size(vxc,1)/=cplex*nfft.or.size(vxc,2)/=nspden) then
msg='invalid size for vxc!'
LIBPAW_BUG(msg)
end if
LIBPAW_POINTER_ALLOCATE(v_dijhat,(cplex*nfft,nspden))
v_dijhat_allocated=.true.
!v_dijhat=vtrial-vxc
do idij=1,nspden
do klmn=1,cplex*nfft
v_dijhat(klmn,idij)=vtrial(klmn,idij)-vxc(klmn,idij)
end do
end do
else
v_dijhat => vtrial
end if
end if
end if
!------------------------------------------------------------------------
!----- Loop over atoms
!------------------------------------------------------------------------
do iatom=1,my_natom
iatom_tot=iatom;if (paral_atom) iatom_tot=my_atmtab(iatom)
! === Atom-dependent data ===
itypat=paw_ij(iatom)%itypat
cplex_dij=paw_ij(iatom)%cplex_dij
qphase=paw_ij(iatom)%qphase
lm_size=paw_an(iatom)%lm_size
lmn2_size=paw_ij(iatom)%lmn2_size
ndij=paw_ij(iatom)%ndij
usepawu=pawtab(itypat)%usepawu
pawu_algo=merge(PAWU_ALGO_1,PAWU_ALGO_2,ipert<=0.and.usepawu>=0)
pawu_dblec=merge(PAWU_FLL,PAWU_AMF,abs(usepawu)==1.or.abs(usepawu)==4)
usekden=merge(0,1,paw_an(iatom)%has_vxctau/=2)
need_to_print=((abs(pawprtvol)>=1).and. &
& (iatom_tot==1.or.iatom_tot==natom.or.pawprtvol<0))
! === Determine which conditions and prerequisites are fulfilled for Dij ===
if (my_natom>0) then
! Total Dij: no condition ; no prerequisites
dij_available=.true.;dij_prereq=.true.
! Dij0: not available for RF ; need kij for the positron
dij0_available=(ipert<=0);dij0_prereq=(ipositron/=1.or.pawtab(itypat)%has_kij==2)
! DijFock:not available for RF, positron; only for Fock exact exch. ; Vxc_ex needed
dijfock_available=(paw_ij(iatom)%has_dijfock>0.and.ipert<=0.and.ipositron/=1)
dijfock_prereq=(paw_ij(iatom)%has_dijfock==2)
! DijHartree: no condition ; no prerequisites
dijhartree_available=.true.;dijhartree_prereq=.true.
! DijXC: no condition ; Vxc needed
dijxc_available=.true.
dijxc_prereq=(paw_ij(iatom)%has_dijxc==2.or.paw_an(iatom)%has_vxc>0)
! Dij^hat: no condition ; no prerequisites
dijhat_available=.true.;dijhat_prereq=.true.
! Dij^hat_FR: only for RF and when it was previously computed
dijhatfr_available=(ipert>0.and.paw_ij(iatom)%has_dijfr==2) ; dijhatfr_prereq=.true.
! DijND: requires non-zero nucdipmom
dijnd_available=.false. ; dijnd_prereq=(cplex_dij==2)
if (has_nucdipmom) dijnd_available=(any(abs(nucdipmom(:,iatom))>tol8))
! DijSO: not available for RF, positron; only for spin-orbit ; VHartree and Vxc needed
dijso_available=(pawspnorb>0.and.ipert<=0.and.ipositron/=1)
dijso_prereq=(paw_ij(iatom)%has_dijso==2.or.&
& (paw_an(iatom)%has_vhartree>0.and.paw_an(iatom)%has_vxc>0))
! DijU: not available for positron; only for DFT+U
dijU_available=(pawtab(itypat)%usepawu/=0.and.ipositron/=1)
dijU_prereq=(paw_ij(iatom)%has_dijU==2.or.paw_ij(iatom)%has_pawu_occ>0.or. &
& (paw_ij(iatom)%has_dijU>0))
! DijExxc: not available for RF, positron; only for local exact exch. ; Vxc_ex needed
dijexxc_available=(pawtab(itypat)%useexexch/=0.and.ipert<=0.and.ipositron/=1)
dijexxc_prereq=(paw_ij(iatom)%has_dijexxc==2.or.paw_ij(iatom)%has_exexch_pot>0)
! DijXC^hat: not available for RF ; Vxc needed
dijxchat_available=(ipert<=0)
dijxchat_prereq=(paw_ij(iatom)%has_dijxc_hat==2.or.paw_an(iatom)%has_vxc>0)
! DijXC_val: not available for RF ; Vxc_val needed
dijxcval_available=(ipert<=0)
dijxcval_prereq=(paw_ij(iatom)%has_dijxc_val==2.or.paw_an(iatom)%has_vxcval>0)
end if
! === Determine which parts of Dij have to be computed ===
dij_need=.false.;dij0_need=.false.;dijexxc_need=.false.;dijfock_need=.false.
dijhartree_need=.false.;dijhat_need=.false.;dijhatfr_need=.false.;
dijso_need=.false.;dijU_need=.false.;dijxc_need=.false.;dijxchat_need=.false.
dijxcval_need=.false.; dijnd_need=.false.
if (dij_available) then
if (paw_ij(iatom)%has_dij==1) then
dij_need=.true.;paw_ij(iatom)%dij(:,:)=zero
else if (paw_ij(iatom)%has_dij==0.and.need_to_print) then
LIBPAW_ALLOCATE(paw_ij(iatom)%dij,(cplex_dij*qphase*lmn2_size,ndij))
dij_need=.true.;paw_ij(iatom)%dij(:,:)=zero
paw_ij(iatom)%has_dij=-1
end if
else if (paw_ij(iatom)%has_dij==1) then
paw_ij(iatom)%dij=zero
end if
if (dij0_available) then
if (paw_ij(iatom)%has_dij0==1) then
dij0_need=.true.;paw_ij(iatom)%dij0(:)=zero
else if (paw_ij(iatom)%has_dij0==0.and.need_to_print) then
LIBPAW_ALLOCATE(paw_ij(iatom)%dij0,(lmn2_size))
dij0_need=.true.;paw_ij(iatom)%dij0(:)=zero
paw_ij(iatom)%has_dij0=-1
end if
else if (paw_ij(iatom)%has_dij0==1) then
paw_ij(iatom)%dij0=zero
end if
if (dijfock_available) then
if (paw_ij(iatom)%has_dijfock==1) then
dijfock_need=.true.;paw_ij(iatom)%dijfock(:,:)=zero
else if (paw_ij(iatom)%has_dijfock==0.and.need_to_print) then
LIBPAW_ALLOCATE(paw_ij(iatom)%dijfock,(cplex_dij*lmn2_size,ndij))
dijfock_need=.true.;paw_ij(iatom)%dijfock(:,:)=zero
paw_ij(iatom)%has_dijfock=-1
end if
else if (paw_ij(iatom)%has_dijfock==1) then
paw_ij(iatom)%dijfock=zero
end if
if (dijhartree_available) then
if (paw_ij(iatom)%has_dijhartree==1) then
dijhartree_need=.true.;paw_ij(iatom)%dijhartree(:)=zero
else if (paw_ij(iatom)%has_dijhartree==0) then
LIBPAW_ALLOCATE(paw_ij(iatom)%dijhartree,(qphase*lmn2_size))
dijhartree_need=.true.;paw_ij(iatom)%dijhartree(:)=zero
paw_ij(iatom)%has_dijhartree=-1
end if
else if (paw_ij(iatom)%has_dijhartree==1) then
paw_ij(iatom)%dijhartree=zero
end if
if (dijxc_available) then
if (paw_ij(iatom)%has_dijxc==1) then
dijxc_need=.true.;paw_ij(iatom)%dijxc(:,:)=zero
else if (paw_ij(iatom)%has_dijxc==0.and.need_to_print) then
LIBPAW_ALLOCATE(paw_ij(iatom)%dijxc,(cplex_dij*qphase*lmn2_size,ndij))
dijxc_need=.true.;paw_ij(iatom)%dijxc(:,:)=zero
paw_ij(iatom)%has_dijxc=-1
end if
else if (paw_ij(iatom)%has_dijxc==1) then
paw_ij(iatom)%dijxc=zero
end if
if (dijhat_available) then
if (paw_ij(iatom)%has_dijhat==1) then
dijhat_need=.true.;paw_ij(iatom)%dijhat(:,:)=zero
else if (paw_ij(iatom)%has_dijhat==0.and.need_to_print) then
LIBPAW_ALLOCATE(paw_ij(iatom)%dijhat,(cplex_dij*qphase*lmn2_size,ndij))
dijhat_need=.true.;paw_ij(iatom)%dijhat(:,:)=zero
paw_ij(iatom)%has_dijhat=-1
end if
else if (paw_ij(iatom)%has_dijhat==1) then
paw_ij(iatom)%dijhat=zero
end if
if (dijnd_available) then
if (paw_ij(iatom)%has_dijnd==1) then
dijnd_need=.true.;paw_ij(iatom)%dijnd(:,:)=zero
else if (paw_ij(iatom)%has_dijnd==0.and.need_to_print) then
LIBPAW_ALLOCATE(paw_ij(iatom)%dijnd,(cplex_dij*lmn2_size,ndij))
dijnd_need=.true.;paw_ij(iatom)%dijnd(:,:)=zero
paw_ij(iatom)%has_dijnd=-1
end if
else if (paw_ij(iatom)%has_dijnd==1) then
paw_ij(iatom)%dijnd=zero
end if
if (dijso_available) then
if (paw_ij(iatom)%has_dijso==1) then
dijso_need=.true.;paw_ij(iatom)%dijso(:,:)=zero
else if (paw_ij(iatom)%has_dijso==0.and.need_to_print) then
LIBPAW_ALLOCATE(paw_ij(iatom)%dijso,(cplex_dij*qphase*lmn2_size,ndij))
dijso_need=.true.;paw_ij(iatom)%dijso(:,:)=zero
paw_ij(iatom)%has_dijso=-1
end if
else if (paw_ij(iatom)%has_dijso==1) then
paw_ij(iatom)%dijso=zero
end if
if (dijU_available) then
if (paw_ij(iatom)%has_dijU==1) then
dijU_need=.true.;paw_ij(iatom)%dijU(:,:)=zero
else if (paw_ij(iatom)%has_dijU==0.and.need_to_print) then
LIBPAW_ALLOCATE(paw_ij(iatom)%dijU,(cplex_dij*qphase*lmn2_size,ndij))
dijU_need=.true.;paw_ij(iatom)%dijU(:,:)=zero
paw_ij(iatom)%has_dijU=-1
end if
else if (paw_ij(iatom)%has_dijU==1) then
paw_ij(iatom)%dijU=zero
end if
if (dijexxc_available.and.paw_ij(iatom)%has_dijexxc/=2) then
if (paw_ij(iatom)%has_dijexxc==1) then
dijexxc_need=.true.;paw_ij(iatom)%dijexxc(:,:)=zero
else if (paw_ij(iatom)%has_dijexxc==0.and.need_to_print) then
LIBPAW_ALLOCATE(paw_ij(iatom)%dijexxc,(cplex_dij*lmn2_size,ndij))
dijexxc_need=.true.;paw_ij(iatom)%dijexxc(:,:)=zero
paw_ij(iatom)%has_dijexxc=-1
end if
else if (paw_ij(iatom)%has_dijexxc==1) then
paw_ij(iatom)%dijexxc=zero
end if
if (dijxchat_available) then
if (paw_ij(iatom)%has_dijxc_hat==1) then
dijxchat_need=.true.;paw_ij(iatom)%dijxc_hat(:,:)=zero
! else if (paw_ij(iatom)%has_dijxc_hat==0.and.need_to_print) then
! LIBPAW_ALLOCATE(paw_ij(iatom)%dijxc_hat,(cplex_dij*qphase*lmn2_size,ndij))
! dijxchat_need=.true.;paw_ij(iatom)%dijxc_hat(:,:)=zero
! paw_ij(iatom)%has_dijxc_hat=-1
end if
else if (paw_ij(iatom)%has_dijxc_hat==1) then
paw_ij(iatom)%dijxc_hat=zero
end if
if (dijxcval_available) then
if (paw_ij(iatom)%has_dijxc_val==1) then
dijxcval_need=.true.;paw_ij(iatom)%dijxc_val(:,:)=zero
! else if (paw_ij(iatom)%has_dijxc_val==0.and.need_to_print) then
! LIBPAW_ALLOCATE(paw_ij(iatom)%dijxc_val,(cplex_dij*qphase*lmn2_size,ndij))
! dijxcval_need=.true.;paw_ij(iatom)%dijxc_val(:,:)=zero
! paw_ij(iatom)%has_dijxc_val=-1
end if
else if (paw_ij(iatom)%has_dijxc_val==1) then
paw_ij(iatom)%dijxc_val=zero
end if
! === Print error messages if prerequisites are not fulfilled ===
if (dij_need.and.(.not.dij_prereq)) then
msg='Dij prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dij0_need.and.(.not.dij0_prereq)) then
msg='Dij0 prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijfock_need.and.(.not.dijfock_prereq)) then
msg='DijFock prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijhartree_need.and.(.not.dijhartree_prereq)) then
msg='DijHartree prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijxc_need.and.(.not.dijxc_prereq)) then
msg='Dij^XC prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijhat_need.and.(.not.dijhat_prereq)) then
msg='Dij^hat prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijhatfr_need.and.(.not.dijhatfr_prereq)) then
msg='DijFR^hat prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijnd_need.and.(.not.dijnd_prereq)) then
msg='DijND prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijso_need.and.(.not.dijso_prereq)) then
msg='DijSO prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijU_need.and.(.not.dijU_prereq)) then
msg='DijU prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijexxc_need.and.(.not.dijexxc_prereq)) then
msg='DijExcc prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijxchat_need.and.(.not.dijxchat_prereq)) then
msg='DijXC^hat prerequisites missing!'
LIBPAW_BUG(msg)
end if
if (dijxcval_need.and.(.not.dijxcval_prereq)) then
msg='DijXC_val prerequisites missing!'
LIBPAW_BUG(msg)
end if
! ------------------------------------------------------------------------
! ----------- Add atomic Dij0 to Dij
! ------------------------------------------------------------------------
if ((dij0_need.or.dij_need).and.dij0_available) then
LIBPAW_ALLOCATE(dij0,(lmn2_size))
! ===== Dij0 already computed
if (paw_ij(iatom)%has_dij0==2) then
dij0(:)=paw_ij(iatom)%dij0(:)
else
! ===== Need to compute Dij0
dij0(:)=pawtab(itypat)%dij0(:)
if (ipositron==1) dij0(:)=two*pawtab(itypat)%kij(:)-dij0(:)
if (pawu_algo==PAWU_ALGO_2.and.pawu_dblec==PAWU_FLL) dij0(:)=dij0(:)+pawtab(itypat)%euij_fll(:)
if (dij0_need) paw_ij(iatom)%dij0(:)=dij0(:)
end if
if (dij_need) then
do idij=1,min(nsploop,2)
klmn1=1
do klmn=1,lmn2_size
paw_ij(iatom)%dij(klmn1,idij)=paw_ij(iatom)%dij(klmn1,idij)+dij0(klmn)
klmn1=klmn1+cplex_dij
end do
end do
end if
LIBPAW_DEALLOCATE(dij0)
end if
! ------------------------------------------------------------------------
! ------------------------------------------------------------------------
! ----------- Add Dij_{Fock exact-exchange} to Dij
! ------------------------------------------------------------------------
if ((dijfock_need.or.dij_need).and.dijfock_available) then
! ===== DijFock already computed
if (paw_ij(iatom)%has_dijfock==2) then
if (dij_need) paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:)= &
& paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:) &
& +paw_ij(iatom)%dijfock(1:cplex_dij*lmn2_size,:)
else
! ===== Need to compute DijFock
LIBPAW_ALLOCATE(dijfock_vv,(cplex_dij*lmn2_size,ndij))
LIBPAW_ALLOCATE(dijfock_cv,(cplex_dij*lmn2_size,ndij))
dijfock_vv(:,:)=zero ; dijfock_cv(:,:)=zero
! Exact exchange is evaluated for electrons only
if (ipositron/=1) then
call pawdijfock(dijfock_vv,dijfock_cv,cplex_dij,qphase,hyb_mixing_,hyb_mixing_sr_, &
& ndij,pawrhoij(iatom),pawtab(itypat))
end if
if (dijfock_need) paw_ij(iatom)%dijfock(:,:)=dijfock_vv(:,:)+dijfock_cv(:,:)
if (dij_need) paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:)= &
& paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:) &
& +dijfock_vv(1:cplex_dij*lmn2_size,:)+dijfock_cv(1:cplex_dij*lmn2_size,:)
LIBPAW_DEALLOCATE(dijfock_vv)
LIBPAW_DEALLOCATE(dijfock_cv)
end if
end if
! ----------- Add Dij_Hartree to Dij
! ------------------------------------------------------------------------
if ((dijhartree_need.or.dij_need).and.dijhartree_available) then
LIBPAW_ALLOCATE(dijhartree,(qphase*lmn2_size))
! ===== DijHartree already computed
if (paw_ij(iatom)%has_dijhartree==2) then
dijhartree(:)=paw_ij(iatom)%dijhartree(:)
else
! ===== Need to compute DijHartree
if (ipositron/=1) then
call pawdijhartree(dijhartree,qphase,nspden,pawrhoij(iatom),pawtab(itypat))
else
dijhartree(:)=zero
end if
if (ipositron/=0) then
LIBPAW_ALLOCATE(dij_ep,(qphase*lmn2_size))
call pawdijhartree(dij_ep,qphase,nspden,electronpositron_pawrhoij(iatom),pawtab(itypat))
dijhartree(:)=dijhartree(:)-dij_ep(:)
LIBPAW_DEALLOCATE(dij_ep)
end if
if (dijhartree_need) paw_ij(iatom)%dijhartree(:)=dijhartree(:)
end if
if (dij_need) then
do idij=1,min(nsploop,2)
klmn1=1
do klmn=1,qphase*lmn2_size
paw_ij(iatom)%dij(klmn1,idij)=paw_ij(iatom)%dij(klmn1,idij)+dijhartree(klmn)
klmn1=klmn1+cplex_dij
end do
end do
end if
LIBPAW_DEALLOCATE(dijhartree)
end if
! ------------------------------------------------------------------------
! ----------- Add Dij_xc to Dij
! ------------------------------------------------------------------------
if ((dijxc_need.or.dij_need).and.dijxc_available) then
! ===== Dijxc already computed
if (paw_ij(iatom)%has_dijxc==2) then
if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+paw_ij(iatom)%dijxc(:,:)
else
! ===== Need to compute DijXC
LIBPAW_ALLOCATE(dijxc,(cplex_dij*qphase*lmn2_size,ndij))
if (pawxcdev/=0) then
LIBPAW_ALLOCATE(lmselect,(lm_size))
lmselect(:)=paw_an(iatom)%lmselect(:)
if (ipositron/=0) lmselect(:)=(lmselect(:).or.electronpositron_lmselect(1:lm_size,iatom))
call pawdijxcm(dijxc,cplex_dij,qphase,lmselect,ndij,nspden,nsppol,pawang,&
& pawrad(itypat),pawtab(itypat),paw_an(iatom)%vxc1,&
& paw_an(iatom)%vxct1,usexcnhat)
LIBPAW_DEALLOCATE(lmselect)
else
call pawdijxc(dijxc,cplex_dij,qphase,ndij,nspden,nsppol,&
& pawang,pawrad(itypat),pawtab(itypat),paw_an(iatom)%vxc1,&
& paw_an(iatom)%vxct1,usexcnhat,usekden,&
& vxctau1=paw_an(iatom)%vxctau1,vxcttau1=paw_an(iatom)%vxcttau1)
end if
if (dijxc_need) paw_ij(iatom)%dijxc(:,:)=dijxc(:,:)
if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+dijxc(:,:)
LIBPAW_DEALLOCATE(dijxc)
end if
end if
! ------------------------------------------------------------------------
! ----------- Add Dij_hat to Dij
! ------------------------------------------------------------------------
if ((dijhat_need.or.dij_need).and.dijhat_available) then
! ===== Dijhat already computed
if (paw_ij(iatom)%has_dijhat==2) then
if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+paw_ij(iatom)%dijhat(:,:)
else
! ===== Need to compute Dijhat
LIBPAW_ALLOCATE(dijhat,(cplex_dij*qphase*lmn2_size,ndij))
call pawdijhat(dijhat,cplex_dij,qphase,gprimd,iatom_tot,&
& natom,ndij,nfft,nfftot,nspden,nsppol,pawang,pawfgrtab(iatom),&
& pawtab(itypat),v_dijhat,qphon,ucvol,xred,mpi_comm_grid=my_comm_grid)
if (dijhat_need) paw_ij(iatom)%dijhat(:,:)=dijhat(:,:)
if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+dijhat(:,:)
LIBPAW_DEALLOCATE(dijhat)
end if
! ===== RF: add frozen part of 1st-order Dij
if (dijhatfr_available) then
do idij=1,nsploop
if (dij_need) paw_ij(iatom)%dij(:,idij)=paw_ij(iatom)%dij(:,idij) &
& +paw_ij(iatom)%dijfr(:,idij)
if (dijhat_need) paw_ij(iatom)%dijhat(:,idij)=paw_ij(iatom)%dijhat(:,idij) &
& +paw_ij(iatom)%dijfr(:,idij)
end do
end if
end if
! ------------------------------------------------------------------------
! ----------- Add Dij nuclear dipole moments to Dij
! ------------------------------------------------------------------------
if ((dijnd_need.or.dij_need).and.dijnd_available) then
! ===== Dijnd already computed
if (paw_ij(iatom)%has_dijnd==2) then
if (dij_need) then
paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:)= &
& paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:) + &
& paw_ij(iatom)%dijnd(1:cplex_dij*lmn2_size,:)
end if
else
! ===== Need to compute Dijnd
LIBPAW_ALLOCATE(dijnd,(cplex_dij*lmn2_size,ndij))
call pawdijnd(dijnd,cplex_dij,ndij,nucdipmom(:,iatom),pawrad(itypat),pawtab(itypat))
if (dijnd_need) paw_ij(iatom)%dijnd(:,:)=dijnd(:,:)
if (dij_need) then
paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:)= &
& paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:) + &
& dijnd(1:cplex_dij*lmn2_size,:)
end if
LIBPAW_DEALLOCATE(dijnd)
end if
end if
! ------------------------------------------------------------------------
! ----------- Add Dij spin-orbit to Dij
! ------------------------------------------------------------------------
if ((dijso_need.or.dij_need).and.dijso_available) then
! ===== DijSO already computed
if (paw_ij(iatom)%has_dijso==2) then
if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+paw_ij(iatom)%dijso(:,:)
else
! ===== Need to compute DijSO
LIBPAW_ALLOCATE(dijso,(cplex_dij*qphase*lmn2_size,ndij))
call pawdijso(dijso,cplex_dij,qphase,ndij,nspden,&
& pawang,pawrad(itypat),pawtab(itypat),pawxcdev,spnorbscl,&
& paw_an(iatom)%vh1,paw_an(iatom)%vxc1)
if (dijso_need) paw_ij(iatom)%dijso(:,:)=dijso(:,:)
if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+dijso(:,:)
LIBPAW_DEALLOCATE(dijso)
end if
end if
! ------------------------------------------------------------------------
! ----------- Add Dij_{DFT+U} to Dij
! ------------------------------------------------------------------------
if ((dijU_need.or.dij_need).and.dijU_available) then
! ===== DijU already computed
if (paw_ij(iatom)%has_dijU==2) then
if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+paw_ij(iatom)%dijU(:,:)
else
! ===== Need to compute DijU
LIBPAW_ALLOCATE(dijpawu,(cplex_dij*qphase*lmn2_size,ndij))
if (pawu_algo==PAWU_ALGO_2) then
call pawdiju_euijkl(dijpawu,cplex_dij,qphase,ndij,pawrhoij(iatom),pawtab(itypat))
else
lpawu=pawtab(itypat)%lpawu
LIBPAW_POINTER_ALLOCATE(vpawu,(cplex_dij,lpawu*2+1,lpawu*2+1,ndij))
if (usepawu>=10) vpawu=zero ! if dmft, do not apply U in DFT+U
if (usepawu< 10) then
call pawpupot(cplex_dij,ndij,paw_ij(iatom)%noccmmp,paw_ij(iatom)%nocctot,&
& pawprtvol,pawtab(itypat),vpawu)
end if
if (natvshift_==0) then
call pawdiju(dijpawu,cplex_dij,qphase,ndij,nsppol,pawtab(itypat),vpawu)
else
call pawdiju(dijpawu,cplex_dij,qphase,ndij,nsppol,pawtab(itypat),vpawu,&
& natvshift=natvshift_,atvshift=atvshift(:,:,iatom_tot),&
& fatvshift=fatvshift)
end if
LIBPAW_POINTER_DEALLOCATE(vpawu)
end if
if (dijU_need) paw_ij(iatom)%dijU(:,:)=dijpawu(:,:)
if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+dijpawu(:,:)
LIBPAW_DEALLOCATE(dijpawu)
end if
end if
! ------------------------------------------------------------------------
! ----------- Add Dij_{local exact-exchange} to Dij
! ------------------------------------------------------------------------
if ((dijexxc_need.or.dij_need).and.dijexxc_available) then
! ===== DijEXXC already computed
if (paw_ij(iatom)%has_dijexxc==2) then
if (dij_need) paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:)= &
& paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:) &
& +paw_ij(iatom)%dijexxc(1:cplex_dij*lmn2_size,:)
else
! ===== Need to compute DijEXXC
LIBPAW_ALLOCATE(dijexxc,(cplex_dij*lmn2_size,ndij))
if (pawxcdev/=0) then
if (paw_ij(iatom)%has_exexch_pot/=2) then
LIBPAW_POINTER_ALLOCATE(vpawx,(1,lmn2_size,ndij))
call pawxpot(ndij,pawprtvol,pawrhoij(iatom),pawtab(itypat),vpawx)
else
vpawx=>paw_ij(iatom)%vpawx
end if
LIBPAW_ALLOCATE(lmselect,(lm_size))
lmselect(:)=paw_an(iatom)%lmselect(:)
if (ipositron/=0) lmselect(:)=(lmselect(:).or.electronpositron_lmselect(1:lm_size,iatom))
call pawdijexxc(dijexxc,cplex_dij,qphase,lmselect,ndij,nspden,nsppol,&
& pawang,pawrad(itypat),pawtab(itypat),vpawx,paw_an(iatom)%vxc_ex)
LIBPAW_DEALLOCATE(lmselect)
if (paw_ij(iatom)%has_exexch_pot/=2) then
LIBPAW_POINTER_DEALLOCATE(vpawx)
end if
if (dijexxc_need) paw_ij(iatom)%dijexxc(:,:)=dijexxc(:,:)
if (dij_need) paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:)= &
& paw_ij(iatom)%dij(1:cplex_dij*lmn2_size,:) &
& +dijexxc(1:cplex_dij*lmn2_size,:)
LIBPAW_DEALLOCATE(dijexxc)
end if
end if
end if
! ------------------------------------------------------------------------
! ----------- Add Dij background contribution to the total Dij
! ------------------------------------------------------------------------
if (dij_need.and.pawtab(itypat)%usepotzero==1 ) then
do idij=1,min(nsploop,2)
klmn1=1
do klmn=1,lmn2_size
paw_ij(iatom)%dij(klmn1,idij)=paw_ij(iatom)%dij(klmn1,idij)+pawtab(itypat)%gammaij(klmn)*charge/ucvol
klmn1=klmn1+cplex_dij*qphase
end do
end do
end if
! ------------------------------------------------------------------------
! ----------- Compute Dijxc_hat
! ------------------------------------------------------------------------
if (dijxchat_need) then
if (usexcnhat/=0) then
LIBPAW_ALLOCATE(dijxchat,(cplex_dij*lmn2_size,ndij))
call pawdijhat(dijxchat,cplex_dij,1,gprimd,iatom_tot,&
& natom,ndij,nfft,nfftot,nspden,nsppol,pawang,pawfgrtab(iatom),&
& pawtab(itypat),vxc,qphon,ucvol,xred,mpi_comm_grid=my_comm_grid)
paw_ij(iatom)%dijxc_hat(1:cplex_dij*lmn2_size,:)=dijxchat(1:cplex_dij*lmn2_size,:)
LIBPAW_DEALLOCATE(dijxchat)
else ! usexcnhat=0
paw_ij(iatom)%dijxc_hat=zero
end if
end if
! ------------------------------------------------------------------------
! ----------- Compute Dijxc_val
! ------------------------------------------------------------------------
if (dijxcval_need) then
LIBPAW_ALLOCATE(dijxcval,(cplex_dij*lmn2_size,ndij))
! Note that usexcnhat=0 for this call (no compensation term)
if (pawxcdev/=0) then
LIBPAW_ALLOCATE(lmselect,(lm_size))
lmselect(:)=paw_an(iatom)%lmselect(:)
if (ipositron/=0) lmselect(:)=(lmselect(:).or.electronpositron_lmselect(1:lm_size,iatom))
call pawdijxcm(dijxcval,cplex_dij,1,lmselect,ndij,nspden,nsppol,&
& pawang,pawrad(itypat),pawtab(itypat),paw_an(iatom)%vxc1_val,&
& paw_an(iatom)%vxct1_val,0)
LIBPAW_DEALLOCATE(lmselect)
else
call pawdijxc(dijxcval,cplex_dij,1,ndij,nspden,nsppol,&
& pawang,pawrad(itypat),pawtab(itypat),paw_an(iatom)%vxc1_val,&
& paw_an(iatom)%vxct1_val,0,0)
end if
paw_ij(iatom)%dijxc_val(1:cplex_dij*lmn2_size,:)=dijxcval(1:cplex_dij*lmn2_size,:)
LIBPAW_DEALLOCATE(dijxcval)
end if
! ------------------------------------------------------------------------
! Update some flags
if (dij_need.and.paw_ij(iatom)%has_dij>=1) paw_ij(iatom)%has_dij=2
if (dij0_need.and.paw_ij(iatom)%has_dij0>=1) paw_ij(iatom)%has_dij0=2
if (dijfock_need.and.paw_ij(iatom)%has_dijfock>=1) paw_ij(iatom)%has_dijfock=2
if (dijhartree_need.and.paw_ij(iatom)%has_dijhartree>=1) paw_ij(iatom)%has_dijhartree=2
if (dijxc_need.and.paw_ij(iatom)%has_dijxc>=1) paw_ij(iatom)%has_dijxc=2
if (dijhat_need.and.paw_ij(iatom)%has_dijhat>=1) paw_ij(iatom)%has_dijhat=2
if (dijnd_need.and.paw_ij(iatom)%has_dijnd>=1) paw_ij(iatom)%has_dijnd=2
if (dijso_need.and.paw_ij(iatom)%has_dijso>=1) paw_ij(iatom)%has_dijso=2
if (dijU_need.and.paw_ij(iatom)%has_dijU>=1) paw_ij(iatom)%has_dijU=2
if (dijexxc_need.and.paw_ij(iatom)%has_dijexxc>=1) paw_ij(iatom)%has_dijexxc=2
if (dijxchat_need.and.paw_ij(iatom)%has_dijxc_hat>=1) paw_ij(iatom)%has_dijxc_hat=2
if (dijxcval_need.and.paw_ij(iatom)%has_dijxc_val>=1) paw_ij(iatom)%has_dijxc_val=2
!End loop over atoms
end do ! iatom
!------------------------------------------------------------------------
!Final printing