|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Copyright 2017-2023 The diffsims developers |
| 3 | +# |
| 4 | +# This file is part of diffsims. |
| 5 | +# |
| 6 | +# diffsims is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# diffsims is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with diffsims. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from itertools import product |
| 20 | + |
| 21 | +import numpy as np |
| 22 | +from orix.vector import Vector3d |
| 23 | + |
| 24 | +from diffsims.utils._deprecated import deprecated |
| 25 | + |
| 26 | + |
| 27 | +@deprecated( |
| 28 | + since="0.6", |
| 29 | + alternative="diffsims.crystallography.ReciprocalLatticeVector.from_min_dspacing", |
| 30 | + removal="0.7", |
| 31 | +) |
| 32 | +def get_highest_hkl(lattice, min_dspacing=0.5): |
| 33 | + """Return the highest Miller indices hkl of the plane with a direct |
| 34 | + space interplanar spacing (d-spacing) greater than but closest to |
| 35 | + *min_dspacing*. |
| 36 | +
|
| 37 | + Parameters |
| 38 | + ---------- |
| 39 | + lattice : diffpy.structure.Lattice |
| 40 | + Crystal lattice. |
| 41 | + min_dspacing : float, optional |
| 42 | + Smallest interplanar spacing to consider. Default is 0.5 Å. |
| 43 | +
|
| 44 | + Returns |
| 45 | + ------- |
| 46 | + highest_hkl : np.ndarray |
| 47 | + Highest Miller indices. |
| 48 | + """ |
| 49 | + highest_hkl = np.ones(3, dtype=int) |
| 50 | + for i in range(3): |
| 51 | + hkl = np.zeros(3) |
| 52 | + d = min_dspacing + 1 |
| 53 | + while d > min_dspacing: |
| 54 | + hkl[i] += 1 |
| 55 | + d = 1 / lattice.rnorm(hkl) |
| 56 | + highest_hkl[i] = hkl[i] |
| 57 | + return highest_hkl |
| 58 | + |
| 59 | + |
| 60 | +@deprecated( |
| 61 | + since="0.6", |
| 62 | + alternative="diffsims.crystallography.ReciprocalLatticeVector.from_highest_hkl", |
| 63 | + removal="0.7", |
| 64 | +) |
| 65 | +def get_hkl(highest_hkl): |
| 66 | + """Return a list of planes from a set of highest Miller indices. |
| 67 | +
|
| 68 | + Parameters |
| 69 | + ---------- |
| 70 | + highest_hkl : orix.vector.Vector3d, np.ndarray, list, or tuple of int |
| 71 | + Highest Miller indices to consider. |
| 72 | +
|
| 73 | + Returns |
| 74 | + ------- |
| 75 | + hkl : np.ndarray |
| 76 | + An array of Miller indices. |
| 77 | + """ |
| 78 | + index_ranges = [np.arange(-i, i + 1) for i in highest_hkl] |
| 79 | + return np.asarray(list(product(*index_ranges))) |
| 80 | + |
| 81 | + |
| 82 | +@deprecated( |
| 83 | + since="0.6", |
| 84 | + alternative="diffsims.crystallography.ReciprocalLatticeVector.symmetrise", |
| 85 | + removal="0.7", |
| 86 | +) |
| 87 | +def get_equivalent_hkl(hkl, operations, unique=False, return_multiplicity=False): |
| 88 | + """Return symmetrically equivalent Miller indices. |
| 89 | +
|
| 90 | + Parameters |
| 91 | + ---------- |
| 92 | + hkl : orix.vector.Vector3d, np.ndarray, list or tuple of int |
| 93 | + Miller indices. |
| 94 | + operations : orix.quaternion.symmetry.Symmetry |
| 95 | + Point group describing allowed symmetry operations. |
| 96 | + unique : bool, optional |
| 97 | + Whether to return only unique Miller indices. Default is False. |
| 98 | + return_multiplicity : bool, optional |
| 99 | + Whether to return the multiplicity of the input indices. Default |
| 100 | + is False. |
| 101 | +
|
| 102 | + Returns |
| 103 | + ------- |
| 104 | + new_hkl : orix.vector.Vector3d |
| 105 | + The symmetrically equivalent Miller indices. |
| 106 | + multiplicity : np.ndarray |
| 107 | + Number of symmetrically equivalent indices. Only returned if |
| 108 | + `return_multiplicity` is True. |
| 109 | + """ |
| 110 | + new_hkl = operations.outer(Vector3d(hkl)) |
| 111 | + new_hkl = new_hkl.flatten().reshape(*new_hkl.shape[::-1]) |
| 112 | + |
| 113 | + multiplicity = None |
| 114 | + if unique: |
| 115 | + n_families = new_hkl.shape[0] |
| 116 | + multiplicity = np.zeros(n_families, dtype=int) |
| 117 | + temp_hkl = new_hkl[0].unique().data |
| 118 | + multiplicity[0] = temp_hkl.shape[0] |
| 119 | + if n_families > 1: |
| 120 | + for i, hkl in enumerate(new_hkl[1:]): |
| 121 | + temp_hkl2 = hkl.unique() |
| 122 | + multiplicity[i + 1] = temp_hkl2.size |
| 123 | + temp_hkl = np.append(temp_hkl, temp_hkl2.data, axis=0) |
| 124 | + new_hkl = Vector3d(temp_hkl[: multiplicity.sum()]) |
| 125 | + |
| 126 | + # Remove 1-dimensions |
| 127 | + new_hkl = new_hkl.squeeze() |
| 128 | + |
| 129 | + if unique and return_multiplicity: |
| 130 | + return new_hkl, multiplicity |
| 131 | + else: |
| 132 | + return new_hkl |
0 commit comments