LAMMPS椭球粒子朝向、角动量与温度实操
用三个不同质量和形状的椭球,实际比较同时旋转朝向与角动量、只改朝向、整体平移速度对转动能和温度的影响。
阅读本篇目录
椭球粒子的三个主转动惯量一般不同。同样的实验室坐标系角动量,对应的角速度和自旋动能会随粒子朝向改变。本篇从输入形状、朝向和角动量开始,演示temp/asphere与erotate/asphere的实际操作。
采用三个粒子的四组静态run 0,LJ单位,没有热平衡或动力学积分。读出的温度用于说明动能及自由度定义,不作为真实材料的平衡温度或压力结论。
1.下载、读表和画图#
下载椭球粒子实例包,解压进入lammps-ellipsoid-temperature:
bash read.sh
bash plot.sh
| 输出 | 内容 |
|---|---|
analysis/LAMMPS-ellipsoid-inertia.csv |
半轴、主惯量、实验室与主轴坐标系角动量、主轴角速度、独立公式的逐粒子转动能 |
analysis/LAMMPS-ellipsoid-temperatures.csv |
原生总转动能、总平动能、四种标量温度与自由度 |
figures/LAMMPS-ellipsoid-orientation.png |
实际xy轮廓、朝向变化和角动量投影 |
figures/LAMMPS-ellipsoid-temperature.png |
四种条件的能量和温度比较 |
读取和画图不会重跑LAMMPS。CSV中逐粒子能量由随包脚本按惯量公式计算;LAMMPS的erotate/asphere输出总量,两者求和比较。

前后粒子的中心位置和实验室角动量相同,只改变朝向。轮廓由三维椭球在xy平面的投影计算,箭头是按图注比例显示的角动量投影,不是角速度。
2.重新运行#
bash prepare.sh
bash run.sh
bash read.sh work-new analysis-new
bash plot.sh analysis-new figures-new
prepare.sh新建work-new,已有目录不会覆盖。run.sh采用LAMMPS 30Sep2026、oneAPI 2024.2 CPU版,单MPI、单线程,依次计算四个快照。在已申请的计算资源中,也可只运行基准目录:
module load lammps/30Sep2026-8173m
export OMP_NUM_THREADS=1
export I_MPI_FABRICS=shm
cd work-new/base
lmp -in in.lammps
这里是单节点单进程示例,MPI使用共享内存;多节点任务应按对应软件环境配置通信。
3.形状、朝向与角动量怎样写#
三个粒子的半轴为:
| ID | 质量 | 半轴(a,b,c) | 基准朝向 | 实验室角动量(Lx,Ly,Lz) |
|---|---|---|---|---|
| 1 | 1 | (1,0.5,0.25) | 初始主轴与坐标轴重合 | (0.1,0.2,0.3) |
| 2 | 2 | (0.8,0.4,0.3) | 绕z旋转45° | (−0.2,0.1,0.4) |
| 3 | 1 | (0.6,0.5,0.2) | 绕x旋转30° | (0.1,−0.1,0.2) |
atom_style ellipsoid
set atom 1 shape 2 1 0.5
set atom 1 mass 1
set atom 1 quat 0 0 1 0
set atom 1 angmom 0.1 0.2 0.3
set shape填三个全轴长,所以第一粒子的输入为(2,1,0.5),半轴为(1,0.5,0.25)。随后设置质量,避免把形状变化导致的默认质量变化混入比较。set quat用“旋转轴x、y、z与角度”设置朝向;输出的quatw quati quatj quatk才是四元数四个分量,二者不能直接照抄混用。
angmom设置实验室坐标系的角动量,不是角速度。
展开base/in.lammps完整输入
units lj
atom_style ellipsoid
boundary p p p
region BOX block 0 10 0 10 0 10
create_box 1 BOX
create_atoms 1 single 2 2 2 units box
set atom 1 shape 2 1 0.5
set atom 1 mass 1
set atom 1 quat 0 0 1 0
set atom 1 angmom 0.10000000000000001 0.20000000000000001 0.29999999999999999
group A1 id 1
velocity A1 set 0.20000000000000001 0.10000000000000001 0 units box
create_atoms 1 single 6 2 2 units box
set atom 2 shape 1.6000000000000001 0.80000000000000004 0.59999999999999998
set atom 2 mass 2
set atom 2 quat 0 0 1 45.000000000000007
set atom 2 angmom -0.20000000000000001 0.10000000000000001 0.40000000000000002
group A2 id 2
velocity A2 set -0.10000000000000001 -0.050000000000000003 0 units box
create_atoms 1 single 2 6 2 units box
set atom 3 shape 1.2 1 0.40000000000000002
set atom 3 mass 1
set atom 3 quat 1.0000000000000002 0 0 29.999999999999993
set atom 3 angmom 0.10000000000000001 -0.10000000000000001 0.20000000000000001
group A3 id 3
velocity A3 set 0 0 0 units box
pair_style zero 2
pair_coeff * *
compute TB all temp/com
compute TD all temp/asphere
compute T0 all temp/asphere
compute_modify T0 extra/dof 0
compute TC all temp/asphere bias TB
compute_modify TC extra/dof 3
compute TR all temp/asphere dof rotate
compute ER all erotate/asphere
compute KT all ke
compute P all property/atom mass shapex shapey shapez quatw quati quatj quatk
fix OBS all ave/time 1 1 1 c_TD c_T0 c_TC c_TR c_ER c_KT file temperatures.dat format " %.17g"
dump AT all custom 1 atoms.dump id x y z vx vy vz angmomx angmomy angmomz c_P[*]
dump_modify AT sort id format float %.17g
thermo 1
thermo_style custom step atoms c_TD c_TC c_TR c_ER c_KT
thermo_modify norm no format float %.17g
run 0
4.从角动量得到自旋动能#
均匀椭球的三个主惯量为:
I1 = m(b²+c²)/5
I2 = m(a²+c²)/5
I3 = m(a²+b²)/5
用朝向矩阵R把主轴坐标系转到实验室坐标系时,先算L_body=RᵀL_lab,再算ω_body=L_body/I和E_rot=0.5Σ(L_body²/I)。
第一粒子的主惯量为(0.0625,0.2125,0.25),对应基准自旋动能0.3541176471。三个粒子的独立逐粒子能量分别为0.3541176471、0.3520547945、0.2915111312,合计0.9976835728,与原生总量一致:
compute ER all erotate/asphere
5.四种条件有什么区别#
| 目录 | 改变的内容 | 原生总自旋动能 | 原生总平动能 |
|---|---|---|---|
base |
基准 | 0.9976835728 | 0.0375 |
rotated |
朝向、角动量和平动速度共同绕z转30° | 0.9976835728 | 0.0375 |
boosted |
所有平动速度增加(0.8,−0.2,0.1) | 0.9976835728 | 1.4175 |
orientation-only |
只将朝向绕z转30°,保持实验室角动量 | 1.0891849948 | 0.0375 |
共同旋转朝向与角动量时,相对主轴的角动量分量不变,自旋动能不变。只转朝向时,角动量在三个主轴上的分配改变,动能也改变。这两种操作是不同的物理初始条件。
6.全温度、去质心温度与旋转温度#
compute TB all temp/com
compute TD all temp/asphere
compute T0 all temp/asphere
compute_modify T0 extra/dof 0
compute TC all temp/asphere bias TB
compute_modify TC extra/dof 3
compute TR all temp/asphere dof rotate
本例三维三粒子均保留三个转动自由度。默认全模式为6×3−3=15个自由度,显式extra/dof 0为18;去质心模式显式按15归一化,只看旋转为9。
| 条件 | 默认全温度 | extra/dof 0 | 去质心温度 | 只看旋转温度 |
|---|---|---|---|---|
| 基准 | 0.1380244764 | 0.1150203970 | 0.1380244764 | 0.2217074606 |
| 共同旋转 | 0.1380244764 | 0.1150203970 | 0.1380244764 | 0.2217074606 |
| 整体漂移 | 0.3220244764 | 0.2683537303 | 0.1380244764 | 0.2217074606 |
| 只转朝向 | 0.1502246660 | 0.1251872216 | 0.1502246660 | 0.2420411100 |

整体漂移只改变平动能,去质心温度和旋转温度不变。若自己的模型限制某些转动自由度,应按实际约束调整归一化,不能直接套本表。
7.查看输出并迁移到自己的输入#
cat work-new/base/temperatures.dat
head -n 5 analysis/LAMMPS-ellipsoid-inertia.csv
head -n 5 analysis/LAMMPS-ellipsoid-temperatures.csv
原生输出列在步数后依次为默认全温度、extra/dof 0温度、去质心温度、旋转温度、总自旋动能、总平动能。形状、质量、朝向和角动量保存在atoms.dump中。
temp/asphere要求参与计算的粒子均为有限尺寸,本例未混入点粒子。迁移到真实椭球模型时,还需要适合其形状的相互作用势、转动积分方法与合理的平衡过程;本例的pair_style zero仅用于观察动能定义。此处只讨论标量温度和能量,不能把曲线解释为椭球压力或应力结果。