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.IOUNITS'
10 include 'COMMON.DERIV'
11 dimension temp(6,maxres),xx(3),gg(3)
12 indmat(i,j)=((2*(nres-2)-i)*(i-1))/2+j-1
14 * Check the gradient of the virtual-bond and SC vectors in the internal
20 write (iout,'(a)') '**************** dx/dalpha'
26 temp(k,i)=dc(k,nres+i)
30 gg(k)=(dc(k,nres+i)-temp(k,i))/aincr
31 xx(k)=dabs((gg(k)-dxds(k,i))/(aincr*dabs(dxds(k,i))+aincr))
33 write (iout,'(i4,3e15.6/4x,3e15.6,3f9.3)')
34 & i,(gg(k),k=1,3),(dxds(k,i),k=1,3),(xx(k),k=1,3)
40 write (iout,'(a)') '**************** dx/domega'
46 temp(k,i)=dc(k,nres+i)
50 gg(k)=(dc(k,nres+i)-temp(k,i))/aincr
51 xx(k)=dabs((gg(k)-dxds(k+3,i))/
52 & (aincr*dabs(dxds(k+3,i))+aincr))
54 write (iout,'(i4,3e15.6/4x,3e15.6,3f9.3)')
55 & i,(gg(k),k=1,3),(dxds(k+3,i),k=1,3),(xx(k),k=1,3)
61 write (iout,'(a)') '**************** dx/dtheta'
65 theta(i)=theta(i)+aincr
68 temp(k,j)=dc(k,nres+j)
74 c print *,'i=',i-2,' j=',j-1,' ii=',ii
76 gg(k)=(dc(k,nres+j)-temp(k,j))/aincr
77 xx(k)=dabs((gg(k)-dxdv(k,ii))/
78 & (aincr*dabs(dxdv(k,ii))+aincr))
80 write (iout,'(2i4,3e14.6/8x,3e14.6,3f9.3)')
81 & i,j,(gg(k),k=1,3),(dxdv(k,ii),k=1,3),(xx(k),k=1,3)
88 write (iout,'(a)') '***************** dx/dphi'
94 temp(k,j)=dc(k,nres+j)
102 gg(k)=(dc(k,nres+j)-temp(k,j))/aincr
103 xx(k)=dabs((gg(k)-dxdv(k+3,ii))/
104 & (aincr*dabs(dxdv(k+3,ii))+aincr))
106 write (iout,'(2i4,3e14.6/8x,3e14.6,3f9.3)')
107 & i,j,(gg(k),k=1,3),(dxdv(k+3,ii),k=1,3),(xx(k),k=1,3)
113 write (iout,'(a)') '****************** ddc/dtheta'
116 theta(i+2)=thet+aincr
127 gg(k)=(dc(k,j)-temp(k,j))/aincr
128 xx(k)=dabs((gg(k)-dcdv(k,ii))/
129 & (aincr*dabs(dcdv(k,ii))+aincr))
131 write (iout,'(2i4,3e14.6/8x,3e14.6,3f9.3)')
132 & i,j,(gg(k),k=1,3),(dcdv(k,ii),k=1,3),(xx(k),k=1,3)
142 write (iout,'(a)') '******************* ddc/dphi'
156 gg(k)=(dc(k,j)-temp(k,j))/aincr
157 xx(k)=dabs((gg(k)-dcdv(k+3,ii))/
158 & (aincr*dabs(dcdv(k+3,ii))+aincr))
160 write (iout,'(2i4,3e14.6/8x,3e14.6,3f9.3)')
161 & i,j,(gg(k),k=1,3),(dcdv(k+3,ii),k=1,3),(xx(k),k=1,3)
173 C----------------------------------------------------------------------------
174 subroutine check_ecart
175 C Check the gradient of the energy in Cartesian coordinates.
176 implicit real*8 (a-h,o-z)
178 include 'COMMON.CHAIN'
179 include 'COMMON.DERIV'
180 include 'COMMON.IOUNITS'
182 include 'COMMON.CONTACTS'
184 include 'COMMON.CONTACTS.MOMENT'
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)
198 print '(a)','CG processor',me,' calling CHECK_CART.'
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.CONTACTS.MOMENT'
268 include 'COMMON.LOCAL'
269 include 'COMMON.SPLITELE'
271 dimension ggg(6),ggg1(6),cc(3),xx(3),ddc(3),ddx(3),x(maxvar),
273 dimension dcnorm_safe(3),dxnorm_safe(3)
274 dimension grad_s(6,0:maxres),grad_s1(6,0:maxres)
275 double precision phi_temp(maxres),theta_temp(maxres),
276 & alph_temp(maxres),omeg_temp(maxres)
277 double precision energia(0:n_ene),energia1(0:n_ene)
279 double precision urparm(1)
288 c call checkintcartgrad
291 write(iout,*) 'Calling CHECK_ECARTINT.'
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"
307 write (iout,'(i5,3f10.5)') i,(gradxorr(j,i),j=1,3)
310 grad_s(j,0)=gcart(j,0)
314 grad_s(j,i)=gcart(j,i)
315 grad_s(j+3,i)=gxcart(j,i)
319 !- split gradient check
320 write (iout,*) "split_ene not supported"
322 c call etotal_long(energia(0))
323 c call enerprint(energia(0))
325 c write (iout,*) "enter cartgrad"
328 c write (iout,*) "exit cartgrad"
331 c write (iout,*) "longrange grad"
333 c write (iout,'(i5,3f10.5,5x,3f10.5)') i,(gcart(j,i),j=1,3),
334 c & (gxcart(j,i),j=1,3)
337 c grad_s(j,0)=gcart(j,0)
341 c grad_s(j,i)=gcart(j,i)
342 c grad_s(j+3,i)=gxcart(j,i)
346 c call etotal_short(energia(0))
347 c call enerprint(energia(0))
349 c write (iout,*) "enter cartgrad"
352 c write (iout,*) "exit cartgrad"
355 c write (iout,*) "shortrange grad"
357 c write (iout,'(i5,3f10.5,5x,3f10.5)') i,(gcart(j,i),j=1,3),
358 c & (gxcart(j,i),j=1,3)
361 c grad_s1(j,0)=gcart(j,0)
365 c grad_s1(j,i)=gcart(j,i)
366 c grad_s1(j+3,i)=gxcart(j,i)
370 write (iout,'(/a/)') 'Gradient in virtual-bond and SC vectors'
377 dcnorm_safe(k)=dc_norm(k,i)
378 dxnorm_safe(k)=dc_norm(k,i+nres)
385 c Broadcast the order to compute internal coordinates to the slaves.
387 c & call MPI_Bcast(6,1,MPI_INTEGER,king,FG_COMM,IERROR)
389 c call int_from_cart1(.false.)
390 if (.not.split_ene) then
391 call etotal(energia1(0))
395 c call etotal_long(energia1(0))
397 c call etotal_short(energia1(0))
399 c write (iout,*) "etot11",etot11," etot12",etot12
401 !- end split gradient
402 c write(iout,'(2i5,2(a,f15.10))')i,j," etot",etot," etot1",etot1
405 c call int_from_cart1(.false.)
406 if (.not.split_ene) then
407 call etotal(energia1(0))
409 ggg(j)=(etot1-etot2)/(2*aincr)
412 c call etotal_long(energia1(0))
414 c ggg(j)=(etot11-etot21)/(2*aincr)
415 c call etotal_short(energia1(0))
417 c ggg1(j)=(etot12-etot22)/(2*aincr)
418 !- end split gradient
419 c write (iout,*) "etot21",etot21," etot22",etot22
421 c write(iout,'(2i5,2(a,f15.10))')i,j," etot",etot," etot2",etot2
426 dc(j,i+nres)=ddx(j)+aincr
428 c write (iout,*) "i",i," j",j," dxnorm+ and dxnorm"
429 c write (iout,'(3f15.10)') (dc_norm(k,i+nres),k=1,3)
430 c write (iout,'(3f15.10)') (dxnorm_safe(k),k=1,3)
431 c write (iout,*) "dxnormnorm",dsqrt(
432 c & dc_norm(1,i+nres)**2+dc_norm(2,i+nres)**2+dc_norm(3,i+nres)**2)
433 c write (iout,*) "dxnormnormsafe",dsqrt(
434 c & dxnorm_safe(1)**2+dxnorm_safe(2)**2+dxnorm_safe(3)**2)
436 if (.not.split_ene) then
437 call etotal(energia1(0))
441 c call etotal_long(energia1(0))
443 c call etotal_short(energia1(0))
446 !- end split gradient
447 c write(iout,'(2i5,2(a,f15.10))')i,j," etot",etot," etot1",etot1
448 dc(j,i+nres)=ddx(j)-aincr
450 c write (iout,*) "i",i," j",j," dxnorm- and dxnorm"
451 c write (iout,'(3f15.10)') (dc_norm(k,i+nres),k=1,3)
452 c write (iout,'(3f15.10)') (dxnorm_safe(k),k=1,3)
454 c write (iout,*) "dxnormnorm",dsqrt(
455 c & dc_norm(1,i+nres)**2+dc_norm(2,i+nres)**2+dc_norm(3,i+nres)**2)
456 c write (iout,*) "dxnormnormsafe",dsqrt(
457 c & dxnorm_safe(1)**2+dxnorm_safe(2)**2+dxnorm_safe(3)**2)
458 if (.not.split_ene) then
459 call etotal(energia1(0))
461 ggg(j+3)=(etot1-etot2)/(2*aincr)
464 c call etotal_long(energia1(0))
466 c ggg(j+3)=(etot11-etot21)/(2*aincr)
467 c call etotal_short(energia1(0))
469 c ggg1(j+3)=(etot12-etot22)/(2*aincr)
470 !- end split gradient
472 c write(iout,'(2i5,2(a,f15.10))')i,j," etot",etot," etot2",etot2
476 write (iout,'(i3,6(1pe12.5)/3x,6(1pe12.5)/3x,6(1pe12.5)/)')
477 & i,(ggg(k),k=1,6),(grad_s(k,i),k=1,6),(ggg(k)/grad_s(k,i),k=1,6)
479 write (iout,'(i3,6(1pe12.5)/3x,6(1pe12.5)/3x,6(1pe12.5)/)')
480 & i,(ggg1(k),k=1,6),(grad_s1(k,i),k=1,6),(ggg1(k)/grad_s1(k,i),
482 write (iout,'(i3,6(1pe12.5)/3x,6(1pe12.5)/3x,6(1pe12.5)/)')
483 & i,(ggg(k)+ggg1(k),k=1,6),(grad_s(k,i)+grad_s1(k,i),k=1,6),
484 & ((ggg(k)+ggg1(k))/(grad_s(k,i)+grad_s1(k,i)),k=1,6)
489 c-------------------------------------------------------------------------
490 subroutine int_from_cart1(lprn)
491 implicit real*8 (a-h,o-z)
497 include 'COMMON.IOUNITS'
499 include 'COMMON.CHAIN'
501 include 'COMMON.INTERACT'
502 include 'COMMON.LOCAL'
503 include 'COMMON.NAMES'
504 include 'COMMON.SETUP'
505 include 'COMMON.TIME1'
507 if (lprn) write (iout,'(/a)') 'Recalculated internal coordinates'
511 #if defined(PARINT) && defined(MPI)
512 do i=iint_start,iint_end
519 c(j,maxres2)=0.5D0*(2*c(j,i)+(c(j,i-1)-c(j,i))/dnorm1
520 & +(c(j,i+1)-c(j,i))/dnorm2)
523 if (i.gt.2) phi(i+1)=beta(i-2,i-1,i,i+1)
524 omeg(i)=beta(nres+i,i,maxres2,i+1)
525 alph(i)=alpha(nres+i,i,maxres2)
526 theta(i+1)=alpha(i-1,i,i+1)
528 vbld_inv(i)=1.0d0/vbld(i)
529 vbld(nres+i)=dist(nres+i,i)
530 if (itype(i).ne.10) then
531 vbld_inv(nres+i)=1.0d0/vbld(nres+i)
533 vbld_inv(nres+i)=0.0d0
536 #if defined(PARINT) && defined(MPI)
537 if (nfgtasks1.gt.1) then
538 cd write(iout,*) "iint_start",iint_start," iint_count",
539 cd & (iint_count(i),i=0,nfgtasks-1)," iint_displ",
540 cd & (iint_displ(i),i=0,nfgtasks-1)
541 cd write (iout,*) "Gather vbld backbone"
544 call MPI_Allgatherv(vbld(iint_start),iint_count(fg_rank1),
545 & MPI_DOUBLE_PRECISION,vbld(1),iint_count(0),iint_displ(0),
546 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
547 cd write (iout,*) "Gather vbld_inv"
549 call MPI_Allgatherv(vbld_inv(iint_start),iint_count(fg_rank1),
550 & MPI_DOUBLE_PRECISION,vbld_inv(1),iint_count(0),iint_displ(0),
551 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
552 cd write (iout,*) "Gather vbld side chain"
554 call MPI_Allgatherv(vbld(iint_start+nres),iint_count(fg_rank1),
555 & MPI_DOUBLE_PRECISION,vbld(nres+1),iint_count(0),iint_displ(0),
556 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
557 cd write (iout,*) "Gather vbld_inv side chain"
559 call MPI_Allgatherv(vbld_inv(iint_start+nres),
560 & iint_count(fg_rank1),MPI_DOUBLE_PRECISION,vbld_inv(nres+1),
561 & iint_count(0),iint_displ(0),MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
562 cd write (iout,*) "Gather theta"
564 call MPI_Allgatherv(theta(iint_start+1),iint_count(fg_rank1),
565 & MPI_DOUBLE_PRECISION,theta(2),iint_count(0),iint_displ(0),
566 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
567 cd write (iout,*) "Gather phi"
569 call MPI_Allgatherv(phi(iint_start+1),iint_count(fg_rank1),
570 & MPI_DOUBLE_PRECISION,phi(2),iint_count(0),iint_displ(0),
571 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
573 cd write (iout,*) "Gather alph"
575 call MPI_Allgatherv(alph(iint_start),iint_count(fg_rank1),
576 & MPI_DOUBLE_PRECISION,alph(1),iint_count(0),iint_displ(0),
577 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
578 cd write (iout,*) "Gather omeg"
580 call MPI_Allgatherv(omeg(iint_start),iint_count(fg_rank1),
581 & MPI_DOUBLE_PRECISION,omeg(1),iint_count(0),iint_displ(0),
582 & MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
584 time_gather=time_gather+MPI_Wtime()-time00
589 dc_norm(j,i)=dc(j,i)*vbld_inv(i+1)
594 dc_norm(j,i+nres)=dc(j,i+nres)*vbld_inv(i+nres)
599 write (iout,1212) restyp(itype(i)),i,vbld(i),
600 &rad2deg*theta(i),rad2deg*phi(i),vbld(nres+i),
601 &rad2deg*alph(i),rad2deg*omeg(i)
604 1212 format (a3,'(',i3,')',2(f15.10,2f10.2))
606 time_intfcart=time_intfcart+MPI_Wtime()-time01
610 c----------------------------------------------------------------------------
611 subroutine check_eint
612 C Check the gradient of energy in internal coordinates.
613 implicit real*8 (a-h,o-z)
615 include 'COMMON.CHAIN'
616 include 'COMMON.DERIV'
617 include 'COMMON.IOUNITS'
621 dimension x(maxvar),gana(maxvar),gg(maxvar)
623 double precision urparm(1)
624 double precision energia(0:n_ene),energia1(0:n_ene),
630 print '(a)','Calling CHECK_INT.'
634 call geom_to_var(nvar,x)
635 call var_to_geom(nvar,x)
639 call etotal(energia(0))
641 call enerprint(energia(0))
644 if (MyID.ne.BossID) then
645 call mp_bcast(x(1),8*(nvar+3),BossID,fgGroupID)
653 cd write (iout,'(10f8.3)') (rad2deg*x(i),i=1,nvar)
654 call gradient(nvar,x,nf,gana,uiparm,urparm,fdum)
655 cd write (iout,'(i3,1pe14.4)') (i,gana(i),i=1,nvar)
660 call var_to_geom(nvar,x)
662 call etotal(energia1(0))
665 call var_to_geom(nvar,x)
667 call etotal(energia2(0))
669 gg(i)=(etot2-etot1)/aincr
670 write (iout,*) i,etot1,etot2
673 write (iout,'(/2a)')' Variable Numerical Analytical',
679 else if (i.le.nphi+ntheta) then
682 else if (i.le.nphi+ntheta+nside) then
686 ii=i-(nphi+ntheta+nside)
689 write (iout,'(i3,a,i3,3(1pd16.6))')
690 & i,key,ii,gg(i),gana(i),
691 & 100.0D0*dabs(gg(i)-gana(i))/(dabs(gana(i))+aincr)