def get_orientations_from_stereographic_triangle(self, inplane_rotations, resolution): """ Create a structure library from the stereographic triangles of the given crystal systems. Parameters ---------- inplane_rotations : list List over identifiers of lists of inplane rotations of the diffraction patterns, in degrees. resolution : float Rotation list resolution in degrees. Returns ------- structure_library : StructureLibrary Structure library for the given phase names, structures and crystal system. """ rotation_lists = [ rotation_list_stereographic(structure, *stereographic_corners[system], np.deg2rad(inplane_rotation), np.deg2rad(resolution)) for phase_name, structure, system, inplane_rotation in zip( self.phase_names, self.structures, self.systems, inplane_rotations) ] return StructureLibrary(self.phase_names, self.structures, rotation_lists)
def get_library(default_structure): diffraction_calculator = DiffractionGenerator(300., 0.02) dfl = DiffractionLibraryGenerator(diffraction_calculator) structure_library = StructureLibrary(['Phase'], [default_structure], [np.array([(0, 0, 0), (0, 0.2, 0)])]) return dfl.get_diffraction_library(structure_library, 0.017, 2.4, (72, 72))
def test_from_systems_methods(): identifiers = ["a", "b"] structures = [1, 2] systems = ["cubic", "hexagonal"] library = StructureLibrary.from_crystal_systems(identifiers, structures, systems, resolution=2)
def test_from_orientations_method(): identifiers = ['a', 'b'] structures = [1, 2] orientations = [3, 4] library = StructureLibrary.from_orientation_lists(identifiers, structures, orientations) np.testing.assert_equal(library.identifiers, identifiers) np.testing.assert_equal(library.structures, structures) np.testing.assert_equal(library.orientations, orientations) np.testing.assert_equal(library.struct_lib['a'], (1, 3)) np.testing.assert_equal(library.struct_lib['b'], (2, 4))
def test_library_phases(): latt = diffpy.structure.lattice.Lattice(3, 3, 3, 90, 90, 90) atom = diffpy.structure.atom.Atom(atype="Ni", xyz=[0, 0, 0], lattice=latt) structure = diffpy.structure.Structure(atoms=[atom], lattice=latt) library_phases_test = StructureLibrary( ["Test"], [structure], [np.array([(0, 0, 90), (0, 44, 90), (0, 54.735, 45)])], ) return library_phases_test
def test_from_systems_methods(): identifiers = ["a", "b"] structures = [1, 2] systems = ["cubic", "hexagonal"] library = StructureLibrary.from_crystal_systems(identifiers, structures, systems, resolution=2, equal="angle") assert len(library.struct_lib["a"][1]) < len( library.struct_lib["b"][1]) # cubic is less area the hexagonal
def test_constructor(): identifiers = ['a', 'b'] # Arbitrary values for tracking structures = [1, 2] orientations = [3, 4] library = StructureLibrary(identifiers, structures, orientations) np.testing.assert_equal(library.identifiers, identifiers) np.testing.assert_equal(library.structures, structures) np.testing.assert_equal(library.orientations, orientations) np.testing.assert_equal(library.struct_lib['a'], (1, 3)) np.testing.assert_equal(library.struct_lib['b'], (2, 4))
def get_template_library(structure, rot_list, edc): diff_gen = pxm.DiffractionLibraryGenerator(edc) struc_lib = StructureLibrary(['A'], [structure], [rot_list]) library = diff_gen.get_diffraction_library(struc_lib, calibration=1 / half_side_length, reciprocal_radius=0.8, half_shape=(half_side_length, half_side_length), with_direct_beam=False) library.diffraction_generator = edc library.reciprocal_radius = 0.8 library.with_direct_beam = False return library
def get_orientations_from_list(self, orientations): """Create a structure library from a list of rotations. Parameters ---------- orientations : list A list over identifiers of lists of euler angles (as tuples) in the rzxz convention and in degrees. Returns ------- structure_library : StructureLibrary Structure library for the given phase names, structures and orientations. """ return StructureLibrary(self.phase_names, self.structures, orientations)
def test_library_phases_multi(): ni_structure = diffpy.structure.Structure( atoms=[diffpy.structure.atom.Atom(atype="Ni", xyz=[0, 0, 0])], lattice=diffpy.structure.lattice.Lattice(3, 3, 3, 90, 90, 90)) al_structure = diffpy.structure.Structure( atoms=[diffpy.structure.atom.Atom(atype="Al", xyz=[0, 0, 0])], lattice=diffpy.structure.lattice.Lattice(4, 4, 4, 90, 90, 90)) library_phases_test = StructureLibrary( ["Ni", "Al"], [ni_structure, al_structure], [ np.array([(0, 0, 90), (0, 44, 90), (0, 54.735, 45)]), np.array([(45, 45, 90), (45, 90, 45), (90, 45, 0)]), ], ) return library_phases_test
def test_TemplateIndexationGenerator(default_structure, method): identifiers = ["a", "b"] structures = [default_structure, default_structure] orientations = [[(0, 0, 0), (0, 1, 0), (1, 0, 0)], [(0, 0, 1), (0, 0, 2), (0, 0, 3)]] structure_library = StructureLibrary(identifiers, structures, orientations) libgen = DiffractionLibraryGenerator(DiffractionGenerator(300)) library = libgen.get_diffraction_library(structure_library, 0.017, 0.02, (100, 100), False) edp = ElectronDiffraction2D(np.random.rand(2, 2, 200, 200)) indexer = TemplateIndexationGenerator(edp, library) z = indexer.correlate(method=method, n_largest=2) assert isinstance(z, TemplateMatchingResults) assert isinstance(z.data, Signal2D) assert z.data.data.shape[0:2] == edp.data.shape[0:2] assert z.data.data.shape[3] == 5
def get_vector_match_results(structure, rot_list, edc): diffraction_library = get_template_library(structure, rot_list, edc) peak_lists = [] for pixel_coords in diffraction_library['A']['pixel_coords']: peak_lists.append(pixel_coords) peaks = DiffractionVectors((np.array([peak_lists, peak_lists]) - half_side_length) / half_side_length) peaks.axes_manager.set_signal_dimension(2) peaks.calculate_cartesian_coordinates(200, 0.2) peaks.cartesian.axes_manager.set_signal_dimension(2) structure_library = StructureLibrary(['A'], [structure], [[]]) library_generator = VectorLibraryGenerator(structure_library) vector_library = library_generator.get_vector_library(1) indexation_generator = VectorIndexationGenerator(peaks, vector_library) indexation = indexation_generator.index_vectors( mag_tol=1.5 / half_side_length, angle_tol=1, index_error_tol=0.2, n_peaks_to_index=5, n_best=2) return diffraction_library, indexation
def test_TemplateMatchingResults_plot_best_results_on_signal( diffraction_pattern, default_structure): """ Coverage testing """ edc = ds.DiffractionGenerator(300, 5e-2) half_side_length = 4 rot_list = [[0, 1, 0], [1, 0, 0]] diff_gen = ds.DiffractionLibraryGenerator(edc) struc_lib = StructureLibrary(["A"], [default_structure], [rot_list]) library = diff_gen.get_diffraction_library( struc_lib, calibration=1 / half_side_length, reciprocal_radius=0.8, half_shape=(half_side_length, half_side_length), with_direct_beam=True, ) indexer = TemplateIndexationGenerator(diffraction_pattern, library) match_results = indexer.correlate() match_results.plot_best_matching_results_on_signal(diffraction_pattern, library=library) plt.close("all")
def structure_library(default_structure): return StructureLibrary(["Si"], [default_structure], [[(0, 0, 0), (0.1, 0.1, 0)]])
def test_constructor_parameter_validation_errors(identifiers, structures, orientations): StructureLibrary(identifiers, structures, orientations)
def test_from_systems_methods(): identifiers = ['a', 'b'] structures = [1, 2] systems = ['cubic', 'hexagonal'] library = StructureLibrary.from_crystal_systems(identifiers, structures, systems, resolution=2, equal='angle') assert len(library.struct_lib['a'][1]) < len(library.struct_lib['b'][1]) # cubic is less area the hexagonal
def get_library(default_structure): structure_library = StructureLibrary(['Phase'], [default_structure], [[(0, 0, 0), (0, 0.2, 0)]]) vlg = VectorLibraryGenerator(structure_library) return vlg.get_vector_library(0.5)
def test_get_library_size(): identifiers = ["a", "b"] structures = [1, 2] orientations = [[(0, 0, 0), (0.0, 90.0, -180.0)], [(0, 0, 0)]] library = StructureLibrary(identifiers, structures, orientations) assert library.get_library_size(to_print=True) == 3