Skip to content

Commit

Permalink
Merge pull request #208 from hschnait/new_gf_struct
Browse files Browse the repository at this point in the history
Modify gf_struct to be in line with triqs/3.1.x
  • Loading branch information
the-hampel authored Mar 9, 2022
2 parents 9bac476 + 320b2d2 commit d6e0409
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 186 deletions.
7 changes: 7 additions & 0 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions doc/tutorials/images_scripts/nio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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 *
Expand All @@ -20,8 +19,8 @@

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()
Expand All @@ -41,15 +40,15 @@
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)

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

Expand Down Expand Up @@ -130,14 +129,14 @@

# 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
Expand All @@ -150,13 +149,13 @@
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
Expand Down
87 changes: 43 additions & 44 deletions doc/tutorials/images_scripts/nio_csc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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 *
Expand All @@ -21,14 +20,14 @@

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()
Expand All @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -158,45 +157,45 @@ 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
ar['DMFT_results']['Iterations']['G0loc_it'+str(it)] = S.G0_iw
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
Loading

0 comments on commit d6e0409

Please sign in to comment.