利用Biopython库去除PDB中的残留物

2024-06-01 03:35:27 发布

您现在位置:Python中文网/ 问答频道 /正文

使用biopython库,我想删除列表中列出的残留物,如下所示。这个线程(http://pelican.rsvs.ulaval.ca/mediawiki/index.php/Manipulating_PDB_files_using_BioPython)提供了一个移除残留物的示例。我有以下代码来清除残留物

 residue_ids_to_remove = [105, 5, 8, 10, 25, 48]
 structure = pdbparser.get_structure("3chy", "./3chy.pdb")
 first_model = structure[0]
 for chain in first_model:
     for residue in chain:
         id = residue.id
         if id[1] in residue_ids_to_remove:
             chain.detach_child(id[1])
 modified_first_model = first_model 

但这段代码不起作用并引发了错误

^{pr2}$

这个密码怎么了?在

或者,我可以使用accept_remainment()并将其写入PDB。我不想这样做,因为我想在内存中进行下一步处理。在


Tags: to代码inididschainformodel
1条回答
网友
1楼 · 发布于 2024-06-01 03:35:27

Biopython无法在内部字典中找到链的密钥,因为您提供的是随机密钥。dict看起来像这样:

child_dict = {(' ', 5, ' '): <Residue HOH het=W resseq=5 icode= >,
              (' ', 6, ' '): <Residue HOH het=W resseq=6 icode= >,
              (' ', 7, ' '): <Residue HOH het=W resseq=7 icode= >}

即:使用元组作为dict键。您可以看到dict正在print chain.child_dict。在

一旦你知道了这一点,错误/解决方案就一目了然了。向detach_child传递一个有效密钥,即删除[1]

^{pr2}$

正确的方法

将子级与链级分离,不要直接循环残留物:

for chain in first model:
    for id in residue_ids_to_remove:
        chain.detach_child((' ', id, ' '))

或列表理解:

for chain in first_model:
    [chain.detach_child((' ', id, ' ')) for id in residue_ids_to_remove]

相关问题 更多 >