我使用biopython找到两个残基的C alpha原子之间的距离,并且我不断收到错误。这是我的代码和错误:
```
>>> 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'
>>>
```
这是否与&#34; get_structure_from_url&#34;有关? MMTFParser的方法? 我已经用PDBParser()。get_structure尝试了这个,它工作得很好。
答案 0 :(得分:2)
Biopython的原子类有一个自定义减法方法。
来自source code:
for i, name in enumerate(files):
os.rename(os.path.join(path, name), os.path.join(path, '{}.mp4'.format(names[i])))
对于MMTFParser,此功能似乎缺失,但您可以轻松自行完成。
MMTFParser将坐标作为列表(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))
,line 53)读取,这与PDBParser不同,PDBParser将坐标读取为Numpy数组(init_atom(str(atom_name), [x, y, z] ...
,line 187)。
为了获得距离,您可以将坐标列表转换为Numpy数组,然后计算距离。
coord = numpy.array((x, y, z), "f")