mirror of
https://github.com/triqs/dft_tools
synced 2024-11-18 12:03:50 +01:00
Modify block_structure for new gf_struct convention.
This commit is contained in:
parent
a8338819f0
commit
0a95ffd9d0
@ -48,11 +48,11 @@ class BlockStructure(object):
|
|||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
gf_struct_sumk : list of list of tuple
|
gf_struct_sumk : list of list of tuple
|
||||||
gf_struct_sumk[ish][idx] = (block_name,list of indices in block)
|
gf_struct_sumk[ish][idx] = (block_name, dimension of block)
|
||||||
|
|
||||||
for correlated shell ish; idx is just a counter in the list
|
for correlated shell ish; idx is just a counter in the list
|
||||||
gf_struct_solver : list of dict
|
gf_struct_solver : list of dict
|
||||||
gf_struct_solver[ish][block] = list of indices in that block
|
gf_struct_solver[ish][block] = dimension of that block
|
||||||
|
|
||||||
for *inequivalent* correlated shell ish
|
for *inequivalent* correlated shell ish
|
||||||
solver_to_sumk : list of dict
|
solver_to_sumk : list of dict
|
||||||
@ -197,7 +197,7 @@ class BlockStructure(object):
|
|||||||
"""
|
"""
|
||||||
if self.gf_struct_sumk is None:
|
if self.gf_struct_sumk is None:
|
||||||
return None
|
return None
|
||||||
return [{block: indices for block, indices in gfs}
|
return [{block: block_dim for block, block_dim in gfs}
|
||||||
for gfs in self.gf_struct_sumk]
|
for gfs in self.gf_struct_sumk]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -249,7 +249,7 @@ class BlockStructure(object):
|
|||||||
raise Exception('gf_struct_solver not set.')
|
raise Exception('gf_struct_solver not set.')
|
||||||
|
|
||||||
if trans is None:
|
if trans is None:
|
||||||
trans = [{block: np.eye(len(indices)) for block, indices in gfs}
|
trans = [{block: np.eye(block_dim) for block, block_dim in gfs}
|
||||||
for gfs in self.gf_struct_sumk]
|
for gfs in self.gf_struct_sumk]
|
||||||
|
|
||||||
assert isinstance(trans, list),\
|
assert isinstance(trans, list),\
|
||||||
@ -261,12 +261,12 @@ class BlockStructure(object):
|
|||||||
for icrsh in list(range(len(trans))):
|
for icrsh in list(range(len(trans))):
|
||||||
ish = self.corr_to_inequiv[icrsh]
|
ish = self.corr_to_inequiv[icrsh]
|
||||||
if trans[icrsh] is None:
|
if trans[icrsh] is None:
|
||||||
trans[icrsh] = {block: np.eye(len(indices))
|
trans[icrsh] = {block: np.eye(block_dim)
|
||||||
for block, indices in self.gf_struct_sumk[icrsh]}
|
for block, block_dim in self.gf_struct_sumk[icrsh]}
|
||||||
|
|
||||||
if not isinstance(trans[icrsh], dict):
|
if not isinstance(trans[icrsh], dict):
|
||||||
trans[icrsh] = {block: copy.deepcopy(trans[icrsh])
|
trans[icrsh] = {block: copy.deepcopy(trans[icrsh])
|
||||||
for block, indices in self.gf_struct_sumk[icrsh]}
|
for block, block_dim in self.gf_struct_sumk[icrsh]}
|
||||||
|
|
||||||
assert list(trans[icrsh].keys()) == list(self.gf_struct_sumk_dict[icrsh].keys()),\
|
assert list(trans[icrsh].keys()) == list(self.gf_struct_sumk_dict[icrsh].keys()),\
|
||||||
"wrong block names used in transformation (icrsh = {})".format(icrsh)
|
"wrong block names used in transformation (icrsh = {})".format(icrsh)
|
||||||
@ -275,14 +275,18 @@ class BlockStructure(object):
|
|||||||
assert trans[icrsh][block].shape[0] == trans[icrsh][block].shape[1],\
|
assert trans[icrsh][block].shape[0] == trans[icrsh][block].shape[1],\
|
||||||
"Transformation has to be quadratic; throwing away orbitals can be achieved on the level of the mapping. (icrsh = {}, block = {})".format(icrsh, block)
|
"Transformation has to be quadratic; throwing away orbitals can be achieved on the level of the mapping. (icrsh = {}, block = {})".format(icrsh, block)
|
||||||
|
|
||||||
assert trans[icrsh][block].shape[0] == len(self.gf_struct_sumk_dict[icrsh][block]),\
|
assert trans[icrsh][block].shape[0] == self.gf_struct_sumk_dict[icrsh][block],\
|
||||||
"Transformation block shape does not match gf_struct_sumk. (icrsh = {}, block = {})".format(icrsh, block)
|
"Transformation block shape does not match gf_struct_sumk. (icrsh = {}, block = {})".format(icrsh, block)
|
||||||
|
|
||||||
# zero out all the lines of the transformation that are
|
# zero out all the lines of the transformation that are
|
||||||
# not included in gf_struct_solver
|
# not included in gf_struct_solver
|
||||||
for iorb, norb in enumerate(self.gf_struct_sumk_dict[icrsh][block]):
|
#TODO CHECK THIS!
|
||||||
if self.sumk_to_solver[ish][(block, norb)][0] is None:
|
for iorb in range(self.gf_struct_sumk_dict[icrsh][block]):
|
||||||
|
if self.sumk_to_solver[ish][(block, iorb)][0] is None:
|
||||||
trans[icrsh][block][iorb, :] = 0.0
|
trans[icrsh][block][iorb, :] = 0.0
|
||||||
|
# for iorb, norb in enumerate(self.gf_struct_sumk_dict[icrsh][block]):
|
||||||
|
# if self.sumk_to_solver[ish][(block, norb)][0] is None:
|
||||||
|
# trans[icrsh][block][iorb, :] = 0.0
|
||||||
return trans
|
return trans
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -321,10 +325,10 @@ class BlockStructure(object):
|
|||||||
for block in self.gf_struct_solver[ish]:
|
for block in self.gf_struct_solver[ish]:
|
||||||
block_sumk = self.solver_to_sumk_block[ish][block]
|
block_sumk = self.solver_to_sumk_block[ish][block]
|
||||||
T = eff_trans_sumk[icrsh][block_sumk]
|
T = eff_trans_sumk[icrsh][block_sumk]
|
||||||
ets[ish][block] = np.zeros((len(self.gf_struct_solver[ish][block]),
|
ets[ish][block] = np.zeros((self.gf_struct_solver[ish][block],
|
||||||
len(T)),
|
len(T)),
|
||||||
dtype=T.dtype)
|
dtype=T.dtype)
|
||||||
for i in self.gf_struct_solver[ish][block]:
|
for i in range(self.gf_struct_solver[ish][block]):
|
||||||
i_sumk = self.solver_to_sumk[ish][block, i]
|
i_sumk = self.solver_to_sumk[ish][block, i]
|
||||||
assert i_sumk[0] == block_sumk,\
|
assert i_sumk[0] == block_sumk,\
|
||||||
"Wrong block in solver_to_sumk"
|
"Wrong block in solver_to_sumk"
|
||||||
@ -343,7 +347,7 @@ class BlockStructure(object):
|
|||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
gf_struct : list of dict
|
gf_struct : list of dict
|
||||||
gf_struct[ish][block] = list of indices in that block
|
gf_struct[ish][block] = block dimension of that block
|
||||||
|
|
||||||
for (inequivalent) correlated shell ish
|
for (inequivalent) correlated shell ish
|
||||||
corr_to_inequiv : list
|
corr_to_inequiv : list
|
||||||
@ -365,7 +369,7 @@ class BlockStructure(object):
|
|||||||
gss = []
|
gss = []
|
||||||
for block in gf_struct[ish]:
|
for block in gf_struct[ish]:
|
||||||
so2sublock[block]=block
|
so2sublock[block]=block
|
||||||
for ind in gf_struct[ish][block]:
|
for ind in range(gf_struct[ish][block]):
|
||||||
so2su[(block,ind)]=(block,ind)
|
so2su[(block,ind)]=(block,ind)
|
||||||
gss.append((block,gf_struct[ish][block]))
|
gss.append((block,gf_struct[ish][block]))
|
||||||
solver_to_sumk.append(so2su)
|
solver_to_sumk.append(so2su)
|
||||||
@ -409,16 +413,14 @@ class BlockStructure(object):
|
|||||||
|
|
||||||
[{'up':[0],'down':[1]}]
|
[{'up':[0],'down':[1]}]
|
||||||
|
|
||||||
Note that the indices will be renamed to be a 0-based
|
Note that as of version 3.1.x, the new structure itself will
|
||||||
sequence of integers, i.e. the new structure will actually
|
actually be stored as [{'up':1,'down':1}].
|
||||||
be [{'up':[0],'down':[0]}].
|
|
||||||
|
|
||||||
For dropped indices, sumk_to_solver will map to (None,None).
|
For dropped indices, sumk_to_solver will map to (None,None).
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
new_gf_struct : list of dict
|
new_gf_struct : list of dict
|
||||||
formatted the same as gf_struct_solver:
|
|
||||||
|
|
||||||
new_gf_struct[ish][block]=list of indices in that block.
|
new_gf_struct[ish][block]=list of indices in that block.
|
||||||
"""
|
"""
|
||||||
@ -454,7 +456,8 @@ class BlockStructure(object):
|
|||||||
|
|
||||||
# reindexing gf_struct so that it starts with 0
|
# reindexing gf_struct so that it starts with 0
|
||||||
for k in gf_struct:
|
for k in gf_struct:
|
||||||
gf_struct[k]=list(range(len(gf_struct[k])))
|
# gf_struct[k]=list(range(len(gf_struct[k])))
|
||||||
|
gf_struct[k]=len(gf_struct[k])
|
||||||
self.gf_struct_solver[ish]=gf_struct
|
self.gf_struct_solver[ish]=gf_struct
|
||||||
|
|
||||||
def adapt_deg_shells(self, gf_struct, ish=0):
|
def adapt_deg_shells(self, gf_struct, ish=0):
|
||||||
@ -468,7 +471,7 @@ class BlockStructure(object):
|
|||||||
if not key in gf_struct:
|
if not key in gf_struct:
|
||||||
del degsh[key]
|
del degsh[key]
|
||||||
continue
|
continue
|
||||||
if gf_struct[key] != self.gf_struct_solver[ish][key]:
|
if len(gf_struct[key]) != self.gf_struct_solver[ish][key]:
|
||||||
v, C = degsh[key]
|
v, C = degsh[key]
|
||||||
degsh[key][0] = \
|
degsh[key][0] = \
|
||||||
v[gf_struct[key], :][:, gf_struct[key]]
|
v[gf_struct[key], :][:, gf_struct[key]]
|
||||||
@ -509,7 +512,6 @@ class BlockStructure(object):
|
|||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
new_gf_struct : list of dict
|
new_gf_struct : list of dict
|
||||||
formatted the same as gf_struct_solver:
|
|
||||||
|
|
||||||
new_gf_struct[ish][block]=list of indices in that block.
|
new_gf_struct[ish][block]=list of indices in that block.
|
||||||
|
|
||||||
@ -529,16 +531,16 @@ class BlockStructure(object):
|
|||||||
# one non-zero entry
|
# one non-zero entry
|
||||||
|
|
||||||
for icrsh in range(len(new_gf_struct)):
|
for icrsh in range(len(new_gf_struct)):
|
||||||
for block, indices in self.gf_struct_sumk[icrsh]:
|
for block, block_dim in self.gf_struct_sumk[icrsh]:
|
||||||
if not block in new_gf_struct[icrsh]:
|
if not block in new_gf_struct[icrsh]:
|
||||||
#del new_gf_struct_transformed[block] # this MUST be wrong, as new_gf_struct_transformed needs to have a integer index for icrsh... # error when index is not kept at all
|
#del new_gf_struct_transformed[block] # this MUST be wrong, as new_gf_struct_transformed needs to have a integer index for icrsh... # error when index is not kept at all
|
||||||
continue
|
continue
|
||||||
T = eff_trans_sumk[icrsh][block]
|
T = eff_trans_sumk[icrsh][block]
|
||||||
for index in indices:
|
for index in range(block_dim):
|
||||||
if not index in new_gf_struct[icrsh][block]:
|
if not index in new_gf_struct[icrsh][block]:
|
||||||
T[:, index] = 0.0
|
T[:, index] = 0.0
|
||||||
new_indices = []
|
new_indices = []
|
||||||
for index in indices:
|
for index in range(block_dim):
|
||||||
if np.any(np.abs(T[index, :]) > 1.e-15):
|
if np.any(np.abs(T[index, :]) > 1.e-15):
|
||||||
new_indices.append(index)
|
new_indices.append(index)
|
||||||
new_gf_struct_transformed[icrsh][block] = new_indices
|
new_gf_struct_transformed[icrsh][block] = new_indices
|
||||||
@ -558,6 +560,7 @@ class BlockStructure(object):
|
|||||||
gfs[icrsh][ind_sol[0]].append(ind_sol[1])
|
gfs[icrsh][ind_sol[0]].append(ind_sol[1])
|
||||||
self.pick_gf_struct_solver(gfs)
|
self.pick_gf_struct_solver(gfs)
|
||||||
|
|
||||||
|
# TODO!
|
||||||
def map_gf_struct_solver(self, mapping):
|
def map_gf_struct_solver(self, mapping):
|
||||||
r""" Map the Green function structure from one struct to another.
|
r""" Map the Green function structure from one struct to another.
|
||||||
|
|
||||||
@ -660,8 +663,8 @@ class BlockStructure(object):
|
|||||||
which space the structure should correspond to
|
which space the structure should correspond to
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def gf_function(indices):
|
def gf_function(target_shape):
|
||||||
return np.zeros((len(indices), len(indices)), dtype=dtype)
|
return np.zeros(target_shape, dtype=dtype)
|
||||||
|
|
||||||
def block_function(name_list, block_list):
|
def block_function(name_list, block_list):
|
||||||
d = dict()
|
d = dict()
|
||||||
@ -683,7 +686,7 @@ class BlockStructure(object):
|
|||||||
names = list(gf_struct[ish].keys())
|
names = list(gf_struct[ish].keys())
|
||||||
blocks = []
|
blocks = []
|
||||||
for n in names:
|
for n in names:
|
||||||
G = gf_function(indices=gf_struct[ish][n], **kwargs)
|
G = gf_function(target_shape=(gf_struct[ish][n],gf_struct[ish][n]), **kwargs)
|
||||||
blocks.append(G)
|
blocks.append(G)
|
||||||
G = block_function(name_list=names, block_list=blocks)
|
G = block_function(name_list=names, block_list=blocks)
|
||||||
return G
|
return G
|
||||||
@ -766,7 +769,7 @@ class BlockStructure(object):
|
|||||||
for block, gf in G:
|
for block, gf in G:
|
||||||
assert block in gf_struct[ish],\
|
assert block in gf_struct[ish],\
|
||||||
"block " + block + " not in struct (shell {})".format(ish)
|
"block " + block + " not in struct (shell {})".format(ish)
|
||||||
assert list(gf.indices) == 2 * [list(map(str, gf_struct[ish][block]))],\
|
assert (gf.target_shape) == (gf_struct[ish][block], gf_struct[ish][block]),\
|
||||||
"block " + block + \
|
"block " + block + \
|
||||||
" has wrong indices (shell {})".format(ish)
|
" has wrong indices (shell {})".format(ish)
|
||||||
else:
|
else:
|
||||||
@ -776,7 +779,7 @@ class BlockStructure(object):
|
|||||||
for block, gf in list(G.items()):
|
for block, gf in list(G.items()):
|
||||||
assert block in gf_struct[ish],\
|
assert block in gf_struct[ish],\
|
||||||
"block " + block + " not in struct (shell {})".format(ish)
|
"block " + block + " not in struct (shell {})".format(ish)
|
||||||
assert list(range(len(gf))) == 2 * [list(map(str, gf_struct[ish][block]))],\
|
assert len(gf) == gf_struct[ish][block],\
|
||||||
"block " + block + \
|
"block " + block + \
|
||||||
" has wrong indices (shell {})".format(ish)
|
" has wrong indices (shell {})".format(ish)
|
||||||
|
|
||||||
@ -936,8 +939,8 @@ class BlockStructure(object):
|
|||||||
block_mapping_from = G_struct.sumk_to_solver_block[ish_from]
|
block_mapping_from = G_struct.sumk_to_solver_block[ish_from]
|
||||||
elif space_from == 'sumk':
|
elif space_from == 'sumk':
|
||||||
gf_struct_from = G_struct.gf_struct_sumk_dict[ish_from]
|
gf_struct_from = G_struct.gf_struct_sumk_dict[ish_from]
|
||||||
eff_trans_from = {block: np.eye(len(indices))
|
eff_trans_from = {block: np.eye(block_dim)
|
||||||
for block, indices in G_struct.gf_struct_sumk[ish_from]}
|
for block, block_dim in G_struct.gf_struct_sumk[ish_from]}
|
||||||
block_mapping_from = {b: [b] for b in gf_struct_from}
|
block_mapping_from = {b: [b] for b in gf_struct_from}
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
@ -949,8 +952,8 @@ class BlockStructure(object):
|
|||||||
block_mapping_to = self.solver_to_sumk_block[ish_to]
|
block_mapping_to = self.solver_to_sumk_block[ish_to]
|
||||||
elif space_to == 'sumk':
|
elif space_to == 'sumk':
|
||||||
gf_struct_to = self.gf_struct_sumk_dict[ish_to]
|
gf_struct_to = self.gf_struct_sumk_dict[ish_to]
|
||||||
eff_trans_to = {block: np.eye(len(indices))
|
eff_trans_to = {block: np.eye(block_dim)
|
||||||
for block, indices in self.gf_struct_sumk_list[ish_to]}
|
for block, block_dim in self.gf_struct_sumk_list[ish_to]}
|
||||||
block_mapping_to = {b: b for b in gf_struct_to}
|
block_mapping_to = {b: b for b in gf_struct_to}
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
@ -1046,7 +1049,7 @@ class BlockStructure(object):
|
|||||||
self.solver_to_sumk_block.append({})
|
self.solver_to_sumk_block.append({})
|
||||||
for frm,to in list(self.sumk_to_solver[ish].items()):
|
for frm,to in list(self.sumk_to_solver[ish].items()):
|
||||||
if to[0] is not None:
|
if to[0] is not None:
|
||||||
self.gf_struct_solver[ish][frm[0]+'_'+str(frm[1])]=[0]
|
self.gf_struct_solver[ish][frm[0]+'_'+str(frm[1])]=1
|
||||||
self.sumk_to_solver[ish][frm]=(frm[0]+'_'+str(frm[1]),0)
|
self.sumk_to_solver[ish][frm]=(frm[0]+'_'+str(frm[1]),0)
|
||||||
self.solver_to_sumk[ish][(frm[0]+'_'+str(frm[1]),0)]=frm
|
self.solver_to_sumk[ish][(frm[0]+'_'+str(frm[1]),0)]=frm
|
||||||
self.solver_to_sumk_block[ish][frm[0]+'_'+str(frm[1])]=frm[0]
|
self.solver_to_sumk_block[ish][frm[0]+'_'+str(frm[1])]=frm[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user