Skip to content

CLI --help without torch; difference-map phases, DELFWT and extrapolations - #93

Merged
HatPdotS merged 3 commits into
mainfrom
claude/intelligent-albattani-dtmncg
Oct 22, 2026
Merged

HatPdotS merged 3 commits into
mainfrom
claude/intelligent-albattani-dtmncg

Conversation

@HatPdotS

Copy link
Copy Markdown
Owner

Summary

--help without importing torch

  • import torchref no longer imports torch: the top-level re-exports and subpackages load on first access via a module __getattr__. TORCHREF_DTYPE_*/TORCHREF_DEVICE are read on that first access.
  • Every CLI module defers its torch-dependent imports until after parse_args; the choice lists shown in --help come from torchref/cli/_choices.py, a torch-free mirror of the source tables. --help drops from ~4 s to ~0.1 s.

torchref.difference-map / torchref.difference-refine

  • The difference map (DELFWT/PHDELWT, dF, weights, KSCALE, Fc_dark) takes its phases from a scale fit of the dark model alone, so it no longer changes when a light model is given. The joint fit is used only for the light-model, extrapolation and two-moment layers.
  • New DELFWT = dF × the --ded-weight weight, so Coot opens the difference map directly.
  • The phase-aware (2FEXT_PHASED-Fc/PHFEXT_PHASED) and classic scalar (2FEXT_SCALAR-Fc/PHFEXT_SCALAR) extrapolations are written by default beside the shrunk FWT/PHWT. --all-columns now gates only the model-phased difference and intensity columns. The single-weight FEXT_*-Fc columns are dropped.
  • Renamed FC/PHIC/PHIC_diff → Fc_light/PHFc_light/PHdFc, consistent with Fc_dark/Fo_light.
  • difference-map: -o is an output directory (difference_map.mtz, summary.json with inputs, scaling, R-factors and weight/shrinkage fits); -lm/--fraction sit in an "optional" help group; incompatible -lm/--fraction/--all-columns combinations are refused up front.
  • Both difference CLIs gain --dmax; without --dmin the models' FFT grid follows the data's resolution instead of a fixed 1.0 Å.
  • Column builders return {label: (values, MTZ type)}, removing the duplicated type tables; the extrapolation constructions are one loop.

Net diff is −72 lines.

Breaking for scripts

  • difference-map -o is now a directory.
  • MTZ labels FC, PHIC, PHIC_diff, FEXT_PHASED-Fc, FEXT_SCALAR-Fc are renamed or removed.

Testing

  • tests/unit (full suite passed on the first commit; CLI, import-smoke and DED-weight unit tests re-run on the final head: 324 passed).
  • tests/integration/test_cli_ded_weights.py and test_cli_two_moment_mtz.py with --run-slow (16 passed), updated for the new labels, DELFWT and the -o directory.
  • Manual 1DAW runs: difference columns with and without -lm agree to within run-to-run noise; --help of every console script leaves torch unimported.

Generated by Claude Code

import torchref no longer imports torch: the top-level re-exports and the
subpackages load on first access through a module __getattr__. Every CLI
module defers its torch-dependent imports until after parse_args, and the
choice lists --help shows come from torchref.cli._choices, a torch-free
mirror pinned to its sources by a test. --help drops from ~4 s to ~0.1 s.

torchref.difference-map:
- refuses --all-columns without -lm, and a non-default --ded-weight unless
  -lm --all-columns writes the model-phased columns it weights
- requires -o to name a .mtz file, checked before any data is read
- writes <name>_summary.json beside the MTZ (inputs, dataset scaling,
  R-factors, q-weight and shrinkage diagnostics), as difference-refine does
- sizes the model FFT grid from the data's d_min when --dmin is not given
- names itself, not difference-refine, in the MTZ history

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aviwqFcZpxP3HWNy1ZruY
…ctory

- The difference map (DELFWT/PHDELWT, dF, weights, KSCALE, Fc_dark) takes its
  phases from a scale fit of the dark model alone, in difference-map and
  difference-refine, so it no longer changes when a light model is given
- DELFWT = dF times the --ded-weight weight, so Coot opens the difference map
- The phase-aware and scalar extrapolations are written by default beside
  the shrunk one; --all-columns now gates only the model-phased difference
  and intensity columns
- FC/PHIC/PHIC_diff are renamed Fc_light/PHFc_light/PHdFc, matching Fc_dark
- difference-map takes -o as a directory (difference_map.mtz, summary.json)
  and both difference CLIs gain --dmax; difference-refine sizes the model
  grid from the data without --dmin
- -lm/--fraction sit in an "optional" help group
- Column builders return {label: (values, MTZ type)}; the torch-free choice
  mirror and lazy torchref exports are compacted, and the new tests dropped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aviwqFcZpxP3HWNy1ZruY
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T13:45:47.825320Z 32b5a9c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 32b5a9c3a6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread torchref/cli/_common.py
The argparse converter imported difference_power for its bounds check, so a
bad value paid torch start-up before the usage error. The bounds now come
from the torch-free mirror; DifferencePowerConfig still validates at run time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aviwqFcZpxP3HWNy1ZruY
@HatPdotS
HatPdotS merged commit e9de435 into main Oct 22, 2026
13 checks passed
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.

2 participants