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 !TEST 27.06.2023 godz 16.00
180 if (molnum(chain_border1(1,ichain)+1).eq.5) cycle
181 !c write (iout,*) "ichain",chain_border1(1,ichain)-1,
182 !c & chain_border1(1,ichain)
183 d_a(:,chain_border1(1,ichain)-1)=d_a(:,chain_border1(1,ichain))
184 d_a(:,chain_border1(1,ichain))=0.0d0
186 !c write (iout,*) "Adding accelerations"
188 if (molnum(chain_border1(1,ichain)+1).eq.5) cycle
189 !c write (iout,*) "chain",ichain,chain_border1(1,ichain)-1,
190 !c & chain_border(2,ichain-1)
191 d_a(:,chain_border1(1,ichain)-1)=&
192 d_a(:,chain_border1(1,ichain)-1)+d_a(:,chain_border(2,ichain-1))
193 d_a(:,chain_border(2,ichain-1))=0.0d0
202 innt=chain_border(1,ichain)
203 inct=chain_border(2,ichain)
205 d_a(j,inct_prev)=d_a(j,innt)-aaux(j)
210 if ((itype(i).ne.10).and.(mnum.le.3)) then
212 d_a(j,i+nres)=d_a(j,i+nres)-d_a(j,i)
221 d_a(j,i)=d_a(j,i+1)-d_a(j,i)
227 write(iout,*) 'acceleration 3D FIVEDIAG in dC and dX'
229 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3)
232 write (iout,'(i3,3f10.5,3x,3f10.5)')&
233 i,(d_a(j,i+nres),j=1,3)
244 write (iout,*) "Potential forces backbone"
247 if (lprn) write (iout,'(i5,3e15.5,5x,3e15.5)') &
248 i,(-gcart(j,i),j=1,3)
251 zapas(ind)=-gcart(j,i)
254 if (lprn) write (iout,*) "Potential forces sidechain"
257 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
259 if (lprn) write (iout,'(i5,3e15.5,5x,3e15.5)') &
260 i,(-gxcart(j,i),j=1,3)
263 zapas(ind)=-gxcart(j,i)
268 call ginv_mult(zapas,d_a_work)
277 d_a(j,i)=d_a_work(ind)
282 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
283 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
287 d_a(j,i+nres)=d_a_work(ind)
295 if(mucadyn.gt.0) call muca_update(potE)
296 factor=muca_factor(potE)*t_bath*Rb
298 !d print *,'lmuca ',factor,potE
300 d_a(j,0)=d_a(j,0)*factor
304 d_a(j,i)=d_a(j,i)*factor
309 d_a(j,i+nres)=d_a(j,i+nres)*factor
316 write(iout,*) 'acceleration 3D'
317 write (iout,'(i3,3f10.5,3x,3f10.5)') 0,(d_a(j,0),j=1,3)
319 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3)
322 write (iout,'(i3,3f10.5,3x,3f10.5)') &
323 i+nres,(d_a(j,i+nres),j=1,3)
327 time_lagrangian=time_lagrangian+MPI_Wtime()-time00
330 end subroutine lagrangian
331 !-----------------------------------------------------------------------------
332 subroutine setup_MD_matrices
334 use geometry_data, only: nres,nside
338 use geometry, only:int_bounds
340 ! implicit real*8 (a-h,o-z)
341 ! include 'DIMENSIONS'
345 real(kind=8) :: time00
346 ! real(kind=8) ,allocatable, dimension(:) :: DDM,DDU1,DDU2
348 ! include 'COMMON.SETUP'
349 ! include 'COMMON.VAR'
350 ! include 'COMMON.CHAIN'
351 ! include 'COMMON.DERIV'
352 ! include 'COMMON.GEO'
353 ! include 'COMMON.LOCAL'
354 ! include 'COMMON.INTERACT'
355 ! include 'COMMON.MD'
357 ! include 'COMMON.LANGEVIN'
359 ! include 'COMMON.LANGEVIN.lang0'
361 ! include 'COMMON.IOUNITS'
362 ! include 'COMMON.TIME1'
363 logical :: lprn = .false.
366 real(kind=8),allocatable,dimension(:,:) :: Bmat,matmult
369 real(kind=8),dimension(:),allocatable :: massvec,sqreig !(maxres2) maxres2=2*maxres
370 real(kind=8) :: relfeh,eps1,eps2
371 !el real(kind=8),dimension(:),allocatable :: Ghalf
372 !el real(kind=8),dimension(2*nres*(2*nres+1)/2) :: Ghalf !(mmaxres2) (mmaxres2=(maxres2*(maxres2+1)/2))
373 !el real(kind=8),dimension(2*nres,2*nres) :: Gcopy !(maxres2,maxres2)
374 !el real(kind=8),dimension(:,:),allocatable :: Gcopy
375 real(kind=8),dimension(:),allocatable :: work !(8*maxres6)
376 integer,dimension(:),allocatable :: iwork !(maxres6) maxres6=6*maxres
377 ! common /jakistam/ iwork,work,massvec,sqreig
378 !el common /przechowalnia/ Gcopy,Ghalf
379 real(kind=8) :: coeff,mscab
380 integer :: i,j,ind,ind1,k,l,ii,jj,m,m1,ii1,iti,nres2,ierr,nind,mark
382 integer :: iz,mnum,ichain,n,dimenp,innt,inct
383 if(.not.allocated(massvec)) then
384 allocate(massvec(2*nres),sqreig(2*nres))
385 allocate(work(8*6*nres))
386 allocate(iwork(6*nres))
388 print *,"just entered"
392 write (iout,*) "before FIVEDIAG"
394 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !mmaxres2=(maxres2*(maxres+1)/2)
397 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !mmaxres2=(maxres2*(maxres+1)/2)
398 write (iout,*) "ALLOCATE"
400 if(.not.allocated(Gcopy)) allocate(Gcopy(nres2,nres2)) !(maxres2,maxres2)
401 ! if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !mmaxres2=(maxres2*(maxres+1)/2)
402 if(.not.allocated(Bmat)) allocate(Bmat(nres2,nres2))
403 if(.not.allocated(matmult)) allocate(matmult(nres2,nres2))
406 ! Set up the matrix of the (dC,dX)-->(C,X) transformation (A), the
407 ! inertia matrix (Gmat) and the inverse of the inertia matrix (Ginv)
409 ! Determine the number of degrees of freedom (dimen) and the number of
411 ! dimen=(nct-nnt+1)+nside
412 ! dimen1=(nct-nnt)+(nct-nnt+1)
414 ! write (iout,*) "nnt",nnt," nct",nct," nside",nside
419 if (iabs(itype(nnt)).eq.10) then
424 DM(1)=DM(1)+isc(iabs(itype(nnt)))
425 DM(2)=msc(iabs(itype(nnt)))+isc(iabs(itype(nnt)))
431 ! if (iabs(itype(i,1)).eq.ntyp1) cycle
433 if (iabs(itype(i,1)).eq.10 .or. &
434 iabs(itype(i,mnum)).eq.ntyp1_molec(mnum) .or. mnum.ge.4) then
435 if (iabs(itype(i,1)).eq.10) DM(ind)=DM(ind)+msc(10)
438 DM(ind)=DM(ind)+isc(iabs(itype(i,1)))
439 DM(ind+1)=msc(iabs(itype(i,1)))+isc(iabs(itype(i,1)))
445 if (iabs(itype(nct)).eq.10) then
446 DM(ind)=DM(ind)+msc(10)
449 DM(ind)=DM(ind)+isc(iabs(itype(nct)))
450 DM(ind+1)=msc(iabs(itype(nct)))+isc(iabs(itype(nct)))
459 if (iabs(itype(i,1)).ne.10 .and.iabs(itype((i))).ne.ntyp1 &
461 DU1(ind)=-isc(iabs(itype(i,1)))
473 ! if (iabs(itype(i,1)).eq.ntyp1) cycle
474 write (iout,*) "i",i," itype",itype(i,1),ntyp1
475 if (iabs(itype(i,1)).ne.10 .and. &
476 iabs(itype(i,mnum)).ne.ntyp1_molec(mnum) .and. mnum.lt.4) then
491 dimen=dimen+chain_length(ichain)
492 dimen1=dimen1+2*chain_length(ichain)-1
493 dimenp=dimenp+chain_length(ichain)-1
495 write (iout,*) "Number of Calphas",dimen
496 write (iout,*) "Number of sidechains",nside
497 write (iout,*) "Number of peptide groups",dimenp
498 dimen=dimen+nside ! number of centers
499 dimen3=3*dimen ! degrees of freedom
500 write (iout,*) "Number of centers",dimen
501 write (iout,*) "Degrees of freedom:",dimen3
505 iposd_chain(ichain)=ind
506 innt=chain_border(1,ichain)
508 inct=chain_border(2,ichain)
509 if (mnum.eq.5) mp(mnum)=0.0
510 if (mnum.eq.5) ip(mnum)=0.0
511 ! if (mnum.eq.5) mp(mnum)=msc(itype(innt,mnum),mnum)
512 DM(ind)=mp(mnum)/4+ip(mnum)/4
513 if (iabs(itype(innt,1)).eq.10.or.molnum(innt).gt.2) then
514 DM(ind)=DM(ind)+msc(itype(innt,mnum),mnum)
518 DM(ind)=DM(ind)+isc(iabs(itype(innt,mnum)),mnum)
519 DM(ind+1)=msc(iabs(itype(innt,mnum)),mnum)+isc(iabs(itype(innt,mnum)),mnum)
523 write (iout,*) "ind",ind," nind",nind
526 ! if (iabs(itype(i)).eq.ntyp1) cycle
527 ! if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
528 ! if (mnum.eq.5) ip(mnum)=isc(itype(i,mnum),mnum)
529 if (mnum.eq.5) mp(mnum)=0.0
530 if (mnum.eq.5) ip(mnum)=0.0
531 ! if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
532 DM(ind)=2*ip(mnum)/4+mp(mnum)/2
533 if (iabs(itype(i,1)).eq.10.or.molnum(i).gt.2) then
534 ! if (iabs(itype(i,1)).eq.10.or.molnum(i).gt.2)&
535 ! DM(ind)=DM(ind)+msc(itype(i,molnum(i)),mnum)
536 DM(ind)=DM(ind)+msc(itype(i,mnum),mnum)
540 DM(ind)=DM(ind)+isc(iabs(itype(i,mnum)),mnum)
541 DM(ind+1)=msc(iabs(itype(i,mnum)),mnum)+isc(iabs(itype(i,mnum)),mnum)
545 write (iout,*) "i",i," ind",ind," nind",nind
547 if (inct.gt.innt) then
548 ! DM(ind)=ip4+mp(molnum(inct))/4
550 if (mnum.eq.5) mp(mnum)=0.0
551 ! if (mnum.eq.5) mp(mnum)=msc(itype(inct,molnum(inct)),molnum(inct))
553 DM(ind)=mp(mnum)/4+ip(mnum)/4
554 if (iabs(itype(inct,mnum)).eq.10.or.molnum(inct).gt.2) then
555 DM(ind)=DM(ind)+msc(itype(inct,molnum(inct)),molnum(inct))
560 DM(ind)=DM(ind)+isc(iabs(itype(inct,mnum)),mnum)
561 DM(ind+1)=msc(iabs(itype(inct,mnum)),mnum)+isc(iabs(itype(inct,mnum)),mnum)
566 write (iout,*) "ind",ind," nind",nind
567 dimen_chain(ichain)=nind
571 ind=iposd_chain(ichain)
572 innt=chain_border(1,ichain)
573 inct=chain_border(2,ichain)
576 if (iabs(itype(i,1)).ne.10 .and.iabs(itype(i,mnum)).ne.ntyp1_molec(mnum).and.mnum.le.2) then
577 DU1(ind)=-isc(iabs(itype(i,mnum)),mnum)
581 ! if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
582 ! if (mnum.eq.5) ip(mnum)=isc(itype(i,mnum),mnum)
583 if (mnum.eq.5) mp(mnum)=0.0
584 DU1(ind)=mp(mnum)/4-ip(mnum)/4
591 ind=iposd_chain(ichain)
592 innt=chain_border(1,ichain)
593 inct=chain_border(2,ichain)
596 ! if (iabs(itype(i)).eq.ntyp1) cycle
597 !c write (iout,*) "i",i," itype",itype(i),ntyp1
598 if (iabs(itype(i,1)).ne.10 .and. iabs(itype(i,mnum)).ne.ntyp1_molec(mnum).and.mnum.le.2) then
599 ! if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
600 if (mnum.eq.5) mp(mnum)=0.0
601 DU2(ind)=mp(mnum)/4-ip(mnum)/4
616 write (iout,*)"The upper part of the five-diagonal inertia matrix"
619 if (gmatout) write (iout,'(a,i5)') 'Chain',ichain
620 n=dimen_chain(ichain)
621 innt=iposd_chain(ichain)
622 inct=iposd_chain(ichain)+dimen_chain(ichain)-1
625 if (i.lt.inct-1) then
626 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i),DU2(i)
627 else if (i.eq.inct-1) then
628 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i)
630 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i)
634 call FDISYP (n, DM(innt:inct), DU1(innt:inct-1),&
635 DU2(innt:inct-1), MARK)
639 "ERROR: the inertia matrix is not positive definite for chain",&
642 call MPI_Finalize(ierr)
645 else if (mark.eq.0) then
647 "ERROR: the inertia matrix is singular for chain",ichain
649 call MPI_Finalize(ierr)
651 else if (mark.eq.1) then
653 write (iout,*) "The transformed five-diagonal inertia matrix"
654 write (iout,'(a,i5)') 'Chain',ichain
656 if (i.lt.inct-1) then
657 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i),DU2(i)
658 else if (i.eq.inct-1) then
659 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i),DU1(i)
661 write (iout,'(2i3,3f10.5)') i,i-innt+1,DM(i)
667 ! Diagonalization of the pentadiagonal matrix
676 dimen=(nct-nnt+1)+nside
677 dimen1=(nct-nnt)+(nct-nnt+1)
679 write (iout,*) "nnt",nnt," nct",nct," nside",nside
682 if (nfgtasks.gt.1) then
684 call MPI_Bcast(5,1,MPI_INTEGER,king,FG_COMM,IERROR)
685 time_Bcast=time_Bcast+MPI_Wtime()-time00
686 call int_bounds(dimen,igmult_start,igmult_end)
687 igmult_start=igmult_start-1
688 call MPI_Allgather(3*igmult_start,1,MPI_INTEGER,&
689 ng_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
690 my_ng_count=igmult_end-igmult_start
691 call MPI_Allgather(3*my_ng_count,1,MPI_INTEGER,ng_counts(0),1,&
692 MPI_INTEGER,FG_COMM,IERROR)
693 write (iout,*) 'Processor:',fg_rank,' CG group',kolor,&
694 ' absolute rank',myrank,' igmult_start',igmult_start,&
695 ' igmult_end',igmult_end,' count',my_ng_count
696 write (iout,*) "ng_start",(ng_start(i),i=0,nfgtasks-1)
697 write (iout,*) "ng_counts",(ng_counts(i),i=0,nfgtasks-1)
707 ! write (iout,*) "dimen",dimen," dimen1",dimen1," dimen3",dimen3
708 ! Zeroing out A and fricmat
714 ! Diagonal elements of the dC part of A and the respective friction coefficients
717 ! print *,"TUTUTUT?!",nnt,nct-1
722 coeff=0.25d0*IP(mnum)
723 print *,"TU",i,itype(i,mnum),mnum
724 if (mnum.ge.5) mp(mnum)=msc(itype(i,mnum),mnum)
725 print *,"TU2",i,coeff,mp(mnum)
726 massvec(ind1)=mp(mnum)
728 ! print *,"i",mp(mnum)
732 ! Off-diagonal elements of the dC part of A
739 ! Diagonal elements of the dX part of A and the respective friction coefficients
745 msc(ntyp1_molec(i),i)=1.0d0
747 msc(ntyp1_molec(4),4)=1.0d0
748 ! print *,"TU3",ntyp1_molec(4)-1
749 msc(ntyp1_molec(4)-1,4)=1.0d0
755 ! if (mnum.eq.5) then
758 mscab=msc(iabs(iti),mnum)
762 if (iti.ne.10 .and. iti.ne.ntyp1_molec(mnum) .and. mnum.lt.4) then
766 Gmat(ii1,ii1)=ISC(iabs(iti),mnum)
769 ! Off-diagonal elements of the dX part of A
784 write (iout,*) "Vector massvec"
786 write (iout,*) i,massvec(i)
788 write (iout,'(//a)') "A"
789 call matout(dimen,dimen1,nres2,nres2,A)
792 ! Calculate the G matrix (store in Gmat)
797 dtdi=dtdi+A(j,k)*A(j,i)*massvec(j)
799 Gmat(k,i)=Gmat(k,i)+dtdi
804 write (iout,'(//a)') "Gmat"
805 call matout(dimen,dimen,nres2,nres2,Gmat)
814 ! Invert the G matrix
815 call MATINVERT(dimen,nres2,Gcopy,Ginv,osob)
817 write (iout,'(//a)') "Ginv"
818 call matout(dimen,dimen,nres2,nres2,Ginv)
826 if ((itype(i,1).eq.10).or.(itype(i,mnum).eq.ntyp1_molec(mnum))&
827 .or.(mnum.ge.4)) then
835 Bmat(i-nnt+1+(nct-nnt)+1,j-1)=-1
836 Bmat(i-nnt+1+(nct-nnt)+1,j)=1
839 Bmat(i-nnt+1+(nct-nnt)+1,j-1)=-1
840 Bmat(i-nnt+1+(nct-nnt)+1,j)=1
844 write (iout,*) "j",j," dimen",dimen
846 write (iout,'(//a)') "Bmat"
847 call matout(dimen,dimen,nres2,nres2,Bmat)
850 write(iout,*) "before Gcopy",dimen,nres*2
854 ! write (iout,*) "myij",i,j
857 ! write(iout,*) "i,j,k,l",i,j,k,l
858 Gcopy(i,j)=Gcopy(i,j)+Bmat(k,i)*Gmat(k,l)*Bmat(l,j)
865 write (iout,'(//a)') "Gmat-transformed"
866 call matout(dimen,dimen,nres2,nres2,Gcopy)
869 if (nfgtasks.gt.1) then
870 myginv_ng_count=nres2*my_ng_count
871 call MPI_Allgather(nres2*igmult_start,1,MPI_INTEGER,&
872 nginv_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
873 call MPI_Allgather(myginv_ng_count,1,MPI_INTEGER,&
874 nginv_counts(0),1,MPI_INTEGER,FG_COMM,IERROR)
875 write (iout,*) "nginv_start",(nginv_start(i),i=0,nfgtasks-1)
876 write (iout,*) "nginv_counts",(nginv_counts(i),i=0,nfgtasks-1)
878 ! call MPI_Scatterv(ginv(1,1),nginv_counts(0),
879 ! & nginv_start(0),MPI_DOUBLE_PRECISION,ginv,
880 ! & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
881 ! call MPI_Barrier(FG_COMM,IERR)
883 call MPI_Scatterv(ginv(1,1),nginv_counts(0),&
884 nginv_start(0),MPI_DOUBLE_PRECISION,gcopy(1,1),&
885 myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
887 time_scatter_ginv=time_scatter_ginv+MPI_Wtime()-time00
894 ! write (iout,*) "Master's chunk of ginv"
895 ! call MATOUT2(my_ng_count,dimen,maxres2,maxres2,ginv)
899 write (iout,*) "The G matrix is singular."
900 write (iout,'(//a)') "Gmat-transformed"
901 call matout(dimen,dimen,nres2,nres2,Gcopy)
904 ! Compute G**(-1/2) and G**(1/2)
912 call gldiag(nres2,dimen,dimen,Ghalf,work,Geigen,Gvec,&
915 write (iout,'(//a)') &
916 "Eigenvectors and eigenvalues of the G matrix"
917 call eigout(dimen,dimen,nres2,nres2,Gvec,Geigen)
920 sqreig(i)=dsqrt(Geigen(i))
928 Gsqrp(i,j)=Gsqrp(i,j)+Gvec(i,k)*Gvec(j,k)*sqreig(k)
929 Gsqrm(i,j)=Gsqrm(i,j)+Gvec(i,k)*Gvec(j,k)/sqreig(k)
930 Gcopy(i,j)=Gcopy(i,j)+Gvec(i,k)*Gvec(j,k)*Geigen(k)
935 write (iout,*) "Comparison of original and restored G"
938 write (iout,'(2i5,5f10.5)') i,j,Gmat(i,j),Gcopy(i,j),&
939 Gmat(i,j)-Gcopy(i,j),Gsqrp(i,j),Gsqrm(i,j)
943 if (allocated(Gcopy)) deallocate(Gcopy)
945 !write(iout,*) "end setup_MD_matr"
947 end subroutine setup_MD_matrices
948 !-----------------------------------------------------------------------------
949 subroutine EIGOUT(NC,NR,LM2,LM3,A,B)
951 ! implicit real*8 (a-h,o-z)
952 ! include 'DIMENSIONS'
953 ! include 'COMMON.IOUNITS'
954 integer :: LM2,LM3,NC,NR,KA,KC,KB,I,J,N
955 real(kind=8) :: A(LM2,LM3),B(LM2)
959 WRITE(IOUT,600) (I,I=KA,KB)
960 WRITE(IOUT,601) (B(I),I=KA,KB)
964 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
970 4 IF (KB.EQ.NC) RETURN
974 600 FORMAT (// 9H ROOT NO.,I4,9I11)
975 601 FORMAT (/5X,10(1PE11.4))
977 603 FORMAT (I5,10F11.5)
979 end subroutine EIGOUT
980 !-----------------------------------------------------------------------------
981 subroutine MATOUT(NC,NR,LM2,LM3,A)
983 ! implicit real*8 (a-h,o-z)
984 ! include 'DIMENSIONS'
985 ! include 'COMMON.IOUNITS'
986 integer :: LM2,LM3,NC,NR,KA,KC,KB,I,J,N
987 real(kind=8) :: A(LM2,LM3)
991 WRITE(IOUT,600) (I,I=KA,KB)
995 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
1001 4 IF (KB.EQ.NC) RETURN
1005 600 FORMAT (//5x,9I11)
1007 603 FORMAT (I5,10F11.3)
1009 end subroutine MATOUT
1010 !-----------------------------------------------------------------------------
1011 subroutine MATOUT1(NC,NR,LM2,LM3,A)
1013 ! implicit real*8 (a-h,o-z)
1014 ! include 'DIMENSIONS'
1015 ! include 'COMMON.IOUNITS'
1016 integer :: LM2,LM3,NC,NR,KA,KC,KB,I,J,N
1017 real(kind=8) :: A(LM2,LM3)
1021 WRITE(IOUT,600) (I,I=KA,KB)
1025 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
1031 4 IF (KB.EQ.NC) RETURN
1035 600 FORMAT (//5x,7(3I5,2x))
1037 603 FORMAT (I5,7(3F5.1,2x))
1039 end subroutine MATOUT1
1040 !-----------------------------------------------------------------------------
1041 subroutine MATOUT2(NC,NR,LM2,LM3,A)
1043 ! implicit real*8 (a-h,o-z)
1044 ! include 'DIMENSIONS'
1045 ! include 'COMMON.IOUNITS'
1046 integer :: I,J,KA,KC,KB,N
1047 integer :: LM2,LM3,NC,NR
1048 real(kind=8) :: A(LM2,LM3)
1052 WRITE(IOUT,600) (I,I=KA,KB)
1056 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
1062 4 IF (KB.EQ.NC) RETURN
1066 600 FORMAT (//5x,4(3I9,2x))
1068 603 FORMAT (I5,4(3F9.3,2x))
1070 end subroutine MATOUT2
1072 subroutine fivediagmult(n,DM,DU1,DU2,x,y)
1074 double precision DM(n),DU1(n),DU2(n),x(n),y(n)
1076 y(1)=DM(1)*x(1)+DU1(1)*x(2)+DU2(1)*x(3)
1077 y(2)=DU1(1)*x(1)+DM(2)*x(2)+DU1(2)*x(3)+DU2(2)*x(4)
1079 y(i)=DU2(i-2)*x(i-2)+DU1(i-1)*x(i-1)+DM(i)*x(i) &
1080 +DU1(i)*x(i+1)+DU2(i)*x(i+2)
1082 y(n-1)=DU2(n-3)*x(n-3)+DU1(n-2)*x(n-2)+DM(n-1)*x(n-1) &
1084 y(n)=DU2(n-2)*x(n-2)+DU1(n-1)*x(n-1)+DM(n)*x(n)
1087 !c---------------------------------------------------------------------------
1088 subroutine fivediaginv_mult(ndim,forces,d_a_vec)
1089 use energy_data, only:nchain,chain_border,nct,nnt,molnum,&
1091 use geometry_data, only: nside
1094 real(kind=8),dimension(:),allocatable ::forces,d_a_vec
1095 real(kind=8),dimension(:),allocatable :: xsolv,rs
1096 real(kind=8),dimension(:,:),allocatable :: accel
1097 integer i,j,ind,ichain,n,iposc,innt,inct,inct_prev,mnum
1100 if (.not.allocated(forces)) allocate(forces(6*nres))
1101 if (.not.allocated(d_a_vec)) allocate(d_a_vec(6*nres))
1102 if (.not.allocated(xsolv)) allocate(xsolv(3*ndim))
1103 if (.not.allocated(rs)) allocate(rs(3*ndim))
1104 if (.not.allocated(accel)) allocate(accel(3,0:2*nres))
1108 write(iout,*) "received forces",i,forces(i)
1112 !Compute accelerations in Calpha and SC
1114 n=dimen_chain(ichain)
1115 iposc=iposd_chain(ichain)
1116 innt=chain_border(1,ichain)
1117 inct=chain_border(2,ichain)
1118 do i=iposc,iposc+n-1
1119 ! write(iout,*) "index",3*(i-1)+j,forces(3*(i-1)+j)
1120 rs(i-iposc+1)=forces(3*(i-1)+j)
1123 write (iout,*) "j",j," chain",ichain,"n",n
1124 write (iout,*) "innt",innt,inct,iposc
1127 write (iout,'(i5,f10.5)') i,rs(i)
1130 call FDISYS (n,DM(iposc),DU1(iposc),DU2(iposc),rs,xsolv)
1132 write (iout,*) "xsolv"
1133 write (iout,'(f10.5)') (xsolv(i),i=1,n)
1138 if (itype(i,1).eq.10.or.mnum.gt.2)then
1139 accel(j,i)=xsolv(ind)
1142 accel(j,i)=xsolv(ind)
1143 accel(j,i+nres)=xsolv(ind+1)
1149 !C Convert d_a to virtual-bon-vector basis
1151 write (iout,*) "accel in CA-SC basis"
1153 write (iout,'(i5,3f10.5,5x,3f10.5)') i,(accel(j,i),j=1,3),&
1154 (accel(j,i+nres),j=1,3)
1156 write (iout,*) "nnt",nnt
1159 accel(:,0)=accel(:,1)
1163 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
1166 accel(j,i)=accel(j,i+1)-accel(j,i)
1170 accel(j,i+nres)=accel(j,i+nres)-accel(j,i)
1171 accel(j,i)=accel(j,i+1)-accel(j,i)
1177 accel(:,2*nres)=0.0d0
1179 accel(:,0)=accel(:,1)
1183 if (molnum(chain_border1(1,ichain)+1).eq.5) cycle
1184 accel(:,chain_border1(1,ichain)-1)= &
1185 accel(:,chain_border1(1,ichain))
1186 accel(:,chain_border1(1,ichain))=0.0d0
1189 if (molnum(chain_border1(1,ichain)+1).eq.5) cycle
1190 accel(:,chain_border1(1,ichain)-1)= &
1191 accel(:,chain_border1(1,ichain)-1) &
1192 +accel(:,chain_border(2,ichain-1))
1193 accel(:,chain_border(2,ichain-1))=0.0d0
1196 write (iout,*) "accel in fivediaginv_mult: 1"
1198 write(iout,'(i5,3f10.5)') i,(accel(j,i),j=1,3)
1202 d_a_vec(j)=accel(j,0)
1207 d_a_vec(ind+j)=accel(j,i)
1213 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1214 .and.mnum.le.2) then
1216 d_a_vec(ind+j)=accel(j,i+nres)
1222 write (iout,*) "d_a_vec"
1223 write (iout,'(3f10.5)') (d_a_vec(j),j=1,3*(nct-nnt+nside))
1230 !-----------------------------------------------------------------------------
1231 subroutine ginv_mult(z,d_a_tmp)
1233 use geometry_data, only: nres
1236 ! implicit real*8 (a-h,o-z)
1237 ! include 'DIMENSIONS'
1240 integer :: ierr,ierror
1242 ! include 'COMMON.SETUP'
1243 ! include 'COMMON.TIME1'
1244 ! include 'COMMON.MD'
1245 real(kind=8),dimension(dimen3) :: z,z1,d_a_tmp
1246 real(kind=8),dimension(6*nres) :: temp !(maxres6) maxres6=6*maxres
1247 real(kind=8) :: time00,time01
1248 integer :: i,j,k,ind
1250 if (nfgtasks.gt.1) then
1251 if (fg_rank.eq.0) then
1252 ! The matching BROADCAST for fg processors is called in ERGASTULUM
1254 call MPI_Bcast(4,1,MPI_INTEGER,king,FG_COMM,IERROR)
1255 time_Bcast=time_Bcast+MPI_Wtime()-time00
1256 ! print *,"Processor",myrank," BROADCAST iorder in GINV_MULT"
1258 ! write (2,*) "time00",time00
1259 ! write (2,*) "Before Scatterv"
1261 ! write (2,*) "Whole z (for FG master)"
1263 ! write (2,*) i,z(i)
1265 ! call MPI_Barrier(FG_COMM,IERROR)
1267 !elwrite(iout,*) "do tej pory jest OK, MPI_Scatterv w ginv_mult"
1268 call MPI_Scatterv(z,ng_counts(0),ng_start(0),&
1269 MPI_DOUBLE_PRECISION,&
1270 z1,3*my_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
1271 ! write (2,*) "My chunk of z"
1272 ! do i=1,3*my_ng_count
1273 ! write (2,*) i,z(i)
1275 ! write (2,*) "After SCATTERV"
1277 ! write (2,*) "MPI_Wtime",MPI_Wtime()
1278 time_scatter=time_scatter+MPI_Wtime()-time00
1280 time_scatter_ginvmult=time_scatter_ginvmult+MPI_Wtime()-time00
1282 ! write (2,*) "time_scatter",time_scatter
1283 ! write (2,*) "dimen",dimen," dimen3",dimen3," my_ng_count",
1292 ! write (2,*) "k,i,j,ind",k,i,j,ind,(j-1)*3+k+1,
1293 ! & Ginv(i,j),z((j-1)*3+k+1),
1294 ! & Ginv(i,j)*z((j-1)*3+k+1)
1295 ! temp(ind)=temp(ind)+Ginv(i,j)*z((j-1)*3+k+1)
1296 temp(ind)=temp(ind)+Ginv(j,i)*z1((j-1)*3+k+1)
1300 time_ginvmult=time_ginvmult+MPI_Wtime()-time01
1301 ! write (2,*) "Before REDUCE"
1303 ! write (2,*) "z before reduce"
1305 ! write (2,*) i,temp(i)
1308 call MPI_Reduce(temp(1),d_a_tmp(1),dimen3,MPI_DOUBLE_PRECISION,&
1309 MPI_SUM,king,FG_COMM,IERR)
1310 time_reduce=time_reduce+MPI_Wtime()-time00
1311 ! write (2,*) "After REDUCE"
1323 ! write (2,*) "k,i,j,ind",k,i,j,ind,(j-1)*3+k+1
1325 ! & Ginv(i,j),z((j-1)*3+k+1),
1326 ! & Ginv(i,j)*z((j-1)*3+k+1)
1327 d_a_tmp(ind)=d_a_tmp(ind) &
1328 +Ginv(j,i)*z((j-1)*3+k+1)
1329 ! d_a_tmp(ind)=d_a_tmp(ind)
1330 ! & +Ginv(i,j)*z((j-1)*3+k+1)
1335 time_ginvmult=time_ginvmult+MPI_Wtime()-time01
1341 end subroutine ginv_mult
1342 !-----------------------------------------------------------------------------
1344 subroutine ginv_mult_test(z,d_a_tmp)
1346 ! include 'DIMENSIONS'
1347 !el integer :: dimen
1348 ! include 'COMMON.MD'
1349 real(kind=8),dimension(dimen) :: z,d_a_tmp
1350 real(kind=8),dimension(dimen/3) :: ztmp,dtmp
1351 integer :: i,j,k,ind
1355 ! d_a_tmp(i)=d_a_tmp(i)+Ginv(i,j)*z(j)
1364 ztmp(j)=z((j-1)*3+k+1)
1367 call alignx(16,ztmp(1))
1368 call alignx(16,dtmp(1))
1369 call alignx(16,Ginv(1,1))
1374 dtmp(i)=dtmp(i)+Ginv(i,j)*ztmp(j)
1379 d_a_tmp(ind)=dtmp(i)
1383 end subroutine ginv_mult_test
1385 !-----------------------------------------------------------------------------
1386 subroutine fricmat_mult(z,d_a_tmp)
1388 use geometry_data, only: nres
1391 ! include 'DIMENSIONS'
1394 integer :: IERROR,ierr
1396 ! include 'COMMON.MD'
1397 ! include 'COMMON.IOUNITS'
1398 ! include 'COMMON.SETUP'
1399 ! include 'COMMON.TIME1'
1401 ! include 'COMMON.LANGEVIN'
1403 ! include 'COMMON.LANGEVIN.lang0'
1405 real(kind=8),dimension(dimen3) :: z,z1,d_a_tmp
1406 real(kind=8),dimension(6*nres) :: temp !(maxres6) maxres6=6*maxres
1407 real(kind=8) :: time00,time01
1408 integer :: i,j,k,ind,nres2
1410 !el if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
1413 if (nfgtasks.gt.1) then
1414 if (fg_rank.eq.0) then
1415 ! The matching BROADCAST for fg processors is called in ERGASTULUM
1417 call MPI_Bcast(9,1,MPI_INTEGER,king,FG_COMM,IERROR)
1418 time_Bcast=time_Bcast+MPI_Wtime()-time00
1419 ! print *,"Processor",myrank," BROADCAST iorder in FRICMAT_MULT"
1421 ! call MPI_Barrier(FG_COMM,IERROR)
1423 call MPI_Scatterv(z,ng_counts(0),ng_start(0),&
1424 MPI_DOUBLE_PRECISION,&
1425 z1,3*my_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
1426 ! write (2,*) "My chunk of z"
1427 ! do i=1,3*my_ng_count
1428 ! write (2,*) i,z(i)
1430 time_scatter=time_scatter+MPI_Wtime()-time00
1432 time_scatter_fmatmult=time_scatter_fmatmult+MPI_Wtime()-time00
1440 temp(ind)=temp(ind)-fricmat(j,i)*z1((j-1)*3+k+1)
1444 time_fricmatmult=time_fricmatmult+MPI_Wtime()-time01
1445 ! write (2,*) "Before REDUCE"
1446 ! write (2,*) "d_a_tmp before reduce"
1448 ! write (2,*) i,temp(i)
1452 call MPI_Reduce(temp(1),d_a_tmp(1),dimen3,MPI_DOUBLE_PRECISION,&
1453 MPI_SUM,king,FG_COMM,IERR)
1454 time_reduce=time_reduce+MPI_Wtime()-time00
1455 ! write (2,*) "After REDUCE"
1467 d_a_tmp(ind)=d_a_tmp(ind) &
1468 -fricmat(j,i)*z((j-1)*3+k+1)
1473 time_fricmatmult=time_fricmatmult+MPI_Wtime()-time01
1478 ! write (iout,*) "Vector d_a"
1480 ! write (2,*) i,d_a_tmp(i)
1483 end subroutine fricmat_mult
1484 !-----------------------------------------------------------------------------
1486 !-----------------------------------------------------------------------------