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

spectral routines plotpt3d update

This commit is contained in:
Alyn James 2023-04-15 18:30:37 +01:00
parent df7e3958af
commit 45696baf9a
4 changed files with 50 additions and 73 deletions

View File

@ -297,8 +297,9 @@ class ElkConverterTools:
return dy return dy
def plotpt3d(self,n_k,vkl,n_symm,symlat,grid3d,ngrid): def plotpt3d(self,n_k,vkl,n_symm,symlat,grid3d,ngrid):
#import time
import triqs.utility.mpi as mpi import triqs.utility.mpi as mpi
#import time
#st = time.time()
#default vector tolerance used in Elk. This should not be altered. #default vector tolerance used in Elk. This should not be altered.
epslat=1E-6 epslat=1E-6
tol=int(numpy.log10(1/epslat)) tol=int(numpy.log10(1/epslat))
@ -307,82 +308,54 @@ class ElkConverterTools:
nk = ngrid[0]*ngrid[1]*ngrid[2] nk = ngrid[0]*ngrid[1]*ngrid[2]
BZvkl = numpy.zeros([nk,3], float) BZvkl = numpy.zeros([nk,3], float)
BZvkl[:,:] = None BZvkl[:,:] = None
vklir = numpy.zeros([3], float) #array which maps the new vkl to the symmetrically equivalent interface vkl
vklir[:] = None
#array which maps the new vkl to the symmetrically equivalent interface self.vkl
iknr = numpy.zeros([nk], int) iknr = numpy.zeros([nk], int)
v = numpy.zeros([3], float)
nk_ = 0 nk_ = 0
ik = 0
vklIBZ = [self.v3frac(vkl[ik,:],epslat) for ik in range(n_k)] vklIBZ = [self.v3frac(vkl[ik,:],epslat) for ik in range(n_k)]
vklIBZ = numpy.array(vklIBZ) vklIBZ = numpy.array(vklIBZ)
#print(vklIBZ)
#st = time.time() #generate mesh grid
#loop over the number of grid points for each reciprocal lattice i0, i1, i2 = numpy.meshgrid(numpy.arange(ngrid[0]), numpy.arange(ngrid[1]),
for i2 in range(ngrid[2]): numpy.arange(ngrid[2]), indexing='ij')
t2=float(i2)/float(ngrid[2]) #convert to floats
for i1 in range(ngrid[1]): t0 = i0.astype(float)/ngrid[0]
t1=float(i1)/float(ngrid[1]) t1 = i1.astype(float)/ngrid[1]
for i0 in range(ngrid[0]): t2 = i2.astype(float)/ngrid[2]
t0=float(i0)/float(ngrid[0]) #Calculate Brillouin zone lattice vectors
#br = None BZvkl[:, 0] = (t0*b[0,0]+t1*b[1, 0]+t2*b[2, 0]+grid3d[0, 0]).flatten()
#calculate Brillouin zone lattice vector BZvkl[:, 1] = (t0*b[0,1]+t1*b[1, 1]+t2*b[2, 1]+grid3d[0, 1]).flatten()
v = t0*b[0,:]+t1*b[1,:]+t2*b[2,:]+grid3d[0,:] BZvkl[:, 2] = (t0*b[0,2]+t1*b[1, 2]+t2*b[2, 2]+grid3d[0, 2]).flatten()
BZvkl[ik,:] = v.copy() #check k-point has equivalent point dft-interfaced k-point list (this is a bottle neck for performance)
ik += 1 for ik in range(nk):
br = None
#check if generated points are symmetrically equivalent to interfaced vkl v1 = self.v3frac(BZvkl[ik,:], epslat)
#Note that this loop is the bottle neck for this routine hence the #see if v1 is symmetrically equivalent to a vector in IBZvkl
#parallelisation. for isym in range(n_symm):
ikarray = numpy.array(range(nk)) v_symm=numpy.matmul(symlat[isym][:,:].transpose(),v1)
for ik in mpi.slice_array(ikarray): v_symm=self.v3frac(v_symm,epslat)
#apply translation to reduce back to first Brillouin zone if v_symm.round(tol).tolist() in vklIBZ.round(tol).tolist():
v = self.v3frac(BZvkl[ik,:].copy(),epslat) iknr[ik] = vkl.round(tol).tolist().index(v_symm.round(tol).tolist())
br = None #if identity symmetry operation was used, this v1 must be in the IBZ vector set
if numpy.allclose(symlat[isym][:,:],numpy.eye(3)):
if v.round(tol).tolist() in vklIBZ.copy().round(tol).tolist(): nk_+=1
#Find index of v in self.vkl br = 1
ikk = vkl.copy().round(tol).tolist().index(v.round(tol).tolist()) break
iknr[ik] = ikk if br == 1: continue
#ikir = numpy.append(ikir,ikk) #if v1 is not symmetrically equivalent, then wrong input mesh.
#check if v is a irreducible vector and tally these vectors mpi.report('No identity symmetry operator or symmetrically equivalent vector in interface vkl set')
if v.round(tol).tolist() not in vklir.round(tol).tolist(): assert 0, "input grid does not generate interfaced reciprocal vectors"
nk_+=1
vklir = numpy.vstack((vklir,v))
continue
#if v is not in interface set, see if it's symmetrically equivalent to
#a vector in self.vkl
for isym in range(n_symm):
if numpy.allclose(symlat[isym][:,:],numpy.eye(3)):
continue
v_symm=numpy.matmul(symlat[isym][:,:].transpose(),v)
v_symm=self.v3frac(v_symm,epslat)
if v_symm.round(tol).tolist() in vklIBZ.copy().round(tol).tolist():
ikk = vkl.copy().round(tol).tolist().index(v_symm.round(tol).tolist())
#ikir = numpy.append(ikir,ikk)
iknr[ik] = ikk
br = 1
break
if br == 1: continue
#if v is not symmetrically equivalent, then wrong input mesh.
mpi.report('No symmetrically equavilent vector in interface vkl set')
assert 0, "input grid does not generate interfaced reciprocal vectors"
#collect required variables and arrays (initialised to zero) from all threads.
nk_ = mpi.all_reduce(mpi.world, nk_, lambda x, y: x + y)
iknr = mpi.all_reduce(mpi.world, iknr, lambda x, y: x + y)
#check that all the vectors from the interface are in this list of vectors #check that all the vectors from the interface are in this list of vectors
if(nk_!=n_k): if(nk_!=n_k):
mpi.report('Incorrect number of irreducible vectors with respect to self.vkl ') mpi.report('Incorrect number of irreducible vectors with respect to vkl ')
mpi.report('%s!=%s'%(nk_,n_k)) mpi.report('%s!=%s'%(nk_,n_k))
assert 0, "input grid does not generate interfaced reciprocal vectors" assert 0, "input grid does not generate interfaced reciprocal vectors"
#et = time.time() #et = time.time()
#mpi.report(et-st,nk,nk_) #mpi.report(et-st,nk)
#assert 0, ""
return BZvkl, iknr, nk return BZvkl, iknr, nk
def bzfoldout(self,n_k,vkl,n_symm,symlat): def bzfoldout(self,n_k,vkl,n_symm,symlat):
import triqs.utility.mpi as mpi #import triqs.utility.mpi as mpi
epslat=1E-6 epslat=1E-6
tol=int(numpy.log10(1/epslat)) tol=int(numpy.log10(1/epslat))
#new temporary arrays for expanding irreducible Brillouin zone #new temporary arrays for expanding irreducible Brillouin zone
@ -393,20 +366,13 @@ class ElkConverterTools:
vkl2[0,:,:] = vkl[:,:].copy() vkl2[0,:,:] = vkl[:,:].copy()
iknr2[0,:] = iknr[:].copy() iknr2[0,:] = iknr[:].copy()
#expand irreducible Brillouin zone #expand irreducible Brillouin zone
ikarray = numpy.array(range(n_k)) for ik in range(n_k):
for ik in mpi.slice_array(ikarray):
for isym in range(n_symm): for isym in range(n_symm):
#find point in BZ by symmetry operation #find point in BZ by symmetry operation
v=numpy.matmul(symlat[isym][:,:].transpose(),vkl[ik,:]) v=numpy.matmul(symlat[isym][:,:].transpose(),vkl[ik,:])
#shift back in to range [0,1) - Elk specific
#v[:]=self.v3frac(v,epslat)
#alter temporary arrays #alter temporary arrays
vkl2[isym,ik,:] = v[:] vkl2[isym,ik,:] = v[:]
iknr2[isym,ik] = ik iknr2[isym,ik] = ik
# Collect data from mpi (adding to elements with zeros):
vkl2 = mpi.all_reduce(mpi.world, vkl2, lambda x, y: x + y)
iknr2 = mpi.all_reduce(mpi.world, iknr2, lambda x, y: x + y)
mpi.barrier()
#flatten arrays #flatten arrays
BZvkl = vkl2.reshape(n_k*n_symm,3) BZvkl = vkl2.reshape(n_k*n_symm,3)
iknr = iknr2.reshape(n_k*n_symm) iknr = iknr2.reshape(n_k*n_symm)

View File

@ -13,6 +13,7 @@ testdir = cwd+'/elk_spectralcontours_convert'
#change to test directory #change to test directory
os.chdir(testdir) os.chdir(testdir)
#default k-mesh
Converter = ElkConverter(filename='SrVO3', repacking=True) Converter = ElkConverter(filename='SrVO3', repacking=True)
Converter.hdf_file = 'elk_spectralcontours_convert.out.h5' Converter.hdf_file = 'elk_spectralcontours_convert.out.h5'
Converter.convert_dft_input() Converter.convert_dft_input()
@ -27,16 +28,26 @@ fs_elk = SK.spectral_contours(broadening=0.01, mesh=mesh, with_Sigma=False, with
omega_elk = SK.spectral_contours(broadening=0.01, mesh=mesh, with_Sigma=False, with_dc=False, FS=False, proj_type='wann', save_to_file=False) omega_elk = SK.spectral_contours(broadening=0.01, mesh=mesh, with_Sigma=False, with_dc=False, FS=False, proj_type='wann', save_to_file=False)
omega_range_elk = SK.spectral_contours(broadening=0.01, mesh=mesh, plot_range=(-0.5,2), with_Sigma=False, with_dc=False, FS=False, proj_type='wann', save_to_file=False) omega_range_elk = SK.spectral_contours(broadening=0.01, mesh=mesh, plot_range=(-0.5,2), with_Sigma=False, with_dc=False, FS=False, proj_type='wann', save_to_file=False)
#user specified k-mesh - has to be same as used in elk.in
Converter = ElkConverter(filename='SrVO3', repacking=True)
Converter.hdf_file = 'elk_spectralcontours_convert.out.h5'
ngrid=np.array([10,10,1],np.int_)
kgrid=np.array([[0.0,0.0,0.0],[1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0]],np.float_)
Converter.convert_contours_input(kgrid=kgrid,ngrid=ngrid)
SK2 = SumkDFTTools(hdf_file='elk_spectralcontours_convert.out.h5', use_dft_blocks=True)
fs_elk_user = SK2.spectral_contours(broadening=0.01, mesh=mesh, with_Sigma=False, with_dc=False, FS=True, proj_type='wann', save_to_file=False)
if mpi.is_master_node(): if mpi.is_master_node():
#with HDFArchive('elk_fermisurface_convert.ref.h5', 'a') as ar: #with HDFArchive('elk_spectralcontours_convert.ref.h5', 'a') as ar:
# ar['fs_elk'] = fs_elk # ar['fs_elk'] = fs_elk
# ar['fs_elk_user'] = fs_elk_user
# ar['omega_elk'] = omega_elk # ar['omega_elk'] = omega_elk
# ar['omega_range_elk'] = omega_range_elk # ar['omega_range_elk'] = omega_range_elk
# ar['mesh'] = [omin,omax,oN] # ar['mesh'] = [omin,omax,oN]
with HDFArchive('elk_spectralcontours_convert.out.h5', 'a') as ar: with HDFArchive('elk_spectralcontours_convert.out.h5', 'a') as ar:
ar['fs_elk'] = fs_elk ar['fs_elk'] = fs_elk
ar['fs_elk_user'] = fs_elk_user
ar['omega_elk'] = omega_elk ar['omega_elk'] = omega_elk
ar['omega_range_elk'] = omega_range_elk ar['omega_range_elk'] = omega_range_elk
ar['mesh'] = [omin,omax,oN] ar['mesh'] = [omin,omax,oN]