2017-11-17 51 views
1

我正在使用biopython來查找兩個殘基的C原子之間的距離,並且不斷收到錯誤。這裏是我的代碼和錯誤:Biopython:MMTFParser找不到原子之間的距離

```

>>> from Bio.PDB.mmtf import MMTFParser 
>>> structure = MMTFParser.get_structure_from_url('4mne') 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:89: PDBConstructionWarning: WARNING: Chain A is discontinuous at line 0. 
    PDBConstructionWarning) 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:89: PDBConstructionWarning: WARNING: Chain D is discontinuous at line 0. 
    PDBConstructionWarning) 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:89: PDBConstructionWarning: WARNING: Chain E is discontinuous at line 0. 
    PDBConstructionWarning) 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:89: PDBConstructionWarning: WARNING: Chain F is discontinuous at line 0. 
    PDBConstructionWarning) 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:89: PDBConstructionWarning: WARNING: Chain H is discontinuous at line 0. 
    PDBConstructionWarning) 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:89: PDBConstructionWarning: WARNING: Chain B is discontinuous at line 0. 
    PDBConstructionWarning) 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:89: PDBConstructionWarning: WARNING: Chain C is discontinuous at line 0. 
    PDBConstructionWarning) 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:89: PDBConstructionWarning: WARNING: Chain G is discontinuous at line 0. 
    PDBConstructionWarning) 
>>> for c in structure.get_chains(): 
...  if c.get_id() == 'B': 
...    chain = c 
... 
>>> chain 
<Chain id=B> 
>>> CAatoms = [a for a in chain.get_atoms() if a.id == 'CA'] 
>>> for a in CAatoms: 
...  for b in CAatoms: 
...    distance = a-b 
... 
Traceback (most recent call last): 
    File "<stdin>", line 3, in <module> 
    File "/Library/Python/2.7/site-packages/Bio/PDB/Atom.py", line 124, in __sub__ 
    diff = self.coord - other.coord 
TypeError: unsupported operand type(s) for -: 'list' and 'list' 
>>> 

```

這是否有東西做的MMTFParser的 「get_structure_from_url」 的方法? 我試過用PDBParser()。get_structure,它工作正常。

回答

1

Biopython的atom類有一個自定義的減法方法。

source code

def __sub__(self, other): 
    """Calculate distance between two atoms. 
    :param other: the other atom 
    :type other: L{Atom} 
    Examples 
    -------- 
    >>> distance = atom1 - atom2 
    """ 
    diff = self.coord - other.coord 
    return numpy.sqrt(numpy.dot(diff, diff)) 

對於MMTFParser這個功能似乎缺少,但你可以輕鬆地做自己。

MMTFParser讀取的座標爲列表(init_atom(str(atom_name), [x, y, z] ...line 53),不像PDBParser讀取的座標作爲numpy的陣列(coord = numpy.array((x, y, z), "f")line 187)。

爲了獲得距離,您可以將座標列表轉換爲Numpy數組,然後計算距離。

import numpy as np 
distance = np.linalg.norm(np.array(a.coord) - np.array(b.coord)) 
+0

謝謝!我想知道MMTFParser是否沒有這個功能,或者只是我做錯了什麼。 –

+0

@ M.Iyer:查看更新後的答案,這是一個執行錯誤,我將在接下來的幾天內打開一個拉取請求。 –

+2

@ M.lyer:錯誤修復已實施,可能會成爲下一個版本的一部分:https://github.com/biopython/biopython/pull/1456 –