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 ! print *,i,vbld(i),"vbld(i)"
454 vbld_inv(i)=1.0d0/vbld(i)
455 vbld(nres+i)=dist(nres+i,i)
456 if ((itype(i,1).ne.10).and.(molnum(i).lt.4)) then
457 vbld_inv(nres+i)=1.0d0/vbld(nres+i)
459 vbld_inv(nres+i)=0.0d0
462 #if defined(PARINT) && defined(MPI)
463 if (nfgtasks1.gt.1) then
464 !d write(iout,*) "iint_start",iint_start," iint_count",
465 !d & (iint_count(i),i=0,nfgtasks-1)," iint_displ",
466 !d & (iint_displ(i),i=0,nfgtasks-1)
467 !d write (iout,*) "Gather vbld backbone"
470 call MPI_Allgatherv(vbld(iint_start),iint_count(fg_rank1),&
471 MPI_DOUBLE_PRECISION,vbld(1),iint_count(0),iint_displ(0),&
472 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
473 !d write (iout,*) "Gather vbld_inv"
475 call MPI_Allgatherv(vbld_inv(iint_start),iint_count(fg_rank1),&
476 MPI_DOUBLE_PRECISION,vbld_inv(1),iint_count(0),iint_displ(0),&
477 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
478 !d write (iout,*) "Gather vbld side chain"
480 call MPI_Allgatherv(vbld(iint_start+nres),iint_count(fg_rank1),&
481 MPI_DOUBLE_PRECISION,vbld(nres+1),iint_count(0),iint_displ(0),&
482 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
483 !d write (iout,*) "Gather vbld_inv side chain"
485 call MPI_Allgatherv(vbld_inv(iint_start+nres),&
486 iint_count(fg_rank1),MPI_DOUBLE_PRECISION,vbld_inv(nres+1),&
487 iint_count(0),iint_displ(0),MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
488 !d write (iout,*) "Gather theta"
490 call MPI_Allgatherv(theta(iint_start+1),iint_count(fg_rank1),&
491 MPI_DOUBLE_PRECISION,theta(2),iint_count(0),iint_displ(0),&
492 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
493 !d write (iout,*) "Gather phi"
495 call MPI_Allgatherv(phi(iint_start+1),iint_count(fg_rank1),&
496 MPI_DOUBLE_PRECISION,phi(2),iint_count(0),iint_displ(0),&
497 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
499 !d write (iout,*) "Gather alph"
501 call MPI_Allgatherv(alph(iint_start),iint_count(fg_rank1),&
502 MPI_DOUBLE_PRECISION,alph(1),iint_count(0),iint_displ(0),&
503 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
504 !d write (iout,*) "Gather omeg"
506 call MPI_Allgatherv(omeg(iint_start),iint_count(fg_rank1),&
507 MPI_DOUBLE_PRECISION,omeg(1),iint_count(0),iint_displ(0),&
508 MPI_DOUBLE_PRECISION,FG_COMM1,IERR)
510 time_gather=time_gather+MPI_Wtime()-time00
516 #if defined(WHAM_RUN) || defined(CLUSTER)
517 dc(j,i)=c(j,i+1)-c(j,i)
519 dc_norm(j,i)=dc(j,i)*vbld_inv(i+1)
525 #if defined(WHAM_RUN) || defined(CLUSTER)
526 dc(j,i+nres)=c(j,i+nres)-c(j,i)
528 dc_norm(j,i+nres)=dc(j,i+nres)*vbld_inv(i+nres)
533 write (iout,1212) restyp(itype(i,1),1),i,vbld(i),&
534 rad2deg*theta(i),rad2deg*phi(i),vbld(nres+i),&
535 rad2deg*alph(i),rad2deg*omeg(i)
538 1212 format (a3,'(',i3,')',2(f15.10,2f10.2))
540 time_intfcart=time_intfcart+MPI_Wtime()-time01
543 end subroutine int_from_cart1
544 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
545 !-----------------------------------------------------------------------------
547 !-----------------------------------------------------------------------------
548 subroutine check_sc_distr
549 ! implicit real*8 (a-h,o-z)
550 ! include 'DIMENSIONS'
551 ! include 'COMMON.TIME1'
552 ! include 'COMMON.INTERACT'
553 ! include 'COMMON.NAMES'
554 ! include 'COMMON.GEO'
555 ! include 'COMMON.HEADER'
556 ! include 'COMMON.CONTROL'
558 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
559 real(kind=8) :: hrtime,mintime,sectime
560 integer,parameter :: MaxSample=10000000
561 real(kind=8),parameter :: delt=1.0D0/MaxSample
562 real(kind=8),dimension(0:72,0:90) :: prob
564 integer :: it,i,j,isample,indal,indom
565 real(kind=8) :: al,om,dV
566 dV=2.0D0*5.0D0*deg2rad*deg2rad
569 if ((it.eq.10).or.(it.eq.ntyp1)) goto 10
570 open (20,file=restyp(it,1)//'_distr.sdc',status='unknown')
571 call gen_side(it,90.0D0 * deg2rad,al,om,fail,1)
574 open (20,file=restyp(it,1)//'_distr1.sdc',status='unknown')
580 do isample=1,MaxSample
581 call gen_side(it,90.0D0 * deg2rad,al,om,fail,1)
583 indom=(rad2deg*om+180.0D0)/5
584 prob(indom,indal)=prob(indom,indal)+delt
588 write (20,'(2f10.3,1pd15.5)') 2*i+0.0D0,5*j-180.0D0,&
594 end subroutine check_sc_distr
596 !-----------------------------------------------------------------------------
598 !-----------------------------------------------------------------------------
599 subroutine geom_to_var(n,x)
601 ! Transfer the geometry parameters to the variable array.
602 ! The positions of variables are as follows:
603 ! 1. Virtual-bond torsional angles: 1 thru nres-3
604 ! 2. Virtual-bond valence angles: nres-2 thru 2*nres-5
605 ! 3. The polar angles alpha of local SC orientation: 2*nres-4 thru
607 ! 4. The torsional angles omega of SC orientation: 2*nres-4+nside+1
608 ! thru 2*nre-4+2*nside
610 ! implicit real*8 (a-h,o-z)
611 ! include 'DIMENSIONS'
612 ! include 'COMMON.VAR'
613 ! include 'COMMON.GEO'
614 ! include 'COMMON.CHAIN'
616 real(kind=8),dimension(n) :: x
617 !d print *,'nres',nres,' nphi',nphi,' ntheta',ntheta,' nvar',nvar
620 !d print *,i,i-3,phi(i)
622 if (n.eq.nphi) return
625 !d print *,i,i-2+nphi,theta(i)
627 if (n.eq.nphi+ntheta) return
629 if (ialph(i,1).gt.0) then
630 x(ialph(i,1))=alph(i)
631 x(ialph(i,1)+nside)=omeg(i)
632 !d print *,i,ialph(i,1),ialph(i,1)+nside,alph(i),omeg(i)
636 end subroutine geom_to_var
637 !-----------------------------------------------------------------------------
638 subroutine var_to_geom(n,x)
640 ! Update geometry parameters according to the variable array.
642 ! implicit real*8 (a-h,o-z)
643 ! include 'DIMENSIONS'
644 ! include 'COMMON.VAR'
645 ! include 'COMMON.CHAIN'
646 ! include 'COMMON.GEO'
647 ! include 'COMMON.IOUNITS'
649 real(kind=8),dimension(n) :: x
650 logical :: change !,reduce
657 if (n.gt.nphi+ntheta) then
660 alph(ii)=x(nphi+ntheta+i)
661 omeg(ii)=pinorm(x(nphi+ntheta+nside+i))
662 !elwrite(iout,*) "alph",ii,alph
663 !elwrite(iout,*) "omeg",ii,omeg
668 !elwrite(iout,*) "phi",i,phi
670 if (n.eq.nphi) return
673 !elwrite(iout,*) "theta",i,theta
674 if (theta(i).eq.pi) theta(i)=0.99d0*pi
678 end subroutine var_to_geom
679 !-----------------------------------------------------------------------------
680 logical function convert_side(alphi,omegi)
682 real(kind=8) :: alphi,omegi
683 !el real(kind=8) :: pinorm
684 ! include 'COMMON.GEO'
686 ! Apply periodicity restrictions.
687 if (alphi.gt.pi) then
689 omegi=pinorm(omegi+pi)
693 end function convert_side
694 !-----------------------------------------------------------------------------
695 logical function reduce(x)
697 ! Apply periodic restrictions to variables.
699 ! implicit real*8 (a-h,o-z)
700 ! include 'DIMENSIONS'
701 ! include 'COMMON.VAR'
702 ! include 'COMMON.CHAIN'
703 ! include 'COMMON.GEO'
704 logical :: zm,zmiana !,convert_side
705 real(kind=8),dimension(nvar) :: x
709 x(i-3)=pinorm(x(i-3))
711 if (nvar.gt.nphi+ntheta) then
715 x(ii)=thetnorm(x(ii))
716 x(iii)=pinorm(x(iii))
717 ! Apply periodic restrictions.
718 zm=convert_side(x(ii),x(iii))
722 if (nvar.eq.nphi) return
726 x(ii)=dmod(x(ii),dwapi)
727 ! Apply periodic restrictions.
728 if (x(ii).gt.pi) then
731 if (iii.gt.0) x(iii)=pinorm(x(iii)+pi)
732 if (i.lt.nres) x(iii+1)=pinorm(x(iii+1)+pi)
735 x(ii)=dmod(pi-x(ii),dwapi)
736 x(ii+nside)=pinorm(-x(ii+nside))
737 zm=convert_side(x(ii),x(ii+nside))
739 else if (x(ii).lt.-pi) then
744 x(ii)=dmod(pi-x(ii),dwapi)
745 x(ii+nside)=pinorm(-pi-x(ii+nside))
746 zm=convert_side(x(ii),x(ii+nside))
748 else if (x(ii).lt.0.0d0) then
751 if (iii.gt.0) x(iii)=pinorm(x(iii)+pi)
752 if (i.lt.nres) x(iii+1)=pinorm(x(iii+1)+pi)
755 x(ii+nside)=pinorm(-x(ii+nside))
756 zm=convert_side(x(ii),x(ii+nside))
763 !-----------------------------------------------------------------------------
764 real(kind=8) function thetnorm(x)
765 ! This function puts x within [0,2Pi].
768 ! include 'COMMON.GEO'
770 if (xx.lt.0.0d0) xx=xx+dwapi
771 if (xx.gt.0.9999d0*pi) xx=0.9999d0*pi
774 end function thetnorm
775 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
776 !-----------------------------------------------------------------------------
777 subroutine var_to_geom_restr(n,xx)
779 ! Update geometry parameters according to the variable array.
781 ! implicit real*8 (a-h,o-z)
782 ! include 'DIMENSIONS'
783 ! include 'COMMON.VAR'
784 ! include 'COMMON.CHAIN'
785 ! include 'COMMON.GEO'
786 ! include 'COMMON.IOUNITS'
788 real(kind=8),dimension(6*nres) :: x,xx !(maxvar) (maxvar=6*maxres)
789 logical :: change !,reduce
795 alph(ii)=x(nphi+ntheta+i)
796 omeg(ii)=pinorm(x(nphi+ntheta+nside+i))
803 if (theta(i).eq.pi) theta(i)=0.99d0*pi
807 end subroutine var_to_geom_restr
808 !-----------------------------------------------------------------------------
810 !-----------------------------------------------------------------------------
811 subroutine gen_rand_conf(nstart,*)
812 ! Generate random conformation or chain cut and regrowth.
814 use random, only: iran_num,ran_number
815 ! implicit real*8 (a-h,o-z)
816 ! include 'DIMENSIONS'
817 ! include 'COMMON.CHAIN'
818 ! include 'COMMON.LOCAL'
819 ! include 'COMMON.VAR'
820 ! include 'COMMON.INTERACT'
821 ! include 'COMMON.IOUNITS'
822 ! include 'COMMON.MCM'
823 ! include 'COMMON.GEO'
824 ! include 'COMMON.CONTROL'
825 logical :: back,fail !overlap,
827 integer :: i,nstart,maxsi,nsi,maxnit,nit,niter
828 integer :: it1,it2,it,j
829 !d print *,' CG Processor',me,' maxgen=',maxgen
831 write (iout,*) 'Gen_Rand_conf: nstart=',nstart,nres
832 if (nstart.lt.5) then
834 phi(4)=gen_phi(4,iabs(itype(2,1)),iabs(itype(3,1)))
835 ! write(iout,*)'phi(4)=',rad2deg*phi(4)
836 if (nstart.lt.3) theta(3)=gen_theta(iabs(itype(2,1)),pi,phi(4),molnum(2))
837 ! write(iout,*)'theta(3)=',rad2deg*theta(3)
838 if ((it1.ne.10).and.(it1.ne.ntyp1)) then
841 do while (fail.and.nsi.le.maxsi)
842 call gen_side(it1,theta(3),alph(2),omeg(2),fail,molnum(2))
843 write (iout,*) 'nsi=',nsi,maxsi
846 if (nsi.gt.maxsi) return 1
848 write(iout,*) "before origin_frame"
850 write(iout,*) "after origin_frame"
863 do while (i.le.nres .and. niter.lt.maxgen)
864 write(iout,*) 'i=',i,'back=',back
865 if (i.lt.nstart) then
867 write (iout,'(/80(1h*)/2a/80(1h*))') &
868 'Generation procedure went down to ',&
869 'chain beginning. Cannot continue...'
870 write (*,'(/80(1h*)/2a/80(1h*))') &
871 'Generation procedure went down to ',&
872 'chain beginning. Cannot continue...'
876 it1=iabs(itype(i-1,molnum(i-1)))
877 it2=iabs(itype(i-2,molnum(i-2)))
878 it=iabs(itype(i,molnum(i)))
879 if ((it.eq.ntyp1).and.(it1.eq.ntyp1)) &
880 vbld(i)=ran_number(30.0D0,40.0D0)
881 ! print *,'Gen_Rand_Conf: i=',i,' it=',it,' it1=',it1,' it2=',it2,&
882 ! ' nit=',nit,' niter=',niter,' maxgen=',maxgen
883 phi(i+1)=gen_phi(i+1,it1,it)
885 phi(i)=gen_phi(i+1,it2,it1)
886 ! print *,'phi(',i,')=',phi(i)
887 theta(i-1)=gen_theta(it2,phi(i-1),phi(i),molnum(i))
888 ! print *,"theta",theta(i-1),phi(i)
889 if ((it2.ne.10).and.(it2.ne.ntyp1)) then
892 do while (fail.and.nsi.le.maxsi)
893 call gen_side(it2,theta(i-1),alph(i-2),omeg(i-2),fail,molnum(i-2))
896 if (nsi.gt.maxsi) return 1
898 call locate_next_res(i-1)
900 theta(i)=gen_theta(it1,phi(i),phi(i+1),molnum(i))
901 ! write(iout,*) "theta(i),",theta(i)
902 if ((it1.ne.10).and.(it1.ne.ntyp1)) then
905 do while (fail.and.nsi.le.maxsi)
906 call gen_side(it1,theta(i),alph(i-1),omeg(i-1),fail,molnum(i))
907 ! write(iout,*)"alpha,omeg(i-1)",alph(i-1),omeg(i-1),i,nsi,maxsi
910 if (nsi.gt.maxsi) return 1
912 call locate_next_res(i)
913 write(iout,*) "overlap,",overlap(i-1)
914 if (overlap(i-1)) then
915 if (nit.lt.maxnit) then
925 'Cannot generate non-overlaping conformation. Increase MAXNIT.'
927 'Cannot generate non-overlaping conformation. Increase MAXNIT.'
932 ! write(iout,*) "tu dochodze"
939 if (niter.ge.maxgen) then
940 write (iout,'(a,2i5)') &
941 'Too many trials in conformation generation',niter,maxgen
942 write (*,'(a,2i5)') &
943 'Too many trials in conformation generation',niter,maxgen
948 c(j,nres+nres)=c(j,nres)
951 end subroutine gen_rand_conf
952 !-----------------------------------------------------------------------------
953 logical function overlap(i)
954 ! implicit real*8 (a-h,o-z)
955 ! include 'DIMENSIONS'
956 ! include 'COMMON.CHAIN'
957 ! include 'COMMON.INTERACT'
958 ! include 'COMMON.FFIELD'
959 integer :: i,j,iti,itj,iteli,itelj,k
960 real(kind=8) :: redfac,rcomp
965 iti=iabs(itype(i,molnum(i)))
966 if (iti.gt.ntyp) return
967 ! Check for SC-SC overlaps.
968 !d print *,'nnt=',nnt,' nct=',nct
970 ! print *, "molnum(j)",j,molnum(j)
971 if (molnum(j).eq.1) then
973 if (itj.eq.ntyp1) cycle
974 if (j.lt.i-1 .or. ipot.ne.4) then
975 rcomp=sigmaii(iti,itj)
980 if (dist(nres+i,nres+j).lt.redfac*rcomp) then
983 ! print *,'overlap, SC-SC: i=',i,' j=',j,
984 ! & ' dist=',dist(nres+i,nres+j),' rcomp=',
988 else if (molnum(j).eq.2) then
990 if (dist(nres+i,nres+j).lt.redfac*sigma_nucl(iti,itj)) then
993 ! print *,'overlap, SC-SC: i=',i,' j=',j,
994 ! & ' dist=',dist(nres+i,nres+j),' rcomp=',
1001 ! Check for overlaps between the added peptide group and the preceding
1005 ! c(j,nres2+1)=0.5D0*(c(j,i)+c(j,i+1))
1006 c(j,nres2+3)=0.5D0*(c(j,i)+c(j,i+1))
1009 if (molnum(j).ne.1) cycle
1010 itj=iabs(itype(j,1))
1011 !d print *,'overlap, p-Sc: i=',i,' j=',j,
1012 !d & ' dist=',dist(nres+j,maxres2+1)
1013 if (dist(nres+j,nres2+3).lt.4.0D0*redfac) then
1018 ! Check for overlaps between the added side chain and the preceding peptide
1021 if (molnum(j).ne.1) cycle
1023 c(k,nres2+3)=0.5D0*(c(k,j)+c(k,j+1))
1025 !d print *,'overlap, SC-p: i=',i,' j=',j,
1026 !d & ' dist=',dist(nres+i,maxres2+1)
1027 if (dist(nres+i,nres2+3).lt.4.0D0*redfac) then
1032 ! Check for p-p overlaps
1034 c(j,nres2+3)=0.5D0*(c(j,i)+c(j,i+1))
1037 ! if (molnum(j).eq.1) then
1040 c(k,nres2+4)=0.5D0*(c(k,j)+c(k,j+1))
1042 !d print *,'overlap, p-p: i=',i,' j=',j,
1043 !d & ' dist=',dist(maxres2+1,maxres2+2)
1044 if (molnum(j).eq.1) then
1045 if(iteli.ne.0.and.itelj.ne.0)then
1046 if (dist(nres2+3,nres2+4).lt.rpp(iteli,itelj)*redfac) then
1051 else if (molnum(j).eq.2) then
1052 if (dist(nres2+3,nres2+4).lt.3.0) then
1059 end function overlap
1060 !-----------------------------------------------------------------------------
1061 real(kind=8) function gen_phi(i,it1,it2)
1062 use random, only:ran_number
1063 ! implicit real*8 (a-h,o-z)
1064 ! include 'DIMENSIONS'
1065 ! include 'COMMON.GEO'
1066 ! include 'COMMON.BOUNDS'
1067 integer :: i,it1,it2
1068 ! gen_phi=ran_number(-pi,pi)
1069 ! 8/13/98 Generate phi using pre-defined boundaries
1070 gen_phi=ran_number(phibound(1,i),phibound(2,i))
1072 end function gen_phi
1073 !-----------------------------------------------------------------------------
1074 real(kind=8) function gen_theta(it,gama,gama1,mnum)
1075 use random,only:binorm,ran_number
1076 ! implicit real*8 (a-h,o-z)
1077 ! include 'DIMENSIONS'
1078 ! include 'COMMON.LOCAL'
1079 ! include 'COMMON.GEO'
1080 real(kind=8),dimension(2) :: y,z
1081 real(kind=8) :: theta_max,theta_min,sig,ak
1083 integer :: j,it,k,mnum
1084 real(kind=8) :: gama,gama1,thet_pred_mean,theta_temp
1085 ! print *,'gen_theta: it=',it
1088 if (dabs(gama).gt.dwapi) then
1095 if (dabs(gama1).gt.dwapi) then
1102 if (it.eq.ntyp1) then
1103 gen_theta=ran_number(theta_max/2.0,theta_max)
1104 else if (mnum.eq.1) then
1106 thet_pred_mean=a0thet(it)
1107 ! write(iout,*),it,thet_pred_mean,"gen_thet"
1109 thet_pred_mean=thet_pred_mean+athet(k,it,1,1)*y(k) &
1110 +bthet(k,it,1,1)*z(k)
1114 sig=sig*thet_pred_mean+polthet(j,it)
1116 sig=0.5D0/(sig*sig+sigc0(it))
1117 ak=dexp(gthet(1,it)- &
1118 0.5D0*((gthet(2,it)-thet_pred_mean)/gthet(3,it))**2)
1119 ! print '(i5,5(1pe14.4))',it,(gthet(j,it),j=1,3)
1120 ! print '(5(1pe14.4))',thet_pred_mean,theta0(it),sig,sig0(it),ak
1121 theta_temp=binorm(thet_pred_mean,theta0(it),sig,sig0(it),ak)
1122 if (theta_temp.lt.theta_min) theta_temp=theta_min
1123 if (theta_temp.gt.theta_max) theta_temp=theta_max
1124 gen_theta=theta_temp
1125 ! print '(a)','Exiting GENTHETA.'
1126 else if (mnum.eq.2) then
1127 gen_theta=2.0d0 + ran_number(0.0d0,0.34d0)
1129 gen_theta=ran_number(theta_max/2.0,theta_max)
1132 end function gen_theta
1133 !-----------------------------------------------------------------------------
1134 subroutine gen_side(it,the,al,om,fail,mnum)
1135 use random, only:ran_number,mult_norm1
1136 ! implicit real*8 (a-h,o-z)
1137 ! include 'DIMENSIONS'
1138 ! include 'COMMON.GEO'
1139 ! include 'COMMON.LOCAL'
1140 ! include 'COMMON.SETUP'
1141 ! include 'COMMON.IOUNITS'
1142 real(kind=8) :: MaxBoxLen=10.0D0
1143 real(kind=8),dimension(3,3) :: Ap_inv,a,vec
1144 real(kind=8),dimension(:,:),allocatable :: z !(3,maxlob)
1145 real(kind=8),dimension(:),allocatable :: W1,detAp !(maxlob)
1146 real(kind=8),dimension(:),allocatable :: sumW !(0:maxlob)
1147 real(kind=8),dimension(2) :: y,cm,eig
1148 real(kind=8),dimension(2,2) :: box
1149 real(kind=8),dimension(100) :: work
1150 real(kind=8) :: eig_limit=1.0D-8
1151 real(kind=8) :: Big=10.0D0
1152 logical :: lprint,fail,lcheck
1154 integer :: it,i,j,k,l,nlobit,ial,iom,iii,ilob,mnum
1155 real(kind=8) :: the,al,om,detApi,wart,y2,wykl,radmax
1156 real(kind=8) :: tant,zz1,W1i,radius,zk,fac,dV,sum,sum1
1157 real(kind=8) :: which_lobe
1162 if (the.eq.0.0D0 .or. the.eq.pi) then
1164 write (*,'(a,i4,a,i3,a,1pe14.5)') &
1165 'CG Processor:',me,' Error in GenSide: it=',it,' theta=',the
1167 !d write (iout,'(a,i3,a,1pe14.5)')
1168 !d & 'Error in GenSide: it=',it,' theta=',the
1173 if (nlobit.eq.0) then
1174 al=ran_number(0.05d0,pi/2)
1175 om=ran_number(-pi,pi)
1178 tant=dtan(the-pipol)
1180 allocate(z(3,nlobit))
1181 allocate(W1(nlobit))
1182 allocate(detAp(nlobit))
1183 allocate(sumW(0:nlobit))
1186 print '(a,i4,a)','CG Processor:',me,' Enter Gen_Side.'
1187 write (iout,'(a,i4,a)') 'Processor:',me,' Enter Gen_Side.'
1189 print *,'it=',it,' nlobit=',nlobit,' the=',the,' tant=',tant
1190 write (iout,*) 'it=',it,' nlobit=',nlobit,' the=',the,&
1194 zz1=tant-censc(1,i,it)
1197 a(k,l)=gaussc(k,l,i,it)
1200 detApi=a(2,2)*a(3,3)-a(2,3)**2
1201 Ap_inv(2,2)=a(3,3)/detApi
1202 Ap_inv(2,3)=-a(2,3)/detApi
1203 Ap_inv(3,2)=Ap_inv(2,3)
1204 Ap_inv(3,3)=a(2,2)/detApi
1206 write (*,'(/a,i2/)') 'Cluster #',i
1207 write (*,'(3(1pe14.5),5x,1pe14.5)') &
1208 ((a(l,k),l=1,3),censc(k,i,it),k=1,3)
1209 write (iout,'(/a,i2/)') 'Cluster #',i
1210 write (iout,'(3(1pe14.5),5x,1pe14.5)') &
1211 ((a(l,k),l=1,3),censc(k,i,it),k=1,3)
1216 W1i=W1i+a(k,1)*a(l,1)*Ap_inv(k,l)
1220 W1(i)=dexp(bsc(i,it)-0.5D0*W1i*zz1*zz1)
1221 ! if (lprint) write(*,'(a,3(1pe15.5)/)')
1222 ! & 'detAp, W1, anormi',detApi,W1i,anormi
1226 zk=zk+zz1*Ap_inv(k,l)*a(l,1)
1230 detAp(i)=dsqrt(detApi)
1234 print *,'W1:',(w1(i),i=1,nlobit)
1235 print *,'detAp:',(detAp(i),i=1,nlobit)
1238 print '(i2,3f10.5)',i,(rad2deg*z(j,i),j=2,3)
1240 write (iout,*) 'W1:',(w1(i),i=1,nlobit)
1241 write (iout,*) 'detAp:',(detAp(i),i=1,nlobit)
1244 write (iout,'(i2,3f10.5)') i,(rad2deg*z(j,i),j=2,3)
1248 ! Writing the distribution just to check the procedure
1250 dV=deg2rad**2*10.0D0
1254 fac=fac+W1(i)/detAp(i)
1256 fac=1.0D0/(2.0D0*fac*pi)
1257 !d print *,it,'fac=',fac
1266 a(j-1,k-1)=gaussc(j,k,i,it)
1278 wykl=wykl+a(j,k)*(y(j)-z(j+1,i))*(y(k)-z(k+1,i))
1281 wart=wart+W1(i)*dexp(-0.5D0*wykl)
1288 ! print *,'y',y(1),y(2),' fac=',fac
1290 write (20,'(2f10.3,1pd15.5)') y(1)*rad2deg,y(2)*rad2deg,wart
1295 ! print *,'it=',it,' sum=',sum*dV,' sum1=',sum1*dV
1299 ! Calculate the CM of the system
1302 W1(i)=W1(i)/detAp(i)
1306 sumW(i)=sumW(i-1)+W1(i)
1311 cm(1)=cm(1)+z(2,j)*W1(j)
1312 cm(2)=cm(2)+W1(j)*(z(3,1)+pinorm(z(3,j)-z(3,1)))
1314 cm(1)=cm(1)/sumW(nlobit)
1315 cm(2)=cm(2)/sumW(nlobit)
1316 if (cm(1).gt.Big .or. cm(1).lt.-Big .or. &
1317 cm(2).gt.Big .or. cm(2).lt.-Big) then
1318 !d write (iout,'(a)')
1319 !d & 'Unexpected error in GenSide - CM coordinates too large.'
1320 !d write (iout,'(i5,2(1pe14.5))') it,cm(1),cm(2)
1322 !d & 'Unexpected error in GenSide - CM coordinates too large.'
1323 !d write (*,'(i5,2(1pe14.5))') it,cm(1),cm(2)
1327 !d print *,'CM:',cm(1),cm(2)
1329 ! Find the largest search distance from CM
1335 a(j-1,k-1)=gaussc(j,k,i,it)
1339 call f02faf('N','U',2,a,3,eig,work,100,ifail)
1341 call djacob(2,3,10000,1.0d-10,a,vec,eig)
1345 print *,'*************** CG Processor',me
1346 print *,'CM:',cm(1),cm(2)
1347 write (iout,*) '*************** CG Processor',me
1348 write (iout,*) 'CM:',cm(1),cm(2)
1349 print '(A,8f10.5)','Eigenvalues: ',(1.0/dsqrt(eig(k)),k=1,2)
1350 write (iout,'(A,8f10.5)') &
1351 'Eigenvalues: ',(1.0/dsqrt(eig(k)),k=1,2)
1354 if (eig(1).lt.eig_limit) then
1356 'From Mult_Norm: Eigenvalues of A are too small.'
1358 'From Mult_Norm: Eigenvalues of A are too small.'
1365 radius=radius+pinorm(z(j+1,i)-cm(j))**2
1367 radius=dsqrt(radius)+3.0D0/dsqrt(eig(1))
1368 if (radius.gt.radmax) radmax=radius
1370 if (radmax.gt.pi) radmax=pi
1372 ! Determine the boundaries of the search rectangle.
1375 print '(a,4(1pe14.4))','W1: ',(W1(i),i=1,nlob(it) )
1376 print '(a,4(1pe14.4))','radmax: ',radmax
1378 box(1,1)=dmax1(cm(1)-radmax,0.0D0)
1379 box(2,1)=dmin1(cm(1)+radmax,pi)
1380 box(1,2)=cm(2)-radmax
1381 box(2,2)=cm(2)+radmax
1384 print *,'CG Processor',me,' Array BOX:'
1386 print *,'Array BOX:'
1388 print '(4(1pe14.4))',((box(k,j),k=1,2),j=1,2)
1389 print '(a,4(1pe14.4))','sumW: ',(sumW(i),i=0,nlob(it) )
1391 write (iout,*)'CG Processor',me,' Array BOX:'
1393 write (iout,*)'Array BOX:'
1395 write(iout,'(4(1pe14.4))') ((box(k,j),k=1,2),j=1,2)
1396 write(iout,'(a,4(1pe14.4))')'sumW: ',(sumW(i),i=0,nlob(it) )
1398 ! if (box(1,2).lt.-MaxBoxLen .or. box(2,2).gt.MaxBoxLen) then
1400 ! write (iout,'(a,i4,a,3e15.5)') 'CG Processor:',me,': bad sampling box.',box(1,2),box(2,2),radmax
1401 ! write (*,'(a,i4,a)') 'CG Processor:',me,': bad sampling box.'
1403 ! write (iout,'(a)') 'Bad sampling box.'
1408 which_lobe=ran_number(0.0D0,sumW(nlobit))
1409 ! print '(a,1pe14.4)','which_lobe=',which_lobe
1411 if (sumW(i-1).le.which_lobe .and. sumW(i).ge.which_lobe) goto 1
1414 ! print *,'ilob=',ilob,' nlob=',nlob(it)
1418 a(i-1,j-1)=gaussc(i,j,ilob,it)
1421 !d print '(a,i4,a)','CG Processor',me,' Calling MultNorm1.'
1422 call mult_norm1(3,2,a,cm,box,y,fail)
1426 else if (mnum.eq.2) then
1427 al=0.7+ran_number(0.0d0,0.2d0)
1428 om=ran_number(0.0d0,3.14d0)
1431 !d print *,'al=',al,' om=',om
1434 end subroutine gen_side
1435 !-----------------------------------------------------------------------------
1436 subroutine overlap_sc(scfail)
1438 ! Internal and cartesian coordinates must be consistent as input,
1439 ! and will be up-to-date on return.
1440 ! At the end of this procedure, scfail is true if there are
1441 ! overlapping residues left, or false otherwise (success)
1443 ! implicit real*8 (a-h,o-z)
1444 ! include 'DIMENSIONS'
1445 ! include 'COMMON.CHAIN'
1446 ! include 'COMMON.INTERACT'
1447 ! include 'COMMON.FFIELD'
1448 ! include 'COMMON.VAR'
1449 ! include 'COMMON.SBRIDGE'
1450 ! include 'COMMON.IOUNITS'
1451 logical :: had_overlaps,fail,scfail
1452 integer,dimension(nres) :: ioverlap !(maxres)
1453 integer :: ioverlap_last,k,maxsi,i,iti,nsi
1456 had_overlaps=.false.
1457 call overlap_sc_list(ioverlap,ioverlap_last)
1458 if (ioverlap_last.gt.0) then
1459 write (iout,*) '#OVERLAPing residues ',ioverlap_last
1460 write (iout,'(20i4)') (ioverlap(k),k=1,ioverlap_last)
1466 if (ioverlap_last.eq.0) exit
1468 do ires=1,ioverlap_last
1470 iti=iabs(itype(i,1))
1471 if ((iti.ne.10).and.(molnum(i).lt.3).and.(iti.ne.ntyp1)) then
1474 do while (fail.and.nsi.le.maxsi)
1475 call gen_side(iti,theta(i+1),alph(i),omeg(i),fail,molnum(i))
1483 call overlap_sc_list(ioverlap,ioverlap_last)
1484 ! write (iout,*) 'Overlaping residues ',ioverlap_last,
1485 ! & (ioverlap(j),j=1,ioverlap_last)
1488 if (k.le.1000.and.ioverlap_last.eq.0) then
1490 if (had_overlaps) then
1491 write (iout,*) '#OVERLAPing all corrected after ',k,&
1492 ' random generation'
1496 write (iout,*) '#OVERLAPing NOT all corrected ',ioverlap_last
1497 write (iout,'(20i4)') (ioverlap(j),j=1,ioverlap_last)
1503 write (iout,'(a30,i5,a12,i4)') &
1504 '#OVERLAP FAIL in gen_side after',maxsi,&
1508 end subroutine overlap_sc
1509 !-----------------------------------------------------------------------------
1510 subroutine overlap_sc_list(ioverlap,ioverlap_last)
1512 ! implicit real*8 (a-h,o-z)
1513 ! include 'DIMENSIONS'
1514 ! include 'COMMON.GEO'
1515 ! include 'COMMON.LOCAL'
1516 ! include 'COMMON.IOUNITS'
1517 ! include 'COMMON.CHAIN'
1518 ! include 'COMMON.INTERACT'
1519 ! include 'COMMON.FFIELD'
1520 ! include 'COMMON.VAR'
1521 ! include 'COMMON.CALC'
1523 integer,dimension(nres) :: ioverlap !(maxres)
1524 integer :: ioverlap_last
1527 real(kind=8) :: redfac,sig !rrij,sigsq,
1528 integer :: itypi,itypj,itypi1
1529 real(kind=8) :: xi,yi,zi,sig0ij,rcomp,rrij,rij_shift
1533 ! Check for SC-SC overlaps and mark residues
1534 ! print *,'>>overlap_sc nnt=',nnt,' nct=',nct
1536 do i=iatsc_s,iatsc_e
1537 if (itype(i,molnum(i)).eq.ntyp1_molec(molnum(i))) cycle
1538 if (molnum(i).eq.5) print *,"WTF",i,iatsc_s,iatsc_e
1539 if (molnum(i).eq.5) cycle
1540 itypi=iabs(itype(i,molnum(i)))
1541 itypi1=iabs(itype(i+1,1))
1545 dxi=dc_norm(1,nres+i)
1546 dyi=dc_norm(2,nres+i)
1547 dzi=dc_norm(3,nres+i)
1548 print *,i,itypi,"sc_move"
1549 dsci_inv=dsc_inv(itypi)
1551 do iint=1,nint_gr(i)
1552 do j=istart(i,iint),iend(i,iint)
1553 if (itype(j,molnum(j)).eq.ntyp1_molec(molnum(j))) cycle
1555 itypj=iabs(itype(j,molnum(j)))
1556 print *,j,itypj,"sc_move"
1558 dscj_inv=dsc_inv(itypj)
1559 sig0ij=sigma(itypi,itypj)
1560 chi1=chi(itypi,itypj)
1561 chi2=chi(itypj,itypi)
1568 alf12=0.5D0*(alf1+alf2)
1570 rcomp=sigmaii(itypi,itypj)
1572 rcomp=sigma(itypi,itypj)
1574 ! print '(2(a3,2i3),a3,2f10.5)',
1575 ! & ' i=',i,iti,' j=',j,itj,' d=',dist(nres+i,nres+j)
1580 dxj=dc_norm(1,nres+j)
1581 dyj=dc_norm(2,nres+j)
1582 dzj=dc_norm(3,nres+j)
1583 rrij=1.0D0/(xj*xj+yj*yj+zj*zj)
1587 sig=sig0ij*dsqrt(sigsq)
1588 rij_shift=1.0D0/rij-sig+sig0ij
1590 !t if ( 1.0/rij .lt. redfac*rcomp .or.
1591 !t & rij_shift.le.0.0D0 ) then
1592 if ( rij_shift.le.0.0D0 ) then
1593 !d write (iout,'(a,i3,a,i3,a,f10.5,a,3f10.5)')
1594 !d & 'overlap SC-SC: i=',i,' j=',j,
1595 !d & ' dist=',dist(nres+i,nres+j),' rcomp=',
1596 !d & rcomp,1.0/rij,rij_shift
1597 ioverlap_last=ioverlap_last+1
1598 ioverlap(ioverlap_last)=i
1599 do k=1,ioverlap_last-1
1600 if (ioverlap(k).eq.i) ioverlap_last=ioverlap_last-1
1602 ioverlap_last=ioverlap_last+1
1603 ioverlap(ioverlap_last)=j
1604 do k=1,ioverlap_last-1
1605 if (ioverlap(k).eq.j) ioverlap_last=ioverlap_last-1
1612 end subroutine overlap_sc_list
1614 !-----------------------------------------------------------------------------
1615 ! energy_p_new_barrier.F
1616 !-----------------------------------------------------------------------------
1617 subroutine sc_angular
1618 ! Calculate eps1,eps2,eps3,sigma, and parts of their derivatives in om1,om2,
1619 ! om12. Called by ebp, egb, and egbv.
1622 ! include 'COMMON.CALC'
1623 ! include 'COMMON.IOUNITS'
1627 om1=dxi*erij(1)+dyi*erij(2)+dzi*erij(3)
1628 om2=dxj*erij(1)+dyj*erij(2)+dzj*erij(3)
1629 om12=dxi*dxj+dyi*dyj+dzi*dzj
1631 ! Calculate eps1(om12) and its derivative in om12
1632 faceps1=1.0D0-om12*chiom12
1633 faceps1_inv=1.0D0/faceps1
1634 eps1=dsqrt(faceps1_inv)
1635 ! Following variable is eps1*deps1/dom12
1636 eps1_om12=faceps1_inv*chiom12
1641 ! write (iout,*) "om12",om12," eps1",eps1
1642 ! Calculate sigma(om1,om2,om12) and the derivatives of sigma**2 in om1,om2,
1647 facsig=om1*chiom1+om2*chiom2-2.0D0*om1om2*chiom12
1648 ! print *,"TUT?",om1*chiom1,facsig,om1,om2,om12
1649 sigsq=1.0D0-facsig*faceps1_inv
1650 sigsq_om1=(chiom1-chiom12*om2)*faceps1_inv
1651 sigsq_om2=(chiom2-chiom12*om1)*faceps1_inv
1652 sigsq_om12=-chi12*(om1om2*faceps1-om12*facsig)*faceps1_inv**2
1658 ! write (iout,*) "chiom1",chiom1," chiom2",chiom2," chiom12",chiom12
1659 ! write (iout,*) "faceps1",faceps1," faceps1_inv",faceps1_inv,
1661 ! Calculate eps2 and its derivatives in om1, om2, and om12.
1664 chipom12=chip12*om12
1665 facp=1.0D0-om12*chipom12
1667 facp1=om1*chipom1+om2*chipom2-2.0D0*om1om2*chipom12
1668 ! write (iout,*) "chipom1",chipom1," chipom2",chipom2,
1669 ! & " chipom12",chipom12," facp",facp," facp_inv",facp_inv
1670 ! Following variable is the square root of eps2
1671 eps2rt=1.0D0-facp1*facp_inv
1672 ! Following three variables are the derivatives of the square root of eps
1673 ! in om1, om2, and om12.
1674 eps2rt_om1=-4.0D0*(chipom1-chipom12*om2)*facp_inv
1675 eps2rt_om2=-4.0D0*(chipom2-chipom12*om1)*facp_inv
1676 eps2rt_om12=4.0D0*chip12*(om1om2*facp-om12*facp1)*facp_inv**2
1677 ! Evaluate the "asymmetric" factor in the VDW constant, eps3
1678 eps3rt=1.0D0-alf1*om1+alf2*om2-alf12*om12
1679 ! write (iout,*) "eps2rt",eps2rt," eps3rt",eps3rt
1680 ! write (iout,*) "eps2rt_om1",eps2rt_om1," eps2rt_om2",eps2rt_om2,
1681 ! & " eps2rt_om12",eps2rt_om12
1682 ! Calculate whole angle-dependent part of epsilon and contributions
1683 ! to its derivatives
1685 end subroutine sc_angular
1686 !-----------------------------------------------------------------------------
1688 subroutine sc_angular_nucl
1689 ! Calculate eps1,eps2,eps3,sigma, and parts of their derivatives in om1,om2,
1690 ! om12. Called by ebp, egb, and egbv.
1693 ! include 'COMMON.CALC'
1694 ! include 'COMMON.IOUNITS'
1700 om1=dxi*erij(1)+dyi*erij(2)+dzi*erij(3)
1701 om2=dxj*erij(1)+dyj*erij(2)+dzj*erij(3)
1702 om12=dxi*dxj+dyi*dyj+dzi*dzj
1704 ! Calculate eps1(om12) and its derivative in om12
1705 faceps1=1.0D0-om12*chiom12
1706 faceps1_inv=1.0D0/faceps1
1707 eps1=dsqrt(faceps1_inv)
1708 ! Following variable is eps1*deps1/dom12
1709 eps1_om12=faceps1_inv*chiom12
1714 ! write (iout,*) "om12",om12," eps1",eps1
1715 ! Calculate sigma(om1,om2,om12) and the derivatives of sigma**2 in om1,om2,
1720 facsig=om1*chiom1+om2*chiom2-2.0D0*om1om2*chiom12
1721 sigsq=1.0D0-facsig*faceps1_inv
1722 sigsq_om1=(chiom1-chiom12*om2)*faceps1_inv
1723 sigsq_om2=(chiom2-chiom12*om1)*faceps1_inv
1724 sigsq_om12=-chi12*(om1om2*faceps1-om12*facsig)*faceps1_inv**2
1727 chipom12=chip12*om12
1728 facp=1.0D0-om12*chipom12
1730 facp1=om1*chipom1+om2*chipom2-2.0D0*om1om2*chipom12
1731 ! write (iout,*) "chipom1",chipom1," chipom2",chipom2,
1732 ! & " chipom12",chipom12," facp",facp," facp_inv",facp_inv
1733 ! Following variable is the square root of eps2
1734 eps2rt=1.0D0-facp1*facp_inv
1735 ! Following three variables are the derivatives of the square root of eps
1736 ! in om1, om2, and om12.
1737 eps2rt_om1=-4.0D0*(chipom1-chipom12*om2)*facp_inv
1738 eps2rt_om2=-4.0D0*(chipom2-chipom12*om1)*facp_inv
1739 eps2rt_om12=4.0D0*chip12*(om1om2*facp-om12*facp1)*facp_inv**2
1740 ! Evaluate the "asymmetric" factor in the VDW constant, eps3
1741 eps3rt=1.0D0-alf1*om1+alf2*om2-alf12*om12
1742 ! write (iout,*) "eps2rt",eps2rt," eps3rt",eps3rt
1743 ! write (iout,*) "eps2rt_om1",eps2rt_om1," eps2rt_om2",eps2rt_om2,
1744 ! & " eps2rt_om12",eps2rt_om12
1745 ! Calculate whole angle-dependent part of epsilon and contributions
1746 ! to its derivatives
1748 end subroutine sc_angular_nucl
1750 !-----------------------------------------------------------------------------
1751 subroutine int_bounds(total_ints,lower_bound,upper_bound)
1752 ! implicit real*8 (a-h,o-z)
1753 ! include 'DIMENSIONS'
1755 ! include 'COMMON.SETUP'
1756 integer :: total_ints,lower_bound,upper_bound,nint
1757 integer,dimension(0:nfgtasks) :: int4proc,sint4proc !(0:max_fg_procs)
1758 integer :: i,nexcess
1759 if (total_ints.le.0) then
1764 nint=total_ints/nfgtasks
1768 nexcess=total_ints-nint*nfgtasks
1770 int4proc(nfgtasks-i)=int4proc(nfgtasks-i)+1
1774 lower_bound=lower_bound+int4proc(i)
1776 upper_bound=lower_bound+int4proc(fg_rank)
1777 lower_bound=lower_bound+1
1779 end subroutine int_bounds
1780 !-----------------------------------------------------------------------------
1781 subroutine int_bounds1(total_ints,lower_bound,upper_bound)
1782 ! implicit real*8 (a-h,o-z)
1783 ! include 'DIMENSIONS'
1785 ! include 'COMMON.SETUP'
1786 integer :: total_ints,lower_bound,upper_bound,nint
1787 integer :: nexcess,i
1788 integer,dimension(0:nfgtasks) :: int4proc,sint4proc !(0:max_fg_procs)
1789 nint=total_ints/nfgtasks1
1793 nexcess=total_ints-nint*nfgtasks1
1795 int4proc(nfgtasks1-i)=int4proc(nfgtasks1-i)+1
1799 lower_bound=lower_bound+int4proc(i)
1801 upper_bound=lower_bound+int4proc(fg_rank1)
1802 lower_bound=lower_bound+1
1804 end subroutine int_bounds1
1805 !-----------------------------------------------------------------------------
1807 !-----------------------------------------------------------------------------
1808 subroutine chainbuild_cart
1809 ! implicit real*8 (a-h,o-z)
1810 ! include 'DIMENSIONS'
1815 ! include 'COMMON.SETUP'
1816 ! include 'COMMON.CHAIN'
1817 ! include 'COMMON.LOCAL'
1818 ! include 'COMMON.TIME1'
1819 ! include 'COMMON.IOUNITS'
1820 integer :: j,i,ierror,ierr
1821 real(kind=8) :: time00,time01
1823 if (nfgtasks.gt.1) then
1824 ! write (iout,*) "BCAST in chainbuild_cart"
1826 ! Broadcast the order to build the chain and compute internal coordinates
1827 ! to the slaves. The slaves receive the order in ERGASTULUM.
1829 ! write (iout,*) "CHAINBUILD_CART: DC before BCAST"
1831 ! write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),
1832 ! & (dc(j,i+nres),j=1,3)
1835 call MPI_Bcast(7,1,MPI_INTEGER,king,FG_COMM,IERROR)
1836 time_bcast7=time_bcast7+MPI_Wtime()-time00
1838 call MPI_Bcast(dc(1,0),6*(nres+1),MPI_DOUBLE_PRECISION,&
1840 ! write (iout,*) "CHAINBUILD_CART: DC after BCAST"
1842 ! write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),
1843 ! & (dc(j,i+nres),j=1,3)
1845 ! write (iout,*) "End BCAST in chainbuild_cart"
1847 time_bcast=time_bcast+MPI_Wtime()-time00
1848 time_bcastc=time_bcastc+MPI_Wtime()-time01
1856 c(j,i)=c(j,i-1)+dc(j,i-1)
1861 c(j,i+nres)=c(j,i)+dc(j,i+nres)
1864 ! write (iout,*) "CHAINBUILD_CART"
1866 call int_from_cart1(.false.)
1868 end subroutine chainbuild_cart
1869 !-----------------------------------------------------------------------------
1871 !-----------------------------------------------------------------------------
1872 real(kind=8) function alpha(i1,i2,i3)
1874 ! Calculates the planar angle between atoms (i1), (i2), and (i3).
1876 ! implicit real*8 (a-h,o-z)
1877 ! include 'DIMENSIONS'
1878 ! include 'COMMON.GEO'
1879 ! include 'COMMON.CHAIN'
1882 real(kind=8) :: x12,x23,y12,y23,z12,z23,vnorm,wnorm,scalar
1889 vnorm=dsqrt(x12*x12+y12*y12+z12*z12)
1890 wnorm=dsqrt(x23*x23+y23*y23+z23*z23)
1891 scalar=(x12*x23+y12*y23+z12*z23)/(vnorm*wnorm)
1895 !-----------------------------------------------------------------------------
1896 real(kind=8) function beta(i1,i2,i3,i4)
1898 ! Calculates the dihedral angle between atoms (i1), (i2), (i3) and (i4)
1900 ! implicit real*8 (a-h,o-z)
1901 ! include 'DIMENSIONS'
1902 ! include 'COMMON.GEO'
1903 ! include 'COMMON.CHAIN'
1905 integer :: i1,i2,i3,i4
1906 real(kind=8) :: x12,x23,x34,y12,y23,y34,z12,z23,z34
1907 real(kind=8) :: wx,wy,wz,wnorm,vx,vy,vz,vnorm,scalar,angle
1908 real(kind=8) :: tx,ty,tz
1918 !d print '(2i3,3f10.5)',i1,i2,x12,y12,z12
1919 !d print '(2i3,3f10.5)',i2,i3,x23,y23,z23
1920 !d print '(2i3,3f10.5)',i3,i4,x34,y34,z34
1924 wnorm=dsqrt(wx*wx+wy*wy+wz*wz)
1928 vnorm=dsqrt(vx*vx+vy*vy+vz*vz)
1929 if (vnorm.gt.1.0D-13 .and. wnorm.gt.1.0D-13) then
1930 scalar=(vx*wx+vy*wy+vz*wz)/(vnorm*wnorm)
1931 if (dabs(scalar).gt.1.0D0) &
1932 scalar=0.99999999999999D0*scalar/dabs(scalar)
1934 !d print '(2i4,10f7.3)',i2,i3,vx,vy,vz,wx,wy,wz,vnorm,wnorm,
1939 ! if (angle.le.0.0D0) angle=pi+angle
1943 scalar=tx*x23+ty*y23+tz*z23
1944 if (scalar.lt.0.0D0) angle=-angle
1948 !-----------------------------------------------------------------------------
1949 real(kind=8) function dist(i1,i2)
1951 ! Calculates the distance between atoms (i1) and (i2).
1953 ! implicit real*8 (a-h,o-z)
1954 ! include 'DIMENSIONS'
1955 ! include 'COMMON.GEO'
1956 ! include 'COMMON.CHAIN'
1959 real(kind=8) :: x12,y12,z12
1963 dist=dsqrt(x12*x12+y12*y12+z12*z12)
1966 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
1967 !-----------------------------------------------------------------------------
1969 !-----------------------------------------------------------------------------
1970 subroutine local_move_init(debug)
1974 ! implicit real*8 (a-h,o-z)
1975 ! include 'DIMENSIONS' ! Needed by COMMON.LOCAL
1976 ! include 'COMMON.GEO' ! For pi, deg2rad
1977 ! include 'COMMON.LOCAL' ! For vbl
1978 ! include 'COMMON.LOCMOVE'
1984 ! Determine wheter to do some debugging output
1985 locmove_output=debug
1987 ! Set the init_called flag to 1
1990 ! The following are never changed
1991 min_theta=60.D0*deg2rad ! (0,PI)
1992 max_theta=175.D0*deg2rad ! (0,PI)
1993 dmin2=vbl*vbl*2.*(1.-cos(min_theta))
1994 dmax2=vbl*vbl*2.*(1.-cos(max_theta))
1997 small2=0.5*small*small
1999 ! Not really necessary...
2005 end subroutine local_move_init
2006 !-----------------------------------------------------------------------------
2007 subroutine local_move(n_start, n_end, PHImin, PHImax)
2008 ! Perform a local move between residues m and n (inclusive)
2009 ! PHImin and PHImax [0,PI] determine the size of the move
2010 ! Works on whatever structure is in the variables theta and phi,
2011 ! sidechain variables are left untouched
2012 ! The final structure is NOT minimized, but both the cartesian
2013 ! variables c and the angles are up-to-date at the end (no further
2014 ! chainbuild is required)
2016 use random,only:ran_number
2018 ! implicit real*8 (a-h,o-z)
2019 ! include 'DIMENSIONS'
2020 ! include 'COMMON.GEO'
2021 ! include 'COMMON.CHAIN'
2022 ! include 'COMMON.VAR'
2023 ! include 'COMMON.MINIM'
2024 ! include 'COMMON.SBRIDGE'
2025 ! include 'COMMON.LOCMOVE'
2027 ! External functions
2028 !EL integer move_res
2029 !EL external move_res
2030 !EL double precision ran_number
2031 !EL external ran_number
2034 integer :: n_start, n_end ! First and last residues to move
2035 real(kind=8) :: PHImin, PHImax ! min/max angles [0,PI]
2039 real(kind=8) :: min,max
2043 ! Check if local_move_init was called. This assumes that it
2044 ! would not be 1 if not explicitely initialized
2045 if (init_called.ne.1) then
2046 write(6,*)' *** local_move_init not called!!!'
2050 ! Quick check for crazy range
2051 if (n_start.gt.n_end .or. n_start.lt.1 .or. n_end.gt.nres) then
2052 write(6,'(a,i3,a,i3)') &
2053 ' *** Cannot make local move between n_start = ',&
2054 n_start,' and n_end = ',n_end
2058 ! Take care of end residues first...
2059 if (n_start.eq.1) then
2060 ! Move residue 1 (completely random)
2061 theta(3)=ran_number(min_theta,max_theta)
2062 phi(4)=ran_number(-PI,PI)
2067 if (n_end.eq.nres) then
2068 ! Move residue nres (completely random)
2069 theta(nres)=ran_number(min_theta,max_theta)
2070 phi(nres)=ran_number(-PI,PI)
2076 ! ...then go through all other residues one by one
2077 ! Start from the two extremes and converge
2082 !$$$c Move the first two residues by less than the others
2083 !$$$ if (i-n_start.lt.3) then
2084 !$$$ if (i-n_start.eq.0) then
2087 !$$$ else if (i-n_start.eq.1) then
2090 !$$$ else if (i-n_start.eq.2) then
2096 ! The actual move, on residue i
2097 iretcode=move_res(min,max,i) ! Discard iretcode
2103 !$$$c Move the last two residues by less than the others
2104 !$$$ if (n_end-j.lt.3) then
2105 !$$$ if (n_end-j.eq.0) then
2108 !$$$ else if (n_end-j.eq.1) then
2111 !$$$ else if (n_end-j.eq.2) then
2117 ! The actual move, on residue j
2118 iretcode=move_res(min,max,j) ! Discard iretcode
2123 call int_from_cart(.false.,.false.)
2126 end subroutine local_move
2127 !-----------------------------------------------------------------------------
2128 subroutine output_tabs
2129 ! Prints out the contents of a_..., b_..., res_...
2133 ! include 'COMMON.GEO'
2134 ! include 'COMMON.LOCMOVE'
2140 write(6,'(8f7.1)')(a_ang(i)*rad2deg,i=0,a_n-1)
2141 write(6,'(8(2x,3l1,2x))')((a_tab(i,j),i=0,2),j=0,a_n-1)
2144 write(6,'(4f7.1)')(b_ang(i)*rad2deg,i=0,b_n-1)
2145 write(6,'(4(2x,3l1,2x))')((b_tab(i,j),i=0,2),j=0,b_n-1)
2148 write(6,'(12f7.1)')(res_ang(i)*rad2deg,i=0,res_n-1)
2149 write(6,'(12(2x,3l1,2x))')((res_tab(0,i,j),i=0,2),j=0,res_n-1)
2150 write(6,'(12(2x,3l1,2x))')((res_tab(1,i,j),i=0,2),j=0,res_n-1)
2151 write(6,'(12(2x,3l1,2x))')((res_tab(2,i,j),i=0,2),j=0,res_n-1)
2154 end subroutine output_tabs
2155 !-----------------------------------------------------------------------------
2156 subroutine angles2tab(PHImin,PHImax,n,ang,tab)
2157 ! Only uses angles if [0,PI] (but PHImin cannot be 0.,
2158 ! and PHImax cannot be PI)
2162 ! include 'COMMON.GEO'
2165 real(kind=8) :: PHImin,PHImax
2169 real(kind=8),dimension(0:3) :: ang
2170 logical,dimension(0:2,0:3) :: tab
2173 if (PHImin .eq. PHImax) then
2174 ! Special case with two 010's
2184 else if (PHImin .eq. PI) then
2185 ! Special case with one 010
2191 else if (PHImax .eq. 0.) then
2192 ! Special case with one 010
2201 if (PHImin .gt. 0.) then
2202 ! Start of range (011)
2207 ! End of range (110)
2211 tab(2,n+1) = .false.
2214 if (PHImax .lt. PI) then
2215 ! Start of range (011)
2220 ! End of range (110)
2224 tab(2,n+1) = .false.
2230 end subroutine angles2tab
2231 !-----------------------------------------------------------------------------
2232 subroutine minmax_angles(x,y,z,r,n,ang,tab)
2233 ! When solutions do not exist, assume all angles
2234 ! are acceptable - i.e., initial geometry must be correct
2238 ! include 'COMMON.GEO'
2239 ! include 'COMMON.LOCMOVE'
2242 real(kind=8) :: x,y,z,r
2246 real(kind=8),dimension(0:3) :: ang
2247 logical,dimension(0:2,0:3) :: tab
2250 real(kind=8) :: num, denom, phi
2251 real(kind=8) :: Kmin, Kmax
2255 num = x*x + y*y + z*z
2258 if (denom .gt. 0.) then
2260 denom = 2.*r*sqrt(denom)
2262 Kmin = (num - dmin2)/denom
2263 Kmax = (num - dmax2)/denom
2265 ! Allowed values of K (else all angles are acceptable)
2268 if (Kmin .gt. 1. .or. abs(Kmin-1.) .lt. small2) then
2270 else if (Kmin .lt. -1. .or. abs(Kmin+1.) .lt. small2) then
2276 if (Kmax .lt. -1. .or. abs(Kmax+1.) .lt. small2) then
2278 else if (Kmax .gt. 1. .or. abs(Kmax-1.) .lt. small2) then
2284 if (Kmax .lt. Kmin) Kmax = Kmin
2286 call angles2tab(Kmin, Kmax, n, ang, tab)
2288 ! Add phi and check that angles are within range (-PI,PI]
2291 if (ang(i) .le. -PI) then
2292 ang(i) = ang(i)+2.*PI
2293 else if (ang(i) .gt. PI) then
2294 ang(i) = ang(i)-2.*PI
2300 end subroutine minmax_angles
2301 !-----------------------------------------------------------------------------
2302 subroutine construct_tab
2303 ! Take a_... and b_... values and produces the results res_...
2304 ! x_ang are assumed to be all different (diff > small)
2305 ! x_tab(1,i) must be 1 for all i (i.e., all x_ang are acceptable)
2309 ! include 'COMMON.LOCMOVE'
2312 integer :: n_max,i,j,index
2318 if (n_max .eq. 0) then
2325 res_tab(j,0,i) = .true.
2326 res_tab(j,2,i) = .true.
2327 res_tab(j,1,i) = .false.
2334 do while (.not.done)
2335 res_ang(index) = flag
2339 if ((a_ang(i)-phi).gt.small .and. &
2340 a_ang(i) .lt. res_ang(index)) then
2341 ! Found a lower angle
2342 res_ang(index) = a_ang(i)
2343 ! Copy the values from a_tab into res_tab(0,,)
2344 res_tab(0,0,index) = a_tab(0,i)
2345 res_tab(0,1,index) = a_tab(1,i)
2346 res_tab(0,2,index) = a_tab(2,i)
2347 ! Set default values for res_tab(1,,)
2348 res_tab(1,0,index) = .true.
2349 res_tab(1,1,index) = .false.
2350 res_tab(1,2,index) = .true.
2351 else if (abs(a_ang(i)-res_ang(index)).lt.small) then
2352 ! Found an equal angle (can only be equal to a b_ang)
2353 res_tab(0,0,index) = a_tab(0,i)
2354 res_tab(0,1,index) = a_tab(1,i)
2355 res_tab(0,2,index) = a_tab(2,i)
2360 if ((b_ang(i)-phi).gt.small .and. &
2361 b_ang(i) .lt. res_ang(index)) then
2362 ! Found a lower angle
2363 res_ang(index) = b_ang(i)
2364 ! Copy the values from b_tab into res_tab(1,,)
2365 res_tab(1,0,index) = b_tab(0,i)
2366 res_tab(1,1,index) = b_tab(1,i)
2367 res_tab(1,2,index) = b_tab(2,i)
2368 ! Set default values for res_tab(0,,)
2369 res_tab(0,0,index) = .true.
2370 res_tab(0,1,index) = .false.
2371 res_tab(0,2,index) = .true.
2372 else if (abs(b_ang(i)-res_ang(index)).lt.small) then
2373 ! Found an equal angle (can only be equal to an a_ang)
2374 res_tab(1,0,index) = b_tab(0,i)
2375 res_tab(1,1,index) = b_tab(1,i)
2376 res_tab(1,2,index) = b_tab(2,i)
2380 if (res_ang(index) .eq. flag) then
2383 else if (index .eq. n_max-1) then
2387 phi = res_ang(index) ! Store previous angle
2395 if (a_n .gt. 0) then
2396 do while (.not.res_tab(0,1,index))
2399 done = res_tab(0,2,index)
2400 do i=index+1,res_n-1
2401 if (res_tab(0,1,i)) then
2402 done = res_tab(0,2,i)
2404 res_tab(0,0,i) = done
2405 res_tab(0,1,i) = done
2406 res_tab(0,2,i) = done
2409 done = res_tab(0,0,index)
2411 if (res_tab(0,1,i)) then
2412 done = res_tab(0,0,i)
2414 res_tab(0,0,i) = done
2415 res_tab(0,1,i) = done
2416 res_tab(0,2,i) = done
2421 res_tab(0,0,i) = .true.
2422 res_tab(0,1,i) = .true.
2423 res_tab(0,2,i) = .true.
2428 if (b_n .gt. 0) then
2429 do while (.not.res_tab(1,1,index))
2432 done = res_tab(1,2,index)
2433 do i=index+1,res_n-1
2434 if (res_tab(1,1,i)) then
2435 done = res_tab(1,2,i)
2437 res_tab(1,0,i) = done
2438 res_tab(1,1,i) = done
2439 res_tab(1,2,i) = done
2442 done = res_tab(1,0,index)
2444 if (res_tab(1,1,i)) then
2445 done = res_tab(1,0,i)
2447 res_tab(1,0,i) = done
2448 res_tab(1,1,i) = done
2449 res_tab(1,2,i) = done
2454 res_tab(1,0,i) = .true.
2455 res_tab(1,1,i) = .true.
2456 res_tab(1,2,i) = .true.
2460 ! Finally fill the last row with AND operation
2463 res_tab(2,j,i) = (res_tab(0,j,i) .and. res_tab(1,j,i))
2468 end subroutine construct_tab
2469 !-----------------------------------------------------------------------------
2470 subroutine construct_ranges(phi_n,phi_start,phi_end)
2471 ! Given the data in res_..., construct a table of
2472 ! min/max allowed angles
2476 ! include 'COMMON.GEO'
2477 ! include 'COMMON.LOCMOVE'
2481 real(kind=8),dimension(0:11) :: phi_start,phi_end
2488 if (res_n .eq. 0) then
2489 ! Any move is allowed
2497 do while (.not.done)
2498 ! Find start of range (01x)
2500 do while (.not.done)
2501 if (res_tab(2,0,index).or.(.not.res_tab(2,1,index))) then
2505 phi_start(phi_n) = res_ang(index)
2507 if (index .eq. res_n) done = .true.
2509 ! If a start was found (index < res_n), find the end of range (x10)
2510 ! It may not be found without wrapping around
2511 if (index .lt. res_n) then
2513 do while (.not.done)
2514 if ((.not.res_tab(2,1,index)).or.res_tab(2,2,index)) then
2519 if (index .eq. res_n) done = .true.
2521 if (index .lt. res_n) then
2522 ! Found the end of the range
2523 phi_end(phi_n) = res_ang(index)
2526 if (index .eq. res_n) then
2532 ! Need to wrap around
2534 phi_end(phi_n) = flag
2538 ! Take care of the last one if need to wrap around
2539 if (phi_end(phi_n) .eq. flag) then
2541 do while ((.not.res_tab(2,1,index)).or.res_tab(2,2,index))
2544 phi_end(phi_n) = res_ang(index) + 2.*PI
2550 end subroutine construct_ranges
2551 !-----------------------------------------------------------------------------
2552 subroutine fix_no_moves(phi)
2556 ! include 'COMMON.GEO'
2557 ! include 'COMMON.LOCMOVE'
2564 real(kind=8) :: diff,temp
2567 ! Look for first 01x in gammas (there MUST be at least one)
2570 do while (res_tab(1,0,index) .or. (.not.res_tab(1,1,index)))
2573 if (res_ang(index) .le. 0.D0) then ! Make sure it's from PHImax
2574 ! Try to increase PHImax
2575 if (index .gt. 0) then
2576 phi = res_ang(index-1)
2577 diff = abs(res_ang(index) - res_ang(index-1))
2579 ! Look for last (corresponding) x10
2581 do while ((.not.res_tab(1,1,index)) .or. res_tab(1,2,index))
2584 if (index .lt. res_n-1) then
2585 temp = abs(res_ang(index) - res_ang(index+1))
2586 if (temp .lt. diff) then
2587 phi = res_ang(index+1)
2593 ! If increasing PHImax didn't work, decreasing PHImin
2594 ! will (with one exception)
2595 ! Look for first x10 (there MUST be at least one)
2597 do while ((.not.res_tab(1,1,index)) .or. res_tab(1,2,index))
2600 if (res_ang(index) .lt. 0.D0) then ! Make sure it's from PHImin
2601 ! Try to decrease PHImin
2602 if (index .lt. res_n-1) then
2603 temp = abs(res_ang(index) - res_ang(index+1))
2604 if (res_ang(index+1) .le. 0.D0 .and. temp .lt. diff) then
2605 phi = res_ang(index+1)
2609 ! Look for last (corresponding) 01x
2611 do while (res_tab(1,0,index) .or. (.not.res_tab(1,1,index)))
2614 if (index .gt. 0) then
2615 temp = abs(res_ang(index) - res_ang(index-1))
2616 if (res_ang(index-1) .ge. 0.D0 .and. temp .lt. diff) then
2617 phi = res_ang(index-1)
2623 ! If it still didn't work, it must be PHImax == 0. or PHImin == PI
2624 if (diff .eq. flag) then
2626 if (res_tab(index,1,0) .or. (.not.res_tab(index,1,1)) .or. &
2627 res_tab(index,1,2)) index = res_n - 1
2628 ! This MUST work at this point
2629 if (index .eq. 0) then
2632 phi = res_ang(index - 1)
2637 end subroutine fix_no_moves
2638 !-----------------------------------------------------------------------------
2639 integer function move_res(PHImin,PHImax,i_move)
2640 ! Moves residue i_move (in array c), leaving everything else fixed
2641 ! Starting geometry is not checked, it should be correct!
2642 ! R(,i_move) is the only residue that will move, but must have
2643 ! 1 < i_move < nres (i.e., cannot move ends)
2644 ! Whether any output is done is controlled by locmove_output
2646 use random,only:ran_number
2648 ! implicit real*8 (a-h,o-z)
2649 ! include 'DIMENSIONS'
2650 ! include 'COMMON.CHAIN'
2651 ! include 'COMMON.GEO'
2652 ! include 'COMMON.LOCMOVE'
2654 ! External functions
2655 !EL double precision ran_number
2656 !EL external ran_number
2659 real(kind=8) :: PHImin,PHImax
2663 ! 0: move successfull
2664 ! 1: Dmin or Dmax had to be modified
2665 ! 2: move failed - check your input geometry
2669 real(kind=8),dimension(0:2) :: X,Y,Z,Orig
2670 real(kind=8),dimension(0:2) :: P
2671 logical :: no_moves,done
2672 integer :: index,i,j
2673 real(kind=8) :: phi,temp,radius
2674 real(kind=8),dimension(0:11) :: phi_start,phi_end
2677 ! Set up the coordinate system
2679 Orig(i)=0.5*(c(i+1,i_move-1)+c(i+1,i_move+1)) ! Position of origin
2683 Z(i)=c(i+1,i_move+1)-c(i+1,i_move-1)
2685 temp=sqrt(Z(0)*Z(0)+Z(1)*Z(1)+Z(2)*Z(2))
2691 X(i)=c(i+1,i_move)-Orig(i)
2693 ! radius is the radius of the circle on which c(,i_move) can move
2694 radius=sqrt(X(0)*X(0)+X(1)*X(1)+X(2)*X(2))
2699 Y(0)=Z(1)*X(2)-X(1)*Z(2)
2700 Y(1)=X(0)*Z(2)-Z(0)*X(2)
2701 Y(2)=Z(0)*X(1)-X(0)*Z(1)
2703 ! Calculate min, max angles coming from dmin, dmax to c(,i_move-2)
2704 if (i_move.gt.2) then
2706 P(i)=c(i+1,i_move-2)-Orig(i)
2708 call minmax_angles(P(0)*X(0)+P(1)*X(1)+P(2)*X(2),&
2709 P(0)*Y(0)+P(1)*Y(1)+P(2)*Y(2),&
2710 P(0)*Z(0)+P(1)*Z(1)+P(2)*Z(2),&
2711 radius,a_n,a_ang,a_tab)
2716 ! Calculate min, max angles coming from dmin, dmax to c(,i_move+2)
2717 if (i_move.lt.nres-2) then
2719 P(i)=c(i+1,i_move+2)-Orig(i)
2721 call minmax_angles(P(0)*X(0)+P(1)*X(1)+P(2)*X(2),&
2722 P(0)*Y(0)+P(1)*Y(1)+P(2)*Y(2),&
2723 P(0)*Z(0)+P(1)*Z(1)+P(2)*Z(2),&
2724 radius,b_n,b_ang,b_tab)
2729 ! Construct the resulting table for alpha and beta
2730 call construct_tab()
2732 if (locmove_output) then
2733 print *,'ALPHAS & BETAS TABLE'
2737 ! Check that there is at least one possible move
2739 if (res_n .eq. 0) then
2743 do while ((index .lt. res_n) .and. no_moves)
2744 if (res_tab(2,1,index)) no_moves = .false.
2749 if (locmove_output) print *,' *** Cannot move anywhere'
2754 ! Transfer res_... into a_...
2757 if ( (res_tab(2,0,i).neqv.res_tab(2,1,i)) .or. &
2758 (res_tab(2,0,i).neqv.res_tab(2,2,i)) ) then
2759 a_ang(a_n) = res_ang(i)
2761 a_tab(j,a_n) = res_tab(2,j,i)
2767 ! Check that the PHI's are within [0,PI]
2768 if (PHImin .lt. 0. .or. abs(PHImin) .lt. small) PHImin = -flag
2769 if (PHImin .gt. PI .or. abs(PHImin-PI) .lt. small) PHImin = PI
2770 if (PHImax .gt. PI .or. abs(PHImax-PI) .lt. small) PHImax = flag
2771 if (PHImax .lt. 0. .or. abs(PHImax) .lt. small) PHImax = 0.
2772 if (PHImax .lt. PHImin) PHImax = PHImin
2773 ! Calculate min and max angles coming from PHImin and PHImax,
2774 ! and put them in b_...
2775 call angles2tab(PHImin, PHImax, b_n, b_ang, b_tab)
2776 ! Construct the final table
2777 call construct_tab()
2779 if (locmove_output) then
2780 print *,'FINAL TABLE'
2784 ! Check that there is at least one possible move
2786 if (res_n .eq. 0) then
2790 do while ((index .lt. res_n) .and. no_moves)
2791 if (res_tab(2,1,index)) no_moves = .false.
2797 ! Take care of the case where no solution exists...
2798 call fix_no_moves(phi)
2799 if (locmove_output) then
2800 print *,' *** Had to modify PHImin or PHImax'
2801 print *,'phi: ',phi*rad2deg
2805 ! ...or calculate the solution
2806 ! Construct phi_start/phi_end arrays
2807 call construct_ranges(phi_n, phi_start, phi_end)
2808 ! Choose random angle phi in allowed range(s)
2811 temp = temp + phi_end(i) - phi_start(i)
2813 phi = ran_number(phi_start(0),phi_start(0)+temp)
2816 do while (.not.done)
2817 if (phi .lt. phi_end(index)) then
2822 if (index .eq. phi_n) then
2824 else if (.not.done) then
2825 phi = phi + phi_start(index) - phi_end(index-1)
2828 if (index.eq.phi_n) phi=phi_end(phi_n-1) ! Fix numerical errors
2829 if (phi .gt. PI) phi = phi-2.*PI
2831 if (locmove_output) then
2832 print *,'ALLOWED RANGE(S)'
2834 print *,phi_start(i)*rad2deg,phi_end(i)*rad2deg
2836 print *,'phi: ',phi*rad2deg
2841 ! Re-use radius as temp variable
2842 temp=radius*cos(phi)
2843 radius=radius*sin(phi)
2845 c(i+1,i_move)=Orig(i)+temp*X(i)+radius*Y(i)
2849 end function move_res
2850 !-----------------------------------------------------------------------------
2855 ! implicit real*8 (a-h,o-z)
2856 ! include 'DIMENSIONS'
2857 ! include 'COMMON.GEO'
2858 ! include 'COMMON.LOCAL'
2859 ! include 'COMMON.LOCMOVE'
2861 ! External functions
2862 !EL integer move_res
2863 !EL external move_res
2868 real(kind=8),dimension(0:11) :: phi_start,phi_end
2870 real(kind=8),dimension(0:2,0:5) :: R
2872 locmove_output=.true.
2874 ! call angles2tab(30.*deg2rad,70.*deg2rad,a_n,a_ang,a_tab)
2875 ! call angles2tab(80.*deg2rad,130.*deg2rad,b_n,b_ang,b_tab)
2876 ! call minmax_angles(0.D0,3.8D0,0.D0,3.8D0,b_n,b_ang,b_tab)
2877 ! call construct_tab
2880 ! call construct_ranges(phi_n,phi_start,phi_end)
2882 ! print *,phi_start(i)*rad2deg,phi_end(i)*rad2deg
2885 ! call fix_no_moves(phi)
2886 ! print *,'NO MOVES FOUND, BEST PHI IS',phi*rad2deg
2892 R(1,1)=-cos(28.D0*deg2rad)
2893 R(2,1)=-0.5D0-sin(28.D0*deg2rad)
2897 R(0,3)=cos(30.D0*deg2rad)
2904 R(1,5)=cos(26.D0*deg2rad)
2905 R(2,5)=0.5D0+sin(26.D0*deg2rad)
2911 ! i=move_res(R(0,1),0.D0*deg2rad,180.D0*deg2rad)
2913 i=move_res(0.D0*deg2rad,180.D0*deg2rad,imov)
2914 print *,'RETURNED ',i
2915 print *,(R(i,3)/vbl,i=0,2)
2918 end subroutine loc_test
2920 !-----------------------------------------------------------------------------
2922 !-----------------------------------------------------------------------------
2923 subroutine MATMULT(A1,A2,A3)
2924 ! implicit real*8 (a-h,o-z)
2925 ! include 'DIMENSIONS'
2928 real(kind=8) :: A3IJ
2930 real(kind=8),DIMENSION(3,3) :: A1,A2,A3
2931 real(kind=8),DIMENSION(3,3) :: AI3
2936 3 A3IJ=A3IJ+A1(I,K)*A2(K,J)
2944 end subroutine MATMULT
2945 !-----------------------------------------------------------------------------
2947 !-----------------------------------------------------------------------------
2948 subroutine int_from_cart(lside,lprn)
2949 ! implicit real*8 (a-h,o-z)
2950 ! include 'DIMENSIONS'
2951 use control_data,only:out1file
2955 ! include 'COMMON.LOCAL'
2956 ! include 'COMMON.VAR'
2957 ! include 'COMMON.CHAIN'
2958 ! include 'COMMON.INTERACT'
2959 ! include 'COMMON.IOUNITS'
2960 ! include 'COMMON.GEO'
2961 ! include 'COMMON.NAMES'
2962 ! include 'COMMON.CONTROL'
2963 ! include 'COMMON.SETUP'
2964 character(len=3) :: seq,res
2966 character(len=80) :: card
2967 real(kind=8),dimension(3,20) :: sccor
2968 integer :: i,j,iti !el rescode,
2969 logical :: lside,lprn
2970 real(kind=8) :: di,cosfac,sinfac
2974 if(me.eq.king.or..not.out1file)then
2976 write (iout,'(/a)') &
2977 'Internal coordinates calculated from crystal structure.'
2979 write (iout,'(8a)') ' Res ',' dvb',' Theta',&
2980 ' Gamma',' Dsc_id',' Dsc',' Alpha',&
2983 write (iout,'(4a)') ' Res ',' dvb',' Theta',&
2989 ! if (molnum(i).ne.1) cycle
2990 !in wham do i=1,nres
2992 if (((dist(i,i+1).lt.2.0D0 .or. dist(i,i+1).gt.5.0D0).and.&
2993 (iti.ne.ntyp1 .and. itype(i+1,1).ne.ntyp1)).and.molnum(i).eq.1) then
2994 write (iout,'(a,i4)') 'Bad Cartesians for residue',i
2998 vbld(i+1)=dist(i,i+1)
2999 vbld_inv(i+1)=1.0d0/vbld(i+1)
3001 if (i.gt.1) theta(i+1)=alpha(i-1,i,i+1)
3002 if (i.gt.2) phi(i+1)=beta(i-2,i-1,i,i+1)
3006 ! if (itype(1,1).eq.ntyp1) then
3008 ! c(j,1)=c(j,2)+(c(j,3)-c(j,4))
3011 ! if (itype(nres,1).eq.ntyp1) then
3013 ! c(j,nres)=c(j,nres-1)+(c(j,nres-2)-c(j,nres-3))
3017 ! if (unres_pdb) then
3018 ! if (itype(1,1).eq.21) then
3019 ! theta(3)=90.0d0*deg2rad
3020 ! phi(4)=180.0d0*deg2rad
3022 ! vbld_inv(2)=1.0d0/vbld(2)
3024 ! if (itype(nres,1).eq.21) then
3025 ! theta(nres)=90.0d0*deg2rad
3026 ! phi(nres)=180.0d0*deg2rad
3028 ! vbld_inv(nres)=1.0d0/vbld(2)
3034 c(j,nres2+2)=0.5D0*(2*c(j,i)+(c(j,i-1)-c(j,i))*vbld_inv(i) &
3035 +(c(j,i+1)-c(j,i))*vbld_inv(i+1))
3036 ! in wham c(j,maxres2)=0.5D0*(c(j,i-1)+c(j,i+1)
3041 ! 10/03/12 Adam: Correction for zero SC-SC bond length
3043 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1 .and. di.eq.0.0d0) &
3044 di=dsc(itype(i,molnum(i)))
3046 if (itype(i,1).ne.10) then
3047 vbld_inv(i+nres)=1.0d0/di
3049 vbld_inv(i+nres)=0.0d0
3053 alph(i)=alpha(nres+i,i,nres2+2)
3054 omeg(i)=beta(nres+i,i,nres2+2,i+1)
3057 if(me.eq.king.or..not.out1file)then
3059 write (iout,'(a3,i4,7f10.3)') restyp(iti,1),i,vbld(i),&
3060 rad2deg*theta(i),rad2deg*phi(i),dsc(iti),vbld(nres+i),&
3061 rad2deg*alph(i),rad2deg*omeg(i)
3064 if(me.eq.king.or..not.out1file)then
3066 write (iout,'(a3,i4,7f10.3)') restyp(iti,1),i,vbld(i),&
3067 rad2deg*theta(i),rad2deg*phi(i),dsc(iti+1),vbld(nres+i),&
3068 rad2deg*alph(i),rad2deg*omeg(i)
3075 if(me.eq.king.or..not.out1file) &
3076 write (iout,'(a3,i4,7f10.3)') restyp(iti,1),i,dist(i,i-1),&
3077 rad2deg*theta(i),rad2deg*phi(i)
3081 end subroutine int_from_cart
3082 !-----------------------------------------------------------------------------
3083 subroutine sc_loc_geom(lprn)
3084 ! implicit real*8 (a-h,o-z)
3085 ! include 'DIMENSIONS'
3086 use control_data,only:out1file
3090 ! include 'COMMON.LOCAL'
3091 ! include 'COMMON.VAR'
3092 ! include 'COMMON.CHAIN'
3093 ! include 'COMMON.INTERACT'
3094 ! include 'COMMON.IOUNITS'
3095 ! include 'COMMON.GEO'
3096 ! include 'COMMON.NAMES'
3097 ! include 'COMMON.CONTROL'
3098 ! include 'COMMON.SETUP'
3099 real(kind=8),dimension(3) :: x_prime,y_prime,z_prime
3102 integer :: i,j,it,iti
3103 real(kind=8) :: cosfac2,sinfac2,xx,yy,zz,cosfac,sinfac
3106 dc_norm(j,i)=vbld_inv(i+1)*(c(j,i+1)-c(j,i))
3110 if (itype(i,1).ne.10) then
3112 dc_norm(j,i+nres)=vbld_inv(i+nres)*(c(j,i+nres)-c(j,i))
3116 dc_norm(j,i+nres)=0.0d0
3121 costtab(i+1) =dcos(theta(i+1))
3122 sinttab(i+1) =dsqrt(1-costtab(i+1)*costtab(i+1))
3123 cost2tab(i+1)=dsqrt(0.5d0*(1.0d0+costtab(i+1)))
3124 sint2tab(i+1)=dsqrt(0.5d0*(1.0d0-costtab(i+1)))
3125 cosfac2=0.5d0/(1.0d0+costtab(i+1))
3126 cosfac=dsqrt(cosfac2)
3127 sinfac2=0.5d0/(1.0d0-costtab(i+1))
3128 sinfac=dsqrt(sinfac2)
3131 if ((it.ne.10).and.(it.ne.ntyp1)) then
3132 !el if (it.ne.10) then
3134 ! Compute the axes of tghe local cartesian coordinates system; store in
3135 ! x_prime, y_prime and z_prime
3143 x_prime(j) = (dc_norm(j,i) - dc_norm(j,i-1))*cosfac
3144 y_prime(j) = (dc_norm(j,i) + dc_norm(j,i-1))*sinfac
3146 call vecpr(x_prime,y_prime,z_prime)
3148 ! Transform the unit vector of the ith side-chain centroid, dC_norm(*,i),
3149 ! to local coordinate system. Store in xx, yy, zz.
3155 xx = xx + x_prime(j)*dc_norm(j,i+nres)
3156 yy = yy + y_prime(j)*dc_norm(j,i+nres)
3157 zz = zz + z_prime(j)*dc_norm(j,i+nres)
3172 if(me.eq.king.or..not.out1file) &
3173 write (iout,'(a3,i4,3f10.5)') restyp(iti,1),i,xxref(i),&
3179 end subroutine sc_loc_geom
3180 !-----------------------------------------------------------------------------
3181 subroutine sccenter(ires,nscat,sccor)
3182 ! implicit real*8 (a-h,o-z)
3183 ! include 'DIMENSIONS'
3184 ! include 'COMMON.CHAIN'
3185 integer :: i,j,ires,nscat
3186 real(kind=8),dimension(3,20) :: sccor
3187 real(kind=8) :: sccmj
3188 ! print *,"I am in sccenter",ires,nscat
3192 sccmj=sccmj+sccor(j,i)
3193 !C print *,"insccent", ires,sccor(j,i)
3195 dc(j,ires)=sccmj/nscat
3198 end subroutine sccenter
3199 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
3200 !-----------------------------------------------------------------------------
3201 subroutine bond_regular
3203 ! implicit real*8 (a-h,o-z)
3204 ! include 'DIMENSIONS'
3205 ! include 'COMMON.VAR'
3206 ! include 'COMMON.LOCAL'
3207 ! include 'COMMON.CALC'
3208 ! include 'COMMON.INTERACT'
3209 ! include 'COMMON.CHAIN'
3213 vbld_inv(i+1)=1.0d0/vbld(i+1)
3214 vbld(i+1+nres)=dsc(itype(i+1,molnum(i)))
3215 vbld_inv(i+1+nres)=dsc_inv(itype(i+1,molnum(i)))
3216 ! print *,vbld(i+1),vbld(i+1+nres)
3219 end subroutine bond_regular
3221 !-----------------------------------------------------------------------------
3223 !-----------------------------------------------------------------------------
3224 subroutine refsys(i2,i3,i4,e1,e2,e3,fail)
3225 ! This subroutine calculates unit vectors of a local reference system
3226 ! defined by atoms (i2), (i3), and (i4). The x axis is the axis from
3227 ! atom (i3) to atom (i2), and the xy plane is the plane defined by atoms
3228 ! (i2), (i3), and (i4). z axis is directed according to the sign of the
3229 ! vector product (i3)-(i2) and (i3)-(i4). Sets fail to .true. if atoms
3230 ! (i2) and (i3) or (i3) and (i4) coincide or atoms (i2), (i3), and (i4)
3231 ! form a linear fragment. Returns vectors e1, e2, and e3.
3232 ! implicit real*8 (a-h,o-z)
3233 ! include 'DIMENSIONS'
3235 real(kind=8),dimension(3) :: e1,e2,e3
3236 real(kind=8),dimension(3) :: u,z
3237 ! include 'COMMON.IOUNITS'
3238 ! include 'COMMON.CHAIN'
3239 real(kind=8) :: coinc=1.0D-13,align=1.0D-13
3241 integer :: i,i1,i2,i3,i4
3242 real(kind=8) :: v1,v2,v3,s1,s2,zi,ui,anorm
3255 if (s1.gt.coinc) goto 2
3256 write (iout,1000) i2,i3,i1
3261 2 if (s2.gt.coinc) goto 4
3262 write(iout,1000) i3,i4,i1
3269 v1=z(2)*u(3)-z(3)*u(2)
3270 v2=z(3)*u(1)-z(1)*u(3)
3271 v3=z(1)*u(2)-z(2)*u(1)
3272 anorm=dsqrt(v1*v1+v2*v2+v3*v3)
3273 if (anorm.gt.align) goto 6
3274 write (iout,1010) i2,i3,i4,i1
3286 e2(1)=e1(3)*e3(2)-e1(2)*e3(3)
3287 e2(2)=e1(1)*e3(3)-e1(3)*e3(1)
3288 e2(3)=e1(2)*e3(1)-e1(1)*e3(2)
3289 1000 format (/1x,' * * * Error - atoms',i4,' and',i4,' coincide.',&
3290 'coordinates of atom',i4,' are set to zero.')
3291 1010 format (/1x,' * * * Error - atoms',2(i4,2h, ),i4,' form a linear',&
3292 ' fragment. coordinates of atom',i4,' are set to zero.')
3294 end subroutine refsys
3295 !-----------------------------------------------------------------------------
3297 !-----------------------------------------------------------------------------
3298 subroutine int_to_cart
3299 !--------------------------------------------------------------
3300 ! This subroutine converts the energy derivatives from internal
3301 ! coordinates to cartesian coordinates
3302 !-------------------------------------------------------------
3303 ! implicit real*8 (a-h,o-z)
3304 ! include 'DIMENSIONS'
3305 ! include 'COMMON.VAR'
3306 ! include 'COMMON.CHAIN'
3307 ! include 'COMMON.DERIV'
3308 ! include 'COMMON.GEO'
3309 ! include 'COMMON.LOCAL'
3310 ! include 'COMMON.INTERACT'
3311 ! include 'COMMON.MD'
3312 ! include 'COMMON.IOUNITS'
3313 ! include 'COMMON.SCCOR'
3314 ! calculating dE/ddc1
3317 ! print *,"gloc",gloc(:,:)
3318 ! print *, "gcart",gcart(:,:)
3319 if (nres.lt.3) go to 18
3321 gcart(j,1)=gcart(j,1)+gloc(1,icg)*dphi(j,1,4) &
3322 +gloc(nres-2,icg)*dtheta(j,1,3)
3323 ! write(iout,*) "pierwszy gcart", gcart(j,2)
3324 if ((itype(2,1).ne.10).and.&
3325 (itype(2,molnum(2)).ne.ntyp1_molec(molnum(2)).and.(molnum(2).lt.3))) then
3326 gcart(j,1)=gcart(j,1)+gloc(ialph(2,1),icg)*dalpha(j,1,2)+ &
3327 gloc(ialph(2,1)+nside,icg)*domega(j,1,2)
3330 ! Calculating the remainder of dE/ddc2
3332 gcart(j,2)=gcart(j,2)+gloc(1,icg)*dphi(j,2,4)+ &
3333 gloc(nres-2,icg)*dtheta(j,2,3)+gloc(nres-1,icg)*dtheta(j,1,4)
3334 ! write(iout,*) "drugi gcart", gcart(j,2)
3335 if((itype(2,1).ne.10).and.(molnum(2).lt.3)) then
3336 gcart(j,2)=gcart(j,2)+gloc(ialph(2,1),icg)*dalpha(j,2,2)+ &
3337 gloc(ialph(2,1)+nside,icg)*domega(j,2,2)
3339 if(itype(3,1).ne.10) then
3340 gcart(j,2)=gcart(j,2)+gloc(ialph(3,1),icg)*dalpha(j,1,3)+ &
3341 gloc(ialph(3,1)+nside,icg)*domega(j,1,3)
3344 gcart(j,2)=gcart(j,2)+gloc(2,icg)*dphi(j,1,5)
3347 ! If there are only five residues
3350 gcart(j,3)=gcart(j,3)+gloc(1,icg)*dphi(j,3,4)+gloc(2,icg)* &
3351 dphi(j,2,5)+gloc(nres-1,icg)*dtheta(j,2,4)+gloc(nres,icg)* &
3353 ! if(itype(3,1).ne.10) then
3354 if ((itype(3,1).ne.10).and.&
3355 (itype(3,molnum(3)).ne.ntyp1_molec(molnum(3)))) then
3356 gcart(j,3)=gcart(j,3)+gloc(ialph(3,1),icg)* &
3357 dalpha(j,2,3)+gloc(ialph(3,1)+nside,icg)*domega(j,2,3)
3359 ! if(itype(4,1).ne.10) then
3360 if ((itype(4,1).ne.10).and.&
3361 (itype(4,molnum(4)).ne.ntyp1_molec(molnum(4)))) then
3362 gcart(j,3)=gcart(j,3)+gloc(ialph(4,1),icg)* &
3363 dalpha(j,1,4)+gloc(ialph(4,1)+nside,icg)*domega(j,1,4)
3367 ! If there are more than five residues
3371 gcart(j,i)=gcart(j,i)+gloc(i-2,icg)*dphi(j,3,i+1) &
3372 +gloc(i-1,icg)*dphi(j,2,i+2)+ &
3373 gloc(i,icg)*dphi(j,1,i+3)+gloc(nres+i-4,icg)*dtheta(j,2,i+1)+ &
3374 gloc(nres+i-3,icg)*dtheta(j,1,i+2)
3375 if((itype(i,1).ne.10).and.(molnum(nres-1).lt.3)) then
3376 gcart(j,i)=gcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,2,i)+ &
3377 gloc(ialph(i,1)+nside,icg)*domega(j,2,i)
3379 if(itype(i+1,1).ne.10) then
3380 gcart(j,i)=gcart(j,i)+gloc(ialph(i+1,1),icg)*dalpha(j,1,i+1) &
3381 +gloc(ialph(i+1,1)+nside,icg)*domega(j,1,i+1)
3386 ! Setting dE/ddnres-2
3389 gcart(j,nres-2)=gcart(j,nres-2)+gloc(nres-4,icg)* &
3390 dphi(j,3,nres-1)+gloc(nres-3,icg)*dphi(j,2,nres) &
3391 +gloc(2*nres-6,icg)* &
3392 dtheta(j,2,nres-1)+gloc(2*nres-5,icg)*dtheta(j,1,nres)
3393 if((itype(nres-2,1).ne.10).and.(molnum(nres-1).lt.3)) then
3394 gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-2,1),icg)* &
3395 dalpha(j,2,nres-2)+gloc(ialph(nres-2,1)+nside,icg)* &
3398 if((itype(nres-1,1).ne.10).and.(molnum(nres-1).lt.3)) then
3399 gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-1,1),icg)* &
3400 dalpha(j,1,nres-1)+gloc(ialph(nres-1,1)+nside,icg)* &
3405 ! Settind dE/ddnres-1
3409 ! write(iout,*)"in int to carta",nres-1,gcart(j,nres-1),gloc(nres-3,icg),dphi(j,3,nres), &
3410 ! gloc(2*nres-5,icg),dtheta(j,2,nres)
3416 gcart(j,nres-1)=gcart(j,nres-1)+gloc(nres-3,icg)*dphi(j,3,nres)+ &
3417 gloc(2*nres-5,icg)*dtheta(j,2,nres)
3420 ! write(iout,*)"in int to cartb",nres-1,gcart(j,nres-1),gloc(nres-3,icg),dphi(j,3,nres), &
3421 ! gloc(2*nres-5,icg),dtheta(j,2,nres)
3425 if((itype(nres-1,1).ne.10).and.(molnum(nres-1).lt.3)) then
3426 gcart(j,nres-1)=gcart(j,nres-1)+gloc(ialph(nres-1,1),icg)* &
3427 dalpha(j,2,nres-1)+gloc(ialph(nres-1,1)+nside,icg)* &
3431 ! write(iout,*)"in int to cart2",i,gcart(j,nres-1),gloc(ialph(nres-1,1),icg)* &
3432 ! dalpha(j,2,nres-1),gloc(ialph(nres-1,1)+nside,icg), &
3433 ! domega(j,2,nres-1)
3440 ! The side-chain vector derivatives
3442 if(itype(i,1).ne.10 .and. &
3443 itype(i,molnum(i)).ne.ntyp1_molec(molnum(i)).and.&
3444 (molnum(i).lt.3)) then
3446 gxcart(j,i)=gxcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,3,i) &
3447 +gloc(ialph(i,1)+nside,icg)*domega(j,3,i)
3450 ! write(iout,*)"in int to cart",i, gxcart(j,i),gloc(ialph(i,1),icg),dalpha(j,3,i), &
3451 ! gloc(ialph(i,1)+nside,icg),domega(j,3,i)
3457 !----------------------------------------------------------------------
3458 ! INTERTYP=1 SC...Ca...Ca...Ca
3459 ! INTERTYP=2 Ca...Ca...Ca...SC
3460 ! INTERTYP=3 SC...Ca...Ca...SC
3461 ! calculating dE/ddc1
3463 ! write(iout,*) "przed sccor gcart", gcart(1,2)
3467 ! write (iout,*) "poczotkoawy",i,gloc_sc(1,i,icg)
3469 if (nres.lt.2) return
3470 if ((nres.lt.3).and.(itype(1,1).eq.10)) return
3471 if ((itype(1,1).ne.10).and. &
3472 (itype(1,molnum(1)).ne.ntyp1_molec(molnum(1))).and.(molnum(1).lt.3)) then
3474 !c Derviative was calculated for oposite vector of side chain therefore
3475 ! there is "-" sign before gloc_sc
3476 gxcart(j,1)=gxcart(j,1)-gloc_sc(1,0,icg)* &
3478 gcart(j,1)=gcart(j,1)+gloc_sc(1,0,icg)* &
3480 if ((itype(2,1).ne.10).and. &
3481 (itype(2,molnum(2)).ne.ntyp1_molec(molnum(2))).and.(molnum(2).lt.3)) then
3482 gxcart(j,1)= gxcart(j,1) &
3483 -gloc_sc(3,0,icg)*dtauangle(j,3,1,3)
3484 gcart(j,1)=gcart(j,1)+gloc_sc(3,0,icg)* &
3489 if ((nres.ge.3).and.(itype(3,molnum(3)).ne.10).and.&
3490 (itype(3,molnum(3)).ne.ntyp1_molec(molnum(3)))) &
3493 gcart(j,1)=gcart(j,1)+gloc_sc(2,1,icg)*dtauangle(j,2,1,4)
3496 ! As potetnial DO NOT depend on omicron anlge their derivative is
3498 ! & +gloc_sc(intertyp,nres-2,icg)*dtheta(j,1,3)
3500 ! write(iout,*) "przed dE/ddc2 gcart", gcart(1,2)
3502 ! Calculating the remainder of dE/ddc2
3504 if((itype(2,1).ne.10).and. &
3505 (itype(2,molnum(2)).ne.ntyp1_molec(molnum(2)).and.(molnum(2).lt.3))) then
3506 if ((itype(1,1).ne.10).and.&
3507 ((itype(1,molnum(1)).ne.ntyp1_molec(molnum(1)))).and.(molnum(1).lt.3))&
3508 gxcart(j,2)=gxcart(j,2)+ &
3509 gloc_sc(3,0,icg)*dtauangle(j,3,3,3)
3510 if ((itype(3,1).ne.10).and.(nres.ge.3).and.(itype(3,molnum(3)).ne.ntyp1_molec(3)).and.molnum(3).lt.3) &
3512 gxcart(j,2)=gxcart(j,2)-gloc_sc(3,1,icg)*dtauangle(j,3,1,4)
3513 !c the - above is due to different vector direction
3514 gcart(j,2)=gcart(j,2)+gloc_sc(3,1,icg)*dtauangle(j,3,2,4)
3517 ! if ((itype(1,1).ne.10).and.&
3518 ! ((itype(1,molnum(1)).ne.ntyp1_molec(molnum(1))))) &
3519 gxcart(j,2)=gxcart(j,2)-gloc_sc(1,1,icg)*dtauangle(j,1,1,4)
3520 !c the - above is due to different vector direction
3521 gcart(j,2)=gcart(j,2)+gloc_sc(1,1,icg)*dtauangle(j,1,2,4)
3522 ! write(iout,*) gloc_sc(1,1,icg),dtauangle(j,1,2,4),"gcart",gcart(j,2)
3523 ! write(iout,*) gloc_sc(1,1,icg),dtauangle(j,1,1,4),"gx"
3526 if ((itype(1,1).ne.10).and.&
3527 (itype(1,molnum(1)).ne.ntyp1_molec(molnum(1))).and.(molnum(1).lt.3)) then
3528 gcart(j,2)=gcart(j,2)+gloc_sc(1,0,icg)*dtauangle(j,1,3,3)
3529 ! write(iout,*) gloc_sc(1,0,icg),dtauangle(j,1,3,3)
3531 if ((itype(3,1).ne.10).and.(nres.ge.3).and.(molnum(3).lt.3)) then
3532 gcart(j,2)=gcart(j,2)+gloc_sc(2,1,icg)*dtauangle(j,2,2,4)
3533 ! write(iout,*) gloc_sc(2,1,icg),dtauangle(j,2,2,4)
3535 if ((itype(4,1).ne.10).and.(nres.ge.4).and.(molnum(4).lt.3)) then
3536 gcart(j,2)=gcart(j,2)+gloc_sc(2,2,icg)*dtauangle(j,2,1,5)
3537 ! write(iout,*) gloc_sc(2,2,icg),dtauangle(j,2,1,5)
3540 ! write(iout,*) gcart(j,2),itype(2,1),itype(1,1),itype(3,1), "gcart2"
3542 ! write(iout,*) "po dE/ddc2 gcart", gcart(1,2)
3544 ! If there are more than five residues
3548 ! write(iout,*) "before", gcart(j,i)
3549 if ((itype(i,1).ne.10).and.&
3550 (itype(i,molnum(i)).ne.ntyp1_molec(molnum(i))).and.(molnum(i).lt.3)) then
3551 gxcart(j,i)=gxcart(j,i)+gloc_sc(2,i-2,icg) &
3552 *dtauangle(j,2,3,i+1) &
3553 -gloc_sc(1,i-1,icg)*dtauangle(j,1,1,i+2)
3554 gcart(j,i)=gcart(j,i)+gloc_sc(1,i-1,icg) &
3555 *dtauangle(j,1,2,i+2)
3556 ! write(iout,*) "new",j,i,
3557 ! & gcart(j,i),gloc_sc(1,i-1,icg),dtauangle(j,1,2,i+2)
3558 ! if (itype(i-1,1).ne.10) then
3559 if ((itype(i-1,1).ne.10).and.&
3560 (itype(i-1,molnum(i-1)).ne.ntyp1_molec(molnum(i-1))).and.(molnum(i-1).eq.5)) then
3562 gxcart(j,i)=gxcart(j,i)+gloc_sc(3,i-2,icg) &
3563 *dtauangle(j,3,3,i+1)
3565 ! if (itype(i+1,1).ne.10) then
3566 if ((itype(i+1,1).ne.10).and.&
3567 (itype(i+1,molnum(i+1)).ne.ntyp1_molec(molnum(i+1))).and.&
3568 (molnum(i+1).lt.3)) then
3569 gxcart(j,i)=gxcart(j,i)-gloc_sc(3,i-1,icg) &
3570 *dtauangle(j,3,1,i+2)
3571 gcart(j,i)=gcart(j,i)+gloc_sc(3,i-1,icg) &
3572 *dtauangle(j,3,2,i+2)
3575 ! if (itype(i-1,1).ne.10) then
3576 if ((itype(i-1,1).ne.10).and.&
3577 (itype(i-1,molnum(i-1)).ne.ntyp1_molec(molnum(i-1))).and.&
3578 (molnum(i-1).lt.3)) then
3579 gcart(j,i)=gcart(j,i)+gloc_sc(1,i-2,icg)* &
3580 dtauangle(j,1,3,i+1)
3582 ! if (itype(i+1,1).ne.10) then
3583 if ((itype(i+1,1).ne.10).and.&
3584 (itype(i+1,molnum(i+1)).ne.ntyp1_molec(molnum(i+1)))&
3585 .and. (molnum(i+1).lt.3)) then
3586 gcart(j,i)=gcart(j,i)+gloc_sc(2,i-1,icg)* &
3587 dtauangle(j,2,2,i+2)
3588 ! write(iout,*) "numer",i,gloc_sc(2,i-1,icg),
3589 ! & dtauangle(j,2,2,i+2)
3591 ! if (itype(i+2,1).ne.10) then
3592 if ((itype(i+2,1).ne.10).and.&
3593 (itype(i+2,molnum(i+2)).ne.ntyp1_molec(molnum(i+2))).and.(molnum(i+2).lt.3)) then
3594 gcart(j,i)=gcart(j,i)+gloc_sc(2,i,icg)* &
3595 dtauangle(j,2,1,i+3)
3600 ! Setting dE/ddnres-1
3603 if ((itype(nres-1,1).ne.10).and.&
3604 (itype(nres-1,molnum(nres-1)).ne.ntyp1_molec(molnum(nres-1))).and.(molnum(nres-1).lt.3)) then
3605 gxcart(j,nres-1)=gxcart(j,nres-1)+gloc_sc(2,nres-3,icg) &
3606 *dtauangle(j,2,3,nres)
3607 ! write (iout,*) "gxcart(nres-1)", gloc_sc(2,nres-3,icg),
3608 ! & dtauangle(j,2,3,nres), gxcart(j,nres-1)
3609 ! if (itype(nres-2,1).ne.10) then
3610 if ((itype(nres-2,1).ne.10).and.&
3611 (itype(nres-2,molnum(nres-2)).ne.ntyp1_molec(molnum(nres-2))).and.(molnum(nres-2).lt.3)) then
3612 gxcart(j,nres-1)=gxcart(j,nres-1)+gloc_sc(3,nres-3,icg) &
3613 *dtauangle(j,3,3,nres)
3615 if ((itype(nres,1).ne.10).and.&
3616 (itype(nres,molnum(nres)).ne.ntyp1_molec(molnum(nres))).and.(molnum(nres).lt.3)) then
3617 gxcart(j,nres-1)=gxcart(j,nres-1)-gloc_sc(3,nres-2,icg) &
3618 *dtauangle(j,3,1,nres+1)
3619 gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(3,nres-2,icg) &
3620 *dtauangle(j,3,2,nres+1)
3623 if ((itype(nres-2,1).ne.10).and.&
3624 (itype(nres-2,molnum(nres-2)).ne.ntyp1_molec(molnum(nres-2))).and.(molnum(nres-2).lt.3)) then
3625 gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(1,nres-3,icg)* &
3626 dtauangle(j,1,3,nres)
3628 if ((itype(nres,1).ne.10).and.(itype(nres,molnum(nres)).ne.ntyp1_molec(molnum(nres))).and.(molnum(nres).lt.3)) then
3629 gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(2,nres-2,icg)* &
3630 dtauangle(j,2,2,nres+1)
3631 ! write (iout,*) "gcart(nres-1)", gloc_sc(2,nres-2,icg),
3632 ! & dtauangle(j,2,2,nres+1), itype(nres-1,1),itype(nres,1)
3637 if ((nres.ge.3).and.(itype(nres,1).ne.10).and. &
3638 (itype(nres,molnum(nres)).ne.ntyp1_molec(molnum(nres))).and.(molnum(nres).lt.3))then
3640 gxcart(j,nres)=gxcart(j,nres)+gloc_sc(3,nres-2,icg) &
3641 *dtauangle(j,3,3,nres+1)+gloc_sc(2,nres-2,icg) &
3642 *dtauangle(j,2,3,nres+1)
3645 ! write(iout,*) "final gcart",gcart(1,2)
3646 ! The side-chain vector derivatives
3647 ! print *,"gcart",gcart(:,:)
3649 end subroutine int_to_cart
3650 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
3651 !-----------------------------------------------------------------------------
3653 !-----------------------------------------------------------------------------
3654 subroutine gen_dist_constr
3655 ! Generate CA distance constraints.
3656 ! implicit real*8 (a-h,o-z)
3657 ! include 'DIMENSIONS'
3658 ! include 'COMMON.IOUNITS'
3659 ! include 'COMMON.GEO'
3660 ! include 'COMMON.VAR'
3661 ! include 'COMMON.INTERACT'
3662 ! include 'COMMON.LOCAL'
3663 ! include 'COMMON.NAMES'
3664 ! include 'COMMON.CHAIN'
3665 ! include 'COMMON.FFIELD'
3666 ! include 'COMMON.SBRIDGE'
3667 ! include 'COMMON.HEADER'
3668 ! include 'COMMON.CONTROL'
3669 ! include 'COMMON.DBASE'
3670 ! include 'COMMON.THREAD'
3671 ! include 'COMMON.TIME1'
3672 ! integer :: itype_pdb !(maxres)
3673 ! common /pizda/ itype_pdb(nres)
3674 character(len=2) :: iden
3677 !d print *,'gen_dist_constr: nnt=',nnt,' nct=',nct
3678 !d write (2,*) 'gen_dist_constr: nnt=',nnt,' nct=',nct,
3679 !d & ' nstart_sup',nstart_sup,' nstart_seq',nstart_seq,
3681 do i=nstart_sup,nstart_sup+nsup-1
3682 !d write (2,*) 'i',i,' seq ',restyp(itype(i+nstart_seq-nstart_sup)),
3683 !d & ' seq_pdb', restyp(itype_pdb(i))
3684 do j=i+2,nstart_sup+nsup-1
3686 ihpb(nhpb)=i+nstart_seq-nstart_sup
3687 jhpb(nhpb)=j+nstart_seq-nstart_sup
3689 dhpb(nhpb)=dist(i,j)
3692 !d write (iout,'(a)') 'Distance constraints:'
3697 !d if (ii.gt.nres) then
3702 !d write (iout,'(a,1x,a,i4,3x,a,1x,a,i4,2f10.3)')
3703 !d & restyp(itype(ii)),iden,ii,restyp(itype(jj)),iden,jj,
3704 !d & dhpb(i),forcon(i)
3706 ! deallocate(itype_pdb)
3709 end subroutine gen_dist_constr
3711 !-----------------------------------------------------------------------------
3713 !-----------------------------------------------------------------------------
3714 subroutine cartprint
3716 use geometry_data, only: c
3717 use energy_data, only: itype
3718 ! implicit real*8 (a-h,o-z)
3719 ! include 'DIMENSIONS'
3720 ! include 'COMMON.CHAIN'
3721 ! include 'COMMON.INTERACT'
3722 ! include 'COMMON.NAMES'
3723 ! include 'COMMON.IOUNITS'
3728 write (iout,110) restyp(itype(i,1),1),i,c(1,i),c(2,i),&
3729 c(3,i),c(1,nres+i),c(2,nres+i),c(3,nres+i)
3731 100 format (//' alpha-carbon coordinates ',&
3732 ' centroid coordinates'/ &
3733 ' ', 6X,'X',11X,'Y',11X,'Z',&
3734 10X,'X',11X,'Y',11X,'Z')
3735 110 format (a,'(',i3,')',6f12.5)
3737 end subroutine cartprint
3738 !-----------------------------------------------------------------------------
3739 !-----------------------------------------------------------------------------
3740 subroutine alloc_geo_arrays
3741 !EL Allocation of tables used by module energy
3743 integer :: i,j,nres2
3747 allocate(phibound(2,nres+2)) !(2,maxres)
3748 !----------------------
3750 ! common /chain/ in molread
3751 ! real(kind=8),dimension(:,:),allocatable :: c !(3,maxres2+2)
3752 ! real(kind=8),dimension(:,:),allocatable :: dc
3753 allocate(dc_old(3,0:nres2))
3754 ! if(.not.allocated(dc_norm2)) allocate(dc_norm2(3,0:nres2+2)) !(3,0:maxres2)
3755 if(.not.allocated(dc_norm2)) then
3756 allocate(dc_norm2(3,0:nres2+2)) !(3,0:maxres2)
3760 !el if(.not.allocated(dc_norm))
3761 !elwrite(iout,*) "jestem w alloc geo 1"
3762 if(.not.allocated(dc_norm)) then
3763 allocate(dc_norm(3,0:nres2+2)) !(3,0:maxres2)
3766 !elwrite(iout,*) "jestem w alloc geo 1"
3767 allocate(xloc(3,nres),xrot(3,nres))
3768 !elwrite(iout,*) "jestem w alloc geo 1"
3770 !elwrite(iout,*) "jestem w alloc geo 1"
3771 allocate(dc_work(6*nres)) !(MAXRES6) maxres6=6*maxres
3773 allocate(t(3,3,nres),r(3,3,nres))
3774 allocate(prod(3,3,nres),rt(3,3,nres)) !(3,3,maxres)
3775 ! common /refstruct/
3776 if(.not.allocated(cref)) allocate(cref(3,nres2+2,maxperm)) !(3,maxres2+2,maxperm)
3777 !elwrite(iout,*) "jestem w alloc geo 2"
3778 ! allocate(crefjlee(3,nres2+2)) !(3,maxres2+2)
3779 if (.not.allocated(crefjlee)) allocate (crefjlee(3,nres2+2))
3780 if(.not.allocated(chain_rep)) allocate(chain_rep(3,nres2+2,maxsym)) !(3,maxres2+2,maxsym)
3781 if(.not.allocated(tabperm)) allocate(tabperm(maxperm,maxsym)) !(maxperm,maxsym)
3782 ! common /from_zscore/ in module.compare
3783 !----------------------
3785 ! Inverses of the actual virtual bond lengths
3786 ! common /invlen/ in io_conf: molread or readpdb
3787 ! real(kind=8),dimension(:),allocatable :: vbld_inv !(maxres2)
3788 !----------------------
3790 ! Store the geometric variables in the following COMMON block.
3791 ! common /var/ in readpdb or ...
3792 if(.not.allocated(theta)) allocate(theta(nres+2))
3793 if(.not.allocated(phi)) allocate(phi(nres+2))
3794 if(.not.allocated(alph)) allocate(alph(nres+2))
3795 if(.not.allocated(omeg)) allocate(omeg(nres+2))
3796 if(.not.allocated(thetaref)) allocate(thetaref(nres+2))
3797 if(.not.allocated(phiref)) allocate(phiref(nres+2))
3798 if(.not.allocated(costtab)) allocate(costtab(nres))
3799 if(.not.allocated(sinttab)) allocate(sinttab(nres))
3800 if(.not.allocated(cost2tab)) allocate(cost2tab(nres))
3801 if(.not.allocated(sint2tab)) allocate(sint2tab(nres))
3802 ! real(kind=8),dimension(:),allocatable :: vbld !(2*maxres) in io_conf: molread or readpdb
3803 allocate(omicron(2,nres+2)) !(2,maxres)
3804 allocate(tauangle(3,nres+2)) !(3,maxres)
3805 !elwrite(iout,*) "jestem w alloc geo 3"
3806 if(.not.allocated(xxtab)) allocate(xxtab(nres))
3807 if(.not.allocated(yytab)) allocate(yytab(nres))
3808 if(.not.allocated(zztab)) allocate(zztab(nres)) !(maxres)
3809 if(.not.allocated(xxref)) allocate(xxref(nres))
3810 if(.not.allocated(yyref)) allocate(yyref(nres))
3811 if(.not.allocated(zzref)) allocate(zzref(nres)) !(maxres)
3812 allocate(ialph(nres,2)) !(maxres,2)
3815 allocate(ivar(4*nres2)) !(4*maxres2)
3817 #if defined(WHAM_RUN) || defined(CLUSTER)
3818 allocate(vbld(2*nres))
3820 allocate(vbld_inv(2*nres))
3825 end subroutine alloc_geo_arrays
3826 !-----------------------------------------------------------------------------
3827 !-----------------------------------------------------------------------------
3828 subroutine returnbox
3829 integer :: allareout,i,j,k,nojumpval,chain_beg,mnum
3830 integer :: chain_end,ireturnval,idum,mnumi1
3831 real*8 :: difference,xi,boxsize,x,xtemp,box2shift
3832 real(kind=8),dimension(3) :: boxx
3833 real(kind=8),dimension(3,10000) :: xorg
3834 integer,dimension(10000) :: posdummy
3836 !C change suggested by Ana - end
3843 ! if(me.eq.king.or..not.out1file) then
3845 ! write(iout,'(a6,2i3,6f9.3)') 'initial', i,j,(c(j,i),j=1,3),(c(j,i+nres),j=1,3)
3848 !C change suggested by Ana - begin
3851 !C change suggested by Ana -end
3854 if (itype(i,mnum).eq.ntyp1_molec(mnum)) then
3859 if ((itype(i+1,mnum).eq.ntyp1_molec(mnum)).or.(mnum.ne.mnumi1)) then
3861 xorg(j,idum)=c(j,i)-c(j,i-1)
3865 xorg(j,idum)=c(j,i)-c(j,i+1)
3870 xorg(j,idum)=c(j,i)-c(j,i-1)
3878 if (molnum(i).ge.1) then
3882 if (itype(i,mnum).ne.ntyp1_molec(mnum)) then
3887 if (itype(k,mnum).eq.ntyp1_molec(mnum)) k=k+1
3888 if (itype(k,mnum).eq.ntyp1_molec(mnum)) k=k+1
3892 c(j,i)=dmod(c(j,i),boxx(j))
3893 ! if (c(1,i).lt.0) c(1,i)=c(1,i)+boxxsize
3895 ! print *,"return box,before wrap",c(1,i)
3897 xtemp=dmod(x,boxsize)
3898 if (dabs(xtemp-boxsize).lt.dabs(xtemp)) then
3899 box2shift=xtemp-boxsize
3900 else if (dabs(xtemp+boxsize).lt.dabs(xtemp)) then
3901 box2shift=xtemp+boxsize
3906 ! print *,c(1,2),xi,xtemp,box2shift
3910 c(j,i+nres)=dmod(c(j,i+nres),boxx(j))
3911 ! if (c(1,i).lt.0) c(1,i)=c(1,i)+boxxsize
3912 x=c(j,i+nres)-c(j,i)
3913 ! print *,"return box,before wrap",c(1,i)
3915 xtemp=dmod(x,boxsize)
3916 if (dabs(xtemp-boxsize).lt.dabs(xtemp)) then
3917 box2shift=xtemp-boxsize
3918 else if (dabs(xtemp+boxsize).lt.dabs(xtemp)) then
3919 box2shift=xtemp+boxsize
3924 ! print *,c(1,2),xi,xtemp,box2shift
3925 c(j,i+nres)=c(j,i)+xi
3932 if(me.eq.king.or..not.out1file) then
3933 write(iout,*),"posdummy",i,k,(xorg(j,i),j=1,3)
3936 ! if (dabs(xorg(j,i)).gt.boxx(j))then
3939 ! xtemp=dmod(x,boxsize)
3940 ! if (dabs(-boxsize).lt.dabs(xtemp)) then
3941 ! box2shift=xtemp-boxsize
3942 ! else if (dabs(xtemp+boxsize).lt.dabs(xtemp)) then
3943 ! box2shift=xtemp+boxsize
3947 ! xorg(j,i)=box2shift
3952 c(j,k)=c(j,k-1)+xorg(j,i)
3956 if ((itype(k+1,mnum).eq.ntyp1_molec(mnum)).or.(mnum.ne.mnumi1)) then
3958 c(j,k)=c(j,k-1)+xorg(j,i)
3962 c(j,k)=c(j,k+1)+xorg(j,i)
3967 ! if(me.eq.king.or..not.out1file) then
3969 ! write(iout,'(a6,2i3,6f9.3)') 'final', i,j,(c(j,i),j=1,3),(c(j,i+nres),j=1,3)
3973 end subroutine returnbox
3974 !-------------------------------------------------------------------------------------------------------