mirror of
https://github.com/triqs/dft_tools
synced 2024-12-22 20:34:38 +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
|
||||
----------
|
||||
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
|
||||
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
|
||||
solver_to_sumk : list of dict
|
||||
@ -197,7 +197,7 @@ class BlockStructure(object):
|
||||
"""
|
||||
if self.gf_struct_sumk is 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]
|
||||
|
||||
@property
|
||||
@ -249,7 +249,7 @@ class BlockStructure(object):
|
||||
raise Exception('gf_struct_solver not set.')
|
||||
|
||||
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]
|
||||
|
||||
assert isinstance(trans, list),\
|
||||
@ -261,12 +261,12 @@ class BlockStructure(object):
|
||||
for icrsh in list(range(len(trans))):
|
||||
ish = self.corr_to_inequiv[icrsh]
|
||||
if trans[icrsh] is None:
|
||||
trans[icrsh] = {block: np.eye(len(indices))
|
||||
for block, indices in self.gf_struct_sumk[icrsh]}
|
||||
trans[icrsh] = {block: np.eye(block_dim)
|
||||
for block, block_dim in self.gf_struct_sumk[icrsh]}
|
||||
|
||||
if not isinstance(trans[icrsh], dict):
|
||||
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()),\
|
||||
"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],\
|
||||
"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)
|
||||
|
||||
# zero out all the lines of the transformation that are
|
||||
# not included in gf_struct_solver
|
||||
for iorb, norb in enumerate(self.gf_struct_sumk_dict[icrsh][block]):
|
||||
if self.sumk_to_solver[ish][(block, norb)][0] is None:
|
||||
#TODO CHECK THIS!
|
||||
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
|
||||
# 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
|
||||
|
||||
@property
|
||||
@ -321,10 +325,10 @@ class BlockStructure(object):
|
||||
for block in self.gf_struct_solver[ish]:
|
||||
block_sumk = self.solver_to_sumk_block[ish][block]
|
||||
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)),
|
||||
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]
|
||||
assert i_sumk[0] == block_sumk,\
|
||||
"Wrong block in solver_to_sumk"
|
||||
@ -343,7 +347,7 @@ class BlockStructure(object):
|
||||
Parameters
|
||||
----------
|
||||
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
|
||||
corr_to_inequiv : list
|
||||
@ -365,7 +369,7 @@ class BlockStructure(object):
|
||||
gss = []
|
||||
for block in gf_struct[ish]:
|
||||
so2sublock[block]=block
|
||||
for ind in gf_struct[ish][block]:
|
||||
for ind in range(gf_struct[ish][block]):
|
||||
so2su[(block,ind)]=(block,ind)
|
||||
gss.append((block,gf_struct[ish][block]))
|
||||
solver_to_sumk.append(so2su)
|
||||
@ -409,16 +413,14 @@ class BlockStructure(object):
|
||||
|
||||
[{'up':[0],'down':[1]}]
|
||||
|
||||
Note that the indices will be renamed to be a 0-based
|
||||
sequence of integers, i.e. the new structure will actually
|
||||
be [{'up':[0],'down':[0]}].
|
||||
Note that as of version 3.1.x, the new structure itself will
|
||||
actually be stored as [{'up':1,'down':1}].
|
||||
|
||||
For dropped indices, sumk_to_solver will map to (None,None).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
new_gf_struct : list of dict
|
||||
formatted the same as gf_struct_solver:
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
def adapt_deg_shells(self, gf_struct, ish=0):
|
||||
@ -468,7 +471,7 @@ class BlockStructure(object):
|
||||
if not key in gf_struct:
|
||||
del degsh[key]
|
||||
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]
|
||||
degsh[key][0] = \
|
||||
v[gf_struct[key], :][:, gf_struct[key]]
|
||||
@ -509,7 +512,6 @@ class BlockStructure(object):
|
||||
Parameters
|
||||
----------
|
||||
new_gf_struct : list of dict
|
||||
formatted the same as gf_struct_solver:
|
||||
|
||||
new_gf_struct[ish][block]=list of indices in that block.
|
||||
|
||||
@ -529,16 +531,16 @@ class BlockStructure(object):
|
||||
# one non-zero entry
|
||||
|
||||
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]:
|
||||
#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
|
||||
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]:
|
||||
T[:, index] = 0.0
|
||||
new_indices = []
|
||||
for index in indices:
|
||||
for index in range(block_dim):
|
||||
if np.any(np.abs(T[index, :]) > 1.e-15):
|
||||
new_indices.append(index)
|
||||
new_gf_struct_transformed[icrsh][block] = new_indices
|
||||
@ -558,6 +560,7 @@ class BlockStructure(object):
|
||||
gfs[icrsh][ind_sol[0]].append(ind_sol[1])
|
||||
self.pick_gf_struct_solver(gfs)
|
||||
|
||||
# TODO!
|
||||
def map_gf_struct_solver(self, mapping):
|
||||
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
|
||||
"""
|
||||
|
||||
def gf_function(indices):
|
||||
return np.zeros((len(indices), len(indices)), dtype=dtype)
|
||||
def gf_function(target_shape):
|
||||
return np.zeros(target_shape, dtype=dtype)
|
||||
|
||||
def block_function(name_list, block_list):
|
||||
d = dict()
|
||||
@ -683,7 +686,7 @@ class BlockStructure(object):
|
||||
names = list(gf_struct[ish].keys())
|
||||
blocks = []
|
||||
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)
|
||||
G = block_function(name_list=names, block_list=blocks)
|
||||
return G
|
||||
@ -766,7 +769,7 @@ class BlockStructure(object):
|
||||
for block, gf in G:
|
||||
assert block in gf_struct[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 + \
|
||||
" has wrong indices (shell {})".format(ish)
|
||||
else:
|
||||
@ -776,7 +779,7 @@ class BlockStructure(object):
|
||||
for block, gf in list(G.items()):
|
||||
assert block in gf_struct[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 + \
|
||||
" has wrong indices (shell {})".format(ish)
|
||||
|
||||
@ -936,8 +939,8 @@ class BlockStructure(object):
|
||||
block_mapping_from = G_struct.sumk_to_solver_block[ish_from]
|
||||
elif space_from == 'sumk':
|
||||
gf_struct_from = G_struct.gf_struct_sumk_dict[ish_from]
|
||||
eff_trans_from = {block: np.eye(len(indices))
|
||||
for block, indices in G_struct.gf_struct_sumk[ish_from]}
|
||||
eff_trans_from = {block: np.eye(block_dim)
|
||||
for block, block_dim in G_struct.gf_struct_sumk[ish_from]}
|
||||
block_mapping_from = {b: [b] for b in gf_struct_from}
|
||||
else:
|
||||
raise Exception(
|
||||
@ -949,8 +952,8 @@ class BlockStructure(object):
|
||||
block_mapping_to = self.solver_to_sumk_block[ish_to]
|
||||
elif space_to == 'sumk':
|
||||
gf_struct_to = self.gf_struct_sumk_dict[ish_to]
|
||||
eff_trans_to = {block: np.eye(len(indices))
|
||||
for block, indices in self.gf_struct_sumk_list[ish_to]}
|
||||
eff_trans_to = {block: np.eye(block_dim)
|
||||
for block, block_dim in self.gf_struct_sumk_list[ish_to]}
|
||||
block_mapping_to = {b: b for b in gf_struct_to}
|
||||
else:
|
||||
raise Exception(
|
||||
@ -1046,7 +1049,7 @@ class BlockStructure(object):
|
||||
self.solver_to_sumk_block.append({})
|
||||
for frm,to in list(self.sumk_to_solver[ish].items()):
|
||||
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.solver_to_sumk[ish][(frm[0]+'_'+str(frm[1]),0)]=frm
|
||||
self.solver_to_sumk_block[ish][frm[0]+'_'+str(frm[1])]=frm[0]
|
||||
|
Loading…
Reference in New Issue
Block a user