Repository navigation
internal-coords vector assembly update - #3774
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3774 +/- ##
==========================================
- Coverage 84.05% 78.82% -5.24%
==========================================
Files 321 301 -20
Lines 54093 51749 -2344
==========================================
- Hits 45470 40790 -4680
- Misses 8623 10959 +2336
Continue to review full report at Codecov.
|
|
New bpbp-gist.py sample code for exercising features in this PR, plus the two example scripts above, uploaded to rtm-biopython-scripts. |
|
Closes #3793 |
d13bc43 to
5dd44fb
Compare
|
Working on improving test coverage and hoping to resolve #3802 |
b5ec61f to
eaf3794
Compare
…key(), rm L12, L23 refs
eaf3794 to
3301155
Compare
JoaoRodrigues
left a comment
There was a problem hiding this comment.
Sorry this took so long @rob-miller - work+life got in the way. 👍 for me to merge. It would be really nice at some point to have a doc showcasing how useful this code can be for the users!
PR overhauls the vector assembly code and makes heavier use of numpy for fast vectorized operations.
PR overhauls the vector assembly code and makes heavier use of numpy for fast vectorized operations.
The module docstring lists MissingAtomError as one of the module's custom exceptions, but nothing has raised it since Biopython 1.80. Its only raise site was Edron.gen_acs, which biopython/biopython#3774 (January 2022) removed when atom coordinates moved into NumPy arrays; the class was left behind. The current code tolerates missing atoms instead: a missing backbone atom breaks the chain there, and angles needing a missing atom come back as None. Raising it again would turn that tolerance into an error for any structure with unresolved atoms, which the docs never promised (they name no raise site), so deprecate the class instead. It stays importable: a module __getattr__ hands back the same class and emits a BiopythonDeprecationWarning, so an except clause that names it learns that it never runs. The module docstring no longer lists it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The module docstring lists MissingAtomError as one of the module's custom exceptions, but nothing has raised it since Biopython 1.80. Its only raise site was Edron.gen_acs, which biopython/biopython#3774 (January 2022) removed when atom coordinates moved into NumPy arrays; the class was left behind. The current code tolerates missing atoms instead: a missing backbone atom breaks the chain there, and angles needing a missing atom come back as None. Raising it again would turn that tolerance into an error for any structure with unresolved atoms, which the docs never promised (they name no raise site), so deprecate the class instead. It stays importable: a module __getattr__ hands back the same class and emits a BiopythonDeprecationWarning, so an except clause that names it learns that it never runs. The module docstring no longer lists it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The module docstring lists MissingAtomError as one of the module's custom exceptions, but nothing has raised it since Biopython 1.80. Its only raise site was Edron.gen_acs, which biopython/biopython#3774 (January 2022) removed when atom coordinates moved into NumPy arrays; the class was left behind. The current code tolerates missing atoms instead: a missing backbone atom breaks the chain there, and angles needing a missing atom come back as None. Raising it again would turn that tolerance into an error for any structure with unresolved atoms, which the docs never promised (they name no raise site), so deprecate the class instead. It stays importable: a module __getattr__ hands back the same class and emits a BiopythonDeprecationWarning, so an except clause that names it learns that it never runs. The module docstring no longer lists it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The module docstring lists MissingAtomError as one of the module's custom exceptions, but nothing has raised it since Biopython 1.80. Its only raise site was Edron.gen_acs, which biopython/biopython#3774 (January 2022) removed when atom coordinates moved into NumPy arrays; the class was left behind. The current code tolerates missing atoms instead: a missing backbone atom breaks the chain there, and angles needing a missing atom come back as None. Raising it again would turn that tolerance into an error for any structure with unresolved atoms, which the docs never promised (they name no raise site), so deprecate the class instead. It stays importable: a module __getattr__ hands back the same class and emits a BiopythonDeprecationWarning, so an except clause that names it learns that it never runs. The module docstring no longer lists it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The module docstring lists MissingAtomError as one of the module's custom exceptions, but nothing has raised it since Biopython 1.80. Its only raise site was Edron.gen_acs, which biopython/biopython#3774 (January 2022) removed when atom coordinates moved into NumPy arrays; the class was left behind. The current code tolerates missing atoms instead: a missing backbone atom breaks the chain there, and angles needing a missing atom come back as None. Raising it again would turn that tolerance into an error for any structure with unresolved atoms, which the docs never promised (they name no raise site), so deprecate the class instead. It stays importable: a module __getattr__ hands back the same class and emits a BiopythonDeprecationWarning, so an except clause that names it learns that it never runs. The module docstring no longer lists it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The module docstring lists MissingAtomError as one of the module's custom exceptions, but nothing has raised it since Biopython 1.80. Its only raise site was Edron.gen_acs, which biopython/biopython#3774 (January 2022) removed when atom coordinates moved into NumPy arrays; the class was left behind. The current code tolerates missing atoms instead: a missing backbone atom breaks the chain there, and angles needing a missing atom come back as None. Raising it again would turn that tolerance into an error for any structure with unresolved atoms, which the docs never promised (they name no raise site), so deprecate the class instead. It stays importable: a module __getattr__ hands back the same class and emits a BiopythonDeprecationWarning, so an except clause that names it learns that it never runs. The module docstring no longer lists it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ses (#144) * Deprecate Bio.PDB.internal_coords.MissingAtomError, which nothing raises The module docstring lists MissingAtomError as one of the module's custom exceptions, but nothing has raised it since Biopython 1.80. Its only raise site was Edron.gen_acs, which biopython/biopython#3774 (January 2022) removed when atom coordinates moved into NumPy arrays; the class was left behind. The current code tolerates missing atoms instead: a missing backbone atom breaks the chain there, and angles needing a missing atom come back as None. Raising it again would turn that tolerance into an error for any structure with unresolved atoms, which the docs never promised (they name no raise site), so deprecate the class instead. It stays importable: a module __getattr__ hands back the same class and emits a BiopythonDeprecationWarning, so an except clause that names it learns that it never runs. The module docstring no longer lists it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * Hide internal_coords' module __getattr__ from type checkers A module-level __getattr__ makes mypy and other type checkers accept any name imported from or read off the module, so after the deprecation "from Bio.PDB.internal_coords import NoSuchName" passed mypy --strict. Bio ships py.typed, so that weakened every downstream user's typo checking for the whole module. Define the __getattr__ and the del only when not TYPE_CHECKING. Type checkers keep seeing MissingAtomError as the class, so except clauses naming it still type-check, and they reject other unknown names as they did before. Runtime behaviour is unchanged. A downstream_typing file pins both: the "type: ignore[attr-defined]" lines fail as unused ignores without this change. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Dan Bolser <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.rstfile, have runpre-commitlocally,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.rstandCONTRIB.rstas part of this pull request, am listedalready, or do not wish to be listed. (This acknowledgement is optional.)
This is an update / upgrade to the Bio/PDB/internal_coords module, primarily around 'vectorizing' (NumPy-izing') the generation of atom coordinates from bond lengths, angles and dihedral angles.
Will come up with News entry when happy to merge; last time forgot to mention 3D printing aspect.
Primary improvements / additions:
assembly (internal_to_atom_coordinates()) is now ‘vectorized’, as in the steps are processed as NumPy commands on arrays of data as the coordinates become available. Assembly is still dependent on preceding regions of a chain, so for example both the side chain and backbone can be assembled in the same numpy steps once the shared initial coordinates are set. Chains over 100 residues assemble in about 1/2 the time as for the serial algorithm, while the speedup for shorter chains (e.g. 1crn, 46 residues) is insignificant. For more specific cases like changing all side chain chi1 angles on a fixed backbone, the speedup is much greater as all sidechains can be processed in parallel. The serial algorithm can still be optionally activated, and is triggered when start and end positions are specified for assembly. The reverse procedure, atom_to_internal_coordinates(), was vectorized in the initial release.
AtomArray: To support the vectorized assembly process, all atom coordinates are relocated into one numpy array and the coordinates in the Biopython Atom objects become views into this larger array. (This was discussed on the Biopython mailing list in Oct, 2019 as "Overhauling of Bio.PDB module" but the result here just came about as a result of vectorizing the assembly step.) The atomArray is created and made available when internal coordinates are calculated (atom_to_internal_cooordinates()). Subsets of this array can be accessed using AtomKey objects, and generating a 2D distance plot is a single (admittedly arcane) line of numpy code.
Both the assembly and internal coordinate calculation algorithms are based on computing coordinate spaces for relevant triples (hedra) of atoms. The coordinate transform matrices to and from these spaces for every dihedral are available for use, for example to compare residue environments or pairwise interactions. The steps are essentially:
chi1 = ric0.pick_angle("chi1") # chi1 space defined with CA at origin
cst = np.transpose(chi1.cst) # transform TO chi1 space
newAtomCoords = oldAomCoords.dot(cst)
See attached sample code presenting phe-phe pair interactions as PDB files for inspection (proof of concept only, not carefully selected interacting pairs). Note this should/will use PR #3676 if/when it is approved but for now there is a redundant pdb_residue_string() routine (and supporting data structures) supplied with the internal_coordinates module.
bugfixes / smaller things:
ca-plot-7rsa.py.txt
phe-pairs-2.py.txt