mirror of
https://github.com/triqs/dft_tools
synced 2024-11-18 03:53:48 +01:00
Merge pull request #208 from hschnait/new_gf_struct
Modify gf_struct to be in line with triqs/3.1.x
This commit is contained in:
commit
d6e04091b0
@ -22,6 +22,13 @@ DFTTools Version 3.1.0 is a release that
|
||||
* update documentation of W90 Converter
|
||||
* bugfix: This fix makes the function find_rot_mat() safer to use in case there are errors in finding the correct mapping. The converter will now abort if the agreement in mapping is below a user-definable threshold.
|
||||
|
||||
### Change in gf_struct
|
||||
* In line with TRIQS 3.1.x, the form of the Green's function's structure (`gf_struct`) has been modified (see [triqs changelog](https://triqs.github.io/triqs/latest/ChangeLog.html#change-in-gf-struct-objects) for more information)
|
||||
* Instead of `gf_struct = [("up", [0, 1]), ("down", [0, 1])]`, the new convention uses `gf_struct = [("up", 2), ("down", 2)]`
|
||||
* This modifies the form of `gf_struct_solver` (and `sumk`) in `block_structure` and `SumkDFT` as well.
|
||||
* Backwards-compatibility with old, stored `block_structure` objects is given, however a warning is issued.
|
||||
* A helper-function `triqs.gf.block_gf.fix_gf_struct_type(gf_struct_old)` is provided in triqs to manually bring `gf_struct`s to the new form.
|
||||
|
||||
### Documentation
|
||||
* change to read the docs sphinx theme
|
||||
* clean up various doc files
|
||||
|
@ -6,7 +6,6 @@ from triqs.gf import *
|
||||
import sys, triqs.version as triqs_version
|
||||
from triqs_dft_tools.sumk_dft import *
|
||||
from triqs_dft_tools.sumk_dft_tools import *
|
||||
from triqs_dft_tools.block_structure import gf_struct_flatten
|
||||
from triqs.operators.util.hamiltonians import *
|
||||
from triqs.operators.util.U_matrix import *
|
||||
from triqs_cthyb import *
|
||||
@ -41,7 +40,7 @@ spin_names = ['up','down']
|
||||
orb_names = [i for i in range(0,n_orb)]
|
||||
|
||||
#gf_struct = set_operator_structure(spin_names, orb_names, orb_hyb)
|
||||
gf_struct = gf_struct_flatten(SK.gf_struct_solver[0])
|
||||
gf_struct = SK.gf_struct_solver_list[0]
|
||||
mpi.report('Sumk to Solver: %s'%SK.sumk_to_solver)
|
||||
mpi.report('GF struct sumk: %s'%SK.gf_struct_sumk)
|
||||
mpi.report('GF struct solver: %s'%SK.gf_struct_solver)
|
||||
|
@ -6,7 +6,6 @@ from triqs.gf import *
|
||||
import sys, triqs.version as triqs_version
|
||||
from triqs_dft_tools.sumk_dft import *
|
||||
from triqs_dft_tools.sumk_dft_tools import *
|
||||
from triqs_dft_tools.block_structure import gf_struct_flatten
|
||||
from triqs.operators.util.hamiltonians import *
|
||||
from triqs.operators.util.U_matrix import *
|
||||
from triqs_cthyb import *
|
||||
@ -48,7 +47,7 @@ def dmft_cycle():
|
||||
orb_names = [i for i in range(0,n_orb)]
|
||||
|
||||
#gf_struct = set_operator_structure(spin_names, orb_names, orb_hyb)
|
||||
gf_struct = SK.gf_struct_solver[0]
|
||||
gf_struct = SK.gf_struct_solver_list[0]
|
||||
mpi.report('Sumk to Solver: %s'%SK.sumk_to_solver)
|
||||
mpi.report('GF struct sumk: %s'%SK.gf_struct_sumk)
|
||||
mpi.report('GF struct solver: %s'%SK.gf_struct_solver)
|
||||
|
@ -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
|
||||
@ -120,8 +120,27 @@ class BlockStructure(object):
|
||||
deg_shells=None,
|
||||
corr_to_inequiv = None,
|
||||
transformation=None):
|
||||
|
||||
# Ensure backwards-compatibility with pre-3.1.x gf_structs
|
||||
show_gf_struct_warning = False
|
||||
if gf_struct_sumk != None:
|
||||
for gf_struct in gf_struct_sumk:
|
||||
for i, block in enumerate(gf_struct):
|
||||
if isinstance(block[1], (list, np.ndarray)):
|
||||
gf_struct[i] = (block[0], len(block[1]))
|
||||
show_gf_struct_warning = True
|
||||
if gf_struct_solver != None:
|
||||
for gf_struct in gf_struct_solver:
|
||||
for block in gf_struct:
|
||||
if isinstance(gf_struct[block], (list, np.ndarray)):
|
||||
gf_struct[block] = len(gf_struct[block])
|
||||
show_gf_struct_warning = True
|
||||
if show_gf_struct_warning:
|
||||
warn('Old (pre 3.1.x) form of gf_struct provided! The structure will be updated to the new convention!')
|
||||
|
||||
self.gf_struct_sumk = gf_struct_sumk
|
||||
self.gf_struct_solver = gf_struct_solver
|
||||
|
||||
self.solver_to_sumk = solver_to_sumk
|
||||
self.sumk_to_solver = sumk_to_solver
|
||||
self.solver_to_sumk_block = solver_to_sumk_block
|
||||
@ -136,13 +155,13 @@ class BlockStructure(object):
|
||||
This is returned as a
|
||||
list (for each shell)
|
||||
of lists (for each block)
|
||||
of tuples (block_name, block_indices).
|
||||
of tuples (block_name, block_dimension).
|
||||
|
||||
That is,
|
||||
``gf_struct_solver_list[ish][b][0]``
|
||||
is the name of the block number ``b`` of shell ``ish``, and
|
||||
``gf_struct_solver_list[ish][b][1]``
|
||||
is a list of its indices.
|
||||
is the dimension of the block ``b``.
|
||||
|
||||
The list for each shell is sorted alphabetically by block name.
|
||||
"""
|
||||
@ -159,13 +178,13 @@ class BlockStructure(object):
|
||||
This is returned as a
|
||||
list (for each shell)
|
||||
of lists (for each block)
|
||||
of tuples (block_name, block_indices)
|
||||
of tuples (block_name, block_dimension)
|
||||
|
||||
That is,
|
||||
``gf_struct_sumk_list[ish][b][0]``
|
||||
is the name of the block number ``b`` of shell ``ish``, and
|
||||
``gf_struct_sumk_list[ish][b][1]``
|
||||
is a list of its indices.
|
||||
is the dimension of the block ``b``.
|
||||
"""
|
||||
return self.gf_struct_sumk
|
||||
|
||||
@ -179,7 +198,7 @@ class BlockStructure(object):
|
||||
|
||||
That is,
|
||||
``gf_struct_solver_dict[ish][bname]``
|
||||
is a list of the indices of block ``bname`` of shell ``ish``.
|
||||
is the dimension of block ``bname`` of shell ``ish``.
|
||||
"""
|
||||
return self.gf_struct_solver
|
||||
|
||||
@ -193,11 +212,11 @@ class BlockStructure(object):
|
||||
|
||||
That is,
|
||||
``gf_struct_sumk_dict[ish][bname]``
|
||||
is a list of the indices of block ``bname`` of shell ``ish``.
|
||||
is the dimension of block ``bname`` of shell ``ish``.
|
||||
"""
|
||||
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 +268,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 +280,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,13 +294,13 @@ 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:
|
||||
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
|
||||
return trans
|
||||
|
||||
@ -321,10 +340,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 +362,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 +384,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 +428,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 +471,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 +486,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 +527,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 +546,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
|
||||
@ -609,6 +626,11 @@ class BlockStructure(object):
|
||||
if not k in su2so:
|
||||
su2so[k] = (None, None)
|
||||
|
||||
for new_block in gf_struct:
|
||||
assert all(np.sort(gf_struct[new_block]) == list(range(len(gf_struct[new_block])))) ,\
|
||||
"New gf_struct does not have valid 0-based indices!"
|
||||
gf_struct[new_block] = len(gf_struct[new_block])
|
||||
|
||||
self.adapt_deg_shells(gf_struct, ish)
|
||||
|
||||
self.gf_struct_solver[ish] = gf_struct
|
||||
@ -660,8 +682,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 +705,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 +788,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 +798,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 +958,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 +971,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 +1068,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]
|
||||
@ -1168,45 +1190,5 @@ class BlockStructure(object):
|
||||
s += str(self.transformation)
|
||||
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
|
||||
register_class(BlockStructure)
|
||||
|
@ -138,10 +138,10 @@ class SumkDFT(object):
|
||||
# GF structure used for the local things in the k sums
|
||||
# Most general form allowing for all hybridisation, i.e. largest
|
||||
# blocks possible
|
||||
self.gf_struct_sumk = [[(sp, list(range(self.corr_shells[icrsh]['dim']))) for sp in self.spin_block_names[self.corr_shells[icrsh]['SO']]]
|
||||
self.gf_struct_sumk = [[(sp, self.corr_shells[icrsh]['dim']) for sp in self.spin_block_names[self.corr_shells[icrsh]['SO']]]
|
||||
for icrsh in range(self.n_corr_shells)]
|
||||
# First set a standard gf_struct solver:
|
||||
self.gf_struct_solver = [dict([(sp, list(range(self.corr_shells[self.inequiv_to_corr[ish]]['dim'])))
|
||||
self.gf_struct_solver = [dict([(sp, self.corr_shells[self.inequiv_to_corr[ish]]['dim'])
|
||||
for sp in self.spin_block_names[self.corr_shells[self.inequiv_to_corr[ish]]['SO']]])
|
||||
for ish in range(self.n_inequiv_shells)]
|
||||
# Set standard (identity) maps from gf_struct_sumk <->
|
||||
@ -151,9 +151,9 @@ class SumkDFT(object):
|
||||
self.solver_to_sumk_block = [{}
|
||||
for ish in range(self.n_inequiv_shells)]
|
||||
for ish in range(self.n_inequiv_shells):
|
||||
for block, inner_list in self.gf_struct_sumk[self.inequiv_to_corr[ish]]:
|
||||
for block, inner_dim in self.gf_struct_sumk[self.inequiv_to_corr[ish]]:
|
||||
self.solver_to_sumk_block[ish][block] = block
|
||||
for inner in inner_list:
|
||||
for inner in range(inner_dim):
|
||||
self.sumk_to_solver[ish][
|
||||
(block, inner)] = (block, inner)
|
||||
self.solver_to_sumk[ish][
|
||||
@ -743,13 +743,13 @@ class SumkDFT(object):
|
||||
G_loc = [self.Sigma_imp_iw[icrsh].copy() for icrsh in range(
|
||||
self.n_corr_shells)] # this list will be returned
|
||||
beta = G_loc[0].mesh.beta
|
||||
G_loc_inequiv = [BlockGf(name_block_generator=[(block, GfImFreq(indices=inner, mesh=G_loc[0].mesh)) for block, inner in self.gf_struct_solver[ish].items()],
|
||||
G_loc_inequiv = [BlockGf(name_block_generator=[(block, GfImFreq(target_shape=(block_dim, block_dim), mesh=G_loc[0].mesh)) for block, block_dim in self.gf_struct_solver[ish].items()],
|
||||
make_copies=False) for ish in range(self.n_inequiv_shells)]
|
||||
elif iw_or_w == "w":
|
||||
G_loc = [self.Sigma_imp_w[icrsh].copy() for icrsh in range(
|
||||
self.n_corr_shells)] # this list will be returned
|
||||
mesh = G_loc[0].mesh
|
||||
G_loc_inequiv = [BlockGf(name_block_generator=[(block, GfReFreq(indices=inner, mesh=mesh)) for block, inner in self.gf_struct_solver[ish].items()],
|
||||
G_loc_inequiv = [BlockGf(name_block_generator=[(block, GfReFreq(target_shape=(block_dim, block_dim), mesh=mesh)) for block, block_dim in self.gf_struct_solver[ish].items()],
|
||||
make_copies=False) for ish in range(self.n_inequiv_shells)]
|
||||
|
||||
for icrsh in range(self.n_corr_shells):
|
||||
@ -911,7 +911,7 @@ class SumkDFT(object):
|
||||
for i in range(num_blocs):
|
||||
blocs[i].sort()
|
||||
self.gf_struct_solver[ish].update(
|
||||
[('%s_%s' % (sp, i), list(range(len(blocs[i]))))])
|
||||
[('%s_%s' % (sp, i), len(blocs[i]))])
|
||||
|
||||
# Construct sumk_to_solver taking (sumk_block, sumk_index) --> (solver_block, solver_inner)
|
||||
# and solver_to_sumk taking (solver_block, solver_inner) -->
|
||||
@ -930,12 +930,12 @@ class SumkDFT(object):
|
||||
|
||||
# Now calculate degeneracies of orbitals
|
||||
dm = {}
|
||||
for block, inner in self.gf_struct_solver[ish].items():
|
||||
for block, block_dim in self.gf_struct_solver[ish].items():
|
||||
# get dm for the blocks:
|
||||
dm[block] = numpy.zeros(
|
||||
[len(inner), len(inner)], numpy.complex_)
|
||||
for ind1 in inner:
|
||||
for ind2 in inner:
|
||||
[block_dim, block_dim], numpy.complex_)
|
||||
for ind1 in range(block_dim):
|
||||
for ind2 in range(block_dim):
|
||||
block_sumk, ind1_sumk = self.solver_to_sumk[
|
||||
ish][(block, ind1)]
|
||||
block_sumk, ind2_sumk = self.solver_to_sumk[
|
||||
@ -1100,7 +1100,7 @@ class SumkDFT(object):
|
||||
for i in range(num_blocs):
|
||||
blocs[i].sort()
|
||||
self.gf_struct_solver[ish].update(
|
||||
[('%s_%s' % (sp, i), list(range(len(blocs[i]))))])
|
||||
[('%s_%s' % (sp, i), len(blocs[i]))])
|
||||
|
||||
# Construct sumk_to_solver taking (sumk_block, sumk_index) --> (solver_block, solver_inner)
|
||||
# and solver_to_sumk taking (solver_block, solver_inner) -->
|
||||
@ -1119,7 +1119,7 @@ class SumkDFT(object):
|
||||
|
||||
# transform G to the new structure
|
||||
full_structure = BlockStructure.full_structure(
|
||||
[{sp:list(range(self.corr_shells[self.inequiv_to_corr[ish]]['dim']))
|
||||
[{sp:self.corr_shells[self.inequiv_to_corr[ish]]['dim']
|
||||
for sp in self.spin_block_names[self.corr_shells[self.inequiv_to_corr[ish]]['SO']]}
|
||||
for ish in range(self.n_inequiv_shells)],self.corr_to_inequiv)
|
||||
G_transformed = [
|
||||
@ -1420,7 +1420,7 @@ class SumkDFT(object):
|
||||
"calculate_diagonalization_matrix: Choices for prop_to_be_diagonal are 'eal' or 'dm'.")
|
||||
return 0
|
||||
|
||||
trans = [{block: numpy.eye(len(indices)) for block, indices in gfs} for gfs in self.gf_struct_sumk]
|
||||
trans = [{block: numpy.eye(block_dim) for block, block_dim in gfs} for gfs in self.gf_struct_sumk]
|
||||
|
||||
for ish in shells:
|
||||
trafo = {}
|
||||
|
@ -97,8 +97,8 @@ class SumkDFTTools(SumkDFT):
|
||||
G_loc = []
|
||||
for icrsh in range(self.n_corr_shells):
|
||||
spn = self.spin_block_names[self.corr_shells[icrsh]['SO']]
|
||||
glist = [GfReFreq(indices=inner, window=(om_min, om_max), n_points=n_om)
|
||||
for block, inner in self.gf_struct_sumk[icrsh]]
|
||||
glist = [GfReFreq(target_shape=(block_dim, block_dim), window=(om_min, om_max), n_points=n_om)
|
||||
for block, block_dim in self.gf_struct_sumk[icrsh]]
|
||||
G_loc.append(
|
||||
BlockGf(name_list=spn, block_list=glist, make_copies=False))
|
||||
for icrsh in range(self.n_corr_shells):
|
||||
@ -236,8 +236,8 @@ class SumkDFTTools(SumkDFT):
|
||||
n_local_orbs = self.proj_mat_csc.shape[2]
|
||||
gf_struct_parproj_all = [[(sp, list(range(n_local_orbs))) for sp in spn]]
|
||||
|
||||
glist_all = [GfReFreq(indices=inner, window=(om_min, om_max), n_points=n_om)
|
||||
for block, inner in gf_struct_parproj_all[0]]
|
||||
glist_all = [GfReFreq(target_shape=(block_dim, block_dim), window=(om_min, om_max), n_points=n_om)
|
||||
for block, block_dim in gf_struct_parproj_all[0]]
|
||||
G_loc_all = BlockGf(name_list=spn, block_list=glist_all, make_copies=False)
|
||||
|
||||
DOS = {sp: numpy.zeros([n_om], numpy.float_)
|
||||
@ -364,11 +364,11 @@ class SumkDFTTools(SumkDFT):
|
||||
|
||||
G_loc = []
|
||||
spn = self.spin_block_names[self.SO]
|
||||
gf_struct_parproj = [[(sp, list(range(self.shells[ish]['dim']))) for sp in spn]
|
||||
gf_struct_parproj = [[(sp, self.shells[ish]['dim']) for sp in spn]
|
||||
for ish in range(self.n_shells)]
|
||||
for ish in range(self.n_shells):
|
||||
glist = [GfReFreq(indices=inner, window=(om_min, om_max), n_points=n_om)
|
||||
for block, inner in gf_struct_parproj[ish]]
|
||||
glist = [GfReFreq(target_shape=(block_dim, block_dim), window=(om_min, om_max), n_points=n_om)
|
||||
for block, block_dim in gf_struct_parproj[ish]]
|
||||
G_loc.append(
|
||||
BlockGf(name_list=spn, block_list=glist, make_copies=False))
|
||||
for ish in range(self.n_shells):
|
||||
@ -873,9 +873,9 @@ class SumkDFTTools(SumkDFT):
|
||||
|
||||
if not ishell is None:
|
||||
gf_struct_parproj = [
|
||||
(sp, list(range(self.shells[ishell]['dim']))) for sp in spn]
|
||||
G_loc = BlockGf(name_block_generator=[(block, GfReFreq(indices=inner, mesh=self.Sigma_imp_w[0].mesh))
|
||||
for block, inner in gf_struct_parproj], make_copies=False)
|
||||
(sp, self.shells[ishell]['dim']) for sp in spn]
|
||||
G_loc = BlockGf(name_block_generator=[(block, GfReFreq(target_shape=(block_dim, block_dim), mesh=self.Sigma_imp_w[0].mesh))
|
||||
for block, block_dim in gf_struct_parproj], make_copies=False)
|
||||
G_loc.zero()
|
||||
|
||||
ikarray = numpy.array(list(range(self.n_k)))
|
||||
@ -993,16 +993,16 @@ class SumkDFTTools(SumkDFT):
|
||||
for ish in range(self.n_shells)]
|
||||
for isp in range(len(spn))]
|
||||
# Set up G_loc
|
||||
gf_struct_parproj = [[(sp, list(range(self.shells[ish]['dim']))) for sp in spn]
|
||||
gf_struct_parproj = [[(sp, self.shells[ish]['dim']) for sp in spn]
|
||||
for ish in range(self.n_shells)]
|
||||
if with_Sigma:
|
||||
G_loc = [BlockGf(name_block_generator=[(block, GfImFreq(indices=inner, mesh=self.Sigma_imp_iw[0].mesh))
|
||||
for block, inner in gf_struct_parproj[ish]], make_copies=False)
|
||||
G_loc = [BlockGf(name_block_generator=[(block, GfImFreq(target_shape=(block_dim, block_dim), mesh=self.Sigma_imp_iw[0].mesh))
|
||||
for block, block_dim in gf_struct_parproj[ish]], make_copies=False)
|
||||
for ish in range(self.n_shells)]
|
||||
beta = self.Sigma_imp_iw[0].mesh.beta
|
||||
else:
|
||||
G_loc = [BlockGf(name_block_generator=[(block, GfImFreq(indices=inner, beta=beta))
|
||||
for block, inner in gf_struct_parproj[ish]], make_copies=False)
|
||||
G_loc = [BlockGf(name_block_generator=[(block, GfImFreq(target_shape=(block_dim, block_dim), beta=beta))
|
||||
for block, block_dim in gf_struct_parproj[ish]], make_copies=False)
|
||||
for ish in range(self.n_shells)]
|
||||
for ish in range(self.n_shells):
|
||||
G_loc[ish].zero()
|
||||
@ -1227,8 +1227,8 @@ class SumkDFTTools(SumkDFT):
|
||||
for icrsh in range(self.n_corr_shells):
|
||||
Sigma_save = self.Sigma_imp_w[icrsh].copy()
|
||||
spn = self.spin_block_names[self.corr_shells[icrsh]['SO']]
|
||||
glist = lambda: [GfReFreq(indices=inner, window=(self.omega[
|
||||
0], self.omega[-1]), n_points=n_om) for block, inner in self.gf_struct_sumk[icrsh]]
|
||||
glist = lambda: [GfReFreq(target_shape=(block_dim, block_dim), window=(self.omega[
|
||||
0], self.omega[-1]), n_points=n_om) for block, block_dim in self.gf_struct_sumk[icrsh]]
|
||||
self.Sigma_imp_w[icrsh] = BlockGf(
|
||||
name_list=spn, block_list=glist(), make_copies=False)
|
||||
for i, g in self.Sigma_imp_w[icrsh]:
|
||||
|
@ -150,14 +150,14 @@ class TransBasis:
|
||||
|
||||
# build a full GF
|
||||
gfrotated = BlockGf(name_block_generator=[(block, GfImFreq(
|
||||
indices=inner, mesh=gf_to_rot.mesh)) for block, inner in self.SK.gf_struct_sumk[0]], make_copies=False)
|
||||
target_shape=(block_dim, block_dim), mesh=gf_to_rot.mesh)) for block, block_dim in self.SK.gf_struct_sumk[0]], make_copies=False)
|
||||
|
||||
# transform the CTQMC blocks to the full matrix:
|
||||
# ish is the index of the inequivalent shell corresponding to icrsh
|
||||
ish = self.SK.corr_to_inequiv[0]
|
||||
for block, inner in self.gf_struct_solver[ish].items():
|
||||
for ind1 in inner:
|
||||
for ind2 in inner:
|
||||
for block, block_dim in self.gf_struct_solver[ish].items():
|
||||
for ind1 in range(block_dim):
|
||||
for ind2 in range(block_dim):
|
||||
gfrotated[self.SK.solver_to_sumk_block[ish][block]][
|
||||
ind1, ind2] << gf_to_rot[block][ind1, ind2]
|
||||
|
||||
@ -168,9 +168,9 @@ class TransBasis:
|
||||
|
||||
gfreturn = gf_to_rot.copy()
|
||||
# Put back into CTQMC basis:
|
||||
for block, inner in self.gf_struct_solver[ish].items():
|
||||
for ind1 in inner:
|
||||
for ind2 in inner:
|
||||
for block, block_dim in self.gf_struct_solver[ish].items():
|
||||
for ind1 in range(block_dim):
|
||||
for ind2 in range(block_dim):
|
||||
gfreturn[block][ind1, ind2] << gfrotated[
|
||||
self.SK.solver_to_sumk_block[0][block]][ind1, ind2]
|
||||
|
||||
|
@ -54,11 +54,11 @@ SK.symm_deg_gf(G_new_symm, 0)
|
||||
assert_block_gfs_are_close(G_new[0], G_new_symm)
|
||||
|
||||
|
||||
assert SK.gf_struct_sumk == [[('ud', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])], [('ud', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])]],\
|
||||
assert SK.gf_struct_sumk == [[('ud', 10)], [('ud', 10)]],\
|
||||
"wrong gf_struct_sumk"
|
||||
for i in range(5):
|
||||
assert 'ud_{}'.format(i) in SK.gf_struct_solver[0], "missing block"
|
||||
assert SK.gf_struct_solver[0]['ud_{}'.format(i)] == list(range(2)), "wrong block size"
|
||||
assert SK.gf_struct_solver[0]['ud_{}'.format(i)] == 2, "wrong block size"
|
||||
for i in range(10):
|
||||
assert SK.sumk_to_solver[0]['ud',i] == ('ud_{}'.format(i//2), i%2), "wrong mapping"
|
||||
|
||||
@ -98,11 +98,11 @@ G_new_symm = G_new[0].copy()
|
||||
SK.symm_deg_gf(G_new_symm, 0)
|
||||
assert_block_gfs_are_close(G_new[0], G_new_symm)
|
||||
|
||||
assert SK.gf_struct_sumk == [[('ud', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])], [('ud', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])]],\
|
||||
assert SK.gf_struct_sumk == [[('ud', 10)], [('ud', 10)]],\
|
||||
"wrong gf_struct_sumk"
|
||||
for i in range(5):
|
||||
assert 'ud_{}'.format(i) in SK.gf_struct_solver[0], "missing block"
|
||||
assert SK.gf_struct_solver[0]['ud_{}'.format(i)] == list(range(2)), "wrong block size"
|
||||
assert SK.gf_struct_solver[0]['ud_{}'.format(i)] == 2, "wrong block size"
|
||||
for i in range(10):
|
||||
assert SK.sumk_to_solver[0]['ud',i] == ('ud_{}'.format(i//2), i%2), "wrong mapping"
|
||||
|
||||
|
@ -92,7 +92,7 @@ BS.transformation = [{'up':np.array([[1,0,0],[0,1/np.sqrt(2),1/np.sqrt(2)],[0,1/
|
||||
H3 = BS.convert_operator(h_int_slater(spin_names=['up','down'], orb_names=[0,1,2], U_matrix=U3x3, off_diag=True))
|
||||
for op in H3:
|
||||
for c_op in op[0]:
|
||||
assert(BS.gf_struct_solver_dict[0][c_op[1][0]][c_op[1][1]] is not None) # This crashes with a key error if the operator structure is not the solver structure
|
||||
assert(BS.solver_to_sumk[0][(c_op[1][0], c_op[1][1])] is not None) # This crashes with a key error if the operator structure is not the solver structure
|
||||
|
||||
U_trafod = transform_U_matrix(U3x3, BS.transformation[0]['up'].conjugate()) # The notorious .conjugate()
|
||||
H4 = h_int_slater(spin_names=['up','down'], orb_names=range(3), U_matrix=U_trafod, map_operator_structure=BS.sumk_to_solver[0])
|
||||
|
@ -3,7 +3,7 @@ from triqs.utility.h5diff import h5diff, compare, failures
|
||||
from triqs.gf import *
|
||||
from triqs.utility.comparison_tests import assert_block_gfs_are_close
|
||||
from scipy.linalg import expm
|
||||
from triqs_dft_tools.block_structure import BlockStructure, gf_struct_flatten
|
||||
from triqs_dft_tools.block_structure import BlockStructure
|
||||
import numpy as np
|
||||
|
||||
|
||||
@ -174,11 +174,9 @@ cmp(m2,
|
||||
|
||||
# check full_structure
|
||||
full = BlockStructure.full_structure(
|
||||
[{'up_0': [0, 1], 'up_1': [0], 'down_1': [0], 'down_0': [0, 1]}], None)
|
||||
[{'up_0': 2, 'up_1': 1, 'down_1': 1, 'down_0': 2}], None)
|
||||
|
||||
print(original_bs.gf_struct_sumk[0])
|
||||
print(gf_struct_flatten(original_bs.gf_struct_sumk[0]))
|
||||
G_sumk = BlockGf(mesh=G1.mesh, gf_struct=gf_struct_flatten(original_bs.gf_struct_sumk[0]))
|
||||
G_sumk = BlockGf(mesh=G1.mesh, gf_struct=original_bs.gf_struct_sumk[0])
|
||||
for i in range(3):
|
||||
G_sumk['up'][i, i] << SemiCircular(1 if i < 2 else 2)
|
||||
G_sumk['down'][i, i] << SemiCircular(4 if i < 2 else 3)
|
||||
@ -204,13 +202,13 @@ G_bT = transformed_bs.convert_gf(G_T, None, space_from='sumk',
|
||||
assert_block_gfs_are_close(G1, G_bT)
|
||||
|
||||
assert original_bs.gf_struct_sumk_list ==\
|
||||
[[('up', [0, 1, 2]), ('down', [0, 1, 2])]]
|
||||
[[('up', 3), ('down', 3)]]
|
||||
assert original_bs.gf_struct_solver_dict ==\
|
||||
[{'up_0': [0, 1], 'up_1': [0], 'down_1': [0], 'down_0': [0, 1]}]
|
||||
[{'up_0': 2, 'up_1': 1, 'down_1': 1, 'down_0': 2}]
|
||||
assert original_bs.gf_struct_sumk_dict ==\
|
||||
[{'down': [0, 1, 2], 'up': [0, 1, 2]}]
|
||||
[{'down': 3, 'up': 3}]
|
||||
assert original_bs.gf_struct_solver_list ==\
|
||||
[[('down_0', [0, 1]), ('down_1', [0]), ('up_0', [0, 1]), ('up_1', [0])]]
|
||||
[[('down_0', 2), ('down_1', 1), ('up_0', 2), ('up_1', 1)]]
|
||||
|
||||
# check __eq__
|
||||
assert full == full, 'equality not correct (equal structures not equal)'
|
||||
|
Loading…
Reference in New Issue
Block a user