gmx distance 命令,配合强大的选区(selection)语法,可以非常灵活地完成这类计算。今天就来详细讲讲如何用 gmx distance 计算任意组分或参考点之间的距离。
在开始之前,先理解 GROMACS 选区语法的核心思想:你可以通过 -select 参数直接在命令行中定义要计算距离的两个位置,而不需要提前制作复杂的索引文件(虽然索引文件依然是一种可选方式)。
gmx distance 的基本工作原理是:你在 -select 中提供一对位置,程序计算它们之间的距离随时间的变化。选区中的 plus 关键词用于连接两个位置。
⚠️注意:gmx distance 计算的是固定配对的距离。对于计算两组之间的最小距离、最大距离或所有两两距离,应使用 gmx pairdist。
这是最常用的方法。首先用 gmx make_ndx 创建索引文件,定义好两个组,然后在 gmx distance 中通过 -select 引用它们。
gmx make_ndx -f md.tpr -o index.ndx
在交互界面中,用 ri 列出残基,用 r 残基号 选择残基,用 name 组名 命名组例如:
> ri # 列出所有残基
> r 1-50 # 选择残基 1 到 50
> name 19 Protein_A # 命名为 Protein_A(注意组编号)
> r 100-150 # 选择另一个组
> name 20 Protein_B
> q # 退出保存
gmx distance -s md.tpr -f md.xtc -n index.ndx -select 'com of group "Protein_A" plus com of group "Protein_B"' -oall dist.xvg
这里的选区语法 'com of group "组名 A" plus com of group "组名 B"' 表示:计算组 A 的质心(center of mass)与组 B 的质心之间的距离。
如果你不想制作索引文件,可以直接在 -select 中用原子选择条件来定义两组:
gmx distance -s md.tpr -f md.xtc -select 'com of resnr 1 to 50 plus com of resnr 100 to 150' -oall dist.xvg
或者按链选择:
gmx distance -s md.tpr -f md.xtc -select 'com of chain "A" plus com of chain "B"' -oall dist.xvg
按残基名选择:
gmx distance -s md.tpr -f md.xtc -select 'com of resname "Protein" plus com of resname "Ligand"' -oall dist.xvg
💡 小技巧:选区语法非常灵活,你可以组合使用各种条件,比如 resnr 204 and name OD1 and chain G 表示链 G 中残基 204 的 OD1 原子。
-s md.tpr | |
-f md.xtc | |
-n index.ndx | |
-select '...' | |
-oall dist.xvg | |
-[no]pbc |
其他常用输出选项:
-oav distave.xvg:输出平均距离-oxyz distxyz.xvg:输出距离的 x、y、z 分量-oh disthist.xvg:输出距离的直方图-oallstat diststat.xvg:输出每个距离的平均值和标准差如果你需要计算某个组分的质心到空间中一个固定点的距离(比如到某个特定坐标位置),可以直接在选区中嵌入坐标。
gmx distance -s md.tpr -f md.xtc -n index.ndx -select 'com of group "Chain_A" plus [1.718, 3.711, 1.532]' -oall dist.xvg -nopbc
这里的 [1.718, 3.711, 1.532] 就是一个常量位置(constant position),单位 nm,表示空间中的一个固定点。plus 连接了组 A 的质心和这个固定坐标点,程序计算二者之间的距离。
⚠️注意:这里加了 -nopbc 参数,表示不使用周期性边界条件。因为固定坐标点可能位于周期性盒子之外,使用 PBC 可能导致距离计算错误。
你甚至可以直接在选区中定义更复杂的坐标表达式,比如:
# 计算质心到原点 (0,0,0) 的距离
gmx distance -s md.tpr -f md.xtc -select 'com of group "Protein" plus [0, 0, 0]' -oall dist.xvg -nopbc
# 计算某个原子到固定点的距离
gmx distance -s md.tpr -f md.xtc -select 'atomnr 100 plus [2.5, 1.2, 3.8]' -oall dist.xvg -nopbc
com of 选择 | |
cog of 选择 | |
[x, y, z] | |
atomnr N |
group "组名" | |
resnr N | |
resname "名称" | |
chain "X" | |
name "原子名" | |
resnr N to M |
A plus B | |
and / or |
如果需要同时计算多对距离,可以用多个 -select 参数,或者在一个选区中用多对位置:
gmx distance -s md.tpr -f md.xtc -select 'atomnr 1 plus atomnr 2 plus atomnr 3 plus atomnr 4' -oall dist.xvg
# 这会计算 1-2 和 3-4 两对距离
建议使用单引号包裹整个选区字符串,内部的双引号用于包裹组名或残基名:
-select 'com of group "Chain_A" plus com of group "Chain_B"'
如果混用不当,可能会导致 shell 解析错误。
-nopbc,因为固定点可能不在周期性盒子内对于大规模轨迹,选区解析和质心计算可能会消耗较多时间。如果反复使用相同的选区,可以考虑:
gmx select 生成索引文件,再用 -n 引用-dt 参数跳帧,减少计算量掌握这些基本语法后,你可以组合出更复杂的选择条件,满足各种分析需求。如果在使用中遇到问题,别忘了 gmx distance -h 可以查看完整的帮助信息!