Statistiques
| Révision :

root / src / Extrapol_baker.f90 @ 3

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

1
SUBROUTINE Extrapol_baker(s,dist,x0,y0,z0,xgeom,Coef,XgeomF)
2

    
3
  ! This subroutine constructs the path, andabscissa 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
  ! A reference geometry for the alignment: X0(Nat),Y0(Nat),Z0(Nat)
11

    
12
  use Path_module, only : IntCoordI, NMaxPtPath, XyzGeomF, IntCoordF, &
13
       IntTangent, Renum, Nom, Order, MassAt, SGeom, Nat, NGeomI, &
14
       NGeomF, Atome, NCoord, OrderInv, XyzGeomI,BTransInvF, &
15
       XPrimitive,XPrimitiveF, NPrim,                                      &
16
       BTransInv_local,UMatF,UMat_local,FirstTimePathCreate,Pi
17
  ! IntCoordI(NGeomI,3*Nat-6), Coef(NGeomI,NCoord), NMaxPtPath=1000 (default value)
18
  ! More appropriate: IntCoordI(NGeomI,NCoord)
19
  use Io_module
20
  IMPLICIT NONE
21

    
22
  REAL(KREAL), INTENT(OUT) :: s
23
  ! A reference geometry for the alignment:
24
  REAL(KREAL), INTENT(IN) :: dist,X0(Nat),Y0(Nat),Z0(Nat)
25
  ! Xgeom(NGeomI): abscissa of all initial geometries.
26
  ! Coef(NGeomI,NCoord): spline coefficients.
27
  REAL(KREAL), INTENT(IN) :: Xgeom(NGeomI),Coef(NGeomI,NCoord)
28
  ! Number of the cycles for the optimization:
29
  ! XGeomF(NGeomF): Final geometries.
30
  REAL(KREAL), INTENT(OUT) :: XGeomF(NGeomF)
31

    
32
  INTEGER(KINT) :: IdxGeom, I, J, K
33
  REAL(KREAL) :: Rmsd,MRot(3,3), ds, u, v
34

    
35
  REAL(KREAL), ALLOCATABLE :: XyzTmp(:,:), XyzTmp2(:,:), DerInt(:) ! (Nat,3)
36
  REAL(KREAL), ALLOCATABLE :: Xyz_k(:,:) ! (Nat,3)
37
  REAL(KREAL), ALLOCATABLE :: IntCoord_interpol(:) ! (3*Nat-6)
38
  REAL(KREAL), ALLOCATABLE :: IntCoord_k(:) ! (3*Nat-6)
39
  REAL(KREAL), ALLOCATABLE :: XPrimRef(:),XPrim(:) ! NPrim
40

    
41
  LOGICAL ::  debug, print,printspline
42
  LOGICAL, EXTERNAL :: valid
43

    
44
  INTEGER(KINT) :: NSpline
45

    
46

    
47
  ! We will calculate the length of the path, in MW coordinates...
48
  ! this is done in a stupid way: we interpolate the Baker coordinates values,
49
  ! convert them into cartesian, weight the cartesian
50
  ! and calculate the evolution of the distance ! 
51
  ! We have to follow the same procedure for every geometry,
52
  ! so even for the first one, we have to convert it from internal Baker 
53
  ! coordinates to cartesian !
54

    
55
  debug=valid("Extrapol_baker")
56
  print=valid("printgeom")
57
  printspline=(valid("printspline").AND.(dist<=1e30))
58

    
59
  if (debug) WRITE(*,*) "================= Entering Extrapol_baker ===================="
60
  if (debug) WRITE(*,*) "DBG Extrapol_baker dist=",Dist
61
  NSpline=int(NMaxPtPath/100)
62
  !IF (printspline) THEN
63
  !  WRITE(TmpChar,'(I5)') Iopt
64
  ! FileSpline=Trim(adjustL(PathName)) // '_spline.' // AdjustL(TRIM(TmpChar))
65
  !OPEN(IOTMP,FILE=FileSpline)
66
  ! END IF
67

    
68
  ALLOCATE(XyzTmp(Nat,3),XyzTmp2(Nat,3),IntCoord_interpol(NCoord),DerInt(NCoord))
69
  ALLOCATE(IntCoord_k(NCoord),Xyz_k(Nat,3))
70
  ALLOCATE(XPrimRef(NPrim),XPrim(NPrim))
71

    
72
  ! XyzGeomI(:,:,:) ! (NGeomI,3,Nat)
73
  ! IntCoordI(:,:) ! (NGeomI,3*Nat-6)
74

    
75
  !XyzGeomF(1,:,:)=Reshape(XyzTmp2(:,:),(/3,Nat/),ORDER=(/2,1/))
76
  XyzGeomF(1,:,:)=XyzGeomI(1,:,:) ! 1st index is geometry-index.
77
  IntCoordF(1,:)=IntCoordI(1,:)
78

    
79
  ! We calculate the first derivatives
80
  u=0.d0
81
  DO I=1,NCoord
82
     ! Given the arrays xgeom(1:NGeomI) and IntCoordI(1:NGeomI,Idx) of length 
83
     ! NGeomI, which tabulate a function
84
     ! (with the xgeom's in order), and given the array Coef(1:NGeomI,Idx), 
85
     ! which is the output from spline, and given a value of u,
86
     ! this routine returns a cubic-spline interpolated value v.
87
     ! and the derivative DerInt(Idx).
88
     call splintder(u,v,DerInt(I),NGeomI,xgeom(1),IntCoordI(1,I),Coef(1,I))
89
  END DO
90
  IntTangent(1,:)=DerInt
91

    
92
  IF (print.AND.(Dist.LE.1e20)) THEN
93
     WRITE(IOOUT,'(1X,I5)') Nat
94
     WRITE(IOOUT,*) "# Cartesian Coordinates for geom",1
95
     DO I=1,Nat
96
        If (Renum) THEN
97
           WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)), &
98
                (XyzTmp2(Order(I),J),J=1,3)
99
        ELSE
100
           WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(OrderInv(I))), &
101
                (XyzTmp2(I,J),J=1,3)
102
        END IF
103
     END DO
104
  END IF ! matches IF (print.AND.(Dist.LE.1e20)) THEN
105

    
106
  XyzTmp(:,1) = XyzGeomI(1,1,:) ! 1st index is geometry-index.
107
  XyzTmp(:,2) = XyzGeomI(1,2,:)
108
  XyzTmp(:,3) = XyzGeomI(1,3,:)
109

    
110
  s=0.d0
111
  IntCoord_k=IntCoordF(1,:)
112
  Xyz_k(:,1) = XyzGeomI(1,1,:) ! 1st index is geometry-index.
113
  Xyz_k(:,2) = XyzGeomI(1,2,:)
114
  Xyz_k(:,3) = XyzGeomI(1,3,:)
115
  IdxGeom=1
116
  XPrimRef=XPrimitive(1,:)
117
  XPrimitiveF(1,:)=XPrimitive(1,:)
118
  DO K=1,NMaxPtPath
119
     u=real(K)/NMaxPtPath*(NGeomI-1.)
120

    
121
     ! We generate the interpolated internal coordinates in v.
122
     ! Given the arrays Xgeom(1:NGeomI) (Xgeom(NGeomI): abscissa of all initial geometries)
123
     ! and IntCoordI(1:NGeomI,I) of length NGeomI, which tabulate a function (with the 
124
     ! Xgeom's in order), and given the array Coef(1:NGeomI,Idx), which is the output from 
125
     ! spline, and given a value of u, this routine returns a cubic-spline interpolated 
126
     ! value v and the derivative DerInt(I).
127

    
128
     ! this loop is to be confirmed:
129
     ! IntCoordI(NGeomI,3*Nat-6)
130
     DO I=1,NCoord
131
        call splintder(u,v,DerInt(I),NGeomI,Xgeom(1),IntCoordI(1,I),Coef(1,I))
132
        IntCoord_interpol(I)=v
133
     END DO
134
     IF(.NOT.FirstTimePathCreate) Then
135
       WRITE(*,*) "DBG Extrapol_baker Umat_local=UMatF"
136
        DO I=1,NCoord ! these variables are used in ConvertBakerInternal_cart()
137
           BTransInv_local(I,:) = BTransInvF(IdxGeom,I,:)
138
           UMat_local(:,I) = UMatF(IdxGeom,:,I)
139
        END DO
140
     END IF
141
     ! We convert it into Cartesian coordinates:
142
     if (debug) WRITE(*,*) "DBG Extrapol_baker, call ConvertBakerInt_car for k=",k
143
     Call ConvertBakerInternal_cart(IntCoord_k,IntCoord_interpol,Xyz_k(1,1), &
144
          Xyz_k(1,2),Xyz_k(1,3),XyzTMP2(1,1),XyzTMP2(1,2),XyzTMP2(1,3),XPrim,XPrimRef)
145
     XPrimRef=Xprim
146
     IF(.NOT.FirstTimePathCreate) Then
147
        DO I=1,NCoord ! these variables are used in ConvertBakerInternal_cart()
148
           BTransInvF(IdxGeom,I,:) = BTransInv_local(I,:)
149
        END DO
150
     END IF
151

    
152
     if (debug) THEN
153
        WRITE(*,*) "DBG Extrapol_baker, XyzTmp2 before RMSD"
154
           DO I=1,Nat
155
              IF (Renum) THEN
156
                 WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)), &
157
                      (XyzTmp2(Order(I),J),J=1,3)
158
              ELSE
159
                 WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(OrderInv(I))), &
160
                      (XyzTmp2(I,J),J=1,3)
161
              END IF
162
           END DO
163
        END IF
164
     
165

    
166
     call CalcRmsd(Nat,XyzTmp(1:Nat,1),XyzTmp(1:Nat,2),XyzTmp(1:Nat,3), &
167
    XyzTmp2(1:Nat,1),XyzTmp2(1:Nat,2),XyzTmp2(1:Nat,3),           &
168
          MRot,rmsd,.TRUE.,.TRUE.)
169

    
170

    
171
     if (debug) THEN
172
        WRITE(*,*) "DBG Extrapol_baker, XyzTmp2 after RMSD"
173
           DO I=1,Nat
174
              IF (Renum) THEN
175
                 WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)), &
176
                      (XyzTmp2(Order(I),J),J=1,3)
177
              ELSE
178
                 WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(OrderInv(I))), &
179
                      (XyzTmp2(I,J),J=1,3)
180
              END IF
181
           END DO
182
        END IF
183

    
184

    
185
     IntCoord_k=IntCoord_interpol
186
     Xyz_k(:,1)=XyzTMP2(:,1)
187
     Xyz_k(:,2)=XyzTMP2(:,2)
188
     Xyz_k(:,3)=XyzTMP2(:,3)
189

    
190
     ds=0.
191
     DO I=1,Nat
192
        DO J=1,3
193
           ds=ds+MassAt(I)*(XYZTMp2(I,J)-XYZTmp(I,J))**2
194
           XYZTmp(I,J)=XyzTMP2(I,J)
195
        END DO
196
     END DO
197

    
198
     s=s+sqrt(ds)
199

    
200
     IF (s>=dist) THEN
201
        if (debug) THEN
202
           WRITE(*,*) "DBG Extrapol_baker s,IdxGeom,dist",s,IdxGeom,dist
203
           WRITE(*,'(50(1X,F12.8))') IntCoord_interpol
204
           WRITE(*,*) "DBG Extrapol_baker Angles in deg ?"
205
           WRITE(*,'(50(1X,F12.8))') IntCoord_interpol*180./pi
206
        END IF
207
        s=s-dist
208
        IdxGeom=IdxGeom+1
209
        XprimitiveF(IdxGeom,:)=Xprim(:)
210
        UMatF(IdxGeom,:,:)=UMat_local(:,:)
211
        SGeom(IdxGeom)=s+IdxGeom*dist !SGeom(NGeomF)
212
        XgeomF(IdxGeom)=u
213
        XyzGeomF(IdxGeom,:,:)=Reshape(XyzTmp2(:,:),(/3,Nat/),ORDER=(/2,1/))
214

    
215
        ! IntCoordF(NGeomF,NCoord): Final Internal coordinates for number of final 
216
        ! geometries. NCoord is the number of coordinates (NCoord) of each geometry.
217
        IntCoordF(IdxGeom,:)=IntCoord_interpol(:)
218
        IntTangent(IdxGeom,:)=DerInt
219

    
220
        IF (print) THEN
221
           WRITE(IOOUT,'(1X,I5)') Nat
222
           WRITE(IOOUT,*) "# Cartesian coord for Geometry ",IdxGeom,K
223
           ! PFL 17/July/2006: only if we have more than 4 atoms.
224
           IF (Nat.GE.4) THEN
225
              Call  CalcRmsd(Nat,x0,y0,z0, &
226
                   xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3), &
227
                   MRot,rmsd,.TRUE.,.TRUE.)
228
           END IF
229

    
230
           DO I=1,Nat
231
              IF (Renum) THEN
232
                 WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)), &
233
                      (XyzTmp2(Order(I),J),J=1,3)
234
              ELSE
235
                 WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(OrderInv(I))), &
236
                      (XyzTmp2(I,J),J=1,3)
237
              END IF
238
           END DO
239
        END IF !matches IF (print) THEN
240
     END IF ! matches IF (s>=dist) THEN
241
  END DO ! matches DO K=1,NMaxPtPath
242

    
243

    
244
  if (s>=0.9*dist) THEN
245
     s=s-dist
246
     IdxGeom=IdxGeom+1
247
     SGeom(IdxGeom)=s+IdxGeom*dist
248
     XgeomF(IdxGeom)=min(u,NGeomI-1.d0)
249
     XyzGeomF(IdxGeom,:,:)=Reshape(XyzTmp2(:,:),(/3,Nat/),ORDER=(/2,1/))
250
     !  XyzGeomF(IdxGeom,:,:)=XyzTmp2(:,:)
251

    
252
     IntCoordF(IdxGeom,:)=IntCoord_interpol(:)
253
     XprimitiveF(IdxGeom,:)=Xprim(:)
254
     UMatF(IdxGeom,:,:)=UMat_local(:,:)
255
     IntTangent(IdxGeom,:)=DerInt     
256

    
257
     if (print) THEN
258
        WRITE(IOOUT,'(1X,I5)') Nat
259
        WRITE(IOOUT,*) "# Cartesian coord for Geometry ",IdxGeom,K
260
        ! PFL 17/July/2006: only if we have more than 4 atoms.
261
        IF (Nat.GE.4) THEN
262
           Call  CalcRmsd(Nat,x0,y0,z0, &
263
                xyzTmp2(1,1),xyzTmp2(1,2),xyzTMP2(1,3), &
264
                MRot,rmsd,.TRUE.,.TRUE.)
265
        END IF
266

    
267
        DO I=1,Nat
268
           IF (Renum) THEN
269
              WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(I)), &
270
                   (XyzTmp2(Order(I),J),J=1,3)
271
           ELSE
272
              WRITE(IOOUT,'(1X,A2,3(1X,F15.6))') Nom(Atome(OrderInv(I))), &
273
                   (XyzTmp2(I,J),J=1,3)
274
           END IF
275
        END DO
276
     END IF ! matches if (print) THEN
277
  END IF ! matches if (s>=0.9*dist) THEN
278

    
279
  if (debug) WRITE(*,*) 's final =',s
280
   if (debug) THEN
281
      WRITE(*,*) "XPrimitiveF"
282
      DO I=1,NGeomF
283
        WRITE(*,'(1X,I5," : ",50(1X,F10.6))') I,XPrimitiveF(I,:)
284
     END DO
285
     END IF
286

    
287
  DEALLOCATE(XyzTmp,XyzTmp2,IntCoord_interpol,IntCoord_k,Xyz_k)
288

    
289
  if (printspline) CLOSE(IOTMP)
290
  if (debug) WRITE(*,*) "================= Extrapol_baker Over ====================="
291

    
292
END SUBROUTINE EXTRAPOL_BAKER