He knows most who speaks least.
大智若愚
Updated time: 04/23 2024.
Install package/software (Debian 12.5)
Lammps
Ref:
LAMMPS 的源代码安装相对复杂,因为它可以根据需要配置各种选项和扩展。下面是使用 CMake 进行安装的一种常规方法,包括了一些可能需要的依赖项如 FFTW 和 MPICH。
安装
1. 安装前准备
首先,确保你的系统上安装了编译工具和 CMake。另外,对于并行计算支持,你可能需要安装 MPI 实现,如 MPICH 或 OpenMPI。
sudo apt-get update
sudo apt-get install build-essential cmake git
sudo apt-get install mpich libmpich-dev
sudo apt-get install openmpi-bin openmpi-common libopenmpi-dev
mpirun --version
如果你打算使用 FFTW (用于更快的傅里叶变换),你也需要安装 FFTW 库:
sudo apt-get install libfftw3-dev libfftw3-double3
2. 获取 LAMMPS 源代码
从 GitHub 克隆 LAMMPS 的仓库:
git clone -b stable https://github.com/lammps/lammps.git lammps
cd lammps
这里我们选择了稳定版分支,但你也可以选择其他分支,如开发版等。
3. 使用 CMake 配置构建
创建一个构建目录并进入:
mkdir build
cd build
运行 CMake 来配置构建过程。你可以根据需要启用或禁用特定的包或功能:
cmake ../cmake -D PKG_MPI=yes # configuration reading CMake scripts from ../cmake
cmake --build . # compilation (or type "make")
# cmake ../cmake -DCMAKE_INSTALL_PREFIX=/path/to/install/lammps
这里的 /path/to/install/lammps
应该被替换为你希望安装 LAMMPS 的目录。你可以添加额外的 CMake 选项来启用或禁用特定的 LAMMPS 包,例如:
-DPKG_MANYBODY=yes -DPKG_MOLECULE=yes
#test
/build/lmp -h
4. 编译和安装
编译 LAMMPS:
make -j4 # 使用4个核心进行编译,根据你的处理器调整这个数字
安装 LAMMPS:
make install
5. 测试安装
确保 LAMMPS 已正确安装,可以运行下面的命令测试:
/path/to/install/lammps/bin/lmp -h
这应该会显示 LAMMPS 的帮助信息,证明安装成功。
After the initial build, whenever you edit LAMMPS source files, enable or disable packages, change compiler flags or build options, you must re-compile and relink the LAMMPS executable with cmake --build .
(or make
). If the compilation fails for some reason, try running cmake .
and then compile again. The included dependency tracking should make certain that only the necessary subset of files is re-compiled. You can also delete compiled objects, libraries, and executables with cmake --build . --target clean
(or make clean
).
6. 修改
在使用 ccmake .
进行配置时,退出 ccmake
的界面操作比较简单:
- 保存并生成配置:如果您已经进行了配置修改并希望保存这些更改,并生成用于编译的
Makefile
:- 按下
c
键以配置参数,可能需要多次按c
直到所有配置问题解决并出现[g]enerate
的选项。 - 完成配置后,按下
g
键来生成Makefile
并退出ccmake
。
- 按下
- 退出而不保存更改:如果您想退出而不保存所做的更改:
- 按下
q
键。如果您没有进行任何未保存的更改,这将直接退出ccmake
。 - 如果您已经修改了配置但还未保存,系统会询问您是否真的要退出。此时,再次按
q
确认退出而不保存更改。
- 按下
总的来说,ccmake
的操作主要通过界面底部的提示进行,按键操作直接响应于提示的指令。
修改配置
1. 打开 CMake 配置
首先,您需要进入到 LAMMPS 的源代码或构建目录,并使用 CMake 来修改现有配置。
使用命令行界面
如果您在终端中,可以使用 ccmake
(面向字符的界面)或 cmake-gui
(图形界面):
cd /path/to/lammps/build
ccmake .
# 或者
cmake-gui .
在 ccmake
界面中:
- 按
t
切换到高级视图。 - 使用键盘上下箭头选择要启用的包(包名称以
PKG_
开头)。 - 按
Enter
改变选项(ON
/OFF
)。 - 一旦完成配置,按
c
进行配置,然后按g
生成并退出。
在 cmake-gui
中:
- 修改包的选项,将它们从
OFF
改为ON
。 - 点击 “Configure”,然后 “Generate”。
修改 CMake 文件
或者,您可以直接编辑 CMake 命令行选项,在终端中运行:
cd /path/to/lammps/build
cmake -DPKG_MANYBODY=ON -DPKG_MOLECULAR=ON ..
上述命令启用了 MANYBODY
和 MOLECULAR
包。您可以根据需要启用更多包。
2. 重新编译 LAMMPS
配置完成后,重新编译 LAMMPS:
make -j $(nproc)
这里的 -j $(nproc)
选项允许并行编译,加快编译过程。$(nproc)
命令会自动替换为您系统中的处理器核心数。
3. 安装(可选)
如果您之前安装了 LAMMPS(通过 make install
),则需要再次安装来更新安装的二进制文件:
make install
4. 验证
验证新包是否正确安装,可以运行:
/path/to/lammps/build/lmp -info
查看输出,确认新包已列出。
这些步骤将指导您通过添加所需的 LAMMPS 包来自定义您的模拟环境。
安装python包
2.2. Installation — LAMMPS documentation
To specify a virtual environment when installing LAMMPS using CMake, follow these steps:
1. First, create and activate your virtual environment:
python3 -m venv ~/myenv
source ~/myenv/bin/activate
2. When configuring LAMMPS with CMake, set the CMAKE_INSTALL_PREFIX
to point to your virtual environment:
cmake -DCMAKE_INSTALL_PREFIX='~/mysoft/env/mydft' ../cmake
3. Build and install LAMMPS:
cmake --build . --target install
4. You can also install the Python package with:
make install-python
This approach ensures that LAMMPS and its Python module are correctly integrated into your virtual environment.
安装Vorinoi/KIm 包
3.7. Packages with extra build options — LAMMPS documentation
Very easy using CMAKE.
VASP
6.3.2 (5.4.4 装不了)
Install intel Base/HPC toolkit
VASP 5.4.4编译与安装 - 知乎 (zhihu.com)
甚至可以用apt安装,但是我们需要自行编译 fftw
,以及用apt安装的无法调用 icc
命令,应该是环境配置不对
Please indicate the source when reprinting. Please verify the citation sources in the article and point out any errors or unclear expressions.