Adam's changes
[unres.git] / source / unres / src-HCD-5D / contact_cp2.F
1       subroutine contact_cp2(var,var2,iff,ieval,in_pdb)
2       implicit real*8 (a-h,o-z)
3       include 'DIMENSIONS'
4 #ifdef MPI
5       include 'mpif.h'
6 #endif
7       include 'COMMON.SBRIDGE'
8       include 'COMMON.FFIELD'
9       include 'COMMON.IOUNITS'
10       include 'COMMON.DISTFIT'
11       include 'COMMON.VAR'
12       include 'COMMON.CHAIN'
13       include 'COMMON.MINIM'
14
15       character*50 linia
16       integer nf,ij(4)
17       double precision var(maxvar),var2(maxvar)
18       double precision time0,time1
19       integer iff(maxres),ieval      
20       double precision theta1(maxres),phi1(maxres),alph1(maxres),     
21      &                 omeg1(maxres)                             
22       
23
24        call var_to_geom(nvar,var)
25        call chainbuild                                                           
26        nhpb0=nhpb
27        ind=0                                                                     
28        do i=1,nres-3                                                             
29          do j=i+3,nres                                                           
30           ind=ind+1                                                              
31           if ( iff(i).eq.1.and.iff(j).eq.1 ) then                                           
32             d0(ind)=DIST(i,j)                                                     
33             w(ind)=10.0                                                           
34             nhpb=nhpb+1                                                           
35             ihpb(nhpb)=i                                                          
36             jhpb(nhpb)=j                                                          
37             forcon(nhpb)=10.0                                                     
38             dhpb(nhpb)=d0(ind)                                                    
39           else
40             w(ind)=0.0
41           endif                                                                  
42          enddo                                                                   
43        enddo                                    
44        call hpb_partition
45
46        do i=1,nres                                                               
47         theta1(i)=theta(i)                                                      
48         phi1(i)=phi(i)                                                          
49         alph1(i)=alph(i)                                                        
50         omeg1(i)=omeg(i)                                                        
51        enddo                      
52
53        call var_to_geom(nvar,var2)
54
55        do i=1,nres                                                             
56           if ( iff(i).eq.1 ) then                                           
57               theta(i)=theta1(i)                                                      
58               phi(i)=phi1(i)                                                          
59               alph(i)=alph1(i)                                                        
60               omeg(i)=omeg1(i)                       
61           endif
62        enddo
63
64        call chainbuild
65 cd       call write_pdb(3,'combined structure',0d0)
66 cd       time0=MPI_WTIME()
67        
68        NX=NRES-3                                                                 
69        NY=((NRES-4)*(NRES-5))/2 
70        call distfit(.true.,200)
71    
72 cd       time1=MPI_WTIME()
73 cd       write (iout,'(a,f6.2,a)') ' Time for distfit ',time1-time0,' sec'
74
75        ipot0=ipot
76        maxmin0=maxmin
77        maxfun0=maxfun
78        wstrain0=wstrain
79
80        ipot=6
81        maxmin=2000
82        maxfun=5000
83        call geom_to_var(nvar,var)
84 cd       time0=MPI_WTIME()
85        call minimize(etot,var,iretcode,nfun)                               
86        write(iout,*)'SUMSL return code is',iretcode,' eval SOFT',nfun   
87
88 cd       time1=MPI_WTIME()
89 cd       write (iout,'(a,f6.2,f8.2,a)')' Time for soft min.',time1-time0,
90 cd     &         nfun/(time1-time0),' SOFT eval/s'
91         call var_to_geom(nvar,var)
92         call chainbuild
93
94
95         iwsk=0
96         nf=0
97         if (iff(1).eq.1) then
98           iwsk=1
99           nf=nf+1
100           ij(nf)=0
101         endif
102         do i=2,nres
103            if ( iwsk.eq.0.and.iff(i-1).eq.0.and.iff(i).eq.1 ) then
104              iwsk=1
105              nf=nf+1
106              ij(nf)=i
107            endif
108            if ( iwsk.eq.1.and.iff(i-1).eq.1.and.iff(i).eq.0 ) then
109              iwsk=0
110              nf=nf+1
111              ij(nf)=i-1
112            endif
113         enddo
114         if (iff(nres).eq.1) then
115           nf=nf+1
116           ij(nf)=nres
117         endif
118
119
120 cd        write(linia,'(a6,i3,a1,i3,a1,i3,a1,i3)')
121 cd     &                     "select",ij(1),"-",ij(2),
122 cd     &                         ",",ij(3),"-",ij(4)
123 cd        call write_pdb(in_pdb,linia,etot)
124
125
126        ipot=ipot0
127        maxmin=maxmin0
128        maxfun=maxfun0
129 cd       time0=MPI_WTIME()
130        call minimize(etot,var,iretcode,nfun)
131 cd       write(iout,*)'SUMSL DIST return code is',iretcode,' eval ',nfun
132        ieval=nfun
133
134 cd       time1=MPI_WTIME()
135 cd       write (iout,'(a,f6.2,f8.2,a)')' Time for DIST min.',time1-time0,
136 cd     &         nfun/(time1-time0),' eval/s'
137 cd       call var_to_geom(nvar,var)
138 cd       call chainbuild
139 cd       call write_pdb(6,'dist structure',etot)
140
141
142        nhpb= nhpb0                                                                  
143        link_start=1                                                            
144        link_end=nhpb     
145        wstrain=wstrain0
146
147        return
148        end