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