Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug identified at PDBIO.set_structure() and solution for it #2995

Closed
alexandrefassio opened this issue Jun 23, 2020 · 2 comments · Fixed by #3006
Closed

Bug identified at PDBIO.set_structure() and solution for it #2995

alexandrefassio opened this issue Jun 23, 2020 · 2 comments · Fixed by #3006
Assignees
Labels

Comments

@alexandrefassio
Copy link

Hi,

In the current BioPython version, there are two bugs (lines 86 and 95) in the function set_structure() from the class PDBIO (Bio/PDB/PDBIO.py):

       Line 86: sb.structure[0]["A"].add(pdb_object.copy())
       Line 95: sb.structure[0]["A"].child_list[0].add(pdb_object.copy())

As you can see, it always tries to access a chain object whose id is "A". However, if one tries to save a Residue/Atom whose chain id is not "A", it raises a KeyError exception because the recently created chain (line 79) had its id updated to pdb_object.parent.id at line 83 (when pdb_object is a residue) or 92 (when pdb_object is an atom).

Thus, to fix this problem, move the parent_id to outside the try/except block and substitute the previous lines by

       Line 86: sb.structure[0][parent_id].add(pdb_object.copy())
       Line 95: sb.structure[0][parent_id].child_list[0].add(pdb_object.copy())

bests

@JoaoRodrigues
Copy link
Member

JoaoRodrigues commented Jun 23, 2020

Hi @alexandrefassio thanks for catching this. Would you be willing to submit a pull request on this?

@JoaoRodrigues JoaoRodrigues self-assigned this Jun 24, 2020
@alexandrefassio
Copy link
Author

Hi @JoaoRodrigues

Sure! I can do it.

JoaoRodrigues added a commit to JoaoRodrigues/biopython that referenced this issue Jun 26, 2020
JoaoRodrigues added a commit to JoaoRodrigues/biopython that referenced this issue Jun 26, 2020
@JoaoRodrigues JoaoRodrigues mentioned this issue Jun 26, 2020
3 tasks
@JoaoRodrigues JoaoRodrigues linked a pull request Jun 26, 2020 that will close this issue
3 tasks
JoaoRodrigues added a commit that referenced this issue Aug 13, 2020
* PDBIO should not assume default chain is A: #2995

* Added tests for PDBIO set_structure and object building: #2995
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants