subvxc.F90 22.2 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

Daniel Wortmann's avatar
Daniel Wortmann committed
7
MODULE m_subvxc
8

Daniel Wortmann's avatar
Daniel Wortmann committed
9 10
CONTAINS

11
   SUBROUTINE subvxc(lapw,bk,DIMENSION,input,jsp,vr0,atoms,usdus,hybrid,el,ello,sym,&
12
                     cell,sphhar,stars,xcpot,mpi,oneD,hmat,vx)
13 14 15 16 17 18 19 20 21 22 23 24 25 26


      USE m_intgr,     ONLY : intgr3
      USE m_constants
      USE m_gaunt,     ONLY : gaunt1
      USE m_wrapper
      USE m_loddop
      USE m_radflo
      USE m_radfun
      USE m_abcof3
      USE m_types

      IMPLICIT NONE

27
      CLASS(t_xcpot),        INTENT(IN)    :: xcpot
28 29 30 31 32 33 34 35 36 37 38 39 40
      TYPE(t_mpi),           INTENT(IN)    :: mpi
      TYPE(t_dimension),     INTENT(IN)    :: dimension
      TYPE(t_oneD),          INTENT(IN)    :: oneD
      TYPE(t_hybrid),        INTENT(INOUT) :: hybrid
      TYPE(t_input),         INTENT(IN)    :: input
      TYPE(t_sym),           INTENT(IN)    :: sym
      TYPE(t_stars),         INTENT(IN)    :: stars
      TYPE(t_cell),          INTENT(IN)    :: cell
      TYPE(t_sphhar),        INTENT(IN)    :: sphhar
      TYPE(t_atoms),         INTENT(IN)    :: atoms
      TYPE(t_lapw),          INTENT(IN)    :: lapw
      TYPE(t_usdus),         INTENT(INOUT) :: usdus
      TYPE(t_potden),        INTENT(IN)    :: vx
41
      TYPE(t_mat),           INTENT(INOUT) :: hmat
42 43 44 45 46 47 48 49 50 51 52

      ! Scalar Arguments
      INTEGER, INTENT (IN) :: jsp 

      ! Array Arguments
      REAL,    INTENT (IN) :: vr0(atoms%jmtd,atoms%ntype,DIMENSION%jspd)               ! just for radial functions
      REAL,    INTENT (IN) :: el(0:atoms%lmaxd,atoms%ntype,DIMENSION%jspd)
      REAL,    INTENT (IN) :: ello(atoms%nlod,atoms%ntype,DIMENSION%jspd)
      REAL,    INTENT (IN) :: bk(3)

      ! Local Scalars
53
      INTEGER               ::  ic,indx,m,ig1,ig2,n,nn
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
      INTEGER               ::  nlharm,nnbas,typsym,lm
      INTEGER               ::  noded,nodeu
      INTEGER               ::  nbasf0
      INTEGER               ::  i,j,l,ll,l1,l2 ,m1,m2  ,j1,j2
      INTEGER               ::  ok,p1,p2,lh,mh,pp1,pp2
      INTEGER               ::  igrid,itype,ilharm,istar
      INTEGER               ::  ineq,iatom,ilo,ilop,ieq,icentry
      INTEGER               ::  ikvecat,ikvecprevat,invsfct,ikvec,ikvecp
      INTEGER               ::  lp,mp,pp
      REAL                  ::  a_ex
      REAL                  ::  wronk
      COMPLEX               ::  rc,rr

      ! Local Arrays
      INTEGER               ::  gg(3)
      INTEGER               ::  pointer_lo(atoms%nlod,atoms%ntype)

      REAL                  ::  integ(0:sphhar%nlhd,hybrid%maxindx,0:atoms%lmaxd,hybrid%maxindx,0:atoms%lmaxd)
      REAL                  ::  grid(atoms%jmtd)
      REAL                  ::  vr(atoms%jmtd,0:sphhar%nlhd)
      REAL                  ::  f(atoms%jmtd,2,0:atoms%lmaxd),g(atoms%jmtd,2,0:atoms%lmaxd)
      REAL                  ::  flo(atoms%jmtd,2,atoms%nlod)
      REAL                  ::  uuilon(atoms%nlod,atoms%ntype),duilon(atoms%nlod,atoms%ntype)
      REAL                  ::  ulouilopn(atoms%nlod,atoms%nlod,atoms%ntype)

      REAL                  ::  bas1(atoms%jmtd,hybrid%maxindx,0:atoms%lmaxd,atoms%ntype)
      REAL                  ::  bas2(atoms%jmtd,hybrid%maxindx,0:atoms%lmaxd,atoms%ntype)

      COMPLEX               ::  vpw(stars%ng3)
83
      COMPLEX               ::  vxc(hmat%matsize1*(hmat%matsize1+1)/2)
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
      COMPLEX               ::  vrmat(hybrid%maxlmindx,hybrid%maxlmindx)
      COMPLEX               ::  carr(hybrid%maxlmindx,DIMENSION%nvd),carr1(DIMENSION%nvd,DIMENSION%nvd)
      COMPLEX ,ALLOCATABLE  ::  ahlp(:,:,:),bhlp(:,:,:)
      COMPLEX, ALLOCATABLE  ::  bascof(:,:,:)
      COMPLEX               ::  bascof_lo(3,-atoms%llod:atoms%llod,4*atoms%llod+2,atoms%nlod, atoms%nat)

      CALL timestart("subvxc")
      vxc=0


      ! Calculate radial functions
      hybrid%nindx      = 2
      DO itype = 1,atoms%ntype

         ! Generate the radial basis-functions for each l
         WRITE(6,'(a,i3,a)') new_LINE('n')//new_LINE('n')//' wavefunction parameters for atom type',itype,':'
         WRITE(6,'(31x,a,32x,a)') 'radial function','energy derivative'
         WRITE(6,'(a)') '  l    energy            value        '//&
                        'derivative    nodes          value        derivative    nodes       norm        wronskian'
         DO l = 0,atoms%lmax(itype)
            CALL radfun(l,itype,jsp,el(l,itype,jsp),vr0(1,itype,jsp),atoms,f(1,1,l),g(1,1,l),usdus,nodeu,noded,wronk)
            WRITE (6,FMT=8010) l,el(l,itype,jsp),usdus%us(l,itype,jsp),&
                               usdus%dus(l,itype,jsp),nodeu,usdus%uds(l,itype,jsp),usdus%duds(l,itype,jsp),noded,&
                               usdus%ddn(l,itype,jsp),wronk
         END DO
8010     FORMAT (i3,f10.5,2 (5x,1p,2e16.7,i5),1p,2e16.7)

         bas1(:,1,:,itype) = f(:,1,:)
         bas1(:,2,:,itype) = g(:,1,:)
         bas2(:,1,:,itype) = f(:,2,:)
         bas2(:,2,:,itype) = g(:,2,:)

         ! Generate the extra radial basis-functions for the local orbitals, if there are any.
         IF (atoms%nlo(itype).GE.1) THEN
            CALL radflo(atoms,itype,jsp,ello(1,1,jsp),vr0(1,itype,jsp),f,g,mpi,&
                        usdus,uuilon,duilon,ulouilopn,flo,.TRUE.)

            DO i = 1, atoms%nlo(itype)
               hybrid%nindx(atoms%llo(i,itype),itype) = hybrid%nindx(atoms%llo(i,itype),itype) + 1
               pointer_lo(i,itype) = hybrid%nindx(atoms%llo(i,itype),itype)
               bas1(:,hybrid%nindx(atoms%llo(i,itype),itype),atoms%llo(i,itype),itype) = flo(:,1,i)
               bas2(:,hybrid%nindx(atoms%llo(i,itype),itype),atoms%llo(i,itype),itype) = flo(:,2,i)
            END DO
         END IF
      END DO

      ! Compute APW coefficients

      ! Calculate bascof
      ALLOCATE(ahlp(DIMENSION%nvd,0:DIMENSION%lmd,atoms%nat),bhlp(DIMENSION%nvd,0:DIMENSION%lmd,atoms%nat),stat=ok)
      IF(ok.NE.0) STOP 'subvxc: error in allocation of ahlp/bhlp'

      CALL abcof3(input,atoms,sym,jsp,cell,bk,lapw,usdus,oneD,ahlp,bhlp,bascof_lo)

      ALLOCATE(bascof(DIMENSION%nvd,2*(DIMENSION%lmd+1),atoms%nat), stat=ok)
      IF(ok.NE.0) STOP 'subvxc: error in allocation of bascof'

      bascof = 0
      ic     = 0
      DO itype = 1, atoms%ntype
         DO ieq = 1, atoms%neq(itype)
            ic = ic + 1
            indx = 0
            DO l = 0, atoms%lmax(itype)
               ll = l*(l+1)
               DO M = -l, l
                  lm = ll + M 
                  DO i = 1, 2
                     indx = indx + 1
                     IF(i.EQ.1) THEN
                        bascof(:,indx,ic) = ahlp(:,lm,ic)
                     ELSE IF(i.EQ.2) THEN
                        bascof(:,indx,ic) = bhlp(:,lm,ic)
                     END IF
                  END DO
               END DO
            END DO
         END DO
      END DO

      DEALLOCATE(ahlp,bhlp)

      ! Loop over atom types
      iatom = 0
      DO itype = 1, atoms%ntype

         typsym = atoms%ntypsy(SUM(atoms%neq(:itype-1))+1)
         nlharm = sphhar%nlh(typsym)

         ! Calculate vxc = vtot - vcoul
         DO l=0,nlharm
            DO i=1,atoms%jri(itype)
               IF(l.EQ.0) THEN
                  ! vr(i,0)= vrtot(i,0,itype)*sfp/rmsh(i,itype) - vrcou(i,0,itype,jsp)   
                  vr(i,0)=  vx%mt(i,0,itype,jsp) * sfp_const / atoms%rmsh(i,itype)
               ELSE ! vxc = vtot - vcoul
                  ! vr(i,l)= vrtot(i,l,itype)-vrcou(i,l,itype,jsp)
                  vr(i,l)=  vx%mt(i,l,itype,jsp)      
               END IF
            END DO
         END DO

         ! Calculate MT contribution to vxc matrix elements
         ! Precompute auxiliary radial integrals
         DO ilharm = 0, nlharm
            i = 0
            DO l1 = 0, atoms%lmax(itype)
               DO p1 = 1, 2
                  i = i + 1
                  j = 0
                  DO l2 = 0, atoms%lmax(itype)     
                     DO p2 = 1, 2
                        j = j + 1
                        IF(j.LE.i) THEN
                           DO igrid = 1, atoms%jri(itype)
                              grid(igrid) = vr(igrid,ilharm) * (bas1(igrid,p1,l1,itype) * bas1(igrid,p2,l2,itype) +&
                                                                bas2(igrid,p1,l1,itype) * bas2(igrid,p2,l2,itype))
                           END DO
                           CALL intgr3(grid,atoms%rmsh(:,itype),atoms%dx(itype),atoms%jri(itype),integ(ilharm,p1,l1,p2,l2))
                           integ(ilharm,p2,l2,p1,l1) = integ(ilharm,p1,l1,p2,l2)
                        END IF
                     END DO
                  END DO
               END DO
            END DO
         END DO

         ! Calculate muffin tin contribution to vxc matrix
         vrmat=0

         j1=0
         DO l1 = 0, atoms%lmax(itype) ! loop: left basis function
            DO m1 = -l1,l1
               DO p1 = 1, 2
                  j1 = j1 + 1
                  j2 = 0
                  DO l2 = 0, atoms%lmax(itype) ! loop: right basis function
                     DO m2 = -l2, l2
                        DO p2 = 1, 2
                           j2 = j2 + 1
                           rr = 0
                           DO ilharm = 0, nlharm ! loop: lattice harmonics of vxc
                              l = sphhar%llh(ilharm,typsym)
                              DO i = 1, sphhar%nmem(ilharm,typsym)
                                 M = sphhar%mlh(i,ilharm,typsym)
                                 rc = sphhar%clnu(i,ilharm,typsym) * gaunt1(l1,l,l2,m1,M,m2,atoms%lmaxd)
                                 rr = rr + integ(ilharm,p1,l1,p2,l2) * rc
                              END DO
                           END DO
                           rc = CMPLX(0,1)**(l2-l1) ! adjusts to a/b/ccof-scaling
                           vrmat(j1,j2) = rr * rc
                        END DO
                     END DO
                  END DO
               END DO
            END DO
         END DO
         nnbas = j1

         ! Project on bascof
         DO ineq = 1,atoms%neq(itype)
            iatom = iatom+1
            carr (:nnbas,:lapw%nv(jsp)) = CONJG(MATMUL(vrmat(:nnbas,:nnbas),&
                                                       TRANSPOSE(bascof(:lapw%nv(jsp),:nnbas,iatom))))
            carr1(:lapw%nv(jsp),:lapw%nv(jsp)) = MATMUL(bascof(:lapw%nv(jsp),:nnbas,iatom),carr(:nnbas,:lapw%nv(jsp)))
            ic = 0
            DO j = 1,lapw%nv(jsp)
               ! carr(:nnbas) =  matmul(vrmat(:nnbas,:nnbas),bascof(j,:nnbas,iatom) )
               DO i = 1, j
                  ic = ic + 1
                  vxc(ic) = vxc(ic) + carr1(i,j)
                  ! vxc(ic) = vxc(ic) + conjg(dotprod ( bascof(i,:nnbas,iatom),carr(:nnbas) ))
               END DO
            END DO
         END DO
      END DO ! End loop over atom types

      ! Calculate plane wave contribution
      DO i=1,stars%ng3
         vpw(i)= vx%pw(i,jsp) 
         ! vpw(i)=vpwtot(i)-vpwcou(i,jsp)      
      END DO

      ! Calculate vxc-matrix,  left basis function (ig1)
      !                        right basis function (ig2)
      ic = 0
      DO ig1 = 1, lapw%nv(jsp)
         DO ig2 = 1, ig1
            ic = ic + 1
            gg(1) = lapw%k1(ig1,jsp) - lapw%k1(ig2,jsp)
            gg(2) = lapw%k2(ig1,jsp) - lapw%k2(ig2,jsp)
            gg(3) = lapw%k3(ig1,jsp) - lapw%k3(ig2,jsp)
            istar = stars%ig(gg(1),gg(2),gg(3))
            IF(istar.NE.0) THEN
               vxc(ic)= vxc(ic) + stars%rgphs(gg(1),gg(2),gg(3))*vpw(istar)
            ELSE
               IF (mpi%irank == 0) THEN 
                  WRITE(6,'(A,/6I5)') 'Warning: Gi-Gj not in any star:',&
                                      lapw%k1(ig1,jsp),lapw%k2(ig1,jsp),lapw%k3(ig1,jsp),&
                                      lapw%k1(ig2,jsp),lapw%k2(ig2,jsp),lapw%k3(ig2,jsp)
               END IF
            END IF
         END DO
      END DO

      ! Calculate local orbital contribution
      IF(ANY(atoms%nlo.NE.0)) THEN 

         nbasf0 = lapw%nv(jsp)*(lapw%nv(jsp)+1)/2  ! number of pure APW contributions
         icentry = nbasf0                          ! icentry counts the entry in the matrix vxc
         iatom = 0
         ikvecat = 0
         ikvecprevat = 0

         DO itype = 1, atoms%ntype

            typsym = atoms%ntypsy(SUM(atoms%neq(:itype-1))+1)
            nlharm = sphhar%nlh(typsym)

            ! Calculate vxc = vtot - vcoul
            DO l = 0, nlharm
               DO i = 1, atoms%jri(itype)
                  IF(l.EQ.0) THEN
                     ! vr(i,0)= vrtot(i,0,itype)*sfp/rmsh(i,itype) -  vrcou(i,0,itype,jsp)
                     vr(i,0)=  vx%mt(i,0,itype,jsp) * sfp_const / atoms%rmsh(i,itype)
                  ELSE ! vxc = vtot - vcoul
                     vr(i,l)=  vx%mt(i,l,itype,jsp)                    !
                     ! vr(i,l)=  vrtot(i,l,itype)-vrcou(i,l,itype,jsp)
                  END IF
               END DO
            END DO

            ! Precompute auxiliary radial integrals
            DO ilharm = 0, nlharm
               i = 0
               DO l1 = 0, atoms%lmax(itype)
                  DO p1 = 1, hybrid%nindx(l1,itype)
                     i = i + 1
                     j = 0
                     DO l2 = 0, atoms%lmax(itype)     
                        DO p2 = 1, hybrid%nindx(l2,itype)
                           j = j + 1
                           IF(j.LE.i) THEN
                              DO igrid = 1, atoms%jri(itype)
                                 grid(igrid)=vr(igrid,ilharm) * (bas1(igrid,p1,l1,itype) * bas1(igrid,p2,l2,itype) +&
                                                                 bas2(igrid,p1,l1,itype) * bas2(igrid,p2,l2,itype))
                              END DO
                              CALL intgr3(grid,atoms%rmsh(:,itype),atoms%dx(itype),atoms%jri(itype),integ(ilharm,p1,l1,p2,l2))
                              integ(ilharm,p2,l2,p1,l1) = integ(ilharm,p1,l1,p2,l2)
                           END IF
                        END DO
                     END DO
                  END DO
               END DO
            END DO


            DO ieq = 1, atoms%neq(itype)
               iatom = iatom + 1
               IF((atoms%invsat(iatom).EQ.0).OR.(atoms%invsat(iatom).EQ.1)) THEN

                  IF(atoms%invsat(iatom).EQ.0) invsfct = 1
                  IF(atoms%invsat(iatom).EQ.1) invsfct = 2

                  DO ilo = 1, atoms%nlo(itype)
                     l1 = atoms%llo(ilo,itype)
                     DO ikvec = 1, invsfct*(2*l1+1)
                        DO m1 = -l1, l1
                           DO p1 = 1, 3
                              IF(p1.EQ.3) THEN
                                 pp1 = pointer_lo(ilo,itype)
                              ELSE
                                 pp1 = p1
                              END IF

                              IF(hybrid%nindx(l1,itype).LE.2) STOP 'subvxc: error hybrid%nindx'

                              lm = 0

                              !loop over APW
                              DO l2 = 0, atoms%lmax(itype)
                                 DO m2 = -l2, l2
                                    DO p2 = 1, 2
                                       lm = lm + 1

                                       rr = 0
                                       DO ilharm = 0, nlharm
                                          lh = sphhar%llh(ilharm,typsym)
                                          DO i = 1, sphhar%nmem(ilharm,typsym)
                                             mh = sphhar%mlh(i,ilharm,typsym)
                                             rc = sphhar%clnu(i,ilharm,typsym) * gaunt1(l1,lh,l2,m1,mh,m2,atoms%lmaxd)
                                             rr = rr + integ(ilharm,p2,l2,pp1,l1) * rc
                                          END DO
                                       END DO

                                       rc = CMPLX(0d0,1d0)**(l2-l1) ! adjusts to a/b/ccof-scaling

                                       ! ic counts the entry in vxc
                                       ic = icentry
                                       DO i = 1, lapw%nv(jsp)
                                          ic = ic + 1
385
                                          IF (hmat%l_real) THEN
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
                                             vxc(ic) = vxc(ic) + invsfct * REAL(rr*rc*bascof(i,lm,iatom) *&
                                                                                CONJG(bascof_lo(p1,m1,ikvec,ilo,iatom)))
                                          ELSE
                                             vxc(ic) = vxc(ic) + rr * rc * bascof(i,lm,iatom) *&
                                                                 CONJG(bascof_lo(p1,m1,ikvec,ilo,iatom))
                                          END IF
                                       END DO
                                    END DO  !p2
                                 END DO  ! m2
                              END DO ! l2 ->  loop over APW

                              ! calcualte matrix-elements with local orbitals at the same atom
                              IF(ic.NE.icentry+lapw%nv(jsp)) STOP 'subvxc: error counting ic'

                              ic = ic + ikvecprevat

                              DO ilop = 1, ilo-1
                                 lp = atoms%llo(ilop,itype)
                                 DO ikvecp = 1, invsfct*(2*lp+1)
                                    ic = ic + 1
                                    DO mp = -lp, lp
                                       DO pp = 1, 3
                                          IF (pp.EQ.3) THEN
                                             pp2 = pointer_lo(ilop,itype)
                                          ELSE
                                             pp2 = pp
                                          END IF

                                          rr = 0
                                          DO ilharm = 0, nlharm
                                             lh = sphhar%llh(ilharm,typsym)
                                             DO i = 1, sphhar%nmem(ilharm,typsym)
                                                mh = sphhar%mlh(i,ilharm,typsym)
                                                rc = sphhar%clnu(i,ilharm,typsym) * gaunt1(l1,lh,lp,m1,mh,mp,atoms%lmaxd)
                                                rr = rr + integ(ilharm,pp2,lp,pp1,l1) * rc
                                             END DO
                                          END DO

                                          rc = CMPLX(0d0,1d0)**(lp-l1) ! adjusts to a/b/ccof-scaling

426
                                          IF (hmat%l_real) THEN
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
                                             vxc(ic) = vxc(ic) + invsfct * REAL(rr * rc * bascof_lo(pp,mp,ikvecp,ilop,iatom) *&
                                                                                CONJG(bascof_lo(p1,m1,ikvec,ilo,iatom)))
                                          ELSE
                                             vxc(ic) = vxc(ic) + rr * rc * bascof_lo(pp,mp,ikvecp, ilop,iatom) *&
                                                                 CONJG(bascof_lo(p1,m1,ikvec,ilo, iatom))
                                          END IF
                                       END DO ! pp
                                    END DO ! mp

                                 END DO !ikvecp
                              END DO ! ilop

                              ! calculate matrix-elements of one local orbital with itself
                              DO ikvecp = 1, ikvec
                                 ic = ic + 1

                                 lp   = l1
                                 ilop = ilo
                                 DO mp = -lp, lp
                                    DO pp = 1, 3
                                       IF (pp.EQ.3) THEN
                                          pp2 = pointer_lo(ilop,itype)
                                       ELSE
                                          pp2 = pp
                                       END IF

                                       rr = 0
                                       DO ilharm = 0, nlharm
                                          lh = sphhar%llh(ilharm,typsym)
                                          DO i = 1, sphhar%nmem(ilharm,typsym)
                                             mh = sphhar%mlh(i,ilharm,typsym)
                                             rc = sphhar%clnu(i,ilharm,typsym) * gaunt1(l1,lh,lp,m1,mh,mp,atoms%lmaxd)
                                             rr = rr + integ(ilharm,pp2,lp,pp1,l1) * rc
                                          END DO
                                       END DO

                                       rc = CMPLX(0d0,1d0)**(lp-l1) ! adjusts to a/b/ccof-scaling

465
                                       IF (hmat%l_real) THEN
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
                                          vxc(ic) = vxc(ic) + invsfct*REAL(rr * rc * bascof_lo(pp,mp,ikvecp,ilop,iatom) *&
                                                                           CONJG(bascof_lo(p1,m1,ikvec,ilo,iatom)))
                                       ELSE
                                          vxc(ic) = vxc(ic) + rr * rc * bascof_lo(pp,mp,ikvecp,ilop, iatom) *&
                                                              CONJG(bascof_lo(p1,m1,ikvec,ilo, iatom))
                                       END IF
                                    END DO ! pp
                                 END DO ! mp
                              END DO ! ikvecp
                           END DO  ! p1
                        END DO  ! m1
                        icentry = ic       
                     END DO !ikvec
                     ikvecat = ikvecat + invsfct*(2*l1+1)
                  END DO  ! ilo
                  ikvecprevat = ikvecprevat + ikvecat
                  ikvecat = 0
               END IF ! atoms%invsat(iatom)
            END DO ! ieq
         END DO !itype
      END IF ! if any atoms%llo

      !initialize weighting factor
      a_ex = xcpot%get_exchange_weight()
490 491 492 493 494 495 496 497 498 499

      i = 0
      DO n =1, hmat%matsize1
         DO nn = 1, n
            i = i + 1
            IF (hmat%l_real) THEN
               hmat%data_r(n,nn) = hmat%data_r(n,nn) - a_ex*REAL(vxc(i))
            ELSE
               hmat%data_c(n,nn) = hmat%data_c(n,nn) - a_ex*vxc(i)
            ENDIF
500
         END DO
501
      END DO
Daniel Wortmann's avatar
Daniel Wortmann committed
502

503
      CALL timestop("subvxc")
Daniel Wortmann's avatar
Daniel Wortmann committed
504

505
      DEALLOCATE(bascof)
Daniel Wortmann's avatar
Daniel Wortmann committed
506

507
   END SUBROUTINE subvxc
Daniel Wortmann's avatar
Daniel Wortmann committed
508
END MODULE m_subvxc
509