LCOV - code coverage report
Current view: top level - src - fist_environment.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:936074a) Lines: 100.0 % 89 89
Test Date: 2025-12-04 06:27:48 Functions: 100.0 % 2 2

            Line data    Source code
       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 initialize fist environment
      10              : !> \author CJM
      11              : ! **************************************************************************************************
      12              : MODULE fist_environment
      13              :    USE atomic_kind_types,               ONLY: atomic_kind_type,&
      14              :                                               get_atomic_kind_set
      15              :    USE bibliography,                    ONLY: Devynck2012,&
      16              :                                               Dick1958,&
      17              :                                               Mitchell1993,&
      18              :                                               cite_reference
      19              :    USE cell_methods,                    ONLY: read_cell,&
      20              :                                               write_cell
      21              :    USE cell_types,                      ONLY: 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: cp_subsys_create
      29              :    USE cp_subsys_types,                 ONLY: cp_subsys_set,&
      30              :                                               cp_subsys_type
      31              :    USE cp_symmetry,                     ONLY: write_symmetry
      32              :    USE distribution_1d_types,           ONLY: distribution_1d_release,&
      33              :                                               distribution_1d_type
      34              :    USE distribution_methods,            ONLY: distribute_molecules_1d
      35              :    USE ewald_environment_types,         ONLY: ewald_env_create,&
      36              :                                               ewald_env_get,&
      37              :                                               ewald_env_set,&
      38              :                                               ewald_environment_type,&
      39              :                                               read_ewald_section
      40              :    USE ewald_pw_methods,                ONLY: ewald_pw_grid_update
      41              :    USE ewald_pw_types,                  ONLY: ewald_pw_create,&
      42              :                                               ewald_pw_type
      43              :    USE exclusion_types,                 ONLY: exclusion_type
      44              :    USE fist_efield_types,               ONLY: fist_efield_type,&
      45              :                                               read_efield_section
      46              :    USE fist_energy_types,               ONLY: allocate_fist_energy,&
      47              :                                               fist_energy_type
      48              :    USE fist_environment_types,          ONLY: fist_env_get,&
      49              :                                               fist_env_set,&
      50              :                                               fist_environment_type
      51              :    USE fist_nonbond_env_types,          ONLY: fist_nonbond_env_type
      52              :    USE force_fields,                    ONLY: force_field_control
      53              :    USE header,                          ONLY: fist_header
      54              :    USE input_section_types,             ONLY: section_vals_get_subs_vals,&
      55              :                                               section_vals_type
      56              :    USE kinds,                           ONLY: dp
      57              :    USE message_passing,                 ONLY: mp_para_env_type
      58              :    USE molecule_kind_types,             ONLY: molecule_kind_type,&
      59              :                                               write_molecule_kind_set
      60              :    USE molecule_types,                  ONLY: molecule_type
      61              :    USE multipole_types,                 ONLY: create_multipole_type,&
      62              :                                               multipole_type
      63              :    USE particle_list_types,             ONLY: particle_list_create,&
      64              :                                               particle_list_release,&
      65              :                                               particle_list_type
      66              :    USE particle_methods,                ONLY: write_fist_particle_coordinates,&
      67              :                                               write_particle_distances,&
      68              :                                               write_structure_data
      69              :    USE particle_types,                  ONLY: particle_type
      70              :    USE qmmm_types_low,                  ONLY: qmmm_env_mm_type
      71              : #include "./base/base_uses.f90"
      72              : 
      73              :    IMPLICIT NONE
      74              : 
      75              :    PRIVATE
      76              : 
      77              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'fist_environment'
      78              :    PUBLIC :: fist_init
      79              : 
      80              : CONTAINS
      81              : ! **************************************************************************************************
      82              : !> \brief reads the input and database file for fist
      83              : !> \param fist_env ...
      84              : !> \param root_section ...
      85              : !> \param para_env ...
      86              : !> \param force_env_section ...
      87              : !> \param subsys_section ...
      88              : !> \param use_motion_section ...
      89              : !> \param prev_subsys ...
      90              : !> \par Used By
      91              : !>      fist_main
      92              : ! **************************************************************************************************
      93         7929 :    SUBROUTINE fist_init(fist_env, root_section, para_env, force_env_section, &
      94              :                         subsys_section, use_motion_section, prev_subsys)
      95              : 
      96              :       TYPE(fist_environment_type), POINTER               :: fist_env
      97              :       TYPE(section_vals_type), POINTER                   :: root_section
      98              :       TYPE(mp_para_env_type), POINTER                    :: para_env
      99              :       TYPE(section_vals_type), POINTER                   :: force_env_section, subsys_section
     100              :       LOGICAL, INTENT(IN)                                :: use_motion_section
     101              :       TYPE(cp_subsys_type), OPTIONAL, POINTER            :: prev_subsys
     102              : 
     103              :       CHARACTER(len=*), PARAMETER                        :: routineN = 'fist_init'
     104              : 
     105              :       INTEGER                                            :: handle, iw
     106              :       LOGICAL                                            :: qmmm, shell_adiabatic, shell_present
     107              :       REAL(KIND=dp), DIMENSION(3)                        :: abc
     108              :       TYPE(cell_type), POINTER                           :: cell, cell_ref
     109              :       TYPE(cp_logger_type), POINTER                      :: logger
     110              :       TYPE(cp_subsys_type), POINTER                      :: subsys
     111              :       TYPE(ewald_environment_type), POINTER              :: ewald_env
     112         2643 :       TYPE(exclusion_type), DIMENSION(:), POINTER        :: exclusions
     113              :       TYPE(fist_efield_type), POINTER                    :: efield
     114              :       TYPE(fist_nonbond_env_type), POINTER               :: fist_nonbond_env
     115              :       TYPE(particle_list_type), POINTER                  :: core_particles, shell_particles
     116         2643 :       TYPE(particle_type), DIMENSION(:), POINTER         :: core_particle_set, shell_particle_set
     117              :       TYPE(qmmm_env_mm_type), POINTER                    :: qmmm_env
     118              :       TYPE(section_vals_type), POINTER                   :: cell_section, ewald_section, mm_section, &
     119              :                                                             poisson_section
     120              : 
     121         2643 :       CALL timeset(routineN, handle)
     122         2643 :       logger => cp_get_default_logger()
     123              : 
     124         2643 :       NULLIFY (subsys, cell, cell_ref)
     125         2643 :       NULLIFY (ewald_env, fist_nonbond_env, qmmm_env, cell_section, &
     126         2643 :                poisson_section, shell_particle_set, shell_particles, &
     127         2643 :                core_particle_set, core_particles, exclusions)
     128         2643 :       IF (.NOT. ASSOCIATED(subsys_section)) THEN
     129           26 :          subsys_section => section_vals_get_subs_vals(force_env_section, "SUBSYS")
     130              :       END IF
     131         2643 :       mm_section => section_vals_get_subs_vals(force_env_section, "MM")
     132         2643 :       cell_section => section_vals_get_subs_vals(subsys_section, "CELL")
     133         2643 :       poisson_section => section_vals_get_subs_vals(mm_section, "POISSON")
     134         2643 :       ewald_section => section_vals_get_subs_vals(poisson_section, "EWALD")
     135              : 
     136         2643 :       CALL fist_env_set(fist_env, input=force_env_section)
     137              : 
     138              :       iw = cp_print_key_unit_nr(logger, mm_section, "PRINT%PROGRAM_BANNER", &
     139         2643 :                                 extension=".mmLog")
     140         2643 :       CALL fist_header(iw)
     141         2643 :       CALL cp_print_key_finished_output(iw, logger, mm_section, "PRINT%PROGRAM_BANNER")
     142              : 
     143         2643 :       CALL read_cell(cell, cell_ref, cell_section=cell_section, para_env=para_env)
     144         2643 :       CALL get_cell(cell, abc=abc)
     145              : 
     146              :       ! Print the cell parameters
     147         2643 :       CALL write_cell(cell, subsys_section)
     148         2643 :       CALL write_cell(cell_ref, subsys_section)
     149              : 
     150              :       ! Create the ewald environment
     151        47574 :       ALLOCATE (ewald_env)
     152         2643 :       CALL ewald_env_create(ewald_env, para_env)
     153              : 
     154              :       ! Read the input section and set the ewald_env
     155         2643 :       CALL read_ewald_section(ewald_env, ewald_section)
     156         2643 :       CALL ewald_env_set(ewald_env, poisson_section=poisson_section)
     157              : 
     158              :       ! Read the efield section
     159         2643 :       NULLIFY (efield)
     160         2643 :       CALL read_efield_section(mm_section, efield)
     161         2643 :       CALL fist_env_set(fist_env, efield=efield)
     162              : 
     163              :       ! Topology
     164         2643 :       CALL fist_env_get(fist_env, qmmm=qmmm, qmmm_env=qmmm_env)
     165              :       CALL cp_subsys_create(subsys, para_env=para_env, root_section=root_section, &
     166              :                             force_env_section=force_env_section, subsys_section=subsys_section, &
     167              :                             qmmm=qmmm, qmmm_env=qmmm_env, exclusions=exclusions, &
     168         2643 :                             use_motion_section=use_motion_section)
     169         2643 :       CALL fist_env_set(fist_env, subsys=subsys, exclusions=exclusions)
     170              : 
     171              :       CALL force_field_control(subsys%atomic_kinds%els, subsys%particles%els, &
     172              :                                subsys%molecule_kinds%els, subsys%molecules%els, &
     173              :                                ewald_env, fist_nonbond_env, root_section, para_env, qmmm=qmmm, &
     174              :                                qmmm_env=qmmm_env, subsys_section=subsys_section, &
     175              :                                mm_section=mm_section, shell_particle_set=shell_particle_set, &
     176         2643 :                                core_particle_set=core_particle_set, cell=cell)
     177              : 
     178         2643 :       NULLIFY (shell_particles, core_particles)
     179         2643 :       IF (ASSOCIATED(shell_particle_set)) THEN
     180          256 :          CALL cite_reference(Devynck2012)
     181          256 :          CALL cite_reference(Mitchell1993)
     182          256 :          CALL cite_reference(Dick1958)
     183          256 :          CALL particle_list_create(shell_particles, els_ptr=shell_particle_set)
     184              :       END IF
     185         2643 :       IF (ASSOCIATED(core_particle_set)) THEN
     186          256 :          CALL particle_list_create(core_particles, els_ptr=core_particle_set)
     187              :       END IF
     188              :       CALL get_atomic_kind_set(atomic_kind_set=subsys%atomic_kinds%els, &
     189         2643 :                                shell_present=shell_present, shell_adiabatic=shell_adiabatic)
     190              :       CALL fist_env_set(fist_env, shell_model=shell_present, &
     191         2643 :                         shell_model_ad=shell_adiabatic)
     192              :       CALL cp_subsys_set(subsys, shell_particles=shell_particles, &
     193         2643 :                          core_particles=core_particles)
     194         2643 :       CALL particle_list_release(shell_particles)
     195         2643 :       CALL particle_list_release(core_particles)
     196              : 
     197              :       CALL fist_init_subsys(fist_env, subsys, cell, cell_ref, fist_nonbond_env, ewald_env, &
     198         2643 :                             force_env_section, subsys_section, prev_subsys)
     199              : 
     200         2643 :       CALL cell_release(cell)
     201         2643 :       CALL cell_release(cell_ref)
     202              : 
     203         2643 :       CALL timestop(handle)
     204              : 
     205         2643 :    END SUBROUTINE fist_init
     206              : 
     207              : ! **************************************************************************************************
     208              : !> \brief   Read the input and the database files for the setup of the
     209              : !>          FIST environment.
     210              : !> \param fist_env ...
     211              : !> \param subsys ...
     212              : !> \param cell ...
     213              : !> \param cell_ref ...
     214              : !> \param fist_nonbond_env ...
     215              : !> \param ewald_env ...
     216              : !> \param force_env_section ...
     217              : !> \param subsys_section ...
     218              : !> \param prev_subsys ...
     219              : !> \date    22.05.2000
     220              : !> \author  MK
     221              : !> \version 1.0
     222              : ! **************************************************************************************************
     223         7929 :    SUBROUTINE fist_init_subsys(fist_env, subsys, cell, cell_ref, fist_nonbond_env, &
     224              :                                ewald_env, force_env_section, subsys_section, &
     225              :                                prev_subsys)
     226              : 
     227              :       TYPE(fist_environment_type), POINTER               :: fist_env
     228              :       TYPE(cp_subsys_type), POINTER                      :: subsys
     229              :       TYPE(cell_type), POINTER                           :: cell, cell_ref
     230              :       TYPE(fist_nonbond_env_type), POINTER               :: fist_nonbond_env
     231              :       TYPE(ewald_environment_type), POINTER              :: ewald_env
     232              :       TYPE(section_vals_type), POINTER                   :: force_env_section, subsys_section
     233              :       TYPE(cp_subsys_type), OPTIONAL, POINTER            :: prev_subsys
     234              : 
     235              :       CHARACTER(len=*), PARAMETER                        :: routineN = 'fist_init_subsys'
     236              : 
     237              :       INTEGER                                            :: handle, max_multipole
     238              :       LOGICAL                                            :: do_multipoles
     239         2643 :       TYPE(atomic_kind_type), DIMENSION(:), POINTER      :: atomic_kind_set
     240              :       TYPE(distribution_1d_type), POINTER                :: local_molecules, local_particles, &
     241              :                                                             prev_local_molecules
     242              :       TYPE(ewald_pw_type), POINTER                       :: ewald_pw
     243              :       TYPE(fist_energy_type), POINTER                    :: thermo
     244         2643 :       TYPE(molecule_kind_type), DIMENSION(:), POINTER    :: molecule_kind_set, prev_molecule_kind_set
     245         2643 :       TYPE(molecule_type), DIMENSION(:), POINTER         :: molecule_set
     246              :       TYPE(multipole_type), POINTER                      :: multipoles
     247         2643 :       TYPE(particle_type), DIMENSION(:), POINTER         :: particle_set
     248              :       TYPE(section_vals_type), POINTER                   :: grid_print_section
     249              : 
     250         2643 :       CALL timeset(routineN, handle)
     251         2643 :       NULLIFY (thermo, ewald_pw, local_molecules, local_particles, multipoles)
     252         2643 :       particle_set => subsys%particles%els
     253         2643 :       atomic_kind_set => subsys%atomic_kinds%els
     254         2643 :       molecule_set => subsys%molecules%els
     255         2643 :       molecule_kind_set => subsys%molecule_kinds%els
     256              : 
     257         2643 :       IF (PRESENT(prev_subsys)) THEN
     258           44 :          prev_molecule_kind_set => prev_subsys%molecule_kinds%els
     259           44 :          prev_local_molecules => prev_subsys%local_molecules
     260              :       ELSE
     261         2599 :          NULLIFY (prev_molecule_kind_set)
     262         2599 :          NULLIFY (prev_local_molecules)
     263              :       END IF
     264              : 
     265              :       ! Create the fist_energy_type
     266         2643 :       CALL allocate_fist_energy(thermo)
     267              : 
     268              :       ! Print the molecule kind set
     269         2643 :       CALL write_molecule_kind_set(molecule_kind_set, subsys_section)
     270              : 
     271              :       ! Print the atomic coordinates
     272              :       CALL write_fist_particle_coordinates(particle_set, subsys_section, &
     273         2643 :                                            fist_nonbond_env%charges)
     274         2643 :       CALL write_particle_distances(particle_set, cell, subsys_section)
     275         2643 :       CALL write_structure_data(particle_set, cell=cell, input_section=subsys_section)
     276              : 
     277              :       ! Print symmetry information
     278         2643 :       CALL write_symmetry(particle_set, cell, subsys_section)
     279              : 
     280              :       ! Distribute molecules and atoms using the new data structures ***
     281              :       CALL distribute_molecules_1d(atomic_kind_set=atomic_kind_set, &
     282              :                                    particle_set=particle_set, &
     283              :                                    local_particles=local_particles, &
     284              :                                    molecule_kind_set=molecule_kind_set, &
     285              :                                    molecule_set=molecule_set, &
     286              :                                    local_molecules=local_molecules, &
     287              :                                    prev_molecule_kind_set=prev_molecule_kind_set, &
     288              :                                    prev_local_molecules=prev_local_molecules, &
     289         2643 :                                    force_env_section=force_env_section)
     290              : 
     291              :       ! Create ewald grids
     292              :       grid_print_section => section_vals_get_subs_vals(force_env_section, &
     293         2643 :                                                        "PRINT%GRID_INFORMATION")
     294         2643 :       ALLOCATE (ewald_pw)
     295         2643 :       CALL ewald_pw_create(ewald_pw, ewald_env, cell, cell_ref, grid_print_section)
     296              : 
     297              :       ! Initialize ewald grids
     298         2643 :       CALL ewald_pw_grid_update(ewald_pw, ewald_env, cell%hmat)
     299              : 
     300              :       ! Possibly Initialize the multipole environment
     301              :       CALL ewald_env_get(ewald_env, do_multipoles=do_multipoles, &
     302         2643 :                          max_multipole=max_multipole)
     303         2643 :       IF (do_multipoles) THEN
     304          690 :          ALLOCATE (multipoles)
     305          138 :          CALL create_multipole_type(multipoles, particle_set, subsys_section, max_multipole)
     306              :       END IF
     307         2643 :       CALL cp_subsys_set(subsys, multipoles=multipoles, cell=cell)
     308              : 
     309              :       ! Set the fist_env
     310              :       CALL fist_env_set(fist_env=fist_env, &
     311              :                         cell_ref=cell_ref, &
     312              :                         local_molecules=local_molecules, &
     313              :                         local_particles=local_particles, &
     314              :                         ewald_env=ewald_env, ewald_pw=ewald_pw, &
     315              :                         fist_nonbond_env=fist_nonbond_env, &
     316         2643 :                         thermo=thermo)
     317              : 
     318         2643 :       CALL distribution_1d_release(local_particles)
     319         2643 :       CALL distribution_1d_release(local_molecules)
     320         2643 :       CALL timestop(handle)
     321              : 
     322         2643 :    END SUBROUTINE fist_init_subsys
     323              : END MODULE fist_environment
        

Generated by: LCOV version 2.0-1