CP2K-RS: Rust and Python bindings for CP2K
This project provides Rust bindings for the CP2K quantum chemistry package, with Python bindings generated using PyO3.
Requirements
- Rust toolchain (install via rustup)
- Git (for cloning CP2K)
- Fortran compiler (gfortran)
- MPI library (e.g., OpenMPI or MPICH)
- BLAS, LAPACK, and ScaLAPACK libraries
- Python 3.7+ (for Python bindings)
- Other CP2K dependencies:
- libxc
- libint
- FFTW
- zlib
Installing Dependencies on Ubuntu/Debian
Installing Dependencies on Fedora/RHEL/CentOS/Rocky Linux
After installation, you need to load the MPI module:
Building
Development Mode (Header-only)
For development and testing without building CP2K:
This mode uses only the CP2K headers and allows for fast compilation and testing of the Rust bindings.
Production Mode (With CP2K Library)
To build with the actual CP2K library for full functionality:
Option 1: Using the Build Script (Recommended)
This script will:
- Check all prerequisites
- Verify available disk space and resources
- Configure optimal build settings
- Guide you through the build process
Option 2: Manual Build with Environment Variable
CP2K_RS_BUILD_CP2K=1
Option 3: Manual Build with Feature Flag
⚠️ Important Notes:
- Building CP2K from source takes 30+ minutes on most systems
- Requires 4+ GB of free disk space
- Requires all CP2K dependencies to be installed (see requirements above)
- Uses parallel compilation (adjustable with
NUM_JOBS=Nenvironment variable)
Quick Test Build
To verify everything compiles without building CP2K:
With Python Bindings
Configuration
By default, CP2K is built with MPI and OpenMP support. If you want to customize the build, you can modify the build.rs file to specify different build options.
Using in Rust
use ;
Using in Python
# Initialize CP2K
# Get the CP2K version
=
# Create a force environment from input files
=
# Run some calculations
=
=
# Clean up
Troubleshooting
Development Mode Issues
If you encounter build issues in header-only mode:
- Make sure Rust toolchain is installed:
rustup update - Install basic dependencies:
sudo dnf install clang-devel llvm-devel(Rocky Linux) - For MPI features:
module load mpi/openmpi-x86_64
Production Mode (CP2K Build) Issues
Build Fails with Missing Dependencies
# Install all required dependencies first:
# Load MPI module
# Set library paths if needed
Build Takes Too Long
# Use fewer parallel jobs to reduce memory usage
NUM_JOBS=2 CP2K_RS_BUILD_CP2K=1
Out of Disk Space
CP2K compilation requires ~4GB of space. Clean up or use:
# Build in a different directory
Architecture-specific Issues
The build system creates architecture files for Linux x86_64. For other platforms:
- Check the CP2K documentation for platform-specific build instructions
- Modify the arch file generation in
build.rsif needed
General Issues
If you encounter other build issues:
- Make sure all dependencies are installed
- You may need to set the
LIBRARY_PATHandLD_LIBRARY_PATHenvironment variables to point to your MPI, BLAS, and LAPACK libraries - Check the CP2K documentation for platform-specific build instructions: https://github.com/cp2k/cp2k/blob/master/INSTALL.md
- For Rocky Linux specifically, ensure environment modules are loaded properly
Prerequisites for Building CP2K
Before attempting to build with CP2K, ensure you have:
-
Sufficient Resources:
- At least 4GB free disk space
- 8GB+ RAM recommended
- Multi-core CPU (build time scales with cores)
-
All Dependencies Installed:
# Rocky Linux/RHEL/CentOS # Load MPI environment -
Network Access: The build downloads CP2K source code and dependencies
Build Timeline
- First build: 30-60 minutes (depending on system)
- Subsequent builds: 5-15 minutes (incremental)
- Clean rebuild: 30-60 minutes
Verifying the Build
After building with CP2K support, verify it works:
# Run the example (requires the CP2K library)
# Run tests with CP2K support
If the build was successful, you should see:
- CP2K version information
- Successful force environment creation
- Energy and force calculations
License
This project is licensed under the GPL-2.0-or-later license, same as CP2K.