(git:9807808)
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#include "./base/base_uses.f90"
152
153 IMPLICIT NONE
154 PRIVATE
155
156 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
157 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'f77_interface'
158
159! **************************************************************************************************
160 TYPE f_env_p_type
161 TYPE(f_env_type), POINTER :: f_env => null()
162 END TYPE f_env_p_type
163
164! **************************************************************************************************
166 INTEGER :: id_nr = 0
167 TYPE(force_env_type), POINTER :: force_env => null()
168 TYPE(cp_logger_type), POINTER :: logger => null()
169 TYPE(timer_env_type), POINTER :: timer_env => null()
170 TYPE(mp_perf_env_type), POINTER :: mp_perf_env => null()
171 CHARACTER(len=default_path_length) :: my_path = "", old_path = ""
172 END TYPE f_env_type
173
174 TYPE(f_env_p_type), DIMENSION(:), POINTER, SAVE :: f_envs
175 TYPE(mp_para_env_type), POINTER, SAVE :: default_para_env
176 LOGICAL, SAVE :: module_initialized = .false.
177 INTEGER, SAVE :: last_f_env_id = 0, n_f_envs = 0
178
179 PUBLIC :: default_para_env
180 PUBLIC :: init_cp2k, finalize_cp2k
186 set_vel, set_cell, get_cell, get_qmmm_cell, get_result_r1
187CONTAINS
188
189! **************************************************************************************************
190!> \brief returns the position of the force env corresponding to the given id
191!> \param env_id the id of the requested environment
192!> \return ...
193!> \author fawzi
194!> \note
195!> private utility function
196! **************************************************************************************************
197 FUNCTION get_pos_of_env(env_id) RESULT(res)
198 INTEGER, INTENT(in) :: env_id
199 INTEGER :: res
200
201 INTEGER :: env_pos, isub
202
203 env_pos = -1
204 DO isub = 1, n_f_envs
205 IF (f_envs(isub)%f_env%id_nr == env_id) THEN
206 env_pos = isub
207 END IF
208 END DO
209 res = env_pos
210 END FUNCTION get_pos_of_env
211
212! **************************************************************************************************
213!> \brief initializes cp2k, needs to be called once before using any of the
214!> other functions when using cp2k as library
215!> \param init_mpi if the mpi environment should be initialized
216!> \param ierr returns a number different from 0 if there was an error
217!> \param mpi_comm an existing mpi communicator (if not given mp_comm_world
218!> will be used)
219!> \author fawzi
220! **************************************************************************************************
221 SUBROUTINE init_cp2k(init_mpi, ierr, mpi_comm)
222 LOGICAL, INTENT(in) :: init_mpi
223 INTEGER, INTENT(out) :: ierr
224 TYPE(mp_comm_type), INTENT(in), OPTIONAL :: mpi_comm
225
226 INTEGER :: offload_device_count, unit_nr
227 INTEGER, POINTER :: active_device_id
228 INTEGER, TARGET :: offload_chosen_device
229 TYPE(cp_logger_type), POINTER :: logger
230
231 IF (.NOT. module_initialized) THEN
232 ! install error handler hooks
234
235 ! install timming handler hooks
237
238 ! Initialise preconnection list
240
241 ! get runtime information
242 CALL get_runtime_info()
243
244 ! Intialize CUDA/HIP before MPI
245 ! Needed for HIP on ALPS & LUMI
246 CALL offload_init()
247
248 ! re-create the para_env and log with correct (reordered) ranks
249 ALLOCATE (default_para_env)
250 IF (init_mpi) THEN
251 ! get the default system wide communicator
253 ELSE
254 IF (PRESENT(mpi_comm)) THEN
255 default_para_env = mpi_comm
256 ELSE
258 END IF
259 END IF
260
262 CALL add_mp_perf_env()
263 CALL add_timer_env()
264
265 IF (default_para_env%is_source()) THEN
266 unit_nr = default_output_unit
267 ELSE
268 unit_nr = -1
269 END IF
270 NULLIFY (logger)
271
272 CALL cp_logger_create(logger, para_env=default_para_env, &
273 default_global_unit_nr=unit_nr, &
274 close_global_unit_on_dealloc=.false.)
275 CALL cp_add_default_logger(logger)
276 CALL cp_logger_release(logger)
277
278 ALLOCATE (f_envs(0))
279 module_initialized = .true.
280 ierr = 0
281
282 ! Initialize mathematical constants
284
285 ! Init the bibliography
286 CALL add_all_references()
287
288 NULLIFY (active_device_id)
289 offload_device_count = offload_get_device_count()
290
291 ! Select active offload device when available.
292 IF (offload_device_count > 0) THEN
293 offload_chosen_device = mod(default_para_env%mepos, offload_device_count)
294 CALL offload_set_chosen_device(offload_chosen_device)
295 active_device_id => offload_chosen_device
296 END IF
297
298 ! Initialize the DBCSR configuration
299 ! Attach the time handler hooks to DBCSR
300 CALL dbcsr_init_lib(default_para_env%get_handle(), timeset_hook, timestop_hook, &
301 cp_abort_hook, cp_warn_hook, io_unit=unit_nr, &
302 accdrv_active_device_id=active_device_id)
303 CALL pw_fpga_init()
304 CALL pw_gpu_init()
305 CALL grid_library_init()
306 CALL dbm_library_init()
307 ELSE
308 ierr = cp_failure_level
309 END IF
310
311 !sample peak memory
312 CALL m_memory()
313
314 END SUBROUTINE init_cp2k
315
316! **************************************************************************************************
317!> \brief cleanup after you have finished using this interface
318!> \param finalize_mpi if the mpi environment should be finalized
319!> \param ierr returns a number different from 0 if there was an error
320!> \author fawzi
321! **************************************************************************************************
322 SUBROUTINE finalize_cp2k(finalize_mpi, ierr)
323 LOGICAL, INTENT(in) :: finalize_mpi
324 INTEGER, INTENT(out) :: ierr
325
326 INTEGER :: ienv
327
328!sample peak memory
329
330 CALL m_memory()
331
332 IF (.NOT. module_initialized) THEN
333 ierr = cp_failure_level
334 ELSE
335 DO ienv = n_f_envs, 1, -1
336 CALL destroy_force_env(f_envs(ienv)%f_env%id_nr, ierr=ierr)
337 cpassert(ierr == 0)
338 END DO
339 DEALLOCATE (f_envs)
340
341 ! Finalize libraries (Offload)
344 CALL pw_gpu_finalize()
345 CALL pw_fpga_finalize()
347 ! Finalize the DBCSR library
348 CALL dbcsr_finalize_lib()
349
350 ! Finalize DLA-Future and pika runtime; if already finalized does nothing
352 CALL cp_dlaf_finalize()
353
356
357 ! Deallocate the bibliography
359 CALL rm_timer_env()
360 CALL rm_mp_perf_env()
363 IF (finalize_mpi) THEN
364 CALL mp_world_finalize()
365 END IF
366
367 ierr = 0
368 END IF
369 END SUBROUTINE finalize_cp2k
370
371! **************************************************************************************************
372!> \brief deallocates a f_env
373!> \param f_env the f_env to deallocate
374!> \author fawzi
375! **************************************************************************************************
376 RECURSIVE SUBROUTINE f_env_dealloc(f_env)
377 TYPE(f_env_type), POINTER :: f_env
378
379 INTEGER :: ierr
380
381 cpassert(ASSOCIATED(f_env))
382 CALL force_env_release(f_env%force_env)
383 CALL cp_logger_release(f_env%logger)
384 CALL timer_env_release(f_env%timer_env)
385 CALL mp_perf_env_release(f_env%mp_perf_env)
386 IF (f_env%old_path /= f_env%my_path) THEN
387 CALL m_chdir(f_env%old_path, ierr)
388 cpassert(ierr == 0)
389 END IF
390 END SUBROUTINE f_env_dealloc
391
392! **************************************************************************************************
393!> \brief createates a f_env
394!> \param f_env the f_env to createate
395!> \param force_env the force_environment to be stored
396!> \param timer_env the timer env to be stored
397!> \param mp_perf_env the mp performance environment to be stored
398!> \param id_nr ...
399!> \param logger ...
400!> \param old_dir ...
401!> \author fawzi
402! **************************************************************************************************
403 SUBROUTINE f_env_create(f_env, force_env, timer_env, mp_perf_env, id_nr, logger, old_dir)
404 TYPE(f_env_type), POINTER :: f_env
405 TYPE(force_env_type), POINTER :: force_env
406 TYPE(timer_env_type), POINTER :: timer_env
407 TYPE(mp_perf_env_type), POINTER :: mp_perf_env
408 INTEGER, INTENT(in) :: id_nr
409 TYPE(cp_logger_type), POINTER :: logger
410 CHARACTER(len=*), INTENT(in) :: old_dir
411
412 ALLOCATE (f_env)
413 f_env%force_env => force_env
414 CALL force_env_retain(f_env%force_env)
415 f_env%logger => logger
416 CALL cp_logger_retain(logger)
417 f_env%timer_env => timer_env
418 CALL timer_env_retain(f_env%timer_env)
419 f_env%mp_perf_env => mp_perf_env
420 CALL mp_perf_env_retain(f_env%mp_perf_env)
421 f_env%id_nr = id_nr
422 CALL m_getcwd(f_env%my_path)
423 f_env%old_path = old_dir
424 END SUBROUTINE f_env_create
425
426! **************************************************************************************************
427!> \brief ...
428!> \param f_env_id ...
429!> \param f_env ...
430! **************************************************************************************************
431 SUBROUTINE f_env_get_from_id(f_env_id, f_env)
432 INTEGER, INTENT(in) :: f_env_id
433 TYPE(f_env_type), POINTER :: f_env
434
435 INTEGER :: f_env_pos
436
437 NULLIFY (f_env)
438 f_env_pos = get_pos_of_env(f_env_id)
439 IF (f_env_pos < 1) THEN
440 cpabort("invalid env_id "//cp_to_string(f_env_id))
441 ELSE
442 f_env => f_envs(f_env_pos)%f_env
443 END IF
444
445 END SUBROUTINE f_env_get_from_id
446
447! **************************************************************************************************
448!> \brief adds the default environments of the f_env to the stack of the
449!> defaults, and returns a new error and sets failure to true if
450!> something went wrong
451!> \param f_env_id the f_env from where to take the defaults
452!> \param f_env will contain the f_env corresponding to f_env_id
453!> \param handle ...
454!> \author fawzi
455!> \note
456!> The following routines need to be synchronized wrt. adding/removing
457!> of the default environments (logging, performance,error):
458!> environment:cp2k_init, environment:cp2k_finalize,
459!> f77_interface:f_env_add_defaults, f77_interface:f_env_rm_defaults,
460!> f77_interface:create_force_env, f77_interface:destroy_force_env
461! **************************************************************************************************
462 SUBROUTINE f_env_add_defaults(f_env_id, f_env, handle)
463 INTEGER, INTENT(in) :: f_env_id
464 TYPE(f_env_type), POINTER :: f_env
465 INTEGER, INTENT(out), OPTIONAL :: handle
466
467 INTEGER :: f_env_pos, ierr
468 TYPE(cp_logger_type), POINTER :: logger
469
470 NULLIFY (f_env)
471 f_env_pos = get_pos_of_env(f_env_id)
472 IF (f_env_pos < 1) THEN
473 cpabort("invalid env_id "//cp_to_string(f_env_id))
474 ELSE
475 f_env => f_envs(f_env_pos)%f_env
476 logger => f_env%logger
477 cpassert(ASSOCIATED(logger))
478 CALL m_getcwd(f_env%old_path)
479 IF (f_env%old_path /= f_env%my_path) THEN
480 CALL m_chdir(trim(f_env%my_path), ierr)
481 cpassert(ierr == 0)
482 END IF
483 CALL add_mp_perf_env(f_env%mp_perf_env)
484 CALL add_timer_env(f_env%timer_env)
485 CALL cp_add_default_logger(logger)
486 IF (PRESENT(handle)) handle = cp_default_logger_stack_size()
487 END IF
488 END SUBROUTINE f_env_add_defaults
489
490! **************************************************************************************************
491!> \brief removes the default environments of the f_env to the stack of the
492!> defaults, and sets ierr accordingly to the failuers stored in error
493!> It also releases the error
494!> \param f_env the f_env from where to take the defaults
495!> \param ierr variable that will be set to a number different from 0 if
496!> error contains an error (otherwise it will be set to 0)
497!> \param handle ...
498!> \author fawzi
499!> \note
500!> The following routines need to be synchronized wrt. adding/removing
501!> of the default environments (logging, performance,error):
502!> environment:cp2k_init, environment:cp2k_finalize,
503!> f77_interface:f_env_add_defaults, f77_interface:f_env_rm_defaults,
504!> f77_interface:create_force_env, f77_interface:destroy_force_env
505! **************************************************************************************************
506 SUBROUTINE f_env_rm_defaults(f_env, ierr, handle)
507 TYPE(f_env_type), POINTER :: f_env
508 INTEGER, INTENT(out), OPTIONAL :: ierr
509 INTEGER, INTENT(in), OPTIONAL :: handle
510
511 INTEGER :: ierr2
512 TYPE(cp_logger_type), POINTER :: d_logger, logger
513 TYPE(mp_perf_env_type), POINTER :: d_mp_perf_env
514 TYPE(timer_env_type), POINTER :: d_timer_env
515
516 IF (ASSOCIATED(f_env)) THEN
517 IF (PRESENT(handle)) THEN
518 cpassert(handle == cp_default_logger_stack_size())
519 END IF
520
521 logger => f_env%logger
522 d_logger => cp_get_default_logger()
523 d_timer_env => get_timer_env()
524 d_mp_perf_env => get_mp_perf_env()
525 cpassert(ASSOCIATED(logger))
526 cpassert(ASSOCIATED(d_logger))
527 cpassert(ASSOCIATED(d_timer_env))
528 cpassert(ASSOCIATED(d_mp_perf_env))
529 cpassert(ASSOCIATED(logger, d_logger))
530 ! CPASSERT(ASSOCIATED(d_timer_env, f_env%timer_env))
531 cpassert(ASSOCIATED(d_mp_perf_env, f_env%mp_perf_env))
532 IF (f_env%old_path /= f_env%my_path) THEN
533 CALL m_chdir(trim(f_env%old_path), ierr2)
534 cpassert(ierr2 == 0)
535 END IF
536 IF (PRESENT(ierr)) THEN
537 ierr = 0
538 END IF
540 CALL rm_timer_env()
541 CALL rm_mp_perf_env()
542 ELSE
543 IF (PRESENT(ierr)) THEN
544 ierr = 0
545 END IF
546 END IF
547 END SUBROUTINE f_env_rm_defaults
548
549! **************************************************************************************************
550!> \brief creates a new force environment using the given input, and writing
551!> the output to the given output unit
552!> \param new_env_id will contain the id of the newly created environment
553!> \param input_declaration ...
554!> \param input_path where to read the input (if the input is given it can
555!> a virtual path)
556!> \param output_path filename (or name of the unit) for the output
557!> \param mpi_comm the mpi communicator to be used for this environment
558!> it will not be freed when you get rid of the force_env
559!> \param output_unit if given it should be the unit for the output
560!> and no file is open (should be valid on the processor with rank 0)
561!> \param owns_out_unit if the output unit should be closed upon destroing
562!> of the force_env (defaults to true if not default_output_unit)
563!> \param input the parsed input, if given and valid it is used
564!> instead of parsing from file
565!> \param ierr will return a number different from 0 if there was an error
566!> \param work_dir ...
567!> \param initial_variables key-value list of initial preprocessor variables
568!> \author fawzi
569!> \note
570!> The following routines need to be synchronized wrt. adding/removing
571!> of the default environments (logging, performance,error):
572!> environment:cp2k_init, environment:cp2k_finalize,
573!> f77_interface:f_env_add_defaults, f77_interface:f_env_rm_defaults,
574!> f77_interface:create_force_env, f77_interface:destroy_force_env
575! **************************************************************************************************
576 RECURSIVE SUBROUTINE create_force_env(new_env_id, input_declaration, input_path, &
577 output_path, mpi_comm, output_unit, owns_out_unit, &
578 input, ierr, work_dir, initial_variables)
579 INTEGER, INTENT(out) :: new_env_id
580 TYPE(section_type), POINTER :: input_declaration
581 CHARACTER(len=*), INTENT(in) :: input_path
582 CHARACTER(len=*), INTENT(in), OPTIONAL :: output_path
583
584 CLASS(mp_comm_type), INTENT(IN), OPTIONAL :: mpi_comm
585 INTEGER, INTENT(in), OPTIONAL :: output_unit
586 LOGICAL, INTENT(in), OPTIONAL :: owns_out_unit
587 TYPE(section_vals_type), OPTIONAL, POINTER :: input
588 INTEGER, INTENT(out), OPTIONAL :: ierr
589 CHARACTER(len=*), INTENT(in), OPTIONAL :: work_dir
590 CHARACTER(len=*), DIMENSION(:, :), OPTIONAL :: initial_variables
591
592 CHARACTER(len=*), PARAMETER :: routinen = 'create_force_env'
593
594 CHARACTER(len=default_path_length) :: old_dir, wdir
595 INTEGER :: handle, i, ierr2, iforce_eval, isubforce_eval, k, method_name_id, my_group, &
596 nforce_eval, ngroups, nsubforce_size, unit_nr
597 INTEGER, DIMENSION(:), POINTER :: group_distribution, i_force_eval, &
598 lgroup_distribution
599 LOGICAL :: check, do_qmmm_force_mixing, multiple_subsys, my_owns_out_unit, &
600 use_motion_section, use_multiple_para_env
601 TYPE(cp_logger_type), POINTER :: logger, my_logger
602 TYPE(mp_para_env_type), POINTER :: my_para_env, para_env
603 TYPE(eip_environment_type), POINTER :: eip_env
604 TYPE(embed_env_type), POINTER :: embed_env
605 TYPE(enumeration_type), POINTER :: enum
606 TYPE(f_env_p_type), DIMENSION(:), POINTER :: f_envs_old
607 TYPE(force_env_type), POINTER :: force_env, my_force_env
608 TYPE(fp_type), POINTER :: fp_env
609 TYPE(global_environment_type), POINTER :: globenv
610 TYPE(ipi_environment_type), POINTER :: ipi_env
611 TYPE(keyword_type), POINTER :: keyword
612 TYPE(meta_env_type), POINTER :: meta_env
613 TYPE(mixed_environment_type), POINTER :: mixed_env
614 TYPE(mp_perf_env_type), POINTER :: mp_perf_env
615 TYPE(nnp_type), POINTER :: nnp_env
616 TYPE(pwdft_environment_type), POINTER :: pwdft_env
617 TYPE(qmmm_env_type), POINTER :: qmmm_env
618 TYPE(qmmmx_env_type), POINTER :: qmmmx_env
619 TYPE(qs_environment_type), POINTER :: qs_env
620 TYPE(section_type), POINTER :: section
621 TYPE(section_vals_type), POINTER :: fe_section, force_env_section, force_env_sections, &
622 fp_section, input_file, qmmm_section, qmmmx_section, root_section, subsys_section, &
623 wrk_section
624 TYPE(timer_env_type), POINTER :: timer_env
625
626 cpassert(ASSOCIATED(input_declaration))
627 NULLIFY (para_env, force_env, timer_env, mp_perf_env, globenv, meta_env, &
628 fp_env, eip_env, pwdft_env, mixed_env, qs_env, qmmm_env, embed_env)
629 new_env_id = -1
630 IF (PRESENT(mpi_comm)) THEN
631 ALLOCATE (para_env)
632 para_env = mpi_comm
633 ELSE
634 para_env => default_para_env
635 CALL para_env%retain()
636 END IF
637
638 CALL timeset(routinen, handle)
639
640 CALL m_getcwd(old_dir)
641 wdir = old_dir
642 IF (PRESENT(work_dir)) THEN
643 IF (work_dir /= " ") THEN
644 CALL m_chdir(work_dir, ierr2)
645 IF (ierr2 /= 0) THEN
646 IF (PRESENT(ierr)) ierr = ierr2
647 RETURN
648 END IF
649 wdir = work_dir
650 END IF
651 END IF
652
653 IF (PRESENT(output_unit)) THEN
654 unit_nr = output_unit
655 ELSE
656 IF (para_env%is_source()) THEN
657 IF (output_path == "__STD_OUT__") THEN
658 unit_nr = default_output_unit
659 ELSE
660 CALL open_file(file_name=output_path, &
661 file_status="UNKNOWN", &
662 file_action="WRITE", &
663 file_position="APPEND", &
664 unit_number=unit_nr)
665 END IF
666 ELSE
667 unit_nr = -1
668 END IF
669 END IF
670
671 my_owns_out_unit = unit_nr /= default_output_unit
672 IF (PRESENT(owns_out_unit)) my_owns_out_unit = owns_out_unit
673 CALL globenv_create(globenv)
674 CALL cp2k_init(para_env, output_unit=unit_nr, globenv=globenv, input_file_name=input_path, &
675 wdir=wdir)
676 logger => cp_get_default_logger()
677 ! warning this is dangerous, I did not check that all the subfunctions
678 ! support it, the program might crash upon error
679
680 NULLIFY (input_file)
681 IF (PRESENT(input)) input_file => input
682 IF (.NOT. ASSOCIATED(input_file)) THEN
683 IF (PRESENT(initial_variables)) THEN
684 input_file => read_input(input_declaration, input_path, initial_variables, para_env=para_env)
685 ELSE
686 input_file => read_input(input_declaration, input_path, empty_initial_variables, para_env=para_env)
687 END IF
688 ELSE
689 CALL section_vals_retain(input_file)
690 END IF
691
692 CALL check_cp2k_input(input_declaration, input_file, para_env=para_env, output_unit=unit_nr)
693
694 root_section => input_file
695 CALL section_vals_retain(root_section)
696
697 IF (n_f_envs + 1 > SIZE(f_envs)) THEN
698 f_envs_old => f_envs
699 ALLOCATE (f_envs(n_f_envs + 10))
700 DO i = 1, n_f_envs
701 f_envs(i)%f_env => f_envs_old(i)%f_env
702 END DO
703 DO i = n_f_envs + 1, SIZE(f_envs)
704 NULLIFY (f_envs(i)%f_env)
705 END DO
706 DEALLOCATE (f_envs_old)
707 END IF
708
709 CALL cp2k_read(root_section, para_env, globenv)
710
711 CALL cp2k_setup(root_section, para_env, globenv)
712 ! Group Distribution
713 ALLOCATE (group_distribution(0:para_env%num_pe - 1))
714 group_distribution = 0
715 lgroup_distribution => group_distribution
716 ! Setup all possible force_env
717 force_env_sections => section_vals_get_subs_vals(root_section, "FORCE_EVAL")
718 CALL section_vals_val_get(root_section, "MULTIPLE_FORCE_EVALS%MULTIPLE_SUBSYS", &
719 l_val=multiple_subsys)
720 CALL multiple_fe_list(force_env_sections, root_section, i_force_eval, nforce_eval)
721 ! Enforce the deletion of the subsys (unless not explicitly required)
722 IF (.NOT. multiple_subsys) THEN
723 DO iforce_eval = 2, nforce_eval
724 wrk_section => section_vals_get_subs_vals(force_env_sections, "SUBSYS", &
725 i_rep_section=i_force_eval(iforce_eval))
726 CALL section_vals_remove_values(wrk_section)
727 END DO
728 END IF
729 nsubforce_size = nforce_eval - 1
730 use_multiple_para_env = .false.
731 use_motion_section = .true.
732 DO iforce_eval = 1, nforce_eval
733 NULLIFY (force_env_section, my_force_env, subsys_section)
734 ! Reference subsys from the first ordered force_eval
735 IF (.NOT. multiple_subsys) THEN
736 subsys_section => section_vals_get_subs_vals(force_env_sections, "SUBSYS", &
737 i_rep_section=i_force_eval(1))
738 END IF
739 ! Handling para_env in case of multiple force_eval
740 IF (use_multiple_para_env) THEN
741 ! Check that the order of the force_eval is the correct one
742 CALL section_vals_val_get(force_env_sections, "METHOD", i_val=method_name_id, &
743 i_rep_section=i_force_eval(1))
744 IF ((method_name_id /= do_mixed) .AND. (method_name_id /= do_embed)) &
745 CALL cp_abort(__location__, &
746 "In case of multiple force_eval the MAIN force_eval (the first in the list of FORCE_EVAL_ORDER or "// &
747 "the one omitted from that order list) must be a MIXED_ENV type calculation. Please check your "// &
748 "input file and possibly correct the MULTIPLE_FORCE_EVAL%FORCE_EVAL_ORDER. ")
749
750 IF (method_name_id == do_mixed) THEN
751 check = ASSOCIATED(force_env%mixed_env%sub_para_env)
752 cpassert(check)
753 ngroups = force_env%mixed_env%ngroups
754 my_group = lgroup_distribution(para_env%mepos)
755 isubforce_eval = iforce_eval - 1
756 ! If task not allocated on this procs skip setup..
757 IF (modulo(isubforce_eval - 1, ngroups) /= my_group) cycle
758 my_para_env => force_env%mixed_env%sub_para_env(my_group + 1)%para_env
759 my_logger => force_env%mixed_env%sub_logger(my_group + 1)%p
761 CALL cp_add_default_logger(my_logger)
762 END IF
763 IF (method_name_id == do_embed) THEN
764 check = ASSOCIATED(force_env%embed_env%sub_para_env)
765 cpassert(check)
766 ngroups = force_env%embed_env%ngroups
767 my_group = lgroup_distribution(para_env%mepos)
768 isubforce_eval = iforce_eval - 1
769 ! If task not allocated on this procs skip setup..
770 IF (modulo(isubforce_eval - 1, ngroups) /= my_group) cycle
771 my_para_env => force_env%embed_env%sub_para_env(my_group + 1)%para_env
772 my_logger => force_env%embed_env%sub_logger(my_group + 1)%p
774 CALL cp_add_default_logger(my_logger)
775 END IF
776 ELSE
777 my_para_env => para_env
778 END IF
779
780 ! Initialize force_env_section
781 ! No need to allocate one more force_env_section if only 1 force_eval
782 ! is provided.. this is in order to save memory..
783 IF (nforce_eval > 1) THEN
784 CALL section_vals_duplicate(force_env_sections, force_env_section, &
785 i_force_eval(iforce_eval), i_force_eval(iforce_eval))
786 IF (iforce_eval /= 1) use_motion_section = .false.
787 ELSE
788 force_env_section => force_env_sections
789 use_motion_section = .true.
790 END IF
791 CALL section_vals_val_get(force_env_section, "METHOD", i_val=method_name_id)
792
793 IF (method_name_id == do_qmmm) THEN
794 qmmmx_section => section_vals_get_subs_vals(force_env_section, "QMMM%FORCE_MIXING")
795 CALL section_vals_get(qmmmx_section, explicit=do_qmmm_force_mixing)
796 IF (do_qmmm_force_mixing) &
797 method_name_id = do_qmmmx ! QMMM Force-Mixing has its own (hidden) method_id
798 END IF
799
800 SELECT CASE (method_name_id)
801 CASE (do_fist)
802 CALL fist_create_force_env(my_force_env, root_section, my_para_env, globenv, &
803 force_env_section=force_env_section, subsys_section=subsys_section, &
804 use_motion_section=use_motion_section)
805
806 CASE (do_qs)
807 ALLOCATE (qs_env)
808 CALL qs_env_create(qs_env, globenv)
809 CALL qs_init(qs_env, my_para_env, root_section, globenv=globenv, force_env_section=force_env_section, &
810 subsys_section=subsys_section, use_motion_section=use_motion_section)
811 CALL force_env_create(my_force_env, root_section, qs_env=qs_env, para_env=my_para_env, globenv=globenv, &
812 force_env_section=force_env_section)
813
814 CASE (do_qmmm)
815 qmmm_section => section_vals_get_subs_vals(force_env_section, "QMMM")
816 ALLOCATE (qmmm_env)
817 CALL qmmm_env_create(qmmm_env, root_section, my_para_env, globenv, &
818 force_env_section, qmmm_section, subsys_section, use_motion_section)
819 CALL force_env_create(my_force_env, root_section, qmmm_env=qmmm_env, para_env=my_para_env, &
820 globenv=globenv, force_env_section=force_env_section)
821
822 CASE (do_qmmmx)
823 ALLOCATE (qmmmx_env)
824 CALL qmmmx_env_create(qmmmx_env, root_section, my_para_env, globenv, &
825 force_env_section, subsys_section, use_motion_section)
826 CALL force_env_create(my_force_env, root_section, qmmmx_env=qmmmx_env, para_env=my_para_env, &
827 globenv=globenv, force_env_section=force_env_section)
828
829 CASE (do_eip)
830 ALLOCATE (eip_env)
831 CALL eip_env_create(eip_env)
832 CALL eip_init(eip_env, root_section, my_para_env, force_env_section=force_env_section, &
833 subsys_section=subsys_section)
834 CALL force_env_create(my_force_env, root_section, eip_env=eip_env, para_env=my_para_env, &
835 globenv=globenv, force_env_section=force_env_section)
836
837 CASE (do_sirius)
838 IF (.NOT. cp_sirius_is_initialized()) THEN
839 IF (unit_nr > 0) WRITE (unit=unit_nr, fmt="(T2,A)", advance="NO") "SIRIUS| "
840 CALL cp_sirius_init()
841 END IF
842 ALLOCATE (pwdft_env)
843 CALL pwdft_env_create(pwdft_env)
844 CALL pwdft_init(pwdft_env, root_section, my_para_env, force_env_section=force_env_section, &
845 subsys_section=subsys_section, use_motion_section=use_motion_section)
846 CALL force_env_create(my_force_env, root_section, pwdft_env=pwdft_env, para_env=my_para_env, &
847 globenv=globenv, force_env_section=force_env_section)
848
849 CASE (do_mixed)
850 ALLOCATE (mixed_env)
851 CALL mixed_create_force_env(mixed_env, root_section, my_para_env, &
852 force_env_section=force_env_section, n_subforce_eval=nsubforce_size, &
853 use_motion_section=use_motion_section)
854 CALL force_env_create(my_force_env, root_section, mixed_env=mixed_env, para_env=my_para_env, &
855 globenv=globenv, force_env_section=force_env_section)
856 !TODO: the sub_force_envs should really be created via recursion
857 use_multiple_para_env = .true.
858 CALL cp_add_default_logger(logger) ! just to get the logger swapping started
859 lgroup_distribution => my_force_env%mixed_env%group_distribution
860
861 CASE (do_embed)
862 ALLOCATE (embed_env)
863 CALL embed_create_force_env(embed_env, root_section, my_para_env, &
864 force_env_section=force_env_section, n_subforce_eval=nsubforce_size, &
865 use_motion_section=use_motion_section)
866 CALL force_env_create(my_force_env, root_section, embed_env=embed_env, para_env=my_para_env, &
867 globenv=globenv, force_env_section=force_env_section)
868 !TODO: the sub_force_envs should really be created via recursion
869 use_multiple_para_env = .true.
870 CALL cp_add_default_logger(logger) ! just to get the logger swapping started
871 lgroup_distribution => my_force_env%embed_env%group_distribution
872
873 CASE (do_nnp)
874 ALLOCATE (nnp_env)
875 CALL nnp_init(nnp_env, root_section, my_para_env, force_env_section=force_env_section, &
876 subsys_section=subsys_section, use_motion_section=use_motion_section)
877 CALL force_env_create(my_force_env, root_section, nnp_env=nnp_env, para_env=my_para_env, &
878 globenv=globenv, force_env_section=force_env_section)
879
880 CASE (do_ipi)
881 ALLOCATE (ipi_env)
882 CALL ipi_init(ipi_env, root_section, my_para_env, force_env_section=force_env_section, &
883 subsys_section=subsys_section)
884 CALL force_env_create(my_force_env, root_section, ipi_env=ipi_env, para_env=my_para_env, &
885 globenv=globenv, force_env_section=force_env_section)
886
887 CASE DEFAULT
888 CALL create_force_eval_section(section)
889 keyword => section_get_keyword(section, "METHOD")
890 CALL keyword_get(keyword, enum=enum)
891 CALL cp_abort(__location__, &
892 "Invalid METHOD <"//trim(enum_i2c(enum, method_name_id))// &
893 "> was specified, ")
894 CALL section_release(section)
895 END SELECT
896
897 NULLIFY (meta_env, fp_env)
898 IF (use_motion_section) THEN
899 ! Metadynamics Setup
900 fe_section => section_vals_get_subs_vals(root_section, "MOTION%FREE_ENERGY")
901 CALL metadyn_read(meta_env, my_force_env, root_section, my_para_env, fe_section)
902 CALL force_env_set(my_force_env, meta_env=meta_env)
903 ! Flexible Partition Setup
904 fp_section => section_vals_get_subs_vals(root_section, "MOTION%FLEXIBLE_PARTITIONING")
905 ALLOCATE (fp_env)
906 CALL fp_env_create(fp_env)
907 CALL fp_env_read(fp_env, fp_section)
908 CALL fp_env_write(fp_env, fp_section)
909 CALL force_env_set(my_force_env, fp_env=fp_env)
910 END IF
911 ! Handle multiple force_eval
912 IF (nforce_eval > 1 .AND. iforce_eval == 1) THEN
913 ALLOCATE (my_force_env%sub_force_env(nsubforce_size))
914 ! Nullify subforce_env
915 DO k = 1, nsubforce_size
916 NULLIFY (my_force_env%sub_force_env(k)%force_env)
917 END DO
918 END IF
919 ! Reference the right force_env
920 IF (iforce_eval == 1) THEN
921 force_env => my_force_env
922 ELSE
923 force_env%sub_force_env(iforce_eval - 1)%force_env => my_force_env
924 END IF
925 ! Multiple para env for sub_force_eval
926 IF (.NOT. use_multiple_para_env) THEN
927 lgroup_distribution = iforce_eval
928 END IF
929 ! Release force_env_section
930 IF (nforce_eval > 1) CALL section_vals_release(force_env_section)
931 END DO
932 IF (use_multiple_para_env) &
934 DEALLOCATE (group_distribution)
935 DEALLOCATE (i_force_eval)
936 timer_env => get_timer_env()
938 CALL para_env%max(last_f_env_id)
939 last_f_env_id = last_f_env_id + 1
940 new_env_id = last_f_env_id
941 n_f_envs = n_f_envs + 1
942 CALL f_env_create(f_envs(n_f_envs)%f_env, logger=logger, &
943 timer_env=timer_env, mp_perf_env=mp_perf_env, force_env=force_env, &
944 id_nr=last_f_env_id, old_dir=old_dir)
945 CALL force_env_release(force_env)
946 CALL globenv_release(globenv)
947 CALL section_vals_release(root_section)
948 CALL mp_para_env_release(para_env)
949 CALL f_env_rm_defaults(f_envs(n_f_envs)%f_env, ierr=ierr)
950 CALL timestop(handle)
951
952 END SUBROUTINE create_force_env
953
954! **************************************************************************************************
955!> \brief deallocates the force_env with the given id
956!> \param env_id the id of the force_env to remove
957!> \param ierr will contain a number different from 0 if
958!> \param q_finalize ...
959!> \author fawzi
960!> \note
961!> The following routines need to be synchronized wrt. adding/removing
962!> of the default environments (logging, performance,error):
963!> environment:cp2k_init, environment:cp2k_finalize,
964!> f77_interface:f_env_add_defaults, f77_interface:f_env_rm_defaults,
965!> f77_interface:create_force_env, f77_interface:destroy_force_env
966! **************************************************************************************************
967 RECURSIVE SUBROUTINE destroy_force_env(env_id, ierr, q_finalize)
968 INTEGER, INTENT(in) :: env_id
969 INTEGER, INTENT(out) :: ierr
970 LOGICAL, INTENT(IN), OPTIONAL :: q_finalize
971
972 INTEGER :: env_pos, i
973 TYPE(f_env_type), POINTER :: f_env
974 TYPE(global_environment_type), POINTER :: globenv
975 TYPE(mp_para_env_type), POINTER :: para_env
976 TYPE(section_vals_type), POINTER :: root_section
977
978 NULLIFY (f_env)
979 CALL f_env_add_defaults(env_id, f_env)
980 env_pos = get_pos_of_env(env_id)
981 n_f_envs = n_f_envs - 1
982 DO i = env_pos, n_f_envs
983 f_envs(i)%f_env => f_envs(i + 1)%f_env
984 END DO
985 NULLIFY (f_envs(n_f_envs + 1)%f_env)
986
987 CALL force_env_get(f_env%force_env, globenv=globenv, &
988 root_section=root_section, para_env=para_env)
989
990 cpassert(ASSOCIATED(globenv))
991 NULLIFY (f_env%force_env%globenv)
992 CALL f_env_dealloc(f_env)
993 IF (PRESENT(q_finalize)) THEN
994 CALL cp2k_finalize(root_section, para_env, globenv, f_env%old_path, q_finalize)
995 ELSE
996 CALL cp2k_finalize(root_section, para_env, globenv, f_env%old_path)
997 END IF
998 CALL section_vals_release(root_section)
999 CALL globenv_release(globenv)
1000 DEALLOCATE (f_env)
1001 ierr = 0
1002 END SUBROUTINE destroy_force_env
1003
1004! **************************************************************************************************
1005!> \brief returns the number of atoms in the given force env
1006!> \param env_id id of the force_env
1007!> \param n_atom ...
1008!> \param ierr will return a number different from 0 if there was an error
1009!> \date 22.11.2010 (MK)
1010!> \author fawzi
1011! **************************************************************************************************
1012 SUBROUTINE get_natom(env_id, n_atom, ierr)
1013
1014 INTEGER, INTENT(IN) :: env_id
1015 INTEGER, INTENT(OUT) :: n_atom, ierr
1016
1017 TYPE(f_env_type), POINTER :: f_env
1018
1019 n_atom = 0
1020 NULLIFY (f_env)
1021 CALL f_env_add_defaults(env_id, f_env)
1022 n_atom = force_env_get_natom(f_env%force_env)
1023 CALL f_env_rm_defaults(f_env, ierr)
1024
1025 END SUBROUTINE get_natom
1026
1027! **************************************************************************************************
1028!> \brief returns the number of particles in the given force env
1029!> \param env_id id of the force_env
1030!> \param n_particle ...
1031!> \param ierr will return a number different from 0 if there was an error
1032!> \author Matthias Krack
1033!>
1034! **************************************************************************************************
1035 SUBROUTINE get_nparticle(env_id, n_particle, ierr)
1036
1037 INTEGER, INTENT(IN) :: env_id
1038 INTEGER, INTENT(OUT) :: n_particle, ierr
1039
1040 TYPE(f_env_type), POINTER :: f_env
1041
1042 n_particle = 0
1043 NULLIFY (f_env)
1044 CALL f_env_add_defaults(env_id, f_env)
1045 n_particle = force_env_get_nparticle(f_env%force_env)
1046 CALL f_env_rm_defaults(f_env, ierr)
1047
1048 END SUBROUTINE get_nparticle
1049
1050! **************************************************************************************************
1051!> \brief gets a cell
1052!> \param env_id id of the force_env
1053!> \param cell the array with the cell matrix
1054!> \param per periodicity
1055!> \param ierr will return a number different from 0 if there was an error
1056!> \author Joost VandeVondele
1057! **************************************************************************************************
1058 SUBROUTINE get_cell(env_id, cell, per, ierr)
1059
1060 INTEGER, INTENT(IN) :: env_id
1061 REAL(kind=dp), DIMENSION(3, 3) :: cell
1062 INTEGER, DIMENSION(3), OPTIONAL :: per
1063 INTEGER, INTENT(OUT) :: ierr
1064
1065 TYPE(cell_type), POINTER :: cell_full
1066 TYPE(f_env_type), POINTER :: f_env
1067
1068 NULLIFY (f_env)
1069 CALL f_env_add_defaults(env_id, f_env)
1070 NULLIFY (cell_full)
1071 CALL force_env_get(f_env%force_env, cell=cell_full)
1072 cpassert(ASSOCIATED(cell_full))
1073 cell = cell_full%hmat
1074 IF (PRESENT(per)) per(:) = cell_full%perd(:)
1075 CALL f_env_rm_defaults(f_env, ierr)
1076
1077 END SUBROUTINE get_cell
1078
1079! **************************************************************************************************
1080!> \brief gets the qmmm cell
1081!> \param env_id id of the force_env
1082!> \param cell the array with the cell matrix
1083!> \param ierr will return a number different from 0 if there was an error
1084!> \author Holly Judge
1085! **************************************************************************************************
1086 SUBROUTINE get_qmmm_cell(env_id, cell, ierr)
1087
1088 INTEGER, INTENT(IN) :: env_id
1089 REAL(kind=dp), DIMENSION(3, 3) :: cell
1090 INTEGER, INTENT(OUT) :: ierr
1091
1092 TYPE(cell_type), POINTER :: cell_qmmm
1093 TYPE(f_env_type), POINTER :: f_env
1094 TYPE(qmmm_env_type), POINTER :: qmmm_env
1095
1096 NULLIFY (f_env)
1097 CALL f_env_add_defaults(env_id, f_env)
1098 NULLIFY (cell_qmmm)
1099 CALL force_env_get(f_env%force_env, qmmm_env=qmmm_env)
1100 CALL get_qs_env(qmmm_env%qs_env, cell=cell_qmmm)
1101 cpassert(ASSOCIATED(cell_qmmm))
1102 cell = cell_qmmm%hmat
1103 CALL f_env_rm_defaults(f_env, ierr)
1104
1105 END SUBROUTINE get_qmmm_cell
1106
1107! **************************************************************************************************
1108!> \brief gets a result from CP2K that is a real 1D array
1109!> \param env_id id of the force_env
1110!> \param description the tag of the result
1111!> \param N ...
1112!> \param RESULT ...
1113!> \param res_exist ...
1114!> \param ierr will return a number different from 0 if there was an error
1115!> \author Joost VandeVondele
1116! **************************************************************************************************
1117 SUBROUTINE get_result_r1(env_id, description, N, RESULT, res_exist, ierr)
1118 INTEGER :: env_id
1119 CHARACTER(LEN=default_string_length) :: description
1120 INTEGER :: n
1121 REAL(kind=dp), DIMENSION(1:N) :: result
1122 LOGICAL, OPTIONAL :: res_exist
1123 INTEGER :: ierr
1124
1125 INTEGER :: nres
1126 LOGICAL :: exist_res
1127 TYPE(cp_result_type), POINTER :: results
1128 TYPE(cp_subsys_type), POINTER :: subsys
1129 TYPE(f_env_type), POINTER :: f_env
1130
1131 NULLIFY (f_env, subsys, results)
1132 CALL f_env_add_defaults(env_id, f_env)
1133
1134 CALL force_env_get(f_env%force_env, subsys=subsys)
1135 CALL cp_subsys_get(subsys, results=results)
1136 ! first test for the result
1137 IF (PRESENT(res_exist)) THEN
1138 res_exist = test_for_result(results, description=description)
1139 exist_res = res_exist
1140 ELSE
1141 exist_res = .true.
1142 END IF
1143 ! if existing (or assuming the existence) read the results
1144 IF (exist_res) THEN
1145 CALL get_results(results, description=description, n_rep=nres)
1146 CALL get_results(results, description=description, values=result, nval=nres)
1147 END IF
1148
1149 CALL f_env_rm_defaults(f_env, ierr)
1150
1151 END SUBROUTINE get_result_r1
1152
1153! **************************************************************************************************
1154!> \brief gets the forces of the particles
1155!> \param env_id id of the force_env
1156!> \param frc the array where to write the forces
1157!> \param n_el number of positions (3*nparticle) just to check
1158!> \param ierr will return a number different from 0 if there was an error
1159!> \date 22.11.2010 (MK)
1160!> \author fawzi
1161! **************************************************************************************************
1162 SUBROUTINE get_force(env_id, frc, n_el, ierr)
1163
1164 INTEGER, INTENT(IN) :: env_id, n_el
1165 REAL(kind=dp), DIMENSION(1:n_el) :: frc
1166 INTEGER, INTENT(OUT) :: ierr
1167
1168 TYPE(f_env_type), POINTER :: f_env
1169
1170 NULLIFY (f_env)
1171 CALL f_env_add_defaults(env_id, f_env)
1172 CALL force_env_get_frc(f_env%force_env, frc, n_el)
1173 CALL f_env_rm_defaults(f_env, ierr)
1174
1175 END SUBROUTINE get_force
1176
1177! **************************************************************************************************
1178!> \brief gets the stress tensor
1179!> \param env_id id of the force_env
1180!> \param stress_tensor the array where to write the stress tensor
1181!> \param ierr will return a number different from 0 if there was an error
1182!> \author Ole Schuett
1183! **************************************************************************************************
1184 SUBROUTINE get_stress_tensor(env_id, stress_tensor, ierr)
1185
1186 INTEGER, INTENT(IN) :: env_id
1187 REAL(kind=dp), DIMENSION(3, 3), INTENT(OUT) :: stress_tensor
1188 INTEGER, INTENT(OUT) :: ierr
1189
1190 TYPE(cell_type), POINTER :: cell
1191 TYPE(cp_subsys_type), POINTER :: subsys
1192 TYPE(f_env_type), POINTER :: f_env
1193 TYPE(virial_type), POINTER :: virial
1194
1195 NULLIFY (f_env, subsys, virial, cell)
1196 stress_tensor(:, :) = 0.0_dp
1197
1198 CALL f_env_add_defaults(env_id, f_env)
1199 CALL force_env_get(f_env%force_env, subsys=subsys, cell=cell)
1200 CALL cp_subsys_get(subsys, virial=virial)
1201 IF (virial%pv_availability) THEN
1202 stress_tensor(:, :) = virial%pv_virial(:, :)/cell%deth
1203 END IF
1204 CALL f_env_rm_defaults(f_env, ierr)
1205
1206 END SUBROUTINE get_stress_tensor
1207
1208! **************************************************************************************************
1209!> \brief gets the positions of the particles
1210!> \param env_id id of the force_env
1211!> \param pos the array where to write the positions
1212!> \param n_el number of positions (3*nparticle) just to check
1213!> \param ierr will return a number different from 0 if there was an error
1214!> \date 22.11.2010 (MK)
1215!> \author fawzi
1216! **************************************************************************************************
1217 SUBROUTINE get_pos(env_id, pos, n_el, ierr)
1218
1219 INTEGER, INTENT(IN) :: env_id, n_el
1220 REAL(kind=dp), DIMENSION(1:n_el) :: pos
1221 INTEGER, INTENT(OUT) :: ierr
1222
1223 TYPE(f_env_type), POINTER :: f_env
1224
1225 NULLIFY (f_env)
1226 CALL f_env_add_defaults(env_id, f_env)
1227 CALL force_env_get_pos(f_env%force_env, pos, n_el)
1228 CALL f_env_rm_defaults(f_env, ierr)
1229
1230 END SUBROUTINE get_pos
1231
1232! **************************************************************************************************
1233!> \brief gets the velocities of the particles
1234!> \param env_id id of the force_env
1235!> \param vel the array where to write the velocities
1236!> \param n_el number of velocities (3*nparticle) just to check
1237!> \param ierr will return a number different from 0 if there was an error
1238!> \author fawzi
1239!> date 22.11.2010 (MK)
1240! **************************************************************************************************
1241 SUBROUTINE get_vel(env_id, vel, n_el, ierr)
1242
1243 INTEGER, INTENT(IN) :: env_id, n_el
1244 REAL(kind=dp), DIMENSION(1:n_el) :: vel
1245 INTEGER, INTENT(OUT) :: ierr
1246
1247 TYPE(f_env_type), POINTER :: f_env
1248
1249 NULLIFY (f_env)
1250 CALL f_env_add_defaults(env_id, f_env)
1251 CALL force_env_get_vel(f_env%force_env, vel, n_el)
1252 CALL f_env_rm_defaults(f_env, ierr)
1253
1254 END SUBROUTINE get_vel
1255
1256! **************************************************************************************************
1257!> \brief sets a new cell
1258!> \param env_id id of the force_env
1259!> \param new_cell the array with the cell matrix
1260!> \param ierr will return a number different from 0 if there was an error
1261!> \author Joost VandeVondele
1262! **************************************************************************************************
1263 SUBROUTINE set_cell(env_id, new_cell, ierr)
1264
1265 INTEGER, INTENT(IN) :: env_id
1266 REAL(kind=dp), DIMENSION(3, 3) :: new_cell
1267 INTEGER, INTENT(OUT) :: ierr
1268
1269 TYPE(cell_type), POINTER :: cell
1270 TYPE(cp_subsys_type), POINTER :: subsys
1271 TYPE(f_env_type), POINTER :: f_env
1272
1273 NULLIFY (f_env, cell, subsys)
1274 CALL f_env_add_defaults(env_id, f_env)
1275 NULLIFY (cell)
1276 CALL force_env_get(f_env%force_env, cell=cell)
1277 cpassert(ASSOCIATED(cell))
1278 cell%hmat = new_cell
1279 CALL init_cell(cell)
1280 CALL force_env_get(f_env%force_env, subsys=subsys)
1281 CALL cp_subsys_set(subsys, cell=cell)
1282 CALL f_env_rm_defaults(f_env, ierr)
1283
1284 END SUBROUTINE set_cell
1285
1286! **************************************************************************************************
1287!> \brief sets the positions of the particles
1288!> \param env_id id of the force_env
1289!> \param new_pos the array with the new positions
1290!> \param n_el number of positions (3*nparticle) just to check
1291!> \param ierr will return a number different from 0 if there was an error
1292!> \date 22.11.2010 updated (MK)
1293!> \author fawzi
1294! **************************************************************************************************
1295 SUBROUTINE set_pos(env_id, new_pos, n_el, ierr)
1296
1297 INTEGER, INTENT(IN) :: env_id, n_el
1298 REAL(kind=dp), DIMENSION(1:n_el) :: new_pos
1299 INTEGER, INTENT(OUT) :: ierr
1300
1301 TYPE(cp_subsys_type), POINTER :: subsys
1302 TYPE(f_env_type), POINTER :: f_env
1303
1304 NULLIFY (f_env)
1305 CALL f_env_add_defaults(env_id, f_env)
1306 NULLIFY (subsys)
1307 CALL force_env_get(f_env%force_env, subsys=subsys)
1308 CALL unpack_subsys_particles(subsys=subsys, r=new_pos)
1309 CALL f_env_rm_defaults(f_env, ierr)
1310
1311 END SUBROUTINE set_pos
1312
1313! **************************************************************************************************
1314!> \brief sets the velocities of the particles
1315!> \param env_id id of the force_env
1316!> \param new_vel the array with the new velocities
1317!> \param n_el number of velocities (3*nparticle) just to check
1318!> \param ierr will return a number different from 0 if there was an error
1319!> \date 22.11.2010 updated (MK)
1320!> \author fawzi
1321! **************************************************************************************************
1322 SUBROUTINE set_vel(env_id, new_vel, n_el, ierr)
1323
1324 INTEGER, INTENT(IN) :: env_id, n_el
1325 REAL(kind=dp), DIMENSION(1:n_el) :: new_vel
1326 INTEGER, INTENT(OUT) :: ierr
1327
1328 TYPE(cp_subsys_type), POINTER :: subsys
1329 TYPE(f_env_type), POINTER :: f_env
1330
1331 NULLIFY (f_env)
1332 CALL f_env_add_defaults(env_id, f_env)
1333 NULLIFY (subsys)
1334 CALL force_env_get(f_env%force_env, subsys=subsys)
1335 CALL unpack_subsys_particles(subsys=subsys, v=new_vel)
1336 CALL f_env_rm_defaults(f_env, ierr)
1337
1338 END SUBROUTINE set_vel
1339
1340! **************************************************************************************************
1341!> \brief updates the energy and the forces of given force_env
1342!> \param env_id id of the force_env that you want to update
1343!> \param calc_force if the forces should be updated, if false the forces
1344!> might be wrong.
1345!> \param ierr will return a number different from 0 if there was an error
1346!> \author fawzi
1347! **************************************************************************************************
1348 RECURSIVE SUBROUTINE calc_energy_force(env_id, calc_force, ierr)
1349
1350 INTEGER, INTENT(in) :: env_id
1351 LOGICAL, INTENT(in) :: calc_force
1352 INTEGER, INTENT(out) :: ierr
1353
1354 TYPE(cp_logger_type), POINTER :: logger
1355 TYPE(f_env_type), POINTER :: f_env
1356
1357 NULLIFY (f_env)
1358 CALL f_env_add_defaults(env_id, f_env)
1359 logger => cp_get_default_logger()
1360 CALL cp_iterate(logger%iter_info) ! add one to the iteration count
1362 CALL f_env_rm_defaults(f_env, ierr)
1363
1364 END SUBROUTINE calc_energy_force
1365
1366! **************************************************************************************************
1367!> \brief returns the energy of the last configuration calculated
1368!> \param env_id id of the force_env that you want to update
1369!> \param e_pot the potential energy of the system
1370!> \param ierr will return a number different from 0 if there was an error
1371!> \author fawzi
1372! **************************************************************************************************
1373 SUBROUTINE get_energy(env_id, e_pot, ierr)
1374
1375 INTEGER, INTENT(in) :: env_id
1376 REAL(kind=dp), INTENT(out) :: e_pot
1377 INTEGER, INTENT(out) :: ierr
1378
1379 TYPE(f_env_type), POINTER :: f_env
1380
1381 NULLIFY (f_env)
1382 CALL f_env_add_defaults(env_id, f_env)
1383 CALL force_env_get(f_env%force_env, potential_energy=e_pot)
1384 CALL f_env_rm_defaults(f_env, ierr)
1385
1386 END SUBROUTINE get_energy
1387
1388! **************************************************************************************************
1389!> \brief returns the energy of the configuration given by the positions
1390!> passed as argument
1391!> \param env_id id of the force_env that you want to update
1392!> \param pos array with the positions
1393!> \param n_el number of elements in pos (3*natom)
1394!> \param e_pot the potential energy of the system
1395!> \param ierr will return a number different from 0 if there was an error
1396!> \author fawzi
1397!> \note
1398!> utility call
1399! **************************************************************************************************
1400 RECURSIVE SUBROUTINE calc_energy(env_id, pos, n_el, e_pot, ierr)
1401
1402 INTEGER, INTENT(IN) :: env_id, n_el
1403 REAL(kind=dp), DIMENSION(1:n_el), INTENT(IN) :: pos
1404 REAL(kind=dp), INTENT(OUT) :: e_pot
1405 INTEGER, INTENT(OUT) :: ierr
1406
1407 REAL(kind=dp), DIMENSION(1) :: dummy_f
1408
1409 CALL calc_force(env_id, pos, n_el, e_pot, dummy_f, 0, ierr)
1410
1411 END SUBROUTINE calc_energy
1412
1413! **************************************************************************************************
1414!> \brief returns the energy of the configuration given by the positions
1415!> passed as argument
1416!> \param env_id id of the force_env that you want to update
1417!> \param pos array with the positions
1418!> \param n_el_pos number of elements in pos (3*natom)
1419!> \param e_pot the potential energy of the system
1420!> \param force array that will contain the forces
1421!> \param n_el_force number of elements in force (3*natom). If 0 the
1422!> forces are not calculated
1423!> \param ierr will return a number different from 0 if there was an error
1424!> \author fawzi
1425!> \note
1426!> utility call, but actually it could be a better and more efficient
1427!> interface to connect to other codes if cp2k would be deeply
1428!> refactored
1429! **************************************************************************************************
1430 RECURSIVE SUBROUTINE calc_force(env_id, pos, n_el_pos, e_pot, force, n_el_force, ierr)
1431
1432 INTEGER, INTENT(in) :: env_id, n_el_pos
1433 REAL(kind=dp), DIMENSION(1:n_el_pos), INTENT(in) :: pos
1434 REAL(kind=dp), INTENT(out) :: e_pot
1435 INTEGER, INTENT(in) :: n_el_force
1436 REAL(kind=dp), DIMENSION(1:n_el_force), &
1437 INTENT(inout) :: force
1438 INTEGER, INTENT(out) :: ierr
1439
1440 LOGICAL :: calc_f
1441
1442 calc_f = (n_el_force /= 0)
1443 CALL set_pos(env_id, pos, n_el_pos, ierr)
1444 IF (ierr == 0) CALL calc_energy_force(env_id, calc_f, ierr)
1445 IF (ierr == 0) CALL get_energy(env_id, e_pot, ierr)
1446 IF (calc_f .AND. (ierr == 0)) CALL get_force(env_id, force, n_el_force, ierr)
1447
1448 END SUBROUTINE calc_force
1449
1450! **************************************************************************************************
1451!> \brief performs a check of the input
1452!> \param input_declaration ...
1453!> \param input_file_path the path of the input file to check
1454!> \param output_file_path path of the output file (to which it is appended)
1455!> if it is "__STD_OUT__" the default_output_unit is used
1456!> \param echo_input if the parsed input should be written out with all the
1457!> defaults made explicit
1458!> \param mpi_comm the mpi communicator (if not given it uses the default
1459!> one)
1460!> \param initial_variables key-value list of initial preprocessor variables
1461!> \param ierr error control, if different from 0 there was an error
1462!> \author fawzi
1463! **************************************************************************************************
1464 SUBROUTINE check_input(input_declaration, input_file_path, output_file_path, &
1465 echo_input, mpi_comm, initial_variables, ierr)
1466 TYPE(section_type), POINTER :: input_declaration
1467 CHARACTER(len=*), INTENT(in) :: input_file_path, output_file_path
1468 LOGICAL, INTENT(in), OPTIONAL :: echo_input
1469 TYPE(mp_comm_type), INTENT(in), OPTIONAL :: mpi_comm
1470 CHARACTER(len=default_path_length), &
1471 DIMENSION(:, :), INTENT(IN) :: initial_variables
1472 INTEGER, INTENT(out) :: ierr
1473
1474 INTEGER :: unit_nr
1475 LOGICAL :: my_echo_input
1476 TYPE(cp_logger_type), POINTER :: logger
1477 TYPE(mp_para_env_type), POINTER :: para_env
1478 TYPE(section_vals_type), POINTER :: input_file
1479
1480 my_echo_input = .false.
1481 IF (PRESENT(echo_input)) my_echo_input = echo_input
1482
1483 IF (PRESENT(mpi_comm)) THEN
1484 ALLOCATE (para_env)
1485 para_env = mpi_comm
1486 ELSE
1487 para_env => default_para_env
1488 CALL para_env%retain()
1489 END IF
1490 IF (para_env%is_source()) THEN
1491 IF (output_file_path == "__STD_OUT__") THEN
1492 unit_nr = default_output_unit
1493 ELSE
1494 CALL open_file(file_name=output_file_path, file_status="UNKNOWN", &
1495 file_action="WRITE", file_position="APPEND", &
1496 unit_number=unit_nr)
1497 END IF
1498 ELSE
1499 unit_nr = -1
1500 END IF
1501
1502 NULLIFY (logger)
1503 CALL cp_logger_create(logger, para_env=para_env, &
1504 default_global_unit_nr=unit_nr, &
1505 close_global_unit_on_dealloc=.false.)
1506 CALL cp_add_default_logger(logger)
1507 CALL cp_logger_release(logger)
1508
1509 input_file => read_input(input_declaration, input_file_path, initial_variables=initial_variables, &
1510 para_env=para_env)
1511 CALL check_cp2k_input(input_declaration, input_file, para_env=para_env, output_unit=unit_nr)
1512 IF (my_echo_input .AND. (unit_nr > 0)) THEN
1513 CALL section_vals_write(input_file, &
1514 unit_nr=unit_nr, &
1515 hide_root=.true., &
1516 hide_defaults=.false.)
1517 END IF
1518 CALL section_vals_release(input_file)
1519
1520 CALL cp_logger_release(logger)
1521 CALL mp_para_env_release(para_env)
1522 ierr = 0
1524
1525 END SUBROUTINE check_input
1526
1527END 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:16
subroutine, public get_runtime_info()
...
Definition cp2k_info.F:321
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 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_set(subsys, atomic_kinds, particles, local_particles, molecules, molecule_kinds, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, results, cell)
sets various propreties of the subsys
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell)
returns information about various attributes of the given subsys
subroutine, public dbm_library_init()
Initialize DBM library.
Definition dbm_api.F:1482
subroutine, public dbm_library_finalize()
Finalize DBM library.
Definition dbm_api.F:1496
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:58
subroutine, public m_memory(mem)
Returns the total amount of memory [bytes] in use, if known, zero otherwise.
Definition machine.F:452
subroutine, public m_getcwd(curdir)
...
Definition machine.F:619
subroutine, public m_chdir(dir, ierror)
...
Definition machine.F:648
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:76
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:135
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, 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, cell, cell_ref, qmmm, qmmm_env_qm, force_env_section, subsys_section, use_motion_section, silent)
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:147
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:134
subroutine, public timer_env_release(timer_env)
releases the given timer env
Definition timings.F:173
subroutine, public timer_env_retain(timer_env)
retains the given timer env
Definition timings.F:158
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.