(git:ed6f26b)
Loading...
Searching...
No Matches
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-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
10 USE cp_files, ONLY: close_file,&
19 USE kinds, ONLY: default_string_length,&
20 dp
22 USE pw_env_types, ONLY: pw_env_get,&
25 USE pw_grids, ONLY: pw_grid_create,&
27 USE pw_methods, ONLY: pw_axpy,&
33 USE pw_types, ONLY: pw_c1d_gs_type,&
37 USE qs_ks_types, ONLY: qs_ks_env_type,&
43 USE qs_scf, ONLY: scf
47#include "./base/base_uses.f90"
48
49 IMPLICIT NONE
50
51 PRIVATE
52
53 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tip_scan_methods'
54
55 PUBLIC :: tip_scanning
56
57! **************************************************************************************************
58
59CONTAINS
60
61! **************************************************************************************************
62!> \brief Perform tip scanning calculation.
63!> \param qs_env Quickstep environment
64!> input_section Tip Scan Section
65!> \param input_section ...
66!> \par History
67!> * 05.2021 created [JGH]
68! **************************************************************************************************
69 SUBROUTINE tip_scanning(qs_env, input_section)
70 TYPE(qs_environment_type), POINTER :: qs_env
71 TYPE(section_vals_type), POINTER :: input_section
72
73 CHARACTER(LEN=*), PARAMETER :: routinen = 'tip_scanning'
74
75 CHARACTER(LEN=default_string_length) :: cname
76 INTEGER :: handle, iounit, iscan, iset, nscan, &
77 nset, plevel, tsteps
78 LOGICAL :: do_tip_scan, expot, scf_converged
79 REAL(kind=dp), DIMENSION(3) :: rpos
80 TYPE(cp_logger_type), POINTER :: logger
81 TYPE(dft_control_type), POINTER :: dft_control
82 TYPE(mo_set_type), ALLOCATABLE, DIMENSION(:) :: mos_ref
83 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
84 TYPE(pw_c1d_gs_type) :: sf, vref
85 TYPE(pw_env_type), POINTER :: pw_env
86 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
87 TYPE(pw_r3d_rs_type), POINTER :: vee, vtip
88 TYPE(qs_ks_env_type), POINTER :: ks_env
89 TYPE(scanning_type) :: scan_env
90
91 CALL timeset(routinen, handle)
92
93 NULLIFY (logger)
94 logger => cp_get_default_logger()
95
96 CALL section_vals_val_get(input_section, "_SECTION_PARAMETERS_", l_val=do_tip_scan)
97 IF (do_tip_scan) THEN
98 iounit = cp_logger_get_default_io_unit(logger)
99 cname = logger%iter_info%project_name
100 logger%iter_info%project_name = logger%iter_info%project_name//"+TIP_SCAN"
101 plevel = logger%iter_info%print_level
102 logger%iter_info%print_level = silent_print_level
103
104 IF (iounit > 0) THEN
105 WRITE (iounit, "(T2,A)") "TIP SCAN| Perform a Tip Scanning Calculation"
106 END IF
107
108 ! read the input section
109 CALL read_scanning_section(scan_env, input_section)
110 ! read tip potential file
111 CALL read_tip_file(qs_env, scan_env)
112
113 CALL get_qs_env(qs_env, ks_env=ks_env, pw_env=pw_env, &
114 dft_control=dft_control)
115 expot = dft_control%apply_external_potential
116 dft_control%apply_external_potential = .true.
117 IF (expot) THEN
118 ! save external potential
119 CALL get_qs_env(qs_env, vee=vee)
120 END IF
121
122 ! scratch memory for tip potentials and structure factor
123 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
124 NULLIFY (vtip)
125 ALLOCATE (vtip)
126 CALL auxbas_pw_pool%create_pw(vtip)
127 CALL pw_zero(vtip)
128 CALL auxbas_pw_pool%create_pw(vref)
129 CALL pw_zero(vref)
130 CALL auxbas_pw_pool%create_pw(sf)
131
132 ! get the reference tip potential and store it in reciprocal space (vref)
133 CALL pw_transfer(scan_env%tip_pw_g, vref)
134
135 ! store reference MOs
136 CALL get_qs_env(qs_env, mos=mos)
137 nset = SIZE(mos)
138 ALLOCATE (mos_ref(nset))
139 DO iset = 1, nset
140 CALL duplicate_mo_set(mos_ref(iset), mos(iset))
141 END DO
142
143 nscan = scan_env%num_scan_points
144 IF (iounit > 0) THEN
145 WRITE (iounit, "(T2,A,T74,I7)") "TIP SCAN| Number of scanning points ", nscan
146 WRITE (iounit, "(T2,A)") "TIP SCAN| Start scanning ..."
147 END IF
148
149 DO iscan = 1, nscan
150 IF (iounit > 0) THEN
151 WRITE (iounit, "(T2,A,I7)", advance="NO") "TIP SCAN| Scan point ", iscan
152 END IF
153
154 ! shift the reference tip potential
155 rpos(1:3) = scan_env%tip_pos(1:3, iscan) - scan_env%ref_point(1:3)
156 CALL shift_tip_potential(vref, sf, vtip, rpos)
157 ! set the external potential
158 IF (ASSOCIATED(vee)) THEN
159 CALL pw_axpy(vee, vtip, alpha=1.0_dp)
160 END IF
161 CALL set_ks_env(ks_env, vee=vtip)
162
163 ! reset MOs
164 CALL get_qs_env(qs_env, mos=mos)
165 DO iset = 1, nset
166 CALL reassign_allocated_mos(mos(iset), mos_ref(iset))
167 END DO
168
169 ! Calculate electronic structure
170 CALL scf(qs_env, has_converged=scf_converged, total_scf_steps=tsteps)
171
172 IF (iounit > 0) THEN
173 IF (scf_converged) THEN
174 WRITE (iounit, "(T25,A,I4,A)") "SCF converged in ", tsteps, " steps"
175 ELSE
176 WRITE (iounit, "(T31,A)") "SCF did not converge!"
177 END IF
178 END IF
179 END DO
180 CALL release_scanning_type(scan_env)
181
182 IF (iounit > 0) THEN
183 WRITE (iounit, "(T2,A)") "TIP SCAN| ... end scanning"
184 END IF
185 dft_control%apply_external_potential = expot
186 IF (expot) THEN
187 ! restore vee
188 CALL set_ks_env(ks_env, vee=vee)
189 ELSE
190 NULLIFY (vee)
191 CALL set_ks_env(ks_env, vee=vee)
192 END IF
193 CALL auxbas_pw_pool%give_back_pw(vtip)
194 CALL auxbas_pw_pool%give_back_pw(vref)
195 CALL auxbas_pw_pool%give_back_pw(sf)
196 DEALLOCATE (vtip)
197
198 logger%iter_info%print_level = plevel
199 logger%iter_info%project_name = cname
200
201 ! reset MOs
202 CALL get_qs_env(qs_env, mos=mos)
203 DO iset = 1, nset
204 CALL reassign_allocated_mos(mos(iset), mos_ref(iset))
205 CALL deallocate_mo_set(mos_ref(iset))
206 END DO
207 DEALLOCATE (mos_ref)
208 END IF
209
210 CALL timestop(handle)
211
212 END SUBROUTINE tip_scanning
213
214! **************************************************************************************************
215!> \brief Shift tip potential in reciprocal space
216!> \param vref ...
217!> \param sf ...
218!> \param vtip ...
219!> \param rpos ...
220!> \par History
221!> * 05.2021 created [JGH]
222! **************************************************************************************************
223 SUBROUTINE shift_tip_potential(vref, sf, vtip, rpos)
224
225 TYPE(pw_c1d_gs_type), INTENT(INOUT) :: vref, sf
226 TYPE(pw_r3d_rs_type), INTENT(INOUT) :: vtip
227 REAL(kind=dp), DIMENSION(3), INTENT(IN) :: rpos
228
229 CHARACTER(LEN=*), PARAMETER :: routinen = 'shift_tip_potential'
230
231 INTEGER :: handle
232
233 CALL timeset(routinen, handle)
234
235 CALL pw_structure_factor(sf, rpos)
236 CALL pw_multiply_with(sf, vref)
237 CALL pw_transfer(sf, vtip)
238
239 CALL timestop(handle)
240
241 END SUBROUTINE shift_tip_potential
242
243! **************************************************************************************************
244!> \brief Read tip potential from cube file. Allow any spacing and cell size
245!> \param qs_env ...
246!> \param scan_env ...
247!> \par History
248!> * 05.2021 created [JGH]
249! **************************************************************************************************
250 SUBROUTINE read_tip_file(qs_env, scan_env)
251 TYPE(qs_environment_type), POINTER :: qs_env
252 TYPE(scanning_type), INTENT(INOUT) :: scan_env
253
254 CHARACTER(LEN=*), PARAMETER :: routinen = 'read_tip_file'
255
256 INTEGER :: extunit, handle, i, nat
257 INTEGER, DIMENSION(3) :: npts
258 REAL(kind=dp) :: scaling
259 REAL(kind=dp), DIMENSION(3) :: rdum
260 REAL(kind=dp), DIMENSION(3, 3) :: dcell
261 TYPE(mp_para_env_type), POINTER :: para_env
262 TYPE(pw_grid_type), POINTER :: pw_grid
263
264 CALL timeset(routinen, handle)
265
266 CALL get_qs_env(qs_env, para_env=para_env)
267
268 IF (para_env%is_source()) THEN
269 CALL open_file(file_name=scan_env%tip_cube_file, &
270 file_status="OLD", &
271 file_form="FORMATTED", &
272 file_action="READ", &
273 unit_number=extunit)
274 !skip header comments
275 DO i = 1, 2
276 READ (extunit, *)
277 END DO
278 READ (extunit, *) nat, rdum
279 DO i = 1, 3
280 READ (extunit, *) npts(i), dcell(i, 1:3)
281 dcell(i, 1:3) = npts(i)*dcell(i, 1:3)
282 END DO
283 CALL close_file(unit_number=extunit)
284 END IF
285
286 CALL para_env%bcast(npts)
287 CALL para_env%bcast(dcell)
288
289 NULLIFY (pw_grid)
290 CALL pw_grid_create(pw_grid, para_env, dcell, npts=npts)
291 CALL scan_env%tip_pw_r%create(pw_grid)
292!deb
293 scaling = 0.1_dp
294!deb
295 CALL cp_cube_to_pw(scan_env%tip_pw_r, scan_env%tip_cube_file, scaling, silent=.true.)
296 CALL scan_env%tip_pw_g%create(pw_grid)
297 CALL pw_transfer(scan_env%tip_pw_r, scan_env%tip_pw_g)
298 CALL pw_grid_release(pw_grid)
299
300 CALL timestop(handle)
301
302 END SUBROUTINE read_tip_file
303
304END 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
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
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:2163
subroutine, public pw_structure_factor(sf, r)
Calculate the structure factor for point r.
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
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_pp, 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, harris_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, eeq, 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_pp, 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 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
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
subroutine, public reassign_allocated_mos(mo_set_new, mo_set_old)
reassign an already allocated mo_set
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:199
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)
...
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...