(git:1f285aa)
qmmm_topology_util.F
Go to the documentation of this file.
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 !> \author teo
10 ! **************************************************************************************************
14  cp_logger_type
17  USE input_section_types, ONLY: section_vals_type
18  USE kinds, ONLY: default_string_length
19  USE molecule_kind_types, ONLY: molecule_kind_type
20  USE molecule_types, ONLY: get_molecule,&
21  molecule_type
22  USE qmmm_types_low, ONLY: qmmm_env_mm_type
23  USE string_table, ONLY: id2str,&
24  s2s,&
25  str2id
26  USE string_utilities, ONLY: compress
28 #include "./base/base_uses.f90"
29 
30  IMPLICIT NONE
31  PRIVATE
32  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qmmm_topology_util'
33 
34  PUBLIC :: qmmm_coordinate_control, &
36 
37 CONTAINS
38 
39 ! **************************************************************************************************
40 !> \brief Modifies the atom_info%id_atmname
41 !> \param topology ...
42 !> \param qmmm_env ...
43 !> \param subsys_section ...
44 !> \par History
45 !> 11.2004 created [tlaino]
46 !> \author Teodoro Laino
47 ! **************************************************************************************************
48  SUBROUTINE qmmm_coordinate_control(topology, qmmm_env, subsys_section)
49 
50  TYPE(topology_parameters_type), INTENT(INOUT) :: topology
51  TYPE(qmmm_env_mm_type), POINTER :: qmmm_env
52  TYPE(section_vals_type), POINTER :: subsys_section
53 
54  CHARACTER(len=*), PARAMETER :: routinen = 'qmmm_coordinate_control'
55 
56  CHARACTER(LEN=default_string_length) :: prefix_lnk
57  INTEGER :: handle, iatm, iw
58  LOGICAL :: qmmm_index_in_range
59  TYPE(cp_logger_type), POINTER :: logger
60 
61  CALL timeset(routinen, handle)
62  NULLIFY (logger)
63  logger => cp_get_default_logger()
64  iw = cp_print_key_unit_nr(logger, subsys_section, "PRINT%TOPOLOGY_INFO/UTIL_INFO", &
65  extension=".subsysLog")
66  IF (iw > 0) WRITE (iw, *) " Entering qmmm_coordinate_control"
67  !
68  ! setting ilast and ifirst for QM molecule
69  !
70  cpassert(SIZE(qmmm_env%qm_atom_index) /= 0)
71  qmmm_index_in_range = (maxval(qmmm_env%qm_atom_index) <= SIZE(topology%atom_info%id_atmname)) &
72  .AND. (minval(qmmm_env%qm_atom_index) > 0)
73  cpassert(qmmm_index_in_range)
74  DO iatm = 1, SIZE(qmmm_env%qm_atom_index)
75  topology%atom_info%id_atmname(qmmm_env%qm_atom_index(iatm)) = &
76  str2id(s2s("_QM_"//trim(id2str(topology%atom_info%id_atmname(qmmm_env%qm_atom_index(iatm))))))
77  topology%atom_info%id_resname(qmmm_env%qm_atom_index(iatm)) = &
78  str2id(s2s("_QM_"//trim(id2str(topology%atom_info%id_resname(qmmm_env%qm_atom_index(iatm))))))
79  END DO
80  !
81  ! Modify type for MM link atoms
82  !
83  IF (ASSOCIATED(qmmm_env%mm_link_atoms)) THEN
84  DO iatm = 1, SIZE(qmmm_env%mm_link_atoms)
85  prefix_lnk = "_LNK000"
86  WRITE (prefix_lnk(5:), '(I20)') iatm
87  CALL compress(prefix_lnk, .true.)
88  topology%atom_info%id_atmname(qmmm_env%mm_link_atoms(iatm)) = &
89  str2id(s2s(trim(prefix_lnk)//trim(id2str(topology%atom_info%id_atmname(qmmm_env%mm_link_atoms(iatm))))))
90  topology%atom_info%id_resname(qmmm_env%mm_link_atoms(iatm)) = &
91  str2id(s2s(trim(prefix_lnk)//trim(id2str(topology%atom_info%id_resname(qmmm_env%mm_link_atoms(iatm))))))
92  END DO
93  END IF
94  !
95  IF (iw > 0) WRITE (iw, *) " Exiting qmmm_coordinate_control"
96  CALL cp_print_key_finished_output(iw, logger, subsys_section, &
97  "PRINT%TOPOLOGY_INFO/UTIL_INFO")
98  CALL timestop(handle)
99  END SUBROUTINE qmmm_coordinate_control
100 
101 ! **************************************************************************************************
102 !> \brief Set up the connectivity for QM/MM calculations
103 !> \param molecule_set ...
104 !> \param qmmm_env ...
105 !> \param subsys_section ...
106 !> \par History
107 !> 12.2004 created [tlaino]
108 !> \author Teodoro Laino
109 ! **************************************************************************************************
110  SUBROUTINE qmmm_connectivity_control(molecule_set, &
111  qmmm_env, subsys_section)
112 
113  TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
114  TYPE(qmmm_env_mm_type), POINTER :: qmmm_env
115  TYPE(section_vals_type), POINTER :: subsys_section
116 
117  CHARACTER(len=*), PARAMETER :: routinen = 'qmmm_connectivity_control'
118 
119  INTEGER :: first_atom, handle, i, imolecule, iw, &
120  last_atom, natom, output_unit, &
121  qm_mol_num
122  INTEGER, DIMENSION(:), POINTER :: qm_atom_index, qm_molecule_index
123  LOGICAL :: detected_link
124  TYPE(cp_logger_type), POINTER :: logger
125  TYPE(molecule_kind_type), POINTER :: molecule_kind
126  TYPE(molecule_type), POINTER :: molecule
127 
128  NULLIFY (qm_atom_index, qm_molecule_index, molecule, molecule_kind)
129  detected_link = .false.
130  logger => cp_get_default_logger()
131  output_unit = cp_logger_get_default_io_unit(logger)
132  iw = cp_print_key_unit_nr(logger, subsys_section, "PRINT%TOPOLOGY_INFO/UTIL_INFO", &
133  extension=".subsysLog")
134  CALL timeset(routinen, handle)
135  qm_mol_num = 0
136  qm_atom_index => qmmm_env%qm_atom_index
137  DO imolecule = 1, SIZE(molecule_set)
138  IF (iw > 0) WRITE (iw, *) "Entering molecule number ::", imolecule
139  molecule => molecule_set(imolecule)
140  CALL get_molecule(molecule, molecule_kind=molecule_kind, &
141  first_atom=first_atom, last_atom=last_atom)
142  IF (any(qm_atom_index >= first_atom .AND. qm_atom_index <= last_atom)) &
143  qm_mol_num = qm_mol_num + 1
144  END DO
145  !
146  ALLOCATE (qm_molecule_index(qm_mol_num))
147  qm_mol_num = 0
148  DO imolecule = 1, SIZE(molecule_set)
149  IF (iw > 0) WRITE (iw, *) "Entering molecule number ::", imolecule
150  molecule => molecule_set(imolecule)
151  CALL get_molecule(molecule, molecule_kind=molecule_kind, &
152  first_atom=first_atom, last_atom=last_atom)
153  natom = last_atom - first_atom + 1
154  IF (any(qm_atom_index >= first_atom .AND. qm_atom_index <= last_atom)) THEN
155  qm_mol_num = qm_mol_num + 1
156  !
157  ! Check if all atoms of the molecule are QM or if a QM/MM link scheme
158  ! need to be used...
159  !
160  detected_link = .false.
161  DO i = first_atom, last_atom
162  IF (.NOT. any(qm_atom_index == i)) detected_link = .true.
163  END DO
164  IF (detected_link) THEN
165  IF (iw > 0) WRITE (iw, fmt='(A)', advance="NO") " QM/MM link detected..."
166  IF (.NOT. qmmm_env%qmmm_link) THEN
167  IF (iw > 0) WRITE (iw, fmt='(A)') " Missing LINK section in input file!!"
168  WRITE (output_unit, '(T2,"QMMM_CONNECTIVITY|",A)') &
169  " ERROR in the QM/MM connectivity. A QM/MM LINK was detected but", &
170  " no LINK section was provided in the Input file!", &
171  " This very probably can be identified as an error in the specified QM", &
172  " indexes or in a missing LINK section. Check your structure!"
173  cpabort("")
174  END IF
175  END IF
176  qm_molecule_index(qm_mol_num) = imolecule
177  END IF
178  END DO
179  IF (ASSOCIATED(qmmm_env%qm_molecule_index)) DEALLOCATE (qmmm_env%qm_molecule_index)
180  qmmm_env%qm_molecule_index => qm_molecule_index
181  IF (iw > 0) WRITE (iw, *) " QM molecule index ::", qm_molecule_index
182  CALL cp_print_key_finished_output(iw, logger, subsys_section, &
183  "PRINT%TOPOLOGY_INFO/UTIL_INFO")
184  CALL timestop(handle)
185 
186  END SUBROUTINE qmmm_connectivity_control
187 
188 END MODULE qmmm_topology_util
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
objects that represent the structure of input sections and the data contained in an input section
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public default_string_length
Definition: kinds.F:57
Define the molecule kind structure types and the corresponding functionality.
Define the data structure for the molecule information.
subroutine, public get_molecule(molecule, molecule_kind, lmi, lci, lg3x3, lg4x6, lcolv, first_atom, last_atom, first_shell, last_shell)
Get components from a molecule data set.
subroutine, public qmmm_coordinate_control(topology, qmmm_env, subsys_section)
Modifies the atom_infoid_atmname.
subroutine, public qmmm_connectivity_control(molecule_set, qmmm_env, subsys_section)
Set up the connectivity for QM/MM calculations.
generates a unique id number for a string (str2id) that can be used two compare two strings....
Definition: string_table.F:22
character(len=default_string_length) function, public s2s(str)
converts a string in a string of default_string_length
Definition: string_table.F:141
integer function, public str2id(str)
returns a unique id for a given string, and stores the string for later retrieval using the id.
Definition: string_table.F:72
character(len=default_string_length) function, public id2str(id)
returns the string associated with a given id
Definition: string_table.F:115
Utilities for string manipulations.
subroutine, public compress(string, full)
Eliminate multiple space characters in a string. If full is .TRUE., then all spaces are eliminated.
Control for reading in different topologies and coordinates.
Definition: topology.F:13