仓库源文站点原文


layout: post title: GROMACS QM/MM教程2:编译设置及简单运行 categories:


上一篇博文GROMACS QM/MM教程1: QM/MM方法的实现中, 整理了GROMACS QM/MM方法的基本实现原理, 略显理论化, 本教程中具体讲解如何操作. 以下说明基于Windows下的GROMACS 5.1.4版本.

编译设置

编译GROMACS时, 要打开QM/MM功能选项. 一般是使用高斯--with-qmmm-gaussian, 因为后面一般是使用自己的外挂脚本, 所以就选这个我比较熟悉的. 当然, 如果你更熟悉MOPAC, ORCA或GAMESS, 也可以使用这三个, 但使用MOPAC必须修改源码, 使用GAMESS太复杂, 因此建议选择高斯或ORCA之一.

编译完成后, 在mdp中使用QM/MM的相关选项, 运行grompp, 可能出现下面的错误

  1. QMMM is currently only supported with cutoff-scheme=group

    如果你的mdp中没有设置cutoff-scheme=group, 就会提示这个错误. 按要求使用此选项就可以.

  2. QM/MM does not work in parallel, use a single rank instead

    GROMACS的QM/MM模块无法并行, 只支持单核. 运行时只能使用 gmx mdrun -nt 1. 但根据我的经验, 有时没有加-nt 1选项, mdrun仍可以运行, 详细情况有待考察.

  3. 无法找到环境变量GMX_QM_GAUSS_DIR, GMX_QM_GAUSS_EXE, GMX_QM_MODIFIED_LINKS_DIR

    这三个环境变量是GROMACS调用高斯时使用的, 必须设置, 否则就无法启动高斯.

    GROMACS最终在命令行中调用高斯使用的命令为

    【GMX_QM_GAUSS_DIR】/【GMX_QM_GAUSS_EXE】 < input.com > input.log

    所以你必须设置好需要的环境变量, 保证在命令行中上面的命令能运行成功. 三个环境变量的具体说明和设置如下:

  4. 高斯无法运行

    高斯运行时可能需要自己的环境变量 GAUSS_EXE_DIR, 需要的话, 按要求设置. 有时还需要将高斯路径加到path环境变量.

下面是不同系统的环境变量设置示例

<table class="highlighttable"><th colspan="2" style="text-align:left">~/.bashrc</th><tr><td><div class="linenodiv" style="background-color: #f0f0f0; padding-right: 10px"><pre style="line-height: 125%">1 2 3</pre></div></td><td class="code"><div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #AA22FF">export</span><span style="color: #bbbbbb"> </span><span style="color: #B8860B">GMX_QM_GAUSS_DIR</span><span style="color: #666666">=</span>E:/G09w<span style="color: #bbbbbb"></span> <span style="color: #AA22FF">export</span><span style="color: #bbbbbb"> </span><span style="color: #B8860B">GMX_QM_GAUSS_EXE</span><span style="color: #666666">=</span>g09.bsh<span style="color: #bbbbbb"></span> <span style="color: #AA22FF">export</span><span style="color: #bbbbbb"> </span><span style="color: #B8860B">GMX_QM_MODIFIED_LINKS_DIR</span><span style="color: #666666">=</span><span style="color: #BB4444">''</span><span style="color: #bbbbbb"></span> </pre></div> </td></tr></table>

简单运行

上面的设置都成功后, 就可以拿一个简单的体系来测试运行了. 可惜的是, GROMACS的QM/MM模块已经很老, 且无人更新, 坐等废弃, 所以你直接拿来运行时不大会成功的. 可行的解决方案就是自己写点代码, 将高斯的运行过程包装一下, 来代替直接使用GROMACS运行高斯. 上篇博文中已经给了这么一个bash脚本gau, 但写得比较乱, 不易扩展修改. 我整理改进了一下, 并加以注释. 想了解具体细节, 遇到问题或进行修改时, 可参考注释.

<table class="highlighttable"><th colspan="2" style="text-align:left">g09.bsh</th><tr><td><div class="linenodiv" style="background-color: #f0f0f0; padding-right: 10px"><pre style="line-height: 125%"> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106</pre></div></td><td class="code"><div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008800; font-style: italic">#/bin/bash</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">请仔细阅读此脚本,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">了解具体的处理过程</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">因为你可能需要对其修改才能适用于自己的体系</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">此脚本对</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">高斯GAUSSIAN</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">程序进行封装</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">主要使用awk对输入和输出文件进行转换</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">首先对GMX</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">QM/MM模块给出的高斯输入文件进行处理,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">生成新的输入文件</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">然后调用系统已安装的高斯程序运行新的高斯输入文件</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">最后将高斯的输出文件转换为GMX需要的格式,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">供其调用</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">**注意**</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">系统可能对长文件名支持不好,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">所以此脚本名称最好短一点</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">调用高斯程序的完整路径,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">根据自己的安装进行设置</span><span style="color: #bbbbbb"></span> GAUSSIAN<span style="color: #666666">=</span>E<span style="border: 1px solid #FF0000">:</span><span style="color: #666666">/</span>G09w<span style="color: #666666">/</span>g09.exe<span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">清空前一步运行用到的临时文件</span><span style="color: #bbbbbb"></span> rm<span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>rf<span style="color: #bbbbbb"> </span>_GMXtmp.<span style="color: #666666">*</span><span style="color: #bbbbbb"> </span>fort.<span style="color: #666666">7</span><span style="color: #bbbbbb"> </span>gxx.<span style="color: #666666">*</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">GMX</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">QM/MM给出一个"正常"的高斯输入文件</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">里面包含用户在mdp文件中给出的一些设置</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">但这个文件格式古老且死板,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">不适用</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">因此你需要自己提供一个</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">_Gkwd.gjf,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">放于工作目录下</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">里面指定计算时要使用的关键词(【标题】之前的部分)</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">这些关键词会覆盖GMX的默认设置</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">**注意**</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">1.</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">脚本坚持在输入文件中使用</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">埃</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">为单位,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">所以你</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">不能</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">再使用</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">Units=Bohr</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">2.</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">脚本会根据情况自动添加</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">Guess=Read,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">所以你</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">不能</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">再使用</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">Guess=Read</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">3.</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">脚本中</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">必须</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">使用</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">NoSymm</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">Force</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">Punch=Derivatives</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">三个关键词</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">4.</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">如果体系中有MM电荷,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">必须</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">使用</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">Charge</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">Prop=(Field,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">Read)</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">关键词</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">5.</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">其他关键词可根据自己的情况决定使用与否</span><span style="color: #bbbbbb"></span> [[<span style="color: #bbbbbb"> </span><span style="color: #666666">!</span><span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>e<span style="color: #bbbbbb"> </span>_Gkwd.gjf<span style="color: #bbbbbb"> </span>]]<span style="color: #bbbbbb"> </span><span style="color: #666666">&&</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span>echo<span style="color: #bbbbbb"> </span><span style="color: #BB4444">'</span>NO<span style="color: #bbbbbb"> </span>_Gkwd.gjf<span style="color: #bbbbbb"> </span><span style="color: #666666">!!!</span><span style="color: #BB4444">'</span>;<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">exit</span>;<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">使用自定义的关键词</span><span style="color: #bbbbbb"></span> awk<span style="color: #bbbbbb"> </span><span style="color: #AA22FF">NF</span><span style="color: #bbbbbb"> </span>_Gkwd.gjf<span style="color: #bbbbbb"> </span><span style="color: #666666">>></span><span style="color: #bbbbbb"> </span>_GMXtmp.gjf<span style="color: #bbbbbb"></span> awk<span style="color: #bbbbbb"> </span><span style="color: #BB4444">'</span><span style="color: #666666">/</span>guess<span style="color: #666666">=</span>read<span style="color: #666666">/</span>{<span style="color: #AA22FF; font-weight: bold">print</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">"Guess=Read"</span>}<span style="color: #BB4444">'</span><span style="color: #bbbbbb"> </span>input.com<span style="color: #bbbbbb"> </span><span style="color: #666666">>></span><span style="color: #bbbbbb"> </span>_GMXtmp.gjf<span style="color: #bbbbbb"></span> echo<span style="color: #bbbbbb"> </span><span style="color: #BB4444">""</span><span style="color: #bbbbbb"> </span><span style="color: #666666">>></span><span style="color: #bbbbbb"> </span>_GMXtmp.gjf<span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">使用GMX给出的【标题】【电荷</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">多重度】【QM坐标】【MM坐标</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">电荷大小】</span><span style="color: #bbbbbb"></span> awk<span style="color: #bbbbbb"> </span><span style="color: #BB4444">'</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF">BEGIN</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span>n<span style="color: #666666">=0</span>;<span style="color: #bbbbbb"> </span>Bhr<span style="color: #666666">=0.52917721092</span><span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF">NF</span><span style="color: #666666">==0</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span>n<span style="color: #666666">++</span><span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>n<span style="color: #666666">==1</span><span style="color: #bbbbbb"> </span><span style="color: #666666">&&</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF">NF</span><span style="color: #bbbbbb"> </span><span style="color: #666666">>0</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">print</span><span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>n<span style="color: #666666">==2</span><span style="color: #bbbbbb"> </span><span style="color: #666666">&&</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF">NF</span><span style="color: #666666">==4</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">printf</span><span style="color: #BB4444">"%4d</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">%16.7f</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">%16.7f</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">%16.7f\n"</span>,<span style="color: #bbbbbb"> </span><span style="border: 1px solid #FF0000">\</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #666666">$1</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">$2*</span>Bhr,<span style="color: #bbbbbb"> </span><span style="color: #666666">$3*</span>Bhr,<span style="color: #bbbbbb"> </span><span style="color: #666666">$4*</span>Bhr<span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>n<span style="color: #bbbbbb"> </span><span style="color: #666666">>2</span><span style="color: #bbbbbb"> </span><span style="color: #666666">&&</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF">NF</span><span style="color: #666666">==4</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">printf</span><span style="color: #BB4444">"%4s</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">%16.7f</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">%16.7f</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">%16.7f</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">%10.6f\n"</span>,<span style="color: #bbbbbb"> </span><span style="border: 1px solid #FF0000">\</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #BB4444">""</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">$1*</span>Bhr,<span style="color: #bbbbbb"> </span><span style="color: #666666">$2*</span>Bhr,<span style="color: #bbbbbb"> </span><span style="color: #666666">$3*</span>Bhr,<span style="color: #bbbbbb"> </span><span style="color: #666666">$4</span><span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>n<span style="color: #bbbbbb"> </span><span style="color: #666666">>1</span><span style="color: #bbbbbb"> </span><span style="color: #666666">&&</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF">NF</span><span style="color: #666666">!=4</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">print</span><span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #BB4444">'</span><span style="color: #bbbbbb"> </span>input.com<span style="color: #bbbbbb"> </span><span style="color: #666666">>></span><span style="color: #bbbbbb"> </span>_GMXtmp.gjf<span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">高斯无法直接给出MM电荷上的梯度</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">为得到MM电荷上的梯度,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">需要指定高斯计算MM位置上的静电场</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">然后根据MM电荷的大小和静电场计算出所需要的梯度</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">为此,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">需要再次提供MM电荷位置的坐标,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">并将其写到文件的最后</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">这些坐标仍然由GMX提供的文件获得</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">**注意**</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">下面两点脚本会自动处理</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">1.</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">MM电荷部分与坐标部分之间</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">必须</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">有空行</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">2.</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">MM电荷部分</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">必须</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">以埃为单位</span><span style="color: #bbbbbb"></span> awk<span style="color: #bbbbbb"> </span><span style="color: #BB4444">'</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF">BEGIN</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span>n<span style="color: #666666">=0</span>;<span style="color: #bbbbbb"> </span>Bhr<span style="color: #666666">=0.52917721067</span><span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF">NF</span><span style="color: #666666">==0</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span>n<span style="color: #666666">++</span>;<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">next</span><span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>n<span style="color: #bbbbbb"> </span><span style="color: #666666">></span><span style="color: #bbbbbb"> </span><span style="color: #666666">2</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">printf</span><span style="color: #BB4444">"%4s</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">%16.7f</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">%16.7f</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">%16.7f\n"</span>,<span style="color: #bbbbbb"> </span><span style="border: 1px solid #FF0000">\</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #BB4444">""</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">$1*</span>Bhr,<span style="color: #bbbbbb"> </span><span style="color: #666666">$2*</span>Bhr,<span style="color: #bbbbbb"> </span><span style="color: #666666">$3*</span>Bhr}<span style="color: #bbbbbb"></span> <span style="color: #BB4444">'</span><span style="color: #bbbbbb"> </span>input.com<span style="color: #bbbbbb"> </span><span style="color: #666666">>></span><span style="color: #bbbbbb"> </span>_GMXtmp.gjf<span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">高斯输入文件准备完毕,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">调用高斯进行计算</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">如果运行时还需要其他文件(如态平均系数),</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">可在此处添加</span><span style="color: #bbbbbb"></span> <span style="color: #666666">$</span>GAUSSIAN<span style="color: #bbbbbb"> </span>_GMXtmp.gjf<span style="color: #bbbbbb"> </span>_GMXtmp.out<span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">处理得到的高斯输出文件,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">准备GMX需要的输入文件</span><span style="color: #bbbbbb"></span> awk<span style="color: #bbbbbb"> </span><span style="color: #BB4444">'</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">获取MM电荷值</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #666666">/</span>Point<span style="color: #bbbbbb"> </span>Charges<span style="border: 1px solid #FF0000">:</span><span style="color: #666666">/</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>Nchg<span style="color: #666666">=0</span>;<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">getline</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">while</span>(<span style="color: #666666">$1==</span><span style="color: #BB4444">"XYZ="</span>)<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>Nchg<span style="color: #666666">++</span>;<span style="color: #bbbbbb"> </span>Q[Nchg]<span style="color: #666666">=$6</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">getline</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">获取MM电荷自能,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">SCF能量</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #666666">/</span>Self<span style="color: #bbbbbb"> </span>energy<span style="color: #bbbbbb"> </span>of<span style="color: #bbbbbb"> </span>the<span style="color: #bbbbbb"> </span>charges<span style="color: #666666">/</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"> </span>Eslf<span style="color: #666666">=$7</span><span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #666666">/</span>SCF<span style="color: #bbbbbb"> </span>Done<span style="border: 1px solid #FF0000">:</span><span style="color: #666666">/</span>{<span style="color: #bbbbbb"> </span>Escf<span style="color: #666666">=$5</span><span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">获取每个MM电荷上的电场强度</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #666666">/--------</span><span style="color: #bbbbbb"> </span>Electric<span style="color: #bbbbbb"> </span>Field<span style="color: #bbbbbb"> </span><span style="color: #666666">--------</span><span style="border: 1px solid #FF0000">/</span><span style="color: #bbbbbb"> </span><span style="border: 1px solid #FF0000">{</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">getline</span>;<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">getline</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>Npnt<span style="color: #666666">=0</span>;<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">getline</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">while</span>(<span style="color: #AA22FF">NF</span><span style="color: #666666">>4</span>)<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">if</span>(<span style="color: #666666">$2!=</span><span style="color: #BB4444">"Atom"</span>)<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>Npnt<span style="color: #666666">++</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>Ex[Npnt]<span style="color: #666666">=$3</span>;<span style="color: #bbbbbb"> </span>Ey[Npnt]<span style="color: #666666">=$4</span>;<span style="color: #bbbbbb"> </span>Ez[Npnt]<span style="color: #666666">=$5</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">getline</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">输出需要的能量和梯度</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF">END</span><span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">printf</span><span style="color: #BB4444">"%19.12f\n"</span>,<span style="color: #bbbbbb"> </span>Escf<span style="color: #666666">-</span>Eslf<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">system</span>(<span style="color: #BB4444">"cat</span><span style="color: #bbbbbb"> </span><span style="color: #BB4444">fort.7"</span>)<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">for</span>(i<span style="color: #666666">=1</span>;<span style="color: #bbbbbb"> </span>i<span style="color: #666666"><=</span>Nchg;<span style="color: #bbbbbb"> </span>i<span style="color: #666666">++</span>)<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">printf</span><span style="color: #BB4444">"%20.10e%20.10e%20.10e\n"</span>,<span style="color: #bbbbbb"> </span><span style="border: 1px solid #FF0000">\</span><span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>Q[i]<span style="color: #666666">*</span>Ex[i],<span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>Q[i]<span style="color: #666666">*</span>Ey[i],<span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>Q[i]<span style="color: #666666">*</span>Ez[i]<span style="color: #bbbbbb"></span> <span style="color: #bbbbbb"> </span>}<span style="color: #bbbbbb"></span> <span style="color: #BB4444">'</span><span style="color: #bbbbbb"> </span>_GMXtmp.out<span style="color: #bbbbbb"> </span><span style="color: #666666">></span><span style="color: #bbbbbb"> </span>_GMXtmp.<span style="color: #666666">7</span><span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">高斯使用</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">D</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">而不是</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">E</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">作为科学计数法的标识,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">改过来,</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">否则GMX无法识别</span><span style="color: #bbbbbb"></span> sed<span style="color: #bbbbbb"> </span><span style="color: #BB4444">'</span>s<span style="color: #666666">/</span>D<span style="color: #666666">/</span>E<span style="color: #666666">/</span>g<span style="color: #BB4444">'</span><span style="color: #bbbbbb"> </span>_GMXtmp.<span style="color: #666666">7</span><span style="color: #bbbbbb"> </span><span style="color: #666666">></span><span style="color: #bbbbbb"> </span>fort.<span style="color: #666666">7</span><span style="color: #bbbbbb"></span> </pre></div> </td></tr></table>

将此脚本g09.bsh放于高斯可执行程序所在目录下, 再将环境变量GMX_QM_GAUSS_EXE设为g09.bsh, 然后准备一个高斯关键词文件_Gkwd.gjf, 大致如下

<table class="highlighttable"><th colspan="2" style="text-align:left">_Gkwd.gjf</th><tr><td><div class="linenodiv" style="background-color: #f0f0f0; padding-right: 10px"><pre style="line-height: 125%">1 2 3 4</pre></div></td><td class="code"><div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #666666">%</span>chk<span style="color: #666666">=</span>input<span style="color: #bbbbbb"></span> <span style="color: #666666">%</span>mem<span style="color: #666666">=1</span>GB<span style="color: #bbbbbb"></span> <span style="color: #008800; font-style: italic">#T</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">RHF/STO-3G</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">NoSymm</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">Force</span><span style="color: #bbbbbb"> </span><span style="color: #008800; font-style: italic">Punch=Derivatives</span><span style="color: #bbbbbb"></span> Charge<span style="color: #bbbbbb"> </span>Prop<span style="color: #666666">=</span>(Field,<span style="color: #bbbbbb"> </span>Read)<span style="color: #bbbbbb"></span> </pre></div> </td></tr></table>

这样就可以开始测试运行了.

简单示例

下载相关输入文件

说明 使用QM方法模拟反应时, 很难一次就能跑出一条反应轨迹. 这是正常的. 因为每个反应都有特定的发生几率, 不可能随便发生. 否则相应的反应速率非常大, 与事实不符. 如果你随便一跑就得到一条反应轨迹, 除了偶然之外, 更大的可能是你的设置有问题. 此外, 同样的初始条件(构型, 速度), 使用不同的QM方法进行模拟, 得到的轨迹也大不同. 一种QM方法下的反应轨迹, 换用另一种QM方法很可能就变成非反应轨迹了. 所以, 讨论反应速率的话, 需要对大量的轨迹进行统计, 单单几条轨迹意义不大. 当然, 根据几条反应轨迹说明反应的一些特点和机制, 还是可行的.

技术细节

GROMACS QM/MM模块涉及的源代码位置

各部分的功能文件名称揭示得很清楚.

其他高斯环境变量

实际上GROMACS与高斯联用时, 根据源代码还有其他一些非必要的环境变量

实际上这些设置直接在高斯的输入文件中设置更方便, 使用环境变量反而罗嗦.

GROMACS支持的高斯输出文件格式

GROMACS与高斯联用时, 读取的高斯输出文件为fort.7. 这是一个文本文件, 里面的数据为

  1. 优化后的坐标(非必需, 当工作类型为优化时才需要)
  2. 能量
  3. QM原子上的梯度
  4. MM原子上的梯度

只要此文件满足上面的数据格式, 且数据数量与体系需要的一致, GROMACS就可以读取. 下面是两个水分子的例子, 第一行为体系能量, 下面三行为QM水分子中每个原子上的力, 最后三行为MM水分子中每个原子上的力.

   -74.959189786700
    0.8122428486E-01    0.4936266263E-02    0.2405930866E-01
   -0.6954208610E-01    0.1296978682E-02   -0.7381477271E-02
   -0.1168492817E-01   -0.6264009111E-02   -0.1670717046E-01
    4.5870000000e-05   -3.5862000000e-05   -1.0508400000e-04
   -2.0433000000e-05    3.7947000000e-05    7.2558000000e-05
   -2.2935000000e-05    2.8773000000e-05    6.1716000000e-05

知晓了此文件的格式, 自己写其他量化程序的外挂脚本也就不困难了. 值得注意的是, 计算能量时一般要扣除MM电荷之间的自相互作用能.