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:
parent
3b150ddbea
commit
03d3f362e6
|
@ -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."""
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue