9#include "gauxc/gauxc_config.f"
34 USE iso_c_binding,
ONLY: c_char,&
60 USE xc_gauxc_interface,
ONLY: &
61 cp_gauxc_basisset_type, cp_gauxc_grid_type, cp_gauxc_integrator_type, &
62 cp_gauxc_molecule_type, cp_gauxc_status_type, cp_gauxc_xc_gradient_type, cp_gauxc_xc_type, &
63 gauxc_check_status, gauxc_compute_xc, gauxc_compute_xc_gradient, gauxc_create_basisset, &
64 gauxc_create_grid, gauxc_create_integrator, gauxc_create_molecule, gauxc_destroy_basisset, &
65 gauxc_destroy_grid, gauxc_destroy_integrator, gauxc_destroy_molecule, &
66 gauxc_write_basisset_hdf5, gauxc_write_molecule_hdf5
69#include "../base/base_uses.f90"
75 LOGICAL,
PARAMETER :: debug_this_module = .true.
76 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'xc_gauxc_functional'
83 INTEGER(c_int) FUNCTION c_setenv(name, value, overwrite)
BIND(C, name="setenv")
84 IMPORT :: c_char, c_int
85 CHARACTER(KIND=c_char),
DIMENSION(*),
INTENT(IN) :: name, value
86 INTEGER(c_int),
VALUE :: overwrite
89 INTEGER(c_int) FUNCTION c_unsetenv(name)
BIND(C, name="unsetenv")
90 IMPORT :: c_char, c_int
91 CHARACTER(KIND=c_char),
DIMENSION(*),
INTENT(IN) :: name
92 END FUNCTION c_unsetenv
103 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
104 LOGICAL :: all_all_electron
109 cpassert(
ASSOCIATED(qs_kind_set))
111 all_all_electron = .true.
112 DO ikind = 1,
SIZE(qs_kind_set)
113 NULLIFY (all_potential)
114 CALL get_qs_kind(qs_kind_set(ikind), all_potential=all_potential)
115 IF (.NOT.
ASSOCIATED(all_potential))
THEN
116 all_all_electron = .false.
128 SUBROUTINE set_gauxc_model_atom_chunk_env(atom_chunk_size, is_explicit)
129 INTEGER,
INTENT(IN) :: atom_chunk_size
130 LOGICAL,
INTENT(IN) :: is_explicit
132 CHARACTER(LEN=32) :: chunk_value
133 INTEGER(c_int) :: ierr
135 IF (.NOT. is_explicit)
RETURN
137 IF (atom_chunk_size < 0)
THEN
138 ierr = c_unsetenv(
"GAUXC_ONEDFT_ATOM_CHUNK_SIZE"//c_null_char)
140 WRITE (chunk_value,
'(I0)') atom_chunk_size
142 "GAUXC_ONEDFT_ATOM_CHUNK_SIZE"//c_null_char, &
143 trim(chunk_value)//c_null_char, &
146 IF (ierr /= 0_c_int)
THEN
147 CALL cp_abort(__location__, &
148 "Could not set GAUXC_ONEDFT_ATOM_CHUNK_SIZE for GauXC Skala.")
150 END SUBROUTINE set_gauxc_model_atom_chunk_env
158 SUBROUTINE dbcsr_to_dense(dbcsr_mat, dense_mat, para_env)
164 REAL(c_double),
ALLOCATABLE,
DIMENSION(:, :), &
165 INTENT(INOUT) :: dense_mat
168 CHARACTER :: matrix_type
169 INTEGER :: col, col_end, col_start, icol, irow, mynode, nblkcols_total, nblkrows_total, &
170 ncols, nrows, numnodes, owner, row, row_end, row_start
171 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: c_offset, r_offset
172 INTEGER,
DIMENSION(:),
POINTER :: col_blk_size, row_blk_size
174 REAL(c_double),
POINTER :: block(:, :)
178 row_blk_size=row_blk_size, &
179 col_blk_size=col_blk_size, &
180 nblkrows_total=nblkrows_total, &
181 nblkcols_total=nblkcols_total, &
182 nfullrows_total=nrows, &
183 nfullcols_total=ncols, &
188 IF (.NOT.
ALLOCATED(dense_mat))
THEN
189 ALLOCATE (dense_mat(nrows, ncols))
190 ELSE IF (.NOT. all(shape(dense_mat) == [nrows, ncols]))
THEN
191 DEALLOCATE (dense_mat)
192 ALLOCATE (dense_mat(nrows, ncols))
194 cpassert(all(shape(dense_mat) == [nrows, ncols]))
198 ALLOCATE (r_offset(nblkrows_total), c_offset(nblkcols_total))
201 DO row = 2, nblkrows_total
202 r_offset(row) = r_offset(row - 1) + row_blk_size(row - 1)
205 DO col = 2, nblkcols_total
206 c_offset(col) = c_offset(col - 1) + col_blk_size(col - 1)
210 DO irow = 1, nblkrows_total
211 DO icol = 1, nblkcols_total
212 IF (numnodes == 1 .AND. para_env%num_pe > 1 .AND. para_env%mepos /= 0) cycle
214 IF (owner /= mynode) cycle
216 block=block, found=found)
217 IF (.NOT. found) cycle
218 row_start = r_offset(irow)
219 row_end = row_start + row_blk_size(irow) - 1
220 col_start = c_offset(icol)
221 col_end = col_start + col_blk_size(icol) - 1
222 dense_mat(row_start:row_end, col_start:col_end) = block
223 IF (irow /= icol)
THEN
224 IF (matrix_type == dbcsr_type_symmetric)
THEN
225 dense_mat(col_start:col_end, row_start:row_end) = transpose(block)
226 ELSE IF (matrix_type == dbcsr_type_antisymmetric)
THEN
227 dense_mat(col_start:col_end, row_start:row_end) = -transpose(block)
233 DEALLOCATE (r_offset, c_offset)
235 END SUBROUTINE dbcsr_to_dense
245 FUNCTION dense_to_dbcsr(dense_mat, template_dbcsr)
RESULT(dbcsr_mat)
256 dbcsr_type_symmetric, &
258 REAL(c_double),
DIMENSION(:, :),
INTENT(IN) :: dense_mat
262 INTEGER :: col, icol, irow, mynode, nblkcols_total, &
263 nblkrows_total, ncols, nrows, owner, &
265 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: c_offset, r_offset
266 INTEGER,
DIMENSION(:),
POINTER :: col_blk_size, row_blk_size
270 row_blk_size=row_blk_size, &
271 col_blk_size=col_blk_size, &
272 nblkrows_total=nblkrows_total, &
273 nblkcols_total=nblkcols_total, &
274 nfullrows_total=nrows, &
275 nfullcols_total=ncols, &
279 cpassert(nrows ==
SIZE(dense_mat, 1))
280 cpassert(ncols ==
SIZE(dense_mat, 2))
284 template=template_dbcsr%matrix, &
285 name=
"VXC from GauXC (dense)", &
286 matrix_type=dbcsr_type_symmetric)
289 ALLOCATE (r_offset(nblkrows_total), c_offset(nblkcols_total))
292 DO row = 2, nblkrows_total
293 r_offset(row) = r_offset(row - 1) + row_blk_size(row - 1)
296 DO col = 2, nblkcols_total
297 c_offset(col) = c_offset(col - 1) + col_blk_size(col - 1)
300 DO irow = 1, nblkrows_total
301 DO icol = 1, nblkcols_total
302 IF (irow > icol) cycle
304 IF (owner /= mynode) cycle
307 dense_mat(r_offset(irow):r_offset(irow) + row_blk_size(irow) - 1, &
308 c_offset(icol):c_offset(icol) + col_blk_size(icol) - 1) + &
309 transpose(dense_mat(r_offset(icol):r_offset(icol) + row_blk_size(icol) - 1, &
310 c_offset(irow):c_offset(irow) + col_blk_size(irow) - 1))))
316 DEALLOCATE (r_offset, c_offset)
318 END FUNCTION dense_to_dbcsr
325 FUNCTION get_gauxc_functional(xc_section)
RESULT(gauxc_functional_section)
332 NULLIFY (gauxc_functional_section)
335 IF (.NOT.
ASSOCIATED(functionals))
THEN
336 cpabort(
"XC_FUNCTIONAL section not found")
343 IF (.NOT.
ASSOCIATED(xc_fun))
EXIT
344 IF (xc_fun%section%name /=
"GAUXC" .OR. ifun > 1)
THEN
345 cpabort(
"GauXC functionals are mutually exclusive with any other functional.")
347 gauxc_functional_section => xc_fun
350 IF (.NOT.
ASSOCIATED(gauxc_functional_section))
THEN
351 cpabort(
"No XC functional found in XC_FUNCTIONAL section")
353 END FUNCTION get_gauxc_functional
362 LOGICAL :: uses_gauxc
368 IF (.NOT.
ASSOCIATED(xc_section))
RETURN
371 IF (.NOT.
ASSOCIATED(functionals))
RETURN
377 IF (.NOT.
ASSOCIATED(xc_fun))
EXIT
378 IF (xc_fun%section%name ==
"GAUXC")
THEN
392 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
393 LOGICAL :: has_pseudopotentials
399 cpassert(
ASSOCIATED(qs_kind_set))
401 has_pseudopotentials = .false.
402 DO ikind = 1,
SIZE(qs_kind_set)
403 NULLIFY (gth_potential, sgp_potential)
405 gth_potential=gth_potential, &
406 sgp_potential=sgp_potential)
407 IF (
ASSOCIATED(gth_potential) .OR.
ASSOCIATED(sgp_potential))
THEN
408 has_pseudopotentials = .true.
421 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
422 LOGICAL :: all_pseudopotentials
428 cpassert(
ASSOCIATED(qs_kind_set))
430 all_pseudopotentials = .true.
431 DO ikind = 1,
SIZE(qs_kind_set)
432 NULLIFY (gth_potential, sgp_potential)
434 gth_potential=gth_potential, &
435 sgp_potential=sgp_potential)
436 IF (.NOT. (
ASSOCIATED(gth_potential) .OR.
ASSOCIATED(sgp_potential)))
THEN
437 all_pseudopotentials = .false.
450 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
451 LOGICAL :: has_paw_pseudopotentials
458 cpassert(
ASSOCIATED(qs_kind_set))
460 has_paw_pseudopotentials = .false.
461 DO ikind = 1,
SIZE(qs_kind_set)
462 NULLIFY (gth_potential, sgp_potential)
464 gth_potential=gth_potential, &
466 sgp_potential=sgp_potential)
467 IF ((
ASSOCIATED(gth_potential) .OR.
ASSOCIATED(sgp_potential)) .AND. &
469 has_paw_pseudopotentials = .true.
486 SUBROUTINE ensure_gauxc_periodic_reference_scope( &
487 dft_control, cell, qs_kind_set, do_kpoints, periodic_reference)
490 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
491 LOGICAL,
INTENT(IN) :: do_kpoints, periodic_reference
494 LOGICAL :: is_periodic
498 cpassert(
ASSOCIATED(dft_control))
499 cpassert(
ASSOCIATED(qs_kind_set))
501 is_periodic = .false.
502 IF (
ASSOCIATED(cell)) is_periodic = any(cell%perd /= 0)
505 CALL cp_abort(__location__, &
506 "GauXC currently supports only Gamma-only density matrices in CP2K. "// &
507 "Periodic k-point density matrices require a dedicated GauXC periodic interface.")
509 IF (dft_control%nimages /= 1)
THEN
510 CALL cp_abort(__location__, &
511 "GauXC currently supports only a single AO image in CP2K. "// &
512 "Periodic neighbour-cell AO blocks require a dedicated GauXC periodic interface.")
514 IF (.NOT. is_periodic)
RETURN
516 IF (.NOT. periodic_reference)
THEN
517 CALL cp_abort(__location__, &
518 "Periodic GauXC calculations in CP2K require GAUXC%PERIODIC_REFERENCE T. "// &
519 "This opt-in documents that the current path is only an isolated-cell, "// &
520 "Gamma-only, single-image METHOD GPW reference path using GauXC molecular "// &
521 "quadrature, not a dedicated periodic GauXC interface.")
524 IF (.NOT. all(cell%perd == 1))
THEN
525 CALL cp_abort(__location__, &
526 "The current GauXC isolated-cell reference path supports only PERIODIC XYZ. "// &
527 "Partial periodicity requires a dedicated GauXC periodic interface.")
529 IF (.NOT. dft_control%qs_control%gpw)
THEN
530 CALL cp_abort(__location__, &
531 "The current GauXC isolated-cell reference path is limited to METHOD GPW with GTH "// &
532 "pseudopotentials. GAPW, GAPW_XC, and other QS methods are not supported here.")
535 DO ikind = 1,
SIZE(qs_kind_set)
536 NULLIFY (gth_potential, sgp_potential)
538 gth_potential=gth_potential, &
539 sgp_potential=sgp_potential)
540 IF (.NOT.
ASSOCIATED(gth_potential) .OR.
ASSOCIATED(sgp_potential))
THEN
541 CALL cp_abort(__location__, &
542 "The current GauXC isolated-cell reference path is limited to GTH pseudopotentials. "// &
543 "Use non-periodic all-electron GAPW validation for molecular GAPW cases.")
547 END SUBROUTINE ensure_gauxc_periodic_reference_scope
556 SUBROUTINE add_gauxc_gradient_to_force(exc_grad, force, atomic_kind_set, para_env)
557 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: exc_grad
562 INTEGER :: ia, iatom, ikind, natom_kind
565 cpassert(
ASSOCIATED(force))
566 cpassert(
ASSOCIATED(atomic_kind_set))
568 IF (para_env%mepos /= 0)
RETURN
570 DO ikind = 1,
SIZE(atomic_kind_set, 1)
571 atomic_kind => atomic_kind_set(ikind)
573 DO ia = 1, natom_kind
574 iatom = atomic_kind%atom_list(ia)
575 force(ikind)%rho_elec(:, ia) = force(ikind)%rho_elec(:, ia) + &
576 exc_grad(3*iatom - 2:3*iatom)
580 END SUBROUTINE add_gauxc_gradient_to_force
601 SUBROUTINE gauxc_xc_energy_for_particles( &
602 particle_set_eval, qs_kind_set, density_scalar, nspins, model_name, &
603 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
604 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, exc, density_zeta)
605 TYPE(
particle_type),
DIMENSION(:),
INTENT(IN) :: particle_set_eval
606 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
607 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: density_scalar
608 INTEGER,
INTENT(IN) :: nspins
609 CHARACTER(len=*),
INTENT(IN) :: model_name, xc_fun_name, grid_type, radial_quadrature, &
610 pruning_scheme, lb_exec_space, int_exec_space, lwd_kernel
611 INTEGER,
INTENT(IN) :: batch_size
612 REAL(kind=
dp),
INTENT(IN) :: device_runtime_fill_fraction
613 REAL(kind=
dp),
INTENT(OUT) :: exc
614 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN), &
615 OPTIONAL :: density_zeta
617 TYPE(cp_gauxc_basisset_type) :: gauxc_basis_fd
618 TYPE(cp_gauxc_grid_type) :: gauxc_grid_fd
619 TYPE(cp_gauxc_integrator_type) :: gauxc_integrator_fd
620 TYPE(cp_gauxc_molecule_type) :: gauxc_mol_fd
621 TYPE(cp_gauxc_status_type) :: gauxc_status
622 TYPE(cp_gauxc_xc_type) :: gauxc_xc_result
624 gauxc_mol_fd = gauxc_create_molecule(particle_set_eval, gauxc_status)
625 CALL gauxc_check_status(gauxc_status)
626 gauxc_basis_fd = gauxc_create_basisset(qs_kind_set, particle_set_eval, gauxc_status)
627 CALL gauxc_check_status(gauxc_status)
628 gauxc_grid_fd = gauxc_create_grid( &
636 device_runtime_fill_fraction, &
639 force_new_runtime=.true.)
640 CALL gauxc_check_status(gauxc_status)
641 gauxc_integrator_fd = gauxc_create_integrator( &
648 CALL gauxc_check_status(gauxc_status)
650 IF (nspins == 1)
THEN
651 gauxc_xc_result = gauxc_compute_xc( &
652 gauxc_integrator_fd, &
655 status=gauxc_status, &
656 model=trim(model_name))
658 cpassert(nspins == 2)
659 cpassert(
PRESENT(density_zeta))
660 gauxc_xc_result = gauxc_compute_xc( &
661 gauxc_integrator_fd, &
666 model=trim(model_name))
668 CALL gauxc_check_status(gauxc_status)
669 exc = gauxc_xc_result%exc
671 IF (
ALLOCATED(gauxc_xc_result%vxc_scalar))
DEALLOCATE (gauxc_xc_result%vxc_scalar)
672 IF (
ALLOCATED(gauxc_xc_result%vxc_zeta))
DEALLOCATE (gauxc_xc_result%vxc_zeta)
674 CALL gauxc_destroy_integrator(gauxc_integrator_fd, gauxc_status)
675 CALL gauxc_check_status(gauxc_status)
676 CALL gauxc_destroy_grid(gauxc_grid_fd, gauxc_status)
677 CALL gauxc_check_status(gauxc_status)
678 CALL gauxc_destroy_basisset(gauxc_basis_fd, gauxc_status)
679 CALL gauxc_check_status(gauxc_status)
680 CALL gauxc_destroy_molecule(gauxc_mol_fd, gauxc_status)
681 CALL gauxc_check_status(gauxc_status)
683 END SUBROUTINE gauxc_xc_energy_for_particles
706 SUBROUTINE gauxc_xc_gradient_fd( &
707 particle_set, qs_kind_set, density_scalar, nspins, model_name, &
708 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
709 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, dx, para_env, exc_grad, &
712 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
713 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: density_scalar
714 INTEGER,
INTENT(IN) :: nspins
715 CHARACTER(len=*),
INTENT(IN) :: model_name, xc_fun_name, grid_type, radial_quadrature, &
716 pruning_scheme, lb_exec_space, int_exec_space, lwd_kernel
717 INTEGER,
INTENT(IN) :: batch_size
718 REAL(kind=
dp),
INTENT(IN) :: device_runtime_fill_fraction, dx
720 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
721 INTENT(OUT) :: exc_grad
722 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN), &
723 OPTIONAL :: density_zeta
725 INTEGER :: iatom, idir
726 REAL(kind=
dp) :: xc_minus, xc_plus
727 TYPE(
particle_type),
ALLOCATABLE,
DIMENSION(:) :: particle_set_minus, particle_set_plus
729 cpassert(
ASSOCIATED(particle_set))
730 cpassert(dx > 0.0_dp)
732 ALLOCATE (exc_grad(3*
SIZE(particle_set)))
735 IF (para_env%mepos == 0)
THEN
736 ALLOCATE (particle_set_minus(
SIZE(particle_set)), particle_set_plus(
SIZE(particle_set)))
738 DO iatom = 1,
SIZE(particle_set)
740 particle_set_minus = particle_set
741 particle_set_plus = particle_set
742 particle_set_minus(iatom)%r(idir) = particle_set_minus(iatom)%r(idir) - dx
743 particle_set_plus(iatom)%r(idir) = particle_set_plus(iatom)%r(idir) + dx
744 IF (
PRESENT(density_zeta))
THEN
745 CALL gauxc_xc_energy_for_particles( &
746 particle_set_plus, qs_kind_set, density_scalar, nspins, model_name, &
747 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
748 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_plus, &
749 density_zeta=density_zeta)
750 CALL gauxc_xc_energy_for_particles( &
751 particle_set_minus, qs_kind_set, density_scalar, nspins, model_name, &
752 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
753 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_minus, &
754 density_zeta=density_zeta)
756 CALL gauxc_xc_energy_for_particles( &
757 particle_set_plus, qs_kind_set, density_scalar, nspins, model_name, &
758 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
759 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_plus)
760 CALL gauxc_xc_energy_for_particles( &
761 particle_set_minus, qs_kind_set, density_scalar, nspins, model_name, &
762 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
763 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_minus)
765 exc_grad(3*iatom - 3 + idir) = (xc_plus - xc_minus)/(2.0_dp*dx)
769 DEALLOCATE (particle_set_minus, particle_set_plus)
772 CALL para_env%bcast(exc_grad, 0)
774 END SUBROUTINE gauxc_xc_gradient_fd
797 SUBROUTINE debug_gauxc_molecular_virial( &
798 exc_grad, particle_set, qs_kind_set, density_scalar, nspins, model_name, &
799 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
800 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, dx, para_env, density_zeta)
801 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: exc_grad
803 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
804 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: density_scalar
805 INTEGER,
INTENT(IN) :: nspins
806 CHARACTER(len=*),
INTENT(IN) :: model_name, xc_fun_name, grid_type, radial_quadrature, &
807 pruning_scheme, lb_exec_space, int_exec_space, lwd_kernel
808 INTEGER,
INTENT(IN) :: batch_size
809 REAL(kind=
dp),
INTENT(IN) :: device_runtime_fill_fraction, dx
811 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN), &
812 OPTIONAL :: density_zeta
815 REAL(kind=
dp) :: analytic_trace, diff_trace, &
816 numerical_trace, xc_minus, xc_plus
817 REAL(kind=
dp),
DIMENSION(3) :: center, displacement, grad
818 TYPE(
particle_type),
ALLOCATABLE,
DIMENSION(:) :: particle_set_minus, particle_set_plus
820 cpassert(
ASSOCIATED(particle_set))
821 cpassert(
SIZE(exc_grad) == 3*
SIZE(particle_set))
823 IF (para_env%mepos /= 0)
RETURN
826 DO iatom = 1,
SIZE(particle_set)
827 center = center + particle_set(iatom)%r
829 center = center/real(
SIZE(particle_set),
dp)
831 ALLOCATE (particle_set_minus(
SIZE(particle_set)), particle_set_plus(
SIZE(particle_set)))
832 particle_set_minus = particle_set
833 particle_set_plus = particle_set
835 analytic_trace = 0.0_dp
836 DO iatom = 1,
SIZE(particle_set)
837 grad = exc_grad(3*iatom - 2:3*iatom)
838 displacement = particle_set(iatom)%r - center
839 analytic_trace = analytic_trace + dot_product(grad, displacement)
840 particle_set_minus(iatom)%r = center + (1.0_dp - dx)*displacement
841 particle_set_plus(iatom)%r = center + (1.0_dp + dx)*displacement
843 analytic_trace = analytic_trace/3.0_dp
845 IF (
PRESENT(density_zeta))
THEN
846 CALL gauxc_xc_energy_for_particles( &
847 particle_set_plus, qs_kind_set, density_scalar, nspins, model_name, &
848 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
849 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_plus, &
850 density_zeta=density_zeta)
851 CALL gauxc_xc_energy_for_particles( &
852 particle_set_minus, qs_kind_set, density_scalar, nspins, model_name, &
853 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
854 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_minus, &
855 density_zeta=density_zeta)
857 CALL gauxc_xc_energy_for_particles( &
858 particle_set_plus, qs_kind_set, density_scalar, nspins, model_name, &
859 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
860 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_plus)
861 CALL gauxc_xc_energy_for_particles( &
862 particle_set_minus, qs_kind_set, density_scalar, nspins, model_name, &
863 xc_fun_name, grid_type, radial_quadrature, pruning_scheme, lb_exec_space, &
864 int_exec_space, lwd_kernel, batch_size, device_runtime_fill_fraction, xc_minus)
867 numerical_trace = (xc_plus - xc_minus)/(2.0_dp*dx)/3.0_dp
868 diff_trace = analytic_trace - numerical_trace
872 WRITE (unit=iw, fmt=
"(/,T2,A,1X,ES11.4)") &
873 "GAUXC| Molecular XC virial finite-difference dx", dx
874 WRITE (unit=iw, fmt=
"(T2,A,3(1X,ES19.11))") &
875 "GAUXC| Molecular XC virial FD 1/3 Trace", &
876 analytic_trace, numerical_trace, diff_trace
879 DEALLOCATE (particle_set_minus, particle_set_plus)
881 END SUBROUTINE debug_gauxc_molecular_virial
889 SUBROUTINE print_gauxc_molecular_virial(exc_grad, particle_set, para_env)
890 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: exc_grad
894 CHARACTER(len=1),
DIMENSION(3),
PARAMETER :: label = [
"x",
"y",
"z"]
896 INTEGER :: i, iatom, iw, j
897 REAL(kind=
dp),
DIMENSION(3) :: center, displacement, grad, grad_sum
898 REAL(kind=
dp),
DIMENSION(3, 3) :: molecular_virial
900 cpassert(
ASSOCIATED(particle_set))
901 cpassert(
SIZE(exc_grad) == 3*
SIZE(particle_set))
903 IF (para_env%mepos /= 0)
RETURN
906 DO iatom = 1,
SIZE(particle_set)
907 center = center + particle_set(iatom)%r
909 center = center/real(
SIZE(particle_set),
dp)
912 molecular_virial = 0.0_dp
913 DO iatom = 1,
SIZE(particle_set)
914 grad = exc_grad(3*iatom - 2:3*iatom)
915 displacement = particle_set(iatom)%r - center
916 grad_sum = grad_sum + grad
919 molecular_virial(i, j) = molecular_virial(i, j) + grad(i)*displacement(j)
927 WRITE (unit=iw, fmt=
"(/,T2,A)") &
928 "GAUXC| Molecular XC gradient virial diagnostic [a.u.]"
929 WRITE (unit=iw, fmt=
"(T2,A,T20,A,T40,A,T60,A)")
"GAUXC|",
"x",
"y",
"z"
931 WRITE (unit=iw, fmt=
"(T2,A,1X,A1,3(1X,ES19.11))") &
932 "GAUXC|", label(i), molecular_virial(i, :)
934 WRITE (unit=iw, fmt=
"(T2,A,1X,ES19.11)") &
935 "GAUXC| Molecular XC gradient virial 1/3 Trace", &
936 (molecular_virial(1, 1) + molecular_virial(2, 2) + molecular_virial(3, 3))/3.0_dp
937 WRITE (unit=iw, fmt=
"(T2,A,3(1X,ES19.11))") &
938 "GAUXC| Molecular XC gradient sum", grad_sum
939 WRITE (unit=iw, fmt=
"(T2,A)") &
940 "GAUXC| Diagnostic only; this is not an analytical periodic stress tensor."
942 END SUBROUTINE print_gauxc_molecular_virial
954 SUBROUTINE skala_info(functional, lsd, reference, shortform, needs, max_deriv)
956 LOGICAL,
INTENT(in) :: lsd
957 CHARACTER(LEN=*),
INTENT(OUT),
OPTIONAL :: reference, shortform
959 INTEGER,
INTENT(out),
OPTIONAL :: max_deriv
961 CHARACTER(len=default_path_length) :: model_key, model_name
962 CHARACTER(len=default_string_length) :: xc_fun_key, xc_fun_name
963 INTEGER :: gapw_representation
964 LOGICAL :: native_grid
970 i_val=gapw_representation)
972 model_key = adjustl(model_name)
973 xc_fun_key = adjustl(xc_fun_name)
977 IF (
PRESENT(reference))
THEN
978 IF (trim(model_key) ==
"NONE" .OR. trim(model_key) ==
"" .OR. &
979 trim(model_key) == trim(xc_fun_key))
THEN
980 reference =
"Functional computed by GauXC (underlying: "//trim(xc_fun_name)//
")"
982 reference =
"Functional computed by GauXC Skala model "//trim(model_name)
985 IF (
PRESENT(shortform))
THEN
986 IF (trim(model_key) ==
"NONE" .OR. trim(model_key) ==
"" .OR. &
987 trim(model_key) == trim(xc_fun_key))
THEN
988 shortform =
"GAUXC ("//trim(xc_fun_name)//
")"
990 shortform =
"GAUXC Skala"
993 IF (
PRESENT(needs))
THEN
994 IF (native_grid .AND. trim(model_key) /=
"NONE" .AND. trim(model_key) /=
"" .AND. &
995 trim(model_key) /= trim(xc_fun_key))
THEN
997 needs%rho_spin = .true.
998 needs%drho_spin = .true.
999 needs%tau_spin = .true.
1008 needs%rho_spin = .true.
1012 IF (
PRESENT(max_deriv)) max_deriv = 1
1029 LOGICAL,
INTENT(IN) :: calculate_forces
1031 CHARACTER(len=*),
PARAMETER :: nonlocal_vdw_abort_message = &
1032 "GauXC does not support non-local VDW_POTENTIAL corrections. "// &
1033 "Use an additive PAIR_POTENTIAL dispersion correction or disable GauXC."
1034 REAL(kind=
dp),
PARAMETER :: gapw_fd_gradient_dx = 1.0e-4_dp
1036 CHARACTER(len=default_path_length) :: model_key, model_name, output_path
1037 CHARACTER(len=default_string_length) :: gradient_runtime, gradient_runtime_key, grid_key, &
1038 int_exec_space_key, lwd_kernel_key, pruning_key, skala_runtime, skala_runtime_key, &
1040 INTEGER :: atom_chunk_size, env_status, img, ispin, &
1042 LOGICAL :: atom_chunk_size_explicit, do_kpoints, gapw_method, gapw_paw_pseudopotentials, &
1043 gapw_pseudopotentials, grid_explicit, hdf5_output, is_periodic, molecular_virial, &
1044 molecular_virial_debug, need_xc_gradient, periodic_reference, pruning_explicit, &
1045 use_skala_model, write_hdf5_output
1046 REAL(kind=
dp) :: molecular_virial_debug_dx
1047 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: density_scalar, density_zeta
1052 TYPE(cp_gauxc_status_type) :: gauxc_status
1053 TYPE(cp_gauxc_xc_gradient_type) :: exc_grad
1054 TYPE(cp_gauxc_xc_type) :: gauxc_xc_result
1055 TYPE(dbcsr_p_type) :: vxc_zeta_tmp
1056 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_vxc
1057 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao
1063 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1065 TYPE(
qs_rho_type),
POINTER :: rho, rho_use, rho_xc
1089 dft_control=dft_control, &
1090 do_kpoints=do_kpoints, &
1093 matrix_vxc=matrix_vxc, &
1094 natom=params%natom, &
1095 atomic_kind_set=atomic_kind_set, &
1097 para_env=para_env, &
1098 particle_set=particle_set, &
1099 qs_kind_set=qs_kind_set, &
1104 gapw_method = dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc
1105 gapw_pseudopotentials = gapw_method .AND. &
1107 gapw_paw_pseudopotentials = gapw_method .AND. &
1109 IF (dft_control%qs_control%gapw_xc)
THEN
1110 cpassert(
ASSOCIATED(rho_xc))
1113 cpassert(
ASSOCIATED(rho))
1120 nimages = dft_control%nimages
1121 params%nspins = dft_control%nspins
1122 is_periodic = .false.
1123 IF (
ASSOCIATED(cell)) is_periodic = any(cell%perd /= 0)
1125 IF (
ASSOCIATED(qs_env%dispersion_env))
THEN
1127 cpabort(nonlocal_vdw_abort_message)
1130 NULLIFY (vxc_zeta_tmp%matrix)
1132 gauxc_functional_section => get_gauxc_functional(xc_section)
1134 gauxc_functional_section, &
1136 c_val=params%xc_fun_name)
1138 gauxc_functional_section, &
1142 gauxc_functional_section, &
1144 c_val=params%grid_type, &
1145 explicit=grid_explicit)
1147 gauxc_functional_section, &
1148 "RADIAL_QUADRATURE", &
1149 c_val=params%radial_quadrature)
1151 gauxc_functional_section, &
1153 c_val=params%pruning_scheme, &
1154 explicit=pruning_explicit)
1156 gauxc_functional_section, &
1158 i_val=params%batch_size)
1160 gauxc_functional_section, &
1161 "DEVICE_RUNTIME_FILL_FRACTION", &
1162 r_val=params%device_runtime_fill_fraction)
1164 gauxc_functional_section, &
1165 "MODEL_ATOM_CHUNK_SIZE", &
1166 i_val=atom_chunk_size, &
1167 explicit=atom_chunk_size_explicit)
1169 gauxc_functional_section, &
1170 "PERIODIC_REFERENCE", &
1171 l_val=periodic_reference)
1173 gauxc_functional_section, &
1174 "MOLECULAR_VIRIAL", &
1175 l_val=molecular_virial)
1177 gauxc_functional_section, &
1178 "MOLECULAR_VIRIAL_DEBUG", &
1179 l_val=molecular_virial_debug)
1181 gauxc_functional_section, &
1182 "MOLECULAR_VIRIAL_DEBUG_DX", &
1183 r_val=molecular_virial_debug_dx)
1185 gauxc_functional_section, &
1186 "LB_EXECUTION_SPACE", &
1187 c_val=params%lb_exec_space)
1189 gauxc_functional_section, &
1190 "INT_EXECUTION_SPACE", &
1191 c_val=params%int_exec_space)
1193 gauxc_functional_section, &
1195 c_val=params%lwd_kernel)
1197 gauxc_functional_section, &
1199 c_val=skala_runtime)
1201 gauxc_functional_section, &
1202 "MODEL_GRADIENT_RUNTIME", &
1203 c_val=gradient_runtime)
1205 gauxc_functional_section, &
1209 model_key = adjustl(model_name)
1211 xc_fun_key = adjustl(params%xc_fun_name)
1213 skala_runtime_key = adjustl(skala_runtime)
1215 gradient_runtime_key = adjustl(gradient_runtime)
1217 int_exec_space_key = adjustl(params%int_exec_space)
1219 params%use_gauxc_model = (trim(model_key) /=
"" .AND. trim(model_key) /=
"NONE" .AND. &
1220 trim(model_key) /= trim(xc_fun_key))
1221 use_skala_model = (index(trim(model_key),
"SKALA") > 0)
1222 lwd_kernel_key = adjustl(params%lwd_kernel)
1224 IF (trim(lwd_kernel_key) ==
"AUTO")
THEN
1225 params%lwd_kernel =
"DEFAULT"
1226#if defined(GAUXC_HAS_CUTLASS)
1227 IF (use_skala_model .AND. trim(params%int_exec_space) ==
"DEVICE")
THEN
1228 params%lwd_kernel =
"SCHEME1-CUTLASS"
1232 params%model_eval_name = model_name
1233 IF (.NOT. params%use_gauxc_model)
THEN
1235 params%model_eval_name =
"NONE"
1237 IF (gapw_pseudopotentials .AND. params%use_gauxc_model .AND. .NOT. dft_control%qs_control%gapw_xc .AND. &
1238 .NOT. gapw_paw_pseudopotentials .AND. para_env%mepos == 0 .AND.
ASSOCIATED(scf_env))
THEN
1239 IF (scf_env%iter_count == 1)
THEN
1242 "GauXC Skala with METHOD GAPW and GPW_TYPE pseudopotentials evaluates "// &
1243 "the XC term directly on the molecular AO/valence density; no GAPW one-center "// &
1244 "XC correction is used for those regular-grid kinds.")
1247 IF (params%device_runtime_fill_fraction <= 0.0_dp .OR. params%device_runtime_fill_fraction > 1.0_dp)
THEN
1248 CALL cp_abort(__location__, &
1249 "GAUXC%DEVICE_RUNTIME_FILL_FRACTION must be > 0 and <= 1.")
1251 IF (atom_chunk_size < -1)
THEN
1252 CALL cp_abort(__location__, &
1253 "GAUXC%MODEL_ATOM_CHUNK_SIZE must be -1, zero, or positive.")
1255 IF (molecular_virial_debug)
THEN
1256 IF (molecular_virial_debug_dx <= 0.0_dp)
THEN
1257 CALL cp_abort(__location__, &
1258 "GauXC MOLECULAR_VIRIAL_DEBUG_DX must be positive.")
1260 molecular_virial = .true.
1262 need_xc_gradient = calculate_forces .OR. molecular_virial
1263 CALL ensure_gauxc_periodic_reference_scope( &
1264 dft_control, cell, qs_kind_set, do_kpoints, periodic_reference)
1265 IF (is_periodic .AND. periodic_reference .AND. para_env%mepos == 0)
THEN
1266 IF (
ASSOCIATED(scf_env))
THEN
1267 IF (scf_env%iter_count == 1)
THEN
1270 "GAUXC%PERIODIC_REFERENCE uses GauXC molecular quadrature for isolated validation "// &
1271 "cells. Compact periodic materials require a dedicated periodic GauXC interface.")
1275 IF (params%use_gauxc_model)
THEN
1277 CALL cp_abort(__location__, &
1278 "GauXC Skala with NLCC pseudopotentials is not implemented. "// &
1279 "The frozen core density would need a SKALA-consistent feature definition.")
1282 IF (params%use_gauxc_model)
THEN
1283 CALL set_gauxc_model_atom_chunk_env( &
1284 atom_chunk_size, atom_chunk_size_explicit)
1285 IF (.NOT. grid_explicit) params%grid_type =
"SUPERFINE"
1286 IF (.NOT. pruning_explicit) params%pruning_scheme =
"UNPRUNED"
1288 grid_key = adjustl(params%grid_type)
1289 pruning_key = adjustl(params%pruning_scheme)
1292 IF (use_skala_model .AND. need_xc_gradient .AND. &
1293 (trim(grid_key) /=
"SUPERFINE" .OR. trim(pruning_key) /=
"UNPRUNED"))
THEN
1296 "GauXC Skala nuclear gradients are sensitive to the GauXC molecular grid. "// &
1297 "Use GRID SUPERFINE and PRUNING_SCHEME UNPRUNED for quantitative force checks.")
1299 IF (trim(model_key) ==
"SKALA")
THEN
1302 IF (trim(int_exec_space_key) ==
"DEVICE")
THEN
1303 CALL get_environment_variable(
"GAUXC_SKALA_CUDA_MODEL", model_name, status=env_status)
1305 IF (env_status /= 0 .OR. len_trim(model_name) == 0)
THEN
1306 CALL get_environment_variable(
"GAUXC_SKALA_MODEL", model_name, status=env_status)
1308 IF (env_status /= 0 .OR. len_trim(model_name) == 0)
THEN
1309 IF (trim(int_exec_space_key) ==
"DEVICE")
THEN
1312 "MODEL SKALA with DEVICE execution requires GAUXC_SKALA_CUDA_MODEL or "// &
1313 "GAUXC_SKALA_MODEL")
1315 cpabort(
"MODEL SKALA requires the GAUXC_SKALA_MODEL environment variable")
1318 params%model_eval_name = model_name
1321 SELECT CASE (trim(skala_runtime_key))
1323 params%use_self_runtime = use_skala_model .AND. para_env%num_pe > 1 .AND. params%nspins > 1
1325 params%use_self_runtime = .false.
1327 params%use_self_runtime = use_skala_model .AND. para_env%num_pe > 1
1329 CALL cp_abort(__location__,
"Unknown GAUXC%SKALA_RUNTIME value.")
1331 IF (.NOT. use_skala_model) params%use_self_runtime = .false.
1332 SELECT CASE (trim(gradient_runtime_key))
1333 CASE (
"AUTO",
"SELF")
1334 params%use_gradient_mpi_runtime = .false.
1335 params%use_gradient_self_runtime = need_xc_gradient .AND. params%use_gauxc_model .AND. &
1336 para_env%num_pe > 1 .AND. .NOT. params%use_self_runtime
1338 params%use_gradient_mpi_runtime = need_xc_gradient .AND. params%use_gauxc_model .AND. para_env%num_pe > 1
1339 params%use_gradient_self_runtime = .false.
1341 CALL cp_abort(__location__,
"Unknown GAUXC%MODEL_GRADIENT_RUNTIME value.")
1343 IF (.NOT. params%use_gauxc_model)
THEN
1344 params%use_gradient_mpi_runtime = .false.
1345 params%use_gradient_self_runtime = .false.
1347 IF (use_skala_model .AND. para_env%num_pe > 1 .AND. .NOT. params%use_self_runtime .AND. &
1348 para_env%mepos == 0 .AND.
ASSOCIATED(scf_env))
THEN
1349 IF (scf_env%iter_count == 1)
THEN
1352 "GAUXC%SKALA_RUNTIME uses the MPI communicator for energy/VXC. "// &
1353 "SKALA Torch atom chunks can be distributed across MPI ranks; "// &
1354 "set GAUXC_ONEDFT_DISTRIBUTED_TORCH=0 to force rank-0 Torch inference.")
1359 params%use_fd_gradient = gapw_method .AND. need_xc_gradient
1361 IF (.NOT.
ASSOCIATED(qs_env%gauxc_cache))
ALLOCATE (qs_env%gauxc_cache)
1362 cache => qs_env%gauxc_cache
1371 hdf5_output = (trim(output_path) /=
"")
1372 write_hdf5_output = hdf5_output .AND. para_env%mepos == 0
1373 IF (write_hdf5_output .AND.
ASSOCIATED(scf_env))
THEN
1374 write_hdf5_output = scf_env%iter_count == 1
1376 IF (write_hdf5_output)
THEN
1377 CALL gauxc_write_molecule_hdf5( &
1383 CALL gauxc_check_status(gauxc_status)
1384 CALL gauxc_write_basisset_hdf5( &
1390 CALL gauxc_check_status(gauxc_status)
1393 IF (qs_env%run_rtp)
THEN
1394 cpabort(
"GAUXC XC energy currently does not support real-time propagation")
1404 cpabort(
"UNIMPLEMENTED: Handling nimg>1 in k-point integration")
1406 CALL dbcsr_to_dense(rho_ao(1, img), density_scalar, para_env)
1407 CALL para_env%sum(density_scalar)
1408 IF (params%nspins == 1)
THEN
1409 gauxc_xc_result = gauxc_compute_xc( &
1412 nspins=params%nspins, &
1413 status=gauxc_status, &
1414 model=trim(params%model_eval_name))
1415 CALL gauxc_check_status(gauxc_status)
1416 IF (need_xc_gradient)
THEN
1417 IF (params%use_fd_gradient)
THEN
1418 CALL gauxc_xc_gradient_fd( &
1419 particle_set, qs_kind_set, density_scalar, params%nspins, params%model_eval_name, &
1420 params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1421 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1422 params%device_runtime_fill_fraction, gapw_fd_gradient_dx, para_env, &
1424 ELSE IF (params%use_gradient_self_runtime)
THEN
1425 exc_grad = gauxc_compute_xc_gradient( &
1426 cache%gradient_integrator, &
1428 nspins=params%nspins, &
1429 natom=params%natom, &
1430 status=gauxc_status, &
1431 model=trim(params%model_eval_name))
1433 exc_grad = gauxc_compute_xc_gradient( &
1436 nspins=params%nspins, &
1437 natom=params%natom, &
1438 status=gauxc_status, &
1439 model=trim(params%model_eval_name))
1441 CALL gauxc_check_status(gauxc_status)
1442 IF (calculate_forces)
THEN
1443 CALL add_gauxc_gradient_to_force( &
1444 exc_grad%exc_grad, &
1449 IF (molecular_virial)
THEN
1450 CALL print_gauxc_molecular_virial(exc_grad%exc_grad, particle_set, para_env)
1452 IF (molecular_virial_debug)
THEN
1453 CALL debug_gauxc_molecular_virial( &
1454 exc_grad%exc_grad, particle_set, qs_kind_set, density_scalar, params%nspins, &
1455 params%model_eval_name, params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1456 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1457 params%device_runtime_fill_fraction, molecular_virial_debug_dx, para_env)
1459 DEALLOCATE (exc_grad%exc_grad)
1462 cpassert(params%nspins == 2)
1466 CALL dbcsr_to_dense(rho_ao(2, img), density_zeta, para_env)
1467 CALL para_env%sum(density_zeta)
1469 density_scalar(:, :) = density_scalar(:, :) + density_zeta(:, :)
1474 density_zeta(:, :) = density_scalar(:, :) - 2.0_dp*density_zeta(:, :)
1475 gauxc_xc_result = gauxc_compute_xc( &
1481 model=trim(params%model_eval_name))
1482 CALL gauxc_check_status(gauxc_status)
1483 IF (need_xc_gradient)
THEN
1484 IF (params%use_fd_gradient)
THEN
1485 CALL gauxc_xc_gradient_fd( &
1486 particle_set, qs_kind_set, density_scalar, params%nspins, params%model_eval_name, &
1487 params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1488 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1489 params%device_runtime_fill_fraction, gapw_fd_gradient_dx, para_env, &
1490 exc_grad%exc_grad, density_zeta=density_zeta)
1491 ELSE IF (params%use_gradient_self_runtime)
THEN
1492 exc_grad = gauxc_compute_xc_gradient( &
1493 cache%gradient_integrator, &
1499 model=trim(params%model_eval_name))
1501 exc_grad = gauxc_compute_xc_gradient( &
1508 model=trim(params%model_eval_name))
1510 CALL gauxc_check_status(gauxc_status)
1511 IF (calculate_forces)
THEN
1512 CALL add_gauxc_gradient_to_force( &
1513 exc_grad%exc_grad, &
1518 IF (molecular_virial)
THEN
1519 CALL print_gauxc_molecular_virial(exc_grad%exc_grad, particle_set, para_env)
1521 IF (molecular_virial_debug)
THEN
1522 CALL debug_gauxc_molecular_virial( &
1523 exc_grad%exc_grad, particle_set, qs_kind_set, density_scalar, params%nspins, &
1524 params%model_eval_name, params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1525 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1526 params%device_runtime_fill_fraction, molecular_virial_debug_dx, para_env, &
1527 density_zeta=density_zeta)
1529 DEALLOCATE (exc_grad%exc_grad)
1533 energy%exc = energy%exc + gauxc_xc_result%exc
1535 IF (params%nspins == 1)
THEN
1537 matrix_vxc(1) = dense_to_dbcsr(gauxc_xc_result%vxc_scalar, rho_ao(1, img))
1539 cpabort(
"UNIMPLEMENTED: Handling multiple result matrices in k-point integration")
1542 cpassert(params%nspins == 2)
1544 vxc_zeta_tmp = dense_to_dbcsr(gauxc_xc_result%vxc_zeta, rho_ao(1, img))
1547 matrix_vxc(ispin) = dense_to_dbcsr(gauxc_xc_result%vxc_scalar, rho_ao(ispin, 1))
1549 matrix_vxc(ispin)%matrix, &
1550 vxc_zeta_tmp%matrix, &
1553 1.0_dp - real(ispin - 1,
dp)*2.0_dp)
1556 cpabort(
"UNIMPLEMENTED: Handling multiple result matrices in k-point integration")
1558 CALL dbcsr_release(vxc_zeta_tmp%matrix)
1559 DEALLOCATE (vxc_zeta_tmp%matrix)
1563 DEALLOCATE (density_scalar)
1564 IF (
ALLOCATED(density_zeta))
DEALLOCATE (density_zeta)
1565 DEALLOCATE (gauxc_xc_result%vxc_scalar)
1566 IF (
ALLOCATED(gauxc_xc_result%vxc_zeta))
DEALLOCATE (gauxc_xc_result%vxc_zeta)
1568 CALL set_ks_env(ks_env, matrix_vxc=matrix_vxc)
1569 DO ispin = 1, params%nspins
1570 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...
subroutine, public dbcsr_get_readonly_block_p(matrix, row, col, block, found, row_size, col_size)
Like dbcsr_get_block_p() but with matrix being INTENT(IN). When invoking this routine,...
character function, public dbcsr_get_matrix_type(matrix)
...
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_finalize(matrix)
...
subroutine, public dbcsr_release(matrix)
...
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)
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)
...
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)
...
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)
...
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...