layout: post title: VMD渲染相关的几个问题 categories:
编译VMD的过程中顺便总结了一下遇到的几个问题, 供参考.
VMD自带了33种颜色, 可以改变它们的值, 但无法添加新的颜色, 只能修改源码实现. 由于我已经可以从源码编译VMD, 所以就给它新增了200种颜色, 名字从usr-1
到usr-200
, 专门用于自定义颜色, 这样也避免与已有的颜色冲突. 这些颜色的默认值, 我选用了Jmol用于元素, 氨基酸残基, 核酸残基, 二级结构, 链的颜色, 方便使用. 当然也可以将其更改为任意你需要的颜色.
目前常用的元素颜色主要有三种, Jmol, PyMOL, Rasmol及其改进. 在查看有机小分子时, 这些颜色比较常用, 容易识别对应的元素.
使用VMD的tcl脚本更改颜色, 命令类似
<div class="highlight"><pre style="line-height:125%"><span style="color:#A2F">color</span> change rgb "usr-1" 0.800 0.800 0.800</pre></div>"usr-1"
为要更改的颜色名称, 后面三个数字为颜色的rgb值(0-1之间).
下面是几种颜色方案的对比.
VMD自带了几种颜色标尺, 可以修改它们, 但无法自己添加新的标尺, 临时的解决方法也是修改源码, 添加一些自定义标尺. 但好像不能同时使多种颜色标尺?
要更改正在使用的颜色标尺, 可以使用类似下面的tcl脚本. 这个脚本支持matlab的几种颜色映射方案. 如果需要, 可以继续添加其他各种颜色映射方案. 我以前也整理过一些颜色映射方案, 并给出了相应的公式, 可以直接使用.
下面是颜色标尺的测试效果图.
VMD自带了几种材质用于渲染. 每种材质需要定义名称, 环境光强度, 漫反射强度, 高光强度, 高光值, 镜面, 不透明度, 描边, 描边线宽, 透明度这些参数. 其中重要的是前4个参数, 它们决定了渲染后物体的观感. 但这种材质系统比较简单, 自定义性不强, 再加上VMD的灯光颜色只支持白色, 且强度无法调节, 所以要达到好的渲染效果需要费心调, 建议尽量使用VMD自带的几种材质, 需要时在其基础上稍加修改.
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #AA22FF; font-weight: bold">set</span> properties <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">ambient</span> diffuse specular shininess mirror opacity outline outlinewidth transmode<span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">set</span> VMDmaterials <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Opaque</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.650</span> <span style="color: #666666">0.500</span> <span style="color: #666666">0.534</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Transparent</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.650</span> <span style="color: #666666">0.500</span> <span style="color: #666666">0.534</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.300</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">BrushedMetal</span> <span style="color: #666666">0.080</span> <span style="color: #666666">0.390</span> <span style="color: #666666">0.340</span> <span style="color: #666666">0.150</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Diffuse</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.620</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.530</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Ghost</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.230</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.100</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Glass1</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.500</span> <span style="color: #666666">0.650</span> <span style="color: #666666">0.530</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.150</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Glass2</span> <span style="color: #666666">0.520</span> <span style="color: #666666">0.760</span> <span style="color: #666666">0.220</span> <span style="color: #666666">0.590</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.680</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Glass3</span> <span style="color: #666666">0.150</span> <span style="color: #666666">0.250</span> <span style="color: #666666">0.750</span> <span style="color: #666666">0.800</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.500</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Glossy</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.650</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.880</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">HardPlastic</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.560</span> <span style="color: #666666">0.280</span> <span style="color: #666666">0.690</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">MetallicPastel</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.260</span> <span style="color: #666666">0.550</span> <span style="color: #666666">0.190</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Steel</span> <span style="color: #666666">0.250</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.380</span> <span style="color: #666666">0.320</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Translucent</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.700</span> <span style="color: #666666">0.600</span> <span style="color: #666666">0.300</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.800</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Edgy</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.660</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.750</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.620</span> <span style="color: #666666">0.940</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">EdgyShiny</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.660</span> <span style="color: #666666">0.960</span> <span style="color: #666666">0.750</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.760</span> <span style="color: #666666">0.940</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">EdgyGlass</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.660</span> <span style="color: #666666">0.500</span> <span style="color: #666666">0.750</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.620</span> <span style="color: #666666">0.620</span> <span style="color: #666666">0.940</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">Goodsell</span> <span style="color: #666666">0.520</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">4.000</span> <span style="color: #666666">0.900</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">AOShiny</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.850</span> <span style="color: #666666">0.200</span> <span style="color: #666666">0.530</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">AOChalky</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.850</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.530</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">AOEdgy</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.900</span> <span style="color: #666666">0.200</span> <span style="color: #666666">0.530</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.620</span> <span style="color: #666666">0.930</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">BlownGlass</span> <span style="color: #666666">0.040</span> <span style="color: #666666">0.340</span> <span style="color: #666666">1.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.100</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">GlassBubble</span> <span style="color: #666666">0.250</span> <span style="color: #666666">0.340</span> <span style="color: #666666">1.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.040</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">RTChrome</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.650</span> <span style="color: #666666">0.500</span> <span style="color: #666666">0.530</span> <span style="color: #666666">0.700</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">}</span></pre></div>网上有OpenGL常用的几种材质, 但无法直接在VMD中使用, 需要先转换成VMD的格式才可以.
VMD可以自定义材质, 并添加到自带的材质后面, 但同一个分子中只能使用一种材质. 自定义材质使用的tcl脚本类似下面:
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #AA22FF; font-weight: bold">set</span> materials <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">usr-1_default</span> <span style="color: #666666">0.800</span> <span style="color: #666666">0.800</span> <span style="color: #666666">0.800</span> <span style="color: #666666">0.250</span> <span style="color: #666666">0.800</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.200</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">usr-2_solid-Black</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.022</span> <span style="color: #666666">0.100</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">usr-3_solid-Blue</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.072</span> <span style="color: #666666">0.022</span> <span style="color: #666666">0.100</span> <span style="color: #666666">0.000</span> <span style="color: #666666">1.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #666666">0.000</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">foreach</span> ele <span style="color: #B8860B">$materials</span> <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #AA22FF">incr</span> n <span style="color: #B8860B">color</span> change rgb <span style="color: #BB4444">"usr-$n"</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$ele</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$ele</span> <span style="color: #666666">2</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$ele</span> <span style="color: #666666">3</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #AA22FF; font-weight: bold">set</span> mat <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$ele</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #B8860B">material</span> add <span style="color: #B8860B">$mat</span> <span style="color: #B8860B">material</span> change ambient <span style="color: #B8860B">$mat</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$ele</span> <span style="color: #666666">4</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #B8860B">material</span> change diffuse <span style="color: #B8860B">$mat</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$ele</span> <span style="color: #666666">5</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #B8860B">material</span> change specular <span style="color: #B8860B">$mat</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$ele</span> <span style="color: #666666">6</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #B8860B">material</span> change shininess <span style="color: #B8860B">$mat</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #AA22FF">lindex</span> <span style="color: #B8860B">$ele</span> <span style="color: #666666">7</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #AA22FF; font-weight: bold">}</span></pre></div>下面是几个材质示例图.
VMD编译时可以启用Intel的OSPRay渲染器. 这是个纯CPU的渲染器, 效率比VMD自带的tachyon高. 根据我的测试, 耗时只有tachyon的1/5, 场景越复杂, 加速效果越好, 如果可以, 建议尽量使用这个渲染器. 但VMD对这个渲染器的支持并不全面, 无法发挥它的全部功能.
前面的图都是用OSPRay渲染的. 下面是两种渲染器对不同材质渲染效果的对比图. 可以看到OSPRay默认的灯光要暗一些.