Skip to content

Commit

Permalink
Hessian readin mode for RF optimizer (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
awvwgk authored Dec 9, 2019
1 parent 8b22106 commit 7644b8c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
52 changes: 38 additions & 14 deletions xtb/optimizer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ subroutine ancopt(iunit,ilog,mol,wfn,calc, &
real(wp) :: maxdispl,gthr,ethr,hmax,energy,acc,rij(3),t1,t0,w1,w0,ccc
integer :: n3,i,j,k,l,jjj,ic,jc,ia,ja,ii,jj,info,lwork,nat3,liwork
integer :: nvar,iter,nread,maxcycle,maxmicro,itry,maxopt,iupdat,iii
integer :: id,ich
integer :: id,ihess,error
integer, intent(in) :: ilog
integer, external :: lin
real(wp),allocatable :: h (:,:)
Expand Down Expand Up @@ -197,8 +197,6 @@ subroutine ancopt(iunit,ilog,mol,wfn,calc, &
endif
if(maxopt.lt.maxmicro) maxmicro=maxopt

inquire(file='hessian',exist=ex)

call axis2(mol%n,mol%at,mol%xyz,aaa,bbb,ccc,dumi,dumj)

!call open_file(ilog,'xtbopt.log','w')
Expand Down Expand Up @@ -243,7 +241,6 @@ subroutine ancopt(iunit,ilog,mol,wfn,calc, &
else
write(iunit,chrfmt) "RF solver ","davidson"
endif
write(iunit,chrfmt) "input Hessian ",bool2string(ex)
write(iunit,chrfmt) "write xtbopt.log ",bool2string(ilog.ne.-1)
if (linear) then
write(iunit,chrfmt) "linear (good luck)",bool2string(linear)
Expand All @@ -264,40 +261,47 @@ subroutine ancopt(iunit,ilog,mol,wfn,calc, &

allocate(h(nat3,nat3),fc(nat3*(nat3+1)/2),eig(nat3))

if (mhset%model == p_modh_read) then
call open_file(ihess, 'hessian', 'r')
if (ihess == -1) then
call raise('E', "Could not read in hessian as requested.", 1)
return
endif
call read_hessian(ihess, nat3, h, error)
if (error /= 0) then
call raise('E', "Could not read hessian from file.", 1)
return
endif
! do not reset the hessian
maxmicro = maxopt
ex = .true.
endif

call anc%allocate(mol%n,nvar,hlow,hmax)

molopt = mol

! special TS section
if(tsopt)then
if (.not.ex) call raise('E','TS search requires Hessian!',1)
maxdispl=min(maxdispl,0.05d0)
maxmicro=maxopt ! new ANC are never generated
write(*,*)'root to follow for TS :',tsroot
endif
if (profile) call timer%measure(1)

! ======================================================================
ANC_microiter: do
! ======================================================================

if (profile) call timer%measure(2,'model hessian')
if(.not.ex)then ! normal case
if (.not.ex)then ! normal case
if(pr)write(iunit,'(/,''generating ANC from model Hessian ...'')')
call modhes(iunit, mhset, molopt%n, molopt%xyz, molopt%at, fc, pr) ! WBO (array wb) not used in present version
!call qpothess(molopt%n,fc,molopt%xyz)
thr=1.d-11
else
if(pr)write(iunit,'(/,''generating ANC from read Hessian ...'')')
call rdhess(nat3,h,'hessian')
k=0
do i=1,nat3
do j=1,i
k=k+1
fc(k)=h(j,i)
enddo
enddo
ex=.false.
thr=1.d-10
endif

Expand Down Expand Up @@ -1057,5 +1061,25 @@ subroutine itochess(nvar,nat3,b,hess,fc)
enddo

end subroutine itochess

subroutine read_hessian(ihess, ndim, hessian, error)
use mctc_systools
implicit none
integer, intent(in) :: ihess
integer, intent(in) :: ndim
real(wp), intent(out) :: hessian(:, :)
character(len=:), allocatable :: line
integer, intent(out) :: error
integer :: i, j
error = 0
do while(error == 0)
call getline(ihess, line, error)
if (index(line, '$hessian') == 1) then
read(ihess, *, iostat=error) &
& ((hessian(j, i), j = 1, ndim), i = 1, ndim)
exit
endif
enddo
end subroutine read_hessian
end module optimizer

2 changes: 2 additions & 0 deletions xtb/set_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ subroutine write_set_opt(ictrl)
write(ictrl,'(3x,"hessian=")',advance='no')
select case(mhset%model)
case default; write(ictrl,'("lindh-d2")')
case(p_modh_read); write(ictrl,'("read")')
case(p_modh_unit); write(ictrl,'("unit")')
case(p_modh_old); write(ictrl,'("old")')
case(p_modh_lindh); write(ictrl,'("lindh")')
Expand Down Expand Up @@ -1407,6 +1408,7 @@ subroutine set_opt(key,val)
case("swart"); mhset%model = p_modh_swart
case("old"); mhset%model = p_modh_old
case("unit"); mhset%model = p_modh_unit
case("read"); mhset%model = p_modh_read
end select
endif
set14 = .false.
Expand Down
1 change: 1 addition & 0 deletions xtb/setparam.f90
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module setparam
maxdispl_opt = 1.000_wp, &
! lowest force constant in ANC generation (should be > 0.005)
hlow_opt = 0.010_wp )
integer, parameter :: p_modh_read = -2
integer, parameter :: p_modh_unit = -1
integer, parameter :: p_modh_lindh = 1
integer, parameter :: p_modh_lindh_d2 = 2
Expand Down

0 comments on commit 7644b8c

Please sign in to comment.