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.IOUNITS'
20 include 'COMMON.CONTROL'
22 include 'COMMON.TIME1'
25 double precision zapas(MAXRES6),muca_factor
26 logical lprn /.false./
27 common /cipiszcze/ itime
37 write (iout,*) "Potential forces backbone"
40 if (lprn) write (iout,'(i5,3e15.5,5x,3e15.5)')
41 & i,(-gcart(j,i),j=1,3)
44 zapas(ind)=-gcart(j,i)
47 if (lprn) write (iout,*) "Potential forces sidechain"
49 if (itype(i).ne.10 .and. itype(i).ne.21) then
50 if (lprn) write (iout,'(i5,3e15.5,5x,3e15.5)')
51 & i,(-gcart(j,i),j=1,3)
54 zapas(ind)=-gxcart(j,i)
59 call ginv_mult(zapas,d_a_work)
68 d_a(j,i)=d_a_work(ind)
72 if (itype(i).ne.10 .and. itype(i).ne.21) then
75 d_a(j,i+nres)=d_a_work(ind)
82 if(mucadyn.gt.0) call muca_update(potE)
83 factor=muca_factor(potE)*t_bath*Rb
85 cd print *,'lmuca ',factor,potE
87 d_a(j,0)=d_a(j,0)*factor
91 d_a(j,i)=d_a(j,i)*factor
96 d_a(j,i+nres)=d_a(j,i+nres)*factor
103 write(iout,*) 'acceleration 3D'
104 write (iout,'(i3,3f10.5,3x,3f10.5)') 0,(d_a(j,0),j=1,3)
106 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3)
109 write (iout,'(i3,3f10.5,3x,3f10.5)')
110 & i+nres,(d_a(j,i+nres),j=1,3)
114 time_lagrangian=time_lagrangian+MPI_Wtime()-time00
118 c------------------------------------------------------------------
119 subroutine setup_MD_matrices
120 implicit real*8 (a-h,o-z)
126 include 'COMMON.SETUP'
128 include 'COMMON.CHAIN'
129 include 'COMMON.DERIV'
131 include 'COMMON.LOCAL'
132 include 'COMMON.INTERACT'
135 include 'COMMON.LANGEVIN'
137 include 'COMMON.LANGEVIN.lang0'
139 include 'COMMON.IOUNITS'
140 include 'COMMON.TIME1'
142 logical lprn /.false./
144 double precision dtdi,massvec(maxres2),Gcopy(maxres2,maxres2),
145 & Ghalf(mmaxres2),sqreig(maxres2)
146 double precision work(8*maxres6)
147 integer iwork(maxres6)
148 common /przechowalnia/ Gcopy,Ghalf
150 c Set up the matrix of the (dC,dX)-->(C,X) transformation (A), the
151 c inertia matrix (Gmat) and the inverse of the inertia matrix (Ginv)
153 c Determine the number of degrees of freedom (dimen) and the number of
155 dimen=(nct-nnt+1)+nside
156 dimen1=(nct-nnt)+(nct-nnt+1)
159 if (nfgtasks.gt.1) then
161 call MPI_Bcast(5,1,MPI_INTEGER,king,FG_COMM,IERROR)
162 time_Bcast=time_Bcast+MPI_Wtime()-time00
163 call int_bounds(dimen,igmult_start,igmult_end)
164 igmult_start=igmult_start-1
165 call MPI_Allgather(3*igmult_start,1,MPI_INTEGER,
166 & ng_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
167 my_ng_count=igmult_end-igmult_start
168 call MPI_Allgather(3*my_ng_count,1,MPI_INTEGER,ng_counts(0),1,
169 & MPI_INTEGER,FG_COMM,IERROR)
170 write (iout,*) 'Processor:',fg_rank,' CG group',kolor,
171 & ' absolute rank',myrank,' igmult_start',igmult_start,
172 & ' igmult_end',igmult_end,' count',my_ng_count
173 write (iout,*) "ng_start",(ng_start(i),i=0,nfgtasks-1)
174 write (iout,*) "ng_counts",(ng_counts(i),i=0,nfgtasks-1)
184 c write (iout,*) "dimen",dimen," dimen1",dimen1," dimen3",dimen3
185 c Zeroing out A and fricmat
191 c Diagonal elements of the dC part of A and the respective friction coefficients
203 c Off-diagonal elements of the dC part of A
210 c Diagonal elements of the dX part of A and the respective friction coefficients
220 massvec(ii)=msc(iabs(iti))
221 if (iti.ne.10 .and. iti.ne.ntyp1) then
225 Gmat(ii1,ii1)=ISC(iabs(iti))
228 c Off-diagonal elements of the dX part of A
242 write (iout,*) "Vector massvec"
244 write (iout,*) i,massvec(i)
246 write (iout,'(//a)') "A"
247 call matout(dimen,dimen1,maxres2,maxres2,A)
250 c Calculate the G matrix (store in Gmat)
255 dtdi=dtdi+A(j,k)*A(j,i)*massvec(j)
257 Gmat(k,i)=Gmat(k,i)+dtdi
262 write (iout,'(//a)') "Gmat"
263 call matout(dimen,dimen,maxres2,maxres2,Gmat)
272 c Invert the G matrix
273 call MATINVERT(dimen,maxres2,Gcopy,Ginv,osob)
275 write (iout,'(//a)') "Ginv"
276 call matout(dimen,dimen,maxres2,maxres2,Ginv)
279 if (nfgtasks.gt.1) then
280 myginv_ng_count=maxres2*my_ng_count
281 call MPI_Allgather(maxres2*igmult_start,1,MPI_INTEGER,
282 & nginv_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
283 call MPI_Allgather(myginv_ng_count,1,MPI_INTEGER,
284 & nginv_counts(0),1,MPI_INTEGER,FG_COMM,IERROR)
285 write (iout,*) "nginv_start",(nginv_start(i),i=0,nfgtasks-1)
286 write (iout,*) "nginv_counts",(nginv_counts(i),i=0,nfgtasks-1)
288 c call MPI_Scatterv(ginv(1,1),nginv_counts(0),
289 c & nginv_start(0),MPI_DOUBLE_PRECISION,ginv,
290 c & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
291 c call MPI_Barrier(FG_COMM,IERR)
293 call MPI_Scatterv(ginv(1,1),nginv_counts(0),
294 & nginv_start(0),MPI_DOUBLE_PRECISION,gcopy(1,1),
295 & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
297 time_scatter_ginv=time_scatter_ginv+MPI_Wtime()-time00
304 c write (iout,*) "Master's chunk of ginv"
305 c call MATOUT2(my_ng_count,dimen,maxres2,maxres2,ginv)
309 write (iout,*) "The G matrix is singular."
312 c Compute G**(-1/2) and G**(1/2)
320 call gldiag(maxres2,dimen,dimen,Ghalf,work,Geigen,Gvec,
324 & "Eigenvectors and eigenvalues of the G matrix"
325 call eigout(dimen,dimen,maxres2,maxres2,Gvec,Geigen)
328 sqreig(i)=dsqrt(Geigen(i))
336 Gsqrp(i,j)=Gsqrp(i,j)+Gvec(i,k)*Gvec(j,k)*sqreig(k)
337 Gsqrm(i,j)=Gsqrm(i,j)+Gvec(i,k)*Gvec(j,k)/sqreig(k)
338 Gcopy(i,j)=Gcopy(i,j)+Gvec(i,k)*Gvec(j,k)*Geigen(k)
343 write (iout,*) "Comparison of original and restored G"
346 write (iout,'(2i5,5f10.5)') i,j,Gmat(i,j),Gcopy(i,j),
347 & Gmat(i,j)-Gcopy(i,j),Gsqrp(i,j),Gsqrm(i,j)
353 c-------------------------------------------------------------------------------
354 SUBROUTINE EIGOUT(NC,NR,LM2,LM3,A,B)
355 implicit real*8 (a-h,o-z)
357 include 'COMMON.IOUNITS'
358 double precision A(LM2,LM3),B(LM2)
362 WRITE(IOUT,600) (I,I=KA,KB)
363 WRITE(IOUT,601) (B(I),I=KA,KB)
367 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
373 4 IF (KB.EQ.NC) RETURN
377 600 FORMAT (// 9H ROOT NO.,I4,9I11)
378 601 FORMAT (/5X,10(1PE11.4))
380 603 FORMAT (I5,10F11.5)
383 c-------------------------------------------------------------------------------
384 SUBROUTINE MATOUT(NC,NR,LM2,LM3,A)
385 implicit real*8 (a-h,o-z)
387 include 'COMMON.IOUNITS'
388 double precision A(LM2,LM3)
392 WRITE(IOUT,600) (I,I=KA,KB)
396 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
402 4 IF (KB.EQ.NC) RETURN
406 600 FORMAT (//5x,9I11)
408 603 FORMAT (I5,10F11.3)
411 c-------------------------------------------------------------------------------
412 SUBROUTINE MATOUT1(NC,NR,LM2,LM3,A)
413 implicit real*8 (a-h,o-z)
415 include 'COMMON.IOUNITS'
416 double precision A(LM2,LM3)
420 WRITE(IOUT,600) (I,I=KA,KB)
424 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
430 4 IF (KB.EQ.NC) RETURN
434 600 FORMAT (//5x,7(3I5,2x))
436 603 FORMAT (I5,7(3F5.1,2x))
439 c-------------------------------------------------------------------------------
440 SUBROUTINE MATOUT2(NC,NR,LM2,LM3,A)
441 implicit real*8 (a-h,o-z)
443 include 'COMMON.IOUNITS'
444 double precision A(LM2,LM3)
448 WRITE(IOUT,600) (I,I=KA,KB)
452 WRITE(IOUT,603) I,(A(I,J),J=KA,KB)
458 4 IF (KB.EQ.NC) RETURN
462 600 FORMAT (//5x,4(3I9,2x))
464 603 FORMAT (I5,4(3F9.3,2x))
467 c---------------------------------------------------------------------------
468 SUBROUTINE ginv_mult(z,d_a_tmp)
469 implicit real*8 (a-h,o-z)
475 include 'COMMON.SETUP'
476 include 'COMMON.TIME1'
478 double precision z(dimen3),d_a_tmp(dimen3),temp(maxres6),time00
481 if (nfgtasks.gt.1) then
482 if (fg_rank.eq.0) then
483 c The matching BROADCAST for fg processors is called in ERGASTULUM
485 call MPI_Bcast(4,1,MPI_INTEGER,king,FG_COMM,IERROR)
486 time_Bcast=time_Bcast+MPI_Wtime()-time00
487 c print *,"Processor",myrank," BROADCAST iorder in GINV_MULT"
489 c write (2,*) "time00",time00
490 c write (2,*) "Before Scatterv"
492 c write (2,*) "Whole z (for FG master)"
496 c call MPI_Barrier(FG_COMM,IERROR)
498 call MPI_Scatterv(z,ng_counts(0),ng_start(0),
499 & MPI_DOUBLE_PRECISION,
500 & z,3*my_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
501 c write (2,*) "My chunk of z"
502 c do i=1,3*my_ng_count
505 c write (2,*) "After SCATTERV"
507 c write (2,*) "MPI_Wtime",MPI_Wtime()
508 time_scatter=time_scatter+MPI_Wtime()-time00
510 time_scatter_ginvmult=time_scatter_ginvmult+MPI_Wtime()-time00
512 c write (2,*) "time_scatter",time_scatter
513 c write (2,*) "dimen",dimen," dimen3",dimen3," my_ng_count",
522 c write (2,*) "k,i,j,ind",k,i,j,ind,(j-1)*3+k+1,
523 c & Ginv(i,j),z((j-1)*3+k+1),
524 c & Ginv(i,j)*z((j-1)*3+k+1)
525 c temp(ind)=temp(ind)+Ginv(i,j)*z((j-1)*3+k+1)
526 temp(ind)=temp(ind)+Ginv(j,i)*z((j-1)*3+k+1)
530 time_ginvmult=time_ginvmult+MPI_Wtime()-time01
531 c write (2,*) "Before REDUCE"
533 c write (2,*) "z before reduce"
535 c write (2,*) i,temp(i)
538 call MPI_Reduce(temp(1),d_a_tmp(1),dimen3,MPI_DOUBLE_PRECISION,
539 & MPI_SUM,king,FG_COMM,IERR)
540 time_reduce=time_reduce+MPI_Wtime()-time00
541 c write (2,*) "After REDUCE"
553 c write (2,*) "k,i,j,ind",k,i,j,ind,(j-1)*3+k+1
555 c & Ginv(i,j),z((j-1)*3+k+1),
556 c & Ginv(i,j)*z((j-1)*3+k+1)
557 d_a_tmp(ind)=d_a_tmp(ind)
558 & +Ginv(j,i)*z((j-1)*3+k+1)
559 c d_a_tmp(ind)=d_a_tmp(ind)
560 c & +Ginv(i,j)*z((j-1)*3+k+1)
565 time_ginvmult=time_ginvmult+MPI_Wtime()-time01
572 c---------------------------------------------------------------------------
574 SUBROUTINE ginv_mult_test(z,d_a_tmp)
577 c include 'COMMON.MD'
578 double precision z(dimen),d_a_tmp(dimen)
579 double precision ztmp(dimen/3),dtmp(dimen/3)
584 c d_a_tmp(i)=d_a_tmp(i)+Ginv(i,j)*z(j)
593 ztmp(j)=z((j-1)*3+k+1)
596 call alignx(16,ztmp(1))
597 call alignx(16,dtmp(1))
598 call alignx(16,Ginv(1,1))
603 dtmp(i)=dtmp(i)+Ginv(i,j)*ztmp(j)
614 c---------------------------------------------------------------------------
615 SUBROUTINE fricmat_mult(z,d_a_tmp)
622 include 'COMMON.IOUNITS'
623 include 'COMMON.SETUP'
624 include 'COMMON.TIME1'
626 include 'COMMON.LANGEVIN'
628 include 'COMMON.LANGEVIN.lang0'
630 double precision z(dimen3),d_a_tmp(dimen3),temp(maxres6),time00
633 if (nfgtasks.gt.1) then
634 if (fg_rank.eq.0) then
635 c The matching BROADCAST for fg processors is called in ERGASTULUM
637 call MPI_Bcast(9,1,MPI_INTEGER,king,FG_COMM,IERROR)
638 time_Bcast=time_Bcast+MPI_Wtime()-time00
639 c print *,"Processor",myrank," BROADCAST iorder in FRICMAT_MULT"
641 c call MPI_Barrier(FG_COMM,IERROR)
643 call MPI_Scatterv(z,ng_counts(0),ng_start(0),
644 & MPI_DOUBLE_PRECISION,
645 & z,3*my_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
646 c write (2,*) "My chunk of z"
647 c do i=1,3*my_ng_count
650 time_scatter=time_scatter+MPI_Wtime()-time00
652 time_scatter_fmatmult=time_scatter_fmatmult+MPI_Wtime()-time00
660 temp(ind)=temp(ind)-fricmat(j,i)*z((j-1)*3+k+1)
664 time_fricmatmult=time_fricmatmult+MPI_Wtime()-time01
665 c write (2,*) "Before REDUCE"
666 c write (2,*) "d_a_tmp before reduce"
668 c write (2,*) i,temp(i)
672 call MPI_Reduce(temp(1),d_a_tmp(1),dimen3,MPI_DOUBLE_PRECISION,
673 & MPI_SUM,king,FG_COMM,IERR)
674 time_reduce=time_reduce+MPI_Wtime()-time00
675 c write (2,*) "After REDUCE"
687 d_a_tmp(ind)=d_a_tmp(ind)
688 & -fricmat(j,i)*z((j-1)*3+k+1)
693 time_fricmatmult=time_fricmatmult+MPI_Wtime()-time01
698 c write (iout,*) "Vector d_a"
700 c write (2,*) i,d_a_tmp(i)