Statistiques
| Révision :

root / src / Extrapol_cart.f90 @ 3

Historique | Voir | Annoter | Télécharger (10,24 ko)

1
SUBROUTINE Extrapol_cart(iopt,s,dist,x0,y0,z0,xgeom,Coef)
2

    
3
  ! This subroutine constructs the path, and if dist<>Infinity, it samples
4
  ! the path to obtain geometries.
5
  ! Basically, you call it twice: i) dist=infinity, it will calculate the length of the path
6
  ! ii) dist finite, it will give you the images you want along the path.
7
  !
8
  ! For now, it gives equidistant geometries
9
  !
10

    
11
  use Path_module
12
  use Io_module
13

    
14

    
15
  IMPLICIT NONE
16

    
17

    
18
  REAL(KREAL), INTENT(OUT) :: s
19
  ! X0(Nat),Y0(Nat),Z0(Nat): reference geometry.
20
  REAL(KREAL), INTENT(IN) :: dist,X0(Nat),Y0(Nat),Z0(Nat)
21
  REAL(KREAL), INTENT(IN) :: Xgeom(NGeomI),Coef(NGeomI,NCoord)
22
! Iopt: Number of the cycles for the optimization
23
  INTEGER(KINT), INTENT(IN) :: Iopt
24
  INTEGER(KINT) :: IdxGeom, I, J, K, Iat
25
! NSpline is the number of points along the interpolating path
26
  INTEGER(KINT) :: NSpline
27
! FileSpline: Filename to save the interpolating path coordinates
28
  CHARACTER(LCHARS) :: FileSpline,TmpChar
29
  REAL(KREAL) :: Rmsd, MRot(3, 3), ds, u
30

    
31
  REAL(KREAL), ALLOCATABLE :: XyzTmp(:,:), XyzTmp2(:,:) ! (Nat,3)
32
  REAL(KREAL), ALLOCATABLE :: DerXyz(:,:) ! Nat,3
33

    
34

    
35
  LOGICAL ::  debug, print, printspline
36
  LOGICAL, EXTERNAL :: valid
37

    
38
  !We will calculate the length of the path, in MW coordinates...
39
  ! this is done is a stupid way: we interpolate the zmatrix values,
40
  ! convert them into cartesian, weight the cartesian
41
  ! and calculate the evolution of the distance ! 
42
  ! We have to follow the same procedure for every geometry
43
  ! so even for the first one, we have to convert it from zmat
44
  ! to cartesian !
45

    
46
  debug=valid("pathcreate")
47
  print=valid("printgeom")
48

    
49
  printspline=(valid("printspline").AND.(dist<=1e30))
50

    
51
  if (debug) Call Header("Entering Extrapol_cart")
52

    
53
! We want 100 points along the interpolating path
54
  NSpline=int(NMaxPtPath/100)
55

    
56
  if (printspline) THEN
57
     WRITE(TmpChar,'(I5)') Iopt
58
     FileSpline=Trim(adjustL(PathName)) // '_spline.' // AdjustL(TRIM(TmpChar))
59
     OPEN(IOTMP,FILE=FileSpline)
60

    
61
  END IF
62

    
63

    
64
  ALLOCATE(XyzTmp(Nat,3),XyzTmp2(Nat,3),DerXyz(Nat,3))
65

    
66
! PFL 2011 June 22
67
! There was an alignment procedure there.
68
! It has been moved to PathCreate before the 
69
! computation of the Spline coefficient.
70

    
71
  XyzGeomF(1,:,:)=XyzGeomI(1,:,:)
72

    
73

    
74
  ! We initialize the first geometry
75

    
76
  XyzTmp=Reshape(XyzGeomI(1,:,:),(/Nat,3/),ORDER=(/2,1/))
77

    
78

    
79

    
80
  s=0.d0
81
  SGeom(1)=0.d0
82

    
83
  if (printspline) THEN
84
     u=0.d0
85
     DO Iat=1,Nat
86
        ! We generate the interpolated coordinates
87
        if (Linear) THEN
88
           call LinearInt(u,XyzTmp2(Iat,1),DerXyz(Iat,1),NGeomI,xgeom(1),XyzGeomI(1,1,Iat))
89
           call LinearInt(u,XyzTmp2(Iat,2),DerXyz(Iat,2),NGeomI,xgeom(1),XyzGeomI(1,2,Iat))
90
           call LinearInt(u,XyzTmp2(Iat,3),DerXyz(Iat,3),NGeomI,xgeom(1),XyzGeomI(1,3,Iat))
91

    
92
        ELSE
93
           call splintder(u,XyzTmp2(Iat,1),DerXyz(Iat,1),NGeomI,xgeom(1),XyzGeomI(1,1,Iat),Coef(1,3*Iat-2))
94
           call splintder(u,XyzTmp2(Iat,2),DerXyz(Iat,2),NGeomI,xgeom(1),XyzGeomI(1,2,Iat),Coef(1,3*Iat-1))
95
           call splintder(u,XyzTmp2(Iat,3),DerXyz(Iat,3),NGeomI,xgeom(1),XyzGeomI(1,3,Iat),Coef(1,3*Iat))
96
        END IF
97
     END DO
98

    
99
     WRITE(IOTMP,*) Nat
100
     WRITE(IOTMP,'(1X,A,1X,F15.6)') "Debug Spline - Coord=Cart,s=",s
101
     DO Iat=1,Nat
102
        WRITE(IOTMP,'(1X,A2,3(1X,F15.6))') Nom(Atome(Iat)),    &
103
                   (XyzTmp2(Iat,1:3))
104
     END DO
105
  END IF
106

    
107
 IdxGeom=1
108

    
109
  DO K=1,NMaxPtPath
110
     u=real(K)/NMaxPtPath*(NGeomI-1.)
111

    
112
     DO Iat=1,Nat
113
        ! We generate the interpolated coordinates
114
        if (Linear) THEN
115
           call LinearInt(u,XyzTmp2(Iat,1),DerXyz(Iat,1),NGeomI,xgeom(1),XyzGeomI(1,1,Iat))
116
           call LinearInt(u,XyzTmp2(Iat,2),DerXyz(Iat,2),NGeomI,xgeom(1),XyzGeomI(1,2,Iat))
117
           call LinearInt(u,XyzTmp2(Iat,3),DerXyz(Iat,3),NGeomI,xgeom(1),XyzGeomI(1,3,Iat))
118

    
119
        ELSE
120
           call splintder(u,XyzTmp2(Iat,1),DerXyz(Iat,1),NGeomI,xgeom(1),XyzGeomI(1,1,Iat),Coef(1,3*Iat-2))
121
           call splintder(u,XyzTmp2(Iat,2),DerXyz(Iat,2),NGeomI,xgeom(1),XyzGeomI(1,2,Iat),Coef(1,3*Iat-1))
122
           call splintder(u,XyzTmp2(Iat,3),DerXyz(Iat,3),NGeomI,xgeom(1),XyzGeomI(1,3,Iat),Coef(1,3*Iat))
123
        END IF
124
     END DO
125

    
126

    
127
! PFL 2011 June 22: We now align on the previous one
128
! as we do for internal coord interpolation
129

    
130
! We align this geometry with the previous one
131

    
132
  ! PFL 17/July/2006: only if we have more than 4 atoms.
133
!  IF (Nat.GT.4) THEN
134
! PFL 24 Nov 2008 ->
135
! If we have frozen atoms we align only those ones.
136
! PFL 8 Feb 2011 ->
137
! I add a flag to see if we should align or not.
138
! For small systems, it might be better to let the user align himself
139
      IF (Align) THEN
140
         if (NFroz.GT.0) THEN
141
            Call AlignPartial(Nat,                     &
142
                 xyzTmp(1,1),xyzTmp(1,2),xyzTMP(1,3),       &
143
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
144
                 FrozAtoms,MRot)
145
         ELSE
146
            Call  CalcRmsd(Nat,                              &
147
                 xyzTmp(1,1),xyzTmp(1,2),xyzTMP(1,3),       &
148
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
149
                 MRot,rmsd,.TRUE.,.TRUE.)
150
         END IF
151
! <- PFL 24 Nov 2008
152
      END IF
153
! -> PFL 8 Feb 2011
154
!  END IF
155

    
156

    
157

    
158
     ds=0.
159
     DO I=1,Nat
160
        DO J=1,3
161
           ds=ds+MassAt(I)*(XYZTMp2(I,J)-XYZTmp(I,J))**2
162
           XYZTmp(I,J)=XyzTMP2(I,J)
163
        ENDDO
164
     ENDDO
165
     s=s+sqrt(ds)
166

    
167
     !         if (debug) WRITE(*,*) "Debug u,s,dist",u,s,dist
168

    
169
  if ((printspline).AND.(MOD(K,NSpline).EQ.0)) THEN
170
     WRITE(IOTMP,*) Nat
171
     WRITE(IOTMP,'(1X,A,1X,F15.6)') "Debug Spline - Coord=Cart,s=",s
172
     DO Iat=1,Nat
173
        WRITE(IOTMP,'(1X,A2,3(1X,F15.6))') Nom(Atome(Iat)),    &
174
                   (XyzTmp2(Iat,1:3))
175
     END DO
176
  END IF
177

    
178

    
179
     if (s>=dist) THEN
180

    
181
        if (debug) THEN
182
           WRITE(*,*) "DBG Interpol_cart",s
183
           DO i=1,Nat
184
              WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)),    &
185
                   (XyzTmp2(I,J),J=1,3)
186
           END DO
187
        END IF
188

    
189
        s=s-dist
190
        IdxGeom=IdxGeom+1
191
        SGeom(IdxGeom)=s+dist*(IdxGeom-1)
192

    
193
  ! We align this geometry with the original one
194
  ! PFL 17/July/2006: only if we have more than 4 atoms.
195
!  IF (Nat.GT.4) THEN
196
! PFL 24 Nov 2008 ->
197
! If we have frozen atoms we align only those ones.
198
! PFL 8 Feb 2011 ->
199
! I add a flag to see if we should align or not.
200
! For small systems, it might be better to let the user align himself
201
      IF (Align) THEN
202
         if (NFroz.GT.0) THEN
203
            Call AlignPartial(Nat,x0,y0,z0,                     &
204
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
205
                 FrozAtoms,MRot)
206
         ELSE
207
            Call  CalcRmsd(Nat, x0,y0,z0,                              &
208
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
209
                 MRot,rmsd,.TRUE.,.TRUE.)
210
         END IF
211
! <- PFL 24 Nov 2008
212
      END IF
213
! -> PFL 8 Feb 2011
214
!  END IF
215

    
216
        XyzGeomF(IdxGeom,:,:)=Reshape(XyzTmp2(:,:),(/3,Nat/),ORDER=(/2,1/))
217
        XyzTangent(IdxGeom,:)=Reshape(DerXyz(:,:),(/3*Nat/))
218

    
219
        if (print) THEN
220
           WRITE(IOOUT,'(1X,I5)') Nat
221
           WRITE(IOOUT,*) "# Cartesian coord for Geometry ",IdxGeom,K
222

    
223
           DO i=1,Nat
224
              WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)),    &
225
                   (XyzTmp2(I,J),J=1,3)
226
           END DO
227

    
228
        END IF
229
     END IF  ! s>= dist
230
  ENDDO  ! K
231

    
232

    
233
  if (s>=0.9*dist) THEN
234
     s=s-dist
235
     XyzTmp2=Reshape(XyzGeomI(NGeomI,:,:),(/Nat,3/),ORDER=(/2,1/))
236

    
237
  if (printspline) THEN
238
     WRITE(IOTMP,*) Nat
239
     WRITE(IOTMP,*) "Debug Spline - Coord=Cart,s=",s
240
     DO Iat=1,Nat
241
        WRITE(IOTMP,'(1X,A2,3(1X,F15.6))') Nom(Atome(Iat)),    &
242
                   (XyzTmp2(Iat,1:3))
243
     END DO
244
  END IF
245

    
246

    
247
  ! We align this geometry with the original one
248
  ! PFL 17/July/2006: only if we have more than 4 atoms.
249
!  IF (Nat.GT.4) THEN
250
! PFL 24 Nov 2008 ->
251
! If we have frozen atoms we align only those ones.
252
! PFL 8 Feb 2011 ->
253
! I add a flag to see if we should align or not.
254
! For small systems, it might be better to let the user align himself
255
      IF (Align) THEN
256
         if (NFroz.GT.0) THEN
257
            Call AlignPartial(Nat,x0,y0,z0,                     &
258
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
259
                 FrozAtoms,MRot)
260
         ELSE
261
            Call  CalcRmsd(Nat, x0,y0,z0,                              &
262
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
263
                 MRot,rmsd,.TRUE.,.TRUE.)
264
         END IF
265
! <- PFL 24 Nov 2008
266
      END IF
267
! -> PFL 8 Feb 2011
268
!  END IF
269

    
270
     IdxGeom=IdxGeom+1
271
     SGeom(IdxGeom)=s+dist*(IdxGeom-1)
272

    
273
    IF (IdxGeom.GT.NGeomF) THEN
274
        WRITE(IOOUT,*) "!!! ERROR in Extrapol_cart !!!!"
275
        WRITE(IOOUT,*) "Too many structures. Increase NMaxPath"
276
        WRITE(*,*) "** PathCreate ***"
277
        WRITE(*,*) "Distribution of points along the path is wrong."
278
        WRITE(*,*) "Increase value of NMaxPtPath in the input file"
279
        WRITE(*,*) "Present value is:", NMaxPtPath
280
        STOP
281
     END IF
282

    
283

    
284
  ! We align this geometry with the original one
285
  ! PFL 17/July/2006: only if we have more than 4 atoms.
286
!  IF (Nat.GT.4) THEN
287
! PFL 24 Nov 2008 ->
288
! If we have frozen atoms we align only those ones.
289
! PFL 8 Feb 2011 ->
290
! I add a flag to see if we should align or not.
291
! For small systems, it might be better to let the user align himself
292
      IF (Align) THEN
293
         if (NFroz.GT.0) THEN
294
            Call AlignPartial(Nat,x0,y0,z0,                     &
295
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
296
                 FrozAtoms,MRot)
297
         ELSE
298
            Call  CalcRmsd(Nat, x0,y0,z0,                              &
299
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
300
                 MRot,rmsd,.TRUE.,.TRUE.)
301
         END IF
302
! <- PFL 24 Nov 2008
303
      END IF
304
! -> PFL 8 Feb 2011
305
!  END IF
306

    
307
     XyzGeomF(IdxGeom,:,:)=Reshape(XyzTmp2(:,:),(/3,Nat/),ORDER=(/2,1/))
308
     XyzTangent(IdxGeom,:)=Reshape(DerXyz(:,:),(/3*Nat/))
309

    
310
     if (print) THEN
311
        WRITE(IOOUT,'(1X,I5)') Nat
312
        WRITE(IOOUT,*) "# Cartesian coord for Geometry ",IdxGeom,K
313

    
314
        DO i=1,Nat
315
           WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)),     &
316
                (XyzTmp2(I,J),J=1,3)
317
        END DO
318
     END IF
319
  END IF
320

    
321
  DEALLOCATE(XyzTmp,XyzTmp2)
322

    
323
  if (debug) WRITE(*,*) 's final =',s
324

    
325
  if (printspline) CLOSE(IOTMP)
326

    
327
  if (debug) Call Header("Extrapol_cart over")
328

    
329
END SUBROUTINE EXTRAPOL_CART