技術背景
VMD是分子動力學模擬領域常用的一款可視化軟件,可以非常直觀方便的展示分子的運動過程。而VMD本身對展現的格式有一定的要求,如果不是常見的rst等類型的坐標文件的話,就需要自己手動去實現一個可視化的插件。這里我們介紹的是通過VMD來可視化hdf5格式的坐標文件——hdf5是量子化學領域非常常用的一個數據格式,對於規模較大的數據集有很好的性能支持。
安裝hdf5插件
這里本地使用的是Ubuntu20.04的系統,如果是其他系統,有可能需要針對性的修改下。首先我們將這個hdf5插件的源碼下載到本地:
$ git clone https://github.com/h5md/VMD-h5mdplugin.git
正克隆到 'VMD-h5mdplugin'...
remote: Enumerating objects: 486, done.
remote: Total 486 (delta 0), reused 0 (delta 0), pack-reused 486
接收對象中: 100% (486/486), 1.18 MiB | 2.32 MiB/s, 完成.
處理 delta 中: 100% (302/302), 完成.
$ cd VMD-h5mdplugin/
$ ll
總用量 128
drwxrwxr-x 6 dechin dechin 4096 10月 26 15:58 ./
drwxrwxr-x 8 dechin dechin 4096 10月 26 15:58 ../
drwxrwxr-x 2 dechin dechin 4096 10月 26 15:58 cmake/
-rw-rw-r-- 1 dechin dechin 2133 10月 26 15:58 CMakeLists.txt
-rw-rw-r-- 1 dechin dechin 3190 10月 26 15:58 'Documentation VMD parameters'
drwxrwxr-x 8 dechin dechin 4096 10月 26 15:58 .git/
-rw-rw-r-- 1 dechin dechin 18 10月 26 15:58 .gitignore
-rw-rw-r-- 1 dechin dechin 16210 10月 26 15:58 h5mdplugin.c
-rw-rw-r-- 1 dechin dechin 5000 10月 26 15:58 h5mdtest.c
-rw-rw-r-- 1 dechin dechin 45631 10月 26 15:58 libh5md.c
-rw-rw-r-- 1 dechin dechin 4178 10月 26 15:58 libh5md.h
-rw-rw-r-- 1 dechin dechin 732 10月 26 15:58 LICENSE
-rw-rw-r-- 1 dechin dechin 1300 10月 26 15:58 Makefile
-rw-rw-r-- 1 dechin dechin 2624 10月 26 15:58 README.md
drwxrwxr-x 2 dechin dechin 4096 10月 26 15:58 samples/
drwxrwxr-x 2 dechin dechin 4096 10月 26 15:58 tests/
這里直接clone或者是下載zip壓縮包都是可以的,然后按照官方指示,直接執行make
,我們發現輸出了一個報錯:
$ make
HDF5_CC= h5cc -shlib -Wall -Wuninitialized -std=c99 -pedantic -fPIC -I/usr/local/lib/vmd/plugins/include -c -o h5mdplugin.o h5mdplugin.c
/home/dechin/anaconda3/bin/h5cc: 1: eval: x86_64-conda_cos6-linux-gnu-cc: not found
make: *** [<內置>:h5mdplugin.o] 錯誤 127
經過了解,這個報錯是由於沒有安裝gxx_linux-64
這個庫引起的,因此我們直接使用conda安裝一下這個庫即可:
$ conda install gxx_linux-64
Collecting package metadata (current_repodata.json): done
Solving environment: done
...
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
安裝完成后再次執行編譯:
$ make
HDF5_CC= h5cc -shlib -Wall -Wuninitialized -std=c99 -pedantic -fPIC -I/usr/local/lib/vmd/plugins/include -c -o h5mdplugin.o h5mdplugin.c
HDF5_CC= h5cc -shlib -Wall -Wuninitialized -std=c99 -pedantic -fPIC -I/usr/local/lib/vmd/plugins/include -c -o libh5md.o libh5md.c
libh5md.c: In function 'check_for_pos_dataset':
libh5md.c:94:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
94 | if(pos_dataset_id>=0)
| ^~
libh5md.c:96:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
96 | printf("Position dataset found in group /%s.\n", obj_name);
| ^~~~~~
libh5md.c: In function 'h5md_free_timeindependent_dataset_automatically':
libh5md.c:922:2: warning: enumeration value 'H5T_NO_CLASS' not handled in switch [-Wswitch]
922 | switch (type_class) {
| ^~~~~~
libh5md.c:922:2: warning: enumeration value 'H5T_TIME' not handled in switch [-Wswitch]
libh5md.c:922:2: warning: enumeration value 'H5T_BITFIELD' not handled in switch [-Wswitch]
libh5md.c:922:2: warning: enumeration value 'H5T_OPAQUE' not handled in switch [-Wswitch]
libh5md.c:922:2: warning: enumeration value 'H5T_COMPOUND' not handled in switch [-Wswitch]
libh5md.c:922:2: warning: enumeration value 'H5T_REFERENCE' not handled in switch [-Wswitch]
libh5md.c:922:2: warning: enumeration value 'H5T_ENUM' not handled in switch [-Wswitch]
libh5md.c:922:2: warning: enumeration value 'H5T_VLEN' not handled in switch [-Wswitch]
libh5md.c:922:2: warning: enumeration value 'H5T_ARRAY' not handled in switch [-Wswitch]
libh5md.c:922:2: warning: enumeration value 'H5T_NCLASSES' not handled in switch [-Wswitch]
libh5md.c: In function 'h5md_get_all_infromation_about_property':
libh5md.c:907:22: warning: 'dataset_id' may be used uninitialized in this function [-Wmaybe-uninitialized]
907 | int current_status=H5Dread(dataset_id, wanted_memory_datatype, memspace_id, dataspace_id, H5P_DEFAULT, data_out);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HDF5_CC= h5cc -shlib -Wall -Wuninitialized -std=c99 -pedantic -fPIC -shared -Wl,--no-undefined -L. libh5md.o -o libh5md.so -lm
HDF5_CC= h5cc -shlib -Wall -Wuninitialized -std=c99 -pedantic -fPIC -shared -Wl,--no-undefined -L. h5mdplugin.o -o h5mdplugin.so -Wl,-rpath,'\$ORIGIN' -lh5md
HDF5_CC= h5cc -shlib h5mdtest.c -o h5mdtest h5mdplugin.c -I/usr/local/lib/vmd/plugins/include -Wall -Wuninitialized -std=c99 -pedantic -fPIC -L. -Wl,-rpath,'\$ORIGIN' -lh5md
$ ll
總用量 288
drwxrwxr-x 6 dechin dechin 4096 10月 26 16:24 ./
drwxrwxr-x 8 dechin dechin 4096 10月 26 15:58 ../
drwxrwxr-x 2 dechin dechin 4096 10月 26 15:58 cmake/
-rw-rw-r-- 1 dechin dechin 2133 10月 26 15:58 CMakeLists.txt
-rw-rw-r-- 1 dechin dechin 3190 10月 26 15:58 'Documentation VMD parameters'
drwxrwxr-x 8 dechin dechin 4096 10月 26 15:58 .git/
-rw-rw-r-- 1 dechin dechin 18 10月 26 15:58 .gitignore
-rw-rw-r-- 1 dechin dechin 16210 10月 26 15:58 h5mdplugin.c
-rw-rw-r-- 1 dechin dechin 17536 10月 26 16:24 h5mdplugin.o
-rwxrwxr-x 1 dechin dechin 26456 10月 26 16:24 h5mdplugin.so*
-rwxrwxr-x 1 dechin dechin 31872 10月 26 16:24 h5mdtest*
-rw-rw-r-- 1 dechin dechin 5000 10月 26 15:58 h5mdtest.c
-rw-rw-r-- 1 dechin dechin 6664 10月 26 16:24 h5mdtest.o
-rw-rw-r-- 1 dechin dechin 45631 10月 26 15:58 libh5md.c
-rw-rw-r-- 1 dechin dechin 4178 10月 26 15:58 libh5md.h
-rw-rw-r-- 1 dechin dechin 31152 10月 26 16:24 libh5md.o
-rwxrwxr-x 1 dechin dechin 40808 10月 26 16:24 libh5md.so*
-rw-rw-r-- 1 dechin dechin 732 10月 26 15:58 LICENSE
-rw-rw-r-- 1 dechin dechin 1300 10月 26 15:58 Makefile
-rw-rw-r-- 1 dechin dechin 2624 10月 26 15:58 README.md
drwxrwxr-x 2 dechin dechin 4096 10月 26 15:58 samples/
drwxrwxr-x 2 dechin dechin 4096 10月 26 15:58 tests/
此時我們發現編譯構建成功,並且在當前的目錄下生成了很多的so文件,這些動態鏈接庫就是我們需要使用到的文件。接下來我們需要把這些動態鏈接文件拷貝到vmd的相應目錄下,這個跟安裝的位置有關系,比如博主的vmd是在local賬號下安裝的,vmd相關的庫文件都在/usr/local/lib/vmd/
這個路徑下。總之就是需要在本地電腦上找到vmd下的molfile這個文件夾,然后將剛才生成的so文件都拷貝到這個文件夾下即可:
$ sudo cp *.so /usr/local/lib/vmd/plugins/LINUXAMD64/molfile
拷貝完成后,再次啟動vmd時hdf5的插件就已經被包含在其中,我們可以直接加載hdf5格式的坐標文件。
VMD-hdf5案例測試
在剛才下載下來的VMD-h5mdplugin庫中的samples目錄下,有一些可以用於vmd插件測試和演示的樣例文件,這里我們展示一下基本的讀取過程:
- 在VMD上新建一個分子,並且將一個樣例文件加載到分子信息中:
- 配置展示的模型和模型參數,比如這里使用了球棍模型:
- 查看最終展示效果:
總結概要
VMD是一個分子動力學模擬領域常用的可視化軟件,hdf5是量子化學領域常用的一個二進制文件存儲格式,本文通過介紹VMD-h5mdplugin這個插件的安裝和使用方法,進一步演示了如何在VMD上直接展示hdf5格式文件的分子構象。
版權聲明
本文首發鏈接為:https://www.cnblogs.com/dechinphy/p/vmd-hdf5.html
作者ID:DechinPhy
更多原著文章請參考:https://www.cnblogs.com/dechinphy/
打賞專用鏈接:https://www.cnblogs.com/dechinphy/gallery/image/379634.html