From a36f2fdc61d7a77b1264a0482bea303292a57b9d Mon Sep 17 00:00:00 2001 From: Alexander Hampel Date: Wed, 15 Dec 2021 09:01:10 -0500 Subject: [PATCH] fix spaghettis function and update test --- python/triqs_dft_tools/sumk_dft.py | 10 +++++----- python/triqs_dft_tools/sumk_dft_tools.py | 9 +++++---- test/python/srvo3_spectral.py | 24 ++++++++++-------------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/python/triqs_dft_tools/sumk_dft.py b/python/triqs_dft_tools/sumk_dft.py index 2b2890f1..72d8cd17 100644 --- a/python/triqs_dft_tools/sumk_dft.py +++ b/python/triqs_dft_tools/sumk_dft.py @@ -59,9 +59,9 @@ class SumkDFT(object): It cannot be used with the spin-orbit coupling on; namely h_field is set to 0 if self.SO=True. mesh: MeshImFreq or MeshImFreq, optional. Frequency mesh of Sigma. beta : real, optional - Inverse temperature. Used to construct imaginary frequency if mesh is not given. + Inverse temperature. Used to construct imaginary frequency if mesh is not given. n_iw : integer, optional - Number of Matsubara frequencies. Used to construct imaginary frequency if mesh is not given. + Number of Matsubara frequencies. Used to construct imaginary frequency if mesh is not given. use_dft_blocks : boolean, optional If True, the local Green's function matrix for each spin is divided into smaller blocks with the block structure determined from the DFT density matrix of the corresponding correlated shell. @@ -110,7 +110,7 @@ class SumkDFT(object): self.mesh = mesh else: raise ValueError('mesh must be a triqs mesh of type MeshImFreq or MeshReFreq') - + self.block_structure = BlockStructure() @@ -621,12 +621,12 @@ class SumkDFT(object): assert len(Sigma_imp) == self.n_corr_shells,\ "put_Sigma: give exactly one Sigma for each corr. shell!" - if isinstance(self.mesh, MeshImFreq) and all(isinstance(gf, Gf) and gf.mesh == self.mesh for bname, gf in Sigma_imp[0]): + if isinstance(self.mesh, MeshImFreq) and all(isinstance(gf.mesh, MeshImFreq) and isinstance(gf, Gf) and gf.mesh == self.mesh for bname, gf in Sigma_imp[0]): # Imaginary frequency Sigma: self.Sigma_imp = [self.block_structure.create_gf(ish=icrsh, mesh=Sigma_imp[icrsh].mesh, space='sumk') for icrsh in range(self.n_corr_shells)] SK_Sigma_imp = self.Sigma_imp - elif isinstance(self.mesh, MeshReFreq) and all(isinstance(gf, Gf) and gf.mesh == self.mesh for bname, gf in Sigma_imp[0]): + elif isinstance(self.mesh, MeshReFreq) and all(isinstance(gf, Gf) and isinstance(gf.mesh, MeshReFreq) and gf.mesh == self.mesh for bname, gf in Sigma_imp[0]): # Real frequency Sigma: self.Sigma_imp = [self.block_structure.create_gf(ish=icrsh, mesh=Sigma_imp[icrsh].mesh, gf_function=GfReFreq, space='sumk') for icrsh in range(self.n_corr_shells)] diff --git a/python/triqs_dft_tools/sumk_dft_tools.py b/python/triqs_dft_tools/sumk_dft_tools.py index 5f47c03a..77f12738 100644 --- a/python/triqs_dft_tools/sumk_dft_tools.py +++ b/python/triqs_dft_tools/sumk_dft_tools.py @@ -822,8 +822,9 @@ class SumkDFTTools(SumkDFT): Data as it is also written to the files. """ - assert hasattr( - self, "Sigma_imp_w"), "spaghettis: Set Sigma_imp_w first." + # check if ReFreqMesh is given + assert isinstance(self.mesh, MeshReFreq) + things_to_read = ['n_k', 'n_orbitals', 'proj_mat', 'hopping', 'n_parproj', 'proj_mat_all'] value_read = self.read_input_from_hdf( @@ -840,7 +841,7 @@ class SumkDFTTools(SumkDFT): if mu is None: mu = self.chemical_potential spn = self.spin_block_names[self.SO] - mesh = [x.real for x in self.mesh] + mesh = numpy.array([x.value for x in self.mesh]) n_om = len(mesh) if plot_range is None: @@ -858,7 +859,7 @@ class SumkDFTTools(SumkDFT): Akw = {sp: numpy.zeros( [self.shells[ishell]['dim'], self.n_k, n_om], numpy.float_) for sp in spn} - if not ishell is None: + if ishell is not None: gf_struct_parproj = [ (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)) diff --git a/test/python/srvo3_spectral.py b/test/python/srvo3_spectral.py index 63b833a7..55a47856 100644 --- a/test/python/srvo3_spectral.py +++ b/test/python/srvo3_spectral.py @@ -1,20 +1,16 @@ from triqs_dft_tools.sumk_dft_tools import * -from triqs.utility.h5diff import h5diff +from triqs.utility.h5diff import h5diff from h5 import HDFArchive -beta = 40 - -SK = SumkDFTTools(hdf_file='SrVO3_spectral.h5', use_dft_blocks=True) - -if mpi.is_master_node(): - with HDFArchive('SrVO3_Sigma.h5', 'a') as ar: +with HDFArchive('SrVO3_Sigma.h5', 'r') as ar: Sigma = ar['dmft_transp_input']['Sigma_w'] - SK.chemical_potential = ar['dmft_transp_input']['chemical_potential'] - SK.dc_imp = ar['dmft_transp_input']['dc_imp'] + chemical_potential = ar['dmft_transp_input']['chemical_potential'] + dc_imp = ar['dmft_transp_input']['dc_imp'] -Sigma = mpi.bcast(Sigma) -SK.chemical_potential = mpi.bcast(SK.chemical_potential) -SK.dc_imp = mpi.bcast(SK.dc_imp) +SK = SumkDFTTools(hdf_file='SrVO3_spectral.h5', use_dft_blocks=True, mesh = Sigma.mesh) + +SK.chemical_potential = chemical_potential +SK.dc_imp = dc_imp SK.set_Sigma([Sigma]) dos_wannier = SK.dos_wannier_basis(broadening=0.01, with_Sigma=True, with_dc=True, save_to_file=False) @@ -24,12 +20,12 @@ spaghetti = SK.spaghettis(broadening=0.01, plot_shift=0.0, plot_range=(-1,1), is if mpi.is_master_node(): # with HDFArchive('srvo3_spectral.ref.h5', 'a') as ar: - # ar['dos_wannier'] = dos_wannier + # ar['dos_wannier'] = dos_wannier # ar['dos_parproj'] = dos_parproj # ar['spaghetti'] = spaghetti with HDFArchive('srvo3_spectral.out.h5', 'a') as ar: - ar['dos_wannier'] = dos_wannier + ar['dos_wannier'] = dos_wannier ar['dos_parproj'] = dos_parproj ar['spaghetti'] = spaghetti