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