2015-05-08 19:44:44 +05:30
|
|
|
import numpy as np
|
2019-05-30 23:32:55 +05:30
|
|
|
|
2020-02-21 03:59:12 +05:30
|
|
|
from .lattice import Lattice
|
2020-02-21 03:46:35 +05:30
|
|
|
from .rotation import Rotation
|
2019-02-21 17:06:27 +05:30
|
|
|
|
2019-02-24 12:38:14 +05:30
|
|
|
class Orientation:
|
2019-02-21 17:06:27 +05:30
|
|
|
"""
|
2019-09-04 05:22:28 +05:30
|
|
|
Crystallographic orientation.
|
2020-02-21 03:33:37 +05:30
|
|
|
|
2019-09-04 05:22:28 +05:30
|
|
|
A crystallographic orientation contains a rotation and a lattice.
|
2019-02-21 17:06:27 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
__slots__ = ['rotation','lattice']
|
2020-02-21 03:33:37 +05:30
|
|
|
|
2019-02-21 17:06:27 +05:30
|
|
|
def __repr__(self):
|
2019-09-04 05:22:28 +05:30
|
|
|
"""Report lattice type and orientation."""
|
2019-02-21 17:06:27 +05:30
|
|
|
return self.lattice.__repr__()+'\n'+self.rotation.__repr__()
|
|
|
|
|
|
|
|
def __init__(self, rotation, lattice):
|
2019-09-04 05:22:28 +05:30
|
|
|
"""
|
|
|
|
New orientation from rotation and lattice.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
rotation : Rotation
|
|
|
|
Rotation specifying the lattice orientation.
|
|
|
|
lattice : Lattice
|
|
|
|
Lattice type of the crystal.
|
|
|
|
|
|
|
|
"""
|
2019-02-21 17:06:27 +05:30
|
|
|
if isinstance(lattice, Lattice):
|
|
|
|
self.lattice = lattice
|
|
|
|
else:
|
2020-01-21 22:08:08 +05:30
|
|
|
self.lattice = Lattice(lattice) # assume string
|
2020-02-21 03:33:37 +05:30
|
|
|
|
2019-02-21 17:06:27 +05:30
|
|
|
if isinstance(rotation, Rotation):
|
|
|
|
self.rotation = rotation
|
|
|
|
else:
|
2020-01-21 22:08:08 +05:30
|
|
|
self.rotation = Rotation.fromQuaternion(rotation) # assume quaternion
|
2020-02-21 03:33:37 +05:30
|
|
|
|
2019-02-21 17:06:27 +05:30
|
|
|
def disorientation(self,
|
|
|
|
other,
|
2019-04-12 02:48:32 +05:30
|
|
|
SST = True,
|
|
|
|
symmetries = False):
|
2019-02-21 17:06:27 +05:30
|
|
|
"""
|
|
|
|
Disorientation between myself and given other orientation.
|
|
|
|
|
|
|
|
Rotation axis falls into SST if SST == True.
|
|
|
|
(Currently requires same symmetry for both orientations.
|
|
|
|
Look into A. Heinz and P. Neumann 1991 for cases with differing sym.)
|
|
|
|
"""
|
2019-04-17 14:18:18 +05:30
|
|
|
if self.lattice.symmetry != other.lattice.symmetry:
|
|
|
|
raise NotImplementedError('disorientation between different symmetry classes not supported yet.')
|
2019-02-21 17:06:27 +05:30
|
|
|
|
2019-04-12 04:02:07 +05:30
|
|
|
mySymEqs = self.equivalentOrientations() if SST else self.equivalentOrientations([0]) # take all or only first sym operation
|
2019-02-21 17:06:27 +05:30
|
|
|
otherSymEqs = other.equivalentOrientations()
|
2020-02-21 03:33:37 +05:30
|
|
|
|
2019-02-21 17:06:27 +05:30
|
|
|
for i,sA in enumerate(mySymEqs):
|
2019-04-12 04:02:07 +05:30
|
|
|
aInv = sA.rotation.inversed()
|
2019-02-21 17:06:27 +05:30
|
|
|
for j,sB in enumerate(otherSymEqs):
|
2019-04-12 04:02:07 +05:30
|
|
|
b = sB.rotation
|
|
|
|
r = b*aInv
|
2019-02-21 17:06:27 +05:30
|
|
|
for k in range(2):
|
2019-04-12 04:02:07 +05:30
|
|
|
r.inverse()
|
2019-04-19 11:47:02 +05:30
|
|
|
breaker = self.lattice.symmetry.inFZ(r.asRodrigues(vector=True)) \
|
2019-04-17 12:19:26 +05:30
|
|
|
and (not SST or other.lattice.symmetry.inDisorientationSST(r.asRodrigues(vector=True)))
|
2019-02-21 17:06:27 +05:30
|
|
|
if breaker: break
|
|
|
|
if breaker: break
|
|
|
|
if breaker: break
|
|
|
|
|
2019-04-19 04:35:48 +05:30
|
|
|
return (Orientation(r,self.lattice), i,j, k == 1) if symmetries else r # disorientation ...
|
2019-04-12 02:48:32 +05:30
|
|
|
# ... own sym, other sym,
|
|
|
|
# self-->other: True, self<--other: False
|
2019-02-21 17:06:27 +05:30
|
|
|
def inFZ(self):
|
2019-04-19 11:47:02 +05:30
|
|
|
return self.lattice.symmetry.inFZ(self.rotation.asRodrigues(vector=True))
|
2019-10-23 03:01:27 +05:30
|
|
|
|
2020-02-21 03:33:37 +05:30
|
|
|
|
2019-04-12 04:37:41 +05:30
|
|
|
def equivalentOrientations(self,members=[]):
|
2019-09-04 05:22:28 +05:30
|
|
|
"""List of orientations which are symmetrically equivalent."""
|
2019-04-12 04:37:41 +05:30
|
|
|
try:
|
|
|
|
iter(members) # asking for (even empty) list of members?
|
|
|
|
except TypeError:
|
|
|
|
return self.__class__(self.lattice.symmetry.symmetryOperations(members)*self.rotation,self.lattice) # no, return rotation object
|
|
|
|
else:
|
|
|
|
return [self.__class__(q*self.rotation,self.lattice) \
|
|
|
|
for q in self.lattice.symmetry.symmetryOperations(members)] # yes, return list of rotations
|
2020-02-21 03:33:37 +05:30
|
|
|
|
2019-02-21 17:06:27 +05:30
|
|
|
def relatedOrientations(self,model):
|
2019-09-04 05:22:28 +05:30
|
|
|
"""List of orientations related by the given orientation relationship."""
|
2019-02-21 17:06:27 +05:30
|
|
|
r = self.lattice.relationOperations(model)
|
2019-10-22 02:47:58 +05:30
|
|
|
return [self.__class__(o*self.rotation,r['lattice']) for o in r['rotations']]
|
2019-10-23 03:01:27 +05:30
|
|
|
|
2020-02-21 03:33:37 +05:30
|
|
|
|
2019-02-21 17:06:27 +05:30
|
|
|
def reduced(self):
|
2019-09-04 05:22:28 +05:30
|
|
|
"""Transform orientation to fall into fundamental zone according to symmetry."""
|
2019-02-21 17:06:27 +05:30
|
|
|
for me in self.equivalentOrientations():
|
2019-04-19 12:34:54 +05:30
|
|
|
if self.lattice.symmetry.inFZ(me.rotation.asRodrigues(vector=True)): break
|
2019-02-21 17:06:27 +05:30
|
|
|
|
|
|
|
return self.__class__(me.rotation,self.lattice)
|
2020-02-21 03:33:37 +05:30
|
|
|
|
|
|
|
|
2015-10-09 18:33:10 +05:30
|
|
|
def inversePole(self,
|
|
|
|
axis,
|
2015-10-24 01:46:01 +05:30
|
|
|
proper = False,
|
2015-10-09 18:33:10 +05:30
|
|
|
SST = True):
|
2019-09-04 05:22:28 +05:30
|
|
|
"""Axis rotated according to orientation (using crystal symmetry to ensure location falls into SST)."""
|
2015-08-24 19:09:09 +05:30
|
|
|
if SST: # pole requested to be within SST
|
2019-02-24 12:38:14 +05:30
|
|
|
for i,o in enumerate(self.equivalentOrientations()): # test all symmetric equivalent quaternions
|
|
|
|
pole = o.rotation*axis # align crystal direction to axis
|
|
|
|
if self.lattice.symmetry.inSST(pole,proper): break # found SST version
|
2015-06-13 17:21:10 +05:30
|
|
|
else:
|
2019-02-24 12:38:14 +05:30
|
|
|
pole = self.rotation*axis # align crystal direction to axis
|
2015-03-28 13:13:49 +05:30
|
|
|
|
2015-10-23 02:45:15 +05:30
|
|
|
return (pole,i if SST else 0)
|
2020-02-21 03:33:37 +05:30
|
|
|
|
|
|
|
|
2013-11-26 00:34:39 +05:30
|
|
|
def IPFcolor(self,axis):
|
2019-09-04 05:22:28 +05:30
|
|
|
"""TSL color of inverse pole figure for given axis."""
|
2015-05-08 19:44:44 +05:30
|
|
|
color = np.zeros(3,'d')
|
2013-11-26 00:34:39 +05:30
|
|
|
|
2019-02-24 12:38:14 +05:30
|
|
|
for o in self.equivalentOrientations():
|
|
|
|
pole = o.rotation*axis # align crystal direction to axis
|
|
|
|
inSST,color = self.lattice.symmetry.inSST(pole,color=True)
|
2013-11-26 00:34:39 +05:30
|
|
|
if inSST: break
|
|
|
|
|
2020-02-21 03:33:37 +05:30
|
|
|
return color
|
2015-04-03 00:45:09 +05:30
|
|
|
|
2015-06-13 17:21:10 +05:30
|
|
|
|
2019-12-13 20:16:40 +05:30
|
|
|
@staticmethod
|
|
|
|
def fromAverage(orientations,
|
2019-04-17 12:59:49 +05:30
|
|
|
weights = []):
|
2019-09-04 05:22:28 +05:30
|
|
|
"""Create orientation from average of list of orientations."""
|
2019-04-12 02:48:32 +05:30
|
|
|
if not all(isinstance(item, Orientation) for item in orientations):
|
|
|
|
raise TypeError("Only instances of Orientation can be averaged.")
|
|
|
|
|
2019-04-12 18:32:00 +05:30
|
|
|
closest = []
|
|
|
|
ref = orientations[0]
|
|
|
|
for o in orientations:
|
|
|
|
closest.append(o.equivalentOrientations(
|
2020-01-11 22:06:22 +05:30
|
|
|
ref.disorientation(o,
|
|
|
|
SST = False, # select (o[ther]'s) sym orientation
|
|
|
|
symmetries = True)[2]).rotation) # with lowest misorientation
|
2019-04-12 02:48:32 +05:30
|
|
|
|
2019-04-17 12:59:49 +05:30
|
|
|
return Orientation(Rotation.fromAverage(closest,weights),ref.lattice)
|
|
|
|
|
|
|
|
|
|
|
|
def average(self,other):
|
2019-09-04 05:22:28 +05:30
|
|
|
"""Calculate the average rotation."""
|
2019-04-17 12:59:49 +05:30
|
|
|
return Orientation.fromAverage([self,other])
|