WIP: more reasonable naming
This commit is contained in:
parent
b8b34080fe
commit
ce7018164f
|
@ -5,7 +5,7 @@ from . import Rotation
|
||||||
|
|
||||||
class Symmetry:
|
class Symmetry:
|
||||||
"""
|
"""
|
||||||
Symmetry operations for lattice systems.
|
Symmetry-related operations for crystal systems.
|
||||||
|
|
||||||
References
|
References
|
||||||
----------
|
----------
|
||||||
|
@ -13,34 +13,35 @@ class Symmetry:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
lattices = [None,'orthorhombic','tetragonal','hexagonal','cubic']
|
crystal_systems = [None,'orthorhombic','tetragonal','hexagonal','cubic']
|
||||||
|
|
||||||
def __init__(self, symmetry = None):
|
def __init__(self, system = None):
|
||||||
"""
|
"""
|
||||||
Symmetry Definition.
|
Symmetry Definition.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
symmetry : str, optional
|
system : {None,'orthorhombic','tetragonal','hexagonal','cubic'}, optional
|
||||||
label of the crystal system
|
Name of the crystal system. Defaults to 'None'.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if symmetry is not None and symmetry.lower() not in Symmetry.lattices:
|
if system is not None and system.lower() not in self.crystal_systems:
|
||||||
raise KeyError('Symmetry/crystal system "{}" is unknown'.format(symmetry))
|
raise KeyError(f'Crystal system "{system}" is unknown')
|
||||||
|
|
||||||
self.lattice = symmetry.lower() if isinstance(symmetry,str) else symmetry
|
self.system = system.lower() if isinstance(system,str) else system
|
||||||
|
self.lattice = self.system # for compatibility
|
||||||
|
|
||||||
|
|
||||||
def __copy__(self):
|
def __copy__(self):
|
||||||
"""Copy."""
|
"""Copy."""
|
||||||
return self.__class__(self.lattice)
|
return self.__class__(self.system)
|
||||||
|
|
||||||
copy = __copy__
|
copy = __copy__
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""Readable string."""
|
"""Readable string."""
|
||||||
return '{}'.format(self.lattice)
|
return '{}'.format(self.system)
|
||||||
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
@ -53,7 +54,7 @@ class Symmetry:
|
||||||
Symmetry to check for equality.
|
Symmetry to check for equality.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self.lattice == other.lattice
|
return self.system == other.system
|
||||||
|
|
||||||
def __neq__(self, other):
|
def __neq__(self, other):
|
||||||
"""
|
"""
|
||||||
|
@ -77,13 +78,13 @@ class Symmetry:
|
||||||
Symmetry to check for for order.
|
Symmetry to check for for order.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
myOrder = Symmetry.lattices.index(self.lattice)
|
myOrder = self.crystal_systems.index(self.system)
|
||||||
otherOrder = Symmetry.lattices.index(other.lattice)
|
otherOrder = self.crystal_systems.index(other.system)
|
||||||
return (myOrder > otherOrder) - (myOrder < otherOrder)
|
return (myOrder > otherOrder) - (myOrder < otherOrder)
|
||||||
|
|
||||||
def symmetryOperations(self,members=[]):
|
def symmetryOperations(self,members=[]):
|
||||||
"""List (or single element) of symmetry operations as rotations."""
|
"""List (or single element) of symmetry operations as rotations."""
|
||||||
if self.lattice == 'cubic':
|
if self.system == 'cubic':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
[ 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 ],
|
||||||
|
@ -110,7 +111,7 @@ class Symmetry:
|
||||||
[-0.5*np.sqrt(2), 0.5*np.sqrt(2), 0.0, 0.0 ],
|
[-0.5*np.sqrt(2), 0.5*np.sqrt(2), 0.0, 0.0 ],
|
||||||
[-0.5*np.sqrt(2),-0.5*np.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.system == 'hexagonal':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
[ 1.0, 0.0, 0.0, 0.0 ],
|
[ 1.0, 0.0, 0.0, 0.0 ],
|
||||||
[-0.5*np.sqrt(3), 0.0, 0.0, -0.5 ],
|
[-0.5*np.sqrt(3), 0.0, 0.0, -0.5 ],
|
||||||
|
@ -125,7 +126,7 @@ class Symmetry:
|
||||||
[ 0.0, -0.5, -0.5*np.sqrt(3), 0.0 ],
|
[ 0.0, -0.5, -0.5*np.sqrt(3), 0.0 ],
|
||||||
[ 0.0, 0.5*np.sqrt(3), 0.5, 0.0 ],
|
[ 0.0, 0.5*np.sqrt(3), 0.5, 0.0 ],
|
||||||
]
|
]
|
||||||
elif self.lattice == 'tetragonal':
|
elif self.system == 'tetragonal':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
[ 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 ],
|
||||||
|
@ -136,7 +137,7 @@ class Symmetry:
|
||||||
[ 0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
[ 0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
||||||
[-0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
[-0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
||||||
]
|
]
|
||||||
elif self.lattice == 'orthorhombic':
|
elif self.system == 'orthorhombic':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
[ 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 ],
|
||||||
|
@ -160,7 +161,7 @@ class Symmetry:
|
||||||
@property
|
@property
|
||||||
def symmetry_operations(self):
|
def symmetry_operations(self):
|
||||||
"""Symmetry operations as Rotations."""
|
"""Symmetry operations as Rotations."""
|
||||||
if self.lattice == 'cubic':
|
if self.system == 'cubic':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
[ 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 ],
|
||||||
|
@ -187,7 +188,7 @@ class Symmetry:
|
||||||
[-0.5*np.sqrt(2), 0.5*np.sqrt(2), 0.0, 0.0 ],
|
[-0.5*np.sqrt(2), 0.5*np.sqrt(2), 0.0, 0.0 ],
|
||||||
[-0.5*np.sqrt(2),-0.5*np.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.system == 'hexagonal':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
[ 1.0, 0.0, 0.0, 0.0 ],
|
[ 1.0, 0.0, 0.0, 0.0 ],
|
||||||
[-0.5*np.sqrt(3), 0.0, 0.0, -0.5 ],
|
[-0.5*np.sqrt(3), 0.0, 0.0, -0.5 ],
|
||||||
|
@ -202,7 +203,7 @@ class Symmetry:
|
||||||
[ 0.0, -0.5, -0.5*np.sqrt(3), 0.0 ],
|
[ 0.0, -0.5, -0.5*np.sqrt(3), 0.0 ],
|
||||||
[ 0.0, 0.5*np.sqrt(3), 0.5, 0.0 ],
|
[ 0.0, 0.5*np.sqrt(3), 0.5, 0.0 ],
|
||||||
]
|
]
|
||||||
elif self.lattice == 'tetragonal':
|
elif self.system == 'tetragonal':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
[ 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 ],
|
||||||
|
@ -213,7 +214,7 @@ class Symmetry:
|
||||||
[ 0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
[ 0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
||||||
[-0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
[-0.5*np.sqrt(2), 0.0, 0.0, 0.5*np.sqrt(2) ],
|
||||||
]
|
]
|
||||||
elif self.lattice == 'orthorhombic':
|
elif self.system == 'orthorhombic':
|
||||||
symQuats = [
|
symQuats = [
|
||||||
[ 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 ],
|
||||||
|
@ -240,21 +241,21 @@ class Symmetry:
|
||||||
|
|
||||||
Rabs = abs(rodrigues)
|
Rabs = abs(rodrigues)
|
||||||
|
|
||||||
if self.lattice == 'cubic':
|
if self.system == 'cubic':
|
||||||
return np.sqrt(2.0)-1.0 >= Rabs[0] \
|
return np.sqrt(2.0)-1.0 >= Rabs[0] \
|
||||||
and np.sqrt(2.0)-1.0 >= Rabs[1] \
|
and np.sqrt(2.0)-1.0 >= Rabs[1] \
|
||||||
and np.sqrt(2.0)-1.0 >= Rabs[2] \
|
and np.sqrt(2.0)-1.0 >= Rabs[2] \
|
||||||
and 1.0 >= Rabs[0] + Rabs[1] + Rabs[2]
|
and 1.0 >= Rabs[0] + Rabs[1] + Rabs[2]
|
||||||
elif self.lattice == 'hexagonal':
|
elif self.system == 'hexagonal':
|
||||||
return 1.0 >= Rabs[0] and 1.0 >= Rabs[1] and 1.0 >= Rabs[2] \
|
return 1.0 >= Rabs[0] and 1.0 >= Rabs[1] and 1.0 >= Rabs[2] \
|
||||||
and 2.0 >= np.sqrt(3)*Rabs[0] + Rabs[1] \
|
and 2.0 >= np.sqrt(3)*Rabs[0] + Rabs[1] \
|
||||||
and 2.0 >= np.sqrt(3)*Rabs[1] + Rabs[0] \
|
and 2.0 >= np.sqrt(3)*Rabs[1] + Rabs[0] \
|
||||||
and 2.0 >= np.sqrt(3) + Rabs[2]
|
and 2.0 >= np.sqrt(3) + Rabs[2]
|
||||||
elif self.lattice == 'tetragonal':
|
elif self.system == 'tetragonal':
|
||||||
return 1.0 >= Rabs[0] and 1.0 >= Rabs[1] \
|
return 1.0 >= Rabs[0] and 1.0 >= Rabs[1] \
|
||||||
and np.sqrt(2.0) >= Rabs[0] + Rabs[1] \
|
and np.sqrt(2.0) >= Rabs[0] + Rabs[1] \
|
||||||
and np.sqrt(2.0) >= Rabs[2] + 1.0
|
and np.sqrt(2.0) >= Rabs[2] + 1.0
|
||||||
elif self.lattice == 'orthorhombic':
|
elif self.system == 'orthorhombic':
|
||||||
return 1.0 >= Rabs[0] and 1.0 >= Rabs[1] and 1.0 >= Rabs[2]
|
return 1.0 >= Rabs[0] and 1.0 >= Rabs[1] and 1.0 >= Rabs[2]
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
@ -275,13 +276,13 @@ class Symmetry:
|
||||||
R = rodrigues
|
R = rodrigues
|
||||||
|
|
||||||
epsilon = 0.0
|
epsilon = 0.0
|
||||||
if self.lattice == 'cubic':
|
if self.system == 'cubic':
|
||||||
return R[0] >= R[1]+epsilon and R[1] >= R[2]+epsilon and R[2] >= epsilon
|
return R[0] >= R[1]+epsilon and R[1] >= R[2]+epsilon and R[2] >= epsilon
|
||||||
elif self.lattice == 'hexagonal':
|
elif self.system == 'hexagonal':
|
||||||
return R[0] >= np.sqrt(3)*(R[1]-epsilon) and R[1] >= epsilon and R[2] >= epsilon
|
return R[0] >= np.sqrt(3)*(R[1]-epsilon) and R[1] >= epsilon and R[2] >= epsilon
|
||||||
elif self.lattice == 'tetragonal':
|
elif self.system == 'tetragonal':
|
||||||
return R[0] >= R[1]-epsilon and R[1] >= epsilon and R[2] >= epsilon
|
return R[0] >= R[1]-epsilon and R[1] >= epsilon and R[2] >= epsilon
|
||||||
elif self.lattice == 'orthorhombic':
|
elif self.system == 'orthorhombic':
|
||||||
return R[0] >= epsilon and R[1] >= epsilon and R[2] >= epsilon
|
return R[0] >= epsilon and R[1] >= epsilon and R[2] >= epsilon
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
@ -313,7 +314,7 @@ class Symmetry:
|
||||||
... }
|
... }
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self.lattice == 'cubic':
|
if self.system == 'cubic':
|
||||||
basis = {'improper':np.array([ [-1. , 0. , 1. ],
|
basis = {'improper':np.array([ [-1. , 0. , 1. ],
|
||||||
[ np.sqrt(2.) , -np.sqrt(2.) , 0. ],
|
[ np.sqrt(2.) , -np.sqrt(2.) , 0. ],
|
||||||
[ 0. , np.sqrt(3.) , 0. ] ]),
|
[ 0. , np.sqrt(3.) , 0. ] ]),
|
||||||
|
@ -321,7 +322,7 @@ class Symmetry:
|
||||||
[-np.sqrt(2.) , np.sqrt(2.) , 0. ],
|
[-np.sqrt(2.) , np.sqrt(2.) , 0. ],
|
||||||
[ np.sqrt(3.) , 0. , 0. ] ]),
|
[ np.sqrt(3.) , 0. , 0. ] ]),
|
||||||
}
|
}
|
||||||
elif self.lattice == 'hexagonal':
|
elif self.system == 'hexagonal':
|
||||||
basis = {'improper':np.array([ [ 0. , 0. , 1. ],
|
basis = {'improper':np.array([ [ 0. , 0. , 1. ],
|
||||||
[ 1. , -np.sqrt(3.) , 0. ],
|
[ 1. , -np.sqrt(3.) , 0. ],
|
||||||
[ 0. , 2. , 0. ] ]),
|
[ 0. , 2. , 0. ] ]),
|
||||||
|
@ -329,7 +330,7 @@ class Symmetry:
|
||||||
[-1. , np.sqrt(3.) , 0. ],
|
[-1. , np.sqrt(3.) , 0. ],
|
||||||
[ np.sqrt(3.) , -1. , 0. ] ]),
|
[ np.sqrt(3.) , -1. , 0. ] ]),
|
||||||
}
|
}
|
||||||
elif self.lattice == 'tetragonal':
|
elif self.system == 'tetragonal':
|
||||||
basis = {'improper':np.array([ [ 0. , 0. , 1. ],
|
basis = {'improper':np.array([ [ 0. , 0. , 1. ],
|
||||||
[ 1. , -1. , 0. ],
|
[ 1. , -1. , 0. ],
|
||||||
[ 0. , np.sqrt(2.) , 0. ] ]),
|
[ 0. , np.sqrt(2.) , 0. ] ]),
|
||||||
|
@ -337,7 +338,7 @@ class Symmetry:
|
||||||
[-1. , 1. , 0. ],
|
[-1. , 1. , 0. ],
|
||||||
[ np.sqrt(2.) , 0. , 0. ] ]),
|
[ np.sqrt(2.) , 0. , 0. ] ]),
|
||||||
}
|
}
|
||||||
elif self.lattice == 'orthorhombic':
|
elif self.system == 'orthorhombic':
|
||||||
basis = {'improper':np.array([ [ 0., 0., 1.],
|
basis = {'improper':np.array([ [ 0., 0., 1.],
|
||||||
[ 1., 0., 0.],
|
[ 1., 0., 0.],
|
||||||
[ 0., 1., 0.] ]),
|
[ 0., 1., 0.] ]),
|
||||||
|
@ -401,7 +402,7 @@ class Symmetry:
|
||||||
... }
|
... }
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self.lattice == 'cubic':
|
if self.system == 'cubic':
|
||||||
basis = {'improper':np.array([ [-1. , 0. , 1. ],
|
basis = {'improper':np.array([ [-1. , 0. , 1. ],
|
||||||
[ np.sqrt(2.) , -np.sqrt(2.) , 0. ],
|
[ np.sqrt(2.) , -np.sqrt(2.) , 0. ],
|
||||||
[ 0. , np.sqrt(3.) , 0. ] ]),
|
[ 0. , np.sqrt(3.) , 0. ] ]),
|
||||||
|
@ -409,7 +410,7 @@ class Symmetry:
|
||||||
[-np.sqrt(2.) , np.sqrt(2.) , 0. ],
|
[-np.sqrt(2.) , np.sqrt(2.) , 0. ],
|
||||||
[ np.sqrt(3.) , 0. , 0. ] ]),
|
[ np.sqrt(3.) , 0. , 0. ] ]),
|
||||||
}
|
}
|
||||||
elif self.lattice == 'hexagonal':
|
elif self.system == 'hexagonal':
|
||||||
basis = {'improper':np.array([ [ 0. , 0. , 1. ],
|
basis = {'improper':np.array([ [ 0. , 0. , 1. ],
|
||||||
[ 1. , -np.sqrt(3.) , 0. ],
|
[ 1. , -np.sqrt(3.) , 0. ],
|
||||||
[ 0. , 2. , 0. ] ]),
|
[ 0. , 2. , 0. ] ]),
|
||||||
|
@ -417,7 +418,7 @@ class Symmetry:
|
||||||
[-1. , np.sqrt(3.) , 0. ],
|
[-1. , np.sqrt(3.) , 0. ],
|
||||||
[ np.sqrt(3.) , -1. , 0. ] ]),
|
[ np.sqrt(3.) , -1. , 0. ] ]),
|
||||||
}
|
}
|
||||||
elif self.lattice == 'tetragonal':
|
elif self.system == 'tetragonal':
|
||||||
basis = {'improper':np.array([ [ 0. , 0. , 1. ],
|
basis = {'improper':np.array([ [ 0. , 0. , 1. ],
|
||||||
[ 1. , -1. , 0. ],
|
[ 1. , -1. , 0. ],
|
||||||
[ 0. , np.sqrt(2.) , 0. ] ]),
|
[ 0. , np.sqrt(2.) , 0. ] ]),
|
||||||
|
@ -425,7 +426,7 @@ class Symmetry:
|
||||||
[-1. , 1. , 0. ],
|
[-1. , 1. , 0. ],
|
||||||
[ np.sqrt(2.) , 0. , 0. ] ]),
|
[ np.sqrt(2.) , 0. , 0. ] ]),
|
||||||
}
|
}
|
||||||
elif self.lattice == 'orthorhombic':
|
elif self.system == 'orthorhombic':
|
||||||
basis = {'improper':np.array([ [ 0., 0., 1.],
|
basis = {'improper':np.array([ [ 0., 0., 1.],
|
||||||
[ 1., 0., 0.],
|
[ 1., 0., 0.],
|
||||||
[ 0., 1., 0.] ]),
|
[ 0., 1., 0.] ]),
|
||||||
|
|
|
@ -13,26 +13,26 @@ class TestSymmetry:
|
||||||
s = Symmetry(invalid_symmetry) # noqa
|
s = Symmetry(invalid_symmetry) # noqa
|
||||||
|
|
||||||
def test_equal(self):
|
def test_equal(self):
|
||||||
symmetry = random.choice(Symmetry.lattices)
|
symmetry = random.choice(Symmetry.crystal_systems)
|
||||||
print(symmetry)
|
print(symmetry)
|
||||||
assert Symmetry(symmetry) == Symmetry(symmetry)
|
assert Symmetry(symmetry) == Symmetry(symmetry)
|
||||||
|
|
||||||
def test_not_equal(self):
|
def test_not_equal(self):
|
||||||
symmetries = random.sample(Symmetry.lattices,k=2)
|
symmetries = random.sample(Symmetry.crystal_systems,k=2)
|
||||||
assert Symmetry(symmetries[0]) != Symmetry(symmetries[1])
|
assert Symmetry(symmetries[0]) != Symmetry(symmetries[1])
|
||||||
|
|
||||||
@pytest.mark.parametrize('lattice',Symmetry.lattices)
|
@pytest.mark.parametrize('system',Symmetry.crystal_systems)
|
||||||
def test_inFZ(self,lattice):
|
def test_inFZ(self,system):
|
||||||
assert Symmetry(lattice).inFZ(np.zeros(3))
|
assert Symmetry(system).inFZ(np.zeros(3))
|
||||||
|
|
||||||
@pytest.mark.parametrize('lattice',Symmetry.lattices)
|
@pytest.mark.parametrize('system',Symmetry.crystal_systems)
|
||||||
def test_inDisorientationSST(self,lattice):
|
def test_inDisorientationSST(self,system):
|
||||||
assert Symmetry(lattice).inDisorientationSST(np.zeros(3))
|
assert Symmetry(system).inDisorientationSST(np.zeros(3))
|
||||||
|
|
||||||
@pytest.mark.parametrize('lattice',Symmetry.lattices)
|
@pytest.mark.parametrize('system',Symmetry.crystal_systems)
|
||||||
@pytest.mark.parametrize('proper',[True,False])
|
@pytest.mark.parametrize('proper',[True,False])
|
||||||
def test_inSST(self,lattice,proper):
|
def test_inSST(self,system,proper):
|
||||||
assert Symmetry(lattice).inSST(np.zeros(3),proper)
|
assert Symmetry(system).inSST(np.zeros(3),proper)
|
||||||
|
|
||||||
@pytest.mark.parametrize('function',['inFZ','inDisorientationSST'])
|
@pytest.mark.parametrize('function',['inFZ','inDisorientationSST'])
|
||||||
def test_invalid_argument(self,function):
|
def test_invalid_argument(self,function):
|
||||||
|
|
Loading…
Reference in New Issue