Skip to main content

Many-body dispersion library

Project description

Libmbd — many-body dispersion library

build coverage python release conda pypi commits since last commit license

This project contains implementations of the many-body dispersion (MBD) method in several programming languages and frameworks:

  • 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, and a C API. Furthermore, Python bindings to the C API are provided.
  • The Python/Numpy implementation is intended for prototyping, and as a high-level language reference.
  • The Python/Tensorflow implementation is an experiment that should enable rapid prototyping of machine learning applications with MBD.

The Python-based implementations as well as Python bindings to the Libmbd C API are accessible from the Python package called Pymbd.

Installing Pymbd

The easiest way to get Pymbd is to install the Pymbd Conda package, which ships with pre-built Libmbd.

conda install -c azag0 pymbd

Alternatively, if you have Libmbd installed on your system (see below), you can install Pymbd via Pip, in which case it links against the installed Libmbd. To support Libmbd built with ScaLAPACK/MPI, the MPI extras is required.

pip install pymbd  # or pymbd[MPI]

In both cases, tests can be run with Pytest.

pytest -v --durations=3 --pyargs pymbd

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

pip install pymbd --install-option="--no-ext"

Installing Libmbd

Libmbd uses CMake for building and installation, and requires a Fortran compiler, LAPACK, and optionally ScaLAPACK/MPI.

On Ubuntu:

apt-get install gfortran libblas-dev liblapack-dev [mpi-default-dev mpi-default-bin libscalapack-mpi-dev]

On macOS:

brew install gcc [open-mpi scalapack]

The building and installation can then proceed with

git clone https://github.com/azag0/libmbd.git && cd libmbd
mkdir build && cd build
cmake .. [-DENABLE_SCALAPACK_MPI=ON]
make
make install

This installs the Libmbd shared library, C API header file, and high-level Fortran API module file.

Tests can be run with

make check

Examples

from pymbd import mbd_energy_species, ang
from pymbd.fortran import MBDCalc

ene_py = mbd_energy_species(  # pure Python implementation
    [(0, 0, 0), (0, 0, 4*ang)], ['Ar', 'Ar'], [1, 1], 0.83
)
with MBDCalc() as calc:
    ene_f = calc.mbd_energy_species(  # Fortran implementation
        [(0, 0, 0), (0, 0, 4*ang)], ['Ar', 'Ar'], [1, 1], 0.83
    )
assert abs(ene_f-ene_py) < 1e-15
use mbd, only: mbd_input, mbd_calculation

type(mbd_input) :: inp
type(mbd_calculation) :: calc
real(dp) :: energy, gradients(3, 2)
integer :: code
character(200) :: origin, msg

inp%atom_types = ['Ar', 'Ar']
inp%coords = reshape([0d0, 0d0, 0d0, 0d0, 0d0, 7.5d0], [3, 2])
inp%xc = 'pbe'
call calc%init(inp)
call calc%get_exception(code, origin, msg)
if (code > 0) then
    print *, msg
    stop
end if
call calc%update_vdw_params_from_ratios([0.98d0, 0.98d0])
call calc%get_energy(energy)
call calc%get_gradients(gradients)
call calc%destroy()

Developing

For development, Libmbd doesn't have to be installed on the system, and Pymbd can be linked against Libmbd in ./build.

git clone https://github.com/azag0/libmbd.git && cd libmbd
mkdir build
(cd build && cmake .. -DENABLE_SCALAPACK_MPI=ON)
make -C build
make -C build check
python3 -m venv venv && source venv/bin/activate
pip install cffi numpy scipy mpi4py
python setup.py build_ext -i -Isrc -Lbuild/src -Rbuild/src
pytest -v --durations=3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymbd-0.4.0a8.tar.gz (31.3 kB view details)

Uploaded Source

File details

Details for the file pymbd-0.4.0a8.tar.gz.

File metadata

  • Download URL: pymbd-0.4.0a8.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for pymbd-0.4.0a8.tar.gz
Algorithm Hash digest
SHA256 eb2bcf709a51e0bc6f9e540130f803f2fb80b6744b373b60400ffadf8e800653
MD5 579c717cbc11d50f8774d1e152ccfaba
BLAKE2b-256 4e3f3ce4089165a030829c69594be5957c3d48ccca3271cf21896d627489a5f7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page