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
1032 rho_ao_external, exc_external, matrix_vxc_external)
1035 LOGICAL,
INTENT(IN) :: calculate_forces
1036 TYPE(dbcsr_p_type),
DIMENSION(:, :),
INTENT(IN), &
1037 OPTIONAL,
POINTER :: rho_ao_external
1038 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: exc_external
1039 TYPE(dbcsr_p_type),
DIMENSION(:),
INTENT(INOUT), &
1040 OPTIONAL,
POINTER :: matrix_vxc_external
1042 CHARACTER(len=*),
PARAMETER :: nonlocal_vdw_abort_message = &
1043 "GauXC does not support non-local VDW_POTENTIAL corrections. "// &
1044 "Use an additive PAIR_POTENTIAL dispersion correction or disable GauXC."
1045 REAL(kind=
dp),
PARAMETER :: gapw_fd_gradient_dx = 1.0e-4_dp
1047 CHARACTER(len=default_path_length) :: model_key, model_name, output_path
1048 CHARACTER(len=default_string_length) :: gradient_runtime, gradient_runtime_key, grid_key, &
1049 int_exec_space_key, lwd_kernel_key, pruning_key, skala_runtime, skala_runtime_key, &
1051 INTEGER :: atom_chunk_size, env_status, img, ispin, &
1053 LOGICAL :: atom_chunk_size_explicit, do_kpoints, external_density, gapw_method, &
1054 gapw_paw_pseudopotentials, gapw_pseudopotentials, grid_explicit, hdf5_output, &
1055 is_periodic, low_spin_scope, molecular_virial, molecular_virial_debug, need_xc_gradient, &
1056 periodic_reference, pruning_explicit, use_skala_model, write_hdf5_output
1057 REAL(kind=
dp) :: exc_value, molecular_virial_debug_dx
1058 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: density_scalar, density_zeta
1063 TYPE(cp_gauxc_status_type) :: gauxc_status
1064 TYPE(cp_gauxc_xc_gradient_type) :: exc_grad
1065 TYPE(cp_gauxc_xc_type) :: gauxc_xc_result
1066 TYPE(dbcsr_p_type) :: vxc_zeta_tmp
1067 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_vxc
1068 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao
1074 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1076 TYPE(
qs_rho_type),
POINTER :: rho, rho_use, rho_xc
1080 external_density =
PRESENT(rho_ao_external)
1081 cpassert(
PRESENT(exc_external) .EQV. external_density)
1082 cpassert(
PRESENT(matrix_vxc_external) .EQV. external_density)
1083 IF (external_density)
THEN
1084 cpassert(
ASSOCIATED(rho_ao_external))
1085 cpassert(.NOT.
ASSOCIATED(matrix_vxc_external))
1108 dft_control=dft_control, &
1109 do_kpoints=do_kpoints, &
1112 matrix_vxc=matrix_vxc, &
1113 natom=params%natom, &
1114 atomic_kind_set=atomic_kind_set, &
1116 para_env=para_env, &
1117 particle_set=particle_set, &
1118 qs_kind_set=qs_kind_set, &
1123 gapw_method = dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc
1124 gapw_pseudopotentials = gapw_method .AND. &
1126 gapw_paw_pseudopotentials = gapw_method .AND. &
1128 IF (dft_control%qs_control%gapw_xc)
THEN
1129 cpassert(
ASSOCIATED(rho_xc))
1132 cpassert(
ASSOCIATED(rho))
1139 IF (external_density)
THEN
1140 rho_ao => rho_ao_external
1142 NULLIFY (matrix_vxc)
1144 nimages = dft_control%nimages
1145 params%nspins = dft_control%nspins
1146 IF (external_density)
THEN
1147 cpassert(
SIZE(rho_ao, 1) == params%nspins)
1148 cpassert(
SIZE(rho_ao, 2) == nimages)
1150 low_spin_scope = external_density .OR. (dft_control%low_spin_roks .AND. gapw_method)
1151 is_periodic = .false.
1152 IF (
ASSOCIATED(cell)) is_periodic = any(cell%perd /= 0)
1154 IF (
ASSOCIATED(qs_env%dispersion_env))
THEN
1156 cpabort(nonlocal_vdw_abort_message)
1159 NULLIFY (vxc_zeta_tmp%matrix)
1161 gauxc_functional_section => get_gauxc_functional(xc_section)
1163 gauxc_functional_section, &
1165 c_val=params%xc_fun_name)
1167 gauxc_functional_section, &
1171 gauxc_functional_section, &
1173 c_val=params%grid_type, &
1174 explicit=grid_explicit)
1176 gauxc_functional_section, &
1177 "RADIAL_QUADRATURE", &
1178 c_val=params%radial_quadrature)
1180 gauxc_functional_section, &
1182 c_val=params%pruning_scheme, &
1183 explicit=pruning_explicit)
1185 gauxc_functional_section, &
1187 i_val=params%batch_size)
1189 gauxc_functional_section, &
1190 "DEVICE_RUNTIME_FILL_FRACTION", &
1191 r_val=params%device_runtime_fill_fraction)
1193 gauxc_functional_section, &
1194 "MODEL_ATOM_CHUNK_SIZE", &
1195 i_val=atom_chunk_size, &
1196 explicit=atom_chunk_size_explicit)
1198 gauxc_functional_section, &
1199 "PERIODIC_REFERENCE", &
1200 l_val=periodic_reference)
1202 gauxc_functional_section, &
1203 "MOLECULAR_VIRIAL", &
1204 l_val=molecular_virial)
1206 gauxc_functional_section, &
1207 "MOLECULAR_VIRIAL_DEBUG", &
1208 l_val=molecular_virial_debug)
1210 gauxc_functional_section, &
1211 "MOLECULAR_VIRIAL_DEBUG_DX", &
1212 r_val=molecular_virial_debug_dx)
1214 gauxc_functional_section, &
1215 "LB_EXECUTION_SPACE", &
1216 c_val=params%lb_exec_space)
1218 gauxc_functional_section, &
1219 "INT_EXECUTION_SPACE", &
1220 c_val=params%int_exec_space)
1222 gauxc_functional_section, &
1224 c_val=params%lwd_kernel)
1226 gauxc_functional_section, &
1228 c_val=skala_runtime)
1230 gauxc_functional_section, &
1231 "MODEL_GRADIENT_RUNTIME", &
1232 c_val=gradient_runtime)
1234 gauxc_functional_section, &
1235 "FORCE_NUMERICAL_GRADIENT", &
1236 l_val=params%force_fd_gradient)
1238 gauxc_functional_section, &
1242 model_key = adjustl(model_name)
1244 xc_fun_key = adjustl(params%xc_fun_name)
1246 skala_runtime_key = adjustl(skala_runtime)
1248 gradient_runtime_key = adjustl(gradient_runtime)
1250 int_exec_space_key = adjustl(params%int_exec_space)
1252 params%use_gauxc_model = (trim(model_key) /=
"" .AND. trim(model_key) /=
"NONE" .AND. &
1253 trim(model_key) /= trim(xc_fun_key))
1254 use_skala_model = (index(trim(model_key),
"SKALA") > 0)
1255 lwd_kernel_key = adjustl(params%lwd_kernel)
1257 IF (trim(lwd_kernel_key) ==
"AUTO")
THEN
1258 params%lwd_kernel =
"DEFAULT"
1259#if defined(GAUXC_HAS_CUTLASS)
1260 IF (use_skala_model .AND. trim(params%int_exec_space) ==
"DEVICE")
THEN
1261 params%lwd_kernel =
"SCHEME1-CUTLASS"
1265 params%model_eval_name = model_name
1266 IF (.NOT. params%use_gauxc_model)
THEN
1268 params%model_eval_name =
"NONE"
1270 IF (gapw_pseudopotentials .AND. params%use_gauxc_model .AND. .NOT. dft_control%qs_control%gapw_xc .AND. &
1271 .NOT. gapw_paw_pseudopotentials .AND. para_env%mepos == 0 .AND.
ASSOCIATED(scf_env))
THEN
1272 IF (scf_env%iter_count == 1)
THEN
1275 "GauXC Skala with METHOD GAPW and GPW_TYPE pseudopotentials evaluates "// &
1276 "the XC term directly on the molecular AO/valence density; no GAPW one-center "// &
1277 "XC correction is used for those regular-grid kinds.")
1280 IF (params%device_runtime_fill_fraction <= 0.0_dp .OR. params%device_runtime_fill_fraction > 1.0_dp)
THEN
1281 CALL cp_abort(__location__, &
1282 "GAUXC%DEVICE_RUNTIME_FILL_FRACTION must be > 0 and <= 1.")
1284 IF (atom_chunk_size < -1)
THEN
1285 CALL cp_abort(__location__, &
1286 "GAUXC%MODEL_ATOM_CHUNK_SIZE must be -1, zero, or positive.")
1288 IF (molecular_virial_debug)
THEN
1289 IF (molecular_virial_debug_dx <= 0.0_dp)
THEN
1290 CALL cp_abort(__location__, &
1291 "GauXC MOLECULAR_VIRIAL_DEBUG_DX must be positive.")
1293 molecular_virial = .true.
1295 need_xc_gradient = calculate_forces .OR. molecular_virial
1296 IF (low_spin_scope)
THEN
1297 IF (.NOT. dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1298 cpabort(
"GauXC low spin ROKS requires METHOD GAPW.")
1301 cpabort(
"GAPW low spin ROKS GauXC requires all-electron kinds.")
1303 IF (is_periodic .OR. do_kpoints .OR. nimages /= 1)
THEN
1304 cpabort(
"GAPW low spin ROKS GauXC requires an isolated Gamma-point calculation.")
1306 IF (need_xc_gradient)
THEN
1307 CALL cp_abort(__location__, &
1308 "GAPW low spin ROKS GauXC nuclear gradients and molecular virial are not implemented.")
1310 IF (trim(int_exec_space_key) /=
"HOST" .OR. trim(params%lb_exec_space) /=
"HOST")
THEN
1311 cpabort(
"GAPW low spin ROKS GauXC currently requires HOST execution.")
1313 IF (params%use_gauxc_model .AND. .NOT. use_skala_model)
THEN
1314 cpabort(
"GAPW low spin ROKS GauXC supports only the SKALA model or conventional XC.")
1316 IF (use_skala_model .AND. trim(skala_runtime_key) ==
"MPI")
THEN
1317 cpabort(
"GAPW low spin ROKS Skala requires SKALA_RUNTIME AUTO or SELF.")
1320 CALL ensure_gauxc_periodic_reference_scope( &
1321 dft_control, cell, qs_kind_set, do_kpoints, periodic_reference)
1322 IF (is_periodic .AND. periodic_reference .AND. para_env%mepos == 0)
THEN
1323 IF (
ASSOCIATED(scf_env))
THEN
1324 IF (scf_env%iter_count == 1)
THEN
1327 "GAUXC%PERIODIC_REFERENCE uses GauXC molecular quadrature for isolated validation "// &
1328 "cells. Compact periodic materials require a dedicated periodic GauXC interface.")
1332 IF (params%use_gauxc_model)
THEN
1334 CALL cp_abort(__location__, &
1335 "GauXC Skala with NLCC pseudopotentials is not implemented. "// &
1336 "The frozen core density would need a SKALA-consistent feature definition.")
1339 IF (params%use_gauxc_model)
THEN
1340 CALL set_gauxc_model_atom_chunk_env( &
1341 atom_chunk_size, atom_chunk_size_explicit)
1342 IF (.NOT. grid_explicit) params%grid_type =
"SUPERFINE"
1343 IF (.NOT. pruning_explicit) params%pruning_scheme =
"UNPRUNED"
1345 grid_key = adjustl(params%grid_type)
1346 pruning_key = adjustl(params%pruning_scheme)
1349 IF (use_skala_model .AND. need_xc_gradient .AND. &
1350 (trim(grid_key) /=
"SUPERFINE" .OR. trim(pruning_key) /=
"UNPRUNED"))
THEN
1353 "GauXC Skala nuclear gradients are sensitive to the GauXC molecular grid. "// &
1354 "Use GRID SUPERFINE and PRUNING_SCHEME UNPRUNED for quantitative force checks.")
1356 IF (trim(model_key) ==
"SKALA")
THEN
1359 IF (trim(int_exec_space_key) ==
"DEVICE")
THEN
1360 CALL get_environment_variable(
"SKALA_CUDA_MODEL", model_name, status=env_status)
1362 IF (env_status /= 0 .OR. len_trim(model_name) == 0)
THEN
1363 CALL get_environment_variable(
"SKALA_MODEL", model_name, status=env_status)
1365 IF (env_status /= 0 .OR. len_trim(model_name) == 0)
THEN
1366 IF (trim(int_exec_space_key) ==
"DEVICE")
THEN
1369 "MODEL SKALA with DEVICE execution requires SKALA_CUDA_MODEL or "// &
1370 "GAUXC_SKALA_MODEL")
1372 cpabort(
"MODEL SKALA requires the GAUXC_SKALA_MODEL environment variable")
1375 params%model_eval_name = model_name
1378 SELECT CASE (trim(skala_runtime_key))
1380 params%use_self_runtime = use_skala_model .AND. para_env%num_pe > 1 .AND. params%nspins > 1
1382 params%use_self_runtime = .false.
1384 params%use_self_runtime = use_skala_model .AND. para_env%num_pe > 1
1386 CALL cp_abort(__location__,
"Unknown GAUXC%SKALA_RUNTIME value.")
1388 IF (.NOT. use_skala_model) params%use_self_runtime = .false.
1389 params%gradient_runtime = gradient_runtime_key
1390 IF (use_skala_model .AND. para_env%num_pe > 1 .AND. .NOT. params%use_self_runtime .AND. &
1391 para_env%mepos == 0 .AND.
ASSOCIATED(scf_env))
THEN
1392 IF (scf_env%iter_count == 1)
THEN
1395 "GAUXC%SKALA_RUNTIME uses the MPI communicator for energy/VXC. "// &
1396 "SKALA Torch atom chunks can be distributed across MPI ranks; "// &
1397 "set GAUXC_ONEDFT_DISTRIBUTED_TORCH=0 to force rank-0 Torch inference.")
1402 params%gapw_method = gapw_method
1403 params%need_xc_gradient = need_xc_gradient
1405 IF (.NOT.
ASSOCIATED(qs_env%gauxc_cache))
ALLOCATE (qs_env%gauxc_cache)
1406 cache => qs_env%gauxc_cache
1415 hdf5_output = (trim(output_path) /=
"")
1416 write_hdf5_output = hdf5_output .AND. para_env%mepos == 0 .AND. .NOT. external_density
1417 IF (write_hdf5_output .AND.
ASSOCIATED(scf_env))
THEN
1418 write_hdf5_output = scf_env%iter_count == 1
1420 IF (write_hdf5_output)
THEN
1421 CALL gauxc_write_molecule_hdf5( &
1427 CALL gauxc_check_status(gauxc_status)
1428 CALL gauxc_write_basisset_hdf5( &
1434 CALL gauxc_check_status(gauxc_status)
1437 IF (qs_env%run_rtp)
THEN
1438 cpabort(
"GAUXC XC energy currently does not support real-time propagation")
1448 cpabort(
"UNIMPLEMENTED: Handling nimg>1 in k-point integration")
1450 CALL dbcsr_to_dense(rho_ao(1, img), density_scalar, para_env)
1451 CALL para_env%sum(density_scalar)
1452 IF (params%nspins == 1)
THEN
1453 gauxc_xc_result = gauxc_compute_xc( &
1456 nspins=params%nspins, &
1457 status=gauxc_status, &
1458 model=trim(params%model_eval_name))
1459 CALL gauxc_check_status(gauxc_status)
1460 IF (need_xc_gradient)
THEN
1461 IF (params%use_fd_gradient)
THEN
1462 CALL gauxc_xc_gradient_fd( &
1463 particle_set, qs_kind_set, density_scalar, params%nspins, params%model_eval_name, &
1464 params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1465 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1466 params%device_runtime_fill_fraction, gapw_fd_gradient_dx, para_env, &
1468 ELSE IF (params%use_gradient_self_runtime)
THEN
1469 exc_grad = gauxc_compute_xc_gradient( &
1470 cache%gradient_integrator, &
1472 nspins=params%nspins, &
1473 natom=params%natom, &
1474 status=gauxc_status, &
1475 model=trim(params%model_eval_name))
1477 exc_grad = gauxc_compute_xc_gradient( &
1480 nspins=params%nspins, &
1481 natom=params%natom, &
1482 status=gauxc_status, &
1483 model=trim(params%model_eval_name))
1485 CALL gauxc_check_status(gauxc_status)
1486 IF (calculate_forces)
THEN
1487 CALL add_gauxc_gradient_to_force( &
1488 exc_grad%exc_grad, &
1493 IF (molecular_virial)
THEN
1494 CALL print_gauxc_molecular_virial(exc_grad%exc_grad, particle_set, para_env)
1496 IF (molecular_virial_debug)
THEN
1497 CALL debug_gauxc_molecular_virial( &
1498 exc_grad%exc_grad, particle_set, qs_kind_set, density_scalar, params%nspins, &
1499 params%model_eval_name, params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1500 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1501 params%device_runtime_fill_fraction, molecular_virial_debug_dx, para_env)
1503 DEALLOCATE (exc_grad%exc_grad)
1506 cpassert(params%nspins == 2)
1510 CALL dbcsr_to_dense(rho_ao(2, img), density_zeta, para_env)
1511 CALL para_env%sum(density_zeta)
1513 density_scalar(:, :) = density_scalar(:, :) + density_zeta(:, :)
1518 density_zeta(:, :) = density_scalar(:, :) - 2.0_dp*density_zeta(:, :)
1519 gauxc_xc_result = gauxc_compute_xc( &
1525 model=trim(params%model_eval_name))
1526 CALL gauxc_check_status(gauxc_status)
1527 IF (need_xc_gradient)
THEN
1528 IF (params%use_fd_gradient)
THEN
1529 CALL gauxc_xc_gradient_fd( &
1530 particle_set, qs_kind_set, density_scalar, params%nspins, params%model_eval_name, &
1531 params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1532 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1533 params%device_runtime_fill_fraction, gapw_fd_gradient_dx, para_env, &
1534 exc_grad%exc_grad, density_zeta=density_zeta)
1535 ELSE IF (params%use_gradient_self_runtime)
THEN
1536 exc_grad = gauxc_compute_xc_gradient( &
1537 cache%gradient_integrator, &
1543 model=trim(params%model_eval_name))
1545 exc_grad = gauxc_compute_xc_gradient( &
1552 model=trim(params%model_eval_name))
1554 CALL gauxc_check_status(gauxc_status)
1555 IF (calculate_forces)
THEN
1556 CALL add_gauxc_gradient_to_force( &
1557 exc_grad%exc_grad, &
1562 IF (molecular_virial)
THEN
1563 CALL print_gauxc_molecular_virial(exc_grad%exc_grad, particle_set, para_env)
1565 IF (molecular_virial_debug)
THEN
1566 CALL debug_gauxc_molecular_virial( &
1567 exc_grad%exc_grad, particle_set, qs_kind_set, density_scalar, params%nspins, &
1568 params%model_eval_name, params%xc_fun_name, params%grid_type, params%radial_quadrature, params%pruning_scheme, &
1569 params%lb_exec_space, params%int_exec_space, params%lwd_kernel, params%batch_size, &
1570 params%device_runtime_fill_fraction, molecular_virial_debug_dx, para_env, &
1571 density_zeta=density_zeta)
1573 DEALLOCATE (exc_grad%exc_grad)
1577 exc_value = exc_value + gauxc_xc_result%exc
1579 IF (params%nspins == 1)
THEN
1581 matrix_vxc(1) = dense_to_dbcsr(gauxc_xc_result%vxc_scalar, rho_ao(1, img))
1583 cpabort(
"UNIMPLEMENTED: Handling multiple result matrices in k-point integration")
1586 cpassert(params%nspins == 2)
1588 vxc_zeta_tmp = dense_to_dbcsr(gauxc_xc_result%vxc_zeta, rho_ao(1, img))
1591 matrix_vxc(ispin) = dense_to_dbcsr(gauxc_xc_result%vxc_scalar, rho_ao(ispin, 1))
1593 matrix_vxc(ispin)%matrix, &
1594 vxc_zeta_tmp%matrix, &
1597 1.0_dp - real(ispin - 1,
dp)*2.0_dp)
1600 cpabort(
"UNIMPLEMENTED: Handling multiple result matrices in k-point integration")
1602 CALL dbcsr_release(vxc_zeta_tmp%matrix)
1603 DEALLOCATE (vxc_zeta_tmp%matrix)
1607 DEALLOCATE (density_scalar)
1608 IF (
ALLOCATED(density_zeta))
DEALLOCATE (density_zeta)
1609 DEALLOCATE (gauxc_xc_result%vxc_scalar)
1610 IF (
ALLOCATED(gauxc_xc_result%vxc_zeta))
DEALLOCATE (gauxc_xc_result%vxc_zeta)
1612 IF (external_density)
THEN
1613 exc_external = exc_value
1614 matrix_vxc_external => matrix_vxc
1616 energy%exc = exc_value
1617 CALL set_ks_env(ks_env, matrix_vxc=matrix_vxc)
1619 DO ispin = 1, params%nspins
1620 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, 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...