(git:ccc2433)
embed_types.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 
8 MODULE embed_types
11  atomic_kind_list_type
12  USE atomic_kind_types, ONLY: atomic_kind_type
13  USE cell_types, ONLY: cell_release,&
14  cell_retain,&
15  cell_type
16  USE cp_fm_types, ONLY: cp_fm_type
17  USE cp_log_handling, ONLY: cp_logger_p_type,&
19  USE cp_result_types, ONLY: cp_result_type
20  USE cp_subsys_types, ONLY: cp_subsys_get,&
23  cp_subsys_type
24  USE distribution_1d_types, ONLY: distribution_1d_type
27  section_vals_type
28  USE kinds, ONLY: dp
29  USE lri_environment_types, ONLY: lri_kind_type
30  USE message_passing, ONLY: mp_para_env_p_type,&
32  mp_para_env_type
35  molecule_kind_list_type
36  USE molecule_kind_types, ONLY: molecule_kind_type
39  molecule_list_type
40  USE molecule_types, ONLY: molecule_type
43  particle_list_type
44  USE particle_types, ONLY: particle_type
45  USE pw_types, ONLY: pw_r3d_rs_type
46 #include "./base/base_uses.f90"
47 
48  IMPLICIT NONE
49  PRIVATE
50  PUBLIC :: opt_embed_pot_type, opt_dmfet_pot_type, embed_env_type
51 
52 ! *** Public subroutines ***
53 
54  PUBLIC :: get_embed_env, &
55  set_embed_env, &
58 
59  LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
60  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'embed_types'
61 
62 ! **************************************************************************************************
63 !> \brief Type containing main data for embedding potential optimization
64 !> \author Vladimir Rybkin
65 ! **************************************************************************************************
66 
67  TYPE opt_embed_pot_type
68  TYPE(cp_fm_type), POINTER :: embed_pot_coef => null(), embed_pot_grad => null(), &
69  prev_step => null(), step => null(), embed_pot_hess => null(), &
70  prev_embed_pot_coef => null(), prev_embed_pot_grad => null(), &
71  prev_embed_pot_hess => null(), kinetic_mat => null()
72  REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: w_func, max_diff, int_diff, int_diff_square, &
73  max_grid_step, max_subsys_dens_diff
74  INTEGER :: n_iter = -1, i_iter = -1, dimen_aux = -1, &
75  last_accepted = -1, dimen_var_aux = -1
76  REAL(KIND=dp) :: lambda = 0.0_dp, allowed_decrease = 0.0_dp, &
77  max_trad = 0.0_dp, min_trad = 0.0_dp, &
78  grad_norm = 0.0_dp, vw_cutoff = 0.0_dp, &
79  vw_smooth_cutoff_range = 0.0_dp, eta = 0.0_dp
80  TYPE(pw_r3d_rs_type), POINTER :: const_pot => null(), prev_embed_pot => null(), &
81  prev_spin_embed_pot => null(), pot_diff => null()
82  TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: prev_grid_grad => null(), prev_grid_pot => null(), &
83  prev_subsys_dens => null(), v_w => null()
84  REAL(KIND=dp) :: reg_term = 0.0_dp, trust_rad = 0.0_dp, &
85  conv_max = 0.0_dp, conv_int = 0.0_dp, &
86  conv_max_spin = 0.0_dp, conv_int_spin = 0.0_dp, step_len = 0.0_dp
87  LOGICAL :: accept_step = .false., newton_step = .false., &
88  level_shift = .false., steep_desc = .false., &
89  add_const_pot = .false., converged = .false., read_embed_pot = .false., &
90  read_embed_pot_cube = .false., change_spin = .false., &
91  open_shell_embed = .false., &
92  grid_opt = .false., leeuwen = .false., fab = .false., &
93  coulomb_guess = .false., fermi_amaldi = .false., &
94  diff_guess = .false.
95  INTEGER, ALLOCATABLE, DIMENSION(:) :: all_nspins
96  TYPE(lri_kind_type), DIMENSION(:), POINTER :: lri => null() ! Needed to store integrals
97 
98  END TYPE opt_embed_pot_type
99 
100 ! **************************************************************************************************
101 !> \brief Type containing main data for matrix embedding potential optimization
102 !> \author Vladimir Rybkin
103 ! **************************************************************************************************
104 
105  TYPE opt_dmfet_pot_type
106  TYPE(cp_fm_type), POINTER :: dmfet_pot => null(), dm_1 => null(), dm_2 => null(), &
107  dm_total => null(), dm_diff => null(), &
108  dmfet_pot_beta => null(), dm_total_beta => null(), &
109  dm_diff_beta => null(), dm_subsys => null(), dm_subsys_beta => null()
110  REAL(KIND=dp) :: trust_rad = 0.0_dp, conv_max = 0.0_dp, &
111  conv_int = 0.0_dp, conv_max_beta = 0.0_dp, &
112  conv_int_beta = 0.0_dp
113  LOGICAL :: accept_step = .false., converged = .false., &
114  read_dmfet_pot = .false., &
115  change_spin = .false., open_shell_embed = .false.
116  REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: w_func, max_diff, int_diff
117  INTEGER :: n_iter = -1, i_iter = -1, last_accepted = -1
118  INTEGER, ALLOCATABLE, DIMENSION(:) :: all_nspins
119 
120  END TYPE opt_dmfet_pot_type
121 
122 ! **************************************************************************************************
123 !> \brief Embedding environment type
124 !> \author Vladimir Rybkin
125 ! **************************************************************************************************
126 
127  TYPE embed_env_type
128  TYPE(cell_type), POINTER :: cell_ref => null()
129  TYPE(mp_para_env_type), POINTER :: para_env => null()
130  TYPE(cp_subsys_type), POINTER :: subsys => null()
131  TYPE(section_vals_type), POINTER :: input => null()
132  REAL(KIND=dp), DIMENSION(:), POINTER :: energies => null()
133  ! Parallelization of multiple force_eval
134  INTEGER :: ngroups = -1
135  INTEGER, DIMENSION(:), POINTER :: group_distribution => null()
136  TYPE(mp_para_env_p_type), DIMENSION(:), POINTER :: sub_para_env => null()
137  TYPE(cp_logger_p_type), DIMENSION(:), POINTER :: sub_logger => null()
138  ! Densities from sunbsystem
139  REAL(KIND=dp) :: pot_energy = 0.0_dp
140  END TYPE embed_env_type
141 
142 CONTAINS
143 
144 ! **************************************************************************************************
145 !> \brief Get the embed environment.
146 !> \param embed_env ...
147 !> \param atomic_kind_set ...
148 !> \param particle_set ...
149 !> \param local_particles ...
150 !> \param local_molecules ...
151 !> \param molecule_kind_set ...
152 !> \param molecule_set ...
153 !> \param cell ...
154 !> \param cell_ref ...
155 !> \param para_env ...
156 !> \param sub_para_env ...
157 !> \param subsys ...
158 !> \param input ...
159 !> \param results ...
160 !> \param pot_energy ...
161 ! **************************************************************************************************
162  SUBROUTINE get_embed_env(embed_env, atomic_kind_set, particle_set, &
163  local_particles, local_molecules, molecule_kind_set, &
164  molecule_set, cell, cell_ref, &
165  para_env, sub_para_env, subsys, &
166  input, results, pot_energy)
167 
168  TYPE(embed_env_type), INTENT(IN) :: embed_env
169  TYPE(atomic_kind_type), OPTIONAL, POINTER :: atomic_kind_set(:)
170  TYPE(particle_type), OPTIONAL, POINTER :: particle_set(:)
171  TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles, local_molecules
172  TYPE(molecule_kind_type), OPTIONAL, POINTER :: molecule_kind_set(:)
173  TYPE(molecule_type), OPTIONAL, POINTER :: molecule_set(:)
174  TYPE(cell_type), OPTIONAL, POINTER :: cell, cell_ref
175  TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
176  TYPE(mp_para_env_p_type), DIMENSION(:), OPTIONAL, &
177  POINTER :: sub_para_env
178  TYPE(cp_subsys_type), OPTIONAL, POINTER :: subsys
179  TYPE(section_vals_type), OPTIONAL, POINTER :: input
180  TYPE(cp_result_type), OPTIONAL, POINTER :: results
181  REAL(kind=dp), OPTIONAL :: pot_energy
182 
183  TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
184  TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
185  TYPE(molecule_list_type), POINTER :: molecules
186  TYPE(particle_list_type), POINTER :: particles
187 
188  NULLIFY (atomic_kinds, particles, molecules, molecule_kinds)
189  cpassert(ASSOCIATED(embed_env%subsys))
190 
191  IF (PRESENT(input)) input => embed_env%input
192  IF (PRESENT(cell_ref)) cell_ref => embed_env%cell_ref
193  IF (PRESENT(para_env)) para_env => embed_env%para_env
194  IF (PRESENT(sub_para_env)) sub_para_env => embed_env%sub_para_env
195  IF (PRESENT(subsys)) subsys => embed_env%subsys
196  CALL cp_subsys_get(embed_env%subsys, &
197  atomic_kinds=atomic_kinds, &
198  local_molecules=local_molecules, &
199  local_particles=local_particles, &
200  particles=particles, &
201  molecule_kinds=molecule_kinds, &
202  molecules=molecules, &
203  results=results, &
204  cell=cell)
205  IF (PRESENT(atomic_kind_set)) atomic_kind_set => atomic_kinds%els
206  IF (PRESENT(particle_set)) particle_set => particles%els
207  IF (PRESENT(molecule_kind_set)) molecule_kind_set => molecule_kinds%els
208  IF (PRESENT(molecule_set)) molecule_set => molecules%els
209  IF (PRESENT(pot_energy)) pot_energy = embed_env%pot_energy
210 
211  END SUBROUTINE get_embed_env
212 
213 ! **************************************************************************************************
214 !> \brief ...
215 !> \param embed_env ...
216 !> \param atomic_kind_set ...
217 !> \param particle_set ...
218 !> \param local_particles ...
219 !> \param local_molecules ...
220 !> \param molecule_kind_set ...
221 !> \param molecule_set ...
222 !> \param cell_ref ...
223 !> \param subsys ...
224 !> \param input ...
225 !> \param sub_para_env ...
226 ! **************************************************************************************************
227  SUBROUTINE set_embed_env(embed_env, atomic_kind_set, particle_set, &
228  local_particles, local_molecules, molecule_kind_set, &
229  molecule_set, cell_ref, subsys, &
230  input, sub_para_env)
231 
232  TYPE(embed_env_type), INTENT(INOUT) :: embed_env
233  TYPE(atomic_kind_type), OPTIONAL, POINTER :: atomic_kind_set(:)
234  TYPE(particle_type), OPTIONAL, POINTER :: particle_set(:)
235  TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles, local_molecules
236  TYPE(molecule_kind_type), OPTIONAL, POINTER :: molecule_kind_set(:)
237  TYPE(molecule_type), OPTIONAL, POINTER :: molecule_set(:)
238  TYPE(cell_type), OPTIONAL, POINTER :: cell_ref
239  TYPE(cp_subsys_type), OPTIONAL, POINTER :: subsys
240  TYPE(section_vals_type), OPTIONAL, POINTER :: input
241  TYPE(mp_para_env_p_type), DIMENSION(:), OPTIONAL, &
242  POINTER :: sub_para_env
243 
244  TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
245  TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
246  TYPE(molecule_list_type), POINTER :: molecules
247  TYPE(particle_list_type), POINTER :: particles
248 
249  IF (PRESENT(cell_ref)) THEN
250  CALL cell_retain(cell_ref)
251  CALL cell_release(embed_env%cell_ref)
252  embed_env%cell_ref => cell_ref
253  END IF
254  IF (PRESENT(input)) THEN
255  CALL section_vals_retain(input)
256  CALL section_vals_release(embed_env%input)
257  embed_env%input => input
258  END IF
259  IF (PRESENT(subsys)) THEN
260  IF (ASSOCIATED(embed_env%subsys)) THEN
261  IF (.NOT. ASSOCIATED(embed_env%subsys, subsys)) THEN
262  CALL cp_subsys_release(embed_env%subsys)
263  END IF
264  END IF
265  embed_env%subsys => subsys
266  END IF
267  IF (PRESENT(sub_para_env)) THEN
268  embed_env%sub_para_env => sub_para_env
269  END IF
270  IF (PRESENT(atomic_kind_set)) THEN
271  CALL atomic_kind_list_create(atomic_kinds, &
272  els_ptr=atomic_kind_set)
273  CALL cp_subsys_set(embed_env%subsys, &
274  atomic_kinds=atomic_kinds)
275  CALL atomic_kind_list_release(atomic_kinds)
276  END IF
277  IF (PRESENT(particle_set)) THEN
278  CALL particle_list_create(particles, &
279  els_ptr=particle_set)
280  CALL cp_subsys_set(embed_env%subsys, &
281  particles=particles)
282  CALL particle_list_release(particles)
283  END IF
284  IF (PRESENT(local_particles)) THEN
285  CALL cp_subsys_set(embed_env%subsys, &
286  local_particles=local_particles)
287  END IF
288  IF (PRESENT(local_molecules)) THEN
289  CALL cp_subsys_set(embed_env%subsys, &
290  local_molecules=local_molecules)
291  END IF
292  IF (PRESENT(molecule_kind_set)) THEN
293  CALL molecule_kind_list_create(molecule_kinds, els_ptr=molecule_kind_set)
294  CALL cp_subsys_set(embed_env%subsys, molecule_kinds=molecule_kinds)
295  CALL molecule_kind_list_release(molecule_kinds)
296  END IF
297  IF (PRESENT(molecule_set)) THEN
298  CALL molecule_list_create(molecules, els_ptr=molecule_set)
299  CALL cp_subsys_set(embed_env%subsys, molecules=molecules)
300  CALL molecule_list_release(molecules)
301  END IF
302 
303  END SUBROUTINE set_embed_env
304 
305 ! **************************************************************************************************
306 !> \brief ...
307 !> \param embed_env ...
308 !> \param para_env the parallel environment for the qs_env
309 !> \author Vladimir Rybkin 02.2018
310 ! **************************************************************************************************
311  SUBROUTINE embed_env_create(embed_env, para_env)
312  TYPE(embed_env_type), INTENT(OUT) :: embed_env
313  TYPE(mp_para_env_type), INTENT(IN), TARGET :: para_env
314 
315  embed_env%para_env => para_env
316  CALL embed_env%para_env%retain()
317 
318  END SUBROUTINE embed_env_create
319 
320 ! **************************************************************************************************
321 !> \brief ...
322 !> \param embed_env ...
323 !> \author Vladimir Rybkin 02.2018
324 ! **************************************************************************************************
325  SUBROUTINE embed_env_release(embed_env)
326  TYPE(embed_env_type), INTENT(INOUT) :: embed_env
327 
328  INTEGER :: i, ngroups
329 
330  ngroups = embed_env%ngroups
331  DO i = 1, ngroups
332  IF (ASSOCIATED(embed_env%sub_para_env(i)%para_env)) THEN
333  CALL cp_logger_release(embed_env%sub_logger(i)%p)
334  CALL mp_para_env_release(embed_env%sub_para_env(i)%para_env)
335  END IF
336  END DO
337  DEALLOCATE (embed_env%sub_para_env)
338  DEALLOCATE (embed_env%sub_logger)
339  DEALLOCATE (embed_env%energies)
340  CALL cell_release(embed_env%cell_ref)
341  CALL mp_para_env_release(embed_env%para_env)
342  CALL cp_subsys_release(embed_env%subsys)
343  CALL section_vals_release(embed_env%input)
344  IF (ASSOCIATED(embed_env%group_distribution)) THEN
345  DEALLOCATE (embed_env%group_distribution)
346  END IF
347 
348  END SUBROUTINE embed_env_release
349 
350 END MODULE embed_types
351 
represent a simple array based list of the given type
subroutine, public atomic_kind_list_release(list)
releases a list (see doc/ReferenceCounting.html)
subroutine, public atomic_kind_list_create(list, els_ptr, owns_els, n_els)
creates a list
Define the atomic kind types and their sub types.
Handles all functions related to the CELL.
Definition: cell_types.F:15
subroutine, public cell_release(cell)
releases the given cell (see doc/ReferenceCounting.html)
Definition: cell_types.F:559
subroutine, public cell_retain(cell)
retains the given cell (see doc/ReferenceCounting.html)
Definition: cell_types.F:542
represent a full matrix distributed on many processors
Definition: cp_fm_types.F:15
various routines to log and control the output. The idea is that decisions about where to log should ...
subroutine, public cp_logger_release(logger)
releases this logger
set of type/routines to handle the storage of results in force_envs
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_release(subsys)
releases a subsys (see doc/ReferenceCounting.html)
subroutine, public cp_subsys_set(subsys, atomic_kinds, particles, local_particles, molecules, molecule_kinds, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, results, cell)
sets various propreties of the subsys
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell)
returns information about various attributes of the given subsys
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
subroutine, public get_embed_env(embed_env, atomic_kind_set, particle_set, local_particles, local_molecules, molecule_kind_set, molecule_set, cell, cell_ref, para_env, sub_para_env, subsys, input, results, pot_energy)
Get the embed environment.
Definition: embed_types.F:167
subroutine, public embed_env_create(embed_env, para_env)
...
Definition: embed_types.F:312
subroutine, public set_embed_env(embed_env, atomic_kind_set, particle_set, local_particles, local_molecules, molecule_kind_set, molecule_set, cell_ref, subsys, input, sub_para_env)
...
Definition: embed_types.F:231
subroutine, public embed_env_release(embed_env)
...
Definition: embed_types.F:326
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_retain(section_vals)
retains the given section values (see doc/ReferenceCounting.html)
recursive subroutine, public section_vals_release(section_vals)
releases the given object
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
contains the types and subroutines for dealing with the lri_env lri : local resolution of the identit...
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
represent a simple array based list of the given type
subroutine, public molecule_kind_list_create(list, els_ptr, owns_els, n_els)
creates a list
subroutine, public molecule_kind_list_release(list)
releases a list (see doc/ReferenceCounting.html)
Define the molecule kind structure types and the corresponding functionality.
represent a simple array based list of the given type
subroutine, public molecule_list_create(list, els_ptr, owns_els, n_els)
creates a list
subroutine, public molecule_list_release(list)
releases a list (see doc/ReferenceCounting.html)
Define the data structure for the molecule information.
represent a simple array based list of the given type
subroutine, public particle_list_create(list, els_ptr, owns_els, n_els)
creates a list
subroutine, public particle_list_release(list)
releases a list (see doc/ReferenceCounting.html)
Define the data structure for the particle information.