-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathget_hamk_sparse.f90
1137 lines (999 loc) · 41.7 KB
/
get_hamk_sparse.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
#include "alias.inc"
#ifdef MKL_SPARSE
subroutine get_hamk_sparse_overlap(SHk, SSk, SH0,SS0, SHm, SHs, is, kp, PINPT, PPRAM, neig, NN_TABLE, flag_init, flag_phase, &
flag_sparse_zero_SHm, flag_sparse_zero_SHs)
use parameters, only : incar, hopping, spmat, params
use mpi_setup
use phase_factor
use do_math
use kronecker_prod
use sparse_tool
#ifdef MKL_SPARSE
use MKL_SPBLAS
#endif
use time
use print_io
implicit none
type (incar ) :: PINPT
type (params ) :: PPRAM
type (hopping) :: NN_TABLE
type (spmat ) :: SHk, SH0, SHm, SHs
type (spmat ) :: SSk, SS0 ! for overlap matrix
#ifdef MKL_SPARSE
type (SPARSE_MATRIX_T) :: Sk, Sk_ , S0, Sm, Ss
type (SPARSE_MATRIX_T) ::S_Sk,S_Sk_, S_S0 ! for overlap matrix
#endif
logical flag_init, flag_phase
integer*4 is, neig, ispinor, ispin
integer*4 istat
real*8 kp(3)
complex*16 alpha
logical flag_sparse_zero_SHm ! if the sparse matrix has no non-zero element (nnz = 0),
logical flag_sparse_zero_SHs ! this flag will be .true. and will skip related construction routine.
real*8 t1, t0
integer*4 mpierr
! DEALLOCATION of array
! Hk: initialized every call (deallocated with cal_eig_Hk_sparse exit)
! H0: initialized every call (deallocated with cal_eig_Hk_sparse exit) ! same rule holds for overlap matrix construction
! Hm: initialized in the first call (deallocated after get_eig exit)
! Hs: initialized in the first call if slater-koster (deallocated after get_eig exit)
! initialized every call if .not. slater-koster (deallocated after cal_eig_Hk_sparse exit)
! H0 will be constructed for spin-1. For spin-2, copied from spin-1
if(PPRAM%flag_use_overlap) then
if(is .eq. 1) call set_ham0_sparse_overlap (SH0, SS0, kp, PINPT, PPRAM, neig, NN_TABLE, flag_phase)
elseif(.not. PPRAM%flag_use_overlap) then
if(is .eq. 1) call set_ham0_sparse (SH0, kp, PINPT, PPRAM, neig, NN_TABLE, flag_phase)
endif
if(flag_init) then ! setup k-independent Hamiltonian: Hm, Hs (if .not. slater_koster)
if(PINPT%flag_collinear .or. PINPT%flag_noncollinear) then
call set_ham_mag_sparse(SHm, NN_TABLE, PPRAM, neig, PINPT%ispinor, &
flag_sparse_zero_SHm, PINPT%flag_collinear, PINPT%flag_noncollinear)
if(PINPT%flag_soc .and. PPRAM%flag_slater_koster .and. PINPT%flag_noncollinear) then
call set_ham_soc_sparse(SHs, 0d0, PPRAM, neig, NN_TABLE, flag_phase, flag_sparse_zero_SHs, .true., F_IJ)
endif
endif
flag_init = .false.
endif
if(PINPT%flag_collinear) then
if(.not. flag_sparse_zero_SHm) then
call sparse_create_csr_handle(S0, SH0)
if(PPRAM%flag_use_overlap) then
call sparse_create_csr_handle(S_Sk, SS0) ! since overlap matrix does not need to add Sm, SS0 is directly handled by S_Sk
endif
call sparse_create_csr_handle(Sm, SHm)
alpha = ((-1d0)**(is+1))
! Sk(up) = S0 + Sm , Sk(dn) = S0 - Sm
istat = MKL_SPARSE_z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, S0 , alpha, Sm, Sk)
call sparse_error_report('MKL_SPARSE_z_ADD: S0+Sm=Sk', istat)
call sparse_export_csr(Sk, SHk)
if(PPRAM%flag_use_overlap) then
call sparse_export_csr(S_Sk, SSk)
endif
istat = MKL_SPARSE_DESTROY(Sm)
call sparse_error_report('MKL_SPARSE_DESTROY: Sm ', istat)
istat = MKL_SPARSE_DESTROY(S0)
call sparse_error_report('MKL_SPARSE_DESTROY: S0 ', istat)
elseif(flag_sparse_zero_SHm) then
SHk%msize = SH0%msize
SHk%nnz = SH0%nnz
allocate(SHk%H(SH0%nnz )) ; SHk%H = SH0%H
allocate(SHk%J(SH0%nnz )) ; SHk%J = SH0%J
allocate(SHk%I(SH0%msize+1)) ; SHk%I = SH0%I
if(PPRAM%flag_use_overlap) then
SSk%msize = SS0%msize
SSk%nnz = SS0%nnz
allocate(SSk%H(SS0%nnz )) ; SSk%H = SS0%H
allocate(SSk%J(SS0%nnz )) ; SSk%J = SS0%J
allocate(SSk%I(SS0%msize+1)) ; SSk%I = SS0%I
endif
endif
elseif(PINPT%flag_noncollinear) then
if(PINPT%flag_soc) then
if(.not. PPRAM%flag_slater_koster) then
!set up k-dependent SOC in the case of 'cc' orbitals
call set_ham_soc_sparse(SHs, kp, PPRAM, neig, NN_TABLE, flag_phase, flag_sparse_zero_SHs, .false., F_IJ)
endif
call kproduct_pauli_0_CSR(SH0)
call sparse_create_csr_handle(S0, SH0)
if(PPRAM%flag_use_overlap) then
call kproduct_pauli_0_CSR(SS0)
call sparse_create_csr_handle(S_Sk, SS0)
endif
if(.not. flag_sparse_zero_SHm) call sparse_create_csr_handle(Sm, SHm)
if(.not. flag_sparse_zero_SHs) call sparse_create_csr_handle(Ss, SHs)
alpha = 1d0
if(.not. flag_sparse_zero_SHm) then
istat = MKL_SPARSE_Z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, S0 , alpha, Sm, Sk_)
call sparse_error_report('MKL_SPARSE_z_ADD: S0+Sm=Sk_', istat)
istat = MKL_SPARSE_DESTROY(Sm)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: Sm ', istat)
istat = MKL_SPARSE_DESTROY(S0)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: S0 ', istat)
endif
if(.not. flag_sparse_zero_SHm) then
if(.not. flag_sparse_zero_SHs) then
istat = MKL_SPARSE_Z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, Sk_ , alpha, Ss, Sk)
call sparse_error_report('MKL_SPARSE_z_ADD: Sk_+Ss=Sk', istat)
istat = MKL_SPARSE_DESTROY(Sk_)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: Sk_', istat)
istat = MKL_SPARSE_DESTROY(Ss)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: Ss ', istat)
endif
else
if(.not. flag_sparse_zero_SHs) then
istat = MKL_SPARSE_Z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, S0 , alpha, Ss, Sk)
call sparse_error_report('MKL_SPARSE_z_ADD: S0 +Ss=Sk', istat)
istat = MKL_SPARSE_DESTROY(S0)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: S0 ', istat)
istat = MKL_SPARSE_DESTROY(Ss)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: Ss ', istat)
endif
endif
if(.not. flag_sparse_zero_SHm) then
if(.not. flag_sparse_zero_SHs) then
call sparse_export_csr(Sk, SHk)
else
call sparse_export_csr(Sk_, SHk)
endif
elseif( flag_sparse_zero_SHm) then
if(.not. flag_sparse_zero_SHs) then
call sparse_export_csr(Sk, SHk)
elseif( flag_sparse_zero_SHs) then
call sparse_export_csr(S0, SHk)
endif
endif
if(PPRAM%flag_use_overlap) then
call sparse_export_csr(S_Sk, SSk)
endif
else
call kproduct_pauli_0_CSR(SH0)
call sparse_create_csr_handle(S0, SH0)
if(PPRAM%flag_use_overlap) then
call kproduct_pauli_0_CSR(SS0)
call sparse_create_csr_handle(S_Sk, SS0)
endif
if(.not. flag_sparse_zero_SHm) call sparse_create_csr_handle(Sm, SHm)
alpha = 1d0
if(.not. flag_sparse_zero_SHm) then
istat = MKL_SPARSE_Z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, S0 , alpha, Sm, Sk)
call sparse_error_report('MKL_SPARSE_z_ADD: S0+Sm=Sk', istat)
endif
if(.not. flag_sparse_zero_SHm) then
call sparse_export_csr(Sk, SHk)
else
call sparse_export_csr(S0, SHk)
endif
if(PPRAM%flag_use_overlap) then
call sparse_export_csr(S_Sk, SSk)
endif
istat = MKL_SPARSE_DESTROY(Sm)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: Sm ', istat)
istat = MKL_SPARSE_DESTROY(S0)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: S0 ', istat)
endif
elseif(.not. PINPT%flag_collinear .and. .not. PINPT%flag_noncollinear) then
allocate(SHk%H(SH0%nnz))
allocate(SHk%J(SH0%nnz))
allocate(SHk%I(SH0%msize + 1))
SHk%H = SH0%H
SHk%I = SH0%I
SHk%J = SH0%J
SHk%nnz = SH0%nnz
SHk%msize = SH0%msize
if(PPRAM%flag_use_overlap) then
allocate(SSk%H(SS0%nnz))
allocate(SSk%J(SS0%nnz))
allocate(SSk%I(SS0%msize + 1))
SSk%H = SS0%H
SSk%I = SS0%I
SSk%J = SS0%J
SSk%nnz = SS0%nnz
SSk%msize = SS0%msize
endif
endif
return
endsubroutine
subroutine get_hamk_sparse(SHk, SH0, SHm, SHs, is, kp, PINPT, PPRAM, neig, NN_TABLE, flag_init, flag_phase, &
flag_sparse_zero_SHm, flag_sparse_zero_SHs)
use parameters, only : incar, hopping, spmat, params
use mpi_setup
use phase_factor
use do_math
use kronecker_prod
use sparse_tool
#ifdef MKL_SPARSE
use MKL_SPBLAS
#endif
use time
use print_io
implicit none
type (incar ) :: PINPT
type (params ) :: PPRAM
type (hopping) :: NN_TABLE
type (spmat ) :: SHk, SH0, SHm, SHs
#ifdef MKL_SPARSE
type (SPARSE_MATRIX_T) :: Sk, Sk_, S0, Sm, Ss
#endif
logical flag_init, flag_phase
integer*4 is, neig, ispinor, ispin
integer*4 istat
real*8 kp(3)
complex*16 alpha
logical flag_sparse_zero_SHm ! if the sparse matrix has no non-zero element (nnz = 0),
logical flag_sparse_zero_SHs ! this flag will be .true. and will skip related construction routine.
! logical flag_slater_koster
real*8 t1, t0
integer*4 mpierr
! DEALLOCATION of array
! Hk: initialized every call (deallocated with cal_eig_Hk_sparse exit)
! H0: initialized every call (deallocated with cal_eig_Hk_sparse exit)
! Hm: initialized in the first call (deallocated after get_eig exit)
! Hs: initialized in the first call if slater-koster (deallocated after get_eig exit)
! initialized every call if .not. slater-koster (deallocated after cal_eig_Hk_sparse exit)
! H0 will be constructed for spin-1. For spin-2, copied from spin-1
if(is .eq. 1) call set_ham0_sparse (SH0, kp, PINPT, PPRAM, neig, NN_TABLE, flag_phase)
if(flag_init) then ! setup k-independent Hamiltonian: Hm, Hs (if .not. slater_koster)
if(PINPT%flag_collinear .or. PINPT%flag_noncollinear) then
call set_ham_mag_sparse(SHm, NN_TABLE, PPRAM, neig, PINPT%ispinor, &
flag_sparse_zero_SHm, PINPT%flag_collinear, PINPT%flag_noncollinear)
if(PINPT%flag_soc .and. PPRAM%flag_slater_koster .and. PINPT%flag_noncollinear) then
call set_ham_soc_sparse(SHs, 0d0, PPRAM, neig, NN_TABLE, flag_phase, flag_sparse_zero_SHs, .true., F_IJ)
endif
endif
flag_init = .false.
endif
if(PINPT%flag_collinear) then
if(.not. flag_sparse_zero_SHm) then
call sparse_create_csr_handle(S0, SH0)
call sparse_create_csr_handle(Sm, SHm)
alpha = ((-1d0)**(is+1))
! Sk(up) = S0 + Sm , Sk(dn) = S0 - Sm
istat = MKL_SPARSE_z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, S0 , alpha, Sm, Sk)
call sparse_error_report('MKL_SPARSE_z_ADD: S0+Sm=Sk', istat)
call sparse_export_csr(Sk, SHk)
istat = MKL_SPARSE_DESTROY(Sm)
call sparse_error_report('MKL_SPARSE_DESTROY: Sm ', istat)
istat = MKL_SPARSE_DESTROY(S0)
call sparse_error_report('MKL_SPARSE_DESTROY: S0 ', istat)
elseif(flag_sparse_zero_SHm) then
SHk%msize = SH0%msize
SHk%nnz = SH0%nnz
allocate(SHk%H(SH0%nnz )) ; SHk%H = SH0%H
allocate(SHk%J(SH0%nnz )) ; SHk%J = SH0%J
allocate(SHk%I(SH0%msize+1)) ; SHk%I = SH0%I
endif
elseif(PINPT%flag_noncollinear) then
if(PINPT%flag_soc) then
if(.not. PPRAM%flag_slater_koster) then
!set up k-dependent SOC in the case of 'cc' orbitals
call set_ham_soc_sparse(SHs, kp, PPRAM, neig, NN_TABLE, flag_phase, flag_sparse_zero_SHs, .false., F_IJ)
endif
call kproduct_pauli_0_CSR(SH0)
call sparse_create_csr_handle(S0, SH0)
if(.not. flag_sparse_zero_SHm) call sparse_create_csr_handle(Sm, SHm)
if(.not. flag_sparse_zero_SHs) call sparse_create_csr_handle(Ss, SHs)
alpha = 1d0
if(.not. flag_sparse_zero_SHm) then
istat = MKL_SPARSE_Z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, S0 , alpha, Sm, Sk_)
call sparse_error_report('MKL_SPARSE_z_ADD: S0+Sm=Sk_', istat)
istat = MKL_SPARSE_DESTROY(Sm)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: Sm ', istat)
istat = MKL_SPARSE_DESTROY(S0)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: S0 ', istat)
endif
if(.not. flag_sparse_zero_SHm) then
if(.not. flag_sparse_zero_SHs) then
istat = MKL_SPARSE_Z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, Sk_ , alpha, Ss, Sk)
call sparse_error_report('MKL_SPARSE_z_ADD: Sk_+Ss=Sk', istat)
istat = MKL_SPARSE_DESTROY(Sk_)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: Sk_', istat)
istat = MKL_SPARSE_DESTROY(Ss)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: Ss ', istat)
endif
else
if(.not. flag_sparse_zero_SHs) then
istat = MKL_SPARSE_Z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, S0 , alpha, Ss, Sk)
call sparse_error_report('MKL_SPARSE_z_ADD: S0 +Ss=Sk', istat)
istat = MKL_SPARSE_DESTROY(S0)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: S0 ', istat)
istat = MKL_SPARSE_DESTROY(Ss)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: Ss ', istat)
endif
endif
if(.not. flag_sparse_zero_SHm) then
if(.not. flag_sparse_zero_SHs) then
call sparse_export_csr(Sk, SHk)
else
call sparse_export_csr(Sk_, SHk)
endif
elseif( flag_sparse_zero_SHm) then
if(.not. flag_sparse_zero_SHs) then
call sparse_export_csr(Sk, SHk)
elseif( flag_sparse_zero_SHs) then
call sparse_export_csr(S0, SHk)
endif
endif
else
call kproduct_pauli_0_CSR(SH0)
call sparse_create_csr_handle(S0, SH0)
if(.not. flag_sparse_zero_SHm) call sparse_create_csr_handle(Sm, SHm)
alpha = 1d0
if(.not. flag_sparse_zero_SHm) then
istat = MKL_SPARSE_Z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, S0 , alpha, Sm, Sk)
call sparse_error_report('MKL_SPARSE_z_ADD: S0+Sm=Sk', istat)
endif
if(.not. flag_sparse_zero_SHm) then
call sparse_export_csr(Sk, SHk)
else
call sparse_export_csr(S0, SHk)
endif
istat = MKL_SPARSE_DESTROY(Sm)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: Sm ', istat)
istat = MKL_SPARSE_DESTROY(S0)
if(istat .gt. 1) call sparse_error_report('MKL_SPARSE_DESTROY: S0 ', istat)
endif
elseif(.not. PINPT%flag_collinear .and. .not. PINPT%flag_noncollinear) then
allocate(SHk%H(SH0%nnz))
allocate(SHk%J(SH0%nnz))
allocate(SHk%I(SH0%msize + 1))
SHk%H = SH0%H
SHk%I = SH0%I
SHk%J = SH0%J
SHk%nnz = SH0%nnz
SHk%msize = SH0%msize
endif
return
endsubroutine
subroutine set_ham0_sparse_overlap(SH0, SS0, kpoint, PINPT, PPRAM, neig, NN_TABLE, flag_phase)
use parameters, only : zi, hopping, incar, spmat, eta, params
use phase_factor
use mpi_setup
use sparse_tool
use print_io
implicit none
type (hopping) :: NN_TABLE
type (incar ) :: PINPT
type (params ) :: PPRAM
type (spmat ) :: SH0_COO, SH0
type (spmat ) :: SS0_COO, SS0
integer*4 neig , ii, jj, nn, m, mm
integer*4 ivel_axis
real*8 kpoint(3), tol
integer*4 I(NN_TABLE%n_neighbor*2) ! default maximum : n_neighbor
integer*4 J(NN_TABLE%n_neighbor*2)
complex*16 H(NN_TABLE%n_neighbor*2)
complex*16 S(NN_TABLE%n_neighbor*2) ! for overlap
complex*16 IJ(NN_TABLE%n_neighbor*2)
complex*16 Eij, Tij
complex*16 Sij
logical flag_phase
real*8 abstol
H=0.0d0
S=0.0d0
IJ= (-1d0,-1d0)
mm = 0
tol=NN_TABLE%onsite_tolerance
nn_:do nn=1,NN_TABLE%n_neighbor
ii=NN_TABLE%i_matrix(nn)
jj=NN_TABLE%j_matrix(nn)
call get_hopping_integral(Eij, NN_TABLE, nn, PPRAM, tol, kpoint, F_IJ, flag_phase, .false., PINPT%flag_load_nntable)
call get_hopping_integral(Sij, NN_TABLE, nn, PPRAM, tol, kpoint, F_IJ, flag_phase, .true. , PINPT%flag_load_nntable)
if(ii .eq. jj .and. NN_TABLE%Dij(nn) <= tol) then
if(nint(PPRAM%param_const(4,NN_TABLE%local_U_param_index(ii))) .ge. 1) then
Tij = Eij + NN_TABLE%local_charge(ii)*PPRAM%param_const(5,(NN_TABLE%local_U_param_index(ii)))
else
Tij = Eij + NN_TABLE%local_charge(ii)*PPRAM%param((NN_TABLE%local_U_param_index(ii)))
endif
if(abs(Tij) .ge. eta) then
do m = 1, mm ! check previously stored array: if exist, overwrite Tij (Tii), otherwise, save new array
if( ii .eq. nint(real(IJ(m))) .and. jj .eq. nint(aimag(IJ(m))) ) then
H(m) = H(m) + Tij
S(m) = S(m) + 1d0 ! if onsite, overlap integral should be 1d0.
cycle nn_
endif
enddo
mm = mm + 1
I(mm) = ii
J(mm) = jj
H(mm) = Tij
S(mm) = 1d0 ! if onsite, overlap integral should be 1d0.
IJ(mm) = real(I(mm)) + real(J(mm)) * zi
endif
elseif(ii .eq. jj .and. NN_TABLE%Dij(nn) > tol) then
Tij = Eij
if(abs(Tij) .ge. eta) then
do m = 1, mm ! check previously stored array: if exist, overwrite Tij (Tii), otherwise, save new array
if( ii .eq. nint(real(IJ(m))) .and. jj .eq. nint(aimag(IJ(m))) ) then
H(m) = H(m) + Tij
S(m) = S(m) + Sij
cycle nn_
endif
enddo
mm = mm + 1
I(mm) = ii
J(mm) = jj
H(mm) = Tij
S(mm) = Sij
IJ(mm) = real(I(mm)) + real(J(mm)) * zi
endif
else
Tij = Eij
if(abs(Tij) .ge. eta) then
do m = 1, mm ! check previously stored array: if exist, overwrite Tij and Tji, otherwise, save new array
if( ii .eq. nint(real(IJ(m))) .and. jj .eq. nint(aimag(IJ(m))) ) then
H(m) = H(m) + Tij
H(m+1) = H(m+1) + conjg(Tij)
S(m) = S(m) + Sij
S(m+1) = S(m+1) + conjg(Sij)
cycle nn_
endif
enddo
mm = mm + 1
I(mm) = ii
J(mm) = jj
H(mm) = Tij
S(mm) = Sij
IJ(mm) = real(I(mm)) + real(J(mm)) * zi
mm = mm + 1
I(mm) = jj
J(mm) = ii
H(mm) = conjg(Tij)
S(mm) = conjg(Sij)
IJ(mm) = real(I(mm)) + real(J(mm)) * zi
if(mm .gt. NN_TABLE%n_neighbor*2) then
write(message,'(A)')' !WARN! Number of non-zero element NNZ > n_neighbor*2.' ; write_msg
write(message,'(A)')' Please check "set_ham0_sparse" routine. Exit program...' ; write_msg
stop
endif
endif
endif
enddo nn_
if(mm .eq. 0) then
write(message,'(A)')' !WARN! No non-zero element is found in preparing Hamiltonian H0.' ; write_msg
write(message,'(A)')' Please check your system, input file etc. Exit program...' ; write_msg
stop
endif
allocate(SH0_COO%H(mm))
allocate(SH0_COO%I(mm))
allocate(SH0_COO%J(mm))
SH0_COO%nnz = mm
SH0_COO%msize = neig
SH0_COO%H = H(1:mm)
SH0_COO%I = I(1:mm)
SH0_COO%J = J(1:mm)
call sparse_convert_coo_csr(SH0_COO, SH0)
allocate(SS0_COO%H(mm))
allocate(SS0_COO%I(mm))
allocate(SS0_COO%J(mm))
SS0_COO%nnz = mm
SS0_COO%msize = neig
SS0_COO%H = S(1:mm)
SS0_COO%I = I(1:mm)
SS0_COO%J = J(1:mm)
call sparse_convert_coo_csr(SS0_COO, SS0)
deallocate(SH0_COO%H)
deallocate(SH0_COO%I)
deallocate(SH0_COO%J)
return
endsubroutine
subroutine set_ham0_sparse(SH0, kpoint, PINPT, PPRAM, neig, NN_TABLE, flag_phase)
use parameters, only : zi, hopping, incar, spmat, eta, params
use phase_factor
use mpi_setup
use sparse_tool
use print_io
implicit none
type (hopping) :: NN_TABLE
type (incar ) :: PINPT
type (params ) :: PPRAM
type (spmat ) :: SH0_COO, SH0
integer*4 neig , ii, jj, nn, m, mm
integer*4 ivel_axis
real*8 kpoint(3), tol
integer*4 I(NN_TABLE%n_neighbor*2) ! default maximum : n_neighbor
integer*4 J(NN_TABLE%n_neighbor*2)
complex*16 H(NN_TABLE%n_neighbor*2)
complex*16 IJ(NN_TABLE%n_neighbor*2)
complex*16 Eij, Tij
logical flag_phase
real*8 abstol
H=0.0d0
IJ= (-1d0,-1d0)
mm = 0
tol=NN_TABLE%onsite_tolerance
nn_:do nn=1,NN_TABLE%n_neighbor
ii=NN_TABLE%i_matrix(nn)
jj=NN_TABLE%j_matrix(nn)
call get_hopping_integral(Eij, NN_TABLE, nn, PPRAM, tol, kpoint, F_IJ, flag_phase, .false., PINPT%flag_load_nntable)
if(ii .eq. jj .and. NN_TABLE%Dij(nn) <= tol) then
if(nint(PPRAM%param_const(4,NN_TABLE%local_U_param_index(ii))) .ge. 1) then
Tij = Eij + NN_TABLE%local_charge(ii)*PPRAM%param_const(5,(NN_TABLE%local_U_param_index(ii)))
else
Tij = Eij + NN_TABLE%local_charge(ii)*PPRAM%param((NN_TABLE%local_U_param_index(ii)))
endif
if(abs(Tij) .ge. eta) then
do m = 1, mm ! check previously stored array: if exist, overwrite Tij (Tii), otherwise, save new array
if( ii .eq. nint(real(IJ(m))) .and. jj .eq. nint(aimag(IJ(m))) ) then
H(m) = H(m) + Tij
cycle nn_
endif
enddo
mm = mm + 1
I(mm) = ii
J(mm) = jj
H(mm) = Tij
IJ(mm) = real(I(mm)) + real(J(mm)) * zi
endif
elseif(ii .eq. jj .and. NN_TABLE%Dij(nn) > tol) then
Tij = Eij
if(abs(Tij) .ge. eta) then
do m = 1, mm ! check previously stored array: if exist, overwrite Tij (Tii), otherwise, save new array
if( ii .eq. nint(real(IJ(m))) .and. jj .eq. nint(aimag(IJ(m))) ) then
H(m) = H(m) + Tij
cycle nn_
endif
enddo
mm = mm + 1
I(mm) = ii
J(mm) = jj
H(mm) = Tij
IJ(mm) = real(I(mm)) + real(J(mm)) * zi
endif
else
Tij = Eij
if(abs(Tij) .ge. eta) then
do m = 1, mm ! check previously stored array: if exist, overwrite Tij and Tji, otherwise, save new array
if( ii .eq. nint(real(IJ(m))) .and. jj .eq. nint(aimag(IJ(m))) ) then
H(m) = H(m) + Tij
H(m+1) = H(m+1) + conjg(Tij)
cycle nn_
endif
enddo
mm = mm + 1
I(mm) = ii
J(mm) = jj
H(mm) = Tij
IJ(mm) = real(I(mm)) + real(J(mm)) * zi
mm = mm + 1
I(mm) = jj
J(mm) = ii
H(mm) = conjg(Tij)
IJ(mm) = real(I(mm)) + real(J(mm)) * zi
if(mm .gt. NN_TABLE%n_neighbor*2) then
write(message,'(A)')' !WARN! Number of non-zero element NNZ > n_neighbor*2.' ; write_msg
write(message,'(A)')' Please check "set_ham0_sparse" routine. Exit program...' ; write_msg
stop
endif
endif
endif
enddo nn_
if(mm .eq. 0) then
write(message,'(A)')' !WARN! No non-zero element is found in preparing Hamiltonian H0.' ; write_msg
write(message,'(A)')' Please check your system, input file etc. Exit program...' ; write_msg
stop
endif
allocate(SH0_COO%H(mm))
allocate(SH0_COO%I(mm))
allocate(SH0_COO%J(mm))
SH0_COO%nnz = mm
SH0_COO%msize = neig
SH0_COO%H = H(1:mm)
SH0_COO%I = I(1:mm)
SH0_COO%J = J(1:mm)
call sparse_convert_coo_csr(SH0_COO, SH0)
deallocate(SH0_COO%H)
deallocate(SH0_COO%I)
deallocate(SH0_COO%J)
return
endsubroutine
subroutine set_ham_mag_sparse(SHm, NN_TABLE, PPRAM, neig, ispinor, &
flag_sparse_zero, flag_collinear, flag_noncollinear)
use parameters, only : zi, hopping, spmat, eta, params
use mpi_setup
use sparse_tool
use print_io
implicit none
type (hopping) :: NN_TABLE
type (params ) :: PPRAM
type (spmat ) :: SHm_COO, SHm
integer*4 neig, ispinor
integer*4 nn, ii, mm, m
complex*16 Tij, Tij_x, Tij_y, Tij_z
integer*4 I(NN_TABLE%n_neighbor*4) ! default maximum : n_neighbor*4
integer*4 J(NN_TABLE%n_neighbor*4)
complex*16 H(NN_TABLE%n_neighbor*4)
complex*16 IJ(NN_TABLE%n_neighbor*4)
logical flag_sparse_zero
logical flag_collinear, flag_noncollinear
flag_sparse_zero = .false.
H=0d0
mm = 0
IJ = (-1d0,-1d0)
if(flag_collinear) then
nn_c:do nn = 1, neig
if(NN_TABLE%stoner_I_param_index(nn) .gt. 0) then ! if stoner parameter has been set...
if(nint(PPRAM%param_const(4,NN_TABLE%stoner_I_param_index(nn))) .eq. 1) then ! if i-th basis has constraint .true.
Tij = -0.5d0 * NN_TABLE%local_moment(1,nn) * PPRAM%param_const(5,NN_TABLE%stoner_I_param_index(nn))
else
Tij = -0.5d0 * NN_TABLE%local_moment(1,nn) * PPRAM%param(NN_TABLE%stoner_I_param_index(nn))
endif
if(abs(Tij) .ge. eta) then
do m = 1, mm ! check previously stored array: if exist, overwrite Tij (Tii), otherwise, save new array
if( nn .eq. nint(real(IJ(m))) ) then
H(m) = H(m) + Tij
cycle nn_c
endif
enddo
mm = mm + 1
I(mm) = nn
J(mm) = nn
H(mm) = Tij
IJ(mm) = real(I(mm))
if(mm .gt. NN_TABLE%n_neighbor*4) then
write(message,'(A)')' !WARN! Number of non-zero element NNZ > n_neighbor*4.' ; write_msg
write(message,'(A)')' Please check "set_ham_mag_sparse" routine. Exit program...' ; write_msg
stop
endif
endif
endif
enddo nn_c
elseif(flag_noncollinear) then
nn_nc:do nn = 1, neig
if(NN_TABLE%stoner_I_param_index(nn) .gt. 0) then ! if stoner parameter has been set...
if(nint(PPRAM%param_const(4,NN_TABLE%stoner_I_param_index(nn))) .eq. 1) then ! if i-th basis has constraint .true.
Tij_x = - 0.5d0 * NN_TABLE%local_moment_rot(1,nn) * PPRAM%param_const(5,NN_TABLE%stoner_I_param_index(nn))
Tij_y = 0.5d0 * NN_TABLE%local_moment_rot(2,nn) * PPRAM%param_const(5,NN_TABLE%stoner_I_param_index(nn)) * zi
Tij_z = - 0.5d0 * NN_TABLE%local_moment_rot(3,nn) * PPRAM%param_const(5,NN_TABLE%stoner_I_param_index(nn))
else
Tij_x = - 0.5d0 * NN_TABLE%local_moment_rot(1,nn) * PPRAM%param(NN_TABLE%stoner_I_param_index(nn))
Tij_y = 0.5d0 * NN_TABLE%local_moment_rot(2,nn) * PPRAM%param(NN_TABLE%stoner_I_param_index(nn)) * zi
Tij_z = - 0.5d0 * NN_TABLE%local_moment_rot(3,nn) * PPRAM%param(NN_TABLE%stoner_I_param_index(nn))
endif
if(abs(Tij_x) + abs(Tij_y) + abs(Tij_z) .ge. eta) then
do m = 1, mm
if( nn .eq. nint(real(IJ(m))) .and. nn .eq. nint(aimag(IJ(m))) ) then
H(m) = H(m ) + Tij_z
H(m+1) = H(m+1) - Tij_z
H(m+2) = H(m+2) + Tij_x + Tij_y
H(m+3) = H(m+3) + Tij_x - Tij_y
cycle nn_nc
endif
enddo
mm = mm + 1
I(mm) = nn
J(mm) = nn
H(mm) = Tij_z
IJ(mm) = real(I(mm)) + zi * real(J(mm))
mm = mm + 1
I(mm) = nn + neig
J(mm) = nn + neig
H(mm) = -Tij_z
IJ(mm) = real(I(mm)) + zi * real(J(mm))
mm = mm + 1
I(mm) = nn
J(mm) = nn + neig
H(mm) = Tij_x + Tij_y
IJ(mm) = real(I(mm)) + zi * real(J(mm))
mm = mm + 1
I(mm) = nn + neig
J(mm) = nn
H(mm) = Tij_x - Tij_y
IJ(mm) = real(I(mm)) + zi * real(J(mm))
if(mm .gt. NN_TABLE%n_neighbor*4) then
write(message,'(A)')' !WARN! Number of non-zero element NNZ > n_neighbor*4.' ; write_msg
write(message,'(A)')' Please check "set_ham_mag_sparse" routine. Exit program...' ; write_msg
stop
endif
endif
endif
enddo nn_nc
endif
if(mm .eq. 0) then
flag_sparse_zero = .true.
elseif(mm .ge. 1) then
allocate(SHm_COO%H(mm))
allocate(SHm_COO%I(mm))
allocate(SHm_COO%J(mm))
SHm_COO%nnz = mm
SHm_COO%msize = neig * ispinor
SHm_COO%H = H(1:mm)
SHm_COO%I = I(1:mm)
SHm_COO%J = J(1:mm)
call sparse_convert_coo_csr(SHm_COO, SHm)
deallocate(SHm_COO%H)
deallocate(SHm_COO%I)
deallocate(SHm_COO%J)
endif
return
endsubroutine
subroutine set_ham_soc_sparse(SHs, kp , PPRAM, neig, NN_TABLE, flag_phase, flag_sparse_zero, flag_slater_koster, FIJ)
use parameters, only : zi, hopping, params, spmat, eta, pi, pi2, params
use sparse_tool
use kronecker_prod
use mpi_setup
use phase_factor
use get_parameter
use print_io
#ifdef MKL_SPARSE
use MKL_SPBLAS
#endif
implicit none
interface
function FIJ(k,R)
complex*16 :: FIJ
real*8, intent(in) :: k(3)
real*8, intent(in) :: R(3)
endfunction
end interface
type (hopping) :: NN_TABLE
type (params ) :: PPRAM
type (spmat ) :: COO_x, COO_y, COO_z, CSR_x, CSR_y, CSR_z, SHs
type (SPARSE_MATRIX_T) :: SHx, SHy, SHz, SHxy, SHxyz
integer*4 neig
integer*4 nn, ii,jj, mm, m
integer*4 istat
integer*4 soc_index, rashba_index
real*8 lambda_soc, lambda_rashba
real*8 kp(3)
logical flag_phase, flag_sparse_zero, flag_slater_koster
complex*16 Tij, Tij_x, Tij_y, Tij_z
complex*16 F
integer*4 I(NN_TABLE%n_neighbor*2) ! default maximum : n_neighbor*4
integer*4 J(NN_TABLE%n_neighbor*2)
complex*16 Hx(NN_TABLE%n_neighbor*2)
complex*16 Hy(NN_TABLE%n_neighbor*2)
complex*16 Hz(NN_TABLE%n_neighbor*2)
complex*16 IJ(NN_TABLE%n_neighbor*2)
complex*16 alpha
complex*16 L_x, L_y, L_z
external L_x, L_y, L_z
character*8 ci_orb, cj_orb
character*20 ci_atom, cj_atom
real*8 lsign, hsign
real*8 hop_signx, hop_signy, hop_signatom
complex*16 prod
flag_sparse_zero = .false.
alpha = 1d0
mm = 0
IJ = (-1d0, -1d0)
if(flag_slater_koster) then
Hx = 0d0
Hy = 0d0
Hz = 0d0
nn_sk:do nn = 1, NN_TABLE%n_neighbor
soc_index = NN_TABLE%soc_param_index(nn)
ii = NN_TABLE%i_matrix(nn) ; jj = NN_TABLE%j_matrix(nn)
! set SOC hamiltonian based on atomic orbitals or
! set SOC hamiltonian based on 'xx' type orbitals which are composed by linear combination of atomic orbitals
if( soc_index .gt. 0 .and. (NN_TABLE%p_class(nn) .eq. 'pp' .or. NN_TABLE%p_class(nn) .eq. 'dd' &
.or. NN_TABLE%p_class(nn) .eq. 'xx' ) ) then
call get_param(PPRAM, soc_index, 1, lambda_soc )
! CALCULATE <orb_i|LS|orb_j>
Tij_x = lambda_soc * L_x(NN_TABLE%ci_orb(nn), NN_TABLE%cj_orb(nn), NN_TABLE%p_class(nn))
Tij_y = lambda_soc * L_y(NN_TABLE%ci_orb(nn), NN_TABLE%cj_orb(nn), NN_TABLE%p_class(nn))
Tij_z = lambda_soc * L_z(NN_TABLE%ci_orb(nn), NN_TABLE%cj_orb(nn), NN_TABLE%p_class(nn))
if(abs(Tij_x) + abs(Tij_y) + abs(Tij_z) .ge. eta) then
mm = mm + 1
I(mm) = ii
J(mm) = jj
Hx(mm) = Tij_x
Hy(mm) = Tij_y
Hz(mm) = Tij_z
mm = mm + 1
I(mm) = jj
J(mm) = ii
Hx(mm) = conjg(Tij_x)
Hy(mm) = conjg(Tij_y)
Hz(mm) = conjg(Tij_z)
if(mm .gt. NN_TABLE%n_neighbor*4) then
write(message,'(A)')' !WARN! Number of non-zero element NNZ > n_neighbor*4.' ; write_msg
write(message,'(A)')' Please check "set_ham_soc_sparse" routine. Exit program...' ; write_msg
stop
endif
endif
endif
enddo nn_sk
if(mm .eq. 0) then
flag_sparse_zero = .true.
elseif(mm .ge. 1) then
allocate(COO_x%H(mm));allocate(COO_y%H(mm));allocate(COO_z%H(mm))
allocate(COO_x%I(mm));allocate(COO_y%I(mm));allocate(COO_z%I(mm))
allocate(COO_x%J(mm));allocate(COO_y%J(mm));allocate(COO_z%J(mm))
COO_x%nnz = mm ; COO_x%msize = neig
COO_y%nnz = mm ; COO_y%msize = neig
COO_z%nnz = mm ; COO_z%msize = neig
COO_x%H = Hx(1:mm) ; COO_x%I = I(1:mm) ; COO_x%J = J(1:mm)
COO_y%H = Hy(1:mm) ; COO_y%I = I(1:mm) ; COO_y%J = J(1:mm)
COO_z%H = Hz(1:mm) ; COO_z%I = I(1:mm) ; COO_z%J = J(1:mm)
call sparse_convert_coo_csr(COO_x, CSR_x)
call sparse_convert_coo_csr(COO_y, CSR_y)
call sparse_convert_coo_csr(COO_z, CSR_z)
!SET UP Hamiltonian H_soc*sigma
call kproduct_pauli_x_CSR(CSR_x)
call kproduct_pauli_y_CSR(CSR_y)
call kproduct_pauli_z_CSR(CSR_z)
call sparse_create_csr_handle(SHx, CSR_x)
call sparse_create_csr_handle(SHy, CSR_y)
call sparse_create_csr_handle(SHz, CSR_z)
istat = MKL_SPARSE_z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, SHx , alpha, SHy, SHxy)
call sparse_error_report('MKL_SPARSE_z_ADD: SHx+SHy=SHxy', istat)
istat = MKL_SPARSE_z_ADD(SPARSE_OPERATION_NON_TRANSPOSE, SHxy, alpha, SHz, SHxyz)
call sparse_error_report('MKL_SPARSE_z_ADD: SHxy+SHz=SHxyz', istat)
call sparse_export_csr(SHxyz, SHs)
deallocate(COO_x%H);deallocate(COO_y%H);deallocate(COO_z%H)
deallocate(COO_x%I);deallocate(COO_y%I);deallocate(COO_z%I)
deallocate(COO_x%J);deallocate(COO_y%J);deallocate(COO_z%J)
deallocate(CSR_x%H);deallocate(CSR_y%H);deallocate(CSR_z%H)
deallocate(CSR_x%I);deallocate(CSR_y%I);deallocate(CSR_z%I)
deallocate(CSR_x%J);deallocate(CSR_y%J);deallocate(CSR_z%J)
istat = MKL_SPARSE_DESTROY(SHx)
call sparse_error_report('MKL_SPARSE_DESTROY: SHx', istat)
istat = MKL_SPARSE_DESTROY(SHy)
call sparse_error_report('MKL_SPARSE_DESTROY: SHy', istat)
istat = MKL_SPARSE_DESTROY(SHz)
call sparse_error_report('MKL_SPARSE_DESTROY: SHz', istat)
istat = MKL_SPARSE_DESTROY(SHxy)
call sparse_error_report('MKL_SPARSE_DESTROY: SHxy', istat)
endif
elseif(.not. flag_slater_koster) then
Hx = 0d0
Hy = 0d0
Hz = 0d0
!WARNING!! This setting is only valid for Bi/Si(110) case with certain atomic geometry and lattice vectors,
! since the sign convention is only valid and meaningful for this particular case.
! If you are dealing with other system, please construct your own hamltonian setup.
nn_cc:do nn = 1, NN_TABLE%n_neighbor
soc_index = NN_TABLE%cc_index_set(2,nn)
rashba_index = NN_TABLE%cc_index_set(3,nn)
ii = NN_TABLE%i_matrix(nn) ; jj = NN_TABLE%j_matrix(nn)
if(flag_phase) then
F = FIJ(kp, NN_TABLE%Rij(:,nn))
elseif(.not. flag_phase) then
F = FIJ(kp, NN_TABLE%R (:,nn))
endif
if( soc_index .ge. 1 .and. rashba_index .ge. 1) then
call get_param(PPRAM, soc_index, 1, lambda_soc )
call get_param(PPRAM, rashba_index, 1, lambda_rashba)
! ! set Rashba-SOC between i_orb and j_orb separated by |dij|, originated from E-field normal to surface
Tij_x = zi * lambda_rashba * NN_TABLE%Rij(2,nn)/NN_TABLE%Dij(nn) * F ! sigma_x
Tij_y = zi * lambda_rashba *-NN_TABLE%Rij(1,nn)/NN_TABLE%Dij(nn) * F ! sigma_y
! set SOC between i_orb and j_orb separated by |dij|,
! originated from E-field due to neighbor atom nearby the hopping path
! H_SOC = sigma_<<ij>> i * lsoc * v_ij * ci' * sigma_z * cj
! v_ij = di x dj / (|di x dj|) , di(dj) are vector connecting nearest neigbohor
! atom from i (to j).
hop_signx= NN_TABLE%Rij(1,nn)/NN_TABLE%Dij(nn)
hop_signy= NN_TABLE%Rij(2,nn)/NN_TABLE%Dij(nn)
ci_atom = NN_TABLE%site_cindex(NN_TABLE%i_atom(nn))
cj_atom = NN_TABLE%site_cindex(NN_TABLE%j_atom(nn))
if( ci_atom(1:2) .eq. 'b1') hop_signatom = 1.0
if( ci_atom(1:2) .eq. 'b2') hop_signatom =-1.0
Tij_z = zi * lambda_soc * hop_signatom * (hop_signx + hop_signy) * F
call save_Hsoc_sparse(Tij_x, Tij_y, Tij_z, Hx, Hy, Hz, mm, ii, jj, I, J, IJ, NN_TABLE%n_neighbor)
elseif( soc_index .ge. 1 .and. rashba_index .eq. 0) then
call get_param(PPRAM, soc_index, 1, lambda_soc )
! ! This model is only for Kane-mele type of SOC. Be careful..
prod=exp(-2d0*zi * pi * dot_product((/2.45d0,0d0/), NN_TABLE%Rij(1:2,nn)))
hsign = sign(1d0,aimag(prod))
ci_atom = NN_TABLE%site_cindex(NN_TABLE%i_atom(nn))
cj_atom = NN_TABLE%site_cindex(NN_TABLE%j_atom(nn))
if( ci_atom(1:1) .eq. 'a') lsign = -1.0d0
if( ci_atom(1:1) .eq. 'b') lsign = 1.0d0
Tij_x = (0d0, 0d0)