forked from wannier-developers/wannier90
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadwrite.F90
4713 lines (4186 loc) · 195 KB
/
readwrite.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!-*- mode: F90 -*-!
!------------------------------------------------------------!
! This file is distributed as part of the Wannier90 code and !
! under the terms of the GNU General Public License. See the !
! file `LICENSE' in the root directory of the Wannier90 !
! distribution, or http://www.gnu.org/copyleft/gpl.txt !
! !
! The webpage of the Wannier90 code is www.wannier.org !
! !
! The Wannier90 code is hosted on GitHub: !
! !
! https://github.com/wannier-developers/wannier90 !
!------------------------------------------------------------!
! !
! w90_readwrite: input parsing and information printout !
! routines for input/output for data used/needed by !
! *both* wannier90.x and postw90.x !
! !
!------------------------------------------------------------!
module w90_readwrite
!! Common read/write routines for data needed by both
!! wannier90.x and postw90.x executables
use w90_constants, only: dp, maxlen
use w90_types
use w90_comms, only: w90_comm_type, mpisize
implicit none
private
public :: w90_readwrite_chkpt_dist
public :: w90_readwrite_clean_infile
public :: w90_readwrite_clear_keywords
public :: w90_readwrite_dealloc
public :: w90_readwrite_get_block_length
public :: w90_readwrite_get_centre_constraints
public :: w90_readwrite_get_convention_type
public :: w90_readwrite_get_projections
public :: w90_readwrite_get_range_vector
public :: w90_readwrite_get_smearing_index
public :: w90_readwrite_get_smearing_type
public :: w90_readwrite_get_vector_length
public :: w90_readwrite_in_file
public :: w90_readwrite_read_algorithm_control
public :: w90_readwrite_read_atoms
public :: w90_readwrite_read_chkpt
public :: w90_readwrite_read_chkpt_header
public :: w90_readwrite_read_chkpt_matrices
public :: w90_readwrite_read_dis_manifold
public :: w90_readwrite_read_distk
public :: w90_readwrite_read_eigvals
public :: w90_readwrite_read_exclude_bands
public :: w90_readwrite_read_fermi_energy
public :: w90_readwrite_read_final_alloc
public :: w90_readwrite_read_gamma_only
public :: w90_readwrite_read_kmesh_data
public :: w90_readwrite_read_kpath
public :: w90_readwrite_read_kpoints
public :: w90_readwrite_read_explicit_kpath
public :: w90_readwrite_read_lattice
public :: w90_readwrite_read_mp_grid
public :: w90_readwrite_read_num_bands
public :: w90_readwrite_read_num_wann
public :: w90_readwrite_read_system
public :: w90_readwrite_read_total_bands
public :: w90_readwrite_read_units
public :: w90_readwrite_read_verbosity
public :: w90_readwrite_read_ws_data
public :: w90_readwrite_set_kmesh
public :: w90_readwrite_write_header
private :: w90_readwrite_set_atoms
public :: w90_readwrite_get_keyword
public :: w90_readwrite_get_keyword_block
public :: w90_readwrite_get_keyword_vector
public :: expand_settings
public :: init_settings
contains
!================================================!
subroutine w90_readwrite_read_verbosity(settings, print_output, svd_omega, error, comm)
!! read verbosity "iprint" and timing "timing_level" variables
!! if iprint>2 svd_omega printing is enabled
!! printing is supressed on all non-root MPI ranks
use w90_error, only: w90_error_type
use w90_comms, only: mpirank
implicit none
logical, intent(inout) :: svd_omega
type(print_output_type), intent(inout) :: print_output
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
integer :: unlucky_rank
logical :: found
call w90_readwrite_get_keyword(settings, 'timing_level', found, error, comm, &
i_value=print_output%timing_level)
if (allocated(error)) return
! special test case; use the timing_level variable to
! communicate a kill to remote process, testing error handling
call w90_readwrite_get_keyword(settings, 'unlucky', found, error, comm, i_value=unlucky_rank)
if (found) then
if (unlucky_rank > 0) then
print_output%timing_level = -unlucky_rank
endif
endif
call w90_readwrite_get_keyword(settings, 'iprint', found, error, comm, &
i_value=print_output%iprint)
if (allocated(error)) return
if (print_output%iprint >= 2) svd_omega = .true. ! a printout that does not have its own option flag
if (mpirank(comm) /= 0) print_output%iprint = 0 ! supress printing non-rank-0
end subroutine w90_readwrite_read_verbosity
subroutine w90_readwrite_read_algorithm_control(settings, optimisation, error, comm)
!! reads the "optimisation" flag
use w90_error, only: w90_error_type
implicit none
integer, intent(inout) :: optimisation
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
type(settings_type), intent(inout) :: settings
logical :: found
call w90_readwrite_get_keyword(settings, 'optimisation', found, error, comm, &
i_value=optimisation)
if (allocated(error)) return
end subroutine w90_readwrite_read_algorithm_control
subroutine w90_readwrite_read_units(settings, lenconfac, length_unit, energy_unit, bohr, error, &
comm)
!! reads the "energy_unit" and "length_unit" (valid: "ang" or "bohr") variables
use w90_error, only: w90_error_type, set_error_input
implicit none
character(len=*), intent(inout) :: energy_unit
character(len=*), intent(inout) :: length_unit
real(kind=dp), intent(in) :: bohr
real(kind=dp), intent(inout) :: lenconfac
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
integer :: ic
logical :: found
call w90_readwrite_get_keyword(settings, 'energy_unit', found, error, comm, c_value=energy_unit)
if (allocated(error)) return
call w90_readwrite_get_keyword(settings, 'length_unit', found, error, comm, c_value=length_unit)
if (allocated(error)) return
if (found) then
if (length_unit .ne. 'ang' .and. length_unit .ne. 'bohr') then
call set_error_input(error, &
'Error: value of length_unit not recognised in w90_readwrite_read_units', comm)
return
else if (length_unit .eq. 'bohr') then
lenconfac = 1.0_dp/bohr
endif
endif
! Length unit (ang --> Ang, bohr --> Bohr) set to uppercase for printout
ic = ichar(length_unit(1:1))
if ((ic .ge. ichar('a')) .and. (ic .le. ichar('z'))) &
length_unit(1:1) = char(ic + ichar('Z') - ichar('z'))
end subroutine w90_readwrite_read_units
subroutine w90_readwrite_read_num_wann(settings, num_wann, error, comm)
!! reads the number of wannier functions "num_wann" (mandatory input)
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
call w90_readwrite_get_keyword(settings, 'num_wann', 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
else 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_num_wann
subroutine w90_readwrite_read_total_bands(settings, total_bands, error, comm)
!! read the "total_bands" variable
!! this is a convenience for combination with an "exclude_bands" to evaluate num_bands
use w90_error, only: w90_error_type, set_error_input
implicit none
integer, intent(inout) :: total_bands
type(w90_error_type), allocatable, intent(out) :: error
type(w90_comm_type), intent(in) :: comm
type(settings_type), intent(inout) :: settings
logical :: found
total_bands = 0
call w90_readwrite_get_keyword(settings, 'total_bands', found, error, comm, i_value=total_bands)
if (allocated(error)) return
end subroutine w90_readwrite_read_total_bands
subroutine w90_readwrite_read_distk(settings, distk, nkin, error, comm)
!! Read MPI distribution of k-points
!! The array to be read must have num_kpt entries, with each entry being
!! the MPI rank to which each k-point is assigned
use w90_error, only: w90_error_type, set_error_input, set_error_alloc
implicit none
integer, allocatable, intent(inout) :: distk(:)
integer, intent(in) :: nkin
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
integer :: nk
logical :: found
found = .false.
call w90_readwrite_get_range_vector(settings, 'distk', found, nk, .true., error, comm)
if (allocated(error)) return
if (found) then
if (nk /= nkin) then
call set_error_input(error, 'Error: incorrect length of k-distribution (distk)', comm)
return
endif
allocate (distk(nkin))
call w90_readwrite_get_range_vector(settings, 'distk', found, nk, .false., error, comm, distk)
if (allocated(error)) return
else
! fixme JJ, some output might be helpful here
allocate (distk(nkin))
distk = 0 ! default to no distribution if not specified
end if
endsubroutine w90_readwrite_read_distk
subroutine w90_readwrite_read_exclude_bands(settings, exclude_bands, num_exclude_bands, error, &
comm)
!! Read (and allocate) excluded_bands list "exclude_bands"
use w90_error, only: w90_error_type, set_error_input, set_error_alloc
implicit none
integer, allocatable, intent(inout) :: exclude_bands(:)
integer, intent(out) :: num_exclude_bands
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
integer :: ierr
logical :: found = .false.
num_exclude_bands = 0
call w90_readwrite_get_range_vector(settings, 'exclude_bands', found, num_exclude_bands, &
.true., error, comm)
if (allocated(error)) return
if (found) then
if (num_exclude_bands < 1) then
call set_error_input(error, 'Error: problem reading exclude_bands', comm)
return
endif
allocate (exclude_bands(num_exclude_bands), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, &
'Error allocating exclude_bands in w90_readwrite_read_exclude_bands', comm)
return
endif
call w90_readwrite_get_range_vector(settings, 'exclude_bands', found, num_exclude_bands, &
.false., error, comm, exclude_bands)
if (allocated(error)) return
if (any(exclude_bands < 1)) then
call set_error_input(error, 'Error: exclude_bands must contain positive numbers', comm)
return
endif
end if
end subroutine w90_readwrite_read_exclude_bands
subroutine w90_readwrite_read_num_bands(settings, pw90_effective_model, num_bands, num_wann, &
error, comm)
!! Read the number of bands ("num_bands")
!! If not specified (and exclude_bands and total_bands are not both provided), defaults to num_wann
use w90_error, only: w90_error_type, set_error_input
implicit none
integer, intent(in) :: num_wann
integer, intent(inout) :: num_bands
logical, intent(in) :: pw90_effective_model
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
integer :: i_temp
logical :: found
call w90_readwrite_get_keyword(settings, 'num_bands', found, error, comm, i_value=i_temp)
if (allocated(error)) return
! in the pw90_effective_model case, this variable is ignored
if (.not. pw90_effective_model) then
if (found) then
num_bands = i_temp
if (num_bands < num_wann) then
call set_error_input(error, &
'Error: num_bands must be greater than or equal to num_wann', comm)
return
endif
else
num_bands = num_wann
endif
endif
end subroutine w90_readwrite_read_num_bands
subroutine w90_readwrite_read_gamma_only(settings, gamma_only, num_kpts, error, comm)
!! Reads the flag for Gamma-only mode ("gamma_only")
use w90_error, only: w90_error_type, set_error_input
implicit none
integer, intent(in) :: num_kpts
logical, intent(inout) :: gamma_only
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
logical :: found, ltmp
ltmp = .false.
gamma_only = .false.
call w90_readwrite_get_keyword(settings, 'gamma_only', found, error, comm, l_value=ltmp)
if (allocated(error)) return
if (found) gamma_only = ltmp
if (gamma_only .and. (num_kpts .ne. 1)) then
call set_error_input(error, 'Error: gamma_only is true, but num_kpts > 1', comm)
return
endif
end subroutine w90_readwrite_read_gamma_only
subroutine w90_readwrite_read_mp_grid(settings, pw90_effective_model, mp_grid, num_kpts, error, &
comm)
!! Read the mandatory k-point mesh input ("mp_grid")
use w90_error, only: w90_error_type, set_error_input
implicit none
integer, intent(inout) :: mp_grid(3), num_kpts
logical, intent(in) :: pw90_effective_model
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
integer :: iv_temp(3)
logical :: found
call w90_readwrite_get_keyword_vector(settings, 'mp_grid', found, 3, error, comm, &
i_value=iv_temp)
if (allocated(error)) return
! ignored in pw90_effective_model case
if (.not. pw90_effective_model) then
if (found) mp_grid = iv_temp
if (.not. found) then
call set_error_input(error, &
'Error: You must specify dimensions of the Monkhorst-Pack grid by setting mp_grid', comm)
return
elseif (any(mp_grid < 1)) then
call set_error_input(error, 'Error: mp_grid must be greater than zero', comm)
return
end if
num_kpts = mp_grid(1)*mp_grid(2)*mp_grid(3)
end if
end subroutine w90_readwrite_read_mp_grid
subroutine w90_readwrite_read_system(settings, w90_system, error, comm)
!! Read a group of variables defining the system
!! "spinors" -- coupled spins
!! "num_elec_per_state" -- spin degeneracy
!! "num_valence_bands"
use w90_error, only: w90_error_type, set_error_input
implicit none
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
type(w90_system_type), intent(inout) :: w90_system
logical :: found, ltmp
integer :: itmp
ltmp = .false. ! by default our WF are not spinors
call w90_readwrite_get_keyword(settings, 'spinors', found, error, comm, l_value=ltmp)
if (allocated(error)) return
if (found) then
w90_system%spinors = ltmp
else
w90_system%spinors = .false.
endif
! We need to know if the bands are double degenerate due to spin, e.g. when calculating DOS
if (w90_system%spinors) then
w90_system%num_elec_per_state = 1
else
w90_system%num_elec_per_state = 2 ! the default
endif
call w90_readwrite_get_keyword(settings, 'num_elec_per_state', found, error, comm, &
i_value=itmp)
if (allocated(error)) return
if (found) then
if (itmp /= 1 .and. itmp /= 2) then
call set_error_input(error, 'Error: num_elec_per_state can be only 1 or 2', comm)
return
else
if (w90_system%spinors .and. itmp /= 1) then
call set_error_input(error, 'Error: when spinors = T num_elec_per_state must be 1', comm)
return
else
w90_system%num_elec_per_state = itmp
endif
endif
endif
call w90_readwrite_get_keyword(settings, 'num_valence_bands', found, error, comm, &
i_value=w90_system%num_valence_bands)
if (allocated(error)) return
if (found .and. (w90_system%num_valence_bands .le. 0)) then
call set_error_input(error, 'Error: num_valence_bands should be greater than zero', comm)
return
endif
end subroutine w90_readwrite_read_system
subroutine w90_readwrite_read_kpath(settings, kpoint_path, path_found, bands_plot, error, comm)
!! Read band plotting path variables: "kpoint_path" and "bands_num_points"
use w90_error, only: w90_error_type, set_error_input, set_error_alloc
implicit none
logical, intent(in) :: bands_plot
logical, intent(out) :: path_found
type(kpoint_path_type), intent(inout) :: kpoint_path
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
integer :: i_temp, ierr, bands_num_spec_points
logical :: found
path_found = .false.
bands_num_spec_points = 0
call w90_readwrite_get_block_length(settings, 'kpoint_path', path_found, i_temp, error, comm)
if (allocated(error)) return
if (path_found) then
bands_num_spec_points = i_temp*2
if (allocated(kpoint_path%labels)) deallocate (kpoint_path%labels)
allocate (kpoint_path%labels(bands_num_spec_points), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error allocating labels in w90_wannier90_readwrite_read', comm)
return
endif
if (allocated(kpoint_path%points)) deallocate (kpoint_path%points)
allocate (kpoint_path%points(3, bands_num_spec_points), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error allocating points in w90_wannier90_readwrite_read', comm)
return
endif
call w90_readwrite_get_keyword_kpath(settings, kpoint_path, error, comm)
if (allocated(error)) return
end if
call w90_readwrite_get_keyword(settings, 'bands_num_points', found, error, comm, &
i_value=kpoint_path%num_points_first_segment)
if (allocated(error)) return
if (bands_plot) then
if (kpoint_path%num_points_first_segment < 0) then
call set_error_input(error, 'Error: bands_num_points must be positive', comm)
return
endif
endif
end subroutine w90_readwrite_read_kpath
subroutine w90_readwrite_read_explicit_kpath(settings, kpoint_path, ok, bands_plot, bohr, error, comm)
use w90_error, only: w90_error_type, set_error_input, set_error_alloc
implicit none
logical, intent(in) :: bands_plot
type(kpoint_path_type), intent(inout) :: kpoint_path
logical, intent(out) :: ok
real(kind=dp), intent(in) :: bohr
type(w90_error_type), allocatable, intent(out) :: error
type(w90_comm_type), intent(in) :: comm
type(settings_type), intent(inout) :: settings
integer :: i_temp, ierr, bands_num_spec_points
logical :: found
bands_num_spec_points = 0
kpoint_path%bands_kpt_explicit = .false.
call w90_readwrite_get_block_length(settings, 'explicit_kpath_labels', found, bands_num_spec_points, error, comm)
if (allocated(error)) return
if (found) then
ok = .true.
kpoint_path%bands_kpt_explicit = .true.
! bands_num_spec_points = i_temp*2
if (allocated(kpoint_path%labels)) deallocate (kpoint_path%labels)
allocate (kpoint_path%labels(bands_num_spec_points), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error allocating explicit_kpath labels in w90_wannier90_readwrite_read', comm)
return
endif
if (allocated(kpoint_path%points)) deallocate (kpoint_path%points)
allocate (kpoint_path%points(3, bands_num_spec_points), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error allocating explicit kpoint labels in w90_wannier90_readwrite_read', comm)
return
endif
call w90_readwrite_get_keyword_explicit_kpath(settings, kpoint_path, error, comm)
if (allocated(error)) return
call w90_readwrite_read_explicit_kpath_points(settings, kpoint_path%bands_kpt_frac, bohr, &
error, comm)
if (allocated(error)) return
else
ok = .false.
end if
! if (bands_plot) then
! if (kpoint_path%num_points_first_segment < 0) then
! call set_error_input(error, 'Error: bands_num_points must be positive', comm)
! return
! endif
! endif
end subroutine w90_readwrite_read_explicit_kpath
subroutine w90_readwrite_read_fermi_energy(settings, found_fermi_energy, fermi_energy_list, &
error, comm)
!! Read Fermi energy ("fermi_energy") and/or ranges ("fermi_energy_min", "fermi_energy_max" and
!! "fermi_energy_step") used to setup fermi_energy_list tabulation
!! _max and _step are only sought if _min found and are optional
use w90_error, only: w90_error_type, set_error_input, set_error_alloc
implicit none
! arguments
logical, intent(out) :: found_fermi_energy ! flags that E_F provided
real(kind=dp), allocatable, intent(out) :: fermi_energy_list(:)
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
! local variables
integer :: i, ierr, n
logical :: found, fermi_energy_scan
real(kind=dp) :: fermi_energy
real(kind=dp) :: fermi_energy_max
real(kind=dp) :: fermi_energy_min
real(kind=dp) :: fermi_energy_step
found_fermi_energy = .false.
fermi_energy_scan = .false.
n = 1
fermi_energy = 0.0_dp
fermi_energy_min = fermi_energy
fermi_energy_step = 0.0_dp
call w90_readwrite_get_keyword(settings, 'fermi_energy', found_fermi_energy, error, comm, &
r_value=fermi_energy)
if (allocated(error)) return
if (found_fermi_energy) then
n = 1
fermi_energy_step = 0.0_dp
fermi_energy_min = fermi_energy
endif
call w90_readwrite_get_keyword(settings, 'fermi_energy_min', fermi_energy_scan, error, comm, &
r_value=fermi_energy_min)
if (allocated(error)) return
if (fermi_energy_scan) then
if (found_fermi_energy) then
call set_error_input(error, &
'Error: Cannot specify both fermi_energy and fermi_energy_min', comm)
return
endif
call w90_readwrite_get_keyword(settings, 'fermi_energy_max', found, error, comm, &
r_value=fermi_energy_max)
if (allocated(error)) return
if (.not. found) then
fermi_energy_max = fermi_energy_min + 1.0_dp !default
else if (found .and. fermi_energy_max <= fermi_energy_min) then
call set_error_input(error, &
'Error: fermi_energy_max must be larger than fermi_energy_min', comm)
return
endif
call w90_readwrite_get_keyword(settings, 'fermi_energy_step', found, error, comm, &
r_value=fermi_energy_step)
if (allocated(error)) return
if (.not. found) then
fermi_energy_step = 0.01_dp !default
else if (found .and. fermi_energy_step <= 0.0_dp) then
call set_error_input(error, 'Error: fermi_energy_step must be positive', comm)
return
endif
n = nint(abs((fermi_energy_max - fermi_energy_min)/fermi_energy_step)) + 1
fermi_energy_step = (fermi_energy_max - fermi_energy_min)/real(n - 1, dp)
endif
allocate (fermi_energy_list(n), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, &
'Error allocating fermi_energy_list in w90_readwrite_read_fermi_energy', comm)
return
endif
do i = 1, n
fermi_energy_list(i) = fermi_energy_min + (i - 1)*fermi_energy_step
enddo
end subroutine w90_readwrite_read_fermi_energy
subroutine w90_readwrite_read_ws_data(settings, ws_region, error, comm)
!! Reads "use_ws_distance", "ws_distance_tol", "ws_search_size"
use w90_error, only: w90_error_type, set_error_input
implicit none
type(ws_region_type), intent(inout) :: ws_region
type(w90_error_type), allocatable, intent(out) :: error
type(w90_comm_type), intent(in) :: comm
type(settings_type), intent(inout) :: settings
integer :: i
logical :: found
call w90_readwrite_get_keyword(settings, 'use_ws_distance', found, error, comm, &
l_value=ws_region%use_ws_distance)
if (allocated(error)) return
call w90_readwrite_get_keyword(settings, 'ws_distance_tol', found, error, comm, &
r_value=ws_region%ws_distance_tol)
if (allocated(error)) return
call w90_readwrite_get_vector_length(settings, 'ws_search_size', found, i, error, comm)
if (allocated(error)) return
if (found) then
if (i .eq. 1) then
call w90_readwrite_get_keyword_vector(settings, 'ws_search_size', found, 1, error, comm, &
i_value=ws_region%ws_search_size)
if (allocated(error)) return
ws_region%ws_search_size(2) = ws_region%ws_search_size(1)
ws_region%ws_search_size(3) = ws_region%ws_search_size(1)
elseif (i .eq. 3) then
call w90_readwrite_get_keyword_vector(settings, 'ws_search_size', found, 3, error, comm, &
i_value=ws_region%ws_search_size)
if (allocated(error)) return
else
call set_error_input(error, &
'Error: ws_search_size must be provided as either one integer or a vector of three integers', comm)
return
end if
if (any(ws_region%ws_search_size <= 0)) then
call set_error_input(error, 'Error: ws_search_size elements must be greater than zero', comm)
return
endif
end if
end subroutine w90_readwrite_read_ws_data
subroutine w90_readwrite_read_eigvals(eig_found, eigval, num_bands, num_kpts, stdout, &
seedname, error, comm)
!! Read the eigenvalues from wannier.eig
! fixme (jj) consider relocating to library_extra
use w90_error, only: w90_error_type, set_error_file, set_error_file, set_error_alloc
implicit none
! arguments
character(len=*), intent(in) :: seedname
integer, intent(in) :: num_bands, num_kpts
integer, intent(in) :: stdout
logical, intent(inout) :: eig_found
real(kind=dp), intent(inout) :: eigval(:, :)
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
! local
integer :: i, j, k, n, eig_unit
inquire (file=trim(seedname)//'.eig', exist=eig_found)
if (.not. eig_found) then
call set_error_file(error, 'No '//trim(seedname)//'.eig file found. Needed for disentanglement', comm)
return
else
open (newunit=eig_unit, file=trim(seedname)//'.eig', form='formatted', status='old', err=105)
do k = 1, num_kpts
do n = 1, num_bands
read (eig_unit, *, err=106, end=106) i, j, eigval(n, k)
if ((i .ne. n) .or. (j .ne. k)) then
write (stdout, '(a)') 'Found a mismatch in '//trim(seedname)//'.eig'
write (stdout, '(a,i0,a,i0)') 'Wanted band : ', n, ' found band : ', i
write (stdout, '(a,i0,a,i0)') 'Wanted kpoint: ', k, ' found kpoint: ', j
write (stdout, '(a)') ' '
write (stdout, '(a)') 'A common cause of this error is using the wrong'
write (stdout, '(a)') 'number of bands. Check your input files.'
write (stdout, '(a)') 'If your pseudopotentials have shallow core states remember'
write (stdout, '(a)') 'to account for these electrons.'
write (stdout, '(a)') ' '
call set_error_file(error, 'w90_wannier90_readwrite_read: mismatch in '//trim(seedname)//'.eig', comm)
return
end if
enddo
end do
close (eig_unit)
end if
return
105 call set_error_file(error, 'Error: Problem opening eigenvalue file '//trim(seedname)//'.eig', comm)
return
106 call set_error_file(error, 'Error: Problem reading eigenvalue file '//trim(seedname)//'.eig', comm)
return
end subroutine w90_readwrite_read_eigvals
subroutine w90_readwrite_read_dis_manifold(settings, dis_manifold, error, comm)
!! Reads disentanglement windows "dis_win_min" and "dis_win_max" (both are optional)
!! Reads frozen window "dis_froz_min" and "dis_froz_max" (either neither or both to be supplied)
use w90_error, only: w90_error_type, set_error_input
implicit none
! arguments
type(dis_manifold_type), intent(inout) :: dis_manifold
type(w90_error_type), allocatable, intent(out) :: error
type(w90_comm_type), intent(in) :: comm
type(settings_type), intent(inout) :: settings
! local
logical :: found, found2
call w90_readwrite_get_keyword(settings, 'dis_win_min', found, error, comm, &
r_value=dis_manifold%win_min)
if (allocated(error)) return
call w90_readwrite_get_keyword(settings, 'dis_win_max', found, error, comm, &
r_value=dis_manifold%win_max)
if (allocated(error)) return
if (dis_manifold%win_max .lt. dis_manifold%win_min) then
call set_error_input(error, &
'Error: w90_readwrite_read_dis_manifold: check disentanglement windows (win_max < win_min !)', comm)
return
endif
call w90_readwrite_get_keyword(settings, 'dis_froz_max', found, error, comm, &
r_value=dis_manifold%froz_max)
if (allocated(error)) return
if (found) dis_manifold%frozen_states = .true.
call w90_readwrite_get_keyword(settings, 'dis_froz_min', found2, error, comm, &
r_value=dis_manifold%froz_min)
if (allocated(error)) return
if (dis_manifold%froz_max .lt. dis_manifold%froz_min) then
call set_error_input(error, 'Error: w90_readwrite_read_dis_manifold: check disentanglement frozen windows', comm)
return
endif
if (found2 .and. .not. found) then
call set_error_input(error, 'Error: w90_readwrite_read_dis_manifold: found dis_froz_min but not dis_froz_max', comm)
return
endif
! ndimwin/lwindow are not read
! default not using projectability disentanglement, since it works the best
! with AMN generated from pseudo-atomic projections.
! However, here upon reading AMN we do not know where it comes from.
! So we still use energy disentanglement by default.
dis_manifold%frozen_proj = .false.
call w90_readwrite_get_keyword(settings, 'dis_froz_proj', found, error, comm, &
l_value=dis_manifold%frozen_proj)
if (allocated(error)) return
! default values for proj_min and proj_max
dis_manifold%proj_min = 0.01_dp; dis_manifold%proj_max = 0.95_dp
call w90_readwrite_get_keyword(settings, 'dis_proj_min', found, error, comm, &
r_value=dis_manifold%proj_min)
if (allocated(error)) return
if (found) then
if ((dis_manifold%proj_min < 0.0_dp) .or. (dis_manifold%proj_min > 1.0_dp)) then
call set_error_input(error, 'Error: w90_readwrite_read_dis_manifold: dis_proj_min < 0.0 or > 1.0', comm)
return
endif
endif
call w90_readwrite_get_keyword(settings, 'dis_proj_max', found2, error, comm, &
r_value=dis_manifold%proj_max)
if (allocated(error)) return
if (found2) then
if ((dis_manifold%proj_max < 0.0_dp) .or. (dis_manifold%proj_max > 1.0_dp)) then
call set_error_input(error, 'Error: w90_readwrite_read_dis_manifold: dis_proj_max < 0.0 or > 1.0', comm)
return
endif
endif
if (dis_manifold%proj_max < dis_manifold%proj_min) then
call set_error_input(error, 'Error: w90_readwrite_read_dis_manifold: dis_proj_max < dis_proj_min', comm)
return
endif
end subroutine w90_readwrite_read_dis_manifold
subroutine w90_readwrite_read_kmesh_data(settings, kmesh_input, error, comm)
!! Reads finite-difference input variables:
!! "search_shells"
!! "kmesh_tol"
!! "shell_list"
!! "num_shells"
!! "skip_B1_tests"
use w90_error, only: w90_error_type, set_error_input, set_error_alloc
implicit none
type(kmesh_input_type), intent(inout) :: kmesh_input
type(w90_error_type), allocatable, intent(out) :: error
type(w90_comm_type), intent(in) :: comm
type(settings_type), intent(inout) :: settings
integer :: itmp, ierr
logical :: found
integer :: n
call w90_readwrite_get_keyword(settings, 'search_shells', found, error, comm, &
i_value=kmesh_input%search_shells)
if (allocated(error)) return
if (kmesh_input%search_shells < 0) then
call set_error_input(error, 'Error: search_shells must be positive', comm)
return
endif
call w90_readwrite_get_keyword(settings, 'search_supcell_size', found, error, comm, &
i_value=kmesh_input%search_supcell_size)
if (allocated(error)) return
if (kmesh_input%search_supcell_size < 0) then
call set_error_input(error, 'Error: search_supcell_size must be positive', comm)
return
endif
call w90_readwrite_get_keyword(settings, 'higher_order_n', found, error, comm, &
i_value=kmesh_input%higher_order_n)
if (allocated(error)) return
if (kmesh_input%higher_order_n < 0) then
call set_error_input(error, 'Error: higher_order_n must be positive', comm)
return
endif
n = kmesh_input%higher_order_n
kmesh_input%max_shells_h = n*(4*n**2 + 15*n + 17)/6
kmesh_input%max_shells_aux = kmesh_input%max_shells_h
kmesh_input%num_nnmax_h = 2*kmesh_input%max_shells_h
call w90_readwrite_get_keyword(settings, 'higher_order_nearest_shells', found, error, comm, &
l_value=kmesh_input%higher_order_nearest_shells)
if (allocated(error)) return
if (.not. kmesh_input%higher_order_nearest_shells) then
kmesh_input%max_shells_aux = 6
endif
call w90_readwrite_get_keyword(settings, 'kmesh_tol', found, error, comm, &
r_value=kmesh_input%tol)
if (allocated(error)) return
if (kmesh_input%tol < 0.0_dp) then
call set_error_input(error, 'Error: kmesh_tol must be positive', comm)
return
endif
call w90_readwrite_get_range_vector(settings, 'shell_list', found, kmesh_input%num_shells, &
.true., error, comm)
if (allocated(error)) return
if (found) then
if (kmesh_input%num_shells < 0 .or. kmesh_input%num_shells > kmesh_input%max_shells_h) then
call set_error_input(error, 'Error: number of shell in shell_list must be between zero and kmesh_input%max_shells_h', comm)
return
endif
allocate (kmesh_input%shell_list(kmesh_input%num_shells), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error allocating shell_list in w90_wannier90_readwrite_read', comm)
return
endif
call w90_readwrite_get_range_vector(settings, 'shell_list', found, kmesh_input%num_shells, &
.false., error, comm, kmesh_input%shell_list)
if (allocated(error)) return
if (any(kmesh_input%shell_list < 1)) then
call set_error_input(error, 'Error: shell_list must contain positive numbers', comm)
return
endif
else
! this is the default allocation of the shell_list--used by kmesh_shell_automatic()
allocate (kmesh_input%shell_list(kmesh_input%max_shells_h), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error allocating shell_list in w90_readwrite_read_kmesh_data', comm)
return
endif
end if
call w90_readwrite_get_keyword(settings, 'num_shells', found, error, comm, i_value=itmp)
if (allocated(error)) return
if (found .and. (itmp /= kmesh_input%num_shells)) then
call set_error_input(error, &
'Error: Found obsolete keyword num_shells. Its value does not agree with shell_list', comm)
return
endif
! If .true., does not perform the check of B1 of
! Marzari, Vanderbild, PRB 56, 12847 (1997)
! in kmesh.F90
! mainly needed for the interaction with Z2PACK
! By default: .false. (perform the tests)
call w90_readwrite_get_keyword(settings, 'skip_b1_tests', found, error, comm, &
l_value=kmesh_input%skip_B1_tests)
if (allocated(error)) return
end subroutine w90_readwrite_read_kmesh_data
subroutine w90_readwrite_read_kpoints(settings, pw90_effective_model, kpt_latt, num_kpts, bohr, &
error, comm)
use w90_error, only: w90_error_type, set_error_input, set_error_alloc, set_error_dealloc
implicit none
! arguments
integer, intent(in) :: num_kpts
logical, intent(in) :: pw90_effective_model
real(kind=dp), allocatable, intent(out) :: kpt_latt(:, :)
real(kind=dp), intent(in) :: bohr
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
! local variables
real(kind=dp), allocatable :: kpt_cart(:, :)
integer :: ierr
logical :: found
! pw90_effective_model ignores kpt_cart
! this routine allocates the intent(out) kpt_latt
ierr = 0
allocate (kpt_latt(3, num_kpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error allocating kpt_latt in w90_readwrite_read_kpoints', comm)
return
endif
if (.not. pw90_effective_model) then
allocate (kpt_cart(3, num_kpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error allocating kpt_cart in w90_readwrite_read_kpoints', comm)
return
endif
call w90_readwrite_get_keyword_block(settings, 'kpoints', found, num_kpts, 3, bohr, error, &
comm, r_value=kpt_cart)
if (allocated(error)) return
if (.not. found) then
call set_error_input(error, 'Error: Did not find the kpoint information in the input file', comm)
return
endif
kpt_latt = kpt_cart
deallocate (kpt_cart, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error deallocating kpt_cart in w90_readwrite_read_kpoints', comm)
return
endif
endif
end subroutine w90_readwrite_read_kpoints
subroutine w90_readwrite_read_explicit_kpath_points(settings, kpt_latt, bohr, &
error, comm)
use w90_error, only: w90_error_type, set_error_input, set_error_alloc, set_error_dealloc
implicit none
! arguments
real(kind=dp), allocatable, intent(out) :: kpt_latt(:, :)
real(kind=dp), intent(in) :: bohr
type(settings_type), intent(inout) :: settings
type(w90_comm_type), intent(in) :: comm
type(w90_error_type), allocatable, intent(out) :: error
! local variables
real(kind=dp), allocatable :: kpt_cart(:, :)
integer :: ierr, num_kpts
logical :: found
! pw90_effective_model ignores kpt_cart
! this routine allocates the intent(out) kpt_latt
call w90_readwrite_get_block_length(settings, 'explicit_kpath', found, num_kpts, error, comm)
ierr = 0