Skip to content

Commit 917b269

Browse files
committed
Add ABINIT option to the sumk class.
1 parent 51e0586 commit 917b269

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

python/triqs_dft_tools/sumk_dft.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def read_input_from_hdf(self, subgrp, things_to_read):
222222
Returns
223223
-------
224224
subgroup_present : boolean
225-
Is the subgrp is present in hdf5 file?
225+
Is the subgrp present in hdf5 file?
226226
values_not_read : list of strings
227227
List of things that could not be read
228228
@@ -759,15 +759,15 @@ def extract_G_loc(self, mu=None, with_Sigma=True, with_dc=True, broadening=None,
759759
if with_Sigma and hasattr(self, "Sigma_imp"):
760760
mesh = self.Sigma_imp[0].mesh
761761
if mesh != self.mesh:
762-
warn('self.mesh and self.Sigma_imp[0].mesh are differen! Using mesh from Sigma')
762+
warn('self.mesh and self.Sigma_imp[0].mesh are different! Using mesh from Sigma')
763763
elif with_Sigma and not hasattr(self, "Sigma_imp"):
764764
mpi.report('Warning: No Sigma set but parameter with_Sigma=True, calculating Gloc without Sigma.')
765765
with_Sigma = False
766766
mesh = self.mesh
767767
else:
768768
mesh = self.mesh
769769

770-
# create G_loc to be returned in sumk space for all correlated shells. Trafo to solver block structure done later
770+
# create G_loc to be returned in sumk space for all correlated shells. Transform to solver block structure done later
771771
G_loc = [self.block_structure.create_gf(ish=ish, mesh=mesh, space='sumk') for ish in range(self.n_corr_shells)]
772772

773773
ikarray = np.array(list(range(self.n_k)))
@@ -2136,7 +2136,7 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
21362136
Name of the file to store the charge density correction.
21372137
dm_type : string
21382138
DFT code to write the density correction for. Options:
2139-
'vasp', 'wien2k', 'elk' or 'qe'. Needs to be set for 'qe'
2139+
'vasp', 'wien2k', 'elk', 'qe' or 'abinit'. Needs to be set for 'qe' or 'abinit'
21402140
spinave : logical
21412141
Elk specific and for magnetic calculations in DMFT only.
21422142
It averages the spin to keep the DFT part non-magnetic.
@@ -2162,7 +2162,7 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
21622162
if dm_type is None:
21632163
dm_type = self.dft_code
21642164

2165-
assert dm_type in ('vasp', 'wien2k','elk', 'qe'), "'dm_type' must be either 'vasp', 'wienk', 'elk' or 'qe'"
2165+
assert dm_type in ('vasp', 'wien2k','elk', 'qe', 'abinit'), "'dm_type' must be either 'vasp', 'wienk', 'elk', 'qe' or 'abinit'"
21662166
#default file names
21672167
if filename is None:
21682168
if dm_type == 'wien2k':
@@ -2173,6 +2173,8 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
21732173
filename = 'DMATDMFT.OUT'
21742174
elif dm_type == 'qe':
21752175
filename = self.hdf_file
2176+
elif dm_type == 'abinit':
2177+
filename = "abiout.delta_N"
21762178

21772179

21782180
assert isinstance(filename, str), ("calc_density_correction: "
@@ -2187,7 +2189,7 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
21872189
band_en_correction = 0.0
21882190

21892191
# Fetch Fermi weights and energy window band indices
2190-
if dm_type in ['vasp','qe']:
2192+
if dm_type in ['vasp','qe', 'abinit']:
21912193
fermi_weights = 0
21922194
band_window = 0
21932195
if mpi.is_master_node():
@@ -2202,7 +2204,6 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
22022204
for sp in spn:
22032205
dens_mat_dft[sp] = [fermi_weights[ik, ntoi[sp], :].astype(complex) for ik in range(self.n_k)]
22042206

2205-
22062207
# Set up deltaN:
22072208
deltaN = {}
22082209
for sp in spn:
@@ -2229,7 +2230,7 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
22292230
dens[bname] += self.bz_weights[ik] * G_latt[bname].total_density()
22302231
else:
22312232
dens[bname] += self.bz_weights[ik] * G_latt[bname].total_density(beta)
2232-
if dm_type in ['vasp','qe']:
2233+
if dm_type in ['vasp', 'qe', 'abinit']:
22332234
# In 'vasp'-mode subtract the DFT density matrix
22342235
nb = self.n_orbitals[ik, ntoi[bname]]
22352236
diag_inds = np.diag_indices(nb)
@@ -2386,8 +2387,8 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
23862387
ib2 = band_window[0][ik, 1]
23872388
for inu in range(self.n_orbitals[ik, 0]):
23882389
for imu in range(self.n_orbitals[ik, 0]):
2389-
valre = (deltaN['up'][ik][inu, imu].real + deltaN['down'][ik][inu, imu].real) / 2.0
2390-
valim = (deltaN['up'][ik][inu, imu].imag + deltaN['down'][ik][inu, imu].imag) / 2.0
2390+
valre = (deltaN['up'][ik][inu, imu].real + deltaN['down'][ik][inu, imu].real)
2391+
valim = (deltaN['up'][ik][inu, imu].imag + deltaN['down'][ik][inu, imu].imag)
23912392
# write into delta_N
23922393
delta_N[ik, inu, imu] = valre + 1j*valim
23932394
if mpi.is_master_node():
@@ -2398,13 +2399,34 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
23982399
for it in things_to_save:
23992400
ar[subgrp][it] = locals()[it]
24002401

2402+
elif dm_type == 'abinit':
2403+
if kpts_to_write is None:
2404+
kpts_to_write = np.arange(self.n_k)
2405+
else:
2406+
assert np.min(kpts_to_write) >= 0 and np.max(kpts_to_write) < self.n_k
2407+
2408+
assert self.SP == 0, "Spin-polarized density matrix is not implemented"
2409+
2410+
if mpi.is_master_node():
2411+
with open(filename, 'w') as f:
2412+
f.write(" %i -1 ! Number of k-points, default number of bands\n"%len(kpts_to_write))
2413+
for index, ik in enumerate(kpts_to_write):
2414+
ib1 = band_window[0][ik, 0]
2415+
ib2 = band_window[0][ik, 1]
2416+
f.write(" %i %i %i\n"%(index + 1, ib1, ib2))
2417+
for inu in range(self.n_orbitals[ik, 0]):
2418+
for imu in range(self.n_orbitals[ik, 0]):
2419+
valre = (deltaN['up'][ik][inu, imu].real + deltaN['down'][ik][inu, imu].real) / 2.0
2420+
valim = (deltaN['up'][ik][inu, imu].imag + deltaN['down'][ik][inu, imu].imag) / 2.0
2421+
f.write(" %.14f %.14f"%(valre, valim))
2422+
f.write("\n")
24012423

24022424
else:
24032425
raise NotImplementedError("Unknown density matrix type: '%s'"%(dm_type))
24042426

24052427
res = deltaN, dens
24062428

2407-
if dm_type in ['vasp', 'qe']:
2429+
if dm_type in ['vasp', 'qe', 'abinit']:
24082430
res += (band_en_correction,)
24092431

24102432
return res

0 commit comments

Comments
 (0)