Skip to content

PDBConstructionWarning and PDBIOWarning need silencing in tests #5082

Closed

Description

@peterjc
test_PDB_PDBIO ... /Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'NA' for Atom (name=NA) with given element 'A'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
  warnings.warn(
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
  warnings.warn(
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
  warnings.warn(
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
  warnings.warn(
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
  warnings.warn(
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
  warnings.warn(msg, PDBConstructionWarning)
/Users/peterjc/miniforge3/envs/pyani-plus_py312/lib/python3.12/site-packages/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
  warnings.warn(
ok

The PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E' ones are a very old warning, so this is likely from adding a new test PDB file, and was missed in review.

The PDBIOWarning: Truncated bfactor ones are likely from #5047 and missed in review.

Activity

  1. added
    good first issue
    on Oct 15, 2025
  2. peterjc commented on Oct 15, 2025

    @peterjc
    MemberAuthor

    The fix should be something like 758c6ae where these warnings are triggered.

  3. sneharaghuram commented on Oct 23, 2025

    @sneharaghuram

    Hello, I'm a first time contributor (but used BioPython before) and would like to be assigned this issue, if it hasn't gone to someone else already.

  4. peterjc commented on Oct 23, 2025

    @peterjc
    MemberAuthor

    Great - please have a go @sneharaghuram - thanks!

  5. peterjc commented on Oct 28, 2025

    @peterjc
    MemberAuthor

    To narrow down where the warnings are from, run the problem file directly (in the tests directory):

    ❯ python test_PDB_PDBIO.py
    /Users/peterjc/repositories/biopython/Bio/__init__.py:138: BiopythonWarning: You may be importing Biopython from inside the source tree. This is bad practice and might lead to downstream issues. In particular, you might encounter ImportErrors due to missing compiled C extensions. We recommend that you try running your code from outside the source tree. If you are outside the source tree then you have a setup.py file in an unexpected directory: /Users/peterjc/repositories/biopython
      warnings.warn(
    test_model_numbering (__main__.WriteTest.test_model_numbering)
    Preserve model serial numbers during I/O. ... /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'NA' for Atom (name=NA) with given element 'A'
      warnings.warn(msg, PDBConstructionWarning)
    ok
    test_pdbio_missing_occupancy (__main__.WriteTest.test_pdbio_missing_occupancy)
    Write PDB file with missing occupancy. ... ok
    test_pdbio_pdb_format_limits (__main__.WriteTest.test_pdbio_pdb_format_limits)
    Test raising error when structure cannot meet PDB format limits. ... ok
    test_pdbio_revert_write_on_file_handle_1 (__main__.WriteTest.test_pdbio_revert_write_on_file_handle_1)
    Test removing file when exception is caught (handle). ... ok
    test_pdbio_revert_write_on_file_handle_2 (__main__.WriteTest.test_pdbio_revert_write_on_file_handle_2)
    Test removing file when exception is caught (handle + data). ... ok
    test_pdbio_revert_write_on_filename (__main__.WriteTest.test_pdbio_revert_write_on_filename)
    Test removing file when exception is caught (string). ... ok
    test_pdbio_select (__main__.WriteTest.test_pdbio_select)
    Write a selection of the structure using a Select subclass. ... ok
    test_pdbio_write_auto_numbering (__main__.WriteTest.test_pdbio_write_auto_numbering)
    Test writing PDB and do not preserve atom numbering. ... /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    ok
    test_pdbio_write_custom_residue (__main__.WriteTest.test_pdbio_write_custom_residue)
    Write a chainless residue using PDBIO. ... ok
    test_pdbio_write_high_b_factor (__main__.WriteTest.test_pdbio_write_high_b_factor) ... /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    ok
    test_pdbio_write_preserve_numbering (__main__.WriteTest.test_pdbio_write_preserve_numbering)
    Test writing PDB and preserve atom numbering. ... /Users/peterjc/repositories/biopython/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
      warnings.warn(
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    ok
    test_pdbio_write_residue (__main__.WriteTest.test_pdbio_write_residue)
    Write a single residue using PDBIO. ... /Users/peterjc/repositories/biopython/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
      warnings.warn(
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    ok
    test_pdbio_write_residue_w_chain (__main__.WriteTest.test_pdbio_write_residue_w_chain)
    Write a single residue (chain id == X) using PDBIO. ... /Users/peterjc/repositories/biopython/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
      warnings.warn(
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    ok
    test_pdbio_write_residue_wout_chain (__main__.WriteTest.test_pdbio_write_residue_wout_chain)
    Write a single orphan residue using PDBIO. ... /Users/peterjc/repositories/biopython/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
      warnings.warn(
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    ok
    test_pdbio_write_structure (__main__.WriteTest.test_pdbio_write_structure)
    Write a full structure using PDBIO. ... /Users/peterjc/repositories/biopython/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
      warnings.warn(
    /Users/peterjc/repositories/biopython/Bio/PDB/Atom.py:237: PDBConstructionWarning: Used element 'SE' for Atom (name=SE) with given element 'E'
      warnings.warn(msg, PDBConstructionWarning)
    ok
    test_pdbio_write_truncated (__main__.WriteTest.test_pdbio_write_truncated)
    Test parsing of truncated lines. ... /Users/peterjc/repositories/biopython/Bio/PDB/PDBIO.py:50: PDBIOWarning: Truncated bfactor 1000009 to 999999 to fit wwPDB spec. Consider using mmCIF instead!
      warnings.warn(
    ok
    test_pdbio_write_unk_element (__main__.WriteTest.test_pdbio_write_unk_element)
    PDBIO raises PDBIOException when writing unrecognised atomic elements. ... ok
    test_pdbio_write_x_element (__main__.WriteTest.test_pdbio_write_x_element)
    Write a structure with atomic element X with PDBIO. ... ok
    
    ----------------------------------------------------------------------
    Ran 18 tests in 0.085s
    
    OK
    

    So lots, but most in test_pdbio_write_high_b_factor.

  6. peterjc commented on Oct 28, 2025

    @peterjc
    MemberAuthor

    This suppresses the warnings in that test:

    ❯ git diff
    diff --git a/Tests/test_PDB_PDBIO.py b/Tests/test_PDB_PDBIO.py
    index 2ad9d9cbc..20a3deefe 100644
    --- a/Tests/test_PDB_PDBIO.py
    +++ b/Tests/test_PDB_PDBIO.py
    @@ -385,6 +385,8 @@ class WriteTest(unittest.TestCase):
    
         def test_pdbio_write_high_b_factor(self):
             def check_pdb(filename, expected_bfactor):
    -            struct = self.parser.get_structure("high_b", filename)
    +            with warnings.catch_warnings():
    +                # Used element 'SE' for Atom (name=SE) with given element 'E'
    +                warnings.simplefilter("ignore", PDBConstructionWarning)
    +                struct = self.parser.get_structure("high_b", filename)
                 atom = next(struct.get_atoms())
                 self.assertEqual(atom.bfactor, expected_bfactor)
    

    I couldn't work out if warnings.filterwarning could be used instead with a regex to match Used element 'SE' for Atom (name=SE) with given element 'E' which would be more specific.

  7. peterjc commented on Oct 28, 2025

    @peterjc
    MemberAuthor

    I ended up doing this myself as I wanted it fixed for #5062, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions