root / src / Step_GDIIS_Simple_Err.f90 @ 2
Historique | Voir | Annoter | Télécharger (9,86 ko)
| 1 | 1 | pfleura2 | !C HEAT is never used, not even in call of Space(...) |
|---|---|---|---|
| 2 | 1 | pfleura2 | !C Geom = input parameter vector (Geometry). |
| 3 | 1 | pfleura2 | !C Grad = input gradient vector. |
| 4 | 2 | pfleura2 | SUBROUTINE Step_GDIIS_Simple_Err(NewGeom,Geom,NewGrad,GRAD,HP,HEAT,NCoord,FRST) |
| 5 | 2 | pfleura2 | |
| 6 | 1 | pfleura2 | IMPLICIT NONE |
| 7 | 1 | pfleura2 | integer, parameter :: KINT = kind(1) |
| 8 | 1 | pfleura2 | integer, parameter :: KREAL = kind(1.0d0) |
| 9 | 1 | pfleura2 | |
| 10 | 1 | pfleura2 | ! INCLUDE 'SIZES' |
| 11 | 1 | pfleura2 | |
| 12 | 1 | pfleura2 | INTEGER(KINT) :: NCoord |
| 13 | 2 | pfleura2 | REAL(KREAL) :: NewGeom(NCoord), Geom(NCoord), NewGrad(NCoord), GRAD(NCoord) |
| 14 | 1 | pfleura2 | REAL(KREAL) :: HEAT, HP |
| 15 | 1 | pfleura2 | LOGICAL :: FRST |
| 16 | 1 | pfleura2 | |
| 17 | 1 | pfleura2 | !************************************************************************ |
| 18 | 1 | pfleura2 | !* * |
| 19 | 1 | pfleura2 | !* DIIS PERFORMS DIRECT INVERSION IN THE ITERATIVE SUBSPACE * |
| 20 | 1 | pfleura2 | !* * |
| 21 | 1 | pfleura2 | !* THIS INVOLVES SOLVING FOR C IN Geom(NEW) = Geom' - HG' * |
| 22 | 1 | pfleura2 | !* * |
| 23 | 1 | pfleura2 | !* WHERE Geom' = SUM(C(I)Geom(I), THE C COEFFICIENTES COMING FROM * |
| 24 | 1 | pfleura2 | !* * |
| 25 | 1 | pfleura2 | !* | B 1 | . | C | = | 0 | * |
| 26 | 1 | pfleura2 | !* | 1 0 | |-L | | 1 | * |
| 27 | 1 | pfleura2 | !* * |
| 28 | 1 | pfleura2 | !* WHERE B(I,J) =GRAD(I)H(T)HGRAD(J) GRAD(I) = GRADIENT ON CYCLE I * |
| 29 | 1 | pfleura2 | !* Hess = INVERSE HESSIAN * |
| 30 | 1 | pfleura2 | !* * |
| 31 | 1 | pfleura2 | !* REFERENCE * |
| 32 | 1 | pfleura2 | !* * |
| 33 | 1 | pfleura2 | !* P. CSASZAR, P. PULAY, J. MOL. STRUCT. (THEOCHEM), 114, 31 (1984) * |
| 34 | 1 | pfleura2 | !* * |
| 35 | 1 | pfleura2 | !************************************************************************ |
| 36 | 1 | pfleura2 | !************************************************************************ |
| 37 | 1 | pfleura2 | !* * |
| 38 | 1 | pfleura2 | !* GEOMETRY OPTIMIZATION USING THE METHOD OF DIRECT INVERSION IN * |
| 39 | 1 | pfleura2 | !* THE ITERATIVE SUBSPACE (GDIIS), COMBINED WITH THE BFGS OPTIMIZER * |
| 40 | 1 | pfleura2 | !* (A VARIABLE METRIC METHOD) * |
| 41 | 1 | pfleura2 | !* * |
| 42 | 1 | pfleura2 | !* WRITTEN BY PETER L. CUMMINS, UNIVERSITY OF SYDNEY, AUSTRALIA * |
| 43 | 1 | pfleura2 | !* * |
| 44 | 1 | pfleura2 | !* REFERENCE * |
| 45 | 1 | pfleura2 | !* * |
| 46 | 1 | pfleura2 | !* "COMPUTATIONAL STRATEGIES FOR THE OPTIMIZATION OF EQUILIBRIUM * |
| 47 | 1 | pfleura2 | !* GEOMETRIES AND TRANSITION-STATE STRUCTURES AT THE SEMIEMPIRICAL * |
| 48 | 1 | pfleura2 | !* LEVEL", PETER L. CUMMINS, JILL E. GREADY, J. COMP. CHEM., 10, * |
| 49 | 1 | pfleura2 | !* 939-950 (1989). * |
| 50 | 1 | pfleura2 | !* * |
| 51 | 1 | pfleura2 | !* MODIFIED BY JJPS TO CONFORM TO EXISTING MOPAC CONVENTIONS * |
| 52 | 1 | pfleura2 | !* * |
| 53 | 1 | pfleura2 | !************************************************************************ |
| 54 | 1 | pfleura2 | |
| 55 | 1 | pfleura2 | ! MRESET = number of iterations. |
| 56 | 1 | pfleura2 | INTEGER(KINT), PARAMETER :: MRESET=15, M2=(MRESET+1)*(MRESET+1) !M2 = 256 |
| 57 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE, SAVE :: GeomSet(:), GradSet(:), ERR(:) ! MRESET*NCoord |
| 58 | 1 | pfleura2 | REAL(KREAL) :: ESET(MRESET) |
| 59 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE, SAVE :: DX(:), GSAVE(:) !NCoord |
| 60 | 2 | pfleura2 | REAL(KREAL) :: B(M2), BS(M2) |
| 61 | 1 | pfleura2 | LOGICAL DEBUG, PRINT |
| 62 | 1 | pfleura2 | INTEGER(KINT), SAVE :: MSET |
| 63 | 1 | pfleura2 | INTEGER(KINT) :: NDIIS, MPLUS, INV, ITERA, MM, I, J, K |
| 64 | 2 | pfleura2 | INTEGER(KINT) :: JJ, JNV, II, IONE, IJ, INK, ITmp |
| 65 | 2 | pfleura2 | REAL(KREAL) :: XMax, XNorm, DET, THRES |
| 66 | 1 | pfleura2 | |
| 67 | 1 | pfleura2 | DEBUG=.TRUE. |
| 68 | 1 | pfleura2 | PRINT=.TRUE. |
| 69 | 1 | pfleura2 | |
| 70 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(/,'' BEGIN Step_GDIIS_Simple_Err '')') |
| 71 | 1 | pfleura2 | |
| 72 | 1 | pfleura2 | ! Initialization |
| 73 | 1 | pfleura2 | IF (FRST) THEN |
| 74 | 1 | pfleura2 | ! FRST will be set to False in Space, so no need to modify it here |
| 75 | 1 | pfleura2 | IF (ALLOCATED(GeomSet)) THEN |
| 76 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(/,'' In FRST, Step_GDIIS_Simple_Err Dealloc '')') |
| 77 | 1 | pfleura2 | DEALLOCATE(GeomSet,GradSet,ERR,DX,GSave) |
| 78 | 1 | pfleura2 | RETURN |
| 79 | 1 | pfleura2 | ELSE |
| 80 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(/,'' In FRST, Step_GDIIS_Simple_Err alloc '')') |
| 81 | 1 | pfleura2 | ALLOCATE(GeomSet(MRESET*NCoord), GradSet(MRESET*NCoord), ERR(MRESET*NCoord)) |
| 82 | 1 | pfleura2 | ALLOCATE(DX(NCoord),GSAVE(NCoord)) |
| 83 | 1 | pfleura2 | END IF |
| 84 | 1 | pfleura2 | END IF |
| 85 | 1 | pfleura2 | |
| 86 | 1 | pfleura2 | ! SPACE SIMPLY LOADS THE CURRENT VALUES OF Geom AND GRAD INTO THE ARRAYS GeomSet AND GradSet |
| 87 | 1 | pfleura2 | ! HEAT is never used, not even in Space(...) |
| 88 | 1 | pfleura2 | CALL SPACE(MRESET,MSET,Geom,Grad,HEAT,NCoord,GeomSet,GradSet,ESET,FRST) |
| 89 | 1 | pfleura2 | |
| 90 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(/,'' Step_GDIIS_Simple_Err after Space '')') |
| 91 | 1 | pfleura2 | |
| 92 | 1 | pfleura2 | ! INITIALIZE SOME VARIABLES AND CONSTANTS: |
| 93 | 1 | pfleura2 | NDIIS = MSET |
| 94 | 1 | pfleura2 | MPLUS = MSET + 1 |
| 95 | 1 | pfleura2 | MM = MPLUS * MPLUS |
| 96 | 1 | pfleura2 | |
| 97 | 1 | pfleura2 | ! CONSTRUCT THE GDIIS MATRIX: |
| 98 | 1 | pfleura2 | ! B_ij calculations from <B_ij=(g_i-g_j)(R_i-R_j)> |
| 99 | 1 | pfleura2 | JJ=0 |
| 100 | 1 | pfleura2 | INV=-NCoord |
| 101 | 1 | pfleura2 | DO I=1,MSET |
| 102 | 1 | pfleura2 | INV=INV+NCoord |
| 103 | 1 | pfleura2 | JNV=-NCoord |
| 104 | 1 | pfleura2 | DO J=1,MSET |
| 105 | 1 | pfleura2 | JNV=JNV+NCoord |
| 106 | 1 | pfleura2 | JJ = JJ + 1 |
| 107 | 1 | pfleura2 | B(JJ)=0.D0 |
| 108 | 1 | pfleura2 | DO K=1, NCoord |
| 109 | 1 | pfleura2 | B(JJ) = B(JJ) + (((GradSet(INV+K)-GradSet(JNV+K))*(GeomSet(INV+K)-GeomSet(JNV+K)))/2.D0) |
| 110 | 1 | pfleura2 | END DO |
| 111 | 1 | pfleura2 | END DO |
| 112 | 1 | pfleura2 | END DO |
| 113 | 1 | pfleura2 | |
| 114 | 1 | pfleura2 | ! The following shifting is required to correct indices of B_ij elements in the GDIIS matrix. |
| 115 | 1 | pfleura2 | ! The correction is needed because the last coloumn of the matrix contains all 1 and one zero. |
| 116 | 1 | pfleura2 | DO 60 I=MSET-1,1,-1 |
| 117 | 1 | pfleura2 | DO 60 J=MSET,1,-1 |
| 118 | 1 | pfleura2 | 60 B(I*MSET+J+I) = B(I*MSET+J) |
| 119 | 1 | pfleura2 | |
| 120 | 1 | pfleura2 | ! for last row and last column of GDIIS matrix |
| 121 | 1 | pfleura2 | DO 70 I=1,MPLUS |
| 122 | 1 | pfleura2 | B(MPLUS*I) = 1.D0 |
| 123 | 1 | pfleura2 | 70 B(MPLUS*MSET+I) = 1.D0 |
| 124 | 1 | pfleura2 | B(MM) = 0.D0 |
| 125 | 1 | pfleura2 | |
| 126 | 1 | pfleura2 | ! ELIMINATE ERROR VECTORS WITH THE LARGEST NORM: |
| 127 | 1 | pfleura2 | 80 CONTINUE |
| 128 | 1 | pfleura2 | DO 90 I=1,MM |
| 129 | 1 | pfleura2 | 90 BS(I) = B(I) |
| 130 | 1 | pfleura2 | IF (NDIIS .EQ. MSET) GO TO 140 |
| 131 | 1 | pfleura2 | DO 130 II=1,MSET-NDIIS |
| 132 | 1 | pfleura2 | XMAX = -1.D10 |
| 133 | 1 | pfleura2 | ITERA = 0 |
| 134 | 1 | pfleura2 | DO 110 I=1,MSET |
| 135 | 1 | pfleura2 | XNORM = 0.D0 |
| 136 | 1 | pfleura2 | INV = (I-1) * MPLUS |
| 137 | 1 | pfleura2 | DO 100 J=1,MSET |
| 138 | 1 | pfleura2 | 100 XNORM = XNORM + ABS(B(INV + J)) |
| 139 | 1 | pfleura2 | IF (XMAX.LT.XNORM .AND. XNORM.NE.1.0D0) THEN |
| 140 | 1 | pfleura2 | XMAX = XNORM |
| 141 | 1 | pfleura2 | ITERA = I |
| 142 | 1 | pfleura2 | IONE = INV + I |
| 143 | 1 | pfleura2 | ENDIF |
| 144 | 1 | pfleura2 | 110 CONTINUE |
| 145 | 1 | pfleura2 | DO 120 I=1,MPLUS |
| 146 | 1 | pfleura2 | INV = (I-1) * MPLUS |
| 147 | 1 | pfleura2 | DO 120 J=1,MPLUS |
| 148 | 1 | pfleura2 | JNV = (J-1) * MPLUS |
| 149 | 1 | pfleura2 | IF (J.EQ.ITERA) B(INV + J) = 0.D0 |
| 150 | 1 | pfleura2 | B(JNV + I) = B(INV + J) |
| 151 | 1 | pfleura2 | 120 CONTINUE |
| 152 | 1 | pfleura2 | B(IONE) = 1.0D0 |
| 153 | 1 | pfleura2 | 130 CONTINUE |
| 154 | 1 | pfleura2 | 140 CONTINUE |
| 155 | 1 | pfleura2 | |
| 156 | 1 | pfleura2 | IF (DEBUG) THEN |
| 157 | 1 | pfleura2 | |
| 158 | 1 | pfleura2 | ! OUTPUT THE GDIIS MATRIX: |
| 159 | 1 | pfleura2 | WRITE(*,'(/5X,'' Step_GDIIS_Simple_Err MATRIX'')') |
| 160 | 1 | pfleura2 | ITmp=min(12,MPLUS) |
| 161 | 1 | pfleura2 | DO IJ=1,MPLUS |
| 162 | 1 | pfleura2 | WRITE(*,'(12(F10.4,1X))') B((IJ-1)*MPLUS+1:(IJ-1)*MPLUS+ITmp) |
| 163 | 1 | pfleura2 | END DO |
| 164 | 1 | pfleura2 | ENDIF |
| 165 | 1 | pfleura2 | |
| 166 | 1 | pfleura2 | ! SCALE DIIS MATRIX BEFORE INVERSION: |
| 167 | 1 | pfleura2 | DO 160 I=1,MPLUS |
| 168 | 1 | pfleura2 | II = MPLUS * (I-1) + I |
| 169 | 1 | pfleura2 | 160 GSAVE(I) = 1.D0 / DSQRT(1.D-20+DABS(B(II))) |
| 170 | 1 | pfleura2 | GSAVE(MPLUS) = 1.D0 |
| 171 | 1 | pfleura2 | DO 170 I=1,MPLUS |
| 172 | 1 | pfleura2 | DO 170 J=1,MPLUS |
| 173 | 1 | pfleura2 | IJ = MPLUS * (I-1) + J |
| 174 | 1 | pfleura2 | 170 B(IJ) = B(IJ) * GSAVE(I) * GSAVE(J) |
| 175 | 1 | pfleura2 | |
| 176 | 1 | pfleura2 | IF (DEBUG) THEN |
| 177 | 1 | pfleura2 | |
| 178 | 1 | pfleura2 | ! OUTPUT SCALED GDIIS MATRIX: |
| 179 | 1 | pfleura2 | WRITE(*,'(/5X,'' Step_GDIIS_Simple_Err MATRIX (SCALED)'')') |
| 180 | 1 | pfleura2 | ITmp=min(12,MPLUS) |
| 181 | 1 | pfleura2 | DO IJ=1,MPLUS |
| 182 | 1 | pfleura2 | WRITE(*,'(12(F10.4,1X))') B((IJ-1)*MPLUS+1:(IJ-1)*MPLUS+ITmp) |
| 183 | 1 | pfleura2 | END DO |
| 184 | 1 | pfleura2 | |
| 185 | 1 | pfleura2 | ENDIF ! matches IF (DEBUG) THEN |
| 186 | 1 | pfleura2 | |
| 187 | 1 | pfleura2 | ! INVERT THE GDIIS MATRIX B: |
| 188 | 1 | pfleura2 | CALL MINV(B,MPLUS,DET) ! matrix inversion. |
| 189 | 1 | pfleura2 | |
| 190 | 1 | pfleura2 | DO 190 I=1,MPLUS |
| 191 | 1 | pfleura2 | DO 190 J=1,MPLUS |
| 192 | 1 | pfleura2 | IJ = MPLUS * (I-1) + J |
| 193 | 1 | pfleura2 | 190 B(IJ) = B(IJ) * GSAVE(I) * GSAVE(J) |
| 194 | 1 | pfleura2 | |
| 195 | 1 | pfleura2 | ! COMPUTE THE INTERMEDIATE INTERPOLATED PARAMETER AND GRADIENT VECTORS: |
| 196 | 1 | pfleura2 | DO 200 K=1,NCoord |
| 197 | 1 | pfleura2 | NewGeom(K) = 0.D0 |
| 198 | 1 | pfleura2 | NewGrad(K) = 0.D0 |
| 199 | 1 | pfleura2 | DO 200 I=1,MSET |
| 200 | 1 | pfleura2 | INK = (I-1) * NCoord + K |
| 201 | 1 | pfleura2 | !Print *, 'B(',MPLUS*MSET+I,')=', B(MPLUS*MSET+I)
|
| 202 | 1 | pfleura2 | NewGeom(K) = NewGeom(K) + B(MPLUS*MSET+I) * GeomSet(INK) |
| 203 | 1 | pfleura2 | 200 NewGrad(K) = NewGrad(K) + B(MPLUS*MSET+I) * GradSet(INK) |
| 204 | 1 | pfleura2 | HP=0.D0 |
| 205 | 1 | pfleura2 | DO 210 I=1,MSET |
| 206 | 1 | pfleura2 | 210 HP=HP+B(MPLUS*MSET+I)*ESET(I) |
| 207 | 1 | pfleura2 | |
| 208 | 1 | pfleura2 | DO 220 K=1,NCoord |
| 209 | 1 | pfleura2 | 220 DX(K) = Geom(K) - NewGeom(K) |
| 210 | 1 | pfleura2 | XNORM = SQRT(DOT_PRODUCT(DX,DX)) |
| 211 | 1 | pfleura2 | IF (PRINT) THEN |
| 212 | 1 | pfleura2 | WRITE (6,'(/10X,''DEVIATION IN X '',F7.4,8X,''DETERMINANT '',G9.3)') XNORM,DET |
| 213 | 1 | pfleura2 | WRITE(*,'(10X,''Step_GDIIS_Simple_Err COEFFICIENTS'')') |
| 214 | 1 | pfleura2 | WRITE(*,'(10X,5F12.5)') (B(MPLUS*MSET+I),I=1,MSET) |
| 215 | 1 | pfleura2 | ENDIF |
| 216 | 1 | pfleura2 | |
| 217 | 1 | pfleura2 | ! THE FOLLOWING TOLERENCES FOR XNORM AND DET ARE SOMEWHAT ARBITRARY: |
| 218 | 1 | pfleura2 | THRES = MAX(10.D0**(-NCoord), 1.D-25) |
| 219 | 1 | pfleura2 | IF (XNORM.GT.2.D0 .OR. DABS(DET).LT. THRES) THEN |
| 220 | 1 | pfleura2 | IF (PRINT)THEN |
| 221 | 1 | pfleura2 | WRITE(*,*) "THE DIIS MATRIX IS ILL CONDITIONED" |
| 222 | 1 | pfleura2 | WRITE(*,*) " - PROBABLY, VECTORS ARE LINEARLY DEPENDENT - " |
| 223 | 1 | pfleura2 | WRITE(*,*) "THE DIIS STEP WILL BE REPEATED WITH A SMALLER SPACE" |
| 224 | 1 | pfleura2 | END IF |
| 225 | 1 | pfleura2 | DO 230 K=1,MM |
| 226 | 1 | pfleura2 | 230 B(K) = BS(K) |
| 227 | 1 | pfleura2 | NDIIS = NDIIS - 1 |
| 228 | 1 | pfleura2 | IF (NDIIS .GT. 0) GO TO 80 |
| 229 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(10X,''NEWTON-RAPHSON STEP TAKEN'')') |
| 230 | 1 | pfleura2 | DO 240 K=1,NCoord |
| 231 | 1 | pfleura2 | NewGeom(K) = Geom(K) |
| 232 | 1 | pfleura2 | 240 NewGrad(K) = GRAD(K) |
| 233 | 1 | pfleura2 | ENDIF ! matches IF (XNORM.GT.2.D0 .OR. DABS(DET).LT. THRES) THEN |
| 234 | 1 | pfleura2 | |
| 235 | 1 | pfleura2 | ! q_{m+1} = q'_{m+1} - H^{-1}g'_{m+1}
|
| 236 | 1 | pfleura2 | ! Hess is a symmetric matrix. |
| 237 | 1 | pfleura2 | !Hess_inv = 1.d0 ! to be deleted. |
| 238 | 1 | pfleura2 | !Call GenInv(NCoord,Reshape(Hess,(/NCoord,NCoord/)),Hess_inv,NCoord) ! Implemented in Mat_util.f90 |
| 239 | 1 | pfleura2 | ! H^{-1}g'_{m+1}
|
| 240 | 1 | pfleura2 | !Print *, 'Hess_inv=' |
| 241 | 1 | pfleura2 | ! Print *, Hess_inv |
| 242 | 1 | pfleura2 | !Geom=0.d0 |
| 243 | 1 | pfleura2 | !DO I=1, NCoord |
| 244 | 1 | pfleura2 | ! Geom(:) = Geom(:) + Hess_inv(:,I)*NewGrad(I) |
| 245 | 1 | pfleura2 | !END DO |
| 246 | 1 | pfleura2 | !Geom(:) = NewGeom(:) - Geom(:) ! now Geom is a new geometry. |
| 247 | 1 | pfleura2 | |
| 248 | 1 | pfleura2 | ! STEP is the difference between the new and old geometry and thus "step": |
| 249 | 1 | pfleura2 | !STEP = Geom - Geom_old |
| 250 | 1 | pfleura2 | |
| 251 | 1 | pfleura2 | IF (PRINT) WRITE(*,'(/,'' END Step_GDIIS_Simple_Err '',/)') |
| 252 | 1 | pfleura2 | |
| 253 | 1 | pfleura2 | END SUBROUTINE Step_GDIIS_Simple_Err |