2 !-----------------------------------------------------------------------------
15 !-----------------------------------------------------------------------------
17 ! common /mdgrad/ in module.energy
18 ! common /back_constr/ in module.energy
19 ! common /qmeas/ in module.energy
23 real(kind=8),dimension(:),allocatable :: d_t_work,&
24 d_t_work_new,d_af_work,d_as_work,kinetic_force !(MAXRES6)
25 real(kind=8),dimension(:,:),allocatable :: d_t_new,&
26 d_a_old,d_a_short!,d_a !(3,0:MAXRES2)
27 ! real(kind=8),dimension(:),allocatable :: d_a_work !(6*MAXRES)
28 ! real(kind=8),dimension(:,:),allocatable :: Gmat,Ginv,A,&
29 ! Gsqrp,Gsqrm,Gvec !(maxres2,maxres2)
30 ! real(kind=8),dimension(:),allocatable :: Geigen !(maxres2)
31 ! integer :: dimen,dimen1,dimen3
32 ! integer :: lang,count_reset_moment,count_reset_vel
33 ! logical :: reset_moment,reset_vel,rattle,RESPA
36 ! real(kind=8) :: rwat,etawat,stdfp,cPoise
37 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
38 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
39 real(kind=8),dimension(:),allocatable :: stdforcp,stdforcsc !(MAXRES)
40 !-----------------------------------------------------------------------------
44 ! ###################################################
45 ! ## COPYRIGHT (C) 1992 by Jay William Ponder ##
46 ! ## All Rights Reserved ##
47 ! ###################################################
49 ! #############################################################
51 ! ## sizes.i -- parameter values to set array dimensions ##
53 ! #############################################################
56 ! "sizes.i" sets values for critical array dimensions used
57 ! throughout the software; these parameters will fix the size
58 ! of the largest systems that can be handled; values too large
59 ! for the computer's memory and/or swap space to accomodate
60 ! will result in poor performance or outright failure
62 ! parameter: maximum allowed number of:
64 ! maxatm atoms in the molecular system
65 ! maxval atoms directly bonded to an atom
66 ! maxgrp ! user-defined groups of atoms
67 ! maxtyp force field atom type definitions
68 ! maxclass force field atom class definitions
69 ! maxkey lines in the keyword file
70 ! maxrot bonds for torsional rotation
71 ! maxvar optimization variables (vector storage)
72 ! maxopt optimization variables (matrix storage)
73 ! maxhess off-diagonal Hessian elements
74 ! maxlight sites for method of lights neighbors
75 ! maxvib vibrational frequencies
76 ! maxgeo distance geometry points
77 ! maxcell unit cells in replicated crystal
78 ! maxring 3-, 4-, or 5-membered rings
79 ! maxfix geometric restraints
80 ! maxbio biopolymer atom definitions
81 ! maxres residues in the macromolecule
82 ! maxamino amino acid residue types
83 ! maxnuc nucleic acid residue types
84 ! maxbnd covalent bonds in molecular system
85 ! maxang bond angles in molecular system
86 ! maxtors torsional angles in molecular system
87 ! maxpi atoms in conjugated pisystem
88 ! maxpib covalent bonds involving pisystem
89 ! maxpit torsional angles involving pisystem
92 !el integer maxatm,maxval,maxgrp
93 !el integer maxtyp,maxclass,maxkey
94 !el integer maxrot,maxopt
95 !el integer maxhess,maxlight,maxvib
96 !el integer maxgeo,maxcell,maxring
97 !el integer maxfix,maxbio
98 !el integer maxamino,maxnuc,maxbnd
99 !el integer maxang,maxtors,maxpi
100 !el integer maxpib,maxpit
101 ! integer :: maxatm !=2*nres !maxres2 maxres2=2*maxres
102 ! integer,parameter :: maxval=8
103 ! integer,parameter :: maxgrp=1000
104 ! integer,parameter :: maxtyp=3000
105 ! integer,parameter :: maxclass=500
106 ! integer,parameter :: maxkey=10000
107 ! integer,parameter :: maxrot=1000
108 ! integer,parameter :: maxopt=1000
109 ! integer,parameter :: maxhess=1000000
110 ! integer :: maxlight !=8*maxatm
111 ! integer,parameter :: maxvib=1000
112 ! integer,parameter :: maxgeo=1000
113 ! integer,parameter :: maxcell=10000
114 ! integer,parameter :: maxring=10000
115 ! integer,parameter :: maxfix=10000
116 ! integer,parameter :: maxbio=10000
117 ! integer,parameter :: maxamino=31
118 ! integer,parameter :: maxnuc=12
119 ! integer :: maxbnd !=2*maxatm
120 ! integer :: maxang !=3*maxatm
121 ! integer :: maxtors !=4*maxatm
122 ! integer,parameter :: maxpi=100
123 ! integer,parameter :: maxpib=2*maxpi
124 ! integer,parameter :: maxpit=4*maxpi
125 !-----------------------------------------------------------------------------
126 ! Maximum number of seed
127 ! integer,parameter :: max_seed=1
128 !-----------------------------------------------------------------------------
129 real(kind=8),dimension(:),allocatable :: stochforcvec !(MAXRES6) maxres6=6*maxres
130 ! common /stochcalc/ stochforcvec
131 !-----------------------------------------------------------------------------
132 ! common /przechowalnia/ subroutines: rattle1,rattle2,rattle_brown
133 real(kind=8),dimension(:,:),allocatable :: GGinv !(2*nres,2*nres) maxres2=2*maxres
134 real(kind=8),dimension(:,:,:),allocatable :: gdc !(3,2*nres,2*nres) maxres2=2*maxres
135 real(kind=8),dimension(:,:),allocatable :: Cmat !(2*nres,2*nres) maxres2=2*maxres
136 !-----------------------------------------------------------------------------
137 ! common /syfek/ subroutines: friction_force,setup_fricmat
138 !el real(kind=8),dimension(:),allocatable :: gamvec !(MAXRES6) or (MAXRES2)
139 !-----------------------------------------------------------------------------
140 ! common /przechowalnia/ subroutines: friction_force,setup_fricmat
141 real(kind=8),dimension(:,:),allocatable :: ginvfric !(2*nres,2*nres) !maxres2=2*maxres
142 !-----------------------------------------------------------------------------
143 ! common /przechowalnia/ subroutine: setup_fricmat
144 real(kind=8),dimension(:,:),allocatable :: fcopy !(2*nres,2*nres)
145 !-----------------------------------------------------------------------------
148 !-----------------------------------------------------------------------------
150 !-----------------------------------------------------------------------------
152 !-----------------------------------------------------------------------------
153 subroutine brown_step(itime)
154 !------------------------------------------------
155 ! Perform a single Euler integration step of Brownian dynamics
156 !------------------------------------------------
157 ! implicit real*8 (a-h,o-z)
159 use control, only: tcpu
162 ! use io_conf, only:cartprint
163 ! include 'DIMENSIONS'
167 ! include 'COMMON.CONTROL'
168 ! include 'COMMON.VAR'
169 ! include 'COMMON.MD'
171 ! include 'COMMON.LANGEVIN'
173 ! include 'COMMON.LANGEVIN.lang0'
175 ! include 'COMMON.CHAIN'
176 ! include 'COMMON.DERIV'
177 ! include 'COMMON.GEO'
178 ! include 'COMMON.LOCAL'
179 ! include 'COMMON.INTERACT'
180 ! include 'COMMON.IOUNITS'
181 ! include 'COMMON.NAMES'
182 ! include 'COMMON.TIME1'
183 real(kind=8),dimension(6*nres) :: zapas !(MAXRES6) maxres6=6*maxres
184 integer :: rstcount !ilen,
186 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
187 real(kind=8),dimension(6*nres,2*nres) :: Bmat,GBmat,Tmat !(MAXRES6,MAXRES2) (maxres2=2*maxres,maxres6=6*maxres)
188 real(kind=8),dimension(2*nres,2*nres) :: Cmat_,Cinv !(maxres2,maxres2) maxres2=2*maxres
189 real(kind=8),dimension(6*nres,6*nres) :: Pmat !(maxres6,maxres6) maxres6=6*maxres
190 ! real(kind=8),dimension(:,:),allocatable :: Bmat,GBmat,Tmat !(MAXRES6,MAXRES2) (maxres2=2*maxres,maxres6=6*maxres)
191 ! real(kind=8),dimension(:,:),allocatable :: Cmat_,Cinv !(maxres2,maxres2) maxres2=2*maxres
192 ! real(kind=8),dimension(:,:),allocatable :: Pmat !(maxres6,maxres6) maxres6=6*maxres
193 real(kind=8),dimension(6*nres) :: Td !(maxres6) maxres6=6*maxres
194 real(kind=8),dimension(2*nres) :: ppvec !(maxres2) maxres2=2*maxres
195 !el common /stochcalc/ stochforcvec
196 !el real(kind=8),dimension(3) :: cm !el
197 !el common /gucio/ cm
199 logical :: lprn = .false.,lprn1 = .false.
200 integer :: maxiter = 5
201 real(kind=8) :: difftol = 1.0d-5
202 real(kind=8) :: xx,diffmax,blen2,diffbond,tt0
203 integer :: i,j,nbond,k,ind,ind1,iter
204 integer :: nres2,nres6
208 ! if (.not.allocated(Bmat)) allocate(Bmat(nres6,nres2))
209 ! if (.not.allocated(GBmat)) allocate (GBmat(nres6,nres2))
210 ! if (.not.allocated(Tmat)) allocate (Tmat(nres6,nres2))
211 ! if (.not.allocated(Cmat_)) allocate(Cmat_(nres2,nres2))
212 ! if (.not.allocated(Cinv)) allocate (Cinv(nres2,nres2))
213 ! if (.not.allocated(Pmat)) allocate(Pmat(6*nres,6*nres))
215 if (.not.allocated(stochforcvec)) allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
219 if (itype(i,1).ne.10) nbond=nbond+1
223 write (iout,*) "Generalized inverse of fricmat"
224 call matout(dimen,dimen,nres6,nres6,fricmat)
236 Bmat(ind+j,ind1)=dC_norm(j,i)
241 if (itype(i,1).ne.10) then
244 Bmat(ind+j,ind1)=dC_norm(j,i+nres)
250 write (iout,*) "Matrix Bmat"
251 call MATOUT(nbond,dimen,nres6,nres6,Bmat)
257 GBmat(i,j)=GBmat(i,j)+fricmat(i,k)*Bmat(k,j)
262 write (iout,*) "Matrix GBmat"
263 call MATOUT(nbond,dimen,nres6,nres2,Gbmat)
269 Cmat_(i,j)=Cmat_(i,j)+Bmat(k,i)*GBmat(k,j)
274 write (iout,*) "Matrix Cmat"
275 call MATOUT(nbond,nbond,nres2,nres2,Cmat_)
277 call matinvert(nbond,nres2,Cmat_,Cinv,osob)
279 write (iout,*) "Matrix Cinv"
280 call MATOUT(nbond,nbond,nres2,nres2,Cinv)
286 Tmat(i,j)=Tmat(i,j)+GBmat(i,k)*Cinv(k,j)
291 write (iout,*) "Matrix Tmat"
292 call MATOUT(nbond,dimen,nres6,nres2,Tmat)
302 Pmat(i,j)=Pmat(i,j)-Tmat(i,k)*Bmat(j,k)
307 write (iout,*) "Matrix Pmat"
308 call MATOUT(dimen,dimen,nres6,nres6,Pmat)
315 Td(i)=Td(i)+vbl*Tmat(i,ind)
318 if (itype(k,1).ne.10) then
320 Td(i)=Td(i)+vbldsc0(1,itype(k,1))*Tmat(i,ind)
325 write (iout,*) "Vector Td"
327 write (iout,'(i5,f10.5)') i,Td(i)
330 call stochastic_force(stochforcvec)
332 write (iout,*) "stochforcvec"
334 write (iout,*) i,stochforcvec(i)
338 zapas(j)=-gcart(j,0)+stochforcvec(j)
340 dC_work(j)=dC_old(j,0)
346 zapas(ind)=-gcart(j,i)+stochforcvec(ind)
347 dC_work(ind)=dC_old(j,i)
351 if (itype(i,1).ne.10) then
354 zapas(ind)=-gxcart(j,i)+stochforcvec(ind)
355 dC_work(ind)=dC_old(j,i+nres)
361 write (iout,*) "Initial d_t_work"
363 write (iout,*) i,d_t_work(i)
370 d_t_work(i)=d_t_work(i)+fricmat(i,j)*zapas(j)
377 zapas(i)=zapas(i)+Pmat(i,j)*(dC_work(j)+d_t_work(j)*d_time)
381 write (iout,*) "Final d_t_work and zapas"
383 write (iout,*) i,d_t_work(i),zapas(i)
397 dc_work(ind+j)=dc(j,i)
403 d_t(j,i+nres)=d_t_work(ind+j)
404 dc(j,i+nres)=zapas(ind+j)
405 dc_work(ind+j)=dc(j,i+nres)
411 write (iout,*) "Before correction for rotational lengthening"
412 write (iout,*) "New coordinates",&
413 " and differences between actual and standard bond lengths"
418 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
422 if (itype(i,1).ne.10) then
424 xx=vbld(i+nres)-vbldsc0(1,itype(i,1))
425 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
426 i,(dC(j,i+nres),j=1,3),xx
430 ! Second correction (rotational lengthening)
436 blen2 = scalar(dc(1,i),dc(1,i))
437 ppvec(ind)=2*vbl**2-blen2
438 diffbond=dabs(vbl-dsqrt(blen2))
439 if (diffbond.gt.diffmax) diffmax=diffbond
440 if (ppvec(ind).gt.0.0d0) then
441 ppvec(ind)=dsqrt(ppvec(ind))
446 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
450 if (itype(i,1).ne.10) then
452 blen2 = scalar(dc(1,i+nres),dc(1,i+nres))
453 ppvec(ind)=2*vbldsc0(1,itype(i,1))**2-blen2
454 diffbond=dabs(vbldsc0(1,itype(i,1))-dsqrt(blen2))
455 if (diffbond.gt.diffmax) diffmax=diffbond
456 if (ppvec(ind).gt.0.0d0) then
457 ppvec(ind)=dsqrt(ppvec(ind))
462 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
466 if (lprn) write (iout,*) "iter",iter," diffmax",diffmax
467 if (diffmax.lt.difftol) goto 10
471 Td(i)=Td(i)+ppvec(j)*Tmat(i,j)
477 zapas(i)=zapas(i)+Pmat(i,j)*dc_work(j)
488 dc_work(ind+j)=zapas(ind+j)
493 if (itype(i,1).ne.10) then
495 dc(j,i+nres)=zapas(ind+j)
496 dc_work(ind+j)=zapas(ind+j)
501 ! Building the chain from the newly calculated coordinates
504 if (large.and. mod(itime,ntwe).eq.0) then
505 write (iout,*) "Cartesian and internal coordinates: step 1"
508 write (iout,'(a)') "Potential forces"
510 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(-gcart(j,i),j=1,3),&
513 write (iout,'(a)') "Stochastic forces"
515 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(stochforc(j,i),j=1,3),&
516 (stochforc(j,i+nres),j=1,3)
518 write (iout,'(a)') "Velocities"
520 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
521 (d_t(j,i+nres),j=1,3)
526 write (iout,*) "After correction for rotational lengthening"
527 write (iout,*) "New coordinates",&
528 " and differences between actual and standard bond lengths"
533 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
537 if (itype(i,1).ne.10) then
539 xx=vbld(i+nres)-vbldsc0(1,itype(i,1))
540 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
541 i,(dC(j,i+nres),j=1,3),xx
546 ! write (iout,*) "Too many attempts at correcting the bonds"
554 ! Calculate energy and forces
556 call etotal(potEcomp)
557 potE=potEcomp(0)-potEcomp(20)
561 ! Calculate the kinetic and total energy and the kinetic temperature
564 t_enegrad=t_enegrad+MPI_Wtime()-tt0
566 t_enegrad=t_enegrad+tcpu()-tt0
569 kinetic_T=2.0d0/(dimen*Rb)*EK
571 end subroutine brown_step
572 !-----------------------------------------------------------------------------
574 !-----------------------------------------------------------------------------
575 subroutine gauss(RO,AP,MT,M,N,*)
577 ! CALCULATES (RO**(-1))*AP BY GAUSS ELIMINATION
578 ! RO IS A SQUARE MATRIX
579 ! THE CALCULATED PRODUCT IS STORED IN AP
580 ! ABNORMAL EXIT IF RO IS SINGULAR
582 integer :: MT, M, N, M1,I,J,IM,&
584 real(kind=8) :: RO(MT,M),AP(MT,N),X,RM,PR,Y
590 if(dabs(X).le.1.0D-13) return 1
602 if(DABS(RO(J,I)).LE.RM) goto 2
616 if(dabs(X).le.1.0E-13) return 1
625 8 AP(J,K)=AP(J,K)-Y*AP(I,K)
627 9 RO(J,K)=RO(J,K)-Y*RO(I,K)
631 if(dabs(X).le.1.0E-13) return 1
641 15 X=X-AP(K,J)*RO(MI,K)
646 !-----------------------------------------------------------------------------
648 !-----------------------------------------------------------------------------
649 subroutine kinetic(KE_total)
650 !----------------------------------------------------------------
651 ! This subroutine calculates the total kinetic energy of the chain
652 !-----------------------------------------------------------------
654 ! implicit real*8 (a-h,o-z)
655 ! include 'DIMENSIONS'
656 ! include 'COMMON.VAR'
657 ! include 'COMMON.CHAIN'
658 ! include 'COMMON.DERIV'
659 ! include 'COMMON.GEO'
660 ! include 'COMMON.LOCAL'
661 ! include 'COMMON.INTERACT'
662 ! include 'COMMON.MD'
663 ! include 'COMMON.IOUNITS'
664 real(kind=8) :: KE_total,mscab
666 integer :: i,j,k,iti,mnum
667 real(kind=8) :: KEt_p,KEt_sc,KEr_p,KEr_sc,incr(3),&
670 write (iout,*) "Velocities, kietic"
672 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
673 (d_t(j,i+nres),j=1,3)
678 ! write (iout,*) "ISC",(isc(itype(i,1)),i=1,nres)
679 ! The translational part for peptide virtual bonds
685 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
686 ! write (iout,*) "Kinetic trp:",i,(incr(j),j=1,3)
688 v(j)=incr(j)+0.5d0*d_t(j,i)
690 vtot(i)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
691 KEt_p=KEt_p+mp(mnum)*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))
693 incr(j)=incr(j)+d_t(j,i)
696 ! write(iout,*) 'KEt_p', KEt_p
697 ! The translational part for the side chain virtual bond
698 ! Only now we can initialize incr with zeros. It must be equal
699 ! to the velocities of the first Calpha.
705 iti=iabs(itype(i,mnum))
711 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
712 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
713 .or.(mnum.eq.5)) then
719 v(j)=incr(j)+d_t(j,nres+i)
722 ! write (iout,*) "Kinetic trsc:",i,(incr(j),j=1,3)
723 ! write (iout,*) "i",i," msc",msc(iti)," v",(v(j),j=1,3)
724 KEt_sc=KEt_sc+mscab*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))
725 vtot(i+nres)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
727 incr(j)=incr(j)+d_t(j,i)
731 ! write(iout,*) 'KEt_sc', KEt_sc
732 ! The part due to stretching and rotation of the peptide groups
736 ! write (iout,*) "i",i
737 ! write (iout,*) "i",i," mag1",mag1," mag2",mag2
741 ! write (iout,*) "Kinetic rotp:",i,(incr(j),j=1,3)
742 KEr_p=KEr_p+Ip(mnum)*(incr(1)*incr(1)+incr(2)*incr(2) &
746 ! write(iout,*) 'KEr_p', KEr_p
747 ! The rotational part of the side chain virtual bond
751 iti=iabs(itype(i,mnum))
752 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
753 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
754 .and.(mnum.ne.5)) then
756 incr(j)=d_t(j,nres+i)
758 ! write (iout,*) "Kinetic rotsc:",i,(incr(j),j=1,3)
759 KEr_sc=KEr_sc+Isc(iti,mnum)*(incr(1)*incr(1)+incr(2)*incr(2)+ &
763 ! The total kinetic energy
765 ! write(iout,*) 'KEr_sc', KEr_sc
766 KE_total=0.5d0*(KEt_p+KEt_sc+0.25d0*KEr_p+KEr_sc)
767 ! write (iout,*) "KE_total",KE_total
769 end subroutine kinetic
770 !-----------------------------------------------------------------------------
772 !-----------------------------------------------------------------------------
774 !------------------------------------------------
775 ! The driver for molecular dynamics subroutines
776 !------------------------------------------------
779 use control, only:tcpu,ovrtim
780 ! use io_comm, only:ilen
782 use compare, only:secondary2,hairpin
783 use io, only:cartout,statout
784 ! implicit real*8 (a-h,o-z)
785 ! include 'DIMENSIONS'
788 integer :: IERROR,ERRCODE
790 ! include 'COMMON.SETUP'
791 ! include 'COMMON.CONTROL'
792 ! include 'COMMON.VAR'
793 ! include 'COMMON.MD'
795 ! include 'COMMON.LANGEVIN'
797 ! include 'COMMON.LANGEVIN.lang0'
799 ! include 'COMMON.CHAIN'
800 ! include 'COMMON.DERIV'
801 ! include 'COMMON.GEO'
802 ! include 'COMMON.LOCAL'
803 ! include 'COMMON.INTERACT'
804 ! include 'COMMON.IOUNITS'
805 ! include 'COMMON.NAMES'
806 ! include 'COMMON.TIME1'
807 ! include 'COMMON.HAIRPIN'
808 real(kind=8),dimension(3) :: L,vcm
810 real(kind=8),dimension(6*nres) :: v_work,v_transf !(maxres6) maxres6=6*maxres
812 integer :: rstcount !ilen,
814 character(len=50) :: tytul
815 !el common /gucio/ cm
816 integer :: itime,i,j,nharp
817 integer,dimension(4,nres/3) :: iharp !(4,nres/3)(4,maxres/3)
819 real(kind=8) :: tt0,scalfac
825 print *,"MY tmpdir",tmpdir,ilen(tmpdir)
826 if (ilen(tmpdir).gt.0) &
827 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_" &
828 //liczba(:ilen(liczba))//'.rst')
830 if (ilen(tmpdir).gt.0) &
831 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_"//'.rst')
838 write (iout,'(20(1h=),a20,20(1h=))') "MD calculation started"
844 print *,"just befor setup matix",nres
845 ! Determine the inverse of the inertia matrix.
846 call setup_MD_matrices
848 print *,"AFTER SETUP MATRICES"
850 print *,"AFTER INIT MD"
853 t_MDsetup = MPI_Wtime()-tt0
855 t_MDsetup = tcpu()-tt0
858 ! Entering the MD loop
864 if (lang.eq.2 .or. lang.eq.3) then
868 call sd_verlet_p_setup
870 call sd_verlet_ciccotti_setup
874 pfric0_mat(i,j,0)=pfric_mat(i,j)
875 afric0_mat(i,j,0)=afric_mat(i,j)
876 vfric0_mat(i,j,0)=vfric_mat(i,j)
877 prand0_mat(i,j,0)=prand_mat(i,j)
878 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
879 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
884 flag_stoch(i)=.false.
888 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
890 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
894 else if (lang.eq.1 .or. lang.eq.4) then
895 print *,"before setup_fricmat"
897 print *,"after setup_fricmat"
900 t_langsetup=MPI_Wtime()-tt0
903 t_langsetup=tcpu()-tt0
906 do itime=1,n_timestep
908 if (large.and. mod(itime,ntwe).eq.0) &
909 write (iout,*) "itime",itime
911 if (lang.gt.0 .and. surfarea .and. &
912 mod(itime,reset_fricmat).eq.0) then
913 if (lang.eq.2 .or. lang.eq.3) then
917 call sd_verlet_p_setup
919 call sd_verlet_ciccotti_setup
923 pfric0_mat(i,j,0)=pfric_mat(i,j)
924 afric0_mat(i,j,0)=afric_mat(i,j)
925 vfric0_mat(i,j,0)=vfric_mat(i,j)
926 prand0_mat(i,j,0)=prand_mat(i,j)
927 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
928 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
933 flag_stoch(i)=.false.
936 else if (lang.eq.1 .or. lang.eq.4) then
939 write (iout,'(a,i10)') &
940 "Friction matrix reset based on surface area, itime",itime
942 if (reset_vel .and. tbf .and. lang.eq.0 &
943 .and. mod(itime,count_reset_vel).eq.0) then
945 write(iout,'(a,f20.2)') &
946 "Velocities reset to random values, time",totT
949 d_t_old(j,i)=d_t(j,i)
953 if (reset_moment .and. mod(itime,count_reset_moment).eq.0) then
957 d_t(j,0)=d_t(j,0)-vcm(j)
960 kinetic_T=2.0d0/(dimen3*Rb)*EK
961 scalfac=dsqrt(T_bath/kinetic_T)
962 write(iout,'(a,f20.2)') "Momenta zeroed out, time",totT
965 d_t_old(j,i)=scalfac*d_t(j,i)
971 ! Time-reversible RESPA algorithm
972 ! (Tuckerman et al., J. Chem. Phys., 97, 1990, 1992)
973 call RESPA_step(itime)
975 ! Variable time step algorithm.
976 call velverlet_step(itime)
980 call brown_step(itime)
982 print *,"Brown dynamics not here!"
984 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
990 if (mod(itime,ntwe).eq.0) then
1002 v_work(ind)=d_t(j,i)
1007 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1.and.mnum.ne.5) then
1010 v_work(ind)=d_t(j,i+nres)
1015 write (66,'(80f10.5)') &
1016 ((d_t(j,i),j=1,3),i=0,nres-1),((d_t(j,i+nres),j=1,3),i=1,nres)
1020 v_transf(i)=v_transf(i)+gvec(j,i)*v_work(j)
1022 v_transf(i)= v_transf(i)*dsqrt(geigen(i))
1024 write (67,'(80f10.5)') (v_transf(i),i=1,ind)
1027 if (mod(itime,ntwx).eq.0) then
1029 write (tytul,'("time",f8.2)') totT
1031 call hairpin(.true.,nharp,iharp)
1032 call secondary2(.true.)
1033 call pdbout(potE,tytul,ipdb)
1038 if (rstcount.eq.1000.or.itime.eq.n_timestep) then
1039 open(irest2,file=rest2name,status='unknown')
1040 write(irest2,*) totT,EK,potE,totE,t_bath
1042 ! AL 4/17/17: Now writing d_t(0,:) too
1044 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
1046 ! AL 4/17/17: Now writing d_c(0,:) too
1048 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
1056 t_MD=MPI_Wtime()-tt0
1060 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))') &
1062 'MD calculations setup:',t_MDsetup,&
1063 'Energy & gradient evaluation:',t_enegrad,&
1064 'Stochastic MD setup:',t_langsetup,&
1065 'Stochastic MD step setup:',t_sdsetup,&
1067 write (iout,'(/28(1h=),a25,27(1h=))') &
1068 ' End of MD calculation '
1070 write (iout,*) "time for etotal",t_etotal," elong",t_elong,&
1072 write (iout,*) "time_fric",time_fric," time_stoch",time_stoch,&
1073 " time_fricmatmult",time_fricmatmult," time_fsample ",&
1078 !-----------------------------------------------------------------------------
1079 subroutine velverlet_step(itime)
1080 !-------------------------------------------------------------------------------
1081 ! Perform a single velocity Verlet step; the time step can be rescaled if
1082 ! increments in accelerations exceed the threshold
1083 !-------------------------------------------------------------------------------
1084 ! implicit real*8 (a-h,o-z)
1085 ! include 'DIMENSIONS'
1087 use control, only:tcpu
1091 integer :: ierror,ierrcode
1092 real(kind=8) :: errcode
1094 ! include 'COMMON.SETUP'
1095 ! include 'COMMON.VAR'
1096 ! include 'COMMON.MD'
1098 ! include 'COMMON.LANGEVIN'
1100 ! include 'COMMON.LANGEVIN.lang0'
1102 ! include 'COMMON.CHAIN'
1103 ! include 'COMMON.DERIV'
1104 ! include 'COMMON.GEO'
1105 ! include 'COMMON.LOCAL'
1106 ! include 'COMMON.INTERACT'
1107 ! include 'COMMON.IOUNITS'
1108 ! include 'COMMON.NAMES'
1109 ! include 'COMMON.TIME1'
1110 ! include 'COMMON.MUCA'
1111 real(kind=8),dimension(3) :: vcm,incr
1112 real(kind=8),dimension(3) :: L
1113 integer :: count,rstcount !ilen,
1115 character(len=50) :: tytul
1116 integer :: maxcount_scale = 20
1117 !el common /gucio/ cm
1118 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1119 !el common /stochcalc/ stochforcvec
1120 integer :: itime,icount_scale,itime_scal,i,j,ifac_time
1122 real(kind=8) :: epdrift,tt0,fac_time
1124 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1130 else if (lang.eq.2 .or. lang.eq.3) then
1132 call stochastic_force(stochforcvec)
1135 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1137 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1144 icount_scale=icount_scale+1
1145 if (icount_scale.gt.maxcount_scale) then
1147 "ERROR: too many attempts at scaling down the time step. ",&
1148 "amax=",amax,"epdrift=",epdrift,&
1149 "damax=",damax,"edriftmax=",edriftmax,&
1153 call MPI_Abort(MPI_COMM_WORLD,IERROR,IERRCODE)
1157 ! First step of the velocity Verlet algorithm
1162 else if (lang.eq.3) then
1164 call sd_verlet1_ciccotti
1166 else if (lang.eq.1) then
1171 ! Build the chain from the newly calculated coordinates
1172 call chainbuild_cart
1173 if (rattle) call rattle1
1175 if (large.and. mod(itime,ntwe).eq.0) then
1176 write (iout,*) "Cartesian and internal coordinates: step 1"
1181 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
1182 (dc(j,i+nres),j=1,3)
1184 write (iout,*) "Accelerations"
1186 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1187 (d_a(j,i+nres),j=1,3)
1189 write (iout,*) "Velocities, step 1"
1191 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1192 (d_t(j,i+nres),j=1,3)
1201 ! Calculate energy and forces
1203 call etotal(potEcomp)
1204 ! AL 4/17/17: Reduce the steps if NaNs occurred.
1205 if (potEcomp(0).gt.0.99e20 .or. isnan(potEcomp(0)).gt.0) then
1210 if (large.and. mod(itime,ntwe).eq.0) &
1211 call enerprint(potEcomp)
1214 t_etotal=t_etotal+MPI_Wtime()-tt0
1216 t_etotal=t_etotal+tcpu()-tt0
1219 potE=potEcomp(0)-potEcomp(20)
1221 ! Get the new accelerations
1224 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1226 t_enegrad=t_enegrad+tcpu()-tt0
1228 ! Determine maximum acceleration and scale down the timestep if needed
1230 amax=amax/(itime_scal+1)**2
1231 call predict_edrift(epdrift)
1232 if (amax/(itime_scal+1).gt.damax .or. epdrift.gt.edriftmax) then
1233 ! Maximum acceleration or maximum predicted energy drift exceeded, rescale the time step
1235 ifac_time=dmax1(dlog(amax/damax),dlog(epdrift/edriftmax)) &
1237 itime_scal=itime_scal+ifac_time
1238 ! fac_time=dmin1(damax/amax,0.5d0)
1239 fac_time=0.5d0**ifac_time
1240 d_time=d_time*fac_time
1241 if (lang.eq.2 .or. lang.eq.3) then
1243 ! write (iout,*) "Calling sd_verlet_setup: 1"
1244 ! Rescale the stochastic forces and recalculate or restore
1245 ! the matrices of tinker integrator
1246 if (itime_scal.gt.maxflag_stoch) then
1247 if (large) write (iout,'(a,i5,a)') &
1248 "Calculate matrices for stochastic step;",&
1249 " itime_scal ",itime_scal
1251 call sd_verlet_p_setup
1253 call sd_verlet_ciccotti_setup
1255 write (iout,'(2a,i3,a,i3,1h.)') &
1256 "Warning: cannot store matrices for stochastic",&
1257 " integration because the index",itime_scal,&
1258 " is greater than",maxflag_stoch
1259 write (iout,'(2a)')"Increase MAXFLAG_STOCH or use direct",&
1260 " integration Langevin algorithm for better efficiency."
1261 else if (flag_stoch(itime_scal)) then
1262 if (large) write (iout,'(a,i5,a,l1)') &
1263 "Restore matrices for stochastic step; itime_scal ",&
1264 itime_scal," flag ",flag_stoch(itime_scal)
1267 pfric_mat(i,j)=pfric0_mat(i,j,itime_scal)
1268 afric_mat(i,j)=afric0_mat(i,j,itime_scal)
1269 vfric_mat(i,j)=vfric0_mat(i,j,itime_scal)
1270 prand_mat(i,j)=prand0_mat(i,j,itime_scal)
1271 vrand_mat1(i,j)=vrand0_mat1(i,j,itime_scal)
1272 vrand_mat2(i,j)=vrand0_mat2(i,j,itime_scal)
1276 if (large) write (iout,'(2a,i5,a,l1)') &
1277 "Calculate & store matrices for stochastic step;",&
1278 " itime_scal ",itime_scal," flag ",flag_stoch(itime_scal)
1280 call sd_verlet_p_setup
1282 call sd_verlet_ciccotti_setup
1284 flag_stoch(ifac_time)=.true.
1287 pfric0_mat(i,j,itime_scal)=pfric_mat(i,j)
1288 afric0_mat(i,j,itime_scal)=afric_mat(i,j)
1289 vfric0_mat(i,j,itime_scal)=vfric_mat(i,j)
1290 prand0_mat(i,j,itime_scal)=prand_mat(i,j)
1291 vrand0_mat1(i,j,itime_scal)=vrand_mat1(i,j)
1292 vrand0_mat2(i,j,itime_scal)=vrand_mat2(i,j)
1296 fac_time=1.0d0/dsqrt(fac_time)
1298 stochforcvec(i)=fac_time*stochforcvec(i)
1301 else if (lang.eq.1) then
1302 ! Rescale the accelerations due to stochastic forces
1303 fac_time=1.0d0/dsqrt(fac_time)
1305 d_as_work(i)=d_as_work(i)*fac_time
1308 if (large) write (iout,'(a,i10,a,f8.6,a,i3,a,i3)') &
1309 "itime",itime," Timestep scaled down to ",&
1310 d_time," ifac_time",ifac_time," itime_scal",itime_scal
1312 ! Second step of the velocity Verlet algorithm
1317 else if (lang.eq.3) then
1319 call sd_verlet2_ciccotti
1321 else if (lang.eq.1) then
1326 if (rattle) call rattle2
1329 if (d_time.ne.d_time0) then
1332 if (lang.eq.2 .or. lang.eq.3) then
1333 if (large) write (iout,'(a)') &
1334 "Restore original matrices for stochastic step"
1335 ! write (iout,*) "Calling sd_verlet_setup: 2"
1336 ! Restore the matrices of tinker integrator if the time step has been restored
1339 pfric_mat(i,j)=pfric0_mat(i,j,0)
1340 afric_mat(i,j)=afric0_mat(i,j,0)
1341 vfric_mat(i,j)=vfric0_mat(i,j,0)
1342 prand_mat(i,j)=prand0_mat(i,j,0)
1343 vrand_mat1(i,j)=vrand0_mat1(i,j,0)
1344 vrand_mat2(i,j)=vrand0_mat2(i,j,0)
1353 ! Calculate the kinetic and the total energy and the kinetic temperature
1357 ! call kinetic1(EK1)
1358 ! write (iout,*) "step",itime," EK",EK," EK1",EK1
1360 ! Couple the system to Berendsen bath if needed
1361 if (tbf .and. lang.eq.0) then
1364 kinetic_T=2.0d0/(dimen3*Rb)*EK
1365 ! Backup the coordinates, velocities, and accelerations
1369 d_t_old(j,i)=d_t(j,i)
1370 d_a_old(j,i)=d_a(j,i)
1374 if (mod(itime,ntwe).eq.0 .and. large) then
1375 write (iout,*) "Velocities, step 2"
1377 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1378 (d_t(j,i+nres),j=1,3)
1383 end subroutine velverlet_step
1384 !-----------------------------------------------------------------------------
1385 subroutine RESPA_step(itime)
1386 !-------------------------------------------------------------------------------
1387 ! Perform a single RESPA step.
1388 !-------------------------------------------------------------------------------
1389 ! implicit real*8 (a-h,o-z)
1390 ! include 'DIMENSIONS'
1394 use control, only:tcpu
1396 ! use io_conf, only:cartprint
1399 integer :: IERROR,ERRCODE
1401 ! include 'COMMON.SETUP'
1402 ! include 'COMMON.CONTROL'
1403 ! include 'COMMON.VAR'
1404 ! include 'COMMON.MD'
1406 ! include 'COMMON.LANGEVIN'
1408 ! include 'COMMON.LANGEVIN.lang0'
1410 ! include 'COMMON.CHAIN'
1411 ! include 'COMMON.DERIV'
1412 ! include 'COMMON.GEO'
1413 ! include 'COMMON.LOCAL'
1414 ! include 'COMMON.INTERACT'
1415 ! include 'COMMON.IOUNITS'
1416 ! include 'COMMON.NAMES'
1417 ! include 'COMMON.TIME1'
1418 real(kind=8),dimension(0:n_ene) :: energia_short,energia_long
1419 real(kind=8),dimension(3) :: L,vcm,incr
1420 real(kind=8),dimension(3,0:2*nres) :: dc_old0,d_t_old0,d_a_old0 !(3,0:maxres2) maxres2=2*maxres
1421 logical :: PRINT_AMTS_MSG = .false.
1422 integer :: count,rstcount !ilen,
1424 character(len=50) :: tytul
1425 integer :: maxcount_scale = 10
1426 !el common /gucio/ cm
1427 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1428 !el common /stochcalc/ stochforcvec
1429 integer :: itime,itt,i,j,itsplit
1431 !el common /cipiszcze/ itt
1433 real(kind=8) :: epdrift,tt0,epdriftmax
1436 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1440 if (large.and. mod(itime,ntwe).eq.0) then
1441 write (iout,*) "***************** RESPA itime",itime
1442 write (iout,*) "Cartesian and internal coordinates: step 0"
1444 call pdbout(0.0d0,"cipiszcze",iout)
1446 write (iout,*) "Accelerations from long-range forces"
1448 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1449 (d_a(j,i+nres),j=1,3)
1451 write (iout,*) "Velocities, step 0"
1453 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1454 (d_t(j,i+nres),j=1,3)
1459 ! Perform the initial RESPA step (increment velocities)
1460 ! write (iout,*) "*********************** RESPA ini"
1463 if (mod(itime,ntwe).eq.0 .and. large) then
1464 write (iout,*) "Velocities, end"
1466 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1467 (d_t(j,i+nres),j=1,3)
1471 ! Compute the short-range forces
1477 ! 7/2/2009 commented out
1479 ! call etotal_short(energia_short)
1482 ! 7/2/2009 Copy accelerations due to short-lange forces from previous MD step
1485 d_a(j,i)=d_a_short(j,i)
1489 if (large.and. mod(itime,ntwe).eq.0) then
1490 write (iout,*) "energia_short",energia_short(0)
1491 write (iout,*) "Accelerations from short-range forces"
1493 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1494 (d_a(j,i+nres),j=1,3)
1499 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1501 t_enegrad=t_enegrad+tcpu()-tt0
1506 d_t_old(j,i)=d_t(j,i)
1507 d_a_old(j,i)=d_a(j,i)
1510 ! 6/30/08 A-MTS: attempt at increasing the split number
1513 dc_old0(j,i)=dc_old(j,i)
1514 d_t_old0(j,i)=d_t_old(j,i)
1515 d_a_old0(j,i)=d_a_old(j,i)
1518 if (ntime_split.gt.ntime_split0) ntime_split=ntime_split/2
1519 if (ntime_split.lt.ntime_split0) ntime_split=ntime_split0
1526 ! write (iout,*) "itime",itime," ntime_split",ntime_split
1527 ! Split the time step
1528 d_time=d_time0/ntime_split
1529 ! Perform the short-range RESPA steps (velocity Verlet increments of
1530 ! positions and velocities using short-range forces)
1531 ! write (iout,*) "*********************** RESPA split"
1532 do itsplit=1,ntime_split
1535 else if (lang.eq.2 .or. lang.eq.3) then
1537 call stochastic_force(stochforcvec)
1540 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1542 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1547 ! First step of the velocity Verlet algorithm
1552 else if (lang.eq.3) then
1554 call sd_verlet1_ciccotti
1556 else if (lang.eq.1) then
1561 ! Build the chain from the newly calculated coordinates
1562 call chainbuild_cart
1563 if (rattle) call rattle1
1565 if (large.and. mod(itime,ntwe).eq.0) then
1566 write (iout,*) "***** ITSPLIT",itsplit
1567 write (iout,*) "Cartesian and internal coordinates: step 1"
1568 call pdbout(0.0d0,"cipiszcze",iout)
1571 write (iout,*) "Velocities, step 1"
1573 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1574 (d_t(j,i+nres),j=1,3)
1583 ! Calculate energy and forces
1585 call etotal_short(energia_short)
1586 ! AL 4/17/17: Exit itime_split loop when energy goes infinite
1587 if (energia_short(0).gt.0.99e20 .or. isnan(energia_short(0)) ) then
1588 if (PRINT_AMTS_MSG) &
1589 write (iout,*) "Infinities/NaNs in energia_short",energia_short(0),"; increasing ntime_split to",ntime_split
1590 ntime_split=ntime_split*2
1591 if (ntime_split.gt.maxtime_split) then
1594 "Cannot rescue the run; aborting job. Retry with a smaller time step"
1596 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1599 "Cannot rescue the run; terminating. Retry with a smaller time step"
1605 if (large.and. mod(itime,ntwe).eq.0) &
1606 call enerprint(energia_short)
1609 t_eshort=t_eshort+MPI_Wtime()-tt0
1611 t_eshort=t_eshort+tcpu()-tt0
1615 ! Get the new accelerations
1617 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
1620 d_a_short(j,i)=d_a(j,i)
1624 if (large.and. mod(itime,ntwe).eq.0) then
1625 write (iout,*)"energia_short",energia_short(0)
1626 write (iout,*) "Accelerations from short-range forces"
1628 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1629 (d_a(j,i+nres),j=1,3)
1634 ! Determine maximum acceleration and scale down the timestep if needed
1636 amax=amax/ntime_split**2
1637 call predict_edrift(epdrift)
1638 if (ntwe.gt.0 .and. large .and. mod(itime,ntwe).eq.0) &
1639 write (iout,*) "amax",amax," damax",damax,&
1640 " epdrift",epdrift," epdriftmax",epdriftmax
1641 ! Exit loop and try with increased split number if the change of
1642 ! acceleration is too big
1643 if (amax.gt.damax .or. epdrift.gt.edriftmax) then
1644 if (ntime_split.lt.maxtime_split) then
1646 ntime_split=ntime_split*2
1647 ! AL 4/17/17: We should exit the itime_split loop when acceleration change is too big
1651 dc_old(j,i)=dc_old0(j,i)
1652 d_t_old(j,i)=d_t_old0(j,i)
1653 d_a_old(j,i)=d_a_old0(j,i)
1656 if (PRINT_AMTS_MSG) then
1657 write (iout,*) "acceleration/energy drift too large",amax,&
1658 epdrift," split increased to ",ntime_split," itime",itime,&
1664 "Uh-hu. Bumpy landscape. Maximum splitting number",&
1666 " already reached!!! Trying to carry on!"
1670 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1672 t_enegrad=t_enegrad+tcpu()-tt0
1674 ! Second step of the velocity Verlet algorithm
1679 else if (lang.eq.3) then
1681 call sd_verlet2_ciccotti
1683 else if (lang.eq.1) then
1688 if (rattle) call rattle2
1689 ! Backup the coordinates, velocities, and accelerations
1693 d_t_old(j,i)=d_t(j,i)
1694 d_a_old(j,i)=d_a(j,i)
1701 ! Restore the time step
1703 ! Compute long-range forces
1710 call etotal_long(energia_long)
1711 if (energia_long(0).gt.0.99e20 .or. isnan(energia_long(0))) then
1714 "Infinitied/NaNs in energia_long, Aborting MPI job."
1716 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1718 write (iout,*) "Infinitied/NaNs in energia_long, terminating."
1722 if (large.and. mod(itime,ntwe).eq.0) &
1723 call enerprint(energia_long)
1726 t_elong=t_elong+MPI_Wtime()-tt0
1728 t_elong=t_elong+tcpu()-tt0
1734 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1736 t_enegrad=t_enegrad+tcpu()-tt0
1738 ! Compute accelerations from long-range forces
1740 if (large.and. mod(itime,ntwe).eq.0) then
1741 write (iout,*) "energia_long",energia_long(0)
1742 write (iout,*) "Cartesian and internal coordinates: step 2"
1744 call pdbout(0.0d0,"cipiszcze",iout)
1746 write (iout,*) "Accelerations from long-range forces"
1748 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1749 (d_a(j,i+nres),j=1,3)
1751 write (iout,*) "Velocities, step 2"
1753 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1754 (d_t(j,i+nres),j=1,3)
1758 ! Compute the final RESPA step (increment velocities)
1759 ! write (iout,*) "*********************** RESPA fin"
1761 ! Compute the complete potential energy
1763 potEcomp(i)=energia_short(i)+energia_long(i)
1765 potE=potEcomp(0)-potEcomp(20)
1766 ! potE=energia_short(0)+energia_long(0)
1769 ! Calculate the kinetic and the total energy and the kinetic temperature
1772 ! Couple the system to Berendsen bath if needed
1773 if (tbf .and. lang.eq.0) then
1776 kinetic_T=2.0d0/(dimen3*Rb)*EK
1777 ! Backup the coordinates, velocities, and accelerations
1779 if (mod(itime,ntwe).eq.0 .and. large) then
1780 write (iout,*) "Velocities, end"
1782 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1783 (d_t(j,i+nres),j=1,3)
1788 end subroutine RESPA_step
1789 !-----------------------------------------------------------------------------
1790 subroutine RESPA_vel
1791 ! First and last RESPA step (incrementing velocities using long-range
1794 ! implicit real*8 (a-h,o-z)
1795 ! include 'DIMENSIONS'
1796 ! include 'COMMON.CONTROL'
1797 ! include 'COMMON.VAR'
1798 ! include 'COMMON.MD'
1799 ! include 'COMMON.CHAIN'
1800 ! include 'COMMON.DERIV'
1801 ! include 'COMMON.GEO'
1802 ! include 'COMMON.LOCAL'
1803 ! include 'COMMON.INTERACT'
1804 ! include 'COMMON.IOUNITS'
1805 ! include 'COMMON.NAMES'
1806 integer :: i,j,inres,mnum
1809 d_t(j,0)=d_t(j,0)+0.5d0*d_a(j,0)*d_time
1813 d_t(j,i)=d_t(j,i)+0.5d0*d_a(j,i)*d_time
1818 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1819 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1820 .and.(mnum.ne.5)) then
1823 d_t(j,inres)=d_t(j,inres)+0.5d0*d_a(j,inres)*d_time
1828 end subroutine RESPA_vel
1829 !-----------------------------------------------------------------------------
1831 ! Applying velocity Verlet algorithm - step 1 to coordinates
1833 ! implicit real*8 (a-h,o-z)
1834 ! include 'DIMENSIONS'
1835 ! include 'COMMON.CONTROL'
1836 ! include 'COMMON.VAR'
1837 ! include 'COMMON.MD'
1838 ! include 'COMMON.CHAIN'
1839 ! include 'COMMON.DERIV'
1840 ! include 'COMMON.GEO'
1841 ! include 'COMMON.LOCAL'
1842 ! include 'COMMON.INTERACT'
1843 ! include 'COMMON.IOUNITS'
1844 ! include 'COMMON.NAMES'
1845 real(kind=8) :: adt,adt2
1846 integer :: i,j,inres,mnum
1849 write (iout,*) "VELVERLET1 START: DC"
1851 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1852 (dc(j,i+nres),j=1,3)
1856 adt=d_a_old(j,0)*d_time
1858 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1859 d_t_new(j,0)=d_t_old(j,0)+adt2
1860 d_t(j,0)=d_t_old(j,0)+adt
1864 adt=d_a_old(j,i)*d_time
1866 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1867 d_t_new(j,i)=d_t_old(j,i)+adt2
1868 d_t(j,i)=d_t_old(j,i)+adt
1873 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1874 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1875 .and.(mnum.ne.5)) then
1878 adt=d_a_old(j,inres)*d_time
1880 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1881 d_t_new(j,inres)=d_t_old(j,inres)+adt2
1882 d_t(j,inres)=d_t_old(j,inres)+adt
1887 write (iout,*) "VELVERLET1 END: DC"
1889 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1890 (dc(j,i+nres),j=1,3)
1894 end subroutine verlet1
1895 !-----------------------------------------------------------------------------
1897 ! Step 2 of the velocity Verlet algorithm: update velocities
1899 ! implicit real*8 (a-h,o-z)
1900 ! include 'DIMENSIONS'
1901 ! include 'COMMON.CONTROL'
1902 ! include 'COMMON.VAR'
1903 ! include 'COMMON.MD'
1904 ! include 'COMMON.CHAIN'
1905 ! include 'COMMON.DERIV'
1906 ! include 'COMMON.GEO'
1907 ! include 'COMMON.LOCAL'
1908 ! include 'COMMON.INTERACT'
1909 ! include 'COMMON.IOUNITS'
1910 ! include 'COMMON.NAMES'
1911 integer :: i,j,inres,mnum
1914 d_t(j,0)=d_t_new(j,0)+0.5d0*d_a(j,0)*d_time
1918 d_t(j,i)=d_t_new(j,i)+0.5d0*d_a(j,i)*d_time
1923 ! iti=iabs(itype(i,mnum))
1924 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1925 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1926 .and.(mnum.ne.5)) then
1929 d_t(j,inres)=d_t_new(j,inres)+0.5d0*d_a(j,inres)*d_time
1934 end subroutine verlet2
1935 !-----------------------------------------------------------------------------
1936 subroutine sddir_precalc
1937 ! Applying velocity Verlet algorithm - step 1 to coordinates
1938 ! implicit real*8 (a-h,o-z)
1939 ! include 'DIMENSIONS'
1945 ! include 'COMMON.CONTROL'
1946 ! include 'COMMON.VAR'
1947 ! include 'COMMON.MD'
1949 ! include 'COMMON.LANGEVIN'
1951 ! include 'COMMON.LANGEVIN.lang0'
1953 ! include 'COMMON.CHAIN'
1954 ! include 'COMMON.DERIV'
1955 ! include 'COMMON.GEO'
1956 ! include 'COMMON.LOCAL'
1957 ! include 'COMMON.INTERACT'
1958 ! include 'COMMON.IOUNITS'
1959 ! include 'COMMON.NAMES'
1960 ! include 'COMMON.TIME1'
1961 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1962 !el common /stochcalc/ stochforcvec
1963 real(kind=8) :: time00
1965 ! Compute friction and stochastic forces
1970 time_fric=time_fric+MPI_Wtime()-time00
1972 call stochastic_force(stochforcvec)
1973 time_stoch=time_stoch+MPI_Wtime()-time00
1976 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
1977 ! forces (d_as_work)
1979 call ginv_mult(fric_work, d_af_work)
1980 call ginv_mult(stochforcvec, d_as_work)
1982 end subroutine sddir_precalc
1983 !-----------------------------------------------------------------------------
1984 subroutine sddir_verlet1
1985 ! Applying velocity Verlet algorithm - step 1 to velocities
1988 ! implicit real*8 (a-h,o-z)
1989 ! include 'DIMENSIONS'
1990 ! include 'COMMON.CONTROL'
1991 ! include 'COMMON.VAR'
1992 ! include 'COMMON.MD'
1994 ! include 'COMMON.LANGEVIN'
1996 ! include 'COMMON.LANGEVIN.lang0'
1998 ! include 'COMMON.CHAIN'
1999 ! include 'COMMON.DERIV'
2000 ! include 'COMMON.GEO'
2001 ! include 'COMMON.LOCAL'
2002 ! include 'COMMON.INTERACT'
2003 ! include 'COMMON.IOUNITS'
2004 ! include 'COMMON.NAMES'
2005 ! Revised 3/31/05 AL: correlation between random contributions to
2006 ! position and velocity increments included.
2007 real(kind=8) :: sqrt13 = 0.57735026918962576451d0 ! 1/sqrt(3)
2008 real(kind=8) :: adt,adt2
2009 integer :: i,j,ind,inres,mnum
2011 ! Add the contribution from BOTH friction and stochastic force to the
2012 ! coordinates, but ONLY the contribution from the friction forces to velocities
2015 adt=(d_a_old(j,0)+d_af_work(j))*d_time
2016 adt2=0.5d0*adt+sqrt13*d_as_work(j)*d_time
2017 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
2018 d_t_new(j,0)=d_t_old(j,0)+0.5d0*adt
2019 d_t(j,0)=d_t_old(j,0)+adt
2024 adt=(d_a_old(j,i)+d_af_work(ind+j))*d_time
2025 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
2026 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
2027 d_t_new(j,i)=d_t_old(j,i)+0.5d0*adt
2028 d_t(j,i)=d_t_old(j,i)+adt
2034 ! iti=iabs(itype(i,mnum))
2035 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2036 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2037 .and.(mnum.ne.5)) then
2040 adt=(d_a_old(j,inres)+d_af_work(ind+j))*d_time
2041 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
2042 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
2043 d_t_new(j,inres)=d_t_old(j,inres)+0.5d0*adt
2044 d_t(j,inres)=d_t_old(j,inres)+adt
2050 end subroutine sddir_verlet1
2051 !-----------------------------------------------------------------------------
2052 subroutine sddir_verlet2
2053 ! Calculating the adjusted velocities for accelerations
2056 ! implicit real*8 (a-h,o-z)
2057 ! include 'DIMENSIONS'
2058 ! include 'COMMON.CONTROL'
2059 ! include 'COMMON.VAR'
2060 ! include 'COMMON.MD'
2062 ! include 'COMMON.LANGEVIN'
2064 ! include 'COMMON.LANGEVIN.lang0'
2066 ! include 'COMMON.CHAIN'
2067 ! include 'COMMON.DERIV'
2068 ! include 'COMMON.GEO'
2069 ! include 'COMMON.LOCAL'
2070 ! include 'COMMON.INTERACT'
2071 ! include 'COMMON.IOUNITS'
2072 ! include 'COMMON.NAMES'
2073 real(kind=8),dimension(6*nres) :: stochforcvec,d_as_work1 !(MAXRES6) maxres6=6*maxres
2074 real(kind=8) :: cos60 = 0.5d0, sin60 = 0.86602540378443864676d0
2075 integer :: i,j,ind,inres,mnum
2076 ! Revised 3/31/05 AL: correlation between random contributions to
2077 ! position and velocity increments included.
2078 ! The correlation coefficients are calculated at low-friction limit.
2079 ! Also, friction forces are now not calculated with new velocities.
2081 ! call friction_force
2082 call stochastic_force(stochforcvec)
2084 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
2085 ! forces (d_as_work)
2087 call ginv_mult(stochforcvec, d_as_work1)
2093 d_t(j,0)=d_t_new(j,0)+(0.5d0*(d_a(j,0)+d_af_work(j)) &
2094 +sin60*d_as_work(j)+cos60*d_as_work1(j))*d_time
2099 d_t(j,i)=d_t_new(j,i)+(0.5d0*(d_a(j,i)+d_af_work(ind+j)) &
2100 +sin60*d_as_work(ind+j)+cos60*d_as_work1(ind+j))*d_time
2106 ! iti=iabs(itype(i,mnum))
2107 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2108 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2109 .and.(mnum.ne.5)) then
2112 d_t(j,inres)=d_t_new(j,inres)+(0.5d0*(d_a(j,inres) &
2113 +d_af_work(ind+j))+sin60*d_as_work(ind+j) &
2114 +cos60*d_as_work1(ind+j))*d_time
2120 end subroutine sddir_verlet2
2121 !-----------------------------------------------------------------------------
2122 subroutine max_accel
2124 ! Find the maximum difference in the accelerations of the the sites
2125 ! at the beginning and the end of the time step.
2128 ! implicit real*8 (a-h,o-z)
2129 ! include 'DIMENSIONS'
2130 ! include 'COMMON.CONTROL'
2131 ! include 'COMMON.VAR'
2132 ! include 'COMMON.MD'
2133 ! include 'COMMON.CHAIN'
2134 ! include 'COMMON.DERIV'
2135 ! include 'COMMON.GEO'
2136 ! include 'COMMON.LOCAL'
2137 ! include 'COMMON.INTERACT'
2138 ! include 'COMMON.IOUNITS'
2139 real(kind=8),dimension(3) :: aux,accel,accel_old
2140 real(kind=8) :: dacc
2144 ! aux(j)=d_a(j,0)-d_a_old(j,0)
2145 accel_old(j)=d_a_old(j,0)
2152 ! 7/3/08 changed to asymmetric difference
2154 ! accel(j)=aux(j)+0.5d0*(d_a(j,i)-d_a_old(j,i))
2155 accel_old(j)=accel_old(j)+0.5d0*d_a_old(j,i)
2156 accel(j)=accel(j)+0.5d0*d_a(j,i)
2157 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2158 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2159 dacc=dabs(accel(j)-accel_old(j))
2160 ! write (iout,*) i,dacc
2161 if (dacc.gt.amax) amax=dacc
2169 accel_old(j)=d_a_old(j,0)
2174 accel_old(j)=accel_old(j)+d_a_old(j,1)
2175 accel(j)=accel(j)+d_a(j,1)
2180 ! iti=iabs(itype(i,mnum))
2181 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2182 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2183 .and.(mnum.ne.5)) then
2185 ! accel(j)=accel(j)+d_a(j,i+nres)-d_a_old(j,i+nres)
2186 accel_old(j)=accel_old(j)+d_a_old(j,i+nres)
2187 accel(j)=accel(j)+d_a(j,i+nres)
2191 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2192 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2193 dacc=dabs(accel(j)-accel_old(j))
2194 ! write (iout,*) "side-chain",i,dacc
2195 if (dacc.gt.amax) amax=dacc
2199 accel_old(j)=accel_old(j)+d_a_old(j,i)
2200 accel(j)=accel(j)+d_a(j,i)
2201 ! aux(j)=aux(j)+d_a(j,i)-d_a_old(j,i)
2205 end subroutine max_accel
2206 !-----------------------------------------------------------------------------
2207 subroutine predict_edrift(epdrift)
2209 ! Predict the drift of the potential energy
2212 use control_data, only: lmuca
2213 ! implicit real*8 (a-h,o-z)
2214 ! include 'DIMENSIONS'
2215 ! include 'COMMON.CONTROL'
2216 ! include 'COMMON.VAR'
2217 ! include 'COMMON.MD'
2218 ! include 'COMMON.CHAIN'
2219 ! include 'COMMON.DERIV'
2220 ! include 'COMMON.GEO'
2221 ! include 'COMMON.LOCAL'
2222 ! include 'COMMON.INTERACT'
2223 ! include 'COMMON.IOUNITS'
2224 ! include 'COMMON.MUCA'
2225 real(kind=8) :: epdrift,epdriftij
2227 ! Drift of the potential energy
2233 epdriftij=dabs((d_a(j,i)-d_a_old(j,i))*gcart(j,i))
2234 if (lmuca) epdriftij=epdriftij*factor
2235 ! write (iout,*) "back",i,j,epdriftij
2236 if (epdriftij.gt.epdrift) epdrift=epdriftij
2240 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1.and.&
2241 molnum(i).ne.5) then
2244 dabs((d_a(j,i+nres)-d_a_old(j,i+nres))*gxcart(j,i))
2245 if (lmuca) epdriftij=epdriftij*factor
2246 ! write (iout,*) "side",i,j,epdriftij
2247 if (epdriftij.gt.epdrift) epdrift=epdriftij
2251 epdrift=0.5d0*epdrift*d_time*d_time
2252 ! write (iout,*) "epdrift",epdrift
2254 end subroutine predict_edrift
2255 !-----------------------------------------------------------------------------
2256 subroutine verlet_bath
2258 ! Coupling to the thermostat by using the Berendsen algorithm
2261 ! implicit real*8 (a-h,o-z)
2262 ! include 'DIMENSIONS'
2263 ! include 'COMMON.CONTROL'
2264 ! include 'COMMON.VAR'
2265 ! include 'COMMON.MD'
2266 ! include 'COMMON.CHAIN'
2267 ! include 'COMMON.DERIV'
2268 ! include 'COMMON.GEO'
2269 ! include 'COMMON.LOCAL'
2270 ! include 'COMMON.INTERACT'
2271 ! include 'COMMON.IOUNITS'
2272 ! include 'COMMON.NAMES'
2273 real(kind=8) :: T_half,fact
2274 integer :: i,j,inres,mnum
2276 T_half=2.0d0/(dimen3*Rb)*EK
2277 fact=dsqrt(1.0d0+(d_time/tau_bath)*(t_bath/T_half-1.0d0))
2278 ! write(iout,*) "T_half", T_half
2279 ! write(iout,*) "EK", EK
2280 ! write(iout,*) "fact", fact
2282 d_t(j,0)=fact*d_t(j,0)
2286 d_t(j,i)=fact*d_t(j,i)
2291 ! iti=iabs(itype(i,mnum))
2292 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2293 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2294 .and.(mnum.ne.5)) then
2297 d_t(j,inres)=fact*d_t(j,inres)
2302 end subroutine verlet_bath
2303 !-----------------------------------------------------------------------------
2305 ! Set up the initial conditions of a MD simulation
2308 use control, only:tcpu
2309 !el use io_basic, only:ilen
2312 use minimm, only:minim_dc,minimize,sc_move
2313 use io_config, only:readrst
2314 use io, only:statout
2315 ! implicit real*8 (a-h,o-z)
2316 ! include 'DIMENSIONS'
2319 character(len=16) :: form
2320 integer :: IERROR,ERRCODE
2322 ! include 'COMMON.SETUP'
2323 ! include 'COMMON.CONTROL'
2324 ! include 'COMMON.VAR'
2325 ! include 'COMMON.MD'
2327 ! include 'COMMON.LANGEVIN'
2329 ! include 'COMMON.LANGEVIN.lang0'
2331 ! include 'COMMON.CHAIN'
2332 ! include 'COMMON.DERIV'
2333 ! include 'COMMON.GEO'
2334 ! include 'COMMON.LOCAL'
2335 ! include 'COMMON.INTERACT'
2336 ! include 'COMMON.IOUNITS'
2337 ! include 'COMMON.NAMES'
2338 ! include 'COMMON.REMD'
2339 real(kind=8),dimension(0:n_ene) :: energia_long,energia_short
2340 real(kind=8),dimension(3) :: vcm,incr,L
2341 real(kind=8) :: xv,sigv,lowb,highb
2342 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
2343 character(len=256) :: qstr
2346 character(len=50) :: tytul
2347 logical :: file_exist
2348 !el common /gucio/ cm
2349 integer :: i,j,ipos,iq,iw,nft_sc,iretcode,nfun,itime,ierr,mnum
2350 real(kind=8) :: etot,tt0
2354 ! write(iout,*) "d_time", d_time
2355 ! Compute the standard deviations of stochastic forces for Langevin dynamics
2356 ! if the friction coefficients do not depend on surface area
2357 if (lang.gt.0 .and. .not.surfarea) then
2360 stdforcp(i)=stdfp(mnum)*dsqrt(gamp(mnum))
2364 stdforcsc(i)=stdfsc(iabs(itype(i,mnum)),mnum) &
2365 *dsqrt(gamsc(iabs(itype(i,mnum)),mnum))
2368 ! Open the pdb file for snapshotshots
2371 if (ilen(tmpdir).gt.0) &
2372 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2373 liczba(:ilen(liczba))//".pdb")
2375 file=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2379 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2380 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2381 liczba(:ilen(liczba))//".x")
2382 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2385 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2386 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2387 liczba(:ilen(liczba))//".cx")
2388 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2394 if (ilen(tmpdir).gt.0) &
2395 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.pdb")
2396 open(ipdb,file=prefix(:ilen(prefix))//"_MD.pdb")
2398 if (ilen(tmpdir).gt.0) &
2399 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.cx")
2400 cartname=prefix(:ilen(prefix))//"_MD.cx"
2404 write (qstr,'(256(1h ))')
2407 iq = qinfrag(i,iset)*10
2408 iw = wfrag(i,iset)/100
2410 if(me.eq.king.or..not.out1file) &
2411 write (iout,*) "Frag",qinfrag(i,iset),wfrag(i,iset),iq,iw
2412 write (qstr(ipos:ipos+6),'(2h_f,i1,1h_,i1,1h_,i1)') i,iq,iw
2417 iq = qinpair(i,iset)*10
2418 iw = wpair(i,iset)/100
2420 if(me.eq.king.or..not.out1file) &
2421 write (iout,*) "Pair",i,qinpair(i,iset),wpair(i,iset),iq,iw
2422 write (qstr(ipos:ipos+6),'(2h_p,i1,1h_,i1,1h_,i1)') i,iq,iw
2426 ! pdbname=pdbname(:ilen(pdbname)-4)//qstr(:ipos-1)//'.pdb'
2428 ! cartname=cartname(:ilen(cartname)-2)//qstr(:ipos-1)//'.x'
2430 ! cartname=cartname(:ilen(cartname)-3)//qstr(:ipos-1)//'.cx'
2432 ! statname=statname(:ilen(statname)-5)//qstr(:ipos-1)//'.stat'
2436 if (restart1file) then
2438 inquire(file=mremd_rst_name,exist=file_exist)
2439 write (*,*) me," Before broadcast: file_exist",file_exist
2441 call MPI_Bcast(file_exist,1,MPI_LOGICAL,king,CG_COMM,&
2444 write (*,*) me," After broadcast: file_exist",file_exist
2445 ! inquire(file=mremd_rst_name,exist=file_exist)
2446 if(me.eq.king.or..not.out1file) &
2447 write(iout,*) "Initial state read by master and distributed"
2449 if (ilen(tmpdir).gt.0) &
2450 call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_' &
2451 //liczba(:ilen(liczba))//'.rst')
2452 inquire(file=rest2name,exist=file_exist)
2455 if(.not.restart1file) then
2456 if(me.eq.king.or..not.out1file) &
2457 write(iout,*) "Initial state will be read from file ",&
2458 rest2name(:ilen(rest2name))
2461 call rescale_weights(t_bath)
2463 if(me.eq.king.or..not.out1file)then
2464 if (restart1file) then
2465 write(iout,*) "File ",mremd_rst_name(:ilen(mremd_rst_name)),&
2468 write(iout,*) "File ",rest2name(:ilen(rest2name)),&
2471 write(iout,*) "Initial velocities randomly generated"
2478 ! Generate initial velocities
2479 if(me.eq.king.or..not.out1file) &
2480 write(iout,*) "Initial velocities randomly generated"
2485 ! rest2name = prefix(:ilen(prefix))//'.rst'
2486 if(me.eq.king.or..not.out1file)then
2487 write (iout,*) "Initial velocities"
2489 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2490 (d_t(j,i+nres),j=1,3)
2492 ! Zeroing the total angular momentum of the system
2493 write(iout,*) "Calling the zero-angular momentum subroutine"
2496 ! Getting the potential energy and forces and velocities and accelerations
2498 ! write (iout,*) "velocity of the center of the mass:"
2499 ! write (iout,*) (vcm(j),j=1,3)
2501 d_t(j,0)=d_t(j,0)-vcm(j)
2503 ! Removing the velocity of the center of mass
2505 if(me.eq.king.or..not.out1file)then
2506 write (iout,*) "vcm right after adjustment:"
2507 write (iout,*) (vcm(j),j=1,3)
2509 if ((.not.rest).and.(indpdb.eq.0)) then
2511 if(iranconf.ne.0) then
2513 print *, 'Calling OVERLAP_SC'
2514 call overlap_sc(fail)
2517 call sc_move(2,nres-1,10,1d10,nft_sc,etot)
2518 print *,'SC_move',nft_sc,etot
2519 if(me.eq.king.or..not.out1file) &
2520 write(iout,*) 'SC_move',nft_sc,etot
2524 print *, 'Calling MINIM_DC'
2525 call minim_dc(etot,iretcode,nfun)
2527 call geom_to_var(nvar,varia)
2528 print *,'Calling MINIMIZE.'
2529 call minimize(etot,varia,iretcode,nfun)
2530 call var_to_geom(nvar,varia)
2532 if(me.eq.king.or..not.out1file) &
2533 write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
2536 call chainbuild_cart
2541 kinetic_T=2.0d0/(dimen3*Rb)*EK
2542 if(me.eq.king.or..not.out1file)then
2552 call etotal(potEcomp)
2553 if (large) call enerprint(potEcomp)
2556 t_etotal=t_etotal+MPI_Wtime()-tt0
2558 t_etotal=t_etotal+tcpu()-tt0
2565 if (amax*d_time .gt. dvmax) then
2566 d_time=d_time*dvmax/amax
2567 if(me.eq.king.or..not.out1file) write (iout,*) &
2568 "Time step reduced to",d_time,&
2569 " because of too large initial acceleration."
2571 if(me.eq.king.or..not.out1file)then
2572 write(iout,*) "Potential energy and its components"
2573 call enerprint(potEcomp)
2574 ! write(iout,*) (potEcomp(i),i=0,n_ene)
2576 potE=potEcomp(0)-potEcomp(20)
2579 if (ntwe.ne.0) call statout(itime)
2580 if(me.eq.king.or..not.out1file) &
2581 write (iout,'(/a/3(a25,1pe14.5/))') "Initial:", &
2582 " Kinetic energy",EK," Potential energy",potE, &
2583 " Total energy",totE," Maximum acceleration ", &
2586 write (iout,*) "Initial coordinates"
2588 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(c(j,i),j=1,3),&
2591 write (iout,*) "Initial dC"
2593 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
2594 (dc(j,i+nres),j=1,3)
2596 write (iout,*) "Initial velocities"
2597 write (iout,"(13x,' backbone ',23x,' side chain')")
2599 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2600 (d_t(j,i+nres),j=1,3)
2602 write (iout,*) "Initial accelerations"
2604 ! write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
2605 write (iout,'(i3,3f15.10,3x,3f15.10)') i,(d_a(j,i),j=1,3),&
2606 (d_a(j,i+nres),j=1,3)
2612 d_t_old(j,i)=d_t(j,i)
2613 d_a_old(j,i)=d_a(j,i)
2615 ! write (iout,*) "dc_old",i,(dc_old(j,i),j=1,3)
2624 call etotal_short(energia_short)
2625 if (large) call enerprint(potEcomp)
2628 t_eshort=t_eshort+MPI_Wtime()-tt0
2630 t_eshort=t_eshort+tcpu()-tt0
2635 if(.not.out1file .and. large) then
2636 write (iout,*) "energia_long",energia_long(0),&
2637 " energia_short",energia_short(0),&
2638 " total",energia_long(0)+energia_short(0)
2639 write (iout,*) "Initial fast-force accelerations"
2641 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2642 (d_a(j,i+nres),j=1,3)
2645 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
2648 d_a_short(j,i)=d_a(j,i)
2657 call etotal_long(energia_long)
2658 if (large) call enerprint(potEcomp)
2661 t_elong=t_elong+MPI_Wtime()-tt0
2663 t_elong=t_elong+tcpu()-tt0
2668 if(.not.out1file .and. large) then
2669 write (iout,*) "energia_long",energia_long(0)
2670 write (iout,*) "Initial slow-force accelerations"
2672 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2673 (d_a(j,i+nres),j=1,3)
2677 t_enegrad=t_enegrad+MPI_Wtime()-tt0
2679 t_enegrad=t_enegrad+tcpu()-tt0
2683 end subroutine init_MD
2684 !-----------------------------------------------------------------------------
2685 subroutine random_vel
2687 ! implicit real*8 (a-h,o-z)
2689 use random, only:anorm_distr
2691 ! include 'DIMENSIONS'
2692 ! include 'COMMON.CONTROL'
2693 ! include 'COMMON.VAR'
2694 ! include 'COMMON.MD'
2696 ! include 'COMMON.LANGEVIN'
2698 ! include 'COMMON.LANGEVIN.lang0'
2700 ! include 'COMMON.CHAIN'
2701 ! include 'COMMON.DERIV'
2702 ! include 'COMMON.GEO'
2703 ! include 'COMMON.LOCAL'
2704 ! include 'COMMON.INTERACT'
2705 ! include 'COMMON.IOUNITS'
2706 ! include 'COMMON.NAMES'
2707 ! include 'COMMON.TIME1'
2708 real(kind=8) :: xv,sigv,lowb,highb ,Ek1
2711 real(kind=8) ,allocatable, dimension(:) :: DDU1,DDU2,DL2,DL1,xsolv,DML,rs
2712 real(kind=8) :: sumx
2714 real(kind=8) ,allocatable, dimension(:) :: rsold
2715 real (kind=8),allocatable,dimension(:,:) :: matold
2719 integer :: i,j,ii,k,ind,mark,imark,mnum
2720 ! Generate random velocities from Gaussian distribution of mean 0 and std of KT/m
2721 ! First generate velocities in the eigenspace of the G matrix
2722 ! write (iout,*) "Calling random_vel dimen dimen3",dimen,dimen3
2729 sigv=dsqrt((Rb*t_bath)/geigen(i))
2732 d_t_work_new(ii)=anorm_distr(xv,sigv,lowb,highb)
2734 write (iout,*) "i",i," ii",ii," geigen",geigen(i),&
2735 " d_t_work_new",d_t_work_new(ii)
2746 Ek1=Ek1+0.5d0*geigen(i)*d_t_work_new(ii)**2
2749 write (iout,*) "Ek from eigenvectors",Ek1
2750 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2754 ! Transform velocities to UNRES coordinate space
2755 allocate (DL1(2*nres))
2756 allocate (DDU1(2*nres))
2757 allocate (DL2(2*nres))
2758 allocate (DDU2(2*nres))
2759 allocate (xsolv(2*nres))
2760 allocate (DML(2*nres))
2761 allocate (rs(2*nres))
2763 allocate (rsold(2*nres))
2764 allocate (matold(2*nres,2*nres))
2766 matold(1,1)=DMorig(1)
2767 matold(1,2)=DU1orig(1)
2768 matold(1,3)=DU2orig(1)
2769 write (*,*) DMorig(1),DU1orig(1),DU2orig(1)
2774 matold(i,j)=DMorig(i)
2775 matold(i,j-1)=DU1orig(i-1)
2777 matold(i,j-2)=DU2orig(i-2)
2785 matold(i,j+1)=DU1orig(i)
2791 matold(i,j+2)=DU2orig(i)
2795 matold(dimen,dimen)=DMorig(dimen)
2796 matold(dimen,dimen-1)=DU1orig(dimen-1)
2797 matold(dimen,dimen-2)=DU2orig(dimen-2)
2798 write(iout,*) "old gmatrix"
2799 call matout(dimen,dimen,2*nres,2*nres,matold)
2803 ! Find the ith eigenvector of the pentadiagonal inertiq matrix
2807 DML(j)=DMorig(j)-geigen(i)
2810 DML(j-1)=DMorig(j)-geigen(i)
2815 DDU1(imark-1)=DU2orig(imark-1)
2816 do j=imark+1,dimen-1
2817 DDU1(j-1)=DU1orig(j)
2825 DDU2(j)=DU2orig(j+1)
2834 write (iout,*) "DL2,DL1,DML,DDU1,DDU2"
2835 write(iout,'(10f10.5)') (DL2(k),k=3,dimen-1)
2836 write(iout,'(10f10.5)') (DL1(k),k=2,dimen-1)
2837 write(iout,'(10f10.5)') (DML(k),k=1,dimen-1)
2838 write(iout,'(10f10.5)') (DDU1(k),k=1,dimen-2)
2839 write(iout,'(10f10.5)') (DDU2(k),k=1,dimen-3)
2842 if (imark.gt.2) rs(imark-2)=-DU2orig(imark-2)
2843 if (imark.gt.1) rs(imark-1)=-DU1orig(imark-1)
2844 if (imark.lt.dimen) rs(imark)=-DU1orig(imark)
2845 if (imark.lt.dimen-1) rs(imark+1)=-DU2orig(imark)
2849 ! write (iout,*) "Vector rs"
2851 ! write (iout,*) j,rs(j)
2854 call FDIAG(dimen-1,DL2,DL1,DML,DDU1,DDU2,rs,xsolv,mark)
2861 sumx=-geigen(i)*xsolv(j)
2863 sumx=sumx+matold(j,k)*xsolv(k)
2866 sumx=sumx+matold(j,k)*xsolv(k-1)
2868 write(iout,'(i5,3f10.5)') j,sumx,rsold(j),sumx-rsold(j)
2871 sumx=-geigen(i)*xsolv(j-1)
2873 sumx=sumx+matold(j,k)*xsolv(k)
2876 sumx=sumx+matold(j,k)*xsolv(k-1)
2878 write(iout,'(i5,3f10.5)') j-1,sumx,rsold(j-1),sumx-rsold(j-1)
2882 "Solution of equations system",i," for eigenvalue",geigen(i)
2884 write(iout,'(i5,f10.5)') j,xsolv(j)
2887 do j=dimen-1,imark,-1
2892 write (iout,*) "Un-normalized eigenvector",i," for eigenvalue",geigen(i)
2894 write(iout,'(i5,f10.5)') j,xsolv(j)
2897 ! Normalize ith eigenvector
2900 sumx=sumx+xsolv(j)**2
2904 xsolv(j)=xsolv(j)/sumx
2907 write (iout,*) "Eigenvector",i," for eigenvalue",geigen(i)
2909 write(iout,'(i5,3f10.5)') j,xsolv(j)
2912 ! All done at this point for eigenvector i, exit loop
2920 write (iout,*) "Unable to find eigenvector",i
2923 ! write (iout,*) "i=",i
2925 ! write (iout,*) "k=",k
2928 ! write(iout,*) "ind",ind," ind1",3*(i-1)+k
2929 d_t_work(ind)=d_t_work(ind) &
2930 +xsolv(j)*d_t_work_new(3*(i-1)+k)
2933 enddo ! i (loop over the eigenvectors)
2936 write (iout,*) "d_t_work"
2938 write (iout,"(i5,f10.5)") i,d_t_work(i)
2943 ! if (itype(i,1).eq.10) then
2945 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
2946 iti=iabs(itype(i,mnum))
2947 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2948 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
2949 .or.(mnum.eq.5)) then
2956 ! write (iout,*) "k",k," ii+k",ii+k," ii+j+k",ii+j+k,"EK1",Ek1
2957 Ek1=Ek1+0.5d0*mp(mnum)*((d_t_work(ii+j+k)+d_t_work_new(ii+k))/2)**2+&
2958 0.5d0*0.25d0*IP(mnum)*(d_t_work(ii+j+k)-d_t_work_new(ii+k))**2
2961 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2962 .and.(mnum.ne.5)) ii=ii+3
2963 write (iout,*) "i",i," itype",itype(i,mnum)," mass",msc(itype(i,mnum),mnum)
2964 write (iout,*) "ii",ii
2967 write (iout,*) "k",k," ii",ii,"EK1",EK1
2968 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2970 Ek1=Ek1+0.5d0*Isc(iabs(itype(i,mnum)),mnum)*(d_t_work(ii)-d_t_work(ii-3))**2
2971 Ek1=Ek1+0.5d0*msc(iabs(itype(i,mnum)),mnum)*d_t_work(ii)**2
2973 write (iout,*) "i",i," ii",ii
2975 write (iout,*) "Ek from d_t_work",Ek1
2976 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2992 d_t(k,j)=d_t_work(ind)
2996 if (itype(j,1).ne.10 .and. itype(j,mnum).ne.ntyp1_molec(mnum)&
2997 .and.(mnum.ne.5)) then
2999 d_t(k,j+nres)=d_t_work(ind)
3005 write (iout,*) "Random velocities in the Calpha,SC space"
3007 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
3010 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
3017 ! if (itype(i,1).eq.10) then
3019 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
3020 .or.(mnum.eq.5)) then
3022 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
3026 d_t(j,i+nres)=d_t(j,i+nres)-d_t(j,i)
3027 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
3032 write (iout,*)"Random velocities in the virtual-bond-vector space"
3034 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
3037 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
3040 write (iout,*) "Ek from d_t_work",Ek1
3041 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
3049 d_t_work(ind)=d_t_work(ind) &
3050 +Gvec(i,j)*d_t_work_new((j-1)*3+k+1)
3052 ! write (iout,*) "i",i," ind",ind," d_t_work",d_t_work(ind)
3056 ! Transfer to the d_t vector
3058 d_t(j,0)=d_t_work(j)
3064 d_t(j,i)=d_t_work(ind)
3069 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3070 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3071 .and.(mnum.ne.5)) then
3074 d_t(j,i+nres)=d_t_work(ind)
3080 ! write (iout,*) "Kinetic energy",Ek,EK1," kinetic temperature",&
3081 ! 2.0d0/(dimen3*Rb)*EK,2.0d0/(dimen3*Rb)*EK1
3083 ! write(iout,*) "end init MD"
3085 end subroutine random_vel
3086 !-----------------------------------------------------------------------------
3088 subroutine sd_verlet_p_setup
3089 ! Sets up the parameters of stochastic Verlet algorithm
3090 ! implicit real*8 (a-h,o-z)
3091 ! include 'DIMENSIONS'
3092 use control, only: tcpu
3097 ! include 'COMMON.CONTROL'
3098 ! include 'COMMON.VAR'
3099 ! include 'COMMON.MD'
3101 ! include 'COMMON.LANGEVIN'
3103 ! include 'COMMON.LANGEVIN.lang0'
3105 ! include 'COMMON.CHAIN'
3106 ! include 'COMMON.DERIV'
3107 ! include 'COMMON.GEO'
3108 ! include 'COMMON.LOCAL'
3109 ! include 'COMMON.INTERACT'
3110 ! include 'COMMON.IOUNITS'
3111 ! include 'COMMON.NAMES'
3112 ! include 'COMMON.TIME1'
3113 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3114 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3115 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3116 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3117 logical :: lprn = .false.
3118 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3119 real(kind=8) :: ktm,gdt,egdt,gdt2,gdt3,gdt4,gdt5,gdt6,gdt7,gdt8,&
3121 integer :: i,maxres2
3128 ! AL 8/17/04 Code adapted from tinker
3130 ! Get the frictional and random terms for stochastic dynamics in the
3131 ! eigenspace of mass-scaled UNRES friction matrix
3135 gdt = fricgam(i) * d_time
3137 ! Stochastic dynamics reduces to simple MD for zero friction
3139 if (gdt .le. zero) then
3140 pfric_vec(i) = 1.0d0
3141 vfric_vec(i) = d_time
3142 afric_vec(i) = 0.5d0 * d_time * d_time
3143 prand_vec(i) = 0.0d0
3144 vrand_vec1(i) = 0.0d0
3145 vrand_vec2(i) = 0.0d0
3147 ! Analytical expressions when friction coefficient is large
3150 if (gdt .ge. gdt_radius) then
3153 vfric_vec(i) = (1.0d0-egdt) / fricgam(i)
3154 afric_vec(i) = (d_time-vfric_vec(i)) / fricgam(i)
3155 pterm = 2.0d0*gdt - 3.0d0 + (4.0d0-egdt)*egdt
3156 vterm = 1.0d0 - egdt**2
3157 rho = (1.0d0-egdt)**2 / sqrt(pterm*vterm)
3159 ! Use series expansions when friction coefficient is small
3170 afric_vec(i) = (gdt2/2.0d0 - gdt3/6.0d0 + gdt4/24.0d0 &
3171 - gdt5/120.0d0 + gdt6/720.0d0 &
3172 - gdt7/5040.0d0 + gdt8/40320.0d0 &
3173 - gdt9/362880.0d0) / fricgam(i)**2
3174 vfric_vec(i) = d_time - fricgam(i)*afric_vec(i)
3175 pfric_vec(i) = 1.0d0 - fricgam(i)*vfric_vec(i)
3176 pterm = 2.0d0*gdt3/3.0d0 - gdt4/2.0d0 &
3177 + 7.0d0*gdt5/30.0d0 - gdt6/12.0d0 &
3178 + 31.0d0*gdt7/1260.0d0 - gdt8/160.0d0 &
3179 + 127.0d0*gdt9/90720.0d0
3180 vterm = 2.0d0*gdt - 2.0d0*gdt2 + 4.0d0*gdt3/3.0d0 &
3181 - 2.0d0*gdt4/3.0d0 + 4.0d0*gdt5/15.0d0 &
3182 - 4.0d0*gdt6/45.0d0 + 8.0d0*gdt7/315.0d0 &
3183 - 2.0d0*gdt8/315.0d0 + 4.0d0*gdt9/2835.0d0
3184 rho = sqrt(3.0d0) * (0.5d0 - 3.0d0*gdt/16.0d0 &
3185 - 17.0d0*gdt2/1280.0d0 &
3186 + 17.0d0*gdt3/6144.0d0 &
3187 + 40967.0d0*gdt4/34406400.0d0 &
3188 - 57203.0d0*gdt5/275251200.0d0 &
3189 - 1429487.0d0*gdt6/13212057600.0d0)
3192 ! Compute the scaling factors of random terms for the nonzero friction case
3194 ktm = 0.5d0*d_time/fricgam(i)
3195 psig = dsqrt(ktm*pterm) / fricgam(i)
3196 vsig = dsqrt(ktm*vterm)
3197 rhoc = dsqrt(1.0d0 - rho*rho)
3199 vrand_vec1(i) = vsig * rho
3200 vrand_vec2(i) = vsig * rhoc
3205 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3208 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3209 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3213 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3216 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3217 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3218 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3219 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3220 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec1,vrand_mat1)
3221 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3224 t_sdsetup=t_sdsetup+MPI_Wtime()
3226 t_sdsetup=t_sdsetup+tcpu()-tt0
3229 end subroutine sd_verlet_p_setup
3230 !-----------------------------------------------------------------------------
3231 subroutine eigtransf1(n,ndim,ab,d,c)
3235 real(kind=8) :: ab(ndim,ndim,n),c(ndim,n),d(ndim)
3241 c(i,j)=c(i,j)+ab(k,j,i)*d(k)
3246 end subroutine eigtransf1
3247 !-----------------------------------------------------------------------------
3248 subroutine eigtransf(n,ndim,a,b,d,c)
3252 real(kind=8) :: a(ndim,n),b(ndim,n),c(ndim,n),d(ndim)
3258 c(i,j)=c(i,j)+a(i,k)*b(k,j)*d(k)
3263 end subroutine eigtransf
3264 !-----------------------------------------------------------------------------
3265 subroutine sd_verlet1
3267 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3269 ! implicit real*8 (a-h,o-z)
3270 ! include 'DIMENSIONS'
3271 ! include 'COMMON.CONTROL'
3272 ! include 'COMMON.VAR'
3273 ! include 'COMMON.MD'
3275 ! include 'COMMON.LANGEVIN'
3277 ! include 'COMMON.LANGEVIN.lang0'
3279 ! include 'COMMON.CHAIN'
3280 ! include 'COMMON.DERIV'
3281 ! include 'COMMON.GEO'
3282 ! include 'COMMON.LOCAL'
3283 ! include 'COMMON.INTERACT'
3284 ! include 'COMMON.IOUNITS'
3285 ! include 'COMMON.NAMES'
3286 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3287 !el common /stochcalc/ stochforcvec
3288 logical :: lprn = .false.
3289 real(kind=8) :: ddt1,ddt2
3290 integer :: i,j,ind,inres
3292 ! write (iout,*) "dc_old"
3294 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3295 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3298 dc_work(j)=dc_old(j,0)
3299 d_t_work(j)=d_t_old(j,0)
3300 d_a_work(j)=d_a_old(j,0)
3305 dc_work(ind+j)=dc_old(j,i)
3306 d_t_work(ind+j)=d_t_old(j,i)
3307 d_a_work(ind+j)=d_a_old(j,i)
3313 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3314 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3315 .and.(mnum.ne.5)) then
3317 dc_work(ind+j)=dc_old(j,i+nres)
3318 d_t_work(ind+j)=d_t_old(j,i+nres)
3319 d_a_work(ind+j)=d_a_old(j,i+nres)
3327 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3331 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3332 vfric_mat(i,j),afric_mat(i,j),&
3333 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3341 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3342 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3343 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3344 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3346 d_t_work_new(i)=ddt1+0.5d0*ddt2
3347 d_t_work(i)=ddt1+ddt2
3352 d_t(j,0)=d_t_work(j)
3357 dc(j,i)=dc_work(ind+j)
3358 d_t(j,i)=d_t_work(ind+j)
3364 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3365 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3366 .and.(mnum.ne.5)) then
3369 dc(j,inres)=dc_work(ind+j)
3370 d_t(j,inres)=d_t_work(ind+j)
3376 end subroutine sd_verlet1
3377 !-----------------------------------------------------------------------------
3378 subroutine sd_verlet2
3380 ! Calculating the adjusted velocities for accelerations
3382 ! implicit real*8 (a-h,o-z)
3383 ! include 'DIMENSIONS'
3384 ! include 'COMMON.CONTROL'
3385 ! include 'COMMON.VAR'
3386 ! include 'COMMON.MD'
3388 ! include 'COMMON.LANGEVIN'
3390 ! include 'COMMON.LANGEVIN.lang0'
3392 ! include 'COMMON.CHAIN'
3393 ! include 'COMMON.DERIV'
3394 ! include 'COMMON.GEO'
3395 ! include 'COMMON.LOCAL'
3396 ! include 'COMMON.INTERACT'
3397 ! include 'COMMON.IOUNITS'
3398 ! include 'COMMON.NAMES'
3399 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3400 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3401 !el common /stochcalc/ stochforcvec
3403 real(kind=8) :: ddt1,ddt2
3404 integer :: i,j,ind,inres
3405 ! Compute the stochastic forces which contribute to velocity change
3407 call stochastic_force(stochforcvecV)
3414 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3415 ddt2=ddt2+vrand_mat1(i,j)*stochforcvec(j)+ &
3416 vrand_mat2(i,j)*stochforcvecV(j)
3418 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3422 d_t(j,0)=d_t_work(j)
3427 d_t(j,i)=d_t_work(ind+j)
3433 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3434 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3435 .and.(mnum.ne.5)) then
3438 d_t(j,inres)=d_t_work(ind+j)
3444 end subroutine sd_verlet2
3445 !-----------------------------------------------------------------------------
3446 subroutine sd_verlet_ciccotti_setup
3448 ! Sets up the parameters of stochastic velocity Verlet algorithmi; Ciccotti's
3450 ! implicit real*8 (a-h,o-z)
3451 ! include 'DIMENSIONS'
3452 use control, only: tcpu
3457 ! include 'COMMON.CONTROL'
3458 ! include 'COMMON.VAR'
3459 ! include 'COMMON.MD'
3461 ! include 'COMMON.LANGEVIN'
3463 ! include 'COMMON.LANGEVIN.lang0'
3465 ! include 'COMMON.CHAIN'
3466 ! include 'COMMON.DERIV'
3467 ! include 'COMMON.GEO'
3468 ! include 'COMMON.LOCAL'
3469 ! include 'COMMON.INTERACT'
3470 ! include 'COMMON.IOUNITS'
3471 ! include 'COMMON.NAMES'
3472 ! include 'COMMON.TIME1'
3473 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3474 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3475 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3476 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3477 logical :: lprn = .false.
3478 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3479 real(kind=8) :: ktm,gdt,egdt,tt0
3480 integer :: i,maxres2
3487 ! AL 8/17/04 Code adapted from tinker
3489 ! Get the frictional and random terms for stochastic dynamics in the
3490 ! eigenspace of mass-scaled UNRES friction matrix
3494 write (iout,*) "i",i," fricgam",fricgam(i)
3495 gdt = fricgam(i) * d_time
3497 ! Stochastic dynamics reduces to simple MD for zero friction
3499 if (gdt .le. zero) then
3500 pfric_vec(i) = 1.0d0
3501 vfric_vec(i) = d_time
3502 afric_vec(i) = 0.5d0*d_time*d_time
3503 prand_vec(i) = afric_vec(i)
3504 vrand_vec2(i) = vfric_vec(i)
3506 ! Analytical expressions when friction coefficient is large
3511 vfric_vec(i) = dexp(-0.5d0*gdt)*d_time
3512 afric_vec(i) = 0.5d0*dexp(-0.25d0*gdt)*d_time*d_time
3513 prand_vec(i) = afric_vec(i)
3514 vrand_vec2(i) = vfric_vec(i)
3516 ! Compute the scaling factors of random terms for the nonzero friction case
3518 ! ktm = 0.5d0*d_time/fricgam(i)
3519 ! psig = dsqrt(ktm*pterm) / fricgam(i)
3520 ! vsig = dsqrt(ktm*vterm)
3521 ! prand_vec(i) = psig*afric_vec(i)
3522 ! vrand_vec2(i) = vsig*vfric_vec(i)
3527 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3530 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3531 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3535 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3537 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3538 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3539 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3540 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3541 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3543 t_sdsetup=t_sdsetup+MPI_Wtime()
3545 t_sdsetup=t_sdsetup+tcpu()-tt0
3548 end subroutine sd_verlet_ciccotti_setup
3549 !-----------------------------------------------------------------------------
3550 subroutine sd_verlet1_ciccotti
3552 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3553 ! implicit real*8 (a-h,o-z)
3555 ! include 'DIMENSIONS'
3559 ! include 'COMMON.CONTROL'
3560 ! include 'COMMON.VAR'
3561 ! include 'COMMON.MD'
3563 ! include 'COMMON.LANGEVIN'
3565 ! include 'COMMON.LANGEVIN.lang0'
3567 ! include 'COMMON.CHAIN'
3568 ! include 'COMMON.DERIV'
3569 ! include 'COMMON.GEO'
3570 ! include 'COMMON.LOCAL'
3571 ! include 'COMMON.INTERACT'
3572 ! include 'COMMON.IOUNITS'
3573 ! include 'COMMON.NAMES'
3574 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3575 !el common /stochcalc/ stochforcvec
3576 logical :: lprn = .false.
3577 real(kind=8) :: ddt1,ddt2
3578 integer :: i,j,ind,inres
3579 ! write (iout,*) "dc_old"
3581 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3582 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3585 dc_work(j)=dc_old(j,0)
3586 d_t_work(j)=d_t_old(j,0)
3587 d_a_work(j)=d_a_old(j,0)
3592 dc_work(ind+j)=dc_old(j,i)
3593 d_t_work(ind+j)=d_t_old(j,i)
3594 d_a_work(ind+j)=d_a_old(j,i)
3599 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3601 dc_work(ind+j)=dc_old(j,i+nres)
3602 d_t_work(ind+j)=d_t_old(j,i+nres)
3603 d_a_work(ind+j)=d_a_old(j,i+nres)
3612 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3616 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3617 vfric_mat(i,j),afric_mat(i,j),&
3618 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3626 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3627 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3628 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3629 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3631 d_t_work_new(i)=ddt1+0.5d0*ddt2
3632 d_t_work(i)=ddt1+ddt2
3637 d_t(j,0)=d_t_work(j)
3642 dc(j,i)=dc_work(ind+j)
3643 d_t(j,i)=d_t_work(ind+j)
3649 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3650 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3651 .and.(mnum.ne.5)) then
3654 dc(j,inres)=dc_work(ind+j)
3655 d_t(j,inres)=d_t_work(ind+j)
3661 end subroutine sd_verlet1_ciccotti
3662 !-----------------------------------------------------------------------------
3663 subroutine sd_verlet2_ciccotti
3665 ! Calculating the adjusted velocities for accelerations
3667 ! implicit real*8 (a-h,o-z)
3668 ! include 'DIMENSIONS'
3669 ! include 'COMMON.CONTROL'
3670 ! include 'COMMON.VAR'
3671 ! include 'COMMON.MD'
3673 ! include 'COMMON.LANGEVIN'
3675 ! include 'COMMON.LANGEVIN.lang0'
3677 ! include 'COMMON.CHAIN'
3678 ! include 'COMMON.DERIV'
3679 ! include 'COMMON.GEO'
3680 ! include 'COMMON.LOCAL'
3681 ! include 'COMMON.INTERACT'
3682 ! include 'COMMON.IOUNITS'
3683 ! include 'COMMON.NAMES'
3684 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3685 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3686 !el common /stochcalc/ stochforcvec
3687 real(kind=8) :: ddt1,ddt2
3688 integer :: i,j,ind,inres
3690 ! Compute the stochastic forces which contribute to velocity change
3692 call stochastic_force(stochforcvecV)
3699 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3700 ! ddt2=ddt2+vrand_mat2(i,j)*stochforcvecV(j)
3701 ddt2=ddt2+vrand_mat2(i,j)*stochforcvec(j)
3703 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3707 d_t(j,0)=d_t_work(j)
3712 d_t(j,i)=d_t_work(ind+j)
3718 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3720 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3723 d_t(j,inres)=d_t_work(ind+j)
3729 end subroutine sd_verlet2_ciccotti
3731 !-----------------------------------------------------------------------------
3733 !-----------------------------------------------------------------------------
3734 subroutine inertia_tensor
3736 ! Calculating the intertia tensor for the entire protein in order to
3737 ! remove the perpendicular components of velocity matrix which cause
3738 ! the molecule to rotate.
3741 ! implicit real*8 (a-h,o-z)
3742 ! include 'DIMENSIONS'
3743 ! include 'COMMON.CONTROL'
3744 ! include 'COMMON.VAR'
3745 ! include 'COMMON.MD'
3746 ! include 'COMMON.CHAIN'
3747 ! include 'COMMON.DERIV'
3748 ! include 'COMMON.GEO'
3749 ! include 'COMMON.LOCAL'
3750 ! include 'COMMON.INTERACT'
3751 ! include 'COMMON.IOUNITS'
3752 ! include 'COMMON.NAMES'
3754 real(kind=8),dimension(3,3) :: Im,Imcp,eigvec,Id
3755 real(kind=8),dimension(3) :: pr,eigval,L,vp,vrot
3756 real(kind=8) :: M_SC,mag,mag2,M_PEP
3757 real(kind=8),dimension(3,0:nres) :: vpp !(3,0:MAXRES)
3758 real(kind=8),dimension(3) :: vs_p,pp,incr,v
3759 real(kind=8),dimension(3,3) :: pr1,pr2
3761 !el common /gucio/ cm
3762 integer :: iti,inres,i,j,k,mnum
3773 ! calculating the center of the mass of the protein
3777 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3778 if (itype(i,mnum).eq.ntyp1_molec(mnum)) cycle
3779 M_PEP=M_PEP+mp(mnum)
3781 cm(j)=cm(j)+(c(j,i)+0.5d0*dc(j,i))*mp(mnum)
3790 if (mnum.eq.5) cycle
3791 iti=iabs(itype(i,mnum))
3792 M_SC=M_SC+msc(iabs(iti),mnum)
3795 cm(j)=cm(j)+msc(iabs(iti),mnum)*c(j,inres)
3799 cm(j)=cm(j)/(M_SC+M_PEP)
3804 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3806 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3808 Im(1,1)=Im(1,1)+mp(mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
3809 Im(1,2)=Im(1,2)-mp(mnum)*pr(1)*pr(2)
3810 Im(1,3)=Im(1,3)-mp(mnum)*pr(1)*pr(3)
3811 Im(2,3)=Im(2,3)-mp(mnum)*pr(2)*pr(3)
3812 Im(2,2)=Im(2,2)+mp(mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
3813 Im(3,3)=Im(3,3)+mp(mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
3818 iti=iabs(itype(i,mnum))
3819 if (mnum.eq.5) cycle
3822 pr(j)=c(j,inres)-cm(j)
3824 Im(1,1)=Im(1,1)+msc(iabs(iti),mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
3825 Im(1,2)=Im(1,2)-msc(iabs(iti),mnum)*pr(1)*pr(2)
3826 Im(1,3)=Im(1,3)-msc(iabs(iti),mnum)*pr(1)*pr(3)
3827 Im(2,3)=Im(2,3)-msc(iabs(iti),mnum)*pr(2)*pr(3)
3828 Im(2,2)=Im(2,2)+msc(iabs(iti),mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
3829 Im(3,3)=Im(3,3)+msc(iabs(iti),mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
3834 Im(1,1)=Im(1,1)+Ip(mnum)*(1-dc_norm(1,i)*dc_norm(1,i))* &
3835 vbld(i+1)*vbld(i+1)*0.25d0
3836 Im(1,2)=Im(1,2)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(2,i))* &
3837 vbld(i+1)*vbld(i+1)*0.25d0
3838 Im(1,3)=Im(1,3)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(3,i))* &
3839 vbld(i+1)*vbld(i+1)*0.25d0
3840 Im(2,3)=Im(2,3)+Ip(mnum)*(-dc_norm(2,i)*dc_norm(3,i))* &
3841 vbld(i+1)*vbld(i+1)*0.25d0
3842 Im(2,2)=Im(2,2)+Ip(mnum)*(1-dc_norm(2,i)*dc_norm(2,i))* &
3843 vbld(i+1)*vbld(i+1)*0.25d0
3844 Im(3,3)=Im(3,3)+Ip(mnum)*(1-dc_norm(3,i)*dc_norm(3,i))* &
3845 vbld(i+1)*vbld(i+1)*0.25d0
3851 ! if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
3852 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3853 .and.(mnum.ne.5)) then
3854 iti=iabs(itype(i,mnum))
3856 Im(1,1)=Im(1,1)+Isc(iti,mnum)*(1-dc_norm(1,inres)* &
3857 dc_norm(1,inres))*vbld(inres)*vbld(inres)
3858 Im(1,2)=Im(1,2)-Isc(iti,mnum)*(dc_norm(1,inres)* &
3859 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3860 Im(1,3)=Im(1,3)-Isc(iti,mnum)*(dc_norm(1,inres)* &
3861 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3862 Im(2,3)=Im(2,3)-Isc(iti,mnum)*(dc_norm(2,inres)* &
3863 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3864 Im(2,2)=Im(2,2)+Isc(iti,mnum)*(1-dc_norm(2,inres)* &
3865 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3866 Im(3,3)=Im(3,3)+Isc(iti,mnum)*(1-dc_norm(3,inres)* &
3867 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3872 ! write(iout,*) "The angular momentum before adjustment:"
3873 ! write(iout,*) (L(j),j=1,3)
3879 ! Copying the Im matrix for the djacob subroutine
3887 ! Finding the eigenvectors and eignvalues of the inertia tensor
3888 call djacob(3,3,10000,1.0d-10,Imcp,eigvec,eigval)
3889 ! write (iout,*) "Eigenvalues & Eigenvectors"
3890 ! write (iout,'(5x,3f10.5)') (eigval(i),i=1,3)
3893 ! write (iout,'(i5,3f10.5)') i,(eigvec(i,j),j=1,3)
3895 ! Constructing the diagonalized matrix
3897 if (dabs(eigval(i)).gt.1.0d-15) then
3898 Id(i,i)=1.0d0/eigval(i)
3905 Imcp(i,j)=eigvec(j,i)
3911 pr1(i,j)=pr1(i,j)+Id(i,k)*Imcp(k,j)
3918 pr2(i,j)=pr2(i,j)+eigvec(i,k)*pr1(k,j)
3922 ! Calculating the total rotational velocity of the molecule
3925 vrot(i)=vrot(i)+pr2(i,j)*L(j)
3928 ! Resetting the velocities
3930 call vecpr(vrot(1),dc(1,i),vp)
3932 d_t(j,i)=d_t(j,i)-vp(j)
3937 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3938 .and.(mnum.ne.5)) then
3939 ! if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
3940 ! if(itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3942 call vecpr(vrot(1),dc(1,inres),vp)
3944 d_t(j,inres)=d_t(j,inres)-vp(j)
3949 ! write(iout,*) "The angular momentum after adjustment:"
3950 ! write(iout,*) (L(j),j=1,3)
3953 end subroutine inertia_tensor
3954 !-----------------------------------------------------------------------------
3955 subroutine angmom(cm,L)
3958 ! implicit real*8 (a-h,o-z)
3959 ! include 'DIMENSIONS'
3960 ! include 'COMMON.CONTROL'
3961 ! include 'COMMON.VAR'
3962 ! include 'COMMON.MD'
3963 ! include 'COMMON.CHAIN'
3964 ! include 'COMMON.DERIV'
3965 ! include 'COMMON.GEO'
3966 ! include 'COMMON.LOCAL'
3967 ! include 'COMMON.INTERACT'
3968 ! include 'COMMON.IOUNITS'
3969 ! include 'COMMON.NAMES'
3970 real(kind=8) :: mscab
3971 real(kind=8),dimension(3) :: L,cm,pr,vp,vrot,incr,v,pp
3972 integer :: iti,inres,i,j,mnum
3973 ! Calculate the angular momentum
3982 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3984 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3987 v(j)=incr(j)+0.5d0*d_t(j,i)
3990 incr(j)=incr(j)+d_t(j,i)
3992 call vecpr(pr(1),v(1),vp)
3994 L(j)=L(j)+mp(mnum)*vp(j)
3998 pp(j)=0.5d0*d_t(j,i)
4000 call vecpr(pr(1),pp(1),vp)
4002 L(j)=L(j)+Ip(mnum)*vp(j)
4010 iti=iabs(itype(i,mnum))
4018 pr(j)=c(j,inres)-cm(j)
4020 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4021 .and.(mnum.ne.5)) then
4023 v(j)=incr(j)+d_t(j,inres)
4030 call vecpr(pr(1),v(1),vp)
4031 ! write (iout,*) "i",i," iti",iti," pr",(pr(j),j=1,3),&
4032 ! " v",(v(j),j=1,3)," vp",(vp(j),j=1,3)
4034 L(j)=L(j)+mscab*vp(j)
4036 ! write (iout,*) "L",(l(j),j=1,3)
4037 if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4038 .and.(mnum.ne.5)) then
4040 v(j)=incr(j)+d_t(j,inres)
4042 call vecpr(dc(1,inres),d_t(1,inres),vp)
4044 L(j)=L(j)+Isc(iti,mnum)*vp(j)
4048 incr(j)=incr(j)+d_t(j,i)
4052 end subroutine angmom
4053 !-----------------------------------------------------------------------------
4054 subroutine vcm_vel(vcm)
4057 ! implicit real*8 (a-h,o-z)
4058 ! include 'DIMENSIONS'
4059 ! include 'COMMON.VAR'
4060 ! include 'COMMON.MD'
4061 ! include 'COMMON.CHAIN'
4062 ! include 'COMMON.DERIV'
4063 ! include 'COMMON.GEO'
4064 ! include 'COMMON.LOCAL'
4065 ! include 'COMMON.INTERACT'
4066 ! include 'COMMON.IOUNITS'
4067 real(kind=8),dimension(3) :: vcm,vv
4068 real(kind=8) :: summas,amas
4078 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
4080 summas=summas+mp(mnum)
4082 vcm(j)=vcm(j)+mp(mnum)*(vv(j)+0.5d0*d_t(j,i))
4086 amas=msc(iabs(itype(i,mnum)),mnum)
4091 if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4092 .and.(mnum.ne.5)) then
4094 vcm(j)=vcm(j)+amas*(vv(j)+d_t(j,i+nres))
4098 vcm(j)=vcm(j)+amas*vv(j)
4102 vv(j)=vv(j)+d_t(j,i)
4105 ! write (iout,*) "vcm",(vcm(j),j=1,3)," summas",summas
4107 vcm(j)=vcm(j)/summas
4110 end subroutine vcm_vel
4111 !-----------------------------------------------------------------------------
4113 !-----------------------------------------------------------------------------
4115 ! RATTLE algorithm for velocity Verlet - step 1, UNRES
4119 ! implicit real*8 (a-h,o-z)
4120 ! include 'DIMENSIONS'
4122 ! include 'COMMON.CONTROL'
4123 ! include 'COMMON.VAR'
4124 ! include 'COMMON.MD'
4126 ! include 'COMMON.LANGEVIN'
4128 ! include 'COMMON.LANGEVIN.lang0'
4130 ! include 'COMMON.CHAIN'
4131 ! include 'COMMON.DERIV'
4132 ! include 'COMMON.GEO'
4133 ! include 'COMMON.LOCAL'
4134 ! include 'COMMON.INTERACT'
4135 ! include 'COMMON.IOUNITS'
4136 ! include 'COMMON.NAMES'
4137 ! include 'COMMON.TIME1'
4138 !el real(kind=8) :: gginv(2*nres,2*nres),&
4139 !el gdc(3,2*nres,2*nres)
4140 real(kind=8) :: dC_uncor(3,2*nres) !,&
4141 !el real(kind=8) :: Cmat(2*nres,2*nres)
4142 real(kind=8) :: x(2*nres),xcorr(3,2*nres) !maxres2=2*maxres
4143 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4144 !el common /przechowalnia/ nbond
4145 integer :: max_rattle = 5
4146 logical :: lprn = .false., lprn1 = .false., not_done
4147 real(kind=8) :: tol_rattle = 1.0d-5
4149 integer :: ii,i,j,jj,l,ind,ind1,nres2
4152 !el /common/ przechowalnia
4154 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4155 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4156 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4158 if (lprn) write (iout,*) "RATTLE1"
4162 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4163 .and.(mnum.ne.5)) nbond=nbond+1
4165 ! Make a folded form of the Ginv-matrix
4178 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4183 if (itype(k,1).ne.10 .and. itype(k,mnum).ne.ntyp1_molec(mnum)&
4184 .and.(mnum.ne.5)) then
4188 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4196 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4207 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4211 if (itype(k,1).ne.10) then
4215 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4223 write (iout,*) "Matrix GGinv"
4224 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4230 if (iter.gt.max_rattle) then
4231 write (iout,*) "Error - too many iterations in RATTLE."
4234 ! Calculate the matrix C = GG**(-1) dC_old o dC
4239 dC_uncor(j,ind1)=dC(j,i)
4243 if (itype(i,1).ne.10) then
4246 dC_uncor(j,ind1)=dC(j,i+nres)
4255 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4259 if (itype(k,1).ne.10) then
4262 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4267 ! Calculate deviations from standard virtual-bond lengths
4271 x(ind)=vbld(i+1)**2-vbl**2
4274 if (itype(i,1).ne.10) then
4276 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4280 write (iout,*) "Coordinates and violations"
4282 write(iout,'(i5,3f10.5,5x,e15.5)') &
4283 i,(dC_uncor(j,i),j=1,3),x(i)
4285 write (iout,*) "Velocities and violations"
4289 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4290 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4294 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4295 .and.(mnum.ne.5)) then
4298 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4299 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4300 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4303 ! write (iout,*) "gdc"
4305 ! write (iout,*) "i",i
4307 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4313 if (dabs(x(i)).gt.xmax) then
4317 if (xmax.lt.tol_rattle) then
4321 ! Calculate the matrix of the system of equations
4326 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4331 write (iout,*) "Matrix Cmat"
4332 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4334 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4335 ! Add constraint term to positions
4342 xx = xx+x(ii)*gdc(j,ind,ii)
4346 d_t_new(j,i)=d_t_new(j,i)-xx/d_time
4350 if (itype(i,1).ne.10) then
4355 xx = xx+x(ii)*gdc(j,ind,ii)
4358 dC(j,i+nres)=dC(j,i+nres)-xx
4359 d_t_new(j,i+nres)=d_t_new(j,i+nres)-xx/d_time
4363 ! Rebuild the chain using the new coordinates
4364 call chainbuild_cart
4366 write (iout,*) "New coordinates, Lagrange multipliers,",&
4367 " and differences between actual and standard bond lengths"
4371 xx=vbld(i+1)**2-vbl**2
4372 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4373 i,(dC(j,i),j=1,3),x(ind),xx
4377 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4380 xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4381 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4382 i,(dC(j,i+nres),j=1,3),x(ind),xx
4385 write (iout,*) "Velocities and violations"
4389 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4390 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4393 if (itype(i,1).ne.10) then
4395 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4396 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4397 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4404 10 write (iout,*) "Error - singularity in solving the system",&
4405 " of equations for Lagrange multipliers."
4409 "RATTLE inactive; use -DRATTLE switch at compile time."
4412 end subroutine rattle1
4413 !-----------------------------------------------------------------------------
4415 ! RATTLE algorithm for velocity Verlet - step 2, UNRES
4419 ! implicit real*8 (a-h,o-z)
4420 ! include 'DIMENSIONS'
4422 ! include 'COMMON.CONTROL'
4423 ! include 'COMMON.VAR'
4424 ! include 'COMMON.MD'
4426 ! include 'COMMON.LANGEVIN'
4428 ! include 'COMMON.LANGEVIN.lang0'
4430 ! include 'COMMON.CHAIN'
4431 ! include 'COMMON.DERIV'
4432 ! include 'COMMON.GEO'
4433 ! include 'COMMON.LOCAL'
4434 ! include 'COMMON.INTERACT'
4435 ! include 'COMMON.IOUNITS'
4436 ! include 'COMMON.NAMES'
4437 ! include 'COMMON.TIME1'
4438 !el real(kind=8) :: gginv(2*nres,2*nres),&
4439 !el gdc(3,2*nres,2*nres)
4440 real(kind=8) :: dC_uncor(3,2*nres) !,&
4441 !el Cmat(2*nres,2*nres)
4442 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4443 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4444 !el common /przechowalnia/ nbond
4445 integer :: max_rattle = 5
4446 logical :: lprn = .false., lprn1 = .false., not_done
4447 real(kind=8) :: tol_rattle = 1.0d-5
4451 !el /common/ przechowalnia
4452 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4453 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4454 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4456 if (lprn) write (iout,*) "RATTLE2"
4457 if (lprn) write (iout,*) "Velocity correction"
4458 ! Calculate the matrix G dC
4464 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k)
4469 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4470 .and.(mnum.ne.5)) then
4473 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k+nres)
4479 ! write (iout,*) "gdc"
4481 ! write (iout,*) "i",i
4483 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4487 ! Calculate the matrix of the system of equations
4494 Cmat(ind,j)=Cmat(ind,j)+dC(k,i)*gdc(k,ind,j)
4500 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4501 .and.(mnum.ne.5)) then
4506 Cmat(ind,j)=Cmat(ind,j)+dC(k,i+nres)*gdc(k,ind,j)
4511 ! Calculate the scalar product dC o d_t_new
4515 x(ind)=scalar(d_t(1,i),dC(1,i))
4519 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4520 .and.(mnum.ne.5)) then
4522 x(ind)=scalar(d_t(1,i+nres),dC(1,i+nres))
4526 write (iout,*) "Velocities and violations"
4530 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4531 i,ind,(d_t(j,i),j=1,3),x(ind)
4535 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4536 .and.(mnum.ne.5)) then
4538 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4539 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind)
4545 if (dabs(x(i)).gt.xmax) then
4549 if (xmax.lt.tol_rattle) then
4554 write (iout,*) "Matrix Cmat"
4555 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4557 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4558 ! Add constraint term to velocities
4565 xx = xx+x(ii)*gdc(j,ind,ii)
4567 d_t(j,i)=d_t(j,i)-xx
4572 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4573 .and.(mnum.ne.5)) then
4578 xx = xx+x(ii)*gdc(j,ind,ii)
4580 d_t(j,i+nres)=d_t(j,i+nres)-xx
4586 "New velocities, Lagrange multipliers violations"
4590 if (lprn) write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4591 i,ind,(d_t(j,i),j=1,3),x(ind),scalar(d_t(1,i),dC(1,i))
4595 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4598 write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4599 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind),&
4600 scalar(d_t(1,i+nres),dC(1,i+nres))
4606 10 write (iout,*) "Error - singularity in solving the system",&
4607 " of equations for Lagrange multipliers."
4611 "RATTLE inactive; use -DRATTLE option at compile time."
4614 end subroutine rattle2
4615 !-----------------------------------------------------------------------------
4616 subroutine rattle_brown
4617 ! RATTLE/LINCS algorithm for Brownian dynamics, UNRES
4621 ! implicit real*8 (a-h,o-z)
4622 ! include 'DIMENSIONS'
4624 ! include 'COMMON.CONTROL'
4625 ! include 'COMMON.VAR'
4626 ! include 'COMMON.MD'
4628 ! include 'COMMON.LANGEVIN'
4630 ! include 'COMMON.LANGEVIN.lang0'
4632 ! include 'COMMON.CHAIN'
4633 ! include 'COMMON.DERIV'
4634 ! include 'COMMON.GEO'
4635 ! include 'COMMON.LOCAL'
4636 ! include 'COMMON.INTERACT'
4637 ! include 'COMMON.IOUNITS'
4638 ! include 'COMMON.NAMES'
4639 ! include 'COMMON.TIME1'
4640 !el real(kind=8) :: gginv(2*nres,2*nres),&
4641 !el gdc(3,2*nres,2*nres)
4642 real(kind=8) :: dC_uncor(3,2*nres) !,&
4643 !el real(kind=8) :: Cmat(2*nres,2*nres)
4644 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4645 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4646 !el common /przechowalnia/ nbond
4647 integer :: max_rattle = 5
4648 logical :: lprn = .false., lprn1 = .false., not_done
4649 real(kind=8) :: tol_rattle = 1.0d-5
4653 !el /common/ przechowalnia
4654 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4655 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4656 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4659 if (lprn) write (iout,*) "RATTLE_BROWN"
4662 if (itype(i,1).ne.10) nbond=nbond+1
4664 ! Make a folded form of the Ginv-matrix
4677 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4681 if (itype(k,1).ne.10) then
4685 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4692 if (itype(i,1).ne.10) then
4702 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4706 if (itype(k,1).ne.10) then
4710 if (j.eq.1 .and. l.eq.1)GGinv(ii,jj)=fricmat(ind,ind1)
4718 write (iout,*) "Matrix GGinv"
4719 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4725 if (iter.gt.max_rattle) then
4726 write (iout,*) "Error - too many iterations in RATTLE."
4729 ! Calculate the matrix C = GG**(-1) dC_old o dC
4734 dC_uncor(j,ind1)=dC(j,i)
4738 if (itype(i,1).ne.10) then
4741 dC_uncor(j,ind1)=dC(j,i+nres)
4750 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4754 if (itype(k,1).ne.10) then
4757 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4762 ! Calculate deviations from standard virtual-bond lengths
4766 x(ind)=vbld(i+1)**2-vbl**2
4769 if (itype(i,1).ne.10) then
4771 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4775 write (iout,*) "Coordinates and violations"
4777 write(iout,'(i5,3f10.5,5x,e15.5)') &
4778 i,(dC_uncor(j,i),j=1,3),x(i)
4780 write (iout,*) "Velocities and violations"
4784 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4785 i,ind,(d_t(j,i),j=1,3),scalar(d_t(1,i),dC_old(1,i))
4788 if (itype(i,1).ne.10) then
4790 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4791 i+nres,ind,(d_t(j,i+nres),j=1,3),&
4792 scalar(d_t(1,i+nres),dC_old(1,i+nres))
4795 write (iout,*) "gdc"
4797 write (iout,*) "i",i
4799 write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4805 if (dabs(x(i)).gt.xmax) then
4809 if (xmax.lt.tol_rattle) then
4813 ! Calculate the matrix of the system of equations
4818 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4823 write (iout,*) "Matrix Cmat"
4824 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4826 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4827 ! Add constraint term to positions
4834 xx = xx+x(ii)*gdc(j,ind,ii)
4837 d_t(j,i)=d_t(j,i)+xx/d_time
4842 if (itype(i,1).ne.10) then
4847 xx = xx+x(ii)*gdc(j,ind,ii)
4850 d_t(j,i+nres)=d_t(j,i+nres)+xx/d_time
4851 dC(j,i+nres)=dC(j,i+nres)+xx
4855 ! Rebuild the chain using the new coordinates
4856 call chainbuild_cart
4858 write (iout,*) "New coordinates, Lagrange multipliers,",&
4859 " and differences between actual and standard bond lengths"
4863 xx=vbld(i+1)**2-vbl**2
4864 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4865 i,(dC(j,i),j=1,3),x(ind),xx
4868 if (itype(i,1).ne.10) then
4870 xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4871 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4872 i,(dC(j,i+nres),j=1,3),x(ind),xx
4875 write (iout,*) "Velocities and violations"
4879 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4880 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4883 if (itype(i,1).ne.10) then
4885 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4886 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4887 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4894 10 write (iout,*) "Error - singularity in solving the system",&
4895 " of equations for Lagrange multipliers."
4899 "RATTLE inactive; use -DRATTLE option at compile time"
4902 end subroutine rattle_brown
4903 !-----------------------------------------------------------------------------
4905 !-----------------------------------------------------------------------------
4906 subroutine friction_force
4911 ! implicit real*8 (a-h,o-z)
4912 ! include 'DIMENSIONS'
4913 ! include 'COMMON.VAR'
4914 ! include 'COMMON.CHAIN'
4915 ! include 'COMMON.DERIV'
4916 ! include 'COMMON.GEO'
4917 ! include 'COMMON.LOCAL'
4918 ! include 'COMMON.INTERACT'
4919 ! include 'COMMON.MD'
4921 ! include 'COMMON.LANGEVIN'
4923 ! include 'COMMON.LANGEVIN.lang0'
4925 ! include 'COMMON.IOUNITS'
4926 !el real(kind=8),dimension(6*nres) :: gamvec !(MAXRES6) maxres6=6*maxres
4927 !el common /syfek/ gamvec
4928 real(kind=8) :: vv(3),vvtot(3,nres),v_work(6*nres) !,&
4929 !el ginvfric(2*nres,2*nres) !maxres2=2*maxres
4930 !el common /przechowalnia/ ginvfric
4932 logical :: lprn = .false., checkmode = .false.
4933 integer :: i,j,ind,k,nres2,nres6,mnum
4937 if(.not.allocated(gamvec)) allocate(gamvec(nres6)) !(MAXRES6)
4938 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
4946 d_t_work(j)=d_t(j,0)
4951 d_t_work(ind+j)=d_t(j,i)
4957 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
4958 .and.(mnum.ne.5)) then
4960 d_t_work(ind+j)=d_t(j,i+nres)
4966 call fricmat_mult(d_t_work,fric_work)
4968 if (.not.checkmode) return
4971 write (iout,*) "d_t_work and fric_work"
4973 write (iout,'(i3,2e15.5)') i,d_t_work(i),fric_work(i)
4977 friction(j,0)=fric_work(j)
4982 friction(j,i)=fric_work(ind+j)
4988 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
4989 .and.(mnum.ne.5)) then
4990 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
4992 friction(j,i+nres)=fric_work(ind+j)
4998 write(iout,*) "Friction backbone"
5000 write(iout,'(i5,3e15.5,5x,3e15.5)') &
5001 i,(friction(j,i),j=1,3),(d_t(j,i),j=1,3)
5003 write(iout,*) "Friction side chain"
5005 write(iout,'(i5,3e15.5,5x,3e15.5)') &
5006 i,(friction(j,i+nres),j=1,3),(d_t(j,i+nres),j=1,3)
5015 vvtot(j,i)=vv(j)+0.5d0*d_t(j,i)
5016 vvtot(j,i+nres)=vv(j)+d_t(j,i+nres)
5017 vv(j)=vv(j)+d_t(j,i)
5020 write (iout,*) "vvtot backbone and sidechain"
5022 write (iout,'(i5,3e15.5,5x,3e15.5)') i,(vvtot(j,i),j=1,3),&
5023 (vvtot(j,i+nres),j=1,3)
5028 v_work(ind+j)=vvtot(j,i)
5034 v_work(ind+j)=vvtot(j,i+nres)
5038 write (iout,*) "v_work gamvec and site-based friction forces"
5040 write (iout,'(i5,3e15.5)') i,v_work(i),gamvec(i),&
5044 ! fric_work1(i)=0.0d0
5046 ! fric_work1(i)=fric_work1(i)-A(j,i)*gamvec(j)*v_work(j)
5049 ! write (iout,*) "fric_work and fric_work1"
5051 ! write (iout,'(i5,2e15.5)') i,fric_work(i),fric_work1(i)
5057 ginvfric(i,j)=ginvfric(i,j)+ginv(i,k)*fricmat(k,j)
5061 write (iout,*) "ginvfric"
5063 write (iout,'(i5,100f8.3)') i,(ginvfric(i,j),j=1,dimen)
5065 write (iout,*) "symmetry check"
5068 write (iout,*) i,j,ginvfric(i,j)-ginvfric(j,i)
5073 end subroutine friction_force
5074 !-----------------------------------------------------------------------------
5075 subroutine setup_fricmat
5079 use control_data, only:time_Bcast
5080 use control, only:tcpu
5082 ! implicit real*8 (a-h,o-z)
5086 real(kind=8) :: time00
5088 ! include 'DIMENSIONS'
5089 ! include 'COMMON.VAR'
5090 ! include 'COMMON.CHAIN'
5091 ! include 'COMMON.DERIV'
5092 ! include 'COMMON.GEO'
5093 ! include 'COMMON.LOCAL'
5094 ! include 'COMMON.INTERACT'
5095 ! include 'COMMON.MD'
5096 ! include 'COMMON.SETUP'
5097 ! include 'COMMON.TIME1'
5098 ! integer licznik /0/
5101 ! include 'COMMON.LANGEVIN'
5103 ! include 'COMMON.LANGEVIN.lang0'
5105 ! include 'COMMON.IOUNITS'
5107 integer :: i,j,ind,ind1,m
5108 logical :: lprn = .false.
5109 real(kind=8) :: dtdi !el ,gamvec(2*nres)
5110 !el real(kind=8),dimension(2*nres,2*nres) :: ginvfric,fcopy
5111 ! real(kind=8),allocatable,dimension(:,:) :: fcopy
5112 !el real(kind=8),dimension(2*nres*(2*nres+1)/2) :: Ghalf !(mmaxres2) (mmaxres2=(maxres2*(maxres2+1)/2))
5113 !el common /syfek/ gamvec
5114 real(kind=8) :: work(8*2*nres)
5115 integer :: iwork(2*nres)
5116 !el common /przechowalnia/ ginvfric,Ghalf,fcopy
5117 integer :: ii,iti,k,l,nzero,nres2,nres6,ierr,mnum
5121 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5122 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5123 if (fg_rank.ne.king) goto 10
5128 if(.not.allocated(gamvec)) allocate(gamvec(nres2)) !(MAXRES2)
5129 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
5130 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5131 !el allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5132 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !maxres2=2*maxres
5134 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5135 ! Zeroing out fricmat
5141 ! Load the friction coefficients corresponding to peptide groups
5146 gamvec(ind1)=gamp(mnum)
5148 ! Load the friction coefficients corresponding to side chains
5152 gamsc(ntyp1_molec(j),j)=1.0d0
5159 gamvec(ii)=gamsc(iabs(iti),mnum)
5161 if (surfarea) call sdarea(gamvec)
5163 ! write (iout,*) "Matrix A and vector gamma"
5165 ! write (iout,'(i2,$)') i
5167 ! write (iout,'(f4.1,$)') A(i,j)
5169 ! write (iout,'(f8.3)') gamvec(i)
5173 write (iout,*) "Vector gamvec"
5175 write (iout,'(i5,f10.5)') i, gamvec(i)
5179 ! The friction matrix
5184 dtdi=dtdi+A(j,k)*A(j,i)*gamvec(j)
5191 write (iout,'(//a)') "Matrix fricmat"
5192 call matout2(dimen,dimen,nres2,nres2,fricmat)
5194 if (lang.eq.2 .or. lang.eq.3) then
5195 ! Mass-scale the friction matrix if non-direct integration will be performed
5201 Ginvfric(i,j)=Ginvfric(i,j)+ &
5202 Gsqrm(i,k)*Gsqrm(l,j)*fricmat(k,l)
5207 ! Diagonalize the friction matrix
5212 Ghalf(ind)=Ginvfric(i,j)
5215 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5218 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5219 " mass-scaled friction matrix"
5220 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5222 ! Precompute matrices for tinker stochastic integrator
5229 mt1(i,j)=mt1(i,j)+fricvec(k,i)*gsqrm(k,j)
5230 mt2(i,j)=mt2(i,j)+fricvec(k,i)*gsqrp(k,j)
5236 else if (lang.eq.4) then
5237 ! Diagonalize the friction matrix
5242 Ghalf(ind)=fricmat(i,j)
5245 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5248 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5250 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5252 ! Determine the number of zero eigenvalues of the friction matrix
5253 nzero=max0(dimen-dimen1,0)
5254 ! do while (fricgam(nzero+1).le.1.0d-5 .and. nzero.lt.dimen)
5257 write (iout,*) "Number of zero eigenvalues:",nzero
5262 fricmat(i,j)=fricmat(i,j) &
5263 +fricvec(i,k)*fricvec(j,k)/fricgam(k)
5268 write (iout,'(//a)') "Generalized inverse of fricmat"
5269 call matout(dimen,dimen,nres6,nres6,fricmat)
5274 if (nfgtasks.gt.1) then
5275 if (fg_rank.eq.0) then
5276 ! The matching BROADCAST for fg processors is called in ERGASTULUM
5282 call MPI_Bcast(10,1,MPI_INTEGER,king,FG_COMM,IERROR)
5284 time_Bcast=time_Bcast+MPI_Wtime()-time00
5286 time_Bcast=time_Bcast+tcpu()-time00
5288 ! print *,"Processor",myrank,
5289 ! & " BROADCAST iorder in SETUP_FRICMAT"
5292 write (iout,*) "setup_fricmat licznik"!,licznik !sp
5298 ! Scatter the friction matrix
5299 call MPI_Scatterv(fricmat(1,1),nginv_counts(0),&
5300 nginv_start(0),MPI_DOUBLE_PRECISION,fcopy(1,1),&
5301 myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
5304 time_scatter=time_scatter+MPI_Wtime()-time00
5305 time_scatter_fmat=time_scatter_fmat+MPI_Wtime()-time00
5307 time_scatter=time_scatter+tcpu()-time00
5308 time_scatter_fmat=time_scatter_fmat+tcpu()-time00
5312 do j=1,2*my_ng_count
5313 fricmat(j,i)=fcopy(i,j)
5316 ! write (iout,*) "My chunk of fricmat"
5317 ! call MATOUT2(my_ng_count,dimen,maxres2,maxres2,fcopy)
5321 end subroutine setup_fricmat
5322 !-----------------------------------------------------------------------------
5323 subroutine stochastic_force(stochforcvec)
5326 use random, only:anorm_distr
5327 ! implicit real*8 (a-h,o-z)
5328 ! include 'DIMENSIONS'
5329 use control, only: tcpu
5334 ! include 'COMMON.VAR'
5335 ! include 'COMMON.CHAIN'
5336 ! include 'COMMON.DERIV'
5337 ! include 'COMMON.GEO'
5338 ! include 'COMMON.LOCAL'
5339 ! include 'COMMON.INTERACT'
5340 ! include 'COMMON.MD'
5341 ! include 'COMMON.TIME1'
5343 ! include 'COMMON.LANGEVIN'
5345 ! include 'COMMON.LANGEVIN.lang0'
5347 ! include 'COMMON.IOUNITS'
5349 real(kind=8) :: x,sig,lowb,highb
5350 real(kind=8) :: ff(3),force(3,0:2*nres),zeta2,lowb2
5351 real(kind=8) :: highb2,sig2,forcvec(6*nres),stochforcvec(6*nres)
5352 real(kind=8) :: time00
5353 logical :: lprn = .false.
5354 integer :: i,j,ind,mnum
5358 stochforc(j,i)=0.0d0
5368 ! Compute the stochastic forces acting on bodies. Store in force.
5374 force(j,i)=anorm_distr(x,sig,lowb,highb)
5382 force(j,i+nres)=anorm_distr(x,sig2,lowb2,highb2)
5386 time_fsample=time_fsample+MPI_Wtime()-time00
5388 time_fsample=time_fsample+tcpu()-time00
5390 ! Compute the stochastic forces acting on virtual-bond vectors.
5396 stochforc(j,i)=ff(j)+0.5d0*force(j,i)
5399 ff(j)=ff(j)+force(j,i)
5401 ! if (itype(i+1,1).ne.ntyp1) then
5403 if (itype(i+1,mnum).ne.ntyp1_molec(mnum)) then
5405 stochforc(j,i)=stochforc(j,i)+force(j,i+nres+1)
5406 ff(j)=ff(j)+force(j,i+nres+1)
5411 stochforc(j,0)=ff(j)+force(j,nnt+nres)
5415 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5416 .and.(mnum.ne.5)) then
5417 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5419 stochforc(j,i+nres)=force(j,i+nres)
5425 stochforcvec(j)=stochforc(j,0)
5430 stochforcvec(ind+j)=stochforc(j,i)
5436 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5437 .and.(mnum.ne.5)) then
5438 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5440 stochforcvec(ind+j)=stochforc(j,i+nres)
5446 write (iout,*) "stochforcvec"
5448 write(iout,'(i5,e15.5)') i,stochforcvec(i)
5450 write(iout,*) "Stochastic forces backbone"
5452 write(iout,'(i5,3e15.5)') i,(stochforc(j,i),j=1,3)
5454 write(iout,*) "Stochastic forces side chain"
5456 write(iout,'(i5,3e15.5)') &
5457 i,(stochforc(j,i+nres),j=1,3)
5465 write (iout,*) i,ind
5467 forcvec(ind+j)=force(j,i)
5472 write (iout,*) i,ind
5474 forcvec(j+ind)=force(j,i+nres)
5479 write (iout,*) "forcvec"
5483 write (iout,'(2i3,2f10.5)') i,j,force(j,i),&
5490 write (iout,'(2i3,2f10.5)') i,j,force(j,i+nres),&
5499 end subroutine stochastic_force
5500 !-----------------------------------------------------------------------------
5501 subroutine sdarea(gamvec)
5503 ! Scale the friction coefficients according to solvent accessible surface areas
5504 ! Code adapted from TINKER
5508 ! implicit real*8 (a-h,o-z)
5509 ! include 'DIMENSIONS'
5510 ! include 'COMMON.CONTROL'
5511 ! include 'COMMON.VAR'
5512 ! include 'COMMON.MD'
5514 ! include 'COMMON.LANGEVIN'
5516 ! include 'COMMON.LANGEVIN.lang0'
5518 ! include 'COMMON.CHAIN'
5519 ! include 'COMMON.DERIV'
5520 ! include 'COMMON.GEO'
5521 ! include 'COMMON.LOCAL'
5522 ! include 'COMMON.INTERACT'
5523 ! include 'COMMON.IOUNITS'
5524 ! include 'COMMON.NAMES'
5525 real(kind=8),dimension(2*nres) :: radius,gamvec !(maxres2)
5526 real(kind=8),parameter :: twosix = 1.122462048309372981d0
5527 logical :: lprn = .false.
5528 real(kind=8) :: probe,area,ratio
5529 integer :: i,j,ind,iti,mnum
5531 ! determine new friction coefficients every few SD steps
5533 ! set the atomic radii to estimates of sigma values
5535 ! print *,"Entered sdarea"
5541 ! Load peptide group radii
5544 radius(i)=pstok(mnum)
5546 ! Load side chain radii
5550 radius(i+nres)=restok(iti,mnum)
5553 ! write (iout,*) "i",i," radius",radius(i)
5556 radius(i) = radius(i) / twosix
5557 if (radius(i) .ne. 0.0d0) radius(i) = radius(i) + probe
5560 ! scale atomic friction coefficients by accessible area
5562 if (lprn) write (iout,*) &
5563 "Original gammas, surface areas, scaling factors, new gammas, ",&
5564 "std's of stochastic forces"
5567 if (radius(i).gt.0.0d0) then
5568 call surfatom (i,area,radius)
5569 ratio = dmax1(area/(4.0d0*pi*radius(i)**2),1.0d-1)
5570 if (lprn) write (iout,'(i5,3f10.5,$)') &
5571 i,gamvec(ind+1),area,ratio
5574 gamvec(ind) = ratio * gamvec(ind)
5577 stdforcp(i)=stdfp(mnum)*dsqrt(gamvec(ind))
5578 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcp(i)
5582 if (radius(i+nres).gt.0.0d0) then
5583 call surfatom (i+nres,area,radius)
5584 ratio = dmax1(area/(4.0d0*pi*radius(i+nres)**2),1.0d-1)
5585 if (lprn) write (iout,'(i5,3f10.5,$)') &
5586 i,gamvec(ind+1),area,ratio
5589 gamvec(ind) = ratio * gamvec(ind)
5592 stdforcsc(i)=stdfsc(itype(i,mnum),mnum)*dsqrt(gamvec(ind))
5593 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcsc(i)
5598 end subroutine sdarea
5599 !-----------------------------------------------------------------------------
5601 !-----------------------------------------------------------------------------
5604 ! ###################################################
5605 ! ## COPYRIGHT (C) 1996 by Jay William Ponder ##
5606 ! ## All Rights Reserved ##
5607 ! ###################################################
5609 ! ################################################################
5611 ! ## subroutine surfatom -- exposed surface area of an atom ##
5613 ! ################################################################
5616 ! "surfatom" performs an analytical computation of the surface
5617 ! area of a specified atom; a simplified version of "surface"
5619 ! literature references:
5621 ! T. J. Richmond, "Solvent Accessible Surface Area and
5622 ! Excluded Volume in Proteins", Journal of Molecular Biology,
5625 ! L. Wesson and D. Eisenberg, "Atomic Solvation Parameters
5626 ! Applied to Molecular Dynamics of Proteins in Solution",
5627 ! Protein Science, 1, 227-235 (1992)
5629 ! variables and parameters:
5631 ! ir number of atom for which area is desired
5632 ! area accessible surface area of the atom
5633 ! radius radii of each of the individual atoms
5636 subroutine surfatom(ir,area,radius)
5638 ! implicit real*8 (a-h,o-z)
5639 ! include 'DIMENSIONS'
5641 ! include 'COMMON.GEO'
5642 ! include 'COMMON.IOUNITS'
5644 integer :: nsup,nstart_sup
5645 ! double precision c,dc,dc_old,d_c_work,xloc,xrot,dc_norm
5646 ! common /chain/ c(3,maxres2+2),dc(3,0:maxres2),dc_old(3,0:maxres2),
5647 ! & xloc(3,maxres),xrot(3,maxres),dc_norm(3,0:maxres2),
5648 ! & dc_work(MAXRES6),nres,nres0
5649 integer,parameter :: maxarc=300
5653 integer :: mi,ni,narc
5654 integer :: key(maxarc)
5655 integer :: intag(maxarc)
5656 integer :: intag1(maxarc)
5657 real(kind=8) :: area,arcsum
5658 real(kind=8) :: arclen,exang
5659 real(kind=8) :: delta,delta2
5660 real(kind=8) :: eps,rmove
5661 real(kind=8) :: xr,yr,zr
5662 real(kind=8) :: rr,rrsq
5663 real(kind=8) :: rplus,rminus
5664 real(kind=8) :: axx,axy,axz
5665 real(kind=8) :: ayx,ayy
5666 real(kind=8) :: azx,azy,azz
5667 real(kind=8) :: uxj,uyj,uzj
5668 real(kind=8) :: tx,ty,tz
5669 real(kind=8) :: txb,tyb,td
5670 real(kind=8) :: tr2,tr,txr,tyr
5671 real(kind=8) :: tk1,tk2
5672 real(kind=8) :: thec,the,t,tb
5673 real(kind=8) :: txk,tyk,tzk
5674 real(kind=8) :: t1,ti,tf,tt
5675 real(kind=8) :: txj,tyj,tzj
5676 real(kind=8) :: ccsq,cc,xysq
5677 real(kind=8) :: bsqk,bk,cosine
5678 real(kind=8) :: dsqj,gi,pix2
5679 real(kind=8) :: therk,dk,gk
5680 real(kind=8) :: risqk,rik
5681 real(kind=8) :: radius(2*nres) !(maxatm) (maxatm=maxres2)
5682 real(kind=8) :: ri(maxarc),risq(maxarc)
5683 real(kind=8) :: ux(maxarc),uy(maxarc),uz(maxarc)
5684 real(kind=8) :: xc(maxarc),yc(maxarc),zc(maxarc)
5685 real(kind=8) :: xc1(maxarc),yc1(maxarc),zc1(maxarc)
5686 real(kind=8) :: dsq(maxarc),bsq(maxarc)
5687 real(kind=8) :: dsq1(maxarc),bsq1(maxarc)
5688 real(kind=8) :: arci(maxarc),arcf(maxarc)
5689 real(kind=8) :: ex(maxarc),lt(maxarc),gr(maxarc)
5690 real(kind=8) :: b(maxarc),b1(maxarc),bg(maxarc)
5691 real(kind=8) :: kent(maxarc),kout(maxarc)
5692 real(kind=8) :: ther(maxarc)
5693 logical :: moved,top
5694 logical :: omit(maxarc)
5697 ! maxatm = 2*nres !maxres2 maxres2=2*maxres
5698 ! maxlight = 8*maxatm
5701 ! maxtors = 4*maxatm
5703 ! zero out the surface area for the sphere of interest
5706 ! write (2,*) "ir",ir," radius",radius(ir)
5707 if (radius(ir) .eq. 0.0d0) return
5709 ! set the overlap significance and connectivity shift
5713 delta2 = delta * delta
5718 ! store coordinates and radius of the sphere of interest
5726 ! initialize values of some counters and summations
5735 ! test each sphere to see if it overlaps the sphere of interest
5738 if (i.eq.ir .or. radius(i).eq.0.0d0) goto 30
5739 rplus = rr + radius(i)
5741 if (abs(tx) .ge. rplus) goto 30
5743 if (abs(ty) .ge. rplus) goto 30
5745 if (abs(tz) .ge. rplus) goto 30
5747 ! check for sphere overlap by testing distance against radii
5749 xysq = tx*tx + ty*ty
5750 if (xysq .lt. delta2) then
5757 if (rplus-cc .le. delta) goto 30
5758 rminus = rr - radius(i)
5760 ! check to see if sphere of interest is completely buried
5762 if (cc-abs(rminus) .le. delta) then
5763 if (rminus .le. 0.0d0) goto 170
5767 ! check for too many overlaps with sphere of interest
5769 if (io .ge. maxarc) then
5771 20 format (/,' SURFATOM -- Increase the Value of MAXARC')
5775 ! get overlap between current sphere and sphere of interest
5784 gr(io) = (ccsq+rplus*rminus) / (2.0d0*rr*b1(io))
5790 ! case where no other spheres overlap the sphere of interest
5793 area = 4.0d0 * pi * rrsq
5797 ! case where only one sphere overlaps the sphere of interest
5800 area = pix2 * (1.0d0 + gr(1))
5801 area = mod(area,4.0d0*pi) * rrsq
5805 ! case where many spheres intersect the sphere of interest;
5806 ! sort the intersecting spheres by their degree of overlap
5808 call sort2 (io,gr,key)
5811 intag(i) = intag1(k)
5820 ! get radius of each overlap circle on surface of the sphere
5825 risq(i) = rrsq - gi*gi
5826 ri(i) = sqrt(risq(i))
5827 ther(i) = 0.5d0*pi - asin(min(1.0d0,max(-1.0d0,gr(i))))
5830 ! find boundary of inaccessible area on sphere of interest
5833 if (.not. omit(k)) then
5840 ! check to see if J circle is intersecting K circle;
5841 ! get distance between circle centers and sum of radii
5844 if (omit(j)) goto 60
5845 cc = (txk*xc(j)+tyk*yc(j)+tzk*zc(j))/(bk*b(j))
5846 cc = acos(min(1.0d0,max(-1.0d0,cc)))
5847 td = therk + ther(j)
5849 ! check to see if circles enclose separate regions
5851 if (cc .ge. td) goto 60
5853 ! check for circle J completely inside circle K
5855 if (cc+ther(j) .lt. therk) goto 40
5857 ! check for circles that are essentially parallel
5859 if (cc .gt. delta) goto 50
5864 ! check to see if sphere of interest is completely buried
5867 if (pix2-cc .le. td) goto 170
5873 ! find T value of circle intersections
5876 if (omit(k)) goto 110
5891 ! rotation matrix elements
5903 if (.not. omit(j)) then
5908 ! rotate spheres so K vector colinear with z-axis
5910 uxj = txj*axx + tyj*axy - tzj*axz
5911 uyj = tyj*ayy - txj*ayx
5912 uzj = txj*azx + tyj*azy + tzj*azz
5913 cosine = min(1.0d0,max(-1.0d0,uzj/b(j)))
5914 if (acos(cosine) .lt. therk+ther(j)) then
5915 dsqj = uxj*uxj + uyj*uyj
5920 tr2 = risqk*dsqj - tb*tb
5926 ! get T values of intersection for K circle
5929 tb = min(1.0d0,max(-1.0d0,tb))
5931 if (tyb-txr .lt. 0.0d0) tk1 = pix2 - tk1
5933 tb = min(1.0d0,max(-1.0d0,tb))
5935 if (tyb+txr .lt. 0.0d0) tk2 = pix2 - tk2
5936 thec = (rrsq*uzj-gk*bg(j)) / (rik*ri(j)*b(j))
5937 if (abs(thec) .lt. 1.0d0) then
5939 else if (thec .ge. 1.0d0) then
5941 else if (thec .le. -1.0d0) then
5945 ! see if "tk1" is entry or exit point; check t=0 point;
5946 ! "ti" is exit point, "tf" is entry point
5948 cosine = min(1.0d0,max(-1.0d0, &
5949 (uzj*gk-uxj*rik)/(b(j)*rr)))
5950 if ((acos(cosine)-ther(j))*(tk2-tk1) .le. 0.0d0) then
5958 if (narc .ge. maxarc) then
5960 70 format (/,' SURFATOM -- Increase the Value',&
5964 if (tf .le. ti) then
5985 ! special case; K circle without intersections
5987 if (narc .le. 0) goto 90
5989 ! general case; sum up arclength and set connectivity code
5991 call sort2 (narc,arci,key)
5996 if (narc .gt. 1) then
5999 if (t .lt. arci(j)) then
6000 arcsum = arcsum + arci(j) - t
6001 exang = exang + ex(ni)
6003 if (jb .ge. maxarc) then
6005 80 format (/,' SURFATOM -- Increase the Value',&
6010 kent(jb) = maxarc*i + k
6012 kout(jb) = maxarc*k + i
6021 arcsum = arcsum + pix2 - t
6023 exang = exang + ex(ni)
6026 kent(jb) = maxarc*i + k
6028 kout(jb) = maxarc*k + i
6035 arclen = arclen + gr(k)*arcsum
6038 if (arclen .eq. 0.0d0) goto 170
6039 if (jb .eq. 0) goto 150
6041 ! find number of independent boundaries and check connectivity
6045 if (kout(k) .ne. 0) then
6052 if (m .eq. kent(ii)) then
6055 if (j .eq. jb) goto 150
6067 ! attempt to fix connectivity error by moving atom slightly
6071 140 format (/,' SURFATOM -- Connectivity Error at Atom',i6)
6080 ! compute the exposed surface area for the sphere of interest
6083 area = ib*pix2 + exang + arclen
6084 area = mod(area,4.0d0*pi) * rrsq
6086 ! attempt to fix negative area by moving atom slightly
6088 if (area .lt. 0.0d0) then
6091 160 format (/,' SURFATOM -- Negative Area at Atom',i6)
6102 end subroutine surfatom
6103 !----------------------------------------------------------------
6104 !----------------------------------------------------------------
6105 subroutine alloc_MD_arrays
6106 !EL Allocation of arrays used by MD module
6108 integer :: nres2,nres6
6111 !----------------------
6115 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
6116 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
6117 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
6118 allocate(fricvec(nres2,nres2))
6119 allocate(pfric_mat(nres2,nres2),vfric_mat(nres2,nres2))
6120 allocate(afric_mat(nres2,nres2),prand_mat(nres2,nres2))
6121 allocate(vrand_mat1(nres2,nres2),vrand_mat2(nres2,nres2)) !(MAXRES2,MAXRES2)
6122 allocate(pfric0_mat(nres2,nres2,0:maxflag_stoch))
6123 allocate(afric0_mat(nres2,nres2,0:maxflag_stoch))
6124 allocate(vfric0_mat(nres2,nres2,0:maxflag_stoch))
6125 allocate(prand0_mat(nres2,nres2,0:maxflag_stoch))
6126 allocate(vrand0_mat1(nres2,nres2,0:maxflag_stoch))
6127 allocate(vrand0_mat2(nres2,nres2,0:maxflag_stoch)) !(MAXRES2,MAXRES2,0:maxflag_stoch)
6128 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
6130 allocate(mt1(nres2,nres2),mt2(nres2,nres2),mt3(nres2,nres2)) !(maxres2,maxres2)
6131 !----------------------
6133 ! commom.langevin.lang0
6135 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
6136 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
6137 allocate(fricvec(nres2,nres2)) !(MAXRES2,MAXRES2)
6138 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
6139 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
6142 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2))
6143 !----------------------
6144 ! commom.hairpin in CSA module
6145 !----------------------
6146 ! common.mce in MCM_MD module
6147 !----------------------
6149 ! common /mdgrad/ in module.energy
6150 ! common /back_constr/ in module.energy
6151 ! common /qmeas/ in module.energy
6154 allocate(potEcomp(0:n_ene+4)) !(0:n_ene+4)
6156 allocate(d_t(3,0:nres2),d_a(3,0:nres2),d_t_old(3,0:nres2)) !(3,0:MAXRES2)
6157 allocate(d_a_work(nres6)) !(6*MAXRES)
6159 allocate(DM(nres2),DU1(nres2),DU2(nres2))
6160 allocate(DMorig(nres2),DU1orig(nres2),DU2orig(nres2))
6162 allocate(Gmat(nres2,nres2),A(nres2,nres2))
6163 if(.not.allocated(Ginv)) allocate(Ginv(nres2,nres2)) !in control: ergastulum
6164 allocate(Gsqrp(nres2,nres2),Gsqrm(nres2,nres2),Gvec(nres2,nres2)) !(maxres2,maxres2)
6166 allocate(Geigen(nres2)) !(maxres2)
6167 if(.not.allocated(vtot)) allocate(vtot(nres2)) !(maxres2)
6168 ! common /inertia/ in io_conf: parmread
6169 ! real(kind=8),dimension(:),allocatable :: ISC,msc !(ntyp+1)
6170 ! common /langevin/in io read_MDpar
6171 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
6172 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
6173 ! in io_conf: parmread
6174 ! real(kind=8),dimension(:),allocatable :: restok !(ntyp+1)
6175 ! common /mdpmpi/ in control: ergastulum
6176 if(.not.allocated(ng_start)) allocate(ng_start(0:nfgtasks-1))
6177 if(.not.allocated(ng_counts)) allocate(ng_counts(0:nfgtasks-1))
6178 if(.not.allocated(nginv_counts)) allocate(nginv_counts(0:nfgtasks-1)) !(0:MaxProcs-1)
6179 if(.not.allocated(nginv_start)) allocate(nginv_start(0:nfgtasks)) !(0:MaxProcs)
6180 !----------------------
6181 ! common.muca in read_muca
6182 ! common /double_muca/
6183 ! real(kind=8) :: elow,ehigh,factor,hbin,factor_min
6184 ! real(kind=8),dimension(:),allocatable :: emuca,nemuca,&
6185 ! nemuca2,hist !(4*maxres)
6186 ! common /integer_muca/
6187 ! integer :: nmuca,imtime,muca_smooth
6189 ! real(kind=8),dimension(:),allocatable :: elowi,ehighi !(maxprocs)
6190 !----------------------
6192 ! common /mdgrad/ in module.energy
6193 ! common /back_constr/ in module.energy
6194 ! common /qmeas/ in module.energy
6198 allocate(d_t_work(nres6),d_t_work_new(nres6),d_af_work(nres6))
6199 allocate(d_as_work(nres6),kinetic_force(nres6)) !(MAXRES6)
6200 allocate(d_t_new(3,0:nres2),d_a_old(3,0:nres2),d_a_short(3,0:nres2)) !,d_a !(3,0:MAXRES2)
6201 allocate(stdforcp(nres),stdforcsc(nres)) !(MAXRES)
6202 !----------------------
6204 allocate(D_ban(nres6)) !(MAXRES6) maxres6=6*maxres
6205 ! common /stochcalc/ stochforcvec
6206 allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
6207 !----------------------
6209 end subroutine alloc_MD_arrays
6210 !-----------------------------------------------------------------------------
6211 !-----------------------------------------------------------------------------