<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Mar 11, 2011, at 7:42 AM, Jean Didier Pie Marechal wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi, <br><br>I have a system from which I only have xyz coordinates. What I would like to do is to define myself residue attribute on different fragments of the molecules. Could you tell me how (or if there is a way to ):<br></div></blockquote><div><blockquote type="cite"><div><br>1. expand a selection to bonding atoms (i.e. I click on one atom and expand selection through one bond after each actions) This would be of the easiest way for me to select the fragments I want to.</div></blockquote><br></div>Hi JD,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>My only idea as to how to do this is with a short Python script:</div><div><br></div><div>from chimera.selection import currentAtoms, addCurrent</div><div>addAtoms = set()</div><div>for a in currentAtoms():</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>addAtoms.update(a.neighbors)</div><div>addCurrent(addAtoms)</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>You could then use the open command to run it:</div><div><br></div><div>open <script folder location (e.g. ~marechal/scripts)>/expand.py</div><div><br></div><div>which you could short to "xp" with the alias command:</div><div><br></div><div>alias ^xp open blah-blah/expand.py</div><div><br><blockquote type="cite"><div><br>2. set a residue attribute to the given selected fragment. I think I remember how to do so in scripting, but what is the command line to do so?</div></blockquote><br></div><div>So, do you really want to set a residue-level attribute, or do you want to organize the selected atoms into a residue? Setting a residue-level attribute for the atoms is easy:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>setattr r myAttrName my-attr-val sel</div><div><br></div><div>Organizing the atoms into a residue again requires Python, and not as simple a script as for your first question, e.g.:</div><div><br></div><div># script designed to run under "runscript" command, therefore has an "arguments" variable available...</div><div>try:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>rname, rnum = arguments</div><div>except ValueError:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>raise chimera.UserError("must supply residue name and number arguments")</div><div><br></div><div>try:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>rnum = int(rnum)</div><div>except ValueError:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>raise chimera.UserError("residue number (second arg) must be an integer")</div><div><br></div><div>atoms = chimera.selection.currentAtoms()</div><div>if not atoms:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>raise chimera.UserError("No atoms selected")</div><div><br></div><div># make a new residue</div><div>newRes = atoms[0].molecule.newResidue(rname, "A", rnum, ' ')</div><div><br></div><div># withdraw atoms from their current residues</div><div>for a in atoms:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>a.residue.removeAtom(a)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if len(a.residue.atoms) == 0:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>a.molecule.deleteResidue(a.residue)</div><div><br></div><div># add atoms to new residue</div><div>for a in atoms:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>newRes.addAtom(a)</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>So you would run this script with the command "runscript blah-blah/newres.py TYR 1", which could again be shorted using aliasing:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>alias ^nr runscript blah-blah/newres.py $1 $2</div><div><br></div><div>--Eric</div><br><br><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><br></body></html>