From ea663e99cfdb430c52ec736bcd617acc89ea2698 Mon Sep 17 00:00:00 2001 From: HE Zilong <159878975+he-zilong@users.noreply.github.com> Date: Wed, 15 Jul 2026 19:35:03 +0800 Subject: [PATCH] Address issues #1498 and #4023 (#5588) --- src/auto_basis.F | 26 ++++++++++++++++++++++---- src/cp_control_utils.F | 32 +++++++++++++++++++++++++++++--- src/input_cp2k_dft.F | 10 ++++++++-- src/input_cp2k_properties_dft.F | 9 +++++++-- 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/auto_basis.F b/src/auto_basis.F index 94bccf5995..23546df6e7 100644 --- a/src/auto_basis.F +++ b/src/auto_basis.F @@ -61,7 +61,7 @@ CONTAINS INTEGER, INTENT(IN), OPTIONAL :: basis_sort CHARACTER(LEN=2) :: element_symbol - CHARACTER(LEN=default_string_length) :: bsname + CHARACTER(LEN=default_string_length) :: bsname, kname INTEGER :: i, j, jj, l, laux, linc, lmax, lval, lx, & nsets, nx, z INTEGER, DIMENSION(0:18) :: nval @@ -84,7 +84,7 @@ CONTAINS 2.0_dp, 2.0_dp, 2.0_dp, 2.0_dp, 2.0_dp, 2.0_dp, 2.0_dp, 2.0_dp] ! CPASSERT(.NOT. ASSOCIATED(ri_aux_basis_set)) - NULLIFY (orb_basis_set) + NULLIFY (orb_basis_set, econf) IF (.NOT. PRESENT(basis_type)) THEN CALL get_qs_kind(qs_kind, basis_set=orb_basis_set, basis_type="ORB") ELSE @@ -106,6 +106,15 @@ CONTAINS CALL init_orbital_pointers(2*lmax) CALL get_basis_products(lmax, zmin, zmax, zeff, pmin, pmax, peff) CALL get_qs_kind(qs_kind, zeff=zval, elec_conf=econf, element_symbol=element_symbol) + IF (.NOT. ASSOCIATED(econf)) THEN + CALL get_qs_kind(qs_kind, name=kname) + CALL cp_abort(__LOCATION__, & + "AUTO_BASIS RI_AUX cannot process atom kind "// & + "<"//TRIM(ADJUSTL(kname))//"> due to missing "// & + "definition of potential or electron configuration; "// & + "consider setting keyword ELEC_CONF explicitly for "// & + "GHOST atom kind that has assigned a basis set") + END IF CALL get_ptable_info(element_symbol, ielement=z) lval = 0 DO l = 0, MAXVAL(UBOUND(econf)) @@ -236,7 +245,7 @@ CONTAINS LOGICAL, INTENT(IN), OPTIONAL :: exact_1c_terms, tda_kernel CHARACTER(LEN=2) :: element_symbol - CHARACTER(LEN=default_string_length) :: bsname + CHARACTER(LEN=default_string_length) :: bsname, kname INTEGER :: i, j, l, laux, linc, lm, lmax, lval, n1, & n2, nsets, z INTEGER, DIMENSION(0:18) :: nval @@ -267,12 +276,21 @@ CONTAINS END IF ! CPASSERT(.NOT. ASSOCIATED(lri_aux_basis_set)) - NULLIFY (orb_basis_set) + NULLIFY (orb_basis_set, econf) CALL get_qs_kind(qs_kind, basis_set=orb_basis_set, basis_type="ORB") IF (ASSOCIATED(orb_basis_set)) THEN CALL get_basis_keyfigures(orb_basis_set, lmax, zmin, zmax, zeff) CALL get_basis_products(lmax, zmin, zmax, zeff, pmin, pmax, peff) CALL get_qs_kind(qs_kind, zeff=zval, elec_conf=econf, element_symbol=element_symbol) + IF (.NOT. ASSOCIATED(econf)) THEN + CALL get_qs_kind(qs_kind, name=kname) + CALL cp_abort(__LOCATION__, & + "AUTO_BASIS LRI_AUX cannot process atom kind "// & + "<"//TRIM(ADJUSTL(kname))//"> due to missing "// & + "definition of potential or electron configuration; "// & + "consider setting keyword ELEC_CONF explicitly for "// & + "GHOST atom kind that has assigned a basis set") + END IF CALL get_ptable_info(element_symbol, ielement=z) lval = 0 DO l = 0, MAXVAL(UBOUND(econf)) diff --git a/src/cp_control_utils.F b/src/cp_control_utils.F index 3a2478e19e..23cc7d56b5 100644 --- a/src/cp_control_utils.F +++ b/src/cp_control_utils.F @@ -242,7 +242,18 @@ CONTAINS CALL uppercase(tmpstringlist(2)) SELECT CASE (tmpstringlist(2)) CASE ("X") - isize = -1 + SELECT CASE (tmpstringlist(1)) + CASE ("X") + ! Do nothing + CASE DEFAULT + CALL cp_abort(__LOCATION__, & + "AUTO_BASIS: the size is invalid for the "// & + "type <"//TRIM(ADJUSTL(tmpstringlist(1)))//">; "// & + "use one of SMALL, MEDIUM, LARGE, HUGE for "// & + "the size. The syntax AUTO_BASIS X X is a "// & + "reserved case for using NO automatically "// & + "generated basis sets.") + END SELECT CASE ("SMALL") isize = 0 CASE ("MEDIUM") @@ -648,7 +659,11 @@ CONTAINS END IF ! periodic fields don't work with RTP - CPASSERT(.NOT. do_rtp) + IF (do_rtp) & + CALL cp_abort(__LOCATION__, & + "Periodic efield cannot be used with RTP. When restarting a "// & + "run with periodic efield, set RESTART_RTP under &EXT_RESTART "// & + "section to .FALSE. explicitly if RESTART_DEFAULT is .TRUE.") IF (dft_control%period_efield%displacement_field) THEN CALL cite_reference(Stengel2009) ELSE @@ -2122,7 +2137,18 @@ CONTAINS CALL uppercase(tmpstringlist(2)) SELECT CASE (tmpstringlist(2)) CASE ("X") - isize = -1 + SELECT CASE (tmpstringlist(1)) + CASE ("X") + ! Do nothing + CASE DEFAULT + CALL cp_abort(__LOCATION__, & + "AUTO_BASIS: the size is invalid for the "// & + "type <"//TRIM(ADJUSTL(tmpstringlist(1)))//">; "// & + "use one of SMALL, MEDIUM, LARGE, HUGE for "// & + "the size. The syntax AUTO_BASIS X X is a "// & + "reserved case for using NO automatically "// & + "generated basis sets.") + END SELECT CASE ("SMALL") isize = 0 CASE ("MEDIUM") diff --git a/src/input_cp2k_dft.F b/src/input_cp2k_dft.F index 082cc27f4b..74c65fff9f 100644 --- a/src/input_cp2k_dft.F +++ b/src/input_cp2k_dft.F @@ -250,8 +250,14 @@ CONTAINS CALL keyword_release(keyword) CALL keyword_create(keyword, __LOCATION__, name="AUTO_BASIS", & - description="Specify size of automatically generated auxiliary (RI) basis sets: "// & - "Options={small,medium,large,huge}", & + description="Specify type and size of automatically generated auxiliary "// & + "(RI) basis sets. Exactly two arguments are required for this option. "// & + "The first argument of basis type should be one of the following: "// & + "`RI_AUX`, `AUX_FIT`, `LRI_AUX`, `P_LRI_AUX`, `RI_HXC`, `RI_XAS`, or "// & + "`RI_HFX`. The second argument of basis size should be one of the "// & + "following: `SMALL`, `MEDIUM`, `LARGE`, or `HUGE`. The default is not "// & + "using any of these basis sets, requested by `AUTO_BASIS X X` (exactly "// & + "as written here).", & usage="AUTO_BASIS {basis_type} {basis_size}", & type_of_var=char_t, repeats=.TRUE., n_var=-1, default_c_vals=["X", "X"]) CALL section_add_keyword(section, keyword) diff --git a/src/input_cp2k_properties_dft.F b/src/input_cp2k_properties_dft.F index e120efee04..68a5a348e7 100644 --- a/src/input_cp2k_properties_dft.F +++ b/src/input_cp2k_properties_dft.F @@ -1803,8 +1803,13 @@ CONTAINS CALL keyword_release(keyword) CALL keyword_create(keyword, __LOCATION__, name="AUTO_BASIS", & - description="Specify size of automatically generated auxiliary basis sets: "// & - "Options={small,medium,large,huge}", & + description="Specify type and size of automatically generated auxiliary "// & + "(RI) basis sets. Exactly two arguments are required for this option. "// & + "The first argument of basis type should be one of the following: "// & + "`P_LRI_AUX`. The second argument of basis size should be one of the "// & + "following: `SMALL`, `MEDIUM`, `LARGE`, or `HUGE`. The default is not "// & + "using any of these basis sets, requested by `AUTO_BASIS X X` (exactly "// & + "as written here).", & usage="AUTO_BASIS {basis_type} {basis_size}", & type_of_var=char_t, repeats=.TRUE., n_var=-1, default_c_vals=["X", "X"]) CALL section_add_keyword(section, keyword)