Skip to content

Pdb residue string - #3676

Open
rob-miller wants to merge 5 commits into
biopython:masterfrom
rob-miller:pdb-residue-string
Open

rob-miller wants to merge 5 commits into
biopython:masterfrom
rob-miller:pdb-residue-string

Conversation

@rob-miller

Copy link
Copy Markdown
Contributor
  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file, have run pre-commit locally,
    and understand that AppVeyor and TravisCI will be used to confirm the Biopython unit
    tests and style checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

This patch exposes functionality in PDBIO to generate a string for a single residue in PDB or PQR format. The primary new functionality over the 'selector' mechanism is that residues can be generated with arbitrary chain IDs. Relevant test code is added.

Less significant features are accessing as a string instead of e.g. using io.StringIO, documenting the preserve_atom_numbering parameter, addressing #1383, and minor cleanup of the PDBIO tests.

This functionality enables generating non-standard 'PDB' files like the attached for investigating residue sidechain interactions. (suggest 'color by chain' if you load this into a viewer; each 'chain' is a group of potentially interacting PHE residues, with one member of each group superimposed on the N-CA-CB plane.)
phe-pair.pdb.gz

With respect to #1383, the discussion appears to have stopped with the question of 'what to do if preserve_atom_numbering=True'. I submit that this is not the default case, so (1) we should do the correct TER numbering in the default case, (2) for the non-default user this solution is correct for exporting correctly numbered (accounting for TER) input data, and (3) I think this exposes enough functionality for the non-default user to generate their desired output in the remaining cases.

With respect to the PDBIO tests, I believe that the write_auto_numbering and write_preserve_numbering test labels are currently swapped, and this fixes that as well.

@codecov

codecov Bot commented Jul 30, 2021 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (1d0ddef) to head (05a1fce).

❗ Current head 05a1fce differs from pull request most recent head 1f1baea. Consider uploading reports for the commit 1f1baea to get more accurate results

Additional details and impacted files
@@      Coverage Diff       @@
##   master   #3676   +/-   ##
==============================
==============================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JoaoRodrigues

Copy link
Copy Markdown
Member

This makes the code in PDBIO a little more convoluted than it needs to be, in my opinion. Could you change the chains of the residues themselves instead before writing? What exactly would be the use case here? Trying to see if the change is worth it.

FWIW, I just created #3679 and was toying with the idea of breaking down the code in more functions, for easier test coverage, so this would play along those lines.

@JoaoRodrigues JoaoRodrigues self-assigned this Aug 1, 2021
@rob-miller

rob-miller commented Aug 1, 2021 via email

Copy link
Copy Markdown
Contributor Author

@JoaoRodrigues

Copy link
Copy Markdown
Member

Catching up indeed :)

The TER statement is something we can try to improve. Some tools write "naked" TER statements (simply TER), while others output a little more info. Most tools I know of don't actually read the info on the TER statement.

I like the idea of refactoring PDBIO to make it a little more modular. That's what I had in mind too when I looked at it yesterday. Would make it much simpler to unit test as well, as opposed to the current style of more like "integration" tests. Having said that, the records are pretty much written atom by atom (line by line), so bundling them would be annoying. We'd have to reverse the parser process in order to be robust, when writing is a much simpler aspect.

Can you post a sample of what you are trying to do? I have the feeling there's a simpler solution here.

@rob-miller

rob-miller commented Aug 2, 2021 via email

Copy link
Copy Markdown
Contributor Author

@rob-miller

Copy link
Copy Markdown
Contributor Author

The TER statement is something we can try to improve. Some tools write "naked" TER statements (simply TER), while others output a little more info. Most tools I know of don't actually read the info on the TER statement.

lennax fixed Biopython's TER records in 7e185d8, but as you say I'd never noticed the other fields. Nonetheless it does seem like we should do the right thing, and I can't seem to load the redmine.open-bio.org link from that previous commit to see if that explains why it was an issue.

I like the idea of refactoring PDBIO to make it a little more modular. That's what I had in mind too when I looked at it yesterday. Would make it much simpler to unit test as well, as opposed to the current style of more like "integration" tests. Having said that, the records are pretty much written atom by atom (line by line), so bundling them would be annoying. We'd have to reverse the parser process in order to be robust, when writing is a much simpler aspect.

I do think it is useful to bundle the atoms together as residues, and initially just had this as a convenience function inside my current internal_coords.py -- but assumed this would be criticized for code duplication. I would like to replace the similar _pdb_atom_string in the Biopython internal_coords.py if we changed PDBIO's version to be public.

Can you post a sample of what you are trying to do? I have the feeling there's a simpler solution here.

Sorry, just noticed I had re-sequenced parts of my code before generating the previous sample and broke the serial numbers again. Here's three more views on the same data since I'm playing with them:

phe-pair-groups.pdb.gz
phe-pair-environs.pdb.gz
phe-pair-rings.pdb.gz

Again, they are all intended to be color-by-chain in your structure viewer of choice, and this time have the serial numbers correct throughout.

I don't think you can actually generate these with the current PDBIO short of creating a new (SM)CRA object, and with that you would lose the ability to annotate different residues in the file as these examples do (another advantage of exposing this part of PDBIO as a subroutine).

@peterjc

peterjc commented Aug 3, 2021 •

Copy link
Copy Markdown
Member

Cross reference PR #989, to fix redmine 2292 https://redmine.open-bio.org/issues/2292 - from my emails:

Bug # 2292: Bio.PDBIO writes TER records without any required fields
Author: Michal J.
Status: Resolved
Bio.PDBIO is happy to write TER records as "TER\n", which is inconsistent with PDB format specification.

The PDB format requires that TER records have some fields similar to ATOM records:
'''The TER record has the same residue name, chain identifier, sequence number and insertion code as the terminal residue. The serial number of the TER record is one number greater than the serial number of the ATOM/HETATM preceding the TER.'''

[See http://www.wwpdb.org/documentation/format23/sect9.html#TER]

It leads to problem with programs that require correct TER records (like multiple structural alignment program MUSTANG), and crash when they are not found

(with a patch which I think is what Lenna committed)

@rob-miller

Copy link
Copy Markdown
Contributor Author

updated to incorporate #3679

@rob-miller

Copy link
Copy Markdown
Contributor Author

updated to incorporate #3882

@JoaoRodrigues I am still keen to get this in :-)

I want/need the ability to write arbitrary PDB residues with control over chain ID and atom numbering in order to study pairwise residue interactions like:

Screenshot 2022-04-08 at 15 21 56

I support doing this in #3774 and describe it in #3898. I've implemented this functionality (pdb_residue_string()) in the internal_coords module, but really it should be in PDBIO - both logically and to benefit from improvements like #3679 and #3882.

The implementation suggested here for PDBIO is much better than what I've done in internal_coords, and I would very much like to remove this code from internal_coords in time for a 1.80 release.

Abusing PDB files is an old and venerable technique, and the kind of thing I feel Biopython really should support!

@rob-miller
rob-miller force-pushed the pdb-residue-string branch from 4baba03 to 1955998 Compare May 4, 2022 13:03
@rob-miller

Copy link
Copy Markdown
Contributor Author

Some explanation on the image above and why it needs this PR:

The image shows 3 pairs of PHE residues from PDB structure 3PBL (Human dopamine D3 receptor), selected as putatively interacting on the basis that their C-alphas are within 6 angstroms of each other (there are much better and more stringent tests in the literature). The N-Ca-C atoms (hedra) of the first residue in each pair (197-201, 345-346, and 390-394) are aligned using Chi1 transformation matrices exposed by the internal_coords module.

The attached PDB format file presents these pairs for analysis in PDB viewer software, as used to make the screenshot shown. The key characteristics that I don't think are possible (at least without a lot more work) without this PR are:

  • Each pair has its own chain ID (A, B, C)
  • Each individual residue has a correctly formatted TER line
  • Atom serial numbers are all sequential
  • Each residue has a REMARK line annotating description and distance

Clearly the generated PDB file is not a 'structure', and various viewers will handle the issues this addresses differently. The goal is to generate data that can be interactively selected, inspected and analysed with the minimum of noise - whether that's warnings and complaints or extraneous bonds.

phe_pairs_4a.pdb.gz

@rob-miller

Copy link
Copy Markdown
Contributor Author

My reasons for wanting this merged:

  1. It modularizes PDBIO.save(), which is usually considered a good thing, and factors out the residue generation in the same way the ATOM generation is factored out. There is complication in handling the atom number for the TER string, but it is reasonable to expect to manage this at the chain level and expose this for manually generating PDB files. Otherwise it is all the same code, so I really thought this would be a trivial change providing additional capability.
  2. The current approach of supplying a select() function (a) doesn't support on-the-fly filtering of a chain as easily or efficiently because you have to generate that function and re-scan the chain each time, (b) doesn't support more complicated things like arbitrary chain IDs for coloring in viewers, (c) writes the TER line after each set of residues which may not be desired, (d) writes to a file or stringio which has to be configured separately so less flexible, and (e) probably some other stuff that I've forgotten.
  3. It really should not be in the internal coords code, but it is there at least to support the examples in the documentation. The support for this could and should be removed from internal coords.
  4. Everything that writes PDB output should be together in one place so that changes/improvements like PR Support PDB charges in Atom class #3857 get picked up automatically.

@peterjc

peterjc commented Mar 19, 2024

Copy link
Copy Markdown
Member

Could you take a fresh look at this @JoaoRodrigues? Or maybe @etal or @lennax?

@JoaoRodrigues

JoaoRodrigues commented Mar 20, 2024 via email

Copy link
Copy Markdown
Member

@rob-miller

Copy link
Copy Markdown
Contributor Author

Update for 1.84

@shubhodeepcx shubhodeepcx mentioned this pull request Oct 17, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants