Statistics
| Revision:

root / utils / Xyz2Scan.f @ 3

History | View | Annotate | Download (18.8 kB)

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