### Install Dependencies (C) Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/guide/minimal-example.md Installs the necessary dependencies for running the C example, including the DFTD3 library, a C compiler, and pkg-config. ```text mamba create d3 simple-dftd3 c-compiler pkg-config mamba activate d3 ``` -------------------------------- ### Setup Build with Meson Source: https://github.com/dftd3/simple-dftd3/blob/main/README.md Use this command to set up the build environment for the project using Meson. Specify the installation prefix as needed. ```bash meson setup _build --prefix=/path/to/install ``` -------------------------------- ### Install Dependencies (Fortran) Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/guide/minimal-example.md Installs the necessary dependencies for running the Fortran example, including the DFTD3 library, a Fortran compiler, and pkg-config. ```text mamba create d3 simple-dftd3 fortran-compiler pkg-config mamba activate d3 ``` -------------------------------- ### Install Project with Meson Source: https://github.com/dftd3/simple-dftd3/blob/main/python/README.rst Configure the installation prefix and then install the compiled project using meson. ```sh meson configure _build --prefix=/path/to/install meson install -C _build ``` -------------------------------- ### Setup Meson Build Environment Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Configure a new build directory for Simple-DFT-D3 using Meson. This command sets up the build system and specifies the installation prefix. ```text meson setup _build --prefix=$HOME/.local ``` -------------------------------- ### Install with FPM Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Installs the project using fpm, specifying the profile and installation prefix. ```text fpm install --profile release --prefix $HOME/.local ``` -------------------------------- ### Install Dependencies (Python) Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/guide/minimal-example.md Installs the necessary dependencies for running the Python example, including the `dftd3-python` package. ```text mamba create d3 dftd3-python mamba activate d3 ``` -------------------------------- ### Run Example (Python) Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/guide/minimal-example.md Executes the Python example code to compute and print the dispersion energy. ```shell python energy.py ``` -------------------------------- ### Install Executable Source: https://github.com/dftd3/simple-dftd3/blob/main/app/CMakeLists.txt Installs the built executable to the specified binary directory. ```cmake install( TARGETS "${PROJECT_NAME}-exe" DESTINATION "${CMAKE_INSTALL_BINDIR}" ) ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/dftd3/simple-dftd3/blob/main/README.md Start a local HTTP server to view the generated documentation pages. Open the provided URL in a browser. ```bash python -m http.server -d _docs ``` -------------------------------- ### Install Pkgconfig File Source: https://github.com/dftd3/simple-dftd3/blob/main/config/CMakeLists.txt Installs the generated .pc file to the pkgconfig directory for system-wide package management. ```cmake install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) ``` -------------------------------- ### Configure Meson Installation Prefix Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Sets the installation prefix for the project when using Meson. ```sh meson configure _build --prefix=/path/to/install ``` -------------------------------- ### Install with CMake Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Installs the project after a successful CMake build. ```text cmake --install _build ``` -------------------------------- ### Run Example (C) Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/guide/minimal-example.md Compiles and runs the C example code. It uses pkg-config to obtain compiler and linker flags for the DFTD3 and MCTC libraries. ```shell $CC energy.c $(pkg-config s-dftd3 mctc-lib --cflags --libs) && ./a.out ``` -------------------------------- ### Install Simple-DFT-D3 with Meson Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Install the Simple-DFT-D3 project after successful compilation and testing using Meson. This makes the library available for use. ```text meson install -C _build ``` -------------------------------- ### Fortran Command Line Execution Example Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/tutorial/first-steps-fortran.md This example shows how to run the Fortran program from the command line, specifying the calculation method and molecular structures. The output displays calculated energies. ```text ❯ fpm run -- PBE0 1 dimer.xyz -1 monomer-a.xyz -1 monomer-b.xyz Energies in kJ/mol ------------------------------------------------------------------ method E(2) E(2+3) %E(3) ------------------------------------------------------------------ PBE0-D3(0) -4.591 -4.607 -0.350% ------------------------------------------------------------------ ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/dftd3/simple-dftd3/blob/main/README.md Install the necessary Python packages for building the main documentation pages using Sphinx. ```bash pip install -r doc/requirements.txt ``` -------------------------------- ### Install Package Config Files Source: https://github.com/dftd3/simple-dftd3/blob/main/config/CMakeLists.txt Installs the generated CMake package configuration and version files to the installation directory. ```cmake install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) ``` -------------------------------- ### Run Example (Fortran) Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/guide/minimal-example.md Compiles and runs the Fortran example code. It uses pkg-config to obtain compiler and linker flags for the DFTD3 and MCTC libraries. ```shell $FC energy.f90 $(pkg-config s-dftd3 mctc-lib --cflags --libs) && ./a.out ``` -------------------------------- ### Example Command Line Execution and Output Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/tutorial/first-steps-fortran.md Demonstrates how to run the parameter scanner with specific inputs and shows the expected output table comparing different D3 damping functions. ```text ❯ fpm run -- PBE0 1 dimer.xyz -1 monomer-a.xyz -1 monomer-b.xyz -0.012069608770 Energies in kJ/mol ------------------------------------------------------------------ method E(2) E(2+3) %E(3) ------------------------------------------------------------------ PBE0-D3(0) -36.280 -36.296 -0.044% PBE0-D3(BJ) -35.463 -35.479 -0.045% PBE0-D3M(BJ) -35.677 -35.693 -0.045% PBE0-D3(op) -35.616 -35.632 -0.045% ------------------------------------------------------------------ ``` -------------------------------- ### Meson Install License Data Source: https://github.com/dftd3/simple-dftd3/blob/main/docs.md Code to install Simple-DFT-D3 license files when linking statically. ```python install_data( sdftd3_prj.get_variable('sdftd3_lic'), install_dir: get_option('datadir')/'licenses'/meson.project_name()/'s-dftd3', ) ``` -------------------------------- ### Install CMake Module Directory Source: https://github.com/dftd3/simple-dftd3/blob/main/config/CMakeLists.txt Installs the 'cmake' directory from the source to the installation's lib/cmake/ location. ```cmake install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) ``` -------------------------------- ### Install Python Package with Pip Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Installs the project and its Python API using pip. ```sh pip install . ``` -------------------------------- ### Configure Pkgconfig File Source: https://github.com/dftd3/simple-dftd3/blob/main/config/CMakeLists.txt Configures the .pc file for pkgconfig using a template, preparing it for installation. ```cmake configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/template.pc" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY ) ``` -------------------------------- ### Install Python Extension from Git URL Source: https://github.com/dftd3/simple-dftd3/blob/main/python/README.rst Install the Python extension module directly from a Git repository URL if a conda-forge installation exists. ```sh pip install "https://github.com/dftd3/simple-dftd3/archive/refs/heads/main.zip#egg=dftd3-python&subdirectory=python" ``` -------------------------------- ### Install FORD for API Documentation Source: https://github.com/dftd3/simple-dftd3/blob/main/README.md Install the FORD tool, which is used for generating API documentation for the Fortran library. This command uses mamba for package management. ```bash mamba install ford ``` -------------------------------- ### Setup Meson Build Environment Source: https://github.com/dftd3/simple-dftd3/blob/main/python/README.rst Configure the out-of-tree build for the CFFI extension module using meson. Specify the Python version to use for the build. ```sh meson setup _build -Dpython_version=$(which python3) ``` -------------------------------- ### Install Python Package with Pip and Extra Dependencies Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Installs the project with pip, including extra dependencies like 'ase'. ```sh pip install '.[ase]' ``` -------------------------------- ### Meson Subproject Setup Source: https://github.com/dftd3/simple-dftd3/blob/main/docs.md Boilerplate code to include Simple-DFT-D3 as a subproject in Meson and retrieve its dependency. ```python sdftd3_prj = subproject( 's-dftd3', version: '>=0.1', default_options: [ 'default_library=static', ], ) sdftd3_dep = sdftd3_prj.get_variable('sdftd3_dep') ``` -------------------------------- ### Configure CMake Build Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Sets up a new build directory using CMake with the Ninja backend and specifies the installation prefix. ```text cmake -B _build -G Ninja -DCMAKE_INSTALL_PREFIX=$HOME/.local ``` -------------------------------- ### Fortran Command Line Execution with DFT Energy Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/tutorial/first-steps-fortran.md This example shows running the Fortran program with an additional DFT relative energy argument. The output reflects the updated energy calculations including the provided DFT energy. ```text ❯ fpm run -- PBE0 1 dimer.xyz -1 monomer-a.xyz -1 monomer-b.xyz -0.012069608770 Energies in kJ/mol ------------------------------------------------------------------ method E(2) E(2+3) %E(3) ------------------------------------------------------------------ PBE0-D3(0) -36.280 -36.296 -0.044% ------------------------------------------------------------------ ``` -------------------------------- ### Setup Meson Build for Python Extension Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Configures a Meson build for the Python extension module, specifying the Python version. ```sh meson setup _build_python python -Dpython_version=3 ``` -------------------------------- ### Install dftd3 via Pip Source: https://github.com/dftd3/simple-dftd3/blob/main/python/README.rst Install the dftd3 Python package using pip. Precompiled wheels are available for Linux on PyPI. ```sh pip install dftd3 ``` -------------------------------- ### Install Simple-DFT-D3 via Conda Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Install the Simple-DFT-D3 package using the mamba package manager after enabling the conda-forge channel. ```bash mamba install simple-dftd3 ``` -------------------------------- ### Install Simple-DFT-D3 with Python API via Conda Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Install Simple-DFT-D3 along with its Python API using mamba. This command ensures that the Python interface is available for use. ```bash mamba install dftd3-python ``` -------------------------------- ### QCSchema Integration for DFT-D3 Calculations Source: https://github.com/dftd3/simple-dftd3/blob/main/python/README.rst Integrate DFT-D3 with QCSchema by using the `run_qcschema` function. This requires the QCElemental package to be installed. The function takes an AtomicInput object and returns the calculation result. ```python from dftd3.qcschema import run_qcschema import qcelemental as qcel atomic_input = qcel.models.AtomicInput( molecule = qcel.models.Molecule( symbols = ["O", "H", "H"], geometry = [ 0.00000000000000, 0.00000000000000, -0.73578586109551, 1.44183152868459, 0.00000000000000, 0.36789293054775, -1.44183152868459, 0.00000000000000, 0.36789293054775 ], ), driver = "energy", model = { "method": "tpss", }, keywords = { "level_hint": "d3bj", }, ) atomic_result = run_qcschema(atomic_input) print(atomic_result.return_result) ``` -------------------------------- ### Install dftd3-python via Conda Source: https://github.com/dftd3/simple-dftd3/blob/main/python/README.rst Install the dftd3-python package using the conda package manager from the conda-forge channel. Ensure the conda-forge channel is enabled before installation. ```sh conda config --add channels conda-forge conda install dftd3-python ``` -------------------------------- ### Run QCSchema Calculation with DFTD3 Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/api/qcschema.md Demonstrates how to set up and run a QCSchema atomic input using the DFTD3 library. This snippet shows the creation of a molecule, specifying the driver and model, and executing the calculation. ```python >>> from dftd3.qcschema import run_qcschema >>> import qcelemental as qcel >>> atomic_input = qcel.models.AtomicInput( ... molecule = qcel.models.Molecule( ... symbols = ["O", "H", "H"], ... geometry = [ ... 0.00000000000000, 0.00000000000000, -0.73578586109551, ... 1.44183152868459, 0.00000000000000, 0.36789293054775, ... -1.44183152868459, 0.00000000000000, 0.36789293054775 ... ], ... ), ... driver = "energy", ... model = { ... "method": "TPSS-D3(BJ)", ... }, ... keywords = {}, ... ) ... >>> atomic_result = run_qcschema(atomic_input) >>> atomic_result.return_result -0.00042042440936212056 ``` -------------------------------- ### Fortran Main Program Structure for Parameter Scanning Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/tutorial/first-steps-fortran.md Sets up the main program for parameter scanning, including argument parsing and module imports. It checks for the minimum number of command-line arguments. ```fortran program param_scanner use mctc_env, only : wp, error_type, get_argument, fatal_error use mctc_io, only : structure_type, read_structure use d3_param_scan, only : reaction_type, scan_param_for_reaction implicit none type(reaction_type) :: reaction type(error_type), allocatable :: error character(:), allocatable :: method real(wp), allocatable :: dft_energy integer :: n_args, n_mol, iarg, imol n_args = command_argument_count() if (n_args < 3) then print '(a)', "Usage: param-scanner ... [dft energy]" stop 1 end if n_mol = (n_args - 1) / 2 call get_argument(1, method) allocate(reaction%mol(n_mol)) allocate(reaction%stochiometry(n_mol)) if (allocated(error)) then print '(a)', error%message stop 1 end if end program param_scanner ``` -------------------------------- ### Build Documentation with Sphinx Source: https://github.com/dftd3/simple-dftd3/blob/main/README.md Build the HTML documentation pages using Sphinx. The output will be placed in the _docs directory. ```bash sphinx-build doc _docs -b html ``` -------------------------------- ### Generate API Documentation with FORD Source: https://github.com/dftd3/simple-dftd3/blob/main/README.md Generate the API documentation for the Fortran library using FORD. The documentation will be output to the _api directory. ```bash ford docs.md -o _api ``` -------------------------------- ### Add conda-forge Channel Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Enable the conda-forge channel to access the Simple-DFT-D3 package. This is a prerequisite for installing via mamba. ```bash mamba config --add channels conda-forge ``` -------------------------------- ### Verify dftd3 Python Import Source: https://github.com/dftd3/simple-dftd3/blob/main/python/README.rst Check if the dftd3 library can be imported and retrieve the API version. This confirms a successful installation. ```python >>> import dftd3 >>> from dftd3.library import get_api_version >>> get_api_version() '1.4.0' ``` -------------------------------- ### Run Simple-DFT-D3 Benchmark Tests with Meson Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Run the extra test suite, including benchmarks, for Simple-DFT-D3 using Meson. This command is useful for performance testing. ```text meson test -C _build --print-errorlogs --benchmark ``` -------------------------------- ### Initialize and Calculate DFT-D3 Dispersion Energy and Gradients Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/api/pyscf.md Demonstrates initializing DFTD3Dispersion with a molecule, setting the exchange-correlation functional and dispersion version, and calculating the energy. It also shows how to change the dispersion version and activate three-body dispersion. ```python from pyscf import gto import dftd3.pyscf as disp mol = gto.M( atom=''' C -0.189833176 -0.645396435 0.069807761 C 1.121636324 -0.354065576 0.439096514 C 1.486520953 0.962572632 0.712107225 C 0.549329390 1.989209324 0.617868956 C -0.757627135 1.681862630 0.246856908 C -1.138190460 0.370551816 -0.028582325 Br -2.038462778 3.070459841 0.115165429 H 1.852935245 -1.146434699 0.514119204 H 0.825048723 3.012176989 0.829385472 H 2.502259769 1.196433556 1.000317333 H -2.157140187 0.151608161 -0.313181471 H -0.480820487 -1.664983631 -0.142918416 S -4.157443472 5.729584377 -0.878761129 H -4.823791426 4.796089466 -1.563433338 C -2.828338520 5.970593053 -2.091189515 H -2.167577293 6.722356639 -1.668621815 H -2.264954814 5.054835899 -2.240198499 H -3.218524904 6.337447714 -3.035087058 ''' ) d3 = disp.DFTD3Dispersion(mol, xc="PW6B95", version="d3bj") d3.kernel()[0] array(-0.01009386) d3.version = "d3zero" # Change to zero damping d3.kernel()[0] array(-0.00574098) d3.atm = True # Activate three-body dispersion d3.kernel()[0] array(-0.00574289) ``` -------------------------------- ### ASE DFTD3 Calculator with SumCalculator Source: https://github.com/dftd3/simple-dftd3/blob/main/python/README.rst Combine the DFTD3 calculator with other ASE calculators using SumCalculator for additive corrections. This example shows combining DFTD3 with NWChem. ```python from ase.build import molecule from ase.calculators.mixing import SumCalculator from ase.calculators.nwchem import NWChem from dftd3.ase import DFTD3 atoms = molecule('H2O') atoms.calc = SumCalculator([DFTD3(method="PBE", damping="d3bj"), NWChem(xc="PBE")]) ``` -------------------------------- ### Meson Wrap File Configuration Source: https://github.com/dftd3/simple-dftd3/blob/main/docs.md Configuration for a Meson wrap file to fetch Simple-DFT-D3 as a git submodule. ```ini [wrap-git] directory = s-dftd3 url = https://github.com/dftd3/simple-dftd3 revision = head ``` -------------------------------- ### Calculate DFT-D3 Energy with PySCF Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/api/pyscf.md This snippet shows how to calculate the total energy of a molecule with DFT-D3 dispersion corrections applied using PySCF. It requires PySCF and dftd3 to be installed. ```python >>> from pyscf import gto, scf >>> import dftd3.pyscf as disp >>> mol = gto.M( ... atom=''' ... N -1.57871857 -0.04661102 0.00000000 ... N 1.57871857 0.04661102 0.00000000 ... H -2.15862174 0.13639605 0.80956529 ... H -0.84947130 0.65819321 0.00000000 ... H -2.15862174 0.13639605 -0.80956529 ... H 2.15862174 -0.13639605 -0.80956529 ... H 0.84947130 -0.65819321 0.00000000 ... H 2.15862174 -0.13639605 0.80956529 ... ''' ... ) >>> mf = disp.d3_energy(scf.RHF(mol)).run() converged SCF energy = -110.932603617026 >>> mf.kernel() -110.93260361702605 ``` -------------------------------- ### Run Simple-DFT-D3 Test Suite with Meson Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Execute the test suite for Simple-DFT-D3 using Meson to verify the build. This command checks the correctness of the compiled project. ```text meson test -C _build --print-errorlogs ``` -------------------------------- ### Build with FPM Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Creates a new build using the Fortran Package Manager (fpm). ```text fpm build ``` -------------------------------- ### Calculate DFT-D3 Gradients with PySCF Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/api/pyscf.md This snippet demonstrates how to compute nuclear gradients for a molecule with DFT-D3 dispersion corrections applied using PySCF. Ensure PySCF and dftd3 are installed. ```python >>> from pyscf import gto, scf >>> import dftd3.pyscf as disp >>> mol = gto.M( ... atom=''' ... O -1.65542061 -0.12330038 0.00000000 ... O 1.24621244 0.10268870 0.00000000 ... H -0.70409026 0.03193167 0.00000000 ... H -2.03867273 0.75372294 0.00000000 ... H 1.57598558 -0.38252146 -0.75856129 ... H 1.57598558 -0.38252146 0.75856129 ... ''' ... ) >>> grad = disp.d3_energy(scf.RHF(mol)).run().nuc_grad_method() converged SCF energy = -149.947191000075 >>> g = grad.kernel() --------------- DFTD3 gradients --------------- x y z 0 O 0.0171886976 0.0506606246 0.0000000000 1 O 0.0383596853 -0.0459057549 0.0000000000 2 H -0.0313133974 -0.0125865676 -0.0000000000 3 H 0.0066705789 -0.0380501872 0.0000000000 4 H -0.0154527822 0.0229409425 0.0215141991 5 H -0.0154527822 0.0229409425 -0.0215141991 ---------------------------------------------- ``` -------------------------------- ### Test with FPM Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Runs the test suite for the fpm-built project. ```text fpm test ``` -------------------------------- ### Run Command Line Driver with FPM Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Executes the command line driver of the project directly through fpm, passing arguments like --help. ```text fpm run --profile release -- --help ``` -------------------------------- ### s-dftd3 Output with Citation Information Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/guide/citing.md This is an example of the output generated by the s-dftd3 command when the --citation flag is used. It includes the dispersion energy and information about where citation details are written. ```text ----------------------------------- s i m p l e D F T - D 3 v1.2.1 ----------------------------------- Rational (Becke-Johnson) damping: scan-D3(BJ) --------------------- s6 1.0000 s8 0.0000 s9 0.0000 a1 0.5380 a2 5.4200 alp 14.0000 -------------------- Dispersion energy: -1.0554287327920E-02 Eh [Info] Writing Dispersion energy to '.EDISP' [Info] Citation information written to 'dftd3.bib' ``` -------------------------------- ### PySCF DFTD3 Energy and Gradient Calculation Source: https://github.com/dftd3/simple-dftd3/blob/main/python/README.rst Apply a dispersion correction to an existing calculator using the energy method to obtain gradients. This example demonstrates calculating gradients for a water molecule. ```python >>> from pyscf import gto, scf >>> import dftd3.pyscf as disp >>> mol = gto.M( ... atom=""" O -1.65542061 -0.12330038 0.00000000 O 1.24621244 0.10268870 0.00000000 H -0.70409026 0.03193167 0.00000000 H -2.03867273 0.75372294 0.00000000 H 1.57598558 -0.38252146 -0.75856129 H 1.57598558 -0.38252146 0.75856129 """) >>> grad = disp.energy(scf.RHF(mol)).run().nuc_grad_method() converged SCF energy = -149.947191000075 >>> g = grad.kernel() --------------- DFTD3 gradients --------------- x y z 0 O 0.0171886976 0.0506606246 0.0000000000 1 O 0.0383596853 -0.0459057549 0.0000000000 2 H -0.0313133974 -0.0125865676 -0.0000000000 3 H 0.0066705789 -0.0380501872 0.0000000000 4 H -0.0154527822 0.0229409425 0.0215141991 5 H -0.0154527822 0.0229409425 -0.0215141991 ---------------------------------------------- ``` -------------------------------- ### Compile Simple-DFT-D3 with Meson Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Compile the Simple-DFT-D3 project after the build environment has been set up with Meson. This command builds the library and its components. ```text meson compile -C _build ``` -------------------------------- ### Compute Dispersion Energy with Rational Damping (Python) Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/guide/minimal-example.md Calculates the dispersion energy using the rational damping function in Python. This example utilizes the `dftd3-python` library to define molecular geometry and compute the energy. ```python import numpy as np from dftd3.interface import RationalDampingParam, DispersionModel num = np.array([6, 1, 1, 1, 1]) xyz = np.array( # coordinates in Bohr [ [ 0.0000000, -0.0000000, 0.0000000], [-1.1922080, 1.1922080, 1.1922080], [ 1.1922080, -1.1922080, 1.1922080], [-1.1922080, -1.1922080, -1.1922080], [ 1.1922080, 1.1922080, -1.1922080], ] ) method = "PBE0" model = DispersionModel(num, xyz) res = model.get_dispersion(RationalDampingParam(method=method), grad=False) print(f"Dispersion energy for {method}-D3(BJ) is {res['energy']:13.10f} Hartree") ``` -------------------------------- ### Build with CMake Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/installation.md Compiles the project using the CMake build system. ```text cmake --build _build ``` -------------------------------- ### Configure DFT-D3 with Python API using Meson Source: https://github.com/dftd3/simple-dftd3/blob/main/README.md Enable the Python API during the Meson configuration step. Specify the desired Python 3 executable to ensure compatibility. ```sh meson setup _build -Dpython=true -Dpython_version=$(which python3) ``` -------------------------------- ### Fortran DFT-D3 Calculation Example Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/api/fortran.md This subroutine calculates dispersion energy and gradients using DFT-D3(BJ)-ATM. It demonstrates the use of rational damping parameters and the `get_dispersion` function. Ensure the necessary modules (`mctc_env`, `mctc_io`, `dftd3`) are available. ```fortran subroutine calc_dftd3(mol, method, energy, gradient, sigma, error) use mctc_env, only : wp, error_type use mctc_io, only : structure_type use dftd3, only : d3_model, d3_param, rational_damping_param, & & get_rational_damping, new_rational_damping, new_d3_model, & & get_dispersion, realspace_cutoff type(structure_type), intent(in) :: mol character(len=*), intent(in) :: method real(wp), intent(out) :: energy real(wp), intent(out) :: gradient(:, :) real(wp), intent(out) :: sigma(:, :) type(error_type), allocatable, intent(out) :: error type(d3_model) :: disp type(d3_param) :: inp type(rational_damping_param) :: param call get_rational_damping(inp, method, error, s9=1.0_wp) if (allocated(error)) return call new_rational_damping(param, inp) call new_d3_model(disp, mol) call get_dispersion(mol, disp, param, realspace_cutoff(), energy, & & gradient, sigma) end subroutine calc_dftd3 ``` -------------------------------- ### fpm Dependency Configuration Source: https://github.com/dftd3/simple-dftd3/blob/main/docs.md Adding Simple-DFT-D3 as a dependency in an fpm.toml file. ```toml [dependencies] s-dftd3.git = "https://github.com/dftd3/simple-dftd3" ``` -------------------------------- ### Fortran Loop to Populate Reaction Data Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/tutorial/first-steps-fortran.md Iterates through command-line arguments to read stoichiometry coefficients and molecular structures, populating the `reaction` data type. Exits the loop if an error occurs. ```fortran imol = 0 do iarg = 1, 2 * n_mol, 2 imol = imol + 1 call read_real(iarg + 1, reaction%stochiometry(imol), error) if (allocated(error)) exit call read_mol(iarg + 2, reaction%mol(imol), error) if (allocated(error)) exit end do ``` -------------------------------- ### Fortran Implementation of Parameter Scanner Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/tutorial/first-steps-fortran.md Implements the parameter scanning subroutine, handling zero damping parameters and calculating dispersion energies. It uses error checking and parameter updates to evaluate different contributions. ```fortran subroutine scan_param_for_reaction(error, reaction, method, dft_energy) use mctc_env, only : error_type, fatal_error use dftd3, only : d3_param type(error_type), allocatable :: error type(reaction_type), intent(in) :: reaction character(*), intent(in) :: method real(wp), intent(in), optional :: dft_energy logical :: has_param(5) real(wp) :: disp_energies(2, 5) type(d3_param) :: inp integer, parameter :: zero_damping_idx = 1, rational_damping_idx = 2, & & mzero_damping_idx = 3, mrational_damping_idx = 4, op_damping_idx = 5 has_param(:) = .false. disp_energies(:, :) = 0.0_wp if (present(dft_energy)) disp_energies(:, :) = dft_energy zero_d: block use dftd3, only : zero_damping_param, get_zero_damping, new_zero_damping type(zero_damping_param) :: param call get_zero_damping(inp, method, error, s9=0.0_wp) if (allocated(error)) exit zero_d has_param(zero_damping_idx) = .true. call new_zero_damping(param, inp) call get_dispersion_for_reaction(reaction, param, disp_energies(1, zero_damping_idx)) inp%s9 = 1.0_wp call new_zero_damping(param, inp) call get_dispersion_for_reaction(reaction, param, disp_energies(2, zero_damping_idx)) end block zero_d if (allocated(error)) deallocate(error) end subroutine scan_param_for_reaction ``` -------------------------------- ### Link Libraries for Test Executable Source: https://github.com/dftd3/simple-dftd3/blob/main/test/unit/CMakeLists.txt Links the project's library and the 'mstore' library to the test executable, making them available for use during testing. ```cmake target_link_libraries( "${PROJECT_NAME}-tester" PRIVATE "${PROJECT_NAME}-lib" "mstore::mstore" ) ``` -------------------------------- ### C API: Calculation Entrypoints Source: https://github.com/dftd3/simple-dftd3/blob/main/doc/api/index.md Primary functions for performing dispersion and counterpoise calculations using the C API of DFT-D3. ```APIDOC ## C API: Calculation Entrypoints ### Description Entry points for performing dispersion and counterpoise calculations via the DFT-D3 C API. ### Functions - `dftd3_get_dispersion()` - `dftd3_get_pairwise_dispersion()` - `dftd3_get_counterpoise()` ```