(git:993c3eb)
Loading...
Searching...
No Matches
bsse.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 Module to perform a counterpoise correction (BSSE)
10!> \par History
11!> 6.2005 created [tlaino]
12!> \author Teodoro Laino
13! **************************************************************************************************
14MODULE bsse
32 USE input_constants, ONLY: do_qs
39 USE kinds, ONLY: default_string_length,&
40 dp
44 USE qs_energy, ONLY: qs_energies
46 USE qs_environment, ONLY: qs_init
51 USE string_utilities, ONLY: compress
52#include "./base/base_uses.f90"
53
54 IMPLICIT NONE
55 PRIVATE
56
57 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
58 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'bsse'
59
60 PUBLIC :: do_bsse_calculation
61
62CONTAINS
63
64! **************************************************************************************************
65!> \brief Perform an COUNTERPOISE CORRECTION (BSSE)
66!> For a 2-body system the correction scheme can be represented as:
67!>
68!> E_{AB}^{2} = E_{AB}(AB) - E_A(AB) - E_B(AB) [BSSE-corrected interaction energy]
69!> E_{AB}^{2,uncorr} = E_{AB}(AB) - E_A(A) - E_B(B)
70!> E_{AB}^{CP} = E_{AB}(AB) + [ E_A(A) - E_A(AB) ] + [ E_B(B) - E_B(AB) ]
71!> [CP-corrected total energy of AB]
72!> \param force_env ...
73!> \param globenv ...
74!> \par History
75!> 06.2005 created [tlaino]
76!> \author Teodoro Laino
77! **************************************************************************************************
78 SUBROUTINE do_bsse_calculation(force_env, globenv)
79 TYPE(force_env_type), POINTER :: force_env
80 TYPE(global_environment_type), POINTER :: globenv
81
82 INTEGER :: i, istart, k, num_of_conf, num_of_frag
83 INTEGER, DIMENSION(:, :), POINTER :: conf
84 LOGICAL :: explicit, should_stop
85 REAL(kind=dp), DIMENSION(:), POINTER :: em
86 TYPE(cp_logger_type), POINTER :: logger
87 TYPE(section_vals_type), POINTER :: bsse_section, fragment_energies_section, &
88 n_frags, root_section
89
90 NULLIFY (bsse_section, n_frags, em, conf)
91 logger => cp_get_default_logger()
92 root_section => force_env%root_section
93 bsse_section => section_vals_get_subs_vals(force_env%force_env_section, "BSSE")
94 n_frags => section_vals_get_subs_vals(bsse_section, "FRAGMENT")
95 CALL section_vals_get(n_frags, n_repetition=num_of_frag)
96
97 ! Number of configurations
98 num_of_conf = 0
99 DO k = 1, num_of_frag
100 num_of_conf = num_of_conf + fact(num_of_frag)/(fact(k)*fact(num_of_frag - k))
101 END DO
102 ALLOCATE (conf(num_of_conf, num_of_frag))
103 ALLOCATE (em(num_of_conf))
104 CALL gen_nbody_conf(num_of_frag, conf)
105
106 should_stop = .false.
107 istart = 0
108 fragment_energies_section => section_vals_get_subs_vals(bsse_section, "FRAGMENT_ENERGIES")
109 CALL section_vals_get(fragment_energies_section, explicit=explicit)
110 IF (explicit) THEN
111 CALL section_vals_val_get(fragment_energies_section, "_DEFAULT_KEYWORD_", n_rep_val=istart)
112 DO i = 1, istart
113 CALL section_vals_val_get(fragment_energies_section, "_DEFAULT_KEYWORD_", r_val=em(i), &
114 i_rep_val=i)
115 END DO
116 END IF
117 ! Setup the iteration level for BSSE
118 CALL cp_add_iter_level(logger%iter_info, "BSSE")
119 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=istart)
120
121 ! Evaluating the energy of the N-body cluster terms
122 DO i = istart + 1, num_of_conf
123 CALL cp_iterate(logger%iter_info, last=(i == num_of_conf), iter_nr=i)
124 CALL eval_bsse_energy(conf(i, :), em(i), force_env, n_frags, &
125 root_section, globenv, should_stop)
126 IF (should_stop) EXIT
127
128 ! If no signal was received in the inner loop let's check also at this stage
129 CALL external_control(should_stop, "BSSE", globenv=globenv)
130 IF (should_stop) EXIT
131
132 ! Dump Restart info only if the calculation of the energy of a configuration
133 ! ended nicely..
134 CALL section_vals_val_set(fragment_energies_section, "_DEFAULT_KEYWORD_", r_val=em(i), &
135 i_rep_val=i)
136 CALL write_bsse_restart(bsse_section, root_section)
137 END DO
138 IF (.NOT. should_stop) CALL dump_bsse_results(conf, em, num_of_frag, bsse_section)
139 CALL cp_rm_iter_level(logger%iter_info, "BSSE")
140 DEALLOCATE (em)
141 DEALLOCATE (conf)
142
143 END SUBROUTINE do_bsse_calculation
144
145! **************************************************************************************************
146!> \brief Evaluate the N-body energy contribution to the BSSE evaluation
147!> \param conf ...
148!> \param Em ...
149!> \param force_env ...
150!> \param n_frags ...
151!> \param root_section ...
152!> \param globenv ...
153!> \param should_stop ...
154!> \par History
155!> 07.2005 created [tlaino]
156!> \author Teodoro Laino
157! **************************************************************************************************
158 SUBROUTINE eval_bsse_energy(conf, Em, force_env, n_frags, root_section, &
159 globenv, should_stop)
160 INTEGER, DIMENSION(:), INTENT(IN) :: conf
161 REAL(kind=dp), INTENT(OUT) :: em
162 TYPE(force_env_type), POINTER :: force_env
163 TYPE(section_vals_type), POINTER :: n_frags, root_section
164 TYPE(global_environment_type), POINTER :: globenv
165 LOGICAL, INTENT(OUT) :: should_stop
166
167 INTEGER :: i, j, k, num_of_sub_conf, num_of_sub_frag
168 INTEGER, DIMENSION(:, :), POINTER :: conf_loc
169 REAL(kind=dp) :: my_energy
170 REAL(kind=dp), DIMENSION(:), POINTER :: em_loc
171
172 NULLIFY (conf_loc, em_loc)
173 should_stop = .false.
174 ! Count the number of subconfiguration to evaluate..
175 num_of_sub_frag = count(conf == 1)
176 num_of_sub_conf = 0
177 IF (num_of_sub_frag == 1) THEN
178 CALL eval_bsse_energy_low(force_env, conf, conf, n_frags, root_section, globenv, em)
179 ELSE
180 my_energy = 0.0_dp
181 DO k = 1, num_of_sub_frag
182 num_of_sub_conf = num_of_sub_conf + &
183 fact(num_of_sub_frag)/(fact(k)*fact(num_of_sub_frag - k))
184 END DO
185 ALLOCATE (conf_loc(num_of_sub_conf, num_of_sub_frag))
186 ALLOCATE (em_loc(num_of_sub_conf))
187 em_loc = 0.0_dp
188 CALL gen_nbody_conf(num_of_sub_frag, conf_loc)
189 CALL make_plan_conf(conf, conf_loc)
190 DO i = 1, num_of_sub_conf
191 CALL eval_bsse_energy_low(force_env, conf, conf_loc(i, :), n_frags, &
192 root_section, globenv, em_loc(i))
193 CALL external_control(should_stop, "BSSE", globenv=globenv)
194 IF (should_stop) EXIT
195 END DO
196 ! Energy
197 k = count(conf == 1)
198 DO i = 1, num_of_sub_conf
199 j = count(conf_loc(i, :) == 1)
200 my_energy = my_energy + (-1.0_dp)**(k + j)*em_loc(i)
201 END DO
202 em = my_energy
203 DEALLOCATE (em_loc)
204 DEALLOCATE (conf_loc)
205 END IF
206
207 END SUBROUTINE eval_bsse_energy
208
209! **************************************************************************************************
210!> \brief Evaluate the N-body energy contribution to the BSSE evaluation
211!> \param force_env ...
212!> \param conf ...
213!> \param conf_loc ...
214!> \param n_frags ...
215!> \param root_section ...
216!> \param globenv ...
217!> \param energy ...
218!> \par History
219!> 07.2005 created [tlaino]
220!> 2014/09/17 made atom list to be read from repeated occurrence of LIST [LTong]
221!> \author Teodoro Laino
222! **************************************************************************************************
223 SUBROUTINE eval_bsse_energy_low(force_env, conf, conf_loc, n_frags, &
224 root_section, globenv, energy)
225 TYPE(force_env_type), POINTER :: force_env
226 INTEGER, DIMENSION(:), INTENT(IN) :: conf, conf_loc
227 TYPE(section_vals_type), POINTER :: n_frags, root_section
228 TYPE(global_environment_type), POINTER :: globenv
229 REAL(kind=dp), INTENT(OUT) :: energy
230
231 CHARACTER(LEN=default_string_length) :: name
232 CHARACTER(len=default_string_length), &
233 DIMENSION(:), POINTER :: atom_type
234 INTEGER :: i, ir, isize, j, k, method_name_id, &
235 my_targ, n_rep, num_of_frag, old_size, &
236 present_charge, present_multpl
237 INTEGER, DIMENSION(:), POINTER :: atom_index, atom_list, my_conf, tmplist
238 TYPE(cp_subsys_type), POINTER :: subsys
239 TYPE(mp_para_env_type), POINTER :: para_env
240 TYPE(particle_list_type), POINTER :: particles
241 TYPE(section_vals_type), POINTER :: bsse_section, dft_section, &
242 force_env_section, subsys_section
243
244 CALL section_vals_get(n_frags, n_repetition=num_of_frag)
245 cpassert(SIZE(conf) == num_of_frag)
246 NULLIFY (subsys, particles, para_env, atom_index, atom_type, tmplist, &
247 force_env_section)
248 CALL force_env_get(force_env, force_env_section=force_env_section)
249 CALL section_vals_val_get(force_env_section, "METHOD", i_val=method_name_id)
250 bsse_section => section_vals_get_subs_vals(force_env_section, "BSSE")
251 subsys_section => section_vals_get_subs_vals(force_env_section, "SUBSYS")
252 dft_section => section_vals_get_subs_vals(force_env_section, "DFT")
253
254 ALLOCATE (my_conf(SIZE(conf)))
255 my_conf = conf
256 CALL force_env_get(force_env=force_env, subsys=subsys, para_env=para_env)
257 CALL cp_subsys_get(subsys, particles=particles)
258 isize = 0
259 ALLOCATE (atom_index(isize))
260 DO i = 1, num_of_frag
261 IF (conf(i) == 1) THEN
262 !
263 ! Get the list of atoms creating the present fragment
264 !
265 old_size = isize
266 CALL section_vals_val_get(n_frags, "LIST", i_rep_section=i, n_rep_val=n_rep)
267 IF (n_rep /= 0) THEN
268 DO ir = 1, n_rep
269 CALL section_vals_val_get(n_frags, "LIST", i_rep_section=i, i_rep_val=ir, i_vals=tmplist)
270 CALL reallocate(atom_index, 1, isize + SIZE(tmplist))
271 atom_index(isize + 1:isize + SIZE(tmplist)) = tmplist
272 isize = SIZE(atom_index)
273 END DO
274 END IF
275 my_conf(i) = isize - old_size
276 cpassert(conf(i) /= 0)
277 END IF
278 END DO
279 CALL conf_info_setup(present_charge, present_multpl, conf, conf_loc, bsse_section, &
280 dft_section)
281 !
282 ! Get names and modify the ghost ones
283 !
284 ALLOCATE (atom_type(isize))
285 DO j = 1, isize
286 my_targ = atom_index(j)
287 DO k = 1, SIZE(particles%els)
288 CALL get_atomic_kind(particles%els(k)%atomic_kind, atom_list=atom_list, name=name)
289 IF (any(atom_list == my_targ)) EXIT
290 END DO
291 atom_type(j) = name
292 END DO
293 DO i = 1, SIZE(conf_loc)
294 IF (my_conf(i) /= 0 .AND. conf_loc(i) == 0) THEN
295 DO j = sum(my_conf(1:i - 1)) + 1, sum(my_conf(1:i))
296 atom_type(j) = trim(atom_type(j))//"_ghost"
297 END DO
298 END IF
299 END DO
300 CALL dump_bsse_info(atom_index, atom_type, conf, conf_loc, bsse_section, &
301 present_charge, present_multpl)
302 !
303 ! Let's start setting up environments and calculations
304 !
305 energy = 0.0_dp
306 IF (method_name_id == do_qs) THEN
307 block
308 TYPE(qs_environment_type), POINTER :: qs_env
309 TYPE(qs_energy_type), POINTER :: qs_energy
310 TYPE(cp_subsys_type), POINTER :: subsys_loc
311 NULLIFY (subsys_loc)
312 CALL create_small_subsys(subsys_loc, big_subsys=subsys, &
313 small_para_env=para_env, small_cell=subsys%cell, sub_atom_index=atom_index, &
314 sub_atom_kind_name=atom_type, para_env=para_env, &
315 force_env_section=force_env_section, subsys_section=subsys_section)
316
317 ALLOCATE (qs_env)
318 CALL qs_env_create(qs_env, globenv)
319 CALL qs_init(qs_env, para_env, root_section, globenv=globenv, cp_subsys=subsys_loc, &
320 force_env_section=force_env_section, subsys_section=subsys_section, &
321 use_motion_section=.false.)
322 CALL cp_subsys_release(subsys_loc)
323
324 !
325 ! Evaluate Energy
326 !
327 CALL qs_energies(qs_env)
328 CALL get_qs_env(qs_env, energy=qs_energy)
329 energy = qs_energy%total
330 CALL qs_env_release(qs_env)
331 DEALLOCATE (qs_env)
332 END block
333 ELSE
334 cpabort("BSSE calculation is only available for QuickStep method!")
335 END IF
336 DEALLOCATE (atom_index)
337 DEALLOCATE (atom_type)
338 DEALLOCATE (my_conf)
339
340 END SUBROUTINE eval_bsse_energy_low
341
342! **************************************************************************************************
343!> \brief Dumps bsse information (configuration fragment)
344!> \param atom_index ...
345!> \param atom_type ...
346!> \param conf ...
347!> \param conf_loc ...
348!> \param bsse_section ...
349!> \param present_charge ...
350!> \param present_multpl ...
351!> \par History
352!> 07.2005 created [tlaino]
353!> \author Teodoro Laino
354! **************************************************************************************************
355 SUBROUTINE dump_bsse_info(atom_index, atom_type, conf, conf_loc, bsse_section, &
356 present_charge, present_multpl)
357 INTEGER, DIMENSION(:), POINTER :: atom_index
358 CHARACTER(len=default_string_length), &
359 DIMENSION(:), POINTER :: atom_type
360 INTEGER, DIMENSION(:), INTENT(IN) :: conf, conf_loc
361 TYPE(section_vals_type), POINTER :: bsse_section
362 INTEGER, INTENT(IN) :: present_charge, present_multpl
363
364 INTEGER :: i, istat, iw
365 CHARACTER(len=20*SIZE(conf)) :: conf_loc_s, conf_s
366 TYPE(cp_logger_type), POINTER :: logger
367
368 NULLIFY (logger)
369 logger => cp_get_default_logger()
370 iw = cp_print_key_unit_nr(logger, bsse_section, "PRINT%PROGRAM_RUN_INFO", &
371 extension=".log")
372 IF (iw > 0) THEN
373 WRITE (conf_s, fmt="(1000I0)", iostat=istat) conf
374 IF (istat /= 0) conf_s = "exceeded"
375 CALL compress(conf_s, full=.true.)
376 WRITE (conf_loc_s, fmt="(1000I0)", iostat=istat) conf_loc
377 IF (istat /= 0) conf_loc_s = "exceeded"
378 CALL compress(conf_loc_s, full=.true.)
379
380 WRITE (unit=iw, fmt="(/,T2,A)") repeat("-", 79)
381 WRITE (unit=iw, fmt="(T2,A,T80,A)") "-", "-"
382 WRITE (unit=iw, fmt="(T2,A,T5,A,T30,A,T55,A,T80,A)") &
383 "-", "BSSE CALCULATION", "FRAGMENT CONF: "//trim(conf_s), "FRAGMENT SUBCONF: "//trim(conf_loc_s), "-"
384 WRITE (unit=iw, fmt="(T2,A,T30,A,I6,T55,A,I6,T80,A)") "-", "CHARGE =", present_charge, "MULTIPLICITY =", &
385 present_multpl, "-"
386 WRITE (unit=iw, fmt="(T2,A,T80,A)") "-", "-"
387 WRITE (unit=iw, fmt="(T2,A,T20,A,T60,A,T80,A)") "-", "ATOM INDEX", "ATOM NAME", "-"
388 WRITE (unit=iw, fmt="(T2,A,T20,A,T60,A,T80,A)") "-", "----------", "---------", "-"
389 DO i = 1, SIZE(atom_index)
390 WRITE (unit=iw, fmt="(T2,A,T20,I6,T61,A,T80,A)") "-", atom_index(i), trim(atom_type(i)), "-"
391 END DO
392 WRITE (unit=iw, fmt="(T2,A)") repeat("-", 79)
393
394 CALL cp_print_key_finished_output(iw, logger, bsse_section, &
395 "PRINT%PROGRAM_RUN_INFO")
396
397 END IF
398 END SUBROUTINE dump_bsse_info
399
400! **************************************************************************************************
401!> \brief Read modified parameters for configurations
402!> \param present_charge ...
403!> \param present_multpl ...
404!> \param conf ...
405!> \param conf_loc ...
406!> \param bsse_section ...
407!> \param dft_section ...
408!> \par History
409!> 09.2007 created [tlaino]
410!> \author Teodoro Laino - University of Zurich
411! **************************************************************************************************
412 SUBROUTINE conf_info_setup(present_charge, present_multpl, conf, conf_loc, &
413 bsse_section, dft_section)
414 INTEGER, INTENT(OUT) :: present_charge, present_multpl
415 INTEGER, DIMENSION(:), INTENT(IN) :: conf, conf_loc
416 TYPE(section_vals_type), POINTER :: bsse_section, dft_section
417
418 INTEGER :: i, nconf
419 INTEGER, DIMENSION(:), POINTER :: glb_conf, sub_conf
420 LOGICAL :: explicit
421 TYPE(section_vals_type), POINTER :: configurations
422
423 present_charge = 0
424 present_multpl = 0
425 NULLIFY (configurations, glb_conf, sub_conf)
426 ! Loop over all configurations to pick up the right one
427 configurations => section_vals_get_subs_vals(bsse_section, "CONFIGURATION")
428 CALL section_vals_get(configurations, explicit=explicit, n_repetition=nconf)
429 IF (explicit) THEN
430 DO i = 1, nconf
431 CALL section_vals_val_get(configurations, "GLB_CONF", i_rep_section=i, i_vals=glb_conf)
432 IF (SIZE(glb_conf) /= SIZE(conf)) THEN
433 CALL cp_abort(__location__, &
434 "GLB_CONF requires a binary description of the configuration. Number of integer "// &
435 "different from the number of fragments defined!")
436 END IF
437 CALL section_vals_val_get(configurations, "SUB_CONF", i_rep_section=i, i_vals=sub_conf)
438 IF (SIZE(sub_conf) /= SIZE(conf)) THEN
439 CALL cp_abort(__location__, &
440 "SUB_CONF requires a binary description of the configuration. Number of integer "// &
441 "different from the number of fragments defined!")
442 END IF
443 IF (all(conf == glb_conf) .AND. all(conf_loc == sub_conf)) THEN
444 CALL section_vals_val_get(configurations, "CHARGE", i_rep_section=i, &
445 i_val=present_charge)
446 CALL section_vals_val_get(configurations, "MULTIPLICITY", i_rep_section=i, &
447 i_val=present_multpl)
448 END IF
449 END DO
450 END IF
451 ! Setup parameter for this configuration
452 CALL section_vals_val_set(dft_section, "CHARGE", i_val=present_charge)
453 CALL section_vals_val_set(dft_section, "MULTIPLICITY", i_val=present_multpl)
454 END SUBROUTINE conf_info_setup
455
456! **************************************************************************************************
457!> \brief Dumps results
458!> \param conf ...
459!> \param Em ...
460!> \param num_of_frag ...
461!> \param bsse_section ...
462!> \par History
463!> 09.2007 created [tlaino]
464!> \author Teodoro Laino - University of Zurich
465! **************************************************************************************************
466 SUBROUTINE dump_bsse_results(conf, Em, num_of_frag, bsse_section)
467 INTEGER, DIMENSION(:, :), INTENT(IN) :: conf
468 REAL(kind=dp), DIMENSION(:), POINTER :: em
469 INTEGER, INTENT(IN) :: num_of_frag
470 TYPE(section_vals_type), POINTER :: bsse_section
471
472 INTEGER :: i, iw
473 TYPE(cp_logger_type), POINTER :: logger
474
475 NULLIFY (logger)
476 logger => cp_get_default_logger()
477 iw = cp_print_key_unit_nr(logger, bsse_section, "PRINT%PROGRAM_RUN_INFO", &
478 extension=".log")
479
480 IF (iw > 0) THEN
481 WRITE (unit=iw, fmt="(/,T2,A)") repeat("-", 79)
482 WRITE (unit=iw, fmt="(T2,A,T80,A)") "-", "-"
483 WRITE (unit=iw, fmt="(T2,A,T36,A,T80,A)") &
484 "-", "BSSE RESULTS", "-"
485 WRITE (unit=iw, fmt="(T2,A,T80,A)") "-", "-"
486 WRITE (unit=iw, fmt="(T2,A,T20,A,F16.6,T80,A)") "-", "CP-corrected Total energy:", sum(em), "-"
487 WRITE (unit=iw, fmt="(T2,A,T80,A)") "-", "-"
488 DO i = 1, SIZE(conf, 1)
489 IF (i > 1) THEN
490 IF (sum(conf(i - 1, :)) == 1 .AND. sum(conf(i, :)) /= 1) THEN
491 WRITE (unit=iw, fmt="(T2,A,T80,A)") "-", "-"
492 END IF
493 END IF
494 WRITE (unit=iw, fmt="(T2,A,T24,I3,A,F16.6,T80,A)") "-", sum(conf(i, :)), "-body contribution:", em(i), "-"
495 END DO
496 WRITE (unit=iw, fmt="(T2,A,T20,A,F16.6,T80,A)") "-", "BSSE-free interaction energy:", sum(em(num_of_frag + 1:)), "-"
497 WRITE (unit=iw, fmt="(T2,A)") repeat("-", 79)
498 END IF
499
500 CALL cp_print_key_finished_output(iw, logger, bsse_section, &
501 "PRINT%PROGRAM_RUN_INFO")
502
503 END SUBROUTINE dump_bsse_results
504
505! **************************************************************************************************
506!> \brief generate the N-body configuration for the N-body BSSE evaluation
507!> \param Num_of_frag ...
508!> \param conf ...
509!> \par History
510!> 07.2005 created [tlaino]
511!> \author Teodoro Laino
512! **************************************************************************************************
513 SUBROUTINE gen_nbody_conf(Num_of_frag, conf)
514 INTEGER, INTENT(IN) :: num_of_frag
515 INTEGER, DIMENSION(:, :), POINTER :: conf
516
517 INTEGER :: k, my_ind
518
519 my_ind = 0
520 !
521 ! Set up the N-body configurations
522 !
523 conf = 0
524 DO k = 1, num_of_frag
525 CALL build_nbody_conf(1, num_of_frag, conf, k, my_ind)
526 END DO
527 END SUBROUTINE gen_nbody_conf
528
529! **************************************************************************************************
530!> \brief ...
531!> \param ldown ...
532!> \param lup ...
533!> \param conf ...
534!> \param k ...
535!> \param my_ind ...
536! **************************************************************************************************
537 RECURSIVE SUBROUTINE build_nbody_conf(ldown, lup, conf, k, my_ind)
538 INTEGER, INTENT(IN) :: ldown, lup
539 INTEGER, DIMENSION(:, :), POINTER :: conf
540 INTEGER, INTENT(IN) :: k
541 INTEGER, INTENT(INOUT) :: my_ind
542
543 INTEGER :: i, kloc, my_ind0
544
545 kloc = k - 1
546 my_ind0 = my_ind
547 IF (kloc /= 0) THEN
548 DO i = ldown, lup
549 CALL build_nbody_conf(i + 1, lup, conf, kloc, my_ind)
550 conf(my_ind0 + 1:my_ind, i) = 1
551 my_ind0 = my_ind
552 END DO
553 ELSE
554 DO i = ldown, lup
555 my_ind = my_ind + 1
556 conf(my_ind, i) = 1
557 END DO
558 END IF
559 END SUBROUTINE build_nbody_conf
560
561! **************************************************************************************************
562!> \brief ...
563!> \param num ...
564!> \return ...
565! **************************************************************************************************
566 RECURSIVE FUNCTION fact(num) RESULT(my_fact)
567 INTEGER, INTENT(IN) :: num
568 INTEGER :: my_fact
569
570 IF (num <= 1) THEN
571 my_fact = 1
572 ELSE
573 my_fact = num*fact(num - 1)
574 END IF
575 END FUNCTION fact
576
577! **************************************************************************************************
578!> \brief ...
579!> \param main_conf ...
580!> \param conf ...
581! **************************************************************************************************
582 SUBROUTINE make_plan_conf(main_conf, conf)
583 INTEGER, DIMENSION(:), INTENT(IN) :: main_conf
584 INTEGER, DIMENSION(:, :), POINTER :: conf
585
586 INTEGER :: i, ind
587 INTEGER, DIMENSION(:, :), POINTER :: tmp_conf
588
589 ALLOCATE (tmp_conf(SIZE(conf, 1), SIZE(main_conf)))
590 tmp_conf = 0
591 ind = 0
592 DO i = 1, SIZE(main_conf)
593 IF (main_conf(i) /= 0) THEN
594 ind = ind + 1
595 tmp_conf(:, i) = conf(:, ind)
596 END IF
597 END DO
598 DEALLOCATE (conf)
599 ALLOCATE (conf(SIZE(tmp_conf, 1), SIZE(tmp_conf, 2)))
600 conf = tmp_conf
601 DEALLOCATE (tmp_conf)
602
603 END SUBROUTINE make_plan_conf
604
605! **************************************************************************************************
606!> \brief Writes restart for BSSE calculations
607!> \param bsse_section ...
608!> \param root_section ...
609!> \par History
610!> 01.2008 created [tlaino]
611!> \author Teodoro Laino
612! **************************************************************************************************
613 SUBROUTINE write_bsse_restart(bsse_section, root_section)
614
615 TYPE(section_vals_type), POINTER :: bsse_section, root_section
616
617 INTEGER :: ires
618 TYPE(cp_logger_type), POINTER :: logger
619
620 logger => cp_get_default_logger()
621 ires = cp_print_key_unit_nr(logger, bsse_section, "PRINT%RESTART", &
622 extension=".restart", do_backup=.false., file_position="REWIND")
623
624 IF (ires > 0) THEN
625 CALL write_restart_header(ires)
626 CALL section_vals_write(root_section, unit_nr=ires, hide_root=.true.)
627 END IF
628
629 CALL cp_print_key_finished_output(ires, logger, bsse_section, &
630 "PRINT%RESTART")
631
632 END SUBROUTINE write_bsse_restart
633
634END MODULE bsse
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.
Module to perform a counterpoise correction (BSSE)
Definition bsse.F:14
subroutine, public do_bsse_calculation(force_env, globenv)
Perform an COUNTERPOISE CORRECTION (BSSE) For a 2-body system the correction scheme can be represente...
Definition bsse.F:79
some minimal info about CP2K, including its version and license
Definition cp2k_info.F:22
subroutine, public write_restart_header(iunit)
Writes the header for the restart file.
Definition cp2k_info.F:404
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
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,...
subroutine, public cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
subroutine, public cp_rm_iter_level(iteration_info, level_name, n_rlevel_att)
Removes an iteration level.
subroutine, public cp_add_iter_level(iteration_info, level_name, n_rlevel_new)
Adds an iteration level.
Initialize a small environment for a particular calculation.
subroutine, public create_small_subsys(small_subsys, big_subsys, small_cell, small_para_env, sub_atom_index, sub_atom_kind_name, para_env, force_env_section, subsys_section, ignore_outside_box)
updates the molecule information of the given subsys
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_release(subsys)
releases a subsys (see doc/ReferenceCounting.html)
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell)
returns information about various attributes of the given subsys
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
Define type storing the global information of a run. Keep the amount of stored data small....
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_qs
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_set(section_vals, keyword_name, i_rep_section, i_rep_val, val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
sets the requested value
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
recursive subroutine, public section_vals_write(section_vals, unit_nr, hide_root, hide_defaults)
writes the values in the given section in a way that is suitable to the automatic parsing
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_string_length
Definition kinds.F:57
Utility routines for the memory handling.
Interface to the message passing library MPI.
represent a simple array based list of the given type
Perform a QUICKSTEP wavefunction optimization (single point)
Definition qs_energy.F:14
subroutine, public qs_energies(qs_env, consistent_energies, calc_forces)
Driver routine for QUICKSTEP single point wavefunction optimization.
Definition qs_energy.F:70
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.
subroutine, public qs_env_release(qs_env)
releases the given qs_env (see doc/ReferenceCounting.html)
subroutine, public qs_env_create(qs_env, globenv)
allocates and intitializes a qs_env
subroutine, public qs_init(qs_env, para_env, root_section, globenv, cp_subsys, kpoint_env, qmmm, qmmm_env_qm, force_env_section, subsys_section, use_motion_section, silent, multip, charge)
Read the input and the database files for the setup of the QUICKSTEP environment.
Utilities for string manipulations.
subroutine, public compress(string, full)
Eliminate multiple space characters in a string. If full is .TRUE., then all spaces are eliminated.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represents a system: atoms, molecules, their pos,vel,...
wrapper to abstract the force evaluation of the various methods
contains the initially parsed file and the initial parallel environment
stores all the informations relevant to an mpi environment