LCOV - code coverage report
Current view: top level - src/motion - neb_io.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4dc10b3) Lines: 207 226 91.6 %
Date: 2024-11-21 06:45:46 Functions: 6 6 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 I/O Module for Nudged Elastic Band Calculation
      10             : !> \note
      11             : !>      Numerical accuracy for parallel runs:
      12             : !>       Each replica starts the SCF run from the one optimized
      13             : !>       in a previous run. It may happen then energies and derivatives
      14             : !>       of a serial run and a parallel run could be slightly different
      15             : !>       'cause of a different starting density matrix.
      16             : !>       Exact results are obtained using:
      17             : !>          EXTRAPOLATION USE_GUESS in QS section (Teo 09.2006)
      18             : !> \author Teodoro Laino 10.2006
      19             : ! **************************************************************************************************
      20             : MODULE neb_io
      21             :    USE cell_types,                      ONLY: cell_type
      22             :    USE cp2k_info,                       ONLY: get_runtime_info
      23             :    USE cp_files,                        ONLY: close_file,&
      24             :                                               open_file
      25             :    USE cp_log_handling,                 ONLY: cp_add_default_logger,&
      26             :                                               cp_get_default_logger,&
      27             :                                               cp_logger_type,&
      28             :                                               cp_rm_default_logger,&
      29             :                                               cp_to_string
      30             :    USE cp_output_handling,              ONLY: cp_print_key_finished_output,&
      31             :                                               cp_print_key_unit_nr
      32             :    USE cp_units,                        ONLY: cp_unit_from_cp2k
      33             :    USE f77_interface,                   ONLY: f_env_add_defaults,&
      34             :                                               f_env_rm_defaults,&
      35             :                                               f_env_type
      36             :    USE force_env_types,                 ONLY: force_env_get,&
      37             :                                               use_mixed_force
      38             :    USE header,                          ONLY: cp2k_footer
      39             :    USE input_constants,                 ONLY: band_md_opt,&
      40             :                                               do_sm,&
      41             :                                               dump_xmol,&
      42             :                                               pot_neb_fe,&
      43             :                                               pot_neb_full,&
      44             :                                               pot_neb_me
      45             :    USE input_cp2k_neb,                  ONLY: create_band_section
      46             :    USE input_cp2k_restarts,             ONLY: write_restart
      47             :    USE input_enumeration_types,         ONLY: enum_i2c,&
      48             :                                               enumeration_type
      49             :    USE input_keyword_types,             ONLY: keyword_get,&
      50             :                                               keyword_type
      51             :    USE input_section_types,             ONLY: section_get_keyword,&
      52             :                                               section_release,&
      53             :                                               section_type,&
      54             :                                               section_vals_get,&
      55             :                                               section_vals_get_subs_vals,&
      56             :                                               section_vals_type,&
      57             :                                               section_vals_val_get,&
      58             :                                               section_vals_val_set
      59             :    USE kinds,                           ONLY: default_path_length,&
      60             :                                               default_string_length,&
      61             :                                               dp
      62             :    USE machine,                         ONLY: m_flush
      63             :    USE neb_md_utils,                    ONLY: get_temperatures
      64             :    USE neb_types,                       ONLY: neb_type,&
      65             :                                               neb_var_type
      66             :    USE particle_methods,                ONLY: write_particle_coordinates
      67             :    USE particle_types,                  ONLY: get_particle_pos_or_vel,&
      68             :                                               particle_type
      69             :    USE physcon,                         ONLY: angstrom
      70             :    USE replica_types,                   ONLY: replica_env_type
      71             : #include "../base/base_uses.f90"
      72             : 
      73             :    IMPLICIT NONE
      74             :    PRIVATE
      75             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'neb_io'
      76             : 
      77             :    PUBLIC :: read_neb_section, &
      78             :              dump_neb_info, &
      79             :              dump_replica_coordinates, &
      80             :              handle_band_file_names, &
      81             :              neb_rep_env_map_info
      82             : 
      83             : CONTAINS
      84             : 
      85             : ! **************************************************************************************************
      86             : !> \brief Read data from the NEB input section
      87             : !> \param neb_env ...
      88             : !> \param neb_section ...
      89             : !> \author Teodoro Laino 09.2006
      90             : ! **************************************************************************************************
      91          34 :    SUBROUTINE read_neb_section(neb_env, neb_section)
      92             :       TYPE(neb_type), POINTER                            :: neb_env
      93             :       TYPE(section_vals_type), POINTER                   :: neb_section
      94             : 
      95             :       LOGICAL                                            :: explicit
      96             :       TYPE(section_vals_type), POINTER                   :: wrk_section
      97             : 
      98          34 :       CPASSERT(ASSOCIATED(neb_env))
      99          34 :       neb_env%istep = 0
     100          34 :       CALL section_vals_val_get(neb_section, "BAND_TYPE", i_val=neb_env%id_type)
     101          34 :       CALL section_vals_val_get(neb_section, "NUMBER_OF_REPLICA", i_val=neb_env%number_of_replica)
     102          34 :       CALL section_vals_val_get(neb_section, "K_SPRING", r_val=neb_env%K)
     103          34 :       CALL section_vals_val_get(neb_section, "ROTATE_FRAMES", l_val=neb_env%rotate_frames)
     104          34 :       CALL section_vals_val_get(neb_section, "ALIGN_FRAMES", l_val=neb_env%align_frames)
     105          34 :       CALL section_vals_val_get(neb_section, "OPTIMIZE_BAND%OPTIMIZE_END_POINTS", l_val=neb_env%optimize_end_points)
     106             :       ! Climb Image NEB
     107          34 :       CALL section_vals_val_get(neb_section, "CI_NEB%NSTEPS_IT", i_val=neb_env%nsteps_it)
     108             :       ! Band Optimization Type
     109          34 :       CALL section_vals_val_get(neb_section, "OPTIMIZE_BAND%OPT_TYPE", i_val=neb_env%opt_type)
     110             :       ! Use colvars
     111          34 :       CALL section_vals_val_get(neb_section, "USE_COLVARS", l_val=neb_env%use_colvar)
     112          34 :       CALL section_vals_val_get(neb_section, "POT_TYPE", i_val=neb_env%pot_type)
     113             :       ! Before continuing let's do some consistency check between keywords
     114          34 :       IF (neb_env%pot_type /= pot_neb_full) THEN
     115             :          ! Requires the use of colvars
     116           4 :          IF (.NOT. neb_env%use_colvar) &
     117             :             CALL cp_abort(__LOCATION__, &
     118             :                           "A potential energy function based on free energy or minimum energy"// &
     119             :                           " was requested without enabling the usage of COLVARS. Both methods"// &
     120           0 :                           " are based on COLVARS definition.")
     121             :          ! Moreover let's check if the proper sections have been defined..
     122           4 :          SELECT CASE (neb_env%pot_type)
     123             :          CASE (pot_neb_fe)
     124           0 :             wrk_section => section_vals_get_subs_vals(neb_env%root_section, "MOTION%MD")
     125           0 :             CALL section_vals_get(wrk_section, explicit=explicit)
     126           0 :             IF (.NOT. explicit) &
     127             :                CALL cp_abort(__LOCATION__, &
     128             :                              "A free energy BAND (colvars projected) calculation is requested"// &
     129           0 :                              " but NONE MD section was defined in the input.")
     130             :          CASE (pot_neb_me)
     131           4 :             wrk_section => section_vals_get_subs_vals(neb_env%root_section, "MOTION%GEO_OPT")
     132           4 :             CALL section_vals_get(wrk_section, explicit=explicit)
     133           4 :             IF (.NOT. explicit) &
     134             :                CALL cp_abort(__LOCATION__, &
     135             :                              "A minimum energy BAND (colvars projected) calculation is requested"// &
     136           8 :                              " but NONE GEO_OPT section was defined in the input.")
     137             :          END SELECT
     138             :       ELSE
     139          30 :          IF (neb_env%use_colvar) &
     140             :             CALL cp_abort(__LOCATION__, &
     141             :                           "A band calculation was requested with a full potential energy. USE_COLVAR cannot"// &
     142           0 :                           " be set for this kind of calculation!")
     143             :       END IF
     144             :       ! String Method
     145          34 :       CALL section_vals_val_get(neb_section, "STRING_METHOD%SMOOTHING", r_val=neb_env%smoothing)
     146          34 :       CALL section_vals_val_get(neb_section, "STRING_METHOD%SPLINE_ORDER", i_val=neb_env%spline_order)
     147          34 :       neb_env%reparametrize_frames = .FALSE.
     148          34 :       IF (neb_env%id_type == do_sm) THEN
     149           2 :          neb_env%reparametrize_frames = .TRUE.
     150             :       END IF
     151          34 :    END SUBROUTINE read_neb_section
     152             : 
     153             : ! **************************************************************************************************
     154             : !> \brief dump print info of a NEB run
     155             : !> \param neb_env ...
     156             : !> \param coords ...
     157             : !> \param vels ...
     158             : !> \param forces ...
     159             : !> \param particle_set ...
     160             : !> \param logger ...
     161             : !> \param istep ...
     162             : !> \param energies ...
     163             : !> \param distances ...
     164             : !> \param output_unit ...
     165             : !> \author Teodoro Laino 09.2006
     166             : ! **************************************************************************************************
     167         578 :    SUBROUTINE dump_neb_info(neb_env, coords, vels, forces, particle_set, logger, &
     168         578 :                             istep, energies, distances, output_unit)
     169             :       TYPE(neb_type), POINTER                            :: neb_env
     170             :       TYPE(neb_var_type), POINTER                        :: coords
     171             :       TYPE(neb_var_type), OPTIONAL, POINTER              :: vels, forces
     172             :       TYPE(particle_type), DIMENSION(:), POINTER         :: particle_set
     173             :       TYPE(cp_logger_type), POINTER                      :: logger
     174             :       INTEGER, INTENT(IN)                                :: istep
     175             :       REAL(KIND=dp), DIMENSION(:), INTENT(IN)            :: energies, distances
     176             :       INTEGER, INTENT(IN)                                :: output_unit
     177             : 
     178             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'dump_neb_info'
     179             : 
     180             :       CHARACTER(LEN=20)                                  :: mytype
     181             :       CHARACTER(LEN=default_string_length)               :: line, title, unit_str
     182             :       INTEGER                                            :: crd, ener, frc, handle, i, irep, ndig, &
     183             :                                                             ndigl, ttst, vel
     184             :       LOGICAL                                            :: explicit, lval, print_kind
     185             :       REAL(KIND=dp)                                      :: f_ann, tmp_r1, unit_conv
     186         578 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)           :: ekin, temperatures
     187             :       TYPE(cell_type), POINTER                           :: cell
     188             :       TYPE(enumeration_type), POINTER                    :: enum
     189             :       TYPE(keyword_type), POINTER                        :: keyword
     190             :       TYPE(section_type), POINTER                        :: section
     191             :       TYPE(section_vals_type), POINTER                   :: tc_section, vc_section
     192             : 
     193         578 :       CALL timeset(routineN, handle)
     194         578 :       ndig = CEILING(LOG10(REAL(neb_env%number_of_replica + 1, KIND=dp)))
     195         578 :       CALL force_env_get(neb_env%force_env, cell=cell)
     196        4152 :       DO irep = 1, neb_env%number_of_replica
     197        3574 :          ndigl = CEILING(LOG10(REAL(irep + 1, KIND=dp)))
     198        3574 :          WRITE (line, '(A,'//cp_to_string(ndig)//'("0"),T'//cp_to_string(11 + ndig + 1 - ndigl)//',I0)') "Replica_nr_", irep
     199             :          crd = cp_print_key_unit_nr(logger, neb_env%motion_print_section, "TRAJECTORY", &
     200        3574 :                                     extension=".xyz", file_form="FORMATTED", middle_name="pos-"//TRIM(line))
     201        3574 :          IF (PRESENT(vels)) THEN
     202             :             vel = cp_print_key_unit_nr(logger, neb_env%motion_print_section, "VELOCITIES", &
     203        3574 :                                        extension=".xyz", file_form="FORMATTED", middle_name="vel-"//TRIM(line))
     204             :          END IF
     205        3574 :          IF (PRESENT(forces)) THEN
     206             :             frc = cp_print_key_unit_nr(logger, neb_env%motion_print_section, "FORCES", &
     207        3574 :                                        extension=".xyz", file_form="FORMATTED", middle_name="force-"//TRIM(line))
     208             :          END IF
     209             :          ! Dump Trajectory
     210        3574 :          IF (crd > 0) THEN
     211             :             ! Gather units of measure for output
     212             :             CALL section_vals_val_get(neb_env%motion_print_section, "TRAJECTORY%UNIT", &
     213        1565 :                                       c_val=unit_str)
     214             :             CALL section_vals_val_get(neb_env%motion_print_section, "TRAJECTORY%PRINT_ATOM_KIND", &
     215        1565 :                                       l_val=print_kind)
     216        1565 :             unit_conv = cp_unit_from_cp2k(1.0_dp, TRIM(unit_str))
     217             :             ! This information can be digested by Molden
     218        1565 :             WRITE (UNIT=title, FMT="(A,I8,A,F20.10)") " i =", istep, ", E =", energies(irep)
     219             :             CALL write_particle_coordinates(particle_set, crd, dump_xmol, "POS", title, &
     220             :                                             cell=cell, array=coords%xyz(:, irep), unit_conv=unit_conv, &
     221        1565 :                                             print_kind=print_kind)
     222        1565 :             CALL m_flush(crd)
     223             :          END IF
     224             :          ! Dump Velocities
     225        3574 :          IF (vel > 0 .AND. PRESENT(vels)) THEN
     226             :             ! Gather units of measure for output
     227             :             CALL section_vals_val_get(neb_env%motion_print_section, "VELOCITIES%UNIT", &
     228           0 :                                       c_val=unit_str)
     229             :             CALL section_vals_val_get(neb_env%motion_print_section, "VELOCITIES%PRINT_ATOM_KIND", &
     230           0 :                                       l_val=print_kind)
     231           0 :             unit_conv = cp_unit_from_cp2k(1.0_dp, TRIM(unit_str))
     232           0 :             WRITE (UNIT=title, FMT="(A,I8,A,F20.10)") " i =", istep, ", E =", energies(irep)
     233             :             CALL write_particle_coordinates(particle_set, vel, dump_xmol, "VEL", title, &
     234             :                                             cell=cell, array=vels%xyz(:, irep), unit_conv=unit_conv, &
     235           0 :                                             print_kind=print_kind)
     236           0 :             CALL m_flush(vel)
     237             :          END IF
     238             :          ! Dump Forces
     239        3574 :          IF (frc > 0 .AND. PRESENT(forces)) THEN
     240             :             ! Gather units of measure for output
     241             :             CALL section_vals_val_get(neb_env%motion_print_section, "FORCES%UNIT", &
     242           0 :                                       c_val=unit_str)
     243             :             CALL section_vals_val_get(neb_env%motion_print_section, "FORCES%PRINT_ATOM_KIND", &
     244           0 :                                       l_val=print_kind)
     245           0 :             unit_conv = cp_unit_from_cp2k(1.0_dp, TRIM(unit_str))
     246           0 :             WRITE (UNIT=title, FMT="(A,I8,A,F20.10)") " i =", istep, ", E =", energies(irep)
     247             :             CALL write_particle_coordinates(particle_set, frc, dump_xmol, "FRC", title, &
     248             :                                             cell=cell, array=forces%xyz(:, irep), unit_conv=unit_conv, &
     249           0 :                                             print_kind=print_kind)
     250           0 :             CALL m_flush(frc)
     251             :          END IF
     252             :          CALL cp_print_key_finished_output(crd, logger, neb_env%motion_print_section, &
     253        3574 :                                            "TRAJECTORY")
     254        3574 :          IF (PRESENT(vels)) THEN
     255             :             CALL cp_print_key_finished_output(vel, logger, neb_env%motion_print_section, &
     256        3574 :                                               "VELOCITIES")
     257             :          END IF
     258        4152 :          IF (PRESENT(forces)) THEN
     259             :             CALL cp_print_key_finished_output(frc, logger, neb_env%motion_print_section, &
     260        3574 :                                               "FORCES")
     261             :          END IF
     262             :       END DO
     263             :       ! NEB summary info on screen
     264         578 :       IF (output_unit > 0) THEN
     265         289 :          tc_section => section_vals_get_subs_vals(neb_env%neb_section, "OPTIMIZE_BAND%MD%TEMP_CONTROL")
     266         289 :          vc_section => section_vals_get_subs_vals(neb_env%neb_section, "OPTIMIZE_BAND%MD%VEL_CONTROL")
     267         867 :          ALLOCATE (temperatures(neb_env%number_of_replica))
     268         578 :          ALLOCATE (ekin(neb_env%number_of_replica))
     269         289 :          CALL get_temperatures(vels, particle_set, temperatures, ekin=ekin)
     270         289 :          WRITE (output_unit, '(/)', ADVANCE="NO")
     271         289 :          WRITE (output_unit, FMT='(A,A)') ' **************************************', &
     272         578 :             '*****************************************'
     273         289 :          NULLIFY (section, keyword, enum)
     274         289 :          CALL create_band_section(section)
     275         289 :          keyword => section_get_keyword(section, "BAND_TYPE")
     276         289 :          CALL keyword_get(keyword, enum=enum)
     277         289 :          mytype = TRIM(enum_i2c(enum, neb_env%id_type))
     278             :          WRITE (output_unit, FMT='(A,T61,A)') &
     279         289 :             ' BAND TYPE                     =', ADJUSTR(mytype)
     280         289 :          CALL section_release(section)
     281             :          WRITE (output_unit, FMT='(A,T61,A)') &
     282         289 :             ' BAND TYPE OPTIMIZATION        =', ADJUSTR(neb_env%opt_type_label(1:20))
     283             :          WRITE (output_unit, '( A,T71,I10 )') &
     284         289 :             ' STEP NUMBER                   =', istep
     285         289 :          IF (neb_env%rotate_frames) WRITE (output_unit, '( A,T71,L10 )') &
     286          80 :             ' RMSD DISTANCE DEFINITION      =', neb_env%rotate_frames
     287             :          ! velocity control parameters output
     288         289 :          CALL section_vals_get(vc_section, explicit=explicit)
     289         289 :          IF (explicit) THEN
     290          88 :             CALL section_vals_val_get(vc_section, "PROJ_VELOCITY_VERLET", l_val=lval)
     291          88 :             IF (lval) WRITE (output_unit, '( A,T71,L10 )') &
     292          77 :                ' PROJECTED VELOCITY VERLET     =', lval
     293          88 :             CALL section_vals_val_get(vc_section, "SD_LIKE", l_val=lval)
     294          88 :             IF (lval) WRITE (output_unit, '( A,T71,L10)') &
     295           0 :                ' STEEPEST DESCENT LIKE         =', lval
     296          88 :             CALL section_vals_val_get(vc_section, "ANNEALING", r_val=f_ann)
     297          88 :             IF (f_ann /= 1.0_dp) THEN
     298             :                WRITE (output_unit, '( A,T71,F10.5)') &
     299          88 :                   ' ANNEALING FACTOR              = ', f_ann
     300             :             END IF
     301             :          END IF
     302             :          ! temperature control parameters output
     303         289 :          CALL section_vals_get(tc_section, explicit=explicit)
     304         289 :          IF (explicit) THEN
     305          32 :             CALL section_vals_val_get(tc_section, "TEMP_TOL_STEPS", i_val=ttst)
     306          32 :             IF (istep <= ttst) THEN
     307          22 :                CALL section_vals_val_get(tc_section, "TEMPERATURE", r_val=f_ann)
     308          22 :                tmp_r1 = cp_unit_from_cp2k(f_ann, "K")
     309             :                WRITE (output_unit, '( A,T71,F10.5)') &
     310          22 :                   ' TEMPERATURE TARGET            =', tmp_r1
     311             :             END IF
     312             :          END IF
     313             :          WRITE (output_unit, '( A,T71,I10 )') &
     314         289 :             ' NUMBER OF NEB REPLICA         =', neb_env%number_of_replica
     315             :          WRITE (output_unit, '( A,T17,4F16.6)') &
     316         289 :             ' DISTANCES REP =', distances(1:MIN(4, SIZE(distances)))
     317         289 :          IF (SIZE(distances) > 4) THEN
     318          74 :             WRITE (output_unit, '( T17,4F16.6)') distances(5:SIZE(distances))
     319             :          END IF
     320             :          WRITE (output_unit, '( A,T17,4F16.6)') &
     321         289 :             ' ENERGIES [au] =', energies(1:MIN(4, SIZE(energies)))
     322         289 :          IF (SIZE(energies) > 4) THEN
     323         198 :             WRITE (output_unit, '( T17,4F16.6)') energies(5:SIZE(energies))
     324             :          END IF
     325         289 :          IF (neb_env%opt_type == band_md_opt) THEN
     326             :             WRITE (output_unit, '( A,T33,4(1X,F11.5))') &
     327          88 :                ' REPLICA TEMPERATURES (K)      =', temperatures(1:MIN(4, SIZE(temperatures)))
     328         187 :             DO i = 5, SIZE(temperatures), 4
     329             :                WRITE (output_unit, '( T33,4(1X,F11.5))') &
     330         187 :                   temperatures(i:MIN(i + 3, SIZE(temperatures)))
     331             :             END DO
     332             :          END IF
     333             :          WRITE (output_unit, '( A,T56,F25.14)') &
     334         289 :             ' BAND TOTAL ENERGY [au]        =', SUM(energies(:) + ekin(:)) + &
     335        2365 :             neb_env%spring_energy
     336         289 :          WRITE (output_unit, FMT='(A,A)') ' **************************************', &
     337         578 :             '*****************************************'
     338         289 :          DEALLOCATE (ekin)
     339         867 :          DEALLOCATE (temperatures)
     340             :       END IF
     341             :       ! Ener file
     342             :       ener = cp_print_key_unit_nr(logger, neb_env%neb_section, "ENERGY", &
     343         578 :                                   extension=".ener", file_form="FORMATTED")
     344         578 :       IF (ener > 0) THEN
     345         289 :          WRITE (line, '(I0)') 2*neb_env%number_of_replica - 1
     346         289 :          WRITE (ener, '(I10,'//TRIM(line)//'(1X,F20.9))') istep, &
     347         578 :             energies, distances
     348             :       END IF
     349             :       CALL cp_print_key_finished_output(ener, logger, neb_env%neb_section, &
     350         578 :                                         "ENERGY")
     351             : 
     352             :       ! Dump Restarts
     353         578 :       CALL cp_add_default_logger(logger)
     354             :       CALL write_restart(force_env=neb_env%force_env, &
     355             :                          root_section=neb_env%root_section, &
     356             :                          coords=coords, &
     357         578 :                          vels=vels)
     358         578 :       CALL cp_rm_default_logger()
     359             : 
     360         578 :       CALL timestop(handle)
     361             : 
     362         578 :    END SUBROUTINE dump_neb_info
     363             : 
     364             : ! **************************************************************************************************
     365             : !> \brief dump coordinates of a replica NEB
     366             : !> \param particle_set ...
     367             : !> \param coords ...
     368             : !> \param i_rep ...
     369             : !> \param ienum ...
     370             : !> \param iw ...
     371             : !> \param use_colvar ...
     372             : !> \author Teodoro Laino 09.2006
     373             : ! **************************************************************************************************
     374         212 :    SUBROUTINE dump_replica_coordinates(particle_set, coords, i_rep, ienum, iw, use_colvar)
     375             : 
     376             :       TYPE(particle_type), DIMENSION(:), POINTER         :: particle_set
     377             :       TYPE(neb_var_type), POINTER                        :: coords
     378             :       INTEGER, INTENT(IN)                                :: i_rep, ienum, iw
     379             :       LOGICAL, INTENT(IN)                                :: use_colvar
     380             : 
     381             :       INTEGER                                            :: iatom, j
     382             :       REAL(KIND=dp), DIMENSION(3)                        :: r
     383             : 
     384         212 :       IF (iw > 0) THEN
     385          18 :          WRITE (iw, '(/,T2,"NEB|",75("*"))')
     386             :          WRITE (iw, '(T2,"NEB|",1X,A,I0,A)') &
     387          18 :             "Geometry for Replica Nr. ", ienum, " in Angstrom"
     388         948 :          DO iatom = 1, SIZE(particle_set)
     389         930 :             r(1:3) = get_particle_pos_or_vel(iatom, particle_set, coords%xyz(:, i_rep))
     390             :             WRITE (iw, '(T2,"NEB|",1X,A10,5X,3F15.9)') &
     391        4668 :                TRIM(particle_set(iatom)%atomic_kind%name), r(1:3)*angstrom
     392             :          END DO
     393          18 :          IF (use_colvar) THEN
     394          10 :             WRITE (iw, '(/,T2,"NEB|",1X,A10)') "COLLECTIVE VARIABLES:"
     395             :             WRITE (iw, '(T2,"NEB|",16X,3F15.9)') &
     396          20 :                (coords%int(j, i_rep), j=1, SIZE(coords%int(:, :), 1))
     397             :          END IF
     398          18 :          WRITE (iw, '(T2,"NEB|",75("*"))')
     399          18 :          CALL m_flush(iw)
     400             :       END IF
     401             : 
     402         212 :    END SUBROUTINE dump_replica_coordinates
     403             : 
     404             : ! **************************************************************************************************
     405             : !> \brief Handles the correct file names during a band calculation
     406             : !> \param rep_env ...
     407             : !> \param irep ...
     408             : !> \param n_rep ...
     409             : !> \param istep ...
     410             : !> \author Teodoro Laino  06.2009
     411             : ! **************************************************************************************************
     412        8376 :    SUBROUTINE handle_band_file_names(rep_env, irep, n_rep, istep)
     413             :       TYPE(replica_env_type), POINTER                    :: rep_env
     414             :       INTEGER, INTENT(IN)                                :: irep, n_rep, istep
     415             : 
     416             :       CHARACTER(len=*), PARAMETER :: routineN = 'handle_band_file_names'
     417             : 
     418             :       CHARACTER(LEN=default_path_length)                 :: output_file_path, replica_proj_name
     419             :       INTEGER                                            :: handle, handle2, i, ierr, j, lp, unit_nr
     420             :       TYPE(cp_logger_type), POINTER                      :: logger, sub_logger
     421             :       TYPE(f_env_type), POINTER                          :: f_env
     422             :       TYPE(section_vals_type), POINTER                   :: root_section
     423             : 
     424        2792 :       CALL timeset(routineN, handle)
     425             :       CALL f_env_add_defaults(f_env_id=rep_env%f_env_id, f_env=f_env, &
     426        2792 :                               handle=handle2)
     427        2792 :       logger => cp_get_default_logger()
     428        2792 :       CALL force_env_get(f_env%force_env, root_section=root_section)
     429        2792 :       j = irep + (rep_env%local_rep_indices(1) - 1)
     430             :       ! Get replica_project_name
     431        2792 :       replica_proj_name = get_replica_project_name(rep_env, n_rep, j)
     432        2792 :       lp = LEN_TRIM(replica_proj_name)
     433             :       CALL section_vals_val_set(root_section, "GLOBAL%PROJECT_NAME", &
     434        2792 :                                 c_val=TRIM(replica_proj_name))
     435        2792 :       logger%iter_info%project_name = replica_proj_name
     436             : 
     437             :       ! We change the file on which is pointing the global logger and error
     438        2792 :       output_file_path = replica_proj_name(1:lp)//".out"
     439             :       CALL section_vals_val_set(root_section, "GLOBAL%OUTPUT_FILE_NAME", &
     440        2792 :                                 c_val=TRIM(output_file_path))
     441        2792 :       IF (logger%default_global_unit_nr > 0) THEN
     442        2777 :          CALL close_file(logger%default_global_unit_nr)
     443             :          CALL open_file(file_name=output_file_path, file_status="UNKNOWN", &
     444             :                         file_action="WRITE", file_position="APPEND", &
     445             :                         unit_number=logger%default_global_unit_nr, &
     446        2777 :                         skip_get_unit_number=.TRUE.)
     447             :          WRITE (UNIT=logger%default_global_unit_nr, FMT="(/,(T2,A79))") &
     448        2777 :             "*******************************************************************************", &
     449        2777 :             "**                 BAND EVALUATION OF ENERGIES AND FORCES                    **", &
     450        5554 :             "*******************************************************************************"
     451        2777 :          WRITE (UNIT=logger%default_global_unit_nr, FMT="(T2,A,T79,A)") "**", "**"
     452        2777 :          WRITE (UNIT=logger%default_global_unit_nr, FMT="(T2,A,T79,A)") "**", "**"
     453             :          WRITE (UNIT=logger%default_global_unit_nr, FMT="(T2,A,I5,T41,A,I5,T79,A)") &
     454        2777 :             "** Replica Env Nr. :", rep_env%local_rep_indices(1) - 1, "Replica Band Nr. :", j, "**"
     455             :          WRITE (UNIT=logger%default_global_unit_nr, FMT="(T2,A,I5,T79,A)") &
     456        2777 :             "** Band  Step  Nr. :", istep, "**"
     457             :          WRITE (UNIT=logger%default_global_unit_nr, FMT="(T2,A79)") &
     458        2777 :             "*******************************************************************************"
     459             :       END IF
     460             : 
     461             :       ! Handle specific case for mixed_env
     462        2822 :       SELECT CASE (f_env%force_env%in_use)
     463             :       CASE (use_mixed_force)
     464        2852 :          DO i = 1, f_env%force_env%mixed_env%ngroups
     465          60 :             IF (MODULO(i - 1, f_env%force_env%mixed_env%ngroups) == &
     466          30 :                 f_env%force_env%mixed_env%group_distribution(f_env%force_env%mixed_env%para_env%mepos)) THEN
     467          30 :                sub_logger => f_env%force_env%mixed_env%sub_logger(i)%p
     468          30 :                sub_logger%iter_info%project_name = replica_proj_name(1:lp)//"-r-"//TRIM(ADJUSTL(cp_to_string(i)))
     469             : 
     470          30 :                unit_nr = sub_logger%default_global_unit_nr
     471          30 :                IF (unit_nr > 0) THEN
     472          30 :                   CALL close_file(unit_nr)
     473             : 
     474          30 :                   output_file_path = replica_proj_name(1:lp)//"-r-"//TRIM(ADJUSTL(cp_to_string(i)))//".out"
     475             :                   CALL open_file(file_name=output_file_path, file_status="UNKNOWN", &
     476             :                                  file_action="WRITE", file_position="APPEND", &
     477          30 :                                  unit_number=unit_nr, skip_get_unit_number=.TRUE.)
     478             :                END IF
     479             :             END IF
     480             :          END DO
     481             :       END SELECT
     482             : 
     483        2792 :       CALL f_env_rm_defaults(f_env=f_env, ierr=ierr, handle=handle2)
     484        2792 :       CPASSERT(ierr == 0)
     485        2792 :       CALL timestop(handle)
     486             : 
     487        2792 :    END SUBROUTINE handle_band_file_names
     488             : 
     489             : ! **************************************************************************************************
     490             : !> \brief  Constructs project names for BAND replicas
     491             : !> \param rep_env ...
     492             : !> \param n_rep ...
     493             : !> \param j ...
     494             : !> \return ...
     495             : !> \author Teodoro Laino  06.2009
     496             : ! **************************************************************************************************
     497        2916 :    FUNCTION get_replica_project_name(rep_env, n_rep, j) RESULT(replica_proj_name)
     498             :       TYPE(replica_env_type), POINTER                    :: rep_env
     499             :       INTEGER, INTENT(IN)                                :: n_rep, j
     500             :       CHARACTER(LEN=default_path_length)                 :: replica_proj_name
     501             : 
     502             :       CHARACTER(LEN=default_string_length)               :: padding
     503             :       INTEGER                                            :: i, lp, ndigits
     504             : 
     505             : ! Setup new replica project name and output file
     506             : 
     507        2916 :       replica_proj_name = rep_env%original_project_name
     508             :       ! Find padding
     509             :       ndigits = CEILING(LOG10(REAL(n_rep + 1, KIND=dp))) - &
     510        2916 :                 CEILING(LOG10(REAL(j + 1, KIND=dp)))
     511        2916 :       padding = ""
     512        3618 :       DO i = 1, ndigits
     513        3618 :          padding(i:i) = "0"
     514             :       END DO
     515        2916 :       lp = LEN_TRIM(replica_proj_name)
     516             :       replica_proj_name(lp + 1:LEN(replica_proj_name)) = "-BAND"// &
     517        2916 :                                                          TRIM(padding)//ADJUSTL(cp_to_string(j))
     518        2916 :    END FUNCTION get_replica_project_name
     519             : 
     520             : ! **************************************************************************************************
     521             : !> \brief  Print some mapping infos in the replica_env setup output files
     522             : !>         i.e. prints in which files one can find information for each band
     523             : !>         replica
     524             : !> \param rep_env ...
     525             : !> \param neb_env ...
     526             : !> \author Teodoro Laino  06.2009
     527             : ! **************************************************************************************************
     528          68 :    SUBROUTINE neb_rep_env_map_info(rep_env, neb_env)
     529             :       TYPE(replica_env_type), POINTER                    :: rep_env
     530             :       TYPE(neb_type), POINTER                            :: neb_env
     531             : 
     532             :       CHARACTER(LEN=default_path_length)                 :: replica_proj_name
     533             :       INTEGER                                            :: handle2, ierr, irep, n_rep, n_rep_neb, &
     534             :                                                             output_unit
     535             :       TYPE(cp_logger_type), POINTER                      :: logger
     536             :       TYPE(f_env_type), POINTER                          :: f_env
     537             : 
     538          34 :       n_rep_neb = neb_env%number_of_replica
     539          34 :       n_rep = rep_env%nrep
     540             :       CALL f_env_add_defaults(f_env_id=rep_env%f_env_id, f_env=f_env, &
     541          34 :                               handle=handle2)
     542          34 :       logger => cp_get_default_logger()
     543          34 :       output_unit = logger%default_global_unit_nr
     544          34 :       IF (output_unit > 0) THEN
     545             :          WRITE (UNIT=output_unit, FMT='(/,(T2,A79))') &
     546          33 :             "*******************************************************************************", &
     547          33 :             "**                  MAPPING OF BAND REPLICA TO REPLICA ENV                   **", &
     548          66 :             "*******************************************************************************"
     549             :          WRITE (UNIT=output_unit, FMT='(T2,A,I6,T32,A,T79,A)') &
     550          33 :             "** Replica Env Nr.: ", rep_env%local_rep_indices(1) - 1, &
     551          66 :             "working on the following BAND replicas", "**"
     552             :          WRITE (UNIT=output_unit, FMT='(T2,A79)') &
     553          33 :             "**                                                                           **"
     554             :       END IF
     555         158 :       DO irep = 1, n_rep_neb, n_rep
     556         124 :          replica_proj_name = get_replica_project_name(rep_env, n_rep_neb, irep + rep_env%local_rep_indices(1) - 1)
     557         158 :          IF (output_unit > 0) THEN
     558             :             WRITE (UNIT=output_unit, FMT='(T2,A,I6,T32,A,T79,A)') &
     559         119 :                "** Band Replica   Nr.: ", irep + rep_env%local_rep_indices(1) - 1, &
     560         238 :                "Output available on file: "//TRIM(replica_proj_name)//".out", "**"
     561             :          END IF
     562             :       END DO
     563          34 :       IF (output_unit > 0) THEN
     564             :          WRITE (UNIT=output_unit, FMT='(T2,A79)') &
     565          33 :             "**                                                                           **", &
     566          66 :             "*******************************************************************************"
     567          33 :          WRITE (UNIT=output_unit, FMT='(/)')
     568             :       END IF
     569             :       ! update runtime info before printing the footer
     570          34 :       CALL get_runtime_info()
     571             :       ! print footer
     572          34 :       CALL cp2k_footer(output_unit)
     573          34 :       CALL f_env_rm_defaults(f_env=f_env, ierr=ierr, handle=handle2)
     574          34 :       CPASSERT(ierr == 0)
     575          34 :    END SUBROUTINE neb_rep_env_map_info
     576             : 
     577             : END MODULE neb_io

Generated by: LCOV version 1.15