subroutine RotateOrbs()
if (iProcIndex == Root) then
! If we are reading in our own transformation matrix (coeffT1) don't need a lot of the initialisation stuff.
if (tReadInCoeff .or. tUseMP2VarDenMat .or. tFindCINatOrbs .or. tUseHFOrbs) then
tNotConverged = .false.
call FindNatOrbitals()
else
! Need to actually find the coefficient matrix and then use it.
tNotConverged = .true.
call InitLocalOrbs() ! Set defaults, allocate arrays, write out headings
! for OUTPUT, set integarals to HF values.
if (tDiagonalizehij) then
call Diagonalizehij()
tNotConverged = .false.
Iteration = 2
else if (tMaxHLGap) then
call EquateDiagFock()
tNotConverged = .false.
else
tNotConverged = .true.
call WriteStats() ! write out the original stats before any rotation.
call set_timer(Rotation_Time, 30)
do while (tNotConverged) ! rotate the orbitals until the sum of the four index
! integral falls below a chose convergence value.
Iteration = Iteration + 1
call FindNewOrbs() ! bulk of the calculation.
! do the actual transformations, moving the coefficients by
!a timestep according to the calculated force.
call WriteStats() ! write out the stats for this iteration.
end do
call halt_timer(Rotation_Time)
write(stdout, *) "Convergence criterion met. Finalizing new orbitals..."
end if
! Make symmetry, orbitals, one/two-electron integrals consistent with rest of NECI
call FinalizeNewOrbs()
call writebasis(stdout, G1, nBasis, ARR, BRR)
call DeallocateMem()
end if
call neci_flush(stdout)
call neci_flush(transform_unit)
end if
end subroutine RotateOrbs