Skip to content

Commit c79ec1b

Browse files
phibeckthe-hampel
authored andcommitted
[fix] WannierBerri velocity updates
This commit simplifies the WannierBerri/numpy import, and fixes an issue in the velocity matrix elements in the Wannier gauge.
1 parent f8fed7d commit c79ec1b

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

python/triqs_dft_tools/sumk_dft_transport.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
##########################################################################
2525
import sys
26+
try: # try wannierberri import - needs to be placed before importing numpy
27+
import wannierberri as wb
28+
except ImportError:
29+
pass
2630
import numpy
2731
from warnings import warn
2832
from triqs.gf import *
@@ -253,23 +257,17 @@ def recompute_w90_input_on_different_mesh(sum_k, seedname, nk_optics, pathname='
253257
inverse_mass = None
254258

255259
if mpi.is_master_node():
256-
# try wannierberri import
257-
try:
258-
import wannierberri as wb
259-
except ImportError:
260-
print('ImportError: WannierBerri needs to be installed to run test "Py_w90_optics_Sr2RuO4"')
260+
if 'wannierberri' not in sys.modules:
261+
print('ImportError: WannierBerri needs to be installed to run optics calculations with Wannier90')
261262
try:
262263
mpi.MPI.COMM_WORLD.Abort(1)
263264
except:
264265
sys.exit()
265266
# initialize WannierBerri system
266267
shift_gamma = numpy.array([0.0, 0.0, 0.0])
267-
# wberri = wb.System_w90(pathname + seedname, berry=True, fft='numpy')
268-
# WannierBerri uses python multiprocessing which might conflict with mpi.
269-
# if there's a segfault, uncomment the following line
270-
wberri = wb.System_w90(pathname + seedname, berry=True, fftlib='numpy', npar=16)
268+
wberri = wb.System_w90(pathname + seedname, berry=True)
271269
grid = wb.Grid(wberri, NKdiv=1, NKFFT=[nk_x, nk_y, nk_z])
272-
dataK = wb.data_K.Data_K(wberri, dK=shift_gamma, grid=grid, fftlib='numpy')
270+
dataK = wb.data_K.Data_K_R(wberri, dK=shift_gamma, grid=grid)
273271

274272
assert dataK.HH_K.shape == hopping[:, 0, :, :].shape, 'wberri / wannier Hamiltonian has different number of orbitals than SumK object. Disentanglement is not supported as of now.'
275273

@@ -327,11 +325,12 @@ def _commutator(A, B):
327325
# in the orbital basis
328326
# vw_alpha = Hw_alpha + i [Hw, Aw_alpha]
329327
elif oc_basis == 'w':
330-
# first term, taken from
331-
# github.com/wannier-berri/wannier-berri/blob/2d3982331c02775f5ee033c664849d5f2d41d0c1/wannierberri/data_K.py#L687
332-
Hw_alpha = wb.data_K.Data_K_R._R_to_k_H(dataK, dataK.Ham_R, der=1, hermitian=True)
328+
# first term
329+
Hw_R = dataK.get_R_mat('Ham').copy()
330+
Hw_alpha = dataK.rvec.R_to_k(Hw_R, hermitian=True, der=1)[dataK.select_K]
333331
# second term
334-
Aw_alpha = dataK.fft_R_to_k(dataK.get_R_mat('AA'), hermitian=True)
332+
Aw_R = dataK.get_R_mat('AA').copy()
333+
Aw_alpha = dataK.rvec.R_to_k(Aw_R, hermitian=True)[dataK.select_K]
335334
c_Hw_Aw_alpha = _commutator(hopping[:, 0, :, :], Aw_alpha)
336335
velocities_k = (Hw_alpha + 1j * c_Hw_Aw_alpha) / HARTREETOEV / BOHRTOANG
337336

0 commit comments

Comments
 (0)