(git:6344619)
Loading...
Searching...
No Matches
force_env_types.F
Go to the documentation of this file.
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 Interface for the force calculations
10!> \par History
11!> cjm, FEB-20-2001: pass variable box_ref
12!> cjm, SEPT-12-2002: major reorganization
13!> fawzi, APR-12-2003: introduced force_env
14!> cjm, FEB-27-2006: no more box_change
15!> MK, Nov. 2010: new interfaces added and others were updated
16!> \author CJM & JGH
17! **************************************************************************************************
19 USE cell_types, ONLY: cell_type
36 USE fp_types, ONLY: fp_env_release,&
49 USE kinds, ONLY: dp
65 USE qmmm_types, ONLY: qmmm_env_get,&
68 USE qmmmx_types, ONLY: qmmmx_env_get,&
75#include "./base/base_uses.f90"
76
77 IMPLICIT NONE
78
79 PRIVATE
80
81 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'force_env_types'
82
83 INTEGER, PARAMETER, PUBLIC :: use_fist_force = 501, &
84 use_qs_force = 502, &
85 use_qmmm = 503, &
86 use_qmmmx = 504, &
87 use_eip_force = 505, &
88 use_mixed_force = 506, &
89 use_embed = 507, &
90 use_pwdft_force = 508, &
91 use_nnp_force = 509, &
92 use_ipi = 510
93
94 CHARACTER(LEN=10), DIMENSION(501:510), PARAMETER, PUBLIC :: &
95 use_prog_name = [ &
96 "FIST ", &
97 "QS ", &
98 "QMMM ", &
99 "QMMMX ", &
100 "EIP ", &
101 "MIXED ", &
102 "EMBED ", &
103 "SIRIUS", &
104 "NNP ", &
105 "IPI "]
106
107 PUBLIC :: force_env_type, &
109
110 PUBLIC :: force_env_retain, &
120
121! **************************************************************************************************
122!> \brief wrapper to abstract the force evaluation of the various methods
123!> \param ref_count reference count (see doc/ReferenceCounting.html)
124!> \param in_use which method is in use
125!> \param fist_env the fist environment (allocated only if fist is in use)
126!> \param qs_env qs_env (activated only if quickstep is in use)
127!> \param globenv the globenv to have the input that generated this force_env
128!> \param para_env the parallel environment that contains all the parallel
129!> environment of the fragments
130!> \param meta_env the metadynamics environment, allocated if there is
131!> metadynamics
132!> \param fp_env the flexible partitioning environment
133!> read-only attributes (get them *only* through force_env_get):
134!> \param subsys the fragments that build up the actual system.
135!> \param cell the cell of the actual system
136!> \note
137!> as always direct manipulation of these attributes can have very
138!> bad effects. In this case it can be quite bad and the variables
139!> might not be up to date. You are warned, use only the get method...
140!> \par History
141!> 04.2003 created [fawzi]
142!> 07.2003 tried to adapt to multiple mpi groups
143!> \author fawzi
144! **************************************************************************************************
146 INTEGER :: ref_count = 0, in_use = 0, method_name_id = 0
147 REAL(kind=dp) :: additional_potential = 0.0_dp
148 TYPE(fist_environment_type), POINTER :: fist_env => null()
149 TYPE(meta_env_type), POINTER :: meta_env => null()
150 TYPE(fp_type), POINTER :: fp_env => null()
151 TYPE(qs_environment_type), POINTER :: qs_env => null()
152 TYPE(eip_environment_type), POINTER :: eip_env => null()
153 TYPE(pwdft_environment_type), POINTER :: pwdft_env => null()
154 TYPE(global_environment_type), POINTER :: globenv => null()
155 TYPE(mp_para_env_type), POINTER :: para_env => null()
156 TYPE(force_env_p_type), DIMENSION(:), POINTER :: sub_force_env => null()
157 TYPE(qmmm_env_type), POINTER :: qmmm_env => null()
158 TYPE(qmmmx_env_type), POINTER :: qmmmx_env => null()
159 TYPE(mixed_environment_type), POINTER :: mixed_env => null()
160 TYPE(nnp_type), POINTER :: nnp_env => null()
161 TYPE(embed_env_type), POINTER :: embed_env => null()
162 TYPE(ipi_environment_type), POINTER :: ipi_env => null()
163 TYPE(section_vals_type), POINTER :: force_env_section => null()
164 TYPE(section_vals_type), POINTER :: root_section => null()
165 END TYPE force_env_type
166
167! **************************************************************************************************
168!> \brief allows for the creation of an array of force_env
169!> \param force_env a force environment (see above)
170!> \note
171!> added by MJM for MC swap moves
172!> \author MJM
173! **************************************************************************************************
175 TYPE(force_env_type), POINTER :: force_env => null()
176 END TYPE force_env_p_type
177
178CONTAINS
179
180! **************************************************************************************************
181!> \brief retains the given force env
182!> \param force_env the force environment to retain
183!> \par History
184!> 04.2003 created [fawzi]
185!> \author fawzi
186!> \note
187!> see doc/ReferenceCounting.html
188! **************************************************************************************************
189 SUBROUTINE force_env_retain(force_env)
190 TYPE(force_env_type), POINTER :: force_env
191
192 cpassert(ASSOCIATED(force_env))
193 cpassert(force_env%ref_count > 0)
194 force_env%ref_count = force_env%ref_count + 1
195 END SUBROUTINE force_env_retain
196
197! **************************************************************************************************
198!> \brief releases the given force env
199!> \param force_env the force environment to release
200!> \par History
201!> 04.2003 created [fawzi]
202!> \author fawzi
203!> \note
204!> see doc/ReferenceCounting.html
205! **************************************************************************************************
206 RECURSIVE SUBROUTINE force_env_release(force_env)
207 TYPE(force_env_type), POINTER :: force_env
208
209 INTEGER :: i, my_group
210 TYPE(cp_logger_type), POINTER :: my_logger
211
212 IF (ASSOCIATED(force_env)) THEN
213 cpassert(force_env%ref_count > 0)
214 force_env%ref_count = force_env%ref_count - 1
215 IF (force_env%ref_count == 0) THEN
216 ! Deallocate SUB_FORCE_ENV
217 IF (ASSOCIATED(force_env%sub_force_env)) THEN
218 DO i = 1, SIZE(force_env%sub_force_env)
219 IF (.NOT. ASSOCIATED(force_env%sub_force_env(i)%force_env)) cycle
220 ! Use the proper logger to deallocate..
221 IF (force_env%in_use == use_mixed_force) THEN
222 my_group = force_env%mixed_env%group_distribution(force_env%para_env%mepos)
223 my_logger => force_env%mixed_env%sub_logger(my_group + 1)%p
224 CALL cp_add_default_logger(my_logger)
225 END IF
226 ! The same for embedding
227 IF (force_env%in_use == use_embed) THEN
228 my_group = force_env%embed_env%group_distribution(force_env%para_env%mepos)
229 my_logger => force_env%embed_env%sub_logger(my_group + 1)%p
230 CALL cp_add_default_logger(my_logger)
231 END IF
232 CALL force_env_release(force_env%sub_force_env(i)%force_env)
233 IF (force_env%in_use == use_mixed_force) THEN
235 END IF
236 IF (force_env%in_use == use_embed) THEN
238 END IF
239 END DO
240 DEALLOCATE (force_env%sub_force_env)
241 END IF
242
243 SELECT CASE (force_env%in_use)
244 CASE (use_fist_force)
245 CALL fist_env_release(force_env%fist_env)
246 DEALLOCATE (force_env%fist_env)
247 CASE (use_qs_force)
248 CALL qs_env_release(force_env%qs_env)
249 DEALLOCATE (force_env%qs_env)
250 CASE (use_eip_force)
251 CALL eip_env_release(force_env%eip_env)
252 DEALLOCATE (force_env%eip_env)
253 CASE (use_pwdft_force)
254 CALL pwdft_env_release(force_env%pwdft_env)
255 DEALLOCATE (force_env%pwdft_env)
256 CASE (use_mixed_force)
257 CALL mixed_env_release(force_env%mixed_env)
258 DEALLOCATE (force_env%mixed_env)
259 CASE (use_nnp_force)
260 CALL nnp_env_release(force_env%nnp_env)
261 DEALLOCATE (force_env%nnp_env)
262 CASE (use_embed)
263 CALL embed_env_release(force_env%embed_env)
264 DEALLOCATE (force_env%embed_env)
265 CASE (use_ipi)
266 CALL shutdown_server(force_env%ipi_env)
267 CALL ipi_env_release(force_env%ipi_env)
268 DEALLOCATE (force_env%ipi_env)
269 END SELECT
270 CALL globenv_release(force_env%globenv)
271 CALL mp_para_env_release(force_env%para_env)
272 ! Not deallocated
273 cpassert(.NOT. ASSOCIATED(force_env%fist_env))
274 cpassert(.NOT. ASSOCIATED(force_env%qs_env))
275 cpassert(.NOT. ASSOCIATED(force_env%eip_env))
276 cpassert(.NOT. ASSOCIATED(force_env%pwdft_env))
277 cpassert(.NOT. ASSOCIATED(force_env%mixed_env))
278 cpassert(.NOT. ASSOCIATED(force_env%nnp_env))
279 cpassert(.NOT. ASSOCIATED(force_env%embed_env))
280 cpassert(.NOT. ASSOCIATED(force_env%ipi_env))
281 IF (ASSOCIATED(force_env%meta_env)) THEN
282 CALL meta_env_release(force_env%meta_env)
283 DEALLOCATE (force_env%meta_env)
284 END IF
285 IF (ASSOCIATED(force_env%fp_env)) THEN
286 CALL fp_env_release(force_env%fp_env)
287 DEALLOCATE (force_env%fp_env)
288 END IF
289 IF (ASSOCIATED(force_env%qmmm_env)) THEN
290 CALL qmmm_env_release(force_env%qmmm_env)
291 DEALLOCATE (force_env%qmmm_env)
292 END IF
293 IF (ASSOCIATED(force_env%qmmmx_env)) THEN
294 CALL qmmmx_env_release(force_env%qmmmx_env)
295 DEALLOCATE (force_env%qmmmx_env)
296 END IF
297 CALL section_vals_release(force_env%force_env_section)
298 CALL section_vals_release(force_env%root_section)
299 DEALLOCATE (force_env)
300 END IF
301 END IF
302 NULLIFY (force_env)
303 END SUBROUTINE force_env_release
304
305! **************************************************************************************************
306!> \brief returns various attributes about the force environment
307!> \param force_env the force environment you what informations about
308!> \param in_use ...
309!> \param fist_env ...
310!> \param qs_env ...
311!> \param meta_env ...
312!> \param fp_env ...
313!> \param subsys ...
314!> \param para_env ...
315!> \param potential_energy ...
316!> \param additional_potential ...
317!> \param kinetic_energy ...
318!> \param harmonic_shell ...
319!> \param kinetic_shell ...
320!> \param cell ...
321!> \param sub_force_env ...
322!> \param qmmm_env ...
323!> \param qmmmx_env ...
324!> \param eip_env ...
325!> \param pwdft_env ...
326!> \param globenv ...
327!> \param input ...
328!> \param force_env_section ...
329!> \param method_name_id ...
330!> \param root_section ...
331!> \param mixed_env ...
332!> \param nnp_env ...
333!> \param embed_env ...
334!> \param ipi_env ...
335!> \par History
336!> 04.2003 created [fawzi]
337!> \author fawzi
338! **************************************************************************************************
339 RECURSIVE SUBROUTINE force_env_get(force_env, in_use, fist_env, qs_env, &
340 meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, &
341 kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, &
342 qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, &
343 method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
344 TYPE(force_env_type), INTENT(IN) :: force_env
345 INTEGER, INTENT(out), OPTIONAL :: in_use
346 TYPE(fist_environment_type), OPTIONAL, POINTER :: fist_env
347 TYPE(qs_environment_type), OPTIONAL, POINTER :: qs_env
348 TYPE(meta_env_type), OPTIONAL, POINTER :: meta_env
349 TYPE(fp_type), OPTIONAL, POINTER :: fp_env
350 TYPE(cp_subsys_type), OPTIONAL, POINTER :: subsys
351 TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
352 REAL(kind=dp), INTENT(OUT), OPTIONAL :: potential_energy, additional_potential, &
353 kinetic_energy, harmonic_shell, &
354 kinetic_shell
355 TYPE(cell_type), OPTIONAL, POINTER :: cell
356 TYPE(force_env_p_type), DIMENSION(:), OPTIONAL, &
357 POINTER :: sub_force_env
358 TYPE(qmmm_env_type), OPTIONAL, POINTER :: qmmm_env
359 TYPE(qmmmx_env_type), OPTIONAL, POINTER :: qmmmx_env
360 TYPE(eip_environment_type), OPTIONAL, POINTER :: eip_env
361 TYPE(pwdft_environment_type), OPTIONAL, POINTER :: pwdft_env
362 TYPE(global_environment_type), OPTIONAL, POINTER :: globenv
363 TYPE(section_vals_type), OPTIONAL, POINTER :: input, force_env_section
364 INTEGER, INTENT(out), OPTIONAL :: method_name_id
365 TYPE(section_vals_type), OPTIONAL, POINTER :: root_section
366 TYPE(mixed_environment_type), OPTIONAL, POINTER :: mixed_env
367 TYPE(nnp_type), OPTIONAL, POINTER :: nnp_env
368 TYPE(embed_env_type), OPTIONAL, POINTER :: embed_env
369 TYPE(ipi_environment_type), OPTIONAL, POINTER :: ipi_env
370
371 REAL(kind=dp) :: eip_kinetic_energy, eip_potential_energy
372 TYPE(cp_subsys_type), POINTER :: subsys_tmp
373 TYPE(fist_energy_type), POINTER :: thermo
374 TYPE(mixed_energy_type), POINTER :: mixed_energy
375 TYPE(pwdft_energy_type), POINTER :: pwdft_energy
376 TYPE(qs_energy_type), POINTER :: qs_energy
377
378 NULLIFY (subsys_tmp)
379
380 cpassert(force_env%ref_count > 0)
381
382 SELECT CASE (force_env%in_use)
383 CASE (use_qs_force)
384 cpassert(ASSOCIATED(force_env%qs_env))
385 cpassert(.NOT. PRESENT(fist_env))
386 cpassert(.NOT. PRESENT(eip_env))
387 cpassert(.NOT. PRESENT(pwdft_env))
388 cpassert(.NOT. PRESENT(ipi_env))
389 CALL get_qs_env(force_env%qs_env, &
390 energy=qs_energy, &
391 input=input, &
392 cp_subsys=subsys)
393 IF (PRESENT(potential_energy)) potential_energy = qs_energy%total
394 cpassert(.NOT. PRESENT(kinetic_energy))
395 CASE (use_fist_force)
396 cpassert(ASSOCIATED(force_env%fist_env))
397 cpassert(.NOT. PRESENT(input))
398 CALL fist_env_get(force_env%fist_env, &
399 thermo=thermo, &
400 subsys=subsys)
401 IF (PRESENT(potential_energy)) potential_energy = thermo%pot
402 IF (PRESENT(kinetic_energy)) kinetic_energy = thermo%kin
403 IF (PRESENT(kinetic_shell)) kinetic_shell = thermo%kin_shell
404 IF (PRESENT(harmonic_shell)) harmonic_shell = thermo%harm_shell
405 CASE (use_eip_force)
406 cpassert(ASSOCIATED(force_env%eip_env))
407 cpassert(.NOT. PRESENT(qs_env))
408 cpassert(.NOT. PRESENT(fist_env))
409 cpassert(.NOT. PRESENT(ipi_env))
410 CALL eip_env_get(force_env%eip_env, &
411 eip_potential_energy=eip_potential_energy, &
412 eip_kinetic_energy=eip_kinetic_energy, &
413 subsys=subsys)
414 IF (PRESENT(potential_energy)) THEN
415 potential_energy = eip_potential_energy
416 END IF
417 IF (PRESENT(kinetic_energy)) kinetic_energy = eip_kinetic_energy
418 cpassert(.NOT. PRESENT(kinetic_energy))
419 CASE (use_pwdft_force)
420 cpassert(ASSOCIATED(force_env%pwdft_env))
421 cpassert(.NOT. PRESENT(qs_env))
422 cpassert(.NOT. PRESENT(fist_env))
423 cpassert(.NOT. PRESENT(ipi_env))
424 CALL pwdft_env_get(force_env%pwdft_env, energy=pwdft_energy)
425 CALL pwdft_env_get(force_env%pwdft_env, cp_subsys=subsys)
426 IF (PRESENT(potential_energy)) potential_energy = pwdft_energy%etotal
427 cpassert(.NOT. PRESENT(kinetic_energy))
428 CASE (use_qmmm)
429 CALL qmmm_env_get(force_env%qmmm_env, &
430 subsys=subsys, &
431 potential_energy=potential_energy, &
432 kinetic_energy=kinetic_energy)
433 CASE (use_qmmmx)
434 CALL qmmmx_env_get(force_env%qmmmx_env, &
435 subsys=subsys, &
436 potential_energy=potential_energy, &
437 kinetic_energy=kinetic_energy)
438 CASE (use_mixed_force)
439 cpassert(ASSOCIATED(force_env%mixed_env))
440 cpassert(.NOT. PRESENT(input))
441 CALL get_mixed_env(force_env%mixed_env, &
442 mixed_energy=mixed_energy, &
443 subsys=subsys)
444 IF (PRESENT(potential_energy)) potential_energy = mixed_energy%pot
445 IF (PRESENT(kinetic_energy)) kinetic_energy = mixed_energy%kin
446 ! In embedding we only have potential energies (electronic energies)
447 CASE (use_embed)
448 cpassert(ASSOCIATED(force_env%embed_env))
449 cpassert(.NOT. PRESENT(input))
450 CALL get_embed_env(force_env%embed_env, &
451 pot_energy=potential_energy, &
452 subsys=subsys)
453 CASE (use_nnp_force)
454 cpassert(ASSOCIATED(force_env%nnp_env))
455 cpassert(.NOT. PRESENT(ipi_env))
456 CALL nnp_env_get(force_env%nnp_env, &
457 nnp_potential_energy=potential_energy, &
458 subsys=subsys)
459 cpassert(.NOT. PRESENT(kinetic_energy))
460 CASE (use_ipi)
461 CALL ipi_env_get(force_env%ipi_env, &
462 ipi_energy=potential_energy, &
463 subsys=subsys)
464 CASE DEFAULT
465 cpabort("unknown in_use flag value ")
466 END SELECT
467
468 IF (PRESENT(force_env_section)) force_env_section => force_env%force_env_section
469 IF (PRESENT(in_use)) in_use = force_env%in_use
470 IF (PRESENT(method_name_id)) method_name_id = force_env%method_name_id
471 IF (PRESENT(fist_env)) THEN
472 fist_env => force_env%fist_env
473 END IF
474 IF (PRESENT(qs_env)) THEN
475 qs_env => force_env%qs_env
476 END IF
477 IF (PRESENT(eip_env)) THEN
478 eip_env => force_env%eip_env
479 END IF
480 IF (PRESENT(pwdft_env)) THEN
481 pwdft_env => force_env%pwdft_env
482 END IF
483 IF (PRESENT(nnp_env)) THEN
484 nnp_env => force_env%nnp_env
485 END IF
486 IF (PRESENT(ipi_env)) THEN
487 ipi_env => force_env%ipi_env
488 END IF
489 IF (PRESENT(para_env)) para_env => force_env%para_env
490 ! adjust the total energy for the metadynamics
491 IF (ASSOCIATED(force_env%meta_env)) THEN
492 IF (PRESENT(potential_energy)) THEN
493 potential_energy = potential_energy + &
494 force_env%meta_env%epot_s + &
495 force_env%meta_env%epot_walls + &
496 force_env%meta_env%plumed_bias + &
497 force_env%meta_env%hills_env%energy
498 END IF
499 IF (PRESENT(kinetic_energy)) THEN
500 kinetic_energy = kinetic_energy + force_env%meta_env%ekin_s
501 END IF
502 END IF
503 ! adjust the total energy for the flexible partitioning
504 IF (ASSOCIATED(force_env%fp_env) .AND. PRESENT(potential_energy)) THEN
505 IF (force_env%fp_env%use_fp) THEN
506 potential_energy = potential_energy + force_env%fp_env%energy
507 END IF
508 END IF
509 IF (PRESENT(potential_energy)) THEN
510 potential_energy = potential_energy + force_env%additional_potential
511 END IF
512 IF (PRESENT(additional_potential)) THEN
513 additional_potential = force_env%additional_potential
514 END IF
515 IF (PRESENT(cell)) THEN
516 CALL force_env_get(force_env, subsys=subsys_tmp)
517 CALL cp_subsys_get(subsys_tmp, cell=cell)
518 END IF
519 IF (PRESENT(fp_env)) fp_env => force_env%fp_env
520 IF (PRESENT(meta_env)) meta_env => force_env%meta_env
521 IF (PRESENT(sub_force_env)) sub_force_env => force_env%sub_force_env
522 IF (PRESENT(qmmm_env)) qmmm_env => force_env%qmmm_env
523 IF (PRESENT(qmmmx_env)) qmmmx_env => force_env%qmmmx_env
524 IF (PRESENT(mixed_env)) mixed_env => force_env%mixed_env
525 IF (PRESENT(embed_env)) embed_env => force_env%embed_env
526 IF (PRESENT(ipi_env)) ipi_env => force_env%ipi_env
527 IF (PRESENT(globenv)) globenv => force_env%globenv
528 IF (PRESENT(root_section)) root_section => force_env%root_section
529
530 END SUBROUTINE force_env_get
531
532! **************************************************************************************************
533!> \brief returns the number of atoms
534!> \param force_env the force_env you what information about
535!> \return the number of atoms
536!> \date 22.11.2010 updated (MK)
537!> \author fawzi
538! **************************************************************************************************
539 FUNCTION force_env_get_natom(force_env) RESULT(n_atom)
540
541 TYPE(force_env_type), INTENT(IN) :: force_env
542 INTEGER :: n_atom
543
544 TYPE(cp_subsys_type), POINTER :: subsys
545
546 n_atom = 0
547 NULLIFY (subsys)
548 CALL force_env_get(force_env, subsys=subsys)
549 CALL cp_subsys_get(subsys, natom=n_atom)
550
551 END FUNCTION force_env_get_natom
552
553! **************************************************************************************************
554!> \brief returns the number of particles in a force environment
555!> \param force_env the force_env you what information about
556!> \return the number of particles
557!> \date 22.11.2010 (MK)
558!> \author Matthias Krack
559! **************************************************************************************************
560 FUNCTION force_env_get_nparticle(force_env) RESULT(n_particle)
561
562 TYPE(force_env_type), INTENT(IN) :: force_env
563 INTEGER :: n_particle
564
565 TYPE(cp_subsys_type), POINTER :: subsys
566
567 n_particle = 0
568 NULLIFY (subsys)
569 CALL force_env_get(force_env, subsys=subsys)
570 CALL cp_subsys_get(subsys, nparticle=n_particle)
571
572 END FUNCTION force_env_get_nparticle
573
574! **************************************************************************************************
575!> \brief returns the particle forces in a dimension(*) array
576!> \param force_env the force_env you want to get the forces
577!> \param frc the array of the forces
578!> \param n ...
579!> \date 22.11.2010 Creation
580!> \author Matthias Krack
581! **************************************************************************************************
582 SUBROUTINE force_env_get_frc(force_env, frc, n)
583
584 TYPE(force_env_type), INTENT(IN) :: force_env
585 REAL(kind=dp), DIMENSION(*), INTENT(OUT) :: frc
586 INTEGER, INTENT(IN) :: n
587
588 CHARACTER(LEN=*), PARAMETER :: routinen = 'force_env_get_frc'
589
590 INTEGER :: handle
591 TYPE(cp_subsys_type), POINTER :: subsys
592
593 CALL timeset(routinen, handle)
594 cpassert(force_env%ref_count > 0)
595 CALL force_env_get(force_env, subsys=subsys)
596 CALL pack_subsys_particles(subsys=subsys, f=frc(1:n))
597 CALL timestop(handle)
598
599 END SUBROUTINE force_env_get_frc
600
601! **************************************************************************************************
602!> \brief returns the particle positions in a dimension(*) array
603!> \param force_env the force_env you want to get the positions
604!> \param pos the array of the positions
605!> \param n ...
606!> \date 22.11.2010 updated (MK)
607!> \author fawzi
608! **************************************************************************************************
609 SUBROUTINE force_env_get_pos(force_env, pos, n)
610
611 TYPE(force_env_type), INTENT(IN) :: force_env
612 REAL(kind=dp), DIMENSION(*), INTENT(OUT) :: pos
613 INTEGER, INTENT(IN) :: n
614
615 CHARACTER(LEN=*), PARAMETER :: routinen = 'force_env_get_pos'
616
617 INTEGER :: handle
618 TYPE(cp_subsys_type), POINTER :: subsys
619
620 CALL timeset(routinen, handle)
621 cpassert(force_env%ref_count > 0)
622 CALL force_env_get(force_env, subsys=subsys)
623 CALL pack_subsys_particles(subsys=subsys, r=pos(1:n))
624 CALL timestop(handle)
625
626 END SUBROUTINE force_env_get_pos
627
628! **************************************************************************************************
629!> \brief returns the particle velocities in a dimension(*) array
630!> \param force_env the force_env you want to get the velocities
631!> \param vel the array of the velocities
632!> \param n ...
633!> \date 22.11.2010 Creation (MK)
634!> \author Matthias Krack
635! **************************************************************************************************
636 SUBROUTINE force_env_get_vel(force_env, vel, n)
637
638 TYPE(force_env_type), INTENT(IN) :: force_env
639 REAL(kind=dp), DIMENSION(*), INTENT(OUT) :: vel
640 INTEGER, INTENT(IN) :: n
641
642 CHARACTER(LEN=*), PARAMETER :: routinen = 'force_env_get_vel'
643
644 INTEGER :: handle
645 TYPE(cp_subsys_type), POINTER :: subsys
646
647 CALL timeset(routinen, handle)
648 cpassert(force_env%ref_count > 0)
649 CALL force_env_get(force_env, subsys=subsys)
650 CALL pack_subsys_particles(subsys=subsys, v=vel(1:n))
651 CALL timestop(handle)
652
653 END SUBROUTINE force_env_get_vel
654
655! **************************************************************************************************
656!> \brief changes some attributes of the force_env
657!> \param force_env the force environment where the cell should be changed
658!> \param meta_env the new meta environment
659!> \param fp_env ...
660!> \param force_env_section ...
661!> \param method_name_id ...
662!> \param additional_potential ...
663!> \par History
664!> 09.2003 created [fawzi]
665!> \author Fawzi Mohamed
666! **************************************************************************************************
667 SUBROUTINE force_env_set(force_env, meta_env, fp_env, force_env_section, &
668 method_name_id, additional_potential)
669
670 TYPE(force_env_type), INTENT(INOUT) :: force_env
671 TYPE(meta_env_type), OPTIONAL, POINTER :: meta_env
672 TYPE(fp_type), OPTIONAL, POINTER :: fp_env
673 TYPE(section_vals_type), OPTIONAL, POINTER :: force_env_section
674 INTEGER, OPTIONAL :: method_name_id
675 REAL(kind=dp), INTENT(IN), OPTIONAL :: additional_potential
676
677 cpassert(force_env%ref_count > 0)
678 IF (PRESENT(meta_env)) THEN
679 IF (ASSOCIATED(force_env%meta_env)) THEN
680 CALL meta_env_release(force_env%meta_env)
681 DEALLOCATE (force_env%meta_env)
682 END IF
683 force_env%meta_env => meta_env
684 END IF
685 IF (PRESENT(fp_env)) THEN
686 IF (ASSOCIATED(force_env%fp_env)) CALL fp_env_release(force_env%fp_env)
687 force_env%fp_env => fp_env
688 END IF
689 IF (PRESENT(force_env_section)) THEN
690 IF (ASSOCIATED(force_env_section)) THEN
691 CALL section_vals_retain(force_env_section)
692 CALL section_vals_release(force_env%force_env_section)
693 force_env%force_env_section => force_env_section
694 END IF
695 END IF
696 IF (PRESENT(additional_potential)) THEN
697 force_env%additional_potential = additional_potential
698 END IF
699 IF (PRESENT(method_name_id)) THEN
700 force_env%method_name_id = method_name_id
701 END IF
702
703 END SUBROUTINE force_env_set
704
705! **************************************************************************************************
706!> \brief returns the order of the multiple force_env
707!> \param force_env_sections ...
708!> \param root_section ...
709!> \param i_force_eval ...
710!> \param nforce_eval ...
711!> \author teo
712! **************************************************************************************************
713 SUBROUTINE multiple_fe_list(force_env_sections, root_section, i_force_eval, nforce_eval)
714
715 TYPE(section_vals_type), INTENT(IN) :: force_env_sections, root_section
716 INTEGER, DIMENSION(:), POINTER :: i_force_eval
717 INTEGER :: nforce_eval
718
719 INTEGER :: iforce_eval, main_force_eval
720 INTEGER, DIMENSION(:), POINTER :: my_i_force_eval
721
722! Let's treat the case of Multiple force_eval
723
724 CALL section_vals_get(force_env_sections, n_repetition=nforce_eval)
725 CALL section_vals_val_get(root_section, "MULTIPLE_FORCE_EVALS%FORCE_EVAL_ORDER", &
726 i_vals=my_i_force_eval)
727 ALLOCATE (i_force_eval(nforce_eval))
728 IF (nforce_eval > 0) THEN
729 IF (nforce_eval == SIZE(my_i_force_eval)) THEN
730 i_force_eval = my_i_force_eval
731 ELSE
732 ! The difference in the amount of defined force_env MUST be one..
733 cpassert(nforce_eval - SIZE(my_i_force_eval) == 1)
734 DO iforce_eval = 1, nforce_eval
735 IF (any(my_i_force_eval == iforce_eval)) cycle
736 main_force_eval = iforce_eval
737 EXIT
738 END DO
739 i_force_eval(1) = main_force_eval
740 i_force_eval(2:nforce_eval) = my_i_force_eval
741 END IF
742 END IF
743
744 END SUBROUTINE multiple_fe_list
745
746END MODULE force_env_types
Handles all functions related to the CELL.
Definition cell_types.F:15
various routines to log and control the output. The idea is that decisions about where to log should ...
subroutine, public cp_rm_default_logger()
the cousin of cp_add_default_logger, decrements the stack, so that the default logger is what it has ...
subroutine, public cp_add_default_logger(logger)
adds a default logger. MUST be called before logging occours
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell)
returns information about various attributes of the given subsys
subroutine, public pack_subsys_particles(subsys, f, r, s, v, fscale, cell)
Pack components of a subsystem particle sets into a single vector.
The environment for the empirical interatomic potential methods.
subroutine, public eip_env_release(eip_env)
Releases the given eip environment (see doc/ReferenceCounting.html).
subroutine, public eip_env_get(eip_env, eip_model, eip_energy, eip_energy_var, eip_forces, coord_avg, coord_var, count, subsys, atomic_kind_set, particle_set, local_particles, molecule_kind_set, molecule_set, local_molecules, eip_input, force_env_input, cell, cell_ref, use_ref_cell, eip_kinetic_energy, eip_potential_energy, virial)
Returns various attributes of the eip environment.
subroutine, public get_embed_env(embed_env, atomic_kind_set, particle_set, local_particles, local_molecules, molecule_kind_set, molecule_set, cell, cell_ref, para_env, sub_para_env, subsys, input, results, pot_energy)
Get the embed environment.
subroutine, public embed_env_release(embed_env)
...
subroutine, public fist_env_release(fist_env)
releases the given fist_env (see doc/ReferenceCounting.html)
subroutine, public fist_env_get(fist_env, atomic_kind_set, particle_set, ewald_pw, local_particles, local_molecules, molecule_kind_set, molecule_set, cell, cell_ref, ewald_env, fist_nonbond_env, thermo, para_env, subsys, qmmm, qmmm_env, input, shell_model, shell_model_ad, shell_particle_set, core_particle_set, multipoles, results, exclusions, efield)
Purpose: Get the FIST environment.
Interface for the force calculations.
integer function, public force_env_get_natom(force_env)
returns the number of atoms
subroutine, public force_env_get_vel(force_env, vel, n)
returns the particle velocities in a dimension(*) array
integer, parameter, public use_qmmm
subroutine, public multiple_fe_list(force_env_sections, root_section, i_force_eval, nforce_eval)
returns the order of the multiple force_env
integer, parameter, public use_mixed_force
character(len=10), dimension(501:510), parameter, public use_prog_name
integer, parameter, public use_eip_force
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
integer, parameter, public use_embed
integer, parameter, public use_qmmmx
subroutine, public force_env_retain(force_env)
retains the given force env
subroutine, public force_env_get_pos(force_env, pos, n)
returns the particle positions in a dimension(*) array
subroutine, public force_env_set(force_env, meta_env, fp_env, force_env_section, method_name_id, additional_potential)
changes some attributes of the force_env
integer, parameter, public use_qs_force
subroutine, public force_env_get_frc(force_env, frc, n)
returns the particle forces in a dimension(*) array
integer, parameter, public use_pwdft_force
integer, parameter, public use_nnp_force
recursive subroutine, public force_env_release(force_env)
releases the given force env
integer, parameter, public use_ipi
integer, parameter, public use_fist_force
integer function, public force_env_get_nparticle(force_env)
returns the number of particles in a force environment
types used in the flexible partitioning scheme
Definition fp_types.F:14
subroutine, public fp_env_release(fp_env)
...
Definition fp_types.F:80
Define type storing the global information of a run. Keep the amount of stored data small....
subroutine, public globenv_release(globenv)
Releases the global environment globenv.
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_retain(section_vals)
retains the given section values (see doc/ReferenceCounting.html)
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
recursive subroutine, public section_vals_release(section_vals)
releases the given object
The environment for the empirical interatomic potential methods.
subroutine, public ipi_env_get(ipi_env, ipi_energy, ipi_forces, subsys, atomic_kind_set, particle_set, local_particles, molecule_kind_set, molecule_set, local_molecules, force_env_input, cell, cell_ref, virial, sockfd)
Returns various attributes of the ipi environment.
subroutine, public ipi_env_release(ipi_env)
Releases the given ipi environment (see doc/ReferenceCounting.html).
i–PI server mode: Communication with i–PI clients
Definition ipi_server.F:14
subroutine, public shutdown_server(ipi_env)
Shut down the i–PI server.
Definition ipi_server.F:159
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
defines types for metadynamics calculation
subroutine, public meta_env_release(meta_env)
releases the meta_env
subroutine, public mixed_env_release(mixed_env)
releases the given mixed_env (see doc/ReferenceCounting.html)
subroutine, public get_mixed_env(mixed_env, atomic_kind_set, particle_set, local_particles, local_molecules, molecule_kind_set, molecule_set, cell, cell_ref, mixed_energy, para_env, sub_para_env, subsys, input, results, cdft_control)
Get the MIXED environment.
Data types for neural network potentials.
subroutine, public nnp_env_get(nnp_env, nnp_forces, subsys, atomic_kind_set, particle_set, local_particles, molecule_kind_set, molecule_set, local_molecules, nnp_input, force_env_input, cell, cell_ref, use_ref_cell, nnp_potential_energy, virial)
Returns various attributes of the nnp environment.
subroutine, public nnp_env_release(nnp_env)
Release data structure that holds all the information for neural network potentials.
The type definitions for the PWDFT environment.
subroutine, public pwdft_env_get(pwdft_env, pwdft_input, force_env_input, xc_input, cp_subsys, qs_subsys, para_env, energy, forces, stress, sctx, gs_handler, ks_handler)
Returns various attributes of the pwdft environment.
subroutine, public pwdft_env_release(pwdft_env)
Releases the given pwdft environment.
Basic container type for QM/MM.
Definition qmmm_types.F:12
subroutine, public qmmm_env_release(qmmm_env)
releases the given qmmm_env (see doc/ReferenceCounting.html)
Definition qmmm_types.F:81
subroutine, public qmmm_env_get(qmmm_env, subsys, potential_energy, kinetic_energy)
...
Definition qmmm_types.F:50
Basic container type for QM/MM with force mixing.
Definition qmmmx_types.F:12
subroutine, public qmmmx_env_release(qmmmx_env)
releases the given qmmmx_env (see doc/ReferenceCounting.html)
Definition qmmmx_types.F:61
subroutine, public qmmmx_env_get(qmmmx_env, subsys, potential_energy, kinetic_energy)
...
Definition qmmmx_types.F:42
Perform a QUICKSTEP wavefunction optimization (single point).
Definition qs_energy.F:14
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public qs_env_release(qs_env)
releases the given qs_env (see doc/ReferenceCounting.html)
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represents a system: atoms, molecules, their pos,vel,...
The empirical interatomic potential environment.
Embedding environment type.
allows for the creation of an array of force_env
wrapper to abstract the force evaluation of the various methods
contains the initially parsed file and the initial parallel environment
stores all the informations relevant to an mpi environment
Main data type collecting all relevant data for neural network potentials.