LCOV - code coverage report
Current view: top level - src - qs_oce_methods.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 67.8 % 304 206
Test Date: 2026-11-24 01:22:08 Functions: 71.4 % 7 5

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Routines for the construction of the coefficients
      10              : !>      for the expansion  of the atomic
      11              : !>      densities rho1_hard and rho1_soft in terms of primitive spherical gaussians.
      12              : !> \par History
      13              : !>      05-2004 created
      14              : !> \author MI
      15              : ! **************************************************************************************************
      16              : MODULE qs_oce_methods
      17              : 
      18              :    USE ai_overlap,                      ONLY: overlap,&
      19              :                                               overlap_ab
      20              :    USE ao_util,                         ONLY: exp_radius
      21              :    USE basis_set_types,                 ONLY: get_gto_basis_set,&
      22              :                                               gto_basis_set_type
      23              :    USE block_p_types,                   ONLY: block_p_type
      24              :    USE kinds,                           ONLY: dp
      25              :    USE orbital_pointers,                ONLY: init_orbital_pointers,&
      26              :                                               nco,&
      27              :                                               ncoset,&
      28              :                                               nso
      29              :    USE orbital_transformation_matrices, ONLY: orbtramat
      30              :    USE particle_types,                  ONLY: particle_type
      31              :    USE paw_basis_types,                 ONLY: get_paw_basis_info
      32              :    USE paw_proj_set_types,              ONLY: get_paw_proj_set,&
      33              :                                               paw_proj_set_type
      34              :    USE qs_kind_types,                   ONLY: get_qs_kind,&
      35              :                                               get_qs_kind_set,&
      36              :                                               qs_kind_type
      37              :    USE qs_neighbor_list_types,          ONLY: neighbor_list_set_p_type
      38              :    USE sap_kind_types,                  ONLY: clist_type,&
      39              :                                               sap_int_type,&
      40              :                                               sap_sort
      41              : #include "./base/base_uses.f90"
      42              : 
      43              :    IMPLICIT NONE
      44              : 
      45              :    PRIVATE
      46              : 
      47              :    ! Global parameters (only in this module)
      48              : 
      49              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_oce_methods'
      50              : 
      51              :    ! Public subroutines
      52              : 
      53              :    PUBLIC :: build_oce_matrices, proj_blk, prj_scatter, prj_gather
      54              : 
      55              : CONTAINS
      56              : 
      57              : ! **************************************************************************************************
      58              : !> \brief Overlap and derivative integrals <b|p_a> between orbital basis on B and PAW projectors on A
      59              : !> \param oces_t Transposed projector-orbital integrals (nsgf_cnt, nsatbas, maxder)
      60              : !> \param atom_ka Atomic kind of projector center A
      61              : !> \param atom_kb Atomic kind of orbital basis center B
      62              : !> \param rab Distance vector between centers A and B
      63              : !> \param nder Derivative order (0 <= nder <= 1)
      64              : !> \param sgf_list Indices of active spherical orbital functions on B
      65              : !> \param nsgf_cnt Number of active spherical orbital functions on B
      66              : !> \param sgf_soft_only True if all active functions on B are soft
      67              : !> \param eps_fit Threshold used to classify hard vs. soft functions
      68              : !> \param ovs_ws Spherical projector-primitive workspace (>= np_sph, >= maxco, maxder)
      69              : !> \param work One-dimensional scratch buffer for overlap_ab and DGEMM contractions
      70              : ! **************************************************************************************************
      71       143662 :    SUBROUTINE build_oce_block(oces_t, atom_ka, atom_kb, rab, nder, sgf_list, nsgf_cnt, &
      72       143662 :                               sgf_soft_only, eps_fit, ovs_ws, work)
      73              : 
      74              :       REAL(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), &
      75              :          INTENT(INOUT)                                   :: oces_t
      76              :       TYPE(qs_kind_type), POINTER                        :: atom_ka, atom_kb
      77              :       REAL(KIND=dp), DIMENSION(3)                        :: rab
      78              :       INTEGER, INTENT(IN)                                :: nder
      79              :       INTEGER, DIMENSION(:), INTENT(OUT)                 :: sgf_list
      80              :       INTEGER, INTENT(OUT)                               :: nsgf_cnt
      81              :       LOGICAL, INTENT(OUT)                               :: sgf_soft_only
      82              :       REAL(KIND=dp), INTENT(IN)                          :: eps_fit
      83              :       REAL(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), &
      84              :          INTENT(INOUT)                                   :: ovs_ws
      85              :       REAL(KIND=dp), CONTIGUOUS, DIMENSION(:), &
      86              :          INTENT(INOUT), TARGET                           :: work
      87              : 
      88              :       INTEGER :: ic, ider, igau, ip, ipgf, isgfb, isgfb_cnt, jc, jset, lprj, lsgfb, lshell, m0, &
      89              :          maxder, maxlprj, n, na_tot, nb_tot, nco_l, ncob, ncob_max, np_sph, nprj_l, nsatbas, &
      90              :          nsetb, nso_l, nso_tot, ofb, ovlp_cnt, rr_off, sgf_hard_only, sph_off
      91       143662 :       INTEGER, DIMENSION(:), POINTER                     :: fp_spha, lb_max, lb_min, npgfb, nprjla, &
      92       143662 :                                                             nsgfb
      93       143662 :       INTEGER, DIMENSION(:, :), POINTER                  :: first_sgfb
      94              :       LOGICAL                                            :: paw_atom_a, paw_atom_b
      95              :       REAL(KIND=dp)                                      :: dab, hard_radius_a, hard_radius_b, radius
      96       143662 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: set_radius_b, zisominb
      97       143662 :       REAL(KIND=dp), DIMENSION(:, :), POINTER            :: csprj, rpgfb, rzetprja, sab_p, sphi_b, &
      98       143662 :                                                             zetb, zetprja
      99       143662 :       REAL(KIND=dp), DIMENSION(:, :, :), POINTER         :: dab_p
     100       143662 :       REAL(KIND=dp), DIMENSION(:, :, :, :), POINTER      :: sph_p4
     101              :       TYPE(gto_basis_set_type), POINTER                  :: orb_basis_b
     102              :       TYPE(paw_proj_set_type), POINTER                   :: paw_proj_a, paw_proj_b
     103              : 
     104            0 :       CPASSERT(nder >= 0 .AND. nder <= 1)
     105       143662 :       nsgf_cnt = 0
     106       143662 :       sgf_soft_only = .TRUE.
     107              : 
     108       143662 :       NULLIFY (paw_proj_a)
     109              :       CALL get_qs_kind(qs_kind=atom_ka, paw_proj_set=paw_proj_a, paw_atom=paw_atom_a, &
     110       143662 :                        hard_radius=hard_radius_a)
     111              : 
     112       143662 :       NULLIFY (orb_basis_b, paw_proj_b)
     113              :       CALL get_qs_kind(qs_kind=atom_kb, basis_set=orb_basis_b, &
     114              :                        paw_proj_set=paw_proj_b, paw_atom=paw_atom_b, &
     115       143662 :                        hard_radius=hard_radius_b)
     116              : 
     117       159850 :       IF (.NOT. paw_atom_a) RETURN
     118              : 
     119       143662 :       NULLIFY (first_sgfb, lb_max, lb_min, npgfb, nsgfb, rpgfb, sphi_b, set_radius_b, zetb, zisominb)
     120              :       CALL get_gto_basis_set(gto_basis_set=orb_basis_b, nset=nsetb, &
     121              :                              set_radius=set_radius_b, lmax=lb_max, lmin=lb_min, &
     122              :                              npgf=npgfb, nsgf_set=nsgfb, pgf_radius=rpgfb, &
     123       143662 :                              sphi=sphi_b, zet=zetb, first_sgf=first_sgfb)
     124              : 
     125              :       !  Add the block ab
     126       574648 :       dab = SQRT(SUM(rab*rab))
     127       486390 :       IF (hard_radius_a + MAXVAL(set_radius_b(1:nsetb)) < dab) RETURN
     128              : 
     129       127474 :       NULLIFY (nprjla, fp_spha, rzetprja, zetprja, csprj)
     130              :       CALL get_paw_proj_set(paw_proj_set=paw_proj_a, csprj=csprj, maxl=maxlprj, &
     131              :                             nprj=nprjla, nsgauprj=np_sph, nsatbas=nsatbas, &
     132       127474 :                             first_prjs=fp_spha, rzetprj=rzetprja, zetprj=zetprja)
     133       127474 :       IF (nsatbas == 0 .OR. np_sph == 0) RETURN
     134       127474 :       IF (paw_atom_b) CALL get_paw_proj_set(paw_proj_set=paw_proj_b, zisomin=zisominb)
     135              : 
     136       127474 :       maxder = ncoset(nder)
     137       127474 :       isgfb_cnt = 1
     138       127474 :       sgf_hard_only = 0
     139       436590 :       DO jset = 1, nsetb
     140              :          !
     141              :          ! Set the contribution list
     142       436590 :          IF (hard_radius_a + set_radius_b(jset) >= dab) THEN
     143       183560 :             isgfb = first_sgfb(1, jset)
     144       183560 :             lsgfb = isgfb - 1 + nsgfb(jset)
     145       977648 :             DO jc = isgfb, lsgfb
     146       794088 :                nsgf_cnt = nsgf_cnt + 1
     147       977648 :                sgf_list(nsgf_cnt) = jc
     148              :             END DO
     149              : 
     150              :             ! check if this function is hard
     151       775176 :             radius = exp_radius(lb_max(jset), MAXVAL(zetb(1:npgfb(jset), jset)), eps_fit, 1.0_dp)
     152       183560 :             IF (radius <= hard_radius_b) sgf_hard_only = sgf_hard_only + 1
     153              : 
     154              :             ! Integral between proj of iatom and primitives of jatom
     155              :             ! Calculate the primitives overlap
     156       183560 :             ncob_max = ncoset(lb_max(jset))
     157       183560 :             ofb = ncoset(lb_min(jset) - 1)
     158       183560 :             n = ncob_max - ofb
     159       183560 :             ncob = npgfb(jset)*ncob_max
     160       183560 :             nb_tot = npgfb(jset)*n
     161     20378994 :             IF (ofb > 0) ovs_ws(1:np_sph, 1:ncob, 1:maxder) = 0.0_dp
     162              : 
     163       641138 :             DO lprj = 0, maxlprj
     164       457578 :                nprj_l = nprjla(lprj)
     165       457578 :                IF (nprj_l <= 0) CYCLE
     166       457578 :                nco_l = nco(lprj)
     167       457578 :                nso_l = nso(lprj)
     168       457578 :                na_tot = nco_l*nprj_l
     169       457578 :                nso_tot = nso_l*nprj_l
     170       457578 :                m0 = fp_spha(lprj)
     171       457578 :                ovlp_cnt = na_tot*nb_tot*maxder
     172       457578 :                sph_off = ovlp_cnt + 1
     173       457578 :                rr_off = ovlp_cnt + nso_tot*nb_tot*maxder + 1
     174              : 
     175       457578 :                sab_p(1:na_tot, 1:nb_tot) => work(1:na_tot*nb_tot)
     176       457578 :                IF (nder == 0) THEN
     177              :                   CALL overlap_ab(lprj, lprj, nprj_l, rzetprja(:, lprj), zetprja(:, lprj), &
     178              :                                   lb_max(jset), lb_min(jset), npgfb(jset), rpgfb(:, jset), &
     179      1120120 :                                   zetb(:, jset), -rab, sab=sab_p, rr_work=work(rr_off:))
     180              :                ELSE
     181       177548 :                   dab_p(1:na_tot, 1:nb_tot, 1:3) => work(na_tot*nb_tot + 1:ovlp_cnt)
     182              :                   CALL overlap_ab(lprj, lprj, nprj_l, rzetprja(:, lprj), zetprja(:, lprj), &
     183              :                                   lb_max(jset), lb_min(jset), npgfb(jset), rpgfb(:, jset), &
     184       710192 :                                   zetb(:, jset), -rab, sab=sab_p, dab=dab_p, rr_work=work(rr_off:))
     185              :                END IF
     186              : 
     187              :                CALL dgemm("N", "N", nso_l, nprj_l*nb_tot*maxder, nco_l, &
     188              :                           1.0_dp, orbtramat(lprj)%slm(1, 1), SIZE(orbtramat(lprj)%slm, 1), &
     189              :                           work(1), nco_l, &
     190       457578 :                           0.0_dp, work(sph_off), nso_l)
     191              : 
     192              :                sph_p4(1:nso_tot, 1:n, 1:npgfb(jset), 1:maxder) => &
     193       457578 :                   work(sph_off:sph_off + nso_tot*nb_tot*maxder - 1)
     194      1631360 :                DO ider = 1, maxder
     195      4572154 :                   DO ip = 1, npgfb(jset)
     196      3124354 :                      ic = (ip - 1)*ncob_max + ofb
     197    179478662 :                      ovs_ws(m0:m0 + nso_tot - 1, ic + 1:ic + n, ider) = sph_p4(1:nso_tot, 1:n, ip, ider)
     198              :                   END DO
     199              :                END DO
     200              :             END DO
     201              : 
     202       183560 :             IF (paw_atom_b) THEN
     203       734140 :                DO ipgf = 1, npgfb(jset)
     204      1661094 :                   DO lshell = lb_min(jset), lb_max(jset)
     205      1489010 :                      IF (zetb(ipgf, jset) >= zisominb(lshell)) THEN
     206        26690 :                         igau = n*(ipgf - 1) + ncoset(lshell - 1)
     207      1965426 :                         ovs_ws(1:np_sph, igau + 1:igau + nco(lshell), 1:maxder) = 0.0_dp
     208              :                      END IF
     209              :                   END DO
     210              :                END DO
     211              :             END IF
     212              : 
     213              :             ! Contraction step (integrals and derivatives)
     214       577834 :             DO ider = 1, maxder
     215              :                CALL dgemm("N", "N", np_sph, nsgfb(jset), ncob, &
     216              :                           1.0_dp, ovs_ws(1, 1, ider), SIZE(ovs_ws, 1), &
     217              :                           sphi_b(1, isgfb), SIZE(sphi_b, 1), &
     218       394274 :                           0.0_dp, work(1), np_sph)
     219              :                CALL dgemm("T", "N", nsgfb(jset), nsatbas, np_sph, &
     220              :                           1.0_dp, work(1), np_sph, &
     221              :                           csprj(1, 1), SIZE(csprj, 1), &
     222       577834 :                           0.0_dp, oces_t(isgfb_cnt, 1, ider), SIZE(oces_t, 1))
     223              :             END DO
     224       183560 :             isgfb_cnt = isgfb_cnt + nsgfb(jset)
     225              :          END IF ! radius
     226              :       END DO !jset
     227              : 
     228              :       ! Check if the screened functions are all soft
     229       127474 :       sgf_soft_only = .FALSE.
     230       127474 :       IF (sgf_hard_only == 0) sgf_soft_only = .TRUE.
     231              : 
     232       143662 :    END SUBROUTINE build_oce_block
     233              : 
     234              : ! **************************************************************************************************
     235              : !> \brief ...
     236              : !> \param oceh ...
     237              : !> \param oces ...
     238              : !> \param atom_ka ...
     239              : !> \param sgf_list ...
     240              : !> \param nsgf_cnt ...
     241              : ! **************************************************************************************************
     242        11560 :    SUBROUTINE build_oce_block_local(oceh, oces, atom_ka, sgf_list, nsgf_cnt)
     243              : 
     244              :       TYPE(block_p_type), DIMENSION(:), POINTER          :: oceh, oces
     245              :       TYPE(qs_kind_type), POINTER                        :: atom_ka
     246              :       INTEGER, DIMENSION(:), INTENT(OUT)                 :: sgf_list
     247              :       INTEGER, INTENT(OUT)                               :: nsgf_cnt
     248              : 
     249              :       INTEGER                                            :: i, iset, isgfa, j, jc, lsgfa, maxlprj, &
     250              :                                                             maxso1a, n, nsatbas, nset1a, nseta, &
     251              :                                                             nsgfa
     252        11560 :       INTEGER, DIMENSION(:), POINTER                     :: n2oindex, nsgf_seta
     253        11560 :       INTEGER, DIMENSION(:, :), POINTER                  :: first_sgfa
     254              :       LOGICAL                                            :: paw_atom_a
     255        11560 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)        :: prjloc_h, prjloc_s
     256        11560 :       REAL(KIND=dp), DIMENSION(:, :), POINTER            :: local_oce_h, local_oce_s
     257              :       TYPE(gto_basis_set_type), POINTER                  :: basis_1c_a, orb_basis_a
     258              :       TYPE(paw_proj_set_type), POINTER                   :: paw_proj_a
     259              : 
     260        11560 :       NULLIFY (orb_basis_a, basis_1c_a, paw_proj_a)
     261              :       CALL get_qs_kind(qs_kind=atom_ka, basis_set=orb_basis_a, &
     262        11560 :                        paw_proj_set=paw_proj_a, paw_atom=paw_atom_a)
     263              : 
     264        11560 :       IF (.NOT. paw_atom_a) RETURN
     265              : 
     266        11560 :       CALL get_paw_proj_set(paw_proj_set=paw_proj_a, maxl=maxlprj)
     267        11560 :       CALL get_qs_kind(qs_kind=atom_ka, basis_set=basis_1c_a, basis_type="GAPW_1C")
     268        11560 :       CALL get_gto_basis_set(gto_basis_set=basis_1c_a, nset=nset1a, maxso=maxso1a)
     269        11560 :       NULLIFY (n2oindex)
     270        11560 :       CALL get_paw_basis_info(basis_1c_a, n2oindex=n2oindex, nsatbas=nsatbas)
     271              : 
     272              :       CALL get_gto_basis_set(gto_basis_set=orb_basis_a, first_sgf=first_sgfa, &
     273        11560 :                              nsgf=nsgfa, nsgf_set=nsgf_seta, nset=nseta)
     274              : 
     275        11560 :       NULLIFY (local_oce_h, local_oce_s)
     276              :       CALL get_paw_proj_set(paw_proj_set=paw_proj_a, &
     277              :                             local_oce_sphi_h=local_oce_h, &
     278        11560 :                             local_oce_sphi_s=local_oce_s)
     279              : 
     280        69360 :       ALLOCATE (prjloc_h(nset1a*maxso1a, nsgfa), prjloc_s(nset1a*maxso1a, nsgfa))
     281        11560 :       prjloc_h = 0._dp
     282        11560 :       prjloc_s = 0._dp
     283              : 
     284        11560 :       nsgf_cnt = 0
     285        40226 :       DO iset = 1, nseta
     286        28666 :          isgfa = first_sgfa(1, iset)
     287        28666 :          lsgfa = isgfa - 1 + nsgf_seta(iset)
     288       124422 :          DO jc = isgfa, lsgfa
     289        95756 :             nsgf_cnt = nsgf_cnt + 1
     290       124422 :             sgf_list(nsgf_cnt) = jc
     291              :          END DO
     292              :          ! this asumes that the first sets are the same for basis_1c/orb_basis!
     293        28666 :          n = maxso1a*(iset - 1)
     294      1732982 :          prjloc_h(n + 1:n + maxso1a, isgfa:lsgfa) = local_oce_h(1:maxso1a, isgfa:lsgfa)
     295      1744542 :          prjloc_s(n + 1:n + maxso1a, isgfa:lsgfa) = local_oce_s(1:maxso1a, isgfa:lsgfa)
     296              :       END DO
     297              : 
     298       107316 :       DO i = 1, nsgfa
     299      2552058 :          DO j = 1, nsatbas
     300      2444742 :             jc = n2oindex(j)
     301      2444742 :             oceh(1)%block(j, i) = prjloc_h(jc, i)
     302      2540498 :             oces(1)%block(j, i) = prjloc_s(jc, i)
     303              :          END DO
     304              :       END DO
     305              : 
     306        11560 :       DEALLOCATE (prjloc_h, prjloc_s)
     307        11560 :       DEALLOCATE (n2oindex)
     308              : 
     309        34680 :    END SUBROUTINE build_oce_block_local
     310              : 
     311              : ! **************************************************************************************************
     312              : !> \brief ...
     313              : !> \param oceh ...
     314              : !> \param oces ...
     315              : !> \param atom_ka ...
     316              : !> \param sgf_list ...
     317              : !> \param nsgf_cnt ...
     318              : !> \param eps_fit ...
     319              : ! **************************************************************************************************
     320            0 :    SUBROUTINE build_oce_block_1c(oceh, oces, atom_ka, sgf_list, nsgf_cnt, eps_fit)
     321              : 
     322              :       TYPE(block_p_type), DIMENSION(:), POINTER          :: oceh, oces
     323              :       TYPE(qs_kind_type), POINTER                        :: atom_ka
     324              :       INTEGER, DIMENSION(:), INTENT(OUT)                 :: sgf_list
     325              :       INTEGER, INTENT(OUT)                               :: nsgf_cnt
     326              :       REAL(KIND=dp), INTENT(IN)                          :: eps_fit
     327              : 
     328              :       INTEGER :: first_col, ic, ig1, igau, ip, ipgf, isgfb, isgfb_cnt, jc, jset, lds, lm, lpoint, &
     329              :          lprj, lsgfb, lsgfb_cnt, lshell, m, m1, maxcob, maxlb, maxlprj, maxnprja, maxsoa, msab, n, &
     330              :          ncob, np_car, np_sph, nsatbas, nseta, nsetb, nsoatot, ntotsgfb
     331            0 :       INTEGER, DIMENSION(:), POINTER                     :: fp_cara, fp_spha, lb_max, lb_min, npgfb, &
     332            0 :                                                             nprjla, nsgfb
     333            0 :       INTEGER, DIMENSION(:, :), POINTER                  :: first_sgfb
     334              :       LOGICAL                                            :: paw_atom_a
     335              :       REAL(KIND=dp)                                      :: radius, rc, rcprja
     336            0 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)        :: ovh, ovs, spa_sb
     337            0 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: s
     338            0 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: set_radius_b, zisominb
     339            0 :       REAL(KIND=dp), DIMENSION(:, :), POINTER            :: chprj, csprj, rpgfb, rzetprja, spa_tmp, &
     340            0 :                                                             sphi_b, zetb, zetprja
     341              :       TYPE(gto_basis_set_type), POINTER                  :: basis_1c_a, orb_basis_b
     342              :       TYPE(paw_proj_set_type), POINTER                   :: paw_proj_a
     343              : 
     344            0 :       NULLIFY (orb_basis_b, basis_1c_a, paw_proj_a)
     345            0 :       CALL get_qs_kind(qs_kind=atom_ka, paw_atom=paw_atom_a)
     346              : 
     347            0 :       IF (.NOT. paw_atom_a) RETURN
     348              : 
     349            0 :       CALL get_qs_kind(qs_kind=atom_ka, paw_proj_set=paw_proj_a)
     350            0 :       NULLIFY (nprjla, fp_cara, fp_spha, rzetprja, zetprja)
     351              :       CALL get_paw_proj_set(paw_proj_set=paw_proj_a, csprj=csprj, chprj=chprj, maxl=maxlprj, &
     352              :                             nprj=nprjla, ncgauprj=np_car, nsgauprj=np_sph, nsatbas=nsatbas, rcprj=rcprja, &
     353              :                             first_prj=fp_cara, first_prjs=fp_spha, &
     354            0 :                             rzetprj=rzetprja, zetprj=zetprja)
     355              : 
     356            0 :       CALL get_qs_kind(qs_kind=atom_ka, basis_set=orb_basis_b)
     357            0 :       NULLIFY (first_sgfb, lb_max, lb_min, npgfb, nsgfb, rpgfb, sphi_b, set_radius_b, zetb, zisominb)
     358              :       CALL get_gto_basis_set(gto_basis_set=orb_basis_b, nset=nsetb, nsgf=ntotsgfb, &
     359              :                              set_radius=set_radius_b, lmax=lb_max, lmin=lb_min, &
     360              :                              npgf=npgfb, nsgf_set=nsgfb, pgf_radius=rpgfb, &
     361              :                              sphi=sphi_b, zet=zetb, first_sgf=first_sgfb, &
     362            0 :                              maxco=maxcob, maxl=maxlb)
     363              : 
     364            0 :       CALL get_qs_kind(qs_kind=atom_ka, hard_radius=rc)
     365              : 
     366            0 :       CALL get_qs_kind(qs_kind=atom_ka, basis_set=basis_1c_a, basis_type="GAPW_1C")
     367            0 :       CALL get_gto_basis_set(gto_basis_set=basis_1c_a, nset=nseta, maxso=maxsoa)
     368              : 
     369              :       !  Add the block ab
     370            0 :       nsoatot = maxsoa*nseta
     371            0 :       maxnprja = SIZE(zetprja, 1)
     372              : 
     373            0 :       lm = MAX(maxlb, maxlprj)
     374            0 :       lds = ncoset(lm + 1)
     375            0 :       msab = MAX(maxnprja*ncoset(maxlprj), maxcob)
     376              : 
     377            0 :       ALLOCATE (s(lds, lds, 1))
     378            0 :       ALLOCATE (spa_sb(np_car, ntotsgfb))
     379            0 :       ALLOCATE (spa_tmp(msab, msab))
     380            0 :       ALLOCATE (ovs(np_sph, maxcob*nsetb))
     381            0 :       ALLOCATE (ovh(np_sph, maxcob*nsetb))
     382              : 
     383            0 :       m1 = 0
     384            0 :       nsgf_cnt = 0
     385            0 :       isgfb_cnt = 1
     386            0 :       DO jset = 1, nsetb
     387              :          !
     388              :          ! Set the contribution list
     389            0 :          isgfb = first_sgfb(1, jset)
     390            0 :          lsgfb = isgfb - 1 + nsgfb(jset)
     391            0 :          DO jc = isgfb, lsgfb
     392            0 :             nsgf_cnt = nsgf_cnt + 1
     393            0 :             sgf_list(nsgf_cnt) = jc
     394              :          END DO
     395              : 
     396              :          ! Integral between proj of iatom and primitives of iatom
     397              :          ! Calculate the primitives overlap
     398            0 :          spa_tmp = 0.0_dp
     399            0 :          ovs = 0.0_dp
     400            0 :          ovh = 0.0_dp
     401            0 :          s = 0.0_dp
     402            0 :          ncob = npgfb(jset)*ncoset(lb_max(jset))
     403            0 :          isgfb = first_sgfb(1, jset)
     404            0 :          lsgfb = isgfb - 1 + nsgfb(jset)
     405              : 
     406            0 :          lsgfb_cnt = isgfb_cnt - 1 + nsgfb(jset)
     407              : 
     408            0 :          DO lprj = 0, maxlprj
     409              :             CALL overlap(lprj, lprj, nprjla(lprj), &
     410              :                          rzetprja(:, lprj), zetprja(:, lprj), &
     411              :                          lb_max(jset), lb_min(jset), npgfb(jset), &
     412              :                          rpgfb(:, jset), zetb(:, jset), &
     413              :                          -[0._dp, 0._dp, 0._dp], 0.0_dp, spa_tmp, &
     414            0 :                          0, .TRUE., s, lds)
     415            0 :             DO ipgf = 1, nprjla(lprj)
     416            0 :                lpoint = ncoset(lprj - 1) + 1 + (ipgf - 1)*ncoset(lprj)
     417            0 :                m = fp_spha(lprj) + (ipgf - 1)*nso(lprj)
     418            0 :                DO ip = 1, npgfb(jset)
     419            0 :                   ic = (ip - 1)*ncoset(lb_max(jset))
     420            0 :                   igau = ic + m1 + ncoset(lb_min(jset) - 1) + 1
     421            0 :                   ig1 = ic + ncoset(lb_min(jset) - 1) + 1
     422            0 :                   n = ncoset(lb_max(jset)) - ncoset(lb_min(jset) - 1)
     423              :                   ovs(m:m + nso(lprj) - 1, igau:igau + n - 1) = &
     424            0 :                      MATMUL(orbtramat(lprj)%slm(1:nso(lprj), 1:nco(lprj)), &
     425            0 :                             spa_tmp(lpoint:lpoint + nco(lprj) - 1, ig1:ig1 + n - 1))
     426              :                END DO
     427              :             END DO
     428              :          END DO
     429              : 
     430            0 :          ovh(:, :) = ovs(:, :)
     431              : 
     432            0 :          CALL get_paw_proj_set(paw_proj_set=paw_proj_a, zisomin=zisominb)
     433            0 :          DO ipgf = 1, npgfb(jset)
     434            0 :             DO lshell = lb_min(jset), lb_max(jset)
     435            0 :                radius = exp_radius(lshell, zetb(ipgf, jset), eps_fit, 1.0_dp)
     436            0 :                IF (radius < rc) THEN
     437            0 :                   n = ncoset(lb_max(jset)) - ncoset(lb_min(jset) - 1)
     438            0 :                   igau = n*(ipgf - 1) + ncoset(lshell - 1)
     439            0 :                   ovs(:, igau + 1 + m1:igau + nco(lshell) + m1) = 0.0_dp
     440              :                END IF
     441              :             END DO
     442              :          END DO
     443              : 
     444              :          ! Contraction step (integrals and derivatives)
     445            0 :          first_col = 1 + m1
     446              :          spa_sb(1:np_sph, isgfb:isgfb + nsgfb(jset) - 1) = &
     447            0 :             MATMUL(ovs(1:np_sph, first_col:first_col + ncob - 1), &
     448            0 :                    sphi_b(1:ncob, isgfb:isgfb + nsgfb(jset) - 1))
     449              : 
     450              :          oces(1)%block(1:nsatbas, isgfb_cnt:isgfb_cnt + nsgfb(jset) - 1) = &
     451              :             oces(1)%block(1:nsatbas, isgfb_cnt:isgfb_cnt + nsgfb(jset) - 1) + &
     452            0 :             MATMUL(TRANSPOSE(csprj(1:np_sph, 1:nsatbas)), &
     453            0 :                    spa_sb(1:np_sph, isgfb:isgfb + nsgfb(jset) - 1))
     454              : 
     455              :          spa_sb(1:np_sph, isgfb:isgfb + nsgfb(jset) - 1) = &
     456            0 :             MATMUL(ovh(1:np_sph, first_col:first_col + ncob - 1), &
     457            0 :                    sphi_b(1:ncob, isgfb:isgfb + nsgfb(jset) - 1))
     458              : 
     459              :          oceh(1)%block(1:nsatbas, isgfb_cnt:isgfb_cnt + nsgfb(jset) - 1) = &
     460              :             oceh(1)%block(1:nsatbas, isgfb_cnt:isgfb_cnt + nsgfb(jset) - 1) + &
     461            0 :             MATMUL(TRANSPOSE(chprj(1:np_sph, 1:nsatbas)), &
     462            0 :                    spa_sb(1:np_sph, isgfb:isgfb + nsgfb(jset) - 1))
     463              : 
     464            0 :          isgfb_cnt = isgfb_cnt + nsgfb(jset)
     465            0 :          m1 = m1 + maxcob
     466              :       END DO !jset
     467              : 
     468            0 :       DEALLOCATE (s, spa_sb, spa_tmp, ovs)
     469              : 
     470            0 :    END SUBROUTINE build_oce_block_1c
     471              : 
     472              : ! **************************************************************************************************
     473              : !> \brief Set up the sparse matrix for the coefficients of one center expansions
     474              : !>      This routine uses the same logic as the nonlocal pseudopotential
     475              : !> \param intac TYPE that holds the integrals (a=basis; c=projector)
     476              : !> \param calculate_forces ...
     477              : !> \param nder Derivative order (0 <= nder <= 1)
     478              : !> \param qs_kind_set ...
     479              : !> \param particle_set ...
     480              : !> \param sap_oce ...
     481              : !> \param eps_fit ...
     482              : !> \par History
     483              : !>      02.2009 created
     484              : !> \author jgh
     485              : ! **************************************************************************************************
     486         4146 :    SUBROUTINE build_oce_matrices(intac, calculate_forces, nder, &
     487              :                                  qs_kind_set, particle_set, sap_oce, eps_fit)
     488              : 
     489              :       TYPE(sap_int_type), DIMENSION(:), POINTER          :: intac
     490              :       LOGICAL, INTENT(IN)                                :: calculate_forces
     491              :       INTEGER                                            :: nder
     492              :       TYPE(qs_kind_type), DIMENSION(:), POINTER          :: qs_kind_set
     493              :       TYPE(particle_type), DIMENSION(:), POINTER         :: particle_set
     494              :       TYPE(neighbor_list_set_p_type), DIMENSION(:), &
     495              :          POINTER                                         :: sap_oce
     496              :       REAL(KIND=dp), INTENT(IN)                          :: eps_fit
     497              : 
     498              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'build_oce_matrices'
     499              : 
     500              :       INTEGER :: atom_a, atom_b, handle, i, iac, ikind, ilist, jkind, jneighbor, lwork, &
     501              :          max_nsatbas, maxco, maxder, maxl, maxlgto, maxlprj, maxprj, maxsgf, natom, nkind, nlist, &
     502              :          nneighbor, nsgf_cnt, nsgfa, nsobtot, slot
     503         4146 :       INTEGER, ALLOCATABLE, DIMENSION(:)                 :: nsatbas_kind, nsgfa_kind, sgf_list
     504              :       INTEGER, DIMENSION(3)                              :: cell_b
     505              :       LOGICAL                                            :: local, sgf_soft_only
     506         4146 :       LOGICAL, ALLOCATABLE, DIMENSION(:)                 :: has_1c_basis, has_orb_basis, paw_kind
     507         4146 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)           :: work
     508         4146 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: oces_t, ovs_ws
     509              :       REAL(KIND=dp), DIMENSION(3)                        :: rab
     510         4146 :       TYPE(block_p_type), DIMENSION(:), POINTER          :: oceh, oces
     511              :       TYPE(clist_type), POINTER                          :: clist
     512              :       TYPE(gto_basis_set_type), POINTER                  :: orb_basis_paw, orb_basis_set
     513              :       TYPE(paw_proj_set_type), POINTER                   :: paw_proj_b
     514              :       TYPE(qs_kind_type), POINTER                        :: at_a, at_b
     515              : 
     516         8292 :       IF (calculate_forces) THEN
     517         1490 :          CALL timeset(routineN//"_forces", handle)
     518              :       ELSE
     519         2656 :          CALL timeset(routineN, handle)
     520              :       END IF
     521              : 
     522         4146 :       IF (ASSOCIATED(sap_oce)) THEN
     523              : 
     524         4146 :          nkind = SIZE(qs_kind_set)
     525         4146 :          natom = SIZE(particle_set)
     526              : 
     527         4146 :          CPASSERT(nder >= 0 .AND. nder <= 1)
     528         4146 :          maxder = ncoset(nder)
     529              : 
     530              :          CALL get_qs_kind_set(qs_kind_set=qs_kind_set, &
     531              :                               maxco=maxco, &
     532              :                               maxlgto=maxlgto, &
     533              :                               maxlprj=maxlprj, &
     534              :                               maxco_proj=maxprj, &
     535         4146 :                               maxsgf=maxsgf)
     536              : 
     537         4146 :          maxl = MAX(maxlgto, maxlprj)
     538         4146 :          CALL init_orbital_pointers(maxl + nder + 1)
     539              : 
     540        20294 :          DO i = 1, nkind*nkind
     541        16148 :             NULLIFY (intac(i)%alist, intac(i)%asort, intac(i)%aindex)
     542        20294 :             intac(i)%nalist = 0
     543              :          END DO
     544              : 
     545            0 :          ALLOCATE (has_orb_basis(nkind), paw_kind(nkind), has_1c_basis(nkind), &
     546        29022 :                    nsgfa_kind(nkind), nsatbas_kind(nkind))
     547         4146 :          nsgfa_kind(:) = 0
     548         4146 :          nsatbas_kind(:) = 0
     549        12002 :          DO ikind = 1, nkind
     550         7856 :             NULLIFY (orb_basis_set, paw_proj_b, orb_basis_paw)
     551              :             CALL get_qs_kind(qs_kind=qs_kind_set(ikind), basis_set=orb_basis_set, &
     552         7856 :                              paw_proj_set=paw_proj_b, paw_atom=paw_kind(ikind))
     553         7856 :             CALL get_qs_kind(qs_kind=qs_kind_set(ikind), basis_set=orb_basis_paw, basis_type="GAPW_1C")
     554         7856 :             has_orb_basis(ikind) = ASSOCIATED(orb_basis_set)
     555         7856 :             has_1c_basis(ikind) = ASSOCIATED(orb_basis_paw)
     556         7856 :             IF (has_orb_basis(ikind)) CALL get_gto_basis_set(orb_basis_set, nsgf=nsgfa_kind(ikind))
     557        12002 :             IF (paw_kind(ikind) .AND. ASSOCIATED(paw_proj_b)) THEN
     558         7232 :                CALL get_paw_proj_set(paw_proj_b, nsatbas=nsatbas_kind(ikind))
     559              :             END IF
     560              :          END DO
     561        12002 :          max_nsatbas = MAXVAL(nsatbas_kind)
     562              : 
     563              :          ! Allocate memory list
     564       159368 :          DO slot = 1, sap_oce(1)%nl_size
     565       155222 :             ikind = sap_oce(1)%nlist_task(slot)%ikind
     566       155222 :             jkind = sap_oce(1)%nlist_task(slot)%jkind
     567       155222 :             atom_a = sap_oce(1)%nlist_task(slot)%iatom
     568       155222 :             nlist = sap_oce(1)%nlist_task(slot)%nlist
     569       155222 :             ilist = sap_oce(1)%nlist_task(slot)%ilist
     570       155222 :             nneighbor = sap_oce(1)%nlist_task(slot)%nnode
     571              : 
     572       155222 :             iac = ikind + nkind*(jkind - 1)
     573              : 
     574       155222 :             IF (.NOT. has_orb_basis(ikind)) CYCLE
     575       155222 :             IF (.NOT. paw_kind(jkind)) CYCLE
     576       155222 :             IF (.NOT. has_1c_basis(jkind)) CYCLE
     577       155222 :             IF (.NOT. ASSOCIATED(intac(iac)%alist)) THEN
     578        14796 :                intac(iac)%a_kind = ikind
     579        14796 :                intac(iac)%p_kind = jkind
     580        14796 :                intac(iac)%nalist = nlist
     581        67432 :                ALLOCATE (intac(iac)%alist(nlist))
     582        37840 :                DO i = 1, nlist
     583        23044 :                   NULLIFY (intac(iac)%alist(i)%clist)
     584        23044 :                   intac(iac)%alist(i)%aatom = 0
     585        37840 :                   intac(iac)%alist(i)%nclist = 0
     586              :                END DO
     587              :             END IF
     588       159368 :             IF (.NOT. ASSOCIATED(intac(iac)%alist(ilist)%clist)) THEN
     589        23044 :                intac(iac)%alist(ilist)%aatom = atom_a
     590        23044 :                intac(iac)%alist(ilist)%nclist = nneighbor
     591       385662 :                ALLOCATE (intac(iac)%alist(ilist)%clist(nneighbor))
     592              :             END IF
     593              :          END DO
     594              : 
     595         4146 :          lwork = MAX(1, maxprj*maxsgf, 2*maxprj*maxco*maxder + 3*(maxl + nder + 1)**2)
     596              : 
     597              :          !calculate the overlap integrals <a|p>
     598              : !$OMP PARALLEL DEFAULT(NONE) &
     599              : !$OMP SHARED (intac, nder, nkind, maxder, sap_oce, qs_kind_set, eps_fit, &
     600              : !$OMP         has_orb_basis, paw_kind, has_1c_basis, nsgfa_kind, nsatbas_kind, &
     601              : !$OMP         maxco, maxprj, maxsgf, max_nsatbas, lwork) &
     602              : !$OMP PRIVATE (oceh, oces, oces_t, ovs_ws, work, sgf_list, slot, ikind, jkind, atom_a, atom_b, &
     603              : !$OMP          ilist, jneighbor, rab, cell_b, iac, nsgfa, nsobtot, clist, at_a, at_b, local, i, &
     604         4146 : !$OMP          sgf_soft_only, nsgf_cnt)
     605              : 
     606              :          ALLOCATE (oces_t(MAX(1, maxsgf), MAX(1, max_nsatbas), maxder), &
     607              :                    ovs_ws(MAX(1, maxprj), MAX(1, maxco), maxder), work(lwork), &
     608              :                    oceh(maxder), oces(maxder), sgf_list(maxsgf))
     609              : 
     610              : !$OMP DO SCHEDULE(GUIDED)
     611              :          DO slot = 1, sap_oce(1)%nl_size
     612              :             ikind = sap_oce(1)%nlist_task(slot)%ikind
     613              :             jkind = sap_oce(1)%nlist_task(slot)%jkind
     614              :             atom_a = sap_oce(1)%nlist_task(slot)%iatom
     615              :             atom_b = sap_oce(1)%nlist_task(slot)%jatom
     616              :             ilist = sap_oce(1)%nlist_task(slot)%ilist
     617              :             jneighbor = sap_oce(1)%nlist_task(slot)%inode
     618              :             rab(1:3) = sap_oce(1)%nlist_task(slot)%r(1:3)
     619              :             cell_b(1:3) = sap_oce(1)%nlist_task(slot)%cell(1:3)
     620              : 
     621              :             iac = ikind + nkind*(jkind - 1)
     622              : 
     623              :             IF (.NOT. has_orb_basis(ikind)) CYCLE
     624              :             IF (.NOT. paw_kind(jkind)) CYCLE
     625              :             IF (.NOT. has_1c_basis(jkind)) CYCLE
     626              : 
     627              :             nsgfa = nsgfa_kind(ikind)
     628              :             nsobtot = nsatbas_kind(jkind)
     629              : 
     630              :             clist => intac(iac)%alist(ilist)%clist(jneighbor)
     631              :             clist%catom = atom_b
     632              :             clist%cell = cell_b
     633              :             clist%rac = rab
     634              :             clist%nsgf_cnt = 0
     635              :             clist%maxac = 0.0_dp
     636              :             clist%maxach = 0.0_dp
     637              :             NULLIFY (clist%acint, clist%achint, clist%sgf_list)
     638              : 
     639              :             at_a => qs_kind_set(jkind)
     640              :             at_b => qs_kind_set(ikind)
     641              : 
     642              :             local = (atom_a == atom_b .AND. ALL(cell_b == 0))
     643              : 
     644              :             IF (local) THEN
     645              :                DO i = 1, maxder
     646              :                   ALLOCATE (oceh(i)%block(nsobtot, nsgfa), oces(i)%block(nsobtot, nsgfa))
     647              :                   oceh(i)%block = 0._dp
     648              :                   oces(i)%block = 0._dp
     649              :                END DO
     650              :                CALL build_oce_block_local(oceh, oces, at_a, sgf_list, nsgf_cnt)
     651              :                clist%nsgf_cnt = nsgf_cnt
     652              :                clist%sgf_soft_only = .FALSE.
     653              :                IF (nsgf_cnt > 0) THEN
     654              :                   ALLOCATE (clist%acint(nsgf_cnt, nsobtot, maxder), clist%sgf_list(nsgf_cnt))
     655              :                   clist%acint(:, :, :) = 0._dp
     656              :                   clist%sgf_list(:) = HUGE(0)
     657              :                   CPASSERT(nsgf_cnt == nsgfa)
     658              :                   ! *** Special case: A=B
     659              :                   ALLOCATE (clist%achint(nsgfa, nsobtot, maxder))
     660              :                   clist%achint = 0._dp
     661              :                   clist%acint(1:nsgfa, 1:nsobtot, 1) = TRANSPOSE(oces(1)%block(1:nsobtot, 1:nsgfa))
     662              :                   clist%achint(1:nsgfa, 1:nsobtot, 1) = TRANSPOSE(oceh(1)%block(1:nsobtot, 1:nsgfa))
     663              :                   clist%maxac = MAXVAL(ABS(clist%acint(:, :, 1)))
     664              :                   clist%maxach = 0._dp
     665              :                   clist%sgf_list(1:nsgf_cnt) = sgf_list(1:nsgf_cnt)
     666              :                END IF
     667              :                DO i = 1, maxder
     668              :                   DEALLOCATE (oceh(i)%block, oces(i)%block)
     669              :                END DO
     670              :             ELSE
     671              :                CALL build_oce_block(oces_t, at_a, at_b, rab, nder, sgf_list, nsgf_cnt, &
     672              :                                     sgf_soft_only, eps_fit, ovs_ws, work)
     673              :                clist%nsgf_cnt = nsgf_cnt
     674              :                clist%sgf_soft_only = sgf_soft_only
     675              :                IF (nsgf_cnt > 0) THEN
     676              :                   ALLOCATE (clist%acint(nsgf_cnt, nsobtot, maxder), clist%sgf_list(nsgf_cnt))
     677              :                   clist%acint(:, :, :) = oces_t(1:nsgf_cnt, 1:nsobtot, 1:maxder)
     678              :                   clist%maxac = MAXVAL(ABS(clist%acint(:, :, 1)))
     679              :                   clist%maxach = 0._dp
     680              :                   clist%sgf_list(1:nsgf_cnt) = sgf_list(1:nsgf_cnt)
     681              :                END IF
     682              :             END IF
     683              : 
     684              :          END DO
     685              : 
     686              :          DEALLOCATE (oces_t, ovs_ws, work, sgf_list, oceh, oces)
     687              : !$OMP END PARALLEL
     688              : 
     689              :          ! Setup sort index
     690         4146 :          CALL sap_sort(intac)
     691              : 
     692         8292 :          DEALLOCATE (has_orb_basis, paw_kind, has_1c_basis, nsgfa_kind, nsatbas_kind)
     693              : 
     694              :       END IF
     695              : 
     696         4146 :       CALL timestop(handle)
     697              : 
     698         8292 :    END SUBROUTINE build_oce_matrices
     699              : 
     700              : ! **************************************************************************************************
     701              : !> \brief Project a matrix block onto the local atomic functions.
     702              : !>
     703              : !> \param h_a ...
     704              : !> \param s_a ...
     705              : !> \param na ...
     706              : !> \param h_b ...
     707              : !> \param s_b ...
     708              : !> \param nb ...
     709              : !> \param blk ...
     710              : !> \param ldb ...
     711              : !> \param proj_h ...
     712              : !> \param proj_s ...
     713              : !> \param nso ...
     714              : !> \param len1 ...
     715              : !> \param len2 ...
     716              : !> \param fac ...
     717              : !> \param distab ...
     718              : !> \param work1 ...
     719              : !> \param work2 ...
     720              : !> \par History
     721              : !>      02.2009 created
     722              : !>      09.2016 use automatic arrays [M Tucker]
     723              : !>      05.2026 move work arrays to callers
     724              : ! **************************************************************************************************
     725       417653 :    SUBROUTINE proj_blk(h_a, s_a, na, h_b, s_b, nb, blk, ldb, proj_h, proj_s, nso, len1, len2, fac, distab, &
     726       417653 :                        work1, work2)
     727              : 
     728              :       INTEGER, INTENT(IN)                                :: na
     729              :       REAL(KIND=dp), INTENT(IN)                          :: s_a(na, *), h_a(na, *)
     730              :       INTEGER, INTENT(IN)                                :: nb
     731              :       REAL(KIND=dp), INTENT(IN)                          :: s_b(nb, *), h_b(nb, *)
     732              :       INTEGER, INTENT(IN)                                :: ldb
     733              :       REAL(KIND=dp), INTENT(IN)                          :: blk(ldb, *)
     734              :       INTEGER, INTENT(IN)                                :: nso
     735              :       REAL(KIND=dp), INTENT(INOUT)                       :: proj_s(nso, *), proj_h(nso, *)
     736              :       INTEGER, INTENT(IN)                                :: len1, len2
     737              :       REAL(KIND=dp), INTENT(IN)                          :: fac
     738              :       LOGICAL, INTENT(IN)                                :: distab
     739              :       REAL(KIND=dp), INTENT(INOUT)                       :: work1(len1), work2(len2)
     740              : 
     741       417653 :       IF (na == 0 .OR. nb == 0 .OR. nso == 0) RETURN
     742              : 
     743              :       ! Handle special cases
     744       417653 :       IF (na == 1 .AND. nb == 1) THEN
     745              :          ! hard
     746        11023 :          CALL dger(nso, nso, fac*blk(1, 1), h_a(1, 1), 1, h_b(1, 1), 1, proj_h(1, 1), nso)
     747              :          ! soft
     748        11023 :          CALL dger(nso, nso, fac*blk(1, 1), s_a(1, 1), 1, s_b(1, 1), 1, proj_s(1, 1), nso)
     749              :       ELSE
     750       406630 :          IF (distab) THEN
     751              :             ! hard
     752        88380 :             CALL dgemm('N', 'N', na, nso, nb, fac, blk(1, 1), ldb, h_b(1, 1), nb, 0.0_dp, work1(1), na)
     753        88380 :             CALL dgemm('T', 'N', nso, nso, na, 1.0_dp, h_a(1, 1), na, work1(1), na, 0.0_dp, work2(1), nso)
     754        88380 :             CALL daxpy(nso*nso, 1.0_dp, work2(1), 1, proj_h(1, 1), 1)
     755              :             ! soft
     756        88380 :             CALL daxpy(nso*nso, 1.0_dp, work2(1), 1, proj_s(1, 1), 1)
     757              :          ELSE
     758              :             ! hard
     759       318250 :             CALL dgemm('N', 'N', na, nso, nb, fac, blk(1, 1), ldb, h_b(1, 1), nb, 0.0_dp, work1(1), na)
     760       318250 :             CALL dgemm('T', 'N', nso, nso, na, 1.0_dp, h_a(1, 1), na, work1(1), na, 1.0_dp, proj_h(1, 1), nso)
     761              :             ! soft
     762       318250 :             CALL dgemm('N', 'N', na, nso, nb, fac, blk(1, 1), ldb, s_b(1, 1), nb, 0.0_dp, work1(1), na)
     763       318250 :             CALL dgemm('T', 'N', nso, nso, na, 1.0_dp, s_a(1, 1), na, work1(1), na, 1.0_dp, proj_s(1, 1), nso)
     764              :          END IF
     765              :       END IF
     766              : 
     767              :    END SUBROUTINE proj_blk
     768              : 
     769              : ! **************************************************************************************************
     770              : !> \brief ...
     771              : !> \param ain matrix in old indexing
     772              : !> \param aout matrix in new compressed indexing
     773              : !> \param atom ...
     774              : ! **************************************************************************************************
     775       125596 :    SUBROUTINE prj_gather(ain, aout, atom)
     776              : 
     777              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(IN)         :: ain
     778              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(INOUT)      :: aout
     779              :       TYPE(qs_kind_type), INTENT(IN)                     :: atom
     780              : 
     781              :       INTEGER                                            :: i, ip, j, jp, nbas
     782       125596 :       INTEGER, DIMENSION(:), POINTER                     :: n2oindex
     783              :       TYPE(gto_basis_set_type), POINTER                  :: basis_1c
     784              : 
     785       125596 :       NULLIFY (basis_1c)
     786       125596 :       CALL get_qs_kind(qs_kind=atom, basis_set=basis_1c, basis_type="GAPW_1C")
     787       125596 :       NULLIFY (n2oindex)
     788       125596 :       CALL get_paw_basis_info(basis_1c, n2oindex=n2oindex, nsatbas=nbas)
     789              : 
     790      2218946 :       DO i = 1, nbas
     791      2093350 :          ip = n2oindex(i)
     792     61511040 :          DO j = 1, nbas
     793     59292094 :             jp = n2oindex(j)
     794     61385444 :             aout(j, i) = ain(jp, ip)
     795              :          END DO
     796              :       END DO
     797              : 
     798       125596 :       DEALLOCATE (n2oindex)
     799              : 
     800       125596 :    END SUBROUTINE prj_gather
     801              : 
     802              : ! **************************************************************************************************
     803              : !> \brief ...
     804              : !> \param ain  matrix in new compressed indexing
     805              : !> \param aout matrix in old indexing (addup)
     806              : !> \param atom ...
     807              : ! **************************************************************************************************
     808            0 :    SUBROUTINE prj_scatter(ain, aout, atom)
     809              : 
     810              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(IN)         :: ain
     811              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(INOUT)      :: aout
     812              :       TYPE(qs_kind_type), INTENT(IN)                     :: atom
     813              : 
     814              :       INTEGER                                            :: i, ip, j, jp, nbas
     815            0 :       INTEGER, DIMENSION(:), POINTER                     :: n2oindex
     816              :       TYPE(gto_basis_set_type), POINTER                  :: basis_1c
     817              : 
     818            0 :       NULLIFY (basis_1c)
     819            0 :       CALL get_qs_kind(qs_kind=atom, basis_set=basis_1c, basis_type="GAPW_1C")
     820            0 :       NULLIFY (n2oindex)
     821            0 :       CALL get_paw_basis_info(basis_1c, n2oindex=n2oindex, nsatbas=nbas)
     822              : 
     823            0 :       DO i = 1, nbas
     824            0 :          ip = n2oindex(i)
     825            0 :          DO j = 1, nbas
     826            0 :             jp = n2oindex(j)
     827            0 :             aout(jp, ip) = aout(jp, ip) + ain(j, i)
     828              :          END DO
     829              :       END DO
     830              : 
     831            0 :       DEALLOCATE (n2oindex)
     832              : 
     833            0 :    END SUBROUTINE prj_scatter
     834              : 
     835            0 : END MODULE qs_oce_methods
        

Generated by: LCOV version 2.0-1