{"cells": [{"cell_type": "markdown", "id": "ae8a10ff-b625-4c35-9500-19344cd9c7b9", "metadata": {}, "source": ["# Sigma 3 twinning overlaps computer"]}, {"cell_type": "markdown", "metadata": {}, "source": "Source: [docs/sigma_3_twins.ipynb](https://github.com/FABLE-3DXRD/ImageD11/blob/master/docs/sigma_3_twins.ipynb). Executed during the documentation build."}, {"cell_type": "code", "execution_count": null, "id": "8b7c935e-65dd-4038-89b1-0f3bc2ca8f3c", "metadata": {"tags": []}, "outputs": [], "source": ["from scipy.spatial.transform import Rotation\n", "import numpy as np, pylab as pl\n", "import ImageD11.unitcell"]}, {"cell_type": "code", "execution_count": null, "id": "bf62f412-9562-4a1b-b488-5a1d4c8b400e", "metadata": {"tags": []}, "outputs": [], "source": ["# this is the rotation 180 degree around 111 (sigma3 twin)\n", "v = np.array((1,1,1))\n", "n = v / np.linalg.norm(v)\n", "SigmaU = Rotation.from_rotvec(180*n, degrees=True).as_matrix()"]}, {"cell_type": "code", "execution_count": null, "id": "7a58ec93-c0b9-42f6-814e-9d11ef3d80a6", "metadata": {"tags": []}, "outputs": [], "source": ["# peak generation\n", "a = 3.61\n", "uc = ImageD11.unitcell.unitcell([a,a,a,90,90,90], 'F')\n", "uc.makerings( 5 )\n", "hkls = np.concatenate( [ uc.ringhkls[ds] for ds in uc.ringds ] ).T\n", "hkls.shape"]}, {"cell_type": "markdown", "id": "28bf2c94-4be0-4c80-bc92-222fb2607360", "metadata": {}, "source": ["# \n", "g = (UB).h\n", "\n", "h = inv(UB).g = inv(B).inv(U).g\n", "\n", "UB == I\n", "\n", "g = Ut.h\n", "h = Ut.T g\n"]}, {"cell_type": "code", "execution_count": null, "id": "f08f6bf3-31f9-4a1c-a1a8-a05417733fb6", "metadata": {"tags": []}, "outputs": [], "source": ["# this is Utwin . hkl \n", "# we assume the U matrix for the grain is the identity\n", "gcalc = uc.B.dot( hkls )\n", "gtwin = SigmaU.dot( gcalc )"]}, {"cell_type": "code", "execution_count": null, "id": "c5e73595-5eee-4d41-bf04-f48c4c805be7", "metadata": {"tags": []}, "outputs": [], "source": ["pl.figure()\n", "pl.plot( gcalc[0], gcalc[1], '+')\n", "pl.plot( gtwin[0], gtwin[1], '.')"]}, {"cell_type": "code", "execution_count": null, "id": "b0aa888c-bfc8-4488-b6d9-8f19fbc9a3e6", "metadata": {"tags": []}, "outputs": [], "source": ["ubi = np.linalg.inv( uc.B )\n", "h = hindexed_from_twin = ubi.dot( gtwin )\n", "olaps = ((h - np.round(h))**2).sum(axis=0) < 0.05"]}, {"cell_type": "code", "execution_count": null, "id": "da7f44eb-4873-4df8-8b23-fc67d7fe8ca9", "metadata": {"tags": []}, "outputs": [], "source": ["modh = (hkls**2).sum(axis=0)"]}, {"cell_type": "code", "execution_count": null, "id": "cf17eb23-c87c-4608-8b45-9ef8d495e3c7", "metadata": {"tags": []}, "outputs": [], "source": ["pl.hist(modh,bins = modh.max()*2)\n", "pl.hist(modh[olaps],bins = modh.max()*2);"]}, {"cell_type": "code", "execution_count": null, "id": "9d37f73f-15b7-4aca-a932-2fd8a3d58f58", "metadata": {"tags": []}, "outputs": [], "source": ["order = np.argsort( modh )\n", "c= 0\n", "print(\"#sum(h^2) [h k l] multiplicity #overlaps_percent\")\n", "for i in order:\n", " if modh[i] == c: # dont print M times the same\n", " continue\n", " c = modh[i]\n", " m = (modh[i] == modh)\n", " print( \"( %2d %2d %2d )\"%tuple(hkls[:,i]), \"%5d %5d %5d\"%(m.sum(), m[olaps].sum(), 100*m[olaps].sum()/m.sum(), ))"]}, {"cell_type": "code", "execution_count": null, "id": "0a724613-f404-49e6-868e-8a8d38501a4f", "metadata": {}, "outputs": [], "source": []}, {"cell_type": "code", "execution_count": null, "id": "f184e0f5-de41-423a-8a88-61d9b93f460d", "metadata": {}, "outputs": [], "source": []}], "metadata": {"kernelspec": {"display_name": "Python 3 (main)", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.6"}, "widgets": {"application/vnd.jupyter.widget-state+json": {"state": {}, "version_major": 2, "version_minor": 0}}}, "nbformat": 4, "nbformat_minor": 5}