Make a fancy snapshot for your work!
TLDR: This post is a collection of softwares (e.g., VMD and Blender) for visualizing your atomic structures. Personally, I use VMD for quick visualization and Blender for making publication-ready figures.
VMD (ver 1.9.4a51)
I am a user of MacOS, and I prefer working with scripts rather than GUI. Therefore, I will show how to work with tcl scripts in VMD, which make the whole process much easier to be repeated.
General references
- Chris MacDermaid: Draw me a picture! and other cool things to do with VMD and LAMMPS
- VMD Cheatsheet
- (Comprehensive official documentation!) Tcl Text Commands
Modify your startup files
The default setup of VMD is far from satisfactory for myself. In addition, there are some specify styles I would like to set up for my own work. Therefore, it will be convenient to modify the startup files of VMD, rather than doing it every time I start VMD.
- find
VMDDIR
- run
puts $::env(VMDDIR)
in vmd command line. This would return the path of VMD. - (Optional: MacOS) set
VMDDIR
as env var:export VMDDIR="/Applications/VMD.app/Contents/vmd"
in~/.bash_profile
(You should be able to do similar things in Linux.)
- run
-
link executable files
# Ubuntu 22.04 export VMDDIR="/home/jxzhu/apps/vmd/1.9.3/lib/vmd" VMDOS="LINUXAMD64" # MacOS # export VMDDIR="/Applications/VMD.app/Contents/vmd" # VMDOS="MACOSXARM64" cd $VMDDIR # soft link remove os suffix ln -sf stride_$VMDOS stride ln -sf surf_$VMDOS surf ln -sf tachyon_$VMDOS tachyon ln -sf vmd_$VMDOS vmd
-
modify default setting
cd $VMDDIR && vi .vmdrc
# ... append what you want to change mol default color Element mol default material Diffuse mol default style {CPK 1.000000 0.000000 10.0 1.0} # set default display display projection Orthographic display depthcue off # set background color to white color Display Background white # modify RGB for default yellow color change rgb yellow 1.000000 0.800200 0.200000 # set default color for elements color Element Pt silver color Element Au yellow color Element Na orange3 color Element K violet2 color Element Cs mauve color Element F cyan3 color Element Cl lime color Element X gray
References
Work with TCL scripts
It will be nice if I can save all commands for visualization in a script and run it in VMD. This is exactly what TCL scripts are for. Let’s see how it works.
If you can call vmd in the command line, for example, in Linux and MacOS, you can run the following command to start VMD:
# if you don't want to have the GUI, especially for remote connection
# use `-dispdev none`
vmd -dispdev none
source plot.tcl
...
# or
vmd -dispdev none -e plot.tcl
# you can aslo have the GUI with `vmd -e plot.tcl`
If you don’t want to use the command line in your OS, you can also run the TCL script in the VMD console: open tk console (see how to find it) & source tcl file.
In principle, you can also run the commands one by one in the tk console.
References
- VMD Command-Line Options
- Scripting in VMD
- (Some commonly-used commands) Visualizing Molecular Structures with VMD
- (Some examples) VMD TCL scripts
Track TCL commands
Sometimes, if you are not sure what the corresponding command of a GUI operation is, you can use the logfile
command to record all the commands you are using in VMD.
# start logging to vmd.log
logfile vmd.log
# stop logging
logfile off
References
Render
You have gotten a good snapshot! How to save it as a high resolution picture?
If you want to use Tachyon renderer in the TCL script, you need to specify the Tachyon executable in your system. You should be able to find the executable file tachyon_*
under $VMDDIR
. For convenience, you can make a soft link from the executable to tachyon
in the same directory, so that you will not need to modify your scripts when using it on different systems. Then, you can use the following command in the TCL script:
# output is $fname.tga
render Tachyon $fname "$VMDDIR/tachyon" -aasamples 12 %s -format TARGA -o %s.tga -res 1920 1920
In the GUI, you can go to File
-> Render
, and choose Tachyon
as the renderer. The default resolution is not high enough for publication. The default command is:
# the Tachyon executable might be different in your system
"/Applications/VMD.app/Contents/vmd/tachyon_MACOSXARM64" -aasamples 12 %s -format TARGA -o %s.tga
You can specify the resolution by appending -res 1600 1200
to the command. The final command should look like this:
"/Applications/VMD.app/Contents/vmd/tachyon_MACOSXARM64" -aasamples 12 %s -format TARGA -o %s.tga -res 1920 1920
References
Load plugins
Sometimes, you might want to load some plugins, such as pbc, by adding the following command in the beginning of the TCL script:
package require pbctools
You can also find guide in the reference about loading the plugin automatically by modifying the .vmdrc
file.
References
Blender (ver 4.4.3)
Compared with VMD, Blender is a more powerful tool for visualization. You can use it to create high-quality figures for publication. While Blender is a free and open-source 3D creation suite for general purposes, it can be used for molecular visualization with the help of the following add-ons:
You can find the first two add-ons in the Blender add-on repository: Edit
-> Preferences
-> Get Extensions
. For the final one, Beautiful Atoms
, you need to install it manually. You can find the installation instructions in the documentation.
For MacOS, it is important to put the application in the path where you have write permission (which is not true for Applications
normally). And only the manual installation works for me:
# check your path
cd /Applications/Blender.app/Contents/Resources/3.4/python/bin
# change the python executable to the one in your path
./python3.10 -m ensurepip
./python3.10 -m pip install --upgrade pip
# I cannot find pip executable in the path, so I use the following commands
# rather than `./pip install`
./python3.10 -m pip install --upgrade ase
./python3.10 -m pip install --upgrade scikit-image
Then install batoms
add-on in Blender as guided in the documentation.
(I still cannot load this add-on in the Blender python console, but I can use it in the Blender GUI. I will update this post if I find a solution.)
Enjoy Reading This Article?
Here are some more articles you might like to read next: