Many example ChimeraX Python scripts are on the ChimeraX Recipes web site

https://rbvi.github.io/chimerax-recipes/

and the ChimeraX Programming manual has information about the Python functions and data structures.

https://www.cgl.ucsf.edu/chimerax/docs/devel/index.html

  Tom

On Oct 17, 2022, at 10:59 AM, Tom Goddard <goddard@sonic.net> wrote:

Here is an example ChimeraX Python script to open an atomic structure and a map, rotate and save an image. All it does is run the equivalent ChimeraX commands.  Saving an image can only be done with the GUI or on Linux with the --offscreen startup flag.  If I don't need to save an image I could run it without a gui

chimerax --nogui batch.py

Python code below.

  Tom


# Open a PDB file and an XPLOR map file, rotate and save an image.

from chimerax.core.commands import run

pdb_path = '~/Downloads/ChimeraX/PDB/1grl.cif'
map_path = '~/Downloads/ChimeraX/EMDB/emd_1080.map'

models = run(session, f'open {pdb_path}')
m = models[0]
print(f'Opened {m.name} with {m.num_atoms} atoms') 

maps = run(session, f'open {map_path}')
v = maps[0]
sx,sy,sz = v.data.size
print(f'Opened {v.name} with grid size {sx}, {sy}, {sz}') 

run(session, 'turn y 90')
run(session, 'save image.png')


<batch.py>


On Oct 17, 2022, at 9:12 AM, Elaine Meng via Chimera-dev <chimera-dev@cgl.ucsf.edu> wrote:


On Oct 17, 2022, at 7:26 AM, Jan Hofmann via Chimera-dev <chimera-dev@cgl.ucsf.edu> wrote:

To whom it may concern,
I want to write a python script to open a pdb file, then load a .xplor file in as well. After one rotation which I also want to do via the script I want to export the output file as a .png file.
Could you provide any advice to me on how to write such a script? I am having troubles loading any python script into ChimeraX. Eventually I want to use this script to batch wise output structures including guest adsorption where the guest species is introduced via the .xplor from previous analysis and the structure is provided by a .pdb file. I really would need some advice/tutorial at this stage so I would be more than happy to hear back from you.
Many thanks and kind regards,
Jan Hofmann, M.Sc.
PhD Student, Department of Chemistry
Chapman Group
Stony Brook University
jan.hofmann@stonybrook.edu
Office: Room 563, Chemistry

Hi Jan,
This is the Chimera list, maybe you wanted to send to chimerax-users@cgl.ucsf.edu instead?  (Cc'd)

Maybe it can be done at least partly with ChimeraX command script instead of a python script.  If you do these steps interactively in ChimeraX, it should show the corresponding commands in the Log .   A ChimeraX command script is just the same commands you would enter in the Command Line, except in a plain text file named something.cxc as explained here:
<https://rbvi.ucsf.edu/chimerax/docs/user/commands/usageconventions.html#cxc-files>

There is also a "forEachFile" option of the "open" command to read a ChimeraX command file and apply it to a series of input files, e.g. all the .pdb files in some folder.  If you name the .xplor files to match the corresponding .pdb files, maybe you can use the $ mechanism described for that option, see:
<https://rbvi.ucsf.edu/chimerax/docs/user/commands/open.html#forEachFile>

I hope this helps,
Elaine
-----
Elaine C. Meng, Ph.D.                       
UCSF Chimera(X) team
Department of Pharmaceutical Chemistry
University of California, San Francisco


_______________________________________________
Chimera-dev mailing list
Chimera-dev@cgl.ucsf.edu
https://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev