Statistiques
| Révision :

root / src / PathCreate.f90 @ 3

Historique | Voir | Annoter | Télécharger (37,5 ko)

1 1 pfleura2
!================================================================
2 1 pfleura2
!
3 1 pfleura2
! This subroutine create a path using starting geometries
4 1 pfleura2
! it is 'original' in the sense that the path is generated
5 1 pfleura2
! by interpolating internal coordinates instead of cartesian.
6 1 pfleura2
! Comes from the Extrapol.f subroutine of Cart suite.
7 1 pfleura2
! Rewritten in F90 to be more flexible
8 1 pfleura2
!
9 1 pfleura2
!================================================================
10 1 pfleura2
11 1 pfleura2
SUBROUTINE PathCreate(IOpt)
12 1 pfleura2
13 1 pfleura2
  use Io_module
14 1 pfleura2
  use Path_module, only : Nat, NGeomI, NCoord, NGeomF, IGeomRef, NMaxL, IReparam, IReparamT, &
15 1 pfleura2
       Coord, Frozen, Cart, NCart, NFroz, XyzGeomI, atome, r_cov, fact, &
16 1 pfleura2
       IndZmat, Renum, Order, OrderInv, IntCoordI, IntCoordF,Pi, BMat_BakerT, Nom, &
17 1 pfleura2
       Hess,IntFroz, ISpline, IntTangent, XyzGeomF, NPrim,Xprimitive_t, OptGeom,  &
18 1 pfleura2
       UMatF, UMat_local, XyzTangent, Linear, Align, FrozAtoms
19 1 pfleura2
  ! BMat_BakerT (3*Nat,NCoord), XyzGeomI(NGeomI,3,Nat), IGeomRef=-1 (default value)
20 1 pfleura2
  ! IntCoordI(NGeomI,NCoord)
21 1 pfleura2
22 1 pfleura2
  IMPLICIT NONE
23 1 pfleura2
24 1 pfleura2
  REAL(KREAL), PARAMETER :: Inf=1e32
25 1 pfleura2
  INTEGER(KINT), INTENT(IN) :: IOpt
26 1 pfleura2
27 1 pfleura2
  REAL(KREAL), ALLOCATABLE :: val_zmat(:,:), val_zmatTmp(:,:) ! (3,Nat)
28 1 pfleura2
  REAL(KREAL), ALLOCATABLE :: X0(:), Y0(:), Z0(:) ! Nat
29 1 pfleura2
  REAL(KREAL), ALLOCATABLE ::  XyzTmp(:,:), XyzTmp2(:,:) ! (Nat,3)
30 1 pfleura2
  !  REAL(KREAL), ALLOCATABLE ::  XyzTmp3(:,:) ! (3,Nat)
31 1 pfleura2
  REAL(KREAL), ALLOCATABLE ::  IntCoordTmp(:) ! (NCoord)
32 1 pfleura2
  INTEGER(KINT), ALLOCATABLE :: IndZmat0(:,:) !Nat,5
33 1 pfleura2
  REAL(KREAL), ALLOCATABLE :: Coef(:,:) ! (NGeomI,NCoord)
34 1 pfleura2
  ! NPrim=Number of primitive coordinates.
35 1 pfleura2
  REAL(KREAL), ALLOCATABLE :: XGeom(:) ! NGeomI
36 1 pfleura2
  REAL(KREAL), ALLOCATABLE :: XGeomF(:) ! NGeomF
37 1 pfleura2
  INTEGER(KINT) :: NGeomS
38 1 pfleura2
39 2 pfleura2
  REAL(KREAL) :: Rmsd, MRot(3, 3), Delta
40 2 pfleura2
  REAL(KREAL), PARAMETER ::  TwoPi=360.d0
41 2 pfleura2
  REAL(KREAL)  ::s, dist, a_val, d
42 2 pfleura2
  INTEGER(KINT) :: I, J, igeom, iat
43 2 pfleura2
  INTEGER(KINT) :: Itmp, Jat
44 1 pfleura2
  INTEGER(KINT) :: Idx,IBeg
45 1 pfleura2
  CHARACTER(LCHARS) :: Title
46 1 pfleura2
  REAL(KREAL), ALLOCATABLE :: x(:), y(:), z(:)
47 1 pfleura2
  LOGICAL ::  debug, print
48 1 pfleura2
  LOGICAL, SAVE :: First=.TRUE.
49 1 pfleura2
  ! Frozen contains the indices of frozen atoms
50 1 pfleura2
  LOGICAL, ALLOCATABLE :: FCart(:) ! Nat
51 1 pfleura2
  INTEGER, ALLOCATABLE :: AtCart(:) !Nat
52 1 pfleura2
  INTEGER(KINT), ALLOCATABLE ::  LIAISONS(:,:),LiaisonsIni(:,:) ! (Nat,0:NMaxL)
53 1 pfleura2
  INTEGER(KINT), ALLOCATABLE :: Fragment(:),NbAtFrag(:) !nat
54 1 pfleura2
  INTEGER(KINT), ALLOCATABLE :: FragAt(:,:) !nat,nat
55 1 pfleura2
  INTEGER(KINT) :: NbFrag,NFragRef
56 1 pfleura2
57 1 pfleura2
58 1 pfleura2
  INTERFACE
59 1 pfleura2
     function valid(string) result (isValid)
60 1 pfleura2
       CHARACTER(*), intent(in) :: string
61 1 pfleura2
       logical                  :: isValid
62 1 pfleura2
     END function VALID
63 1 pfleura2
64 1 pfleura2
     FUNCTION test_zmat(na,ind_zmat)
65 1 pfleura2
66 1 pfleura2
       USE Path_module
67 1 pfleura2
68 1 pfleura2
       logical :: test_zmat
69 1 pfleura2
       integer(KINT) :: na
70 1 pfleura2
       integer(KINT) :: ind_zmat(Na,5)
71 1 pfleura2
     END FUNCTION TEST_ZMAT
72 1 pfleura2
  END INTERFACE
73 1 pfleura2
74 1 pfleura2
75 1 pfleura2
76 1 pfleura2
  debug=valid("pathcreate")
77 1 pfleura2
  print=valid("printgeom")
78 1 pfleura2
  if (debug) Call header("Entering PathCreate")
79 1 pfleura2
  if (debug.AND.First) WRITE(*,*) "=     First call          ="
80 1 pfleura2
81 1 pfleura2
  if (debug) WRITE(*,*) "Iopt,IReparam=",Iopt,IReparam
82 1 pfleura2
83 1 pfleura2
  ALLOCATE(Coef(NGeomI,NCoord),val_zmat(Nat,3),val_zmatTMP(Nat,3))
84 1 pfleura2
  ALLOCATE(X0(Nat),Y0(Nat),Z0(Nat),Indzmat0(Nat,5))
85 1 pfleura2
  ALLOCATE(X(Nat),Y(Nat),Z(Nat),Xgeom(NGeomI),XgeomF(NGeomF))
86 1 pfleura2
  ! ALLOCATE(XyzTmp(Nat,3),XyzTmp2(Nat,3),XyzTmp3(3,Nat))
87 1 pfleura2
  ALLOCATE(XyzTmp(Nat,3),XyzTmp2(Nat,3))
88 1 pfleura2
  ALLOCATE(IntCoordTmp(NCoord))
89 1 pfleura2
90 1 pfleura2
  Do I=1,NGeomI
91 1 pfleura2
     XGeom(I)=FLoat(I)-1.d0
92 1 pfleura2
  END DO
93 1 pfleura2
94 1 pfleura2
  ! First iteration of the optimization:
95 1 pfleura2
  IF (First) THEN ! matches at L484
96 1 pfleura2
     if (debug) WRITE(*,*) "first iteration in PathCreate.90, L93"
97 1 pfleura2
98 1 pfleura2
     ! This is the first call, so we might have to generate a Zmat
99 1 pfleura2
     First=.FALSE.
100 1 pfleura2
101 1 pfleura2
     IF ( ((COORD.EQ."ZMAT").OR.(COORD.EQ."HYBRID").OR.(COORD.EQ."MIXED") &
102 1 pfleura2
          .OR.(COORD.EQ."BAKER")).AND.(IGeomRef.LE.0)) THEN
103 1 pfleura2
104 1 pfleura2
        ! User has not defined the Reference geometry, we have to choose it ourselves!
105 1 pfleura2
        ! This is done by counting the number of fragments of each geometry. The
106 1 pfleura2
        ! reference geometry is the one with the least fragments. When there are
107 1 pfleura2
        ! frozen or cart atoms, they are discarded to count the fragments.
108 1 pfleura2
109 1 pfleura2
        ALLOCATE(Liaisons(Nat,0:NMaxL))
110 1 pfleura2
        ALLOCATE(Fragment(nat),NbAtFrag(nat),FragAt(nat,nat),FCart(Nat))
111 1 pfleura2
        FCart=.FALSE.
112 1 pfleura2
        ! FCart(Nat) was under IF below earlier but is being accessed after this loop.
113 1 pfleura2
        IF ((Frozen(1).NE.0).OR.(Cart(1).NE.0)) THEN
114 1 pfleura2
           ALLOCATE(AtCart(Nat),LiaisonsIni(Nat,0:NMaxL))
115 1 pfleura2
           FCart=.FALSE.
116 1 pfleura2
           NCart=0
117 1 pfleura2
           Idx=1
118 1 pfleura2
           DO WHILE (Frozen(Idx).NE.0)
119 1 pfleura2
              IF (Frozen(Idx).LT.0) THEN
120 1 pfleura2
                 DO I=Frozen(Idx-1),abs(Frozen(Idx))
121 1 pfleura2
                    IF (.NOT.FCart(I)) THEN
122 1 pfleura2
                       NCart=NCart+1
123 1 pfleura2
                       AtCart(NCart)=I
124 1 pfleura2
                       FCart(I)=.TRUE.
125 1 pfleura2
                    END IF
126 1 pfleura2
                 END DO
127 1 pfleura2
              ELSE IF (.NOT.FCart(Frozen(Idx))) THEN
128 1 pfleura2
                 FCart(Frozen(Idx))=.TRUE.
129 1 pfleura2
                 NCart=NCart+1
130 1 pfleura2
                 AtCart(NCart)=Frozen(Idx)
131 1 pfleura2
              END IF
132 1 pfleura2
              Idx=Idx+1
133 1 pfleura2
           END DO ! matches DO WHILE (Frozen(Idx).NE.0)
134 1 pfleura2
           NFroz=NCart
135 1 pfleura2
           Idx=1
136 1 pfleura2
           DO WHILE (Cart(Idx).NE.0)
137 1 pfleura2
              IF (Cart(Idx).LT.0) THEN
138 1 pfleura2
                 DO I=Cart(Idx-1),abs(Cart(Idx))
139 1 pfleura2
                    IF (.NOT.FCart(I)) THEN
140 1 pfleura2
                       NCart=NCart+1
141 1 pfleura2
                       AtCart(NCart)=I
142 1 pfleura2
                       FCart(I)=.TRUE.
143 1 pfleura2
                    END IF
144 1 pfleura2
                 END DO
145 1 pfleura2
              ELSEIF (.NOT.FCart(Cart(Idx))) THEN
146 1 pfleura2
                 FCart(Cart(Idx))=.TRUE.
147 1 pfleura2
                 NCart=NCart+1
148 1 pfleura2
                 AtCart(NCart)=Cart(Idx)
149 1 pfleura2
              END IF
150 1 pfleura2
              Idx=Idx+1
151 1 pfleura2
           END DO !matches DO WHILE (Cart(Idx).NE.0)
152 1 pfleura2
           IF (debug) THEN
153 1 pfleura2
              WRITE(*,'(1X,A,I4,A,I4,A)') "DBG PathCreate - GeomRef :: Found ", &
154 1 pfleura2
                   NFroz," frozen atoms, and a total of ",NCart, &
155 1 pfleura2
                   " atoms described in cartesian coordinates"
156 1 pfleura2
              WRITE(*,*) "AtCart:",AtCart(1:NCart)
157 1 pfleura2
           END IF
158 1 pfleura2
        END IF ! IF ((Frozen(1).NE.0).OR.(Cart(1).NE.0)) THEN
159 1 pfleura2
160 1 pfleura2
        NFragRef=2*Nat
161 1 pfleura2
        DO IGeom=1,NGeomI
162 1 pfleura2
           x(1:Nat) = XyzGeomI(IGeom,1,1:Nat)
163 1 pfleura2
           y(1:Nat) = XyzGeomI(IGeom,2,1:Nat)
164 1 pfleura2
           z(1:Nat) = XyzGeomI(IGeom,3,1:Nat)
165 1 pfleura2
           ! we calculate the connectivities
166 1 pfleura2
           Call CalcCnct(nat,atome,x,y,z,LIAISONS,r_cov,fact)
167 1 pfleura2
           ! if needed, we get rid of links between cart or frozen atoms
168 1 pfleura2
           IF (NCart.GE.2) THEN
169 1 pfleura2
              LiaisonsIni=Liaisons
170 1 pfleura2
              DO I=1,NCart
171 1 pfleura2
                 Iat=AtCart(I)
172 1 pfleura2
                 if (debug) WRITE(*,'(20(1X,I3))') I,Iat,  &
173 1 pfleura2
                      (LiaisonsIni(Iat,Itmp),ITmp=0,LiaisonsIni(Iat,0))
174 1 pfleura2
                 DO J=1,LiaisonsIni(Iat,0)
175 1 pfleura2
                    Jat=LiaisonsIni(Iat,J)
176 1 pfleura2
                    IF (FCart(Jat)) THEN
177 1 pfleura2
                       Call Annul(Liaisons,Iat,Jat)
178 1 pfleura2
                       Call Annul(Liaisons,Jat,Iat)
179 1 pfleura2
                       Call Annul(LiaisonsIni,Jat,Iat)
180 1 pfleura2
                       Liaisons(Iat,0)=Liaisons(Iat,0)-1
181 1 pfleura2
                       Liaisons(Jat,0)=Liaisons(Jat,0)-1
182 1 pfleura2
                       LiaisonsIni(Jat,0)=LiaisonsIni(Jat,0)-1
183 1 pfleura2
                    END IF
184 1 pfleura2
                 END DO
185 1 pfleura2
              END DO
186 1 pfleura2
           END IF ! matches IF (NCart.GE.2) THEN
187 1 pfleura2
           ! we now calculate the number of fragments.
188 1 pfleura2
           Call Decomp_frag(nat,liaisons,.NOT.Fcart,nbfrag,Fragment,NbAtFrag,FragAt)
189 1 pfleura2
           IF (NbFrag.LT.NFragRef) THEN
190 1 pfleura2
              NFragRef=NbFrag
191 1 pfleura2
              ! The reference geometry, IGeomRef, is determined based on the least number
192 1 pfleura2
              ! of fragments (here if (((COORD.EQ."ZMAT").OR.(COORD.EQ."HYBRID").OR.(COORD
193 1 pfleura2
              !.EQ."MIXED")).AND.(IGeomRef.LE.0))), otherwise it still has the value of
194 1 pfleura2
              ! IGeomRef=-1.
195 1 pfleura2
              IGeomRef=IGeom
196 1 pfleura2
           END IF
197 1 pfleura2
        END DO ! matches DO IGeom=1,NGeomI
198 1 pfleura2
        DEALLOCATE(FCart)
199 1 pfleura2
     END IF ! matches IF (((COORD.EQ."ZMAT").OR.(COORD.EQ."HYBRID").OR.(COORD.EQ."MIXED")
200 1 pfleura2
     ! .OR.(COORD.EQ."BAKER")).AND.(IGeomRef.LE.0)).
201 1 pfleura2
202 1 pfleura2
     if (debug) WRITE(*,*) "DBG PathCreate : IGeomRef= ",IGeomRef
203 1 pfleura2
204 1 pfleura2
     ! we now compute the internal coordinates for this geometry !
205 1 pfleura2
     ! The reference geometry, IGeomRef, is determined based on the least number
206 1 pfleura2
     ! of fragments if (((COORD.EQ."ZMAT").OR.(COORD.EQ."HYBRID").OR.(COORD
207 1 pfleura2
     !.EQ."MIXED")).AND.(IGeomRef.LE.0)), otherwise it has the value of
208 1 pfleura2
     ! IGeomRef=-1.
209 1 pfleura2
     x(1:Nat) = XyzGeomI(IGeomRef,1,1:Nat) ! XyzGeomI(NGeomI,3,Nat)
210 1 pfleura2
     y(1:Nat) = XyzGeomI(IGeomRef,2,1:Nat)
211 1 pfleura2
     z(1:Nat) = XyzGeomI(IGeomRef,3,1:Nat)
212 1 pfleura2
213 1 pfleura2
     IndZmat=0
214 1 pfleura2
     IndZmat0=0
215 1 pfleura2
216 1 pfleura2
     SELECT CASE(COORD)
217 1 pfleura2
     CASE ('BAKER')
218 1 pfleura2
        ! atome(Nat), r_cov(0:Max_Z)
219 1 pfleura2
        ! Frozen(Nat) contains the indices of frozen atoms
220 1 pfleura2
        Call Calc_baker(atome,r_cov,fact,frozen,IGeomRef)
221 1 pfleura2
        if (debug) THEN
222 1 pfleura2
           WRITE(*,*) "UMat_local after Calc_baker"
223 1 pfleura2
           DO I=1,3*Nat-6
224 1 pfleura2
              WRITE(*,'(50(1X,F12.8))') UMat_local(:,I)
225 1 pfleura2
           END DO
226 1 pfleura2
        END IF
227 1 pfleura2
        DO IGeom=1,NGeomF
228 1 pfleura2
           UMatF(IGeom,:,:)=UMat_Local(:,:)
229 1 pfleura2
        END DO
230 1 pfleura2
231 1 pfleura2
        ALLOCATE(Xprimitive_t(NPrim))
232 1 pfleura2
        ! x, y, z corresponds the reference geometry.
233 1 pfleura2
        DO I=1,Nat
234 1 pfleura2
           Order(I)=I
235 1 pfleura2
           OrderInv(I)=I
236 1 pfleura2
        END DO
237 1 pfleura2
        x0=x
238 1 pfleura2
        y0=y
239 1 pfleura2
        z0=z
240 1 pfleura2
     CASE ('ZMAT','HYBRID')
241 1 pfleura2
        ! IN case we are using Hybrid or zmat coordinate system, we have to
242 1 pfleura2
        ! generate the internal coordinates with a Z-Matrix
243 1 pfleura2
        ! IN case we have frozen atoms, we generate a constrained Zmat
244 1 pfleura2
        IF (Frozen(1).NE.0) THEN
245 1 pfleura2
           Renum=.True.
246 1 pfleura2
           call Calc_zmat_const_frag(Nat,atome,IndZmat0,val_zmat,x,y,z,r_cov,fact,frozen)
247 1 pfleura2
        ELSE
248 1 pfleura2
           !no zmat... we create our own
249 1 pfleura2
           call Calc_zmat_frag(Nat,atome,IndZmat0,val_zmat,x,y,z,r_cov,fact)
250 1 pfleura2
           if (valid('old_zmat')) THEN
251 1 pfleura2
              call Calc_zmat(Nat,atome,IndZmat0,val_zmat,x,y,z,r_cov,fact)
252 1 pfleura2
              WRITE(*,*) "DBG PathCreate Calc_Zmat.... STOP"
253 1 pfleura2
              STOP
254 1 pfleura2
           END IF
255 1 pfleura2
        END IF
256 1 pfleura2
257 1 pfleura2
        if (debug) WRITE(*,*) 'Back from Calc_zmat'
258 1 pfleura2
        IF (.NOT.test_zmat(nat,IndZmat0)) THEN
259 1 pfleura2
           WRITE(IOOUT,*) "I cannot generate a valid Zmat... help"
260 1 pfleura2
           STOP
261 1 pfleura2
        END IF
262 1 pfleura2
263 1 pfleura2
        ! The IndZmat0 generated by Calc_zmat refers to the order of the input x,y,z
264 1 pfleura2
        ! However, we need it with the new order so that we can use the zmat
265 1 pfleura2
        ! coordinates to generate cartesian coordinates.
266 1 pfleura2
        ! So, we have to reorder it...
267 1 pfleura2
        DO I=1,Nat
268 1 pfleura2
           Order(IndZmat0(I,1))=I
269 1 pfleura2
           OrderInv(I)=IndZmat0(I,1)
270 1 pfleura2
           ! I let X0 being the Cartesian coordinates of the reference geometry. Before it was
271 1 pfleura2
           ! those of the First geometry (which was also the reference one). This might change!
272 1 pfleura2
           X0(i)=X(IndZmat0(i,1))
273 1 pfleura2
           Y0(i)=Y(IndZmat0(i,1))
274 1 pfleura2
           Z0(i)=Z(IndZmat0(i,1))
275 1 pfleura2
        END DO
276 1 pfleura2
        IndZmat(1,1)=Order(IndZmat0(1,1))
277 1 pfleura2
        IndZmat(2,1)=Order(IndZmat0(2,1))
278 1 pfleura2
        IndZmat(2,2)=Order(IndZmat0(2,2))
279 1 pfleura2
        IndZmat(3,1)=Order(IndZmat0(3,1))
280 1 pfleura2
        IndZmat(3,2)=Order(IndZmat0(3,2))
281 1 pfleura2
        IndZmat(3,3)=Order(IndZmat0(3,3))
282 1 pfleura2
        DO I=4,Nat
283 1 pfleura2
           DO J=1,4
284 1 pfleura2
              IndZmat(I,J)=Order(IndZmat0(I,J))
285 1 pfleura2
           END DO
286 1 pfleura2
        end do
287 1 pfleura2
        IF (DEBUG) THEN
288 1 pfleura2
           WRITE(IOOUT,*) "DBG PathCreate : IndZmat"
289 1 pfleura2
           DO I=1,Nat
290 1 pfleura2
              WRITE(IOOUT,*) (IndZmat(I,J),J=1,5)
291 1 pfleura2
           END DO
292 1 pfleura2
           WRITE(IOOUT,*) "DBG PathCreate : IndZmat0"
293 1 pfleura2
           DO I=1,Nat
294 1 pfleura2
              WRITE(IOOUT,*) (IndZmat0(I,J),J=1,5)
295 1 pfleura2
           END DO
296 1 pfleura2
297 1 pfleura2
        END IF
298 1 pfleura2
299 1 pfleura2
        ! It is the first call, we have to create all internal coordinates
300 1 pfleura2
        if (debug) WrITE(*,*) "DBG PathCreate L302: First Call, we generate internal coords"
301 1 pfleura2
        DO igeom=1,NgeomI
302 1 pfleura2
           x(1:Nat) = XyzGeomI(IGeom,1,1:Nat)
303 1 pfleura2
           y(1:Nat) = XyzGeomI(IGeom,2,1:Nat)
304 1 pfleura2
           z(1:Nat) = XyzGeomI(IGeom,3,1:Nat)
305 1 pfleura2
306 1 pfleura2
           if (debug) WRITE(*,*) "DBG PathCreate L308: we generate internal coords for geom",IGeom
307 1 pfleura2
308 1 pfleura2
           Call ConvXyzZmat(Nat,x,y,z,IndZmat0,val_zmatTmp)
309 1 pfleura2
           IntCoordI(IGeom,1)=val_zmatTmp(2,1)
310 1 pfleura2
           IntCoordI(IGeom,2)=val_zmatTmp(3,1)
311 1 pfleura2
           IntCoordI(IGeom,3)=val_zmatTmp(3,2)*Pi/180.
312 1 pfleura2
           Idx=4
313 1 pfleura2
           DO i=4,nat
314 1 pfleura2
              IntCoordI(IGeom,Idx)=val_zmatTmp(i,1)
315 1 pfleura2
              Idx=Idx+1
316 1 pfleura2
              IntCoordI(IGeom,Idx)=val_zmatTmp(i,2)*Pi/180.
317 1 pfleura2
              Idx=Idx+1
318 1 pfleura2
319 1 pfleura2
              ! Some tests to check that the dihedral angles are similar... this is
320 1 pfleura2
              ! important if they are close to Pi.
321 1 pfleura2
              Delta=0.
322 1 pfleura2
323 1 pfleura2
              if (abs(val_zmatTMP(i,3)-val_zmat(i,3))>=180.) THEN
324 1 pfleura2
                 if ((val_zmatTMP(i,3)-val_zmat(i,3))<=-180.) THEN
325 1 pfleura2
                    Delta=-1.0d0*TwoPi
326 1 pfleura2
                 ELSE
327 1 pfleura2
                    Delta=TwoPi
328 1 pfleura2
                 END IF
329 1 pfleura2
                 if (debug) THEN
330 1 pfleura2
                    WRITE(*,*) Nom(atome(i)),        &
331 1 pfleura2
                         abs(val_zmatTMP(i,3)-val_zmat(i,3)), &
332 1 pfleura2
                         val_zmatTMP(i,3),val_zmat(i,3),Delta, &
333 1 pfleura2
                         val_zmatTMP(i,3)-Delta
334 1 pfleura2
                 END IF
335 1 pfleura2
              END IF
336 1 pfleura2
              IntCoordI(IGeom,Idx)=(val_zmatTmp(i,3)-Delta)/180.*Pi
337 1 pfleura2
              Idx=Idx+1
338 1 pfleura2
           END DO
339 1 pfleura2
        END DO  ! End Loop on Igeom
340 1 pfleura2
341 1 pfleura2
     CASE ('MIXED')
342 1 pfleura2
        ! IN case we are using mixed coordinate system, we have to
343 1 pfleura2
        ! we generate the internal coordinates with a Z-Matrix
344 1 pfleura2
        Renum=.TRUE.
345 1 pfleura2
        !
346 1 pfleura2
        call Calc_mixed_frag(Nat,atome,IndZmat0,val_zmat,x,y,z, &
347 1 pfleura2
             r_cov,fact,frozen,cart,ncart)
348 1 pfleura2
349 1 pfleura2
        if (debug) WRITE(*,*) 'Back from Calc_Mixed'
350 1 pfleura2
351 1 pfleura2
        ! How to test this partial zmat ? it must be good as it was automatically generated...
352 1 pfleura2
        !        IF (.NOT.test_zmat(nat,IndZmat0)) THEN
353 1 pfleura2
        !           WRITE(IOOUT,*) "I cannot generate a valid Zmat... help"
354 1 pfleura2
        !           STOP
355 1 pfleura2
        !        END IF
356 1 pfleura2
357 1 pfleura2
        ! The IndZmat0 generated by Calc_zmat refers to the order of the input x,y,z
358 1 pfleura2
        ! However, we need it with the new order so that we can use the zmat
359 1 pfleura2
        ! coordinates to generate cartesian coordinates.
360 1 pfleura2
        ! So, we have to reorder it...
361 1 pfleura2
        DO I=1,Nat
362 1 pfleura2
           Order(IndZmat0(I,1))=I
363 1 pfleura2
           OrderInv(I)=IndZmat0(I,1)
364 1 pfleura2
           ! I let X0 being the Cartesian coordinates of the reference geometry. Before it was
365 1 pfleura2
           ! those of the First geometry (which was also the reference one). This might change!
366 1 pfleura2
           X0(i)=X(IndZmat0(i,1))
367 1 pfleura2
           Y0(i)=Y(IndZmat0(i,1))
368 1 pfleura2
           Z0(i)=Z(IndZmat0(i,1))
369 1 pfleura2
        END DO
370 1 pfleura2
        IndZmat=0
371 1 pfleura2
        IndZmat(1:NCart,:)=-1
372 1 pfleura2
373 1 pfleura2
        DO I=1,Nat
374 1 pfleura2
           IndZmat(I,1)=Order(IndZmat0(I,1))
375 1 pfleura2
        END DO
376 1 pfleura2
377 1 pfleura2
        SELECT CASE (NCart)
378 1 pfleura2
        CASE (1)
379 1 pfleura2
           IndZmat(2,2)=Order(IndZmat0(2,2))
380 1 pfleura2
           IndZmat(3,2)=Order(IndZmat0(3,2))
381 1 pfleura2
           IndZmat(3,3)=Order(IndZmat0(3,3))
382 1 pfleura2
           IdX=4
383 1 pfleura2
        CASE (2)
384 1 pfleura2
           IndZmat(3,2)=Order(IndZmat0(3,2))
385 1 pfleura2
           IndZmat(3,3)=Order(IndZmat0(3,3))
386 1 pfleura2
           Idx=4
387 1 pfleura2
        CASE DEFAULT
388 1 pfleura2
           Idx=NCart+1
389 1 pfleura2
        END SELECT
390 1 pfleura2
391 1 pfleura2
        DO I=Idx,Nat
392 1 pfleura2
           DO J=1,4
393 1 pfleura2
              IndZmat(I,J)=Order(IndZmat0(I,J))
394 1 pfleura2
           END DO
395 1 pfleura2
        end do
396 1 pfleura2
        IF (DEBUG) THEN
397 1 pfleura2
           WRITE(IOOUT,*) "DBG PathCreate : IndZmat - Mixed"
398 1 pfleura2
           DO I=1,Nat
399 1 pfleura2
              WRITE(IOOUT,*) (IndZmat(I,J),J=1,5)
400 1 pfleura2
           END DO
401 1 pfleura2
        END IF
402 1 pfleura2
403 1 pfleura2
        ! It is the first call, we have to create all internal coordinates
404 1 pfleura2
        !            Idx=1
405 1 pfleura2
        !            DO I=1,NCart
406 1 pfleura2
        !               IntCoordI(1,Idx)=val_zmat(I,1)
407 1 pfleura2
        !               IntCoordI(1,Idx+1)=val_zmat(I,2)
408 1 pfleura2
        !               IntCoordI(1,Idx+2)=val_zmat(I,3)
409 1 pfleura2
        !               Idx=Idx+3
410 1 pfleura2
        !            END DO
411 1 pfleura2
        !            SELECT CASE (NCART)
412 1 pfleura2
        !            CASE (1)
413 1 pfleura2
        !               IntCoordI(1,Idx)=val_zmat(2,1)
414 1 pfleura2
        !               IntCoordI(1,Idx+1)=val_zmat(3,1)
415 1 pfleura2
        !               IntCoordI(1,Idx+2)=val_zmat(3,2)*Pi/180.
416 1 pfleura2
        !               Idx=Idx+3
417 1 pfleura2
        !               IBeg=4
418 1 pfleura2
        !            CASE (2)
419 1 pfleura2
        !               IntCoordI(1,Idx)=val_zmat(3,1)
420 1 pfleura2
        !               IntCoordI(1,Idx+1)=val_zmat(3,2)*Pi/180.
421 1 pfleura2
        !               Idx=Idx+2
422 1 pfleura2
        !               IBeg=4
423 1 pfleura2
        !            CASE DEFAULT
424 1 pfleura2
        !               IBeg=NCart+1
425 1 pfleura2
        !            END SELECT
426 1 pfleura2
        !            DO i=iBeg,Nat
427 1 pfleura2
        !               IntCoordI(1,Idx)=val_zmat(i,1)
428 1 pfleura2
        !               Idx=Idx+1
429 1 pfleura2
        !               DO j=2,3
430 1 pfleura2
        !                  IntCoordI(1,Idx)=val_zmat(i,j)*Pi/180.
431 1 pfleura2
        !                  Idx=Idx+1
432 1 pfleura2
        !               END DO
433 1 pfleura2
        !            END DO
434 1 pfleura2
435 1 pfleura2
        !            If (debug) WRITE(*,*) "Idx, NCoord",Idx-1,NCoord
436 1 pfleura2
437 1 pfleura2
        DO Igeom=1,NgeomI
438 1 pfleura2
           x(1:Nat) = XyzGeomI(IGeom,1,1:Nat)
439 1 pfleura2
           y(1:Nat) = XyzGeomI(IGeom,2,1:Nat)
440 1 pfleura2
           z(1:Nat) = XyzGeomI(IGeom,3,1:Nat)
441 1 pfleura2
442 1 pfleura2
           Call ConvXyzMixed(Nat,Ncart,x,y,z,IndZmat0,val_zmatTmp(1,1))
443 1 pfleura2
           Idx=1
444 1 pfleura2
           DO I=1,NCart
445 1 pfleura2
              IntCoordI(IGeom,Idx)=val_zmatTmp(I,1)
446 1 pfleura2
              IntCoordI(IGeom,Idx+1)=val_zmatTmp(I,2)
447 1 pfleura2
              IntCoordI(IGeom,Idx+2)=val_zmatTmp(I,3)
448 1 pfleura2
              Idx=Idx+3
449 1 pfleura2
           END DO
450 1 pfleura2
451 1 pfleura2
           SELECT CASE (NCART)
452 1 pfleura2
           CASE (1)
453 1 pfleura2
              IntCoordI(IGeom,Idx)=val_zmatTmp(2,1)
454 1 pfleura2
              Idx=Idx+1
455 1 pfleura2
              IntCoordI(IGeom,Idx)=val_zmatTmp(3,1)
456 1 pfleura2
              IntCoordI(IGeom,Idx+1)=val_zmatTmp(3,2)*Pi/180.
457 1 pfleura2
              Idx=Idx+2
458 1 pfleura2
              IBeg=4
459 1 pfleura2
           CASE (2)
460 1 pfleura2
              IntCoordI(IGeom,Idx)=val_zmatTmp(3,1)
461 1 pfleura2
              IntCoordI(IGeom,Idx+1)=val_zmatTmp(3,2)*Pi/180.
462 1 pfleura2
              Idx=Idx+2
463 1 pfleura2
              IBeg=4
464 1 pfleura2
           CASE DEFAULT
465 1 pfleura2
              Ibeg=Ncart+1
466 1 pfleura2
           END SELECT
467 1 pfleura2
           DO i=IBeg,Nat
468 1 pfleura2
              IntCoordI(IGeom,Idx)=val_zmatTmp(i,1)
469 1 pfleura2
              Idx=Idx+1
470 1 pfleura2
              IntCoordI(IGeom,Idx)=val_zmatTmp(i,2)*Pi/180.
471 1 pfleura2
              Idx=Idx+1
472 1 pfleura2
473 1 pfleura2
              ! Some tests to check that the dihedral angles are similar... this is
474 1 pfleura2
              ! important if they are close to Pi.
475 1 pfleura2
              Delta=0.
476 1 pfleura2
477 1 pfleura2
              if (abs(val_zmatTMP(i,3)-val_zmat(i,3))>=180.) THEN
478 1 pfleura2
                 if ((val_zmatTMP(i,3)-val_zmat(i,3))<=-180.) THEN
479 1 pfleura2
                    Delta=-1.0d0*TwoPi
480 1 pfleura2
                 ELSE
481 1 pfleura2
                    Delta=TwoPi
482 1 pfleura2
                 END IF
483 1 pfleura2
                 if (debug) THEN
484 1 pfleura2
                    WRITE(*,*) Nom(atome(i)), &
485 1 pfleura2
                         abs(val_zmatTMP(i,3)-val_zmat(i,3)), &
486 1 pfleura2
                         val_zmatTMP(i,3),val_zmat(i,3),Delta, &
487 1 pfleura2
                         val_zmatTMP(i,3)-Delta
488 1 pfleura2
                 END IF
489 1 pfleura2
              END IF
490 1 pfleura2
              IntCoordI(IGeom,Idx)=(val_zmatTmp(i,3)-Delta)/180.*Pi
491 1 pfleura2
              Idx=Idx+1
492 1 pfleura2
           END DO
493 1 pfleura2
494 1 pfleura2
        END DO
495 1 pfleura2
     CASE ('CART')
496 1 pfleura2
        DO I=1,Nat
497 1 pfleura2
           Order(I)=I
498 1 pfleura2
           OrderInv(I)=I
499 1 pfleura2
        END DO
500 1 pfleura2
        X0=X
501 1 pfleura2
        Y0=y
502 1 pfleura2
        Z0=z
503 1 pfleura2
     END SELECT
504 1 pfleura2
505 1 pfleura2
  ELSE ! First iteration of the optimization. Match at L616
506 1 pfleura2
507 1 pfleura2
     IGeom=1
508 1 pfleura2
     x(1:Nat) = XyzGeomI(IGeom,1,1:Nat)
509 1 pfleura2
     y(1:Nat) = XyzGeomI(IGeom,2,1:Nat)
510 1 pfleura2
     z(1:Nat) = XyzGeomI(IGeom,3,1:Nat)
511 1 pfleura2
512 1 pfleura2
     SELECT CASE (COORD)
513 1 pfleura2
     CASE ('HYBRID')
514 1 pfleura2
        IndZmat0=IndZmat
515 1 pfleura2
        Call ConvXyzZmat(Nat,x,y,z,IndZmat,val_zmat(1,1))
516 1 pfleura2
     CASE ('ZMAT')
517 1 pfleura2
        IndZmat0=IndZmat
518 1 pfleura2
        val_zmat=0.d0
519 1 pfleura2
        val_zmat(2,1)=IntCoordI(1,1)
520 1 pfleura2
        val_zmat(3,1)=IntCoordI(1,2)
521 1 pfleura2
        val_zmat(3,2)=IntCoordI(1,3)*180./Pi
522 1 pfleura2
523 1 pfleura2
        Idx=4
524 1 pfleura2
        DO iat=4,Nat
525 1 pfleura2
           val_zmat(iat,1)=IntCoordI(1,idx)
526 1 pfleura2
           Idx=Idx+1
527 1 pfleura2
           do j=2,3
528 1 pfleura2
              val_zmat(iat,J)=IntCoordI(1,idx)*180./Pi
529 1 pfleura2
              Idx=Idx+1
530 1 pfleura2
           END DO
531 1 pfleura2
        END DO
532 1 pfleura2
533 1 pfleura2
     CASE ('MIXED')
534 1 pfleura2
        IndZmat0=IndZmat
535 1 pfleura2
        val_zmat=0.d0
536 1 pfleura2
        Idx=1
537 1 pfleura2
        DO I=1,NCart
538 1 pfleura2
           DO J=1,3
539 1 pfleura2
              val_zmat(i,j)= IntCoordI(1,Idx)
540 1 pfleura2
              Idx=Idx+1
541 1 pfleura2
           END DO
542 1 pfleura2
        END DO
543 1 pfleura2
        SELECT CASE (NCart)
544 1 pfleura2
        CASE(1)
545 1 pfleura2
           val_zmat(2,1)=IntCoordI(1,Idx)
546 1 pfleura2
           val_zmat(3,1)=IntCoordI(1,Idx+1)
547 1 pfleura2
           val_zmat(3,2)=IntCoordI(1,Idx+2)*180./Pi
548 1 pfleura2
           Idx=Idx+3
549 1 pfleura2
           IBeg=4
550 1 pfleura2
        CASE(2)
551 1 pfleura2
           val_zmat(3,1)=IntCoordI(1,Idx)
552 1 pfleura2
           val_zmat(3,2)=IntCoordI(1,Idx)*180./Pi
553 1 pfleura2
           Idx=Idx+2
554 1 pfleura2
           IBeg=4
555 1 pfleura2
        CASE DEFAULT
556 1 pfleura2
           IBeg=NCart+1
557 1 pfleura2
        END SELECT
558 1 pfleura2
559 1 pfleura2
        DO Iat=IBeg,Nat
560 1 pfleura2
           val_zmat(iat,1)=IntCoordI(1,idx)
561 1 pfleura2
           Idx=Idx+1
562 1 pfleura2
           do j=2,3
563 1 pfleura2
              val_zmat(iat,J)=IntCoordI(1,idx)*180./Pi
564 1 pfleura2
              Idx=Idx+1
565 1 pfleura2
           END DO
566 1 pfleura2
        END DO
567 1 pfleura2
     CASE ('BAKER')
568 1 pfleura2
        ! Nothing to be done here.
569 1 pfleura2
     CASE ('CART')
570 1 pfleura2
        ! Nothing to be done here.
571 1 pfleura2
     CASE DEFAULT
572 1 pfleura2
        WRITE(*,*) "Coord=",TRIM(COORD)," not recognized in PathCreate.L554.STOP"
573 1 pfleura2
        STOP
574 1 pfleura2
     END SELECT
575 1 pfleura2
     X0=x
576 1 pfleura2
     y0=y
577 1 pfleura2
     z0=z
578 1 pfleura2
  END IF  ! First
579 1 pfleura2
580 1 pfleura2
  ! Now that we have a zmat, we will generate all the IntCoodI corresponding...
581 1 pfleura2
  ! First one
582 1 pfleura2
  IF (COORD.EQ.'HYBRID') THEN     ! Matches at L680
583 1 pfleura2
     DO IGeom=1,NGeomI
584 1 pfleura2
        x(1:Nat) = XyzGeomI(IGeom,1,1:Nat)
585 1 pfleura2
        y(1:Nat) = XyzGeomI(IGeom,2,1:Nat)
586 1 pfleura2
        z(1:Nat) = XyzGeomI(IGeom,3,1:Nat)
587 1 pfleura2
588 1 pfleura2
        Call ConvXyzZmat(Nat,x,y,z,IndZmat0,val_zmatTmp(1,1))
589 1 pfleura2
        IntCoordI(IGeom,1)=val_zmatTmp(2,1)
590 1 pfleura2
        IntCoordI(IGeom,2)=val_zmatTmp(3,1)
591 1 pfleura2
        IntCoordI(IGeom,3)=val_zmatTmp(3,2)*Pi/180.
592 1 pfleura2
        Idx=4
593 1 pfleura2
        DO i=4,nat
594 1 pfleura2
           IntCoordI(IGeom,Idx)=val_zmatTmp(i,1)
595 1 pfleura2
           Idx=Idx+1
596 1 pfleura2
           IntCoordI(IGeom,Idx)=val_zmatTmp(i,2)*Pi/180.
597 1 pfleura2
           Idx=Idx+1
598 1 pfleura2
599 1 pfleura2
           ! Some tests to check that the dihedral angles are similar... this is
600 1 pfleura2
           ! important if they are close to Pi.
601 1 pfleura2
           Delta=0.
602 1 pfleura2
603 1 pfleura2
           if (abs(val_zmatTMP(i,3)-val_zmat(i,3))>=180.) THEN
604 1 pfleura2
              if ((val_zmatTMP(i,3)-val_zmat(i,3))<=-180.) THEN
605 1 pfleura2
                 Delta=-1.0d0*TwoPi
606 1 pfleura2
              ELSE
607 1 pfleura2
                 Delta=TwoPi
608 1 pfleura2
              END IF
609 1 pfleura2
              if (debug) THEN
610 1 pfleura2
                 WRITE(*,*) Nom(atome(i)), &
611 1 pfleura2
                      abs(val_zmatTMP(i,3)-val_zmat(i,3)), &
612 1 pfleura2
                      val_zmatTMP(i,3),val_zmat(i,3),Delta, &
613 1 pfleura2
                      val_zmatTMP(i,3)-Delta
614 1 pfleura2
              END IF
615 1 pfleura2
           END IF
616 1 pfleura2
           IntCoordI(IGeom,Idx)=(val_zmatTmp(i,3)-Delta)/180.*Pi
617 1 pfleura2
           Idx=Idx+1
618 1 pfleura2
        END DO
619 1 pfleura2
     END DO
620 1 pfleura2
  END IF ! Matches Coord=Hybrid
621 1 pfleura2
622 1 pfleura2
  ! PFL 24 Nov 2008 ->
623 1 pfleura2
  ! This should not be necessary...
624 1 pfleura2
  !   ! if we have frozen atoms, we make sure that they do not move between geometries
625 1 pfleura2
  !   IF (IntFroz.NE.0) THEN
626 1 pfleura2
  !      if (debug) WRITE(*,*) 'DBG PathCreate L641: Number of frozen coordinates=', IntFroz
627 1 pfleura2
  !      DO IGeom=2,NGeomI ! For IOpt .GT. 0, NGeomI is equal to NGeomF
628 1 pfleura2
  !         IntCoordI(IGeom,1:IntFroz)=IntCoordI(1,1:IntFroz)
629 1 pfleura2
  !      END DO
630 1 pfleura2
  !   END IF
631 1 pfleura2
  ! -> PFL 24 Nov 2008
632 1 pfleura2
633 1 pfleura2
  Idx=min(9,NCoord)
634 1 pfleura2
635 1 pfleura2
  IF (DEBUG.AND.(COORD.NE.'CART')) THEN
636 1 pfleura2
     WRITE(*,*) "DBG PathCreate. L685 IntCoordI(IGeom,:)"
637 1 pfleura2
     DO I=1,NGeomI
638 1 pfleura2
        WRITE(*,'("Geom:",I5,9(1X,F10.4))') I,IntCoordI(I,1:Idx)
639 1 pfleura2
     END DO
640 1 pfleura2
     ! We write it also in terms of Zmat
641 1 pfleura2
     IF ((COORD.EQ.'ZMAT').OR.(COORD.EQ.'HYBRID')) THEN
642 1 pfleura2
        DO I=1,NGeomI
643 1 pfleura2
           WRITE(*,*) 'Zmat for geom ',I,'/',NGeomI,'Xgeom=',Xgeom(I)
644 1 pfleura2
           WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(IndZmat0(1,1)))
645 1 pfleura2
           WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(IndZmat0(2,1))), &
646 1 pfleura2
                IndZmat(2,2),IntCoordI(I,1)
647 1 pfleura2
           WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(IndZmat0(3,1))), &
648 1 pfleura2
                IndZmat(3,2),IntCoordI(I,2),IndZmat(3,3),IntCoordI(I,3)*180./Pi
649 1 pfleura2
           Idx=4
650 1 pfleura2
           DO J=4,Nat
651 1 pfleura2
              WRITE(*,'(1X,A5,3(1X,I5,1X,F11.6))') Nom(Atome(IndZmat0(J,1))), &
652 1 pfleura2
                   IndZmat(J,2),IntCoordI(I,Idx),IndZmat(J,3),          &
653 1 pfleura2
                   IntCoordI(I,Idx+1)*180./Pi, &
654 1 pfleura2
                   IndZmat(J,4),IntCoordI(I,Idx+2)*180./Pi
655 1 pfleura2
              Idx=Idx+3
656 1 pfleura2
           END DO
657 1 pfleura2
658 1 pfleura2
           XyzTmp2=0.
659 1 pfleura2
           ! We convert it into Cartesian coordinates
660 1 pfleura2
           XyzTmp2(2,1)=IntCoordI(I,1)
661 1 pfleura2
           d=IntCoordI(I,2)
662 1 pfleura2
           a_val=IntCoordI(I,3)
663 1 pfleura2
           if (Nat.GE.3) THEN
664 1 pfleura2
              if (IndZmat(3,2).EQ.1)  THEN
665 1 pfleura2
                 XyzTmp2(3,1)=XYzTmp2(1,1)+d*cos(a_val)
666 1 pfleura2
              ELSE
667 1 pfleura2
                 XyzTmp2(3,1)=XyzTmp2(2,1)-d*cos(a_val)
668 1 pfleura2
              ENDIF
669 1 pfleura2
              XyzTmp2(3,2)=d*sin(a_val)
670 1 pfleura2
           ENDIF
671 1 pfleura2
672 1 pfleura2
           Idx=4
673 1 pfleura2
           DO iat=4,Nat
674 1 pfleura2
              val_zmatTMP(iat,1)=IntCoordI(I,idx)
675 1 pfleura2
              Idx=Idx+1
676 1 pfleura2
              DO j=2,3
677 1 pfleura2
                 val_zmatTMP(iat,J)=IntCoordI(I,idx)*180./Pi
678 1 pfleura2
                 Idx=Idx+1
679 1 pfleura2
              END DO
680 1 pfleura2
           END DO
681 1 pfleura2
           DO iat=4,Nat
682 1 pfleura2
              call ConvertZmat_cart(iat,IndZmat,val_zmatTMP, &
683 1 pfleura2
                   XYzTMP2(1,1), XYzTMP2(1,2),XYzTMP2(1,3))
684 1 pfleura2
           END DO
685 1 pfleura2
           DO Iat=1,nat
686 1 pfleura2
              WRITE(*,'(1X,A5,3(1X,F11.6))') Nom(Atome(IndZmat0(Iat,1))),&
687 1 pfleura2
                   XyzTmp2(iat,1:3)
688 1 pfleura2
           END DO
689 1 pfleura2
690 1 pfleura2
        END DO
691 1 pfleura2
     END IF
692 1 pfleura2
     IF (COORD.EQ.'MIXED') THEN
693 1 pfleura2
        DO I=1,NGeomI
694 1 pfleura2
           WRITE(*,*) 'Cart+Zmat for geom ',I,'/',NGeomI,'Xgeom=',Xgeom(I)
695 1 pfleura2
           Idx=1
696 1 pfleura2
           XyzTmp2=0.
697 1 pfleura2
           DO J=1,NCART
698 1 pfleura2
              WRITE(*,'(1X,A5,3(1X,F11.6))') Nom(Atome(IndZmat0(1,1))), &
699 1 pfleura2
                   IntCoordI(I,Idx:Idx+2)
700 1 pfleura2
              XyzTmp2(J,1:3)=IntCoordI(I,Idx:Idx+2)
701 1 pfleura2
              Idx=Idx+3
702 1 pfleura2
           END DO
703 1 pfleura2
           SELECT CASE (NCart)
704 1 pfleura2
           CASE (1)
705 1 pfleura2
              J=2
706 1 pfleura2
              WRITE(*,'(1X,A5,3(I5,F11.6))') Nom(Atome(IndZmat0(J,1))), &
707 1 pfleura2
                   IndZmat(J,2),IntCoordI(I,Idx)
708 1 pfleura2
              Idx=Idx+1
709 1 pfleura2
              J=3
710 1 pfleura2
              WRITE(*,'(1X,A5,3(I5,F11.6))') Nom(Atome(IndZmat0(J,1))), &
711 1 pfleura2
                   IndZmat(J,2),IntCoordI(I,Idx),IndZmat(J,3), &
712 1 pfleura2
                   IntCoordI(I,Idx+1)*180./Pi
713 1 pfleura2
              Idx=Idx+2
714 1 pfleura2
              Ibeg=4
715 1 pfleura2
           CASE (2)
716 1 pfleura2
              J=3
717 1 pfleura2
              WRITE(*,'(1X,A5,3(I5,F11.6))') Nom(Atome(IndZmat0(J,1))), &
718 1 pfleura2
                   IndZmat(J,2),IntCoordI(I,Idx),IndZmat(J,3), &
719 1 pfleura2
                   IntCoordI(I,Idx+1)*180./Pi
720 1 pfleura2
              Idx=Idx+2
721 1 pfleura2
              Ibeg=4
722 1 pfleura2
           CASE DEFAULT
723 1 pfleura2
              IBeg=NCart+1
724 1 pfleura2
           END SELECT
725 1 pfleura2
           DO J=IBeg,Nat
726 1 pfleura2
              IF (J.EQ.2) &
727 1 pfleura2
                   WRITE(*,'(1X,A5,3(I5,F11.6))') Nom(Atome(IndZmat0(J,1))), &
728 1 pfleura2
                   IndZmat(J,2),IntCoordI(I,Idx),IndZmat(J,3), &
729 1 pfleura2
                   IntCoordI(I,Idx+1)*180./Pi, &
730 1 pfleura2
                   IndZmat(J,4),IntCoordI(I,Idx+2)*180./Pi
731 1 pfleura2
              Idx=Idx+3
732 1 pfleura2
           END DO
733 1 pfleura2
734 1 pfleura2
           ! We convert it into Cartesian coordinates
735 1 pfleura2
           IntCoordTmp=IntCoordI(I,1:NCoord)
736 1 pfleura2
           Call Mixed2cart(Nat,IndZmat,IntCoordTmp,XyzTmp2)
737 1 pfleura2
738 1 pfleura2
           DO Iat=1,nat
739 1 pfleura2
              WRITE(*,'(1X,A5,3(1X,F11.6))') Nom(Atome(IndZmat0(Iat,1))),&
740 1 pfleura2
                   XyzTmp2(iat,1:3)
741 1 pfleura2
           END DO
742 1 pfleura2
743 1 pfleura2
        END DO
744 1 pfleura2
     END IF
745 1 pfleura2
  END IF ! matches IF (DEBUG.AND.(COORD.NE.'CART')) THEN
746 1 pfleura2
747 1 pfleura2
  if (debug) WRITE(*,*) "Before interpolation, PathCreate.f90, L740, IOpt=",IOpt, &
748 1 pfleura2
       "ISpline=", ISpline
749 1 pfleura2
  ! Now comes the Interpolation:
750 1 pfleura2
  IF ((NGeomI>2).AND.(IOpt.GE.ISpline)) THEN
751 1 pfleura2
     Linear=.FALSE.
752 1 pfleura2
     ! We have at least three geometries so we can apply cubic spline
753 1 pfleura2
     SELECT CASE (COORD)
754 1 pfleura2
     CASE ('ZMAT','HYBRID','MIXED')
755 1 pfleura2
        DO I=1,NCoord
756 1 pfleura2
           ! We compute the spline coefficients
757 1 pfleura2
           call spline(xGeom,IntCoordI(1,I),NGeomI,Inf,Inf, Coef(1,I))
758 1 pfleura2
           if (debug) THEN
759 1 pfleura2
              WRITE(*,*) 'Coef Spline for coord',I
760 1 pfleura2
              WRITE(*,*) Coef(1:NGeomI,I)
761 1 pfleura2
           END IF
762 1 pfleura2
        END DO
763 1 pfleura2
     CASE ('BAKER')
764 1 pfleura2
        ! We compute the spline coefficients
765 1 pfleura2
        ! xGeom(NGeomI), IntCoordI(NGeomI,3*Nat-6) declared in Path_module.f90
766 1 pfleura2
        ! can also be used for the Baker's internal coordinates.
767 1 pfleura2
        ! we need to get Baker's internal coordinates from cartesian coordinates.
768 1 pfleura2
        ! as we have subroutine ConvXyzmat(...) in Z matrix case.
769 1 pfleura2
        ! Coef(NGeomI,NCoord) or (NGeomI,N3at) has INTENT(OUT)
770 1 pfleura2
        DO I=1,NCoord ! NCoord=3*Nat-6-symmetry_eliminated.
771 1 pfleura2
           call spline(xGeom,IntCoordI(1,I),NGeomI,Inf,Inf,Coef(1,I))
772 1 pfleura2
           ! IF (debug) THEN
773 1 pfleura2
           !   WRITE(*,*) 'Coef Spline for coord',I
774 1 pfleura2
           !  WRITE(*,*) Coef(1:NGeomI,I)
775 1 pfleura2
           !    END IF
776 1 pfleura2
        END DO
777 1 pfleura2
     CASE ('CART')
778 1 pfleura2
779 1 pfleura2
!! PFL 2011 June 22 ->
780 1 pfleura2
!! The alignment procedure from Extrapol_cart has been moved
781 1 pfleura2
!! here, before computation of the spline coefficients
782 1 pfleura2
783 1 pfleura2
!  XyzTmp2=Reshape(XyzGeomI(1,:,:),(/Nat,3/),ORDER=(/2,1/))
784 1 pfleura2
785 1 pfleura2
  if (debug) THEN
786 1 pfleura2
     WRITE(*,*) "DBG PathCreate - Calc Spline coeff CART- Initial geometries"
787 1 pfleura2
     DO IGeom=1,NGeomI
788 1 pfleura2
        WRITE(*,*) 'XyzGeomI, IGeom=',IGeom
789 1 pfleura2
        DO I=1,Nat
790 1 pfleura2
           WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)),      &
791 1 pfleura2
                (XyzGeomI(IGeom,J,I),J=1,3)
792 1 pfleura2
        END DO
793 1 pfleura2
     END DO
794 1 pfleura2
  END IF
795 1 pfleura2
796 1 pfleura2
797 1 pfleura2
! In order to mesure only the relevant distance between two points
798 1 pfleura2
! we align all geometries on the original one
799 1 pfleura2
800 1 pfleura2
   DO IGeom=1,NGeomI
801 1 pfleura2
802 1 pfleura2
      XyzTmp2=Reshape(XyzGeomI(IGeom,:,:),(/Nat,3/),ORDER=(/2,1/))
803 1 pfleura2
  ! We align this geometry with the original one
804 1 pfleura2
  ! PFL 17/July/2006: only if we have more than 4 atoms.
805 1 pfleura2
!  IF (Nat.GT.4) THEN
806 1 pfleura2
! PFL 24 Nov 2008 ->
807 1 pfleura2
! If we have frozen atoms we align only those ones.
808 1 pfleura2
! PFL 8 Feb 2011 ->
809 1 pfleura2
! I add a flag to see if we should align or not.
810 1 pfleura2
! For small systems, it might be better to let the user align himself
811 1 pfleura2
      IF (Align) THEN
812 1 pfleura2
         if (NFroz.GT.0) THEN
813 1 pfleura2
            Call AlignPartial(Nat,x0,y0,z0,                     &
814 1 pfleura2
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
815 1 pfleura2
                 FrozAtoms,MRot)
816 1 pfleura2
         ELSE
817 1 pfleura2
            Call  CalcRmsd(Nat, x0,y0,z0,                              &
818 1 pfleura2
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
819 1 pfleura2
                 MRot,rmsd,.TRUE.,.TRUE.)
820 1 pfleura2
         END IF
821 1 pfleura2
! <- PFL 24 Nov 2008
822 1 pfleura2
      END IF
823 1 pfleura2
! -> PFL 8 Feb 2011
824 1 pfleura2
!  END IF
825 1 pfleura2
826 1 pfleura2
  XyzGeomI(IGeom,:,:)=Reshape(XyzTmp2(:,:),(/3,Nat/),ORDER=(/2,1/))
827 1 pfleura2
 END DO
828 1 pfleura2
829 1 pfleura2
   if (debug) THEN
830 1 pfleura2
     WRITE(*,*) "DBG PathCreate - Calc Spline coeff CART- Aligned geometries"
831 1 pfleura2
      DO J=1, NGeomI
832 1 pfleura2
         WRITE(IOOUT,*) Nat
833 1 pfleura2
         WRITE(IOOUT,*) " Aligned geometry ",J,"/",NGeomI
834 1 pfleura2
           DO i=1,Nat
835 1 pfleura2
              WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)),    &
836 1 pfleura2
                   XyzGeomI(J,1:3,I)
837 1 pfleura2
           END DO
838 1 pfleura2
        END DO
839 1 pfleura2
     END IF
840 1 pfleura2
841 1 pfleura2
!! <- PFL 2011 June 22
842 1 pfleura2
843 1 pfleura2
        DO I=1,Nat
844 1 pfleura2
           ! We compute the spline coefficients
845 1 pfleura2
           call spline(xGeom,XyzGeomI(1,1,I),NGeomI,Inf,Inf, Coef(1,3*I-2))
846 1 pfleura2
           call spline(xGeom,XyzGeomI(1,2,I),NGeomI,Inf,Inf, Coef(1,3*I-1))
847 1 pfleura2
           call spline(xGeom,XyzGeomI(1,3,I),NGeomI,Inf,Inf, Coef(1,3*I))
848 1 pfleura2
           if (debug) THEN
849 1 pfleura2
              WRITE(*,*) 'Coef Spline for coord',i
850 1 pfleura2
              WRITE(*,*) Coef(1:NGeomI,I)
851 1 pfleura2
           END IF
852 1 pfleura2
        END DO
853 1 pfleura2
     CASE DEFAULT
854 1 pfleura2
        WRITE(*,*) "Coord=",TRIM(COORD)," not recognized in PathCreate.L783.STOP"
855 1 pfleura2
        STOP
856 1 pfleura2
     END SELECT
857 1 pfleura2
  ELSE ! matches IF ((NGeomI>2).AND.(Iopt.Ge.ISpline)) THEN
858 1 pfleura2
     ! On n'a que deux images. On fera une interpolation lineaire,
859 1 pfleura2
     ! qui est un cas particulier avec Coef=0
860 1 pfleura2
     if (debug.AND.(NGeomI.EQ.2)) WRITE(*,*) "DBG : Only 2 starting geometries"
861 1 pfleura2
     if (debug.AND.(Iopt.LE.ISpline)) WRITE(*,*) "DBG : Not enough path -> linear int"
862 1 pfleura2
     Coef=0.d0
863 1 pfleura2
     Linear=.TRUE.
864 1 pfleura2
  END IF ! matches IF ((NGeomI>2).AND.(Iopt.Ge.ISpline)) THEN
865 1 pfleura2
  ! Shall we redistribute the points along the path ?
866 1 pfleura2
  if (debug) WRITE(*,*) "PathCreate.f90, L795, IOpt=", IOpt, "IReparam=", IReparam
867 1 pfleura2
868 1 pfleura2
  IF (MOD(IOpt,IReparam).EQ.0) THEN
869 1 pfleura2
     ! We generate the Path, in two steps:
870 1 pfleura2
     ! i) we calculate the length of the mass weighted (MW) path
871 1 pfleura2
     ! ii) we sample the path to get the geometries
872 1 pfleura2
873 1 pfleura2
     NGeomS=NGeomI
874 1 pfleura2
     SELECT CASE (COORD)
875 1 pfleura2
     CASE ('ZMAT','HYBRID')
876 1 pfleura2
        ! We call the extrapolation once to get the path length
877 1 pfleura2
        dist=Inf
878 1 pfleura2
        Call ExtraPol_int(IOpt,s,dist,x0,y0,z0,xgeom,Coef,XgeomF)
879 1 pfleura2
        ! we have the length, we calculate the distance between two points
880 1 pfleura2
881 1 pfleura2
        if (s.LE.1e-6) THEN
882 1 pfleura2
           IF (OptGeom.LE.0) THEN
883 1 pfleura2
              WRITE(*,*) "Length of the path is 0 and you are not doing Geometry Optimization."
884 1 pfleura2
              WRITE(*,*) "ERROR !!! Stop !"
885 1 pfleura2
              STOP
886 1 pfleura2
           END IF
887 1 pfleura2
        ELSE
888 1 pfleura2
           ! we have the length, we calculate the distance between two points
889 1 pfleura2
           dist=s/Real(NGeomf-1)
890 1 pfleura2
           if (debug) WRITE(*,*) 'Dbg PathCreate ZMAT s, dist:',s,dist
891 1 pfleura2
           ! we call it again to obtain the geometries !
892 1 pfleura2
           Call ExtraPol_int(iopt,s,dist,x0,y0,z0,xgeom,Coef,XgeomF)
893 1 pfleura2
        END IF
894 1 pfleura2
     CASE ('BAKER')
895 1 pfleura2
        ! We generate the Path, in two steps:
896 1 pfleura2
        ! i) we calculate the length of the mass weighted (MW) path
897 1 pfleura2
        ! ii) we sample the path to get the geometries
898 1 pfleura2
899 1 pfleura2
        ! We call the extrapolation first time to get the path length
900 1 pfleura2
        ! iopt: Number of the cycles for the optimization.
901 1 pfleura2
        ! s: a real number and has INTENT(OUT), probably returns the
902 1 pfleura2
        ! length of the path.
903 1 pfleura2
        ! dist=Inf=> ExtraPol_baker has to calculate the length of the path.
904 1 pfleura2
        ! X0(Nat),Y0(Nat),Z0(Nat): reference geometry.
905 1 pfleura2
        ! Xgeom: Xgeom(NGeomI) has INTENT(IN)
906 1 pfleura2
        ! Coef(NGeomI,NCoord) is obtained from spline interpolation subroutine.
907 1 pfleura2
        ! XgeomF: XGeomF(NGeomF) has INTENT(OUT)
908 1 pfleura2
        ! Which reference coordinate geometry X0, Y0, Z0 to use???
909 1 pfleura2
        dist=Inf
910 1 pfleura2
        !if (debug) WRITE(*,*) "Before the call of ExtraPol_baker in redistribution &
911 1 pfleura2
        !of the points, in PathCreate.f90, L836"
912 1 pfleura2
        !Print *, 'Before ExtraPol_baker, PathCreate.90, L848, IntCoordI='
913 1 pfleura2
        !Print *, IntCoordI
914 1 pfleura2
        Call ExtraPol_baker(s,dist,x0,y0,z0,xgeom,Coef,XgeomF)
915 1 pfleura2
        !Print *, 'After ExtraPol_baker, PathCreate.90, L848, IntCoordI='
916 1 pfleura2
        !Print *, IntCoordI
917 1 pfleura2
        !if (debug) WRITE(*,*) "After the call of ExtraPol_baker in the redistribution &
918 1 pfleura2
        ! of the points, in PathCreate.f90, L843"
919 1 pfleura2
920 1 pfleura2
        ! we have the lenght, we calculate the distance between two points
921 1 pfleura2
        !Print *, 'After first call of ExtraPol_baker in PathCreate.f90, s=', s
922 1 pfleura2
923 1 pfleura2
        if (s.LE.1e-6) THEN
924 1 pfleura2
           IF (OptGeom.LE.0) THEN
925 1 pfleura2
              WRITE(*,*) "Length of the path is 0 and you are not doing Geometry Optimization."
926 1 pfleura2
              WRITE(*,*) "ERROR !!! Stop !"
927 1 pfleura2
              STOP
928 1 pfleura2
           END IF
929 1 pfleura2
        ELSE
930 1 pfleura2
931 1 pfleura2
           dist=s/Real(NGeomf-1)
932 1 pfleura2
           !if (debug) WRITE(*,*) 'Dbg PathCreate ZMAT s, dist:',s,dist
933 1 pfleura2
934 1 pfleura2
           ! we call it again to obtain the geometries !
935 1 pfleura2
           Call ExtraPol_baker(s,dist,x0,y0,z0,xgeom,Coef,XgeomF)
936 1 pfleura2
           WRITE(*,*) "At the end of Baker case in the redistribution of the points, in PathCreate.f90, L966"
937 1 pfleura2
        END IF
938 1 pfleura2
939 1 pfleura2
        DO IGeom=1,NGeomF
940 1 pfleura2
           WRITE(*,*) "UMatF for IGeom=",IGeom
941 1 pfleura2
           DO I=1,3*Nat-6
942 1 pfleura2
              WRITE(*,'(50(1X,F12.8))') UMatF(IGeom,:,I)
943 1 pfleura2
           END DO
944 1 pfleura2
        END DO
945 1 pfleura2
946 1 pfleura2
     CASE ('MIXED')
947 1 pfleura2
        !           WRITE(*,*) "IOIOIOIOIOIOIOI"
948 1 pfleura2
        ! We call the extrapolation once to get the path length
949 1 pfleura2
        Dist=Inf
950 1 pfleura2
        Call ExtraPol_Mixed(s,dist,x0,y0,z0,xgeom,Coef)
951 1 pfleura2
952 1 pfleura2
        if (s.LE.1e-6) THEN
953 1 pfleura2
           IF (OptGeom.LE.0) THEN
954 1 pfleura2
              WRITE(*,*) "Length of the path is 0 and you are not doing Geometry Optimization."
955 1 pfleura2
              WRITE(*,*) "ERROR !!! Stop !"
956 1 pfleura2
              STOP
957 1 pfleura2
           END IF
958 1 pfleura2
        ELSE
959 1 pfleura2
960 1 pfleura2
           ! we have the length, we calculate the distance between two points
961 1 pfleura2
           dist=s/Real(NGeomf-1)
962 1 pfleura2
           if (debug) WRITE(*,*) 'Dbg PathCreate Mixed s, dist:',s,dist
963 1 pfleura2
964 1 pfleura2
           ! we call it again to obtain the geometries !
965 1 pfleura2
           Call ExtraPol_Mixed(s,dist,x0,y0,z0,xgeom,Coef)
966 1 pfleura2
967 1 pfleura2
           IF (debug) THEN
968 1 pfleura2
              DO I=1,NGeomF
969 1 pfleura2
                 WRITE(*,'(1X,A,12(1X,F10.5))') "IntTangent:",IntTangent(I,1:NCoord)
970 1 pfleura2
              END DO
971 1 pfleura2
           END IF
972 1 pfleura2
        END IF
973 1 pfleura2
     CASE ('CART')
974 1 pfleura2
        ! We call the extrapolation once to get the path length
975 1 pfleura2
        Dist=Inf
976 1 pfleura2
        Call ExtraPol_cart(iopt,s,dist,x0,y0,z0,xgeom,Coef)
977 1 pfleura2
978 1 pfleura2
        if (s.LE.1e-6) THEN
979 1 pfleura2
           IF (OptGeom.LE.0) THEN
980 1 pfleura2
              WRITE(*,*) "Length of the path is 0 and you are not doing Geometry Optimization."
981 1 pfleura2
              WRITE(*,*) "ERROR !!! Stop !"
982 1 pfleura2
              STOP
983 1 pfleura2
           END IF
984 1 pfleura2
        ELSE
985 1 pfleura2
           ! we have the lenght, we calculate the distance between two points
986 1 pfleura2
           dist=s/Real(NGeomf-1)
987 1 pfleura2
           if (debug) WRITE(*,*) 'Debug s, dist:',s,dist
988 1 pfleura2
989 1 pfleura2
           ! we call it again to obtain the geometries !
990 1 pfleura2
           Call ExtraPol_cart(iopt,s,dist,x0,y0,z0,xgeom,Coef)
991 1 pfleura2
        END IF
992 1 pfleura2
     END SELECT
993 1 pfleura2
  ELSE
994 1 pfleura2
     ! PFL 3 Jan 2008 ->
995 1 pfleura2
     ! Tangents are not recalculated if the points are not reparameterized
996 1 pfleura2
     ! PFL 6 Apr 2008 ->
997 1 pfleura2
     ! Unless user has asked to reparameterized them !
998 1 pfleura2
     IF (mod(Iopt,iReparamT).EQ.0) THEN
999 1 pfleura2
        XGeomF=XGeom
1000 1 pfleura2
        NGeomS=NGeomI
1001 1 pfleura2
        Call CalcTangent(XgeomF,NGeomS,xgeom,Coef)
1002 1 pfleura2
        !
1003 1 pfleura2
     END IF
1004 1 pfleura2
     ! <- PFL 3 Jan 2008 / 6 Apr 2008
1005 1 pfleura2
  END IF ! if (mod(Iop,iReparam).EQ.0)
1006 1 pfleura2
  if (debug) WRITE(*,*) "PathCreate.f90, L885"
1007 1 pfleura2
1008 1 pfleura2
  ! PFL 22.Nov.2007 ->
1009 1 pfleura2
  ! We do not write tangents for baker coordinates because they are hard to
1010 1 pfleura2
  ! interpret for a chemist.
1011 1 pfleura2
1012 1 pfleura2
  IF (debug.AND.(COORD.NE."BAKER")) THEN
1013 1 pfleura2
     ! we write the tangents :-)
1014 1 pfleura2
     DO I=1,NGeomF
1015 1 pfleura2
        SELECT CASE(Coord)
1016 1 pfleura2
        CASE ('ZMAT','MIXED')
1017 1 pfleura2
           IntCoordTmp=IntTangent(I,:)
1018 1 pfleura2
           WRITE(*,'(1X,A,12(1X,F10.5))') "IntCoordTmp:",IntCoordTmp(1:NCoord)
1019 1 pfleura2
           WRITE(*,'(1X,A,12(1X,F10.5))') "IntTangent:",IntTangent(I,1:NCoord)
1020 1 pfleura2
        CASE ('CART','HYBRID')
1021 1 pfleura2
           IntCoordTmp=XyzTangent(I,:)
1022 1 pfleura2
        CASE DEFAULT
1023 1 pfleura2
           WRITE(*,*) "Coord=",TRIM(COORD)," not recognized in PathCreate. STOP"
1024 1 pfleura2
           STOP
1025 1 pfleura2
        END SELECT
1026 1 pfleura2
        WRITE(Title,"('Tangents for geometry ',I3,'/',I3,' for iteration ',I3)") I,NgeomF
1027 1 pfleura2
        Call PrintGeom(Title,Nat,Ncoord,IntCoordTmp,Coord,6,Atome,Order,OrderInv,IndZmat)
1028 1 pfleura2
     END DO
1029 1 pfleura2
  END IF
1030 1 pfleura2
1031 1 pfleura2
1032 1 pfleura2
  IF (DEBUG.AND.(COORD.NE.'CART')) THEN
1033 1 pfleura2
     Idx=min(12,NCoord)
1034 1 pfleura2
     WRITE(*,*) "DBG PathCreate. IntCoordF(IGeom,:)"
1035 1 pfleura2
     DO I=1,NGeomF
1036 1 pfleura2
        WRITE(*,'("Geom:",I5,12(1X,F10.4))') I,IntCoordF(I,1:Idx)
1037 1 pfleura2
     END DO
1038 1 pfleura2
  END IF
1039 1 pfleura2
1040 1 pfleura2
  DEALLOCATE(Coef,val_zmat,val_zmatTMP)
1041 1 pfleura2
  DEALLOCATE(X0,Y0,Z0,Indzmat0)
1042 1 pfleura2
  DEALLOCATE(X,Y,Z,Xgeom,XgeomF)
1043 1 pfleura2
  DEALLOCATE(XyzTmp,XyzTmp2)
1044 1 pfleura2
1045 1 pfleura2
  if (debug) Call header("PathCreate over")
1046 1 pfleura2
1047 1 pfleura2
END SUBROUTINE PathCreate