Commit graph

372 commits

Author SHA1 Message Date
Juerg Hutter
467dd45610
Native implementation for xTB spin polarisation (#5611) 2026-07-22 09:57:20 +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
Sebastian Wellig
8b1f5daa69
Add support for functions with multiple arguments to fparser 2026-02-04 10:40:02 +01:00
Hans Pabst
bfa518009f Adjusted tolerance
- Ubuntu, GCC 13 (ssmp).
2025-10-17 09:54:44 +02:00
BelizSertcan
51092d044b
Add tests for force constant 2025-09-12 09:43:02 +02:00
Ole Schütt
a9db95da33 Adjust tolerance of SE/regtest-2-1/hcl_ot.inp 2025-07-20 10:20:55 +02:00
Juerg Hutter
a2cdc0283b
Adjust regtests (#4142) 2025-04-16 12:23:35 +02:00
Juerg Hutter
e43e35a407
CG/Linesearch (#4141) 2025-04-15 20:13:30 +02:00
Ole Schütt
3d0b1c90e6 Tests: Convert TEST_TYPES to matchers.py 2025-03-01 19:07:38 +01:00
Matthias Krack
db61e8c41f Tag printout of the forces
- Make bar the default pressure unit like for the MD trajectory file
- Update regression test inputs (reference values and search strings)
2024-11-14 16:09:18 +01:00
Juerg Hutter
8e5fe4401f
gfn0-xTB and parallel DFT-D4 (#3765) 2024-11-08 17:48:34 +01:00
Ole Schütt
e47f988d92 Speedup SE/regtest-2-2/c2h5cl.inp 2024-10-27 00:20:17 +02:00
Ole Schütt
e3caab8e45 Adjust 5 regtests 2024-03-22 21:42:41 +01:00
Ole Schütt
2b6ea54d62 Format all input files 2023-12-18 22:41:19 +01:00
Matthias Krack
6292a7e94e Use the same EPS_SCF for inner and outer SCF loop 2023-12-11 14:26:50 +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
Ole Schütt
96b3c5ec5f MD: Refactor REFTRAJ / EVAL_ENERGY_FORCES keyword 2023-09-11 14:10:18 +02:00
Juerg Hutter
ad7b276f2d
New default settings for regtesting with DEBUG (#2889) 2023-08-02 15:16:24 +02:00
Matthias Krack
a3faa4464b Use ScaLAPACK library for test case 2021-05-15 23:08:00 +02:00
Ole Schütt
6a330cddb3 Remove tabs and trailing spaces 2021-03-11 20:06:46 +01:00
Matthias Krack
8605141417 Add COMPONENTS and drop NDIGITS keyword in stress tensor output, adjust regression test types and tolerances 2020-10-15 14:10:58 +02:00
Ole Schütt
a42c4d12de do_regtest: Make reference values mandatory 2020-01-28 12:07:44 +01:00
Ole Schütt
00acad58f2 Add reference value to SE/regtest-3-4/Al2O3.inp 2020-01-28 12:07:44 +01:00
Ole Schütt
757314a100 Adjust threshold of SE/regtest/st.inp 2020-01-20 17:11:21 +01:00
Tiziano Müller
502ab3a435 tests: raise tolerance for SE/regtest-3-2/SiO2
see #713
2020-01-08 18:25:34 +01:00
Eisuke Kawashima
e835aa6bda Unset executable flag [ci skip] 2019-11-20 14:47:56 +01:00
Ole Schütt
ab4c7a9ddb Adjust tolerance of SE/regtest-3-3/H2O-4.inp 2019-10-30 14:18:43 +01:00
Matthias Krack
6d0e192ef1 Update reference value 2019-09-13 11:44:25 +02:00
Matthias Krack
509d6ebe64 Stabilize SE h2o_vib test numerically 2019-09-13 11:44:25 +02:00
Juerg Hutter
f34d7e4980 Vib analysis non-distributed 2019-09-11 13:17:11 +02:00
Juerg Hutter
7863fcd744
Debug using finite field differences for dipole and polarizability. … (#549)
* Local energy for GPW method

* Local stress (1. step)

* Towards local stress

* Add stop for not yet implemented local stress

* Fix regtests

* Debug using finite field differences for dipole and polarizability.
Enable IR intensities for semi-empirical methods.

* More regtests for DEBUG option

* Bug fix on call to get_results
2019-09-11 10:32:55 +02:00
Juerg Hutter
5d92070080 Read cell information from CIF file 2019-01-25 12:17:47 +01:00
Ole Schütt
1eb8f5e7a1 Prettify TEST_FILES 2018-10-10 21:23:50 +02:00
Alfio Lazzaro
8b23bea459 Update Intel arch files popt and psmp
svn-origin-rev: 18319
2018-03-14 22:13:31 +00:00
Alfio Lazzaro
35b3579252 Update Intel arch files
svn-origin-rev: 18318
2018-03-14 12:11:23 +00:00
Iain Bethune
e1329759fd Couple of minor improvements in GAPW-related code
One regtest tolerance relaxed for OpenMP


svn-origin-rev: 16819
2016-04-15 14:29:11 +00:00
Iain Bethune
c3bcbb6686 Split SE/regtest-2 to speed up BG/Q regtest
svn-origin-rev: 16325
2015-11-16 14:52:11 +00:00
Joost VandeVondele
0907ae95c9 adjust tol
svn-origin-rev: 16085
2015-10-08 08:22:17 +00:00
Iain Bethune
36c89078b8 Optionally, omit the row/column headers and only print the contents
when printing sparse matrices (feature requested by user).
Enabled via the flag FORCE_EVAL%DFT%PRINT%AO_MATRICES%OMIT_HEADERS .
Added two new regtests using the flag.


svn-origin-rev: 15947
2015-09-23 14:22:35 +00:00
Joost VandeVondele
c8a8a61df9 adjust tol for -mno-sse2
svn-origin-rev: 15876
2015-09-11 06:14:45 +00:00
Joost VandeVondele
c9ea6e3942 adjust tol, restrict two at least two ranks
svn-origin-rev: 15851
2015-09-07 13:29:10 +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
f880d7a3df adjust tol
svn-origin-rev: 15771
2015-08-28 06:52:32 +00:00
Joost VandeVondele
4bcb82792d adjust tol
svn-origin-rev: 15770
2015-08-28 06:00:56 +00:00
Joost VandeVondele
8b2e08f2b5 adjust tol
svn-origin-rev: 15719
2015-08-20 08:59:43 +00:00
Joost VandeVondele
d9040a3905 adjust tol
svn-origin-rev: 15712
2015-08-19 10:24:48 +00:00
Joost VandeVondele
d64b5077a9 adjust tol
svn-origin-rev: 15709
2015-08-19 09:16:08 +00:00
Ole Schütt
401b4b7074 Adjust tolerance
svn-origin-rev: 15641
2015-07-31 15:39:01 +00:00
Ole Schütt
be1de0f33d Stabilize tests/SE/regtest/h2o_gks_e.inp
svn-origin-rev: 15534
2015-07-01 06:24:58 +00:00