0

我想绘制泛素蛋白的alpha-cabonnitrogen距分布。所以我从 RCSB 网站下载了 1UBQ.pdb。现在使用biopython,我试图找到所有债券之间的alpha-cabon(CA)距离nitrogen(N)

我试过做如下代码:

import sys
#from Bio.PDB import *
from Bio.PDB.PDBParser import PDBParser 
from numpy import loadtxt

pdb1 ='/home/devanandt/Documents/VMD/1UBQ.pdb'
sys.stdout = open('file_ubq', 'w')
parser=PDBParser(PERMISSIVE=1)

#file=open('1UBQ.pdb','r')
#header_dict=parse_pdb_header(file)
#file.close()
i=1
structure = parser.get_structure('1UBQ',pdb1)
for model in structure:
    for chain in model:
        for residue in chain:
            for atom in residue:
                model = structure[0] 
                chain = model['A'] 
                residue_1 = chain[i] 
                atom_1 = residue_1['N'] 
                atom_2 = residue_1['CA'] 
                distance = atom_1-atom_2 
                #print atom.get_vector(),atom.name,distance
                print distance
                i=i+1

#lines = loadtxt("file_ubq")

我在文件'file_ubq'中得到了输出,如下所示:

1.47369
1.4966
1.47547
1.51187
1.44885
1.50423
1.47052
1.48006
1.50265
.
.
.
.
1.48417
1.47194
1.45661
1.47023

但除此之外,我也遇到了如下错误:

    return self.child_dict[id]
KeyError: (' ', 77, ' ')

----------------------------------------------
Program exited successfully with errcode (1)
Press the Enter key to close this terminal ... 
EXECUTING:
/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py 
----------------------------------------------
Traceback (most recent call last):
  File "/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py", line 38, in <module>
    residue_1 = chain[i] 
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Chain.py", line 67, in __getitem__
    return Entity.__getitem__(self, id)
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Entity.py", line 38, in __getitem__
    return self.child_dict[id]
KeyError: (' ', 77, ' ')

----------------------------------------------
Program exited successfully with errcode (1)
Press the Enter key to close this terminal ... 

EXECUTING:
/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py 
----------------------------------------------
Traceback (most recent call last):
  File "/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py", line 38, in <module>
    residue_1 = chain[i] 
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Chain.py", line 67, in __getitem__
    return Entity.__getitem__(self, id)
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Entity.py", line 38, in __getitem__
    return self.child_dict[id]
KeyError: (' ', 77, ' ')

----------------------------------------------
Program exited successfully with errcode (1)
Press the Enter key to close this terminal ... 
^CEXECUTING:
/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py 
----------------------------------------------
Traceback (most recent call last):
  File "/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py", line 38, in <module>
    residue_1 = chain[i] 
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Chain.py", line 67, in __getitem__
    return Entity.__getitem__(self, id)
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Entity.py", line 38, in __getitem__
    return self.child_dict[id]
KeyError: (' ', 77, ' ')

----------------------------------------------
Program exited successfully with errcode (1)
Press the Enter key to close this terminal ... 
EXECUTING:
/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py 
----------------------------------------------
Traceback (most recent call last):
  File "/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py", line 38, in <module>
    residue_1 = chain[i] 
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Chain.py", line 67, in __getitem__
    return Entity.__getitem__(self, id)
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Entity.py", line 38, in __getitem__
    return self.child_dict[id]
KeyError: (' ', 77, ' ')

----------------------------------------------
Program exited successfully with errcode (1)
Press the Enter key to close this terminal ... 

EXECUTING:
/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py 
----------------------------------------------
Traceback (most recent call last):
  File "/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py", line 38, in <module>
    residue_1 = chain[i] 
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Chain.py", line 67, in __getitem__
    return Entity.__getitem__(self, id)
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Entity.py", line 38, in __getitem__
    return self.child_dict[id]
KeyError: (' ', 77, ' ')

----------------------------------------------
Program exited successfully with errcode (1)
Press the Enter key to close this terminal ... 

EXECUTING:
/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py 
----------------------------------------------
Traceback (most recent call last):
  File "/home/devanandt/Documents/PYTHON/ubq/src/ubq_dist_pdf.py", line 38, in <module>
    residue_1 = chain[i] 
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Chain.py", line 67, in __getitem__
    return Entity.__getitem__(self, id)
  File "/usr/lib/pymodules/python2.7/Bio/PDB/Entity.py", line 38, in __getitem__
    return self.child_dict[id]
KeyError: (' ', 77, ' ')

----------------------------------------------
Program exited successfully with errcode (1)
Press the Enter key to close this terminal ... 

谁能帮我理解和解决这个错误?

4

3 回答 3

3

您的代码有几个问题。

  1. 您正在使用文件句柄重载 sys.stdout,以便您可以写入文件。你可以简单地做:
f_handle = open('random.pdb', 'w')
print >>f_handle, "This will be written to the file, followed by a newline character"
  1. 您可以更好地访问 Structure 对象和相应的子对象(Chain、Residue 等),请阅读一些常见问题解答以更好地了解该库。您可能达到了链的极限(76 个残基)并尝试寻找第 77 个残基,因为您正在使用计数器来访问残基。Biopython 在 Structure、Chain 等对象中实现了迭代器,所以你可以说“for x in object”并遍历它的子对象。要打印每个链中 N 和 Ca 原子之间的距离,请执行以下操作:
parser = PDBParser()
structure = parser.get_structure('randomPDB', 'randomPDB.pdb')
for model in structure:
    for chain in model:
        for residue in chain:
            if residue.id[1] == ' ': # filters heteroatoms
                resid = residue.id[0]
                n_ca_dist = residue['N'] - residue['CA']
                print >>f_handle, "Distance N-Ca bond of residue {0}: {1}".format(resid, n_ca_dist)
于 2014-10-05T12:30:22.197 回答
1

好的,这段代码修复了错误:

import sys
#from Bio.PDB import *
from Bio.PDB.PDBParser import PDBParser 
from numpy import loadtxt

pdb1 ='1UBQ.pdb'
sys.stdout = open('file_ubq', 'w')
parser=PDBParser(PERMISSIVE=1)

#file=open('1UBQ.pdb','r')
#header_dict=parse_pdb_header(file)
#file.close()
i=1
structure = parser.get_structure('1UBQ',pdb1)
for model in structure:
    for chain in model:
        for residue in chain:
            i = 1
            for atom in residue:
                model = structure[0] 
                chain = model['A'] 
                residue_1 = chain[i] 
                atom_1 = residue_1['N'] 
                atom_2 = residue_1['CA'] 
                distance = atom_1-atom_2 
                #print atom.get_vector(),atom.name,distance
                print distance
                i=i+1

#lines = loadtxt("file_ubq")

但是,它似乎包含许多重复的结果,并且可能无法覆盖整个链。此代码不应包含重复项:

import sys
from Bio.PDB.PDBParser import PDBParser 
from numpy import loadtxt

pdb1 ='1UBQ.pdb'
sys.stdout = open('file_ubq', 'w')
parser=PDBParser(PERMISSIVE=1)

structure = parser.get_structure('1UBQ',pdb1)
for model in structure:
    for chain in model:
        for residue in chain:
            try:
                atom_1 = residue['N'] 
                atom_2 = residue['CA'] 
                distance = atom_1-atom_2 
                print distance
            except:
                pass

它也只产生 76 个结果,这是链的长度。告诉我是否有任何问题,因为我以前没有使用biopython过。

于 2014-10-04T17:36:49.160 回答
-1
import sys
#from Bio.PDB import *
from Bio.PDB.PDBParser import PDBParser 
from numpy import loadtxt

pdb1 ='1UBQ.pdb'
sys.stdout = open('file_ubq', 'w')
parser=PDBParser(PERMISSIVE=1)

#file=open('1UBQ.pdb','r')
#header_dict=parse_pdb_header(file)
#file.close()
i=1
structure = parser.get_structure('1UBQ',pdb1)
for model in structure:
    for chain in model:
        for residue in chain:
            i = 1
            for atom in residue:
                model = structure[0] 
                chain = model['A'] 
                residue_1 = chain[i] 
                atom_1 = residue_1['N'] 
                atom_2 = residue_1['CA'] 
                distance = atom_1-atom_2 
                #print atom.get_vector(),atom.name,distance
                print distance
                i=i+1

#lines = loadtxt("file_ubq")

This might help you 
于 2020-12-17T06:47:13.303 回答