[Chimera-users] bond transparency as a function of length?
Eric Pettersen
pett at cgl.ucsf.edu
Tue May 29 15:08:38 PDT 2012
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20120529/abe49f1f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: saveBonds.py
Type: text/x-python-script
Size: 163 bytes
Desc: not available
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20120529/abe49f1f/attachment.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20120529/abe49f1f/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: byDist.py
Type: text/x-python-script
Size: 193 bytes
Desc: not available
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20120529/abe49f1f/attachment-0001.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20120529/abe49f1f/attachment-0002.html>
More information about the Chimera-users
mailing list