[Chimera-users] bond transparency as a function of length?

Eric Pettersen pett at cgl.ucsf.edu
Mon Jun 4 14:10:27 PDT 2012


Great!  Glad your got it to work and kind of impressed you resolved  
those issues on your own!  I'm envisioning a lot of nosing around the  
Chimera code on your part to see how the sausage is made. :-)

--Eric

On Jun 4, 2012, at 9:50 AM, Kersey Black wrote:

> Hi Eric,
>
> Thanks so much for the help.  I was able to quickly get the basic  
> functionality
> I wanted, and I would not have gotten there without your guidance.   
> In the process
> I ran into a few small issues that come simply from not yet  
> understanding the overall
> structure of the data and its representation, and its interaction in  
> the python interface.
> But that is coming together.  Notably, I needed to find other ways  
> to select the
> bonds that would have be affected by the fading and also how to  
> control element colors
> in the context of applying this to C-C bonds in a simple  
> hydrocarbon.  Evidentially, an arbitrary color
> gets applied to the model as a whole when it comes up, and then when  
> fading the bonds
> they would sometimes fade to reveal that underlying solid color.   
> But I have sorted those things out.
> The Python interface is very cool.
>
> Thanks again.
>
> Cheers
> Kersey
>
> On May 29, 2012, at 3:08 PM, Eric Pettersen wrote:
>
>> On May 29, 2012, at 12:29 PM, Kersey Black wrote:
>>
>>> Hi,
>>>
>>> Very recent to Chimera.  Trying to set the transparency of a bond
>>> to be a function of bond length in each frame of a trajectory.
>>> I have figured out how to define a transparent color, and
>>> now I am imaging the solution might use something like range color
>>> to vary the blending of the opaque version of the color and the
>>> fully transparent version based on distance, with the distance being
>>> determined as a per frame attribute of those atoms, but someplace  
>>> around
>>> here I am lost.  Any hints, links or suggestions would be very much
>>> appreciated.
>>
>> Hi Kersey,
>> 	This is doable but you have to resort to Python, and even then  
>> it's tricky.  The issues are:
>>
>> 1) By default, bonds are colored in "halfbond" mode, where each  
>> half of the bond is colored the same as the corresponding endpoint  
>> atom.
>> 2) There is no command to set only the transparency of a bond.   
>> There is a 'bondcolor' command which sets the red, green, and blue  
>> components as well (and also takes the bond out of halfbond mode).   
>> The 'transparency' command works on atoms, not bonds (but bonds in  
>> halfbond mode "inherit" the transparency changes of their endpoint  
>> atoms).
>> 3) In Python, changing the transparency component of a color object  
>> will affect every atom/bond/molecule using that color object, so  
>> the bonds you want to vary the transparency of will have to have  
>> unique color objects assigned to them.
>>
>> 	So, as best I can determine the general plan of action would be:
>>
>> 1) Select the bond or bonds you want to do this for using whatever  
>> means you like.
>> 2) Store a list of the selected bonds in the Python layer and  
>> create color objects for them.
>> 3) Each frame, assign distance-dependent transparency values
>>
>> You do both steps 2 and 3 with Python scripts in the Per-Frame  
>> dialog of the MD Movie tool.  For step 2 you input the script,  
>> click Apply and execute 1 step of your trajectory.  Then back up  
>> the trajectory and input the script for step 3, click OK, and run  
>> the trajectory.  Here are the scripts:
>>
>> (step 2)
>> bonds = mdInfo['mol'].ghostBonds = chimera.selection.currentBonds()
>> for b in bonds:
>>         b.halfbond = False
>>         b.color = chimera.MaterialColor(*b.molecule.color.rgba())
>>
>>
>> (step 3)
>> for b in mdInfo['mol'].ghostBonds:
>>         dist = b.length()
>>         if dist <= 2.0:
>>                 opacity = 1.0
>>         elif dist >= 5.0:
>>                 opacity = 0.0
>>         else:
>>                 opacity = 1.0 - (dist - 2.0) / 3.0
>>         b.color.opacity = opacity
>>
>> For the step 3 script, change the distance cutoff values and  
>> interpolation formula as you like to fit your needs.  I've attached  
>> the scripts as files so that you can save some typing and use the  
>> 'insert from file' button on the Per-Frame dialog.
>>
>> --Eric
>>
>>                         Eric Pettersen
>>                         UCSF Computer Graphics Lab
>>                         http://www.cgl.ucsf.edu
>>
>> <saveBonds.py>
>> <byDist.py>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20120604/03562cd3/attachment.html>


More information about the Chimera-users mailing list