Skip to content

Conversation

alongd
Copy link
Member

@alongd alongd commented Sep 30, 2025

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.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an over-squaring issue in the internal coordinate objective function used when adding atoms to XYZ structures. The angular constraint functions were returning squared errors that were then squared again in the objective function, leading to fourth-power minimization instead of the intended squared error minimization.

Key changes:

  • Refactored angle_constraint to return linear difference instead of squared error
  • Modified dihedral_constraint to return magnitude of error vector instead of squared sum
  • Added precision constants to improve code maintainability

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@alongd alongd changed the title Correct over-squaring in internal coordinate objective function for addiong an atom to XYZ Correct over-squaring in internal coordinate objective function for adding an atom to XYZ Sep 30, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant