<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Also, the detach_child method should work in place, so I’m not sure why this is not working. Can you give an example PDB?<div class=""><br class=""></div><div class="">Jordan<br class=""><div><blockquote type="cite" class=""><div class="">On Nov 25, 2015, at 12:16 PM, Claudia Millán Nebot <<a href="mailto:cmncri@ibmb.csic.es" class="">cmncri@ibmb.csic.es</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="">Dear all,<br class=""><br class=""></div>I am writing a function that examines a structure, and if there are discontinuous regions that are smaller than a certain size, they will be removed from the structure. Then, I would like to write the structure as a pdb in which the chain identifiers are different for each discontinuous fragment. For that purpose, I want to change the chain id of certain residues. ¿What will be the best way to do it? Because right now it is not working, of course, because I am iterating over something that I am trying to change at the same time. Maybe I am missing something very obvious or straightforward, but I do not see what will be the best way to do it... ¿Maybe creating and empty chain and using the set_parent method?<br class=""><br class="">The current code looks like this:<br class="">def trimByContinuityLimit(pdb_file,min_size):<br class="">    parser=PDBParser()<br class="">    structure=parser.get_structure(pdb_file[:-4],pdb_file)<br class="">    residues=Selection.unfold_entities(structure,'R')<br class="">    list_id="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"<br class="">    dictio_chainid={}<br class="">    residues_to_remove=[]<br class="">    current_listres=[]<br class="">    index=0<br class="">    for i in range(len(residues)-1):<br class="">        res1=residues[i]<br class="">        res2=residues[i+1]<br class="">        id1=<a href="http://res1.id/" class="">res1.id</a><br class="">        id2=<a href="http://res2.id/" class="">res2.id</a><br class="">        check=Bioinformatics.checkContinuity(res1,res2)<br class="">        #print 'check',check<br class="">        #print 'list_id[index]',list_id[index]<br class="">        if check==True:<br class="">            #print "These two residues are consecutive",res1,res2<br class="">            if id1 not in current_listres:<br class="">                current_listres.append(id1)<br class="">            dictio_chainid[id1]=list_id[index]<br class="">            if id2 not in current_listres:<br class="">                current_listres.append(id2)<br class="">            dictio_chainid[id2]=list_id[index]<br class="">            #print 'list_id[index]',list_id[index]<br class="">            #print 'id1,dictio_chainid[id1]',dictio_chainid[id1],id1<br class="">            #print 'id2,dictio_chainid[id2]',dictio_chainid[id2],id2<br class="">        elif check==False:<br class="">            #print "These two residues are not consecutive",res1,res2<br class="">            if id1 not in current_listres:<br class="">               current_listres.append(id1)<br class="">               dictio_chainid[id1]=list_id[index]<br class="">            if len(current_listres)<min_size:<br class="">               residues_to_remove.extend(current_listres)<br class="">            if i==len(residues)-2 and min_size>1: # If we reach this point, then the last residue is not continuous so it is single :<br class="">               residues_to_remove.append(id2)<br class="">            else:<br class="">               current_listres=[]<br class="">               current_listres.append(id2)<br class="">               index=index+1<br class="">               dictio_chainid[id2]=list_id[index]<br class="">    # Remove the residues and write the pdb<br class="">    for model in structure:<br class="">       for chain in model:<br class="">           for residue in chain:<br class="">               id_res=<a href="http://residue.id/" class="">residue.id</a><br class="">               if id_res in residues_to_remove:<br class="">                   chain.detach_child(id_res)<br class="">               else:<br class="">                   <a href="http://chain.id/" class="">chain.id</a>=dictio_chainid[id_res]<br class="">    io=PDBIO()<br class="">    io.set_structure(structure)<br class="">    io.save(pdb_file[:-4]+'_trimmed.pdb',write_end=False)<br class=""><br class=""></div>Thanks in advance :)<br class=""><br class=""></div>Claudia<br class=""></div>
_______________________________________________<br class="">Biopython mailing list  -  <a href="mailto:Biopython@mailman.open-bio.org" class="">Biopython@mailman.open-bio.org</a><br class=""><a href="http://mailman.open-bio.org/mailman/listinfo/biopython" class="">http://mailman.open-bio.org/mailman/listinfo/biopython</a></div></blockquote></div><br class=""></div></body></html>