Skip to content

Commit

Permalink
add logic to read total number of bands (to be used with exclude_bands)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Jackson committed Jan 15, 2025
1 parent 5ba477c commit 7028621
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
35 changes: 33 additions & 2 deletions src/readwrite.F90
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module w90_readwrite
public :: w90_readwrite_read_mp_grid
public :: w90_readwrite_read_num_bands
public :: w90_readwrite_read_num_wann
public :: w90_readwrite_read_total_bands
public :: w90_readwrite_read_system
public :: w90_readwrite_read_units
public :: w90_readwrite_read_verbosity
Expand Down Expand Up @@ -191,6 +192,31 @@ subroutine w90_readwrite_read_num_wann(settings, num_wann, error, comm)
endif
end subroutine w90_readwrite_read_num_wann

! fixme
subroutine w90_readwrite_read_total_bands(settings, num_wann, error, comm)
use w90_error, only: w90_error_type, set_error_input
implicit none
integer, intent(inout) :: num_wann
type(w90_error_type), allocatable, intent(out) :: error
type(w90_comm_type), intent(in) :: comm
type(settings_type), intent(inout) :: settings

logical :: found
num_wann = 0

call w90_readwrite_get_keyword(settings, 'total_bands', found, error, comm, i_value=num_wann)
if (allocated(error)) return

!if (.not. found) then
! call set_error_input(error, 'Error: You must specify num_wann', comm)
! return
!endif
if (num_wann <= 0) then
call set_error_input(error, 'Error: num_wann must be greater than zero', comm)
return
endif
end subroutine w90_readwrite_read_total_bands

subroutine w90_readwrite_read_distk(settings, distk, nkin, error, comm)
! read distribution of kpoints
use w90_error, only: w90_error_type, set_error_input, set_error_alloc
Expand Down Expand Up @@ -1155,6 +1181,7 @@ subroutine w90_readwrite_clear_keywords(settings, comm)
call w90_readwrite_get_keyword(settings, 'spinors', found, error, comm)
call w90_readwrite_get_keyword(settings, 'symmetrize_eps', found, error, comm)
call w90_readwrite_get_keyword(settings, 'timing_level', found, error, comm)
call w90_readwrite_get_keyword(settings, 'total_bands', found, error, comm)
call w90_readwrite_get_keyword(settings, 'tran_easy_fix', found, error, comm)
call w90_readwrite_get_keyword(settings, 'tran_energy_step', found, error, comm)
call w90_readwrite_get_keyword(settings, 'tran_group_threshold', found, error, comm)
Expand Down Expand Up @@ -1215,7 +1242,11 @@ subroutine w90_readwrite_clear_keywords(settings, comm)
call w90_readwrite_get_range_vector(settings, 'shell_list', found, lx, .true., error, comm)
if (allocated(lxa)) deallocate (lxa); allocate (lxa(lx))
call w90_readwrite_get_range_vector(settings, 'shell_list', found, lx, .false., error, comm, lxa)
call w90_readwrite_read_exclude_bands(settings, lxa, lx, error, comm)
call w90_readwrite_get_range_vector(settings, 'exclude_bands', found, lx, .true., error, comm)
if (allocated(lxa)) deallocate (lxa); allocate (lxa(lx))
call w90_readwrite_get_range_vector(settings, 'exclude_bands', found, lx, .false., error, comm, lxa)

!call w90_readwrite_read_exclude_bands(settings, lxa, lx, error, comm)
! ends list of wannier.x keywords

! keywords for postw90.x
Expand Down Expand Up @@ -3713,7 +3744,7 @@ subroutine w90_readwrite_get_projections(settings, num_proj, atom_data, num_wann
endif

elseif (allocated(settings%entries)) then ! reading from setopt
do loop = 1, settings%num_entries ! this means the first occurance of the variable in settings is used
do loop = 1, settings%num_entries
if (settings%entries(loop)%keyword == 'projections') then
counter = counter + 1
if (settings%entries(loop)%txtdata == 'bohr') lconvert = .true.
Expand Down
25 changes: 20 additions & 5 deletions src/wannier90_readwrite.F90
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ subroutine w90_wannier90_readwrite_read_special(settings, atom_data, kmesh_input
kpt_latt, wann_control, proj, proj_input, &
select_proj, w90_system, w90_calculation, &
real_lattice, bohr, mp_grid, num_bands, &
exclude_bands, &
num_kpts, num_proj, num_wann, gamma_only, &
lhasproj, use_bloch_phases, distk, stdout, &
error, comm)
Expand Down Expand Up @@ -83,6 +84,7 @@ subroutine w90_wannier90_readwrite_read_special(settings, atom_data, kmesh_input
type(wann_control_type), intent(inout) :: wann_control
type(w90_calculation_type), intent(inout) :: w90_calculation !check if really needed??

integer, allocatable, intent(inout) :: exclude_bands(:)
integer, allocatable, intent(inout) :: distk(:)
integer, intent(inout) :: mp_grid(3)
integer, intent(inout) :: num_bands
Expand All @@ -103,6 +105,7 @@ subroutine w90_wannier90_readwrite_read_special(settings, atom_data, kmesh_input
logical :: disentanglement
real(kind=dp) :: inv_lattice(3, 3)
integer :: ip
integer :: num_exclude_bands, total_bands

call w90_readwrite_read_lattice(settings, real_lattice, bohr, error, comm)
if (allocated(error)) return
Expand All @@ -113,8 +116,21 @@ subroutine w90_wannier90_readwrite_read_special(settings, atom_data, kmesh_input
call w90_readwrite_read_num_wann(settings, num_wann, error, comm)
if (allocated(error)) return

call w90_readwrite_read_num_bands(settings, .false., num_bands, num_wann, stdout, error, comm)
call w90_readwrite_read_exclude_bands(settings, exclude_bands, num_exclude_bands, error, comm)
if (allocated(error)) return

total_bands = 0
call w90_readwrite_read_total_bands(settings, total_bands, error, comm)
if (allocated(error)) return

if (total_bands > 0) then
num_bands = total_bands - num_exclude_bands
else
! fixme, flag up that it is a mistake to set total bands and num_bands
call w90_readwrite_read_num_bands(settings, .false., num_bands, num_wann, stdout, error, comm)
if (allocated(error)) return
endif

disentanglement = (num_bands > num_wann)

num_proj = num_wann !default, no projections specified
Expand Down Expand Up @@ -155,7 +171,7 @@ end subroutine w90_wannier90_readwrite_read_special

!================================================!
subroutine w90_wannier90_readwrite_read(settings, band_plot, dis_control, dis_spheres, &
dis_manifold, exclude_bands, fermi_energy_list, &
dis_manifold, fermi_energy_list, &
fermi_surface_data, &
output_file, wvfn_read, wann_control, &
real_space_ham, kpoint_path, w90_system, &
Expand Down Expand Up @@ -202,7 +218,6 @@ subroutine w90_wannier90_readwrite_read(settings, band_plot, dis_control, dis_sp
type(ws_region_type), intent(inout) :: ws_region
type(wvfn_read_type), intent(inout) :: wvfn_read

integer, allocatable, intent(inout) :: exclude_bands(:)
integer, intent(inout) :: num_bands
integer, intent(inout) :: num_kpts
integer, intent(inout) :: num_wann
Expand Down Expand Up @@ -259,8 +274,8 @@ subroutine w90_wannier90_readwrite_read(settings, band_plot, dis_control, dis_sp
!call w90_readwrite_read_num_wann(settings, num_wann, error, comm)
!if (allocated(error)) return

call w90_readwrite_read_exclude_bands(settings, exclude_bands, num_exclude_bands, error, comm)
if (allocated(error)) return
!call w90_readwrite_read_exclude_bands(settings, exclude_bands, num_exclude_bands, error, comm)
!if (allocated(error)) return

!call w90_readwrite_read_num_bands(settings, .false., num_bands, num_wann, stdout, error, comm)
!if (allocated(error)) return
Expand Down

0 comments on commit 7028621

Please sign in to comment.