Statistiques
| Révision :

root / utils / Xyz2Scan.f90 @ 7

Historique | Voir | Annoter | Télécharger (19,06 ko)

1 6 pfleura2
          program Xyz2irc
2 6 pfleura2
! This programs reads a XYZ file and converts it into distances,
3 6 pfleura2
! valence angle and dihedral angles.
4 6 pfleura2
! It prints them as a function of the irc distance...
5 6 pfleura2
!-----------------------------------------------
6 6 pfleura2
! Input: name of the ROOT file of PAW
7 6 pfleura2
! it also needs a file call list which has the following structure:
8 6 pfleura2
! the first line gives the time when you want to start your analysis
9 6 pfleura2
! one line contains the type of the value you want to follow, it can be
10 6 pfleura2
! b  for a Bond distance
11 6 pfleura2
! a for an angle
12 6 pfleura2
! d for a dihedral
13 6 pfleura2
! this descriptor is followed by the number of the atoms involved !
14 6 pfleura2
! a typical file can be:
15 6 pfleura2
! 3.
16 6 pfleura2
! b  1  2
17 6 pfleura2
! b 2  3
18 6 pfleura2
! a 1 2 3
19 6 pfleura2
!----------------------------------------------
20 6 pfleura2
! Ouput: A files call Scan.dat
21 6 pfleura2
! wich contains in the first lines the input file (as a reminder)
22 6 pfleura2
! and then for each step the wanted values
23 6 pfleura2
!------------------------------------------------
24 6 pfleura2
! Second version also reads the energy (as to be written after E= on
25 6 pfleura2
! the comment line)
26 6 pfleura2
!------------------------------------------------
27 6 pfleura2
! Third version contains a new command: c for Center of Mass
28 6 pfleura2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29 6 pfleura2
! v 3.1 the c command now creates the center of mass... and allows
30 6 pfleura2
! people to do whatever they want with it...
31 6 pfleura2
! Syntax: c NbAt ListAt
32 6 pfleura2
!!
33 6 pfleura2
! v 3.2
34 6 pfleura2
! Added the p command that gives the oriented angle between two planes
35 6 pfleura2
! Syntax: p At1 At2 At3 At4 At5 At6
36 6 pfleura2
! At1, At2, At3 define the first plane
37 6 pfleura2
! At4, At5, At6 define the second plane
38 6 pfleura2
! How it works: gives the angles between the normal of the two planes, defined by
39 6 pfleura2
! the cross produc At2-At1 x At2-At3 etc.
40 6 pfleura2
!!!!
41 6 pfleura2
42 6 pfleura2
43 6 pfleura2
          IMPLICIT NONE
44 6 pfleura2
          INTEGER(4), PARAMETER :: maxnat=10000,MaxList=100
45 6 pfleura2
46 6 pfleura2
          CHARACTER(120) :: f1
47 6 pfleura2
          REAL(8) ::   geos(3,maxnat)
48 6 pfleura2
          CHARACTER(33) :: fmt
49 6 pfleura2
          CHARACTER(3) :: atoms(maxnat)
50 6 pfleura2
          character(5) :: Type
51 6 pfleura2
          CHARACTER(120) :: line
52 6 pfleura2
          INTEGER(4) :: NbPrint
53 6 pfleura2
          REAL(8) ::   AU2PS,Pi
54 6 pfleura2
! Mass is not used for now.
55 6 pfleura2
!          REAL(8) ::  Mass(MaxNat)
56 6 pfleura2
          REAL(8) :: Ener, Conv
57 6 pfleura2
          INTEGER(4) :: At1,At2,At3,At4,At5,At6,IOOUT
58 6 pfleura2
          INTEGER(4) ::  IArg, I, NNN, Ng, J
59 6 pfleura2
60 6 pfleura2
          INTEGER(4) :: Nat,NbDist, NbAngle, NbDie,NbP,NbCOM
61 6 pfleura2
          INTEGER(4) :: At1B(MaxList),At2B(MaxList)
62 6 pfleura2
          INTEGER(4) :: At1A(MaxList),At2A(MaxList),At3A(MaxList)
63 6 pfleura2
          INTEGER(4) :: At1D(MaxList),At2D(MaxList),At3D(MaxList),At4D(MaxList)
64 6 pfleura2
          INTEGER(4) :: At1p(MaxList),At2p(MaxList),At3p(MaxList), &
65 6 pfleura2
                   At4p(MaxList),At5p(MaxList),At6p(MaxList)
66 6 pfleura2
          INTEGER(4) :: AtCom(0:MaxList,MaxList)
67 6 pfleura2
          REAL(8) ::    VB(MaxList),VA(MaxList),VD(MaxList),VCOM(MaxList)
68 6 pfleura2
          REAL(8) ::    Vp(MaxList)
69 6 pfleura2
          LOGICAL FExist
70 6 pfleura2
71 6 pfleura2
          COMMON /Indices/Nat,NbDist,NbAngle,NbDie,NbP,NbCom, At1B,At2B, &
72 6 pfleura2
              At1A,At2A,At3A,At1D,At2D,At3D,At4D,AtCom,  &
73 6 pfleura2
              At1p,At2p,At3p,At4p,At5p,At6p
74 6 pfleura2
          COMMON /Values/VB,VA,VD,Vp,VCom
75 6 pfleura2
          COMMON /Const/AU2ps,Pi
76 6 pfleura2
77 6 pfleura2
          AU2PS=1./41341.37
78 6 pfleura2
          NbPrint=100
79 6 pfleura2
          Pi=dacos(-1.d0)
80 6 pfleura2
          IOOUT=13
81 6 pfleura2
          Conv=1.
82 6 pfleura2
          iarg=iargc()
83 6 pfleura2
          if (iarg.lt.1) then
84 6 pfleura2
             WRITE(*,*) "=============================================="
85 6 pfleura2
             WRITE(*,*) "==                                          =="
86 6 pfleura2
             WRITE(*,*) "==   Xyz2Scan: Xyz file to scan file        =="
87 6 pfleura2
             WRITE(*,*) "==                                          =="
88 6 pfleura2
             WRITE(*,*) "=============================================="
89 6 pfleura2
             WRITE(*,*) "Usage: xyz2scan XYZ_file "
90 6 pfleura2
             WRITE(*,*) "The XYZ file should follow the 'usual' format:"
91 6 pfleura2
             WRITE(*,*) "Number of atoms on the first line "
92 6 pfleura2
             WRITE(*,*) "Comment on the second line"
93 6 pfleura2
             WRITE(*,*) "The geometry is given in cartesian coordinates"
94 6 pfleura2
             WRITE(*,*) "with atom symbol and three coordinates:"
95 6 pfleura2
             WRITE(*,*) " C   0. 1. 0."
96 6 pfleura2
             WRITE(*,*) ""
97 6 pfleura2
             WRITE(*,*) " xyz2scan also needs a file called 'list' "
98 6 pfleura2
             WRITE(*,*) "which has the following structure:"
99 6 pfleura2
             WRITE(*,*) "Each line contains the type of the value you"
100 6 pfleura2
             WRITE(*,*) "want to follow, it can be:"
101 6 pfleura2
             WRITE(*,*) " - b  for a Bond distance"
102 6 pfleura2
             WRITE(*,*) " - a for an angle"
103 6 pfleura2
             WRITE(*,*) " - d for a dihedral"
104 6 pfleura2
             WRITE(*,*) " - p for the oriented angle between two planes"
105 6 pfleura2
             WRITE(*,*) "This descriptor is followed by the number of"
106 6 pfleura2
             WRITE(*,*) "the atoms involved"
107 6 pfleura2
             WRITE(*,*) "One can also create 'barycenter' atoms that"
108 6 pfleura2
             WRITE(*,*) "can then be used as normal atoms."
109 6 pfleura2
             WRITE(*,*) "the descriptor is 'c' followed by the number"
110 6 pfleura2
             WRITE(*,*) "of atoms and the list of atoms:"
111 6 pfleura2
             WRITE(*,*) " c 2  1 5"
112 6 pfleura2
             WRITE(*,*) "A typical file can be:"
113 6 pfleura2
             WRITE(*,*) " b  1  2"
114 6 pfleura2
             WRITE(*,*) " b 2  3"
115 6 pfleura2
             WRITE(*,*) " a 1 2 3"
116 6 pfleura2
             WRITE(*,*) "     "
117 6 pfleura2
             WRITE(*,*) "=============================================="
118 6 pfleura2
             write(*,*) 'XYZ filename:'
119 6 pfleura2
              read(*,'(a)') f1
120 6 pfleura2
            else
121 6 pfleura2
              call getarg(1,f1)
122 6 pfleura2
          endif
123 6 pfleura2
124 6 pfleura2
          open(13,file='Scan.dat')
125 6 pfleura2
126 6 pfleura2
          INQUIRE(File='list',Exist=FExist)
127 6 pfleura2
          if (.NOT.FExist) THEN
128 6 pfleura2
             WRITE(*,*) "File *list* is missing"
129 6 pfleura2
             STOP
130 6 pfleura2
          END IF
131 6 pfleura2
132 6 pfleura2
          open(11,file=f1)
133 6 pfleura2
          READ(11,*) nnn
134 6 pfleura2
          close(11)
135 6 pfleura2
136 6 pfleura2
137 6 pfleura2
          if (nnn.GT.MaxNat) THEN
138 6 pfleura2
             WRITE(*,*) "Sorry but your system has too many atoms"
139 6 pfleura2
             WRITE(*,*) "Change the value of MaxNat in the source file"
140 6 pfleura2
             WRITE(*,*) "and then recompile."
141 6 pfleura2
             WRITE(*,*) "For information, now MaxNat=",MaxNat
142 6 pfleura2
             WRITE(*,*) "and you have ",nnn," atoms."
143 6 pfleura2
             STOP
144 6 pfleura2
          END IF
145 6 pfleura2
146 6 pfleura2
          Nat=nnn
147 6 pfleura2
148 6 pfleura2
         open(14,file='list')
149 6 pfleura2
         Type="d"
150 6 pfleura2
         DO WHILE (Type.ne."E")
151 6 pfleura2
          CALL READLINE(14,Type,Line)
152 6 pfleura2
!          WRITE(*,*) Line,Type
153 6 pfleura2
          if (Type.eq."b") THEN
154 6 pfleura2
             NbDist=NbDist+1
155 6 pfleura2
             READ(Line,*) At1,At2
156 6 pfleura2
             At1B(NbDist)=At1
157 6 pfleura2
             At2B(NbDist)=At2
158 6 pfleura2
          END IF
159 6 pfleura2
          if (Type.eq."a") THEN
160 6 pfleura2
             NbAngle=NbAngle+1
161 6 pfleura2
             READ(Line,*) At1,At2,At3
162 6 pfleura2
             At1A(NbAngle)=At1
163 6 pfleura2
             At2A(NbAngle)=At2
164 6 pfleura2
             At3A(NbAngle)=At3
165 6 pfleura2
          END IF
166 6 pfleura2
          if (Type.eq."d") THEN
167 6 pfleura2
             NbDie=NbDie+1
168 6 pfleura2
             READ(Line,*) At1,At2,At3,At4
169 6 pfleura2
             At1D(NbDie)=At1
170 6 pfleura2
             At2D(NbDie)=At2
171 6 pfleura2
             At3D(NbDie)=At3
172 6 pfleura2
             At4D(NbDie)=At4
173 6 pfleura2
!            WRITE(13,'("# d ",4(A3,I3))') Atoms(At1),At1,Atoms(At2),At2,
174 6 pfleura2
!     &          Atoms(At3),At3,Atoms(At4),At4
175 6 pfleura2
!            WRITE(*,'("# d ",4(A3,I3))') Atoms(At1),At1,Atoms(At2),At2,
176 6 pfleura2
!     &          Atoms(At3),At3,Atoms(At4),At4
177 6 pfleura2
178 6 pfleura2
          END IF
179 6 pfleura2
          if (Type.eq."p") THEN
180 6 pfleura2
             NbP=NbP+1
181 6 pfleura2
             READ(Line,*) At1,At2,At3,At4,At5,At6
182 6 pfleura2
             At1p(NbP)=At1
183 6 pfleura2
             At2p(NbP)=At2
184 6 pfleura2
             At3p(NbP)=At3
185 6 pfleura2
             At4p(NbP)=At4
186 6 pfleura2
             At5p(NbP)=At5
187 6 pfleura2
             At6p(NbP)=At6
188 6 pfleura2
          END IF
189 6 pfleura2
190 6 pfleura2
          if (Type.eq."c") THEN
191 6 pfleura2
            NbCOM=NbCOM+1
192 6 pfleura2
            READ(Line,*) At1,(AtCom(j,NbCOM),j=1,At1)
193 6 pfleura2
            AtCom(0,NbCOM)=At1
194 6 pfleura2
            Atoms(nat+NbCom)="G"
195 6 pfleura2
          END IF
196 6 pfleura2
197 6 pfleura2
         END DO
198 6 pfleura2
199 6 pfleura2
         CLOSE(14)
200 6 pfleura2
201 6 pfleura2
! We read one geoetry to get the atoms name
202 6 pfleura2
         open(11,file=f1)
203 6 pfleura2
          call rtraitem(11,nnn,ener,geos,atoms)
204 6 pfleura2
         close(11)
205 6 pfleura2
206 6 pfleura2
207 6 pfleura2
! We write things
208 6 pfleura2
! First NbCom
209 6 pfleura2
         if (NbCom.GE.1) THEN
210 6 pfleura2
            WRITE(*,*) "# Added center of mass"
211 6 pfleura2
            WRITE(IOOUT,*) "# Added center of mass"
212 6 pfleura2
            DO J=1,NbCom
213 6 pfleura2
            WRITE(IOOUT,'("# c ",I4,20(A3,I3))') AtCom(0,J),           &
214 6 pfleura2
               (Atoms(AtCom(i,J)),AtCom(i,J),i=1,At1)
215 6 pfleura2
            WRITE(*,'("# c ",I4,20(A3,I3))') AtCom(0,J),              &
216 6 pfleura2
               (Atoms(AtCom(i,J)),AtCom(i,J),i=1,At1)
217 6 pfleura2
            END DO
218 6 pfleura2
         END IF
219 6 pfleura2
220 6 pfleura2
! Distances
221 6 pfleura2
         if (NbDist.GE.1) THEN
222 6 pfleura2
            WRITE(*,*) "# Bonds"
223 6 pfleura2
            WRITE(IOOUT,*) "# Bonds"
224 6 pfleura2
            DO J=1,NbDist
225 6 pfleura2
               At1= At1B(J)
226 6 pfleura2
               At2=At2B(J)
227 6 pfleura2
             WRITE(IOOUT,'("# b ",2(A3,I3))') Atoms(At1),At1, &
228 6 pfleura2
                   Atoms(At2),At2
229 6 pfleura2
             WRITE(*,'("# b ",2(A3,I3))') Atoms(At1),At1,Atoms(At2),At2
230 6 pfleura2
            END DO
231 6 pfleura2
         END IF
232 6 pfleura2
233 6 pfleura2
! Angles
234 6 pfleura2
         if (NbAngle.GE.1) THEN
235 6 pfleura2
            WRITE(*,*) "# Angles"
236 6 pfleura2
            WRITE(IOOUT,*) "# Angles"
237 6 pfleura2
            DO J=1,NbAngle
238 6 pfleura2
            At1= At1A(J)
239 6 pfleura2
            At2= At2A(J)
240 6 pfleura2
            At3= At3A(J)
241 6 pfleura2
            WRITE(IOOUT,'("# a ",3(A3,I3))') Atoms(At1),At1,Atoms(At2), &
242 6 pfleura2
                 At2, Atoms(At3),At3
243 6 pfleura2
            WRITE(*,'("# a ",3(A3,I3))') Atoms(At1),At1,Atoms(At2),     &
244 6 pfleura2
                At2, Atoms(At3),At3
245 6 pfleura2
246 6 pfleura2
            END DO
247 6 pfleura2
         END IF
248 6 pfleura2
249 6 pfleura2
250 6 pfleura2
! Dihedrals
251 6 pfleura2
         if (NbDie.GE.1) THEN
252 6 pfleura2
            WRITE(*,*) "# Dihedrals"
253 6 pfleura2
            WRITE(IOOUT,*) "# Dihedrals"
254 6 pfleura2
            DO J=1,NbDie
255 6 pfleura2
            At1= At1D(J)
256 6 pfleura2
            At2= At2D(J)
257 6 pfleura2
            At3= At3D(J)
258 6 pfleura2
            At4= At4D(J)
259 6 pfleura2
            WRITE(IOOUT,'("# d ",4(A3,I3))') Atoms(At1),At1,Atoms(At2) &
260 6 pfleura2
               ,At2,Atoms(At3),At3,Atoms(At4),At4
261 6 pfleura2
            WRITE(*,'("# d ",4(A3,I3))') Atoms(At1),At1,Atoms(At2),At2,  &
262 6 pfleura2
               Atoms(At3),At3,Atoms(At4),At4
263 6 pfleura2
            END DO
264 6 pfleura2
         END IF
265 6 pfleura2
266 6 pfleura2
! Planar angles
267 6 pfleura2
         if (NbP.GE.1) THEN
268 6 pfleura2
            WRITE(*,*) "# Planes angles"
269 6 pfleura2
            WRITE(IOOUT,*) "# Planes angles"
270 6 pfleura2
            DO J=1,NbP
271 6 pfleura2
            At1= At1p(J)
272 6 pfleura2
            At2= At2p(J)
273 6 pfleura2
            At3= At3p(J)
274 6 pfleura2
            At4= At4p(J)
275 6 pfleura2
            At5= At5p(J)
276 6 pfleura2
            At6= At6p(J)
277 6 pfleura2
            WRITE(IOOUT,'("# p ",8(A3,I3))') Atoms(At1),At1,Atoms(At2) &
278 6 pfleura2
               ,At2,Atoms(At3),At3,Atoms(At4),At4 &
279 6 pfleura2
               ,Atoms(At5),At5,Atoms(At6),At6
280 6 pfleura2
            WRITE(*,'("# p ",8(A3,I3))') Atoms(At1),At1,Atoms(At2),At2,    &
281 6 pfleura2
               Atoms(At3),At3,Atoms(At4),At4             &
282 6 pfleura2
               ,Atoms(At5),At5,Atoms(At6),At6
283 6 pfleura2
            END DO
284 6 pfleura2
         END IF
285 6 pfleura2
286 6 pfleura2
287 6 pfleura2
          fmt='(   (1X,F12.5),1X,F15.6)'
288 6 pfleura2
          write(fmt(2:4),'(i3)') NbDist+NbAngle+NbDie+NbP
289 6 pfleura2
!           write(*,*) nat3
290 6 pfleura2
!          write(*,*) 'fmt:',fmt
291 6 pfleura2
292 6 pfleura2
          ng=1
293 6 pfleura2
294 6 pfleura2
          open(11,file=f1)
295 6 pfleura2
296 6 pfleura2
10           call rtraitem(11,nnn,ener,geos,atoms)
297 6 pfleura2
!           WRITE(*,*) nnn
298 6 pfleura2
299 6 pfleura2
           if (nnn.gt.0) then
300 6 pfleura2
! We convert coordinates in a0 into Angstroem
301 6 pfleura2
!              write(*,*) "Analyse !"
302 6 pfleura2
            Call Analyse(geos)
303 6 pfleura2
304 6 pfleura2
             write(IOOUT,fmt) (VB(j)/Conv,j=1,NbDist),  &
305 6 pfleura2
                 (VA(j),j=1,NbAngle),    &
306 6 pfleura2
                 (VD(j),j=1,NbDie),(Vp(j),j=1,NbP),ener
307 6 pfleura2
             write(*,fmt) (VB(j)/Conv,j=1,NbDist),   &
308 6 pfleura2
                 (VA(j),j=1,NbAngle),                &
309 6 pfleura2
                 (VD(j),j=1,NbDie),(Vp(j),j=1,NbP),ener
310 6 pfleura2
311 6 pfleura2
           ng=ng+1
312 6 pfleura2
            goto 10
313 6 pfleura2
           endif
314 6 pfleura2
           WRITE(*,*) 'Found ',ng-1,' geometries'
315 6 pfleura2
           close(11)
316 6 pfleura2
         end
317 6 pfleura2
318 6 pfleura2
!--------------------------------------------------------------
319 6 pfleura2
          subroutine rtraitem(ifil,nnn,E,tab,atoms)
320 6 pfleura2
!           implicit REAL(8) :: (a-h,o-z)
321 6 pfleura2
            IMPLICIT NONE
322 6 pfleura2
           CHARACTER(120) :: line
323 6 pfleura2
           CHARACTER(3) :: Atoms(*)
324 6 pfleura2
           INTEGER(4) :: nnn, IFil, Idx, I, J
325 6 pfleura2
           REAL(8) ::  Tab(3,*), E
326 6 pfleura2
327 6 pfleura2
328 6 pfleura2
           read(ifil,*,err=99,end=99) nnn
329 6 pfleura2
           read(ifil,'(A)') line
330 6 pfleura2
           idx=index(line,'E')
331 6 pfleura2
!           WRITE(*,*) 'idx,line',idx,line
332 6 pfleura2
           if (idx/=0) THEN
333 6 pfleura2
             line=line(idx+2:)
334 6 pfleura2
              idx=index(line,"=")
335 6 pfleura2
              if (idx/=0) line=line(idx+1:)
336 6 pfleura2
              idx=index(line,":")
337 6 pfleura2
              if (idx/=0) line=line(idx+1:)
338 6 pfleura2
              read(line,*) E
339 6 pfleura2
           ELSE
340 6 pfleura2
             E=0.
341 6 pfleura2
           END IF
342 6 pfleura2
343 6 pfleura2
!           write(*,*) 'coucou',line
344 6 pfleura2
           do i=1,nnn
345 6 pfleura2
              read(ifil,'(A)',err=99,end=99) Line
346 6 pfleura2
              do while (line(1:1)==' ')
347 6 pfleura2
                 line=line(2:)
348 6 pfleura2
              end do
349 6 pfleura2
              atoms(i)=line(1:3)
350 6 pfleura2
!            write(*,*) 'coucou atoms',atoms(i)
351 6 pfleura2
              do while (line(1:1).ne.' ')
352 6 pfleura2
                 line=line(2:)
353 6 pfleura2
              end do
354 6 pfleura2
!              WRITE(*,*) 'coucou2:',i,line
355 6 pfleura2
              read(line,*) (tab(j,i),j=1,3)
356 6 pfleura2
           end do
357 6 pfleura2
!           WRITE(*,*) 'coucou:',nnn,tab(1,1)
358 6 pfleura2
           return
359 6 pfleura2
99           nnn=0
360 6 pfleura2
!             WRITE(*,*) 'Erreur lecture',ifil,nnn
361 6 pfleura2
             return
362 6 pfleura2
           end subroutine rtraitem
363 6 pfleura2
364 6 pfleura2
!--------------------------------------------------------------
365 6 pfleura2
366 6 pfleura2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367 6 pfleura2
! READLINE
368 6 pfleura2
! This subroutine reads a line for a file, and converts
369 6 pfleura2
! the first field into a character variable, and the rest into 4 integers
370 6 pfleura2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
371 6 pfleura2
372 6 pfleura2
      SUBROUTINE READLINE(IOIN,Type,Line)
373 6 pfleura2
374 6 pfleura2
       IMPLICIT NONE
375 6 pfleura2
      CHARACTER(5) :: Type
376 6 pfleura2
      CHARACTER(120) :: LINE
377 6 pfleura2
      INTEGER(4) ::  i,IOIN
378 6 pfleura2
      READ(IOIN,'(A120)',ERR=999,END=999) LINE
379 6 pfleura2
!      WRITE(*,*) Line
380 6 pfleura2
      DO WHILE (LINE(1:1).eq.' ')
381 6 pfleura2
         LINE=LINE(2:)
382 6 pfleura2
      END DO
383 6 pfleura2
384 6 pfleura2
      i=1
385 6 pfleura2
      DO WHILE (LINE(i:i).ne.' ')
386 6 pfleura2
         i=i+1
387 6 pfleura2
      END DO
388 6 pfleura2
389 6 pfleura2
      if (i.ge.6) THEN
390 6 pfleura2
         WRITE(*,*) 'Pb with READLINE:',LINE
391 6 pfleura2
         GOTO 999
392 6 pfleura2
      END IF
393 6 pfleura2
      Type=LINE(1:i-1)
394 6 pfleura2
      LINE=LINE(i:120) // " 0 0 0 0"
395 6 pfleura2
396 6 pfleura2
      RETURN
397 6 pfleura2
 999  Type="E"
398 6 pfleura2
    END SUBROUTINE READLINE
399 6 pfleura2
400 6 pfleura2
401 6 pfleura2
402 6 pfleura2
      SUBROUTINE Analyse(geos)
403 6 pfleura2
404 6 pfleura2
      IMPLICIT NONE
405 6 pfleura2
      INTEGER(4),PARAMETER  :: MaxNat=10000,MaxList=100
406 6 pfleura2
407 6 pfleura2
      REAL(8) :: geos(3,maxnat)
408 6 pfleura2
      REAL(8) :: AU2PS,Pi
409 6 pfleura2
      INTEGER(4) :: i,j,k
410 6 pfleura2
      REAL(8) :: V1x,V1y,V1z,V2x,V2y,V2z,V3x,V3y,V3z
411 6 pfleura2
      REAL(8) :: d1,d2,ca,sa
412 6 pfleura2
      REAL(8) :: V4x,v4y,v4z,v5x,v5y,v5z
413 6 pfleura2
      REAL(8) :: COG(3)
414 6 pfleura2
415 6 pfleura2
          INTEGER(4) :: Nat,NbDist, NbAngle, NbDie,NbP,NbCOM
416 6 pfleura2
          INTEGER(4) :: At1B(MaxList),At2B(MaxList)
417 6 pfleura2
          INTEGER(4) :: At1A(MaxList),At2A(MaxList),At3A(MaxList)
418 6 pfleura2
          INTEGER(4) :: At1D(MaxList),At2D(MaxList),At3D(MaxList), &
419 6 pfleura2
                   At4D(MaxList)
420 6 pfleura2
          INTEGER(4) :: At1p(MaxList),At2p(MaxList),At3p(MaxList), &
421 6 pfleura2
                   At4p(MaxList),At5p(MaxList),At6p(MaxList)
422 6 pfleura2
          INTEGER(4) :: AtCom(0:MaxList,MaxList)
423 6 pfleura2
          REAL(8) ::    VB(MaxList),VA(MaxList),VD(MaxList),VCOM(MaxList)
424 6 pfleura2
          REAL(8) ::    Vp(MaxList)
425 6 pfleura2
426 6 pfleura2
          LOGICAL :: Debug=.FALSE.
427 6 pfleura2
428 6 pfleura2
          COMMON /Indices/Nat,NbDist,NbAngle,NbDie,NbP,NbCom, At1B,At2B, &
429 6 pfleura2
              At1A,At2A,At3A,At1D,At2D,At3D,At4D,AtCom, &
430 6 pfleura2
              At1p,At2p,At3p,At4p,At5p,At6p
431 6 pfleura2
          COMMON /Values/VB,VA,VD,Vp,VCom
432 6 pfleura2
          COMMON /Const/AU2ps,Pi
433 6 pfleura2
434 6 pfleura2
          if (Debug) THEN
435 6 pfleura2
             DO I=1,Nat
436 6 pfleura2
                WRITE(*,'(1X,I3,3(1X,F15.6))') i,(geos(j,i),j=1,3)
437 6 pfleura2
             END DO
438 6 pfleura2
          END IF
439 6 pfleura2
! First, we create the Centre of Mass atoms
440 6 pfleura2
          DO i=1,NbCOM
441 6 pfleura2
             COG(1)=0.
442 6 pfleura2
             COG(2)=0.
443 6 pfleura2
             COG(3)=0.
444 6 pfleura2
             DO j=1,AtCOm(0,i)
445 6 pfleura2
                DO k=1,3
446 6 pfleura2
                   COG(k)=COG(k)+geos(k,AtCom(j,i))
447 6 pfleura2
                 END DO
448 6 pfleura2
                 DO k=1,3
449 6 pfleura2
                   COG(k)=COG(k)/AtCOM(0,i)
450 6 pfleura2
                   geos(k,Nat+i)=COG(k)
451 6 pfleura2
                END DO
452 6 pfleura2
             END DO
453 6 pfleura2
          END DO
454 6 pfleura2
455 6 pfleura2
            DO i=1,NbDist
456 6 pfleura2
               VB(i)=sqrt((geos(1,At1B(i))-geos(1,At2B(i)))**2+   &
457 6 pfleura2
           (geos(2,At1B(i))-geos(2,At2B(i)))**2+                      &
458 6 pfleura2
           (geos(3,At1B(i))-geos(3,At2B(i)))**2)
459 6 pfleura2
            END DO
460 6 pfleura2
            DO i=1,NbAngle
461 6 pfleura2
               v1x=geos(1,At1A(i))-geos(1,At2A(i))
462 6 pfleura2
               v1y=geos(2,At1A(i))-geos(2,At2A(i))
463 6 pfleura2
               v1z=geos(3,At1A(i))-geos(3,At2A(i))
464 6 pfleura2
               d1=sqrt(v1x**2+v1y**2+v1z**2)
465 6 pfleura2
               v2x=geos(1,At3A(i))-geos(1,At2A(i))
466 6 pfleura2
               v2y=geos(2,At3A(i))-geos(2,At2A(i))
467 6 pfleura2
               v2z=geos(3,At3A(i))-geos(3,At2A(i))
468 6 pfleura2
               d2=sqrt(v2x**2+v2y**2+v2z**2)
469 6 pfleura2
               VA(i)=acos((v1x*v2x+v1y*v2y+v1z*v2z)/(d1*d2))*180./Pi
470 6 pfleura2
            END DO
471 6 pfleura2
            DO i=1,NbDie
472 6 pfleura2
!               WRITE(*,*) At1D(i),At2D(i),At3D(i),At4D(i)
473 6 pfleura2
!              WRITE(*,*) geos(1,At1D(i)),geos(2,At1D(i)),geos(3,At1D(i))
474 6 pfleura2
!              WRITE(*,*) geos(1,At2D(i)),geos(2,At2D(i)),geos(3,At2D(i))
475 6 pfleura2
               v1x=geos(1,At1D(i))-geos(1,At2D(i))
476 6 pfleura2
               v1y=geos(2,At1D(i))-geos(2,At2D(i))
477 6 pfleura2
               v1z=geos(3,At1D(i))-geos(3,At2D(i))
478 6 pfleura2
               v2x=geos(1,At3D(i))-geos(1,At2D(i))
479 6 pfleura2
               v2y=geos(2,At3D(i))-geos(2,At2D(i))
480 6 pfleura2
               v2z=geos(3,At3D(i))-geos(3,At2D(i))
481 6 pfleura2
               v3x=geos(1,At4D(i))-geos(1,At3D(i))
482 6 pfleura2
               v3y=geos(2,At4D(i))-geos(2,At3D(i))
483 6 pfleura2
               v3z=geos(3,At4D(i))-geos(3,At3D(i))
484 6 pfleura2
485 6 pfleura2
               v4x=v1y*v2z-v1z*v2y
486 6 pfleura2
               v4y=v1z*v2x-v1x*v2z
487 6 pfleura2
               v4z=v1x*v2y-v1y*v2x
488 6 pfleura2
               d1=sqrt(v4x**2+v4y**2+v4z**2)
489 6 pfleura2
               v5x=-v2y*v3z+v2z*v3y
490 6 pfleura2
               v5y=-v2z*v3x+v2x*v3z
491 6 pfleura2
               v5z=-v2x*v3y+v2y*v3x
492 6 pfleura2
               d2=sqrt(v5x**2+v5y**2+v5z**2)
493 6 pfleura2
               if (d1<=1e-12) THEN
494 6 pfleura2
                  WRITE(*,*) "WARNING: Dihedral, d1=0"
495 6 pfleura2
                  ca=-1.
496 6 pfleura2
                  sa=0.
497 6 pfleura2
               END IF
498 6 pfleura2
               if (d2<=1e-12) THEN
499 6 pfleura2
                  WRITE(*,*) "WARNING: Dihedral, d2=0"
500 6 pfleura2
                  ca=-1.
501 6 pfleura2
                  sa=0.
502 6 pfleura2
               END IF
503 6 pfleura2
               ca=(v4x*v5x+v4y*v5y+v4z*v5z)/(d1*d2)
504 6 pfleura2
               sa=v1x*v5x+v1y*v5y+v1z*v5z
505 6 pfleura2
               if (abs(ca)>1.) ca=sign(1.d0,ca)
506 6 pfleura2
               VD(i)=acos(ca)*180./Pi
507 6 pfleura2
               if (sa<0.) VD(i)=-VD(i)
508 6 pfleura2
!               WRITE(*,*) "Dihe",v5x,v5y,v5z,v4x,v4y,v4z,d1,d2,
509 6 pfleura2
!     &(v4x*v5x+v4y*v5y+v4z*v5z)/(d1*d2),pi
510 6 pfleura2
!                WRITE(*,*) "Dihe ca,sa,d1,d2",ca,sa,d1,d2,acos(ca)
511 6 pfleura2
512 6 pfleura2
513 6 pfleura2
!!!!!!!!! Another solution, more elegant ?
514 6 pfleura2
!               norm2=sqrt(v2x**2+v2y**2+v2z**2)
515 6 pfleura2
!               sa=(v4x*(v5y*v2z-v5z*v2y)
516 6 pfleura2
!     *            -v4y*(v5x*v2z-v5z*v2x)
517 6 pfleura2
!     *            +v4z*(v5x*v2y-v5y*v2x))
518 6 pfleura2
!     *       /(d1*norm2*d2)
519 6 pfleura2
!               angle_d=datan2(sa,ca)*180./Pi
520 6 pfleura2
!               WRITE(*,*) sa,ca,angle_d,d1,d2,norm2
521 6 pfleura2
!               WRITE(*,*) VD(i),angle_d
522 6 pfleura2
            END DO
523 6 pfleura2
524 6 pfleura2
            DO i=1,NbP
525 6 pfleura2
! v1= At2-At1
526 6 pfleura2
               v1x=geos(1,At1p(i))-geos(1,At2p(i))
527 6 pfleura2
               v1y=geos(2,At1p(i))-geos(2,At2p(i))
528 6 pfleura2
               v1z=geos(3,At1p(i))-geos(3,At2p(i))
529 6 pfleura2
! v2=At2-At3
530 6 pfleura2
               v2x=geos(1,At3p(i))-geos(1,At2p(i))
531 6 pfleura2
               v2y=geos(2,At3p(i))-geos(2,At2p(i))
532 6 pfleura2
               v2z=geos(3,At3p(i))-geos(3,At2p(i))
533 6 pfleura2
! v4 = v1 x v2
534 6 pfleura2
               v4x=v1y*v2z-v1z*v2y
535 6 pfleura2
               v4y=v1z*v2x-v1x*v2z
536 6 pfleura2
               v4z=v1x*v2y-v1y*v2x
537 6 pfleura2
               d1=sqrt(v4x**2+v4y**2+v4z**2)
538 6 pfleura2
539 6 pfleura2
! v3= At5-At4
540 6 pfleura2
               v3x=geos(1,At4p(i))-geos(1,At5p(i))
541 6 pfleura2
               v3y=geos(2,At4p(i))-geos(2,At5p(i))
542 6 pfleura2
               v3z=geos(3,At4p(i))-geos(3,At5p(i))
543 6 pfleura2
! v2=At5-At6
544 6 pfleura2
               v2x=geos(1,At6p(i))-geos(1,At5p(i))
545 6 pfleura2
               v2y=geos(2,At6p(i))-geos(2,At5p(i))
546 6 pfleura2
               v2z=geos(3,At6p(i))-geos(3,At5p(i))
547 6 pfleura2
548 6 pfleura2
! v5 = v3 x v2
549 6 pfleura2
               v5x=v3y*v2z-v3z*v2y
550 6 pfleura2
               v5y=v3z*v2x-v3x*v2z
551 6 pfleura2
               v5z=v3x*v2y-v3y*v2x
552 6 pfleura2
               d2=sqrt(v5x**2+v5y**2+v5z**2)
553 6 pfleura2
554 6 pfleura2
               ca=(v4x*v5x+v4y*v5y+v4z*v5z)/(d1*d2)
555 6 pfleura2
               sa=v1x*v5x+v1y*v5y+v1z*v5z
556 6 pfleura2
               Vp(i)=acos(ca)*180./Pi
557 6 pfleura2
               if (sa<0.) Vp(i)=-Vp(i)
558 6 pfleura2
!               WRITE(*,*) "Dihe",v5x,v5y,v5z,v4x,v4y,v4z,d1,d2,
559 6 pfleura2
!     &(v4x*v5x+v4y*v5y+v4z*v5z)/(d1*d2),pi
560 6 pfleura2
!!!!!!!!! Another solution, more elegant ?
561 6 pfleura2
! See Dihedral routine
562 6 pfleura2
            END DO
563 6 pfleura2
564 6 pfleura2
565 6 pfleura2
          END SUBROUTINE Analyse