0%

使用singularity容器化CP2K程序

依赖环境安装

宿主系统为Centos 7。

安装docker

参考官方安装文档即可。

docker可以更换为清华镜像源加快下载速度

1
2
3
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
yum makecache fast

安装singularity

参考官方安装教程

安装依赖

1
2
3
4
5
6
7
8
sudo yum groupinstall -y 'Development Tools'
sudo yum install -y \
wget \
libseccomp-devel \
glib2-devel \
squashfs-tools \
cryptsetup \
runc

安装Go

1
2
3
4
export VERSION=1.17.2 OS=linux ARCH=amd64 && \
wget https://dl.google.com/go/go$VERSION.$OS-$ARCH.tar.gz && \
sudo tar -C /usr/local -xzvf go$VERSION.$OS-$ARCH.tar.gz && \
go$VERSION.$OS-$ARCH.tar.gz
1
2
3
# 设置Go的环境变量
echo 'export PATH=/usr/local/go/bin:$PATH' >> ~/.bashrc && \
source ~/.bashrc

安装Singularity

1
2
3
4
5
# 下载源码
export VERSION=3.10.0 && \
wget https://github.com/sylabs/singularity/releases/download/v${VERSION}/singularity-ce-${VERSION}.tar.gz && \
tar -xzf singularity-ce-${VERSION}.tar.gz && \
cd singularity-ce-${VERSION}
1
2
3
4
# 编译源码
./mconfig && \
make -C builddir && \
sudo make -C builddir install

下载cp2k源码

github仓库地址:cp2k/cp2k: Quantum chemistry and solid state physics software package (github.com)

1
git clone -b support/v2022.1 --recursive https://github.com/cp2k/cp2k.git cp2k

编译docker镜像

1
2
cd cp2k/tools/docker
docker build -f Dockerfile.prod_psmp --build-arg GIT_COMMIT_SHA=$(git rev-parse HEAD) -t cp2k_prod_psmp ../../

sif 镜像转换

1
2
docker save cp2k_prod_psmp -o cp2k2022.tar 
singularity build cp2k2022.sif docker-archive://cp2k2022.tar

sif 镜像添加环境变量

解压镜像

1
singularity build --sandbox sandbox/ cp2k2022.sif

写入环境变量

1
2
3
4
5
6
7
8
9
10
11
12
13
vim sandbox/.singularity.d/env/90-environment.sh

source /opt/cp2k-toolchain/install/setup
export PATH=$PATH:/opt/cp2k/exe/local
export CP2K_DATA_DIR=/opt/cp2k/data
export OMP_NUM_THREADS=1

# add plumed environment
PLUMEDROOT=/opt/cp2k-toolchain/install/plumed-2.8.0/
export PATH=$PATH:$PLUMEDROOT/bin
export INCLUDE_PATH=$INCLUDE_PATH:$PLUMEDROOT/include
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PLUMEDROOT/lib
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$PLUMEDROOT/lib/pkgconfig

重新生成镜像

1
singularity build new.sif sandbox/

运行cp2k

1
2
SINGPATH=/your/cp2k/sif/file/path.sif
singularity exec -B ${PWD}:/mnt -H /mnt ${SINGPATH} mpirun -np 24 cp2k.psmp inp | tee ${2:-out.log}