update new files
[unres.git] / source / maxlik / src_MD_T_maxlik-NEWCORR / cont_frag.f
1       subroutine contacts_between_fragments(lprint,is,ncont,icont,
2      &   ncont_interfrag,icont_interfrag,mask_res,ib,iprot)
3       implicit none
4       include 'DIMENSIONS'
5       include 'DIMENSIONS.ZSCOPT'
6       include 'DIMENSIONS.COMPAR'
7       include 'COMMON.INTERACT'
8       include 'COMMON.COMPAR'
9       include 'COMMON.IOUNITS'
10       include 'COMMON.CHAIN'
11       include 'COMMON.NAMES'
12       integer icont(2,maxcont),ncont_interfrag(mmaxfrag),
13      &  icont_interfrag(2,maxcont,mmaxfrag),mask_res(nres)
14       integer i,j,k,l,i1,i2,it1,it2,ic1,ic2,iprot,ind,nc,is,ncont,
15      &  icant,ib
16       logical OK1,OK2,lprint
17 c Determine the contacts that occur within a fragment and between fragments.
18       do i=1,nfrag(1,iprot)
19         do j=1,i
20           ind = icant(i,j)
21           nc=0
22 c          write (iout,*) "i",i,(ifrag(1,k,i,ib,iprot),
23 c            ifrag(2,k,i,ib,iprot)
24 c     &      ,k=1,npiece(i,1,ib,iprot))
25 c          write (iout,*) "j",j,(ifrag(1,k,j,ib,iprot),
26 c            ifrag(2,k,j,ib,iprot)
27 c     &      ,k=1,npiece(j,1,ib,iprot))
28 c          write (iout,*) "ncont",ncont
29           do k=1,ncont
30             ic1=icont(1,k)
31             ic2=icont(2,k)
32
33             if (mask_res(ic1)*mask_res(ic2).gt.0) then
34
35             OK1=.false.
36             l=0
37             do while (.not.OK1 .and. l.lt.npiece(j,1,ib,iprot)) 
38               l=l+1
39               OK1=ic1.ge.ifrag(1,l,j,ib,iprot)-is .and. 
40      &         ic1.le.ifrag(2,l,j,ib,iprot)+is
41             enddo
42             OK2=.false.
43             l=0
44             do while (.not.OK2 .and. l.lt.npiece(i,1,ib,iprot)) 
45               l=l+1
46               OK2=ic2.ge.ifrag(1,l,i,ib,iprot)-is .and. 
47      &         ic2.le.ifrag(2,l,i,ib,iprot)+is
48             enddo 
49 c            write(iout,*) "k",k," ic1",ic1," ic2",ic2," OK1",OK1,
50 c     &        " OK2",OK2
51             if (OK1.and.OK2) then
52               nc=nc+1
53               icont_interfrag(1,nc,ind)=ic1 
54               icont_interfrag(2,nc,ind)=ic2 
55 c              write (iout,*) "nc",nc," ic1",ic1," ic2",ic2
56             endif
57
58             endif
59
60           enddo
61           ncont_interfrag(ind)=nc
62 c          do k=1,ncont_interfrag(ind)
63 c              i1=icont_interfrag(1,k,ind)
64 c              i2=icont_interfrag(2,k,ind)
65 c              it1=itype(i1)
66 c              it2=itype(i2)
67 c              write (iout,'(i3,2x,a,i4,2x,a,i4)')
68 c     &          i,restyp(it1),i1,restyp(it2),i2
69 c          enddo
70         enddo
71       enddo
72       if (lprint) then
73         write (iout,*) "Contacts within fragments:"
74         do i=1,nfrag(1,iprot)
75           write (iout,*) "Fragment",i," (",(ifrag(1,k,i,ib,iprot),
76      &     ifrag(2,k,i,ib,iprot),k=1,npiece(i,1,ib,iprot)),")"
77           ind=icant(i,i)
78           do k=1,ncont_interfrag(ind)
79             i1=icont_interfrag(1,k,ind)
80             i2=icont_interfrag(2,k,ind)
81             it1=itype(i1)
82             it2=itype(i2)
83             write (iout,'(i3,2x,a,i4,2x,a,i4)')
84      &        i,restyp(it1),i1,restyp(it2),i2
85           enddo
86         enddo
87         write (iout,*)
88         write (iout,*) "Contacts between fragments:"
89         do i=1,nfrag(1,iprot)
90         do j=1,i-1
91           ind = icant(i,j)
92           write (iout,*) "Fragments",i," (",(ifrag(1,k,i,ib,iprot),
93      &     ifrag(2,k,i,ib,iprot),k=1,npiece(i,1,ib,iprot)),") and",j,
94      &     " (",(ifrag(1,k,j,ib,iprot),ifrag(2,k,j,ib,iprot),
95      &     k=1,npiece(j,1,ib,iprot)),")"
96           write (iout,*) "Number of contacts",
97      &     ncont_interfrag(ind)
98           ind=icant(i,j)
99           do k=1,ncont_interfrag(ind)
100             i1=icont_interfrag(1,k,ind)
101             i2=icont_interfrag(2,k,ind)
102             it1=itype(i1)
103             it2=itype(i2)
104             write (iout,'(i3,2x,a,i4,2x,a,i4)')
105      &        i,restyp(it1),i1,restyp(it2),i2
106           enddo
107         enddo
108         enddo
109       endif
110       return
111       end