Skip to content

Bio.PDB.PDBIO.save() - increment serial number of the TER record #1383

Open

Description

@ChristopheDeprez

Setup

I am reporting a problem with Biopython version 1.70

Expected behaviour

When writing out in PDB format, the serial number of the TER record should be one number greater than the serial number of the ATOM/HETATM preceding the TER.

Reference: http://www.wwpdb.org/documentation/file-format-content/format33/sect9.html#TER

Actual behaviour

When writing out in PDB format with preserve_atom_numbering = True, the serial number of the TER record is the same as the serial number of the ATOM/HETATM preceding the TER.

Proposed Solution:

Write out the TER record with an incremented atom_number.

--- Bio/PDB/PDBIO.py    2017-09-01 14:42:30.000000000 -0400
+++ Bio/PDB/PDBIO.py    2017-09-01 14:53:45.000000000 -0400
@@ -222,7 +222,7 @@
                                 atom_number += 1
                 if chain_residues_written:
                     fp.write("TER   %5i      %3s %c%4i%c                                                      \n"
-                             % (atom_number, resname, chain_id, resseq, icode))
+                             % (atom_number + 1, resname, chain_id, resseq, icode))
 
             if model_flag and model_residues_written:
                 fp.write("ENDMDL\n")

Licensing:

I agree to the current contribution being dual licensed under both the original "Biopython License Agreement" and the more widely used "3-Clause BSD License".

Activity

  1. changed the title [-]Bio.PDB.PDBIO.py - increment serial number of the TER record[/-] [+]Bio.PDB.PDBIO.save() - increment serial number of the TER record[/+] on Sep 1, 2017
  2. peterjc commented on Sep 1, 2017

    @peterjc
    Member

    @lennax could you look at this please?

    Cross reference 7e185d8

  3. JoaoRodrigues commented on Sep 4, 2017

    @JoaoRodrigues
    Member

    This will actually cause the TER statement and the the ATOM record right after to have the same serial number. Also needs to account for when we want to preserve numbering (how do we preserve numbering then if we add statements is another very good question).

  4. ChristopheDeprez commented on Sep 5, 2017

    @ChristopheDeprez
    Author

    You're right, I was only considering the "preserve_atom_numbering" case!
    In the not "preserve_atom_numbering" case, the serial number should be incremented after writing each record (after writing the TER as well as after writing the ATOM/HETATM records). I guess the following patch would cover both cases, because in the "preserve_atom_numbering" case, the serial number of the ATOM/HETATM records gets overwritten anyways. This assumes correct numbering of the TER record in the original PDB.

    --- PDBIO.py       2017-09-01 14:33:42.000000000 -0400
    +++ PDBIO.py    2017-09-05 09:12:25.000000000 -0400
    @@ -218,11 +218,11 @@
                                 s = get_atom_line(atom, hetfield, segid, atom_number, resname,
                                                   resseq, icode, chain_id)
                                 fp.write(s)
    -                            if not preserve_atom_numbering:
    -                                atom_number += 1
    +                            atom_number += 1
                     if chain_residues_written:
                         fp.write("TER   %5i      %3s %c%4i%c                                                      \n"
                                  % (atom_number, resname, chain_id, resseq, icode))
    +                    atom_number += 1
     
                 if model_flag and model_residues_written:
                     fp.write("ENDMDL\n")
    
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions