1 c----------------------------------------------------------------------------
2 subroutine check_energies
9 include 'COMMON.IOUNITS'
10 include 'COMMON.SBRIDGE'
11 include 'COMMON.LOCAL'
15 double precision ran_number
19 integer i,j,k,l,lmax,p,pmax
20 double precision rmin,rmax
24 double precision wi,rij,tj,pj
48 ct wi=ran_number(0.0D0,pi)
49 c wi=ran_number(0.0D0,pi/6.0D0)
51 ct tj=ran_number(0.0D0,pi)
52 ct pj=ran_number(0.0D0,pi)
53 c pj=ran_number(0.0D0,pi/6.0D0)
57 ct rij=ran_number(rmin,rmax)
59 c(1,j)=d*sin(pj)*cos(tj)
60 c(2,j)=d*sin(pj)*sin(tj)
69 dc(k,nres+i)=c(k,nres+i)-c(k,i)
70 dc_norm(k,nres+i)=dc(k,nres+i)/d
71 dc(k,nres+j)=c(k,nres+j)-c(k,j)
72 dc_norm(k,nres+j)=dc(k,nres+j)/d
75 call dyn_ssbond_ene(i,j,eij)
84 C-----------------------------------------------------------------------------
86 subroutine dyn_ssbond_ene(resi,resj,eij)
91 include 'COMMON.SBRIDGE'
92 include 'COMMON.CHAIN'
93 include 'COMMON.DERIV'
94 include 'COMMON.LOCAL'
95 include 'COMMON.INTERACT'
97 include 'COMMON.IOUNITS'
101 C include 'COMMON.MD'
106 double precision h_base
117 c integer itypi,itypj,k,l
118 double precision rrij,ssd,deltat1,deltat2,deltat12,cosphi
119 double precision sig0ij,ljd,sig,fac,e1,e2
120 double precision dcosom1(3),dcosom2(3),ed
121 double precision pom1,pom2
122 double precision ljA,ljB,ljXs
123 double precision d_ljB(1:3)
124 double precision ssA,ssB,ssC,ssXs
125 double precision ssxm,ljxm,ssm,ljm
126 double precision d_ssxm(1:3),d_ljxm(1:3),d_ssm(1:3),d_ljm(1:3)
127 double precision f1,f2,h1,h2,hd1,hd2
128 double precision omega,delta_inv,deltasq_inv,fac1,fac2
130 double precision xm,d_xm(1:3)
131 c-------END FIRST METHOD
132 c-------SECOND METHOD
133 c$$$ double precision ss,d_ss(0:3),ljf,d_ljf(0:3)
134 c-------END SECOND METHOD
137 logical checkstop,transgrad
138 common /sschecks/ checkstop,transgrad
140 integer icheck,nicheck,jcheck,njcheck
141 double precision echeck(-1:1),deps,ssx0,ljx0
142 c-------END TESTING CODE
149 dxi=dc_norm(1,nres+i)
150 dyi=dc_norm(2,nres+i)
151 dzi=dc_norm(3,nres+i)
152 dsci_inv=vbld_inv(i+nres)
157 if (xi.lt.0) xi=xi+boxxsize
159 if (yi.lt.0) yi=yi+boxysize
161 if (zi.lt.0) zi=zi+boxzsize
162 C define scaling factor for lipids
164 C if (positi.le.0) positi=positi+boxzsize
166 C first for peptide groups
167 c for each residue check if it is in lipid or lipid water border area
168 if ((zi.gt.bordlipbot)
169 &.and.(zi.lt.bordliptop)) then
170 C the energy transfer exist
171 if (zi.lt.buflipbot) then
172 C what fraction I am in
174 & ((positi-bordlipbot)/lipbufthick)
175 C lipbufthick is thickenes of lipid buffore
176 sslipi=sscalelip(fracinbuf)
177 ssgradlipi=-sscagradlip(fracinbuf)/lipbufthick
178 elseif (zi.gt.bufliptop) then
179 fracinbuf=1.0d0-((bordliptop-positi)/lipbufthick)
180 sslipi=sscalelip(fracinbuf)
181 ssgradlipi=sscagradlip(fracinbuf)/lipbufthick
196 if (xj.lt.0) xj=xj+boxxsize
198 if (yj.lt.0) yj=yj+boxysize
200 if (zj.lt.0) zj=zj+boxzsize
201 if ((zj.gt.bordlipbot)
202 &.and.(zj.lt.bordliptop)) then
203 C the energy transfer exist
204 if (zj.lt.buflipbot) then
205 C what fraction I am in
207 & ((positi-bordlipbot)/lipbufthick)
208 C lipbufthick is thickenes of lipid buffore
209 sslipj=sscalelip(fracinbuf)
210 ssgradlipj=-sscagradlip(fracinbuf)/lipbufthick
211 elseif (zi.gt.bufliptop) then
212 fracinbuf=1.0d0-((bordliptop-positi)/lipbufthick)
213 sslipj=sscalelip(fracinbuf)
214 ssgradlipj=sscagradlip(fracinbuf)/lipbufthick
223 aa=aa_lip(itypi,itypj)*(sslipi+sslipj)/2.0d0
224 & +aa_aq(itypi,itypj)*(2.0d0-sslipi+sslipj)/2.0d0
225 bb=bb_lip(itypi,itypj)*(sslipi+sslipj)/2.0d0
226 & +bb_aq(itypi,itypj)*(2.0d0-sslipi+sslipj)/2.0d0
228 dist_init=(xj-xi)**2+(yj-yi)**2+(zj-zi)**2
240 xj=xj_safe+xshift*boxxsize
241 yj=yj_safe+yshift*boxysize
242 zj=zj_safe+zshift*boxzsize
243 dist_temp=(xj-xi)**2+(yj-yi)**2+(zj-zi)**2
244 if(dist_temp.lt.dist_init) then
254 if (subchap.eq.1) then
264 dxj=dc_norm(1,nres+j)
265 dyj=dc_norm(2,nres+j)
266 dzj=dc_norm(3,nres+j)
267 dscj_inv=vbld_inv(j+nres)
269 chi1=chi(itypi,itypj)
270 chi2=chi(itypj,itypi)
277 alf12=0.5D0*(alf1+alf2)
279 rrij=1.0D0/(xj*xj+yj*yj+zj*zj)
280 rij=dsqrt(rrij) ! sc_angular needs rij to really be the inverse
281 c The following are set in sc_angular
285 c om1=dxi*erij(1)+dyi*erij(2)+dzi*erij(3)
286 c om2=dxj*erij(1)+dyj*erij(2)+dzj*erij(3)
287 c om12=dxi*dxj+dyi*dyj+dzi*dzj
289 rij=1.0D0/rij ! Reset this so it makes sense
291 sig0ij=sigma(itypi,itypj)
292 sig=sig0ij*dsqrt(1.0D0/sigsq)
295 ljA=eps1*eps2rt**2*eps3rt**2
298 ljxm=ljXs+(-2.0D0*aa/bb)**(1.0D0/6.0D0)
303 deltat12=om2-om1+2.0d0
308 & +akth*(deltat1*deltat1+deltat2*deltat2)
309 & +v1ss*cosphi+v2ss*cosphi*cosphi+v3ss*cosphi*cosphi*cosphi
310 ssxm=ssXs-0.5D0*ssB/ssA
313 c$$$c Some extra output
314 c$$$ ssm=ssC-0.25D0*ssB*ssB/ssA
315 c$$$ ljm=-0.25D0*ljB*bb(itypi,itypj)/aa(itypi,itypj)
316 c$$$ ssx0=ssB*ssB-4.0d0*ssA*ssC
317 c$$$ if (ssx0.gt.0.0d0) then
318 c$$$ ssx0=ssXs+0.5d0*(-ssB+sqrt(ssx0))/ssA
322 c$$$ ljx0=ljXs+(-aa(itypi,itypj)/bb(itypi,itypj))**(1.0D0/6.0D0)
323 c$$$ write(iout,'(a,4f8.2,2f15.2,3f6.2)')"SSENERGIES ",
324 c$$$ & ssxm,ljxm,ssx0,ljx0,ssm,ljm,om1,om2,om12
326 c-------END TESTING CODE
329 c Stop and plot energy and derivative as a function of distance
331 ssm=ssC-0.25D0*ssB*ssB/ssA
332 ljm=-0.25D0*ljB*bb/aa
334 & dabs(rij-0.5d0*(ssxm+ljxm)).lt.0.35d0*(ljxm-ssxm)) then
342 if (.not.checkstop) then
349 if (checkstop) rij=(ssxm-1.0d0)+
350 & ((ljxm-ssxm+2.0d0)*icheck)/nicheck+jcheck*deps
351 c-------END TESTING CODE
353 if (rij.gt.ljxm) then
356 fac=(1.0D0/ljd)**expon
359 eij=eps1*eps2rt*eps3rt*(e1+e2)
360 C write(iout,*) eij,'TU?1'
363 eij=eij*eps2rt*eps3rt
366 e1=e1*eps1*eps2rt**2*eps3rt**2
367 ed=-expon*(e1+eij)/ljd
369 eom1=eps2der*eps2rt_om1-2.0D0*alf1*eps3der+sigder*sigsq_om1
370 eom2=eps2der*eps2rt_om2+2.0D0*alf2*eps3der+sigder*sigsq_om2
371 eom12=eij*eps1_om12+eps2der*eps2rt_om12
372 & -2.0D0*alf12*eps3der+sigder*sigsq_om12
373 else if (rij.lt.ssxm) then
376 eij=ssA*ssd*ssd+ssB*ssd+ssC
377 C write(iout,*) 'TU?2',ssc,ssd
378 ed=2*akcm*ssd+akct*deltat12
380 pom2=v1ss+2*v2ss*cosphi+3*v3ss*cosphi*cosphi
381 eom1=-2*akth*deltat1-pom1-om2*pom2
382 eom2= 2*akth*deltat2+pom1-om1*pom2
385 omega=v1ss+2.0d0*v2ss*cosphi+3.0d0*v3ss*cosphi*cosphi
387 d_ssxm(1)=0.5D0*akct/ssA
391 d_ljxm(1)=sig0ij/sqrt(sigsq**3)
392 d_ljxm(2)=d_ljxm(1)*sigsq_om2
393 d_ljxm(3)=d_ljxm(1)*sigsq_om12
394 d_ljxm(1)=d_ljxm(1)*sigsq_om1
396 c-------FIRST METHOD, DISCONTINUOUS SECOND DERIVATIVE
399 d_xm(k)=0.5d0*(d_ssxm(k)+d_ljxm(k))
403 ssm=ssC-0.25D0*ssB*ssB/ssA
404 d_ssm(1)=0.5D0*akct*ssB/ssA
405 d_ssm(2)=2.0D0*akth*deltat2-om1*omega-d_ssm(1)
406 d_ssm(1)=-2.0D0*akth*deltat1-om2*omega+d_ssm(1)
408 f1=(rij-xm)/(ssxm-xm)
409 f2=(rij-ssxm)/(xm-ssxm)
413 C write(iout,*) eij,'TU?3'
414 delta_inv=1.0d0/(xm-ssxm)
415 deltasq_inv=delta_inv*delta_inv
417 fac1=deltasq_inv*fac*(xm-rij)
418 fac2=deltasq_inv*fac*(rij-ssxm)
419 ed=delta_inv*(Ht*hd2-ssm*hd1)
420 eom1=fac1*d_ssxm(1)+fac2*d_xm(1)+h1*d_ssm(1)
421 eom2=fac1*d_ssxm(2)+fac2*d_xm(2)+h1*d_ssm(2)
422 eom12=fac1*d_ssxm(3)+fac2*d_xm(3)+h1*d_ssm(3)
425 ljm=-0.25D0*ljB*bb/aa
426 d_ljm(1)=-0.5D0*bb/aa*ljB
427 d_ljm(2)=d_ljm(1)*(0.5D0*eps2rt_om2/eps2rt+alf2/eps3rt)
428 d_ljm(3)=d_ljm(1)*(0.5D0*eps1_om12+0.5D0*eps2rt_om12/eps2rt-
430 d_ljm(1)=d_ljm(1)*(0.5D0*eps2rt_om1/eps2rt-alf1/eps3rt)
431 f1=(rij-ljxm)/(xm-ljxm)
432 f2=(rij-xm)/(ljxm-xm)
436 C write(iout,*) 'TU?4',ssA
437 delta_inv=1.0d0/(ljxm-xm)
438 deltasq_inv=delta_inv*delta_inv
440 fac1=deltasq_inv*fac*(ljxm-rij)
441 fac2=deltasq_inv*fac*(rij-xm)
442 ed=delta_inv*(ljm*hd2-Ht*hd1)
443 eom1=fac1*d_xm(1)+fac2*d_ljxm(1)+h2*d_ljm(1)
444 eom2=fac1*d_xm(2)+fac2*d_ljxm(2)+h2*d_ljm(2)
445 eom12=fac1*d_xm(3)+fac2*d_ljxm(3)+h2*d_ljm(3)
447 c-------END FIRST METHOD, DISCONTINUOUS SECOND DERIVATIVE
449 c-------SECOND METHOD, CONTINUOUS SECOND DERIVATIVE
455 c$$$ d_ljB(1)=ljB*(eps2rt_om1/eps2rt-2.0d0*alf1/eps3rt)
456 c$$$ d_ljB(2)=ljB*(eps2rt_om2/eps2rt+2.0d0*alf2/eps3rt)
457 c$$$ d_ljB(3)=ljB*(eps1_om12+eps2rt_om12/eps2rt-2.0d0*alf12/eps3rt)
459 c$$$ ssm=ssC-0.25D0*ssB*ssB/ssA
460 c$$$ d_ssm(1)=0.5D0*akct*ssB/ssA
461 c$$$ d_ssm(2)=2.0D0*akth*deltat2-om1*omega-d_ssm(1)
462 c$$$ d_ssm(1)=-2.0D0*akth*deltat1-om2*omega+d_ssm(1)
465 c$$$ ljm=-0.25D0*bb(itypi,itypj)/aa(itypi,itypj)
467 c$$$ d_ljm(k)=ljm*d_ljB(k)
471 c$$$ ss=ssA*ssd*ssd+ssB*ssd+ssC
472 c$$$ d_ss(0)=2.0d0*ssA*ssd+ssB
473 c$$$ d_ss(2)=akct*ssd
474 c$$$ d_ss(1)=-d_ss(2)-2.0d0*akth*deltat1-om2*omega
475 c$$$ d_ss(2)=d_ss(2)+2.0d0*akth*deltat2-om1*omega
478 c$$$ ljf=bb(itypi,itypj)/aa(itypi,itypj)
479 c$$$ ljf=9.0d0*ljf*(-0.5d0*ljf)**(1.0d0/3.0d0)
480 c$$$ d_ljf(0)=ljf*2.0d0*ljB*fac1
482 c$$$ d_ljf(k)=d_ljm(k)+ljf*(d_ljB(k)*fac1*fac1-
483 c$$$ & 2.0d0*ljB*fac1*d_ljxm(k))
485 c$$$ ljf=ljm+ljf*ljB*fac1*fac1
487 c$$$ f1=(rij-ljxm)/(ssxm-ljxm)
488 c$$$ f2=(rij-ssxm)/(ljxm-ssxm)
489 c$$$ h1=h_base(f1,hd1)
490 c$$$ h2=h_base(f2,hd2)
491 c$$$ eij=ss*h1+ljf*h2
492 c$$$ delta_inv=1.0d0/(ljxm-ssxm)
493 c$$$ deltasq_inv=delta_inv*delta_inv
494 c$$$ fac=ljf*hd2-ss*hd1
495 c$$$ ed=d_ss(0)*h1+d_ljf(0)*h2+delta_inv*fac
496 c$$$ eom1=d_ss(1)*h1+d_ljf(1)*h2+deltasq_inv*fac*
497 c$$$ & (fac1*d_ssxm(1)-fac2*(d_ljxm(1)))
498 c$$$ eom2=d_ss(2)*h1+d_ljf(2)*h2+deltasq_inv*fac*
499 c$$$ & (fac1*d_ssxm(2)-fac2*(d_ljxm(2)))
500 c$$$ eom12=d_ss(3)*h1+d_ljf(3)*h2+deltasq_inv*fac*
501 c$$$ & (fac1*d_ssxm(3)-fac2*(d_ljxm(3)))
503 c$$$ havebond=.false.
504 c$$$ if (ed.gt.0.0d0) havebond=.true.
505 c-------END SECOND METHOD, CONTINUOUS SECOND DERIVATIVE
508 C write(iout,*) 'havebond',havebond
512 c if (dyn_ssbond_ij(i,j).eq.1.0d300) then
513 c write(iout,'(a15,f12.2,f8.1,2i5)')
514 c & "SSBOND_E_FORM",totT,t_bath,i,j
518 dyn_ssbond_ij(i,j)=eij
519 else if (.not.havebond .and. dyn_ssbond_ij(i,j).lt.1.0d300) then
520 dyn_ssbond_ij(i,j)=1.0d300
523 c write(iout,'(a15,f12.2,f8.1,2i5)')
524 c & "SSBOND_E_BREAK",totT,t_bath,i,j
531 if (jcheck.eq.0) write(iout,'(a,3f15.8,$)')
532 & "CHECKSTOP",rij,eij,ed
537 write(iout,'(f15.8)')(echeck(1)-echeck(-1))*0.5d0/deps
544 c-------END TESTING CODE
547 dcosom1(k)=(dc_norm(k,nres+i)-om1*erij(k))/rij
548 dcosom2(k)=(dc_norm(k,nres+j)-om2*erij(k))/rij
551 gg(k)=ed*erij(k)+eom1*dcosom1(k)+eom2*dcosom2(k)
554 gvdwx(k,i)=gvdwx(k,i)-gg(k)
555 & +(eom12*(dc_norm(k,nres+j)-om12*dc_norm(k,nres+i))
556 & +eom1*(erij(k)-om1*dc_norm(k,nres+i)))*dsci_inv
557 gvdwx(k,j)=gvdwx(k,j)+gg(k)
558 & +(eom12*(dc_norm(k,nres+i)-om12*dc_norm(k,nres+j))
559 & +eom2*(erij(k)-om2*dc_norm(k,nres+j)))*dscj_inv
563 cgrad gvdwc(l,k)=gvdwc(l,k)+gg(l)
568 gvdwc(l,i)=gvdwc(l,i)-gg(l)
569 gvdwc(l,j)=gvdwc(l,j)+gg(l)
575 C-----------------------------------------------------------------------------
577 double precision function h_base(x,deriv)
578 c A smooth function going 0->1 in range [0,1]
579 c It should NOT be called outside range [0,1], it will not work there.
586 double precision deriv
592 c Two parabolas put together. First derivative zero at extrema
593 c$$$ if (x.lt.0.5D0) then
594 c$$$ h_base=2.0D0*x*x
598 c$$$ h_base=1.0D0-2.0D0*deriv*deriv
599 c$$$ deriv=4.0D0*deriv
602 c Third degree polynomial. First derivative zero at extrema
603 h_base=x*x*(3.0d0-2.0d0*x)
604 deriv=6.0d0*x*(1.0d0-x)
606 c Fifth degree polynomial. First and second derivatives zero at extrema
608 c$$$ h_base=x*xsq*(6.0d0*xsq-15.0d0*x+10.0d0)
610 c$$$ deriv=deriv*deriv
611 c$$$ deriv=30.0d0*xsq*deriv
616 c----------------------------------------------------------------------------
618 subroutine dyn_set_nss
619 c Adjust nss and other relevant variables based on dyn_ssbond_ij
627 include 'COMMON.SBRIDGE'
628 include 'COMMON.CHAIN'
629 include 'COMMON.IOUNITS'
630 C include 'COMMON.SETUP'
633 C include 'COMMON.MD'
638 double precision emin
640 integer diff,allflag(maxdim),allnss,
641 & allihpb(maxdim),alljhpb(maxdim),
642 & newnss,newihpb(maxdim),newjhpb(maxdim)
644 integer i_newnss(1024),displ(0:1024)
645 integer g_newihpb(maxdim),g_newjhpb(maxdim),g_newnss
650 if (dyn_ssbond_ij(i,j).lt.1.0d300) then
659 cmc write(iout,*)"ALLNSS ",allnss,(allihpb(i),alljhpb(i),i=1,allnss)
663 if (allflag(i).eq.0 .and.
664 & dyn_ssbond_ij(allihpb(i),alljhpb(i)).lt.emin) then
665 emin=dyn_ssbond_ij(allihpb(i),alljhpb(i))
669 if (emin.lt.1.0d300) then
672 if (allflag(i).eq.0 .and.
673 & (allihpb(i).eq.allihpb(imin) .or.
674 & alljhpb(i).eq.allihpb(imin) .or.
675 & allihpb(i).eq.alljhpb(imin) .or.
676 & alljhpb(i).eq.alljhpb(imin))) then
683 cmc write(iout,*)"ALLNSS ",allnss,(allihpb(i),alljhpb(i),i=1,allnss)
687 if (allflag(i).eq.1) then
689 newihpb(newnss)=allihpb(i)
690 newjhpb(newnss)=alljhpb(i)
695 if (nfgtasks.gt.1)then
697 call MPI_Reduce(newnss,g_newnss,1,
698 & MPI_INTEGER,MPI_SUM,king,FG_COMM,IERR)
699 call MPI_Gather(newnss,1,MPI_INTEGER,
700 & i_newnss,1,MPI_INTEGER,king,FG_COMM,IERR)
703 displ(i)=i_newnss(i-1)+displ(i-1)
705 call MPI_Gatherv(newihpb,newnss,MPI_INTEGER,
706 & g_newihpb,i_newnss,displ,MPI_INTEGER,
708 call MPI_Gatherv(newjhpb,newnss,MPI_INTEGER,
709 & g_newjhpb,i_newnss,displ,MPI_INTEGER,
711 if(fg_rank.eq.0) then
712 c print *,'g_newnss',g_newnss
713 c print *,'g_newihpb',(g_newihpb(i),i=1,g_newnss)
714 c print *,'g_newjhpb',(g_newjhpb(i),i=1,g_newnss)
717 newihpb(i)=g_newihpb(i)
718 newjhpb(i)=g_newjhpb(i)
726 cmc write(iout,*)"NEWNSS ",newnss,(newihpb(i),newjhpb(i),i=1,newnss)
731 if (idssb(i).eq.newihpb(j) .and.
732 & jdssb(i).eq.newjhpb(j)) found=.true.
736 c if (.not.found.and.fg_rank.eq.0)
737 c & write(iout,'(a15,f12.2,f8.1,2i5)')
738 c & "SSBOND_BREAK",totT,t_bath,idssb(i),jdssb(i)
746 if (newihpb(i).eq.idssb(j) .and.
747 & newjhpb(i).eq.jdssb(j)) found=.true.
751 c if (.not.found.and.fg_rank.eq.0)
752 c & write(iout,'(a15,f12.2,f8.1,2i5)')
753 c & "SSBOND_FORM",totT,t_bath,newihpb(i),newjhpb(i)
768 c$$$c-----------------------------------------------------------------------------
770 c$$$ subroutine ss_relax(i_in,j_in)
774 c$$$ include 'DIMENSIONS'
775 c$$$ include 'COMMON.VAR'
776 c$$$ include 'COMMON.CHAIN'
777 c$$$ include 'COMMON.IOUNITS'
778 c$$$ include 'COMMON.INTERACT'
780 c$$$c Input arguments
781 c$$$ integer i_in,j_in
783 c$$$c Local variables
784 c$$$ integer i,iretcode,nfun_sc
786 c$$$ double precision var(maxvar),e_sc,etot
793 c$$$ mask_side(i_in)=1
794 c$$$ mask_side(j_in)=1
796 c$$$c Minimize the two selected side-chains
797 c$$$ call overlap_sc(scfail) ! Better not fail!
798 c$$$ call minimize_sc(e_sc,var,iretcode,nfun_sc)
805 c$$$c-------------------------------------------------------------
807 c$$$ subroutine minimize_sc(etot_sc,iretcode,nfun)
808 c$$$c Minimize side-chains only, starting from geom but without modifying
810 c$$$c If mask_r is already set, only the selected side-chains are minimized,
811 c$$$c otherwise all side-chains are minimized keeping the backbone frozen.
815 c$$$ include 'DIMENSIONS'
816 c$$$ include 'COMMON.IOUNITS'
817 c$$$ include 'COMMON.VAR'
818 c$$$ include 'COMMON.CHAIN'
819 c$$$ include 'COMMON.GEO'
820 c$$$ include 'COMMON.MINIM'
822 c$$$ common /srutu/ icall
824 c$$$c Output arguments
825 c$$$ double precision etot_sc
826 c$$$ integer iretcode,nfun
828 c$$$c External functions/subroutines
829 c$$$ external func_sc,grad_sc,fdum
831 c$$$c Local variables
833 c$$$ parameter (liv=60,lv=(77+maxvar*(maxvar+17)/2))
835 c$$$ double precision rdum(1)
836 c$$$ double precision d(maxvar),v(1:lv),x(maxvar),xx(maxvar)
838 c$$$ integer i,nvar_restr
841 c$$$cmc start_minim=.true.
842 c$$$ call deflt(2,iv,liv,lv,v)
843 c$$$* 12 means fresh start, dont call deflt
845 c$$$* max num of fun calls
846 c$$$ if (maxfun.eq.0) maxfun=500
848 c$$$* max num of iterations
849 c$$$ if (maxmin.eq.0) maxmin=1000
851 c$$$* controls output
853 c$$$* selects output unit
855 c$$$c iv(21)=iout ! DEBUG
856 c$$$c iv(21)=8 ! DEBUG
857 c$$$* 1 means to print out result
859 c$$$c iv(22)=1 ! DEBUG
860 c$$$* 1 means to print out summary stats
862 c$$$c iv(23)=1 ! DEBUG
863 c$$$* 1 means to print initial x and d
865 c$$$c iv(24)=1 ! DEBUG
866 c$$$* min val for v(radfac) default is 0.1
868 c$$$* max val for v(radfac) default is 4.0
871 c$$$* check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)
872 c$$$* the sumsl default is 0.1
874 c$$$* false conv if (act fnctn decrease) .lt. v(34)
875 c$$$* the sumsl default is 100*machep
876 c$$$ v(34)=v(34)/100.0D0
877 c$$$* absolute convergence
878 c$$$ if (tolf.eq.0.0D0) tolf=1.0D-4
880 c$$$* relative convergence
881 c$$$ if (rtolf.eq.0.0D0) rtolf=1.0D-1
883 c$$$* controls initial step size
885 c$$$* large vals of d correspond to small components of step
889 c$$$ do i=nphi+1,nvar
893 c$$$ call geom_to_var(nvar,x)
894 c$$$ IF (mask_r) THEN
895 c$$$ do i=1,nres ! Just in case...
899 c$$$ call x2xx(x,xx,nvar_restr)
900 c$$$ call sumsl(nvar_restr,d,xx,func_sc,grad_sc,
901 c$$$ & iv,liv,lv,v,idum,rdum,fdum)
904 c$$$c When minimizing ALL side-chains, etotal_sc is a little
905 c$$$c faster if we don't set mask_r
911 c$$$ call x2xx(x,xx,nvar_restr)
912 c$$$ call sumsl(nvar_restr,d,xx,func_sc,grad_sc,
913 c$$$ & iv,liv,lv,v,idum,rdum,fdum)
916 c$$$ call var_to_geom(nvar,x)
917 c$$$ call chainbuild_sc
924 c$$$C--------------------------------------------------------------------------
926 c$$$ subroutine chainbuild_sc
928 c$$$ include 'DIMENSIONS'
929 c$$$ include 'COMMON.VAR'
930 c$$$ include 'COMMON.INTERACT'
932 c$$$c Local variables
937 c$$$ if (.not.mask_r .or. mask_side(i).eq.1) then
938 c$$$ call locate_side_chain(i)
945 c$$$C--------------------------------------------------------------------------
947 c$$$ subroutine func_sc(n,x,nf,f,uiparm,urparm,ufparm)
951 c$$$ include 'DIMENSIONS'
952 c$$$ include 'COMMON.DERIV'
953 c$$$ include 'COMMON.VAR'
954 c$$$ include 'COMMON.MINIM'
955 c$$$ include 'COMMON.IOUNITS'
957 c$$$c Input arguments
959 c$$$ double precision x(maxvar)
960 c$$$ double precision ufparm
963 c$$$c Input/Output arguments
965 c$$$ integer uiparm(1)
966 c$$$ double precision urparm(1)
968 c$$$c Output arguments
969 c$$$ double precision f
971 c$$$c Local variables
972 c$$$ double precision energia(0:n_ene)
974 c$$$c Variables used to intercept NaNs
975 c$$$ double precision x_sum
984 c$$$c Intercept NaNs in the coordinates, before calling etotal_sc
987 c$$$ x_sum=x_sum+x(i_NAN)
989 c$$$c Calculate the energy only if the coordinates are ok
990 c$$$ if ((.not.(x_sum.lt.0.D0)) .and. (.not.(x_sum.ge.0.D0))) then
991 c$$$ write(iout,*)" *** func_restr_sc : Found NaN in coordinates"
997 c$$$ call var_to_geom_restr(n,x)
999 c$$$ call chainbuild_sc
1000 c$$$ call etotal_sc(energia(0))
1002 c$$$ if (energia(1).eq.1.0D20 .or. energia(0).eq.1.0D99) nf=0
1011 c$$$c-------------------------------------------------------
1013 c$$$ subroutine grad_sc(n,x,nf,g,uiparm,urparm,ufparm)
1017 c$$$ include 'DIMENSIONS'
1018 c$$$ include 'COMMON.CHAIN'
1019 c$$$ include 'COMMON.DERIV'
1020 c$$$ include 'COMMON.VAR'
1021 c$$$ include 'COMMON.INTERACT'
1022 c$$$ include 'COMMON.MINIM'
1024 c$$$c Input arguments
1026 c$$$ double precision x(maxvar)
1027 c$$$ double precision ufparm
1028 c$$$ external ufparm
1030 c$$$c Input/Output arguments
1032 c$$$ integer uiparm(1)
1033 c$$$ double precision urparm(1)
1035 c$$$c Output arguments
1036 c$$$ double precision g(maxvar)
1038 c$$$c Local variables
1039 c$$$ double precision f,gphii,gthetai,galphai,gomegai
1040 c$$$ integer ig,ind,i,j,k,igall,ij
1043 c$$$ icg=mod(nf,2)+1
1044 c$$$ if (nf-nfl+1) 20,30,40
1045 c$$$ 20 call func_sc(n,x,nf,f,uiparm,urparm,ufparm)
1046 c$$$c write (iout,*) 'grad 20'
1047 c$$$ if (nf.eq.0) return
1049 c$$$ 30 call var_to_geom_restr(n,x)
1050 c$$$ call chainbuild_sc
1052 c$$$C Evaluate the derivatives of virtual bond lengths and SC vectors in variables.
1054 c$$$ 40 call cartder
1056 c$$$C Convert the Cartesian gradient into internal-coordinate gradient.
1062 c$$$ IF (mask_phi(i+2).eq.1) THEN
1064 c$$$ do j=i+1,nres-1
1067 c$$$ gphii=gphii+dcdv(k+3,ind)*gradc(k,j,icg)
1068 c$$$ gphii=gphii+dxdv(k+3,ind)*gradx(k,j,icg)
1074 c$$$ ind=ind+nres-1-i
1081 c$$$ IF (mask_theta(i+2).eq.1) THEN
1084 c$$$ do j=i+1,nres-1
1087 c$$$ gthetai=gthetai+dcdv(k,ind)*gradc(k,j,icg)
1088 c$$$ gthetai=gthetai+dxdv(k,ind)*gradx(k,j,icg)
1093 c$$$ ind=ind+nres-1-i
1098 c$$$ if (itype(i).ne.10) then
1099 c$$$ IF (mask_side(i).eq.1) THEN
1103 c$$$ galphai=galphai+dxds(k,i)*gradx(k,i,icg)
1112 c$$$ if (itype(i).ne.10) then
1113 c$$$ IF (mask_side(i).eq.1) THEN
1117 c$$$ gomegai=gomegai+dxds(k+3,i)*gradx(k,i,icg)
1125 c$$$C Add the components corresponding to local energy terms.
1132 c$$$ if (mask_phi(i).eq.1) then
1134 c$$$ g(ig)=g(ig)+gloc(igall,icg)
1140 c$$$ if (mask_theta(i).eq.1) then
1142 c$$$ g(ig)=g(ig)+gloc(igall,icg)
1148 c$$$ if (itype(i).ne.10) then
1150 c$$$ if (mask_side(i).eq.1) then
1152 c$$$ g(ig)=g(ig)+gloc(igall,icg)
1159 c$$$cd write (iout,'(a2,i5,a3,f25.8)') 'i=',i,' g=',g(i)
1165 c$$$C-----------------------------------------------------------------------------
1167 c$$$ subroutine etotal_sc(energy_sc)
1171 c$$$ include 'DIMENSIONS'
1172 c$$$ include 'COMMON.VAR'
1173 c$$$ include 'COMMON.INTERACT'
1174 c$$$ include 'COMMON.DERIV'
1175 c$$$ include 'COMMON.FFIELD'
1177 c$$$c Output arguments
1178 c$$$ double precision energy_sc(0:n_ene)
1180 c$$$c Local variables
1181 c$$$ double precision evdw,escloc
1186 c$$$ energy_sc(i)=0.0D0
1189 c$$$ if (mask_r) then
1190 c$$$ call egb_sc(evdw)
1191 c$$$ call esc_sc(escloc)
1194 c$$$ call esc(escloc)
1197 c$$$ if (evdw.eq.1.0D20) then
1198 c$$$ energy_sc(0)=evdw
1200 c$$$ energy_sc(0)=wsc*evdw+wscloc*escloc
1202 c$$$ energy_sc(1)=evdw
1203 c$$$ energy_sc(12)=escloc
1206 c$$$C Sum up the components of the Cartesian gradient.
1210 c$$$ gradx(j,i,icg)=wsc*gvdwx(j,i)
1217 c$$$C-----------------------------------------------------------------------------
1219 c$$$ subroutine egb_sc(evdw)
1221 c$$$C This subroutine calculates the interaction energy of nonbonded side chains
1222 c$$$C assuming the Gay-Berne potential of interaction.
1224 c$$$ implicit real*8 (a-h,o-z)
1225 c$$$ include 'DIMENSIONS'
1226 c$$$ include 'COMMON.GEO'
1227 c$$$ include 'COMMON.VAR'
1228 c$$$ include 'COMMON.LOCAL'
1229 c$$$ include 'COMMON.CHAIN'
1230 c$$$ include 'COMMON.DERIV'
1231 c$$$ include 'COMMON.NAMES'
1232 c$$$ include 'COMMON.INTERACT'
1233 c$$$ include 'COMMON.IOUNITS'
1234 c$$$ include 'COMMON.CALC'
1235 c$$$ include 'COMMON.CONTROL'
1238 c$$$ energy_dec=.false.
1239 c$$$c print *,'Entering EGB nnt=',nnt,' nct=',nct,' expon=',expon
1242 c$$$c if (icall.eq.0) lprn=.false.
1244 c$$$ do i=iatsc_s,iatsc_e
1246 c$$$ itypi1=itype(i+1)
1250 c$$$ dxi=dc_norm(1,nres+i)
1251 c$$$ dyi=dc_norm(2,nres+i)
1252 c$$$ dzi=dc_norm(3,nres+i)
1253 c$$$c dsci_inv=dsc_inv(itypi)
1254 c$$$ dsci_inv=vbld_inv(i+nres)
1255 c$$$c write (iout,*) "i",i,dsc_inv(itypi),dsci_inv,1.0d0/vbld(i+nres)
1256 c$$$c write (iout,*) "dcnori",dxi*dxi+dyi*dyi+dzi*dzi
1258 c$$$C Calculate SC interaction energy.
1260 c$$$ do iint=1,nint_gr(i)
1261 c$$$ do j=istart(i,iint),iend(i,iint)
1262 c$$$ IF (mask_side(j).eq.1.or.mask_side(i).eq.1) THEN
1265 c$$$c dscj_inv=dsc_inv(itypj)
1266 c$$$ dscj_inv=vbld_inv(j+nres)
1267 c$$$c write (iout,*) "j",j,dsc_inv(itypj),dscj_inv,
1268 c$$$c & 1.0d0/vbld(j+nres)
1269 c$$$c write (iout,*) "i",i," j", j," itype",itype(i),itype(j)
1270 c$$$ sig0ij=sigma(itypi,itypj)
1271 c$$$ chi1=chi(itypi,itypj)
1272 c$$$ chi2=chi(itypj,itypi)
1273 c$$$ chi12=chi1*chi2
1274 c$$$ chip1=chip(itypi)
1275 c$$$ chip2=chip(itypj)
1276 c$$$ chip12=chip1*chip2
1277 c$$$ alf1=alp(itypi)
1278 c$$$ alf2=alp(itypj)
1279 c$$$ alf12=0.5D0*(alf1+alf2)
1280 c$$$C For diagnostics only!!!
1290 c$$$ xj=c(1,nres+j)-xi
1291 c$$$ yj=c(2,nres+j)-yi
1292 c$$$ zj=c(3,nres+j)-zi
1293 c$$$ dxj=dc_norm(1,nres+j)
1294 c$$$ dyj=dc_norm(2,nres+j)
1295 c$$$ dzj=dc_norm(3,nres+j)
1296 c$$$c write (iout,*) "dcnorj",dxi*dxi+dyi*dyi+dzi*dzi
1297 c$$$c write (iout,*) "j",j," dc_norm",
1298 c$$$c & dc_norm(1,nres+j),dc_norm(2,nres+j),dc_norm(3,nres+j)
1299 c$$$ rrij=1.0D0/(xj*xj+yj*yj+zj*zj)
1300 c$$$ rij=dsqrt(rrij)
1301 c$$$C Calculate angle-dependent terms of energy and contributions to their
1303 c$$$ call sc_angular
1304 c$$$ sigsq=1.0D0/sigsq
1305 c$$$ sig=sig0ij*dsqrt(sigsq)
1306 c$$$ rij_shift=1.0D0/rij-sig+sig0ij
1307 c$$$c for diagnostics; uncomment
1308 c$$$c rij_shift=1.2*sig0ij
1309 c$$$C I hate to put IF's in the loops, but here don't have another choice!!!!
1310 c$$$ if (rij_shift.le.0.0D0) then
1312 c$$$cd write (iout,'(2(a3,i3,2x),17(0pf7.3))')
1313 c$$$cd & restyp(itypi),i,restyp(itypj),j,
1314 c$$$cd & rij_shift,1.0D0/rij,sig,sig0ij,sigsq,1-dsqrt(sigsq)
1317 c$$$ sigder=-sig*sigsq
1318 c$$$c---------------------------------------------------------------
1319 c$$$ rij_shift=1.0D0/rij_shift
1320 c$$$ fac=rij_shift**expon
1321 c$$$ e1=fac*fac*aa(itypi,itypj)
1322 c$$$ e2=fac*bb(itypi,itypj)
1323 c$$$ evdwij=eps1*eps2rt*eps3rt*(e1+e2)
1324 c$$$ eps2der=evdwij*eps3rt
1325 c$$$ eps3der=evdwij*eps2rt
1326 c$$$c write (iout,*) "sigsq",sigsq," sig",sig," eps2rt",eps2rt,
1327 c$$$c & " eps3rt",eps3rt," eps1",eps1," e1",e1," e2",e2
1328 c$$$ evdwij=evdwij*eps2rt*eps3rt
1329 c$$$ evdw=evdw+evdwij
1331 c$$$ sigm=dabs(aa(itypi,itypj)/bb(itypi,itypj))**(1.0D0/6.0D0)
1332 c$$$ epsi=bb(itypi,itypj)**2/aa(itypi,itypj)
1333 c$$$ write (iout,'(2(a3,i3,2x),17(0pf7.3))')
1334 c$$$ & restyp(itypi),i,restyp(itypj),j,
1335 c$$$ & epsi,sigm,chi1,chi2,chip1,chip2,
1336 c$$$ & eps1,eps2rt**2,eps3rt**2,sig,sig0ij,
1337 c$$$ & om1,om2,om12,1.0D0/rij,1.0D0/rij_shift,
1341 c$$$ if (energy_dec) write (iout,'(a6,2i,0pf7.3)')
1342 c$$$ & 'evdw',i,j,evdwij
1344 c$$$C Calculate gradient components.
1345 c$$$ e1=e1*eps1*eps2rt**2*eps3rt**2
1346 c$$$ fac=-expon*(e1+evdwij)*rij_shift
1347 c$$$ sigder=fac*sigder
1350 c$$$C Calculate the radial part of the gradient
1354 c$$$C Calculate angular part of the gradient.
1360 c$$$ energy_dec=.false.
1364 c$$$c-----------------------------------------------------------------------------
1366 c$$$ subroutine esc_sc(escloc)
1367 c$$$C Calculate the local energy of a side chain and its derivatives in the
1368 c$$$C corresponding virtual-bond valence angles THETA and the spherical angles
1369 c$$$C ALPHA and OMEGA.
1370 c$$$ implicit real*8 (a-h,o-z)
1371 c$$$ include 'DIMENSIONS'
1372 c$$$ include 'COMMON.GEO'
1373 c$$$ include 'COMMON.LOCAL'
1374 c$$$ include 'COMMON.VAR'
1375 c$$$ include 'COMMON.INTERACT'
1376 c$$$ include 'COMMON.DERIV'
1377 c$$$ include 'COMMON.CHAIN'
1378 c$$$ include 'COMMON.IOUNITS'
1379 c$$$ include 'COMMON.NAMES'
1380 c$$$ include 'COMMON.FFIELD'
1381 c$$$ include 'COMMON.CONTROL'
1382 c$$$ double precision x(3),dersc(3),xemp(3),dersc0(3),dersc1(3),
1383 c$$$ & ddersc0(3),ddummy(3),xtemp(3),temp(3)
1384 c$$$ common /sccalc/ time11,time12,time112,theti,it,nlobit
1385 c$$$ delta=0.02d0*pi
1387 c$$$c write (iout,'(a)') 'ESC'
1388 c$$$ do i=loc_start,loc_end
1389 c$$$ IF (mask_side(i).eq.1) THEN
1391 c$$$ if (it.eq.10) goto 1
1392 c$$$ nlobit=nlob(it)
1393 c$$$c print *,'i=',i,' it=',it,' nlobit=',nlobit
1394 c$$$c write (iout,*) 'i=',i,' ssa=',ssa,' ssad=',ssad
1395 c$$$ theti=theta(i+1)-pipol
1396 c$$$ x(1)=dtan(theti)
1400 c$$$ if (x(2).gt.pi-delta) then
1402 c$$$ xtemp(2)=pi-delta
1404 c$$$ call enesc(xtemp,escloci0,dersc0,ddersc0,.true.)
1406 c$$$ call enesc(xtemp,escloci1,dersc1,ddummy,.false.)
1407 c$$$ call spline1(x(2),pi-delta,delta,escloci0,escloci1,dersc0(2),
1408 c$$$ & escloci,dersc(2))
1409 c$$$ call spline2(x(2),pi-delta,delta,dersc0(1),dersc1(1),
1410 c$$$ & ddersc0(1),dersc(1))
1411 c$$$ call spline2(x(2),pi-delta,delta,dersc0(3),dersc1(3),
1412 c$$$ & ddersc0(3),dersc(3))
1413 c$$$ xtemp(2)=pi-delta
1414 c$$$ call enesc_bound(xtemp,esclocbi0,dersc0,dersc12,.true.)
1416 c$$$ call enesc_bound(xtemp,esclocbi1,dersc1,chuju,.false.)
1417 c$$$ call spline1(x(2),pi-delta,delta,esclocbi0,esclocbi1,
1418 c$$$ & dersc0(2),esclocbi,dersc02)
1419 c$$$ call spline2(x(2),pi-delta,delta,dersc0(1),dersc1(1),
1420 c$$$ & dersc12,dersc01)
1421 c$$$ call splinthet(x(2),0.5d0*delta,ss,ssd)
1422 c$$$ dersc0(1)=dersc01
1423 c$$$ dersc0(2)=dersc02
1424 c$$$ dersc0(3)=0.0d0
1426 c$$$ dersc(k)=ss*dersc(k)+(1.0d0-ss)*dersc0(k)
1428 c$$$ dersc(2)=dersc(2)+ssd*(escloci-esclocbi)
1429 c$$$c write (iout,*) 'i=',i,x(2)*rad2deg,escloci0,escloci,
1430 c$$$c & esclocbi,ss,ssd
1431 c$$$ escloci=ss*escloci+(1.0d0-ss)*esclocbi
1432 c$$$c escloci=esclocbi
1433 c$$$c write (iout,*) escloci
1434 c$$$ else if (x(2).lt.delta) then
1438 c$$$ call enesc(xtemp,escloci0,dersc0,ddersc0,.true.)
1440 c$$$ call enesc(xtemp,escloci1,dersc1,ddummy,.false.)
1441 c$$$ call spline1(x(2),delta,-delta,escloci0,escloci1,dersc0(2),
1442 c$$$ & escloci,dersc(2))
1443 c$$$ call spline2(x(2),delta,-delta,dersc0(1),dersc1(1),
1444 c$$$ & ddersc0(1),dersc(1))
1445 c$$$ call spline2(x(2),delta,-delta,dersc0(3),dersc1(3),
1446 c$$$ & ddersc0(3),dersc(3))
1448 c$$$ call enesc_bound(xtemp,esclocbi0,dersc0,dersc12,.true.)
1450 c$$$ call enesc_bound(xtemp,esclocbi1,dersc1,chuju,.false.)
1451 c$$$ call spline1(x(2),delta,-delta,esclocbi0,esclocbi1,
1452 c$$$ & dersc0(2),esclocbi,dersc02)
1453 c$$$ call spline2(x(2),delta,-delta,dersc0(1),dersc1(1),
1454 c$$$ & dersc12,dersc01)
1455 c$$$ dersc0(1)=dersc01
1456 c$$$ dersc0(2)=dersc02
1457 c$$$ dersc0(3)=0.0d0
1458 c$$$ call splinthet(x(2),0.5d0*delta,ss,ssd)
1460 c$$$ dersc(k)=ss*dersc(k)+(1.0d0-ss)*dersc0(k)
1462 c$$$ dersc(2)=dersc(2)+ssd*(escloci-esclocbi)
1463 c$$$c write (iout,*) 'i=',i,x(2)*rad2deg,escloci0,escloci,
1464 c$$$c & esclocbi,ss,ssd
1465 c$$$ escloci=ss*escloci+(1.0d0-ss)*esclocbi
1466 c$$$c write (iout,*) escloci
1468 c$$$ call enesc(x,escloci,dersc,ddummy,.false.)
1471 c$$$ escloc=escloc+escloci
1472 c$$$ if (energy_dec) write (iout,'(a6,i,0pf7.3)')
1473 c$$$ & 'escloc',i,escloci
1474 c$$$c write (iout,*) 'i=',i,' escloci=',escloci,' dersc=',dersc
1476 c$$$ gloc(nphi+i-1,icg)=gloc(nphi+i-1,icg)+
1477 c$$$ & wscloc*dersc(1)
1478 c$$$ gloc(ialph(i,1),icg)=wscloc*dersc(2)
1479 c$$$ gloc(ialph(i,1)+nside,icg)=wscloc*dersc(3)
1486 c$$$C-----------------------------------------------------------------------------
1488 c$$$ subroutine egb_ij(i_sc,j_sc,evdw)
1490 c$$$C This subroutine calculates the interaction energy of nonbonded side chains
1491 c$$$C assuming the Gay-Berne potential of interaction.
1493 c$$$ implicit real*8 (a-h,o-z)
1494 c$$$ include 'DIMENSIONS'
1495 c$$$ include 'COMMON.GEO'
1496 c$$$ include 'COMMON.VAR'
1497 c$$$ include 'COMMON.LOCAL'
1498 c$$$ include 'COMMON.CHAIN'
1499 c$$$ include 'COMMON.DERIV'
1500 c$$$ include 'COMMON.NAMES'
1501 c$$$ include 'COMMON.INTERACT'
1502 c$$$ include 'COMMON.IOUNITS'
1503 c$$$ include 'COMMON.CALC'
1504 c$$$ include 'COMMON.CONTROL'
1507 c$$$ energy_dec=.false.
1508 c$$$c print *,'Entering EGB nnt=',nnt,' nct=',nct,' expon=',expon
1512 c$$$c$$$ do i=iatsc_s,iatsc_e
1515 c$$$ itypi1=itype(i+1)
1519 c$$$ dxi=dc_norm(1,nres+i)
1520 c$$$ dyi=dc_norm(2,nres+i)
1521 c$$$ dzi=dc_norm(3,nres+i)
1522 c$$$c dsci_inv=dsc_inv(itypi)
1523 c$$$ dsci_inv=vbld_inv(i+nres)
1524 c$$$c write (iout,*) "i",i,dsc_inv(itypi),dsci_inv,1.0d0/vbld(i+nres)
1525 c$$$c write (iout,*) "dcnori",dxi*dxi+dyi*dyi+dzi*dzi
1527 c$$$C Calculate SC interaction energy.
1529 c$$$c$$$ do iint=1,nint_gr(i)
1530 c$$$c$$$ do j=istart(i,iint),iend(i,iint)
1534 c$$$c dscj_inv=dsc_inv(itypj)
1535 c$$$ dscj_inv=vbld_inv(j+nres)
1536 c$$$c write (iout,*) "j",j,dsc_inv(itypj),dscj_inv,
1537 c$$$c & 1.0d0/vbld(j+nres)
1538 c$$$c write (iout,*) "i",i," j", j," itype",itype(i),itype(j)
1539 c$$$ sig0ij=sigma(itypi,itypj)
1540 c$$$ chi1=chi(itypi,itypj)
1541 c$$$ chi2=chi(itypj,itypi)
1542 c$$$ chi12=chi1*chi2
1543 c$$$ chip1=chip(itypi)
1544 c$$$ chip2=chip(itypj)
1545 c$$$ chip12=chip1*chip2
1546 c$$$ alf1=alp(itypi)
1547 c$$$ alf2=alp(itypj)
1548 c$$$ alf12=0.5D0*(alf1+alf2)
1549 c$$$C For diagnostics only!!!
1559 c$$$ xj=c(1,nres+j)-xi
1560 c$$$ yj=c(2,nres+j)-yi
1561 c$$$ zj=c(3,nres+j)-zi
1562 c$$$ dxj=dc_norm(1,nres+j)
1563 c$$$ dyj=dc_norm(2,nres+j)
1564 c$$$ dzj=dc_norm(3,nres+j)
1565 c$$$c write (iout,*) "dcnorj",dxi*dxi+dyi*dyi+dzi*dzi
1566 c$$$c write (iout,*) "j",j," dc_norm",
1567 c$$$c & dc_norm(1,nres+j),dc_norm(2,nres+j),dc_norm(3,nres+j)
1568 c$$$ rrij=1.0D0/(xj*xj+yj*yj+zj*zj)
1569 c$$$ rij=dsqrt(rrij)
1570 c$$$C Calculate angle-dependent terms of energy and contributions to their
1572 c$$$ call sc_angular
1573 c$$$ sigsq=1.0D0/sigsq
1574 c$$$ sig=sig0ij*dsqrt(sigsq)
1575 c$$$ rij_shift=1.0D0/rij-sig+sig0ij
1576 c$$$c for diagnostics; uncomment
1577 c$$$c rij_shift=1.2*sig0ij
1578 c$$$C I hate to put IF's in the loops, but here don't have another choice!!!!
1579 c$$$ if (rij_shift.le.0.0D0) then
1581 c$$$cd write (iout,'(2(a3,i3,2x),17(0pf7.3))')
1582 c$$$cd & restyp(itypi),i,restyp(itypj),j,
1583 c$$$cd & rij_shift,1.0D0/rij,sig,sig0ij,sigsq,1-dsqrt(sigsq)
1586 c$$$ sigder=-sig*sigsq
1587 c$$$c---------------------------------------------------------------
1588 c$$$ rij_shift=1.0D0/rij_shift
1589 c$$$ fac=rij_shift**expon
1590 c$$$ e1=fac*fac*aa(itypi,itypj)
1591 c$$$ e2=fac*bb(itypi,itypj)
1592 c$$$ evdwij=eps1*eps2rt*eps3rt*(e1+e2)
1593 c$$$ eps2der=evdwij*eps3rt
1594 c$$$ eps3der=evdwij*eps2rt
1595 c$$$c write (iout,*) "sigsq",sigsq," sig",sig," eps2rt",eps2rt,
1596 c$$$c & " eps3rt",eps3rt," eps1",eps1," e1",e1," e2",e2
1597 c$$$ evdwij=evdwij*eps2rt*eps3rt
1598 c$$$ evdw=evdw+evdwij
1600 c$$$ sigm=dabs(aa(itypi,itypj)/bb(itypi,itypj))**(1.0D0/6.0D0)
1601 c$$$ epsi=bb(itypi,itypj)**2/aa(itypi,itypj)
1602 c$$$ write (iout,'(2(a3,i3,2x),17(0pf7.3))')
1603 c$$$ & restyp(itypi),i,restyp(itypj),j,
1604 c$$$ & epsi,sigm,chi1,chi2,chip1,chip2,
1605 c$$$ & eps1,eps2rt**2,eps3rt**2,sig,sig0ij,
1606 c$$$ & om1,om2,om12,1.0D0/rij,1.0D0/rij_shift,
1610 c$$$ if (energy_dec) write (iout,'(a6,2i,0pf7.3)')
1611 c$$$ & 'evdw',i,j,evdwij
1613 c$$$C Calculate gradient components.
1614 c$$$ e1=e1*eps1*eps2rt**2*eps3rt**2
1615 c$$$ fac=-expon*(e1+evdwij)*rij_shift
1616 c$$$ sigder=fac*sigder
1619 c$$$C Calculate the radial part of the gradient
1623 c$$$C Calculate angular part of the gradient.
1626 c$$$c$$$ enddo ! iint
1628 c$$$ energy_dec=.false.
1632 c$$$C-----------------------------------------------------------------------------
1634 c$$$ subroutine perturb_side_chain(i,angle)
1638 c$$$ include 'DIMENSIONS'
1639 c$$$ include 'COMMON.CHAIN'
1640 c$$$ include 'COMMON.GEO'
1641 c$$$ include 'COMMON.VAR'
1642 c$$$ include 'COMMON.LOCAL'
1643 c$$$ include 'COMMON.IOUNITS'
1645 c$$$c External functions
1646 c$$$ external ran_number
1647 c$$$ double precision ran_number
1649 c$$$c Input arguments
1651 c$$$ double precision angle ! In degrees
1653 c$$$c Local variables
1655 c$$$ double precision rad_ang,rand_v(3),length,cost,sint
1659 c$$$ rad_ang=angle*deg2rad
1662 c$$$ do while (length.lt.0.01)
1663 c$$$ rand_v(1)=ran_number(0.01D0,1.0D0)
1664 c$$$ rand_v(2)=ran_number(0.01D0,1.0D0)
1665 c$$$ rand_v(3)=ran_number(0.01D0,1.0D0)
1666 c$$$ length=rand_v(1)*rand_v(1)+rand_v(2)*rand_v(2)+
1667 c$$$ + rand_v(3)*rand_v(3)
1668 c$$$ length=sqrt(length)
1669 c$$$ rand_v(1)=rand_v(1)/length
1670 c$$$ rand_v(2)=rand_v(2)/length
1671 c$$$ rand_v(3)=rand_v(3)/length
1672 c$$$ cost=rand_v(1)*dc_norm(1,i_sc)+rand_v(2)*dc_norm(2,i_sc)+
1673 c$$$ + rand_v(3)*dc_norm(3,i_sc)
1674 c$$$ length=1.0D0-cost*cost
1675 c$$$ if (length.lt.0.0D0) length=0.0D0
1676 c$$$ length=sqrt(length)
1677 c$$$ rand_v(1)=rand_v(1)-cost*dc_norm(1,i_sc)
1678 c$$$ rand_v(2)=rand_v(2)-cost*dc_norm(2,i_sc)
1679 c$$$ rand_v(3)=rand_v(3)-cost*dc_norm(3,i_sc)
1681 c$$$ rand_v(1)=rand_v(1)/length
1682 c$$$ rand_v(2)=rand_v(2)/length
1683 c$$$ rand_v(3)=rand_v(3)/length
1685 c$$$ cost=dcos(rad_ang)
1686 c$$$ sint=dsin(rad_ang)
1687 c$$$ dc(1,i_sc)=vbld(i_sc)*(dc_norm(1,i_sc)*cost+rand_v(1)*sint)
1688 c$$$ dc(2,i_sc)=vbld(i_sc)*(dc_norm(2,i_sc)*cost+rand_v(2)*sint)
1689 c$$$ dc(3,i_sc)=vbld(i_sc)*(dc_norm(3,i_sc)*cost+rand_v(3)*sint)
1690 c$$$ dc_norm(1,i_sc)=dc(1,i_sc)*vbld_inv(i_sc)
1691 c$$$ dc_norm(2,i_sc)=dc(2,i_sc)*vbld_inv(i_sc)
1692 c$$$ dc_norm(3,i_sc)=dc(3,i_sc)*vbld_inv(i_sc)
1693 c$$$ c(1,i_sc)=c(1,i)+dc(1,i_sc)
1694 c$$$ c(2,i_sc)=c(2,i)+dc(2,i_sc)
1695 c$$$ c(3,i_sc)=c(3,i)+dc(3,i_sc)
1697 c$$$ call chainbuild_cart
1702 c$$$c----------------------------------------------------------------------------
1704 c$$$ subroutine ss_relax3(i_in,j_in)
1708 c$$$ include 'DIMENSIONS'
1709 c$$$ include 'COMMON.VAR'
1710 c$$$ include 'COMMON.CHAIN'
1711 c$$$ include 'COMMON.IOUNITS'
1712 c$$$ include 'COMMON.INTERACT'
1714 c$$$c External functions
1715 c$$$ external ran_number
1716 c$$$ double precision ran_number
1718 c$$$c Input arguments
1719 c$$$ integer i_in,j_in
1721 c$$$c Local variables
1722 c$$$ double precision energy_sc(0:n_ene),etot
1723 c$$$ double precision org_dc(3),org_dc_norm(3),org_c(3)
1724 c$$$ double precision ang_pert,rand_fact,exp_fact,beta
1725 c$$$ integer n,i_pert,i
1726 c$$$ logical notdone
1735 c$$$ mask_side(i_in)=1
1736 c$$$ mask_side(j_in)=1
1738 c$$$ call etotal_sc(energy_sc)
1739 c$$$ etot=energy_sc(0)
1740 c$$$c write(iout,'(a,3d15.5)')" SS_MC_START ",energy_sc(0),
1741 c$$$c + energy_sc(1),energy_sc(12)
1745 c$$$ do while (notdone)
1746 c$$$ if (mod(n,2).eq.0) then
1754 c$$$ org_dc(i)=dc(i,i_pert+nres)
1755 c$$$ org_dc_norm(i)=dc_norm(i,i_pert+nres)
1756 c$$$ org_c(i)=c(i,i_pert+nres)
1758 c$$$ ang_pert=ran_number(0.0D0,3.0D0)
1759 c$$$ call perturb_side_chain(i_pert,ang_pert)
1760 c$$$ call etotal_sc(energy_sc)
1761 c$$$ exp_fact=exp(beta*(etot-energy_sc(0)))
1762 c$$$ rand_fact=ran_number(0.0D0,1.0D0)
1763 c$$$ if (rand_fact.lt.exp_fact) then
1764 c$$$c write(iout,'(a,3d15.5)')" SS_MC_ACCEPT ",energy_sc(0),
1765 c$$$c + energy_sc(1),energy_sc(12)
1766 c$$$ etot=energy_sc(0)
1768 c$$$c write(iout,'(a,3d15.5)')" SS_MC_REJECT ",energy_sc(0),
1769 c$$$c + energy_sc(1),energy_sc(12)
1771 c$$$ dc(i,i_pert+nres)=org_dc(i)
1772 c$$$ dc_norm(i,i_pert+nres)=org_dc_norm(i)
1773 c$$$ c(i,i_pert+nres)=org_c(i)
1777 c$$$ if (n.eq.10000.or.etot.lt.30.0D0) notdone=.false.
1785 c$$$c----------------------------------------------------------------------------
1787 c$$$ subroutine ss_relax2(etot,iretcode,nfun,i_in,j_in)
1789 c$$$ include 'DIMENSIONS'
1791 c$$$ parameter (liv=60,lv=(77+maxres6*(maxres6+17)/2))
1792 c$$$*********************************************************************
1793 c$$$* OPTIMIZE sets up SUMSL or DFP and provides a simple interface for *
1794 c$$$* the calling subprogram. *
1795 c$$$* when d(i)=1.0, then v(35) is the length of the initial step, *
1796 c$$$* calculated in the usual pythagorean way. *
1797 c$$$* absolute convergence occurs when the function is within v(31) of *
1798 c$$$* zero. unless you know the minimum value in advance, abs convg *
1799 c$$$* is probably not useful. *
1800 c$$$* relative convergence is when the model predicts that the function *
1801 c$$$* will decrease by less than v(32)*abs(fun). *
1802 c$$$*********************************************************************
1803 c$$$ include 'COMMON.IOUNITS'
1804 c$$$ include 'COMMON.VAR'
1805 c$$$ include 'COMMON.GEO'
1806 c$$$ include 'COMMON.MINIM'
1807 c$$$ include 'COMMON.CHAIN'
1809 c$$$ double precision orig_ss_dc,orig_ss_var,orig_ss_dist
1810 c$$$ common /orig_ss/ orig_ss_dc(3,0:maxres2),orig_ss_var(maxvar),
1811 c$$$ + orig_ss_dist(maxres2,maxres2)
1813 c$$$ double precision etot
1814 c$$$ integer iretcode,nfun,i_in,j_in
1817 c$$$ double precision dist
1818 c$$$ external ss_func,fdum
1819 c$$$ double precision ss_func,fdum
1821 c$$$ integer iv(liv),uiparm(2)
1822 c$$$ double precision v(lv),x(maxres6),d(maxres6),rdum
1826 c$$$ call deflt(2,iv,liv,lv,v)
1827 c$$$* 12 means fresh start, dont call deflt
1829 c$$$* max num of fun calls
1830 c$$$ if (maxfun.eq.0) maxfun=500
1832 c$$$* max num of iterations
1833 c$$$ if (maxmin.eq.0) maxmin=1000
1835 c$$$* controls output
1837 c$$$* selects output unit
1840 c$$$* 1 means to print out result
1842 c$$$* 1 means to print out summary stats
1844 c$$$* 1 means to print initial x and d
1846 c$$$* min val for v(radfac) default is 0.1
1848 c$$$* max val for v(radfac) default is 4.0
1851 c$$$* check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)
1852 c$$$* the sumsl default is 0.1
1854 c$$$* false conv if (act fnctn decrease) .lt. v(34)
1855 c$$$* the sumsl default is 100*machep
1856 c$$$ v(34)=v(34)/100.0D0
1857 c$$$* absolute convergence
1858 c$$$ if (tolf.eq.0.0D0) tolf=1.0D-4
1861 c$$$* relative convergence
1862 c$$$ if (rtolf.eq.0.0D0) rtolf=1.0D-4
1865 c$$$* controls initial step size
1867 c$$$* large vals of d correspond to small components of step
1874 c$$$ orig_ss_dc(j,i)=dc(j,i)
1877 c$$$ call geom_to_var(nvar,orig_ss_var)
1881 c$$$ orig_ss_dist(j,i)=dist(j,i)
1882 c$$$ orig_ss_dist(j+nres,i)=dist(j+nres,i)
1883 c$$$ orig_ss_dist(j,i+nres)=dist(j,i+nres)
1884 c$$$ orig_ss_dist(j+nres,i+nres)=dist(j+nres,i+nres)
1896 c$$$ if (ialph(i,1).gt.0) then
1899 c$$$ x(k)=dc(j,i+nres)
1906 c$$$ call smsno(k,d,x,ss_func,iv,liv,lv,v,uiparm,rdum,fdum)
1909 c$$$ nfun=iv(6)+iv(30)
1919 c$$$ if (ialph(i,1).gt.0) then
1922 c$$$ dc(j,i+nres)=x(k)
1926 c$$$ call chainbuild_cart
1931 c$$$C-----------------------------------------------------------------------------
1933 c$$$ subroutine ss_func(n,x,nf,f,uiparm,urparm,ufparm)
1935 c$$$ include 'DIMENSIONS'
1936 c$$$ include 'COMMON.DERIV'
1937 c$$$ include 'COMMON.IOUNITS'
1938 c$$$ include 'COMMON.VAR'
1939 c$$$ include 'COMMON.CHAIN'
1940 c$$$ include 'COMMON.INTERACT'
1941 c$$$ include 'COMMON.SBRIDGE'
1943 c$$$ double precision orig_ss_dc,orig_ss_var,orig_ss_dist
1944 c$$$ common /orig_ss/ orig_ss_dc(3,0:maxres2),orig_ss_var(maxvar),
1945 c$$$ + orig_ss_dist(maxres2,maxres2)
1948 c$$$ double precision x(maxres6)
1950 c$$$ double precision f
1951 c$$$ integer uiparm(2)
1952 c$$$ real*8 urparm(1)
1953 c$$$ external ufparm
1954 c$$$ double precision ufparm
1957 c$$$ double precision dist
1959 c$$$ integer i,j,k,ss_i,ss_j
1960 c$$$ double precision tempf,var(maxvar)
1975 c$$$ if (ialph(i,1).gt.0) then
1978 c$$$ dc(j,i+nres)=x(k)
1982 c$$$ call chainbuild_cart
1984 c$$$ call geom_to_var(nvar,var)
1986 c$$$c Constraints on all angles
1988 c$$$ tempf=var(i)-orig_ss_var(i)
1989 c$$$ f=f+tempf*tempf
1992 c$$$c Constraints on all distances
1994 c$$$ if (i.gt.1) then
1995 c$$$ tempf=dist(i+nres,i)-orig_ss_dist(i+nres,i)
1996 c$$$ f=f+tempf*tempf
1999 c$$$ tempf=dist(j,i)-orig_ss_dist(j,i)
2000 c$$$ if (tempf.lt.0.0D0 .or. j.eq.i+1) f=f+tempf*tempf
2001 c$$$ tempf=dist(j+nres,i)-orig_ss_dist(j+nres,i)
2002 c$$$ if (tempf.lt.0.0D0) f=f+tempf*tempf
2003 c$$$ tempf=dist(j,i+nres)-orig_ss_dist(j,i+nres)
2004 c$$$ if (tempf.lt.0.0D0) f=f+tempf*tempf
2005 c$$$ tempf=dist(j+nres,i+nres)-orig_ss_dist(j+nres,i+nres)
2006 c$$$ if (tempf.lt.0.0D0) f=f+tempf*tempf
2010 c$$$c Constraints for the relevant CYS-CYS
2011 c$$$ tempf=dist(nres+ss_i,nres+ss_j)-8.0D0
2012 c$$$ f=f+tempf*tempf
2013 c$$$CCCCCCCCCCCCCCCCC ADD SOME ANGULAR STUFF
2015 c$$$c$$$ if (nf.ne.nfl) then
2016 c$$$c$$$ write(iout,'(a,i10,2d15.5)')"IN DIST_FUNC (NF,F,DIST)",nf,
2017 c$$$c$$$ + f,dist(5+nres,14+nres)
2025 c$$$C-----------------------------------------------------------------------------
2026 c$$$C-----------------------------------------------------------------------------
2027 subroutine triple_ssbond_ene(resi,resj,resk,eij)
2028 include 'DIMENSIONS'
2029 include 'COMMON.SBRIDGE'
2030 include 'COMMON.CHAIN'
2031 include 'COMMON.DERIV'
2032 include 'COMMON.LOCAL'
2033 include 'COMMON.INTERACT'
2034 include 'COMMON.VAR'
2035 include 'COMMON.IOUNITS'
2036 include 'COMMON.CALC'
2039 C include 'COMMON.MD'
2043 c External functions
2044 double precision h_base
2048 integer resi,resj,resk
2051 double precision eij,eij1,eij2,eij3
2055 c integer itypi,itypj,k,l
2056 double precision rrij,ssd,deltat1,deltat2,deltat12,cosphi
2057 double precision rrik,rrjk,rik,rjk,xi,xk,yi,yk,zi,zk,xij,yij,zij
2058 double precision xik,yik,zik,xjk,yjk,zjk
2059 double precision sig0ij,ljd,sig,fac,e1,e2
2060 double precision dcosom1(3),dcosom2(3),ed
2061 double precision pom1,pom2
2062 double precision ljA,ljB,ljXs
2063 double precision d_ljB(1:3)
2064 double precision ssA,ssB,ssC,ssXs
2065 double precision ssxm,ljxm,ssm,ljm
2066 double precision d_ssxm(1:3),d_ljxm(1:3),d_ssm(1:3),d_ljm(1:3)
2071 C write(iout,*) resi,resj,resk
2073 dxi=dc_norm(1,nres+i)
2074 dyi=dc_norm(2,nres+i)
2075 dzi=dc_norm(3,nres+i)
2076 dsci_inv=vbld_inv(i+nres)
2086 dxj=dc_norm(1,nres+j)
2087 dyj=dc_norm(2,nres+j)
2088 dzj=dc_norm(3,nres+j)
2089 dscj_inv=vbld_inv(j+nres)
2095 dxk=dc_norm(1,nres+k)
2096 dyk=dc_norm(2,nres+k)
2097 dzk=dc_norm(3,nres+k)
2098 dscj_inv=vbld_inv(k+nres)
2108 rrij=(xij*xij+yij*yij+zij*zij)
2109 rij=dsqrt(rrij) ! sc_angular needs rij to really be the inverse
2110 rrik=(xik*xik+yik*yik+zik*zik)
2112 rrjk=(xjk*xjk+yjk*yjk+zjk*zjk)
2114 C there are three combination of distances for each trisulfide bonds
2115 C The first case the ith atom is the center
2116 C Energy function is E=d/(a*(x-y)**2+b*(x+y)**2+c) where x is first
2117 C distance y is second distance the a,b,c,d are parameters derived for
2118 C this problem d parameter was set as a penalty currenlty set to 1.
2119 eij1=dtriss/(atriss*(rij-rik)**2+btriss*(rij+rik)**2+ctriss)
2120 C second case jth atom is center
2121 eij2=dtriss/(atriss*(rij-rjk)**2+btriss*(rij+rjk)**2+ctriss)
2122 C the third case kth atom is the center
2123 eij3=dtriss/(atriss*(rik-rjk)**2+btriss*(rik+rjk)**2+ctriss)
2128 C write(iout,*)i,j,k,eij
2129 C The energy penalty calculated now time for the gradient part
2130 C derivative over rij
2131 fac=-eij1**2/dtriss*(2.0*atriss*(rij-rik)+2.0*btriss*(rij+rik))
2132 &-eij2**2/dtriss*(2.0*atriss*(rij-rjk)+2.0*btriss*(rij+rjk))
2137 gvdwx(m,i)=gvdwx(m,i)-gg(m)
2138 gvdwx(m,j)=gvdwx(m,j)+gg(m)
2141 gvdwc(l,i)=gvdwc(l,i)-gg(l)
2142 gvdwc(l,j)=gvdwc(l,j)+gg(l)
2144 C now derivative over rik
2145 fac=-eij1**2/dtriss*(-2.0*atriss*(rij-rik)+2.0*btriss*(rij+rik))
2146 &-eij3**2/dtriss*(2.0*atriss*(rik-rjk)+2.0*btriss*(rik+rjk))
2151 gvdwx(m,i)=gvdwx(m,i)-gg(m)
2152 gvdwx(m,k)=gvdwx(m,k)+gg(m)
2155 gvdwc(l,i)=gvdwc(l,i)-gg(l)
2156 gvdwc(l,k)=gvdwc(l,k)+gg(l)
2158 C now derivative over rjk
2159 fac=-eij2**2/dtriss*(-2.0*atriss*(rij-rjk)+2.0*btriss*(rij+rjk))-
2160 &eij3**2/dtriss*(-2.0*atriss*(rik-rjk)+2.0*btriss*(rik+rjk))
2165 gvdwx(m,j)=gvdwx(m,j)-gg(m)
2166 gvdwx(m,k)=gvdwx(m,k)+gg(m)
2169 gvdwc(l,j)=gvdwc(l,j)-gg(l)
2170 gvdwc(l,k)=gvdwc(l,k)+gg(l)