10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-07 06:33:49 +01:00
QuantumPackage/src/determinants/configuration_CI_sigma_helpers.irp.f

416 lines
14 KiB
Fortran
Raw Normal View History

2021-02-01 14:54:11 +01:00
subroutine obtain_associated_alphaI(idxI, Icfg, alphasIcfg, NalphaIcfg)
implicit none
use bitmasks
BEGIN_DOC
! Documentation for alphasI
! Returns the associated alpha's for
! the input configuration Icfg.
END_DOC
integer,intent(in) :: idxI ! The id of the Ith CFG
integer(bit_kind),intent(in) :: Icfg(N_int,2)
integer,intent(out) :: NalphaIcfg
integer(bit_kind),intent(out) :: alphasIcfg(N_int,2,*)
logical,dimension(:,:),allocatable :: tableUniqueAlphas
integer :: listholes(mo_num)
integer :: holetype(mo_num) ! 1-> SOMO 2->DOMO
integer :: nholes
integer :: nvmos
integer :: listvmos(mo_num)
integer :: vmotype(mo_num) ! 1 -> VMO 2 -> SOMO
integer*8 :: Idomo
integer*8 :: Isomo
integer*8 :: Jdomo
integer*8 :: Jsomo
integer*8 :: diffSOMO
integer*8 :: diffDOMO
integer :: ndiffSOMO
integer :: ndiffDOMO
integer :: ndiffAll
integer :: i
integer :: j
integer :: k
integer :: hole
integer :: p
integer :: q
integer :: countalphas
logical :: pqAlreadyGenQ
logical :: pqExistsQ
Isomo = iand(reunion_of_act_virt_bitmask(1,1),Icfg(1,1))
Idomo = iand(reunion_of_act_virt_bitmask(1,1),Icfg(1,2))
!print*,"Input cfg"
!call debug_spindet(Isomo,1)
!call debug_spindet(Idomo,1)
!print*,n_act_orb, "monum=",mo_num," n_core=",n_core_orb
! find out all pq holes possible
nholes = 0
! holes in SOMO
do i = n_core_orb+1,n_core_orb + n_act_orb
if(POPCNT(IAND(Isomo,IBSET(0_8,i-1))) .EQ. 1) then
2021-02-01 14:54:11 +01:00
nholes += 1
listholes(nholes) = i
holetype(nholes) = 1
endif
end do
! holes in DOMO
do i = n_core_orb+1,n_core_orb + n_act_orb
if(POPCNT(IAND(Idomo,IBSET(0_8,i-1))) .EQ. 1) then
2021-02-01 14:54:11 +01:00
nholes += 1
listholes(nholes) = i
holetype(nholes) = 2
endif
end do
! find vmos
listvmos = -1
vmotype = -1
nvmos = 0
do i = n_core_orb+1,n_core_orb + n_act_orb
!print *,i,IBSET(0,i-1),POPCNT(IAND(Isomo,(IBSET(0_8,i-1)))), POPCNT(IAND(Idomo,(IBSET(0_8,i-1))))
if(POPCNT(IAND(Isomo,(IBSET(0_8,i-1)))) .EQ. 0 .AND. POPCNT(IAND(Idomo,(IBSET(0_8,i-1)))) .EQ. 0) then
2021-02-01 14:54:11 +01:00
nvmos += 1
listvmos(nvmos) = i
vmotype(nvmos) = 1
else if(POPCNT(IAND(Isomo,(IBSET(0_8,i-1)))) .EQ. 1 .AND. POPCNT(IAND(Idomo,(IBSET(0_8,i-1)))) .EQ. 0 ) then
2021-02-01 14:54:11 +01:00
nvmos += 1
listvmos(nvmos) = i
vmotype(nvmos) = 2
end if
end do
!print *,"Nvmo=",nvmos
!print *,listvmos
!print *,vmotype
allocate(tableUniqueAlphas(mo_num,mo_num))
tableUniqueAlphas = .FALSE.
! Now find the allowed (p,q) excitations
Isomo = iand(reunion_of_act_virt_bitmask(1,1),Icfg(1,1))
Idomo = iand(reunion_of_act_virt_bitmask(1,1),Icfg(1,2))
!print *,"Isomo"
!call debug_spindet(Isomo,1)
!call debug_spindet(Idomo,1)
2021-02-01 21:18:48 +01:00
! TODO cfg_seniority_index
2021-02-01 14:54:11 +01:00
do i = 1,nholes
p = listholes(i)
do j = 1,nvmos
q = listvmos(j)
if(p == q) cycle
if(holetype(i) .EQ. 1 .AND. vmotype(j) .EQ. 1) then
! SOMO -> VMO
Jsomo = IBCLR(Isomo,p-1)
Jsomo = IBSET(Jsomo,q-1)
Jdomo = Idomo
else if(holetype(i) .EQ. 1 .AND. vmotype(j) .EQ. 2) then
! SOMO -> SOMO
Jsomo = IBCLR(Isomo,p-1)
Jsomo = IBCLR(Jsomo,q-1)
Jdomo = IBSET(Idomo,q-1)
else if(holetype(i) .EQ. 2 .AND. vmotype(j) .EQ. 1) then
! DOMO -> VMO
Jsomo = IBSET(Isomo,p-1)
Jsomo = IBSET(Jsomo,q-1)
Jdomo = IBCLR(Idomo,p-1)
else if(holetype(i) .EQ. 2 .AND. vmotype(j) .EQ. 2) then
! DOMO -> SOMO
Jsomo = IBSET(Isomo,p-1)
Jsomo = IBCLR(Jsomo,q-1)
Jdomo = IBCLR(Idomo,p-1)
Jdomo = IBSET(Jdomo,q-1)
else
print*,"Something went wrong in obtain_associated_alphaI"
endif
pqAlreadyGenQ = .FALSE.
! First check if it can be generated before
do k = 1, idxI-1
2021-02-01 17:30:56 +01:00
diffSOMO = IEOR(Jsomo,iand(reunion_of_act_virt_bitmask(1,1),psi_configuration(1,1,k)))
diffDOMO = IEOR(Jdomo,iand(reunion_of_act_virt_bitmask(1,1),psi_configuration(1,2,k)))
2021-02-01 14:54:11 +01:00
ndiffSOMO = POPCNT(diffSOMO)
ndiffDOMO = POPCNT(diffDOMO)
2021-02-01 17:30:56 +01:00
if(POPCNT(IEOR(diffSOMO,diffDOMO)) .LE. 1 .AND. ndiffDOMO .LT. 3) then
2021-02-01 14:54:11 +01:00
pqAlreadyGenQ = .TRUE.
!print *,i,k,ndiffSOMO,ndiffDOMO
!call debug_spindet(Jsomo,1)
!call debug_spindet(Jdomo,1)
!call debug_spindet(iand(reunion_of_act_virt_bitmask(1,1),psi_configuration(1,1,k)),1)
!call debug_spindet(iand(reunion_of_act_virt_bitmask(1,1),psi_configuration(1,2,k)),1)
EXIT
endif
end do
if(pqAlreadyGenQ) cycle
pqExistsQ = .FALSE.
! now check if this exists in the selected list
do k = idxI, N_configuration
2021-02-01 17:30:56 +01:00
diffSOMO = IEOR(OR(reunion_of_act_virt_bitmask(1,1),Jsomo),psi_configuration(1,1,k))
diffDOMO = IEOR(OR(reunion_of_act_virt_bitmask(1,1),Jdomo),psi_configuration(1,2,k))
2021-02-01 14:54:11 +01:00
ndiffSOMO = POPCNT(diffSOMO)
ndiffDOMO = POPCNT(diffDOMO)
if((ndiffSOMO + ndiffDOMO) .EQ. 0) then
pqExistsQ = .TRUE.
EXIT
endif
end do
if(.NOT. pqExistsQ) then
tableUniqueAlphas(p,q) = .TRUE.
!print *,p,q
!call debug_spindet(Jsomo,1)
!call debug_spindet(Jdomo,1)
endif
end do
end do
!print *,tableUniqueAlphas(:,:)
! prune list of alphas
Isomo = Icfg(1,1)
Idomo = Icfg(1,2)
Jsomo = Icfg(1,1)
Jdomo = Icfg(1,2)
NalphaIcfg = 0
do i = 1, nholes
p = listholes(i)
do j = 1, nvmos
q = listvmos(j)
2021-02-01 21:18:48 +01:00
if(p .EQ. q) cycle
2021-02-01 14:54:11 +01:00
if(tableUniqueAlphas(p,q)) then
if(holetype(i) .EQ. 1 .AND. vmotype(j) .EQ. 1) then
! SOMO -> VMO
Jsomo = IBCLR(Isomo,p-1)
Jsomo = IBSET(Jsomo,q-1)
Jdomo = Idomo
else if(holetype(i) .EQ. 1 .AND. vmotype(j) .EQ. 2) then
! SOMO -> SOMO
Jsomo = IBCLR(Isomo,p-1)
Jsomo = IBCLR(Jsomo,q-1)
Jdomo = IBSET(Idomo,q-1)
else if(holetype(i) .EQ. 2 .AND. vmotype(j) .EQ. 1) then
! DOMO -> VMO
Jsomo = IBSET(Isomo,p-1)
Jsomo = IBSET(Jsomo,q-1)
Jdomo = IBCLR(Idomo,p-1)
else if(holetype(i) .EQ. 2 .AND. vmotype(j) .EQ. 2) then
! DOMO -> SOMO
Jsomo = IBSET(Isomo,p-1)
Jsomo = IBCLR(Jsomo,q-1)
Jdomo = IBCLR(Idomo,p-1)
Jdomo = IBSET(Jdomo,q-1)
else
print*,"Something went wrong in obtain_associated_alphaI"
endif
NalphaIcfg += 1
2021-02-01 21:18:48 +01:00
!print *,p,q,"|",holetype(i),vmotype(j),NalphaIcfg
2021-02-01 14:54:11 +01:00
!call debug_spindet(Jsomo,1)
!call debug_spindet(Jdomo,1)
alphasIcfg(1,1,NalphaIcfg) = Jsomo
alphasIcfg(1,2,NalphaIcfg) = Jdomo
endif
end do
end do
end subroutine
2021-02-01 16:52:40 +01:00
subroutine obtain_connected_I_foralpha(idxI, Ialpha, connectedI, nconnectedI, excitationIds, excitationTypes)
2021-02-01 16:52:40 +01:00
implicit none
use bitmasks
BEGIN_DOC
! Documentation for obtain_connected_I_foralpha
! This function returns all those selected configurations
! which are connected to the input configuration
! Ialpha by a single excitation.
!
! The type of excitations are ordered as follows:
! Type 1 - SOMO -> SOMO
! Type 2 - DOMO -> VMO
! Type 3 - SOMO -> VMO
! Type 4 - DOMO -> SOMO
!
! Order of operators
! \alpha> = a^\dag_p a_q |I> = E_pq |I>
END_DOC
integer ,intent(in) :: idxI
2021-02-01 16:52:40 +01:00
integer(bit_kind),intent(in) :: Ialpha(N_int,2)
integer(bit_kind),intent(out) :: connectedI(N_int,2,*)
integer,intent(out) :: nconnectedI
integer,intent(out) :: excitationIds(2,*)
integer,intent(out) :: excitationTypes(*)
integer*8 :: Idomo
integer*8 :: Isomo
integer*8 :: Jdomo
integer*8 :: Jsomo
integer*8 :: diffSOMO
integer*8 :: diffDOMO
integer :: ndiffSOMO
integer :: ndiffDOMO
2021-02-01 21:18:48 +01:00
integer :: i,j,k,l,p,q,nsomoJ,nsomoalpha
2021-02-01 16:52:40 +01:00
nconnectedI = 0
2021-02-01 18:08:13 +01:00
p = 0
q = 0
do i=idxI,N_configuration
2021-02-01 21:18:48 +01:00
Isomo = Ialpha(1,1)
Idomo = Ialpha(1,2)
Jsomo = psi_configuration(1,1,i)
Jdomo = psi_configuration(1,2,i)
!call debug_spindet(Isomo,1)
!call debug_spindet(Idomo,1)
!print *,"-J--i=",i,Jsomo,Isomo
!call debug_spindet(Jsomo,1)
!call debug_spindet(Jdomo,1)
diffSOMO = IEOR(Isomo,Jsomo)
diffDOMO = IEOR(Idomo,Jdomo)
2021-02-01 16:52:40 +01:00
ndiffSOMO = POPCNT(diffSOMO)
ndiffDOMO = POPCNT(diffDOMO)
2021-02-01 21:18:48 +01:00
if((ndiffSOMO + ndiffDOMO) .EQ. 0) cycle
!print *,"-I--i=",i,Isomo,Jsomo,ndiffSOMO,ndiffDOMO
2021-02-01 17:30:56 +01:00
if(POPCNT(IEOR(diffSOMO,diffDOMO)) .LE. 1 .AND. ndiffDOMO .LT. 3) then
2021-02-01 16:52:40 +01:00
nconnectedI += 1
connectedI(:,:,nconnectedI) = psi_configuration(:,:,i)
select case(ndiffDOMO)
case (0)
! SOMO -> VMO
2021-02-01 21:18:48 +01:00
!print *,"obt SOMO -> VMO"
2021-02-01 16:52:40 +01:00
excitationTypes(nconnectedI) = 3
2021-02-01 21:18:48 +01:00
Jsomo = IEOR(Isomo, Jsomo)
p = TRAILZ(Jsomo) + 1
Jsomo = IBCLR(Jsomo,p-1)
q = TRAILZ(Jsomo) + 1
2021-02-01 16:52:40 +01:00
case (1)
! DOMO -> VMO
! or
! SOMO -> SOMO
2021-02-01 21:18:48 +01:00
nsomoJ = POPCNT(Jsomo)
2021-02-01 16:52:40 +01:00
nsomoalpha = POPCNT(Isomo)
2021-02-01 21:18:48 +01:00
if(nsomoJ .GT. nsomoalpha) then
2021-02-01 16:52:40 +01:00
! DOMO -> VMO
2021-02-01 21:18:48 +01:00
!print *,"obt DOMO -> VMO"
2021-02-01 16:52:40 +01:00
excitationTypes(nconnectedI) = 2
2021-02-01 21:18:48 +01:00
Isomo = IOR(IEOR(Isomo, Jsomo),IEOR(Idomo,Jdomo))
p = TRAILZ(Isomo) + 1
Isomo = IBCLR(Isomo,p-1)
q = TRAILZ(Isomo) + 1
2021-02-01 16:52:40 +01:00
else
! SOMO -> SOMO
2021-02-01 21:18:48 +01:00
!print *,"obt SOMO -> SOMO"
2021-02-01 16:52:40 +01:00
excitationTypes(nconnectedI) = 1
2021-02-01 21:18:48 +01:00
Isomo = IOR(IEOR(Isomo, Jsomo),IEOR(Idomo,Jdomo))
p = TRAILZ(Isomo) + 1
Isomo = IBCLR(Isomo,p-1)
q = TRAILZ(Isomo) + 1
2021-02-01 16:52:40 +01:00
end if
case (2)
! DOMO -> SOMO
2021-02-01 21:18:48 +01:00
!print *,"obt DOMO -> SOMO"
2021-02-01 16:52:40 +01:00
excitationTypes(nconnectedI) = 4
2021-02-01 21:18:48 +01:00
Isomo = IEOR(Isomo, Jsomo)
p = TRAILZ(Isomo) + 1
Isomo = IBCLR(Isomo,p-1)
q = TRAILZ(Isomo) + 1
2021-02-01 16:52:40 +01:00
case default
print *,"something went wront in get connectedI"
end select
excitationIds(1,nconnectedI)=p
excitationIds(2,nconnectedI)=q
2021-02-01 21:18:48 +01:00
!print *,"------ > output p,q in obt=",p,q
2021-02-01 16:52:40 +01:00
endif
end do
end subroutine obtain_connected_I_foralpha
2021-02-01 18:08:13 +01:00
function getNSOMO(Icfg) result(NSOMO)
implicit none
integer(bit_kind),intent(in) :: Icfg(N_int,2)
integer :: NSOMO
integer :: i
NSOMO = 0
do i = 1,N_int
NSOMO += POPCNT(Icfg(i,1))
enddo
end function getNSOMO
2021-02-01 21:18:48 +01:00
subroutine convertOrbIdsToModelSpaceIds(Ialpha, Jcfg, p, q, extype, pmodel, qmodel)
implicit none
BEGIN_DOC
! This function converts the orbital ids
! in real space to those used in model space
! in order to identify the matrices required
! for the calculation of MEs.
!
! The type of excitations are ordered as follows:
! Type 1 - SOMO -> SOMO
! Type 2 - DOMO -> VMO
! Type 3 - SOMO -> VMO
! Type 4 - DOMO -> SOMO
END_DOC
integer(bit_kind),intent(in) :: Ialpha(N_int,2)
integer(bit_kind),intent(in) :: Jcfg(N_int,2)
integer,intent(in) :: p,q
integer,intent(in) :: extype
integer,intent(out) :: pmodel,qmodel
integer*8 :: Isomo
integer*8 :: Idomo
integer*8 :: Jsomo
integer*8 :: Jdomo
integer*8 :: mask
integer :: pos0,pos0prev
! TODO Flag (print) when model space indices is > 64
2021-02-01 21:18:48 +01:00
Isomo = Ialpha(1,1)
Idomo = Ialpha(1,2)
Jsomo = Jcfg(1,1)
Jdomo = Jcfg(1,2)
pos0prev = 0
pmodel = p
qmodel = q
!print *,"input pq=",p,q
select case(extype)
case (1)
! SOMO -> SOMO
! remove all domos
!print *,"type -> SOMO -> SOMO"
mask = IBSET(0_8,p) - 1
pmodel = POPCNT(mask) - POPCNT(AND(Isomo,mask)) - n_core_orb + 1
mask = IBSET(0_8,q) - 1
qmodel = POPCNT(mask) - POPCNT(AND(Isomo,mask)) - n_core_orb + 1
case (2)
! DOMO -> VMO
! remove all domos except one at p
!print *,"type -> DOMO -> VMO"
mask = IBSET(0_8,p) - 1
pmodel = POPCNT(mask) - POPCNT(AND(Jsomo,mask)) - n_core_orb + 1
mask = IBSET(0_8,q) - 1
qmodel = POPCNT(mask) - POPCNT(AND(Jsomo,mask)) - n_core_orb + 1
case (3)
! SOMO -> VMO
!print *,"type -> SOMO -> VMO"
Isomo = IEOR(Isomo,Jsomo)
mask = IBSET(0_8,p) - 1
pmodel = POPCNT(mask) - POPCNT(AND(Isomo,mask)) - n_core_orb + 1
mask = IBSET(0_8,q) - 1
qmodel = POPCNT(mask) - POPCNT(AND(Isomo,mask)) - n_core_orb + 1
case (4)
! DOMO -> SOMO
! remove all domos except one at p
!print *,"type -> DOMO -> SOMO"
Isomo = IEOR(Isomo,Jsomo)
mask = IBSET(0_8,p) - 1
pmodel = POPCNT(mask) - POPCNT(AND(Isomo,mask)) - n_core_orb + 1
mask = IBSET(0_8,q) - 1
qmodel = POPCNT(mask) - POPCNT(AND(Isomo,mask)) - n_core_orb + 1
case default
print *,"something is wrong in convertOrbIdsToModelSpaceIds"
end select
!print *,p,q,"model ids=",pmodel,qmodel
end subroutine convertOrbIdsToModelSpaceIds