仓库源文站点原文


layout: post title: PyMOL绘制坐标轴以及盒子 categories:


PyMOL官方网站上给了两个绘制坐标轴的脚本, 但无法满足我的需要. 所以我就照葫芦画瓢, 改写了一个根据PDB中的信息绘制坐标轴和盒子的脚本.

PyMOL读取的盒子信息来自PDB文件中的CRYST1行, 类似如下:

<div class="highlight"><pre style="line-height:125%"><span style="color:#A2F">CRYST1</span> 42.844 42.844 128.531 90.00 90.00 90.00 P 1 1</pre></div>

如果你使用gmx editconf -f FILE.gro -o FILE.pdb进行转换, 得到的PDB文件中会自动带有这些信息.

这个脚本只能绘制简单的长方体盒子, 但改成任意的六面体盒子也不困难. 因为我暂时用不到这个功能, 就不再操心了.

绘制出的效果类似下图, 看起来还可以. 这也是我们在最近发表的一篇文章中所用的图.

使用

打开PyMOL, 在命令行中执行 load FILE.pdb; run axes.py.

或者, 将脚本中注释掉的 #cmd.load('FILE.pdb') # 载入PDB 这行取消注释, 直接run axes.py就可以了.

脚本

<table class="highlighttable"><th colspan="2" style="text-align:left">axes.py</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"><pre style="line-height:125%"><span></span><span style="color: #008800; font-style: italic"># coding: utf-8</span> <span style="color: #AA22FF; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pymol.cgo</span> <span style="color: #AA22FF; font-weight: bold">import</span> <span style="color: #666666">*</span> <span style="color: #AA22FF; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pymol</span> <span style="color: #AA22FF; font-weight: bold">import</span> cmd r<span style="color: #666666">=0.5</span> <span style="color: #008800; font-style: italic"># 坐标轴半径</span> h<span style="color: #666666">=5</span> <span style="color: #008800; font-style: italic"># 圆锥高度</span> d<span style="color: #666666">=2*</span>r<span style="color: #666666">*1.618</span> <span style="color: #008800; font-style: italic"># 圆锥底面直径</span> <span style="color: #008800; font-style: italic">#cmd.load('FILE.pdb') # 载入PDB</span> a, b, c <span style="color: #666666">=</span> cmd<span style="color: #666666">.</span>get_symmetry(cmd<span style="color: #666666">.</span>get_object_list()[<span style="color: #666666">0</span>])[<span style="color: #666666">0</span>:<span style="color: #666666">3</span>] cmd<span style="color: #666666">.</span>bg_color(<span style="color: #BB4444">'</span>white<span style="color: #BB4444">'</span>) cmd<span style="color: #666666">.</span>set(<span style="color: #BB4444">'</span>cgo_line_width<span style="color: #BB4444">'</span>, <span style="color: #666666">5</span>) cmd<span style="color: #666666">.</span>delete(<span style="color: #BB4444">'</span>axes<span style="color: #BB4444">'</span>) obj <span style="color: #666666">=</span> [ CYLINDER, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, a<span style="color: #666666">-</span>h, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, r, <span style="color: #666666">1</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, CYLINDER, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, b<span style="color: #666666">-</span>h, <span style="color: #666666">0</span>, r, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">0</span>, CYLINDER, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, c<span style="color: #666666">-</span>h, r, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, CONE, a<span style="color: #666666">-</span>h, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, a, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, d, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">1</span>, CONE, <span style="color: #666666">0</span>, b<span style="color: #666666">-</span>h, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, b, <span style="color: #666666">0</span>, d, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">1</span>, CONE, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, c<span style="color: #666666">-</span>h, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, c, d, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, <span style="color: #666666">1</span>, <span style="color: #666666">1</span>, <span style="color: #666666">1</span>, CYLINDER, a, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, a, b, <span style="color: #666666">0</span>, r<span style="color: #666666">/2</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, CYLINDER, <span style="color: #666666">0</span>, b, <span style="color: #666666">0</span>, a, b, <span style="color: #666666">0</span>, r<span style="color: #666666">/2</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, CYLINDER, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, c, a, <span style="color: #666666">0</span>, c, r<span style="color: #666666">/2</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, CYLINDER, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, c, <span style="color: #666666">0</span>, b, c, r<span style="color: #666666">/2</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, CYLINDER, a, <span style="color: #666666">0</span>, c, a, b, c, r<span style="color: #666666">/2</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, CYLINDER, <span style="color: #666666">0</span>, b, c, a, b, c, r<span style="color: #666666">/2</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, CYLINDER, a, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, a, <span style="color: #666666">0</span>, c, r<span style="color: #666666">/2</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, CYLINDER, <span style="color: #666666">0</span>, b, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>, b, c, r<span style="color: #666666">/2</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, CYLINDER, a, b, <span style="color: #666666">0</span>, a, b, c, r<span style="color: #666666">/2</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span>, <span style="color: #666666">.5</span> ] cmd<span style="color: #666666">.</span>load_cgo(obj, <span style="color: #BB4444">'</span>axes<span style="color: #BB4444">'</span>) cmd<span style="color: #666666">.</span>set(<span style="color: #BB4444">'</span>label_size<span style="color: #BB4444">'</span>, <span style="color: #666666">-5</span>) cmd<span style="color: #666666">.</span>set(<span style="color: #BB4444">'</span>label_font_id<span style="color: #BB4444">'</span>, <span style="color: #666666">7</span>) cmd<span style="color: #666666">.</span>delete(<span style="color: #BB4444">'</span>xtag<span style="color: #BB4444">'</span>) cmd<span style="color: #666666">.</span>delete(<span style="color: #BB4444">'</span>ytag<span style="color: #BB4444">'</span>) cmd<span style="color: #666666">.</span>delete(<span style="color: #BB4444">'</span>ztag<span style="color: #BB4444">'</span>) cmd<span style="color: #666666">.</span>pseudoatom(<span style="color: #BB4444">'</span>xtag<span style="color: #BB4444">'</span>, name<span style="color: #666666">=</span><span style="color: #BB4444">'</span>xtag<span style="color: #BB4444">'</span>, pos<span style="color: #666666">=</span>[a<span style="color: #666666">+5</span>, <span style="color: #666666">0</span>, <span style="color: #666666">0</span>]) cmd<span style="color: #666666">.</span>pseudoatom(<span style="color: #BB4444">'</span>ytag<span style="color: #BB4444">'</span>, name<span style="color: #666666">=</span><span style="color: #BB4444">'</span>ytag<span style="color: #BB4444">'</span>, pos<span style="color: #666666">=</span>[<span style="color: #666666">0</span>, b<span style="color: #666666">+5</span>, <span style="color: #666666">0</span>]) cmd<span style="color: #666666">.</span>pseudoatom(<span style="color: #BB4444">'</span>ztag<span style="color: #BB4444">'</span>, name<span style="color: #666666">=</span><span style="color: #BB4444">'</span>ztag<span style="color: #BB4444">'</span>, pos<span style="color: #666666">=</span>[<span style="color: #666666">0</span>, <span style="color: #666666">0</span>, c<span style="color: #666666">+5</span>]) cmd<span style="color: #666666">.</span>hide(<span style="color: #BB4444">'</span>everything<span style="color: #BB4444">'</span>, <span style="color: #BB4444">'</span>name xtag<span style="color: #BB4444">'</span>) cmd<span style="color: #666666">.</span>hide(<span style="color: #BB4444">'</span>everything<span style="color: #BB4444">'</span>, <span style="color: #BB4444">'</span>name ytag<span style="color: #BB4444">'</span>) cmd<span style="color: #666666">.</span>hide(<span style="color: #BB4444">'</span>everything<span style="color: #BB4444">'</span>, <span style="color: #BB4444">'</span>name ztag<span style="color: #BB4444">'</span>) cmd<span style="color: #666666">.</span>label(<span style="color: #BB4444">'</span>name xtag<span style="color: #BB4444">'</span>, <span style="color: #BB4444">'"X"'</span>) cmd<span style="color: #666666">.</span>label(<span style="color: #BB4444">'</span>name ytag<span style="color: #BB4444">'</span>, <span style="color: #BB4444">'"Y"'</span>) cmd<span style="color: #666666">.</span>label(<span style="color: #BB4444">'</span>name ztag<span style="color: #BB4444">'</span>, <span style="color: #BB4444">'"Z"'</span>)</pre></div> </td></tr></table>