equality checks

note: doing this type of comparison means:
- LatticeFamily('cubic') == Lattice('cF')
- Lattice('cF') != LatticeFamily('cubic')

we have the same behavior for comparison between Orientation and
Rotation
This commit is contained in:
Martin Diehl 2021-06-03 09:31:24 +02:00
parent 3b150ddbea
commit 03d3f362e6
3 changed files with 31 additions and 6 deletions

View File

@ -99,6 +99,18 @@ class Lattice(LatticeFamily):
raise ValueError ('Each lattice angle must be less than sum of others')
def __eq__(self,other):
"""
Equal to other.
Parameters
----------
other : Lattice
Lattice to check for equality.
"""
return self.lattice == other.lattice and self.parameters == other.parameters
@property
def parameters(self):
"""Return lattice parameters a, b, c, alpha, beta, gamma."""

View File

@ -19,6 +19,19 @@ class LatticeFamily():
self.family = family
def __eq__(self,other):
"""
Equal to other.
Parameters
----------
other : LatticeFamily
Lattice family to check for equality.
"""
return self.family == other.family
@property
def symmetry_operations(self):
"""Symmetry operations as Rotations."""

View File

@ -136,7 +136,7 @@ class Orientation(Rotation):
self.family = family
self.lattice = None
l = LatticeFamily(self.family) # noqa
self.structure = l = LatticeFamily(self.family) # noqa
self.immutable = l.immutable
self.basis = l.basis
self.symmetry_operations = l.symmetry_operations
@ -149,7 +149,7 @@ class Orientation(Rotation):
self.family = lattice_symmetries[lattice]
self.lattice = lattice
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.basis = l.basis
self.symmetry_operations = l.symmetry_operations
@ -210,8 +210,8 @@ class Orientation(Rotation):
Orientation to check for equality.
"""
matching_type = all([hasattr(other,attr) and getattr(self,attr) == getattr(other,attr)
for attr in ['family','lattice','parameters']])
matching_type = self.structure == other.structure if hasattr(other,'structure') else \
False
return np.logical_and(matching_type,super(self.__class__,self.reduced).__eq__(other.reduced))
def __ne__(self,other):
@ -248,8 +248,8 @@ class Orientation(Rotation):
Mask indicating where corresponding orientations are close.
"""
matching_type = all([hasattr(other,attr) and getattr(self,attr) == getattr(other,attr)
for attr in ['family','lattice','parameters']])
matching_type = self.structure == other.structure if hasattr(other,'structure') else \
False
return np.logical_and(matching_type,super(self.__class__,self.reduced).isclose(other.reduced))