Command line rendering of chemical structures in Blender
go back to Main Page, Group Pages, Núria López and Group, Scripts_for_VASP
in preparation, absolute beginner friendly: Here is a procedure on how to take a CONTCAR and convert it to high quality PNG image.
Installing Blender
- Blender is installed by downloading the code (https://www.blender.org/download/) unpacking it to a path of your choosing.
- In the program folder you will find an executable called blender
example: /usr/bin/blender-2.80-linux-glibc217-x86_64
- To launch blender you will execute (if you use the path from previous line)
/usr/bin/blender-2.80-linux-glibc217-x86_64/blender
- you do not need to launch blender at this point
Preparing the structure
I am assuming that you are more or less familiar with the use of vtst-scripts (http://theory.cm.utexas.edu/vtsttools/scripts.html), openbabel (http://openbabel.org/wiki/Main_Page) or just check out Scripts for VASP
- Let's start from the same spot, do this:
$ mkdir ~/blender_test $ cd ~/blender_test
move the CONTCAR you want to render to ~/blender_test
$ ls CONTCAR
- Let's use a HCl molecule as our subject:
$ cat CONTCAR HCl 1.0 10.0000000000 10.0000000000 10.0000000000 10.0000000000 10.0000000000 10.0000000000 10.0000000000 10.0000000000 10.0000000000 H Cl 1 1 Selective Cartesian +0.1000000000 +1.0000000000 +0.1000000000 T T T +1.0000000000 +0.1000000000 +0.1000000000 T T T
- if you do use openbabel:
$babel CONTCAR hcl.pdb $cat hcl.pdb COMPND HCl AUTHOR GENERATED BY OPEN BABEL 2.4.1 CRYST1 17.321 17.321 17.321 0.03 0.03 0.03 P 1 1 HETATM 1 H UNL 1 0.100 1.000 0.100 1.00 0.00 H HETATM 2 CL UNL 1 1.000 0.100 0.100 1.00 0.00 Cl CONECT 1 2 CONECT 2 1 MASTER 0 0 0 0 0 0 0 0 2 0 2 0 END
- so now you have:
$ ls CONTCAR hcl.pdb
Preparing the blender scene
A scene in blender contains three main things:
- Camera (has all the features that a real camera would have, focal length etc.; you don't need to know what that is)
- Light
- Subject (that will be the hcl.pdb molecule)
Since blender has many (really many) options for setting up a scene, you can use this blender file that has the Camera and Light set up. The idea is to use the scene.blend file as a container for all the settings (and that you can change and tune using blenders graphical interface and save). Download the scene.blend file and move it to ~/test_blender
- if you want additional details watch this: https://www.youtube.com/watch?v=zqK4m8a52U8
now we have the Camera and Light (inside of scene.blend) and the molecule (hcl.pdb)
$ ls CONTCAR hcl.pdb scene.blend
Rendering in the command line
- To call blender from the command line you can use the following command:
$ /usr/bin/blender-2.80-linux-glibc217-x86_64/blender -b ./scene.blend -o //./black_image -F PNG -f 1
here is what all the things mean:
/usr/bin/blender-2.80-linux-glibc217-x86_64/blender --call the blender executable-- -b ./scene.blend -o //./black_image -F PNG -f 1
(more details here: https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html)
Looping over multiple structures
MISC NOTES
Notice the two lines of hcl.pdb starting with "CONECT", those are important to draw bonds in blender. Not all converters include bonds in the output pdb file. Good news is that this also works:
COMPND HCl AUTHOR GENERATED BY OPEN BABEL 2.4.1 CRYST1 17.321 17.321 17.321 0.03 0.03 0.03 P 1 1 ATOM 1 H UNK 1 0.100 1.000 0.100 1.00 0.00 H HETATM 2 CL UNL 2 1.000 0.100 0.100 1.00 0.00 Cl MASTER 0 0 0 0 0 0 0 0 2 0 2 0 END
Back to Núria López and Group / Scripts_for_VASP.