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 : !> \par History
10 : !> gt sept-23-02 added atomic_kind_set to replica_environment_type
11 : !> to allow use of kind_based neighbor list
12 : !> CJM rewrite
13 : !> \author CJM SEPT-01-02
14 : ! **************************************************************************************************
15 : MODULE fist_environment_types
16 : USE atomic_kind_list_types, ONLY: atomic_kind_list_create,&
17 : atomic_kind_list_release,&
18 : atomic_kind_list_type
19 : USE atomic_kind_types, ONLY: atomic_kind_type
20 : USE cell_types, ONLY: cell_release,&
21 : cell_retain,&
22 : cell_type
23 : USE cp_result_types, ONLY: cp_result_type
24 : USE cp_subsys_types, ONLY: cp_subsys_get,&
25 : cp_subsys_release,&
26 : cp_subsys_set,&
27 : cp_subsys_type
28 : USE distribution_1d_types, ONLY: distribution_1d_type
29 : USE ewald_environment_types, ONLY: ewald_env_release,&
30 : ewald_environment_type
31 : USE ewald_pw_types, ONLY: ewald_pw_release,&
32 : ewald_pw_type
33 : USE exclusion_types, ONLY: exclusion_release,&
34 : exclusion_type
35 : USE fist_efield_types, ONLY: fist_efield_type
36 : USE fist_energy_types, ONLY: deallocate_fist_energy,&
37 : fist_energy_type
38 : USE fist_nonbond_env_types, ONLY: fist_nonbond_env_release,&
39 : fist_nonbond_env_type
40 : USE input_section_types, ONLY: section_vals_release,&
41 : section_vals_retain,&
42 : section_vals_type
43 : USE message_passing, ONLY: mp_para_env_release,&
44 : mp_para_env_type
45 : USE molecule_kind_list_types, ONLY: molecule_kind_list_create,&
46 : molecule_kind_list_release,&
47 : molecule_kind_list_type
48 : USE molecule_kind_types, ONLY: molecule_kind_type
49 : USE molecule_list_types, ONLY: molecule_list_create,&
50 : molecule_list_release,&
51 : molecule_list_type
52 : USE molecule_types, ONLY: molecule_type
53 : USE multipole_types, ONLY: multipole_type
54 : USE particle_list_types, ONLY: particle_list_create,&
55 : particle_list_release,&
56 : particle_list_type
57 : USE particle_types, ONLY: particle_type
58 : USE qmmm_types_low, ONLY: qmmm_env_mm_create,&
59 : qmmm_env_mm_release,&
60 : qmmm_env_mm_type
61 : #include "./base/base_uses.f90"
62 :
63 : IMPLICIT NONE
64 : PRIVATE
65 :
66 : ! **************************************************************************************************
67 : !> \par History
68 : !> 11/03
69 : !> \author CJM
70 : ! **************************************************************************************************
71 : TYPE fist_environment_type
72 : PRIVATE
73 : LOGICAL :: qmmm = .FALSE.
74 : LOGICAL :: shell_model = .FALSE., shell_model_ad = .FALSE.
75 : TYPE(qmmm_env_mm_type), POINTER :: qmmm_env => NULL()
76 : TYPE(cell_type), POINTER :: cell_ref => NULL()
77 : TYPE(ewald_environment_type), POINTER :: ewald_env => NULL()
78 : TYPE(ewald_pw_type), POINTER :: ewald_pw => NULL()
79 : TYPE(fist_energy_type), POINTER :: thermo => NULL()
80 : TYPE(mp_para_env_type), POINTER :: para_env => NULL()
81 : TYPE(cp_subsys_type), POINTER :: subsys => NULL()
82 : TYPE(fist_nonbond_env_type), POINTER :: fist_nonbond_env => NULL()
83 : TYPE(section_vals_type), POINTER :: input => NULL()
84 : TYPE(exclusion_type), DIMENSION(:), POINTER :: exclusions => NULL()
85 : TYPE(fist_efield_type), POINTER :: efield => NULL()
86 : END TYPE fist_environment_type
87 :
88 : ! *** Public data types ***
89 : PUBLIC :: fist_environment_type
90 :
91 : ! *** Public subroutines ***
92 : PUBLIC :: fist_env_get, &
93 : fist_env_set, &
94 : fist_env_create, &
95 : fist_env_release
96 :
97 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'fist_environment_types'
98 :
99 : !***
100 :
101 : CONTAINS
102 :
103 : ! **************************************************************************************************
104 : !> \brief Purpose: Get the FIST environment.
105 : !> \param fist_env the pointer to the fist_env
106 : !> \param atomic_kind_set ...
107 : !> \param particle_set ...
108 : !> \param ewald_pw ...
109 : !> \param local_particles ...
110 : !> \param local_molecules ...
111 : !> \param molecule_kind_set ...
112 : !> \param molecule_set ...
113 : !> \param cell ...
114 : !> \param cell_ref ...
115 : !> \param ewald_env ...
116 : !> \param fist_nonbond_env ...
117 : !> \param thermo ...
118 : !> \param para_env ...
119 : !> \param subsys ...
120 : !> \param qmmm ...
121 : !> \param qmmm_env ...
122 : !> \param input ...
123 : !> \param shell_model ...
124 : !> \param shell_model_ad ...
125 : !> \param shell_particle_set ...
126 : !> \param core_particle_set ...
127 : !> \param multipoles ...
128 : !> \param results ...
129 : !> \param exclusions ...
130 : !> \param efield ...
131 : !> \par History
132 : !> 11/03
133 : !> \author CJM
134 : ! **************************************************************************************************
135 2155447 : SUBROUTINE fist_env_get(fist_env, atomic_kind_set, particle_set, ewald_pw, &
136 : local_particles, local_molecules, molecule_kind_set, molecule_set, cell, &
137 : cell_ref, ewald_env, fist_nonbond_env, thermo, para_env, subsys, qmmm, &
138 : qmmm_env, input, shell_model, shell_model_ad, shell_particle_set, &
139 : core_particle_set, multipoles, results, exclusions, efield)
140 :
141 : TYPE(fist_environment_type), INTENT(IN) :: fist_env
142 : TYPE(atomic_kind_type), OPTIONAL, POINTER :: atomic_kind_set(:)
143 : TYPE(particle_type), OPTIONAL, POINTER :: particle_set(:)
144 : TYPE(ewald_pw_type), OPTIONAL, POINTER :: ewald_pw
145 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles, local_molecules
146 : TYPE(molecule_kind_type), OPTIONAL, POINTER :: molecule_kind_set(:)
147 : TYPE(molecule_type), OPTIONAL, POINTER :: molecule_set(:)
148 : TYPE(cell_type), OPTIONAL, POINTER :: cell, cell_ref
149 : TYPE(ewald_environment_type), OPTIONAL, POINTER :: ewald_env
150 : TYPE(fist_nonbond_env_type), OPTIONAL, POINTER :: fist_nonbond_env
151 : TYPE(fist_energy_type), OPTIONAL, POINTER :: thermo
152 : TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
153 : TYPE(cp_subsys_type), OPTIONAL, POINTER :: subsys
154 : LOGICAL, OPTIONAL :: qmmm
155 : TYPE(qmmm_env_mm_type), OPTIONAL, POINTER :: qmmm_env
156 : TYPE(section_vals_type), OPTIONAL, POINTER :: input
157 : LOGICAL, OPTIONAL :: shell_model, shell_model_ad
158 : TYPE(particle_type), OPTIONAL, POINTER :: shell_particle_set(:), &
159 : core_particle_set(:)
160 : TYPE(multipole_type), OPTIONAL, POINTER :: multipoles
161 : TYPE(cp_result_type), OPTIONAL, POINTER :: results
162 : TYPE(exclusion_type), DIMENSION(:), OPTIONAL, &
163 : POINTER :: exclusions
164 : TYPE(fist_efield_type), OPTIONAL, POINTER :: efield
165 :
166 : TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
167 : TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
168 : TYPE(molecule_list_type), POINTER :: molecules
169 : TYPE(multipole_type), POINTER :: fist_multipoles
170 : TYPE(particle_list_type), POINTER :: core_particles, particles, &
171 : shell_particles
172 :
173 2155447 : NULLIFY (atomic_kinds, particles, molecules, molecule_kinds, fist_multipoles)
174 :
175 2155447 : IF (PRESENT(input)) input => fist_env%input
176 2155447 : IF (PRESENT(qmmm)) qmmm = fist_env%qmmm
177 2155447 : IF (PRESENT(qmmm_env)) qmmm_env => fist_env%qmmm_env
178 2155447 : IF (PRESENT(cell_ref)) cell_ref => fist_env%cell_ref
179 2155447 : IF (PRESENT(ewald_env)) ewald_env => fist_env%ewald_env
180 2155447 : IF (PRESENT(thermo)) thermo => fist_env%thermo
181 2155447 : IF (PRESENT(exclusions)) exclusions => fist_env%exclusions
182 2155447 : IF (PRESENT(para_env)) para_env => fist_env%para_env
183 2155447 : IF (PRESENT(ewald_pw)) ewald_pw => fist_env%ewald_pw
184 2155447 : IF (PRESENT(fist_nonbond_env)) fist_nonbond_env => fist_env%fist_nonbond_env
185 2155447 : IF (PRESENT(shell_model)) shell_model = fist_env%shell_model
186 2155447 : IF (PRESENT(shell_model_ad)) shell_model_ad = fist_env%shell_model_ad
187 2155447 : IF (PRESENT(subsys)) subsys => fist_env%subsys
188 2155447 : IF (PRESENT(efield)) efield => fist_env%efield
189 :
190 2155447 : IF (ASSOCIATED(fist_env%subsys)) &
191 : CALL cp_subsys_get(fist_env%subsys, &
192 : atomic_kinds=atomic_kinds, &
193 : local_molecules=local_molecules, &
194 : local_particles=local_particles, &
195 : particles=particles, &
196 : molecule_kinds=molecule_kinds, &
197 : molecules=molecules, &
198 : shell_particles=shell_particles, &
199 : core_particles=core_particles, &
200 : multipoles=fist_multipoles, &
201 : results=results, &
202 2152808 : cell=cell)
203 2155447 : IF (PRESENT(atomic_kind_set)) atomic_kind_set => atomic_kinds%els
204 2155447 : IF (PRESENT(particle_set)) particle_set => particles%els
205 2155447 : IF (PRESENT(molecule_kind_set)) molecule_kind_set => molecule_kinds%els
206 2155447 : IF (PRESENT(molecule_set)) molecule_set => molecules%els
207 2155447 : IF (PRESENT(shell_particle_set)) shell_particle_set => shell_particles%els
208 2155447 : IF (PRESENT(core_particle_set)) core_particle_set => core_particles%els
209 2155447 : IF (PRESENT(multipoles)) multipoles => fist_multipoles
210 2155447 : END SUBROUTINE fist_env_get
211 :
212 : ! **************************************************************************************************
213 : !> \brief Initialise the FIST environment.
214 : !> \param fist_env the pointer to the fist_env
215 : !> \param para_env ...
216 : !> \par History
217 : !> 11/03
218 : !> \author CJM
219 : ! **************************************************************************************************
220 2639 : SUBROUTINE init_fist_env(fist_env, para_env)
221 :
222 : TYPE(fist_environment_type), INTENT(OUT) :: fist_env
223 : TYPE(mp_para_env_type), POINTER :: para_env
224 :
225 : NULLIFY (fist_env%input)
226 : NULLIFY (fist_env%qmmm_env)
227 : NULLIFY (fist_env%cell_ref)
228 : NULLIFY (fist_env%ewald_env)
229 : NULLIFY (fist_env%ewald_pw)
230 : NULLIFY (fist_env%thermo)
231 : NULLIFY (fist_env%fist_nonbond_env)
232 : NULLIFY (fist_env%subsys)
233 : NULLIFY (fist_env%exclusions)
234 : NULLIFY (fist_env%efield)
235 : fist_env%qmmm = .FALSE.
236 : fist_env%shell_model = .FALSE.
237 : fist_env%shell_model_ad = .FALSE.
238 2639 : ALLOCATE (fist_env%qmmm_env)
239 2639 : CALL qmmm_env_mm_create(fist_env%qmmm_env)
240 2639 : NULLIFY (fist_env%subsys)
241 2639 : CALL para_env%retain()
242 2639 : fist_env%para_env => para_env
243 :
244 2639 : END SUBROUTINE init_fist_env
245 :
246 : ! **************************************************************************************************
247 : !> \brief Set the FIST environment.
248 : !> \param fist_env the pointer to the fist_env
249 : !> \param atomic_kind_set ...
250 : !> \param particle_set ...
251 : !> \param ewald_pw ...
252 : !> \param local_particles ...
253 : !> \param local_molecules ...
254 : !> \param molecule_kind_set ...
255 : !> \param molecule_set ...
256 : !> \param cell_ref ...
257 : !> \param ewald_env ...
258 : !> \param fist_nonbond_env ...
259 : !> \param thermo ...
260 : !> \param subsys ...
261 : !> \param qmmm ...
262 : !> \param qmmm_env ...
263 : !> \param input ...
264 : !> \param shell_model ...
265 : !> \param shell_model_ad ...
266 : !> \param exclusions ...
267 : !> \param efield ...
268 : !> \par History
269 : !> 11/03
270 : !> \author CJM
271 : ! **************************************************************************************************
272 15834 : SUBROUTINE fist_env_set(fist_env, atomic_kind_set, particle_set, ewald_pw, &
273 : local_particles, local_molecules, molecule_kind_set, &
274 : molecule_set, cell_ref, ewald_env, &
275 : fist_nonbond_env, thermo, subsys, qmmm, qmmm_env, &
276 : input, shell_model, shell_model_ad, exclusions, efield)
277 :
278 : TYPE(fist_environment_type), INTENT(INOUT) :: fist_env
279 : TYPE(atomic_kind_type), OPTIONAL, POINTER :: atomic_kind_set(:)
280 : TYPE(particle_type), OPTIONAL, POINTER :: particle_set(:)
281 : TYPE(ewald_pw_type), OPTIONAL, POINTER :: ewald_pw
282 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles, local_molecules
283 : TYPE(molecule_kind_type), OPTIONAL, POINTER :: molecule_kind_set(:)
284 : TYPE(molecule_type), OPTIONAL, POINTER :: molecule_set(:)
285 : TYPE(cell_type), OPTIONAL, POINTER :: cell_ref
286 : TYPE(ewald_environment_type), OPTIONAL, POINTER :: ewald_env
287 : TYPE(fist_nonbond_env_type), OPTIONAL, POINTER :: fist_nonbond_env
288 : TYPE(fist_energy_type), OPTIONAL, POINTER :: thermo
289 : TYPE(cp_subsys_type), OPTIONAL, POINTER :: subsys
290 : LOGICAL, OPTIONAL :: qmmm
291 : TYPE(qmmm_env_mm_type), OPTIONAL, POINTER :: qmmm_env
292 : TYPE(section_vals_type), OPTIONAL, POINTER :: input
293 : LOGICAL, OPTIONAL :: shell_model, shell_model_ad
294 : TYPE(exclusion_type), DIMENSION(:), OPTIONAL, &
295 : POINTER :: exclusions
296 : TYPE(fist_efield_type), OPTIONAL, POINTER :: efield
297 :
298 : TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
299 : TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
300 : TYPE(molecule_list_type), POINTER :: molecules
301 : TYPE(particle_list_type), POINTER :: particles
302 :
303 15834 : IF (PRESENT(qmmm)) fist_env%qmmm = qmmm
304 15834 : IF (PRESENT(qmmm_env)) THEN
305 394 : IF (ASSOCIATED(fist_env%qmmm_env)) THEN
306 394 : CALL qmmm_env_mm_release(fist_env%qmmm_env)
307 394 : DEALLOCATE (fist_env%qmmm_env)
308 : END IF
309 394 : fist_env%qmmm_env => qmmm_env
310 : END IF
311 15834 : IF (PRESENT(ewald_env)) THEN
312 2639 : IF (ASSOCIATED(fist_env%ewald_env)) THEN
313 0 : IF (.NOT. ASSOCIATED(fist_env%ewald_env, ewald_env)) THEN
314 0 : CALL ewald_env_release(fist_env%ewald_env)
315 0 : DEALLOCATE (fist_env%ewald_env)
316 : END IF
317 : END IF
318 2639 : fist_env%ewald_env => ewald_env
319 : END IF
320 15834 : IF (PRESENT(ewald_pw)) THEN
321 2639 : IF (ASSOCIATED(fist_env%ewald_pw)) THEN
322 0 : IF (.NOT. ASSOCIATED(fist_env%ewald_pw, ewald_pw)) THEN
323 0 : CALL ewald_pw_release(fist_env%ewald_pw)
324 0 : DEALLOCATE (fist_env%ewald_pw)
325 : END IF
326 : END IF
327 2639 : fist_env%ewald_pw => ewald_pw
328 : END IF
329 15834 : IF (PRESENT(cell_ref)) THEN
330 2639 : CALL cell_retain(cell_ref)
331 2639 : CALL cell_release(fist_env%cell_ref)
332 2639 : fist_env%cell_ref => cell_ref
333 : END IF
334 15834 : IF (PRESENT(fist_nonbond_env)) THEN
335 2639 : IF (ASSOCIATED(fist_env%fist_nonbond_env)) THEN
336 0 : IF (.NOT. ASSOCIATED(fist_env%fist_nonbond_env, fist_nonbond_env)) THEN
337 0 : CALL fist_nonbond_env_release(fist_env%fist_nonbond_env)
338 0 : DEALLOCATE (fist_env%fist_nonbond_env)
339 : END IF
340 : END IF
341 2639 : fist_env%fist_nonbond_env => fist_nonbond_env
342 : END IF
343 15834 : IF (PRESENT(input)) THEN
344 2639 : CALL section_vals_retain(input)
345 2639 : CALL section_vals_release(fist_env%input)
346 2639 : fist_env%input => input
347 : END IF
348 15834 : IF (PRESENT(thermo)) fist_env%thermo => thermo
349 15834 : IF (PRESENT(subsys)) THEN
350 2639 : IF (ASSOCIATED(fist_env%subsys)) THEN
351 0 : IF (.NOT. ASSOCIATED(fist_env%subsys, subsys)) THEN
352 0 : CALL cp_subsys_release(fist_env%subsys)
353 : END IF
354 : END IF
355 2639 : fist_env%subsys => subsys
356 : END IF
357 15834 : IF (PRESENT(atomic_kind_set)) THEN
358 : CALL atomic_kind_list_create(atomic_kinds, &
359 0 : els_ptr=atomic_kind_set)
360 : CALL cp_subsys_set(fist_env%subsys, &
361 0 : atomic_kinds=atomic_kinds)
362 0 : CALL atomic_kind_list_release(atomic_kinds)
363 : END IF
364 15834 : IF (PRESENT(particle_set)) THEN
365 : CALL particle_list_create(particles, &
366 0 : els_ptr=particle_set)
367 : CALL cp_subsys_set(fist_env%subsys, &
368 0 : particles=particles)
369 0 : CALL particle_list_release(particles)
370 : END IF
371 15834 : IF (PRESENT(local_particles)) THEN
372 : CALL cp_subsys_set(fist_env%subsys, &
373 2639 : local_particles=local_particles)
374 : END IF
375 15834 : IF (PRESENT(local_molecules)) THEN
376 : CALL cp_subsys_set(fist_env%subsys, &
377 2639 : local_molecules=local_molecules)
378 : END IF
379 15834 : IF (PRESENT(molecule_kind_set)) THEN
380 : CALL molecule_kind_list_create(molecule_kinds, &
381 0 : els_ptr=molecule_kind_set)
382 : CALL cp_subsys_set(fist_env%subsys, &
383 0 : molecule_kinds=molecule_kinds)
384 0 : CALL molecule_kind_list_release(molecule_kinds)
385 : END IF
386 15834 : IF (PRESENT(molecule_set)) THEN
387 : CALL molecule_list_create(molecules, &
388 0 : els_ptr=molecule_set)
389 : CALL cp_subsys_set(fist_env%subsys, &
390 0 : molecules=molecules)
391 0 : CALL molecule_list_release(molecules)
392 : END IF
393 15834 : IF (PRESENT(exclusions)) fist_env%exclusions => exclusions
394 15834 : IF (PRESENT(shell_model)) THEN
395 2639 : fist_env%shell_model = shell_model
396 : END IF
397 15834 : IF (PRESENT(shell_model_ad)) THEN
398 2639 : fist_env%shell_model_ad = shell_model_ad
399 : END IF
400 15834 : IF (PRESENT(efield)) fist_env%efield => efield
401 :
402 15834 : END SUBROUTINE fist_env_set
403 :
404 : ! **************************************************************************************************
405 : !> \brief allocates and intitializes a fist_env
406 : !> \param fist_env the object to create
407 : !> \param para_env the parallel environment for the qs_env
408 : !> \par History
409 : !> 12.2002 created [fawzi]
410 : !> \author Fawzi Mohamed
411 : ! **************************************************************************************************
412 2639 : SUBROUTINE fist_env_create(fist_env, para_env)
413 : TYPE(fist_environment_type), INTENT(OUT) :: fist_env
414 : TYPE(mp_para_env_type), INTENT(IN), POINTER :: para_env
415 :
416 2639 : CALL init_fist_env(fist_env, para_env=para_env)
417 2639 : END SUBROUTINE fist_env_create
418 :
419 : ! **************************************************************************************************
420 : !> \brief releases the given fist_env (see doc/ReferenceCounting.html)
421 : !> \param fist_env the object to release
422 : !> \par History
423 : !> 12.2002 created [fawzi]
424 : !> \author Fawzi Mohamed
425 : ! **************************************************************************************************
426 2639 : SUBROUTINE fist_env_release(fist_env)
427 : TYPE(fist_environment_type), INTENT(INOUT) :: fist_env
428 :
429 2639 : IF (ASSOCIATED(fist_env%qmmm_env)) THEN
430 2639 : CALL qmmm_env_mm_release(fist_env%qmmm_env)
431 2639 : DEALLOCATE (fist_env%qmmm_env)
432 : END IF
433 2639 : CALL cell_release(fist_env%cell_ref)
434 2639 : IF (ASSOCIATED(fist_env%ewald_pw)) THEN
435 2639 : CALL ewald_pw_release(fist_env%ewald_pw)
436 2639 : DEALLOCATE (fist_env%ewald_pw)
437 : END IF
438 2639 : IF (ASSOCIATED(fist_env%ewald_env)) THEN
439 2639 : CALL ewald_env_release(fist_env%ewald_env)
440 2639 : DEALLOCATE (fist_env%ewald_env)
441 : END IF
442 2639 : CALL mp_para_env_release(fist_env%para_env)
443 2639 : CALL deallocate_fist_energy(fist_env%thermo)
444 :
445 2639 : IF (ASSOCIATED(fist_env%fist_nonbond_env)) THEN
446 2639 : CALL fist_nonbond_env_release(fist_env%fist_nonbond_env)
447 2639 : DEALLOCATE (fist_env%fist_nonbond_env)
448 : END IF
449 2639 : CALL cp_subsys_release(fist_env%subsys)
450 2639 : CALL section_vals_release(fist_env%input)
451 2639 : CALL exclusion_release(fist_env%exclusions)
452 :
453 2639 : IF (ASSOCIATED(fist_env%efield)) THEN
454 2639 : DEALLOCATE (fist_env%efield)
455 : END IF
456 :
457 2639 : END SUBROUTINE fist_env_release
458 :
459 0 : END MODULE fist_environment_types
|