-
Notifications
You must be signed in to change notification settings - Fork 37
/
mlwf.patch
1538 lines (1480 loc) · 58.8 KB
/
mlwf.patch
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
diff --color -ruN src/mlwf.F ../vasp.5.4.4.pl2_w90/src/mlwf.F
--- src/mlwf.F 2019-11-04 13:45:34.000000000 +0000
+++ ../vasp.5.4.4.pl2_w90/src/mlwf.F 2022-04-06 09:35:32.330727930 +0100
@@ -6,12 +6,26 @@
! write the wave functions to UNK files
LOGICAL, PRIVATE, SAVE :: WRITE_UNK
+ LOGICAL, PRIVATE, SAVE :: UNK_FMTED
+ LOGICAL, PRIVATE, SAVE :: REDUCE_UNK
+
+ ! write the wave functions to UNK files
+ LOGICAL, PRIVATE, SAVE :: WRITE_SPN
+ LOGICAL, PRIVATE, SAVE :: SPN_FMTED
+
! write the mmn and amn files when WANNIER90 runs in lib mode
- LOGICAL, PRIVATE, SAVE :: WRITE_MMN_AMN
+ LOGICAL, PRIVATE, SAVE :: CALC_MMN
+ LOGICAL, PRIVATE, SAVE :: CALC_AMN
+ LOGICAL, PRIVATE, SAVE :: WRITE_MMN
+ LOGICAL, PRIVATE, SAVE :: WRITE_AMN
+ LOGICAL, PRIVATE, SAVE :: WRITE_EIG
! read amn file instead of computing it
LOGICAL, PRIVATE, SAVE :: READ_AMN
+ ! which collinear spin channel do we want?
+ INTEGER, PRIVATE, SAVE :: W90_SPIN
+
! wannier90_run variables: output
COMPLEX(q), ALLOCATABLE, SAVE :: U_matrix(:,:,:,:)
COMPLEX(q), ALLOCATABLE, SAVE :: U_matrix_opt(:,:,:,:)
@@ -185,6 +199,20 @@
! Switch on the PEAD routines
CALL PEAD_REQUEST
+ ! spin channel
+ W90_SPIN=0
+ CALL RDATAB(.FALSE.,INCAR,IU5,'W90_SPIN','=','#',';','I', &
+ & W90_SPIN,RDUM,CDUM,LDUM,CHARAC,N,1,IERR)
+ IF (((IERR/=0).AND.(IERR/=3)).OR. &
+ & ((IERR==0).AND.(N<1))) THEN
+ IF (IU0>=0) &
+ WRITE(IU0,*)'Error reading item ''LWRITE_UNK'' from file INCAR.'
+ W90_SPIN=0
+ IF (W90_SPIN/=0 .AND. W90_SPIN/=1 .AND. W90_SPIN/=2) &
+ WRITE(IU0,*)'Error reading item ''LWRITE_UNK'' from file INCAR.'
+ W90_SPIN=0
+ ENDIF
+
! Do we want to write UNK files?
WRITE_UNK=.FALSE.
CALL RDATAB(.FALSE.,INCAR,IU5,'LWRITE_UNK','=','#',';','L', &
@@ -195,17 +223,119 @@
WRITE(IU0,*)'Error reading item ''LWRITE_UNK'' from file INCAR.'
WRITE_UNK=.FALSE.
ENDIF
+
+ ! 2020-06-22 CCX: added to determine UNK is formatted or not
+ UNK_FMTED=.FALSE.
+ CALL RDATAB(.FALSE.,INCAR,IU5,'LUNK_FMTED','=','#',';','L', &
+ & IDUM,RDUM,CDUM,UNK_FMTED,CHARAC,N,1,IERR)
+ IF (((IERR/=0).AND.(IERR/=3)).OR. &
+ & ((IERR==0).AND.(N<1))) THEN
+ IF (IU0>=0) &
+ WRITE(IU0,*)'Error reading item ''LUNK_FMTED'' from file INCAR.'
+ UNK_FMTED=.FALSE.
+ ENDIF
+
+ ! 2020-07-04 CCX: added to determine UNK is formatted or not
+ REDUCE_UNK=.FALSE.
+ CALL RDATAB(.FALSE.,INCAR,IU5,'LREDUCE_UNK','=','#',';','L', &
+ & IDUM,RDUM,CDUM,REDUCE_UNK,CHARAC,N,1,IERR)
+ IF (((IERR/=0).AND.(IERR/=3)).OR. &
+ & ((IERR==0).AND.(N<1))) THEN
+ IF (IU0>=0) &
+ WRITE(IU0,*)'Error reading item ''LREDUCE_UNK'' from file INCAR.'
+ REDUCE_UNK=.FALSE.
+ ENDIF
+
+ ! 2020-06-25 CCX: Do we want to write the spn file?
+ WRITE_SPN=.FALSE.
+ CALL RDATAB(.FALSE.,INCAR,IU5,'LWRITE_SPN','=','#',';','L', &
+ & IDUM,RDUM,CDUM,WRITE_SPN,CHARAC,N,1,IERR)
+ IF (((IERR/=0).AND.(IERR/=3)).OR. &
+ & ((IERR==0).AND.(N<1))) THEN
+ IF (IU0>=0) &
+ WRITE(IU0,*)'Error reading item ''LWRITE_SPN'' from file INCAR.'
+ WRITE_SPN=.FALSE.
+ ENDIF
+
+ ! 2020-06-25 CCX: Do we want to write the spn file?
+ SPN_FMTED=.FALSE.
+ CALL RDATAB(.FALSE.,INCAR,IU5,'LSPN_FMTED','=','#',';','L', &
+ & IDUM,RDUM,CDUM,SPN_FMTED,CHARAC,N,1,IERR)
+ IF (((IERR/=0).AND.(IERR/=3)).OR. &
+ & ((IERR==0).AND.(N<1))) THEN
+ IF (IU0>=0) &
+ WRITE(IU0,*)'Error reading item ''LSPN_FMTED'' from file INCAR.'
+ SPN_FMTED=.FALSE.
+ ENDIF
+
+
! Do we want to write the mmn and amn files
! even though WANNIER90 runs in library mode?
- WRITE_MMN_AMN=.NOT.LWANNIER90_RUN
- CALL RDATAB(.FALSE.,INCAR,IU5,'LWRITE_MMN_AMN','=','#',';','L', &
- & IDUM,RDUM,CDUM,WRITE_MMN_AMN,CHARAC,N,1,IERR)
+ ! 2020-07-04 CCX: do we really need to calculate MMN AMN and write EIG?
+ CALC_MMN=.TRUE.
+ CALL RDATAB(.FALSE.,INCAR,IU5,'LCALC_MMN','=','#',';','L', &
+ & IDUM,RDUM,CDUM,CALC_MMN,CHARAC,N,1,IERR)
+ IF (((IERR/=0).AND.(IERR/=3)).OR. &
+ & ((IERR==0).AND.(N<1))) THEN
+ IF (IU0>=0) &
+ WRITE(IU0,*)'Error reading item ''LCALC_MMN'' from file INCAR.'
+ ! this is counterintuitive, we want to calculate MMN by default
+ CALC_MMN=.TRUE.
+ ENDIF
+ ! if wannier90_run, we need mmn calculation
+ IF ((LWANNIER90_RUN) .AND. (.NOT.CALC_MMN)) CALC_MMN=.TRUE.
+
+
+ WRITE_MMN=.NOT.LWANNIER90_RUN
+ CALL RDATAB(.FALSE.,INCAR,IU5,'LWRITE_MMN','=','#',';','L', &
+ & IDUM,RDUM,CDUM,WRITE_MMN,CHARAC,N,1,IERR)
IF (((IERR/=0).AND.(IERR/=3)).OR. &
& ((IERR==0).AND.(N<1))) THEN
IF (IU0>=0) &
- WRITE(IU0,*)'Error reading item ''LWRITE_MMN_AMN'' from file INCAR.'
- WRITE_MMN_AMN=.NOT.LWANNIER90_RUN
+ WRITE(IU0,*)'Error reading item ''LWRITE_MMN'' from file INCAR.'
+ WRITE_MMN=.NOT.LWANNIER90_RUN
ENDIF
+ ! if we dont calculate mmn, we cannot write amn...
+ IF (.NOT.CALC_MMN) WRITE_MMN=.FALSE.
+
+
+ CALC_AMN=.TRUE.
+ CALL RDATAB(.FALSE.,INCAR,IU5,'LCALC_AMN','=','#',';','L', &
+ & IDUM,RDUM,CDUM,CALC_AMN,CHARAC,N,1,IERR)
+ IF (((IERR/=0).AND.(IERR/=3)).OR. &
+ & ((IERR==0).AND.(N<1))) THEN
+ IF (IU0>=0) &
+ WRITE(IU0,*)'Error reading item ''LCALC_AMN'' from file INCAR.'
+ ! this is counterintuitive, we want to calculate MMN by default
+ CALC_AMN=.TRUE.
+ ENDIF
+ ! if wannier90_run, we need amn calculation
+ IF ((LWANNIER90_RUN) .AND. (.NOT.CALC_AMN)) CALC_AMN=.TRUE.
+
+ WRITE_AMN=.NOT.LWANNIER90_RUN
+ CALL RDATAB(.FALSE.,INCAR,IU5,'LWRITE_AMN','=','#',';','L', &
+ & IDUM,RDUM,CDUM,WRITE_AMN,CHARAC,N,1,IERR)
+ IF (((IERR/=0).AND.(IERR/=3)).OR. &
+ & ((IERR==0).AND.(N<1))) THEN
+ IF (IU0>=0) &
+ WRITE(IU0,*)'Error reading item ''LWRITE_AMN'' from file INCAR.'
+ WRITE_AMN=.NOT.LWANNIER90_RUN
+ ENDIF
+ ! if we dont calculate amn, we cannot write amn...
+ IF (.NOT.CALC_AMN) WRITE_AMN=.FALSE.
+
+
+ WRITE_EIG=.NOT.LWANNIER90_RUN
+ CALL RDATAB(.FALSE.,INCAR,IU5,'LWRITE_EIG','=','#',';','L', &
+ & IDUM,RDUM,CDUM,WRITE_EIG,CHARAC,N,1,IERR)
+ IF (((IERR/=0).AND.(IERR/=3)).OR. &
+ & ((IERR==0).AND.(N<1))) THEN
+ IF (IU0>=0) &
+ WRITE(IU0,*)'Error reading item ''LWRITE_EIG'' from file INCAR.'
+ WRITE_EIG=.NOT.LWANNIER90_RUN
+ ENDIF
+
+
! Do we want to read the amn file instead of
! computing it anew?
READ_AMN=.FALSE.
@@ -320,6 +450,9 @@
REAL(q), ALLOCATABLE :: proj_x(:,:)
REAL(q), ALLOCATABLE :: proj_zona(:)
INTEGER, ALLOCATABLE :: exclude_bands(:)
+ ! CCX_2019-05-05: define proj_s and proj_s_qaxis
+ INTEGER, ALLOCATABLE :: proj_s(:)
+ REAL(q), ALLOCATABLE :: proj_s_qaxis(:,:)
! wannier90_run variables: input
COMPLEX(q), ALLOCATABLE :: M_matrix(:,:,:,:,:)
COMPLEX(q), ALLOCATABLE :: A_matrix(:,:,:,:)
@@ -329,6 +462,12 @@
INTEGER NI,MI,NK,NKP,ICNTR
INTEGER NKI,NKJ,ISP,ISPINOR,L,M,N,NP
INTEGER NEXCLB,NPROJ
+ ! CCX_2019-05-06: spin quantization local variables
+ LOGICAL spin_z_pos,spin_z_neg
+ COMPLEX(q) FAC(2)
+ REAL(q) :: eps6=0.000001_q
+ REAL(q) xnorm
+ ! CCX_2019-05-06: end definition
REAL(q) POS(3)
REAL(q) KI(3),KJ(3)
INTEGER IDUM,IERR
@@ -347,6 +486,13 @@
REAL(q), ALLOCATABLE :: ROTYLM(:,:)
REAL(q), ALLOCATABLE :: HYBRID_ORBITAL(:)
+ ! 2020-06-25 CCX added for spn matrix calc
+ GDEF, ALLOCATABLE :: SPN(:,:,:)
+ GDEF, ALLOCATABLE :: spin_mat(:,:)
+ INTEGER :: spn_counter
+ CHARACTER (len=60) :: SPN_header
+ ! CCX_2019-05-06: end definition
+
LOGICAL, ALLOCATABLE :: EXCLUDE_BAND(:)
LOGICAL LUSE_BLOCH_PHASES
@@ -357,20 +503,38 @@
INTEGER num_bands_on_file,num_kpts_on_file,NPROJ_on_file
IF (.NOT.WANNIER90()) RETURN
+ IF (IO%IU0>=0) WRITE(IO%IU0,*) "*---------------------------------------*"
+ IF (IO%IU0>=0) WRITE(IO%IU0,*) "* VASP2WANNIER90 *"
+ IF (IO%IU0>=0) WRITE(IO%IU0,*) "*---------------------------------------*"
-#ifdef MPI
+ ! 2020-06-28 CCX: I moved this to here so we can have control over collinear spin channels.
+ ! loop over spin
+ spin: DO ISP=1,WDES%ISPIN
+
+ IF ((.not. WDES%LNONCOLLINEAR) .AND. (W90_SPIN==2) .AND. (ISP==1)) CYCLE spin
+ IF ((.not. WDES%LNONCOLLINEAR) .AND. (W90_SPIN==1) .AND. (ISP==2)) CYCLE spin
+ IF ((.not. WDES%LNONCOLLINEAR) .AND. (WDES%ISPIN==2) .AND. (IO%IU0>=0)) &
+ WRITE(IO%IU0,*)'* Collinear spin -> '//SP(ISP)//' *'
+ IF ((WDES%LNONCOLLINEAR) .AND. (IO%IU0>=0)) &
+ WRITE(IO%IU0,*)'* Non-collinear spin *'
+ IF ((.not. WDES%LNONCOLLINEAR) .AND. (WDES%ISPIN==1) .AND. (IO%IU0>=0)) &
+ WRITE(IO%IU0,*)'* No spin polarization *'
+
+!#ifdef MPI
! IF (WDES%COMM_KINTER%NCPU.NE.1) THEN
! CALLMPI( M_stop('MLWF_WANNIER90: KPAR>1 not implemented, sorry.') )
! STOP
! END IF
-#endif
+!#endif
+
+! 2020-06-22 CCX: wannier90 CAN plot spinors.
! WANNIER90 cannot plot spinors
- IF (WRITE_UNK.AND.WDES%LNONCOLLINEAR) THEN
- IF (IO%IU0>=0) WRITE(IO%IU0,*) &
- & 'MLWF_WANNIER90: ERROR: will not write spinors to UNK files, sorry ...'
- WRITE_UNK=.FALSE.
- ENDIF
-!
+! IF (WRITE_UNK.AND.WDES%LNONCOLLINEAR) THEN
+! IF (IO%IU0>=0) WRITE(IO%IU0,*) &
+! & 'MLWF_WANNIER90: ERROR: will not write spinors to UNK files, sorry ...'
+! WRITE_UNK=.FALSE.
+! ENDIF
+
! allocation
ALLOCATE(S(WDES%NB_TOT,WDES%NB_TOT))
@@ -422,8 +586,25 @@
! A minimal wannier90.win file must exist; it must at least
! contain the keyword "num_wann"
IF (IO%IU6>=0) THEN
- INQUIRE(FILE=seed_name//'.win',EXIST=LWIN_FOUND)
+ IF ((.not. spinors) .AND. (WDES%ISPIN==2)) THEN
+ INQUIRE(FILE=seed_name//'.'//SP(ISP)//'.win',EXIST=LWIN_FOUND)
+ ELSE
+ INQUIRE(FILE=seed_name//'.win',EXIST=LWIN_FOUND)
+ ENDIF
+
IF (LWIN_FOUND) THEN
+ IF ((.not. spinors) .AND. (WDES%ISPIN==2)) THEN
+ OPEN(UNIT=99,FILE=seed_name//'.'//SP(ISP)//'.win',STATUS='OLD')
+ CALL RDATAB(.FALSE.,seed_name//'.'//SP(ISP)//'.win',99,'num_wann','=','#',';','I', &
+ & IDUM,RDUM,CDUM,LDUM,CHARAC,N,1,IERR)
+ IF (((IERR/=0).AND.(IERR/=3)).OR. &
+ & ((IERR==0).AND.(N<1))) THEN
+ IF (IO%IU0>=0) &
+ WRITE(IO%IU0,*)'Error reading item ''num_wann'' from file '//seed_name//'.win'
+ STOP
+ ENDIF
+ IF (IERR==3) WRITE(99,'(A,I6,2X,A)') ' num_wann =',WDES%NB_TOT,'! set to NBANDS by VASP'
+ ELSE
OPEN(UNIT=99,FILE=seed_name//'.win',STATUS='OLD')
CALL RDATAB(.FALSE.,seed_name//'.win',99,'num_wann','=','#',';','I', &
& IDUM,RDUM,CDUM,LDUM,CHARAC,N,1,IERR)
@@ -434,10 +615,16 @@
STOP
ENDIF
IF (IERR==3) WRITE(99,'(A,I6,2X,A)') ' num_wann =',WDES%NB_TOT,'! set to NBANDS by VASP'
+ ENDIF
+ ELSE
+ IF ((.not. spinors) .AND. (WDES%ISPIN==2)) THEN
+ OPEN(UNIT=99,FILE=seed_name//'.'//SP(ISP)//'.win',STATUS='REPLACE')
+ WRITE(99,'(A,I6,2X,A)') ' num_wann =',WDES%NB_TOT,'! set to NBANDS by VASP'
ELSE
OPEN(UNIT=99,FILE=seed_name//'.win',STATUS='REPLACE')
WRITE(99,'(A,I6,2X,A)') ' num_wann =',WDES%NB_TOT,'! set to NBANDS by VASP'
ENDIF
+ ENDIF
CLOSE(99)
ENDIF
@@ -449,18 +636,47 @@
ALLOCATE(proj_site(3,num_bands_tot),proj_l(num_bands_tot),proj_m(num_bands_tot), &
& proj_radial(num_bands_tot),proj_z(3,num_bands_tot),proj_x(3,num_bands_tot), &
- & proj_zona(num_bands_tot),exclude_bands(num_bands_tot))
+ & proj_zona(num_bands_tot),exclude_bands(num_bands_tot), &
+#ifdef VASP2WANNIER90v2
+! CCX_2019-05-05: allocate proj_s and proj_s_qaxis.
+ & proj_s(num_bands_tot),proj_s_qaxis(3,num_bands_tot) &
+#endif
+ & )
proj_site=0; proj_l=0; proj_m=0; proj_radial=0; proj_z=0; proj_x=0; proj_zona=0; exclude_bands=0
+! CCX_2019-05-05: initialize proj_s and proj_s_qaxis.
+#ifdef VASP2WANNIER90v2
+ proj_s=0; proj_s_qaxis=0
+#endif
+
! Only one node will do the actual work,
! otherwise all will write to wannier90.wout
#ifdef VASP2WANNIER90
- IF (IO%IU6>=0) &
+ IF (IO%IU6>=0) THEN
+ IF ((.not.spinors) .AND. (WDES%ISPIN==2)) THEN
+ CALL wannier_setup(seed_name//'.'//SP(ISP),mp_grid,num_kpts,real_lattice,recip_lattice, &
+ & kpt_latt,num_bands_tot,num_atoms,atom_symbols,atoms_cart, &
+ & gamma_only,spinors,nntot,nnlist,nncell,num_bands,num_wann, &
+ & proj_site,proj_l,proj_m,proj_radial,proj_z,proj_x,proj_zona, &
+ & exclude_bands, &
+#ifdef VASP2WANNIER90v2
+! CCX_2019-05-05: call wannier_setup to calculate proj_s and proj_s_qaxis
+ & proj_s,proj_s_qaxis &
+#endif
+ & )
+ ELSE
CALL wannier_setup(seed_name,mp_grid,num_kpts,real_lattice,recip_lattice, &
& kpt_latt,num_bands_tot,num_atoms,atom_symbols,atoms_cart, &
& gamma_only,spinors,nntot,nnlist,nncell,num_bands,num_wann, &
& proj_site,proj_l,proj_m,proj_radial,proj_z,proj_x,proj_zona, &
- & exclude_bands)
+ & exclude_bands, &
+#ifdef VASP2WANNIER90v2
+! CCX_2019-05-05: call wannier_setup to calculate proj_s and proj_s_qaxis
+ & proj_s,proj_s_qaxis &
+#endif
+ & )
+ ENDIF
+ ENDIF
#endif
! Now communicate the output to the other nodes
CALLMPI( M_sum_i(WDES%COMM,nntot,1) )
@@ -476,6 +692,11 @@
CALLMPI( M_sum_d(WDES%COMM,proj_x,3*num_bands_tot) )
CALLMPI( M_sum_d(WDES%COMM,proj_zona,num_bands_tot) )
CALLMPI( M_sum_i(WDES%COMM,exclude_bands,num_bands_tot) )
+! CCX_2019-05-05: bcast proj_s and proj_s_qaxis
+#ifdef VASP2WANNIER90v2
+ CALLMPI( M_sum_i(WDES%COMM,proj_s,num_bands_tot) )
+ CALLMPI( M_sum_d(WDES%COMM,proj_s_qaxis,3*num_bands_tot) )
+#endif
ALLOCATE(EXCLUDE_BAND(num_bands_tot))
EXCLUDE_BAND=.FALSE. ; NEXCLB=0
@@ -530,10 +751,7 @@
! nullify pointers by default
R%R=>NULL(); R%SI=>NULL()
- ! loop over spin
- spin: DO ISP=1,WDES%ISPIN
-
- IF (IO%IU6>=0.AND.WRITE_MMN_AMN) THEN
+ IF (IO%IU6>=0.AND.WRITE_MMN) THEN
IF (WDES%ISPIN==1) THEN
OPEN(UNIT=99,FILE=seed_name//'.mmn',STATUS='REPLACE')
ELSE
@@ -542,6 +760,9 @@
WRITE(99,'(A)') 'File generated by VASP: '//INFO%SZNAM1
WRITE(99,'(3I12)') num_bands,num_kpts,nntot
ENDIF
+
+ ! 2020-07-04 CCX: do we want to calculate mmn matrix
+ IF (CALC_MMN) THEN
! runs over all k-points
ki_loop: DO NKI=1,num_kpts
KI(:)=kpt_latt(:,NKI)
@@ -553,7 +774,7 @@
#endif
CALL PEAD_CALC_OVERLAP(W,KI,KJ,ISP,P,CQIJ,LATT_CUR,T_INFO,S,LQIJB=.TRUE.)
- IF (IO%IU6>=0.AND.WRITE_MMN_AMN) WRITE(99,'(5I5)') NKI,nnlist(NKI,NKJ),nncell(:,NKI,NKJ)
+ IF (IO%IU6>=0.AND.WRITE_MMN) WRITE(99,'(5I5)') NKI,nnlist(NKI,NKJ),nncell(:,NKI,NKJ)
NI=0
n_loop: DO N=1,WDES%NB_TOT
@@ -563,7 +784,7 @@
IF (EXCLUDE_BAND(M)) CYCLE m_loop
MI=MI+1
M_matrix(MI,NI,NKJ,NKI,ISP)=S(M,N)
- IF (IO%IU6>=0.AND.WRITE_MMN_AMN) WRITE(99,'(2F18.12)') S(M,N)
+ IF (IO%IU6>=0.AND.WRITE_MMN) WRITE(99,'(2F18.12)') S(M,N)
ENDDO m_loop
ENDDO n_loop
! check consistency
@@ -575,7 +796,82 @@
ENDDO kj_loop
ENDDO ki_loop
- IF (IO%IU6>=0.AND.WRITE_MMN_AMN) CLOSE(99)
+ IF (IO%IU6>=0.AND.WRITE_MMN) CLOSE(99)
+ IF (IO%IU0>=0) WRITE(IO%IU0,*) "* MMN calculated. *"
+ !2020-07-04
+ ENDIF
+
+
+ ! 2020-06-25 CCX: write SPN matrix
+ IF (WRITE_SPN .AND. (.NOT. spinors)) THEN
+ IF (IO%IU0>=0) WRITE(*,*) 'MLWF_WANNIER90: WRITE_SPN only works in non-collinear, skipping.'
+ WRITE_SPN=.FALSE.
+ ENDIF
+
+ IF (WRITE_SPN .AND. WDES%COMM%NCPU.NE.1) THEN
+ IF (IO%IU0>=0) WRITE(*,*) 'MLWF_WANNIER90: WRITE_SPN only works in serial, skipping.'
+ WRITE_SPN=.FALSE.
+ ENDIF
+
+ IF (IO%IU6>=0.AND.WRITE_SPN) THEN
+ IF (WDES%NRSPINORS==1) THEN
+ IF (IO%IU0>=0) WRITE(*,*) 'MLWF_WANNIER90: ERROR: WRITE_SPN specified, but collinear calculation.'
+ STOP
+ ELSE
+ IF (SPN_FMTED) THEN
+ OPEN(UNIT=99,FILE=seed_name//'.spn',FORM="FORMATTED",STATUS='REPLACE')
+ SPN_header = 'File generated by VASP: '//INFO%SZNAM1
+ WRITE(99,'(A)') SPN_header
+ WRITE(99,'(3I12)') num_bands,num_kpts
+ ELSE
+ OPEN(UNIT=99,FILE=seed_name//'.spn',FORM="UNFORMATTED",STATUS='REPLACE')
+ SPN_header = 'File generated by VASP: '//INFO%SZNAM1
+ WRITE(99) SPN_header
+ WRITE(99) num_bands,num_kpts
+ ENDIF
+ ENDIF
+ ENDIF
+
+ IF (WDES%NRSPINORS/=1.AND.WRITE_SPN) THEN
+ ALLOCATE(spin_mat((num_bands+1)*num_bands/2,3))
+ ALLOCATE(SPN(WDES%NB_TOT,WDES%NB_TOT,3))
+ ! runs over all k-points
+ spn_ki_loop: DO NKI=1,num_kpts
+ KI(:)=kpt_latt(:,NKI)
+
+ CALL CALC_SPN_EXP(W,KI,P,CQIJ,LATT_CUR,T_INFO,SPN)
+
+ !now, we nned to exclude some bands.
+ NI=0
+ spn_n_loop: DO N=1,WDES%NB_TOT
+ IF (EXCLUDE_BAND(N)) CYCLE spn_n_loop
+ spn_m_loop: DO M=1,N
+ IF (EXCLUDE_BAND(M)) CYCLE spn_m_loop
+ NI=NI+1
+ DO spn_counter=1,3
+ spin_mat(NI,spn_counter)=SPN(M,N,spn_counter)
+ ENDDO
+ ENDDO spn_m_loop
+ ENDDO spn_n_loop
+
+ ! writing spn matrix to file
+ IF (SPN_FMTED) THEN
+ DO N=1,(num_bands+1)*num_bands/2
+ IF (IO%IU6>=0.AND.WRITE_SPN) WRITE(99,'(2ES26.16)') (spin_mat(N,spn_counter), spn_counter=1,3)
+ ENDDO
+ ELSE
+ IF (IO%IU6>=0.AND.WRITE_SPN) WRITE(99) ((spin_mat(N,spn_counter), spn_counter=1,3), N=1,(num_bands+1)*num_bands/2)
+ ENDIF
+ ENDDO spn_ki_loop
+
+ ! some deallocation for spn mat
+ DEALLOCATE(spin_mat)
+ DEALLOCATE(SPN)
+
+ IF (IO%IU6>=0.AND.WRITE_SPN) CLOSE(99)
+ IF (IO%IU0>=0) WRITE(IO%IU0,*) "* SPN calculated. *"
+ ENDIF
+ ! 2020-06-25 CCX: spin matrix calculated
! and we might want to read an existing amn file
IF (READ_AMN) THEN
@@ -584,9 +880,16 @@
DO ISPINOR=1,WDES%NRSPINORS
DO ICNTR=1,num_bands_tot
IF (proj_l(ICNTR)==0.AND.proj_m(ICNTR)==0.AND.proj_radial(ICNTR)==0) CYCLE
+! CCX_2019-05-05: only calculate corresponding spin channel
+#ifdef VASP2WANNIER90v2
+ IF (WDES%NRSPINORS/=1.AND.proj_s(ICNTR)==1.AND.ISPINOR==2) CYCLE
+ IF (WDES%NRSPINORS/=1.AND.proj_s(ICNTR)==-1.AND.ISPINOR==1) CYCLE
+#endif
+
NPROJ=NPROJ+1
ENDDO
ENDDO
+
! check if amn file exists
IF (WDES%ISPIN==1) THEN
INQUIRE(FILE=seed_name//'.amn',EXIST=LAMN_FOUND)
@@ -627,7 +930,8 @@
ENDIF
ENDIF ! finished reading A_matrix
- IF (.NOT.READ_AMN) THEN
+ ! 2020-07-04 CCX: added to control amn calculaiton
+ IF ( .NOT. READ_AMN .AND. CALC_AMN) THEN
! we need to calculate the projection of the wave functions
! onto a set of trial functions {g}: A(m,n,i) = < \psi_m,k_i | g_n >
! A(m,n,i) is then written to the file seed_name.amn
@@ -643,11 +947,36 @@
ALLOCATE(ROTYLM((LMAX+1)**2,(LMAX+1)**2),HYBRID_ORBITAL((LMAX+1)**2))
NPROJ=0
-! CALL START_TIMING("T1")
+ ! CCX_2020-06-15: initialize A matrix
+ A_matrix=0
! runs over all projector sites
- spinor: DO ISPINOR=1,WDES%NRSPINORS
sites : DO ICNTR=1,num_bands_tot
IF (proj_l(ICNTR)==0.AND.proj_m(ICNTR)==0.AND.proj_radial(ICNTR)==0) CYCLE sites
+ ! CCX_2019-05-06: determin spin quantization axis along z axis or not.
+ spin_z_pos=.false.
+ spin_z_neg=.false.
+ ! CCX_2019-06-10: renormalize spin quantization axis
+ xnorm=SQRT(proj_s_qaxis(1,ICNTR)*proj_s_qaxis(1,ICNTR)+proj_s_qaxis(2,ICNTR)*proj_s_qaxis(2,ICNTR)+proj_s_qaxis(3,ICNTR)*proj_s_qaxis(3,ICNTR))
+ proj_s_qaxis(1,ICNTR)=proj_s_qaxis(1,ICNTR)/xnorm
+ proj_s_qaxis(2,ICNTR)=proj_s_qaxis(2,ICNTR)/xnorm
+ proj_s_qaxis(3,ICNTR)=proj_s_qaxis(3,ICNTR)/xnorm
+
+ IF ((abs(proj_s_qaxis(1,ICNTR)-0.0d0)<eps6).and.(abs(proj_s_qaxis(2,ICNTR)-0.0d0)<eps6) &
+ .and.(abs(proj_s_qaxis(3,ICNTR)-1.0d0)<eps6)) then
+ spin_z_pos=.true.
+ ELSEIF(abs(proj_s_qaxis(1,ICNTR)-0.0d0)<eps6.and.abs(proj_s_qaxis(2,ICNTR)-0.0d0)<eps6 &
+ .and.abs(proj_s_qaxis(3,ICNTR)+1.0d0)<eps6) then
+ spin_z_neg=.true.
+ ENDIF
+ ! CCX_2019-05-06: [start] if proj_s_qaxis lies along z, normal projections are done.
+ IF (spin_z_pos .OR. spin_z_neg .OR. WDES%NRSPINORS==1) THEN ! if not spinor, still use this routine.
+ spinor1: DO ISPINOR=1,WDES%NRSPINORS
+ IF (spin_z_pos.AND.WDES%NRSPINORS/=1.AND.proj_s(ICNTR)==1.AND.ISPINOR==2) CYCLE spinor1
+ IF (spin_z_pos.AND.WDES%NRSPINORS/=1.AND.proj_s(ICNTR)==-1.AND.ISPINOR==1) CYCLE spinor1
+ ! if neg then swap up and down definition
+ IF (spin_z_neg.AND.WDES%NRSPINORS/=1.AND.proj_s(ICNTR)==1.AND.ISPINOR==1) CYCLE spinor1
+ IF (spin_z_neg.AND.WDES%NRSPINORS/=1.AND.proj_s(ICNTR)==-1.AND.ISPINOR==2) CYCLE spinor1
+
NPROJ=NPROJ+1
! setup the Ylm rotation matrix in accordance with proj_z and proj_x
CALL SETROTYLM(proj_x(:,ICNTR),proj_z(:,ICNTR),LMAX,ROTYLM)
@@ -673,9 +1002,9 @@
ENDDO
-! CALL START_TIMING("T2")
+ ! CALL START_TIMING("T2")
! runs over all k-points
- kpoints : DO NKI=1,num_kpts
+ kpoints1 : DO NKI=1,num_kpts
CALL CALC_OVERLAP_GN( &
& LMAX,FG,proj_site(:,ICNTR),W,kpt_latt(:,NKI),ISP,ISPINOR,P,CQIJ,LATT_CUR,T_INFO,A)
! and rotate them in accordance with proj_z and proj_x
@@ -712,15 +1041,111 @@
A_matrix(MI,NPROJ,NKI,ISP)=CPROJ
ENDDO
+ ENDDO kpoints1
+
+ DEALLOCATE(FTMP,FR,FGTMP,FG)
+
+ IF (IO%IU0>=0) WRITE(IO%IU0,'(X,A,I3,A,I3,A)') '* Projection [',NPROJ,'/',num_wann,'] done. *'
+ ! CALL STOP_TIMING("T2",IO%IU6,' OVL')
+ ! CALL STOP_TIMING("T1",IO%IU6,'ICNTR')
+ ENDDO spinor1
+ ! CCX_2019-05-06: [end] end normal routine.
+
+ ELSE ! CCX_2019-05-06: quantization axis does not lies along z axis, do special projection routine.
+ ! CCX_2019-05-06: generate spinor eigenvectors.
+ ! CCX_2019-06-10: renormalize spin quantization axis
+ xnorm=SQRT(proj_s_qaxis(1,ICNTR)*proj_s_qaxis(1,ICNTR)+proj_s_qaxis(2,ICNTR)*proj_s_qaxis(2,ICNTR)+proj_s_qaxis(3,ICNTR)*proj_s_qaxis(3,ICNTR))
+ proj_s_qaxis(1,ICNTR)=proj_s_qaxis(1,ICNTR)/xnorm
+ proj_s_qaxis(2,ICNTR)=proj_s_qaxis(2,ICNTR)/xnorm
+ proj_s_qaxis(3,ICNTR)=proj_s_qaxis(3,ICNTR)/xnorm
+
+ IF (proj_s(ICNTR)==1) THEN ! up channel
+ FAC(1)=(1.0d0/SQRT(1+proj_s_qaxis(3,ICNTR)))*(proj_s_qaxis(3,ICNTR)+1)*CMPLX(1.0d0,0.0d0,q)
+ FAC(2)=(1.0d0/SQRT(1+proj_s_qaxis(3,ICNTR)))*CMPLX(proj_s_qaxis(1,ICNTR),proj_s_qaxis(2,ICNTR),q)
+ NPROJ=NPROJ+1
+ ELSE ! down channel
+ FAC(1)=(1.0d0/SQRT(1-proj_s_qaxis(3,ICNTR)))*(proj_s_qaxis(3,ICNTR)-1)*CMPLX(1.0d0,0.0d0,q)
+ FAC(2)=(1.0d0/SQRT(1-proj_s_qaxis(3,ICNTR)))*CMPLX(proj_s_qaxis(1,ICNTR),proj_s_qaxis(2,ICNTR),q)
+ NPROJ=NPROJ+1
+ ENDIF
+
+ ! 2020-06-15 CCX: we no longer need ISPINOR loop since we are using full spinor guiding functions.
+ !spinor: DO ISPINOR=1,WDES%NRSPINORS
+ ! setup the Ylm rotation matrix in accordance with proj_z and proj_x
+ CALL SETROTYLM(proj_x(:,ICNTR),proj_z(:,ICNTR),LMAX,ROTYLM)
+#ifdef debug
+ IF (IO%IU6>=0) THEN
+ WRITE(*,'(I4,3F14.7)') ICNTR,proj_site(1:3,ICNTR)
+ DO N=10,MIN((LMAX+1)**2,16)
+ WRITE(*,'(9F10.5)') (ROTYLM(N,M),M=10,MIN((LMAX+1)**2,16))
+ ENDDO
+ ENDIF
+#endif
+ ! translate between VASP and the orbital definition of wannier90
+ CALL WANNIER90_ORBITAL_DEFINITIONS(proj_l(ICNTR),proj_m(ICNTR),HYBRID_ORBITAL)
+
+ ! setup the radial functions (real space)
+ CALL SETRGRID(RSTART/proj_zona(ICNTR),REND,H,R)
+ ALLOCATE(FTMP(R%NMAX),FR(R%NMAX,LMAX+1))
+ ALLOCATE(FGTMP(NMAX,5),FG(NMAX,5,LMAX+1))
+
+ ! For now we use the same radial function for all L
+ DO L=0,LMAX
+ CALL RADIAL_FUNCTION(proj_radial(ICNTR),R,proj_zona(ICNTR),FTMP)
+ CALL BESSEL_TRANSFORM_RADIAL_FUNCTION(L,R,FTMP,REAL(SQRT(2._q*INFO%ENMAX/HSQDTM)/NMAX,KIND=q),FGTMP)
+ FR(:,L+1)=FTMP; FG(:,:,L+1)=FGTMP
+ ENDDO
+
+ ! CALL START_TIMING("T2")
+ ! runs over all k-points
+ kpoints : DO NKI=1,num_kpts
+ CALL CALC_OVERLAP_GN_ALL( &
+ & LMAX,FG,proj_site(:,ICNTR),W,kpt_latt(:,NKI),ISP,FAC,P,CQIJ,LATT_CUR,T_INFO,A)
+ ! and rotate them in accordance with proj_z and proj_x
+ AP=0
+ DO M=1,WDES%NB_TOT
+ DO N=1,(LMAX+1)**2
+ DO NP=1,(LMAX+1)**2
+ AP(M,N)=AP(M,N)+A(M,NP)*ROTYLM(N,NP)
+ ENDDO
+ ENDDO
+ ENDDO
+#ifdef debug
+ IF (IO%IU6>=0) THEN
+ WRITE(*,'(I4,3F14.7)') NKI,kpt_latt(1:3,NKI)
+ DO M=1,WDES%NB_TOT
+ WRITE(*,'(4(2F14.7,2X))') (A(M,N),N=1,4)
+ ENDDO
+ WRITE(*,*)
+ DO M=1,WDES%NB_TOT
+ WRITE(*,'(4(2F14.7,2X))') (AP(M,N),N=1,4)
+ ENDDO
+ WRITE(*,*)
+ ENDIF
+#endif
+ ! Make the desired linear combinations
+ MI=0
+ DO M=1,WDES%NB_TOT
+ IF (EXCLUDE_BAND(M)) CYCLE
+ CPROJ=0
+ DO N=1,(LMAX+1)**2
+ CPROJ=CPROJ+AP(M,N)*HYBRID_ORBITAL(N)
+ ENDDO
+ MI=MI+1
+ A_matrix(MI,NPROJ,NKI,ISP)=CPROJ
+ ENDDO
+
ENDDO kpoints
DEALLOCATE(FTMP,FR,FGTMP,FG)
- IF (IO%IU0>=0) WRITE(IO%IU0,'(X,A,I3,A)') 'Projection ',NPROJ,' done.'
-! CALL STOP_TIMING("T2",IO%IU6,' OVL')
-! CALL STOP_TIMING("T1",IO%IU6,'ICNTR')
+ ! IF (IO%IU0>=0) WRITE(IO%IU0,'(X,A,I3,A,I3,A)') 'Spin channel',ISPINOR,' done.'
+ ! CALL STOP_TIMING("T2",IO%IU6,' OVL')
+ ! CALL STOP_TIMING("T1",IO%IU6,'ICNTR')
+ !ENDDO spinor
+ IF (IO%IU0>=0) WRITE(IO%IU0,'(X,A,I3,A,I3,A)') '* Projection [',NPROJ,'/',num_wann,'] done. [axis mod] *'
+ ENDIF ! quantization IF
ENDDO sites
- ENDDO spinor
DEALLOCATE(A,AP,ROTYLM,HYBRID_ORBITAL)
@@ -733,13 +1158,14 @@
IF (IO%IU0>=0) WRITE(*,*) 'MLWF_WANNIER90: ERROR: number of projections not equal to num_wann',NPROJ,num_wann
STOP
ENDIF
-
+ IF (IO%IU0>=0) WRITE(IO%IU0,*) "* AMN calculated. *"
ENDIF ! finished computing A_matrix
+ IF (WRITE_AMN) THEN
! write A_matrix to file
LUSE_BLOCH_PHASES=.FALSE.
IF (NPROJ/=0) THEN
- IF (IO%IU6>=0.AND.WRITE_MMN_AMN.AND..NOT.READ_AMN) THEN
+ IF (IO%IU6>=0.AND.WRITE_AMN.AND..NOT.READ_AMN) THEN
IF (WDES%ISPIN==1) THEN
OPEN(UNIT=99,FILE=seed_name//'.amn',STATUS='REPLACE')
ELSE
@@ -757,8 +1183,14 @@
CLOSE(99)
ENDIF
ELSE
- ! read use_bloch_phases from the .win file
- OPEN(UNIT=99,FILE=seed_name//'.win',STATUS='OLD')
+ ! 2022-04-04 CCX: added for spin polarized calculations
+ IF ((.not. spinors) .AND. (WDES%ISPIN==2)) THEN
+ ! read use_bloch_phases from the .win file
+ OPEN(UNIT=99,FILE=seed_name//'.'//SP(ISP)//'.win',STATUS='OLD')
+ ELSE
+ OPEN(UNIT=99,FILE=seed_name//'.win',STATUS='OLD')
+ ENDIF
+
CALL RDATAB(.FALSE.,seed_name//'.win',99,'use_bloch_phases','=','#',';','L', &
& IDUM,RDUM,CDUM,LUSE_BLOCH_PHASES,CHARAC,N,1,IERR)
IF (((IERR/=0).AND.(IERR/=3)).OR. &
@@ -773,6 +1205,7 @@
LUSE_BLOCH_PHASES=.TRUE.
ENDIF
CLOSE(99)
+
ENDIF
! if we do not have starting projections and
! use_bloch_phases=.false. in the .win file
@@ -781,10 +1214,13 @@
IF (NPROJ==0.AND.(.NOT.LUSE_BLOCH_PHASES).AND.WANNIER90RUN()) THEN
!
ENDIF
+ ! 2020-07-04
+ ENDIF
+
! and ...
! we should write the eigenvalues onto seed_name.eig
- IF (IO%IU6>=0.AND.WRITE_MMN_AMN) THEN
+ IF (IO%IU6>=0.AND.WRITE_EIG) THEN
IF (WDES%ISPIN==1) THEN
OPEN(UNIT=99,FILE=seed_name//'.eig',STATUS='REPLACE')
ELSE
@@ -792,6 +1228,8 @@
ENDIF
ENDIF
+ ! actually write eig file
+ IF (WRITE_EIG) THEN
DO NKI=1,num_kpts
NK=KPOINT_IN_FULL_GRID(kpt_latt(:,NKI),KPOINTS_FULL)
NK=KPOINTS_FULL%NEQUIV(NK)
@@ -800,10 +1238,13 @@
IF (EXCLUDE_BAND(M)) CYCLE
MI=MI+1
eigenvalues(MI,NKI,ISP)=REAL(W%CELTOT(M,NK,ISP))
- IF (IO%IU6>0.AND.WRITE_MMN_AMN) WRITE(99,'(2I12,F22.12)') MI,NKI,REAL(W%CELTOT(M,NK,ISP))
+ IF (IO%IU6>0.AND.WRITE_EIG) WRITE(99,'(2I12,F22.12)') MI,NKI,REAL(W%CELTOT(M,NK,ISP))
ENDDO
ENDDO
- IF (IO%IU6>=0.AND.WRITE_MMN_AMN) CLOSE(99)
+ IF (IO%IU6>=0.AND.WRITE_EIG) CLOSE(99)
+ IF (IO%IU0>=0.AND.WRITE_EIG) WRITE(IO%IU0,*) "* EIG written. *"
+ !2020-07-04
+ ENDIF
! and last but not least we may need to write UNK files
! which is a bit tricky since the bands at a certain k-point
@@ -811,23 +1252,47 @@
! to make matters worse, WANNIER90 works with the full k-mesh
! whereas VASP uses the symmetry reduced one.
100 FORMAT('UNK',I5.5,'.',I1)
+ 101 FORMAT('UNK',I5.5,'.NC')
IF (WRITE_UNK) THEN
DO NKI=1,num_kpts
IF (IO%IU6>=0) THEN
+ IF (W%WDES%NRSPINORS/=1) THEN
+ WRITE(UNKFILE,101) NKI
+ ELSE
WRITE(UNKFILE,100) NKI,ISP
+ ENDIF
+ IF (UNK_FMTED) THEN
+ OPEN(UNIT=99,FILE=UNKFILE,FORM='FORMATTED',STATUS='REPLACE')
+ IF (REDUCE_UNK) THEN
+ WRITE(99,*) (W%WDES%GRID%NGX+1)/2,(W%WDES%GRID%NGY+1)/2,(W%WDES%GRID%NGZ+1)/2,NKI,num_bands
+ ELSE
+ WRITE(99,*) W%WDES%GRID%NGX,W%WDES%GRID%NGY,W%WDES%GRID%NGZ,NKI,num_bands
+ ENDIF
+ ELSE
OPEN(UNIT=99,FILE=UNKFILE,FORM='UNFORMATTED',STATUS='REPLACE')
+ IF (REDUCE_UNK) THEN
+ WRITE(99) (W%WDES%GRID%NGX+1)/2,(W%WDES%GRID%NGY+1)/2,(W%WDES%GRID%NGZ+1)/2,NKI,num_bands
+ ELSE
WRITE(99) W%WDES%GRID%NGX,W%WDES%GRID%NGY,W%WDES%GRID%NGZ,NKI,num_bands
ENDIF
- CALL WRITE_WAVE_FUNCTIONS(W,kpt_latt(:,NKI),ISP,EXCLUDE_BAND,P,LATT_CUR,99)
+ ENDIF
+ ENDIF
+ CALL WRITE_WAVE_FUNCTIONS(W,kpt_latt(:,NKI),ISP,EXCLUDE_BAND,P,LATT_CUR,UNK_FMTED,REDUCE_UNK,99)
IF (IO%IU6>=0) CLOSE(99)
ENDDO
+ IF (IO%IU0>=0) WRITE(IO%IU0,*) "* UNK written. *"
ENDIF
-
- ENDDO spin
+ IF (IO%IU0>=0) WRITE(IO%IU0,*) "*---------------------------------------*"
! Write information on seed_name.win
IF (IO%IU6>=0) THEN
+ IF ((.NOT. spinors) .AND. (WDES%ISPIN==2)) THEN
+ OPEN(UNIT=99,FILE=seed_name//'.'//SP(ISP)//'.win',STATUS='OLD')
+! ELSEIF ((.NOT. spinors) .AND. (WDES%RSPIN==1)) THEN
+! OPEN(UNIT=99,FILE=seed_name//'.win',STATUS='OLD')
+ ELSE
OPEN(UNIT=99,FILE=seed_name//'.win',STATUS='OLD')
+ ENDIF
IF (spinors) THEN
CALL OCCURS_IN_FILE(99,'spinors',N)
@@ -919,9 +1384,9 @@
& U_matrix(:,:,:,1),U_matrix_opt(:,:,:,1),lwindow(:,:,1), &
& wann_centres(:,:,1),wann_spreads(:,1),spread(:,1))
ELSE
- DO ISP=1,WDES%ISPIN
+ !DO ISP=1,WDES%ISPIN
! copy wannier90.win to wannier90.(up/dn).win
- CALL COPYFILE(seed_name//'.win',seed_name//'.'//SP(ISP)//'.win')
+ !CALL COPYFILE(seed_name//'.win',seed_name//'.'//SP(ISP)//'.win')
! run wannier90 for spin component ISP
CALL wannier_run(seed_name//'.'//SP(ISP), &
@@ -932,7 +1397,7 @@
& U_matrix(:,:,:,ISP),U_matrix_opt(:,:,:,ISP),lwindow(:,:,ISP), &
& wann_centres(:,:,ISP),wann_spreads(:,ISP),spread(:,ISP))
- ENDDO
+ !ENDDO
ENDIF
ENDIF
#endif
@@ -955,13 +1420,21 @@
ENDIF
ENDIF
- DEALLOCATE(atom_symbols,atoms_cart)
DEALLOCATE(nnlist,nncell)
DEALLOCATE(proj_site,proj_l,proj_m,proj_radial,proj_z,proj_x,proj_zona,exclude_bands)
+#ifdef VASP2WANNIER90v2
+! CCX_2019-05-05: deall
+ DEALLOCATE(proj_s,proj_s_qaxis)
+#endif
+
+ DEALLOCATE(atom_symbols,atoms_cart)
DEALLOCATE(EXCLUDE_BAND)
DEALLOCATE(M_matrix,A_matrix,eigenvalues)
DEALLOCATE(S)
+ ! 2020-06-27 CCX: I moved this here so we can have total control of collinear spin channels.
+ ENDDO spin
+
IF (ASSOCIATED(R%R)) THEN
DEALLOCATE(R%R); NULLIFY(R%R)
ENDIF
@@ -1880,6 +2353,186 @@
RETURN
END SUBROUTINE CALC_OVERLAP_GN
+!******************** SUBROUTINE CALC_OVERLAP_GN_ALL *******************
+! 2020-06-15 CCX: added to use CONSTRUCT_FUNCTION_RYlm_ALL
+! for spin_quantization calculations
+!***********************************************************************
+ SUBROUTINE CALC_OVERLAP_GN_ALL( &
+ & L,FG,POS,W,K,ISP,SPIN_FAC,P,CQIJ,LATT_CUR,T_INFO,S &
+ &)
+ USE pead
+ USE poscar
+ USE pseudo
+ USE lattice
+ USE full_kpoints
+ USE wave_high
+ USE nonl_high
+ IMPLICIT NONE
+ TYPE(wavespin) W
+ TYPE(potcar) P(:)
+ TYPE(latt) LATT_CUR
+ TYPE(type_info) T_INFO
+ INTEGER L
+ INTEGER ISP
+ ! 2020-06-15 CCX: read in SPIN_FAC
+ COMPLEX(q) SPIN_FAC(2)
+ REAL(q) K(3)
+ REAL(q) FG(:,:,:)
+ REAL(q) POS(3)
+ OVERLAP CQIJ(:,:,:,:)
+ GDEF S(W%WDES%NB_TOT,(L+1)**2)
+ ! local variables
+ TYPE(wavespin) WP
+ TYPE(wavefuna) WK,WRYlm
+ TYPE(wavedes1), TARGET :: WDESK
+ TYPE(nonl_struct) NONL_S
+
+ TYPE(rotation_handle), POINTER :: ROT_HANDLE
+
+ GDEF C
+ REAL(q) WSCAL
+ INTEGER NK,NB,N,NYLM
+
+ WP=W
+ WP%WDES=>WDES_FULL_PEAD
+
+ CALL CHECK_FULL_KPOINTS
+
+ NULLIFY(ROT_HANDLE)
+
+ NYLM=(L+1)**2
+
+ ! search for kpoint k in BZ
+ NK=KPOINT_IN_FULL_GRID(K,KPOINTS_FULL)
+ CALL SETWDES(WP%WDES,WDESK,NK)
+ IF (NK==KPOINTS_FULL%NEQUIV(NK)) THEN
+ ! k is a kpoint in the IBZ
+ WK=ELEMENTS(WP,WDESK,ISP)
+ ELSE
+ ! k is not a kpoint in the IBZ
+ CALL NEWWAVA(WK,WDESK,WDESK%NBANDS)
+ CALL PEAD_WA_ROTATE(WP,P,LATT_CUR,ISP,WK)
+ ENDIF
+
+ CALL NONL_ALLOC(NONL_S,T_INFO,P,WP%WDES,.FALSE.)
+ CALL SPHER(WP%WDES%GRID,NONL_S,P,WP%WDES,LATT_CUR,1,NK)
+ CALL PHASE(WP%WDES,NONL_S,NK)
+
+ CALL NEWWAVA(WRYlm,WDESK,NYLM)
+ WRYlm%CW=0
+ !WRITE(*,*) WRYlm%WDES1%LOVERL, WRYlm%WDES1%NPROD
+ ! 2020-06-15 CCX: use CONSTRUCT_FUNCTION_RYlm_ALL.
+ CALL CONSTRUCT_FUNCTION_RYlm_ALL(L,FG,LATT_CUR,POS,NONL_S,SPIN_FAC,WRYlm)
+ ! and normalize the functions WRYlm
+ DO N=1,NYLM
+ CALL CNORMN(ELEMENT(WRYlm,N),CQIJ,1,WSCAL)
+ ENDDO
+
+ ! calculate overlap between Wk and WRYlm: < w_{m,k1} | S | RYlm >
+ S=0
+ DO NB=1,WP%WDES%NBANDS
+ DO N=1,NYLM
+ C=W1_DOT(ELEMENT(WK,NB),ELEMENT(WRYlm,N),CQIJ)
+ S(WDESK%NB_LOW+WDESK%NB_PAR*(NB-1),N)=C
+! WRITE(*,*) WDESK%NB_LOW+WDESK%NB_PAR*(NB-1),N,C
+ ENDDO
+ ENDDO
+
+ CALLMPI( M_sum_g(WDESK%COMM_INTER,S(1,1),WDESK%NB_TOT*NYLM) )
+
+ ! some deallocation to be done
+ CALL DEALLOCATE_ROT_HANDLE(ROT_HANDLE)
+
+ CALL DELWAVA(WRYlm)
+ IF (NK/=KPOINTS_FULL%NEQUIV(NK)) CALL DELWAVA(WK)
+
+ CALL NONL_DEALLOC(NONL_S)
+
+ RETURN
+ END SUBROUTINE CALC_OVERLAP_GN_ALL
+
+!******************** SUBROUTINE CALC_SPN_EXP ***********************
+! 2020-06-15 CCX: a modified version of CALC_OVERLAP_GN
+! calculates expectation value of the
+! Pauli Matrix. Uses W1_SPN_DOT in wave_high.F
+! Note: This routine only works in serial.
+!***********************************************************************
+ SUBROUTINE CALC_SPN_EXP( &
+ & W,K,P,CQIJ,LATT_CUR,T_INFO,S &
+ &)
+ USE pead
+ USE poscar
+ USE pseudo
+ USE lattice
+ USE full_kpoints
+ USE wave_high
+ USE nonl_high
+ IMPLICIT NONE
+ TYPE(wavespin) W
+ TYPE(potcar) P(:)
+ TYPE(latt) LATT_CUR
+ TYPE(type_info) T_INFO
+ ! INTEGER L
+ ! INTEGER ISP
+ ! INTEGER ISPINOR
+ REAL(q) K(3)
+ ! REAL(q) FG(:,:,:)
+ ! REAL(q) POS(3)
+ OVERLAP CQIJ(:,:,:,:)
+ GDEF S(W%WDES%NB_TOT,W%WDES%NB_TOT,3)
+ ! local variables
+ TYPE(wavespin) WP
+ TYPE(wavefuna) WK
+ TYPE(wavedes1), TARGET :: WDESK
+
+ TYPE(rotation_handle), POINTER :: ROT_HANDLE