LAMMPS球粒子与非球形数据
两粒子最小合法数据、属性设置、原生读写与结构示意,配套完整输入和实算结果。
阅读本篇目录
本组例子解决一个常见问题:选好 atom_style 后,Atoms 每列该填什么,电荷、密度、取向等属性怎样一起保存。每个模型只有两个粒子,先读入数据,设置速度,再写出、清空和读回。它们是可直接修改的数据文件模板;没有配置相互作用势,也没有计算材料性质。
资料包使用 LAMMPS 30Sep2026;基础类型调用 lammps/30Sep2026-p100-gpu,Kokkos 条目调用 lammps/30Sep2026-p100-kokkos。这两套模块分别加载相应的 MPI/CUDA 环境,后处理使用 ase/3.29.0 环境中的 NumPy/Matplotlib。先用模块切换环境,不要把两套 LAMMPS 的动态库路径混在一起。
先下载、提交,再查看输出#
下载完整的41例数据文件、输入脚本与参考结果。在个人工作目录执行:
mkdir atom-data
cd atom-data
curl -fL https://yuansuan.top/assets/downloads/full-function/lammps-atom-data-wave77-d41f95983061.zip -o examples.zip
unzip examples.zip
sbatch submit.slurm
submit.slurm 申请一个 P100、一个 CPU 核;脚本逐个运行,Kokkos 条目会初始化 GPU 后端,基础类型仅做原生数据读写。没有 GPU 力计算或性能测试。提交后先看作业输出,再提取数据:
module purge
module load ase/3.29.0
python analyze.py work
python export_xyz.py work
python plot_results.py work
head -8 work/analysis/atom-style-io.csv
依次得到 first.data、读回后的 second.data、两份坐标与速度 dump、属性 CSV、位置 XYZ 和四张原图。已完成算例位于 reference/,可以把上述三个命令的 work 换为 reference 查看配套结果。重新计算请重新解压到新目录。
所有类型共同的读写流程#
下面是 atomic 的完整输入。更换类型时,atom_style 与 input.data 的列格式必须同时匹配;带模板的类型还有额外的初始化步骤。
units lj
dimension 3
atom_style atomic
read_data input.data
velocity all set .1 .2 .3
write_data first.data nocoeff noinit
write_dump all custom first.dump id type x y z vx vy vz modify sort id format float %.16g
clear
units lj
dimension 3
atom_style atomic
read_data first.data
write_data second.data nocoeff noinit
write_dump all custom second.dump id type x y z vx vy vz modify sort id format float %.16g
print "IO_ROUNDTRIP_DONE"
nocoeff 不输出势参数,noinit 用于本例的数据读写,不初始化力模型。要做真实动力学,需要另行设置对应势函数、参数和积分器,并正常执行 run;不要把这里的零步读写当作已经完成的物性计算。velocity all set 是人为给定速度,不是按温度抽样。
write_data 在每个原子行末增加 nx ny nz 三个周期映像标志,本例均为0。读取自己生成的数据时保留它们即可。

图中蓝黄分别标识两个粒子,位置、尺寸、取向及标注均取自实际输出;是xy投影,z信息仍完整保存在data/CSV中。
本篇类型与列顺序#
| 类型 | 实际Atoms列(不含末尾可选映像标志) |
|---|---|
sphere |
id type diameter density x y z |
bpm/sphere |
id molecule type diameter density x y z |
ellipsoid |
id type ellipsoidflag density x y z |
line |
id molecule type lineflag density x y z |
tri |
id molecule type triangleflag density x y z |
body |
id type bodyflag mass x y z |
hybrid |
id type x y z q diameter density |
sphere:最小可修改数据#
Atoms 中写直径和密度,软件据体积计算每粒子质量;不是半径和质量。
先看配套文件:
head -60 inputs/sphere/input.data
cat inputs/sphere/in.lammps
input.data 完整内容:
Yuansuan minimal sphere data; reduced LJ units, IO example only
2 atoms
1 atom types
0 8 xlo xhi
0 8 ylo yhi
0 8 zlo zhi
Atoms # sphere
1 1 1.2 2 2 2 2
2 1 .8 3 5 5 5
bpm/sphere:最小可修改数据#
在球粒子字段中增加分子ID,并支持相应键模型;本例没有额外建立BPM键。
先看配套文件:
head -60 inputs/bpm-sphere/input.data
cat inputs/bpm-sphere/in.lammps
input.data 完整内容:
Yuansuan minimal bpm/sphere data; reduced LJ units, IO example only
2 atoms
1 atom types
0 8 xlo xhi
0 8 ylo yhi
0 8 zlo zhi
Atoms # bpm/sphere
1 1 1 1.2 2 2 2 2
2 1 1 .8 3 5 5 5
ellipsoid:最小可修改数据#
Atoms 用标志1声明有限尺寸椭球;长短轴尺寸和四元数放在 Ellipsoids。这里的尺寸是全轴长。
先看配套文件:
head -60 inputs/ellipsoid/input.data
cat inputs/ellipsoid/in.lammps
input.data 完整内容:
Yuansuan minimal ellipsoid data; reduced LJ units, IO example only
2 atoms
1 atom types
2 ellipsoids
0 8 xlo xhi
0 8 ylo yhi
0 8 zlo zhi
Atoms # ellipsoid
1 1 1 2 2 2 2
2 1 1 3 5 5 5
Ellipsoids
1 1.2 .8 .6 1 0 0 0
2 .8 1.4 .6 .9238795325112867 0 0 .3826834323650898
line:最小可修改数据#
必须使用二维盒子,所有z坐标为0;Lines 每行给ID和两端点xy。
先看配套文件:
head -60 inputs/line/input.data
cat inputs/line/in.lammps
input.data 完整内容:
Yuansuan minimal line data; reduced LJ units, IO example only
2 atoms
1 atom types
2 lines
0 8 xlo xhi
0 8 ylo yhi
-1 1 zlo zhi
Atoms # line
1 1 1 1 2 2 2 0
2 1 1 1 3 5 5 0
Lines
1 1.5 2 2.5 2
2 4.5 4.5 5.5 5.5
本例完整输入:
units lj
dimension 2
atom_style line
read_data input.data
velocity all set .1 .2 0
write_data first.data nocoeff noinit
write_dump all custom first.dump id type x y z vx vy vz modify sort id format float %.16g
clear
units lj
dimension 2
atom_style line
read_data first.data
write_data second.data nocoeff noinit
write_dump all custom second.dump id type x y z vx vy vz modify sort id format float %.16g
print "IO_ROUNDTRIP_DONE"
tri:最小可修改数据#
Triangles 按ID给三个顶点的xyz;Atoms 中的位置是粒子中心,密度不是直接的总质量。
先看配套文件:
head -60 inputs/tri/input.data
cat inputs/tri/in.lammps
input.data 完整内容:
Yuansuan minimal tri data; reduced LJ units, IO example only
2 atoms
1 atom types
2 triangles
0 8 xlo xhi
0 8 ylo yhi
0 8 zlo zhi
Atoms # tri
1 1 1 1 2 2 2 2
2 1 1 1 3 5 5 5
Triangles
1 1.5 1.7113248654051871 2 2.5 1.7113248654051871 2 2 2.5773502691896257 2
2 4.5 4.711324865405187 5 5.5 4.711324865405187 5 5 5.577350269189626 5
body:最小可修改数据#
使用 body nparticle 2 10;每个刚体由3个子粒子组成,Atoms 中的3是刚体总质量。Bodies 记录子粒子数、惯量和相对质心坐标。
先看配套文件:
head -60 inputs/body/input.data
cat inputs/body/in.lammps
input.data 完整内容:
Yuansuan minimal body data; reduced LJ units, IO example only
2 atoms
1 atom types
2 bodies
0 8 xlo xhi
0 8 ylo yhi
0 8 zlo zhi
Atoms # body
1 1 1 3 2 2 2
2 1 1 3 5 5 5
Bodies
1 1 15
3
.5 .5 1 0 0 0
-.5 -0.28867513459481287 0
.5 -0.28867513459481287 0
0 0.5773502691896257 0
2 1 15
3
.5 .5 1 0 0 0
-.5 -0.28867513459481287 0
.5 -0.28867513459481287 0
0 0.5773502691896257 0
本例完整输入:
units lj
dimension 3
atom_style body nparticle 2 10
read_data input.data
velocity all set .1 .2 .3
write_data first.data nocoeff noinit
write_dump all custom first.dump id type x y z vx vy vz modify sort id format float %.16g
clear
units lj
dimension 3
atom_style body nparticle 2 10
read_data first.data
write_data second.data nocoeff noinit
write_dump all custom second.dump id type x y z vx vy vz modify sort id format float %.16g
print "IO_ROUNDTRIP_DONE"
每条 Bodies 记录的首行是 atom-ID ninteger ndouble,本例为 1 1 15;下一行的3表示3个子粒子。15个浮点数=6个惯量分量+9个相对坐标。惯量是当前空间取向下的 Ixx Iyy Izz Ixy Ixz Iyz,必须与子粒子分布及质量一致,不能随意填。
hybrid:最小可修改数据#
本例组合 charge sphere,同时保存电荷与球粒子信息。两种质量机制并存时,设置类型质量和逐粒子质量,动力学优先使用逐粒子质量。
先看配套文件:
head -60 inputs/hybrid/input.data
cat inputs/hybrid/in.lammps
input.data 完整内容:
Yuansuan minimal hybrid data; reduced LJ units, IO example only
2 atoms
1 atom types
0 8 xlo xhi
0 8 ylo yhi
0 8 zlo zhi
Masses
1 2.0
Atoms # hybrid
1 1 2 2 2 .5 1.2 2
2 1 5 5 5 -.5 .8 3
本例完整输入:
units lj
dimension 3
atom_style hybrid charge sphere
read_data input.data
velocity all set .1 .2 .3
write_data first.data nocoeff noinit
write_dump all custom first.dump id type x y z vx vy vz modify sort id format float %.16g
clear
units lj
dimension 3
atom_style hybrid charge sphere
read_data first.data
write_data second.data nocoeff noinit
write_dump all custom second.dump id type x y z vx vy vz modify sort id format float %.16g
print "IO_ROUNDTRIP_DONE"
如何核对结果与继续使用#
实际两次写出覆盖全部原子属性、质量/形状/拓扑附加段、速度及坐标dump。41例逐项核对通过;数值差异只在有限尺寸几何的浮点舍入范围内,完整误差在CSV中。
head -12 work/analysis/atom-style-io.csv
head -5 work/analysis/xyz/charge-attributes.csv
head -5 work/analysis/xyz/charge.xyz
XYZ导出工具只输出位置,电荷、取向、密度等另存属性CSV;继续计算时保留原生data文件及附加段。只把XYZ读回不能恢复完整模型。图件为PNG原图,可点击放大。
本包统一使用约化 units lj 演示存储格式,数值是教学输入;套用真实体系时,把单位、质量、相互作用参数、边界、粒子属性及积分器作为一个整体检查。尤其电子、磁性、流变与连续介质模型不要直接套用这里的人为参数。
继续阅读:
字段解释参照官方atom_style说明、read_data说明和Body粒子说明,实际列顺序以本教程对应30Sep2026原生写出文件为准。