Correct over-squaring in internal coordinate objective function for adding an atom to XYZ #802
+8
−3
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.
The objective function for adding a new atom previously led to over-penalization of angular errors (effectively minimizing the error to the fourth power). This was due to the angular constraint functions (g_theta and g_phi) already returning squared errors, which were then squared again in the final objective function.
This commit refactors the constraint functions to return the linear error or linear error magnitude:
angle_constraint
: Now returns the linear difference (calc_angle - target_angle).dihedral_constraint
: Now returns the magnitude of the sine/cosine error vector (square root of the squared sum).The main objective function remains structurally the same (sum of squared, scaled terms), but now correctly implements a standard relative squared error minimization.