diff --git a/image_analysis/structure_refinement/Refinement.cpp b/image_analysis/structure_refinement/Refinement.cpp index 8f94870b3..2dbc0ba8d 100644 --- a/image_analysis/structure_refinement/Refinement.cpp +++ b/image_analysis/structure_refinement/Refinement.cpp @@ -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(gemmi::u_to_b() * a.aniso.trace() / 3.0); - a.b_iso = static_cast(std::clamp(a.b_iso, B_FLOOR, B_CEILING_MAX)); + a.b_iso = static_cast(std::max(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(B_CEILING_MAX / top)); + if (top > b_ceiling) { + at.aniso = at.aniso.scaled(static_cast(b_ceiling / top)); at.b_iso = static_cast(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::vectorb_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(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 &o : own)