One of my goals for the summer (and thus 2.0) is to get a set of Python commands - for automating from scripts, or for an embedded Python terminal.
At some point these features will also be turned into a “record my actions” command, but that’s a longer-term project (help wanted )
For example - loop through a list of files (e.g. *.xyz
) and save screenshots
- File operations
- Open File / Read from String
- Save Current Molecule to File / Save to String
- Close file (i.e., so you don’t have 100s of open files)
- Save Screenshot (with specified resolution)
- Save Movie (with specified frames)
- Camera operations (e.g., to “tour” a molecule)
- Rotate camera in x, y, z axis
- Zoom camera
- Set / Save camera view
- Render settings
- Turn on / off display types (e.g., Ball-and-Stick, Wireframe, etc.)
- Surfaces
- Generate MO / Electron Density (etc.)
- Editing
- Add atom / bond
- Remove atom / bond
- Change atom (element, position, etc.)
- Change bond order
- Selection
- Standard selection commands (e.g., select atom X, select element 6, etc.)
- Import
- Properties
- Get molecule name (from PubChem)
- Get distance, angle, torsion angle
- CJSON
- Convert array of coordinates to array of (x,y,z) vectors and vice-versa
Work on these commands will be an incremental effort. But I’m open to suggestions / priorities…
What are things you’d like to automate, or you currently automate with Jmol, VMD, Pymol, etc.?
1 Like
In your example:
loop through a list of files (e.g. *.xyz) and save screenshots
It would be nice to have an option to draw Molecular Orbitals or Densities to save to screenshots. Like this I could check how a MO/Electron Density change along a reaction.
Yep, we’ve got the “list of files and save screenshots” script, although I’ll want to polish it.
In that use case, you’d load a .molden
or .fchk
(or similar), create a specific orbital or electron density surface, save the screenshot, and then loop through the next file?
Sounds like a good use case…
Or are there formats with orbitals / checkpoints with multiple frames?
<< In that use case, you’d load a .molden
or .fchk
(or similar), create a specific orbital or electron density surface, save the screenshot, and then loop through the next file?
Thats it. E.g. Orca save gbw files for each point along a path. This files can be converted to molden files for each point. In this case Avogadro would loop over the molden files, plot the selected MO or Density and save them to screenshots.
Just wondering if it would be difficult to do this for more than one orbital per file. Working with MCSCF or CAS calculations, it is really usefull to check wheter the MOs in the active space are the same for the whole path.
No, I don’t think so. The idea would be something like this pseudo-code:
from avogadro import connect as avo
for file_name in glob.iglob("*.molden"):
# we need the full path to the file
path = cwd + "/" + file_name
avo.openFile(path)
avo.setRendering("Surfaces", True)
# calculate the MO - assuming 6 is the HOMO
avo.sendMessage("calculateOrbital", 6)
# save the screenshot
avo.saveGraphic(path[:-4] + "homo.png")
avo.sendMessage("calculateOrbital", 7)
# save the screenshot
avo.saveGraphic(path[:-4] + "lumo.png")
avo.sendMessage("calculateElectronDensity")
avo.saveGraphic(path[:-4] + "dens.png")
avo.closeFile()
Thinking about it again, maybe it is better to make the script plot only one orbital and then run the script one time for each orbital.
Yes, it wouldn’t be hard to write the script either way. The main thing was to know that you have .molden
or similar files for each step.