Statistiques
| Révision :

root / src / Extrapol_cart.f90 @ 2

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

1 1 pfleura2
SUBROUTINE Extrapol_cart(iopt,s,dist,x0,y0,z0,xgeom,Coef)
2 1 pfleura2
3 1 pfleura2
  ! This subroutine constructs the path, and if dist<>Infinity, it samples
4 1 pfleura2
  ! the path to obtain geometries.
5 1 pfleura2
  ! Basically, you call it twice: i) dist=infinity, it will calculate the length of the path
6 1 pfleura2
  ! ii) dist finite, it will give you the images you want along the path.
7 1 pfleura2
  !
8 1 pfleura2
  ! For now, it gives equidistant geometries
9 1 pfleura2
  !
10 1 pfleura2
11 1 pfleura2
  use Path_module
12 1 pfleura2
  use Io_module
13 1 pfleura2
14 1 pfleura2
15 1 pfleura2
  IMPLICIT NONE
16 1 pfleura2
17 1 pfleura2
18 1 pfleura2
  REAL(KREAL), INTENT(OUT) :: s
19 1 pfleura2
  ! X0(Nat),Y0(Nat),Z0(Nat): reference geometry.
20 1 pfleura2
  REAL(KREAL), INTENT(IN) :: dist,X0(Nat),Y0(Nat),Z0(Nat)
21 1 pfleura2
  REAL(KREAL), INTENT(IN) :: Xgeom(NGeomI),Coef(NGeomI,NCoord)
22 1 pfleura2
! Iopt: Number of the cycles for the optimization
23 1 pfleura2
  INTEGER(KINT), INTENT(IN) :: Iopt
24 2 pfleura2
  INTEGER(KINT) :: IdxGeom, I, J, K, Iat
25 1 pfleura2
! NSpline is the number of points along the interpolating path
26 1 pfleura2
  INTEGER(KINT) :: NSpline
27 1 pfleura2
! FileSpline: Filename to save the interpolating path coordinates
28 1 pfleura2
  CHARACTER(LCHARS) :: FileSpline,TmpChar
29 2 pfleura2
  REAL(KREAL) :: Rmsd, MRot(3, 3), ds, u
30 1 pfleura2
31 1 pfleura2
  REAL(KREAL), ALLOCATABLE :: XyzTmp(:,:), XyzTmp2(:,:) ! (Nat,3)
32 1 pfleura2
  REAL(KREAL), ALLOCATABLE :: DerXyz(:,:) ! Nat,3
33 1 pfleura2
34 1 pfleura2
35 1 pfleura2
  LOGICAL ::  debug, print, printspline
36 1 pfleura2
  LOGICAL, EXTERNAL :: valid
37 1 pfleura2
38 1 pfleura2
  !We will calculate the length of the path, in MW coordinates...
39 1 pfleura2
  ! this is done is a stupid way: we interpolate the zmatrix values,
40 1 pfleura2
  ! convert them into cartesian, weight the cartesian
41 1 pfleura2
  ! and calculate the evolution of the distance !
42 1 pfleura2
  ! We have to follow the same procedure for every geometry
43 1 pfleura2
  ! so even for the first one, we have to convert it from zmat
44 1 pfleura2
  ! to cartesian !
45 1 pfleura2
46 1 pfleura2
  debug=valid("pathcreate")
47 1 pfleura2
  print=valid("printgeom")
48 1 pfleura2
49 1 pfleura2
  printspline=(valid("printspline").AND.(dist<=1e30))
50 1 pfleura2
51 1 pfleura2
  if (debug) Call Header("Entering Extrapol_cart")
52 1 pfleura2
53 1 pfleura2
! We want 100 points along the interpolating path
54 1 pfleura2
  NSpline=int(NMaxPtPath/100)
55 1 pfleura2
56 1 pfleura2
  if (printspline) THEN
57 1 pfleura2
     WRITE(TmpChar,'(I5)') Iopt
58 1 pfleura2
     FileSpline=Trim(adjustL(PathName)) // '_spline.' // AdjustL(TRIM(TmpChar))
59 1 pfleura2
     OPEN(IOTMP,FILE=FileSpline)
60 1 pfleura2
61 1 pfleura2
  END IF
62 1 pfleura2
63 1 pfleura2
64 1 pfleura2
  ALLOCATE(XyzTmp(Nat,3),XyzTmp2(Nat,3),DerXyz(Nat,3))
65 1 pfleura2
66 1 pfleura2
! PFL 2011 June 22
67 1 pfleura2
! There was an alignment procedure there.
68 1 pfleura2
! It has been moved to PathCreate before the
69 1 pfleura2
! computation of the Spline coefficient.
70 1 pfleura2
71 1 pfleura2
  XyzGeomF(1,:,:)=XyzGeomI(1,:,:)
72 1 pfleura2
73 1 pfleura2
74 1 pfleura2
  ! We initialize the first geometry
75 1 pfleura2
76 1 pfleura2
  XyzTmp=Reshape(XyzGeomI(1,:,:),(/Nat,3/),ORDER=(/2,1/))
77 1 pfleura2
78 1 pfleura2
79 1 pfleura2
80 1 pfleura2
  s=0.d0
81 1 pfleura2
  SGeom(1)=0.d0
82 1 pfleura2
83 1 pfleura2
  if (printspline) THEN
84 1 pfleura2
     u=0.d0
85 1 pfleura2
     DO Iat=1,Nat
86 1 pfleura2
        ! We generate the interpolated coordinates
87 1 pfleura2
        if (Linear) THEN
88 1 pfleura2
           call LinearInt(u,XyzTmp2(Iat,1),DerXyz(Iat,1),NGeomI,xgeom(1),XyzGeomI(1,1,Iat))
89 1 pfleura2
           call LinearInt(u,XyzTmp2(Iat,2),DerXyz(Iat,2),NGeomI,xgeom(1),XyzGeomI(1,2,Iat))
90 1 pfleura2
           call LinearInt(u,XyzTmp2(Iat,3),DerXyz(Iat,3),NGeomI,xgeom(1),XyzGeomI(1,3,Iat))
91 1 pfleura2
92 1 pfleura2
        ELSE
93 1 pfleura2
           call splintder(u,XyzTmp2(Iat,1),DerXyz(Iat,1),NGeomI,xgeom(1),XyzGeomI(1,1,Iat),Coef(1,3*Iat-2))
94 1 pfleura2
           call splintder(u,XyzTmp2(Iat,2),DerXyz(Iat,2),NGeomI,xgeom(1),XyzGeomI(1,2,Iat),Coef(1,3*Iat-1))
95 1 pfleura2
           call splintder(u,XyzTmp2(Iat,3),DerXyz(Iat,3),NGeomI,xgeom(1),XyzGeomI(1,3,Iat),Coef(1,3*Iat))
96 1 pfleura2
        END IF
97 1 pfleura2
     END DO
98 1 pfleura2
99 1 pfleura2
     WRITE(IOTMP,*) Nat
100 1 pfleura2
     WRITE(IOTMP,'(1X,A,1X,F15.6)') "Debug Spline - Coord=Cart,s=",s
101 1 pfleura2
     DO Iat=1,Nat
102 1 pfleura2
        WRITE(IOTMP,'(1X,A2,3(1X,F15.6))') Nom(Atome(Iat)),    &
103 1 pfleura2
                   (XyzTmp2(Iat,1:3))
104 1 pfleura2
     END DO
105 1 pfleura2
  END IF
106 1 pfleura2
107 1 pfleura2
 IdxGeom=1
108 1 pfleura2
109 1 pfleura2
  DO K=1,NMaxPtPath
110 1 pfleura2
     u=real(K)/NMaxPtPath*(NGeomI-1.)
111 1 pfleura2
112 1 pfleura2
     DO Iat=1,Nat
113 1 pfleura2
        ! We generate the interpolated coordinates
114 1 pfleura2
        if (Linear) THEN
115 1 pfleura2
           call LinearInt(u,XyzTmp2(Iat,1),DerXyz(Iat,1),NGeomI,xgeom(1),XyzGeomI(1,1,Iat))
116 1 pfleura2
           call LinearInt(u,XyzTmp2(Iat,2),DerXyz(Iat,2),NGeomI,xgeom(1),XyzGeomI(1,2,Iat))
117 1 pfleura2
           call LinearInt(u,XyzTmp2(Iat,3),DerXyz(Iat,3),NGeomI,xgeom(1),XyzGeomI(1,3,Iat))
118 1 pfleura2
119 1 pfleura2
        ELSE
120 1 pfleura2
           call splintder(u,XyzTmp2(Iat,1),DerXyz(Iat,1),NGeomI,xgeom(1),XyzGeomI(1,1,Iat),Coef(1,3*Iat-2))
121 1 pfleura2
           call splintder(u,XyzTmp2(Iat,2),DerXyz(Iat,2),NGeomI,xgeom(1),XyzGeomI(1,2,Iat),Coef(1,3*Iat-1))
122 1 pfleura2
           call splintder(u,XyzTmp2(Iat,3),DerXyz(Iat,3),NGeomI,xgeom(1),XyzGeomI(1,3,Iat),Coef(1,3*Iat))
123 1 pfleura2
        END IF
124 1 pfleura2
     END DO
125 1 pfleura2
126 1 pfleura2
127 1 pfleura2
! PFL 2011 June 22: We now align on the previous one
128 1 pfleura2
! as we do for internal coord interpolation
129 1 pfleura2
130 1 pfleura2
! We align this geometry with the previous one
131 1 pfleura2
132 1 pfleura2
  ! PFL 17/July/2006: only if we have more than 4 atoms.
133 1 pfleura2
!  IF (Nat.GT.4) THEN
134 1 pfleura2
! PFL 24 Nov 2008 ->
135 1 pfleura2
! If we have frozen atoms we align only those ones.
136 1 pfleura2
! PFL 8 Feb 2011 ->
137 1 pfleura2
! I add a flag to see if we should align or not.
138 1 pfleura2
! For small systems, it might be better to let the user align himself
139 1 pfleura2
      IF (Align) THEN
140 1 pfleura2
         if (NFroz.GT.0) THEN
141 1 pfleura2
            Call AlignPartial(Nat,                     &
142 1 pfleura2
                 xyzTmp(1,1),xyzTmp(1,2),xyzTMP(1,3),       &
143 1 pfleura2
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
144 1 pfleura2
                 FrozAtoms,MRot)
145 1 pfleura2
         ELSE
146 1 pfleura2
            Call  CalcRmsd(Nat,                              &
147 1 pfleura2
                 xyzTmp(1,1),xyzTmp(1,2),xyzTMP(1,3),       &
148 1 pfleura2
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
149 1 pfleura2
                 MRot,rmsd,.TRUE.,.TRUE.)
150 1 pfleura2
         END IF
151 1 pfleura2
! <- PFL 24 Nov 2008
152 1 pfleura2
      END IF
153 1 pfleura2
! -> PFL 8 Feb 2011
154 1 pfleura2
!  END IF
155 1 pfleura2
156 1 pfleura2
157 1 pfleura2
158 1 pfleura2
     ds=0.
159 1 pfleura2
     DO I=1,Nat
160 1 pfleura2
        DO J=1,3
161 1 pfleura2
           ds=ds+MassAt(I)*(XYZTMp2(I,J)-XYZTmp(I,J))**2
162 1 pfleura2
           XYZTmp(I,J)=XyzTMP2(I,J)
163 1 pfleura2
        ENDDO
164 1 pfleura2
     ENDDO
165 1 pfleura2
     s=s+sqrt(ds)
166 1 pfleura2
167 1 pfleura2
     !         if (debug) WRITE(*,*) "Debug u,s,dist",u,s,dist
168 1 pfleura2
169 1 pfleura2
  if ((printspline).AND.(MOD(K,NSpline).EQ.0)) THEN
170 1 pfleura2
     WRITE(IOTMP,*) Nat
171 1 pfleura2
     WRITE(IOTMP,'(1X,A,1X,F15.6)') "Debug Spline - Coord=Cart,s=",s
172 1 pfleura2
     DO Iat=1,Nat
173 1 pfleura2
        WRITE(IOTMP,'(1X,A2,3(1X,F15.6))') Nom(Atome(Iat)),    &
174 1 pfleura2
                   (XyzTmp2(Iat,1:3))
175 1 pfleura2
     END DO
176 1 pfleura2
  END IF
177 1 pfleura2
178 1 pfleura2
179 1 pfleura2
     if (s>=dist) THEN
180 1 pfleura2
181 1 pfleura2
        if (debug) THEN
182 1 pfleura2
           WRITE(*,*) "DBG Interpol_cart",s
183 1 pfleura2
           DO i=1,Nat
184 1 pfleura2
              WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)),    &
185 1 pfleura2
                   (XyzTmp2(I,J),J=1,3)
186 1 pfleura2
           END DO
187 1 pfleura2
        END IF
188 1 pfleura2
189 1 pfleura2
        s=s-dist
190 1 pfleura2
        IdxGeom=IdxGeom+1
191 1 pfleura2
        SGeom(IdxGeom)=s+dist*(IdxGeom-1)
192 1 pfleura2
193 1 pfleura2
  ! We align this geometry with the original one
194 1 pfleura2
  ! PFL 17/July/2006: only if we have more than 4 atoms.
195 1 pfleura2
!  IF (Nat.GT.4) THEN
196 1 pfleura2
! PFL 24 Nov 2008 ->
197 1 pfleura2
! If we have frozen atoms we align only those ones.
198 1 pfleura2
! PFL 8 Feb 2011 ->
199 1 pfleura2
! I add a flag to see if we should align or not.
200 1 pfleura2
! For small systems, it might be better to let the user align himself
201 1 pfleura2
      IF (Align) THEN
202 1 pfleura2
         if (NFroz.GT.0) THEN
203 1 pfleura2
            Call AlignPartial(Nat,x0,y0,z0,                     &
204 1 pfleura2
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
205 1 pfleura2
                 FrozAtoms,MRot)
206 1 pfleura2
         ELSE
207 1 pfleura2
            Call  CalcRmsd(Nat, x0,y0,z0,                              &
208 1 pfleura2
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
209 1 pfleura2
                 MRot,rmsd,.TRUE.,.TRUE.)
210 1 pfleura2
         END IF
211 1 pfleura2
! <- PFL 24 Nov 2008
212 1 pfleura2
      END IF
213 1 pfleura2
! -> PFL 8 Feb 2011
214 1 pfleura2
!  END IF
215 1 pfleura2
216 1 pfleura2
        XyzGeomF(IdxGeom,:,:)=Reshape(XyzTmp2(:,:),(/3,Nat/),ORDER=(/2,1/))
217 1 pfleura2
        XyzTangent(IdxGeom,:)=Reshape(DerXyz(:,:),(/3*Nat/))
218 1 pfleura2
219 1 pfleura2
        if (print) THEN
220 1 pfleura2
           WRITE(IOOUT,'(1X,I5)') Nat
221 1 pfleura2
           WRITE(IOOUT,*) "# Cartesian coord for Geometry ",IdxGeom,K
222 1 pfleura2
223 1 pfleura2
           DO i=1,Nat
224 1 pfleura2
              WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)),    &
225 1 pfleura2
                   (XyzTmp2(I,J),J=1,3)
226 1 pfleura2
           END DO
227 1 pfleura2
228 1 pfleura2
        END IF
229 1 pfleura2
     END IF  ! s>= dist
230 1 pfleura2
  ENDDO  ! K
231 1 pfleura2
232 1 pfleura2
233 1 pfleura2
  if (s>=0.9*dist) THEN
234 1 pfleura2
     s=s-dist
235 1 pfleura2
     XyzTmp2=Reshape(XyzGeomI(NGeomI,:,:),(/Nat,3/),ORDER=(/2,1/))
236 1 pfleura2
237 1 pfleura2
  if (printspline) THEN
238 1 pfleura2
     WRITE(IOTMP,*) Nat
239 1 pfleura2
     WRITE(IOTMP,*) "Debug Spline - Coord=Cart,s=",s
240 1 pfleura2
     DO Iat=1,Nat
241 1 pfleura2
        WRITE(IOTMP,'(1X,A2,3(1X,F15.6))') Nom(Atome(Iat)),    &
242 1 pfleura2
                   (XyzTmp2(Iat,1:3))
243 1 pfleura2
     END DO
244 1 pfleura2
  END IF
245 1 pfleura2
246 1 pfleura2
247 1 pfleura2
  ! We align this geometry with the original one
248 1 pfleura2
  ! PFL 17/July/2006: only if we have more than 4 atoms.
249 1 pfleura2
!  IF (Nat.GT.4) THEN
250 1 pfleura2
! PFL 24 Nov 2008 ->
251 1 pfleura2
! If we have frozen atoms we align only those ones.
252 1 pfleura2
! PFL 8 Feb 2011 ->
253 1 pfleura2
! I add a flag to see if we should align or not.
254 1 pfleura2
! For small systems, it might be better to let the user align himself
255 1 pfleura2
      IF (Align) THEN
256 1 pfleura2
         if (NFroz.GT.0) THEN
257 1 pfleura2
            Call AlignPartial(Nat,x0,y0,z0,                     &
258 1 pfleura2
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
259 1 pfleura2
                 FrozAtoms,MRot)
260 1 pfleura2
         ELSE
261 1 pfleura2
            Call  CalcRmsd(Nat, x0,y0,z0,                              &
262 1 pfleura2
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
263 1 pfleura2
                 MRot,rmsd,.TRUE.,.TRUE.)
264 1 pfleura2
         END IF
265 1 pfleura2
! <- PFL 24 Nov 2008
266 1 pfleura2
      END IF
267 1 pfleura2
! -> PFL 8 Feb 2011
268 1 pfleura2
!  END IF
269 1 pfleura2
270 1 pfleura2
     IdxGeom=IdxGeom+1
271 1 pfleura2
     SGeom(IdxGeom)=s+dist*(IdxGeom-1)
272 1 pfleura2
273 1 pfleura2
    IF (IdxGeom.GT.NGeomF) THEN
274 1 pfleura2
        WRITE(IOOUT,*) "!!! ERROR in Extrapol_cart !!!!"
275 1 pfleura2
        WRITE(IOOUT,*) "Too many structures. Increase NMaxPath"
276 1 pfleura2
        WRITE(*,*) "** PathCreate ***"
277 1 pfleura2
        WRITE(*,*) "Distribution of points along the path is wrong."
278 1 pfleura2
        WRITE(*,*) "Increase value of NMaxPtPath in the input file"
279 1 pfleura2
        WRITE(*,*) "Present value is:", NMaxPtPath
280 1 pfleura2
        STOP
281 1 pfleura2
     END IF
282 1 pfleura2
283 1 pfleura2
284 1 pfleura2
  ! We align this geometry with the original one
285 1 pfleura2
  ! PFL 17/July/2006: only if we have more than 4 atoms.
286 1 pfleura2
!  IF (Nat.GT.4) THEN
287 1 pfleura2
! PFL 24 Nov 2008 ->
288 1 pfleura2
! If we have frozen atoms we align only those ones.
289 1 pfleura2
! PFL 8 Feb 2011 ->
290 1 pfleura2
! I add a flag to see if we should align or not.
291 1 pfleura2
! For small systems, it might be better to let the user align himself
292 1 pfleura2
      IF (Align) THEN
293 1 pfleura2
         if (NFroz.GT.0) THEN
294 1 pfleura2
            Call AlignPartial(Nat,x0,y0,z0,                     &
295 1 pfleura2
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
296 1 pfleura2
                 FrozAtoms,MRot)
297 1 pfleura2
         ELSE
298 1 pfleura2
            Call  CalcRmsd(Nat, x0,y0,z0,                              &
299 1 pfleura2
                 xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3),       &
300 1 pfleura2
                 MRot,rmsd,.TRUE.,.TRUE.)
301 1 pfleura2
         END IF
302 1 pfleura2
! <- PFL 24 Nov 2008
303 1 pfleura2
      END IF
304 1 pfleura2
! -> PFL 8 Feb 2011
305 1 pfleura2
!  END IF
306 1 pfleura2
307 1 pfleura2
     XyzGeomF(IdxGeom,:,:)=Reshape(XyzTmp2(:,:),(/3,Nat/),ORDER=(/2,1/))
308 1 pfleura2
     XyzTangent(IdxGeom,:)=Reshape(DerXyz(:,:),(/3*Nat/))
309 1 pfleura2
310 1 pfleura2
     if (print) THEN
311 1 pfleura2
        WRITE(IOOUT,'(1X,I5)') Nat
312 1 pfleura2
        WRITE(IOOUT,*) "# Cartesian coord for Geometry ",IdxGeom,K
313 1 pfleura2
314 1 pfleura2
        DO i=1,Nat
315 1 pfleura2
           WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)),     &
316 1 pfleura2
                (XyzTmp2(I,J),J=1,3)
317 1 pfleura2
        END DO
318 1 pfleura2
     END IF
319 1 pfleura2
  END IF
320 1 pfleura2
321 1 pfleura2
  DEALLOCATE(XyzTmp,XyzTmp2)
322 1 pfleura2
323 1 pfleura2
  if (debug) WRITE(*,*) 's final =',s
324 1 pfleura2
325 1 pfleura2
  if (printspline) CLOSE(IOTMP)
326 1 pfleura2
327 1 pfleura2
  if (debug) Call Header("Extrapol_cart over")
328 1 pfleura2
329 1 pfleura2
END SUBROUTINE EXTRAPOL_CART