[chimerax-users] [chimera-dev] ChimeraX pyhton script

Tom Goddard goddard at sonic.net
Mon Oct 17 10:59:54 PDT 2022


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




> On Oct 17, 2022, at 9:12 AM, Elaine Meng via Chimera-dev <chimera-dev at cgl.ucsf.edu> wrote:
> 
>> 
>> On Oct 17, 2022, at 7:26 AM, Jan Hofmann via Chimera-dev <chimera-dev at 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 at stonybrook.edu
>> Office: Room 563, Chemistry
> 
> Hi Jan,
> This is the Chimera list, maybe you wanted to send to chimerax-users at cgl.ucsf.edu <mailto:chimerax-users at 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 <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 <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 at cgl.ucsf.edu <mailto:Chimera-dev at cgl.ucsf.edu>
> https://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev <https://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.rbvi.ucsf.edu/pipermail/chimerax-users/attachments/20221017/69966955/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: batch.py
Type: text/x-python-script
Size: 509 bytes
Desc: not available
URL: <http://www.rbvi.ucsf.edu/pipermail/chimerax-users/attachments/20221017/69966955/attachment.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.rbvi.ucsf.edu/pipermail/chimerax-users/attachments/20221017/69966955/attachment-0001.html>


More information about the ChimeraX-users mailing list