1!--------------------------------------------------------------------------------------------------!
2!   CP2K: A general program to perform molecular dynamics simulations                              !
3!   Copyright (C) 2000 - 2020  CP2K developers group                                               !
4!--------------------------------------------------------------------------------------------------!
5
6! **************************************************************************************************
7!> \brief Initialize a QM/MM calculation with Force-Mixing
8!> \author Ole Schuett
9! **************************************************************************************************
10MODULE qmmmx_create
11   USE cp_para_types,                   ONLY: cp_para_env_type
12   USE cp_subsys_types,                 ONLY: cp_subsys_type
13   USE global_types,                    ONLY: global_environment_type
14   USE input_section_types,             ONLY: section_vals_get_subs_vals,&
15                                              section_vals_release,&
16                                              section_vals_type
17   USE qmmm_create,                     ONLY: qmmm_env_create
18   USE qmmm_types,                      ONLY: qmmm_env_get,&
19                                              qmmm_env_release,&
20                                              qmmm_env_type
21   USE qmmmx_types,                     ONLY: qmmmx_env_type
22   USE qmmmx_util,                      ONLY: setup_force_mixing_qmmm_sections,&
23                                              update_force_mixing_labels
24#include "./base/base_uses.f90"
25
26   IMPLICIT NONE
27   PRIVATE
28
29   LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
30   CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qmmmx_create'
31
32   PUBLIC :: qmmmx_env_create
33
34CONTAINS
35
36! **************************************************************************************************
37!> \brief ...
38!> \param qmmmx_env ...
39!> \param root_section ...
40!> \param para_env ...
41!> \param globenv ...
42!> \param force_env_section ...
43!> \param subsys_section ...
44!> \param use_motion_section ...
45!> \par History
46!>      02.2012 created [noam]
47!> \author Noam Bernstein
48! **************************************************************************************************
49   SUBROUTINE qmmmx_env_create(qmmmx_env, root_section, para_env, globenv, &
50                               force_env_section, subsys_section, use_motion_section)
51      TYPE(qmmmx_env_type), POINTER                      :: qmmmx_env
52      TYPE(section_vals_type), POINTER                   :: root_section
53      TYPE(cp_para_env_type), POINTER                    :: para_env
54      TYPE(global_environment_type), POINTER             :: globenv
55      TYPE(section_vals_type), POINTER                   :: force_env_section, subsys_section
56      LOGICAL, INTENT(IN)                                :: use_motion_section
57
58      CHARACTER(len=*), PARAMETER :: routineN = 'qmmmx_env_create', &
59         routineP = moduleN//':'//routineN
60
61      TYPE(cp_subsys_type), POINTER                      :: subsys
62      TYPE(qmmm_env_type), POINTER                       :: dummy_qmmm_env
63      TYPE(section_vals_type), POINTER                   :: qmmm_core_section, &
64                                                            qmmm_extended_section, qmmm_section
65
66      NULLIFY (dummy_qmmm_env)
67
68      qmmm_section => section_vals_get_subs_vals(force_env_section, "QMMM")
69
70      CALL qmmm_env_create(dummy_qmmm_env, root_section, para_env, globenv, &
71                           force_env_section, qmmm_section, subsys_section, use_motion_section, &
72                           ignore_outside_box=.TRUE.)
73      CALL qmmm_env_get(dummy_qmmm_env, subsys=subsys)
74
75      CALL update_force_mixing_labels(subsys, qmmm_section)
76
77      ! using CUR_INDICES and CUR_LABELS, create appropriate QM_KIND sections for two QM/MM calculations
78      CALL setup_force_mixing_qmmm_sections(subsys, qmmm_section, qmmm_core_section, qmmm_extended_section)
79
80      ALLOCATE (qmmmx_env)
81      CALL qmmm_env_create(qmmmx_env%core, root_section, para_env, globenv, &
82                           force_env_section, qmmm_core_section, subsys_section, use_motion_section, &
83                           ignore_outside_box=.TRUE.)
84
85      CALL qmmm_env_create(qmmmx_env%ext, root_section, para_env, globenv, &
86                           force_env_section, qmmm_extended_section, subsys_section, use_motion_section, &
87                           ignore_outside_box=.TRUE.)
88
89      CALL section_vals_release(qmmm_core_section)
90      CALL section_vals_release(qmmm_extended_section)
91      CALL qmmm_env_release(dummy_qmmm_env)
92
93   END SUBROUTINE qmmmx_env_create
94
95END MODULE qmmmx_create
96