Skip to main content

geom.alignment_rotation()

Find the rotation that best aligns a reference geometry onto a geometry.

Usage

Source

geom.alignment_rotation(
    geo,
    ref,
)

The rotation is found by the Kabsch algorithm, after moving both centers of mass to the origin. Atoms are matched by index.

Parameters

geo: Geometry

Target geometry.

ref: Geometry
Reference geometry, with the same atoms as geo.

Returns

Rotation

The rotation rot minimizing the RMSD between rotate(center(ref), rot)

and center(geo).

Raises

ValueError
If the geometries have different symbols.

Examples

    >>> ref = Geometry(
    ...     symbols=["O", "H", "H"],
    ...     coordinates=[[0, 0, 0], [1, 0, 0], [0, 1, 0]],
    ...     charge=0,
    ...     spin=0,
    ... )
    >>> rot = Rotation.from_euler("z", 30, degrees=True)
    >>> geo = rotate(ref, rot)
    >>> round(float(alignment_rotation(geo, ref).magnitude()), 6)
0.523599