Merge branch 'KCW_bugs-fix' into 'develop'

Few bug-fixes in KCW: should solve isseu  #494

See merge request QEF/q-e!1869
This commit is contained in:
Ye Luo 2022-06-03 16:30:30 +00:00
commit accec34683
7 changed files with 91 additions and 47 deletions

View File

@ -7,5 +7,5 @@ qe_install_targets(qe_kcw qe_kcw_exe qe_kcwpp_sh_exe qe_kcwpp_interp_exe)
add_custom_target(
kcw
DEPENDS pw pp w90 qe_kcw_exe qe_kcwpp_sh_exe qe_kcwpp_interp_exe
DEPENDS pw qe_pp_pw2wannier90_exe w90 qe_kcw_exe qe_kcwpp_sh_exe qe_kcwpp_interp_exe
COMMENT "Koopmans spectral functionals")

View File

@ -78,6 +78,7 @@ $ECHO " done"
PW_COMMAND="$PARA_PREFIX $BIN_DIR/pw.x $PARA_POSTFIX"
W90_COMMAND="$BIN_DIR/wannier90.x"
PW2W90_COMMAND="$PARA_PREFIX $BIN_DIR/pw2wannier90.x"
KCW_COMMAND_noPOSTFIX="$PARA_PREFIX $BIN_DIR/kcw.x"
KCW_COMMAND="$PARA_PREFIX $BIN_DIR/kcw.x $PARA_POSTFIX"
$ECHO
$ECHO " running pw.x as: $PW_COMMAND"
@ -423,5 +424,5 @@ K_POINTS crystal_b
EOF
$ECHO " Running the KI hamiltonian calculation for $PREFIX...\c"
$KCW_COMMAND -in $PREFIX.kcw-ham.in > $PREFIX.kcw-ham.out
$KCW_COMMAND_noPOSTFIX -in $PREFIX.kcw-ham.in > $PREFIX.kcw-ham.out
$ECHO " done"

View File

@ -77,6 +77,7 @@ $ECHO " done"
# how to run executables
PW_COMMAND="$PARA_PREFIX $BIN_DIR/pw.x $PARA_POSTFIX"
KCW_COMMAND="$PARA_PREFIX $BIN_DIR/kcw.x $PARA_POSTFIX"
KCW_COMMAND_noPOSTFIX="$PARA_PREFIX $BIN_DIR/kcw.x"
$ECHO
$ECHO " running pw.x as: $PW_COMMAND"
$ECHO " running kcw.x as: $KCW_COMMAND"
@ -206,5 +207,5 @@ KCW H2O KI hamiltonian
EOF
$ECHO " Running the KI hamiltonian calculation for $PREFIX...\c"
$KCW_COMMAND -in $PREFIX.kcw-ham.in > $PREFIX.kcw-ham.out
$KCW_COMMAND_noPOSTFIX -in $PREFIX.kcw-ham.in > $PREFIX.kcw-ham.out
$ECHO " done"

View File

@ -20,18 +20,19 @@ KCW stands for "Koopmans-compliant functionals in a Wannier representation". KCW
code which calculates quasiparticle energies of finite and extended systems using
[Koopmans-compliant functionals](https://journals.aps.org/prx/abstract/10.1103/PhysRevX.8.021051)
and [Maximally Localized Wannier Functions](http://journals.aps.org/prb/abstract/10.1103/PhysRevB.56.12847).
The code consists of 3 programs:
The details of this implementation are described [here](https://arxiv.org/abs/2202.08155).
The code consists of 3 modules specified by the "calculation" variable in CONTROL namelist:
1) an interface between Wannier90 and the KCW code (wann_to_kc.x)
1) interface between Wannier90 and the KCW code (calculation="wann_to_kc")
2) a program that computes the screening coefficients as described [here](https://pubs.acs.org/doi/abs/10.1021/acs.jctc.7b01116) (kc_screen.x)
2) calcuation of the screening coefficients (calculation="screen")
3) a program that computes the KC hamiltonian, interpolates it if needed, and finally diagonalizes it (kc_ham.x)
3) calculation, interpolation and diagonalization of the KC hamiltonian (calculation = "kc_ham")
KCW is developed and maintained by [Nicola Colonna](https://www.psi.ch/en/lns/people/nicola-colonna), [Riccardo de Gennaro](https://people.epfl.ch/riccardo.degennaro), and [Edward Linscott](https://people.epfl.ch/edward.linscott)
@Note
Still in development. This version of the code works with QE7.0
Still in development. This version of the code works with QE7.1
TODO list:
1) Symmetry: at the moment no symmetry are used.
@ -40,5 +41,6 @@ Still in development. This version of the code works with QE7.0
2) Initialize the xc-kernel and KC response as the spin-polarized one
also when nspin=1. This is needed to correctly define the perturbing
potentials. At the moment we do a nspin=2 calculation from the beginning
(not a big deal since the bottleneck is the LR calculation).
(not a big deal since the bottleneck is the LR calculation for which in
any case a spin-polarized response is needed).

View File

@ -51,6 +51,8 @@ SUBROUTINE convert_kpts_names()
ELSE
!
nks_bands = nkstot
ALLOCATE( xk_bands(3,nks_bands) )
ALLOCATE( wk_bands(nks_bands) )
xk_bands = xk
wk_bands = wk
!

View File

@ -38,9 +38,10 @@ MODULE io_kcw
! ... on a single proc.
!
USE mp, ONLY : mp_get, mp_sum, mp_rank, mp_size
#if defined __HDF5
USE hdf5_qe, ONLY : write_rho_hdf5, h5fclose_f, &
prepare_for_writing_final, add_attributes_hdf5, rho_hdf5_write
#if defined(__HDF5)
USE qeh5_base_module, ONLY : qeh5_file, qeh5_dataset, qeh5_openfile, qeh5_open_dataset, &
qeh5_add_attribute, qeh5_write_dataset, qeh5_close, qeh5_set_space, &
qeh5_set_file_hyperslab
#endif
USE fft_types
!
@ -64,7 +65,12 @@ MODULE io_kcw
io_group_id, io_group2, io_group3
INTEGER, EXTERNAL :: find_free_unit
!
#if defined(__HDF5)
TYPE (qeh5_file) :: h5file
TYPE (qeh5_dataset) :: rhowann_dset
!
#endif
!
my_group_id = mp_rank( inter_group_comm )
me_group = fft_desc%mype ; me_group2 = fft_desc%mype2 ; me_group3 = fft_desc%mype3
@ -80,12 +86,11 @@ MODULE io_kcw
rhounit = find_free_unit ()
!
IF ( ionode ) THEN
#if defined __HDF5
rho_file_hdf5 = TRIM( file_base ) // '.hdf5'
CALL prepare_for_writing_final(rho_hdf5_write, 0 ,rho_file_hdf5)
CALL add_attributes_hdf5(rho_hdf5_write,nr1,"nr1")
CALL add_attributes_hdf5(rho_hdf5_write,nr2,"nr2")
CALL add_attributes_hdf5(rho_hdf5_write,nr3,"nr3")
#if defined(__HDF5)
CALL qeh5_openfile(h5file, TRIM(file_base)//'.hdf5',action = 'write')
CALL qeh5_add_attribute( h5file%id, "nr1", nr1 )
CALL qeh5_add_attribute( h5file%id, "nr2", nr2 )
CALL qeh5_add_attribute( h5file%id, "nr3", nr3 )
#else
IF (rho_binary) OPEN (rhounit, FILE=rho_file, IOSTAT=ierr, FORM='unformatted')
IF (.NOT. rho_binary) OPEN (rhounit, FILE=rho_file, IOSTAT=ierr, FORM='formatted')
@ -93,7 +98,7 @@ MODULE io_kcw
#endif
END IF
!
#if !defined __HDF5
#if !defined(__HDF5)
IF ( ionode ) THEN
!
IF (rho_binary) THEN
@ -106,8 +111,17 @@ MODULE io_kcw
#endif
!
ALLOCATE( rho_plane( nr1*nr2 ) )
rho_plane = (0.D0, 0.D0)
ALLOCATE( kowner( nr3 ) )
!
#if defined(__HDF5)
IF ( ionode ) THEN
CALL qeh5_set_space ( rhowann_dset, rho_plane(1), 2, [nr1*nr2, nr3], MODE = 'f')
CALL qeh5_set_space ( rhowann_dset, rho_plane(1), 1, [nr1*nr2], MODE = 'm')
CALL qeh5_open_dataset (h5file, rhowann_dset, ACTION = 'write', NAME = 'rhowann' )
END IF
#endif
!
! ... find the index of the group (pool) that will write rho
!
io_group_id = 0
@ -164,8 +178,10 @@ MODULE io_kcw
CALL mp_get( rho_plane, rho_plane, me_group3, io_group3, kowner(k), k, fft_desc%comm3 )
!
IF ( ionode ) THEN
#if defined __HDF5
CALL write_rho_hdf5(rho_hdf5_write,k,rho_plane)
#if defined(__HDF5)
CALL qeh5_set_file_hyperslab ( rhowann_dset, OFFSET = [0,k-1], COUNT = [2*nr1*nr2,1] )
CALL qeh5_write_dataset ( rho_plane, rhowann_dset)
write(*,*) "NICOLA", rho_plane(1:3)
#else
!
IF (rho_binary) THEN
@ -187,8 +203,9 @@ MODULE io_kcw
DEALLOCATE( kowner )
!
IF ( ionode ) THEN
#if defined __HDF5
CALL h5fclose_f(rho_hdf5_write%file_id,ierr)
#if defined(__HDF5)
CALL qeh5_close (rhowann_dset)
CALL qeh5_close (h5file)
#else
CLOSE (rhounit, STATUS='keep')
#endif
@ -209,9 +226,8 @@ MODULE io_kcw
USE io_global, ONLY : ionode, ionode_id
USE mp_images, ONLY : intra_image_comm
USE mp, ONLY : mp_put, mp_sum, mp_rank, mp_size
#if defined __HDF5
USE hdf5_qe, ONLY : read_rho_hdf5, read_attributes_hdf5, &
prepare_for_reading_final, h5fclose_f, rho_hdf5_write, hdf5_type
#if defined(__HDF5)
USE qeh5_base_module
#endif
USE fft_types
USE io_files, ONLY : check_file_exist
@ -232,11 +248,13 @@ MODULE io_kcw
INTEGER, ALLOCATABLE :: kowner(:)
LOGICAL :: exst
INTEGER, EXTERNAL :: find_free_unit
#if defined(__HDF5)
TYPE(hdf5_type),ALLOCATABLE :: h5desc
#endif
CHARACTER(LEN=256) :: string
CHARACTER(LEN=10) :: rho_extension
#if defined(__HDF5)
INTEGER :: nr1_, nr2_, nr3_
TYPE (qeh5_file) :: h5file
TYPE (qeh5_dataset) :: rhowann_dset
#endif
!
me_group = fft_desc%mype ; me_group2 = fft_desc%mype2 ; me_group3 = fft_desc%mype3
nproc_group = fft_desc%nproc ; nproc_group2 = fft_desc%nproc2 ; nproc_group3 = fft_desc%nproc3
@ -259,29 +277,45 @@ MODULE io_kcw
#endif
!
IF ( ionode ) THEN
#if defined (__HDF5)
ALLOCATE ( h5desc)
CALL prepare_for_reading_final(h5desc, 0 ,rho_file_hdf5)
CALL read_attributes_hdf5(h5desc, nr1_,"nr1")
CALL read_attributes_hdf5(h5desc, nr2_,"nr2")
CALL read_attributes_hdf5(h5desc, nr3_,"nr3")
#if defined(__HDF5)
!ALLOCATE ( h5desc)
!CALL prepare_for_reading_final(h5desc, 0 ,rho_file_hdf5)
!CALL read_attributes_hdf5(h5desc, nr1_,"nr1")
!CALL read_attributes_hdf5(h5desc, nr2_,"nr2")
!CALL read_attributes_hdf5(h5desc, nr3_,"nr3")
!nr = [nr1_,nr2_,nr3_]
CALL qeh5_openfile( h5file, TRIM(rho_file_hdf5), ACTION = 'read', ERROR = ierr)
CALL errore( 'read_rhowann', 'cannot open ' // TRIM( rho_file_hdf5 ) // ' file for reading', ierr )
CALL qeh5_read_attribute (h5file%id, "nr1", nr1_)
CALL qeh5_read_attribute (h5file%id, "nr2", nr2_)
CALL qeh5_read_attribute (h5file%id, "nr3", nr3_)
nr = [nr1_,nr2_,nr3_]
#else
IF (rho_binary) OPEN (rhounit, FILE=rho_file, IOSTAT=ierr, FORM='unformatted', STATUS='old')
IF (.NOT. rho_binary) OPEN (rhounit, FILE=rho_file, IOSTAT=ierr, FORM='formatted', STATUS='old')
CALL errore( 'read_rho_xml', 'cannot open ' // TRIM( rho_file ) // ' file for reading', ierr )
CALL errore( 'read_rhowann', 'cannot open ' // TRIM( rho_file ) // ' file for reading', ierr )
IF (rho_binary) READ(rhounit) nr(1), nr(2), nr(3)
IF (.NOT. rho_binary) READ(rhounit,*) string,nr(1), nr(2), nr(3)
#endif
!
IF ( nr1 /= nr(1) .OR. nr2 /= nr(2) .OR. nr3 /= nr(3) ) &
CALL errore( 'read_rhowann', 'dimensions do not match', 1 )
!
!
END IF
!
CALL mp_bcast( nr, ionode_id, intra_image_comm )
!
IF ( nr1 /= nr(1) .OR. nr2 /= nr(2) .OR. nr3 /= nr(3) ) &
CALL errore( 'read_rhowann', 'dimensions do not match', 1 )
!
!
ALLOCATE( rho_plane( nr1*nr2 ) )
ALLOCATE( kowner( nr3 ) )
!
#if defined(__HDF5)
IF (ionode ) THEN
CALL qeh5_open_dataset( h5file, rhowann_dset, ACTION = 'read', NAME = 'rhowann')
CALL qeh5_set_space ( rhowann_dset, rho_plane(1), RANK = 1, DIMENSIONS = [nr1*nr2], MODE = 'm')
ENDIF
#endif
!
DO ip = 1, nproc_group3
!
kowner( (fft_desc%i0r3p(ip)+1):(fft_desc%i0r3p(ip)+fft_desc%nr3p(ip)) ) = ip - 1
@ -300,8 +334,10 @@ MODULE io_kcw
! ... only ionode reads the charge planes
!
IF ( ionode ) THEN
#if defined __HDF5
CALL read_rho_hdf5(h5desc , k,rho_plane)
#if defined(__HDF5)
!CALL read_rho_hdf5(h5desc , k,rho_plane)
CALL qeh5_set_file_hyperslab (rhowann_dset, OFFSET = [0,k-1], COUNT = [2*nr1*nr2,1] )
CALL qeh5_read_dataset (rho_plane, rhowann_dset )
#else
IF (rho_binary) THEN
READ(rhounit) k_
@ -336,9 +372,11 @@ MODULE io_kcw
!
IF ( ionode ) THEN
!
#if defined __HDF5
CALL h5fclose_f(h5desc%file_id,ierr)
DEALLOCATE ( h5desc)
#if defined(__HDF5)
CALL qeh5_close(rhowann_dset)
CALL qeh5_close(h5file)
!CALL h5fclose_f(h5desc%file_id,ierr)
!DEALLOCATE ( h5desc)
#else
CLOSE (rhounit)
#endif

View File

@ -122,7 +122,7 @@ subroutine kcw_setup_ham
call setup_dmuxc()
CALL kcw_R_points ()
CALL read_alpha ()
alpha_final_full = alpha_final
IF (nkstot/nspin == 1 ) alpha_final_full = alpha_final
! CALL setup_dgc()
ENDIF
!