improved names and layout
This commit is contained in:
parent
c7c6627dfb
commit
8609eb6eb7
|
@ -112,6 +112,11 @@ class Rotation:
|
||||||
return self.__class__(other.quaternion*self.quaternion.conjugated())
|
return self.__class__(other.quaternion*self.quaternion.conjugated())
|
||||||
|
|
||||||
|
|
||||||
|
def average(self,other):
|
||||||
|
"""Calculate the average rotation"""
|
||||||
|
return Rotation.fromAverage([self,other])
|
||||||
|
|
||||||
|
|
||||||
################################################################################################
|
################################################################################################
|
||||||
# convert to different orientation representations (numpy arrays)
|
# convert to different orientation representations (numpy arrays)
|
||||||
|
|
||||||
|
@ -262,7 +267,7 @@ class Rotation:
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def average(cls,
|
def fromAverage(cls,
|
||||||
rotations,
|
rotations,
|
||||||
weights = []):
|
weights = []):
|
||||||
"""
|
"""
|
||||||
|
@ -272,6 +277,8 @@ class Rotation:
|
||||||
Averaging Quaternions,
|
Averaging Quaternions,
|
||||||
Journal of Guidance, Control, and Dynamics, Vol. 30, No. 4 (2007), pp. 1193-1197.
|
Journal of Guidance, Control, and Dynamics, Vol. 30, No. 4 (2007), pp. 1193-1197.
|
||||||
doi: 10.2514/1.28949
|
doi: 10.2514/1.28949
|
||||||
|
|
||||||
|
usage: input a list of rotations and optional weights
|
||||||
"""
|
"""
|
||||||
if not all(isinstance(item, Rotation) for item in rotations):
|
if not all(isinstance(item, Rotation) for item in rotations):
|
||||||
raise TypeError("Only instances of Rotation can be averaged.")
|
raise TypeError("Only instances of Rotation can be averaged.")
|
||||||
|
@ -339,12 +346,12 @@ class Symmetry:
|
||||||
[ 0.0, 1.0, 0.0, 0.0 ],
|
[ 0.0, 1.0, 0.0, 0.0 ],
|
||||||
[ 0.0, 0.0, 1.0, 0.0 ],
|
[ 0.0, 0.0, 1.0, 0.0 ],
|
||||||
[ 0.0, 0.0, 0.0, 1.0 ],
|
[ 0.0, 0.0, 0.0, 1.0 ],
|
||||||
[ 0.0, 0.0, 0.5*math.sqrt(2), 0.5*math.sqrt(2) ],
|
[ 0.0, 0.0, 0.5*np.sqrt(2), 0.5*np.sqrt(2) ],
|
||||||
[ 0.0, 0.0, 0.5*math.sqrt(2),-0.5*math.sqrt(2) ],
|
[ 0.0, 0.0, 0.5*np.sqrt(2),-0.5*np.sqrt(2) ],
|
||||||
[ 0.0, 0.5*math.sqrt(2), 0.0, 0.5*math.sqrt(2) ],
|
[ 0.0, 0.5*np.sqrt(2), 0.0, 0.5*np.sqrt(2) ],
|
||||||
[ 0.0, 0.5*math.sqrt(2), 0.0, -0.5*math.sqrt(2) ],
|
[ 0.0, 0.5*np.sqrt(2), 0.0, -0.5*np.sqrt(2) ],
|
||||||
[ 0.0, 0.5*math.sqrt(2),-0.5*math.sqrt(2), 0.0 ],
|
[ 0.0, 0.5*np.sqrt(2),-0.5*np.sqrt(2), 0.0 ],
|
||||||
[ 0.0, -0.5*math.sqrt(2),-0.5*math.sqrt(2), 0.0 ],
|
[ 0.0, -0.5*np.sqrt(2),-0.5*np.sqrt(2), 0.0 ],
|
||||||
[ 0.5, 0.5, 0.5, 0.5 ],
|
[ 0.5, 0.5, 0.5, 0.5 ],
|
||||||
[-0.5, 0.5, 0.5, 0.5 ],
|
[-0.5, 0.5, 0.5, 0.5 ],
|
||||||
[-0.5, 0.5, 0.5, -0.5 ],
|
[-0.5, 0.5, 0.5, -0.5 ],
|
||||||
|
@ -353,27 +360,27 @@ class Symmetry:
|
||||||
[-0.5, -0.5, 0.5, -0.5 ],
|
[-0.5, -0.5, 0.5, -0.5 ],
|
||||||
[-0.5, -0.5, -0.5, 0.5 ],
|
[-0.5, -0.5, -0.5, 0.5 ],
|
||||||
[-0.5, 0.5, -0.5, -0.5 ],
|
[-0.5, 0.5, -0.5, -0.5 ],
|
||||||
[-0.5*math.sqrt(2), 0.0, 0.0, 0.5*math.sqrt(2) ],
|
[-0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
||||||
[ 0.5*math.sqrt(2), 0.0, 0.0, 0.5*math.sqrt(2) ],
|
[ 0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
||||||
[-0.5*math.sqrt(2), 0.0, 0.5*math.sqrt(2), 0.0 ],
|
[-0.5*np.sqrt(2), 0.0, 0.5*np.sqrt(2), 0.0 ],
|
||||||
[-0.5*math.sqrt(2), 0.0, -0.5*math.sqrt(2), 0.0 ],
|
[-0.5*np.sqrt(2), 0.0, -0.5*np.sqrt(2), 0.0 ],
|
||||||
[-0.5*math.sqrt(2), 0.5*math.sqrt(2), 0.0, 0.0 ],
|
[-0.5*np.sqrt(2), 0.5*np.sqrt(2), 0.0, 0.0 ],
|
||||||
[-0.5*math.sqrt(2),-0.5*math.sqrt(2), 0.0, 0.0 ],
|
[-0.5*np.sqrt(2),-0.5*np.sqrt(2), 0.0, 0.0 ],
|
||||||
]
|
]
|
||||||
elif self.lattice == 'hexagonal':
|
elif self.lattice == 'hexagonal':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
[ 1.0, 0.0, 0.0, 0.0 ],
|
[ 1.0, 0.0, 0.0, 0.0 ],
|
||||||
[-0.5*math.sqrt(3), 0.0, 0.0,-0.5 ],
|
[-0.5*np.sqrt(3), 0.0, 0.0, -0.5 ],
|
||||||
[ 0.5, 0.0, 0.0, 0.5*math.sqrt(3) ],
|
[ 0.5, 0.0, 0.0, 0.5*np.sqrt(3) ],
|
||||||
[ 0.0, 0.0, 0.0, 1.0 ],
|
[ 0.0, 0.0, 0.0, 1.0 ],
|
||||||
[-0.5, 0.0, 0.0, 0.5*math.sqrt(3) ],
|
[-0.5, 0.0, 0.0, 0.5*np.sqrt(3) ],
|
||||||
[-0.5*math.sqrt(3), 0.0, 0.0, 0.5 ],
|
[-0.5*np.sqrt(3), 0.0, 0.0, 0.5 ],
|
||||||
[ 0.0, 1.0, 0.0, 0.0 ],
|
[ 0.0, 1.0, 0.0, 0.0 ],
|
||||||
[ 0.0,-0.5*math.sqrt(3), 0.5, 0.0 ],
|
[ 0.0, -0.5*np.sqrt(3), 0.5, 0.0 ],
|
||||||
[ 0.0, 0.5,-0.5*math.sqrt(3), 0.0 ],
|
[ 0.0, 0.5, -0.5*np.sqrt(3), 0.0 ],
|
||||||
[ 0.0, 0.0, 1.0, 0.0 ],
|
[ 0.0, 0.0, 1.0, 0.0 ],
|
||||||
[ 0.0,-0.5,-0.5*math.sqrt(3), 0.0 ],
|
[ 0.0, -0.5, -0.5*np.sqrt(3), 0.0 ],
|
||||||
[ 0.0, 0.5*math.sqrt(3), 0.5, 0.0 ],
|
[ 0.0, 0.5*np.sqrt(3), 0.5, 0.0 ],
|
||||||
]
|
]
|
||||||
elif self.lattice == 'tetragonal':
|
elif self.lattice == 'tetragonal':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
|
@ -381,10 +388,10 @@ class Symmetry:
|
||||||
[ 0.0, 1.0, 0.0, 0.0 ],
|
[ 0.0, 1.0, 0.0, 0.0 ],
|
||||||
[ 0.0, 0.0, 1.0, 0.0 ],
|
[ 0.0, 0.0, 1.0, 0.0 ],
|
||||||
[ 0.0, 0.0, 0.0, 1.0 ],
|
[ 0.0, 0.0, 0.0, 1.0 ],
|
||||||
[ 0.0, 0.5*math.sqrt(2), 0.5*math.sqrt(2), 0.0 ],
|
[ 0.0, 0.5*np.sqrt(2), 0.5*np.sqrt(2), 0.0 ],
|
||||||
[ 0.0,-0.5*math.sqrt(2), 0.5*math.sqrt(2), 0.0 ],
|
[ 0.0, -0.5*np.sqrt(2), 0.5*np.sqrt(2), 0.0 ],
|
||||||
[ 0.5*math.sqrt(2), 0.0, 0.0, 0.5*math.sqrt(2) ],
|
[ 0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
||||||
[-0.5*math.sqrt(2), 0.0, 0.0, 0.5*math.sqrt(2) ],
|
[-0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
||||||
]
|
]
|
||||||
elif self.lattice == 'orthorhombic':
|
elif self.lattice == 'orthorhombic':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
|
@ -447,6 +454,8 @@ class Symmetry:
|
||||||
Acta Cryst. (1991). A47, 780-789
|
Acta Cryst. (1991). A47, 780-789
|
||||||
"""
|
"""
|
||||||
R = rodrigues
|
R = rodrigues
|
||||||
|
if (len(R) != 3):
|
||||||
|
raise ValueError('Input is not a Rodriques-Frank vector.\n')
|
||||||
|
|
||||||
epsilon = 0.0
|
epsilon = 0.0
|
||||||
if self.lattice == 'cubic':
|
if self.lattice == 'cubic':
|
||||||
|
@ -967,21 +976,10 @@ class Orientation:
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def average(cls,
|
def fromAverage(cls,
|
||||||
orientations,
|
orientations,
|
||||||
weights = []):
|
weights = []):
|
||||||
"""
|
"""Create orientation from average of list of orientations"""
|
||||||
Average orientation
|
|
||||||
|
|
||||||
ref: F. Landis Markley, Yang Cheng, John Lucas Crassidis, and Yaakov Oshman.
|
|
||||||
Averaging Quaternions,
|
|
||||||
Journal of Guidance, Control, and Dynamics, Vol. 30, No. 4 (2007), pp. 1193-1197.
|
|
||||||
doi: 10.2514/1.28949
|
|
||||||
usage:
|
|
||||||
a = Orientation(Eulers=np.radians([10, 10, 0]), symmetry='hexagonal')
|
|
||||||
b = Orientation(Eulers=np.radians([20, 0, 0]), symmetry='hexagonal')
|
|
||||||
avg = Orientation.average([a,b])
|
|
||||||
"""
|
|
||||||
if not all(isinstance(item, Orientation) for item in orientations):
|
if not all(isinstance(item, Orientation) for item in orientations):
|
||||||
raise TypeError("Only instances of Orientation can be averaged.")
|
raise TypeError("Only instances of Orientation can be averaged.")
|
||||||
|
|
||||||
|
@ -993,7 +991,12 @@ class Orientation:
|
||||||
SST = False, # select (o[ther]'s) sym orientation
|
SST = False, # select (o[ther]'s) sym orientation
|
||||||
symmetries = True)[2]).rotation) # with lowest misorientation
|
symmetries = True)[2]).rotation) # with lowest misorientation
|
||||||
|
|
||||||
return Orientation(Rotation.average(closest,weights),ref.lattice)
|
return Orientation(Rotation.fromAverage(closest,weights),ref.lattice)
|
||||||
|
|
||||||
|
|
||||||
|
def average(self,other):
|
||||||
|
"""Calculate the average rotation"""
|
||||||
|
return Orientation.fromAverage([self,other])
|
||||||
|
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
Loading…
Reference in New Issue