LCOV - code coverage report
Current view: top level - src/motion - reftraj_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:b195825) Lines: 39 42 92.9 %
Date: 2024-04-20 06:29:22 Functions: 2 5 40.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 initialization of the reftraj structure used to analyse
      10             : !>     previously generated trajectories
      11             : !> \par History
      12             : !>      Created 10-07 [MI]
      13             : !> \author MI
      14             : ! **************************************************************************************************
      15             : MODULE reftraj_types
      16             : 
      17             :    USE cp_parser_types,                 ONLY: cp_parser_type,&
      18             :                                               parser_create,&
      19             :                                               parser_release
      20             :    USE input_section_types,             ONLY: section_vals_type,&
      21             :                                               section_vals_val_get
      22             :    USE kinds,                           ONLY: default_path_length,&
      23             :                                               dp
      24             :    USE message_passing,                 ONLY: mp_para_env_type
      25             : #include "../base/base_uses.f90"
      26             : 
      27             :    IMPLICIT NONE
      28             : 
      29             :    PRIVATE
      30             :    PUBLIC :: reftraj_type, reftraj_msd_type, &
      31             :              create_reftraj, release_reftraj
      32             : 
      33             :    INTEGER, PARAMETER, PUBLIC :: REFTRAJ_EVAL_NONE = 101
      34             :    INTEGER, PARAMETER, PUBLIC :: REFTRAJ_EVAL_ENERGY = 102
      35             :    INTEGER, PARAMETER, PUBLIC :: REFTRAJ_EVAL_ENERGY_FORCES = 103
      36             : 
      37             : ! **************************************************************************************************
      38             : !> \brief parameters related to the analysis of previously generated trajecorties
      39             : !> \author MI
      40             : ! **************************************************************************************************
      41             :    TYPE reftraj_info_type
      42             :       INTEGER                                  :: first_snapshot = 0
      43             :       INTEGER                                  :: last_snapshot = 0
      44             :       INTEGER                                  :: stride = 0
      45             :       INTEGER                                  :: eval = REFTRAJ_EVAL_NONE
      46             :       LOGICAL                                  :: variable_volume = .FALSE.
      47             :       LOGICAL                                  :: msd = .FALSE.
      48             :       TYPE(cp_parser_type), POINTER            :: traj_parser => NULL()
      49             :       TYPE(cp_parser_type), POINTER            :: cell_parser => NULL()
      50             :    END TYPE reftraj_info_type
      51             : 
      52             : ! **************************************************************************************************
      53             :    TYPE reftraj_msd_type
      54             :    LOGICAL                                  :: disp_atom = .FALSE., msd_kind = .FALSE., msd_molecule = .FALSE., msd_region = .FALSE.
      55             :       INTEGER                                  :: num_disp_atom = 0, ref0_unit = 0
      56             :       INTEGER, POINTER, DIMENSION(:)           :: disp_atom_index => NULL()
      57             :     REAL(KIND=dp)                            :: disp_atom_tol = 0.0_dp, drcom(3) = 0.0_dp, ref0_com(3) = 0.0_dp, total_mass = 0.0_dp
      58             :       REAL(KIND=dp), POINTER, DIMENSION(:, :)   :: disp_atom_dr => NULL()
      59             :       REAL(KIND=dp), POINTER, DIMENSION(:, :)   :: ref0_pos => NULL()
      60             :       REAL(KIND=dp), POINTER, DIMENSION(:, :)   :: ref0_com_molecule => NULL()
      61             :       REAL(KIND=dp), POINTER, DIMENSION(:, :)   :: val_msd_kind => NULL()
      62             :       REAL(KIND=dp), POINTER, DIMENSION(:, :)   :: val_msd_molecule => NULL()
      63             :       REAL(KIND=dp), POINTER, DIMENSION(:, :)   :: val_msd_region => NULL()
      64             :    END TYPE reftraj_msd_type
      65             : 
      66             : ! **************************************************************************************************
      67             :    TYPE reftraj_type
      68             :       INTEGER                                  :: itimes = 0
      69             :       INTEGER                                  :: itimes0 = 0
      70             :       INTEGER                                  :: isnap = 0
      71             :       INTEGER                                  :: natom = 0
      72             :       LOGICAL                                  :: init = .FALSE.
      73             :       REAL(KIND=dp)                            :: epot = 0.0_dp, epot0 = 0.0_dp, time = 0.0_dp, time0 = 0.0_dp
      74             :       TYPE(reftraj_info_type), POINTER         :: info => NULL()
      75             :       TYPE(reftraj_msd_type), POINTER          :: msd => NULL()
      76             :    END TYPE reftraj_type
      77             : 
      78             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'reftraj_types'
      79             : 
      80             : CONTAINS
      81             : 
      82             : ! **************************************************************************************************
      83             : !> \brief ...
      84             : !> \param reftraj ...
      85             : !> \param reftraj_section ...
      86             : !> \param para_env ...
      87             : ! **************************************************************************************************
      88         114 :    SUBROUTINE create_reftraj(reftraj, reftraj_section, para_env)
      89             : 
      90             :       TYPE(reftraj_type), INTENT(OUT)                    :: reftraj
      91             :       TYPE(section_vals_type), POINTER                   :: reftraj_section
      92             :       TYPE(mp_para_env_type), POINTER                    :: para_env
      93             : 
      94             :       CHARACTER(LEN=default_path_length)                 :: filename
      95             :       LOGICAL                                            :: old_eval_ef, old_eval_forces
      96             : 
      97             :       NULLIFY (reftraj%info)
      98             :       NULLIFY (reftraj%msd)
      99             : 
     100          38 :       ALLOCATE (reftraj%info)
     101             :       NULLIFY (reftraj%info%traj_parser)
     102             :       NULLIFY (reftraj%info%cell_parser)
     103             : 
     104             :       ! Initialize parser for trajectory
     105          38 :       CALL section_vals_val_get(reftraj_section, "TRAJ_FILE_NAME", c_val=filename)
     106         114 :       ALLOCATE (reftraj%info%traj_parser)
     107          38 :       CALL parser_create(reftraj%info%traj_parser, filename, para_env=para_env)
     108             : 
     109          38 :       CALL section_vals_val_get(reftraj_section, "VARIABLE_VOLUME", l_val=reftraj%info%variable_volume)
     110          38 :       IF (reftraj%info%variable_volume) THEN
     111             :          ! In case requested initialize parser for cell
     112          10 :          CALL section_vals_val_get(reftraj_section, "CELL_FILE_NAME", c_val=filename)
     113          30 :          ALLOCATE (reftraj%info%cell_parser)
     114          10 :          CALL parser_create(reftraj%info%cell_parser, filename, para_env=para_env)
     115             :       END IF
     116             : 
     117          38 :       CALL section_vals_val_get(reftraj_section, "FIRST_SNAPSHOT", i_val=reftraj%info%first_snapshot)
     118          38 :       CALL section_vals_val_get(reftraj_section, "LAST_SNAPSHOT", i_val=reftraj%info%last_snapshot)
     119          38 :       CALL section_vals_val_get(reftraj_section, "STRIDE", i_val=reftraj%info%stride)
     120          38 :       CALL section_vals_val_get(reftraj_section, "EVAL", i_val=reftraj%info%eval)
     121             : 
     122             :       ! Read deprecated keywords to retain backwards compatibility.
     123             :       ! For details see: https://github.com/cp2k/cp2k/issues/894
     124          38 :       CALL section_vals_val_get(reftraj_section, "EVAL_ENERGY_FORCES", l_val=old_eval_ef)
     125          38 :       CALL section_vals_val_get(reftraj_section, "EVAL_FORCES", l_val=old_eval_forces)
     126          38 :       IF (old_eval_ef) reftraj%info%eval = REFTRAJ_EVAL_ENERGY
     127          38 :       IF (old_eval_forces) reftraj%info%eval = REFTRAJ_EVAL_ENERGY_FORCES
     128             : 
     129             :       CALL section_vals_val_get(reftraj_section, "MSD%_SECTION_PARAMETERS_", &
     130          38 :                                 l_val=reftraj%info%msd)
     131             : 
     132          38 :    END SUBROUTINE create_reftraj
     133             : 
     134             : ! **************************************************************************************************
     135             : !> \brief ...
     136             : !> \param reftraj ...
     137             : !> \par History
     138             : !>      10.2007 created
     139             : !> \author MI
     140             : ! **************************************************************************************************
     141          38 :    SUBROUTINE release_reftraj(reftraj)
     142             : 
     143             :       TYPE(reftraj_type), INTENT(INOUT)                  :: reftraj
     144             : 
     145          38 :       IF (ASSOCIATED(reftraj%info%traj_parser)) THEN
     146          38 :          CALL parser_release(reftraj%info%traj_parser)
     147          38 :          DEALLOCATE (reftraj%info%traj_parser)
     148             :       END IF
     149          38 :       IF (ASSOCIATED(reftraj%info%cell_parser)) THEN
     150          10 :          CALL parser_release(reftraj%info%cell_parser)
     151          10 :          DEALLOCATE (reftraj%info%cell_parser)
     152             :       END IF
     153          38 :       IF (ASSOCIATED(reftraj%info)) THEN
     154          38 :          DEALLOCATE (reftraj%info)
     155             :       END IF
     156          38 :       IF (ASSOCIATED(reftraj%msd)) THEN
     157           2 :          DEALLOCATE (reftraj%msd%ref0_pos)
     158           2 :          IF (reftraj%msd%msd_kind) THEN
     159           2 :             DEALLOCATE (reftraj%msd%val_msd_kind)
     160             :          END IF
     161           2 :          IF (reftraj%msd%msd_molecule) THEN
     162           0 :             DEALLOCATE (reftraj%msd%val_msd_molecule)
     163           0 :             DEALLOCATE (reftraj%msd%ref0_com_molecule)
     164             :          END IF
     165           2 :          IF (reftraj%msd%disp_atom) THEN
     166           2 :             DEALLOCATE (reftraj%msd%disp_atom_index)
     167           2 :             DEALLOCATE (reftraj%msd%disp_atom_dr)
     168             :          END IF
     169             : 
     170           2 :          DEALLOCATE (reftraj%msd)
     171             :       END IF
     172             : 
     173          38 :    END SUBROUTINE release_reftraj
     174             : 
     175           0 : END MODULE reftraj_types

Generated by: LCOV version 1.15