A standalone CP2K calculator plugin for the Atomic Simulation Environment (ASE).
- Full CP2K calculator implementation compatible with ASE
- ASE v4 plugin system integration
- Support for ASE configuration system (
ase.config)
git clone https://github.com/cp2k/cp2k_ase_plugin.git
cd cp2k_plugin
pip install -e .- ASE >= 3.23.0 (https://docs.ase-lib.org/install.html) currently using (https://gitlab.com/ase/ase/-/tree/ase4-plugins-all-calculators)
- CP2K (https://github.com/cp2k/cp2k/blob/master/INSTALL.md)
Important: Always specify a working directory via directory=... to keep output files.
If directory=None (the default), a temporary directory is created and auto-cleaned on close().
from ase._4.plugins import plugins
CP2K = plugins.calculators['cp2k'].implementation()
calc = CP2K(directory="/path/to/output")from cp2k_plugin import CP2K
calc = CP2K(directory="/path/to/output")The CP2K executable is launched via CP2K-shell (the interactive socket-mode variant used for ASE communication). The plugin uses the following priority order to locate the command:
calc = CP2K(command="mpiexec -np 4 cp2k.psmp -s")CP2K.command = "mpiexec -np 4 cp2k.psmp -s"
calc = CP2K()Set in ~/.config/ase/config.ini:
[cp2k]
cp2k_shell = env OMP_NUM_THREADS=1 mpiexec -np 4 /path/to/cp2k.psmp -s
cp2k_main = env OMP_NUM_THREADS=1 mpiexec -np 4 /path/to/cp2k.psmpThe cp2k_main setting is used for tests that run CP2K directly (e.g., DCD file generation).
export ASE_CP2K_COMMAND="mpiexec -np 4 cp2k.psmp -s"If none of the above is set, the plugin defaults to:
cp2k.psmp -s
Note: The command must be resolvable via $PATH or given as an absolute path.
The plugin does not search for the executable automatically.
The default command cp2k.psmp -s launches CP2K-shell in shell mode.
For file-I/O mode (batch-style), you may want to use e.g.:
cp2k.psmp -i PREFIX.inp -o PREFIX.outHowever, the CP2K calculator is designed around CP2K-shell and the
-s flag is required for full functionality.
If you use this plugin in your research, please cite:
- M. Iannuzzi et al., "The CP2K Program Package Made Simple," J. Phys. Chem. B, vol. 130, pp. 1237, 2026, (https://doi.org/10.1021/acs.jpcb.5c05851)
- CP2K developers (https://www.cp2k.org/)
LGPL-2.1-or-later
See the doc/ directory for detailed documentation.
The tests require CP2K compiled with the toolchain. Any number of MPI processes should work, but large numbers can slow down the tests.
Set the CP2K executable in ~/.config/ase/config.ini:
[cp2k]
cp2k_shell = env OMP_NUM_THREADS=1 mpiexec -np 4 /path/to/build_cp2k/install/bin/cp2k.psmp -s
cp2k_main = env OMP_NUM_THREADS=1 mpiexec -np 4 /path/to/build_cp2k/install/bin/cp2k.psmpReplace /path/to/build_cp2k/install/bin/cp2k.psmp with your actual CP2K installation path.
Use OMP_NUM_THREADS=1 to avoid thread exhaustion.
# Activate ASE environment
source ~/venvs/ase/bin/activate
# Source CP2K environment (if using toolchain)
source /path/to/build_cp2k/install/cp2k_env
# Run tests
pytest tests/ -vContributions welcome! Please open an issue or submit a pull request.