LAMMPS 专题

LAMMPS NVE、NVT、NPT与随机控温

NVE、NVT、NPT与随机控温,包含可提交输入、实际终端命令、数据和配图。

更新于 2026-10-27约 5 分钟阅读按任务与环境选择适用配置
阅读本篇目录

本文使用鸢算科技集群 LAMMPS 30 Sep 2026 的真实计算。下载输入、参考轨迹、分析脚本与数据图(约 72.5 MB),解压后进入 lammps-examples。cases 保存参考结果,inputs 保存干净输入,使用 new-case.py 创建自己的计算副本。

要完成什么#

NVE 只积分,NVT 控温,NPT 同时控温和允许盒子变化。fix langevin 只提供阻尼与随机力,必须另配积分器;本例与 fix nve 一起使用。换阶段先 unfix 旧的积分/控温命令,再启用新方法。

LJ 演示的 NPT 目标压力为 0,而水的 real 单位演示目标是 1 atm。不同模型的压力零点和相图不同,不能把 LJ 的设定当成真实材料的环境压力。判断平衡要同时观察温度、能量、密度和体积;瞬时压力在小体系中波动很大。

1 准备并提交#

python new-case.py lj-nve-0.002
cd work/lj-nve-0.002
sbatch run.sh

run.sh 是本算例匹配的核时 P100 或 V10016G 模板。套餐用户按自己的权限使用 yskit 生成提交脚本,保留下面的计算命令。完整模拟在计算节点执行。其他例子回到资料包根目录,替换目录名后分别提交。

目录 内容
lj-nve-0.002 独立输入、参考输出和可重跑命令
lj-T1.0 独立输入、参考输出和可重跑命令
lj-npt 独立输入、参考输出和可重跑命令
lj-langevin 独立输入、参考输出和可重跑命令

2 实际计算命令与输入#

lj-nve-0.002#

mpirun -np 1 lmp -sf gpu -pk gpu 1 -in in.lammps > stdout.log 2>&1

lj-T1.0#

mpirun -np 1 lmp -sf gpu -pk gpu 1 -in in.lammps > stdout.log 2>&1

lj-npt#

mpirun -np 1 lmp -sf gpu -pk gpu 1 -in in.lammps > stdout.log 2>&1

lj-langevin#

mpirun -np 1 lmp -sf gpu -pk gpu 1 -in in.lammps > stdout.log 2>&1

下面是 lj-nve-0.002/in.lammps 的完整输入;其他目录的完整输入也在资料包中。

units lj
atom_style atomic
boundary p p p
lattice fcc 0.8
region box block 0 8 0 8 0 8
create_box 1 box
create_atoms 1 box
mass 1 1
pair_style lj/cut 2.5
pair_coeff * * 1 1 2.5
pair_modify shift yes
neighbor 0.3 bin
neigh_modify every 1 delay 0 check yes
thermo 100
thermo_style custom step time atoms temp pe ke etotal press vol density
thermo_modify norm no format float %.12g
timestep 0.002
velocity all create 1.0 927451 mom yes rot yes dist gaussian
fix eq all nvt temp 1.0 1.0 0.5
run 4000
unfix eq
reset_timestep 0
dump tr all custom 200 trajectory.lammpstrj id type x y z vx vy vz
dump_modify tr sort id
fix int all nve
compute rdf all rdf 100
fix rdfout all ave/time 10 100 1000 c_rdf[*] file rdf.dat mode vector
compute msd all msd com yes
compute vac all vacf
fix transport all ave/time 10 1 10 c_msd[4] c_vac[4] file transport.dat
compute peatom all pe/atom
compute cn all coord/atom cutoff 1.4
compute centrosym all centro/atom fcc
run 12000
write_data final.data
write_restart final.restart
write_dump all custom final.dump id type x y z c_peatom c_cn c_centrosym modify sort id

3 查看输出与实际数据#

tail -n 30 stdout.log
ls -lh

stdout.log 是计算输出;轨迹保存在 trajectory.lammpstrj(适用的算例),结构保存在 final.data。静态扫描和 run 0 对照不一定生成动力学轨迹。以下动态均值取最后一个热力学输出块的后半段;静态结果取对应输出,单位随输入确定。

算例 原子数 平均温度 平均密度 最后势能
lj-nve-0.002 2048 0.971622 0.8 -9676.27039
lj-T1.0 2048 0.998884 0.8 -9582.314
lj-npt 2048 1.00157 0.463431 -5453.60091
lj-langevin 2048 0.99857 0.8 -9580.39189

LJ/珠簧例子使用约化单位;metal 为 K、g/cm³、eV;水的 real 单位为 K、g/cm³、kcal/mol。势能列是整个体系的总量,跨不同原子数不可直接相比。

LAMMPS实际结构与计算数据:thermo-lj-langevin

LAMMPS实际结构与计算数据:thermo-lj-npt

4 提取数据与重画#

回到附件根目录,使用已经安装的 ASE Python 环境执行真实数据分析脚本:

module load ase/3.29.0
python analyze.py --root .
ls analysis
ls figures

脚本使用 NumPy/Matplotlib,读取参考日志、轨迹和相关函数,生成 CSV 与 PNG。查看 analyze.py 中本篇对应目录的处理段,可以把路径换成你的新结果。完整脚本按本专题的全部参考目录组织,单个新算例不需要假造其他目录来运行;提取对应段即可。

进一步查阅#

需要根据你的体系选择资源?联系讨论计算需求。实际可用软件与权限,以当前账户和运行环境为准。

查看配图

放大后可滚动查看细节,按 Esc 关闭。

100%查看原图 ↗