本文档详细介绍如何使用 Singularity 容器编译和安装 VASP 6.3.2。内容涵盖从环境准备、依赖安装到 VASP 编译的每一个步骤。
前提条件:
- 需要一个支持 Singularity 的 Linux 系统。
- 需要具备基础的 Linux 命令行操作知识。
- 需要 VASP 6.3.2 的源代码和相关文件。
一、创建Singularity容器文件
#指定容器的基础镜像路径,使用本地存储的 jammy_base 作为基础镜像。
Bootstrap: localimage
From: /mnt/softs/singularity_sifs/jammy_base
#在构建容器时设置初始工作目录,进入根文件系统的 /opt 目录。
%setup
cd $SINGULARITY_ROOTFS/opt
#将 VASP 源代码和配置文件复制到容器中,将 vasp.6.3.2.tgz 和多个makefile.include 文件从主机复制到容器的 /opt 目录。
%files
/mnt/softs/Softs_souce_code/vasp6.3.2/vasp.6.3.2.tgz /opt/vasp.6.3.2.tgz /mnt/softs/Softs_souce_code/vasp6.3.2/VASP.6.3.2_gnu_openmpi.makefile.include /opt/VASP.6.3.2_gnu_openmpi.makefile.include /mnt/softs/Softs_souce_code/vasp6.3.2/VASP.6.3.2_gnu.omp_openmpi.makefile.include /opt/VASP.6.3.2_gnu.omp_openmpi.makefile.include /mnt/softs/Softs_souce_code/vasp6.3.2/VASP.6.3.2_gnu_mpich.makefile.include /opt/VASP.6.3.2_gnu_mpich.makefile.include /mnt/softs/Softs_souce_code/vasp6.3.2/VASP.6.3.2_gnu.omp_mpich.makefile.include /opt/VASP.6.3.2_gnu.omp_mpich.makefile.include
# 记录构建日期并将其导出到环境变量中,并预安装设置和依赖包安装
%post
Build_date=`date`
echo "export Build_date=\"${Build_date}\"" >> $SINGULARITY_ENVIRONMENT
#使用中国科技大学的镜像源替换默认源,加速软件包的下载和更新。
apt update -y
apt install -y wget
cd /etc/apt/ && wget -O sources.list https://mirrors.ustc.edu.cn/repogen/conf/ubuntu-https-4-jammy
apt update -y && apt upgrade -y
#安装 VASP 依赖包
apt install -y build-essential cmake make gcc g++ gfortran clang-format pkgconf coreutils sudo apt-utils nano wget git ffmpeg
# openmpi
apt install -y libopenmpi-dev openmpi-bin openmpi-common
# ibrary for computing Fast Fourier Transforms
apt install -y libfftw3-dev libfftw3-3 libfftw3-mpi-dev
# Basic Linear Algebra Subroutines
apt install -y libblas-dev
# Library of linear algebra routines
apt install -y liblapack-dev
# Scalable Linear Algebra Package
apt install -y libscalapack-mpi-dev libscalapack-openmpi-dev
# hdf5
apt install -y libhdf5-dev libhdf5-mpi-dev libhdf5-openmpi-dev
# focal/jammy
# Optimized BLAS (linear algebra) library (development files)
apt install -y libopenblas-dev libopenblas64-dev libopenblas64-openmp-dev
apt install -y libtmglib-dev libtmglib64-dev
# vasp need this during compililation
apt install -y rsync
## optional package
apt install -y neofetch
#解压和编译 VASP
cd /opt && tar -xvf vasp.6.3.2.tgz
#cp /opt/VASP.6.3.2_gnu.omp_mpich.makefile.include /opt/vasp.6.3.2/makefile.include
#cp /opt/VASP.6.3.2_gnu_openmpi.makefile.include /opt/vasp.6.3.2/makefile.include
#将特定的 makefile 配置文件复制到 VASP 目录。
cp /opt/VASP.6.3.2_gnu.omp_openmpi.makefile.include /opt/vasp.6.3.2/makefile.include
cd /opt/vasp.6.3.2 && make DEPS=1 std -j && make DEPS=1 ncl -j && make DEPS=1 gam -j
chmod 755 -R /opt/vasp.6.3.2
chmod u+x -R /opt/vasp.6.3.2
#添加-j参数多线程编译
#使用 make 命令编译标准版本、非对称晶格(NCL)和伽马点版本
#确保 VASP 目录及其文件具有适当的权限。
#配置环境变量
%environment
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export PATH=/opt/deepmd-kit/bin:$PATH
export PATH=$PATH:/opt/vasp.6.3.2/bin/
# load variables defined in %post stage
source /.singularity.d/env/91-environment.sh
#确保使用英文 UTF-8 编码
#将 VASP 和 DeepMD-Kit 的可执行文件路径添加到系统路径中。
#从 /.singularity.d/env/91-environment.sh 文件中加载定义的变量。
二、构建Singularity容器
sudo apptainer build vasp_6.3.2_omp_mpi_openmpi_412.sif vasp_6.3.2_omp_mpi_openmpi_412.def
三、使用
已将创建好的sif文件上传至/mnt/softs/singularity_sifs/文件夹,若需使用直接在sbatch脚本中调用vasp_6.3.2_omp_mpi_openmpi_412_1.sif即可。详细的任务提交脚本可参考课题组网站VASP使用手册。