仓库源文站点原文


layout: post title: 统计轨迹中分子速度大小沿某一方向的分布 categories:


写过一个简单的awk脚本, 用来统计轨迹中水分子的质心速度大小沿坐标的变化情况, 目的是可以用来拟合计算粘度. 具体的计算方法可参考:

A Comparison Of The Value Of Viscosity For Several Water Models Using Poiseuille Flow In A Nano-channel

A. P. Markesteijn, Remco Hartkamp, S. Luding, J. Westerweel; J. Chem. Phys. 136(13):134104, 2012; 10.1063/1.3697977

脚本只能处理gro格式的轨迹, 效率不是很高, 但基本能用. 放在这里, 存个档, 也供需要的人参考吧.

<table class="highlighttable"><th colspan="2" style="text-align:left">zvx.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</pre></div></td><td class="code"><div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">awk <span style="color: #BB4444">'</span> BEGIN <span style="color: #666666">{</span> <span style="color: #B8860B">mo</span><span style="color: #666666">=</span>16; <span style="color: #B8860B">mh</span><span style="color: #666666">=</span>1; <span style="color: #B8860B">M</span><span style="color: #666666">=</span>mo+2mh <span style="color: #008800; font-style: italic"># 定义原子质量</span> <span style="color: #B8860B">Ntot</span><span style="color: #666666">=10</span> <span style="color: #008800; font-style: italic"># 定义要计算的帧数</span> <span style="color: #B8860B">Zmin</span><span style="color: #666666">=</span>3; <span style="color: #B8860B">Zmax</span><span style="color: #666666">=</span>26; <span style="color: #B8860B">dZ</span><span style="color: #666666">=</span>0.2 <span style="color: #008800; font-style: italic"># 定义计算区间, 分格间距</span> <span style="color: #B8860B">Nfrm</span><span style="color: #666666">=</span>0; <span style="color: #B8860B">N</span><span style="color: #666666">=</span>int<span style="color: #666666">((</span>Zmax-Zmin<span style="color: #666666">)</span>/dZ<span style="color: #666666">)</span> <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>0; i<<span style="color: #666666">=</span>N; i++<span style="color: #666666">)</span> <span style="color: #666666">{</span> Z<span style="color: #666666">[</span>i<span style="color: #666666">]=</span>Zmin+idZ; Vx<span style="color: #666666">[</span>i<span style="color: #666666">]=</span>0; Nwat<span style="color: #666666">[</span>i<span style="color: #666666">]=0</span> <span style="color: #666666">}</span> <span style="color: #666666">}</span>

<span style="color: #B8860B">NF</span><span style="color: #666666">==1</span> <span style="color: #666666">{</span> Nfrm++ <span style="color: #666666">}</span> NF>6 <span style="color: #666666">&&</span> <span style="color: #B8860B">$2</span>~/OW/ <span style="color: #666666">{</span> <span style="color: #008800; font-style: italic"># 根据 OW 原子统计</span> <span style="color: #B8860B">z</span> <span style="color: #666666">=</span> mo<span style="color: #AA22FF; font-weight: bold">$(</span>NF-3<span style="color: #AA22FF; font-weight: bold">)</span>; <span style="color: #B8860B">vx</span> <span style="color: #666666">=</span> mo<span style="color: #AA22FF; font-weight: bold">$(</span>NF-2<span style="color: #AA22FF; font-weight: bold">)</span> <span style="color: #008800; font-style: italic"># O 的z坐标, x方向速度</span> getline; z +<span style="color: #666666">=</span> mh<span style="color: #AA22FF; font-weight: bold">$(</span>NF-3<span style="color: #AA22FF; font-weight: bold">)</span>; vx +<span style="color: #666666">=</span> mh<span style="color: #AA22FF; font-weight: bold">$(</span>NF-2<span style="color: #AA22FF; font-weight: bold">)</span> <span style="color: #008800; font-style: italic"># H1的</span> getline; z +<span style="color: #666666">=</span> mh<span style="color: #AA22FF; font-weight: bold">$(</span>NF-3<span style="color: #AA22FF; font-weight: bold">)</span>; vx +<span style="color: #666666">=</span> mh<span style="color: #AA22FF; font-weight: bold">$(</span>NF-2<span style="color: #AA22FF; font-weight: bold">)</span> <span style="color: #008800; font-style: italic"># H2的</span>

z /<span style="color: #666666">=</span> M; vx /<span style="color: #666666">=</span> M    <span style="color: #008800; font-style: italic"># 质心坐标和速度</span>
<span style="color: #B8860B">i</span><span style="color: #666666">=</span>int<span style="color: #666666">((</span>z-Zmin<span style="color: #666666">)</span>/dZ<span style="color: #666666">)</span>
Nwat<span style="color: #666666">[</span>i<span style="color: #666666">]</span>++; Vx<span style="color: #666666">[</span>i<span style="color: #666666">]</span> +<span style="color: #666666">=</span> vx
<span style="color: #AA22FF; font-weight: bold">if</span><span style="color: #666666">(</span>Nfrm&gt;Ntot<span style="color: #666666">)</span> <span style="color: #AA22FF">exit</span>

<span style="color: #666666">}</span> END <span style="color: #666666">{</span> print <span style="color: #BB4444">"# Z: ["</span>Zmin<span style="color: #BB4444">":"</span>Zmax<span style="color: #BB4444">":"</span>dZ<span style="color: #BB4444">"] Frames: "</span> Nfrm <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>0; i<<span style="color: #666666">=</span>N; i++<span style="color: #666666">)</span> <span style="color: #AA22FF; font-weight: bold">if</span><span style="color: #666666">(</span>Nwat<span style="color: #666666">[</span>i<span style="color: #666666">]</span>>0<span style="color: #666666">)</span> printf<span style="color: #BB4444">"%f %f\n"</span>, Z<span style="color: #666666">[</span>i<span style="color: #666666">]</span>, Vx<span style="color: #666666">[</span>i<span style="color: #666666">]</span>/Nwat<span style="color: #666666">[</span>i<span style="color: #666666">]</span> <span style="color: #666666">}</span> <span style="color: #BB4444">'</span> File.gro >Z-Vx.xvg </pre></div> </td></tr></table>

评论