1 subroutine sc_move(n_start,n_end,n_maxtry,e_drop,
3 c Perform a quick search over side-chain arrangments (over
4 c residues n_start to n_end) for a given (frozen) CA trace
5 c Only side-chains are minimized (at most n_maxtry times each),
7 c Stops if energy drops by e_drop, otherwise tries all residues
9 c If there is an energy drop, full minimization may be useful
10 c n_start, n_end CAN be modified by this routine, but only if
11 c out of bounds (n_start <= 1, n_end >= nres, n_start < n_end)
12 c NOTE: this move should never increase the energy
16 implicit real*8 (a-h,o-z)
21 include 'COMMON.HEADER'
22 include 'COMMON.IOUNITS'
23 include 'COMMON.CHAIN'
24 include 'COMMON.FFIELD'
31 integer n_start,n_end,n_maxtry
32 double precision e_drop
39 double precision energy(0:n_ene)
40 double precision cur_alph(2:nres-1),cur_omeg(2:nres-1)
41 double precision orig_e,cur_e
42 integer n,n_steps,n_first,n_cur,n_tot,i
43 double precision orig_w(n_ene)
44 double precision wtime
47 c Set non side-chain weights to zero (minimization is faster)
48 c NOTE: e(2) does not actually depend on the side-chain, only CA
77 c Make sure n_start, n_end are within proper range
78 if (n_start.lt.2) n_start=2
79 if (n_end.gt.nres-1) n_end=nres-1
80 crc if (n_start.lt.n_end) then
81 if (n_start.gt.n_end) then
86 c Save the initial values of energy and coordinates
88 cd call etotal(energy)
89 cd write (iout,*) 'start sc ene',energy(0)
90 cd call enerprint(energy(0))
96 crc cur_alph(i)=alph(i)
97 crc cur_omeg(i)=omeg(i)
101 c Try (one by one) all specified residues, starting from a
102 c random position in sequence
103 c Stop early if the energy has decreased by at least e_drop
104 n_tot=n_end-n_start+1
105 n_first=iran_num(0,n_tot-1)
108 crc do while (n.lt.n_tot .and. orig_e-etot.lt.e_drop)
109 do while (n.lt.n_tot)
110 n_cur=n_start+mod(n_first+n,n_tot)
111 call single_sc_move(n_cur,n_maxtry,e_drop,
112 + n_steps,n_fun,etot)
113 c If a lower energy was found, update the current structure...
114 crc if (etot.lt.cur_e) then
117 crc cur_alph(i)=alph(i)
118 crc cur_omeg(i)=omeg(i)
121 c ...else revert to the previous one
124 crc alph(i)=cur_alph(i)
125 crc omeg(i)=cur_omeg(i)
131 cd call etotal(energy)
132 cd print *,'running',n,energy(0)
136 cd call etotal(energy)
137 cd write (iout,*) 'end sc ene',energy(0)
139 c Put the original weights back to calculate the full energy
155 ct write (iout,*) 'sc_local time= ',MPI_WTIME()-wtime
159 c-------------------------------------------------------------
161 subroutine single_sc_move(res_pick,n_maxtry,e_drop,
162 + n_steps,n_fun,e_sc)
163 c Perturb one side-chain (res_pick) and minimize the
164 c neighbouring region, keeping all CA's and non-neighbouring
166 c Try until e_drop energy improvement is achieved, or n_maxtry
167 c attempts have been made
168 c At the start, e_sc should contain the side-chain-only energy(0)
169 c nsteps and nfun for this move are ADDED to n_steps and n_fun
173 implicit real*8 (a-h,o-z)
176 include 'COMMON.INTERACT'
177 include 'COMMON.CHAIN'
178 include 'COMMON.MINIM'
179 include 'COMMON.FFIELD'
180 include 'COMMON.IOUNITS'
183 double precision dist
187 integer res_pick,n_maxtry
188 double precision e_drop
190 c Input/Output arguments
191 integer n_steps,n_fun
192 double precision e_sc
198 integer iretcode,loc_nfun,orig_maxfun,n_try
199 double precision sc_dist,sc_dist_cutoff
200 double precision energy(0:n_ene),orig_e,cur_e
201 double precision evdw,escloc
202 double precision cur_alph(2:nres-1),cur_omeg(2:nres-1)
203 double precision var(maxvar)
205 double precision orig_theta(1:nres),orig_phi(1:nres),
206 + orig_alph(1:nres),orig_omeg(1:nres)
209 c Define what is meant by "neighbouring side-chain"
212 c Don't do glycine or ends
214 if (i.eq.10 .or. i.eq.21) return
216 c Freeze everything (later will relax only selected side-chains)
224 c Find the neighbours of the side-chain to move
225 c and save initial variables
230 c Don't do glycine (itype(j)==10)
231 if (itype(i).ne.10) then
232 sc_dist=dist(nres+i,nres+res_pick)
234 sc_dist=sc_dist_cutoff
236 if (sc_dist.lt.sc_dist_cutoff) then
237 nres_moved=nres_moved+1
247 e_sc=wsc*evdw+wscloc*escloc
248 cd call etotal(energy)
249 cd print *,'new ',(energy(k),k=0,n_ene)
254 do while (n_try.lt.n_maxtry .and. orig_e-cur_e.lt.e_drop)
255 c Move the selected residue (don't worry if it fails)
256 call gen_side(itype(res_pick),theta(res_pick+1),
257 + alph(res_pick),omeg(res_pick),fail)
259 c Minimize the side-chains starting from the new arrangement
260 call geom_to_var(nvar,var)
265 crc orig_theta(i)=theta(i)
266 crc orig_phi(i)=phi(i)
267 crc orig_alph(i)=alph(i)
268 crc orig_omeg(i)=omeg(i)
271 call minimize_sc1(e_sc,var,iretcode,loc_nfun)
273 cv write(*,'(2i3,2f12.5,2i3)')
274 cv & res_pick,nres_moved,orig_e,e_sc-cur_e,
275 cv & iretcode,loc_nfun
277 c$$$ if (iretcode.eq.8) then
278 c$$$ write(iout,*)'Coordinates just after code 8'
281 c$$$ call flush(iout)
283 c$$$ theta(i)=orig_theta(i)
284 c$$$ phi(i)=orig_phi(i)
285 c$$$ alph(i)=orig_alph(i)
286 c$$$ omeg(i)=orig_omeg(i)
288 c$$$ write(iout,*)'Coordinates just before code 8'
291 c$$$ call flush(iout)
296 call var_to_geom(nvar,var)
298 c If a lower energy was found, update the current structure...
299 if (e_sc.lt.cur_e) then
301 cv call etotal(energy)
304 cd e_sc1=wsc*evdw+wscloc*escloc
305 cd print *,' new',e_sc1,energy(0)
306 cv print *,'new ',energy(0)
307 cd call enerprint(energy(0))
310 if (mask_side(i).eq.1) then
316 c ...else revert to the previous one
319 if (mask_side(i).eq.1) then
328 n_steps=n_steps+n_try
330 c Reset the minimization mask_r to false
336 c-------------------------------------------------------------
338 subroutine sc_minimize(etot,iretcode,nfun)
339 c Minimizes side-chains only, leaving backbone frozen
343 implicit real*8 (a-h,o-z)
346 include 'COMMON.CHAIN'
347 include 'COMMON.FFIELD'
350 double precision etot
351 integer iretcode,nfun
355 double precision orig_w(n_ene),energy(0:n_ene)
356 double precision var(maxvar)
359 c Set non side-chain weights to zero (minimization is faster)
360 c NOTE: e(2) does not actually depend on the side-chain, only CA
387 c Prepare to freeze backbone
394 c Minimize the side-chains
396 call geom_to_var(nvar,var)
397 call minimize(etot,var,iretcode,nfun)
398 call var_to_geom(nvar,var)
401 c Put the original weights back and calculate the full energy
422 c-------------------------------------------------------------
423 subroutine minimize_sc1(etot,x,iretcode,nfun)
424 implicit real*8 (a-h,o-z)
426 parameter (liv=60,lv=(77+maxvar*(maxvar+17)/2))
427 include 'COMMON.IOUNITS'
430 include 'COMMON.MINIM'
433 double precision minval,x(maxvar),d(maxvar),v(1:lv),xx(maxvar)
434 double precision energia(0:n_ene)
435 external func,gradient,fdum
436 external func_restr1,grad_restr1
437 logical not_done,change,reduce
438 common /przechowalnia/ v
440 call deflt(2,iv,liv,lv,v)
441 * 12 means fresh start, dont call deflt
443 * max num of fun calls
444 if (maxfun.eq.0) maxfun=500
446 * max num of iterations
447 if (maxmin.eq.0) maxmin=1000
451 * selects output unit
454 * 1 means to print out result
456 * 1 means to print out summary stats
458 * 1 means to print initial x and d
460 * min val for v(radfac) default is 0.1
462 * max val for v(radfac) default is 4.0
465 * check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)
466 * the sumsl default is 0.1
468 * false conv if (act fnctn decrease) .lt. v(34)
469 * the sumsl default is 100*machep
471 * absolute convergence
472 if (tolf.eq.0.0D0) tolf=1.0D-4
474 * relative convergence
475 if (rtolf.eq.0.0D0) rtolf=1.0D-4
477 * controls initial step size
479 * large vals of d correspond to small components of step
487 call x2xx(x,xx,nvar_restr)
488 call sumsl(nvar_restr,d,xx,func_restr1,grad_restr1,
489 & iv,liv,lv,v,idum,rdum,fdum)
492 call sumsl(nvar,d,x,func,gradient,iv,liv,lv,v,idum,rdum,fdum)
500 ************************************************************************
501 subroutine func_restr1(n,x,nf,f,uiparm,urparm,ufparm)
502 implicit real*8 (a-h,o-z)
504 include 'COMMON.DERIV'
505 include 'COMMON.IOUNITS'
507 include 'COMMON.FFIELD'
508 include 'COMMON.INTERACT'
509 include 'COMMON.TIME1'
511 double precision energia(0:n_ene),evdw,escloc
513 double precision ufparm,e1,e2
522 c Intercept NaNs in the coordinates, before calling etotal
528 if (x_sum.ne.x_sum) then
529 write(iout,*)" *** func_restr1 : Found NaN in coordinates"
536 call var_to_geom_restr(n,x)
539 cd write (iout,*) 'ETOTAL called from FUNC'
542 f=wsc*evdw+wscloc*escloc
543 cd call etotal(energia(0))
544 cd f=wsc*energia(1)+wscloc*energia(12)
545 cd print *,f,evdw,escloc,energia(0)
547 C Sum up the components of the Cartesian gradient.
551 gradx(j,i,icg)=wsc*gvdwx(j,i)
557 c-------------------------------------------------------
558 subroutine grad_restr1(n,x,nf,g,uiparm,urparm,ufparm)
559 implicit real*8 (a-h,o-z)
561 include 'COMMON.CHAIN'
562 include 'COMMON.DERIV'
564 include 'COMMON.INTERACT'
565 include 'COMMON.FFIELD'
566 include 'COMMON.IOUNITS'
569 double precision urparm(1)
570 dimension x(maxvar),g(maxvar)
573 if (nf-nfl+1) 20,30,40
574 20 call func_restr1(n,x,nf,f,uiparm,urparm,ufparm)
575 c write (iout,*) 'grad 20'
578 30 call var_to_geom_restr(n,x)
581 C Evaluate the derivatives of virtual bond lengths and SC vectors in variables.
585 C Convert the Cartesian gradient into internal-coordinate gradient.
591 IF (mask_phi(i+2).eq.1) THEN
596 gphii=gphii+dcdv(k+3,ind)*gradc(k,j,icg)
597 gphii=gphii+dxdv(k+3,ind)*gradx(k,j,icg)
610 IF (mask_theta(i+2).eq.1) THEN
616 gthetai=gthetai+dcdv(k,ind)*gradc(k,j,icg)
617 gthetai=gthetai+dxdv(k,ind)*gradx(k,j,icg)
627 if (itype(i).ne.10) then
628 IF (mask_side(i).eq.1) THEN
632 galphai=galphai+dxds(k,i)*gradx(k,i,icg)
641 if (itype(i).ne.10) then
642 IF (mask_side(i).eq.1) THEN
646 gomegai=gomegai+dxds(k+3,i)*gradx(k,i,icg)
654 C Add the components corresponding to local energy terms.
661 if (mask_phi(i).eq.1) then
663 g(ig)=g(ig)+gloc(igall,icg)
669 if (mask_theta(i).eq.1) then
671 g(ig)=g(ig)+gloc(igall,icg)
677 if (itype(i).ne.10) then
679 if (mask_side(i).eq.1) then
681 g(ig)=g(ig)+gloc(igall,icg)
688 cd write (iout,'(a2,i5,a3,f25.8)') 'i=',i,' g=',g(i)
692 C-----------------------------------------------------------------------------
693 subroutine egb1(evdw)
695 C This subroutine calculates the interaction energy of nonbonded side chains
696 C assuming the Gay-Berne potential of interaction.
698 implicit real*8 (a-h,o-z)
702 include 'COMMON.LOCAL'
703 include 'COMMON.CHAIN'
704 include 'COMMON.DERIV'
705 include 'COMMON.NAMES'
706 include 'COMMON.INTERACT'
707 include 'COMMON.IOUNITS'
708 include 'COMMON.CALC'
709 include 'COMMON.CONTROL'
712 c print *,'Entering EGB nnt=',nnt,' nct=',nct,' expon=',expon
715 c if (icall.eq.0) lprn=.true.
725 dxi=dc_norm(1,nres+i)
726 dyi=dc_norm(2,nres+i)
727 dzi=dc_norm(3,nres+i)
728 dsci_inv=dsc_inv(itypi)
730 C Calculate SC interaction energy.
733 do j=istart(i,iint),iend(i,iint)
734 IF (mask_side(j).eq.1.or.mask_side(i).eq.1) THEN
737 dscj_inv=dsc_inv(itypj)
738 sig0ij=sigma(itypi,itypj)
739 chi1=chi(itypi,itypj)
740 chi2=chi(itypj,itypi)
747 alf12=0.5D0*(alf1+alf2)
748 C For diagnostics only!!!
761 dxj=dc_norm(1,nres+j)
762 dyj=dc_norm(2,nres+j)
763 dzj=dc_norm(3,nres+j)
764 rrij=1.0D0/(xj*xj+yj*yj+zj*zj)
766 C Calculate angle-dependent terms of energy and contributions to their
770 sig=sig0ij*dsqrt(sigsq)
771 rij_shift=1.0D0/rij-sig+sig0ij
772 C I hate to put IF's in the loops, but here don't have another choice!!!!
773 if (rij_shift.le.0.0D0) then
775 cd write (iout,'(2(a3,i3,2x),17(0pf7.3))')
776 cd & restyp(itypi),i,restyp(itypj),j,
777 cd & rij_shift,1.0D0/rij,sig,sig0ij,sigsq,1-dsqrt(sigsq)
781 c---------------------------------------------------------------
782 rij_shift=1.0D0/rij_shift
784 e1=fac*fac*aa(itypi,itypj)
785 e2=fac*bb(itypi,itypj)
786 evdwij=eps1*eps2rt*eps3rt*(e1+e2)
787 eps2der=evdwij*eps3rt
788 eps3der=evdwij*eps2rt
789 evdwij=evdwij*eps2rt*eps3rt
792 sigm=dabs(aa(itypi,itypj)/bb(itypi,itypj))**(1.0D0/6.0D0)
793 epsi=bb(itypi,itypj)**2/aa(itypi,itypj)
794 cd write (iout,'(2(a3,i3,2x),17(0pf7.3))')
795 cd & restyp(itypi),i,restyp(itypj),j,
796 cd & epsi,sigm,chi1,chi2,chip1,chip2,
797 cd & eps1,eps2rt**2,eps3rt**2,sig,sig0ij,
798 cd & om1,om2,om12,1.0D0/rij,1.0D0/rij_shift,
802 if (energy_dec) write (iout,'(a6,2i5,0pf7.3)')
805 C Calculate gradient components.
806 e1=e1*eps1*eps2rt**2*eps3rt**2
807 fac=-expon*(e1+evdwij)*rij_shift
810 C Calculate the radial part of the gradient
814 C Calculate angular part of the gradient.
821 C-----------------------------------------------------------------------------