Skip to content

Correct over-squaring in internal coordinate objective function for adding an atom to XYZ#802

Merged
alongd merged 2 commits intomainfrom
add_atom_fix
Dec 24, 2025
Merged

Correct over-squaring in internal coordinate objective function for adding an atom to XYZ#802
alongd merged 2 commits intomainfrom
add_atom_fix

Conversation

@alongd
Copy link
Copy Markdown
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
Copy Markdown

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.

Comment thread arc/species/converter.py
Comment thread arc/species/converter.py Outdated
@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.
Copy link
Copy Markdown
Contributor

@LeenFahoum LeenFahoum left a comment

Choose a reason for hiding this comment

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

Code looks good. Do we want to keep the comments in the code? (e.g. "wrapped to the range..)

@alongd alongd merged commit 79c2aca into main Dec 24, 2025
6 checks passed
@alongd alongd deleted the add_atom_fix branch December 24, 2025 13:25
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.

3 participants