Using biopython library, I want to remove the residues that are listed in list as follows. This thread (http://pelican.rsvs.ulaval.ca/mediawiki/index.php/Manipulating_PDB_files_using_BioPython) provides an example to remove residue. I have following code to remove residues
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
But this code did not work and raised the error
def detach_child(self, id):
"Remove a child."
child=self.child_dict[id]
KeyError: '105'
What's wrong with this code?
Alternatively, I can do using accept_residue() and write it in PDB. I don't want to follow like this becauseI want to do it while in memory for further processing.