(git:b195825)
tip_scan_methods.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
9  USE cp_control_types, ONLY: dft_control_type
10  USE cp_files, ONLY: close_file,&
11  open_file
14  cp_logger_type
17  USE input_section_types, ONLY: section_vals_type,&
19  USE kinds, ONLY: default_string_length,&
20  dp
21  USE message_passing, ONLY: mp_para_env_type
22  USE pw_env_types, ONLY: pw_env_get,&
23  pw_env_type
24  USE pw_grid_types, ONLY: pw_grid_type
25  USE pw_grids, ONLY: pw_grid_create,&
28  USE pw_methods, ONLY: pw_axpy,&
29  pw_multiply_with,&
31  pw_transfer,&
32  pw_zero
33  USE pw_pool_types, ONLY: pw_pool_type
34  USE pw_types, ONLY: pw_c1d_gs_type,&
35  pw_r3d_rs_type
36  USE qs_environment_types, ONLY: get_qs_env,&
37  qs_environment_type
38  USE qs_ks_types, ONLY: qs_ks_env_type,&
40  USE qs_mo_types, ONLY: deallocate_mo_set,&
42  mo_set_type,&
44  USE qs_scf, ONLY: scf
47  scanning_type
48 #include "./base/base_uses.f90"
49 
50  IMPLICIT NONE
51 
52  PRIVATE
53 
54  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tip_scan_methods'
55 
56  PUBLIC :: tip_scanning
57 
58 ! **************************************************************************************************
59 
60 CONTAINS
61 
62 ! **************************************************************************************************
63 !> \brief Perform tip scanning calculation.
64 !> \param qs_env Quickstep environment
65 !> input_section Tip Scan Section
66 !> \param input_section ...
67 !> \par History
68 !> * 05.2021 created [JGH]
69 ! **************************************************************************************************
70  SUBROUTINE tip_scanning(qs_env, input_section)
71  TYPE(qs_environment_type), POINTER :: qs_env
72  TYPE(section_vals_type), POINTER :: input_section
73 
74  CHARACTER(LEN=*), PARAMETER :: routinen = 'tip_scanning'
75 
76  CHARACTER(LEN=default_string_length) :: cname
77  INTEGER :: handle, iounit, iscan, iset, nscan, &
78  nset, plevel, tsteps
79  LOGICAL :: do_tip_scan, expot, scf_converged
80  REAL(kind=dp), DIMENSION(3) :: rpos
81  TYPE(cp_logger_type), POINTER :: logger
82  TYPE(dft_control_type), POINTER :: dft_control
83  TYPE(mo_set_type), ALLOCATABLE, DIMENSION(:) :: mos_ref
84  TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
85  TYPE(pw_c1d_gs_type) :: sf, vref
86  TYPE(pw_env_type), POINTER :: pw_env
87  TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
88  TYPE(pw_r3d_rs_type), POINTER :: vee, vtip
89  TYPE(qs_ks_env_type), POINTER :: ks_env
90  TYPE(scanning_type) :: scan_env
91 
92  CALL timeset(routinen, handle)
93 
94  NULLIFY (logger)
95  logger => cp_get_default_logger()
96 
97  CALL section_vals_val_get(input_section, "_SECTION_PARAMETERS_", l_val=do_tip_scan)
98  IF (do_tip_scan) THEN
99  iounit = cp_logger_get_default_io_unit(logger)
100  cname = logger%iter_info%project_name
101  logger%iter_info%project_name = logger%iter_info%project_name//"+TIP_SCAN"
102  plevel = logger%iter_info%print_level
103  logger%iter_info%print_level = silent_print_level
104 
105  IF (iounit > 0) THEN
106  WRITE (iounit, "(T2,A)") "TIP SCAN| Perform a Tip Scanning Calculation"
107  END IF
108 
109  ! read the input section
110  CALL read_scanning_section(scan_env, input_section)
111  ! read tip potential file
112  CALL read_tip_file(qs_env, scan_env)
113 
114  CALL get_qs_env(qs_env, ks_env=ks_env, pw_env=pw_env, &
115  dft_control=dft_control)
116  expot = dft_control%apply_external_potential
117  dft_control%apply_external_potential = .true.
118  IF (expot) THEN
119  ! save external potential
120  CALL get_qs_env(qs_env, vee=vee)
121  END IF
122 
123  ! scratch memory for tip potentials and structure factor
124  CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
125  NULLIFY (vtip)
126  ALLOCATE (vtip)
127  CALL auxbas_pw_pool%create_pw(vtip)
128  CALL pw_zero(vtip)
129  CALL auxbas_pw_pool%create_pw(vref)
130  CALL pw_zero(vref)
131  CALL auxbas_pw_pool%create_pw(sf)
132 
133  ! get the reference tip potential and store it in reciprocal space (vref)
134  CALL pw_transfer(scan_env%tip_pw_g, vref)
135 
136  ! store reference MOs
137  CALL get_qs_env(qs_env, mos=mos)
138  nset = SIZE(mos)
139  ALLOCATE (mos_ref(nset))
140  DO iset = 1, nset
141  CALL duplicate_mo_set(mos_ref(iset), mos(iset))
142  END DO
143 
144  nscan = scan_env%num_scan_points
145  IF (iounit > 0) THEN
146  WRITE (iounit, "(T2,A,T74,I7)") "TIP SCAN| Number of scanning points ", nscan
147  WRITE (iounit, "(T2,A)") "TIP SCAN| Start scanning ..."
148  END IF
149 
150  DO iscan = 1, nscan
151  IF (iounit > 0) THEN
152  WRITE (iounit, "(T2,A,I7)", advance="NO") "TIP SCAN| Scan point ", iscan
153  END IF
154 
155  ! shift the reference tip potential
156  rpos(1:3) = scan_env%tip_pos(1:3, iscan) - scan_env%ref_point(1:3)
157  CALL shift_tip_potential(vref, sf, vtip, rpos)
158  ! set the external potential
159  IF (ASSOCIATED(vee)) THEN
160  CALL pw_axpy(vee, vtip, alpha=1.0_dp)
161  END IF
162  CALL set_ks_env(ks_env, vee=vtip)
163 
164  ! reset MOs
165  CALL get_qs_env(qs_env, mos=mos)
166  DO iset = 1, nset
167  CALL reassign_allocated_mos(mos(iset), mos_ref(iset))
168  END DO
169 
170  ! Calculate electronic structure
171  CALL scf(qs_env, has_converged=scf_converged, total_scf_steps=tsteps)
172 
173  IF (iounit > 0) THEN
174  IF (scf_converged) THEN
175  WRITE (iounit, "(T25,A,I4,A)") "SCF converged in ", tsteps, " steps"
176  ELSE
177  WRITE (iounit, "(T31,A)") "SCF did not converge!"
178  END IF
179  END IF
180  END DO
181  CALL release_scanning_type(scan_env)
182 
183  IF (iounit > 0) THEN
184  WRITE (iounit, "(T2,A)") "TIP SCAN| ... end scanning"
185  END IF
186  dft_control%apply_external_potential = expot
187  IF (expot) THEN
188  ! restore vee
189  CALL set_ks_env(ks_env, vee=vee)
190  ELSE
191  NULLIFY (vee)
192  CALL set_ks_env(ks_env, vee=vee)
193  END IF
194  CALL auxbas_pw_pool%give_back_pw(vtip)
195  CALL auxbas_pw_pool%give_back_pw(vref)
196  CALL auxbas_pw_pool%give_back_pw(sf)
197  DEALLOCATE (vtip)
198 
199  logger%iter_info%print_level = plevel
200  logger%iter_info%project_name = cname
201 
202  ! reset MOs
203  CALL get_qs_env(qs_env, mos=mos)
204  DO iset = 1, nset
205  CALL reassign_allocated_mos(mos(iset), mos_ref(iset))
206  CALL deallocate_mo_set(mos_ref(iset))
207  END DO
208  DEALLOCATE (mos_ref)
209  END IF
210 
211  CALL timestop(handle)
212 
213  END SUBROUTINE tip_scanning
214 
215 ! **************************************************************************************************
216 !> \brief Shift tip potential in reciprocal space
217 !> \param vref ...
218 !> \param sf ...
219 !> \param vtip ...
220 !> \param rpos ...
221 !> \par History
222 !> * 05.2021 created [JGH]
223 ! **************************************************************************************************
224  SUBROUTINE shift_tip_potential(vref, sf, vtip, rpos)
225 
226  TYPE(pw_c1d_gs_type), INTENT(INOUT) :: vref, sf
227  TYPE(pw_r3d_rs_type), INTENT(INOUT) :: vtip
228  REAL(kind=dp), DIMENSION(3), INTENT(IN) :: rpos
229 
230  CHARACTER(LEN=*), PARAMETER :: routinen = 'shift_tip_potential'
231 
232  INTEGER :: handle
233 
234  CALL timeset(routinen, handle)
235 
236  CALL pw_structure_factor(sf, rpos)
237  CALL pw_multiply_with(sf, vref)
238  CALL pw_transfer(sf, vtip)
239 
240  CALL timestop(handle)
241 
242  END SUBROUTINE shift_tip_potential
243 
244 ! **************************************************************************************************
245 !> \brief Read tip potential from cube file. Allow any spacing and cell size
246 !> \param qs_env ...
247 !> \param scan_env ...
248 !> \par History
249 !> * 05.2021 created [JGH]
250 ! **************************************************************************************************
251  SUBROUTINE read_tip_file(qs_env, scan_env)
252  TYPE(qs_environment_type), POINTER :: qs_env
253  TYPE(scanning_type), INTENT(INOUT) :: scan_env
254 
255  CHARACTER(LEN=*), PARAMETER :: routinen = 'read_tip_file'
256 
257  INTEGER :: extunit, handle, i, nat
258  INTEGER, DIMENSION(3) :: npts
259  REAL(kind=dp) :: scaling
260  REAL(kind=dp), DIMENSION(3) :: rdum
261  REAL(kind=dp), DIMENSION(3, 3) :: dcell
262  TYPE(mp_para_env_type), POINTER :: para_env
263  TYPE(pw_grid_type), POINTER :: pw_grid
264 
265  CALL timeset(routinen, handle)
266 
267  CALL get_qs_env(qs_env, para_env=para_env)
268 
269  IF (para_env%is_source()) THEN
270  CALL open_file(file_name=scan_env%tip_cube_file, &
271  file_status="OLD", &
272  file_form="FORMATTED", &
273  file_action="READ", &
274  unit_number=extunit)
275  !skip header comments
276  DO i = 1, 2
277  READ (extunit, *)
278  END DO
279  READ (extunit, *) nat, rdum
280  DO i = 1, 3
281  READ (extunit, *) npts(i), dcell(i, 1:3)
282  dcell(i, 1:3) = npts(i)*dcell(i, 1:3)
283  END DO
284  CALL close_file(unit_number=extunit)
285  END IF
286 
287  CALL para_env%bcast(npts)
288  CALL para_env%bcast(dcell)
289 
290  NULLIFY (pw_grid)
291  CALL pw_grid_create(pw_grid, para_env)
292  CALL pw_grid_setup(dcell, pw_grid, npts=npts)
293  CALL scan_env%tip_pw_r%create(pw_grid)
294 !deb
295  scaling = 0.1_dp
296 !deb
297  CALL cp_cube_to_pw(scan_env%tip_pw_r, scan_env%tip_cube_file, scaling, silent=.true.)
298  CALL scan_env%tip_pw_g%create(pw_grid)
299  CALL pw_transfer(scan_env%tip_pw_r, scan_env%tip_pw_g)
300  CALL pw_grid_release(pw_grid)
301 
302  CALL timestop(handle)
303 
304  END SUBROUTINE read_tip_file
305 
306 END MODULE tip_scan_methods
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Utility routines to open and close files. Tracking of preconnections.
Definition: cp_files.F:16
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.
Definition: cp_files.F:308
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.
Definition: cp_files.F:119
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public silent_print_level
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_cube_to_pw(grid, filename, scaling, silent)
Thin wrapper around routine cube_to_pw.
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
integer, parameter, public default_string_length
Definition: kinds.F:57
Interface to the message passing library MPI.
container for various plainwaves related things
Definition: pw_env_types.F:14
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Definition: pw_env_types.F:113
This module defines the grid data type and some basic operations on it.
Definition: pw_grids.F:36
subroutine, public pw_grid_release(pw_grid)
releases the given pw grid
Definition: pw_grids.F:2133
subroutine, public pw_grid_setup(cell_hmat, pw_grid, grid_span, cutoff, bounds, bounds_local, npts, spherical, odd, fft_usage, ncommensurate, icommensurate, blocked, ref_grid, rs_dims, iounit)
sets up a pw_grid
Definition: pw_grids.F:286
subroutine, public pw_grid_create(pw_grid, pe_group, local)
Initialize a PW grid with all defaults.
Definition: pw_grids.F:93
subroutine, public pw_structure_factor(sf, r)
Calculate the structure factor for point r.
Definition: pw_methods.F:10358
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Definition: pw_pool_types.F:24
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, WannierCentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Get the QUICKSTEP environment.
subroutine, public set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_ks_im_kp, vppl, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, task_list, task_list_soft, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env)
...
Definition: qs_ks_types.F:567
Definition and initialisation of the mo data type.
Definition: qs_mo_types.F:22
subroutine, public duplicate_mo_set(mo_set_new, mo_set_old)
allocate a new mo_set, and copy the old data
Definition: qs_mo_types.F:149
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
Definition: qs_mo_types.F:352
subroutine, public reassign_allocated_mos(mo_set_new, mo_set_old)
reassign an already allocated mo_set
Definition: qs_mo_types.F:109
Routines for the Quickstep SCF run.
Definition: qs_scf.F:47
subroutine, public scf(qs_env, has_converged, total_scf_steps)
perform an scf procedure in the given qs_env
Definition: qs_scf.F:201
subroutine, public tip_scanning(qs_env, input_section)
Perform tip scanning calculation.
subroutine, public release_scanning_type(scan_info)
...
subroutine, public read_scanning_section(scan_info, input_section)
...