我有一个 PDB 文件列表。我想通过使用 BioPython 的 Bio.PDB 模块提取所有文件的配体(因此,杂原子)并将每个文件分别保存到 PDB 文件中。
我尝试了一些解决方案,例如:Remove heteroatoms from PDB,我试图对其进行调整以保留杂原子。但我得到的只是所有配体都在同一个文件中的文件。
我也尝试过这样的事情:
def accept_residue(residue):
""" Recognition of heteroatoms - Remove water molecules """
res = residue.id[0]
if res != " ": # Heteroatoms have some flags, that's why we keep only residue with id != " "
if res != "W": # Don't take in consideration the water molecules
return True
def extract_ligands(path):
""" Extraction of the heteroatoms of .pdb files """
for element in os.listdir(path+'/data/pdb'):
i=1
if element.endswith('.pdb'):
if not element.startswith("lig_"):
pdb = PDBParser().get_structure(element[:-4], path+'/data/pdb/'+element)
io = PDBIO()
io.set_structure(pdb)
for model in pdb:
for chain in model:
for residue in chain:
if accept_residue(residue):
io.save("lig_"+element[:-4]+"_"+str(i)+".pdb", accept_residue(residue))
i += 1 # Counter for the result filename
# Main
path = mypath
extract_ligands(path)
显然,它引发了一个错误:
AttributeError: 'bool' object has no attribute 'accept_model'
我知道这是因为我的“io.save”中的“accept_residue()”。但我没有找到任何合乎逻辑的解决方案来做我想做的事......
最后,我尝试了一个像这样的解决方案,使用 chain.detach_child() :
...
for chain in model:
for residue in chain:
res = residue.id[0]
if res == " " or res == "W":
chain.detach_child(residue.id)
if len(chain) == 0:
model.detach_child(chain.id)
...
在我看来,它会“分离”所有不是杂原子的残基( res.id[0] == " " )和所有的水( res.id[0] == "W")。但总的来说,所有的残留物和水仍然存在并且有缺陷。
那么,有可能做我需要的吗?(从我的所有文件中提取所有配体并分别保存在PDB文件中)
(抱歉我的英语不好,最终我的 Python 技能不好:/)