Add optional DFT-D4 support#7380
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds DFT-D4 (Grimme) van der Waals dispersion support across the build/toolchain and the ABACUS runtime, including new input knobs and output reporting.
Changes:
- Toolchain: add DFT-D4 package/version wiring and a stage-4 installer script.
- Core: implement
vdw_method=d4via a newVdwd4backend calling the DFT-D4 C API and exposevdw_d4_xc. - Build/IO: add
ENABLE_DFTD4CMake option + linking, update energy/stress printing, and fix VDW stress output in LCAO.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| toolchain/toolchain_intel.sh | Adds WITH_DFTD4 option passthrough to toolchain installer. |
| toolchain/toolchain_gnu.sh | Adds WITH_DFTD4 option passthrough to toolchain installer. |
| toolchain/toolchain_gcc-mkl.sh | Adds WITH_DFTD4 option passthrough to toolchain installer. |
| toolchain/scripts/stage4/install_stage4.sh | Runs the new DFT-D4 stage4 install step. |
| toolchain/scripts/stage4/install_dftd4.sh | New installer for the DFT-D4 library. |
| toolchain/scripts/package_versions.sh | Adds DFT-D4 version + checksum + loader case. |
| toolchain/scripts/lib/version_helper.sh | Fixes export line formatting. |
| toolchain/scripts/lib/package_manager.sh | Declares DFT-D4 dependency and fixes formatting. |
| toolchain/scripts/lib/config_manager.sh | Adds dftd4 to package lists and default config. |
| toolchain/build_abacus_intel.sh | Enables DFT-D4 in ABACUS CMake invocation. |
| toolchain/build_abacus_gnu.sh | Enables DFT-D4 in ABACUS CMake invocation. |
| toolchain/build_abacus_gcc-mkl.sh | Enables DFT-D4 in ABACUS CMake invocation. |
| source/source_pw/module_ofdft/of_print_info.cpp | Prints D4 energy label when used. |
| source/source_lcao/FORCE_STRESS.cpp | Fixes VDW stress printing to use stress_vdw. |
| source/source_io/module_parameter/read_input_item_model.cpp | Adds d4 to vdw_method, introduces vdw_d4_xc, and adjusts D4 defaults. |
| source/source_io/module_parameter/input_parameter.h | Adds vdw_d4_xc input field. |
| source/source_hamilt/module_vdw/vdwd4.h | New DFT-D4 VdW backend header. |
| source/source_hamilt/module_vdw/vdwd4.cpp | New DFT-D4 backend implementation using the DFT-D4 C API. |
| source/source_hamilt/module_vdw/vdw.cpp | Adds vdw_method == "d4" factory path. |
| source/source_hamilt/module_vdw/CMakeLists.txt | Conditionally builds/links DFT-D4 backend when enabled. |
| source/source_estate/elecstate_print.cpp | Prints D4 energy label in total-energy reporting. |
| CMakeLists.txt | Adds ENABLE_DFTD4 option and wires find_package(dftd4)/link flags. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e5ed740 to
d408df1
Compare
|
Thanks for your contribution! The addition of the D4 vdW correction is greatly appreciated. However, we still require documentation explaining this new feature (put in the 'docs' directory), along with corresponding unit or integration tests to avoid future regressions. |
This comment was marked as resolved.
This comment was marked as resolved.
|
Maybe, we should begin using toolchain in "Integration Test and Unit Test" workflow, but only for dftd4. |
|
Unittest has been added at source/source_hamilt/module_vdw/test/vdw_test.cpp; Both are tested under "Integration Test and Unit Test" workflow with dftd4 library installed through toolchain. |
133660f to
8a9c6c9
Compare
|
Thanks, we will take a look. |
452d3eb to
7d1148f
Compare
mohanchen
left a comment
There was a problem hiding this comment.
This PR looks solid with the newly added D4 vdW functionality. However, thorough testing has not yet been completed. We recommend follow-up comprehensive validation going forward, and prompt communication for bug fixes should any issues arise.
|
Thank you very much for the approval! I would be very happy to receive feedback and help fix any issues that may arise. As a longer-term follow-up, I will also consider a more native ABACUS implementation of the core D4 components, especially the EEQ solver, so that the DFT-D4 correction in ABACUS can eventually be evaluated with MPI parallelism. |
Towards #5260.
This PR adds optional DFT-D4 support with both D4 and D4S model available through the external dftd4 package. ABACUS provides a thin wrapper that passes atomic numbers, Cartesian positions, lattice vectors, periodic flags, the functional name, and cutoff settings to the DFT-D4 library. The returned dispersion energy, gradient, and virial/sigma are converted to ABACUS energy, force, and stress units and injected through the existing vdW correction framework. DFT-D4 internal damping parameters are used; no D4 parameter table is maintained in ABACUS.
Here is a simple test that shows the consistency with reference binary: d4-test.zip
Note:
dftd4-config*.cmake(with environment variableCMAKE_PREFIX_PATH) without requiring a customFindDFTD4.cmakeon the ABACUS side. This indicates that the conda package of dftd4 (built with meson and does not provide CMake package files) would not be supported.with_dftd4is not set toinstallfor toolchain scripts regarding AMD compilers and math libs, because these build are not tested yet.