| 1 |
<h1 align="center"> |
| 2 |
<picture> |
| 3 |
<source media="(prefers-color-scheme: dark)" srcset="doc/_static/libmbd-lockup-dark.svg"> |
| 4 |
<img alt="libMBD" src="doc/_static/libmbd-lockup.svg" width="260"> |
| 5 |
</picture> |
| 6 |
</h1> |
| 7 |
|
| 8 |
[](https://github.com/libmbd/libmbd/actions/workflows/tests.yaml) |
| 9 |
[](https://codecov.io/gh/libmbd/libmbd) |
| 10 |
 |
| 11 |
[](https://anaconda.org/conda-forge/libmbd) |
| 12 |
[](https://pypi.org/project/pymbd/) |
| 13 |
[](https://github.com/libmbd/libmbd/releases) |
| 14 |
[](https://github.com/libmbd/libmbd/commits/master) |
| 15 |
[](https://github.com/libmbd/libmbd/blob/master/LICENSE) |
| 16 |
[](https://github.com/astral-sh/ruff) |
| 17 |
[](http://doi.org/k4bm) |
| 18 |
|
| 19 |
> libMBD: A general-purpose package for scalable quantum many-body dispersion calculations. [J. Hermann](https://github.com/jhrmnn), [M. Stöhr](https://github.com/martin-stoehr), S. Góger, [S. Chaudhuri](https://github.com/shaychaudhuri), [B. Aradi](https://github.com/aradi), [R. J. Maurer](https://github.com/reinimaurer1) & A. Tkatchenko. [*J. Chem. Phys.* **159**, 174802](http://doi.org/k4bm) (2023) |
| 20 |
|
| 21 |
libMBD implements the [many-body dispersion](http://dx.doi.org/10.1063/1.4865104) (MBD) method in several programming languages and frameworks: |
| 22 |
|
| 23 |
- The Fortran implementation is the reference, most advanced implementation, with support for analytical gradients and distributed parallelism, and additional functionality beyond the MBD method itself. It provides a low-level and a high-level Fortran API, as well as a C API. Furthermore, Python bindings to the C API are provided. |
| 24 |
- The Python/Numpy implementation is intended for prototyping, and as a high-level language reference. |
| 25 |
- The Python/Tensorflow implementation is an experiment that should enable rapid prototyping of machine learning applications with MBD. |
| 26 |
|
| 27 |
The Python-based implementations as well as Python bindings to the libMBD C API are accessible from the Python package called pyMBD. |
| 28 |
|
| 29 |
libMBD is included in [FHI-aims](https://aimsclub.fhi-berlin.mpg.de), [Quantum Espresso](https://www.quantum-espresso.org), [DFTB+](https://dftbplus.org), and [ESL Bundle](https://esl.cecam.org/en/bundle/). |
| 30 |
|
| 31 |
## Installing |
| 32 |
|
| 33 |
**TL;DR** Install prebuilt libMBD binaries via [Conda-forge](https://conda-forge.org) and pyMBD with [Pip](https://pip.pypa.io/en/stable/quickstart/). |
| 34 |
|
| 35 |
``` |
| 36 |
conda install -c conda-forge libmbd |
| 37 |
pip install pymbd |
| 38 |
``` |
| 39 |
|
| 40 |
One can also install the ScaLAPACK/MPI version. |
| 41 |
|
| 42 |
``` |
| 43 |
conda install -c conda-forge 'libmbd=*=mpi_*' mpi4py |
| 44 |
pip install pymbd[mpi] |
| 45 |
``` |
| 46 |
|
| 47 |
Verify installation with |
| 48 |
|
| 49 |
``` |
| 50 |
$ python -m pymbd |
| 51 |
Expected energy: -0.0002462647623815428 |
| 52 |
Calculated energy: -0.0002462647623817456 |
| 53 |
``` |
| 54 |
|
| 55 |
### libMBD |
| 56 |
|
| 57 |
libMBD uses CMake (≥ 3.22) for compiling and installing, and requires a Fortran compiler, LAPACK, and optionally ScaLAPACK/MPI. |
| 58 |
|
| 59 |
On Ubuntu: |
| 60 |
|
| 61 |
```bash |
| 62 |
apt-get install gfortran libblas-dev liblapack-dev [mpi-default-dev mpi-default-bin libscalapack-mpi-dev] |
| 63 |
``` |
| 64 |
|
| 65 |
On macOS: |
| 66 |
|
| 67 |
```bash |
| 68 |
brew install gcc [open-mpi scalapack] |
| 69 |
``` |
| 70 |
|
| 71 |
The compiling and installation can then proceed with |
| 72 |
|
| 73 |
``` |
| 74 |
cmake -B build [-DENABLE_SCALAPACK_MPI=ON] |
| 75 |
make -C build install |
| 76 |
[ctest --test-dir build] |
| 77 |
``` |
| 78 |
|
| 79 |
This installs the libMBD shared library, C API header file, high-level Fortran API module file, and Cmake package files, and optionally runs tests. |
| 80 |
|
| 81 |
### pyMBD |
| 82 |
|
| 83 |
pyMBD requires Python ≥ 3.10 and can be installed and updated using [Pip](https://pip.pypa.io/en/stable/quickstart/), but requires installed libMBD as a dependency (see above). |
| 84 |
|
| 85 |
``` |
| 86 |
pip install pymbd |
| 87 |
``` |
| 88 |
|
| 89 |
To support libMBD built with ScaLAPACK/MPI, the `mpi` extras is required, which installs `mpi4py` as an extra dependency. In this case one has to make sure that `mpi4py` is linked against the same MPI library as libMBD (for instance by compiling both manually, or installing both via Conda-forge). |
| 90 |
|
| 91 |
``` |
| 92 |
pip install pymbd[mpi] |
| 93 |
``` |
| 94 |
|
| 95 |
If libMBD is installed in a non-standard location, you can point pyMBD to it with |
| 96 |
|
| 97 |
``` |
| 98 |
env LIBMBD_PREFIX=<path to libMBD install prefix> pip install pymbd |
| 99 |
``` |
| 100 |
|
| 101 |
If you don’t need the Fortran bindings in pyMBD, you can install it without the C extension, in which case `pymbd.fortran` becomes unimportable: |
| 102 |
|
| 103 |
``` |
| 104 |
env LIBMBD_PREFIX= pip install pymbd |
| 105 |
``` |
| 106 |
|
| 107 |
|
| 108 |
## Examples |
| 109 |
|
| 110 |
```python |
| 111 |
from pymbd import mbd_energy_species |
| 112 |
from pymbd.fortran import MBDGeom |
| 113 |
|
| 114 |
# pure Python implementation |
| 115 |
energy = mbd_energy_species([(0, 0, 0), (0, 0, 7.5)], ['Ar', 'Ar'], [1, 1], 0.83) |
| 116 |
# Fortran implementation |
| 117 |
energy = MBDGeom([(0, 0, 0), (0, 0, 7.5)]).mbd_energy_species( |
| 118 |
['Ar', 'Ar'], [1, 1], 0.83 |
| 119 |
) |
| 120 |
``` |
| 121 |
|
| 122 |
```fortran |
| 123 |
use mbd, only: mbd_input_t, mbd_calc_t |
| 124 |
use iso_fortran_env, only: real64 |
| 125 |
|
| 126 |
type(mbd_input_t) :: inp |
| 127 |
type(mbd_calc_t) :: calc |
| 128 |
real(real64) :: energy, gradients(3, 2) |
| 129 |
integer :: code |
| 130 |
character(200) :: origin, msg |
| 131 |
|
| 132 |
inp%atom_types = ['Ar', 'Ar'] |
| 133 |
inp%coords = reshape([0d0, 0d0, 0d0, 0d0, 0d0, 7.5d0], [3, 2]) |
| 134 |
inp%xc = 'pbe' |
| 135 |
call calc%init(inp) |
| 136 |
call calc%get_exception(code, origin, msg) |
| 137 |
if (code > 0) then |
| 138 |
print *, msg |
| 139 |
stop 1 |
| 140 |
end if |
| 141 |
call calc%update_vdw_params_from_ratios([0.98d0, 0.98d0]) |
| 142 |
call calc%evaluate_vdw_method(energy) |
| 143 |
call calc%get_gradients(gradients) |
| 144 |
call calc%destroy() |
| 145 |
``` |
| 146 |
|
| 147 |
## Links |
| 148 |
|
| 149 |
- libMBD documentation: https://libmbd.nablapsi.science |
| 150 |
- pyMBD documentation: https://libmbd.nablapsi.science/pymbd |
| 151 |
|
| 152 |
## Developing |
| 153 |
|
| 154 |
For development, a top-level `Makefile` is included, which configures and compiles libMBD, compiles the pyMBD C extension, and runs both libMBD and pyMBD tests. |
| 155 |
|
| 156 |
``` |
| 157 |
git clone https://github.com/libmbd/libmbd.git && cd libmbd |
| 158 |
python3 -m venv venv && source venv/bin/activate |
| 159 |
make |
| 160 |
# development work... |
| 161 |
make |
| 162 |
``` |