9#include "gauxc/gauxc_config.f"
37 USE iso_c_binding,
ONLY: c_char,&
64 USE xc_gauxc_interface,
ONLY: &
65 cp_gauxc_basisset_type, cp_gauxc_grid_type, cp_gauxc_integrator_type, &
66 cp_gauxc_molecule_type, cp_gauxc_status_type, cp_gauxc_xc_gradient_type, cp_gauxc_xc_type, &
67 gauxc_check_status, gauxc_compute_xc, gauxc_compute_xc_gradient, gauxc_create_basisset, &
68 gauxc_create_grid, gauxc_create_integrator, gauxc_create_molecule, gauxc_destroy_basisset, &
69 gauxc_destroy_grid, gauxc_destroy_integrator, gauxc_destroy_molecule, &
70 gauxc_write_basisset_hdf5, gauxc_write_molecule_hdf5
72#include "../base/base_uses.f90"
78 LOGICAL,
PARAMETER :: debug_this_module = .true.
79 CHARACTER(LEN=*),
PARAMETER,
PRIVATE :: moduleN =
'xc_gauxc_functional'
86 INTEGER(c_int) FUNCTION c_setenv(name, value, overwrite)
BIND(C, name="setenv")
87 IMPORT :: c_char, c_int
88 CHARACTER(KIND=c_char),
DIMENSION(*),
INTENT(IN) :: name, value
89 INTEGER(c_int),
VALUE :: overwrite
92 INTEGER(c_int) FUNCTION c_unsetenv(name)
BIND(C, name="unsetenv")
93 IMPORT :: c_char, c_int
94 CHARACTER(KIND=c_char),
DIMENSION(*),
INTENT(IN) :: name
95 END FUNCTION c_unsetenv
106 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
107 LOGICAL :: all_all_electron
112 cpassert(
ASSOCIATED(qs_kind_set))
114 all_all_electron = .true.
115 DO ikind = 1,
SIZE(qs_kind_set)
116 NULLIFY (all_potential)
117 CALL get_qs_kind(qs_kind_set(ikind), all_potential=all_potential)
118 IF (.NOT.
ASSOCIATED(all_potential))
THEN
119 all_all_electron = .false.
131 SUBROUTINE set_gauxc_model_atom_chunk_env(atom_chunk_size, is_explicit)
132 INTEGER,
INTENT(IN) :: atom_chunk_size
133 LOGICAL,
INTENT(IN) :: is_explicit
135 CHARACTER(LEN=32) :: chunk_value
136 INTEGER(c_int) :: ierr
138 IF (.NOT. is_explicit)
RETURN
140 IF (atom_chunk_size < 0)
THEN
141 ierr = c_unsetenv(
"GAUXC_ONEDFT_ATOM_CHUNK_SIZE"//c_null_char)
143 WRITE (chunk_value,
'(I0)') atom_chunk_size
145 "GAUXC_ONEDFT_ATOM_CHUNK_SIZE"//c_null_char, &
146 trim(chunk_value)//c_null_char, &
149 IF (ierr /= 0_c_int)
THEN
150 CALL cp_abort(__location__, &
151 "Could not set GAUXC_ONEDFT_ATOM_CHUNK_SIZE for GauXC Skala.")
153 END SUBROUTINE set_gauxc_model_atom_chunk_env
161 SUBROUTINE dbcsr_to_dense(dbcsr_mat, dense_mat, para_env)
168 REAL(c_double),
ALLOCATABLE,
DIMENSION(:, :), &
169 INTENT(INOUT) :: dense_mat
172 CHARACTER :: matrix_type
173 INTEGER :: col_end, col_start, icol, irow, ncol, &
174 ncols, nrow, nrows, numnodes, row_end, &
176 LOGICAL :: has_symmetry, transposed
177 REAL(c_double),
POINTER :: block(:, :)
178 REAL(kind=
dp) :: symmetry_sign
183 nfullrows_total=nrows, &
184 nfullcols_total=ncols, &
188 has_symmetry = matrix_type == dbcsr_type_symmetric .OR. matrix_type == dbcsr_type_antisymmetric
189 symmetry_sign = 1.0_dp
190 IF (matrix_type == dbcsr_type_antisymmetric) symmetry_sign = -1.0_dp
192 IF (.NOT.
ALLOCATED(dense_mat))
THEN
193 ALLOCATE (dense_mat(nrows, ncols))
194 ELSE IF (.NOT. all(shape(dense_mat) == [nrows, ncols]))
THEN
195 DEALLOCATE (dense_mat)
196 ALLOCATE (dense_mat(nrows, ncols))
198 cpassert(all(shape(dense_mat) == [nrows, ncols]))
203 IF (numnodes == 1 .AND. para_env%num_pe > 1 .AND. para_env%mepos /= 0)
RETURN
211 row_size=nrow, col_size=ncol, row_offset=row_start, col_offset=col_start)
212 row_end = row_start + nrow - 1
213 col_end = col_start + ncol - 1
215 dense_mat(row_start:row_end, col_start:col_end) = symmetry_sign*transpose(block)
217 dense_mat(row_start:row_end, col_start:col_end) = block
219 IF (has_symmetry .AND. irow /= icol)
THEN
220 dense_mat(col_start:col_end, row_start:row_end) = &
221 symmetry_sign*transpose(dense_mat(row_start:row_end, col_start:col_end))
227 END SUBROUTINE dbcsr_to_dense
237 FUNCTION dense_to_dbcsr(dense_mat, template_dbcsr)
RESULT(dbcsr_mat)
248 dbcsr_type_symmetric, &
250 REAL(c_double),
DIMENSION(:, :),
INTENT(IN) :: dense_mat
254 INTEGER :: col, icol, irow, mynode, nblkcols_total, &
255 nblkrows_total, ncols, nrows, owner, &
257 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: c_offset, r_offset
258 INTEGER,
DIMENSION(:),
POINTER :: col_blk_size, row_blk_size
262 row_blk_size=row_blk_size, &
263 col_blk_size=col_blk_size, &
264 nblkrows_total=nblkrows_total, &
265 nblkcols_total=nblkcols_total, &
266 nfullrows_total=nrows, &
267 nfullcols_total=ncols, &
271 cpassert(nrows ==
SIZE(dense_mat, 1))
272 cpassert(ncols ==
SIZE(dense_mat, 2))
276 template=template_dbcsr%matrix, &
277 name=
"VXC from GauXC (dense)", &
278 matrix_type=dbcsr_type_symmetric)
281 ALLOCATE (r_offset(nblkrows_total), c_offset(nblkcols_total))
284 DO row = 2, nblkrows_total
285 r_offset(row) = r_offset(row - 1) + row_blk_size(row - 1)
288 DO col = 2, nblkcols_total
289 c_offset(col) = c_offset(col - 1) + col_blk_size(col - 1)
292 DO irow = 1, nblkrows_total
293 DO icol = 1, nblkcols_total
294 IF (irow > icol) cycle
296 IF (owner /= mynode) cycle
299 dense_mat(r_offset(irow):r_offset(irow) + row_blk_size(irow) - 1, &
300 c_offset(icol):c_offset(icol) + col_blk_size(icol) - 1) + &
301 transpose(dense_mat(r_offset(icol):r_offset(icol) + row_blk_size(icol) - 1, &
302 c_offset(irow):c_offset(irow) + col_blk_size(irow) - 1))))
308 DEALLOCATE (r_offset, c_offset)
310 END FUNCTION dense_to_dbcsr
317 FUNCTION get_gauxc_functional(xc_section)
RESULT(gauxc_functional_section)
324 NULLIFY (gauxc_functional_section)
327 IF (.NOT.
ASSOCIATED(functionals))
THEN
328 cpabort(
"XC_FUNCTIONAL section not found")
335 IF (.NOT.
ASSOCIATED(xc_fun))
EXIT
336 IF (xc_fun%section%name /=
"GAUXC" .OR. ifun > 1)
THEN
337 cpabort(
"GauXC functionals are mutually exclusive with any other functional.")
339 gauxc_functional_section => xc_fun
342 IF (.NOT.
ASSOCIATED(gauxc_functional_section))
THEN
343 cpabort(
"No XC functional found in XC_FUNCTIONAL section")
345 END FUNCTION get_gauxc_functional
354 LOGICAL :: uses_gauxc
360 IF (.NOT.
ASSOCIATED(xc_section))
RETURN
363 IF (.NOT.
ASSOCIATED(functionals))
RETURN
369 IF (.NOT.
ASSOCIATED(xc_fun))
EXIT
370 IF (xc_fun%section%name ==
"GAUXC" .OR. xc_fun%section%name ==
"SKALA_NATIVE")
THEN
384 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
385 LOGICAL :: has_pseudopotentials
391 cpassert(
ASSOCIATED(qs_kind_set))
393 has_pseudopotentials = .false.
394 DO ikind = 1,
SIZE(qs_kind_set)
395 NULLIFY (gth_potential, sgp_potential)
397 gth_potential=gth_potential, &
398 sgp_potential=sgp_potential)
399 IF (
ASSOCIATED(gth_potential) .OR.
ASSOCIATED(sgp_potential))
THEN
400 has_pseudopotentials = .true.
413 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
414 LOGICAL :: all_pseudopotentials
420 cpassert(
ASSOCIATED(qs_kind_set))
422 all_pseudopotentials = .true.
423 DO ikind = 1,
SIZE(qs_kind_set)
424 NULLIFY (gth_potential, sgp_potential)
426 gth_potential=gth_potential, &
427 sgp_potential=sgp_potential)
428 IF (.NOT. (
ASSOCIATED(gth_potential) .OR.
ASSOCIATED(sgp_potential)))
THEN
429 all_pseudopotentials = .false.
442 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
443 LOGICAL :: has_paw_pseudopotentials
450 cpassert(
ASSOCIATED(qs_kind_set))
452 has_paw_pseudopotentials = .false.
453 DO ikind = 1,
SIZE(qs_kind_set)
454 NULLIFY (gth_potential, sgp_potential)
456 gth_potential=gth_potential, &
458 sgp_potential=sgp_potential)
459 IF ((
ASSOCIATED(gth_potential) .OR.
ASSOCIATED(sgp_potential)) .AND. &
461 has_paw_pseudopotentials = .true.
478 SUBROUTINE ensure_gauxc_periodic_reference_scope( &
479 dft_control, cell, qs_kind_set, do_kpoints, periodic_reference)
482 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
483 LOGICAL,
INTENT(IN) :: do_kpoints, periodic_reference
486 LOGICAL :: is_periodic
490 cpassert(
ASSOCIATED(dft_control))
491 cpassert(
ASSOCIATED(qs_kind_set))
493 is_periodic = .false.
494 IF (
ASSOCIATED(cell)) is_periodic = any(cell%perd /= 0)
497 CALL cp_abort(__location__, &
498 "GauXC currently supports only Gamma-only density matrices in CP2K. "// &
499 "Periodic k-point density matrices require a dedicated GauXC periodic interface.")
501 IF (dft_control%nimages /= 1)
THEN
502 CALL cp_abort(__location__, &
503 "GauXC currently supports only a single AO image in CP2K. "// &
504 "Periodic neighbour-cell AO blocks require a dedicated GauXC periodic interface.")
506 IF (.NOT. is_periodic)
RETURN
508 IF (.NOT. periodic_reference)
THEN
509 CALL cp_abort(__location__, &
510 "Periodic GauXC calculations in CP2K require GAUXC%PERIODIC_REFERENCE T. "// &
511 "This opt-in documents that the current path is only an isolated-cell, "// &
512 "Gamma-only, single-image METHOD GPW reference path using GauXC molecular "// &
513 "quadrature, not a dedicated periodic GauXC interface.")
516 IF (.NOT. all(cell%perd == 1))
THEN
517 CALL cp_abort(__location__, &
518 "The current GauXC isolated-cell reference path supports only PERIODIC XYZ. "// &
519 "Partial periodicity requires a dedicated GauXC periodic interface.")
521 IF (.NOT. dft_control%qs_control%gpw)
THEN
522 CALL cp_abort(__location__, &
523 "The current GauXC isolated-cell reference path is limited to METHOD GPW with GTH "// &
524 "pseudopotentials. GAPW, GAPW_XC, and other QS methods are not supported here.")
527 DO ikind = 1,
SIZE(qs_kind_set)
528 NULLIFY (gth_potential, sgp_potential)
530 gth_potential=gth_potential, &
531 sgp_potential=sgp_potential)
532 IF (.NOT.
ASSOCIATED(gth_potential) .OR.
ASSOCIATED(sgp_potential))
THEN
533 CALL cp_abort(__location__, &
534 "The current GauXC isolated-cell reference path is limited to GTH pseudopotentials. "// &
535 "Use non-periodic all-electron GAPW validation for molecular GAPW cases.")
539 END SUBROUTINE ensure_gauxc_periodic_reference_scope
548 SUBROUTINE add_gauxc_gradient_to_force(exc_grad, force, atomic_kind_set, para_env)
549 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: exc_grad
554 INTEGER :: ia, iatom, ikind, natom_kind
557 cpassert(
ASSOCIATED(force))
558 cpassert(
ASSOCIATED(atomic_kind_set))
560 IF (para_env%mepos /= 0)
RETURN
562 DO ikind = 1,
SIZE(atomic_kind_set, 1)
563 atomic_kind => atomic_kind_set(ikind)
565 DO ia = 1, natom_kind
566 iatom = atomic_kind%atom_list(ia)
567 force(ikind)%rho_elec(:, ia) = force(ikind)%rho_elec(:, ia) + &
568 exc_grad(3*iatom - 2:3*iatom)
572 END SUBROUTINE add_gauxc_gradient_to_force
593 SUBROUTINE gauxc_xc_energy_for_particles( &
594 particle_set_eval, qs_kind_set, density_scalar, nspins, model_name, &
595 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
596 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, exc, density_zeta)
597 TYPE(
particle_type),
DIMENSION(:),
INTENT(IN) :: particle_set_eval
598 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
599 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: density_scalar
600 INTEGER,
INTENT(IN) :: nspins
601 CHARACTER(LEN=*),
INTENT(IN) :: model_name, xc_fun_name, grid_type, radial_quadrature, &
602 pruning_scheme, lb_exec_space, int_exec_space, lwd_kernel
603 INTEGER,
INTENT(IN) :: batch_size
604 REAL(kind=
dp),
INTENT(IN) :: device_runtime_fill_fraction
605 REAL(kind=
dp),
INTENT(OUT) :: exc
606 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN), &
607 OPTIONAL :: density_zeta
609 TYPE(cp_gauxc_basisset_type) :: gauxc_basis_fd
610 TYPE(cp_gauxc_grid_type) :: gauxc_grid_fd
611 TYPE(cp_gauxc_integrator_type) :: gauxc_integrator_fd
612 TYPE(cp_gauxc_molecule_type) :: gauxc_mol_fd
613 TYPE(cp_gauxc_status_type) :: gauxc_status
614 TYPE(cp_gauxc_xc_type) :: gauxc_xc_result
616 gauxc_mol_fd = gauxc_create_molecule(particle_set_eval, gauxc_status)
617 CALL gauxc_check_status(gauxc_status)
618 gauxc_basis_fd = gauxc_create_basisset(qs_kind_set, particle_set_eval, gauxc_status)
619 CALL gauxc_check_status(gauxc_status)
620 gauxc_grid_fd = gauxc_create_grid( &
628 device_runtime_fill_fraction, &
631 force_new_runtime=.true., &
632 int_exec_space=int_exec_space)
633 CALL gauxc_check_status(gauxc_status)
634 gauxc_integrator_fd = gauxc_create_integrator( &
641 CALL gauxc_check_status(gauxc_status)
643 IF (nspins == 1)
THEN
644 gauxc_xc_result = gauxc_compute_xc( &
645 gauxc_integrator_fd, &
648 status=gauxc_status, &
649 model=trim(model_name))
651 cpassert(nspins == 2)
652 cpassert(
PRESENT(density_zeta))
653 gauxc_xc_result = gauxc_compute_xc( &
654 gauxc_integrator_fd, &
659 model=trim(model_name))
661 CALL gauxc_check_status(gauxc_status)
662 exc = gauxc_xc_result%exc
664 IF (
ALLOCATED(gauxc_xc_result%vxc_scalar))
DEALLOCATE (gauxc_xc_result%vxc_scalar)
665 IF (
ALLOCATED(gauxc_xc_result%vxc_zeta))
DEALLOCATE (gauxc_xc_result%vxc_zeta)
667 CALL gauxc_destroy_integrator(gauxc_integrator_fd, gauxc_status)
668 CALL gauxc_check_status(gauxc_status)
669 CALL gauxc_destroy_grid(gauxc_grid_fd, gauxc_status)
670 CALL gauxc_check_status(gauxc_status)
671 CALL gauxc_destroy_basisset(gauxc_basis_fd, gauxc_status)
672 CALL gauxc_check_status(gauxc_status)
673 CALL gauxc_destroy_molecule(gauxc_mol_fd, gauxc_status)
674 CALL gauxc_check_status(gauxc_status)
676 END SUBROUTINE gauxc_xc_energy_for_particles
699 SUBROUTINE gauxc_xc_gradient_fd( &
700 particle_set, qs_kind_set, density_scalar, nspins, model_name, &
701 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
702 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, dx, para_env, exc_grad, &
705 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
706 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: density_scalar
707 INTEGER,
INTENT(IN) :: nspins
708 CHARACTER(LEN=*),
INTENT(IN) :: model_name, xc_fun_name, grid_type, radial_quadrature, &
709 pruning_scheme, lb_exec_space, int_exec_space, lwd_kernel
710 INTEGER,
INTENT(IN) :: batch_size
711 REAL(kind=
dp),
INTENT(IN) :: device_runtime_fill_fraction, dx
713 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
714 INTENT(OUT) :: exc_grad
715 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN), &
716 OPTIONAL :: density_zeta
718 INTEGER :: iatom, idir
719 REAL(kind=
dp) :: xc_minus, xc_plus
720 TYPE(
particle_type),
ALLOCATABLE,
DIMENSION(:) :: particle_set_minus, particle_set_plus
722 cpassert(
ASSOCIATED(particle_set))
723 cpassert(dx > 0.0_dp)
725 ALLOCATE (exc_grad(3*
SIZE(particle_set)))
728 IF (para_env%mepos == 0)
THEN
729 ALLOCATE (particle_set_minus(
SIZE(particle_set)), particle_set_plus(
SIZE(particle_set)))
731 DO iatom = 1,
SIZE(particle_set)
733 particle_set_minus = particle_set
734 particle_set_plus = particle_set
735 particle_set_minus(iatom)%r(idir) = particle_set_minus(iatom)%r(idir) - dx
736 particle_set_plus(iatom)%r(idir) = particle_set_plus(iatom)%r(idir) + dx
737 IF (
PRESENT(density_zeta))
THEN
738 CALL gauxc_xc_energy_for_particles( &
739 particle_set_plus, qs_kind_set, density_scalar, nspins, model_name, &
740 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
741 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_plus, &
742 density_zeta=density_zeta)
743 CALL gauxc_xc_energy_for_particles( &
744 particle_set_minus, qs_kind_set, density_scalar, nspins, model_name, &
745 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
746 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_minus, &
747 density_zeta=density_zeta)
749 CALL gauxc_xc_energy_for_particles( &
750 particle_set_plus, qs_kind_set, density_scalar, nspins, model_name, &
751 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
752 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_plus)
753 CALL gauxc_xc_energy_for_particles( &
754 particle_set_minus, qs_kind_set, density_scalar, nspins, model_name, &
755 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
756 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_minus)
758 exc_grad(3*iatom - 3 + idir) = (xc_plus - xc_minus)/(2.0_dp*dx)
762 DEALLOCATE (particle_set_minus, particle_set_plus)
765 CALL para_env%bcast(exc_grad, 0)
767 END SUBROUTINE gauxc_xc_gradient_fd
790 SUBROUTINE debug_gauxc_molecular_virial( &
791 exc_grad, particle_set, qs_kind_set, density_scalar, nspins, model_name, &
792 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
793 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, dx, para_env, density_zeta)
794 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: exc_grad
796 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
797 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: density_scalar
798 INTEGER,
INTENT(IN) :: nspins
799 CHARACTER(LEN=*),
INTENT(IN) :: model_name, xc_fun_name, grid_type, radial_quadrature, &
800 pruning_scheme, lb_exec_space, int_exec_space, lwd_kernel
801 INTEGER,
INTENT(IN) :: batch_size
802 REAL(kind=
dp),
INTENT(IN) :: device_runtime_fill_fraction, dx
804 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN), &
805 OPTIONAL :: density_zeta
808 REAL(kind=
dp) :: analytic_trace, diff_trace, &
809 numerical_trace, xc_minus, xc_plus
810 REAL(kind=
dp),
DIMENSION(3) :: center, displacement, grad
811 TYPE(
particle_type),
ALLOCATABLE,
DIMENSION(:) :: particle_set_minus, particle_set_plus
813 cpassert(
ASSOCIATED(particle_set))
814 cpassert(
SIZE(exc_grad) == 3*
SIZE(particle_set))
816 IF (para_env%mepos /= 0)
RETURN
819 DO iatom = 1,
SIZE(particle_set)
820 center = center + particle_set(iatom)%r
822 center = center/real(
SIZE(particle_set),
dp)
824 ALLOCATE (particle_set_minus(
SIZE(particle_set)), particle_set_plus(
SIZE(particle_set)))
825 particle_set_minus = particle_set
826 particle_set_plus = particle_set
828 analytic_trace = 0.0_dp
829 DO iatom = 1,
SIZE(particle_set)
830 grad = exc_grad(3*iatom - 2:3*iatom)
831 displacement = particle_set(iatom)%r - center
832 analytic_trace = analytic_trace + dot_product(grad, displacement)
833 particle_set_minus(iatom)%r = center + (1.0_dp - dx)*displacement
834 particle_set_plus(iatom)%r = center + (1.0_dp + dx)*displacement
836 analytic_trace = analytic_trace/3.0_dp
838 IF (
PRESENT(density_zeta))
THEN
839 CALL gauxc_xc_energy_for_particles( &
840 particle_set_plus, qs_kind_set, density_scalar, nspins, model_name, &
841 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
842 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_plus, &
843 density_zeta=density_zeta)
844 CALL gauxc_xc_energy_for_particles( &
845 particle_set_minus, qs_kind_set, density_scalar, nspins, model_name, &
846 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
847 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_minus, &
848 density_zeta=density_zeta)
850 CALL gauxc_xc_energy_for_particles( &
851 particle_set_plus, qs_kind_set, density_scalar, nspins, model_name, &
852 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
853 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_plus)
854 CALL gauxc_xc_energy_for_particles( &
855 particle_set_minus, qs_kind_set, density_scalar, nspins, model_name, &
856 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
857 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_minus)
860 numerical_trace = (xc_plus - xc_minus)/(2.0_dp*dx)/3.0_dp
861 diff_trace = analytic_trace - numerical_trace
865 WRITE (unit=iw, fmt=
"(/,T2,A,1X,ES11.4)") &
866 "GAUXC| Molecular XC virial finite-difference dx", dx
867 WRITE (unit=iw, fmt=
"(T2,A,3(1X,ES19.11))") &
868 "GAUXC| Molecular XC virial FD 1/3 Trace", &
869 analytic_trace, numerical_trace, diff_trace
872 DEALLOCATE (particle_set_minus, particle_set_plus)
874 END SUBROUTINE debug_gauxc_molecular_virial
882 SUBROUTINE print_gauxc_molecular_virial(exc_grad, particle_set, para_env)
883 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: exc_grad
887 CHARACTER(LEN=1),
DIMENSION(3),
PARAMETER :: label = [
"x",
"y",
"z"]
889 INTEGER :: i, iatom, iw, j
890 REAL(kind=
dp),
DIMENSION(3) :: center, displacement, grad, grad_sum
891 REAL(kind=
dp),
DIMENSION(3, 3) :: molecular_virial
893 cpassert(
ASSOCIATED(particle_set))
894 cpassert(
SIZE(exc_grad) == 3*
SIZE(particle_set))
896 IF (para_env%mepos /= 0)
RETURN
899 DO iatom = 1,
SIZE(particle_set)
900 center = center + particle_set(iatom)%r
902 center = center/real(
SIZE(particle_set),
dp)
905 molecular_virial = 0.0_dp
906 DO iatom = 1,
SIZE(particle_set)
907 grad = exc_grad(3*iatom - 2:3*iatom)
908 displacement = particle_set(iatom)%r - center
909 grad_sum = grad_sum + grad
912 molecular_virial(i, j) = molecular_virial(i, j) + grad(i)*displacement(j)
920 WRITE (unit=iw, fmt=
"(/,T2,A)") &
921 "GAUXC| Molecular XC gradient virial diagnostic [a.u.]"
922 WRITE (unit=iw, fmt=
"(T2,A,T20,A,T40,A,T60,A)")
"GAUXC|",
"x",
"y",
"z"
924 WRITE (unit=iw, fmt=
"(T2,A,1X,A1,3(1X,ES19.11))") &
925 "GAUXC|", label(i), molecular_virial(i, :)
927 WRITE (unit=iw, fmt=
"(T2,A,1X,ES19.11)") &
928 "GAUXC| Molecular XC gradient virial 1/3 Trace", &
929 (molecular_virial(1, 1) + molecular_virial(2, 2) + molecular_virial(3, 3))/3.0_dp
930 WRITE (unit=iw, fmt=
"(T2,A,3(1X,ES19.11))") &
931 "GAUXC| Molecular XC gradient sum", grad_sum
932 WRITE (unit=iw, fmt=
"(T2,A)") &
933 "GAUXC| Diagnostic only; this is not an analytical periodic stress tensor."
935 END SUBROUTINE print_gauxc_molecular_virial
947 SUBROUTINE skala_info(functional, lsd, reference, shortform, needs, max_deriv)
949 LOGICAL,
INTENT(IN) :: lsd
950 CHARACTER(LEN=*),
INTENT(OUT),
OPTIONAL :: reference, shortform
952 INTEGER,
INTENT(OUT),
OPTIONAL :: max_deriv
954 CHARACTER(LEN=default_path_length) :: model_key, model_name
955 CHARACTER(LEN=default_string_length) :: xc_fun_key, xc_fun_name
957 IF (functional%section%name ==
"SKALA_NATIVE")
THEN
959 IF (
PRESENT(reference)) reference =
"CP2K-native SKALA TorchScript model "//trim(model_name)
960 IF (
PRESENT(shortform)) shortform =
"SKALA (native)"
961 IF (
PRESENT(needs))
THEN
963 needs%rho_spin = .true.
964 needs%drho_spin = .true.
965 needs%tau_spin = .true.
972 IF (
PRESENT(max_deriv)) max_deriv = 1
978 model_key = adjustl(model_name)
979 xc_fun_key = adjustl(xc_fun_name)
983 IF (
PRESENT(reference))
THEN
984 IF (trim(model_key) ==
"NONE" .OR. trim(model_key) ==
"" .OR. &
985 trim(model_key) == trim(xc_fun_key))
THEN
986 reference =
"Functional computed by GauXC (underlying: "//trim(xc_fun_name)//
")"
988 reference =
"Functional computed by GauXC Skala model "//trim(model_name)
991 IF (
PRESENT(shortform))
THEN
992 IF (trim(model_key) ==
"NONE" .OR. trim(model_key) ==
"" .OR. &
993 trim(model_key) == trim(xc_fun_key))
THEN
994 shortform =
"GAUXC ("//trim(xc_fun_name)//
")"
996 shortform =
"GAUXC Skala"
999 IF (
PRESENT(needs))
THEN
1002 needs%rho_spin = .true.
1005 IF (
PRESENT(max_deriv)) max_deriv = 1
1025 rho_ao_external, exc_external, matrix_vxc_external)
1028 LOGICAL,
INTENT(IN) :: calculate_forces
1029 TYPE(dbcsr_p_type),
DIMENSION(:, :),
INTENT(IN), &
1030 OPTIONAL,
POINTER :: rho_ao_external
1031 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: exc_external
1032 TYPE(dbcsr_p_type),
DIMENSION(:),
INTENT(INOUT), &
1033 OPTIONAL,
POINTER :: matrix_vxc_external
1035 CHARACTER(LEN=*),
PARAMETER :: nonlocal_vdw_abort_message = &
1036 "GauXC does not support non-local VDW_POTENTIAL corrections. "// &
1037 "Use an additive PAIR_POTENTIAL dispersion correction or disable GauXC."
1038 REAL(kind=
dp),
PARAMETER :: gapw_fd_gradient_dx = 1.0e-4_dp
1040 CHARACTER(LEN=default_path_length) :: model_key, model_name, output_path
1041 CHARACTER(LEN=default_string_length) :: gradient_runtime, gradient_runtime_key, grid_key, &
1042 int_exec_space_key, lb_exec_space_key, lwd_kernel_key, pruning_key, skala_runtime, &
1043 skala_runtime_key, xc_fun_key
1044 INTEGER :: atom_chunk_size, env_status, gpu_mode, &
1046 LOGICAL :: atom_chunk_size_explicit, do_kpoints, external_density, gapw_method, &
1047 gapw_paw_pseudopotentials, gapw_pseudopotentials, grid_explicit, hdf5_output, &
1048 int_space_explicit, is_periodic, lb_space_explicit, low_spin_scope, molecular_virial, &
1049 molecular_virial_debug, need_xc_gradient, periodic_reference, pruning_explicit, use_cuda, &
1050 use_skala_model, write_hdf5_output
1051 REAL(kind=
dp) :: exc_value, molecular_virial_debug_dx
1052 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: density_scalar, density_zeta
1057 TYPE(cp_gauxc_status_type) :: gauxc_status
1058 TYPE(cp_gauxc_xc_gradient_type) :: exc_grad
1059 TYPE(cp_gauxc_xc_type) :: gauxc_xc_result
1060 TYPE(dbcsr_p_type) :: vxc_zeta_tmp
1061 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_vxc
1062 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao
1068 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1070 TYPE(
qs_rho_type),
POINTER :: rho, rho_use, rho_xc
1074 external_density =
PRESENT(rho_ao_external)
1075 cpassert(
PRESENT(exc_external) .EQV. external_density)
1076 cpassert(
PRESENT(matrix_vxc_external) .EQV. external_density)
1077 IF (external_density)
THEN
1078 cpassert(
ASSOCIATED(rho_ao_external))
1079 cpassert(.NOT.
ASSOCIATED(matrix_vxc_external))
1102 dft_control=dft_control, &
1103 do_kpoints=do_kpoints, &
1106 matrix_vxc=matrix_vxc, &
1107 natom=params%natom, &
1108 atomic_kind_set=atomic_kind_set, &
1110 para_env=para_env, &
1111 particle_set=particle_set, &
1112 qs_kind_set=qs_kind_set, &
1117 gapw_method = dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc
1118 gapw_pseudopotentials = gapw_method .AND. &
1120 gapw_paw_pseudopotentials = gapw_method .AND. &
1122 IF (dft_control%qs_control%gapw_xc)
THEN
1123 cpassert(
ASSOCIATED(rho_xc))
1126 cpassert(
ASSOCIATED(rho))
1133 IF (external_density)
THEN
1134 rho_ao => rho_ao_external
1136 NULLIFY (matrix_vxc)
1138 nimages = dft_control%nimages
1139 params%nspins = dft_control%nspins
1140 IF (external_density)
THEN
1141 cpassert(
SIZE(rho_ao, 1) == params%nspins)
1142 cpassert(
SIZE(rho_ao, 2) == nimages)
1144 low_spin_scope = external_density .OR. (dft_control%low_spin_roks .AND. gapw_method)
1145 is_periodic = .false.
1146 IF (
ASSOCIATED(cell)) is_periodic = any(cell%perd /= 0)
1148 IF (
ASSOCIATED(qs_env%dispersion_env))
THEN
1150 cpabort(nonlocal_vdw_abort_message)
1153 NULLIFY (vxc_zeta_tmp%matrix)
1155 gauxc_functional_section => get_gauxc_functional(xc_section)
1157 gauxc_functional_section, &
1159 c_val=params%xc_fun_name)
1161 gauxc_functional_section, &
1165 gauxc_functional_section, &
1167 c_val=params%grid_type, &
1168 explicit=grid_explicit)
1170 gauxc_functional_section, &
1171 "RADIAL_QUADRATURE", &
1172 c_val=params%radial_quadrature)
1174 gauxc_functional_section, &
1176 c_val=params%pruning_scheme, &
1177 explicit=pruning_explicit)
1179 gauxc_functional_section, &
1181 i_val=params%batch_size)
1183 gauxc_functional_section, &
1184 "DEVICE_RUNTIME_FILL_FRACTION", &
1185 r_val=params%device_runtime_fill_fraction)
1187 gauxc_functional_section, &
1188 "MODEL_ATOM_CHUNK_SIZE", &
1189 i_val=atom_chunk_size, &
1190 explicit=atom_chunk_size_explicit)
1192 gauxc_functional_section, &
1193 "PERIODIC_REFERENCE", &
1194 l_val=periodic_reference)
1196 gauxc_functional_section, &
1197 "MOLECULAR_VIRIAL", &
1198 l_val=molecular_virial)
1200 gauxc_functional_section, &
1201 "MOLECULAR_VIRIAL_DEBUG", &
1202 l_val=molecular_virial_debug)
1204 gauxc_functional_section, &
1205 "MOLECULAR_VIRIAL_DEBUG_DX", &
1206 r_val=molecular_virial_debug_dx)
1208 gauxc_functional_section, &
1211 SELECT CASE (gpu_mode)
1213#if defined(GAUXC_HAS_DEVICE) && defined(__LIBTORCH_CUDA)
1223 CALL cp_abort(__location__,
"Unknown GAUXC%USE_GPU value.")
1226 gauxc_functional_section, &
1227 "LB_EXECUTION_SPACE", &
1228 c_val=params%lb_exec_space, &
1229 explicit=lb_space_explicit)
1231 gauxc_functional_section, &
1232 "INT_EXECUTION_SPACE", &
1233 c_val=params%int_exec_space, &
1234 explicit=int_space_explicit)
1235 lb_exec_space_key = adjustl(params%lb_exec_space)
1236 int_exec_space_key = adjustl(params%int_exec_space)
1239 IF (.NOT. use_cuda)
THEN
1240 IF ((lb_space_explicit .AND. trim(lb_exec_space_key) ==
"DEVICE") .OR. &
1241 (int_space_explicit .AND. trim(int_exec_space_key) ==
"DEVICE"))
THEN
1242 CALL cp_abort(__location__, &
1243 "GAUXC%USE_GPU disables GPU execution, but an explicit "// &
1244 "DEVICE execution space was requested. Use USE_GPU GPU "// &
1245 "or remove the explicit DEVICE setting.")
1247 params%lb_exec_space =
"HOST"
1248 params%int_exec_space =
"HOST"
1250 IF (.NOT. lb_space_explicit) params%lb_exec_space =
"DEVICE"
1251 IF (.NOT. int_space_explicit) params%int_exec_space =
"DEVICE"
1254 gauxc_functional_section, &
1256 c_val=params%lwd_kernel)
1258 gauxc_functional_section, &
1260 c_val=skala_runtime)
1262 gauxc_functional_section, &
1263 "MODEL_GRADIENT_RUNTIME", &
1264 c_val=gradient_runtime)
1266 gauxc_functional_section, &
1267 "FORCE_NUMERICAL_GRADIENT", &
1268 l_val=params%force_fd_gradient)
1270 gauxc_functional_section, &
1274 model_key = adjustl(model_name)
1276 xc_fun_key = adjustl(params%xc_fun_name)
1278 skala_runtime_key = adjustl(skala_runtime)
1280 gradient_runtime_key = adjustl(gradient_runtime)
1282 int_exec_space_key = adjustl(params%int_exec_space)
1284 params%use_gauxc_model = (trim(model_key) /=
"" .AND. trim(model_key) /=
"NONE" .AND. &
1285 trim(model_key) /= trim(xc_fun_key))
1286 use_skala_model = (index(trim(model_key),
"SKALA") > 0)
1287 lwd_kernel_key = adjustl(params%lwd_kernel)
1289 IF (trim(lwd_kernel_key) ==
"AUTO")
THEN
1290 params%lwd_kernel =
"DEFAULT"
1291#if defined(GAUXC_HAS_CUTLASS)
1292 IF (use_skala_model .AND. trim(params%int_exec_space) ==
"DEVICE")
THEN
1293 params%lwd_kernel =
"SCHEME1-CUTLASS"
1297 params%model_eval_name = model_name
1298 IF (.NOT. params%use_gauxc_model)
THEN
1300 params%model_eval_name =
"NONE"
1302 IF (gapw_pseudopotentials .AND. params%use_gauxc_model .AND. .NOT. dft_control%qs_control%gapw_xc .AND. &
1303 .NOT. gapw_paw_pseudopotentials .AND. para_env%mepos == 0 .AND.
ASSOCIATED(scf_env))
THEN
1304 IF (scf_env%iter_count == 1)
THEN
1307 "GauXC Skala with METHOD GAPW and GPW_TYPE pseudopotentials evaluates "// &
1308 "the XC term directly on the molecular AO/valence density; no GAPW one-center "// &
1309 "XC correction is used for those regular-grid kinds.")
1312 IF (params%device_runtime_fill_fraction <= 0.0_dp .OR. params%device_runtime_fill_fraction > 1.0_dp)
THEN
1313 CALL cp_abort(__location__, &
1314 "GAUXC%DEVICE_RUNTIME_FILL_FRACTION must be > 0 and <= 1.")
1316 IF (atom_chunk_size < -1)
THEN
1317 CALL cp_abort(__location__, &
1318 "GAUXC%MODEL_ATOM_CHUNK_SIZE must be -1, zero, or positive.")
1320 IF (molecular_virial_debug)
THEN
1321 IF (molecular_virial_debug_dx <= 0.0_dp)
THEN
1322 CALL cp_abort(__location__, &
1323 "GauXC MOLECULAR_VIRIAL_DEBUG_DX must be positive.")
1325 molecular_virial = .true.
1327 need_xc_gradient = calculate_forces .OR. molecular_virial
1328 IF (low_spin_scope)
THEN
1329 IF (.NOT. dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1330 cpabort(
"GauXC low spin ROKS requires METHOD GAPW.")
1333 cpabort(
"GAPW low spin ROKS GauXC requires all-electron kinds.")
1335 IF (is_periodic .OR. do_kpoints .OR. nimages /= 1)
THEN
1336 cpabort(
"GAPW low spin ROKS GauXC requires an isolated Gamma-point calculation.")
1338 IF (need_xc_gradient)
THEN
1339 CALL cp_abort(__location__, &
1340 "GAPW low spin ROKS GauXC nuclear gradients and molecular virial are not implemented.")
1342 IF (trim(int_exec_space_key) /=
"HOST" .OR. trim(params%lb_exec_space) /=
"HOST")
THEN
1343 cpabort(
"GAPW low spin ROKS GauXC currently requires HOST execution.")
1345 IF (params%use_gauxc_model .AND. .NOT. use_skala_model)
THEN
1346 cpabort(
"GAPW low spin ROKS GauXC supports only the SKALA model or conventional XC.")
1348 IF (use_skala_model .AND. trim(skala_runtime_key) ==
"MPI")
THEN
1349 cpabort(
"GAPW low spin ROKS Skala requires SKALA_RUNTIME AUTO or SELF.")
1352 CALL ensure_gauxc_periodic_reference_scope( &
1353 dft_control, cell, qs_kind_set, do_kpoints, periodic_reference)
1354 IF (is_periodic .AND. periodic_reference .AND. para_env%mepos == 0)
THEN
1355 IF (
ASSOCIATED(scf_env))
THEN
1356 IF (scf_env%iter_count == 1)
THEN
1359 "GAUXC%PERIODIC_REFERENCE uses GauXC molecular quadrature for isolated validation "// &
1360 "cells. Compact periodic materials require a dedicated periodic GauXC interface.")
1364 IF (params%use_gauxc_model)
THEN
1366 CALL cp_abort(__location__, &
1367 "GauXC Skala with NLCC pseudopotentials is not implemented. "// &
1368 "The frozen core density would need a SKALA-consistent feature definition.")
1371 IF (params%use_gauxc_model)
THEN
1372 CALL set_gauxc_model_atom_chunk_env( &
1373 atom_chunk_size, atom_chunk_size_explicit)
1374 IF (.NOT. grid_explicit) params%grid_type =
"SUPERFINE"
1375 IF (.NOT. pruning_explicit) params%pruning_scheme =
"UNPRUNED"
1377 grid_key = adjustl(params%grid_type)
1378 pruning_key = adjustl(params%pruning_scheme)
1381 IF (use_skala_model .AND. need_xc_gradient .AND. &
1382 (trim(grid_key) /=
"SUPERFINE" .OR. trim(pruning_key) /=
"UNPRUNED"))
THEN
1385 "GauXC Skala nuclear gradients are sensitive to the GauXC molecular grid. "// &
1386 "Use GRID SUPERFINE and PRUNING_SCHEME UNPRUNED for quantitative force checks.")
1388 IF (trim(model_key) ==
"SKALA")
THEN
1391 IF (trim(int_exec_space_key) ==
"DEVICE")
THEN
1392 CALL get_environment_variable(
"SKALA_CUDA_MODEL", model_name, status=env_status)
1394 IF (env_status /= 0 .OR. len_trim(model_name) == 0)
THEN
1395 CALL get_environment_variable(
"SKALA_MODEL", model_name, status=env_status)
1397 IF (env_status /= 0 .OR. len_trim(model_name) == 0)
THEN
1398 IF (trim(int_exec_space_key) ==
"DEVICE")
THEN
1401 "MODEL SKALA with DEVICE execution requires SKALA_CUDA_MODEL or "// &
1402 "GAUXC_SKALA_MODEL")
1404 cpabort(
"MODEL SKALA requires the GAUXC_SKALA_MODEL environment variable")
1407 params%model_eval_name = model_name
1410 SELECT CASE (trim(skala_runtime_key))
1412 params%use_self_runtime = use_skala_model .AND. para_env%num_pe > 1 .AND. params%nspins > 1
1414 params%use_self_runtime = .false.
1416 params%use_self_runtime = use_skala_model .AND. para_env%num_pe > 1
1418 CALL cp_abort(__location__,
"Unknown GAUXC%SKALA_RUNTIME value.")
1420 IF (.NOT. use_skala_model) params%use_self_runtime = .false.
1421 params%gradient_runtime = gradient_runtime_key
1422 IF (use_skala_model .AND. para_env%num_pe > 1 .AND. .NOT. params%use_self_runtime .AND. &
1423 para_env%mepos == 0 .AND.
ASSOCIATED(scf_env))
THEN
1424 IF (scf_env%iter_count == 1)
THEN
1427 "GAUXC%SKALA_RUNTIME uses the MPI communicator for energy/VXC. "// &
1428 "SKALA Torch atom chunks can be distributed across MPI ranks; "// &
1429 "set GAUXC_ONEDFT_DISTRIBUTED_TORCH=0 to force rank-0 Torch inference.")
1433 params%gapw_method = gapw_method
1434 params%need_xc_gradient = need_xc_gradient
1436 IF (.NOT.
ASSOCIATED(qs_env%gauxc_cache))
ALLOCATE (qs_env%gauxc_cache)
1437 cache => qs_env%gauxc_cache
1447 CALL gauxc_check_status(gauxc_status)
1449 hdf5_output = (trim(output_path) /=
"")
1450 write_hdf5_output = hdf5_output .AND. para_env%mepos == 0 .AND. .NOT. external_density
1451 IF (write_hdf5_output .AND.
ASSOCIATED(scf_env))
THEN
1452 write_hdf5_output = scf_env%iter_count == 1
1454 IF (write_hdf5_output)
THEN
1455 CALL gauxc_write_molecule_hdf5( &
1461 CALL gauxc_check_status(gauxc_status)
1462 CALL gauxc_write_basisset_hdf5( &
1468 CALL gauxc_check_status(gauxc_status)
1471 IF (qs_env%run_rtp)
THEN
1472 cpabort(
"GAUXC XC energy currently does not support real-time propagation")
1482 cpabort(
"UNIMPLEMENTED: Handling nimg>1 in k-point integration")
1484 CALL dbcsr_to_dense(rho_ao(1, img), density_scalar, para_env)
1485 CALL para_env%sum(density_scalar)
1486 IF (params%nspins == 1)
THEN
1487 gauxc_xc_result = gauxc_compute_xc( &
1490 nspins=params%nspins, &
1491 status=gauxc_status, &
1492 model=trim(params%model_eval_name))
1493 CALL gauxc_check_status(gauxc_status)
1494 IF (need_xc_gradient)
THEN
1495 IF (params%use_fd_gradient)
THEN
1496 CALL gauxc_xc_gradient_fd( &
1497 particle_set, qs_kind_set, density_scalar, params%nspins, params%model_eval_name, &
1498 params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1499 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1500 params%device_runtime_fill_fraction, gapw_fd_gradient_dx, para_env, &
1502 ELSE IF (params%use_gradient_self_runtime)
THEN
1503 exc_grad = gauxc_compute_xc_gradient( &
1504 cache%gradient_integrator, &
1506 nspins=params%nspins, &
1507 natom=params%natom, &
1508 status=gauxc_status, &
1509 model=trim(params%model_eval_name))
1511 exc_grad = gauxc_compute_xc_gradient( &
1514 nspins=params%nspins, &
1515 natom=params%natom, &
1516 status=gauxc_status, &
1517 model=trim(params%model_eval_name))
1519 CALL gauxc_check_status(gauxc_status)
1520 IF (calculate_forces)
THEN
1521 CALL add_gauxc_gradient_to_force( &
1522 exc_grad%exc_grad, &
1527 IF (molecular_virial)
THEN
1528 CALL print_gauxc_molecular_virial(exc_grad%exc_grad, particle_set, para_env)
1530 IF (molecular_virial_debug)
THEN
1531 CALL debug_gauxc_molecular_virial( &
1532 exc_grad%exc_grad, particle_set, qs_kind_set, density_scalar, params%nspins, &
1533 params%model_eval_name, params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1534 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1535 params%device_runtime_fill_fraction, molecular_virial_debug_dx, para_env)
1537 DEALLOCATE (exc_grad%exc_grad)
1540 cpassert(params%nspins == 2)
1544 CALL dbcsr_to_dense(rho_ao(2, img), density_zeta, para_env)
1545 CALL para_env%sum(density_zeta)
1547 density_scalar(:, :) = density_scalar(:, :) + density_zeta(:, :)
1552 density_zeta(:, :) = density_scalar(:, :) - 2.0_dp*density_zeta(:, :)
1553 gauxc_xc_result = gauxc_compute_xc( &
1559 model=trim(params%model_eval_name))
1560 CALL gauxc_check_status(gauxc_status)
1561 IF (need_xc_gradient)
THEN
1562 IF (params%use_fd_gradient)
THEN
1563 CALL gauxc_xc_gradient_fd( &
1564 particle_set, qs_kind_set, density_scalar, params%nspins, params%model_eval_name, &
1565 params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1566 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1567 params%device_runtime_fill_fraction, gapw_fd_gradient_dx, para_env, &
1568 exc_grad%exc_grad, density_zeta=density_zeta)
1569 ELSE IF (params%use_gradient_self_runtime)
THEN
1570 exc_grad = gauxc_compute_xc_gradient( &
1571 cache%gradient_integrator, &
1577 model=trim(params%model_eval_name))
1579 exc_grad = gauxc_compute_xc_gradient( &
1586 model=trim(params%model_eval_name))
1588 CALL gauxc_check_status(gauxc_status)
1589 IF (calculate_forces)
THEN
1590 CALL add_gauxc_gradient_to_force( &
1591 exc_grad%exc_grad, &
1596 IF (molecular_virial)
THEN
1597 CALL print_gauxc_molecular_virial(exc_grad%exc_grad, particle_set, para_env)
1599 IF (molecular_virial_debug)
THEN
1600 CALL debug_gauxc_molecular_virial( &
1601 exc_grad%exc_grad, particle_set, qs_kind_set, density_scalar, params%nspins, &
1602 params%model_eval_name, params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1603 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1604 params%device_runtime_fill_fraction, molecular_virial_debug_dx, para_env, &
1605 density_zeta=density_zeta)
1607 DEALLOCATE (exc_grad%exc_grad)
1611 exc_value = exc_value + gauxc_xc_result%exc
1613 IF (params%nspins == 1)
THEN
1615 matrix_vxc(1) = dense_to_dbcsr(gauxc_xc_result%vxc_scalar, rho_ao(1, img))
1617 cpabort(
"UNIMPLEMENTED: Handling multiple result matrices in k-point integration")
1620 cpassert(params%nspins == 2)
1622 vxc_zeta_tmp = dense_to_dbcsr(gauxc_xc_result%vxc_zeta, rho_ao(1, img))
1625 matrix_vxc(ispin) = dense_to_dbcsr(gauxc_xc_result%vxc_scalar, rho_ao(ispin, 1))
1627 matrix_vxc(ispin)%matrix, &
1628 vxc_zeta_tmp%matrix, &
1631 1.0_dp - real(ispin - 1,
dp)*2.0_dp)
1634 cpabort(
"UNIMPLEMENTED: Handling multiple result matrices in k-point integration")
1636 CALL dbcsr_release(vxc_zeta_tmp%matrix)
1637 DEALLOCATE (vxc_zeta_tmp%matrix)
1641 DEALLOCATE (density_scalar)
1642 IF (
ALLOCATED(density_zeta))
DEALLOCATE (density_zeta)
1643 DEALLOCATE (gauxc_xc_result%vxc_scalar)
1644 IF (
ALLOCATED(gauxc_xc_result%vxc_zeta))
DEALLOCATE (gauxc_xc_result%vxc_zeta)
1646 IF (external_density)
THEN
1647 exc_external = exc_value
1648 matrix_vxc_external => matrix_vxc
1650 energy%exc = exc_value
1651 CALL set_ks_env(ks_env, matrix_vxc=matrix_vxc)
1653 DO ispin = 1, params%nspins
1654 CALL dbcsr_finalize(matrix_vxc(ispin)%matrix)
Define the atomic kind types and their sub types.
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.
Handles all functions related to the CELL.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
character function, public dbcsr_get_matrix_type(matrix)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_get_stored_coordinates(matrix, row, column, processor)
...
subroutine, public dbcsr_init_p(matrix)
...
subroutine, public dbcsr_work_create(matrix, nblks_guess, sizedata_guess, n, work_mutable)
...
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_release(matrix)
...
subroutine, public dbcsr_iterator_readonly_start(iterator, matrix, shared, dynamic, dynamic_byrows)
Like dbcsr_iterator_start() but with matrix being INTENT(IN). When invoking this routine,...
subroutine, public dbcsr_put_block(matrix, row, col, block, summation)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_distribution_get(dist, row_dist, col_dist, nrows, ncols, has_threads, group, mynode, numnodes, nprows, npcols, myprow, mypcol, pgrid, subgroups_defined, prow_group, pcol_group)
...
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...
Definition of the atomic potential types.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Interface to the message passing library MPI.
type(mp_comm_type), parameter, public mp_comm_self
Define the data structure for the particle information.
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, matrix_metric, matrix_metric_kp)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
logical function, public has_nlcc(qs_kind_set)
finds if a given qs run needs to use nlcc
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 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, uspp, upf_inverse)
...
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
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
subroutine, public gauxc_cache_init(cache, params, para_env, particle_set, qs_kind_set, status)
...
subroutine, public gauxc_cache_ensure_gradient(cache, params, status)
Build the separate gradient grid/integrator on first use and keep it cached.
logical function, public gauxc_gapw_has_paw_pseudopotentials(qs_kind_set)
Return whether GauXC GAPW mode sees pseudopotential one-center GAPW kinds.
logical function, public xc_section_uses_gauxc(xc_section)
...
logical function, public gauxc_gapw_has_pseudopotentials(qs_kind_set)
Return whether GauXC GAPW mode sees pseudopotential kinds.
subroutine, public skala_info(functional, lsd, reference, shortform, needs, max_deriv)
Return information about the Skala functional.
logical function, public gauxc_gapw_all_all_electron(qs_kind_set)
Return whether every GAPW kind uses an all-electron potential.
logical function, public gauxc_gapw_all_pseudopotentials(qs_kind_set)
Return whether every GAPW kind uses a pseudopotential.
subroutine, public apply_gauxc(qs_env, xc_section, calculate_forces, rho_ao_external, exc_external, matrix_vxc_external)
Evaluate molecular GauXC, optionally for an explicit configuration density.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
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.
contains a flag for each component of xc_rho_set, so that you can use it to tell which components you...