Skip to content

RMSD and Rotational Constants Modules #230

Merged
haneug merged 28 commits into
faccts:mainfrom
crjacinto:feature-rmsd
Jul 13, 2026
Merged

RMSD and Rotational Constants Modules #230
haneug merged 28 commits into
faccts:mainfrom
crjacinto:feature-rmsd

Conversation

@crjacinto

@crjacinto crjacinto commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Closes Issues

Closes #220 #219

Description

  • Class methods to calculate the RMSD between two structures and the rotational spectrum (rotor type, moments of inertia and rotational constants) of a molecule.

Release Notes

Added

@crjacinto
crjacinto requested a review from a team as a code owner April 17, 2026 12:13
@crjacinto crjacinto changed the title RMSD and Rotationl Constants Modules WIP: RMSD and Rotationl Constants Modules Apr 17, 2026
@crjacinto crjacinto changed the title WIP: RMSD and Rotationl Constants Modules WIP: RMSD and Rotational Constants Modules Apr 17, 2026
@crjacinto crjacinto changed the title WIP: RMSD and Rotational Constants Modules RMSD and Rotational Constants Modules Apr 17, 2026
@timmyte
timmyte self-requested a review April 20, 2026 13:02

@timmyte timmyte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Solid first PR.
But the tools are bit to decoupled from OPI. You should use and add to the data structures that we already have in OPI.

Comment thread src/opi/utils/rmsd.py Outdated
Comment thread src/opi/utils/rmsd.py Outdated
Comment thread src/opi/utils/rmsd.py Outdated
Comment thread src/opi/utils/rmsd.py Outdated
Comment thread src/opi/utils/rmsd.py Outdated
Comment thread src/opi/utils/rotconst.py Outdated
Comment thread src/opi/utils/rmsd.py Outdated
Comment thread src/opi/utils/rotconst.py Outdated
Comment thread src/opi/utils/rotconst.py Outdated
Comment thread src/opi/utils/rotconst.py Outdated
@timmyte

timmyte commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

As discussed, I would design the RMSD function as follows:

class Structure:
    def rmsd(self, other: Structure, /, only_atoms: Sequence[int] = (), *, ignore_hs: bool = False) -> float:
        return _rmsd(self.coordinates, other.coordinates, only_atoms=only_atoms, ignore_hs=ignore_hs)

    def _rmsd(coords1: NDArray[float], coords2: NDArray[float], /, only_atoms: Sequence[int] = (), *, ignore_hs: bool = False)
        # We ignore `ignore_hs` if `only_atoms` is populated. This should also be documented
        if coords1.shape != coords2.shape:
            raise ValueError

    def rmsd_kabsch(self, other: Structure, /, only_atoms: Sequence[int] = (), *, ignore_hs: bool = False) -> float:
        # 1) Translate to center of geometry (centroid)
        # 2) find optimal rotation

        # `only_atoms` and `ignore_hs` don't need to be passed here anymore as `coords1` and `coords2_rotated` should only contain the coordinates of the relevant atoms.
        return _rmsd(coords1, coords2_rotated)

@timmyte timmyte assigned timmyte and crjacinto and unassigned timmyte Apr 28, 2026
@crjacinto
crjacinto requested a review from timmyte May 6, 2026 14:12

@timmyte timmyte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very nice improvement of the code. We are getting there.
I really appreciate how well you documented the code.

Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/utils/rotconst.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
@crjacinto
crjacinto requested a review from timmyte May 19, 2026 18:24

@timmyte timmyte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for tackling my remarks. There are still some unresolved issues though.

Please also see the few additional points I raised.

Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread tests/unit/test_rmsd.py Outdated
@crjacinto
crjacinto requested a review from timmyte May 22, 2026 14:17

@timmyte timmyte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. Please consider my last remark before merging.
I also would like to get @haneug opinion on the API with all the different weight parameters

Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/utils/rotconst.py Outdated
@timmyte
timmyte requested a review from haneug June 2, 2026 14:08

@timmyte timmyte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very good, especially the exhaustive amount of tests. BRAVO!

Comment thread src/opi/input/structures/structure.py
Comment thread src/opi/input/structures/structure.py
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread tests/unit/test_structure_rmsd.py
Comment thread tests/unit/test_structure_rmsd.py
Comment thread tests/unit/test_structure_rmsd.py
Comment thread tests/unit/test_structure_rmsd.py
Comment thread tests/unit/test_rotconst.py Outdated

@timmyte timmyte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for quickly tackling my remarks. But please make sure you addressed all of them.

Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
Comment thread src/opi/input/structures/structure.py
Comment thread src/opi/utils/rotconst.py
Comment thread tests/unit/test_rmsd.py Outdated
@crjacinto
crjacinto requested a review from timmyte July 2, 2026 13:54

@haneug haneug left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please address all of the comments by Tim and resolve them when they are resolved. I added some more. Also in PR message on its own you should only add to the section Added and do not describe stuff that changed within the PR.
Edit: If they are just regular comments and you cannot resolve them thumps up also works for me to see that you addressed them.

Comment thread tests/unit/test_structure_rmsd.py
Comment thread src/opi/utils/constants.py
Comment thread tests/unit/test_rotconst.py Outdated
Comment thread src/opi/input/structures/structure.py Outdated
…d speed of light units. Cleaned up unit tests for RMSD and RotConst. Modifed changelog
@crjacinto
crjacinto requested a review from haneug July 10, 2026 15:17
@haneug
haneug removed the request for review from timmyte July 13, 2026 10:19

@haneug haneug left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Really nice PR! I just made some small style changes and will merge this now.

@haneug
haneug dismissed timmyte’s stale review July 13, 2026 10:22

Handed this to HN for review

@haneug
haneug merged commit addb0ee into faccts:main Jul 13, 2026
6 checks passed
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.

RMSD between Structure Objects

3 participants