Testing for Python - Batch Render Orbitals

@arugula_jones - I have very crude script here:

(I say crude … the code to connect and send messages to the desktop app needs to be polished and put into a Python class, so from avogadro import connection is possible.)

The main part of the script is:

for fileName in glob.glob("*.fchk"):
        # open the file
        print("Opening " + fileName)
        path = cwd + "/" + fileName
        basename = path[:-5] # strip off the .fchk
        sendMessage("openFile", {"fileName": path})

        sendMessage("renderOrbital", options)
        # wait 1 minute to compute the surface
        # .. adjust as needed
        time.sleep(60)
        print("Saving HOMO")
        sendMessage("saveGraphic", { "fileName": basename + "-homo.png" })

The surfaces dialog now accepts a few messages:

  • renderOrbital or renderMO
  • renderElectronDensity
  • renderVDW
  • renderSolventAccessible

The one catch is that generating surfaces is asynchronous, so the current solution is just to have the Python code wait 60 seconds before sending the saveGraphic message.

But it’ll go through a pile of .fchk or other files, open them, save orbitals, etc. Of course you can generate multiple orbitals and save the graphic of each, or the electron density, etc.

Suggestions? Concerns? General thoughts?

Oh, right. At the moment, the script requires this pull request:

I don’t know when the ‘nightly’ snapshots are handled. If anyone wants to test it, please let me know what OS / binary would work best?

I understand

" […] so the current solution is just to have the Python code wait 60 seconds before sending the saveGraphic message. […]"

as 1) a command is assembled, 2) Python broadcasts this command to an other part of Avogadro, 3) Python assumes 60 seconds are probably enough for the task to be completed, to 4) continue with other work (e.g., saveGraphic).

If so, Python’s module subprocess (part of the standard library) has an optional flag check=True. Could this be used to collect the exit signal of task renderOrbital as “task has been completed” which might happen earlier, or later than the fix threshold of a minute? I apologize for not providing a MWE, this comment only is conceptual.

No, the “problem” is that at the moment, Avogadro generates surfaces and meshes entirely asynchronously on its own threads.

So I need to do some more “plumbing” to have Avogadro send back a JSON signal when the work is done. At that point, the script can just wait for the signal.

Until then, we have this. (I’m guessing it’s close enough for some purposes.)

Thanks folks, I‘ll try to use this and see how it goes.