Fix TBLITE forces and stress for periodic k-point calculations (#5582)

Co-authored-by: Thomas D. Kuehne <tkuehne@cp2k.org>
This commit is contained in:
Dynamics of Condensed Matter 2026-07-14 13:37:50 +02:00 committed by GitHub
parent 97cfbf5b46
commit c92cc08b45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 648 additions and 394 deletions

File diff suppressed because it is too large Load diff

View file

@ -30,8 +30,7 @@ MODULE tblite_ks_matrix
mo_set_type
USE qs_rho_types, ONLY: qs_rho_get,&
qs_rho_type
USE tblite_interface, ONLY: tb_derive_dH_diag,&
tb_derive_dH_off,&
USE tblite_interface, ONLY: tb_derive_dH_off,&
tb_ham_add_coulomb,&
tb_update_charges
#include "./base/base_uses.f90"
@ -139,7 +138,6 @@ CONTAINS
END IF
IF (calculate_forces) THEN
CALL tb_derive_dH_diag(qs_env, force_use_rho, nimg)
CALL tb_derive_dH_off(qs_env, force_use_rho, nimg)
END IF

View file

@ -0,0 +1,61 @@
&GLOBAL
PRINT_LEVEL MEDIUM
PROJECT H2O_gfn1_yz_kp_debug
RUN_TYPE DEBUG
&END GLOBAL
&DEBUG
DEBUG_FORCES T
DEBUG_STRESS_TENSOR T
DX 0.0001
MAX_RELATIVE_ERROR 0.5
STOP_ON_MISMATCH F
&END DEBUG
&FORCE_EVAL
STRESS_TENSOR ANALYTICAL
&DFT
&KPOINTS
EPS_SYMMETRY 1.e-8
FULL_GRID OFF
SCHEME MONKHORST-PACK 1 2 2
SYMMETRY ON
SYMMETRY_BACKEND SPGLIB
VERBOSE T
&END KPOINTS
&QS
EPS_DEFAULT 1.00E-10
METHOD xTB
&XTB
GFN_TYPE TBLITE
&TBLITE
METHOD GFN1
&END TBLITE
&END XTB
&END QS
&SCF
EPS_SCF 1.e-10
MAX_SCF 300
SCF_GUESS MOPAC
&MIXING
ALPHA 0.2
METHOD DIRECT_P_MIXING
&END MIXING
&PRINT
&RESTART OFF
&END RESTART
&END PRINT
&END SCF
&END DFT
&SUBSYS
&CELL
ABC 18.0 6.0 6.0
PERIODIC YZ
&END CELL
&COORD
O 0.421000 0.377000 0.289000
H 1.179602 0.391000 0.793284
H -0.337602 0.364000 0.793284
&END COORD
&END SUBSYS
&END FORCE_EVAL

View file

@ -10,7 +10,11 @@
"CH2O_gfn1_stress.inp" = [{matcher="DEBUG_stress_sum", tol=1.0E-5, ref=0.0000000}]
"Si_gfn1_fd_force.inp" = [{matcher="M082", tol=2.0E-4, ref=0.0000000}]
"Si_gfn1_fd_stress.inp" = [{matcher="M042", tol=1.0E-5, ref=0.0000000}]
"Si_gfn1_kp_stress.inp" = [{matcher="DEBUG_stress_sum", tol=5.0E-5, ref=0.0000000}]
"Si_gfn1_kp_stress.inp" = [{matcher="DEBUG_stress_sum", tol=5.0E-6, ref=0.0000000}]
"H2O_gfn1_yz_kp_debug.inp" = [{matcher="DEBUG_stress_sum", tol=1.0E-7, ref=0.0000000},
{matcher="DEBUG_periodic_stress_sum", tol=1.0E-7, ref=0.0000000},
{matcher="DEBUG_force_sum", tol=1.0E-6, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=2}]
"Ar_fcc_gfn1_kp_debug.inp" = [{matcher="DEBUG_stress_sum", tol=1.0E-5, ref=0.0000000},
{matcher="DEBUG_force_sum", tol=1.0E-5, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=4}]
@ -29,4 +33,7 @@
{matcher="DEBUG_periodic_stress_sum", tol=5.0E-6, ref=0.0000000},
{matcher="DEBUG_force_sum", tol=1.0E-6, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=2}]
"hbn_gfn1_hex_kp_debug.inp" = [{matcher="DEBUG_stress_sum", tol=1.0E-6, ref=0.0000000},
{matcher="DEBUG_force_sum", tol=1.0E-6, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=8}]
#EOF

View file

@ -0,0 +1,67 @@
&GLOBAL
PRINT_LEVEL MEDIUM
PROJECT hbn_gfn1_hex_kp_debug
RUN_TYPE DEBUG
&END GLOBAL
&DEBUG
DEBUG_FORCES T
DEBUG_STRESS_TENSOR T
DX 1.0E-4
MAX_RELATIVE_ERROR 0.5
STOP_ON_MISMATCH F
&END DEBUG
&FORCE_EVAL
METHOD QS
STRESS_TENSOR ANALYTICAL
&DFT
&KPOINTS
EPS_SYMMETRY 1.0E-8
FULL_GRID F
SCHEME MACDONALD 2 2 2 0.25 0.25 0.25
SYMMETRY T
SYMMETRY_BACKEND SPGLIB
SYMMETRY_REDUCTION_METHOD SPGLIB
VERBOSE T
&END KPOINTS
&QS
EPS_DEFAULT 1.0E-12
METHOD xTB
&XTB
GFN_TYPE TBLITE
&TBLITE
ACCURACY 0.1
METHOD GFN1
&END TBLITE
&END XTB
&END QS
&SCF
EPS_SCF 1.0E-10
MAX_SCF 300
SCF_GUESS MOPAC
&MIXING
ALPHA 0.2
METHOD DIRECT_P_MIXING
&END MIXING
&PRINT
&RESTART OFF
&END RESTART
&END PRINT
&END SCF
&END DFT
&SUBSYS
&CELL
A 2.500000000000 0.000000000000 0.000000000000
B -1.250000000000 2.165063509461 0.000000000000
C 0.000000000000 0.000000000000 6.660000000000
CANONICALIZE TRUE
PERIODIC XYZ
&END CELL
&COORD
SCALED
B 0.000000000000 0.000000000000 0.000000000000
N 0.333333333333 0.666666666667 0.500000000000
&END COORD
&END SUBSYS
&END FORCE_EVAL

View file

@ -0,0 +1,61 @@
&GLOBAL
PRINT_LEVEL MEDIUM
PROJECT N2_gfn2_cp2k_kp_stress
RUN_TYPE DEBUG
&END GLOBAL
&DEBUG
DEBUG_FORCES F
DEBUG_STRESS_TENSOR T
DX 0.0001
MAX_RELATIVE_ERROR 0.5
STOP_ON_MISMATCH F
&END DEBUG
&FORCE_EVAL
STRESS_TENSOR ANALYTICAL
&DFT
&KPOINTS
FULL_GRID OFF
SCHEME MONKHORST-PACK 2 2 2
SYMMETRY ON
SYMMETRY_BACKEND SPGLIB
VERBOSE T
&END KPOINTS
&QS
EPS_DEFAULT 1.0E-12
METHOD xTB
&XTB
GFN_TYPE TBLITE
SCC_MIXER CP2K
&TBLITE
METHOD GFN2
&END TBLITE
&END XTB
&END QS
&SCF
ADDED_MOS -1 -1
EPS_SCF 1.0E-9
MAX_SCF 200
SCF_GUESS MOPAC
&MIXING
ALPHA 0.2
METHOD DIRECT_P_MIXING
&END MIXING
&PRINT
&RESTART OFF
&END RESTART
&END PRINT
&END SCF
&END DFT
&SUBSYS
&CELL
ABC 4.0 4.0 4.0
PERIODIC XYZ
&END CELL
&COORD
N 0.417000 0.283000 0.191000
N 1.517000 0.311000 0.203000
&END COORD
&END SUBSYS
&END FORCE_EVAL

View file

@ -0,0 +1,57 @@
&GLOBAL
PRINT_LEVEL MEDIUM
PROJECT O2_gfn2_uks_kp_debug
RUN_TYPE DEBUG
&END GLOBAL
&DEBUG
DEBUG_FORCES T
DEBUG_STRESS_TENSOR T
DX 0.0001
STOP_ON_MISMATCH F
&END DEBUG
&FORCE_EVAL
STRESS_TENSOR ANALYTICAL
&DFT
LSD
MULTIPLICITY 3
&KPOINTS
FULL_GRID OFF
SCHEME MONKHORST-PACK 2 2 2
SYMMETRY ON
SYMMETRY_BACKEND SPGLIB
&END KPOINTS
&QS
EPS_DEFAULT 1.00E-12
METHOD xTB
&XTB
GFN_TYPE TBLITE
SCC_MIXER TBLITE
&TBLITE
METHOD GFN2
&END TBLITE
&END XTB
&END QS
&SCF
ADDED_MOS 1 3
EPS_SCF 1.e-10
MAX_SCF 200
SCF_GUESS MOPAC
&PRINT
&RESTART OFF
&END RESTART
&END PRINT
&END SCF
&END DFT
&SUBSYS
&CELL
ABC 4.0 4.0 4.0
PERIODIC XYZ
&END CELL
&COORD
O 0.417000 0.283000 0.191000
O 1.625000 0.311000 0.203000
&END COORD
&END SUBSYS
&END FORCE_EVAL

View file

@ -37,7 +37,7 @@
&END QS
&SCF
ADDED_MOS -1 -1
EPS_SCF 5.e-7
EPS_SCF 3.e-7
MAX_SCF 80
SCF_GUESS MOPAC
&MIXING

View file

@ -33,10 +33,14 @@
# Low-symmetry periodic GFN2/tblite stress diagnostic enabled on this branch.
# DEBUG_STRESS_TENSOR matches the final finite-difference cell, whose symmetry is lower.
"Si_gfn2_asym_fd_stress.inp" = [{matcher="DEBUG_stress_sum", tol=5.0E-6, ref=0.0000000}]
"Si_gfn2_kp_stress.inp" = [{matcher="DEBUG_stress_sum", tol=5.0E-5, ref=0.0000000},
"Si_gfn2_kp_stress.inp" = [{matcher="DEBUG_stress_sum", tol=5.0E-6, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=2}]
"Si_gfn2_kp_333_stress.inp" = [{matcher="DEBUG_stress_sum", tol=2.0E-4, ref=0.0000000},
"Si_gfn2_kp_333_stress.inp" = [{matcher="DEBUG_stress_sum", tol=2.0E-5, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=6}]
"N2_gfn2_cp2k_kp_stress.inp" = [{matcher="DEBUG_stress_sum", tol=1.0E-6, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=4}]
"O2_gfn2_uks_kp_debug.inp" = [{matcher="DEBUG_stress_sum", tol=5.0E-6, ref=0.0000000},
{matcher="DEBUG_force_sum", tol=5.0E-6, ref=0.0000000}]
"Si_gfn2_kp_kpsym.inp" = [{matcher="E_total", tol=1.0E-8, ref=-13.65677573470654},
{matcher="N_special_kpoints", tol=0.0, ref=4}]
"Si_gfn2_kp_spglib_backend.inp" = [{matcher="E_total", tol=1.0E-8, ref=-13.65677573470654},
@ -55,7 +59,7 @@
{matcher="DEBUG_force_sum", tol=1.0E-5, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=4}]
"Ar_layer_gfn2_xz_kp_debug.inp" = [{matcher="DEBUG_stress_sum", tol=5.0E-5, ref=0.0000000},
{matcher="DEBUG_periodic_stress_sum", tol=2.0E-5, ref=0.0000000},
{matcher="DEBUG_periodic_stress_sum", tol=5.0E-5, ref=0.0000000},
{matcher="DEBUG_force_sum", tol=1.0E-5, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=2}]
"Ar2_chain_gfn2_x_kp_debug.inp" = [{matcher="DEBUG_stress_sum", tol=5.0E-6, ref=0.0000000},
@ -67,7 +71,7 @@
{matcher="DEBUG_force_sum", tol=1.0E-6, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=1}]
"Ar_layer_gfn2_yz_kp_debug.inp" = [{matcher="DEBUG_stress_sum", tol=5.0E-5, ref=0.0000000},
{matcher="DEBUG_periodic_stress_sum", tol=2.0E-5, ref=0.0000000},
{matcher="DEBUG_periodic_stress_sum", tol=5.0E-5, ref=0.0000000},
{matcher="DEBUG_force_sum", tol=1.0E-5, ref=0.0000000},
{matcher="N_special_kpoints", tol=0.0, ref=2}]
#EOF