Skip to content

PDBIo error when saving chain with more than one character #3438

Closed

Description

@saiden89

Setup

I am reporting a problem with Biopython version, Python version, and operating
system as follows:

import sys; print(sys.version)
import platform; print(platform.python_implementation()); print(platform.platform())
import Bio; print(Bio.__version__)

3.8.6 | packaged by conda-forge | (default, Nov 27 2020, 19:31:52) 
[GCC 9.3.0]
CPython
Linux-5.8.0-31-generic-x86_64-with-glibc2.10
1.78

Expected behaviour

Using PDBio.save to save any chain that has more than one character as identifier should work, regardless on the length of the chain id.

Actual behaviour

When subclassing Select for chain extraction, and using PDBio for saving, an exception is raised as follows.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PDBIO.py", line 370, in save
    s = get_atom_line(
  File "PDBIO.py", line 229, in _get_atom_line
    return _ATOM_FORMAT_STRING % args
TypeError: %c requires int or char

Steps to reproduce

Minimal code to reproduce:

from Bio.PDB import PDBList, PDBIO, FastMMCIFParser, Select

class ChainSelect(Select):
    def __init__(self, chain):
        self.chain = chain

    def accept_chain(self, chain):
        if chain.get_id() == self.chain:
            return 1
        else:
            return 0

pdbl = PDBList()
io = PDBIO()
parser = FastMMCIFParser(QUIET=True)

pdbl.retrieve_pdb_file('6kmw', pdir='.', file_format='mmCif')
structure = parser.get_structure('6kmw', '6kmw.cif')
io.set_structure(structure)
io.save('6kmw_aA.pdb', ChainSelect('aA'))

Activity

  1. peterjc commented on Dec 9, 2020

    @peterjc
    Member

    Reminds me of the discussion on #3250 and #3262 - can you look at this @JoaoRodrigues ?

  2. JoaoRodrigues commented on Dec 9, 2020

    @JoaoRodrigues
    Member

    Thanks for the ping @peterjc .

    I disagree that this use case "should work, regardless of the length of the chain id". The PDB format allows for one character in that field, so what would you do then? Truncate and issue a warning? I prefer to explicitly throw an exception (probably a more informative one) and let the user change the chain id themselves before extracting.

  3. saiden89 commented on Dec 9, 2020

    @saiden89
    Author

    You are absolutely right, I forgot that when using PDBIO the output file must comply to the PDB file format.
    It would still be nice to have a more informative exception though.
    Thank you very much for the clarification.

  4. JoaoRodrigues commented on Dec 9, 2020

    @JoaoRodrigues
    Member

    More informative exception it is then :) I'll push it through this afternoon.

  5. added a commit that references this issue on Aug 1, 2021
    bda5056
  6. self-assigned this
    on Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions