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] 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() 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
for e in eal: assert is_diagonal_matrix(np.dot(np.dot(t_solver_eal[0][e], eal[e].conj().T),t_solver_eal[0][e].conj().T)) dm = SK.density_matrix(method='using_point_integration') for dmi in dm: for e in dmi: assert is_diagonal_matrix(np.dot(np.dot(t_solver_dm[0][e], dmi[e].conj().T),t_solver_dm[0][e].conj().T)) # Test convert_operator SK = SumkDFT(hdf_file = 'SrVO3.ref.h5', use_dft_blocks=True) BS = SK.block_structure from triqs.operators.util import h_int_slater, U_matrix, t2g_submatrix, transform_U_matrix U3x3 = t2g_submatrix(U_matrix(2, U_int=2, J_hund=0.2, basis='spheric')) BS.transformation = [{'up':np.eye(3), 'down': np.eye(3)}] H0 = h_int_slater(spin_names=['up','down'], orb_names=range(3), U_matrix=U3x3, off_diag=False) H1 = h_int_slater(spin_names=['up','down'], orb_names=range(3), U_matrix=U3x3, off_diag=True) assert( H0 == BS.convert_operator(H1) ) # Trafo Matrix switching index 1 & 2 BS.transformation = [{'up':np.array([[1,0,0],[0,0,1],[0,1,0]]), 'down': np.array([[1,0,0],[0,0,1],[0,1,0]])}] H2 = BS.convert_operator(h_int_slater(spin_names=['up','down'], orb_names=[0,2,1], U_matrix=U3x3, off_diag=True)) assert( H0 == H2 ) BS.transformation = [{'up':np.array([[1,0,0],[0,1/np.sqrt(2),1/np.sqrt(2)],[0,1/np.sqrt(2),-1/np.sqrt(2)]]), 'down': np.array([[1,0,0],[0,1/np.sqrt(2),1/np.sqrt(2)],[0,1/np.sqrt(2),-1/np.sqrt(2)]])}] 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]:
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 Sigma = SK.block_structure.create_gf(beta=beta) SK.put_Sigma([Sigma]) G = SK.extract_G_loc() SK.analyse_block_structure_from_gf(G, threshold = 1e-2) for i_sh in range(len(SK.deg_shells)): num_block_deg_orbs = len(SK.deg_shells[i_sh]) mpi.report('found {0:d} blocks of degenerate orbitals in shell {1:d}'.format(num_block_deg_orbs, i_sh)) for iblock in range(num_block_deg_orbs): 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] 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() 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 p["random_name"] = "" p["random_seed"] = 123 * mpi.rank + 567 p["length_cycle"] = 100 p["n_warmup_cycles"] = 2000 p["n_cycles"] = 20000 p["fit_max_moment"] = 4 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') if not 'DMFT_results' in ar: ar.create_group('DMFT_results') if not 'Iterations' in ar['DMFT_results']: ar['DMFT_results'].create_group('Iterations') if not 'DMFT_input' in ar: ar.create_group('DMFT_input') if not 'Iterations' in ar['DMFT_input']: ar['DMFT_input'].create_group('Iterations') if not 'code_versions' in ar['DMFT_input']: ar['DMFT_input'].create_group('code_versio\ ns') ar['DMFT_input']['code_versions']["triqs_version"] = triqs_version.version ar['DMFT_input']['code_versions']["triqs_git"] = triqs_version.git_hash ar['DMFT_input']['code_versions']["cthyb_version"] = cthyb_version.version ar['DMFT_input']['code_versions']["cthyb_git"] = cthyb_version.triqs_cthyb_hash ar['DMFT_input']['code_versions']["dft_tools_version"] = dft_tools_version.version ar['DMFT_input']['code_versions']["dft_tools_git"] = dft_tools_version.triqs_dft_tools_hash if 'iteration_count' in ar['DMFT_results']: iteration_offset = ar['DMFT_results']['iteration_count']+1 S.Sigma_iw = ar['DMFT_results']['Iterations']['Sigma_it'+str(iteration_offset-1)] SK.dc_imp = ar['DMFT_results']['Iterations']['dc_imp'+str(iteration_offset-1)] SK.dc_energ = ar['DMFT_results']['Iterations']['dc_energ'+str(iteration_offset-1)] SK.chemical_potential = ar['DMFT_results']['Iterations']['chemical_potential'+str(iteration_offset-1)].real ar['DMFT_input']["dmft_script_it"+str(iteration_offset)] = open(sys.argv[0]).read() iteration_offset = mpi.bcast(iteration_offset) S.Sigma_iw = mpi.bcast(S.Sigma_iw) 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(): 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 ar['DMFT_results']['Iterations']['Sigma_uns_it'+str(it)] = S.Sigma_iw # Calculate double counting 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) # Get new G 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] # 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(): 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(): 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