Skip to content

Commit 765064a

Browse files
authored
Merge branch 'develop' into ppcg
2 parents c1840ef + d83621a commit 765064a

96 files changed

Lines changed: 3361 additions & 1269 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Shell scripts and the bash-parsed integration-test case lists must keep LF
2+
# endings so they run under bash, including MSYS2/Git-Bash on Windows where
3+
# core.autocrlf may rewrite them to CRLF (which breaks `#!/bin/bash` and adds
4+
# stray \r to parsed lines such as the case names in CASES_*.txt).
5+
*.sh text eol=lf
6+
CASES_*.txt text eol=lf
7+
18
.gitattributes export-ignore
29
.gitignore export-ignore
310
.gitmodules export-ignore

.github/workflows/test.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ concurrency:
77
group: ${{ github.workflow }}-${{ github.ref }}
88
cancel-in-progress: true
99

10+
defaults:
11+
run:
12+
shell: bash
13+
1014
jobs:
1115
test:
1216
name: Test
@@ -32,12 +36,20 @@ jobs:
3236
- name: Install CI tools
3337
run: |
3438
sudo apt-get update
35-
sudo apt-get install -y ccache ca-certificates python-is-python3 python3-pip
39+
sudo apt-get install -y gfortran ccache ca-certificates python-is-python3 python3-pip
3640
sudo pip install clang-format clang-tidy
3741
42+
- name: Install dftd4 from toolchain
43+
run: |
44+
cd toolchain
45+
./install_abacus_toolchain_new.sh --with-dftd4=install --dry-run -j8
46+
./scripts/stage4/install_dftd4.sh
47+
cd ..
48+
3849
- name: Configure
3950
run: |
40-
cmake -B build -DBUILD_TESTING=ON -DENABLE_MLALGO=ON -DENABLE_LIBXC=ON -DENABLE_LIBRI=ON -DENABLE_GOOGLEBENCH=ON -DENABLE_RAPIDJSON=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DENABLE_FLOAT_FFTW=ON
51+
source toolchain/install/setup
52+
cmake -B build -DBUILD_TESTING=ON -DENABLE_MLALGO=ON -DENABLE_LIBXC=ON -DENABLE_LIBRI=ON -DENABLE_GOOGLEBENCH=ON -DENABLE_RAPIDJSON=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DENABLE_FLOAT_FFTW=ON -DENABLE_DFTD4=ON
4153
4254
# Temporarily removed because no one maintains this now.
4355
# And it will break the CI test workflow.

CMakeLists.txt

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ option(USE_ELPA "Enable ELPA for LCAO" ON)
3434
option(ENABLE_LIBRI "Enable LibRI for hybrid functional" OFF)
3535
option(ENABLE_LIBCOMM "Enable LibComm" OFF)
3636
option(ENABLE_PEXSI "Enable PEXSI for LCAO" OFF)
37+
option(ENABLE_DFTD4 "Enable DFT-D4 dispersion correction" OFF)
3738

3839
option(BUILD_TESTING "Build unittests" OFF)
3940
option(DEBUG_INFO "Print message to debug" OFF)
@@ -236,6 +237,18 @@ if(ENABLE_COVERAGE)
236237
add_coverage(${ABACUS_BIN_NAME})
237238
endif()
238239

240+
if(ENABLE_DFTD4)
241+
# DFTD4 requires enabling C and Fortran to work
242+
enable_language(C)
243+
enable_language(Fortran)
244+
# Avoid custom-lapack fallback when resolving DFT-D4 dependencies
245+
find_package(BLAS REQUIRED)
246+
find_package(LAPACK REQUIRED)
247+
find_package(dftd4 4.2.0 REQUIRED)
248+
if(NOT TARGET dftd4::dftd4)
249+
message(FATAL_ERROR "DFT-D4 was found, but target dftd4::dftd4 is missing.")
250+
endif()
251+
endif()
239252

240253
macro(set_if_higher VARIABLE VALUE)
241254
if(${VARIABLE} LESS ${VALUE})
@@ -268,7 +281,7 @@ if(ENABLE_ASAN)
268281
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
269282
endif()
270283

271-
if(NOT CMAKE_BUILD_TYPE)
284+
if(NOT CMAKE_BUILD_TYPE AND NOT MSVC)
272285
add_compile_options(-O3 -g)
273286
endif()
274287

@@ -289,6 +302,14 @@ if(ENABLE_NATIVE_OPTIMIZATION)
289302
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mtune=native")
290303
endif()
291304

305+
# Windows (native build, e.g. MinGW-w64 or MSVC) portability defines:
306+
# _USE_MATH_DEFINES - expose M_PI and friends from <cmath>
307+
# NOMINMAX - stop <windows.h> defining min()/max() macros
308+
# _CRT_SECURE_NO_WARNINGS - silence CRT "use _s function" deprecations
309+
if(WIN32)
310+
add_compile_definitions(_USE_MATH_DEFINES NOMINMAX _CRT_SECURE_NO_WARNINGS)
311+
endif()
312+
292313
if(ENABLE_LCAO)
293314
find_package(Cereal REQUIRED)
294315
include_directories(${CEREAL_INCLUDE_DIR})
@@ -610,8 +631,13 @@ elseif(NOT USE_SW)
610631
find_package(Lapack REQUIRED)
611632
include_directories(${FFTW3_INCLUDE_DIRS})
612633
list(APPEND math_libs FFTW3::FFTW3 LAPACK::LAPACK BLAS::BLAS)
613-
find_package(ScaLAPACK REQUIRED)
614-
list(APPEND math_libs ScaLAPACK::ScaLAPACK)
634+
# ScaLAPACK is a distributed-memory library and is only needed for the
635+
# MPI build. A serial build (e.g. the native Windows serial version)
636+
# must not require it.
637+
if(ENABLE_MPI)
638+
find_package(ScaLAPACK REQUIRED)
639+
list(APPEND math_libs ScaLAPACK::ScaLAPACK)
640+
endif()
615641
if(USE_OPENMP)
616642
list(APPEND math_libs FFTW3::FFTW3_OMP)
617643
endif()
@@ -869,16 +895,23 @@ if (USE_SW)
869895
list(APPEND math_libs gfortran)
870896
endif()
871897

872-
list(APPEND math_libs m)
898+
# libm exists on Linux and MinGW-w64 but not in the MSVC CRT.
899+
if(NOT MSVC)
900+
list(APPEND math_libs m)
901+
endif()
873902
target_link_libraries(${ABACUS_BIN_NAME} ${math_libs})
874903

875904
install(PROGRAMS ${ABACUS_BIN_PATH}
876905
TYPE BIN
877906
# DESTINATION ${CMAKE_INSTALL_BINDIR}
878907
)
879908

880-
# Create a symbolic link 'abacus' pointing to the actual executable
881-
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${ABACUS_BIN_NAME} ${CMAKE_INSTALL_PREFIX}/bin/abacus WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)")
909+
# Create a symbolic link 'abacus' pointing to the actual executable.
910+
# Skipped on Windows: symlink creation needs elevated/developer-mode
911+
# privileges there and the executable carries an .exe suffix anyway.
912+
if(NOT WIN32)
913+
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${ABACUS_BIN_NAME} ${CMAKE_INSTALL_PREFIX}/bin/abacus WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)")
914+
endif()
882915

883916
if(ENABLE_COVERAGE)
884917
coverage_evaluate()

cmake/FindBlas.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ if(DEFINED BLAS_LIBRARY)
55
set(BLAS_LIBRARIES ${BLAS_LIBRARY})
66
endif()
77

8+
# Delegate to CMake's builtin FindBLAS module. On case-insensitive
9+
# filesystems (Windows, macOS) this file "FindBlas.cmake" and the builtin
10+
# "FindBLAS.cmake" resolve to the same name, so a plain find_package(BLAS)
11+
# recurses into this very file. Temporarily remove our module directory
12+
# from CMAKE_MODULE_PATH so the builtin module is used instead. Harmless
13+
# no-op on case-sensitive filesystems.
14+
set(_abacus_blas_saved_module_path "${CMAKE_MODULE_PATH}")
15+
list(REMOVE_ITEM CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
816
find_package(BLAS REQUIRED)
17+
set(CMAKE_MODULE_PATH "${_abacus_blas_saved_module_path}")
918

1019
if(NOT TARGET BLAS::BLAS)
1120
add_library(BLAS::BLAS UNKNOWN IMPORTED)

cmake/FindLapack.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@ if(DEFINED LAPACK_LIBRARY)
66
set(LAPACK_LIBRARIES ${LAPACK_LIBRARY})
77
endif()
88

9+
# find_package(Blas) must resolve to our cmake/FindBlas.cmake wrapper, so
10+
# leave CMAKE_MODULE_PATH intact for it.
911
find_package(Blas REQUIRED)
12+
13+
# Delegate to CMake's builtin FindLAPACK module. As with FindBlas, the names
14+
# "FindLapack.cmake" and builtin "FindLAPACK.cmake" collide on
15+
# case-insensitive filesystems, so drop our module directory from
16+
# CMAKE_MODULE_PATH around the call to avoid infinite recursion.
17+
set(_abacus_lapack_saved_module_path "${CMAKE_MODULE_PATH}")
18+
list(REMOVE_ITEM CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
1019
find_package(LAPACK REQUIRED)
20+
set(CMAKE_MODULE_PATH "${_abacus_lapack_saved_module_path}")
1121

1222
if(NOT TARGET LAPACK::LAPACK)
1323
add_library(LAPACK::LAPACK UNKNOWN IMPORTED)

docs/CITATIONS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,11 @@ The following references are required to be cited when using ABACUS. Specificall
4747
Sun, Liang, and Mohan Chen. "Machine learning based nonlocal kinetic energy density functional for simple metals and alloys." Physical Review B 109.11 (2024): 115135.
4848

4949
Sun, Liang, and Mohan Chen. "Multi-channel machine learning based nonlocal kinetic energy density functional for semiconductors." Electronic Structure 6.4 (2024): 045006.
50+
51+
- **If DFT-D4 dispersion correction is used:**
52+
53+
Eike Caldeweyher, Sebastian Ehlert, Andreas Hansen, Hagen Neugebauer, Sebastian Spicher, Christoph Bannwarth, and Stefan Grimme. "A generally applicable atomic-charge dependent London dispersion correction." The Journal of Chemical Physics 150, 154122 (2019). DOI: 10.1063/1.5090222.
54+
55+
Eike Caldeweyher, Jan-Michael Mewes, Sebastian Ehlert, and Stefan Grimme. "Extension and evaluation of the D4 London-dispersion model for periodic systems." Physical Chemistry Chemical Physics 22, 8499-8512 (2020). DOI: 10.1039/D0CP00502A.
56+
57+
Nikolay V. Tkachenko, Linus B. Dittmer, Rebecca Tomann, and Martin Head-Gordon. "Smooth D4S model." The Journal of Physical Chemistry Letters 15, 10629-10637 (2024). DOI: 10.1021/acs.jpclett.4c02653.

docs/advanced/input_files/input-main.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@
396396
- [sc\_scf\_thr](#sc_scf_thr)
397397
- [vdW correction](#vdw-correction)
398398
- [vdw\_method](#vdw_method)
399+
- [vdw\_d4\_xc](#vdw_d4_xc)
400+
- [vdw\_d4\_model](#vdw_d4_model)
399401
- [vdw\_s6](#vdw_s6)
400402
- [vdw\_s8](#vdw_s8)
401403
- [vdw\_a1](#vdw_a1)
@@ -3640,11 +3642,28 @@
36403642
- d2: Grimme's D2 dispersion correction method
36413643
- d3_0: Grimme's DFT-D3(0) dispersion correction method (zero-damping)
36423644
- d3_bj: Grimme's DFTD3(BJ) dispersion correction method (BJ-damping)
3645+
- d4: Grimme's DFT-D4 dispersion correction method using the external DFT-D4 library
36433646
- none: no vdW correction
36443647

36453648
> Note: ABACUS supports automatic setting of DFT-D3 parameters for common functionals. To benefit from this feature, please specify the parameter dft_functional explicitly, otherwise the autoset procedure will crash. If not satisfied with the built-in parameters, any manual setting on vdw_s6, vdw_s8, vdw_a1 and vdw_a2 will overwrite the automatic values.
3649+
3650+
> Note: DFT-D4 support requires ABACUS to be configured with ENABLE_DFTD4=ON and a CMake-installed dftd4 library exporting dftd4-config.cmake. DFT-D4 damping parameters are loaded from the external library.
36463651
- **Default**: none
36473652

3653+
### vdw_d4_xc
3654+
3655+
- **Type**: String
3656+
- **Availability**: *vdw_method is set to d4*
3657+
- **Description**: Functional name passed to the DFT-D4 library to load its internal damping parameters. If set to default, ABACUS infers the functional name from dft_functional or pseudopotential metadata.
3658+
- **Default**: default
3659+
3660+
### vdw_d4_model
3661+
3662+
- **Type**: String
3663+
- **Availability**: *vdw_method is set to d4*
3664+
- **Description**: DFT-D4 dispersion model used by the external DFT-D4 library. Available options are d4 for the standard D4 model and d4s for the smooth D4S model.
3665+
- **Default**: d4
3666+
36483667
### vdw_s6
36493668

36503669
- **Type**: String
@@ -3737,7 +3756,7 @@
37373756

37383757
- **Type**: String
37393758
- **Availability**: *vdw_cutoff_type is set to radius*
3740-
- **Description**: Defines the radius of the cutoff sphere when vdw_cutoff_type is set to radius. The default values depend on the chosen vdw_method.
3759+
- **Description**: Defines the cutoff radius when vdw_cutoff_type is set to radius. The default values depend on the chosen vdw_method. For DFT-D4, this controls the two-body dispersion cutoff, while the three-body cutoff is internally limited to the DFT-D4 default value of 40 Bohr.
37413760
- **Unit**: defined by vdw_radius_unit (default Bohr)
37423761

37433762
### vdw_radius_unit
@@ -3759,8 +3778,8 @@
37593778
### vdw_cn_thr
37603779

37613780
- **Type**: Real
3762-
- **Availability**: *vdw_method is set to d3_0 or d3_bj*
3763-
- **Description**: The cutoff radius when calculating coordination numbers.
3781+
- **Availability**: *vdw_method is set to d3_0, d3_bj, or d4*
3782+
- **Description**: The cutoff radius when calculating coordination numbers. The default is 40 Bohr for DFT-D3 and 30 Bohr for DFT-D4.
37643783
- **Default**: 40
37653784
- **Unit**: defined by vdw_cn_thr_unit (default: Bohr)
37663785

docs/advanced/install.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ These two libraries are added as submodules in the [deps](https://github.com/dee
7777

7878
If you prefer using manually downloaded libraries, provide `-DLIBRI_DIR=${path to your LibRI folder} -DLIBCOMM_DIR=${path to your LibComm folder}`.
7979

80+
81+
## Build with DFT-D4 support
82+
83+
ABACUS can use the external [DFT-D4](https://github.com/dftd4/dftd4) library for Grimme's DFT-D4 dispersion correction. DFT-D4 support is optional and disabled by default.
84+
85+
DFT-D4 must be built and installed with CMake, so that ABACUS can locate it through the exported `dftd4-config.cmake` package. Meson-built installations, including the Conda package of `dftd4`, are not supported unless they provide a compatible CMake package file.
86+
87+
To build ABACUS with DFT-D4 support, pass `-DENABLE_DFTD4=ON` to CMake and provide `CMAKE_PREFIX_PATH` environment variable.
88+
89+
In the input file, enable DFT-D4 with:
90+
91+
```text
92+
vdw_method d4
93+
vdw_d4_xc pbe
94+
vdw_d4_model d4 # or d4s for the smooth D4S model
95+
```
96+
97+
If `vdw_d4_xc` is set to `default`, ABACUS will infer the functional name from `dft_functional` or pseudopotential metadata and pass it to the DFT-D4 library. The `vdw_d4_model` keyword selects the dispersion model inside the DFT-D4 library; the default is `d4`, while `d4s` enables the smooth D4S model.
98+
8099
## Build Unit Tests
81100

82101
To build tests for ABACUS, define `BUILD_TESTING` flag. You can also specify path to local installation of [Googletest](https://github.com/google/googletest) by setting `GTEST_DIR` flags. If not found in local, the configuration process will try to download it automatically.

docs/parameters.yaml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,12 +3738,31 @@ parameters:
37383738
* d2: Grimme's D2 dispersion correction method
37393739
* d3_0: Grimme's DFT-D3(0) dispersion correction method (zero-damping)
37403740
* d3_bj: Grimme's DFTD3(BJ) dispersion correction method (BJ-damping)
3741+
* d4: Grimme's DFT-D4 dispersion correction method using the external DFT-D4 library
37413742
* none: no vdW correction
37423743
37433744
[NOTE] ABACUS supports automatic setting of DFT-D3 parameters for common functionals. To benefit from this feature, please specify the parameter dft_functional explicitly, otherwise the autoset procedure will crash. If not satisfied with the built-in parameters, any manual setting on vdw_s6, vdw_s8, vdw_a1 and vdw_a2 will overwrite the automatic values.
3745+
3746+
[NOTE] DFT-D4 support requires ABACUS to be configured with ENABLE_DFTD4=ON and a CMake-installed dftd4 library exporting `dftd4-config.cmake`. DFT-D4 damping parameters are loaded from the external library.
37443747
default_value: none
37453748
unit: ""
37463749
availability: ""
3750+
- name: vdw_d4_xc
3751+
category: vdW correction
3752+
type: String
3753+
description: |
3754+
Functional name passed to the DFT-D4 library to load its internal damping parameters. If set to default, ABACUS infers the functional name from dft_functional or pseudopotential metadata.
3755+
default_value: default
3756+
unit: ""
3757+
availability: vdw_method is set to d4
3758+
- name: vdw_d4_model
3759+
category: vdW correction
3760+
type: String
3761+
description: |
3762+
DFT-D4 dispersion model used by the external DFT-D4 library. Available options are d4 for the standard D4 model and d4s for the smooth D4S model.
3763+
default_value: d4
3764+
unit: ""
3765+
availability: vdw_method is set to d4
37473766
- name: vdw_s6
37483767
category: vdW correction
37493768
type: String
@@ -3852,7 +3871,7 @@ parameters:
38523871
category: vdW correction
38533872
type: String
38543873
description: |
3855-
Defines the radius of the cutoff sphere when vdw_cutoff_type is set to radius. The default values depend on the chosen vdw_method.
3874+
Defines the cutoff radius when vdw_cutoff_type is set to radius. The default values depend on the chosen vdw_method. For DFT-D4, this controls the two-body dispersion cutoff, while the three-body cutoff is internally limited to the DFT-D4 default value of 40 Bohr.
38563875
default_value: ""
38573876
unit: defined by vdw_radius_unit (default Bohr)
38583877
availability: vdw_cutoff_type is set to radius
@@ -3878,10 +3897,10 @@ parameters:
38783897
category: vdW correction
38793898
type: Real
38803899
description: |
3881-
The cutoff radius when calculating coordination numbers.
3900+
The cutoff radius when calculating coordination numbers. The default is 40 Bohr for DFT-D3 and 30 Bohr for DFT-D4.
38823901
default_value: "40"
38833902
unit: "defined by vdw_cn_thr_unit (default: Bohr)"
3884-
availability: vdw_method is set to d3_0 or d3_bj
3903+
availability: vdw_method is set to d3_0, d3_bj, or d4
38853904
- name: vdw_cn_thr_unit
38863905
category: vdW correction
38873906
type: String

source/source_base/fs_compat.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef MODULEBASE_FS_COMPAT_H
2+
#define MODULEBASE_FS_COMPAT_H
3+
4+
//==========================================================
5+
// Small filesystem-portability helpers.
6+
//
7+
// The POSIX `mkdir(path, mode)` takes a permission-mode argument that
8+
// does not exist in the Windows CRT (`_mkdir`/MinGW `mkdir` take only a
9+
// path). This header provides a single cross-platform directory-creation
10+
// helper so call sites stay identical on every platform.
11+
//==========================================================
12+
13+
#include <cerrno>
14+
#include <string>
15+
16+
#ifdef _WIN32
17+
#include <direct.h> // _mkdir
18+
#else
19+
#include <sys/stat.h> // mkdir
20+
#include <sys/types.h>
21+
#endif
22+
23+
namespace ModuleBase
24+
{
25+
26+
/**
27+
* @brief Create a single directory, portably.
28+
*
29+
* @param path directory path to create
30+
* @return 0 on success; -1 on failure with `errno` set (e.g. EEXIST when
31+
* the directory already exists), matching POSIX `mkdir` semantics.
32+
*
33+
* On Windows the permission mode is not applicable and is ignored; on
34+
* POSIX systems the directory is created with mode 0755 (subject to umask),
35+
* preserving the previous behaviour of the call sites.
36+
*/
37+
inline int make_directory(const std::string& path)
38+
{
39+
#ifdef _WIN32
40+
return _mkdir(path.c_str());
41+
#else
42+
return mkdir(path.c_str(), 0755);
43+
#endif
44+
}
45+
46+
} // namespace ModuleBase
47+
48+
#endif // MODULEBASE_FS_COMPAT_H

0 commit comments

Comments
 (0)