22#include "./base/base_uses.f90"
29 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_ri_rs_grid_from_file'
40 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_ri_rs_grid_from_file'
42 CHARACTER(LEN=default_path_length) :: filepath
43 CHARACTER(LEN=default_string_length) :: element_symbol
44 INTEGER :: handle, iatom, ikind, natom, nkind
48 CALL timeset(routinen, handle)
50 cpassert(
ASSOCIATED(bs_env%ri_rs%atomic_kind_set))
51 nkind =
SIZE(bs_env%ri_rs%atomic_kind_set)
52 particle_set => bs_env%ri_rs%particle_set
53 cpassert(
ASSOCIATED(particle_set))
55 ALLOCATE (kind_grids(nkind))
58 element_symbol = trim(bs_env%ri_rs%atomic_kind_set(ikind)%element_symbol)
59 CALL get_ri_rs_grid_filepath(element_symbol, bs_env%ri_rs%grid_select, &
60 bs_env%ri_rs%grid_file_suffix, filepath)
61 CALL read_ri_rs_grid_file(trim(filepath), kind_grids(ikind)%raw_points)
62 kind_grids(ikind)%npts =
SIZE(kind_grids(ikind)%raw_points, 2)
65 IF (
ALLOCATED(bs_env%ri_rs%atomic_grids))
DEALLOCATE (bs_env%ri_rs%atomic_grids)
66 ALLOCATE (bs_env%ri_rs%atomic_grids(natom))
68 ikind = particle_set(iatom)%atomic_kind%kind_number
69 bs_env%ri_rs%atomic_grids(iatom) = kind_grids(ikind)
71 DEALLOCATE (kind_grids)
84 SUBROUTINE get_ri_rs_grid_filepath(element_symbol, grid_select, grid_file_suffix, filepath)
85 CHARACTER(LEN=*),
INTENT(IN) :: element_symbol
86 INTEGER,
INTENT(IN) :: grid_select
87 CHARACTER(LEN=*),
INTENT(IN) :: grid_file_suffix
88 CHARACTER(LEN=*),
INTENT(OUT) :: filepath
90 CHARACTER(LEN=default_string_length) :: suffix
92 SELECT CASE (grid_select)
94 suffix =
"_def2-tzvp-rs.ion"
96 suffix =
"_cc-pvtz-rs.ion"
98 IF (len_trim(grid_file_suffix) > 0)
THEN
99 suffix = trim(grid_file_suffix)
104 cpabort(
"Unknown grid_select (1=def2-TZVPP, 2=cc-pVTZ, 3=user-provided).")
106 filepath =
"ri_rs_grid/"//trim(element_symbol)//trim(suffix)
107 END SUBROUTINE get_ri_rs_grid_filepath
114 SUBROUTINE read_ri_rs_grid_file(filename, points)
115 CHARACTER(LEN=*),
INTENT(IN) :: filename
116 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :), &
117 INTENT(OUT) :: points
119 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_ri_rs_grid_file'
121 CHARACTER(LEN=default_path_length) :: line
122 INTEGER :: handle, ierr, ipoint, iunit, npoints
123 LOGICAL :: found_points
125 CALL timeset(routinen, handle)
126 CALL open_file(file_name=trim(filename), unit_number=iunit, &
127 file_action=
'READ', file_status=
'OLD')
129 CALL read_ri_rs_grid_header(iunit, filename, npoints)
132 found_points = .false.
134 READ (iunit,
'(A)', iostat=ierr) line
136 IF (index(line,
'<grid_points>') > 0)
THEN
137 found_points = .true.
141 IF (.NOT. found_points)
THEN
142 cpabort(
'RI-RS .ion file has no <grid_points> block: '//trim(filename))
145 ALLOCATE (points(3, npoints))
146 DO ipoint = 1, npoints
147 READ (iunit, *, iostat=ierr) points(:, ipoint)
148 IF (ierr /= 0) cpabort(
'Invalid grid point in RI-RS .ion file: '//trim(filename))
151 CALL timestop(handle)
152 END SUBROUTINE read_ri_rs_grid_file
160 SUBROUTINE read_ri_rs_grid_header(iunit, filename, npoints)
161 INTEGER,
INTENT(IN) :: iunit
162 CHARACTER(LEN=*),
INTENT(IN) :: filename
163 INTEGER,
INTENT(OUT) :: npoints
165 CHARACTER(LEN=default_path_length) :: line
166 INTEGER :: colon, ierr
167 LOGICAL :: found_size
172 READ (iunit,
'(A)', iostat=ierr) line
174 IF (index(line,
'n points') > 0)
THEN
175 colon = index(line,
':')
177 READ (line(colon + 1:), *, iostat=ierr) npoints
178 found_size = ierr == 0 .AND. npoints > 0
183 IF (.NOT. found_size)
THEN
184 cpabort(
'RI-RS .ion file has no valid n points field: '//trim(filename))
186 END SUBROUTINE read_ri_rs_grid_header
Utility routines to open and close files. Tracking of preconnections.
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Read pretabulated atom-relative RI-RS grids from data files.
subroutine, public read_ri_rs_grid_from_file(bs_env)
Read pretabulated atom-relative RI-RS grids from the CP2K data files.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Define the data structure for the particle information.