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 USE gauxc_molecule,
ONLY: &
85 gauxc_molecule_new_from_atoms, &
87 USE gauxc_atom,
ONLY: &
89 USE gauxc_basisset,
ONLY: &
91 gauxc_basisset_new_from_shells, &
92 gauxc_basisset_type, &
94 USE gauxc_shell,
ONLY: &
96 USE gauxc_molgrid,
ONLY: &
98 gauxc_molgrid_new_default, &
100 USE gauxc_load_balancer,
ONLY: &
102 gauxc_load_balancer_factory_get_instance, &
103 gauxc_load_balancer_factory_new, &
104 gauxc_load_balancer_factory_type, &
105 gauxc_load_balancer_type
106 USE gauxc_molecular_weights,
ONLY: &
108 gauxc_get_instance, &
109 gauxc_molecular_weights_factory_new, &
110 gauxc_molecular_weights_factory_type, &
111 gauxc_molecular_weights_modify_weights, &
112 gauxc_molecular_weights_settings, &
113 gauxc_molecular_weights_type
114 USE gauxc_xc_functional,
ONLY: &
116 gauxc_functional_from_string, &
117 gauxc_functional_type
118 USE gauxc_integrator,
ONLY: &
120 gauxc_integrator_eval_exc_grad_rks, &
121 gauxc_integrator_eval_exc_grad_uks, &
122 gauxc_integrator_eval_exc_vxc_rks, &
123 gauxc_integrator_eval_exc_vxc_uks, &
124 gauxc_integrator_new, &
125 gauxc_integrator_type
126#ifdef GAUXC_HAS_ONEDFT
127 USE gauxc_integrator,
ONLY: &
128 gauxc_integrator_eval_exc_grad_onedft_uks, &
129 gauxc_integrator_eval_exc_vxc_onedft_uks
131 omp_get_max_threads, &
135 USE gauxc_external_hdf5_write,
ONLY: &
136 gauxc_write_hdf5_record
142#include "../base/base_uses.f90"
151 TYPE cp_gauxc_molecule_type
152 END TYPE cp_gauxc_molecule_type
154 TYPE cp_gauxc_basisset_type
155 INTEGER :: max_l = -1
156 END TYPE cp_gauxc_basisset_type
158 TYPE cp_gauxc_grid_type
159 END TYPE cp_gauxc_grid_type
161 TYPE cp_gauxc_integrator_type
162 END TYPE cp_gauxc_integrator_type
164 TYPE cp_gauxc_status_type
165 END TYPE cp_gauxc_status_type
171 TYPE cp_gauxc_molecule_type
172 TYPE(gauxc_molecule_type) :: molecule
173 END TYPE cp_gauxc_molecule_type
175 TYPE cp_gauxc_basisset_type
176 TYPE(gauxc_basisset_type) :: basis
177 INTEGER :: max_l = -1
178 END TYPE cp_gauxc_basisset_type
180 TYPE cp_gauxc_grid_type
181 TYPE(gauxc_molgrid_type) :: grid
182 TYPE(gauxc_load_balancer_type) :: lb
183 TYPE(gauxc_load_balancer_factory_type) :: lbf
184 TYPE(gauxc_molecular_weights_type) :: mw
185 TYPE(gauxc_molecular_weights_factory_type) :: mwf
186 TYPE(gauxc_runtime_environment_type) :: rt
187 LOGICAL :: owns_rt = .false.
188 END TYPE cp_gauxc_grid_type
190 TYPE cp_gauxc_integrator_type
191 TYPE(gauxc_functional_type) :: func
193 END TYPE cp_gauxc_integrator_type
195 TYPE cp_gauxc_status_type
196 TYPE(gauxc_status_type) :: status
197 END TYPE cp_gauxc_status_type
199 TYPE(gauxc_runtime_environment_type) :: rt
200 INTEGER :: rt_mpi_comm = -1
201 LOGICAL :: rt_has_mpi_comm = .false.
205 TYPE cp_gauxc_xc_type
206 REAL(c_double) :: exc = 0.0_c_double
207 REAL(c_double),
DIMENSION(:, :),
ALLOCATABLE :: vxc_scalar, vxc_zeta
208 END TYPE cp_gauxc_xc_type
210 TYPE cp_gauxc_xc_gradient_type
211 REAL(c_double),
ALLOCATABLE,
DIMENSION(:) :: exc_grad
212 END TYPE cp_gauxc_xc_gradient_type
214 CHARACTER(len=*),
PARAMETER :: no_gauxc_message =
"Compile CP2K with GauXC to use this functionality!"
217 cp_gauxc_basisset_type, &
218 cp_gauxc_grid_type, &
219 cp_gauxc_integrator_type, &
220 cp_gauxc_molecule_type, &
221 cp_gauxc_status_type, &
222 cp_gauxc_xc_gradient_type, &
224 gauxc_check_status, &
225 gauxc_compute_xc_gradient, &
227 gauxc_create_basisset, &
229 gauxc_create_integrator, &
230 gauxc_create_molecule, &
231 gauxc_destroy_basisset, &
232 gauxc_destroy_grid, &
233 gauxc_destroy_integrator, &
234 gauxc_destroy_molecule, &
237 gauxc_write_basisset_hdf5, &
238 gauxc_write_molecule_hdf5
247 TYPE(cp_gauxc_status_type) :: status
250 CHARACTER(kind=c_char),
POINTER :: s(:)
251 CHARACTER(len=32) :: stderr_env
252 INTEGER :: i, ierr, iw
253 LOGICAL :: print_to_stderr
254 INTEGER,
PARAMETER :: status_message_length = 4096
258 CALL get_environment_variable(
"CP2K_GAUXC_STATUS_STDERR", stderr_env)
260 SELECT CASE (trim(stderr_env))
261 CASE (
"",
"0",
"FALSE",
"F",
"OFF",
"NO")
262 print_to_stderr = .false.
263 CASE (
"1",
"TRUE",
"T",
"ON",
"YES")
264 print_to_stderr = .true.
266 print_to_stderr = .true.
269 WRITE (unit=iw, fmt=
'(a,1x,i0)')
"GauXC returned with status code", status%status%code
270 IF (c_associated(status%status%message))
THEN
271 WRITE (unit=iw, fmt=
'(a)', advance=
'no')
"GauXC status message: ["
273 CALL c_f_pointer(status%status%message, s, [status_message_length])
275 IF (s(i) == c_null_char)
EXIT
276 WRITE (unit=iw, fmt=
'(A)', advance=
'no') s(i)
279 WRITE (unit=iw, fmt=
'(a)')
"]"
281 WRITE (unit=iw, fmt=
'(a)')
"GauXC status message: [null]"
284 IF (print_to_stderr)
THEN
285 WRITE (unit=ierr, fmt=
'(a,1x,i0)')
"GauXC returned with status code", status%status%code
286 IF (c_associated(status%status%message))
THEN
287 WRITE (unit=ierr, fmt=
'(a)', advance=
'no')
"GauXC status message: ["
289 CALL c_f_pointer(status%status%message, s, [status_message_length])
291 IF (s(i) == c_null_char)
EXIT
292 WRITE (unit=ierr, fmt=
'(A)', advance=
'no') s(i)
295 WRITE (unit=ierr, fmt=
'(a)')
"]"
297 WRITE (unit=ierr, fmt=
'(a)')
"GauXC status message: [null]"
310 SUBROUTINE gauxc_init(mpi_comm, status)
311 INTEGER,
INTENT(IN),
OPTIONAL :: mpi_comm
312 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
315#if defined(GAUXC_HAS_MPI) && defined(__parallel)
316 IF (
PRESENT(mpi_comm))
THEN
317 rt = gauxc_runtime_environment_new(status%status, mpi_comm)
318 rt_mpi_comm = mpi_comm
319 rt_has_mpi_comm = .true.
321 rt = gauxc_runtime_environment_new(status%status)
323 rt_has_mpi_comm = .false.
327 rt = gauxc_runtime_environment_new(status%status)
329 rt_has_mpi_comm = .false.
331 gauxc_return_if_error(status)
336 END SUBROUTINE gauxc_init
342 SUBROUTINE gauxc_finalize(status)
343 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
346 CALL gauxc_runtime_environment_delete(status%status, rt)
347 gauxc_return_if_error(status)
349 rt_has_mpi_comm = .false.
353 END SUBROUTINE gauxc_finalize
361 FUNCTION gauxc_create_molecule(particle_set, status)
RESULT(res)
362 TYPE(
particle_type),
DIMENSION(:),
INTENT(IN) :: particle_set
363 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
364 TYPE(cp_gauxc_molecule_type) :: res
367 CHARACTER(LEN=2) :: element_symbol
368 INTEGER :: atomic_number, i, natoms
370 TYPE(gauxc_atom_type),
ALLOCATABLE,
DIMENSION(:) :: atoms
372 natoms =
SIZE(particle_set)
373 ALLOCATE (atoms(natoms))
376 atomic_kind => particle_set(i)%atomic_kind
379 atoms(i)%atomic_number = int(atomic_number, c_int64_t)
380 atoms(i)%x = real(particle_set(i)%r(1), c_double)
381 atoms(i)%y = real(particle_set(i)%r(2), c_double)
382 atoms(i)%z = real(particle_set(i)%r(3), c_double)
385 res%molecule = gauxc_molecule_new_from_atoms(status%status, atoms, int(natoms, c_size_t))
386 gauxc_return_if_error(status)
390 mark_used(particle_set)
393 cpabort(no_gauxc_message)
395 END FUNCTION gauxc_create_molecule
404 FUNCTION gauxc_create_basisset(qs_kind_set, particle_set, status)
RESULT(res)
406 POINTER :: qs_kind_set
407 TYPE(
particle_type),
DIMENSION(:),
INTENT(IN) :: particle_set
408 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
409 TYPE(cp_gauxc_basisset_type) :: res
412 INTEGER :: iatom, ikind, iprim, iset, ishell, lval, &
413 nkind, npgf, nset, nshell, &
414 nshell_total, shell_index, natoms
415 REAL(c_double),
DIMENSION(3) :: shell_origin
417 TYPE(gauxc_shell_type),
ALLOCATABLE,
DIMENSION(:) :: shells
421 nkind =
SIZE(qs_kind_set)
422 natoms =
SIZE(particle_set)
424 ALLOCATE (basis_set_list(nkind))
429 atomic_kind => particle_set(iatom)%atomic_kind
431 gto_basis => basis_set_list(ikind)%gto_basis_set
432 cpassert(
ASSOCIATED(gto_basis))
434 nshell_total = nshell_total + sum(gto_basis%nshell)
437 ALLOCATE (shells(nshell_total))
442 atomic_kind => particle_set(iatom)%atomic_kind
444 gto_basis => basis_set_list(ikind)%gto_basis_set
445 cpassert(
ASSOCIATED(gto_basis))
447 shell_origin(1) = real(particle_set(iatom)%r(1), c_double)
448 shell_origin(2) = real(particle_set(iatom)%r(2), c_double)
449 shell_origin(3) = real(particle_set(iatom)%r(3), c_double)
451 nset = gto_basis%nset
452 cpassert(nset ==
SIZE(gto_basis%nshell))
454 nshell = gto_basis%nshell(iset)
455 npgf = gto_basis%npgf(iset)
457 DO ishell = 1, gto_basis%nshell(iset)
458 shell_index = shell_index + 1
459 lval = gto_basis%l(ishell, iset)
460 res%max_l = max(res%max_l, lval)
461 shells(shell_index)%l = int(lval, c_int32_t)
464 shells(shell_index)%pure = .true._c_bool
465 shells(shell_index)%nprim = int(npgf, c_int32_t)
466 shells(shell_index)%origin = shell_origin
469 shells(shell_index)%exponents(iprim) = &
470 REAL(gto_basis%zet(iprim, iset), c_double)
471 shells(shell_index)%coefficients(iprim) = &
472 REAL(gto_basis%norm_cgf(gto_basis%first_cgf(ishell, iset))* &
473 gto_basis%gcc(iprim, ishell, iset), c_double)
479 res%basis = gauxc_basisset_new_from_shells( &
483 gauxc_return_if_error(status)
486 DEALLOCATE (basis_set_list)
489 mark_used(particle_set)
490 mark_used(qs_kind_set)
493 cpabort(no_gauxc_message)
495 END FUNCTION gauxc_create_basisset
512 FUNCTION gauxc_create_grid( &
520 device_runtime_fill_fraction, &
523 force_new_runtime)
RESULT(res)
525 TYPE(cp_gauxc_molecule_type),
INTENT(IN) :: molecule
526 TYPE(cp_gauxc_basisset_type),
INTENT(in) :: basis
527 CHARACTER(len=*) :: grid_type, lb_exec_space, &
528 pruning_scheme, radial_quadrature
529 INTEGER :: batch_size
530 REAL(c_double),
INTENT(IN) :: device_runtime_fill_fraction
531 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
532 INTEGER,
INTENT(IN),
OPTIONAL :: mpi_comm
533 LOGICAL,
INTENT(IN),
OPTIONAL :: force_new_runtime
534 TYPE(cp_gauxc_grid_type) :: res
537 INTEGER(c_int) :: grid_type_local, int_exec_space_local, &
538 lb_exec_space_local, &
539 pruning_scheme_local, radial_quad_local
540 LOGICAL :: force_new_runtime_local, use_device_runtime
542 grid_type_local = read_atomic_grid_size(grid_type)
543 radial_quad_local = read_radial_quad(radial_quadrature)
544 pruning_scheme_local = read_pruning_scheme(pruning_scheme)
545 lb_exec_space_local = read_execution_space(lb_exec_space)
546 int_exec_space_local = read_execution_space(
"host")
547 use_device_runtime = (lb_exec_space_local == gauxc_executionspace%device)
548 force_new_runtime_local = .false.
549 IF (
PRESENT(force_new_runtime)) force_new_runtime_local = force_new_runtime
550 res%owns_rt = .false.
552 IF (use_device_runtime)
THEN
553#ifdef GAUXC_HAS_DEVICE
554#if defined(GAUXC_HAS_MPI) && defined(__parallel)
555 IF (
PRESENT(mpi_comm))
THEN
556 res%rt = gauxc_device_runtime_environment_new( &
557 status%status, mpi_comm, device_runtime_fill_fraction)
559 res%rt = gauxc_device_runtime_environment_new( &
560 status%status, device_runtime_fill_fraction)
564 res%rt = gauxc_device_runtime_environment_new( &
565 status%status, device_runtime_fill_fraction)
567 gauxc_return_if_error(status)
570 mark_used(device_runtime_fill_fraction)
571 cpabort(
"GauXC was built without device runtime support")
574#if defined(GAUXC_HAS_MPI) && defined(__parallel)
575 IF (
PRESENT(mpi_comm))
THEN
578 IF (force_new_runtime_local .OR. .NOT. rt_has_mpi_comm .OR. &
579 mpi_comm /= rt_mpi_comm)
THEN
580 res%rt = gauxc_runtime_environment_new(status%status, mpi_comm)
581 gauxc_return_if_error(status)
587 mark_used(force_new_runtime)
591 res%grid = gauxc_molgrid_new_default( &
594 pruning_scheme_local, &
595 int(batch_size, c_int64_t), &
598 gauxc_return_if_error(status)
600 res%lbf = gauxc_load_balancer_factory_new( &
603 gauxc_return_if_error(status)
605 IF (res%owns_rt)
THEN
606 res%lb = gauxc_load_balancer_factory_get_instance( &
614 res%lb = gauxc_load_balancer_factory_get_instance( &
622 gauxc_return_if_error(status)
624 res%mwf = gauxc_molecular_weights_factory_new( &
626 int_exec_space_local)
627 gauxc_return_if_error(status)
629 res%mw = gauxc_get_instance( &
632 gauxc_return_if_error(status)
634 CALL gauxc_molecular_weights_modify_weights( &
638 gauxc_return_if_error(status)
642 mark_used(batch_size)
643 mark_used(device_runtime_fill_fraction)
645 mark_used(lb_exec_space)
647 mark_used(force_new_runtime)
649 mark_used(pruning_scheme)
650 mark_used(radial_quadrature)
653 cpabort(no_gauxc_message)
655 END FUNCTION gauxc_create_grid
667 FUNCTION gauxc_create_integrator( &
668 xc_functional_name, &
675 CHARACTER(len=*),
INTENT(IN) :: xc_functional_name, int_exec_space, &
677 TYPE(cp_gauxc_grid_type),
INTENT(IN) :: grid
678 INTEGER,
INTENT(IN) :: nspins
679 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
680 TYPE(cp_gauxc_integrator_type) :: res
683 INTEGER(c_int) :: int_exec_space_local
684 LOGICAL(c_bool) :: polarized
686 polarized = (nspins == 2)
687 res%func = gauxc_functional_from_string( &
689 xc_functional_name, &
691 gauxc_return_if_error(status)
693 int_exec_space_local = read_execution_space(int_exec_space)
694 res%integrator = gauxc_integrator_new( &
698 int_exec_space_local, &
699 local_work_kernel_name=trim(lwd_kernel))
700 gauxc_return_if_error(status)
704 mark_used(int_exec_space)
705 mark_used(lwd_kernel)
709 mark_used(xc_functional_name)
710 cpabort(no_gauxc_message)
712 END FUNCTION gauxc_create_integrator
724 FUNCTION gauxc_compute_xc( &
732 TYPE(cp_gauxc_integrator_type),
INTENT(IN) :: integrator
733 REAL(c_double),
DIMENSION(:, :),
INTENT(IN) :: density_scalar
734 REAL(c_double),
DIMENSION(:, :),
INTENT(IN), &
735 OPTIONAL :: density_zeta
736 INTEGER,
INTENT(IN) :: nspins
737 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
738 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: model
739 TYPE(cp_gauxc_xc_type) :: res
742 CHARACTER(len=default_path_length) :: model_key
743 LOGICAL :: use_gauxc_model
744 REAL(c_double),
ALLOCATABLE,
DIMENSION(:, :) :: density_scalar_rks
745#ifdef GAUXC_HAS_ONEDFT
746 REAL(c_double),
ALLOCATABLE,
DIMENSION(:, :) :: density_zeta_zero
747#if defined (__HAS_IEEE_EXCEPTIONS)
748 LOGICAL,
DIMENSION(5) :: ieee_halt
750 INTEGER :: omp_max_threads_restore
753 use_gauxc_model = .false.
754 IF (
PRESENT(model))
THEN
755 model_key = adjustl(model)
757 use_gauxc_model = (trim(model_key) /=
"" .AND. trim(model_key) /=
"NONE")
760 IF (.NOT.
ALLOCATED(res%vxc_scalar))
THEN
761 ALLOCATE (res%vxc_scalar, mold=density_scalar)
763 cpassert(all(shape(res%vxc_scalar) == shape(density_scalar)))
765 res%vxc_scalar = 0._dp
767 IF (use_gauxc_model)
THEN
768#ifndef GAUXC_HAS_ONEDFT
769 cpabort(
"GauXC lacks Skala support")
773 omp_max_threads_restore = omp_get_max_threads()
774#if defined (__HAS_IEEE_EXCEPTIONS)
775 CALL ieee_get_halting_mode(ieee_all, ieee_halt)
776 CALL ieee_set_halting_mode(ieee_all, .false.)
778 IF (.NOT.
ALLOCATED(res%vxc_zeta))
THEN
779 ALLOCATE (res%vxc_zeta, mold=density_scalar)
781 cpassert(all(shape(res%vxc_zeta) == shape(density_scalar)))
785 IF (nspins == 1)
THEN
786 ALLOCATE (density_zeta_zero, mold=density_scalar)
787 density_zeta_zero = 0._dp
788 CALL gauxc_integrator_eval_exc_vxc_onedft_uks( &
797 DEALLOCATE (density_zeta_zero)
799 cpassert(
PRESENT(density_zeta))
800 CALL gauxc_integrator_eval_exc_vxc_onedft_uks( &
810#if defined (__HAS_IEEE_EXCEPTIONS)
811 CALL ieee_set_halting_mode(ieee_all, ieee_halt)
813 CALL omp_set_num_threads(omp_max_threads_restore)
814 gauxc_return_if_error(status)
819 IF (nspins == 1)
THEN
823 ALLOCATE (density_scalar_rks, mold=density_scalar)
824 density_scalar_rks(:, :) = 0.5_dp*density_scalar
825 CALL gauxc_integrator_eval_exc_vxc_rks( &
828 density_scalar_rks, &
831 DEALLOCATE (density_scalar_rks)
833 cpassert(
PRESENT(density_zeta))
835 IF (.NOT.
ALLOCATED(res%vxc_zeta))
THEN
836 ALLOCATE (res%vxc_zeta, mold=density_zeta)
838 cpassert(all(shape(res%vxc_zeta) == shape(density_scalar)))
842 CALL gauxc_integrator_eval_exc_vxc_uks( &
851 gauxc_return_if_error(status)
855 mark_used(density_scalar)
856 mark_used(density_zeta)
860 cpabort(no_gauxc_message)
862 END FUNCTION gauxc_compute_xc
875 FUNCTION gauxc_compute_xc_gradient( &
884 TYPE(cp_gauxc_integrator_type),
INTENT(IN) :: integrator
885 REAL(c_double),
DIMENSION(:, :),
INTENT(IN) :: density_scalar
886 REAL(c_double),
DIMENSION(:, :),
INTENT(IN), &
887 OPTIONAL :: density_zeta
888 INTEGER,
INTENT(IN) :: nspins, natom
889 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
890 CHARACTER(len=*),
INTENT(IN),
OPTIONAL :: model
891 TYPE(cp_gauxc_xc_gradient_type) :: res
894 CHARACTER(len=default_path_length) :: model_key
895 LOGICAL :: use_gauxc_model
896 REAL(c_double),
ALLOCATABLE,
DIMENSION(:, :) :: density_scalar_rks
897#ifdef GAUXC_HAS_ONEDFT
898 REAL(c_double),
ALLOCATABLE,
DIMENSION(:, :) :: density_zeta_zero
899#if defined (__HAS_IEEE_EXCEPTIONS)
900 LOGICAL,
DIMENSION(5) :: ieee_halt
902 INTEGER :: omp_max_threads_restore
905 ALLOCATE (res%exc_grad(3*natom))
908 use_gauxc_model = .false.
909 IF (
PRESENT(model))
THEN
910 model_key = adjustl(model)
912 use_gauxc_model = (trim(model_key) /=
"" .AND. trim(model_key) /=
"NONE")
915 IF (use_gauxc_model)
THEN
916#ifndef GAUXC_HAS_ONEDFT
917 cpabort(
"GauXC lacks Skala support")
921 omp_max_threads_restore = omp_get_max_threads()
922#if defined (__HAS_IEEE_EXCEPTIONS)
923 CALL ieee_get_halting_mode(ieee_all, ieee_halt)
924 CALL ieee_set_halting_mode(ieee_all, .false.)
926 IF (nspins == 1)
THEN
927 ALLOCATE (density_zeta_zero, mold=density_scalar)
928 density_zeta_zero = 0._dp
929 CALL gauxc_integrator_eval_exc_grad_onedft_uks( &
936 DEALLOCATE (density_zeta_zero)
938 cpassert(
PRESENT(density_zeta))
939 CALL gauxc_integrator_eval_exc_grad_onedft_uks( &
947#if defined (__HAS_IEEE_EXCEPTIONS)
948 CALL ieee_set_halting_mode(ieee_all, ieee_halt)
950 CALL omp_set_num_threads(omp_max_threads_restore)
951 gauxc_return_if_error(status)
956 IF (nspins == 1)
THEN
957 ALLOCATE (density_scalar_rks, mold=density_scalar)
958 density_scalar_rks(:, :) = 0.5_dp*density_scalar
959 CALL gauxc_integrator_eval_exc_grad_rks( &
962 density_scalar_rks, &
964 DEALLOCATE (density_scalar_rks)
966 cpassert(
PRESENT(density_zeta))
967 CALL gauxc_integrator_eval_exc_grad_uks( &
974 gauxc_return_if_error(status)
977 mark_used(density_scalar)
978 mark_used(density_zeta)
985 cpabort(no_gauxc_message)
987 END FUNCTION gauxc_compute_xc_gradient
994 SUBROUTINE gauxc_destroy_molecule(molecule, status)
995 TYPE(cp_gauxc_molecule_type),
INTENT(INOUT) :: molecule
996 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
999 CALL gauxc_delete(status%status, molecule%molecule)
1000 gauxc_return_if_error(status)
1004 cpabort(no_gauxc_message)
1006 END SUBROUTINE gauxc_destroy_molecule
1013 SUBROUTINE gauxc_destroy_basisset(basis, status)
1014 TYPE(cp_gauxc_basisset_type),
INTENT(INOUT) :: basis
1015 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
1018 CALL gauxc_delete(status%status, basis%basis)
1019 gauxc_return_if_error(status)
1023 cpabort(no_gauxc_message)
1025 END SUBROUTINE gauxc_destroy_basisset
1032 SUBROUTINE gauxc_destroy_grid(grid_result, status)
1033 TYPE(cp_gauxc_grid_type),
INTENT(INOUT) :: grid_result
1034 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
1037 CALL gauxc_delete(status%status, grid_result%mw)
1038 gauxc_return_if_error(status)
1039 CALL gauxc_delete(status%status, grid_result%mwf)
1040 gauxc_return_if_error(status)
1041 CALL gauxc_delete(status%status, grid_result%lb)
1042 gauxc_return_if_error(status)
1043 CALL gauxc_delete(status%status, grid_result%lbf)
1044 gauxc_return_if_error(status)
1045 CALL gauxc_delete(status%status, grid_result%grid)
1046 gauxc_return_if_error(status)
1047 IF (grid_result%owns_rt)
THEN
1048 CALL gauxc_runtime_environment_delete(status%status, grid_result%rt)
1049 gauxc_return_if_error(status)
1050 grid_result%owns_rt = .false.
1053 mark_used(grid_result)
1055 cpabort(no_gauxc_message)
1057 END SUBROUTINE gauxc_destroy_grid
1064 SUBROUTINE gauxc_destroy_integrator(integrator_result, status)
1065 TYPE(cp_gauxc_integrator_type),
INTENT(INOUT) :: integrator_result
1066 TYPE(cp_gauxc_status_type),
INTENT(OUT) :: status
1069 CALL gauxc_delete(status%status, integrator_result%integrator)
1070 gauxc_return_if_error(status)
1071 CALL gauxc_delete(status%status, integrator_result%func)
1072 gauxc_return_if_error(status)
1074 mark_used(integrator_result)
1076 cpabort(no_gauxc_message)
1078 END SUBROUTINE gauxc_destroy_integrator
1084 SUBROUTINE gauxc_check_status(status)
1085 TYPE(cp_gauxc_status_type),
INTENT(IN) :: status
1088 IF (status%status%code /= 0)
THEN
1090 cpabort(
"GauXC returned with non-zero status code")
1095 END SUBROUTINE gauxc_check_status
1108 PURE FUNCTION read_execution_space(spec)
RESULT(val)
1109 CHARACTER(len=*),
INTENT(IN) :: spec
1110 INTEGER(c_int) :: val
1112 CHARACTER(len=LEN(spec)) :: spec_upper
1117 SELECT CASE (spec_upper)
1119 val = gauxc_executionspace%host
1121 val = gauxc_executionspace%device
1123 val = gauxc_executionspace%host
1125 END FUNCTION read_execution_space
1132 PURE FUNCTION read_atomic_grid_size(spec)
RESULT(val)
1133 CHARACTER(len=*),
INTENT(IN) :: spec
1134 INTEGER(c_int) :: val
1136 CHARACTER(len=LEN(spec)) :: spec_upper
1141 SELECT CASE (spec_upper)
1143 val = gauxc_atomicgridsizedefault%finegrid
1145 val = gauxc_atomicgridsizedefault%ultrafinegrid
1147 val = gauxc_atomicgridsizedefault%superfinegrid
1149 val = gauxc_atomicgridsizedefault%gm3
1151 val = gauxc_atomicgridsizedefault%gm5
1153 val = gauxc_atomicgridsizedefault%finegrid
1155 END FUNCTION read_atomic_grid_size
1162 PURE FUNCTION read_radial_quad(spec)
RESULT(val)
1163 CHARACTER(len=*),
INTENT(IN) :: spec
1164 INTEGER(c_int) :: val
1166 CHARACTER(len=LEN(spec)) :: spec_upper
1171 SELECT CASE (spec_upper)
1173 val = gauxc_radialquad%becke
1174 CASE (
"MURAKNOWLES")
1175 val = gauxc_radialquad%mura_knowles
1176 CASE (
"TREUTLERAHLRICHS")
1177 val = gauxc_radialquad%treutler_ahlrichs
1178 CASE (
"MURRAYHANDYLAMING")
1179 val = gauxc_radialquad%murray_handy_laming
1181 val = gauxc_radialquad%mura_knowles
1183 END FUNCTION read_radial_quad
1190 PURE FUNCTION read_pruning_scheme(spec)
RESULT(val)
1191 CHARACTER(len=*),
INTENT(IN) :: spec
1192 INTEGER(c_int) :: val
1194 CHARACTER(len=LEN(spec)) :: spec_upper
1199 SELECT CASE (spec_upper)
1201 val = gauxc_pruningscheme%unpruned
1203 val = gauxc_pruningscheme%robust
1205 val = gauxc_pruningscheme%treutler
1207 val = gauxc_pruningscheme%robust
1209 END FUNCTION read_pruning_scheme
1221 SUBROUTINE gauxc_write_molecule_hdf5(molecule, output_path, filename, dataset, status)
1222 TYPE(cp_gauxc_molecule_type),
INTENT(IN) :: molecule
1223 CHARACTER(len=*),
INTENT(IN) :: output_path, filename, dataset
1224 TYPE(cp_gauxc_status_type),
INTENT(INOUT) :: status
1226#if defined(__GAUXC) && defined(GAUXC_HAS_HDF5)
1227 CHARACTER(len=default_path_length) :: full_path
1229 full_path = trim(output_path)//
"/"//trim(filename)
1230 CALL gauxc_write_hdf5_record(status%status, molecule%molecule, full_path, dataset)
1233 mark_used(output_path)
1237 cpabort(
"GauXC HDF5 output requires GauXC to be built with HDF5 support.")
1239 END SUBROUTINE gauxc_write_molecule_hdf5
1249 SUBROUTINE gauxc_write_basisset_hdf5(basis, output_path, filename, dataset, status)
1250 TYPE(cp_gauxc_basisset_type),
INTENT(IN) :: basis
1251 CHARACTER(len=*),
INTENT(IN) :: output_path, filename, dataset
1252 TYPE(cp_gauxc_status_type),
INTENT(INOUT) :: status
1254#if defined(__GAUXC) && defined(GAUXC_HAS_HDF5)
1255 CHARACTER(len=default_path_length) :: full_path
1257 full_path = trim(output_path)//
"/"//trim(filename)
1258 CALL gauxc_write_hdf5_record(status%status, basis%basis, full_path, dataset)
1261 mark_used(output_path)
1265 cpabort(
"GauXC HDF5 output requires GauXC to be built with HDF5 support.")
1267 END SUBROUTINE gauxc_write_basisset_hdf5
1269END 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.
Provides all information about an atomic kind.
Provides all information about a quickstep kind.
subroutine print_gauxc_status_message(status)
...