LAMMPS compute chunk/atom 命令详解:原子分块(chunk)机制、空间分箱与源码实现原理
LAMMPS compute chunk/atom 命令详解:原子分块(chunk)机制、空间分箱与源码实现原理
LAMMPS 中的 compute chunk/atom 命令把模拟体系中的每个原子归入一个"chunk"(原子分组),并输出 per-atom 的 chunk ID(1 到 Nchunk 的整数,未分组的原子为 0)和全局标量 Nchunk(chunk 总数)。它是 LAMMPS 分块统计体系的入口:fix ave/chunk、compute \*/chunk 系列命令都依赖它产生的分组信息,可完成空间分箱求平均、逐分子质心/均方位移/温度、聚类大小直方图等常见分析任务。读完本文,你将掌握全部 8 种 chunk 风格(bin/1d、bin/2d、bin/3d、bin/sphere、bin/cylinder、type、molecule、compute/fix/variable)的参数含义、9 个可选关键字(region/nchunk/limit/ids/compress/discard/bound/pbc/units)的交互规则与默认值,并能对照 compute_chunk_atom.cpp 理解分箱、压缩与锁机制的底层实现。
dump image 渲染的 bin/1d、bin/2d、bin/3d 空间分箱边界可视化(图源 doc/src/compute_chunk_atom.rst)
1. 命令语法与参数总览
命令的完整语法为:
compute ID group-ID chunk/atom style args keyword values ...
其中 ID、group-ID 的语义与通用 compute 命令相同;style 决定 chunk 的定义方式,可选值为:bin/1d 或 bin/2d 或 bin/3d 或 bin/sphere 或 bin/cylinder 或 type 或 molecule 或 c_ID、c_ID[I]、f_ID、f_ID[I]、v_name。各风格的 args 参数如下表:
| 风格 | args | 参数含义 |
|---|---|---|
bin/1d |
dim origin delta |
dim = x/y/z;origin = lower/center/upper 或坐标值(距离单位);delta = 该维度分箱厚度(距离单位) |
bin/2d |
dim origin delta dim origin delta |
上述三参数各写两次 |
bin/3d |
dim origin delta dim origin delta dim origin delta |
上述三参数各写三次 |
bin/sphere |
xorig yorig zorig rmin rmax nsbin |
球心坐标;从半径 rmin 到 rmax 分箱;nsbin = 球壳层数 |
bin/cylinder |
dim origin delta c1 c2 rmin rmax ncbin |
dim = 圆柱轴向;origin/delta 同 bin/1d;c1、c2 = 轴在另外两个维度的坐标;rmin/rmax 为径向分箱范围;ncbin = 同心圆层数 |
type |
无 | chunk ID = 原子类型 |
molecule |
无 | chunk ID = 分子的 molecule ID |
c_ID / c_ID[I] |
无 | c_ID 为已定义 compute 的 ID;不带括号用其 per-atom 向量,c_ID[I] 用其 per-atom 数组第 I 列 |
f_ID / f_ID[I] |
无 | 同上,但引用 fix 的 per-atom 向量/数组 |
v_name |
无 | v_name 为 atom-style variable 的名称 |
之后可追加零个或多个 keyword value 对,关键字为:region、nchunk、limit、ids、compress、discard、bound、pbc、units,各关键字的取值:
| 关键字 | 取值 | 含义 |
|---|---|---|
region |
region-ID | 原子必须同时位于 group 和该几何 region 内才会被分到 chunk |
nchunk |
once / every |
只在首次调用时计算 Nchunk / 每次调用都重新计算 |
limit |
0 / Nc max / Nc exact |
不限 / 把 Nchunk 限制为不超过 Nc / 强制 Nchunk 恰为 Nc |
ids |
once / nfreq / every |
chunk ID 只分配一次且永久保持 / 在 fix ave/chunk 的 Nfreq 步窗口内保持不变 / 每次调用都重算 |
compress |
yes / no |
压缩掉没有任何原子的 chunk ID / 不压缩 |
discard |
yes / no / mixed |
越界原子置 0 / 越界原子归入最近 chunk / 按空间分箱规则(仅 bin 风格) |
bound |
x/y/z lo hi |
限制某维度分箱范围,lo/hi = lower/upper 或坐标值,可多次使用 |
pbc |
yes / no |
bin/sphere 与 bin/cylinder 用最小镜像距离计算原子到球心/轴的距离 |
units |
box / lattice / reduced |
分箱距离参数的单位体系(仅 bin 风格有效) |
官方文档给出的完整示例(可直接复制到输入脚本,替换 group 后使用):
compute 1 all chunk/atom type
compute 1 all chunk/atom bin/1d z lower 0.02 units reduced
compute 1 all chunk/atom bin/2d z lower 1.0 y 0.0 2.5
compute 1 all chunk/atom molecule region sphere nchunk once ids once compress yes
compute 1 all chunk/atom bin/sphere 5 5 5 2.0 5.0 5 discard yes
compute 1 all chunk/atom bin/cylinder z lower 2 10 10 2.0 5.0 3 discard yes
compute 1 all chunk/atom c_cluster
compute-chunk_atom.yaml 单元测试则验证了 compute test all chunk/atom molecule 在 29 原子、6 分子体系上产生 global_scalar: 6(Nchunk = 6)以及上表 per-atom 数据所示的逐原子 chunk ID。
2. 核心概念:两个相互独立的动作
从文档描述和源码结构看,compute chunk/atom 在概念上只做两件简单的事:
- 确定 Nchunk(chunk 的总数),它可以是常量,也可以随时间变化(例如 box 尺寸变化、新分子加入);
- 为每个原子分配 chunk ID,取值 1 到 Nchunk;不属于任何 chunk 的原子被赋予 0。
注意这两个动作并不总是同时发生:例如空间分箱可以只建立一次(设定 Nchunk),之后每次调用只把原子映射到已有 bin(更新 chunk ID)。在 compute_chunk_atom.cpp 中,这一分离体现为两个独立入口函数:setup_chunks()(计算 Nchunk 与 bin 几何)和 compute_ichunk()(分配逐原子 chunk ID),外部命令(fix ave/chunk 及 compute \*/chunk 系列)可以直接调用它们而无需走 compute_peratom() 路径。
体系中所有使用 chunk ID 的其他命令都默认:存在 Nchunk 个 chunk,每个原子要么属于其中一个,要么不属于任何 chunk。
3. bin 风格:空间分箱的几何规则
bin 风格对原子做空间分箱,原子得到其所在 bin 的编号作为 chunk ID,Nchunk = bin 数。box 尺寸变化时 bin 数可能随之变化,这取决于 units 关键字的设置(例如 reduced 单位下即使 box 尺寸变化,chunk 数也不变)。
3.1 bin/1d、bin/2d、bin/3d
这三个风格分别把空间划分为 1D 层(slab)、2D 铅笔(pencil)和 3D 盒子。dim/origin/delta 分别指定 1、2、3 次;对 2D/3D bin,维度书写顺序不限(可以先 x 后 y,也可以先 y 后 z)。每个维度上 bin 的厚度由 delta 决定,bin 相对 origin 定义——origin 可以是该维度 box 的下边缘(lower)、上边缘(upper)、中心(center),或一个指定的坐标值。从 origin 出发,向两个方向创建足够多的 bin,直到完全覆盖模拟 box 或 bound 关键字指定的范围。
源码 setup_xyz_bins() 中可以看到具体做法:先按 origin 解析出该维度的 bin 起点 offset<a href="https://link.gitcode.com/i/b26a9463370b721e41da95398e4de2a3" target="_blank">m],然后取"紧贴 boxlo 下方的边界"和"紧贴 boxhi 上方的边界",nlayers[m] = round((hi - lo) / delta),总 bin 数为各维 nlayers 的乘积 nbins *= nlayers[m]。逐原子映射在 [atom2bin1d/2d/3d() 中完成,核心就一行整除运算:ibin = (xremap - offset[0]) * invdelta[0],再按 discard 规则裁剪越界值。2D/3D 的编号规则(第 4 节末尾详述)对应 ibin = i1bin * nlayers[1] * nlayers[2] + i2bin * nlayers[2] + i3bin。
正交与三斜 box 的差异。 对正交 box,bin 的面平行 xyz 坐标轴;对三斜(非正交)box,bin 的面平行 box 的倾斜面。按 LAMMPS 三斜 box 记法(棱向量 a、b、c),x 维 bin 的面法向为 b×c 方向,y 维为 a×c 方向,z 维为 a×b 方向。为了使 bin 的大小和位置定义无歧义,三斜 box 必须把 units 设为 reduced。这一点在源码中有硬性检查:
if (domain->triclinic == 1 && scaleflag != REDUCED)
error->all(FLERR, Error::NOLASTLINE,
"Compute chunk/atom for triclinic boxes requires units reduced");
(见 compute_chunk_atom.cpp#L394-L397。)
reduced 单位下 origin/delta 的含义:无论 box 如何倾斜,origin 为 0.0 表示从该维度的下起始面开始,1.0 表示从上面开始;delta = 0.1 意味着 0.0 到 1.0 之间共 10 层,与 box 当前尺寸、形状无关。
3.2 bin/sphere
围绕原点 (xorig, yorig, zorig) 建立一组球壳 bin,共 nsbin 层,半径在 rmin 到 rmax 之间等间隔分布。这实际上是一个 1D bin 向量。例如 rmin = 1.0、rmax = 10.0、nsbin = 9 时,第一层覆盖 1.0 < r < 2.0,最后一层覆盖 9.0 < r < 10.0。无论 box 正交还是三斜,球壳几何不变(不会因不同维度尺度不同而变成椭球壳)。setup_sphere_bins() 中还实现了 pbc yes 的约束检查:任一周期方向上若 rmax 超过 box 长度的一半,直接报错 bin/sphere radius is too large for periodic box。
3.3 bin/cylinder
定义一个沿 dim 轴、轴坐标 (c1, c2) 的圆柱 bin 体系:dim = x 时 c1/c2 = y/z;dim = y 时 c1/c2 = x/z;dim = z 时 c1/c2 = x/y。这实际是一个 2D bin 数组:第一维沿圆柱轴向(用 origin/delta 描述,同 bin/1d),第二维是距轴线的径向方向,在 rmin 到 rmax 之间有 ncbin 个同心圆层。例如 rmin = 1.0、rmax = 10.0、ncbin = 9 时,第一层覆盖 1.0 < r < 2.0,最后一层覆盖 9.0 < r < 10.0。径向几何同样不随三斜 box 倾斜成椭圆。2D 系统中圆柱轴必须是 z 方向(源码 L345-L346 有检查)。
3.4 bin 编号规则
所有 bin(即 chunk ID)从 1 连续编号到 bin 总数 Nchunk:
- bin/2d 与 bin/3d:最后一个维度的编号变化最快,第二维度次之,第一维度最慢(最后维度可以是 x、y 或 z);
- bin/sphere:半径最小的 bin 是 chunk 1,最大半径的是 chunk Nchunk = nsbin;
- bin/cylinder:沿圆柱轴方向的编号比径向变化快;
- 同一维度内,编号随坐标值(笛卡尔坐标、球/圆柱半径、轴向位置)增大而增大。
4. type、molecule 与 compute/fix/variable 风格
4.1 type
chunk ID = 原子类型,Nchunk = 体系定义的原子类型数(例如通过 create_box 或 read_data 设定)。源码中直接取 nchunk = atom->ntypes。
4.2 molecule
chunk ID = 每个原子的 molecule ID,Nchunk = 最大 molecule ID(不计指定 group/region 之外的原子)。两点注意事项:
- 同一分子的原子不要求都被赋予相同的 chunk ID(0 或非 0),但如果你要计算逐分子性质,通常希望如此。LAMMPS 会在 Nchunk 首次计算时做一次性检查(check_molecules()),发现"分子被切开"(部分原子在 chunk 内、部分被排除)时发出警告
One or more chunks do not contain all atoms in molecule。 - molecule ID = 0 的原子(通常是非分子溶剂原子)的 chunk ID 越界,根据
discard关键字被丢弃(不归属任何 chunk)或归入 Nchunk。 - molecule ID 不能超过 MAXSMALLINT,否则初始化时报错(init())。
4.3 compute/fix/variable 风格
这类风格把其他对象算出的 per-atom 浮点量作为 chunk ID:
- 以
c_开头:后面必须是输入脚本中已定义的 compute ID,使用其 per-atom 向量或第 I 列 per-atom 数组; - 以
f_开头:引用 fix 的 per-atom 向量/数组。注意有些 fix 只在特定步长产生值,必须与本 compute 访问它的步长兼容,否则报错(源码 L1151-L1154 会检查update->ntimestep % fchunk->peratom_freq); - 以
v_开头:引用一个 atom 或 atomfile 风格的 variable 名称。atom 风格 variable 可引用热力学关键字、逐原子属性,或求值时调用其他 compute/fix/variable,因此这是生成逐原子量最灵活的手段。
浮点值到整数的转换规则统一为:向下取整;整数 ≤ 0 时该原子 chunk ID = 0;整数 > 0 时即为 chunk ID;Nchunk = 最大 chunk ID(不含 group/region 之外的原子)。源码对应 assign_chunk_ids() 中的 ichunk<a href="https://link.gitcode.com/i/32374f61f3764865526dae13eea1839a" target="_blank">i] = static_cast<int>(vec[i]),以及 [setup_chunks() 中对非 bin 风格扫描最大 ID 并用 MPI_Allreduce(..., MPI_MAX) 求全局最大值。用户也可以自行编写 compute/fix 风格并添加进 LAMMPS(参见 Modify 文档)。
由于 chunk ID 是整数,浮点属性(如电荷、能量)会被截断;Howto chunk 指南 建议用一个 variable 先把浮点值缩放,使其散布在多个整数上。该指南还总结了常见 chunk 定义方式,例如:同分子原子、同类型原子、同属性原子(charge/radius 等,用 compute property/atom 输出)、同簇原子(compute cluster/atom 输出)、同空间 bin、刚性体、势场能量相近、局部缺陷结构相同(compute centro/atom 或 compute coord/atom)等。
5. Nchunk 何时计算,以及 fix ave/chunk 的锁定机制
通常,每次调用本 compute 都会重算 Nchunk(值可能不变)。nchunk once 表示永不改变。此外,如果 fix ave/chunk 正在使用本 compute,它可以在若干时间窗内关闭 Nchunk 的重算——窗口范围由 fix 的 Nevery、Nrepeat、Nfreq 与 ave 关键字共同决定:
ave one时,在每个 Nfreq 长的窗口内,Nchunk 从该窗口内第一次做平均的步保持到该窗口内最后一次做平均的步(Nfreq 的倍数);ave running或window时,Nchunk 从 fix 首次调用本 compute 的那一步起永久保持恒定。
多个 fix ave/chunk 可以共享同一个 chunk/atom compute,但它们诱导的"Nchunk 恒定窗口"必须完全一致,否则报错。源码层面这是通过 lock()/unlock() 接口实现的:
void ComputeChunkAtom::lock(Fix *fixptr, bigint startstep, bigint stopstep)
{
if (lockfix == nullptr) { /* 记录第一个锁 */ return; }
if (startstep != lockstart || stopstep != lockstop)
error->all(FLERR, Error::NOLASTLINE,
"Two fix commands using same compute chunk/atom command in incompatible ways");
lockfix = fixptr; // 锁移交给最后一个调用者,以便它负责 unlock
}
(见 compute_chunk_atom.cpp#L810-L826。)setup_chunks() 检测到 lockfix 存在时直接返回缓存的 Nchunk,不重建 bin。
6. 可选关键字详解:语义、默认值与交互规则
不同风格下部分关键字行为不同或被忽略,默认值也随风格而变。逐项说明如下。
6.1 region(所有风格)
如果指定,原子必须同时在指定 group 和指定几何 region 中才会被分到 chunk;不满足的原子 chunk ID 恒为 0。源码在 assign_chunk_ids() 中用 region->match(x) 对每个原子判定并写入 exclude 数组。
6.2 nchunk(所有风格)
控制 Nchunk 的重算频率,进而影响原子 chunk ID。once = 只在首次调用时计算一次;every = 每次调用都重算(注意可被 fix ave/chunk 的锁定机制覆盖)。默认值依风格而定(源码 L294-L309 及 init()):
type风格:默认once;molecule风格:无 region 时默认once,有 region 时默认every;- bin 风格:box 尺寸静态或
units reduced时默认once,box 尺寸动态且 units 为 lattice/box 时默认every(bin 风格下若显式设置了compress yes,则默认值被强制改为every); - compute/fix/variable 风格:默认
every。
另外源码强制一条一致性规则:ids once 时 nchunk 必须也是 once,否则报错 ids once but nchunk is not once。
6.3 limit(除 bin 风格外有效)
限制 Nchunk 的取值。bin 风格忽略此关键字,因为其 bin 数可以用 bound 关键字裁剪。三种取值:
limit 0:不设限(但compress仍可能缩减 Nchunk);limit Nc max:Nchunk 取 min(Nchunk, Nc);limit Nc exact:Nchunk 直接置为 Nc,无论原值大小。
若 Nchunk 被限小,chunk ID > Nchunk 的原子按 discard 设置被置 0 或置 Nchunk;若 Nchunk 被限大,则出现若干没有原子的 chunk。
limit 与 compress 的组合顺序很重要(setup_chunks() 的三段式处理与之逐行对应):
- 未设
compress yes:limit 先对原始 Nchunk 生效(max 取小值 / exact 直接覆盖)。 compress yes写在limit之前:先压缩(Nchunk 变为"有原子的 ID 数"),再对压缩后的值应用 limit。此时所有原子最终 ID ≤ Nc,但压缩前原始值(如 molecule ID)可能 > Nc。compress yes写在limit之后:limit 先应用于未压缩 Nchunk,且仅当 Nc < Nchunk 时生效(等价于把 ID > Nc 的原子置 0 或 Nc),然后才压缩;若压缩后新 Nchunk < Nc 且 limit 为 exact,则把 Nchunk 回填为 Nc,产生空 chunk。此情形下所有原子 ID ≤ Nc,且其原始值也 ≤ Nc。
6.4 ids(所有风格)
once:首次分配的 chunk ID 永久保持,之后不再重算;nfreq:若被fix ave/chunk使用,在每个 Nchunk 恒定的时间窗内,窗口首步分配的 ID 保持到窗口结束;every(默认):每次调用都重算。
重启文件的注意事项(官方 note):若希望从 restart 文件续算时保持持久 chunk ID 连续,应使用与原运行相同的 compute ID,因为持久 ID 是靠一个同名前缀的 fix store 保存的,ID 一致才能正确初始化。从源码 init() 可以看到机制:当 ids once(或 ids nfreq 且有 fix 锁定)时,compute 会自动创建 ID_COMPUTE_STORE 这个 fix store/atom,把每次算出的 ID 存入其 vstore 数组,后续调用直接取回(compute_ichunk() 的 restore 分支)。
6.5 compress(所有风格)
把"稀疏"的 chunk ID 集(大量 ID 没有原子)压缩为"稠密"集(每个 chunk 至少有一个原子)。两个典型场景:
- box 大部分是空区时,bin 风格会产生许多无原子 bin;
- molecule / compute/fix/variable 风格可能产生极大的 Nchunk。例如
compute cluster/atom给每个原子赋予其所属簇中某原子的 ID,百万原子体系只有 5 个簇时,最大 chunk ID 可能是 100 万,compress yes会把 Nchunk 重置为 5。
compress no(默认)不做任何压缩。compress yes 时:去掉所有无原子 ID、排序剩余 ID、重新编号 1 到新的 Nchunk,原子 chunk ID 同步更新。压缩前的原始 ID 可通过 compute property/chunk 的 id 关键字、或 fix ave/chunk 全局输出数组中的一列访问。例如上述 5 簇的原始 ID (27, 4982, 58374, 857838, 1000000) 压缩后变为 (1,2,3,4,5),原始值可由 fix ave/chunk 或 fix ave/time + compute property/chunk 输出。
官方 note 同时警告压缩的代价:需要跨所有处理器共享 ID 的全局通信;每个处理器都要用 STL map 存 ID 列表,唯一 ID 很多时内存开销大;每个原子都要访问一次 map。compress_chunk_ids() 中有一个阈值优化:全处理器唯一 ID 总数 ≤ 1024×1024(IDMAX)时用 MPI_Allgatherv 一次交换;超过则退化为环形通信(comm->ring + idring 回调),避免超大 allgather。
6.6 discard(所有风格)
决定"算出的 chunk ID 不在 1..Nchunk 范围内"的原子如何处置。注意它不适用于不在 group/region 内的原子——那些原子永远是 chunk ID = 0。
- 非 bin 风格只能用
yes(默认)或no:yes把越界原子置 0;no把它们并入最后一个 chunk(chunk ID = Nchunk)。越界来源包括:Nchunk 被limit限小、压缩后某些原 ID 失效、molecule 风格下新加入的分子 ID 超过旧 Nchunk、compute/fix/variable 在后续步长返回了超出旧 Nchunk 的值等。 - bin 风格用
discard决定"落在 bin 覆盖域外的原子"是丢弃还是归入最近 bin,默认mixed:bin/1d/2d/3d:yes→ 域外原子置 0;no→ 归入该维度首/末 bin;mixed(默认)→ 仅当该方向 bin 延伸到 box 边界(即bound为lower/upper,默认如此)时才归入首/末 bin,若 bound 是数值,则超出数值边界的原子置 0(细节:若 origin 导致首/末 bin 本身超出数值 bound,只有真正落在首/末 bin 之外才置 0)。bin/sphere:yes→ 域外置 0;no或mixed→ 距原点距离 < rmin 的归入最内层,> rmax 的归入最外层。bin/cylinder:yes→ 域外置 0;no→ 径向和轴向都归入首/末 bin;mixed(默认)→ 径向按no处理,轴向仅在 bin 延伸到 box 边界(bound 为 lower/upper)时归入首/末 bin,数值 bound 下越界置 0。
非 bin 风格使用 discard mixed 会在构造时报错(源码 L323-L325)。
6.7 bound(仅 bin/1d/2d/3d 与 bin/cylinder 轴向)
可多次使用,限制指定维度上分箱的覆盖范围(只给 box 的一部分分箱)。lo lower 或 hi upper 时该方向延伸到 box 边界;给数值时只延伸到该值(LAMMPS 不检查该值是否在 box 内附近)。使用 bound 通常会减少总 bin 数,从而减小 Nchunk。
6.8 pbc(仅 bin/sphere 与 bin/cylinder)
yes 时,原子到球心/轴的距离在周期方向上按最小镜像计算:若 x 周期且原子与球心的 x 向距离超过 box x 长度一半,则减去一个 box 长度。这样球/圆柱中心可以靠近 box 边缘,周期镜像中的原子仍算作离中心近。注意 yes 要求:除圆柱轴向外的任一周期方向上,外半径必须 ≤ 0.5 × box 长度,否则报错(setup_sphere_bins() / setup_cylinder_bins())。
6.9 units(仅 bin 风格)
决定分箱距离参数(delta、origin/bounds、球心/半径等)的单位含义:
box:使用units命令定义的标准距离单位(如 real/metal 下的 Å);lattice:以晶格常数为单位,前提是已用lattice命令定义;源码会按维度取xlattice/ylattice/zlattice分别缩放;reduced:0 到 1 的无量纲值,分别表示 box 的下/上面。origin 0.5 = 该维度中心,delta 0.1 = 该维度 10 层 bin。
三斜 box 只能用 reduced(见 3.1 节强制检查)。另外两个缩放细节:bin/sphere 的 rmin/rmax 按晶格常数或 x 维 reduced 值缩放;bin/cylinder 的 crmin/crmax 按垂直于圆柱轴的第一个维度的晶格常数或 reduced 值缩放(x 轴圆柱按 y、y 轴圆柱按 x、z 轴圆柱按 x)。
7. 输出信息与使用方式
本 compute 产生两个输出:
- per-atom 向量:无量纲 chunk ID,1 到 Nchunk(已分组原子)或 0(未分组原子),可被任何接受 per-atom compute 值的命令使用;
- 全局标量:Nchunk 的值,可在任何非 per-atom 上下文中访问。
输出选项总览参见 Howto output 页面。典型的"分块统计"完整用法来自 Howto chunk 指南,例如计算 2D 空间中 1000 个空间 bin 内的平均速度:
compute cc1 all chunk/atom bin/2d x 0.0 0.1 y lower 0.01 units reduced
fix 1 all ave/chunk 100 10 1000 cc1 vx vy file tmp.out
以及用 compute property/chunk 统计簇大小并做直方图:
compute cluster all cluster/atom 1.0
compute cc1 all chunk/atom c_cluster compress yes
compute size all property/chunk cc1 count
fix 1 all ave/histo 100 1 100 0 20 20 c_size mode vector ave running beyond ignore file tmp.histo
compute \*/chunk 系列(angmom/chunk、com/chunk、dipole/chunk、gyration/chunk、inertia/chunk、msd/chunk、omega/chunk、temp/chunk、torque/chunk、vacf/chunk、vcm/chunk、property/chunk 等)都直接接收本命令的 ID 作为输入;Howto chunk 还给出了逐分子质心、逐分子合力与 ave()/max() 特殊函数、compute reduce/chunk + compute chunk/spread/atom 二级分块等 7 个完整示例。
8. dump image 中的分箱边界可视化
compute chunk/atom 支持与 dump image 的 compute 关键字配合,在渲染图像中画出 bin 边界。目前只支持 bin/1d、bin/2d、bin/3d:3D 系统中 bin/1d 与 bin/2d 用三角形拼成表示 bin 边界的矩形;2D 系统或 bin/3d 则用圆柱把边界画成线(bin/3d 即 3D 网格线框)。源码 compute_image() 正是按此逻辑生成 Graphics::TRIANGLE / Graphics::CYLINDER 对象:2D 系统每维 nlayers + 1 条线,3D 的 bin/1d 与 bin/2d 每维两个三角形拼一个矩形面,bin/3d 每个 bin 面 4 条边。
矩形/线的颜色默认取第一种原子类型的颜色(color style 为 type 或 element 时);color style 为 const 时默认可由 dump_modify ccolor 修改,透明度默认不透明,可用 dump_modify ctrans 修改。2D 系统或 3D 的 bin/3d 中,fflag1 控制表示边界的圆柱两端是否加球帽(0 无帽、1 下端加帽、2 上端加帽、3 两端加帽);fflag2 用来调节渲染圆柱半径,必须 > 0 否则不可见(内部把直径设为 0,因为缺少对所有 wall 类型和单位设置都适用的启发式)。3D 系统的 bin/1d、bin/2d 则忽略 cflag1/cflag2。
四张官方示意图分别展示 3D 体系的 bin/1d、bin/2d、bin/3d 与 2D 体系的 bin/2d(见文首图片,源文件 chunk-3d-1d-bin.png、chunk-3d-2d-bin.png、chunk-3d-3d-bin.png、chunk-2d-2d-bin.png);对应的图形化测试用例位于 compute-image-chunk-bin1d.yaml 与 compute-image-chunk-bin3d.yaml。
9. 限制、默认值速查与相关命令
Restart 限制。 即使 nchunk once,分配给每个原子的 chunk ID 也不会存入 restart 文件,不能期望重启后这些分配自动延续;必须在重启模拟开始时重新指定该命令并重新分块(持久 ID 经由 6.4 节所述的 fix store/atom 机制,仍需 compute ID 保持一致)。
默认值汇总(官方文档 Default 一节):
- region = none
- nchunk = every(若 compress 为 yes,覆盖下列其他默认)
- nchunk = once(type 风格)
- nchunk = once(molecule 风格且无 region)/ every(molecule 风格有 region)
- nchunk = once(bin 风格,box 尺寸静态或 units = reduced)/ every(bin 风格,box 尺寸动态且 units 为 lattice 或 box)
- nchunk = every(compute/fix/variable 风格)
- limit = 0
- ids = every
- compress = no
- discard = yes(所有非 bin 风格)/ mixed(bin 风格)
- bound = 各维度 lower 和 upper
- pbc = no
- units = lattice
相关命令:fix ave/chunk、compute global/atom,以及 Howto chunk 中的全套分块统计示例。