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'
28 use energy, only: grad_transform
30 use geometry_data, only: nres
31 use control_data !el, only: mucadyn,lmuca
34 real(kind=8) :: time00
36 ! include 'COMMON.VAR'
37 ! include 'COMMON.CHAIN'
38 ! include 'COMMON.DERIV'
39 ! include 'COMMON.GEO'
40 ! include 'COMMON.LOCAL'
41 ! include 'COMMON.INTERACT'
43 ! include 'COMMON.IOUNITS'
44 ! include 'COMMON.CONTROL'
45 ! include 'COMMON.MUCA'
46 ! include 'COMMON.TIME1'
47 integer ::i,j,ind,itime,mnum,innt,inct,inct_prev,ichain,n,mark
48 real(kind=8) :: zapas(6*nres) !,muca_factor !maxres6=6*maxres
49 ! the line below might be wrong
51 real(kind=8) :: rs(2*nres),xsolv(2*nres)
53 real(kind=8) :: rscheck(2*nres),rsold(2*nres)
56 logical :: lprn = .false.
57 !el common /cipiszcze/ itime
67 write (iout,*) "Potential forces backbone"
69 write (iout,'(i5,3e15.5,5x,3e15.5)')i,(-gcart(j,i),j=1,3)
71 write (iout,*) "Potential forces sidechain"
73 ! if (itype(i).ne.10 .and. itype(i).ne.ntyp1) &
74 write (iout,'(i5,3e15.5,5x,3e15.5)') i,(-gxcart(j,i),j=1,3)
79 innt=iposd_chain(ichain)
82 do i=chain_border(1,ichain),chain_border(2,ichain)
84 if (itype(i,1).eq.10.or.mnum.ge.3)then
85 rs(ind)=-gcart(j,i)-gxcart(j,i)
89 rs(ind+1)=-gxcart(j,i)
98 write(iout,*) "RHS of the 5-diag equations system",&
101 write(iout,*) i,rs(i)
105 call FDISYS (n,DM(innt),DU1(innt),DU2(innt),rs,xsolv)
107 write (iout,*) "Solution of the 5-diagonal equations system"
109 write (iout,'(i5,f10.5)') i,xsolv(i)
114 call fivediagmult(n,DMorig(innt),DU1orig(innt),DU2orig(innt),
117 write(iout,*) "i",i,"rsold",rsold(i),"rscheck",rscheck(i),
118 & "ratio",rscheck(i)/rsold(i)
124 do i=chain_border(1,ichain),chain_border(2,ichain)
126 if (itype(i,1).eq.10 .or.mnum.ge.3) then
131 d_a(j,i+nres)=xsolv(ind+1)
138 write (iout,*) "Acceleration in CA and SC oordinates"
140 write (iout,'(i3,3f10.5)') i,(d_a(j,i),j=1,3)
143 write (iout,'(i3,3f10.5)') i,(d_a(j,i+nres),j=1,3)
146 !C Conevert d_a to virtual-bon-vector basis
149 !c write (iout,*) "WLOS"
155 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum) .or.mnum.ge.3) then
157 d_a(j,i)=d_a(j,i+1)-d_a(j,i)
161 d_a(j,i+nres)=d_a(j,i+nres)-d_a(j,i)
162 d_a(j,i)=d_a(j,i+1)-d_a(j,i)
171 !c write (iout,*) "Shifting accelerations"
179 !c write (iout,*) "ichain",chain_border1(1,ichain)-1,
180 !c & chain_border1(1,ichain)
181 d_a(:,chain_border1(1,ichain)-1)=d_a(:,chain_border1(1,ichain))
182 d_a(:,chain_border1(1,ichain))=0.0d0
184 !c write (iout,*) "Adding accelerations"
186 !c write (iout,*) "chain",ichain,chain_border1(1,ichain)-1,
187 !c & chain_border(2,ichain-1)
188 d_a(:,chain_border1(1,ichain)-1)=&
189 d_a(:,chain_border1(1,ichain)-1)+d_a(:,chain_border(2,ichain-1))
190 d_a(:,chain_border(2,ichain-1))=0.0d0
199 innt=chain_border(1,ichain)
200 inct=chain_border(2,ichain)
202 d_a(j,inct_prev)=d_a(j,innt)-aaux(j)
207 if ((itype(i).ne.10).and.(mnum.le.3)) then
209 d_a(j,i+nres)=d_a(j,i+nres)-d_a(j,i)
218 d_a(j,i)=d_a(j,i+1)-d_a(j,i)
224 write(iout,*) 'acceleration 3D FIVEDIAG in dC and dX'
226 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3)
229 write (iout,'(i3,3f10.5,3x,3f10.5)')&
230 i,(d_a(j,i+nres),j=1,3)
241 write (iout,*) "Potential forces backbone"
244 if (lprn) write (iout,'(i5,3e15.5,5x,3e15.5)') &
245 i,(-gcart(j,i),j=1,3)
248 zapas(ind)=-gcart(j,i)
251 if (lprn) write (iout,*) "Potential forces sidechain"
254 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
256 if (lprn) write (iout,'(i5,3e15.5,5x,3e15.5)') &
257 i,(-gxcart(j,i),j=1,3)
260 zapas(ind)=-gxcart(j,i)
265 call ginv_mult(zapas,d_a_work)
274 d_a(j,i)=d_a_work(ind)
279 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
280 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
284 d_a(j,i+nres)=d_a_work(ind)
292 if(mucadyn.gt.0) call muca_update(potE)
293 factor=muca_factor(potE)*t_bath*Rb
295 !d print *,'lmuca ',factor,potE
297 d_a(j,0)=d_a(j,0)*factor
301 d_a(j,i)=d_a(j,i)*factor
306 d_a(j,i+nres)=d_a(j,i+nres)*factor
313 write(iout,*) 'acceleration 3D'
314 write (iout,'(i3,3f10.5,3x,3f10.5)') 0,(d_a(j,0),j=1,3)
316 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3)
319 write (iout,'(i3,3f10.5,3x,3f10.5)') &
320 i+nres,(d_a(j,i+nres),j=1,3)
324 time_lagrangian=time_lagrangian+MPI_Wtime()-time00
327 end subroutine lagrangian
328 !-----------------------------------------------------------------------------
329 subroutine setup_MD_matrices
331 use geometry_data, only: nres,nside
335 use geometry, only:int_bounds
337 ! implicit real*8 (a-h,o-z)
338 ! include 'DIMENSIONS'
342 real(kind=8) :: time00
343 ! real(kind=8) ,allocatable, dimension(:) :: DDM,DDU1,DDU2
345 ! include 'COMMON.SETUP'
346 ! include 'COMMON.VAR'
347 ! include 'COMMON.CHAIN'
348 ! include 'COMMON.DERIV'
349 ! include 'COMMON.GEO'
350 ! include 'COMMON.LOCAL'
351 ! include 'COMMON.INTERACT'
352 ! include 'COMMON.MD'
354 ! include 'COMMON.LANGEVIN'
356 ! include 'COMMON.LANGEVIN.lang0'
358 ! include 'COMMON.IOUNITS'
359 ! include 'COMMON.TIME1'
360 logical :: lprn = .false.
363 real(kind=8),allocatable,dimension(:,:) :: Bmat,matmult
366 real(kind=8),dimension(:),allocatable :: massvec,sqreig !(maxres2) maxres2=2*maxres
367 real(kind=8) :: relfeh,eps1,eps2
368 !el real(kind=8),dimension(:),allocatable :: Ghalf
369 !el real(kind=8),dimension(2*nres*(2*nres+1)/2) :: Ghalf !(mmaxres2) (mmaxres2=(maxres2*(maxres2+1)/2))
370 !el real(kind=8),dimension(2*nres,2*nres) :: Gcopy !(maxres2,maxres2)
371 !el real(kind=8),dimension(:,:),allocatable :: Gcopy
372 real(kind=8),dimension(:),allocatable :: work !(8*maxres6)
373 integer,dimension(:),allocatable :: iwork !(maxres6) maxres6=6*maxres
374 ! common /jakistam/ iwork,work,massvec,sqreig
375 !el common /przechowalnia/ Gcopy,Ghalf
376 real(kind=8) :: coeff,mscab
377 integer :: i,j,ind,ind1,k,l,ii,jj,m,m1,ii1,iti,nres2,ierr,nind,mark
379 integer :: iz,mnum,ichain,n,dimenp,innt,inct
380 if(.not.allocated(massvec)) then
381 allocate(massvec(2*nres),sqreig(2*nres))
382 allocate(work(8*6*nres))
383 allocate(iwork(6*nres))
385 print *,"just entered"
389 write (iout,*) "before FIVEDIAG"
391 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !mmaxres2=(maxres2*(maxres+1)/2)
394 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !mmaxres2=(maxres2*(maxres+1)/2)
395 write (iout,*) "ALLOCATE"
397 if(.not.allocated(Gcopy)) allocate(Gcopy(nres2,nres2)) !(maxres2,maxres2)
398 ! if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !mmaxres2=(maxres2*(maxres+1)/2)
399 if(.not.allocated(Bmat)) allocate(Bmat(nres2,nres2))
400 if(.not.allocated(matmult)) allocate(matmult(nres2,nres2))
403 ! Set up the matrix of the (dC,dX)-->(C,X) transformation (A), the
404 ! inertia matrix (Gmat) and the inverse of the inertia matrix (Ginv)
406 ! Determine the number of degrees of freedom (dimen) and the number of
408 ! dimen=(nct-nnt+1)+nside
409 ! dimen1=(nct-nnt)+(nct-nnt+1)
411 ! write (iout,*) "nnt",nnt," nct",nct," nside",nside
416 if (iabs(itype(nnt)).eq.10) then
421 DM(1)=DM(1)+isc(iabs(itype(nnt)))
422 DM(2)=msc(iabs(itype(nnt)))+isc(iabs(itype(nnt)))
428 ! if (iabs(itype(i,1)).eq.ntyp1) cycle
430 if (iabs(itype(i,1)).eq.10 .or. &
431 iabs(itype(i,mnum)).eq.ntyp1_molec(mnum) .or. mnum.ge.4) then
432 if (iabs(itype(i,1)).eq.10) DM(ind)=DM(ind)+msc(10)
435 DM(ind)=DM(ind)+isc(iabs(itype(i,1)))
436 DM(ind+1)=msc(iabs(itype(i,1)))+isc(iabs(itype(i,1)))
442 if (iabs(itype(nct)).eq.10) then
443 DM(ind)=DM(ind)+msc(10)
446 DM(ind)=DM(ind)+isc(iabs(itype(nct)))
447 DM(ind+1)=msc(iabs(itype(nct)))+isc(iabs(itype(nct)))
456 if (iabs(itype(i,1)).ne.10 .and.iabs(itype((i))).ne.ntyp1 &
458 DU1(ind)=-isc(iabs(itype(i,1)))
470 ! if (iabs(itype(i,1)).eq.ntyp1) cycle
471 write (iout,*) "i",i," itype",itype(i,1),ntyp1
472 if (iabs(itype(i,1)).ne.10 .and. &
473 iabs(itype(i,mnum)).ne.ntyp1_molec(mnum) .and. mnum.lt.4) then
488 dimen=dimen+chain_length(ichain)
489 dimen1=dimen1+2*chain_length(ichain)-1
490 dimenp=dimenp+chain_length(ichain)-1
492 write (iout,*) "Number of Calphas",dimen
493 write (iout,*) "Number of sidechains",nside
494 write (iout,*) "Number of peptide groups",dimenp
495 dimen=dimen+nside ! number of centers
496 dimen3=3*dimen ! degrees of freedom
497 write (iout,*) "Number of centers",dimen
498 write (iout,*) "Degrees of freedom:",dimen3
502 iposd_chain(ichain)=ind
503 innt=chain_border(1,ichain)
505 inct=chain_border(2,ichain)
506 if (mnum.eq.5) mp(mnum)=0.0
507 ! if (mnum.eq.5) mp(mnum)=msc(itype(innt,mnum),mnum)
508 DM(ind)=mp(mnum)/4+ip(mnum)/4
509 if (iabs(itype(innt,1)).eq.10.or.molnum(innt).gt.2) then
510 DM(ind)=DM(ind)+msc(itype(innt,mnum),mnum)
514 DM(ind)=DM(ind)+isc(iabs(itype(innt,mnum)),mnum)
515 DM(ind+1)=msc(iabs(itype(innt,mnum)),mnum)+isc(iabs(itype(innt,mnum)),mnum)
519 write (iout,*) "ind",ind," nind",nind
522 ! if (iabs(itype(i)).eq.ntyp1) cycle
523 ! if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
524 ! if (mnum.eq.5) ip(mnum)=isc(itype(i,mnum),mnum)
525 if (mnum.eq.5) mp(mnum)=0.0
526 ! if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
527 DM(ind)=2*ip(mnum)/4+mp(mnum)/2
528 if (iabs(itype(i,1)).eq.10.or.molnum(i).gt.2) then
529 ! if (iabs(itype(i,1)).eq.10.or.molnum(i).gt.2)&
530 ! DM(ind)=DM(ind)+msc(itype(i,molnum(i)),mnum)
531 DM(ind)=DM(ind)+msc(itype(i,mnum),mnum)
535 DM(ind)=DM(ind)+isc(iabs(itype(i,mnum)),mnum)
536 DM(ind+1)=msc(iabs(itype(i,mnum)),mnum)+isc(iabs(itype(i,mnum)),mnum)
540 write (iout,*) "i",i," ind",ind," nind",nind
542 if (inct.gt.innt) then
543 ! DM(ind)=ip4+mp(molnum(inct))/4
545 if (mnum.eq.5) mp(mnum)=0.0
546 ! if (mnum.eq.5) mp(mnum)=msc(itype(inct,molnum(inct)),molnum(inct))
548 DM(ind)=mp(mnum)/4+ip(mnum)/4
549 if (iabs(itype(inct,mnum)).eq.10.or.molnum(inct).gt.2) then
550 DM(ind)=DM(ind)+msc(itype(inct,molnum(inct)),molnum(inct))
555 DM(ind)=DM(ind)+isc(iabs(itype(inct,mnum)),mnum)
556 DM(ind+1)=msc(iabs(itype(inct,mnum)),mnum)+isc(iabs(itype(inct,mnum)),mnum)
561 write (iout,*) "ind",ind," nind",nind
562 dimen_chain(ichain)=nind
566 ind=iposd_chain(ichain)
567 innt=chain_border(1,ichain)
568 inct=chain_border(2,ichain)
571 if (iabs(itype(i,1)).ne.10 .and.iabs(itype(i,mnum)).ne.ntyp1_molec(mnum).and.mnum.le.2) then
572 DU1(ind)=-isc(iabs(itype(i,mnum)),mnum)
576 ! if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
577 ! if (mnum.eq.5) ip(mnum)=isc(itype(i,mnum),mnum)
578 if (mnum.eq.5) mp(mnum)=0.0
579 DU1(ind)=mp(mnum)/4-ip(mnum)/4
586 ind=iposd_chain(ichain)
587 innt=chain_border(1,ichain)
588 inct=chain_border(2,ichain)
591 ! if (iabs(itype(i)).eq.ntyp1) cycle
592 !c write (iout,*) "i",i," itype",itype(i),ntyp1
593 if (iabs(itype(i,1)).ne.10 .and. iabs(itype(i,mnum)).ne.ntyp1_molec(mnum).and.mnum.le.2) then
594 ! if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
595 if (mnum.eq.5) mp(mnum)=0.0
596 DU2(ind)=mp(mnum)/4-ip(mnum)/4
610 write (iout,*)"The upper part of the five-diagonal inertia matrix"
613 if (gmatout) write (iout,'(a,i5)') 'Chain',ichain
614 n=dimen_chain(ichain)
615 innt=iposd_chain(ichain)
616 inct=iposd_chain(ichain)+dimen_chain(ichain)-1
619 if (i.lt.inct-1) then
620 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i),DU2(i)
621 else if (i.eq.inct-1) then
622 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i)
624 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i)
628 call FDISYP (n, DM(innt:inct), DU1(innt:inct-1),&
629 DU2(innt:inct-1), MARK)
633 "ERROR: the inertia matrix is not positive definite for chain",&
636 call MPI_Finalize(ierr)
639 else if (mark.eq.0) then
641 "ERROR: the inertia matrix is singular for chain",ichain
643 call MPI_Finalize(ierr)
645 else if (mark.eq.1) then
647 write (iout,*) "The transformed five-diagonal inertia matrix"
648 write (iout,'(a,i5)') 'Chain',ichain
650 if (i.lt.inct-1) then
651 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i),DU2(i)
652 else if (i.eq.inct-1) then
653 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i)
655 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i)
661 ! Diagonalization of the pentadiagonal matrix
670 dimen=(nct-nnt+1)+nside
671 dimen1=(nct-nnt)+(nct-nnt+1)
673 write (iout,*) "nnt",nnt," nct",nct," nside",nside
676 if (nfgtasks.gt.1) then
678 call MPI_Bcast(5,1,MPI_INTEGER,king,FG_COMM,IERROR)
679 time_Bcast=time_Bcast+MPI_Wtime()-time00
680 call int_bounds(dimen,igmult_start,igmult_end)
681 igmult_start=igmult_start-1
682 call MPI_Allgather(3*igmult_start,1,MPI_INTEGER,&
683 ng_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
684 my_ng_count=igmult_end-igmult_start
685 call MPI_Allgather(3*my_ng_count,1,MPI_INTEGER,ng_counts(0),1,&
686 MPI_INTEGER,FG_COMM,IERROR)
687 write (iout,*) 'Processor:',fg_rank,' CG group',kolor,&
688 ' absolute rank',myrank,' igmult_start',igmult_start,&
689 ' igmult_end',igmult_end,' count',my_ng_count
690 write (iout,*) "ng_start",(ng_start(i),i=0,nfgtasks-1)
691 write (iout,*) "ng_counts",(ng_counts(i),i=0,nfgtasks-1)
701 ! write (iout,*) "dimen",dimen," dimen1",dimen1," dimen3",dimen3
702 ! Zeroing out A and fricmat
708 ! Diagonal elements of the dC part of A and the respective friction coefficients
711 ! print *,"TUTUTUT?!",nnt,nct-1
716 coeff=0.25d0*IP(mnum)
717 print *,"TU",i,itype(i,mnum),mnum
718 if (mnum.ge.5) mp(mnum)=msc(itype(i,mnum),mnum)
719 print *,"TU2",i,coeff,mp(mnum)
720 massvec(ind1)=mp(mnum)
722 ! print *,"i",mp(mnum)
726 ! Off-diagonal elements of the dC part of A
733 ! Diagonal elements of the dX part of A and the respective friction coefficients
739 msc(ntyp1_molec(i),i)=1.0d0
741 msc(ntyp1_molec(4),4)=1.0d0
742 ! print *,"TU3",ntyp1_molec(4)-1
743 msc(ntyp1_molec(4)-1,4)=1.0d0
749 ! if (mnum.eq.5) then
752 mscab=msc(iabs(iti),mnum)
756 if (iti.ne.10 .and. iti.ne.ntyp1_molec(mnum) .and. mnum.lt.4) then
760 Gmat(ii1,ii1)=ISC(iabs(iti),mnum)
763 ! Off-diagonal elements of the dX part of A
778 write (iout,*) "Vector massvec"
780 write (iout,*) i,massvec(i)
782 write (iout,'(//a)') "A"
783 call matout(dimen,dimen1,nres2,nres2,A)
786 ! Calculate the G matrix (store in Gmat)
791 dtdi=dtdi+A(j,k)*A(j,i)*massvec(j)
793 Gmat(k,i)=Gmat(k,i)+dtdi
798 write (iout,'(//a)') "Gmat"
799 call matout(dimen,dimen,nres2,nres2,Gmat)
808 ! Invert the G matrix
809 call MATINVERT(dimen,nres2,Gcopy,Ginv,osob)
811 write (iout,'(//a)') "Ginv"
812 call matout(dimen,dimen,nres2,nres2,Ginv)
820 if ((itype(i,1).eq.10).or.(itype(i,mnum).eq.ntyp1_molec(mnum))&
821 .or.(mnum.ge.4)) then
829 Bmat(i-nnt+1+(nct-nnt)+1,j-1)=-1
830 Bmat(i-nnt+1+(nct-nnt)+1,j)=1
833 Bmat(i-nnt+1+(nct-nnt)+1,j-1)=-1
834 Bmat(i-nnt+1+(nct-nnt)+1,j)=1
838 write (iout,*) "j",j," dimen",dimen
840 write (iout,'(//a)') "Bmat"
841 call matout(dimen,dimen,nres2,nres2,Bmat)
844 write(iout,*) "before Gcopy",dimen,nres*2
848 ! write (iout,*) "myij",i,j
851 ! write(iout,*) "i,j,k,l",i,j,k,l
852 Gcopy(i,j)=Gcopy(i,j)+Bmat(k,i)*Gmat(k,l)*Bmat(l,j)
859 write (iout,'(//a)') "Gmat-transformed"
860 call matout(dimen,dimen,nres2,nres2,Gcopy)
863 if (nfgtasks.gt.1) then
864 myginv_ng_count=nres2*my_ng_count
865 call MPI_Allgather(nres2*igmult_start,1,MPI_INTEGER,&
866 nginv_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
867 call MPI_Allgather(myginv_ng_count,1,MPI_INTEGER,&
868 nginv_counts(0),1,MPI_INTEGER,FG_COMM,IERROR)
869 write (iout,*) "nginv_start",(nginv_start(i),i=0,nfgtasks-1)
870 write (iout,*) "nginv_counts",(nginv_counts(i),i=0,nfgtasks-1)
872 ! call MPI_Scatterv(ginv(1,1),nginv_counts(0),
873 ! & nginv_start(0),MPI_DOUBLE_PRECISION,ginv,
874 ! & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
875 ! call MPI_Barrier(FG_COMM,IERR)
877 call MPI_Scatterv(ginv(1,1),nginv_counts(0),&
878 nginv_start(0),MPI_DOUBLE_PRECISION,gcopy(1,1),&
879 myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
881 time_scatter_ginv=time_scatter_ginv+MPI_Wtime()-time00
888 ! write (iout,*) "Master's chunk of ginv"
889 ! call MATOUT2(my_ng_count,dimen,maxres2,maxres2,ginv)
893 write (iout,*) "The G matrix is singular."
894 write (iout,'(//a)') "Gmat-transformed"
895 call matout(dimen,dimen,nres2,nres2,Gcopy)
898 ! Compute G**(-1/2) and G**(1/2)
906 call gldiag(nres2,dimen,dimen,Ghalf,work,Geigen,Gvec,&
909 write (iout,'(//a)') &
910 "Eigenvectors and eigenvalues of the G matrix"
911 call eigout(dimen,dimen,nres2,nres2,Gvec,Geigen)
914 sqreig(i)=dsqrt(Geigen(i))
922 Gsqrp(i,j)=Gsqrp(i,j)+Gvec(i,k)*Gvec(j,k)*sqreig(k)
923 Gsqrm(i,j)=Gsqrm(i,j)+Gvec(i,k)*Gvec(j,k)/sqreig(k)
924 Gcopy(i,j)=Gcopy(i,j)+Gvec(i,k)*Gvec(j,k)*Geigen(k)
929 write (iout,*) "Comparison of original and restored G"
932 write (iout,'(2i5,5f10.5)') i,j,Gmat(i,j),Gcopy(i,j),&
933 Gmat(i,j)-Gcopy(i,j),Gsqrp(i,j),Gsqrm(i,j)
937 if (allocated(Gcopy)) deallocate(Gcopy)
939 !write(iout,*) "end setup_MD_matr"
941 end subroutine setup_MD_matrices
942 !-----------------------------------------------------------------------------
943 subroutine EIGOUT(NC,NR,LM2,LM3,A,B)
945 ! implicit real*8 (a-h,o-z)
946 ! include 'DIMENSIONS'
947 ! include 'COMMON.IOUNITS'
948 integer :: LM2,LM3,NC,NR,KA,KC,KB,I,J,N
949 real(kind=8) :: A(LM2,LM3),B(LM2)
953 WRITE(IOUT,600) (I,I=KA,KB)
954 WRITE(IOUT,601) (B(I),I=KA,KB)
958 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
964 4 IF (KB.EQ.NC) RETURN
968 600 FORMAT (// 9H ROOT NO.,I4,9I11)
969 601 FORMAT (/5X,10(1PE11.4))
971 603 FORMAT (I5,10F11.5)
973 end subroutine EIGOUT
974 !-----------------------------------------------------------------------------
975 subroutine MATOUT(NC,NR,LM2,LM3,A)
977 ! implicit real*8 (a-h,o-z)
978 ! include 'DIMENSIONS'
979 ! include 'COMMON.IOUNITS'
980 integer :: LM2,LM3,NC,NR,KA,KC,KB,I,J,N
981 real(kind=8) :: A(LM2,LM3)
985 WRITE(IOUT,600) (I,I=KA,KB)
989 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
995 4 IF (KB.EQ.NC) RETURN
999 600 FORMAT (//5x,9I11)
1001 603 FORMAT (I5,10F11.3)
1003 end subroutine MATOUT
1004 !-----------------------------------------------------------------------------
1005 subroutine MATOUT1(NC,NR,LM2,LM3,A)
1007 ! implicit real*8 (a-h,o-z)
1008 ! include 'DIMENSIONS'
1009 ! include 'COMMON.IOUNITS'
1010 integer :: LM2,LM3,NC,NR,KA,KC,KB,I,J,N
1011 real(kind=8) :: A(LM2,LM3)
1015 WRITE(IOUT,600) (I,I=KA,KB)
1019 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
1025 4 IF (KB.EQ.NC) RETURN
1029 600 FORMAT (//5x,7(3I5,2x))
1031 603 FORMAT (I5,7(3F5.1,2x))
1033 end subroutine MATOUT1
1034 !-----------------------------------------------------------------------------
1035 subroutine MATOUT2(NC,NR,LM2,LM3,A)
1037 ! implicit real*8 (a-h,o-z)
1038 ! include 'DIMENSIONS'
1039 ! include 'COMMON.IOUNITS'
1040 integer :: I,J,KA,KC,KB,N
1041 integer :: LM2,LM3,NC,NR
1042 real(kind=8) :: A(LM2,LM3)
1046 WRITE(IOUT,600) (I,I=KA,KB)
1050 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
1056 4 IF (KB.EQ.NC) RETURN
1060 600 FORMAT (//5x,4(3I9,2x))
1062 603 FORMAT (I5,4(3F9.3,2x))
1064 end subroutine MATOUT2
1066 subroutine fivediagmult(n,DM,DU1,DU2,x,y)
1068 double precision DM(n),DU1(n),DU2(n),x(n),y(n)
1070 y(1)=DM(1)*x(1)+DU1(1)*x(2)+DU2(1)*x(3)
1071 y(2)=DU1(1)*x(1)+DM(2)*x(2)+DU1(2)*x(3)+DU2(2)*x(4)
1073 y(i)=DU2(i-2)*x(i-2)+DU1(i-1)*x(i-1)+DM(i)*x(i) &
1074 +DU1(i)*x(i+1)+DU2(i)*x(i+2)
1076 y(n-1)=DU2(n-3)*x(n-3)+DU1(n-2)*x(n-2)+DM(n-1)*x(n-1) &
1078 y(n)=DU2(n-2)*x(n-2)+DU1(n-1)*x(n-1)+DM(n)*x(n)
1081 !c---------------------------------------------------------------------------
1082 subroutine fivediaginv_mult(ndim,forces,d_a_vec)
1083 use energy_data, only:nchain,chain_border,nct,nnt,molnum,&
1086 double precision forces(3*ndim),accel(3,0:maxres2),rs(ndim), &
1087 xsolv(ndim),d_a_vec(6*nres)
1088 integer i,j,ind,ichain,n,iposc,innt,inct,inct_prev,mnum
1091 !Compute accelerations in Calpha and SC
1093 n=dimen_chain(ichain)
1094 iposc=iposd_chain(ichain)
1095 innt=chain_border(1,ichain)
1096 inct=chain_border(2,ichain)
1097 do i=iposc,iposc+n-1
1098 rs(i-iposc+1)=forces(3*(i-1)+j)
1101 write (iout,*) "j",j," chain",ichain
1103 write (iout,'(f10.5)') (rs(i),i=1,n)
1105 call FDISYS (n,DM(iposc),DU1(iposc),DU2(iposc),rs,xsolv)
1107 write (iout,*) "xsolv"
1108 write (iout,'(f10.5)') (xsolv(i),i=1,n)
1113 if (itype(i,1).eq.10.or.mnum.gt.2)then
1114 accel(j,i)=xsolv(ind)
1117 accel(j,i)=xsolv(ind)
1118 accel(j,i+nres)=xsolv(ind+1)
1124 !C Convert d_a to virtual-bon-vector basis
1126 write (iout,*) "accel in CA-SC basis"
1128 write (iout,'(i5,3f10.5,5x,3f10.5)') i,(accel(j,i),j=1,3),
1129 & (accel(j,i+nres),j=1,3)
1131 write (iout,*) "nnt",nnt
1134 accel(:,0)=accel(:,1)
1138 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
1141 accel(j,i)=accel(j,i+1)-accel(j,i)
1145 accel(j,i+nres)=accel(j,i+nres)-accel(j,i)
1146 accel(j,i)=accel(j,i+1)-accel(j,i)
1152 accel(:,2*nres)=0.0d0
1154 accel(:,0)=accel(:,1)
1158 accel(:,chain_border1(1,ichain)-1)= &
1159 accel(:,chain_border1(1,ichain))
1160 accel(:,chain_border1(1,ichain))=0.0d0
1163 accel(:,chain_border1(1,ichain)-1)= &
1164 accel(:,chain_border1(1,ichain)-1) &
1165 +accel(:,chain_border(2,ichain-1))
1166 accel(:,chain_border(2,ichain-1))=0.0d0
1169 write (iout,*) "accel in fivediaginv_mult: 1"
1171 write(iout,'(i5,3f10.5)') i,(accel(j,i),j=1,3)
1175 d_a_vec(j)=accel(j,0)
1180 d_a_vec(ind+j)=accel(j,i)
1186 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1187 .and.mnum.le.2) then
1189 d_a_vec(ind+j)=accel(j,i+nres)
1195 write (iout,*) "d_a_vec"
1196 write (iout,'(3f10.5)') (d_a_vec(j),j=1,3*(nct-nnt+nside))
1203 !-----------------------------------------------------------------------------
1204 subroutine ginv_mult(z,d_a_tmp)
1206 use geometry_data, only: nres
1209 ! implicit real*8 (a-h,o-z)
1210 ! include 'DIMENSIONS'
1213 integer :: ierr,ierror
1215 ! include 'COMMON.SETUP'
1216 ! include 'COMMON.TIME1'
1217 ! include 'COMMON.MD'
1218 real(kind=8),dimension(dimen3) :: z,z1,d_a_tmp
1219 real(kind=8),dimension(6*nres) :: temp !(maxres6) maxres6=6*maxres
1220 real(kind=8) :: time00,time01
1221 integer :: i,j,k,ind
1223 if (nfgtasks.gt.1) then
1224 if (fg_rank.eq.0) then
1225 ! The matching BROADCAST for fg processors is called in ERGASTULUM
1227 call MPI_Bcast(4,1,MPI_INTEGER,king,FG_COMM,IERROR)
1228 time_Bcast=time_Bcast+MPI_Wtime()-time00
1229 ! print *,"Processor",myrank," BROADCAST iorder in GINV_MULT"
1231 ! write (2,*) "time00",time00
1232 ! write (2,*) "Before Scatterv"
1234 ! write (2,*) "Whole z (for FG master)"
1236 ! write (2,*) i,z(i)
1238 ! call MPI_Barrier(FG_COMM,IERROR)
1240 !elwrite(iout,*) "do tej pory jest OK, MPI_Scatterv w ginv_mult"
1241 call MPI_Scatterv(z,ng_counts(0),ng_start(0),&
1242 MPI_DOUBLE_PRECISION,&
1243 z1,3*my_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
1244 ! write (2,*) "My chunk of z"
1245 ! do i=1,3*my_ng_count
1246 ! write (2,*) i,z(i)
1248 ! write (2,*) "After SCATTERV"
1250 ! write (2,*) "MPI_Wtime",MPI_Wtime()
1251 time_scatter=time_scatter+MPI_Wtime()-time00
1253 time_scatter_ginvmult=time_scatter_ginvmult+MPI_Wtime()-time00
1255 ! write (2,*) "time_scatter",time_scatter
1256 ! write (2,*) "dimen",dimen," dimen3",dimen3," my_ng_count",
1265 ! write (2,*) "k,i,j,ind",k,i,j,ind,(j-1)*3+k+1,
1266 ! & Ginv(i,j),z((j-1)*3+k+1),
1267 ! & Ginv(i,j)*z((j-1)*3+k+1)
1268 ! temp(ind)=temp(ind)+Ginv(i,j)*z((j-1)*3+k+1)
1269 temp(ind)=temp(ind)+Ginv(j,i)*z1((j-1)*3+k+1)
1273 time_ginvmult=time_ginvmult+MPI_Wtime()-time01
1274 ! write (2,*) "Before REDUCE"
1276 ! write (2,*) "z before reduce"
1278 ! write (2,*) i,temp(i)
1281 call MPI_Reduce(temp(1),d_a_tmp(1),dimen3,MPI_DOUBLE_PRECISION,&
1282 MPI_SUM,king,FG_COMM,IERR)
1283 time_reduce=time_reduce+MPI_Wtime()-time00
1284 ! write (2,*) "After REDUCE"
1296 ! write (2,*) "k,i,j,ind",k,i,j,ind,(j-1)*3+k+1
1298 ! & Ginv(i,j),z((j-1)*3+k+1),
1299 ! & Ginv(i,j)*z((j-1)*3+k+1)
1300 d_a_tmp(ind)=d_a_tmp(ind) &
1301 +Ginv(j,i)*z((j-1)*3+k+1)
1302 ! d_a_tmp(ind)=d_a_tmp(ind)
1303 ! & +Ginv(i,j)*z((j-1)*3+k+1)
1308 time_ginvmult=time_ginvmult+MPI_Wtime()-time01
1314 end subroutine ginv_mult
1315 !-----------------------------------------------------------------------------
1317 subroutine ginv_mult_test(z,d_a_tmp)
1319 ! include 'DIMENSIONS'
1320 !el integer :: dimen
1321 ! include 'COMMON.MD'
1322 real(kind=8),dimension(dimen) :: z,d_a_tmp
1323 real(kind=8),dimension(dimen/3) :: ztmp,dtmp
1324 integer :: i,j,k,ind
1328 ! d_a_tmp(i)=d_a_tmp(i)+Ginv(i,j)*z(j)
1337 ztmp(j)=z((j-1)*3+k+1)
1340 call alignx(16,ztmp(1))
1341 call alignx(16,dtmp(1))
1342 call alignx(16,Ginv(1,1))
1347 dtmp(i)=dtmp(i)+Ginv(i,j)*ztmp(j)
1352 d_a_tmp(ind)=dtmp(i)
1356 end subroutine ginv_mult_test
1358 !-----------------------------------------------------------------------------
1359 subroutine fricmat_mult(z,d_a_tmp)
1361 use geometry_data, only: nres
1364 ! include 'DIMENSIONS'
1367 integer :: IERROR,ierr
1369 ! include 'COMMON.MD'
1370 ! include 'COMMON.IOUNITS'
1371 ! include 'COMMON.SETUP'
1372 ! include 'COMMON.TIME1'
1374 ! include 'COMMON.LANGEVIN'
1376 ! include 'COMMON.LANGEVIN.lang0'
1378 real(kind=8),dimension(dimen3) :: z,z1,d_a_tmp
1379 real(kind=8),dimension(6*nres) :: temp !(maxres6) maxres6=6*maxres
1380 real(kind=8) :: time00,time01
1381 integer :: i,j,k,ind,nres2
1383 !el if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
1386 if (nfgtasks.gt.1) then
1387 if (fg_rank.eq.0) then
1388 ! The matching BROADCAST for fg processors is called in ERGASTULUM
1390 call MPI_Bcast(9,1,MPI_INTEGER,king,FG_COMM,IERROR)
1391 time_Bcast=time_Bcast+MPI_Wtime()-time00
1392 ! print *,"Processor",myrank," BROADCAST iorder in FRICMAT_MULT"
1394 ! call MPI_Barrier(FG_COMM,IERROR)
1396 call MPI_Scatterv(z,ng_counts(0),ng_start(0),&
1397 MPI_DOUBLE_PRECISION,&
1398 z1,3*my_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
1399 ! write (2,*) "My chunk of z"
1400 ! do i=1,3*my_ng_count
1401 ! write (2,*) i,z(i)
1403 time_scatter=time_scatter+MPI_Wtime()-time00
1405 time_scatter_fmatmult=time_scatter_fmatmult+MPI_Wtime()-time00
1413 temp(ind)=temp(ind)-fricmat(j,i)*z1((j-1)*3+k+1)
1417 time_fricmatmult=time_fricmatmult+MPI_Wtime()-time01
1418 ! write (2,*) "Before REDUCE"
1419 ! write (2,*) "d_a_tmp before reduce"
1421 ! write (2,*) i,temp(i)
1425 call MPI_Reduce(temp(1),d_a_tmp(1),dimen3,MPI_DOUBLE_PRECISION,&
1426 MPI_SUM,king,FG_COMM,IERR)
1427 time_reduce=time_reduce+MPI_Wtime()-time00
1428 ! write (2,*) "After REDUCE"
1440 d_a_tmp(ind)=d_a_tmp(ind) &
1441 -fricmat(j,i)*z((j-1)*3+k+1)
1446 time_fricmatmult=time_fricmatmult+MPI_Wtime()-time01
1451 ! write (iout,*) "Vector d_a"
1453 ! write (2,*) i,d_a_tmp(i)
1456 end subroutine fricmat_mult
1457 !-----------------------------------------------------------------------------
1459 !-----------------------------------------------------------------------------