3
0
mirror of https://github.com/triqs/dft_tools synced 2024-09-12 05:38:31 +02:00

block_structure: add check_gf method

This commit is contained in:
Gernot J. Kraberger 2018-08-29 11:29:46 +02:00
parent f4ad91f8b4
commit 6c908e9c6e
2 changed files with 74 additions and 31 deletions

View File

@ -281,6 +281,46 @@ class BlockStructure(object):
G = BlockGf(name_list = names, block_list = blocks) G = BlockGf(name_list = names, block_list = blocks)
return G return G
def check_gf(self, G, ish=None):
""" check whether the Green's function G has the right structure
This throws an error if the structure of G is not the same
as ``gf_struct_solver``.
Parameters
----------
G : BlockGf or list of BlockGf
Green's function to check
if it is a list, there should be as many entries as there
are shells, and the check is performed for all shells (unless
ish is given).
ish : int
shell index
default: 0 if G is just one Green's function is given,
check all if list of Green's functions is given
"""
if isinstance(G, list):
assert len(G) == len(self.gf_struct_solver),\
"list of G does not have the correct length"
if ish is None:
ishs = range(len(self.gf_struct_solver))
else:
ishs = [ish]
for ish in ishs:
self.check_gf(G[ish], ish=ish)
return
if ish is None:
ish = 0
for block in self.gf_struct_solver[ish]:
assert block in G.indices,\
"block " + block + " not in G (shell {})".format(ish)
for block, gf in G:
assert block in self.gf_struct_solver[ish],\
"block " + block + " not in struct (shell {})".format(ish)
assert list(gf.indices) == 2 * [map(str, self.gf_struct_solver[ish][block])],\
"block " + block + " has wrong indices (shell {})".format(ish)
def convert_gf(self,G,G_struct,ish=0,show_warnings=True,**kwargs): def convert_gf(self,G,G_struct,ish=0,show_warnings=True,**kwargs):
""" Convert BlockGf from its structure to this structure. """ Convert BlockGf from its structure to this structure.

View File

@ -44,6 +44,8 @@ i = 1
for block, gf in G1: for block, gf in G1:
gf << SemiCircular(i) gf << SemiCircular(i)
i += 1 i += 1
original_bs.check_gf(G1)
original_bs.check_gf([G1])
# check approximate_as_diagonal # check approximate_as_diagonal
offd = original_bs.copy() offd = original_bs.copy()
@ -53,7 +55,8 @@ offd.approximate_as_diagonal()
G2 = map1.convert_gf(G1, original_bs, beta=40, n_points=3, show_warnings=False) G2 = map1.convert_gf(G1, original_bs, beta=40, n_points=3, show_warnings=False)
# check full_structure # check full_structure
full = BlockStructure.full_structure([{'up_0': [0, 1], 'up_1': [0], 'down_1': [0], 'down_0': [0, 1]}],None) full = BlockStructure.full_structure(
[{'up_0': [0, 1], 'up_1': [0], 'down_1': [0], 'down_0': [0, 1]}], None)
# check __eq__ # check __eq__
assert full == full, 'equality not correct (equal structures not equal)' assert full == full, 'equality not correct (equal structures not equal)'