(git:1145456)
Loading...
Searching...
No Matches
f77_interface.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 interface to use cp2k as library
10!> \note
11!> useful additions for the future would be:
12!> - string(path) based set/get of simple values (to change the new
13!> input during the run and extract more data (energy types for example).
14!> - set/get of a subset of atoms
15!> \par History
16!> 07.2004 created [fawzi]
17!> 11.2004 parallel version [fawzi]
18!> \author fawzi & Johanna
19! **************************************************************************************************
21 USE base_hooks, ONLY: cp_abort_hook,&
26 USE cell_methods, ONLY: init_cell
27 USE cell_types, ONLY: cell_type
29 USE cp_dbcsr_api, ONLY: dbcsr_finalize_lib,&
30 dbcsr_init_lib
36 USE cp_log_handling, ONLY: &
49 USE dbm_api, ONLY: dbm_library_finalize,&
51 USE eip_environment, ONLY: eip_init
56 USE environment, ONLY: cp2k_finalize,&
57 cp2k_init,&
58 cp2k_read,&
63 USE force_env_types, ONLY: &
67 USE fp_types, ONLY: fp_env_create,&
76 USE input_constants, ONLY: &
80 USE input_cp2k_read, ONLY: empty_initial_variables,&
86 USE input_section_types, ONLY: &
91 USE ipi_environment, ONLY: ipi_init
93 USE kinds, ONLY: default_path_length,&
95 dp
96 USE machine, ONLY: default_output_unit,&
97 m_chdir,&
98 m_getcwd,&
100 USE message_passing, ONLY: mp_comm_type,&
110 USE mp_perf_env, ONLY: add_mp_perf_env,&
116 USE nnp_environment, ONLY: nnp_init
122 USE pw_fpga, ONLY: pw_fpga_finalize,&
124 USE pw_gpu, ONLY: pw_gpu_finalize,&
130 USE qmmm_types, ONLY: qmmm_env_type
132 USE qmmmx_types, ONLY: qmmmx_env_type
133 USE qs_environment, ONLY: qs_init
143 USE timings, ONLY: add_timer_env,&
150 USE virial_types, ONLY: virial_type
151 USE xc_gauxc_interface, ONLY: cp_gauxc_status_type,&
152 gauxc_check_status,&
153 gauxc_finalize,&
154 gauxc_init
155#include "./base/base_uses.f90"
156
157 IMPLICIT NONE
158 PRIVATE
159
160 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
161 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'f77_interface'
162
163! **************************************************************************************************
164 TYPE f_env_p_type
165 TYPE(f_env_type), POINTER :: f_env => null()
166 END TYPE f_env_p_type
167
168! **************************************************************************************************
170 INTEGER :: id_nr = 0
171 TYPE(force_env_type), POINTER :: force_env => null()
172 TYPE(cp_logger_type), POINTER :: logger => null()
173 TYPE(timer_env_type), POINTER :: timer_env => null()
174 TYPE(mp_perf_env_type), POINTER :: mp_perf_env => null()
175 CHARACTER(len=default_path_length) :: my_path = "", old_path = ""
176 END TYPE f_env_type
177
178 TYPE(f_env_p_type), DIMENSION(:), POINTER, SAVE :: f_envs
179 TYPE(mp_para_env_type), POINTER, SAVE :: default_para_env
180 LOGICAL, SAVE :: module_initialized = .false.
181 INTEGER, SAVE :: last_f_env_id = 0, n_f_envs = 0
182
183 PUBLIC :: default_para_env
184 PUBLIC :: init_cp2k, finalize_cp2k
190 set_vel, set_cell, get_cell, get_qmmm_cell, get_result_r1
191CONTAINS
192
193! **************************************************************************************************
194!> \brief returns the position of the force env corresponding to the given id
195!> \param env_id the id of the requested environment
196!> \return ...
197!> \author fawzi
198!> \note
199!> private utility function
200! **************************************************************************************************
201 FUNCTION get_pos_of_env(env_id) RESULT(res)
202 INTEGER, INTENT(in) :: env_id
203 INTEGER :: res
204
205 INTEGER :: env_pos, isub
206
207 env_pos = -1
208 DO isub = 1, n_f_envs
209 IF (f_envs(isub)%f_env%id_nr == env_id) THEN
210 env_pos = isub
211 END IF
212 END DO
213 res = env_pos
214 END FUNCTION get_pos_of_env
215
216! **************************************************************************************************
217!> \brief initializes cp2k, needs to be called once before using any of the
218!> other functions when using cp2k as library
219!> \param init_mpi if the mpi environment should be initialized
220!> \param ierr returns a number different from 0 if there was an error
221!> \param mpi_comm an existing mpi communicator (if not given mp_comm_world
222!> will be used)
223!> \author fawzi
224! **************************************************************************************************
225 SUBROUTINE init_cp2k(init_mpi, ierr, mpi_comm)
226 LOGICAL, INTENT(in) :: init_mpi
227 INTEGER, INTENT(out) :: ierr
228 TYPE(mp_comm_type), INTENT(in), OPTIONAL :: mpi_comm
229
230 INTEGER :: offload_device_count, unit_nr
231 INTEGER, POINTER :: active_device_id
232 INTEGER, TARGET :: offload_chosen_device
233 TYPE(cp_gauxc_status_type) :: gauxc_status
234 TYPE(cp_logger_type), POINTER :: logger
235
236 IF (.NOT. module_initialized) THEN
237 ! install error handler hooks
239
240 ! install timming handler hooks
242
243 ! Initialise preconnection list
245
246 ! get runtime information
247 CALL get_runtime_info()
248
249 ! Intialize CUDA/HIP before MPI
250 ! Needed for HIP on ALPS & LUMI
251 CALL offload_init()
252
253 ! re-create the para_env and log with correct (reordered) ranks
254 ALLOCATE (default_para_env)
255 IF (init_mpi) THEN
256 ! get the default system wide communicator
258 ELSE
259 IF (PRESENT(mpi_comm)) THEN
260 default_para_env = mpi_comm
261 ELSE
263 END IF
264 END IF
265
267 CALL add_mp_perf_env()
268 CALL add_timer_env()
269
270 IF (default_para_env%is_source()) THEN
271 unit_nr = default_output_unit
272 ELSE
273 unit_nr = -1
274 END IF
275 NULLIFY (logger)
276
277 CALL cp_logger_create(logger, para_env=default_para_env, &
278 default_global_unit_nr=unit_nr, &
279 close_global_unit_on_dealloc=.false.)
280 CALL cp_add_default_logger(logger)
281 CALL cp_logger_release(logger)
282
283 ALLOCATE (f_envs(0))
284 module_initialized = .true.
285 ierr = 0
286
287 ! Initialize mathematical constants
289
290 ! Init the bibliography
291 CALL add_all_references()
292
293 NULLIFY (active_device_id)
294 offload_device_count = offload_get_device_count()
295
296 ! Select active offload device when available.
297 IF (offload_device_count > 0) THEN
298 offload_chosen_device = mod(default_para_env%mepos, offload_device_count)
299 CALL offload_set_chosen_device(offload_chosen_device)
300 active_device_id => offload_chosen_device
301 END IF
302
303 ! Initialize the DBCSR configuration
304 ! Attach the time handler hooks to DBCSR
305 CALL dbcsr_init_lib(default_para_env%get_handle(), timeset_hook, timestop_hook, &
306 cp_abort_hook, cp_warn_hook, io_unit=unit_nr, &
307 accdrv_active_device_id=active_device_id)
308#if defined(__parallel)
309 CALL gauxc_init(default_para_env%get_handle(), gauxc_status)
310#else
311 CALL gauxc_init(status=gauxc_status)
312#endif
313 CALL gauxc_check_status(gauxc_status)
314 CALL pw_fpga_init()
315 CALL pw_gpu_init()
316 CALL grid_library_init()
317 CALL dbm_library_init()
318 ELSE
319 ierr = cp_failure_level
320 END IF
321
322 !sample peak memory
323 CALL m_memory()
324
325 END SUBROUTINE init_cp2k
326
327! **************************************************************************************************
328!> \brief cleanup after you have finished using this interface
329!> \param finalize_mpi if the mpi environment should be finalized
330!> \param ierr returns a number different from 0 if there was an error
331!> \author fawzi
332! **************************************************************************************************
333 SUBROUTINE finalize_cp2k(finalize_mpi, ierr)
334 LOGICAL, INTENT(in) :: finalize_mpi
335 INTEGER, INTENT(out) :: ierr
336
337 INTEGER :: ienv
338 TYPE(cp_gauxc_status_type) :: gauxc_status
339
340!sample peak memory
341
342 CALL m_memory()
343
344 IF (.NOT. module_initialized) THEN
345 ierr = cp_failure_level
346 ELSE
347 DO ienv = n_f_envs, 1, -1
348 CALL destroy_force_env(f_envs(ienv)%f_env%id_nr, ierr=ierr)
349 cpassert(ierr == 0)
350 END DO
351 DEALLOCATE (f_envs)
352
353 ! Finalize libraries (Offload)
356 CALL pw_gpu_finalize()
357 CALL pw_fpga_finalize()
359 CALL gauxc_finalize(gauxc_status)
360 CALL gauxc_check_status(gauxc_status)
361 ! Finalize the DBCSR library
362 CALL dbcsr_finalize_lib()
363
364 ! Finalize DLA-Future and pika runtime; if already finalized does nothing
366 CALL cp_dlaf_finalize()
367
370
371 ! Deallocate the bibliography
373 CALL rm_timer_env()
374 CALL rm_mp_perf_env()
377 IF (finalize_mpi) THEN
378 CALL mp_world_finalize()
379 END IF
380
381 ierr = 0
382 END IF
383 END SUBROUTINE finalize_cp2k
384
385! **************************************************************************************************
386!> \brief deallocates a f_env
387!> \param f_env the f_env to deallocate
388!> \author fawzi
389! **************************************************************************************************
390 RECURSIVE SUBROUTINE f_env_dealloc(f_env)
391 TYPE(f_env_type), POINTER :: f_env
392
393 INTEGER :: ierr
394
395 cpassert(ASSOCIATED(f_env))
396 CALL force_env_release(f_env%force_env)
397 CALL cp_logger_release(f_env%logger)
398 CALL timer_env_release(f_env%timer_env)
399 CALL mp_perf_env_release(f_env%mp_perf_env)
400 IF (f_env%old_path /= f_env%my_path) THEN
401 CALL m_chdir(f_env%old_path, ierr)
402 cpassert(ierr == 0)
403 END IF
404 END SUBROUTINE f_env_dealloc
405
406! **************************************************************************************************
407!> \brief createates a f_env
408!> \param f_env the f_env to createate
409!> \param force_env the force_environment to be stored
410!> \param timer_env the timer env to be stored
411!> \param mp_perf_env the mp performance environment to be stored
412!> \param id_nr ...
413!> \param logger ...
414!> \param old_dir ...
415!> \author fawzi
416! **************************************************************************************************
417 SUBROUTINE f_env_create(f_env, force_env, timer_env, mp_perf_env, id_nr, logger, old_dir)
418 TYPE(f_env_type), POINTER :: f_env
419 TYPE(force_env_type), POINTER :: force_env
420 TYPE(timer_env_type), POINTER :: timer_env
421 TYPE(mp_perf_env_type), POINTER :: mp_perf_env
422 INTEGER, INTENT(in) :: id_nr
423 TYPE(cp_logger_type), POINTER :: logger
424 CHARACTER(len=*), INTENT(in) :: old_dir
425
426 ALLOCATE (f_env)
427 f_env%force_env => force_env
428 CALL force_env_retain(f_env%force_env)
429 f_env%logger => logger
430 CALL cp_logger_retain(logger)
431 f_env%timer_env => timer_env
432 CALL timer_env_retain(f_env%timer_env)
433 f_env%mp_perf_env => mp_perf_env
434 CALL mp_perf_env_retain(f_env%mp_perf_env)
435 f_env%id_nr = id_nr
436 CALL m_getcwd(f_env%my_path)
437 f_env%old_path = old_dir
438 END SUBROUTINE f_env_create
439
440! **************************************************************************************************
441!> \brief ...
442!> \param f_env_id ...
443!> \param f_env ...
444! **************************************************************************************************
445 SUBROUTINE f_env_get_from_id(f_env_id, f_env)
446 INTEGER, INTENT(in) :: f_env_id
447 TYPE(f_env_type), POINTER :: f_env
448
449 INTEGER :: f_env_pos
450
451 NULLIFY (f_env)
452 f_env_pos = get_pos_of_env(f_env_id)
453 IF (f_env_pos < 1) THEN
454 cpabort("invalid env_id "//cp_to_string(f_env_id))
455 ELSE
456 f_env => f_envs(f_env_pos)%f_env
457 END IF
458
459 END SUBROUTINE f_env_get_from_id
460
461! **************************************************************************************************
462!> \brief adds the default environments of the f_env to the stack of the
463!> defaults, and returns a new error and sets failure to true if
464!> something went wrong
465!> \param f_env_id the f_env from where to take the defaults
466!> \param f_env will contain the f_env corresponding to f_env_id
467!> \param handle ...
468!> \author fawzi
469!> \note
470!> The following routines need to be synchronized wrt. adding/removing
471!> of the default environments (logging, performance,error):
472!> environment:cp2k_init, environment:cp2k_finalize,
473!> f77_interface:f_env_add_defaults, f77_interface:f_env_rm_defaults,
474!> f77_interface:create_force_env, f77_interface:destroy_force_env
475! **************************************************************************************************
476 SUBROUTINE f_env_add_defaults(f_env_id, f_env, handle)
477 INTEGER, INTENT(in) :: f_env_id
478 TYPE(f_env_type), POINTER :: f_env
479 INTEGER, INTENT(out), OPTIONAL :: handle
480
481 INTEGER :: f_env_pos, ierr
482 TYPE(cp_logger_type), POINTER :: logger
483
484 NULLIFY (f_env)
485 f_env_pos = get_pos_of_env(f_env_id)
486 IF (f_env_pos < 1) THEN
487 cpabort("invalid env_id "//cp_to_string(f_env_id))
488 ELSE
489 f_env => f_envs(f_env_pos)%f_env
490 logger => f_env%logger
491 cpassert(ASSOCIATED(logger))
492 CALL m_getcwd(f_env%old_path)
493 IF (f_env%old_path /= f_env%my_path) THEN
494 CALL m_chdir(trim(f_env%my_path), ierr)
495 cpassert(ierr == 0)
496 END IF
497 CALL add_mp_perf_env(f_env%mp_perf_env)
498 CALL add_timer_env(f_env%timer_env)
499 CALL cp_add_default_logger(logger)
500 IF (PRESENT(handle)) handle = cp_default_logger_stack_size()
501 END IF
502 END SUBROUTINE f_env_add_defaults
503
504! **************************************************************************************************
505!> \brief removes the default environments of the f_env to the stack of the
506!> defaults, and sets ierr accordingly to the failuers stored in error
507!> It also releases the error
508!> \param f_env the f_env from where to take the defaults
509!> \param ierr variable that will be set to a number different from 0 if
510!> error contains an error (otherwise it will be set to 0)
511!> \param handle ...
512!> \author fawzi
513!> \note
514!> The following routines need to be synchronized wrt. adding/removing
515!> of the default environments (logging, performance,error):
516!> environment:cp2k_init, environment:cp2k_finalize,
517!> f77_interface:f_env_add_defaults, f77_interface:f_env_rm_defaults,
518!> f77_interface:create_force_env, f77_interface:destroy_force_env
519! **************************************************************************************************
520 SUBROUTINE f_env_rm_defaults(f_env, ierr, handle)
521 TYPE(f_env_type), POINTER :: f_env
522 INTEGER, INTENT(out), OPTIONAL :: ierr
523 INTEGER, INTENT(in), OPTIONAL :: handle
524
525 INTEGER :: ierr2
526 TYPE(cp_logger_type), POINTER :: d_logger, logger
527 TYPE(mp_perf_env_type), POINTER :: d_mp_perf_env
528 TYPE(timer_env_type), POINTER :: d_timer_env
529
530 IF (ASSOCIATED(f_env)) THEN
531 IF (PRESENT(handle)) THEN
532 cpassert(handle == cp_default_logger_stack_size())
533 END IF
534
535 logger => f_env%logger
536 d_logger => cp_get_default_logger()
537 d_timer_env => get_timer_env()
538 d_mp_perf_env => get_mp_perf_env()
539 cpassert(ASSOCIATED(logger))
540 cpassert(ASSOCIATED(d_logger))
541 cpassert(ASSOCIATED(d_timer_env))
542 cpassert(ASSOCIATED(d_mp_perf_env))
543 cpassert(ASSOCIATED(logger, d_logger))
544 ! CPASSERT(ASSOCIATED(d_timer_env, f_env%timer_env))
545 cpassert(ASSOCIATED(d_mp_perf_env, f_env%mp_perf_env))
546 IF (f_env%old_path /= f_env%my_path) THEN
547 CALL m_chdir(trim(f_env%old_path), ierr2)
548 cpassert(ierr2 == 0)
549 END IF
550 IF (PRESENT(ierr)) THEN
551 ierr = 0
552 END IF
554 CALL rm_timer_env()
555 CALL rm_mp_perf_env()
556 ELSE
557 IF (PRESENT(ierr)) THEN
558 ierr = 0
559 END IF
560 END IF
561 END SUBROUTINE f_env_rm_defaults
562
563! **************************************************************************************************
564!> \brief creates a new force environment using the given input, and writing
565!> the output to the given output unit
566!> \param new_env_id will contain the id of the newly created environment
567!> \param input_declaration ...
568!> \param input_path where to read the input (if the input is given it can
569!> a virtual path)
570!> \param output_path filename (or name of the unit) for the output
571!> \param mpi_comm the mpi communicator to be used for this environment
572!> it will not be freed when you get rid of the force_env
573!> \param output_unit if given it should be the unit for the output
574!> and no file is open (should be valid on the processor with rank 0)
575!> \param owns_out_unit if the output unit should be closed upon destroing
576!> of the force_env (defaults to true if not default_output_unit)
577!> \param input the parsed input, if given and valid it is used
578!> instead of parsing from file
579!> \param ierr will return a number different from 0 if there was an error
580!> \param work_dir ...
581!> \param initial_variables key-value list of initial preprocessor variables
582!> \author fawzi
583!> \note
584!> The following routines need to be synchronized wrt. adding/removing
585!> of the default environments (logging, performance,error):
586!> environment:cp2k_init, environment:cp2k_finalize,
587!> f77_interface:f_env_add_defaults, f77_interface:f_env_rm_defaults,
588!> f77_interface:create_force_env, f77_interface:destroy_force_env
589! **************************************************************************************************
590 RECURSIVE SUBROUTINE create_force_env(new_env_id, input_declaration, input_path, &
591 output_path, mpi_comm, output_unit, owns_out_unit, &
592 input, ierr, work_dir, initial_variables)
593 INTEGER, INTENT(out) :: new_env_id
594 TYPE(section_type), POINTER :: input_declaration
595 CHARACTER(len=*), INTENT(in) :: input_path
596 CHARACTER(len=*), INTENT(in), OPTIONAL :: output_path
597
598 CLASS(mp_comm_type), INTENT(IN), OPTIONAL :: mpi_comm
599 INTEGER, INTENT(in), OPTIONAL :: output_unit
600 LOGICAL, INTENT(in), OPTIONAL :: owns_out_unit
601 TYPE(section_vals_type), OPTIONAL, POINTER :: input
602 INTEGER, INTENT(out), OPTIONAL :: ierr
603 CHARACTER(len=*), INTENT(in), OPTIONAL :: work_dir
604 CHARACTER(len=*), DIMENSION(:, :), OPTIONAL :: initial_variables
605
606 CHARACTER(len=*), PARAMETER :: routinen = 'create_force_env'
607
608 CHARACTER(len=default_path_length) :: old_dir, wdir
609 INTEGER :: handle, i, ierr2, iforce_eval, isubforce_eval, k, method_name_id, my_group, &
610 nforce_eval, ngroups, nsubforce_size, unit_nr
611 INTEGER, DIMENSION(:), POINTER :: group_distribution, i_force_eval, &
612 lgroup_distribution
613 LOGICAL :: check, do_qmmm_force_mixing, multiple_subsys, my_owns_out_unit, &
614 use_motion_section, use_multiple_para_env
615 TYPE(cp_logger_type), POINTER :: logger, my_logger
616 TYPE(mp_para_env_type), POINTER :: my_para_env, para_env
617 TYPE(eip_environment_type), POINTER :: eip_env
618 TYPE(embed_env_type), POINTER :: embed_env
619 TYPE(enumeration_type), POINTER :: enum
620 TYPE(f_env_p_type), DIMENSION(:), POINTER :: f_envs_old
621 TYPE(force_env_type), POINTER :: force_env, my_force_env
622 TYPE(fp_type), POINTER :: fp_env
623 TYPE(global_environment_type), POINTER :: globenv
624 TYPE(ipi_environment_type), POINTER :: ipi_env
625 TYPE(keyword_type), POINTER :: keyword
626 TYPE(meta_env_type), POINTER :: meta_env
627 TYPE(mixed_environment_type), POINTER :: mixed_env
628 TYPE(mp_perf_env_type), POINTER :: mp_perf_env
629 TYPE(nnp_type), POINTER :: nnp_env
630 TYPE(pwdft_environment_type), POINTER :: pwdft_env
631 TYPE(qmmm_env_type), POINTER :: qmmm_env
632 TYPE(qmmmx_env_type), POINTER :: qmmmx_env
633 TYPE(qs_environment_type), POINTER :: qs_env
634 TYPE(section_type), POINTER :: section
635 TYPE(section_vals_type), POINTER :: fe_section, force_env_section, force_env_sections, &
636 fp_section, input_file, qmmm_section, qmmmx_section, root_section, subsys_section, &
637 wrk_section
638 TYPE(timer_env_type), POINTER :: timer_env
639
640 cpassert(ASSOCIATED(input_declaration))
641 NULLIFY (para_env, force_env, timer_env, mp_perf_env, globenv, meta_env, &
642 fp_env, eip_env, pwdft_env, mixed_env, qs_env, qmmm_env, embed_env)
643 new_env_id = -1
644 IF (PRESENT(mpi_comm)) THEN
645 ALLOCATE (para_env)
646 para_env = mpi_comm
647 ELSE
648 para_env => default_para_env
649 CALL para_env%retain()
650 END IF
651
652 CALL timeset(routinen, handle)
653
654 CALL m_getcwd(old_dir)
655 wdir = old_dir
656 IF (PRESENT(work_dir)) THEN
657 IF (work_dir /= " ") THEN
658 CALL m_chdir(work_dir, ierr2)
659 IF (ierr2 /= 0) THEN
660 IF (PRESENT(ierr)) ierr = ierr2
661 RETURN
662 END IF
663 wdir = work_dir
664 END IF
665 END IF
666
667 IF (PRESENT(output_unit)) THEN
668 unit_nr = output_unit
669 ELSE
670 IF (para_env%is_source()) THEN
671 IF (output_path == "__STD_OUT__") THEN
672 unit_nr = default_output_unit
673 ELSE
674 CALL open_file(file_name=output_path, &
675 file_status="UNKNOWN", &
676 file_action="WRITE", &
677 file_position="APPEND", &
678 unit_number=unit_nr)
679 END IF
680 ELSE
681 unit_nr = -1
682 END IF
683 END IF
684
685 my_owns_out_unit = unit_nr /= default_output_unit
686 IF (PRESENT(owns_out_unit)) my_owns_out_unit = owns_out_unit
687 CALL globenv_create(globenv)
688 CALL cp2k_init(para_env, output_unit=unit_nr, globenv=globenv, input_file_name=input_path, &
689 wdir=wdir)
690 logger => cp_get_default_logger()
691 ! warning this is dangerous, I did not check that all the subfunctions
692 ! support it, the program might crash upon error
693
694 NULLIFY (input_file)
695 IF (PRESENT(input)) input_file => input
696 IF (.NOT. ASSOCIATED(input_file)) THEN
697 IF (PRESENT(initial_variables)) THEN
698 input_file => read_input(input_declaration, input_path, initial_variables, para_env=para_env)
699 ELSE
700 input_file => read_input(input_declaration, input_path, empty_initial_variables, para_env=para_env)
701 END IF
702 ELSE
703 CALL section_vals_retain(input_file)
704 END IF
705
706 CALL check_cp2k_input(input_declaration, input_file, para_env=para_env, output_unit=unit_nr)
707
708 root_section => input_file
709 CALL section_vals_retain(root_section)
710
711 IF (n_f_envs + 1 > SIZE(f_envs)) THEN
712 f_envs_old => f_envs
713 ALLOCATE (f_envs(n_f_envs + 10))
714 DO i = 1, n_f_envs
715 f_envs(i)%f_env => f_envs_old(i)%f_env
716 END DO
717 DO i = n_f_envs + 1, SIZE(f_envs)
718 NULLIFY (f_envs(i)%f_env)
719 END DO
720 DEALLOCATE (f_envs_old)
721 END IF
722
723 CALL cp2k_read(root_section, para_env, globenv)
724
725 CALL cp2k_setup(root_section, para_env, globenv)
726 ! Group Distribution
727 ALLOCATE (group_distribution(0:para_env%num_pe - 1))
728 group_distribution = 0
729 lgroup_distribution => group_distribution
730 ! Setup all possible force_env
731 force_env_sections => section_vals_get_subs_vals(root_section, "FORCE_EVAL")
732 CALL section_vals_val_get(root_section, "MULTIPLE_FORCE_EVALS%MULTIPLE_SUBSYS", &
733 l_val=multiple_subsys)
734 CALL multiple_fe_list(force_env_sections, root_section, i_force_eval, nforce_eval)
735 ! Enforce the deletion of the subsys (unless not explicitly required)
736 IF (.NOT. multiple_subsys) THEN
737 DO iforce_eval = 2, nforce_eval
738 wrk_section => section_vals_get_subs_vals(force_env_sections, "SUBSYS", &
739 i_rep_section=i_force_eval(iforce_eval))
740 CALL section_vals_remove_values(wrk_section)
741 END DO
742 END IF
743 nsubforce_size = nforce_eval - 1
744 use_multiple_para_env = .false.
745 use_motion_section = .true.
746 DO iforce_eval = 1, nforce_eval
747 NULLIFY (force_env_section, my_force_env, subsys_section)
748 ! Reference subsys from the first ordered force_eval
749 IF (.NOT. multiple_subsys) THEN
750 subsys_section => section_vals_get_subs_vals(force_env_sections, "SUBSYS", &
751 i_rep_section=i_force_eval(1))
752 END IF
753 ! Handling para_env in case of multiple force_eval
754 IF (use_multiple_para_env) THEN
755 ! Check that the order of the force_eval is the correct one
756 CALL section_vals_val_get(force_env_sections, "METHOD", i_val=method_name_id, &
757 i_rep_section=i_force_eval(1))
758 IF ((method_name_id /= do_mixed) .AND. (method_name_id /= do_embed)) THEN
759 CALL cp_abort(__location__, &
760 "In case of multiple force_eval the MAIN force_eval (the first in the list of FORCE_EVAL_ORDER or "// &
761 "the one omitted from that order list) must be a MIXED_ENV type calculation. Please check your "// &
762 "input file and possibly correct the MULTIPLE_FORCE_EVAL%FORCE_EVAL_ORDER. ")
763 END IF
764
765 IF (method_name_id == do_mixed) THEN
766 check = ASSOCIATED(force_env%mixed_env%sub_para_env)
767 cpassert(check)
768 ngroups = force_env%mixed_env%ngroups
769 my_group = lgroup_distribution(para_env%mepos)
770 isubforce_eval = iforce_eval - 1
771 ! If task not allocated on this procs skip setup..
772 IF (modulo(isubforce_eval - 1, ngroups) /= my_group) cycle
773 my_para_env => force_env%mixed_env%sub_para_env(my_group + 1)%para_env
774 my_logger => force_env%mixed_env%sub_logger(my_group + 1)%p
776 CALL cp_add_default_logger(my_logger)
777 END IF
778 IF (method_name_id == do_embed) THEN
779 check = ASSOCIATED(force_env%embed_env%sub_para_env)
780 cpassert(check)
781 ngroups = force_env%embed_env%ngroups
782 my_group = lgroup_distribution(para_env%mepos)
783 isubforce_eval = iforce_eval - 1
784 ! If task not allocated on this procs skip setup..
785 IF (modulo(isubforce_eval - 1, ngroups) /= my_group) cycle
786 my_para_env => force_env%embed_env%sub_para_env(my_group + 1)%para_env
787 my_logger => force_env%embed_env%sub_logger(my_group + 1)%p
789 CALL cp_add_default_logger(my_logger)
790 END IF
791 ELSE
792 my_para_env => para_env
793 END IF
794
795 ! Initialize force_env_section
796 ! No need to allocate one more force_env_section if only 1 force_eval
797 ! is provided.. this is in order to save memory..
798 IF (nforce_eval > 1) THEN
799 CALL section_vals_duplicate(force_env_sections, force_env_section, &
800 i_force_eval(iforce_eval), i_force_eval(iforce_eval))
801 IF (iforce_eval /= 1) use_motion_section = .false.
802 ELSE
803 force_env_section => force_env_sections
804 use_motion_section = .true.
805 END IF
806 CALL section_vals_val_get(force_env_section, "METHOD", i_val=method_name_id)
807
808 IF (method_name_id == do_qmmm) THEN
809 qmmmx_section => section_vals_get_subs_vals(force_env_section, "QMMM%FORCE_MIXING")
810 CALL section_vals_get(qmmmx_section, explicit=do_qmmm_force_mixing)
811 IF (do_qmmm_force_mixing) THEN
812 method_name_id = do_qmmmx
813 END IF ! QMMM Force-Mixing has its own (hidden) method_id
814 END IF
815
816 SELECT CASE (method_name_id)
817 CASE (do_fist)
818 CALL fist_create_force_env(my_force_env, root_section, my_para_env, globenv, &
819 force_env_section=force_env_section, subsys_section=subsys_section, &
820 use_motion_section=use_motion_section)
821
822 CASE (do_qs)
823 ALLOCATE (qs_env)
824 CALL qs_env_create(qs_env, globenv)
825 CALL qs_init(qs_env, my_para_env, root_section, globenv=globenv, force_env_section=force_env_section, &
826 subsys_section=subsys_section, use_motion_section=use_motion_section)
827 CALL force_env_create(my_force_env, root_section, qs_env=qs_env, para_env=my_para_env, globenv=globenv, &
828 force_env_section=force_env_section)
829
830 CASE (do_qmmm)
831 qmmm_section => section_vals_get_subs_vals(force_env_section, "QMMM")
832 ALLOCATE (qmmm_env)
833 CALL qmmm_env_create(qmmm_env, root_section, my_para_env, globenv, &
834 force_env_section, qmmm_section, subsys_section, use_motion_section)
835 CALL force_env_create(my_force_env, root_section, qmmm_env=qmmm_env, para_env=my_para_env, &
836 globenv=globenv, force_env_section=force_env_section)
837
838 CASE (do_qmmmx)
839 ALLOCATE (qmmmx_env)
840 CALL qmmmx_env_create(qmmmx_env, root_section, my_para_env, globenv, &
841 force_env_section, subsys_section, use_motion_section)
842 CALL force_env_create(my_force_env, root_section, qmmmx_env=qmmmx_env, para_env=my_para_env, &
843 globenv=globenv, force_env_section=force_env_section)
844
845 CASE (do_eip)
846 ALLOCATE (eip_env)
847 CALL eip_env_create(eip_env)
848 CALL eip_init(eip_env, root_section, my_para_env, force_env_section=force_env_section, &
849 subsys_section=subsys_section)
850 CALL force_env_create(my_force_env, root_section, eip_env=eip_env, para_env=my_para_env, &
851 globenv=globenv, force_env_section=force_env_section)
852
853 CASE (do_sirius)
854 IF (.NOT. cp_sirius_is_initialized()) THEN
855 IF (unit_nr > 0) WRITE (unit=unit_nr, fmt="(T2,A)", advance="NO") "SIRIUS| "
856 CALL cp_sirius_init()
857 END IF
858 ALLOCATE (pwdft_env)
859 CALL pwdft_env_create(pwdft_env)
860 CALL pwdft_init(pwdft_env, root_section, my_para_env, force_env_section=force_env_section, &
861 subsys_section=subsys_section, use_motion_section=use_motion_section)
862 CALL force_env_create(my_force_env, root_section, pwdft_env=pwdft_env, para_env=my_para_env, &
863 globenv=globenv, force_env_section=force_env_section)
864
865 CASE (do_mixed)
866 ALLOCATE (mixed_env)
867 CALL mixed_create_force_env(mixed_env, root_section, my_para_env, &
868 force_env_section=force_env_section, n_subforce_eval=nsubforce_size, &
869 use_motion_section=use_motion_section)
870 CALL force_env_create(my_force_env, root_section, mixed_env=mixed_env, para_env=my_para_env, &
871 globenv=globenv, force_env_section=force_env_section)
872 !TODO: the sub_force_envs should really be created via recursion
873 use_multiple_para_env = .true.
874 CALL cp_add_default_logger(logger) ! just to get the logger swapping started
875 lgroup_distribution => my_force_env%mixed_env%group_distribution
876
877 CASE (do_embed)
878 ALLOCATE (embed_env)
879 CALL embed_create_force_env(embed_env, root_section, my_para_env, &
880 force_env_section=force_env_section, n_subforce_eval=nsubforce_size, &
881 use_motion_section=use_motion_section)
882 CALL force_env_create(my_force_env, root_section, embed_env=embed_env, para_env=my_para_env, &
883 globenv=globenv, force_env_section=force_env_section)
884 !TODO: the sub_force_envs should really be created via recursion
885 use_multiple_para_env = .true.
886 CALL cp_add_default_logger(logger) ! just to get the logger swapping started
887 lgroup_distribution => my_force_env%embed_env%group_distribution
888
889 CASE (do_nnp)
890 ALLOCATE (nnp_env)
891 CALL nnp_init(nnp_env, root_section, my_para_env, force_env_section=force_env_section, &
892 subsys_section=subsys_section, use_motion_section=use_motion_section)
893 CALL force_env_create(my_force_env, root_section, nnp_env=nnp_env, para_env=my_para_env, &
894 globenv=globenv, force_env_section=force_env_section)
895
896 CASE (do_ipi)
897 ALLOCATE (ipi_env)
898 CALL ipi_init(ipi_env, root_section, my_para_env, force_env_section=force_env_section, &
899 subsys_section=subsys_section)
900 CALL force_env_create(my_force_env, root_section, ipi_env=ipi_env, para_env=my_para_env, &
901 globenv=globenv, force_env_section=force_env_section)
902
903 CASE DEFAULT
904 CALL create_force_eval_section(section)
905 keyword => section_get_keyword(section, "METHOD")
906 CALL keyword_get(keyword, enum=enum)
907 CALL cp_abort(__location__, &
908 "Invalid METHOD <"//trim(enum_i2c(enum, method_name_id))// &
909 "> was specified, ")
910 CALL section_release(section)
911 END SELECT
912
913 NULLIFY (meta_env, fp_env)
914 IF (use_motion_section) THEN
915 ! Metadynamics Setup
916 fe_section => section_vals_get_subs_vals(root_section, "MOTION%FREE_ENERGY")
917 CALL metadyn_read(meta_env, my_force_env, root_section, my_para_env, fe_section)
918 CALL force_env_set(my_force_env, meta_env=meta_env)
919 ! Flexible Partition Setup
920 fp_section => section_vals_get_subs_vals(root_section, "MOTION%FLEXIBLE_PARTITIONING")
921 ALLOCATE (fp_env)
922 CALL fp_env_create(fp_env)
923 CALL fp_env_read(fp_env, fp_section)
924 CALL fp_env_write(fp_env, fp_section)
925 CALL force_env_set(my_force_env, fp_env=fp_env)
926 END IF
927 ! Handle multiple force_eval
928 IF (nforce_eval > 1 .AND. iforce_eval == 1) THEN
929 ALLOCATE (my_force_env%sub_force_env(nsubforce_size))
930 ! Nullify subforce_env
931 DO k = 1, nsubforce_size
932 NULLIFY (my_force_env%sub_force_env(k)%force_env)
933 END DO
934 END IF
935 ! Reference the right force_env
936 IF (iforce_eval == 1) THEN
937 force_env => my_force_env
938 ELSE
939 force_env%sub_force_env(iforce_eval - 1)%force_env => my_force_env
940 END IF
941 ! Multiple para env for sub_force_eval
942 IF (.NOT. use_multiple_para_env) THEN
943 lgroup_distribution = iforce_eval
944 END IF
945 ! Release force_env_section
946 IF (nforce_eval > 1) CALL section_vals_release(force_env_section)
947 END DO
948 IF (use_multiple_para_env) THEN
950 END IF
951 DEALLOCATE (group_distribution)
952 DEALLOCATE (i_force_eval)
953 timer_env => get_timer_env()
955 CALL para_env%max(last_f_env_id)
956 last_f_env_id = last_f_env_id + 1
957 new_env_id = last_f_env_id
958 n_f_envs = n_f_envs + 1
959 CALL f_env_create(f_envs(n_f_envs)%f_env, logger=logger, &
960 timer_env=timer_env, mp_perf_env=mp_perf_env, force_env=force_env, &
961 id_nr=last_f_env_id, old_dir=old_dir)
962 CALL force_env_release(force_env)
963 CALL globenv_release(globenv)
964 CALL section_vals_release(root_section)
965 CALL mp_para_env_release(para_env)
966 CALL f_env_rm_defaults(f_envs(n_f_envs)%f_env, ierr=ierr)
967 CALL timestop(handle)
968
969 END SUBROUTINE create_force_env
970
971! **************************************************************************************************
972!> \brief deallocates the force_env with the given id
973!> \param env_id the id of the force_env to remove
974!> \param ierr will contain a number different from 0 if
975!> \param q_finalize ...
976!> \author fawzi
977!> \note
978!> The following routines need to be synchronized wrt. adding/removing
979!> of the default environments (logging, performance,error):
980!> environment:cp2k_init, environment:cp2k_finalize,
981!> f77_interface:f_env_add_defaults, f77_interface:f_env_rm_defaults,
982!> f77_interface:create_force_env, f77_interface:destroy_force_env
983! **************************************************************************************************
984 RECURSIVE SUBROUTINE destroy_force_env(env_id, ierr, q_finalize)
985 INTEGER, INTENT(in) :: env_id
986 INTEGER, INTENT(out) :: ierr
987 LOGICAL, INTENT(IN), OPTIONAL :: q_finalize
988
989 INTEGER :: env_pos, i
990 TYPE(f_env_type), POINTER :: f_env
991 TYPE(global_environment_type), POINTER :: globenv
992 TYPE(mp_para_env_type), POINTER :: para_env
993 TYPE(section_vals_type), POINTER :: root_section
994
995 NULLIFY (f_env)
996 CALL f_env_add_defaults(env_id, f_env)
997 env_pos = get_pos_of_env(env_id)
998 n_f_envs = n_f_envs - 1
999 DO i = env_pos, n_f_envs
1000 f_envs(i)%f_env => f_envs(i + 1)%f_env
1001 END DO
1002 NULLIFY (f_envs(n_f_envs + 1)%f_env)
1003
1004 CALL force_env_get(f_env%force_env, globenv=globenv, &
1005 root_section=root_section, para_env=para_env)
1006
1007 cpassert(ASSOCIATED(globenv))
1008 NULLIFY (f_env%force_env%globenv)
1009 CALL f_env_dealloc(f_env)
1010 IF (PRESENT(q_finalize)) THEN
1011 CALL cp2k_finalize(root_section, para_env, globenv, f_env%old_path, q_finalize)
1012 ELSE
1013 CALL cp2k_finalize(root_section, para_env, globenv, f_env%old_path)
1014 END IF
1015 CALL section_vals_release(root_section)
1016 CALL globenv_release(globenv)
1017 DEALLOCATE (f_env)
1018 ierr = 0
1019 END SUBROUTINE destroy_force_env
1020
1021! **************************************************************************************************
1022!> \brief returns the number of atoms in the given force env
1023!> \param env_id id of the force_env
1024!> \param n_atom ...
1025!> \param ierr will return a number different from 0 if there was an error
1026!> \date 22.11.2010 (MK)
1027!> \author fawzi
1028! **************************************************************************************************
1029 SUBROUTINE get_natom(env_id, n_atom, ierr)
1030
1031 INTEGER, INTENT(IN) :: env_id
1032 INTEGER, INTENT(OUT) :: n_atom, ierr
1033
1034 TYPE(f_env_type), POINTER :: f_env
1035
1036 n_atom = 0
1037 NULLIFY (f_env)
1038 CALL f_env_add_defaults(env_id, f_env)
1039 n_atom = force_env_get_natom(f_env%force_env)
1040 CALL f_env_rm_defaults(f_env, ierr)
1041
1042 END SUBROUTINE get_natom
1043
1044! **************************************************************************************************
1045!> \brief returns the number of particles in the given force env
1046!> \param env_id id of the force_env
1047!> \param n_particle ...
1048!> \param ierr will return a number different from 0 if there was an error
1049!> \author Matthias Krack
1050!>
1051! **************************************************************************************************
1052 SUBROUTINE get_nparticle(env_id, n_particle, ierr)
1053
1054 INTEGER, INTENT(IN) :: env_id
1055 INTEGER, INTENT(OUT) :: n_particle, ierr
1056
1057 TYPE(f_env_type), POINTER :: f_env
1058
1059 n_particle = 0
1060 NULLIFY (f_env)
1061 CALL f_env_add_defaults(env_id, f_env)
1062 n_particle = force_env_get_nparticle(f_env%force_env)
1063 CALL f_env_rm_defaults(f_env, ierr)
1064
1065 END SUBROUTINE get_nparticle
1066
1067! **************************************************************************************************
1068!> \brief gets a cell
1069!> \param env_id id of the force_env
1070!> \param cell the array with the cell matrix
1071!> \param per periodicity
1072!> \param ierr will return a number different from 0 if there was an error
1073!> \author Joost VandeVondele
1074! **************************************************************************************************
1075 SUBROUTINE get_cell(env_id, cell, per, ierr)
1076
1077 INTEGER, INTENT(IN) :: env_id
1078 REAL(kind=dp), DIMENSION(3, 3) :: cell
1079 INTEGER, DIMENSION(3), OPTIONAL :: per
1080 INTEGER, INTENT(OUT) :: ierr
1081
1082 TYPE(cell_type), POINTER :: cell_full
1083 TYPE(f_env_type), POINTER :: f_env
1084
1085 NULLIFY (f_env)
1086 CALL f_env_add_defaults(env_id, f_env)
1087 NULLIFY (cell_full)
1088 CALL force_env_get(f_env%force_env, cell=cell_full)
1089 cpassert(ASSOCIATED(cell_full))
1090 cell = cell_full%hmat
1091 IF (PRESENT(per)) per(:) = cell_full%perd(:)
1092 CALL f_env_rm_defaults(f_env, ierr)
1093
1094 END SUBROUTINE get_cell
1095
1096! **************************************************************************************************
1097!> \brief gets the qmmm cell
1098!> \param env_id id of the force_env
1099!> \param cell the array with the cell matrix
1100!> \param ierr will return a number different from 0 if there was an error
1101!> \author Holly Judge
1102! **************************************************************************************************
1103 SUBROUTINE get_qmmm_cell(env_id, cell, ierr)
1104
1105 INTEGER, INTENT(IN) :: env_id
1106 REAL(kind=dp), DIMENSION(3, 3) :: cell
1107 INTEGER, INTENT(OUT) :: ierr
1108
1109 TYPE(cell_type), POINTER :: cell_qmmm
1110 TYPE(f_env_type), POINTER :: f_env
1111 TYPE(qmmm_env_type), POINTER :: qmmm_env
1112
1113 NULLIFY (f_env)
1114 CALL f_env_add_defaults(env_id, f_env)
1115 NULLIFY (cell_qmmm)
1116 CALL force_env_get(f_env%force_env, qmmm_env=qmmm_env)
1117 CALL get_qs_env(qmmm_env%qs_env, cell=cell_qmmm)
1118 cpassert(ASSOCIATED(cell_qmmm))
1119 cell = cell_qmmm%hmat
1120 CALL f_env_rm_defaults(f_env, ierr)
1121
1122 END SUBROUTINE get_qmmm_cell
1123
1124! **************************************************************************************************
1125!> \brief gets a result from CP2K that is a real 1D array
1126!> \param env_id id of the force_env
1127!> \param description the tag of the result
1128!> \param N ...
1129!> \param RESULT ...
1130!> \param res_exist ...
1131!> \param ierr will return a number different from 0 if there was an error
1132!> \author Joost VandeVondele
1133! **************************************************************************************************
1134 SUBROUTINE get_result_r1(env_id, description, N, RESULT, res_exist, ierr)
1135 INTEGER :: env_id
1136 CHARACTER(LEN=default_string_length) :: description
1137 INTEGER :: n
1138 REAL(kind=dp), DIMENSION(1:N) :: result
1139 LOGICAL, OPTIONAL :: res_exist
1140 INTEGER :: ierr
1141
1142 INTEGER :: nres
1143 LOGICAL :: exist_res
1144 TYPE(cp_result_type), POINTER :: results
1145 TYPE(cp_subsys_type), POINTER :: subsys
1146 TYPE(f_env_type), POINTER :: f_env
1147
1148 NULLIFY (f_env, subsys, results)
1149 CALL f_env_add_defaults(env_id, f_env)
1150
1151 CALL force_env_get(f_env%force_env, subsys=subsys)
1152 CALL cp_subsys_get(subsys, results=results)
1153 ! first test for the result
1154 IF (PRESENT(res_exist)) THEN
1155 res_exist = test_for_result(results, description=description)
1156 exist_res = res_exist
1157 ELSE
1158 exist_res = .true.
1159 END IF
1160 ! if existing (or assuming the existence) read the results
1161 IF (exist_res) THEN
1162 CALL get_results(results, description=description, n_rep=nres)
1163 CALL get_results(results, description=description, values=result, nval=nres)
1164 END IF
1165
1166 CALL f_env_rm_defaults(f_env, ierr)
1167
1168 END SUBROUTINE get_result_r1
1169
1170! **************************************************************************************************
1171!> \brief gets the forces of the particles
1172!> \param env_id id of the force_env
1173!> \param frc the array where to write the forces
1174!> \param n_el number of positions (3*nparticle) just to check
1175!> \param ierr will return a number different from 0 if there was an error
1176!> \date 22.11.2010 (MK)
1177!> \author fawzi
1178! **************************************************************************************************
1179 SUBROUTINE get_force(env_id, frc, n_el, ierr)
1180
1181 INTEGER, INTENT(IN) :: env_id, n_el
1182 REAL(kind=dp), DIMENSION(1:n_el) :: frc
1183 INTEGER, INTENT(OUT) :: ierr
1184
1185 TYPE(f_env_type), POINTER :: f_env
1186
1187 NULLIFY (f_env)
1188 CALL f_env_add_defaults(env_id, f_env)
1189 CALL force_env_get_frc(f_env%force_env, frc, n_el)
1190 CALL f_env_rm_defaults(f_env, ierr)
1191
1192 END SUBROUTINE get_force
1193
1194! **************************************************************************************************
1195!> \brief gets the stress tensor
1196!> \param env_id id of the force_env
1197!> \param stress_tensor the array where to write the stress tensor
1198!> \param ierr will return a number different from 0 if there was an error
1199!> \author Ole Schuett
1200! **************************************************************************************************
1201 SUBROUTINE get_stress_tensor(env_id, stress_tensor, ierr)
1202
1203 INTEGER, INTENT(IN) :: env_id
1204 REAL(kind=dp), DIMENSION(3, 3), INTENT(OUT) :: stress_tensor
1205 INTEGER, INTENT(OUT) :: ierr
1206
1207 TYPE(cell_type), POINTER :: cell
1208 TYPE(cp_subsys_type), POINTER :: subsys
1209 TYPE(f_env_type), POINTER :: f_env
1210 TYPE(virial_type), POINTER :: virial
1211
1212 NULLIFY (f_env, subsys, virial, cell)
1213 stress_tensor(:, :) = 0.0_dp
1214
1215 CALL f_env_add_defaults(env_id, f_env)
1216 CALL force_env_get(f_env%force_env, subsys=subsys, cell=cell)
1217 CALL cp_subsys_get(subsys, virial=virial)
1218 IF (virial%pv_availability) THEN
1219 stress_tensor(:, :) = virial%pv_virial(:, :)/cell%deth
1220 END IF
1221 CALL f_env_rm_defaults(f_env, ierr)
1222
1223 END SUBROUTINE get_stress_tensor
1224
1225! **************************************************************************************************
1226!> \brief gets the positions of the particles
1227!> \param env_id id of the force_env
1228!> \param pos the array where to write the positions
1229!> \param n_el number of positions (3*nparticle) just to check
1230!> \param ierr will return a number different from 0 if there was an error
1231!> \date 22.11.2010 (MK)
1232!> \author fawzi
1233! **************************************************************************************************
1234 SUBROUTINE get_pos(env_id, pos, n_el, ierr)
1235
1236 INTEGER, INTENT(IN) :: env_id, n_el
1237 REAL(kind=dp), DIMENSION(1:n_el) :: pos
1238 INTEGER, INTENT(OUT) :: ierr
1239
1240 TYPE(f_env_type), POINTER :: f_env
1241
1242 NULLIFY (f_env)
1243 CALL f_env_add_defaults(env_id, f_env)
1244 CALL force_env_get_pos(f_env%force_env, pos, n_el)
1245 CALL f_env_rm_defaults(f_env, ierr)
1246
1247 END SUBROUTINE get_pos
1248
1249! **************************************************************************************************
1250!> \brief gets the velocities of the particles
1251!> \param env_id id of the force_env
1252!> \param vel the array where to write the velocities
1253!> \param n_el number of velocities (3*nparticle) just to check
1254!> \param ierr will return a number different from 0 if there was an error
1255!> \author fawzi
1256!> date 22.11.2010 (MK)
1257! **************************************************************************************************
1258 SUBROUTINE get_vel(env_id, vel, n_el, ierr)
1259
1260 INTEGER, INTENT(IN) :: env_id, n_el
1261 REAL(kind=dp), DIMENSION(1:n_el) :: vel
1262 INTEGER, INTENT(OUT) :: ierr
1263
1264 TYPE(f_env_type), POINTER :: f_env
1265
1266 NULLIFY (f_env)
1267 CALL f_env_add_defaults(env_id, f_env)
1268 CALL force_env_get_vel(f_env%force_env, vel, n_el)
1269 CALL f_env_rm_defaults(f_env, ierr)
1270
1271 END SUBROUTINE get_vel
1272
1273! **************************************************************************************************
1274!> \brief sets a new cell
1275!> \param env_id id of the force_env
1276!> \param new_cell the array with the cell matrix
1277!> \param ierr will return a number different from 0 if there was an error
1278!> \author Joost VandeVondele
1279! **************************************************************************************************
1280 SUBROUTINE set_cell(env_id, new_cell, ierr)
1281
1282 INTEGER, INTENT(IN) :: env_id
1283 REAL(kind=dp), DIMENSION(3, 3) :: new_cell
1284 INTEGER, INTENT(OUT) :: ierr
1285
1286 TYPE(cell_type), POINTER :: cell
1287 TYPE(cp_subsys_type), POINTER :: subsys
1288 TYPE(f_env_type), POINTER :: f_env
1289
1290 NULLIFY (f_env, cell, subsys)
1291 CALL f_env_add_defaults(env_id, f_env)
1292 NULLIFY (cell)
1293 CALL force_env_get(f_env%force_env, cell=cell)
1294 cpassert(ASSOCIATED(cell))
1295 cell%hmat = new_cell
1296 CALL init_cell(cell)
1297 CALL force_env_get(f_env%force_env, subsys=subsys)
1298 CALL cp_subsys_set(subsys, cell=cell)
1299 CALL f_env_rm_defaults(f_env, ierr)
1300
1301 END SUBROUTINE set_cell
1302
1303! **************************************************************************************************
1304!> \brief sets the positions of the particles
1305!> \param env_id id of the force_env
1306!> \param new_pos the array with the new positions
1307!> \param n_el number of positions (3*nparticle) just to check
1308!> \param ierr will return a number different from 0 if there was an error
1309!> \date 22.11.2010 updated (MK)
1310!> \author fawzi
1311! **************************************************************************************************
1312 SUBROUTINE set_pos(env_id, new_pos, n_el, ierr)
1313
1314 INTEGER, INTENT(IN) :: env_id, n_el
1315 REAL(kind=dp), DIMENSION(1:n_el) :: new_pos
1316 INTEGER, INTENT(OUT) :: ierr
1317
1318 TYPE(cp_subsys_type), POINTER :: subsys
1319 TYPE(f_env_type), POINTER :: f_env
1320
1321 NULLIFY (f_env)
1322 CALL f_env_add_defaults(env_id, f_env)
1323 NULLIFY (subsys)
1324 CALL force_env_get(f_env%force_env, subsys=subsys)
1325 CALL unpack_subsys_particles(subsys=subsys, r=new_pos)
1326 CALL f_env_rm_defaults(f_env, ierr)
1327
1328 END SUBROUTINE set_pos
1329
1330! **************************************************************************************************
1331!> \brief sets the velocities of the particles
1332!> \param env_id id of the force_env
1333!> \param new_vel the array with the new velocities
1334!> \param n_el number of velocities (3*nparticle) just to check
1335!> \param ierr will return a number different from 0 if there was an error
1336!> \date 22.11.2010 updated (MK)
1337!> \author fawzi
1338! **************************************************************************************************
1339 SUBROUTINE set_vel(env_id, new_vel, n_el, ierr)
1340
1341 INTEGER, INTENT(IN) :: env_id, n_el
1342 REAL(kind=dp), DIMENSION(1:n_el) :: new_vel
1343 INTEGER, INTENT(OUT) :: ierr
1344
1345 TYPE(cp_subsys_type), POINTER :: subsys
1346 TYPE(f_env_type), POINTER :: f_env
1347
1348 NULLIFY (f_env)
1349 CALL f_env_add_defaults(env_id, f_env)
1350 NULLIFY (subsys)
1351 CALL force_env_get(f_env%force_env, subsys=subsys)
1352 CALL unpack_subsys_particles(subsys=subsys, v=new_vel)
1353 CALL f_env_rm_defaults(f_env, ierr)
1354
1355 END SUBROUTINE set_vel
1356
1357! **************************************************************************************************
1358!> \brief updates the energy and the forces of given force_env
1359!> \param env_id id of the force_env that you want to update
1360!> \param calc_force if the forces should be updated, if false the forces
1361!> might be wrong.
1362!> \param ierr will return a number different from 0 if there was an error
1363!> \author fawzi
1364! **************************************************************************************************
1365 RECURSIVE SUBROUTINE calc_energy_force(env_id, calc_force, ierr)
1366
1367 INTEGER, INTENT(in) :: env_id
1368 LOGICAL, INTENT(in) :: calc_force
1369 INTEGER, INTENT(out) :: ierr
1370
1371 TYPE(cp_logger_type), POINTER :: logger
1372 TYPE(f_env_type), POINTER :: f_env
1373
1374 NULLIFY (f_env)
1375 CALL f_env_add_defaults(env_id, f_env)
1376 logger => cp_get_default_logger()
1377 CALL cp_iterate(logger%iter_info) ! add one to the iteration count
1379 CALL f_env_rm_defaults(f_env, ierr)
1380
1381 END SUBROUTINE calc_energy_force
1382
1383! **************************************************************************************************
1384!> \brief returns the energy of the last configuration calculated
1385!> \param env_id id of the force_env that you want to update
1386!> \param e_pot the potential energy of the system
1387!> \param ierr will return a number different from 0 if there was an error
1388!> \author fawzi
1389! **************************************************************************************************
1390 SUBROUTINE get_energy(env_id, e_pot, ierr)
1391
1392 INTEGER, INTENT(in) :: env_id
1393 REAL(kind=dp), INTENT(out) :: e_pot
1394 INTEGER, INTENT(out) :: ierr
1395
1396 TYPE(f_env_type), POINTER :: f_env
1397
1398 NULLIFY (f_env)
1399 CALL f_env_add_defaults(env_id, f_env)
1400 CALL force_env_get(f_env%force_env, potential_energy=e_pot)
1401 CALL f_env_rm_defaults(f_env, ierr)
1402
1403 END SUBROUTINE get_energy
1404
1405! **************************************************************************************************
1406!> \brief returns the energy of the configuration given by the positions
1407!> passed as argument
1408!> \param env_id id of the force_env that you want to update
1409!> \param pos array with the positions
1410!> \param n_el number of elements in pos (3*natom)
1411!> \param e_pot the potential energy of the system
1412!> \param ierr will return a number different from 0 if there was an error
1413!> \author fawzi
1414!> \note
1415!> utility call
1416! **************************************************************************************************
1417 RECURSIVE SUBROUTINE calc_energy(env_id, pos, n_el, e_pot, ierr)
1418
1419 INTEGER, INTENT(IN) :: env_id, n_el
1420 REAL(kind=dp), DIMENSION(1:n_el), INTENT(IN) :: pos
1421 REAL(kind=dp), INTENT(OUT) :: e_pot
1422 INTEGER, INTENT(OUT) :: ierr
1423
1424 REAL(kind=dp), DIMENSION(1) :: dummy_f
1425
1426 CALL calc_force(env_id, pos, n_el, e_pot, dummy_f, 0, ierr)
1427
1428 END SUBROUTINE calc_energy
1429
1430! **************************************************************************************************
1431!> \brief returns the energy of the configuration given by the positions
1432!> passed as argument
1433!> \param env_id id of the force_env that you want to update
1434!> \param pos array with the positions
1435!> \param n_el_pos number of elements in pos (3*natom)
1436!> \param e_pot the potential energy of the system
1437!> \param force array that will contain the forces
1438!> \param n_el_force number of elements in force (3*natom). If 0 the
1439!> forces are not calculated
1440!> \param ierr will return a number different from 0 if there was an error
1441!> \author fawzi
1442!> \note
1443!> utility call, but actually it could be a better and more efficient
1444!> interface to connect to other codes if cp2k would be deeply
1445!> refactored
1446! **************************************************************************************************
1447 RECURSIVE SUBROUTINE calc_force(env_id, pos, n_el_pos, e_pot, force, n_el_force, ierr)
1448
1449 INTEGER, INTENT(in) :: env_id, n_el_pos
1450 REAL(kind=dp), DIMENSION(1:n_el_pos), INTENT(in) :: pos
1451 REAL(kind=dp), INTENT(out) :: e_pot
1452 INTEGER, INTENT(in) :: n_el_force
1453 REAL(kind=dp), DIMENSION(1:n_el_force), &
1454 INTENT(inout) :: force
1455 INTEGER, INTENT(out) :: ierr
1456
1457 LOGICAL :: calc_f
1458
1459 calc_f = (n_el_force /= 0)
1460 CALL set_pos(env_id, pos, n_el_pos, ierr)
1461 IF (ierr == 0) CALL calc_energy_force(env_id, calc_f, ierr)
1462 IF (ierr == 0) CALL get_energy(env_id, e_pot, ierr)
1463 IF (calc_f .AND. (ierr == 0)) CALL get_force(env_id, force, n_el_force, ierr)
1464
1465 END SUBROUTINE calc_force
1466
1467! **************************************************************************************************
1468!> \brief performs a check of the input
1469!> \param input_declaration ...
1470!> \param input_file_path the path of the input file to check
1471!> \param output_file_path path of the output file (to which it is appended)
1472!> if it is "__STD_OUT__" the default_output_unit is used
1473!> \param echo_input if the parsed input should be written out with all the
1474!> defaults made explicit
1475!> \param mpi_comm the mpi communicator (if not given it uses the default
1476!> one)
1477!> \param initial_variables key-value list of initial preprocessor variables
1478!> \param ierr error control, if different from 0 there was an error
1479!> \author fawzi
1480! **************************************************************************************************
1481 SUBROUTINE check_input(input_declaration, input_file_path, output_file_path, &
1482 echo_input, mpi_comm, initial_variables, ierr)
1483 TYPE(section_type), POINTER :: input_declaration
1484 CHARACTER(len=*), INTENT(in) :: input_file_path, output_file_path
1485 LOGICAL, INTENT(in), OPTIONAL :: echo_input
1486 TYPE(mp_comm_type), INTENT(in), OPTIONAL :: mpi_comm
1487 CHARACTER(len=default_path_length), &
1488 DIMENSION(:, :), INTENT(IN) :: initial_variables
1489 INTEGER, INTENT(out) :: ierr
1490
1491 INTEGER :: unit_nr
1492 LOGICAL :: my_echo_input
1493 TYPE(cp_logger_type), POINTER :: logger
1494 TYPE(mp_para_env_type), POINTER :: para_env
1495 TYPE(section_vals_type), POINTER :: input_file
1496
1497 my_echo_input = .false.
1498 IF (PRESENT(echo_input)) my_echo_input = echo_input
1499
1500 IF (PRESENT(mpi_comm)) THEN
1501 ALLOCATE (para_env)
1502 para_env = mpi_comm
1503 ELSE
1504 para_env => default_para_env
1505 CALL para_env%retain()
1506 END IF
1507 IF (para_env%is_source()) THEN
1508 IF (output_file_path == "__STD_OUT__") THEN
1509 unit_nr = default_output_unit
1510 ELSE
1511 CALL open_file(file_name=output_file_path, file_status="UNKNOWN", &
1512 file_action="WRITE", file_position="APPEND", &
1513 unit_number=unit_nr)
1514 END IF
1515 ELSE
1516 unit_nr = -1
1517 END IF
1518
1519 NULLIFY (logger)
1520 CALL cp_logger_create(logger, para_env=para_env, &
1521 default_global_unit_nr=unit_nr, &
1522 close_global_unit_on_dealloc=.false.)
1523 CALL cp_add_default_logger(logger)
1524 CALL cp_logger_release(logger)
1525
1526 input_file => read_input(input_declaration, input_file_path, initial_variables=initial_variables, &
1527 para_env=para_env)
1528 CALL check_cp2k_input(input_declaration, input_file, para_env=para_env, output_unit=unit_nr)
1529 IF (my_echo_input .AND. (unit_nr > 0)) THEN
1530 CALL section_vals_write(input_file, &
1531 unit_nr=unit_nr, &
1532 hide_root=.true., &
1533 hide_defaults=.false.)
1534 END IF
1535 CALL section_vals_release(input_file)
1536
1537 CALL cp_logger_release(logger)
1538 CALL mp_para_env_release(para_env)
1539 ierr = 0
1541
1542 END SUBROUTINE check_input
1543
1544END MODULE f77_interface
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
void grid_library_finalize(void)
Finalizes the grid library.
void grid_library_init(void)
Initializes the grid library.
Central dispatch for basic hooks.
Definition base_hooks.F:12
procedure(cp_warn_interface), pointer, public cp_warn_hook
Definition base_hooks.F:59
subroutine, public cp_abort(location, message)
Terminate the program.
Definition base_hooks.F:73
subroutine, public timeset(routinen, handle)
Start timer.
Definition base_hooks.F:127
procedure(cp_abort_interface), pointer, public cp_abort_hook
Definition base_hooks.F:58
procedure(timeset_interface), pointer, public timeset_hook
Definition base_hooks.F:61
subroutine, public timestop(handle)
Stop timer.
Definition base_hooks.F:143
procedure(timestop_interface), pointer, public timestop_hook
Definition base_hooks.F:62
collects all references to literature in CP2K as new algorithms / method are included from literature...
subroutine, public add_all_references()
adds references that can later be cited / printed using the key
Handles all functions related to the CELL.
subroutine, public init_cell(cell, hmat, periodic)
Initialise/readjust a simulation cell after hmat has been changed.
Handles all functions related to the CELL.
Definition cell_types.F:15
some minimal info about CP2K, including its version and license
Definition cp2k_info.F:22
subroutine, public get_runtime_info()
...
Definition cp2k_info.F:378
subroutine, public cp_dlaf_finalize()
Finalize DLA-Future and pika runtime.
subroutine, public cp_dlaf_free_all_grids()
Free all DLA-Future grids.
Module that contains the routines for error handling.
subroutine, public cp_error_handling_setup()
Registers handlers with base_hooks.F.
Utility routines to open and close files. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:311
subroutine, public init_preconnection_list()
Allocate and initialise the list of preconnected units.
Definition cp_files.F:276
various routines to log and control the output. The idea is that decisions about where to log should ...
subroutine, public cp_rm_default_logger()
the cousin of cp_add_default_logger, decrements the stack, so that the default logger is what it has ...
subroutine, public cp_logger_release(logger)
releases this logger
subroutine, public cp_logger_create(logger, para_env, print_level, default_global_unit_nr, default_local_unit_nr, global_filename, local_filename, close_global_unit_on_dealloc, iter_info, close_local_unit_on_dealloc, suffix, template_logger)
initializes a logger
integer function, public cp_default_logger_stack_size()
...
integer, parameter, public cp_failure_level
subroutine, public cp_logger_retain(logger)
retains the given logger (to be called to keep a shared copy of the logger)
subroutine, public cp_add_default_logger(logger)
adds a default logger. MUST be called before logging occours
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...
subroutine, public cp_openpmd_output_finalize()
Close all outputs.
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
subroutine, public cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
set of type/routines to handle the storage of results in force_envs
logical function, public test_for_result(results, description)
test for a certain result in the result_list
set of type/routines to handle the storage of results in force_envs
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_set(subsys, atomic_kinds, particles, local_particles, molecules, molecule_kinds, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, results, cell, cell_ref, use_ref_cell)
sets various propreties of the subsys
subroutine, public unpack_subsys_particles(subsys, f, r, s, v, fscale, cell)
Unpack components of a subsystem particle sets into a single vector.
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
subroutine, public dbm_library_init()
Initialize DBM library.
Definition dbm_api.F:1483
subroutine, public dbm_library_finalize()
Finalize DBM library.
Definition dbm_api.F:1497
The environment for the empirical interatomic potential methods.
subroutine, public eip_env_create(eip_env)
Creates the eip environment.
Methods and functions on the EIP environment.
subroutine, public eip_init(eip_env, root_section, para_env, force_env_section, subsys_section)
Initialize the eip environment.
Main force create for embedding.
Definition embed_main.F:12
subroutine, public embed_create_force_env(embed_env, root_section, para_env, force_env_section, n_subforce_eval, use_motion_section)
Controls program flow for embedded calculations.
Definition embed_main.F:52
Sets up and terminates the global environment variables.
Definition environment.F:17
subroutine, public cp2k_finalize(root_section, para_env, globenv, wdir, q_finalize)
Writes final timings and banner for CP2K.
subroutine, public cp2k_read(root_section, para_env, globenv)
read part of cp2k_init
subroutine, public cp2k_init(para_env, output_unit, globenv, input_file_name, wdir)
Initializes a CP2K run (setting of the global environment variables)
subroutine, public cp2k_setup(root_section, para_env, globenv)
globenv initializations that need the input and error
interface to use cp2k as library
recursive subroutine, public destroy_force_env(env_id, ierr, q_finalize)
deallocates the force_env with the given id
subroutine, public f_env_get_from_id(f_env_id, f_env)
...
subroutine, public set_vel(env_id, new_vel, n_el, ierr)
sets the velocities of the particles
subroutine, public get_nparticle(env_id, n_particle, ierr)
returns the number of particles in the given force env
subroutine, public get_natom(env_id, n_atom, ierr)
returns the number of atoms in the given force env
subroutine, public f_env_add_defaults(f_env_id, f_env, handle)
adds the default environments of the f_env to the stack of the defaults, and returns a new error and ...
subroutine, public get_cell(env_id, cell, per, ierr)
gets a cell
type(mp_para_env_type), pointer, save, public default_para_env
recursive subroutine, public calc_energy_force(env_id, calc_force, ierr)
updates the energy and the forces of given force_env
subroutine, public get_energy(env_id, e_pot, ierr)
returns the energy of the last configuration calculated
subroutine, public init_cp2k(init_mpi, ierr, mpi_comm)
initializes cp2k, needs to be called once before using any of the other functions when using cp2k as ...
subroutine, public get_qmmm_cell(env_id, cell, ierr)
gets the qmmm cell
subroutine, public get_pos(env_id, pos, n_el, ierr)
gets the positions of the particles
type(f_env_p_type), dimension(:), pointer, save f_envs
recursive subroutine, public create_force_env(new_env_id, input_declaration, input_path, output_path, mpi_comm, output_unit, owns_out_unit, input, ierr, work_dir, initial_variables)
creates a new force environment using the given input, and writing the output to the given output uni...
recursive subroutine, public calc_energy(env_id, pos, n_el, e_pot, ierr)
returns the energy of the configuration given by the positions passed as argument
subroutine, public set_cell(env_id, new_cell, ierr)
sets a new cell
subroutine, public finalize_cp2k(finalize_mpi, ierr)
cleanup after you have finished using this interface
subroutine, public set_pos(env_id, new_pos, n_el, ierr)
sets the positions of the particles
subroutine, public get_stress_tensor(env_id, stress_tensor, ierr)
gets the stress tensor
subroutine, public check_input(input_declaration, input_file_path, output_file_path, echo_input, mpi_comm, initial_variables, ierr)
performs a check of the input
subroutine, public f_env_rm_defaults(f_env, ierr, handle)
removes the default environments of the f_env to the stack of the defaults, and sets ierr accordingly...
subroutine, public get_force(env_id, frc, n_el, ierr)
gets the forces of the particles
recursive subroutine, public calc_force(env_id, pos, n_el_pos, e_pot, force, n_el_force, ierr)
returns the energy of the configuration given by the positions passed as argument
perform classical molecular dynamics and path integral simulations
Definition fist_main.F:16
subroutine, public fist_create_force_env(force_env, root_section, para_env, globenv, qmmm, qmmm_env, force_env_section, subsys_section, use_motion_section, prev_subsys)
Controls program flow for classical MD and path-integrals.
Definition fist_main.F:66
Interface for the force calculations.
recursive subroutine, public force_env_calc_energy_force(force_env, calc_force, consistent_energies, skip_external_control, eval_energy_forces, require_consistent_energy_force, linres, calc_stress_tensor)
Interface routine for force and energy calculations.
subroutine, public force_env_create(force_env, root_section, para_env, globenv, fist_env, qs_env, meta_env, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, force_env_section, mixed_env, embed_env, nnp_env, ipi_env)
creates and initializes a force environment
Interface for the force calculations.
integer function, public force_env_get_natom(force_env)
returns the number of atoms
subroutine, public force_env_get_vel(force_env, vel, n)
returns the particle velocities in a dimension(*) array
subroutine, public multiple_fe_list(force_env_sections, root_section, i_force_eval, nforce_eval)
returns the order of the multiple force_env
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
subroutine, public force_env_retain(force_env)
retains the given force env
subroutine, public force_env_get_pos(force_env, pos, n)
returns the particle positions in a dimension(*) array
subroutine, public force_env_set(force_env, meta_env, fp_env, force_env_section, method_name_id, additional_potential)
changes some attributes of the force_env
subroutine, public force_env_get_frc(force_env, frc, n)
returns the particle forces in a dimension(*) array
recursive subroutine, public force_env_release(force_env)
releases the given force env
integer function, public force_env_get_nparticle(force_env)
returns the number of particles in a force environment
types used in the flexible partitioning scheme
Definition fp_types.F:14
subroutine, public fp_env_write(fp_env, fp_section)
writes information concerning the fp_env to the output
Definition fp_types.F:140
subroutine, public fp_env_read(fp_env, fp_section)
reads the corresponding input section and stores it in the fp_env
Definition fp_types.F:97
pure subroutine, public fp_env_create(fp_env)
create retain release the flexible partitioning environment
Definition fp_types.F:66
Define type storing the global information of a run. Keep the amount of stored data small....
subroutine, public globenv_create(globenv)
Creates the global environment globenv.
subroutine, public globenv_release(globenv)
Releases the global environment globenv.
Fortran API for the grid package, which is written in C.
Definition grid_api.F:12
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_nnp
integer, parameter, public do_qmmmx
integer, parameter, public do_eip
integer, parameter, public do_fist
integer, parameter, public do_qmmm
integer, parameter, public do_embed
integer, parameter, public do_sirius
integer, parameter, public do_qs
integer, parameter, public do_mixed
integer, parameter, public do_ipi
checks the input and perform some automatic "magic" on it
subroutine, public check_cp2k_input(input_declaration, input_file, para_env, output_unit)
performs further checks on an input that parsed successfully
builds the input structure for the FORCE_EVAL section of cp2k
subroutine, public create_force_eval_section(section)
creates the force_eval section
parse cp2k input files
type(section_vals_type) function, pointer, public read_input(input_declaration, file_path, initial_variables, para_env)
reads the cp2k input from the given filepath and returns a section_vals containing the input
represents an enumeration, i.e. a mapping between integers and strings
character(len=default_string_length) function, public enum_i2c(enum, i)
maps an integer to a string
represents keywords in an input
subroutine, public keyword_get(keyword, names, usage, description, type_of_var, n_var, default_value, lone_keyword_value, repeats, enum, citations)
...
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_remove_values(section_vals)
removes the values of a repetition of the section
subroutine, public section_vals_retain(section_vals)
retains the given section values (see doc/ReferenceCounting.html)
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_release(section)
releases the given keyword list (see doc/ReferenceCounting.html)
recursive type(keyword_type) function, pointer, public section_get_keyword(section, keyword_name)
returns the requested keyword
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_duplicate(section_vals_in, section_vals_out, i_rep_start, i_rep_end)
creates a deep copy from section_vals_in to section_vals_out
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
recursive subroutine, public section_vals_release(section_vals)
releases the given object
The environment for the empirical interatomic potential methods.
Methods and functions on the i–PI environment.
subroutine, public ipi_init(ipi_env, root_section, para_env, force_env_section, subsys_section)
Initialize the ipi environment.
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
integer, parameter, public default_path_length
Definition kinds.F:58
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
integer, parameter, public default_output_unit
Definition machine.F:46
subroutine, public m_memory(mem)
Returns the total amount of memory [bytes] in use, if known, zero otherwise.
Definition machine.F:440
subroutine, public m_getcwd(curdir)
...
Definition machine.F:607
subroutine, public m_chdir(dir, ierror)
...
Definition machine.F:636
Interface to the message passing library MPI.
subroutine, public mp_world_init(mp_comm)
initializes the system default communicator
type(mp_comm_type), parameter, public mp_comm_world
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
subroutine, public mp_world_finalize()
finalizes the system default communicator
defines types for metadynamics calculation
Performs the metadynamics calculation.
subroutine, public metadyn_read(meta_env, force_env, root_section, para_env, fe_section)
reads metadynamics section
perform biased molecular dynamics (H= k H1 + (1-k) H2 [linear or general mixing)
Definition mixed_main.F:12
subroutine, public mixed_create_force_env(mixed_env, root_section, para_env, force_env_section, n_subforce_eval, use_motion_section)
Controls program flow for mixed calculations.
Definition mixed_main.F:52
Defines all routines to deal with the performance of MPI routines.
Definition mp_perf_env.F:11
subroutine, public mp_perf_env_release(perf_env)
...
subroutine, public rm_mp_perf_env()
...
type(mp_perf_env_type) function, pointer, public get_mp_perf_env()
...
elemental subroutine, public mp_perf_env_retain(perf_env)
...
subroutine, public add_mp_perf_env(perf_env)
start and stop the performance indicators for every call to start there has to be (exactly) one call ...
Definition mp_perf_env.F:78
Data types for neural network potentials.
Methods dealing with Neural Network potentials.
subroutine, public nnp_init(nnp_env, root_section, para_env, force_env_section, subsys_section, use_motion_section)
Read and initialize all the information for neural network potentials.
Fortran API for the offload package, which is written in C.
Definition offload_api.F:12
subroutine, public offload_set_chosen_device(device_id)
Selects the chosen device to be used.
integer function, public offload_get_device_count()
Returns the number of available devices.
subroutine, public offload_init()
Initialize runtime.
Definition offload_api.F:93
Periodic Table related data definitions.
subroutine, public init_periodic_table()
Initialization of Periodic Table related data.
subroutine, public pw_fpga_finalize()
Releases resources on the fpga device.
Definition pw_fpga.F:136
subroutine, public pw_fpga_init()
Allocates resources on the fpga device.
Definition pw_fpga.F:112
subroutine, public pw_gpu_init()
Allocates resources on the gpu device for gpu fft acceleration.
Definition pw_gpu.F:62
subroutine, public pw_gpu_finalize()
Releases resources on the gpu device for gpu fft acceleration.
Definition pw_gpu.F:81
The type definitions for the PWDFT environment.
subroutine, public pwdft_env_create(pwdft_env)
Creates the pwdft environment.
Methods and functions on the PWDFT environment.
subroutine, public pwdft_init(pwdft_env, root_section, para_env, force_env_section, subsys_section, use_motion_section)
Initialize the pwdft environment.
Initialize a QM/MM calculation.
Definition qmmm_create.F:14
subroutine, public qmmm_env_create(qmmm_env, root_section, para_env, globenv, force_env_section, qmmm_section, subsys_section, use_motion_section, prev_subsys, ignore_outside_box)
...
Basic container type for QM/MM.
Definition qmmm_types.F:12
Initialize a QM/MM calculation with Force-Mixing.
subroutine, public qmmmx_env_create(qmmmx_env, root_section, para_env, globenv, force_env_section, subsys_section, use_motion_section)
...
Basic container type for QM/MM with force mixing.
Definition qmmmx_types.F:12
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, 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_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.
provides a uniform framework to add references to CP2K cite and output these
subroutine, public remove_all_references()
deallocate the bibliography
Interface to the SIRIUS Library.
subroutine, public cp_sirius_init()
Empty implementation in case SIRIUS is not compiled in.
logical function, public cp_sirius_is_initialized()
Return always .FALSE. because the Sirius library is not compiled in.
subroutine, public cp_sirius_finalize()
Empty implementation in case SIRIUS is not compiled in.
generates a unique id number for a string (str2id) that can be used two compare two strings....
subroutine, public string_table_deallocate(iw)
deallocates the string table
subroutine, public string_table_allocate()
allocates the string table
Types used by timings.F and timings_report.F Due to the fortran restriction on cicular module-depende...
Timing routines for accounting.
Definition timings.F:17
subroutine, public timings_register_hooks()
Registers handlers with base_hooks.F.
Definition timings.F:79
type(timer_env_type) function, pointer, public get_timer_env()
returns the current timer env from the stack
Definition timings.F:148
subroutine, public add_timer_env(timer_env)
adds the given timer_env to the top of the stack
Definition timings.F:93
subroutine, public rm_timer_env()
removes the current timer env from the stack
Definition timings.F:135
subroutine, public timer_env_release(timer_env)
releases the given timer env
Definition timings.F:176
subroutine, public timer_env_retain(timer_env)
retains the given timer env
Definition timings.F:159
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...
contains arbitrary information which need to be stored
represents a system: atoms, molecules, their pos,vel,...
The empirical interatomic potential environment.
Embedding environment type.
wrapper to abstract the force evaluation of the various methods
contains the initially parsed file and the initial parallel environment
represent a keyword in the input
represent a section of the input file
stores all the informations relevant to an mpi environment
Main data type collecting all relevant data for neural network potentials.