(git:fd7f302)
Loading...
Searching...
No Matches
qs_cdft_utils.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Utility subroutines for CDFT calculations
10!> \par History
11!> separated from et_coupling [03.2017]
12!> \author Nico Holmberg [03.2017]
13! **************************************************************************************************
18 USE bibliography, ONLY: becke1988b,&
21 cite_reference
22 USE cell_types, ONLY: cell_type,&
23 pbc
33 USE grid_api, ONLY: grid_func_ab,&
39 USE input_constants, ONLY: &
48 USE kinds, ONLY: default_path_length,&
49 dp
55 USE pw_env_types, ONLY: pw_env_get,&
57 USE pw_methods, ONLY: pw_zero
65 USE qs_kind_types, ONLY: get_qs_kind,&
73#include "./base/base_uses.f90"
74
75 IMPLICIT NONE
76
77 PRIVATE
78
79 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_cdft_utils'
80 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .false.
81
82! *** Public subroutines ***
84 PUBLIC :: hfun_scale, hirshfeld_constraint_init, cdft_constraint_print, &
86
87CONTAINS
88
89! **************************************************************************************************
90!> \brief Initializes the Becke constraint environment
91!> \param qs_env the qs_env where to build the constraint
92!> \par History
93!> Created 01.2007 [fschiff]
94!> Extended functionality 12/15-12/16 [Nico Holmberg]
95! **************************************************************************************************
96 SUBROUTINE becke_constraint_init(qs_env)
97 TYPE(qs_environment_type), POINTER :: qs_env
98
99 CHARACTER(len=*), PARAMETER :: routinen = 'becke_constraint_init'
100
101 CHARACTER(len=2) :: element_symbol
102 INTEGER :: atom_a, bounds(2), handle, i, iatom, iex, igroup, ikind, ip, ithread, iw, j, &
103 jatom, katom, natom, nkind, npme, nthread, numexp, unit_nr
104 INTEGER, DIMENSION(2, 3) :: bo
105 INTEGER, DIMENSION(:), POINTER :: atom_list, cores, stride
106 LOGICAL :: build, in_memory, mpi_io
107 LOGICAL, ALLOCATABLE, DIMENSION(:) :: is_constraint
108 REAL(kind=dp) :: alpha, chi, coef, eps_cavity, ircov, &
109 jrcov, radius, uij
110 REAL(kind=dp), DIMENSION(3) :: cell_v, dist_vec, r, r1, ra
111 REAL(kind=dp), DIMENSION(:), POINTER :: radii_list
112 REAL(kind=dp), DIMENSION(:, :), POINTER :: pab
113 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
114 TYPE(becke_constraint_type), POINTER :: becke_control
115 TYPE(cdft_control_type), POINTER :: cdft_control
116 TYPE(cdft_group_type), DIMENSION(:), POINTER :: group
117 TYPE(cell_type), POINTER :: cell
118 TYPE(cp_logger_type), POINTER :: logger
119 TYPE(dft_control_type), POINTER :: dft_control
120 TYPE(hirshfeld_type), POINTER :: cavity_env
121 TYPE(mp_para_env_type), POINTER :: para_env
122 TYPE(particle_list_type), POINTER :: particles
123 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
124 TYPE(pw_env_type), POINTER :: pw_env
125 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
126 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
127 TYPE(qs_subsys_type), POINTER :: subsys
128 TYPE(realspace_grid_type), POINTER :: rs_cavity
129 TYPE(section_vals_type), POINTER :: cdft_constraint_section
130
131 NULLIFY (cores, stride, atom_list, cell, para_env, dft_control, &
132 particle_set, logger, cdft_constraint_section, qs_kind_set, &
133 particles, subsys, pab, pw_env, rs_cavity, cavity_env, &
134 auxbas_pw_pool, atomic_kind_set, group, radii_list, cdft_control)
135 logger => cp_get_default_logger()
136 CALL timeset(routinen, handle)
137 CALL get_qs_env(qs_env, &
138 cell=cell, &
139 particle_set=particle_set, &
140 natom=natom, &
141 dft_control=dft_control, &
142 para_env=para_env)
143 cdft_constraint_section => section_vals_get_subs_vals(qs_env%input, "DFT%QS%CDFT")
144 iw = cp_print_key_unit_nr(logger, cdft_constraint_section, "PROGRAM_RUN_INFO", extension=".cdftLog")
145 cdft_control => dft_control%qs_control%cdft_control
146 becke_control => cdft_control%becke_control
147 group => cdft_control%group
148 in_memory = .false.
149 IF (cdft_control%save_pot) THEN
150 in_memory = becke_control%in_memory
151 END IF
152 IF (becke_control%cavity_confine) THEN
153 ALLOCATE (is_constraint(natom))
154 is_constraint = .false.
155 DO i = 1, cdft_control%natoms
156 ! Notice that here is_constraint=.TRUE. also for dummy atoms to properly compute their Becke charges
157 ! A subsequent check (atom_in_group) ensures that the gradients of these dummy atoms are correct
158 is_constraint(cdft_control%atoms(i)) = .true.
159 END DO
160 END IF
161 eps_cavity = becke_control%eps_cavity
162 ! Setup atomic radii for adjusting cell boundaries
163 IF (becke_control%adjust) THEN
164 IF (.NOT. ASSOCIATED(becke_control%radii)) THEN
165 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
166 IF (.NOT. SIZE(atomic_kind_set) == SIZE(becke_control%radii_tmp)) THEN
167 CALL cp_abort(__location__, &
168 "Length of keyword BECKE_CONSTRAINT\ATOMIC_RADII does not "// &
169 "match number of atomic kinds in the input coordinate file.")
170 END IF
171 ALLOCATE (becke_control%radii(SIZE(atomic_kind_set)))
172 becke_control%radii(:) = becke_control%radii_tmp(:)
173 DEALLOCATE (becke_control%radii_tmp)
174 END IF
175 END IF
176 ! Setup cutoff scheme
177 IF (.NOT. ASSOCIATED(becke_control%cutoffs)) THEN
178 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
179 ALLOCATE (becke_control%cutoffs(natom))
180 SELECT CASE (becke_control%cutoff_type)
182 becke_control%cutoffs(:) = becke_control%rglobal
184 IF (.NOT. SIZE(atomic_kind_set) == SIZE(becke_control%cutoffs_tmp)) THEN
185 CALL cp_abort(__location__, &
186 "Length of keyword BECKE_CONSTRAINT\ELEMENT_CUTOFFS does not "// &
187 "match number of atomic kinds in the input coordinate file.")
188 END IF
189 DO ikind = 1, SIZE(atomic_kind_set)
190 CALL get_atomic_kind(atomic_kind_set(ikind), natom=katom, atom_list=atom_list)
191 DO iatom = 1, katom
192 atom_a = atom_list(iatom)
193 becke_control%cutoffs(atom_a) = becke_control%cutoffs_tmp(ikind)
194 END DO
195 END DO
196 DEALLOCATE (becke_control%cutoffs_tmp)
197 END SELECT
198 END IF
199 ! Zero weight functions
200 DO igroup = 1, SIZE(group)
201 CALL pw_zero(group(igroup)%weight)
202 END DO
203 IF (cdft_control%atomic_charges) THEN
204 DO iatom = 1, cdft_control%natoms
205 CALL pw_zero(cdft_control%charge(iatom))
206 END DO
207 END IF
208 ! Allocate storage for cell adjustment coefficients and needed distance vectors
209 build = .false.
210 IF (becke_control%adjust .AND. .NOT. ASSOCIATED(becke_control%aij)) THEN
211 ALLOCATE (becke_control%aij(natom, natom))
212 build = .true.
213 END IF
214 IF (becke_control%vector_buffer%store_vectors) THEN
215 ALLOCATE (becke_control%vector_buffer%distances(natom))
216 ALLOCATE (becke_control%vector_buffer%distance_vecs(3, natom))
217 IF (in_memory) ALLOCATE (becke_control%vector_buffer%pair_dist_vecs(3, natom, natom))
218 ALLOCATE (becke_control%vector_buffer%position_vecs(3, natom))
219 END IF
220 ALLOCATE (becke_control%vector_buffer%R12(natom, natom))
221 ! Calculate pairwise distances between each atom pair
222 DO i = 1, 3
223 cell_v(i) = cell%hmat(i, i)
224 END DO
225 DO iatom = 1, natom - 1
226 DO jatom = iatom + 1, natom
227 r = particle_set(iatom)%r
228 r1 = particle_set(jatom)%r
229 DO i = 1, 3
230 r(i) = modulo(r(i), cell%hmat(i, i)) - cell%hmat(i, i)/2._dp
231 r1(i) = modulo(r1(i), cell%hmat(i, i)) - cell%hmat(i, i)/2._dp
232 END DO
233 dist_vec = (r - r1) - anint((r - r1)/cell_v)*cell_v
234 ! Store pbc corrected position and pairwise distance vectors for later reuse
235 IF (becke_control%vector_buffer%store_vectors) THEN
236 becke_control%vector_buffer%position_vecs(:, iatom) = r(:)
237 IF (iatom == 1 .AND. jatom == natom) becke_control%vector_buffer%position_vecs(:, jatom) = r1(:)
238 IF (in_memory) THEN
239 becke_control%vector_buffer%pair_dist_vecs(:, iatom, jatom) = dist_vec(:)
240 becke_control%vector_buffer%pair_dist_vecs(:, jatom, iatom) = -dist_vec(:)
241 END IF
242 END IF
243 becke_control%vector_buffer%R12(iatom, jatom) = norm2(dist_vec)
244 becke_control%vector_buffer%R12(jatom, iatom) = becke_control%vector_buffer%R12(iatom, jatom)
245 ! Set up heteronuclear cell partitioning using user defined radii
246 IF (build) THEN
247 CALL get_atomic_kind(atomic_kind=particle_set(iatom)%atomic_kind, kind_number=ikind)
248 ircov = becke_control%radii(ikind)
249 CALL get_atomic_kind(atomic_kind=particle_set(jatom)%atomic_kind, kind_number=ikind)
250 jrcov = becke_control%radii(ikind)
251 IF (ircov /= jrcov) THEN
252 chi = ircov/jrcov
253 uij = (chi - 1.0_dp)/(chi + 1.0_dp)
254 becke_control%aij(iatom, jatom) = uij/(uij**2 - 1.0_dp)
255 IF (becke_control%aij(iatom, jatom) > 0.5_dp) THEN
256 becke_control%aij(iatom, jatom) = 0.5_dp
257 ELSE IF (becke_control%aij(iatom, jatom) < -0.5_dp) THEN
258 becke_control%aij(iatom, jatom) = -0.5_dp
259 END IF
260 ELSE
261 becke_control%aij(iatom, jatom) = 0.0_dp
262 END IF
263 ! Note change of sign
264 becke_control%aij(jatom, iatom) = -becke_control%aij(iatom, jatom)
265 END IF
266 END DO
267 END DO
268 ! Dump some additional information about the calculation
269 IF (cdft_control%first_iteration) THEN
270 IF (iw > 0) THEN
271 WRITE (iw, '(/,T3,A)') &
272 '----------------------- Becke atomic parameters ------------------------'
273 IF (becke_control%adjust) THEN
274 WRITE (iw, '(T3,A)') &
275 'Atom Element Cutoff (angstrom) CDFT Radius (angstrom)'
276 DO iatom = 1, natom
277 CALL get_atomic_kind(atomic_kind=particle_set(iatom)%atomic_kind, element_symbol=element_symbol, &
278 kind_number=ikind)
279 ircov = cp_unit_from_cp2k(becke_control%radii(ikind), "angstrom")
280 WRITE (iw, "(i6,T15,A2,T37,F8.3,T67,F8.3)") &
281 iatom, adjustr(element_symbol), cp_unit_from_cp2k(becke_control%cutoffs(iatom), "angstrom"), &
282 ircov
283 END DO
284 ELSE
285 WRITE (iw, '(T3,A)') &
286 'Atom Element Cutoff (angstrom)'
287 DO iatom = 1, natom
288 CALL get_atomic_kind(atomic_kind=particle_set(iatom)%atomic_kind, element_symbol=element_symbol)
289 WRITE (iw, "(i7,T15,A2,T37,F8.3)") &
290 iatom, adjustr(element_symbol), cp_unit_from_cp2k(becke_control%cutoffs(iatom), "angstrom")
291 END DO
292 END IF
293 WRITE (iw, '(T3,A)') &
294 '------------------------------------------------------------------------'
295 WRITE (iw, '(/,T3,A,T60)') &
296 '----------------------- Becke group definitions ------------------------'
297 DO igroup = 1, SIZE(group)
298 IF (igroup > 1) WRITE (iw, '(T3,A)') ' '
299 WRITE (iw, '(T5,A,I5,A,I5)') &
300 'Atomic group', igroup, ' of ', SIZE(group)
301 WRITE (iw, '(T5,A)') 'Atom Element Coefficient'
302 DO ip = 1, SIZE(group(igroup)%atoms)
303 iatom = group(igroup)%atoms(ip)
304 CALL get_atomic_kind(atomic_kind=particle_set(iatom)%atomic_kind, element_symbol=element_symbol)
305 WRITE (iw, '(i8,T16,A2,T23,F8.3)') iatom, adjustr(element_symbol), group(igroup)%coeff(ip)
306 END DO
307 END DO
308 WRITE (iw, '(T3,A)') &
309 '------------------------------------------------------------------------'
310 END IF
311 cdft_control%first_iteration = .false.
312 END IF
313 ! Setup cavity confinement using spherical Gaussians
314 IF (becke_control%cavity_confine) THEN
315 cavity_env => becke_control%cavity_env
316 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, pw_env=pw_env, qs_kind_set=qs_kind_set)
317 cpassert(ASSOCIATED(qs_kind_set))
318 nkind = SIZE(qs_kind_set)
319 ! Setup the Gaussian shape function
320 IF (.NOT. ASSOCIATED(cavity_env%kind_shape_fn)) THEN
321 IF (ASSOCIATED(becke_control%radii)) THEN
322 ALLOCATE (radii_list(SIZE(becke_control%radii)))
323 DO ikind = 1, SIZE(becke_control%radii)
324 IF (cavity_env%use_bohr) THEN
325 radii_list(ikind) = becke_control%radii(ikind)
326 ELSE
327 radii_list(ikind) = cp_unit_from_cp2k(becke_control%radii(ikind), "angstrom")
328 END IF
329 END DO
330 END IF
331 CALL create_shape_function(cavity_env, qs_kind_set, atomic_kind_set, &
332 radius=becke_control%rcavity, &
333 radii_list=radii_list)
334 IF (ASSOCIATED(radii_list)) THEN
335 DEALLOCATE (radii_list)
336 END IF
337 END IF
338 ! Form cavity by summing isolated Gaussian densities over constraint atoms
339 NULLIFY (rs_cavity)
340 CALL pw_env_get(pw_env, auxbas_rs_grid=rs_cavity, auxbas_pw_pool=auxbas_pw_pool)
341 CALL rs_grid_zero(rs_cavity)
342 ALLOCATE (pab(1, 1))
343 nthread = 1
344 ithread = 0
345 DO ikind = 1, SIZE(atomic_kind_set)
346 numexp = cavity_env%kind_shape_fn(ikind)%numexp
347 IF (numexp <= 0) cycle
348 CALL get_atomic_kind(atomic_kind_set(ikind), natom=katom, atom_list=atom_list)
349 ALLOCATE (cores(katom))
350 DO iex = 1, numexp
351 alpha = cavity_env%kind_shape_fn(ikind)%zet(iex)
352 coef = cavity_env%kind_shape_fn(ikind)%coef(iex)
353 npme = 0
354 cores = 0
355 DO iatom = 1, katom
356 IF (rs_cavity%desc%parallel .AND. .NOT. rs_cavity%desc%distributed) THEN
357 ! replicated realspace grid, split the atoms up between procs
358 IF (modulo(iatom, rs_cavity%desc%group_size) == rs_cavity%desc%my_pos) THEN
359 npme = npme + 1
360 cores(npme) = iatom
361 END IF
362 ELSE
363 npme = npme + 1
364 cores(npme) = iatom
365 END IF
366 END DO
367 DO j = 1, npme
368 iatom = cores(j)
369 atom_a = atom_list(iatom)
370 pab(1, 1) = coef
371 IF (becke_control%vector_buffer%store_vectors) THEN
372 ra(:) = becke_control%vector_buffer%position_vecs(:, atom_a) + cell_v(:)/2._dp
373 ELSE
374 ra(:) = pbc(particle_set(atom_a)%r, cell)
375 END IF
376 IF (is_constraint(atom_a)) THEN
377 radius = exp_radius_very_extended(la_min=0, la_max=0, lb_min=0, lb_max=0, &
378 ra=ra, rb=ra, rp=ra, zetp=alpha, &
379 eps=dft_control%qs_control%eps_rho_rspace, &
380 pab=pab, o1=0, o2=0, & ! without map_consistent
381 prefactor=1.0_dp, cutoff=0.0_dp)
382
383 CALL collocate_pgf_product(0, alpha, 0, 0, 0.0_dp, 0, ra, &
384 [0.0_dp, 0.0_dp, 0.0_dp], 1.0_dp, &
385 pab, 0, 0, rs_cavity, &
386 radius=radius, ga_gb_function=grid_func_ab, &
387 use_subpatch=.true., subpatch_pattern=0)
388 END IF
389 END DO
390 END DO
391 DEALLOCATE (cores)
392 END DO
393 DEALLOCATE (pab)
394 CALL auxbas_pw_pool%create_pw(becke_control%cavity)
395 CALL transfer_rs2pw(rs_cavity, becke_control%cavity)
396 ! Grid points where the Gaussian density falls below eps_cavity are ignored
397 ! We can calculate the smallest/largest values along z-direction outside
398 ! which the cavity is zero at every point (x, y)
399 ! If gradients are needed storage needs to be allocated only for grid points within
400 ! these bounds
401 IF (in_memory .OR. cdft_control%save_pot) THEN
402 CALL hfun_zero(becke_control%cavity%array, eps_cavity, just_bounds=.true., bounds=bounds)
403 ! Save bounds (first nonzero grid point indices)
404 bo = group(1)%weight%pw_grid%bounds_local
405 IF (bounds(2) < bo(2, 3)) THEN
406 bounds(2) = bounds(2) - 1
407 ELSE
408 bounds(2) = bo(2, 3)
409 END IF
410 IF (bounds(1) > bo(1, 3)) THEN
411 ! In the special case bounds(1) == bounds(2) == bo(2, 3), after this check
412 ! bounds(1) > bounds(2) and the subsequent gradient allocation (:, :, :, bounds(1):bounds(2))
413 ! will correctly allocate a 0-sized array
414 bounds(1) = bounds(1) + 1
415 ELSE
416 bounds(1) = bo(1, 3)
417 END IF
418 becke_control%confine_bounds = bounds
419 END IF
420 ! Optional printing of cavity (meant for testing, so options currently hardcoded...)
421 IF (becke_control%print_cavity) THEN
422 CALL hfun_zero(becke_control%cavity%array, eps_cavity, just_bounds=.false.)
423 ALLOCATE (stride(3))
424 stride = [2, 2, 2]
425 mpi_io = .true.
426 ! Note PROGRAM_RUN_INFO section neeeds to be active!
427 unit_nr = cp_print_key_unit_nr(logger, cdft_constraint_section, "PROGRAM_RUN_INFO", &
428 middle_name="BECKE_CAVITY", &
429 extension=".cube", file_position="REWIND", &
430 log_filename=.false., mpi_io=mpi_io)
431 IF (para_env%is_source() .AND. unit_nr < 1) THEN
432 CALL cp_abort(__location__, &
433 "Please turn on PROGRAM_RUN_INFO to print cavity")
434 END IF
435 CALL get_qs_env(qs_env, subsys=subsys)
436 CALL qs_subsys_get(subsys, particles=particles)
437 CALL cp_pw_to_cube(becke_control%cavity, unit_nr, "CAVITY", particles=particles, stride=stride, mpi_io=mpi_io)
438 CALL cp_print_key_finished_output(unit_nr, logger, cdft_constraint_section, "PROGRAM_RUN_INFO", mpi_io=mpi_io)
439 DEALLOCATE (stride)
440 END IF
441 END IF
442 IF (ALLOCATED(is_constraint)) THEN
443 DEALLOCATE (is_constraint)
444 END IF
445 CALL timestop(handle)
446
447 END SUBROUTINE becke_constraint_init
448
449! **************************************************************************************************
450!> \brief reads the input parameters specific to Becke-based CDFT constraints
451!> \param cdft_control the cdft_control which holds the Becke control type
452!> \param becke_section the input section containing Becke constraint information
453!> \par History
454!> Created 01.2007 [fschiff]
455!> Merged Becke into CDFT 09.2018 [Nico Holmberg]
456!> \author Nico Holmberg [09.2018]
457! **************************************************************************************************
458 SUBROUTINE read_becke_section(cdft_control, becke_section)
459
460 TYPE(cdft_control_type), INTENT(INOUT) :: cdft_control
461 TYPE(section_vals_type), POINTER :: becke_section
462
463 INTEGER :: j
464 LOGICAL :: exists
465 REAL(kind=dp), DIMENSION(:), POINTER :: rtmplist
466 TYPE(becke_constraint_type), POINTER :: becke_control
467
468 NULLIFY (rtmplist)
469 becke_control => cdft_control%becke_control
470 cpassert(ASSOCIATED(becke_control))
471
472 ! Atomic size corrections
473 CALL section_vals_val_get(becke_section, "ADJUST_SIZE", l_val=becke_control%adjust)
474 IF (becke_control%adjust) THEN
475 CALL section_vals_val_get(becke_section, "ATOMIC_RADII", explicit=exists)
476 IF (.NOT. exists) cpabort("Keyword ATOMIC_RADII is missing.")
477 CALL section_vals_val_get(becke_section, "ATOMIC_RADII", r_vals=rtmplist)
478 cpassert(SIZE(rtmplist) > 0)
479 ALLOCATE (becke_control%radii_tmp(SIZE(rtmplist)))
480 DO j = 1, SIZE(rtmplist)
481 becke_control%radii_tmp(j) = rtmplist(j)
482 END DO
483 END IF
484
485 ! Cutoff scheme
486 CALL section_vals_val_get(becke_section, "CUTOFF_TYPE", i_val=becke_control%cutoff_type)
487 SELECT CASE (becke_control%cutoff_type)
489 CALL section_vals_val_get(becke_section, "GLOBAL_CUTOFF", r_val=becke_control%rglobal)
491 CALL section_vals_val_get(becke_section, "ELEMENT_CUTOFF", r_vals=rtmplist)
492 cpassert(SIZE(rtmplist) > 0)
493 ALLOCATE (becke_control%cutoffs_tmp(SIZE(rtmplist)))
494 DO j = 1, SIZE(rtmplist)
495 becke_control%cutoffs_tmp(j) = rtmplist(j)
496 END DO
497 END SELECT
498
499 ! Gaussian cavity confinement
500 CALL section_vals_val_get(becke_section, "CAVITY_CONFINE", l_val=becke_control%cavity_confine)
501 CALL section_vals_val_get(becke_section, "SHOULD_SKIP", l_val=becke_control%should_skip)
502 CALL section_vals_val_get(becke_section, "IN_MEMORY", l_val=becke_control%in_memory)
503 IF (cdft_control%becke_control%cavity_confine) THEN
504 CALL section_vals_val_get(becke_section, "CAVITY_SHAPE", i_val=becke_control%cavity_shape)
505 IF (becke_control%cavity_shape == radius_user .AND. .NOT. becke_control%adjust) THEN
506 CALL cp_abort(__location__, &
507 "Activate keyword ADJUST_SIZE to use cavity shape USER.")
508 END IF
509 CALL section_vals_val_get(becke_section, "CAVITY_RADIUS", r_val=becke_control%rcavity)
510 CALL section_vals_val_get(becke_section, "EPS_CAVITY", r_val=becke_control%eps_cavity)
511 CALL section_vals_val_get(becke_section, "CAVITY_PRINT", l_val=becke_control%print_cavity)
512 CALL section_vals_val_get(becke_section, "CAVITY_USE_BOHR", l_val=becke_control%use_bohr)
513 IF (.NOT. cdft_control%becke_control%use_bohr) THEN
514 becke_control%rcavity = cp_unit_from_cp2k(becke_control%rcavity, "angstrom")
515 END IF
516 CALL create_hirshfeld_type(becke_control%cavity_env)
517 CALL set_hirshfeld_info(becke_control%cavity_env, &
518 shape_function_type=shape_function_gaussian, iterative=.false., &
519 radius_type=becke_control%cavity_shape, &
520 use_bohr=becke_control%use_bohr)
521 END IF
522
523 CALL cite_reference(becke1988b)
524
525 END SUBROUTINE read_becke_section
526
527! **************************************************************************************************
528!> \brief reads the input parameters needed to define CDFT constraints
529!> \param cdft_control the object which holds the CDFT control type
530!> \param cdft_control_section the input section containing CDFT constraint information
531!> \author Nico Holmberg [09.2018]
532! **************************************************************************************************
533 SUBROUTINE read_constraint_definitions(cdft_control, cdft_control_section)
534
535 TYPE(cdft_control_type), INTENT(INOUT) :: cdft_control
536 TYPE(section_vals_type), INTENT(INOUT), POINTER :: cdft_control_section
537
538 INTEGER :: i, j, jj, k, n_rep, natoms, nvar, &
539 tot_natoms
540 INTEGER, DIMENSION(:), POINTER :: atomlist, dummylist, tmplist
541 LOGICAL :: exists, is_duplicate
542 REAL(kind=dp), DIMENSION(:), POINTER :: rtmplist
543 TYPE(section_vals_type), POINTER :: group_section
544
545 NULLIFY (tmplist, rtmplist, atomlist, dummylist, group_section)
546
547 group_section => section_vals_get_subs_vals(cdft_control_section, "ATOM_GROUP")
548 CALL section_vals_get(group_section, n_repetition=nvar, explicit=exists)
549 IF (.NOT. exists) cpabort("Section ATOM_GROUP is missing.")
550 ALLOCATE (cdft_control%group(nvar))
551 tot_natoms = 0
552 ! Parse all ATOM_GROUP sections
553 DO k = 1, nvar
554 ! First determine how much storage is needed
555 natoms = 0
556 CALL section_vals_val_get(group_section, "ATOMS", i_rep_section=k, n_rep_val=n_rep)
557 DO j = 1, n_rep
558 CALL section_vals_val_get(group_section, "ATOMS", i_rep_section=k, i_rep_val=j, i_vals=tmplist)
559 IF (SIZE(tmplist) < 1) THEN
560 cpabort("Each ATOM_GROUP must contain at least 1 atom.")
561 END IF
562 natoms = natoms + SIZE(tmplist)
563 END DO
564 ALLOCATE (cdft_control%group(k)%atoms(natoms))
565 ALLOCATE (cdft_control%group(k)%coeff(natoms))
566 NULLIFY (cdft_control%group(k)%weight)
567 NULLIFY (cdft_control%group(k)%integrated)
568 tot_natoms = tot_natoms + natoms
569 ! Now parse
570 jj = 0
571 DO j = 1, n_rep
572 CALL section_vals_val_get(group_section, "ATOMS", i_rep_section=k, i_rep_val=j, i_vals=tmplist)
573 DO i = 1, SIZE(tmplist)
574 jj = jj + 1
575 cdft_control%group(k)%atoms(jj) = tmplist(i)
576 END DO
577 END DO
578 CALL section_vals_val_get(group_section, "COEFF", i_rep_section=k, n_rep_val=n_rep)
579 jj = 0
580 DO j = 1, n_rep
581 CALL section_vals_val_get(group_section, "COEFF", i_rep_section=k, i_rep_val=j, r_vals=rtmplist)
582 DO i = 1, SIZE(rtmplist)
583 jj = jj + 1
584 IF (jj > natoms) cpabort("Length of keywords ATOMS and COEFF must match.")
585 IF (abs(rtmplist(i)) /= 1.0_dp) cpabort("Keyword COEFF accepts only values +/-1.0")
586 cdft_control%group(k)%coeff(jj) = rtmplist(i)
587 END DO
588 END DO
589 IF (jj < natoms) cpabort("Length of keywords ATOMS and COEFF must match.")
590 CALL section_vals_val_get(group_section, "CONSTRAINT_TYPE", i_rep_section=k, &
591 i_val=cdft_control%group(k)%constraint_type)
592 CALL section_vals_val_get(group_section, "FRAGMENT_CONSTRAINT", i_rep_section=k, &
593 l_val=cdft_control%group(k)%is_fragment_constraint)
594 IF (cdft_control%group(k)%is_fragment_constraint) cdft_control%fragment_density = .true.
595 END DO
596 ! Create a list containing all constraint atoms
597 ALLOCATE (atomlist(tot_natoms))
598 atomlist = -1
599 jj = 0
600 DO k = 1, nvar
601 DO j = 1, SIZE(cdft_control%group(k)%atoms)
602 is_duplicate = .false.
603 DO i = 1, jj + 1
604 IF (cdft_control%group(k)%atoms(j) == atomlist(i)) THEN
605 is_duplicate = .true.
606 EXIT
607 END IF
608 END DO
609 IF (.NOT. is_duplicate) THEN
610 jj = jj + 1
611 atomlist(jj) = cdft_control%group(k)%atoms(j)
612 END IF
613 END DO
614 END DO
615 CALL reallocate(atomlist, 1, jj)
616 CALL section_vals_val_get(cdft_control_section, "ATOMIC_CHARGES", &
617 l_val=cdft_control%atomic_charges)
618 ! Parse any dummy atoms (no constraint, just charges)
619 IF (cdft_control%atomic_charges) THEN
620 group_section => section_vals_get_subs_vals(cdft_control_section, "DUMMY_ATOMS")
621 CALL section_vals_get(group_section, explicit=exists)
622 IF (exists) THEN
623 ! First determine how many atoms there are
624 natoms = 0
625 CALL section_vals_val_get(group_section, "ATOMS", n_rep_val=n_rep)
626 DO j = 1, n_rep
627 CALL section_vals_val_get(group_section, "ATOMS", i_rep_val=j, i_vals=tmplist)
628 IF (SIZE(tmplist) < 1) THEN
629 cpabort("DUMMY_ATOMS must contain at least 1 atom.")
630 END IF
631 natoms = natoms + SIZE(tmplist)
632 END DO
633 ALLOCATE (dummylist(natoms))
634 ! Now parse
635 jj = 0
636 DO j = 1, n_rep
637 CALL section_vals_val_get(group_section, "ATOMS", i_rep_val=j, i_vals=tmplist)
638 DO i = 1, SIZE(tmplist)
639 jj = jj + 1
640 dummylist(jj) = tmplist(i)
641 END DO
642 END DO
643 ! Check for duplicates
644 DO j = 1, natoms
645 DO i = j + 1, natoms
646 IF (dummylist(i) == dummylist(j)) THEN
647 cpabort("Duplicate atoms defined in section DUMMY_ATOMS.")
648 END IF
649 END DO
650 END DO
651 ! Check that a dummy atom is not included in any ATOM_GROUP
652 DO j = 1, SIZE(atomlist)
653 DO i = 1, SIZE(dummylist)
654 IF (dummylist(i) == atomlist(j)) THEN
655 CALL cp_abort(__location__, &
656 "Duplicate atoms defined in sections ATOM_GROUP and DUMMY_ATOMS.")
657 END IF
658 END DO
659 END DO
660 END IF
661 END IF
662 ! Join dummy atoms and constraint atoms into one list
663 IF (ASSOCIATED(dummylist)) THEN
664 cdft_control%natoms = SIZE(atomlist) + SIZE(dummylist)
665 ELSE
666 cdft_control%natoms = SIZE(atomlist)
667 END IF
668 ALLOCATE (cdft_control%atoms(cdft_control%natoms))
669 ALLOCATE (cdft_control%is_constraint(cdft_control%natoms))
670 IF (cdft_control%atomic_charges) ALLOCATE (cdft_control%charge(cdft_control%natoms))
671 cdft_control%atoms(1:SIZE(atomlist)) = atomlist
672 IF (ASSOCIATED(dummylist)) THEN
673 cdft_control%atoms(1 + SIZE(atomlist):) = dummylist
674 DEALLOCATE (dummylist)
675 END IF
676 cdft_control%is_constraint = .false.
677 cdft_control%is_constraint(1:SIZE(atomlist)) = .true.
678 DEALLOCATE (atomlist)
679 ! Get constraint potential definitions from input
680 ALLOCATE (cdft_control%strength(nvar))
681 ALLOCATE (cdft_control%value(nvar))
682 ALLOCATE (cdft_control%target(nvar))
683 CALL section_vals_val_get(cdft_control_section, "STRENGTH", r_vals=rtmplist)
684 IF (SIZE(rtmplist) /= nvar) THEN
685 CALL cp_abort(__location__, &
686 "The length of keyword STRENGTH is incorrect. "// &
687 "Expected "//trim(adjustl(cp_to_string(nvar)))// &
688 " value(s), got "// &
689 trim(adjustl(cp_to_string(SIZE(rtmplist))))//" value(s).")
690 END IF
691 DO j = 1, nvar
692 cdft_control%strength(j) = rtmplist(j)
693 END DO
694 CALL section_vals_val_get(cdft_control_section, "TARGET", r_vals=rtmplist)
695 IF (SIZE(rtmplist) /= nvar) THEN
696 CALL cp_abort(__location__, &
697 "The length of keyword TARGET is incorrect. "// &
698 "Expected "//trim(adjustl(cp_to_string(nvar)))// &
699 " value(s), got "// &
700 trim(adjustl(cp_to_string(SIZE(rtmplist))))//" value(s).")
701 END IF
702 DO j = 1, nvar
703 cdft_control%target(j) = rtmplist(j)
704 END DO
705 ! Read fragment constraint definitions
706 IF (cdft_control%fragment_density) THEN
707 CALL section_vals_val_get(cdft_control_section, "FRAGMENT_A_FILE_NAME", &
708 c_val=cdft_control%fragment_a_fname)
709 CALL section_vals_val_get(cdft_control_section, "FRAGMENT_B_FILE_NAME", &
710 c_val=cdft_control%fragment_b_fname)
711 CALL section_vals_val_get(cdft_control_section, "FRAGMENT_A_SPIN_FILE", &
712 c_val=cdft_control%fragment_a_spin_fname)
713 CALL section_vals_val_get(cdft_control_section, "FRAGMENT_B_SPIN_FILE", &
714 c_val=cdft_control%fragment_b_spin_fname)
715 CALL section_vals_val_get(cdft_control_section, "FLIP_FRAGMENT_A", &
716 l_val=cdft_control%flip_fragment(1))
717 CALL section_vals_val_get(cdft_control_section, "FLIP_FRAGMENT_B", &
718 l_val=cdft_control%flip_fragment(2))
719 END IF
720
721 END SUBROUTINE read_constraint_definitions
722
723! **************************************************************************************************
724!> \brief reads the input parameters needed for CDFT with OT
725!> \param qs_control the qs_control which holds the CDFT control type
726!> \param cdft_control_section the input section for CDFT
727!> \author Nico Holmberg [12.2015]
728! **************************************************************************************************
729 SUBROUTINE read_cdft_control_section(qs_control, cdft_control_section)
730 TYPE(qs_control_type), INTENT(INOUT) :: qs_control
731 TYPE(section_vals_type), POINTER :: cdft_control_section
732
733 INTEGER :: k, nvar
734 LOGICAL :: exists
735 TYPE(cdft_control_type), POINTER :: cdft_control
736 TYPE(section_vals_type), POINTER :: becke_constraint_section, group_section, &
737 hirshfeld_constraint_section, &
738 outer_scf_section, print_section
739
740 NULLIFY (outer_scf_section, hirshfeld_constraint_section, becke_constraint_section, &
741 print_section, group_section)
742 cdft_control => qs_control%cdft_control
743 cpassert(ASSOCIATED(cdft_control))
744 group_section => section_vals_get_subs_vals(cdft_control_section, "ATOM_GROUP")
745 CALL section_vals_get(group_section, n_repetition=nvar, explicit=exists)
746
747 CALL section_vals_val_get(cdft_control_section, "TYPE_OF_CONSTRAINT", &
748 i_val=qs_control%cdft_control%type)
749
750 IF (cdft_control%type /= outer_scf_none) THEN
751 CALL section_vals_val_get(cdft_control_section, "REUSE_PRECOND", &
752 l_val=cdft_control%reuse_precond)
753 CALL section_vals_val_get(cdft_control_section, "PRECOND_FREQ", &
754 i_val=cdft_control%precond_freq)
755 CALL section_vals_val_get(cdft_control_section, "MAX_REUSE", &
756 i_val=cdft_control%max_reuse)
757 CALL section_vals_val_get(cdft_control_section, "PURGE_HISTORY", &
758 l_val=cdft_control%purge_history)
759 CALL section_vals_val_get(cdft_control_section, "PURGE_FREQ", &
760 i_val=cdft_control%purge_freq)
761 CALL section_vals_val_get(cdft_control_section, "PURGE_OFFSET", &
762 i_val=cdft_control%purge_offset)
763 CALL section_vals_val_get(cdft_control_section, "COUNTER", &
764 i_val=cdft_control%ienergy)
765 print_section => section_vals_get_subs_vals(cdft_control_section, "PROGRAM_RUN_INFO%WEIGHT_FUNCTION")
766 CALL section_vals_get(print_section, explicit=cdft_control%print_weight)
767
768 outer_scf_section => section_vals_get_subs_vals(cdft_control_section, "OUTER_SCF")
769 CALL outer_scf_read_parameters(cdft_control%constraint_control, outer_scf_section)
770 IF (cdft_control%constraint_control%have_scf) THEN
771 IF (cdft_control%constraint_control%type /= outer_scf_cdft_constraint) THEN
772 cpabort("Unsupported CDFT constraint.")
773 END IF
774 ! Constraint definitions
775 CALL read_constraint_definitions(cdft_control, cdft_control_section)
776 ! Constraint-specific initializations
777 SELECT CASE (cdft_control%type)
779 becke_constraint_section => section_vals_get_subs_vals(cdft_control_section, "BECKE_CONSTRAINT")
780 CALL section_vals_get(becke_constraint_section, explicit=exists)
781 IF (.NOT. exists) cpabort("BECKE_CONSTRAINT section is missing.")
782 DO k = 1, nvar
783 NULLIFY (cdft_control%group(k)%gradients)
784 END DO
785 CALL read_becke_section(cdft_control, becke_constraint_section)
787 hirshfeld_constraint_section => section_vals_get_subs_vals(cdft_control_section, "HIRSHFELD_CONSTRAINT")
788 CALL section_vals_get(hirshfeld_constraint_section, explicit=exists)
789 IF (.NOT. exists) cpabort("HIRSHFELD_CONSTRAINT section is missing.")
790 DO k = 1, nvar
791 NULLIFY (cdft_control%group(k)%gradients_x)
792 NULLIFY (cdft_control%group(k)%gradients_y)
793 NULLIFY (cdft_control%group(k)%gradients_z)
794 END DO
795 CALL read_hirshfeld_constraint_section(cdft_control, hirshfeld_constraint_section)
796 CASE DEFAULT
797 cpabort("Unknown constraint type.")
798 END SELECT
799
800 CALL cite_reference(holmberg2017)
801 CALL cite_reference(holmberg2018)
802 ELSE
803 qs_control%cdft = .false.
804 END IF
805 ELSE
806 qs_control%cdft = .false.
807 END IF
808
809 END SUBROUTINE read_cdft_control_section
810
811! **************************************************************************************************
812!> \brief reads the input parameters needed for Hirshfeld constraint
813!> \param cdft_control the cdft_control which holds the Hirshfeld constraint
814!> \param hirshfeld_section the input section for a Hirshfeld constraint
815! **************************************************************************************************
816 SUBROUTINE read_hirshfeld_constraint_section(cdft_control, hirshfeld_section)
817 TYPE(cdft_control_type), INTENT(INOUT) :: cdft_control
818 TYPE(section_vals_type), POINTER :: hirshfeld_section
819
820 LOGICAL :: exists
821 REAL(kind=dp), DIMENSION(:), POINTER :: rtmplist
822 TYPE(hirshfeld_constraint_type), POINTER :: hirshfeld_control
823
824 NULLIFY (rtmplist)
825 hirshfeld_control => cdft_control%hirshfeld_control
826 cpassert(ASSOCIATED(hirshfeld_control))
827
828 CALL section_vals_val_get(hirshfeld_section, "SHAPE_FUNCTION", i_val=hirshfeld_control%shape_function)
829 CALL section_vals_val_get(hirshfeld_section, "GAUSSIAN_SHAPE", i_val=hirshfeld_control%gaussian_shape)
830 CALL section_vals_val_get(hirshfeld_section, "GAUSSIAN_RADIUS", r_val=hirshfeld_control%radius)
831 CALL section_vals_val_get(hirshfeld_section, "USE_BOHR", l_val=hirshfeld_control%use_bohr)
832 CALL section_vals_val_get(hirshfeld_section, "USE_ATOMIC_CUTOFF", l_val=hirshfeld_control%use_atomic_cutoff)
833 CALL section_vals_val_get(hirshfeld_section, "PRINT_DENSITY", l_val=hirshfeld_control%print_density)
834 CALL section_vals_val_get(hirshfeld_section, "EPS_CUTOFF", r_val=hirshfeld_control%eps_cutoff)
835 CALL section_vals_val_get(hirshfeld_section, "ATOMIC_CUTOFF", r_val=hirshfeld_control%atomic_cutoff)
836
837 IF (.NOT. hirshfeld_control%use_bohr) THEN
838 hirshfeld_control%radius = cp_unit_from_cp2k(hirshfeld_control%radius, "angstrom")
839 END IF
840
841 IF (hirshfeld_control%shape_function == shape_function_gaussian .AND. &
842 hirshfeld_control%gaussian_shape == radius_user) THEN
843 CALL section_vals_val_get(hirshfeld_section, "ATOMIC_RADII", explicit=exists)
844 IF (.NOT. exists) cpabort("Keyword ATOMIC_RADII is missing.")
845 CALL section_vals_val_get(hirshfeld_section, "ATOMIC_RADII", r_vals=rtmplist)
846 cpassert(SIZE(rtmplist) > 0)
847 ALLOCATE (hirshfeld_control%radii(SIZE(rtmplist)))
848 hirshfeld_control%radii(:) = rtmplist
849 END IF
850
851 CALL create_hirshfeld_type(hirshfeld_control%hirshfeld_env)
852 CALL set_hirshfeld_info(hirshfeld_control%hirshfeld_env, &
853 shape_function_type=hirshfeld_control%shape_function, &
854 iterative=.false., &
855 radius_type=hirshfeld_control%gaussian_shape, &
856 use_bohr=hirshfeld_control%use_bohr)
857
858 END SUBROUTINE read_hirshfeld_constraint_section
859
860! **************************************************************************************************
861!> \brief Calculate fout = fun1/fun2 or fout = fun1*fun2
862!> \param fout the output 3D potential
863!> \param fun1 the first input 3D potential
864!> \param fun2 the second input 3D potential
865!> \param divide logical that decides whether to divide or multiply the input potentials
866!> \param small customisable parameter to determine lower bound of division
867! **************************************************************************************************
868 SUBROUTINE hfun_scale(fout, fun1, fun2, divide, small)
869 REAL(kind=dp), DIMENSION(:, :, :), INTENT(OUT) :: fout
870 REAL(kind=dp), DIMENSION(:, :, :), INTENT(IN) :: fun1, fun2
871 LOGICAL, INTENT(IN) :: divide
872 REAL(kind=dp), INTENT(IN) :: small
873
874 INTEGER :: i1, i2, i3, n1, n2, n3
875
876 n1 = SIZE(fout, 1)
877 n2 = SIZE(fout, 2)
878 n3 = SIZE(fout, 3)
879 cpassert(n1 == SIZE(fun1, 1))
880 cpassert(n2 == SIZE(fun1, 2))
881 cpassert(n3 == SIZE(fun1, 3))
882 cpassert(n1 == SIZE(fun2, 1))
883 cpassert(n2 == SIZE(fun2, 2))
884 cpassert(n3 == SIZE(fun2, 3))
885
886 IF (divide) THEN
887 DO i3 = 1, n3
888 DO i2 = 1, n2
889 DO i1 = 1, n1
890 IF (fun2(i1, i2, i3) > small) THEN
891 fout(i1, i2, i3) = fun1(i1, i2, i3)/fun2(i1, i2, i3)
892 ELSE
893 fout(i1, i2, i3) = 0.0_dp
894 END IF
895 END DO
896 END DO
897 END DO
898 ELSE
899 DO i3 = 1, n3
900 DO i2 = 1, n2
901 DO i1 = 1, n1
902 fout(i1, i2, i3) = fun1(i1, i2, i3)*fun2(i1, i2, i3)
903 END DO
904 END DO
905 END DO
906 END IF
907
908 END SUBROUTINE hfun_scale
909
910! **************************************************************************************************
911!> \brief Determine confinement bounds along confinement dir (hardcoded to be z)
912!> and optionally zero entries below a given threshold
913!> \param fun input 3D potential (real space)
914!> \param th threshold for screening values
915!> \param just_bounds if the bounds should be computed without zeroing values
916!> \param bounds the confinement bounds: fun is nonzero only between these values along 3rd dimension
917! **************************************************************************************************
918 SUBROUTINE hfun_zero(fun, th, just_bounds, bounds)
919 REAL(kind=dp), DIMENSION(:, :, :), INTENT(INOUT) :: fun
920 REAL(kind=dp), INTENT(IN) :: th
921 LOGICAL :: just_bounds
922 INTEGER, OPTIONAL :: bounds(2)
923
924 INTEGER :: i1, i2, i3, lb, n1, n2, n3, nzeroed, &
925 nzeroed_inner, ub
926 LOGICAL :: lb_final, ub_final
927
928 n1 = SIZE(fun, 1)
929 n2 = SIZE(fun, 2)
930 n3 = SIZE(fun, 3)
931 IF (just_bounds) THEN
932 cpassert(PRESENT(bounds))
933 lb = 1
934 lb_final = .false.
935 ub_final = .false.
936 END IF
937
938 DO i3 = 1, n3
939 IF (just_bounds) nzeroed = 0
940 DO i2 = 1, n2
941 IF (just_bounds) nzeroed_inner = 0
942 DO i1 = 1, n1
943 IF (fun(i1, i2, i3) < th) THEN
944 IF (just_bounds) THEN
945 nzeroed_inner = nzeroed_inner + 1
946 ELSE
947 fun(i1, i2, i3) = 0.0_dp
948 END IF
949 ELSE
950 IF (just_bounds) EXIT
951 END IF
952 END DO
953 IF (just_bounds) THEN
954 IF (nzeroed_inner < n1) EXIT
955 nzeroed = nzeroed + nzeroed_inner
956 END IF
957 END DO
958 IF (just_bounds) THEN
959 IF (nzeroed == (n2*n1)) THEN
960 IF (.NOT. lb_final) THEN
961 lb = i3
962 ELSE IF (.NOT. ub_final) THEN
963 ub = i3
964 ub_final = .true.
965 END IF
966 ELSE
967 IF (.NOT. lb_final) lb_final = .true.
968 IF (ub_final) ub_final = .false. ! Safeguard against "holes"
969 END IF
970 END IF
971 END DO
972 IF (just_bounds) THEN
973 IF (.NOT. ub_final) ub = n3
974 bounds(1) = lb
975 bounds(2) = ub
976 bounds = bounds - (n3/2) - 1
977 END IF
978
979 END SUBROUTINE hfun_zero
980
981! **************************************************************************************************
982!> \brief Initializes Gaussian Hirshfeld constraints
983!> \param qs_env the qs_env where to build the constraint
984!> \author Nico Holmberg (09.2018)
985! **************************************************************************************************
986 SUBROUTINE hirshfeld_constraint_init(qs_env)
987 TYPE(qs_environment_type), POINTER :: qs_env
988
989 CHARACTER(len=*), PARAMETER :: routinen = 'hirshfeld_constraint_init'
990
991 CHARACTER(len=2) :: element_symbol
992 INTEGER :: handle, iat, iatom, igroup, ikind, ip, &
993 iw, natom, nkind
994 INTEGER, DIMENSION(:), POINTER :: atom_list
995 REAL(kind=dp) :: zeff
996 REAL(kind=dp), DIMENSION(:), POINTER :: radii_list
997 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
998 TYPE(atomic_kind_type), POINTER :: atomic_kind
999 TYPE(cdft_control_type), POINTER :: cdft_control
1000 TYPE(cdft_group_type), DIMENSION(:), POINTER :: group
1001 TYPE(cp_logger_type), POINTER :: logger
1002 TYPE(dft_control_type), POINTER :: dft_control
1003 TYPE(hirshfeld_constraint_type), POINTER :: hirshfeld_control
1004 TYPE(hirshfeld_type), POINTER :: hirshfeld_env
1005 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1006 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1007 TYPE(section_vals_type), POINTER :: print_section
1008
1009 NULLIFY (cdft_control, hirshfeld_control, hirshfeld_env, qs_kind_set, atomic_kind_set, &
1010 radii_list, dft_control, group, atomic_kind, atom_list)
1011 CALL timeset(routinen, handle)
1012
1013 logger => cp_get_default_logger()
1014 print_section => section_vals_get_subs_vals(qs_env%input, "DFT%QS%CDFT")
1015 iw = cp_print_key_unit_nr(logger, print_section, "PROGRAM_RUN_INFO", extension=".cdftLog")
1016
1017 CALL get_qs_env(qs_env, dft_control=dft_control)
1018 cdft_control => dft_control%qs_control%cdft_control
1019 hirshfeld_control => cdft_control%hirshfeld_control
1020 hirshfeld_env => hirshfeld_control%hirshfeld_env
1021
1022 ! Setup the Hirshfeld shape function
1023 IF (.NOT. ASSOCIATED(hirshfeld_env%kind_shape_fn)) THEN
1024 hirshfeld_env => hirshfeld_control%hirshfeld_env
1025 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set)
1026 cpassert(ASSOCIATED(qs_kind_set))
1027 nkind = SIZE(qs_kind_set)
1028 ! Parse atomic radii for setting up Gaussian shape function
1029 IF (ASSOCIATED(hirshfeld_control%radii)) THEN
1030 IF (.NOT. SIZE(atomic_kind_set) == SIZE(hirshfeld_control%radii)) THEN
1031 CALL cp_abort(__location__, &
1032 "Length of keyword HIRSHFELD_CONSTRAINT\ATOMIC_RADII does not "// &
1033 "match number of atomic kinds in the input coordinate file.")
1034 END IF
1035
1036 ALLOCATE (radii_list(SIZE(hirshfeld_control%radii)))
1037 DO ikind = 1, SIZE(hirshfeld_control%radii)
1038 IF (hirshfeld_control%use_bohr) THEN
1039 radii_list(ikind) = hirshfeld_control%radii(ikind)
1040 ELSE
1041 radii_list(ikind) = cp_unit_from_cp2k(hirshfeld_control%radii(ikind), "angstrom")
1042 END IF
1043 END DO
1044 END IF
1045 ! radius/radii_list parameters are optional for shape_function_density
1046 CALL create_shape_function(hirshfeld_env, qs_kind_set, atomic_kind_set, &
1047 radius=hirshfeld_control%radius, &
1048 radii_list=radii_list)
1049 IF (ASSOCIATED(radii_list)) DEALLOCATE (radii_list)
1050 END IF
1051
1052 ! Atomic reference charges (Mulliken not supported)
1053 IF (.NOT. ASSOCIATED(hirshfeld_env%charges)) THEN
1054 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, atomic_kind_set=atomic_kind_set, &
1055 nkind=nkind, natom=natom)
1056 ALLOCATE (hirshfeld_env%charges(natom))
1057 DO ikind = 1, nkind
1058 CALL get_qs_kind(qs_kind_set(ikind), zeff=zeff)
1059 atomic_kind => atomic_kind_set(ikind)
1060 CALL get_atomic_kind(atomic_kind, atom_list=atom_list)
1061 DO iat = 1, SIZE(atom_list)
1062 iatom = atom_list(iat)
1063 hirshfeld_env%charges(iatom) = zeff
1064 END DO
1065 END DO
1066 END IF
1067
1068 ! Print some additional information about the calculation on the first iteration
1069 IF (cdft_control%first_iteration) THEN
1070 IF (iw > 0) THEN
1071 group => cdft_control%group
1072 CALL get_qs_env(qs_env, particle_set=particle_set)
1073 IF (ASSOCIATED(hirshfeld_control%radii)) THEN
1074 WRITE (iw, '(T3,A)') &
1075 'Atom Element Gaussian radius (angstrom)'
1076 DO iatom = 1, natom
1077 CALL get_atomic_kind(atomic_kind=particle_set(iatom)%atomic_kind, element_symbol=element_symbol)
1078 WRITE (iw, "(i7,T15,A2,T37,F8.3)") &
1079 iatom, adjustr(element_symbol), cp_unit_from_cp2k(hirshfeld_control%radii(iatom), "angstrom")
1080 END DO
1081 WRITE (iw, '(T3,A)') &
1082 '------------------------------------------------------------------------'
1083 END IF
1084 WRITE (iw, '(/,T3,A,T60)') &
1085 '----------------------- CDFT group definitions -------------------------'
1086 DO igroup = 1, SIZE(group)
1087 IF (igroup > 1) WRITE (iw, '(T3,A)') ' '
1088 WRITE (iw, '(T5,A,I5,A,I5)') &
1089 'Atomic group', igroup, ' of ', SIZE(group)
1090 WRITE (iw, '(T5,A)') 'Atom Element Coefficient'
1091 DO ip = 1, SIZE(group(igroup)%atoms)
1092 iatom = group(igroup)%atoms(ip)
1093 CALL get_atomic_kind(atomic_kind=particle_set(iatom)%atomic_kind, element_symbol=element_symbol)
1094 WRITE (iw, '(i8,T16,A2,T23,F8.3)') iatom, adjustr(element_symbol), group(igroup)%coeff(ip)
1095 END DO
1096 END DO
1097 WRITE (iw, '(T3,A)') &
1098 '------------------------------------------------------------------------'
1099 END IF
1100 cdft_control%first_iteration = .false.
1101 END IF
1102
1103 ! Radii no longer needed
1104 IF (ASSOCIATED(hirshfeld_control%radii)) DEALLOCATE (hirshfeld_control%radii)
1105 CALL timestop(handle)
1106
1107 END SUBROUTINE hirshfeld_constraint_init
1108
1109! **************************************************************************************************
1110!> \brief Prints information about CDFT constraints
1111!> \param qs_env the qs_env where to build the constraint
1112!> \param electronic_charge the CDFT charges
1113!> \par History
1114!> Created 9.2018 [Nico Holmberg]
1115! **************************************************************************************************
1116 SUBROUTINE cdft_constraint_print(qs_env, electronic_charge)
1117 TYPE(qs_environment_type), POINTER :: qs_env
1118 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: electronic_charge
1119
1120 CHARACTER(len=2) :: element_symbol
1121 INTEGER :: iatom, ikind, iw, jatom
1122 REAL(kind=dp) :: tc(2), zeff
1123 TYPE(cdft_control_type), POINTER :: cdft_control
1124 TYPE(cp_logger_type), POINTER :: logger
1125 TYPE(dft_control_type), POINTER :: dft_control
1126 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1127 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1128 TYPE(section_vals_type), POINTER :: cdft_constraint_section
1129
1130 NULLIFY (cdft_constraint_section, logger, particle_set, dft_control, qs_kind_set)
1131 logger => cp_get_default_logger()
1132
1133 CALL get_qs_env(qs_env, &
1134 particle_set=particle_set, &
1135 dft_control=dft_control, &
1136 qs_kind_set=qs_kind_set)
1137 cpassert(ASSOCIATED(qs_kind_set))
1138
1139 cdft_constraint_section => section_vals_get_subs_vals(qs_env%input, "DFT%QS%CDFT")
1140 iw = cp_print_key_unit_nr(logger, cdft_constraint_section, "PROGRAM_RUN_INFO", extension=".cdftLog")
1141 cdft_control => dft_control%qs_control%cdft_control
1142
1143 ! Print constraint information
1144 CALL qs_scf_cdft_constraint_info(iw, cdft_control)
1145
1146 ! Print weight function(s) to cube file(s) whenever weight is (re)built
1147 IF (cdft_control%print_weight .AND. cdft_control%need_pot) THEN
1148 CALL cdft_print_weight_function(qs_env)
1149 END IF
1150
1151 ! Print atomic CDFT charges
1152 IF (iw > 0 .AND. cdft_control%atomic_charges) THEN
1153 IF (.NOT. cdft_control%fragment_density) THEN
1154 IF (dft_control%nspins == 1) THEN
1155 WRITE (iw, '(/,T3,A)') &
1156 '-------------------------------- CDFT atomic charges --------------------------------'
1157 WRITE (iw, '(T3,A,A)') &
1158 '#Atom Element Is_constraint', ' Core charge Population (total)'// &
1159 ' Net charge'
1160 tc = 0.0_dp
1161 DO iatom = 1, cdft_control%natoms
1162 jatom = cdft_control%atoms(iatom)
1163 CALL get_atomic_kind(atomic_kind=particle_set(jatom)%atomic_kind, &
1164 element_symbol=element_symbol, &
1165 kind_number=ikind)
1166 CALL get_qs_kind(qs_kind_set(ikind), zeff=zeff)
1167 WRITE (iw, "(i7,T15,A2,T23,L10,T39,F8.3,T61,F8.3,T81,F8.3)") &
1168 jatom, adjustr(element_symbol), cdft_control%is_constraint(iatom), zeff, electronic_charge(iatom, 1), &
1169 (zeff - electronic_charge(iatom, 1))
1170 tc(1) = tc(1) + (zeff - electronic_charge(iatom, 1))
1171 END DO
1172 WRITE (iw, '(/,T3,A,T81,F8.3,/)') "Total Charge: ", tc(1)
1173 ELSE
1174 WRITE (iw, '(/,T3,A)') &
1175 '------------------------------------------ CDFT atomic charges -------------------------------------------'
1176 WRITE (iw, '(T3,A,A)') &
1177 '#Atom Element Is_constraint', ' Core charge Population (alpha, beta)'// &
1178 ' Net charge Spin population'
1179 tc = 0.0_dp
1180 DO iatom = 1, cdft_control%natoms
1181 jatom = cdft_control%atoms(iatom)
1182 CALL get_atomic_kind(atomic_kind=particle_set(jatom)%atomic_kind, &
1183 element_symbol=element_symbol, &
1184 kind_number=ikind)
1185 CALL get_qs_kind(qs_kind_set(ikind), zeff=zeff)
1186 WRITE (iw, "(i7,T15,A2,T23,L10,T39,F8.3,T53,F8.3,T67,F8.3,T81,F8.3,T102,F8.3)") &
1187 jatom, adjustr(element_symbol), &
1188 cdft_control%is_constraint(iatom), &
1189 zeff, electronic_charge(iatom, 1), electronic_charge(iatom, 2), &
1190 (zeff - electronic_charge(iatom, 1) - electronic_charge(iatom, 2)), &
1191 electronic_charge(iatom, 1) - electronic_charge(iatom, 2)
1192 tc(1) = tc(1) + (zeff - electronic_charge(iatom, 1) - electronic_charge(iatom, 2))
1193 tc(2) = tc(2) + (electronic_charge(iatom, 1) - electronic_charge(iatom, 2))
1194 END DO
1195 WRITE (iw, '(/,T3,A,T81,F8.3,T102,F8.3/)') "Total Charge and Spin Moment: ", tc(1), tc(2)
1196 END IF
1197 ELSE
1198 IF (all(cdft_control%group(:)%constraint_type == cdft_charge_constraint)) THEN
1199 WRITE (iw, '(/,T3,A)') &
1200 '-------------------------------- CDFT atomic charges --------------------------------'
1201 IF (dft_control%nspins == 1) THEN
1202 WRITE (iw, '(T3,A,A)') &
1203 '#Atom Element Is_constraint', ' Fragment charge Population (total)'// &
1204 ' Net charge'
1205 ELSE
1206 WRITE (iw, '(T3,A,A)') &
1207 '#Atom Element Is_constraint', ' Fragment charge Population (alpha, beta)'// &
1208 ' Net charge'
1209 END IF
1210 tc = 0.0_dp
1211 DO iatom = 1, cdft_control%natoms
1212 jatom = cdft_control%atoms(iatom)
1213 CALL get_atomic_kind(atomic_kind=particle_set(jatom)%atomic_kind, &
1214 element_symbol=element_symbol, &
1215 kind_number=ikind)
1216 IF (dft_control%nspins == 1) THEN
1217 WRITE (iw, "(i7,T15,A2,T23,L10,T43,F8.3,T65,F8.3,T81,F8.3)") &
1218 jatom, adjustr(element_symbol), &
1219 cdft_control%is_constraint(iatom), &
1220 cdft_control%charges_fragment(iatom, 1), &
1221 electronic_charge(iatom, 1), &
1222 (electronic_charge(iatom, 1) - &
1223 cdft_control%charges_fragment(iatom, 1))
1224 tc(1) = tc(1) + (electronic_charge(iatom, 1) - &
1225 cdft_control%charges_fragment(iatom, 1))
1226 ELSE
1227 WRITE (iw, "(i7,T15,A2,T23,L10,T43,F8.3,T57,F8.3,T69,F8.3,T81,F8.3)") &
1228 jatom, adjustr(element_symbol), &
1229 cdft_control%is_constraint(iatom), &
1230 cdft_control%charges_fragment(iatom, 1), &
1231 electronic_charge(iatom, 1), electronic_charge(iatom, 2), &
1232 (electronic_charge(iatom, 1) + electronic_charge(iatom, 2) - &
1233 cdft_control%charges_fragment(iatom, 1))
1234 tc(1) = tc(1) + (electronic_charge(iatom, 1) + electronic_charge(iatom, 2) - &
1235 cdft_control%charges_fragment(iatom, 1))
1236 END IF
1237 END DO
1238 WRITE (iw, '(/,T3,A,T81,F8.3,/)') "Total Charge: ", tc(1)
1239 ELSE
1240 WRITE (iw, '(/,T3,A)') &
1241 '------------------------------------------ CDFT atomic charges -------------------------------------------'
1242 WRITE (iw, '(T3,A,A)') &
1243 '#Atom Element Is_constraint', ' Fragment charge/spin moment'// &
1244 ' Population (alpha, beta) Net charge/spin moment'
1245 tc = 0.0_dp
1246 DO iatom = 1, cdft_control%natoms
1247 jatom = cdft_control%atoms(iatom)
1248 CALL get_atomic_kind(atomic_kind=particle_set(jatom)%atomic_kind, &
1249 element_symbol=element_symbol, &
1250 kind_number=ikind)
1251 WRITE (iw, "(i7,T15,A2,T22,L10,T40,F8.3,T52,F8.3,T66,F8.3,T78,F8.3,T90,F8.3,T102,F8.3)") &
1252 jatom, adjustr(element_symbol), &
1253 cdft_control%is_constraint(iatom), &
1254 cdft_control%charges_fragment(iatom, 1), &
1255 cdft_control%charges_fragment(iatom, 2), &
1256 electronic_charge(iatom, 1), electronic_charge(iatom, 2), &
1257 (electronic_charge(iatom, 1) + electronic_charge(iatom, 2) - &
1258 cdft_control%charges_fragment(iatom, 1)), &
1259 (electronic_charge(iatom, 1) - electronic_charge(iatom, 2) - &
1260 cdft_control%charges_fragment(iatom, 2))
1261 tc(1) = tc(1) + (electronic_charge(iatom, 1) + electronic_charge(iatom, 2) - &
1262 cdft_control%charges_fragment(iatom, 1))
1263 tc(2) = tc(2) + (electronic_charge(iatom, 1) - electronic_charge(iatom, 2) - &
1264 cdft_control%charges_fragment(iatom, 2))
1265 END DO
1266 WRITE (iw, '(/,T3,A,T90,F8.3,T102,F8.3/)') "Total Charge and Spin Moment: ", tc(1), tc(2)
1267 END IF
1268 END IF
1269 END IF
1270
1271 END SUBROUTINE cdft_constraint_print
1272
1273! **************************************************************************************************
1274!> \brief Prints CDFT weight functions to cube files
1275!> \param qs_env ...
1276! **************************************************************************************************
1278 TYPE(qs_environment_type), POINTER :: qs_env
1279
1280 CHARACTER(LEN=default_path_length) :: middle_name
1281 INTEGER :: igroup, unit_nr
1282 LOGICAL :: mpi_io
1283 TYPE(cdft_control_type), POINTER :: cdft_control
1284 TYPE(cp_logger_type), POINTER :: logger
1285 TYPE(dft_control_type), POINTER :: dft_control
1286 TYPE(mp_para_env_type), POINTER :: para_env
1287 TYPE(particle_list_type), POINTER :: particles
1288 TYPE(qs_subsys_type), POINTER :: subsys
1289 TYPE(section_vals_type), POINTER :: cdft_constraint_section
1290
1291 NULLIFY (cdft_constraint_section, logger, particles, dft_control, &
1292 para_env, subsys, cdft_control)
1293 logger => cp_get_default_logger()
1294
1295 CALL get_qs_env(qs_env, subsys=subsys, para_env=para_env, dft_control=dft_control)
1296 CALL qs_subsys_get(subsys, particles=particles)
1297 cdft_control => dft_control%qs_control%cdft_control
1298 cdft_constraint_section => section_vals_get_subs_vals(qs_env%input, "DFT%QS%CDFT")
1299
1300 DO igroup = 1, SIZE(cdft_control%group)
1301 mpi_io = .true.
1302 middle_name = "cdft_weight_"//trim(adjustl(cp_to_string(igroup)))
1303 unit_nr = cp_print_key_unit_nr(logger, cdft_constraint_section, "PROGRAM_RUN_INFO", &
1304 middle_name=middle_name, &
1305 extension=".cube", file_position="REWIND", &
1306 log_filename=.false., mpi_io=mpi_io)
1307 ! Note PROGRAM_RUN_INFO section neeeds to be active!
1308 IF (para_env%is_source() .AND. unit_nr < 1) THEN
1309 CALL cp_abort(__location__, &
1310 "Please turn on PROGRAM_RUN_INFO to print CDFT weight function.")
1311 END IF
1312
1313 CALL cp_pw_to_cube(cdft_control%group(igroup)%weight, &
1314 unit_nr, &
1315 "CDFT Weight Function", &
1316 particles=particles, &
1317 stride=section_get_ivals(cdft_constraint_section, "PROGRAM_RUN_INFO%WEIGHT_FUNCTION%STRIDE"), &
1318 mpi_io=mpi_io)
1319 CALL cp_print_key_finished_output(unit_nr, logger, cdft_constraint_section, "PROGRAM_RUN_INFO", mpi_io=mpi_io)
1320 END DO
1321
1322 END SUBROUTINE cdft_print_weight_function
1323
1324! **************************************************************************************************
1325!> \brief Prints Hirshfeld weight function and promolecule density
1326!> \param qs_env ...
1327! **************************************************************************************************
1329 TYPE(qs_environment_type), POINTER :: qs_env
1330
1331 CHARACTER(LEN=default_path_length) :: middle_name
1332 INTEGER :: iatom, igroup, unit_nr
1333 LOGICAL :: mpi_io
1334 TYPE(cdft_control_type), POINTER :: cdft_control
1335 TYPE(cp_logger_type), POINTER :: logger
1336 TYPE(dft_control_type), POINTER :: dft_control
1337 TYPE(mp_para_env_type), POINTER :: para_env
1338 TYPE(particle_list_type), POINTER :: particles
1339 TYPE(pw_env_type), POINTER :: pw_env
1340 TYPE(qs_subsys_type), POINTER :: subsys
1341 TYPE(section_vals_type), POINTER :: cdft_constraint_section
1342
1343 NULLIFY (cdft_constraint_section, logger, particles, dft_control, &
1344 para_env, subsys, cdft_control, pw_env)
1345 logger => cp_get_default_logger()
1346
1347 CALL get_qs_env(qs_env, subsys=subsys, para_env=para_env, dft_control=dft_control, pw_env=pw_env)
1348 CALL qs_subsys_get(subsys, particles=particles)
1349 cdft_control => dft_control%qs_control%cdft_control
1350 cdft_constraint_section => section_vals_get_subs_vals(qs_env%input, "DFT%QS%CDFT")
1351
1352 mpi_io = .true.
1353
1354 DO igroup = 1, SIZE(cdft_control%group)
1355
1356 middle_name = "hw_rho_total"//trim(adjustl(cp_to_string(igroup)))
1357 unit_nr = cp_print_key_unit_nr(logger, cdft_constraint_section, "PROGRAM_RUN_INFO", mpi_io=mpi_io, &
1358 file_position="REWIND", middle_name=middle_name, extension=".cube")
1359
1360 CALL cp_pw_to_cube(cdft_control%hw_rho_total, unit_nr, "CDFT Weight Function", mpi_io=mpi_io, &
1361 particles=particles, stride=section_get_ivals(cdft_constraint_section, "PROGRAM_RUN_INFO%WEIGHT_FUNCTION%STRIDE"))
1362
1363 CALL cp_print_key_finished_output(unit_nr, logger, cdft_constraint_section, "PROGRAM_RUN_INFO", mpi_io=mpi_io)
1364
1365 END DO
1366
1367 DO igroup = 1, SIZE(cdft_control%group)
1368
1369 middle_name = "hw_rho_total_constraint_"//trim(adjustl(cp_to_string(igroup)))
1370 unit_nr = cp_print_key_unit_nr(logger, cdft_constraint_section, "PROGRAM_RUN_INFO", mpi_io=mpi_io, &
1371 file_position="REWIND", middle_name=middle_name, extension=".cube")
1372
1373 CALL cp_pw_to_cube(cdft_control%group(igroup)%hw_rho_total_constraint, unit_nr, &
1374 "CDFT Weight Function", mpi_io=mpi_io, particles=particles, &
1375 stride=section_get_ivals(cdft_constraint_section, "PROGRAM_RUN_INFO%WEIGHT_FUNCTION%STRIDE"))
1376
1377 CALL cp_print_key_finished_output(unit_nr, logger, cdft_constraint_section, "PROGRAM_RUN_INFO", mpi_io=mpi_io)
1378
1379 END DO
1380
1381 DO igroup = 1, SIZE(cdft_control%group)
1382 DO iatom = 1, (cdft_control%natoms)
1383
1384 middle_name = "hw_rho_atomic_"//trim(adjustl(cp_to_string(iatom)))
1385 unit_nr = cp_print_key_unit_nr(logger, cdft_constraint_section, "PROGRAM_RUN_INFO", mpi_io=mpi_io, &
1386 file_position="REWIND", middle_name=middle_name, extension=".cube")
1387
1388 CALL cp_pw_to_cube(cdft_control%group(igroup)%hw_rho_atomic(iatom), unit_nr, &
1389 "CDFT Weight Function", mpi_io=mpi_io, particles=particles, &
1390 stride=section_get_ivals(cdft_constraint_section, "PROGRAM_RUN_INFO%WEIGHT_FUNCTION%STRIDE"))
1391
1392 CALL cp_print_key_finished_output(unit_nr, logger, cdft_constraint_section, "PROGRAM_RUN_INFO", mpi_io=mpi_io)
1393
1394 END DO
1395 END DO
1396
1397 END SUBROUTINE cdft_print_hirshfeld_density
1398
1399END MODULE qs_cdft_utils
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
All kind of helpful little routines.
Definition ao_util.F:14
real(kind=dp) function, public exp_radius_very_extended(la_min, la_max, lb_min, lb_max, pab, o1, o2, ra, rb, rp, zetp, eps, prefactor, cutoff, epsabs)
computes the radius of the Gaussian outside of which it is smaller than eps
Definition ao_util.F:209
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public holmberg2017
integer, save, public holmberg2018
integer, save, public becke1988b
Handles all functions related to the CELL.
Definition cell_types.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
various routines to log and control the output. The idea is that decisions about where to log should ...
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 function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_pw_to_cube(pw, unit_nr, title, particles, zeff, stride, max_file_size_mb, zero_tails, silent, mpi_io)
...
unit conversion facility
Definition cp_units.F:30
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
Definition cp_units.F:1251
Fortran API for the grid package, which is written in C.
Definition grid_api.F:12
integer, parameter, public grid_func_ab
Definition grid_api.F:27
subroutine, public collocate_pgf_product(la_max, zeta, la_min, lb_max, zetb, lb_min, ra, rab, scale, pab, o1, o2, rsgrid, ga_gb_function, radius, use_subpatch, subpatch_pattern)
low level collocation of primitive gaussian functions
Definition grid_api.F:116
Calculate Hirshfeld charges and related functions.
subroutine, public create_shape_function(hirshfeld_env, qs_kind_set, atomic_kind_set, radius, radii_list)
creates kind specific shape functions for Hirshfeld charges
The types needed for the calculation of Hirshfeld charges and related functions.
subroutine, public create_hirshfeld_type(hirshfeld_env)
...
subroutine, public set_hirshfeld_info(hirshfeld_env, shape_function_type, iterative, ref_charge, fnorm, radius_type, use_bohr)
Set values of a Hirshfeld env.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public becke_cutoff_element
integer, parameter, public outer_scf_cdft_constraint
integer, parameter, public cdft_charge_constraint
integer, parameter, public outer_scf_becke_constraint
integer, parameter, public radius_user
integer, parameter, public outer_scf_hirshfeld_constraint
integer, parameter, public shape_function_gaussian
integer, parameter, public outer_scf_none
integer, parameter, public becke_cutoff_global
objects that represent the structure of input sections and the data contained in an input section
integer function, dimension(:), pointer, public section_get_ivals(section_vals, keyword_name)
...
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
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_path_length
Definition kinds.F:58
Utility routines for the memory handling.
Interface to the message passing library MPI.
parameters that control the outer loop of an SCF iteration
subroutine, public outer_scf_read_parameters(outer_scf, outer_scf_section)
reads the parameters of the outer_scf section into the given outer_scf
represent a simple array based list of the given type
Define the data structure for the particle information.
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
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Defines CDFT control structures.
Utility subroutines for CDFT calculations.
subroutine, public read_cdft_control_section(qs_control, cdft_control_section)
reads the input parameters needed for CDFT with OT
subroutine, public cdft_constraint_print(qs_env, electronic_charge)
Prints information about CDFT constraints.
subroutine, public hirshfeld_constraint_init(qs_env)
Initializes Gaussian Hirshfeld constraints.
subroutine, public cdft_print_weight_function(qs_env)
Prints CDFT weight functions to cube files.
subroutine, public becke_constraint_init(qs_env)
Initializes the Becke constraint environment.
subroutine, public read_becke_section(cdft_control, becke_section)
reads the input parameters specific to Becke-based CDFT constraints
subroutine, public cdft_print_hirshfeld_density(qs_env)
Prints Hirshfeld weight function and promolecule density.
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, mimic, 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, sab_cneo, 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, matrix_vhxc, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public qs_scf_cdft_constraint_info(output_unit, cdft_control)
writes CDFT constraint information
types that represent a quickstep subsys
subroutine, public qs_subsys_get(subsys, 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, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...
subroutine, public transfer_rs2pw(rs, pw)
...
subroutine, public rs_grid_zero(rs)
Initialize grid to zero.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
type of a logger, at the moment it contains just a print level starting at which level it should be l...
quantities needed for a Hirshfeld based partitioning of real space
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 ...
control parameters for CDFT simulations
Provides all information about a quickstep kind.