root / src / Opt_Geom.f90 @ 3
Historique | Voir | Annoter | Télécharger (16,73 ko)
| 1 | 1 | pfleura2 | ! This subroutine optimizes a geometry. It is mainly here for debugging purposes.. |
|---|---|---|---|
| 2 | 1 | pfleura2 | ! It has been designed to be almost independent of the rest of the code. |
| 3 | 1 | pfleura2 | |
| 4 | 1 | pfleura2 | SUBROUTINE Opt_geom(IGeom,Nat,NCoord,Coord,Geom,E,Flag_Opt_Geom,Step_method) |
| 5 | 1 | pfleura2 | |
| 6 | 1 | pfleura2 | use Path_module, only : maxcyc,sthresh,gthresh,Hinv,Smax,Nom,Atome,OrderInv,indzmat,& |
| 7 | 1 | pfleura2 | XyzGeomF,IntCoordF,UMat,ScanCoord,Coordinate,NPrim,& |
| 8 | 1 | pfleura2 | BTransInv,BTransInv_local,XyzGeomI,Xprimitive_t,ScanCoord,& |
| 9 | 1 | pfleura2 | Coordinate,Pi,UMat_local,NCart |
| 10 | 1 | pfleura2 | use VarTypes |
| 11 | 1 | pfleura2 | IMPLICIT NONE |
| 12 | 1 | pfleura2 | |
| 13 | 1 | pfleura2 | INTEGER(KINT), INTENT(IN) :: Nat,NCoord,IGeom |
| 14 | 1 | pfleura2 | CHARACTER(32), INTENT(IN) :: Coord |
| 15 | 1 | pfleura2 | CHARACTER(32), INTENT(IN) :: Step_method |
| 16 | 1 | pfleura2 | REAL(KREAL), INTENT(INOUT) :: Geom(NCoord) |
| 17 | 1 | pfleura2 | REAL(KREAL), INTENT(OUT) :: E |
| 18 | 1 | pfleura2 | LOGICAL, INTENT(IN) :: Flag_Opt_Geom |
| 19 | 1 | pfleura2 | |
| 20 | 1 | pfleura2 | ! As this subroutine is here for debugging, debug=T ! |
| 21 | 1 | pfleura2 | LOGICAL :: debug |
| 22 | 1 | pfleura2 | LOGICAL :: Fini |
| 23 | 1 | pfleura2 | LOGICAL, SAVE :: FRST=.TRUE. |
| 24 | 1 | pfleura2 | |
| 25 | 1 | pfleura2 | ! Variables |
| 26 | 1 | pfleura2 | INTEGER(KINT) :: IOpt, I,J,Iat, IBEG |
| 27 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: GradTmp(:),ZeroVec(:) ! 3*Nat or 3*Nat-6 |
| 28 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: GeomOld(:),GradOld(:) ! (3*Nat or 3*Nat-6) |
| 29 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: GeomRef(:) ! (3*Nat or 3*Nat-6) |
| 30 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: GeomTmp2(:),GradTmp2(:) ! 3*Nat or 3*Nat-6 |
| 31 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: Hess_local(:,:) |
| 32 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: GeomCart(:,:) !(Nat,3) |
| 33 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: GeomCart_old(:,:) !(Nat,3) |
| 34 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: Hprim(:,:) !(NPrim,NPrim) |
| 35 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: HprimU(:,:) !(NPrim,3*Nat-6)) |
| 36 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: NewGeom(:) !NCoord=3*Nat-6 |
| 37 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: NewGradTmp(:) |
| 38 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: Hess_local_inv(:,:) ! used in diis |
| 39 | 1 | pfleura2 | REAL(KREAL) :: NormStep, FactStep, HP |
| 40 | 1 | pfleura2 | |
| 41 | 1 | pfleura2 | INTERFACE |
| 42 | 1 | pfleura2 | function valid(string) result (isValid) |
| 43 | 1 | pfleura2 | CHARACTER(*), intent(in) :: string |
| 44 | 1 | pfleura2 | logical :: isValid |
| 45 | 1 | pfleura2 | END function VALID |
| 46 | 1 | pfleura2 | |
| 47 | 1 | pfleura2 | subroutine Egrad(E,Geom,Grad,NCoord,IGeom,IOpt,GeomCart,FOptGeom,GeomOld,GeomCart_old) |
| 48 | 1 | pfleura2 | |
| 49 | 1 | pfleura2 | ! This routines calculates the energy E and the gradient Grad of |
| 50 | 1 | pfleura2 | ! a molecule with Geometry Geom (may be in internal coordinates), |
| 51 | 1 | pfleura2 | ! using for now, either Gaussian or Ext, more general later. |
| 52 | 1 | pfleura2 | |
| 53 | 1 | pfleura2 | use Path_module, only : Nat,AtName,Coord,dzdc,indzmat,Nom,Atome,massat,unit, & |
| 54 | 1 | pfleura2 | prog,NCart,XyzGeomF,IntCoordF,BTransInv, XyzGeomI, & |
| 55 | 1 | pfleura2 | GeomOld_all,BTransInvF,BTransInv_local,UMatF,UMat_local & |
| 56 | 1 | pfleura2 | , BprimT,a0,ScanCoord, Coordinate,NPrim,BMat_BakerT,BBT,BBT_inv & |
| 57 | 1 | pfleura2 | , Order,OrderInv, XPrimitiveF |
| 58 | 1 | pfleura2 | |
| 59 | 1 | pfleura2 | ! IntCoordF(NGeomF,NCoord),GeomOld_all(NGeomF,NCoord) |
| 60 | 1 | pfleura2 | ! allocated in Path.f90 |
| 61 | 1 | pfleura2 | |
| 62 | 1 | pfleura2 | use Io_module |
| 63 | 1 | pfleura2 | |
| 64 | 1 | pfleura2 | ! Energy (calculated if F300K=.F., else estimated) |
| 65 | 1 | pfleura2 | REAL(KREAL), INTENT (OUT) :: E |
| 66 | 1 | pfleura2 | ! NCoord: Number of the degrees of freedom |
| 67 | 1 | pfleura2 | ! IGeom: index of the geometry. |
| 68 | 1 | pfleura2 | INTEGER(KINT), INTENT (IN) :: NCoord, IGeom, IOpt |
| 69 | 1 | pfleura2 | ! Geometry at which gradient is calculated (cf Factual also): |
| 70 | 1 | pfleura2 | REAL(KREAL), INTENT (INOUT) :: Geom(NCoord) |
| 71 | 1 | pfleura2 | ! Gradient calculated at Geom geometry: |
| 72 | 1 | pfleura2 | REAL(KREAL), INTENT (OUT) :: Grad(NCoord) |
| 73 | 1 | pfleura2 | ! Cartesian geometry corresponding to (Internal Geometry) Geom: |
| 74 | 1 | pfleura2 | REAL(KREAL), INTENT (OUT) :: GeomCart(Nat,3) |
| 75 | 1 | pfleura2 | !!! Optional, just for geometry optimization with Baker coordinates |
| 76 | 1 | pfleura2 | REAL(KREAL), INTENT (IN), OPTIONAL :: GeomCart_old(Nat,3) |
| 77 | 1 | pfleura2 | REAL(KREAL), INTENT (INOUT), OPTIONAL :: GeomOld(NCoord) |
| 78 | 1 | pfleura2 | ! FOptGeom is a flag indicating if we are doing a geom optimization |
| 79 | 1 | pfleura2 | ! it can be omitted so that we use a local flag: Flag_Opt_Geom |
| 80 | 1 | pfleura2 | LOGICAL,INTENT (IN), OPTIONAL :: FOptGeom |
| 81 | 1 | pfleura2 | ! if FOptGeom is given Flag_Opt_Geom=FOptGeom, else Flag_Opt_Geom=F |
| 82 | 1 | pfleura2 | LOGICAL :: Flag_Opt_Geom |
| 83 | 1 | pfleura2 | |
| 84 | 1 | pfleura2 | END subroutine Egrad |
| 85 | 1 | pfleura2 | |
| 86 | 1 | pfleura2 | END INTERFACE |
| 87 | 1 | pfleura2 | |
| 88 | 1 | pfleura2 | debug=valid('OptGeom')
|
| 89 | 1 | pfleura2 | |
| 90 | 1 | pfleura2 | E=0. |
| 91 | 1 | pfleura2 | |
| 92 | 1 | pfleura2 | if (debug) Call Header("Entering Geom Optimization")
|
| 93 | 1 | pfleura2 | |
| 94 | 1 | pfleura2 | ALLOCATE(GradTmp2(NCoord),GeomTmp2(NCoord),GradTmp(NCoord)) |
| 95 | 1 | pfleura2 | ALLOCATE(GradOld(NCoord),GeomOld(NCoord),ZeroVec(NCoord)) |
| 96 | 1 | pfleura2 | ALLOCATE(GeomRef(NCoord)) |
| 97 | 1 | pfleura2 | ALLOCATE(Hess_local(NCoord,NCoord)) |
| 98 | 1 | pfleura2 | ALLOCATE(GeomCart(Nat,3),GeomCart_old(Nat,3)) |
| 99 | 1 | pfleura2 | ALLOCATE(NewGeom(NCoord)) |
| 100 | 1 | pfleura2 | ALLOCATE(NewGradTmp(NCoord)) |
| 101 | 1 | pfleura2 | ALLOCATE(Hess_local_inv(NCoord,NCoord)) |
| 102 | 1 | pfleura2 | |
| 103 | 1 | pfleura2 | IOpt=0 |
| 104 | 1 | pfleura2 | ZeroVec=0.d0 |
| 105 | 1 | pfleura2 | |
| 106 | 1 | pfleura2 | ! Initialize the Hessian |
| 107 | 1 | pfleura2 | Hess_local=0. |
| 108 | 1 | pfleura2 | |
| 109 | 1 | pfleura2 | SELECT CASE (COORD) |
| 110 | 1 | pfleura2 | CASE ('ZMAT')
|
| 111 | 1 | pfleura2 | ! We use the fact that we know that approximate good hessian values |
| 112 | 1 | pfleura2 | ! are 0.5 for bonds, 0.1 for valence angle and 0.02 for dihedral angles |
| 113 | 1 | pfleura2 | Hess_local(1,1)=0.5d0 |
| 114 | 1 | pfleura2 | Hess_local(2,2)=0.5d0 |
| 115 | 1 | pfleura2 | Hess_local(3,3)=0.1d0 |
| 116 | 1 | pfleura2 | DO J=1,Nat-3 |
| 117 | 1 | pfleura2 | Hess_local(3*J+1,3*J+1)=0.5d0 |
| 118 | 1 | pfleura2 | Hess_local(3*J+2,3*J+2)=0.1d0 |
| 119 | 1 | pfleura2 | Hess_local(3*J+3,3*J+3)=0.02d0 |
| 120 | 1 | pfleura2 | END DO |
| 121 | 1 | pfleura2 | IF (HInv) THEN |
| 122 | 1 | pfleura2 | DO I=1,NCoord |
| 123 | 1 | pfleura2 | Hess_local(I,I)=1.d0/Hess_local(I,I) |
| 124 | 1 | pfleura2 | END DO |
| 125 | 1 | pfleura2 | END IF |
| 126 | 1 | pfleura2 | |
| 127 | 1 | pfleura2 | IF (Step_method .EQ. "RFO") Then |
| 128 | 1 | pfleura2 | Hess_local=0. |
| 129 | 1 | pfleura2 | DO I=1,NCoord |
| 130 | 1 | pfleura2 | Hess_local(I,I)=0.5d0 |
| 131 | 1 | pfleura2 | END DO |
| 132 | 1 | pfleura2 | END IF |
| 133 | 1 | pfleura2 | |
| 134 | 1 | pfleura2 | CASE ('BAKER')
|
| 135 | 1 | pfleura2 | ! UMat(NPrim,3*Nat-6) |
| 136 | 1 | pfleura2 | BTransInv_local = BTransInv |
| 137 | 1 | pfleura2 | UMat_local = UMat |
| 138 | 1 | pfleura2 | ALLOCATE(Hprim(NPrim,NPrim),HprimU(NPrim,NCoord)) |
| 139 | 1 | pfleura2 | Hprim=0.d0 |
| 140 | 1 | pfleura2 | ScanCoord=>Coordinate |
| 141 | 1 | pfleura2 | I=0 |
| 142 | 1 | pfleura2 | DO WHILE (Associated(ScanCoord%next)) |
| 143 | 1 | pfleura2 | I=I+1 |
| 144 | 1 | pfleura2 | SELECT CASE (ScanCoord%Type) |
| 145 | 1 | pfleura2 | CASE ('BOND')
|
| 146 | 1 | pfleura2 | Hprim(I,I) = 0.5d0 |
| 147 | 1 | pfleura2 | CASE ('ANGLE')
|
| 148 | 1 | pfleura2 | Hprim(I,I) = 0.2d0 |
| 149 | 1 | pfleura2 | CASE ('DIHEDRAL')
|
| 150 | 1 | pfleura2 | Hprim(I,I) = 0.1d0 |
| 151 | 1 | pfleura2 | END SELECT |
| 152 | 1 | pfleura2 | ScanCoord => ScanCoord%next |
| 153 | 1 | pfleura2 | END DO |
| 154 | 1 | pfleura2 | |
| 155 | 1 | pfleura2 | ! Hprim U: |
| 156 | 1 | pfleura2 | HprimU=0.d0 |
| 157 | 1 | pfleura2 | DO I=1, NCoord |
| 158 | 1 | pfleura2 | DO J=1,NPrim |
| 159 | 1 | pfleura2 | HprimU(:,I) = HprimU(:,I) + Hprim(:,J)*UMat(J,I) |
| 160 | 1 | pfleura2 | END DO |
| 161 | 1 | pfleura2 | END DO |
| 162 | 1 | pfleura2 | |
| 163 | 1 | pfleura2 | ! Hess = U^T Hprim U: |
| 164 | 1 | pfleura2 | Hess_local=0.d0 |
| 165 | 1 | pfleura2 | DO I=1, NCoord |
| 166 | 1 | pfleura2 | DO J=1,NPrim |
| 167 | 1 | pfleura2 | ! UMat^T is needed below. |
| 168 | 1 | pfleura2 | Hess_local(:,I) = Hess_local(:,I) + UMat(J,:)*HprimU(J,I) |
| 169 | 1 | pfleura2 | END DO |
| 170 | 1 | pfleura2 | END DO |
| 171 | 1 | pfleura2 | |
| 172 | 1 | pfleura2 | !Print *, 'Hprim=' |
| 173 | 1 | pfleura2 | DO I=1,NPrim |
| 174 | 1 | pfleura2 | ! WRITE(*,'(10(1X,F6.3))') Hprim(I,:) |
| 175 | 1 | pfleura2 | END DO |
| 176 | 1 | pfleura2 | !Print *, 'UMat=' |
| 177 | 1 | pfleura2 | DO I=1,NPrim |
| 178 | 1 | pfleura2 | ! WRITE(*,'(3(1X,F6.3))') UMat(I,1:3) |
| 179 | 1 | pfleura2 | END DO |
| 180 | 1 | pfleura2 | !Print *, 'HprimU=' |
| 181 | 1 | pfleura2 | DO I=1,NPrim |
| 182 | 1 | pfleura2 | ! WRITE(*,'(3(1X,F6.3))') HprimU(I,1:3) |
| 183 | 1 | pfleura2 | END DO |
| 184 | 1 | pfleura2 | !Print *, 'Hess_local=' |
| 185 | 1 | pfleura2 | DO I=1,NCoord |
| 186 | 1 | pfleura2 | ! WRITE(*,'(3(1X,F6.3))') Hess_local(I,1:3) |
| 187 | 1 | pfleura2 | END DO |
| 188 | 1 | pfleura2 | |
| 189 | 1 | pfleura2 | DEALLOCATE(Hprim,HprimU) |
| 190 | 1 | pfleura2 | |
| 191 | 1 | pfleura2 | IF (HInv) THEN |
| 192 | 1 | pfleura2 | Call GenInv(NCoord,Hess_local,Hess_local_inv,NCoord) |
| 193 | 1 | pfleura2 | Hess_local = Hess_local_inv |
| 194 | 1 | pfleura2 | END IF |
| 195 | 1 | pfleura2 | |
| 196 | 1 | pfleura2 | !Print *, 'Hess_local after inversion=' |
| 197 | 1 | pfleura2 | DO I=1,NCoord |
| 198 | 1 | pfleura2 | ! WRITE(*,'(3(1X,F6.3))') Hess_local(I,1:3) |
| 199 | 1 | pfleura2 | END DO |
| 200 | 1 | pfleura2 | |
| 201 | 1 | pfleura2 | IF (Step_method .EQ. "RFO") Then |
| 202 | 1 | pfleura2 | Hess_local=0. |
| 203 | 1 | pfleura2 | DO I=1,NCoord |
| 204 | 1 | pfleura2 | Hess_local(I,I)=0.5d0 |
| 205 | 1 | pfleura2 | END DO |
| 206 | 1 | pfleura2 | END IF |
| 207 | 1 | pfleura2 | |
| 208 | 1 | pfleura2 | CASE ('MIXED','CART','HYBRID')
|
| 209 | 1 | pfleura2 | DO J=1,NCoord |
| 210 | 1 | pfleura2 | Hess_local(J,J)=1. |
| 211 | 1 | pfleura2 | END DO |
| 212 | 1 | pfleura2 | CASE DEFAULT |
| 213 | 1 | pfleura2 | WRITE (*,*) "Coord=",TRIM(COORD)," not recognized, opt_Geom.f90, L164. Stop" |
| 214 | 1 | pfleura2 | STOP |
| 215 | 1 | pfleura2 | END SELECT |
| 216 | 1 | pfleura2 | |
| 217 | 1 | pfleura2 | ! Go to optimization |
| 218 | 1 | pfleura2 | GeomOld=0.d0 ! Internal coordinates |
| 219 | 1 | pfleura2 | GeomCart_old=0.d0 ! Cartesian coordinates |
| 220 | 1 | pfleura2 | |
| 221 | 1 | pfleura2 | Fini=.FALSE. |
| 222 | 1 | pfleura2 | DO WHILE ((IOpt.LT.MaxCyc).AND.(.NOT.Fini)) |
| 223 | 1 | pfleura2 | IOpt=IOpt+1 |
| 224 | 1 | pfleura2 | |
| 225 | 1 | pfleura2 | ! Calculate the energy and gradient |
| 226 | 1 | pfleura2 | IF (debug) THEN |
| 227 | 1 | pfleura2 | WRITE(*,*) 'L134, DBG Opt_Geom, COORD=',TRIM(COORD),' IOpt=',IOpt |
| 228 | 1 | pfleura2 | WRITE(*,*) "Energy and Coordinates:" |
| 229 | 1 | pfleura2 | WRITE(*,'(F12.6,12(1X,F8.3))') E,Geom(1:min(NCoord,12)) |
| 230 | 1 | pfleura2 | WRITE(*,*) "Geom Old:" |
| 231 | 1 | pfleura2 | WRITE(*,'(F12.6,12(1X,F8.3))') GEomOld(1:min(NCoord,13)) |
| 232 | 1 | pfleura2 | WRITE(*,*) "Grad Old:" |
| 233 | 1 | pfleura2 | WRITE(*,'(F12.6,12(1X,F8.3))') GradOld(1:min(NCoord,13)) |
| 234 | 1 | pfleura2 | END IF |
| 235 | 1 | pfleura2 | |
| 236 | 1 | pfleura2 | !Call EGrad(E,Geom,GradTmp,NCoord) |
| 237 | 1 | pfleura2 | IF (COORD.EQ.'BAKER') THEN |
| 238 | 1 | pfleura2 | ! GradTmp is gradient and calculated in Egrad.F, INTENT(OUT). |
| 239 | 1 | pfleura2 | ! GeomCart has INTENT(OUT) |
| 240 | 1 | pfleura2 | ! GeomRef is modified in Egrag_baker, so we should not use GeomOld variable |
| 241 | 1 | pfleura2 | GeomRef=GeomOld |
| 242 | 1 | pfleura2 | Call EGrad(E,Geom,GradTmp,NCoord,IGeom,IOpt,GeomCart,Flag_Opt_Geom, & |
| 243 | 1 | pfleura2 | GeomRef,GeomCart_old) |
| 244 | 1 | pfleura2 | GeomCart_old=GeomCart |
| 245 | 1 | pfleura2 | ELSE |
| 246 | 1 | pfleura2 | Call EGrad(E,Geom,GradTmp,NCoord,IGeom,IOpt,GeomCart) |
| 247 | 1 | pfleura2 | END IF |
| 248 | 1 | pfleura2 | |
| 249 | 1 | pfleura2 | IF (debug) THEN |
| 250 | 1 | pfleura2 | WRITE(*,*) 'L198, DBG Opt_Geom, COORD=',TRIM(COORD),' IOpt=',IOpt |
| 251 | 1 | pfleura2 | WRITE(*,*) "Energy and Coordinates:" |
| 252 | 1 | pfleura2 | WRITE(*,'(F12.6,12(1X,F8.3))') E,Geom(1:min(NCoord,12)) |
| 253 | 1 | pfleura2 | WRITE(*,*) "Geom Old:" |
| 254 | 1 | pfleura2 | WRITE(*,'(F12.6,12(1X,F8.3))') GEomOld(1:min(NCoord,13)) |
| 255 | 1 | pfleura2 | END IF |
| 256 | 1 | pfleura2 | |
| 257 | 1 | pfleura2 | IF (IOpt.GE.2) THEN |
| 258 | 1 | pfleura2 | ! We have enough geometries and gradient to update the hessian (or its |
| 259 | 1 | pfleura2 | ! inverse) |
| 260 | 1 | pfleura2 | GradTmp2=GradTmp-GradOld |
| 261 | 1 | pfleura2 | GeomTmp2=Geom-GeomOld |
| 262 | 1 | pfleura2 | |
| 263 | 1 | pfleura2 | if (debug) Write(*,*) "Call Hupdate_all, Geom" |
| 264 | 1 | pfleura2 | IF (debug) THEN |
| 265 | 1 | pfleura2 | WRITE(*,*) "dx before calling",SHAPE(GeomTmp2) |
| 266 | 1 | pfleura2 | WRITE(*,'(12(1X,F8.4))') GeomTmp2(1:NCoord) |
| 267 | 1 | pfleura2 | WRITE(*,*) "dgrad before calling",SHAPE(GradTmp2) |
| 268 | 1 | pfleura2 | WRITE(*,'(12(1X,F8.4))') GradTmp2(1:NCoord) |
| 269 | 1 | pfleura2 | END IF |
| 270 | 1 | pfleura2 | Call Hupdate_all(NCoord,GeomTmp2,GradTmp2,Hess_local) |
| 271 | 1 | pfleura2 | END IF ! matches IF (IOpt.GE.2) THEN |
| 272 | 1 | pfleura2 | |
| 273 | 1 | pfleura2 | GradOld=GradTmp |
| 274 | 1 | pfleura2 | GeomOld=Geom |
| 275 | 1 | pfleura2 | |
| 276 | 1 | pfleura2 | ! GradTmp becomes Step in Step_RFO_all. |
| 277 | 1 | pfleura2 | SELECT CASE (Step_method) |
| 278 | 1 | pfleura2 | CASE ('RFO')
|
| 279 | 1 | pfleura2 | Call Step_RFO_all(NCoord,GradTmp,IGeom,Geom,GradTmp,Hess_local,ZeroVec) |
| 280 | 1 | pfleura2 | CASE ('GDIIS')
|
| 281 | 1 | pfleura2 | Call Step_DIIS(NewGeom,Geom,NewGradTmp,GradTmp,HP,E,Hess_local,NCoord,FRST) |
| 282 | 1 | pfleura2 | ! q_{m+1} = q'_{m+1} - H^{-1}g'_{m+1}
|
| 283 | 1 | pfleura2 | Geom=0.d0 |
| 284 | 1 | pfleura2 | DO I=1, NCoord |
| 285 | 1 | pfleura2 | ! If Hinv=.False., then we need to invert Hess_local |
| 286 | 1 | pfleura2 | Geom(:) = Geom(:) + Hess_local(:,I)*NewGradTmp(I) |
| 287 | 1 | pfleura2 | END DO |
| 288 | 1 | pfleura2 | Geom(:) = NewGeom(:) - Geom(:) |
| 289 | 1 | pfleura2 | ! GradTmp now becomes "step" below: |
| 290 | 1 | pfleura2 | GradTmp = Geom - GeomOld |
| 291 | 1 | pfleura2 | CASE ('GDIIST')
|
| 292 | 2 | pfleura2 | Call Step_GDIIS_Simple_Err(NewGeom,Geom,NewGradTmp,GradTmp,HP,E,NCoord,FRST) |
| 293 | 1 | pfleura2 | ! q_{m+1} = q'_{m+1} - H^{-1}g'_{m+1}
|
| 294 | 1 | pfleura2 | Geom=0.d0 |
| 295 | 1 | pfleura2 | DO I=1, NCoord |
| 296 | 1 | pfleura2 | ! If Hinv=.False., then we need to invert Hess_local |
| 297 | 1 | pfleura2 | Geom(:) = Geom(:) + Hess_local(:,I)*NewGradTmp(I) |
| 298 | 1 | pfleura2 | END DO |
| 299 | 1 | pfleura2 | Geom(:) = NewGeom(:) - Geom(:) |
| 300 | 1 | pfleura2 | ! GradTmp now becomes "step" below: |
| 301 | 1 | pfleura2 | GradTmp = Geom - GeomOld |
| 302 | 1 | pfleura2 | CASE ('GEDIIS')
|
| 303 | 1 | pfleura2 | Call Step_GEDIIS(NewGeom,Geom,GradTmp,E,Hess_local,NCoord,FRST) |
| 304 | 1 | pfleura2 | ! GradTmp is actually "step" below: |
| 305 | 1 | pfleura2 | GradTmp = NewGeom - GeomOld |
| 306 | 1 | pfleura2 | !Call Step_GEDIIS_All(3,1,GradTmp,Geom,GradTmp,E,Hess_local,NCoord,FRST,ZeroVec) |
| 307 | 1 | pfleura2 | CASE DEFAULT |
| 308 | 1 | pfleura2 | WRITE (*,*) "Step_method=",TRIM(Step_method)," not recognized, opt_Geom.f90, L225. Stop" |
| 309 | 1 | pfleura2 | STOP |
| 310 | 1 | pfleura2 | END SELECT |
| 311 | 1 | pfleura2 | |
| 312 | 1 | pfleura2 | Fini=.TRUE. |
| 313 | 1 | pfleura2 | ! If (IOpt.LT.5) GradTmp=(IOpt*GradTmp+(5-IOpt)*0.01*Grad(IGeom,:))/5.d0 |
| 314 | 1 | pfleura2 | NormStep=sqrt(DOT_Product(GradTmp,GradTmp)) |
| 315 | 1 | pfleura2 | WRITE(*,'(A,E10.4,1X,A,E10.4)') 'DBG OptGeom L215, NormStep=', NormStep, 'Step Threshold=', SThresh |
| 316 | 1 | pfleura2 | FactStep=min(1.d0,SMax/NormStep) |
| 317 | 1 | pfleura2 | Fini=(NormStep.LE.SThresh) |
| 318 | 1 | pfleura2 | NormStep=sqrt(DOT_Product(GradOld,GradOld)) ! GradOld is the value of gradients. |
| 319 | 1 | pfleura2 | WRITE(*,'(A,E10.4,1X,A,E10.4)') 'DBG OptGeom L219, NormStep (Gradient)=', NormStep, 'Gradient Threshold=', GThresh |
| 320 | 1 | pfleura2 | Fini=(Fini.AND.(NormStep.LE.GThresh)) |
| 321 | 1 | pfleura2 | if (debug) WRITE(*,*) "DBG OptGeom FactStep=",FactStep |
| 322 | 1 | pfleura2 | GradTmp=GradTmp*FactStep ! GradTmp is step size here, from Step_RFO_all. |
| 323 | 1 | pfleura2 | |
| 324 | 2 | pfleura2 | Call Check_step(Coord,Nat,NCoord,GeomOld,GradTmp) |
| 325 | 1 | pfleura2 | |
| 326 | 1 | pfleura2 | Geom=GeomOld+GradTmp ! GradTmp is step size here, from Step_RFO_all. |
| 327 | 1 | pfleura2 | |
| 328 | 1 | pfleura2 | IF (debug) THEN |
| 329 | 1 | pfleura2 | WRITE(*,*) "L235, DBG OptGeom, IGeom=",IGeom," IOpt=", IOpt |
| 330 | 1 | pfleura2 | SELECT CASE (COORD) |
| 331 | 1 | pfleura2 | CASE ('ZMAT','BAKER')
|
| 332 | 1 | pfleura2 | !WRITE(*,'(12(1X,F8.3))') Geom(1:min(12,NCoord)) |
| 333 | 1 | pfleura2 | CASE('CART','HYBRID')
|
| 334 | 1 | pfleura2 | DO Iat=1,Nat |
| 335 | 1 | pfleura2 | ! PFL 30 Apr 2008 -> |
| 336 | 1 | pfleura2 | ! Deleted ref to orderinv that is created only for coord in zmat, baker, hybrid. |
| 337 | 1 | pfleura2 | ! WRITE(*,'(1X,A5,3(1X,F11.6))') Nom(Atome(OrderInv(indzmat(iat,1)))), & |
| 338 | 1 | pfleura2 | WRITE(*,'(1X,A5,3(1X,F11.6))') Nom(Atome(iat)), & |
| 339 | 1 | pfleura2 | Geom(3*Iat-2:3*Iat) |
| 340 | 1 | pfleura2 | ! <- PFL 30 Apr 2008 |
| 341 | 1 | pfleura2 | END DO |
| 342 | 1 | pfleura2 | CASE('MIXED')
|
| 343 | 1 | pfleura2 | DO Iat=1,NCart |
| 344 | 1 | pfleura2 | WRITE(*,'(1X,A5,3(1X,F11.6))') Nom(Atome(OrderInv(indzmat(iat,1)))), & |
| 345 | 1 | pfleura2 | Geom(3*Iat-2:3*Iat) |
| 346 | 1 | pfleura2 | END DO |
| 347 | 1 | pfleura2 | |
| 348 | 1 | pfleura2 | SELECT CASE (NCart) |
| 349 | 1 | pfleura2 | CASE(1) |
| 350 | 1 | pfleura2 | if (NAt.GE.2) THEN |
| 351 | 1 | pfleura2 | WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(OrderInv(indzmat(2,1)))), & |
| 352 | 1 | pfleura2 | IndZmat(2,2),Geom(4) |
| 353 | 1 | pfleura2 | IBEG=5 |
| 354 | 1 | pfleura2 | END IF |
| 355 | 1 | pfleura2 | IF (NAT.GE.3) THEN |
| 356 | 1 | pfleura2 | WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(OrderInv(indzmat(3,1)))), & |
| 357 | 1 | pfleura2 | IndZmat(3,2),Geom(5),IndZmat(3,3),Geom(6) |
| 358 | 1 | pfleura2 | IBeg=7 |
| 359 | 1 | pfleura2 | END IF |
| 360 | 1 | pfleura2 | CASE(2) |
| 361 | 1 | pfleura2 | WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(OrderInv(indzmat(3,1)))), & |
| 362 | 1 | pfleura2 | IndZmat(3,2),Geom(7),IndZmat(3,3),Geom(8) |
| 363 | 1 | pfleura2 | IBeg=9 |
| 364 | 1 | pfleura2 | CASE DEFAULT |
| 365 | 1 | pfleura2 | IBeg=3*NCart+1 |
| 366 | 1 | pfleura2 | END SELECT |
| 367 | 1 | pfleura2 | |
| 368 | 1 | pfleura2 | DO Iat=max(4,NCart),Nat |
| 369 | 1 | pfleura2 | WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(OrderInv(indzmat(iat,1)))), & |
| 370 | 1 | pfleura2 | IndZmat(iat,1),Geom(IBeg),IndZmat(3,2),Geom(IBeg+1), & |
| 371 | 1 | pfleura2 | IndZmat(3,3),Geom(IBeg+2)*180./pi |
| 372 | 1 | pfleura2 | IBeg=IBeg+3 |
| 373 | 1 | pfleura2 | END DO |
| 374 | 1 | pfleura2 | |
| 375 | 1 | pfleura2 | CASE DEFAULT |
| 376 | 1 | pfleura2 | WRITE(*,*) "Coord=",TRIM(COORD)," not recognized in OptGeom. L294." |
| 377 | 1 | pfleura2 | STOP |
| 378 | 1 | pfleura2 | END SELECT |
| 379 | 1 | pfleura2 | END IF ! matches IF (debug) THEN |
| 380 | 1 | pfleura2 | |
| 381 | 1 | pfleura2 | END DO ! matches DO WHILE ((IOpt.LT.MaxCyc).AND.(.NOT.Fini)) |
| 382 | 1 | pfleura2 | |
| 383 | 1 | pfleura2 | DEALLOCATE(GradTmp2,GeomTmp2,GradTmp) |
| 384 | 1 | pfleura2 | DEALLOCATE(GradOld,GeomOld) |
| 385 | 1 | pfleura2 | DEALLOCATE(Hess_local) |
| 386 | 1 | pfleura2 | DEALLOCATE(GeomCart_old) |
| 387 | 1 | pfleura2 | DEALLOCATE(NewGeom,NewGradTmp) |
| 388 | 1 | pfleura2 | DEALLOCATE(Hess_local_inv) |
| 389 | 1 | pfleura2 | |
| 390 | 1 | pfleura2 | IF (Fini) THEN |
| 391 | 1 | pfleura2 | WRITE(*,'(1X,A,I5,A,I5,A,F15.8)') "Optimization for geom ",IGeom," converged in ",Iopt," cycles, Energy =",E |
| 392 | 1 | pfleura2 | ELSE |
| 393 | 1 | pfleura2 | WRITE(*,'(1X,A,I5,A,I5,A,F15.8)') "Optimization for geom ",IGeom,"*NOT* converged in ",Iopt," cycles, Last Energy = ",E |
| 394 | 1 | pfleura2 | END IF |
| 395 | 1 | pfleura2 | |
| 396 | 1 | pfleura2 | WRITE(*,*) "Initial Geometry:" |
| 397 | 1 | pfleura2 | DO I=1, Nat |
| 398 | 1 | pfleura2 | WRITE(*,'(3(1X,F8.4))') XyzGeomI(IGeom,:,I) |
| 399 | 1 | pfleura2 | END DO |
| 400 | 1 | pfleura2 | WRITE(*,*) "Final Geometry:" |
| 401 | 1 | pfleura2 | DO I=1, Nat |
| 402 | 1 | pfleura2 | WRITE(*,'(3(1X,F8.4))') GeomCart(I,:) |
| 403 | 1 | pfleura2 | !IF (I .GT. 1) Then |
| 404 | 1 | pfleura2 | ! WRITE(*,'(F6.4)') Sqrt(((GeomCart(I,1)-GeomCart(I-1,1))*(GeomCart(I,1)-GeomCart(I-1,1)))& |
| 405 | 1 | pfleura2 | ! + ((GeomCart(I,2)-GeomCart(I-1,2))*(GeomCart(I,2)-GeomCart(I-1,2)))& |
| 406 | 1 | pfleura2 | ! + ((GeomCart(I,3)-GeomCart(I-1,3))*(GeomCart(I,3)-GeomCart(I-1,3)))) |
| 407 | 1 | pfleura2 | !END IF |
| 408 | 1 | pfleura2 | END DO |
| 409 | 1 | pfleura2 | |
| 410 | 1 | pfleura2 | IF (COORD .EQ. "BAKER") Then |
| 411 | 1 | pfleura2 | I=0 ! index for the NPrim (NPrim is the number of primitive coordinates). |
| 412 | 1 | pfleura2 | ScanCoord=>Coordinate |
| 413 | 1 | pfleura2 | DO WHILE (Associated(ScanCoord%next)) |
| 414 | 1 | pfleura2 | I=I+1 |
| 415 | 1 | pfleura2 | SELECT CASE (ScanCoord%Type) |
| 416 | 1 | pfleura2 | CASE ('BOND')
|
| 417 | 1 | pfleura2 | WRITE(*,'(1X,I3,":",I5," - ",I5," = ",F10.4)') I,ScanCoord%At1,ScanCoord%At2,Xprimitive_t(I) |
| 418 | 1 | pfleura2 | CASE ('ANGLE')
|
| 419 | 1 | pfleura2 | WRITE(*,'(1X,I3,":",I5," - ",I5," - ",I5," = ",F10.4)') I,ScanCoord%At1, & |
| 420 | 1 | pfleura2 | ScanCoord%At2, ScanCoord%At3,Xprimitive_t(I)*180./Pi |
| 421 | 1 | pfleura2 | CASE ('DIHEDRAL')
|
| 422 | 1 | pfleura2 | WRITE(*,'(1X,I3,":",I5," - ",I5," - ",I5," - ",I5," = ",F10.4)') I,ScanCoord%At1,& |
| 423 | 1 | pfleura2 | ScanCoord%At2, ScanCoord%At3,ScanCoord%At4,Xprimitive_t(I)*180./Pi |
| 424 | 1 | pfleura2 | END SELECT |
| 425 | 1 | pfleura2 | ScanCoord => ScanCoord%next |
| 426 | 1 | pfleura2 | END DO ! matches DO WHILE (Associated(ScanCoord%next)) |
| 427 | 1 | pfleura2 | END IF |
| 428 | 1 | pfleura2 | |
| 429 | 1 | pfleura2 | DEALLOCATE(GeomCart) |
| 430 | 1 | pfleura2 | |
| 431 | 1 | pfleura2 | if (debug) Call Header("Geom Optimization Over")
|
| 432 | 1 | pfleura2 | |
| 433 | 1 | pfleura2 | END SUBROUTINE Opt_geom |