2 !-----------------------------------------------------------------------------
9 !-----------------------------------------------------------------------------
12 !-----------------------------------------------------------------------------
14 !-----------------------------------------------------------------------------
16 !-----------------------------------------------------------------------------
18 !-------------------------------------------------------------------------
19 ! This subroutine contains the total lagrangain from which the accelerations
20 ! are obtained. For numerical gradient checking, the derivetive of the
21 ! lagrangian in the velocities and coordinates are calculated seperately
22 !-------------------------------------------------------------------------
23 ! implicit real*8 (a-h,o-z)
24 ! include 'DIMENSIONS'
27 use energy, only: grad_transform
28 use geometry_data, only: nres
29 use control_data !el, only: mucadyn,lmuca
32 real(kind=8) :: time00
34 ! include 'COMMON.VAR'
35 ! include 'COMMON.CHAIN'
36 ! include 'COMMON.DERIV'
37 ! include 'COMMON.GEO'
38 ! include 'COMMON.LOCAL'
39 ! include 'COMMON.INTERACT'
41 ! include 'COMMON.IOUNITS'
42 ! include 'COMMON.CONTROL'
43 ! include 'COMMON.MUCA'
44 ! include 'COMMON.TIME1'
45 integer ::i,j,ind,itime,mnum,innt,inct,inct_prev,ichain,n,mark
46 real(kind=8) :: zapas(6*nres) !,muca_factor !maxres6=6*maxres
47 ! the line below might be wrong
49 real(kind=8) :: rs(2*nres),xsolv(2*nres)
51 real(kind=8) :: rscheck(2*nres),rsold(2*nres)
54 logical :: lprn = .true.
55 !el common /cipiszcze/ itime
65 write (iout,*) "Potential forces backbone"
67 write (iout,'(i5,3e15.5,5x,3e15.5)')i,(-gcart(j,i),j=1,3)
69 write (iout,*) "Potential forces sidechain"
71 ! if (itype(i).ne.10 .and. itype(i).ne.ntyp1) &
72 write (iout,'(i5,3e15.5,5x,3e15.5)') i,(-gxcart(j,i),j=1,3)
77 innt=iposd_chain(ichain)
80 do i=chain_border(1,ichain),chain_border(2,ichain)
82 if (itype(i,1).eq.10.or.mnum.ge.3)then
83 rs(ind)=-gcart(j,i)-gxcart(j,i)
87 rs(ind+1)=-gxcart(j,i)
96 write(iout,*) "RHS of the 5-diag equations system",&
103 call FDISYS (n,DM(innt),DU1(innt),DU2(innt),rs,xsolv)
105 write (iout,*) "Solution of the 5-diagonal equations system"
107 write (iout,'(i5,f10.5)') i,xsolv(i)
112 call fivediagmult(n,DMorig(innt),DU1orig(innt),DU2orig(innt),
115 write(iout,*) "i",i,"rsold",rsold(i),"rscheck",rscheck(i),
116 & "ratio",rscheck(i)/rsold(i)
122 do i=chain_border(1,ichain),chain_border(2,ichain)
124 if (itype(i,1).eq.10 .or.mnum.ge.3) then
129 d_a(j,i+nres)=xsolv(ind+1)
136 write (iout,*) "Acceleration in CA and SC oordinates"
138 write (iout,'(i3,3f10.5)') i,(d_a(j,i),j=1,3)
141 write (iout,'(i3,3f10.5)') i,(d_a(j,i+nres),j=1,3)
144 !C Conevert d_a to virtual-bon-vector basis
147 !c write (iout,*) "WLOS"
153 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum) .or.mnum.ge.3) then
155 d_a(j,i)=d_a(j,i+1)-d_a(j,i)
159 d_a(j,i+nres)=d_a(j,i+nres)-d_a(j,i)
160 d_a(j,i)=d_a(j,i+1)-d_a(j,i)
169 !c write (iout,*) "Shifting accelerations"
177 !c write (iout,*) "ichain",chain_border1(1,ichain)-1,
178 !c & chain_border1(1,ichain)
179 d_a(:,chain_border1(1,ichain)-1)=d_a(:,chain_border1(1,ichain))
180 d_a(:,chain_border1(1,ichain))=0.0d0
182 !c write (iout,*) "Adding accelerations"
184 !c write (iout,*) "chain",ichain,chain_border1(1,ichain)-1,
185 !c & chain_border(2,ichain-1)
186 d_a(:,chain_border1(1,ichain)-1)=&
187 d_a(:,chain_border1(1,ichain)-1)+d_a(:,chain_border(2,ichain-1))
188 d_a(:,chain_border(2,ichain-1))=0.0d0
197 innt=chain_border(1,ichain)
198 inct=chain_border(2,ichain)
200 d_a(j,inct_prev)=d_a(j,innt)-aaux(j)
204 if (itype(i).ne.10) then
206 d_a(j,i+nres)=d_a(j,i+nres)-d_a(j,i)
215 d_a(j,i)=d_a(j,i+1)-d_a(j,i)
221 write(iout,*) 'acceleration 3D FIVEDIAG in dC and dX'
223 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3)
226 write (iout,'(i3,3f10.5,3x,3f10.5)')&
227 i,(d_a(j,i+nres),j=1,3)
238 write (iout,*) "Potential forces backbone"
241 if (lprn) write (iout,'(i5,3e15.5,5x,3e15.5)') &
242 i,(-gcart(j,i),j=1,3)
245 zapas(ind)=-gcart(j,i)
248 if (lprn) write (iout,*) "Potential forces sidechain"
251 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
253 if (lprn) write (iout,'(i5,3e15.5,5x,3e15.5)') &
254 i,(-gxcart(j,i),j=1,3)
257 zapas(ind)=-gxcart(j,i)
262 call ginv_mult(zapas,d_a_work)
271 d_a(j,i)=d_a_work(ind)
276 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
277 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
281 d_a(j,i+nres)=d_a_work(ind)
289 if(mucadyn.gt.0) call muca_update(potE)
290 factor=muca_factor(potE)*t_bath*Rb
292 !d print *,'lmuca ',factor,potE
294 d_a(j,0)=d_a(j,0)*factor
298 d_a(j,i)=d_a(j,i)*factor
303 d_a(j,i+nres)=d_a(j,i+nres)*factor
310 write(iout,*) 'acceleration 3D'
311 write (iout,'(i3,3f10.5,3x,3f10.5)') 0,(d_a(j,0),j=1,3)
313 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3)
316 write (iout,'(i3,3f10.5,3x,3f10.5)') &
317 i+nres,(d_a(j,i+nres),j=1,3)
321 time_lagrangian=time_lagrangian+MPI_Wtime()-time00
324 end subroutine lagrangian
325 !-----------------------------------------------------------------------------
326 subroutine setup_MD_matrices
328 use geometry_data, only: nres,nside
332 use geometry, only:int_bounds
334 ! implicit real*8 (a-h,o-z)
335 ! include 'DIMENSIONS'
339 real(kind=8) :: time00
340 real(kind=8) ,allocatable, dimension(:) :: DDM,DDU1,DDU2
342 ! include 'COMMON.SETUP'
343 ! include 'COMMON.VAR'
344 ! include 'COMMON.CHAIN'
345 ! include 'COMMON.DERIV'
346 ! include 'COMMON.GEO'
347 ! include 'COMMON.LOCAL'
348 ! include 'COMMON.INTERACT'
349 ! include 'COMMON.MD'
351 ! include 'COMMON.LANGEVIN'
353 ! include 'COMMON.LANGEVIN.lang0'
355 ! include 'COMMON.IOUNITS'
356 ! include 'COMMON.TIME1'
357 logical :: lprn = .false.
360 real(kind=8),allocatable,dimension(:,:) :: Bmat,matmult
363 real(kind=8),dimension(2*nres) :: massvec,sqreig !(maxres2) maxres2=2*maxres
364 real(kind=8) :: relfeh,eps1,eps2
365 !el real(kind=8),dimension(:),allocatable :: Ghalf
366 !el real(kind=8),dimension(2*nres*(2*nres+1)/2) :: Ghalf !(mmaxres2) (mmaxres2=(maxres2*(maxres2+1)/2))
367 !el real(kind=8),dimension(2*nres,2*nres) :: Gcopy !(maxres2,maxres2)
368 !el real(kind=8),dimension(:,:),allocatable :: Gcopy
369 real(kind=8),dimension(8*6*nres) :: work !(8*maxres6)
370 integer,dimension(6*nres) :: iwork !(maxres6) maxres6=6*maxres
371 !el common /przechowalnia/ Gcopy,Ghalf
372 real(kind=8) :: coeff,mscab
373 integer :: i,j,ind,ind1,k,l,ii,jj,m,m1,ii1,iti,nres2,ierr,nind,mark
375 integer :: iz,mnum,ichain,n,dimenp,innt,inct
376 print *,"just entered"
380 write (iout,*) "before FIVEDIAG"
381 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !mmaxres2=(maxres2*(maxres+1)/2)
383 write (iout,*) "ALLOCATE"
385 if(.not.allocated(Gcopy)) allocate(Gcopy(nres2,nres2)) !(maxres2,maxres2)
386 ! if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !mmaxres2=(maxres2*(maxres+1)/2)
387 if(.not.allocated(Bmat)) allocate(Bmat(nres2,nres2))
388 if(.not.allocated(matmult)) allocate(matmult(nres2,nres2))
391 ! Set up the matrix of the (dC,dX)-->(C,X) transformation (A), the
392 ! inertia matrix (Gmat) and the inverse of the inertia matrix (Ginv)
394 ! Determine the number of degrees of freedom (dimen) and the number of
396 ! dimen=(nct-nnt+1)+nside
397 ! dimen1=(nct-nnt)+(nct-nnt+1)
399 ! write (iout,*) "nnt",nnt," nct",nct," nside",nside
404 if (iabs(itype(nnt)).eq.10) then
409 DM(1)=DM(1)+isc(iabs(itype(nnt)))
410 DM(2)=msc(iabs(itype(nnt)))+isc(iabs(itype(nnt)))
416 ! if (iabs(itype(i,1)).eq.ntyp1) cycle
418 if (iabs(itype(i,1)).eq.10 .or. &
419 iabs(itype(i,mnum)).eq.ntyp1_molec(mnum) .or. mnum.ge.4) then
420 if (iabs(itype(i,1)).eq.10) DM(ind)=DM(ind)+msc(10)
423 DM(ind)=DM(ind)+isc(iabs(itype(i,1)))
424 DM(ind+1)=msc(iabs(itype(i,1)))+isc(iabs(itype(i,1)))
430 if (iabs(itype(nct)).eq.10) then
431 DM(ind)=DM(ind)+msc(10)
434 DM(ind)=DM(ind)+isc(iabs(itype(nct)))
435 DM(ind+1)=msc(iabs(itype(nct)))+isc(iabs(itype(nct)))
444 if (iabs(itype(i,1)).ne.10 .and.iabs(itype((i))).ne.ntyp1 &
446 DU1(ind)=-isc(iabs(itype(i,1)))
458 ! if (iabs(itype(i,1)).eq.ntyp1) cycle
459 write (iout,*) "i",i," itype",itype(i,1),ntyp1
460 if (iabs(itype(i,1)).ne.10 .and. &
461 iabs(itype(i,mnum)).ne.ntyp1_molec(mnum) .and. mnum.lt.4) then
476 dimen=dimen+chain_length(ichain)
477 dimen1=dimen1+2*chain_length(ichain)-1
478 dimenp=dimenp+chain_length(ichain)-1
480 write (iout,*) "Number of Calphas",dimen
481 write (iout,*) "Number of sidechains",nside
482 write (iout,*) "Number of peptide groups",dimenp
483 dimen=dimen+nside ! number of centers
484 dimen3=3*dimen ! degrees of freedom
485 write (iout,*) "Number of centers",dimen
486 write (iout,*) "Degrees of freedom:",dimen3
490 iposd_chain(ichain)=ind
491 innt=chain_border(1,ichain)
493 inct=chain_border(2,ichain)
494 DM(ind)=mp(mnum)/4+ip(mnum)/4
495 if (iabs(itype(innt,1)).eq.10.or.molnum(innt).gt.2) then
496 DM(ind)=DM(ind)+msc(itype(innt,mnum),mnum)
500 DM(ind)=DM(ind)+isc(iabs(itype(innt,mnum)),mnum)
501 DM(ind+1)=msc(iabs(itype(innt,mnum)),mnum)+isc(iabs(itype(innt,mnum)),mnum)
505 write (iout,*) "ind",ind," nind",nind
508 ! if (iabs(itype(i)).eq.ntyp1) cycle
509 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
510 if (mnum.eq.5) ip(mnum)=isc(itype(i,mnum),mnum)
511 DM(ind)=2*ip(mnum)/4+mp(mnum)/2
512 if (iabs(itype(i,1)).eq.10.or.molnum(i).gt.2) then
513 if (iabs(itype(i,1)).eq.10.or.molnum(i).gt.2)&
514 DM(ind)=DM(ind)+msc(itype(i,molnum(i)),mnum)
518 DM(ind)=DM(ind)+isc(iabs(itype(i,mnum)),mnum)
519 DM(ind+1)=msc(iabs(itype(i,mnum)),mnum)+isc(iabs(itype(i,mnum)),mnum)
523 write (iout,*) "i",i," ind",ind," nind",nind
525 if (inct.gt.innt) then
526 ! DM(ind)=ip4+mp(molnum(inct))/4
528 DM(ind)=mp(mnum)/4+ip(mnum)/4
529 if (iabs(itype(inct,mnum)).eq.10.or.molnum(inct).gt.2) then
530 DM(ind)=DM(ind)+msc(itype(inct,molnum(inct)),molnum(inct))
535 DM(ind)=DM(ind)+isc(iabs(itype(inct,mnum)),mnum)
536 DM(ind+1)=msc(iabs(itype(inct,mnum)),mnum)+isc(iabs(itype(inct,mnum)),mnum)
541 write (iout,*) "ind",ind," nind",nind
542 dimen_chain(ichain)=nind
546 ind=iposd_chain(ichain)
547 innt=chain_border(1,ichain)
548 inct=chain_border(2,ichain)
551 if (iabs(itype(i,1)).ne.10 .and.iabs(itype(i,mnum)).ne.ntyp1_molec(mnum).and.mnum.le.2) then
552 DU1(ind)=-isc(iabs(itype(i,mnum)),mnum)
556 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
557 if (mnum.eq.5) ip(mnum)=isc(itype(i,mnum),mnum)
558 DU1(ind)=mp(mnum)/4-ip(mnum)/4
565 ind=iposd_chain(ichain)
566 innt=chain_border(1,ichain)
567 inct=chain_border(2,ichain)
570 ! if (iabs(itype(i)).eq.ntyp1) cycle
571 !c write (iout,*) "i",i," itype",itype(i),ntyp1
572 if (iabs(itype(i,1)).ne.10 .and. iabs(itype(i,mnum)).ne.ntyp1_molec(mnum).and.mnum.le.2) then
573 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
574 DU2(ind)=mp(mnum)/4-ip(mnum)/4
588 write (iout,*)"The upper part of the five-diagonal inertia matrix"
591 if (gmatout) write (iout,'(a,i5)') 'Chain',ichain
592 n=dimen_chain(ichain)
593 innt=iposd_chain(ichain)
594 inct=iposd_chain(ichain)+dimen_chain(ichain)-1
597 if (i.lt.inct-1) then
598 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i),DU2(i)
599 else if (i.eq.inct-1) then
600 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i)
602 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i)
606 call FDISYP (n, DM(innt:inct), DU1(innt:inct-1),&
607 DU2(innt:inct-1), MARK)
611 "ERROR: the inertia matrix is not positive definite for chain",&
614 call MPI_Finalize(ierr)
617 else if (mark.eq.0) then
619 "ERROR: the inertia matrix is singular for chain",ichain
621 call MPI_Finalize(ierr)
623 else if (mark.eq.1) then
625 write (iout,*) "The transformed five-diagonal inertia matrix"
626 write (iout,'(a,i5)') 'Chain',ichain
628 if (i.lt.inct-1) then
629 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i),DU2(i)
630 else if (i.eq.inct-1) then
631 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i)
633 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i)
639 ! Diagonalization of the pentadiagonal matrix
648 dimen=(nct-nnt+1)+nside
649 dimen1=(nct-nnt)+(nct-nnt+1)
651 write (iout,*) "nnt",nnt," nct",nct," nside",nside
654 if (nfgtasks.gt.1) then
656 call MPI_Bcast(5,1,MPI_INTEGER,king,FG_COMM,IERROR)
657 time_Bcast=time_Bcast+MPI_Wtime()-time00
658 call int_bounds(dimen,igmult_start,igmult_end)
659 igmult_start=igmult_start-1
660 call MPI_Allgather(3*igmult_start,1,MPI_INTEGER,&
661 ng_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
662 my_ng_count=igmult_end-igmult_start
663 call MPI_Allgather(3*my_ng_count,1,MPI_INTEGER,ng_counts(0),1,&
664 MPI_INTEGER,FG_COMM,IERROR)
665 write (iout,*) 'Processor:',fg_rank,' CG group',kolor,&
666 ' absolute rank',myrank,' igmult_start',igmult_start,&
667 ' igmult_end',igmult_end,' count',my_ng_count
668 write (iout,*) "ng_start",(ng_start(i),i=0,nfgtasks-1)
669 write (iout,*) "ng_counts",(ng_counts(i),i=0,nfgtasks-1)
679 ! write (iout,*) "dimen",dimen," dimen1",dimen1," dimen3",dimen3
680 ! Zeroing out A and fricmat
686 ! Diagonal elements of the dC part of A and the respective friction coefficients
689 ! print *,"TUTUTUT?!",nnt,nct-1
694 coeff=0.25d0*IP(mnum)
695 print *,"TU",i,itype(i,mnum),mnum
696 if (mnum.ge.5) mp(mnum)=msc(itype(i,mnum),mnum)
697 print *,"TU2",i,coeff,mp(mnum)
698 massvec(ind1)=mp(mnum)
700 ! print *,"i",mp(mnum)
704 ! Off-diagonal elements of the dC part of A
711 ! Diagonal elements of the dX part of A and the respective friction coefficients
717 msc(ntyp1_molec(i),i)=1.0d0
719 msc(ntyp1_molec(4),4)=1.0d0
720 ! print *,"TU3",ntyp1_molec(4)-1
721 msc(ntyp1_molec(4)-1,4)=1.0d0
727 ! if (mnum.eq.5) then
730 mscab=msc(iabs(iti),mnum)
734 if (iti.ne.10 .and. iti.ne.ntyp1_molec(mnum) .and. mnum.lt.4) then
738 Gmat(ii1,ii1)=ISC(iabs(iti),mnum)
741 ! Off-diagonal elements of the dX part of A
756 write (iout,*) "Vector massvec"
758 write (iout,*) i,massvec(i)
760 write (iout,'(//a)') "A"
761 call matout(dimen,dimen1,nres2,nres2,A)
764 ! Calculate the G matrix (store in Gmat)
769 dtdi=dtdi+A(j,k)*A(j,i)*massvec(j)
771 Gmat(k,i)=Gmat(k,i)+dtdi
776 write (iout,'(//a)') "Gmat"
777 call matout(dimen,dimen,nres2,nres2,Gmat)
786 ! Invert the G matrix
787 call MATINVERT(dimen,nres2,Gcopy,Ginv,osob)
789 write (iout,'(//a)') "Ginv"
790 call matout(dimen,dimen,nres2,nres2,Ginv)
798 if ((itype(i,1).eq.10).or.(itype(i,mnum).eq.ntyp1_molec(mnum))&
799 .or.(mnum.ge.4)) then
807 Bmat(i-nnt+1+(nct-nnt)+1,j-1)=-1
808 Bmat(i-nnt+1+(nct-nnt)+1,j)=1
811 Bmat(i-nnt+1+(nct-nnt)+1,j-1)=-1
812 Bmat(i-nnt+1+(nct-nnt)+1,j)=1
816 write (iout,*) "j",j," dimen",dimen
818 write (iout,'(//a)') "Bmat"
819 call matout(dimen,dimen,nres2,nres2,Bmat)
822 write(iout,*) "before Gcopy",dimen,nres*2
826 ! write (iout,*) "myij",i,j
829 ! write(iout,*) "i,j,k,l",i,j,k,l
830 Gcopy(i,j)=Gcopy(i,j)+Bmat(k,i)*Gmat(k,l)*Bmat(l,j)
837 write (iout,'(//a)') "Gmat-transformed"
838 call matout(dimen,dimen,nres2,nres2,Gcopy)
841 if (nfgtasks.gt.1) then
842 myginv_ng_count=nres2*my_ng_count
843 call MPI_Allgather(nres2*igmult_start,1,MPI_INTEGER,&
844 nginv_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
845 call MPI_Allgather(myginv_ng_count,1,MPI_INTEGER,&
846 nginv_counts(0),1,MPI_INTEGER,FG_COMM,IERROR)
847 write (iout,*) "nginv_start",(nginv_start(i),i=0,nfgtasks-1)
848 write (iout,*) "nginv_counts",(nginv_counts(i),i=0,nfgtasks-1)
850 ! call MPI_Scatterv(ginv(1,1),nginv_counts(0),
851 ! & nginv_start(0),MPI_DOUBLE_PRECISION,ginv,
852 ! & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
853 ! call MPI_Barrier(FG_COMM,IERR)
855 call MPI_Scatterv(ginv(1,1),nginv_counts(0),&
856 nginv_start(0),MPI_DOUBLE_PRECISION,gcopy(1,1),&
857 myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
859 time_scatter_ginv=time_scatter_ginv+MPI_Wtime()-time00
866 ! write (iout,*) "Master's chunk of ginv"
867 ! call MATOUT2(my_ng_count,dimen,maxres2,maxres2,ginv)
871 write (iout,*) "The G matrix is singular."
872 write (iout,'(//a)') "Gmat-transformed"
873 call matout(dimen,dimen,nres2,nres2,Gcopy)
876 ! Compute G**(-1/2) and G**(1/2)
884 call gldiag(nres2,dimen,dimen,Ghalf,work,Geigen,Gvec,&
887 write (iout,'(//a)') &
888 "Eigenvectors and eigenvalues of the G matrix"
889 call eigout(dimen,dimen,nres2,nres2,Gvec,Geigen)
892 sqreig(i)=dsqrt(Geigen(i))
900 Gsqrp(i,j)=Gsqrp(i,j)+Gvec(i,k)*Gvec(j,k)*sqreig(k)
901 Gsqrm(i,j)=Gsqrm(i,j)+Gvec(i,k)*Gvec(j,k)/sqreig(k)
902 Gcopy(i,j)=Gcopy(i,j)+Gvec(i,k)*Gvec(j,k)*Geigen(k)
907 write (iout,*) "Comparison of original and restored G"
910 write (iout,'(2i5,5f10.5)') i,j,Gmat(i,j),Gcopy(i,j),&
911 Gmat(i,j)-Gcopy(i,j),Gsqrp(i,j),Gsqrm(i,j)
915 if (allocated(Gcopy)) deallocate(Gcopy)
917 !write(iout,*) "end setup_MD_matr"
919 end subroutine setup_MD_matrices
920 !-----------------------------------------------------------------------------
921 subroutine EIGOUT(NC,NR,LM2,LM3,A,B)
923 ! implicit real*8 (a-h,o-z)
924 ! include 'DIMENSIONS'
925 ! include 'COMMON.IOUNITS'
926 integer :: LM2,LM3,NC,NR,KA,KC,KB,I,J,N
927 real(kind=8) :: A(LM2,LM3),B(LM2)
931 WRITE(IOUT,600) (I,I=KA,KB)
932 WRITE(IOUT,601) (B(I),I=KA,KB)
936 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
942 4 IF (KB.EQ.NC) RETURN
946 600 FORMAT (// 9H ROOT NO.,I4,9I11)
947 601 FORMAT (/5X,10(1PE11.4))
949 603 FORMAT (I5,10F11.5)
951 end subroutine EIGOUT
952 !-----------------------------------------------------------------------------
953 subroutine MATOUT(NC,NR,LM2,LM3,A)
955 ! implicit real*8 (a-h,o-z)
956 ! include 'DIMENSIONS'
957 ! include 'COMMON.IOUNITS'
958 integer :: LM2,LM3,NC,NR,KA,KC,KB,I,J,N
959 real(kind=8) :: A(LM2,LM3)
963 WRITE(IOUT,600) (I,I=KA,KB)
967 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
973 4 IF (KB.EQ.NC) RETURN
977 600 FORMAT (//5x,9I11)
979 603 FORMAT (I5,10F11.3)
981 end subroutine MATOUT
982 !-----------------------------------------------------------------------------
983 subroutine MATOUT1(NC,NR,LM2,LM3,A)
985 ! implicit real*8 (a-h,o-z)
986 ! include 'DIMENSIONS'
987 ! include 'COMMON.IOUNITS'
988 integer :: LM2,LM3,NC,NR,KA,KC,KB,I,J,N
989 real(kind=8) :: A(LM2,LM3)
993 WRITE(IOUT,600) (I,I=KA,KB)
997 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
1003 4 IF (KB.EQ.NC) RETURN
1007 600 FORMAT (//5x,7(3I5,2x))
1009 603 FORMAT (I5,7(3F5.1,2x))
1011 end subroutine MATOUT1
1012 !-----------------------------------------------------------------------------
1013 subroutine MATOUT2(NC,NR,LM2,LM3,A)
1015 ! implicit real*8 (a-h,o-z)
1016 ! include 'DIMENSIONS'
1017 ! include 'COMMON.IOUNITS'
1018 integer :: I,J,KA,KC,KB,N
1019 integer :: LM2,LM3,NC,NR
1020 real(kind=8) :: A(LM2,LM3)
1024 WRITE(IOUT,600) (I,I=KA,KB)
1028 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
1034 4 IF (KB.EQ.NC) RETURN
1038 600 FORMAT (//5x,4(3I9,2x))
1040 603 FORMAT (I5,4(3F9.3,2x))
1042 end subroutine MATOUT2
1044 subroutine fivediagmult(n,DM,DU1,DU2,x,y)
1046 double precision DM(n),DU1(n),DU2(n),x(n),y(n)
1048 y(1)=DM(1)*x(1)+DU1(1)*x(2)+DU2(1)*x(3)
1049 y(2)=DU1(1)*x(1)+DM(2)*x(2)+DU1(2)*x(3)+DU2(2)*x(4)
1051 y(i)=DU2(i-2)*x(i-2)+DU1(i-1)*x(i-1)+DM(i)*x(i) &
1052 +DU1(i)*x(i+1)+DU2(i)*x(i+2)
1054 y(n-1)=DU2(n-3)*x(n-3)+DU1(n-2)*x(n-2)+DM(n-1)*x(n-1) &
1056 y(n)=DU2(n-2)*x(n-2)+DU1(n-1)*x(n-1)+DM(n)*x(n)
1059 !c---------------------------------------------------------------------------
1060 subroutine fivediaginv_mult(ndim,forces,d_a_vec)
1061 use energy_data, only:nchain,chain_border,nct,nnt,molnum,&
1064 double precision forces(3*ndim),accel(3,0:maxres2),rs(ndim), &
1065 xsolv(ndim),d_a_vec(6*nres)
1066 integer i,j,ind,ichain,n,iposc,innt,inct,inct_prev,mnum
1069 !Compute accelerations in Calpha and SC
1071 n=dimen_chain(ichain)
1072 iposc=iposd_chain(ichain)
1073 innt=chain_border(1,ichain)
1074 inct=chain_border(2,ichain)
1075 do i=iposc,iposc+n-1
1076 rs(i-iposc+1)=forces(3*(i-1)+j)
1079 write (iout,*) "j",j," chain",ichain
1081 write (iout,'(f10.5)') (rs(i),i=1,n)
1083 call FDISYS (n,DM(iposc),DU1(iposc),DU2(iposc),rs,xsolv)
1085 write (iout,*) "xsolv"
1086 write (iout,'(f10.5)') (xsolv(i),i=1,n)
1091 if (itype(i,1).eq.10.or.mnum.gt.2)then
1092 accel(j,i)=xsolv(ind)
1095 accel(j,i)=xsolv(ind)
1096 accel(j,i+nres)=xsolv(ind+1)
1102 !C Convert d_a to virtual-bon-vector basis
1104 write (iout,*) "accel in CA-SC basis"
1106 write (iout,'(i5,3f10.5,5x,3f10.5)') i,(accel(j,i),j=1,3),
1107 & (accel(j,i+nres),j=1,3)
1109 write (iout,*) "nnt",nnt
1112 accel(:,0)=accel(:,1)
1116 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
1119 accel(j,i)=accel(j,i+1)-accel(j,i)
1123 accel(j,i+nres)=accel(j,i+nres)-accel(j,i)
1124 accel(j,i)=accel(j,i+1)-accel(j,i)
1130 accel(:,2*nres)=0.0d0
1132 accel(:,0)=accel(:,1)
1136 accel(:,chain_border1(1,ichain)-1)= &
1137 accel(:,chain_border1(1,ichain))
1138 accel(:,chain_border1(1,ichain))=0.0d0
1141 accel(:,chain_border1(1,ichain)-1)= &
1142 accel(:,chain_border1(1,ichain)-1) &
1143 +accel(:,chain_border(2,ichain-1))
1144 accel(:,chain_border(2,ichain-1))=0.0d0
1147 write (iout,*) "accel in fivediaginv_mult: 1"
1149 write(iout,'(i5,3f10.5)') i,(accel(j,i),j=1,3)
1153 d_a_vec(j)=accel(j,0)
1158 d_a_vec(ind+j)=accel(j,i)
1164 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1165 .and.mnum.le.2) then
1167 d_a_vec(ind+j)=accel(j,i+nres)
1173 write (iout,*) "d_a_vec"
1174 write (iout,'(3f10.5)') (d_a_vec(j),j=1,3*(nct-nnt+nside))
1181 !-----------------------------------------------------------------------------
1182 subroutine ginv_mult(z,d_a_tmp)
1184 use geometry_data, only: nres
1187 ! implicit real*8 (a-h,o-z)
1188 ! include 'DIMENSIONS'
1191 integer :: ierr,ierror
1193 ! include 'COMMON.SETUP'
1194 ! include 'COMMON.TIME1'
1195 ! include 'COMMON.MD'
1196 real(kind=8),dimension(dimen3) :: z,z1,d_a_tmp
1197 real(kind=8),dimension(6*nres) :: temp !(maxres6) maxres6=6*maxres
1198 real(kind=8) :: time00,time01
1199 integer :: i,j,k,ind
1201 if (nfgtasks.gt.1) then
1202 if (fg_rank.eq.0) then
1203 ! The matching BROADCAST for fg processors is called in ERGASTULUM
1205 call MPI_Bcast(4,1,MPI_INTEGER,king,FG_COMM,IERROR)
1206 time_Bcast=time_Bcast+MPI_Wtime()-time00
1207 ! print *,"Processor",myrank," BROADCAST iorder in GINV_MULT"
1209 ! write (2,*) "time00",time00
1210 ! write (2,*) "Before Scatterv"
1212 ! write (2,*) "Whole z (for FG master)"
1214 ! write (2,*) i,z(i)
1216 ! call MPI_Barrier(FG_COMM,IERROR)
1218 !elwrite(iout,*) "do tej pory jest OK, MPI_Scatterv w ginv_mult"
1219 call MPI_Scatterv(z,ng_counts(0),ng_start(0),&
1220 MPI_DOUBLE_PRECISION,&
1221 z1,3*my_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
1222 ! write (2,*) "My chunk of z"
1223 ! do i=1,3*my_ng_count
1224 ! write (2,*) i,z(i)
1226 ! write (2,*) "After SCATTERV"
1228 ! write (2,*) "MPI_Wtime",MPI_Wtime()
1229 time_scatter=time_scatter+MPI_Wtime()-time00
1231 time_scatter_ginvmult=time_scatter_ginvmult+MPI_Wtime()-time00
1233 ! write (2,*) "time_scatter",time_scatter
1234 ! write (2,*) "dimen",dimen," dimen3",dimen3," my_ng_count",
1243 ! write (2,*) "k,i,j,ind",k,i,j,ind,(j-1)*3+k+1,
1244 ! & Ginv(i,j),z((j-1)*3+k+1),
1245 ! & Ginv(i,j)*z((j-1)*3+k+1)
1246 ! temp(ind)=temp(ind)+Ginv(i,j)*z((j-1)*3+k+1)
1247 temp(ind)=temp(ind)+Ginv(j,i)*z1((j-1)*3+k+1)
1251 time_ginvmult=time_ginvmult+MPI_Wtime()-time01
1252 ! write (2,*) "Before REDUCE"
1254 ! write (2,*) "z before reduce"
1256 ! write (2,*) i,temp(i)
1259 call MPI_Reduce(temp(1),d_a_tmp(1),dimen3,MPI_DOUBLE_PRECISION,&
1260 MPI_SUM,king,FG_COMM,IERR)
1261 time_reduce=time_reduce+MPI_Wtime()-time00
1262 ! write (2,*) "After REDUCE"
1274 ! write (2,*) "k,i,j,ind",k,i,j,ind,(j-1)*3+k+1
1276 ! & Ginv(i,j),z((j-1)*3+k+1),
1277 ! & Ginv(i,j)*z((j-1)*3+k+1)
1278 d_a_tmp(ind)=d_a_tmp(ind) &
1279 +Ginv(j,i)*z((j-1)*3+k+1)
1280 ! d_a_tmp(ind)=d_a_tmp(ind)
1281 ! & +Ginv(i,j)*z((j-1)*3+k+1)
1286 time_ginvmult=time_ginvmult+MPI_Wtime()-time01
1292 end subroutine ginv_mult
1293 !-----------------------------------------------------------------------------
1295 subroutine ginv_mult_test(z,d_a_tmp)
1297 ! include 'DIMENSIONS'
1298 !el integer :: dimen
1299 ! include 'COMMON.MD'
1300 real(kind=8),dimension(dimen) :: z,d_a_tmp
1301 real(kind=8),dimension(dimen/3) :: ztmp,dtmp
1302 integer :: i,j,k,ind
1306 ! d_a_tmp(i)=d_a_tmp(i)+Ginv(i,j)*z(j)
1315 ztmp(j)=z((j-1)*3+k+1)
1318 call alignx(16,ztmp(1))
1319 call alignx(16,dtmp(1))
1320 call alignx(16,Ginv(1,1))
1325 dtmp(i)=dtmp(i)+Ginv(i,j)*ztmp(j)
1330 d_a_tmp(ind)=dtmp(i)
1334 end subroutine ginv_mult_test
1336 !-----------------------------------------------------------------------------
1337 subroutine fricmat_mult(z,d_a_tmp)
1339 use geometry_data, only: nres
1342 ! include 'DIMENSIONS'
1345 integer :: IERROR,ierr
1347 ! include 'COMMON.MD'
1348 ! include 'COMMON.IOUNITS'
1349 ! include 'COMMON.SETUP'
1350 ! include 'COMMON.TIME1'
1352 ! include 'COMMON.LANGEVIN'
1354 ! include 'COMMON.LANGEVIN.lang0'
1356 real(kind=8),dimension(dimen3) :: z,z1,d_a_tmp
1357 real(kind=8),dimension(6*nres) :: temp !(maxres6) maxres6=6*maxres
1358 real(kind=8) :: time00,time01
1359 integer :: i,j,k,ind,nres2
1361 !el if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
1364 if (nfgtasks.gt.1) then
1365 if (fg_rank.eq.0) then
1366 ! The matching BROADCAST for fg processors is called in ERGASTULUM
1368 call MPI_Bcast(9,1,MPI_INTEGER,king,FG_COMM,IERROR)
1369 time_Bcast=time_Bcast+MPI_Wtime()-time00
1370 ! print *,"Processor",myrank," BROADCAST iorder in FRICMAT_MULT"
1372 ! call MPI_Barrier(FG_COMM,IERROR)
1374 call MPI_Scatterv(z,ng_counts(0),ng_start(0),&
1375 MPI_DOUBLE_PRECISION,&
1376 z1,3*my_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
1377 ! write (2,*) "My chunk of z"
1378 ! do i=1,3*my_ng_count
1379 ! write (2,*) i,z(i)
1381 time_scatter=time_scatter+MPI_Wtime()-time00
1383 time_scatter_fmatmult=time_scatter_fmatmult+MPI_Wtime()-time00
1391 temp(ind)=temp(ind)-fricmat(j,i)*z1((j-1)*3+k+1)
1395 time_fricmatmult=time_fricmatmult+MPI_Wtime()-time01
1396 ! write (2,*) "Before REDUCE"
1397 ! write (2,*) "d_a_tmp before reduce"
1399 ! write (2,*) i,temp(i)
1403 call MPI_Reduce(temp(1),d_a_tmp(1),dimen3,MPI_DOUBLE_PRECISION,&
1404 MPI_SUM,king,FG_COMM,IERR)
1405 time_reduce=time_reduce+MPI_Wtime()-time00
1406 ! write (2,*) "After REDUCE"
1418 d_a_tmp(ind)=d_a_tmp(ind) &
1419 -fricmat(j,i)*z((j-1)*3+k+1)
1424 time_fricmatmult=time_fricmatmult+MPI_Wtime()-time01
1429 ! write (iout,*) "Vector d_a"
1431 ! write (2,*) i,d_a_tmp(i)
1434 end subroutine fricmat_mult
1435 !-----------------------------------------------------------------------------
1437 !-----------------------------------------------------------------------------