2014-10-04 130 views
0

我想繪製一個分佈alpha-cabonnitrogen鍵距離的泛素蛋白。所以我下載了1UBQ.pdb from RCSB website。現在使用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 ... 

任何人都可以幫助我理解和解決這個錯誤嗎?

+0

但我必須在循環權增加,從而得到76米殘渣鍵長。我注意到錯誤從第77個水分子點開始。 – dexterdev 2014-10-04 16:08:10

+0

沒有它的不工作 – dexterdev 2014-10-04 16:20:51

+0

你問的pdb文件或程序。 – dexterdev 2014-10-04 17:03:40

回答

1

OK,這個代碼修正錯誤:

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

+0

感謝您的努力。我會嘗試這個代碼。我是初學Python和第一次嘗試使用biopython:P – dexterdev 2014-10-04 17:39:36

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" 
  • 您對結構對象和相應的兒童(鏈,殘渣等)接入可以做的更好,讀了一下常見問題解答更好地瞭解圖書館。您可能達到了鏈的極限(76個殘基),並嘗試尋找第77個殘基,因爲您正在使用計數器來訪問殘基。 Biopython在結構,鏈接等對象中實現了迭代器,因此您可以只說'用於對象中的x'並覆蓋其子元素。要打印在每個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) 
    
    +0

    謝謝,我改變了這些。 – dexterdev 2014-10-05 17:36:30

    相關問題