Add conservative AUTO default for cell canonicalization (#5318)

Co-authored-by: Thomas D. Kuehne <tkuehne@cp2k.org>
This commit is contained in:
Dynamics of Condensed Matter 2026-05-30 20:11:58 +02:00 committed by GitHub
parent bff9b1f227
commit 099792108e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 164 additions and 18 deletions

View file

@ -33,8 +33,8 @@ MODULE cell_methods
USE cp_units, ONLY: cp_unit_from_cp2k,&
cp_unit_to_cp2k
USE input_constants, ONLY: &
do_cell_cif, do_cell_cp2k, do_cell_extxyz, do_cell_pdb, do_cell_xsc, do_coord_cif, &
do_coord_cp2k, do_coord_pdb, do_coord_xyz
canonicalize_cell_auto, canonicalize_cell_true, do_cell_cif, do_cell_cp2k, do_cell_extxyz, &
do_cell_pdb, do_cell_xsc, do_coord_cif, do_coord_cp2k, do_coord_pdb, do_coord_xyz
USE input_cp2k_subsys, ONLY: create_cell_section
USE input_enumeration_types, ONLY: enum_i2c,&
enumeration_type
@ -347,8 +347,8 @@ CONTAINS
CHARACTER(LEN=default_path_length) :: cell_file_name, coord_file_name, &
error_msg
INTEGER :: cell_file_format, coord_file_format, &
my_per
INTEGER :: canonicalize_mode, cell_file_format, &
coord_file_format, my_per
INTEGER, DIMENSION(:), POINTER :: multiple_unit_cell
LOGICAL :: canonicalize_cell, cell_read_a, cell_read_abc, cell_read_alpha_beta_gamma, &
cell_read_b, cell_read_c, cell_read_file, my_check_ref, tmp_comb_abc, tmp_comb_cell, &
@ -408,7 +408,8 @@ CONTAINS
CALL section_vals_val_get(cell_section, "ABC", explicit=cell_read_abc)
CALL section_vals_val_get(cell_section, "ALPHA_BETA_GAMMA", explicit=cell_read_alpha_beta_gamma)
CALL section_vals_val_get(cell_section, "CELL_FILE_NAME", explicit=cell_read_file)
CALL section_vals_val_get(cell_section, "CANONICALIZE", l_val=canonicalize_cell)
CALL section_vals_val_get(cell_section, "CANONICALIZE", i_val=canonicalize_mode)
canonicalize_cell = (canonicalize_mode == canonicalize_cell_true)
! Case 4
tmp_comb_top = (.NOT. (cell_read_file .OR. cell_read_abc))
@ -520,12 +521,22 @@ CONTAINS
IF (.NOT. canonicalize_cell .AND. &
((ABS(read_mat(2, 1)) > eps) .OR. &
(ABS(read_mat(3, 1)) > eps) .OR. &
(ABS(read_mat(3, 2)) > eps))) &
CALL cp_warn(__LOCATION__, &
"Cell vectors are read but cell matrix is not "// &
"a lower triangle, not conforming to the program "// &
"convention that A lies along the X-axis and "// &
"B is in the XY plane.")
(ABS(read_mat(3, 2)) > eps))) THEN
IF (canonicalize_mode == canonicalize_cell_auto) THEN
CALL cp_warn(__LOCATION__, &
"CELL%CANONICALIZE AUTO keeps the general input cell orientation. "// &
"The cell matrix is not a lower triangle and does not conform to the "// &
"program convention that A lies along the X-axis and B is in the XY plane. "// &
"Set CELL%CANONICALIZE TRUE to explicitly transform the cell and supported "// &
"cell-dependent input to the canonical internal frame.")
ELSE
CALL cp_warn(__LOCATION__, &
"Cell vectors are read but cell matrix is not "// &
"a lower triangle, not conforming to the program "// &
"convention that A lies along the X-axis and "// &
"B is in the XY plane.")
END IF
END IF
cell%hmat = read_mat
ELSE
IF (ANY(read_ang(:) > eps) .AND. ANY(read_len(:) > eps)) THEN

View file

@ -86,6 +86,9 @@ MODULE input_constants
do_cell_xsc = 3, &
do_cell_extxyz = 4, &
do_cell_pdb = 5
INTEGER, PARAMETER, PUBLIC :: canonicalize_cell_auto = 0, &
canonicalize_cell_true = 1, &
canonicalize_cell_false = 2
INTEGER, PARAMETER, PUBLIC :: rmsd_all = 0, &
rmsd_list = 1, &

View file

@ -28,7 +28,8 @@ MODULE input_cp2k_subsys
USE cp_output_handling, ONLY: cp_print_key_section_create, debug_print_level, &
high_print_level, medium_print_level
USE cp_units, ONLY: cp_unit_to_cp2k
USE input_constants, ONLY: do_add, do_bondparm_covalent, do_bondparm_vdw, &
USE input_constants, ONLY: canonicalize_cell_auto, canonicalize_cell_false, &
canonicalize_cell_true, do_add, do_bondparm_covalent, do_bondparm_vdw, &
do_cell_cif, do_cell_cp2k, do_cell_xsc, &
do_cell_extxyz, do_cell_pdb, &
do_conn_amb7, do_conn_g87, do_conn_g96, &
@ -202,12 +203,25 @@ CONTAINS
CALL keyword_release(keyword)
CALL keyword_create(keyword, __LOCATION__, name="CANONICALIZE", &
description="Transform a general input cell to CP2K's internal convention "// &
"that A lies along the X-axis and B is in the XY plane. Cell-dependent "// &
"Cartesian input such as coordinates, restarts, velocities, k-points, band "// &
"paths, electric-field directions, and fixed spatial points is transformed "// &
"consistently. The stress tensor follows the canonical internal cell.", &
usage="CANONICALIZE T", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
description="Policy for transforming a general input cell to CP2K's internal "// &
"convention that A lies along the X-axis and B is in the XY plane. AUTO is "// &
"conservative and keeps the input orientation when a silent transformation "// &
"could affect Cartesian or direction-dependent input. TRUE explicitly requests "// &
"canonicalization and transforms supported cell-dependent input. FALSE always "// &
"keeps the input orientation.", &
usage="CANONICALIZE AUTO", &
enum_c_vals=s2a("AUTO", "TRUE", "FALSE", "T", "F", ".TRUE.", ".FALSE."), &
enum_i_vals=[canonicalize_cell_auto, canonicalize_cell_true, &
canonicalize_cell_false, canonicalize_cell_true, canonicalize_cell_false, &
canonicalize_cell_true, canonicalize_cell_false], &
enum_desc=s2a("Keep the input orientation unless canonicalization is unambiguously safe", &
"Explicitly canonicalize the input cell", &
"Keep the input cell orientation", &
"Alias for TRUE", &
"Alias for FALSE", &
"Alias for TRUE", &
"Alias for FALSE"), &
default_i_val=canonicalize_cell_auto, lone_keyword_i_val=canonicalize_cell_true)
CALL section_add_keyword(section, keyword)
CALL keyword_release(keyword)

View file

@ -33,6 +33,7 @@
&END MM
&SUBSYS
&CELL
CANONICALIZE T
CELL_FILE_FORMAT CP2K
CELL_FILE_NAME deca_ala4-1.cell
&END CELL

View file

@ -43,6 +43,7 @@
A -3.85000/-2 -3.85*+SQRT(3.000e00)/2 COS(+9.E001)
B +3.850/+2.0 -0.385E1*-TAN(+6E+01)/2 -LOG(01)/-10
C -SIN(0) +000/342 +LOG10(+0.10)*6.366*+EXP(-00.000)/-COS(0.000E-5)
CANONICALIZE T
MULTIPLE_UNIT_CELL 3 3 3
PERIODIC XYZ
&CELL_REF

View file

@ -67,6 +67,7 @@
A 2.7 0.0 2.7
B 0.0 2.7 2.7
C 2.7 2.7 0.0
CANONICALIZE T
MULTIPLE_UNIT_CELL 2 2 2
PERIODIC XYZ
&END CELL

View file

@ -81,6 +81,7 @@
A 26.2236461476644 0.508235414971433 0.352095900341464
B 15.3935301632910 21.2250717093132 0.339884967068496
C 15.3881435611913 8.04313631389397 19.6199427770879
CANONICALIZE T
&END CELL
&COORD
AL -18.8567449782927 -9.84653151159998 -6.72435609218356

View file

@ -83,6 +83,7 @@
A 26.2236461476644 0.508235414971433 0.352095900341464
B 15.3935301632910 21.2250717093132 0.339884967068496
C 15.3881435611913 8.04313631389397 19.6199427770879
CANONICALIZE T
&END CELL
&COORD
AL -18.8567449782927 -9.84653151159998 -6.72435609218356

View file

@ -135,6 +135,7 @@
&SUBSYS
&CELL
ABC 10.936 10.936 10.936
CANONICALIZE T
&END CELL
&KIND U
MASS 238.03000

View file

@ -134,6 +134,7 @@
&SUBSYS
&CELL
ABC 10.8949 10.8949 10.8949
CANONICALIZE T
&END CELL
&COORD
U 0.000000 0.000000 0.000000 UO2 1

View file

@ -140,6 +140,7 @@
&SUBSYS
&CELL
ABC 10.8949 10.8949 10.8949
CANONICALIZE T
&END CELL
&COORD
U 0.000000 0.000000 0.000000 UO2 1

View file

@ -140,6 +140,7 @@
&SUBSYS
&CELL
ABC 10.8949 10.8949 10.8949
CANONICALIZE T
&END CELL
&COORD
U 0.000000 0.000000 0.000000 UO2 1

View file

@ -140,6 +140,7 @@
&SUBSYS
&CELL
ABC 10.8949 10.8949 10.8949
CANONICALIZE T
&END CELL
&COORD
U 0.000000 0.000000 0.000000 UO2 1

View file

@ -161,6 +161,7 @@
&SUBSYS
&CELL
ABC 10.8949 10.8949 10.8949
CANONICALIZE T
&END CELL
&COORD
U 0.000000 0.000000 0.000000 UO2 1

View file

@ -133,6 +133,7 @@
&SUBSYS
&CELL
ABC 10.8949 10.8949 10.8949
CANONICALIZE T
&END CELL
&COORD
U 0.000000 0.000000 0.000000 UO2 1

View file

@ -123,6 +123,7 @@
A 21.87537964 -0.32813069 0.00000000
B -0.32813069 21.87537964 0.00000000
C 0.00000000 0.00000000 21.88030271 # V = 10468.0743, x = -0.03
CANONICALIZE T
&END CELL
&COORD
SCALED

View file

@ -123,6 +123,7 @@
A 21.87537964 -0.32813069 0.00000000
B -0.32813069 21.87537964 0.00000000
C 0.00000000 0.00000000 21.88030271 # V = 10468.0743, x = -0.03
CANONICALIZE T
&END CELL
&COORD
SCALED

View file

@ -96,6 +96,7 @@
A 4.914 8.510 0.0
B 4.914 -8.510 0.0
C 0.0 0.0 10.810
CANONICALIZE T
PERIODIC XYZ
&END CELL
&COORD

View file

@ -96,6 +96,7 @@
A 4.914 8.510 0.0
B 4.914 -8.510 0.0
C 0.0 0.0 10.810
CANONICALIZE T
PERIODIC XYZ
&END CELL
&COORD

View file

@ -52,6 +52,7 @@
A 6.0 .2 .0
B .0 6.0 .0
C -.2 .0 6.0
CANONICALIZE T
&END CELL
&COORD
O 0.000000 0.000000 -0.065587

View file

@ -52,6 +52,7 @@
A 6.0 .2 .0
B .0 6.0 .0
C -.2 .0 6.0
CANONICALIZE T
&END CELL
&COORD
O 0.000000 0.000000 -0.065587

View file

@ -39,6 +39,7 @@
A 6.0 .2 .0
B .0 6.0 .0
C -.2 .0 6.0
CANONICALIZE T
&END CELL
&COORD
O 0.000000 0.000000 -0.065587

View file

@ -38,6 +38,7 @@
A 6.0 0.0 1.0
B 0.0 6.0 0.0
C 0.0 0.0 6.0
CANONICALIZE T
&END CELL
&COORD
O 0.000000 0.000000 -0.065587

View file

@ -44,6 +44,7 @@
A 5.0 0.0 3.0
B 1.0 5.0 0.0
C 0.0 2.0 5.0
CANONICALIZE T
&END CELL
&COORD
O 0.000000 2.000000 1.940000

View file

@ -62,6 +62,7 @@
A 5.42858871335 1.0 0.0
B 0.0 5.42858871335 0.0
C 0.00 0.00 5.42858871335
CANONICALIZE T
&END CELL
&KIND Si
BASIS_SET DZVP-GTH

View file

@ -62,6 +62,7 @@
A 5.42858871335 1.0 0.0
B 0.0 5.42858871335 0.0
C 0.00 0.00 5.42858871335
CANONICALIZE T
&END CELL
&KIND Si
BASIS_SET DZVP-GTH

View file

@ -34,6 +34,7 @@
A 6.0 0.0 0.0
B 0.0 6.0 1.0
C 1.0 0.0 8.0
CANONICALIZE T
&END CELL
&COORD
C -0.2558206925 -0.0449868417 0.6850619693

View file

@ -56,6 +56,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -56,6 +56,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -57,6 +57,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -56,6 +56,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -56,6 +56,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -18,6 +18,8 @@
"h_sym_red_restart.inp" = [{matcher="E_total", tol=1e-8, ref=-4.34916647312477}]
"h_noncanonical_kpsym.inp" = [{matcher="E_total", tol=1e-12, ref=-4.34916646889997},
{matcher="N_special_kpoints", tol=0.0, ref=4}]
"h_auto_noncanonical_kpsym.inp" = [{matcher="E_total", tol=1e-12, ref=-4.34916646889997},
{matcher="N_special_kpoints", tol=0.0, ref=4}]
"h_canonical_kpsym.inp" = [{matcher="E_total", tol=1e-12, ref=-4.34916646889997},
{matcher="N_special_kpoints", tol=0.0, ref=2}]
"h_canonical_cart_kpsym.inp" = [{matcher="E_total", tol=1e-12, ref=-4.34916646889997},

View file

@ -0,0 +1,69 @@
&GLOBAL
PRINT_LEVEL LOW
PROJECT H_AUTO_NONCANONICAL_KPSYM
RUN_TYPE ENERGY
&END GLOBAL
&FORCE_EVAL
&DFT
BASIS_SET_FILE_NAME GTH_BASIS_SETS
POTENTIAL_FILE_NAME POTENTIAL
&KPOINTS
EPS_SYMMETRY 1.e-8
FULL_GRID OFF
PARALLEL_GROUP_SIZE -1
SCHEME MONKHORST-PACK 2 2 2
SYMMETRY ON
VERBOSE T
&END KPOINTS
&MGRID
CUTOFF 280
REL_CUTOFF 50
&END MGRID
&QS
EPS_DEFAULT 1.0E-12
METHOD GPW
&END QS
&SCF
CHOLESKY OFF
EPS_EIGVAL 1.e-8
EPS_SCF 1.0E-8
MAX_SCF 20
SCF_GUESS ATOMIC
&MIXING
ALPHA 0.50
METHOD BROYDEN_MIXING
&END MIXING
&PRINT
&RESTART OFF
&END RESTART
&END PRINT
&END SCF
&XC
&XC_FUNCTIONAL PADE
&END XC_FUNCTIONAL
&END XC
&END DFT
&SUBSYS
&CELL
A 0.0 3.56683 0.0
B 3.56683 0.0 0.0
C 0.0 0.0 3.56683
&END CELL
&COORD
SCALED
H 0.100000 0.000000 0.000000
H 0.500000 0.500000 0.000000
H 0.500000 0.000000 0.500000
H 0.000000 0.500000 0.500000
H 0.250000 0.250000 0.250000
H 0.250000 0.750000 0.750000
H 0.750000 0.250000 0.750000
H 0.750000 0.750000 0.250000
&END COORD
&KIND H
BASIS_SET SZV-GTH
POTENTIAL GTH-PADE-q1
&END KIND
&END SUBSYS
&END FORCE_EVAL

View file

@ -49,6 +49,7 @@
A 0.0 3.56683 0.0
B 3.56683 0.0 0.0
C 0.0 0.0 3.56683
CANONICALIZE T
&END CELL
&COORD
UNIT ANGSTROM

View file

@ -49,6 +49,7 @@
A 0.0 3.56683 0.0
B 3.56683 0.0 0.0
C 0.0 0.0 3.56683
CANONICALIZE T
&END CELL
&COORD
SCALED

View file

@ -39,6 +39,7 @@
A 0.0000 1.7835 1.7835
B 1.7835 0.0000 1.7835
C 1.7835 1.7835 0.0000
CANONICALIZE T
MULTIPLE_UNIT_CELL 1 1 1
&END CELL
&COORD

View file

@ -40,6 +40,7 @@
A 0.0000 1.7835 1.7835
B 1.7835 0.0000 1.7835
C 1.7835 1.7835 0.0000
CANONICALIZE T
MULTIPLE_UNIT_CELL 1 1 1
&END CELL
&COORD

View file

@ -81,6 +81,7 @@
A 8.0 0.05 0.0
B 0.05 8.0 0.0
C 0.05 0.0 8.0
CANONICALIZE T
&END CELL
&COORD
O 4.0000000084 4.0000000084 4.6623718822

View file

@ -83,6 +83,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -84,6 +84,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -55,6 +55,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -47,6 +47,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -54,6 +54,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -59,6 +59,7 @@
A 1.22800000 -2.12695839 0.00000000
B 1.22800000 2.12695839 0.00000000
C 0.00000000 0.00000000 6.69600000
CANONICALIZE T
&END CELL
&COORD
C 0.00000000 0.00000000 1.67400000

View file

@ -58,6 +58,7 @@
A 8.0 -0.1 0.2
B -0.2 8.0 0.1
C 0.2 -0.2 8.0
CANONICALIZE T
&END CELL
&KIND H
BASIS_SET DZVP-GTH

View file

@ -91,6 +91,7 @@
A 5.42858871335 1.0 0.0
B 0.0 5.42858871335 0.0
C 0.00 0.00 5.42858871335
CANONICALIZE T
&END CELL
&KIND Si
BASIS_SET DZVP-GTH

View file

@ -88,6 +88,7 @@
A 5.42858871335 1.0 0.0
B 0.0 5.42858871335 0.0
C 0.00 0.00 5.42858871335
CANONICALIZE T
&END CELL
&KIND Si
BASIS_SET DZVP-GTH

View file

@ -84,6 +84,7 @@
A 5.42858871335 1.0 0.0
B 0.0 5.42858871335 0.0
C 0.00 0.00 5.42858871335
CANONICALIZE T
&END CELL
&KIND Si
BASIS_SET DZVP-GTH

View file

@ -109,6 +109,7 @@
A 0.00 7.50000 0.00000
B 0.00 3.75000 6.49518
C 12.0 0.00000 0.00000
CANONICALIZE T
&END CELL
&KIND B
BASIS_SET DZVP-MOLOPT-SR-GTH

View file

@ -53,6 +53,7 @@
A [bohr] -3.85500000000000000000 0.0 3.85500000000000000000
B [bohr] 0.0 3.85500000000000000000 3.85500000000000000000
C [bohr] -3.85500000000000000000 3.85500000000000000000 0.0
CANONICALIZE T
&END CELL
&COORD
SCALED

View file

@ -54,6 +54,7 @@
A [bohr] -3.85500000000000000000 0.0 3.85500000000000000000
B [bohr] 0.0 3.85500000000000000000 3.85500000000000000000
C [bohr] -3.85500000000000000000 3.85500000000000000000 0.0
CANONICALIZE T
&END CELL
&COORD
SCALED