introduction of shielding effect (volume of overlap)
[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       implicit real*8 (a-h,o-z)
5       include 'DIMENSIONS'
6       include 'COMMON.IOUNITS'
7       include "COMMON.CHAIN"
8 c this subroutine calculates unity vectors of a local reference system
9 c defined by atoms (i2), (i3), and (i4). the x axis is the axis from
10 c atom (i3) to atom (i2), and the xy plane is the plane defined by atoms
11 c (i2), (i3), and (i4). z axis is directed according to the sign of the
12 c vector product (i3)-(i2) and (i3)-(i4). sets fail to .true. if atoms
13 c (i2) and (i3) or (i3) and (i4) coincide or atoms (i2), (i3), and (i4)
14 c form a linear fragment. returns vectors e1, e2, and e3.
15       logical fail
16       double precision e1(3),e2(3),e3(3)
17       double precision u(3),z(3)
18       double precision coinc/1.0D-13/,align /1.0D-13/
19 c      print *,'just initialize'
20       fail=.false.
21 c      print *,fail
22       s1=0.0
23       s2=0.0
24       print *,s1,s2
25       do 1 i=1,3
26       print *, i2,i3,i4
27       zi=c(i,i2)-c(i,i3)
28       ui=c(i,i4)-c(i,i3)
29       print *,zi,ui
30       s1=s1+zi*zi
31       s2=s2+ui*ui
32       z(i)=zi
33     1 u(i)=ui
34       s1=sqrt(s1)
35       s2=sqrt(s2)
36       if (s1.gt.coinc) goto 2
37       write (iout,1000) i2,i3,i1
38       fail=.true.
39       return
40     2 if (s2.gt.coinc) goto 4
41       write(iout,1000) i3,i4,i1
42       fail=.true.
43       return
44       print *,'two if pass'
45     4 s1=1.0/s1
46       s2=1.0/s2
47       v1=z(2)*u(3)-z(3)*u(2)
48       v2=z(3)*u(1)-z(1)*u(3)
49       v3=z(1)*u(2)-z(2)*u(1)
50       anorm=sqrt(v1*v1+v2*v2+v3*v3)
51       if (anorm.gt.align) goto 6
52       write (iout,1010) i2,i3,i4,i1
53       fail=.true.
54       return
55     6 anorm=1.0/anorm
56       e3(1)=v1*anorm
57       e3(2)=v2*anorm
58       e3(3)=v3*anorm
59       e1(1)=z(1)*s1
60       e1(2)=z(2)*s1
61       e1(3)=z(3)*s1
62       e2(1)=e1(3)*e3(2)-e1(2)*e3(3)
63       e2(2)=e1(1)*e3(3)-e1(3)*e3(1)
64       e2(3)=e1(2)*e3(1)-e1(1)*e3(2)
65  1000 format (/1x,' * * * Error - atoms',i4,' and',i4,' coincide.',
66      1 'coordinates of atom',i4,' are set to zero.')
67  1010 format (/1x,' * * * Error - atoms',2(i4,2h, ),i4,' form a linear',
68      1 ' fragment. coordinates of atom',i4,' are set to zero.')
69       return
70       end