Skip to content

Commit de701d1

Browse files
committed
use IBZ kpoint list for writing GAMMA vaspgamma.h5
* 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 * write n_k_ibz into seed.ctrl json file * change ref h5 files for VASP tests by adding n_k_ibz * add new svo converter test
1 parent d4b129f commit de701d1

File tree

12 files changed

+101
-11
lines changed

12 files changed

+101
-11
lines changed

python/triqs_dft_tools/converters/plovasp/elstruct.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ElectronicStructure:
3939
4040
- *natom* (int) : total number of atoms
4141
- *nktot* (int) : total number of `k`-points
42+
- *nkibz* (int) : number of `k`-points in IBZ
4243
- *nband* (int) : total number of bands
4344
- *nspin* (int) : spin-polarization
4445
- *nc_flag* (True/False) : non-collinearity flag
@@ -58,8 +59,9 @@ def __init__(self, vasp_data):
5859
self.natom = vasp_data.poscar.nq
5960
self.type_of_ion = vasp_data.poscar.type_of_ion
6061
self.nktot = vasp_data.kpoints.nktot
62+
self.nkibz = vasp_data.kpoints.nkibz
6163

62-
self.kmesh = {'nktot': self.nktot}
64+
self.kmesh = {'nktot': self.nktot, 'nkibz': self.nkibz}
6365
self.kmesh['kpoints'] = vasp_data.kpoints.kpts
6466
# VASP.6.
6567
self.nc_flag = vasp_data.plocar.nc_flag
@@ -86,7 +88,7 @@ def __init__(self, vasp_data):
8688

8789
# Check that the number of k-points is the same in all files
8890
_, ns_plo, nk_plo, nb_plo = vasp_data.plocar.plo.shape
89-
assert nk_plo == self.nktot, "PLOCAR is inconsistent with IBZKPT (number of k-points)"
91+
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"
9092

9193
# FIXME: Reading from EIGENVAL is obsolete and should be
9294
# removed completely.

python/triqs_dft_tools/converters/plovasp/plotools.py

+3
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def ctrl_output(conf_pars, el_struct, ng):
289289
290290
* *nk*: number of `k`-points
291291
292+
* *nkibz*: number of `k`-points in IBZ
293+
292294
* *ns*: number of spin channels
293295
294296
* *nc_flag*: collinear/noncollinear case (False/True)
@@ -309,6 +311,7 @@ def ctrl_output(conf_pars, el_struct, ng):
309311
# Construct the header dictionary
310312
head_dict['ngroups'] = ng
311313
head_dict['nk'] = el_struct.kmesh['nktot']
314+
head_dict['nkibz'] = el_struct.kmesh['nkibz']
312315
head_dict['ns'] = el_struct.nspin
313316
head_dict['kvec1'] = list(el_struct.structure['kpt_basis'][:,0])
314317
head_dict['kvec2'] = list(el_struct.structure['kpt_basis'][:,1])

python/triqs_dft_tools/converters/plovasp/vaspio.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import numpy as np
4141
import re
4242
import os
43+
import time
4344
from h5 import HDFArchive
4445

4546
log = logging.getLogger('plovasp.vaspio')
@@ -79,6 +80,10 @@ def __init__(self, vasp_dir, read_all=True, efermi_required=True):
7980
if vasph5:
8081
log.warning("Reading from vaspout.h5")
8182
h5path = os.path.join(vasp_dir, 'vaspout.h5')
83+
# give VASP some time to write the file
84+
with HDFArchive(h5path, 'r') as archive:
85+
if 'locproj' not in archive['results']:
86+
time.sleep(2)
8287
self.plocar = h5Plocar(h5path)
8388
self.poscar = h5Poscar(h5path)
8489
self.kpoints = h5Kpoints(h5path)
@@ -401,7 +406,8 @@ class Kpoints:
401406
Class describing k-points and optionally tetrahedra.
402407
403408
Properties:
404-
- nktot (int) : total number of k-points in the IBZ
409+
- nktot (int) : total number of k-points in the BZ
410+
- nkibz (int) : number of k-points in the IBZ
405411
- kpts (numpy.array((nktot, 3), dtype=float)) : k-point vectors (fractional coordinates)
406412
- ntet (int) : total number of k-point tetrahedra
407413
- itet (numpy.array((ntet, 5), dtype=float) : array of tetrahedra
@@ -412,6 +418,7 @@ class Kpoints:
412418
def __init__(self):
413419
self.kpts = None
414420
self.nktot = None
421+
self.nkibz = None
415422
self.kwghts = None
416423

417424
#
@@ -441,6 +448,9 @@ def from_file(self, vasp_dir='./', ibz_filename='IBZKPT'):
441448
# Number of k-points
442449
line = next(ibz_file)
443450
self.nktot = int(line.strip().split()[0])
451+
# when reading from IBZKPT file we do not know the full number of k-points, i.e.
452+
# works only ISYM=-1
453+
self.nkibz = self.nktot
444454

445455
print()
446456
print(" {0:>26} {1:d}".format("Total number of k-points:", self.nktot))
@@ -716,7 +726,7 @@ def __init__(self, h5path):
716726
# h5path = './vasptriqs.h5'
717727
with HDFArchive(h5path, 'a') as archive:
718728
kpoints = archive['results/electron_eigenvalues']
719-
self.nkred = kpoints['kpoints']
729+
self.nkibz = kpoints['kpoints']
720730
self.kpts = kpoints['kpoint_coords_full']
721731
self.nktot = len(self.kpts)
722732
self.kwghts = kpoints['kpoints_symmetry_weight_full']
@@ -731,7 +741,7 @@ def __init__(self, h5path):
731741
self.ntet = 0
732742

733743
print()
734-
print(" {0:>26} {1:d}".format("Reduced number of k-points:", self.nkred))
744+
print(" {0:>26} {1:d}".format("Reduced number of k-points:", self.nkibz))
735745
print(" {0:>26} {1:d}".format("Total number of k-points:", self.nktot))
736746
print(" {0:>26} {1:d}".format("Total number of tetrahedra:", self.ntet))
737747

python/triqs_dft_tools/converters/vasp.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ def convert_dft_input(self):
158158

159159
ng = ctrl_head['ngroups']
160160
n_k = ctrl_head['nk']
161+
n_k_ibz = ctrl_head['nkibz']
162+
161163
# Note the difference in name conventions!
162164
SP = ctrl_head['ns'] - 1
163165
SO = ctrl_head['nc_flag']
@@ -387,7 +389,7 @@ def convert_dft_input(self):
387389
with HDFArchive(self.hdf_file,'a') as ar:
388390
if not (self.dft_subgrp in ar): ar.create_group(self.dft_subgrp)
389391
# The subgroup containing the data. If it does not exist, it is created. If it exists, the data is overwritten!
390-
things_to_save = ['energy_unit','n_k','k_dep_projection','SP','SO','charge_below','density_required',
392+
things_to_save = ['energy_unit','n_k', 'k_dep_projection','SP','SO','charge_below','density_required',
391393
'symm_op','n_shells','shells','n_corr_shells','corr_shells','use_rotations','rot_mat',
392394
'rot_mat_time_inv','n_reps','dim_reps','T','n_orbitals','proj_mat','bz_weights',
393395
'hopping','n_inequiv_shells', 'corr_to_inequiv', 'inequiv_to_corr','proj_or_hk',
@@ -401,6 +403,8 @@ def convert_dft_input(self):
401403
ar[self.misc_subgrp]['dft_fermi_weights'] = f_weights
402404
ar[self.misc_subgrp]['kpts_cart'] = kpts_cart
403405
ar[self.misc_subgrp]['band_window'] = band_window
406+
if n_k_ibz is not None:
407+
ar[self.misc_subgrp]['n_k_ibz'] = n_k_ibz
404408

405409
# Symmetries are used, so now convert symmetry information for *correlated* orbitals:
406410
self.convert_symmetry_input(ctrl_head, orbits=self.corr_shells, symm_subgrp=self.symmcorr_subgrp)

python/triqs_dft_tools/sumk_dft.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -2207,8 +2207,7 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
22072207
filename = 'dens_mat.dat'
22082208
elif dm_type == 'vasp':
22092209
# use new h5 interface to vasp by default, if not wanted specify dm_type='vasp' + filename='GAMMA'
2210-
# filename = 'vaspgamma.h5'
2211-
filename = 'GAMMA'
2210+
filename = 'vaspgamma.h5'
22122211
elif dm_type == 'elk':
22132212
filename = 'DMATDMFT.OUT'
22142213
elif dm_type == 'qe':
@@ -2229,12 +2228,17 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
22292228
if dm_type in ['vasp', 'qe']:
22302229
fermi_weights = 0
22312230
band_window = 0
2231+
n_k_ibz = self.n_k
22322232
if mpi.is_master_node():
22332233
with HDFArchive(self.hdf_file, 'r') as ar:
22342234
fermi_weights = ar['dft_misc_input']['dft_fermi_weights']
22352235
band_window = ar['dft_misc_input']['band_window']
2236+
2237+
if 'n_k_ibz' in ar['dft_misc_input']:
2238+
n_k_ibz = ar['dft_misc_input']['n_k_ibz']
22362239
fermi_weights = mpi.bcast(fermi_weights)
22372240
band_window = mpi.bcast(band_window)
2241+
n_k_ibz = mpi.bcast(n_k_ibz)
22382242

22392243
# Convert Fermi weights to a density matrix
22402244
dens_mat_dft = {}
@@ -2349,8 +2353,13 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
23492353
fout.write("\n")
23502354
fout.close()
23512355
elif dm_type == 'vasp':
2352-
if kpts_to_write is None:
2356+
if kpts_to_write is None and self.n_k == n_k_ibz:
23532357
kpts_to_write = np.arange(self.n_k)
2358+
elif kpts_to_write is None and n_k_ibz < self.n_k:
2359+
# If the number of IBZ k-points is less than the total number of k-points,
2360+
# then we only write the IBZ k-points, which are the first n_k_ibz k-points
2361+
# in VASP
2362+
kpts_to_write = np.arange(n_k_ibz)
23542363
else:
23552364
assert np.min(kpts_to_write) >= 0 and np.max(kpts_to_write) < self.n_k
23562365

@@ -2359,8 +2368,12 @@ def calc_density_correction(self, filename=None, dm_type=None, spinave=False, kp
23592368
if mpi.is_master_node():
23602369
if filename == 'vaspgamma.h5':
23612370
with HDFArchive('vaspgamma.h5', 'w') as vasp_h5:
2362-
vasp_h5['band_window'] = band_window
2363-
vasp_h5['deltaN'] = deltaN
2371+
# only store the ibz kpoints in the h5
2372+
bnd_win_towrite = [band_window[0][:n_k_ibz,:]]
2373+
vasp_h5['band_window'] = bnd_win_towrite
2374+
vasp_h5.create_group('deltaN')
2375+
vasp_h5['deltaN']['up'] = deltaN['up'][:n_k_ibz]
2376+
vasp_h5['deltaN']['down'] = deltaN['down'][:n_k_ibz]
23642377
else:
23652378
with open(filename, 'w') as f:
23662379
f.write(" -1 -1 ! Number of k-points, default number of bands\n") # % len(kpts_to_write))
2.01 KB
Binary file not shown.
2.01 KB
Binary file not shown.
2.01 KB
Binary file not shown.

test/python/plovasp/converter/svo.cfg

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[General]
2+
BASENAME = converter/svo
3+
4+
[Group 1]
5+
SHELLS = 1
6+
NORMALIZE = True
7+
EWINDOW = -1.4 2.0
8+
9+
[Shell 1]
10+
LSHELL = 2
11+
IONS = 2
12+
13+
TRANSFORM = 1.0 0.0 0.0 0.0 0.0
14+
0.0 1.0 0.0 0.0 0.0
15+
0.0 0.0 0.0 1.0 0.0
16+
101 KB
Binary file not shown.
1.49 MB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
import os
3+
import rpath
4+
_rpath = os.path.dirname(rpath.__file__) + '/'
5+
6+
from triqs_dft_tools.converters.plovasp.converter import generate_and_output_as_text
7+
from triqs_dft_tools.converters import VaspConverter
8+
import mytest
9+
10+
################################################################################
11+
#
12+
# TestConverterOneSite
13+
#
14+
################################################################################
15+
class TestConverterSVO(mytest.MyTestCase):
16+
"""
17+
Function:
18+
19+
def generate_and_output_as_text(pars, el_struct)
20+
and
21+
VaspConverter
22+
23+
Scenarios:
24+
25+
- Parse config file and produce a correct converted h5-file
26+
"""
27+
# Scenario 1
28+
def test_convert_svo(self):
29+
generate_and_output_as_text(_rpath + 'svo.cfg', _rpath + 'svo/')
30+
31+
test_file = _rpath + 'svo.test.h5'
32+
converter = VaspConverter(filename=_rpath + 'svo',
33+
hdf_filename=test_file)
34+
35+
converter.convert_dft_input()
36+
37+
expected_file = _rpath + 'svo.ref.h5'
38+
self.assertH5FileEqual(test_file, expected_file)
39+
40+
if __name__ == '__main__':
41+
import unittest
42+
unittest.main(verbosity=2, buffer=False)

0 commit comments

Comments
 (0)