17 USE mctc_env,
ONLY: error_type
18 USE mctc_io,
ONLY: structure_type, new
19 USE mctc_io_symbols,
ONLY: symbol_to_number
20 USE tblite_adjlist,
ONLY: adjacency_list, new_adjacency_list
21 USE tblite_basis_type,
ONLY: get_cutoff
22 USE tblite_container,
ONLY: container_cache
23 USE tblite_container_type,
ONLY: container_type
24 USE tblite_cutoff,
ONLY: get_lattice_points
25 USE tblite_data_spin,
ONLY: get_spin_constant
26 USE tblite_integral_multipole,
ONLY: multipole_cgto, multipole_grad_cgto, maxl, msao
27 USE tblite_integral_type,
ONLY: integral_type, new_integral
28 USE tblite_scf,
ONLY: get_mixer_dimension
29 USE tblite_scf_info,
ONLY: scf_info, atom_resolved, shell_resolved, &
30 orbital_resolved, not_used
31 USE tblite_scf_potential,
ONLY: potential_type, new_potential, add_pot_to_h1
32 USE tblite_spin,
ONLY: spin_polarization, new_spin_polarization
33 USE tblite_wavefunction_type,
ONLY: wavefunction_type, new_wavefunction
34 USE tblite_xtb_calculator,
ONLY: xtb_calculator, new_xtb_calculator
35 USE tblite_xtb_gfn1,
ONLY: new_gfn1_calculator
36 USE tblite_xtb_gfn2,
ONLY: new_gfn2_calculator
37 USE tblite_xtb_h0,
ONLY: get_selfenergy, get_hamiltonian, get_occupation, &
38 get_hamiltonian_gradient, tb_hamiltonian
39 USE tblite_xtb_ipea1,
ONLY: new_ipea1_calculator
118#include "./base/base_uses.f90"
123 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'tblite_interface'
125 INTEGER,
PARAMETER :: dip_n = 3
126 INTEGER,
PARAMETER :: quad_n = 6
127 REAL(KIND=
dp),
PARAMETER :: same_atom = 0.00001_dp
128 REAL(KIND=
dp),
PARAMETER :: tblite_scc_pconv = 2.0e-5_dp
148 PURE FUNCTION tb_spin_project(values, ispin)
RESULT(value)
150 REAL(KIND=
dp),
DIMENSION(:),
INTENT(IN) :: values
151 INTEGER,
INTENT(IN) :: ispin
152 REAL(KIND=
dp) ::
value
155 IF (
SIZE(values) > 1)
THEN
158 value = values(1) + values(2)
160 value = values(1) - values(2)
166 END FUNCTION tb_spin_project
173 SUBROUTINE tb_store_density_ref(tb, matrix_p)
175 TYPE(tblite_type),
POINTER :: tb
176 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
178 INTEGER :: img, ispin, nimg, nspin
180 nspin =
SIZE(matrix_p, 1)
181 nimg =
SIZE(matrix_p, 2)
182 IF (
ASSOCIATED(tb%rho_ao_kp_ref))
THEN
183 IF (
SIZE(tb%rho_ao_kp_ref, 1) /= nspin .OR.
SIZE(tb%rho_ao_kp_ref, 2) /= nimg)
THEN
187 IF (.NOT.
ASSOCIATED(tb%rho_ao_kp_ref))
THEN
191 ALLOCATE (tb%rho_ao_kp_ref(ispin, img)%matrix)
197 CALL dbcsr_copy(tb%rho_ao_kp_ref(ispin, img)%matrix, matrix_p(ispin, img)%matrix)
201 END SUBROUTINE tb_store_density_ref
216 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tblite_init_geometry'
220 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
221 INTEGER :: iatom, natom
222 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: xyz
223 INTEGER :: handle, ikind
224 INTEGER,
DIMENSION(3) :: periodic
225 LOGICAL,
DIMENSION(3) :: lperiod
227 CALL timeset(routinen, handle)
230 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, cell=cell, qs_kind_set=qs_kind_set)
233 natom =
SIZE(particle_set)
234 ALLOCATE (xyz(3, natom))
236 ALLOCATE (tb%el_num(natom))
239 xyz(:, iatom) = particle_set(iatom)%r(:)
240 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind)
241 CALL get_qs_kind(qs_kind_set(ikind), zatom=tb%el_num(iatom))
242 IF (tb%el_num(iatom) < 1 .OR. tb%el_num(iatom) > 85)
THEN
243 cpabort(
"only elements 1-85 are supported by tblite")
248 CALL get_cell(cell=cell, periodic=periodic)
249 lperiod(1) = periodic(1) == 1
250 lperiod(2) = periodic(2) == 1
251 lperiod(3) = periodic(3) == 1
254 CALL new(tb%mol, tb%el_num, xyz, lattice=cell%hmat, periodic=lperiod)
258 CALL timestop(handle)
263 cpabort(
"Built without TBLITE")
273 SUBROUTINE tb_update_geometry(qs_env, tb)
280 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tblite_update_geometry'
284 INTEGER :: iatom, natom
285 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: xyz
288 CALL timeset(routinen, handle)
292 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, cell=cell)
295 natom =
SIZE(particle_set)
296 ALLOCATE (xyz(3, natom))
298 xyz(:, iatom) = particle_set(iatom)%r(:)
300 tb%mol%xyz(:, :) = xyz
301 tb%mol%lattice(:, :) = cell%hmat
305 CALL timestop(handle)
310 cpabort(
"Built without TBLITE")
313 END SUBROUTINE tb_update_geometry
329 TYPE(scf_info) :: info
331 nspin = dft_control%nspins
332 IF (nspin /= 1 .AND. nspin /= 2) cpabort(
"tblite supports only one or two spin channels")
334 tb%mol%charge = dft_control%charge
335 tb%mol%uhf = max(0, dft_control%multiplicity - 1)
336 IF (nspin == 2)
CALL tb_add_spin_polarization(tb)
338 info = tb%calc%variable_info()
339 IF (info%charge > shell_resolved) cpabort(
"tblite: no support for orbital resolved charge")
340 IF (info%dipole > atom_resolved) cpabort(
"tblite: no support for shell resolved dipole moment")
341 IF (info%quadrupole > atom_resolved)
THEN
342 cpabort(
"tblite: no support shell resolved quadrupole moment")
345 CALL new_wavefunction(tb%wfn, tb%mol%nat, tb%calc%bas%nsh, tb%calc%bas%nao, nspin, 0.0_dp)
346 CALL get_occupation(tb%mol, tb%calc%bas, tb%calc%h0, tb%wfn%nocc, tb%wfn%n0at, tb%wfn%n0sh)
347 CALL tb_reset_mixer(tb)
349 CALL new_potential(tb%pot, tb%mol, tb%calc%bas, tb%wfn%nspin)
352 ALLOCATE (tb%e_hal(tb%mol%nat), tb%e_rep(tb%mol%nat), tb%e_disp(tb%mol%nat))
353 ALLOCATE (tb%e_scd(tb%mol%nat), tb%e_es(tb%mol%nat), tb%e_int(tb%mol%nat))
354 ALLOCATE (tb%selfenergy(tb%calc%bas%nsh))
355 IF (
ALLOCATED(tb%calc%ncoord))
ALLOCATE (tb%cn(tb%mol%nat))
359 mark_used(dft_control)
360 cpabort(
"Built without TBLITE")
370 SUBROUTINE tb_add_spin_polarization(tb)
374 CLASS(container_type),
ALLOCATABLE :: cont
375 TYPE(spin_polarization),
ALLOCATABLE :: spin
376 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: wll
379 CALL tb_get_spin_constants(tb, wll)
380 CALL new_spin_polarization(spin, tb%mol, wll, tb%calc%bas%nsh_id)
381 CALL move_alloc(spin, cont)
382 CALL tb%calc%push_back(cont)
384 END SUBROUTINE tb_add_spin_polarization
391 SUBROUTINE tb_get_spin_constants(tb, wll)
394 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :), &
397 INTEGER :: il, ish, izp, jl, jsh
399 ALLOCATE (wll(tb%calc%bas%nsh, tb%calc%bas%nsh, tb%mol%nid))
401 DO izp = 1, tb%mol%nid
402 DO ish = 1, tb%calc%bas%nsh_id(izp)
403 il = tb%calc%bas%cgto(ish, izp)%ang
404 DO jsh = 1, tb%calc%bas%nsh_id(izp)
405 jl = tb%calc%bas%cgto(jsh, izp)%ang
406 wll(jsh, ish, izp) = get_spin_constant(jl, il, tb%mol%num(izp))
411 END SUBROUTINE tb_get_spin_constants
418 SUBROUTINE tb_reset_mixer(tb)
424 TYPE(scf_info) :: info
426 info = tb%calc%variable_info()
427 IF (
ALLOCATED(tb%mixer))
DEALLOCATE (tb%mixer)
428 CALL new_cp2k_tblite_mixer(tb%mixer, tb%mixer_memory, &
429 tb%wfn%nspin*get_mixer_dimension(tb%mol, tb%calc%bas, info), &
430 tb%mixer_damping, tb%mixer_omega0, tb%mixer_min_weight, &
431 tb%mixer_max_weight, tb%mixer_weight_factor)
435 cpabort(
"Built without TBLITE")
438 END SUBROUTINE tb_reset_mixer
452 SUBROUTINE tb_configure_mixer(tb, iterations, memory, damping, omega0, min_weight, max_weight, &
453 weight_factor, solver)
456 INTEGER,
INTENT(IN) :: iterations, memory, solver
457 REAL(kind=
dp),
INTENT(IN) :: damping, max_weight, min_weight, omega0, &
462 IF (iterations < 1) cpabort(
"tblite SCC mixer ITERATIONS must be positive")
463 IF (memory < 1) cpabort(
"tblite SCC mixer MEMORY must be positive")
464 IF (damping <= 0.0_dp) cpabort(
"tblite SCC mixer damping must be positive")
465 IF (omega0 <= 0.0_dp) cpabort(
"tblite SCC mixer OMEGA0 must be positive")
466 IF (min_weight <= 0.0_dp) cpabort(
"tblite SCC mixer MIN_WEIGHT must be positive")
467 IF (max_weight <= 0.0_dp) cpabort(
"tblite SCC mixer MAX_WEIGHT must be positive")
468 IF (max_weight < min_weight)
THEN
469 cpabort(
"tblite SCC mixer MAX_WEIGHT must not be smaller than MIN_WEIGHT")
471 IF (weight_factor <= 0.0_dp) cpabort(
"tblite SCC mixer WEIGHT_FACTOR must be positive")
475 cpabort(
"Unknown tblite SCC mixer SOLVER")
478 tb%calc%max_iter = iterations
479 tb%mixer_memory = memory
480 tb%mixer_solver = solver
481 tb%mixer_damping = damping
482 tb%calc%mixer_input%damping = damping
483 tb%mixer_omega0 = omega0
484 tb%mixer_min_weight = min_weight
485 tb%mixer_max_weight = max_weight
486 tb%mixer_weight_factor = weight_factor
490 mark_used(iterations)
494 mark_used(min_weight)
495 mark_used(max_weight)
496 mark_used(weight_factor)
498 cpabort(
"Built without TBLITE")
501 END SUBROUTINE tb_configure_mixer
511 LOGICAL :: use_native_mixer
513 use_native_mixer = .false.
514 IF (.NOT.
ASSOCIATED(dft_control))
RETURN
515 IF (dft_control%qs_control%do_ls_scf)
RETURN
517 SELECT CASE (dft_control%qs_control%xtb_control%tblite_scc_mixer)
519 use_native_mixer = .true.
521 use_native_mixer = .true.
523 use_native_mixer = .false.
525 cpabort(
"Unknown tblite SCC mixer")
541 REAL(kind=
dp),
INTENT(IN) :: eps_scf
542 REAL(kind=
dp) :: mixer_error
545 REAL(kind=
dp) :: raw_error
551 IF (.NOT.
ASSOCIATED(tb))
RETURN
553 IF (
ALLOCATED(tb%mixer))
THEN
554 raw_error = real(tb%mixer%get_error(), kind=
dp)
555 IF (eps_scf > 0.0_dp)
THEN
556 mixer_error = eps_scf*raw_error/ &
557 (tblite_scc_pconv*dft_control%qs_control%xtb_control%tblite_accuracy)
559 mixer_error = raw_error
563 mark_used(dft_control)
581 REAL(kind=
dp),
INTENT(IN) :: accuracy
582 CHARACTER(LEN=*),
INTENT(IN) :: param_file
586 TYPE(error_type),
ALLOCATABLE :: error
588 IF (
ALLOCATED(tb%param))
DEALLOCATE (tb%param)
589 IF (len_trim(param_file) > 0)
THEN
591 CALL tb%param%load(trim(param_file), error)
592 IF (
ALLOCATED(error)) cpabort(
"Could not load tblite PARAM file: "//trim(param_file))
593 CALL new_xtb_calculator(tb%calc, tb%mol, tb%param, error)
597 cpabort(
"Unknown xtb type")
599 CALL new_gfn1_calculator(tb%calc, tb%mol, error)
601 CALL new_gfn2_calculator(tb%calc, tb%mol, error)
603 CALL new_ipea1_calculator(tb%calc, tb%mol, error)
606 IF (
ALLOCATED(error)) cpabort(
"tblite calculator setup failed")
608 tb%accuracy = accuracy
614 mark_used(param_file)
615 cpabort(
"Built without TBLITE")
626 SUBROUTINE tb_init_ham(qs_env, tb, para_env)
634 TYPE(container_cache) :: hcache, rcache
640 IF (
ALLOCATED(tb%grad))
THEN
642 CALL tb_zero_force(qs_env)
646 IF (
ALLOCATED(tb%calc%halogen))
THEN
647 CALL tb%calc%halogen%update(tb%mol, hcache)
648 IF (
ALLOCATED(tb%grad))
THEN
650 CALL tb%calc%halogen%get_engrad(tb%mol, hcache, tb%e_hal, &
652 CALL tb_dump_sigma_component(
"after_halogen", tb%sigma, para_env)
653 CALL tb_grad2force(qs_env, tb, para_env, 0)
655 CALL tb%calc%halogen%get_engrad(tb%mol, hcache, tb%e_hal)
659 IF (
ALLOCATED(tb%calc%repulsion))
THEN
660 CALL tb%calc%repulsion%update(tb%mol, rcache)
661 IF (
ALLOCATED(tb%grad))
THEN
663 CALL tb%calc%repulsion%get_engrad(tb%mol, rcache, tb%e_rep, &
665 CALL tb_dump_sigma_component(
"after_repulsion", tb%sigma, para_env)
666 CALL tb_grad2force(qs_env, tb, para_env, 1)
668 CALL tb%calc%repulsion%get_engrad(tb%mol, rcache, tb%e_rep)
672 IF (
ALLOCATED(tb%calc%dispersion))
THEN
673 CALL tb%calc%dispersion%update(tb%mol, tb%dcache)
674 IF (
ALLOCATED(tb%grad))
THEN
676 CALL tb%calc%dispersion%get_engrad(tb%mol, tb%dcache, tb%e_disp, &
678 CALL tb_dump_sigma_component(
"after_dispersion_static", tb%sigma, para_env)
679 CALL tb_grad2force(qs_env, tb, para_env, 2)
681 CALL tb%calc%dispersion%get_engrad(tb%mol, tb%dcache, tb%e_disp)
685 IF (
ALLOCATED(tb%calc%interactions))
THEN
686 CALL tb%calc%interactions%update(tb%mol, tb%icache)
689 CALL new_potential(tb%pot, tb%mol, tb%calc%bas, tb%wfn%nspin)
690 IF (
ALLOCATED(tb%calc%coulomb))
THEN
691 CALL tb%calc%coulomb%update(tb%mol, tb%cache)
694 IF (
ALLOCATED(tb%grad))
THEN
695 IF (
ALLOCATED(tb%calc%ncoord))
THEN
696 CALL tb%calc%ncoord%get_cn(tb%mol, tb%cn, tb%dcndr, tb%dcndL)
698 CALL get_selfenergy(tb%calc%h0, tb%mol%id, tb%calc%bas%ish_at, &
699 & tb%calc%bas%nsh_id, cn=tb%cn, selfenergy=tb%selfenergy, dsedcn=tb%dsedcn)
701 IF (
ALLOCATED(tb%calc%ncoord))
THEN
702 CALL tb%calc%ncoord%get_cn(tb%mol, tb%cn)
704 CALL get_selfenergy(tb%calc%h0, tb%mol%id, tb%calc%bas%ish_at, &
705 & tb%calc%bas%nsh_id, cn=tb%cn, selfenergy=tb%selfenergy, dsedcn=tb%dsedcn)
712 cpabort(
"Built without TBLITE")
715 END SUBROUTINE tb_init_ham
734 REAL(kind=
dp) :: xtb_inter
735 NULLIFY (scf_section, logger)
741 energy%repulsive = sum(tb%e_rep)
742 energy%el_stat = sum(tb%e_es)
743 energy%dispersion = sum(tb%e_disp)
744 energy%dispersion_sc = sum(tb%e_scd)
745 energy%xtb_xb_inter = sum(tb%e_hal)
746 xtb_inter = sum(tb%e_int)
748 energy%total = energy%core + energy%repulsive + energy%el_stat + energy%dispersion &
749 + energy%dispersion_sc + energy%xtb_xb_inter + xtb_inter &
750 + energy%kTS + energy%efield + energy%qmmm_el
755 WRITE (unit=iounit, fmt=
"(/,(T9,A,T60,F20.10))") &
756 "Repulsive pair potential energy: ", energy%repulsive, &
757 "Zeroth order Hamiltonian energy: ", energy%core, &
758 "Electrostatic energy: ", energy%el_stat, &
759 "Self-consistent dispersion energy: ", energy%dispersion_sc, &
760 "Non-self consistent dispersion energy: ", energy%dispersion
761 IF (abs(energy%xtb_xb_inter) > 1.e-9_dp)
THEN
762 WRITE (unit=iounit, fmt=
"(T9,A,T60,F20.10)") &
763 "Correction for halogen bonding: ", energy%xtb_xb_inter
765 IF (abs(xtb_inter) > 1.e-9_dp)
THEN
766 WRITE (unit=iounit, fmt=
"(T9,A,T60,F20.10)") &
767 "Additional interaction (e.g. spin): ", xtb_inter
769 IF (abs(energy%efield) > 1.e-9_dp)
THEN
770 WRITE (unit=iounit, fmt=
"(T9,A,T60,F20.10)") &
771 "Electric field interaction energy: ", energy%efield
773 IF (qs_env%qmmm)
THEN
774 WRITE (unit=iounit, fmt=
"(T9,A,T60,F20.10)") &
775 "QM/MM Electrostatic energy: ", energy%qmmm_el
779 "PRINT%DETAILED_ENERGY")
785 cpabort(
"Built without TBLITE")
802 CHARACTER(len=2),
INTENT(IN) :: element_symbol
804 INTEGER,
DIMENSION(5),
INTENT(out) :: occ
808 REAL(kind=
dp) :: docc
809 CHARACTER(LEN=default_string_length) :: sng
810 INTEGER :: ang, i_type, id_atom, ind_ao, ipgf, ish, &
811 ishell, ityp, maxl, mprim, natorb, &
818 CALL symbol_to_number(i_type, element_symbol)
819 DO id_atom = 1, tb%mol%nat
820 IF (i_type == tb%el_num(id_atom))
EXIT
823 param%symbol = element_symbol
824 param%defined = .true.
825 ityp = tb%mol%id(id_atom)
828 nset = tb%calc%bas%nsh_id(ityp)
832 mprim = max(mprim, tb%calc%bas%cgto(ishell, ityp)%nprim)
839 gto_basis_set%name = element_symbol//
"_STO-"//trim(sng)//
"G"
840 gto_basis_set%nset = nset
844 CALL reallocate(gto_basis_set%nshell, 1, nset)
845 CALL reallocate(gto_basis_set%n, 1, 1, 1, nset)
846 CALL reallocate(gto_basis_set%l, 1, 1, 1, nset)
847 CALL reallocate(gto_basis_set%zet, 1, mprim, 1, nset)
848 CALL reallocate(gto_basis_set%gcc, 1, mprim, 1, 1, 1, nset)
853 ang = tb%calc%bas%cgto(ishell, ityp)%ang
854 natorb = natorb + (2*ang + 1)
855 param%lval(ishell) = ang
856 maxl = max(ang, maxl)
857 gto_basis_set%lmax(ishell) = ang
858 gto_basis_set%lmin(ishell) = ang
859 gto_basis_set%npgf(ishell) = tb%calc%bas%cgto(ishell, ityp)%nprim
860 gto_basis_set%nshell(ishell) = nshell
861 gto_basis_set%n(1, ishell) = ang + 1
862 gto_basis_set%l(1, ishell) = ang
863 DO ipgf = 1, gto_basis_set%npgf(ishell)
864 gto_basis_set%gcc(ipgf, 1, ishell) = tb%calc%bas%cgto(ishell, ityp)%coeff(ipgf)
865 gto_basis_set%zet(ipgf, ishell) = tb%calc%bas%cgto(ishell, ityp)%alpha(ipgf)
867 DO ipgf = 1, (2*ang + 1)
869 param%lao(ind_ao) = ang
870 param%nao(ind_ao) = ishell
878 param%rcut = get_cutoff(tb%calc%bas, tb%accuracy)
879 param%natorb = natorb
885 IF (tb%calc%bas%nsh_at(id_atom) > 5) cpabort(
"too many shells in tblite")
886 DO ish = 1, tb%calc%bas%nsh_at(id_atom)
887 occ(ish) = nint(tb%calc%h0%refocc(ish, ityp) + docc)
888 docc = docc + tb%calc%h0%refocc(ish, ityp) - real(occ(ish))
889 param%occupation(ish) = occ(ish)
891 IF (abs(docc) > 0.1_dp) cpabort(
"Getting occupation numbers from tblite fails")
892 param%zeff = sum(occ)
895 gto_basis_set%norm_type = 3
900 mark_used(gto_basis_set)
901 mark_used(element_symbol)
903 cpabort(
"Built without TBLITE")
916 LOGICAL,
INTENT(IN) :: calculate_forces
920 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_tblite_matrices'
922 INTEGER :: handle, maxder, nderivatives, nimg, img, nkind, i, &
923 ic, iw, iatom, jatom, ikind, jkind, iset, jset, n1, n2, icol, &
924 irow, ia, ib, sgfa, sgfb, ldsab, nseta, nsetb, &
925 natorb_a, natorb_b, raw_iatom, raw_jatom, &
927 LOGICAL :: found, norml1, norml2, use_arnoldi
928 REAL(kind=
dp) :: dr, dshpoly, ff, hij_base, r2, rr
929 REAL(kind=
dp) :: native_dot_tmp, native_cn_icol, native_cn_irow, &
931 INTEGER,
DIMENSION(3) :: cell
932 REAL(kind=
dp) :: hij, shpoly
933 REAL(kind=
dp),
DIMENSION(2) :: condnum
934 REAL(kind=
dp),
DIMENSION(3) :: native_h0_overlap_force, native_radial_force, raw_rij, rij
935 REAL(kind=
dp),
DIMENSION(3, 3) :: native_radial_dot
936 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
937 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
938 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: owork
939 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: native_cn_deriv_thread
940 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: native_radial_force_thread
941 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: oint, sint, hint
942 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :, :) :: radial_hint
943 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, lb_max, lb_min
944 INTEGER,
DIMENSION(:),
POINTER :: npgfa, npgfb, nsgfa, nsgfb
945 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
946 REAL(kind=
dp),
DIMENSION(:),
POINTER :: set_radius_a, set_radius_b
947 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: rpgfa, rpgfb, zeta, zetb, scon_a, scon_b
948 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: fblock, pblock, sblock
953 INTEGER,
PARAMETER :: nlock = 501
959 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_dh_native, matrix_h, matrix_p, &
960 matrix_q_native, matrix_s, matrix_s_native, matrix_w
971 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
974 TYPE(tb_hamiltonian),
POINTER :: h0
977 CALL timeset(routinen, handle)
979 NULLIFY (ks_env, energy, atomic_kind_set, qs_kind_set)
980 NULLIFY (matrix_dh_native, matrix_h, matrix_q_native, matrix_s, matrix_s_native, atprop, dft_control)
981 NULLIFY (sab_orb, sab_kp, rho, tb, kpoints, cell_to_index)
984 ks_env=ks_env, para_env=para_env, &
986 atomic_kind_set=atomic_kind_set, &
987 qs_kind_set=qs_kind_set, &
988 matrix_h_kp=matrix_h, &
989 matrix_s_kp=matrix_s, &
991 dft_control=dft_control, &
994 rho=rho, tb_tblite=tb)
998 CALL tb_update_geometry(qs_env, tb)
1000 nkind =
SIZE(atomic_kind_set)
1002 IF (calculate_forces)
THEN
1004 IF (
ALLOCATED(tb%grad))
DEALLOCATE (tb%grad)
1005 ALLOCATE (tb%grad(3, tb%mol%nat))
1006 IF (
ALLOCATED(tb%dsedcn))
DEALLOCATE (tb%dsedcn)
1007 ALLOCATE (tb%dsedcn(tb%calc%bas%nsh))
1008 IF (
ALLOCATED(tb%calc%ncoord))
THEN
1009 IF (
ALLOCATED(tb%dcndr))
DEALLOCATE (tb%dcndr)
1010 ALLOCATE (tb%dcndr(3, tb%mol%nat, tb%mol%nat))
1011 IF (
ALLOCATED(tb%dcndL))
DEALLOCATE (tb%dcndL)
1012 ALLOCATE (tb%dcndL(3, 3, tb%mol%nat))
1015 IF (
ALLOCATED(tb%grad))
DEALLOCATE (tb%grad)
1016 IF (
ALLOCATED(tb%dcndr))
DEALLOCATE (tb%dcndr)
1017 IF (
ALLOCATED(tb%dcndL))
DEALLOCATE (tb%dcndL)
1019 maxder =
ncoset(nderivatives)
1020 nimg = dft_control%nimages
1022 IF (.NOT.
ASSOCIATED(sab_kp)) cpabort(
"Missing k-point neighbor list for tblite")
1024 CALL get_ks_env(ks_env=ks_env, kpoints=kpoints)
1029 CALL tb_init_ham(qs_env, tb, para_env)
1035 IF (calculate_forces)
THEN
1036 NULLIFY (force, matrix_w, virial)
1038 matrix_w_kp=matrix_w, &
1039 virial=virial, force=force)
1041 IF (
SIZE(matrix_p, 1) == 2)
THEN
1043 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
1044 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1045 CALL dbcsr_add(matrix_w(1, img)%matrix, matrix_w(2, img)%matrix, &
1046 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1049 tb%use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1052 IF (calculate_forces)
THEN
1055 ALLOCATE (matrix_q_native(1, img)%matrix)
1056 CALL dbcsr_copy(matrix_q_native(1, img)%matrix, matrix_w(1, img)%matrix, &
1057 name=
"TBLITE NATIVE OVERLAP FORCE MATRIX")
1061 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, atom_of_kind=atom_of_kind, kind_of=kind_of)
1062 IF (calculate_forces)
THEN
1063 ALLOCATE (native_radial_force_thread(3,
SIZE(atom_of_kind)))
1064 ALLOCATE (native_cn_deriv_thread(
SIZE(atom_of_kind)))
1065 native_cn_deriv_thread = 0.0_dp
1066 native_radial_force_thread = 0.0_dp
1070 ALLOCATE (basis_set_list(nkind))
1075 CALL create_sab_matrix(ks_env, matrix_s,
"OVERLAP MATRIX", basis_set_list, basis_set_list, &
1077 CALL set_ks_env(ks_env, matrix_s_kp=matrix_s)
1082 ALLOCATE (matrix_h(1, img)%matrix)
1083 CALL dbcsr_create(matrix_h(1, img)%matrix, template=matrix_s(1, img)%matrix, &
1084 name=
"HAMILTONIAN MATRIX")
1087 CALL set_ks_env(ks_env, matrix_h_kp=matrix_h)
1088 IF (calculate_forces .AND. nimg > 1)
THEN
1092 ALLOCATE (matrix_dh_native(idim, img)%matrix)
1093 CALL dbcsr_create(matrix_dh_native(idim, img)%matrix, template=matrix_s(1, img)%matrix, &
1094 name=
"TBLITE H0 STRAIN DERIVATIVE")
1101 native_radial_dot = 0.0_dp
1129 ALLOCATE (oint(ldsab, ldsab, maxder), owork(ldsab, ldsab))
1132 DO slot = 1, sab_orb(1)%nl_size
1134 ikind = sab_orb(1)%nlist_task(slot)%ikind
1135 jkind = sab_orb(1)%nlist_task(slot)%jkind
1136 iatom = sab_orb(1)%nlist_task(slot)%iatom
1137 jatom = sab_orb(1)%nlist_task(slot)%jatom
1138 cell(:) = sab_orb(1)%nlist_task(slot)%cell(:)
1139 rij(1:3) = sab_orb(1)%nlist_task(slot)%r(1:3)
1143 native_cn_icol = 0.0_dp
1144 native_cn_irow = 0.0_dp
1145 native_h0_overlap_force = 0.0_dp
1146 native_radial_force = 0.0_dp
1149 icol = max(iatom, jatom)
1150 irow = min(iatom, jatom)
1151 IF (iatom < jatom)
THEN
1164 ic = cell_to_index(cell(1), cell(2), cell(3))
1170 row=irow, col=icol, block=sblock, found=found)
1174 row=irow, col=icol, block=fblock, found=found)
1176 IF (calculate_forces)
THEN
1179 row=irow, col=icol, block=pblock, found=found)
1184 NULLIFY (radial_blocks(idim, jdim)%block)
1185 CALL dbcsr_get_block_p(matrix=matrix_dh_native(idim + 3*(jdim - 1), ic)%matrix, &
1186 row=irow, col=icol, block=radial_blocks(idim, jdim)%block, &
1196 basis_set_a => basis_set_list(ikind)%gto_basis_set
1197 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
1198 basis_set_b => basis_set_list(jkind)%gto_basis_set
1199 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
1201 first_sgfa => basis_set_a%first_sgf
1202 la_max => basis_set_a%lmax
1203 la_min => basis_set_a%lmin
1204 npgfa => basis_set_a%npgf
1205 nseta = basis_set_a%nset
1206 nsgfa => basis_set_a%nsgf_set
1207 rpgfa => basis_set_a%pgf_radius
1208 set_radius_a => basis_set_a%set_radius
1209 scon_a => basis_set_a%scon
1210 zeta => basis_set_a%zet
1212 first_sgfb => basis_set_b%first_sgf
1213 lb_max => basis_set_b%lmax
1214 lb_min => basis_set_b%lmin
1215 npgfb => basis_set_b%npgf
1216 nsetb = basis_set_b%nset
1217 nsgfb => basis_set_b%nsgf_set
1218 rpgfb => basis_set_b%pgf_radius
1219 set_radius_b => basis_set_b%set_radius
1220 scon_b => basis_set_b%scon
1221 zetb => basis_set_b%zet
1225 natorb_a = natorb_a + (2*basis_set_a%l(1, iset) + 1)
1229 natorb_b = natorb_b + (2*basis_set_b%l(1, iset) + 1)
1231 ALLOCATE (sint(natorb_a, natorb_b, maxder))
1233 ALLOCATE (hint(natorb_a, natorb_b, maxder))
1235 IF (calculate_forces .AND. nimg > 1)
THEN
1236 ALLOCATE (radial_hint(natorb_a, natorb_b, 3, 3))
1237 radial_hint = 0.0_dp
1242 n1 = npgfa(iset)*(
ncoset(la_max(iset)) -
ncoset(la_min(iset) - 1))
1243 sgfa = first_sgfa(1, iset)
1245 IF (set_radius_a(iset) + set_radius_b(jset) < dr) cycle
1246 n2 = npgfb(jset)*(
ncoset(lb_max(jset)) -
ncoset(lb_min(jset) - 1))
1247 sgfb = first_sgfb(1, jset)
1248 IF (calculate_forces)
THEN
1249 CALL overlap_ab(la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
1250 lb_max(jset), lb_min(jset), npgfb(jset), rpgfb(:, jset), zetb(:, jset), &
1251 rij, sab=oint(:, :, 1), dab=oint(:, :, 2:4))
1253 CALL overlap_ab(la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
1254 lb_max(jset), lb_min(jset), npgfb(jset), rpgfb(:, jset), zetb(:, jset), &
1255 rij, sab=oint(:, :, 1))
1258 CALL contraction(oint(:, :, 1), owork, ca=scon_a(:, sgfa:), na=n1, ma=nsgfa(iset), &
1259 cb=scon_b(:, sgfb:), nb=n2, mb=nsgfb(jset), fscale=1.0_dp, trans=.false.)
1260 CALL block_add(
"IN", owork, nsgfa(iset), nsgfb(jset), sint(:, :, 1), sgfa, sgfb, trans=.false.)
1261 IF (calculate_forces)
THEN
1263 CALL contraction(oint(:, :, i), owork, ca=scon_a(:, sgfa:), na=n1, ma=nsgfa(iset), &
1264 cb=scon_b(:, sgfb:), nb=n2, mb=nsgfb(jset), fscale=1.0_dp, trans=.false.)
1265 CALL block_add(
"IN", owork, nsgfa(iset), nsgfb(jset), sint(:, :, i), sgfa, sgfb, trans=.false.)
1276 IF (icol <= irow)
THEN
1277 sblock(:, :) = sblock(:, :) + sint(:, :, 1)
1279 sblock(:, :) = sblock(:, :) + transpose(sint(:, :, 1))
1284 IF (icol == irow .AND. dr < same_atom)
THEN
1286 n1 = tb%calc%bas%ish_at(icol)
1288 sgfa = first_sgfa(1, iset)
1289 hij = tb%selfenergy(n1 + iset)
1290 DO ia = sgfa, sgfa + nsgfa(iset) - 1
1291 hint(ia, ia, 1) = hij
1292 IF (calculate_forces)
THEN
1293 native_cn_icol = native_cn_icol + tb%dsedcn(n1 + iset)*pblock(ia, ia)
1297 native_radial_dot(idim, jdim) = native_radial_dot(idim, jdim) + &
1298 tb%dsedcn(n1 + iset)*tb%dcndL(idim, jdim, icol)*pblock(ia, ia)
1300 radial_hint(ia, ia, idim, jdim) = radial_hint(ia, ia, idim, jdim) + &
1301 tb%dsedcn(n1 + iset)*tb%dcndL(idim, jdim, icol)
1310 rr = sqrt(dr/(h0%rad(jkind) + h0%rad(ikind)))
1311 n1 = tb%calc%bas%ish_at(icol)
1313 sgfa = first_sgfa(1, iset)
1314 n2 = tb%calc%bas%ish_at(irow)
1316 sgfb = first_sgfb(1, jset)
1317 shpoly = (1.0_dp + h0%shpoly(iset, ikind)*rr) &
1318 *(1.0_dp + h0%shpoly(jset, jkind)*rr)
1319 dshpoly = ((1.0_dp + h0%shpoly(iset, ikind)*rr)*h0%shpoly(jset, jkind)*rr &
1320 + (1.0_dp + h0%shpoly(jset, jkind)*rr)*h0%shpoly(iset, ikind)*rr) &
1322 hij_base = 0.5_dp*(tb%selfenergy(n1 + iset) + tb%selfenergy(n2 + jset)) &
1323 *h0%hscale(iset, jset, ikind, jkind)
1324 hij = hij_base*shpoly
1325 DO ia = sgfa, sgfa + nsgfa(iset) - 1
1326 DO ib = sgfb, sgfb + nsgfb(jset) - 1
1327 hint(ia, ib, 1) = hij*sint(ia, ib, 1)
1328 IF (calculate_forces)
THEN
1329 native_dot_weight = 2.0_dp
1330 IF (icol == irow) native_dot_weight = 1.0_dp
1331 native_cn_icol = native_cn_icol + native_dot_weight*0.5_dp* &
1332 h0%hscale(iset, jset, ikind, jkind)*shpoly* &
1333 tb%dsedcn(n1 + iset)*pblock(ib, ia)*sint(ia, ib, 1)
1334 native_cn_irow = native_cn_irow + native_dot_weight*0.5_dp* &
1335 h0%hscale(iset, jset, ikind, jkind)*shpoly* &
1336 tb%dsedcn(n2 + jset)*pblock(ib, ia)*sint(ia, ib, 1)
1337 native_radial_force = native_radial_force + &
1338 hij_base*dshpoly*pblock(ib, ia)*sint(ia, ib, 1)*raw_rij
1339 native_h0_overlap_force = native_h0_overlap_force + &
1340 hij*pblock(ib, ia)*sint(ia, ib, 2:4)
1344 native_radial_dot(idim, jdim) = native_radial_dot(idim, jdim) + &
1345 native_dot_weight*pblock(ib, ia)*( &
1346 (-hij)*sint(ia, ib, idim + 1)*rij(jdim) + &
1347 hij_base*dshpoly*sint(ia, ib, 1)*rij(idim)*rij(jdim) + &
1348 0.5_dp*h0%hscale(iset, jset, ikind, jkind)*shpoly*sint(ia, ib, 1)* &
1349 (tb%dsedcn(n1 + iset)*tb%dcndL(idim, jdim, icol) + &
1350 tb%dsedcn(n2 + jset)*tb%dcndL(idim, jdim, irow)))
1352 radial_hint(ia, ib, idim, jdim) = radial_hint(ia, ib, idim, jdim) + &
1353 (-hij)*sint(ia, ib, idim + 1)*rij(jdim) + &
1354 hij_base*dshpoly*sint(ia, ib, 1)*rij(idim)*rij(jdim) + &
1355 0.5_dp*h0%hscale(iset, jset, ikind, jkind)*shpoly*sint(ia, ib, 1)* &
1356 (tb%dsedcn(n1 + iset)*tb%dcndL(idim, jdim, icol) + &
1357 tb%dsedcn(n2 + jset)*tb%dcndL(idim, jdim, irow))
1370 IF (icol <= irow)
THEN
1371 fblock(:, :) = fblock(:, :) + hint(:, :, 1)
1372 IF (calculate_forces .AND. nimg > 1)
THEN
1375 radial_blocks(idim, jdim)%block(:, :) = radial_blocks(idim, jdim)%block(:, :) + &
1376 radial_hint(:, :, idim, jdim)
1381 fblock(:, :) = fblock(:, :) + transpose(hint(:, :, 1))
1382 IF (calculate_forces .AND. nimg > 1)
THEN
1385 radial_blocks(idim, jdim)%block(:, :) = radial_blocks(idim, jdim)%block(:, :) + &
1386 transpose(radial_hint(:, :, idim, jdim))
1393 IF (calculate_forces)
THEN
1396 native_radial_force_thread(:, raw_iatom) = &
1397 native_radial_force_thread(:, raw_iatom) - ff*native_radial_force
1398 native_radial_force_thread(:, raw_jatom) = &
1399 native_radial_force_thread(:, raw_jatom) + ff*native_radial_force
1400 native_radial_force_thread(:, icol) = &
1401 native_radial_force_thread(:, icol) + ff*native_h0_overlap_force
1402 native_radial_force_thread(:, irow) = &
1403 native_radial_force_thread(:, irow) - ff*native_h0_overlap_force
1404 native_cn_deriv_thread(icol) = native_cn_deriv_thread(icol) + native_cn_icol
1405 native_cn_deriv_thread(irow) = native_cn_deriv_thread(irow) + native_cn_irow
1409 DEALLOCATE (sint, hint)
1410 IF (
ALLOCATED(radial_hint))
DEALLOCATE (radial_hint)
1414 DEALLOCATE (oint, owork)
1425 IF (calculate_forces)
THEN
1427 native_radial_dot = 0.0_dp
1431 CALL dbcsr_finalize(matrix_dh_native(idim + 3*(jdim - 1), img)%matrix)
1432 CALL dbcsr_dot(matrix_dh_native(idim + 3*(jdim - 1), img)%matrix, &
1433 matrix_p(1, img)%matrix, native_dot_tmp)
1434 native_radial_dot(idim, jdim) = native_radial_dot(idim, jdim) + native_dot_tmp
1440 CALL para_env%sum(native_radial_dot)
1442 CALL para_env%sum(native_cn_deriv_thread)
1444 CALL tb_add_grad(tb%grad, tb%dcndr, native_cn_deriv_thread, tb%mol%nat)
1445 CALL tb_grad2force(qs_env, tb, para_env, 4)
1446 DO iatom = 1,
SIZE(atom_of_kind)
1447 ikind = kind_of(iatom)
1448 force(ikind)%overlap(:, atom_of_kind(iatom)) = &
1449 force(ikind)%overlap(:, atom_of_kind(iatom)) + native_radial_force_thread(:, iatom)
1451 IF (tb%use_virial)
THEN
1452 virial%pv_overlap = virial%pv_overlap - native_radial_dot/para_env%num_pe
1453 virial%pv_virial = virial%pv_virial - native_radial_dot/para_env%num_pe
1458 DO i = 1,
SIZE(matrix_s, 1)
1461 DO i = 1,
SIZE(matrix_h, 1)
1466 IF (calculate_forces)
THEN
1468 matrix_name=
"OVERLAP MATRIX", nderivative=nderivatives, &
1469 basis_type_a=
"ORB", basis_type_b=
"ORB", sab_nl=sab_orb, &
1470 calculate_forces=.true., matrixkp_p=matrix_q_native)
1476 IF (dft_control%qs_control%xtb_control%tblite_method ==
gfn2xtb)
THEN
1483 IF (.NOT. calculate_forces)
THEN
1485 "DFT%PRINT%OVERLAP_CONDITION") /= 0)
THEN
1489 CALL section_vals_val_get(qs_env%input,
"DFT%PRINT%OVERLAP_CONDITION%DIAGONALIZATION", l_val=norml2)
1490 CALL section_vals_val_get(qs_env%input,
"DFT%PRINT%OVERLAP_CONDITION%ARNOLDI", l_val=use_arnoldi)
1491 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env)
1492 CALL overlap_condnum(matrix_s, condnum, iw, norml1, norml2, use_arnoldi, blacs_env)
1496 DEALLOCATE (basis_set_list)
1497 IF (
ALLOCATED(native_cn_deriv_thread))
DEALLOCATE (native_cn_deriv_thread)
1498 IF (
ALLOCATED(native_radial_force_thread))
DEALLOCATE (native_radial_force_thread)
1500 CALL timestop(handle)
1504 mark_used(calculate_forces)
1505 cpabort(
"Built without TBLITE")
1523 LOGICAL,
INTENT(IN) :: calculate_forces
1524 LOGICAL,
INTENT(IN) :: use_rho
1526#if defined(__TBLITE)
1528 INTEGER :: iatom, ikind, is, ns, atom_a, ii, im
1529 INTEGER :: ispin, nspin
1530 INTEGER :: nimg, nkind, nsgf, natorb, na, n_mix_cols, mix_offset
1531 INTEGER :: n_atom, max_orb, max_shell
1532 INTEGER :: raw_state_status, raw_state_unit
1533 LOGICAL :: advance_native_mixer, discard_mixed_output, do_combined_mixing, &
1534 do_dipole, do_quadrupole, native_sign_mixing, &
1535 skip_charge_mixing, reuse_native_input, skip_scf_dispersion, &
1536 skip_scf_dispersion_energy, seed_native_from_rho, &
1537 skip_scf_dispersion_gradient, skip_scf_dispersion_potential, &
1538 use_native_mixer, use_no_mixer
1539 REAL(kind=
dp) :: native_seed_charge, norm, new_charge, pao
1540#if defined(__TBLITE_DEBUG_DIAGNOSTICS)
1541 INTEGER :: debug_status
1542 CHARACTER(LEN=32) :: debug_value
1544 CHARACTER(LEN=default_path_length) :: raw_state_file
1545 INTEGER,
DIMENSION(5) :: occ
1546 INTEGER,
DIMENSION(25) :: lao
1547 INTEGER,
DIMENSION(25) :: nao
1548 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ch_atom, ch_shell, ch_ref, ch_orb, mix_vars
1549 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: aocg, ao_dip, ao_quad
1550 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: aocg_spin, ao_dip_spin, ao_quad_spin, &
1551 ch_orb_spin, ch_shell_spin
1554 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s, matrix_p
1557 TYPE(error_type),
ALLOCATABLE :: error
1560 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1567 NULLIFY (particle_set, qs_kind_set, atomic_kind_set, scf_control)
1568 CALL get_qs_env(qs_env=qs_env, scf_env=scf_env, particle_set=particle_set, qs_kind_set=qs_kind_set, &
1569 atomic_kind_set=atomic_kind_set, matrix_s_kp=matrix_s, rho=rho, para_env=para_env, &
1570 scf_control=scf_control)
1574 do_quadrupole = .false.
1575 skip_scf_dispersion = .false.
1576#if defined(__TBLITE_DEBUG_DIAGNOSTICS)
1577 CALL get_environment_variable(
"CP2K_TBLITE_DEBUG_SKIP_SCF_DISPERSION", debug_value, status=debug_status)
1578 IF (debug_status == 0)
READ (debug_value, *, iostat=debug_status) skip_scf_dispersion
1580 skip_scf_dispersion_energy = skip_scf_dispersion
1581 skip_scf_dispersion_gradient = skip_scf_dispersion
1582 skip_scf_dispersion_potential = skip_scf_dispersion
1583#if defined(__TBLITE_DEBUG_DIAGNOSTICS)
1584 CALL get_environment_variable(
"CP2K_TBLITE_DEBUG_SKIP_SCF_DISPERSION_ENERGY", debug_value, status=debug_status)
1585 IF (debug_status == 0)
READ (debug_value, *, iostat=debug_status) skip_scf_dispersion_energy
1586 CALL get_environment_variable(
"CP2K_TBLITE_DEBUG_SKIP_SCF_DISPERSION_GRADIENT", debug_value, status=debug_status)
1587 IF (debug_status == 0)
READ (debug_value, *, iostat=debug_status) skip_scf_dispersion_gradient
1588 CALL get_environment_variable(
"CP2K_TBLITE_DEBUG_SKIP_SCF_DISPERSION_POTENTIAL", debug_value, status=debug_status)
1589 IF (debug_status == 0)
READ (debug_value, *) skip_scf_dispersion_potential
1591 IF (dft_control%qs_control%do_ls_scf .OR. scf_control%use_ot)
THEN
1592 use_native_mixer = .false.
1593 use_no_mixer = .true.
1595 SELECT CASE (dft_control%qs_control%xtb_control%tblite_scc_mixer)
1598 use_no_mixer = .false.
1600 use_native_mixer = .true.
1601 use_no_mixer = .false.
1603 use_native_mixer = .false.
1604 use_no_mixer = .false.
1606 use_native_mixer = .false.
1607 use_no_mixer = .true.
1609 cpabort(
"Unknown tblite SCC mixer")
1612 IF (use_native_mixer)
THEN
1613 IF (.NOT.
ASSOCIATED(scf_env)) cpabort(
"tblite SCC mixer requires a QS SCF environment")
1614 IF (use_rho .AND. (.NOT. calculate_forces))
THEN
1615 IF (scf_env%iter_count > dft_control%qs_control%xtb_control%tblite_mixer_iterations)
THEN
1616 cpabort(
"tblite SCC mixer exceeded TBLITE_MIXER/ITERATIONS")
1618 IF (scf_env%iter_count == 1)
THEN
1619 CALL tb_configure_mixer(tb, dft_control%qs_control%xtb_control%tblite_mixer_iterations, &
1620 dft_control%qs_control%xtb_control%tblite_mixer_memory, &
1621 dft_control%qs_control%xtb_control%tblite_mixer_damping, &
1622 dft_control%qs_control%xtb_control%tblite_mixer_omega0, &
1623 dft_control%qs_control%xtb_control%tblite_mixer_min_weight, &
1624 dft_control%qs_control%xtb_control%tblite_mixer_max_weight, &
1625 dft_control%qs_control%xtb_control%tblite_mixer_weight_factor, &
1626 dft_control%qs_control%xtb_control%tblite_mixer_solver)
1627 CALL tb_reset_mixer(tb)
1631 nspin = dft_control%nspins
1632 IF (nspin /= tb%wfn%nspin) cpabort(
"CP2K/tblite spin channel mismatch")
1637 ELSE IF (calculate_forces .AND. nspin > 1)
THEN
1638 IF (.NOT.
ASSOCIATED(tb%rho_ao_kp_ref))
THEN
1639 cpabort(
"Missing converged tblite density for UKS/LSD forces")
1641 matrix_p => tb%rho_ao_kp_ref
1643 matrix_p => scf_env%p_mix_new
1645 IF (nspin > 1 .AND. (.NOT. calculate_forces))
CALL tb_store_density_ref(tb, matrix_p)
1646 IF (
ASSOCIATED(tb%dipbra)) do_dipole = .true.
1647 IF (
ASSOCIATED(tb%quadbra)) do_quadrupole = .true.
1648 reuse_native_input = .false.
1649 IF (use_native_mixer)
THEN
1650 IF (scf_env%iter_count == 1)
THEN
1651 reuse_native_input = any(abs(tb%wfn%qsh) > 1.0e-14_dp)
1652 IF (do_dipole) reuse_native_input = reuse_native_input .OR. &
1653 any(abs(tb%wfn%dpat) > 1.0e-14_dp)
1654 IF (do_quadrupole) reuse_native_input = reuse_native_input .OR. &
1655 any(abs(tb%wfn%qpat) > 1.0e-14_dp)
1658 n_atom =
SIZE(particle_set)
1659 nkind =
SIZE(atomic_kind_set)
1660 nimg = dft_control%nimages
1662 ALLOCATE (aocg(nsgf, n_atom))
1663 ALLOCATE (aocg_spin(nsgf, n_atom, nspin))
1667 ALLOCATE (ao_dip(n_atom, dip_n))
1668 ALLOCATE (ao_dip_spin(n_atom, dip_n, nspin))
1669 ao_dip_spin = 0.0_dp
1671 IF (do_quadrupole)
THEN
1672 ALLOCATE (ao_quad(n_atom, quad_n))
1673 ALLOCATE (ao_quad_spin(n_atom, quad_n, nspin))
1674 ao_quad_spin = 0.0_dp
1679 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
1681 max_orb = max(max_orb, natorb)
1684 max_shell = max(max_shell, tb%calc%bas%nsh_at(is))
1686 ALLOCATE (ch_atom(n_atom, nspin), ch_shell(n_atom, max_shell))
1687 ALLOCATE (ch_orb(max_orb, n_atom), ch_ref(max_orb, n_atom))
1688 ALLOCATE (ch_orb_spin(max_orb, n_atom, nspin), ch_shell_spin(n_atom, max_shell, nspin))
1692 ch_orb_spin = 0.0_dp
1693 ch_shell_spin = 0.0_dp
1697 CALL tb_ao_charges_kp_spin(matrix_p, matrix_s, aocg_spin(:, :, ispin), ispin, para_env)
1700 CALL tb_contract_dens_kp_spin(matrix_p, tb%dipbra, tb%dipket, im, dip_n, &
1701 ao_dip_spin(:, im, ispin), ispin, para_env)
1704 IF (do_quadrupole)
THEN
1706 CALL tb_contract_dens_kp_spin(matrix_p, tb%quadbra, tb%quadket, im, quad_n, &
1707 ao_quad_spin(:, im, ispin), ispin, para_env)
1712 NULLIFY (p_matrix, s_matrix)
1713 p_matrix => matrix_p(:, 1)
1714 s_matrix => matrix_s(1, 1)%matrix
1716 CALL tb_ao_charges_matrix(matrix_p(ispin, 1)%matrix, s_matrix, aocg_spin(:, :, ispin), para_env)
1719 CALL tb_contract_dens_matrix(matrix_p(ispin, 1)%matrix, tb%dipbra(im)%matrix, &
1720 tb%dipket(im)%matrix, ao_dip_spin(:, im, ispin), para_env)
1723 IF (do_quadrupole)
THEN
1725 CALL tb_contract_dens_matrix(matrix_p(ispin, 1)%matrix, tb%quadbra(im)%matrix, &
1726 tb%quadket(im)%matrix, ao_quad_spin(:, im, ispin), para_env)
1731 IF (nspin == 1)
THEN
1732 aocg(:, :) = aocg_spin(:, :, 1)
1733 IF (do_dipole) ao_dip(:, :) = ao_dip_spin(:, :, 1)
1734 IF (do_quadrupole) ao_quad(:, :) = ao_quad_spin(:, :, 1)
1736 aocg(:, :) = aocg_spin(:, :, 1) + aocg_spin(:, :, 2)
1739 DO iatom = 1, n_atom
1740 pao = ao_dip_spin(iatom, im, 1)
1741 ao_dip_spin(iatom, im, 1) = pao + ao_dip_spin(iatom, im, 2)
1742 ao_dip_spin(iatom, im, 2) = pao - ao_dip_spin(iatom, im, 2)
1745 ao_dip(:, :) = ao_dip_spin(:, :, 1)
1747 IF (do_quadrupole)
THEN
1749 DO iatom = 1, n_atom
1750 pao = ao_quad_spin(iatom, im, 1)
1751 ao_quad_spin(iatom, im, 1) = pao + ao_quad_spin(iatom, im, 2)
1752 ao_quad_spin(iatom, im, 2) = pao - ao_quad_spin(iatom, im, 2)
1755 ao_quad(:, :) = ao_quad_spin(:, :, 1)
1761 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
1764 atom_a = atomic_kind_set(ikind)%atom_list(iatom)
1767 norm = 2*lao(is) + 1
1768 ch_ref(is, atom_a) = tb%calc%h0%refocc(nao(is), ikind)/norm
1769 ch_orb(is, atom_a) = aocg(is, atom_a) - ch_ref(is, atom_a)
1770 ch_orb_spin(is, atom_a, 1) = ch_orb(is, atom_a)
1771 IF (nspin == 2) ch_orb_spin(is, atom_a, 2) = &
1772 aocg_spin(is, atom_a, 1) - aocg_spin(is, atom_a, 2)
1773 ch_shell(atom_a, ns) = ch_orb(is, atom_a) + ch_shell(atom_a, ns)
1775 ch_shell_spin(atom_a, ns, ispin) = ch_orb_spin(is, atom_a, ispin) + &
1776 ch_shell_spin(atom_a, ns, ispin)
1780 ch_atom(atom_a, ispin) = sum(ch_orb_spin(:, atom_a, ispin))
1784 native_seed_charge = -sum(ch_atom(:, 1))
1785 seed_native_from_rho = sum(abs(aocg_spin)) > 1.0e-10_dp .AND. &
1786 abs(native_seed_charge - real(dft_control%charge,
dp)) < 1.0e-5_dp
1787 DEALLOCATE (aocg, aocg_spin)
1789 raw_state_status = 1
1790#if defined(__TBLITE_DEBUG_DIAGNOSTICS)
1791 CALL get_environment_variable(
"CP2K_TBLITE_RAW_STATE_DUMP", raw_state_file, status=raw_state_status)
1793 IF (raw_state_status == 0)
THEN
1794 OPEN (newunit=raw_state_unit, file=trim(raw_state_file), status=
"REPLACE", action=
"WRITE")
1795 WRITE (raw_state_unit, *)
"qat"
1796 DO iatom = 1, n_atom
1797 WRITE (raw_state_unit,
"(I0,1X,ES24.16)") iatom, -ch_atom(iatom, 1)
1799 WRITE (raw_state_unit, *)
"qsh"
1800 DO iatom = 1, n_atom
1801 DO is = 1, tb%calc%bas%nsh_at(iatom)
1802 WRITE (raw_state_unit,
"(I0,1X,ES24.16)") tb%calc%bas%ish_at(iatom) + is, -ch_shell(iatom, is)
1806 WRITE (raw_state_unit, *)
"dpat"
1807 DO iatom = 1, n_atom
1808 WRITE (raw_state_unit,
"(I0,3(1X,ES24.16))") iatom, -ao_dip(iatom, :)
1811 IF (do_quadrupole)
THEN
1812 WRITE (raw_state_unit, *)
"qpat"
1813 DO iatom = 1, n_atom
1814 WRITE (raw_state_unit,
"(I0,6(1X,ES24.16))") iatom, -ao_quad(iatom, :)
1817 CLOSE (raw_state_unit)
1820 IF (use_native_mixer)
THEN
1821 IF (.NOT.
ALLOCATED(tb%mixer)) cpabort(
"tblite mixer not initialized")
1822 advance_native_mixer = .false.
1823 IF (use_rho .AND. (.NOT. calculate_forces))
THEN
1824 advance_native_mixer = scf_env%iter_count > 1
1826 IF (advance_native_mixer)
THEN
1827 CALL tb%mixer%next(error)
1828 IF (
ALLOCATED(error)) cpabort(
"tblite native mixer failed")
1829 CALL tb%mixer%get(tb%wfn%qsh)
1830 tb%wfn%qat(:, :) = 0.0_dp
1831 DO iatom = 1, n_atom
1832 ii = tb%calc%bas%ish_at(iatom)
1834 tb%wfn%qat(iatom, ispin) = &
1835 sum(tb%wfn%qsh(ii + 1:ii + tb%calc%bas%nsh_at(iatom), ispin))
1839 CALL tb%mixer%get(tb%wfn%dpat)
1842 IF (do_quadrupole)
THEN
1843 CALL tb%mixer%get(tb%wfn%qpat)
1844 DEALLOCATE (ao_quad)
1847 IF (use_rho .AND. (.NOT. calculate_forces))
THEN
1848 IF (.NOT. reuse_native_input)
THEN
1849 IF (seed_native_from_rho)
THEN
1852 DO iatom = 1, n_atom
1853 ii = tb%calc%bas%ish_at(iatom)
1855 DO is = 1, tb%calc%bas%nsh_at(iatom)
1856 tb%wfn%qsh(ii + is, ispin) = -ch_shell_spin(iatom, is, ispin)
1858 tb%wfn%qat(iatom, ispin) = &
1859 sum(tb%wfn%qsh(ii + 1:ii + tb%calc%bas%nsh_at(iatom), ispin))
1863 DO iatom = 1, n_atom
1865 tb%wfn%dpat(:, iatom, ispin) = -ao_dip_spin(iatom, :, ispin)
1869 IF (do_quadrupole)
THEN
1870 DO iatom = 1, n_atom
1872 tb%wfn%qpat(:, iatom, ispin) = -ao_quad_spin(iatom, :, ispin)
1877 tb%wfn%qsh(:, :) = 0.0_dp
1878 tb%wfn%qat(:, :) = 0.0_dp
1879 IF (do_dipole) tb%wfn%dpat(:, :, :) = 0.0_dp
1880 IF (do_quadrupole) tb%wfn%qpat(:, :, :) = 0.0_dp
1883 IF (do_dipole)
DEALLOCATE (ao_dip)
1884 IF (do_quadrupole)
DEALLOCATE (ao_quad)
1886 IF ((.NOT. use_rho) .AND. (.NOT. calculate_forces))
THEN
1887 CALL tb%mixer%set(tb%wfn%qsh)
1888 IF (do_dipole)
CALL tb%mixer%set(tb%wfn%dpat)
1889 IF (do_quadrupole)
CALL tb%mixer%set(tb%wfn%qpat)
1891 DO iatom = 1, n_atom
1892 ii = tb%calc%bas%ish_at(iatom)
1894 DO is = 1, tb%calc%bas%nsh_at(iatom)
1895 tb%wfn%qsh(ii + is, ispin) = -ch_shell_spin(iatom, is, ispin)
1897 tb%wfn%qat(iatom, ispin) = &
1898 sum(tb%wfn%qsh(ii + 1:ii + tb%calc%bas%nsh_at(iatom), ispin))
1902 DO iatom = 1, n_atom
1904 tb%wfn%dpat(:, iatom, ispin) = -ao_dip_spin(iatom, :, ispin)
1909 IF (do_quadrupole)
THEN
1910 DO iatom = 1, n_atom
1912 tb%wfn%qpat(:, iatom, ispin) = -ao_quad_spin(iatom, :, ispin)
1915 DEALLOCATE (ao_quad)
1917 IF ((.NOT. use_rho) .AND. (.NOT. calculate_forces))
THEN
1918 CALL tb%mixer%diff(tb%wfn%qsh)
1919 IF (do_dipole)
CALL tb%mixer%diff(tb%wfn%dpat)
1920 IF (do_quadrupole)
CALL tb%mixer%diff(tb%wfn%qpat)
1926 native_sign_mixing = .false.
1927 IF (dft_control%qs_control%do_ls_scf .OR. scf_control%use_ot)
THEN
1931 ELSE IF (nspin > 1)
THEN
1932 n_mix_cols = nspin*max_shell
1933 IF (do_dipole) n_mix_cols = n_mix_cols + nspin*dip_n
1934 IF (do_quadrupole) n_mix_cols = n_mix_cols + nspin*quad_n
1935 ALLOCATE (mix_vars(n_atom, n_mix_cols))
1940 mix_vars(:, mix_offset + 1:mix_offset + max_shell) = &
1941 -ch_shell_spin(:, 1:max_shell, ispin)
1942 mix_offset = mix_offset + max_shell
1946 mix_vars(:, mix_offset + 1:mix_offset + dip_n) = &
1947 -ao_dip_spin(:, 1:dip_n, ispin)
1948 mix_offset = mix_offset + dip_n
1951 IF (do_quadrupole)
THEN
1953 mix_vars(:, mix_offset + 1:mix_offset + quad_n) = &
1954 -ao_quad_spin(:, 1:quad_n, ispin)
1955 mix_offset = mix_offset + quad_n
1959 IF (.NOT. use_no_mixer)
THEN
1960 CALL charge_mixing(scf_env%mixing_method, scf_env%mixing_store, &
1961 mix_vars, para_env, scf_env%iter_count)
1966 ch_shell_spin(:, 1:max_shell, ispin) = &
1967 -mix_vars(:, mix_offset + 1:mix_offset + max_shell)
1968 mix_offset = mix_offset + max_shell
1970 ch_shell(:, 1:max_shell) = ch_shell_spin(:, 1:max_shell, 1)
1973 ao_dip_spin(:, 1:dip_n, ispin) = &
1974 -mix_vars(:, mix_offset + 1:mix_offset + dip_n)
1975 mix_offset = mix_offset + dip_n
1977 ao_dip(:, 1:dip_n) = ao_dip_spin(:, 1:dip_n, 1)
1979 IF (do_quadrupole)
THEN
1981 ao_quad_spin(:, 1:quad_n, ispin) = &
1982 -mix_vars(:, mix_offset + 1:mix_offset + quad_n)
1983 mix_offset = mix_offset + quad_n
1985 ao_quad(:, 1:quad_n) = ao_quad_spin(:, 1:quad_n, 1)
1987 DEALLOCATE (mix_vars)
1989 do_combined_mixing = do_dipole .OR. do_quadrupole
1990 native_sign_mixing = do_dipole .OR. do_quadrupole
1991 discard_mixed_output = .false.
1992 skip_charge_mixing = use_no_mixer
1993 IF (skip_charge_mixing)
THEN
1995 ELSE IF (do_combined_mixing)
THEN
1996 n_mix_cols = max_shell
1997 IF (do_dipole) n_mix_cols = n_mix_cols + dip_n
1998 IF (do_quadrupole) n_mix_cols = n_mix_cols + quad_n
1999 ALLOCATE (mix_vars(n_atom, n_mix_cols))
2000 IF (native_sign_mixing)
THEN
2001 mix_vars(:, 1:max_shell) = -ch_shell(:, 1:max_shell)
2003 mix_vars(:, 1:max_shell) = ch_shell(:, 1:max_shell)
2005 mix_offset = max_shell
2007 IF (native_sign_mixing)
THEN
2008 mix_vars(:, mix_offset + 1:mix_offset + dip_n) = -ao_dip(:, 1:dip_n)
2010 mix_vars(:, mix_offset + 1:mix_offset + dip_n) = ao_dip(:, 1:dip_n)
2012 mix_offset = mix_offset + dip_n
2014 IF (do_quadrupole)
THEN
2015 IF (native_sign_mixing)
THEN
2016 mix_vars(:, mix_offset + 1:mix_offset + quad_n) = -ao_quad(:, 1:quad_n)
2018 mix_vars(:, mix_offset + 1:mix_offset + quad_n) = ao_quad(:, 1:quad_n)
2021 CALL charge_mixing(scf_env%mixing_method, scf_env%mixing_store, &
2022 mix_vars, para_env, scf_env%iter_count)
2023 IF (.NOT. discard_mixed_output)
THEN
2024 IF (native_sign_mixing)
THEN
2025 ch_shell(:, 1:max_shell) = -mix_vars(:, 1:max_shell)
2027 ch_shell(:, 1:max_shell) = mix_vars(:, 1:max_shell)
2029 mix_offset = max_shell
2031 IF (native_sign_mixing)
THEN
2032 ao_dip(:, 1:dip_n) = -mix_vars(:, mix_offset + 1:mix_offset + dip_n)
2034 ao_dip(:, 1:dip_n) = mix_vars(:, mix_offset + 1:mix_offset + dip_n)
2036 mix_offset = mix_offset + dip_n
2038 IF (do_quadrupole)
THEN
2039 IF (native_sign_mixing)
THEN
2040 ao_quad(:, 1:quad_n) = -mix_vars(:, mix_offset + 1:mix_offset + quad_n)
2042 ao_quad(:, 1:quad_n) = mix_vars(:, mix_offset + 1:mix_offset + quad_n)
2046 DEALLOCATE (mix_vars)
2048 CALL charge_mixing(scf_env%mixing_method, scf_env%mixing_store, &
2049 ch_shell, para_env, scf_env%iter_count)
2058 DO iatom = 1, n_atom
2059 ii = tb%calc%bas%ish_at(iatom)
2061 DO is = 1, tb%calc%bas%nsh_at(iatom)
2062 tb%wfn%qsh(ii + is, ispin) = -ch_shell_spin(iatom, is, ispin)
2064 tb%wfn%qat(iatom, ispin) = &
2065 sum(tb%wfn%qsh(ii + 1:ii + tb%calc%bas%nsh_at(iatom), ispin))
2069 DO iatom = 1, n_atom
2071 tb%wfn%dpat(:, iatom, ispin) = -ao_dip_spin(iatom, :, ispin)
2076 IF (do_quadrupole)
THEN
2077 DO iatom = 1, n_atom
2079 tb%wfn%qpat(:, iatom, ispin) = -ao_quad_spin(iatom, :, ispin)
2082 DEALLOCATE (ao_quad)
2085 DO iatom = 1, n_atom
2086 ii = tb%calc%bas%ish_at(iatom)
2087 DO is = 1, tb%calc%bas%nsh_at(iatom)
2088 new_charge = -ch_shell(iatom, is)
2089 tb%wfn%qsh(ii + is, 1) = new_charge
2091 IF (native_sign_mixing)
THEN
2092 tb%wfn%qat(iatom, 1) = sum(tb%wfn%qsh(ii + 1:ii + tb%calc%bas%nsh_at(iatom), 1))
2094 tb%wfn%qat(iatom, 1) = -ch_atom(iatom, 1)
2099 DO iatom = 1, n_atom
2101 tb%wfn%dpat(im, iatom, 1) = -ao_dip(iatom, im)
2106 IF (do_quadrupole)
THEN
2107 DO iatom = 1, n_atom
2109 tb%wfn%qpat(im, iatom, 1) = -ao_quad(iatom, im)
2112 DEALLOCATE (ao_quad)
2121 IF (
ALLOCATED(tb%calc%coulomb))
THEN
2122 CALL tb%calc%coulomb%get_potential(tb%mol, tb%cache, tb%wfn, tb%pot)
2123 CALL tb%calc%coulomb%get_energy(tb%mol, tb%cache, tb%wfn, tb%e_es)
2125 IF (
ALLOCATED(tb%calc%dispersion))
THEN
2126 IF (.NOT. skip_scf_dispersion_potential)
THEN
2127 CALL tb%calc%dispersion%get_potential(tb%mol, tb%dcache, tb%wfn, tb%pot)
2129 IF (.NOT. skip_scf_dispersion_energy)
THEN
2130 CALL tb%calc%dispersion%get_energy(tb%mol, tb%dcache, tb%wfn, tb%e_scd)
2133 IF (
ALLOCATED(tb%calc%interactions))
THEN
2134 CALL tb%calc%interactions%get_potential(tb%mol, tb%icache, tb%wfn, tb%pot)
2135 CALL tb%calc%interactions%get_energy(tb%mol, tb%icache, tb%wfn, tb%e_int)
2138 IF (calculate_forces)
THEN
2139 IF (
ALLOCATED(tb%calc%coulomb))
THEN
2141 CALL tb%calc%coulomb%get_gradient(tb%mol, tb%cache, tb%wfn, tb%grad, tb%sigma)
2142 CALL tb_dump_sigma_component(
"after_coulomb", tb%sigma, para_env)
2143 CALL tb_grad2force(qs_env, tb, para_env, 3)
2146 IF (
ALLOCATED(tb%calc%dispersion) .AND. .NOT. skip_scf_dispersion_gradient)
THEN
2148 CALL tb%calc%dispersion%get_gradient(tb%mol, tb%dcache, tb%wfn, tb%grad, tb%sigma)
2149 CALL tb_dump_sigma_component(
"after_dispersion_scf", tb%sigma, para_env)
2150 CALL tb_grad2force(qs_env, tb, para_env, 2)
2153 IF (
ALLOCATED(tb%calc%interactions))
THEN
2155 CALL tb%calc%interactions%get_gradient(tb%mol, tb%icache, tb%wfn, tb%grad, tb%sigma)
2156 CALL tb_dump_sigma_component(
"after_interactions_scf", tb%sigma, para_env)
2157 CALL tb_grad2force(qs_env, tb, para_env, 3)
2161 IF (
ALLOCATED(ao_dip_spin))
DEALLOCATE (ao_dip_spin)
2162 IF (
ALLOCATED(ao_quad_spin))
DEALLOCATE (ao_quad_spin)
2163 DEALLOCATE (ch_atom, ch_shell, ch_orb, ch_ref, ch_orb_spin, ch_shell_spin)
2168 mark_used(dft_control)
2169 mark_used(calculate_forces)
2171 cpabort(
"Built without TBLITE")
2188#if defined(__TBLITE)
2190 INTEGER :: ikind, jkind, iatom, jatom, icol, irow
2191 INTEGER :: ic, id1, id2, id3, iq1, iq2, iq3, iq4, iq5, iq6, &
2192 is, nimg, ni, nj, i, j, nspin
2193 INTEGER :: la, lb, za, zb
2195 INTEGER,
DIMENSION(3) :: cellind
2196 INTEGER,
DIMENSION(25) :: naoa, naob
2197 REAL(kind=
dp),
DIMENSION(3) :: rij
2198 REAL(kind=
dp) :: mpfac
2199#if defined(__TBLITE_DEBUG_DIAGNOSTICS)
2200 INTEGER :: debug_status
2201 CHARACTER(LEN=32) :: debug_value
2203 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: kind_of, sum_shell
2204 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ashift, bshift
2205 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: ksblock, sblock
2206 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2207 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: dip_ket1, dip_ket2, dip_ket3, &
2208 dip_bra1, dip_bra2, dip_bra3
2209 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: quad_ket1, quad_ket2, quad_ket3, &
2210 quad_ket4, quad_ket5, quad_ket6, &
2211 quad_bra1, quad_bra2, quad_bra3, &
2212 quad_bra4, quad_bra5, quad_bra6
2216 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
2217 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ks_matrix
2220 DIMENSION(:),
POINTER :: nl_iterator
2225 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2228 nimg = dft_control%nimages
2231 NULLIFY (matrix_s, ks_matrix, n_list, kp_list, qs_kind_set)
2232 CALL get_qs_env(qs_env=qs_env, sab_orb=n_list, sab_kp=kp_list, &
2233 matrix_s_kp=matrix_s, matrix_ks_kp=ks_matrix, qs_kind_set=qs_kind_set)
2235 IF (.NOT.
ASSOCIATED(kp_list)) cpabort(
"Missing k-point neighbor list for tblite Hamiltonian")
2238 nspin =
SIZE(ks_matrix, 1)
2241 ALLOCATE (sum_shell(tb%mol%nat))
2243 DO j = 1, tb%mol%nat
2245 i = i + tb%calc%bas%nsh_at(j)
2250 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set)
2257 ikind = kind_of(irow)
2258 jkind = kind_of(icol)
2261 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
2262 CALL get_qs_kind(qs_kind_set(jkind), xtb_parameter=xtb_atom_b)
2266 ni =
SIZE(sblock, 1)
2267 ALLOCATE (ashift(ni, ni))
2269 nj =
SIZE(sblock, 2)
2270 ALLOCATE (bshift(nj, nj))
2275 la = naoa(i) + sum_shell(irow)
2276 ashift(i, i) = tb_spin_project(tb%pot%vsh(la, :), is)
2280 lb = naob(j) + sum_shell(icol)
2281 bshift(j, j) = tb_spin_project(tb%pot%vsh(lb, :), is)
2285 row=irow, col=icol, block=ksblock, found=found)
2287 ksblock = ksblock - 0.5_dp*(matmul(ashift, sblock) &
2288 + matmul(sblock, bshift))
2289 ksblock = ksblock - 0.5_dp*(tb_spin_project(tb%pot%vat(irow, :), is) &
2290 + tb_spin_project(tb%pot%vat(icol, :), is))*sblock
2292 DEALLOCATE (ashift, bshift)
2296 IF (
ASSOCIATED(tb%dipbra))
THEN
2301 NULLIFY (dip_bra1, dip_bra2, dip_bra3)
2303 row=irow, col=icol, block=dip_bra1, found=found)
2306 row=irow, col=icol, block=dip_bra2, found=found)
2309 row=irow, col=icol, block=dip_bra3, found=found)
2311 NULLIFY (dip_ket1, dip_ket2, dip_ket3)
2313 row=irow, col=icol, block=dip_ket1, found=found)
2316 row=irow, col=icol, block=dip_ket2, found=found)
2319 row=irow, col=icol, block=dip_ket3, found=found)
2325 row=irow, col=icol, block=ksblock, found=found)
2327 ksblock = ksblock + mpfac*(dip_ket1*tb_spin_project(tb%pot%vdp(1, irow, :), is) &
2328 + dip_ket2*tb_spin_project(tb%pot%vdp(2, irow, :), is) &
2329 + dip_ket3*tb_spin_project(tb%pot%vdp(3, irow, :), is) &
2330 + dip_bra1*tb_spin_project(tb%pot%vdp(1, icol, :), is) &
2331 + dip_bra2*tb_spin_project(tb%pot%vdp(2, icol, :), is) &
2332 + dip_bra3*tb_spin_project(tb%pot%vdp(3, icol, :), is))
2338 IF (
ASSOCIATED(tb%quadbra))
THEN
2343 NULLIFY (quad_bra1, quad_bra2, quad_bra3, quad_bra4, quad_bra5, quad_bra6)
2345 row=irow, col=icol, block=quad_bra1, found=found)
2348 row=irow, col=icol, block=quad_bra2, found=found)
2351 row=irow, col=icol, block=quad_bra3, found=found)
2354 row=irow, col=icol, block=quad_bra4, found=found)
2357 row=irow, col=icol, block=quad_bra5, found=found)
2360 row=irow, col=icol, block=quad_bra6, found=found)
2363 NULLIFY (quad_ket1, quad_ket2, quad_ket3, quad_ket4, quad_ket5, quad_ket6)
2365 row=irow, col=icol, block=quad_ket1, found=found)
2368 row=irow, col=icol, block=quad_ket2, found=found)
2371 row=irow, col=icol, block=quad_ket3, found=found)
2374 row=irow, col=icol, block=quad_ket4, found=found)
2377 row=irow, col=icol, block=quad_ket5, found=found)
2380 row=irow, col=icol, block=quad_ket6, found=found)
2386 row=irow, col=icol, block=ksblock, found=found)
2389 ksblock = ksblock + mpfac*(quad_ket1*tb_spin_project(tb%pot%vqp(1, irow, :), is) &
2390 + quad_ket2*tb_spin_project(tb%pot%vqp(2, irow, :), is) &
2391 + quad_ket3*tb_spin_project(tb%pot%vqp(3, irow, :), is) &
2392 + quad_ket4*tb_spin_project(tb%pot%vqp(4, irow, :), is) &
2393 + quad_ket5*tb_spin_project(tb%pot%vqp(5, irow, :), is) &
2394 + quad_ket6*tb_spin_project(tb%pot%vqp(6, irow, :), is) &
2395 + quad_bra1*tb_spin_project(tb%pot%vqp(1, icol, :), is) &
2396 + quad_bra2*tb_spin_project(tb%pot%vqp(2, icol, :), is) &
2397 + quad_bra3*tb_spin_project(tb%pot%vqp(3, icol, :), is) &
2398 + quad_bra4*tb_spin_project(tb%pot%vqp(4, icol, :), is) &
2399 + quad_bra5*tb_spin_project(tb%pot%vqp(5, icol, :), is) &
2400 + quad_bra6*tb_spin_project(tb%pot%vqp(6, icol, :), is))
2408 CALL get_qs_env(qs_env=qs_env, kpoints=kpoints)
2409 NULLIFY (cell_to_index)
2412 NULLIFY (nl_iterator)
2416 iatom=iatom, jatom=jatom, r=rij, cell=cellind)
2418 icol = max(iatom, jatom)
2419 irow = min(iatom, jatom)
2421 IF (iatom > jatom)
THEN
2427 ic = cell_to_index(cellind(1), cellind(2), cellind(3))
2432 row=irow, col=icol, block=sblock, found=found)
2436 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
2437 CALL get_qs_kind(qs_kind_set(jkind), xtb_parameter=xtb_atom_b)
2441 ni =
SIZE(sblock, 1)
2442 ALLOCATE (ashift(ni, ni))
2444 nj =
SIZE(sblock, 2)
2445 ALLOCATE (bshift(nj, nj))
2450 la = naoa(i) + sum_shell(irow)
2451 ashift(i, i) = tb_spin_project(tb%pot%vsh(la, :), is)
2455 lb = naob(j) + sum_shell(icol)
2456 bshift(j, j) = tb_spin_project(tb%pot%vsh(lb, :), is)
2460 row=irow, col=icol, block=ksblock, found=found)
2462 ksblock = ksblock - 0.5_dp*(matmul(ashift, sblock) &
2463 + matmul(sblock, bshift))
2464 ksblock = ksblock - 0.5_dp*(tb_spin_project(tb%pot%vat(irow, :), is) &
2465 + tb_spin_project(tb%pot%vat(icol, :), is))*sblock
2467 DEALLOCATE (ashift, bshift)
2471 IF (
ASSOCIATED(tb%dipbra))
THEN
2472 NULLIFY (nl_iterator)
2476 iatom=iatom, jatom=jatom, cell=cellind)
2477 icol = max(iatom, jatom)
2478 irow = min(iatom, jatom)
2479 ic = cell_to_index(cellind(1), cellind(2), cellind(3))
2481 id1 = 1 + dip_n*(ic - 1)
2482 id2 = 2 + dip_n*(ic - 1)
2483 id3 = 3 + dip_n*(ic - 1)
2485 NULLIFY (dip_bra1, dip_bra2, dip_bra3)
2487 row=irow, col=icol, block=dip_bra1, found=found)
2490 row=irow, col=icol, block=dip_bra2, found=found)
2493 row=irow, col=icol, block=dip_bra3, found=found)
2495 NULLIFY (dip_ket1, dip_ket2, dip_ket3)
2497 row=irow, col=icol, block=dip_ket1, found=found)
2500 row=irow, col=icol, block=dip_ket2, found=found)
2503 row=irow, col=icol, block=dip_ket3, found=found)
2509 row=irow, col=icol, block=ksblock, found=found)
2511 ksblock = ksblock + mpfac*(dip_ket1*tb_spin_project(tb%pot%vdp(1, irow, :), is) &
2512 + dip_ket2*tb_spin_project(tb%pot%vdp(2, irow, :), is) &
2513 + dip_ket3*tb_spin_project(tb%pot%vdp(3, irow, :), is) &
2514 + dip_bra1*tb_spin_project(tb%pot%vdp(1, icol, :), is) &
2515 + dip_bra2*tb_spin_project(tb%pot%vdp(2, icol, :), is) &
2516 + dip_bra3*tb_spin_project(tb%pot%vdp(3, icol, :), is))
2522 IF (
ASSOCIATED(tb%quadbra))
THEN
2523 NULLIFY (nl_iterator)
2527 iatom=iatom, jatom=jatom, cell=cellind)
2528 icol = max(iatom, jatom)
2529 irow = min(iatom, jatom)
2530 ic = cell_to_index(cellind(1), cellind(2), cellind(3))
2532 iq1 = 1 + quad_n*(ic - 1)
2533 iq2 = 2 + quad_n*(ic - 1)
2534 iq3 = 3 + quad_n*(ic - 1)
2535 iq4 = 4 + quad_n*(ic - 1)
2536 iq5 = 5 + quad_n*(ic - 1)
2537 iq6 = 6 + quad_n*(ic - 1)
2539 NULLIFY (quad_bra1, quad_bra2, quad_bra3, quad_bra4, quad_bra5, quad_bra6)
2541 row=irow, col=icol, block=quad_bra1, found=found)
2544 row=irow, col=icol, block=quad_bra2, found=found)
2547 row=irow, col=icol, block=quad_bra3, found=found)
2550 row=irow, col=icol, block=quad_bra4, found=found)
2553 row=irow, col=icol, block=quad_bra5, found=found)
2556 row=irow, col=icol, block=quad_bra6, found=found)
2559 NULLIFY (quad_ket1, quad_ket2, quad_ket3, quad_ket4, quad_ket5, quad_ket6)
2561 row=irow, col=icol, block=quad_ket1, found=found)
2564 row=irow, col=icol, block=quad_ket2, found=found)
2567 row=irow, col=icol, block=quad_ket3, found=found)
2570 row=irow, col=icol, block=quad_ket4, found=found)
2573 row=irow, col=icol, block=quad_ket5, found=found)
2576 row=irow, col=icol, block=quad_ket6, found=found)
2582 row=irow, col=icol, block=ksblock, found=found)
2585 ksblock = ksblock + mpfac*(quad_ket1*tb_spin_project(tb%pot%vqp(1, irow, :), is) &
2586 + quad_ket2*tb_spin_project(tb%pot%vqp(2, irow, :), is) &
2587 + quad_ket3*tb_spin_project(tb%pot%vqp(3, irow, :), is) &
2588 + quad_ket4*tb_spin_project(tb%pot%vqp(4, irow, :), is) &
2589 + quad_ket5*tb_spin_project(tb%pot%vqp(5, irow, :), is) &
2590 + quad_ket6*tb_spin_project(tb%pot%vqp(6, irow, :), is) &
2591 + quad_bra1*tb_spin_project(tb%pot%vqp(1, icol, :), is) &
2592 + quad_bra2*tb_spin_project(tb%pot%vqp(2, icol, :), is) &
2593 + quad_bra3*tb_spin_project(tb%pot%vqp(3, icol, :), is) &
2594 + quad_bra4*tb_spin_project(tb%pot%vqp(4, icol, :), is) &
2595 + quad_bra5*tb_spin_project(tb%pot%vqp(5, icol, :), is) &
2596 + quad_bra6*tb_spin_project(tb%pot%vqp(6, icol, :), is))
2607 mark_used(dft_control)
2608 cpabort(
"Built without TBLITE")
2623#if defined(__TBLITE)
2625 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tb_get_multipole'
2627 INTEGER :: ikind, jkind, iatom, jatom, icol, irow, iset, jset, ityp, jtyp
2628 INTEGER :: ic,
idx, id1, id2, id3, img, iq1, iq2, iq3, iq4, iq5, iq6
2629 INTEGER :: nkind, natom, handle, nimg, i, inda, indb
2630 INTEGER :: atom_a, atom_b, nseta, nsetb, ia, ib, ij
2633 INTEGER,
DIMENSION(3) :: cell
2634 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2635 REAL(kind=
dp),
DIMENSION(3) :: rij
2636 INTEGER,
DIMENSION(:),
POINTER :: la_max, lb_max
2637 INTEGER,
DIMENSION(:),
POINTER :: nsgfa, nsgfb
2638 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
2639 INTEGER,
ALLOCATABLE :: atom_of_kind(:)
2640 REAL(kind=
dp),
ALLOCATABLE :: stmp(:)
2641 REAL(kind=
dp),
ALLOCATABLE :: dtmp(:, :), qtmp(:, :), dtmpj(:, :), qtmpj(:, :)
2642 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: dip_ket1, dip_ket2, dip_ket3, &
2643 dip_bra1, dip_bra2, dip_bra3
2644 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: quad_ket1, quad_ket2, quad_ket3, &
2645 quad_ket4, quad_ket5, quad_ket6, &
2646 quad_bra1, quad_bra2, quad_bra3, &
2647 quad_bra4, quad_bra5, quad_bra6
2650 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
2658 DIMENSION(:),
POINTER :: nl_iterator
2660 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2662 CALL timeset(routinen, handle)
2665 NULLIFY (atomic_kind_set, qs_kind_set, sab_orb, sab_kp, particle_set)
2666 NULLIFY (dft_control, matrix_s, kpoints, cell_to_index)
2667 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, &
2668 qs_kind_set=qs_kind_set, &
2671 particle_set=particle_set, &
2672 dft_control=dft_control, &
2674 matrix_s_kp=matrix_s)
2675 natom =
SIZE(particle_set)
2676 nkind =
SIZE(atomic_kind_set)
2677 nimg = dft_control%nimages
2679 IF (.NOT.
ASSOCIATED(sab_kp)) cpabort(
"Missing k-point neighbor list for tblite multipoles")
2687 ALLOCATE (basis_set_list(nkind))
2690 ALLOCATE (stmp(msao(tb%calc%bas%maxl)**2))
2691 ALLOCATE (dtmp(dip_n, msao(tb%calc%bas%maxl)**2))
2692 ALLOCATE (qtmp(quad_n, msao(tb%calc%bas%maxl)**2))
2693 ALLOCATE (dtmpj(dip_n, msao(tb%calc%bas%maxl)**2))
2694 ALLOCATE (qtmpj(quad_n, msao(tb%calc%bas%maxl)**2))
2703 idx = i + dip_n*(img - 1)
2704 ALLOCATE (tb%dipbra(
idx)%matrix)
2705 ALLOCATE (tb%dipket(
idx)%matrix)
2706 CALL dbcsr_create(tb%dipbra(
idx)%matrix, template=matrix_s(1, img)%matrix, &
2707 name=
"DIPOLE BRAMATRIX")
2708 CALL dbcsr_create(tb%dipket(
idx)%matrix, template=matrix_s(1, img)%matrix, &
2709 name=
"DIPOLE KETMATRIX")
2714 idx = i + quad_n*(img - 1)
2715 ALLOCATE (tb%quadbra(
idx)%matrix)
2716 ALLOCATE (tb%quadket(
idx)%matrix)
2717 CALL dbcsr_create(tb%quadbra(
idx)%matrix, template=matrix_s(1, img)%matrix, &
2718 name=
"QUADRUPOLE BRAMATRIX")
2719 CALL dbcsr_create(tb%quadket(
idx)%matrix, template=matrix_s(1, img)%matrix, &
2720 name=
"QUADRUPOLE KETMATRIX")
2727 NULLIFY (nl_iterator)
2731 iatom=iatom, jatom=jatom, r=rij, cell=cell)
2733 r2 = norm2(rij(:))**2
2735 icol = max(iatom, jatom)
2736 irow = min(iatom, jatom)
2738 IF (iatom < jatom)
THEN
2748 ic = cell_to_index(cell(1), cell(2), cell(3))
2751 id1 = 1 + dip_n*(ic - 1)
2752 id2 = 2 + dip_n*(ic - 1)
2753 id3 = 3 + dip_n*(ic - 1)
2754 iq1 = 1 + quad_n*(ic - 1)
2755 iq2 = 2 + quad_n*(ic - 1)
2756 iq3 = 3 + quad_n*(ic - 1)
2757 iq4 = 4 + quad_n*(ic - 1)
2758 iq5 = 5 + quad_n*(ic - 1)
2759 iq6 = 6 + quad_n*(ic - 1)
2761 ityp = tb%mol%id(icol)
2762 jtyp = tb%mol%id(irow)
2764 NULLIFY (dip_bra1, dip_bra2, dip_bra3)
2766 row=irow, col=icol, block=dip_bra1, found=found)
2769 row=irow, col=icol, block=dip_bra2, found=found)
2772 row=irow, col=icol, block=dip_bra3, found=found)
2775 NULLIFY (dip_ket1, dip_ket2, dip_ket3)
2777 row=irow, col=icol, block=dip_ket1, found=found)
2780 row=irow, col=icol, block=dip_ket2, found=found)
2783 row=irow, col=icol, block=dip_ket3, found=found)
2786 NULLIFY (quad_bra1, quad_bra2, quad_bra3, quad_bra4, quad_bra5, quad_bra6)
2788 row=irow, col=icol, block=quad_bra1, found=found)
2791 row=irow, col=icol, block=quad_bra2, found=found)
2794 row=irow, col=icol, block=quad_bra3, found=found)
2797 row=irow, col=icol, block=quad_bra4, found=found)
2800 row=irow, col=icol, block=quad_bra5, found=found)
2803 row=irow, col=icol, block=quad_bra6, found=found)
2806 NULLIFY (quad_ket1, quad_ket2, quad_ket3, quad_ket4, quad_ket5, quad_ket6)
2808 row=irow, col=icol, block=quad_ket1, found=found)
2811 row=irow, col=icol, block=quad_ket2, found=found)
2814 row=irow, col=icol, block=quad_ket3, found=found)
2817 row=irow, col=icol, block=quad_ket4, found=found)
2820 row=irow, col=icol, block=quad_ket5, found=found)
2823 row=irow, col=icol, block=quad_ket6, found=found)
2827 basis_set_a => basis_set_list(ikind)%gto_basis_set
2828 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
2829 basis_set_b => basis_set_list(jkind)%gto_basis_set
2830 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
2831 atom_a = atom_of_kind(icol)
2832 atom_b = atom_of_kind(irow)
2834 first_sgfa => basis_set_a%first_sgf
2835 la_max => basis_set_a%lmax
2836 nseta = basis_set_a%nset
2837 nsgfa => basis_set_a%nsgf_set
2839 first_sgfb => basis_set_b%first_sgf
2840 lb_max => basis_set_b%lmax
2841 nsetb = basis_set_b%nset
2842 nsgfb => basis_set_b%nsgf_set
2846 IF (icol == irow .AND. r2 < same_atom**2)
THEN
2849 CALL multipole_cgto(tb%calc%bas%cgto(jset, ityp), tb%calc%bas%cgto(iset, ityp), &
2850 & r2, -rij, tb%calc%bas%intcut, stmp, dtmp, qtmp)
2852 DO inda = 1, nsgfa(iset)
2853 ia = first_sgfa(1, iset) - first_sgfa(1, 1) + inda
2854 DO indb = 1, nsgfb(jset)
2855 ib = first_sgfb(1, jset) - first_sgfb(1, 1) + indb
2856 ij = indb + nsgfb(jset)*(inda - 1)
2858 dip_ket1(ib, ia) = dip_ket1(ib, ia) + dtmp(1, ij)
2859 dip_ket2(ib, ia) = dip_ket2(ib, ia) + dtmp(2, ij)
2860 dip_ket3(ib, ia) = dip_ket3(ib, ia) + dtmp(3, ij)
2862 quad_ket1(ib, ia) = quad_ket1(ib, ia) + qtmp(1, ij)
2863 quad_ket2(ib, ia) = quad_ket2(ib, ia) + qtmp(2, ij)
2864 quad_ket3(ib, ia) = quad_ket3(ib, ia) + qtmp(3, ij)
2865 quad_ket4(ib, ia) = quad_ket4(ib, ia) + qtmp(4, ij)
2866 quad_ket5(ib, ia) = quad_ket5(ib, ia) + qtmp(5, ij)
2867 quad_ket6(ib, ia) = quad_ket6(ib, ia) + qtmp(6, ij)
2869 dip_bra1(ib, ia) = dip_bra1(ib, ia) + dtmp(1, ij)
2870 dip_bra2(ib, ia) = dip_bra2(ib, ia) + dtmp(2, ij)
2871 dip_bra3(ib, ia) = dip_bra3(ib, ia) + dtmp(3, ij)
2873 quad_bra1(ib, ia) = quad_bra1(ib, ia) + qtmp(1, ij)
2874 quad_bra2(ib, ia) = quad_bra2(ib, ia) + qtmp(2, ij)
2875 quad_bra3(ib, ia) = quad_bra3(ib, ia) + qtmp(3, ij)
2876 quad_bra4(ib, ia) = quad_bra4(ib, ia) + qtmp(4, ij)
2877 quad_bra5(ib, ia) = quad_bra5(ib, ia) + qtmp(5, ij)
2878 quad_bra6(ib, ia) = quad_bra6(ib, ia) + qtmp(6, ij)
2886 CALL multipole_cgto(tb%calc%bas%cgto(jset, jtyp), tb%calc%bas%cgto(iset, ityp), &
2887 & r2, -rij, tb%calc%bas%intcut, stmp, dtmp, qtmp)
2889 DO inda = 1, nsgfa(iset)
2890 ia = first_sgfa(1, iset) - first_sgfa(1, 1) + inda
2891 DO indb = 1, nsgfb(jset)
2892 ib = first_sgfb(1, jset) - first_sgfb(1, 1) + indb
2894 ij = indb + nsgfb(jset)*(inda - 1)
2895 CALL tb_shift_multipole(-rij, stmp(ij), dtmp(:, ij), qtmp(:, ij), &
2896 dtmpj(:, ij), qtmpj(:, ij))
2898 dip_bra1(ib, ia) = dip_bra1(ib, ia) + dtmp(1, ij)
2899 dip_bra2(ib, ia) = dip_bra2(ib, ia) + dtmp(2, ij)
2900 dip_bra3(ib, ia) = dip_bra3(ib, ia) + dtmp(3, ij)
2902 quad_bra1(ib, ia) = quad_bra1(ib, ia) + qtmp(1, ij)
2903 quad_bra2(ib, ia) = quad_bra2(ib, ia) + qtmp(2, ij)
2904 quad_bra3(ib, ia) = quad_bra3(ib, ia) + qtmp(3, ij)
2905 quad_bra4(ib, ia) = quad_bra4(ib, ia) + qtmp(4, ij)
2906 quad_bra5(ib, ia) = quad_bra5(ib, ia) + qtmp(5, ij)
2907 quad_bra6(ib, ia) = quad_bra6(ib, ia) + qtmp(6, ij)
2909 dip_ket1(ib, ia) = dip_ket1(ib, ia) + dtmpj(1, ij)
2910 dip_ket2(ib, ia) = dip_ket2(ib, ia) + dtmpj(2, ij)
2911 dip_ket3(ib, ia) = dip_ket3(ib, ia) + dtmpj(3, ij)
2913 quad_ket1(ib, ia) = quad_ket1(ib, ia) + qtmpj(1, ij)
2914 quad_ket2(ib, ia) = quad_ket2(ib, ia) + qtmpj(2, ij)
2915 quad_ket3(ib, ia) = quad_ket3(ib, ia) + qtmpj(3, ij)
2916 quad_ket4(ib, ia) = quad_ket4(ib, ia) + qtmpj(4, ij)
2917 quad_ket5(ib, ia) = quad_ket5(ib, ia) + qtmpj(5, ij)
2918 quad_ket6(ib, ia) = quad_ket6(ib, ia) + qtmpj(6, ij)
2927 DO i = 1,
SIZE(tb%dipbra)
2931 DO i = 1,
SIZE(tb%quadbra)
2936 DEALLOCATE (basis_set_list)
2938 CALL timestop(handle)
2943 cpabort(
"Built without TBLITE")
2957 PURE SUBROUTINE tb_shift_multipole(vec, s, di, qi, dj, qj)
2959 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: vec
2960 REAL(kind=
dp),
INTENT(IN) :: s
2961 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: di, qi
2962 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: dj, qj
2966 dj(1) = di(1) + vec(1)*s
2967 dj(2) = di(2) + vec(2)*s
2968 dj(3) = di(3) + vec(3)*s
2970 qj(1) = 2*vec(1)*di(1) + vec(1)**2*s
2971 qj(3) = 2*vec(2)*di(2) + vec(2)**2*s
2972 qj(6) = 2*vec(3)*di(3) + vec(3)**2*s
2973 qj(2) = vec(1)*di(2) + vec(2)*di(1) + vec(1)*vec(2)*s
2974 qj(4) = vec(1)*di(3) + vec(3)*di(1) + vec(1)*vec(3)*s
2975 qj(5) = vec(2)*di(3) + vec(3)*di(2) + vec(2)*vec(3)*s
2976 tr = 0.5_dp*(qj(1) + qj(3) + qj(6))
2978 qj(1) = qi(1) + 1.5_dp*qj(1) - tr
2979 qj(2) = qi(2) + 1.5_dp*qj(2)
2980 qj(3) = qi(3) + 1.5_dp*qj(3) - tr
2981 qj(4) = qi(4) + 1.5_dp*qj(4)
2982 qj(5) = qi(5) + 1.5_dp*qj(5)
2983 qj(6) = qi(6) + 1.5_dp*qj(6) - tr
2985 END SUBROUTINE tb_shift_multipole
2994 SUBROUTINE tb_ao_charges_matrix(p_mat, s_matrix, charges, para_env)
2996 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: charges
2999 INTEGER :: i, iblock_col, iblock_row, j
3001 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: p_block, s_block
3007 NULLIFY (s_block, p_block)
3009 CALL dbcsr_get_block_p(matrix=p_mat, row=iblock_row, col=iblock_col, block=p_block, found=found)
3010 IF (.NOT. found) cycle
3011 IF (.NOT. (
ASSOCIATED(s_block) .AND.
ASSOCIATED(p_block))) cycle
3013 DO j = 1,
SIZE(p_block, 2)
3014 DO i = 1,
SIZE(p_block, 1)
3015 charges(i, iblock_row) = charges(i, iblock_row) + p_block(i, j)*s_block(i, j)
3018 IF (iblock_col /= iblock_row)
THEN
3019 DO j = 1,
SIZE(p_block, 2)
3020 DO i = 1,
SIZE(p_block, 1)
3021 charges(j, iblock_col) = charges(j, iblock_col) + p_block(i, j)*s_block(i, j)
3027 CALL para_env%sum(charges)
3029 END SUBROUTINE tb_ao_charges_matrix
3039 SUBROUTINE tb_ao_charges_kp_spin(p_matrix_kp, s_matrix_kp, charges, ispin, para_env)
3040 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: p_matrix_kp, s_matrix_kp
3041 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: charges
3042 INTEGER,
INTENT(IN) :: ispin
3046 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: image_charges
3050 ALLOCATE (image_charges(
SIZE(charges, 1),
SIZE(charges, 2)))
3051 DO ic = 1,
SIZE(s_matrix_kp, 2)
3052 NULLIFY (p_mat, s_mat)
3053 p_mat => p_matrix_kp(ispin, ic)%matrix
3054 s_mat => s_matrix_kp(1, ic)%matrix
3055 IF (
ASSOCIATED(p_mat) .AND.
ASSOCIATED(s_mat))
THEN
3056 image_charges = 0.0_dp
3057 CALL tb_ao_charges_matrix(p_mat, s_mat, image_charges, para_env)
3058 charges(:, :) = charges(:, :) + image_charges(:, :)
3061 DEALLOCATE (image_charges)
3063 END SUBROUTINE tb_ao_charges_kp_spin
3073 SUBROUTINE tb_contract_dens_matrix(p_mat, bra_mat, ket_mat, output, para_env)
3074 TYPE(
dbcsr_type),
POINTER :: p_mat, bra_mat, ket_mat
3075 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: output
3078 INTEGER :: i, iblock_col, iblock_row, j
3080 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: bra, ket, p_block
3086 NULLIFY (p_block, bra, ket)
3088 CALL dbcsr_get_block_p(matrix=p_mat, row=iblock_row, col=iblock_col, block=p_block, found=found)
3089 IF (.NOT. found) cycle
3090 CALL dbcsr_get_block_p(matrix=ket_mat, row=iblock_row, col=iblock_col, block=ket, found=found)
3091 IF (.NOT. found) cpabort(
"missing block")
3093 IF (.NOT. (
ASSOCIATED(bra) .AND.
ASSOCIATED(p_block))) cycle
3094 IF (iblock_col == iblock_row)
THEN
3095 DO j = 1,
SIZE(p_block, 1)
3096 DO i = 1,
SIZE(p_block, 2)
3097 output(iblock_row) = output(iblock_row) + p_block(j, i)*bra(j, i)
3101 DO j = 1,
SIZE(p_block, 1)
3102 DO i = 1,
SIZE(p_block, 2)
3103 output(iblock_row) = output(iblock_row) + p_block(j, i)*ket(j, i)
3106 DO j = 1,
SIZE(p_block, 1)
3107 DO i = 1,
SIZE(p_block, 2)
3108 output(iblock_col) = output(iblock_col) + p_block(j, i)*bra(j, i)
3114 CALL para_env%sum(output)
3116 END SUBROUTINE tb_contract_dens_matrix
3129 SUBROUTINE tb_contract_dens_kp_spin(p_matrix, bra_mat, ket_mat, iop, nops, output, ispin, para_env)
3130 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: p_matrix
3131 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: bra_mat, ket_mat
3132 INTEGER,
INTENT(IN) :: iop, nops
3133 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: output
3134 INTEGER,
INTENT(IN) :: ispin
3137 INTEGER :: ic,
idx, nimg
3138 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: image_output
3141 nimg =
SIZE(p_matrix, 2)
3143 ALLOCATE (image_output(
SIZE(output)))
3145 idx = iop + nops*(ic - 1)
3146 cpassert(
idx <=
SIZE(bra_mat))
3147 cpassert(
idx <=
SIZE(ket_mat))
3149 p_mat => p_matrix(ispin, ic)%matrix
3150 image_output = 0.0_dp
3151 CALL tb_contract_dens_matrix(p_mat, bra_mat(
idx)%matrix, ket_mat(
idx)%matrix, image_output, para_env)
3152 output = output + image_output
3154 DEALLOCATE (image_output)
3156 END SUBROUTINE tb_contract_dens_kp_spin
3169 SUBROUTINE contract_dens(p_matrix, bra_mat, ket_mat, output, para_env)
3171 TYPE(
dbcsr_type),
POINTER :: bra_mat, ket_mat
3172 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: output
3175 CHARACTER(len=*),
PARAMETER :: routinen =
'contract_dens'
3177 INTEGER :: handle, i, iblock_col, iblock_row, &
3180 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: bra, ket, p_block
3183 CALL timeset(routinen, handle)
3185 nspin =
SIZE(p_matrix)
3190 NULLIFY (p_block, bra, ket)
3194 row=iblock_row, col=iblock_col, block=p_block, found=found)
3195 IF (.NOT. found) cycle
3197 row=iblock_row, col=iblock_col, block=ket, found=found)
3198 IF (.NOT. found) cpabort(
"missing block")
3200 IF (.NOT. (
ASSOCIATED(bra) .AND.
ASSOCIATED(p_block))) cycle
3201 IF (iblock_col == iblock_row)
THEN
3202 DO j = 1,
SIZE(p_block, 1)
3203 DO i = 1,
SIZE(p_block, 2)
3204 output(iblock_row) = output(iblock_row) + p_block(j, i)*bra(j, i)
3208 DO j = 1,
SIZE(p_block, 1)
3209 DO i = 1,
SIZE(p_block, 2)
3210 output(iblock_row) = output(iblock_row) + p_block(j, i)*ket(j, i)
3213 DO j = 1,
SIZE(p_block, 1)
3214 DO i = 1,
SIZE(p_block, 2)
3215 output(iblock_col) = output(iblock_col) + p_block(j, i)*bra(j, i)
3223 CALL para_env%sum(output)
3224 CALL timestop(handle)
3226 END SUBROUTINE contract_dens
3238 SUBROUTINE contract_dens_kp(p_matrix, bra_mat, ket_mat, iop, nops, output, para_env)
3239 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: p_matrix
3240 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: bra_mat, ket_mat
3241 INTEGER,
INTENT(IN) :: iop, nops
3242 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: output
3245 INTEGER :: ic,
idx, nimg
3246 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: image_output
3249 nimg =
SIZE(p_matrix, 2)
3251 ALLOCATE (image_output(
SIZE(output)))
3253 idx = iop + nops*(ic - 1)
3254 cpassert(
idx <=
SIZE(bra_mat))
3255 cpassert(
idx <=
SIZE(ket_mat))
3257 p_image => p_matrix(:, ic)
3258 image_output = 0.0_dp
3259 CALL contract_dens(p_image, bra_mat(
idx)%matrix, ket_mat(
idx)%matrix, image_output, para_env)
3260 output = output + image_output
3262 DEALLOCATE (image_output)
3264 END SUBROUTINE contract_dens_kp
3274 SUBROUTINE tb_grad2force(qs_env, tb, para_env, ityp)
3281 CHARACTER(len=*),
PARAMETER :: routinen =
'tb_grad2force'
3283 CHARACTER(LEN=default_path_length) :: dump_file
3284 INTEGER :: atoma, dump_status, dump_unit, handle, &
3286 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
3291 CALL timeset(routinen, handle)
3293 NULLIFY (force, atomic_kind_set)
3294 CALL get_qs_env(qs_env=qs_env, force=force, particle_set=particle_set, &
3295 atomic_kind_set=atomic_kind_set)
3297 atom_of_kind=atom_of_kind, kind_of=kind_of)
3299 natom =
SIZE(particle_set)
3302#if defined(__TBLITE_DEBUG_DIAGNOSTICS)
3303 CALL get_environment_variable(
"CP2K_TBLITE_FORCE_DUMP", dump_file, status=dump_status)
3305 IF (dump_status == 0)
THEN
3306 OPEN (newunit=dump_unit, file=trim(dump_file), status=
"UNKNOWN", &
3307 position=
"APPEND", action=
"WRITE")
3308 WRITE (dump_unit,
"(A,1X,I0)")
"component", ityp
3310 WRITE (dump_unit,
"(I0,3(1X,ES24.16))") iatom, tb%grad(:, iatom)/para_env%num_pe
3317 cpabort(
"unknown force type")
3320 ikind = kind_of(iatom)
3321 atoma = atom_of_kind(iatom)
3322 force(ikind)%all_potential(:, atoma) = &
3323 force(ikind)%all_potential(:, atoma) + tb%grad(:, iatom)/para_env%num_pe
3327 ikind = kind_of(iatom)
3328 atoma = atom_of_kind(iatom)
3329 force(ikind)%repulsive(:, atoma) = &
3330 force(ikind)%repulsive(:, atoma) + tb%grad(:, iatom)/para_env%num_pe
3334 ikind = kind_of(iatom)
3335 atoma = atom_of_kind(iatom)
3336 force(ikind)%dispersion(:, atoma) = &
3337 force(ikind)%dispersion(:, atoma) + tb%grad(:, iatom)/para_env%num_pe
3341 ikind = kind_of(iatom)
3342 atoma = atom_of_kind(iatom)
3343 force(ikind)%rho_elec(:, atoma) = &
3344 force(ikind)%rho_elec(:, atoma) + tb%grad(:, iatom)/para_env%num_pe
3348 ikind = kind_of(iatom)
3349 atoma = atom_of_kind(iatom)
3350 force(ikind)%overlap(:, atoma) = &
3351 force(ikind)%overlap(:, atoma) + tb%grad(:, iatom)/para_env%num_pe
3355 ikind = kind_of(iatom)
3356 atoma = atom_of_kind(iatom)
3357 force(ikind)%efield(:, atoma) = &
3358 force(ikind)%efield(:, atoma) + tb%grad(:, iatom)/para_env%num_pe
3362 CALL timestop(handle)
3364 END SUBROUTINE tb_grad2force
3371 SUBROUTINE tb_zero_force(qs_env)
3375 INTEGER :: iatom, ikind, natom
3376 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: kind_of
3381 NULLIFY (force, atomic_kind_set)
3382 CALL get_qs_env(qs_env=qs_env, force=force, particle_set=particle_set, &
3383 atomic_kind_set=atomic_kind_set)
3387 natom =
SIZE(particle_set)
3390 ikind = kind_of(iatom)
3391 force(ikind)%all_potential = 0.0_dp
3392 force(ikind)%repulsive = 0.0_dp
3393 force(ikind)%dispersion = 0.0_dp
3394 force(ikind)%rho_elec = 0.0_dp
3395 force(ikind)%overlap = 0.0_dp
3396 force(ikind)%efield = 0.0_dp
3399 END SUBROUTINE tb_zero_force
3410 LOGICAL,
INTENT(IN) :: use_rho
3411 INTEGER,
INTENT(IN) :: nimg
3413#if defined(__TBLITE)
3414 INTEGER :: i, idim, ij, iatom, ic, icol, ikind, img, ispin, &
3415 jdim, ni, nj, nkind, nel, &
3416 ityp, jatom, jkind, jrow, jtyp, iset, jset, nseti, nsetj, &
3417 ia, ib, inda, indb, sampled_axes, sampled_even_axes, &
3418 sampled_gamma_axes, nspin, ikp_axis
3419 INTEGER,
DIMENSION(3) :: cellind, nkp_cellind, nkp_grid
3420 INTEGER,
DIMENSION(:),
POINTER :: nsgfa, nsgfb
3421 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
3422 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
3423 LOGICAL :: found, gamma_centered, gamma_sampled_image_pair, &
3424 has_multipole_response, sampled_image_pair, &
3425 use_matrix_scc_stress
3426 LOGICAL,
DIMENSION(3) :: mesh_has_gamma
3427 REAL(kind=
dp) :: r2, dr, i_a_shift, j_a_shift, i_a_shift_mag, j_a_shift_mag, &
3428 ishift, jshift, ishift_mag, jshift_mag, pij_charge, &
3429 pij_magnet, mp_pair_scale, kpoint_coordinate, native_dot_tmp
3430 REAL(kind=
dp),
DIMENSION(3) :: kp_shift
3431 REAL(kind=
dp),
DIMENSION(3) :: rij, dgrad, dhgrad_charge, dhgrad_magnet, &
3432 mpgrad_charge, mpgrad_magnet
3433 REAL(kind=
dp),
DIMENSION(3, 3) :: hsigma
3434 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: t_ov, idip, jdip, idip_mag, jdip_mag, &
3435 iquad, jquad, iquad_mag, jquad_mag
3436 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: t_dip, t_quad, t_d_ov
3437 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: t_i_dip, t_i_quad, t_j_dip, t_j_quad
3438 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :, :, :) :: scc_strain_hint
3439 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pblock, pblock_beta
3440 TYPE(
block_p_type),
DIMENSION(3, 3, 2) :: scc_strain_blocks
3443 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_dh_scc, matrix_p
3449 DIMENSION(:),
POINTER :: nl_iterator
3454 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3461 NULLIFY (scf_env, rho, tb, sab_orb, sab_kp, para_env, kpoints, matrix_dh_scc, virial)
3463 atomic_kind_set=atomic_kind_set, &
3469 para_env=para_env, &
3470 qs_kind_set=qs_kind_set, &
3473 NULLIFY (cell_to_index)
3475 IF (.NOT.
ASSOCIATED(sab_kp)) cpabort(
"Missing tblite k-point neighbor list")
3477 CALL get_kpoint_info(kpoint=kpoints, cell_to_index=cell_to_index, nkp_grid=nkp_grid, &
3478 kp_shift=kp_shift, gamma_centered=gamma_centered)
3482 gamma_centered = .true.
3484 mesh_has_gamma = .false.
3486 DO ikp_axis = 1, nkp_grid(i)
3487 IF (gamma_centered .AND.
modulo(nkp_grid(i), 2) == 0)
THEN
3488 kpoint_coordinate = real(2*ikp_axis - nkp_grid(i), kind=
dp)/ &
3489 REAL(2*nkp_grid(i), kind=
dp) + kp_shift(i)
3491 kpoint_coordinate = real(2*ikp_axis - nkp_grid(i) - 1, kind=
dp)/ &
3492 REAL(2*nkp_grid(i), kind=
dp) + kp_shift(i)
3494 IF (abs(kpoint_coordinate - anint(kpoint_coordinate)) < 1.0e-12_dp)
THEN
3495 mesh_has_gamma(i) = .true.
3499 has_multipole_response =
ASSOCIATED(tb%dipbra) .OR.
ASSOCIATED(tb%quadbra)
3504 ELSE IF (
ASSOCIATED(tb%rho_ao_kp_ref))
THEN
3505 matrix_p => tb%rho_ao_kp_ref
3507 matrix_p => scf_env%p_mix_new
3509 nspin =
SIZE(matrix_p, 1)
3510 use_matrix_scc_stress = tb%use_virial .AND. nimg > 1 .AND. all(tb%mol%periodic)
3512 IF (use_matrix_scc_stress)
THEN
3518 i = idim + 3*(jdim - 1) + 9*(ispin - 1)
3519 ALLOCATE (matrix_dh_scc(i, img)%matrix)
3520 CALL dbcsr_create(matrix_dh_scc(i, img)%matrix, template=matrix_p(ispin, img)%matrix, &
3521 name=
"TBLITE SCC STRAIN DERIVATIVE")
3530 nkind =
SIZE(atomic_kind_set)
3531 ALLOCATE (basis_set_list(nkind))
3534 nel = msao(tb%calc%bas%maxl)**2
3535 ALLOCATE (t_ov(nel))
3536 ALLOCATE (t_d_ov(3, nel))
3537 ALLOCATE (t_dip(dip_n, nel))
3538 ALLOCATE (t_i_dip(3, dip_n, nel), t_j_dip(3, dip_n, nel))
3539 ALLOCATE (t_quad(quad_n, nel))
3540 ALLOCATE (t_i_quad(3, quad_n, nel), t_j_quad(3, quad_n, nel))
3542 ALLOCATE (idip(dip_n), jdip(dip_n), idip_mag(dip_n), jdip_mag(dip_n))
3543 ALLOCATE (iquad(quad_n), jquad(quad_n), iquad_mag(quad_n), jquad_mag(quad_n))
3548 NULLIFY (nl_iterator)
3552 iatom=iatom, jatom=jatom, r=rij, cell=cellind)
3554 icol = max(iatom, jatom)
3555 jrow = min(iatom, jatom)
3557 IF (iatom < jatom)
THEN
3564 ityp = tb%mol%id(icol)
3565 jtyp = tb%mol%id(jrow)
3567 r2 = dot_product(rij, rij)
3569 IF (icol == jrow .AND. dr < same_atom) cycle
3572 basis_set_a => basis_set_list(ikind)%gto_basis_set
3573 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
3574 first_sgfa => basis_set_a%first_sgf
3575 nsgfa => basis_set_a%nsgf_set
3576 nseti = basis_set_a%nset
3577 basis_set_b => basis_set_list(jkind)%gto_basis_set
3578 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
3579 first_sgfb => basis_set_b%first_sgf
3580 nsgfb => basis_set_b%nsgf_set
3581 nsetj = basis_set_b%nset
3586 ic = cell_to_index(cellind(1), cellind(2), cellind(3))
3591 IF (nkp_grid(i) > 1)
THEN
3592 nkp_cellind(i) =
modulo(cellind(i), nkp_grid(i))
3593 IF (2*nkp_cellind(i) > nkp_grid(i)) nkp_cellind(i) = nkp_cellind(i) - nkp_grid(i)
3597 IF (nkp_cellind(1) /= 0) sampled_axes = sampled_axes + 1
3598 IF (nkp_cellind(2) /= 0) sampled_axes = sampled_axes + 1
3599 IF (nkp_cellind(3) /= 0) sampled_axes = sampled_axes + 1
3600 sampled_even_axes = 0
3601 sampled_gamma_axes = 0
3603 IF (nkp_grid(i) > 1 .AND.
modulo(nkp_grid(i), 2) == 0 .AND. &
3604 abs(2*nkp_cellind(i)) == nkp_grid(i))
THEN
3605 sampled_even_axes = sampled_even_axes + 1
3606 IF (mesh_has_gamma(i)) sampled_gamma_axes = sampled_gamma_axes + 1
3609 sampled_image_pair = sampled_axes > 0 .AND. sampled_even_axes > 0
3610 gamma_sampled_image_pair = sampled_image_pair .AND. sampled_gamma_axes == sampled_even_axes
3611 mp_pair_scale = 1.0_dp
3612 IF (icol == jrow .AND. sampled_image_pair .AND. has_multipole_response .AND. &
3613 .NOT. gamma_sampled_image_pair) mp_pair_scale = -1.0_dp
3615 NULLIFY (pblock, pblock_beta)
3617 row=jrow, col=icol, block=pblock, found=found)
3618 IF (.NOT. found) cpabort(
"pblock not found")
3621 row=jrow, col=icol, block=pblock_beta, found=found)
3622 IF (.NOT. found) cpabort(
"pblock beta not found")
3624 IF (use_matrix_scc_stress)
THEN
3625 ALLOCATE (scc_strain_hint(
SIZE(pblock, 2),
SIZE(pblock, 1), 3, 3, nspin))
3626 scc_strain_hint = 0.0_dp
3630 NULLIFY (scc_strain_blocks(idim, jdim, ispin)%block)
3631 i = idim + 3*(jdim - 1) + 9*(ispin - 1)
3633 row=jrow, col=icol, &
3634 block=scc_strain_blocks(idim, jdim, ispin)%block, found=found)
3635 IF (.NOT. found) cpabort(
"SCC strain derivative block not found")
3640 i_a_shift = tb%pot%vat(icol, 1)
3641 j_a_shift = tb%pot%vat(jrow, 1)
3642 i_a_shift_mag = 0.0_dp
3643 j_a_shift_mag = 0.0_dp
3644 IF (
SIZE(tb%pot%vat, 2) > 1)
THEN
3645 i_a_shift_mag = tb%pot%vat(icol, 2)
3646 j_a_shift_mag = tb%pot%vat(jrow, 2)
3648 idip(:) = tb%pot%vdp(:, icol, 1)
3649 jdip(:) = tb%pot%vdp(:, jrow, 1)
3650 idip_mag(:) = 0.0_dp
3651 jdip_mag(:) = 0.0_dp
3652 IF (
SIZE(tb%pot%vdp, 3) > 1)
THEN
3653 idip_mag(:) = tb%pot%vdp(:, icol, 2)
3654 jdip_mag(:) = tb%pot%vdp(:, jrow, 2)
3656 iquad(:) = tb%pot%vqp(:, icol, 1)
3657 jquad(:) = tb%pot%vqp(:, jrow, 1)
3658 iquad_mag(:) = 0.0_dp
3659 jquad_mag(:) = 0.0_dp
3660 IF (
SIZE(tb%pot%vqp, 3) > 1)
THEN
3661 iquad_mag(:) = tb%pot%vqp(:, icol, 2)
3662 jquad_mag(:) = tb%pot%vqp(:, jrow, 2)
3664 ni = tb%calc%bas%ish_at(icol)
3666 ishift = i_a_shift + tb%pot%vsh(ni + iset, 1)
3668 IF (
SIZE(tb%pot%vsh, 2) > 1) ishift_mag = i_a_shift_mag + tb%pot%vsh(ni + iset, 2)
3669 nj = tb%calc%bas%ish_at(jrow)
3671 jshift = j_a_shift + tb%pot%vsh(nj + jset, 1)
3673 IF (
SIZE(tb%pot%vsh, 2) > 1) jshift_mag = j_a_shift_mag + tb%pot%vsh(nj + jset, 2)
3676 CALL multipole_grad_cgto(tb%calc%bas%cgto(iset, ityp), tb%calc%bas%cgto(jset, jtyp), &
3677 & r2, rij, tb%calc%bas%intcut, t_ov, t_dip, t_quad, t_d_ov, t_i_dip, t_i_quad, &
3678 & t_j_dip, t_j_quad)
3681 DO inda = 1, nsgfa(iset)
3682 ia = first_sgfa(1, iset) - first_sgfa(1, 1) + inda
3683 DO indb = 1, nsgfb(jset)
3684 ib = first_sgfb(1, jset) - first_sgfb(1, 1) + indb
3686 ij = inda + nsgfa(iset)*(indb - 1)
3688 pij_charge = pblock(ib, ia)
3691 pij_charge = pij_charge + pblock_beta(ib, ia)
3692 pij_magnet = pblock(ib, ia) - pblock_beta(ib, ia)
3694 mpgrad_charge = matmul(t_i_dip(:, :, ij), idip) &
3695 + matmul(t_j_dip(:, :, ij), jdip) &
3696 + matmul(t_i_quad(:, :, ij), iquad) &
3697 + matmul(t_j_quad(:, :, ij), jquad)
3698 mpgrad_magnet = matmul(t_i_dip(:, :, ij), idip_mag) &
3699 + matmul(t_j_dip(:, :, ij), jdip_mag) &
3700 + matmul(t_i_quad(:, :, ij), iquad_mag) &
3701 + matmul(t_j_quad(:, :, ij), jquad_mag)
3702 dhgrad_charge = -(ishift + jshift)*t_d_ov(:, ij) - mp_pair_scale*mpgrad_charge
3703 dhgrad_magnet = -(ishift_mag + jshift_mag)*t_d_ov(:, ij) - mp_pair_scale*mpgrad_magnet
3704 dgrad(:) = dgrad(:) - &
3705 ((ishift + jshift)*pij_charge + &
3706 (ishift_mag + jshift_mag)*pij_magnet)*t_d_ov(:, ij) - &
3707 mp_pair_scale*(pij_charge*mpgrad_charge + pij_magnet*mpgrad_magnet)
3709 IF (
ALLOCATED(scc_strain_hint))
THEN
3712 scc_strain_hint(ia, ib, idim, jdim, 1) = &
3713 scc_strain_hint(ia, ib, idim, jdim, 1) &
3714 + (dhgrad_charge(idim) + merge(dhgrad_magnet(idim), 0.0_dp, nspin > 1))*rij(jdim)
3716 scc_strain_hint(ia, ib, idim, jdim, 2) = &
3717 scc_strain_hint(ia, ib, idim, jdim, 2) &
3718 + (dhgrad_charge(idim) - dhgrad_magnet(idim))*rij(jdim)
3726 tb%grad(:, icol) = tb%grad(:, icol) - dgrad
3727 tb%grad(:, jrow) = tb%grad(:, jrow) + dgrad
3728 IF (tb%use_virial .AND. .NOT. use_matrix_scc_stress)
THEN
3729 IF (icol == jrow)
THEN
3732 IF (sampled_image_pair .AND. .NOT. gamma_sampled_image_pair)
THEN
3733 hsigma(ia, ib) = hsigma(ia, ib) - 0.25_dp* &
3734 (rij(ia)*dgrad(ib) + rij(ib)*dgrad(ia))
3736 hsigma(ia, ib) = hsigma(ia, ib) + 0.25_dp* &
3737 (rij(ia)*dgrad(ib) + rij(ib)*dgrad(ia))
3744 hsigma(ia, ib) = hsigma(ia, ib) + 0.50_dp*(rij(ia)*dgrad(ib) + rij(ib)*dgrad(ia))
3751 IF (
ALLOCATED(scc_strain_hint))
THEN
3755 IF (icol <= jrow)
THEN
3756 scc_strain_blocks(idim, jdim, ispin)%block(:, :) = &
3757 scc_strain_blocks(idim, jdim, ispin)%block(:, :) &
3758 + scc_strain_hint(:, :, idim, jdim, ispin)
3760 scc_strain_blocks(idim, jdim, ispin)%block(:, :) = &
3761 scc_strain_blocks(idim, jdim, ispin)%block(:, :) &
3762 + transpose(scc_strain_hint(:, :, idim, jdim, ispin))
3767 DEALLOCATE (scc_strain_hint)
3772 IF (use_matrix_scc_stress)
THEN
3778 i = idim + 3*(jdim - 1) + 9*(ispin - 1)
3780 CALL dbcsr_dot(matrix_dh_scc(i, img)%matrix, matrix_p(ispin, img)%matrix, native_dot_tmp)
3782 hsigma(idim, jdim) = hsigma(idim, jdim) + 0.5_dp*native_dot_tmp
3789 CALL para_env%sum(hsigma)
3791 CALL para_env%sum(tb%grad)
3792 CALL tb_grad2force(qs_env, tb, para_env, 4)
3794 IF (.NOT. use_matrix_scc_stress) tb%sigma = tb%sigma + hsigma
3796 DEALLOCATE (basis_set_list)
3797 DEALLOCATE (t_ov, t_d_ov)
3798 DEALLOCATE (t_dip, t_i_dip, t_j_dip)
3799 DEALLOCATE (t_quad, t_i_quad, t_j_quad)
3800 DEALLOCATE (idip, jdip, idip_mag, jdip_mag, iquad, jquad, iquad_mag, jquad_mag)
3802 IF (tb%use_virial)
THEN
3803 CALL tb_add_stress(qs_env, tb, para_env)
3804 IF (use_matrix_scc_stress)
THEN
3805 CALL get_qs_env(qs_env=qs_env, virial=virial)
3806 virial%pv_virial = virial%pv_virial - hsigma/para_env%num_pe
3814 cpabort(
"Built without TBLITE")
3827 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tb_reference_cli_compare'
3829 CHARACTER(LEN=16) :: solvation_model_name
3830 CHARACTER(LEN=32) :: acc_str, charge_str, efield_x_str, efield_y_str, efield_z_str, &
3831 etemp_guess_val_str, etemp_str, iter_str, spin_str, spinpol_str
3832 CHARACTER(LEN=4*default_path_length+16) :: efield_str, etemp_guess_str, param_str, &
3833 post_processing_output_str, post_processing_str, restart_str, solvation_str, verbosity_str
3834 CHARACTER(LEN=8) :: guess, method, solver
3835 CHARACTER(LEN=8*default_path_length) :: command
3836 CHARACTER(LEN=default_path_length) :: file_base, gen_file, grad_file, &
3837 json_file, log_file, &
3838 post_processing_output_file
3839 INTEGER :: cmdstat, exitstat, handle, iounit, &
3840 n_periodic, natom, nkp, &
3841 reference_iterations, spin
3842 INTEGER,
DIMENSION(3) :: periodic
3843 LOGICAL :: do_kpoints, have_energy, have_gradient, &
3844 have_virial, too_large, &
3846 REAL(kind=
dp) :: cli_energy, cp_energy, ediff, etemp, &
3847 etemp_guess, fmax, fsum, vmax, vsum
3848 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: cli_gradient, cli_virial, cp_gradient
3849 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
3863 CALL timeset(routinen, handle)
3865 NULLIFY (atomic_kind_set, cell, dft_control, energy, force, kpoints, logger, para_env, particle_set, &
3866 scf_control, virial, xkp)
3867 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, cell=cell, &
3868 dft_control=dft_control, energy=energy, force=force, &
3869 para_env=para_env, particle_set=particle_set, scf_control=scf_control, &
3870 virial=virial, do_kpoints=do_kpoints, kpoints=kpoints)
3872 ref = dft_control%qs_control%xtb_control%reference_cli
3873 IF (.NOT. ref%enabled)
THEN
3874 CALL timestop(handle)
3877 IF (.NOT. para_env%is_source())
THEN
3878 CALL timestop(handle)
3886 verbosity_str =
" --silent"
3889 verbosity_str =
" --verbose"
3891 IF (ref%solvation_active)
THEN
3893 IF (
ASSOCIATED(cell))
CALL get_cell(cell=cell, periodic=periodic)
3894 n_periodic = count(periodic == 1)
3895 IF (n_periodic == 3)
THEN
3896 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
3897 "tblite reference CLI implicit solvation is not supported for PERIODIC XYZ."
3898 WRITE (unit=iounit, fmt=
"(T2,A)") &
3899 "Use PERIODIC NONE for molecular solvation diagnostics, or remove IMPLICIT_SOLVATION."
3900 cpabort(
"REFERENCE_CLI implicit solvation is incompatible with PERIODIC XYZ")
3901 ELSE IF (n_periodic > 0)
THEN
3902 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
3903 "WARNING: tblite reference CLI implicit solvation with finite periodicity is diagnostic only."
3904 WRITE (unit=iounit, fmt=
"(T2,A,I0,A)") &
3905 "The generated native tblite reference geometry has ", n_periodic, &
3906 " periodic direction(s); continuum-solvation conventions are primarily molecular."
3909 unsupported_kpoints = .false.
3910 IF (do_kpoints .AND.
ASSOCIATED(kpoints))
THEN
3913 unsupported_kpoints = nkp > 1
3914 IF (nkp == 1 .AND.
ASSOCIATED(xkp)) unsupported_kpoints = any(abs(xkp(:, 1)) > 1.0e-12_dp)
3916 IF (unsupported_kpoints)
THEN
3917 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
3918 "tblite reference CLI check skipped: CP2K KPOINTS are active."
3919 WRITE (unit=iounit, fmt=
"(T2,A)") &
3920 "The native tblite CLI reference path does not reproduce CP2K multi-k-point sampling."
3921 IF (ref%stop_on_error) cpabort(
"tblite reference CLI cannot check CP2K k-point calculations")
3922 CALL timestop(handle)
3926 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
3927 "WARNING: tblite reference CLI cannot reproduce XTB/SCC_MIXER CP2K."
3928 WRITE (unit=iounit, fmt=
"(T2,A)") &
3929 "The external native tblite run uses tblite's own SCC mixer; only the converged result is compared."
3930 IF (ref%stop_on_error) cpabort(
"tblite reference CLI cannot reproduce SCC_MIXER CP2K")
3932 natom =
SIZE(particle_set)
3933 method = tb_reference_method_name(dft_control%qs_control%xtb_control%tblite_method)
3934 guess = tb_reference_guess_name(ref%guess)
3935 solver = tb_reference_solver_name(dft_control%qs_control%xtb_control%tblite_mixer_solver)
3936 file_base = tb_join_path(ref%work_directory, ref%prefix)
3937 gen_file = trim(file_base)//
".gen"
3938 grad_file = trim(file_base)//
".grad"
3939 json_file = trim(file_base)//
".json"
3940 log_file = trim(file_base)//
".log"
3941 post_processing_output_file =
""
3942 IF (len_trim(ref%grad_file) > 0) grad_file = ref%grad_file
3943 IF (len_trim(ref%json_file) > 0) json_file = ref%json_file
3944 IF (len_trim(ref%post_processing_output_file) > 0)
THEN
3945 post_processing_output_file = ref%post_processing_output_file
3948 WRITE (charge_str,
"(I0)") dft_control%charge
3949 spin = max(0, dft_control%multiplicity - 1)
3950 WRITE (spin_str,
"(I0)") spin
3951 WRITE (acc_str,
"(ES16.8)") dft_control%qs_control%xtb_control%tblite_accuracy
3952 reference_iterations = dft_control%qs_control%xtb_control%tblite_mixer_iterations
3953 WRITE (iter_str,
"(I0)") reference_iterations
3955 IF (ref%efield_active)
THEN
3956 WRITE (efield_x_str,
"(ES16.8)") ref%efield(1)
3957 WRITE (efield_y_str,
"(ES16.8)") ref%efield(2)
3958 WRITE (efield_z_str,
"(ES16.8)") ref%efield(3)
3959 efield_str =
" --efield "//trim(adjustl(efield_x_str))//
","// &
3960 trim(adjustl(efield_y_str))//
","//trim(adjustl(efield_z_str))
3963 solvation_model_name =
""
3964 IF (ref%solvation_active)
THEN
3965 SELECT CASE (ref%solvation_model)
3967 solvation_model_name =
"ALPB"
3968 solvation_str =
" --alpb "
3970 solvation_model_name =
"GBSA"
3971 solvation_str =
" --gbsa "
3973 solvation_model_name =
"GBE"
3974 solvation_str =
" --gbe "
3976 solvation_model_name =
"GB"
3977 solvation_str =
" --gb "
3979 solvation_model_name =
"CPCM"
3980 solvation_str =
" --cpcm "
3982 cpabort(
"Unknown tblite reference CLI implicit-solvation model")
3984 solvation_str = trim(solvation_str)//
" "//trim(tb_shell_quote(ref%solvation_solvent))
3985 SELECT CASE (ref%solvation_born_kernel)
3988 solvation_str = trim(solvation_str)//
" --born-kernel p16"
3990 solvation_str = trim(solvation_str)//
" --born-kernel still"
3992 cpabort(
"Unknown tblite reference CLI Born kernel")
3994 SELECT CASE (ref%solvation_state)
3997 solvation_str = trim(solvation_str)//
" --solv-state bar1mol"
3999 solvation_str = trim(solvation_str)//
" --solv-state reference"
4001 cpabort(
"Unknown tblite reference CLI solution state")
4004 IF (dft_control%qs_control%xtb_control%tblite_mixer_memory /= reference_iterations)
THEN
4005 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
4006 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/MEMORY."
4007 WRITE (unit=iounit, fmt=
"(T2,A,I0,A,I0,A)") &
4008 "The native reference run uses tblite's internal mixer memory tied to --iterations (", &
4009 reference_iterations,
"), while CP2K uses MEMORY ", &
4010 dft_control%qs_control%xtb_control%tblite_mixer_memory,
"."
4011 IF (ref%stop_on_error) cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/MEMORY")
4013 IF (abs(dft_control%qs_control%xtb_control%tblite_mixer_damping - &
4015 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
4016 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/DAMPING."
4017 WRITE (unit=iounit, fmt=
"(T2,A,F8.4,A,F8.4,A)") &
4019 ", while CP2K uses DAMPING ", dft_control%qs_control%xtb_control%tblite_mixer_damping,
"."
4020 IF (ref%stop_on_error) cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/DAMPING")
4022 IF (abs(dft_control%qs_control%xtb_control%tblite_mixer_omega0 - &
4024 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
4025 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/OMEGA0."
4026 WRITE (unit=iounit, fmt=
"(T2,A,ES12.4,A,ES12.4,A)") &
4028 ", while CP2K uses OMEGA0 ", dft_control%qs_control%xtb_control%tblite_mixer_omega0,
"."
4029 IF (ref%stop_on_error) cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/OMEGA0")
4031 IF (abs(dft_control%qs_control%xtb_control%tblite_mixer_min_weight - &
4033 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
4034 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/MIN_WEIGHT."
4035 WRITE (unit=iounit, fmt=
"(T2,A,ES12.4,A,ES12.4,A)") &
4037 ", while CP2K uses MIN_WEIGHT ", dft_control%qs_control%xtb_control%tblite_mixer_min_weight,
"."
4038 IF (ref%stop_on_error)
THEN
4039 cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/MIN_WEIGHT")
4042 IF (abs(dft_control%qs_control%xtb_control%tblite_mixer_max_weight - &
4044 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
4045 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/MAX_WEIGHT."
4046 WRITE (unit=iounit, fmt=
"(T2,A,ES12.4,A,ES12.4,A)") &
4048 ", while CP2K uses MAX_WEIGHT ", dft_control%qs_control%xtb_control%tblite_mixer_max_weight,
"."
4049 IF (ref%stop_on_error)
THEN
4050 cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/MAX_WEIGHT")
4053 IF (abs(dft_control%qs_control%xtb_control%tblite_mixer_weight_factor - &
4055 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
4056 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/WEIGHT_FACTOR."
4057 WRITE (unit=iounit, fmt=
"(T2,A,ES12.4,A,ES12.4,A)") &
4059 ", while CP2K uses WEIGHT_FACTOR ", &
4060 dft_control%qs_control%xtb_control%tblite_mixer_weight_factor,
"."
4061 IF (ref%stop_on_error)
THEN
4062 cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/WEIGHT_FACTOR")
4066 IF (
ASSOCIATED(scf_control))
THEN
4067 IF (
ASSOCIATED(scf_control%smear))
THEN
4068 IF (scf_control%smear%do_smear)
THEN
4071 WRITE (unit=iounit, fmt=
"(/,T2,A,A,A)") &
4072 "WARNING: tblite reference CLI cannot reproduce CP2K smearing method ", &
4073 trim(tb_reference_smear_method_name(scf_control%smear%method)),
"."
4074 WRITE (unit=iounit, fmt=
"(T2,A,F12.3,A)") &
4075 "The native reference run uses Fermi-Dirac electronic temperature ", etemp,
" K instead."
4080 WRITE (etemp_str,
"(ES16.8)") etemp
4081 etemp_guess = 0.0_dp
4082 etemp_guess_str =
""
4083 IF (ref%electronic_temperature_guess > 0.0_dp)
THEN
4085 WRITE (etemp_guess_val_str,
"(ES16.8)") etemp_guess
4086 etemp_guess_str =
" --etemp-guess "//trim(adjustl(etemp_guess_val_str))
4089 IF (len_trim(dft_control%qs_control%xtb_control%tblite_param_file) > 0)
THEN
4090 param_str =
" --param "//trim(tb_shell_quote(dft_control%qs_control%xtb_control%tblite_param_file))
4093 IF (dft_control%lsd) spinpol_str =
" --spin-polarized"
4094 post_processing_str =
""
4095 IF (len_trim(ref%post_processing) > 0)
THEN
4096 post_processing_str =
" --post-processing "//trim(tb_shell_quote(ref%post_processing))
4098 post_processing_output_str =
""
4099 IF (len_trim(post_processing_output_file) > 0)
THEN
4100 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
4101 "WARNING: tblite reference CLI POST_PROCESSING_OUTPUT was requested explicitly."
4102 WRITE (unit=iounit, fmt=
"(T2,A)") &
4103 "Some tblite 0.5.0 command-line builds document --post-processing-output but do not parse it."
4104 post_processing_output_str =
" --post-processing-output "// &
4105 trim(tb_shell_quote(post_processing_output_file))
4107 restart_str =
" --no-restart"
4108 IF (len_trim(ref%restart_file) > 0)
THEN
4109 restart_str =
" --restart "//trim(tb_shell_quote(ref%restart_file))
4112 CALL tb_write_reference_gen(qs_env, trim(gen_file))
4114 command = trim(tb_shell_quote(ref%program_name))//
" run --method "//trim(method)// &
4116 trim(spinpol_str)// &
4117 " --charge "//trim(adjustl(charge_str))// &
4118 " --spin "//trim(adjustl(spin_str))// &
4119 " --acc "//trim(adjustl(acc_str))// &
4120 " --guess "//trim(guess)// &
4121 " --solver "//trim(solver)// &
4122 " --iterations "//trim(adjustl(iter_str))// &
4123 " --etemp "//trim(adjustl(etemp_str))// &
4124 trim(etemp_guess_str)// &
4125 trim(efield_str)// &
4126 trim(solvation_str)// &
4127 trim(post_processing_str)// &
4128 trim(post_processing_output_str)// &
4129 trim(restart_str)// &
4130 trim(verbosity_str)//
" --input "//trim(tb_shell_quote(ref%input_format))// &
4131 " --grad "//trim(tb_shell_quote(grad_file))// &
4132 " --json "//trim(tb_shell_quote(json_file))//
" "//trim(tb_shell_quote(gen_file))// &
4133 " > "//trim(tb_shell_quote(log_file))//
" 2>&1"
4137 CALL execute_command_line(trim(command), exitstat=exitstat, cmdstat=cmdstat)
4138 IF (cmdstat /= 0 .OR. exitstat /= 0)
THEN
4139 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"tblite reference CLI check failed to run."
4140 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Command: ", trim(command)
4141 WRITE (unit=iounit, fmt=
"(T2,A,I0,T32,A,I0)")
"cmdstat:", cmdstat,
"exitstat:", exitstat
4142 IF (ref%stop_on_error) cpabort(
"tblite reference CLI command failed")
4143 CALL tb_reference_cleanup(ref, gen_file, grad_file, json_file, log_file, post_processing_output_file)
4144 CALL timestop(handle)
4148 ALLOCATE (cli_gradient(3, natom), cli_virial(3, 3))
4149 CALL tb_read_reference_grad(trim(grad_file), natom, cli_energy, cli_gradient, cli_virial, &
4150 have_energy, have_gradient, have_virial)
4152 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"tblite reference CLI check"
4153 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Executable: ", trim(ref%program_name)
4154 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Method: ", trim(method)
4155 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Guess: ", trim(guess)
4156 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Solver: ", trim(solver)
4157 WRITE (unit=iounit, fmt=
"(T2,A,L1)")
"Spin-pol.: ", dft_control%lsd
4158 IF (ref%efield_active)
THEN
4159 WRITE (unit=iounit, fmt=
"(T2,A,3ES16.8,A)")
"Efield: ", ref%efield,
" V/Angstrom"
4161 IF (ref%solvation_active)
THEN
4162 WRITE (unit=iounit, fmt=
"(T2,A,A,1X,A)")
"Solvation: ", trim(solvation_model_name), &
4163 trim(ref%solvation_solvent)
4165 IF (len_trim(ref%post_processing) > 0)
THEN
4166 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Post proc.: ", trim(ref%post_processing)
4168 IF (len_trim(post_processing_output_file) > 0)
THEN
4169 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"PP output: ", trim(post_processing_output_file)
4171 IF (ref%electronic_temperature_guess > 0.0_dp)
THEN
4172 WRITE (unit=iounit, fmt=
"(T2,A,F12.3,A)")
"Guess etemp:", etemp_guess,
" K"
4174 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Grad file: ", trim(grad_file)
4175 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"JSON file: ", trim(json_file)
4176 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Log file: ", trim(log_file)
4179 IF (ref%check_energy)
THEN
4180 IF (have_energy)
THEN
4181 cp_energy = energy%total
4182 ediff = abs(cp_energy - cli_energy)
4183 WRITE (unit=iounit, fmt=
"(T2,A,3ES22.12)") &
4184 "Energy CP2K/CLI/absdiff:", cp_energy, cli_energy, ediff
4185 too_large = too_large .OR. ediff > ref%error_limit
4187 WRITE (unit=iounit, fmt=
"(T2,A)")
"Energy check skipped: no CLI energy found."
4191 IF (ref%check_forces)
THEN
4192 IF (have_gradient .AND.
ASSOCIATED(force))
THEN
4193 ALLOCATE (cp_gradient(3, natom))
4195 fsum = sum(abs(cp_gradient - cli_gradient))
4196 fmax = maxval(abs(cp_gradient - cli_gradient))
4197 WRITE (unit=iounit, fmt=
"(T2,A,2ES22.12)")
"Gradient diff sum/max:", fsum, fmax
4198 too_large = too_large .OR. fmax > ref%error_limit
4199 DEALLOCATE (cp_gradient)
4201 WRITE (unit=iounit, fmt=
"(T2,A)")
"Gradient check skipped: no CLI gradient or CP2K force found."
4205 IF (ref%check_virial)
THEN
4206 IF (have_virial .AND.
ASSOCIATED(virial))
THEN
4209 vsum = sum(abs(-virial%pv_virial - cli_virial))
4210 vmax = maxval(abs(-virial%pv_virial - cli_virial))
4211 WRITE (unit=iounit, fmt=
"(T2,A,2ES22.12)")
"Virial diff sum/max:", vsum, vmax
4212 too_large = too_large .OR. vmax > ref%error_limit
4214 WRITE (unit=iounit, fmt=
"(T2,A)")
"Virial check skipped: no CLI virial or CP2K virial found."
4219 WRITE (unit=iounit, fmt=
"(T2,A,ES12.4)") &
4220 "tblite reference CLI deviation exceeded ERROR_LIMIT = ", ref%error_limit
4221 IF (ref%stop_on_error) cpabort(
"tblite reference CLI deviation exceeded ERROR_LIMIT")
4224 CALL tb_reference_cli_aux_commands(ref, dft_control, gen_file, file_base, verbosity_str, iounit)
4226 CALL tb_reference_cleanup(ref, gen_file, grad_file, json_file, log_file, post_processing_output_file)
4227 DEALLOCATE (cli_gradient, cli_virial)
4229 CALL timestop(handle)
4238 FUNCTION tb_reference_method_name(method_id)
RESULT(method)
4239 INTEGER,
INTENT(IN) :: method_id
4240 CHARACTER(LEN=8) :: method
4242 SELECT CASE (method_id)
4250 cpabort(
"Unknown tblite reference CLI method")
4253 END FUNCTION tb_reference_method_name
4260 FUNCTION tb_reference_guess_name(guess_id)
RESULT(guess)
4261 INTEGER,
INTENT(IN) :: guess_id
4262 CHARACTER(LEN=8) :: guess
4264 SELECT CASE (guess_id)
4272 cpabort(
"Unknown tblite reference CLI guess")
4275 END FUNCTION tb_reference_guess_name
4282 FUNCTION tb_reference_solver_name(solver_id)
RESULT(solver)
4283 INTEGER,
INTENT(IN) :: solver_id
4284 CHARACTER(LEN=8) :: solver
4286 SELECT CASE (solver_id)
4292 cpabort(
"Unknown tblite reference CLI solver")
4295 END FUNCTION tb_reference_solver_name
4302 FUNCTION tb_reference_smear_method_name(method_id)
RESULT(method)
4303 INTEGER,
INTENT(IN) :: method_id
4304 CHARACTER(LEN=24) :: method
4306 SELECT CASE (method_id)
4308 method =
"FERMI_DIRAC"
4310 method =
"ENERGY_WINDOW"
4316 method =
"METHFESSEL_PAXTON"
4318 method =
"MARZARI_VANDERBILT"
4323 END FUNCTION tb_reference_smear_method_name
4334 SUBROUTINE tb_reference_cli_aux_commands(ref, dft_control, gen_file, file_base, verbosity_str, iounit)
4338 CHARACTER(LEN=*),
INTENT(IN) :: gen_file, file_base, verbosity_str
4339 INTEGER,
INTENT(IN) :: iounit
4341 CHARACTER(LEN=32) :: charge_str, efield_x_str, efield_y_str, &
4342 efield_z_str, etemp_guess_val_str, &
4344 CHARACTER(LEN=4*default_path_length+16) :: copy_str, dry_run_str, efield_str, &
4345 etemp_guess_str, grad_str, json_str, &
4346 method_str, output_str
4347 CHARACTER(LEN=8*default_path_length) :: command
4348 CHARACTER(LEN=default_path_length) :: guess_input, log_file
4350 REAL(kind=
dp) :: etemp_guess
4352 WRITE (charge_str,
"(I0)") dft_control%charge
4353 spin = max(0, dft_control%multiplicity - 1)
4354 WRITE (spin_str,
"(I0)") spin
4356 IF (ref%guess_cli%enabled)
THEN
4357 guess_input = ref%guess_cli%input_file
4358 IF (len_trim(guess_input) == 0) guess_input = gen_file
4359 etemp_guess_str =
""
4360 IF (ref%guess_cli%electronic_temperature_guess > 0.0_dp)
THEN
4361 etemp_guess =
cp_unit_from_cp2k(ref%guess_cli%electronic_temperature_guess,
"K")
4362 WRITE (etemp_guess_val_str,
"(ES16.8)") etemp_guess
4363 etemp_guess_str =
" --etemp-guess "//trim(adjustl(etemp_guess_val_str))
4366 IF (ref%guess_cli%efield_active)
THEN
4367 WRITE (efield_x_str,
"(ES16.8)") ref%guess_cli%efield(1)
4368 WRITE (efield_y_str,
"(ES16.8)") ref%guess_cli%efield(2)
4369 WRITE (efield_z_str,
"(ES16.8)") ref%guess_cli%efield(3)
4370 efield_str =
" --efield "//trim(adjustl(efield_x_str))//
","// &
4371 trim(adjustl(efield_y_str))//
","//trim(adjustl(efield_z_str))
4374 IF (ref%guess_cli%grad) grad_str =
" --grad"
4376 IF (len_trim(ref%guess_cli%json_file) > 0)
THEN
4377 json_str =
" --json "//trim(tb_shell_quote(ref%guess_cli%json_file))
4379 log_file = trim(file_base)//
".guess.log"
4380 command = trim(tb_shell_quote(ref%program_name))// &
4381 " guess --charge "//trim(adjustl(charge_str))// &
4382 " --spin "//trim(adjustl(spin_str))// &
4383 " --method "//trim(tb_reference_guess_name(ref%guess_cli%method))// &
4384 " --solver "//trim(tb_reference_solver_name(ref%guess_cli%solver))// &
4385 trim(etemp_guess_str)// &
4386 trim(efield_str)// &
4389 trim(verbosity_str)//
" --input "//trim(tb_shell_quote(ref%guess_cli%input_format))// &
4390 " "//trim(tb_shell_quote(guess_input))// &
4391 " > "//trim(tb_shell_quote(log_file))//
" 2>&1"
4392 CALL tb_reference_cli_execute(ref,
"guess", command, log_file, iounit)
4393 IF (.NOT. ref%keep_files .AND. len_trim(ref%guess_cli%json_file) > 0)
THEN
4394 CALL tb_delete_file(ref%guess_cli%json_file)
4398 IF (ref%param_cli%enabled)
THEN
4400 IF (ref%param_cli%method_explicit .OR. len_trim(ref%param_cli%input_file) == 0)
THEN
4401 method_str =
" --method "// &
4402 trim(tb_reference_method_name(merge(ref%param_cli%method, &
4403 dft_control%qs_control%xtb_control%tblite_method, &
4404 ref%param_cli%method_explicit)))
4407 IF (len_trim(ref%param_cli%output_file) > 0)
THEN
4408 output_str =
" --output "//trim(tb_shell_quote(ref%param_cli%output_file))
4410 log_file = trim(file_base)//
".param.log"
4411 command = trim(tb_shell_quote(ref%program_name))//
" param"// &
4412 trim(method_str)// &
4414 IF (len_trim(ref%param_cli%input_file) > 0)
THEN
4415 command = trim(command)//
" "//trim(tb_shell_quote(ref%param_cli%input_file))
4417 command = trim(command)//
" > "//trim(tb_shell_quote(log_file))//
" 2>&1"
4418 CALL tb_reference_cli_execute(ref,
"param", command, log_file, iounit)
4419 IF (.NOT. ref%keep_files .AND. len_trim(ref%param_cli%output_file) > 0)
THEN
4420 CALL tb_delete_file(ref%param_cli%output_file)
4424 IF (ref%fit_cli%enabled)
THEN
4426 IF (ref%fit_cli%dry_run) dry_run_str =
" --dry-run"
4428 IF (len_trim(ref%fit_cli%copy_file) > 0)
THEN
4429 copy_str =
" --copy "//trim(tb_shell_quote(ref%fit_cli%copy_file))
4431 log_file = trim(file_base)//
".fit.log"
4432 command = trim(tb_shell_quote(ref%program_name))//
" fit"// &
4433 trim(dry_run_str)// &
4435 trim(verbosity_str)//
" "//trim(tb_shell_quote(ref%fit_cli%param_file))// &
4436 " "//trim(tb_shell_quote(ref%fit_cli%input_file))// &
4437 " > "//trim(tb_shell_quote(log_file))//
" 2>&1"
4438 CALL tb_reference_cli_execute(ref,
"fit", command, log_file, iounit)
4439 IF (.NOT. ref%keep_files .AND. len_trim(ref%fit_cli%copy_file) > 0)
THEN
4440 CALL tb_delete_file(ref%fit_cli%copy_file)
4444 IF (ref%tagdiff_cli%enabled)
THEN
4446 IF (ref%tagdiff_cli%fit) method_str =
" --fit"
4447 log_file = trim(file_base)//
".tagdiff.log"
4448 command = trim(tb_shell_quote(ref%program_name))//
" tagdiff"// &
4449 trim(method_str)//
" "//trim(tb_shell_quote(ref%tagdiff_cli%actual_file))// &
4450 " "//trim(tb_shell_quote(ref%tagdiff_cli%reference_file))// &
4451 " > "//trim(tb_shell_quote(log_file))//
" 2>&1"
4452 CALL tb_reference_cli_execute(ref,
"tagdiff", command, log_file, iounit)
4455 END SUBROUTINE tb_reference_cli_aux_commands
4465 SUBROUTINE tb_reference_cli_execute(ref, label, command, log_file, iounit)
4468 CHARACTER(LEN=*),
INTENT(IN) :: label, command, log_file
4469 INTEGER,
INTENT(IN) :: iounit
4471 INTEGER :: cmdstat, exitstat
4475 CALL execute_command_line(trim(command), exitstat=exitstat, cmdstat=cmdstat)
4476 IF (cmdstat /= 0 .OR. exitstat /= 0)
THEN
4477 WRITE (unit=iounit, fmt=
"(/,T2,A,A)")
"tblite reference CLI auxiliary command failed: ", &
4479 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Command: ", trim(command)
4480 WRITE (unit=iounit, fmt=
"(T2,A,I0,T32,A,I0)")
"cmdstat:", cmdstat,
"exitstat:", exitstat
4481 IF (ref%stop_on_error) cpabort(
"tblite reference CLI auxiliary command failed")
4483 WRITE (unit=iounit, fmt=
"(/,T2,A,A)")
"tblite reference CLI auxiliary command completed: ", &
4485 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Log file: ", trim(log_file)
4487 IF (.NOT. ref%keep_files)
CALL tb_delete_file(log_file)
4489 END SUBROUTINE tb_reference_cli_execute
4497 FUNCTION tb_join_path(directory, filename)
RESULT(path)
4498 CHARACTER(LEN=*),
INTENT(IN) :: directory, filename
4499 CHARACTER(LEN=default_path_length) :: path
4501 IF (len_trim(directory) == 0 .OR. trim(directory) ==
".")
THEN
4502 path = trim(filename)
4503 ELSE IF (directory(len_trim(directory):len_trim(directory)) ==
"/")
THEN
4504 path = trim(directory)//trim(filename)
4506 path = trim(directory)//
"/"//trim(filename)
4509 END FUNCTION tb_join_path
4516 FUNCTION tb_shell_quote(text)
RESULT(quoted)
4517 CHARACTER(LEN=*),
INTENT(IN) :: text
4518 CHARACTER(LEN=4*default_path_length) :: quoted
4523 DO i = 1, len_trim(text)
4524 IF (text(i:i) ==
"'")
THEN
4525 quoted = trim(quoted)//
"'\\''"
4527 quoted = trim(quoted)//text(i:i)
4530 quoted = trim(quoted)//
"'"
4532 END FUNCTION tb_shell_quote
4539 SUBROUTINE tb_write_reference_gen(qs_env, filename)
4542 CHARACTER(LEN=*),
INTENT(IN) :: filename
4544 CHARACTER(LEN=2),
ALLOCATABLE,
DIMENSION(:) :: symbols, unique_symbols
4545 INTEGER :: iatom, ikind, ios, natom, nuniq, unit_nr
4546 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: species
4547 INTEGER,
DIMENSION(3) :: periodic
4549 REAL(kind=
dp) :: to_angstrom
4553 NULLIFY (cell, particle_set)
4554 CALL get_qs_env(qs_env=qs_env, cell=cell, particle_set=particle_set)
4556 natom =
SIZE(particle_set)
4558 ALLOCATE (symbols(natom), unique_symbols(natom), species(natom))
4561 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, element_symbol=symbols(iatom))
4564 IF (trim(unique_symbols(ikind)) == trim(symbols(iatom)))
THEN
4569 IF (.NOT. found)
THEN
4571 unique_symbols(nuniq) = symbols(iatom)
4574 species(iatom) = ikind
4577 OPEN (newunit=unit_nr, file=trim(filename), status=
"REPLACE", action=
"WRITE", &
4578 form=
"FORMATTED", iostat=ios)
4579 IF (ios /= 0) cpabort(
"Could not open tblite reference CLI geometry file")
4581 CALL get_cell(cell=cell, periodic=periodic)
4582 IF (any(periodic == 1))
THEN
4583 WRITE (unit=unit_nr, fmt=
"(I0,1X,A)") natom,
"S"
4585 WRITE (unit=unit_nr, fmt=
"(I0,1X,A)") natom,
"C"
4587 WRITE (unit=unit_nr, fmt=
"(*(A,1X))") (trim(unique_symbols(ikind)), ikind=1, nuniq)
4589 WRITE (unit=unit_nr, fmt=
"(I0,1X,I0,3(1X,ES24.16))") &
4590 iatom, species(iatom), particle_set(iatom)%r(:)*to_angstrom
4592 IF (any(periodic == 1))
THEN
4593 WRITE (unit=unit_nr, fmt=
"(3(1X,ES24.16))") 0.0_dp, 0.0_dp, 0.0_dp
4595 WRITE (unit=unit_nr, fmt=
"(3(1X,ES24.16))") cell%hmat(:, ikind)*to_angstrom
4600 DEALLOCATE (symbols, unique_symbols, species)
4602 END SUBROUTINE tb_write_reference_gen
4615 SUBROUTINE tb_read_reference_grad(filename, natom, energy, gradient, virial, &
4616 have_energy, have_gradient, have_virial)
4618 CHARACTER(LEN=*),
INTENT(IN) :: filename
4619 INTEGER,
INTENT(IN) :: natom
4620 REAL(kind=
dp),
INTENT(OUT) :: energy
4621 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(OUT) :: gradient, virial
4622 LOGICAL,
INTENT(OUT) :: have_energy, have_gradient, have_virial
4624 CHARACTER(LEN=1024) :: line
4625 INTEGER :: ios, nread, unit_nr
4627 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: values
4629 have_energy = .false.
4630 have_gradient = .false.
4631 have_virial = .false.
4636 INQUIRE (file=trim(filename), exist=exists)
4637 IF (.NOT. exists)
RETURN
4639 OPEN (newunit=unit_nr, file=trim(filename), status=
"OLD", action=
"READ", &
4640 form=
"FORMATTED", iostat=ios)
4641 IF (ios /= 0)
RETURN
4644 READ (unit=unit_nr, fmt=
"(A)", iostat=ios) line
4646 IF (index(line,
"energy :real:0:") > 0)
THEN
4647 READ (unit=unit_nr, fmt=
"(A)", iostat=ios) line
4649 READ (line, *, iostat=ios) energy
4650 have_energy = ios == 0
4652 ELSE IF (index(line,
"gradient :real:2:3,") > 0)
THEN
4653 ALLOCATE (values(3*natom))
4654 CALL tb_read_real_values(unit_nr, values, nread)
4655 IF (nread == 3*natom)
THEN
4656 CALL tb_values_to_matrix(values, gradient)
4657 have_gradient = .true.
4660 ELSE IF (index(line,
"virial :real:2:3,3") > 0)
THEN
4661 ALLOCATE (values(9))
4662 CALL tb_read_real_values(unit_nr, values, nread)
4663 IF (nread == 9)
THEN
4664 CALL tb_values_to_matrix(values, virial)
4665 have_virial = .true.
4672 END SUBROUTINE tb_read_reference_grad
4680 SUBROUTINE tb_read_real_values(unit_nr, values, nread)
4682 INTEGER,
INTENT(IN) :: unit_nr
4683 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: values
4684 INTEGER,
INTENT(OUT) :: nread
4686 CHARACTER(LEN=1024) :: line
4690 DO WHILE (nread <
SIZE(values))
4691 READ (unit=unit_nr, fmt=
"(A)", iostat=ios) line
4693 CALL tb_parse_real_line(line, values, nread)
4696 END SUBROUTINE tb_read_real_values
4704 SUBROUTINE tb_parse_real_line(line, values, nread)
4706 CHARACTER(LEN=*),
INTENT(IN) :: line
4707 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: values
4708 INTEGER,
INTENT(INOUT) :: nread
4710 CHARACTER(LEN=128) :: token
4711 INTEGER :: first, ios, last, pos
4714 DO WHILE (pos <= len_trim(line) .AND. nread <
SIZE(values))
4715 DO WHILE (pos <= len_trim(line) .AND. index(
" ,[]", line(pos:pos)) > 0)
4718 IF (pos > len_trim(line))
EXIT
4720 DO WHILE (pos <= len_trim(line) .AND. index(
" ,[]", line(pos:pos)) == 0)
4724 token = line(first:last)
4725 READ (token, *, iostat=ios) values(nread + 1)
4726 IF (ios == 0) nread = nread + 1
4729 END SUBROUTINE tb_parse_real_line
4736 SUBROUTINE tb_values_to_matrix(values, matrix)
4738 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: values
4739 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(OUT) :: matrix
4744 DO j = 1,
SIZE(matrix, 2)
4745 DO i = 1,
SIZE(matrix, 1)
4747 matrix(i, j) = values(n)
4751 END SUBROUTINE tb_values_to_matrix
4762 SUBROUTINE tb_reference_cleanup(ref, gen_file, grad_file, json_file, log_file, post_processing_output_file)
4765 CHARACTER(LEN=*),
INTENT(IN) :: gen_file, grad_file, json_file, &
4766 log_file, post_processing_output_file
4768 IF (ref%keep_files)
RETURN
4769 CALL tb_delete_file(gen_file)
4770 CALL tb_delete_file(grad_file)
4771 CALL tb_delete_file(json_file)
4772 CALL tb_delete_file(log_file)
4773 IF (len_trim(post_processing_output_file) > 0)
THEN
4774 CALL tb_delete_file(post_processing_output_file)
4777 END SUBROUTINE tb_reference_cleanup
4783 SUBROUTINE tb_delete_file(filename)
4785 CHARACTER(LEN=*),
INTENT(IN) :: filename
4787 INTEGER :: ios, unit_nr
4790 INQUIRE (file=trim(filename), exist=exists)
4791 IF (.NOT. exists)
RETURN
4792 OPEN (newunit=unit_nr, file=trim(filename), status=
"OLD", iostat=ios)
4793 IF (ios == 0)
CLOSE (unit_nr, status=
"DELETE")
4795 END SUBROUTINE tb_delete_file
4803 SUBROUTINE tb_dump_sigma_component(label, sigma, para_env)
4805 CHARACTER(LEN=*),
INTENT(IN) :: label
4806 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: sigma
4809 CHARACTER(LEN=default_path_length) :: dump_file
4810 INTEGER :: dump_status, dump_unit, i
4813#if defined(__TBLITE_DEBUG_DIAGNOSTICS)
4814 CALL get_environment_variable(
"CP2K_TBLITE_SIGMA_COMPONENT_DUMP", dump_file, status=dump_status)
4816 IF (dump_status /= 0)
RETURN
4818 OPEN (newunit=dump_unit, file=trim(dump_file), status=
"UNKNOWN", &
4819 position=
"APPEND", action=
"WRITE")
4820 WRITE (dump_unit,
"(A)") trim(label)
4822 WRITE (dump_unit,
"(3(1X,ES24.16))") sigma(i, :)/para_env%num_pe
4826 END SUBROUTINE tb_dump_sigma_component
4834 SUBROUTINE tb_add_stress(qs_env, tb, para_env)
4840 CHARACTER(LEN=default_path_length) :: dump_file
4841 INTEGER :: dump_status, dump_unit, i
4842 INTEGER,
DIMENSION(3) :: periodic
4846 NULLIFY (virial, cell)
4847 CALL get_qs_env(qs_env=qs_env, virial=virial, cell=cell)
4848 CALL get_cell(cell=cell, periodic=periodic)
4850 IF (all(periodic == 0))
THEN
4851 CALL cp_warn(__location__, &
4852 "tblite stress tensor requested for an isolated system. "// &
4853 "The reported virial is useful for finite-difference checks, "// &
4854 "but it is not a physically meaningful bulk stress for an isolated molecule.")
4858#if defined(__TBLITE_DEBUG_DIAGNOSTICS)
4859 CALL get_environment_variable(
"CP2K_TBLITE_VIRIAL_DUMP", dump_file, status=dump_status)
4861 IF (dump_status == 0)
THEN
4862 OPEN (newunit=dump_unit, file=trim(dump_file), status=
"UNKNOWN", &
4863 position=
"APPEND", action=
"WRITE")
4864 WRITE (dump_unit,
"(A)")
"sigma"
4866 WRITE (dump_unit,
"(3(1X,ES24.16))") tb%sigma(i, :)/para_env%num_pe
4871 virial%pv_virial = virial%pv_virial - tb%sigma/para_env%num_pe
4873 END SUBROUTINE tb_add_stress
4882 SUBROUTINE tb_add_grad(grad, deriv, dE, natom)
4884 REAL(kind=
dp),
DIMENSION(:, :) :: grad
4885 REAL(kind=
dp),
DIMENSION(:, :, :) :: deriv
4886 REAL(kind=
dp),
DIMENSION(:) :: de
4893 grad(:, i) = grad(:, i) + deriv(:, i, j)*de(j)
4897 END SUBROUTINE tb_add_grad
4906 SUBROUTINE tb_add_sig(sig, deriv, dE, natom)
4908 REAL(kind=
dp),
DIMENSION(:, :) :: sig
4909 REAL(kind=
dp),
DIMENSION(:, :, :) :: deriv
4910 REAL(kind=
dp),
DIMENSION(:) :: de
4917 sig(:, i) = sig(:, i) + deriv(:, i, j)*de(j)
4921 END SUBROUTINE tb_add_sig
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
static GRID_HOST_DEVICE int idx(const orbital a)
Return coset index of given orbital angular momentum.
Set of routines to: Contract integrals over primitive Gaussians Decontract (density) matrices Trace m...
Calculation of the overlap integrals over Cartesian Gaussian-type functions.
subroutine, public overlap_ab(la_max, la_min, npgfa, rpgfa, zeta, lb_max, lb_min, npgfb, rpgfb, zetb, rab, sab, dab, ddab)
Calculation of the two-center overlap integrals [a|b] over Cartesian Gaussian-type functions....
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Holds information on atomic properties.
subroutine, public process_gto_basis(gto_basis_set, do_ortho, nset, maxl)
...
subroutine, public allocate_gto_basis_set(gto_basis_set)
...
subroutine, public write_gto_basis_set(gto_basis_set, output_unit, header)
Write a Gaussian-type orbital (GTO) basis set data set to the output unit.
collect pointers to a block of reals
Handles all functions related to the CELL.
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_print(matrix, variable_name, unit_nr)
Prints given matrix in matlab format (only present blocks).
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_alloc_block_from_nbl(matrix, sab_orb, desymmetrize)
allocate the blocks of a dbcsr based on the neighbor list
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_write_sparse_matrix(sparse_matrix, before, after, qs_env, para_env, first_row, last_row, first_col, last_col, scale, output_unit, omit_headers, cartesian_basis)
...
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public debug_print_level
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public high_print_level
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...
integer, parameter, public silent_print_level
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Types and basic routines needed for a kpoint calculation.
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.
Utility routines for the memory handling.
Interface to the message passing library MPI.
compute mulliken charges we (currently) define them as c_i = 1/2 [ (PS)_{ii} + (SP)_{ii} ]
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
Define the data structure for the particle information.
subroutine, public charge_mixing(mixing_method, mixing_store, charges, para_env, iter_count, scc_mixer, tblite_mixer_iterations, tblite_mixer_damping, tblite_mixer_memory, tblite_mixer_omega0, tblite_mixer_min_weight, tblite_mixer_max_weight, tblite_mixer_weight_factor)
Driver for TB SCC variable mixing, calls the requested method.
Calculation of overlap matrix condition numbers.
subroutine, public overlap_condnum(matrixkp_s, condnum, iunit, norml1, norml2, use_arnoldi, blacs_env)
Calculation of the overlap matrix Condition Number.
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 total_qs_force(force, qs_force, atomic_kind_set)
Get current total force.
Some utility functions for the calculation of integrals.
subroutine, public basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
Set up an easy accessible list of the basis sets for all kinds.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
subroutine, public set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env)
...
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
Calculation of overlap matrix, its derivatives and forces.
subroutine, public build_overlap_matrix(ks_env, matrix_s, matrixkp_s, matrix_name, nderivative, basis_type_a, basis_type_b, sab_nl, calculate_forces, matrix_p, matrixkp_p, ext_kpoints)
Calculation of the overlap matrix over Cartesian Gaussian functions.
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...
module that contains the definitions of the scf types
parameters that control an scf iteration
Utilities for string manipulations.
subroutine, public integer_to_string(inumber, string)
Converts an integer number to a string. The WRITE statement will return an error message,...
logical function, public tb_native_scc_mixer_active(dft_control)
Return whether the tblite native SCC mixer is active for this run.
subroutine, public tb_ham_add_coulomb(qs_env, tb, dft_control)
...
subroutine, public tb_init_wf(tb, dft_control)
initialize wavefunction ...
subroutine, public tb_update_charges(qs_env, dft_control, tb, calculate_forces, use_rho)
...
subroutine, public tb_init_geometry(qs_env, tb)
intialize geometry objects ...
subroutine, public build_tblite_matrices(qs_env, calculate_forces)
...
subroutine, public tb_get_energy(qs_env, tb, energy)
...
subroutine, public tb_set_calculator(tb, typ, accuracy, param_file)
...
subroutine, public tb_derive_dh_off(qs_env, use_rho, nimg)
Add SCC-overlap and direct multipole Hamiltonian derivatives.
subroutine, public tb_get_multipole(qs_env, tb)
...
subroutine, public tb_reference_cli_compare(qs_env)
Run native tblite CLI and compare against CP2K/tblite.
real(kind=dp) function, public tb_scf_mixer_error(dft_control, tb, eps_scf)
Return the native tblite SCC mixer residual on the CP2K iter_delta scale.
subroutine, public tb_get_basis(tb, gto_basis_set, element_symbol, param, occ)
...
CP2K-side tblite-compatible SCC Broyden mixer.
subroutine, public allocate_tblite_type(tb_tblite)
...
subroutine, public deallocate_tblite_type(tb_tblite)
...
Definition of the xTB parameter types.
subroutine, public get_xtb_atom_param(xtb_parameter, symbol, aname, typ, defined, z, zeff, natorb, lmax, nao, lao, rcut, rcov, kx, eta, xgamma, alpha, zneff, nshell, nval, lval, kpoly, kappa, wall, hen, zeta, xi, kappa0, alpg, occupation, electronegativity, chmax, en, kqat2, kcn, kq)
...
Provides all information about an atomic kind.
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 information about kpoints.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.