3
$\begingroup$

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?

$\endgroup$
4
  • 3
    $\begingroup$ Pymol does a pretty good job and you can do everything using the command line. There's also a lot of documentation on it. $\endgroup$
    – DSVA
    Commented Feb 6, 2017 at 15:56
  • $\begingroup$ @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? $\endgroup$ Commented Feb 6, 2017 at 16:08
  • 3
    $\begingroup$ 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 $\endgroup$
    – DSVA
    Commented Feb 6, 2017 at 16:12
  • 1
    $\begingroup$ 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! $\endgroup$ Commented Feb 6, 2017 at 16:17

2 Answers 2

5
$\begingroup$

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

enter image description here

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).

$\endgroup$
6
  • 2
    $\begingroup$ 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. $\endgroup$ Commented Mar 23, 2017 at 18:24
  • 1
    $\begingroup$ 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... $\endgroup$ Commented Mar 23, 2017 at 18:41
  • $\begingroup$ 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). $\endgroup$ Commented Mar 23, 2017 at 18:46
  • $\begingroup$ @deusexmachina You may be able to script VMD to do this -- Geoff, thoughts? It's Tcl/Tk driven, right? $\endgroup$
    – hBy2Py
    Commented Mar 27, 2017 at 15:59
  • $\begingroup$ @hBy2Py - that's likely true, although I can't find any documentation on running VMD as a command-line tool. $\endgroup$ Commented Mar 27, 2017 at 19:54
3
$\begingroup$

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

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

beta-carotene-2d.png

$\endgroup$
1
  • 1
    $\begingroup$ Its about 3D structures. $\endgroup$ Commented Mar 4, 2017 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.