decoupling Orientation and Lattice/LatticeFamily

This commit is contained in:
Martin Diehl 2021-06-03 10:02:49 +02:00
parent 03d3f362e6
commit 4701eea10f
2 changed files with 9 additions and 14 deletions

View File

@ -32,9 +32,9 @@ lattice_symmetries = {
_parameter_doc = \ _parameter_doc = \
""" """
family : {'triclinic', 'monoclinic', 'orthorhombic', 'tetragonal', 'hexagonal', 'cubic'} family : {'triclinic', 'monoclinic', 'orthorhombic', 'tetragonal', 'hexagonal', 'cubic'}
Crystal family. Mutual exclusive with 'lattice' parameter. Crystal family. Mutual exclusive with 'lattice' parameter.
lattice : {'aP', 'mP', 'mS', 'oP', 'oS', 'oI', 'oF', 'tP', 'tI', 'hP', 'cP', 'cI', 'cF'}. lattice : {'aP', 'mP', 'mS', 'oP', 'oS', 'oI', 'oF', 'tP', 'tI', 'hP', 'cP', 'cI', 'cF'}.
Bravais lattice in Pearson notation. Bravais lattice in Pearson notation.
Mutual exclusive with 'family' parameter. Mutual exclusive with 'family' parameter.
a : float, optional a : float, optional
@ -139,7 +139,6 @@ class Orientation(Rotation):
self.structure = l = LatticeFamily(self.family) # noqa self.structure = l = LatticeFamily(self.family) # noqa
self.immutable = l.immutable self.immutable = l.immutable
self.basis = l.basis self.basis = l.basis
self.symmetry_operations = l.symmetry_operations
self.a = self.b = self.c = None self.a = self.b = self.c = None
self.alpha = self.beta = self.gamma = None self.alpha = self.beta = self.gamma = None
@ -152,7 +151,6 @@ class Orientation(Rotation):
self.structure = l = Lattice(self.lattice, a,b,c, alpha,beta,gamma, degrees) # noqa self.structure = l = Lattice(self.lattice, a,b,c, alpha,beta,gamma, degrees) # noqa
self.immutable = l.immutable self.immutable = l.immutable
self.basis = l.basis self.basis = l.basis
self.symmetry_operations = l.symmetry_operations
self.a = l.a self.a = l.a
self.b = l.b self.b = l.b
@ -178,11 +176,6 @@ class Orientation(Rotation):
+ ([f'Crystal family {self.family}']) + ([f'Crystal family {self.family}'])
+ [super().__repr__()]) + [super().__repr__()])
@property
def parameters(self):
"""Return lattice parameters a, b, c, alpha, beta, gamma."""
return (self.a,self.b,self.c,self.alpha,self.beta,self.gamma)
def __copy__(self,**kwargs): def __copy__(self,**kwargs):
"""Create deep copy.""" """Create deep copy."""
@ -437,7 +430,8 @@ class Orientation(Rotation):
is added to the left of the Rotation array. is added to the left of the Rotation array.
""" """
o = self.symmetry_operations.broadcast_to(self.symmetry_operations.shape+self.shape,mode='right') sym_ops = self.structure.symmetry_operations
o = sym_ops.broadcast_to(sym_ops.shape+self.shape,mode='right')
return self.copy(rotation=o*Rotation(self.quaternion).broadcast_to(o.shape,mode='left')) return self.copy(rotation=o*Rotation(self.quaternion).broadcast_to(o.shape,mode='left'))
@ -817,11 +811,12 @@ class Orientation(Rotation):
Lab frame vector (or vectors if with_symmetry) along [uvw] direction or (hkl) plane normal. Lab frame vector (or vectors if with_symmetry) along [uvw] direction or (hkl) plane normal.
""" """
sym_ops = self.structure.symmetry_operations
# ToDo: simplify 'with_symmetry' # ToDo: simplify 'with_symmetry'
v = self.to_frame(uvw=uvw,hkl=hkl) v = self.to_frame(uvw=uvw,hkl=hkl)
if with_symmetry: if with_symmetry:
v = self.symmetry_operations.broadcast_to(self.symmetry_operations.shape+v.shape[:-1],mode='right') \ v = sym_ops.broadcast_to(sym_ops.shape+v.shape[:-1],mode='right') \
@ np.broadcast_to(v,self.symmetry_operations.shape+v.shape) @ np.broadcast_to(v,sym_ops.shape+v.shape)
return ~(self if self.shape+v.shape[:-1] == () else self.broadcast_to(self.shape+v.shape[:-1],mode='right')) \ return ~(self if self.shape+v.shape[:-1] == () else self.broadcast_to(self.shape+v.shape[:-1],mode='right')) \
@ np.broadcast_to(v,self.shape+v.shape) @ np.broadcast_to(v,self.shape+v.shape)

View File

@ -75,7 +75,7 @@ class TestOrientation:
]) ])
def test_invalid_init(self,kwargs): def test_invalid_init(self,kwargs):
with pytest.raises(ValueError): with pytest.raises(ValueError):
Orientation(**kwargs).parameters # noqa Orientation(**kwargs)
@pytest.mark.parametrize('kwargs',[ @pytest.mark.parametrize('kwargs',[
dict(lattice='aP',a=1.0,b=1.1,c=1.2,alpha=np.pi/4,beta=np.pi/3,gamma=np.pi/2), dict(lattice='aP',a=1.0,b=1.1,c=1.2,alpha=np.pi/4,beta=np.pi/3,gamma=np.pi/2),
@ -436,7 +436,7 @@ class TestOrientation:
a=a,b=b,c=c, a=a,b=b,c=c,
alpha=alpha,beta=beta,gamma=gamma) alpha=alpha,beta=beta,gamma=gamma)
assert o.to_pole(**{kw:vector,'with_symmetry':with_symmetry}).shape \ assert o.to_pole(**{kw:vector,'with_symmetry':with_symmetry}).shape \
== o.shape + (o.symmetry_operations.shape if with_symmetry else ()) + vector.shape == o.shape + (o.structure.symmetry_operations.shape if with_symmetry else ()) + vector.shape
@pytest.mark.parametrize('lattice',['hP','cI','cF']) @pytest.mark.parametrize('lattice',['hP','cI','cF'])
def test_Schmid(self,update,ref_path,lattice): def test_Schmid(self,update,ref_path,lattice):