9#include "gauxc/gauxc_config.f"
12#define GAUXC_RETURN_IF_ERROR(status) IF (status%status%code /= 0) RETURN
14MODULE xc_gauxc_interface
16 USE iso_fortran_env,
ONLY: &
18#if defined (__HAS_IEEE_EXCEPTIONS)
19 USE ieee_exceptions,
ONLY: &
21 ieee_get_halting_mode, &
24 USE iso_c_binding,
ONLY: &
67 USE gauxc_status,
ONLY: &
68 gauxc_status_message, &
70 USE gauxc_enums,
ONLY: &
71 gauxc_atomicgridsizedefault, &
72 gauxc_executionspace, &
73 gauxc_pruningscheme, &
75 USE gauxc_runtime_environment,
ONLY: &
76 gauxc_runtime_environment_delete, &
77 gauxc_runtime_environment_new, &
78 gauxc_runtime_environment_type
79#ifdef GAUXC_HAS_DEVICE
80 USE gauxc_runtime_environment,
ONLY: &
81 gauxc_device_runtime_environment_new
83#if defined(GAUXC_HAS_DEVICE) && defined(__LIBTORCH)
86 USE gauxc_molecule,
ONLY: &
88 gauxc_molecule_new_from_atoms, &
90 USE gauxc_atom,
ONLY: &
92 USE gauxc_basisset,
ONLY: &
94 gauxc_basisset_new_from_shells, &
95 gauxc_basisset_type, &
97 USE gauxc_shell,
ONLY: &
99 USE gauxc_molgrid,
ONLY: &
101 gauxc_molgrid_new_default, &
103 USE gauxc_load_balancer,
ONLY: &
105 gauxc_load_balancer_factory_get_instance, &
106 gauxc_load_balancer_factory_new, &
107 gauxc_load_balancer_factory_type, &
108 gauxc_load_balancer_type
109 USE gauxc_molecular_weights,
ONLY: &
111 gauxc_get_instance, &
112 gauxc_molecular_weights_factory_new, &
113 gauxc_molecular_weights_factory_type, &
114 gauxc_molecular_weights_modify_weights, &
115 gauxc_molecular_weights_settings, &
116 gauxc_molecular_weights_type
117 USE gauxc_xc_functional,
ONLY: &
119 gauxc_functional_from_string, &
120 gauxc_functional_type
121 USE gauxc_integrator,
ONLY: &
123 gauxc_integrator_eval_exc_grad_rks, &
124 gauxc_integrator_eval_exc_grad_uks, &
125 gauxc_integrator_eval_exc_vxc_rks, &
126 gauxc_integrator_eval_exc_vxc_uks, &
127 gauxc_integrator_new, &
128 gauxc_integrator_type
129#ifdef GAUXC_HAS_ONEDFT
130 USE gauxc_integrator,
ONLY: &
131 gauxc_integrator_eval_exc_grad_onedft_uks, &
132 gauxc_integrator_eval_exc_vxc_onedft_uks
134 omp_get_max_threads, &
138 USE gauxc_external_hdf5_write,
ONLY: &
139 gauxc_write_hdf5_record
145#include "../base/base_uses.f90"
154 TYPE cp_gauxc_molecule_type
155 END TYPE cp_gauxc_molecule_type
157 TYPE cp_gauxc_basisset_type
158 INTEGER :: max_l = -1
159 END TYPE cp_gauxc_basisset_type
161 TYPE cp_gauxc_grid_type
162 END TYPE cp_gauxc_grid_type
164 TYPE cp_gauxc_integrator_type
165 END TYPE cp_gauxc_integrator_type
167 TYPE cp_gauxc_status_type
168 END TYPE cp_gauxc_status_type
174 TYPE cp_gauxc_molecule_type
175 TYPE(gauxc_molecule_type) :: molecule
176 END TYPE cp_gauxc_molecule_type
178 TYPE cp_gauxc_basisset_type
179 TYPE(gauxc_basisset_type) :: basis
180 INTEGER :: max_l = -1
181 END TYPE cp_gauxc_basisset_type
183 TYPE cp_gauxc_grid_type
184 TYPE(gauxc_molgrid_type) :: grid
185 TYPE(gauxc_load_balancer_type) :: lb
186 TYPE(gauxc_load_balancer_factory_type) :: lbf
187 TYPE(gauxc_molecular_weights_type) :: mw
188 TYPE(gauxc_molecular_weights_factory_type) :: mwf
189 TYPE(gauxc_runtime_environment_type) :: rt
190 LOGICAL :: owns_rt = .false.
191 LOGICAL :: uses_device_runtime = .false.
192 END TYPE cp_gauxc_grid_type
194 TYPE cp_gauxc_integrator_type
195 TYPE(gauxc_functional_type) :: func
197 END TYPE cp_gauxc_integrator_type
199 TYPE cp_gauxc_status_type
200 TYPE(gauxc_status_type) :: status
201 END TYPE cp_gauxc_status_type
203 TYPE(gauxc_runtime_environment_type) :: rt
204 INTEGER :: rt_mpi_comm = -1
205 LOGICAL :: rt_has_mpi_comm = .false.
209 TYPE cp_gauxc_xc_type
210 REAL(c_double) :: exc = 0.0_c_double
211 REAL(c_double),
DIMENSION(:, :),
ALLOCATABLE :: vxc_scalar, vxc_zeta
212 END TYPE cp_gauxc_xc_type
214 TYPE cp_gauxc_xc_gradient_type
215 REAL(c_double),
ALLOCATABLE,
DIMENSION(:) :: exc_grad
216 END TYPE cp_gauxc_xc_gradient_type
218 CHARACTER(LEN=*),
PARAMETER :: no_gauxc_message =
"Compile CP2K with GauXC to use this functionality!"
221 cp_gauxc_basisset_type, &
222 cp_gauxc_grid_type, &
223 cp_gauxc_integrator_type, &
224 cp_gauxc_molecule_type, &
225 cp_gauxc_status_type, &
226 cp_gauxc_xc_gradient_type, &
228 gauxc_check_status, &
229 gauxc_compute_xc_gradient, &
231 gauxc_create_basisset, &
233 gauxc_create_integrator, &
234 gauxc_create_molecule, &
235 gauxc_destroy_basisset, &
236 gauxc_destroy_grid, &
237 gauxc_destroy_integrator, &
238 gauxc_destroy_molecule, &
241 gauxc_write_basisset_hdf5, &
242 gauxc_write_molecule_hdf5
251 TYPE(cp_gauxc_status_type) :: status
254 CHARACTER(KIND=c_char),
POINTER :: s(:)
255 CHARACTER(LEN=32) :: stderr_env
256 INTEGER :: i, ierr, iw
257 LOGICAL :: print_to_stderr
258 INTEGER,
PARAMETER :: status_message_length = 4096
262 CALL get_environment_variable(
"CP2K_GAUXC_STATUS_STDERR", stderr_env)
264 SELECT CASE (trim(stderr_env))
265 CASE (
"",
"0",
"FALSE",
"F",
"OFF",
"NO")
266 print_to_stderr = .false.
267 CASE (
"1",
"TRUE",
"T",
"ON",
"YES")
268 print_to_stderr = .true.
270 print_to_stderr = .true.
273 WRITE (unit=iw, fmt=
'(a,1x,i0)')
"GauXC returned with status code", status%status%code
274 IF (c_associated(status%status%message))
THEN
275 WRITE (unit=iw, fmt=
'(a)', advance=
'no')
"GauXC status message: ["
277 CALL c_f_pointer(status%status%message, s, [status_message_length])
279 IF (s(i) == c_null_char)
EXIT
280 WRITE (unit=iw, fmt=
'(A)', advance=
'no') s(i)
283 WRITE (unit=iw, fmt=
'(a)')
"]"
285 WRITE (unit=iw, fmt=
'(a)')
"GauXC status message: [null]"
288 IF (print_to_stderr)
THEN
289 WRITE (unit=ierr, fmt=
'(a,1x,i0)')
"GauXC returned with status code", status%status%code
290 IF (c_associated(status%status%message))
THEN
291 WRITE (unit=ierr, fmt=
'(a)', advance=
'no')
"GauXC status message: ["
293 CALL c_f_pointer(status%status%message, s, [status_message_length])
295 IF (s(i) == c_null_char)
EXIT
296 WRITE (unit=ierr, fmt=
'(A)', advance=
'no') s(i)
299 WRITE (unit=ierr, fmt=
'(a)')
"]"
301 WRITE (unit=ierr, fmt=
'(a)')
"GauXC status message: [null]"
314 SUBROUTINE gauxc_init(mpi_comm, status)
315 INTEGER,
INTENT(IN),
OPTIONAL :: mpi_comm
316 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
319#if defined(GAUXC_HAS_MPI) && defined(__parallel)
320 IF (
PRESENT(mpi_comm))
THEN
321 rt = gauxc_runtime_environment_new(status%status, mpi_comm)
322 rt_mpi_comm = mpi_comm
323 rt_has_mpi_comm = .true.
325 rt = gauxc_runtime_environment_new(status%status)
327 rt_has_mpi_comm = .false.
331 rt = gauxc_runtime_environment_new(status%status)
333 rt_has_mpi_comm = .false.
335 gauxc_return_if_error(status)
340 END SUBROUTINE gauxc_init
346 SUBROUTINE gauxc_finalize(status)
347 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
350 CALL gauxc_runtime_environment_delete(status%status, rt)
351 gauxc_return_if_error(status)
353 rt_has_mpi_comm = .false.
357 END SUBROUTINE gauxc_finalize
365 FUNCTION gauxc_create_molecule(particle_set, status)
RESULT(res)
366 TYPE(
particle_type),
DIMENSION(:),
INTENT(IN) :: particle_set
367 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
368 TYPE(cp_gauxc_molecule_type) :: res
371 CHARACTER(LEN=2) :: element_symbol
372 INTEGER :: atomic_number, i, natoms
374 TYPE(gauxc_atom_type),
ALLOCATABLE,
DIMENSION(:) :: atoms
376 natoms =
SIZE(particle_set)
377 ALLOCATE (atoms(natoms))
380 atomic_kind => particle_set(i)%atomic_kind
383 atoms(i)%atomic_number = int(atomic_number, c_int64_t)
384 atoms(i)%x = real(particle_set(i)%r(1), c_double)
385 atoms(i)%y = real(particle_set(i)%r(2), c_double)
386 atoms(i)%z = real(particle_set(i)%r(3), c_double)
389 res%molecule = gauxc_molecule_new_from_atoms(status%status, atoms, int(natoms, c_size_t))
390 gauxc_return_if_error(status)
394 mark_used(particle_set)
397 cpabort(no_gauxc_message)
399 END FUNCTION gauxc_create_molecule
408 FUNCTION gauxc_create_basisset(qs_kind_set, particle_set, status)
RESULT(res)
410 POINTER :: qs_kind_set
411 TYPE(
particle_type),
DIMENSION(:),
INTENT(IN) :: particle_set
412 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
413 TYPE(cp_gauxc_basisset_type) :: res
416 INTEGER :: iatom, ikind, iprim, iset, ishell, lval, &
417 nkind, npgf, nset, nshell, &
418 nshell_total, shell_index, natoms
419 REAL(c_double),
DIMENSION(3) :: shell_origin
421 TYPE(gauxc_shell_type),
ALLOCATABLE,
DIMENSION(:) :: shells
425 nkind =
SIZE(qs_kind_set)
426 natoms =
SIZE(particle_set)
428 ALLOCATE (basis_set_list(nkind))
433 atomic_kind => particle_set(iatom)%atomic_kind
435 gto_basis => basis_set_list(ikind)%gto_basis_set
436 cpassert(
ASSOCIATED(gto_basis))
438 nshell_total = nshell_total + sum(gto_basis%nshell)
441 ALLOCATE (shells(nshell_total))
446 atomic_kind => particle_set(iatom)%atomic_kind
448 gto_basis => basis_set_list(ikind)%gto_basis_set
449 cpassert(
ASSOCIATED(gto_basis))
451 shell_origin(1) = real(particle_set(iatom)%r(1), c_double)
452 shell_origin(2) = real(particle_set(iatom)%r(2), c_double)
453 shell_origin(3) = real(particle_set(iatom)%r(3), c_double)
455 nset = gto_basis%nset
456 cpassert(nset ==
SIZE(gto_basis%nshell))
458 nshell = gto_basis%nshell(iset)
459 npgf = gto_basis%npgf(iset)
461 DO ishell = 1, gto_basis%nshell(iset)
462 shell_index = shell_index + 1
463 lval = gto_basis%l(ishell, iset)
464 res%max_l = max(res%max_l, lval)
465 shells(shell_index)%l = int(lval, c_int32_t)
468 shells(shell_index)%pure = .true._c_bool
469 shells(shell_index)%nprim = int(npgf, c_int32_t)
470 shells(shell_index)%origin = shell_origin
473 shells(shell_index)%exponents(iprim) = &
474 REAL(gto_basis%zet(iprim, iset), c_double)
475 shells(shell_index)%coefficients(iprim) = &
476 REAL(gto_basis%norm_cgf(gto_basis%first_cgf(ishell, iset))* &
477 gto_basis%gcc(iprim, ishell, iset), c_double)
483 res%basis = gauxc_basisset_new_from_shells( &
487 gauxc_return_if_error(status)
490 DEALLOCATE (basis_set_list)
493 mark_used(particle_set)
494 mark_used(qs_kind_set)
497 cpabort(no_gauxc_message)
499 END FUNCTION gauxc_create_basisset
519 FUNCTION gauxc_create_grid( &
527 device_runtime_fill_fraction, &
531 int_exec_space)
RESULT(res)
533 TYPE(cp_gauxc_molecule_type),
INTENT(IN) :: molecule
534 TYPE(cp_gauxc_basisset_type),
INTENT(IN) :: basis
535 CHARACTER(LEN=*) :: grid_type, lb_exec_space, &
536 pruning_scheme, radial_quadrature
537 INTEGER :: batch_size
538 REAL(c_double),
INTENT(IN) :: device_runtime_fill_fraction
539 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
540 INTEGER,
INTENT(IN),
OPTIONAL :: mpi_comm
541 LOGICAL,
INTENT(IN),
OPTIONAL :: force_new_runtime
542 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: int_exec_space
543 TYPE(cp_gauxc_grid_type) :: res
546 INTEGER(c_int) :: grid_type_local, int_exec_space_local, &
547 int_exec_requested, &
548 lb_exec_space_local, &
549 pruning_scheme_local, radial_quad_local
550 LOGICAL :: force_new_runtime_local, &
553 grid_type_local = read_atomic_grid_size(grid_type)
554 radial_quad_local = read_radial_quad(radial_quadrature)
555 pruning_scheme_local = read_pruning_scheme(pruning_scheme)
556 lb_exec_space_local = read_execution_space(lb_exec_space)
557 int_exec_requested = read_execution_space(
"host")
558 IF (
PRESENT(int_exec_space)) int_exec_requested = read_execution_space(int_exec_space)
559 use_device_runtime = (lb_exec_space_local == gauxc_executionspace%device) .OR. &
560 (int_exec_requested == gauxc_executionspace%device)
561 IF (use_device_runtime)
THEN
562 int_exec_space_local = gauxc_executionspace%device
564 int_exec_space_local = gauxc_executionspace%host
566#if defined(GAUXC_HAS_DEVICE) && defined(__LIBTORCH)
567 IF (use_device_runtime)
THEN
569 CALL cp_abort(__location__, &
570 "GPU execution was requested for GauXC, but no usable CUDA device was found. "// &
571 "Set GAUXC%USE_GPU HOST to force host-only execution.")
575 force_new_runtime_local = .false.
576 IF (
PRESENT(force_new_runtime)) force_new_runtime_local = force_new_runtime
577 res%owns_rt = .false.
578 res%uses_device_runtime = .false.
580 IF (use_device_runtime)
THEN
581#ifdef GAUXC_HAS_DEVICE
582#if defined(GAUXC_HAS_MPI) && defined(__parallel)
583 IF (
PRESENT(mpi_comm))
THEN
584 res%rt = gauxc_device_runtime_environment_new( &
585 status%status, mpi_comm, device_runtime_fill_fraction)
587 res%rt = gauxc_device_runtime_environment_new( &
588 status%status, device_runtime_fill_fraction)
592 res%rt = gauxc_device_runtime_environment_new( &
593 status%status, device_runtime_fill_fraction)
595 gauxc_return_if_error(status)
597 res%uses_device_runtime = .true.
599 mark_used(device_runtime_fill_fraction)
600 cpabort(
"GauXC was built without device runtime support")
603#if defined(GAUXC_HAS_MPI) && defined(__parallel)
604 IF (
PRESENT(mpi_comm))
THEN
607 IF (force_new_runtime_local .OR. .NOT. rt_has_mpi_comm .OR. &
608 mpi_comm /= rt_mpi_comm)
THEN
609 res%rt = gauxc_runtime_environment_new(status%status, mpi_comm)
610 gauxc_return_if_error(status)
616 mark_used(force_new_runtime)
620 res%grid = gauxc_molgrid_new_default( &
623 pruning_scheme_local, &
624 int(batch_size, c_int64_t), &
627 gauxc_return_if_error(status)
629 res%lbf = gauxc_load_balancer_factory_new( &
632 gauxc_return_if_error(status)
634 IF (res%owns_rt)
THEN
635 res%lb = gauxc_load_balancer_factory_get_instance( &
643 res%lb = gauxc_load_balancer_factory_get_instance( &
651 gauxc_return_if_error(status)
653 res%mwf = gauxc_molecular_weights_factory_new( &
655 int_exec_space_local)
656 gauxc_return_if_error(status)
658 res%mw = gauxc_get_instance( &
661 gauxc_return_if_error(status)
663 CALL gauxc_molecular_weights_modify_weights( &
667 gauxc_return_if_error(status)
671 mark_used(batch_size)
672 mark_used(device_runtime_fill_fraction)
674 mark_used(int_exec_space)
675 mark_used(lb_exec_space)
677 mark_used(force_new_runtime)
678 mark_used(int_exec_space)
680 mark_used(pruning_scheme)
681 mark_used(radial_quadrature)
684 cpabort(no_gauxc_message)
686 END FUNCTION gauxc_create_grid
698 FUNCTION gauxc_create_integrator( &
699 xc_functional_name, &
706 CHARACTER(LEN=*),
INTENT(IN) :: xc_functional_name, int_exec_space, &
708 TYPE(cp_gauxc_grid_type),
INTENT(IN) :: grid
709 INTEGER,
INTENT(IN) :: nspins
710 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
711 TYPE(cp_gauxc_integrator_type) :: res
714 INTEGER(c_int) :: int_exec_space_local
715 LOGICAL(c_bool) :: polarized
717 polarized = (nspins == 2)
718 res%func = gauxc_functional_from_string( &
720 xc_functional_name, &
722 gauxc_return_if_error(status)
724 int_exec_space_local = read_execution_space(int_exec_space)
725 res%integrator = gauxc_integrator_new( &
729 int_exec_space_local, &
730 local_work_kernel_name=trim(lwd_kernel))
731 gauxc_return_if_error(status)
735 mark_used(int_exec_space)
736 mark_used(lwd_kernel)
740 mark_used(xc_functional_name)
741 cpabort(no_gauxc_message)
743 END FUNCTION gauxc_create_integrator
755 FUNCTION gauxc_compute_xc( &
763 TYPE(cp_gauxc_integrator_type),
INTENT(IN) :: integrator
764 REAL(c_double),
DIMENSION(:, :),
INTENT(IN) :: density_scalar
765 REAL(c_double),
DIMENSION(:, :),
INTENT(IN), &
766 OPTIONAL :: density_zeta
767 INTEGER,
INTENT(IN) :: nspins
768 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
769 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: model
770 TYPE(cp_gauxc_xc_type) :: res
773 CHARACTER(LEN=default_path_length) :: model_key
774 LOGICAL :: use_gauxc_model
775 REAL(c_double),
ALLOCATABLE,
DIMENSION(:, :) :: density_scalar_rks
776#ifdef GAUXC_HAS_ONEDFT
777 REAL(c_double),
ALLOCATABLE,
DIMENSION(:, :) :: density_zeta_zero
778#if defined (__HAS_IEEE_EXCEPTIONS)
779 LOGICAL,
DIMENSION(5) :: ieee_halt
781 INTEGER :: omp_max_threads_restore
784 use_gauxc_model = .false.
785 IF (
PRESENT(model))
THEN
786 model_key = adjustl(model)
788 use_gauxc_model = (trim(model_key) /=
"" .AND. trim(model_key) /=
"NONE")
791 IF (.NOT.
ALLOCATED(res%vxc_scalar))
THEN
792 ALLOCATE (res%vxc_scalar, mold=density_scalar)
794 cpassert(all(shape(res%vxc_scalar) == shape(density_scalar)))
796 res%vxc_scalar = 0._dp
798 IF (use_gauxc_model)
THEN
799#ifndef GAUXC_HAS_ONEDFT
800 cpabort(
"GauXC lacks Skala support")
804 omp_max_threads_restore = omp_get_max_threads()
805#if defined (__HAS_IEEE_EXCEPTIONS)
806 CALL ieee_get_halting_mode(ieee_all, ieee_halt)
807 CALL ieee_set_halting_mode(ieee_all, .false.)
809 IF (.NOT.
ALLOCATED(res%vxc_zeta))
THEN
810 ALLOCATE (res%vxc_zeta, mold=density_scalar)
812 cpassert(all(shape(res%vxc_zeta) == shape(density_scalar)))
816 IF (nspins == 1)
THEN
817 ALLOCATE (density_zeta_zero, mold=density_scalar)
818 density_zeta_zero = 0._dp
819 CALL gauxc_integrator_eval_exc_vxc_onedft_uks( &
828 DEALLOCATE (density_zeta_zero)
830 cpassert(
PRESENT(density_zeta))
831 CALL gauxc_integrator_eval_exc_vxc_onedft_uks( &
841#if defined (__HAS_IEEE_EXCEPTIONS)
842 CALL ieee_set_halting_mode(ieee_all, ieee_halt)
844 CALL omp_set_num_threads(omp_max_threads_restore)
845 gauxc_return_if_error(status)
850 IF (nspins == 1)
THEN
854 ALLOCATE (density_scalar_rks, mold=density_scalar)
855 density_scalar_rks(:, :) = 0.5_dp*density_scalar
856 CALL gauxc_integrator_eval_exc_vxc_rks( &
859 density_scalar_rks, &
862 DEALLOCATE (density_scalar_rks)
864 cpassert(
PRESENT(density_zeta))
866 IF (.NOT.
ALLOCATED(res%vxc_zeta))
THEN
867 ALLOCATE (res%vxc_zeta, mold=density_zeta)
869 cpassert(all(shape(res%vxc_zeta) == shape(density_scalar)))
873 CALL gauxc_integrator_eval_exc_vxc_uks( &
882 gauxc_return_if_error(status)
886 mark_used(density_scalar)
887 mark_used(density_zeta)
891 cpabort(no_gauxc_message)
893 END FUNCTION gauxc_compute_xc
906 FUNCTION gauxc_compute_xc_gradient( &
915 TYPE(cp_gauxc_integrator_type),
INTENT(IN) :: integrator
916 REAL(c_double),
DIMENSION(:, :),
INTENT(IN) :: density_scalar
917 REAL(c_double),
DIMENSION(:, :),
INTENT(IN), &
918 OPTIONAL :: density_zeta
919 INTEGER,
INTENT(IN) :: nspins, natom
920 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
921 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: model
922 TYPE(cp_gauxc_xc_gradient_type) :: res
925 CHARACTER(LEN=default_path_length) :: model_key
926 LOGICAL :: use_gauxc_model
927 REAL(c_double),
ALLOCATABLE,
DIMENSION(:, :) :: density_scalar_rks
928#ifdef GAUXC_HAS_ONEDFT
929 REAL(c_double),
ALLOCATABLE,
DIMENSION(:, :) :: density_zeta_zero
930#if defined (__HAS_IEEE_EXCEPTIONS)
931 LOGICAL,
DIMENSION(5) :: ieee_halt
933 INTEGER :: omp_max_threads_restore
936 ALLOCATE (res%exc_grad(3*natom))
939 use_gauxc_model = .false.
940 IF (
PRESENT(model))
THEN
941 model_key = adjustl(model)
943 use_gauxc_model = (trim(model_key) /=
"" .AND. trim(model_key) /=
"NONE")
946 IF (use_gauxc_model)
THEN
947#ifndef GAUXC_HAS_ONEDFT
948 cpabort(
"GauXC lacks Skala support")
952 omp_max_threads_restore = omp_get_max_threads()
953#if defined (__HAS_IEEE_EXCEPTIONS)
954 CALL ieee_get_halting_mode(ieee_all, ieee_halt)
955 CALL ieee_set_halting_mode(ieee_all, .false.)
957 IF (nspins == 1)
THEN
958 ALLOCATE (density_zeta_zero, mold=density_scalar)
959 density_zeta_zero = 0._dp
960 CALL gauxc_integrator_eval_exc_grad_onedft_uks( &
967 DEALLOCATE (density_zeta_zero)
969 cpassert(
PRESENT(density_zeta))
970 CALL gauxc_integrator_eval_exc_grad_onedft_uks( &
978#if defined (__HAS_IEEE_EXCEPTIONS)
979 CALL ieee_set_halting_mode(ieee_all, ieee_halt)
981 CALL omp_set_num_threads(omp_max_threads_restore)
982 gauxc_return_if_error(status)
987 IF (nspins == 1)
THEN
988 ALLOCATE (density_scalar_rks, mold=density_scalar)
989 density_scalar_rks(:, :) = 0.5_dp*density_scalar
990 CALL gauxc_integrator_eval_exc_grad_rks( &
993 density_scalar_rks, &
995 DEALLOCATE (density_scalar_rks)
997 cpassert(
PRESENT(density_zeta))
998 CALL gauxc_integrator_eval_exc_grad_uks( &
1005 gauxc_return_if_error(status)
1008 mark_used(density_scalar)
1009 mark_used(density_zeta)
1016 cpabort(no_gauxc_message)
1018 END FUNCTION gauxc_compute_xc_gradient
1025 SUBROUTINE gauxc_destroy_molecule(molecule, status)
1026 TYPE(cp_gauxc_molecule_type),
INTENT(INOUT) :: molecule
1027 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
1030 CALL gauxc_delete(status%status, molecule%molecule)
1031 gauxc_return_if_error(status)
1035 cpabort(no_gauxc_message)
1037 END SUBROUTINE gauxc_destroy_molecule
1044 SUBROUTINE gauxc_destroy_basisset(basis, status)
1045 TYPE(cp_gauxc_basisset_type),
INTENT(INOUT) :: basis
1046 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
1049 CALL gauxc_delete(status%status, basis%basis)
1050 gauxc_return_if_error(status)
1054 cpabort(no_gauxc_message)
1056 END SUBROUTINE gauxc_destroy_basisset
1063 SUBROUTINE gauxc_destroy_grid(grid_result, status)
1064 TYPE(cp_gauxc_grid_type),
INTENT(INOUT) :: grid_result
1065 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
1068 CALL gauxc_delete(status%status, grid_result%mw)
1069 gauxc_return_if_error(status)
1070 CALL gauxc_delete(status%status, grid_result%mwf)
1071 gauxc_return_if_error(status)
1072 CALL gauxc_delete(status%status, grid_result%lb)
1073 gauxc_return_if_error(status)
1074 CALL gauxc_delete(status%status, grid_result%lbf)
1075 gauxc_return_if_error(status)
1076 CALL gauxc_delete(status%status, grid_result%grid)
1077 gauxc_return_if_error(status)
1078 IF (grid_result%owns_rt)
THEN
1079 CALL gauxc_runtime_environment_delete(status%status, grid_result%rt)
1080 gauxc_return_if_error(status)
1081 grid_result%owns_rt = .false.
1084 mark_used(grid_result)
1086 cpabort(no_gauxc_message)
1088 END SUBROUTINE gauxc_destroy_grid
1095 SUBROUTINE gauxc_destroy_integrator(integrator_result, status)
1096 TYPE(cp_gauxc_integrator_type),
INTENT(INOUT) :: integrator_result
1097 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
1100 CALL gauxc_delete(status%status, integrator_result%integrator)
1101 gauxc_return_if_error(status)
1102 CALL gauxc_delete(status%status, integrator_result%func)
1103 gauxc_return_if_error(status)
1105 mark_used(integrator_result)
1107 cpabort(no_gauxc_message)
1109 END SUBROUTINE gauxc_destroy_integrator
1115 SUBROUTINE gauxc_check_status(status)
1116 TYPE(cp_gauxc_status_type),
INTENT(IN) :: status
1119 IF (status%status%code /= 0)
THEN
1121 cpabort(
"GauXC returned with non-zero status code")
1126 END SUBROUTINE gauxc_check_status
1139 PURE FUNCTION read_execution_space(spec)
RESULT(val)
1140 CHARACTER(LEN=*),
INTENT(IN) :: spec
1141 INTEGER(c_int) :: val
1143 CHARACTER(LEN=LEN(spec)) :: spec_upper
1148 SELECT CASE (spec_upper)
1150 val = gauxc_executionspace%host
1152 val = gauxc_executionspace%device
1154 val = gauxc_executionspace%host
1156 END FUNCTION read_execution_space
1163 PURE FUNCTION read_atomic_grid_size(spec)
RESULT(val)
1164 CHARACTER(LEN=*),
INTENT(IN) :: spec
1165 INTEGER(c_int) :: val
1167 CHARACTER(LEN=LEN(spec)) :: spec_upper
1172 SELECT CASE (spec_upper)
1174 val = gauxc_atomicgridsizedefault%finegrid
1176 val = gauxc_atomicgridsizedefault%ultrafinegrid
1178 val = gauxc_atomicgridsizedefault%superfinegrid
1180 val = gauxc_atomicgridsizedefault%gm3
1182 val = gauxc_atomicgridsizedefault%gm5
1184 val = gauxc_atomicgridsizedefault%finegrid
1186 END FUNCTION read_atomic_grid_size
1193 PURE FUNCTION read_radial_quad(spec)
RESULT(val)
1194 CHARACTER(LEN=*),
INTENT(IN) :: spec
1195 INTEGER(c_int) :: val
1197 CHARACTER(LEN=LEN(spec)) :: spec_upper
1202 SELECT CASE (spec_upper)
1204 val = gauxc_radialquad%becke
1205 CASE (
"MURAKNOWLES")
1206 val = gauxc_radialquad%mura_knowles
1207 CASE (
"TREUTLERAHLRICHS")
1208 val = gauxc_radialquad%treutler_ahlrichs
1209 CASE (
"MURRAYHANDYLAMING")
1210 val = gauxc_radialquad%murray_handy_laming
1212 val = gauxc_radialquad%mura_knowles
1214 END FUNCTION read_radial_quad
1221 PURE FUNCTION read_pruning_scheme(spec)
RESULT(val)
1222 CHARACTER(LEN=*),
INTENT(IN) :: spec
1223 INTEGER(c_int) :: val
1225 CHARACTER(LEN=LEN(spec)) :: spec_upper
1230 SELECT CASE (spec_upper)
1232 val = gauxc_pruningscheme%unpruned
1234 val = gauxc_pruningscheme%robust
1236 val = gauxc_pruningscheme%treutler
1238 val = gauxc_pruningscheme%robust
1240 END FUNCTION read_pruning_scheme
1252 SUBROUTINE gauxc_write_molecule_hdf5(molecule, output_path, filename, dataset, status)
1253 TYPE(cp_gauxc_molecule_type),
INTENT(IN) :: molecule
1254 CHARACTER(LEN=*),
INTENT(IN) :: output_path, filename, dataset
1255 TYPE(cp_gauxc_status_type),
INTENT(INOUT) :: status
1257#if defined(__GAUXC) && defined(GAUXC_HAS_HDF5)
1258 CHARACTER(LEN=default_path_length) :: full_path
1260 full_path = trim(output_path)//
"/"//trim(filename)
1261 CALL gauxc_write_hdf5_record(status%status, molecule%molecule, full_path, dataset)
1264 mark_used(output_path)
1268 cpabort(
"GauXC HDF5 output requires GauXC to be built with HDF5 support.")
1270 END SUBROUTINE gauxc_write_molecule_hdf5
1280 SUBROUTINE gauxc_write_basisset_hdf5(basis, output_path, filename, dataset, status)
1281 TYPE(cp_gauxc_basisset_type),
INTENT(IN) :: basis
1282 CHARACTER(LEN=*),
INTENT(IN) :: output_path, filename, dataset
1283 TYPE(cp_gauxc_status_type),
INTENT(INOUT) :: status
1285#if defined(__GAUXC) && defined(GAUXC_HAS_HDF5)
1286 CHARACTER(LEN=default_path_length) :: full_path
1288 full_path = trim(output_path)//
"/"//trim(filename)
1289 CALL gauxc_write_hdf5_record(status%status, basis%basis, full_path, dataset)
1292 mark_used(output_path)
1296 cpabort(
"GauXC HDF5 output requires GauXC to be built with HDF5 support.")
1298 END SUBROUTINE gauxc_write_basisset_hdf5
1300END MODULE xc_gauxc_interface
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
subroutine, public write_gto_basis_set(gto_basis_set, output_unit, header)
Write a Gaussian-type orbital (GTO) basis set data set to the output unit.
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...
Provides integrator routines (velocity verlet) for all the ensemble types.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Define the data structure for the particle information.
Periodic Table related data definitions.
subroutine, public get_ptable_info(symbol, number, amass, ielement, covalent_radius, metallic_radius, vdw_radius, found)
Pass information about the kind given the element symbol.
Definition of physical constants:
real(kind=dp), parameter, public bohr
Some utility functions for the calculation of integrals.
subroutine, public basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
Set up an easy accessible list of the basis sets for all kinds.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
integer function, public torch_cuda_device_count()
Return the number of CUDA devices visible to Torch.
logical function, public torch_cuda_is_available()
Returns true iff the Torch CUDA backend is available.
Provides all information about an atomic kind.
Provides all information about a quickstep kind.
subroutine print_gauxc_status_message(status)
...