mirror of
https://github.com/triqs/dft_tools
synced 2024-12-23 12:55:17 +01:00
added helper function to flatten gf_struct objects for new triqs version
This commit is contained in:
parent
fae1217fa4
commit
9b22859553
@ -1157,5 +1157,45 @@ class BlockStructure(object):
|
|||||||
s += str(self.transformation)
|
s += str(self.transformation)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
def gf_struct_flatten(gf_struct):
|
||||||
|
'''
|
||||||
|
flattens gf_struct objecti
|
||||||
|
|
||||||
|
input gf_struct can looks like this:
|
||||||
|
|
||||||
|
[('up', [0, 1, 2]), ('down', [0, 1, 2])]
|
||||||
|
|
||||||
|
and will be returned as
|
||||||
|
|
||||||
|
[('up', 3), ('down', 3)]
|
||||||
|
|
||||||
|
Same for dict but replacing the values. This is for compatibility with the upcoming triqs releases.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
gf_struct: list of tuple or dict representing the Gf structure
|
||||||
|
__Returns:__
|
||||||
|
gf_struct_flat: flattens the values of the dict or the tuple representing the Gf indices by replacing them with the len of the list of indices
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
if isinstance(gf_struct, list):
|
||||||
|
# create a copy of the original list
|
||||||
|
gf_struct_flat = gf_struct.copy()
|
||||||
|
for idx, block in enumerate(gf_struct_flat):
|
||||||
|
# exchange list of indices with length of list
|
||||||
|
gf_struct_flat[idx] = (block[0], len(block[1]))
|
||||||
|
elif isinstance(gf_struct, dict):
|
||||||
|
# create a copy of the original dict
|
||||||
|
gf_struct_flat = dict(gf_struct)
|
||||||
|
for key, value in gf_struct_flat.items():
|
||||||
|
# exchange list of indices with length of list
|
||||||
|
gf_struct_flat[key] = len(value)
|
||||||
|
else:
|
||||||
|
raise Exception('gf_struct input needs to be list or dict')
|
||||||
|
|
||||||
|
|
||||||
|
return gf_struct_flat
|
||||||
|
|
||||||
from h5.formats import register_class
|
from h5.formats import register_class
|
||||||
register_class(BlockStructure)
|
register_class(BlockStructure)
|
||||||
|
Loading…
Reference in New Issue
Block a user