184#include "./base/base_uses.f90"
190 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'force_env_methods'
196 INTEGER,
SAVE,
PRIVATE :: last_force_env_id = 0
216 consistent_energies, skip_external_control, eval_energy_forces, &
217 require_consistent_energy_force, linres, calc_stress_tensor)
220 LOGICAL,
INTENT(IN),
OPTIONAL :: calc_force, consistent_energies, skip_external_control, &
221 eval_energy_forces, require_consistent_energy_force, linres, calc_stress_tensor
223 REAL(kind=
dp),
PARAMETER :: ateps = 1.0e-6_dp
225 CHARACTER(LEN=default_string_length) :: unit_string
226 INTEGER :: ikind, nat, ndigits, nfixed_atoms, &
227 nfixed_atoms_total, nkind, &
228 output_unit, print_forces, print_grrm, &
230 LOGICAL :: calculate_forces, calculate_stress_tensor, do_apt_fd, energy_consistency, &
231 eval_ef, linres_run, my_skip, print_components
232 REAL(kind=
dp) :: checksum, e_entropy, e_gap, e_pot, &
234 REAL(kind=
dp),
DIMENSION(3) :: grand_total_force, total_force
247 NULLIFY (logger, virial, subsys, atprop_env, cell)
251 calculate_forces = .true.
252 energy_consistency = .false.
258 IF (
PRESENT(eval_energy_forces)) eval_ef = eval_energy_forces
259 IF (
PRESENT(skip_external_control)) my_skip = skip_external_control
260 IF (
PRESENT(calc_force)) calculate_forces = calc_force
261 IF (
PRESENT(calc_stress_tensor))
THEN
262 calculate_stress_tensor = calc_stress_tensor
264 calculate_stress_tensor = calculate_forces
266 IF (
PRESENT(consistent_energies)) energy_consistency = consistent_energies
267 IF (
PRESENT(linres)) linres_run = linres
269 cpassert(
ASSOCIATED(force_env))
270 cpassert(force_env%ref_count > 0)
273 CALL cp_subsys_get(subsys, virial=virial, atprop=atprop_env, cell=cell)
274 IF (virial%pv_availability)
CALL zero_virial(virial, reset=.false.)
279 SELECT CASE (force_env%in_use)
283 CALL force_env_refresh_kpoint_symmetry(force_env, fd_energy=.NOT. calculate_forces)
286 IF (virial%pv_availability .AND. calculate_stress_tensor)
THEN
291 e_gap = force_env%pwdft_env%energy%band_gap
292 e_entropy = force_env%pwdft_env%energy%entropy
294 SELECT CASE (force_env%eip_env%eip_model)
304 cpabort(
"Unknown EIP model.")
308 calculate_forces, energy_consistency, linres=linres_run)
311 calculate_forces, energy_consistency, linres=linres_run, &
312 require_consistent_energy_force=require_consistent_energy_force)
314 CALL mixed_energy_forces(force_env, calculate_forces)
319 CALL embed_energy(force_env)
327 IF (virial%pv_availability)
THEN
328 IF (virial%pv_numer .AND. calculate_stress_tensor)
THEN
332 IF (calculate_forces)
THEN
336 IF (calculate_stress_tensor)
THEN
337 CALL cp_warn(__location__,
"The calculation of the stress tensor "// &
338 "requires the calculation of the forces")
347 CALL section_vals_val_get(force_env%qs_env%input,
"PROPERTIES%LINRES%DCDR%APT_FD", l_val=do_apt_fd)
350 subsection_name=
"PROPERTIES%LINRES%DCDR%PRINT%APT")
361 IF (.NOT. my_skip)
THEN
363 IF (
ASSOCIATED(force_env%fp_env))
THEN
364 IF (force_env%fp_env%use_fp)
THEN
365 CALL fp_eval(force_env%fp_env, subsys, cell)
383 output_unit =
cp_print_key_unit_nr(logger, force_env%force_env_section,
"PRINT%PROGRAM_RUN_INFO", &
385 IF (output_unit > 0)
THEN
389 WRITE (unit=output_unit, fmt=
"(/,T2,A,T55,F26.15)") &
390 "ENERGY| Total FORCE_EVAL ( "//trim(adjustl(
use_prog_name(force_env%in_use)))// &
391 " ) energy ["//trim(adjustl(unit_string))//
"]", e_pot*fconv
392 IF (e_gap > -0.1_dp)
THEN
393 WRITE (unit=output_unit, fmt=
"(/,T2,A,T55,F26.15)") &
394 "ENERGY| Total FORCE_EVAL ( "//trim(adjustl(
use_prog_name(force_env%in_use)))// &
395 " ) gap ["//trim(adjustl(unit_string))//
"]", e_gap*fconv
397 IF (e_entropy > -0.1_dp)
THEN
398 WRITE (unit=output_unit, fmt=
"(/,T2,A,T55,F26.15)") &
399 "ENERGY| Total FORCE_EVAL ( "//trim(adjustl(
use_prog_name(force_env%in_use)))// &
400 " ) free energy ["//trim(adjustl(unit_string))//
"]", (e_pot - e_entropy)*fconv
404 "PRINT%PROGRAM_RUN_INFO")
408 cpabort(
"Potential energy is an abnormal value (NaN/Inf).")
413 IF ((print_forces > 0) .AND. calculate_forces)
THEN
416 core_particles=core_particles, &
417 particles=particles, &
418 shell_particles=shell_particles)
424 IF (
ASSOCIATED(core_particles) .OR.
ASSOCIATED(shell_particles))
THEN
425 CALL write_forces(particles, print_forces,
"Atomic", ndigits, unit_string, &
426 total_force, zero_force_core_shell_atom=.true.)
427 grand_total_force(1:3) = total_force(1:3)
428 IF (
ASSOCIATED(core_particles))
THEN
429 CALL write_forces(core_particles, print_forces,
"Core particle", ndigits, &
430 unit_string, total_force, zero_force_core_shell_atom=.false.)
431 grand_total_force(:) = grand_total_force(:) + total_force(:)
433 IF (
ASSOCIATED(shell_particles))
THEN
434 CALL write_forces(shell_particles, print_forces,
"Shell particle", ndigits, &
435 unit_string, total_force, zero_force_core_shell_atom=.false., &
436 grand_total_force=grand_total_force)
439 CALL write_forces(particles, print_forces,
"Atomic", ndigits, unit_string, total_force)
445 IF (virial%pv_availability)
THEN
448 IF (calculate_forces .AND. calculate_stress_tensor)
THEN
449 output_unit =
cp_print_key_unit_nr(logger, force_env%force_env_section,
"PRINT%STRESS_TENSOR", &
450 extension=
".stress_tensor")
451 IF (output_unit > 0)
THEN
453 l_val=print_components)
456 IF (print_components)
THEN
457 IF ((.NOT. virial%pv_numer) .AND. (force_env%in_use ==
use_qs_force))
THEN
461 CALL write_stress_tensor(virial%pv_virial, output_unit, cell, unit_string, virial%pv_numer)
464 "PRINT%STRESS_TENSOR")
469 output_unit =
cp_print_key_unit_nr(logger, force_env%force_env_section,
"PRINT%STRESS_TENSOR", &
470 extension=
".stress_tensor")
471 IF (output_unit > 0)
THEN
472 CALL cp_warn(__location__,
"To print the stress tensor switch on the "// &
473 "virial evaluation with the keyword: STRESS_TENSOR")
476 "PRINT%STRESS_TENSOR")
480 output_unit =
cp_print_key_unit_nr(logger, force_env%force_env_section,
"PRINT%PROGRAM_RUN_INFO", &
482 IF (atprop_env%energy)
THEN
483 CALL force_env%para_env%sum(atprop_env%atener)
485 IF (output_unit > 0)
THEN
488 CALL write_atener(output_unit, particles, atprop_env%atener,
"Mulliken Atomic Energies")
491 checksum = abs(e_pot - sum_energy)
492 WRITE (unit=output_unit, fmt=
"(/,(T2,A,T56,F25.13))") &
493 "Potential energy (Atomic):", sum_energy, &
494 "Potential energy (Total) :", e_pot, &
495 "Difference :", checksum
496 cpassert((checksum < ateps*abs(e_pot)))
499 "PRINT%PROGRAM_RUN_INFO")
504 file_position=
"REWIND", extension=
".rrm")
505 IF (print_grrm > 0)
THEN
508 molecule_kinds=molecule_kinds)
510 nfixed_atoms_total = 0
511 nkind = molecule_kinds%n_els
512 molecule_kind_set => molecule_kinds%els
514 molecule_kind => molecule_kind_set(ikind)
516 nfixed_atoms_total = nfixed_atoms_total + nfixed_atoms
519 CALL write_grrm(print_grrm, force_env, particles%els, e_pot, fixed_atoms=nfixed_atoms_total)
524 file_position=
"REWIND", extension=
".scine")
525 IF (print_scine > 0)
THEN
529 CALL write_scine(print_scine, force_env, particles%els, e_pot)
541 SUBROUTINE force_env_refresh_kpoint_symmetry(force_env, fd_energy)
544 LOGICAL,
INTENT(IN) :: fd_energy
546 CHARACTER(LEN=default_string_length) :: kp_scheme
547 INTEGER :: run_type_id
548 LOGICAL :: debug_full_kpoint_symmetry, debug_inversion_only, do_kpoints, dynamic_symmetry, &
549 full_grid, input_full_grid, input_inversion_symmetry_only, inversion_symmetry_only, &
550 kpoint_symmetry, moving_geometry, use_full_grid, use_inversion_symmetry_only
562 IF (.NOT.
ASSOCIATED(force_env))
RETURN
567 IF (.NOT.
ASSOCIATED(globenv))
RETURN
568 run_type_id = globenv%run_type_id
569 moving_geometry = .false.
570 SELECT CASE (run_type_id)
572 moving_geometry = .true.
574 moving_geometry = .false.
576 IF (run_type_id /=
debug_run .AND. .NOT. moving_geometry)
RETURN
578 NULLIFY (blacs_env, cell, dft_control, input, kpoint_section, kpoints, mos, para_env, &
579 particle_set, wf_history)
581 blacs_env=blacs_env, &
583 dft_control=dft_control, &
584 do_kpoints=do_kpoints, &
589 particle_set=particle_set, &
590 wf_history=wf_history)
591 IF (.NOT. do_kpoints)
RETURN
593 CALL get_kpoint_info(kpoints, kp_scheme=kp_scheme, symmetry=kpoint_symmetry, full_grid=full_grid, &
594 inversion_symmetry_only=inversion_symmetry_only)
595 IF (.NOT. kpoint_symmetry)
RETURN
596 IF (trim(kp_scheme) /=
"MONKHORST-PACK" .AND. trim(kp_scheme) /=
"MACDONALD" .AND. &
597 trim(kp_scheme) /=
"GENERAL")
RETURN
599 input_full_grid = full_grid
600 input_inversion_symmetry_only = inversion_symmetry_only
601 debug_full_kpoint_symmetry = .false.
602 IF (
ASSOCIATED(input))
THEN
606 l_val=input_inversion_symmetry_only)
608 l_val=debug_full_kpoint_symmetry)
614 debug_inversion_only = run_type_id ==
debug_run .AND. .NOT. debug_full_kpoint_symmetry .AND. &
615 (fd_energy .OR. dft_control%qs_control%dftb)
616 use_full_grid = input_full_grid
617 use_inversion_symmetry_only = (input_inversion_symmetry_only .OR. debug_inversion_only) .AND. &
618 (.NOT. use_full_grid)
619 dynamic_symmetry = kpoint_symmetry .AND. .NOT. use_full_grid .AND. &
620 .NOT. use_inversion_symmetry_only
621 IF (run_type_id ==
debug_run .AND. .NOT. fd_energy .AND. .NOT. dynamic_symmetry .AND. &
622 (full_grid .EQV. use_full_grid) .AND. &
623 (inversion_symmetry_only .EQV. use_inversion_symmetry_only))
THEN
627 IF (moving_geometry .AND. .NOT. dynamic_symmetry)
RETURN
628 IF (moving_geometry .AND. .NOT. kpoint_has_nontrivial_atomic_symmetry(kpoints))
RETURN
630 inversion_symmetry_only=use_inversion_symmetry_only)
639 END SUBROUTINE force_env_refresh_kpoint_symmetry
646 FUNCTION kpoint_has_nontrivial_atomic_symmetry(kpoints)
RESULT(has_symmetry)
649 LOGICAL :: has_symmetry
651 INTEGER :: iatom, ik, isym, natom
652 REAL(kind=
dp),
DIMENSION(3, 3) :: eye3
655 has_symmetry = .false.
656 IF (.NOT.
ASSOCIATED(kpoints))
RETURN
657 IF (.NOT.
ASSOCIATED(kpoints%kp_sym))
RETURN
664 DO ik = 1, kpoints%nkp
665 kpsym => kpoints%kp_sym(ik)%kpoint_sym
666 IF (.NOT.
ASSOCIATED(
kpsym)) cycle
667 IF (.NOT.
kpsym%apply_symmetry) cycle
668 IF (.NOT.
ASSOCIATED(
kpsym%rot)) cycle
669 IF (.NOT.
ASSOCIATED(
kpsym%f0)) cycle
670 IF (.NOT.
ASSOCIATED(
kpsym%fcell)) cycle
672 natom =
SIZE(
kpsym%f0, 1)
673 DO isym = 1,
SIZE(
kpsym%rot, 3)
674 IF (maxval(abs(
kpsym%rot(1:3, 1:3, isym) - eye3(1:3, 1:3))) > 1.e-12_dp .OR. &
675 any(
kpsym%fcell(1:3, 1:natom, isym) /= 0))
THEN
676 has_symmetry = .true.
680 IF (
kpsym%f0(iatom, isym) /= iatom)
THEN
681 has_symmetry = .true.
688 END FUNCTION kpoint_has_nontrivial_atomic_symmetry
703 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: dx
705 REAL(kind=
dp),
PARAMETER :: default_dx = 0.001_dp
707 CHARACTER(LEN=default_string_length) :: unit_string
708 INTEGER :: i, ip, iq, j, k, method_id, natom, &
709 ncore, nshell, output_unit, symmetry_id
710 LOGICAL :: use_sym_strain_2d
711 REAL(kind=
dp) :: dx_w, eps_w
712 REAL(kind=
dp),
DIMENSION(2) :: numer_energy
713 REAL(kind=
dp),
DIMENSION(3) :: s
714 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat_deformed, numer_pv_2d, &
716 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: ref_pos_atom, ref_pos_core, ref_pos_shell
717 TYPE(
cell_type),
POINTER :: cell, cell_local
727 NULLIFY (dft_control)
728 NULLIFY (core_particles)
730 NULLIFY (shell_particles)
731 NULLIFY (ref_pos_atom)
732 NULLIFY (ref_pos_core)
733 NULLIFY (ref_pos_shell)
739 numer_stress = 0.0_dp
740 use_sym_strain_2d = .false.
745 IF (
PRESENT(dx)) dx_w = dx
746 CALL force_env_get(force_env, subsys=subsys, globenv=globenv, in_use=method_id)
748 core_particles=core_particles, &
749 particles=particles, &
750 shell_particles=shell_particles, &
752 output_unit =
cp_print_key_unit_nr(logger, force_env%force_env_section,
"PRINT%STRESS_TENSOR", &
753 extension=
".stress_tensor")
754 IF (output_unit > 0)
THEN
755 WRITE (output_unit,
"(/A,A/)")
" **************************** ", &
756 "NUMERICAL STRESS ********************************"
760 natom = particles%n_els
761 ALLOCATE (ref_pos_atom(natom, 3))
763 ref_pos_atom(i, :) = particles%els(i)%r
765 IF (
ASSOCIATED(core_particles))
THEN
766 ncore = core_particles%n_els
767 ALLOCATE (ref_pos_core(ncore, 3))
769 ref_pos_core(i, :) = core_particles%els(i)%r
772 IF (
ASSOCIATED(shell_particles))
THEN
773 nshell = shell_particles%n_els
774 ALLOCATE (ref_pos_shell(nshell, 3))
776 ref_pos_shell(i, :) = shell_particles%els(i)%r
781 symmetry_id = cell%symmetry_id
786 IF (count(cell_local%perd /= 0) == 2 .AND. method_id ==
use_qs_force)
THEN
787 CALL get_qs_env(qs_env=force_env%qs_env, dft_control=dft_control)
788 SELECT CASE (dft_control%qs_control%method_id)
791 use_sym_strain_2d = .true.
797 IF (use_sym_strain_2d)
THEN
798 IF (cell_local%perd(ip) == 0 .OR. cell_local%perd(iq) == 0) cycle
801 IF (virial%pv_diagonal .AND. (ip /= iq)) cycle
803 hmat_deformed = cell_local%hmat
804 IF (use_sym_strain_2d)
THEN
805 eps_w = -(-1.0_dp)**k*dx_w
808 strain(i, i) = 1.0_dp
811 strain(ip, ip) = strain(ip, ip) + eps_w
813 strain(ip, iq) = strain(ip, iq) + 0.5_dp*eps_w
814 strain(iq, ip) = strain(iq, ip) + 0.5_dp*eps_w
816 hmat_deformed = matmul(strain, cell_local%hmat)
818 hmat_deformed(ip, iq) = hmat_deformed(ip, iq) - (-1.0_dp)**k*dx_w
820 cell%hmat = hmat_deformed
837 calc_force=.false., &
838 consistent_energies=.true., &
839 calc_stress_tensor=.false.)
840 CALL force_env_get(force_env, potential_energy=numer_energy(k))
842 cell%hmat = cell_local%hmat
845 IF (use_sym_strain_2d)
THEN
846 numer_pv_2d(ip, iq) = -0.5_dp*(numer_energy(1) - numer_energy(2))/dx_w
847 numer_pv_2d(iq, ip) = numer_pv_2d(ip, iq)
848 IF (output_unit > 0)
THEN
849 IF (globenv%run_type_id ==
debug_run)
THEN
850 WRITE (unit=output_unit, fmt=
"(/,T2,A,T19,A,F7.4,A,T44,A,F7.4,A,T69,A)") &
851 "DEBUG|",
"E(e"//achar(119 + ip)//achar(119 + iq)//
" +", dx_w,
")", &
852 "E(e"//achar(119 + ip)//achar(119 + iq)//
" -", dx_w,
")", &
854 WRITE (unit=output_unit, fmt=
"(T2,A,2(1X,F24.8),1X,F22.8)") &
855 "DEBUG|", numer_energy(1:2), numer_pv_2d(ip, iq)
857 WRITE (unit=output_unit, fmt=
"(/,T7,A,F7.4,A,T27,A,F7.4,A,T49,A)") &
858 "E(e"//achar(119 + ip)//achar(119 + iq)//
" +", dx_w,
")", &
859 "E(e"//achar(119 + ip)//achar(119 + iq)//
" -", dx_w,
")", &
861 WRITE (unit=output_unit, fmt=
"(3(1X,F19.8))") &
862 numer_energy(1:2), numer_pv_2d(ip, iq)
866 numer_stress(ip, iq) = 0.5_dp*(numer_energy(1) - numer_energy(2))/dx_w
867 IF (output_unit > 0)
THEN
868 IF (globenv%run_type_id ==
debug_run)
THEN
869 WRITE (unit=output_unit, fmt=
"(/,T2,A,T19,A,F7.4,A,T44,A,F7.4,A,T69,A)") &
870 "DEBUG|",
"E("//achar(119 + ip)//achar(119 + iq)//
" +", dx_w,
")", &
871 "E("//achar(119 + ip)//achar(119 + iq)//
" -", dx_w,
")", &
873 WRITE (unit=output_unit, fmt=
"(T2,A,2(1X,F24.8),1X,F22.8)") &
874 "DEBUG|", numer_energy(1:2), numer_stress(ip, iq)
876 WRITE (unit=output_unit, fmt=
"(/,T7,A,F7.4,A,T27,A,F7.4,A,T49,A)") &
877 "E("//achar(119 + ip)//achar(119 + iq)//
" +", dx_w,
")", &
878 "E("//achar(119 + ip)//achar(119 + iq)//
" -", dx_w,
")", &
880 WRITE (unit=output_unit, fmt=
"(3(1X,F19.8))") &
881 numer_energy(1:2), numer_stress(ip, iq)
889 cell%symmetry_id = symmetry_id
892 particles%els(i)%r = ref_pos_atom(i, :)
895 core_particles%els(i)%r = ref_pos_core(i, :)
898 shell_particles%els(i)%r = ref_pos_shell(i, :)
901 calc_force=.false., &
902 consistent_energies=.true., &
903 calc_stress_tensor=.false.)
906 virial%pv_virial = 0.0_dp
907 IF (use_sym_strain_2d)
THEN
908 virial%pv_virial = numer_pv_2d
913 virial%pv_virial(i, j) = virial%pv_virial(i, j) - &
914 0.5_dp*(numer_stress(i, k)*cell_local%hmat(j, k) + &
915 numer_stress(j, k)*cell_local%hmat(i, k))
920 IF (output_unit > 0)
THEN
921 IF (globenv%run_type_id ==
debug_run)
THEN
924 CALL write_stress_tensor(virial%pv_virial, output_unit, cell, unit_string, virial%pv_numer)
926 WRITE (output_unit,
"(/,A,/)")
" **************************** "// &
927 "NUMERICAL STRESS END *****************************"
931 "PRINT%STRESS_TENSOR")
934 IF (
ASSOCIATED(ref_pos_atom))
THEN
935 DEALLOCATE (ref_pos_atom)
937 IF (
ASSOCIATED(ref_pos_core))
THEN
938 DEALLOCATE (ref_pos_core)
940 IF (
ASSOCIATED(ref_pos_shell))
THEN
941 DEALLOCATE (ref_pos_shell)
943 IF (
ASSOCIATED(cell_local))
CALL cell_release(cell_local)
972 qs_env, meta_env, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, force_env_section, &
973 mixed_env, embed_env, nnp_env, ipi_env)
983 POINTER :: sub_force_env
991 TYPE(
nnp_type),
OPTIONAL,
POINTER :: nnp_env
995 NULLIFY (force_env%fist_env, force_env%qs_env, &
996 force_env%para_env, force_env%globenv, &
997 force_env%meta_env, force_env%sub_force_env, &
998 force_env%qmmm_env, force_env%qmmmx_env, force_env%fp_env, &
999 force_env%force_env_section, force_env%eip_env, force_env%mixed_env, &
1000 force_env%embed_env, force_env%pwdft_env, force_env%nnp_env, &
1001 force_env%root_section)
1002 last_force_env_id = last_force_env_id + 1
1003 force_env%ref_count = 1
1004 force_env%in_use = 0
1005 force_env%additional_potential = 0.0_dp
1007 force_env%globenv => globenv
1010 force_env%root_section => root_section
1013 force_env%para_env => para_env
1014 CALL force_env%para_env%retain()
1017 force_env%force_env_section => force_env_section
1019 IF (
PRESENT(fist_env))
THEN
1020 cpassert(
ASSOCIATED(fist_env))
1021 cpassert(force_env%in_use == 0)
1023 force_env%fist_env => fist_env
1025 IF (
PRESENT(eip_env))
THEN
1026 cpassert(
ASSOCIATED(eip_env))
1027 cpassert(force_env%in_use == 0)
1029 force_env%eip_env => eip_env
1031 IF (
PRESENT(pwdft_env))
THEN
1032 cpassert(
ASSOCIATED(pwdft_env))
1033 cpassert(force_env%in_use == 0)
1035 force_env%pwdft_env => pwdft_env
1037 IF (
PRESENT(qs_env))
THEN
1038 cpassert(
ASSOCIATED(qs_env))
1039 cpassert(force_env%in_use == 0)
1041 force_env%qs_env => qs_env
1043 IF (
PRESENT(qmmm_env))
THEN
1044 cpassert(
ASSOCIATED(qmmm_env))
1045 cpassert(force_env%in_use == 0)
1047 force_env%qmmm_env => qmmm_env
1049 IF (
PRESENT(qmmmx_env))
THEN
1050 cpassert(
ASSOCIATED(qmmmx_env))
1051 cpassert(force_env%in_use == 0)
1053 force_env%qmmmx_env => qmmmx_env
1055 IF (
PRESENT(mixed_env))
THEN
1056 cpassert(
ASSOCIATED(mixed_env))
1057 cpassert(force_env%in_use == 0)
1059 force_env%mixed_env => mixed_env
1061 IF (
PRESENT(embed_env))
THEN
1062 cpassert(
ASSOCIATED(embed_env))
1063 cpassert(force_env%in_use == 0)
1065 force_env%embed_env => embed_env
1067 IF (
PRESENT(nnp_env))
THEN
1068 cpassert(
ASSOCIATED(nnp_env))
1069 cpassert(force_env%in_use == 0)
1071 force_env%nnp_env => nnp_env
1073 IF (
PRESENT(ipi_env))
THEN
1074 cpassert(
ASSOCIATED(ipi_env))
1075 cpassert(force_env%in_use == 0)
1077 force_env%ipi_env => ipi_env
1079 cpassert(force_env%in_use /= 0)
1081 IF (
PRESENT(sub_force_env))
THEN
1082 force_env%sub_force_env => sub_force_env
1085 IF (
PRESENT(meta_env))
THEN
1086 force_env%meta_env => meta_env
1088 NULLIFY (force_env%meta_env)
1109 SUBROUTINE mixed_energy_forces(force_env, calculate_forces)
1112 LOGICAL,
INTENT(IN) :: calculate_forces
1114 CHARACTER(LEN=default_path_length) :: coupling_function
1115 CHARACTER(LEN=default_string_length) :: def_error, description, this_error
1116 INTEGER :: iforce_eval, iparticle, istate(2), &
1117 jparticle, mixing_type, my_group, &
1118 natom, nforce_eval, source, unit_nr
1119 INTEGER,
DIMENSION(:),
POINTER :: glob_natoms, itmplist, map_index
1120 LOGICAL :: dip_exists
1121 REAL(kind=
dp) :: coupling_parameter, dedf, der_1, der_2, &
1122 dx, energy, err, lambda, lerr, &
1123 restraint_strength, restraint_target, &
1125 REAL(kind=
dp),
DIMENSION(3) :: dip_mix
1126 REAL(kind=
dp),
DIMENSION(:),
POINTER :: energies
1138 mapping_section, mixed_section, &
1141 TYPE(
virial_type),
POINTER :: loc_virial, virial_mix
1144 cpassert(
ASSOCIATED(force_env))
1147 subsys=subsys_mix, &
1148 force_env_section=force_env_section, &
1149 root_section=root_section, &
1152 particles=particles_mix, &
1153 virial=virial_mix, &
1154 results=results_mix)
1155 NULLIFY (map_index, glob_natoms, global_forces, itmplist)
1157 nforce_eval =
SIZE(force_env%sub_force_env)
1161 ALLOCATE (subsystems(nforce_eval))
1162 ALLOCATE (particles(nforce_eval))
1164 ALLOCATE (global_forces(nforce_eval))
1165 ALLOCATE (energies(nforce_eval))
1166 ALLOCATE (glob_natoms(nforce_eval))
1167 ALLOCATE (virials(nforce_eval))
1168 ALLOCATE (results(nforce_eval))
1175 IF (.NOT. force_env%mixed_env%do_mixed_cdft)
THEN
1176 DO iforce_eval = 1, nforce_eval
1177 NULLIFY (subsystems(iforce_eval)%subsys, particles(iforce_eval)%list)
1178 NULLIFY (results(iforce_eval)%results, virials(iforce_eval)%virial)
1179 ALLOCATE (virials(iforce_eval)%virial)
1181 IF (.NOT.
ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env)) cycle
1183 my_group = force_env%mixed_env%group_distribution(force_env%para_env%mepos)
1184 my_logger => force_env%mixed_env%sub_logger(my_group + 1)%p
1190 CALL force_env_get(force_env=force_env%sub_force_env(iforce_eval)%force_env, &
1191 subsys=subsystems(iforce_eval)%subsys)
1194 CALL cp_subsys_set(subsystems(iforce_eval)%subsys, cell=cell_mix)
1198 particles=particles(iforce_eval)%list)
1201 natom =
SIZE(particles(iforce_eval)%list%els)
1207 DO iparticle = 1, natom
1208 jparticle = map_index(iparticle)
1209 particles(iforce_eval)%list%els(iparticle)%r = particles_mix%els(jparticle)%r
1214 calc_force=calculate_forces, &
1215 skip_external_control=.true.)
1218 IF (force_env%sub_force_env(iforce_eval)%force_env%para_env%is_source())
THEN
1219 CALL force_env_get(force_env%sub_force_env(iforce_eval)%force_env, &
1220 potential_energy=energy)
1222 virial=loc_virial, results=loc_results)
1223 energies(iforce_eval) = energy
1224 glob_natoms(iforce_eval) = natom
1225 virials(iforce_eval)%virial = loc_virial
1229 IF (
ASSOCIATED(map_index))
THEN
1230 DEALLOCATE (map_index)
1235 CALL mixed_cdft_energy_forces(force_env, calculate_forces, particles, energies, &
1236 glob_natoms, virials, results)
1239 CALL force_env%para_env%sync()
1241 CALL mixed_cdft_post_energy_forces(force_env)
1243 CALL force_env%para_env%sum(energies)
1244 CALL force_env%para_env%sum(glob_natoms)
1246 DO iforce_eval = 1, nforce_eval
1247 ALLOCATE (global_forces(iforce_eval)%forces(3, glob_natoms(iforce_eval)))
1248 global_forces(iforce_eval)%forces = 0.0_dp
1249 IF (
ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env))
THEN
1250 IF (force_env%sub_force_env(iforce_eval)%force_env%para_env%is_source())
THEN
1252 DO iparticle = 1, glob_natoms(iforce_eval)
1253 global_forces(iforce_eval)%forces(:, iparticle) = &
1254 particles(iforce_eval)%list%els(iparticle)%f
1258 CALL force_env%para_env%sum(global_forces(iforce_eval)%forces)
1260 CALL force_env%para_env%sum(virials(iforce_eval)%virial%pv_total)
1261 CALL force_env%para_env%sum(virials(iforce_eval)%virial%pv_kinetic)
1262 CALL force_env%para_env%sum(virials(iforce_eval)%virial%pv_virial)
1263 CALL force_env%para_env%sum(virials(iforce_eval)%virial%pv_xc)
1264 CALL force_env%para_env%sum(virials(iforce_eval)%virial%pv_fock_4c)
1265 CALL force_env%para_env%sum(virials(iforce_eval)%virial%pv_constraint)
1268 IF (
ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env))
THEN
1269 IF (force_env%sub_force_env(iforce_eval)%force_env%para_env%is_source()) &
1270 source = force_env%para_env%mepos
1272 CALL force_env%para_env%sum(source)
1276 force_env%mixed_env%energies = energies
1279 mixed_energy=mixed_energy)
1283 DO iparticle = 1,
SIZE(particles_mix%els)
1284 particles_mix%els(iparticle)%f(:) = 0.0_dp
1288 SELECT CASE (mixing_type)
1291 cpassert(nforce_eval == 2)
1293 mixed_energy%pot = lambda*energies(1) + (1.0_dp - lambda)*energies(2)
1295 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1296 lambda, 1, nforce_eval, map_index, mapping_section, .true.)
1297 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1298 (1.0_dp - lambda), 2, nforce_eval, map_index, mapping_section, .false.)
1301 cpassert(nforce_eval == 2)
1302 IF (energies(1) < energies(2))
THEN
1303 mixed_energy%pot = energies(1)
1304 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1305 1.0_dp, 1, nforce_eval, map_index, mapping_section, .true.)
1307 mixed_energy%pot = energies(2)
1308 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1309 1.0_dp, 2, nforce_eval, map_index, mapping_section, .true.)
1313 cpassert(nforce_eval == 2)
1315 r_val=coupling_parameter)
1316 sd = sqrt((energies(1) - energies(2))**2 + 4.0_dp*coupling_parameter**2)
1317 der_1 = (1.0_dp - (1.0_dp/(2.0_dp*sd))*2.0_dp*(energies(1) - energies(2)))/2.0_dp
1318 der_2 = (1.0_dp + (1.0_dp/(2.0_dp*sd))*2.0_dp*(energies(1) - energies(2)))/2.0_dp
1319 mixed_energy%pot = (energies(1) + energies(2) - sd)/2.0_dp
1321 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1322 der_1, 1, nforce_eval, map_index, mapping_section, .true.)
1323 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1324 der_2, 2, nforce_eval, map_index, mapping_section, .false.)
1327 cpassert(nforce_eval == 2)
1329 r_val=restraint_target)
1331 r_val=restraint_strength)
1332 mixed_energy%pot = energies(1) + restraint_strength*(energies(1) - energies(2) - restraint_target)**2
1333 der_2 = -2.0_dp*restraint_strength*(energies(1) - energies(2) - restraint_target)
1334 der_1 = 1.0_dp - der_2
1336 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1337 der_1, 1, nforce_eval, map_index, mapping_section, .true.)
1338 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1339 der_2, 2, nforce_eval, map_index, mapping_section, .false.)
1343 CALL get_generic_info(gen_section,
"MIXING_FUNCTION", coupling_function, force_env%mixed_env%par, &
1344 force_env%mixed_env%val, energies)
1346 CALL parsef(1, trim(coupling_function), force_env%mixed_env%par)
1348 mixed_energy%pot =
evalf(1, force_env%mixed_env%val)
1352 DO iforce_eval = 1, nforce_eval
1355 dedf =
evalfd(1, iforce_eval, force_env%mixed_env%val, dx, err)
1356 IF (abs(err) > lerr)
THEN
1357 WRITE (this_error,
"(A,G12.6,A)")
"(", err,
")"
1358 WRITE (def_error,
"(A,G12.6,A)")
"(", lerr,
")"
1361 CALL cp_warn(__location__, &
1362 'ASSERTION (cond) failed at line '//
cp_to_string(__line__)// &
1363 ' Error '//trim(this_error)//
' in computing numerical derivatives larger then'// &
1364 trim(def_error)//
' .')
1367 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1368 dedf, iforce_eval, nforce_eval, map_index, mapping_section, .false.)
1369 force_env%mixed_env%val(iforce_eval) = energies(iforce_eval)
1372 force_env%mixed_env%dx = dx
1373 force_env%mixed_env%lerr = lerr
1374 force_env%mixed_env%coupling_function = trim(coupling_function)
1381 IF (
SIZE(itmplist) /= 2) &
1382 CALL cp_abort(__location__, &
1383 "Keyword FORCE_STATES takes exactly two input values.")
1384 IF (any(itmplist < 0)) &
1385 cpabort(
"Invalid force_eval index.")
1387 IF (istate(1) > nforce_eval .OR. istate(2) > nforce_eval) &
1388 cpabort(
"Invalid force_eval index.")
1389 mixed_energy%pot = lambda*energies(istate(1)) + (1.0_dp - lambda)*energies(istate(2))
1391 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1392 lambda, istate(1), nforce_eval, map_index, mapping_section, .true.)
1393 CALL mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, &
1394 (1.0_dp - lambda), istate(2), nforce_eval, map_index, mapping_section, .false.)
1399 DO iforce_eval = 1, nforce_eval
1400 DEALLOCATE (global_forces(iforce_eval)%forces)
1401 IF (
ASSOCIATED(virials(iforce_eval)%virial))
DEALLOCATE (virials(iforce_eval)%virial)
1404 DEALLOCATE (global_forces)
1405 DEALLOCATE (subsystems)
1406 DEALLOCATE (particles)
1407 DEALLOCATE (energies)
1408 DEALLOCATE (glob_natoms)
1409 DEALLOCATE (virials)
1410 DEALLOCATE (results)
1413 extension=
".data", middle_name=
"MIXED_DIPOLE", log_filename=.false.)
1414 IF (unit_nr > 0)
THEN
1415 description =
'[DIPOLE]'
1416 dip_exists =
test_for_result(results=results_mix, description=description)
1417 IF (dip_exists)
THEN
1418 CALL get_results(results=results_mix, description=description, values=dip_mix)
1419 WRITE (unit_nr,
'(/,1X,A,T48,3F21.16)')
"MIXED ENV| DIPOLE ( A.U.)|", dip_mix
1420 WRITE (unit_nr,
'( 1X,A,T48,3F21.16)')
"MIXED ENV| DIPOLE (Debye)|", dip_mix*
debye
1422 WRITE (unit_nr, *)
"NO FORCE_EVAL section calculated the dipole"
1426 END SUBROUTINE mixed_energy_forces
1441 SUBROUTINE mixed_cdft_energy_forces(force_env, calculate_forces, particles, energies, &
1442 glob_natoms, virials, results)
1444 LOGICAL,
INTENT(IN) :: calculate_forces
1446 REAL(kind=
dp),
DIMENSION(:),
POINTER :: energies
1447 INTEGER,
DIMENSION(:),
POINTER :: glob_natoms
1451 INTEGER :: iforce_eval, iparticle, jparticle, &
1452 my_group, natom, nforce_eval
1453 INTEGER,
DIMENSION(:),
POINTER :: map_index
1454 REAL(kind=
dp) :: energy
1462 mixed_section, root_section
1463 TYPE(
virial_type),
POINTER :: loc_virial, virial_mix
1466 cpassert(
ASSOCIATED(force_env))
1469 subsys=subsys_mix, &
1470 force_env_section=force_env_section, &
1471 root_section=root_section, &
1474 particles=particles_mix, &
1475 virial=virial_mix, &
1476 results=results_mix)
1478 nforce_eval =
SIZE(force_env%sub_force_env)
1481 ALLOCATE (subsystems(nforce_eval))
1482 DO iforce_eval = 1, nforce_eval
1483 NULLIFY (subsystems(iforce_eval)%subsys, particles(iforce_eval)%list)
1484 NULLIFY (results(iforce_eval)%results, virials(iforce_eval)%virial)
1485 ALLOCATE (virials(iforce_eval)%virial)
1487 IF (.NOT.
ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env)) cycle
1489 CALL force_env_get(force_env=force_env%sub_force_env(iforce_eval)%force_env, &
1490 subsys=subsystems(iforce_eval)%subsys)
1493 CALL cp_subsys_set(subsystems(iforce_eval)%subsys, cell=cell_mix)
1497 particles=particles(iforce_eval)%list)
1500 natom =
SIZE(particles(iforce_eval)%list%els)
1502 IF (
ASSOCIATED(map_index)) &
1503 DEALLOCATE (map_index)
1508 DO iparticle = 1, natom
1509 jparticle = map_index(iparticle)
1510 particles(iforce_eval)%list%els(iparticle)%r = particles_mix%els(jparticle)%r
1513 IF (force_env%mixed_env%do_mixed_qmmm_cdft) &
1520 DO iforce_eval = 1, nforce_eval
1521 IF (.NOT.
ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env)) cycle
1523 IF (force_env%mixed_env%cdft_control%run_type ==
mixed_cdft_serial .AND. iforce_eval >= 2)
THEN
1524 my_logger => force_env%mixed_env%cdft_control%sub_logger(iforce_eval - 1)%p
1526 my_group = force_env%mixed_env%group_distribution(force_env%para_env%mepos)
1527 my_logger => force_env%mixed_env%sub_logger(my_group + 1)%p
1536 calc_force=calculate_forces, &
1537 skip_external_control=.true.)
1539 IF (force_env%sub_force_env(iforce_eval)%force_env%para_env%is_source())
THEN
1540 CALL force_env_get(force_env%sub_force_env(iforce_eval)%force_env, &
1541 potential_energy=energy)
1543 virial=loc_virial, results=loc_results)
1544 energies(iforce_eval) = energy
1545 glob_natoms(iforce_eval) = natom
1546 virials(iforce_eval)%virial = loc_virial
1550 IF (
ASSOCIATED(map_index))
THEN
1551 DEALLOCATE (map_index)
1555 DEALLOCATE (subsystems)
1557 END SUBROUTINE mixed_cdft_energy_forces
1567 SUBROUTINE mixed_cdft_post_energy_forces(force_env)
1570 INTEGER :: iforce_eval, nforce_eval, nvar
1574 cpassert(
ASSOCIATED(force_env))
1575 NULLIFY (qs_env, dft_control)
1576 IF (force_env%mixed_env%do_mixed_cdft)
THEN
1577 nforce_eval =
SIZE(force_env%sub_force_env)
1578 nvar = force_env%mixed_env%cdft_control%nconstraint
1580 IF (.NOT.
ASSOCIATED(force_env%mixed_env%strength)) &
1581 ALLOCATE (force_env%mixed_env%strength(nforce_eval, nvar))
1582 force_env%mixed_env%strength = 0.0_dp
1583 DO iforce_eval = 1, nforce_eval
1584 IF (.NOT.
ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env)) cycle
1585 IF (force_env%mixed_env%do_mixed_qmmm_cdft)
THEN
1586 qs_env => force_env%sub_force_env(iforce_eval)%force_env%qmmm_env%qs_env
1588 CALL force_env_get(force_env%sub_force_env(iforce_eval)%force_env, qs_env=qs_env)
1590 CALL get_qs_env(qs_env, dft_control=dft_control)
1591 IF (force_env%sub_force_env(iforce_eval)%force_env%para_env%is_source()) &
1592 force_env%mixed_env%strength(iforce_eval, :) = dft_control%qs_control%cdft_control%strength(:)
1594 CALL force_env%para_env%sum(force_env%mixed_env%strength)
1596 IF (force_env%mixed_env%do_mixed_et)
THEN
1597 IF (
modulo(force_env%mixed_env%cdft_control%sim_step, force_env%mixed_env%et_freq) == 0) &
1602 END SUBROUTINE mixed_cdft_post_energy_forces
1609 SUBROUTINE embed_energy(force_env)
1613 INTEGER :: iforce_eval, iparticle, jparticle, &
1614 my_group, natom, nforce_eval
1615 INTEGER,
DIMENSION(:),
POINTER :: glob_natoms, map_index
1616 LOGICAL :: converged_embed
1617 REAL(kind=
dp) :: energy
1618 REAL(kind=
dp),
DIMENSION(:),
POINTER :: energies
1632 mapping_section, root_section
1635 cpassert(
ASSOCIATED(force_env))
1638 subsys=subsys_embed, &
1639 force_env_section=force_env_section, &
1640 root_section=root_section, &
1643 particles=particles_embed, &
1644 results=results_embed)
1645 NULLIFY (map_index, glob_natoms)
1647 nforce_eval =
SIZE(force_env%sub_force_env)
1651 ALLOCATE (subsystems(nforce_eval))
1652 ALLOCATE (particles(nforce_eval))
1654 ALLOCATE (energies(nforce_eval))
1655 ALLOCATE (glob_natoms(nforce_eval))
1656 ALLOCATE (results(nforce_eval))
1660 DO iforce_eval = 1, nforce_eval
1661 NULLIFY (subsystems(iforce_eval)%subsys, particles(iforce_eval)%list)
1662 NULLIFY (results(iforce_eval)%results)
1664 IF (.NOT.
ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env)) cycle
1666 my_group = force_env%embed_env%group_distribution(force_env%para_env%mepos)
1667 my_logger => force_env%embed_env%sub_logger(my_group + 1)%p
1673 CALL force_env_get(force_env=force_env%sub_force_env(iforce_eval)%force_env, &
1674 subsys=subsystems(iforce_eval)%subsys)
1678 IF (
ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env%qs_env))
THEN
1679 NULLIFY (dft_control)
1680 CALL get_qs_env(force_env%sub_force_env(iforce_eval)%force_env%qs_env, dft_control=dft_control)
1681 IF (dft_control%qs_control%ref_embed_subsys)
THEN
1682 IF (iforce_eval == 2) cpabort(
"Density importing force_eval can't be the first.")
1687 CALL cp_subsys_set(subsystems(iforce_eval)%subsys, cell=cell_embed)
1691 particles=particles(iforce_eval)%list)
1694 natom =
SIZE(particles(iforce_eval)%list%els)
1700 DO iparticle = 1, natom
1701 jparticle = map_index(iparticle)
1702 particles(iforce_eval)%list%els(iparticle)%r = particles_embed%els(jparticle)%r
1707 calc_force=.false., &
1708 skip_external_control=.true.)
1711 IF (
ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env%qs_env))
THEN
1712 NULLIFY (dft_control)
1713 CALL get_qs_env(force_env%sub_force_env(iforce_eval)%force_env%qs_env, dft_control=dft_control)
1714 IF (dft_control%qs_control%ref_embed_subsys)
THEN
1716 CALL dft_embedding(force_env, iforce_eval, energies, converged_embed)
1717 IF (.NOT. converged_embed) cpabort(
"Embedding potential optimization not converged.")
1720 IF (dft_control%qs_control%high_level_embed_subsys)
THEN
1721 CALL get_qs_env(qs_env=force_env%sub_force_env(iforce_eval)%force_env%qs_env, &
1722 embed_pot=embed_pot, spin_embed_pot=spin_embed_pot, pw_env=pw_env)
1723 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1724 CALL auxbas_pw_pool%give_back_pw(embed_pot)
1725 IF (
ASSOCIATED(embed_pot))
THEN
1726 CALL embed_pot%release()
1727 DEALLOCATE (embed_pot)
1729 IF (
ASSOCIATED(spin_embed_pot))
THEN
1730 CALL auxbas_pw_pool%give_back_pw(spin_embed_pot)
1731 CALL spin_embed_pot%release()
1732 DEALLOCATE (spin_embed_pot)
1738 IF (force_env%sub_force_env(iforce_eval)%force_env%para_env%is_source())
THEN
1739 CALL force_env_get(force_env%sub_force_env(iforce_eval)%force_env, &
1740 potential_energy=energy)
1742 results=loc_results)
1743 energies(iforce_eval) = energy
1744 glob_natoms(iforce_eval) = natom
1748 IF (
ASSOCIATED(map_index))
THEN
1749 DEALLOCATE (map_index)
1755 CALL force_env%para_env%sync()
1757 CALL force_env%para_env%sum(energies)
1758 CALL force_env%para_env%sum(glob_natoms)
1760 force_env%embed_env%energies = energies
1763 DO iparticle = 1,
SIZE(particles_embed%els)
1764 particles_embed%els(iparticle)%f(:) = 0.0_dp
1768 force_env%embed_env%pot_energy = energies(3) + energies(4) - energies(2)
1771 DO iforce_eval = 1, nforce_eval
1774 DEALLOCATE (subsystems)
1775 DEALLOCATE (particles)
1776 DEALLOCATE (energies)
1777 DEALLOCATE (glob_natoms)
1778 DEALLOCATE (results)
1780 END SUBROUTINE embed_energy
1789 SUBROUTINE dft_embedding(force_env, ref_subsys_number, energies, converged_embed)
1791 INTEGER :: ref_subsys_number
1792 REAL(kind=
dp),
DIMENSION(:),
POINTER :: energies
1793 LOGICAL :: converged_embed
1795 INTEGER :: embed_method
1800 force_env_section=force_env_section)
1804 SELECT CASE (embed_method)
1807 CALL dfet_embedding(force_env, ref_subsys_number, energies, converged_embed)
1810 CALL dmfet_embedding(force_env, ref_subsys_number, energies, converged_embed)
1813 END SUBROUTINE dft_embedding
1822 SUBROUTINE dfet_embedding(force_env, ref_subsys_number, energies, converged_embed)
1824 INTEGER :: ref_subsys_number
1825 REAL(kind=
dp),
DIMENSION(:),
POINTER :: energies
1826 LOGICAL :: converged_embed
1828 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dfet_embedding'
1830 INTEGER :: cluster_subsys_num, handle, &
1831 i_force_eval, i_iter, i_spin, &
1832 nforce_eval, nspins, nspins_subsys, &
1834 REAL(kind=
dp) :: cluster_energy
1835 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rhs
1842 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r_ref, rho_r_subsys
1844 spin_embed_pot, spin_embed_pot_subsys
1848 force_env_section, input, &
1849 mapping_section, opt_embed_section
1851 CALL timeset(routinen, handle)
1856 CALL get_qs_env(qs_env=force_env%sub_force_env(ref_subsys_number)%force_env%qs_env)
1861 output_unit =
cp_print_key_unit_nr(logger, force_env%force_env_section,
"PRINT%PROGRAM_RUN_INFO", &
1864 NULLIFY (dft_section, input, opt_embed_section)
1865 NULLIFY (energy, dft_control)
1867 CALL get_qs_env(qs_env=force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, &
1868 pw_env=pw_env, dft_control=dft_control, rho=rho, energy=energy, &
1870 nspins = dft_control%nspins
1876 CALL qs_rho_get(rho_struct=rho, rho_r=rho_r_ref)
1879 CALL understand_spin_states(force_env, ref_subsys_number, opt_embed%change_spin, opt_embed%open_shell_embed, &
1880 opt_embed%all_nspins)
1883 CALL prepare_embed_opt(force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, opt_embed, &
1887 CALL init_embed_pot(force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, embed_pot, &
1888 opt_embed%add_const_pot, opt_embed%Fermi_Amaldi, opt_embed%const_pot, &
1889 opt_embed%open_shell_embed, spin_embed_pot, &
1890 opt_embed%pot_diff, opt_embed%Coulomb_guess, opt_embed%grid_opt)
1893 IF (opt_embed%read_embed_pot .OR. opt_embed%read_embed_pot_cube)
CALL read_embed_pot( &
1894 force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, embed_pot, spin_embed_pot, &
1895 opt_embed_section, opt_embed)
1898 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1899 CALL auxbas_pw_pool%create_pw(diff_rho_r)
1901 IF (opt_embed%open_shell_embed)
THEN
1902 CALL auxbas_pw_pool%create_pw(diff_rho_spin)
1907 DO i_spin = 1, nspins
1908 CALL pw_axpy(rho_r_ref(i_spin), diff_rho_r, -1.0_dp)
1910 IF (opt_embed%open_shell_embed)
THEN
1911 IF (nspins == 2)
THEN
1912 CALL pw_axpy(rho_r_ref(1), diff_rho_spin, -1.0_dp)
1913 CALL pw_axpy(rho_r_ref(2), diff_rho_spin, 1.0_dp)
1917 DO i_force_eval = 1, ref_subsys_number - 1
1918 NULLIFY (subsys_rho, rho_r_subsys, dft_control)
1919 CALL get_qs_env(force_env%sub_force_env(i_force_eval)%force_env%qs_env, rho=subsys_rho, energy=energy, &
1920 dft_control=dft_control)
1921 nspins_subsys = dft_control%nspins
1923 CALL qs_rho_get(rho_struct=subsys_rho, rho_r=rho_r_subsys)
1924 DO i_spin = 1, nspins_subsys
1925 CALL pw_axpy(rho_r_subsys(i_spin), diff_rho_r, allow_noncompatible_grids=.true.)
1927 IF (opt_embed%open_shell_embed)
THEN
1928 IF (nspins_subsys == 2)
THEN
1930 IF ((i_force_eval == 2) .AND. (opt_embed%change_spin))
THEN
1931 CALL pw_axpy(rho_r_subsys(1), diff_rho_spin, -1.0_dp, allow_noncompatible_grids=.true.)
1932 CALL pw_axpy(rho_r_subsys(2), diff_rho_spin, 1.0_dp, allow_noncompatible_grids=.true.)
1935 CALL pw_axpy(rho_r_subsys(1), diff_rho_spin, 1.0_dp, allow_noncompatible_grids=.true.)
1936 CALL pw_axpy(rho_r_subsys(2), diff_rho_spin, -1.0_dp, allow_noncompatible_grids=.true.)
1943 CALL print_rho_diff(diff_rho_r, 0, force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, .false.)
1944 IF (opt_embed%open_shell_embed)
THEN
1945 CALL print_rho_spin_diff(diff_rho_spin, 0, force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, .false.)
1949 IF (opt_embed%Coulomb_guess)
THEN
1951 nforce_eval =
SIZE(force_env%sub_force_env)
1953 CALL get_qs_env(force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, rhs=rhs)
1956 force_env_section=force_env_section)
1960 DO i_force_eval = 1, ref_subsys_number - 1
1961 IF (i_force_eval == 1)
THEN
1963 force_env%sub_force_env(i_force_eval)%force_env%qs_env, nforce_eval, i_force_eval, opt_embed%eta)
1965 CALL coulomb_guess(opt_embed%pot_diff, rhs, mapping_section, &
1966 force_env%sub_force_env(i_force_eval)%force_env%qs_env, nforce_eval, i_force_eval, opt_embed%eta)
1969 CALL pw_axpy(opt_embed%pot_diff, embed_pot)
1970 IF (.NOT. opt_embed%grid_opt)
CALL pw_copy(embed_pot, opt_embed%const_pot)
1975 IF (opt_embed%diff_guess)
THEN
1976 CALL pw_copy(diff_rho_r, embed_pot)
1977 IF (.NOT. opt_embed%grid_opt)
CALL pw_copy(embed_pot, opt_embed%const_pot)
1979 IF (opt_embed%open_shell_embed)
CALL pw_copy(diff_rho_spin, spin_embed_pot)
1983 DO i_iter = 1, opt_embed%n_iter
1984 opt_embed%i_iter = i_iter
1988 CALL get_qs_env(force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, dft_control=dft_control)
1989 nspins = dft_control%nspins
1990 DO i_spin = 1, nspins
1991 CALL pw_axpy(rho_r_ref(i_spin), diff_rho_r, -1.0_dp)
1993 IF (opt_embed%open_shell_embed)
THEN
1995 IF (nspins == 2)
THEN
1996 CALL pw_axpy(rho_r_ref(1), diff_rho_spin, -1.0_dp)
1997 CALL pw_axpy(rho_r_ref(2), diff_rho_spin, 1.0_dp)
2001 DO i_force_eval = 1, ref_subsys_number - 1
2002 NULLIFY (dft_control)
2003 CALL get_qs_env(force_env%sub_force_env(i_force_eval)%force_env%qs_env, dft_control=dft_control)
2004 nspins_subsys = dft_control%nspins
2006 IF ((i_force_eval == 2) .AND. (opt_embed%change_spin))
THEN
2010 embed_pot, embed_pot_subsys, spin_embed_pot, spin_embed_pot_subsys, &
2011 opt_embed%open_shell_embed, .true.)
2014 embed_pot, embed_pot_subsys, spin_embed_pot, spin_embed_pot_subsys, &
2015 opt_embed%open_shell_embed, .false.)
2019 dft_control%apply_embed_pot = .true.
2022 CALL set_qs_env(force_env%sub_force_env(i_force_eval)%force_env%qs_env, embed_pot=embed_pot_subsys)
2023 IF ((opt_embed%open_shell_embed) .AND. (nspins_subsys == 2))
THEN
2024 CALL set_qs_env(force_env%sub_force_env(i_force_eval)%force_env%qs_env, &
2025 spin_embed_pot=spin_embed_pot_subsys)
2029 CALL get_prev_density(opt_embed, force_env%sub_force_env(i_force_eval)%force_env, i_force_eval)
2033 calc_force=.false., &
2034 skip_external_control=.true.)
2036 CALL get_max_subsys_diff(opt_embed, force_env%sub_force_env(i_force_eval)%force_env, i_force_eval)
2039 NULLIFY (rho_r_subsys, energy)
2041 CALL get_qs_env(force_env%sub_force_env(i_force_eval)%force_env%qs_env, rho=subsys_rho, &
2043 opt_embed%w_func(i_iter) = opt_embed%w_func(i_iter) + energy%total
2046 IF (dft_control%qs_control%cluster_embed_subsys)
THEN
2047 cluster_subsys_num = i_force_eval
2048 cluster_energy = energy%total
2052 CALL qs_rho_get(rho_struct=subsys_rho, rho_r=rho_r_subsys)
2053 DO i_spin = 1, nspins_subsys
2054 CALL pw_axpy(rho_r_subsys(i_spin), diff_rho_r, allow_noncompatible_grids=.true.)
2056 IF (opt_embed%open_shell_embed)
THEN
2057 IF (nspins_subsys == 2)
THEN
2059 IF ((i_force_eval == 2) .AND. (opt_embed%change_spin))
THEN
2060 CALL pw_axpy(rho_r_subsys(1), diff_rho_spin, -1.0_dp, allow_noncompatible_grids=.true.)
2061 CALL pw_axpy(rho_r_subsys(2), diff_rho_spin, 1.0_dp, allow_noncompatible_grids=.true.)
2064 CALL pw_axpy(rho_r_subsys(1), diff_rho_spin, 1.0_dp, allow_noncompatible_grids=.true.)
2065 CALL pw_axpy(rho_r_subsys(2), diff_rho_spin, -1.0_dp, allow_noncompatible_grids=.true.)
2071 CALL embed_pot_subsys%release()
2072 DEALLOCATE (embed_pot_subsys)
2073 IF (opt_embed%open_shell_embed)
THEN
2074 CALL spin_embed_pot_subsys%release()
2075 DEALLOCATE (spin_embed_pot_subsys)
2082 opt_embed%dimen_aux, opt_embed%embed_pot_coef, embed_pot, i_iter, &
2083 spin_embed_pot, opt_embed%open_shell_embed, opt_embed%grid_opt, .false.)
2085 embed_pot, spin_embed_pot, i_iter, opt_embed%open_shell_embed, .false., &
2086 force_env%sub_force_env(cluster_subsys_num)%force_env%qs_env)
2089 DO i_spin = 1, nspins
2090 opt_embed%w_func(i_iter) = opt_embed%w_func(i_iter) -
pw_integral_ab(embed_pot, rho_r_ref(i_spin))
2093 IF (opt_embed%open_shell_embed)
THEN
2095 IF (nspins == 2)
THEN
2096 opt_embed%w_func(i_iter) = opt_embed%w_func(i_iter) &
2102 opt_embed%w_func(i_iter) = opt_embed%w_func(i_iter) + opt_embed%reg_term
2107 IF (opt_embed%converged)
EXIT
2110 IF ((i_iter > 1) .AND. (.NOT. opt_embed%steep_desc))
CALL step_control(opt_embed)
2113 CALL print_rho_diff(diff_rho_r, i_iter, force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, .false.)
2114 IF (opt_embed%open_shell_embed)
THEN
2115 CALL print_rho_spin_diff(diff_rho_spin, i_iter, force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, .false.)
2120 IF (opt_embed%accept_step .AND. (.NOT. opt_embed%grid_opt)) &
2122 diff_rho_r, diff_rho_spin, opt_embed)
2124 CALL opt_embed_step(diff_rho_r, diff_rho_spin, opt_embed, embed_pot, spin_embed_pot, rho_r_ref, &
2125 force_env%sub_force_env(ref_subsys_number)%force_env%qs_env)
2131 opt_embed%dimen_aux, opt_embed%embed_pot_coef, embed_pot, i_iter, &
2132 spin_embed_pot, opt_embed%open_shell_embed, opt_embed%grid_opt, .true.)
2134 embed_pot, spin_embed_pot, i_iter, opt_embed%open_shell_embed, .true., &
2135 force_env%sub_force_env(cluster_subsys_num)%force_env%qs_env)
2139 IF (opt_embed%open_shell_embed)
THEN
2140 CALL print_rho_spin_diff(diff_rho_spin, i_iter, force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, .true.)
2144 CALL diff_rho_r%release()
2145 IF (opt_embed%open_shell_embed)
THEN
2146 CALL diff_rho_spin%release()
2150 "PRINT%PROGRAM_RUN_INFO")
2153 IF (opt_embed%converged)
THEN
2154 CALL get_qs_env(force_env%sub_force_env(ref_subsys_number + 1)%force_env%qs_env, dft_control=dft_control, &
2156 nspins_subsys = dft_control%nspins
2157 dft_control%apply_embed_pot = .true.
2160 embed_pot, embed_pot_subsys, spin_embed_pot, spin_embed_pot_subsys, &
2161 opt_embed%open_shell_embed, opt_embed%change_spin)
2163 IF (opt_embed%Coulomb_guess)
THEN
2164 CALL pw_axpy(opt_embed%pot_diff, embed_pot_subsys, -1.0_dp, allow_noncompatible_grids=.true.)
2167 CALL set_qs_env(force_env%sub_force_env(ref_subsys_number + 1)%force_env%qs_env, embed_pot=embed_pot_subsys)
2169 IF ((opt_embed%open_shell_embed) .AND. (nspins_subsys == 2))
THEN
2170 CALL set_qs_env(force_env%sub_force_env(ref_subsys_number + 1)%force_env%qs_env, &
2171 spin_embed_pot=spin_embed_pot_subsys)
2175 IF (force_env%sub_force_env(cluster_subsys_num)%force_env%para_env%is_source())
THEN
2176 energies(cluster_subsys_num) = cluster_energy
2184 CALL embed_pot%release()
2185 DEALLOCATE (embed_pot)
2186 IF (opt_embed%open_shell_embed)
THEN
2187 CALL spin_embed_pot%release()
2188 DEALLOCATE (spin_embed_pot)
2191 converged_embed = opt_embed%converged
2193 CALL timestop(handle)
2195 END SUBROUTINE dfet_embedding
2205 SUBROUTINE dmfet_embedding(force_env, ref_subsys_number, energies, converged_embed)
2207 INTEGER :: ref_subsys_number
2208 REAL(kind=
dp),
DIMENSION(:),
POINTER :: energies
2209 LOGICAL :: converged_embed
2211 CHARACTER(LEN=*),
PARAMETER :: routinen =
'dmfet_embedding'
2213 INTEGER :: cluster_subsys_num, handle, &
2214 i_force_eval, i_iter, output_unit
2215 LOGICAL :: subsys_open_shell
2216 REAL(kind=
dp) :: cluster_energy
2224 CALL timeset(routinen, handle)
2226 CALL get_qs_env(qs_env=force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, &
2232 output_unit =
cp_print_key_unit_nr(logger, force_env%force_env_section,
"PRINT%PROGRAM_RUN_INFO", &
2235 NULLIFY (dft_section, input, opt_dmfet_section)
2238 CALL get_qs_env(qs_env=force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, &
2239 energy=energy, input=input)
2246 CALL understand_spin_states(force_env, ref_subsys_number, opt_dmfet%change_spin, opt_dmfet%open_shell_embed, &
2247 opt_dmfet%all_nspins)
2250 CALL prepare_dmfet_opt(force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, &
2251 opt_dmfet, opt_dmfet_section)
2254 subsys_open_shell =
subsys_spin(force_env%sub_force_env(ref_subsys_number)%force_env%qs_env)
2255 CALL build_full_dm(force_env%sub_force_env(ref_subsys_number)%force_env%qs_env, &
2256 opt_dmfet%dm_total, subsys_open_shell, opt_dmfet%open_shell_embed, opt_dmfet%dm_total_beta)
2261 opt_dmfet%dm_diff_beta, para_env)
2263 DO i_force_eval = 1, ref_subsys_number - 1
2266 subsys_open_shell =
subsys_spin(force_env%sub_force_env(i_force_eval)%force_env%qs_env)
2268 CALL build_full_dm(force_env%sub_force_env(i_force_eval)%force_env%qs_env, &
2269 opt_dmfet%dm_subsys, subsys_open_shell, opt_dmfet%open_shell_embed, &
2270 opt_dmfet%dm_subsys_beta)
2274 IF (opt_dmfet%open_shell_embed)
CALL cp_fm_scale_and_add(-1.0_dp, opt_dmfet%dm_diff_beta, &
2275 1.0_dp, opt_dmfet%dm_subsys_beta)
2280 DO i_iter = 1, opt_dmfet%n_iter
2282 opt_dmfet%i_iter = i_iter
2288 opt_dmfet%dm_diff_beta, para_env)
2291 DO i_force_eval = 1, ref_subsys_number - 1
2294 NULLIFY (dft_control)
2295 CALL get_qs_env(force_env%sub_force_env(i_force_eval)%force_env%qs_env, dft_control=dft_control)
2296 dft_control%apply_dmfet_pot = .true.
2300 calc_force=.false., &
2301 skip_external_control=.true.)
2306 CALL get_qs_env(force_env%sub_force_env(i_force_eval)%force_env%qs_env, energy=energy)
2307 opt_dmfet%w_func(i_iter) = opt_dmfet%w_func(i_iter) + energy%total
2310 IF (dft_control%qs_control%cluster_embed_subsys)
THEN
2311 cluster_subsys_num = i_force_eval
2312 cluster_energy = energy%total
2316 subsys_open_shell =
subsys_spin(force_env%sub_force_env(i_force_eval)%force_env%qs_env)
2318 CALL build_full_dm(force_env%sub_force_env(i_force_eval)%force_env%qs_env, &
2319 opt_dmfet%dm_subsys, subsys_open_shell, opt_dmfet%open_shell_embed, &
2320 opt_dmfet%dm_subsys_beta)
2322 IF (opt_dmfet%open_shell_embed)
THEN
2324 IF ((i_force_eval == 2) .AND. (opt_dmfet%change_spin))
THEN
2329 CALL cp_fm_scale_and_add(-1.0_dp, opt_dmfet%dm_diff_beta, 1.0_dp, opt_dmfet%dm_subsys_beta)
2337 CALL check_dmfet(opt_dmfet, force_env%sub_force_env(ref_subsys_number)%force_env%qs_env)
2342 IF (force_env%sub_force_env(cluster_subsys_num)%force_env%para_env%is_source())
THEN
2343 energies(cluster_subsys_num) = cluster_energy
2348 converged_embed = .false.
2350 END SUBROUTINE dmfet_embedding
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Holds information on atomic properties.
subroutine, public atprop_init(atprop_env, natom)
...
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public huang2011
integer, save, public heaton_burgess2007
Handles all functions related to the CELL.
subroutine, public init_cell(cell, hmat, periodic)
Initialise/readjust a simulation cell after hmat has been changed.
subroutine, public cell_create(cell, hmat, periodic, tag)
allocates and initializes a cell
Handles all functions related to the CELL.
subroutine, public scaled_to_real(r, s, cell)
Transform scaled cell coordinates real coordinates. r=h*s.
integer, parameter, public cell_sym_triclinic
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
subroutine, public cell_release(cell)
releases the given cell (see doc/ReferenceCounting.html)
subroutine, public cell_clone(cell_in, cell_out, tag)
Clone cell variable.
subroutine, public fix_atom_control(force_env, w)
allows for fix atom constraints
Routines to handle the virtual site constraint/restraint.
subroutine, public vsite_force_control(force_env)
control force distribution for virtual sites
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
represent a full matrix distributed on many processors
subroutine, public cp_fm_copy_general(source, destination, para_env)
General copy of a fm matrix to another fm matrix. Uses non-blocking MPI rather than ScaLAPACK.
Collection of routines to handle the iteration info.
subroutine, public cp_iteration_info_copy_iter(iteration_info_in, iteration_info_out)
Copies iterations info of an iteration info into another iteration info.
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
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)
...
integer, parameter, public low_print_level
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,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
set of type/routines to handle the storage of results in force_envs
subroutine, public cp_results_mp_bcast(results, source, para_env)
broadcast results type
subroutine, public cp_results_erase(results, description, nval)
erase a part of result_list
logical function, public test_for_result(results, description)
test for a certain result in the result_list
set of type/routines to handle the storage of results in force_envs
subroutine, public cp_result_copy(results_in, results_out)
Copies the cp_result type.
subroutine, public cp_result_release(results)
Releases cp_result type.
subroutine, public cp_result_create(results)
Allocates and intitializes the cp_result.
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_set(subsys, atomic_kinds, particles, local_particles, molecules, molecule_kinds, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, results, cell, cell_ref, use_ref_cell)
sets various propreties of the subsys
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
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
The environment for the empirical interatomic potential methods.
Empirical interatomic potentials for Silicon.
subroutine, public eip_stillinger_weber(eip_env)
Interface routine of the Stillinger-Weber force field to CP2K.
subroutine, public eip_lenosky(eip_env)
Interface routine of Goedecker's Lenosky force field to CP2K.
subroutine, public eip_tersoff(eip_env)
Interface routine of the Tersoff force field to CP2K.
subroutine, public eip_bazant(eip_env)
Interface routine of Goedecker's Bazant EDIP to CP2K.
Methods to include the effect of an external potential during an MD or energy calculation.
subroutine, public add_external_potential(force_env)
...
subroutine, public fist_calc_energy_force(fist_env, debug)
Calculates the total potential energy, total force, and the total pressure tensor from the potentials...
Interface for the force calculations.
recursive subroutine, public force_env_calc_energy_force(force_env, calc_force, consistent_energies, skip_external_control, eval_energy_forces, require_consistent_energy_force, linres, calc_stress_tensor)
Interface routine for force and energy calculations.
subroutine, public force_env_calc_num_pressure(force_env, dx)
Evaluates the stress tensor and pressure numerically.
subroutine, public force_env_create(force_env, root_section, para_env, globenv, fist_env, qs_env, meta_env, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, force_env_section, mixed_env, embed_env, nnp_env, ipi_env)
creates and initializes a force environment
Interface for the force calculations.
integer function, public force_env_get_natom(force_env)
returns the number of atoms
integer, parameter, public use_qmmm
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_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
integer, parameter, public use_pwdft_force
integer, parameter, public use_nnp_force
integer, parameter, public use_ipi
integer, parameter, public use_fist_force
subroutine, public write_forces(particles, iw, label, ndigits, unit_string, total_force, grand_total_force, zero_force_core_shell_atom)
Write forces either to the screen or to a file.
subroutine, public write_atener(iounit, particles, atener, label)
Write the atomic coordinates, types, and energies.
subroutine, public rescale_forces(force_env)
Rescale forces if requested.
subroutine, public get_generic_info(gen_section, func_name, xfunction, parameters, values, var_values, size_variables, i_rep_sec, input_variables)
Reads from the input structure all information for generic functions.
methods used in the flexible partitioning scheme
subroutine, public fp_eval(fp_env, subsys, cell)
Computes the forces and the energy due to the flexible potential & bias, and writes the weights file.
This public domain function parser module is intended for applications where a set of mathematical ex...
subroutine, public parsef(i, funcstr, var)
Parse ith function string FuncStr and compile it into bytecode.
real(rn) function, public evalf(i, val)
...
integer, public evalerrtype
real(kind=rn) function, public evalfd(id_fun, ipar, vals, h, err)
Evaluates derivatives.
subroutine, public finalizef()
...
subroutine, public initf(n)
...
Define type storing the global information of a run. Keep the amount of stored data small....
subroutine, public globenv_retain(globenv)
Retains the global environment globenv.
subroutine, public write_grrm(iounit, force_env, particles, energy, dipole, hessian, dipder, polar, fixed_atoms)
Write GRRM interface file.
The environment for the empirical interatomic potential methods.
i–PI server mode: Communication with i–PI clients
subroutine, public request_forces(ipi_env)
Send atomic positions to a client and retrieve forces.
sums arrays of real/complex numbers with much reduced round-off as compared to a naive implementation...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Routines needed for kpoint calculation.
subroutine, public kpoint_initialize_mos(kpoint, mos, added_mos, for_aux_fit)
Initialize a set of MOs and density matrix for each kpoint (kpoint group)
subroutine, public kpoint_initialize(kpoint, particle_set, cell)
Generate the kpoints and initialize the kpoint environment.
subroutine, public kpoint_env_initialize(kpoint, para_env, blacs_env, with_aux_fit)
Initialize the kpoint environment.
Types and basic routines needed for a kpoint calculation.
subroutine, public set_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered)
Set information in a kpoint environment.
subroutine, public kpoint_reset_initialization(kpoint)
Reset all data derived from a concrete k-point initialization. Input options such as the scheme,...
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered)
Retrieve information from a kpoint environment.
K-points and crystal symmetry routines based on.
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_memory(mem)
Returns the total amount of memory [bytes] in use, if known, zero otherwise.
Collection of simple mathematical functions and subroutines.
logical function, public abnormal_value(a)
determines if a value is not normal (e.g. for Inf and Nan) based on IO to work also under optimizatio...
Interface to the message passing library MPI.
Methods for mixed CDFT calculations.
subroutine, public mixed_cdft_calculate_coupling(force_env)
Driver routine to calculate the electronic coupling(s) between CDFT states.
subroutine, public mixed_cdft_build_weight(force_env, calculate_forces, iforce_eval)
Driver routine to handle the build of CDFT weight/gradient in parallel and serial modes.
subroutine, public mixed_cdft_init(force_env, calculate_forces)
Initialize a mixed CDFT calculation.
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.
subroutine, public get_subsys_map_index(mapping_section, natom, iforce_eval, nforce_eval, map_index, force_eval_embed)
performs mapping of the subsystems of different force_eval
subroutine, public mixed_map_forces(particles_mix, virial_mix, results_mix, global_forces, virials, results, factor, iforce_eval, nforce_eval, map_index, mapping_section, overwrite)
Maps forces between the different force_eval sections/environments.
represent a simple array based list of the given type
Define the molecule kind structure types and the corresponding functionality.
subroutine, public get_molecule_kind(molecule_kind, atom_list, bond_list, bend_list, ub_list, impr_list, opbend_list, colv_list, fixd_list, g3x3_list, g4x6_list, vsite_list, torsion_list, shell_list, name, mass, charge, kind_number, natom, nbend, nbond, nub, nimpr, nopbend, nconstraint, nconstraint_fixd, nfixd, ncolv, ng3x3, ng4x6, nvsite, nfixd_restraint, ng3x3_restraint, ng4x6_restraint, nvsite_restraint, nrestraints, nmolecule, nsgf, nshell, ntorsion, molecule_list, nelectron, nelectron_alpha, nelectron_beta, bond_kind_set, bend_kind_set, ub_kind_set, impr_kind_set, opbend_kind_set, torsion_kind_set, molname_generated)
Get informations about a molecule kind.
Data types for neural network potentials.
Methods dealing with Neural Network potentials.
subroutine, public nnp_calc_energy_force(nnp, calc_forces)
Calculate the energy and force for a given configuration with the NNP.
subroutine, public check_dmfet(opt_dmfet, qs_env)
...
subroutine, public release_dmfet_opt(opt_dmfet)
...
subroutine, public build_full_dm(qs_env, dm, open_shell, open_shell_embed, dm_beta)
Builds density matrices from MO coefficients in full matrix format.
subroutine, public prepare_dmfet_opt(qs_env, opt_dmfet, opt_dmfet_section)
...
logical function, public subsys_spin(qs_env)
...
subroutine, public print_embed_restart(qs_env, dimen_aux, embed_pot_coef, embed_pot, i_iter, embed_pot_spin, open_shell_embed, grid_opt, final_one)
Print embedding potential as a cube and as a binary (for restarting)
subroutine, public make_subsys_embed_pot(qs_env, embed_pot, embed_pot_subsys, spin_embed_pot, spin_embed_pot_subsys, open_shell_embed, change_spin_sign)
Creates a subsystem embedding potential.
subroutine, public print_rho_spin_diff(spin_diff_rho_r, i_iter, qs_env, final_one)
Prints a cube for the (spin_rho_A + spin_rho_B - spin_rho_ref) to be minimized in embedding.
subroutine, public get_max_subsys_diff(opt_embed, force_env, subsys_num)
...
subroutine, public print_emb_opt_info(output_unit, step_num, opt_embed)
...
subroutine, public init_embed_pot(qs_env, embed_pot, add_const_pot, fermi_amaldi, const_pot, open_shell_embed, spin_embed_pot, pot_diff, coulomb_guess, grid_opt)
...
subroutine, public understand_spin_states(force_env, ref_subsys_number, change_spin, open_shell_embed, all_nspins)
Find out whether we need to swap alpha- and beta- spind densities in the second subsystem.
subroutine, public read_embed_pot(qs_env, embed_pot, spin_embed_pot, section, opt_embed)
...
subroutine, public get_prev_density(opt_embed, force_env, subsys_num)
...
subroutine, public coulomb_guess(v_rspace, rhs, mapping_section, qs_env, nforce_eval, iforce_eval, eta)
Calculates subsystem Coulomb potential from the RESP charges of the total system.
subroutine, public print_rho_diff(diff_rho_r, i_iter, qs_env, final_one)
Prints a cube for the (rho_A + rho_B - rho_ref) to be minimized in embedding.
subroutine, public conv_check_embed(opt_embed, diff_rho_r, diff_rho_spin, output_unit)
...
subroutine, public step_control(opt_embed)
Controls the step, changes the trust radius if needed in maximization of the V_emb.
subroutine, public opt_embed_step(diff_rho_r, diff_rho_spin, opt_embed, embed_pot, spin_embed_pot, rho_r_ref, qs_env)
Takes maximization step in embedding potential optimization.
subroutine, public calculate_embed_pot_grad(qs_env, diff_rho_r, diff_rho_spin, opt_embed)
Calculates the derivative of the embedding potential wrt to the expansion coefficients.
subroutine, public print_pot_simple_grid(qs_env, embed_pot, embed_pot_spin, i_iter, open_shell_embed, final_one, qs_env_cluster)
Prints a volumetric file: X Y Z value for interfacing with external programs.
subroutine, public prepare_embed_opt(qs_env, opt_embed, opt_embed_section)
Creates and allocates objects for optimization of embedding potential.
subroutine, public release_opt_embed(opt_embed)
Deallocate stuff for optimizing embedding potential.
represent a simple array based list of the given type
Define the data structure for the particle information.
Definition of physical constants:
real(kind=dp), parameter, public debye
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
The type definitions for the PWDFT environment.
Methods and functions on the PWDFT environment.
subroutine, public pwdft_calc_energy_force(pwdft_env, calculate_forces, calculate_stress)
Calculate energy and forces within the PWDFT/SIRIUS code.
Calculates QM/MM energy and forces.
subroutine, public qmmm_calc_energy_force(qmmm_env, calc_force, consistent_energies, linres)
calculates the qm/mm energy and forces
Basic container type for QM/MM.
subroutine, public apply_qmmm_translate(qmmm_env)
Apply translation to the full system in order to center the QM system into the QM box.
Calculates QM/MM energy and forces with Force-Mixing.
subroutine, public qmmmx_calc_energy_force(qmmmx_env, calc_force, consistent_energies, linres, require_consistent_energy_force)
calculates the qm/mm energy and forces
Basic container type for QM/MM with force mixing.
Atomic Polarization Tensor calculation by dF/d(E-field) finite differences.
subroutine, public apt_fdiff(force_env)
Calculate Atomic Polarization Tensors by dF/d(E-field) finite differences.
subroutine, public qs_basis_rotation(qs_env, kpoints, basis_type)
Construct basis set rotation matrices.
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, 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 set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, rhoz_cneo_set, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Set the QUICKSTEP environment.
Quickstep force driver routine.
subroutine, public qs_calc_energy_force(qs_env, calc_force, consistent_energies, linres)
...
Definition and initialisation of the mo data type.
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
interpolate the wavefunctions to speed up the convergence when doing MD
subroutine, public wfi_clear(wf_history)
Clear stored wavefunction snapshots while preserving history settings.
Handles all possible kinds of restraints in CP2K.
subroutine, public restraint_control(force_env)
Computes restraints.
subroutine, public write_scine(iounit, force_env, particles, energy, hessian)
Write SCINE interface file.
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.
subroutine, public write_stress_tensor(pv_virial, iw, cell, unit_string, numerical)
Print stress tensor to output file.
subroutine, public write_stress_tensor_components(virial, iw, cell, unit_string)
...
subroutine, public zero_virial(virial, reset)
...
subroutine, public symmetrize_virial(virial)
Symmetrize the virial components.
type for the atomic properties
Type defining parameters related to the simulation cell.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
type of a logger, at the moment it contains just a print level starting at which level it should be l...
contains arbitrary information which need to be stored
represent a pointer to a subsys, to be able to create arrays of pointers
represents a system: atoms, molecules, their pos,vel,...
The empirical interatomic potential environment.
Embedding environment type.
Type containing main data for matrix embedding potential optimization.
Type containing main data for embedding potential optimization.
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
Keeps symmetry information about a specific k-point.
Contains information about kpoints.
stores all the informations relevant to an mpi environment
represent a list of objects
Main data type collecting all relevant data for neural network potentials.
represents a pointer to a list
represent a list of objects
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
The PWDFT environment type.
keeps the density in various representations, keeping track of which ones are valid.
keeps track of the previous wavefunctions and can extrapolate them for the next step of md