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

Merge pull request #189 from phibeck/calc_density_correction_qe

Calc_density_correction with Quantum Espresso
This commit is contained in:
Alexander Hampel 2021-11-04 15:40:10 -04:00 committed by GitHub
commit b8b1b6b77d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2007,7 +2007,7 @@ class SumkDFT(object):
the corresponing total charge `dens`. the corresponing total charge `dens`.
""" """
assert dm_type in ('vasp', 'wien2k','elk'), "'dm_type' must be either 'vasp', 'wienk' or 'elk'" assert dm_type in ('vasp', 'wien2k','elk', 'qe'), "'dm_type' must be either 'vasp', 'wienk', 'elk' or 'qe'"
#default file names #default file names
if filename is None: if filename is None:
if dm_type == 'wien2k': if dm_type == 'wien2k':
@ -2016,6 +2016,8 @@ class SumkDFT(object):
filename = 'GAMMA' filename = 'GAMMA'
elif dm_type == 'elk': elif dm_type == 'elk':
filename = 'DMATDMFT.OUT' filename = 'DMATDMFT.OUT'
elif dm_type == 'qe':
filename = self.hdf_file
assert isinstance(filename, str), ("calc_density_correction: " assert isinstance(filename, str), ("calc_density_correction: "
@ -2030,7 +2032,7 @@ class SumkDFT(object):
band_en_correction = 0.0 band_en_correction = 0.0
# Fetch Fermi weights and energy window band indices # Fetch Fermi weights and energy window band indices
if dm_type == 'vasp': if dm_type in ['vasp','qe']:
fermi_weights = 0 fermi_weights = 0
band_window = 0 band_window = 0
if mpi.is_master_node(): if mpi.is_master_node():
@ -2069,7 +2071,7 @@ class SumkDFT(object):
deltaN[bname][ik] = G_latt_iw[bname].density() deltaN[bname][ik] = G_latt_iw[bname].density()
dens[bname] += self.bz_weights[ik] * G_latt_iw[bname].total_density() dens[bname] += self.bz_weights[ik] * G_latt_iw[bname].total_density()
if dm_type == 'vasp': if dm_type in ['vasp','qe']:
# In 'vasp'-mode subtract the DFT density matrix # In 'vasp'-mode subtract the DFT density matrix
nb = self.n_orbitals[ik, ntoi[bname]] nb = self.n_orbitals[ik, ntoi[bname]]
diag_inds = numpy.diag_indices(nb) diag_inds = numpy.diag_indices(nb)
@ -2216,13 +2218,36 @@ class SumkDFT(object):
f.write(" %.14f %.14f"%(valre, valim)) f.write(" %.14f %.14f"%(valre, valim))
f.write("\n") f.write("\n")
elif dm_type == 'qe':
assert self.SP == 0, "Spin-polarized density matrix is not implemented"
subgrp = 'dft_update'
delta_N = numpy.zeros([self.n_k, max(self.n_orbitals[:,0]), max(self.n_orbitals[:,0])], dtype=complex)
mpi.report(" %i -1 ! Number of k-points, default number of bands\n"%(self.n_k))
for ik in range(self.n_k):
ib1 = band_window[0][ik, 0]
ib2 = band_window[0][ik, 1]
for inu in range(self.n_orbitals[ik, 0]):
for imu in range(self.n_orbitals[ik, 0]):
valre = (deltaN['up'][ik][inu, imu].real + deltaN['down'][ik][inu, imu].real) / 2.0
valim = (deltaN['up'][ik][inu, imu].imag + deltaN['down'][ik][inu, imu].imag) / 2.0
# write into delta_N
delta_N[ik, inu, imu] = valre + 1j*valim
if mpi.is_master_node():
with HDFArchive(self.hdf_file, 'a') as ar:
if not subgrp in ar:
ar.create_group(subgrp)
things_to_save = ['delta_N']
for it in things_to_save:
ar[subgrp][it] = locals()[it]
else: else:
raise NotImplementedError("Unknown density matrix type: '%s'"%(dm_type)) raise NotImplementedError("Unknown density matrix type: '%s'"%(dm_type))
res = deltaN, dens res = deltaN, dens
if dm_type == 'vasp': if dm_type in ['vasp', 'qe']:
res += (band_en_correction,) res += (band_en_correction,)
return res return res