Add pose_stack_from_backbone_coords: in-memory PoseStack construction from N/CA/C/O#380
Open
ssiddhantsharma wants to merge 2 commits into
Conversation
added 2 commits
May 23, 2026 16:02
… memory Introduces a new adapter that constructs a PoseStack directly from backbone coordinates and integer residue type indices, eliminating the PDB file roundtrip required by pose_stack_from_pdb. Follows the same pattern as pose_stack_from_openfold / pose_stack_from_rosettafold2. Public API (all exported from tmol.__init__): - pose_stack_from_backbone_coords(coords, res_types, chain_id, device) - canonical_form_from_backbone_coords(...) — stable serializable intermediate - canonical_ordering_for_backbone_coords() — memoized - packed_block_types_for_backbone_coords(device) — memoized Atom order: N=0, CA=1, C=2, O=3 (matches AlphaFold2 / mosaic convention). Default aa_order="ARNDCQEGHILKMFPSTWYV" (AlphaFold2/mosaic standard). Padding residues are marked with res_types=-1. Single-pose (3-D) inputs are auto-unsqueezed to batch dimension. tmol builds missing side-chain leaf atoms from ideal geometry. Also cherry-picks PoseStack.split(index) and PDBInfo.split(index) from open PR uw-ipd#379 (aleaverfay/split_pose_stack), which enable efficient batch ΔG scoring: build complex/binder/target as a 3-pose batch, score once, and extract per-pose energies.
Resolve the single conflict in tmol/pose/pdb_info.py: master independently added PDBInfo.split, so drop this branch's duplicate and keep master's. All other changes auto-merge; the PR now contributes only the pose_stack_from_backbone_coords feature (+ PoseStack.split, __init__ exports, tests).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
pose_stack_from_pdbrequires writing backbone coordinates to a temporary PDBfile and reading it back — expensive I/O for workloads (gradient-based
hallucination, ΔG scoring loops) that already have coordinates in memory as
tensors.
Changes
New:
tmol/io/pose_stack_from_backbone_coords.pyBuilds a
PoseStackdirectly from(N, CA, C, O)backbone coordinates andinteger residue type indices, with no file I/O. Follows the same adapter
pattern as
pose_stack_from_openfoldandpose_stack_from_rosettafold2.Missing side-chain leaf atoms are reconstructed from ideal internal coordinates
geometry by the existing
pose_stack_from_canonical_formpipeline.Public API (exported from
tmol):pose_stack_from_backbone_coords(coords, res_types, chain_id, device)canonical_form_from_backbone_coords(...)canonical_ordering_for_backbone_coords()packed_block_types_for_backbone_coords(device)Conventions:
N=0, CA=1, C=2, O=3— matches AlphaFold2 / mosaicaa_order="ARNDCQEGHILKMFPSTWYV"(AlphaFold2 / mosaic standard; overridable)res_types=-1marks padding positions(L, 4, 3)inputs are auto-unsqueezed; batched(n_poses, L, 4, 3)also acceptedCherry-pick:
PoseStack.splitandPDBInfo.split(from PR #379)Adds
PoseStack.split(index)andPDBInfo.split(index)fromaleaverfay/split_pose_stack (#379).
These are included here because they compose naturally with the new adapter:
build complex, binder, and target as a 3-pose batch with
PoseStackBuilder.from_poses, score once, and index per-pose energies —rather than three separate
pose_stack_from_pdb+ score calls.Usage
Tests
tmol/tests/io/test_pose_stack_from_backbone_coords.pytest_pose_stack_from_backbone_coords_shapen_posesandmax_n_blocksmatch residue count (ubiquitin, 76 res)test_pose_stack_from_backbone_coords_devicePoseStack.coordsis on the requested devicetest_pose_stack_from_backbone_coords_single_pose_squeeze(L, 4, 3)is auto-unsqueezed to a 1-pose batchtest_backbone_coords_side_chains_builttest_pose_stack_from_backbone_coords_two_chainsmax_n_blockstest_memoization_of_backbone_coords_paramdb_paramdb_for_backbone_coords()returns the same object on repeated callstest_memoization_of_canonical_orderingcanonical_ordering_for_backbone_coords()is memoizedtest_memoization_of_packed_block_typespacked_block_types_for_backbone_coords(device)is memoizedtest_device_of_packed_block_typesPackedBlockTypesis on the correct devicetest_padding_residues_ignoredres_types=-1padding positions are excluded; 3 valid + 2 padding →max_n_blocks=3