.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/misorientations/misorientation_from_aligning_directions.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_misorientations_misorientation_from_aligning_directions.py: ======================================= Misorientation from aligning directions ======================================= This example demonstrates how to use :meth:`~orix.quaternion.Misorientation.from_align_vectors` to estimate a misorientation :math:`M` from two sets of aligned crystal directions :math:`t_{1,2}`, one set in each crystal reference frame :math:`(e_1, e_2, e_3)`. .. GENERATED FROM PYTHON SOURCE LINES 11-78 .. image-sg:: /examples/misorientations/images/sphx_glr_misorientation_from_aligning_directions_001.png :alt: misorientation from aligning directions :srcset: /examples/misorientations/images/sphx_glr_misorientation_from_aligning_directions_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Vector angular deviation [deg]: 7.1025833620124 Error distance: 0.1710643081829647 | .. code-block:: Python from diffpy.structure import Lattice, Structure import matplotlib.pyplot as plt import numpy as np from orix.crystal_map import Phase from orix.quaternion import Misorientation, Orientation from orix.vector import Miller plt.rcParams.update({"figure.figsize": (5, 5), "lines.markersize": 8}) # Specify a cubic and an hexagonal crystal structures and symmetries phase1 = Phase( point_group="m-3m", structure=Structure(lattice=Lattice(1, 1, 1, 90, 90, 90)), ) phase2 = Phase( point_group="6/mmm", structure=Structure(lattice=Lattice(1, 1, 2, 90, 90, 120)), ) # Specify one orientation per crystal O_cubic = Orientation.from_axes_angles( [1, 1, 1], -60, symmetry=phase1.point_group, degrees=True ) O_hex = Orientation.from_axes_angles( [1, 3, 2], -90, symmetry=phase2.point_group, degrees=True ) # Get the reference misorientation (goal). Misorientations are obtained # from the right, so: crystal 1 -> sample -> crystal 2 M_ref = Misorientation(O_hex * ~O_cubic, symmetry=(O_cubic.symmetry, O_hex.symmetry)) # Specify two directions in the first crystal t_cubic = Miller(uvw=[[1, 1, 1], [0, 0, 1]], phase=phase1) # Express the same directions with respect to the second crystal [in the # Cartesian reference frame, (e1, e2, e3)] v_hex = Miller(xyz=(M_ref * t_cubic).data, phase=phase2) # Add some randomness to the second crystal directions (0 error # magnitude gives exact result) error_magnitude = 0.1 v_err = Miller(xyz=np.random.normal(0, error_magnitude, 3), phase=phase2) v_hex_err = Miller(xyz=(v_hex + v_err).data, phase=phase2) angle_err = v_hex_err.angle_with(v_hex, degrees=True).mean() print("Vector angular deviation [deg]: ", angle_err) # Get the misorientation that aligns the directions in the first crystal # with those in the second crystal M_new, err = Misorientation.from_align_vectors(v_hex_err, t_cubic, return_rmsd=True) print("Error distance: ", err) # Plot the two directions in the (unrotated) first crystal's reference # frame as open circles fig = t_cubic.scatter( c="none", ec=["r", "b"], grid=True, axes_labels=["e1", "e2"], return_figure=True, figure_kwargs={"layout": "tight"}, ) # Plot the two directions in the second crystal with respect to the # first crystal's axes (~M_ref * v_hex_err).scatter(c=["r", "b"], figure=fig) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.524 seconds) **Estimated memory usage:** 10 MB .. _sphx_glr_download_examples_misorientations_misorientation_from_aligning_directions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: misorientation_from_aligning_directions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: misorientation_from_aligning_directions.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_