仓库源文站点原文


layout: post title: GROMACS如何做之膜模拟 categories:


运行膜模拟

GROMACS用户在运行双脂质层模拟时往往会遇到各种问题, 尤其是体系中还包含蛋白质的时候. 推荐模拟双脂质层和膜蛋白的用户参考教程KALP-15 in DPPC.

对膜蛋白体系完成一次模拟需要执行下列步骤:

  1. 选择一个能用于蛋白质和脂质分子的力场.
  2. 将蛋白质插入到膜结构中. (例如, 在预备好的双分子层上使用g_membed命令, 或进行一个粗粒化自组装模拟然后再转换回全原子表示)
  3. 向体系中加入溶剂. 并加入离子中和多余的电荷, 确保整个体系最终呈电中性, 同时调整最终的离子浓度
  4. 运行能量最小化.
  5. 让膜适应蛋白质. 典型的方法是, 在限制蛋白质所有重原子的情况下(力常数可取1000 kJ/mol-nm<sup>2</sup>)运行约5~10 ns的MD.
  6. 去掉限制进行平衡.
  7. 运行成品MD.

使用genbox命令添加水

当使用genbox命令(5.0以后版本中为gmx solvate)向预备好的双层膜体系中添加水时, 水分子往往会进入到膜的夹层中, 去除这些水分子的解决办法有以下几种:

删除膜内部的水分子

awk脚本

此脚本可自动计算保留的水分子个数, 更新总原子数目.

<table class="highlighttable"><th colspan="2" style="text-align:left">rmWat.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</pre></div></td><td class="code"><div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #B8860B">usage</span><span style="color: #666666">=</span><span style="color: #BB4444">"\</span> <span style="color: #BB4444">>>>>>>>>>>>>>>>> rmWat <<<<<<<<<<<<<<<<</span> <span style="color: #BB4444">>>>>>>>>>>>>>>>> Jicun LI <<<<<<<<<<<<<<<<</span> <span style="color: #BB4444">>>>>>>>>>> 2016-09-19 11:24:51 <<<<<<<<<</span> <span style="color: #BB4444">>> Usage: rmWat <File.gro> {Zmin} {Zmax} {Nsit} {Ncol}</span> <span style="color: #BB4444">>> Default: rmWat N/A 2 6 3 0</span> <span style="color: #BB4444">>> Zmin: 水分子中原子z坐标的最小值</span> <span style="color: #BB4444">>> Zmax: 水分子中原子z坐标的最大值, 删除 Zmin<z<Zmax 的水分子原子</span> <span style="color: #BB4444">>> Nsit: 水模型的位点数; 3/4/5</span> <span style="color: #BB4444">>> Ncol: gro文件中的速度列数, 不含速度为0, 含速度为3"</span>

<span style="color: #666666">[[</span> <span style="color: #B8860B">$#</span> -lt <span style="color: #666666">1</span> <span style="color: #666666">]]</span> <span style="color: #666666">&&</span> <span style="color: #666666">{</span> <span style="color: #AA22FF">echo</span> <span style="color: #BB4444">"</span>$<span style="color: #BB4444">usage"</span>; exit; <span style="color: #666666">}</span>

<span style="color: #B8860B">File</span><span style="color: #666666">=</span><span style="color: #B8860B">$1</span> <span style="color: #B8860B">Zmin</span><span style="color: #666666">=</span>2; <span style="color: #666666">[[</span> <span style="color: #B8860B">$#</span> -ge <span style="color: #666666">2</span> <span style="color: #666666">]]</span> <span style="color: #666666">&&</span> <span style="color: #666666">{</span> <span style="color: #B8860B">Zmin</span><span style="color: #666666">=</span><span style="color: #B8860B">$2</span>; <span style="color: #666666">}</span> <span style="color: #B8860B">Zmax</span><span style="color: #666666">=</span>6; <span style="color: #666666">[[</span> <span style="color: #B8860B">$#</span> -ge <span style="color: #666666">3</span> <span style="color: #666666">]]</span> <span style="color: #666666">&&</span> <span style="color: #666666">{</span> <span style="color: #B8860B">Zmax</span><span style="color: #666666">=</span><span style="color: #B8860B">$3</span>; <span style="color: #666666">}</span> <span style="color: #B8860B">Nsit</span><span style="color: #666666">=</span>3; <span style="color: #666666">[[</span> <span style="color: #B8860B">$#</span> -ge <span style="color: #666666">4</span> <span style="color: #666666">]]</span> <span style="color: #666666">&&</span> <span style="color: #666666">{</span> <span style="color: #B8860B">Nsit</span><span style="color: #666666">=</span><span style="color: #B8860B">$4</span>; <span style="color: #666666">}</span> <span style="color: #B8860B">Ncol</span><span style="color: #666666">=0</span> <span style="color: #666666">[[</span> <span style="color: #B8860B">$#</span> -ge <span style="color: #666666">5</span> <span style="color: #666666">]]</span> <span style="color: #666666">&&</span> <span style="color: #666666">{</span> <span style="color: #B8860B">Ncol</span><span style="color: #666666">=</span><span style="color: #B8860B">$5</span>; <span style="color: #666666">}</span>

<span style="color: #B8860B">Fout</span><span style="color: #666666">=</span><span style="color: #BB6688; font-weight: bold">${</span><span style="color: #B8860B">File</span>%.gro<span style="color: #BB6688; font-weight: bold">}</span>~rmWat.gro

<span style="color: #008800; font-style: italic"># 获取脂质分子的原子数目, 输出其坐标</span> <span style="color: #B8860B">Natm</span><span style="color: #666666">=</span><span style="color: #AA22FF; font-weight: bold">$(</span>awk <span style="color: #BB4444">'</span> BEGIN<span style="color: #666666">{</span><span style="color: #B8860B">Natm</span><span style="color: #666666">=</span>0<span style="color: #666666">}</span> <span style="color: #B8860B">$1</span>!~/SOL/ <span style="color: #666666">&&</span> NF>4 <span style="color: #666666">{</span> Natm++; print ><span style="color: #BB4444">"_Lip.gro"</span>; next <span style="color: #666666">}</span> END <span style="color: #666666">{</span> print Natm<span style="color: #666666">}</span> <span style="color: #BB4444">'</span> <span style="color: #B8860B">$F</span>ile<span style="color: #AA22FF; font-weight: bold">)</span>

<span style="color: #008800; font-style: italic"># 获取删除水后的总原子数, 输出水的坐标</span> <span style="color: #B8860B">Ntot</span><span style="color: #666666">=</span><span style="color: #AA22FF; font-weight: bold">$(</span>awk -v <span style="color: #B8860B">Ntot</span><span style="color: #666666">=</span>$Natm -v <span style="color: #B8860B">Zmin</span><span style="color: #666666">=</span>$Zmin -v <span style="color: #B8860B">Zmax</span><span style="color: #666666">=</span>$Zmax <span style="color: #BB6622; font-weight: bold">\</span> -v <span style="color: #B8860B">Nsit</span><span style="color: #666666">=</span>$Nsit -v <span style="color: #B8860B">Ncol</span><span style="color: #666666">=</span>$Ncol <span style="color: #BB4444">'</span> <span style="color: #B8860B">$1</span>~/SOL/ <span style="color: #666666">{</span> Atom<span style="color: #666666">[</span>1<span style="color: #666666">]=</span><span style="color: #B8860B">$0</span> <span style="color: #B8860B">YesInc</span><span style="color: #666666">=</span>0 <span style="color: #AA22FF; font-weight: bold">if</span><span style="color: #666666">(</span><span style="color: #AA22FF; font-weight: bold">$(</span>NF-Ncol<span style="color: #AA22FF; font-weight: bold">)</span><Zmin <span style="color: #666666">||</span> <span style="color: #AA22FF; font-weight: bold">$(</span>NF-Ncol<span style="color: #AA22FF; font-weight: bold">)</span>>Zmax<span style="color: #AA22FF; font-weight: bold">)</span> <span style="color: #B8860B">YesInc</span><span style="color: #666666">=</span>1 <span style="color: #AA22FF; font-weight: bold">for</span><span style="color: #666666">(</span><span style="color: #B8860B">i</span><span style="color: #666666">=</span>2; i<<span style="color: #666666">=</span>Nsit; i++<span style="color: #666666">)</span> <span style="color: #666666">{</span> getline; Atom<span style="color: #666666">[</span>i<span style="color: #666666">]=</span><span style="color: #B8860B">$0</span> <span style="color: #AA22FF; font-weight: bold">if</span><span style="color: #666666">(</span><span style="color: #AA22FF; font-weight: bold">$(</span>NF-Ncol<span style="color: #AA22FF; font-weight: bold">)</span><Zmin <span style="color: #666666">||</span> <span style="color: #AA22FF; font-weight: bold">$(</span>NF-Ncol<span style="color: #AA22FF; font-weight: bold">)</span>>Zmax<span style="color: #666666">)</span> <span style="color: #B8860B">YesInc</span><span style="color: #666666">=</span>1 <span style="color: #666666">}</span> <span style="color: #AA22FF; font-weight: bold">if</span><span style="color: #666666">(</span>YesInc<span style="color: #666666">)</span> <span style="color: #666666">{</span> Ntot +<span style="color: #666666">=</span> Nsit <span style="color: #AA22FF; font-weight: bold">for</span><span style="color: #666666">(</span><span style="color: #B8860B">i</span><span style="color: #666666">=</span>1; i<<span style="color: #666666">=</span>Nsit; i++<span style="color: #666666">)</span> print Atom<span style="color: #666666">[</span>i<span style="color: #666666">]</span> ><span style="color: #BB4444">"_Wat.gro"</span> <span style="color: #666666">}</span> <span style="color: #666666">}</span> END<span style="color: #666666">{</span>print Ntot<span style="color: #666666">}</span> <span style="color: #BB4444">'</span> <span style="color: #B8860B">$F</span>ile<span style="color: #666666">)</span>

<span style="color: #008800; font-style: italic"># 组合文件</span> head -n <span style="color: #666666">1</span> <span style="color: #B8860B">$F</span>ile > <span style="color: #B8860B">$F</span>out <span style="color: #AA22FF">echo</span> $Ntot >><span style="color: #B8860B">$F</span>out cat _Lip.gro _Wat.gro >><span style="color: #B8860B">$F</span>out tail -n <span style="color: #666666">1</span> <span style="color: #B8860B">$F</span>ile >><span style="color: #B8860B">$F</span>out

<span style="color: #008800; font-style: italic"># 使用gmx工具重新设定分子, 原子编号</span> gmx editconf -f <span style="color: #B8860B">$F</span>out -o <span style="color: #B8860B">$F</span>out

<span style="color: #008800; font-style: italic"># 删除临时文件</span> rm -rf _Lip.gro _Wat.gro

<span style="color: #AA22FF">echo</span> <span style="color: #BB4444">'</span>保留水分子数目: <span style="color: #BB4444">'</span> $<span style="color: #666666">[(</span>$Ntot-$Natm<span style="color: #666666">)</span>/$Nsit<span style="color: #666666">]</span> </pre></div> </td></tr></table>

tcl脚本

此脚本在VMD中使用, 自动计算所需的z坐标极值.

<table class="highlighttable"><th colspan="2" style="text-align:left">rmwat.tcl</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</pre></div></td><td class="code"><div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008800; font-style: italic">#remove water molecular near lipids within refered distance</span> <span style="color: #AA22FF; font-weight: bold">proc</span> rmwat <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">lipres</span> dz<span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #AA22FF; font-weight: bold">set</span> lip <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">atomselect</span> top <span style="color: #BB4444">"resname $lipres"</span><span style="color: #AA22FF; font-weight: bold">];</span> <span style="color: #AA22FF; font-weight: bold">set</span> lipbox <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">measure</span> minmax <span style="color: #B8860B">$lip</span><span style="color: #AA22FF; font-weight: bold">];</span> <span style="color: #AA22FF; font-weight: bold">set</span> xmin <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$lipbox</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">];</span> <span style="color: #AA22FF; font-weight: bold">set</span> xmax <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$lipbox</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">];</span> <span style="color: #AA22FF; font-weight: bold">set</span> ymin <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$lipbox</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">];</span> <span style="color: #AA22FF; font-weight: bold">set</span> ymax <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$lipbox</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">];</span> <span style="color: #AA22FF; font-weight: bold">set</span> zmin <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$lipbox</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #666666">2</span><span style="color: #AA22FF; font-weight: bold">];</span> <span style="color: #AA22FF; font-weight: bold">set</span> zmax <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$lipbox</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #666666">2</span><span style="color: #AA22FF; font-weight: bold">];</span> <span style="color: #AA22FF; font-weight: bold">set</span> zmin <span style="color: #AA22FF; font-weight: bold">[expr</span> <span style="color: #B8860B">$zmin</span><span style="color: #666666">+</span><span style="color: #B8860B">$dz</span><span style="color: #AA22FF; font-weight: bold">];</span> <span style="color: #AA22FF; font-weight: bold">set</span> zmax <span style="color: #AA22FF; font-weight: bold">[expr</span> <span style="color: #B8860B">$zmax-$dz</span><span style="color: #AA22FF; font-weight: bold">];</span> <span style="color: #AA22FF; font-weight: bold">set</span> selA <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">atomselect</span> top <span style="color: #BB4444">"same residue as water and z>$zmin and z<$zmax"</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #AA22FF; font-weight: bold">set</span> selB <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">atomselect</span> top <span style="color: #BB4444">"all not {same residue as water and z>$zmin and z<$zmax}"</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #AA22FF">puts</span> <span style="color: #BB4444">"all not {same residue as water and z>$zmin and z<$zmax}"</span> <span style="color: #AA22FF; font-weight: bold">set</span> rmwatlen <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">llength</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">$selA</span> <span style="color: #B8860B">get</span> resid<span style="color: #AA22FF; font-weight: bold">]];</span> <span style="color: #AA22FF; font-weight: bold">set</span> rmwatnum <span style="color: #AA22FF; font-weight: bold">[expr</span> <span style="color: #B8860B">$rmwatlen</span><span style="color: #666666">/3</span><span style="color: #AA22FF; font-weight: bold">];</span>

<span style="color: #AA22FF">puts</span> <span style="color: #BB4444">&quot;remove water atom is $rmwatlen, and molecular is $rmwatnum&quot;</span>
<span style="color: #B8860B">$selB</span> <span style="color: #B8860B">writepdb</span> rmWat.pdb

<span style="color: #AA22FF; font-weight: bold">set</span> all <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">atomselect</span> top water<span style="color: #AA22FF; font-weight: bold">]</span>
<span style="color: #AA22FF; font-weight: bold">set</span> allwat <span style="color: #AA22FF; font-weight: bold">[expr</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">llength</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">$all</span> <span style="color: #B8860B">get</span> resid<span style="color: #AA22FF; font-weight: bold">]]</span><span style="color: #666666">/3</span><span style="color: #AA22FF; font-weight: bold">];</span>

<span style="color: #AA22FF; font-weight: bold">set</span> rmwatnum <span style="color: #AA22FF; font-weight: bold">[expr</span> <span style="color: #B8860B">$allwat-$rmwatnum</span><span style="color: #AA22FF; font-weight: bold">];</span>
<span style="color: #AA22FF">puts</span> <span style="color: #BB4444">&quot;Original water molecules number is $allwat&quot;</span>
<span style="color: #AA22FF">puts</span> <span style="color: #BB4444">&quot;Water molecules left $rmwatnum&quot;</span><span style="color: #AA22FF; font-weight: bold">;</span>

<span style="color: #AA22FF; font-weight: bold">}</span> </pre></div> </td></tr></table>

增大水相z方向的尺寸(此shell脚本效率较低, 只有存档意义, 不建议使用)

假定双层膜体系垂直于z轴延展, 其法向沿z轴, Chirs Neale提供了一个方法用以去除不需要的水分子. 具体操作如下(如果需要, 可以修改第41行使脚本适用于x/y/z方向延展的体系):

  1. 对初始双层膜构型initial.gro运行genbox命令, 得到solvated.gro;
  2. cp solvate.gro new_waters.gro;
  3. 使用文本编辑器删除new_waters.gro中除第一步新添加的水之外的内容(若初始构型initial.gro中含有水分子, 这些水分子也要删去). 在vim中删除多行可以用指令ndd, n为行数;
  4. 修改脚本keepbyz.sh中的upperzlowerz参数为需要的值, 并将sol参数改为溶剂分子的名称(upperzlowerz分别为双层膜上下边界的z轴坐标, 注意脂质分子的头基周围需要保留一定数目的水分子, 所以请选择合适的值. sol对应溶剂分子的名称, 默认为SOL)
  5. 执行chmod +x keepbyz.sh确保脚本可执行, 然后运行./keepbyz.sh new_waters.gro > keep_these_waters.gro;
  6. 运行tail -1 initial.gro > last_line.gro获取盒子信息;
  7. head -$(expr $(cat initial.gro | wc -l | awk '{print $1}') - 1 ) initial.gro > not_last_line.gro;
  8. cat not_last_line.gro keep_these_waters.gro last_line.gro > new_system.gro; 手动修改new_system.gro中的原子数目, 使其与体系的总原子数目相等;
  9. editconf -f new_system.gro -o new_system_sequential_numbers.gro; (5.0以后版本中使用gmx editconf); 修改拓扑文件, 确保与gro中的分子数一致.

keepbyz.sh脚本内容如下:

<table class="highlighttable"><th colspan="2" style="text-align:left">keepbyz.sh</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</pre></div></td><td class="code"><div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008800; font-style: italic">#!/bin/bash</span> <span style="color: #008800; font-style: italic"># give x.gro as first command line arguement</span> <span style="color: #B8860B">upperz</span><span style="color: #666666">=</span>6.417 <span style="color: #B8860B">lowerz</span><span style="color: #666666">=</span>0.820 <span style="color: #B8860B">sol</span><span style="color: #666666">=</span>SOL <span style="color: #B8860B">count</span><span style="color: #666666">=</span>0 cat <span style="color: #B8860B">$1</span> | grep <span style="color: #BB4444">"</span>$<span style="color: #BB4444">sol"</span> | <span style="color: #AA22FF; font-weight: bold">while</span> <span style="color: #AA22FF">read</span> line; <span style="color: #AA22FF; font-weight: bold">do</span> <span style="color: #AA22FF; font-weight: bold">for</span> first in $line; <span style="color: #AA22FF; font-weight: bold">do</span> <span style="color: #AA22FF">break</span> <span style="color: #AA22FF; font-weight: bold">done</span> <span style="color: #AA22FF; font-weight: bold">if</span> <span style="color: #666666">[</span> <span style="color: #BB4444">"</span><span style="color: #B8860B">$c</span><span style="color: #BB4444">ount"</span> <span style="color: #666666">=</span> <span style="color: #666666">3</span> <span style="color: #666666">]</span>; <span style="color: #AA22FF; font-weight: bold">then</span> <span style="color: #B8860B">count</span><span style="color: #666666">=</span>0 <span style="color: #AA22FF; font-weight: bold">fi</span> <span style="color: #B8860B">count</span><span style="color: #666666">=</span><span style="color: #AA22FF; font-weight: bold">$(</span>expr <span style="color: #B8860B">$c</span>ount + 1<span style="color: #AA22FF; font-weight: bold">)</span> <span style="color: #AA22FF; font-weight: bold">if</span> <span style="color: #666666">[</span> <span style="color: #BB4444">"</span><span style="color: #B8860B">$c</span><span style="color: #BB4444">ount"</span> !<span style="color: #666666">=</span> <span style="color: #666666">1</span> <span style="color: #666666">]</span>; <span style="color: #AA22FF; font-weight: bold">then</span> <span style="color: #AA22FF; font-weight: bold">continue</span> <span style="color: #AA22FF; font-weight: bold">fi</span> <span style="color: #B8860B">l</span><span style="color: #666666">=</span><span style="color: #BB6688; font-weight: bold">${#</span><span style="color: #B8860B">line</span><span style="color: #BB6688; font-weight: bold">}</span> <span style="color: #B8860B">m</span><span style="color: #666666">=</span><span style="color: #AA22FF; font-weight: bold">$(</span>expr $l - 24<span style="color: #AA22FF; font-weight: bold">)</span> <span style="color: #008800; font-style: italic"># would use -48 if velocities are also in .gro and -24 otherwise. 如果gro文件中包含速度信息, 使用48</span> <span style="color: #B8860B">i</span><span style="color: #666666">=</span>1 <span style="color: #AA22FF; font-weight: bold">for</span> word in <span style="color: #BB6688; font-weight: bold">${</span><span style="color: #B8860B">line</span>:$<span style="color: #B8860B">m</span><span style="color: #BB6688; font-weight: bold">}</span>; <span style="color: #AA22FF; font-weight: bold">do</span> <span style="color: #AA22FF; font-weight: bold">if</span> <span style="color: #666666">[</span> <span style="color: #BB4444">"</span>$<span style="color: #BB4444">i"</span> <span style="color: #666666">=</span> <span style="color: #666666">1</span> <span style="color: #666666">]</span>; <span style="color: #AA22FF; font-weight: bold">then</span> <span style="color: #B8860B">popex</span><span style="color: #666666">=</span>$word <span style="color: #AA22FF; font-weight: bold">else</span> <span style="color: #AA22FF; font-weight: bold">if</span> <span style="color: #666666">[</span> <span style="color: #BB4444">"</span>$<span style="color: #BB4444">i"</span> <span style="color: #666666">=</span> <span style="color: #666666">2</span> <span style="color: #666666">]</span>; <span style="color: #AA22FF; font-weight: bold">then</span> <span style="color: #B8860B">popey</span><span style="color: #666666">=</span>$word <span style="color: #AA22FF; font-weight: bold">else</span> <span style="color: #AA22FF; font-weight: bold">if</span> <span style="color: #666666">[</span> <span style="color: #BB4444">"</span>$<span style="color: #BB4444">i"</span> <span style="color: #666666">=</span> <span style="color: #666666">3</span> <span style="color: #666666">]</span>; <span style="color: #AA22FF; font-weight: bold">then</span> <span style="color: #B8860B">popez</span><span style="color: #666666">=</span>$word <span style="color: #AA22FF">break</span> <span style="color: #AA22FF; font-weight: bold">fi</span> <span style="color: #AA22FF; font-weight: bold">fi</span> <span style="color: #AA22FF; font-weight: bold">fi</span> <span style="color: #B8860B">i</span><span style="color: #666666">=</span><span style="color: #AA22FF; font-weight: bold">$(</span>expr $i + 1<span style="color: #AA22FF; font-weight: bold">)</span> <span style="color: #AA22FF; font-weight: bold">done</span> <span style="color: #B8860B">nolx</span><span style="color: #666666">=</span><span style="color: #BB4444">`</span><span style="color: #AA22FF">echo</span> <span style="color: #BB4444">"</span>$<span style="color: #BB4444">popez > </span>$<span style="color: #BB4444">upperz"</span> | bc<span style="color: #BB4444">`</span> <span style="color: #B8860B">nohx</span><span style="color: #666666">=</span><span style="color: #BB4444">`</span><span style="color: #AA22FF">echo</span> <span style="color: #BB4444">"</span>$<span style="color: #BB4444">popez < </span>$<span style="color: #BB4444">lowerz"</span> | bc<span style="color: #BB4444">`</span> <span style="color: #B8860B">myno</span><span style="color: #666666">=</span><span style="color: #AA22FF; font-weight: bold">$(</span>expr $nolx + $nohx<span style="color: #AA22FF; font-weight: bold">)</span> <span style="color: #AA22FF; font-weight: bold">if</span> <span style="color: #666666">[</span> <span style="color: #BB4444">"</span>$<span style="color: #BB4444">myno"</span> !<span style="color: #666666">=</span> <span style="color: #666666">0</span> <span style="color: #666666">]</span>; <span style="color: #AA22FF; font-weight: bold">then</span> <span style="color: #B8860B">z</span><span style="color: #666666">=</span><span style="color: #BB6688; font-weight: bold">${#</span><span style="color: #B8860B">first</span><span style="color: #BB6688; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">if</span> <span style="color: #666666">[</span> <span style="color: #BB4444">"</span>$<span style="color: #BB4444">z"</span> !<span style="color: #666666">=</span> <span style="color: #666666">8</span> <span style="color: #666666">]</span>; <span style="color: #AA22FF; font-weight: bold">then</span> <span style="color: #B8860B">sfirst</span><span style="color: #666666">=</span><span style="color: #BB4444">"[[:space:]]</span><span style="color: #B8860B">$f</span><span style="color: #BB4444">irst"</span> <span style="color: #AA22FF; font-weight: bold">else</span> <span style="color: #B8860B">sfirst</span><span style="color: #666666">=</span><span style="color: #B8860B">$f</span>irst <span style="color: #AA22FF; font-weight: bold">fi</span> <span style="color: #BB4444">`</span><span style="color: #AA22FF">echo</span> grep $sfirst <span style="color: #B8860B">$1</span><span style="color: #BB4444">`</span> <span style="color: #AA22FF; font-weight: bold">fi</span> <span style="color: #AA22FF; font-weight: bold">done</span> </pre></div> </td></tr></table> 脚本中默认使用3位点的水分子模型, 若使用TIP4P水模型, 则应将

if [ "$count" = 3 ]; then
    count=0
fi

修改为:

if [ "$count" = 4 ]; then
    count=0
fi

同理, 使用TIP5P水模型时应修改为5.

为提高效率, 该脚本的作者还提供了一个同样功能的C程序. 所用水模型的位点数通过命令行参数指定, 但你仍然需要修改接近底部的源代码, 指定自己的选择标准, 并使用-24-48来指定你的gro文件是否包含速度.

<table class="highlighttable"><th colspan="2" style="text-align:left">keepbyz.c</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</pre></div></td><td class="code"><div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008800">#include</span> <span style="color: #008800; font-style: italic"><stdio.h></span><span style="color: #008800"></span> <span style="color: #008800">#include</span> <span style="color: #008800; font-style: italic"><stdlib.h></span><span style="color: #008800"></span> <span style="color: #008800">#include</span> <span style="color: #008800; font-style: italic">"string.h"</span><span style="color: #008800"></span>

<span style="color: #008800">#define LINE_SIZE 1000</span>

<span style="color: #00BB00; font-weight: bold">void</span> <span style="color: #00A000">showUsage</span>(<span style="color: #AA22FF; font-weight: bold">const</span> <span style="color: #00BB00; font-weight: bold">char</span> <span style="color: #666666">*</span>c){ printf(<span style="color: #BB4444">"Usage: %s <solvent.gro> <numAtomsInWaterMolecule></span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BB4444">"</span>,c); printf(<span style="color: #BB4444">" (e.g. 3 for TIP3P, 4 for TIP4P)</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BB4444">"</span>); }

<span style="color: #00BB00; font-weight: bold">int</span> <span style="color: #00A000">main</span>(<span style="color: #00BB00; font-weight: bold">int</span> argn, <span style="color: #00BB00; font-weight: bold">char</span> <span style="color: #666666">*</span>args[]){ <span style="color: #00BB00; font-weight: bold">FILE</span> <span style="color: #666666">*</span>mf; <span style="color: #00BB00; font-weight: bold">char</span> <span style="color: #666666">*</span>c; <span style="color: #00BB00; font-weight: bold">char</span> linein[LINE_SIZE]; <span style="color: #00BB00; font-weight: bold">float</span> mx,my,mz; <span style="color: #00BB00; font-weight: bold">int</span> count,keep; <span style="color: #00BB00; font-weight: bold">int</span> atomInWater;

<span style="color: #AA22FF; font-weight: bold">if</span>(argn<span style="color: #666666">!=3</span>){
    showUsage(args[<span style="color: #666666">0</span>]);
    exit(<span style="color: #666666">1</span>);
}
<span style="color: #AA22FF; font-weight: bold">if</span>(sscanf(args[<span style="color: #666666">2</span>],<span style="color: #BB4444">&quot;%d&quot;</span>,<span style="color: #666666">&amp;</span>atomInWater)<span style="color: #666666">!=1</span>){
    printf(<span style="color: #BB4444">&quot;error: unable to determine number of atoms in the water model</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BB4444">&quot;</span>);
    showUsage(args[<span style="color: #666666">0</span>]);
    exit(<span style="color: #666666">1</span>);
}

mf<span style="color: #666666">=</span>fopen(args[<span style="color: #666666">1</span>],<span style="color: #BB4444">&quot;r&quot;</span>);
<span style="color: #AA22FF; font-weight: bold">if</span>(mf<span style="color: #666666">==</span><span style="color: #AA22FF">NULL</span>){
    printf(<span style="color: #BB4444">&quot;error: unable to open the membrane file %s</span><span style="color: #BB6622; font-weight: bold">\n</span><span style="color: #BB4444">&quot;</span>,args[<span style="color: #666666">1</span>]);
    exit(<span style="color: #666666">1</span>);
}

count<span style="color: #666666">=0</span>;
keep<span style="color: #666666">=0</span>;
<span style="color: #AA22FF; font-weight: bold">while</span>(fgets(linein,LINE_SIZE,mf)<span style="color: #666666">!=</span><span style="color: #AA22FF">NULL</span>){
    <span style="color: #AA22FF; font-weight: bold">if</span>(count<span style="color: #666666">==</span>atomInWater){
        count<span style="color: #666666">=0</span>;
        keep<span style="color: #666666">=0</span>;
    }
    count<span style="color: #666666">++</span>;
    c<span style="color: #666666">=&amp;</span>linein[strlen(linein)<span style="color: #666666">-24</span>];           <span style="color: #008800; font-style: italic">// would use -48 if velocities are also in .gro and -24 otherwise</span>
    <span style="color: #AA22FF; font-weight: bold">if</span>(sscanf(c,<span style="color: #BB4444">&quot;%f %f %f&quot;</span>,<span style="color: #666666">&amp;</span>mx,<span style="color: #666666">&amp;</span>my,<span style="color: #666666">&amp;</span>mz)<span style="color: #666666">!=3</span>) <span style="color: #AA22FF; font-weight: bold">continue</span>;
    <span style="color: #AA22FF; font-weight: bold">if</span>(count<span style="color: #666666">==1</span>){
        <span style="color: #008800; font-style: italic">//Add your selection terms here to set keep=1 when you want to keep that particular solvent</span>
        <span style="color: #AA22FF; font-weight: bold">if</span>(mz<span style="color: #666666">&lt;7.0</span>){
            keep<span style="color: #666666">=1</span>;
        }
    }
    <span style="color: #AA22FF; font-weight: bold">if</span>(keep)printf(<span style="color: #BB4444">&quot;%s&quot;</span>,linein);
}
fclose(mf);

} </pre></div> </td></tr></table>

外部链接

评论