Repository navigation
refactor: move AF3 input preparation out of the backend - #659
Merged
Merged
Conversation
prepare_input was 1,230 lines holding 28 nested functions. They now live in alphafold3_inputs.py: the pure helpers (chain construction, monomer normalisation, region slicing of JSON chains, template mmCIF fixes, chain IDs, the job name) as module functions, and what read prepare_input's state as methods of FoldInputBuilder. prepare_input makes a fresh builder per call, so its chain IDs and its caches of feature metadata and template mmCIF checks still belong to one preparation. _supported_chain_kwargs loses its cache: it runs a few times per fold, and a cache would have pulled the pure chain helpers into the builder. The translated-MSA debug writer and the final-MSA A3M writer, nested in predict_structure, move to alphafold3_debug.py. The moved code changes only in indentation, apart from closure state becoming builder attributes. Tests patch and call the names where the moved code looks them up; the string naming rules are tested in output_paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Chain IDs roll over from Z to AA; JSON-given and generated chain IDs never collide; two preparations in one process share no chain IDs and no cached feature metadata (a process-wide cache fails this test); A3M region slicing keeps only the insertions inside the region; JSON chain regions slice the sequence, residue IDs, PTMs and MSA together, and need exactly one chain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
prepare_input returned single-key dicts {fold_input: (output_dir,
resolve_msa_overlaps)}, which predict took apart with a length check and an
isinstance check for a legacy bare output_dir. It now returns PreparedFold
dataclasses with those three fields, and predict reads them by name.
Callers in the tests switch from unpacking to attribute access; no assertion
changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Second of three behaviour-preserving PRs that split
alphafold3_backend.py; stacked on #658. This one takes input preparation out of the backend. No flag, output or file name changes.What moves
AlphaFold3Backend.prepare_inputwas 1,230 lines holding 28 nested functions. It is now about 40 lines:alphafold3_inputs.py(new)._object_name_fragment,_build_output_job_name).prepare_input's state become methods of aFoldInputBuilder: the chains so far, the chain IDs in use, which chains carry MSAs translated from AF2 features, the debug records, and the caches.prepare_inputmakes a fresh builder per call, so the caches of feature metadata and template mmCIF checks still last one preparation, never the process._supported_chain_kwargsloses its cache: it runs a few times per fold, and caching it would have pulled the pure chain helpers into the builder.alphafold3_debug.py(new). The translated-MSA debug writer and the final-MSA A3M writer that was nested inpredict_structure.The moved code changes only in indentation, apart from closure state becoming builder attributes. That rewiring is spelled out and count-checked by the script that did the cut.
Commits
The move. Tests patch and call the names where the moved code now looks them up. The string naming rules are tested in
output_paths, where they live since refactor: move AF3 output writing and resume out of the backend #658.Builder tests:
Making the metadata cache process-wide fails the shared-state test, as it should.
PreparedFold.prepare_inputreturnsPreparedFold(fold_input, output_dir, resolve_msa_overlaps)instead of single-key{fold_input: (output_dir, flag)}dicts.predictdrops its length and legacy-shape checks. In the tests, unpacking becomes attribute access; no assertion changes.Verification
PreparedFold. It covers 15 inputs: monomer, homo- and hetero-oligomers, chopped regions, RNA, DNA, ligand, PTMs, JSON inputs, multi-seed, and two folds per call. Each runsprepare_inputand thenprocess_fold_input(model_runner=None)with debug MSAs and templates on. Every_data.json, debug artifact, output dir andresolve_msa_overlapsflag is byte-identical tomain.mainplus the 6 new tests. AF2 image: 937 passed, 26 skipped. AF3 image: 1008 passed, 15 skipped. The same pre-existing environmental failures as onmain(nopytest-xdist, no network).RUN_EXPENSIVE_GPU_TESTS=1: 39/39 passed, includingTestAlphaFold3MetadataEndToEnd(real feature generation through inference and ModelCIF), resume, fast kernels and the MMseqs/regression checks.🤖 Generated with Claude Code