[chimerax-users] Batch save the image of each chain

Tom Goddard goddard at sonic.net
Sat Dec 12 11:26:58 PST 2020


Hi Yong Liu,

  The code I gave you makes an image for every chain of a structure.  Here is a version of the code chain_images2.py defining the chainimages command that allows you to specify the chains you want images for

	chainimages #1/A,B,C

I added that code the the ChimeraX Recipes page

	https://rbvi.github.io/chimerax-recipes/chain_images/chain_images.html <https://rbvi.github.io/chimerax-recipes/chain_images/chain_images.html>

For the coloring part, you could try to add that or you could simply color the structure before hand:

	color #1 blue
	color #1/A pink
	color #1/B gold

  Tom




> On Dec 11, 2020, at 9:09 PM, Yong Liu <liuyongbox at gmail.com> wrote:
> 
> Dear Tom, 
> 
> Many thanks. It is working very well.
> 
> I am wondering if it is fine to add two more arguments for this command which are chains of list and color.  For example: chainimages #1/X,Y,Z Blue
> 
> Kind regards,
> Yong Liu
>> On Dec 11, 2020, at 22:29, Tom Goddard <goddard at sonic.net <mailto:goddard at sonic.net>> wrote:
>> 
>> Here is what the saved images look like for 2bbv.
>> 
>> 	Tom
>> 
>> <2bbv.jpg>
>> 
>>> On Dec 11, 2020, at 11:41 AM, Tom Goddard <goddard at sonic.net <mailto:goddard at sonic.net>> wrote:
>>> 
>>> Hi Yong Liu,
>>> 
>>>   First start by figuring out the ChimeraX commands to do what you want.  For example, the commands to save an image of chain A shown as atoms could be
>>> 
>>> 	open 2bbv
>>> 
>>> 	show #1/A only
>>> 	view
>>> 	save ~/Desktop/2bbv_chain_A.png
>>> 
>>> Now the trick is we want to do that for all chains.  The ChimeraX command language has not looping methods so we have to use some Python.  Also you wanted to create a new command that does the 3 commands above with the right chain id and model number substituted in.  I've attached some Python code chain_images.py that does that makes the command.  If you open that Python file in ChimeraX it will define the command then type
>>> 
>>> 	chainimages #1
>>> 
>>> to make the images.  I've put this example Python code on the ChimeraX Recipes web site
>>> 
>>> 	https://rbvi.github.io/chimerax-recipes/chain_images/chain_images.html <https://rbvi.github.io/chimerax-recipes/chain_images/chain_images.html>
>>> 
>>> If you want ChimeraX to define this command each time you start you can put command "open ~/scripts/chain_images.py" in ChimeraX startup preferences.
>>> 
>>>   Tom
>>> 
>>> <chain_images.py>
>>> 
>>> 
>>>> On Dec 10, 2020, at 10:29 PM, Yong Liu <liuyongbox at gmail.com <mailto:liuyongbox at gmail.com>> wrote:
>>>> 
>>>> Hi All,
>>>> I would like to save the image of each chain in one command. I have wrote following python code, but it is not working. Is anybody know how to fix it?
>>>> 
>>>> 
>>>> # save the image of each chain
>>>> 
>>>> def batchSave(session):
>>>> 	chainID_list = info chains 
>>>> for x in chainID_list:
>>>> 
>>>> chainID = chainID_list.split()
>>>> 
>>>> ID = chainID[-1]
>>>> 
>>>> save "Desktop/ID.png" width 4000 height 4000 transparentBackground true
>>>> 
>>>> 
>>>> def register_command(session):
>>>>  from chimerax.core.commands import CmdDesc, register
>>>>  desc = CmdDesc()
>>>>  register('batchSave', desc, batchSave, logger=session.logger)
>>>> 
>>>> register_command(session)
>>>> 
>>>> Best,
>>>> Yong Liu
>>>> _______________________________________________
>>>> ChimeraX-users mailing list
>>>> ChimeraX-users at cgl.ucsf.edu <mailto:ChimeraX-users at cgl.ucsf.edu>
>>>> Manage subscription:
>>>> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users <https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users>
>>>> 
>>> 
>>> _______________________________________________
>>> ChimeraX-users mailing list
>>> ChimeraX-users at cgl.ucsf.edu <mailto:ChimeraX-users at cgl.ucsf.edu>
>>> Manage subscription:
>>> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users <https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users>
>> 
> 
> _______________________________________________
> ChimeraX-users mailing list
> ChimeraX-users at cgl.ucsf.edu
> Manage subscription:
> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimerax-users/attachments/20201212/5fd131cd/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: chain_images2.py
Type: text/x-python-script
Size: 766 bytes
Desc: not available
URL: <http://plato.cgl.ucsf.edu/pipermail/chimerax-users/attachments/20201212/5fd131cd/attachment.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimerax-users/attachments/20201212/5fd131cd/attachment-0001.html>


More information about the ChimeraX-users mailing list