Statistics
| Revision:

root / src / Opt_Geom.f90 @ 5

History | View | Annotate | Download (17.9 kB)

1
! This subroutine optimizes a geometry. 
2
! Initially, it was mainly here for  debugging purposes..
3
!so  It has been designed to be almost independent of the rest of the code.
4
! It is now an (almost) officiel option.
5

    
6
 SUBROUTINE Opt_geom(IGeom,Nat,NCoord,Coord,Geom,E,Flag_Opt_Geom,Step_method)
7

    
8
  use VarTypes
9
  use Path_module, only : maxcyc,sthresh,gthresh,Hinv,Smax,Nom,Atome,OrderInv,indzmat,&
10
                                            XyzGeomF,IntCoordF,UMat,ScanCoord,Coordinate,NPrim,&
11
                                            BTransInv,BTransInv_local,XyzGeomI,Xprimitive_t,ScanCoord,&
12
                                            Coordinate,Pi,UMat_local,NCart, DynMaxStep,FPrintGeom,GeomFile, AtName,Renum,Order
13
  use Io_module, only : IoGeom
14

    
15
  IMPLICIT NONE
16

    
17
  INTEGER(KINT), INTENT(IN) :: Nat,NCoord,IGeom
18
  CHARACTER(32), INTENT(IN) :: Coord
19
  CHARACTER(32), INTENT(IN) :: Step_method
20
  REAL(KREAL), INTENT(INOUT) :: Geom(NCoord)
21
  REAL(KREAL), INTENT(OUT) :: E
22
  LOGICAL, INTENT(IN) :: Flag_Opt_Geom
23

    
24

    
25
  INTERFACE
26
     function valid(string) result (isValid)
27
       CHARACTER(*), intent(in) :: string
28
       logical                  :: isValid
29
     END function VALID
30

    
31
     subroutine Egrad(E,Geom,Grad,NCoord,IGeom,IOpt,GeomCart,FOptGeom,GeomOld,GeomCart_old)
32

    
33
  ! This routines calculates the energy E and the gradient Grad of 
34
  ! a molecule with Geometry Geom (may be in internal coordinates),
35
  ! using for now, either Gaussian or Ext, more general later.
36

    
37
  use Path_module, only : Nat,AtName,Coord,dzdc,indzmat,Nom,Atome,massat,unit, &
38
       prog,NCart,XyzGeomF,IntCoordF,BTransInv, XyzGeomI, &
39
       GeomOld_all,BTransInvF,BTransInv_local,UMatF,UMat_local &
40
       , BprimT,a0,ScanCoord, Coordinate,NPrim,BMat_BakerT,BBT,BBT_inv &
41
      , Order,OrderInv, XPrimitiveF
42

    
43
  ! IntCoordF(NGeomF,NCoord),GeomOld_all(NGeomF,NCoord)
44
  ! allocated in Path.f90
45

    
46
  use Io_module
47

    
48
  ! Energy (calculated if F300K=.F., else estimated)
49
  REAL(KREAL), INTENT (OUT) :: E
50
  ! NCoord: Number of the degrees of freedom
51
  ! IGeom: index of the geometry.
52
  INTEGER(KINT), INTENT (IN) :: NCoord, IGeom, IOpt
53
  ! Geometry at which gradient is calculated (cf Factual also):
54
  REAL(KREAL), INTENT (INOUT) :: Geom(NCoord)
55
  ! Gradient calculated at Geom geometry:
56
  REAL(KREAL), INTENT (OUT) :: Grad(NCoord)
57
  ! Cartesian geometry corresponding to (Internal Geometry) Geom:
58
  REAL(KREAL), INTENT (OUT) :: GeomCart(Nat,3)
59
!!! Optional, just for geometry optimization with Baker coordinates
60
  REAL(KREAL), INTENT (IN), OPTIONAL :: GeomCart_old(Nat,3)
61
  REAL(KREAL), INTENT (INOUT), OPTIONAL :: GeomOld(NCoord)
62
! FOptGeom is a flag indicating if we are doing a geom optimization
63
! it can be omitted so that we use a local flag: Flag_Opt_Geom
64
  LOGICAL,INTENT (IN), OPTIONAL :: FOptGeom
65
! if FOptGeom is given Flag_Opt_Geom=FOptGeom, else Flag_Opt_Geom=F
66
  LOGICAL  :: Flag_Opt_Geom
67

    
68
 END subroutine Egrad
69

    
70
  END INTERFACE
71

    
72

    
73
  LOGICAL  :: debug
74
  LOGICAL :: Fini
75
  LOGICAL, SAVE :: FRST=.TRUE.
76

    
77
! Variables
78
  INTEGER(KINT) :: IOpt, I,J,Iat, IBEG
79
  REAL(KREAL), ALLOCATABLE :: GradTmp(:),ZeroVec(:) ! 3*Nat or 3*Nat-6
80
  REAL(KREAL), ALLOCATABLE :: GeomOld(:),GradOld(:) ! (3*Nat or 3*Nat-6)
81
  REAL(KREAL), ALLOCATABLE :: GeomRef(:) ! (3*Nat or 3*Nat-6)
82
  REAL(KREAL), ALLOCATABLE :: GeomTmp2(:),GradTmp2(:) ! 3*Nat or 3*Nat-6
83
  REAL(KREAL), ALLOCATABLE :: Hess_local(:,:)
84
  REAL(KREAL), ALLOCATABLE :: GeomCart(:,:) !(Nat,3)
85
  REAL(KREAL), ALLOCATABLE :: GeomCart_old(:,:) !(Nat,3)
86
  REAL(KREAL), ALLOCATABLE :: Hprim(:,:) !(NPrim,NPrim)
87
  REAL(KREAL), ALLOCATABLE :: HprimU(:,:) !(NPrim,3*Nat-6))
88
  REAL(KREAL), ALLOCATABLE :: NewGeom(:) !NCoord=3*Nat-6
89
  REAL(KREAL), ALLOCATABLE :: NewGradTmp(:)
90
  REAL(KREAL), ALLOCATABLE :: Hess_local_inv(:,:) ! used in diis
91
  REAL(KREAL) :: NormStep, FactStep, HP, MaxStep
92
  REAL(KREAL) :: Eold  
93

    
94
  debug=valid('OptGeom')
95

    
96
    E=0.
97
    Eold=0.
98
    MaxStep=SMax
99

    
100
    if (debug) Call Header("Entering Geom Optimization")
101

    
102
     ALLOCATE(GradTmp2(NCoord),GeomTmp2(NCoord),GradTmp(NCoord))
103
     ALLOCATE(GradOld(NCoord),GeomOld(NCoord),ZeroVec(NCoord))
104
     ALLOCATE(GeomRef(NCoord))
105
     ALLOCATE(Hess_local(NCoord,NCoord))
106
     ALLOCATE(GeomCart(Nat,3),GeomCart_old(Nat,3))
107
     ALLOCATE(NewGeom(NCoord))
108
     ALLOCATE(NewGradTmp(NCoord))
109
     ALLOCATE(Hess_local_inv(NCoord,NCoord))
110
        
111
     IOpt=0
112
     ZeroVec=0.d0
113
     
114
     ! Initialize the Hessian
115
     Hess_local=0.
116

    
117
     SELECT CASE (COORD)
118
        CASE ('ZMAT')
119
        ! We use the fact that we know that approximate good hessian values
120
        ! are 0.5 for bonds, 0.1 for valence angle and 0.02 for dihedral angles
121
        Hess_local(1,1)=0.5d0
122
        Hess_local(2,2)=0.5d0
123
        Hess_local(3,3)=0.1d0
124
        DO J=1,Nat-3
125
           Hess_local(3*J+1,3*J+1)=0.5d0
126
           Hess_local(3*J+2,3*J+2)=0.1d0
127
           Hess_local(3*J+3,3*J+3)=0.02d0
128
        END DO
129
        IF (HInv) THEN
130
           DO I=1,NCoord
131
              Hess_local(I,I)=1.d0/Hess_local(I,I)
132
           END DO
133
        END IF
134

    
135
        IF (Step_method .EQ. "RFO") Then
136
                   Hess_local=0.
137
           DO I=1,NCoord
138
              Hess_local(I,I)=0.5d0
139
           END DO
140
        END IF
141

    
142
     CASE ('BAKER')
143
            ! UMat(NPrim,3*Nat-6)
144
        BTransInv_local = BTransInv
145
        UMat_local = UMat
146
         ALLOCATE(Hprim(NPrim,NPrim),HprimU(NPrim,NCoord))
147
         Hprim=0.d0
148
         ScanCoord=>Coordinate
149
         I=0
150
         DO WHILE (Associated(ScanCoord%next))
151
            I=I+1
152
            SELECT CASE (ScanCoord%Type)
153
                     CASE ('BOND')
154
                          Hprim(I,I) = 0.5d0
155
            CASE ('ANGLE')
156
                          Hprim(I,I) = 0.2d0
157
            CASE ('DIHEDRAL')
158
                          Hprim(I,I) = 0.1d0
159
               END SELECT
160
            ScanCoord => ScanCoord%next
161
         END DO
162
               
163
         ! Hprim U:
164
         HprimU=0.d0
165
         DO I=1, NCoord
166
                  DO J=1,NPrim
167
               HprimU(:,I) = HprimU(:,I) + Hprim(:,J)*UMat(J,I)
168
            END DO
169
         END DO
170

    
171
         ! Hess = U^T Hprim U:
172
         Hess_local=0.d0
173
         DO I=1, NCoord
174
            DO J=1,NPrim
175
                     ! UMat^T is needed below.
176
                        Hess_local(:,I) = Hess_local(:,I) + UMat(J,:)*HprimU(J,I)
177
            END DO
178
         END DO
179
               
180
               !Print *, 'Hprim='
181
               DO I=1,NPrim
182
               !   WRITE(*,'(10(1X,F6.3))') Hprim(I,:)
183
            END DO
184
               !Print *, 'UMat='
185
               DO I=1,NPrim
186
                !  WRITE(*,'(3(1X,F6.3))') UMat(I,1:3)
187
            END DO
188
               !Print *, 'HprimU='
189
               DO I=1,NPrim
190
                !  WRITE(*,'(3(1X,F6.3))') HprimU(I,1:3)
191
            END DO
192
               !Print *, 'Hess_local='
193
               DO I=1,NCoord
194
                !  WRITE(*,'(3(1X,F6.3))') Hess_local(I,1:3)
195
            END DO
196
               
197
            DEALLOCATE(Hprim,HprimU)
198
               
199
         IF (HInv) THEN
200
                     Call GenInv(NCoord,Hess_local,Hess_local_inv,NCoord)
201
                  Hess_local = Hess_local_inv
202
        END IF
203
              
204
              !Print *, 'Hess_local after inversion='
205
               DO I=1,NCoord
206
               !   WRITE(*,'(3(1X,F6.3))') Hess_local(I,1:3)
207
            END DO
208
                             
209
        IF (Step_method .EQ. "RFO") Then
210
                 Hess_local=0.
211
           DO I=1,NCoord
212
              Hess_local(I,I)=0.5d0
213
           END DO
214
        END IF
215
                 
216
        CASE ('MIXED','CART','HYBRID')
217
        DO J=1,NCoord
218
           Hess_local(J,J)=1.
219
        END DO
220
        CASE DEFAULT
221
        WRITE (*,*) "Coord=",TRIM(COORD)," not recognized, opt_Geom.f90, L164. Stop"
222
        STOP
223
     END SELECT
224

    
225
     ! Go to optimization
226
     GeomOld=0.d0 ! Internal coordinates
227
     GeomCart_old=0.d0 ! Cartesian coordinates
228

    
229
     IF (FPrintGeom) THEN
230
        OPEN(IOGeom,File=GeomFile)
231
     END IF
232

    
233
     Fini=.FALSE.
234
     DO WHILE ((IOpt.LT.MaxCyc).AND.(.NOT.Fini))
235
        IOpt=IOpt+1
236

    
237
        ! Calculate the  energy and gradient
238
        IF (debug) THEN 
239
           WRITE(*,*) 'L134, DBG Opt_Geom, COORD=',TRIM(COORD),' IOpt=',IOpt
240
           WRITE(*,*) "Energy and Coordinates:"
241
           WRITE(*,'(F12.6,12(1X,F8.3))') E,Geom(1:min(NCoord,12))
242
           WRITE(*,*) "Geom Old:"
243
           WRITE(*,'(F12.6,12(1X,F8.3))') GEomOld(1:min(NCoord,13))
244
           WRITE(*,*) "Grad Old:"
245
           WRITE(*,'(F12.6,12(1X,F8.3))') GradOld(1:min(NCoord,13))
246
        END IF
247

    
248
        !Call EGrad(E,Geom,GradTmp,NCoord)
249
        IF (COORD.EQ.'BAKER') THEN
250
           ! GradTmp is gradient and calculated in Egrad.F, INTENT(OUT).
251
           ! GeomCart has INTENT(OUT)
252
           ! GeomRef is modified in Egrag_baker, so we should not use GeomOld variable
253
           GeomRef=GeomOld
254
           Call EGrad(E,Geom,GradTmp,NCoord,IGeom,IOpt,GeomCart,Flag_Opt_Geom, &
255
                GeomRef,GeomCart_old)
256
           GeomCart_old=GeomCart
257
        ELSE
258
           Call EGrad(E,Geom,GradTmp,NCoord,IGeom,IOpt,GeomCart)
259
        END IF
260
              
261
        IF (debug) THEN 
262
           WRITE(*,*) 'L198, DBG Opt_Geom, COORD=',TRIM(COORD),' IOpt=',IOpt
263
           WRITE(*,*) "Energy and Coordinates:"
264
           WRITE(*,'(F12.6,12(1X,F8.3))') E,Geom(1:min(NCoord,12))
265
           WRITE(*,*) "Geom Old:"
266
           WRITE(*,'(F12.6,12(1X,F8.3))') GEomOld(1:min(NCoord,12))
267
           WRITE(*,*) "Grad:"
268
           WRITE(*,'(F12.6,12(1X,F8.3))') GradTmp(1:min(NCoord,12))
269
        END IF
270

    
271
        IF (FPrintGeom) THEN
272
           WRITE(IoGeom,*) Nat
273
           WRITE(IoGeom,"(' Geom. ',I5,' Energy= ',F15.6)") IOpt, E
274

    
275
           DO I=1,Nat
276
              If (renum) THEN
277
                 Iat=Order(I)
278
                 WRITE(IoGeom,'(1X,A10,3(1X,F15.8),5X,3(1X,F15.8))') Trim(AtName(I)),GeomCart(Iat,:),GradTmp(3*Iat-2:3*Iat)
279
              ELSE
280
                 Iat=OrderInv(I)
281
                 WRITE(IoGeom,'(1X,A10,3(1X,F15.8),5X,3(1X,F15.8))') Trim(AtName(Iat)),GeomCart(I,:),GradTmp(3*I-2:3*I)
282
              END IF
283
           END DO
284
        END IF
285

    
286
        IF (IOpt.GE.2) THEN
287
        ! We have enough geometries and gradient to update the hessian (or its 
288
        ! inverse)
289
        GradTmp2=GradTmp-GradOld
290
        GeomTmp2=Geom-GeomOld
291

    
292
        if (debug) Write(*,*) "Call Hupdate_all, Geom"
293
        IF (debug) THEN
294
                 WRITE(*,*) "dx before calling",SHAPE(GeomTmp2)
295
                 WRITE(*,'(12(1X,F8.4))') GeomTmp2(1:NCoord)
296
                 WRITE(*,*) "dgrad before calling",SHAPE(GradTmp2)
297
                 WRITE(*,'(12(1X,F8.4))') GradTmp2(1:NCoord)
298
              END IF
299
           Call Hupdate_all(NCoord,GeomTmp2,GradTmp2,Hess_local)
300
        END IF ! matches IF (IOpt.GE.2) THEN
301
              
302
        GradOld=GradTmp
303
        GeomOld=Geom
304

    
305
        ! GradTmp becomes Step in Step_RFO_all.
306
              SELECT CASE (Step_method)
307
        CASE ('RFO')
308
          Call Step_RFO_all(NCoord,GradTmp,IGeom,Geom,GradTmp,Hess_local,ZeroVec)
309
              CASE ('GDIIS')
310
          Call Step_DIIS(NewGeom,Geom,NewGradTmp,GradTmp,HP,E,Hess_local,NCoord,FRST)
311
               ! q_{m+1} = q'_{m+1} - H^{-1}g'_{m+1}
312
                     Geom=0.d0
313
            DO I=1, NCoord
314
                        ! If Hinv=.False., then we need to invert Hess_local
315
                        Geom(:) = Geom(:) + Hess_local(:,I)*NewGradTmp(I)
316
                     END DO
317
                     Geom(:) = NewGeom(:) - Geom(:)
318
                     ! GradTmp now becomes "step" below:
319
                  GradTmp = Geom - GeomOld
320
              CASE ('GDIIST')
321
          Call Step_GDIIS_Simple_Err(NewGeom,Geom,NewGradTmp,GradTmp,HP,E,NCoord,FRST)
322
               ! q_{m+1} = q'_{m+1} - H^{-1}g'_{m+1}
323
                     Geom=0.d0
324
            DO I=1, NCoord
325
                        ! If Hinv=.False., then we need to invert Hess_local
326
                        Geom(:) = Geom(:) + Hess_local(:,I)*NewGradTmp(I)
327
                     END DO
328
                     Geom(:) = NewGeom(:) - Geom(:)
329
                     ! GradTmp now becomes "step" below:
330
                  GradTmp = Geom - GeomOld
331
              CASE ('GEDIIS')
332
          Call Step_GEDIIS(NewGeom,Geom,GradTmp,E,Hess_local,NCoord,FRST)
333
                     ! GradTmp is actually "step" below:
334
                   GradTmp = NewGeom - GeomOld
335
                !Call Step_GEDIIS_All(3,1,GradTmp,Geom,GradTmp,E,Hess_local,NCoord,FRST,ZeroVec)
336
            CASE DEFAULT
337
          WRITE (*,*) "Step_method=",TRIM(Step_method)," not recognized, opt_Geom.f90, L225. Stop"
338
          STOP
339
        END SELECT       
340

    
341
        Fini=.TRUE.
342
        !   If (IOpt.LT.5) GradTmp=(IOpt*GradTmp+(5-IOpt)*0.01*Grad(IGeom,:))/5.d0
343
        NormStep=sqrt(DOT_Product(GradTmp,GradTmp))
344
              WRITE(*,'(A,E10.4,1X,A,E10.4)') 'DBG OptGeom L215, NormStep=', NormStep, 'Step Threshold=', SThresh
345
        FactStep=min(1.d0,MaxStep/NormStep)
346
        Fini=(NormStep.LE.SThresh)
347
        NormStep=sqrt(DOT_Product(GradOld,GradOld)) ! GradOld is the value of gradients.
348
              WRITE(*,'(A,E10.4,1X,A,E10.4)') 'DBG OptGeom L219, NormStep (Gradient)=', NormStep, 'Gradient Threshold=', GThresh
349
        Fini=(Fini.AND.(NormStep.LE.GThresh))
350
        if (debug) WRITE(*,*) "DBG OptGeom FactStep=",FactStep
351
        GradTmp=GradTmp*FactStep ! GradTmp is step size here, from Step_RFO_all.
352

    
353

    
354
        if (DynMaxStep.AND.(IOpt>1)) THEN
355
           If (E<EOld) Then
356
              MaxStep=min(1.1*MaxStep,2.*SMax)
357
           ELSE
358
              MaxStep=max(0.8*MaxStep,SMax/2.)
359
           END IF
360
           if (debug) WRITE(*,*) "Dynamically updated  Maximum step in Opt_Geom:",MaxStep,MaxStep/SMax
361

    
362
        END IF
363

    
364
        Call Check_step(Coord,Nat,NCoord,GeomOld,GradTmp)
365
       
366
        Geom=GeomOld+GradTmp ! GradTmp is step size here, from Step_RFO_all.
367

    
368
        EOld=E
369

    
370
        IF (debug) THEN
371
           WRITE(*,*) "L235, DBG OptGeom, IGeom=",IGeom," IOpt=", IOpt
372
           SELECT CASE (COORD)
373
           CASE ('ZMAT','BAKER')
374
              !WRITE(*,'(12(1X,F8.3))') Geom(1:min(12,NCoord))
375
           CASE('CART','HYBRID')
376
              DO Iat=1,Nat
377
! PFL 30 Apr 2008 ->
378
! Deleted ref to orderinv that is created only for coord in zmat, baker, hybrid.
379
!                 WRITE(*,'(1X,A5,3(1X,F11.6))') Nom(Atome(OrderInv(indzmat(iat,1)))), &
380
                 WRITE(*,'(1X,A5,3(1X,F11.6))') Nom(Atome(iat)), &
381
                      Geom(3*Iat-2:3*Iat)
382
! <- PFL 30 Apr 2008
383
              END DO
384
           CASE('MIXED')
385
             DO Iat=1,NCart
386
                 WRITE(*,'(1X,A5,3(1X,F11.6))') Nom(Atome(OrderInv(indzmat(iat,1)))), &
387
                      Geom(3*Iat-2:3*Iat)
388
             END DO
389
            
390
             SELECT CASE (NCart)
391
             CASE(1)
392
               if (NAt.GE.2) THEN
393
                WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(OrderInv(indzmat(2,1)))), &
394
                      IndZmat(2,2),Geom(4)
395
                IBEG=5
396
               END IF
397
                IF (NAT.GE.3) THEN
398
                WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(OrderInv(indzmat(3,1)))), &
399
                      IndZmat(3,2),Geom(5),IndZmat(3,3),Geom(6)
400
                IBeg=7
401
               END IF
402
              CASE(2)
403
                WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))')  Nom(Atome(OrderInv(indzmat(3,1)))), &
404
                      IndZmat(3,2),Geom(7),IndZmat(3,3),Geom(8)
405
                IBeg=9
406
              CASE DEFAULT
407
                 IBeg=3*NCart+1
408
              END SELECT
409

    
410
              DO Iat=max(4,NCart),Nat
411
                WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(OrderInv(indzmat(iat,1)))), &
412
                      IndZmat(iat,1),Geom(IBeg),IndZmat(3,2),Geom(IBeg+1), &
413
                      IndZmat(3,3),Geom(IBeg+2)*180./pi
414
                IBeg=IBeg+3
415
              END DO
416

    
417
           CASE DEFAULT
418
               WRITE(*,*) "Coord=",TRIM(COORD)," not recognized in OptGeom. L294."
419
               STOP
420
           END SELECT
421
        END IF ! matches IF (debug) THEN
422
              
423
     END DO ! matches DO WHILE ((IOpt.LT.MaxCyc).AND.(.NOT.Fini))
424
        
425
     DEALLOCATE(GradTmp2,GeomTmp2,GradTmp)
426
     DEALLOCATE(GradOld,GeomOld)
427
     DEALLOCATE(Hess_local)
428
        DEALLOCATE(GeomCart_old)
429
        DEALLOCATE(NewGeom,NewGradTmp)
430
     DEALLOCATE(Hess_local_inv)
431

    
432
     IF (Fini) THEN
433
        WRITE(*,'(1X,A,I5,A,I5,A,F15.8)') "Optimization for geom ",IGeom," converged in ",Iopt," cycles, Energy =",E
434
     ELSE
435
        WRITE(*,'(1X,A,I5,A,I5,A,F15.8)') "Optimization  for geom ",IGeom," *NOT* converged in ",Iopt," cycles, Last Energy = ",E
436
     END IF
437
                
438
        WRITE(*,*) "Initial Geometry:"
439
        DO I=1, Nat
440
           WRITE(*,'(3(1X,F8.4))')  XyzGeomI(IGeom,:,I)
441
        END DO
442
         WRITE(*,*) "Final Geometry:"
443
        DO I=1, Nat
444
           WRITE(*,'(3(1X,F8.4))') GeomCart(I,:)
445
              !IF (I .GT. 1) Then
446
        !       WRITE(*,'(F6.4)') Sqrt(((GeomCart(I,1)-GeomCart(I-1,1))*(GeomCart(I,1)-GeomCart(I-1,1)))&
447
              !        + ((GeomCart(I,2)-GeomCart(I-1,2))*(GeomCart(I,2)-GeomCart(I-1,2)))&
448
              !        + ((GeomCart(I,3)-GeomCart(I-1,3))*(GeomCart(I,3)-GeomCart(I-1,3))))
449
              !END IF
450
        END DO
451
        
452
        IF (COORD .EQ. "BAKER") Then
453
            I=0 ! index for the NPrim (NPrim is the number of primitive coordinates).
454
            ScanCoord=>Coordinate
455
         DO WHILE (Associated(ScanCoord%next))
456
                  I=I+1
457
                     SELECT CASE (ScanCoord%Type)
458
                     CASE ('BOND')
459
                            WRITE(*,'(1X,I3,":",I5," - ",I5," = ",F10.4)') I,ScanCoord%At1,ScanCoord%At2,Xprimitive_t(I)
460
                     CASE ('ANGLE')
461
                            WRITE(*,'(1X,I3,":",I5," - ",I5," - ",I5," = ",F10.4)') I,ScanCoord%At1, &
462
                             ScanCoord%At2, ScanCoord%At3,Xprimitive_t(I)*180./Pi              
463
                     CASE ('DIHEDRAL')
464
                            WRITE(*,'(1X,I3,":",I5," - ",I5," - ",I5," - ",I5," = ",F10.4)') I,ScanCoord%At1,&
465
                            ScanCoord%At2, ScanCoord%At3,ScanCoord%At4,Xprimitive_t(I)*180./Pi
466
                     END SELECT
467
                     ScanCoord => ScanCoord%next
468
               END DO ! matches DO WHILE (Associated(ScanCoord%next))
469
        END IF
470
        
471
     DEALLOCATE(GeomCart)
472

    
473
    if (debug) Call Header("Geom Optimization Over")
474

    
475
   END SUBROUTINE Opt_geom