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
87 ! Define the origin and orientation of the coordinate system and locate the
88 ! first three CA's and SC(2).
90 !elwrite(iout,*)"in chainbuild"
92 !elwrite(iout,*)"after orig_frame"
94 ! Build the alpha-carbon chain.
97 call locate_next_res(i)
99 !elwrite(iout,*)"after locate_next_res"
101 ! First and last SC must coincide with the corresponding CA.
105 dc_norm(j,nres+1)=0.0D0
106 dc(j,nres+nres)=0.0D0
107 dc_norm(j,nres+nres)=0.0D0
109 c(j,nres+nres)=c(j,nres)
112 ! Temporary diagnosis
117 write (iout,'(/a)') 'Recalculated internal coordinates'
120 c(j,nres2+2)=0.5D0*(c(j,i-1)+c(j,i+1)) !maxres2=2*maxres
123 if (i.gt.3) be=rad2deg*beta(i-3,i-2,i-1,i)
124 be1=rad2deg*beta(nres+i,i,nres2+2,i+1)
126 if (i.gt.2) alfai=rad2deg*alpha(i-2,i-1,i)
127 write (iout,1212) restyp(itype(i)),i,dist(i-1,i),&
128 alfai,be,dist(nres+i,i),rad2deg*alpha(nres+i,i,nres2+2),be1
130 1212 format (a3,'(',i3,')',2(f10.5,2f10.2))
135 end subroutine chainbuild
136 !-----------------------------------------------------------------------------
137 subroutine orig_frame
139 ! Define the origin and orientation of the coordinate system and locate
140 ! the first three atoms.
142 ! implicit real*8 (a-h,o-z)
143 ! include 'DIMENSIONS'
144 ! include 'COMMON.CHAIN'
145 ! include 'COMMON.LOCAL'
146 ! include 'COMMON.GEO'
147 ! include 'COMMON.VAR'
150 real(kind=8) :: cost,sint
152 !el allocate(t(3,3,nres)) !(3,3,maxres)
153 !el allocate(r(3,3,nres)) !(3,3,maxres)
154 !el allocate(rt(3,3,nres)) !(3,3,maxres)
155 !el allocate(dc_norm(3,0:2*nres)) !(3,0:maxres2)
156 !el allocate(prod(3,3,nres)) !(3,3,maxres)
209 dc_norm(j,2)=prod(j,1,2)
210 dc(j,2)=vbld(3)*prod(j,1,2)
211 c(j,3)=c(j,2)+dc(j,2)
213 call locate_side_chain(2)
215 end subroutine orig_frame
216 !-----------------------------------------------------------------------------
217 subroutine locate_next_res(i)
219 ! Locate CA(i) and SC(i-1)
221 ! implicit real*8 (a-h,o-z)
222 ! include 'DIMENSIONS'
223 ! include 'COMMON.CHAIN'
224 ! include 'COMMON.LOCAL'
225 ! include 'COMMON.GEO'
226 ! include 'COMMON.VAR'
227 ! include 'COMMON.IOUNITS'
228 ! include 'COMMON.NAMES'
229 ! include 'COMMON.INTERACT'
231 ! Define the rotation matrices corresponding to CA(i)
235 real(kind=8) :: theti,phii
236 real(kind=8) :: cost,sint,cosphi,sinphi
241 call proc_proc(theti,icrc)
242 if(icrc.eq.1)theti=100.0
245 call proc_proc(phii,icrc)
246 if(icrc.eq.1)phii=180.0
249 if (theti.ne.theti) theti=100.0
251 if (phii.ne.phii) phii=180.0
261 ! Define the matrices of the rotation about the virtual-bond valence angles
262 ! theta, T(i,j,k), virtual-bond dihedral angles gamma (miscalled PHI in this
263 ! program), R(i,j,k), and, the cumulative matrices of rotation RT
285 rt(2,1,i-2)=sint*cosphi
286 rt(2,2,i-2)=-cost*cosphi
288 rt(3,1,i-2)=-sint*sinphi
289 rt(3,2,i-2)=cost*sinphi
291 call matmult(prod(1,1,i-2),rt(1,1,i-2),prod(1,1,i-1))
293 dc_norm(j,i-1)=prod(j,1,i-1)
294 dc(j,i-1)=vbld(i)*prod(j,1,i-1)
295 c(j,i)=c(j,i-1)+dc(j,i-1)
297 !d print '(2i3,2(3f10.5,5x))', i-1,i,(dc(j,i-1),j=1,3),(c(j,i),j=1,3)
299 ! Now calculate the coordinates of SC(i-1)
301 call locate_side_chain(i-1)
303 end subroutine locate_next_res
304 !-----------------------------------------------------------------------------
305 subroutine locate_side_chain(i)
307 ! Locate the side-chain centroid i, 1 < i < NRES. Put in C(*,NRES+i).
309 ! implicit real*8 (a-h,o-z)
310 ! include 'DIMENSIONS'
311 ! include 'COMMON.CHAIN'
312 ! include 'COMMON.LOCAL'
313 ! include 'COMMON.GEO'
314 ! include 'COMMON.VAR'
315 ! include 'COMMON.IOUNITS'
316 ! include 'COMMON.NAMES'
317 ! include 'COMMON.INTERACT'
319 real(kind=8),dimension(3) :: xx
320 real(kind=8) :: alphi,omegi,theta2
321 real(kind=8) :: dsci,dsci_inv,sinalphi,cosalphi,cosomegi,sinomegi
322 real(kind=8) :: xp,yp,zp,cost2,sint2,rj
324 ! dsci_inv=dsc_inv(itype(i))
326 dsci_inv=vbld_inv(i+nres)
333 call proc_proc(alphi,icrc)
334 if(icrc.eq.1)alphi=100.0
336 call proc_proc(omegi,icrc)
337 if(icrc.eq.1)omegi=-100.0
339 if (alphi.ne.alphi) alphi=100.0
340 if (omegi.ne.omegi) omegi=-100.0
351 yp= dsci*sinalphi*cosomegi
352 zp=-dsci*sinalphi*sinomegi
353 ! Now we have to rotate the coordinate system by 180-theta(i)/2 so as to get its
354 ! X-axis aligned with the vector DC(*,i)
355 theta2=pi-0.5D0*theta(i+1)
358 xx(1)= xp*cost2+yp*sint2
359 xx(2)=-xp*sint2+yp*cost2
361 !d print '(a3,i3,3f10.5,5x,3f10.5)',restyp(itype(i)),i,
362 !d & xp,yp,zp,(xx(k),k=1,3)
366 ! Bring the SC vectors to the common coordinate system.
368 xx(2)=xloc(2,i)*r(2,2,i-1)+xloc(3,i)*r(2,3,i-1)
369 xx(3)=xloc(2,i)*r(3,2,i-1)+xloc(3,i)*r(3,3,i-1)
376 rj=rj+prod(j,k,i-1)*xx(k)
379 dc_norm(j,nres+i)=rj*dsci_inv
380 c(j,nres+i)=c(j,i)+rj
383 end subroutine locate_side_chain
384 !-----------------------------------------------------------------------------
386 !-----------------------------------------------------------------------------
387 subroutine int_from_cart1(lprn)
388 ! implicit real*8 (a-h,o-z)
389 ! include 'DIMENSIONS'
394 ! include 'COMMON.IOUNITS'
395 ! include 'COMMON.VAR'
396 ! include 'COMMON.CHAIN'
397 ! include 'COMMON.GEO'
398 ! include 'COMMON.INTERACT'
399 ! include 'COMMON.LOCAL'
400 ! include 'COMMON.NAMES'
401 ! include 'COMMON.SETUP'
402 ! include 'COMMON.TIME1'
406 real(kind=8) :: dnorm1,dnorm2,be
409 if (lprn) write (iout,'(/a)') 'Recalculated internal coordinates'
416 !write(iout,*)"geometry warring, vbld=",(vbld(i),i=1,nres+1)
418 vbld_inv(nres+1)=0.0d0
419 vbld_inv(2*nres)=0.0d0
422 #if defined(PARINT) && defined(MPI)
423 do i=iint_start,iint_end
430 c(j,nres2+2)=0.5D0*(2*c(j,i)+(c(j,i-1)-c(j,i))/dnorm1 &
431 +(c(j,i+1)-c(j,i))/dnorm2)
435 if (i.le.nres) phi(i+1)=beta(i-2,i-1,i,i+1)
436 if ((itype(i).ne.10).and.(itype(i-1).ne.10)) then
437 tauangle(3,i+1)=beta(i+nres-1,i-1,i,i+nres)
439 if (itype(i-1).ne.10) then
440 tauangle(1,i+1)=beta(i-1+nres,i-1,i,i+1)
441 omicron(1,i)=alpha(i-2,i-1,i-1+nres)
442 omicron(2,i)=alpha(i-1+nres,i-1,i)
444 if (itype(i).ne.10) then
445 tauangle(2,i+1)=beta(i-2,i-1,i,i+nres)
448 omeg(i)=beta(nres+i,i,nres2+2,i+1)
449 alph(i)=alpha(nres+i,i,nres2+2)
450 theta(i+1)=alpha(i-1,i,i+1)
452 vbld_inv(i)=1.0d0/vbld(i)
453 vbld(nres+i)=dist(nres+i,i)
454 if (itype(i).ne.10) then
455 vbld_inv(nres+i)=1.0d0/vbld(nres+i)
457 vbld_inv(nres+i)=0.0d0
460 #if defined(PARINT) && defined(MPI)
461 if (nfgtasks1.gt.1) then
462 !d write(iout,*) "iint_start",iint_start," iint_count",
463 !d & (iint_count(i),i=0,nfgtasks-1)," iint_displ",
464 !d & (iint_displ(i),i=0,nfgtasks-1)
465 !d write (iout,*) "Gather vbld backbone"
468 call MPI_Allgatherv(vbld(iint_start),iint_count(fg_rank1),&
469 MPI_DOUBLE_PRECISION,vbld(1),iint_count(0),iint_displ(0),&
470 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
471 !d write (iout,*) "Gather vbld_inv"
473 call MPI_Allgatherv(vbld_inv(iint_start),iint_count(fg_rank1),&
474 MPI_DOUBLE_PRECISION,vbld_inv(1),iint_count(0),iint_displ(0),&
475 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
476 !d write (iout,*) "Gather vbld side chain"
478 call MPI_Allgatherv(vbld(iint_start+nres),iint_count(fg_rank1),&
479 MPI_DOUBLE_PRECISION,vbld(nres+1),iint_count(0),iint_displ(0),&
480 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
481 !d write (iout,*) "Gather vbld_inv side chain"
483 call MPI_Allgatherv(vbld_inv(iint_start+nres),&
484 iint_count(fg_rank1),MPI_DOUBLE_PRECISION,vbld_inv(nres+1),&
485 iint_count(0),iint_displ(0),MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
486 !d write (iout,*) "Gather theta"
488 call MPI_Allgatherv(theta(iint_start+1),iint_count(fg_rank1),&
489 MPI_DOUBLE_PRECISION,theta(2),iint_count(0),iint_displ(0),&
490 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
491 !d write (iout,*) "Gather phi"
493 call MPI_Allgatherv(phi(iint_start+1),iint_count(fg_rank1),&
494 MPI_DOUBLE_PRECISION,phi(2),iint_count(0),iint_displ(0),&
495 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
497 !d write (iout,*) "Gather alph"
499 call MPI_Allgatherv(alph(iint_start),iint_count(fg_rank1),&
500 MPI_DOUBLE_PRECISION,alph(1),iint_count(0),iint_displ(0),&
501 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
502 !d write (iout,*) "Gather omeg"
504 call MPI_Allgatherv(omeg(iint_start),iint_count(fg_rank1),&
505 MPI_DOUBLE_PRECISION,omeg(1),iint_count(0),iint_displ(0),&
506 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
508 time_gather=time_gather+MPI_Wtime()-time00
514 #if defined(WHAM_RUN) || defined(CLUSTER)
515 dc(j,i)=c(j,i+1)-c(j,i)
517 dc_norm(j,i)=dc(j,i)*vbld_inv(i+1)
523 #if defined(WHAM_RUN) || defined(CLUSTER)
524 dc(j,i+nres)=c(j,i+nres)-c(j,i)
526 dc_norm(j,i+nres)=dc(j,i+nres)*vbld_inv(i+nres)
531 write (iout,1212) restyp(itype(i)),i,vbld(i),&
532 rad2deg*theta(i),rad2deg*phi(i),vbld(nres+i),&
533 rad2deg*alph(i),rad2deg*omeg(i)
536 1212 format (a3,'(',i3,')',2(f15.10,2f10.2))
538 time_intfcart=time_intfcart+MPI_Wtime()-time01
541 end subroutine int_from_cart1
542 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
543 !-----------------------------------------------------------------------------
545 !-----------------------------------------------------------------------------
546 subroutine check_sc_distr
547 ! implicit real*8 (a-h,o-z)
548 ! include 'DIMENSIONS'
549 ! include 'COMMON.TIME1'
550 ! include 'COMMON.INTERACT'
551 ! include 'COMMON.NAMES'
552 ! include 'COMMON.GEO'
553 ! include 'COMMON.HEADER'
554 ! include 'COMMON.CONTROL'
556 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
557 real(kind=8) :: hrtime,mintime,sectime
558 integer,parameter :: MaxSample=10000000
559 real(kind=8),parameter :: delt=1.0D0/MaxSample
560 real(kind=8),dimension(0:72,0:90) :: prob
562 integer :: it,i,j,isample,indal,indom
563 real(kind=8) :: al,om,dV
564 dV=2.0D0*5.0D0*deg2rad*deg2rad
567 if (it.eq.10) goto 10
568 open (20,file=restyp(it)//'_distr.sdc',status='unknown')
569 call gen_side(it,90.0D0 * deg2rad,al,om,fail)
572 open (20,file=restyp(it)//'_distr1.sdc',status='unknown')
578 do isample=1,MaxSample
579 call gen_side(it,90.0D0 * deg2rad,al,om,fail)
581 indom=(rad2deg*om+180.0D0)/5
582 prob(indom,indal)=prob(indom,indal)+delt
586 write (20,'(2f10.3,1pd15.5)') 2*i+0.0D0,5*j-180.0D0,&
592 end subroutine check_sc_distr
594 !-----------------------------------------------------------------------------
596 !-----------------------------------------------------------------------------
597 subroutine geom_to_var(n,x)
599 ! Transfer the geometry parameters to the variable array.
600 ! The positions of variables are as follows:
601 ! 1. Virtual-bond torsional angles: 1 thru nres-3
602 ! 2. Virtual-bond valence angles: nres-2 thru 2*nres-5
603 ! 3. The polar angles alpha of local SC orientation: 2*nres-4 thru
605 ! 4. The torsional angles omega of SC orientation: 2*nres-4+nside+1
606 ! thru 2*nre-4+2*nside
608 ! implicit real*8 (a-h,o-z)
609 ! include 'DIMENSIONS'
610 ! include 'COMMON.VAR'
611 ! include 'COMMON.GEO'
612 ! include 'COMMON.CHAIN'
614 real(kind=8),dimension(n) :: x
615 !d print *,'nres',nres,' nphi',nphi,' ntheta',ntheta,' nvar',nvar
618 !d print *,i,i-3,phi(i)
620 if (n.eq.nphi) return
623 !d print *,i,i-2+nphi,theta(i)
625 if (n.eq.nphi+ntheta) return
627 if (ialph(i,1).gt.0) then
628 x(ialph(i,1))=alph(i)
629 x(ialph(i,1)+nside)=omeg(i)
630 !d print *,i,ialph(i,1),ialph(i,1)+nside,alph(i),omeg(i)
634 end subroutine geom_to_var
635 !-----------------------------------------------------------------------------
636 subroutine var_to_geom(n,x)
638 ! Update geometry parameters according to the variable array.
640 ! implicit real*8 (a-h,o-z)
641 ! include 'DIMENSIONS'
642 ! include 'COMMON.VAR'
643 ! include 'COMMON.CHAIN'
644 ! include 'COMMON.GEO'
645 ! include 'COMMON.IOUNITS'
647 real(kind=8),dimension(n) :: x
648 logical :: change !,reduce
655 if (n.gt.nphi+ntheta) then
658 alph(ii)=x(nphi+ntheta+i)
659 omeg(ii)=pinorm(x(nphi+ntheta+nside+i))
660 !elwrite(iout,*) "alph",ii,alph
661 !elwrite(iout,*) "omeg",ii,omeg
666 !elwrite(iout,*) "phi",i,phi
668 if (n.eq.nphi) return
671 !elwrite(iout,*) "theta",i,theta
672 if (theta(i).eq.pi) theta(i)=0.99d0*pi
676 end subroutine var_to_geom
677 !-----------------------------------------------------------------------------
678 logical function convert_side(alphi,omegi)
680 real(kind=8) :: alphi,omegi
681 !el real(kind=8) :: pinorm
682 ! include 'COMMON.GEO'
684 ! Apply periodicity restrictions.
685 if (alphi.gt.pi) then
687 omegi=pinorm(omegi+pi)
691 end function convert_side
692 !-----------------------------------------------------------------------------
693 logical function reduce(x)
695 ! Apply periodic restrictions to variables.
697 ! implicit real*8 (a-h,o-z)
698 ! include 'DIMENSIONS'
699 ! include 'COMMON.VAR'
700 ! include 'COMMON.CHAIN'
701 ! include 'COMMON.GEO'
702 logical :: zm,zmiana !,convert_side
703 real(kind=8),dimension(nvar) :: x
707 x(i-3)=pinorm(x(i-3))
709 if (nvar.gt.nphi+ntheta) then
713 x(ii)=thetnorm(x(ii))
714 x(iii)=pinorm(x(iii))
715 ! Apply periodic restrictions.
716 zm=convert_side(x(ii),x(iii))
720 if (nvar.eq.nphi) return
724 x(ii)=dmod(x(ii),dwapi)
725 ! Apply periodic restrictions.
726 if (x(ii).gt.pi) then
729 if (iii.gt.0) x(iii)=pinorm(x(iii)+pi)
730 if (i.lt.nres) x(iii+1)=pinorm(x(iii+1)+pi)
733 x(ii)=dmod(pi-x(ii),dwapi)
734 x(ii+nside)=pinorm(-x(ii+nside))
735 zm=convert_side(x(ii),x(ii+nside))
737 else if (x(ii).lt.-pi) then
742 x(ii)=dmod(pi-x(ii),dwapi)
743 x(ii+nside)=pinorm(-pi-x(ii+nside))
744 zm=convert_side(x(ii),x(ii+nside))
746 else if (x(ii).lt.0.0d0) then
749 if (iii.gt.0) x(iii)=pinorm(x(iii)+pi)
750 if (i.lt.nres) x(iii+1)=pinorm(x(iii+1)+pi)
753 x(ii+nside)=pinorm(-x(ii+nside))
754 zm=convert_side(x(ii),x(ii+nside))
761 !-----------------------------------------------------------------------------
762 real(kind=8) function thetnorm(x)
763 ! This function puts x within [0,2Pi].
766 ! include 'COMMON.GEO'
768 if (xx.lt.0.0d0) xx=xx+dwapi
769 if (xx.gt.0.9999d0*pi) xx=0.9999d0*pi
772 end function thetnorm
773 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
774 !-----------------------------------------------------------------------------
775 subroutine var_to_geom_restr(n,xx)
777 ! Update geometry parameters according to the variable array.
779 ! implicit real*8 (a-h,o-z)
780 ! include 'DIMENSIONS'
781 ! include 'COMMON.VAR'
782 ! include 'COMMON.CHAIN'
783 ! include 'COMMON.GEO'
784 ! include 'COMMON.IOUNITS'
786 real(kind=8),dimension(6*nres) :: x,xx !(maxvar) (maxvar=6*maxres)
787 logical :: change !,reduce
793 alph(ii)=x(nphi+ntheta+i)
794 omeg(ii)=pinorm(x(nphi+ntheta+nside+i))
801 if (theta(i).eq.pi) theta(i)=0.99d0*pi
805 end subroutine var_to_geom_restr
806 !-----------------------------------------------------------------------------
808 !-----------------------------------------------------------------------------
809 subroutine gen_rand_conf(nstart,*)
810 ! Generate random conformation or chain cut and regrowth.
812 ! implicit real*8 (a-h,o-z)
813 ! include 'DIMENSIONS'
814 ! include 'COMMON.CHAIN'
815 ! include 'COMMON.LOCAL'
816 ! include 'COMMON.VAR'
817 ! include 'COMMON.INTERACT'
818 ! include 'COMMON.IOUNITS'
819 ! include 'COMMON.MCM'
820 ! include 'COMMON.GEO'
821 ! include 'COMMON.CONTROL'
822 logical :: back,fail !overlap,
824 integer :: i,nstart,maxsi,nsi,maxnit,nit,niter
825 integer :: it1,it2,it,j
826 !d print *,' CG Processor',me,' maxgen=',maxgen
828 !d write (iout,*) 'Gen_Rand_conf: nstart=',nstart
829 if (nstart.lt.5) then
831 phi(4)=gen_phi(4,iabs(itype(2)),iabs(itype(3)))
832 ! write(iout,*)'phi(4)=',rad2deg*phi(4)
833 if (nstart.lt.3) theta(3)=gen_theta(iabs(itype(2)),pi,phi(4))
834 ! write(iout,*)'theta(3)=',rad2deg*theta(3)
838 do while (fail.and.nsi.le.maxsi)
839 call gen_side(it1,theta(3),alph(2),omeg(2),fail)
842 if (nsi.gt.maxsi) return 1
857 do while (i.le.nres .and. niter.lt.maxgen)
858 if (i.lt.nstart) then
860 write (iout,'(/80(1h*)/2a/80(1h*))') &
861 'Generation procedure went down to ',&
862 'chain beginning. Cannot continue...'
863 write (*,'(/80(1h*)/2a/80(1h*))') &
864 'Generation procedure went down to ',&
865 'chain beginning. Cannot continue...'
872 ! print *,'Gen_Rand_Conf: i=',i,' it=',it,' it1=',it1,' it2=',it2,
873 ! & ' nit=',nit,' niter=',niter,' maxgen=',maxgen
874 phi(i+1)=gen_phi(i+1,it1,it)
876 phi(i)=gen_phi(i+1,it2,it1)
877 ! print *,'phi(',i,')=',phi(i)
878 theta(i-1)=gen_theta(it2,phi(i-1),phi(i))
882 do while (fail.and.nsi.le.maxsi)
883 call gen_side(it2,theta(i-1),alph(i-2),omeg(i-2),fail)
886 if (nsi.gt.maxsi) return 1
888 call locate_next_res(i-1)
890 theta(i)=gen_theta(it1,phi(i),phi(i+1))
894 do while (fail.and.nsi.le.maxsi)
895 call gen_side(it1,theta(i),alph(i-1),omeg(i-1),fail)
898 if (nsi.gt.maxsi) return 1
900 call locate_next_res(i)
901 if (overlap(i-1)) then
902 if (nit.lt.maxnit) then
912 'Cannot generate non-overlaping conformation. Increase MAXNIT.'
914 'Cannot generate non-overlaping conformation. Increase MAXNIT.'
925 if (niter.ge.maxgen) then
926 write (iout,'(a,2i5)') &
927 'Too many trials in conformation generation',niter,maxgen
928 write (*,'(a,2i5)') &
929 'Too many trials in conformation generation',niter,maxgen
934 c(j,nres+nres)=c(j,nres)
937 end subroutine gen_rand_conf
938 !-----------------------------------------------------------------------------
939 logical function overlap(i)
940 ! implicit real*8 (a-h,o-z)
941 ! include 'DIMENSIONS'
942 ! include 'COMMON.CHAIN'
943 ! include 'COMMON.INTERACT'
944 ! include 'COMMON.FFIELD'
945 integer :: i,j,iti,itj,iteli,itelj,k
946 real(kind=8) :: redfac,rcomp
952 if (iti.gt.ntyp) return
953 ! Check for SC-SC overlaps.
954 !d print *,'nnt=',nnt,' nct=',nct
957 if (j.lt.i-1 .or. ipot.ne.4) then
958 rcomp=sigmaii(iti,itj)
963 if (dist(nres+i,nres+j).lt.redfac*rcomp) then
965 ! print *,'overlap, SC-SC: i=',i,' j=',j,
966 ! & ' dist=',dist(nres+i,nres+j),' rcomp=',
971 ! Check for overlaps between the added peptide group and the preceding
975 ! c(j,nres2+1)=0.5D0*(c(j,i)+c(j,i+1))
976 c(j,nres2+3)=0.5D0*(c(j,i)+c(j,i+1))
980 !d print *,'overlap, p-Sc: i=',i,' j=',j,
981 !d & ' dist=',dist(nres+j,maxres2+1)
982 if (dist(nres+j,nres2+3).lt.4.0D0*redfac) then
987 ! Check for overlaps between the added side chain and the preceding peptide
991 c(k,nres2+3)=0.5D0*(c(k,j)+c(k,j+1))
993 !d print *,'overlap, SC-p: i=',i,' j=',j,
994 !d & ' dist=',dist(nres+i,maxres2+1)
995 if (dist(nres+i,nres2+3).lt.4.0D0*redfac) then
1000 ! Check for p-p overlaps
1002 c(j,nres2+4)=0.5D0*(c(j,i)+c(j,i+1))
1007 c(k,nres2+4)=0.5D0*(c(k,j)+c(k,j+1))
1009 !d print *,'overlap, p-p: i=',i,' j=',j,
1010 !d & ' dist=',dist(maxres2+1,maxres2+2)
1011 if(iteli.ne.0.and.itelj.ne.0)then
1012 if (dist(nres2+3,nres2+4).lt.rpp(iteli,itelj)*redfac) then
1019 end function overlap
1020 !-----------------------------------------------------------------------------
1021 real(kind=8) function gen_phi(i,it1,it2)
1022 use random, only:ran_number
1023 ! implicit real*8 (a-h,o-z)
1024 ! include 'DIMENSIONS'
1025 ! include 'COMMON.GEO'
1026 ! include 'COMMON.BOUNDS'
1027 integer :: i,it1,it2
1028 ! gen_phi=ran_number(-pi,pi)
1029 ! 8/13/98 Generate phi using pre-defined boundaries
1030 gen_phi=ran_number(phibound(1,i),phibound(2,i))
1032 end function gen_phi
1033 !-----------------------------------------------------------------------------
1034 real(kind=8) function gen_theta(it,gama,gama1)
1035 use random,only:binorm
1036 ! implicit real*8 (a-h,o-z)
1037 ! include 'DIMENSIONS'
1038 ! include 'COMMON.LOCAL'
1039 ! include 'COMMON.GEO'
1040 real(kind=8),dimension(2) :: y,z
1041 real(kind=8) :: theta_max,theta_min,sig,ak
1044 real(kind=8) :: gama,gama1,thet_pred_mean,theta_temp
1045 ! print *,'gen_theta: it=',it
1048 if (dabs(gama).gt.dwapi) then
1055 if (dabs(gama1).gt.dwapi) then
1062 thet_pred_mean=a0thet(it)
1064 thet_pred_mean=thet_pred_mean+athet(k,it,1,1)*y(k) &
1065 +bthet(k,it,1,1)*z(k)
1069 sig=sig*thet_pred_mean+polthet(j,it)
1071 sig=0.5D0/(sig*sig+sigc0(it))
1072 ak=dexp(gthet(1,it)- &
1073 0.5D0*((gthet(2,it)-thet_pred_mean)/gthet(3,it))**2)
1074 ! print '(i5,5(1pe14.4))',it,(gthet(j,it),j=1,3)
1075 ! print '(5(1pe14.4))',thet_pred_mean,theta0(it),sig,sig0(it),ak
1076 theta_temp=binorm(thet_pred_mean,theta0(it),sig,sig0(it),ak)
1077 if (theta_temp.lt.theta_min) theta_temp=theta_min
1078 if (theta_temp.gt.theta_max) theta_temp=theta_max
1079 gen_theta=theta_temp
1080 ! print '(a)','Exiting GENTHETA.'
1082 end function gen_theta
1083 !-----------------------------------------------------------------------------
1084 subroutine gen_side(it,the,al,om,fail)
1085 use random, only:ran_number,mult_norm1
1086 ! implicit real*8 (a-h,o-z)
1087 ! include 'DIMENSIONS'
1088 ! include 'COMMON.GEO'
1089 ! include 'COMMON.LOCAL'
1090 ! include 'COMMON.SETUP'
1091 ! include 'COMMON.IOUNITS'
1092 real(kind=8) :: MaxBoxLen=10.0D0
1093 real(kind=8),dimension(3,3) :: Ap_inv,a,vec
1094 real(kind=8),dimension(:,:),allocatable :: z !(3,maxlob)
1095 real(kind=8),dimension(:),allocatable :: W1,detAp !(maxlob)
1096 real(kind=8),dimension(:),allocatable :: sumW !(0:maxlob)
1097 real(kind=8),dimension(2) :: y,cm,eig
1098 real(kind=8),dimension(2,2) :: box
1099 real(kind=8),dimension(100) :: work
1100 real(kind=8) :: eig_limit=1.0D-8
1101 real(kind=8) :: Big=10.0D0
1102 logical :: lprint,fail,lcheck
1104 integer :: it,i,j,k,l,nlobit,ial,iom,iii,ilob
1105 real(kind=8) :: the,al,om,detApi,wart,y2,wykl,radmax
1106 real(kind=8) :: tant,zz1,W1i,radius,zk,fac,dV,sum,sum1
1107 real(kind=8) :: which_lobe
1111 if (the.eq.0.0D0 .or. the.eq.pi) then
1113 write (*,'(a,i4,a,i3,a,1pe14.5)') &
1114 'CG Processor:',me,' Error in GenSide: it=',it,' theta=',the
1116 !d write (iout,'(a,i3,a,1pe14.5)')
1117 !d & 'Error in GenSide: it=',it,' theta=',the
1122 tant=dtan(the-pipol)
1124 allocate(z(3,nlobit))
1125 allocate(W1(nlobit))
1126 allocate(detAp(nlobit))
1127 allocate(sumW(0:nlobit))
1130 print '(a,i4,a)','CG Processor:',me,' Enter Gen_Side.'
1131 write (iout,'(a,i4,a)') 'Processor:',me,' Enter Gen_Side.'
1133 print *,'it=',it,' nlobit=',nlobit,' the=',the,' tant=',tant
1134 write (iout,*) 'it=',it,' nlobit=',nlobit,' the=',the,&
1138 zz1=tant-censc(1,i,it)
1141 a(k,l)=gaussc(k,l,i,it)
1144 detApi=a(2,2)*a(3,3)-a(2,3)**2
1145 Ap_inv(2,2)=a(3,3)/detApi
1146 Ap_inv(2,3)=-a(2,3)/detApi
1147 Ap_inv(3,2)=Ap_inv(2,3)
1148 Ap_inv(3,3)=a(2,2)/detApi
1150 write (*,'(/a,i2/)') 'Cluster #',i
1151 write (*,'(3(1pe14.5),5x,1pe14.5)') &
1152 ((a(l,k),l=1,3),censc(k,i,it),k=1,3)
1153 write (iout,'(/a,i2/)') 'Cluster #',i
1154 write (iout,'(3(1pe14.5),5x,1pe14.5)') &
1155 ((a(l,k),l=1,3),censc(k,i,it),k=1,3)
1160 W1i=W1i+a(k,1)*a(l,1)*Ap_inv(k,l)
1164 W1(i)=dexp(bsc(i,it)-0.5D0*W1i*zz1*zz1)
1165 ! if (lprint) write(*,'(a,3(1pe15.5)/)')
1166 ! & 'detAp, W1, anormi',detApi,W1i,anormi
1170 zk=zk+zz1*Ap_inv(k,l)*a(l,1)
1174 detAp(i)=dsqrt(detApi)
1178 print *,'W1:',(w1(i),i=1,nlobit)
1179 print *,'detAp:',(detAp(i),i=1,nlobit)
1182 print '(i2,3f10.5)',i,(rad2deg*z(j,i),j=2,3)
1184 write (iout,*) 'W1:',(w1(i),i=1,nlobit)
1185 write (iout,*) 'detAp:',(detAp(i),i=1,nlobit)
1188 write (iout,'(i2,3f10.5)') i,(rad2deg*z(j,i),j=2,3)
1192 ! Writing the distribution just to check the procedure
1194 dV=deg2rad**2*10.0D0
1198 fac=fac+W1(i)/detAp(i)
1200 fac=1.0D0/(2.0D0*fac*pi)
1201 !d print *,it,'fac=',fac
1210 a(j-1,k-1)=gaussc(j,k,i,it)
1222 wykl=wykl+a(j,k)*(y(j)-z(j+1,i))*(y(k)-z(k+1,i))
1225 wart=wart+W1(i)*dexp(-0.5D0*wykl)
1232 ! print *,'y',y(1),y(2),' fac=',fac
1234 write (20,'(2f10.3,1pd15.5)') y(1)*rad2deg,y(2)*rad2deg,wart
1239 ! print *,'it=',it,' sum=',sum*dV,' sum1=',sum1*dV
1243 ! Calculate the CM of the system
1246 W1(i)=W1(i)/detAp(i)
1250 sumW(i)=sumW(i-1)+W1(i)
1255 cm(1)=cm(1)+z(2,j)*W1(j)
1256 cm(2)=cm(2)+W1(j)*(z(3,1)+pinorm(z(3,j)-z(3,1)))
1258 cm(1)=cm(1)/sumW(nlobit)
1259 cm(2)=cm(2)/sumW(nlobit)
1260 if (cm(1).gt.Big .or. cm(1).lt.-Big .or. &
1261 cm(2).gt.Big .or. cm(2).lt.-Big) then
1262 !d write (iout,'(a)')
1263 !d & 'Unexpected error in GenSide - CM coordinates too large.'
1264 !d write (iout,'(i5,2(1pe14.5))') it,cm(1),cm(2)
1266 !d & 'Unexpected error in GenSide - CM coordinates too large.'
1267 !d write (*,'(i5,2(1pe14.5))') it,cm(1),cm(2)
1271 !d print *,'CM:',cm(1),cm(2)
1273 ! Find the largest search distance from CM
1279 a(j-1,k-1)=gaussc(j,k,i,it)
1283 call f02faf('N','U',2,a,3,eig,work,100,ifail)
1285 call djacob(2,3,10000,1.0d-10,a,vec,eig)
1289 print *,'*************** CG Processor',me
1290 print *,'CM:',cm(1),cm(2)
1291 write (iout,*) '*************** CG Processor',me
1292 write (iout,*) 'CM:',cm(1),cm(2)
1293 print '(A,8f10.5)','Eigenvalues: ',(1.0/dsqrt(eig(k)),k=1,2)
1294 write (iout,'(A,8f10.5)') &
1295 'Eigenvalues: ',(1.0/dsqrt(eig(k)),k=1,2)
1298 if (eig(1).lt.eig_limit) then
1300 'From Mult_Norm: Eigenvalues of A are too small.'
1302 'From Mult_Norm: Eigenvalues of A are too small.'
1309 radius=radius+pinorm(z(j+1,i)-cm(j))**2
1311 radius=dsqrt(radius)+3.0D0/dsqrt(eig(1))
1312 if (radius.gt.radmax) radmax=radius
1314 if (radmax.gt.pi) radmax=pi
1316 ! Determine the boundaries of the search rectangle.
1319 print '(a,4(1pe14.4))','W1: ',(W1(i),i=1,nlob(it) )
1320 print '(a,4(1pe14.4))','radmax: ',radmax
1322 box(1,1)=dmax1(cm(1)-radmax,0.0D0)
1323 box(2,1)=dmin1(cm(1)+radmax,pi)
1324 box(1,2)=cm(2)-radmax
1325 box(2,2)=cm(2)+radmax
1328 print *,'CG Processor',me,' Array BOX:'
1330 print *,'Array BOX:'
1332 print '(4(1pe14.4))',((box(k,j),k=1,2),j=1,2)
1333 print '(a,4(1pe14.4))','sumW: ',(sumW(i),i=0,nlob(it) )
1335 write (iout,*)'CG Processor',me,' Array BOX:'
1337 write (iout,*)'Array BOX:'
1339 write(iout,'(4(1pe14.4))') ((box(k,j),k=1,2),j=1,2)
1340 write(iout,'(a,4(1pe14.4))')'sumW: ',(sumW(i),i=0,nlob(it) )
1342 if (box(1,2).lt.-MaxBoxLen .or. box(2,2).gt.MaxBoxLen) then
1344 write (iout,'(a,i4,a,3e15.5)') 'CG Processor:',me,': bad sampling box.',box(1,2),box(2,2),radmax
1345 write (*,'(a,i4,a)') 'CG Processor:',me,': bad sampling box.'
1347 ! write (iout,'(a)') 'Bad sampling box.'
1352 which_lobe=ran_number(0.0D0,sumW(nlobit))
1353 ! print '(a,1pe14.4)','which_lobe=',which_lobe
1355 if (sumW(i-1).le.which_lobe .and. sumW(i).ge.which_lobe) goto 1
1358 ! print *,'ilob=',ilob,' nlob=',nlob(it)
1362 a(i-1,j-1)=gaussc(i,j,ilob,it)
1365 !d print '(a,i4,a)','CG Processor',me,' Calling MultNorm1.'
1366 call mult_norm1(3,2,a,cm,box,y,fail)
1370 !d print *,'al=',al,' om=',om
1373 end subroutine gen_side
1374 !-----------------------------------------------------------------------------
1375 subroutine overlap_sc(scfail)
1377 ! Internal and cartesian coordinates must be consistent as input,
1378 ! and will be up-to-date on return.
1379 ! At the end of this procedure, scfail is true if there are
1380 ! overlapping residues left, or false otherwise (success)
1382 ! implicit real*8 (a-h,o-z)
1383 ! include 'DIMENSIONS'
1384 ! include 'COMMON.CHAIN'
1385 ! include 'COMMON.INTERACT'
1386 ! include 'COMMON.FFIELD'
1387 ! include 'COMMON.VAR'
1388 ! include 'COMMON.SBRIDGE'
1389 ! include 'COMMON.IOUNITS'
1390 logical :: had_overlaps,fail,scfail
1391 integer,dimension(nres) :: ioverlap !(maxres)
1392 integer :: ioverlap_last,k,maxsi,i,iti,nsi
1395 had_overlaps=.false.
1396 call overlap_sc_list(ioverlap,ioverlap_last)
1397 if (ioverlap_last.gt.0) then
1398 write (iout,*) '#OVERLAPing residues ',ioverlap_last
1399 write (iout,'(20i4)') (ioverlap(k),k=1,ioverlap_last)
1405 if (ioverlap_last.eq.0) exit
1407 do ires=1,ioverlap_last
1413 do while (fail.and.nsi.le.maxsi)
1414 call gen_side(iti,theta(i+1),alph(i),omeg(i),fail)
1422 call overlap_sc_list(ioverlap,ioverlap_last)
1423 ! write (iout,*) 'Overlaping residues ',ioverlap_last,
1424 ! & (ioverlap(j),j=1,ioverlap_last)
1427 if (k.le.1000.and.ioverlap_last.eq.0) then
1429 if (had_overlaps) then
1430 write (iout,*) '#OVERLAPing all corrected after ',k,&
1431 ' random generation'
1435 write (iout,*) '#OVERLAPing NOT all corrected ',ioverlap_last
1436 write (iout,'(20i4)') (ioverlap(j),j=1,ioverlap_last)
1442 write (iout,'(a30,i5,a12,i4)') &
1443 '#OVERLAP FAIL in gen_side after',maxsi,&
1447 end subroutine overlap_sc
1448 !-----------------------------------------------------------------------------
1449 subroutine overlap_sc_list(ioverlap,ioverlap_last)
1451 ! implicit real*8 (a-h,o-z)
1452 ! include 'DIMENSIONS'
1453 ! include 'COMMON.GEO'
1454 ! include 'COMMON.LOCAL'
1455 ! include 'COMMON.IOUNITS'
1456 ! include 'COMMON.CHAIN'
1457 ! include 'COMMON.INTERACT'
1458 ! include 'COMMON.FFIELD'
1459 ! include 'COMMON.VAR'
1460 ! include 'COMMON.CALC'
1462 integer,dimension(nres) :: ioverlap !(maxres)
1463 integer :: ioverlap_last
1466 real(kind=8) :: redfac,sig !rrij,sigsq,
1467 integer :: itypi,itypj,itypi1
1468 real(kind=8) :: xi,yi,zi,sig0ij,rcomp,rrij,rij_shift
1472 ! Check for SC-SC overlaps and mark residues
1473 ! print *,'>>overlap_sc nnt=',nnt,' nct=',nct
1475 do i=iatsc_s,iatsc_e
1476 itypi=iabs(itype(i))
1477 itypi1=iabs(itype(i+1))
1481 dxi=dc_norm(1,nres+i)
1482 dyi=dc_norm(2,nres+i)
1483 dzi=dc_norm(3,nres+i)
1484 dsci_inv=dsc_inv(itypi)
1486 do iint=1,nint_gr(i)
1487 do j=istart(i,iint),iend(i,iint)
1489 itypj=iabs(itype(j))
1490 dscj_inv=dsc_inv(itypj)
1491 sig0ij=sigma(itypi,itypj)
1492 chi1=chi(itypi,itypj)
1493 chi2=chi(itypj,itypi)
1500 alf12=0.5D0*(alf1+alf2)
1502 rcomp=sigmaii(itypi,itypj)
1504 rcomp=sigma(itypi,itypj)
1506 ! print '(2(a3,2i3),a3,2f10.5)',
1507 ! & ' i=',i,iti,' j=',j,itj,' d=',dist(nres+i,nres+j)
1512 dxj=dc_norm(1,nres+j)
1513 dyj=dc_norm(2,nres+j)
1514 dzj=dc_norm(3,nres+j)
1515 rrij=1.0D0/(xj*xj+yj*yj+zj*zj)
1519 sig=sig0ij*dsqrt(sigsq)
1520 rij_shift=1.0D0/rij-sig+sig0ij
1522 !t if ( 1.0/rij .lt. redfac*rcomp .or.
1523 !t & rij_shift.le.0.0D0 ) then
1524 if ( rij_shift.le.0.0D0 ) then
1525 !d write (iout,'(a,i3,a,i3,a,f10.5,a,3f10.5)')
1526 !d & 'overlap SC-SC: i=',i,' j=',j,
1527 !d & ' dist=',dist(nres+i,nres+j),' rcomp=',
1528 !d & rcomp,1.0/rij,rij_shift
1529 ioverlap_last=ioverlap_last+1
1530 ioverlap(ioverlap_last)=i
1531 do k=1,ioverlap_last-1
1532 if (ioverlap(k).eq.i) ioverlap_last=ioverlap_last-1
1534 ioverlap_last=ioverlap_last+1
1535 ioverlap(ioverlap_last)=j
1536 do k=1,ioverlap_last-1
1537 if (ioverlap(k).eq.j) ioverlap_last=ioverlap_last-1
1544 end subroutine overlap_sc_list
1546 !-----------------------------------------------------------------------------
1547 ! energy_p_new_barrier.F
1548 !-----------------------------------------------------------------------------
1549 subroutine sc_angular
1550 ! Calculate eps1,eps2,eps3,sigma, and parts of their derivatives in om1,om2,
1551 ! om12. Called by ebp, egb, and egbv.
1554 ! include 'COMMON.CALC'
1555 ! include 'COMMON.IOUNITS'
1559 om1=dxi*erij(1)+dyi*erij(2)+dzi*erij(3)
1560 om2=dxj*erij(1)+dyj*erij(2)+dzj*erij(3)
1561 om12=dxi*dxj+dyi*dyj+dzi*dzj
1563 ! Calculate eps1(om12) and its derivative in om12
1564 faceps1=1.0D0-om12*chiom12
1565 faceps1_inv=1.0D0/faceps1
1566 eps1=dsqrt(faceps1_inv)
1567 ! Following variable is eps1*deps1/dom12
1568 eps1_om12=faceps1_inv*chiom12
1573 ! write (iout,*) "om12",om12," eps1",eps1
1574 ! Calculate sigma(om1,om2,om12) and the derivatives of sigma**2 in om1,om2,
1579 facsig=om1*chiom1+om2*chiom2-2.0D0*om1om2*chiom12
1580 sigsq=1.0D0-facsig*faceps1_inv
1581 sigsq_om1=(chiom1-chiom12*om2)*faceps1_inv
1582 sigsq_om2=(chiom2-chiom12*om1)*faceps1_inv
1583 sigsq_om12=-chi12*(om1om2*faceps1-om12*facsig)*faceps1_inv**2
1589 ! write (iout,*) "chiom1",chiom1," chiom2",chiom2," chiom12",chiom12
1590 ! write (iout,*) "faceps1",faceps1," faceps1_inv",faceps1_inv,
1592 ! Calculate eps2 and its derivatives in om1, om2, and om12.
1595 chipom12=chip12*om12
1596 facp=1.0D0-om12*chipom12
1598 facp1=om1*chipom1+om2*chipom2-2.0D0*om1om2*chipom12
1599 ! write (iout,*) "chipom1",chipom1," chipom2",chipom2,
1600 ! & " chipom12",chipom12," facp",facp," facp_inv",facp_inv
1601 ! Following variable is the square root of eps2
1602 eps2rt=1.0D0-facp1*facp_inv
1603 ! Following three variables are the derivatives of the square root of eps
1604 ! in om1, om2, and om12.
1605 eps2rt_om1=-4.0D0*(chipom1-chipom12*om2)*facp_inv
1606 eps2rt_om2=-4.0D0*(chipom2-chipom12*om1)*facp_inv
1607 eps2rt_om12=4.0D0*chip12*(om1om2*facp-om12*facp1)*facp_inv**2
1608 ! Evaluate the "asymmetric" factor in the VDW constant, eps3
1609 eps3rt=1.0D0-alf1*om1+alf2*om2-alf12*om12
1610 ! write (iout,*) "eps2rt",eps2rt," eps3rt",eps3rt
1611 ! write (iout,*) "eps2rt_om1",eps2rt_om1," eps2rt_om2",eps2rt_om2,
1612 ! & " eps2rt_om12",eps2rt_om12
1613 ! Calculate whole angle-dependent part of epsilon and contributions
1614 ! to its derivatives
1616 end subroutine sc_angular
1617 !-----------------------------------------------------------------------------
1619 !-----------------------------------------------------------------------------
1620 subroutine int_bounds(total_ints,lower_bound,upper_bound)
1621 ! implicit real*8 (a-h,o-z)
1622 ! include 'DIMENSIONS'
1624 ! include 'COMMON.SETUP'
1625 integer :: total_ints,lower_bound,upper_bound,nint
1626 integer,dimension(0:nfgtasks) :: int4proc,sint4proc !(0:max_fg_procs)
1627 integer :: i,nexcess
1628 nint=total_ints/nfgtasks
1632 nexcess=total_ints-nint*nfgtasks
1634 int4proc(nfgtasks-i)=int4proc(nfgtasks-i)+1
1638 lower_bound=lower_bound+int4proc(i)
1640 upper_bound=lower_bound+int4proc(fg_rank)
1641 lower_bound=lower_bound+1
1643 end subroutine int_bounds
1644 !-----------------------------------------------------------------------------
1645 subroutine int_bounds1(total_ints,lower_bound,upper_bound)
1646 ! implicit real*8 (a-h,o-z)
1647 ! include 'DIMENSIONS'
1649 ! include 'COMMON.SETUP'
1650 integer :: total_ints,lower_bound,upper_bound,nint
1651 integer :: nexcess,i
1652 integer,dimension(0:nfgtasks) :: int4proc,sint4proc !(0:max_fg_procs)
1653 nint=total_ints/nfgtasks1
1657 nexcess=total_ints-nint*nfgtasks1
1659 int4proc(nfgtasks1-i)=int4proc(nfgtasks1-i)+1
1663 lower_bound=lower_bound+int4proc(i)
1665 upper_bound=lower_bound+int4proc(fg_rank1)
1666 lower_bound=lower_bound+1
1668 end subroutine int_bounds1
1669 !-----------------------------------------------------------------------------
1671 !-----------------------------------------------------------------------------
1672 subroutine chainbuild_cart
1673 ! implicit real*8 (a-h,o-z)
1674 ! include 'DIMENSIONS'
1679 ! include 'COMMON.SETUP'
1680 ! include 'COMMON.CHAIN'
1681 ! include 'COMMON.LOCAL'
1682 ! include 'COMMON.TIME1'
1683 ! include 'COMMON.IOUNITS'
1684 integer :: j,i,ierror,ierr
1685 real(kind=8) :: time00,time01
1687 if (nfgtasks.gt.1) then
1688 ! write (iout,*) "BCAST in chainbuild_cart"
1690 ! Broadcast the order to build the chain and compute internal coordinates
1691 ! to the slaves. The slaves receive the order in ERGASTULUM.
1693 ! write (iout,*) "CHAINBUILD_CART: DC before BCAST"
1695 ! write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),
1696 ! & (dc(j,i+nres),j=1,3)
1699 call MPI_Bcast(7,1,MPI_INTEGER,king,FG_COMM,IERROR)
1700 time_bcast7=time_bcast7+MPI_Wtime()-time00
1702 call MPI_Bcast(dc(1,0),6*(nres+1),MPI_DOUBLE_PRECISION,&
1704 ! write (iout,*) "CHAINBUILD_CART: DC after BCAST"
1706 ! write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),
1707 ! & (dc(j,i+nres),j=1,3)
1709 ! write (iout,*) "End BCAST in chainbuild_cart"
1711 time_bcast=time_bcast+MPI_Wtime()-time00
1712 time_bcastc=time_bcastc+MPI_Wtime()-time01
1720 c(j,i)=c(j,i-1)+dc(j,i-1)
1725 c(j,i+nres)=c(j,i)+dc(j,i+nres)
1728 ! write (iout,*) "CHAINBUILD_CART"
1730 call int_from_cart1(.false.)
1732 end subroutine chainbuild_cart
1733 !-----------------------------------------------------------------------------
1735 !-----------------------------------------------------------------------------
1736 real(kind=8) function alpha(i1,i2,i3)
1738 ! Calculates the planar angle between atoms (i1), (i2), and (i3).
1740 ! implicit real*8 (a-h,o-z)
1741 ! include 'DIMENSIONS'
1742 ! include 'COMMON.GEO'
1743 ! include 'COMMON.CHAIN'
1746 real(kind=8) :: x12,x23,y12,y23,z12,z23,vnorm,wnorm,scalar
1753 vnorm=dsqrt(x12*x12+y12*y12+z12*z12)
1754 wnorm=dsqrt(x23*x23+y23*y23+z23*z23)
1755 scalar=(x12*x23+y12*y23+z12*z23)/(vnorm*wnorm)
1759 !-----------------------------------------------------------------------------
1760 real(kind=8) function beta(i1,i2,i3,i4)
1762 ! Calculates the dihedral angle between atoms (i1), (i2), (i3) and (i4)
1764 ! implicit real*8 (a-h,o-z)
1765 ! include 'DIMENSIONS'
1766 ! include 'COMMON.GEO'
1767 ! include 'COMMON.CHAIN'
1769 integer :: i1,i2,i3,i4
1770 real(kind=8) :: x12,x23,x34,y12,y23,y34,z12,z23,z34
1771 real(kind=8) :: wx,wy,wz,wnorm,vx,vy,vz,vnorm,scalar,angle
1772 real(kind=8) :: tx,ty,tz
1782 !d print '(2i3,3f10.5)',i1,i2,x12,y12,z12
1783 !d print '(2i3,3f10.5)',i2,i3,x23,y23,z23
1784 !d print '(2i3,3f10.5)',i3,i4,x34,y34,z34
1788 wnorm=dsqrt(wx*wx+wy*wy+wz*wz)
1792 vnorm=dsqrt(vx*vx+vy*vy+vz*vz)
1793 if (vnorm.gt.1.0D-13 .and. wnorm.gt.1.0D-13) then
1794 scalar=(vx*wx+vy*wy+vz*wz)/(vnorm*wnorm)
1795 if (dabs(scalar).gt.1.0D0) &
1796 scalar=0.99999999999999D0*scalar/dabs(scalar)
1798 !d print '(2i4,10f7.3)',i2,i3,vx,vy,vz,wx,wy,wz,vnorm,wnorm,
1803 ! if (angle.le.0.0D0) angle=pi+angle
1807 scalar=tx*x23+ty*y23+tz*z23
1808 if (scalar.lt.0.0D0) angle=-angle
1812 !-----------------------------------------------------------------------------
1813 real(kind=8) function dist(i1,i2)
1815 ! Calculates the distance between atoms (i1) and (i2).
1817 ! implicit real*8 (a-h,o-z)
1818 ! include 'DIMENSIONS'
1819 ! include 'COMMON.GEO'
1820 ! include 'COMMON.CHAIN'
1823 real(kind=8) :: x12,y12,z12
1827 dist=dsqrt(x12*x12+y12*y12+z12*z12)
1830 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
1831 !-----------------------------------------------------------------------------
1833 !-----------------------------------------------------------------------------
1834 subroutine local_move_init(debug)
1838 ! implicit real*8 (a-h,o-z)
1839 ! include 'DIMENSIONS' ! Needed by COMMON.LOCAL
1840 ! include 'COMMON.GEO' ! For pi, deg2rad
1841 ! include 'COMMON.LOCAL' ! For vbl
1842 ! include 'COMMON.LOCMOVE'
1848 ! Determine wheter to do some debugging output
1849 locmove_output=debug
1851 ! Set the init_called flag to 1
1854 ! The following are never changed
1855 min_theta=60.D0*deg2rad ! (0,PI)
1856 max_theta=175.D0*deg2rad ! (0,PI)
1857 dmin2=vbl*vbl*2.*(1.-cos(min_theta))
1858 dmax2=vbl*vbl*2.*(1.-cos(max_theta))
1861 small2=0.5*small*small
1863 ! Not really necessary...
1869 end subroutine local_move_init
1870 !-----------------------------------------------------------------------------
1871 subroutine local_move(n_start, n_end, PHImin, PHImax)
1872 ! Perform a local move between residues m and n (inclusive)
1873 ! PHImin and PHImax [0,PI] determine the size of the move
1874 ! Works on whatever structure is in the variables theta and phi,
1875 ! sidechain variables are left untouched
1876 ! The final structure is NOT minimized, but both the cartesian
1877 ! variables c and the angles are up-to-date at the end (no further
1878 ! chainbuild is required)
1880 use random,only:ran_number
1882 ! implicit real*8 (a-h,o-z)
1883 ! include 'DIMENSIONS'
1884 ! include 'COMMON.GEO'
1885 ! include 'COMMON.CHAIN'
1886 ! include 'COMMON.VAR'
1887 ! include 'COMMON.MINIM'
1888 ! include 'COMMON.SBRIDGE'
1889 ! include 'COMMON.LOCMOVE'
1891 ! External functions
1892 !EL integer move_res
1893 !EL external move_res
1894 !EL double precision ran_number
1895 !EL external ran_number
1898 integer :: n_start, n_end ! First and last residues to move
1899 real(kind=8) :: PHImin, PHImax ! min/max angles [0,PI]
1903 real(kind=8) :: min,max
1907 ! Check if local_move_init was called. This assumes that it
1908 ! would not be 1 if not explicitely initialized
1909 if (init_called.ne.1) then
1910 write(6,*)' *** local_move_init not called!!!'
1914 ! Quick check for crazy range
1915 if (n_start.gt.n_end .or. n_start.lt.1 .or. n_end.gt.nres) then
1916 write(6,'(a,i3,a,i3)') &
1917 ' *** Cannot make local move between n_start = ',&
1918 n_start,' and n_end = ',n_end
1922 ! Take care of end residues first...
1923 if (n_start.eq.1) then
1924 ! Move residue 1 (completely random)
1925 theta(3)=ran_number(min_theta,max_theta)
1926 phi(4)=ran_number(-PI,PI)
1931 if (n_end.eq.nres) then
1932 ! Move residue nres (completely random)
1933 theta(nres)=ran_number(min_theta,max_theta)
1934 phi(nres)=ran_number(-PI,PI)
1940 ! ...then go through all other residues one by one
1941 ! Start from the two extremes and converge
1946 !$$$c Move the first two residues by less than the others
1947 !$$$ if (i-n_start.lt.3) then
1948 !$$$ if (i-n_start.eq.0) then
1951 !$$$ else if (i-n_start.eq.1) then
1954 !$$$ else if (i-n_start.eq.2) then
1960 ! The actual move, on residue i
1961 iretcode=move_res(min,max,i) ! Discard iretcode
1967 !$$$c Move the last two residues by less than the others
1968 !$$$ if (n_end-j.lt.3) then
1969 !$$$ if (n_end-j.eq.0) then
1972 !$$$ else if (n_end-j.eq.1) then
1975 !$$$ else if (n_end-j.eq.2) then
1981 ! The actual move, on residue j
1982 iretcode=move_res(min,max,j) ! Discard iretcode
1987 call int_from_cart(.false.,.false.)
1990 end subroutine local_move
1991 !-----------------------------------------------------------------------------
1992 subroutine output_tabs
1993 ! Prints out the contents of a_..., b_..., res_...
1997 ! include 'COMMON.GEO'
1998 ! include 'COMMON.LOCMOVE'
2004 write(6,'(8f7.1)')(a_ang(i)*rad2deg,i=0,a_n-1)
2005 write(6,'(8(2x,3l1,2x))')((a_tab(i,j),i=0,2),j=0,a_n-1)
2008 write(6,'(4f7.1)')(b_ang(i)*rad2deg,i=0,b_n-1)
2009 write(6,'(4(2x,3l1,2x))')((b_tab(i,j),i=0,2),j=0,b_n-1)
2012 write(6,'(12f7.1)')(res_ang(i)*rad2deg,i=0,res_n-1)
2013 write(6,'(12(2x,3l1,2x))')((res_tab(0,i,j),i=0,2),j=0,res_n-1)
2014 write(6,'(12(2x,3l1,2x))')((res_tab(1,i,j),i=0,2),j=0,res_n-1)
2015 write(6,'(12(2x,3l1,2x))')((res_tab(2,i,j),i=0,2),j=0,res_n-1)
2018 end subroutine output_tabs
2019 !-----------------------------------------------------------------------------
2020 subroutine angles2tab(PHImin,PHImax,n,ang,tab)
2021 ! Only uses angles if [0,PI] (but PHImin cannot be 0.,
2022 ! and PHImax cannot be PI)
2026 ! include 'COMMON.GEO'
2029 real(kind=8) :: PHImin,PHImax
2033 real(kind=8),dimension(0:3) :: ang
2034 logical,dimension(0:2,0:3) :: tab
2037 if (PHImin .eq. PHImax) then
2038 ! Special case with two 010's
2048 else if (PHImin .eq. PI) then
2049 ! Special case with one 010
2055 else if (PHImax .eq. 0.) then
2056 ! Special case with one 010
2065 if (PHImin .gt. 0.) then
2066 ! Start of range (011)
2071 ! End of range (110)
2075 tab(2,n+1) = .false.
2078 if (PHImax .lt. PI) then
2079 ! Start of range (011)
2084 ! End of range (110)
2088 tab(2,n+1) = .false.
2094 end subroutine angles2tab
2095 !-----------------------------------------------------------------------------
2096 subroutine minmax_angles(x,y,z,r,n,ang,tab)
2097 ! When solutions do not exist, assume all angles
2098 ! are acceptable - i.e., initial geometry must be correct
2102 ! include 'COMMON.GEO'
2103 ! include 'COMMON.LOCMOVE'
2106 real(kind=8) :: x,y,z,r
2110 real(kind=8),dimension(0:3) :: ang
2111 logical,dimension(0:2,0:3) :: tab
2114 real(kind=8) :: num, denom, phi
2115 real(kind=8) :: Kmin, Kmax
2119 num = x*x + y*y + z*z
2122 if (denom .gt. 0.) then
2124 denom = 2.*r*sqrt(denom)
2126 Kmin = (num - dmin2)/denom
2127 Kmax = (num - dmax2)/denom
2129 ! Allowed values of K (else all angles are acceptable)
2132 if (Kmin .gt. 1. .or. abs(Kmin-1.) .lt. small2) then
2134 else if (Kmin .lt. -1. .or. abs(Kmin+1.) .lt. small2) then
2140 if (Kmax .lt. -1. .or. abs(Kmax+1.) .lt. small2) then
2142 else if (Kmax .gt. 1. .or. abs(Kmax-1.) .lt. small2) then
2148 if (Kmax .lt. Kmin) Kmax = Kmin
2150 call angles2tab(Kmin, Kmax, n, ang, tab)
2152 ! Add phi and check that angles are within range (-PI,PI]
2155 if (ang(i) .le. -PI) then
2156 ang(i) = ang(i)+2.*PI
2157 else if (ang(i) .gt. PI) then
2158 ang(i) = ang(i)-2.*PI
2164 end subroutine minmax_angles
2165 !-----------------------------------------------------------------------------
2166 subroutine construct_tab
2167 ! Take a_... and b_... values and produces the results res_...
2168 ! x_ang are assumed to be all different (diff > small)
2169 ! x_tab(1,i) must be 1 for all i (i.e., all x_ang are acceptable)
2173 ! include 'COMMON.LOCMOVE'
2176 integer :: n_max,i,j,index
2182 if (n_max .eq. 0) then
2189 res_tab(j,0,i) = .true.
2190 res_tab(j,2,i) = .true.
2191 res_tab(j,1,i) = .false.
2198 do while (.not.done)
2199 res_ang(index) = flag
2203 if ((a_ang(i)-phi).gt.small .and. &
2204 a_ang(i) .lt. res_ang(index)) then
2205 ! Found a lower angle
2206 res_ang(index) = a_ang(i)
2207 ! Copy the values from a_tab into res_tab(0,,)
2208 res_tab(0,0,index) = a_tab(0,i)
2209 res_tab(0,1,index) = a_tab(1,i)
2210 res_tab(0,2,index) = a_tab(2,i)
2211 ! Set default values for res_tab(1,,)
2212 res_tab(1,0,index) = .true.
2213 res_tab(1,1,index) = .false.
2214 res_tab(1,2,index) = .true.
2215 else if (abs(a_ang(i)-res_ang(index)).lt.small) then
2216 ! Found an equal angle (can only be equal to a b_ang)
2217 res_tab(0,0,index) = a_tab(0,i)
2218 res_tab(0,1,index) = a_tab(1,i)
2219 res_tab(0,2,index) = a_tab(2,i)
2224 if ((b_ang(i)-phi).gt.small .and. &
2225 b_ang(i) .lt. res_ang(index)) then
2226 ! Found a lower angle
2227 res_ang(index) = b_ang(i)
2228 ! Copy the values from b_tab into res_tab(1,,)
2229 res_tab(1,0,index) = b_tab(0,i)
2230 res_tab(1,1,index) = b_tab(1,i)
2231 res_tab(1,2,index) = b_tab(2,i)
2232 ! Set default values for res_tab(0,,)
2233 res_tab(0,0,index) = .true.
2234 res_tab(0,1,index) = .false.
2235 res_tab(0,2,index) = .true.
2236 else if (abs(b_ang(i)-res_ang(index)).lt.small) then
2237 ! Found an equal angle (can only be equal to an a_ang)
2238 res_tab(1,0,index) = b_tab(0,i)
2239 res_tab(1,1,index) = b_tab(1,i)
2240 res_tab(1,2,index) = b_tab(2,i)
2244 if (res_ang(index) .eq. flag) then
2247 else if (index .eq. n_max-1) then
2251 phi = res_ang(index) ! Store previous angle
2259 if (a_n .gt. 0) then
2260 do while (.not.res_tab(0,1,index))
2263 done = res_tab(0,2,index)
2264 do i=index+1,res_n-1
2265 if (res_tab(0,1,i)) then
2266 done = res_tab(0,2,i)
2268 res_tab(0,0,i) = done
2269 res_tab(0,1,i) = done
2270 res_tab(0,2,i) = done
2273 done = res_tab(0,0,index)
2275 if (res_tab(0,1,i)) then
2276 done = res_tab(0,0,i)
2278 res_tab(0,0,i) = done
2279 res_tab(0,1,i) = done
2280 res_tab(0,2,i) = done
2285 res_tab(0,0,i) = .true.
2286 res_tab(0,1,i) = .true.
2287 res_tab(0,2,i) = .true.
2292 if (b_n .gt. 0) then
2293 do while (.not.res_tab(1,1,index))
2296 done = res_tab(1,2,index)
2297 do i=index+1,res_n-1
2298 if (res_tab(1,1,i)) then
2299 done = res_tab(1,2,i)
2301 res_tab(1,0,i) = done
2302 res_tab(1,1,i) = done
2303 res_tab(1,2,i) = done
2306 done = res_tab(1,0,index)
2308 if (res_tab(1,1,i)) then
2309 done = res_tab(1,0,i)
2311 res_tab(1,0,i) = done
2312 res_tab(1,1,i) = done
2313 res_tab(1,2,i) = done
2318 res_tab(1,0,i) = .true.
2319 res_tab(1,1,i) = .true.
2320 res_tab(1,2,i) = .true.
2324 ! Finally fill the last row with AND operation
2327 res_tab(2,j,i) = (res_tab(0,j,i) .and. res_tab(1,j,i))
2332 end subroutine construct_tab
2333 !-----------------------------------------------------------------------------
2334 subroutine construct_ranges(phi_n,phi_start,phi_end)
2335 ! Given the data in res_..., construct a table of
2336 ! min/max allowed angles
2340 ! include 'COMMON.GEO'
2341 ! include 'COMMON.LOCMOVE'
2345 real(kind=8),dimension(0:11) :: phi_start,phi_end
2352 if (res_n .eq. 0) then
2353 ! Any move is allowed
2361 do while (.not.done)
2362 ! Find start of range (01x)
2364 do while (.not.done)
2365 if (res_tab(2,0,index).or.(.not.res_tab(2,1,index))) then
2369 phi_start(phi_n) = res_ang(index)
2371 if (index .eq. res_n) done = .true.
2373 ! If a start was found (index < res_n), find the end of range (x10)
2374 ! It may not be found without wrapping around
2375 if (index .lt. res_n) then
2377 do while (.not.done)
2378 if ((.not.res_tab(2,1,index)).or.res_tab(2,2,index)) then
2383 if (index .eq. res_n) done = .true.
2385 if (index .lt. res_n) then
2386 ! Found the end of the range
2387 phi_end(phi_n) = res_ang(index)
2390 if (index .eq. res_n) then
2396 ! Need to wrap around
2398 phi_end(phi_n) = flag
2402 ! Take care of the last one if need to wrap around
2403 if (phi_end(phi_n) .eq. flag) then
2405 do while ((.not.res_tab(2,1,index)).or.res_tab(2,2,index))
2408 phi_end(phi_n) = res_ang(index) + 2.*PI
2414 end subroutine construct_ranges
2415 !-----------------------------------------------------------------------------
2416 subroutine fix_no_moves(phi)
2420 ! include 'COMMON.GEO'
2421 ! include 'COMMON.LOCMOVE'
2428 real(kind=8) :: diff,temp
2431 ! Look for first 01x in gammas (there MUST be at least one)
2434 do while (res_tab(1,0,index) .or. (.not.res_tab(1,1,index)))
2437 if (res_ang(index) .le. 0.D0) then ! Make sure it's from PHImax
2438 ! Try to increase PHImax
2439 if (index .gt. 0) then
2440 phi = res_ang(index-1)
2441 diff = abs(res_ang(index) - res_ang(index-1))
2443 ! Look for last (corresponding) x10
2445 do while ((.not.res_tab(1,1,index)) .or. res_tab(1,2,index))
2448 if (index .lt. res_n-1) then
2449 temp = abs(res_ang(index) - res_ang(index+1))
2450 if (temp .lt. diff) then
2451 phi = res_ang(index+1)
2457 ! If increasing PHImax didn't work, decreasing PHImin
2458 ! will (with one exception)
2459 ! Look for first x10 (there MUST be at least one)
2461 do while ((.not.res_tab(1,1,index)) .or. res_tab(1,2,index))
2464 if (res_ang(index) .lt. 0.D0) then ! Make sure it's from PHImin
2465 ! Try to decrease PHImin
2466 if (index .lt. res_n-1) then
2467 temp = abs(res_ang(index) - res_ang(index+1))
2468 if (res_ang(index+1) .le. 0.D0 .and. temp .lt. diff) then
2469 phi = res_ang(index+1)
2473 ! Look for last (corresponding) 01x
2475 do while (res_tab(1,0,index) .or. (.not.res_tab(1,1,index)))
2478 if (index .gt. 0) then
2479 temp = abs(res_ang(index) - res_ang(index-1))
2480 if (res_ang(index-1) .ge. 0.D0 .and. temp .lt. diff) then
2481 phi = res_ang(index-1)
2487 ! If it still didn't work, it must be PHImax == 0. or PHImin == PI
2488 if (diff .eq. flag) then
2490 if (res_tab(index,1,0) .or. (.not.res_tab(index,1,1)) .or. &
2491 res_tab(index,1,2)) index = res_n - 1
2492 ! This MUST work at this point
2493 if (index .eq. 0) then
2496 phi = res_ang(index - 1)
2501 end subroutine fix_no_moves
2502 !-----------------------------------------------------------------------------
2503 integer function move_res(PHImin,PHImax,i_move)
2504 ! Moves residue i_move (in array c), leaving everything else fixed
2505 ! Starting geometry is not checked, it should be correct!
2506 ! R(,i_move) is the only residue that will move, but must have
2507 ! 1 < i_move < nres (i.e., cannot move ends)
2508 ! Whether any output is done is controlled by locmove_output
2510 use random,only:ran_number
2512 ! implicit real*8 (a-h,o-z)
2513 ! include 'DIMENSIONS'
2514 ! include 'COMMON.CHAIN'
2515 ! include 'COMMON.GEO'
2516 ! include 'COMMON.LOCMOVE'
2518 ! External functions
2519 !EL double precision ran_number
2520 !EL external ran_number
2523 real(kind=8) :: PHImin,PHImax
2527 ! 0: move successfull
2528 ! 1: Dmin or Dmax had to be modified
2529 ! 2: move failed - check your input geometry
2533 real(kind=8),dimension(0:2) :: X,Y,Z,Orig
2534 real(kind=8),dimension(0:2) :: P
2535 logical :: no_moves,done
2536 integer :: index,i,j
2537 real(kind=8) :: phi,temp,radius
2538 real(kind=8),dimension(0:11) :: phi_start,phi_end
2541 ! Set up the coordinate system
2543 Orig(i)=0.5*(c(i+1,i_move-1)+c(i+1,i_move+1)) ! Position of origin
2547 Z(i)=c(i+1,i_move+1)-c(i+1,i_move-1)
2549 temp=sqrt(Z(0)*Z(0)+Z(1)*Z(1)+Z(2)*Z(2))
2555 X(i)=c(i+1,i_move)-Orig(i)
2557 ! radius is the radius of the circle on which c(,i_move) can move
2558 radius=sqrt(X(0)*X(0)+X(1)*X(1)+X(2)*X(2))
2563 Y(0)=Z(1)*X(2)-X(1)*Z(2)
2564 Y(1)=X(0)*Z(2)-Z(0)*X(2)
2565 Y(2)=Z(0)*X(1)-X(0)*Z(1)
2567 ! Calculate min, max angles coming from dmin, dmax to c(,i_move-2)
2568 if (i_move.gt.2) then
2570 P(i)=c(i+1,i_move-2)-Orig(i)
2572 call minmax_angles(P(0)*X(0)+P(1)*X(1)+P(2)*X(2),&
2573 P(0)*Y(0)+P(1)*Y(1)+P(2)*Y(2),&
2574 P(0)*Z(0)+P(1)*Z(1)+P(2)*Z(2),&
2575 radius,a_n,a_ang,a_tab)
2580 ! Calculate min, max angles coming from dmin, dmax to c(,i_move+2)
2581 if (i_move.lt.nres-2) then
2583 P(i)=c(i+1,i_move+2)-Orig(i)
2585 call minmax_angles(P(0)*X(0)+P(1)*X(1)+P(2)*X(2),&
2586 P(0)*Y(0)+P(1)*Y(1)+P(2)*Y(2),&
2587 P(0)*Z(0)+P(1)*Z(1)+P(2)*Z(2),&
2588 radius,b_n,b_ang,b_tab)
2593 ! Construct the resulting table for alpha and beta
2594 call construct_tab()
2596 if (locmove_output) then
2597 print *,'ALPHAS & BETAS TABLE'
2601 ! Check that there is at least one possible move
2603 if (res_n .eq. 0) then
2607 do while ((index .lt. res_n) .and. no_moves)
2608 if (res_tab(2,1,index)) no_moves = .false.
2613 if (locmove_output) print *,' *** Cannot move anywhere'
2618 ! Transfer res_... into a_...
2621 if ( (res_tab(2,0,i).neqv.res_tab(2,1,i)) .or. &
2622 (res_tab(2,0,i).neqv.res_tab(2,2,i)) ) then
2623 a_ang(a_n) = res_ang(i)
2625 a_tab(j,a_n) = res_tab(2,j,i)
2631 ! Check that the PHI's are within [0,PI]
2632 if (PHImin .lt. 0. .or. abs(PHImin) .lt. small) PHImin = -flag
2633 if (PHImin .gt. PI .or. abs(PHImin-PI) .lt. small) PHImin = PI
2634 if (PHImax .gt. PI .or. abs(PHImax-PI) .lt. small) PHImax = flag
2635 if (PHImax .lt. 0. .or. abs(PHImax) .lt. small) PHImax = 0.
2636 if (PHImax .lt. PHImin) PHImax = PHImin
2637 ! Calculate min and max angles coming from PHImin and PHImax,
2638 ! and put them in b_...
2639 call angles2tab(PHImin, PHImax, b_n, b_ang, b_tab)
2640 ! Construct the final table
2641 call construct_tab()
2643 if (locmove_output) then
2644 print *,'FINAL TABLE'
2648 ! Check that there is at least one possible move
2650 if (res_n .eq. 0) then
2654 do while ((index .lt. res_n) .and. no_moves)
2655 if (res_tab(2,1,index)) no_moves = .false.
2661 ! Take care of the case where no solution exists...
2662 call fix_no_moves(phi)
2663 if (locmove_output) then
2664 print *,' *** Had to modify PHImin or PHImax'
2665 print *,'phi: ',phi*rad2deg
2669 ! ...or calculate the solution
2670 ! Construct phi_start/phi_end arrays
2671 call construct_ranges(phi_n, phi_start, phi_end)
2672 ! Choose random angle phi in allowed range(s)
2675 temp = temp + phi_end(i) - phi_start(i)
2677 phi = ran_number(phi_start(0),phi_start(0)+temp)
2680 do while (.not.done)
2681 if (phi .lt. phi_end(index)) then
2686 if (index .eq. phi_n) then
2688 else if (.not.done) then
2689 phi = phi + phi_start(index) - phi_end(index-1)
2692 if (index.eq.phi_n) phi=phi_end(phi_n-1) ! Fix numerical errors
2693 if (phi .gt. PI) phi = phi-2.*PI
2695 if (locmove_output) then
2696 print *,'ALLOWED RANGE(S)'
2698 print *,phi_start(i)*rad2deg,phi_end(i)*rad2deg
2700 print *,'phi: ',phi*rad2deg
2705 ! Re-use radius as temp variable
2706 temp=radius*cos(phi)
2707 radius=radius*sin(phi)
2709 c(i+1,i_move)=Orig(i)+temp*X(i)+radius*Y(i)
2713 end function move_res
2714 !-----------------------------------------------------------------------------
2719 ! implicit real*8 (a-h,o-z)
2720 ! include 'DIMENSIONS'
2721 ! include 'COMMON.GEO'
2722 ! include 'COMMON.LOCAL'
2723 ! include 'COMMON.LOCMOVE'
2725 ! External functions
2726 !EL integer move_res
2727 !EL external move_res
2732 real(kind=8),dimension(0:11) :: phi_start,phi_end
2734 real(kind=8),dimension(0:2,0:5) :: R
2736 locmove_output=.true.
2738 ! call angles2tab(30.*deg2rad,70.*deg2rad,a_n,a_ang,a_tab)
2739 ! call angles2tab(80.*deg2rad,130.*deg2rad,b_n,b_ang,b_tab)
2740 ! call minmax_angles(0.D0,3.8D0,0.D0,3.8D0,b_n,b_ang,b_tab)
2741 ! call construct_tab
2744 ! call construct_ranges(phi_n,phi_start,phi_end)
2746 ! print *,phi_start(i)*rad2deg,phi_end(i)*rad2deg
2749 ! call fix_no_moves(phi)
2750 ! print *,'NO MOVES FOUND, BEST PHI IS',phi*rad2deg
2756 R(1,1)=-cos(28.D0*deg2rad)
2757 R(2,1)=-0.5D0-sin(28.D0*deg2rad)
2761 R(0,3)=cos(30.D0*deg2rad)
2768 R(1,5)=cos(26.D0*deg2rad)
2769 R(2,5)=0.5D0+sin(26.D0*deg2rad)
2775 ! i=move_res(R(0,1),0.D0*deg2rad,180.D0*deg2rad)
2777 i=move_res(0.D0*deg2rad,180.D0*deg2rad,imov)
2778 print *,'RETURNED ',i
2779 print *,(R(i,3)/vbl,i=0,2)
2782 end subroutine loc_test
2784 !-----------------------------------------------------------------------------
2786 !-----------------------------------------------------------------------------
2787 subroutine MATMULT(A1,A2,A3)
2788 ! implicit real*8 (a-h,o-z)
2789 ! include 'DIMENSIONS'
2792 real(kind=8) :: A3IJ
2794 real(kind=8),DIMENSION(3,3) :: A1,A2,A3
2795 real(kind=8),DIMENSION(3,3) :: AI3
2800 3 A3IJ=A3IJ+A1(I,K)*A2(K,J)
2808 end subroutine MATMULT
2809 !-----------------------------------------------------------------------------
2811 !-----------------------------------------------------------------------------
2812 subroutine int_from_cart(lside,lprn)
2813 ! implicit real*8 (a-h,o-z)
2814 ! include 'DIMENSIONS'
2815 use control_data,only:out1file
2819 ! include 'COMMON.LOCAL'
2820 ! include 'COMMON.VAR'
2821 ! include 'COMMON.CHAIN'
2822 ! include 'COMMON.INTERACT'
2823 ! include 'COMMON.IOUNITS'
2824 ! include 'COMMON.GEO'
2825 ! include 'COMMON.NAMES'
2826 ! include 'COMMON.CONTROL'
2827 ! include 'COMMON.SETUP'
2828 character(len=3) :: seq,res
2830 character(len=80) :: card
2831 real(kind=8),dimension(3,20) :: sccor
2832 integer :: i,j,iti !el rescode,
2833 logical :: lside,lprn
2834 real(kind=8) :: di,cosfac,sinfac
2838 if(me.eq.king.or..not.out1file)then
2840 write (iout,'(/a)') &
2841 'Internal coordinates calculated from crystal structure.'
2843 write (iout,'(8a)') ' Res ',' dvb',' Theta',&
2844 ' Gamma',' Dsc_id',' Dsc',' Alpha',&
2847 write (iout,'(4a)') ' Res ',' dvb',' Theta',&
2853 !in wham do i=1,nres
2855 if (dist(i,i+1).lt.2.0D0 .or. dist(i,i+1).gt.5.0D0) then
2856 write (iout,'(a,i4)') 'Bad Cartesians for residue',i
2860 vbld(i+1)=dist(i,i+1)
2861 vbld_inv(i+1)=1.0d0/vbld(i+1)
2863 if (i.gt.1) theta(i+1)=alpha(i-1,i,i+1)
2864 if (i.gt.2) phi(i+1)=beta(i-2,i-1,i,i+1)
2868 ! if (itype(1).eq.ntyp1) then
2870 ! c(j,1)=c(j,2)+(c(j,3)-c(j,4))
2873 ! if (itype(nres).eq.ntyp1) then
2875 ! c(j,nres)=c(j,nres-1)+(c(j,nres-2)-c(j,nres-3))
2879 ! if (unres_pdb) then
2880 ! if (itype(1).eq.21) then
2881 ! theta(3)=90.0d0*deg2rad
2882 ! phi(4)=180.0d0*deg2rad
2884 ! vbld_inv(2)=1.0d0/vbld(2)
2886 ! if (itype(nres).eq.21) then
2887 ! theta(nres)=90.0d0*deg2rad
2888 ! phi(nres)=180.0d0*deg2rad
2890 ! vbld_inv(nres)=1.0d0/vbld(2)
2896 c(j,nres2+2)=0.5D0*(2*c(j,i)+(c(j,i-1)-c(j,i))*vbld_inv(i) &
2897 +(c(j,i+1)-c(j,i))*vbld_inv(i+1))
2898 ! in wham c(j,maxres2)=0.5D0*(c(j,i-1)+c(j,i+1)
2903 ! 10/03/12 Adam: Correction for zero SC-SC bond length
2904 if (itype(i).ne.10 .and. itype(i).ne.ntyp1 .and. di.eq.0.0d0) &
2907 if (itype(i).ne.10) then
2908 vbld_inv(i+nres)=1.0d0/di
2910 vbld_inv(i+nres)=0.0d0
2914 alph(i)=alpha(nres+i,i,nres2+2)
2915 omeg(i)=beta(nres+i,i,nres2+2,i+1)
2917 if(me.eq.king.or..not.out1file)then
2919 write (iout,'(a3,i4,7f10.3)') restyp(iti),i,vbld(i),&
2920 rad2deg*theta(i),rad2deg*phi(i),dsc(iti),vbld(nres+i),&
2921 rad2deg*alph(i),rad2deg*omeg(i)
2927 if(me.eq.king.or..not.out1file) &
2928 write (iout,'(a3,i4,7f10.3)') restyp(iti),i,dist(i,i-1),&
2929 rad2deg*theta(i),rad2deg*phi(i)
2933 end subroutine int_from_cart
2934 !-----------------------------------------------------------------------------
2935 subroutine sc_loc_geom(lprn)
2936 ! implicit real*8 (a-h,o-z)
2937 ! include 'DIMENSIONS'
2938 use control_data,only:out1file
2942 ! include 'COMMON.LOCAL'
2943 ! include 'COMMON.VAR'
2944 ! include 'COMMON.CHAIN'
2945 ! include 'COMMON.INTERACT'
2946 ! include 'COMMON.IOUNITS'
2947 ! include 'COMMON.GEO'
2948 ! include 'COMMON.NAMES'
2949 ! include 'COMMON.CONTROL'
2950 ! include 'COMMON.SETUP'
2951 real(kind=8),dimension(3) :: x_prime,y_prime,z_prime
2954 integer :: i,j,it,iti
2955 real(kind=8) :: cosfac2,sinfac2,xx,yy,zz,cosfac,sinfac
2958 dc_norm(j,i)=vbld_inv(i+1)*(c(j,i+1)-c(j,i))
2962 if (itype(i).ne.10) then
2964 dc_norm(j,i+nres)=vbld_inv(i+nres)*(c(j,i+nres)-c(j,i))
2968 dc_norm(j,i+nres)=0.0d0
2973 costtab(i+1) =dcos(theta(i+1))
2974 sinttab(i+1) =dsqrt(1-costtab(i+1)*costtab(i+1))
2975 cost2tab(i+1)=dsqrt(0.5d0*(1.0d0+costtab(i+1)))
2976 sint2tab(i+1)=dsqrt(0.5d0*(1.0d0-costtab(i+1)))
2977 cosfac2=0.5d0/(1.0d0+costtab(i+1))
2978 cosfac=dsqrt(cosfac2)
2979 sinfac2=0.5d0/(1.0d0-costtab(i+1))
2980 sinfac=dsqrt(sinfac2)
2983 if ((it.ne.10).and.(it.ne.ntyp1)) then
2984 !el if (it.ne.10) then
2986 ! Compute the axes of tghe local cartesian coordinates system; store in
2987 ! x_prime, y_prime and z_prime
2995 x_prime(j) = (dc_norm(j,i) - dc_norm(j,i-1))*cosfac
2996 y_prime(j) = (dc_norm(j,i) + dc_norm(j,i-1))*sinfac
2998 call vecpr(x_prime,y_prime,z_prime)
3000 ! Transform the unit vector of the ith side-chain centroid, dC_norm(*,i),
3001 ! to local coordinate system. Store in xx, yy, zz.
3007 xx = xx + x_prime(j)*dc_norm(j,i+nres)
3008 yy = yy + y_prime(j)*dc_norm(j,i+nres)
3009 zz = zz + z_prime(j)*dc_norm(j,i+nres)
3024 if(me.eq.king.or..not.out1file) &
3025 write (iout,'(a3,i4,3f10.5)') restyp(iti),i,xxref(i),&
3031 end subroutine sc_loc_geom
3032 !-----------------------------------------------------------------------------
3033 subroutine sccenter(ires,nscat,sccor)
3034 ! implicit real*8 (a-h,o-z)
3035 ! include 'DIMENSIONS'
3036 ! include 'COMMON.CHAIN'
3037 integer :: i,j,ires,nscat
3038 real(kind=8),dimension(3,20) :: sccor
3039 real(kind=8) :: sccmj
3043 sccmj=sccmj+sccor(j,i)
3045 dc(j,ires)=sccmj/nscat
3048 end subroutine sccenter
3049 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
3050 !-----------------------------------------------------------------------------
3051 subroutine bond_regular
3053 ! implicit real*8 (a-h,o-z)
3054 ! include 'DIMENSIONS'
3055 ! include 'COMMON.VAR'
3056 ! include 'COMMON.LOCAL'
3057 ! include 'COMMON.CALC'
3058 ! include 'COMMON.INTERACT'
3059 ! include 'COMMON.CHAIN'
3062 vbld_inv(i+1)=1.0d0/vbld(i+1)
3063 vbld(i+1+nres)=dsc(itype(i+1))
3064 vbld_inv(i+1+nres)=dsc_inv(itype(i+1))
3065 ! print *,vbld(i+1),vbld(i+1+nres)
3068 end subroutine bond_regular
3070 !-----------------------------------------------------------------------------
3072 !-----------------------------------------------------------------------------
3073 subroutine refsys(i2,i3,i4,e1,e2,e3,fail)
3074 ! This subroutine calculates unit vectors of a local reference system
3075 ! defined by atoms (i2), (i3), and (i4). The x axis is the axis from
3076 ! atom (i3) to atom (i2), and the xy plane is the plane defined by atoms
3077 ! (i2), (i3), and (i4). z axis is directed according to the sign of the
3078 ! vector product (i3)-(i2) and (i3)-(i4). Sets fail to .true. if atoms
3079 ! (i2) and (i3) or (i3) and (i4) coincide or atoms (i2), (i3), and (i4)
3080 ! form a linear fragment. Returns vectors e1, e2, and e3.
3081 ! implicit real*8 (a-h,o-z)
3082 ! include 'DIMENSIONS'
3084 real(kind=8),dimension(3) :: e1,e2,e3
3085 real(kind=8),dimension(3) :: u,z
3086 ! include 'COMMON.IOUNITS'
3087 ! include 'COMMON.CHAIN'
3088 real(kind=8) :: coinc=1.0D-13,align=1.0D-13
3090 integer :: i,i1,i2,i3,i4
3091 real(kind=8) :: v1,v2,v3,s1,s2,zi,ui,anorm
3104 if (s1.gt.coinc) goto 2
3105 write (iout,1000) i2,i3,i1
3110 2 if (s2.gt.coinc) goto 4
3111 write(iout,1000) i3,i4,i1
3118 v1=z(2)*u(3)-z(3)*u(2)
3119 v2=z(3)*u(1)-z(1)*u(3)
3120 v3=z(1)*u(2)-z(2)*u(1)
3121 anorm=dsqrt(v1*v1+v2*v2+v3*v3)
3122 if (anorm.gt.align) goto 6
3123 write (iout,1010) i2,i3,i4,i1
3135 e2(1)=e1(3)*e3(2)-e1(2)*e3(3)
3136 e2(2)=e1(1)*e3(3)-e1(3)*e3(1)
3137 e2(3)=e1(2)*e3(1)-e1(1)*e3(2)
3138 1000 format (/1x,' * * * Error - atoms',i4,' and',i4,' coincide.',&
3139 'coordinates of atom',i4,' are set to zero.')
3140 1010 format (/1x,' * * * Error - atoms',2(i4,2h, ),i4,' form a linear',&
3141 ' fragment. coordinates of atom',i4,' are set to zero.')
3143 end subroutine refsys
3144 !-----------------------------------------------------------------------------
3146 !-----------------------------------------------------------------------------
3147 subroutine int_to_cart
3148 !--------------------------------------------------------------
3149 ! This subroutine converts the energy derivatives from internal
3150 ! coordinates to cartesian coordinates
3151 !-------------------------------------------------------------
3152 ! implicit real*8 (a-h,o-z)
3153 ! include 'DIMENSIONS'
3154 ! include 'COMMON.VAR'
3155 ! include 'COMMON.CHAIN'
3156 ! include 'COMMON.DERIV'
3157 ! include 'COMMON.GEO'
3158 ! include 'COMMON.LOCAL'
3159 ! include 'COMMON.INTERACT'
3160 ! include 'COMMON.MD'
3161 ! include 'COMMON.IOUNITS'
3162 ! include 'COMMON.SCCOR'
3163 ! calculating dE/ddc1
3166 if (nres.lt.3) go to 18
3168 gcart(j,1)=gcart(j,1)+gloc(1,icg)*dphi(j,1,4) &
3169 +gloc(nres-2,icg)*dtheta(j,1,3)
3170 if(itype(2).ne.10) then
3171 gcart(j,1)=gcart(j,1)+gloc(ialph(2,1),icg)*dalpha(j,1,2)+ &
3172 gloc(ialph(2,1)+nside,icg)*domega(j,1,2)
3175 ! Calculating the remainder of dE/ddc2
3177 gcart(j,2)=gcart(j,2)+gloc(1,icg)*dphi(j,2,4)+ &
3178 gloc(nres-2,icg)*dtheta(j,2,3)+gloc(nres-1,icg)*dtheta(j,1,4)
3179 if(itype(2).ne.10) then
3180 gcart(j,2)=gcart(j,2)+gloc(ialph(2,1),icg)*dalpha(j,2,2)+ &
3181 gloc(ialph(2,1)+nside,icg)*domega(j,2,2)
3183 if(itype(3).ne.10) then
3184 gcart(j,2)=gcart(j,2)+gloc(ialph(3,1),icg)*dalpha(j,1,3)+ &
3185 gloc(ialph(3,1)+nside,icg)*domega(j,1,3)
3188 gcart(j,2)=gcart(j,2)+gloc(2,icg)*dphi(j,1,5)
3191 ! If there are only five residues
3194 gcart(j,3)=gcart(j,3)+gloc(1,icg)*dphi(j,3,4)+gloc(2,icg)* &
3195 dphi(j,2,5)+gloc(nres-1,icg)*dtheta(j,2,4)+gloc(nres,icg)* &
3197 if(itype(3).ne.10) then
3198 gcart(j,3)=gcart(j,3)+gloc(ialph(3,1),icg)* &
3199 dalpha(j,2,3)+gloc(ialph(3,1)+nside,icg)*domega(j,2,3)
3201 if(itype(4).ne.10) then
3202 gcart(j,3)=gcart(j,3)+gloc(ialph(4,1),icg)* &
3203 dalpha(j,1,4)+gloc(ialph(4,1)+nside,icg)*domega(j,1,4)
3207 ! If there are more than five residues
3211 gcart(j,i)=gcart(j,i)+gloc(i-2,icg)*dphi(j,3,i+1) &
3212 +gloc(i-1,icg)*dphi(j,2,i+2)+ &
3213 gloc(i,icg)*dphi(j,1,i+3)+gloc(nres+i-4,icg)*dtheta(j,2,i+1)+ &
3214 gloc(nres+i-3,icg)*dtheta(j,1,i+2)
3215 if(itype(i).ne.10) then
3216 gcart(j,i)=gcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,2,i)+ &
3217 gloc(ialph(i,1)+nside,icg)*domega(j,2,i)
3219 if(itype(i+1).ne.10) then
3220 gcart(j,i)=gcart(j,i)+gloc(ialph(i+1,1),icg)*dalpha(j,1,i+1) &
3221 +gloc(ialph(i+1,1)+nside,icg)*domega(j,1,i+1)
3226 ! Setting dE/ddnres-2
3229 gcart(j,nres-2)=gcart(j,nres-2)+gloc(nres-4,icg)* &
3230 dphi(j,3,nres-1)+gloc(nres-3,icg)*dphi(j,2,nres) &
3231 +gloc(2*nres-6,icg)* &
3232 dtheta(j,2,nres-1)+gloc(2*nres-5,icg)*dtheta(j,1,nres)
3233 if(itype(nres-2).ne.10) then
3234 gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-2,1),icg)* &
3235 dalpha(j,2,nres-2)+gloc(ialph(nres-2,1)+nside,icg)* &
3238 if(itype(nres-1).ne.10) then
3239 gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-1,1),icg)* &
3240 dalpha(j,1,nres-1)+gloc(ialph(nres-1,1)+nside,icg)* &
3245 ! Settind dE/ddnres-1
3247 gcart(j,nres-1)=gcart(j,nres-1)+gloc(nres-3,icg)*dphi(j,3,nres)+ &
3248 gloc(2*nres-5,icg)*dtheta(j,2,nres)
3249 if(itype(nres-1).ne.10) then
3250 gcart(j,nres-1)=gcart(j,nres-1)+gloc(ialph(nres-1,1),icg)* &
3251 dalpha(j,2,nres-1)+gloc(ialph(nres-1,1)+nside,icg)* &
3255 ! The side-chain vector derivatives
3257 if(itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3259 gxcart(j,i)=gxcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,3,i) &
3260 +gloc(ialph(i,1)+nside,icg)*domega(j,3,i)
3264 !----------------------------------------------------------------------
3265 ! INTERTYP=1 SC...Ca...Ca...Ca
3266 ! INTERTYP=2 Ca...Ca...Ca...SC
3267 ! INTERTYP=3 SC...Ca...Ca...SC
3268 ! calculating dE/ddc1
3272 ! write (iout,*) "poczotkoawy",i,gloc_sc(1,i,icg)
3274 if (nres.lt.2) return
3275 if ((nres.lt.3).and.(itype(1).eq.10)) return
3276 if ((itype(1).ne.10).and.(itype(1).ne.ntyp1)) then
3278 !c Derviative was calculated for oposite vector of side chain therefore
3279 ! there is "-" sign before gloc_sc
3280 gxcart(j,1)=gxcart(j,1)-gloc_sc(1,0,icg)* &
3282 gcart(j,1)=gcart(j,1)+gloc_sc(1,0,icg)* &
3284 if ((itype(2).ne.10).and.(itype(2).ne.ntyp1)) then
3285 gxcart(j,1)= gxcart(j,1) &
3286 -gloc_sc(3,0,icg)*dtauangle(j,3,1,3)
3287 gcart(j,1)=gcart(j,1)+gloc_sc(3,0,icg)* &
3292 if ((nres.ge.3).and.(itype(3).ne.10).and.(itype(3).ne.ntyp1)) &
3295 gcart(j,1)=gcart(j,1)+gloc_sc(2,1,icg)*dtauangle(j,2,1,4)
3298 ! As potetnial DO NOT depend on omicron anlge their derivative is
3300 ! & +gloc_sc(intertyp,nres-2,icg)*dtheta(j,1,3)
3302 ! Calculating the remainder of dE/ddc2
3304 if((itype(2).ne.10).and.(itype(2).ne.ntyp1)) then
3305 if (itype(1).ne.10) gxcart(j,2)=gxcart(j,2)+ &
3306 gloc_sc(3,0,icg)*dtauangle(j,3,3,3)
3307 if ((itype(3).ne.10).and.(nres.ge.3).and.(itype(3).ne.ntyp1)) &
3309 gxcart(j,2)=gxcart(j,2)-gloc_sc(3,1,icg)*dtauangle(j,3,1,4)
3310 !c the - above is due to different vector direction
3311 gcart(j,2)=gcart(j,2)+gloc_sc(3,1,icg)*dtauangle(j,3,2,4)
3314 gxcart(j,2)=gxcart(j,2)-gloc_sc(1,1,icg)*dtauangle(j,1,1,4)
3315 !c the - above is due to different vector direction
3316 gcart(j,2)=gcart(j,2)+gloc_sc(1,1,icg)*dtauangle(j,1,2,4)
3317 ! write(iout,*) gloc_sc(1,1,icg),dtauangle(j,1,2,4),"gcart"
3318 ! write(iout,*) gloc_sc(1,1,icg),dtauangle(j,1,1,4),"gx"
3321 if ((itype(1).ne.10).and.(itype(1).ne.ntyp1)) then
3322 gcart(j,2)=gcart(j,2)+gloc_sc(1,0,icg)*dtauangle(j,1,3,3)
3323 ! write(iout,*) gloc_sc(1,0,icg),dtauangle(j,1,3,3)
3325 if ((itype(3).ne.10).and.(nres.ge.3)) then
3326 gcart(j,2)=gcart(j,2)+gloc_sc(2,1,icg)*dtauangle(j,2,2,4)
3327 ! write(iout,*) gloc_sc(2,1,icg),dtauangle(j,2,2,4)
3329 if ((itype(4).ne.10).and.(nres.ge.4)) then
3330 gcart(j,2)=gcart(j,2)+gloc_sc(2,2,icg)*dtauangle(j,2,1,5)
3331 ! write(iout,*) gloc_sc(2,2,icg),dtauangle(j,2,1,5)
3334 ! write(iout,*) gcart(j,2),itype(2),itype(1),itype(3), "gcart2"
3336 ! If there are more than five residues
3340 ! write(iout,*) "before", gcart(j,i)
3341 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
3342 gxcart(j,i)=gxcart(j,i)+gloc_sc(2,i-2,icg) &
3343 *dtauangle(j,2,3,i+1) &
3344 -gloc_sc(1,i-1,icg)*dtauangle(j,1,1,i+2)
3345 gcart(j,i)=gcart(j,i)+gloc_sc(1,i-1,icg) &
3346 *dtauangle(j,1,2,i+2)
3347 ! write(iout,*) "new",j,i,
3348 ! & gcart(j,i),gloc_sc(1,i-1,icg),dtauangle(j,1,2,i+2)
3349 if (itype(i-1).ne.10) then
3350 gxcart(j,i)=gxcart(j,i)+gloc_sc(3,i-2,icg) &
3351 *dtauangle(j,3,3,i+1)
3353 if (itype(i+1).ne.10) then
3354 gxcart(j,i)=gxcart(j,i)-gloc_sc(3,i-1,icg) &
3355 *dtauangle(j,3,1,i+2)
3356 gcart(j,i)=gcart(j,i)+gloc_sc(3,i-1,icg) &
3357 *dtauangle(j,3,2,i+2)
3360 if (itype(i-1).ne.10) then
3361 gcart(j,i)=gcart(j,i)+gloc_sc(1,i-2,icg)* &
3362 dtauangle(j,1,3,i+1)
3364 if (itype(i+1).ne.10) then
3365 gcart(j,i)=gcart(j,i)+gloc_sc(2,i-1,icg)* &
3366 dtauangle(j,2,2,i+2)
3367 ! write(iout,*) "numer",i,gloc_sc(2,i-1,icg),
3368 ! & dtauangle(j,2,2,i+2)
3370 if (itype(i+2).ne.10) then
3371 gcart(j,i)=gcart(j,i)+gloc_sc(2,i,icg)* &
3372 dtauangle(j,2,1,i+3)
3377 ! Setting dE/ddnres-1
3380 if ((itype(nres-1).ne.10).and.(itype(nres-1).ne.ntyp1)) then
3381 gxcart(j,nres-1)=gxcart(j,nres-1)+gloc_sc(2,nres-3,icg) &
3382 *dtauangle(j,2,3,nres)
3383 ! write (iout,*) "gxcart(nres-1)", gloc_sc(2,nres-3,icg),
3384 ! & dtauangle(j,2,3,nres), gxcart(j,nres-1)
3385 if (itype(nres-2).ne.10) then
3386 gxcart(j,nres-1)=gxcart(j,nres-1)+gloc_sc(3,nres-3,icg) &
3387 *dtauangle(j,3,3,nres)
3389 if ((itype(nres).ne.10).and.(itype(nres).ne.ntyp1)) then
3390 gxcart(j,nres-1)=gxcart(j,nres-1)-gloc_sc(3,nres-2,icg) &
3391 *dtauangle(j,3,1,nres+1)
3392 gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(3,nres-2,icg) &
3393 *dtauangle(j,3,2,nres+1)
3396 if ((itype(nres-2).ne.10).and.(itype(nres-2).ne.ntyp1)) then
3397 gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(1,nres-3,icg)* &
3398 dtauangle(j,1,3,nres)
3400 if ((itype(nres).ne.10).and.(itype(nres).ne.ntyp1)) then
3401 gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(2,nres-2,icg)* &
3402 dtauangle(j,2,2,nres+1)
3403 ! write (iout,*) "gcart(nres-1)", gloc_sc(2,nres-2,icg),
3404 ! & dtauangle(j,2,2,nres+1), itype(nres-1),itype(nres)
3409 if ((nres.ge.3).and.(itype(nres).ne.10).and. &
3410 (itype(nres).ne.ntyp1))then
3412 gxcart(j,nres)=gxcart(j,nres)+gloc_sc(3,nres-2,icg) &
3413 *dtauangle(j,3,3,nres+1)+gloc_sc(2,nres-2,icg) &
3414 *dtauangle(j,2,3,nres+1)
3417 ! The side-chain vector derivatives
3419 end subroutine int_to_cart
3420 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
3421 !-----------------------------------------------------------------------------
3423 !-----------------------------------------------------------------------------
3424 subroutine gen_dist_constr
3425 ! Generate CA distance constraints.
3426 ! implicit real*8 (a-h,o-z)
3427 ! include 'DIMENSIONS'
3428 ! include 'COMMON.IOUNITS'
3429 ! include 'COMMON.GEO'
3430 ! include 'COMMON.VAR'
3431 ! include 'COMMON.INTERACT'
3432 ! include 'COMMON.LOCAL'
3433 ! include 'COMMON.NAMES'
3434 ! include 'COMMON.CHAIN'
3435 ! include 'COMMON.FFIELD'
3436 ! include 'COMMON.SBRIDGE'
3437 ! include 'COMMON.HEADER'
3438 ! include 'COMMON.CONTROL'
3439 ! include 'COMMON.DBASE'
3440 ! include 'COMMON.THREAD'
3441 ! include 'COMMON.TIME1'
3442 ! integer :: itype_pdb !(maxres)
3443 ! common /pizda/ itype_pdb(nres)
3444 character(len=2) :: iden
3447 !d print *,'gen_dist_constr: nnt=',nnt,' nct=',nct
3448 !d write (2,*) 'gen_dist_constr: nnt=',nnt,' nct=',nct,
3449 !d & ' nstart_sup',nstart_sup,' nstart_seq',nstart_seq,
3451 do i=nstart_sup,nstart_sup+nsup-1
3452 !d write (2,*) 'i',i,' seq ',restyp(itype(i+nstart_seq-nstart_sup)),
3453 !d & ' seq_pdb', restyp(itype_pdb(i))
3454 do j=i+2,nstart_sup+nsup-1
3456 ihpb(nhpb)=i+nstart_seq-nstart_sup
3457 jhpb(nhpb)=j+nstart_seq-nstart_sup
3459 dhpb(nhpb)=dist(i,j)
3462 !d write (iout,'(a)') 'Distance constraints:'
3467 !d if (ii.gt.nres) then
3472 !d write (iout,'(a,1x,a,i4,3x,a,1x,a,i4,2f10.3)')
3473 !d & restyp(itype(ii)),iden,ii,restyp(itype(jj)),iden,jj,
3474 !d & dhpb(i),forcon(i)
3476 ! deallocate(itype_pdb)
3479 end subroutine gen_dist_constr
3481 !-----------------------------------------------------------------------------
3483 !-----------------------------------------------------------------------------
3484 subroutine cartprint
3486 use geometry_data, only: c
3487 use energy_data, only: itype
3488 ! implicit real*8 (a-h,o-z)
3489 ! include 'DIMENSIONS'
3490 ! include 'COMMON.CHAIN'
3491 ! include 'COMMON.INTERACT'
3492 ! include 'COMMON.NAMES'
3493 ! include 'COMMON.IOUNITS'
3498 write (iout,110) restyp(itype(i)),i,c(1,i),c(2,i),&
3499 c(3,i),c(1,nres+i),c(2,nres+i),c(3,nres+i)
3501 100 format (//' alpha-carbon coordinates ',&
3502 ' centroid coordinates'/ &
3503 ' ', 6X,'X',11X,'Y',11X,'Z',&
3504 10X,'X',11X,'Y',11X,'Z')
3505 110 format (a,'(',i3,')',6f12.5)
3507 end subroutine cartprint
3508 !-----------------------------------------------------------------------------
3509 !-----------------------------------------------------------------------------
3510 subroutine alloc_geo_arrays
3511 !EL Allocation of tables used by module energy
3513 integer :: i,j,nres2
3517 allocate(phibound(2,nres+2)) !(2,maxres)
3518 !----------------------
3520 ! common /chain/ in molread
3521 ! real(kind=8),dimension(:,:),allocatable :: c !(3,maxres2+2)
3522 ! real(kind=8),dimension(:,:),allocatable :: dc
3523 allocate(dc_old(3,0:nres2))
3524 ! if(.not.allocated(dc_norm2)) allocate(dc_norm2(3,0:nres2+2)) !(3,0:maxres2)
3525 if(.not.allocated(dc_norm2)) then
3526 allocate(dc_norm2(3,0:nres2+2)) !(3,0:maxres2)
3530 !el if(.not.allocated(dc_norm))
3531 !elwrite(iout,*) "jestem w alloc geo 1"
3532 if(.not.allocated(dc_norm)) then
3533 allocate(dc_norm(3,0:nres2+2)) !(3,0:maxres2)
3536 !elwrite(iout,*) "jestem w alloc geo 1"
3537 allocate(xloc(3,nres),xrot(3,nres))
3538 !elwrite(iout,*) "jestem w alloc geo 1"
3540 !elwrite(iout,*) "jestem w alloc geo 1"
3541 allocate(dc_work(6*nres)) !(MAXRES6) maxres6=6*maxres
3543 allocate(t(3,3,nres),r(3,3,nres))
3544 allocate(prod(3,3,nres),rt(3,3,nres)) !(3,3,maxres)
3545 ! common /refstruct/
3546 if(.not.allocated(cref)) allocate(cref(3,nres2+2,maxperm)) !(3,maxres2+2,maxperm)
3547 !elwrite(iout,*) "jestem w alloc geo 2"
3548 allocate(crefjlee(3,nres2+2)) !(3,maxres2+2)
3549 if(.not.allocated(chain_rep)) allocate(chain_rep(3,nres2+2,maxsym)) !(3,maxres2+2,maxsym)
3550 if(.not.allocated(tabperm)) allocate(tabperm(maxperm,maxsym)) !(maxperm,maxsym)
3551 ! common /from_zscore/ in module.compare
3552 !----------------------
3554 ! Inverses of the actual virtual bond lengths
3555 ! common /invlen/ in io_conf: molread or readpdb
3556 ! real(kind=8),dimension(:),allocatable :: vbld_inv !(maxres2)
3557 !----------------------
3559 ! Store the geometric variables in the following COMMON block.
3560 ! common /var/ in readpdb or ...
3561 if(.not.allocated(theta)) allocate(theta(nres+2))
3562 if(.not.allocated(phi)) allocate(phi(nres+2))
3563 if(.not.allocated(alph)) allocate(alph(nres+2))
3564 if(.not.allocated(omeg)) allocate(omeg(nres+2))
3565 if(.not.allocated(thetaref)) allocate(thetaref(nres+2))
3566 if(.not.allocated(phiref)) allocate(phiref(nres+2))
3567 if(.not.allocated(costtab)) allocate(costtab(nres))
3568 if(.not.allocated(sinttab)) allocate(sinttab(nres))
3569 if(.not.allocated(cost2tab)) allocate(cost2tab(nres))
3570 if(.not.allocated(sint2tab)) allocate(sint2tab(nres))
3571 ! real(kind=8),dimension(:),allocatable :: vbld !(2*maxres) in io_conf: molread or readpdb
3572 allocate(omicron(2,nres+2)) !(2,maxres)
3573 allocate(tauangle(3,nres+2)) !(3,maxres)
3574 !elwrite(iout,*) "jestem w alloc geo 3"
3575 if(.not.allocated(xxtab)) allocate(xxtab(nres))
3576 if(.not.allocated(yytab)) allocate(yytab(nres))
3577 if(.not.allocated(zztab)) allocate(zztab(nres)) !(maxres)
3578 if(.not.allocated(xxref)) allocate(xxref(nres))
3579 if(.not.allocated(yyref)) allocate(yyref(nres))
3580 if(.not.allocated(zzref)) allocate(zzref(nres)) !(maxres)
3581 allocate(ialph(nres,2)) !(maxres,2)
3584 allocate(ivar(4*nres2)) !(4*maxres2)
3586 #if defined(WHAM_RUN) || defined(CLUSTER)
3587 allocate(vbld(2*nres))
3589 allocate(vbld_inv(2*nres))
3594 end subroutine alloc_geo_arrays
3595 !-----------------------------------------------------------------------------
3596 !-----------------------------------------------------------------------------