使用 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
但是这段代码不起作用并引发了错误
def detach_child(self, id):
"Remove a child."
child=self.child_dict[id]
KeyError: '105'
这段代码有什么问题?
或者,我可以使用 accept_residue() 并将其写入 PDB。我不想这样做,因为我想在内存中进行进一步处理。