Repository navigation
Use eigh for principal axes and fix moments near the periodic boundary - #440
Merged
Merged
Conversation
np.linalg.eigh for symmetric matrices and fix moment of inertia near the periodic boundaryeigh for principal axes and fix moments near the periodic boundary
harryswift01
marked this pull request as ready for review
October 8, 2026 13:06
jimboid
approved these changes
Oct 8, 2026
jimboid
left a comment
Member
There was a problem hiding this comment.
This looks like both a significant improvement in numerical reproducibility and stability as well as function naming in this area of the code. Baseline update is fairly self explanatory. Numbers don't look to change significantly but prefer Sarah F to have deciding vote on that. Otherwise can't see any reason why this can't merge
skfegan
approved these changes
Oct 8, 2026
skfegan
left a comment
Member
There was a problem hiding this comment.
The changes to the baselines look reasonable.
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.
Summary
This PR addresses #439 and is a step towards #436. It switches the axes calculations from the general eigensolver (
np.linalg.eig) to the symmetric one (np.linalg.eigh), makes the principal axes reproducible across LAPACK builds, and fixes a bug in how moments of inertia were computed for molecules near the periodic boundary.Changes
Use
np.linalg.eighfor symmetric matrices:np.linalg.eigwithnp.linalg.eigh, since inertia tensors are always symmetric.eigdoes not guarantee orthogonal eigenvectors for (near-)degenerate moments, whileeighalways returns an orthonormal set.Make the principal axes reproducible:
eighfixes neither the sign of each eigenvector nor the basis within a degenerate eigenspace, and both can differ between LAPACK builds. The axes define the frame covariances are averaged in, so this changes the entropy.get_principal_axes_from_tensornow returns canonical axes:degeneracy_rtol, default tied to float32 precision) and the reference vector are keyword arguments.get_principal_axes_from_group, which uses it in place of the built-inprincipal_axes()at all call sites inaxes.pyandcovariance.py.Take the moment of inertia tensor after making the molecule whole:
get_molecule_axestook the tensor withunwrap=Truebeforemake_whole. This gives values of order M·L² when a molecule's centre of mass lies outside the primary cell.make_wholefirst and uses the plain tensor, so the moments no longer depend on where the molecule sits relative to the box.Clearer function names:
get_custom_principal_axes→get_principal_axes_from_tensorget_principal_axes→get_principal_axes_from_groupget_vanilla_axes→get_molecule_axesget_custom_axes→get_bonded_vector_axesTests:
Impact