From c05a541d8caf03b7c7b7baf8d9523c29dba67932 Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 13:20:39 +0000 Subject: [PATCH 01/13] Deletion --- diffsims/generators/structure_library_generator.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/diffsims/generators/structure_library_generator.py b/diffsims/generators/structure_library_generator.py index 5bb5a428..5d43aa5a 100644 --- a/diffsims/generators/structure_library_generator.py +++ b/diffsims/generators/structure_library_generator.py @@ -23,17 +23,6 @@ """Generating structure libraries.""" -# Inverse pole figure corners for crystal systems -stereographic_corners = { - 'cubic': [(0, 0, 1), (1, 0, 1), (1, 1, 1)], - 'hexagonal': [(0, 0, 0, 1), (1, 0, -1, 0), (1, 1, -2, 0)], - 'orthorhombic': [(0, 0, 1), (1, 0, 0), (0, 1, 0)], - 'tetragonal': [(0, 0, 1), (1, 0, 0), (1, 1, 0)], - 'trigonal': [(0, 0, 0, 1), (0, -1, 1, 0), (1, -1, 0, 0)], - 'monoclinic': [(0, 0, 1), (0, 1, 0), (0, -1, 0)] -} - - class StructureLibraryGenerator: """Generates a structure library for the given phases From ff1e98e4109dccdc6bbffee922ebc20198d96662 Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 13:22:27 +0000 Subject: [PATCH 02/13] Change imports --- diffsims/generators/structure_library_generator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diffsims/generators/structure_library_generator.py b/diffsims/generators/structure_library_generator.py index 5d43aa5a..5c476ef1 100644 --- a/diffsims/generators/structure_library_generator.py +++ b/diffsims/generators/structure_library_generator.py @@ -19,7 +19,8 @@ import numpy as np from diffsims.libraries.structure_library import StructureLibrary -from diffsims.utils.sim_utils import rotation_list_stereographic +from diffsims.generators.rotation_list_generators import get_grid_streographic + """Generating structure libraries.""" From 824221b47baaf1a25752e208b63020dd9975129f Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 13:39:15 +0000 Subject: [PATCH 03/13] Delete StructureLibraryGenerator and replace with classmethods for StructureLibrary --- .../generators/structure_library_generator.py | 99 ------------------- diffsims/libraries/structure_library.py | 49 +++++++++ 2 files changed, 49 insertions(+), 99 deletions(-) diff --git a/diffsims/generators/structure_library_generator.py b/diffsims/generators/structure_library_generator.py index 5c476ef1..e69de29b 100644 --- a/diffsims/generators/structure_library_generator.py +++ b/diffsims/generators/structure_library_generator.py @@ -1,99 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2017-2019 The diffsims developers -# -# This file is part of diffsims. -# -# diffsims is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# diffsims is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with diffsims. If not, see . - -import numpy as np - -from diffsims.libraries.structure_library import StructureLibrary -from diffsims.generators.rotation_list_generators import get_grid_streographic - - -"""Generating structure libraries.""" - -class StructureLibraryGenerator: - """Generates a structure library for the given phases - - Parameters - ---------- - phases : list - Array of three-component phase descriptions, where the phase - description is [ : string, : - diffpy.structure.Structure, : string], and crystal - system is one of 'cubic', 'hexagonal', 'orthorhombic', 'tetragonal', - 'trigonal', 'monoclinic'. - - Attributes - ---------- - phase_names : list of string - List of phase names. - structures : list of diffpy.structure.Structure - List of structures. - systems : list of string - List of crystal systems. - - Examples - -------- - >>> gen = StructureLibraryGenerator([ - ... ('ZB', structure_zb, 'cubic'), - ... ('WZ', structure_wz, 'hexagonal')]) - """ - - def __init__(self, phases): - self.phase_names = [phase[0] for phase in phases] - self.structures = [phase[1] for phase in phases] - self.systems = [phase[2] for phase in phases] - - 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 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) diff --git a/diffsims/libraries/structure_library.py b/diffsims/libraries/structure_library.py index b81f0f07..386cb02a 100644 --- a/diffsims/libraries/structure_library.py +++ b/diffsims/libraries/structure_library.py @@ -17,6 +17,7 @@ # along with diffsims. If not, see . import diffsims as ds +from diffsims.generators.rotation_list_generators import get_grid_streographic class StructureLibrary(): @@ -54,3 +55,51 @@ def __init__(self, self.struct_lib = dict() for ident, struct, ori in zip(identifiers, structures, orientations): self.struct_lib[ident] = (struct, ori) + + @classmethod + def from_orientation_lists(cls,identifiers,structures,orientations): + """ + Creates a structure library from "manual" orientation lists + + Parameters + ---------- + identifiers : list of strings/ints + A list of phase identifiers referring to different atomic structures. + structures : list of diffpy.structure.Structure objects. + A list of diffpy.structure.Structure objects describing the atomic + structure associated with each phase in the library. + orientations : list + A list over identifiers of lists of euler angles (as tuples) in the rzxz + convention and in degrees. + Returns + ------- + StructureLibrary + """ + return cls(identifier,structure,orientations) + + @classmethod + def from_crystal_systems(cls,identifier,structures,systems,resolution,equal='angle'): + """ + Creates a structure library from crystal system derived orientation lists + + Parameters + ---------- + identifiers : list of strings/ints + A list of phase identifiers referring to different atomic structures. + structures : list of diffpy.structure.Structure objects. + A list of diffpy.structure.Structure objects describing the atomic + structure associated with each phase in the library. + systems : list + A list over indetfiers of crystal systems + resolution : float + resolution in degrees + equal : str + Default is 'angle' + Returns + ------- + StructureLibrary + """ + orientations = [] + for system in systems: + orientations.append(get_grid_streographic(system,resolution,equal)) + return cls(identifier,structure,orientations) From 3d2cf07f331a6bb06c98561c309666a6839e6447 Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 13:39:59 +0000 Subject: [PATCH 04/13] Delete old implementation of streographic triangles --- diffsims/utils/sim_utils.py | 110 +----------------------------------- 1 file changed, 1 insertion(+), 109 deletions(-) diff --git a/diffsims/utils/sim_utils.py b/diffsims/utils/sim_utils.py index 5adbd837..b0bc7fd9 100644 --- a/diffsims/utils/sim_utils.py +++ b/diffsims/utils/sim_utils.py @@ -372,7 +372,7 @@ def simulate_rotated_structure(diffraction_generator, structure, rotation_matrix stdbase = structure.lattice.stdbase stdbase_inverse = np.linalg.inv(stdbase) rotation_matrix_diffpy = stdbase_inverse @ rotation_matrix @ stdbase - + lattice_rotated = diffpy.structure.lattice.Lattice( *structure.lattice.abcABG(), baserot=rotation_matrix_diffpy) @@ -458,111 +458,3 @@ def uvtw_to_uvw(uvtw): u, v, w = 2 * u + v, 2 * v + u, w common_factor = math.gcd(math.gcd(u, v), w) return tuple((int(x / common_factor)) for x in (u, v, w)) - - -def rotation_list_stereographic(structure, corner_a, corner_b, corner_c, - inplane_rotations, resolution): - """Generate a rotation list covering the inverse pole figure specified by - three corners in cartesian coordinates. - - Parameters - ---------- - structure : diffpy.structure.Structure - Structure for which to calculate the rotation list. - corner_a, corner_b, corner_c : tuple - The three corners of the inverse pole figure, each given by a - three-dimensional coordinate. The coordinate system is given by the - structure lattice. - inplane_rotations : list - List of angles in radians for in-plane rotation of the diffraction - pattern. This corresponds to the third Euler angle rotation. The - rotation list will be generated for each of these angles, and combined. - This should be done automatically, but by including all possible - rotations in the rotation list, it becomes too large. - - To cover all inplane rotations, use e.g. np.linspace(0, 2*np.pi, 360). - resolution : float - Angular resolution in radians of the generated rotation list. - - Returns - ------- - rotation_list : numpy.array - Rotations covering the inverse pole figure given as an array of Euler - angles in degrees. - """ - # Convert the crystal directions to cartesian vectors and normalize - if len(corner_a) == 4: - corner_a = uvtw_to_uvw(corner_a) - if len(corner_b) == 4: - corner_b = uvtw_to_uvw(corner_b) - if len(corner_c) == 4: - corner_c = uvtw_to_uvw(corner_c) - - lattice = structure.lattice - - corner_a = np.dot(corner_a, lattice.stdbase) - corner_b = np.dot(corner_b, lattice.stdbase) - corner_c = np.dot(corner_c, lattice.stdbase) - - corner_a /= np.linalg.norm(corner_a) - corner_b /= np.linalg.norm(corner_b) - corner_c /= np.linalg.norm(corner_c) - - angle_a_to_b = get_angle_cartesian(corner_a, corner_b) - angle_a_to_c = get_angle_cartesian(corner_a, corner_c) - angle_b_to_c = get_angle_cartesian(corner_b, corner_c) - axis_a_to_b = np.cross(corner_a, corner_b) - axis_a_to_c = np.cross(corner_a, corner_c) - - # Input validation. The corners have to define a non-degenerate triangle - if np.count_nonzero(axis_a_to_b) == 0: - raise ValueError('Directions a and b are parallel') - if np.count_nonzero(axis_a_to_c) == 0: - raise ValueError('Directions a and c are parallel') - - rotations = [] - - # Generate a list of theta_count evenly spaced angles theta_b in the range - # [0, angle_a_to_b] and an equally long list of evenly spaced angles - # theta_c in the range[0, angle_a_to_c]. - # Ensure that we keep the resolution also along the direction to the corner - # b or c farthest away from a. - theta_count = math.ceil(max(angle_a_to_b, angle_a_to_c) / resolution) - for i, (theta_b, theta_c) in enumerate( - zip(np.linspace(0, angle_a_to_b, theta_count), - np.linspace(0, angle_a_to_c, theta_count))): - # Define the corner local_b at a rotation theta_b from corner_a toward - # corner_b on the circle surface. Similarly, define the corner local_c - # at a rotation theta_c from corner_a toward corner_c. - - rotation_a_to_b = axangle2mat(axis_a_to_b, theta_b) - rotation_a_to_c = axangle2mat(axis_a_to_c, theta_c) - local_b = np.dot(rotation_a_to_b, corner_a) - local_c = np.dot(rotation_a_to_c, corner_a) - - # Then define an axis and a maximum rotation to create a great cicle - # arc between local_b and local_c. Ensure that this is not a degenerate - # case where local_b and local_c are coincident. - angle_local_b_to_c = get_angle_cartesian(local_b, local_c) - axis_local_b_to_c = np.cross(local_b, local_c) - if np.count_nonzero(axis_local_b_to_c) == 0: - # Theta rotation ended at the same position. First position, might - # be other cases? - axis_local_b_to_c = corner_a - axis_local_b_to_c /= np.linalg.norm(axis_local_b_to_c) - - # Generate points along the great circle arc with a distance defined by - # resolution. - phi_count_local = max(math.ceil(angle_local_b_to_c / resolution), 1) - for j, phi in enumerate( - np.linspace(0, angle_local_b_to_c, phi_count_local)): - rotation_phi = axangle2mat(axis_local_b_to_c, phi) - - for k, psi in enumerate(inplane_rotations): - # Combine the rotations. Order is important. The matrix is - # applied from the left, and we rotate by theta first toward - # local_b, then across the triangle toward local_c - rotation = list(mat2euler(rotation_phi @ rotation_a_to_b, 'rzxz')) - rotations.append(np.rad2deg([rotation[0], rotation[1], psi])) - - return np.unique(rotations, axis=0) From 2743ab0fc283e89d617f70f5008a9ef4e85fd3f3 Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 13:41:26 +0000 Subject: [PATCH 05/13] Delete one reference to old streographic implementation --- diffsims/tests/test_utils/test_sim_utils.py | 65 +-------------------- 1 file changed, 1 insertion(+), 64 deletions(-) diff --git a/diffsims/tests/test_utils/test_sim_utils.py b/diffsims/tests/test_utils/test_sim_utils.py index ca8c613a..107774cf 100644 --- a/diffsims/tests/test_utils/test_sim_utils.py +++ b/diffsims/tests/test_utils/test_sim_utils.py @@ -23,8 +23,7 @@ from diffsims.utils.sim_utils import get_electron_wavelength, \ get_interaction_constant, get_unique_families, get_kinematical_intensities, \ get_vectorized_list_for_atomic_scattering_factors, get_points_in_sphere, \ - simulate_kinematic_scattering, is_lattice_hexagonal, uvtw_to_uvw, \ - rotation_list_stereographic + simulate_kinematic_scattering, is_lattice_hexagonal, uvtw_to_uvw def create_lattice_structure(a, b, c, alpha, beta, gamma): @@ -143,65 +142,3 @@ def test_kinematic_simulator_invalid_illumination(): def test_uvtw_to_uvw(uvtw, uvw): val = uvtw_to_uvw(uvtw) np.testing.assert_almost_equal(val, uvw) - - -# Three corners of the rotation lists, for comparison -structure_cubic_rotations = [ - [0, 0, 0], - [90, 45, 0], - [135, 54.73561032, 0] -] - -structure_hexagonal_rotations = [ - [0, 0, 0], - [90, 90, 0], - [120, 90, 0] -] - -structure_orthogonal_rotations = [ - [0, 0, 0], - [90, 90, 0], - [180, 90, 0] -] - -structure_tetragonal_rotations = [ - [0, 0, 0], - [90, 90, 0], - [135, 90, 0] -] - -structure_trigonal_rotations = [ - [0, 0, 0], - [-28.64458044, 75.45951959, 0], - [38.93477108, 90, 0] -] - -structure_monoclinic_rotations = [ - [0, 0, 0], - [0, 90, 0], - [180, 90, 0] -] - - -@pytest.mark.parametrize('structure, corner_a, corner_b, corner_c, rotation_list', [ - (create_structure_cubic(), (0, 0, 1), (1, 0, 1), (1, 1, 1), structure_cubic_rotations), - (create_structure_hexagonal(), (0, 0, 0, 1), (1, 0, -1, 0), (1, 1, -2, 0), structure_hexagonal_rotations), - (create_structure_orthorombic(), (0, 0, 1), (1, 0, 0), (0, 1, 0), structure_orthogonal_rotations), - (create_structure_tetragonal(), (0, 0, 1), (1, 0, 0), (1, 1, 0), structure_tetragonal_rotations), - (create_structure_trigonal(), (0, 0, 0, 1), (0, -1, 1, 0), (1, -1, 0, 0), structure_trigonal_rotations), - (create_structure_monoclinic(), (0, 0, 1), (0, 1, 0), (0, -1, 0), structure_monoclinic_rotations), -]) -def test_rotation_list_stereographic(structure, corner_a, corner_b, corner_c, rotation_list): - val = rotation_list_stereographic(structure, corner_a, corner_b, corner_c, [0], np.deg2rad(10)) - for expected in rotation_list: - assert any((np.allclose(expected, actual) for actual in val)) - - -@pytest.mark.xfail(raises=ValueError) -@pytest.mark.parametrize('structure, corner_a, corner_b, corner_c, inplane_rotations, resolution, rotation_list', [ - (create_structure_cubic(), (0, 0, 1), (0, 0, 1), (1, 1, 1), [0], np.deg2rad(10), structure_cubic_rotations), - (create_structure_cubic(), (0, 0, 1), (1, 0, 1), (0, 0, 1), [0], np.deg2rad(10), structure_cubic_rotations) -]) -def test_rotation_list_stereographic_raises_invalid_corners( - structure, corner_a, corner_b, corner_c, inplane_rotations, resolution, rotation_list): - rotation_list_stereographic(structure, corner_a, corner_b, corner_c, inplane_rotations, resolution) From 737e5dd896b3bd02b25fefbf4e9e68fe89f32938 Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 13:43:53 +0000 Subject: [PATCH 06/13] Delete structure_libaray_generator --- .../generators/structure_library_generator.py | 0 .../test_structure_library_generator.py | 44 ------------------- 2 files changed, 44 deletions(-) delete mode 100644 diffsims/generators/structure_library_generator.py delete mode 100644 diffsims/tests/test_generators/test_structure_library_generator.py diff --git a/diffsims/generators/structure_library_generator.py b/diffsims/generators/structure_library_generator.py deleted file mode 100644 index e69de29b..00000000 diff --git a/diffsims/tests/test_generators/test_structure_library_generator.py b/diffsims/tests/test_generators/test_structure_library_generator.py deleted file mode 100644 index 49b34b5c..00000000 --- a/diffsims/tests/test_generators/test_structure_library_generator.py +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2017-2019 The diffsims developers -# -# This file is part of diffsims. -# -# diffsims is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# diffsims is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with diffsims. If not, see . - -import numpy as np - -from diffsims.generators.structure_library_generator import StructureLibraryGenerator -from diffsims.tests.test_utils.test_sim_utils import create_structure_cubic - - -def test_orientations_from_list(): - expected_orientations = [(0, 0, 0), (0, 90, 0)] - structure_library_generator = StructureLibraryGenerator([ - ('a', None, 'cubic'), - ('b', None, 'hexagonal') - ]) - structure_library = structure_library_generator.get_orientations_from_list(expected_orientations) - assert structure_library.identifiers == ['a', 'b'] - assert structure_library.structures == [None, None] - np.testing.assert_almost_equal(structure_library.orientations, expected_orientations) - - -def test_orientations_from_stereographic_triangle(): - structure_cubic = create_structure_cubic() - structure_library_generator = StructureLibraryGenerator([('a', structure_cubic, 'cubic')]) - structure_library = structure_library_generator.get_orientations_from_stereographic_triangle([[0]], np.pi / 8) - assert structure_library.identifiers == ['a'] - assert structure_library.structures == [structure_cubic] - # Tests for rotation_list_stereographic checks correctness of list content - assert len(structure_library.orientations) == 1 From 92f04a111314ad35059eaacd7f8bc8fd5e034ff9 Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 14:01:42 +0000 Subject: [PATCH 07/13] [skip ci] remove unused test fixtures --- diffsims/tests/test_utils/test_sim_utils.py | 31 --------------------- 1 file changed, 31 deletions(-) diff --git a/diffsims/tests/test_utils/test_sim_utils.py b/diffsims/tests/test_utils/test_sim_utils.py index 107774cf..422e95bd 100644 --- a/diffsims/tests/test_utils/test_sim_utils.py +++ b/diffsims/tests/test_utils/test_sim_utils.py @@ -25,37 +25,6 @@ get_vectorized_list_for_atomic_scattering_factors, get_points_in_sphere, \ simulate_kinematic_scattering, is_lattice_hexagonal, uvtw_to_uvw - -def create_lattice_structure(a, b, c, alpha, beta, gamma): - lattice = diffpy.structure.lattice.Lattice(a, b, c, alpha, beta, gamma) - atom = diffpy.structure.atom.Atom(atype='Si', xyz=[0, 0, 0], lattice=lattice) - return diffpy.structure.Structure(atoms=[atom], lattice=lattice) - - -def create_structure_cubic(): - return create_lattice_structure(1, 1, 1, 90, 90, 90) - - -def create_structure_hexagonal(): - return create_lattice_structure(1, 1, 1, 90, 90, 120) - - -def create_structure_orthorombic(): - return create_lattice_structure(1, 2, 3, 90, 90, 90) - - -def create_structure_tetragonal(): - return create_lattice_structure(1, 1, 2, 90, 90, 90) - - -def create_structure_trigonal(): - return create_lattice_structure(1, 1, 1, 100, 100, 100) - - -def create_structure_monoclinic(): - return create_lattice_structure(1, 2, 3, 90, 100, 90) - - @pytest.mark.parametrize('accelerating_voltage, wavelength', [ (100, 0.0370143659), (200, 0.0250793403), From c26da50f4c853e9123ddfb5a81403fe689838f9b Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 14:05:24 +0000 Subject: [PATCH 08/13] Implementing classmethod tests --- .../tests/test_library/test_structure_library.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/diffsims/tests/test_library/test_structure_library.py b/diffsims/tests/test_library/test_structure_library.py index f9ce5bb7..a5807f37 100644 --- a/diffsims/tests/test_library/test_structure_library.py +++ b/diffsims/tests/test_library/test_structure_library.py @@ -35,6 +35,20 @@ def test_constructor(): np.testing.assert_equal(library.struct_lib['a'], (1, 3)) np.testing.assert_equal(library.struct_lib['b'], (2, 4)) +def test_from_orientations_method(): + #as above + identifiers = ['a', 'b'] + structures = [1, 2] + orientations = [3, 4] + library = StructureLibrary.from_orientation_lists(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=1,equal='angle') + + @pytest.mark.parametrize('identifiers, structures, orientations', [ (['a'], [1, 2], [3, 4]), From b6ddfefc8df1695161c50777a92a13b0cfc5ffff Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 14:06:33 +0000 Subject: [PATCH 09/13] Testing induced fixes --- diffsims/libraries/structure_library.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/diffsims/libraries/structure_library.py b/diffsims/libraries/structure_library.py index 386cb02a..8fa9cbee 100644 --- a/diffsims/libraries/structure_library.py +++ b/diffsims/libraries/structure_library.py @@ -75,10 +75,10 @@ def from_orientation_lists(cls,identifiers,structures,orientations): ------- StructureLibrary """ - return cls(identifier,structure,orientations) + return cls(identifiers,structures,orientations) @classmethod - def from_crystal_systems(cls,identifier,structures,systems,resolution,equal='angle'): + def from_crystal_systems(cls,identifiers,structures,systems,resolution,equal='angle'): """ Creates a structure library from crystal system derived orientation lists @@ -102,4 +102,4 @@ def from_crystal_systems(cls,identifier,structures,systems,resolution,equal='ang orientations = [] for system in systems: orientations.append(get_grid_streographic(system,resolution,equal)) - return cls(identifier,structure,orientations) + return cls(identifiers,structures,orientations) From 12e8981da6ddd7f65401bc983cd91ece6b464803 Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 14:07:17 +0000 Subject: [PATCH 10/13] Lower resolution to speed up tests --- diffsims/tests/test_library/test_structure_library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/tests/test_library/test_structure_library.py b/diffsims/tests/test_library/test_structure_library.py index a5807f37..6026e5b2 100644 --- a/diffsims/tests/test_library/test_structure_library.py +++ b/diffsims/tests/test_library/test_structure_library.py @@ -46,7 +46,7 @@ def test_from_systems_methods(): identifiers = ['a', 'b'] structures = [1, 2] systems = ['cubic', 'hexagonal'] - library = StructureLibrary.from_crystal_systems(identifiers,structures,systems,resolution=1,equal='angle') + library = StructureLibrary.from_crystal_systems(identifiers,structures,systems,resolution=2,equal='angle') From f295aeab587e6e75f4b6875325a9066ee403e403 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 30 Jan 2020 16:37:17 +0000 Subject: [PATCH 11/13] Tidy testing up --- .../test_library/test_structure_library.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/diffsims/tests/test_library/test_structure_library.py b/diffsims/tests/test_library/test_structure_library.py index 6026e5b2..b53c4b8d 100644 --- a/diffsims/tests/test_library/test_structure_library.py +++ b/diffsims/tests/test_library/test_structure_library.py @@ -21,33 +21,24 @@ from diffsims.libraries.structure_library import StructureLibrary - -def test_constructor(): +def test_from_orientations_method(): identifiers = ['a', 'b'] - # Arbitrary values for tracking structures = [1, 2] orientations = [3, 4] - library = StructureLibrary(identifiers, structures, orientations) - + 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_from_orientations_method(): - #as above - identifiers = ['a', 'b'] - structures = [1, 2] - orientations = [3, 4] - library = StructureLibrary.from_orientation_lists(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') - + np.testing.assert_equal(library.struct_lib['b'], (2, 4)) + assert len(library.struct_lib['a']) < len(library.struct_lib['b']) @pytest.mark.parametrize('identifiers, structures, orientations', [ From af24d85c6c1ad53f98532c367f7c2d680c9fdef9 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 30 Jan 2020 16:45:37 +0000 Subject: [PATCH 12/13] Minor adjustments for code clarity --- diffsims/libraries/structure_library.py | 4 ++-- diffsims/tests/test_library/test_structure_library.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/diffsims/libraries/structure_library.py b/diffsims/libraries/structure_library.py index 8fa9cbee..b1969868 100644 --- a/diffsims/libraries/structure_library.py +++ b/diffsims/libraries/structure_library.py @@ -68,7 +68,7 @@ def from_orientation_lists(cls,identifiers,structures,orientations): structures : list of diffpy.structure.Structure objects. A list of diffpy.structure.Structure objects describing the atomic structure associated with each phase in the library. - orientations : list + orientations : list of lists of tuples A list over identifiers of lists of euler angles (as tuples) in the rzxz convention and in degrees. Returns @@ -90,7 +90,7 @@ def from_crystal_systems(cls,identifiers,structures,systems,resolution,equal='an A list of diffpy.structure.Structure objects describing the atomic structure associated with each phase in the library. systems : list - A list over indetfiers of crystal systems + A list over indentifiers of crystal systems resolution : float resolution in degrees equal : str diff --git a/diffsims/tests/test_library/test_structure_library.py b/diffsims/tests/test_library/test_structure_library.py index b53c4b8d..0c26e44a 100644 --- a/diffsims/tests/test_library/test_structure_library.py +++ b/diffsims/tests/test_library/test_structure_library.py @@ -38,7 +38,7 @@ def test_from_systems_methods(): systems = ['cubic', 'hexagonal'] library = StructureLibrary.from_crystal_systems(identifiers,structures,systems,resolution=2,equal='angle') np.testing.assert_equal(library.struct_lib['b'], (2, 4)) - assert len(library.struct_lib['a']) < len(library.struct_lib['b']) + assert len(library.struct_lib['a']) < len(library.struct_lib['b']) #cubic is less area the hexagonal @pytest.mark.parametrize('identifiers, structures, orientations', [ From a8589ce77f5d2aaead2447a8cf2d354de0aecdb2 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 30 Jan 2020 16:53:52 +0000 Subject: [PATCH 13/13] Fix the broken test --- diffsims/tests/test_library/test_structure_library.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/diffsims/tests/test_library/test_structure_library.py b/diffsims/tests/test_library/test_structure_library.py index 0c26e44a..bff32269 100644 --- a/diffsims/tests/test_library/test_structure_library.py +++ b/diffsims/tests/test_library/test_structure_library.py @@ -37,8 +37,7 @@ def test_from_systems_methods(): structures = [1, 2] systems = ['cubic', 'hexagonal'] library = StructureLibrary.from_crystal_systems(identifiers,structures,systems,resolution=2,equal='angle') - np.testing.assert_equal(library.struct_lib['b'], (2, 4)) - assert len(library.struct_lib['a']) < len(library.struct_lib['b']) #cubic is less area the hexagonal + assert len(library.struct_lib['a'][1]) < len(library.struct_lib['b'][1]) #cubic is less area the hexagonal @pytest.mark.parametrize('identifiers, structures, orientations', [