[chimera-dev] volume display in my gui

Tom Goddard goddard at sonic.net
Fri Mar 6 16:40:11 PST 2015


Easier way.  Just use the Chimera “turn” command and if you need to run it from Python use the runCommand() python function I mentioned eariler.

	Tom


> On Mar 6, 2015, at 4:35 PM, Tom Goddard  wrote:
> 
> You can get a PIL (Python Image Library) image of the Chimera graphics window with
> 
> 	import chimera
> 	image = chimera.viewer.pilImages()[0]
> 
> You can supply optional width and height arguments in pixels otherwise the image size will match the graphics window size.  An example using pilImages is the Chimera image saving code in the saveImage() routine
> 
> 	share/chimera/printer.py
> 
> Chimera moves the models and the Chimera always points along the -z axis.  So to change the viewing angle you would rotate the models, for example:
> 
> 	import chimera
> 	axis = chimera.Vector(1,0,0)
> 	angle = 30
> 	r = chimera.Xform.rotation(axis, angle)
> 	chimera.openModels.setXform(r)
> 
> The openModels code is in C++ and you can see the C++ header file for the OpenModels class which has equivalent Python methods here
> 
> 	http://plato.cgl.ucsf.edu/trac/chimera/browser/trunk/libs/_chimera/OpenModels.h <http://plato.cgl.ucsf.edu/trac/chimera/browser/trunk/libs/_chimera/OpenModels.h>
> 
> This stuff is all pretty hard to figure out.  Unfortunately we do not have adequate programming documentation for Chimera.  We are remedying this in our next generation Chimera 2 which is not yet released.
> 
> 	Tom
> 
> 
> 	
>> On Mar 6, 2015, at 4:15 PM, hy liao wrote:
>> 
>> Hi Tom:
>> 
>> Thanks for the great details! A snapshot on the main Chimera window is good enough! I actually do not need interaction but just the correct display. In other words, given a volume data (density map) and a viewing angle (azimuthal and elevation angles), how do I get the corresponding 2D snapshot (a surface rendering) of the volume? Once I have this snapshot, I guess I can place it in my window by assigning it to my canvas object.  
>> 
>> Thanks again!
>> Stu
>> 
>> 
>> On Friday, March 6, 2015 6:27 PM, Tom Goddard wrote:
>> 
>> 
>> Hi Stu,
>> 
>>   The gui.py file I mentioned is shown with Chimera menu entry Tools / Volume Data / Values at Atom Positions.  It does not embed volume images though.
>> 
>>   Chimera is not designed to handle multiple interactive 3-d renderings, so you cannot in any simple way embed the Chimera graphics in your own Tk window.  The graphics is shown as a Togl widget (Tk OpenGL widget) that is drawn by Chimera C++ code.   Why do you want do that?  Why not just manipulate the view in the main Chimera graphics window?  The only example of embedding 3d data display in another window is the Chimera side view (menu Favorites / Side View) which has Python code in
>> 
>> 	chimera/share/chimera/viewing.py
>> 
>> But it uses C++ code to handle the drawing.
>> 
>>   If your aim is to make a custom app with Chimera graphics and your own set of controls you could modify the Chimera main window with Python code in
>> 
>> 	chimera/share/chimera/tkgui.py
>> 
>>   All of this is quite hard.  Another route is to take a snapshot image from the main Chimera window to put it in your own window, but then you could not rotate it.
>> 
>> 	Tom
>> 
>> 
>> 
>>> On Mar 6, 2015, at 3:11 PM, hy liao  wrote:
>>> 
>>> Hi Tom:
>>> 
>>> Thank you for your prompt reply. Sorry for my ignorance, but how can I run the script chimera/share/AtomDensity/gui.py and see the gui it actually produces?
>>> 
>>> Alternatively, this might be another way of formulating my question: to display a picture in a gui using tkinter, one can create a frame object, then a canvas object, then set the position of the canvas, then create a photoimage object, and then indicate that the picture goes in the canvas. Now, instead of a picture, how do I do the same for a chimera type of volume display? Do I have to also go through creating a frame, a canvas, and then indicate that the volume must reside in the just created canvas. It would be great if you know of any example out there. I have been relying on examples so far.   
>>> 
>>> Thanks again!
>>> 
>>> Stu
>>> 
>>> 
>>> On Friday, March 6, 2015 4:26 PM, Tom Goddard  wrote:
>>> 
>>> 
>>> 
>>> Hi Stu,
>>> 
>>>   To find out about Python functions that control volume display in Chimera that you could use from your Tkinter gui take a look at the Chimera Python scripts web page:
>>> 
>>> 	http://plato.cgl.ucsf.edu/trac/chimera/wiki/Scripts <http://plato.cgl.ucsf.edu/trac/chimera/wiki/Scripts>
>>> 
>>> for example the readvol.py example shows how to access volume data values.  In Python you can make use of commands that would be normally typed at the Chimera command-line in the following way
>>> 
>>>   from chimera import runCommand
>>>   runCommand(‘volume #0 level 12.5 color pink’)
>>> 
>>> or you could directly call functions in Python that change volume display, for example,
>>> 
>>> 	import VolumeViewer as vv
>>> 	v0 = vv.volume_list()[0]
>>> 	v0.set_parameters(surface_levels = [12.5], surface_colors = [(1,.5,.5,1)])
>>> 	
>>> To find those functions you can look at the Chimera Volume class Python code in your Chimera distribution
>>> 
>>> 	chimera/share/VolumeViewer/volume.py
>>> 
>>> (on Mac in Chimera.app/Contents/Resources/share/VolumeViewer/volume.py), and you can look at how the Chimera “volume” command does it
>>> 
>>> 	chimera/share/VolumeViewer/volumecommand.py
>>> 
>>> For making a Tk GUI look at a simple example in the Chimera distribution, for example, the values at atom positions dialog
>>> 
>>> 	chimera/share/AtomDensity/gui.py
>>> 
>>> 
>>>   Tom
>>> 
>>> 
>>> 
>>>> On Mar 6, 2015, at 12:16 PM, hy liao wrote:
>>>> 
>>>> Hi, I am developing a GUI with Tkinter, using anaconda's python 2.7.9. I like how chimera displays volumes (density maps), so I would like to a chimera-volume-display in my GUI. I am now disregarding anaconda and developing all within chimera's IDLE. However, I do not know which chimera commands I could use for my purpose; could you please point to some choices?
>>>> 
>>>> I am new with developing chimera extension and tkinter, and I mostly look for code examples. I had a look at  http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/ <http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/>, "Working with the Chimera Extension Manager," but I do not know which commands I could use to have chimera display a volume in a grid of my GUI.  
>>>> 
>>>> Thanks!
>>>> Stu
>>>> _______________________________________________
>>>> Chimera-dev mailing list
>>>> Chimera-dev at cgl.ucsf.edu <mailto:Chimera-dev at cgl.ucsf.edu>
>>>> http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev <http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev>
>>> 
>>> 
>>> 
>> 
>> 
>> 
>> 
> 
> _______________________________________________
> Chimera-dev mailing list
> Chimera-dev at cgl.ucsf.edu <mailto:Chimera-dev at cgl.ucsf.edu>
> http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev <http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-dev/attachments/20150306/3992c26e/attachment.html>


More information about the Chimera-dev mailing list