1 subroutine friction_force
9 include 'COMMON.INTERACT'
12 include 'COMMON.LAGRANGE.5diag'
14 include 'COMMON.LAGRANGE'
17 include 'COMMON.LANGEVIN'
20 include 'COMMON.LANGEVIN.lang0.5diag'
22 include 'COMMON.LANGEVIN.lang0'
25 include 'COMMON.IOUNITS'
27 integer iposc,ichain,n,innt,inct
28 double precision v_work(3,maxres2),vvec(maxres2_chain),rs(maxres2)
30 double precision gamvec(MAXRES6)
32 double precision vv(3),vvtot(3,maxres),v_work(MAXRES6),
33 & ginvfric(maxres2,maxres2)
34 common /przechowalnia/ ginvfric
38 logical lprn /.false./, checkmode /.false./
40 c Here accelerations due to friction forces are computed right after forces.
44 v_work(j,nnt)=d_t(j,0)
48 v_work(j,i)=v_work(j,i-1)+d_t(j,i-1)
52 if (iabs(itype(i)).ne.10 .and. iabs(itype(i)).ne.ntyp1) then
54 v_work(j,i+nres)=v_work(j,i)+d_t(j,i+nres)
59 write (iout,*) "v_work"
61 write (iout,'(i5,3f10.5)') i,(v_work(j,i),j=1,3)
68 iposc=iposd_chain(ichain)
69 c write (iout,*) "friction_force j",j," ichain",ichain,
70 c & " n",n," iposc",iposc,iposc+n-1
71 innt=chain_border(1,ichain)
72 inct=chain_border(2,ichain)
74 vvec(ind+1)=v_work(j,i)
76 if (iabs(itype(i)).ne.10) then
77 vvec(ind+1)=v_work(j,i+nres)
82 write (iout,*) "vvec ind",ind," n",n
83 write (iout,'(f10.5)') (vvec(i),i=iposc,ind)
85 c write (iout,*) "chain",i," ind",ind," n",n
86 call fivediagmult(n,DMfric(iposc),DU1fric(iposc),
87 & DU2fric(iposc),vvec(iposc),rs)
90 write (iout,'(f10.5)') (rs(i),i=1,n)
93 c write (iout,*) "ichain",ichain," i",i," j",j,
94 c & "index",3*(i-1)+j,"rs",rs(i-iposc+1)
95 fric_work(3*(i-1)+j)=-rs(i-iposc+1)
100 write (iout,*) "Vector fric_work dimen3",dimen3
101 write (iout,'(3f10.5)') (fric_work(j),j=1,dimen3)
116 d_t_work(ind+j)=d_t(j,i)
121 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
123 d_t_work(ind+j)=d_t(j,i+nres)
129 call fricmat_mult(d_t_work,fric_work)
131 if (.not.checkmode) return
134 write (iout,*) "d_t_work and fric_work"
136 write (iout,'(i3,2e15.5)') i,d_t_work(i),fric_work(i)
140 friction(j,0)=fric_work(j)
145 friction(j,i)=fric_work(ind+j)
150 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
152 friction(j,i+nres)=fric_work(ind+j)
158 write(iout,*) "Friction backbone"
160 write(iout,'(i5,3e15.5,5x,3e15.5)')
161 & i,(friction(j,i),j=1,3),(d_t(j,i),j=1,3)
163 write(iout,*) "Friction side chain"
165 write(iout,'(i5,3e15.5,5x,3e15.5)')
166 & i,(friction(j,i+nres),j=1,3),(d_t(j,i+nres),j=1,3)
175 vvtot(j,i)=vv(j)+0.5d0*d_t(j,i)
176 vvtot(j,i+nres)=vv(j)+d_t(j,i+nres)
180 write (iout,*) "vvtot backbone and sidechain"
182 write (iout,'(i5,3e15.5,5x,3e15.5)') i,(vvtot(j,i),j=1,3),
183 & (vvtot(j,i+nres),j=1,3)
188 v_work(ind+j)=vvtot(j,i)
194 v_work(ind+j)=vvtot(j,i+nres)
198 write (iout,*) "v_work gamvec and site-based friction forces"
200 write (iout,'(i5,3e15.5)') i,v_work(i),gamvec(i),
201 & gamvec(i)*v_work(i)
204 c fric_work1(i)=0.0d0
206 c fric_work1(i)=fric_work1(i)-A(j,i)*gamvec(j)*v_work(j)
209 c write (iout,*) "fric_work and fric_work1"
211 c write (iout,'(i5,2e15.5)') i,fric_work(i),fric_work1(i)
217 ginvfric(i,j)=ginvfric(i,j)+ginv(i,k)*fricmat(k,j)
221 write (iout,*) "ginvfric"
223 write (iout,'(i5,100f8.3)') i,(ginvfric(i,j),j=1,dimen)
225 write (iout,*) "symmetry check"
228 write (iout,*) i,j,ginvfric(i,j)-ginvfric(j,i)
235 c-----------------------------------------------------
236 subroutine stochastic_force(stochforcvec)
241 double precision time00
244 include 'COMMON.CHAIN'
245 include 'COMMON.DERIV'
247 include 'COMMON.LOCAL'
248 include 'COMMON.INTERACT'
251 include 'COMMON.LAGRANGE.5diag'
253 include 'COMMON.LAGRANGE'
255 include 'COMMON.TIME1'
257 include 'COMMON.LANGEVIN'
260 include 'COMMON.LANGEVIN.lang0.5diag'
262 include 'COMMON.LANGEVIN.lang0'
265 include 'COMMON.IOUNITS'
267 double precision x,sig,lowb,highb,
268 & ff(3),force(3,0:MAXRES2),zeta2,lowb2,
269 & highb2,sig2,forcvec(MAXRES6),stochforcvec(MAXRES6)
270 logical lprn /.false./
271 integer i,j,ind,ii,iti
272 double precision anorm_distr
274 integer ichain,innt,inct,iposc
289 c Compute the stochastic forces acting on bodies. Store in force.
292 if (itype(i).eq.ntyp1 .or. itype(i+1).eq.ntyp1) cycle
298 force(j,i)=anorm_distr(x,sig,lowb,highb)
306 force(j,i+nres)=anorm_distr(x,sig2,lowb2,highb2)
310 write (iout,*) "Stochastic forces on sites"
312 write (iout,'(i5,2(3f10.5,5x))') i,(force(j,i),j=1,3),
313 & (force(j,i+nres),j=1,3)
317 time_fsample=time_fsample+MPI_Wtime()-time00
319 time_fsample=time_fsample+tcpu()-time00
324 innt=chain_border(1,ichain)
325 inct=chain_border(2,ichain)
326 iposc=iposd_chain(ichain)
327 c write (iout,*)"stochastic_force ichain=",ichain," innt",innt,
328 c & " inct",inct," iposc",iposc
330 stochforcvec(ind+j)=0.5d0*force(j,innt)
332 if (iabs(itype(innt)).eq.10) then
334 stochforcvec(ind+j)=stochforcvec(ind+j)+force(j,innt+nres)
340 stochforcvec(ind+j)=force(j,innt+nres)
346 stochforcvec(ind+j)=0.5d0*(force(j,i)+force(j,i-1))
348 if (iabs(itype(i)).eq.10) then
350 stochforcvec(ind+j)=stochforcvec(ind+j)+force(j,i+nres)
356 stochforcvec(ind+j)=force(j,i+nres)
362 stochforcvec(ind+j)=0.5d0*force(j,inct-1)
364 if (iabs(itype(inct)).eq.10) then
366 stochforcvec(ind+j)=stochforcvec(ind+j)+force(j,inct+nres)
372 stochforcvec(ind+j)=force(j,inct+nres)
376 c write (iout,*) "chain",ichain," ind",ind
379 write (iout,*) "stochforcvec"
380 write (iout,'(3f10.5)') (stochforcvec(j),j=1,ind)
383 c Compute the stochastic forces acting on virtual-bond vectors.
389 stochforc(j,i)=ff(j)+0.5d0*force(j,i)
392 ff(j)=ff(j)+force(j,i)
394 if (itype(i+1).ne.ntyp1) then
396 stochforc(j,i)=stochforc(j,i)+force(j,i+nres+1)
397 ff(j)=ff(j)+force(j,i+nres+1)
402 stochforc(j,0)=ff(j)+force(j,nnt+nres)
405 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
407 stochforc(j,i+nres)=force(j,i+nres)
412 stochforcvec(j)=stochforc(j,0)
417 stochforcvec(ind+j)=stochforc(j,i)
422 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
424 stochforcvec(ind+j)=stochforc(j,i+nres)
430 write (iout,*) "stochforcvec"
432 write(iout,'(i5,e15.5)') i,stochforcvec(i)
434 write(iout,*) "Stochastic forces backbone"
436 write(iout,'(i5,3e15.5)') i,(stochforc(j,i),j=1,3)
438 write(iout,*) "Stochastic forces side chain"
440 write(iout,'(i5,3e15.5)')
441 & i,(stochforc(j,i+nres),j=1,3)
451 forcvec(ind+j)=force(j,i)
458 forcvec(j+ind)=force(j,i+nres)
463 write (iout,*) "forcvec"
467 write (iout,'(2i3,2f10.5)') i,j,force(j,i),
474 write (iout,'(2i3,2f10.5)') i,j,force(j,i+nres),
483 c------------------------------------------------------------------
484 subroutine setup_fricmat
489 double precision time00
493 include 'COMMON.CHAIN'
494 include 'COMMON.DERIV'
496 include 'COMMON.LOCAL'
497 include 'COMMON.INTERACT'
500 include 'COMMON.LAGRANGE.5diag'
502 include 'COMMON.LAGRANGE'
504 include 'COMMON.SETUP'
505 include 'COMMON.TIME1'
506 c integer licznik /0/
509 include 'COMMON.LANGEVIN'
512 include 'COMMON.LANGEVIN.lang0.5diag'
514 include 'COMMON.LANGEVIN.lang0'
517 include 'COMMON.IOUNITS'
519 integer i,j,k,l,ind,ind1,m,ii,iti,it,nzero,innt,inct
521 logical lprn /.true./
522 double precision dtdi,gamvec(MAXRES2)
523 common /syfek/ gamvec
525 double precision ginvfric(maxres2,maxres2),Ghalf(mmaxres2),
526 & fcopy(maxres2,maxres2)
527 double precision work(8*maxres2)
528 integer iwork(maxres2)
529 common /przechowalnia/ ginvfric,Ghalf,fcopy
533 if (fg_rank.ne.king) goto 10
540 c Load the friction coefficients corresponding to side chains
542 if (lprn) write (iout,*) "m",m
549 gamvec(ii)=gamsc(iabs(iti))
551 if (surfarea) call sdarea(gamvec)
553 write (iout,*) "Vector gamvec ii",ii
555 write (iout,'(i5,f10.5)') i, gamvec(i)
564 innt=chain_border(1,ichain)
565 inct=chain_border(2,ichain)
566 c write (iout,*) "ichain",ichain," innt",innt," inct",inct
568 DMfric(ind)=gamvec(innt-nnt+1)/4
569 if (iabs(itype(innt)).eq.10) then
570 DMfric(ind)=DMfric(ind)+gamvec(m+innt-nnt+1)
573 DMfric(ind+1)=gamvec(m+innt-nnt+1)
576 c write (iout,*) "DMfric init ind",ind
579 DMfric(ind)=gamvec(i-nnt+1)/2
580 if (iabs(itype(i)).eq.10) then
581 DMfric(ind)=DMfric(ind)+gamvec(m+i-nnt+1)
584 DMfric(ind+1)=gamvec(m+i-nnt+1)
588 c write (iout,*) "DMfric endloop ind",ind
589 if (inct.gt.innt) then
590 DMfric(ind)=gamvec(inct-1-nnt+1)/4
591 if (iabs(itype(inct)).eq.10) then
592 DMfric(ind)=DMfric(ind)+gamvec(inct+m-nnt+1)
595 DMfric(ind+1)=gamvec(inct+m-nnt+1)
599 c write (iout,*) "DMfric end ind",ind
603 ind=iposd_chain(ichain)
604 innt=chain_border(1,ichain)
605 inct=chain_border(2,ichain)
607 if (iabs(itype(i)).ne.10) then
610 DU1fric(ind)=gamvec(i-nnt+1)/4
617 ind=iposd_chain(ichain)
618 innt=chain_border(1,ichain)
619 inct=chain_border(2,ichain)
621 if (iabs(itype(i)).ne.10) then
622 DU2fric(ind)=gamvec(i-nnt+1)/4
632 write(iout,*)"The upper part of the five-diagonal friction matrix"
634 write (iout,'(a,i5)') 'Chain',ichain
635 innt=iposd_chain(ichain)
636 inct=iposd_chain(ichain)+dimen_chain(ichain)-1
638 if (i.lt.inct-1) then
639 write (iout,'(2i3,3f10.5)') i,i-innt+1,DMfric(i),DU1fric(i),
641 else if (i.eq.inct-1) then
642 write (iout,'(2i3,3f10.5)') i,i-innt+1,DMfric(i),DU1fric(i)
644 write (iout,'(2i3,3f10.5)') i,i-innt+1,DMfric(i)
651 c The friction matrix
656 dtdi=dtdi+A(j,k)*A(j,i)*gamvec(j)
663 write (iout,'(//a)') "Matrix fricmat"
664 call matout2(dimen,dimen,maxres2,maxres2,fricmat)
666 if (lang.eq.2 .or. lang.eq.3) then
667 c Mass-scale the friction matrix if non-direct integration will be performed
673 Ginvfric(i,j)=Ginvfric(i,j)+
674 & Gsqrm(i,k)*Gsqrm(l,j)*fricmat(k,l)
679 c Diagonalize the friction matrix
684 Ghalf(ind)=Ginvfric(i,j)
687 call gldiag(maxres2,dimen,dimen,Ghalf,work,fricgam,fricvec,
690 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",
691 & " mass-scaled friction matrix"
692 call eigout(dimen,dimen,maxres2,maxres2,fricvec,fricgam)
694 c Precompute matrices for tinker stochastic integrator
701 mt1(i,j)=mt1(i,j)+fricvec(k,i)*gsqrm(k,j)
702 mt2(i,j)=mt2(i,j)+fricvec(k,i)*gsqrp(k,j)
708 else if (lang.eq.4) then
709 c Diagonalize the friction matrix
714 Ghalf(ind)=fricmat(i,j)
717 call gldiag(maxres2,dimen,dimen,Ghalf,work,fricgam,fricvec,
720 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",
722 call eigout(dimen,dimen,maxres2,maxres2,fricvec,fricgam)
724 c Determine the number of zero eigenvalues of the friction matrix
725 nzero=max0(dimen-dimen1,0)
726 c do while (fricgam(nzero+1).le.1.0d-5 .and. nzero.lt.dimen)
729 write (iout,*) "Number of zero eigenvalues:",nzero
734 fricmat(i,j)=fricmat(i,j)
735 & +fricvec(i,k)*fricvec(j,k)/fricgam(k)
740 write (iout,'(//a)') "Generalized inverse of fricmat"
741 call matout(dimen,dimen,maxres6,maxres6,fricmat)
746 if (nfgtasks.gt.1) then
747 if (fg_rank.eq.0) then
748 c The matching BROADCAST for fg processors is called in ERGASTULUM
754 call MPI_Bcast(10,1,MPI_INTEGER,king,FG_COMM,IERROR)
756 time_Bcast=time_Bcast+MPI_Wtime()-time00
758 time_Bcast=time_Bcast+tcpu()-time00
760 c print *,"Processor",myrank,
761 c & " BROADCAST iorder in SETUP_FRICMAT"
764 c write (iout,*) "setup_fricmat licznik",licznik
770 c Scatter the friction matrix
771 call MPI_Scatterv(fricmat(1,1),nginv_counts(0),
772 & nginv_start(0),MPI_DOUBLE_PRECISION,fcopy(1,1),
773 & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
776 time_scatter=time_scatter+MPI_Wtime()-time00
777 time_scatter_fmat=time_scatter_fmat+MPI_Wtime()-time00
779 time_scatter=time_scatter+tcpu()-time00
780 time_scatter_fmat=time_scatter_fmat+tcpu()-time00
785 fricmat(j,i)=fcopy(i,j)
788 c write (iout,*) "My chunk of fricmat"
789 c call MATOUT2(my_ng_count,dimen,maxres2,maxres2,fcopy)
795 c-------------------------------------------------------------------------------
796 subroutine sdarea(gamvec)
798 c Scale the friction coefficients according to solvent accessible surface areas
799 c Code adapted from TINKER
804 include 'COMMON.CONTROL'
808 include 'COMMON.LANGEVIN'
811 include 'COMMON.LANGEVIN.lang0.5diag'
813 include 'COMMON.LANGEVIN.lang0'
816 include 'COMMON.CHAIN'
817 include 'COMMON.DERIV'
819 include 'COMMON.LOCAL'
820 include 'COMMON.INTERACT'
821 include 'COMMON.IOUNITS'
822 include 'COMMON.NAMES'
823 double precision radius(maxres2),gamvec(maxres2)
824 double precision twosix
825 parameter (twosix=1.122462048309372981d0)
826 logical lprn /.false./
828 double precision probe,area,ratio
830 c determine new friction coefficients every few SD steps
832 c set the atomic radii to estimates of sigma values
834 c print *,"Entered sdarea"
840 c Load peptide group radii
844 c Load side chain radii
847 if (iti.ne.ntyp1) radius(i+nres)=restok(iti)
850 c write (iout,*) "i",i," radius",radius(i)
853 radius(i) = radius(i) / twosix
854 if (radius(i) .ne. 0.0d0) radius(i) = radius(i) + probe
857 c scale atomic friction coefficients by accessible area
859 if (lprn) write (iout,*)
860 & "Original gammas, surface areas, scaling factors, new gammas, ",
861 & "std's of stochastic forces"
864 if (radius(i).gt.0.0d0) then
865 call surfatom (i,area,radius)
866 ratio = dmax1(area/(4.0d0*pi*radius(i)**2),1.0d-1)
867 if (lprn) write (iout,'(i5,3f10.5,$)')
868 & i,gamvec(ind+1),area,ratio
871 gamvec(ind) = ratio * gamvec(ind)
873 stdforcp(i)=stdfp*dsqrt(gamvec(ind))
874 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcp(i)
878 if (radius(i+nres).gt.0.0d0) then
879 call surfatom (i+nres,area,radius)
880 ratio = dmax1(area/(4.0d0*pi*radius(i+nres)**2),1.0d-1)
881 if (lprn) write (iout,'(i5,3f10.5,$)')
882 & i,gamvec(ind+1),area,ratio
885 gamvec(ind) = ratio * gamvec(ind)
887 if (itype(i).ne.ntyp1)
888 & stdforcsc(i)=stdfsc(itype(i))*dsqrt(gamvec(ind))
889 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcsc(i)