Skip to content

Commit

Permalink
new VASP 6.5.0 hdf5 support capability (#262)
Browse files Browse the repository at this point in the history
* [vasp] read fermi from vasp h5 archive and write deltaN to vasp h5 archive
* Reading vasptriqs.h5 file; reading GAMMA file for non-collinear full csc
* fix read error for tetrahedron data and eigs properties
* write deltaN only to vasp h5 if present, write to GAMMA text file only for old interface
* support symmetries at DFT level in VASP
* use IBZ kpoint list for writing GAMMA vaspgamma.h5
* make vaspgamma.h5 default
* write n_k_ibz into dft_misc_input so in can be used inside of sumk
* add new svo converter test

---------

Co-authored-by: Dario Fiore Mosca <[email protected]>
  • Loading branch information
the-hampel and Dario Fiore Mosca authored Jan 9, 2025
1 parent 54918d7 commit 2a8acf4
Show file tree
Hide file tree
Showing 13 changed files with 481 additions and 233 deletions.
24 changes: 10 additions & 14 deletions python/triqs_dft_tools/converters/plovasp/elstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ElectronicStructure:
- *natom* (int) : total number of atoms
- *nktot* (int) : total number of `k`-points
- *nkibz* (int) : number of `k`-points in IBZ
- *nband* (int) : total number of bands
- *nspin* (int) : spin-polarization
- *nc_flag* (True/False) : non-collinearity flag
Expand All @@ -58,8 +59,9 @@ def __init__(self, vasp_data):
self.natom = vasp_data.poscar.nq
self.type_of_ion = vasp_data.poscar.type_of_ion
self.nktot = vasp_data.kpoints.nktot
self.nkibz = vasp_data.kpoints.nkibz

self.kmesh = {'nktot': self.nktot}
self.kmesh = {'nktot': self.nktot, 'nkibz': self.nkibz}
self.kmesh['kpoints'] = vasp_data.kpoints.kpts
# VASP.6.
self.nc_flag = vasp_data.plocar.nc_flag
Expand All @@ -86,21 +88,15 @@ def __init__(self, vasp_data):

# Check that the number of k-points is the same in all files
_, ns_plo, nk_plo, nb_plo = vasp_data.plocar.plo.shape
assert nk_plo == self.nktot, "PLOCAR is inconsistent with IBZKPT (number of k-points)"
assert nk_plo == self.nktot, "PLOCAR is inconsistent with IBZKPT (number of k-points). If you run VASP with symmetry make sure to use the h5 interface of the converter, i.e. have the locproj information written to vaspout.h5"

# FIXME: Reading from EIGENVAL is obsolete and should be
# removed completely.
# if not vasp_data.eigenval.eigs is None:
if False:
if vasp_data.eigenval.eigs is not None:
print("eigvals from EIGENVAL")
self.eigvals = vasp_data.eigenval.eigs
self.ferw = vasp_data.eigenval.ferw.transpose((2, 0, 1))

nk_eig = vasp_data.eigenval.nktot
assert nk_eig == self.nktot, "PLOCAR is inconsistent with EIGENVAL (number of k-points)"

# Check that the number of band is the same in PROJCAR and EIGENVAL
assert nb_plo == self.nband, "PLOCAR is inconsistent with EIGENVAL (number of bands)"
self.efermi = vasp_data.doscar.efermi
else:
print("eigvals from LOCPROJ")
self.eigvals = vasp_data.plocar.eigs
Expand Down Expand Up @@ -151,7 +147,7 @@ def debug_density_matrix(self):

# Spin factor
sp_fac = 2.0 if ns == 1 and self.nc_flag == False else 1.0

if self.nc_flag == False:
den_mat = np.zeros((ns, nproj, nproj), dtype=float)
overlap = np.zeros((ns, nproj, nproj), dtype=float)
Expand Down Expand Up @@ -184,9 +180,9 @@ def debug_density_matrix(self):
out += " "
out += ''.join(map("{0:12.7f}".format, dov))
print(out)



else:
print("!! WARNING !! Non Collinear Routine")
den_mat = np.zeros((ns, nproj, nproj), dtype=float)
Expand Down
3 changes: 3 additions & 0 deletions python/triqs_dft_tools/converters/plovasp/plotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ def ctrl_output(conf_pars, el_struct, ng):
* *nk*: number of `k`-points
* *nkibz*: number of `k`-points in IBZ
* *ns*: number of spin channels
* *nc_flag*: collinear/noncollinear case (False/True)
Expand All @@ -309,6 +311,7 @@ def ctrl_output(conf_pars, el_struct, ng):
# Construct the header dictionary
head_dict['ngroups'] = ng
head_dict['nk'] = el_struct.kmesh['nktot']
head_dict['nkibz'] = el_struct.kmesh['nkibz']
head_dict['ns'] = el_struct.nspin
head_dict['kvec1'] = list(el_struct.structure['kpt_basis'][:,0])
head_dict['kvec2'] = list(el_struct.structure['kpt_basis'][:,1])
Expand Down
44 changes: 23 additions & 21 deletions python/triqs_dft_tools/converters/plovasp/sc_dmft.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,26 @@ def is_vasp_running(vasp_pid):
pid_exists = mpi.bcast(pid_exists)
return pid_exists


def get_dft_energy():
"""
Reads energy from the last line of OSZICAR.
Reads DFT energy from the last line of Vasp's OSZICAR or from vasptriqs.h5
"""
with open('OSZICAR', 'r') as f:
nextline = f.readline()
while nextline.strip():
line = nextline
nextline = f.readline()
# print "OSZICAR: ", line[:-1]
h5_energy = False
if os.path.isfile('vaspout.h5'):
with HDFArchive('vaspout.h5', 'r') as h5:
if 'oszicar' in h5['intermediate/ion_dynamics']:
dft_energy = h5['intermediate/ion_dynamics/oszicar'][-1,1]
h5_energy = True

try:
# as backup use OSZICAR file
if not h5_energy:
with open('OSZICAR', 'r') as file:
nextline = file.readline()
while nextline.strip():
line = nextline
nextline = file.readline()
dft_energy = float(line.split()[2])
except ValueError:
print("Cannot read energy from OSZICAR, setting it to zero")
dft_energy = 0.0

return dft_energy

Expand All @@ -98,9 +102,8 @@ class bcolors:
YELLOW = '\033[93m'
RED = '\033[91m'
ENDC = '\033[0m'
#

# Main self-consistent cycle
#
def run_all(vasp_pid, dmft_cycle, cfg_file, n_iter, n_iter_dft, vasp_version):
"""
"""
Expand All @@ -117,15 +120,14 @@ def run_all(vasp_pid, dmft_cycle, cfg_file, n_iter, n_iter_dft, vasp_version):
mpi.barrier()
while is_vasp_lock_present():
time.sleep(1)
# if debug: print bcolors.YELLOW + " waiting: rank %s"%(mpi.rank) + bcolors.ENDC
if debug: print(bcolors.YELLOW + " waiting: rank %s"%(mpi.rank) + bcolors.ENDC)
if not is_vasp_running(vasp_pid):
mpi.report(" VASP stopped")
vasp_running = False
break

# Tell VASP to stop if the maximum number of iterations is reached


# Tell VASP to stop if the maximum number of iterations is reached

if debug: print(bcolors.MAGENTA + "rank %s"%(mpi.rank) + bcolors.ENDC)
err = 0
exc = None
Expand Down Expand Up @@ -161,7 +163,7 @@ def run_all(vasp_pid, dmft_cycle, cfg_file, n_iter, n_iter_dft, vasp_version):
# electron.F around line 644
iter_dft = 0

if vasp_version == 'standard':
if vasp_version == 'standard' or vasp_version == 'ncl':
copyfile(src='GAMMA',dst='GAMMA_recent')
while iter_dft < n_iter_dft:
# insert recalculation of GAMMA here
Expand Down Expand Up @@ -190,7 +192,7 @@ def run_all(vasp_pid, dmft_cycle, cfg_file, n_iter, n_iter_dft, vasp_version):
vasp_running = False
break
iter_dft += 1
if vasp_version == 'standard':
if vasp_version == 'standard' or vasp_version == 'ncl':
copyfile(src='GAMMA_recent',dst='GAMMA')
iter += 1
if iter == n_iter:
Expand Down Expand Up @@ -253,8 +255,8 @@ def main():
except KeyError:
vasp_version = 'standard'

if vasp_version != 'standard' and vasp_version != 'no_gamma_write':
raise Exception('vasp_version has to be standard or no_gamma_write')
#if vasp_version != 'standard' and vasp_version != 'no_gamma_write':
# raise Exception('vasp_version has to be standard or no_gamma_write')

# if len(sys.argv) > 1:
# vasp_path = sys.argv[1]
Expand Down
Loading

0 comments on commit 2a8acf4

Please sign in to comment.