Skip to content

Use X-H bond axes for united atoms with one hydrogen - #501

Open
michalkrompiec wants to merge 3 commits into
CCPBioSim:mainfrom
michalkrompiec:498-ua-xh-consistent-axes
Open

michalkrompiec wants to merge 3 commits into
CCPBioSim:mainfrom
michalkrompiec:498-ua-xh-consistent-axes

Conversation

@michalkrompiec

@michalkrompiec michalkrompiec commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

For a united atom made of a heavy atom X and one hydrogen, get_custom_moment_of_inertia zeroed the smallest of the three moments about the bonded axes. Those axes are built from the heavy-atom neighbours, so which one has the smallest moment depends on where the hydrogen points, and it can change between frames. One index of the torque covariance then mixes two different rotations. This PR builds the axes of these united atoms from the X-H bond, so the zeroed moment is always the rotation about the bond.

Fixes #498

Changes

  • get_bonded_axes and get_bonded_axes_from_topology: a new case6 for a heavy atom bonded to exactly one hydrogen and at least one heavy atom. Axis1 is along X-H, axis2 is perpendicular to the plane of H, X and the lowest-index bonded heavy atom R1, and axis3 is their cross product (in that plane, towards R1). Both axes paths (local and topology) build the same axes.
  • get_custom_moment_of_inertia: for a two-atom united atom, zero the moment about axis1 (the X-H bond) instead of the smallest moment.
  • case3 now covers one heavy atom with two or more hydrogens and case5 two or more heavy atoms with no or two or more hydrogens; their axes are unchanged.
  • A molecule HX (no heavy neighbour) stays in case1 (principal axes). An exactly collinear H-X-R raises ValueError from get_bonded_vector_axes, as it did before in case3.
  • Docstrings updated.

Testing

  • New unit tests in tests/unit/CodeEntropy/levels/test_axes.py: methanol at C-O-H 108 and 150 degrees, where the smallest moment about the old axes is on different axes, gets axis1 along O-H with a zero moment in both; the N-H of dimethylamine takes axis2 from the lowest-index carbon; the local and topology paths give identical axes and moments for every heavy atom of propanoic acid; united atoms with zero, two or three hydrogens give the same axes and moments as before; HX keeps its principal axes; collinear H-X-R raises.
  • Two existing case3 tests now use two hydrogens, so they still cover case3.
  • Unit tests and pre-commit pass locally.

Impact

  • For an X-H united atom whose X has one heavy neighbour (O-H in an alcohol), the weighted torques, and so the entropies, are unchanged in frames where the old zeroed index stays the same: the torque of the hydrogen about X is perpendicular to X-H, and the two kept components carry the same weighted torque in both frames. They change where the old index switched between frames.
  • For an X-H united atom whose X has two or more heavy neighbours (aromatic C-H, aldehyde C-H, secondary N-H, tertiary C-H), the old axis1 was the sum of the X-R bonds, close to but not along X-H, so part of the torque was dropped. These entropies change.
  • Other united atoms, and axes: principal, are unchanged.
  • Fast regression baselines updated with pytest tests/regression -m "not slow" --update-baselines; only united_atom:Rovibrational (and the total) changes: benzaldehyde selection_subset and combined_forcetorque_false +2.20 J/mol/K, frame_window +0.41; benzene selection_subset and combined_forcetorque_off +1.40, frame_window +0.58; DNA frame_window -0.010 and +0.027 for its two groups; grouping_each (benzaldehyde, benzene, DNA) and DNA selection_subset and combined_forcetorque_off change by less than 0.003 per group. Methanol, octanol and the other systems are unchanged (rounding-level differences were not committed).
  • The slow baselines (default, rad) were not regenerated locally; they will need the Update Regression Baselines workflow on this branch.

Checklist

  • Tests added or updated
  • Documentation updated
  • If dependencies in pyproject.toml changed, the lower bounds were reviewed deliberately

For a united atom of a heavy atom and one hydrogen, the bonded axes were
built from the heavy-atom neighbours and the smallest moment was zeroed.
Which axis had the smallest moment depended on where the hydrogen pointed,
so it could change between frames and one torque covariance index mixed
two rotations.

Build these axes from the X-H bond instead: axis1 along X-H, axis2 from
the lowest-index bonded heavy atom, axis3 their cross product. The zeroed
moment is then always axis1. The cached-topology path uses the same axes.
United atoms with no or more than one hydrogen are unchanged.
Check that the moment about the X-H bond is zeroed on axis1 in frames
where the old smallest-moment axis differs, that both axes paths agree,
and that united atoms without exactly one hydrogen keep their axes.
The fast regression baselines of benzaldehyde, benzene and DNA change in
united_atom:Rovibrational only. Baselines whose only changes were at
floating-point rounding level are left as they were.
@michalkrompiec
michalkrompiec marked this pull request as ready for review November 27, 2026 17:19

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: United atom with one hydrogen: the zeroed moment of inertia can switch axes between frames

1 participant