3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-22 12:23:41 +01:00

remove gf_struct_flatten function and replace with triqs version

This commit is contained in:
Alexander Hampel 2022-03-09 09:15:10 -05:00
parent d28fe3c1ef
commit 320b2d2dfd
5 changed files with 57 additions and 99 deletions

View File

@ -23,11 +23,11 @@ DFTTools Version 3.1.0 is a release that
* 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
* 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 `block_structure.gf_struct_flatten(...)` is provided to manually bring `gf_struct`s to the new form.
* 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

View File

@ -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 *
@ -20,8 +19,8 @@ filename = 'nio'
SK = SumkDFT(hdf_file = filename+'.h5', use_dft_blocks = False)
beta = 5.0
beta = 5.0
Sigma = SK.block_structure.create_gf(beta=beta)
SK.put_Sigma([Sigma])
G = SK.extract_G_loc()
@ -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)
@ -49,7 +48,7 @@ mpi.report('GF struct solver: %s'%SK.gf_struct_solver)
S = Solver(beta=beta, gf_struct=gf_struct)
# Construct the Hamiltonian and save it in Hamiltonian_store.txt
H = Operator()
H = Operator()
U = 8.0
J = 1.0
@ -130,14 +129,14 @@ mpi.report('%s DMFT cycles requested. Starting with iteration %s.'%(n_iterations
# The infamous DMFT self consistency cycle
for it in range(iteration_offset, iteration_offset + n_iterations):
mpi.report('Doing iteration: %s'%it)
# Get G0
S.G0_iw << inverse(S.Sigma_iw + inverse(S.G_iw))
# Solve the impurity problem
S.solve(h_int = H, **p)
if mpi.is_master_node():
if mpi.is_master_node():
ar['DMFT_input']['Iterations']['solver_dict_it'+str(it)] = p
ar['DMFT_results']['Iterations']['Gimp_it'+str(it)] = S.G_iw
ar['DMFT_results']['Iterations']['Gtau_it'+str(it)] = S.G_tau
@ -150,13 +149,13 @@ for it in range(iteration_offset, iteration_offset + n_iterations):
SK.put_Sigma(Sigma_imp=[S.Sigma_iw])
SK.calc_mu(precision=0.01)
S.G_iw << SK.extract_G_loc()[0]
# print densities
for sig,gf in S.G_iw:
mpi.report("Orbital %s density: %.6f"%(sig,dm[sig][0,0]))
mpi.report('Total charge of Gloc : %.6f'%S.G_iw.total_density())
if mpi.is_master_node():
if mpi.is_master_node():
ar['DMFT_results']['iteration_count'] = it
ar['DMFT_results']['Iterations']['Sigma_it'+str(it)] = S.Sigma_iw
ar['DMFT_results']['Iterations']['Gloc_it'+str(it)] = S.G_iw

View File

@ -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 *
@ -21,14 +20,14 @@ warnings.filterwarnings("ignore", category=FutureWarning)
def dmft_cycle():
filename = 'nio'
Converter = VaspConverter(filename=filename)
Converter.convert_dft_input()
SK = SumkDFT(hdf_file = filename+'.h5', use_dft_blocks = False)
beta = 5.0
beta = 5.0
Sigma = SK.block_structure.create_gf(beta=beta)
SK.put_Sigma([Sigma])
G = SK.extract_G_loc()
@ -40,38 +39,38 @@ def dmft_cycle():
mpi.report('block {0:d} consists of orbitals:'.format(iblock))
for keys in list(SK.deg_shells[i_sh][iblock].keys()):
mpi.report(' '+keys)
# Setup CTQMC Solver
n_orb = SK.corr_shells[0]['dim']
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 = 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)
S = Solver(beta=beta, gf_struct=gf_struct)
# Construct the Hamiltonian and save it in Hamiltonian_store.txt
H = Operator()
H = Operator()
U = 8.0
J = 1.0
U_sph = U_matrix(l=2, U_int=U, J_hund=J)
U_cubic = transform_U_matrix(U_sph, spherical_to_cubic(l=2, convention=''))
Umat, Upmat = reduce_4index_to_2index(U_cubic)
H = h_int_density(spin_names, orb_names, map_operator_structure=SK.sumk_to_solver[0], U=Umat, Uprime=Upmat)
# Print some information on the master node
mpi.report('Greens function structure is: %s '%gf_struct)
mpi.report('U Matrix set to:\n%s'%Umat)
mpi.report('Up Matrix set to:\n%s'%Upmat)
# Parameters for the CTQMC Solver
p = {}
p["max_time"] = -1
@ -84,14 +83,14 @@ def dmft_cycle():
p["fit_min_n"] = 30
p["fit_max_n"] = 50
p["perform_tail_fit"] = True
# Double Counting: 0 FLL, 1 Held, 2 AMF
DC_type = 0
DC_value = 59.0
# Prepare hdf file and and check for previous iterations
n_iterations = 1
iteration_offset = 0
if mpi.is_master_node():
ar = HDFArchive(filename+'.h5','a')
@ -119,33 +118,33 @@ def dmft_cycle():
SK.dc_imp = mpi.bcast(SK.dc_imp)
SK.dc_energ = mpi.bcast(SK.dc_energ)
SK.chemical_potential = mpi.bcast(SK.chemical_potential)
# Calc the first G0
SK.symm_deg_gf(S.Sigma_iw, ish=0)
SK.put_Sigma(Sigma_imp = [S.Sigma_iw])
SK.calc_mu(precision=0.01)
S.G_iw << SK.extract_G_loc()[0]
SK.symm_deg_gf(S.G_iw, ish=0)
#Init the DC term and the self-energy if no previous iteration was found
if iteration_offset == 0:
dm = S.G_iw.density()
SK.calc_dc(dm, U_interact=U, J_hund=J, orb=0, use_dc_formula=DC_type,use_dc_value=DC_value)
S.Sigma_iw << SK.dc_imp[0]['up'][0,0]
mpi.report('%s DMFT cycles requested. Starting with iteration %s.'%(n_iterations,iteration_offset))
# The infamous DMFT self consistency cycle
for it in range(iteration_offset, iteration_offset + n_iterations):
mpi.report('Doing iteration: %s'%it)
# Get G0
S.G0_iw << inverse(S.Sigma_iw + inverse(S.G_iw))
# Solve the impurity problem
S.solve(h_int = H, **p)
if mpi.is_master_node():
if mpi.is_master_node():
ar['DMFT_input']['Iterations']['solver_dict_it'+str(it)] = p
ar['DMFT_results']['Iterations']['Gimp_it'+str(it)] = S.G_iw
ar['DMFT_results']['Iterations']['Gtau_it'+str(it)] = S.G_tau
@ -158,13 +157,13 @@ def dmft_cycle():
SK.put_Sigma(Sigma_imp=[S.Sigma_iw])
SK.calc_mu(precision=0.01)
S.G_iw << SK.extract_G_loc()[0]
# print densities
for sig,gf in S.G_iw:
mpi.report("Orbital %s density: %.6f"%(sig,dm[sig][0,0]))
mpi.report('Total charge of Gloc : %.6f'%S.G_iw.total_density())
if mpi.is_master_node():
if mpi.is_master_node():
ar['DMFT_results']['iteration_count'] = it
ar['DMFT_results']['Iterations']['Sigma_it'+str(it)] = S.Sigma_iw
ar['DMFT_results']['Iterations']['Gloc_it'+str(it)] = S.G_iw
@ -172,31 +171,31 @@ def dmft_cycle():
ar['DMFT_results']['Iterations']['dc_imp'+str(it)] = SK.dc_imp
ar['DMFT_results']['Iterations']['dc_energ'+str(it)] = SK.dc_energ
ar['DMFT_results']['Iterations']['chemical_potential'+str(it)] = SK.chemical_potential
if mpi.is_master_node():
print('calculating mu...')
SK.chemical_potential = SK.calc_mu( precision = 0.000001 )
if mpi.is_master_node():
print('calculating GAMMA')
SK.calc_density_correction(dm_type='vasp')
if mpi.is_master_node():
print('calculating energy corrections')
correnerg = 0.5 * (S.G_iw * S.Sigma_iw).total_density()
dm = S.G_iw.density() # compute the density matrix of the impurity problem
SK.calc_dc(dm, U_interact=U, J_hund=J, orb=0, use_dc_formula=DC_type,use_dc_value=DC_value)
dc_energ = SK.dc_energ[0]
if mpi.is_master_node():
if mpi.is_master_node():
ar['DMFT_results']['Iterations']['corr_energy_it'+str(it)] = correnerg
ar['DMFT_results']['Iterations']['dc_energy_it'+str(it)] = dc_energ
if mpi.is_master_node(): del ar
return correnerg, dc_energ

View File

@ -120,7 +120,7 @@ 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:
@ -625,7 +625,7 @@ class BlockStructure(object):
for k in list(self.sumk_to_solver[ish].keys()):
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!"
@ -1190,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)

View File

@ -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