Skip to main content

cp2k-rs

Rust and Python bindings for CP2K, the electronic-structure and ab initio molecular-dynamics package.

Documentation · Examples · Changelog · Issues

pip install "cp2k-rs[ase]"
from ase.build import molecule
from ase.optimize import BFGS
from cp2k_rs.ase import CP2K

atoms = molecule("H2O")
atoms.center(vacuum=4.0)

with CP2K(nproc=4) as calc:           # CP2K on 4 MPI ranks
    atoms.calc = calc
    BFGS(atoms).run(fmax=0.05)        # each step reuses the force environment

No CP2K installation, no BLAS/LAPACK/FFTW/ScaLAPACK to build, no mpi4py in your script.

What it gives you

One command to install. The wheel is ~0.6 MB; a pre-built, statically linked worker binary carrying CP2K and its whole numerical stack is fetched on first use. The default CPU worker needs only your C library and host MPI; CUDA/ROCm workers additionally need their matching runtime, and the opt-in Skala worker needs a compatible PyTorch installation.

MPI without mpi4py. CP2K runs in a separate worker process. Rank 0 talks to your Python process over a Unix-domain socket and broadcasts commands to the other ranks, so an ordinary script drives a fully parallel calculation.

Errors you can catch. Most libcp2k functions return void and call MPI_ABORT on failure. cp2k-rs isolates CP2K, detects the abort and raises a typed exception instead of taking your process down with it.

More than energies and forces. Eigenvalues, HOMO–LUMO gaps, Mulliken and Hirshfeld charges, the electron density on the real-space grid, MO coefficients, and the AO overlap and Kohn–Sham matrices — dense or sparse, at Γ and at arbitrary k-points.

For advanced calculations, Python can also render a complete typed CP2K input tree. The package includes GauXC and SIRIUS plane-wave DFT, plus optional static backends such as DFT-D4, tblite, PLUMED, GreenX, TREXIO and libvdwxc.

Supported platforms

Linux on x86-64 (glibc), with MPI on the host. macOS and Windows are not supported: the worker links CP2K, OpenBLAS, ScaLAPACK, ELPA, SIRIUS and about twenty other libraries statically against glibc and the GCC Fortran runtime.

sudo dnf install openmpi && module load mpi/openmpi-x86_64   # Fedora / RHEL
sudo apt install openmpi-bin                                 # Debian / Ubuntu

Published worker variants: v3 (AVX2, default), v4 (AVX-512), CUDA, ROCm, and Skala for machine-learned functionals. See Installation.

Using it from Rust

use cp2k_rs::{init, finalize, ForceEnv};

init()?;
let mut force_env = ForceEnv::new("input.inp", "output.out")?;
force_env.calc_energy_force()?;
println!("{:.10} Ha", force_env.get_potential_energy()?);
finalize()?;
cp2k-rs = { version = "0.3", features = ["mpi", "extended", "build-cp2k"] }

See Using cp2k-rs from Rust.

Building from source

Only needed to develop cp2k-rs or to target an architecture with no published worker — pip install cp2k-rs is the supported path for using it.

module load mpi/openmpi-x86_64
cargo build --release --features mpi,extended,build-cp2k

The first build compiles CP2K and every dependency from source: ~8 GB of disk and 10–15 minutes. Full instructions, build-control variables and GPU builds are in Building from source.

NOTICE lists every statically linked library with its version and upstream source.

Contributing

See CONTRIBUTING.md and the test guide. Bug reports and merge requests are welcome on GitLab.

Citing

See CITATION.cff. Please cite CP2K itself as well — cp2k-rs is an interface, and the science is CP2K's.

License

GPL-2.0-or-later, the same as CP2K. Bundled dependencies keep their own licenses; see NOTICE.

Metadata

Release files for cp2k-rs 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for cp2k-rs 0.3.1
File
cp2k_rs-0.3.1-cp314-cp314-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64 Details
cp2k_rs-0.3.1-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details
cp2k_rs-0.3.1-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
cp2k_rs-0.3.1-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
cp2k_rs-0.3.1-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details
cp2k_rs-0.3.1-cp39-cp39-manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.28+ x86-64 Details

Total release size: 5.2 MB

Release files / cp2k_rs-0.3.1-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.1-cp314-cp314-manylinux_2_28_x86_64.whl
Size 853.0 kB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
54288878a5a052320949d0ca3b720e5d2449ba14dc30429f1d22dcdf7419563d
BLAKE2b-256 checksum
How to use checksums
7f59d001ab0048915a4fd6d8e97ac6aab0c2db08d7c6f7b88d6d9b2ccb4e7bad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / cp2k_rs-0.3.1-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.1-cp313-cp313-manylinux_2_28_x86_64.whl
Size 852.9 kB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8325ebb16848fee38804c2f9948a89f4146bfafe488fcdae2348ba6fcf0e0f0b
BLAKE2b-256 checksum
How to use checksums
b5c8eb3c8478b1da5693436ff97ab825ac2768049d311b0b2e870073865b90b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / cp2k_rs-0.3.1-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.1-cp312-cp312-manylinux_2_28_x86_64.whl
Size 857.4 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
430b577805c74da6f1d72d0fa87f16c54baffc1fcb9bb2582e046eceddf19bdb
BLAKE2b-256 checksum
How to use checksums
797046d0a9b683d53857ea3412c3dbfcd07536d0d5f9105c8e40d99fe0f6fda9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / cp2k_rs-0.3.1-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.1-cp311-cp311-manylinux_2_28_x86_64.whl
Size 864.3 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b392009af365eae05b90527b137a0bc1711fcfbb8aa3e2ac20dcaeb1d08af759
BLAKE2b-256 checksum
How to use checksums
3a46e9e4968ea70d1661bf9884e278135edbf04db788ecc163c64821cda55bcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / cp2k_rs-0.3.1-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.1-cp310-cp310-manylinux_2_28_x86_64.whl
Size 864.1 kB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
f6959f088eceb2bd34d248f9824861c39f635cca6e024b4adb78f738180dd925
BLAKE2b-256 checksum
How to use checksums
4a881998f1c4f068ca68155dadaae9f90ea44e7c9d741ba3564ebf7cee2b551b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / cp2k_rs-0.3.1-cp39-cp39-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.1-cp39-cp39-manylinux_2_28_x86_64.whl
Size 867.9 kB
Tags CPython 3.9 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
943c477a3b79cecdfb741cfd091235bd8a93ea1b4f744eb641379912deb7fd78
BLAKE2b-256 checksum
How to use checksums
4de4a173aba57f14c9eb79ac9568c89d0f5d8a644b1558fe3bcadc0fdaf0d35e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release history Release notifications | RSS feed

This release

0.3.1 This release

6 release files

0.3.0

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page