2 !-----------------------------------------------------------------------------
11 !-----------------------------------------------------------------------------
14 !-----------------------------------------------------------------------------
18 real(kind=8),dimension(:,:,:),allocatable :: t,r !(3,3,maxres)
19 !-----------------------------------------------------------------------------
22 !-----------------------------------------------------------------------------
24 ! Variables (set in init routine) never modified by local_move
26 integer :: init_called
27 logical :: locmove_output
28 real(kind=8) :: min_theta, max_theta
29 real(kind=8) :: dmin2,dmax2
30 real(kind=8) :: flag,small,small2
31 ! Workspace for local_move
33 integer :: a_n,b_n,res_n
34 real(kind=8),dimension(0:7) :: a_ang
35 real(kind=8),dimension(0:3) :: b_ang
36 real(kind=8),dimension(0:11) :: res_ang
37 logical,dimension(0:2,0:7) :: a_tab
38 logical,dimension(0:2,0:3) :: b_tab
39 logical,dimension(0:2,0:2,0:11) :: res_tab
40 !-----------------------------------------------------------------------------
41 ! integer,dimension(:),allocatable :: itype_pdb !(maxres) initialize in molread
42 !-----------------------------------------------------------------------------
45 !-----------------------------------------------------------------------------
47 !-----------------------------------------------------------------------------
49 !-----------------------------------------------------------------------------
50 real(kind=8) function ARCOS(X)
51 ! implicit real*8 (a-h,o-z)
52 ! include 'COMMON.GEO'
55 IF (DABS(X).LT.1.0D0) GOTO 1
56 ARCOS=PIPOL*(1.0d0-DSIGN(1.0D0,X))
61 !-----------------------------------------------------------------------------
63 !-----------------------------------------------------------------------------
66 ! Build the virtual polypeptide chain. Side-chain centroids are moveable.
69 ! implicit real*8 (a-h,o-z)
70 ! include 'DIMENSIONS'
71 ! include 'COMMON.CHAIN'
72 ! include 'COMMON.LOCAL'
73 ! include 'COMMON.GEO'
74 ! include 'COMMON.VAR'
75 ! include 'COMMON.IOUNITS'
76 ! include 'COMMON.NAMES'
77 ! include 'COMMON.INTERACT'
81 real(kind=8) :: be,be1,alfai
84 ! Set lprn=.true. for debugging
86 print *,"I ENTER CHAINBUILD"
88 ! Define the origin and orientation of the coordinate system and locate the
89 ! first three CA's and SC(2).
91 !elwrite(iout,*)"in chainbuild"
93 !elwrite(iout,*)"after orig_frame"
95 ! Build the alpha-carbon chain.
98 call locate_next_res(i)
100 !elwrite(iout,*)"after locate_next_res"
102 ! First and last SC must coincide with the corresponding CA.
106 dc_norm(j,nres+1)=0.0D0
107 dc(j,nres+nres)=0.0D0
108 dc_norm(j,nres+nres)=0.0D0
110 c(j,nres+nres)=c(j,nres)
113 ! Temporary diagnosis
118 write (iout,'(/a)') 'Recalculated internal coordinates'
121 c(j,nres2+2)=0.5D0*(c(j,i-1)+c(j,i+1)) !maxres2=2*maxres
124 if (i.gt.3) be=rad2deg*beta(i-3,i-2,i-1,i)
125 be1=rad2deg*beta(nres+i,i,nres2+2,i+1)
127 if (i.gt.2) alfai=rad2deg*alpha(i-2,i-1,i)
128 write (iout,1212) restyp(itype(i,1),1),i,dist(i-1,i),&
129 alfai,be,dist(nres+i,i),rad2deg*alpha(nres+i,i,nres2+2),be1
131 1212 format (a3,'(',i3,')',2(f10.5,2f10.2))
136 end subroutine chainbuild
137 !-----------------------------------------------------------------------------
138 subroutine orig_frame
140 ! Define the origin and orientation of the coordinate system and locate
141 ! the first three atoms.
143 ! implicit real*8 (a-h,o-z)
144 ! include 'DIMENSIONS'
145 ! include 'COMMON.CHAIN'
146 ! include 'COMMON.LOCAL'
147 ! include 'COMMON.GEO'
148 ! include 'COMMON.VAR'
151 real(kind=8) :: cost,sint
153 !el allocate(t(3,3,nres)) !(3,3,maxres)
154 !el allocate(r(3,3,nres)) !(3,3,maxres)
155 !el allocate(rt(3,3,nres)) !(3,3,maxres)
156 !el allocate(dc_norm(3,0:2*nres)) !(3,0:maxres2)
157 !el allocate(prod(3,3,nres)) !(3,3,maxres)
210 dc_norm(j,2)=prod(j,1,2)
211 dc(j,2)=vbld(3)*prod(j,1,2)
212 c(j,3)=c(j,2)+dc(j,2)
214 call locate_side_chain(2)
216 end subroutine orig_frame
217 !-----------------------------------------------------------------------------
218 subroutine locate_next_res(i)
220 ! Locate CA(i) and SC(i-1)
222 ! implicit real*8 (a-h,o-z)
223 ! include 'DIMENSIONS'
224 ! include 'COMMON.CHAIN'
225 ! include 'COMMON.LOCAL'
226 ! include 'COMMON.GEO'
227 ! include 'COMMON.VAR'
228 ! include 'COMMON.IOUNITS'
229 ! include 'COMMON.NAMES'
230 ! include 'COMMON.INTERACT'
232 ! Define the rotation matrices corresponding to CA(i)
236 real(kind=8) :: theti,phii
237 real(kind=8) :: cost,sint,cosphi,sinphi
242 call proc_proc(theti,icrc)
243 if(icrc.eq.1)theti=100.0
246 call proc_proc(phii,icrc)
247 if(icrc.eq.1)phii=180.0
250 if (theti.ne.theti) theti=100.0
252 if (phii.ne.phii) phii=180.0
262 ! Define the matrices of the rotation about the virtual-bond valence angles
263 ! theta, T(i,j,k), virtual-bond dihedral angles gamma (miscalled PHI in this
264 ! program), R(i,j,k), and, the cumulative matrices of rotation RT
286 rt(2,1,i-2)=sint*cosphi
287 rt(2,2,i-2)=-cost*cosphi
289 rt(3,1,i-2)=-sint*sinphi
290 rt(3,2,i-2)=cost*sinphi
292 call matmult(prod(1,1,i-2),rt(1,1,i-2),prod(1,1,i-1))
294 dc_norm(j,i-1)=prod(j,1,i-1)
295 dc(j,i-1)=vbld(i)*prod(j,1,i-1)
296 c(j,i)=c(j,i-1)+dc(j,i-1)
298 !d print '(2i3,2(3f10.5,5x))', i-1,i,(dc(j,i-1),j=1,3),(c(j,i),j=1,3)
300 ! Now calculate the coordinates of SC(i-1)
302 call locate_side_chain(i-1)
304 end subroutine locate_next_res
305 !-----------------------------------------------------------------------------
306 subroutine locate_side_chain(i)
308 ! Locate the side-chain centroid i, 1 < i < NRES. Put in C(*,NRES+i).
310 ! implicit real*8 (a-h,o-z)
311 ! include 'DIMENSIONS'
312 ! include 'COMMON.CHAIN'
313 ! include 'COMMON.LOCAL'
314 ! include 'COMMON.GEO'
315 ! include 'COMMON.VAR'
316 ! include 'COMMON.IOUNITS'
317 ! include 'COMMON.NAMES'
318 ! include 'COMMON.INTERACT'
320 real(kind=8),dimension(3) :: xx
321 real(kind=8) :: alphi,omegi,theta2
322 real(kind=8) :: dsci,dsci_inv,sinalphi,cosalphi,cosomegi,sinomegi
323 real(kind=8) :: xp,yp,zp,cost2,sint2,rj
324 ! dsci=dsc(itype(i,1))
325 ! dsci_inv=dsc_inv(itype(i,1))
327 dsci_inv=vbld_inv(i+nres)
334 call proc_proc(alphi,icrc)
335 if(icrc.eq.1)alphi=100.0
337 call proc_proc(omegi,icrc)
338 if(icrc.eq.1)omegi=-100.0
340 if (alphi.ne.alphi) alphi=100.0
341 if (omegi.ne.omegi) omegi=-100.0
352 yp= dsci*sinalphi*cosomegi
353 zp=-dsci*sinalphi*sinomegi
354 ! Now we have to rotate the coordinate system by 180-theta(i)/2 so as to get its
355 ! X-axis aligned with the vector DC(*,i)
356 theta2=pi-0.5D0*theta(i+1)
359 xx(1)= xp*cost2+yp*sint2
360 xx(2)=-xp*sint2+yp*cost2
362 !d print '(a3,i3,3f10.5,5x,3f10.5)',restyp(itype(i,1)),i,
363 !d & xp,yp,zp,(xx(k),k=1,3)
367 ! Bring the SC vectors to the common coordinate system.
369 xx(2)=xloc(2,i)*r(2,2,i-1)+xloc(3,i)*r(2,3,i-1)
370 xx(3)=xloc(2,i)*r(3,2,i-1)+xloc(3,i)*r(3,3,i-1)
377 rj=rj+prod(j,k,i-1)*xx(k)
380 dc_norm(j,nres+i)=rj*dsci_inv
381 c(j,nres+i)=c(j,i)+rj
384 end subroutine locate_side_chain
385 !-----------------------------------------------------------------------------
387 !-----------------------------------------------------------------------------
388 subroutine int_from_cart1(lprn)
389 ! implicit real*8 (a-h,o-z)
390 ! include 'DIMENSIONS'
395 ! include 'COMMON.IOUNITS'
396 ! include 'COMMON.VAR'
397 ! include 'COMMON.CHAIN'
398 ! include 'COMMON.GEO'
399 ! include 'COMMON.INTERACT'
400 ! include 'COMMON.LOCAL'
401 ! include 'COMMON.NAMES'
402 ! include 'COMMON.SETUP'
403 ! include 'COMMON.TIME1'
407 real(kind=8) :: dnorm1,dnorm2,be
410 if (lprn) write (iout,'(/a)') 'Recalculated internal coordinates'
417 !write(iout,*)"geometry warring, vbld=",(vbld(i),i=1,nres+1)
419 vbld_inv(nres+1)=0.0d0
420 vbld_inv(2*nres)=0.0d0
423 #if defined(PARINT) && defined(MPI)
424 do i=iint_start,iint_end
431 c(j,nres2+2)=0.5D0*(2*c(j,i)+(c(j,i-1)-c(j,i))/dnorm1 &
432 +(c(j,i+1)-c(j,i))/dnorm2)
436 if (i.le.nres) phi(i+1)=beta(i-2,i-1,i,i+1)
437 if ((itype(i,1).ne.10).and.(itype(i-1,1).ne.10)) then
438 tauangle(3,i+1)=beta(i+nres-1,i-1,i,i+nres)
440 if (itype(i-1,1).ne.10) then
441 tauangle(1,i+1)=beta(i-1+nres,i-1,i,i+1)
442 omicron(1,i)=alpha(i-2,i-1,i-1+nres)
443 omicron(2,i)=alpha(i-1+nres,i-1,i)
445 if (itype(i,1).ne.10) then
446 tauangle(2,i+1)=beta(i-2,i-1,i,i+nres)
449 omeg(i)=beta(nres+i,i,nres2+2,i+1)
450 alph(i)=alpha(nres+i,i,nres2+2)
451 theta(i+1)=alpha(i-1,i,i+1)
453 vbld_inv(i)=1.0d0/vbld(i)
454 vbld(nres+i)=dist(nres+i,i)
455 if (itype(i,1).ne.10) then
456 vbld_inv(nres+i)=1.0d0/vbld(nres+i)
458 vbld_inv(nres+i)=0.0d0
461 #if defined(PARINT) && defined(MPI)
462 if (nfgtasks1.gt.1) then
463 !d write(iout,*) "iint_start",iint_start," iint_count",
464 !d & (iint_count(i),i=0,nfgtasks-1)," iint_displ",
465 !d & (iint_displ(i),i=0,nfgtasks-1)
466 !d write (iout,*) "Gather vbld backbone"
469 call MPI_Allgatherv(vbld(iint_start),iint_count(fg_rank1),&
470 MPI_DOUBLE_PRECISION,vbld(1),iint_count(0),iint_displ(0),&
471 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
472 !d write (iout,*) "Gather vbld_inv"
474 call MPI_Allgatherv(vbld_inv(iint_start),iint_count(fg_rank1),&
475 MPI_DOUBLE_PRECISION,vbld_inv(1),iint_count(0),iint_displ(0),&
476 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
477 !d write (iout,*) "Gather vbld side chain"
479 call MPI_Allgatherv(vbld(iint_start+nres),iint_count(fg_rank1),&
480 MPI_DOUBLE_PRECISION,vbld(nres+1),iint_count(0),iint_displ(0),&
481 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
482 !d write (iout,*) "Gather vbld_inv side chain"
484 call MPI_Allgatherv(vbld_inv(iint_start+nres),&
485 iint_count(fg_rank1),MPI_DOUBLE_PRECISION,vbld_inv(nres+1),&
486 iint_count(0),iint_displ(0),MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
487 !d write (iout,*) "Gather theta"
489 call MPI_Allgatherv(theta(iint_start+1),iint_count(fg_rank1),&
490 MPI_DOUBLE_PRECISION,theta(2),iint_count(0),iint_displ(0),&
491 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
492 !d write (iout,*) "Gather phi"
494 call MPI_Allgatherv(phi(iint_start+1),iint_count(fg_rank1),&
495 MPI_DOUBLE_PRECISION,phi(2),iint_count(0),iint_displ(0),&
496 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
498 !d write (iout,*) "Gather alph"
500 call MPI_Allgatherv(alph(iint_start),iint_count(fg_rank1),&
501 MPI_DOUBLE_PRECISION,alph(1),iint_count(0),iint_displ(0),&
502 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
503 !d write (iout,*) "Gather omeg"
505 call MPI_Allgatherv(omeg(iint_start),iint_count(fg_rank1),&
506 MPI_DOUBLE_PRECISION,omeg(1),iint_count(0),iint_displ(0),&
507 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
509 time_gather=time_gather+MPI_Wtime()-time00
515 #if defined(WHAM_RUN) || defined(CLUSTER)
516 dc(j,i)=c(j,i+1)-c(j,i)
518 dc_norm(j,i)=dc(j,i)*vbld_inv(i+1)
524 #if defined(WHAM_RUN) || defined(CLUSTER)
525 dc(j,i+nres)=c(j,i+nres)-c(j,i)
527 dc_norm(j,i+nres)=dc(j,i+nres)*vbld_inv(i+nres)
532 write (iout,1212) restyp(itype(i,1),1),i,vbld(i),&
533 rad2deg*theta(i),rad2deg*phi(i),vbld(nres+i),&
534 rad2deg*alph(i),rad2deg*omeg(i)
537 1212 format (a3,'(',i3,')',2(f15.10,2f10.2))
539 time_intfcart=time_intfcart+MPI_Wtime()-time01
542 end subroutine int_from_cart1
543 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
544 !-----------------------------------------------------------------------------
546 !-----------------------------------------------------------------------------
547 subroutine check_sc_distr
548 ! implicit real*8 (a-h,o-z)
549 ! include 'DIMENSIONS'
550 ! include 'COMMON.TIME1'
551 ! include 'COMMON.INTERACT'
552 ! include 'COMMON.NAMES'
553 ! include 'COMMON.GEO'
554 ! include 'COMMON.HEADER'
555 ! include 'COMMON.CONTROL'
557 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
558 real(kind=8) :: hrtime,mintime,sectime
559 integer,parameter :: MaxSample=10000000
560 real(kind=8),parameter :: delt=1.0D0/MaxSample
561 real(kind=8),dimension(0:72,0:90) :: prob
563 integer :: it,i,j,isample,indal,indom
564 real(kind=8) :: al,om,dV
565 dV=2.0D0*5.0D0*deg2rad*deg2rad
568 if (it.eq.10) goto 10
569 open (20,file=restyp(it,1)//'_distr.sdc',status='unknown')
570 call gen_side(it,90.0D0 * deg2rad,al,om,fail)
573 open (20,file=restyp(it,1)//'_distr1.sdc',status='unknown')
579 do isample=1,MaxSample
580 call gen_side(it,90.0D0 * deg2rad,al,om,fail)
582 indom=(rad2deg*om+180.0D0)/5
583 prob(indom,indal)=prob(indom,indal)+delt
587 write (20,'(2f10.3,1pd15.5)') 2*i+0.0D0,5*j-180.0D0,&
593 end subroutine check_sc_distr
595 !-----------------------------------------------------------------------------
597 !-----------------------------------------------------------------------------
598 subroutine geom_to_var(n,x)
600 ! Transfer the geometry parameters to the variable array.
601 ! The positions of variables are as follows:
602 ! 1. Virtual-bond torsional angles: 1 thru nres-3
603 ! 2. Virtual-bond valence angles: nres-2 thru 2*nres-5
604 ! 3. The polar angles alpha of local SC orientation: 2*nres-4 thru
606 ! 4. The torsional angles omega of SC orientation: 2*nres-4+nside+1
607 ! thru 2*nre-4+2*nside
609 ! implicit real*8 (a-h,o-z)
610 ! include 'DIMENSIONS'
611 ! include 'COMMON.VAR'
612 ! include 'COMMON.GEO'
613 ! include 'COMMON.CHAIN'
615 real(kind=8),dimension(n) :: x
616 !d print *,'nres',nres,' nphi',nphi,' ntheta',ntheta,' nvar',nvar
619 !d print *,i,i-3,phi(i)
621 if (n.eq.nphi) return
624 !d print *,i,i-2+nphi,theta(i)
626 if (n.eq.nphi+ntheta) return
628 if (ialph(i,1).gt.0) then
629 x(ialph(i,1))=alph(i)
630 x(ialph(i,1)+nside)=omeg(i)
631 !d print *,i,ialph(i,1),ialph(i,1)+nside,alph(i),omeg(i)
635 end subroutine geom_to_var
636 !-----------------------------------------------------------------------------
637 subroutine var_to_geom(n,x)
639 ! Update geometry parameters according to the variable array.
641 ! implicit real*8 (a-h,o-z)
642 ! include 'DIMENSIONS'
643 ! include 'COMMON.VAR'
644 ! include 'COMMON.CHAIN'
645 ! include 'COMMON.GEO'
646 ! include 'COMMON.IOUNITS'
648 real(kind=8),dimension(n) :: x
649 logical :: change !,reduce
656 if (n.gt.nphi+ntheta) then
659 alph(ii)=x(nphi+ntheta+i)
660 omeg(ii)=pinorm(x(nphi+ntheta+nside+i))
661 !elwrite(iout,*) "alph",ii,alph
662 !elwrite(iout,*) "omeg",ii,omeg
667 !elwrite(iout,*) "phi",i,phi
669 if (n.eq.nphi) return
672 !elwrite(iout,*) "theta",i,theta
673 if (theta(i).eq.pi) theta(i)=0.99d0*pi
677 end subroutine var_to_geom
678 !-----------------------------------------------------------------------------
679 logical function convert_side(alphi,omegi)
681 real(kind=8) :: alphi,omegi
682 !el real(kind=8) :: pinorm
683 ! include 'COMMON.GEO'
685 ! Apply periodicity restrictions.
686 if (alphi.gt.pi) then
688 omegi=pinorm(omegi+pi)
692 end function convert_side
693 !-----------------------------------------------------------------------------
694 logical function reduce(x)
696 ! Apply periodic restrictions to variables.
698 ! implicit real*8 (a-h,o-z)
699 ! include 'DIMENSIONS'
700 ! include 'COMMON.VAR'
701 ! include 'COMMON.CHAIN'
702 ! include 'COMMON.GEO'
703 logical :: zm,zmiana !,convert_side
704 real(kind=8),dimension(nvar) :: x
708 x(i-3)=pinorm(x(i-3))
710 if (nvar.gt.nphi+ntheta) then
714 x(ii)=thetnorm(x(ii))
715 x(iii)=pinorm(x(iii))
716 ! Apply periodic restrictions.
717 zm=convert_side(x(ii),x(iii))
721 if (nvar.eq.nphi) return
725 x(ii)=dmod(x(ii),dwapi)
726 ! Apply periodic restrictions.
727 if (x(ii).gt.pi) then
730 if (iii.gt.0) x(iii)=pinorm(x(iii)+pi)
731 if (i.lt.nres) x(iii+1)=pinorm(x(iii+1)+pi)
734 x(ii)=dmod(pi-x(ii),dwapi)
735 x(ii+nside)=pinorm(-x(ii+nside))
736 zm=convert_side(x(ii),x(ii+nside))
738 else if (x(ii).lt.-pi) then
743 x(ii)=dmod(pi-x(ii),dwapi)
744 x(ii+nside)=pinorm(-pi-x(ii+nside))
745 zm=convert_side(x(ii),x(ii+nside))
747 else if (x(ii).lt.0.0d0) then
750 if (iii.gt.0) x(iii)=pinorm(x(iii)+pi)
751 if (i.lt.nres) x(iii+1)=pinorm(x(iii+1)+pi)
754 x(ii+nside)=pinorm(-x(ii+nside))
755 zm=convert_side(x(ii),x(ii+nside))
762 !-----------------------------------------------------------------------------
763 real(kind=8) function thetnorm(x)
764 ! This function puts x within [0,2Pi].
767 ! include 'COMMON.GEO'
769 if (xx.lt.0.0d0) xx=xx+dwapi
770 if (xx.gt.0.9999d0*pi) xx=0.9999d0*pi
773 end function thetnorm
774 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
775 !-----------------------------------------------------------------------------
776 subroutine var_to_geom_restr(n,xx)
778 ! Update geometry parameters according to the variable array.
780 ! implicit real*8 (a-h,o-z)
781 ! include 'DIMENSIONS'
782 ! include 'COMMON.VAR'
783 ! include 'COMMON.CHAIN'
784 ! include 'COMMON.GEO'
785 ! include 'COMMON.IOUNITS'
787 real(kind=8),dimension(6*nres) :: x,xx !(maxvar) (maxvar=6*maxres)
788 logical :: change !,reduce
794 alph(ii)=x(nphi+ntheta+i)
795 omeg(ii)=pinorm(x(nphi+ntheta+nside+i))
802 if (theta(i).eq.pi) theta(i)=0.99d0*pi
806 end subroutine var_to_geom_restr
807 !-----------------------------------------------------------------------------
809 !-----------------------------------------------------------------------------
810 subroutine gen_rand_conf(nstart,*)
811 ! Generate random conformation or chain cut and regrowth.
813 ! implicit real*8 (a-h,o-z)
814 ! include 'DIMENSIONS'
815 ! include 'COMMON.CHAIN'
816 ! include 'COMMON.LOCAL'
817 ! include 'COMMON.VAR'
818 ! include 'COMMON.INTERACT'
819 ! include 'COMMON.IOUNITS'
820 ! include 'COMMON.MCM'
821 ! include 'COMMON.GEO'
822 ! include 'COMMON.CONTROL'
823 logical :: back,fail !overlap,
825 integer :: i,nstart,maxsi,nsi,maxnit,nit,niter
826 integer :: it1,it2,it,j
827 !d print *,' CG Processor',me,' maxgen=',maxgen
829 !d write (iout,*) 'Gen_Rand_conf: nstart=',nstart
830 if (nstart.lt.5) then
832 phi(4)=gen_phi(4,iabs(itype(2,1)),iabs(itype(3,1)))
833 ! write(iout,*)'phi(4)=',rad2deg*phi(4)
834 if (nstart.lt.3) theta(3)=gen_theta(iabs(itype(2,1)),pi,phi(4))
835 ! write(iout,*)'theta(3)=',rad2deg*theta(3)
839 do while (fail.and.nsi.le.maxsi)
840 call gen_side(it1,theta(3),alph(2),omeg(2),fail)
843 if (nsi.gt.maxsi) return 1
858 do while (i.le.nres .and. niter.lt.maxgen)
859 if (i.lt.nstart) then
861 write (iout,'(/80(1h*)/2a/80(1h*))') &
862 'Generation procedure went down to ',&
863 'chain beginning. Cannot continue...'
864 write (*,'(/80(1h*)/2a/80(1h*))') &
865 'Generation procedure went down to ',&
866 'chain beginning. Cannot continue...'
870 it1=iabs(itype(i-1,1))
871 it2=iabs(itype(i-2,1))
873 ! print *,'Gen_Rand_Conf: i=',i,' it=',it,' it1=',it1,' it2=',it2,
874 ! & ' nit=',nit,' niter=',niter,' maxgen=',maxgen
875 phi(i+1)=gen_phi(i+1,it1,it)
877 phi(i)=gen_phi(i+1,it2,it1)
878 ! print *,'phi(',i,')=',phi(i)
879 theta(i-1)=gen_theta(it2,phi(i-1),phi(i))
883 do while (fail.and.nsi.le.maxsi)
884 call gen_side(it2,theta(i-1),alph(i-2),omeg(i-2),fail)
887 if (nsi.gt.maxsi) return 1
889 call locate_next_res(i-1)
891 theta(i)=gen_theta(it1,phi(i),phi(i+1))
895 do while (fail.and.nsi.le.maxsi)
896 call gen_side(it1,theta(i),alph(i-1),omeg(i-1),fail)
899 if (nsi.gt.maxsi) return 1
901 call locate_next_res(i)
902 if (overlap(i-1)) then
903 if (nit.lt.maxnit) then
913 'Cannot generate non-overlaping conformation. Increase MAXNIT.'
915 'Cannot generate non-overlaping conformation. Increase MAXNIT.'
926 if (niter.ge.maxgen) then
927 write (iout,'(a,2i5)') &
928 'Too many trials in conformation generation',niter,maxgen
929 write (*,'(a,2i5)') &
930 'Too many trials in conformation generation',niter,maxgen
935 c(j,nres+nres)=c(j,nres)
938 end subroutine gen_rand_conf
939 !-----------------------------------------------------------------------------
940 logical function overlap(i)
941 ! implicit real*8 (a-h,o-z)
942 ! include 'DIMENSIONS'
943 ! include 'COMMON.CHAIN'
944 ! include 'COMMON.INTERACT'
945 ! include 'COMMON.FFIELD'
946 integer :: i,j,iti,itj,iteli,itelj,k
947 real(kind=8) :: redfac,rcomp
953 if (iti.gt.ntyp) return
954 ! Check for SC-SC overlaps.
955 !d print *,'nnt=',nnt,' nct=',nct
958 if (j.lt.i-1 .or. ipot.ne.4) then
959 rcomp=sigmaii(iti,itj)
964 if (dist(nres+i,nres+j).lt.redfac*rcomp) then
966 ! print *,'overlap, SC-SC: i=',i,' j=',j,
967 ! & ' dist=',dist(nres+i,nres+j),' rcomp=',
972 ! Check for overlaps between the added peptide group and the preceding
976 ! c(j,nres2+1)=0.5D0*(c(j,i)+c(j,i+1))
977 c(j,nres2+3)=0.5D0*(c(j,i)+c(j,i+1))
981 !d print *,'overlap, p-Sc: i=',i,' j=',j,
982 !d & ' dist=',dist(nres+j,maxres2+1)
983 if (dist(nres+j,nres2+3).lt.4.0D0*redfac) then
988 ! Check for overlaps between the added side chain and the preceding peptide
992 c(k,nres2+3)=0.5D0*(c(k,j)+c(k,j+1))
994 !d print *,'overlap, SC-p: i=',i,' j=',j,
995 !d & ' dist=',dist(nres+i,maxres2+1)
996 if (dist(nres+i,nres2+3).lt.4.0D0*redfac) then
1001 ! Check for p-p overlaps
1003 c(j,nres2+4)=0.5D0*(c(j,i)+c(j,i+1))
1008 c(k,nres2+4)=0.5D0*(c(k,j)+c(k,j+1))
1010 !d print *,'overlap, p-p: i=',i,' j=',j,
1011 !d & ' dist=',dist(maxres2+1,maxres2+2)
1012 if(iteli.ne.0.and.itelj.ne.0)then
1013 if (dist(nres2+3,nres2+4).lt.rpp(iteli,itelj)*redfac) then
1020 end function overlap
1021 !-----------------------------------------------------------------------------
1022 real(kind=8) function gen_phi(i,it1,it2)
1023 use random, only:ran_number
1024 ! implicit real*8 (a-h,o-z)
1025 ! include 'DIMENSIONS'
1026 ! include 'COMMON.GEO'
1027 ! include 'COMMON.BOUNDS'
1028 integer :: i,it1,it2
1029 ! gen_phi=ran_number(-pi,pi)
1030 ! 8/13/98 Generate phi using pre-defined boundaries
1031 gen_phi=ran_number(phibound(1,i),phibound(2,i))
1033 end function gen_phi
1034 !-----------------------------------------------------------------------------
1035 real(kind=8) function gen_theta(it,gama,gama1)
1036 use random,only:binorm
1037 ! implicit real*8 (a-h,o-z)
1038 ! include 'DIMENSIONS'
1039 ! include 'COMMON.LOCAL'
1040 ! include 'COMMON.GEO'
1041 real(kind=8),dimension(2) :: y,z
1042 real(kind=8) :: theta_max,theta_min,sig,ak
1045 real(kind=8) :: gama,gama1,thet_pred_mean,theta_temp
1046 ! print *,'gen_theta: it=',it
1049 if (dabs(gama).gt.dwapi) then
1056 if (dabs(gama1).gt.dwapi) then
1063 thet_pred_mean=a0thet(it)
1065 thet_pred_mean=thet_pred_mean+athet(k,it,1,1)*y(k) &
1066 +bthet(k,it,1,1)*z(k)
1070 sig=sig*thet_pred_mean+polthet(j,it)
1072 sig=0.5D0/(sig*sig+sigc0(it))
1073 ak=dexp(gthet(1,it)- &
1074 0.5D0*((gthet(2,it)-thet_pred_mean)/gthet(3,it))**2)
1075 ! print '(i5,5(1pe14.4))',it,(gthet(j,it),j=1,3)
1076 ! print '(5(1pe14.4))',thet_pred_mean,theta0(it),sig,sig0(it),ak
1077 theta_temp=binorm(thet_pred_mean,theta0(it),sig,sig0(it),ak)
1078 if (theta_temp.lt.theta_min) theta_temp=theta_min
1079 if (theta_temp.gt.theta_max) theta_temp=theta_max
1080 gen_theta=theta_temp
1081 ! print '(a)','Exiting GENTHETA.'
1083 end function gen_theta
1084 !-----------------------------------------------------------------------------
1085 subroutine gen_side(it,the,al,om,fail)
1086 use random, only:ran_number,mult_norm1
1087 ! implicit real*8 (a-h,o-z)
1088 ! include 'DIMENSIONS'
1089 ! include 'COMMON.GEO'
1090 ! include 'COMMON.LOCAL'
1091 ! include 'COMMON.SETUP'
1092 ! include 'COMMON.IOUNITS'
1093 real(kind=8) :: MaxBoxLen=10.0D0
1094 real(kind=8),dimension(3,3) :: Ap_inv,a,vec
1095 real(kind=8),dimension(:,:),allocatable :: z !(3,maxlob)
1096 real(kind=8),dimension(:),allocatable :: W1,detAp !(maxlob)
1097 real(kind=8),dimension(:),allocatable :: sumW !(0:maxlob)
1098 real(kind=8),dimension(2) :: y,cm,eig
1099 real(kind=8),dimension(2,2) :: box
1100 real(kind=8),dimension(100) :: work
1101 real(kind=8) :: eig_limit=1.0D-8
1102 real(kind=8) :: Big=10.0D0
1103 logical :: lprint,fail,lcheck
1105 integer :: it,i,j,k,l,nlobit,ial,iom,iii,ilob
1106 real(kind=8) :: the,al,om,detApi,wart,y2,wykl,radmax
1107 real(kind=8) :: tant,zz1,W1i,radius,zk,fac,dV,sum,sum1
1108 real(kind=8) :: which_lobe
1112 if (the.eq.0.0D0 .or. the.eq.pi) then
1114 write (*,'(a,i4,a,i3,a,1pe14.5)') &
1115 'CG Processor:',me,' Error in GenSide: it=',it,' theta=',the
1117 !d write (iout,'(a,i3,a,1pe14.5)')
1118 !d & 'Error in GenSide: it=',it,' theta=',the
1123 tant=dtan(the-pipol)
1125 allocate(z(3,nlobit))
1126 allocate(W1(nlobit))
1127 allocate(detAp(nlobit))
1128 allocate(sumW(0:nlobit))
1131 print '(a,i4,a)','CG Processor:',me,' Enter Gen_Side.'
1132 write (iout,'(a,i4,a)') 'Processor:',me,' Enter Gen_Side.'
1134 print *,'it=',it,' nlobit=',nlobit,' the=',the,' tant=',tant
1135 write (iout,*) 'it=',it,' nlobit=',nlobit,' the=',the,&
1139 zz1=tant-censc(1,i,it)
1142 a(k,l)=gaussc(k,l,i,it)
1145 detApi=a(2,2)*a(3,3)-a(2,3)**2
1146 Ap_inv(2,2)=a(3,3)/detApi
1147 Ap_inv(2,3)=-a(2,3)/detApi
1148 Ap_inv(3,2)=Ap_inv(2,3)
1149 Ap_inv(3,3)=a(2,2)/detApi
1151 write (*,'(/a,i2/)') 'Cluster #',i
1152 write (*,'(3(1pe14.5),5x,1pe14.5)') &
1153 ((a(l,k),l=1,3),censc(k,i,it),k=1,3)
1154 write (iout,'(/a,i2/)') 'Cluster #',i
1155 write (iout,'(3(1pe14.5),5x,1pe14.5)') &
1156 ((a(l,k),l=1,3),censc(k,i,it),k=1,3)
1161 W1i=W1i+a(k,1)*a(l,1)*Ap_inv(k,l)
1165 W1(i)=dexp(bsc(i,it)-0.5D0*W1i*zz1*zz1)
1166 ! if (lprint) write(*,'(a,3(1pe15.5)/)')
1167 ! & 'detAp, W1, anormi',detApi,W1i,anormi
1171 zk=zk+zz1*Ap_inv(k,l)*a(l,1)
1175 detAp(i)=dsqrt(detApi)
1179 print *,'W1:',(w1(i),i=1,nlobit)
1180 print *,'detAp:',(detAp(i),i=1,nlobit)
1183 print '(i2,3f10.5)',i,(rad2deg*z(j,i),j=2,3)
1185 write (iout,*) 'W1:',(w1(i),i=1,nlobit)
1186 write (iout,*) 'detAp:',(detAp(i),i=1,nlobit)
1189 write (iout,'(i2,3f10.5)') i,(rad2deg*z(j,i),j=2,3)
1193 ! Writing the distribution just to check the procedure
1195 dV=deg2rad**2*10.0D0
1199 fac=fac+W1(i)/detAp(i)
1201 fac=1.0D0/(2.0D0*fac*pi)
1202 !d print *,it,'fac=',fac
1211 a(j-1,k-1)=gaussc(j,k,i,it)
1223 wykl=wykl+a(j,k)*(y(j)-z(j+1,i))*(y(k)-z(k+1,i))
1226 wart=wart+W1(i)*dexp(-0.5D0*wykl)
1233 ! print *,'y',y(1),y(2),' fac=',fac
1235 write (20,'(2f10.3,1pd15.5)') y(1)*rad2deg,y(2)*rad2deg,wart
1240 ! print *,'it=',it,' sum=',sum*dV,' sum1=',sum1*dV
1244 ! Calculate the CM of the system
1247 W1(i)=W1(i)/detAp(i)
1251 sumW(i)=sumW(i-1)+W1(i)
1256 cm(1)=cm(1)+z(2,j)*W1(j)
1257 cm(2)=cm(2)+W1(j)*(z(3,1)+pinorm(z(3,j)-z(3,1)))
1259 cm(1)=cm(1)/sumW(nlobit)
1260 cm(2)=cm(2)/sumW(nlobit)
1261 if (cm(1).gt.Big .or. cm(1).lt.-Big .or. &
1262 cm(2).gt.Big .or. cm(2).lt.-Big) then
1263 !d write (iout,'(a)')
1264 !d & 'Unexpected error in GenSide - CM coordinates too large.'
1265 !d write (iout,'(i5,2(1pe14.5))') it,cm(1),cm(2)
1267 !d & 'Unexpected error in GenSide - CM coordinates too large.'
1268 !d write (*,'(i5,2(1pe14.5))') it,cm(1),cm(2)
1272 !d print *,'CM:',cm(1),cm(2)
1274 ! Find the largest search distance from CM
1280 a(j-1,k-1)=gaussc(j,k,i,it)
1284 call f02faf('N','U',2,a,3,eig,work,100,ifail)
1286 call djacob(2,3,10000,1.0d-10,a,vec,eig)
1290 print *,'*************** CG Processor',me
1291 print *,'CM:',cm(1),cm(2)
1292 write (iout,*) '*************** CG Processor',me
1293 write (iout,*) 'CM:',cm(1),cm(2)
1294 print '(A,8f10.5)','Eigenvalues: ',(1.0/dsqrt(eig(k)),k=1,2)
1295 write (iout,'(A,8f10.5)') &
1296 'Eigenvalues: ',(1.0/dsqrt(eig(k)),k=1,2)
1299 if (eig(1).lt.eig_limit) then
1301 'From Mult_Norm: Eigenvalues of A are too small.'
1303 'From Mult_Norm: Eigenvalues of A are too small.'
1310 radius=radius+pinorm(z(j+1,i)-cm(j))**2
1312 radius=dsqrt(radius)+3.0D0/dsqrt(eig(1))
1313 if (radius.gt.radmax) radmax=radius
1315 if (radmax.gt.pi) radmax=pi
1317 ! Determine the boundaries of the search rectangle.
1320 print '(a,4(1pe14.4))','W1: ',(W1(i),i=1,nlob(it) )
1321 print '(a,4(1pe14.4))','radmax: ',radmax
1323 box(1,1)=dmax1(cm(1)-radmax,0.0D0)
1324 box(2,1)=dmin1(cm(1)+radmax,pi)
1325 box(1,2)=cm(2)-radmax
1326 box(2,2)=cm(2)+radmax
1329 print *,'CG Processor',me,' Array BOX:'
1331 print *,'Array BOX:'
1333 print '(4(1pe14.4))',((box(k,j),k=1,2),j=1,2)
1334 print '(a,4(1pe14.4))','sumW: ',(sumW(i),i=0,nlob(it) )
1336 write (iout,*)'CG Processor',me,' Array BOX:'
1338 write (iout,*)'Array BOX:'
1340 write(iout,'(4(1pe14.4))') ((box(k,j),k=1,2),j=1,2)
1341 write(iout,'(a,4(1pe14.4))')'sumW: ',(sumW(i),i=0,nlob(it) )
1343 if (box(1,2).lt.-MaxBoxLen .or. box(2,2).gt.MaxBoxLen) then
1345 write (iout,'(a,i4,a,3e15.5)') 'CG Processor:',me,': bad sampling box.',box(1,2),box(2,2),radmax
1346 write (*,'(a,i4,a)') 'CG Processor:',me,': bad sampling box.'
1348 ! write (iout,'(a)') 'Bad sampling box.'
1353 which_lobe=ran_number(0.0D0,sumW(nlobit))
1354 ! print '(a,1pe14.4)','which_lobe=',which_lobe
1356 if (sumW(i-1).le.which_lobe .and. sumW(i).ge.which_lobe) goto 1
1359 ! print *,'ilob=',ilob,' nlob=',nlob(it)
1363 a(i-1,j-1)=gaussc(i,j,ilob,it)
1366 !d print '(a,i4,a)','CG Processor',me,' Calling MultNorm1.'
1367 call mult_norm1(3,2,a,cm,box,y,fail)
1371 !d print *,'al=',al,' om=',om
1374 end subroutine gen_side
1375 !-----------------------------------------------------------------------------
1376 subroutine overlap_sc(scfail)
1378 ! Internal and cartesian coordinates must be consistent as input,
1379 ! and will be up-to-date on return.
1380 ! At the end of this procedure, scfail is true if there are
1381 ! overlapping residues left, or false otherwise (success)
1383 ! implicit real*8 (a-h,o-z)
1384 ! include 'DIMENSIONS'
1385 ! include 'COMMON.CHAIN'
1386 ! include 'COMMON.INTERACT'
1387 ! include 'COMMON.FFIELD'
1388 ! include 'COMMON.VAR'
1389 ! include 'COMMON.SBRIDGE'
1390 ! include 'COMMON.IOUNITS'
1391 logical :: had_overlaps,fail,scfail
1392 integer,dimension(nres) :: ioverlap !(maxres)
1393 integer :: ioverlap_last,k,maxsi,i,iti,nsi
1396 had_overlaps=.false.
1397 call overlap_sc_list(ioverlap,ioverlap_last)
1398 if (ioverlap_last.gt.0) then
1399 write (iout,*) '#OVERLAPing residues ',ioverlap_last
1400 write (iout,'(20i4)') (ioverlap(k),k=1,ioverlap_last)
1406 if (ioverlap_last.eq.0) exit
1408 do ires=1,ioverlap_last
1410 iti=iabs(itype(i,1))
1414 do while (fail.and.nsi.le.maxsi)
1415 call gen_side(iti,theta(i+1),alph(i),omeg(i),fail)
1423 call overlap_sc_list(ioverlap,ioverlap_last)
1424 ! write (iout,*) 'Overlaping residues ',ioverlap_last,
1425 ! & (ioverlap(j),j=1,ioverlap_last)
1428 if (k.le.1000.and.ioverlap_last.eq.0) then
1430 if (had_overlaps) then
1431 write (iout,*) '#OVERLAPing all corrected after ',k,&
1432 ' random generation'
1436 write (iout,*) '#OVERLAPing NOT all corrected ',ioverlap_last
1437 write (iout,'(20i4)') (ioverlap(j),j=1,ioverlap_last)
1443 write (iout,'(a30,i5,a12,i4)') &
1444 '#OVERLAP FAIL in gen_side after',maxsi,&
1448 end subroutine overlap_sc
1449 !-----------------------------------------------------------------------------
1450 subroutine overlap_sc_list(ioverlap,ioverlap_last)
1452 ! implicit real*8 (a-h,o-z)
1453 ! include 'DIMENSIONS'
1454 ! include 'COMMON.GEO'
1455 ! include 'COMMON.LOCAL'
1456 ! include 'COMMON.IOUNITS'
1457 ! include 'COMMON.CHAIN'
1458 ! include 'COMMON.INTERACT'
1459 ! include 'COMMON.FFIELD'
1460 ! include 'COMMON.VAR'
1461 ! include 'COMMON.CALC'
1463 integer,dimension(nres) :: ioverlap !(maxres)
1464 integer :: ioverlap_last
1467 real(kind=8) :: redfac,sig !rrij,sigsq,
1468 integer :: itypi,itypj,itypi1
1469 real(kind=8) :: xi,yi,zi,sig0ij,rcomp,rrij,rij_shift
1473 ! Check for SC-SC overlaps and mark residues
1474 ! print *,'>>overlap_sc nnt=',nnt,' nct=',nct
1476 do i=iatsc_s,iatsc_e
1477 itypi=iabs(itype(i,1))
1478 itypi1=iabs(itype(i+1,1))
1482 dxi=dc_norm(1,nres+i)
1483 dyi=dc_norm(2,nres+i)
1484 dzi=dc_norm(3,nres+i)
1485 dsci_inv=dsc_inv(itypi)
1487 do iint=1,nint_gr(i)
1488 do j=istart(i,iint),iend(i,iint)
1490 itypj=iabs(itype(j,1))
1491 dscj_inv=dsc_inv(itypj)
1492 sig0ij=sigma(itypi,itypj)
1493 chi1=chi(itypi,itypj)
1494 chi2=chi(itypj,itypi)
1501 alf12=0.5D0*(alf1+alf2)
1503 rcomp=sigmaii(itypi,itypj)
1505 rcomp=sigma(itypi,itypj)
1507 ! print '(2(a3,2i3),a3,2f10.5)',
1508 ! & ' i=',i,iti,' j=',j,itj,' d=',dist(nres+i,nres+j)
1513 dxj=dc_norm(1,nres+j)
1514 dyj=dc_norm(2,nres+j)
1515 dzj=dc_norm(3,nres+j)
1516 rrij=1.0D0/(xj*xj+yj*yj+zj*zj)
1520 sig=sig0ij*dsqrt(sigsq)
1521 rij_shift=1.0D0/rij-sig+sig0ij
1523 !t if ( 1.0/rij .lt. redfac*rcomp .or.
1524 !t & rij_shift.le.0.0D0 ) then
1525 if ( rij_shift.le.0.0D0 ) then
1526 !d write (iout,'(a,i3,a,i3,a,f10.5,a,3f10.5)')
1527 !d & 'overlap SC-SC: i=',i,' j=',j,
1528 !d & ' dist=',dist(nres+i,nres+j),' rcomp=',
1529 !d & rcomp,1.0/rij,rij_shift
1530 ioverlap_last=ioverlap_last+1
1531 ioverlap(ioverlap_last)=i
1532 do k=1,ioverlap_last-1
1533 if (ioverlap(k).eq.i) ioverlap_last=ioverlap_last-1
1535 ioverlap_last=ioverlap_last+1
1536 ioverlap(ioverlap_last)=j
1537 do k=1,ioverlap_last-1
1538 if (ioverlap(k).eq.j) ioverlap_last=ioverlap_last-1
1545 end subroutine overlap_sc_list
1547 !-----------------------------------------------------------------------------
1548 ! energy_p_new_barrier.F
1549 !-----------------------------------------------------------------------------
1550 subroutine sc_angular
1551 ! Calculate eps1,eps2,eps3,sigma, and parts of their derivatives in om1,om2,
1552 ! om12. Called by ebp, egb, and egbv.
1555 ! include 'COMMON.CALC'
1556 ! include 'COMMON.IOUNITS'
1560 om1=dxi*erij(1)+dyi*erij(2)+dzi*erij(3)
1561 om2=dxj*erij(1)+dyj*erij(2)+dzj*erij(3)
1562 om12=dxi*dxj+dyi*dyj+dzi*dzj
1564 ! Calculate eps1(om12) and its derivative in om12
1565 faceps1=1.0D0-om12*chiom12
1566 faceps1_inv=1.0D0/faceps1
1567 eps1=dsqrt(faceps1_inv)
1568 ! Following variable is eps1*deps1/dom12
1569 eps1_om12=faceps1_inv*chiom12
1574 ! write (iout,*) "om12",om12," eps1",eps1
1575 ! Calculate sigma(om1,om2,om12) and the derivatives of sigma**2 in om1,om2,
1580 facsig=om1*chiom1+om2*chiom2-2.0D0*om1om2*chiom12
1581 sigsq=1.0D0-facsig*faceps1_inv
1582 sigsq_om1=(chiom1-chiom12*om2)*faceps1_inv
1583 sigsq_om2=(chiom2-chiom12*om1)*faceps1_inv
1584 sigsq_om12=-chi12*(om1om2*faceps1-om12*facsig)*faceps1_inv**2
1590 ! write (iout,*) "chiom1",chiom1," chiom2",chiom2," chiom12",chiom12
1591 ! write (iout,*) "faceps1",faceps1," faceps1_inv",faceps1_inv,
1593 ! Calculate eps2 and its derivatives in om1, om2, and om12.
1596 chipom12=chip12*om12
1597 facp=1.0D0-om12*chipom12
1599 facp1=om1*chipom1+om2*chipom2-2.0D0*om1om2*chipom12
1600 ! write (iout,*) "chipom1",chipom1," chipom2",chipom2,
1601 ! & " chipom12",chipom12," facp",facp," facp_inv",facp_inv
1602 ! Following variable is the square root of eps2
1603 eps2rt=1.0D0-facp1*facp_inv
1604 ! Following three variables are the derivatives of the square root of eps
1605 ! in om1, om2, and om12.
1606 eps2rt_om1=-4.0D0*(chipom1-chipom12*om2)*facp_inv
1607 eps2rt_om2=-4.0D0*(chipom2-chipom12*om1)*facp_inv
1608 eps2rt_om12=4.0D0*chip12*(om1om2*facp-om12*facp1)*facp_inv**2
1609 ! Evaluate the "asymmetric" factor in the VDW constant, eps3
1610 eps3rt=1.0D0-alf1*om1+alf2*om2-alf12*om12
1611 ! write (iout,*) "eps2rt",eps2rt," eps3rt",eps3rt
1612 ! write (iout,*) "eps2rt_om1",eps2rt_om1," eps2rt_om2",eps2rt_om2,
1613 ! & " eps2rt_om12",eps2rt_om12
1614 ! Calculate whole angle-dependent part of epsilon and contributions
1615 ! to its derivatives
1617 end subroutine sc_angular
1618 !-----------------------------------------------------------------------------
1620 subroutine sc_angular_nucl
1621 ! Calculate eps1,eps2,eps3,sigma, and parts of their derivatives in om1,om2,
1622 ! om12. Called by ebp, egb, and egbv.
1625 ! include 'COMMON.CALC'
1626 ! include 'COMMON.IOUNITS'
1632 om1=dxi*erij(1)+dyi*erij(2)+dzi*erij(3)
1633 om2=dxj*erij(1)+dyj*erij(2)+dzj*erij(3)
1634 om12=dxi*dxj+dyi*dyj+dzi*dzj
1636 ! Calculate eps1(om12) and its derivative in om12
1637 faceps1=1.0D0-om12*chiom12
1638 faceps1_inv=1.0D0/faceps1
1639 eps1=dsqrt(faceps1_inv)
1640 ! Following variable is eps1*deps1/dom12
1641 eps1_om12=faceps1_inv*chiom12
1646 ! write (iout,*) "om12",om12," eps1",eps1
1647 ! Calculate sigma(om1,om2,om12) and the derivatives of sigma**2 in om1,om2,
1652 facsig=om1*chiom1+om2*chiom2-2.0D0*om1om2*chiom12
1653 sigsq=1.0D0-facsig*faceps1_inv
1654 sigsq_om1=(chiom1-chiom12*om2)*faceps1_inv
1655 sigsq_om2=(chiom2-chiom12*om1)*faceps1_inv
1656 sigsq_om12=-chi12*(om1om2*faceps1-om12*facsig)*faceps1_inv**2
1659 chipom12=chip12*om12
1660 facp=1.0D0-om12*chipom12
1662 facp1=om1*chipom1+om2*chipom2-2.0D0*om1om2*chipom12
1663 ! write (iout,*) "chipom1",chipom1," chipom2",chipom2,
1664 ! & " chipom12",chipom12," facp",facp," facp_inv",facp_inv
1665 ! Following variable is the square root of eps2
1666 eps2rt=1.0D0-facp1*facp_inv
1667 ! Following three variables are the derivatives of the square root of eps
1668 ! in om1, om2, and om12.
1669 eps2rt_om1=-4.0D0*(chipom1-chipom12*om2)*facp_inv
1670 eps2rt_om2=-4.0D0*(chipom2-chipom12*om1)*facp_inv
1671 eps2rt_om12=4.0D0*chip12*(om1om2*facp-om12*facp1)*facp_inv**2
1672 ! Evaluate the "asymmetric" factor in the VDW constant, eps3
1673 eps3rt=1.0D0-alf1*om1+alf2*om2-alf12*om12
1674 ! write (iout,*) "eps2rt",eps2rt," eps3rt",eps3rt
1675 ! write (iout,*) "eps2rt_om1",eps2rt_om1," eps2rt_om2",eps2rt_om2,
1676 ! & " eps2rt_om12",eps2rt_om12
1677 ! Calculate whole angle-dependent part of epsilon and contributions
1678 ! to its derivatives
1680 end subroutine sc_angular_nucl
1682 !-----------------------------------------------------------------------------
1683 subroutine int_bounds(total_ints,lower_bound,upper_bound)
1684 ! implicit real*8 (a-h,o-z)
1685 ! include 'DIMENSIONS'
1687 ! include 'COMMON.SETUP'
1688 integer :: total_ints,lower_bound,upper_bound,nint
1689 integer,dimension(0:nfgtasks) :: int4proc,sint4proc !(0:max_fg_procs)
1690 integer :: i,nexcess
1691 nint=total_ints/nfgtasks
1695 nexcess=total_ints-nint*nfgtasks
1697 int4proc(nfgtasks-i)=int4proc(nfgtasks-i)+1
1701 lower_bound=lower_bound+int4proc(i)
1703 upper_bound=lower_bound+int4proc(fg_rank)
1704 lower_bound=lower_bound+1
1706 end subroutine int_bounds
1707 !-----------------------------------------------------------------------------
1708 subroutine int_bounds1(total_ints,lower_bound,upper_bound)
1709 ! implicit real*8 (a-h,o-z)
1710 ! include 'DIMENSIONS'
1712 ! include 'COMMON.SETUP'
1713 integer :: total_ints,lower_bound,upper_bound,nint
1714 integer :: nexcess,i
1715 integer,dimension(0:nfgtasks) :: int4proc,sint4proc !(0:max_fg_procs)
1716 nint=total_ints/nfgtasks1
1720 nexcess=total_ints-nint*nfgtasks1
1722 int4proc(nfgtasks1-i)=int4proc(nfgtasks1-i)+1
1726 lower_bound=lower_bound+int4proc(i)
1728 upper_bound=lower_bound+int4proc(fg_rank1)
1729 lower_bound=lower_bound+1
1731 end subroutine int_bounds1
1732 !-----------------------------------------------------------------------------
1734 !-----------------------------------------------------------------------------
1735 subroutine chainbuild_cart
1736 ! implicit real*8 (a-h,o-z)
1737 ! include 'DIMENSIONS'
1742 ! include 'COMMON.SETUP'
1743 ! include 'COMMON.CHAIN'
1744 ! include 'COMMON.LOCAL'
1745 ! include 'COMMON.TIME1'
1746 ! include 'COMMON.IOUNITS'
1747 integer :: j,i,ierror,ierr
1748 real(kind=8) :: time00,time01
1750 if (nfgtasks.gt.1) then
1751 ! write (iout,*) "BCAST in chainbuild_cart"
1753 ! Broadcast the order to build the chain and compute internal coordinates
1754 ! to the slaves. The slaves receive the order in ERGASTULUM.
1756 ! write (iout,*) "CHAINBUILD_CART: DC before BCAST"
1758 ! write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),
1759 ! & (dc(j,i+nres),j=1,3)
1762 call MPI_Bcast(7,1,MPI_INTEGER,king,FG_COMM,IERROR)
1763 time_bcast7=time_bcast7+MPI_Wtime()-time00
1765 call MPI_Bcast(dc(1,0),6*(nres+1),MPI_DOUBLE_PRECISION,&
1767 ! write (iout,*) "CHAINBUILD_CART: DC after BCAST"
1769 ! write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),
1770 ! & (dc(j,i+nres),j=1,3)
1772 ! write (iout,*) "End BCAST in chainbuild_cart"
1774 time_bcast=time_bcast+MPI_Wtime()-time00
1775 time_bcastc=time_bcastc+MPI_Wtime()-time01
1783 c(j,i)=c(j,i-1)+dc(j,i-1)
1788 c(j,i+nres)=c(j,i)+dc(j,i+nres)
1791 ! write (iout,*) "CHAINBUILD_CART"
1793 call int_from_cart1(.false.)
1795 end subroutine chainbuild_cart
1796 !-----------------------------------------------------------------------------
1798 !-----------------------------------------------------------------------------
1799 real(kind=8) function alpha(i1,i2,i3)
1801 ! Calculates the planar angle between atoms (i1), (i2), and (i3).
1803 ! implicit real*8 (a-h,o-z)
1804 ! include 'DIMENSIONS'
1805 ! include 'COMMON.GEO'
1806 ! include 'COMMON.CHAIN'
1809 real(kind=8) :: x12,x23,y12,y23,z12,z23,vnorm,wnorm,scalar
1816 vnorm=dsqrt(x12*x12+y12*y12+z12*z12)
1817 wnorm=dsqrt(x23*x23+y23*y23+z23*z23)
1818 scalar=(x12*x23+y12*y23+z12*z23)/(vnorm*wnorm)
1822 !-----------------------------------------------------------------------------
1823 real(kind=8) function beta(i1,i2,i3,i4)
1825 ! Calculates the dihedral angle between atoms (i1), (i2), (i3) and (i4)
1827 ! implicit real*8 (a-h,o-z)
1828 ! include 'DIMENSIONS'
1829 ! include 'COMMON.GEO'
1830 ! include 'COMMON.CHAIN'
1832 integer :: i1,i2,i3,i4
1833 real(kind=8) :: x12,x23,x34,y12,y23,y34,z12,z23,z34
1834 real(kind=8) :: wx,wy,wz,wnorm,vx,vy,vz,vnorm,scalar,angle
1835 real(kind=8) :: tx,ty,tz
1845 !d print '(2i3,3f10.5)',i1,i2,x12,y12,z12
1846 !d print '(2i3,3f10.5)',i2,i3,x23,y23,z23
1847 !d print '(2i3,3f10.5)',i3,i4,x34,y34,z34
1851 wnorm=dsqrt(wx*wx+wy*wy+wz*wz)
1855 vnorm=dsqrt(vx*vx+vy*vy+vz*vz)
1856 if (vnorm.gt.1.0D-13 .and. wnorm.gt.1.0D-13) then
1857 scalar=(vx*wx+vy*wy+vz*wz)/(vnorm*wnorm)
1858 if (dabs(scalar).gt.1.0D0) &
1859 scalar=0.99999999999999D0*scalar/dabs(scalar)
1861 !d print '(2i4,10f7.3)',i2,i3,vx,vy,vz,wx,wy,wz,vnorm,wnorm,
1866 ! if (angle.le.0.0D0) angle=pi+angle
1870 scalar=tx*x23+ty*y23+tz*z23
1871 if (scalar.lt.0.0D0) angle=-angle
1875 !-----------------------------------------------------------------------------
1876 real(kind=8) function dist(i1,i2)
1878 ! Calculates the distance between atoms (i1) and (i2).
1880 ! implicit real*8 (a-h,o-z)
1881 ! include 'DIMENSIONS'
1882 ! include 'COMMON.GEO'
1883 ! include 'COMMON.CHAIN'
1886 real(kind=8) :: x12,y12,z12
1890 dist=dsqrt(x12*x12+y12*y12+z12*z12)
1893 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
1894 !-----------------------------------------------------------------------------
1896 !-----------------------------------------------------------------------------
1897 subroutine local_move_init(debug)
1901 ! implicit real*8 (a-h,o-z)
1902 ! include 'DIMENSIONS' ! Needed by COMMON.LOCAL
1903 ! include 'COMMON.GEO' ! For pi, deg2rad
1904 ! include 'COMMON.LOCAL' ! For vbl
1905 ! include 'COMMON.LOCMOVE'
1911 ! Determine wheter to do some debugging output
1912 locmove_output=debug
1914 ! Set the init_called flag to 1
1917 ! The following are never changed
1918 min_theta=60.D0*deg2rad ! (0,PI)
1919 max_theta=175.D0*deg2rad ! (0,PI)
1920 dmin2=vbl*vbl*2.*(1.-cos(min_theta))
1921 dmax2=vbl*vbl*2.*(1.-cos(max_theta))
1924 small2=0.5*small*small
1926 ! Not really necessary...
1932 end subroutine local_move_init
1933 !-----------------------------------------------------------------------------
1934 subroutine local_move(n_start, n_end, PHImin, PHImax)
1935 ! Perform a local move between residues m and n (inclusive)
1936 ! PHImin and PHImax [0,PI] determine the size of the move
1937 ! Works on whatever structure is in the variables theta and phi,
1938 ! sidechain variables are left untouched
1939 ! The final structure is NOT minimized, but both the cartesian
1940 ! variables c and the angles are up-to-date at the end (no further
1941 ! chainbuild is required)
1943 use random,only:ran_number
1945 ! implicit real*8 (a-h,o-z)
1946 ! include 'DIMENSIONS'
1947 ! include 'COMMON.GEO'
1948 ! include 'COMMON.CHAIN'
1949 ! include 'COMMON.VAR'
1950 ! include 'COMMON.MINIM'
1951 ! include 'COMMON.SBRIDGE'
1952 ! include 'COMMON.LOCMOVE'
1954 ! External functions
1955 !EL integer move_res
1956 !EL external move_res
1957 !EL double precision ran_number
1958 !EL external ran_number
1961 integer :: n_start, n_end ! First and last residues to move
1962 real(kind=8) :: PHImin, PHImax ! min/max angles [0,PI]
1966 real(kind=8) :: min,max
1970 ! Check if local_move_init was called. This assumes that it
1971 ! would not be 1 if not explicitely initialized
1972 if (init_called.ne.1) then
1973 write(6,*)' *** local_move_init not called!!!'
1977 ! Quick check for crazy range
1978 if (n_start.gt.n_end .or. n_start.lt.1 .or. n_end.gt.nres) then
1979 write(6,'(a,i3,a,i3)') &
1980 ' *** Cannot make local move between n_start = ',&
1981 n_start,' and n_end = ',n_end
1985 ! Take care of end residues first...
1986 if (n_start.eq.1) then
1987 ! Move residue 1 (completely random)
1988 theta(3)=ran_number(min_theta,max_theta)
1989 phi(4)=ran_number(-PI,PI)
1994 if (n_end.eq.nres) then
1995 ! Move residue nres (completely random)
1996 theta(nres)=ran_number(min_theta,max_theta)
1997 phi(nres)=ran_number(-PI,PI)
2003 ! ...then go through all other residues one by one
2004 ! Start from the two extremes and converge
2009 !$$$c Move the first two residues by less than the others
2010 !$$$ if (i-n_start.lt.3) then
2011 !$$$ if (i-n_start.eq.0) then
2014 !$$$ else if (i-n_start.eq.1) then
2017 !$$$ else if (i-n_start.eq.2) then
2023 ! The actual move, on residue i
2024 iretcode=move_res(min,max,i) ! Discard iretcode
2030 !$$$c Move the last two residues by less than the others
2031 !$$$ if (n_end-j.lt.3) then
2032 !$$$ if (n_end-j.eq.0) then
2035 !$$$ else if (n_end-j.eq.1) then
2038 !$$$ else if (n_end-j.eq.2) then
2044 ! The actual move, on residue j
2045 iretcode=move_res(min,max,j) ! Discard iretcode
2050 call int_from_cart(.false.,.false.)
2053 end subroutine local_move
2054 !-----------------------------------------------------------------------------
2055 subroutine output_tabs
2056 ! Prints out the contents of a_..., b_..., res_...
2060 ! include 'COMMON.GEO'
2061 ! include 'COMMON.LOCMOVE'
2067 write(6,'(8f7.1)')(a_ang(i)*rad2deg,i=0,a_n-1)
2068 write(6,'(8(2x,3l1,2x))')((a_tab(i,j),i=0,2),j=0,a_n-1)
2071 write(6,'(4f7.1)')(b_ang(i)*rad2deg,i=0,b_n-1)
2072 write(6,'(4(2x,3l1,2x))')((b_tab(i,j),i=0,2),j=0,b_n-1)
2075 write(6,'(12f7.1)')(res_ang(i)*rad2deg,i=0,res_n-1)
2076 write(6,'(12(2x,3l1,2x))')((res_tab(0,i,j),i=0,2),j=0,res_n-1)
2077 write(6,'(12(2x,3l1,2x))')((res_tab(1,i,j),i=0,2),j=0,res_n-1)
2078 write(6,'(12(2x,3l1,2x))')((res_tab(2,i,j),i=0,2),j=0,res_n-1)
2081 end subroutine output_tabs
2082 !-----------------------------------------------------------------------------
2083 subroutine angles2tab(PHImin,PHImax,n,ang,tab)
2084 ! Only uses angles if [0,PI] (but PHImin cannot be 0.,
2085 ! and PHImax cannot be PI)
2089 ! include 'COMMON.GEO'
2092 real(kind=8) :: PHImin,PHImax
2096 real(kind=8),dimension(0:3) :: ang
2097 logical,dimension(0:2,0:3) :: tab
2100 if (PHImin .eq. PHImax) then
2101 ! Special case with two 010's
2111 else if (PHImin .eq. PI) then
2112 ! Special case with one 010
2118 else if (PHImax .eq. 0.) then
2119 ! Special case with one 010
2128 if (PHImin .gt. 0.) then
2129 ! Start of range (011)
2134 ! End of range (110)
2138 tab(2,n+1) = .false.
2141 if (PHImax .lt. PI) then
2142 ! Start of range (011)
2147 ! End of range (110)
2151 tab(2,n+1) = .false.
2157 end subroutine angles2tab
2158 !-----------------------------------------------------------------------------
2159 subroutine minmax_angles(x,y,z,r,n,ang,tab)
2160 ! When solutions do not exist, assume all angles
2161 ! are acceptable - i.e., initial geometry must be correct
2165 ! include 'COMMON.GEO'
2166 ! include 'COMMON.LOCMOVE'
2169 real(kind=8) :: x,y,z,r
2173 real(kind=8),dimension(0:3) :: ang
2174 logical,dimension(0:2,0:3) :: tab
2177 real(kind=8) :: num, denom, phi
2178 real(kind=8) :: Kmin, Kmax
2182 num = x*x + y*y + z*z
2185 if (denom .gt. 0.) then
2187 denom = 2.*r*sqrt(denom)
2189 Kmin = (num - dmin2)/denom
2190 Kmax = (num - dmax2)/denom
2192 ! Allowed values of K (else all angles are acceptable)
2195 if (Kmin .gt. 1. .or. abs(Kmin-1.) .lt. small2) then
2197 else if (Kmin .lt. -1. .or. abs(Kmin+1.) .lt. small2) then
2203 if (Kmax .lt. -1. .or. abs(Kmax+1.) .lt. small2) then
2205 else if (Kmax .gt. 1. .or. abs(Kmax-1.) .lt. small2) then
2211 if (Kmax .lt. Kmin) Kmax = Kmin
2213 call angles2tab(Kmin, Kmax, n, ang, tab)
2215 ! Add phi and check that angles are within range (-PI,PI]
2218 if (ang(i) .le. -PI) then
2219 ang(i) = ang(i)+2.*PI
2220 else if (ang(i) .gt. PI) then
2221 ang(i) = ang(i)-2.*PI
2227 end subroutine minmax_angles
2228 !-----------------------------------------------------------------------------
2229 subroutine construct_tab
2230 ! Take a_... and b_... values and produces the results res_...
2231 ! x_ang are assumed to be all different (diff > small)
2232 ! x_tab(1,i) must be 1 for all i (i.e., all x_ang are acceptable)
2236 ! include 'COMMON.LOCMOVE'
2239 integer :: n_max,i,j,index
2245 if (n_max .eq. 0) then
2252 res_tab(j,0,i) = .true.
2253 res_tab(j,2,i) = .true.
2254 res_tab(j,1,i) = .false.
2261 do while (.not.done)
2262 res_ang(index) = flag
2266 if ((a_ang(i)-phi).gt.small .and. &
2267 a_ang(i) .lt. res_ang(index)) then
2268 ! Found a lower angle
2269 res_ang(index) = a_ang(i)
2270 ! Copy the values from a_tab into res_tab(0,,)
2271 res_tab(0,0,index) = a_tab(0,i)
2272 res_tab(0,1,index) = a_tab(1,i)
2273 res_tab(0,2,index) = a_tab(2,i)
2274 ! Set default values for res_tab(1,,)
2275 res_tab(1,0,index) = .true.
2276 res_tab(1,1,index) = .false.
2277 res_tab(1,2,index) = .true.
2278 else if (abs(a_ang(i)-res_ang(index)).lt.small) then
2279 ! Found an equal angle (can only be equal to a b_ang)
2280 res_tab(0,0,index) = a_tab(0,i)
2281 res_tab(0,1,index) = a_tab(1,i)
2282 res_tab(0,2,index) = a_tab(2,i)
2287 if ((b_ang(i)-phi).gt.small .and. &
2288 b_ang(i) .lt. res_ang(index)) then
2289 ! Found a lower angle
2290 res_ang(index) = b_ang(i)
2291 ! Copy the values from b_tab into res_tab(1,,)
2292 res_tab(1,0,index) = b_tab(0,i)
2293 res_tab(1,1,index) = b_tab(1,i)
2294 res_tab(1,2,index) = b_tab(2,i)
2295 ! Set default values for res_tab(0,,)
2296 res_tab(0,0,index) = .true.
2297 res_tab(0,1,index) = .false.
2298 res_tab(0,2,index) = .true.
2299 else if (abs(b_ang(i)-res_ang(index)).lt.small) then
2300 ! Found an equal angle (can only be equal to an a_ang)
2301 res_tab(1,0,index) = b_tab(0,i)
2302 res_tab(1,1,index) = b_tab(1,i)
2303 res_tab(1,2,index) = b_tab(2,i)
2307 if (res_ang(index) .eq. flag) then
2310 else if (index .eq. n_max-1) then
2314 phi = res_ang(index) ! Store previous angle
2322 if (a_n .gt. 0) then
2323 do while (.not.res_tab(0,1,index))
2326 done = res_tab(0,2,index)
2327 do i=index+1,res_n-1
2328 if (res_tab(0,1,i)) then
2329 done = res_tab(0,2,i)
2331 res_tab(0,0,i) = done
2332 res_tab(0,1,i) = done
2333 res_tab(0,2,i) = done
2336 done = res_tab(0,0,index)
2338 if (res_tab(0,1,i)) then
2339 done = res_tab(0,0,i)
2341 res_tab(0,0,i) = done
2342 res_tab(0,1,i) = done
2343 res_tab(0,2,i) = done
2348 res_tab(0,0,i) = .true.
2349 res_tab(0,1,i) = .true.
2350 res_tab(0,2,i) = .true.
2355 if (b_n .gt. 0) then
2356 do while (.not.res_tab(1,1,index))
2359 done = res_tab(1,2,index)
2360 do i=index+1,res_n-1
2361 if (res_tab(1,1,i)) then
2362 done = res_tab(1,2,i)
2364 res_tab(1,0,i) = done
2365 res_tab(1,1,i) = done
2366 res_tab(1,2,i) = done
2369 done = res_tab(1,0,index)
2371 if (res_tab(1,1,i)) then
2372 done = res_tab(1,0,i)
2374 res_tab(1,0,i) = done
2375 res_tab(1,1,i) = done
2376 res_tab(1,2,i) = done
2381 res_tab(1,0,i) = .true.
2382 res_tab(1,1,i) = .true.
2383 res_tab(1,2,i) = .true.
2387 ! Finally fill the last row with AND operation
2390 res_tab(2,j,i) = (res_tab(0,j,i) .and. res_tab(1,j,i))
2395 end subroutine construct_tab
2396 !-----------------------------------------------------------------------------
2397 subroutine construct_ranges(phi_n,phi_start,phi_end)
2398 ! Given the data in res_..., construct a table of
2399 ! min/max allowed angles
2403 ! include 'COMMON.GEO'
2404 ! include 'COMMON.LOCMOVE'
2408 real(kind=8),dimension(0:11) :: phi_start,phi_end
2415 if (res_n .eq. 0) then
2416 ! Any move is allowed
2424 do while (.not.done)
2425 ! Find start of range (01x)
2427 do while (.not.done)
2428 if (res_tab(2,0,index).or.(.not.res_tab(2,1,index))) then
2432 phi_start(phi_n) = res_ang(index)
2434 if (index .eq. res_n) done = .true.
2436 ! If a start was found (index < res_n), find the end of range (x10)
2437 ! It may not be found without wrapping around
2438 if (index .lt. res_n) then
2440 do while (.not.done)
2441 if ((.not.res_tab(2,1,index)).or.res_tab(2,2,index)) then
2446 if (index .eq. res_n) done = .true.
2448 if (index .lt. res_n) then
2449 ! Found the end of the range
2450 phi_end(phi_n) = res_ang(index)
2453 if (index .eq. res_n) then
2459 ! Need to wrap around
2461 phi_end(phi_n) = flag
2465 ! Take care of the last one if need to wrap around
2466 if (phi_end(phi_n) .eq. flag) then
2468 do while ((.not.res_tab(2,1,index)).or.res_tab(2,2,index))
2471 phi_end(phi_n) = res_ang(index) + 2.*PI
2477 end subroutine construct_ranges
2478 !-----------------------------------------------------------------------------
2479 subroutine fix_no_moves(phi)
2483 ! include 'COMMON.GEO'
2484 ! include 'COMMON.LOCMOVE'
2491 real(kind=8) :: diff,temp
2494 ! Look for first 01x in gammas (there MUST be at least one)
2497 do while (res_tab(1,0,index) .or. (.not.res_tab(1,1,index)))
2500 if (res_ang(index) .le. 0.D0) then ! Make sure it's from PHImax
2501 ! Try to increase PHImax
2502 if (index .gt. 0) then
2503 phi = res_ang(index-1)
2504 diff = abs(res_ang(index) - res_ang(index-1))
2506 ! Look for last (corresponding) x10
2508 do while ((.not.res_tab(1,1,index)) .or. res_tab(1,2,index))
2511 if (index .lt. res_n-1) then
2512 temp = abs(res_ang(index) - res_ang(index+1))
2513 if (temp .lt. diff) then
2514 phi = res_ang(index+1)
2520 ! If increasing PHImax didn't work, decreasing PHImin
2521 ! will (with one exception)
2522 ! Look for first x10 (there MUST be at least one)
2524 do while ((.not.res_tab(1,1,index)) .or. res_tab(1,2,index))
2527 if (res_ang(index) .lt. 0.D0) then ! Make sure it's from PHImin
2528 ! Try to decrease PHImin
2529 if (index .lt. res_n-1) then
2530 temp = abs(res_ang(index) - res_ang(index+1))
2531 if (res_ang(index+1) .le. 0.D0 .and. temp .lt. diff) then
2532 phi = res_ang(index+1)
2536 ! Look for last (corresponding) 01x
2538 do while (res_tab(1,0,index) .or. (.not.res_tab(1,1,index)))
2541 if (index .gt. 0) then
2542 temp = abs(res_ang(index) - res_ang(index-1))
2543 if (res_ang(index-1) .ge. 0.D0 .and. temp .lt. diff) then
2544 phi = res_ang(index-1)
2550 ! If it still didn't work, it must be PHImax == 0. or PHImin == PI
2551 if (diff .eq. flag) then
2553 if (res_tab(index,1,0) .or. (.not.res_tab(index,1,1)) .or. &
2554 res_tab(index,1,2)) index = res_n - 1
2555 ! This MUST work at this point
2556 if (index .eq. 0) then
2559 phi = res_ang(index - 1)
2564 end subroutine fix_no_moves
2565 !-----------------------------------------------------------------------------
2566 integer function move_res(PHImin,PHImax,i_move)
2567 ! Moves residue i_move (in array c), leaving everything else fixed
2568 ! Starting geometry is not checked, it should be correct!
2569 ! R(,i_move) is the only residue that will move, but must have
2570 ! 1 < i_move < nres (i.e., cannot move ends)
2571 ! Whether any output is done is controlled by locmove_output
2573 use random,only:ran_number
2575 ! implicit real*8 (a-h,o-z)
2576 ! include 'DIMENSIONS'
2577 ! include 'COMMON.CHAIN'
2578 ! include 'COMMON.GEO'
2579 ! include 'COMMON.LOCMOVE'
2581 ! External functions
2582 !EL double precision ran_number
2583 !EL external ran_number
2586 real(kind=8) :: PHImin,PHImax
2590 ! 0: move successfull
2591 ! 1: Dmin or Dmax had to be modified
2592 ! 2: move failed - check your input geometry
2596 real(kind=8),dimension(0:2) :: X,Y,Z,Orig
2597 real(kind=8),dimension(0:2) :: P
2598 logical :: no_moves,done
2599 integer :: index,i,j
2600 real(kind=8) :: phi,temp,radius
2601 real(kind=8),dimension(0:11) :: phi_start,phi_end
2604 ! Set up the coordinate system
2606 Orig(i)=0.5*(c(i+1,i_move-1)+c(i+1,i_move+1)) ! Position of origin
2610 Z(i)=c(i+1,i_move+1)-c(i+1,i_move-1)
2612 temp=sqrt(Z(0)*Z(0)+Z(1)*Z(1)+Z(2)*Z(2))
2618 X(i)=c(i+1,i_move)-Orig(i)
2620 ! radius is the radius of the circle on which c(,i_move) can move
2621 radius=sqrt(X(0)*X(0)+X(1)*X(1)+X(2)*X(2))
2626 Y(0)=Z(1)*X(2)-X(1)*Z(2)
2627 Y(1)=X(0)*Z(2)-Z(0)*X(2)
2628 Y(2)=Z(0)*X(1)-X(0)*Z(1)
2630 ! Calculate min, max angles coming from dmin, dmax to c(,i_move-2)
2631 if (i_move.gt.2) then
2633 P(i)=c(i+1,i_move-2)-Orig(i)
2635 call minmax_angles(P(0)*X(0)+P(1)*X(1)+P(2)*X(2),&
2636 P(0)*Y(0)+P(1)*Y(1)+P(2)*Y(2),&
2637 P(0)*Z(0)+P(1)*Z(1)+P(2)*Z(2),&
2638 radius,a_n,a_ang,a_tab)
2643 ! Calculate min, max angles coming from dmin, dmax to c(,i_move+2)
2644 if (i_move.lt.nres-2) then
2646 P(i)=c(i+1,i_move+2)-Orig(i)
2648 call minmax_angles(P(0)*X(0)+P(1)*X(1)+P(2)*X(2),&
2649 P(0)*Y(0)+P(1)*Y(1)+P(2)*Y(2),&
2650 P(0)*Z(0)+P(1)*Z(1)+P(2)*Z(2),&
2651 radius,b_n,b_ang,b_tab)
2656 ! Construct the resulting table for alpha and beta
2657 call construct_tab()
2659 if (locmove_output) then
2660 print *,'ALPHAS & BETAS TABLE'
2664 ! Check that there is at least one possible move
2666 if (res_n .eq. 0) then
2670 do while ((index .lt. res_n) .and. no_moves)
2671 if (res_tab(2,1,index)) no_moves = .false.
2676 if (locmove_output) print *,' *** Cannot move anywhere'
2681 ! Transfer res_... into a_...
2684 if ( (res_tab(2,0,i).neqv.res_tab(2,1,i)) .or. &
2685 (res_tab(2,0,i).neqv.res_tab(2,2,i)) ) then
2686 a_ang(a_n) = res_ang(i)
2688 a_tab(j,a_n) = res_tab(2,j,i)
2694 ! Check that the PHI's are within [0,PI]
2695 if (PHImin .lt. 0. .or. abs(PHImin) .lt. small) PHImin = -flag
2696 if (PHImin .gt. PI .or. abs(PHImin-PI) .lt. small) PHImin = PI
2697 if (PHImax .gt. PI .or. abs(PHImax-PI) .lt. small) PHImax = flag
2698 if (PHImax .lt. 0. .or. abs(PHImax) .lt. small) PHImax = 0.
2699 if (PHImax .lt. PHImin) PHImax = PHImin
2700 ! Calculate min and max angles coming from PHImin and PHImax,
2701 ! and put them in b_...
2702 call angles2tab(PHImin, PHImax, b_n, b_ang, b_tab)
2703 ! Construct the final table
2704 call construct_tab()
2706 if (locmove_output) then
2707 print *,'FINAL TABLE'
2711 ! Check that there is at least one possible move
2713 if (res_n .eq. 0) then
2717 do while ((index .lt. res_n) .and. no_moves)
2718 if (res_tab(2,1,index)) no_moves = .false.
2724 ! Take care of the case where no solution exists...
2725 call fix_no_moves(phi)
2726 if (locmove_output) then
2727 print *,' *** Had to modify PHImin or PHImax'
2728 print *,'phi: ',phi*rad2deg
2732 ! ...or calculate the solution
2733 ! Construct phi_start/phi_end arrays
2734 call construct_ranges(phi_n, phi_start, phi_end)
2735 ! Choose random angle phi in allowed range(s)
2738 temp = temp + phi_end(i) - phi_start(i)
2740 phi = ran_number(phi_start(0),phi_start(0)+temp)
2743 do while (.not.done)
2744 if (phi .lt. phi_end(index)) then
2749 if (index .eq. phi_n) then
2751 else if (.not.done) then
2752 phi = phi + phi_start(index) - phi_end(index-1)
2755 if (index.eq.phi_n) phi=phi_end(phi_n-1) ! Fix numerical errors
2756 if (phi .gt. PI) phi = phi-2.*PI
2758 if (locmove_output) then
2759 print *,'ALLOWED RANGE(S)'
2761 print *,phi_start(i)*rad2deg,phi_end(i)*rad2deg
2763 print *,'phi: ',phi*rad2deg
2768 ! Re-use radius as temp variable
2769 temp=radius*cos(phi)
2770 radius=radius*sin(phi)
2772 c(i+1,i_move)=Orig(i)+temp*X(i)+radius*Y(i)
2776 end function move_res
2777 !-----------------------------------------------------------------------------
2782 ! implicit real*8 (a-h,o-z)
2783 ! include 'DIMENSIONS'
2784 ! include 'COMMON.GEO'
2785 ! include 'COMMON.LOCAL'
2786 ! include 'COMMON.LOCMOVE'
2788 ! External functions
2789 !EL integer move_res
2790 !EL external move_res
2795 real(kind=8),dimension(0:11) :: phi_start,phi_end
2797 real(kind=8),dimension(0:2,0:5) :: R
2799 locmove_output=.true.
2801 ! call angles2tab(30.*deg2rad,70.*deg2rad,a_n,a_ang,a_tab)
2802 ! call angles2tab(80.*deg2rad,130.*deg2rad,b_n,b_ang,b_tab)
2803 ! call minmax_angles(0.D0,3.8D0,0.D0,3.8D0,b_n,b_ang,b_tab)
2804 ! call construct_tab
2807 ! call construct_ranges(phi_n,phi_start,phi_end)
2809 ! print *,phi_start(i)*rad2deg,phi_end(i)*rad2deg
2812 ! call fix_no_moves(phi)
2813 ! print *,'NO MOVES FOUND, BEST PHI IS',phi*rad2deg
2819 R(1,1)=-cos(28.D0*deg2rad)
2820 R(2,1)=-0.5D0-sin(28.D0*deg2rad)
2824 R(0,3)=cos(30.D0*deg2rad)
2831 R(1,5)=cos(26.D0*deg2rad)
2832 R(2,5)=0.5D0+sin(26.D0*deg2rad)
2838 ! i=move_res(R(0,1),0.D0*deg2rad,180.D0*deg2rad)
2840 i=move_res(0.D0*deg2rad,180.D0*deg2rad,imov)
2841 print *,'RETURNED ',i
2842 print *,(R(i,3)/vbl,i=0,2)
2845 end subroutine loc_test
2847 !-----------------------------------------------------------------------------
2849 !-----------------------------------------------------------------------------
2850 subroutine MATMULT(A1,A2,A3)
2851 ! implicit real*8 (a-h,o-z)
2852 ! include 'DIMENSIONS'
2855 real(kind=8) :: A3IJ
2857 real(kind=8),DIMENSION(3,3) :: A1,A2,A3
2858 real(kind=8),DIMENSION(3,3) :: AI3
2863 3 A3IJ=A3IJ+A1(I,K)*A2(K,J)
2871 end subroutine MATMULT
2872 !-----------------------------------------------------------------------------
2874 !-----------------------------------------------------------------------------
2875 subroutine int_from_cart(lside,lprn)
2876 ! implicit real*8 (a-h,o-z)
2877 ! include 'DIMENSIONS'
2878 use control_data,only:out1file
2882 ! include 'COMMON.LOCAL'
2883 ! include 'COMMON.VAR'
2884 ! include 'COMMON.CHAIN'
2885 ! include 'COMMON.INTERACT'
2886 ! include 'COMMON.IOUNITS'
2887 ! include 'COMMON.GEO'
2888 ! include 'COMMON.NAMES'
2889 ! include 'COMMON.CONTROL'
2890 ! include 'COMMON.SETUP'
2891 character(len=3) :: seq,res
2893 character(len=80) :: card
2894 real(kind=8),dimension(3,20) :: sccor
2895 integer :: i,j,iti !el rescode,
2896 logical :: lside,lprn
2897 real(kind=8) :: di,cosfac,sinfac
2901 if(me.eq.king.or..not.out1file)then
2903 write (iout,'(/a)') &
2904 'Internal coordinates calculated from crystal structure.'
2906 write (iout,'(8a)') ' Res ',' dvb',' Theta',&
2907 ' Gamma',' Dsc_id',' Dsc',' Alpha',&
2910 write (iout,'(4a)') ' Res ',' dvb',' Theta',&
2916 if (molnum(i).ne.1) cycle
2917 !in wham do i=1,nres
2919 if ((dist(i,i+1).lt.2.0D0 .or. dist(i,i+1).gt.5.0D0).and.&
2920 (iti.ne.ntyp1 .and. itype(i+1,1).ne.ntyp1)) then
2921 write (iout,'(a,i4)') 'Bad Cartesians for residue',i
2925 vbld(i+1)=dist(i,i+1)
2926 vbld_inv(i+1)=1.0d0/vbld(i+1)
2928 if (i.gt.1) theta(i+1)=alpha(i-1,i,i+1)
2929 if (i.gt.2) phi(i+1)=beta(i-2,i-1,i,i+1)
2933 ! if (itype(1,1).eq.ntyp1) then
2935 ! c(j,1)=c(j,2)+(c(j,3)-c(j,4))
2938 ! if (itype(nres,1).eq.ntyp1) then
2940 ! c(j,nres)=c(j,nres-1)+(c(j,nres-2)-c(j,nres-3))
2944 ! if (unres_pdb) then
2945 ! if (itype(1,1).eq.21) then
2946 ! theta(3)=90.0d0*deg2rad
2947 ! phi(4)=180.0d0*deg2rad
2949 ! vbld_inv(2)=1.0d0/vbld(2)
2951 ! if (itype(nres,1).eq.21) then
2952 ! theta(nres)=90.0d0*deg2rad
2953 ! phi(nres)=180.0d0*deg2rad
2955 ! vbld_inv(nres)=1.0d0/vbld(2)
2961 c(j,nres2+2)=0.5D0*(2*c(j,i)+(c(j,i-1)-c(j,i))*vbld_inv(i) &
2962 +(c(j,i+1)-c(j,i))*vbld_inv(i+1))
2963 ! in wham c(j,maxres2)=0.5D0*(c(j,i-1)+c(j,i+1)
2968 ! 10/03/12 Adam: Correction for zero SC-SC bond length
2970 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1 .and. di.eq.0.0d0) &
2971 di=dsc(itype(i,molnum(i)))
2973 if (itype(i,1).ne.10) then
2974 vbld_inv(i+nres)=1.0d0/di
2976 vbld_inv(i+nres)=0.0d0
2980 alph(i)=alpha(nres+i,i,nres2+2)
2981 omeg(i)=beta(nres+i,i,nres2+2,i+1)
2984 if(me.eq.king.or..not.out1file)then
2986 write (iout,'(a3,i4,7f10.3)') restyp(iti,1),i,vbld(i),&
2987 rad2deg*theta(i),rad2deg*phi(i),dsc(iti),vbld(nres+i),&
2988 rad2deg*alph(i),rad2deg*omeg(i)
2991 if(me.eq.king.or..not.out1file)then
2993 write (iout,'(a3,i4,7f10.3)') restyp(iti,1),i,vbld(i),&
2994 rad2deg*theta(i),rad2deg*phi(i),dsc(iti+1),vbld(nres+i),&
2995 rad2deg*alph(i),rad2deg*omeg(i)
3002 if(me.eq.king.or..not.out1file) &
3003 write (iout,'(a3,i4,7f10.3)') restyp(iti,1),i,dist(i,i-1),&
3004 rad2deg*theta(i),rad2deg*phi(i)
3008 end subroutine int_from_cart
3009 !-----------------------------------------------------------------------------
3010 subroutine sc_loc_geom(lprn)
3011 ! implicit real*8 (a-h,o-z)
3012 ! include 'DIMENSIONS'
3013 use control_data,only:out1file
3017 ! include 'COMMON.LOCAL'
3018 ! include 'COMMON.VAR'
3019 ! include 'COMMON.CHAIN'
3020 ! include 'COMMON.INTERACT'
3021 ! include 'COMMON.IOUNITS'
3022 ! include 'COMMON.GEO'
3023 ! include 'COMMON.NAMES'
3024 ! include 'COMMON.CONTROL'
3025 ! include 'COMMON.SETUP'
3026 real(kind=8),dimension(3) :: x_prime,y_prime,z_prime
3029 integer :: i,j,it,iti
3030 real(kind=8) :: cosfac2,sinfac2,xx,yy,zz,cosfac,sinfac
3033 dc_norm(j,i)=vbld_inv(i+1)*(c(j,i+1)-c(j,i))
3037 if (itype(i,1).ne.10) then
3039 dc_norm(j,i+nres)=vbld_inv(i+nres)*(c(j,i+nres)-c(j,i))
3043 dc_norm(j,i+nres)=0.0d0
3048 costtab(i+1) =dcos(theta(i+1))
3049 sinttab(i+1) =dsqrt(1-costtab(i+1)*costtab(i+1))
3050 cost2tab(i+1)=dsqrt(0.5d0*(1.0d0+costtab(i+1)))
3051 sint2tab(i+1)=dsqrt(0.5d0*(1.0d0-costtab(i+1)))
3052 cosfac2=0.5d0/(1.0d0+costtab(i+1))
3053 cosfac=dsqrt(cosfac2)
3054 sinfac2=0.5d0/(1.0d0-costtab(i+1))
3055 sinfac=dsqrt(sinfac2)
3058 if ((it.ne.10).and.(it.ne.ntyp1)) then
3059 !el if (it.ne.10) then
3061 ! Compute the axes of tghe local cartesian coordinates system; store in
3062 ! x_prime, y_prime and z_prime
3070 x_prime(j) = (dc_norm(j,i) - dc_norm(j,i-1))*cosfac
3071 y_prime(j) = (dc_norm(j,i) + dc_norm(j,i-1))*sinfac
3073 call vecpr(x_prime,y_prime,z_prime)
3075 ! Transform the unit vector of the ith side-chain centroid, dC_norm(*,i),
3076 ! to local coordinate system. Store in xx, yy, zz.
3082 xx = xx + x_prime(j)*dc_norm(j,i+nres)
3083 yy = yy + y_prime(j)*dc_norm(j,i+nres)
3084 zz = zz + z_prime(j)*dc_norm(j,i+nres)
3099 if(me.eq.king.or..not.out1file) &
3100 write (iout,'(a3,i4,3f10.5)') restyp(iti,1),i,xxref(i),&
3106 end subroutine sc_loc_geom
3107 !-----------------------------------------------------------------------------
3108 subroutine sccenter(ires,nscat,sccor)
3109 ! implicit real*8 (a-h,o-z)
3110 ! include 'DIMENSIONS'
3111 ! include 'COMMON.CHAIN'
3112 integer :: i,j,ires,nscat
3113 real(kind=8),dimension(3,20) :: sccor
3114 real(kind=8) :: sccmj
3115 ! print *,"I am in sccenter",ires,nscat
3119 sccmj=sccmj+sccor(j,i)
3120 !C print *,"insccent", ires,sccor(j,i)
3122 dc(j,ires)=sccmj/nscat
3125 end subroutine sccenter
3126 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
3127 !-----------------------------------------------------------------------------
3128 subroutine bond_regular
3130 ! implicit real*8 (a-h,o-z)
3131 ! include 'DIMENSIONS'
3132 ! include 'COMMON.VAR'
3133 ! include 'COMMON.LOCAL'
3134 ! include 'COMMON.CALC'
3135 ! include 'COMMON.INTERACT'
3136 ! include 'COMMON.CHAIN'
3139 vbld_inv(i+1)=1.0d0/vbld(i+1)
3140 vbld(i+1+nres)=dsc(itype(i+1,1))
3141 vbld_inv(i+1+nres)=dsc_inv(itype(i+1,1))
3142 ! print *,vbld(i+1),vbld(i+1+nres)
3145 end subroutine bond_regular
3147 !-----------------------------------------------------------------------------
3149 !-----------------------------------------------------------------------------
3150 subroutine refsys(i2,i3,i4,e1,e2,e3,fail)
3151 ! This subroutine calculates unit vectors of a local reference system
3152 ! defined by atoms (i2), (i3), and (i4). The x axis is the axis from
3153 ! atom (i3) to atom (i2), and the xy plane is the plane defined by atoms
3154 ! (i2), (i3), and (i4). z axis is directed according to the sign of the
3155 ! vector product (i3)-(i2) and (i3)-(i4). Sets fail to .true. if atoms
3156 ! (i2) and (i3) or (i3) and (i4) coincide or atoms (i2), (i3), and (i4)
3157 ! form a linear fragment. Returns vectors e1, e2, and e3.
3158 ! implicit real*8 (a-h,o-z)
3159 ! include 'DIMENSIONS'
3161 real(kind=8),dimension(3) :: e1,e2,e3
3162 real(kind=8),dimension(3) :: u,z
3163 ! include 'COMMON.IOUNITS'
3164 ! include 'COMMON.CHAIN'
3165 real(kind=8) :: coinc=1.0D-13,align=1.0D-13
3167 integer :: i,i1,i2,i3,i4
3168 real(kind=8) :: v1,v2,v3,s1,s2,zi,ui,anorm
3181 if (s1.gt.coinc) goto 2
3182 write (iout,1000) i2,i3,i1
3187 2 if (s2.gt.coinc) goto 4
3188 write(iout,1000) i3,i4,i1
3195 v1=z(2)*u(3)-z(3)*u(2)
3196 v2=z(3)*u(1)-z(1)*u(3)
3197 v3=z(1)*u(2)-z(2)*u(1)
3198 anorm=dsqrt(v1*v1+v2*v2+v3*v3)
3199 if (anorm.gt.align) goto 6
3200 write (iout,1010) i2,i3,i4,i1
3212 e2(1)=e1(3)*e3(2)-e1(2)*e3(3)
3213 e2(2)=e1(1)*e3(3)-e1(3)*e3(1)
3214 e2(3)=e1(2)*e3(1)-e1(1)*e3(2)
3215 1000 format (/1x,' * * * Error - atoms',i4,' and',i4,' coincide.',&
3216 'coordinates of atom',i4,' are set to zero.')
3217 1010 format (/1x,' * * * Error - atoms',2(i4,2h, ),i4,' form a linear',&
3218 ' fragment. coordinates of atom',i4,' are set to zero.')
3220 end subroutine refsys
3221 !-----------------------------------------------------------------------------
3223 !-----------------------------------------------------------------------------
3224 subroutine int_to_cart
3225 !--------------------------------------------------------------
3226 ! This subroutine converts the energy derivatives from internal
3227 ! coordinates to cartesian coordinates
3228 !-------------------------------------------------------------
3229 ! implicit real*8 (a-h,o-z)
3230 ! include 'DIMENSIONS'
3231 ! include 'COMMON.VAR'
3232 ! include 'COMMON.CHAIN'
3233 ! include 'COMMON.DERIV'
3234 ! include 'COMMON.GEO'
3235 ! include 'COMMON.LOCAL'
3236 ! include 'COMMON.INTERACT'
3237 ! include 'COMMON.MD'
3238 ! include 'COMMON.IOUNITS'
3239 ! include 'COMMON.SCCOR'
3240 ! calculating dE/ddc1
3243 ! print *,"gloc",gloc(:,:)
3244 ! print *, "gcart",gcart(:,:)
3245 if (nres.lt.3) go to 18
3247 gcart(j,1)=gcart(j,1)+gloc(1,icg)*dphi(j,1,4) &
3248 +gloc(nres-2,icg)*dtheta(j,1,3)
3249 if(itype(2,1).ne.10) then
3250 gcart(j,1)=gcart(j,1)+gloc(ialph(2,1),icg)*dalpha(j,1,2)+ &
3251 gloc(ialph(2,1)+nside,icg)*domega(j,1,2)
3254 ! Calculating the remainder of dE/ddc2
3256 gcart(j,2)=gcart(j,2)+gloc(1,icg)*dphi(j,2,4)+ &
3257 gloc(nres-2,icg)*dtheta(j,2,3)+gloc(nres-1,icg)*dtheta(j,1,4)
3258 if(itype(2,1).ne.10) then
3259 gcart(j,2)=gcart(j,2)+gloc(ialph(2,1),icg)*dalpha(j,2,2)+ &
3260 gloc(ialph(2,1)+nside,icg)*domega(j,2,2)
3262 if(itype(3,1).ne.10) then
3263 gcart(j,2)=gcart(j,2)+gloc(ialph(3,1),icg)*dalpha(j,1,3)+ &
3264 gloc(ialph(3,1)+nside,icg)*domega(j,1,3)
3267 gcart(j,2)=gcart(j,2)+gloc(2,icg)*dphi(j,1,5)
3270 ! If there are only five residues
3273 gcart(j,3)=gcart(j,3)+gloc(1,icg)*dphi(j,3,4)+gloc(2,icg)* &
3274 dphi(j,2,5)+gloc(nres-1,icg)*dtheta(j,2,4)+gloc(nres,icg)* &
3276 if(itype(3,1).ne.10) then
3277 gcart(j,3)=gcart(j,3)+gloc(ialph(3,1),icg)* &
3278 dalpha(j,2,3)+gloc(ialph(3,1)+nside,icg)*domega(j,2,3)
3280 if(itype(4,1).ne.10) then
3281 gcart(j,3)=gcart(j,3)+gloc(ialph(4,1),icg)* &
3282 dalpha(j,1,4)+gloc(ialph(4,1)+nside,icg)*domega(j,1,4)
3286 ! If there are more than five residues
3290 gcart(j,i)=gcart(j,i)+gloc(i-2,icg)*dphi(j,3,i+1) &
3291 +gloc(i-1,icg)*dphi(j,2,i+2)+ &
3292 gloc(i,icg)*dphi(j,1,i+3)+gloc(nres+i-4,icg)*dtheta(j,2,i+1)+ &
3293 gloc(nres+i-3,icg)*dtheta(j,1,i+2)
3294 if(itype(i,1).ne.10) then
3295 gcart(j,i)=gcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,2,i)+ &
3296 gloc(ialph(i,1)+nside,icg)*domega(j,2,i)
3298 if(itype(i+1,1).ne.10) then
3299 gcart(j,i)=gcart(j,i)+gloc(ialph(i+1,1),icg)*dalpha(j,1,i+1) &
3300 +gloc(ialph(i+1,1)+nside,icg)*domega(j,1,i+1)
3305 ! Setting dE/ddnres-2
3308 gcart(j,nres-2)=gcart(j,nres-2)+gloc(nres-4,icg)* &
3309 dphi(j,3,nres-1)+gloc(nres-3,icg)*dphi(j,2,nres) &
3310 +gloc(2*nres-6,icg)* &
3311 dtheta(j,2,nres-1)+gloc(2*nres-5,icg)*dtheta(j,1,nres)
3312 if(itype(nres-2,1).ne.10) then
3313 gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-2,1),icg)* &
3314 dalpha(j,2,nres-2)+gloc(ialph(nres-2,1)+nside,icg)* &
3317 if(itype(nres-1,1).ne.10) then
3318 gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-1,1),icg)* &
3319 dalpha(j,1,nres-1)+gloc(ialph(nres-1,1)+nside,icg)* &
3324 ! Settind dE/ddnres-1
3326 gcart(j,nres-1)=gcart(j,nres-1)+gloc(nres-3,icg)*dphi(j,3,nres)+ &
3327 gloc(2*nres-5,icg)*dtheta(j,2,nres)
3328 if(itype(nres-1,1).ne.10) then
3329 gcart(j,nres-1)=gcart(j,nres-1)+gloc(ialph(nres-1,1),icg)* &
3330 dalpha(j,2,nres-1)+gloc(ialph(nres-1,1)+nside,icg)* &
3334 ! The side-chain vector derivatives
3336 if(itype(i,1).ne.10 .and. &
3337 itype(i,molnum(i)).ne.ntyp1_molec(molnum(i))) then
3339 gxcart(j,i)=gxcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,3,i) &
3340 +gloc(ialph(i,1)+nside,icg)*domega(j,3,i)
3344 !----------------------------------------------------------------------
3345 ! INTERTYP=1 SC...Ca...Ca...Ca
3346 ! INTERTYP=2 Ca...Ca...Ca...SC
3347 ! INTERTYP=3 SC...Ca...Ca...SC
3348 ! calculating dE/ddc1
3352 ! write (iout,*) "poczotkoawy",i,gloc_sc(1,i,icg)
3354 if (nres.lt.2) return
3355 if ((nres.lt.3).and.(itype(1,1).eq.10)) return
3356 if ((itype(1,1).ne.10).and. &
3357 (itype(1,molnum(1)).ne.ntyp1_molec(molnum(1)))) then
3359 !c Derviative was calculated for oposite vector of side chain therefore
3360 ! there is "-" sign before gloc_sc
3361 gxcart(j,1)=gxcart(j,1)-gloc_sc(1,0,icg)* &
3363 gcart(j,1)=gcart(j,1)+gloc_sc(1,0,icg)* &
3365 if ((itype(2,1).ne.10).and. &
3366 (itype(2,molnum(2)).ne.ntyp1_molec(molnum(2)))) then
3367 gxcart(j,1)= gxcart(j,1) &
3368 -gloc_sc(3,0,icg)*dtauangle(j,3,1,3)
3369 gcart(j,1)=gcart(j,1)+gloc_sc(3,0,icg)* &
3374 if ((nres.ge.3).and.(itype(3,molnum(3)).ne.10).and.&
3375 (itype(3,molnum(3)).ne.ntyp1_molec(molnum(3)))) &
3378 gcart(j,1)=gcart(j,1)+gloc_sc(2,1,icg)*dtauangle(j,2,1,4)
3381 ! As potetnial DO NOT depend on omicron anlge their derivative is
3383 ! & +gloc_sc(intertyp,nres-2,icg)*dtheta(j,1,3)
3385 ! Calculating the remainder of dE/ddc2
3387 if((itype(2,1).ne.10).and. &
3388 (itype(2,molnum(2)).ne.ntyp1_molec(molnum(2)))) then
3389 if (itype(1,1).ne.10) gxcart(j,2)=gxcart(j,2)+ &
3390 gloc_sc(3,0,icg)*dtauangle(j,3,3,3)
3391 if ((itype(3,1).ne.10).and.(nres.ge.3).and.(itype(3,molnum(3)).ne.ntyp1_molec(3))) &
3393 gxcart(j,2)=gxcart(j,2)-gloc_sc(3,1,icg)*dtauangle(j,3,1,4)
3394 !c the - above is due to different vector direction
3395 gcart(j,2)=gcart(j,2)+gloc_sc(3,1,icg)*dtauangle(j,3,2,4)
3398 gxcart(j,2)=gxcart(j,2)-gloc_sc(1,1,icg)*dtauangle(j,1,1,4)
3399 !c the - above is due to different vector direction
3400 gcart(j,2)=gcart(j,2)+gloc_sc(1,1,icg)*dtauangle(j,1,2,4)
3401 ! write(iout,*) gloc_sc(1,1,icg),dtauangle(j,1,2,4),"gcart"
3402 ! write(iout,*) gloc_sc(1,1,icg),dtauangle(j,1,1,4),"gx"
3405 if ((itype(1,1).ne.10).and.&
3406 (itype(1,molnum(1)).ne.ntyp1_molec(molnum(1)))) then
3407 gcart(j,2)=gcart(j,2)+gloc_sc(1,0,icg)*dtauangle(j,1,3,3)
3408 ! write(iout,*) gloc_sc(1,0,icg),dtauangle(j,1,3,3)
3410 if ((itype(3,1).ne.10).and.(nres.ge.3)) then
3411 gcart(j,2)=gcart(j,2)+gloc_sc(2,1,icg)*dtauangle(j,2,2,4)
3412 ! write(iout,*) gloc_sc(2,1,icg),dtauangle(j,2,2,4)
3414 if ((itype(4,1).ne.10).and.(nres.ge.4)) then
3415 gcart(j,2)=gcart(j,2)+gloc_sc(2,2,icg)*dtauangle(j,2,1,5)
3416 ! write(iout,*) gloc_sc(2,2,icg),dtauangle(j,2,1,5)
3419 ! write(iout,*) gcart(j,2),itype(2,1),itype(1,1),itype(3,1), "gcart2"
3421 ! If there are more than five residues
3425 ! write(iout,*) "before", gcart(j,i)
3426 if ((itype(i,1).ne.10).and.&
3427 (itype(i,molnum(i)).ne.ntyp1_molec(molnum(i)))) then
3428 gxcart(j,i)=gxcart(j,i)+gloc_sc(2,i-2,icg) &
3429 *dtauangle(j,2,3,i+1) &
3430 -gloc_sc(1,i-1,icg)*dtauangle(j,1,1,i+2)
3431 gcart(j,i)=gcart(j,i)+gloc_sc(1,i-1,icg) &
3432 *dtauangle(j,1,2,i+2)
3433 ! write(iout,*) "new",j,i,
3434 ! & gcart(j,i),gloc_sc(1,i-1,icg),dtauangle(j,1,2,i+2)
3435 if (itype(i-1,1).ne.10) then
3436 gxcart(j,i)=gxcart(j,i)+gloc_sc(3,i-2,icg) &
3437 *dtauangle(j,3,3,i+1)
3439 if (itype(i+1,1).ne.10) then
3440 gxcart(j,i)=gxcart(j,i)-gloc_sc(3,i-1,icg) &
3441 *dtauangle(j,3,1,i+2)
3442 gcart(j,i)=gcart(j,i)+gloc_sc(3,i-1,icg) &
3443 *dtauangle(j,3,2,i+2)
3446 if (itype(i-1,1).ne.10) then
3447 gcart(j,i)=gcart(j,i)+gloc_sc(1,i-2,icg)* &
3448 dtauangle(j,1,3,i+1)
3450 if (itype(i+1,1).ne.10) then
3451 gcart(j,i)=gcart(j,i)+gloc_sc(2,i-1,icg)* &
3452 dtauangle(j,2,2,i+2)
3453 ! write(iout,*) "numer",i,gloc_sc(2,i-1,icg),
3454 ! & dtauangle(j,2,2,i+2)
3456 if (itype(i+2,1).ne.10) then
3457 gcart(j,i)=gcart(j,i)+gloc_sc(2,i,icg)* &
3458 dtauangle(j,2,1,i+3)
3463 ! Setting dE/ddnres-1
3466 if ((itype(nres-1,1).ne.10).and.&
3467 (itype(nres-1,molnum(nres-1)).ne.ntyp1_molec(molnum(nres-1)))) then
3468 gxcart(j,nres-1)=gxcart(j,nres-1)+gloc_sc(2,nres-3,icg) &
3469 *dtauangle(j,2,3,nres)
3470 ! write (iout,*) "gxcart(nres-1)", gloc_sc(2,nres-3,icg),
3471 ! & dtauangle(j,2,3,nres), gxcart(j,nres-1)
3472 if (itype(nres-2,1).ne.10) then
3473 gxcart(j,nres-1)=gxcart(j,nres-1)+gloc_sc(3,nres-3,icg) &
3474 *dtauangle(j,3,3,nres)
3476 if ((itype(nres,1).ne.10).and.&
3477 (itype(nres,molnum(nres)).ne.ntyp1_molec(molnum(nres)))) then
3478 gxcart(j,nres-1)=gxcart(j,nres-1)-gloc_sc(3,nres-2,icg) &
3479 *dtauangle(j,3,1,nres+1)
3480 gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(3,nres-2,icg) &
3481 *dtauangle(j,3,2,nres+1)
3484 if ((itype(nres-2,1).ne.10).and.&
3485 (itype(nres-2,molnum(nres-2)).ne.ntyp1_molec(molnum(nres-2)))) then
3486 gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(1,nres-3,icg)* &
3487 dtauangle(j,1,3,nres)
3489 if ((itype(nres,1).ne.10).and.(itype(nres,molnum(nres)).ne.ntyp1_molec(molnum(nres)))) then
3490 gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(2,nres-2,icg)* &
3491 dtauangle(j,2,2,nres+1)
3492 ! write (iout,*) "gcart(nres-1)", gloc_sc(2,nres-2,icg),
3493 ! & dtauangle(j,2,2,nres+1), itype(nres-1,1),itype(nres,1)
3498 if ((nres.ge.3).and.(itype(nres,1).ne.10).and. &
3499 (itype(nres,molnum(nres)).ne.ntyp1_molec(molnum(nres))))then
3501 gxcart(j,nres)=gxcart(j,nres)+gloc_sc(3,nres-2,icg) &
3502 *dtauangle(j,3,3,nres+1)+gloc_sc(2,nres-2,icg) &
3503 *dtauangle(j,2,3,nres+1)
3506 ! The side-chain vector derivatives
3507 ! print *,"gcart",gcart(:,:)
3509 end subroutine int_to_cart
3510 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
3511 !-----------------------------------------------------------------------------
3513 !-----------------------------------------------------------------------------
3514 subroutine gen_dist_constr
3515 ! Generate CA distance constraints.
3516 ! implicit real*8 (a-h,o-z)
3517 ! include 'DIMENSIONS'
3518 ! include 'COMMON.IOUNITS'
3519 ! include 'COMMON.GEO'
3520 ! include 'COMMON.VAR'
3521 ! include 'COMMON.INTERACT'
3522 ! include 'COMMON.LOCAL'
3523 ! include 'COMMON.NAMES'
3524 ! include 'COMMON.CHAIN'
3525 ! include 'COMMON.FFIELD'
3526 ! include 'COMMON.SBRIDGE'
3527 ! include 'COMMON.HEADER'
3528 ! include 'COMMON.CONTROL'
3529 ! include 'COMMON.DBASE'
3530 ! include 'COMMON.THREAD'
3531 ! include 'COMMON.TIME1'
3532 ! integer :: itype_pdb !(maxres)
3533 ! common /pizda/ itype_pdb(nres)
3534 character(len=2) :: iden
3537 !d print *,'gen_dist_constr: nnt=',nnt,' nct=',nct
3538 !d write (2,*) 'gen_dist_constr: nnt=',nnt,' nct=',nct,
3539 !d & ' nstart_sup',nstart_sup,' nstart_seq',nstart_seq,
3541 do i=nstart_sup,nstart_sup+nsup-1
3542 !d write (2,*) 'i',i,' seq ',restyp(itype(i+nstart_seq-nstart_sup)),
3543 !d & ' seq_pdb', restyp(itype_pdb(i))
3544 do j=i+2,nstart_sup+nsup-1
3546 ihpb(nhpb)=i+nstart_seq-nstart_sup
3547 jhpb(nhpb)=j+nstart_seq-nstart_sup
3549 dhpb(nhpb)=dist(i,j)
3552 !d write (iout,'(a)') 'Distance constraints:'
3557 !d if (ii.gt.nres) then
3562 !d write (iout,'(a,1x,a,i4,3x,a,1x,a,i4,2f10.3)')
3563 !d & restyp(itype(ii)),iden,ii,restyp(itype(jj)),iden,jj,
3564 !d & dhpb(i),forcon(i)
3566 ! deallocate(itype_pdb)
3569 end subroutine gen_dist_constr
3571 !-----------------------------------------------------------------------------
3573 !-----------------------------------------------------------------------------
3574 subroutine cartprint
3576 use geometry_data, only: c
3577 use energy_data, only: itype
3578 ! implicit real*8 (a-h,o-z)
3579 ! include 'DIMENSIONS'
3580 ! include 'COMMON.CHAIN'
3581 ! include 'COMMON.INTERACT'
3582 ! include 'COMMON.NAMES'
3583 ! include 'COMMON.IOUNITS'
3588 write (iout,110) restyp(itype(i,1),1),i,c(1,i),c(2,i),&
3589 c(3,i),c(1,nres+i),c(2,nres+i),c(3,nres+i)
3591 100 format (//' alpha-carbon coordinates ',&
3592 ' centroid coordinates'/ &
3593 ' ', 6X,'X',11X,'Y',11X,'Z',&
3594 10X,'X',11X,'Y',11X,'Z')
3595 110 format (a,'(',i3,')',6f12.5)
3597 end subroutine cartprint
3598 !-----------------------------------------------------------------------------
3599 !-----------------------------------------------------------------------------
3600 subroutine alloc_geo_arrays
3601 !EL Allocation of tables used by module energy
3603 integer :: i,j,nres2
3607 allocate(phibound(2,nres+2)) !(2,maxres)
3608 !----------------------
3610 ! common /chain/ in molread
3611 ! real(kind=8),dimension(:,:),allocatable :: c !(3,maxres2+2)
3612 ! real(kind=8),dimension(:,:),allocatable :: dc
3613 allocate(dc_old(3,0:nres2))
3614 ! if(.not.allocated(dc_norm2)) allocate(dc_norm2(3,0:nres2+2)) !(3,0:maxres2)
3615 if(.not.allocated(dc_norm2)) then
3616 allocate(dc_norm2(3,0:nres2+2)) !(3,0:maxres2)
3620 !el if(.not.allocated(dc_norm))
3621 !elwrite(iout,*) "jestem w alloc geo 1"
3622 if(.not.allocated(dc_norm)) then
3623 allocate(dc_norm(3,0:nres2+2)) !(3,0:maxres2)
3626 !elwrite(iout,*) "jestem w alloc geo 1"
3627 allocate(xloc(3,nres),xrot(3,nres))
3628 !elwrite(iout,*) "jestem w alloc geo 1"
3630 !elwrite(iout,*) "jestem w alloc geo 1"
3631 allocate(dc_work(6*nres)) !(MAXRES6) maxres6=6*maxres
3633 allocate(t(3,3,nres),r(3,3,nres))
3634 allocate(prod(3,3,nres),rt(3,3,nres)) !(3,3,maxres)
3635 ! common /refstruct/
3636 if(.not.allocated(cref)) allocate(cref(3,nres2+2,maxperm)) !(3,maxres2+2,maxperm)
3637 !elwrite(iout,*) "jestem w alloc geo 2"
3638 allocate(crefjlee(3,nres2+2)) !(3,maxres2+2)
3639 if(.not.allocated(chain_rep)) allocate(chain_rep(3,nres2+2,maxsym)) !(3,maxres2+2,maxsym)
3640 if(.not.allocated(tabperm)) allocate(tabperm(maxperm,maxsym)) !(maxperm,maxsym)
3641 ! common /from_zscore/ in module.compare
3642 !----------------------
3644 ! Inverses of the actual virtual bond lengths
3645 ! common /invlen/ in io_conf: molread or readpdb
3646 ! real(kind=8),dimension(:),allocatable :: vbld_inv !(maxres2)
3647 !----------------------
3649 ! Store the geometric variables in the following COMMON block.
3650 ! common /var/ in readpdb or ...
3651 if(.not.allocated(theta)) allocate(theta(nres+2))
3652 if(.not.allocated(phi)) allocate(phi(nres+2))
3653 if(.not.allocated(alph)) allocate(alph(nres+2))
3654 if(.not.allocated(omeg)) allocate(omeg(nres+2))
3655 if(.not.allocated(thetaref)) allocate(thetaref(nres+2))
3656 if(.not.allocated(phiref)) allocate(phiref(nres+2))
3657 if(.not.allocated(costtab)) allocate(costtab(nres))
3658 if(.not.allocated(sinttab)) allocate(sinttab(nres))
3659 if(.not.allocated(cost2tab)) allocate(cost2tab(nres))
3660 if(.not.allocated(sint2tab)) allocate(sint2tab(nres))
3661 ! real(kind=8),dimension(:),allocatable :: vbld !(2*maxres) in io_conf: molread or readpdb
3662 allocate(omicron(2,nres+2)) !(2,maxres)
3663 allocate(tauangle(3,nres+2)) !(3,maxres)
3664 !elwrite(iout,*) "jestem w alloc geo 3"
3665 if(.not.allocated(xxtab)) allocate(xxtab(nres))
3666 if(.not.allocated(yytab)) allocate(yytab(nres))
3667 if(.not.allocated(zztab)) allocate(zztab(nres)) !(maxres)
3668 if(.not.allocated(xxref)) allocate(xxref(nres))
3669 if(.not.allocated(yyref)) allocate(yyref(nres))
3670 if(.not.allocated(zzref)) allocate(zzref(nres)) !(maxres)
3671 allocate(ialph(nres,2)) !(maxres,2)
3674 allocate(ivar(4*nres2)) !(4*maxres2)
3676 #if defined(WHAM_RUN) || defined(CLUSTER)
3677 allocate(vbld(2*nres))
3679 allocate(vbld_inv(2*nres))
3684 end subroutine alloc_geo_arrays
3685 !-----------------------------------------------------------------------------
3686 !-----------------------------------------------------------------------------