From 08a41500764aeda9dc53e5df97d5749fbb0f4ab5 Mon Sep 17 00:00:00 2001 From: Arthur Zalevsky Date: Thu, 15 Oct 2026 11:30:31 -0700 Subject: [PATCH] Make GaussianEMRestraint score independent of pair list history The model-density close pair container lists every pair closer than the cutoff, plus other pairs that depend on where the particles were at the last list update. The restraint summed every listed pair, so the same coordinates could score differently depending on the sampling history, and Monte Carlo did not sample a fixed distribution when moves were smaller than the container's slack. Score only pairs whose spheres are closer than the cutoff plus 2A, and build the container with that cutoff so that it holds all such pairs. This is the set of pairs a freshly updated list held before, so scores are unchanged whenever the list was just updated. --- include/GaussianEMRestraint.h | 4 ++- src/GaussianEMRestraint.cpp | 57 ++++++++++++++++++++++++----------- test/test_pair_history.py | 44 +++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 test/test_pair_history.py diff --git a/include/GaussianEMRestraint.h b/include/GaussianEMRestraint.h index d6767eb..67539f9 100755 --- a/include/GaussianEMRestraint.h +++ b/include/GaussianEMRestraint.h @@ -85,7 +85,9 @@ class IMPBAYESIANEMEXPORT GaussianEMRestraint : public Restraint \param[in] density_ps particles for the density GMM \param[in] global_sigma Particle to modulate the uncertainty \param[in] model_cutoff_dist Cutoff for the model-model interactions - \param[in] density_cutoff_dist Cutoff for model-density interactions + \param[in] density_cutoff_dist Cutoff for model-density interactions. + Only pairs of Gaussians whose spheres (XYZR) are closer + than the cutoff plus 2A are scored. \param[in] slope Gentle term to move all particles to the density \param[in] update_model (DEPRECATED) update model each cycle \param[in] backbone_slope Limit the slope only to backbone particles diff --git a/src/GaussianEMRestraint.cpp b/src/GaussianEMRestraint.cpp index ab2bfbc..e713183 100755 --- a/src/GaussianEMRestraint.cpp +++ b/src/GaussianEMRestraint.cpp @@ -15,10 +15,27 @@ #include #include #include +#include #include IMPBAYESIANEM_BEGIN_NAMESPACE +namespace { +// The close pair container lists every pair closer than its cutoff, plus +// other pairs that depend on where the particles were when the list was +// last updated. Score only pairs whose spheres are closer than the cutoff +// plus this margin, so that the score depends only on the coordinates. The +// margin (twice the container's default slack of 1A) is the set of pairs a +// freshly updated list holds, so scores are unchanged right after an update. +const double pair_margin = 2.0; + +inline bool get_is_close(Model *m, const ParticleIndexPair &pp, + double cutoff) { + return core::get_distance(core::XYZR(m, std::get<0>(pp)), + core::XYZR(m, std::get<1>(pp))) < cutoff; +} +} // anonymous namespace + GaussianEMRestraint::GaussianEMRestraint(Model *mdl, ParticleIndexes model_ps, ParticleIndexes density_ps, ParticleIndex global_sigma, @@ -52,7 +69,7 @@ GaussianEMRestraint::GaussianEMRestraint(Model *mdl, ParticleIndexes model_ps, md_container_ = new container::CloseBipartitePairContainer( new container::ListSingletonContainer(mdl, model_ps), new container::ListSingletonContainer(mdl, density_ps), - density_cutoff_dist); + density_cutoff_dist + pair_margin); compute_initial_scores(); @@ -146,16 +163,19 @@ GaussianEMRestraint::unprotected_evaluate(DerivativeAccumulator *accum) const { std::map map_score_dm; // std::cout<<"calculating MD score"< map_score_dm; // std::cout<<"calculating MD score"<