LCOV - code coverage report
Current view: top level - src - qmmm_links_methods.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:71c3ab0) Lines: 93.1 % 58 54
Test Date: 2026-07-25 06:35:44 Functions: 100.0 % 4 4

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief A collection of methods to treat the QM/MM links
      10              : !> \par History
      11              : !>      12.2004 created [tlaino]
      12              : !> \author Teodoro Laino
      13              : ! **************************************************************************************************
      14              : MODULE qmmm_links_methods
      15              : 
      16              :    USE cp_log_handling,                 ONLY: cp_to_string
      17              :    USE kinds,                           ONLY: dp
      18              :    USE particle_types,                  ONLY: particle_type
      19              :    USE qmmm_types_low,                  ONLY: add_set_type,&
      20              :                                               qmmm_env_qm_type,&
      21              :                                               qmmm_imomm_link_type,&
      22              :                                               qmmm_links_type
      23              : #include "./base/base_uses.f90"
      24              : 
      25              :    IMPLICIT NONE
      26              :    PRIVATE
      27              : 
      28              :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
      29              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qmmm_links_methods'
      30              :    PUBLIC ::  qmmm_link_Imomm_coord, &
      31              :              qmmm_link_Imomm_forces, &
      32              :              qmmm_added_chrg_coord, &
      33              :              qmmm_added_chrg_forces
      34              : 
      35              : CONTAINS
      36              : 
      37              : ! **************************************************************************************************
      38              : !> \brief correct the position for qm/mm IMOMM link type
      39              : !> \param qmmm_links ...
      40              : !> \param particles ...
      41              : !> \param qm_atom_index ...
      42              : !> \par History
      43              : !>      12.2004 created [tlaino]
      44              : !> \author Teodoro Laino
      45              : ! **************************************************************************************************
      46          338 :    SUBROUTINE qmmm_link_Imomm_coord(qmmm_links, particles, qm_atom_index)
      47              :       TYPE(qmmm_links_type), POINTER                     :: qmmm_links
      48              :       TYPE(particle_type), DIMENSION(:), POINTER         :: particles
      49              :       INTEGER, DIMENSION(:), POINTER                     :: qm_atom_index
      50              : 
      51              :       INTEGER                                            :: ilink, ip, ip_mm, ip_qm, mm_index, &
      52              :                                                             n_imomm, qm_index
      53              :       REAL(KIND=dp)                                      :: alpha
      54              :       TYPE(qmmm_imomm_link_type), POINTER                :: my_link
      55              : 
      56          338 :       n_imomm = SIZE(qmmm_links%imomm)
      57          338 :       CPASSERT(n_imomm /= 0)
      58         1270 :       DO ilink = 1, n_imomm
      59          932 :          my_link => qmmm_links%imomm(ilink)%link
      60          932 :          qm_index = my_link%qm_index
      61          932 :          mm_index = my_link%mm_index
      62          932 :          alpha = 1.0_dp/my_link%alpha
      63        25616 :          DO ip = 1, SIZE(qm_atom_index)
      64        25616 :             IF (qm_atom_index(ip) == qm_index) EXIT
      65              :          END DO
      66          932 :          IF (ip == SIZE(qm_atom_index) + 1) THEN
      67              :             CALL cp_abort(__LOCATION__, &
      68              :                           "QM atom index ("//cp_to_string(qm_index)//") specified in the LINK section nr.("// &
      69            0 :                           cp_to_string(ilink)//") is not defined as a QM atom! Please inspect your QM_KIND sections. ")
      70              :          END IF
      71          932 :          ip_qm = ip
      72        44324 :          DO ip = 1, SIZE(qm_atom_index)
      73        44324 :             IF (qm_atom_index(ip) == mm_index) EXIT
      74              :          END DO
      75          932 :          IF (ip == SIZE(qm_atom_index) + 1) THEN
      76              :             CALL cp_abort(__LOCATION__, &
      77              :                           "Error in setting up the MM atom index ("//cp_to_string(mm_index)// &
      78            0 :                           ") specified in the LINK section nr.("//cp_to_string(ilink)//"). Please report this bug! ")
      79              :          END IF
      80          932 :          ip_mm = ip
      81         4066 :          particles(ip_mm)%r = alpha*particles(ip_mm)%r + (1.0_dp - alpha)*particles(ip_qm)%r
      82              :       END DO
      83              : 
      84          338 :    END SUBROUTINE qmmm_link_Imomm_coord
      85              : 
      86              : ! **************************************************************************************************
      87              : !> \brief correct the forces for qm/mm IMOMM link type
      88              : !> \param qmmm_links ...
      89              : !> \param particles_qm ...
      90              : !> \param qm_atom_index ...
      91              : !> \par History
      92              : !>      12.2004 created [tlaino]
      93              : !> \author Teodoro Laino
      94              : ! **************************************************************************************************
      95          274 :    SUBROUTINE qmmm_link_Imomm_forces(qmmm_links, particles_qm, qm_atom_index)
      96              :       TYPE(qmmm_links_type), POINTER                     :: qmmm_links
      97              :       TYPE(particle_type), DIMENSION(:), POINTER         :: particles_qm
      98              :       INTEGER, DIMENSION(:), POINTER                     :: qm_atom_index
      99              : 
     100              :       INTEGER                                            :: ilink, ip, ip_mm, ip_qm, mm_index, &
     101              :                                                             n_imomm, qm_index
     102              :       REAL(KIND=dp)                                      :: alpha
     103              :       TYPE(qmmm_imomm_link_type), POINTER                :: my_link
     104              : 
     105          274 :       n_imomm = SIZE(qmmm_links%imomm)
     106          274 :       CPASSERT(n_imomm /= 0)
     107         1008 :       DO ilink = 1, n_imomm
     108          734 :          my_link => qmmm_links%imomm(ilink)%link
     109          734 :          qm_index = my_link%qm_index
     110          734 :          mm_index = my_link%mm_index
     111          734 :          alpha = 1.0_dp/my_link%alpha
     112        19558 :          DO ip = 1, SIZE(qm_atom_index)
     113        19558 :             IF (qm_atom_index(ip) == qm_index) EXIT
     114              :          END DO
     115          734 :          IF (ip == SIZE(qm_atom_index) + 1) THEN
     116              :             CALL cp_abort(__LOCATION__, &
     117              :                           "QM atom index ("//cp_to_string(qm_index)//") specified in the LINK section nr.("// &
     118            0 :                           cp_to_string(ilink)//") is not defined as a QM atom! Please inspect your QM_KIND sections. ")
     119              :          END IF
     120          734 :          ip_qm = ip
     121        34278 :          DO ip = 1, SIZE(qm_atom_index)
     122        34278 :             IF (qm_atom_index(ip) == mm_index) EXIT
     123              :          END DO
     124          734 :          IF (ip == SIZE(qm_atom_index) + 1) THEN
     125              :             CALL cp_abort(__LOCATION__, &
     126              :                           "Error in setting up the MM atom index ("//cp_to_string(mm_index)// &
     127            0 :                           ") specified in the LINK section nr.("//cp_to_string(ilink)//"). Please report this bug! ")
     128              :          END IF
     129          734 :          ip_mm = ip
     130         2936 :          particles_qm(ip_qm)%f = particles_qm(ip_qm)%f + particles_qm(ip_mm)%f*(1.0_dp - alpha)
     131         3210 :          particles_qm(ip_mm)%f = particles_qm(ip_mm)%f*alpha
     132              :       END DO
     133              : 
     134          274 :    END SUBROUTINE qmmm_link_Imomm_forces
     135              : 
     136              : ! **************************************************************************************************
     137              : !> \brief correct the position for added charges in qm/mm link scheme
     138              : !> \param qmmm_env ...
     139              : !> \param particles ...
     140              : !> \par History
     141              : !>      01.2005 created [tlaino]
     142              : !> \author Teodoro Laino
     143              : ! **************************************************************************************************
     144           32 :    SUBROUTINE qmmm_added_chrg_coord(qmmm_env, particles)
     145              :       TYPE(qmmm_env_qm_type), POINTER                    :: qmmm_env
     146              :       TYPE(particle_type), DIMENSION(:), POINTER         :: particles
     147              : 
     148              :       INTEGER                                            :: I, Index1, Index2
     149              :       REAL(KIND=dp)                                      :: alpha
     150              :       TYPE(add_set_type), POINTER                        :: added_charges
     151              : 
     152           32 :       added_charges => qmmm_env%added_charges
     153              : 
     154          144 :       DO i = 1, added_charges%num_mm_atoms
     155          112 :          Index1 = added_charges%add_env(i)%Index1
     156          112 :          Index2 = added_charges%add_env(i)%Index2
     157          112 :          alpha = added_charges%add_env(i)%alpha
     158          928 :          added_charges%added_particles(i)%r = alpha*particles(Index1)%r + (1.0_dp - alpha)*particles(Index2)%r
     159              :       END DO
     160              : 
     161           32 :    END SUBROUTINE qmmm_added_chrg_coord
     162              : 
     163              : ! **************************************************************************************************
     164              : !> \brief correct the forces due to the  added charges in qm/mm link scheme
     165              : !> \param qmmm_env ...
     166              : !> \param particles ...
     167              : !> \par History
     168              : !>      01.2005 created [tlaino]
     169              : !> \author Teodoro Laino
     170              : ! **************************************************************************************************
     171           32 :    SUBROUTINE qmmm_added_chrg_forces(qmmm_env, particles)
     172              :       TYPE(qmmm_env_qm_type), POINTER                    :: qmmm_env
     173              :       TYPE(particle_type), DIMENSION(:), POINTER         :: particles
     174              : 
     175              :       INTEGER                                            :: I, Index1, Index2
     176              :       REAL(KIND=dp)                                      :: alpha
     177              :       TYPE(add_set_type), POINTER                        :: added_charges
     178              : 
     179           32 :       added_charges => qmmm_env%added_charges
     180              : 
     181          144 :       DO i = 1, added_charges%num_mm_atoms
     182          112 :          Index1 = added_charges%add_env(i)%Index1
     183          112 :          Index2 = added_charges%add_env(i)%Index2
     184          112 :          alpha = added_charges%add_env(i)%alpha
     185          896 :          particles(Index1)%f = particles(Index1)%f + alpha*added_charges%added_particles(i)%f
     186          928 :          particles(Index2)%f = particles(Index2)%f + (1.0_dp - alpha)*added_charges%added_particles(i)%f
     187              :       END DO
     188              : 
     189           32 :    END SUBROUTINE qmmm_added_chrg_forces
     190              : 
     191              : END MODULE qmmm_links_methods
        

Generated by: LCOV version 2.0-1