<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On May 29, 2012, at 12:29 PM, Kersey Black wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi,<br><br>Very recent to Chimera. Trying to set the transparency of a bond<br>to be a function of bond length in each frame of a trajectory. <br>I have figured out how to define a transparent color, and <br>now I am imaging the solution might use something like range color<br>to vary the blending of the opaque version of the color and the <br>fully transparent version based on distance, with the distance being <br>determined as a per frame attribute of those atoms, but someplace around <br>here I am lost. Any hints, links or suggestions would be very much <br>appreciated. </div></blockquote><br></div><div>Hi Kersey,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>This is doable but you have to resort to Python, and even then it's tricky. The issues are:</div><div><br></div><div>1) By default, bonds are colored in "halfbond" mode, where each half of the bond is colored the same as the corresponding endpoint atom.</div><div>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).</div><div>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.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>So, as best I can determine the general plan of action would be:</div><div><br></div><div>1) Select the bond or bonds you want to do this for using whatever means you like.</div><div>2) Store a list of the selected bonds in the Python layer and create color objects for them.</div><div>3) Each frame, assign distance-dependent transparency values</div><div><br></div><div>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:</div><div><br></div><div>(step 2)</div><div><div>bonds = mdInfo['mol'].ghostBonds = chimera.selection.currentBonds()</div><div>for b in bonds:</div><div> b.halfbond = False</div><div> b.color = chimera.MaterialColor(*b.molecule.color.rgba())</div><div><br></div><div><br></div><div>(step 3)</div><div><div>for b in mdInfo['mol'].ghostBonds:</div><div> dist = b.length()</div><div> if dist <= 2.0:</div><div> opacity = 1.0</div><div> elif dist >= 5.0:</div><div> opacity = 0.0</div><div> else:</div><div> opacity = 1.0 - (dist - 2.0) / 3.0</div><div> b.color.opacity = opacity</div></div><div><br></div><div>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.</div><div><br></div><div>--Eric</div><div><br></div></div><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="5" style="font: 16.0px Helvetica"><span class="Apple-converted-space"> <span class="Apple-converted-space"> </span></span>Eric Pettersen</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="5" style="font: 16.0px Helvetica"><span class="Apple-converted-space"> <span class="Apple-converted-space"> </span></span>UCSF Computer Graphics Lab</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="5" style="font: 16.0px Helvetica"><span class="Apple-converted-space"> </span><a href="http://www.cgl.ucsf.edu">http://www.cgl.ucsf.edu</a></font></p><br class="Apple-interchange-newline"></div></span> </div></body></html>