Automate molecular figures

One of the things I like most from being a computational chemist, is the possibility to automate tasks by using scripts.
There is usually no problem for automating almost anything, but unfortunately, there are a few tricky to automate tasks, for example, when it comes to generate atomic/molecular figures.
Let’s think that we have to calculate the energies of a lot of different molecules, and after doing that, we certainly need to check the results. We can easily “grep” the total energy (or any other numerical/ASCII value) from the output files but usually, the only way to take a look to the geometry of the structures is by going trough all the outputs and opening them with a graphic molecular viewing program (such as molden, vmd, xmakemol, jmol, …). This task can be quite painful, specially for the geek people who does not like wasting their energy using the mouse if it is not completely necessary.
I am one of these people, so I was researching how to avoid that tedious opening > clicking > clicking > typing name > clicking > more clicking ... task, and found two possibilities.
The first one was by using the Atomic Simulation Environment or ASE, which has endless possibilities for any kind of modeling calculations, and can also be used to automate molecular figures. I found it to be quite good, but getting some acceptable (nice) figures is not so straight forward, and the defaults don’t include, for example, proper sticks for the bonds!
I needed to add several hacks in order to for example, create proper balls and sticks, but finally I managed to get figures like this one:

Automate molecular figures: Molecular figure generated with ASE.

Molecular figure generated with ASE.

But the point in automating figures is to save energy, and I found out that jmol can actually generate molecular figures from command line with really simple scripts.
This is the fastest and simplest way I have found to automate molecular figures. Just follow these two steps:

  1. Write the jmol script (called i.e. jmol.cmd) with these two simple lines:
    load ""
    write PNG "figure.png"

    were “load” will open the geometry file (or even output files from the most popular molecular modeling codes) and “write” writes the output, which in this case is set as as PNG (but there are many other different formats including eps, pov, … por PNGT for PNG images with transparent background).
    You can add hundreds of different commands between these two for modifying the look of your molecule.

  2. Run the script simply by:
    jmol -x -s jmol.cmd

    were the “-x” option tells jmol to close after the script is completed and the “-s” option specifies the script to load.

Can anybody generate a figure in a more simple and effortless way?

The result will look like this:

Automate molecular figures: Molecular figure generated by Jmol.

Molecular figure generated by Jmol.

One thought on “Automate molecular figures

  1. Aravindhan Ganesan

    Hi Julen,

    I follow your posts and code regularly and thanks for sharing those stuffs with the community… 🙂

    This code really works like a gem, saving lots of time in generating molecular graphics in a more handy way..I was looking for a similar code in google, but could not find one..Luckily I found yours..Thanks very much…


Comments are closed.