Skip to content

Commit

Permalink
Merge pull request #61 from pc494/tidy-up-streographic
Browse files Browse the repository at this point in the history
Tidy up streographic code + StructureLibrary changes
  • Loading branch information
dnjohnstone authored Jan 30, 2020
2 parents 83ef978 + a8589ce commit 9d370fd
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 362 deletions.
109 changes: 0 additions & 109 deletions diffsims/generators/structure_library_generator.py

This file was deleted.

49 changes: 49 additions & 0 deletions diffsims/libraries/structure_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with diffsims. If not, see <http://www.gnu.org/licenses/>.

import diffsims as ds
from diffsims.generators.rotation_list_generators import get_grid_streographic


class StructureLibrary():
Expand Down Expand Up @@ -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 of lists of tuples
A list over identifiers of lists of euler angles (as tuples) in the rzxz
convention and in degrees.
Returns
-------
StructureLibrary
"""
return cls(identifiers,structures,orientations)

@classmethod
def from_crystal_systems(cls,identifiers,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 indentifiers 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(identifiers,structures,orientations)
44 changes: 0 additions & 44 deletions diffsims/tests/test_generators/test_structure_library_generator.py

This file was deleted.

14 changes: 9 additions & 5 deletions diffsims/tests/test_library/test_structure_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +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_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


@pytest.mark.parametrize('identifiers, structures, orientations', [
(['a'], [1, 2], [3, 4]),
Expand Down
96 changes: 1 addition & 95 deletions diffsims/tests/test_utils/test_sim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +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


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)

simulate_kinematic_scattering, is_lattice_hexagonal, uvtw_to_uvw

@pytest.mark.parametrize('accelerating_voltage, wavelength', [
(100, 0.0370143659),
Expand Down Expand Up @@ -143,65 +111,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)
Loading

0 comments on commit 9d370fd

Please sign in to comment.