Commit c9908074 authored by Tómas's avatar Tómas Committed by Joseph Weston

add validate_symmetries methods to finalized systems

parent 3afbfebd
......@@ -141,10 +141,11 @@ class DiscreteSymmetry:
Returns
-------
broken_symmetry : string or ``None``
One of "Conservation law", "Time reversal", "Particle-hole",
"Chiral": the symmetry broken by the matrix. If the matrix breaks
more than one symmetry, returns only the first failed check.
broken_symmetries : list or ``None``
List of strings, the names of symmetries broken by the
matrix: any combination of "Conservation law", "Time reversal",
"Particle-hole", "Chiral". If no symmetries are broken, returns
None.
"""
# Extra transposes are to enforse sparse dot product in case matrix is
# dense.
......
......@@ -164,6 +164,17 @@ class FiniteSystem(System, metaclass=abc.ABCMeta):
result.leads = new_leads
return result
def validate_symmetries(self, args=(), *, params=None):
"""Check that the Hamiltonian satisfies discrete symmetries.
Applies `~kwant.physics.DiscreteSymmetry.validate` to the
Hamiltonian, see its documentation for details on the return
format.
"""
symmetries = self.discrete_symmetry(args=args, params=params)
ham = self.hamiltonian_submatrix(args, sparse=True, params=params)
return symmetries.validate(ham)
class InfiniteSystem(System, metaclass=abc.ABCMeta):
"""Abstract infinite low-level system.
......@@ -242,8 +253,8 @@ class InfiniteSystem(System, metaclass=abc.ABCMeta):
symmetries.validate(hop))
if item is not None for symmetry in item}
for name in broken:
warnings.warn("Hamiltonian breaks " + name +
", ignoring the symmetry in the computation.")
warnings.warn('Hamiltonian breaks ' + name +
', ignoring the symmetry in the computation.')
if name == 'Conservation law':
symmetries.projectors = None
elif name == 'Time reversal':
......@@ -253,8 +264,8 @@ class InfiniteSystem(System, metaclass=abc.ABCMeta):
elif name == 'Chiral':
symmetries.chiral = None
else:
warnings.warn("Misidentified a broken symmetry"
" in the lead.")
warnings.warn('Misidentified a broken symmetry'
' in the lead.')
shape = ham.shape
assert len(shape) == 2
assert shape[0] == shape[1]
......@@ -283,6 +294,24 @@ class InfiniteSystem(System, metaclass=abc.ABCMeta):
return physics.selfenergy(ham,
self.inter_cell_hopping(args, params=params))
def validate_symmetries(self, args=(), *, params=None):
"""Check that the Hamiltonian satisfies discrete symmetries.
Returns `~kwant.physics.DiscreteSymmetry.validate` applied
to the onsite matrix and the hopping. See its documentation for
details on the return format.
"""
symmetries = self.discrete_symmetry(args=args, params=params)
ham = self.cell_hamiltonian(args=args, sparse=True, params=params)
hop = self.inter_cell_hopping(args=args, sparse=True, params=params)
broken = list({symmetry for item in (symmetries.validate(ham),
symmetries.validate(hop))
if item is not None for symmetry in item})
if len(broken):
return broken
else:
return broken
class PrecalculatedLead:
def __init__(self, modes=None, selfenergy=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment