a6aa5e9c3fc67ece385f726c3e1f3d2f85a2baaf
[unres.git] / source / unres / src_MD-M / refsys.f
1       subroutine refsys(i2,i3,i4,e1,e2,e3,fail)
2 <<<<<<< HEAD
3       implicit real*8 (a-h,o-z)
4       include 'DIMENSIONS'
5 c this subroutine calculates unity vectors of a local reference system
6 c defined by atoms (i2), (i3), and (i4). the x axis is the axis from
7 =======
8 c This subroutine calculates unit vectors of a local reference system
9 c defined by atoms (i2), (i3), and (i4). The x axis is the axis from
10 >>>>>>> 9a082c1ab203120d8e865971546d473fb146fcdc
11 c atom (i3) to atom (i2), and the xy plane is the plane defined by atoms
12 c (i2), (i3), and (i4). z axis is directed according to the sign of the
13 c vector product (i3)-(i2) and (i3)-(i4). sets fail to .true. if atoms
14 c (i2) and (i3) or (i3) and (i4) coincide or atoms (i2), (i3), and (i4)
15 c form a linear fragment. returns vectors e1, e2, and e3.
16       logical fail
17       double precision e1(3),e2(3),e3(3)
18       double precision u(3),z(3)
19       include 'COMMON.IOUNITS'
20       include "COMMON.CHAIN"
21       data coinc /1.0d-13/,align /1.0d-13/
22       fail=.false.
23       s1=0.0d0
24       s2=0.0d0
25       do 1 i=1,3
26       zi=c(i,i2)-c(i,i3)
27       ui=c(i,i4)-c(i,i3)
28       s1=s1+zi*zi
29       s2=s2+ui*ui
30       z(i)=zi
31     1 u(i)=ui
32       s1=sqrt(s1)
33       s2=sqrt(s2)
34       if (s1.gt.coinc) goto 2
35       write (iout,1000) i2,i3,i1
36       fail=.true.
37       return
38     2 if (s2.gt.coinc) goto 4
39       write(iout,1000) i3,i4,i1
40       fail=.true.
41       return
42     4 s1=1.0/s1
43       s2=1.0/s2
44       v1=z(2)*u(3)-z(3)*u(2)
45       v2=z(3)*u(1)-z(1)*u(3)
46       v3=z(1)*u(2)-z(2)*u(1)
47       anorm=sqrt(v1*v1+v2*v2+v3*v3)
48       if (anorm.gt.align) goto 6
49       write (iout,1010) i2,i3,i4,i1
50       fail=.true.
51       return
52     6 anorm=1.0/anorm
53       e3(1)=v1*anorm
54       e3(2)=v2*anorm
55       e3(3)=v3*anorm
56       e1(1)=z(1)*s1
57       e1(2)=z(2)*s1
58       e1(3)=z(3)*s1
59       e2(1)=e1(3)*e3(2)-e1(2)*e3(3)
60       e2(2)=e1(1)*e3(3)-e1(3)*e3(1)
61       e2(3)=e1(2)*e3(1)-e1(1)*e3(2)
62  1000 format (/1x,' * * * error - atoms',i4,' and',i4,' coincide.')
63  1010 format (/1x,' * * * error - atoms',2(i4,2h, ),i4,' form a linear')
64       return
65       end