in文件按照模块,大体可以分为三类:
一、in文件模板
(1)模拟环境参数设置
这一部分主要设置一些模拟参数,比如模拟体系的单位(units)、边界条件(boundary)、原子类型(atom_style)、邻居列表的定义(neighbor)、时间步长(timestep)等。
(2)体系模型的建立
这一部分的功能就是建立体系的原子模型,通常有两种方式。
第一种方式是使用lammps自带的建模命令建模,比如使用region命令划分区域,create_box命令生成模拟盒子,lattcie确定原子晶格常数,create_atoms生成原子。
使用命令行建模比较抽象,建模过程不是“所见即所得”,为了验证所建模型是否符合要求,可以在建模代码的后面使用write_data命令把模型保持为data文件,在lammps中运行in文件,用ovito观察一下模型是否正确。
第二种建模方式是使用其他软件进行可视化的建模,例如Material studio、Atomsk等软件,建模完成后转换为lammps可以识别data文件,使用read_data命令读入到lammps中。
(3)力场的设置
模型建好之后,需要设置力场参数,也就是常说的势函数设置。
力场的设置分两步,首先设置力场类型,如pair_style、bond_style、angle_style、dihedral_style、improper_style。
之后,设置与之相对于的参数,分别使用pair_coeff、bond_coeff、angle_coeff、dihedral_coeff、improper_coeff。
(4)能量最小化
在正式模拟之前,一般都需要进行能量最小化,消除模型不合理的结构。
能量最小化要在温度初始化之前进行,min_style确定能量最小化类型,minimize命令设置相关参数。
(5)温度初始化
能量最小化之后,就可以进行温度初始化。体系的温度是根据原子的速度计算得到的,因此,温度初始化也就是对原子进行速度初始化。
使用velocity命令按照设定的规律随机设定原子速度,使体系温度设定为一个固定值。
(6)弛豫
在npt、nvt等系综下,对体系进行充分的弛豫,使体系的能量达到最低,获得平衡态的结构。
前面这6部分是模拟准备过程,到此为止,体系已经达到平衡,可以进行下一步模拟。
这6部分的代码在大部分的模拟中都是通用的。
(7)具体模拟设置
这一部分代码与模拟的具体内容有关,比如拉伸、剪切、结晶、吸附等等。设置输出轨迹文件、热力学数据等等,便于后期统计分析。
对于不同的模拟过程,lammps模拟in文件可能会有区别,总体结构类似,大部分代码是重复的。
二、代码示例
#in文件模板
#----------0 参数设置--------------------
variable temperature equal 300 #初始温度
variable relaxtemperature equal 300 #弛豫温度
variable tensiontemperature equal 300 #拉伸温度
variable tstep equal 0.001 #步长
variable tdamp equal 100*${tstep} #温度耦合步长
variable pdamp equal 1000*${tstep} #压强耦合步长
variable thermalstep equal 100 #输出模拟结果信息
variable dumpstep equal 100 #参数输出步长
variable medoldumpstep equal 1000 #模型输出步长
variable relaxtime equal 100000 #弛豫时长
variable tensiontime equal 10000000#拉伸时长
variable pressure equal 0 #压强控制
variable strain equal 0.3 #拉伸应变
variable deformrate equal 0.001 #deform拉伸速率
variable velocityrate equal 0.001 #velocity拉伸速率
#----------1 模拟参数--------------------
units metal
dimension 3
boundary p p p
atom_style atomic
atom_modify map array sort 100 2.0
neighbor 3.0 bin
neigh_modify every 1 delay 0 check yes
timestep ${tstep}
#----------2 体系模型的建立----------------
#输出原子初始结构
read_data gp.lammpstrj
#----------3 力场的设置-------
pair_style airebo 3.0 1 1
pair_coeff * * CH.airebo C
#----------4 能量最小化-------
thermo 100
thermo_style custom step press pe temp ke
dump 1 all atom 100 mini.lammpstrj
min_style cg
minimize 1.0e-10 1.0e-10 10000 10000
undump 1
reset_timestep 0
#-----------5 温度初始化--------
velocity all create ${temperature} 534567 dist gaussian units box
#-----------6 弛豫-------------
#能量计算
compute 2 all pe/atom
compute pe all reduce sum c_2
variable PE equal "c_pe"
#nvt弛豫
thermo ${thermalstep}
thermo_style custom step temp press lx ly lz pe ke etotal
fix 1 all nvt temp ${relaxtemperature} ${relaxtemperature} ${tdamp}
fix pe all print ${dumpstep} "${PE} " file PE1.txt screen no
dump 1 all custom ${medoldumpstep} relax_x1.lammpstrj id type x y z
run ${relaxtime}
undump 1 #取消fix、dump设定,步数清零
unfix 1
reset_timestep 0
#npt弛豫
thermo ${thermalstep}
thermo_style custom step temp press lx ly lz pe ke etotal
fix 1 all npt temp ${relaxtemperature} ${relaxtemperature} ${tdamp} iso ${pressure} ${pressure} ${pdamp} drag 1
fix pe all print ${dumpstep} "${PE} " file PE2.txt screen no
dump 1 all custom ${medoldumpstep} relax_x2.lammpstrj id type x y z
run ${relaxtime}
undump 1 #取消fix、dump设定,步数清零
unfix 1
reset_timestep 0
#-------7 具体模拟设置-------
#力学性能参数计算
variable num equal count(all) #计算原子数目
variable toval equal lx*ly*3.35 #计算系统总体积,单层石墨烯厚度为0.335nm
variable vol equal ${toval} #体系的初始体积
variable vatom equal v_vol/v_num #单个原子体积
variable lx equal lx
variable lx0 equal ${lx}
variable ly equal ly
variable ly0 equal ${ly}
variable xstrain equal "(lx - v_lx0) / v_lx0" #计算x方向应变
variable ystrain equal "(ly - v_ly0) / v_ly0" #计算y方向应变
compute stress all stress/atom NULL #计算体系中单原子应力
compute xalls all reduce sum c_stress[1] #计算体系中各方向应力
compute yalls all reduce sum c_stress[2]
compute zalls all reduce sum c_stress[3]
compute xyalls all reduce sum c_stress[4]
variable xstress equal "1.0e-4 * c_xalls/v_toval"
variable ystress equal "1.0e-4 * c_yalls/v_toval"
variable zstress equal "1.0e-4 * c_zalls/v_toval"
variable xystress equal "1.0e-4 * c_xyalls/v_toval"
#具体模拟设置
thermo ${thermalstep}
thermo_style custom step temp lx ly lz v_xstrain v_ystrain v_xstress v_ystress pe ke etotal
fix 2 all npt temp ${tensiontemperature} ${tensiontemperature} ${tdamp} y ${pressure} ${pressure} ${pdamp} z ${pressure} ${pressure} ${pdamp} drag 1
fix 3 all deform 1 x erate ${deformrate} remap x units box
fix 4 all ave/time 1 ${dumpstep} ${dumpstep} v_xstrain v_ystrain v_xstress v_ystress file x.txt
dump 2 all custom ${medoldumpstep} load_x.lammpstrj id type x y z c_stress[1] c_stress[2] c_stress[3] c_stress[4]
fix 5 all halt ${dumpstep} v_xstrain > ${strain} error continue #拉伸终止
run ${tensiontime}
本文参考公众号:lammps加油站
若有问题,欢迎讨论