LCOV - code coverage report
Current view: top level - src/aobasis - soft_basis_set.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:936074a) Lines: 100.0 % 157 157
Test Date: 2025-12-04 06:27:48 Functions: 100.0 % 1 1

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2025 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \par History
      10              : !>      none
      11              : !> \author MI (08.01.2004)
      12              : ! **************************************************************************************************
      13              : MODULE soft_basis_set
      14              : 
      15              :    USE ao_util,                         ONLY: exp_radius
      16              :    USE basis_set_types,                 ONLY: copy_gto_basis_set,&
      17              :                                               deallocate_gto_basis_set,&
      18              :                                               get_gto_basis_set,&
      19              :                                               gto_basis_set_type,&
      20              :                                               init_cphi_and_sphi
      21              :    USE kinds,                           ONLY: default_string_length,&
      22              :                                               dp
      23              :    USE memory_utilities,                ONLY: reallocate
      24              :    USE orbital_pointers,                ONLY: indco,&
      25              :                                               nco,&
      26              :                                               ncoset,&
      27              :                                               nso
      28              :    USE orbital_symbols,                 ONLY: cgf_symbol,&
      29              :                                               sgf_symbol
      30              : #include "../base/base_uses.f90"
      31              : 
      32              :    IMPLICIT NONE
      33              : 
      34              :    PRIVATE
      35              : 
      36              : ! *** Global parameters (only in this module)
      37              : 
      38              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'soft_basis_set'
      39              : 
      40              :    INTEGER, PARAMETER :: max_name_length = 60
      41              : 
      42              : ! *** Public subroutines ***
      43              : 
      44              :    PUBLIC :: create_soft_basis
      45              : 
      46              : CONTAINS
      47              : 
      48              : ! **************************************************************************************************
      49              : !> \brief   create the soft basis from a GTO basis
      50              : !> \param orb_basis ...
      51              : !> \param soft_basis ...
      52              : !> \param eps_fit ...
      53              : !> \param rc ...
      54              : !> \param paw_atom ...
      55              : !> \param paw_type_forced ...
      56              : !> \param gpw_r3d_rs_type_forced ...
      57              : !> \version 1.0
      58              : ! **************************************************************************************************
      59         2124 :    SUBROUTINE create_soft_basis(orb_basis, soft_basis, eps_fit, rc, paw_atom, &
      60              :                                 paw_type_forced, gpw_r3d_rs_type_forced)
      61              : 
      62              :       TYPE(gto_basis_set_type), POINTER                  :: orb_basis, soft_basis
      63              :       REAL(dp), INTENT(IN)                               :: eps_fit, rc
      64              :       LOGICAL, INTENT(OUT)                               :: paw_atom
      65              :       LOGICAL, INTENT(IN)                                :: paw_type_forced, gpw_r3d_rs_type_forced
      66              : 
      67              :       CHARACTER(LEN=default_string_length)               :: bsname
      68              :       INTEGER :: ico, ipgf, ipgf_s, iset, iset_s, ishell, lshell, lshell_old, m, maxco, maxpgf, &
      69              :          maxpgf_s, maxshell, maxshell_s, ncgf, nset, nset_s, nsgf
      70         2124 :       INTEGER, ALLOCATABLE, DIMENSION(:)                 :: iset_s2h
      71         2124 :       INTEGER, DIMENSION(:), POINTER                     :: lmax, lmin, npgf, nshell
      72         2124 :       INTEGER, DIMENSION(:, :), POINTER                  :: l, n
      73              :       LOGICAL                                            :: my_gpw_r3d_rs_type_forced
      74              :       REAL(KIND=dp)                                      :: minzet, radius
      75         2124 :       REAL(KIND=dp), DIMENSION(:, :), POINTER            :: zet
      76         2124 :       REAL(KIND=dp), DIMENSION(:, :, :), POINTER         :: gcc
      77              : 
      78         2124 :       NULLIFY (gcc, l, lmax, lmin, n, npgf, nshell, zet)
      79         2124 :       paw_atom = .FALSE.
      80         2124 :       my_gpw_r3d_rs_type_forced = gpw_r3d_rs_type_forced
      81         2124 :       IF (paw_type_forced) THEN
      82           34 :          paw_atom = .TRUE.
      83              :          my_gpw_r3d_rs_type_forced = .FALSE.
      84              :       END IF
      85         2090 :       IF (.NOT. my_gpw_r3d_rs_type_forced) THEN
      86              :          CALL get_gto_basis_set(gto_basis_set=orb_basis, name=bsname, &
      87         2096 :                                 maxpgf=maxpgf, maxshell=maxshell, nset=nset)
      88              : 
      89         2096 :          soft_basis%name = TRIM(bsname)//"_soft"
      90              : 
      91         2096 :          CALL reallocate(npgf, 1, nset)
      92         2096 :          CALL reallocate(nshell, 1, nset)
      93         2096 :          CALL reallocate(lmax, 1, nset)
      94         2096 :          CALL reallocate(lmin, 1, nset)
      95              : 
      96         2096 :          CALL reallocate(n, 1, maxshell, 1, nset)
      97         2096 :          CALL reallocate(l, 1, maxshell, 1, nset)
      98              : 
      99         2096 :          CALL reallocate(zet, 1, maxpgf, 1, nset)
     100         2096 :          CALL reallocate(gcc, 1, maxpgf, 1, maxshell, 1, nset)
     101              : 
     102         6288 :          ALLOCATE (iset_s2h(nset))
     103              : 
     104         8308 :          iset_s2h = 0
     105         2096 :          iset_s = 0
     106         2096 :          maxpgf_s = 0
     107         2096 :          maxshell_s = 0
     108              : 
     109         8308 :          DO iset = 1, nset ! iset
     110         6212 :             minzet = orb_basis%zet(orb_basis%npgf(iset), iset)
     111        14762 :             DO ipgf = orb_basis%npgf(iset) - 1, 1, -1
     112        14762 :                IF (orb_basis%zet(ipgf, iset) < minzet) THEN
     113           42 :                   minzet = orb_basis%zet(ipgf, iset)
     114              :                END IF
     115              :             END DO
     116         6212 :             radius = exp_radius(orb_basis%lmax(iset), minzet, eps_fit, 1.0_dp)
     117              : 
     118              :             !      The soft basis contains this set
     119         6212 :             iset_s = iset_s + 1
     120         6212 :             nshell(iset_s) = orb_basis%nshell(iset)
     121         6212 :             lmax(iset_s) = orb_basis%lmax(iset)
     122         6212 :             lmin(iset_s) = orb_basis%lmin(iset)
     123              : 
     124         6212 :             iset_s2h(iset_s) = iset
     125              : 
     126        16046 :             DO ishell = 1, nshell(iset_s)
     127         9834 :                n(ishell, iset_s) = orb_basis%n(ishell, iset)
     128        16046 :                l(ishell, iset_s) = orb_basis%l(ishell, iset)
     129              :             END DO
     130              : 
     131         6212 :             IF (nshell(iset_s) > maxshell_s) THEN
     132         2552 :                maxshell_s = nshell(iset_s)
     133              :             END IF
     134              : 
     135         6212 :             IF (radius < rc) THEN
     136              :                ! The soft basis does not contain this set
     137              :                ! For the moment I keep the set as a dummy set
     138              :                ! with no exponents, in order to have the right number of contractions
     139              :                ! In a second time it can be taken away, by creating a pointer
     140              :                ! which connects the remaining sets to the right contraction index
     141          580 :                paw_atom = .TRUE.
     142          580 :                npgf(iset_s) = 0
     143          580 :                CYCLE
     144              :             END IF
     145              : 
     146         5632 :             ipgf_s = 0
     147        18108 :             DO ipgf = 1, orb_basis%npgf(iset) ! ipgf
     148        12476 :                IF (orb_basis%zet(ipgf, iset) > 100.0_dp) THEN
     149              :                   ! The soft basis does not contain this exponent
     150          720 :                   paw_atom = .TRUE.
     151          720 :                   CYCLE
     152              :                END IF
     153              : 
     154              :                radius = exp_radius(orb_basis%lmax(iset), orb_basis%zet(ipgf, iset), &
     155        11756 :                                    eps_fit, 1.0_dp)
     156        11756 :                IF (radius < rc) THEN
     157              :                   ! The soft basis does not contain this exponent
     158         2572 :                   paw_atom = .TRUE.
     159         2572 :                   CYCLE
     160              :                END IF
     161              : 
     162              :                ! The soft basis contains this exponent
     163         9184 :                ipgf_s = ipgf_s + 1
     164         9184 :                zet(ipgf_s, iset_s) = orb_basis%zet(ipgf, iset)
     165              : 
     166         9184 :                lshell_old = orb_basis%l(1, iset)
     167         9184 :                radius = exp_radius(lshell_old, zet(ipgf_s, iset_s), eps_fit, 1.0_dp)
     168              : 
     169        34520 :                DO ishell = 1, nshell(iset_s)
     170        19704 :                   lshell = orb_basis%l(ishell, iset)
     171        19704 :                   IF (lshell == lshell_old) THEN
     172              :                   ELSE
     173         3650 :                      lshell_old = lshell
     174         3650 :                      radius = exp_radius(lshell_old, zet(ipgf_s, iset_s), eps_fit, 1.0_dp)
     175              :                   END IF
     176        28888 :                   IF (radius < rc) THEN
     177            4 :                      gcc(ipgf_s, ishell, iset_s) = 0.0_dp
     178            4 :                      paw_atom = .TRUE.
     179              :                   ELSE
     180        19700 :                      gcc(ipgf_s, ishell, iset_s) = orb_basis%gcc(ipgf, ishell, iset)
     181              :                   END IF
     182              :                END DO
     183              :             END DO
     184         5632 :             npgf(iset_s) = ipgf_s
     185         7728 :             IF (ipgf_s > maxpgf_s) THEN
     186         2354 :                maxpgf_s = ipgf_s
     187              :             END IF
     188              :          END DO
     189         2096 :          nset_s = iset_s
     190         2096 :          IF (paw_atom) THEN
     191         1796 :             soft_basis%nset = nset_s
     192         1796 :             CALL reallocate(soft_basis%lmax, 1, nset_s)
     193         1796 :             CALL reallocate(soft_basis%lmin, 1, nset_s)
     194         1796 :             CALL reallocate(soft_basis%npgf, 1, nset_s)
     195         1796 :             CALL reallocate(soft_basis%nshell, 1, nset_s)
     196         1796 :             CALL reallocate(soft_basis%n, 1, maxshell_s, 1, nset_s)
     197         1796 :             CALL reallocate(soft_basis%l, 1, maxshell_s, 1, nset_s)
     198         1796 :             CALL reallocate(soft_basis%zet, 1, maxpgf_s, 1, nset_s)
     199         1796 :             CALL reallocate(soft_basis%gcc, 1, maxpgf_s, 1, maxshell_s, 1, nset_s)
     200              : 
     201              :             ! *** Copy the basis set information into the data structure ***
     202              : 
     203         7492 :             DO iset = 1, nset_s
     204         5696 :                soft_basis%lmax(iset) = lmax(iset)
     205         5696 :                soft_basis%lmin(iset) = lmin(iset)
     206         5696 :                soft_basis%npgf(iset) = npgf(iset)
     207         5696 :                soft_basis%nshell(iset) = nshell(iset)
     208        14560 :                DO ishell = 1, nshell(iset)
     209         8864 :                   soft_basis%n(ishell, iset) = n(ishell, iset)
     210         8864 :                   soft_basis%l(ishell, iset) = l(ishell, iset)
     211        31568 :                   DO ipgf = 1, npgf(iset)
     212        25872 :                      soft_basis%gcc(ipgf, ishell, iset) = gcc(ipgf, ishell, iset)
     213              :                   END DO
     214              :                END DO
     215        15626 :                DO ipgf = 1, npgf(iset)
     216        13830 :                   soft_basis%zet(ipgf, iset) = zet(ipgf, iset)
     217              :                END DO
     218              :             END DO
     219              : 
     220              :             ! *** Initialise the depending soft_basis pointers ***
     221         1796 :             CALL reallocate(soft_basis%set_radius, 1, nset_s)
     222         1796 :             CALL reallocate(soft_basis%pgf_radius, 1, maxpgf_s, 1, nset_s)
     223         1796 :             CALL reallocate(soft_basis%first_cgf, 1, maxshell_s, 1, nset_s)
     224         1796 :             CALL reallocate(soft_basis%first_sgf, 1, maxshell_s, 1, nset_s)
     225         1796 :             CALL reallocate(soft_basis%last_cgf, 1, maxshell_s, 1, nset_s)
     226         1796 :             CALL reallocate(soft_basis%last_sgf, 1, maxshell_s, 1, nset_s)
     227         1796 :             CALL reallocate(soft_basis%ncgf_set, 1, nset_s)
     228         1796 :             CALL reallocate(soft_basis%nsgf_set, 1, nset_s)
     229              : 
     230         1796 :             maxco = 0
     231         1796 :             ncgf = 0
     232         1796 :             nsgf = 0
     233              : 
     234         7492 :             DO iset = 1, nset_s
     235         5696 :                soft_basis%ncgf_set(iset) = 0
     236         5696 :                soft_basis%nsgf_set(iset) = 0
     237        14560 :                DO ishell = 1, nshell(iset)
     238         8864 :                   lshell = soft_basis%l(ishell, iset)
     239         8864 :                   soft_basis%first_cgf(ishell, iset) = ncgf + 1
     240         8864 :                   ncgf = ncgf + nco(lshell)
     241         8864 :                   soft_basis%last_cgf(ishell, iset) = ncgf
     242              :                   soft_basis%ncgf_set(iset) = &
     243         8864 :                      soft_basis%ncgf_set(iset) + nco(lshell)
     244         8864 :                   soft_basis%first_sgf(ishell, iset) = nsgf + 1
     245         8864 :                   nsgf = nsgf + nso(lshell)
     246         8864 :                   soft_basis%last_sgf(ishell, iset) = nsgf
     247              :                   soft_basis%nsgf_set(iset) = &
     248        14560 :                      soft_basis%nsgf_set(iset) + nso(lshell)
     249              :                END DO
     250         7492 :                maxco = MAX(maxco, npgf(iset)*ncoset(lmax(iset)))
     251              :             END DO
     252         1796 :             soft_basis%ncgf = ncgf
     253         1796 :             soft_basis%nsgf = nsgf
     254              : 
     255         1796 :             CALL reallocate(soft_basis%cphi, 1, maxco, 1, ncgf)
     256         1796 :             CALL reallocate(soft_basis%sphi, 1, maxco, 1, nsgf)
     257         1796 :             CALL reallocate(soft_basis%scon, 1, maxco, 1, nsgf)
     258         1796 :             CALL reallocate(soft_basis%lx, 1, ncgf)
     259         1796 :             CALL reallocate(soft_basis%ly, 1, ncgf)
     260         1796 :             CALL reallocate(soft_basis%lz, 1, ncgf)
     261         1796 :             CALL reallocate(soft_basis%m, 1, nsgf)
     262         1796 :             CALL reallocate(soft_basis%norm_cgf, 1, ncgf)
     263         5388 :             ALLOCATE (soft_basis%cgf_symbol(ncgf))
     264         5388 :             ALLOCATE (soft_basis%sgf_symbol(nsgf))
     265              : 
     266         1796 :             ncgf = 0
     267         1796 :             nsgf = 0
     268              : 
     269         7492 :             DO iset = 1, nset_s
     270        16356 :                DO ishell = 1, nshell(iset)
     271         8864 :                   lshell = soft_basis%l(ishell, iset)
     272        29908 :                   DO ico = ncoset(lshell - 1) + 1, ncoset(lshell)
     273        21044 :                      ncgf = ncgf + 1
     274        21044 :                      soft_basis%lx(ncgf) = indco(1, ico)
     275        21044 :                      soft_basis%ly(ncgf) = indco(2, ico)
     276        21044 :                      soft_basis%lz(ncgf) = indco(3, ico)
     277              :                      soft_basis%cgf_symbol(ncgf) = &
     278              :                         cgf_symbol(n(ishell, iset), [soft_basis%lx(ncgf), &
     279              :                                                      soft_basis%ly(ncgf), &
     280        93040 :                                                      soft_basis%lz(ncgf)])
     281              :                   END DO
     282        34296 :                   DO m = -lshell, lshell
     283        19736 :                      nsgf = nsgf + 1
     284        19736 :                      soft_basis%m(nsgf) = m
     285              :                      soft_basis%sgf_symbol(nsgf) = &
     286        28600 :                         sgf_symbol(n(ishell, iset), lshell, m)
     287              :                   END DO
     288              :                END DO
     289              :             END DO
     290              : 
     291              :             ! *** Normalization factor of the contracted Gaussians ***
     292         1796 :             soft_basis%norm_type = orb_basis%norm_type
     293        43884 :             soft_basis%norm_cgf = orb_basis%norm_cgf
     294              :             ! *** Initialize the transformation matrices ***
     295         1796 :             CALL init_cphi_and_sphi(soft_basis)
     296              :          END IF
     297              : 
     298         4192 :          DEALLOCATE (gcc, l, lmax, lmin, n, npgf, nshell, zet, iset_s2h)
     299              :       END IF
     300              : 
     301         2124 :       IF (.NOT. paw_atom) THEN
     302          328 :          CALL deallocate_gto_basis_set(soft_basis)
     303          328 :          CALL copy_gto_basis_set(orb_basis, soft_basis)
     304          328 :          CALL get_gto_basis_set(gto_basis_set=orb_basis, name=bsname)
     305          328 :          soft_basis%name = TRIM(bsname)//"_soft"
     306              :       END IF
     307              : 
     308         2124 :    END SUBROUTINE create_soft_basis
     309              : 
     310              : END MODULE soft_basis_set
        

Generated by: LCOV version 2.0-1