diff --git a/rugnux/Rugnux.cpp b/rugnux/Rugnux.cpp index 74aa0c628..64cf820cf 100644 --- a/rugnux/Rugnux.cpp +++ b/rugnux/Rugnux.cpp @@ -4732,13 +4732,27 @@ ProcessResult Rugnux::RunPipeline(RugnuxObserver *observer, bool write_output, b flipped.Axis(-gon->GetAxis()); experiment_.Goniometer(flipped); FirstPass alt = pick_best(*indexer_pool, *indexer); - if (alt.result.has_value() && alt.score > best.score) { + // More frames is not enough on its own while both counts sit at the floor: 1/60 against + // 0/60 is noise, and adopting it puts every rescue below on the wrong sign (measured: a + // run whose file sign, kept, went on to index found nothing once flipped on 1/60). So + // the flipped lattice must also beat chance on the pooled spots - the test the run puts + // its final lattice to - which a sparse pattern at the right sign passes on few frames + // (2/60 frames, 89% of the validation spots against 0% by chance). + const bool alt_real = alt.result.has_value() && alt.score > best.score + && beats_chance(pooled_evidence(*indexer, *alt.result)); + if (alt_real) { logger.Info("Rotation axis sign: the file's axis indexes {}/{} validation frames, " "the opposite sign {}/{} - adopting the opposite sign for this run", best.score, static_cast(validation.size()), alt.score, static_cast(validation.size())); best = alt; } else { + if (alt.result.has_value() && alt.score > best.score) + logger.Info("Rotation axis sign: the opposite sign indexes {}/{} validation frames " + "against the file's {}/{}, but its lattice does not beat chance on the " + "pooled spots - the file's sign is kept", + alt.score, static_cast(validation.size()), + best.score, static_cast(validation.size())); experiment_.Goniometer(*gon); // the file was right; put it back } } @@ -5686,14 +5700,17 @@ ProcessResult Rugnux::RunPipeline(RugnuxObserver *observer, bool write_output, b } } indexer->ForceRotationIndexerResult(*best.result); - // A lattice the pooled spots accept while hardly a validation frame clears the per-frame - // floor (LATTICE_MIN_INDEXED_FRACTION) on its own, because the sweep as a whole puts fewer of - // its spots on the lattice than that floor asks of each frame: the crystal is real but its + // A lattice the pooled spots accept while most validation frames fail the per-frame floor + // (LATTICE_MIN_INDEXED_FRACTION) on their own, because the sweep as a whole puts fewer of its + // spots on the lattice than that floor asks of each frame: the crystal is real but its // spots are a minority of every frame - a weak crystal inside a powder of its own // microcrystals and ice. The floor cannot tell its frames from anything else, so integrate // every frame from the sweep's lattice, as XDS and DIALS do, and leave the frames to the - // scaling. A sweep that is sparse only in spots per frame (a small molecule) keeps the floor. - const bool sparse_lattice = best.score < static_cast(validation.size()) / 6 + // scaling. The frames that do clear it are the upper tail of the same population: measured + // on a crystal in a powder of itself (13% of the pooled spots on the lattice), 12/60 + // cleared it, and keeping the floor integrated 15% of the sweep. A sweep that is sparse + // only in spots per frame (a small molecule) keeps the floor. + const bool sparse_lattice = best.score < static_cast(validation.size()) / 2 && pooled < LATTICE_MIN_INDEXED_FRACTION; indexer->IntegrateEveryFrame(sparse_lattice); if (sparse_lattice) diff --git a/tools/battery/shelx_check.py b/tools/battery/shelx_check.py index 119919429..fc38c29d9 100644 --- a/tools/battery/shelx_check.py +++ b/tools/battery/shelx_check.py @@ -16,7 +16,9 @@ Recipe (the same for every run, so two runs compare): the same recipe takes a merged or an unmerged HKLF 4 file; R(int)/R(sigma) are read where SHELXL prints them (meaningful for unmerged data only). - "fixed-model R1(F)": the data scored against |Fc| of the COD model as published (gemmi, no - refinement, one scale): a check that does not depend on what SHELXL can absorb into ADPs or EXTI. + refinement of the model, a scale and SHELXL's extinction coefficient fitted): a check that does + not depend on what SHELXL can absorb into ADPs. Extinction is a property of this crystal, not of + the model, and without it the strongest reflections dominate the score. Derived from the small-molecule harness of the 2026-10 data-quality work (codref.py/fixedmodel.py). SHELXL is called, not shipped: give its path as site key "shelxl" or have it on PATH (it comes with @@ -197,8 +199,9 @@ def run_shelxl(shelxl, name, cwd): "shx_k_top": k_top}, " ".join(wght) -def fixed_model_r1(st, refl, M): - """R1(F) of the (reindexed) data against |Fc| of the COD model as published, one scale.""" +def fixed_model_r1(st, refl, M, lam): + """R1(F) of the (reindexed) data against |Fc| of the COD model as published, with one scale and + SHELXL's extinction, Fc2* = Fc2 (1 + 0.001 x Fc2 lambda^3 / sin 2theta)^-1/2, x fitted by a scan.""" sg = spacegroup(st) ops = sg.operations() asu = gemmi.ReciprocalAsu(sg) @@ -216,15 +219,21 @@ def fixed_model_r1(st, refl, M): groups.setdefault(tuple(asu.to_asu(list(map(int, n)), ops)[0]), []).append((i, s)) if not groups: return None - fo, fc = [], [] + fo, fc, ext = [], [], [] for hkl, obs in groups.items(): w = [1 / s ** 2 for _, s in obs] fo.append(sum(i * wi for (i, _), wi in zip(obs, w)) / sum(w)) fc.append(abs(calc.calculate_sf_from_small_structure(st, list(hkl))) ** 2) - fo, fc = np.array(fo), np.array(fc) - fo = fo / (np.sum(fo * fc) / np.sum(fc * fc)) - Fo, Fc = np.sqrt(np.clip(fo, 0, None)), np.sqrt(fc) - return round(float(np.sum(np.abs(Fo - Fc)) / np.sum(Fo)), 4) + sin_th = lam / (2 * st.cell.calculate_d(list(hkl))) + ext.append(0.001 * lam ** 3 / (2 * sin_th * np.sqrt(1 - sin_th ** 2))) + fo, fc, ext = np.array(fo), np.array(fc), np.array(ext) + + def r1(x): + fcx = fc / np.sqrt(1 + x * fc * ext) + f = fo / (np.sum(fo * fcx) / np.sum(fcx * fcx)) + Fo = np.sqrt(np.clip(f, 0, None)) + return float(np.sum(np.abs(Fo - np.sqrt(fcx))) / np.sum(Fo)) + return round(min(r1(x) for x in np.concatenate(([0.0], np.geomspace(1e-4, 100, 121)))), 4) def check(wd, cod_id, cache=DEFAULT_CACHE, shelxl=None, work=None): @@ -269,7 +278,7 @@ def check(wd, cod_id, cache=DEFAULT_CACHE, shelxl=None, work=None): vals, suggested = run_shelxl(shelxl, "f", d) wght = suggested or wght out.update(vals) - out["shx_fixed_r1"] = fixed_model_r1(st, refl, M) + out["shx_fixed_r1"] = fixed_model_r1(st, refl, M, lam) out["shx_status"] = "ok" if vals["shx_r1"] is not None else "error" if vals["shx_r1"] is None: out["shx_reason"] = "SHELXL did not finish the refinement (see shelx/final/f.lst)"