17 USE mctc_env,
ONLY: error_type
18 USE mctc_io,
ONLY: new
19 USE mctc_io_symbols,
ONLY: symbol_to_number
20 USE tblite_basis_type,
ONLY: get_cutoff
21 USE tblite_container_cache,
ONLY: container_cache
22 USE tblite_container_type,
ONLY: container_type
23 USE tblite_data_spin,
ONLY: get_spin_constant
24 USE tblite_integral_native_integrals,
ONLY: multipole_cgto, multipole_grad_cgto, overlap_grad_cgto, msao
25 USE tblite_partition,
ONLY: work_partition, new_work_partition
26 USE tblite_scf,
ONLY: get_mixer_dimension
27 USE tblite_scf_info,
ONLY: scf_info, atom_resolved, shell_resolved
28 USE tblite_scf_potential,
ONLY: new_potential
29 USE tblite_spin,
ONLY: spin_polarization, new_spin_polarization
30 USE tblite_wavefunction_type,
ONLY: new_wavefunction
31 USE tblite_xtb_calculator,
ONLY: new_xtb_calculator
32 USE tblite_xtb_gfn1,
ONLY: new_gfn1_calculator
33 USE tblite_xtb_gfn2,
ONLY: new_gfn2_calculator
34 USE tblite_xtb_h0,
ONLY: get_selfenergy, get_occupation, tb_hamiltonian
35 USE tblite_xtb_ipea1,
ONLY: new_ipea1_calculator
93#include "../base/base_uses.f90"
98 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'tblite_interface'
100 INTEGER,
PARAMETER :: dip_n = 3
101 INTEGER,
PARAMETER :: quad_n = 6
102 REAL(KIND=
dp),
PARAMETER :: same_atom = 0.00001_dp
121 PURE FUNCTION tb_spin_project(values, ispin)
RESULT(value)
123 REAL(KIND=
dp),
DIMENSION(:),
INTENT(IN) :: values
124 INTEGER,
INTENT(IN) :: ispin
125 REAL(KIND=
dp) ::
value
128 IF (
SIZE(values) > 1)
THEN
131 value = values(1) + values(2)
133 value = values(1) - values(2)
139 END FUNCTION tb_spin_project
146 SUBROUTINE tb_store_density_ref(tb, matrix_p)
148 TYPE(tblite_type),
POINTER :: tb
149 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
151 INTEGER :: img, ispin, nimg, nspin
153 nspin =
SIZE(matrix_p, 1)
154 nimg =
SIZE(matrix_p, 2)
155 IF (
ASSOCIATED(tb%rho_ao_kp_ref))
THEN
156 IF (
SIZE(tb%rho_ao_kp_ref, 1) /= nspin .OR.
SIZE(tb%rho_ao_kp_ref, 2) /= nimg)
THEN
160 IF (.NOT.
ASSOCIATED(tb%rho_ao_kp_ref))
THEN
164 ALLOCATE (tb%rho_ao_kp_ref(ispin, img)%matrix)
170 CALL dbcsr_copy(tb%rho_ao_kp_ref(ispin, img)%matrix, matrix_p(ispin, img)%matrix)
174 END SUBROUTINE tb_store_density_ref
189 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tblite_init_geometry'
193 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
194 INTEGER :: iatom, natom
195 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: xyz
196 INTEGER :: handle, ikind
197 INTEGER,
DIMENSION(3) :: periodic
198 LOGICAL,
DIMENSION(3) :: lperiod
200 CALL timeset(routinen, handle)
203 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, cell=cell, qs_kind_set=qs_kind_set)
206 natom =
SIZE(particle_set)
207 ALLOCATE (xyz(3, natom))
209 ALLOCATE (tb%el_num(natom))
212 xyz(:, iatom) = particle_set(iatom)%r(:)
213 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind)
214 CALL get_qs_kind(qs_kind_set(ikind), zatom=tb%el_num(iatom))
215 IF (tb%el_num(iatom) < 1 .OR. tb%el_num(iatom) > 85)
THEN
216 cpabort(
"only elements 1-85 are supported by tblite")
221 CALL get_cell(cell=cell, periodic=periodic)
222 lperiod(1) = periodic(1) == 1
223 lperiod(2) = periodic(2) == 1
224 lperiod(3) = periodic(3) == 1
227 CALL new(tb%mol, tb%el_num, xyz, lattice=cell%hmat, periodic=lperiod)
231 CALL timestop(handle)
236 cpabort(
"Built without TBLITE")
246 SUBROUTINE tb_update_geometry(qs_env, tb)
253 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tblite_update_geometry'
257 INTEGER :: iatom, natom
260 CALL timeset(routinen, handle)
264 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, cell=cell)
267 natom =
SIZE(particle_set)
269 tb%mol%xyz(:, iatom) = particle_set(iatom)%r(:)
271 tb%mol%lattice(:, :) = cell%hmat
273 CALL timestop(handle)
278 cpabort(
"Built without TBLITE")
281 END SUBROUTINE tb_update_geometry
297 TYPE(scf_info) :: info
299 nspin = dft_control%nspins
300 IF (nspin /= 1 .AND. nspin /= 2) cpabort(
"tblite supports only one or two spin channels")
302 tb%mol%charge = dft_control%charge
303 tb%mol%uhf = max(0, dft_control%multiplicity - 1)
304 IF (nspin == 2)
CALL tb_add_spin_polarization(tb)
306 info = tb%calc%variable_info()
307 IF (info%charge > shell_resolved) cpabort(
"tblite: no support for orbital resolved charge")
308 IF (info%dipole > atom_resolved) cpabort(
"tblite: no support for shell resolved dipole moment")
309 IF (info%quadrupole > atom_resolved)
THEN
310 cpabort(
"tblite: no support shell resolved quadrupole moment")
313 CALL new_wavefunction(tb%wfn, tb%mol%nat, tb%calc%bas%nsh, tb%calc%bas%nao, nspin, 0.0_dp)
314 CALL get_occupation(tb%mol, tb%calc%bas, tb%calc%h0, tb%wfn%nocc, tb%wfn%n0at, tb%wfn%n0sh)
315 CALL tb_reset_mixer(tb)
317 CALL new_potential(tb%pot, tb%mol, tb%calc%bas, tb%wfn%nspin)
320 ALLOCATE (tb%e_hal(tb%mol%nat), tb%e_rep(tb%mol%nat), tb%e_disp(tb%mol%nat))
321 ALLOCATE (tb%e_scd(tb%mol%nat), tb%e_es(tb%mol%nat), tb%e_int(tb%mol%nat))
322 ALLOCATE (tb%selfenergy(tb%calc%bas%nsh))
323 IF (
ALLOCATED(tb%calc%ncoord))
ALLOCATE (tb%cn(tb%mol%nat))
327 mark_used(dft_control)
328 cpabort(
"Built without TBLITE")
338 SUBROUTINE tb_add_spin_polarization(tb)
342 CLASS(container_type),
ALLOCATABLE :: cont
343 TYPE(spin_polarization),
ALLOCATABLE :: spin
344 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: wll
347 CALL tb_get_spin_constants(tb, wll)
348 CALL new_spin_polarization(spin, tb%mol, wll, tb%calc%bas%nsh_id)
349 CALL move_alloc(spin, cont)
350 CALL tb%calc%push_back(cont)
352 END SUBROUTINE tb_add_spin_polarization
359 SUBROUTINE tb_get_spin_constants(tb, wll)
362 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :), &
365 INTEGER :: il, ish, izp, jl, jsh, max_shell
367 max_shell = maxval(tb%calc%bas%nsh_id)
368 ALLOCATE (wll(max_shell, max_shell, tb%mol%nid))
370 DO izp = 1, tb%mol%nid
371 DO ish = 1, tb%calc%bas%nsh_id(izp)
372 il = tb%calc%bas%cgto(ish, izp)%ang
373 DO jsh = 1, tb%calc%bas%nsh_id(izp)
374 jl = tb%calc%bas%cgto(jsh, izp)%ang
375 wll(jsh, ish, izp) = get_spin_constant(jl, il, tb%mol%num(izp))
380 END SUBROUTINE tb_get_spin_constants
387 SUBROUTINE tb_reset_mixer(tb)
393 TYPE(scf_info) :: info
395 info = tb%calc%variable_info()
396 IF (
ALLOCATED(tb%mixer))
DEALLOCATE (tb%mixer)
397 CALL new_cp2k_tblite_mixer(tb%mixer, tb%mixer_memory, &
398 tb%wfn%nspin*get_mixer_dimension(tb%mol, tb%calc%bas, info), &
399 tb%mixer_damping, tb%mixer_omega0, tb%mixer_min_weight, &
400 tb%mixer_max_weight, tb%mixer_weight_factor)
404 cpabort(
"Built without TBLITE")
407 END SUBROUTINE tb_reset_mixer
421 SUBROUTINE tb_configure_mixer(tb, iterations, memory, damping, omega0, min_weight, max_weight, &
422 weight_factor, solver)
425 INTEGER,
INTENT(IN) :: iterations, memory, solver
426 REAL(kind=
dp),
INTENT(IN) :: damping, max_weight, min_weight, omega0, &
431 IF (iterations < 1) cpabort(
"tblite SCC mixer ITERATIONS must be positive")
432 IF (memory < 1) cpabort(
"tblite SCC mixer MEMORY must be positive")
433 IF (damping <= 0.0_dp) cpabort(
"tblite SCC mixer damping must be positive")
434 IF (omega0 <= 0.0_dp) cpabort(
"tblite SCC mixer OMEGA0 must be positive")
435 IF (min_weight <= 0.0_dp) cpabort(
"tblite SCC mixer MIN_WEIGHT must be positive")
436 IF (max_weight <= 0.0_dp) cpabort(
"tblite SCC mixer MAX_WEIGHT must be positive")
437 IF (max_weight < min_weight)
THEN
438 cpabort(
"tblite SCC mixer MAX_WEIGHT must not be smaller than MIN_WEIGHT")
440 IF (weight_factor <= 0.0_dp) cpabort(
"tblite SCC mixer WEIGHT_FACTOR must be positive")
444 cpabort(
"Unknown tblite SCC mixer SOLVER")
447 tb%calc%max_iter = iterations
448 tb%mixer_memory = memory
449 tb%mixer_damping = damping
450 tb%calc%mixer_input%damping = damping
451 tb%mixer_omega0 = omega0
452 tb%mixer_min_weight = min_weight
453 tb%mixer_max_weight = max_weight
454 tb%mixer_weight_factor = weight_factor
458 mark_used(iterations)
462 mark_used(min_weight)
463 mark_used(max_weight)
464 mark_used(weight_factor)
466 cpabort(
"Built without TBLITE")
469 END SUBROUTINE tb_configure_mixer
479 LOGICAL :: use_native_mixer
481 use_native_mixer = .false.
482 IF (.NOT.
ASSOCIATED(dft_control))
RETURN
483 IF (dft_control%qs_control%do_ls_scf)
RETURN
485 SELECT CASE (dft_control%qs_control%xtb_control%tblite_scc_mixer)
487 use_native_mixer = .true.
489 use_native_mixer = .true.
491 use_native_mixer = .false.
493 cpabort(
"Unknown tblite SCC mixer")
509 REAL(kind=
dp),
INTENT(IN) :: eps_scf
510 REAL(kind=
dp) :: mixer_error
513 REAL(kind=
dp) :: raw_error
519 IF (.NOT.
ASSOCIATED(tb))
RETURN
521 IF (
ALLOCATED(tb%mixer))
THEN
522 raw_error = real(tb%mixer%get_error(), kind=
dp)
524 raw_error, eps_scf, &
528 mark_used(dft_control)
546 REAL(kind=
dp),
INTENT(IN) :: accuracy
547 CHARACTER(LEN=*),
INTENT(IN) :: param_file
551 TYPE(error_type),
ALLOCATABLE :: error
553 IF (
ALLOCATED(tb%param))
DEALLOCATE (tb%param)
554 IF (len_trim(param_file) > 0)
THEN
556 CALL tb%param%load(trim(param_file), error)
557 IF (
ALLOCATED(error)) cpabort(
"Could not load tblite PARAM file: "//trim(param_file))
558 CALL new_xtb_calculator(tb%calc, tb%mol, tb%param, error)
562 cpabort(
"Unknown xtb type")
564 CALL new_gfn1_calculator(tb%calc, tb%mol, error)
566 CALL new_gfn2_calculator(tb%calc, tb%mol, error)
568 CALL new_ipea1_calculator(tb%calc, tb%mol, error)
571 IF (
ALLOCATED(error)) cpabort(
"tblite calculator setup failed")
573 tb%accuracy = accuracy
579 mark_used(param_file)
580 cpabort(
"Built without TBLITE")
593 LOGICAL,
INTENT(IN) :: calculate_forces
597 TYPE(container_cache) :: hcache, rcache
598 TYPE(error_type),
ALLOCATABLE :: error
599 TYPE(work_partition) :: partition
604 CALL timeset(
"tb_init_ham", handle)
605 CALL get_qs_env(qs_env=qs_env, tb_tblite=tb, para_env=para_env)
606 CALL tb_update_geometry(qs_env, tb)
608 IF (calculate_forces)
THEN
609 IF (.NOT.
ALLOCATED(tb%grad))
ALLOCATE (tb%grad(3, tb%mol%nat))
610 IF (.NOT.
ALLOCATED(tb%dsedcn))
ALLOCATE (tb%dsedcn(tb%calc%bas%nsh))
611 IF (
ALLOCATED(tb%calc%ncoord))
THEN
612 IF (.NOT.
ALLOCATED(tb%dcndr))
ALLOCATE (tb%dcndr(3, tb%mol%nat, tb%mol%nat))
613 IF (.NOT.
ALLOCATED(tb%dcndL))
ALLOCATE (tb%dcndL(3, 3, tb%mol%nat))
616 IF (
ALLOCATED(tb%grad))
DEALLOCATE (tb%grad)
617 IF (
ALLOCATED(tb%dsedcn))
DEALLOCATE (tb%dsedcn)
618 IF (
ALLOCATED(tb%dcndr))
DEALLOCATE (tb%dcndr)
619 IF (
ALLOCATED(tb%dcndL))
DEALLOCATE (tb%dcndL)
623 CALL new_work_partition(error, partition, para_env%mepos, para_env%num_pe)
624 IF (
ALLOCATED(error)) cpabort(error%message)
625 CALL tb%calc%set_partition(partition)
633 IF (
ALLOCATED(tb%calc%halogen))
THEN
634 CALL tb%calc%halogen%update(tb%mol, hcache)
635 IF (
ALLOCATED(tb%grad))
THEN
637 CALL tb%calc%halogen%get_engrad(tb%mol, hcache, tb%e_hal, &
639 CALL tb_grad2force(qs_env, tb, para_env, 0, replicated=.false.)
641 CALL tb%calc%halogen%get_engrad(tb%mol, hcache, tb%e_hal)
645 IF (
ALLOCATED(tb%calc%repulsion))
THEN
646 CALL tb%calc%repulsion%update(tb%mol, rcache)
647 IF (
ALLOCATED(tb%grad))
THEN
649 CALL tb%calc%repulsion%get_engrad(tb%mol, rcache, tb%e_rep, &
651 CALL tb_grad2force(qs_env, tb, para_env, 1, replicated=.false.)
653 CALL tb%calc%repulsion%get_engrad(tb%mol, rcache, tb%e_rep)
657 IF (
ALLOCATED(tb%calc%dispersion))
THEN
658 CALL tb%calc%dispersion%update(tb%mol, tb%dcache)
659 IF (
ALLOCATED(tb%grad))
THEN
661 CALL tb%calc%dispersion%get_engrad(tb%mol, tb%dcache, tb%e_disp, &
663 CALL tb_grad2force(qs_env, tb, para_env, 2, replicated=.false.)
665 CALL tb%calc%dispersion%get_engrad(tb%mol, tb%dcache, tb%e_disp)
669 IF (
ALLOCATED(tb%calc%interactions))
THEN
670 CALL tb%calc%interactions%update(tb%mol, tb%icache)
673 IF (
ALLOCATED(tb%calc%coulomb))
THEN
674 CALL tb%calc%coulomb%update(tb%mol, tb%cache)
677 IF (
ALLOCATED(tb%grad))
THEN
678 IF (
ALLOCATED(tb%calc%ncoord))
THEN
679 CALL tb%calc%ncoord%get_cn(tb%mol, tb%cn, tb%dcndr, tb%dcndL)
682 IF (
ALLOCATED(tb%calc%ncoord))
THEN
683 CALL tb%calc%ncoord%get_cn(tb%mol, tb%cn)
687 CALL get_selfenergy(tb%calc%h0, tb%mol%id, tb%calc%bas%ish_at, &
688 tb%calc%bas%nsh_id, cn=tb%cn, selfenergy=tb%selfenergy, dsedcn=tb%dsedcn)
690 CALL timestop(handle)
694 mark_used(calculate_forces)
695 cpabort(
"Built without TBLITE")
718 REAL(kind=
dp) :: xtb_inter
719 REAL(kind=
dp),
DIMENSION(6) :: contributions
720 NULLIFY (scf_section, logger)
727 CALL get_qs_env(qs_env=qs_env, para_env=para_env)
728 contributions = [sum(tb%e_rep), sum(tb%e_es), sum(tb%e_disp), &
729 sum(tb%e_scd), sum(tb%e_hal), sum(tb%e_int)]
730 CALL para_env%sum(contributions)
731 energy%repulsive = contributions(1)
732 energy%el_stat = contributions(2)
733 energy%dispersion = contributions(3)
734 energy%dispersion_sc = contributions(4)
735 energy%xtb_xb_inter = contributions(5)
736 xtb_inter = contributions(6)
738 energy%total = energy%core + energy%repulsive + energy%el_stat + energy%dispersion &
739 + energy%dispersion_sc + energy%xtb_xb_inter + xtb_inter &
740 + energy%kTS + energy%efield + energy%qmmm_el
745 WRITE (unit=iounit, fmt=
"(/,(T9,A,T60,F20.10))") &
746 "Repulsive pair potential energy: ", energy%repulsive, &
747 "Zeroth order Hamiltonian energy: ", energy%core, &
748 "Electrostatic energy: ", energy%el_stat, &
749 "Self-consistent dispersion energy: ", energy%dispersion_sc, &
750 "Non-self consistent dispersion energy: ", energy%dispersion
751 IF (abs(energy%xtb_xb_inter) > 1.e-9_dp)
THEN
752 WRITE (unit=iounit, fmt=
"(T9,A,T60,F20.10)") &
753 "Correction for halogen bonding: ", energy%xtb_xb_inter
755 IF (abs(xtb_inter) > 1.e-9_dp)
THEN
756 WRITE (unit=iounit, fmt=
"(T9,A,T60,F20.10)") &
757 "Additional interaction (e.g. spin): ", xtb_inter
759 IF (abs(energy%efield) > 1.e-9_dp)
THEN
760 WRITE (unit=iounit, fmt=
"(T9,A,T60,F20.10)") &
761 "Electric field interaction energy: ", energy%efield
763 IF (qs_env%qmmm)
THEN
764 WRITE (unit=iounit, fmt=
"(T9,A,T60,F20.10)") &
765 "QM/MM Electrostatic energy: ", energy%qmmm_el
769 "PRINT%DETAILED_ENERGY")
775 cpabort(
"Built without TBLITE")
792 CHARACTER(len=2),
INTENT(IN) :: element_symbol
794 INTEGER,
DIMENSION(5),
INTENT(out) :: occ
798 REAL(kind=
dp) :: docc
799 CHARACTER(LEN=default_string_length) :: sng
800 INTEGER :: ang, i_type, id_atom, ind_ao, ipgf, ish, &
801 ishell, ityp, maxl, mprim, natorb, &
808 CALL symbol_to_number(i_type, element_symbol)
809 DO id_atom = 1, tb%mol%nat
810 IF (i_type == tb%el_num(id_atom))
EXIT
813 param%symbol = element_symbol
814 param%defined = .true.
815 ityp = tb%mol%id(id_atom)
818 nset = tb%calc%bas%nsh_id(ityp)
822 mprim = max(mprim, tb%calc%bas%cgto(ishell, ityp)%nprim)
829 gto_basis_set%name = element_symbol//
"_STO-"//trim(sng)//
"G"
830 gto_basis_set%nset = nset
834 CALL reallocate(gto_basis_set%nshell, 1, nset)
835 CALL reallocate(gto_basis_set%n, 1, 1, 1, nset)
836 CALL reallocate(gto_basis_set%l, 1, 1, 1, nset)
837 CALL reallocate(gto_basis_set%zet, 1, mprim, 1, nset)
838 CALL reallocate(gto_basis_set%gcc, 1, mprim, 1, 1, 1, nset)
843 ang = tb%calc%bas%cgto(ishell, ityp)%ang
844 natorb = natorb + (2*ang + 1)
845 param%lval(ishell) = ang
846 maxl = max(ang, maxl)
847 gto_basis_set%lmax(ishell) = ang
848 gto_basis_set%lmin(ishell) = ang
849 gto_basis_set%npgf(ishell) = tb%calc%bas%cgto(ishell, ityp)%nprim
850 gto_basis_set%nshell(ishell) = nshell
851 gto_basis_set%n(1, ishell) = ang + 1
852 gto_basis_set%l(1, ishell) = ang
853 DO ipgf = 1, gto_basis_set%npgf(ishell)
854 gto_basis_set%gcc(ipgf, 1, ishell) = tb%calc%bas%cgto(ishell, ityp)%coeff(ipgf)
855 gto_basis_set%zet(ipgf, ishell) = tb%calc%bas%cgto(ishell, ityp)%alpha(ipgf)
857 DO ipgf = 1, (2*ang + 1)
859 param%lao(ind_ao) = ang
860 param%nao(ind_ao) = ishell
868 param%rcut = get_cutoff(tb%calc%bas, tb%accuracy)
869 param%natorb = natorb
875 IF (tb%calc%bas%nsh_at(id_atom) > 5) cpabort(
"too many shells in tblite")
876 DO ish = 1, tb%calc%bas%nsh_at(id_atom)
877 occ(ish) = nint(tb%calc%h0%refocc(ish, ityp) + docc)
878 docc = docc + tb%calc%h0%refocc(ish, ityp) - real(occ(ish))
879 param%occupation(ish) = occ(ish)
881 IF (abs(docc) > 0.1_dp) cpabort(
"Getting occupation numbers from tblite fails")
882 param%zeff = sum(occ)
885 gto_basis_set%norm_type = 3
890 mark_used(gto_basis_set)
891 mark_used(element_symbol)
893 cpabort(
"Built without TBLITE")
906 LOGICAL,
INTENT(IN) :: calculate_forces
910 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_tblite_matrices'
912 INTEGER :: handle, maxder, maxsgf, nderivatives, nimg, img, nkind, i, &
913 ic, iw, iatom, jatom, ikind, jkind, iset, jset, n1, n2, icol, &
914 irow, ia, ib, sgfa, sgfb, ldsab, nseta, nsetb, &
915 natorb_a, natorb_b, raw_iatom, raw_jatom, &
917 LOGICAL :: found, norml1, norml2, use_arnoldi
918 REAL(kind=
dp) :: dr, dshpoly, ff, hij_base, r2, rr
919 REAL(kind=
dp) :: native_dot_tmp, native_cn_icol, native_cn_irow, &
921 INTEGER,
DIMENSION(3) :: cell
922 REAL(kind=
dp) :: hij, shpoly
923 REAL(kind=
dp),
DIMENSION(2) :: condnum
924 REAL(kind=
dp),
DIMENSION(3) :: native_h0_overlap_force, native_radial_force, raw_rij, rij
925 REAL(kind=
dp),
DIMENSION(3) :: pulay_force
926 REAL(kind=
dp),
DIMENSION(3, 3) :: native_radial_dot, pulay_virial
927 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
928 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
929 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: owork
930 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: native_cn_deriv_sum, local_cn_deriv
931 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: native_radial_force_sum, local_radial_force
932 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: oint, sint, hint
933 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :, :) :: radial_hint
934 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, lb_max, lb_min
935 INTEGER,
DIMENSION(:),
POINTER :: npgfa, npgfb, nsgfa, nsgfb
936 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
937 REAL(kind=
dp),
DIMENSION(:),
POINTER :: set_radius_a, set_radius_b
938 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: rpgfa, rpgfb, zeta, zetb, scon_a, scon_b
939 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: fblock, pblock, sblock, wblock
944 INTEGER,
PARAMETER :: nlock = 501
950 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_dh_native, matrix_h, matrix_p, matrix_s, matrix_w
961 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
964 TYPE(tb_hamiltonian),
POINTER :: h0
967 CALL timeset(routinen, handle)
969 NULLIFY (ks_env, energy, atomic_kind_set, qs_kind_set)
970 NULLIFY (matrix_dh_native, matrix_h, matrix_s, matrix_w, atprop, dft_control)
971 NULLIFY (sab_orb, sab_kp, rho, tb, kpoints, cell_to_index)
974 ks_env=ks_env, para_env=para_env, &
976 atomic_kind_set=atomic_kind_set, &
977 qs_kind_set=qs_kind_set, &
978 matrix_h_kp=matrix_h, &
979 matrix_s_kp=matrix_s, &
981 dft_control=dft_control, &
984 rho=rho, tb_tblite=tb)
987 nkind =
SIZE(atomic_kind_set)
988 nderivatives = merge(1, 0, calculate_forces)
989 maxder =
ncoset(nderivatives)
990 nimg = dft_control%nimages
992 IF (.NOT.
ASSOCIATED(sab_kp)) cpabort(
"Missing k-point neighbor list for tblite")
994 CALL get_ks_env(ks_env=ks_env, kpoints=kpoints)
1002 IF (calculate_forces)
THEN
1003 NULLIFY (force, matrix_w, virial)
1005 matrix_w_kp=matrix_w, &
1006 virial=virial, force=force)
1008 IF (
SIZE(matrix_p, 1) == 2)
THEN
1010 CALL tb_store_density_ref(tb, matrix_p)
1012 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
1013 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1014 CALL dbcsr_add(matrix_w(1, img)%matrix, matrix_w(2, img)%matrix, &
1015 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1018 tb%use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1021 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, atom_of_kind=atom_of_kind, kind_of=kind_of)
1022 IF (calculate_forces)
THEN
1023 ALLOCATE (native_radial_force_sum(3,
SIZE(atom_of_kind)))
1024 ALLOCATE (native_cn_deriv_sum(
SIZE(atom_of_kind)))
1025 native_cn_deriv_sum = 0.0_dp
1026 native_radial_force_sum = 0.0_dp
1030 ALLOCATE (basis_set_list(nkind))
1034 IF (.NOT. calculate_forces)
THEN
1036 CALL create_sab_matrix(ks_env, matrix_s,
"OVERLAP MATRIX", basis_set_list, basis_set_list, &
1038 CALL set_ks_env(ks_env, matrix_s_kp=matrix_s)
1042 ALLOCATE (matrix_h(1, img)%matrix)
1043 CALL dbcsr_create(matrix_h(1, img)%matrix, template=matrix_s(1, img)%matrix, &
1044 name=
"HAMILTONIAN MATRIX")
1047 CALL set_ks_env(ks_env, matrix_h_kp=matrix_h)
1049 IF (calculate_forces .AND. nimg > 1)
THEN
1053 ALLOCATE (matrix_dh_native(idim, img)%matrix)
1054 CALL dbcsr_create(matrix_dh_native(idim, img)%matrix, template=matrix_s(1, img)%matrix, &
1055 name=
"TBLITE H0 STRAIN DERIVATIVE")
1063 native_radial_dot = 0.0_dp
1064 pulay_virial = 0.0_dp
1092 ALLOCATE (oint(ldsab, ldsab, maxder), owork(ldsab, ldsab))
1093 ALLOCATE (sint(maxsgf, maxsgf, maxder))
1094 IF (.NOT. calculate_forces)
ALLOCATE (hint(maxsgf, maxsgf, 1))
1095 IF (calculate_forces)
THEN
1096 ALLOCATE (local_cn_deriv(
SIZE(atom_of_kind)), local_radial_force(3,
SIZE(atom_of_kind)))
1097 local_cn_deriv = 0.0_dp
1098 local_radial_force = 0.0_dp
1099 IF (nimg > 1)
ALLOCATE (radial_hint(maxsgf, maxsgf, 3, 3))
1103 DO slot = 1, sab_orb(1)%nl_size
1105 ikind = sab_orb(1)%nlist_task(slot)%ikind
1106 jkind = sab_orb(1)%nlist_task(slot)%jkind
1107 iatom = sab_orb(1)%nlist_task(slot)%iatom
1108 jatom = sab_orb(1)%nlist_task(slot)%jatom
1109 cell(:) = sab_orb(1)%nlist_task(slot)%cell(:)
1110 rij(1:3) = sab_orb(1)%nlist_task(slot)%r(1:3)
1114 native_cn_icol = 0.0_dp
1115 native_cn_irow = 0.0_dp
1116 native_h0_overlap_force = 0.0_dp
1117 native_radial_force = 0.0_dp
1120 icol = max(iatom, jatom)
1121 irow = min(iatom, jatom)
1122 IF (iatom < jatom)
THEN
1135 ic = cell_to_index(cell(1), cell(2), cell(3))
1139 IF (calculate_forces)
THEN
1142 row=irow, col=icol, block=pblock, found=found)
1146 row=irow, col=icol, block=wblock, found=found)
1151 NULLIFY (radial_blocks(idim, jdim)%block)
1152 CALL dbcsr_get_block_p(matrix=matrix_dh_native(idim + 3*(jdim - 1), ic)%matrix, &
1153 row=irow, col=icol, block=radial_blocks(idim, jdim)%block, &
1163 basis_set_a => basis_set_list(ikind)%gto_basis_set
1164 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
1165 basis_set_b => basis_set_list(jkind)%gto_basis_set
1166 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
1168 first_sgfa => basis_set_a%first_sgf
1169 la_max => basis_set_a%lmax
1170 la_min => basis_set_a%lmin
1171 npgfa => basis_set_a%npgf
1172 nseta = basis_set_a%nset
1173 nsgfa => basis_set_a%nsgf_set
1174 rpgfa => basis_set_a%pgf_radius
1175 set_radius_a => basis_set_a%set_radius
1176 scon_a => basis_set_a%scon
1177 zeta => basis_set_a%zet
1179 first_sgfb => basis_set_b%first_sgf
1180 lb_max => basis_set_b%lmax
1181 lb_min => basis_set_b%lmin
1182 npgfb => basis_set_b%npgf
1183 nsetb = basis_set_b%nset
1184 nsgfb => basis_set_b%nsgf_set
1185 rpgfb => basis_set_b%pgf_radius
1186 set_radius_b => basis_set_b%set_radius
1187 scon_b => basis_set_b%scon
1188 zetb => basis_set_b%zet
1192 natorb_a = natorb_a + (2*basis_set_a%l(1, iset) + 1)
1196 natorb_b = natorb_b + (2*basis_set_b%l(1, iset) + 1)
1198 sint(1:natorb_a, 1:natorb_b, :) = 0.0_dp
1199 IF (.NOT. calculate_forces) hint(1:natorb_a, 1:natorb_b, :) = 0.0_dp
1200 IF (calculate_forces .AND. nimg > 1)
THEN
1201 radial_hint(1:natorb_a, 1:natorb_b, :, :) = 0.0_dp
1206 n1 = npgfa(iset)*(
ncoset(la_max(iset)) -
ncoset(la_min(iset) - 1))
1207 sgfa = first_sgfa(1, iset)
1209 IF (set_radius_a(iset) + set_radius_b(jset) < dr) cycle
1210 n2 = npgfb(jset)*(
ncoset(lb_max(jset)) -
ncoset(lb_min(jset) - 1))
1211 sgfb = first_sgfb(1, jset)
1212 IF (calculate_forces)
THEN
1213 CALL overlap_ab(la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
1214 lb_max(jset), lb_min(jset), npgfb(jset), rpgfb(:, jset), zetb(:, jset), &
1215 rij, sab=oint(:, :, 1), dab=oint(:, :, 2:4))
1217 CALL overlap_ab(la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
1218 lb_max(jset), lb_min(jset), npgfb(jset), rpgfb(:, jset), zetb(:, jset), &
1219 rij, sab=oint(:, :, 1))
1222 CALL contraction(oint(:, :, 1), owork, ca=scon_a(:, sgfa:), na=n1, ma=nsgfa(iset), &
1223 cb=scon_b(:, sgfb:), nb=n2, mb=nsgfb(jset), fscale=1.0_dp, trans=.false.)
1224 CALL block_add(
"IN", owork, nsgfa(iset), nsgfb(jset), sint(:, :, 1), sgfa, sgfb, trans=.false.)
1225 IF (calculate_forces)
THEN
1227 CALL contraction(oint(:, :, i), owork, ca=scon_a(:, sgfa:), na=n1, ma=nsgfa(iset), &
1228 cb=scon_b(:, sgfb:), nb=n2, mb=nsgfb(jset), fscale=1.0_dp, trans=.false.)
1229 CALL block_add(
"IN", owork, nsgfa(iset), nsgfb(jset), sint(:, :, i), sgfa, sgfb, trans=.false.)
1238 IF (.NOT. calculate_forces)
THEN
1239 CALL dbcsr_get_block_p(matrix_s(1, ic)%matrix, irow, icol, block=sblock, found=found)
1243 IF (icol <= irow)
THEN
1244 sblock(:, :) = sblock(:, :) + sint(1:natorb_a, 1:natorb_b, 1)
1246 sblock(:, :) = sblock(:, :) + transpose(sint(1:natorb_a, 1:natorb_b, 1))
1252 IF (icol == irow .AND. dr < same_atom)
THEN
1254 n1 = tb%calc%bas%ish_at(icol)
1256 sgfa = first_sgfa(1, iset)
1257 hij = tb%selfenergy(n1 + iset)
1258 DO ia = sgfa, sgfa + nsgfa(iset) - 1
1259 IF (.NOT. calculate_forces) hint(ia, ia, 1) = hij
1260 IF (calculate_forces)
THEN
1261 native_cn_icol = native_cn_icol + tb%dsedcn(n1 + iset)*pblock(ia, ia)
1265 native_radial_dot(idim, jdim) = native_radial_dot(idim, jdim) + &
1266 tb%dsedcn(n1 + iset)*tb%dcndL(idim, jdim, icol)*pblock(ia, ia)
1268 radial_hint(ia, ia, idim, jdim) = radial_hint(ia, ia, idim, jdim) + &
1269 tb%dsedcn(n1 + iset)*tb%dcndL(idim, jdim, icol)
1278 rr = sqrt(dr/(h0%rad(jkind) + h0%rad(ikind)))
1279 n1 = tb%calc%bas%ish_at(icol)
1281 sgfa = first_sgfa(1, iset)
1282 n2 = tb%calc%bas%ish_at(irow)
1284 sgfb = first_sgfb(1, jset)
1285 shpoly = (1.0_dp + h0%shpoly(iset, ikind)*rr) &
1286 *(1.0_dp + h0%shpoly(jset, jkind)*rr)
1287 dshpoly = ((1.0_dp + h0%shpoly(iset, ikind)*rr)*h0%shpoly(jset, jkind)*rr &
1288 + (1.0_dp + h0%shpoly(jset, jkind)*rr)*h0%shpoly(iset, ikind)*rr) &
1290 hij_base = 0.5_dp*(tb%selfenergy(n1 + iset) + tb%selfenergy(n2 + jset)) &
1291 *h0%hscale(iset, jset, ikind, jkind)
1292 hij = hij_base*shpoly
1293 DO ia = sgfa, sgfa + nsgfa(iset) - 1
1294 DO ib = sgfb, sgfb + nsgfb(jset) - 1
1295 IF (.NOT. calculate_forces) hint(ia, ib, 1) = hij*sint(ia, ib, 1)
1296 IF (calculate_forces)
THEN
1297 native_dot_weight = 2.0_dp
1298 IF (icol == irow) native_dot_weight = 1.0_dp
1299 native_cn_icol = native_cn_icol + native_dot_weight*0.5_dp* &
1300 h0%hscale(iset, jset, ikind, jkind)*shpoly* &
1301 tb%dsedcn(n1 + iset)*pblock(ib, ia)*sint(ia, ib, 1)
1302 native_cn_irow = native_cn_irow + native_dot_weight*0.5_dp* &
1303 h0%hscale(iset, jset, ikind, jkind)*shpoly* &
1304 tb%dsedcn(n2 + jset)*pblock(ib, ia)*sint(ia, ib, 1)
1305 native_radial_force = native_radial_force + &
1306 hij_base*dshpoly*pblock(ib, ia)*sint(ia, ib, 1)*raw_rij
1307 native_h0_overlap_force = native_h0_overlap_force + &
1308 hij*pblock(ib, ia)*sint(ia, ib, 2:4)
1312 native_radial_dot(idim, jdim) = native_radial_dot(idim, jdim) + &
1313 native_dot_weight*pblock(ib, ia)*( &
1314 (-hij)*sint(ia, ib, idim + 1)*rij(jdim) + &
1315 hij_base*dshpoly*sint(ia, ib, 1)*rij(idim)*rij(jdim) + &
1316 0.5_dp*h0%hscale(iset, jset, ikind, jkind)*shpoly*sint(ia, ib, 1)* &
1317 (tb%dsedcn(n1 + iset)*tb%dcndL(idim, jdim, icol) + &
1318 tb%dsedcn(n2 + jset)*tb%dcndL(idim, jdim, irow)))
1320 radial_hint(ia, ib, idim, jdim) = radial_hint(ia, ib, idim, jdim) + &
1321 (-hij)*sint(ia, ib, idim + 1)*rij(jdim) + &
1322 hij_base*dshpoly*sint(ia, ib, 1)*rij(idim)*rij(jdim) + &
1323 0.5_dp*h0%hscale(iset, jset, ikind, jkind)*shpoly*sint(ia, ib, 1)* &
1324 (tb%dsedcn(n1 + iset)*tb%dcndL(idim, jdim, icol) + &
1325 tb%dsedcn(n2 + jset)*tb%dcndL(idim, jdim, irow))
1339 IF (.NOT. calculate_forces)
THEN
1340 CALL dbcsr_get_block_p(matrix_h(1, ic)%matrix, irow, icol, block=fblock, found=found)
1343 IF (icol <= irow)
THEN
1344 IF (.NOT. calculate_forces) fblock(:, :) = fblock(:, :) + hint(1:natorb_a, 1:natorb_b, 1)
1345 IF (calculate_forces .AND. nimg > 1)
THEN
1348 radial_blocks(idim, jdim)%block(:, :) = radial_blocks(idim, jdim)%block(:, :) + &
1349 radial_hint(1:natorb_a, 1:natorb_b, idim, jdim)
1354 IF (.NOT. calculate_forces) fblock(:, :) = fblock(:, :) + transpose(hint(1:natorb_a, 1:natorb_b, 1))
1355 IF (calculate_forces .AND. nimg > 1)
THEN
1358 radial_blocks(idim, jdim)%block(:, :) = radial_blocks(idim, jdim)%block(:, :) + &
1359 transpose(radial_hint(1:natorb_a, 1:natorb_b, idim, jdim))
1366 IF (calculate_forces)
THEN
1370 IF (icol == irow)
THEN
1371 pulay_force(idim) = sum(wblock*sint(1:natorb_a, 1:natorb_b, idim + 1))
1373 pulay_force(idim) = sum(transpose(wblock)*sint(1:natorb_a, 1:natorb_b, idim + 1))
1376 local_radial_force(:, icol) = local_radial_force(:, icol) - 2.0_dp*pulay_force
1377 local_radial_force(:, irow) = local_radial_force(:, irow) + 2.0_dp*pulay_force
1378 IF (tb%use_virial)
THEN
1379 native_dot_weight = 2.0_dp
1380 IF (icol == irow) native_dot_weight = 1.0_dp
1384 local_radial_force(:, raw_iatom) = &
1385 local_radial_force(:, raw_iatom) - ff*native_radial_force
1386 local_radial_force(:, raw_jatom) = &
1387 local_radial_force(:, raw_jatom) + ff*native_radial_force
1388 local_radial_force(:, icol) = &
1389 local_radial_force(:, icol) + ff*native_h0_overlap_force
1390 local_radial_force(:, irow) = &
1391 local_radial_force(:, irow) - ff*native_h0_overlap_force
1392 local_cn_deriv(icol) = local_cn_deriv(icol) + native_cn_icol
1393 local_cn_deriv(irow) = local_cn_deriv(irow) + native_cn_irow
1398 IF (calculate_forces)
THEN
1400 native_radial_force_sum(:, :) = native_radial_force_sum(:, :) + local_radial_force(:, :)
1401 native_cn_deriv_sum(:) = native_cn_deriv_sum(:) + local_cn_deriv(:)
1403 DEALLOCATE (local_radial_force, local_cn_deriv)
1405 DEALLOCATE (oint, owork, sint)
1406 IF (
ALLOCATED(hint))
DEALLOCATE (hint)
1407 IF (
ALLOCATED(radial_hint))
DEALLOCATE (radial_hint)
1418 IF (calculate_forces)
THEN
1420 native_radial_dot = 0.0_dp
1424 CALL dbcsr_finalize(matrix_dh_native(idim + 3*(jdim - 1), img)%matrix)
1425 CALL dbcsr_dot(matrix_dh_native(idim + 3*(jdim - 1), img)%matrix, &
1426 matrix_p(1, img)%matrix, native_dot_tmp)
1427 native_radial_dot(idim, jdim) = native_radial_dot(idim, jdim) + native_dot_tmp
1433 CALL para_env%sum(native_radial_dot)
1435 CALL para_env%sum(native_cn_deriv_sum)
1437 CALL tb_add_grad(tb%grad, tb%dcndr, native_cn_deriv_sum, tb%mol%nat)
1438 CALL tb_grad2force(qs_env, tb, para_env, 4, replicated=.true.)
1439 DO iatom = 1,
SIZE(atom_of_kind)
1440 ikind = kind_of(iatom)
1441 force(ikind)%overlap(:, atom_of_kind(iatom)) = &
1442 force(ikind)%overlap(:, atom_of_kind(iatom)) + native_radial_force_sum(:, iatom)
1444 IF (tb%use_virial)
THEN
1445 virial%pv_overlap = virial%pv_overlap - native_radial_dot/para_env%num_pe + pulay_virial
1446 virial%pv_virial = virial%pv_virial - native_radial_dot/para_env%num_pe + pulay_virial
1450 IF (.NOT. calculate_forces)
THEN
1455 IF (dft_control%qs_control%xtb_control%tblite_method ==
gfn2xtb)
THEN
1463 IF (.NOT. calculate_forces)
THEN
1465 "DFT%PRINT%OVERLAP_CONDITION") /= 0)
THEN
1469 CALL section_vals_val_get(qs_env%input,
"DFT%PRINT%OVERLAP_CONDITION%DIAGONALIZATION", l_val=norml2)
1470 CALL section_vals_val_get(qs_env%input,
"DFT%PRINT%OVERLAP_CONDITION%ARNOLDI", l_val=use_arnoldi)
1471 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env)
1472 CALL overlap_condnum(matrix_s, condnum, iw, norml1, norml2, use_arnoldi, blacs_env)
1476 DEALLOCATE (basis_set_list)
1477 IF (
ALLOCATED(native_cn_deriv_sum))
DEALLOCATE (native_cn_deriv_sum)
1478 IF (
ALLOCATED(native_radial_force_sum))
DEALLOCATE (native_radial_force_sum)
1480 CALL timestop(handle)
1484 mark_used(calculate_forces)
1485 cpabort(
"Built without TBLITE")
1503 LOGICAL,
INTENT(IN) :: calculate_forces
1504 LOGICAL,
INTENT(IN) :: use_rho
1506#if defined(__TBLITE)
1508 INTEGER :: iatom, ikind, is, ns, atom_a, im
1509 INTEGER :: ispin, nspin
1510 INTEGER :: nkind, nsgf, natorb, na
1511 INTEGER :: n_atom, max_orb, max_shell
1512 LOGICAL :: advance_native_mixer, do_dipole, do_quadrupole, &
1513 reuse_native_input, seed_native_from_rho, &
1514 use_native_mixer, use_no_mixer
1515 REAL(kind=
dp) :: native_seed_charge, norm, pao
1516 INTEGER,
DIMENSION(5) :: occ
1517 INTEGER,
DIMENSION(25) :: lao
1518 INTEGER,
DIMENSION(25) :: nao
1519 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ch_atom
1520 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: aocg
1521 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: aocg_spin, ao_dip_spin, ao_quad_spin, &
1522 ch_orb_spin, ch_shell_spin
1525 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s, matrix_p
1526 TYPE(error_type),
ALLOCATABLE :: error
1529 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1536 NULLIFY (particle_set, qs_kind_set, atomic_kind_set, scf_control, scf_env)
1537 CALL get_qs_env(qs_env=qs_env, scf_env=scf_env, particle_set=particle_set, qs_kind_set=qs_kind_set, &
1538 atomic_kind_set=atomic_kind_set, matrix_s_kp=matrix_s, rho=rho, para_env=para_env, &
1539 scf_control=scf_control)
1543 do_quadrupole = .false.
1544 IF (dft_control%qs_control%do_ls_scf .OR. scf_control%use_ot)
THEN
1545 use_native_mixer = .false.
1546 use_no_mixer = .true.
1548 SELECT CASE (dft_control%qs_control%xtb_control%tblite_scc_mixer)
1551 use_no_mixer = .false.
1553 use_native_mixer = .true.
1554 use_no_mixer = .false.
1556 use_native_mixer = .false.
1557 use_no_mixer = .false.
1559 use_native_mixer = .false.
1560 use_no_mixer = .true.
1562 cpabort(
"Unknown tblite SCC mixer")
1565 IF (use_native_mixer)
THEN
1566 IF (.NOT.
ASSOCIATED(scf_env)) cpabort(
"tblite SCC mixer requires a QS SCF environment")
1567 IF (use_rho .AND. (.NOT. calculate_forces))
THEN
1568 IF (scf_env%iter_count > dft_control%qs_control%xtb_control%tblite_mixer_iterations)
THEN
1569 cpabort(
"tblite SCC mixer exceeded TBLITE_MIXER/ITERATIONS")
1571 IF (scf_env%iter_count == 1)
THEN
1572 CALL tb_configure_mixer(tb, dft_control%qs_control%xtb_control%tblite_mixer_iterations, &
1573 dft_control%qs_control%xtb_control%tblite_mixer_memory, &
1574 dft_control%qs_control%xtb_control%tblite_mixer_damping, &
1575 dft_control%qs_control%xtb_control%tblite_mixer_omega0, &
1576 dft_control%qs_control%xtb_control%tblite_mixer_min_weight, &
1577 dft_control%qs_control%xtb_control%tblite_mixer_max_weight, &
1578 dft_control%qs_control%xtb_control%tblite_mixer_weight_factor, &
1579 dft_control%qs_control%xtb_control%tblite_mixer_solver)
1580 CALL tb_reset_mixer(tb)
1584 nspin = dft_control%nspins
1585 IF (nspin /= tb%wfn%nspin) cpabort(
"CP2K/tblite spin channel mismatch")
1590 ELSE IF (calculate_forces .AND. nspin > 1)
THEN
1591 IF (.NOT.
ASSOCIATED(tb%rho_ao_kp_ref))
THEN
1592 cpabort(
"Missing converged tblite density for UKS/LSD forces")
1594 matrix_p => tb%rho_ao_kp_ref
1596 matrix_p => scf_env%p_mix_new
1598 IF (
ASSOCIATED(tb%dipbra)) do_dipole = .true.
1599 IF (
ASSOCIATED(tb%quadbra)) do_quadrupole = .true.
1600 reuse_native_input = .false.
1601 IF (use_native_mixer)
THEN
1602 IF (scf_env%iter_count == 1)
THEN
1603 reuse_native_input = any(abs(tb%wfn%qsh) > 1.0e-14_dp)
1604 IF (do_dipole) reuse_native_input = reuse_native_input .OR. &
1605 any(abs(tb%wfn%dpat) > 1.0e-14_dp)
1606 IF (do_quadrupole) reuse_native_input = reuse_native_input .OR. &
1607 any(abs(tb%wfn%qpat) > 1.0e-14_dp)
1610 n_atom =
SIZE(particle_set)
1611 nkind =
SIZE(atomic_kind_set)
1613 ALLOCATE (aocg(nsgf, n_atom))
1614 ALLOCATE (aocg_spin(nsgf, n_atom, nspin))
1617 ALLOCATE (ao_dip_spin(n_atom, dip_n, nspin))
1619 IF (do_quadrupole)
THEN
1620 ALLOCATE (ao_quad_spin(n_atom, quad_n, nspin))
1625 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
1627 max_orb = max(max_orb, natorb)
1630 max_shell = max(max_shell, tb%calc%bas%nsh_at(is))
1632 ALLOCATE (ch_atom(n_atom, nspin))
1633 ALLOCATE (ch_orb_spin(max_orb, n_atom, nspin), ch_shell_spin(n_atom, max_shell, nspin))
1635 ch_orb_spin = 0.0_dp
1636 ch_shell_spin = 0.0_dp
1637 CALL tb_contract_population(tb, matrix_p, matrix_s, para_env, aocg_spin, ao_dip_spin, ao_quad_spin)
1638 IF (nspin == 1)
THEN
1639 aocg(:, :) = aocg_spin(:, :, 1)
1641 aocg(:, :) = aocg_spin(:, :, 1) + aocg_spin(:, :, 2)
1644 DO iatom = 1, n_atom
1645 pao = ao_dip_spin(iatom, im, 1)
1646 ao_dip_spin(iatom, im, 1) = pao + ao_dip_spin(iatom, im, 2)
1647 ao_dip_spin(iatom, im, 2) = pao - ao_dip_spin(iatom, im, 2)
1651 IF (do_quadrupole)
THEN
1653 DO iatom = 1, n_atom
1654 pao = ao_quad_spin(iatom, im, 1)
1655 ao_quad_spin(iatom, im, 1) = pao + ao_quad_spin(iatom, im, 2)
1656 ao_quad_spin(iatom, im, 2) = pao - ao_quad_spin(iatom, im, 2)
1664 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
1667 atom_a = atomic_kind_set(ikind)%atom_list(iatom)
1671 norm = 2*lao(is) + 1
1672 ch_orb_spin(is, atom_a, 1) = aocg(is, atom_a) - tb%calc%h0%refocc(nao(is), ikind)/norm
1673 IF (nspin == 2) ch_orb_spin(is, atom_a, 2) = &
1674 aocg_spin(is, atom_a, 1) - aocg_spin(is, atom_a, 2)
1676 ch_shell_spin(atom_a, ns, ispin) = ch_orb_spin(is, atom_a, ispin) + &
1677 ch_shell_spin(atom_a, ns, ispin)
1681 ch_atom(atom_a, ispin) = sum(ch_orb_spin(:, atom_a, ispin))
1685 native_seed_charge = -sum(ch_atom(:, 1))
1686 seed_native_from_rho = sum(abs(aocg_spin)) > 1.0e-10_dp .AND. &
1687 abs(native_seed_charge - real(dft_control%charge,
dp)) < 1.0e-5_dp
1688 DEALLOCATE (aocg, aocg_spin)
1692 IF (use_native_mixer)
THEN
1693 IF (.NOT.
ALLOCATED(tb%mixer)) cpabort(
"tblite mixer not initialized")
1694 advance_native_mixer = .false.
1695 IF (use_rho .AND. (.NOT. calculate_forces))
THEN
1696 advance_native_mixer = scf_env%iter_count > 1
1698 IF (advance_native_mixer)
THEN
1700 CALL tb%mixer%next(error)
1701 IF (
ALLOCATED(error)) cpabort(
"tblite native mixer failed: "//error%message)
1702 CALL tb%mixer%get(tb%wfn%qsh)
1703 CALL tb_sum_shell_charges(tb)
1704 IF (do_dipole)
CALL tb%mixer%get(tb%wfn%dpat)
1705 IF (do_quadrupole)
CALL tb%mixer%get(tb%wfn%qpat)
1706 ELSE IF (use_rho .AND. (.NOT. calculate_forces))
THEN
1707 IF (.NOT. reuse_native_input)
THEN
1708 IF (seed_native_from_rho)
THEN
1710 CALL tb_set_population(tb, ch_shell_spin, ao_dip_spin, ao_quad_spin)
1712 tb%wfn%qsh(:, :) = 0.0_dp
1713 tb%wfn%qat(:, :) = 0.0_dp
1714 IF (do_dipole) tb%wfn%dpat(:, :, :) = 0.0_dp
1715 IF (do_quadrupole) tb%wfn%qpat(:, :, :) = 0.0_dp
1720 IF (.NOT. calculate_forces)
THEN
1721 CALL tb%mixer%set(tb%wfn%qsh)
1722 IF (do_dipole)
CALL tb%mixer%set(tb%wfn%dpat)
1723 IF (do_quadrupole)
CALL tb%mixer%set(tb%wfn%qpat)
1725 CALL tb_set_population(tb, ch_shell_spin, ao_dip_spin, ao_quad_spin)
1726 IF (.NOT. calculate_forces)
THEN
1727 CALL tb%mixer%diff(tb%wfn%qsh)
1728 IF (do_dipole)
CALL tb%mixer%diff(tb%wfn%dpat)
1729 IF (do_quadrupole)
CALL tb%mixer%diff(tb%wfn%qpat)
1733 IF (.NOT. (dft_control%qs_control%do_ls_scf .OR. scf_control%use_ot))
THEN
1734 IF (.NOT.
ASSOCIATED(scf_env)) cpabort(
"CP2K SCC mixer requires a QS SCF environment")
1735 IF (.NOT. (do_dipole .OR. do_quadrupole) .AND. &
1737 cpabort(
"MODIFIED_BROYDEN_MIXING with SCC_MIXER CP2K requires GFN2")
1740 IF (.NOT. use_no_mixer)
THEN
1741 CALL tb_mix_population(scf_env, para_env, ch_shell_spin, ao_dip_spin, ao_quad_spin)
1743 CALL tb_set_population(tb, ch_shell_spin, ao_dip_spin, ao_quad_spin)
1744 IF (nspin == 1)
THEN
1745 IF (.NOT. (do_dipole .OR. do_quadrupole) .OR. &
1746 dft_control%qs_control%do_ls_scf .OR. scf_control%use_ot)
THEN
1749 tb%wfn%qat(:, 1) = -ch_atom(:, 1)
1754 CALL tb_update_scf_potential(qs_env, tb, para_env, calculate_forces)
1756 IF (
ALLOCATED(ao_dip_spin))
DEALLOCATE (ao_dip_spin)
1757 IF (
ALLOCATED(ao_quad_spin))
DEALLOCATE (ao_quad_spin)
1758 DEALLOCATE (ch_atom, ch_orb_spin, ch_shell_spin)
1763 mark_used(dft_control)
1764 mark_used(calculate_forces)
1766 cpabort(
"Built without TBLITE")
1771#if defined(__TBLITE)
1779 SUBROUTINE tb_set_population(tb, shell, dipole, quadrupole)
1781 REAL(kind=
dp),
DIMENSION(:, :, :),
INTENT(IN) :: shell
1782 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :), &
1783 INTENT(IN) :: dipole, quadrupole
1785 INTEGER :: iatom, ii, is, ispin
1787 DO iatom = 1, tb%mol%nat
1788 ii = tb%calc%bas%ish_at(iatom)
1789 DO ispin = 1, tb%wfn%nspin
1790 DO is = 1, tb%calc%bas%nsh_at(iatom)
1791 tb%wfn%qsh(ii + is, ispin) = -shell(iatom, is, ispin)
1793 IF (
ALLOCATED(dipole)) tb%wfn%dpat(:, iatom, ispin) = -dipole(iatom, :, ispin)
1794 IF (
ALLOCATED(quadrupole)) tb%wfn%qpat(:, iatom, ispin) = -quadrupole(iatom, :, ispin)
1797 CALL tb_sum_shell_charges(tb)
1799 END SUBROUTINE tb_set_population
1805 SUBROUTINE tb_sum_shell_charges(tb)
1808 INTEGER :: iatom, ii, ispin
1810 DO iatom = 1, tb%mol%nat
1811 ii = tb%calc%bas%ish_at(iatom)
1812 DO ispin = 1, tb%wfn%nspin
1813 tb%wfn%qat(iatom, ispin) = sum(tb%wfn%qsh(ii + 1:ii + tb%calc%bas%nsh_at(iatom), ispin))
1817 END SUBROUTINE tb_sum_shell_charges
1827 SUBROUTINE tb_mix_population(scf_env, para_env, shell, dipole, quadrupole)
1830 REAL(kind=
dp),
DIMENSION(:, :, :),
INTENT(INOUT) :: shell
1831 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :), &
1832 INTENT(INOUT) :: dipole, quadrupole
1834 INTEGER :: ispin, ncols, nsh, nspin, offset
1835 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: mix_vars
1837 nspin =
SIZE(shell, 3)
1838 IF (nspin == 1 .AND. .NOT.
ALLOCATED(dipole) .AND. .NOT.
ALLOCATED(quadrupole))
THEN
1840 CALL charge_mixing(scf_env%mixing_method, scf_env%mixing_store, &
1841 shell(:, :, 1), para_env, scf_env%iter_count)
1845 nsh =
SIZE(shell, 2)
1847 IF (
ALLOCATED(dipole)) ncols = ncols + nspin*dip_n
1848 IF (
ALLOCATED(quadrupole)) ncols = ncols + nspin*quad_n
1849 ALLOCATE (mix_vars(
SIZE(shell, 1), ncols))
1854 mix_vars(:, offset + 1:offset + nsh) = -shell(:, :, ispin)
1855 offset = offset + nsh
1857 IF (
ALLOCATED(dipole))
THEN
1859 mix_vars(:, offset + 1:offset + dip_n) = -dipole(:, :, ispin)
1860 offset = offset + dip_n
1863 IF (
ALLOCATED(quadrupole))
THEN
1865 mix_vars(:, offset + 1:offset + quad_n) = -quadrupole(:, :, ispin)
1866 offset = offset + quad_n
1869 CALL charge_mixing(scf_env%mixing_method, scf_env%mixing_store, &
1870 mix_vars, para_env, scf_env%iter_count)
1873 shell(:, :, ispin) = -mix_vars(:, offset + 1:offset + nsh)
1874 offset = offset + nsh
1876 IF (
ALLOCATED(dipole))
THEN
1878 dipole(:, :, ispin) = -mix_vars(:, offset + 1:offset + dip_n)
1879 offset = offset + dip_n
1882 IF (
ALLOCATED(quadrupole))
THEN
1884 quadrupole(:, :, ispin) = -mix_vars(:, offset + 1:offset + quad_n)
1885 offset = offset + quad_n
1889 END SUBROUTINE tb_mix_population
1898 SUBROUTINE tb_update_scf_potential(qs_env, tb, para_env, calculate_forces)
1902 LOGICAL,
INTENT(IN) :: calculate_forces
1908 IF (
ALLOCATED(tb%calc%coulomb))
THEN
1909 CALL tb%calc%coulomb%get_potential(tb%mol, tb%cache, tb%wfn, tb%pot)
1910 CALL tb%calc%coulomb%get_energy(tb%mol, tb%cache, tb%wfn, tb%e_es)
1912 IF (
ALLOCATED(tb%calc%dispersion))
THEN
1913 CALL tb%calc%dispersion%get_potential(tb%mol, tb%dcache, tb%wfn, tb%pot)
1914 CALL tb%calc%dispersion%get_energy(tb%mol, tb%dcache, tb%wfn, tb%e_scd)
1916 IF (
ALLOCATED(tb%calc%interactions))
THEN
1917 CALL tb%calc%interactions%get_potential(tb%mol, tb%icache, tb%wfn, tb%pot)
1918 CALL tb%calc%interactions%get_energy(tb%mol, tb%icache, tb%wfn, tb%e_int)
1922 CALL para_env%sum(tb%pot%vat)
1923 CALL para_env%sum(tb%pot%vsh)
1924 CALL para_env%sum(tb%pot%vdp)
1925 CALL para_env%sum(tb%pot%vqp)
1927 IF (calculate_forces)
THEN
1928 IF (
ALLOCATED(tb%calc%coulomb))
THEN
1930 CALL tb%calc%coulomb%get_gradient(tb%mol, tb%cache, tb%wfn, tb%grad, tb%sigma)
1931 CALL tb_grad2force(qs_env, tb, para_env, 3, replicated=.false.)
1934 IF (
ALLOCATED(tb%calc%dispersion))
THEN
1936 CALL tb%calc%dispersion%get_gradient(tb%mol, tb%dcache, tb%wfn, tb%grad, tb%sigma)
1937 CALL tb_grad2force(qs_env, tb, para_env, 2, replicated=.false.)
1940 IF (
ALLOCATED(tb%calc%interactions))
THEN
1942 CALL tb%calc%interactions%get_gradient(tb%mol, tb%icache, tb%wfn, tb%grad, tb%sigma)
1943 CALL tb_grad2force(qs_env, tb, para_env, 3, replicated=.false.)
1947 END SUBROUTINE tb_update_scf_potential
1962#if defined(__TBLITE)
1963 INTEGER :: i, im, ispin, ikind, iatom, jatom, irow, icol, img, slot
1964 INTEGER :: nimg, nspin, nsgf, natorb, natom_kind, ndip, nquad
1965 INTEGER,
DIMENSION(3) :: cell
1966 INTEGER,
DIMENSION(25) :: nao
1967 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1969 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: sblock
1970 REAL(kind=
dp),
DIMENSION(:, :),
ALLOCATABLE :: vat
1971 REAL(kind=
dp),
DIMENSION(:, :, :),
ALLOCATABLE :: vsh, vmp
1974 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s, ks_matrix
1977 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1982 INTEGER,
PARAMETER :: nlock = 501
1984 nimg = dft_control%nimages
1985 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
1986 matrix_s_kp=matrix_s, matrix_ks_kp=ks_matrix)
1987 nspin =
SIZE(ks_matrix, 1)
1988 ndip = merge(dip_n, 0,
ASSOCIATED(tb%dipbra))
1989 nquad = merge(quad_n, 0,
ASSOCIATED(tb%quadbra))
1991 ALLOCATE (vsh(nsgf, tb%mol%nat, nspin), vat(tb%mol%nat, nspin), vmp(ndip + nquad, tb%mol%nat, nspin))
1995 DO ikind = 1,
SIZE(atomic_kind_set)
1997 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom)
1999 DO i = 1, natom_kind
2000 iatom = atomic_kind_set(ikind)%atom_list(i)
2003 vsh(im, iatom, ispin) = tb_spin_project(tb%pot%vsh(nao(im) + tb%calc%bas%ish_at(iatom), :), ispin)
2005 vat(iatom, ispin) = tb_spin_project(tb%pot%vat(iatom, :), ispin)
2007 vmp(im, iatom, ispin) = tb_spin_project(tb%pot%vdp(im, iatom, :), ispin)
2010 vmp(ndip + im, iatom, ispin) = tb_spin_project(tb%pot%vqp(im, iatom, :), ispin)
2021 CALL tb_ham_add_block(tb, ks_matrix, sblock, irow, icol, 1, vsh, vat, vmp)
2026 CALL get_qs_env(qs_env=qs_env, sab_kp=n_list, kpoints=kpoints)
2027 IF (.NOT.
ASSOCIATED(n_list))
THEN
2028 cpabort(
"Missing k-point neighbor list for tblite Hamiltonian")
2039 DO slot = 1, n_list(1)%nl_size
2040 iatom = n_list(1)%nlist_task(slot)%iatom
2041 jatom = n_list(1)%nlist_task(slot)%jatom
2042 cell(:) = n_list(1)%nlist_task(slot)%cell(:)
2043 irow = min(iatom, jatom)
2044 icol = max(iatom, jatom)
2045 img = cell_to_index(cell(1), cell(2), cell(3))
2047 CALL dbcsr_get_block_p(matrix_s(1, img)%matrix, irow, icol, block=sblock, found=found)
2052 CALL tb_ham_add_block(tb, ks_matrix, sblock, irow, icol, img, vsh, vat, vmp)
2061 DEALLOCATE (vsh, vat, vmp)
2065 mark_used(dft_control)
2066 cpabort(
"Built without TBLITE")
2071#if defined(__TBLITE)
2084 SUBROUTINE tb_ham_add_block(tb, ks_matrix, sblock, irow, icol, img, vsh, vat, vmp)
2086 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ks_matrix
2087 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: sblock
2088 INTEGER,
INTENT(IN) :: irow, icol, img
2089 REAL(kind=
dp),
DIMENSION(:, :, :),
INTENT(IN) :: vsh
2090 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: vat
2091 REAL(kind=
dp),
DIMENSION(:, :, :),
INTENT(IN) :: vmp
2093 INTEGER :: i, im, ispin, j
2095 REAL(kind=
dp) :: vatom
2096 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: ksblock
2097 TYPE(
block_p_type),
DIMENSION(dip_n+quad_n) :: bra, ket
2099 CALL tb_get_multipole_blocks(tb, irow, icol, img, bra, ket)
2100 DO ispin = 1,
SIZE(ks_matrix, 1)
2101 CALL dbcsr_get_block_p(ks_matrix(ispin, img)%matrix, irow, icol, block=ksblock, found=found)
2103 vatom = vat(irow, ispin) + vat(icol, ispin)
2104 DO j = 1,
SIZE(sblock, 2)
2105 DO i = 1,
SIZE(sblock, 1)
2106 ksblock(i, j) = ksblock(i, j) - 0.5_dp*(vsh(i, irow, ispin)*sblock(i, j) &
2107 + sblock(i, j)*vsh(j, icol, ispin))
2108 ksblock(i, j) = ksblock(i, j) - 0.5_dp*vatom*sblock(i, j)
2111 DO im = 1,
SIZE(vmp, 1)
2112 ksblock(:, :) = ksblock(:, :) - 0.5_dp*(ket(im)%block(:, :)*vmp(im, irow, ispin) &
2113 + bra(im)%block(:, :)*vmp(im, icol, ispin))
2116 END SUBROUTINE tb_ham_add_block
2129#if defined(__TBLITE)
2130 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tb_get_multipole'
2132 INTEGER :: handle, nimg, maxsgf, img, i,
idx, slot, ic, im
2133 INTEGER :: ikind, jkind, iatom, jatom, irow, icol, ityp, jtyp
2134 INTEGER :: iset, jset, inda, indb, ia, ib, ij, ni, nj
2135 INTEGER,
DIMENSION(3) :: cell
2136 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2138 REAL(kind=
dp),
DIMENSION(3) :: rij
2139 REAL(kind=
dp),
DIMENSION(:),
ALLOCATABLE :: stmp
2140 REAL(kind=
dp),
DIMENSION(:, :),
ALLOCATABLE :: dtmp, qtmp, dtmpj, qtmpj
2141 REAL(kind=
dp),
DIMENSION(:, :, :, :),
ALLOCATABLE :: pair_multipole
2142 TYPE(
block_p_type),
DIMENSION(dip_n + quad_n) :: bra, ket
2143 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
2149 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2153 INTEGER,
PARAMETER :: nlock = 501
2155 CALL timeset(routinen, handle)
2156 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, sab_orb=sab_orb, sab_kp=sab_kp, &
2157 dft_control=dft_control, kpoints=kpoints, matrix_s_kp=matrix_s)
2158 nimg = dft_control%nimages
2160 IF (.NOT.
ASSOCIATED(sab_kp))
THEN
2161 cpabort(
"Missing k-point neighbor list for tblite multipoles")
2167 ALLOCATE (basis_set_list(
SIZE(qs_kind_set)))
2177 idx = i + dip_n*(img - 1)
2178 ALLOCATE (tb%dipbra(
idx)%matrix)
2179 ALLOCATE (tb%dipket(
idx)%matrix)
2180 CALL dbcsr_create(tb%dipbra(
idx)%matrix, template=matrix_s(1, img)%matrix, &
2181 name=
"DIPOLE BRAMATRIX")
2182 CALL dbcsr_create(tb%dipket(
idx)%matrix, template=matrix_s(1, img)%matrix, &
2183 name=
"DIPOLE KETMATRIX")
2188 idx = i + quad_n*(img - 1)
2189 ALLOCATE (tb%quadbra(
idx)%matrix)
2190 ALLOCATE (tb%quadket(
idx)%matrix)
2191 CALL dbcsr_create(tb%quadbra(
idx)%matrix, template=matrix_s(1, img)%matrix, &
2192 name=
"QUADRUPOLE BRAMATRIX")
2193 CALL dbcsr_create(tb%quadket(
idx)%matrix, template=matrix_s(1, img)%matrix, &
2194 name=
"QUADRUPOLE KETMATRIX")
2210 ALLOCATE (stmp(msao(tb%calc%bas%maxl)**2))
2211 ALLOCATE (dtmp(dip_n,
SIZE(stmp)), qtmp(quad_n,
SIZE(stmp)))
2212 ALLOCATE (dtmpj(dip_n,
SIZE(stmp)), qtmpj(quad_n,
SIZE(stmp)))
2213 ALLOCATE (pair_multipole(maxsgf, maxsgf, dip_n + quad_n, 2))
2215 DO slot = 1, sab_orb(1)%nl_size
2216 ikind = sab_orb(1)%nlist_task(slot)%ikind
2217 jkind = sab_orb(1)%nlist_task(slot)%jkind
2218 iatom = sab_orb(1)%nlist_task(slot)%iatom
2219 jatom = sab_orb(1)%nlist_task(slot)%jatom
2220 cell(:) = sab_orb(1)%nlist_task(slot)%cell(:)
2221 rij(:) = sab_orb(1)%nlist_task(slot)%r(:)
2223 irow = min(iatom, jatom)
2224 icol = max(iatom, jatom)
2225 IF (iatom < jatom)
THEN
2234 ic = cell_to_index(cell(1), cell(2), cell(3))
2237 ityp = tb%mol%id(icol)
2238 jtyp = tb%mol%id(irow)
2239 basis_set_a => basis_set_list(ikind)%gto_basis_set
2240 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
2241 basis_set_b => basis_set_list(jkind)%gto_basis_set
2242 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
2243 CALL tb_get_multipole_blocks(tb, irow, icol, ic, bra, ket)
2244 ni =
SIZE(bra(1)%block, 1)
2245 nj =
SIZE(bra(1)%block, 2)
2246 pair_multipole(1:ni, 1:nj, :, :) = 0.0_dp
2248 DO iset = 1, basis_set_a%nset
2249 DO jset = 1, basis_set_b%nset
2250 CALL multipole_cgto(tb%calc%bas%cgto(jset, jtyp), tb%calc%bas%cgto(iset, ityp), &
2251 r2, -rij, tb%calc%bas%intcut, stmp, dtmp, qtmp)
2252 DO inda = 1, basis_set_a%nsgf_set(iset)
2253 ia = basis_set_a%first_sgf(1, iset) - basis_set_a%first_sgf(1, 1) + inda
2254 DO indb = 1, basis_set_b%nsgf_set(jset)
2255 ib = basis_set_b%first_sgf(1, jset) - basis_set_b%first_sgf(1, 1) + indb
2256 ij = indb + basis_set_b%nsgf_set(jset)*(inda - 1)
2258 IF (icol == irow .AND. r2 < same_atom**2)
THEN
2259 dtmpj(:, ij) = dtmp(:, ij)
2260 qtmpj(:, ij) = qtmp(:, ij)
2262 CALL tb_shift_multipole(-rij, stmp(ij), dtmp(:, ij), qtmp(:, ij), &
2263 dtmpj(:, ij), qtmpj(:, ij))
2265 pair_multipole(ib, ia, 1:dip_n, 1) = pair_multipole(ib, ia, 1:dip_n, 1) + dtmp(:, ij)
2266 pair_multipole(ib, ia, dip_n + 1:, 1) = pair_multipole(ib, ia, dip_n + 1:, 1) + qtmp(:, ij)
2267 pair_multipole(ib, ia, 1:dip_n, 2) = pair_multipole(ib, ia, 1:dip_n, 2) + dtmpj(:, ij)
2268 pair_multipole(ib, ia, dip_n + 1:, 2) = pair_multipole(ib, ia, dip_n + 1:, 2) + qtmpj(:, ij)
2278 DO im = 1, dip_n + quad_n
2279 bra(im)%block(:, :) = bra(im)%block(:, :) + pair_multipole(1:ni, 1:nj, im, 1)
2280 ket(im)%block(:, :) = ket(im)%block(:, :) + pair_multipole(1:ni, 1:nj, im, 2)
2285 DEALLOCATE (stmp, dtmp, qtmp, dtmpj, qtmpj, pair_multipole)
2292 DO i = 1,
SIZE(tb%dipbra)
2296 DO i = 1,
SIZE(tb%quadbra)
2300 DEALLOCATE (basis_set_list)
2301 CALL timestop(handle)
2305 cpabort(
"Built without TBLITE")
2319 PURE SUBROUTINE tb_shift_multipole(vec, s, di, qi, dj, qj)
2321 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: vec
2322 REAL(kind=
dp),
INTENT(IN) :: s
2323 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: di, qi
2324 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: dj, qj
2328 dj(1) = di(1) + vec(1)*s
2329 dj(2) = di(2) + vec(2)*s
2330 dj(3) = di(3) + vec(3)*s
2332 qj(1) = 2*vec(1)*di(1) + vec(1)**2*s
2333 qj(3) = 2*vec(2)*di(2) + vec(2)**2*s
2334 qj(6) = 2*vec(3)*di(3) + vec(3)**2*s
2335 qj(2) = vec(1)*di(2) + vec(2)*di(1) + vec(1)*vec(2)*s
2336 qj(4) = vec(1)*di(3) + vec(3)*di(1) + vec(1)*vec(3)*s
2337 qj(5) = vec(2)*di(3) + vec(3)*di(2) + vec(2)*vec(3)*s
2338 tr = 0.5_dp*(qj(1) + qj(3) + qj(6))
2340 qj(1) = qi(1) + 1.5_dp*qj(1) - tr
2341 qj(2) = qi(2) + 1.5_dp*qj(2)
2342 qj(3) = qi(3) + 1.5_dp*qj(3) - tr
2343 qj(4) = qi(4) + 1.5_dp*qj(4)
2344 qj(5) = qi(5) + 1.5_dp*qj(5)
2345 qj(6) = qi(6) + 1.5_dp*qj(6) - tr
2347 END SUBROUTINE tb_shift_multipole
2349#if defined(__TBLITE)
2359 SUBROUTINE tb_get_multipole_blocks(tb, irow, icol, img, bra, ket)
2361 INTEGER,
INTENT(IN) :: irow, icol, img
2362 TYPE(
block_p_type),
DIMENSION(:),
INTENT(OUT) :: bra, ket
2364 INTEGER ::
idx, im, ndip
2368 IF (
ASSOCIATED(tb%dipbra))
THEN
2371 idx = im + dip_n*(img - 1)
2378 IF (
ASSOCIATED(tb%quadbra))
THEN
2380 idx = im + quad_n*(img - 1)
2381 CALL dbcsr_get_block_p(tb%quadbra(
idx)%matrix, irow, icol, block=bra(ndip + im)%block, found=found)
2383 CALL dbcsr_get_block_p(tb%quadket(
idx)%matrix, irow, icol, block=ket(ndip + im)%block, found=found)
2387 END SUBROUTINE tb_get_multipole_blocks
2399 SUBROUTINE tb_contract_population(tb, matrix_p, matrix_s, para_env, charges, dipoles, quadrupoles)
2401 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s
2403 REAL(kind=
dp),
DIMENSION(:, :, :),
INTENT(OUT) :: charges
2404 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :), &
2405 INTENT(INOUT) :: dipoles, quadrupoles
2407 INTEGER :: i, icol, im, img, irow, ispin, j, natom, &
2408 ndip, nquad, nsgf, nspin
2410 REAL(kind=
dp) :: pcol, prow, ps
2411 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: local_population, population
2412 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pblock, sblock
2413 TYPE(
block_p_type),
DIMENSION(dip_n+quad_n) :: bra, ket
2416 nsgf =
SIZE(charges, 1)
2417 natom =
SIZE(charges, 2)
2418 nspin =
SIZE(charges, 3)
2419 ndip = merge(dip_n, 0,
ALLOCATED(dipoles))
2420 nquad = merge(quad_n, 0,
ALLOCATED(quadrupoles))
2421 ALLOCATE (population(nsgf + ndip + nquad, natom, nspin))
2427 ALLOCATE (local_population(nsgf + ndip + nquad, natom, nspin))
2428 local_population = 0.0_dp
2429 DO img = 1,
SIZE(matrix_s, 2)
2433 CALL tb_get_multipole_blocks(tb, irow, icol, img, bra, ket)
2435 CALL dbcsr_get_block_p(matrix_p(ispin, img)%matrix, irow, icol, block=pblock, found=found)
2436 IF (.NOT. found) cycle
2437 DO j = 1,
SIZE(pblock, 2)
2438 DO i = 1,
SIZE(pblock, 1)
2439 ps = pblock(i, j)*sblock(i, j)
2440 local_population(i, irow, ispin) = local_population(i, irow, ispin) + ps
2441 IF (irow /= icol)
THEN
2442 local_population(j, icol, ispin) = local_population(j, icol, ispin) + ps
2446 DO im = 1, ndip + nquad
2447 IF (irow == icol)
THEN
2448 prow = sum(pblock*bra(im)%block)
2450 prow = sum(pblock*ket(im)%block)
2451 pcol = sum(pblock*bra(im)%block)
2452 local_population(nsgf + im, icol, ispin) = local_population(nsgf + im, icol, ispin) + pcol
2454 local_population(nsgf + im, irow, ispin) = local_population(nsgf + im, irow, ispin) + prow
2461 population(:, :, :) = population(:, :, :) + local_population(:, :, :)
2463 DEALLOCATE (local_population)
2467 CALL para_env%sum(population)
2468 charges(:, :, :) = population(1:nsgf, :, :)
2471 dipoles(:, im, ispin) = population(nsgf + im, :, ispin)
2474 quadrupoles(:, im, ispin) = population(nsgf + ndip + im, :, ispin)
2477 DEALLOCATE (population)
2478 END SUBROUTINE tb_contract_population
2489 SUBROUTINE tb_grad2force(qs_env, tb, para_env, ityp, replicated)
2495 LOGICAL,
INTENT(IN) :: replicated
2497 CHARACTER(len=*),
PARAMETER :: routinen =
'tb_grad2force'
2499 INTEGER :: atoma, handle, iatom, ikind, natom
2500 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
2501 REAL(kind=
dp) :: scale
2506 CALL timeset(routinen, handle)
2508 NULLIFY (force, atomic_kind_set)
2509 CALL get_qs_env(qs_env=qs_env, force=force, particle_set=particle_set, &
2510 atomic_kind_set=atomic_kind_set)
2512 atom_of_kind=atom_of_kind, kind_of=kind_of)
2514 natom =
SIZE(particle_set)
2518 IF (replicated) scale = 1.0_dp/para_env%num_pe
2522 cpabort(
"unknown force type")
2525 ikind = kind_of(iatom)
2526 atoma = atom_of_kind(iatom)
2527 force(ikind)%all_potential(:, atoma) = &
2528 force(ikind)%all_potential(:, atoma) + scale*tb%grad(:, iatom)
2532 ikind = kind_of(iatom)
2533 atoma = atom_of_kind(iatom)
2534 force(ikind)%repulsive(:, atoma) = &
2535 force(ikind)%repulsive(:, atoma) + scale*tb%grad(:, iatom)
2539 ikind = kind_of(iatom)
2540 atoma = atom_of_kind(iatom)
2541 force(ikind)%dispersion(:, atoma) = &
2542 force(ikind)%dispersion(:, atoma) + scale*tb%grad(:, iatom)
2546 ikind = kind_of(iatom)
2547 atoma = atom_of_kind(iatom)
2548 force(ikind)%rho_elec(:, atoma) = &
2549 force(ikind)%rho_elec(:, atoma) + scale*tb%grad(:, iatom)
2553 ikind = kind_of(iatom)
2554 atoma = atom_of_kind(iatom)
2555 force(ikind)%overlap(:, atoma) = &
2556 force(ikind)%overlap(:, atoma) + scale*tb%grad(:, iatom)
2560 ikind = kind_of(iatom)
2561 atoma = atom_of_kind(iatom)
2562 force(ikind)%efield(:, atoma) = &
2563 force(ikind)%efield(:, atoma) + scale*tb%grad(:, iatom)
2567 CALL timestop(handle)
2569 END SUBROUTINE tb_grad2force
2580 LOGICAL,
INTENT(IN) :: use_rho
2581 INTEGER,
INTENT(IN) :: nimg
2583#if defined(__TBLITE)
2584 INTEGER :: i, idim, ij, iatom, ic, icol, ikind, img, ispin, &
2585 jdim, ni, nj, nkind, nel, &
2586 ityp, jatom, jkind, jrow, jtyp, iset, jset, nseti, nsetj, &
2587 ia, ib, inda, indb, sampled_axes, sampled_even_axes, &
2588 sampled_gamma_axes, nspin, ikp_axis, slot, maxsgf, natorb_a, natorb_b
2589 INTEGER,
DIMENSION(3) :: cellind, nkp_cellind, nkp_grid
2590 INTEGER,
DIMENSION(:),
POINTER :: nsgfa, nsgfb
2591 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
2592 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2593 LOGICAL :: found, gamma_centered, gamma_sampled_image_pair, &
2594 has_multipole_response, sampled_image_pair, &
2595 use_matrix_scc_stress
2596 LOGICAL,
DIMENSION(3) :: mesh_has_gamma
2597 REAL(kind=
dp) :: r2, dr, i_a_shift, j_a_shift, i_a_shift_mag, j_a_shift_mag, &
2598 ishift, jshift, ishift_mag, jshift_mag, pij_charge, &
2599 pij_magnet, mp_pair_scale, kpoint_coordinate, native_dot_tmp
2600 REAL(kind=
dp),
DIMENSION(3) :: kp_shift
2601 REAL(kind=
dp),
DIMENSION(3) :: rij, dgrad, dhgrad_charge, dhgrad_magnet, &
2602 mpgrad_charge, mpgrad_magnet
2603 REAL(kind=
dp),
DIMENSION(3, 3) :: hsigma
2604 REAL(kind=
dp),
DIMENSION(dip_n) :: idip, jdip, idip_mag, jdip_mag
2605 REAL(kind=
dp),
DIMENSION(quad_n) :: iquad, jquad, iquad_mag, jquad_mag
2606 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: t_ov
2607 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: local_grad
2608 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: t_dip, t_quad, t_d_ov
2609 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: t_i_dip, t_i_quad, t_j_dip, t_j_quad
2610 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :, :, :) :: scc_strain_hint
2611 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pblock, pblock_beta
2612 TYPE(
block_p_type),
DIMENSION(3, 3, 2) :: scc_strain_blocks
2615 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_dh_scc, matrix_p
2624 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2633 INTEGER,
PARAMETER :: nlock = 501
2636 NULLIFY (scf_env, rho, tb, sab_orb, sab_kp, para_env, kpoints, matrix_dh_scc, virial)
2638 atomic_kind_set=atomic_kind_set, &
2644 para_env=para_env, &
2645 qs_kind_set=qs_kind_set, &
2648 NULLIFY (cell_to_index)
2650 IF (.NOT.
ASSOCIATED(sab_kp)) cpabort(
"Missing tblite k-point neighbor list")
2652 CALL get_kpoint_info(kpoint=kpoints, cell_to_index=cell_to_index, nkp_grid=nkp_grid, &
2653 kp_shift=kp_shift, gamma_centered=gamma_centered)
2657 gamma_centered = .true.
2659 mesh_has_gamma = .false.
2661 DO ikp_axis = 1, nkp_grid(i)
2662 IF (gamma_centered .AND.
modulo(nkp_grid(i), 2) == 0)
THEN
2663 kpoint_coordinate = real(2*ikp_axis - nkp_grid(i), kind=
dp)/ &
2664 REAL(2*nkp_grid(i), kind=
dp) + kp_shift(i)
2666 kpoint_coordinate = real(2*ikp_axis - nkp_grid(i) - 1, kind=
dp)/ &
2667 REAL(2*nkp_grid(i), kind=
dp) + kp_shift(i)
2669 IF (abs(kpoint_coordinate - anint(kpoint_coordinate)) < 1.0e-12_dp)
THEN
2670 mesh_has_gamma(i) = .true.
2674 has_multipole_response =
ASSOCIATED(tb%dipbra) .OR.
ASSOCIATED(tb%quadbra)
2679 ELSE IF (
ASSOCIATED(tb%rho_ao_kp_ref))
THEN
2680 matrix_p => tb%rho_ao_kp_ref
2682 matrix_p => scf_env%p_mix_new
2684 nspin =
SIZE(matrix_p, 1)
2685 use_matrix_scc_stress = tb%use_virial .AND. nimg > 1 .AND. all(tb%mol%periodic)
2687 IF (use_matrix_scc_stress)
THEN
2693 i = idim + 3*(jdim - 1) + 9*(ispin - 1)
2694 ALLOCATE (matrix_dh_scc(i, img)%matrix)
2695 CALL dbcsr_create(matrix_dh_scc(i, img)%matrix, template=matrix_p(ispin, img)%matrix, &
2696 name=
"TBLITE SCC STRAIN DERIVATIVE")
2705 nkind =
SIZE(atomic_kind_set)
2706 ALLOCATE (basis_set_list(nkind))
2709 nel = msao(tb%calc%bas%maxl)**2
2730 ALLOCATE (t_ov(nel), t_d_ov(3, nel), t_dip(dip_n, nel), t_quad(quad_n, nel))
2731 ALLOCATE (t_i_dip(3, dip_n, nel), t_j_dip(3, dip_n, nel))
2732 ALLOCATE (t_i_quad(3, quad_n, nel), t_j_quad(3, quad_n, nel))
2733 ALLOCATE (local_grad(3, tb%mol%nat))
2735 IF (use_matrix_scc_stress)
ALLOCATE (scc_strain_hint(maxsgf, maxsgf, 3, 3, nspin))
2737 DO slot = 1, sab_orb(1)%nl_size
2738 ikind = sab_orb(1)%nlist_task(slot)%ikind
2739 jkind = sab_orb(1)%nlist_task(slot)%jkind
2740 iatom = sab_orb(1)%nlist_task(slot)%iatom
2741 jatom = sab_orb(1)%nlist_task(slot)%jatom
2742 cellind(:) = sab_orb(1)%nlist_task(slot)%cell(:)
2743 rij(:) = sab_orb(1)%nlist_task(slot)%r(:)
2745 icol = max(iatom, jatom)
2746 jrow = min(iatom, jatom)
2748 IF (iatom < jatom)
THEN
2755 ityp = tb%mol%id(icol)
2756 jtyp = tb%mol%id(jrow)
2758 r2 = dot_product(rij, rij)
2760 IF (icol == jrow .AND. dr < same_atom) cycle
2763 basis_set_a => basis_set_list(ikind)%gto_basis_set
2764 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
2765 first_sgfa => basis_set_a%first_sgf
2766 nsgfa => basis_set_a%nsgf_set
2767 nseti = basis_set_a%nset
2768 basis_set_b => basis_set_list(jkind)%gto_basis_set
2769 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
2770 first_sgfb => basis_set_b%first_sgf
2771 nsgfb => basis_set_b%nsgf_set
2772 nsetj = basis_set_b%nset
2777 ic = cell_to_index(cellind(1), cellind(2), cellind(3))
2782 IF (nkp_grid(i) > 1)
THEN
2783 nkp_cellind(i) =
modulo(cellind(i), nkp_grid(i))
2784 IF (2*nkp_cellind(i) > nkp_grid(i)) nkp_cellind(i) = nkp_cellind(i) - nkp_grid(i)
2788 IF (nkp_cellind(1) /= 0) sampled_axes = sampled_axes + 1
2789 IF (nkp_cellind(2) /= 0) sampled_axes = sampled_axes + 1
2790 IF (nkp_cellind(3) /= 0) sampled_axes = sampled_axes + 1
2791 sampled_even_axes = 0
2792 sampled_gamma_axes = 0
2794 IF (nkp_grid(i) > 1 .AND.
modulo(nkp_grid(i), 2) == 0 .AND. &
2795 abs(2*nkp_cellind(i)) == nkp_grid(i))
THEN
2796 sampled_even_axes = sampled_even_axes + 1
2797 IF (mesh_has_gamma(i)) sampled_gamma_axes = sampled_gamma_axes + 1
2800 sampled_image_pair = sampled_axes > 0 .AND. sampled_even_axes > 0
2801 gamma_sampled_image_pair = sampled_image_pair .AND. sampled_gamma_axes == sampled_even_axes
2802 mp_pair_scale = 1.0_dp
2803 IF (icol == jrow .AND. sampled_image_pair .AND. has_multipole_response .AND. &
2804 .NOT. gamma_sampled_image_pair) mp_pair_scale = -1.0_dp
2806 NULLIFY (pblock, pblock_beta)
2808 row=jrow, col=icol, block=pblock, found=found)
2809 IF (.NOT. found) cpabort(
"pblock not found")
2812 row=jrow, col=icol, block=pblock_beta, found=found)
2813 IF (.NOT. found) cpabort(
"pblock beta not found")
2815 IF (use_matrix_scc_stress)
THEN
2816 natorb_a =
SIZE(pblock, 2)
2817 natorb_b =
SIZE(pblock, 1)
2818 scc_strain_hint(1:natorb_a, 1:natorb_b, :, :, :) = 0.0_dp
2822 NULLIFY (scc_strain_blocks(idim, jdim, ispin)%block)
2823 i = idim + 3*(jdim - 1) + 9*(ispin - 1)
2825 row=jrow, col=icol, &
2826 block=scc_strain_blocks(idim, jdim, ispin)%block, found=found)
2827 IF (.NOT. found) cpabort(
"SCC strain derivative block not found")
2832 i_a_shift = tb%pot%vat(icol, 1)
2833 j_a_shift = tb%pot%vat(jrow, 1)
2834 i_a_shift_mag = 0.0_dp
2835 j_a_shift_mag = 0.0_dp
2836 IF (
SIZE(tb%pot%vat, 2) > 1)
THEN
2837 i_a_shift_mag = tb%pot%vat(icol, 2)
2838 j_a_shift_mag = tb%pot%vat(jrow, 2)
2840 idip(:) = tb%pot%vdp(:, icol, 1)
2841 jdip(:) = tb%pot%vdp(:, jrow, 1)
2842 idip_mag(:) = 0.0_dp
2843 jdip_mag(:) = 0.0_dp
2844 IF (
SIZE(tb%pot%vdp, 3) > 1)
THEN
2845 idip_mag(:) = tb%pot%vdp(:, icol, 2)
2846 jdip_mag(:) = tb%pot%vdp(:, jrow, 2)
2848 iquad(:) = tb%pot%vqp(:, icol, 1)
2849 jquad(:) = tb%pot%vqp(:, jrow, 1)
2850 iquad_mag(:) = 0.0_dp
2851 jquad_mag(:) = 0.0_dp
2852 IF (
SIZE(tb%pot%vqp, 3) > 1)
THEN
2853 iquad_mag(:) = tb%pot%vqp(:, icol, 2)
2854 jquad_mag(:) = tb%pot%vqp(:, jrow, 2)
2856 ni = tb%calc%bas%ish_at(icol)
2858 ishift = i_a_shift + tb%pot%vsh(ni + iset, 1)
2860 IF (
SIZE(tb%pot%vsh, 2) > 1) ishift_mag = i_a_shift_mag + tb%pot%vsh(ni + iset, 2)
2861 nj = tb%calc%bas%ish_at(jrow)
2863 jshift = j_a_shift + tb%pot%vsh(nj + jset, 1)
2865 IF (
SIZE(tb%pot%vsh, 2) > 1) jshift_mag = j_a_shift_mag + tb%pot%vsh(nj + jset, 2)
2868 IF (has_multipole_response)
THEN
2869 CALL multipole_grad_cgto(tb%calc%bas%cgto(iset, ityp), tb%calc%bas%cgto(jset, jtyp), &
2870 & r2, rij, tb%calc%bas%intcut, t_ov, t_dip, t_quad, t_d_ov, t_i_dip, t_i_quad, &
2871 & t_j_dip, t_j_quad)
2873 CALL overlap_grad_cgto(tb%calc%bas%cgto(iset, ityp), tb%calc%bas%cgto(jset, jtyp), &
2874 r2, rij, tb%calc%bas%intcut, t_ov, t_d_ov)
2878 DO inda = 1, nsgfa(iset)
2879 ia = first_sgfa(1, iset) - first_sgfa(1, 1) + inda
2880 DO indb = 1, nsgfb(jset)
2881 ib = first_sgfb(1, jset) - first_sgfb(1, 1) + indb
2883 ij = inda + nsgfa(iset)*(indb - 1)
2885 pij_charge = pblock(ib, ia)
2888 pij_charge = pij_charge + pblock_beta(ib, ia)
2889 pij_magnet = pblock(ib, ia) - pblock_beta(ib, ia)
2891 mpgrad_charge = 0.0_dp
2892 mpgrad_magnet = 0.0_dp
2893 IF (has_multipole_response)
THEN
2894 mpgrad_charge = matmul(t_i_dip(:, :, ij), idip) &
2895 + matmul(t_j_dip(:, :, ij), jdip) &
2896 + matmul(t_i_quad(:, :, ij), iquad) &
2897 + matmul(t_j_quad(:, :, ij), jquad)
2899 mpgrad_magnet = matmul(t_i_dip(:, :, ij), idip_mag) &
2900 + matmul(t_j_dip(:, :, ij), jdip_mag) &
2901 + matmul(t_i_quad(:, :, ij), iquad_mag) &
2902 + matmul(t_j_quad(:, :, ij), jquad_mag)
2905 dhgrad_charge = -(ishift + jshift)*t_d_ov(:, ij) - mp_pair_scale*mpgrad_charge
2906 dhgrad_magnet = -(ishift_mag + jshift_mag)*t_d_ov(:, ij) - mp_pair_scale*mpgrad_magnet
2907 dgrad(:) = dgrad(:) - &
2908 ((ishift + jshift)*pij_charge + &
2909 (ishift_mag + jshift_mag)*pij_magnet)*t_d_ov(:, ij) - &
2910 mp_pair_scale*(pij_charge*mpgrad_charge + pij_magnet*mpgrad_magnet)
2912 IF (use_matrix_scc_stress)
THEN
2915 scc_strain_hint(ia, ib, idim, jdim, 1) = &
2916 scc_strain_hint(ia, ib, idim, jdim, 1) &
2917 + (dhgrad_charge(idim) + merge(dhgrad_magnet(idim), 0.0_dp, nspin > 1))*rij(jdim)
2919 scc_strain_hint(ia, ib, idim, jdim, 2) = &
2920 scc_strain_hint(ia, ib, idim, jdim, 2) &
2921 + (dhgrad_charge(idim) - dhgrad_magnet(idim))*rij(jdim)
2929 local_grad(:, icol) = local_grad(:, icol) - dgrad
2930 local_grad(:, jrow) = local_grad(:, jrow) + dgrad
2931 IF (tb%use_virial .AND. .NOT. use_matrix_scc_stress)
THEN
2932 IF (icol == jrow)
THEN
2935 IF (sampled_image_pair .AND. .NOT. gamma_sampled_image_pair)
THEN
2936 hsigma(ia, ib) = hsigma(ia, ib) - 0.25_dp* &
2937 (rij(ia)*dgrad(ib) + rij(ib)*dgrad(ia))
2939 hsigma(ia, ib) = hsigma(ia, ib) + 0.25_dp* &
2940 (rij(ia)*dgrad(ib) + rij(ib)*dgrad(ia))
2947 hsigma(ia, ib) = hsigma(ia, ib) + 0.50_dp*(rij(ia)*dgrad(ib) + rij(ib)*dgrad(ia))
2954 IF (use_matrix_scc_stress)
THEN
2961 IF (icol <= jrow)
THEN
2962 scc_strain_blocks(idim, jdim, ispin)%block(:, :) = &
2963 scc_strain_blocks(idim, jdim, ispin)%block(:, :) &
2964 + scc_strain_hint(1:natorb_a, 1:natorb_b, idim, jdim, ispin)
2966 scc_strain_blocks(idim, jdim, ispin)%block(:, :) = &
2967 scc_strain_blocks(idim, jdim, ispin)%block(:, :) &
2968 + transpose(scc_strain_hint(1:natorb_a, 1:natorb_b, idim, jdim, ispin))
2978 tb%grad(:, :) = tb%grad(:, :) + local_grad(:, :)
2980 DEALLOCATE (local_grad, t_ov, t_d_ov, t_dip, t_quad, t_i_dip, t_j_dip, t_i_quad, t_j_quad)
2981 IF (
ALLOCATED(scc_strain_hint))
DEALLOCATE (scc_strain_hint)
2988 IF (use_matrix_scc_stress)
THEN
2994 i = idim + 3*(jdim - 1) + 9*(ispin - 1)
2996 CALL dbcsr_dot(matrix_dh_scc(i, img)%matrix, matrix_p(ispin, img)%matrix, native_dot_tmp)
2998 hsigma(idim, jdim) = hsigma(idim, jdim) + 0.5_dp*native_dot_tmp
3005 CALL para_env%sum(hsigma)
3007 CALL para_env%sum(tb%grad)
3008 CALL tb_grad2force(qs_env, tb, para_env, 4, replicated=.true.)
3010 DEALLOCATE (basis_set_list)
3012 IF (tb%use_virial)
THEN
3013 CALL tb_add_stress(qs_env, tb)
3014 CALL get_qs_env(qs_env=qs_env, virial=virial)
3016 virial%pv_virial = virial%pv_virial - hsigma/para_env%num_pe
3023 cpabort(
"Built without TBLITE")
3033 SUBROUTINE tb_add_stress(qs_env, tb)
3038 INTEGER,
DIMENSION(3) :: periodic
3042 NULLIFY (virial, cell)
3043 CALL get_qs_env(qs_env=qs_env, virial=virial, cell=cell)
3044 CALL get_cell(cell=cell, periodic=periodic)
3046 IF (all(periodic == 0))
THEN
3047 CALL cp_warn(__location__, &
3048 "tblite stress tensor requested for an isolated system. "// &
3049 "The reported virial is useful for finite-difference checks, "// &
3050 "but it is not a physically meaningful bulk stress for an isolated molecule.")
3053 virial%pv_virial = virial%pv_virial - tb%sigma
3055 END SUBROUTINE tb_add_stress
3064 SUBROUTINE tb_add_grad(grad, deriv, dE, natom)
3066 REAL(kind=
dp),
DIMENSION(:, :) :: grad
3067 REAL(kind=
dp),
DIMENSION(:, :, :) :: deriv
3068 REAL(kind=
dp),
DIMENSION(:) :: de
3075 grad(:, i) = grad(:, i) + deriv(:, i, j)*de(j)
3079 END SUBROUTINE tb_add_grad
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, rr_work)
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)
...
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_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.
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...
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 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 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, file_access)
...
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
integer, parameter, public default_string_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, lattice_fft)
Retrieve information from a kpoint environment.
Utility routines for the memory handling.
Interface to the message passing library MPI.
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.
pure real(kind=dp) function, public tblite_scc_error_on_cp2k_scale(raw_error, eps_scf, pconv)
Map a raw tblite SCC residual to CP2K's EPS_SCF reporting scale.
real(kind=dp), parameter, public tblite_scc_pconv
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.
module that contains the definitions of the scf types
integer, parameter, public modified_broyden_mixing_nr
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.
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.
Calculation of overlap matrix, its derivatives and forces.
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_ham(qs_env, calculate_forces)
Prepare geometry-dependent data once, before SCF, including requested core forces.
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)
...
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)
...
pure subroutine, public virial_pair_force(pv_virial, f0, force, rab)
Computes the contribution to the stress tensor from two-body pair-wise forces.
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, ngauss, 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.