fix: preserve molecular geometry during manostat scaling#261
Conversation
Stochastic and Berendsen manostats scale the box before calling Molecule::scale(), but Molecule::scale() only shifted atoms by the molecule-COM scale vector and left boundary-crossing coordinates outside the newly scaled box. Apply PBC after the shift so positions are imaged into the scaled box while preserving the rigid molecule-COM scaling model. Also fix the isotropic stochastic-rescaling mu formula to use length scaling in the deterministic pressure term (divide by 3), matching the semi-isotropic / anisotropic forms. Tests cover both the wrapping path and the deterministic zero-temperature mu calculation.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #261 +/- ##
==========================================
+ Coverage 88.12% 88.41% +0.28%
==========================================
Files 283 283
Lines 10874 10910 +36
Branches 3376 3381 +5
==========================================
+ Hits 9583 9646 +63
+ Misses 1251 1224 -27
Partials 40 40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
⚡ Performance (instruction count) — ✅ no regressionsper-benchmark breakdown
Deterministic callgrind instruction counts vs the base branch; gated at ±2%. Not wall-clock. |
|
Real-PQ reproducer zip: https://github.com/MolarVerse/PQ/raw/test/pr-261-reproducer/artifacts/pr-261-real-pq-reproducer.zip Includes native one-step and 1000-step PQ inputs, Force path: normal PQ MM brute-force path ( Same one-step input, observed with real PQ:
1000-step input, observed with real PQ and ASE reference:
Run with: |
ape33
left a comment
There was a problem hiding this comment.
This does not fix the problem at hand. I have attached example input of a MOF-5 simulation, where calculating the shake distances for the second run shows the issue. All C-H shake distances are associated with linker molecules. The shake distances of linkers cut by the box are systematically longer than those of linkers that are fully inside the box (see attached graph: shake.pdf). This is only the case when using the stochastic rescaling manostat. Using the exact same input, but switching to the Berendsen manostat fixes this issue (comparison graph will follow).
Here the example input, including a script for calculating the average distances:
stoch_res.zip
|
@ape33 you were right: the wrapping fix was not the stochastic-only bug. The MOF-5 case points to the extra velocity scaling in So: PBC wrapping stays as a separate shared fix, but this velocity change is the actual fix for your stochastic-rescaling case. CI is green, and the new tests cover that invariant. |
@galjos |
|
@galjos |
|
I replaced the earlier velocity-only approach with the molecule-reconstruction fix and reran the real MOF-5 CUDA/MACE validation. 50000 steps / 5000 saved frames, stochastic/rescale manostat:
The validator package and comparison PNG/CSV/JSON outputs are intentionally kept out of this PR tree and are available as a separate zip: SHA256: |
503edd7 to
a686892
Compare
|
@ape33 I moved the validator/plots out of the PR tree so they will not land in SHA256: The zip contains |
ape33
left a comment
There was a problem hiding this comment.
please do not merge yet, I would like to run tests first
There was a problem hiding this comment.
Nice, these updates seem to fix the issue!
However, is the scaling of the velocities based on the COM necessary and even meaningful? For the velocity rescaling thermostat for example also an atom-based scaling is employed.
On this I would like to hear the opinion of @97gamjak
|
Replying to ape33's review: #261 (review) Good question. I think the meaningfulness comes from matching the velocity update to the coordinate DOF used by the barostat. After this PR, the manostat scales positions via molecule COMs to preserve constrained geometry, so the reciprocal stochastic velocity scaling should act on the molecule COM velocity as well. Atom-wise scaling would change intramolecular relative velocities while the coordinate update intentionally leaves them unchanged. This is also how I read the comparison with other engines: GROMACS C-rescale scales atom velocities, but its coordinate scaling path is atom-based too; OpenMM/Amber/LAMMPS use molecule/rigid-body centers when rigid molecular geometry is what is being preserved. The velocity-rescaling thermostat is different because it intentionally acts on atomic thermal velocities. |
Sounds reasonable to me, thank you for the detailed explanation! |
|
@ape33 me too |
Fixes the MOF-5 stochastic-rescaling manostat distortion reported in review.
What changed:
muas length scaling:exp((-compress * deltaP + stochasticFactor) / 3).Validation:
run-02, stochastic/rescale manostat, 50000 steps / 5000 saved frames on a GPU node.dev13a82748: cut mean1.0943499541 A, min/max1.0925817400 / 1.0960428055 A; inside mean1.0918005631 A, min/max1.0904312459 / 1.0934742641 A; gap0.0025493910 A.a686892e: cut mean1.0932610733 A, min/max1.0922109993 / 1.0972167131 A; inside mean1.0928381316 A, min/max1.0907006212 / 1.0970055845 A; gap0.0004229417 A.660000.Validator/plots package kept out of this PR tree:
af944f5e6c411610e704063c03036e1c8f089b193b565c7cc6098d79c4a72e70analyze_mof5_ch.py, the comparison PNGs, and CSV/JSON summaries.Local checks:
ctest --test-dir build-pr261-publish-static2 -R '^(testMolecule|testManostat)$' --output-on-failuregit diff --cached --check