Re: [Chimera-users] Selection through bond and fragment naming

Dear all, thanks a lot for your answers. I seem to have a problem though. When running the script, one way or another I always ends up with something like: a.residue.removeAtom(a) AttributeError: 'NoneType' object has no attribute 'removeAtom' AttributeError: 'NoneType' object has no attribute 'removeAtom' File "M:\REUNIONS\dibuixos\Manipulate_structure\newres.py", line 20, in <module> a.residue.removeAtom(a) See reply log for Python traceback. I think I got the origin of the problem but can't figure out how to solve it. What I observed is that, before running the script if I do the following after selecting my atoms:
for a in at: print a.residue I have the following list printed
UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 but doing the same AFTER having run the script gives : None UNK 1 UNK 1 UNK 1 UNK 1 UNK 1 ... It seems like the residue type of the first atom disappeared. Any clue? all the best, JD Dr. Jean-Didier Maréchal Lecturer The Computational Biotechnological Chemistry Team Unitat de Química Física Departament de Química Universitat Autònoma de Barcelona Edifici C.n. 08193 Cerdanyola (Barcelona) Tel: +34.935814936 e-mail: JeanDidier.Marechal@uab.es www: http://asklipio.qf.uab.es ----- Missatge original ----- De: Eric Pettersen <pett@cgl.ucsf.edu> Data: Divendres, Març 11, 2011 8:29 pm Assumpte: Re: [Chimera-users] Selection through bond and fragment naming
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(): addAtoms.update(a.neighbors) addCurrent(addAtoms)
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... try: rname, rnum = arguments except ValueError: raise chimera.UserError("must supply residue name and number arguments")
try: rnum = int(rnum) except ValueError: raise chimera.UserError("residue number (second arg) must be an integer")
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: a.residue.removeAtom(a) if len(a.residue.atoms) == 0: a.molecule.deleteResidue(a.residue)
# add atoms to new residue for a in atoms: newRes.addAtom(a)
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
Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu

On Mar 14, 2011, at 1:44 PM, Jean Didier Pie Marechal wrote:
Dear all,
thanks a lot for your answers. I seem to have a problem though. When running the script, one way or another I always ends up with something like: a.residue.removeAtom(a) AttributeError: 'NoneType' object has no attribute 'removeAtom' AttributeError: 'NoneType' object has no attribute 'removeAtom'
File "M:\REUNIONS\dibuixos\Manipulate_structure\newres.py", line 20, in <module> a.residue.removeAtom(a)
So, it seems like the script I sent was mildly buggy. In particular, "a.residue" gets used even after the atom has been removed from the residue. So, you need to change this:
# withdraw atoms from their current residues for a in atoms: a.residue.removeAtom(a) if len(a.residue.atoms) == 0: a.molecule.deleteResidue(a.residue)
to: # withdraw atoms from their current residues for a in atoms: res = a.residue res.removeAtom(a) if len(res.atoms) == 0: a.molecule.deleteResidue(res) Sorry about that! --Eric
participants (2)
-
Eric Pettersen
-
Jean Didier Pie Marechal