|
| 1 | +""" |
| 2 | +0.5.x --> 0.6.x Migration Guide |
| 3 | +=============================== |
| 4 | +This is a migration guide for version 0.5.x to 0.6.x. This guide helps to show the changes |
| 5 | +that were made to the API and how to update your code to use the new API. |
| 6 | +
|
| 7 | +Here you can see how to make an equivalent to a diffraction library |
| 8 | +
|
| 9 | +Old |
| 10 | +--- |
| 11 | +""" |
| 12 | + |
| 13 | +import numpy as np |
| 14 | +import matplotlib.pyplot as plt |
| 15 | +from diffpy.structure import Atom, Lattice, Structure |
| 16 | + |
| 17 | +from diffsims.libraries.structure_library import StructureLibrary |
| 18 | +from diffsims.generators.diffraction_generator import DiffractionGenerator |
| 19 | +from diffsims.generators.library_generator import DiffractionLibraryGenerator |
| 20 | + |
| 21 | + |
| 22 | +latt = Lattice(4, 4, 4, 90, 90, 90) |
| 23 | +atoms = [ |
| 24 | + Atom(atype="Al", xyz=[0.0, 0.0, 0.0], lattice=latt), |
| 25 | + Atom(atype="Al", xyz=[0.5, 0.5, 0.0], lattice=latt), |
| 26 | + Atom(atype="Al", xyz=[0.5, 0.0, 0.5], lattice=latt), |
| 27 | + Atom(atype="Al", xyz=[0.0, 0.5, 0.5], lattice=latt), |
| 28 | +] |
| 29 | +structure_matrix = Structure(atoms=atoms, lattice=latt) |
| 30 | +euler_angles = np.array([[0, 0, 0], [10.0, 0.0, 0.0]]) |
| 31 | +struct_library = StructureLibrary(["Al"], [structure_matrix], [euler_angles]) |
| 32 | +diff_gen = DiffractionGenerator(accelerating_voltage=200) |
| 33 | +lib_gen = DiffractionLibraryGenerator(diff_gen) |
| 34 | +diff_lib = lib_gen.get_diffraction_library( |
| 35 | + struct_library, |
| 36 | + calibration=0.0262, |
| 37 | + reciprocal_radius=1.6768, |
| 38 | + half_shape=64, |
| 39 | + with_direct_beam=True, |
| 40 | + max_excitation_error=0.02, |
| 41 | +) |
| 42 | + |
| 43 | +# %% |
| 44 | +# New |
| 45 | +# --- |
| 46 | + |
| 47 | +from orix.crystal_map import Phase |
| 48 | +from orix.quaternion import Rotation |
| 49 | +from diffsims.generators.simulation_generator import SimulationGenerator |
| 50 | + |
| 51 | +latt = Lattice(4, 4, 4, 90, 90, 90) |
| 52 | +atoms = [ |
| 53 | + Atom(atype="Al", xyz=[0.0, 0.0, 0.0], lattice=latt), |
| 54 | + Atom(atype="Al", xyz=[0.5, 0.5, 0.0], lattice=latt), |
| 55 | + Atom(atype="Al", xyz=[0.5, 0.0, 0.5], lattice=latt), |
| 56 | + Atom(atype="Al", xyz=[0.0, 0.5, 0.5], lattice=latt), |
| 57 | +] |
| 58 | +structure_matrix = Structure(atoms=atoms, lattice=latt) |
| 59 | +p = Phase("Al", point_group="m-3m", structure=structure_matrix) |
| 60 | +gen = SimulationGenerator(accelerating_voltage=200) |
| 61 | +rot = Rotation.from_euler([[0, 0, 0], [10.0, 0.0, 0.0]], degrees=True) |
| 62 | +sim = gen.calculate_diffraction2d( |
| 63 | + phase=p, |
| 64 | + rotation=rot, |
| 65 | + reciprocal_radius=1.6768, |
| 66 | + max_excitation_error=0.02, |
| 67 | + with_direct_beam=True, |
| 68 | +) |
| 69 | + |
| 70 | +fig, axs = plt.subplots(2, 2, figsize=(10, 10)) |
| 71 | +for i in range(2): |
| 72 | + diff_lib["Al"]["simulations"][i].plot( |
| 73 | + size_factor=15, show_labels=True, ax=axs[i, 0] |
| 74 | + ) |
| 75 | + sim.irot[i].plot(ax=axs[i, 1], size_factor=15, show_labels=True) |
| 76 | + axs[i, 0].set_xlim(-1.5, 1.5) |
| 77 | + axs[i, 0].set_ylim(-1.5, 1.5) |
| 78 | + axs[i, 1].set_xlim(-1.5, 1.5) |
| 79 | + axs[i, 1].set_ylim(-1.5, 1.5) |
| 80 | + |
| 81 | +_ = axs[0, 0].set_title("Old") |
| 82 | +_ = axs[0, 1].set_title("New") |
| 83 | + |
| 84 | +# %% |
0 commit comments