Line data Source code
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 : ! **************************************************************************************************
9 : !> \brief Defines CDFT control structures
10 : !> \par History
11 : !> separated from cp_control_types [03.2017]
12 : !> \author Nico Holmberg [03.2017]
13 : ! **************************************************************************************************
14 : MODULE qs_cdft_types
15 : USE cp_array_utils, ONLY: cp_1d_r_p_type
16 : USE cp_dbcsr_api, ONLY: dbcsr_p_type
17 : USE cp_fm_types, ONLY: cp_fm_type
18 : USE hirshfeld_types, ONLY: hirshfeld_type,&
19 : release_hirshfeld_type
20 : USE input_constants, ONLY: becke_cutoff_global,&
21 : outer_scf_becke_constraint,&
22 : outer_scf_hirshfeld_constraint,&
23 : outer_scf_none,&
24 : radius_single,&
25 : shape_function_gaussian
26 : USE kinds, ONLY: default_path_length,&
27 : dp
28 : USE outer_scf_control_types, ONLY: outer_scf_control_type,&
29 : qs_outer_scf_type
30 : USE pw_types, ONLY: pw_r3d_rs_type
31 : USE qs_cdft_opt_types, ONLY: cdft_opt_type_release
32 : #include "./base/base_uses.f90"
33 :
34 : IMPLICIT NONE
35 :
36 : PRIVATE
37 :
38 : ! **************************************************************************************************
39 : !> \brief some parameters useful for becke_constraints
40 : !> \param aij pairwise parameters used to adjust the Becke cell boundaries built from atomic radii
41 : !> \param adjust logical which determines if the Becke potential is adjusted with atomic radii
42 : !> \param cavity the Gaussian confinement cavity: the constraint is nonzero outside this cavity
43 : !> \param cavity_confine logical which determines if cavity confinement is active
44 : !> \param cavity_mat a compacted version of cavity
45 : !> \param cavity_shape the confinement cavity shape id
46 : !> \param cavity_env the structure used to build the Gaussian cavity
47 : !> \param confine_bounds grid point indices outside which the constraint vanishes along Z-axis
48 : !> \param cutoff_type the cutoff type to use for building the constraint
49 : !> \param cutoffs element specific cutoffs
50 : !> \param cutoffs_tmp same as cutoffs but a temporary read during parsing of this type
51 : !> \param eps_cavity threshold used screen small values of the Gaussian cavity density
52 : !> \param in_memory logical which determines if the gradients of the Becke potential should be
53 : !> \param print_cavity logical to print the Gaussian confinement cavity
54 : !> \param radii permanent copy of radii_tmp
55 : !> \param radii_tmp temporary list of element specific atomic radii used to adjust the Becke cells
56 : !> \param rcavity an optional global radius parameter used to define the Gaussian confinement cavity
57 : !> \param rglobal global cutoff to use for building the constraint
58 : !> computed simultaneously with the potential instead of separately
59 : !> \param should_skip logical which determines is grid points should be skipped if all constraint
60 : !> atoms are found to reside beyond the cutoff distance from it
61 : !> \param use_bohr decides whether to use angstrom or bohr units for the confinement cavity radius
62 : ! **************************************************************************************************
63 : ! Utility vector container for building becke constraint
64 : TYPE becke_vector_buffer
65 : LOGICAL :: store_vectors = .FALSE.
66 : REAL(kind=dp), ALLOCATABLE, &
67 : DIMENSION(:) :: distances
68 : REAL(kind=dp), ALLOCATABLE, &
69 : DIMENSION(:, :) :: distance_vecs, &
70 : position_vecs, &
71 : R12
72 : REAL(kind=dp), ALLOCATABLE, &
73 : DIMENSION(:, :, :) :: pair_dist_vecs
74 : END TYPE becke_vector_buffer
75 :
76 : TYPE becke_constraint_type
77 : INTEGER :: cavity_shape = -1, cutoff_type = -1, &
78 : confine_bounds(2) = -1
79 : LOGICAL :: in_memory = .FALSE., &
80 : adjust = .FALSE., cavity_confine = .FALSE., &
81 : should_skip = .FALSE., print_cavity = .FALSE., &
82 : use_bohr = .FALSE.
83 : REAL(KIND=dp) :: rglobal = -1.0_dp, &
84 : rcavity = -1.0_dp, eps_cavity = -1.0_dp
85 : REAL(KIND=dp), DIMENSION(:), POINTER :: cutoffs => NULL(), cutoffs_tmp => NULL(), &
86 : radii_tmp => NULL(), radii => NULL()
87 : REAL(KIND=dp), POINTER, &
88 : DIMENSION(:, :) :: aij => NULL()
89 : REAL(KIND=dp), POINTER, &
90 : DIMENSION(:, :, :) :: cavity_mat => NULL()
91 : TYPE(becke_vector_buffer) :: vector_buffer = becke_vector_buffer()
92 : TYPE(hirshfeld_type), POINTER :: cavity_env => NULL()
93 : TYPE(pw_r3d_rs_type) :: cavity = pw_r3d_rs_type()
94 : END TYPE becke_constraint_type
95 :
96 : ! **************************************************************************************************
97 : ! \brief control parameters for Hirshfeld constraints
98 : !> \param gaussian_shape the type of Gaussian to use (shape_function Gaussian)
99 : !> \param radii list of Gaussian radii for different atomic kinds
100 : !> \param radius Gaussian radius parameter
101 : !> \param shape_function the constraint type: atomic density or single Gaussian
102 : !> \param use_bohr determines whether to use angstrom or bohr units for the radii of Gaussians
103 : !> \param use_atomic_cutoff Logical to control use of ATOMIC_CUTOFF
104 : !> \param atomic_cutoff Numerical cutoff for calculation of Hirshfeld densities
105 : !> \param atoms_memory Number of atomic gradients to store in memory
106 : !> \param eps_cutoff Numerical cutoff for calculation of weight function
107 : !> \param print_density Logical to control printing of Hirshfeld densities to .cube file
108 : !> \param hirshfeld_env auxiliary type storing information about the Gaussians
109 : ! **************************************************************************************************
110 : TYPE hirshfeld_constraint_type
111 : INTEGER :: gaussian_shape = -1, shape_function = -1, atoms_memory = -1
112 : LOGICAL :: use_bohr = .FALSE., print_density = .FALSE., use_atomic_cutoff = .FALSE.
113 : REAL(KIND=dp) :: radius = -1.0_dp, eps_cutoff = -1.0_dp, atomic_cutoff = -1.0_dp
114 : REAL(KIND=dp), DIMENSION(:), POINTER :: radii => NULL()
115 : TYPE(hirshfeld_type), POINTER :: hirshfeld_env => NULL()
116 : END TYPE hirshfeld_constraint_type
117 :
118 : ! **************************************************************************************************
119 : !> \brief control parameters for CDFT simulations
120 : !> \param fragment_a_fname filename of cube file holding the total electron density
121 : !> of isolated fragment a
122 : !> \param fragment_b_fname filename of cube file holding the total electron density
123 : !> of isolated fragment b
124 : !> \param fragment_a_spin_fname filename of cube file holding the spin difference density
125 : !> of isolated fragment a
126 : !> \param fragment_b_spin_fname filename of cube file holding the spin difference density
127 : !> of isolated fragment b
128 : !> \param ref_count the ref count
129 : !> \param need_pot logical which determines if the Becke potential needs to be built
130 : !> \param save_pot logical which determines if the Becke potential should be saved until forces
131 : !> have been evaluated
132 : !> \param atomic_charges flag that determines if atomic CDFT charges should be computed
133 : !> \param total_steps counter to keep track of the total number of SCF steps
134 : !> \param type the type of CDFT constraint to use
135 : !> \param precond_freq preconditioner can be used if SCF converged in less than precond_freq steps
136 : !> \param nreused determines how many times the current OT preconditioner has been reused
137 : !> \param max_reuse the same preconditioner can be used a maximum of max_reuse times
138 : !> \param purge_freq determines how large nbad_conv can grow before purging the wfn/constraint history
139 : !> \param nbad_conv a running counter keeping track of the number of CDFT SCF loops when the first
140 : !> CDFT SCF iteration required more than 1 outer SCF loop. Reset when convergence is
141 : !> smooth
142 : !> \param purge_offset purging is only allowed when more than purge_offset steps have passed since
143 : !> last purge
144 : !> \param istep a counter to keep track of how many steps have passed since the last purge
145 : !> \param ienergy a counter tracking the total number of CDFT energy evaluations
146 : !> \param natoms the total number of atoms included in constraint/dummy atom groups
147 : !> \param atoms list of constraint atoms
148 : !> \param need_pot logical which determines if the constraint potential needs to be built
149 : !> \param save_pot logical which determines if the constraint potential should be saved until forces
150 : !> have been evaluated
151 : !> \param do_et logical which determines if a ET coupling calculation was requested
152 : !> \param reuse_precond logical which determines if a preconditioner can be reused
153 : !> \param purge_history logical which determines if the wfn/constraint history can be purged
154 : !> \param should_purge logical which determines if purging should take place after this CDFT SCF loop
155 : !> \param calculate_metric logical which determines if the ET coupling reliability metric is computed
156 : !> \param fragment_density use isolated fragment densities as a reference for the constraint
157 : !> \param fragments_integrated logical to determine if the fragment densities have been integrated
158 : !> \param flip_fragment should the spin difference density of the either fragment be flipped
159 : !> \param transfer_pot logical which determines if constraint should be saved for reuse later
160 : !> \param external_control logical which determines if the constraint has already been built
161 : !> in a mixed_env that holds multiple CDFT states
162 : !> \param first_iteration a flag to mark the first iteration for printing of additional data
163 : !> \param print_weight logical which determines if CDFT weight functions should be saved to a file
164 : !> \param in_memory logical which determines if the gradients of the Becke potential should be
165 : !> \param is_constraint list of logicals which determines if an atom is included in a constraint group
166 : !> \param strength Lagrangian multipliers of the constraints
167 : !> \param target target values of the constraints
168 : !> \param value integrated values of the constraints
169 : !> \param charges_fragment atomic partial charges computed from the isolated fragment densities
170 : !> \param becke_control control parameters for Becke constraints
171 : !> \param group container for atom groups each defining their own constraint
172 : !> \param occupations occupation numbers in case non-uniform MO occupation (for do_et)
173 : !> \param mo_coeff save the MO coeffs (for do_et)
174 : !> \param matrix_s save the overlap matrix (for do_et)
175 : !> \param wmat matrix representation of the weight function (for do_et)
176 : !> \param matrix_p save the density matrix (for calculate_metric)
177 : !> \param hirshfeld_control control parameters for Hirshfeld constraints
178 : !> \param constraint_control the outer_scf_control_type for the CDFT constraints
179 : !> \param ot_control the outer_scf_control_type for OT where data is stashed when outside the OT
180 : !> outer loop
181 : !> \param charge atomic CDFT real space potentials needed to calculate CDFT charges
182 : !> \param fragments container for isolated fragment densities read from cube files
183 : !> \param constraint holds information about the CDFT SCF loop
184 : ! **************************************************************************************************
185 : ! To build multiple constraints
186 : TYPE cdft_group_type
187 : ! Atoms of this constraint group
188 : INTEGER, POINTER, DIMENSION(:) :: atoms => NULL()
189 : ! Constraint type: charge constraint, magnetization density constraint, or spin channel specific constraint
190 : INTEGER :: constraint_type = -1
191 : ! Is the constraint fragment based
192 : LOGICAL :: is_fragment_constraint = .FALSE.
193 : ! Temporary array holding a component of the weight function gradient that only includes
194 : ! terms defined on constraint atoms
195 : REAL(kind=dp), ALLOCATABLE, &
196 : DIMENSION(:, :) :: d_sum_const_dR
197 : ! Coefficients that determine how to sum up the atoms to form the constraint
198 : REAL(KIND=dp), POINTER, DIMENSION(:) :: coeff => NULL()
199 : ! Result of integration dw/dR * rho_r dr where dw/dR is the weight function gradient
200 : REAL(KIND=dp), POINTER, &
201 : DIMENSION(:, :) :: integrated => NULL()
202 : ! Atomic gradients of the weight function at every grid point
203 : REAL(KIND=dp), POINTER, &
204 : DIMENSION(:, :, :, :) :: gradients => NULL()
205 : REAL(KIND=dp), POINTER, &
206 : DIMENSION(:, :, :, :) :: gradients_x => NULL()
207 : REAL(KIND=dp), POINTER, &
208 : DIMENSION(:, :, :, :) :: gradients_y => NULL()
209 : REAL(KIND=dp), POINTER, &
210 : DIMENSION(:, :, :, :) :: gradients_z => NULL()
211 : ! The weight function of this constraint group
212 : TYPE(pw_r3d_rs_type), POINTER :: weight => NULL()
213 : TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: hw_rho_atomic => NULL()
214 : TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: hw_rho_atomic_dr => NULL()
215 : TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: hw_rho_atomic_charge => NULL()
216 : TYPE(pw_r3d_rs_type) :: hw_rho_total_constraint = pw_r3d_rs_type()
217 : END TYPE cdft_group_type
218 :
219 : TYPE cdft_control_type
220 : CHARACTER(LEN=default_path_length) :: fragment_a_fname = "", &
221 : fragment_b_fname = "", &
222 : fragment_a_spin_fname = "", &
223 : fragment_b_spin_fname = ""
224 : INTEGER :: ref_count = -1, total_steps = -1, TYPE = -1, &
225 : precond_freq = -1, nreused = -1, max_reuse = -1, &
226 : purge_freq = -1, nbad_conv = -1, purge_offset = -1, &
227 : istep = -1, ienergy = -1, natoms = -1
228 : INTEGER, POINTER, DIMENSION(:) :: atoms => NULL()
229 : LOGICAL :: need_pot = .FALSE., save_pot = .FALSE., do_et = .FALSE., &
230 : reuse_precond = .FALSE., purge_history = .FALSE., &
231 : should_purge = .FALSE., calculate_metric = .FALSE., &
232 : atomic_charges = .FALSE., fragment_density = .FALSE., &
233 : fragments_integrated = .FALSE., flip_fragment(2) = .FALSE., &
234 : transfer_pot = .FALSE., external_control = .FALSE., &
235 : first_iteration = .FALSE., print_weight = .FALSE., in_memory = .FALSE.
236 : LOGICAL, POINTER, DIMENSION(:) :: is_constraint => NULL()
237 : REAL(KIND=dp), DIMENSION(:), POINTER :: strength => NULL(), TARGET => NULL(), value => NULL()
238 : REAL(KIND=dp), POINTER, &
239 : DIMENSION(:, :) :: charges_fragment => NULL()
240 : TYPE(becke_constraint_type), POINTER :: becke_control => NULL()
241 : TYPE(cdft_group_type), POINTER, &
242 : DIMENSION(:) :: group => NULL()
243 : TYPE(cp_1d_r_p_type), ALLOCATABLE, &
244 : DIMENSION(:) :: occupations
245 : TYPE(cp_fm_type), DIMENSION(:), &
246 : POINTER :: mo_coeff => NULL()
247 : TYPE(dbcsr_p_type) :: matrix_s
248 : TYPE(dbcsr_p_type), DIMENSION(:), &
249 : POINTER :: wmat => NULL(), matrix_p => NULL()
250 : TYPE(hirshfeld_constraint_type), &
251 : POINTER :: hirshfeld_control => NULL()
252 : TYPE(outer_scf_control_type) :: constraint_control = outer_scf_control_type(), ot_control = outer_scf_control_type()
253 : TYPE(pw_r3d_rs_type), POINTER, &
254 : DIMENSION(:) :: charge => NULL()
255 : TYPE(pw_r3d_rs_type), POINTER, &
256 : DIMENSION(:, :) :: fragments => NULL()
257 : TYPE(qs_outer_scf_type) :: constraint = qs_outer_scf_type()
258 : TYPE(pw_r3d_rs_type) :: hw_rho_total = pw_r3d_rs_type()
259 : END TYPE cdft_control_type
260 :
261 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_cdft_types'
262 :
263 : ! Public data types
264 :
265 : PUBLIC :: becke_constraint_type, &
266 : cdft_control_type, &
267 : cdft_group_type, &
268 : hirshfeld_constraint_type
269 :
270 : ! Public subroutines
271 :
272 : PUBLIC :: cdft_control_create, &
273 : cdft_control_release
274 :
275 : CONTAINS
276 :
277 : ! **************************************************************************************************
278 : !> \brief create the becke_constraint_type
279 : !> \param becke_control the structure to create
280 : !> \par History
281 : !> 02.2007 created [Florian Schiffmann]
282 : ! **************************************************************************************************
283 26832 : SUBROUTINE becke_control_create(becke_control)
284 : TYPE(becke_constraint_type), INTENT(OUT) :: becke_control
285 :
286 : becke_control%adjust = .FALSE.
287 6708 : becke_control%cutoff_type = becke_cutoff_global
288 : becke_control%cavity_confine = .FALSE.
289 : becke_control%should_skip = .FALSE.
290 : becke_control%print_cavity = .FALSE.
291 : becke_control%in_memory = .FALSE.
292 : becke_control%use_bohr = .FALSE.
293 20124 : becke_control%confine_bounds = 0
294 6708 : becke_control%rcavity = 3.0_dp
295 6708 : becke_control%rglobal = 6.0_dp
296 6708 : becke_control%eps_cavity = 1.0e-6_dp
297 6708 : becke_control%cavity_shape = radius_single
298 6708 : becke_control%vector_buffer%store_vectors = .TRUE.
299 6708 : NULLIFY (becke_control%aij)
300 6708 : NULLIFY (becke_control%cavity_mat)
301 6708 : NULLIFY (becke_control%cavity_env)
302 6708 : NULLIFY (becke_control%cutoffs)
303 6708 : NULLIFY (becke_control%cutoffs_tmp)
304 6708 : NULLIFY (becke_control%radii)
305 6708 : NULLIFY (becke_control%radii_tmp)
306 6708 : END SUBROUTINE becke_control_create
307 :
308 : ! **************************************************************************************************
309 : !> \brief release the becke_constraint_type
310 : !> \param becke_control the structure to release
311 : !> \par History
312 : !> 02.2007 created [Florian Schiffmann]
313 : ! **************************************************************************************************
314 6708 : SUBROUTINE becke_control_release(becke_control)
315 : TYPE(becke_constraint_type), INTENT(INOUT) :: becke_control
316 :
317 6708 : IF (becke_control%vector_buffer%store_vectors) THEN
318 6708 : IF (ALLOCATED(becke_control%vector_buffer%distances)) &
319 0 : DEALLOCATE (becke_control%vector_buffer%distances)
320 6708 : IF (ALLOCATED(becke_control%vector_buffer%distance_vecs)) &
321 0 : DEALLOCATE (becke_control%vector_buffer%distance_vecs)
322 6708 : IF (ALLOCATED(becke_control%vector_buffer%position_vecs)) &
323 0 : DEALLOCATE (becke_control%vector_buffer%position_vecs)
324 6708 : IF (ALLOCATED(becke_control%vector_buffer%R12)) &
325 0 : DEALLOCATE (becke_control%vector_buffer%R12)
326 6708 : IF (ALLOCATED(becke_control%vector_buffer%pair_dist_vecs)) &
327 0 : DEALLOCATE (becke_control%vector_buffer%pair_dist_vecs)
328 : END IF
329 6708 : IF (ASSOCIATED(becke_control%cutoffs)) &
330 172 : DEALLOCATE (becke_control%cutoffs)
331 6708 : IF (ASSOCIATED(becke_control%cutoffs_tmp)) &
332 18 : DEALLOCATE (becke_control%cutoffs_tmp)
333 6708 : IF (ASSOCIATED(becke_control%radii_tmp)) &
334 18 : DEALLOCATE (becke_control%radii_tmp)
335 6708 : IF (ASSOCIATED(becke_control%radii)) &
336 112 : DEALLOCATE (becke_control%radii)
337 6708 : IF (ASSOCIATED(becke_control%aij)) &
338 112 : DEALLOCATE (becke_control%aij)
339 6708 : IF (ASSOCIATED(becke_control%cavity_mat)) &
340 0 : DEALLOCATE (becke_control%cavity_mat)
341 6708 : IF (becke_control%cavity_confine) &
342 244 : CALL release_hirshfeld_type(becke_control%cavity_env)
343 :
344 6708 : END SUBROUTINE becke_control_release
345 :
346 : ! **************************************************************************************************
347 : !> \brief create the cdft_control_type
348 : !> \param cdft_control the structure to create
349 : !> \par History
350 : !> 12.2015 created [Nico Holmberg]
351 : ! **************************************************************************************************
352 20124 : SUBROUTINE cdft_control_create(cdft_control)
353 : TYPE(cdft_control_type), INTENT(OUT) :: cdft_control
354 :
355 6708 : cdft_control%total_steps = 0
356 : NULLIFY (cdft_control%strength)
357 : NULLIFY (cdft_control%target)
358 : NULLIFY (cdft_control%value)
359 : NULLIFY (cdft_control%atoms)
360 : NULLIFY (cdft_control%is_constraint)
361 : NULLIFY (cdft_control%charges_fragment)
362 : NULLIFY (cdft_control%fragments)
363 : NULLIFY (cdft_control%group)
364 : NULLIFY (cdft_control%charge)
365 6708 : cdft_control%natoms = 0
366 6708 : cdft_control%type = outer_scf_none
367 6708 : cdft_control%need_pot = .TRUE.
368 : cdft_control%save_pot = .FALSE.
369 : cdft_control%transfer_pot = .FALSE.
370 : cdft_control%atomic_charges = .FALSE.
371 6708 : cdft_control%first_iteration = .TRUE.
372 : cdft_control%fragment_density = .FALSE.
373 : cdft_control%fragments_integrated = .FALSE.
374 20124 : cdft_control%flip_fragment = .FALSE.
375 6708 : cdft_control%external_control = .FALSE.
376 : cdft_control%do_et = .FALSE.
377 : cdft_control%reuse_precond = .FALSE.
378 6708 : cdft_control%nreused = 0
379 6708 : cdft_control%precond_freq = 0
380 6708 : cdft_control%max_reuse = 0
381 : cdft_control%should_purge = .FALSE.
382 : cdft_control%purge_history = .FALSE.
383 : cdft_control%calculate_metric = .FALSE.
384 6708 : cdft_control%in_memory = .FALSE.
385 6708 : cdft_control%purge_freq = 0
386 6708 : cdft_control%nbad_conv = 0
387 6708 : cdft_control%purge_offset = 0
388 6708 : cdft_control%istep = 0
389 6708 : cdft_control%ienergy = 0
390 : NULLIFY (cdft_control%becke_control)
391 26832 : ALLOCATE (cdft_control%becke_control)
392 6708 : CALL becke_control_create(cdft_control%becke_control)
393 : NULLIFY (cdft_control%hirshfeld_control)
394 6708 : ALLOCATE (cdft_control%hirshfeld_control)
395 6708 : CALL hirshfeld_control_create(cdft_control%hirshfeld_control)
396 6708 : NULLIFY (cdft_control%wmat)
397 6708 : NULLIFY (cdft_control%matrix_s%matrix)
398 6708 : NULLIFY (cdft_control%mo_coeff)
399 6708 : NULLIFY (cdft_control%matrix_p)
400 : ! Outer SCF default settings
401 6708 : cdft_control%ot_control%have_scf = .FALSE.
402 6708 : cdft_control%ot_control%max_scf = 0
403 6708 : cdft_control%ot_control%eps_scf = 0.0_dp
404 6708 : cdft_control%ot_control%step_size = 0.0_dp
405 6708 : cdft_control%ot_control%type = -1
406 6708 : cdft_control%ot_control%optimizer = -1
407 6708 : cdft_control%ot_control%diis_buffer_length = -1
408 6708 : NULLIFY (cdft_control%ot_control%cdft_opt_control)
409 6708 : cdft_control%constraint_control%have_scf = .FALSE.
410 6708 : cdft_control%constraint_control%max_scf = 0
411 6708 : cdft_control%constraint_control%eps_scf = 0.0_dp
412 6708 : cdft_control%constraint_control%step_size = 0.0_dp
413 6708 : cdft_control%constraint_control%type = -1
414 6708 : cdft_control%constraint_control%optimizer = -1
415 6708 : cdft_control%constraint_control%diis_buffer_length = -1
416 6708 : NULLIFY (cdft_control%constraint_control%cdft_opt_control)
417 6708 : cdft_control%constraint%iter_count = 0
418 6708 : NULLIFY (cdft_control%constraint%variables)
419 6708 : NULLIFY (cdft_control%constraint%gradient)
420 6708 : NULLIFY (cdft_control%constraint%energy)
421 6708 : NULLIFY (cdft_control%constraint%count)
422 6708 : NULLIFY (cdft_control%constraint%inv_jacobian)
423 6708 : cdft_control%constraint%deallocate_jacobian = .TRUE.
424 6708 : END SUBROUTINE cdft_control_create
425 :
426 : ! **************************************************************************************************
427 : !> \brief release the cdft_control_type
428 : !> \param cdft_control the structure to release
429 : !> \par History
430 : !> 12.2015 created [Nico Holmberg]
431 : ! **************************************************************************************************
432 6708 : SUBROUTINE cdft_control_release(cdft_control)
433 : TYPE(cdft_control_type), INTENT(INOUT) :: cdft_control
434 :
435 : INTEGER :: i
436 :
437 : ! Constraint settings
438 6708 : IF (ASSOCIATED(cdft_control%atoms)) &
439 216 : DEALLOCATE (cdft_control%atoms)
440 6708 : IF (ASSOCIATED(cdft_control%strength)) &
441 264 : DEALLOCATE (cdft_control%strength)
442 6708 : IF (ASSOCIATED(cdft_control%target)) &
443 264 : DEALLOCATE (cdft_control%target)
444 6708 : IF (ASSOCIATED(cdft_control%value)) &
445 264 : DEALLOCATE (cdft_control%value)
446 6708 : IF (ASSOCIATED(cdft_control%charges_fragment)) &
447 0 : DEALLOCATE (cdft_control%charges_fragment)
448 6708 : IF (ASSOCIATED(cdft_control%fragments)) &
449 0 : DEALLOCATE (cdft_control%fragments)
450 6708 : IF (ASSOCIATED(cdft_control%is_constraint)) &
451 264 : DEALLOCATE (cdft_control%is_constraint)
452 6708 : IF (ASSOCIATED(cdft_control%charge)) &
453 16 : DEALLOCATE (cdft_control%charge)
454 : ! Constraint atom groups
455 6708 : IF (ASSOCIATED(cdft_control%group)) THEN
456 594 : DO i = 1, SIZE(cdft_control%group)
457 308 : IF (ASSOCIATED(cdft_control%group(i)%atoms)) &
458 214 : DEALLOCATE (cdft_control%group(i)%atoms)
459 308 : IF (ASSOCIATED(cdft_control%group(i)%coeff)) &
460 214 : DEALLOCATE (cdft_control%group(i)%coeff)
461 308 : IF (ALLOCATED(cdft_control%group(i)%d_sum_const_dR)) &
462 0 : DEALLOCATE (cdft_control%group(i)%d_sum_const_dR)
463 308 : IF (cdft_control%type == outer_scf_becke_constraint) THEN
464 258 : IF (ASSOCIATED(cdft_control%group(i)%gradients)) &
465 0 : DEALLOCATE (cdft_control%group(i)%gradients)
466 50 : ELSE IF (cdft_control%type == outer_scf_hirshfeld_constraint) THEN
467 28 : IF (ASSOCIATED(cdft_control%group(i)%gradients_x)) &
468 0 : DEALLOCATE (cdft_control%group(i)%gradients_x)
469 28 : IF (ASSOCIATED(cdft_control%group(i)%gradients_y)) &
470 0 : DEALLOCATE (cdft_control%group(i)%gradients_y)
471 28 : IF (ASSOCIATED(cdft_control%group(i)%gradients_z)) &
472 0 : DEALLOCATE (cdft_control%group(i)%gradients_z)
473 : END IF
474 308 : IF (ASSOCIATED(cdft_control%group(i)%integrated)) &
475 286 : DEALLOCATE (cdft_control%group(i)%integrated)
476 : END DO
477 286 : DEALLOCATE (cdft_control%group)
478 : END IF
479 : ! Constraint type specific deallocations
480 6708 : IF (ASSOCIATED(cdft_control%becke_control)) THEN
481 6708 : CALL becke_control_release(cdft_control%becke_control)
482 6708 : DEALLOCATE (cdft_control%becke_control)
483 : END IF
484 6708 : IF (ASSOCIATED(cdft_control%hirshfeld_control)) THEN
485 6708 : CALL hirshfeld_control_release(cdft_control%hirshfeld_control)
486 6708 : DEALLOCATE (cdft_control%hirshfeld_control)
487 : END IF
488 : ! Release OUTER_SCF types
489 6708 : CALL cdft_opt_type_release(cdft_control%ot_control%cdft_opt_control)
490 6708 : CALL cdft_opt_type_release(cdft_control%constraint_control%cdft_opt_control)
491 6708 : IF (ASSOCIATED(cdft_control%constraint%variables)) &
492 0 : DEALLOCATE (cdft_control%constraint%variables)
493 6708 : IF (ASSOCIATED(cdft_control%constraint%count)) &
494 0 : DEALLOCATE (cdft_control%constraint%count)
495 6708 : IF (ASSOCIATED(cdft_control%constraint%gradient)) &
496 0 : DEALLOCATE (cdft_control%constraint%gradient)
497 6708 : IF (ASSOCIATED(cdft_control%constraint%energy)) &
498 0 : DEALLOCATE (cdft_control%constraint%energy)
499 6708 : IF (ASSOCIATED(cdft_control%constraint%inv_jacobian)) &
500 44 : DEALLOCATE (cdft_control%constraint%inv_jacobian)
501 : ! Storage for mixed CDFT calculations
502 6708 : IF (ALLOCATED(cdft_control%occupations)) THEN
503 0 : DO i = 1, SIZE(cdft_control%occupations)
504 0 : IF (ASSOCIATED(cdft_control%occupations(i)%array)) &
505 0 : DEALLOCATE (cdft_control%occupations(i)%array)
506 : END DO
507 0 : DEALLOCATE (cdft_control%occupations)
508 : END IF
509 : ! Release control
510 6708 : cdft_control%type = outer_scf_none
511 :
512 6708 : END SUBROUTINE cdft_control_release
513 :
514 : ! **************************************************************************************************
515 : !> \brief create the hirshfeld_constraint_type
516 : !> \param hirshfeld_control the structure to create
517 : !> \par History
518 : !> 09.2018 created [Nico Holmberg]
519 : ! **************************************************************************************************
520 6708 : SUBROUTINE hirshfeld_control_create(hirshfeld_control)
521 : TYPE(hirshfeld_constraint_type), INTENT(OUT) :: hirshfeld_control
522 :
523 : hirshfeld_control%use_bohr = .FALSE.
524 : hirshfeld_control%print_density = .FALSE.
525 6708 : hirshfeld_control%use_atomic_cutoff = .TRUE.
526 6708 : hirshfeld_control%radius = 3.0_dp
527 6708 : hirshfeld_control%eps_cutoff = 1.0e-12_dp
528 6708 : hirshfeld_control%atomic_cutoff = 1.0e-12_dp
529 6708 : hirshfeld_control%shape_function = shape_function_gaussian
530 6708 : hirshfeld_control%atoms_memory = 80
531 6708 : hirshfeld_control%gaussian_shape = radius_single
532 : NULLIFY (hirshfeld_control%hirshfeld_env)
533 : NULLIFY (hirshfeld_control%radii)
534 :
535 6708 : END SUBROUTINE hirshfeld_control_create
536 :
537 : ! **************************************************************************************************
538 : !> \brief release the hirshfeld_constraint_type
539 : !> \param hirshfeld_control the structure to release
540 : !> \par History
541 : !> 09.2018 created [Nico Holmberg]
542 : ! **************************************************************************************************
543 6708 : SUBROUTINE hirshfeld_control_release(hirshfeld_control)
544 : TYPE(hirshfeld_constraint_type), INTENT(INOUT) :: hirshfeld_control
545 :
546 6708 : IF (ASSOCIATED(hirshfeld_control%radii)) &
547 0 : DEALLOCATE (hirshfeld_control%radii)
548 6708 : CALL release_hirshfeld_type(hirshfeld_control%hirshfeld_env)
549 :
550 6708 : END SUBROUTINE hirshfeld_control_release
551 :
552 0 : END MODULE qs_cdft_types
|