LCOV - code coverage report
Current view: top level - wannier - wann_convert_fleur_w90.F90 (source / functions) Coverage Total Hit
Test: FLEUR test coverage Lines: 0.0 % 429 0
Test Date: 2025-06-14 04:34:23 Functions: 0.0 % 1 0

            Line data    Source code
       1              :       MODULE m_wann_convert_fleur_w90
       2              :       contains
       3            0 :       subroutine wann_convert_fleur_w90(jspins_in,l_nocosoc,wann)
       4              :       use m_types
       5              :       use m_juDFT
       6              :       use m_constants
       7              :       IMPLICIT NONE
       8              :       integer,intent(in) :: jspins_in
       9              :       logical,intent(in) :: l_nocosoc
      10              :       type(t_wann), intent(in) :: wann
      11              : 
      12              :       logical :: l_readunf,l_writeunf,l_conjg
      13              :       logical :: l_spinmat,l_paulimat
      14              :       character(len=20) :: filenamewrite
      15              :       character(len=15) :: writeform
      16              :       character(len=20) :: filenameread(3)
      17              :       character(len=15) :: readform
      18              :       integer :: filestoread,fileidx
      19              :       integer :: spn_in,nb_tmp,num_bands,nkp_tmp
      20              :       integer :: num_kpts,ierr,ik,counter,m,n,compo,s
      21              :       character(len=60) :: header
      22            0 :       complex,allocatable :: oper_temp(:,:)
      23            0 :       complex,allocatable :: oper_o(:,:,:,:)
      24              :       integer :: num_compos,jspins,nbnd,fullnkpts,nwfs,nkp,i,j
      25              :       integer :: num_bands1,num_bands2
      26            0 :       complex,allocatable :: matrix6(:,:,:,:,:,:)
      27              :       real :: a,b
      28              :       real :: s_real,s_img
      29              :       complex,parameter   :: ci=(0.0,1.0)
      30              :       integer :: dummy1,dummy2,dummy3,dummy4,dummy5,dummy6
      31              :       integer :: spin1,spin2,spinmat_dims,ikpt,dir,ii,jj
      32              :       real :: conversionfactor
      33              : !      real,parameter      :: hart=27.21138505  !take from m_constants
      34              :       integer :: jj_tmp,ii_tmp,j_tmp,i_tmp,dir_tmp,ikpt_tmp,test_tmp
      35              :       integer :: write_bands,firstband
      36              :       integer :: map3(3)
      37              :       
      38            0 :       call timestart("wann_convert_fleur_w90")
      39              : 
      40            0 :       do ik=1,3
      41            0 :          map3(ik)=ik
      42              :       enddo   
      43              : 
      44            0 :       if(l_nocosoc)then
      45              :          jspins=1
      46              :       else
      47              :          jspins=min(jspins_in,2)
      48              :       endif
      49              : 
      50              : ! Determine number of kpoints.
      51            0 :       spn_in=916
      52            0 :       open(spn_in,file='WF1.amn',form='formatted')
      53            0 :       read(spn_in,*)
      54            0 :       read(spn_in,*)nbnd,num_kpts,nwfs
      55            0 :       close(spn_in)
      56              : 
      57              : 
      58              : ! For hsomtxvec we need the total number of bands.
      59            0 :       num_bands1=wann%band_max(1)-wann%band_min(1)+1
      60            0 :       num_bands2=wann%band_max(2)-wann%band_min(2)+1
      61              : 
      62            0 :       if(l_nocosoc)then
      63              :         num_bands=num_bands1
      64              :       else  !assume that we use socinterpol
      65            0 :          num_bands=num_bands1+num_bands2
      66              :       endif   
      67              : 
      68              : 
      69            0 :       if(nbnd.ne.num_bands1) then
      70            0 :         write(*,*)"num_bands1=",num_bands1
      71            0 :         write(*,*)"nbnd=",nbnd
      72            0 :         call juDFT_error('discrepancy convert fleur_w90')
      73              :       endif   
      74              :       
      75              :       ! Defaults
      76            0 :       filestoread=1
      77            0 :       l_conjg=.false.
      78            0 :       l_spinmat=.false.
      79            0 :       l_paulimat=.false.
      80            0 :       num_compos=3
      81            0 :       write_bands=num_bands
      82            0 :       if(wann%l_mmn0_unf_to_spn_unf)then
      83            0 :          l_readunf=.true.
      84            0 :          readform='unformatted'
      85            0 :          l_writeunf=.true.
      86            0 :          writeform='unformatted'
      87            0 :          filenameread(1)='updown.mmn0_unf'
      88            0 :          if(jspins_in.eq.1.and..not.l_nocosoc)then
      89            0 :             filestoread=1
      90            0 :             filenameread(1)='WF1.mmn0_unf'
      91              :          else         
      92              :             filestoread=3
      93              :          endif         
      94            0 :          if(l_nocosoc)then
      95            0 :              filenameread(2)='WF1.socmmn0_unf'
      96            0 :              filenameread(3)='WF2.socmmn0_unf'
      97              :          else
      98            0 :              filenameread(2)='WF1.mmn0_unf'
      99            0 :              filenameread(3)='WF2.mmn0_unf'
     100              :          endif
     101            0 :          filenamewrite='WF1.spn'
     102            0 :          l_conjg=.true.
     103            0 :          conversionfactor=1.0
     104            0 :          l_paulimat=.true.
     105              :          
     106            0 :       elseif(wann%l_mmn0_to_spn_unf)then
     107            0 :          l_readunf=.false.
     108            0 :          readform='formatted'
     109            0 :          l_writeunf=.true.
     110            0 :          writeform='unformatted'
     111            0 :          filenameread(1)='updown.mmn0'
     112            0 :          if(jspins_in.eq.1.and..not.l_nocosoc)then
     113            0 :             filestoread=1
     114            0 :             filenameread(1)='WF1.mmn0_unf'
     115              :          else
     116              :             filestoread=3
     117              :          endif
     118            0 :          if(l_nocosoc)then
     119            0 :             filenameread(2)='WF1.socmmn0'
     120            0 :             filenameread(3)='WF2.socmmn0'
     121              :          else
     122            0 :             filenameread(2)='WF1.mmn0'
     123            0 :             filenameread(3)='WF2.mmn0'
     124              :          endif
     125            0 :          filenamewrite='WF1.spn'
     126            0 :          l_conjg=.true.
     127            0 :          conversionfactor=1.0
     128            0 :          l_paulimat=.true.
     129              :          
     130            0 :       elseif(wann%l_mmn0_to_spn)then
     131            0 :          l_readunf=.false.
     132            0 :          readform='formatted'
     133            0 :          l_writeunf=.false.
     134            0 :          writeform='formatted'
     135            0 :          filenameread(1)='updown.mmn0'
     136            0 :          if(jspins_in.eq.1.and..not.l_nocosoc)then
     137            0 :             filestoread=1
     138            0 :             filenameread(1)='WF1.mmn0_unf'
     139              :          else
     140              :             filestoread=3
     141              :          endif
     142            0 :          if(l_nocosoc)then
     143            0 :             filenameread(2)='WF1.socmmn0'
     144            0 :             filenameread(3)='WF2.socmmn0'
     145              :          else
     146            0 :             filenameread(2)='WF1.mmn0'
     147            0 :             filenameread(3)='WF2.mmn0'
     148              :          endif
     149            0 :          filenamewrite='WF1.spn'
     150            0 :          l_conjg=.true.
     151            0 :          conversionfactor=1.0
     152            0 :          l_paulimat=.true.
     153              : 
     154              :         
     155            0 :       elseif(wann%l_mmn0_to_spn2)then ! when socinterpolation is used
     156            0 :          l_readunf=.false.
     157            0 :          readform='formatted'
     158            0 :          l_writeunf=.false.
     159            0 :          writeform='formatted'
     160            0 :          filenameread(1)='updown.mmn0'
     161              :          
     162            0 :          if(l_nocosoc)then
     163            0 :             filenameread(2)='WF1.socmmn0'
     164            0 :             filenameread(3)='WF2.socmmn0'
     165              :          else
     166            0 :             filenameread(2)='WF1.mmn0'
     167            0 :             filenameread(3)='WF2.mmn0'
     168              :          endif
     169            0 :          filenamewrite='WF1.spn'
     170            0 :          l_conjg=.true.
     171            0 :          conversionfactor=1.0
     172            0 :          l_paulimat=.true.
     173            0 :          write_bands=num_bands/2
     174              : 
     175              : 
     176              : 
     177            0 :       elseif(wann%l_mmn0_unf_to_spn)then
     178            0 :          l_readunf=.true.
     179            0 :          readform='unformatted'
     180            0 :          l_writeunf=.false.
     181            0 :          writeform='formatted'
     182            0 :          filenameread(1)='updown.mmn0_unf'
     183            0 :          if(jspins_in.eq.1.and..not.l_nocosoc)then
     184            0 :             filestoread=1
     185            0 :             filenameread(1)='WF1.mmn0_unf'
     186              :          else
     187              :             filestoread=3
     188              :          endif
     189            0 :          if(l_nocosoc)then
     190            0 :             filenameread(2)='WF1.socmmn0_unf'
     191            0 :             filenameread(3)='WF2.socmmn0_unf'
     192              :          else
     193            0 :             filenameread(2)='WF1.mmn0_unf'
     194            0 :             filenameread(3)='WF2.mmn0_unf'
     195              :          endif
     196            0 :          filenamewrite='WF1.spn'
     197            0 :          l_conjg=.true.
     198            0 :          conversionfactor=1.0
     199            0 :          l_paulimat=.true.
     200              : 
     201              :         
     202            0 :       elseif(wann%l_perpmag_unf_to_tor_unf)then
     203            0 :          l_readunf=.true.
     204            0 :          readform='unformatted'
     205            0 :          l_writeunf=.true.
     206            0 :          writeform='unformatted'
     207            0 :          filestoread=1
     208            0 :          filenameread(1)='updown.perpmag_unf'
     209            0 :          filenamewrite='WF1.tor'
     210            0 :          conversionfactor=hartree_to_ev_const
     211            0 :          map3(1)=2
     212            0 :          map3(2)=1
     213              :         
     214            0 :       elseif(wann%l_perpmag_to_tor_unf)then
     215            0 :          l_readunf=.false.
     216            0 :          readform='formatted'
     217            0 :          l_writeunf=.true.
     218            0 :          writeform='unformatted'
     219            0 :          filestoread=1
     220            0 :          filenameread(1)='updown.perpmag'
     221            0 :          filenamewrite='WF1.tor'
     222            0 :          conversionfactor=hartree_to_ev_const
     223            0 :          map3(1)=2
     224            0 :          map3(2)=1
     225              :         
     226            0 :       elseif(wann%l_perpmag_to_tor)then
     227            0 :          l_readunf=.false.
     228            0 :          readform='formatted'
     229            0 :          l_writeunf=.false.
     230            0 :          writeform='formatted'
     231            0 :          filestoread=1
     232            0 :          filenameread(1)='updown.perpmag'
     233            0 :          filenamewrite='WF1.tor'
     234            0 :          conversionfactor=hartree_to_ev_const
     235            0 :          map3(1)=2
     236            0 :          map3(2)=1
     237              :          
     238            0 :       elseif(wann%l_perpmag_unf_to_tor)then
     239            0 :          l_readunf=.true.
     240            0 :          readform='unformatted'
     241            0 :          l_writeunf=.false.
     242            0 :          writeform='formatted'
     243            0 :          filestoread=1
     244            0 :          filenameread(1)='updown.perpmag_unf'
     245            0 :          filenamewrite='WF1.tor'
     246            0 :          conversionfactor=hartree_to_ev_const
     247            0 :          map3(1)=2
     248            0 :          map3(2)=1
     249              :         
     250            0 :       elseif(wann%l_hsomtxvec_unf_to_lmpzsoc_unf)then
     251            0 :          l_readunf=.true.
     252            0 :          readform='unformatted'
     253            0 :          l_writeunf=.true.
     254            0 :          writeform='unformatted'
     255            0 :          filestoread=1
     256            0 :          filenameread(1)='WF1.hsomtxvec_unf'
     257            0 :          filenamewrite='WF1.lmpzsoc'
     258            0 :          l_spinmat=.true.
     259            0 :          l_conjg=.true.
     260            0 :          spinmat_dims=3
     261            0 :          conversionfactor=hartree_to_ev_const         
     262              : !         write_bands=num_bands1
     263              :          
     264            0 :          if(l_nocosoc) call juDFT_error('noco_or_soc and hsomtxvec')      
     265            0 :       elseif(wann%l_hsomtxvec_to_lmpzsoc_unf)then
     266            0 :          l_readunf=.false.
     267            0 :          readform='formatted'
     268            0 :          l_writeunf=.true.
     269            0 :          writeform='unformatted'
     270            0 :          filestoread=1
     271            0 :          spinmat_dims=3
     272            0 :          filenameread(1)='WF1.hsomtxvec'
     273            0 :          filenamewrite='WF1.lmpzsoc'
     274            0 :          l_spinmat=.true.
     275            0 :          l_conjg=.true.
     276            0 :          conversionfactor=hartree_to_ev_const
     277              : !         write_bands=num_bands1
     278              :         
     279            0 :          if(l_nocosoc) call juDFT_error('noco_or_soc and hsomtxvec')   
     280            0 :       elseif(wann%l_hsomtxvec_to_lmpzsoc)then
     281            0 :          l_readunf=.false.
     282            0 :          readform='formatted'
     283            0 :          l_writeunf=.false.
     284            0 :          writeform='formatted'
     285            0 :          filestoread=1
     286            0 :          filenameread(1)='WF1.hsomtxvec'
     287            0 :          filenamewrite='WF1.lmpzsoc'
     288            0 :          l_spinmat=.true.
     289            0 :          spinmat_dims=3
     290            0 :          l_conjg=.true.
     291            0 :          conversionfactor=hartree_to_ev_const
     292              : !         write_bands=num_bands1
     293              :         
     294            0 :          if(l_nocosoc) call juDFT_error('noco_or_soc and hsomtxvec')   
     295            0 :       elseif(wann%l_hsomtxvec_unf_to_lmpzsoc)then
     296            0 :          l_readunf=.true.
     297            0 :          readform='unformatted'
     298            0 :          l_writeunf=.false.
     299            0 :          writeform='formatted'
     300            0 :          filestoread=1
     301            0 :          filenameread(1)='WF1.hsomtxvec_unf'
     302            0 :          filenamewrite='WF1.lmpzsoc'
     303            0 :          l_spinmat=.true.
     304            0 :          spinmat_dims=3
     305            0 :          l_conjg=.true.
     306            0 :          conversionfactor=hartree_to_ev_const
     307              : !         write_bands=num_bands1
     308              :         
     309            0 :          if(l_nocosoc) call juDFT_error('noco_or_soc and hsomtxvec')   
     310            0 :       elseif(wann%l_hsomtx_unf_to_hsoc_unf)then
     311            0 :          l_readunf=.true.
     312            0 :          readform='unformatted'
     313            0 :          l_writeunf=.true.
     314            0 :          writeform='unformatted'
     315            0 :          filestoread=1
     316            0 :          filenameread(1)='WF1.hsomtx_unf'
     317            0 :          filenamewrite='WF1.hsoc'
     318            0 :          l_spinmat=.true.
     319            0 :          num_compos=1
     320            0 :            spinmat_dims=1
     321            0 :          l_conjg=.true.
     322            0 :          conversionfactor=hartree_to_ev_const         
     323              : !       
     324              :             
     325            0 :       elseif(wann%l_hsomtx_to_hsoc_unf)then
     326            0 :          l_readunf=.false.
     327            0 :          readform='formatted'
     328            0 :          l_writeunf=.true.
     329            0 :          writeform='unformatted'
     330            0 :          filestoread=1
     331            0 :          filenameread(1)='WF1.hsomtx'
     332            0 :          filenamewrite='WF1.hsoc'
     333            0 :          l_spinmat=.true.
     334            0 :          num_compos=1
     335            0 :            spinmat_dims=1
     336            0 :          l_conjg=.true.
     337            0 :          conversionfactor=hartree_to_ev_const
     338              : !         
     339            0 :       elseif(wann%l_hsomtx_to_hsoc)then
     340            0 :          l_readunf=.false.
     341            0 :          readform='formatted'
     342            0 :          l_writeunf=.false.
     343            0 :          writeform='formatted'
     344            0 :          filestoread=1
     345            0 :          filenameread(1)='WF1.hsomtx'
     346            0 :          filenamewrite='WF1.hsoc'
     347            0 :          l_spinmat=.true.
     348            0 :          num_compos=1
     349            0 :            spinmat_dims=1
     350            0 :          l_conjg=.true.
     351            0 :          conversionfactor=hartree_to_ev_const
     352              : !       
     353            0 :       elseif(wann%l_hsomtx_unf_to_hsoc)then
     354            0 :          l_readunf=.true.
     355            0 :          readform='unformatted'
     356            0 :          l_writeunf=.false.
     357            0 :          writeform='formatted'
     358            0 :          filestoread=1
     359            0 :          num_compos=1
     360            0 :          filenameread(1)='WF1.hsomtx_unf'
     361            0 :          filenamewrite='WF1.hsoc'
     362            0 :          l_spinmat=.true.
     363            0 :            spinmat_dims=1
     364            0 :          l_conjg=.true.
     365            0 :          conversionfactor=hartree_to_ev_const
     366              : !       
     367              :          
     368              :          
     369              :       endif   
     370              : 
     371              : !---- read data in fleur-format
     372            0 :       spn_in=916
     373              :     
     374            0 :       do fileidx=1,filestoread
     375            0 :          write(*,*)"fileidx=",fileidx
     376            0 :          write(*,*)"filenameread(fileidx)=",filenameread(fileidx)
     377            0 :       open(spn_in,file=trim(filenameread(fileidx)),form=trim(readform))
     378            0 :       if(l_readunf)then
     379            0 :          header=trim(filenameread(fileidx))
     380            0 :         if(l_spinmat)then
     381              :            
     382            0 :            allocate( matrix6(2,2,num_bands1,num_bands1,spinmat_dims,num_kpts) )
     383              :            
     384            0 :            if(spinmat_dims==1)then
     385            0 :             read(spn_in)dummy1,dummy2,dummy3,dummy4,dummy5
     386              :            else
     387            0 :             read(spn_in)dummy1,dummy2,dummy3,dummy4,dummy5,dummy6
     388              :            endif
     389              :            
     390            0 :            do nkp=1,num_kpts
     391            0 :             read(spn_in)matrix6(:,:,:,:,:,nkp)
     392              :            enddo 
     393              :         else
     394            0 :           read(spn_in)nbnd,fullnkpts,nwfs
     395            0 :           num_bands=nbnd
     396            0 :           if(.not.l_nocosoc)num_bands=2.0*nbnd
     397            0 :           num_kpts=fullnkpts
     398            0 :           if(.not.allocated(oper_o))then
     399            0 :           allocate(oper_o(num_bands,num_bands,num_kpts,num_compos) )
     400            0 :           oper_o=cmplx(0.0,0.0)
     401              :           endif
     402            0 :           write(*,*)"before read(spn_in):nbnd,fullnkpts,fileidx=",nbnd,fullnkpts,fileidx
     403            0 :           if(.not.l_nocosoc  .and.  fileidx==1  )then
     404            0 :              if(jspins_in==1)then
     405            0 :                 if(.not.l_paulimat) call juDFT_error("check it",calledby="wann_convert_fleur_w90")
     406            0 :                 read(spn_in)oper_o(1:nbnd,1:nbnd,1:fullnkpts,2)
     407              :              else
     408            0 :                read(spn_in)oper_o(1:nbnd,1+nbnd:2*nbnd,1:fullnkpts,fileidx)
     409              :              endif  
     410              :           else
     411            0 :                 read(spn_in)oper_o(1:nbnd,1:nbnd,1:fullnkpts,fileidx)
     412              :               endif
     413              :         endif
     414              :       else
     415            0 :         if(l_spinmat)then
     416            0 :            spin1=2
     417            0 :            spin2=2
     418              :            
     419              : !          num_bands=nbnd
     420            0 :            allocate( matrix6(2,2,num_bands,num_bands,spinmat_dims,num_kpts) )
     421            0 :            num_bands1=nbnd
     422            0 :            num_bands2=nbnd
     423            0 :            read(spn_in,*)header
     424            0 :            read(spn_in,*)
     425            0 :            do ikpt=1,num_kpts
     426            0 :             do dir=1,spinmat_dims  
     427            0 :              do i = 1,num_bands2
     428            0 :               do j = 1,num_bands1
     429            0 :                do ii=1,spin1
     430            0 :                 do jj=1,spin2
     431            0 :                  if(spinmat_dims==3)then
     432            0 :        read (spn_in,'(6i5,3x,2f18.12)') jj_tmp,ii_tmp,j_tmp,i_tmp,dir_tmp,ikpt_tmp,   a,    b
     433            0 :                 test_tmp=abs(jj_tmp-jj)+abs(ii_tmp-ii)+abs(j_tmp-j)+abs(i_tmp-i)+abs(dir_tmp-dir)+abs(ikpt_tmp-ikpt)
     434            0 :                   if(test_tmp.ne.0)call juDFT_error('convert: test_tmp')
     435            0 :                   matrix6(jj,ii,j,i,dir,ikpt) = cmplx(a,b)
     436              :                  else
     437            0 :                  read (spn_in,'(5i5,3x,2f18.12)') jj_tmp,ii_tmp,j_tmp,i_tmp,ikpt_tmp,   a,    b
     438            0 :                 test_tmp=abs(jj_tmp-jj)+abs(ii_tmp-ii)+abs(j_tmp-j)+abs(i_tmp-i)+abs(ikpt_tmp-ikpt)
     439            0 :                   if(test_tmp.ne.0)call juDFT_error('convert: test_tmp')
     440            0 :                   matrix6(jj,ii,j,i,dir,ikpt) = cmplx(a,b)
     441              :                  endif
     442              :                 enddo !jj 
     443              :                enddo !ii
     444              :               enddo !j
     445              :              enddo !i
     446              :             enddo !dir 
     447              :            enddo !ikpt
     448              :         else
     449            0 :            read(spn_in,*)header
     450            0 :            read(spn_in,*)nbnd,fullnkpts,nwfs
     451              : 
     452            0 :            num_kpts=fullnkpts
     453            0 :            if(l_nocosoc)then
     454            0 :              num_bands=nbnd
     455            0 :              firstband=0
     456              :            else
     457            0 :              num_bands=2*nbnd
     458            0 :              if(fileidx.eq.1)then
     459            0 :                firstband=nbnd
     460              :              else
     461              :                firstband=0
     462              :              endif
     463              :            endif  
     464              : 
     465            0 :            if(.not.allocated(oper_o))then
     466            0 :            allocate(oper_o(num_bands,num_bands,num_kpts,num_compos) )
     467            0 :            oper_o=cmplx(0.0,0.0)
     468              :            endif
     469              :            
     470              : 
     471            0 :            do nkp=1,num_kpts
     472            0 :             do i=1,nbnd
     473            0 :              do j=1,nbnd
     474            0 :               read(spn_in,*)dummy1,dummy2,dummy3,a,b
     475              : !             paulimat(1,j,i+num_bands*(jspins-1),nkp)=cmplx(a,b)
     476              : 
     477            0 :                oper_o(j,i+firstband,nkp,fileidx)=cmplx(a,b)
     478              :              enddo !j
     479              :             enddo !i
     480              :            enddo !nkp
     481              :        endif
     482              :       endif
     483            0 :       close(spn_in)
     484              :       enddo !filestoread
     485              : 
     486              : 
     487            0 :       write(*,*)"before spinmat:l_spinmat=",l_spinmat
     488            0 :       if(l_spinmat)then
     489              : 
     490              : 
     491            0 :           write(*,*)"matrix6=",matrix6(1,1,2,1,2,1)
     492              : 
     493              : !         num_bands1=num_bands
     494              : !         num_bands2=num_bands
     495              : !         num_bands=2*num_bands
     496              : !         write(*,*)"num_bands1,num_bands2,num_bands=",num_bands1,
     497              : !     &                   num_bands2,num_bands
     498            0 :          allocate( oper_o(num_bands,num_bands,num_kpts,spinmat_dims) )
     499              :          if(.false.)then
     500              : !   Old variant with num_bands1==num_bands2:
     501              :            if(num_bands1.ne.num_bands2) call juDFT_error('convert: num_bands1.ne.num_bands2')
     502              :            do ikpt=1,fullnkpts
     503              :             do dir=1,spinmat_dims  
     504              :              do i = 1,num_bands2
     505              :               do j = 1,num_bands2
     506              :                do ii=1,spin1
     507              :                 do jj=1,spin2
     508              :          oper_o(j+(jj-1)*num_bands,i+(ii-1)*num_bands,dir,ikpt)=matrix6(jj,ii,j,i,dir,ikpt)
     509              :                 enddo !jj 
     510              :                enddo !ii
     511              :               enddo !j
     512              :              enddo !i
     513              :             enddo !dir 
     514              :            enddo !ikpt
     515              :         else   
     516            0 :           if(num_bands1.ne.num_bands2) call juDFT_error('convert: num_bands1.ne.num_bands2')
     517              : 
     518            0 :           if(l_nocosoc)then !compute the full SOC-matrix
     519            0 :            do ikpt=1,num_kpts
     520            0 :             do dir=1,spinmat_dims   
     521            0 :              do i = 1,num_bands1
     522            0 :               do j = 1,num_bands1
     523              :                  oper_o(j,i,ikpt,dir)=matrix6(1,1,j,i,dir,ikpt)+ &
     524              :                                     matrix6(1,2,j,i,dir,ikpt)+ &
     525              :                                     matrix6(2,1,j,i,dir,ikpt)+ &
     526            0 :                                     matrix6(2,2,j,i,dir,ikpt)
     527              :               enddo !j
     528              :              enddo !i
     529              :             enddo !dir
     530              :            enddo !ikpt
     531              :           else !rewrite the SOC-matrix for the purpose of socinterpol
     532              : 
     533              : 
     534            0 :           write(*,*)"before first loop, fullnkpts,num_dims,num_bands1=",num_kpts,spinmat_dims,num_bands1
     535            0 :            do ikpt=1,num_kpts
     536            0 :             do dir=1,spinmat_dims  
     537              : 
     538            0 :              do i = 1,num_bands1
     539            0 :               do j = 1,num_bands1
     540            0 :                    oper_o(j,i,ikpt,dir)=matrix6(1,1,j,i,dir,ikpt)
     541              : !                   write(*,*)"j,i,ikpt,dir,matrix6=",j,i,ikpt,dir,matrix6(1,1,j,i,dir,ikpt)
     542              :               enddo !j
     543              :              enddo !i
     544              : 
     545            0 :              do i = 1,num_bands1
     546            0 :               do j = 1,num_bands2
     547            0 :           oper_o(j+num_bands1,i,ikpt,dir)=matrix6(2,1,j,i,dir,ikpt)
     548              :               enddo !j
     549              :              enddo !i
     550              : 
     551            0 :              do i = 1,num_bands2
     552            0 :               do j = 1,num_bands1
     553            0 :          oper_o(j,i+num_bands2,ikpt,dir)=matrix6(1,2,j,i,dir,ikpt)
     554              :               enddo !j
     555              :              enddo !i
     556              : 
     557            0 :              do i = 1,num_bands2
     558            0 :               do j = 1,num_bands2
     559            0 :                    oper_o(j+num_bands1,i+num_bands1,ikpt,dir)=matrix6(2,2,j,i,dir,ikpt)
     560              :               enddo !j
     561              :              enddo !i
     562              : 
     563              :             enddo !dir 
     564              :            enddo !ikpt
     565              :           endif !nocosoc?
     566              :         endif   
     567              : 
     568              : !        write(*,*)"oper_o=",oper_o(2,1,1,2)
     569              : 
     570              :       endif
     571              : 
     572            0 :       do nkp=1,num_kpts
     573              : !          paulimat(2,:,:,nkp)=ci*paulimat(1,:,:,nkp)
     574              : !          paulimat(1,:,:,nkp)=paulimat(1,:,:,nkp)+transpose(conjg( paulimat(1,:,:,nkp) ))
     575              : !          paulimat(2,:,:,nkp)=paulimat(2,:,:,nkp)+transpose(conjg( paulimat(2,:,:,nkp) ))
     576              : 
     577            0 :          if(l_paulimat)then
     578              : !            write(*,*)"convert paulimat: num_bands=",num_bands
     579            0 :             if(l_nocosoc)then
     580            0 :              do i=1,num_bands1
     581            0 :               do j=1,num_bands1
     582            0 :                  oper_o(j,i,nkp,3)=oper_o(j,i,nkp,2)-oper_o(j,i,nkp,3)
     583              :               enddo   
     584              :              enddo
     585              :             else
     586              : 
     587              : 
     588              : !             write(*,*)"paulimat conversion:"
     589              : !             write(*,*)"num_bands1=",num_bands1
     590              : 
     591              : 
     592            0 :              if(jspins_in.eq.1)then
     593            0 :               do i=1,num_bands1
     594            0 :                do j=1,num_bands1
     595            0 :                  oper_o(j,i,nkp,3)=oper_o(j,i,nkp,2)
     596              :                enddo   
     597              :               enddo
     598              :               
     599            0 :               oper_o(:,:,nkp,1)=cmplx(0.0,0.0)
     600            0 :               do i=1,num_bands1
     601            0 :                do j=1,num_bands1
     602            0 :                  oper_o(j,i+nbnd,nkp,1)=oper_o(j,i,nkp,2)
     603              :                enddo   
     604              :               enddo
     605              :               
     606              :               
     607              :              endif
     608              : 
     609            0 :              do i=1,num_bands1
     610            0 :               do j=1,num_bands1
     611            0 :                  oper_o(j+num_bands1,i+num_bands1,nkp,3)=-1.0*oper_o(j,i,nkp,3)
     612              :               enddo   
     613              :              enddo
     614              : 
     615              : 
     616            0 :              do i=1,num_bands1
     617            0 :               do j=1,num_bands1
     618            0 :                  oper_o(j,i,nkp,3)=oper_o(j,i,nkp,2)
     619              :               enddo   
     620              :              enddo
     621              : 
     622              : !             do i=1,num_bands1
     623              : !                write(*,*)"i,oper_o=",i,oper_o(i,i,nkp,3)
     624              : !             enddo !i
     625              : 
     626              : !             do i=1,num_bands1
     627              : !              do j=1,num_bands1
     628              : !                 oper_o(j,i+num_bands1,nkp,1)=oper_o(j,i,nkp,1)
     629              : !              enddo   
     630              : !             enddo
     631              : 
     632              : !             do i=1,num_bands1
     633              : !              do j=1,num_bands1
     634              : !                 oper_o(j,i,nkp,1)=cmplx(0.0,0.0)
     635              : !              enddo   
     636              : !             enddo
     637              : 
     638              :             endif  
     639              :          endif
     640              : 
     641              : 
     642              : !         l_conjg=.false.
     643            0 :          if(l_conjg)then
     644              : !           write(*,*)"complex conjugation: num_bands=",num_bands
     645            0 :           do i=1,num_bands
     646            0 :            do j=1,num_bands
     647            0 :               oper_o(j,i,nkp,:)=conjg(oper_o(j,i,nkp,:))
     648              :            enddo   
     649              :           enddo
     650              :          endif   
     651              : 
     652            0 :          if(.not.l_spinmat)then
     653            0 :          if(l_conjg)then
     654            0 :             oper_o(:,:,nkp,2)=-ci*oper_o(:,:,nkp,1)
     655              :          else
     656            0 :             oper_o(:,:,nkp,2)=ci*oper_o(:,:,nkp,1)
     657              :          endif
     658            0 :          oper_o(:,:,nkp,1)=      oper_o(:,:,nkp,1)+transpose(conjg(oper_o(:,:,nkp,1)))
     659            0 :          oper_o(:,:,nkp,2)=      oper_o(:,:,nkp,2)+transpose(conjg(oper_o(:,:,nkp,2)))
     660              :          endif
     661              : 
     662              :       enddo     
     663              : 
     664              : 
     665              : !---- write data in w90-format
     666            0 :       spn_in=916
     667            0 :       nb_tmp=write_bands
     668            0 :       nkp_tmp=num_kpts
     669            0 :       open(spn_in,file=trim(filenamewrite),form=trim(writeform))
     670            0 :       if(l_writeunf)then
     671            0 :         write (spn_in) header
     672            0 :         write (spn_in) nb_tmp, nkp_tmp
     673              : 
     674            0 :         allocate (oper_temp(num_compos, (write_bands*(write_bands + 1))/2), stat=ierr)
     675            0 :         if (ierr /= 0) call juDFT_error('Error in allocating oper_temp',calledby='wann_convert_fleur_w90')
     676              : 
     677            0 :         do ik = 1, num_kpts
     678              : 
     679              :           counter = 0
     680            0 :           do m = 1, write_bands
     681            0 :             do n = 1, m
     682            0 :               counter = counter + 1
     683            0 :               do compo=1,num_compos
     684            0 :                 oper_temp(compo, counter)=oper_o(n, m, ik, map3(compo))
     685              : !              oper_o(n, m, ik, compo) = oper_temp(compo, counter)
     686              : !              oper_o(m, n, ik, compo) = conjg(oper_temp(compo, counter))
     687              :               enddo !compo
     688              :             end do !n
     689              :           end do !m
     690              : 
     691            0 :           oper_temp=oper_temp*conversionfactor
     692              : 
     693            0 :           write (spn_in) ((oper_temp(s, m), s=1, num_compos), m=1, (write_bands*(write_bands + 1))/2)
     694              :         end do !ik
     695              : 
     696              :       else
     697            0 :         write (spn_in, *) header
     698            0 :         write (spn_in, *) nb_tmp, nkp_tmp
     699              : 
     700            0 :         do ik = 1, num_kpts
     701            0 :           do m = 1, write_bands
     702            0 :             do n = 1, m
     703            0 :               do compo=1,num_compos
     704            0 :                   s_real=real(oper_o(n, m, ik, map3(compo)))*conversionfactor
     705            0 :                   s_img=aimag(oper_o(n, m, ik, map3(compo)))*conversionfactor
     706            0 :                   write (spn_in, *) s_real, s_img   !,compo,n, m, ik 
     707              : !               oper_o(n, m, ik, compo) = cmplx(s_real, s_img, dp)
     708              :               ! Read upper-triangular part, now build the rest
     709              : !              oper_o(m, n, ik, compo) = conjg(oper_o(n, m, ik, compo))
     710              :               enddo 
     711              :             end do
     712              :           end do
     713              :         enddo
     714              : 
     715              :       endif  
     716            0 :       close(spn_in)
     717              : 
     718            0 :       if(wann%l_mmn0_to_spn2)then
     719            0 :          open(spn_in,file="WF2.spn",form=trim(writeform))
     720              :          
     721            0 :          write (spn_in, *) header
     722            0 :          write (spn_in, *) nb_tmp, nkp_tmp
     723              : 
     724            0 :          do ik = 1, num_kpts
     725            0 :           do m = 1+write_bands,2*write_bands
     726            0 :             do n = 1+write_bands, m
     727            0 :               do compo=1,num_compos
     728            0 :                   s_real=real(oper_o(n, m, ik, compo))*conversionfactor
     729            0 :                   s_img=aimag(oper_o(n, m, ik, compo))*conversionfactor
     730            0 :                   write (spn_in, *) s_real, s_img
     731              : !               oper_o(n, m, ik, compo) = cmplx(s_real, s_img, dp)
     732              :               ! Read upper-triangular part, now build the rest
     733              : !              oper_o(m, n, ik, compo) = conjg(oper_o(n, m, ik, compo))
     734              :               enddo 
     735              :             end do
     736              :           end do
     737              :          enddo
     738              : 
     739            0 :          close(spn_in)
     740              :       endif !  wann%l_mmn0_to_spn2
     741              : 
     742            0 :       call timestop("wann_convert_fleur_w90")
     743            0 :       end subroutine wann_convert_fleur_w90
     744              :       END MODULE m_wann_convert_fleur_w90
        

Generated by: LCOV version 2.0-1