Refinement: the B ceiling lifted for a model that arrives with B above it

The ceiling of B was clamp(2 Bmax, 100, 300), and PrepareModel cut every B to 300 before it was set: a structure
refined at 4-5 A (mean B 380, most atoms above 300) was flattened, its as-given R-free 0.05 above the validation's
on the same model (0.359 against 0.306), and the refinement ended worse than the validation (0.339). The 300 bound
stays for every model under it (it sizes the gather); a model above it gets a ceiling of 1.5 times its largest B
(BCeiling), PrepareModel keeps only the floor, and an anisotropic U is scaled to the model's ceiling, not the
constant. The case above: as given 0.325, refined 0.242.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK
This commit is contained in:
leonarski_fandClaude Fable 5.1 committed 2026-11-14 12:19:12 +01:00
1 parent 044dc4deb2
commit 13ddef63d3
1 file changed
+11 -5
@@ -52,6 +52,12 @@ namespace {
constexpr double B_FLOOR = 2.0; // A^2: no atom's B goes below it
// nor above twice the model's largest B, within these bounds (the GPU's gather is reserved for it)
constexpr double B_CEILING_MIN = 100.0, B_CEILING_MAX = 300.0;
// The ceiling of B for a model whose highest B is `b_max`: twice it, within the bounds - the bounds lifted for a
// model that comes with B above them (a structure refined at 4-5 A, B 400-600 A^2), which the ceiling would
// otherwise flatten (the gather is reserved for it).
double BCeiling(double b_max) {
return std::clamp(2 * b_max, B_CEILING_MIN, std::max(B_CEILING_MAX, 1.5 * b_max));
}
// A B tensor (8 pi^2 U) inside the bounds: its smallest eigenvalue raised to `floor` by a multiple of I, then the
// whole tensor scaled down so that its largest is at most `ceiling`. The ceiling comes last because the GPU's
@@ -141,7 +147,7 @@ gemmi::Structure PrepareModel(const gemmi::Structure &placed, const gemmi::UnitC
a.charge = ScatteringCharge(r, a);
if (a.aniso.nonzero())
a.b_iso = static_cast<float>(gemmi::u_to_b() * a.aniso.trace() / 3.0);
a.b_iso = static_cast<float>(std::clamp<double>(a.b_iso, B_FLOOR, B_CEILING_MAX));
a.b_iso = static_cast<float>(std::max<double>(a.b_iso, B_FLOOR));
}
}
gemmi::remove_empty_children(st);
@@ -266,8 +272,8 @@ struct Context {
continue;
// its widest axis no wider than the refinement allows
const double top = AnisoRadiusB(at.aniso.scaled(gemmi::u_to_b()));
if (top > B_CEILING_MAX) {
at.aniso = at.aniso.scaled(static_cast<float>(B_CEILING_MAX / top));
if (top > b_ceiling) {
at.aniso = at.aniso.scaled(static_cast<float>(b_ceiling / top));
at.b_iso = static_cast<float>(gemmi::u_to_b() * at.aniso.trace() / 3.0);
}
const double t = at.aniso.trace() / 3.0;
@@ -2308,7 +2314,7 @@ RefinementResult RefineOnce(const gemmi::Structure &placed, const std::vector<Me
for (const TlsBody &body : tls_bodies)
for (int i : body.atoms)
b_max = std::max(b_max, ctx.atoms[i]->b_iso + gemmi::u_to_b() * body.U(ctx.atoms[i]->pos).trace() / 3.0);
ctx.b_ceiling = std::clamp(2 * b_max, B_CEILING_MIN, B_CEILING_MAX);
ctx.b_ceiling = BCeiling(b_max);
if (ctx.atoms.empty()) {
result.failure_reason = "the model has no atoms";
return result;
@@ -3297,7 +3303,7 @@ RefinementResult RefineOnce(const gemmi::Structure &placed, const std::vector<Me
double b_max = 0;
for (size_t i = 0; i < ctx.atoms.size(); i++)
b_max = std::max<double>(b_max, ctx.atoms[i]->b_iso);
const double ceiling = std::clamp(2 * b_max, B_CEILING_MIN, B_CEILING_MAX);
const double ceiling = BCeiling(b_max);
if (ceiling > ctx.b_ceiling) {
const RefinementStage stage("engine");
for (std::unique_ptr<OwnSlot> &o : own)