Command line rendering of chemical structures in Blender

From Wiki
Revision as of 19:34, 29 January 2020 by 10.0.7.29 (talk)
Jump to navigation Jump to search

go back to Main Page, Group Pages, Núria López and Group, Scripts_for_VASP


in preparation: 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 render HCl molecule for example:
$ 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.0000000000  +0.0000000000  +0.0000000000  T T T
 +1.0000000000  +0.0000000000  +0.0000000000  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.000   0.000   0.000  1.00  0.00           H  
HETATM    2 CL   UNL     1       1.000   0.000   0.000  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

notice the two lines 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.000   0.000   0.000  1.00  0.00           H  
HETATM    2 CL   UNL     2       3.000   0.000   0.000  1.00  0.00          Cl  
MASTER        0    0    0    0    0    0    0    0    2    0    2    0
END


Preparing the blender scene

Rendering in the command line

Looping over multiple structures

Back to Núria López and Group / Scripts_for_VASP.