1 subroutine check_cartgrad
2 C Check the gradient of Cartesian coordinates in internal coordinates.
3 implicit real*8 (a-h,o-z)
5 include 'COMMON.CONTROL'
6 include 'COMMON.IOUNITS'
10 include 'COMMON.LOCAL'
11 include 'COMMON.DERIV'
12 dimension temp(6,maxres),xx(3),gg(3)
13 indmat(i,j)=((2*(nres-2)-i)*(i-1))/2+j-1
15 * Check the gradient of the virtual-bond and SC vectors in the internal
18 print '("Calling CHECK_ECART",1pd12.3)',aincr
19 write (iout,'("Calling CHECK_ECART",1pd12.3)') aincr
22 write (iout,'(a)') '**************** dx/dalpha'
28 temp(k,i)=dc(k,nres+i)
32 gg(k)=(dc(k,nres+i)-temp(k,i))/aincr
33 xx(k)=dabs((gg(k)-dxds(k,i))/(aincr*dabs(dxds(k,i))+aincr))
35 write (iout,'(i4,3e15.6/4x,3e15.6,3f9.3)')
36 & i,(gg(k),k=1,3),(dxds(k,i),k=1,3),(xx(k),k=1,3)
42 write (iout,'(a)') '**************** dx/domega'
48 temp(k,i)=dc(k,nres+i)
52 gg(k)=(dc(k,nres+i)-temp(k,i))/aincr
53 xx(k)=dabs((gg(k)-dxds(k+3,i))/
54 & (aincr*dabs(dxds(k+3,i))+aincr))
56 write (iout,'(i4,3e15.6/4x,3e15.6,3f9.3)')
57 & i,(gg(k),k=1,3),(dxds(k+3,i),k=1,3),(xx(k),k=1,3)
63 write (iout,'(a)') '**************** dx/dtheta'
67 theta(i)=theta(i)+aincr
70 temp(k,j)=dc(k,nres+j)
76 c print *,'i=',i-2,' j=',j-1,' ii=',ii
78 gg(k)=(dc(k,nres+j)-temp(k,j))/aincr
79 xx(k)=dabs((gg(k)-dxdv(k,ii))/
80 & (aincr*dabs(dxdv(k,ii))+aincr))
82 write (iout,'(2i4,3e14.6/8x,3e14.6,3f9.3)')
83 & i,j,(gg(k),k=1,3),(dxdv(k,ii),k=1,3),(xx(k),k=1,3)
90 write (iout,'(a)') '***************** dx/dphi'
96 temp(k,j)=dc(k,nres+j)
104 gg(k)=(dc(k,nres+j)-temp(k,j))/aincr
105 xx(k)=dabs((gg(k)-dxdv(k+3,ii))/
106 & (aincr*dabs(dxdv(k+3,ii))+aincr))
108 write (iout,'(2i4,3e14.6/8x,3e14.6,3f9.3)')
109 & i,j,(gg(k),k=1,3),(dxdv(k+3,ii),k=1,3),(xx(k),k=1,3)
115 write (iout,'(a)') '****************** ddc/dtheta'
118 theta(i+2)=thet+aincr
129 gg(k)=(dc(k,j)-temp(k,j))/aincr
130 xx(k)=dabs((gg(k)-dcdv(k,ii))/
131 & (aincr*dabs(dcdv(k,ii))+aincr))
133 write (iout,'(2i4,3e14.6/8x,3e14.6,3f9.3)')
134 & i,j,(gg(k),k=1,3),(dcdv(k,ii),k=1,3),(xx(k),k=1,3)
144 write (iout,'(a)') '******************* ddc/dphi'
158 gg(k)=(dc(k,j)-temp(k,j))/aincr
159 xx(k)=dabs((gg(k)-dcdv(k+3,ii))/
160 & (aincr*dabs(dcdv(k+3,ii))+aincr))
162 write (iout,'(2i4,3e14.6/8x,3e14.6,3f9.3)')
163 & i,j,(gg(k),k=1,3),(dcdv(k+3,ii),k=1,3),(xx(k),k=1,3)
175 C----------------------------------------------------------------------------
176 subroutine check_ecart
177 C Check the gradient of the energy in Cartesian coordinates.
178 implicit real*8 (a-h,o-z)
180 include 'COMMON.CONTROL'
181 include 'COMMON.CHAIN'
182 include 'COMMON.DERIV'
183 include 'COMMON.IOUNITS'
185 include 'COMMON.CONTACTS'
187 dimension ggg(6),cc(3),xx(3),ddc(3),ddx(3),x(maxvar),g(maxvar)
188 dimension grad_s(6,maxres)
189 double precision energia(0:n_ene),energia1(0:n_ene)
191 double precision urparm(1)
197 print '("Calling CHECK_ECART",1pd12.3)',aincr
198 write (iout,'("Calling CHECK_ECART",1pd12.3)') aincr
201 call geom_to_var(nvar,x)
202 call etotal(energia(0))
204 call enerprint(energia(0))
205 call gradient(nvar,x,nf,g,uiparm,urparm,fdum)
208 write (iout,'(i5,3f10.5)') i,(gradxorr(j,i),j=1,3)
212 grad_s(j,i)=gradc(j,i,icg)
213 grad_s(j+3,i)=gradx(j,i,icg)
217 write (iout,'(/a/)') 'Gradient in virtual-bond and SC vectors'
225 dc(j,i)=dc(j,i)+aincr
228 c(j,k+nres)=c(j,k+nres)+aincr
230 call etotal(energia1(0))
232 ggg(j)=(etot1-etot)/aincr
236 c(j,k+nres)=c(j,k+nres)-aincr
240 c(j,i+nres)=c(j,i+nres)+aincr
241 dc(j,i+nres)=dc(j,i+nres)+aincr
242 call etotal(energia1(0))
244 ggg(j+3)=(etot1-etot)/aincr
248 write (iout,'(i3,6(1pe12.5)/3x,6(1pe12.5)/)')
249 & i,(ggg(k),k=1,6),(grad_s(k,i),k=1,6)
253 c----------------------------------------------------------------------------
254 subroutine check_ecartint
255 C Check the gradient of the energy in Cartesian coordinates.
256 implicit real*8 (a-h,o-z)
258 include 'COMMON.CONTROL'
259 include 'COMMON.CHAIN'
260 include 'COMMON.DERIV'
261 include 'COMMON.IOUNITS'
263 include 'COMMON.CONTACTS'
265 include 'COMMON.LOCAL'
266 include 'COMMON.SPLITELE'
268 dimension ggg(6),ggg1(6),cc(3),xx(3),ddc(3),ddx(3),x(maxvar),
270 dimension dcnorm_safe(3),dxnorm_safe(3)
271 dimension grad_s(6,0:maxres),grad_s1(6,0:maxres)
272 double precision phi_temp(maxres),theta_temp(maxres),
273 & alph_temp(maxres),omeg_temp(maxres)
274 double precision energia(0:n_ene),energia1(0:n_ene)
276 double precision urparm(1)
286 c call checkintcartgrad
290 print '("Calling CHECK_ECARTINT",1pd12.3)',aincr
291 write (iout,'("Calling CHECK_ECARTINT",1pd12.3)') aincr
294 call geom_to_var(nvar,x)
295 if (.not.split_ene) then
296 call etotal(energia(0))
298 call enerprint(energia(0))
300 write (iout,*) "enter cartgrad"
303 write (iout,*) "exit cartgrad"
306 write (iout,*) "gcard and gxcart"
308 write (iout,'(i5,3f10.5,5x,3f10.5)') i,(gcart(j,i),j=1,3),
309 & (gxcart(j,i),j=1,3)
312 grad_s(j,0)=gcart(j,0)
316 grad_s(j,i)=gcart(j,i)
317 grad_s(j+3,i)=gxcart(j,i)
321 !- split gradient check
323 call etotal_long(energia(0))
324 call enerprint(energia(0))
326 write (iout,*) "enter cartgrad"
329 write (iout,*) "exit cartgrad"
332 write (iout,*) "longrange grad"
334 write (iout,'(i5,3f10.5,5x,3f10.5)') i,(gcart(j,i),j=1,3),
335 & (gxcart(j,i),j=1,3)
338 grad_s(j,0)=gcart(j,0)
342 grad_s(j,i)=gcart(j,i)
343 grad_s(j+3,i)=gxcart(j,i)
347 call etotal_short(energia(0))
348 call enerprint(energia(0))
350 write (iout,*) "enter cartgrad"
353 write (iout,*) "exit cartgrad"
356 write (iout,*) "shortrange grad"
358 write (iout,'(i5,3f10.5,5x,3f10.5)') i,(gcart(j,i),j=1,3),
359 & (gxcart(j,i),j=1,3)
362 grad_s1(j,0)=gcart(j,0)
366 grad_s1(j,i)=gcart(j,i)
367 grad_s1(j+3,i)=gxcart(j,i)
371 write (iout,'(/a/)') 'Gradient in virtual-bond and SC vectors'
379 dcnorm_safe(k)=dc_norm(k,i)
380 dxnorm_safe(k)=dc_norm(k,i+nres)
387 c Broadcast the order to compute internal coordinates to the slaves.
389 c & call MPI_Bcast(6,1,MPI_INTEGER,king,FG_COMM,IERROR)
391 c call int_from_cart1(.false.)
392 if (.not.split_ene) then
393 call etotal(energia1(0))
397 call etotal_long(energia1(0))
399 call etotal_short(energia1(0))
401 c write (iout,*) "etot11",etot11," etot12",etot12
403 !- end split gradient
404 c write(iout,'(2i5,2(a,f15.10))')i,j," etot",etot," etot1",etot1
408 c call int_from_cart1(.false.)
409 if (.not.split_ene) then
410 call etotal(energia1(0))
412 ggg(j)=(etot1-etot2)/(2*aincr)
415 call etotal_long(energia1(0))
417 ggg(j)=(etot11-etot21)/(2*aincr)
418 call etotal_short(energia1(0))
420 ggg1(j)=(etot12-etot22)/(2*aincr)
421 !- end split gradient
422 c write (iout,*) "etot21",etot21," etot22",etot22
424 c write(iout,'(2i5,2(a,f15.10))')i,j," etot",etot," etot2",etot2
429 dc(j,i+nres)=ddx(j)+aincr
431 c write (iout,*) "i",i," j",j," dxnorm+ and dxnorm"
432 c write (iout,'(3f15.10)') (dc_norm(k,i+nres),k=1,3)
433 c write (iout,'(3f15.10)') (dxnorm_safe(k),k=1,3)
434 c write (iout,*) "dxnormnorm",dsqrt(
435 c & dc_norm(1,i+nres)**2+dc_norm(2,i+nres)**2+dc_norm(3,i+nres)**2)
436 c write (iout,*) "dxnormnormsafe",dsqrt(
437 c & dxnorm_safe(1)**2+dxnorm_safe(2)**2+dxnorm_safe(3)**2)
439 if (.not.split_ene) then
440 call etotal(energia1(0))
444 call etotal_long(energia1(0))
446 call etotal_short(energia1(0))
449 !- end split gradient
450 c write(iout,'(2i5,2(a,f15.10))')i,j," etot",etot," etot1",etot1
451 dc(j,i+nres)=ddx(j)-aincr
453 c write (iout,*) "i",i," j",j," dxnorm- and dxnorm"
454 c write (iout,'(3f15.10)') (dc_norm(k,i+nres),k=1,3)
455 c write (iout,'(3f15.10)') (dxnorm_safe(k),k=1,3)
457 c write (iout,*) "dxnormnorm",dsqrt(
458 c & dc_norm(1,i+nres)**2+dc_norm(2,i+nres)**2+dc_norm(3,i+nres)**2)
459 c write (iout,*) "dxnormnormsafe",dsqrt(
460 c & dxnorm_safe(1)**2+dxnorm_safe(2)**2+dxnorm_safe(3)**2)
461 if (.not.split_ene) then
462 call etotal(energia1(0))
464 ggg(j+3)=(etot1-etot2)/(2*aincr)
467 call etotal_long(energia1(0))
469 ggg(j+3)=(etot11-etot21)/(2*aincr)
470 call etotal_short(energia1(0))
472 ggg1(j+3)=(etot12-etot22)/(2*aincr)
473 !- end split gradient
475 c write(iout,'(2i5,2(a,f15.10))')i,j," etot",etot," etot2",etot2
479 write (iout,'(i3,6(1pe12.5)/3x,6(1pe12.5)/3x,6(1pe12.5)/)')
480 & i,(ggg(k),k=1,6),(grad_s(k,i),k=1,6),(ggg(k)/grad_s(k,i),k=1,6)
482 write (iout,'(i3,6(1pe12.5)/3x,6(1pe12.5)/3x,6(1pe12.5)/)')
483 & i,(ggg1(k),k=1,6),(grad_s1(k,i),k=1,6),(ggg1(k)/grad_s1(k,i),
485 write (iout,'(i3,6(1pe12.5)/3x,6(1pe12.5)/3x,6(1pe12.5)/)')
486 & i,(ggg(k)+ggg1(k),k=1,6),(grad_s(k,i)+grad_s1(k,i),k=1,6),
487 & ((ggg(k)+ggg1(k))/(grad_s(k,i)+grad_s1(k,i)),k=1,6)
492 c-------------------------------------------------------------------------
493 subroutine int_from_cart1(lprn)
494 implicit real*8 (a-h,o-z)
500 include 'COMMON.IOUNITS'
502 include 'COMMON.CHAIN'
504 include 'COMMON.INTERACT'
505 include 'COMMON.LOCAL'
506 include 'COMMON.NAMES'
507 include 'COMMON.SETUP'
508 include 'COMMON.TIME1'
510 if (lprn) write (iout,'(/a)') 'Recalculated internal coordinates'
514 #if defined(PARINT) && defined(MPI)
515 do i=iint_start,iint_end
522 C print *,i,dnorm1,dnorm2
524 c(j,maxres2)=0.5D0*(2*c(j,i)+(c(j,i-1)-c(j,i))/dnorm1
525 & +(c(j,i+1)-c(j,i))/dnorm2)
529 if (i.le.nres) phi(i+1)=beta(i-2,i-1,i,i+1)
530 if ((itype(i).ne.10).and.(itype(i-1).ne.10)) then
531 tauangle(3,i+1)=beta(i+nres-1,i-1,i,i+nres)
533 if (itype(i-1).ne.10) then
534 tauangle(1,i+1)=beta(i-1+nres,i-1,i,i+1)
535 omicron(1,i)=alpha(i-2,i-1,i-1+nres)
536 omicron(2,i)=alpha(i-1+nres,i-1,i)
538 if (itype(i).ne.10) then
539 tauangle(2,i+1)=beta(i-2,i-1,i,i+nres)
542 omeg(i)=beta(nres+i,i,maxres2,i+1)
544 alph(i)=alpha(nres+i,i,maxres2)
546 theta(i+1)=alpha(i-1,i,i+1)
549 vbld_inv(i)=1.0d0/vbld(i)
550 vbld(nres+i)=dist(nres+i,i)
551 C print *,vbld(i+nres)
553 if (itype(i).ne.10) then
554 vbld_inv(nres+i)=1.0d0/vbld(nres+i)
556 vbld_inv(nres+i)=0.0d0
559 #if defined(PARINT) && defined(MPI)
560 if (nfgtasks1.gt.1) then
561 cd write(iout,*) "iint_start",iint_start," iint_count",
562 cd & (iint_count(i),i=0,nfgtasks-1)," iint_displ",
563 cd & (iint_displ(i),i=0,nfgtasks-1)
564 cd write (iout,*) "Gather vbld backbone"
567 call MPI_Allgatherv(vbld(iint_start),iint_count(fg_rank1),
568 & MPI_DOUBLE_PRECISION,vbld(1),iint_count(0),iint_displ(0),
569 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
570 cd write (iout,*) "Gather vbld_inv"
572 call MPI_Allgatherv(vbld_inv(iint_start),iint_count(fg_rank1),
573 & MPI_DOUBLE_PRECISION,vbld_inv(1),iint_count(0),iint_displ(0),
574 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
575 cd write (iout,*) "Gather vbld side chain"
577 call MPI_Allgatherv(vbld(iint_start+nres),iint_count(fg_rank1),
578 & MPI_DOUBLE_PRECISION,vbld(nres+1),iint_count(0),iint_displ(0),
579 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
580 cd write (iout,*) "Gather vbld_inv side chain"
582 call MPI_Allgatherv(vbld_inv(iint_start+nres),
583 & iint_count(fg_rank1),MPI_DOUBLE_PRECISION,vbld_inv(nres+1),
584 & iint_count(0),iint_displ(0),MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
585 cd write (iout,*) "Gather theta"
587 call MPI_Allgatherv(theta(iint_start+1),iint_count(fg_rank1),
588 & MPI_DOUBLE_PRECISION,theta(2),iint_count(0),iint_displ(0),
589 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
590 cd write (iout,*) "Gather phi"
592 call MPI_Allgatherv(phi(iint_start+1),iint_count(fg_rank1),
593 & MPI_DOUBLE_PRECISION,phi(2),iint_count(0),iint_displ(0),
594 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
596 cd write (iout,*) "Gather alph"
598 call MPI_Allgatherv(alph(iint_start),iint_count(fg_rank1),
599 & MPI_DOUBLE_PRECISION,alph(1),iint_count(0),iint_displ(0),
600 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
601 cd write (iout,*) "Gather omeg"
603 call MPI_Allgatherv(omeg(iint_start),iint_count(fg_rank1),
604 & MPI_DOUBLE_PRECISION,omeg(1),iint_count(0),iint_displ(0),
605 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
607 time_gather=time_gather+MPI_Wtime()-time00
612 dc_norm(j,i)=dc(j,i)*vbld_inv(i+1)
617 dc_norm(j,i+nres)=dc(j,i+nres)*vbld_inv(i+nres)
622 write (iout,1212) restyp(itype(i)),i,vbld(i),
623 &rad2deg*theta(i),rad2deg*phi(i),vbld(nres+i),
624 &rad2deg*alph(i),rad2deg*omeg(i)
627 1212 format (a3,'(',i3,')',2(f15.10,2f10.2))
629 time_intfcart=time_intfcart+MPI_Wtime()-time01
633 c----------------------------------------------------------------------------
634 subroutine check_eint
635 C Check the gradient of energy in internal coordinates.
636 implicit real*8 (a-h,o-z)
638 include 'COMMON.CONTROL'
639 include 'COMMON.CHAIN'
640 include 'COMMON.DERIV'
641 include 'COMMON.IOUNITS'
645 dimension x(maxvar),gana(maxvar),gg(maxvar)
647 double precision urparm(1)
648 double precision energia(0:n_ene),energia1(0:n_ene),
654 print '("Calling CHECK_INT",1pd12.3)',aincr
655 write (iout,'("Calling CHECK_INT",1pd12.3)') aincr
659 call geom_to_var(nvar,x)
660 call var_to_geom(nvar,x)
664 call etotal(energia(0))
666 call enerprint(energia(0))
669 if (MyID.ne.BossID) then
670 call mp_bcast(x(1),8*(nvar+3),BossID,fgGroupID)
678 cd write (iout,'(10f8.3)') (rad2deg*x(i),i=1,nvar)
679 call gradient(nvar,x,nf,gana,uiparm,urparm,fdum)
680 cd write (iout,'(i3,1pe14.4)') (i,gana(i),i=1,nvar)
685 call var_to_geom(nvar,x)
686 call chainbuild_extconf
687 call etotal(energia1(0))
690 call var_to_geom(nvar,x)
691 call chainbuild_extconf
692 call etotal(energia2(0))
694 gg(i)=(etot2-etot1)/aincr
695 write (iout,*) i,etot1,etot2
698 write (iout,'(/2a)')' Variable Numerical Analytical',
704 else if (i.le.nphi+ntheta) then
707 else if (i.le.nphi+ntheta+nside) then
711 ii=i-(nphi+ntheta+nside)
714 write (iout,'(i3,a,i3,3(1pd16.6))')
715 & i,key,ii,gg(i),gana(i),
716 & 100.0D0*dabs(gg(i)-gana(i))/(dabs(gana(i))+aincr)