Skip to content

Commit 8c66f1c

Browse files
Dario Fiore Moscathe-hampel
Dario Fiore Mosca
authored andcommitted
Symmetric DFT implementation
1 parent c8fd1e4 commit 8c66f1c

File tree

9 files changed

+105
-39
lines changed

9 files changed

+105
-39
lines changed

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dft_tools.src.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/triqs_dft_tools/converters/plovasp/sc_dmft.py

+23-21
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,26 @@ def is_vasp_running(vasp_pid):
7272
pid_exists = mpi.bcast(pid_exists)
7373
return pid_exists
7474

75+
7576
def get_dft_energy():
7677
"""
77-
Reads energy from the last line of OSZICAR.
78+
Reads DFT energy from the last line of Vasp's OSZICAR or from vasptriqs.h5
7879
"""
79-
with open('OSZICAR', 'r') as f:
80-
nextline = f.readline()
81-
while nextline.strip():
82-
line = nextline
83-
nextline = f.readline()
84-
# print "OSZICAR: ", line[:-1]
80+
h5_energy = False
81+
if os.path.isfile('vaspout.h5'):
82+
with HDFArchive('vaspout.h5', 'r') as h5:
83+
if 'oszicar' in h5['intermediate/ion_dynamics']:
84+
dft_energy = h5['intermediate/ion_dynamics/oszicar'][-1,1]
85+
h5_energy = True
8586

86-
try:
87+
# as backup use OSZICAR file
88+
if not h5_energy:
89+
with open('OSZICAR', 'r') as file:
90+
nextline = file.readline()
91+
while nextline.strip():
92+
line = nextline
93+
nextline = file.readline()
8794
dft_energy = float(line.split()[2])
88-
except ValueError:
89-
print("Cannot read energy from OSZICAR, setting it to zero")
90-
dft_energy = 0.0
9195

9296
return dft_energy
9397

@@ -98,9 +102,8 @@ class bcolors:
98102
YELLOW = '\033[93m'
99103
RED = '\033[91m'
100104
ENDC = '\033[0m'
101-
#
105+
102106
# Main self-consistent cycle
103-
#
104107
def run_all(vasp_pid, dmft_cycle, cfg_file, n_iter, n_iter_dft, vasp_version):
105108
"""
106109
"""
@@ -117,15 +120,14 @@ def run_all(vasp_pid, dmft_cycle, cfg_file, n_iter, n_iter_dft, vasp_version):
117120
mpi.barrier()
118121
while is_vasp_lock_present():
119122
time.sleep(1)
120-
# if debug: print bcolors.YELLOW + " waiting: rank %s"%(mpi.rank) + bcolors.ENDC
123+
if debug: print(bcolors.YELLOW + " waiting: rank %s"%(mpi.rank) + bcolors.ENDC)
121124
if not is_vasp_running(vasp_pid):
122125
mpi.report(" VASP stopped")
123126
vasp_running = False
124127
break
125128

126-
# Tell VASP to stop if the maximum number of iterations is reached
127-
128-
129+
# Tell VASP to stop if the maximum number of iterations is reached
130+
129131
if debug: print(bcolors.MAGENTA + "rank %s"%(mpi.rank) + bcolors.ENDC)
130132
err = 0
131133
exc = None
@@ -161,7 +163,7 @@ def run_all(vasp_pid, dmft_cycle, cfg_file, n_iter, n_iter_dft, vasp_version):
161163
# electron.F around line 644
162164
iter_dft = 0
163165

164-
if vasp_version == 'standard':
166+
if vasp_version == 'standard' or vasp_version == 'ncl':
165167
copyfile(src='GAMMA',dst='GAMMA_recent')
166168
while iter_dft < n_iter_dft:
167169
# insert recalculation of GAMMA here
@@ -190,7 +192,7 @@ def run_all(vasp_pid, dmft_cycle, cfg_file, n_iter, n_iter_dft, vasp_version):
190192
vasp_running = False
191193
break
192194
iter_dft += 1
193-
if vasp_version == 'standard':
195+
if vasp_version == 'standard' or vasp_version == 'ncl':
194196
copyfile(src='GAMMA_recent',dst='GAMMA')
195197
iter += 1
196198
if iter == n_iter:
@@ -253,8 +255,8 @@ def main():
253255
except KeyError:
254256
vasp_version = 'standard'
255257

256-
if vasp_version != 'standard' and vasp_version != 'no_gamma_write':
257-
raise Exception('vasp_version has to be standard or no_gamma_write')
258+
#if vasp_version != 'standard' and vasp_version != 'no_gamma_write':
259+
# raise Exception('vasp_version has to be standard or no_gamma_write')
258260

259261
# if len(sys.argv) > 1:
260262
# vasp_path = sys.argv[1]

python/triqs_dft_tools/converters/plovasp/vaspio.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(self, vasp_dir, read_all=True, efermi_required=True):
8282
self.plocar = h5Plocar(h5path)
8383
self.poscar = h5Poscar(h5path)
8484
self.kpoints = h5Kpoints(h5path)
85-
self.eigenval = h5Eigenval(h5path)
85+
self.eigenval = h5Eigenval(h5path, self.kpoints.ksymmap)
8686
self.doscar = h5Doscar(h5path)
8787
else:
8888
self.plocar = Plocar()
@@ -716,28 +716,34 @@ def __init__(self, h5path):
716716
# h5path = './vasptriqs.h5'
717717
with HDFArchive(h5path, 'a') as archive:
718718
kpoints = archive['results/electron_eigenvalues']
719-
self.nktot = kpoints['kpoints']
720-
self.kpts = kpoints['kpoint_coords']
721-
self.kwghts = kpoints['kpoints_symmetry_weight']
719+
self.nkred = kpoints['kpoints']
720+
self.kpts = kpoints['kpoint_coords_full']
721+
self.nktot = len(self.kpts)
722+
self.kwghts = kpoints['kpoints_symmetry_weight_full']
723+
self.ksymmap = kpoints['kpoints_symmetry_mapping']
724+
self.ksymmap -= 1
722725
try:
723726
self.ntet = kpoints['num_tetrahedra']
724727
self.vtet = kpoints['volume_weight_tetrahedra']
725728
self.itet = kpoints['coordinate_id_tetrahedra']
726729
except KeyError:
727-
print(" No tetrahedron data found in vasptriqs.h5. Skipping...")
730+
print(" No tetrahedron data found in vaspout.h5. Skipping...")
728731
self.ntet = 0
729732

730733
print()
734+
print(" {0:>26} {1:d}".format("Reduced number of k-points:", self.nkred))
731735
print(" {0:>26} {1:d}".format("Total number of k-points:", self.nktot))
732736
print(" {0:>26} {1:d}".format("Total number of tetrahedra:", self.ntet))
733737

734738

735739
class h5Eigenval:
736740

737-
def __init__(self, h5path):
741+
def __init__(self, h5path, symmap):
738742
with HDFArchive(h5path, 'a') as archive:
739743
self.eigs = archive['results/electron_eigenvalues']['eigenvalues']
744+
self.eigs = self.eigs[:, symmap, :]
740745
self.ferw = archive['results/electron_eigenvalues']['fermiweights']
746+
self.ferw = self.ferw[:, symmap, :]
741747
# TODO Change the format in VASP to have [kpoints, bands, spin]
742748
self.eigs = np.transpose(self.eigs, (1, 2, 0))
743749
self.ferw = np.transpose(self.ferw, (1, 2, 0))

python/triqs_dft_tools/sumk_dft.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ def lattice_gf(self, ik, mu=None, broadening=None, mesh=None, with_Sigma=True, w
578578
mesh_values = self.mesh_values
579579

580580
elif not mesh is None:
581-
assert isinstance(mesh, (MeshReFreq, MeshDLRImFreq, MeshImFreq)), "mesh must be a triqs MeshReFreq or MeshImFreq"
581+
assert isinstance(mesh,
582+
(MeshReFreq, MeshDLRImFreq, MeshImFreq)), "mesh must be a triqs MeshReFreq or MeshImFreq"
582583
if isinstance(mesh, MeshImFreq):
583584
mesh_values = np.linspace(mesh(mesh.first_index()), mesh(mesh.last_index()), len(mesh))
584585
elif isinstance(mesh, MeshDLRImFreq):
@@ -596,7 +597,7 @@ def lattice_gf(self, ik, mu=None, broadening=None, mesh=None, with_Sigma=True, w
596597
gf_struct = [(spn[isp], block_structure[isp])
597598
for isp in range(self.n_spin_blocks[self.SO])]
598599
block_ind_list = [block for block, inner in gf_struct]
599-
glist = lambda: [Gf(mesh=mesh, target_shape=[len(inner),len(inner)])
600+
glist = lambda: [Gf(mesh=mesh, target_shape=[len(inner), len(inner)])
600601
for block, inner in gf_struct]
601602
G_latt = BlockGf(name_list=block_ind_list,
602603
block_list=glist(), make_copies=False)
@@ -610,7 +611,7 @@ def lattice_gf(self, ik, mu=None, broadening=None, mesh=None, with_Sigma=True, w
610611
ind = ntoi[spn[ibl]]
611612
n_orb = self.n_orbitals[ik, ind]
612613
if isinstance(mesh, (MeshImFreq, MeshDLRImFreq)):
613-
gf.data[:, :, :] = (idmat[ibl] * (mesh_values[:, None, None] + mu + self.h_field*(1-2*ibl))
614+
gf.data[:, :, :] = (idmat[ibl] * (mesh_values[:, None, None] + mu + self.h_field * (1 - 2 * ibl))
614615
- self.hopping[ik, ind, 0:n_orb, 0:n_orb])
615616
else:
616617
gf.data[:, :, :] = (idmat[ibl] *
@@ -655,8 +656,8 @@ def put_Sigma(self, Sigma_imp, transform_to_sumk_blocks=True):
655656

656657
if (isinstance(self.mesh, (MeshImFreq, MeshDLRImFreq)) and
657658
all(isinstance(gf.mesh, (MeshImFreq, MeshDLRImFreq)) and
658-
isinstance(gf, Gf) and
659-
gf.mesh == self.mesh for bname, gf in Sigma_imp[0])):
659+
isinstance(gf, Gf) and
660+
gf.mesh == self.mesh for bname, gf in Sigma_imp[0])):
660661
# Imaginary frequency Sigma:
661662
self.Sigma_imp = [self.block_structure.create_gf(ish=icrsh, mesh=Sigma_imp[icrsh].mesh, space='sumk')
662663
for icrsh in range(self.n_corr_shells)]
@@ -692,7 +693,7 @@ def put_Sigma(self, Sigma_imp, transform_to_sumk_blocks=True):
692693
self.max_band_energy - self.chemical_potential):
693694
warn(
694695
'The given Sigma is on a mesh which does not cover the band energy range. The Sigma MeshReFreq runs from %f to %f, while the band energy (minus the chemical potential) runs from %f to %f' % (
695-
mesh[0], mesh[-1], self.min_band_energy, self.max_band_energy))
696+
mesh[0], mesh[-1], self.min_band_energy, self.max_band_energy))
696697

697698
def transform_to_sumk_blocks(self, Sigma_imp, Sigma_out=None):
698699
r""" transform Sigma from solver to sumk space
@@ -1843,7 +1844,8 @@ def add_dc(self):
18431844
for bname, gf in sigma_minus_dc[icrsh]:
18441845
# Transform dc_imp to global coordinate system
18451846
if self.use_rotations:
1846-
gf -= np.dot(self.rot_mat[icrsh], np.dot(self.dc_imp[icrsh][bname], self.rot_mat[icrsh].conjugate().transpose()))
1847+
gf -= np.dot(self.rot_mat[icrsh],
1848+
np.dot(self.dc_imp[icrsh][bname], self.rot_mat[icrsh].conjugate().transpose()))
18471849
else:
18481850
gf -= self.dc_imp[icrsh][bname]
18491851

@@ -2205,7 +2207,8 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
22052207
filename = 'dens_mat.dat'
22062208
elif dm_type == 'vasp':
22072209
# use new h5 interface to vasp by default, if not wanted specify dm_type='vasp' + filename='GAMMA'
2208-
filename = 'vaspgamma.h5'
2210+
# filename = 'vaspgamma.h5'
2211+
filename = 'GAMMA'
22092212
elif dm_type == 'elk':
22102213
filename = 'DMATDMFT.OUT'
22112214
elif dm_type == 'qe':
@@ -2360,7 +2363,7 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
23602363
vasp_h5['deltaN'] = deltaN
23612364
else:
23622365
with open(filename, 'w') as f:
2363-
f.write(" %i -1 ! Number of k-points, default number of bands\n" % len(kpts_to_write))
2366+
f.write(" -1 -1 ! Number of k-points, default number of bands\n") # % len(kpts_to_write))
23642367
for index, ik in enumerate(kpts_to_write):
23652368
ib1 = band_window[0][ik, 0]
23662369
ib2 = band_window[0][ik, 1]
@@ -2372,8 +2375,10 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
23722375
valim = (deltaN['ud'][ik][inu, imu].imag) / 1.0
23732376
f.write(" %.14f %.14f" % (valre, valim))
23742377
else:
2375-
valre = (deltaN['up'][ik][inu, imu].real + deltaN['down'][ik][inu, imu].real) / 2.0
2376-
valim = (deltaN['up'][ik][inu, imu].imag + deltaN['down'][ik][inu, imu].imag) / 2.0
2378+
valre = (deltaN['up'][ik][inu, imu].real + deltaN['down'][ik][
2379+
inu, imu].real) / 2.0
2380+
valim = (deltaN['up'][ik][inu, imu].imag + deltaN['down'][ik][
2381+
inu, imu].imag) / 2.0
23772382
f.write(" %.14f %.14f" % (valre, valim))
23782383
f.write("\n")
23792384

@@ -2396,7 +2401,7 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
23962401
mu = self.chemical_potential / self.energy_unit
23972402
# ouput n_k, nspin and max orbitals - a check
23982403
f.write(" %d %d %d %.14f %.14f ! nkpt, nspin, nstmax, beta, mu\n" % (
2399-
self.n_k, n_spin_blocks, nbmax, beta, mu))
2404+
self.n_k, n_spin_blocks, nbmax, beta, mu))
24002405
for ik in range(self.n_k):
24012406
for ispn in range(n_spin_blocks):
24022407
# Determine the SO density matrix band indices from the spinor band indices

0 commit comments

Comments
 (0)