I get this error "NameError: name 'Selection' is not defined"
I am trying to parse a PDB file and also trying to extract some Model, Chain, Residue and Atom objects with Biopython. I tried the following code
from Bio.PDB.PDBParser import PDBParser
parser=PDBParser()
structure=parser.get_structure("test", "1fat.pdb")
model=structure[0]
chain=model["A"]
residue=chain[1]
File "<pyshell#48>", line 1, in <module>
residue = chain[(' ', 1, ' ')]
File "C:\Python27\lib\site-packages\Bio\PDB\Chain.py", line 67, in __getitem__
return Entity.__getitem__(self, id)
File "C:\Python27\lib\site-packages\Bio\PDB\Entity.py", line 38, in __getitem__
return self.child_dict[id]
KeyError: (' ', 1, ' ')
1 answer
you need to make sure that the residue you are trying to get is actually labelled 1.. what I do when I want something from a PDB structure is:
from Bio import PDB
parser= PDBParser()
structure=parser.get_structure("test", "1fat.pdb")
model=structure[0]
chain = model['A']
residue_list = Selection.unfold_entities(chain, 'R')
Now you have the complete list of residues within the chain you specified.
you can then specify that you want the first residue in the list:
my_residue= residue_list[0]
NOTE: It is not uncommon that during the crystallisation process the N and C terminals of the structure have been cleaved. The residue numbering will be consistent with the residue numbering you see in the PDB file.. to check which residues you have try:
my_residue.id()
to make sure it has the number you want..
I'm unfamiliar with Biopython PDB, but my first guess would be to try the following:
residue_list = PDB.Selection.unfold_entities(chain, 'R')
Log in to answer this question.
Is that the complete code? Which version of Biopython are you using? It works for me although I do see eight warnings about discontinuous chains (a problem in the data itself).
Just checked the code myself, Works perfectly fine, I also get the discontinuous chain error
@peter Iam using biopython 1.57
Can you update your Biopython, the current release is 1.58