LCOV - code coverage report
Current view: top level - src - qmmm_create.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:2fce0f8) Lines: 156 159 98.1 %
Date: 2024-12-21 06:28:57 Functions: 1 1 100.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief Initialize a QM/MM calculation
      10             : !> \par History
      11             : !>      5.2004 created [fawzi]
      12             : !> \author Fawzi Mohamed
      13             : ! **************************************************************************************************
      14             : MODULE qmmm_create
      15             :    USE bibliography,                    ONLY: Golze2013,&
      16             :                                               Laino2005,&
      17             :                                               Laino2006,&
      18             :                                               cite_reference
      19             :    USE cell_methods,                    ONLY: write_cell
      20             :    USE cell_types,                      ONLY: cell_clone,&
      21             :                                               cell_release,&
      22             :                                               cell_type,&
      23             :                                               get_cell
      24             :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      25             :                                               cp_logger_type
      26             :    USE cp_output_handling,              ONLY: cp_print_key_finished_output,&
      27             :                                               cp_print_key_unit_nr
      28             :    USE cp_subsys_methods,               ONLY: create_small_subsys
      29             :    USE cp_subsys_types,                 ONLY: cp_subsys_release,&
      30             :                                               cp_subsys_type
      31             :    USE fist_environment,                ONLY: fist_init
      32             :    USE fist_environment_types,          ONLY: fist_env_create,&
      33             :                                               fist_env_get,&
      34             :                                               fist_env_set,&
      35             :                                               fist_environment_type
      36             :    USE fist_nonbond_env_types,          ONLY: fist_nonbond_env_type
      37             :    USE global_types,                    ONLY: global_environment_type
      38             :    USE header,                          ONLY: qmmm_header
      39             :    USE input_constants,                 ONLY: &
      40             :         do_fist, do_multipole_section_off, do_multipole_section_on, do_qmmm, &
      41             :         do_qmmm_center_every_step, do_qmmm_center_never, do_qmmm_center_pbc_aware, &
      42             :         do_qmmm_center_setup_only, do_qmmm_none, do_qs
      43             :    USE input_section_types,             ONLY: section_vals_get,&
      44             :                                               section_vals_get_subs_vals,&
      45             :                                               section_vals_type,&
      46             :                                               section_vals_val_get,&
      47             :                                               section_vals_val_set
      48             :    USE kinds,                           ONLY: default_string_length,&
      49             :                                               dp
      50             :    USE message_passing,                 ONLY: mp_para_env_type
      51             :    USE pw_env_types,                    ONLY: pw_env_type
      52             :    USE qmmm_init,                       ONLY: &
      53             :         assign_mm_charges_and_radius, move_or_add_atoms, print_image_charge_info, &
      54             :         print_qmmm_charges, print_qmmm_links, qmmm_init_gaussian_type, &
      55             :         qmmm_init_periodic_potential, qmmm_init_potential, setup_origin_mm_cell, setup_qmmm_links, &
      56             :         setup_qmmm_vars_mm, setup_qmmm_vars_qm
      57             :    USE qmmm_links_methods,              ONLY: qmmm_link_Imomm_coord
      58             :    USE qmmm_pw_grid,                    ONLY: qmmm_pw_grid_init
      59             :    USE qmmm_types,                      ONLY: qmmm_env_type
      60             :    USE qmmm_types_low,                  ONLY: add_set_release,&
      61             :                                               add_set_type,&
      62             :                                               add_shell_type,&
      63             :                                               qmmm_env_mm_create,&
      64             :                                               qmmm_env_mm_type,&
      65             :                                               qmmm_env_qm_create,&
      66             :                                               qmmm_env_qm_type,&
      67             :                                               qmmm_links_type
      68             :    USE qs_environment,                  ONLY: qs_init
      69             :    USE qs_environment_types,            ONLY: get_qs_env,&
      70             :                                               qs_env_create,&
      71             :                                               qs_environment_type,&
      72             :                                               set_qs_env
      73             : #include "./base/base_uses.f90"
      74             : 
      75             :    IMPLICIT NONE
      76             :    PRIVATE
      77             : 
      78             :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
      79             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qmmm_create'
      80             : 
      81             :    PUBLIC :: qmmm_env_create
      82             : 
      83             : CONTAINS
      84             : 
      85             : ! **************************************************************************************************
      86             : !> \brief ...
      87             : !> \param qmmm_env ...
      88             : !> \param root_section ...
      89             : !> \param para_env ...
      90             : !> \param globenv ...
      91             : !> \param force_env_section ...
      92             : !> \param qmmm_section ...
      93             : !> \param subsys_section ...
      94             : !> \param use_motion_section ...
      95             : !> \param prev_subsys ...
      96             : !> \param ignore_outside_box ...
      97             : !> \par History
      98             : !>      05.2004 created [fawzi]
      99             : !> \author Fawzi Mohamed
     100             : ! **************************************************************************************************
     101         394 :    SUBROUTINE qmmm_env_create(qmmm_env, root_section, para_env, globenv, &
     102             :                               force_env_section, qmmm_section, subsys_section, use_motion_section, prev_subsys, &
     103             :                               ignore_outside_box)
     104             :       TYPE(qmmm_env_type), INTENT(OUT)                   :: qmmm_env
     105             :       TYPE(section_vals_type), POINTER                   :: root_section
     106             :       TYPE(mp_para_env_type), POINTER                    :: para_env
     107             :       TYPE(global_environment_type), POINTER             :: globenv
     108             :       TYPE(section_vals_type), POINTER                   :: force_env_section, qmmm_section, &
     109             :                                                             subsys_section
     110             :       LOGICAL, INTENT(IN)                                :: use_motion_section
     111             :       TYPE(cp_subsys_type), OPTIONAL, POINTER            :: prev_subsys
     112             :       LOGICAL, INTENT(in), OPTIONAL                      :: ignore_outside_box
     113             : 
     114             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'qmmm_env_create'
     115             : 
     116             :       CHARACTER(len=default_string_length), &
     117         394 :          DIMENSION(:), POINTER                           :: qm_atom_type
     118             :       INTEGER                                            :: center_i, delta_charge, handle, iw, iw2, &
     119             :                                                             orig_charge, qmmm_coupl_type, &
     120             :                                                             use_multipole
     121         394 :       INTEGER, DIMENSION(:), POINTER                     :: mm_atom_index, mm_link_atoms, &
     122         394 :                                                             qm_atom_index
     123             :       LOGICAL                                            :: add_mm_charges, explicit, &
     124             :                                                             move_mm_charges, nocompatibility, &
     125             :                                                             qmmm_link, qmmm_link_Imomm, shell_model
     126         394 :       REAL(dp), DIMENSION(:), POINTER                    :: mm_atom_chrg, mm_el_pot_radius, &
     127         394 :                                                             mm_el_pot_radius_corr
     128             :       REAL(KIND=dp)                                      :: eps_mm_rspace
     129             :       REAL(KIND=dp), DIMENSION(3)                        :: abc_mm, abc_qm
     130         394 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: fist_scale_charge_link, &
     131         394 :                                                             mm_link_scale_factor
     132             :       TYPE(add_set_type), POINTER                        :: added_charges
     133             :       TYPE(add_shell_type), POINTER                      :: added_shells
     134             :       TYPE(cell_type), POINTER                           :: mm_cell, qm_cell_small, super_cell
     135             :       TYPE(cp_logger_type), POINTER                      :: logger
     136             :       TYPE(cp_subsys_type), POINTER                      :: subsys_mm, subsys_qm
     137             :       TYPE(fist_environment_type), POINTER               :: fist_env
     138             :       TYPE(fist_nonbond_env_type), POINTER               :: fist_nonbond_env
     139             :       TYPE(pw_env_type), POINTER                         :: pw_env
     140             :       TYPE(qmmm_env_mm_type), POINTER                    :: qmmm_env_mm
     141             :       TYPE(qmmm_env_qm_type), POINTER                    :: qmmm_env_qm
     142             :       TYPE(qmmm_links_type), POINTER                     :: qmmm_links
     143             :       TYPE(qs_environment_type), POINTER                 :: qs_env
     144             :       TYPE(section_vals_type), POINTER                   :: multipole_section, print_gen, &
     145             :                                                             print_section, qmmm_periodic
     146             : 
     147         394 :       CALL timeset(routineN, handle)
     148             : 
     149         394 :       NULLIFY (qm_atom_index, mm_atom_index, qm_atom_type)
     150         394 :       NULLIFY (qmmm_env_qm, subsys_mm, subsys_qm, mm_cell, qm_cell_small)
     151         394 :       NULLIFY (mm_atom_chrg, mm_el_pot_radius, qmmm_env_mm, fist_env)
     152         394 :       NULLIFY (mm_link_atoms, mm_link_scale_factor, qmmm_links, added_charges, added_shells)
     153         394 :       NULLIFY (fist_scale_charge_link, print_section, fist_nonbond_env)
     154         394 :       NULLIFY (print_gen, logger, mm_el_pot_radius_corr, super_cell, pw_env)
     155             : 
     156         394 :       logger => cp_get_default_logger()
     157             : 
     158             :       ! citations
     159         394 :       CALL cite_reference(Laino2005)
     160             : 
     161             :       ! Input section...
     162         394 :       IF (.NOT. ASSOCIATED(subsys_section)) THEN
     163           0 :          subsys_section => section_vals_get_subs_vals(force_env_section, "SUBSYS")
     164             :       END IF
     165         394 :       qmmm_periodic => section_vals_get_subs_vals(qmmm_section, "PERIODIC")
     166         394 :       multipole_section => section_vals_get_subs_vals(qmmm_section, "PERIODIC%MULTIPOLE")
     167         394 :       print_section => section_vals_get_subs_vals(qmmm_section, "PRINT")
     168         394 :       print_gen => section_vals_get_subs_vals(print_section, "PROGRAM_RUN_INFO")
     169         394 :       iw = cp_print_key_unit_nr(logger, print_gen, "", extension=".log")
     170             : 
     171             :       ! Create QM/MM Environments..
     172        6304 :       ALLOCATE (qmmm_env_qm)
     173         394 :       CALL qmmm_env_qm_create(qmmm_env_qm)
     174         394 :       ALLOCATE (qmmm_env_mm)
     175         394 :       CALL qmmm_env_mm_create(qmmm_env_mm)
     176             : 
     177             :       ! Set up QM/MM Options
     178             :       CALL setup_qmmm_vars_mm(qmmm_section, &
     179             :                               qmmm_env_mm, &
     180             :                               qm_atom_index, &
     181             :                               mm_link_atoms, &
     182             :                               mm_link_scale_factor, &
     183             :                               fist_scale_charge_link, &
     184             :                               qmmm_coupl_type, &
     185         394 :                               qmmm_link)
     186             : 
     187         394 :       qmmm_env_mm%qm_atom_index => qm_atom_index
     188         394 :       qmmm_env_mm%mm_link_atoms => mm_link_atoms
     189         394 :       qmmm_env_mm%mm_link_scale_factor => mm_link_scale_factor
     190         394 :       qmmm_env_mm%fist_scale_charge_link => fist_scale_charge_link
     191         394 :       qmmm_env_mm%qmmm_coupl_type = qmmm_coupl_type
     192         394 :       qmmm_env_mm%qmmm_link = qmmm_link
     193             :       ! Center the qm subsys into the qm box
     194         394 :       CALL section_vals_val_get(qmmm_section, "CENTER", i_val=center_i)
     195         394 :       IF (center_i == do_qmmm_center_never) THEN
     196          16 :          qmmm_env_qm%center_qm_subsys = .FALSE.
     197          16 :          qmmm_env_qm%center_qm_subsys0 = .FALSE.
     198         378 :       ELSE IF (center_i == do_qmmm_center_setup_only) THEN
     199          88 :          qmmm_env_qm%center_qm_subsys = .FALSE.
     200          88 :          qmmm_env_qm%center_qm_subsys0 = .TRUE.
     201         290 :       ELSE IF (center_i == do_qmmm_center_every_step) THEN
     202         290 :          qmmm_env_qm%center_qm_subsys = .TRUE.
     203         290 :          qmmm_env_qm%center_qm_subsys0 = .TRUE.
     204             :       ELSE
     205           0 :          CPABORT("Unknown type of CENTER! ")
     206             :       END IF
     207             : 
     208         394 :       CALL section_vals_val_get(qmmm_section, "CENTER_TYPE", i_val=center_i)
     209         394 :       qmmm_env_qm%center_qm_subsys_pbc_aware = (center_i == do_qmmm_center_pbc_aware)
     210             : 
     211             :       ! Compatibility with the QM/MM in CPMD code
     212         394 :       CALL section_vals_val_get(qmmm_section, "NOCOMPATIBILITY", l_val=nocompatibility)
     213         394 :       qmmm_env_qm%compatibility = .NOT. nocompatibility
     214             : 
     215             :       ! Parallel scheme for the long range
     216             :       CALL section_vals_val_get(qmmm_section, "PARALLEL_SCHEME", &
     217         394 :                                 i_val=qmmm_env_qm%par_scheme)
     218             : 
     219             :       ! Periodic boundary condition calculation
     220         394 :       CALL section_vals_get(qmmm_periodic, explicit=explicit)
     221         394 :       qmmm_env_qm%periodic = explicit
     222             :       !multipole section is switched on by default; switched off only if explicitly stated
     223         394 :       IF (qmmm_env_qm%periodic) qmmm_env_qm%multipole = .TRUE.
     224         394 :       CALL section_vals_get(multipole_section, explicit=explicit)
     225         394 :       CALL section_vals_val_get(multipole_section, "_SECTION_PARAMETERS_", i_val=use_multipole)
     226         394 :       IF (explicit .AND. use_multipole == do_multipole_section_off) qmmm_env_qm%multipole = .FALSE.
     227         394 :       IF (explicit .AND. use_multipole == do_multipole_section_on) qmmm_env_qm%multipole = .TRUE.
     228         394 :       IF (qmmm_env_qm%periodic .AND. qmmm_env_qm%multipole) CALL cite_reference(Laino2006)
     229         394 :       IF (qmmm_coupl_type == do_qmmm_none) THEN
     230          52 :          IF (qmmm_env_qm%periodic) &
     231             :             CALL cp_warn(__LOCATION__, &
     232             :                          "QMMM periodic calculation with coupling NONE was requested! "// &
     233             :                          "Switching off the periodic keyword since periodic and non-periodic "// &
     234           2 :                          "calculation with coupling NONE represent the same method! ")
     235          52 :          qmmm_env_qm%periodic = .FALSE.
     236             :       END IF
     237             : 
     238             :       ! First Initialize Fist...
     239         394 :       CALL section_vals_val_set(force_env_section, "METHOD", i_val=do_fist)
     240         394 :       ALLOCATE (fist_env)
     241         394 :       CALL fist_env_create(fist_env, para_env=para_env)
     242         394 :       CALL fist_env_set(fist_env, qmmm=.TRUE., qmmm_env=qmmm_env_mm)
     243             :       CALL fist_init(fist_env, root_section, para_env, force_env_section, &
     244         394 :                      subsys_section, use_motion_section, prev_subsys=prev_subsys)
     245         394 :       CALL fist_env_get(fist_env, subsys=subsys_mm, cell=mm_cell)
     246         394 :       mm_cell%tag = "CELL_MM"
     247             : 
     248             :       ! Set up QM/MM Options
     249             :       CALL setup_qmmm_vars_qm(qmmm_section, &
     250             :                               qmmm_env_qm, &
     251             :                               subsys_mm, &
     252             :                               qm_atom_type, &
     253             :                               qm_atom_index, &
     254             :                               mm_atom_index, &
     255             :                               qm_cell_small, &
     256             :                               qmmm_coupl_type, &
     257             :                               eps_mm_rspace, &
     258             :                               qmmm_link, &
     259         394 :                               para_env)
     260             : 
     261         394 :       qmmm_env_qm%qm_atom_index => qm_atom_index
     262         394 :       qmmm_env_qm%mm_atom_index => mm_atom_index
     263         394 :       qmmm_env_qm%eps_mm_rspace = eps_mm_rspace
     264         394 :       qmmm_env_qm%qmmm_coupl_type = qmmm_coupl_type
     265         394 :       qmmm_env_qm%qmmm_link = qmmm_link
     266         394 :       qmmm_env_qm%num_qm_atoms = SIZE(qm_atom_index)
     267         394 :       qmmm_env_qm%num_mm_atoms = SIZE(mm_atom_index)
     268         394 :       IF (qmmm_env_qm%image_charge) THEN
     269          10 :          qmmm_env_qm%num_image_mm_atoms = SIZE(qmmm_env_qm%image_charge_pot%image_mm_list)
     270          10 :          CALL cite_reference(Golze2013)
     271             :       END IF
     272             : 
     273             :       ! Duplicate structure for link atoms
     274         394 :       IF (qmmm_link) THEN
     275          64 :          IF (ASSOCIATED(mm_link_atoms)) THEN
     276         186 :             ALLOCATE (qmmm_env_qm%mm_link_atoms(SIZE(mm_link_atoms)))
     277         512 :             qmmm_env_qm%mm_link_atoms = mm_link_atoms
     278             :          END IF
     279             :       END IF
     280         394 :       IF (iw > 0) THEN
     281         167 :          WRITE (iw, '(A,I26)') " Number of QM atoms: ", qmmm_env_qm%num_qm_atoms
     282         167 :          WRITE (iw, '(A,I26)') " Number of MM atoms: ", qmmm_env_qm%num_mm_atoms
     283         167 :          IF (qmmm_env_qm%image_charge) THEN
     284           5 :             WRITE (iw, '(A,I8)') " Number of MM atoms with image charge: ", &
     285          10 :                qmmm_env_qm%num_image_mm_atoms
     286             :          END IF
     287         167 :          CALL write_cell(mm_cell, subsys_section)
     288             :       END IF
     289         394 :       CALL get_cell(qm_cell_small, abc=abc_qm)
     290         394 :       CALL get_cell(mm_cell, abc=abc_mm)
     291             : 
     292         394 :       IF (qmmm_env_qm%image_charge) THEN
     293          40 :          IF (ANY(ABS(abc_mm - abc_qm) > 1.0E-12)) &
     294           0 :             CPABORT("QM and MM box need to have the same size when using image charges")
     295             :       END IF
     296             : 
     297             :       ! Assign charges and mm_el_pot_radius from fist_topology
     298         394 :       CALL fist_env_get(fist_env, fist_nonbond_env=fist_nonbond_env)
     299        1180 :       ALLOCATE (mm_atom_chrg(SIZE(mm_atom_index)))
     300         786 :       ALLOCATE (mm_el_pot_radius(SIZE(mm_atom_index)))
     301         786 :       ALLOCATE (mm_el_pot_radius_corr(SIZE(mm_atom_index)))
     302      188174 :       mm_atom_chrg = 0.0_dp
     303      188174 :       mm_el_pot_radius = 0.0_dp
     304      188174 :       mm_el_pot_radius_corr = 0.0_dp
     305             : 
     306             :       CALL assign_mm_charges_and_radius(subsys=subsys_mm, &
     307             :                                         charges=fist_nonbond_env%charges, &
     308             :                                         mm_atom_chrg=mm_atom_chrg, &
     309             :                                         mm_el_pot_radius=mm_el_pot_radius, &
     310             :                                         mm_el_pot_radius_corr=mm_el_pot_radius_corr, &
     311             :                                         mm_atom_index=mm_atom_index, &
     312             :                                         mm_link_atoms=mm_link_atoms, &
     313             :                                         mm_link_scale_factor=mm_link_scale_factor, &
     314             :                                         added_shells=added_shells, &
     315         394 :                                         shell_model=shell_model)
     316             : 
     317         394 :       qmmm_env_qm%mm_atom_chrg => mm_atom_chrg
     318         394 :       qmmm_env_qm%mm_el_pot_radius => mm_el_pot_radius
     319         394 :       qmmm_env_qm%mm_el_pot_radius_corr => mm_el_pot_radius_corr
     320         394 :       qmmm_env_qm%added_shells => added_shells
     321             : 
     322         394 :       qmmm_link_Imomm = .FALSE.
     323         394 :       IF (qmmm_link) THEN
     324             :          CALL setup_qmmm_links(qmmm_section, qmmm_links, mm_el_pot_radius, &
     325          64 :                                mm_el_pot_radius_corr, mm_atom_index, iw)
     326          64 :          qmmm_env_qm%qmmm_links => qmmm_links
     327             : 
     328          64 :          CALL print_qmmm_links(qmmm_section, qmmm_links)
     329             : 
     330          64 :          CALL add_set_release(qmmm_env_qm%added_charges)
     331             :          CALL move_or_add_atoms(qmmm_section, move_mm_charges, add_mm_charges, &
     332             :                                 mm_atom_chrg, mm_el_pot_radius, mm_el_pot_radius_corr, &
     333          64 :                                 added_charges, mm_atom_index)
     334          64 :          qmmm_env_qm%move_mm_charges = move_mm_charges
     335          64 :          qmmm_env_qm%add_mm_charges = add_mm_charges
     336          64 :          qmmm_env_qm%added_charges => added_charges
     337          64 :          IF (ASSOCIATED(qmmm_links%imomm)) qmmm_link_imomm = (SIZE(qmmm_links%imomm) /= 0)
     338             :       END IF
     339             : 
     340             :       CALL print_qmmm_charges(mm_atom_index, mm_atom_chrg, mm_el_pot_radius, &
     341             :                               mm_el_pot_radius_corr, qmmm_env_qm%added_charges, &
     342         394 :                               qmmm_env_qm%added_shells, qmmm_section, nocompatibility, shell_model)
     343         394 :       IF (qmmm_env_qm%image_charge) THEN
     344          10 :          CALL print_image_charge_info(qmmm_env_qm, qmmm_section)
     345             :       END IF
     346             : 
     347         394 :       CALL section_vals_val_get(qmmm_section, "DELTA_CHARGE", i_val=delta_charge)
     348         394 :       CALL section_vals_val_get(force_env_section, "DFT%CHARGE", i_val=orig_charge)
     349         394 :       CALL section_vals_val_set(force_env_section, "DFT%CHARGE", i_val=orig_charge + delta_charge)
     350             : 
     351         394 :       CALL section_vals_val_set(force_env_section, "METHOD", i_val=do_qs)
     352             :       CALL create_small_subsys(subsys_qm, &
     353             :                                big_subsys=subsys_mm, small_para_env=para_env, &
     354             :                                small_cell=qm_cell_small, sub_atom_index=qm_atom_index, &
     355             :                                sub_atom_kind_name=qm_atom_type, para_env=para_env, &
     356             :                                force_env_section=force_env_section, subsys_section=subsys_section, &
     357         394 :                                ignore_outside_box=ignore_outside_box)
     358         394 :       IF (qmmm_link_imomm) CALL qmmm_link_Imomm_coord(qmmm_links, subsys_qm%particles%els, &
     359          62 :                                                       qm_atom_index)
     360         394 :       ALLOCATE (qs_env)
     361         394 :       CALL qs_env_create(qs_env, globenv)
     362             :       CALL qs_init(qs_env, para_env, root_section, globenv=globenv, cp_subsys=subsys_qm, &
     363             :                    cell=qm_cell_small, qmmm=.TRUE., qmmm_env_qm=qmmm_env_qm, &
     364             :                    force_env_section=force_env_section, subsys_section=subsys_section, &
     365         394 :                    use_motion_section=use_motion_section)
     366         394 :       CALL cp_subsys_release(subsys_qm)
     367             : 
     368         394 :       IF (qmmm_env_qm%periodic) THEN
     369          46 :          IF (.NOT. ASSOCIATED(super_cell)) THEN
     370        1380 :             ALLOCATE (super_cell)
     371             :          END IF
     372          46 :          CALL cell_clone(mm_cell, super_cell, tag="SUPER_CELL")
     373          46 :          CALL set_qs_env(qs_env, super_cell=super_cell, qmmm_periodic=qmmm_env_qm%periodic)
     374          46 :          CALL cell_release(super_cell)
     375             :       END IF
     376         394 :       CALL section_vals_val_set(force_env_section, "DFT%CHARGE", i_val=orig_charge)
     377         394 :       CALL cp_print_key_finished_output(iw, logger, print_gen, "")
     378             :       iw2 = cp_print_key_unit_nr(logger, qmmm_section, "PRINT%PROGRAM_BANNER", &
     379         394 :                                  extension=".qmmmLog")
     380         394 :       CALL qmmm_header(iw2)
     381             :       CALL cp_print_key_finished_output(iw2, logger, qmmm_section, &
     382         394 :                                         "PRINT%PROGRAM_BANNER")
     383             :       !
     384             :       ! Initialize MM Potential fitted with Gaussian
     385             :       !
     386             :       CALL qmmm_init_gaussian_type(qmmm_env_qm=qmmm_env_qm, &
     387             :                                    para_env=para_env, &
     388             :                                    qs_env=qs_env, &
     389             :                                    mm_atom_chrg=mm_atom_chrg, &
     390             :                                    added_charges=qmmm_env_qm%added_charges, &
     391             :                                    added_shells=qmmm_env_qm%added_shells, &
     392             :                                    print_section=print_section, &
     393         394 :                                    qmmm_section=qmmm_section)
     394             :       !
     395             :       ! Initialize the MM potential stored on vector
     396             :       !
     397             :       CALL qmmm_init_potential(qmmm_env_qm=qmmm_env_qm, &
     398             :                                mm_cell=mm_cell, &
     399             :                                added_charges=qmmm_env_qm%added_charges, &
     400             :                                added_shells=qmmm_env_qm%added_shells, &
     401         394 :                                print_section=print_section)
     402             :       !
     403             :       ! Initialize the qmmm_pw_grid
     404             :       !
     405         394 :       CALL get_qs_env(qs_env, pw_env=pw_env)
     406             :       CALL qmmm_pw_grid_init(qmmm_env=qmmm_env_qm, &
     407         394 :                              pw_env=pw_env)
     408             :       !
     409             :       ! Initialize the MM periodic potential
     410             :       !
     411             :       CALL qmmm_init_periodic_potential(qmmm_env_qm=qmmm_env_qm, &
     412             :                                         qm_cell_small=qm_cell_small, &
     413             :                                         mm_cell=mm_cell, &
     414             :                                         para_env=para_env, &
     415             :                                         qs_env=qs_env, &
     416             :                                         added_charges=qmmm_env_qm%added_charges, &
     417             :                                         added_shells=qmmm_env_qm%added_shells, &
     418             :                                         qmmm_periodic=qmmm_periodic, &
     419             :                                         print_section=print_section, &
     420         394 :                                         mm_atom_chrg=mm_atom_chrg)
     421             :       !
     422             :       ! Preparing for PBC...
     423             :       !
     424             :       CALL setup_origin_mm_cell(qmmm_section, qmmm_env_qm, qm_cell_small, &
     425         394 :                                 dr=pw_env%pw_pools(pw_env%auxbas_grid)%pool%pw_grid%dr)
     426             : 
     427         394 :       CALL cell_release(qm_cell_small)
     428             : 
     429             :       ! assemble the actual qmmm_env
     430         394 :       qmmm_env%qs_env => qs_env
     431         394 :       qmmm_env%fist_env => fist_env
     432         394 :       qmmm_env%qm => qmmm_env_qm
     433             : 
     434         394 :       CALL section_vals_val_set(force_env_section, "METHOD", i_val=do_qmmm)
     435         394 :       DEALLOCATE (qm_atom_type)
     436             : 
     437         394 :       CALL timestop(handle)
     438             : 
     439        3940 :    END SUBROUTINE qmmm_env_create
     440             : 
     441             : END MODULE qmmm_create

Generated by: LCOV version 1.15