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)
23 include 'COMMON.HEADER'
24 include 'COMMON.IOUNITS'
25 include 'COMMON.CHAIN'
26 include 'COMMON.FFIELD'
33 integer n_start,n_end,n_maxtry
34 double precision e_drop
41 double precision energy(0:n_ene)
42 double precision cur_alph(2:nres-1),cur_omeg(2:nres-1)
43 double precision orig_e,cur_e
44 integer n,n_steps,n_first,n_cur,n_tot,i
45 double precision orig_w(n_ene)
46 double precision wtime
49 c Set non side-chain weights to zero (minimization is faster)
50 c NOTE: e(2) does not actually depend on the side-chain, only CA
79 c Make sure n_start, n_end are within proper range
80 if (n_start.lt.2) n_start=2
81 if (n_end.gt.nres-1) n_end=nres-1
82 crc if (n_start.lt.n_end) then
83 if (n_start.gt.n_end) then
88 c Save the initial values of energy and coordinates
90 cd call etotal(energy)
91 cd write (iout,*) 'start sc ene',energy(0)
92 cd call enerprint(energy(0))
98 crc cur_alph(i)=alph(i)
99 crc cur_omeg(i)=omeg(i)
103 c Try (one by one) all specified residues, starting from a
104 c random position in sequence
105 c Stop early if the energy has decreased by at least e_drop
106 n_tot=n_end-n_start+1
107 n_first=iran_num(0,n_tot-1)
110 crc do while (n.lt.n_tot .and. orig_e-etot.lt.e_drop)
111 do while (n.lt.n_tot)
112 n_cur=n_start+mod(n_first+n,n_tot)
113 call single_sc_move(n_cur,n_maxtry,e_drop,
114 + n_steps,n_fun,etot)
115 c If a lower energy was found, update the current structure...
116 crc if (etot.lt.cur_e) then
119 crc cur_alph(i)=alph(i)
120 crc cur_omeg(i)=omeg(i)
123 c ...else revert to the previous one
126 crc alph(i)=cur_alph(i)
127 crc omeg(i)=cur_omeg(i)
133 cd call etotal(energy)
134 cd print *,'running',n,energy(0)
138 cd call etotal(energy)
139 cd write (iout,*) 'end sc ene',energy(0)
141 c Put the original weights back to calculate the full energy
158 ct write (iout,*) 'sc_local time= ',MPI_WTIME()-wtime
162 c-------------------------------------------------------------
164 subroutine single_sc_move(res_pick,n_maxtry,e_drop,
165 + n_steps,n_fun,e_sc)
166 c Perturb one side-chain (res_pick) and minimize the
167 c neighbouring region, keeping all CA's and non-neighbouring
169 c Try until e_drop energy improvement is achieved, or n_maxtry
170 c attempts have been made
171 c At the start, e_sc should contain the side-chain-only energy(0)
172 c nsteps and nfun for this move are ADDED to n_steps and n_fun
176 implicit real*8 (a-h,o-z)
179 include 'COMMON.INTERACT'
180 include 'COMMON.CHAIN'
181 include 'COMMON.MINIM'
182 include 'COMMON.FFIELD'
183 include 'COMMON.IOUNITS'
186 double precision dist
190 integer res_pick,n_maxtry
191 double precision e_drop
193 c Input/Output arguments
194 integer n_steps,n_fun
195 double precision e_sc
201 integer iretcode,loc_nfun,orig_maxfun,n_try
202 double precision sc_dist,sc_dist_cutoff
203 double precision energy(0:n_ene),orig_e,cur_e
204 double precision evdw,escloc
205 double precision cur_alph(2:nres-1),cur_omeg(2:nres-1)
206 double precision var(maxvar)
208 double precision orig_theta(1:nres),orig_phi(1:nres),
209 + orig_alph(1:nres),orig_omeg(1:nres)
212 c Define what is meant by "neighbouring side-chain"
215 c Don't do glycine or ends
217 if (i.eq.10 .or. i.eq.ntyp1) return
219 c Freeze everything (later will relax only selected side-chains)
227 c Find the neighbours of the side-chain to move
228 c and save initial variables
233 c Don't do glycine (itype(j)==10)
234 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
235 sc_dist=dist(nres+i,nres+res_pick)
237 sc_dist=sc_dist_cutoff
239 if (sc_dist.lt.sc_dist_cutoff) then
240 nres_moved=nres_moved+1
247 call chainbuild_extconf
250 e_sc=wsc*evdw+wscloc*escloc
251 c write (iout,*) "sc_move: e_sc",e_sc
252 cd call etotal(energy)
253 cd print *,'new ',(energy(k),k=0,n_ene)
258 do while (n_try.lt.n_maxtry .and. orig_e-cur_e.lt.e_drop)
259 c Move the selected residue (don't worry if it fails)
260 call gen_side(iabs(itype(res_pick)),theta(res_pick+1),
261 + alph(res_pick),omeg(res_pick),fail)
263 c Minimize the side-chains starting from the new arrangement
264 call geom_to_var(nvar,var)
269 crc orig_theta(i)=theta(i)
270 crc orig_phi(i)=phi(i)
271 crc orig_alph(i)=alph(i)
272 crc orig_omeg(i)=omeg(i)
275 call minimize_sc1(e_sc,var,iretcode,loc_nfun)
276 c write (iout,*) "n_try",n_try
277 c write (iout,*) "sc_move after minimze_sc1 e_sc",e_sc
278 cv write(*,'(2i3,2f12.5,2i3)')
279 cv & res_pick,nres_moved,orig_e,e_sc-cur_e,
280 cv & iretcode,loc_nfun
282 c$$$ if (iretcode.eq.8) then
283 c$$$ write(iout,*)'Coordinates just after code 8'
286 c$$$ call flush(iout)
288 c$$$ theta(i)=orig_theta(i)
289 c$$$ phi(i)=orig_phi(i)
290 c$$$ alph(i)=orig_alph(i)
291 c$$$ omeg(i)=orig_omeg(i)
293 c$$$ write(iout,*)'Coordinates just before code 8'
296 c$$$ call flush(iout)
301 call var_to_geom(nvar,var)
303 c If a lower energy was found, update the current structure...
304 if (e_sc.lt.cur_e) then
306 cv call etotal(energy)
309 cd e_sc1=wsc*evdw+wscloc*escloc
310 cd print *,' new',e_sc1,energy(0)
311 cv print *,'new ',energy(0)
312 cd call enerprint(energy(0))
315 if (mask_side(i).eq.1) then
321 c ...else revert to the previous one
324 if (mask_side(i).eq.1) then
333 n_steps=n_steps+n_try
335 c Reset the minimization mask_r to false
340 c-------------------------------------------------------------
341 subroutine minimize_sc1(etot,x,iretcode,nfun)
349 implicit real*8 (a-h,o-z)
352 c parameter (liv=60,lv=(77+maxvar*(maxvar+17)/2))
353 parameter(max_sc_move=10)
354 parameter (liv=60,lv=(77+2*max_sc_move*(2*max_sc_move+17)/2))
356 include 'COMMON.IOUNITS'
359 include 'COMMON.MINIM'
361 double precision x(maxvar),d(maxvar),xx(maxvar)
362 double precision energia(0:n_ene)
365 common /zmienne/ nvar_restr
366 double precision grdmin
367 double precision funcgrad_restr1
368 external funcgrad_restr1
371 external func,gradient,fdum
372 external func_restr1,grad_restr1
373 logical not_done,change,reduce
375 double precision v(1:lv)
376 common /przechowalnia/ v
380 coordtype='RIGIDBODY'
383 c jprint=print_min_stat
386 if (.not. allocated(scale)) allocate (scale(nvar))
388 c set scaling parameter for function and derivative values;
389 c use square root of median eigenvalue of typical Hessian
391 call x2xx(x,xx,nvar_restr)
402 c write (iout,*) "Calling lbfgs"
403 call lbfgs (nvar_restr,xx,etot,grdmin,funcgrad_restr1,optsave)
405 c write (iout,*) "After lbfgs"
408 call deflt(2,iv,liv,lv,v)
409 * 12 means fresh start, dont call deflt
411 * max num of fun calls
412 if (maxfun.eq.0) maxfun=500
414 * max num of iterations
415 if (maxmin.eq.0) maxmin=1000
419 * selects output unit
422 * 1 means to print out result
424 * 1 means to print out summary stats
426 * 1 means to print initial x and d
428 * min val for v(radfac) default is 0.1
430 * max val for v(radfac) default is 4.0
433 * check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)
434 * the sumsl default is 0.1
436 * false conv if (act fnctn decrease) .lt. v(34)
437 * the sumsl default is 100*machep
439 * absolute convergence
440 if (tolf.eq.0.0D0) tolf=1.0D-4
442 * relative convergence
443 if (rtolf.eq.0.0D0) rtolf=1.0D-4
445 * controls initial step size
447 * large vals of d correspond to small components of step
455 call x2xx(x,xx,nvar_restr)
456 call sumsl(nvar_restr,d,xx,func_restr1,grad_restr1,
457 & iv,liv,lv,v,idum,rdum,fdum)
460 c call sumsl(nvar,d,x,func,gradient,iv,liv,lv,v,idum,rdum,fdum)
469 double precision function funcgrad_restr1(x,g)
470 implicit real*8 (a-h,o-z)
472 include 'COMMON.DERIV'
473 include 'COMMON.IOUNITS'
475 include 'COMMON.FFIELD'
476 include 'COMMON.INTERACT'
477 include 'COMMON.TIME1'
478 include 'COMMON.CHAIN'
481 common /zmienne/ nvar_restr
482 double precision energia(0:n_ene),evdw,escloc
483 double precision ufparm,e1,e2
484 dimension x(maxvar),g(maxvar),gg(maxvar)
486 c Intercept NaNs in the coordinates, before calling etotal
492 if (x_sum.ne.x_sum) then
493 write(iout,*)" *** func_restr1 : Found NaN in coordinates"
501 if (isnan(x(i))) then
505 write (iout,*) "NaN in coordinates"
511 c write (iout,*) "nvar_restr",nvar_restr
512 c write (iout,*) "x",(x(i),i=1,nvar_restr)
513 call var_to_geom_restr(nvar_restr,x)
515 call chainbuild_extconf
516 cd write (iout,*) 'ETOTAL called from FUNC'
519 f=wsc*evdw+wscloc*escloc
520 c write (iout,*) "evdw",evdw," escloc",escloc
527 c write (iout,*) "f",f
528 cd call etotal(energia(0))
529 cd f=wsc*energia(1)+wscloc*energia(12)
530 cd print *,f,evdw,escloc,energia(0)
532 C Sum up the components of the Cartesian gradient.
536 gradx(j,i,icg)=wsc*gvdwx(j,i)+wscloc*gsclocx(j,i)
541 C Evaluate the derivatives of virtual bond lengths and SC vectors in variables.
543 call cart2intgrad(nvar,gg)
545 C Convert the Cartesian gradient into internal-coordinate gradient.
550 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
551 IF (mask_side(i).eq.1) THEN
554 c write (iout,*) "i",i," ig",ig," ialph",ialph(i,1)
555 c write (iout,*) "g",g(ig)," gg",gg(ialph(i,1))
560 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
561 IF (mask_side(i).eq.1) THEN
563 g(ig)=gg(ialph(i,1)+nside)
564 c write (iout,*) "i",i," ig",ig," ialph",ialph(i,1)+nside
565 c write (iout,*) "g",g(ig)," gg",gg(ialph(i,1)+nside)
571 C Add the components corresponding to local energy terms.
578 if (mask_phi(i).eq.1) then
580 g(ig)=g(ig)+gloc(igall,icg)
586 if (mask_theta(i).eq.1) then
588 g(ig)=g(ig)+gloc(igall,icg)
594 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
596 if (mask_side(i).eq.1) then
598 g(ig)=g(ig)+gloc(igall,icg)
599 c write (iout,*) "ij",ij," i",i," ig",ig," igall",igall
600 c write (iout,*) "gloc",gloc(igall,icg)," g",g(ig)
607 cd write (iout,'(a2,i5,a3,f25.8)') 'i=',i,' g=',g(i)
612 ************************************************************************
613 subroutine func_restr1(n,x,nf,f,uiparm,urparm,ufparm)
614 implicit real*8 (a-h,o-z)
616 include 'COMMON.DERIV'
617 include 'COMMON.IOUNITS'
619 include 'COMMON.FFIELD'
620 include 'COMMON.INTERACT'
621 include 'COMMON.TIME1'
622 double precision energia(0:n_ene),evdw,escloc
623 double precision ufparm,e1,e2
632 c Intercept NaNs in the coordinates, before calling etotal
638 if (x_sum.ne.x_sum) then
639 write(iout,*)" *** func_restr1 : Found NaN in coordinates"
646 call var_to_geom_restr(n,x)
648 call chainbuild_extconf
649 cd write (iout,*) 'ETOTAL called from FUNC'
652 f=wsc*evdw+wscloc*escloc
653 c write (iout,*) "f",f
654 cd call etotal(energia(0))
655 cd f=wsc*energia(1)+wscloc*energia(12)
656 cd print *,f,evdw,escloc,energia(0)
658 C Sum up the components of the Cartesian gradient.
662 gradx(j,i,icg)=wsc*gvdwx(j,i)+wscloc*gsclocx(j,i)
668 c-------------------------------------------------------
669 subroutine grad_restr1(n,x,nf,g,uiparm,urparm,ufparm)
670 implicit real*8 (a-h,o-z)
672 include 'COMMON.CHAIN'
673 include 'COMMON.DERIV'
675 include 'COMMON.INTERACT'
676 include 'COMMON.FFIELD'
677 include 'COMMON.IOUNITS'
680 double precision urparm(1)
681 dimension x(maxvar),g(maxvar),gg(maxvar)
684 if (nf-nfl+1) 20,30,40
685 20 call func_restr1(n,x,nf,f,uiparm,urparm,ufparm)
686 c write (iout,*) 'grad 20'
689 30 call var_to_geom_restr(n,x)
690 call chainbuild_extconf
692 C Evaluate the derivatives of virtual bond lengths and SC vectors in variables.
694 40 call cart2intgrad(nvar,gg)
696 C Convert the Cartesian gradient into internal-coordinate gradient.
702 IF (mask_phi(i+2).eq.1) THEN
710 IF (mask_theta(i+2).eq.1) THEN
717 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
718 IF (mask_side(i).eq.1) THEN
721 c write (iout,*) "i",i," ig",ig," ialph",ialph(i,1)
722 c write (iout,*) "g",g(ig)," gg",gg(ialph(i,1))
729 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
730 IF (mask_side(i).eq.1) THEN
732 g(ig)=gg(ialph(i,1)+nside)
733 c write (iout,*) "i",i," ig",ig," ialph",ialph(i,1)+nside
734 c write (iout,*) "g",g(ig)," gg",gg(ialph(i,1)+nside)
740 C Add the components corresponding to local energy terms.
747 if (mask_phi(i).eq.1) then
749 g(ig)=g(ig)+gloc(igall,icg)
755 if (mask_theta(i).eq.1) then
757 g(ig)=g(ig)+gloc(igall,icg)
763 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
765 if (mask_side(i).eq.1) then
767 g(ig)=g(ig)+gloc(igall,icg)
768 c write (iout,*) "ij",ij," i",i," ig",ig," igall",igall
769 c write (iout,*) "gloc",gloc(igall,icg)," g",g(ig)
776 cd write (iout,'(a2,i5,a3,f25.8)') 'i=',i,' g=',g(i)
781 C-----------------------------------------------------------------------------
782 subroutine egb1(evdw)
784 C This subroutine calculates the interaction energy of nonbonded side chains
785 C assuming the Gay-Berne potential of interaction.
787 implicit real*8 (a-h,o-z)
791 include 'COMMON.LOCAL'
792 include 'COMMON.CHAIN'
793 include 'COMMON.DERIV'
794 include 'COMMON.NAMES'
795 include 'COMMON.INTERACT'
796 include 'COMMON.IOUNITS'
797 include 'COMMON.CALC'
798 include 'COMMON.CONTROL'
801 c print *,'Entering EGB nnt=',nnt,' nct=',nct,' expon=',expon
804 c if (icall.eq.0) lprn=.true.
806 c do i=iatsc_s,iatsc_e
811 if (itypi.eq.ntyp1 .or. mask_side(i).eq.0) cycle
812 itypi1=iabs(itype(i+1))
817 if (xi.lt.0) xi=xi+boxxsize
819 if (yi.lt.0) yi=yi+boxysize
821 if (zi.lt.0) zi=zi+boxzsize
822 if ((zi.gt.bordlipbot)
823 &.and.(zi.lt.bordliptop)) then
824 C the energy transfer exist
825 if (zi.lt.buflipbot) then
826 C what fraction I am in
828 & ((positi-bordlipbot)/lipbufthick)
829 C lipbufthick is thickenes of lipid buffore
830 sslipi=sscalelip(fracinbuf)
831 ssgradlipi=-sscagradlip(fracinbuf)/lipbufthick
832 elseif (zi.gt.bufliptop) then
833 fracinbuf=1.0d0-((bordliptop-positi)/lipbufthick)
834 sslipi=sscalelip(fracinbuf)
835 ssgradlipi=sscagradlip(fracinbuf)/lipbufthick
845 dxi=dc_norm(1,nres+i)
846 dyi=dc_norm(2,nres+i)
847 dzi=dc_norm(3,nres+i)
848 dsci_inv=dsc_inv(itypi)
850 C Calculate SC interaction energy.
852 c do iint=1,nint_gr(i)
853 c do j=istart(i,iint),iend(i,iint)
855 IF (mask_side(j).eq.1.or.mask_side(i).eq.1) THEN
858 if (itypj.eq.ntyp1) cycle
859 dscj_inv=dsc_inv(itypj)
860 sig0ij=sigma(itypi,itypj)
861 chi1=chi(itypi,itypj)
862 chi2=chi(itypj,itypi)
869 alf12=0.5D0*(alf1+alf2)
870 C For diagnostics only!!!
887 if (xj.lt.0) xj=xj+boxxsize
889 if (yj.lt.0) yj=yj+boxysize
891 if (zj.lt.0) zj=zj+boxzsize
892 if ((zj.gt.bordlipbot)
893 &.and.(zj.lt.bordliptop)) then
894 C the energy transfer exist
895 if (zj.lt.buflipbot) then
896 C what fraction I am in
898 & ((positi-bordlipbot)/lipbufthick)
899 C lipbufthick is thickenes of lipid buffore
900 sslipj=sscalelip(fracinbuf)
901 ssgradlipj=-sscagradlip(fracinbuf)/lipbufthick
902 elseif (zi.gt.bufliptop) then
903 fracinbuf=1.0d0-((bordliptop-positi)/lipbufthick)
904 sslipj=sscalelip(fracinbuf)
905 ssgradlipj=sscagradlip(fracinbuf)/lipbufthick
914 aa=aa_lip(itypi,itypj)*(sslipi+sslipj)/2.0d0
915 & +aa_aq(itypi,itypj)*(2.0d0-sslipi+sslipj)/2.0d0
916 bb=bb_lip(itypi,itypj)*(sslipi+sslipj)/2.0d0
917 & +bb_aq(itypi,itypj)*(2.0d0-sslipi+sslipj)/2.0d0
919 dist_init=(xj-xi)**2+(yj-yi)**2+(zj-zi)**2
927 xj=xj_safe+xshift*boxxsize
928 yj=yj_safe+yshift*boxysize
929 zj=zj_safe+zshift*boxzsize
930 dist_temp=(xj-xi)**2+(yj-yi)**2+(zj-zi)**2
931 if(dist_temp.lt.dist_init) then
941 if (subchap.eq.1) then
951 dxj=dc_norm(1,nres+j)
952 dyj=dc_norm(2,nres+j)
953 dzj=dc_norm(3,nres+j)
954 rrij=1.0D0/(xj*xj+yj*yj+zj*zj)
956 sss=sscale((1.0d0/rij)/sigma(itypi,itypj))
957 sssgrad=sscagrad((1.0d0/rij)/sigma(itypi,itypj))
959 C Calculate angle-dependent terms of energy and contributions to their
963 sig=sig0ij*dsqrt(sigsq)
964 rij_shift=1.0D0/rij-sig+sig0ij
965 C I hate to put IF's in the loops, but here don't have another choice!!!!
966 if (rij_shift.le.0.0D0) then
968 cd write (iout,'(2(a3,i3,2x),17(0pf7.3))')
969 cd & restyp(itypi),i,restyp(itypj),j,
970 cd & rij_shift,1.0D0/rij,sig,sig0ij,sigsq,1-dsqrt(sigsq)
974 c---------------------------------------------------------------
975 rij_shift=1.0D0/rij_shift
979 evdwij=eps1*eps2rt*eps3rt*(e1+e2)
980 eps2der=evdwij*eps3rt
981 eps3der=evdwij*eps2rt
982 evdwij=evdwij*eps2rt*eps3rt
985 sigm=dabs(aa/bb)**(1.0D0/6.0D0)
987 cd write (iout,'(2(a3,i3,2x),17(0pf7.3))')
988 cd & restyp(itypi),i,restyp(itypj),j,
989 cd & epsi,sigm,chi1,chi2,chip1,chip2,
990 cd & eps1,eps2rt**2,eps3rt**2,sig,sig0ij,
991 cd & om1,om2,om12,1.0D0/rij,1.0D0/rij_shift,
995 if (energy_dec) write (iout,'(a6,2i5,0pf7.3)')
998 C Calculate gradient components.
999 e1=e1*eps1*eps2rt**2*eps3rt**2
1000 fac=-expon*(e1+evdwij)*rij_shift
1003 fac=fac+evdwij/sss*sssgrad/sigma(itypi,itypj)*rij
1004 C Calculate the radial part of the gradient
1008 gg_lipi(3)=ssgradlipi*evdwij
1009 gg_lipj(3)=ssgradlipj*evdwij
1010 C Calculate angular part of the gradient.
1017 C-----------------------------------------------------------------------------