2 c-------------------------------------------------------------------------
3 c This subroutine contains the total lagrangain from which the accelerations
4 c are obtained. For numerical gradient checking, the derivetive of the
5 c lagrangian in the velocities and coordinates are calculated seperately
6 c-------------------------------------------------------------------------
7 implicit real*8 (a-h,o-z)
13 include 'COMMON.CHAIN'
14 include 'COMMON.DERIV'
16 include 'COMMON.LOCAL'
17 include 'COMMON.INTERACT'
19 include 'COMMON.LAGRANGE'
20 include 'COMMON.IOUNITS'
21 include 'COMMON.CONTROL'
23 include 'COMMON.TIME1'
26 double precision zapas(MAXRES6),muca_factor
27 logical lprn /.false./
28 common /cipiszcze/ itime
38 write (iout,*) "Potential forces backbone"
41 if (lprn) write (iout,'(i5,3e15.5,5x,3e15.5)')
42 & i,(-gcart(j,i),j=1,3)
45 zapas(ind)=-gcart(j,i)
48 if (lprn) write (iout,*) "Potential forces sidechain"
50 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
51 if (lprn) write (iout,'(i5,3e15.5,5x,3e15.5)')
52 & i,(-gcart(j,i),j=1,3)
55 zapas(ind)=-gxcart(j,i)
60 call ginv_mult(zapas,d_a_work)
69 d_a(j,i)=d_a_work(ind)
73 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
76 d_a(j,i+nres)=d_a_work(ind)
83 if(mucadyn.gt.0) call muca_update(potE)
84 factor=muca_factor(potE)*t_bath*Rb
86 cd print *,'lmuca ',factor,potE
88 d_a(j,0)=d_a(j,0)*factor
92 d_a(j,i)=d_a(j,i)*factor
97 d_a(j,i+nres)=d_a(j,i+nres)*factor
104 write(iout,*) 'acceleration 3D'
105 write (iout,'(i3,3f10.5,3x,3f10.5)') 0,(d_a(j,0),j=1,3)
107 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3)
110 write (iout,'(i3,3f10.5,3x,3f10.5)')
111 & i+nres,(d_a(j,i+nres),j=1,3)
115 time_lagrangian=time_lagrangian+MPI_Wtime()-time00
119 c------------------------------------------------------------------
120 subroutine setup_MD_matrices
121 implicit real*8 (a-h,o-z)
127 include 'COMMON.SETUP'
129 include 'COMMON.CHAIN'
130 include 'COMMON.DERIV'
132 include 'COMMON.LOCAL'
133 include 'COMMON.INTERACT'
135 include 'COMMON.LAGRANGE'
137 include 'COMMON.LANGEVIN'
139 include 'COMMON.LANGEVIN.lang0'
141 include 'COMMON.IOUNITS'
142 include 'COMMON.TIME1'
144 logical lprn /.false./
146 double precision dtdi,massvec(maxres2),Gcopy(maxres2,maxres2),
147 & Ghalf(mmaxres2),sqreig(maxres2)
148 double precision work(8*maxres6)
149 integer iwork(maxres6)
150 common /przechowalnia/ Gcopy,Ghalf
152 c Set up the matrix of the (dC,dX)-->(C,X) transformation (A), the
153 c inertia matrix (Gmat) and the inverse of the inertia matrix (Ginv)
155 c Determine the number of degrees of freedom (dimen) and the number of
157 dimen=(nct-nnt+1)+nside
158 dimen1=(nct-nnt)+(nct-nnt+1)
161 if (nfgtasks.gt.1) then
163 call MPI_Bcast(5,1,MPI_INTEGER,king,FG_COMM,IERROR)
164 time_Bcast=time_Bcast+MPI_Wtime()-time00
165 call int_bounds(dimen,igmult_start,igmult_end)
166 igmult_start=igmult_start-1
167 call MPI_Allgather(3*igmult_start,1,MPI_INTEGER,
168 & ng_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
169 my_ng_count=igmult_end-igmult_start
170 call MPI_Allgather(3*my_ng_count,1,MPI_INTEGER,ng_counts(0),1,
171 & MPI_INTEGER,FG_COMM,IERROR)
172 write (iout,*) 'Processor:',fg_rank,' CG group',kolor,
173 & ' absolute rank',myrank,' igmult_start',igmult_start,
174 & ' igmult_end',igmult_end,' count',my_ng_count
175 write (iout,*) "ng_start",(ng_start(i),i=0,nfgtasks-1)
176 write (iout,*) "ng_counts",(ng_counts(i),i=0,nfgtasks-1)
186 c write (iout,*) "dimen",dimen," dimen1",dimen1," dimen3",dimen3
187 c Zeroing out A and fricmat
193 c Diagonal elements of the dC part of A and the respective friction coefficients
205 c Off-diagonal elements of the dC part of A
212 c Diagonal elements of the dX part of A and the respective friction coefficients
222 massvec(ii)=msc(iabs(iti))
223 if (iti.ne.10 .and. iti.ne.ntyp1) then
227 Gmat(ii1,ii1)=ISC(iabs(iti))
230 c Off-diagonal elements of the dX part of A
244 write (iout,*) "Vector massvec"
246 write (iout,*) i,massvec(i)
248 write (iout,'(//a)') "A"
249 call matout(dimen,dimen1,maxres2,maxres2,A)
252 c Calculate the G matrix (store in Gmat)
257 dtdi=dtdi+A(j,k)*A(j,i)*massvec(j)
259 Gmat(k,i)=Gmat(k,i)+dtdi
264 write (iout,'(//a)') "Gmat"
265 call matout(dimen,dimen,maxres2,maxres2,Gmat)
274 c Invert the G matrix
275 call MATINVERT(dimen,maxres2,Gcopy,Ginv,osob)
277 write (iout,'(//a)') "Ginv"
278 call matout(dimen,dimen,maxres2,maxres2,Ginv)
281 if (nfgtasks.gt.1) then
282 myginv_ng_count=maxres2*my_ng_count
283 call MPI_Allgather(maxres2*igmult_start,1,MPI_INTEGER,
284 & nginv_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
285 call MPI_Allgather(myginv_ng_count,1,MPI_INTEGER,
286 & nginv_counts(0),1,MPI_INTEGER,FG_COMM,IERROR)
287 write (iout,*) "nginv_start",(nginv_start(i),i=0,nfgtasks-1)
288 write (iout,*) "nginv_counts",(nginv_counts(i),i=0,nfgtasks-1)
290 c call MPI_Scatterv(ginv(1,1),nginv_counts(0),
291 c & nginv_start(0),MPI_DOUBLE_PRECISION,ginv,
292 c & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
293 c call MPI_Barrier(FG_COMM,IERR)
295 call MPI_Scatterv(ginv(1,1),nginv_counts(0),
296 & nginv_start(0),MPI_DOUBLE_PRECISION,gcopy(1,1),
297 & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
299 time_scatter_ginv=time_scatter_ginv+MPI_Wtime()-time00
306 c write (iout,*) "Master's chunk of ginv"
307 c call MATOUT2(my_ng_count,dimen,maxres2,maxres2,ginv)
311 write (iout,*) "The G matrix is singular."
314 c Compute G**(-1/2) and G**(1/2)
322 call gldiag(maxres2,dimen,dimen,Ghalf,work,Geigen,Gvec,
326 & "Eigenvectors and eigenvalues of the G matrix"
327 call eigout(dimen,dimen,maxres2,maxres2,Gvec,Geigen)
330 sqreig(i)=dsqrt(Geigen(i))
338 Gsqrp(i,j)=Gsqrp(i,j)+Gvec(i,k)*Gvec(j,k)*sqreig(k)
339 Gsqrm(i,j)=Gsqrm(i,j)+Gvec(i,k)*Gvec(j,k)/sqreig(k)
340 Gcopy(i,j)=Gcopy(i,j)+Gvec(i,k)*Gvec(j,k)*Geigen(k)
345 write (iout,*) "Comparison of original and restored G"
348 write (iout,'(2i5,5f10.5)') i,j,Gmat(i,j),Gcopy(i,j),
349 & Gmat(i,j)-Gcopy(i,j),Gsqrp(i,j),Gsqrm(i,j)
355 c-------------------------------------------------------------------------------
356 SUBROUTINE EIGOUT(NC,NR,LM2,LM3,A,B)
357 implicit real*8 (a-h,o-z)
359 include 'COMMON.IOUNITS'
360 double precision A(LM2,LM3),B(LM2)
364 WRITE(IOUT,600) (I,I=KA,KB)
365 WRITE(IOUT,601) (B(I),I=KA,KB)
369 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
375 4 IF (KB.EQ.NC) RETURN
379 600 FORMAT (// 9H ROOT NO.,I4,9I11)
380 601 FORMAT (/5X,10(1PE11.4))
382 603 FORMAT (I5,10F11.5)
385 c-------------------------------------------------------------------------------
386 SUBROUTINE MATOUT(NC,NR,LM2,LM3,A)
387 implicit real*8 (a-h,o-z)
389 include 'COMMON.IOUNITS'
390 double precision A(LM2,LM3)
394 WRITE(IOUT,600) (I,I=KA,KB)
398 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
404 4 IF (KB.EQ.NC) RETURN
408 600 FORMAT (//5x,9I11)
410 603 FORMAT (I5,10F11.3)
413 c-------------------------------------------------------------------------------
414 SUBROUTINE MATOUT1(NC,NR,LM2,LM3,A)
415 implicit real*8 (a-h,o-z)
417 include 'COMMON.IOUNITS'
418 double precision A(LM2,LM3)
422 WRITE(IOUT,600) (I,I=KA,KB)
426 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
432 4 IF (KB.EQ.NC) RETURN
436 600 FORMAT (//5x,7(3I5,2x))
438 603 FORMAT (I5,7(3F5.1,2x))
441 c-------------------------------------------------------------------------------
442 SUBROUTINE MATOUT2(NC,NR,LM2,LM3,A)
443 implicit real*8 (a-h,o-z)
445 include 'COMMON.IOUNITS'
446 double precision A(LM2,LM3)
450 WRITE(IOUT,600) (I,I=KA,KB)
454 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
460 4 IF (KB.EQ.NC) RETURN
464 600 FORMAT (//5x,4(3I9,2x))
466 603 FORMAT (I5,4(3F9.3,2x))
469 c---------------------------------------------------------------------------
470 SUBROUTINE ginv_mult(z,d_a_tmp)
471 implicit real*8 (a-h,o-z)
477 include 'COMMON.SETUP'
478 include 'COMMON.TIME1'
480 include 'COMMON.LAGRANGE'
481 double precision z(dimen3),d_a_tmp(dimen3),temp(maxres6),time00
482 &,time01,zcopy(dimen3)
484 if (nfgtasks.gt.1) then
485 if (fg_rank.eq.0) then
486 c The matching BROADCAST for fg processors is called in ERGASTULUM
488 call MPI_Bcast(4,1,MPI_INTEGER,king,FG_COMM,IERROR)
489 time_Bcast=time_Bcast+MPI_Wtime()-time00
490 c print *,"Processor",myrank," BROADCAST iorder in GINV_MULT"
492 c write (2,*) "time00",time00
493 c write (2,*) "Before Scatterv"
495 c write (2,*) "Whole z (for FG master)"
499 c call MPI_Barrier(FG_COMM,IERROR)
501 call MPI_Scatterv(z,ng_counts(0),ng_start(0),
502 & MPI_DOUBLE_PRECISION,
503 & zcopy,3*my_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
504 c write (2,*) "My chunk of z"
509 c write (2,*) "After SCATTERV"
511 c write (2,*) "MPI_Wtime",MPI_Wtime()
512 time_scatter=time_scatter+MPI_Wtime()-time00
514 time_scatter_ginvmult=time_scatter_ginvmult+MPI_Wtime()-time00
516 c write (2,*) "time_scatter",time_scatter
517 c write (2,*) "dimen",dimen," dimen3",dimen3," my_ng_count",
526 c write (2,*) "k,i,j,ind",k,i,j,ind,(j-1)*3+k+1,
527 c & Ginv(i,j),z((j-1)*3+k+1),
528 c & Ginv(i,j)*z((j-1)*3+k+1)
529 c temp(ind)=temp(ind)+Ginv(i,j)*z((j-1)*3+k+1)
530 temp(ind)=temp(ind)+Ginv(j,i)*z((j-1)*3+k+1)
534 time_ginvmult=time_ginvmult+MPI_Wtime()-time01
535 c write (2,*) "Before REDUCE"
537 c write (2,*) "z before reduce"
539 c write (2,*) i,temp(i)
542 call MPI_Reduce(temp(1),d_a_tmp(1),dimen3,MPI_DOUBLE_PRECISION,
543 & MPI_SUM,king,FG_COMM,IERR)
544 time_reduce=time_reduce+MPI_Wtime()-time00
545 c write (2,*) "After REDUCE"
557 c write (2,*) "k,i,j,ind",k,i,j,ind,(j-1)*3+k+1
559 c & Ginv(i,j),z((j-1)*3+k+1),
560 c & Ginv(i,j)*z((j-1)*3+k+1)
561 d_a_tmp(ind)=d_a_tmp(ind)
562 & +Ginv(j,i)*z((j-1)*3+k+1)
563 c d_a_tmp(ind)=d_a_tmp(ind)
564 c & +Ginv(i,j)*z((j-1)*3+k+1)
569 time_ginvmult=time_ginvmult+MPI_Wtime()-time01
576 c---------------------------------------------------------------------------
578 SUBROUTINE ginv_mult_test(z,d_a_tmp)
581 double precision z(dimen),d_a_tmp(dimen)
582 double precision ztmp(dimen/3),dtmp(dimen/3)
587 c d_a_tmp(i)=d_a_tmp(i)+Ginv(i,j)*z(j)
596 ztmp(j)=z((j-1)*3+k+1)
599 call alignx(16,ztmp(1))
600 call alignx(16,dtmp(1))
601 call alignx(16,Ginv(1,1))
606 dtmp(i)=dtmp(i)+Ginv(i,j)*ztmp(j)
617 c---------------------------------------------------------------------------
618 SUBROUTINE fricmat_mult(z,d_a_tmp)
624 include 'COMMON.LAGRANGE'
626 include 'COMMON.IOUNITS'
627 include 'COMMON.SETUP'
628 include 'COMMON.TIME1'
630 include 'COMMON.LANGEVIN'
632 include 'COMMON.LANGEVIN.lang0'
634 double precision z(dimen3),d_a_tmp(dimen3),temp(maxres6),time00
635 &,time01,zcopy(dimen3)
637 if (nfgtasks.gt.1) then
638 if (fg_rank.eq.0) then
639 c The matching BROADCAST for fg processors is called in ERGASTULUM
641 call MPI_Bcast(9,1,MPI_INTEGER,king,FG_COMM,IERROR)
642 time_Bcast=time_Bcast+MPI_Wtime()-time00
643 c print *,"Processor",myrank," BROADCAST iorder in FRICMAT_MULT"
645 c call MPI_Barrier(FG_COMM,IERROR)
647 call MPI_Scatterv(z,ng_counts(0),ng_start(0),
648 & MPI_DOUBLE_PRECISION,
649 & zcopy,3*my_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
650 c write (2,*) "My chunk of z"
655 time_scatter=time_scatter+MPI_Wtime()-time00
657 time_scatter_fmatmult=time_scatter_fmatmult+MPI_Wtime()-time00
665 temp(ind)=temp(ind)-fricmat(j,i)*z((j-1)*3+k+1)
669 time_fricmatmult=time_fricmatmult+MPI_Wtime()-time01
670 c write (2,*) "Before REDUCE"
671 c write (2,*) "d_a_tmp before reduce"
673 c write (2,*) i,temp(i)
677 call MPI_Reduce(temp(1),d_a_tmp(1),dimen3,MPI_DOUBLE_PRECISION,
678 & MPI_SUM,king,FG_COMM,IERR)
679 time_reduce=time_reduce+MPI_Wtime()-time00
680 c write (2,*) "After REDUCE"
692 d_a_tmp(ind)=d_a_tmp(ind)
693 & -fricmat(j,i)*z((j-1)*3+k+1)
698 time_fricmatmult=time_fricmatmult+MPI_Wtime()-time01
703 c write (iout,*) "Vector d_a"
705 c write (2,*) i,d_a_tmp(i)