Fix AttributeError when Hessian has no negative eigenvalues#10
Conversation
Signed-off-by: WHOIM1205 <rathourprateek8@gmail.com>
|
hey @ccastilloo The fix adds a fallback initialization ( |
There was a problem hiding this comment.
Pull request overview
This PR updates Bonded.__init__ to ensure self.hess_new is always initialized, avoiding an AttributeError when the Hessian has no sufficiently negative eigenvalues (the common equilibrium case).
Changes:
- Add an
elsebranch to setself.hess_new = self.hess.copy()when no eigenvalue correction is needed. - Keep the unit-conversion logic operating on both
self.hessandself.hess_newafter initialization.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if np.allclose(evecs.T, np.linalg.inv(evecs)): | ||
| print("Eigenvectors are orthonormal.") | ||
| else: | ||
| raise ValueError("Eigenvectors are not orthonormal.") | ||
| else: |
| else: | ||
| self.hess_new = self.hess.copy() |
|
@WHOIM1205 Thank you for your contribution! The |
Fix: Prevent
AttributeErrorinBonded.__init__when Hessian has no negative eigenvaluesProblem
self.hess_newwas only initialized inside theif np.any(evals < tolerance)branch.For well-optimized molecules (the normal case), this condition is false and
self.hess_newwas never created.However, it was later used unconditionally for unit conversion, causing:
This prevented the
Bondedclass from being instantiated for typical equilibrium geometries.Solution
Add an
elsebranch to initializeself.hess_newwith a copy of the original Hessian when no eigenvalue correction is required.Change