Commit graph

167 commits

Author SHA1 Message Date
Dynamics of Condensed Matter
97cfbf5b46
Fix Bloch phases for fully symmetry-reduced k-point grids (#5581)
Co-authored-by: Thomas D. Kuehne <tkuehne@cp2k.org>
2026-07-13 19:41:54 +02:00
SY Wang
e0f0c17926
Adjust regtests and ignore tblite SCC mixer residual for OT/LS_SCF (#5357) 2026-06-06 00:14:32 +02:00
Ole Schütt
7ac807a875
Adjust tolerance of ch2o_tblite_mixer.inp and si_uks_kp_tblite_mixer_… (#5291) 2026-05-26 11:30:56 +02:00
Matthias Krack
11661d76ba
Switch to tblite@main until a new release will become available (#5186) 2026-05-14 05:56:25 +02:00
Dynamics of Condensed Matter
20f179c892
Improve TB/xTB SCC mixer handling for LS_SCF and UKS k-point cases (#5182)
Co-authored-by: Thomas D. Kuehne <tkuehne@cp2k.org>
2026-05-13 20:06:09 +02:00
Johann Potot.
1233a2ca2a
small fixes for testing (#5177)
Co-authored-by: Johann Pototschnig <j.pototschnig@hzdr.de>
2026-05-13 18:05:44 +02:00
Dynamics of Condensed Matter
6a4e44fd68
"Make it nice": GFN2-xTB (#5162)
Co-authored-by: Thomas D. Kuehne <tkuehne@cp2k.org>
2026-05-10 01:34:44 +02:00
Dynamics of Condensed Matter
ef37d02fde
Finalize GFN2/tblite k-point stress for remaining pathological cases (#5156)
Co-authored-by: Thomas D. Kuehne <tkuehne@cp2k.org>
2026-05-08 21:50:37 +02:00
Dynamics of Condensed Matter
72f118eab7
Expand TB force/stress coverage and improve GFN2/tblite k-point stress of remaining pathological cases (#5155)
Co-authored-by: Thomas D. Kuehne <tkuehne@cp2k.org>
2026-05-08 21:05:08 +02:00
Dynamics of Condensed Matter
55d01f6722
Improve DFTB/xTB stress handling, k-point reductions, and UKS coverage (#5144)
Co-authored-by: Thomas D. Kuehne <tkuehne@cp2k.org>
2026-05-07 23:01:43 +02:00
Dynamics of Condensed Matter
cccd2f3934
Fix TB gradients, virials, and k-point symmetry
# Fix TB gradients, virials, tblite reference checks, and k-point symmetry

## Summary

This PR continues the CP2K/tblite interface work originally started by Johann Pototschnig
(`jpoto`) and relies in part on Sebastian Ehlert's `tblite` library. It makes the CP2K tight
binding paths substantially more consistent for nuclear gradients, virials/stress tensors, and
k-point symmetry, especially for DFTB, CP2K-native GFN0/GFN1, and `&XTB &TBLITE` GFN1/GFN2/IPEA1.

Main changes:

- fix several CP2K/tblite force and virial terms for periodic systems,
- add a native `tblite` CLI reference path under `&XTB &TBLITE &REFERENCE_CLI`,
- enable and test k-point symmetry reduction for CP2K-native TB and CP2K/tblite TB paths,
- improve DFTB SCC/Ewald virials and update affected DFTB references,
- add/extend regtests for molecular and truly periodic systems, including force/stress DEBUG checks,
- update the CP2K toolchain patches for `tblite`/embedded DFTD4 and standalone DFTD4.

## User-visible input changes

- `&DFT &XTB` can now select the library implementation via
  `GFN_TYPE TBLITE`; in that case an `&XTB &TBLITE` section is required.
- `&XTB &TBLITE` supports `METHOD GFN1`, `METHOD GFN2`, and `METHOD IPEA1`.
- `&XTB &TBLITE` has an optional `REFERENCE_CLI` keyword and a lone
  `&REFERENCE_CLI` subsection. If present/enabled, CP2K writes a `.gen` geometry, runs native
  `tblite run --grad`, and compares energy, gradient, and virial.
- `SCC_MIXER TBLITE` is documented as a modified Broyden mixer; the associated controls are named
  `TBLITE_MIXER_DAMPING` and `TBLITE_MIXER_MAX_SCF`.
- `DO_EWALD` remains available as a deprecated/debug override; the manual now documents the required
  periodic `POISSON` setup for CP2K-native DFTB/xTB and the `TBLITE` exception.
- CP2K warns if `CELL%PERIODIC` and `POISSON%PERIODIC` differ, but still runs.

## What was fixed

### CP2K/tblite GFN1/GFN2/IPEA1

- Periodic image-cell matrix construction now fills all image cells instead of only image cell 1.
- H0, overlap/potential, GFN2 multipole, CN-chain-rule, and D4-related virial paths were checked
  term by term against finite differences.
- Periodic self-image virial signs/factors were corrected in the CP2K/tblite interface.
- The previously bad strongly distorted Si8/GFN2 Gamma stress case was traced to a hard D4 two-body
  cutoff discontinuity and fixed by adding a smooth switching region in the D4 path.
- `RUN_TYPE DEBUG` force/stress checks now behave consistently for molecular and periodic
  CP2K/tblite GFN1/GFN2 cases; isolated stress is allowed for tblite with a warning because it is a
  diagnostic virial, not a physical isolated-system stress.

### Native tblite CLI reference

The `REFERENCE_CLI` path initially showed good molecular agreement but poor periodic virials for
Ar-fcc:

- GFN1 periodic virial diff was about `1.15e-2`,
- GFN2 periodic virial diff was about `2.95e-2`.

The parser, units, row order, and sign convention were checked and were correct. The remaining error
was in native `tblite`: periodic H0 self-image pairs (`iat == jat`, non-zero translation) used the
normal pair sigma factor `0.5`. The correct symmetrized cell-derivative factor for these self-image
pairs is `0.25`.

Updated `REFERENCE_CLI` comparison after the native tblite H0 sigma fix:

| Case | SCF | Energy diff | Gradient diff sum/max | Virial diff sum/max |
| --- | ---: | ---: | ---: | ---: |
| CH2O/GFN1, molecular | 12 | `6.775398020409e-10` | `3.296429618975e-08` / `1.577689361792e-08` | `2.884140131919e-08` / `2.625531908551e-08` |
| CH2O/GFN2, molecular | 15 | `6.651852402229e-10` | `1.437665769393e-07` / `6.050656990025e-08` | `1.240845506761e-07` / `8.358997352631e-08` |
| Ar-fcc/GFN1, periodic | 7 | `3.595097552989e-09` | `1.125627343711e-09` / `3.688615600028e-10` | `5.441065574157e-09` / `1.653417298474e-09` |
| Ar-fcc/GFN2, periodic | 20 | `8.975906240494e-09` | `2.140900031075e-08` / `4.424293700931e-09` | `3.094086449720e-07` / `8.057020835922e-08` |

`REFERENCE_CLI` is intentionally skipped/guarded for CP2K multi-k-point runs: native `tblite` CLI is
a useful Gamma reference, but it is not a CP2K-equivalent k-point/symmetry implementation.

### DFTB and CP2K-native xTB/GFN0/GFN1

- DFTB SCC/Ewald background handling was fixed so the homogeneous background contributes to energy
  and atomic properties without entering the SCC overlap virial as a constant potential shift.
- The TB real-space Ewald self-image virial prefactor was fixed.
- CP2K-native DFTB/GFN0/GFN1 k-point symmetry support was extended and tested with the CP2K atomic
  backend and SPGLIB backend.
- Full atomic k-point symmetry is used for high-symmetry production geometries; for displaced DEBUG
  geometries the reduced symmetry is recomputed instead of reusing an invalid high-symmetry map.
- DFTB3 forces, Gamma stress, k-point forces, and k-point stress were tested and covered by new
  regtests.


## What was tried

The debugging was deliberately systematic rather than a single-code-path patch:

- molecular and truly periodic crystals were checked separately; large vacuum cells were not used as
  periodic substitutes,
- GFN1 and GFN2 were tested with tight `EPS_DEFAULT`/`EPS_SCF`, DX scans, and high `MAX_SCF`,
- CP2K/tblite results were compared to native `tblite` CLI for energy, gradient, and virial,
- H0, overlap/potential, Coulomb/multipole, CN-chain-rule, D4, D3/s-D3, DFTD4 and SCC/Ewald pieces
  were isolated where practical and checked against finite differences,
- CP2K-native DFTB, DFTB3, GFN0, GFN1, CP2K/tblite GFN1/GFN2/IPEA1, and native `tblite` CLI were
  tested separately,
- k-point full grids, CP2K atomic symmetry, SPGLIB symmetry, displaced atoms, skew cells, and
  MPI-rank reproducibility were checked,
- 1D/2D periodicity, charged systems, and open-shell/spin behavior were probed.

What helped:

- restoring periodic H0/CN self-image contributions,
- fixing self-image virial signs/factors,
- fixing the native tblite H0 self-image sigma factor,
- fixing the DFTB SCC/Ewald background gauge contribution,
- recomputing k-point symmetry for lowered-symmetry DEBUG geometries,
- smoothing the hard D4 two-body cutoff in the stress-sensitive GFN2/Si8 case,
- updating the external library toolchain patches and DFTB reference values.

What did not help or was not the root cause:

- simply tightening `EPS_SCF`, `EPS_DEFAULT`, `DX`, or `MAX_SCF`,
- changing only SCC damping/mixer parameters for the hard GFN2 stress cases,
- treating the native `tblite` CLI periodic virial as authoritative before fixing its own H0 sigma
  self-image term,
- using large vacuum boxes as stand-ins for true periodic crystals,
- assuming all heteronuclear crystals are good regtests: several are dominated by overlap
  conditioning/SCF-state sensitivity rather than a clean force/stress bug.

## What works now

- CP2K/tblite GFN1/GFN2 molecular force DEBUG checks are at `~1e-8`.
- CP2K/tblite GFN2 isolated diagnostic stress is `~4e-9`.
- CP2K/tblite GFN1/GFN2 Ar-fcc k-point force/stress DEBUG runs with `64 -> 4` k-point reduction.
- CP2K/tblite GFN2 `PERIODIC XZ` Ar-layer k-point stress DEBUG is reduced from the reproduced `5.83e-4` remainder to `2.66e-5`; forces are `2.29e-6`.
- CP2K/tblite GFN1/GFN2 skew/asym Si8 Gamma stress is now in the `~1e-6` range rather than
  `~1e-3`.
- CP2K/tblite IPEA1 runs with k-point reduction and force/stress DEBUG coverage.
- CP2K-native DFTB non-SCC/SCC and GFN0/GFN1 k-point symmetry paths pass the new tests.
- DFTB3 force, Gamma stress, k-point force, and k-point stress tests pass.
- DFTD4/DFTD3/D3(BJ) CP2K tests pass with the updated build; external DFTD4/tblite patches are ready
  for the toolchain.

Representative final regtest values:

| Path | Representative result |
| --- | ---: |
| CP2K/tblite GFN2 CH2O force DEBUG | `M042 = 1e-8` |
| CP2K/tblite GFN2 CH2O isolated stress DEBUG | `M042 = 4.067e-9` |
| CP2K/tblite GFN2 Si8 Gamma stress DEBUG | `M042 = 4.76966e-7` |
| CP2K/tblite GFN2 Ar-fcc k-point stress DEBUG | `M042 = 3.33e-7`, `N_special_kpoints = 4` |
| CP2K/tblite GFN2 Ar-layer XZ k-point stress DEBUG | `M042 = 2.66e-5`, `N_special_kpoints = 2` |
| CP2K/tblite GFN1 Ar-fcc k-point stress DEBUG | `M042 = 1.6417e-8`, `N_special_kpoints = 4` |
| CP2K/tblite IPEA1 Ar-fcc k-point stress DEBUG | `M042 = 2.4656e-8`, `N_special_kpoints = 4` |
| CP2K-native GFN0 Si k-point symmetry | `N_special_kpoints = 4`; displaced geometry `12` |
| DFTB non-SCC Si k-point stress | `M042 = 3.807e-9`, `N_special_kpoints = 4` |
| DFTB SCC C k-point stress | `M042 = 5.409e-9` |
| DFTB SCC ZnS k-point stress | `M042 = 2.18113e-7`, `N_special_kpoints = 4` |
| DFTB3 H2O k-point stress | `M042 = 6.89e-10`, `N_special_kpoints = 4` |

## Remaining limitations

- The reproduced `PERIODIC XZ` CP2K/tblite GFN2 Ar-layer k-point virial remainder is now much smaller (`2.66e-5` instead of `5.83e-4`), but not yet in the `1e-6` range; forces are good.
- `PERIODIC X` full stress DEBUG is limited by the general CP2K cell/Poisson/stress machinery, not by
  a TB-specific quick fix.
- CP2K/tblite open-shell/LSD still aborts intentionally:
  `LSD option not compatible with tblite library`.
- Native `tblite` CLI remains a serial external Gamma-reference path; it is not a k-point/symmetry
  reference implementation.
- Some heteronuclear CP2K/tblite crystals with k-points are sensitive to overlap conditioning and
  SCF state; Ar/Si remain the robust PR regtest choices.

## Verification

- formatting:
  - `tools/precommit/format_fortran.py` on changed Fortran files,
  - `tools/precommit/format_input_file.py` on changed/new CP2K inputs,
  - `tools/precommit/precommit.py -m` on non-Fortran/non-input files.
- patch checks:
  - `tblite-0.5.0-gradient-fixes.patch`: `patch -p1 --dry-run` against fresh `tblite-0.5.0`,
  - `dftd4-4.1.0-gradient-fixes.patch`: `patch -p1 --dry-run` against fresh `dftd4-4.1.0`.
- build:
  - `cmake --build build-tblite-mpi-check --target cp2k-bin -- -j 8`
- regtests with `mpiranks=2`, `ompthreads=1`:
  - `xTB/regtest-tblite-gfn2`, `xTB/regtest-tblite-gfn1-grad`,
    `xTB/regtest-tblite-ipea1`, `DFTB/regtest-scc-2`: `49 / 49` correct,
  - `DFTB/regtest-scc`, `DFTB/regtest-nonscc`: after updating affected references,
    `89 / 89` correct,
  - additionally checked in the same PR-ready run: `xTB/regtest-1`, `xTB/regtest-3`,
    `xTB/regtest-gfn0`, `QS/regtest-dft-vdw-corr-4`; those were green, with only the old DFTB
    references requiring the follow-up update above.
2026-05-06 00:47:46 +02:00
Dynamics of Condensed Matter
9cf845759d
Add k-point symmetry backends and guards (#5124)
Co-authored-by: Thomas D. Kuehne <tkuehne@cp2k.org>
2026-05-04 11:09:36 +02:00
Dynamics of Condensed Matter
33b928ff10
Add k-point symmetry reduction methods (#5123)
Co-authored-by: Thomas D. Kuehne <tkuehne@cp2k.org>
2026-05-03 12:48:36 +02:00
Juerg Hutter
e43e35a407
CG/Linesearch (#4141) 2025-04-15 20:13:30 +02:00
Ole Schütt
53d5369bef Tests: Rename some matchers 2025-03-08 12:10:39 +01:00
Ole Schütt
3d0b1c90e6 Tests: Convert TEST_TYPES to matchers.py 2025-03-01 19:07:38 +01:00
Juerg Hutter
8e5fe4401f
gfn0-xTB and parallel DFT-D4 (#3765) 2024-11-08 17:48:34 +01:00
Juerg Hutter
acd4b0a29d
Update regtests non-scf DFTB + QMMM (prepare for new functionality) (#3436) 2024-05-28 13:23:17 +02:00
Ole Schütt
2b6ea54d62 Format all input files 2023-12-18 22:41:19 +01:00
Matthias Krack
e430776491 Abort run by default on SCF convergence failure
The new keyword IGNORE_CONVERGENCE_FAILURE can be set to obtain the old permissive behaviour.
It replaces the keyword NOTCONV_STOPALL which enforced until now the strict behaviour which is now the default.
2023-12-11 14:26:50 +01:00
Guillaume Le Breton
667ecb8f0e VG for EMD 2023-10-31 10:54:01 +01:00
glb96
e4f5572f67 Update WFN_MIX and RTP 2023-09-28 14:12:02 +02:00
Juerg Hutter
ad7b276f2d
New default settings for regtesting with DEBUG (#2889) 2023-08-02 15:16:24 +02:00
abussy
b234498075 KPOINTS| Implementation of the DIIS/Diag. solver 2023-04-13 10:00:20 +02:00
Juerg Hutter
2cd2f20ff9
Options for DFTB vdW: UFF|D2|D3|D3(BJ) (#2431)
* Add D2/D3/D3BJ options to DFTB/xTB

* Fix DFTB/D2 + regtest

* Remove extra options for vdW correction for xTB
2022-12-05 14:04:54 +01:00
Ole Schütt
6a330cddb3 Remove tabs and trailing spaces 2021-03-11 20:06:46 +01:00
Ole Schütt
3567d8e355 Adjust 42 thresholds for i386 2020-12-10 10:59:24 +01:00
Juerg Hutter
573674aa68 DFTB debug dipole moments
xTB debug dipole moments and polarizabilities
2020-08-31 13:06:57 +02:00
Fabian Ducry
75ef8b136d
Csr write (#915)
* Fix ks_csr_write and s_csr_write not implemented for k-points

Printing the Kohn-Sham and overlap matrices is not implemented for
k-point calculations. Both matrices are now printed at the
k grid used in the scf procedure.

* Added csr_write to TB

Added calls to ks_scr_write and s_csr_write to
qs_scf_post_tb.F. Before these print sections were silently
ignored.

* Move ks_csr_write and s_csr_write to new module

The ks_csr_write and s_csr_write move to the new module
qs_post_scf_csr_write. Also moved the bulk of the printing
function to a helper function to avoid copying of code.

* Add ks_csr_write and s_csr_write to regtests

Add the ks_csr_write and s_csr_write sections to three regtests from
DFTB, xTB and QS. These cover gamma-point, k-point with and without
real wave fucntions.
2020-05-15 13:45:49 +02:00
Ole Schütt
a42c4d12de do_regtest: Make reference values mandatory 2020-01-28 12:07:44 +01:00
Hans Pabst
8865f63939
Enable ELPA by default if compiled into CP2K (#322)
This PR enables ELPA by default when incorporated at compile-time:

1. Enables ELPA by default (if compiled into the binary),
2. Selects ELPA-kernel according to CPUID.

The code uses m_cpuid (machine module) and introduced get_elpa_kernel_index (cp_fm_elpa module) to select the ELPA-kernel according to the CPUID.

The GLOBAL entry `PREFERRED_DIAG_LIBRARY SL` is given for a number of tests that would otherwise exceed tolerances as currently used (mostly CDFT tests). Slightly adjusted some tolerances of non-CDFT tests when reasonable, and one for the PSMP case.

Other (unrelated) changes: fixed some typos (source code comments).
2019-06-20 15:20:13 +02:00
Matthias Krack
51412ade4f Add empty file 2019-05-30 11:45:54 +02:00
Juerg Hutter
89a19eabde
Bug fixes for TB Stress Tensor (DFTB and xTB), two new regtests, (#392)
some regtests have been updated
2019-05-29 11:17:46 +02:00
Juerg Hutter
689f5b18c8
TB Ewald: ensure FFT sizes for grid, ajust regtest values (#342) 2019-05-07 18:36:17 +02:00
Juerg Hutter
8d0aca42e9 Refactor EWALD input for TB Methods, new defaults 2019-03-19 09:15:06 +01:00
Juerg Hutter
bac399e1d9 Bug fixes atomic properties, regtests,
refactoring of post scf routines and QMMM
2019-03-19 09:15:06 +01:00
Juerg Hutter
3930a97b4e Bug fixes for stress tensor, new regtests 2019-03-19 09:15:06 +01:00
Juerg Hutter
99c43e5748 Further refactoring and bug fixes, regtests 2019-03-19 09:15:06 +01:00
Juerg Hutter
c41e13904a
Ewald DFTB stress and atomic stress bug fix (#178)
* Ewald TB stress and atomic stress bug fix

* Update regtests
2019-01-16 16:44:12 +01:00
Juerg Hutter
0b6849bd91 Further refactoring of DFTB, regtests 2019-01-10 19:09:51 +01:00
Ole Schütt
1eb8f5e7a1 Prettify TEST_FILES 2018-10-10 21:23:50 +02:00
Jürg Hutter
011b6b7138 Don't use minimum image convention in DFTB, reset regtests
svn-origin-rev: 18253
2018-02-06 16:36:31 +00:00
Jürg Hutter
cbaabe39a4 DFTB: Option to define Lmax from input (Kind section)
DFTB: Resort to spline potential if Polynomial is not meaningful


svn-origin-rev: 16443
2015-12-16 15:00:09 +00:00
Jürg Hutter
2c04fd3786 Reset Semi-Empirical tests for FULL_GRID k-points
svn-origin-rev: 16397
2015-12-02 13:02:52 +00:00
Samuel Andermatt
4ffb12b94d rtp/emd: Make output have more digits
svn-origin-rev: 16063
2015-10-07 06:59:08 +00:00
Joost VandeVondele
c8a8a61df9 adjust tol for -mno-sse2
svn-origin-rev: 15876
2015-09-11 06:14:45 +00:00
Ole Schütt
bb17fff6cb prettify TEST_FILES files
svn-origin-rev: 15777
2015-08-28 11:26:53 +00:00
Ole Schütt
12cb806831 Fix more regtest references
svn-origin-rev: 15776
2015-08-28 11:21:42 +00:00
Joost VandeVondele
eeabc7f535 adjust tol
svn-origin-rev: 15570
2015-07-07 13:06:28 +00:00
Jürg Hutter
c42a7ba74c K-points: new functionality (DFTB) and bug fixes
svn-origin-rev: 15499
2015-06-22 15:14:00 +00:00