# Avogadro Molecule Editor: How to render image from command line?

Given a molecular geometry in the .xyz file format, how can I use Avogadro on the command line to render an image of it?

The website states that there is some command line API available, but I can't seem to find any documentation/information about it. Alternatively, are there any other molecular visualization tools that provide a convenient command line interface for image rendering of .xyz files?

• Pymol does a pretty good job and you can do everything using the command line. There's also a lot of documentation on it. – DSVA Feb 6 '17 at 15:56
• @DSVA Thanks for pointing that out ; ) I think I will go into that direction for now. Do you know if pymol can also directly render to png without starting the UI? – logical x 2 Feb 6 '17 at 16:08
• Yes, you can start it in command line mode (pymolwiki.org/index.php/Command_Line_Options) or use API and the command you are looking for is "png" pymolwiki.org/index.php/Png – DSVA Feb 6 '17 at 16:12
• That's awesome. I really needed that functionality for a presentation on thursday. I somehow have a lot of geometries to analyze, so I needed some kind of access to rendering geometries from python. I think that really is what I was searching for : ) You made my day, thanks! – logical x 2 Feb 6 '17 at 16:17

There is no way to currently do this using Avogadro, although Python bindings have been "in the works" for a while. The problem is, with volunteer developers, there's not always enough free time to tackle all features.

You can create pseudo-3D images using Open Babel. I developed this for the Pitt Quantum Repository to give SVG and PNG images in the search interface. It's not perfect, but I like the effect.

obabel beta-carotene.xyz -O beta-carotene-2d.svg -xS -xd -xb none


The -xS indicates this 3D "ball and stick" style, -xd prevents the molecule name from being included, and -xb none gives transparent background to the SVG (useful for presentations).

• This current rendering is available in the development version of Open Babel - a slightly different version is available in 2.4.x. The new "tweaks" add some scaling to atom sizes and opacity to give a depth effect, which works well in most molecules. Suggestions are welcome. – Geoff Hutchison Mar 23 '17 at 18:24
• I really think that convenient solutions for batch job visualizations of molecules (e.g. md trajectories) are lacking. The only solution I found so far is pymol, which however I quite dislike due to their licensing choice (e.g. real 3d rendering lacking in free version and so on). So this is quite interesting... – logical x 2 Mar 23 '17 at 18:41
• Agreed on the need for convenient solutions for batch visualization. I was hopeful that we'd have Python bindings for Avogadro2 by now, but the student tackling that last year in Google Summer of Code disappeared (likely doing some other research). – Geoff Hutchison Mar 23 '17 at 18:46
• @deusexmachina You may be able to script VMD to do this -- Geoff, thoughts? It's Tcl/Tk driven, right? – hBy2Py Mar 27 '17 at 15:59
• @hBy2Py - that's likely true, although I can't find any documentation on running VMD as a command-line tool. – Geoff Hutchison Mar 27 '17 at 19:54

If what you want is a simple 2D structure, OpenBabel can do it for you. Say you have a structure named beta-carotene.xyz:

The following command issues a 2D depiction of the above:

\$ obabel beta-carotene.xyz -O beta-carotene-2d.png -xp 600 -x0 molfile


• Its about 3D structures. – logical x 2 Mar 4 '17 at 17:25