[Chimera-users] Selection through bond and fragment naming

Eric Pettersen pett at cgl.ucsf.edu
Fri Mar 11 11:29:37 PST 2011

On Mar 11, 2011, at 7:42 AM, Jean Didier Pie Marechal wrote:

> Hi,
> 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 ):
> 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.

Hi JD,
	My only idea as to how to do this is with a short Python script:

from chimera.selection import currentAtoms, addCurrent
addAtoms = set()
for a in currentAtoms():

	You could then use the open command to run it:

open <script folder location (e.g. ~marechal/scripts)>/expand.py

which you could short to "xp" with the alias command:

alias ^xp open blah-blah/expand.py

> 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?

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:

	setattr r myAttrName my-attr-val sel

Organizing the atoms into a residue again requires Python, and not as  
simple a script as for your first question, e.g.:

# script designed to run under "runscript" command, therefore has an  
"arguments" variable available...
	rname, rnum = arguments
except ValueError:
	raise chimera.UserError("must supply residue name and number  

	rnum = int(rnum)
except ValueError:
	raise chimera.UserError("residue number (second arg) must be an  

atoms = chimera.selection.currentAtoms()
if not atoms:
	raise chimera.UserError("No atoms selected")

# make a new residue
newRes = atoms[0].molecule.newResidue(rname, "A", rnum, ' ')

# withdraw atoms from their current residues
for a in atoms:
	if len(a.residue.atoms) == 0:

# add atoms to new residue
for a in atoms:

	So you would run this script with the command "runscript blah-blah/ 
newres.py TYR 1", which could again be shorted using aliasing:

	alias ^nr runscript blah-blah/newres.py $1 $2


                         Eric Pettersen
                         UCSF Computer Graphics Lab

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

More information about the Chimera-users mailing list