Repository navigation
solid: estimate spring constants from the unrounded MSD - #287
Merged
Merged
Conversation
The mean MSD was rounded to 2 decimals. Below 0.005 A^2 (low T, heavy or stiff elements) it rounded to 0 and was replaced by 1 A^2, giving k = 3kT/1 A^2, orders of magnitude too soft (bcc W at 100 K: 0.026 instead of 6.46 eV/A^2). validate_spring_constants accepted it, so the run went on with a biased free energy and only a warning. - use the unrounded MSD; an MSD that is zero or not finite gives nan, which validate_spring_constants replaces by another element's k (elements without atoms) or rejects with an error when no element has a usable value - converge on the relative change of k between cycles against tolerance.spring_constant; the old check compared the rounded MSD std and always passed on the first cycle - if n_cycles runs out, use the last estimate with a warning instead of leaving self.k unset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Solid.analyse_spring_constantsrounded the mean MSD to 2 decimals. Below 0.005 Ų (low temperature, heavy or stiff elements) the MSD rounded to 0. The code then substituted 1 Ų, giving k = 3kT / 1 Ų. With an MSD of 0.004 Ų at 100 K, that makes k 0.026 eV/Ų instead of 6.46 eV/Ų.validate_spring_constantsaccepted the value because it lies inside [1e-4, 1e3], so the run went on with a badly matched Einstein crystal, large dissipation and a biased free energy. Only a warning was logged.Two related problems:
tolerance.spring_constant. That standard deviation is almost always rounded to 0, so the loop stopped on the first cycle.n_cycles,self.kwas never set and the run crashed later.Between 0.005 and 0.05 Ų, the rounding made k coarse (up to about ±50 %) but did not bias the free energy.
Fix
validate_spring_constantsreplaces it with another element's k (the case of an element without atoms, which the old fallback was there for), or raises when no element has a usable value.tolerance.spring_constant(default 0.1). k only needs to be approximate, so this normally stops at cycle 2.md.n_cycles. If that runs out, the last estimate is used and a warning is logged.Workaround for affected versions: set
spring_constantsexplicitly.Behaviour change
n_small_stepsrun.Tests
tests/test_spring_constants.py: 7 tests covering a small MSD, no rounding, zero MSD for one or all elements, user-supplied k overriding the estimate, stopping after two cycles, and then_cyclescap. All 7 fail onmain.