first changes for shielding
[unres.git] / source / unres / src_MD-M / refsys.f
1       subroutine refsys(i2,i3,i4,e1,e2,e3,fail)
2 c This subroutine calculates unit vectors of a local reference system
3 c defined by atoms (i2), (i3), and (i4). The x axis is the axis from
4 c atom (i3) to atom (i2), and the xy plane is the plane defined by atoms
5 c (i2), (i3), and (i4). z axis is directed according to the sign of the
6 c vector product (i3)-(i2) and (i3)-(i4). Sets fail to .true. if atoms
7 c (i2) and (i3) or (i3) and (i4) coincide or atoms (i2), (i3), and (i4)
8 c form a linear fragment. Returns vectors e1, e2, and e3.
9       implicit real*8 (a-h,o-z)
10       include 'DIMENSIONS'
11       logical fail
12       double precision e1(3),e2(3),e3(3)
13       double precision u(3),z(3)
14       include 'COMMON.IOUNITS'
15       include 'COMMON.CHAIN'
16       double precision coinc/1.0D-13/,align /1.0D-13/
17 c      print *,'just initialize'
18       fail=.false.
19 c      print *,fail
20       s1=0.0
21       s2=0.0
22       print *,s1,s2
23       do 1 i=1,3
24       print *, i2,i3,i4
25       zi=c(i,i2)-c(i,i3)
26       ui=c(i,i4)-c(i,i3)
27       print *,zi,ui
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 c     do 3 i=1,3
38 c   3 c(i,i1)=0.0D0
39       return
40     2 if (s2.gt.coinc) goto 4
41       write(iout,1000) i3,i4,i1
42       fail=.true.
43       do 5 i=1,3
44     5 c(i,i1)=0.0D0
45       return
46       print *,'two if pass'
47     4 s1=1.0/s1
48       s2=1.0/s2
49       v1=z(2)*u(3)-z(3)*u(2)
50       v2=z(3)*u(1)-z(1)*u(3)
51       v3=z(1)*u(2)-z(2)*u(1)
52       anorm=dsqrt(v1*v1+v2*v2+v3*v3)
53       if (anorm.gt.align) goto 6
54       write (iout,1010) i2,i3,i4,i1
55       fail=.true.
56 c     do 7 i=1,3
57 c   7 c(i,i1)=0.0D0
58       return
59     6 anorm=1.0D0/anorm
60       e3(1)=v1*anorm
61       e3(2)=v2*anorm
62       e3(3)=v3*anorm
63       e1(1)=z(1)*s1
64       e1(2)=z(2)*s1
65       e1(3)=z(3)*s1
66       e2(1)=e1(3)*e3(2)-e1(2)*e3(3)
67       e2(2)=e1(1)*e3(3)-e1(3)*e3(1)
68       e2(3)=e1(2)*e3(1)-e1(1)*e3(2)
69       print *,'just before leave'
70  1000 format (/1x,' * * * Error - atoms',i4,' and',i4,' coincide.',
71      1 'coordinates of atom',i4,' are set to zero.')
72  1010 format (/1x,' * * * Error - atoms',2(i4,2h, ),i4,' form a linear',
73      1 ' fragment. coordinates of atom',i4,' are set to zero.')
74       return
75       end