SkillAgentSearch skills...

Dftd4

Generally Applicable Atomic-Charge Dependent London Dispersion Correction

Install / Use

/learn @dftd4/Dftd4

README

DFT-D4 project

License Latest Version Build Status Documentation Status docs codecov

Generally Applicable Atomic-Charge Dependent London Dispersion Correction.

Installing

A statically linked binary distribution for Linux platforms is available at the latest release tag.

Conda package

Conda Version Conda Version

This project is packaged for the conda package manager and available on the conda-forge channel. To install the conda package manager we recommend the miniforge installer. If the conda-forge channel is not yet enabled, add it to your channels with

conda config --add channels conda-forge

Once the conda-forge channel has been enabled, this project can be installed with:

conda install dftd4

If you want to enable the Python API as well install

conda install dftd4-python

It is possible to list all of the versions available on your platform with:

conda search dftd4 --channel conda-forge

Now you are ready to use dftd4.

Spack package

Spack

This project is available with spack in its develop version. You can install and load dftd4 with

spack install dftd4
spack load dftd4

The Python API can be enabled by adding +python to the command.

FreeBSD Port

FreeBSD port

A port for FreeBSD is available and can be installed using

pkg install science/dftd4

In case no package is available build the port using

cd /usr/ports/science/dftd4
make install clean

For more information see the dftd4 port details.

Building from Source

To build this project from the source code in this repository you need to have a Fortran compiler supporting Fortran 2008 and one of the supported build systems:

  • meson version 0.55 or newer, with a build-system backend, i.e. ninja version 1.7 or newer
  • cmake version 3.14 or newer, with a build-system backend, i.e. ninja version 1.10 or newer
  • fpm version 0.2.0 or newer

Currently this project supports GCC and Intel compilers.

<details> <summary>Problematic Versions</summary>

GCC versions 15.0.x - 15.1.x contain a compiler bug leading to "Interface mismatch" errors during compilation.

</details>

Building with meson

To compile this version of DFT-D4 with meson the following programs are needed (the number in parentheses specifies the tested versions).

To build this project from the source code in this repository you need to have

  • a Fortran compiler supporting Fortran 2008
  • meson version 0.55 or newer
  • a build-system backend, i.e. ninja version 1.7 or newer
  • a LAPACK / BLAS provider, like MKL or OpenBLAS

Optional dependencies are

  • asciidoctor to build the manual page
  • FORD to build the developer documentation
  • C compiler to test the C-API and compile the Python extension module
  • Python 3.6 or newer with the CFFI package installed to build the Python API

Setup a build with

meson setup _build

You can select the Fortran compiler by the FC environment variable. To compile and run the projects testsuite use

meson test -C _build --print-errorlogs

If the testsuite passes you can install with

meson configure _build --prefix=/path/to/install
meson install -C _build

This might require administrator access depending on the chosen install prefix.

Building with CMake

Alternatively, this project can be build with CMake (in this case ninja 1.10 or newer is required):

cmake -B _build -G Ninja -DCMAKE_INSTALL_PREFIX=$HOME/.local

To compile the project with CMake run

cmake --build _build

You can run the project testsuite with

ctest --test-dir _build --parallel --output-on-failure

Finally, you can install the project to the selected prefix

cmake --install _build

Note that the CMake build does not support to build the Python extension module as part of the main build.

Building with fpm

This project support the Fortran package manager (fpm). Invoke fpm in the project root with

fpm build

To run the testsuite use

fpm test

You can access the dftd4 program using the run subcommand

fpm run -- --help

To use dftd4 for testing include it as dependency in your package manifest

[dependencies]
dftd4.git = "https://github.com/dftd4/dftd4"

Note that the fpm build does not support exporting the C-API, it only provides access to the standalone binary.

Usage

DFT-D4 calculations can be performed with the dftd4 executable. To calculate the dispersion correction for PBE0-D4 run:

dftd4 --func pbe0 coord

In case you want to access the DFT-D4 results from other programs, dump the results to JSON with (the --noedisp flag prevents the .EDISP file generation):

dftd4 --func pbe0 --json --grad --noedisp struct.xyz

Dispersion related properties can be calculated as well:

dftd4 --property geo.gen

To evaluate pairwise resolved dispersion energies use

dftd4 --pair-resolved mol.xyz

For an overview over all command line arguments use the --help argument or checkout the dftd4(1) manpage.

Parallelism

DFT-D4 calculations can be performed with shared-memory parallelism (OpenMP).

The number of parallel threads can be set through environment variables.

export OMP_NUM_THREADS=4
export MKL_NUM_THREADS=4  # Intel

For large calculations, additional speed-ups might be possible by enabling dynamic scheduling in OMP by setting OMP_SCHEDULE=dynamic. This might help particularly for versions <4.0.0 (explanation).

Note that DFT-D4 is not MPI parallelized, and there are currently no plans to implement MPI parallelism.

Parameters

DFT-D4 is parametrized for plenty of density functionals. The available parameters are listed in the parameters.toml file or with the following command.

dftd4 param --list

While the functionals can be selected with their common names (e.g., PBE), the libxc names can also be used (e.g., GGA_X_PBE:GGA_C_PBE).

dftd4 --func PBE coord
dftd4 --func GGA_X_PBE:GGA_C_PBE coord

The exchange and correlation functional must be separated by a colon. All names are case-insensitive.

<details> <summary>Note on ωB97X-type functionals</summary>

Since there has been some confusion concerning the different ωB97X functionals, we provide a detailed summary:

  • ωB97X (original functional, 2008, parameters: wb97x-2008)
  • ωB97X-D (re-optimization of ωB97X to include dispersion correction, 2008, no D4 parameters)
  • ωB97X-D3 (re-optimization of ωB97X-D with improved dispersion corrections, D3(0), 2013, no D4 parameters)
  • ωB97X-V (new functional, different from the above ωB97X's and not just a re-optimization for VV10 dispersion, 2013)
  • ωB97X-D4 (ωB97X-V with D4 dispersion instead of VV10 dispersion, parameters: wb97x)
  • ωB97X-D4rev (revised D4 parameters for ωB97X-V with D4 dispersion instead of VV10 dispersion, parameters: wb97x-rev)
  • ωB97X-3c (Composite "3c" method based on ωB97X-V, parameters: wb97x-3c)

Note that the ωB97X parameters (wb97x-2008) cannot be used for the ωB97X-V functional (wb97x, wb97x-rev).

We recommend the revised D4 parameters for ωB97X-V (wb97x-rev).

</details> <br>

You can add new functionals using to the TOML file by adding a new subtable

[parameter.name]
reference.doi = ["<functional reference>"]
d4.bj-eeq-atm = { s8=1.0, a1=0.4, a2=5.0, doi="<parameter reference>" }

Those parameters are currently only used as reference and not yet usable in the library or executable.

API access

The DFT-D4 project provides first class API support Fortran, C and Python. Other programming languages should try to interface with to DFT-D4 via one of those three APIs. To provide first class API support for a new language the interface specification should be available as meson build files.

The dftd4 binary provides with the --json option access to all quantities available from the APIs as well.

Fortra

Related Skills

View on GitHub
GitHub Stars208
CategoryDevelopment
Updated18h ago
Forks61

Languages

Fortran

Security Score

100/100

Audited on Mar 26, 2026

No findings