【LAMMPS翻译系列】compute命令

compute命令为一组原子执行某种计算。

使用语法

compute ID group-ID style args
  • ID = compute命令的ID
  • group-ID = 该compute命令所作用的原子组的ID
  • style = compute类型名(最下有列表)
  • args = 特定类型compute命令所需要的参数

使用举例

compute 1 all temp
compute newtemp flow temp/partial 1 1 0
compute 3 all ke/atom

使用介绍

该命令为一组原子执行某种计算。计算出的量是瞬时值,也就是说它们只是原子在当前时间步或迭代步的信息。当然,compute命令也可以在内部保存体系在之前一个状态的某些信息。

定义compute命令的时候并不会执行计算。真正的计算过程是被其他LAMMPS命令激活的,比如某些fix命令需要计算温度的时候,或这需要产生热力学信息的时候,或者需要dump输出到文件中的时候。

compute命令的ID只能包含字母、数字和下划线。




compute命令可以计算出全局量、单原子量或局部量中某一种类型的量。

  • 全局量(global)是系统维度的量,比如体系的温度。
  • 单原子量(per-atom)是每个原子都具有的量,比如每个原子的动能。不在compute命令所指定的组内的原子的该单原子量被设为0。
  • 局域量(local)是每个处理器基于它们所拥有的原子而计算出的量,比如键之间的距离。

计算产生单原子量的compute命令在其类型名中含有单词“atom”,比如ke/atom。计算产生局域量的compute命令在其类型名称中含有单词“local”,比如bond/local。类型名中不包含“atom”或“local”的compute命令计算产生的是全局量。

另外需要注意的是一个单独的compute命令只可能会产生这三种类型的量的某一种。

全局量、单原子量和局域量都有三种存在形式:单独的标量、一维矢量和二维阵列。每种具体类型的compute命令的页面会介绍它会产生哪种类型的变量,以及它的存在形式,比如单原子一维矢量。有些类型的compute命令会产生多种存在形式的某种类型的量,比如全局标量和全局矢量。

如果要使用compute命令计算出的量,比如使用输出命令将它们输出,可以使用下面的方括号记号来引用它们。其中的ID是compute命令的ID。

c_ID 整个标量、整个一维矢量、整个二维阵列
c_ID[I] 一维矢量中的一个元素、二维阵列中的一列
c_ID[I][J] 二维阵列中的一个元素

也就是说,使用使用一个方括号可以将量的维度降低一维,这样矢量就会变成标量,阵列就会变成矢量。使用两个方括号会将维度降低两次,也就是将阵列变为标量。通过这种方法,使用compute标量值作为输入的命令也可以同样处理矢量和阵列的元素。

注意:可以使用compute量的命令和变量并不是可以使用任何一种存在形式的量,比如一个命令可能会需要矢量类型的量,而不是标量类型的。这也就意味着在引用compute计算的量时不能含糊,而需要注意它的存在形式。这也会在具体介绍这些命令时详细的解释到。




在LAMMPS中,compute命令产生的值有下列的使用方法:

compute命令计算的全局量既可以是内部的,也可以是外部的。“内部”是说其值独立于模拟中的原子数,比如温度。“外部”是说其值的大小与模拟中的原子数有关系,比如总的转动动能。命令Thermodynamic output 会将外部量的值对体系中的原子数进行规范化,具体看“thermo_modify norm”的设置。但对于内部量,它不会进行规范化。如果使用其他方法对fix量进行引用,比如变量variable,你需要了解它是内部量还是外部量。




LAMMPS会在内部为热力学输出定义默认的compute计算,而且总会创建三种计算,分别命名为 "thermo_temp", "thermo_press" 和 "thermo_pe"。这种默认的定义与在输入脚本中使用了下面的命令效果相同:

compute thermo_temp all temp
compute thermo_press all pressure thermo_temp
compute thermo_pe all pe

如果热力学输出需要其他类型的量,可以再添加其他相应的compute计算。具体可以参考thermo_style命令。

可以计算温度或压强的fix命令,比如用于恒温或恒压的fix命令,在其内部也可以创建compute计算。这些在fix命令的页面有进行介绍。

上面列举的所有默认定义的compute计算,都可以通过在输入脚本中使用compute命令定义相应的计算而被替换。这些在thermo_modify命令和fix modify命令的页面有介绍。

不论是LAMMPS内部定义的还是用户自定义的compute命令,其设置都可以使用compute_modify命令进行修改。

compute定义的计算可以使用uncompute命令删除。

用户也可以自己通过编写代码创建新的compute命令,其结果的应用与上面提到的引用方法相同。




每一种类型的compute命令都有单独的文档页面来介绍其参数和它具体是做什么的。下面是lammps中可用的compute命令列表。(译注:compute命令会经常增加,所以这里列出的很可能并非全部。)

  • angle/local - theta and energy of each angle
  • atom/molecule - sum per-atom properties for each molecule
  • body/local - attributes of body sub-particles
  • bond/local - distance and energy of each bond
  • centro/atom - centro-symmetry parameter for each atom
  • cluster/atom - cluster ID for each atom
  • cna/atom - common neighbor analysis (CNA) for each atom
  • com - center-of-mass of group of atoms
  • com/molecule - center-of-mass for each molecule
  • contact/atom - contact count for each spherical particle
  • coord/atom - coordination number for each atom
  • damage/atom - Peridynamic damage for each atom
  • dihedral/local - angle of each dihedral
  • displace/atom - displacement of each atom
  • erotate/asphere - rotational energy of aspherical particles
  • erotate/rigid - rotational energy of rigid bodies
  • erotate/sphere - rotational energy of spherical particles
  • erotate/sphere/atom - rotational energy for each spherical particle
  • event/displace - detect event on atom displacement
  • group/group - energy/force between two groups of atoms
  • gyration - radius of gyration of group of atoms
  • gyration/molecule - radius of gyration for each molecule
  • heat/flux - heat flux through a group of atoms
  • improper/local - angle of each improper
  • inertia/molecule - inertia tensor for each molecule
  • ke - translational kinetic energy
  • ke/atom - kinetic energy for each atom
  • ke/rigid - translational kinetic energy of rigid bodies
  • msd - mean-squared displacement of group of atoms
  • msd/molecule - mean-squared displacement for each molecule
  • pair - values computed by a pair style
  • pair/local - distance/energy/force of each pairwise interaction
  • pe - potential energy
  • pe/atom - potential energy for each atom
  • pressure - total pressure and pressure tensor
  • property/atom - convert atom attributes to per-atom vectors/arrays
  • property/local - convert local attributes to localvectors/arrays
  • property/molecule - convert molecule attributes to localvectors/arrays
  • rdf - radial distribution function g(r) histogram of group of atoms
  • reduce - combine per-atom quantities into a single global value
  • reduce/region - same as compute reduce, within a region
  • slice - extract values from global vector or array
  • stress/atom - stress tensor for each atom
  • temp - 计算一组原子的温度
  • temp/asphere - temperature of aspherical particles
  • temp/com - temperature after subtracting center-of-mass velocity
  • temp/deform - temperature excluding box deformation velocity
  • temp/partial - temperature excluding one or more dimensions of velocity
  • temp/profile - temperature excluding a binned velocity profile
  • temp/ramp - temperature excluding ramped velocity component
  • temp/region - temperature of a region of atoms
  • temp/sphere - temperature of spherical particles
  • ti - thermodyanmic integration free energy values
  • voronoi/atom - Voronoi volume and neighbors for each atom

另外还有一些用户贡献的compute命令也发布在LAMMPS程序包中。这些类型的fix命令被列在this page

也有一些用于加速CPU和GPU计算速度的compute命令发布在LAMMPS程序包中。这些类型的compute命令被列在this page

相关命令

uncomputecompute_modifyfix ave/atomfix ave/spatialfix ave/timefix ave/histo

标签: lammps, lammps翻译

相关文章推荐

添加新评论 (无需注册,可直接评论)

已有 2 条评论

  1. 一个学生

    你好,现在这条命令的语法好像和以前不一样了,比如以前的例子中有这样的语句
    compute 2 all stress/atom
    而现在这样的语法会报错,要在末尾加上NULL才能正常运行

  2. 刘柱

    前辈你好,因为是lammps初学者,好多命令不知道咋写,我看到文献中提到可以计算垂直于界面的分子密度 (These density profile was obtained by computing the liquid density using slabs of 1 angstrom paralllel to the interface.),应该是可以在in文件中直接写命令来计算,我知道应该先计算center of mass,
    (compute com_mol all com/molecule
    fix com_mol_out all ave/time 1 1 100 c_com_mol file com_mol.dat mode vector ### output of center of mass per molecule)
    然后in文件该怎么写才能判定那些分子属于哪个slab,然后划分slab来做出密度与slab到interface距离的曲线呢,,麻烦前辈指导了,感激不尽!