我最近的任务是在python中编写一个程序,找到距离.pdb(蛋白质数据库)蛋白质中每种金属2埃范围内的原子。这是我为它写的脚本。
from Bio.PDB import *
parser = PDBParser(PERMISSIVE=True)
def print_coordinates(list):
neighborList = list
for y in neighborList:
print " ", y.get_coord()
structure_id = '5m6n'
fileName = '5m6n.pdb'
structure = parser.get_structure(structure_id, fileName)
atomList = Selection.unfold_entities(structure, 'A')
ns = NeighborSearch(atomList)
for x in structure.get_atoms():
if x.name == 'ZN' or x.name == 'FE' or x.name == 'CU' or x.name == 'MG' or x.name == 'CA' or x.name == 'MN':
center = x.get_coord()
neighbors = ns.search(center,2.0)
neighborList = Selection.unfold_entities(neighbors, 'A')
print x.get_id(), ': ', neighborList
print_coordinates(neighborList)
else:
continue
但这仅适用于单个.pdb文件,我希望能够读取它们的整个目录。由于我直到现在才使用Java,我不完全确定如何在Python 2.7中实现这一点。我的一个想法是,我会将脚本放在try catch语句中,然后放入while循环,然后在它到达结尾时抛出异常,但这就是我将如何在Java中完成的,不知道我将如何在Python中做到这一点。所以我很乐意听到任何人可能有的想法或示例代码。