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 libopenmpi3                     # 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.0

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.0
File
cp2k_rs-0.3.0-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.0-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.0-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.0-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.0-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.0-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.0-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.0-cp314-cp314-manylinux_2_28_x86_64.whl
Size 853.1 kB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
57bf6a0329331c0320cb3d8c8576c614293ed1fd2db9b2f2d4d107fc6d0dcc69
BLAKE2b-256 checksum
How to use checksums
284d2f64dae6f98c4de10035a6dab397a1a03585a3438d024fe944054b961221
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.0-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.0-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
eb3998357642e28c962fd7ef9fc1f347d56a7950fc28bc83cffc538791709498
BLAKE2b-256 checksum
How to use checksums
25ce6f42dd80de29911c7b27b1788edc99c532997df3f0915f97a021fc92b939
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.0-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl
Size 857.5 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
281d7c378788499392a7d4382d22f176cdcb420f1d466b489aac2506b81acf04
BLAKE2b-256 checksum
How to use checksums
fb59a9176d440256a52eccdf64e76d11543b754a6a454b7f73615558d6183293
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.0-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.0-cp311-cp311-manylinux_2_28_x86_64.whl
Size 864.4 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
641f12919c0f5f3e7672f2320d4d83763f9f35f21ab4b8c9bfe3eab680ff1dcb
BLAKE2b-256 checksum
How to use checksums
46cf5942f33401203aacb4d846991806901f19c7377550cf60bb7b65997ed180
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.0-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.0-cp310-cp310-manylinux_2_28_x86_64.whl
Size 864.2 kB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
9d8c17270e27a15be071646f54bd4e25d5e0fbaf03f0cd197fc8a6f193fdcda4
BLAKE2b-256 checksum
How to use checksums
3d67f08d292911bb9e730d99d4e5a1ac94ef3d853d7addf5b9a403e2ec6796d2
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.0-cp39-cp39-manylinux_2_28_x86_64.whl

Download URL cp2k_rs-0.3.0-cp39-cp39-manylinux_2_28_x86_64.whl
Size 867.6 kB
Tags CPython 3.9 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
9c7317d6c25ced725ef410dceea78d9f0ae3582a885c8c21efa472f3a9a54feb
BLAKE2b-256 checksum
How to use checksums
821cd93c2168033c13bd2932793a68ee16d8bd3854742efa290f239da6d3549e
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

0.3.1

6 release files

This release

0.3.0 This release

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