Moltemplate:力场继承与混合参数
用二元LJ小模型讲清类型命名、共同继承和混合规则,比较自动交叉参数与显式交叉参数。
阅读本篇目录
多个分子共用力场时,先统一类型与单位,再通过继承复用参数。本文使用两种珠子的无量纲LJ演示模型,不代表真实混合物力场。
1. 查看共同定义与继承#
module load moltemplate/2.22.5
python prepare.py
cd cases/mix-arithmetic
cat forcefield.lt beads.lt system.lt
forcefield.lt#
ExampleFF {
write_once("In Init") {
units lj
atom_style full
pair_style lj/cut 8.0
pair_modify mix arithmetic
bond_style harmonic
special_bonds lj/coul 0 0 0
}
write_once("Data Masses") {
@atom:A 1.0
@atom:B 2.0
}
write_once("In Settings") {
pair_coeff @atom:A @atom:A 0.1 2.0
pair_coeff @atom:B @atom:B 0.4 3.0
}
}
beads.lt#
import "forcefield.lt"
A inherits ExampleFF {
write("Data Atoms") {
$atom:a $mol:... @atom:A 0 0 0 0
}
}
B inherits ExampleFF {
write("Data Atoms") {
$atom:b $mol:... @atom:B 0 0 0 0
}
}
system.lt#
import "beads.lt"
a=new A.move(0,0,0)
b=new B.move(4,0,0)
write_once("Data Boundary") {
-10 30 xlo xhi
-10 30 ylo yhi
-10 30 zlo zhi
}
A、B都继承ExampleFF,使用同一组类型定义。自己拼接两个完整力场时,不能只看LT导入是否成功,还必须核对单位、atom_style、pair_style、电荷和键角参数是否兼容。
2. 明确交叉参数规则#
本例设置pair_modify mix arithmetic。LAMMPS这里对epsilon取几何平均、sigma取算术平均,因此epsilonAB=√(0.1×0.4)=0.2,sigmaAB=(2+3)/2=2.5。
显式对照目录在system.lt末尾追加:
write_once("In Settings") {
pair_coeff @atom:ExampleFF/A @atom:ExampleFF/B 0.2 2.5
}
这里的命名路径对应共同父类定义,不要根据最终数字类型号猜类型。生成后的system.in.settings可以直接检查实际数字映射。
3. 运行自动与显式两个条件#
moltemplate.sh system.lt
cat system.in.settings
module load lammps/30Sep2026-8173m
export OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 I_MPI_FABRICS=shm
lmp -in run0.in -log lammps.log
cd ../mix-explicit
moltemplate.sh system.lt
lmp -in run0.in -log lammps.log
两粒子相距4,实际两种方式都得到总能量 −0.0448415448772721、单粒子受力大小 0.06299906090134756,均为本例无量纲单位。

4. 独立计算并比较#
python - <<'PY'
r=4.0; epsilon=0.2; sigma=2.5
energy=4*epsilon*((sigma/r)**12-(sigma/r)**6)
print(energy)
PY
这个简单对照适合检查类型和交叉参数;不能据此说明任意两个真实力场都可以混用。多体势、不同水模型或特殊交互项需要遵循各自的软件与物理模型约定。
下载完整可复跑资料包。解压到新目录执行 bash run.sh,脚本最多使用一个CPU线程。这里只做小型建模与六次run 0,没有MD采样;实际生产模拟按作业指南申请资源。每个条件有自己的LT输入、system.data、system.in.init、system.in.settings、run0.in和日志,输出表与图在analysis/、figures/。
需要根据你的体系选择资源?联系讨论计算需求。实际可用软件与权限,以当前账户和运行环境为准。