
Hi Eric, Thank you for your kind response, I did indeed not realize the necessity to look up the residue and that it is not sufficient to just supply the sequence number. I have a follow up question, if I may: I have not been able to figure out how to color the bonds individually, according to the list of colors supplied in the pseudobondsToAdd list. Rather the color is always set according to the last color supplied in the list, since the command in the code obviously colors the group as a whole: for line in data: r1, A1, r2, A2, c = line r1 = int(r1) r2 = int(r2) A1 = unicode(A1) A2 = unicode(A2) rId1 = resLookup[r1] rId2 = resLookup[r2] grp = getPseudoBondGroup("mybonds", associateWith=model) grp.newPseudoBond(rId1.atomsMap[A1][0],rId2.atomsMap[A2][0]) grp.color = getColorByName(c) After consulting the commands index, it is not clear to me how to write the code to color the pseudobonds individually with the input of the color from the variable c. Sincerely Dean ________________________________________ From: Eric Pettersen [pett@cgl.ucsf.edu] Sent: Sunday, October 21, 2012 7:32 AM To: Strotz von Moos Dean Cc: chimera-users@cgl.ucsf.edu Subject: Re: [Chimera-users] scripting problem Hi Dean, Your script looks okay to me. One thing that may be tripping you up is that residue '7' is the eighth residue found in the input file (0: first; 1: second; etc.). It is also not necessarily the residue with sequence number 7. If you want to find the residue with sequence number 7, you would have to make a lookup dictionary, something like: resLookup = {} for r in model[0].residues: resLookup[r.id.position] = r then you could lookup the residue with sequence number 7 with: r = resLookup[7] If you already knew all the above, then somehow the residue doesn't have a QD1 atom in it. Just above the line that throws the error put a "print res". That will print the residue identification to the reply log so you can see which residue it was using to look up the QD1 atom in and make sure it's the residue you expect. I hope something in this reply helps! :-) --Eric Eric Pettersen UCSF Computer Graphics Lab On Oct 19, 2012, at 12:55 PM, Strotz von Moos Dean wrote:
Hi,
I have a question to the following code. I can not figure out why certain atom types are not understood (HG, QD etc). The atom types occur in the structure and I can select them through the terminal or add them as pseudo bonds through the pseudoBond reader.
For a QD1 one for instance I get: KeyError: 'QD1' <module> grp.newPseudoBond(res[r1].atomsMap[A1][0],res[r2].atomsMap[A2][0])
Excerpt from the input file:
7 HA 7 H red #this is understood 7 H 7 QD1 yellow #error message for QD1
What is wrong with my code? The A1 = str(A1) ? How would I do it alternatively?
All the best and many thanks Dean
import chimera from chimera.colorTable import getColorByName from chimera.misc import getPseudoBondGroup from chimera import runCommand as rC # use 'rc' as shorthand for runCommand
model = chimera.openModels.open('xxx.pdb')
rC('show #0') rC('ribbon') rC('ribcolor gray') rC('background solid white') rC('unset depthCue')
ins = open('pseudobondsToAdd.txt', "r" ) array = [] for line in ins: array.append(line) ins.close()
for line in array: r1, A1, r2, A2, c = line.split() # Split the line on white space. r1 = int(r1) r2 = int(r2) A1 = str(A1) A2 = str(A2) c = str(c) res = model[0].residues grp = getPseudoBondGroup("mybonds", associateWith=model) grp.newPseudoBond(res[r1].atomsMap[A1][0],res[r2].atomsMap[A2][0]) grp.color = getColorByName(c)
ETH Zürich Dean Strotz Laboratorium f. Physikalische Chemie HCI F 217 Wolfgang-Pauli-Str. 10 8093 Zürich
E-Mail: dean.strotz@phys.chem.ethz.ch<mailto:dean.strotz@phys.chem.ethz.ch>
_______________________________________________ Chimera-users mailing list Chimera-users@cgl.ucsf.edu http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users