在 LAMMPS 中实现基本示例

计算科学
2021-12-18 12:02:52

我想在 LAMMPS 中实现“分子动力学模拟的艺术”一书中的一个基本示例。它描述了 Lennard-Jones 势中分子的二维运动,定义为

u(rij)={4ε[(σrij)12(σrij)6]+εrij<rc=21/6σ0rijrc
使用温度和密度作为参数。二维区域的尺寸是(20,20),每个节点都有一个分子,产生 400 个分子。测量的值是总动能、总势能和总压力。

因此,我在 lamps 中的实现是

#First test, if I am able to write a lammps script on my own
#------------------Init-----------------
clear
units metal
dimension 2
boundary p p p
atom_style body nparticle 2 6
atom_modify map array#Array or Hash

#------------Create Atoms----------------
lattice sq 1
region box block 0 20 0 20 0 1 units lattice
create_box 1 box

lattice sq 1 orient x 1 0 0 orient y 0 1 0 orient z 0 0 1
create_atoms 1 box
replicate 1 1 1

#-----------Interatomic potential---------
pair_style lj/cut 1.122466
pair_coeff * * 1 1
neighbor 0.4 bin
velocity all create 1.44 87287 loop geom

#------------Define Settings---------------
compute eng all pe/atom
compute keng all ke/atom
compute eatoms all reduce sum c_eng
compute keatoms all reduce sum c_keng
#compute peng all pressure

#-------------Run minimization--------------
reset_timestep 0
fix 1 all box/relax iso 0.0 vmax 0.001
thermo 10
thermo_style custom step pe lx ly lz press pxx pyy pzz c_eatoms
min_style cg
minimize 1e-25 1e-25 5000 10000

variable natoms equal "count(all)"
variable teng equals "c_eatoms"
variable length equals "lx"
variable ecoh equal "v_teng/v_natoms"

print "Total energy (eV) = ${teng};"
print "Number of atoms = ${natoms};"
print "Lattice constant (Angstoms) = ${length};"
print "Cohesive energy (eV) = ${ecoh};"
print "All done!"

该实现大致正确,还是完全错误?
执行文件时,执行停止并出现错误

ERROR: Illegal variable command (../variable.cpp:512)

我该如何调试呢?

1个回答

您的问题似乎更多是关于“如何调试该错误”而不是错误本身。如果您希望我专门调查错误,我会这样做,我保证:)。

否则,从自己的错误中吸取教训并学习如何调试自己是很棒的。调试 lammps 脚本的最佳方法是使用以下命令:

echo both

在脚本的开头。该命令会将lammps处理的每一行一一输出到终端。您必须了解脚本是逐行读取和解释的。因此,如果您同时放置 echo ,则解释的每一行都将在解释时显示。这样,当代码崩溃时,它上面的行将是最后一个被处理的行,并且错误很可能位于该行中。就您而言,我相信您的错误很可能与您的计算命令之一有关。