Moltemplate:用子单元搭建聚合物链
构建12珠谐键链,说明父分子编号和跨子单元连接,并用解析能量与力检查连接是否正确。
阅读本篇目录
本文搭建12珠的粗粒化链,展示模块导入、继承、分子编号与跨子单元连键。珠子是演示单元,不是原子级聚合物或拟合势函数。使用Moltemplate 2.22.5和LAMMPS 30Sep2026 CPU版本。
1. 生成两个间距对照#
module load moltemplate/2.22.5
python prepare.py
cd cases/chain-1p4
这里用units lj无量纲单位、谐键K=100、平衡长度1.3,并把非键相互作用设为零,以便单独核对链连接。
2. 查看完整LT文件#
chainff.lt#
ChainFF {
write_once("In Init") {
units lj
atom_style full
pair_style zero 4.0
bond_style harmonic
}
write_once("Data Masses") {
@atom:bead 1.0
}
write_once("In Settings") {
pair_coeff * *
bond_coeff @bond:link 100.0 1.3
}
}
bead.lt#
import "chainff.lt"
Bead inherits ChainFF {
write("Data Atoms") {
$atom:site $mol:... @atom:bead 0 0 0 0
}
}
chain.lt#
import "bead.lt"
Chain inherits ChainFF {
create_var {$mol}
m0=new Bead.move(0.000000000000,0,0)
m1=new Bead.move(1.400000000000,0,0)
m2=new Bead.move(2.800000000000,0,0)
m3=new Bead.move(4.200000000000,0,0)
m4=new Bead.move(5.600000000000,0,0)
m5=new Bead.move(7.000000000000,0,0)
m6=new Bead.move(8.400000000000,0,0)
m7=new Bead.move(9.800000000000,0,0)
m8=new Bead.move(11.200000000000,0,0)
m9=new Bead.move(12.600000000000,0,0)
m10=new Bead.move(14.000000000000,0,0)
m11=new Bead.move(15.400000000000,0,0)
write("Data Bonds") {
$bond:b0 @bond:link $atom:m0/site $atom:m1/site
$bond:b1 @bond:link $atom:m1/site $atom:m2/site
$bond:b2 @bond:link $atom:m2/site $atom:m3/site
$bond:b3 @bond:link $atom:m3/site $atom:m4/site
$bond:b4 @bond:link $atom:m4/site $atom:m5/site
$bond:b5 @bond:link $atom:m5/site $atom:m6/site
$bond:b6 @bond:link $atom:m6/site $atom:m7/site
$bond:b7 @bond:link $atom:m7/site $atom:m8/site
$bond:b8 @bond:link $atom:m8/site $atom:m9/site
$bond:b9 @bond:link $atom:m9/site $atom:m10/site
$bond:b10 @bond:link $atom:m10/site $atom:m11/site
}
}
system.lt#
import "chain.lt"
p=new Chain
write_once("Data Boundary") {
-10 30 xlo xhi
-10 30 ylo yhi
-10 30 zlo zhi
}
$mol:...让珠子沿用父层的分子编号,create_var {$mol}在链层定义同一个分子。跨单元连接使用$atom:m0/site这类路径,编号由程序生成。每条原子或参数记录单独换行,避免多份模板展开后粘连成一行。
3. 生成并交给LAMMPS#
moltemplate.sh system.lt
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 ../chain-1p3
moltemplate.sh system.lt
lmp -in run0.in -log lammps.log
两者均为12珠、11键、1个分子。间距1.3时势能约2.8×10^-28,可视为零;间距1.4时势能为11,链端力的大小为20,中间珠的两侧力相互抵消。

4. 用公式核对#
LAMMPS谐键为K(r−r0)^2,不是再乘1/2。本例11条键的能量是11×100×(1.4−1.3)^2=11;单个端点力为2×100×0.1=20。thermo_modify norm no确保输出总能量,而不是每原子归一化能量。
cd ../..
/public/toolkit/miniconda3/envs/ase-3.29.0/bin/python analyze.py
cat analysis/models.csv
完整包会逐条检查连接图和解析力。真实聚合物还需要角、二面角、非键相互作用及经过验证的参数;本例是拓扑教学,不应用其零非键势预测材料性质。
下载完整可复跑资料包。解压到新目录执行 bash run.sh,脚本最多使用一个CPU线程。这里只做小型建模与六次run 0,没有MD采样;实际生产模拟按作业指南申请资源。每个条件有自己的LT输入、system.data、system.in.init、system.in.settings、run0.in和日志,输出表与图在analysis/、figures/。