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 !el 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(6*nres) :: Td !(maxres6) maxres6=6*maxres
191 real(kind=8),dimension(2*nres) :: ppvec !(maxres2) maxres2=2*maxres
192 !el common /stochcalc/ stochforcvec
193 !el real(kind=8),dimension(3) :: cm !el
194 !el common /gucio/ cm
196 logical :: lprn = .false.,lprn1 = .false.
197 integer :: maxiter = 5
198 real(kind=8) :: difftol = 1.0d-5
199 real(kind=8) :: xx,diffmax,blen2,diffbond,tt0
200 integer :: i,j,nbond,k,ind,ind1,iter
201 integer :: nres2,nres6
206 if (.not.allocated(stochforcvec)) allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
210 if (itype(i).ne.10) nbond=nbond+1
214 write (iout,*) "Generalized inverse of fricmat"
215 call matout(dimen,dimen,nres6,nres6,fricmat)
227 Bmat(ind+j,ind1)=dC_norm(j,i)
232 if (itype(i).ne.10) then
235 Bmat(ind+j,ind1)=dC_norm(j,i+nres)
241 write (iout,*) "Matrix Bmat"
242 call MATOUT(nbond,dimen,nres6,nres6,Bmat)
248 GBmat(i,j)=GBmat(i,j)+fricmat(i,k)*Bmat(k,j)
253 write (iout,*) "Matrix GBmat"
254 call MATOUT(nbond,dimen,nres6,nres2,Gbmat)
260 Cmat_(i,j)=Cmat_(i,j)+Bmat(k,i)*GBmat(k,j)
265 write (iout,*) "Matrix Cmat"
266 call MATOUT(nbond,nbond,nres2,nres2,Cmat_)
268 call matinvert(nbond,nres2,Cmat_,Cinv,osob)
270 write (iout,*) "Matrix Cinv"
271 call MATOUT(nbond,nbond,nres2,nres2,Cinv)
277 Tmat(i,j)=Tmat(i,j)+GBmat(i,k)*Cinv(k,j)
282 write (iout,*) "Matrix Tmat"
283 call MATOUT(nbond,dimen,nres6,nres2,Tmat)
293 Pmat(i,j)=Pmat(i,j)-Tmat(i,k)*Bmat(j,k)
298 write (iout,*) "Matrix Pmat"
299 call MATOUT(dimen,dimen,nres6,nres6,Pmat)
306 Td(i)=Td(i)+vbl*Tmat(i,ind)
309 if (itype(k).ne.10) then
311 Td(i)=Td(i)+vbldsc0(1,itype(k))*Tmat(i,ind)
316 write (iout,*) "Vector Td"
318 write (iout,'(i5,f10.5)') i,Td(i)
321 call stochastic_force(stochforcvec)
323 write (iout,*) "stochforcvec"
325 write (iout,*) i,stochforcvec(i)
329 zapas(j)=-gcart(j,0)+stochforcvec(j)
331 dC_work(j)=dC_old(j,0)
337 zapas(ind)=-gcart(j,i)+stochforcvec(ind)
338 dC_work(ind)=dC_old(j,i)
342 if (itype(i).ne.10) then
345 zapas(ind)=-gxcart(j,i)+stochforcvec(ind)
346 dC_work(ind)=dC_old(j,i+nres)
352 write (iout,*) "Initial d_t_work"
354 write (iout,*) i,d_t_work(i)
361 d_t_work(i)=d_t_work(i)+fricmat(i,j)*zapas(j)
368 zapas(i)=zapas(i)+Pmat(i,j)*(dC_work(j)+d_t_work(j)*d_time)
372 write (iout,*) "Final d_t_work and zapas"
374 write (iout,*) i,d_t_work(i),zapas(i)
388 dc_work(ind+j)=dc(j,i)
394 d_t(j,i+nres)=d_t_work(ind+j)
395 dc(j,i+nres)=zapas(ind+j)
396 dc_work(ind+j)=dc(j,i+nres)
402 write (iout,*) "Before correction for rotational lengthening"
403 write (iout,*) "New coordinates",&
404 " and differences between actual and standard bond lengths"
409 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
413 if (itype(i).ne.10) then
415 xx=vbld(i+nres)-vbldsc0(1,itype(i))
416 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
417 i,(dC(j,i+nres),j=1,3),xx
421 ! Second correction (rotational lengthening)
427 blen2 = scalar(dc(1,i),dc(1,i))
428 ppvec(ind)=2*vbl**2-blen2
429 diffbond=dabs(vbl-dsqrt(blen2))
430 if (diffbond.gt.diffmax) diffmax=diffbond
431 if (ppvec(ind).gt.0.0d0) then
432 ppvec(ind)=dsqrt(ppvec(ind))
437 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
441 if (itype(i).ne.10) then
443 blen2 = scalar(dc(1,i+nres),dc(1,i+nres))
444 ppvec(ind)=2*vbldsc0(1,itype(i))**2-blen2
445 diffbond=dabs(vbldsc0(1,itype(i))-dsqrt(blen2))
446 if (diffbond.gt.diffmax) diffmax=diffbond
447 if (ppvec(ind).gt.0.0d0) then
448 ppvec(ind)=dsqrt(ppvec(ind))
453 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
457 if (lprn) write (iout,*) "iter",iter," diffmax",diffmax
458 if (diffmax.lt.difftol) goto 10
462 Td(i)=Td(i)+ppvec(j)*Tmat(i,j)
468 zapas(i)=zapas(i)+Pmat(i,j)*dc_work(j)
479 dc_work(ind+j)=zapas(ind+j)
484 if (itype(i).ne.10) then
486 dc(j,i+nres)=zapas(ind+j)
487 dc_work(ind+j)=zapas(ind+j)
492 ! Building the chain from the newly calculated coordinates
495 if (large.and. mod(itime,ntwe).eq.0) then
496 write (iout,*) "Cartesian and internal coordinates: step 1"
499 write (iout,'(a)') "Potential forces"
501 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(-gcart(j,i),j=1,3),&
504 write (iout,'(a)') "Stochastic forces"
506 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(stochforc(j,i),j=1,3),&
507 (stochforc(j,i+nres),j=1,3)
509 write (iout,'(a)') "Velocities"
511 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
512 (d_t(j,i+nres),j=1,3)
517 write (iout,*) "After correction for rotational lengthening"
518 write (iout,*) "New coordinates",&
519 " and differences between actual and standard bond lengths"
524 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
528 if (itype(i).ne.10) then
530 xx=vbld(i+nres)-vbldsc0(1,itype(i))
531 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
532 i,(dC(j,i+nres),j=1,3),xx
537 ! write (iout,*) "Too many attempts at correcting the bonds"
545 ! Calculate energy and forces
547 call etotal(potEcomp)
548 potE=potEcomp(0)-potEcomp(20)
551 ! Calculate the kinetic and total energy and the kinetic temperature
554 t_enegrad=t_enegrad+MPI_Wtime()-tt0
556 t_enegrad=t_enegrad+tcpu()-tt0
559 kinetic_T=2.0d0/(dimen*Rb)*EK
561 end subroutine brown_step
562 !-----------------------------------------------------------------------------
564 !-----------------------------------------------------------------------------
565 subroutine gauss(RO,AP,MT,M,N,*)
567 ! CALCULATES (RO**(-1))*AP BY GAUSS ELIMINATION
568 ! RO IS A SQUARE MATRIX
569 ! THE CALCULATED PRODUCT IS STORED IN AP
570 ! ABNORMAL EXIT IF RO IS SINGULAR
572 integer :: MT, M, N, M1,I,J,IM,&
574 real(kind=8) :: RO(MT,M),AP(MT,N),X,RM,PR,Y
580 if(dabs(X).le.1.0D-13) return 1
592 if(DABS(RO(J,I)).LE.RM) goto 2
606 if(dabs(X).le.1.0E-13) return 1
615 8 AP(J,K)=AP(J,K)-Y*AP(I,K)
617 9 RO(J,K)=RO(J,K)-Y*RO(I,K)
621 if(dabs(X).le.1.0E-13) return 1
631 15 X=X-AP(K,J)*RO(MI,K)
636 !-----------------------------------------------------------------------------
638 !-----------------------------------------------------------------------------
639 subroutine kinetic(KE_total)
640 !----------------------------------------------------------------
641 ! This subroutine calculates the total kinetic energy of the chain
642 !-----------------------------------------------------------------
644 ! implicit real*8 (a-h,o-z)
645 ! include 'DIMENSIONS'
646 ! include 'COMMON.VAR'
647 ! include 'COMMON.CHAIN'
648 ! include 'COMMON.DERIV'
649 ! include 'COMMON.GEO'
650 ! include 'COMMON.LOCAL'
651 ! include 'COMMON.INTERACT'
652 ! include 'COMMON.MD'
653 ! include 'COMMON.IOUNITS'
654 real(kind=8) :: KE_total
657 real(kind=8) :: KEt_p,KEt_sc,KEr_p,KEr_sc,incr(3),&
662 ! write (iout,*) "ISC",(isc(itype(i)),i=1,nres)
663 ! The translational part for peptide virtual bonds
668 ! write (iout,*) "Kinetic trp:",i,(incr(j),j=1,3)
670 v(j)=incr(j)+0.5d0*d_t(j,i)
672 vtot(i)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
673 KEt_p=KEt_p+(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))
675 incr(j)=incr(j)+d_t(j,i)
678 ! write(iout,*) 'KEt_p', KEt_p
679 ! The translational part for the side chain virtual bond
680 ! Only now we can initialize incr with zeros. It must be equal
681 ! to the velocities of the first Calpha.
687 if (itype(i).eq.10) then
693 v(j)=incr(j)+d_t(j,nres+i)
696 ! write (iout,*) "Kinetic trsc:",i,(incr(j),j=1,3)
697 ! write (iout,*) "i",i," msc",msc(iti)," v",(v(j),j=1,3)
698 KEt_sc=KEt_sc+msc(iti)*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))
699 vtot(i+nres)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
701 incr(j)=incr(j)+d_t(j,i)
705 ! write(iout,*) 'KEt_sc', KEt_sc
706 ! The part due to stretching and rotation of the peptide groups
709 ! write (iout,*) "i",i
710 ! write (iout,*) "i",i," mag1",mag1," mag2",mag2
714 ! write (iout,*) "Kinetic rotp:",i,(incr(j),j=1,3)
715 KEr_p=KEr_p+(incr(1)*incr(1)+incr(2)*incr(2) &
719 ! write(iout,*) 'KEr_p', KEr_p
720 ! The rotational part of the side chain virtual bond
724 if (itype(i).ne.10) then
726 incr(j)=d_t(j,nres+i)
728 ! write (iout,*) "Kinetic rotsc:",i,(incr(j),j=1,3)
729 KEr_sc=KEr_sc+Isc(iti)*(incr(1)*incr(1)+incr(2)*incr(2)+ &
733 ! The total kinetic energy
735 ! write(iout,*) 'KEr_sc', KEr_sc
736 KE_total=0.5d0*(mp*KEt_p+KEt_sc+0.25d0*Ip*KEr_p+KEr_sc)
737 ! write (iout,*) "KE_total",KE_total
739 end subroutine kinetic
740 !-----------------------------------------------------------------------------
742 !-----------------------------------------------------------------------------
744 !------------------------------------------------
745 ! The driver for molecular dynamics subroutines
746 !------------------------------------------------
749 use control, only:tcpu,ovrtim
750 ! use io_comm, only:ilen
752 use compare, only:secondary2,hairpin
753 use io, only:cartout,statout
754 ! implicit real*8 (a-h,o-z)
755 ! include 'DIMENSIONS'
758 integer :: IERROR,ERRCODE
760 ! include 'COMMON.SETUP'
761 ! include 'COMMON.CONTROL'
762 ! include 'COMMON.VAR'
763 ! include 'COMMON.MD'
765 ! include 'COMMON.LANGEVIN'
767 ! include 'COMMON.LANGEVIN.lang0'
769 ! include 'COMMON.CHAIN'
770 ! include 'COMMON.DERIV'
771 ! include 'COMMON.GEO'
772 ! include 'COMMON.LOCAL'
773 ! include 'COMMON.INTERACT'
774 ! include 'COMMON.IOUNITS'
775 ! include 'COMMON.NAMES'
776 ! include 'COMMON.TIME1'
777 ! include 'COMMON.HAIRPIN'
778 real(kind=8),dimension(3) :: L,vcm
780 real(kind=8),dimension(6*nres) :: v_work,v_transf !(maxres6) maxres6=6*maxres
782 integer :: rstcount !ilen,
784 character(len=50) :: tytul
785 !el common /gucio/ cm
786 integer :: itime,i,j,nharp
787 integer,dimension(4,nres/3) :: iharp !(4,nres/3)(4,maxres/3)
789 real(kind=8) :: tt0,scalfac
794 if (ilen(tmpdir).gt.0) &
795 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_" &
796 //liczba(:ilen(liczba))//'.rst')
798 if (ilen(tmpdir).gt.0) &
799 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_"//'.rst')
806 write (iout,'(20(1h=),a20,20(1h=))') "MD calculation started"
812 ! Determine the inverse of the inertia matrix.
813 call setup_MD_matrices
817 t_MDsetup = MPI_Wtime()-tt0
819 t_MDsetup = tcpu()-tt0
822 ! Entering the MD loop
828 if (lang.eq.2 .or. lang.eq.3) then
832 call sd_verlet_p_setup
834 call sd_verlet_ciccotti_setup
838 pfric0_mat(i,j,0)=pfric_mat(i,j)
839 afric0_mat(i,j,0)=afric_mat(i,j)
840 vfric0_mat(i,j,0)=vfric_mat(i,j)
841 prand0_mat(i,j,0)=prand_mat(i,j)
842 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
843 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
848 flag_stoch(i)=.false.
852 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
854 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
858 else if (lang.eq.1 .or. lang.eq.4) then
862 t_langsetup=MPI_Wtime()-tt0
865 t_langsetup=tcpu()-tt0
868 do itime=1,n_timestep
870 if (large.and. mod(itime,ntwe).eq.0) &
871 write (iout,*) "itime",itime
873 if (lang.gt.0 .and. surfarea .and. &
874 mod(itime,reset_fricmat).eq.0) then
875 if (lang.eq.2 .or. lang.eq.3) then
879 call sd_verlet_p_setup
881 call sd_verlet_ciccotti_setup
885 pfric0_mat(i,j,0)=pfric_mat(i,j)
886 afric0_mat(i,j,0)=afric_mat(i,j)
887 vfric0_mat(i,j,0)=vfric_mat(i,j)
888 prand0_mat(i,j,0)=prand_mat(i,j)
889 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
890 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
895 flag_stoch(i)=.false.
898 else if (lang.eq.1 .or. lang.eq.4) then
901 write (iout,'(a,i10)') &
902 "Friction matrix reset based on surface area, itime",itime
904 if (reset_vel .and. tbf .and. lang.eq.0 &
905 .and. mod(itime,count_reset_vel).eq.0) then
907 write(iout,'(a,f20.2)') &
908 "Velocities reset to random values, time",totT
911 d_t_old(j,i)=d_t(j,i)
915 if (reset_moment .and. mod(itime,count_reset_moment).eq.0) then
919 d_t(j,0)=d_t(j,0)-vcm(j)
922 kinetic_T=2.0d0/(dimen3*Rb)*EK
923 scalfac=dsqrt(T_bath/kinetic_T)
924 write(iout,'(a,f20.2)') "Momenta zeroed out, time",totT
927 d_t_old(j,i)=scalfac*d_t(j,i)
933 ! Time-reversible RESPA algorithm
934 ! (Tuckerman et al., J. Chem. Phys., 97, 1990, 1992)
935 call RESPA_step(itime)
937 ! Variable time step algorithm.
938 call velverlet_step(itime)
942 call brown_step(itime)
944 print *,"Brown dynamics not here!"
946 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
952 if (mod(itime,ntwe).eq.0) call statout(itime)
965 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
968 v_work(ind)=d_t(j,i+nres)
973 write (66,'(80f10.5)') &
974 ((d_t(j,i),j=1,3),i=0,nres-1),((d_t(j,i+nres),j=1,3),i=1,nres)
978 v_transf(i)=v_transf(i)+gvec(j,i)*v_work(j)
980 v_transf(i)= v_transf(i)*dsqrt(geigen(i))
982 write (67,'(80f10.5)') (v_transf(i),i=1,ind)
985 if (mod(itime,ntwx).eq.0) then
986 write (tytul,'("time",f8.2)') totT
988 call hairpin(.true.,nharp,iharp)
989 call secondary2(.true.)
990 call pdbout(potE,tytul,ipdb)
995 if (rstcount.eq.1000.or.itime.eq.n_timestep) then
996 open(irest2,file=rest2name,status='unknown')
997 write(irest2,*) totT,EK,potE,totE,t_bath
999 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
1002 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
1010 t_MD=MPI_Wtime()-tt0
1014 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))') &
1016 'MD calculations setup:',t_MDsetup,&
1017 'Energy & gradient evaluation:',t_enegrad,&
1018 'Stochastic MD setup:',t_langsetup,&
1019 'Stochastic MD step setup:',t_sdsetup,&
1021 write (iout,'(/28(1h=),a25,27(1h=))') &
1022 ' End of MD calculation '
1024 write (iout,*) "time for etotal",t_etotal," elong",t_elong,&
1026 write (iout,*) "time_fric",time_fric," time_stoch",time_stoch,&
1027 " time_fricmatmult",time_fricmatmult," time_fsample ",&
1032 !-----------------------------------------------------------------------------
1033 subroutine velverlet_step(itime)
1034 !-------------------------------------------------------------------------------
1035 ! Perform a single velocity Verlet step; the time step can be rescaled if
1036 ! increments in accelerations exceed the threshold
1037 !-------------------------------------------------------------------------------
1038 ! implicit real*8 (a-h,o-z)
1039 ! include 'DIMENSIONS'
1041 use control, only:tcpu
1045 integer :: ierror,ierrcode
1046 real(kind=8) :: errcode
1048 ! include 'COMMON.SETUP'
1049 ! include 'COMMON.VAR'
1050 ! include 'COMMON.MD'
1052 ! include 'COMMON.LANGEVIN'
1054 ! include 'COMMON.LANGEVIN.lang0'
1056 ! include 'COMMON.CHAIN'
1057 ! include 'COMMON.DERIV'
1058 ! include 'COMMON.GEO'
1059 ! include 'COMMON.LOCAL'
1060 ! include 'COMMON.INTERACT'
1061 ! include 'COMMON.IOUNITS'
1062 ! include 'COMMON.NAMES'
1063 ! include 'COMMON.TIME1'
1064 ! include 'COMMON.MUCA'
1065 real(kind=8),dimension(3) :: vcm,incr
1066 real(kind=8),dimension(3) :: L
1067 integer :: count,rstcount !ilen,
1069 character(len=50) :: tytul
1070 integer :: maxcount_scale = 20
1071 !el common /gucio/ cm
1072 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1073 !el common /stochcalc/ stochforcvec
1074 integer :: itime,icount_scale,itime_scal,i,j,ifac_time
1076 real(kind=8) :: epdrift,tt0,fac_time
1078 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1084 else if (lang.eq.2 .or. lang.eq.3) then
1086 call stochastic_force(stochforcvec)
1089 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1091 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1098 icount_scale=icount_scale+1
1099 if (icount_scale.gt.maxcount_scale) then
1101 "ERROR: too many attempts at scaling down the time step. ",&
1102 "amax=",amax,"epdrift=",epdrift,&
1103 "damax=",damax,"edriftmax=",edriftmax,&
1107 call MPI_Abort(MPI_COMM_WORLD,IERROR,IERRCODE)
1111 ! First step of the velocity Verlet algorithm
1116 else if (lang.eq.3) then
1118 call sd_verlet1_ciccotti
1120 else if (lang.eq.1) then
1125 ! Build the chain from the newly calculated coordinates
1126 call chainbuild_cart
1127 if (rattle) call rattle1
1129 if (large.and. mod(itime,ntwe).eq.0) then
1130 write (iout,*) "Cartesian and internal coordinates: step 1"
1135 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
1136 (dc(j,i+nres),j=1,3)
1138 write (iout,*) "Accelerations"
1140 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1141 (d_a(j,i+nres),j=1,3)
1143 write (iout,*) "Velocities, step 1"
1145 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1146 (d_t(j,i+nres),j=1,3)
1155 ! Calculate energy and forces
1157 call etotal(potEcomp)
1158 if (large.and. mod(itime,ntwe).eq.0) &
1159 call enerprint(potEcomp)
1162 t_etotal=t_etotal+MPI_Wtime()-tt0
1164 t_etotal=t_etotal+tcpu()-tt0
1167 potE=potEcomp(0)-potEcomp(20)
1169 ! Get the new accelerations
1172 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1174 t_enegrad=t_enegrad+tcpu()-tt0
1176 ! Determine maximum acceleration and scale down the timestep if needed
1178 amax=amax/(itime_scal+1)**2
1179 call predict_edrift(epdrift)
1180 if (amax/(itime_scal+1).gt.damax .or. epdrift.gt.edriftmax) then
1181 ! Maximum acceleration or maximum predicted energy drift exceeded, rescale the time step
1183 ifac_time=dmax1(dlog(amax/damax),dlog(epdrift/edriftmax)) &
1185 itime_scal=itime_scal+ifac_time
1186 ! fac_time=dmin1(damax/amax,0.5d0)
1187 fac_time=0.5d0**ifac_time
1188 d_time=d_time*fac_time
1189 if (lang.eq.2 .or. lang.eq.3) then
1191 ! write (iout,*) "Calling sd_verlet_setup: 1"
1192 ! Rescale the stochastic forces and recalculate or restore
1193 ! the matrices of tinker integrator
1194 if (itime_scal.gt.maxflag_stoch) then
1195 if (large) write (iout,'(a,i5,a)') &
1196 "Calculate matrices for stochastic step;",&
1197 " itime_scal ",itime_scal
1199 call sd_verlet_p_setup
1201 call sd_verlet_ciccotti_setup
1203 write (iout,'(2a,i3,a,i3,1h.)') &
1204 "Warning: cannot store matrices for stochastic",&
1205 " integration because the index",itime_scal,&
1206 " is greater than",maxflag_stoch
1207 write (iout,'(2a)')"Increase MAXFLAG_STOCH or use direct",&
1208 " integration Langevin algorithm for better efficiency."
1209 else if (flag_stoch(itime_scal)) then
1210 if (large) write (iout,'(a,i5,a,l1)') &
1211 "Restore matrices for stochastic step; itime_scal ",&
1212 itime_scal," flag ",flag_stoch(itime_scal)
1215 pfric_mat(i,j)=pfric0_mat(i,j,itime_scal)
1216 afric_mat(i,j)=afric0_mat(i,j,itime_scal)
1217 vfric_mat(i,j)=vfric0_mat(i,j,itime_scal)
1218 prand_mat(i,j)=prand0_mat(i,j,itime_scal)
1219 vrand_mat1(i,j)=vrand0_mat1(i,j,itime_scal)
1220 vrand_mat2(i,j)=vrand0_mat2(i,j,itime_scal)
1224 if (large) write (iout,'(2a,i5,a,l1)') &
1225 "Calculate & store matrices for stochastic step;",&
1226 " itime_scal ",itime_scal," flag ",flag_stoch(itime_scal)
1228 call sd_verlet_p_setup
1230 call sd_verlet_ciccotti_setup
1232 flag_stoch(ifac_time)=.true.
1235 pfric0_mat(i,j,itime_scal)=pfric_mat(i,j)
1236 afric0_mat(i,j,itime_scal)=afric_mat(i,j)
1237 vfric0_mat(i,j,itime_scal)=vfric_mat(i,j)
1238 prand0_mat(i,j,itime_scal)=prand_mat(i,j)
1239 vrand0_mat1(i,j,itime_scal)=vrand_mat1(i,j)
1240 vrand0_mat2(i,j,itime_scal)=vrand_mat2(i,j)
1244 fac_time=1.0d0/dsqrt(fac_time)
1246 stochforcvec(i)=fac_time*stochforcvec(i)
1249 else if (lang.eq.1) then
1250 ! Rescale the accelerations due to stochastic forces
1251 fac_time=1.0d0/dsqrt(fac_time)
1253 d_as_work(i)=d_as_work(i)*fac_time
1256 if (large) write (iout,'(a,i10,a,f8.6,a,i3,a,i3)') &
1257 "itime",itime," Timestep scaled down to ",&
1258 d_time," ifac_time",ifac_time," itime_scal",itime_scal
1260 ! Second step of the velocity Verlet algorithm
1265 else if (lang.eq.3) then
1267 call sd_verlet2_ciccotti
1269 else if (lang.eq.1) then
1274 if (rattle) call rattle2
1276 if (d_time.ne.d_time0) then
1279 if (lang.eq.2 .or. lang.eq.3) then
1280 if (large) write (iout,'(a)') &
1281 "Restore original matrices for stochastic step"
1282 ! write (iout,*) "Calling sd_verlet_setup: 2"
1283 ! Restore the matrices of tinker integrator if the time step has been restored
1286 pfric_mat(i,j)=pfric0_mat(i,j,0)
1287 afric_mat(i,j)=afric0_mat(i,j,0)
1288 vfric_mat(i,j)=vfric0_mat(i,j,0)
1289 prand_mat(i,j)=prand0_mat(i,j,0)
1290 vrand_mat1(i,j)=vrand0_mat1(i,j,0)
1291 vrand_mat2(i,j)=vrand0_mat2(i,j,0)
1300 ! Calculate the kinetic and the total energy and the kinetic temperature
1304 ! call kinetic1(EK1)
1305 ! write (iout,*) "step",itime," EK",EK," EK1",EK1
1307 ! Couple the system to Berendsen bath if needed
1308 if (tbf .and. lang.eq.0) then
1311 kinetic_T=2.0d0/(dimen3*Rb)*EK
1312 ! Backup the coordinates, velocities, and accelerations
1316 d_t_old(j,i)=d_t(j,i)
1317 d_a_old(j,i)=d_a(j,i)
1321 if (mod(itime,ntwe).eq.0 .and. large) then
1322 write (iout,*) "Velocities, step 2"
1324 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1325 (d_t(j,i+nres),j=1,3)
1330 end subroutine velverlet_step
1331 !-----------------------------------------------------------------------------
1332 subroutine RESPA_step(itime)
1333 !-------------------------------------------------------------------------------
1334 ! Perform a single RESPA step.
1335 !-------------------------------------------------------------------------------
1336 ! implicit real*8 (a-h,o-z)
1337 ! include 'DIMENSIONS'
1341 use control, only:tcpu
1343 ! use io_conf, only:cartprint
1346 integer :: IERROR,ERRCODE
1348 ! include 'COMMON.SETUP'
1349 ! include 'COMMON.CONTROL'
1350 ! include 'COMMON.VAR'
1351 ! include 'COMMON.MD'
1353 ! include 'COMMON.LANGEVIN'
1355 ! include 'COMMON.LANGEVIN.lang0'
1357 ! include 'COMMON.CHAIN'
1358 ! include 'COMMON.DERIV'
1359 ! include 'COMMON.GEO'
1360 ! include 'COMMON.LOCAL'
1361 ! include 'COMMON.INTERACT'
1362 ! include 'COMMON.IOUNITS'
1363 ! include 'COMMON.NAMES'
1364 ! include 'COMMON.TIME1'
1365 real(kind=8),dimension(0:n_ene) :: energia_short,energia_long
1366 real(kind=8),dimension(3) :: L,vcm,incr
1367 real(kind=8),dimension(3,0:2*nres) :: dc_old0,d_t_old0,d_a_old0 !(3,0:maxres2) maxres2=2*maxres
1368 logical :: PRINT_AMTS_MSG = .false.
1369 integer :: count,rstcount !ilen,
1371 character(len=50) :: tytul
1372 integer :: maxcount_scale = 10
1373 !el common /gucio/ cm
1374 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1375 !el common /stochcalc/ stochforcvec
1376 integer :: itime,itt,i,j,itsplit
1378 !el common /cipiszcze/ itt
1380 real(kind=8) :: epdrift,tt0,epdriftmax
1383 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1387 if (large.and. mod(itime,ntwe).eq.0) then
1388 write (iout,*) "***************** RESPA itime",itime
1389 write (iout,*) "Cartesian and internal coordinates: step 0"
1391 call pdbout(0.0d0,"cipiszcze",iout)
1393 write (iout,*) "Accelerations from long-range forces"
1395 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1396 (d_a(j,i+nres),j=1,3)
1398 write (iout,*) "Velocities, step 0"
1400 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1401 (d_t(j,i+nres),j=1,3)
1406 ! Perform the initial RESPA step (increment velocities)
1407 ! write (iout,*) "*********************** RESPA ini"
1410 if (mod(itime,ntwe).eq.0 .and. large) then
1411 write (iout,*) "Velocities, end"
1413 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1414 (d_t(j,i+nres),j=1,3)
1418 ! Compute the short-range forces
1424 ! 7/2/2009 commented out
1426 ! call etotal_short(energia_short)
1429 ! 7/2/2009 Copy accelerations due to short-lange forces from previous MD step
1432 d_a(j,i)=d_a_short(j,i)
1436 if (large.and. mod(itime,ntwe).eq.0) then
1437 write (iout,*) "energia_short",energia_short(0)
1438 write (iout,*) "Accelerations from short-range forces"
1440 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1441 (d_a(j,i+nres),j=1,3)
1446 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1448 t_enegrad=t_enegrad+tcpu()-tt0
1453 d_t_old(j,i)=d_t(j,i)
1454 d_a_old(j,i)=d_a(j,i)
1457 ! 6/30/08 A-MTS: attempt at increasing the split number
1460 dc_old0(j,i)=dc_old(j,i)
1461 d_t_old0(j,i)=d_t_old(j,i)
1462 d_a_old0(j,i)=d_a_old(j,i)
1465 if (ntime_split.gt.ntime_split0) ntime_split=ntime_split/2
1466 if (ntime_split.lt.ntime_split0) ntime_split=ntime_split0
1473 ! write (iout,*) "itime",itime," ntime_split",ntime_split
1474 ! Split the time step
1475 d_time=d_time0/ntime_split
1476 ! Perform the short-range RESPA steps (velocity Verlet increments of
1477 ! positions and velocities using short-range forces)
1478 ! write (iout,*) "*********************** RESPA split"
1479 do itsplit=1,ntime_split
1482 else if (lang.eq.2 .or. lang.eq.3) then
1484 call stochastic_force(stochforcvec)
1487 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1489 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1494 ! First step of the velocity Verlet algorithm
1499 else if (lang.eq.3) then
1501 call sd_verlet1_ciccotti
1503 else if (lang.eq.1) then
1508 ! Build the chain from the newly calculated coordinates
1509 call chainbuild_cart
1510 if (rattle) call rattle1
1512 if (large.and. mod(itime,ntwe).eq.0) then
1513 write (iout,*) "***** ITSPLIT",itsplit
1514 write (iout,*) "Cartesian and internal coordinates: step 1"
1515 call pdbout(0.0d0,"cipiszcze",iout)
1518 write (iout,*) "Velocities, step 1"
1520 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1521 (d_t(j,i+nres),j=1,3)
1530 ! Calculate energy and forces
1532 call etotal_short(energia_short)
1533 if (large.and. mod(itime,ntwe).eq.0) &
1534 call enerprint(energia_short)
1537 t_eshort=t_eshort+MPI_Wtime()-tt0
1539 t_eshort=t_eshort+tcpu()-tt0
1543 ! Get the new accelerations
1545 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
1548 d_a_short(j,i)=d_a(j,i)
1552 if (large.and. mod(itime,ntwe).eq.0) then
1553 write (iout,*)"energia_short",energia_short(0)
1554 write (iout,*) "Accelerations from short-range forces"
1556 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1557 (d_a(j,i+nres),j=1,3)
1562 ! Determine maximum acceleration and scale down the timestep if needed
1564 amax=amax/ntime_split**2
1565 call predict_edrift(epdrift)
1566 if (ntwe.gt.0 .and. large .and. mod(itime,ntwe).eq.0) &
1567 write (iout,*) "amax",amax," damax",damax,&
1568 " epdrift",epdrift," epdriftmax",epdriftmax
1569 ! Exit loop and try with increased split number if the change of
1570 ! acceleration is too big
1571 if (amax.gt.damax .or. epdrift.gt.edriftmax) then
1572 if (ntime_split.lt.maxtime_split) then
1574 ntime_split=ntime_split*2
1577 dc_old(j,i)=dc_old0(j,i)
1578 d_t_old(j,i)=d_t_old0(j,i)
1579 d_a_old(j,i)=d_a_old0(j,i)
1582 if (PRINT_AMTS_MSG) then
1583 write (iout,*) "acceleration/energy drift too large",amax,&
1584 epdrift," split increased to ",ntime_split," itime",itime,&
1590 "Uh-hu. Bumpy landscape. Maximum splitting number",&
1592 " already reached!!! Trying to carry on!"
1596 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1598 t_enegrad=t_enegrad+tcpu()-tt0
1600 ! Second step of the velocity Verlet algorithm
1605 else if (lang.eq.3) then
1607 call sd_verlet2_ciccotti
1609 else if (lang.eq.1) then
1614 if (rattle) call rattle2
1615 ! Backup the coordinates, velocities, and accelerations
1619 d_t_old(j,i)=d_t(j,i)
1620 d_a_old(j,i)=d_a(j,i)
1627 ! Restore the time step
1629 ! Compute long-range forces
1636 call etotal_long(energia_long)
1637 if (large.and. mod(itime,ntwe).eq.0) &
1638 call enerprint(energia_long)
1641 t_elong=t_elong+MPI_Wtime()-tt0
1643 t_elong=t_elong+tcpu()-tt0
1649 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1651 t_enegrad=t_enegrad+tcpu()-tt0
1653 ! Compute accelerations from long-range forces
1655 if (large.and. mod(itime,ntwe).eq.0) then
1656 write (iout,*) "energia_long",energia_long(0)
1657 write (iout,*) "Cartesian and internal coordinates: step 2"
1659 call pdbout(0.0d0,"cipiszcze",iout)
1661 write (iout,*) "Accelerations from long-range forces"
1663 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1664 (d_a(j,i+nres),j=1,3)
1666 write (iout,*) "Velocities, step 2"
1668 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1669 (d_t(j,i+nres),j=1,3)
1673 ! Compute the final RESPA step (increment velocities)
1674 ! write (iout,*) "*********************** RESPA fin"
1676 ! Compute the complete potential energy
1678 potEcomp(i)=energia_short(i)+energia_long(i)
1680 potE=potEcomp(0)-potEcomp(20)
1681 ! potE=energia_short(0)+energia_long(0)
1683 ! Calculate the kinetic and the total energy and the kinetic temperature
1686 ! Couple the system to Berendsen bath if needed
1687 if (tbf .and. lang.eq.0) then
1690 kinetic_T=2.0d0/(dimen3*Rb)*EK
1691 ! Backup the coordinates, velocities, and accelerations
1693 if (mod(itime,ntwe).eq.0 .and. large) then
1694 write (iout,*) "Velocities, end"
1696 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1697 (d_t(j,i+nres),j=1,3)
1702 end subroutine RESPA_step
1703 !-----------------------------------------------------------------------------
1704 subroutine RESPA_vel
1705 ! First and last RESPA step (incrementing velocities using long-range
1708 ! implicit real*8 (a-h,o-z)
1709 ! include 'DIMENSIONS'
1710 ! include 'COMMON.CONTROL'
1711 ! include 'COMMON.VAR'
1712 ! include 'COMMON.MD'
1713 ! include 'COMMON.CHAIN'
1714 ! include 'COMMON.DERIV'
1715 ! include 'COMMON.GEO'
1716 ! include 'COMMON.LOCAL'
1717 ! include 'COMMON.INTERACT'
1718 ! include 'COMMON.IOUNITS'
1719 ! include 'COMMON.NAMES'
1720 integer :: i,j,inres
1723 d_t(j,0)=d_t(j,0)+0.5d0*d_a(j,0)*d_time
1727 d_t(j,i)=d_t(j,i)+0.5d0*d_a(j,i)*d_time
1731 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1734 d_t(j,inres)=d_t(j,inres)+0.5d0*d_a(j,inres)*d_time
1739 end subroutine RESPA_vel
1740 !-----------------------------------------------------------------------------
1742 ! Applying velocity Verlet algorithm - step 1 to coordinates
1744 ! implicit real*8 (a-h,o-z)
1745 ! include 'DIMENSIONS'
1746 ! include 'COMMON.CONTROL'
1747 ! include 'COMMON.VAR'
1748 ! include 'COMMON.MD'
1749 ! include 'COMMON.CHAIN'
1750 ! include 'COMMON.DERIV'
1751 ! include 'COMMON.GEO'
1752 ! include 'COMMON.LOCAL'
1753 ! include 'COMMON.INTERACT'
1754 ! include 'COMMON.IOUNITS'
1755 ! include 'COMMON.NAMES'
1756 real(kind=8) :: adt,adt2
1757 integer :: i,j,inres
1760 write (iout,*) "VELVERLET1 START: DC"
1762 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1763 (dc(j,i+nres),j=1,3)
1767 adt=d_a_old(j,0)*d_time
1769 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1770 d_t_new(j,0)=d_t_old(j,0)+adt2
1771 d_t(j,0)=d_t_old(j,0)+adt
1775 adt=d_a_old(j,i)*d_time
1777 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1778 d_t_new(j,i)=d_t_old(j,i)+adt2
1779 d_t(j,i)=d_t_old(j,i)+adt
1783 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1786 adt=d_a_old(j,inres)*d_time
1788 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1789 d_t_new(j,inres)=d_t_old(j,inres)+adt2
1790 d_t(j,inres)=d_t_old(j,inres)+adt
1795 write (iout,*) "VELVERLET1 END: DC"
1797 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1798 (dc(j,i+nres),j=1,3)
1802 end subroutine verlet1
1803 !-----------------------------------------------------------------------------
1805 ! Step 2 of the velocity Verlet algorithm: update velocities
1807 ! implicit real*8 (a-h,o-z)
1808 ! include 'DIMENSIONS'
1809 ! include 'COMMON.CONTROL'
1810 ! include 'COMMON.VAR'
1811 ! include 'COMMON.MD'
1812 ! include 'COMMON.CHAIN'
1813 ! include 'COMMON.DERIV'
1814 ! include 'COMMON.GEO'
1815 ! include 'COMMON.LOCAL'
1816 ! include 'COMMON.INTERACT'
1817 ! include 'COMMON.IOUNITS'
1818 ! include 'COMMON.NAMES'
1819 integer :: i,j,inres
1822 d_t(j,0)=d_t_new(j,0)+0.5d0*d_a(j,0)*d_time
1826 d_t(j,i)=d_t_new(j,i)+0.5d0*d_a(j,i)*d_time
1830 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1833 d_t(j,inres)=d_t_new(j,inres)+0.5d0*d_a(j,inres)*d_time
1838 end subroutine verlet2
1839 !-----------------------------------------------------------------------------
1840 subroutine sddir_precalc
1841 ! Applying velocity Verlet algorithm - step 1 to coordinates
1842 ! implicit real*8 (a-h,o-z)
1843 ! include 'DIMENSIONS'
1849 ! include 'COMMON.CONTROL'
1850 ! include 'COMMON.VAR'
1851 ! include 'COMMON.MD'
1853 ! include 'COMMON.LANGEVIN'
1855 ! include 'COMMON.LANGEVIN.lang0'
1857 ! include 'COMMON.CHAIN'
1858 ! include 'COMMON.DERIV'
1859 ! include 'COMMON.GEO'
1860 ! include 'COMMON.LOCAL'
1861 ! include 'COMMON.INTERACT'
1862 ! include 'COMMON.IOUNITS'
1863 ! include 'COMMON.NAMES'
1864 ! include 'COMMON.TIME1'
1865 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1866 !el common /stochcalc/ stochforcvec
1867 real(kind=8) :: time00
1869 ! Compute friction and stochastic forces
1874 time_fric=time_fric+MPI_Wtime()-time00
1876 call stochastic_force(stochforcvec)
1877 time_stoch=time_stoch+MPI_Wtime()-time00
1880 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
1881 ! forces (d_as_work)
1883 call ginv_mult(fric_work, d_af_work)
1884 call ginv_mult(stochforcvec, d_as_work)
1886 end subroutine sddir_precalc
1887 !-----------------------------------------------------------------------------
1888 subroutine sddir_verlet1
1889 ! Applying velocity Verlet algorithm - step 1 to velocities
1892 ! implicit real*8 (a-h,o-z)
1893 ! include 'DIMENSIONS'
1894 ! include 'COMMON.CONTROL'
1895 ! include 'COMMON.VAR'
1896 ! include 'COMMON.MD'
1898 ! include 'COMMON.LANGEVIN'
1900 ! include 'COMMON.LANGEVIN.lang0'
1902 ! include 'COMMON.CHAIN'
1903 ! include 'COMMON.DERIV'
1904 ! include 'COMMON.GEO'
1905 ! include 'COMMON.LOCAL'
1906 ! include 'COMMON.INTERACT'
1907 ! include 'COMMON.IOUNITS'
1908 ! include 'COMMON.NAMES'
1909 ! Revised 3/31/05 AL: correlation between random contributions to
1910 ! position and velocity increments included.
1911 real(kind=8) :: sqrt13 = 0.57735026918962576451d0 ! 1/sqrt(3)
1912 real(kind=8) :: adt,adt2
1913 integer :: i,j,ind,inres
1915 ! Add the contribution from BOTH friction and stochastic force to the
1916 ! coordinates, but ONLY the contribution from the friction forces to velocities
1919 adt=(d_a_old(j,0)+d_af_work(j))*d_time
1920 adt2=0.5d0*adt+sqrt13*d_as_work(j)*d_time
1921 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1922 d_t_new(j,0)=d_t_old(j,0)+0.5d0*adt
1923 d_t(j,0)=d_t_old(j,0)+adt
1928 adt=(d_a_old(j,i)+d_af_work(ind+j))*d_time
1929 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
1930 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1931 d_t_new(j,i)=d_t_old(j,i)+0.5d0*adt
1932 d_t(j,i)=d_t_old(j,i)+adt
1937 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1940 adt=(d_a_old(j,inres)+d_af_work(ind+j))*d_time
1941 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
1942 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1943 d_t_new(j,inres)=d_t_old(j,inres)+0.5d0*adt
1944 d_t(j,inres)=d_t_old(j,inres)+adt
1950 end subroutine sddir_verlet1
1951 !-----------------------------------------------------------------------------
1952 subroutine sddir_verlet2
1953 ! Calculating the adjusted velocities for accelerations
1956 ! implicit real*8 (a-h,o-z)
1957 ! include 'DIMENSIONS'
1958 ! include 'COMMON.CONTROL'
1959 ! include 'COMMON.VAR'
1960 ! include 'COMMON.MD'
1962 ! include 'COMMON.LANGEVIN'
1964 ! include 'COMMON.LANGEVIN.lang0'
1966 ! include 'COMMON.CHAIN'
1967 ! include 'COMMON.DERIV'
1968 ! include 'COMMON.GEO'
1969 ! include 'COMMON.LOCAL'
1970 ! include 'COMMON.INTERACT'
1971 ! include 'COMMON.IOUNITS'
1972 ! include 'COMMON.NAMES'
1973 real(kind=8),dimension(6*nres) :: stochforcvec,d_as_work1 !(MAXRES6) maxres6=6*maxres
1974 real(kind=8) :: cos60 = 0.5d0, sin60 = 0.86602540378443864676d0
1975 integer :: i,j,ind,inres
1976 ! Revised 3/31/05 AL: correlation between random contributions to
1977 ! position and velocity increments included.
1978 ! The correlation coefficients are calculated at low-friction limit.
1979 ! Also, friction forces are now not calculated with new velocities.
1981 ! call friction_force
1982 call stochastic_force(stochforcvec)
1984 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
1985 ! forces (d_as_work)
1987 call ginv_mult(stochforcvec, d_as_work1)
1993 d_t(j,0)=d_t_new(j,0)+(0.5d0*(d_a(j,0)+d_af_work(j)) &
1994 +sin60*d_as_work(j)+cos60*d_as_work1(j))*d_time
1999 d_t(j,i)=d_t_new(j,i)+(0.5d0*(d_a(j,i)+d_af_work(ind+j)) &
2000 +sin60*d_as_work(ind+j)+cos60*d_as_work1(ind+j))*d_time
2005 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2008 d_t(j,inres)=d_t_new(j,inres)+(0.5d0*(d_a(j,inres) &
2009 +d_af_work(ind+j))+sin60*d_as_work(ind+j) &
2010 +cos60*d_as_work1(ind+j))*d_time
2016 end subroutine sddir_verlet2
2017 !-----------------------------------------------------------------------------
2018 subroutine max_accel
2020 ! Find the maximum difference in the accelerations of the the sites
2021 ! at the beginning and the end of the time step.
2024 ! implicit real*8 (a-h,o-z)
2025 ! include 'DIMENSIONS'
2026 ! include 'COMMON.CONTROL'
2027 ! include 'COMMON.VAR'
2028 ! include 'COMMON.MD'
2029 ! include 'COMMON.CHAIN'
2030 ! include 'COMMON.DERIV'
2031 ! include 'COMMON.GEO'
2032 ! include 'COMMON.LOCAL'
2033 ! include 'COMMON.INTERACT'
2034 ! include 'COMMON.IOUNITS'
2035 real(kind=8),dimension(3) :: aux,accel,accel_old
2036 real(kind=8) :: dacc
2040 ! aux(j)=d_a(j,0)-d_a_old(j,0)
2041 accel_old(j)=d_a_old(j,0)
2048 ! 7/3/08 changed to asymmetric difference
2050 ! accel(j)=aux(j)+0.5d0*(d_a(j,i)-d_a_old(j,i))
2051 accel_old(j)=accel_old(j)+0.5d0*d_a_old(j,i)
2052 accel(j)=accel(j)+0.5d0*d_a(j,i)
2053 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2054 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2055 dacc=dabs(accel(j)-accel_old(j))
2056 ! write (iout,*) i,dacc
2057 if (dacc.gt.amax) amax=dacc
2065 accel_old(j)=d_a_old(j,0)
2070 accel_old(j)=accel_old(j)+d_a_old(j,1)
2071 accel(j)=accel(j)+d_a(j,1)
2075 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2077 ! accel(j)=accel(j)+d_a(j,i+nres)-d_a_old(j,i+nres)
2078 accel_old(j)=accel_old(j)+d_a_old(j,i+nres)
2079 accel(j)=accel(j)+d_a(j,i+nres)
2083 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2084 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2085 dacc=dabs(accel(j)-accel_old(j))
2086 ! write (iout,*) "side-chain",i,dacc
2087 if (dacc.gt.amax) amax=dacc
2091 accel_old(j)=accel_old(j)+d_a_old(j,i)
2092 accel(j)=accel(j)+d_a(j,i)
2093 ! aux(j)=aux(j)+d_a(j,i)-d_a_old(j,i)
2097 end subroutine max_accel
2098 !-----------------------------------------------------------------------------
2099 subroutine predict_edrift(epdrift)
2101 ! Predict the drift of the potential energy
2104 use control_data, only: lmuca
2105 ! implicit real*8 (a-h,o-z)
2106 ! include 'DIMENSIONS'
2107 ! include 'COMMON.CONTROL'
2108 ! include 'COMMON.VAR'
2109 ! include 'COMMON.MD'
2110 ! include 'COMMON.CHAIN'
2111 ! include 'COMMON.DERIV'
2112 ! include 'COMMON.GEO'
2113 ! include 'COMMON.LOCAL'
2114 ! include 'COMMON.INTERACT'
2115 ! include 'COMMON.IOUNITS'
2116 ! include 'COMMON.MUCA'
2117 real(kind=8) :: epdrift,epdriftij
2119 ! Drift of the potential energy
2125 epdriftij=dabs((d_a(j,i)-d_a_old(j,i))*gcart(j,i))
2126 if (lmuca) epdriftij=epdriftij*factor
2127 ! write (iout,*) "back",i,j,epdriftij
2128 if (epdriftij.gt.epdrift) epdrift=epdriftij
2132 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2135 dabs((d_a(j,i+nres)-d_a_old(j,i+nres))*gxcart(j,i))
2136 if (lmuca) epdriftij=epdriftij*factor
2137 ! write (iout,*) "side",i,j,epdriftij
2138 if (epdriftij.gt.epdrift) epdrift=epdriftij
2142 epdrift=0.5d0*epdrift*d_time*d_time
2143 ! write (iout,*) "epdrift",epdrift
2145 end subroutine predict_edrift
2146 !-----------------------------------------------------------------------------
2147 subroutine verlet_bath
2149 ! Coupling to the thermostat by using the Berendsen algorithm
2152 ! implicit real*8 (a-h,o-z)
2153 ! include 'DIMENSIONS'
2154 ! include 'COMMON.CONTROL'
2155 ! include 'COMMON.VAR'
2156 ! include 'COMMON.MD'
2157 ! include 'COMMON.CHAIN'
2158 ! include 'COMMON.DERIV'
2159 ! include 'COMMON.GEO'
2160 ! include 'COMMON.LOCAL'
2161 ! include 'COMMON.INTERACT'
2162 ! include 'COMMON.IOUNITS'
2163 ! include 'COMMON.NAMES'
2164 real(kind=8) :: T_half,fact
2165 integer :: i,j,inres
2167 T_half=2.0d0/(dimen3*Rb)*EK
2168 fact=dsqrt(1.0d0+(d_time/tau_bath)*(t_bath/T_half-1.0d0))
2169 ! write(iout,*) "T_half", T_half
2170 ! write(iout,*) "EK", EK
2171 ! write(iout,*) "fact", fact
2173 d_t(j,0)=fact*d_t(j,0)
2177 d_t(j,i)=fact*d_t(j,i)
2181 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2184 d_t(j,inres)=fact*d_t(j,inres)
2189 end subroutine verlet_bath
2190 !-----------------------------------------------------------------------------
2192 ! Set up the initial conditions of a MD simulation
2195 use control, only:tcpu
2196 !el use io_basic, only:ilen
2199 use minimm, only:minim_dc,minimize,sc_move
2200 use io_config, only:readrst
2201 use io, only:statout
2202 ! implicit real*8 (a-h,o-z)
2203 ! include 'DIMENSIONS'
2206 character(len=16) :: form
2207 integer :: IERROR,ERRCODE
2209 ! include 'COMMON.SETUP'
2210 ! include 'COMMON.CONTROL'
2211 ! include 'COMMON.VAR'
2212 ! include 'COMMON.MD'
2214 ! include 'COMMON.LANGEVIN'
2216 ! include 'COMMON.LANGEVIN.lang0'
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.NAMES'
2225 ! include 'COMMON.REMD'
2226 real(kind=8),dimension(0:n_ene) :: energia_long,energia_short
2227 real(kind=8),dimension(3) :: vcm,incr,L
2228 real(kind=8) :: xv,sigv,lowb,highb
2229 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
2230 character(len=256) :: qstr
2233 character(len=50) :: tytul
2234 logical :: file_exist
2235 !el common /gucio/ cm
2236 integer :: i,j,ipos,iq,iw,nft_sc,iretcode,nfun,itime,ierr
2237 real(kind=8) :: etot,tt0
2241 ! write(iout,*) "d_time", d_time
2242 ! Compute the standard deviations of stochastic forces for Langevin dynamics
2243 ! if the friction coefficients do not depend on surface area
2244 if (lang.gt.0 .and. .not.surfarea) then
2246 stdforcp(i)=stdfp*dsqrt(gamp)
2249 stdforcsc(i)=stdfsc(iabs(itype(i))) &
2250 *dsqrt(gamsc(iabs(itype(i))))
2253 ! Open the pdb file for snapshotshots
2256 if (ilen(tmpdir).gt.0) &
2257 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2258 liczba(:ilen(liczba))//".pdb")
2260 file=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2264 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2265 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2266 liczba(:ilen(liczba))//".x")
2267 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2270 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2271 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2272 liczba(:ilen(liczba))//".cx")
2273 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2279 if (ilen(tmpdir).gt.0) &
2280 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.pdb")
2281 open(ipdb,file=prefix(:ilen(prefix))//"_MD.pdb")
2283 if (ilen(tmpdir).gt.0) &
2284 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.cx")
2285 cartname=prefix(:ilen(prefix))//"_MD.cx"
2289 write (qstr,'(256(1h ))')
2292 iq = qinfrag(i,iset)*10
2293 iw = wfrag(i,iset)/100
2295 if(me.eq.king.or..not.out1file) &
2296 write (iout,*) "Frag",qinfrag(i,iset),wfrag(i,iset),iq,iw
2297 write (qstr(ipos:ipos+6),'(2h_f,i1,1h_,i1,1h_,i1)') i,iq,iw
2302 iq = qinpair(i,iset)*10
2303 iw = wpair(i,iset)/100
2305 if(me.eq.king.or..not.out1file) &
2306 write (iout,*) "Pair",i,qinpair(i,iset),wpair(i,iset),iq,iw
2307 write (qstr(ipos:ipos+6),'(2h_p,i1,1h_,i1,1h_,i1)') i,iq,iw
2311 ! pdbname=pdbname(:ilen(pdbname)-4)//qstr(:ipos-1)//'.pdb'
2313 ! cartname=cartname(:ilen(cartname)-2)//qstr(:ipos-1)//'.x'
2315 ! cartname=cartname(:ilen(cartname)-3)//qstr(:ipos-1)//'.cx'
2317 ! statname=statname(:ilen(statname)-5)//qstr(:ipos-1)//'.stat'
2321 if (restart1file) then
2323 inquire(file=mremd_rst_name,exist=file_exist)
2324 write (*,*) me," Before broadcast: file_exist",file_exist
2326 call MPI_Bcast(file_exist,1,MPI_LOGICAL,king,CG_COMM,&
2329 write (*,*) me," After broadcast: file_exist",file_exist
2330 ! inquire(file=mremd_rst_name,exist=file_exist)
2331 if(me.eq.king.or..not.out1file) &
2332 write(iout,*) "Initial state read by master and distributed"
2334 if (ilen(tmpdir).gt.0) &
2335 call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_' &
2336 //liczba(:ilen(liczba))//'.rst')
2337 inquire(file=rest2name,exist=file_exist)
2340 if(.not.restart1file) then
2341 if(me.eq.king.or..not.out1file) &
2342 write(iout,*) "Initial state will be read from file ",&
2343 rest2name(:ilen(rest2name))
2346 call rescale_weights(t_bath)
2348 if(me.eq.king.or..not.out1file)then
2349 if (restart1file) then
2350 write(iout,*) "File ",mremd_rst_name(:ilen(mremd_rst_name)),&
2353 write(iout,*) "File ",rest2name(:ilen(rest2name)),&
2356 write(iout,*) "Initial velocities randomly generated"
2362 ! Generate initial velocities
2363 if(me.eq.king.or..not.out1file) &
2364 write(iout,*) "Initial velocities randomly generated"
2368 ! rest2name = prefix(:ilen(prefix))//'.rst'
2369 if(me.eq.king.or..not.out1file)then
2370 write (iout,*) "Initial velocities"
2372 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2373 (d_t(j,i+nres),j=1,3)
2375 ! Zeroing the total angular momentum of the system
2376 write(iout,*) "Calling the zero-angular momentum subroutine"
2379 ! Getting the potential energy and forces and velocities and accelerations
2381 ! write (iout,*) "velocity of the center of the mass:"
2382 ! write (iout,*) (vcm(j),j=1,3)
2384 d_t(j,0)=d_t(j,0)-vcm(j)
2386 ! Removing the velocity of the center of mass
2388 if(me.eq.king.or..not.out1file)then
2389 write (iout,*) "vcm right after adjustment:"
2390 write (iout,*) (vcm(j),j=1,3)
2394 if(iranconf.ne.0) then
2396 print *, 'Calling OVERLAP_SC'
2397 call overlap_sc(fail)
2400 call sc_move(2,nres-1,10,1d10,nft_sc,etot)
2401 print *,'SC_move',nft_sc,etot
2402 if(me.eq.king.or..not.out1file) &
2403 write(iout,*) 'SC_move',nft_sc,etot
2407 print *, 'Calling MINIM_DC'
2408 call minim_dc(etot,iretcode,nfun)
2410 call geom_to_var(nvar,varia)
2411 print *,'Calling MINIMIZE.'
2412 call minimize(etot,varia,iretcode,nfun)
2413 call var_to_geom(nvar,varia)
2415 if(me.eq.king.or..not.out1file) &
2416 write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
2419 call chainbuild_cart
2424 kinetic_T=2.0d0/(dimen3*Rb)*EK
2425 if(me.eq.king.or..not.out1file)then
2435 call etotal(potEcomp)
2436 if (large) call enerprint(potEcomp)
2439 t_etotal=t_etotal+MPI_Wtime()-tt0
2441 t_etotal=t_etotal+tcpu()-tt0
2448 if (amax*d_time .gt. dvmax) then
2449 d_time=d_time*dvmax/amax
2450 if(me.eq.king.or..not.out1file) write (iout,*) &
2451 "Time step reduced to",d_time,&
2452 " because of too large initial acceleration."
2454 if(me.eq.king.or..not.out1file)then
2455 write(iout,*) "Potential energy and its components"
2456 call enerprint(potEcomp)
2457 ! write(iout,*) (potEcomp(i),i=0,n_ene)
2459 potE=potEcomp(0)-potEcomp(20)
2462 if (ntwe.ne.0) call statout(itime)
2463 if(me.eq.king.or..not.out1file) &
2464 write (iout,'(/a/3(a25,1pe14.5/))') "Initial:", &
2465 " Kinetic energy",EK," Potential energy",potE, &
2466 " Total energy",totE," Maximum acceleration ", &
2469 write (iout,*) "Initial coordinates"
2471 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(c(j,i),j=1,3),&
2474 write (iout,*) "Initial dC"
2476 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
2477 (dc(j,i+nres),j=1,3)
2479 write (iout,*) "Initial velocities"
2480 write (iout,"(13x,' backbone ',23x,' side chain')")
2482 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2483 (d_t(j,i+nres),j=1,3)
2485 write (iout,*) "Initial accelerations"
2487 ! write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
2488 write (iout,'(i3,3f15.10,3x,3f15.10)') i,(d_a(j,i),j=1,3),&
2489 (d_a(j,i+nres),j=1,3)
2495 d_t_old(j,i)=d_t(j,i)
2496 d_a_old(j,i)=d_a(j,i)
2498 ! write (iout,*) "dc_old",i,(dc_old(j,i),j=1,3)
2507 call etotal_short(energia_short)
2508 if (large) call enerprint(potEcomp)
2511 t_eshort=t_eshort+MPI_Wtime()-tt0
2513 t_eshort=t_eshort+tcpu()-tt0
2518 if(.not.out1file .and. large) then
2519 write (iout,*) "energia_long",energia_long(0),&
2520 " energia_short",energia_short(0),&
2521 " total",energia_long(0)+energia_short(0)
2522 write (iout,*) "Initial fast-force accelerations"
2524 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2525 (d_a(j,i+nres),j=1,3)
2528 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
2531 d_a_short(j,i)=d_a(j,i)
2540 call etotal_long(energia_long)
2541 if (large) call enerprint(potEcomp)
2544 t_elong=t_elong+MPI_Wtime()-tt0
2546 t_elong=t_elong+tcpu()-tt0
2551 if(.not.out1file .and. large) then
2552 write (iout,*) "energia_long",energia_long(0)
2553 write (iout,*) "Initial slow-force accelerations"
2555 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2556 (d_a(j,i+nres),j=1,3)
2560 t_enegrad=t_enegrad+MPI_Wtime()-tt0
2562 t_enegrad=t_enegrad+tcpu()-tt0
2566 end subroutine init_MD
2567 !-----------------------------------------------------------------------------
2568 subroutine random_vel
2570 ! implicit real*8 (a-h,o-z)
2572 use random, only:anorm_distr
2574 ! include 'DIMENSIONS'
2575 ! include 'COMMON.CONTROL'
2576 ! include 'COMMON.VAR'
2577 ! include 'COMMON.MD'
2579 ! include 'COMMON.LANGEVIN'
2581 ! include 'COMMON.LANGEVIN.lang0'
2583 ! include 'COMMON.CHAIN'
2584 ! include 'COMMON.DERIV'
2585 ! include 'COMMON.GEO'
2586 ! include 'COMMON.LOCAL'
2587 ! include 'COMMON.INTERACT'
2588 ! include 'COMMON.IOUNITS'
2589 ! include 'COMMON.NAMES'
2590 ! include 'COMMON.TIME1'
2591 real(kind=8) :: xv,sigv,lowb,highb ,Ek1
2593 real(kind=8) ,allocatable, dimension(:) :: DDU1,DDU2,DL2,DL1,xsolv,DML,rs
2594 real(kind=8) :: sumx
2596 real(kind=8) ,allocatable, dimension(:) :: rsold
2597 real (kind=8),allocatable,dimension(:,:) :: matold
2600 integer :: i,j,ii,k,ind,mark,imark
2601 ! Generate random velocities from Gaussian distribution of mean 0 and std of KT/m
2602 ! First generate velocities in the eigenspace of the G matrix
2603 ! write (iout,*) "Calling random_vel dimen dimen3",dimen,dimen3
2610 sigv=dsqrt((Rb*t_bath)/geigen(i))
2613 d_t_work_new(ii)=anorm_distr(xv,sigv,lowb,highb)
2615 write (iout,*) "i",i," ii",ii," geigen",geigen(i),&
2616 " d_t_work_new",d_t_work_new(ii)
2627 Ek1=Ek1+0.5d0*geigen(i)*d_t_work_new(ii)**2
2630 write (iout,*) "Ek from eigenvectors",Ek1
2631 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2635 ! Transform velocities to UNRES coordinate space
2636 allocate (DL1(2*nres))
2637 allocate (DDU1(2*nres))
2638 allocate (DL2(2*nres))
2639 allocate (DDU2(2*nres))
2640 allocate (xsolv(2*nres))
2641 allocate (DML(2*nres))
2642 allocate (rs(2*nres))
2644 allocate (rsold(2*nres))
2645 allocate (matold(2*nres,2*nres))
2647 matold(1,1)=DMorig(1)
2648 matold(1,2)=DU1orig(1)
2649 matold(1,3)=DU2orig(1)
2650 write (*,*) DMorig(1),DU1orig(1),DU2orig(1)
2655 matold(i,j)=DMorig(i)
2656 matold(i,j-1)=DU1orig(i-1)
2658 matold(i,j-2)=DU2orig(i-2)
2666 matold(i,j+1)=DU1orig(i)
2672 matold(i,j+2)=DU2orig(i)
2676 matold(dimen,dimen)=DMorig(dimen)
2677 matold(dimen,dimen-1)=DU1orig(dimen-1)
2678 matold(dimen,dimen-2)=DU2orig(dimen-2)
2679 write(iout,*) "old gmatrix"
2680 call matout(dimen,dimen,2*nres,2*nres,matold)
2684 ! Find the ith eigenvector of the pentadiagonal inertiq matrix
2688 DML(j)=DMorig(j)-geigen(i)
2691 DML(j-1)=DMorig(j)-geigen(i)
2696 DDU1(imark-1)=DU2orig(imark-1)
2697 do j=imark+1,dimen-1
2698 DDU1(j-1)=DU1orig(j)
2706 DDU2(j)=DU2orig(j+1)
2715 write (iout,*) "DL2,DL1,DML,DDU1,DDU2"
2716 write(iout,'(10f10.5)') (DL2(k),k=3,dimen-1)
2717 write(iout,'(10f10.5)') (DL1(k),k=2,dimen-1)
2718 write(iout,'(10f10.5)') (DML(k),k=1,dimen-1)
2719 write(iout,'(10f10.5)') (DDU1(k),k=1,dimen-2)
2720 write(iout,'(10f10.5)') (DDU2(k),k=1,dimen-3)
2723 if (imark.gt.2) rs(imark-2)=-DU2orig(imark-2)
2724 if (imark.gt.1) rs(imark-1)=-DU1orig(imark-1)
2725 if (imark.lt.dimen) rs(imark)=-DU1orig(imark)
2726 if (imark.lt.dimen-1) rs(imark+1)=-DU2orig(imark)
2730 ! write (iout,*) "Vector rs"
2732 ! write (iout,*) j,rs(j)
2735 call FDIAG(dimen-1,DL2,DL1,DML,DDU1,DDU2,rs,xsolv,mark)
2742 sumx=-geigen(i)*xsolv(j)
2744 sumx=sumx+matold(j,k)*xsolv(k)
2747 sumx=sumx+matold(j,k)*xsolv(k-1)
2749 write(iout,'(i5,3f10.5)') j,sumx,rsold(j),sumx-rsold(j)
2752 sumx=-geigen(i)*xsolv(j-1)
2754 sumx=sumx+matold(j,k)*xsolv(k)
2757 sumx=sumx+matold(j,k)*xsolv(k-1)
2759 write(iout,'(i5,3f10.5)') j-1,sumx,rsold(j-1),sumx-rsold(j-1)
2763 "Solution of equations system",i," for eigenvalue",geigen(i)
2765 write(iout,'(i5,f10.5)') j,xsolv(j)
2768 do j=dimen-1,imark,-1
2773 write (iout,*) "Un-normalized eigenvector",i," for eigenvalue",geigen(i)
2775 write(iout,'(i5,f10.5)') j,xsolv(j)
2778 ! Normalize ith eigenvector
2781 sumx=sumx+xsolv(j)**2
2785 xsolv(j)=xsolv(j)/sumx
2788 write (iout,*) "Eigenvector",i," for eigenvalue",geigen(i)
2790 write(iout,'(i5,3f10.5)') j,xsolv(j)
2793 ! All done at this point for eigenvector i, exit loop
2801 write (iout,*) "Unable to find eigenvector",i
2804 ! write (iout,*) "i=",i
2806 ! write (iout,*) "k=",k
2809 ! write(iout,*) "ind",ind," ind1",3*(i-1)+k
2810 d_t_work(ind)=d_t_work(ind) &
2811 +xsolv(j)*d_t_work_new(3*(i-1)+k)
2814 enddo ! i (loop over the eigenvectors)
2817 write (iout,*) "d_t_work"
2819 write (iout,"(i5,f10.5)") i,d_t_work(i)
2824 if (itype(i).eq.10) then
2831 ! write (iout,*) "k",k," ii+k",ii+k," ii+j+k",ii+j+k,"EK1",Ek1
2832 Ek1=Ek1+0.5d0*mp*((d_t_work(ii+j+k)+d_t_work_new(ii+k))/2)**2+&
2833 0.5d0*0.25d0*IP*(d_t_work(ii+j+k)-d_t_work_new(ii+k))**2
2836 if (itype(i).ne.10) ii=ii+3
2837 write (iout,*) "i",i," itype",itype(i)," mass",msc(itype(i))
2838 write (iout,*) "ii",ii
2841 write (iout,*) "k",k," ii",ii,"EK1",EK1
2842 if (iabs(itype(i)).ne.10) Ek1=Ek1+0.5d0*Isc(iabs(itype(i)))*(d_t_work(ii)-d_t_work(ii-3))**2
2843 Ek1=Ek1+0.5d0*msc(iabs(itype(i)))*d_t_work(ii)**2
2845 write (iout,*) "i",i," ii",ii
2847 write (iout,*) "Ek from d_t_work",Ek1
2848 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2864 d_t(k,j)=d_t_work(ind)
2867 if (itype(j).ne.10 .and. itype(j).ne.ntyp1) then
2869 d_t(k,j+nres)=d_t_work(ind)
2875 write (iout,*) "Random velocities in the Calpha,SC space"
2877 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
2880 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
2887 if (itype(i).eq.10) then
2889 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
2893 d_t(j,i+nres)=d_t(j,i+nres)-d_t(j,i)
2894 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
2899 write (iout,*)"Random velocities in the virtual-bond-vector space"
2901 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
2904 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
2907 write (iout,*) "Ek from d_t_work",Ek1
2908 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2916 d_t_work(ind)=d_t_work(ind) &
2917 +Gvec(i,j)*d_t_work_new((j-1)*3+k+1)
2919 ! write (iout,*) "i",i," ind",ind," d_t_work",d_t_work(ind)
2923 ! Transfer to the d_t vector
2925 d_t(j,0)=d_t_work(j)
2931 d_t(j,i)=d_t_work(ind)
2935 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2938 d_t(j,i+nres)=d_t_work(ind)
2944 ! write (iout,*) "Kinetic energy",Ek,EK1," kinetic temperature",&
2945 ! 2.0d0/(dimen3*Rb)*EK,2.0d0/(dimen3*Rb)*EK1
2949 end subroutine random_vel
2950 !-----------------------------------------------------------------------------
2952 subroutine sd_verlet_p_setup
2953 ! Sets up the parameters of stochastic Verlet algorithm
2954 ! implicit real*8 (a-h,o-z)
2955 ! include 'DIMENSIONS'
2956 use control, only: tcpu
2961 ! include 'COMMON.CONTROL'
2962 ! include 'COMMON.VAR'
2963 ! include 'COMMON.MD'
2965 ! include 'COMMON.LANGEVIN'
2967 ! include 'COMMON.LANGEVIN.lang0'
2969 ! include 'COMMON.CHAIN'
2970 ! include 'COMMON.DERIV'
2971 ! include 'COMMON.GEO'
2972 ! include 'COMMON.LOCAL'
2973 ! include 'COMMON.INTERACT'
2974 ! include 'COMMON.IOUNITS'
2975 ! include 'COMMON.NAMES'
2976 ! include 'COMMON.TIME1'
2977 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
2978 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
2979 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
2980 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
2981 logical :: lprn = .false.
2982 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
2983 real(kind=8) :: ktm,gdt,egdt,gdt2,gdt3,gdt4,gdt5,gdt6,gdt7,gdt8,&
2985 integer :: i,maxres2
2992 ! AL 8/17/04 Code adapted from tinker
2994 ! Get the frictional and random terms for stochastic dynamics in the
2995 ! eigenspace of mass-scaled UNRES friction matrix
2999 gdt = fricgam(i) * d_time
3001 ! Stochastic dynamics reduces to simple MD for zero friction
3003 if (gdt .le. zero) then
3004 pfric_vec(i) = 1.0d0
3005 vfric_vec(i) = d_time
3006 afric_vec(i) = 0.5d0 * d_time * d_time
3007 prand_vec(i) = 0.0d0
3008 vrand_vec1(i) = 0.0d0
3009 vrand_vec2(i) = 0.0d0
3011 ! Analytical expressions when friction coefficient is large
3014 if (gdt .ge. gdt_radius) then
3017 vfric_vec(i) = (1.0d0-egdt) / fricgam(i)
3018 afric_vec(i) = (d_time-vfric_vec(i)) / fricgam(i)
3019 pterm = 2.0d0*gdt - 3.0d0 + (4.0d0-egdt)*egdt
3020 vterm = 1.0d0 - egdt**2
3021 rho = (1.0d0-egdt)**2 / sqrt(pterm*vterm)
3023 ! Use series expansions when friction coefficient is small
3034 afric_vec(i) = (gdt2/2.0d0 - gdt3/6.0d0 + gdt4/24.0d0 &
3035 - gdt5/120.0d0 + gdt6/720.0d0 &
3036 - gdt7/5040.0d0 + gdt8/40320.0d0 &
3037 - gdt9/362880.0d0) / fricgam(i)**2
3038 vfric_vec(i) = d_time - fricgam(i)*afric_vec(i)
3039 pfric_vec(i) = 1.0d0 - fricgam(i)*vfric_vec(i)
3040 pterm = 2.0d0*gdt3/3.0d0 - gdt4/2.0d0 &
3041 + 7.0d0*gdt5/30.0d0 - gdt6/12.0d0 &
3042 + 31.0d0*gdt7/1260.0d0 - gdt8/160.0d0 &
3043 + 127.0d0*gdt9/90720.0d0
3044 vterm = 2.0d0*gdt - 2.0d0*gdt2 + 4.0d0*gdt3/3.0d0 &
3045 - 2.0d0*gdt4/3.0d0 + 4.0d0*gdt5/15.0d0 &
3046 - 4.0d0*gdt6/45.0d0 + 8.0d0*gdt7/315.0d0 &
3047 - 2.0d0*gdt8/315.0d0 + 4.0d0*gdt9/2835.0d0
3048 rho = sqrt(3.0d0) * (0.5d0 - 3.0d0*gdt/16.0d0 &
3049 - 17.0d0*gdt2/1280.0d0 &
3050 + 17.0d0*gdt3/6144.0d0 &
3051 + 40967.0d0*gdt4/34406400.0d0 &
3052 - 57203.0d0*gdt5/275251200.0d0 &
3053 - 1429487.0d0*gdt6/13212057600.0d0)
3056 ! Compute the scaling factors of random terms for the nonzero friction case
3058 ktm = 0.5d0*d_time/fricgam(i)
3059 psig = dsqrt(ktm*pterm) / fricgam(i)
3060 vsig = dsqrt(ktm*vterm)
3061 rhoc = dsqrt(1.0d0 - rho*rho)
3063 vrand_vec1(i) = vsig * rho
3064 vrand_vec2(i) = vsig * rhoc
3069 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3072 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3073 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3077 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3080 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3081 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3082 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3083 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3084 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec1,vrand_mat1)
3085 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3088 t_sdsetup=t_sdsetup+MPI_Wtime()
3090 t_sdsetup=t_sdsetup+tcpu()-tt0
3093 end subroutine sd_verlet_p_setup
3094 !-----------------------------------------------------------------------------
3095 subroutine eigtransf1(n,ndim,ab,d,c)
3099 real(kind=8) :: ab(ndim,ndim,n),c(ndim,n),d(ndim)
3105 c(i,j)=c(i,j)+ab(k,j,i)*d(k)
3110 end subroutine eigtransf1
3111 !-----------------------------------------------------------------------------
3112 subroutine eigtransf(n,ndim,a,b,d,c)
3116 real(kind=8) :: a(ndim,n),b(ndim,n),c(ndim,n),d(ndim)
3122 c(i,j)=c(i,j)+a(i,k)*b(k,j)*d(k)
3127 end subroutine eigtransf
3128 !-----------------------------------------------------------------------------
3129 subroutine sd_verlet1
3131 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3133 ! implicit real*8 (a-h,o-z)
3134 ! include 'DIMENSIONS'
3135 ! include 'COMMON.CONTROL'
3136 ! include 'COMMON.VAR'
3137 ! include 'COMMON.MD'
3139 ! include 'COMMON.LANGEVIN'
3141 ! include 'COMMON.LANGEVIN.lang0'
3143 ! include 'COMMON.CHAIN'
3144 ! include 'COMMON.DERIV'
3145 ! include 'COMMON.GEO'
3146 ! include 'COMMON.LOCAL'
3147 ! include 'COMMON.INTERACT'
3148 ! include 'COMMON.IOUNITS'
3149 ! include 'COMMON.NAMES'
3150 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3151 !el common /stochcalc/ stochforcvec
3152 logical :: lprn = .false.
3153 real(kind=8) :: ddt1,ddt2
3154 integer :: i,j,ind,inres
3156 ! write (iout,*) "dc_old"
3158 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3159 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3162 dc_work(j)=dc_old(j,0)
3163 d_t_work(j)=d_t_old(j,0)
3164 d_a_work(j)=d_a_old(j,0)
3169 dc_work(ind+j)=dc_old(j,i)
3170 d_t_work(ind+j)=d_t_old(j,i)
3171 d_a_work(ind+j)=d_a_old(j,i)
3176 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3178 dc_work(ind+j)=dc_old(j,i+nres)
3179 d_t_work(ind+j)=d_t_old(j,i+nres)
3180 d_a_work(ind+j)=d_a_old(j,i+nres)
3188 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3192 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3193 vfric_mat(i,j),afric_mat(i,j),&
3194 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3202 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3203 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3204 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3205 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3207 d_t_work_new(i)=ddt1+0.5d0*ddt2
3208 d_t_work(i)=ddt1+ddt2
3213 d_t(j,0)=d_t_work(j)
3218 dc(j,i)=dc_work(ind+j)
3219 d_t(j,i)=d_t_work(ind+j)
3224 if (itype(i).ne.10) then
3227 dc(j,inres)=dc_work(ind+j)
3228 d_t(j,inres)=d_t_work(ind+j)
3234 end subroutine sd_verlet1
3235 !-----------------------------------------------------------------------------
3236 subroutine sd_verlet2
3238 ! Calculating the adjusted velocities for accelerations
3240 ! implicit real*8 (a-h,o-z)
3241 ! include 'DIMENSIONS'
3242 ! include 'COMMON.CONTROL'
3243 ! include 'COMMON.VAR'
3244 ! include 'COMMON.MD'
3246 ! include 'COMMON.LANGEVIN'
3248 ! include 'COMMON.LANGEVIN.lang0'
3250 ! include 'COMMON.CHAIN'
3251 ! include 'COMMON.DERIV'
3252 ! include 'COMMON.GEO'
3253 ! include 'COMMON.LOCAL'
3254 ! include 'COMMON.INTERACT'
3255 ! include 'COMMON.IOUNITS'
3256 ! include 'COMMON.NAMES'
3257 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3258 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3259 !el common /stochcalc/ stochforcvec
3261 real(kind=8) :: ddt1,ddt2
3262 integer :: i,j,ind,inres
3263 ! Compute the stochastic forces which contribute to velocity change
3265 call stochastic_force(stochforcvecV)
3272 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3273 ddt2=ddt2+vrand_mat1(i,j)*stochforcvec(j)+ &
3274 vrand_mat2(i,j)*stochforcvecV(j)
3276 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3280 d_t(j,0)=d_t_work(j)
3285 d_t(j,i)=d_t_work(ind+j)
3290 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3293 d_t(j,inres)=d_t_work(ind+j)
3299 end subroutine sd_verlet2
3300 !-----------------------------------------------------------------------------
3301 subroutine sd_verlet_ciccotti_setup
3303 ! Sets up the parameters of stochastic velocity Verlet algorithmi; Ciccotti's
3305 ! implicit real*8 (a-h,o-z)
3306 ! include 'DIMENSIONS'
3307 use control, only: tcpu
3312 ! include 'COMMON.CONTROL'
3313 ! include 'COMMON.VAR'
3314 ! include 'COMMON.MD'
3316 ! include 'COMMON.LANGEVIN'
3318 ! include 'COMMON.LANGEVIN.lang0'
3320 ! include 'COMMON.CHAIN'
3321 ! include 'COMMON.DERIV'
3322 ! include 'COMMON.GEO'
3323 ! include 'COMMON.LOCAL'
3324 ! include 'COMMON.INTERACT'
3325 ! include 'COMMON.IOUNITS'
3326 ! include 'COMMON.NAMES'
3327 ! include 'COMMON.TIME1'
3328 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3329 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3330 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3331 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3332 logical :: lprn = .false.
3333 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3334 real(kind=8) :: ktm,gdt,egdt,tt0
3335 integer :: i,maxres2
3342 ! AL 8/17/04 Code adapted from tinker
3344 ! Get the frictional and random terms for stochastic dynamics in the
3345 ! eigenspace of mass-scaled UNRES friction matrix
3349 write (iout,*) "i",i," fricgam",fricgam(i)
3350 gdt = fricgam(i) * d_time
3352 ! Stochastic dynamics reduces to simple MD for zero friction
3354 if (gdt .le. zero) then
3355 pfric_vec(i) = 1.0d0
3356 vfric_vec(i) = d_time
3357 afric_vec(i) = 0.5d0*d_time*d_time
3358 prand_vec(i) = afric_vec(i)
3359 vrand_vec2(i) = vfric_vec(i)
3361 ! Analytical expressions when friction coefficient is large
3366 vfric_vec(i) = dexp(-0.5d0*gdt)*d_time
3367 afric_vec(i) = 0.5d0*dexp(-0.25d0*gdt)*d_time*d_time
3368 prand_vec(i) = afric_vec(i)
3369 vrand_vec2(i) = vfric_vec(i)
3371 ! Compute the scaling factors of random terms for the nonzero friction case
3373 ! ktm = 0.5d0*d_time/fricgam(i)
3374 ! psig = dsqrt(ktm*pterm) / fricgam(i)
3375 ! vsig = dsqrt(ktm*vterm)
3376 ! prand_vec(i) = psig*afric_vec(i)
3377 ! vrand_vec2(i) = vsig*vfric_vec(i)
3382 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3385 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3386 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3390 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3392 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3393 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3394 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3395 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3396 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3398 t_sdsetup=t_sdsetup+MPI_Wtime()
3400 t_sdsetup=t_sdsetup+tcpu()-tt0
3403 end subroutine sd_verlet_ciccotti_setup
3404 !-----------------------------------------------------------------------------
3405 subroutine sd_verlet1_ciccotti
3407 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3408 ! implicit real*8 (a-h,o-z)
3410 ! include 'DIMENSIONS'
3414 ! include 'COMMON.CONTROL'
3415 ! include 'COMMON.VAR'
3416 ! include 'COMMON.MD'
3418 ! include 'COMMON.LANGEVIN'
3420 ! include 'COMMON.LANGEVIN.lang0'
3422 ! include 'COMMON.CHAIN'
3423 ! include 'COMMON.DERIV'
3424 ! include 'COMMON.GEO'
3425 ! include 'COMMON.LOCAL'
3426 ! include 'COMMON.INTERACT'
3427 ! include 'COMMON.IOUNITS'
3428 ! include 'COMMON.NAMES'
3429 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3430 !el common /stochcalc/ stochforcvec
3431 logical :: lprn = .false.
3432 real(kind=8) :: ddt1,ddt2
3433 integer :: i,j,ind,inres
3434 ! write (iout,*) "dc_old"
3436 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3437 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3440 dc_work(j)=dc_old(j,0)
3441 d_t_work(j)=d_t_old(j,0)
3442 d_a_work(j)=d_a_old(j,0)
3447 dc_work(ind+j)=dc_old(j,i)
3448 d_t_work(ind+j)=d_t_old(j,i)
3449 d_a_work(ind+j)=d_a_old(j,i)
3454 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3456 dc_work(ind+j)=dc_old(j,i+nres)
3457 d_t_work(ind+j)=d_t_old(j,i+nres)
3458 d_a_work(ind+j)=d_a_old(j,i+nres)
3467 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3471 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3472 vfric_mat(i,j),afric_mat(i,j),&
3473 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3481 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3482 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3483 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3484 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3486 d_t_work_new(i)=ddt1+0.5d0*ddt2
3487 d_t_work(i)=ddt1+ddt2
3492 d_t(j,0)=d_t_work(j)
3497 dc(j,i)=dc_work(ind+j)
3498 d_t(j,i)=d_t_work(ind+j)
3503 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3506 dc(j,inres)=dc_work(ind+j)
3507 d_t(j,inres)=d_t_work(ind+j)
3513 end subroutine sd_verlet1_ciccotti
3514 !-----------------------------------------------------------------------------
3515 subroutine sd_verlet2_ciccotti
3517 ! Calculating the adjusted velocities for accelerations
3519 ! implicit real*8 (a-h,o-z)
3520 ! include 'DIMENSIONS'
3521 ! include 'COMMON.CONTROL'
3522 ! include 'COMMON.VAR'
3523 ! include 'COMMON.MD'
3525 ! include 'COMMON.LANGEVIN'
3527 ! include 'COMMON.LANGEVIN.lang0'
3529 ! include 'COMMON.CHAIN'
3530 ! include 'COMMON.DERIV'
3531 ! include 'COMMON.GEO'
3532 ! include 'COMMON.LOCAL'
3533 ! include 'COMMON.INTERACT'
3534 ! include 'COMMON.IOUNITS'
3535 ! include 'COMMON.NAMES'
3536 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3537 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3538 !el common /stochcalc/ stochforcvec
3539 real(kind=8) :: ddt1,ddt2
3540 integer :: i,j,ind,inres
3542 ! Compute the stochastic forces which contribute to velocity change
3544 call stochastic_force(stochforcvecV)
3551 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3552 ! ddt2=ddt2+vrand_mat2(i,j)*stochforcvecV(j)
3553 ddt2=ddt2+vrand_mat2(i,j)*stochforcvec(j)
3555 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3559 d_t(j,0)=d_t_work(j)
3564 d_t(j,i)=d_t_work(ind+j)
3569 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3572 d_t(j,inres)=d_t_work(ind+j)
3578 end subroutine sd_verlet2_ciccotti
3580 !-----------------------------------------------------------------------------
3582 !-----------------------------------------------------------------------------
3583 subroutine inertia_tensor
3585 ! Calculating the intertia tensor for the entire protein in order to
3586 ! remove the perpendicular components of velocity matrix which cause
3587 ! the molecule to rotate.
3590 ! implicit real*8 (a-h,o-z)
3591 ! include 'DIMENSIONS'
3592 ! include 'COMMON.CONTROL'
3593 ! include 'COMMON.VAR'
3594 ! include 'COMMON.MD'
3595 ! include 'COMMON.CHAIN'
3596 ! include 'COMMON.DERIV'
3597 ! include 'COMMON.GEO'
3598 ! include 'COMMON.LOCAL'
3599 ! include 'COMMON.INTERACT'
3600 ! include 'COMMON.IOUNITS'
3601 ! include 'COMMON.NAMES'
3603 real(kind=8),dimension(3,3) :: Im,Imcp,eigvec,Id
3604 real(kind=8),dimension(3) :: pr,eigval,L,vp,vrot
3605 real(kind=8) :: M_SC,mag,mag2
3606 real(kind=8),dimension(3,0:nres) :: vpp !(3,0:MAXRES)
3607 real(kind=8),dimension(3) :: vs_p,pp,incr,v
3608 real(kind=8),dimension(3,3) :: pr1,pr2
3610 !el common /gucio/ cm
3611 integer :: iti,inres,i,j,k
3622 ! calculating the center of the mass of the protein
3625 cm(j)=cm(j)+c(j,i)+0.5d0*dc(j,i)
3634 M_SC=M_SC+msc(iabs(iti))
3637 cm(j)=cm(j)+msc(iabs(iti))*c(j,inres)
3641 cm(j)=cm(j)/(M_SC+(nct-nnt)*mp)
3646 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3648 Im(1,1)=Im(1,1)+mp*(pr(2)*pr(2)+pr(3)*pr(3))
3649 Im(1,2)=Im(1,2)-mp*pr(1)*pr(2)
3650 Im(1,3)=Im(1,3)-mp*pr(1)*pr(3)
3651 Im(2,3)=Im(2,3)-mp*pr(2)*pr(3)
3652 Im(2,2)=Im(2,2)+mp*(pr(3)*pr(3)+pr(1)*pr(1))
3653 Im(3,3)=Im(3,3)+mp*(pr(1)*pr(1)+pr(2)*pr(2))
3660 pr(j)=c(j,inres)-cm(j)
3662 Im(1,1)=Im(1,1)+msc(iabs(iti))*(pr(2)*pr(2)+pr(3)*pr(3))
3663 Im(1,2)=Im(1,2)-msc(iabs(iti))*pr(1)*pr(2)
3664 Im(1,3)=Im(1,3)-msc(iabs(iti))*pr(1)*pr(3)
3665 Im(2,3)=Im(2,3)-msc(iabs(iti))*pr(2)*pr(3)
3666 Im(2,2)=Im(2,2)+msc(iabs(iti))*(pr(3)*pr(3)+pr(1)*pr(1))
3667 Im(3,3)=Im(3,3)+msc(iabs(iti))*(pr(1)*pr(1)+pr(2)*pr(2))
3671 Im(1,1)=Im(1,1)+Ip*(1-dc_norm(1,i)*dc_norm(1,i))* &
3672 vbld(i+1)*vbld(i+1)*0.25d0
3673 Im(1,2)=Im(1,2)+Ip*(-dc_norm(1,i)*dc_norm(2,i))* &
3674 vbld(i+1)*vbld(i+1)*0.25d0
3675 Im(1,3)=Im(1,3)+Ip*(-dc_norm(1,i)*dc_norm(3,i))* &
3676 vbld(i+1)*vbld(i+1)*0.25d0
3677 Im(2,3)=Im(2,3)+Ip*(-dc_norm(2,i)*dc_norm(3,i))* &
3678 vbld(i+1)*vbld(i+1)*0.25d0
3679 Im(2,2)=Im(2,2)+Ip*(1-dc_norm(2,i)*dc_norm(2,i))* &
3680 vbld(i+1)*vbld(i+1)*0.25d0
3681 Im(3,3)=Im(3,3)+Ip*(1-dc_norm(3,i)*dc_norm(3,i))* &
3682 vbld(i+1)*vbld(i+1)*0.25d0
3687 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3690 Im(1,1)=Im(1,1)+Isc(iti)*(1-dc_norm(1,inres)* &
3691 dc_norm(1,inres))*vbld(inres)*vbld(inres)
3692 Im(1,2)=Im(1,2)-Isc(iti)*(dc_norm(1,inres)* &
3693 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3694 Im(1,3)=Im(1,3)-Isc(iti)*(dc_norm(1,inres)* &
3695 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3696 Im(2,3)=Im(2,3)-Isc(iti)*(dc_norm(2,inres)* &
3697 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3698 Im(2,2)=Im(2,2)+Isc(iti)*(1-dc_norm(2,inres)* &
3699 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3700 Im(3,3)=Im(3,3)+Isc(iti)*(1-dc_norm(3,inres)* &
3701 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3706 ! write(iout,*) "The angular momentum before adjustment:"
3707 ! write(iout,*) (L(j),j=1,3)
3713 ! Copying the Im matrix for the djacob subroutine
3721 ! Finding the eigenvectors and eignvalues of the inertia tensor
3722 call djacob(3,3,10000,1.0d-10,Imcp,eigvec,eigval)
3723 ! write (iout,*) "Eigenvalues & Eigenvectors"
3724 ! write (iout,'(5x,3f10.5)') (eigval(i),i=1,3)
3727 ! write (iout,'(i5,3f10.5)') i,(eigvec(i,j),j=1,3)
3729 ! Constructing the diagonalized matrix
3731 if (dabs(eigval(i)).gt.1.0d-15) then
3732 Id(i,i)=1.0d0/eigval(i)
3739 Imcp(i,j)=eigvec(j,i)
3745 pr1(i,j)=pr1(i,j)+Id(i,k)*Imcp(k,j)
3752 pr2(i,j)=pr2(i,j)+eigvec(i,k)*pr1(k,j)
3756 ! Calculating the total rotational velocity of the molecule
3759 vrot(i)=vrot(i)+pr2(i,j)*L(j)
3762 ! Resetting the velocities
3764 call vecpr(vrot(1),dc(1,i),vp)
3766 d_t(j,i)=d_t(j,i)-vp(j)
3770 if(itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3772 call vecpr(vrot(1),dc(1,inres),vp)
3774 d_t(j,inres)=d_t(j,inres)-vp(j)
3779 ! write(iout,*) "The angular momentum after adjustment:"
3780 ! write(iout,*) (L(j),j=1,3)
3783 end subroutine inertia_tensor
3784 !-----------------------------------------------------------------------------
3785 subroutine angmom(cm,L)
3788 ! implicit real*8 (a-h,o-z)
3789 ! include 'DIMENSIONS'
3790 ! include 'COMMON.CONTROL'
3791 ! include 'COMMON.VAR'
3792 ! include 'COMMON.MD'
3793 ! include 'COMMON.CHAIN'
3794 ! include 'COMMON.DERIV'
3795 ! include 'COMMON.GEO'
3796 ! include 'COMMON.LOCAL'
3797 ! include 'COMMON.INTERACT'
3798 ! include 'COMMON.IOUNITS'
3799 ! include 'COMMON.NAMES'
3801 real(kind=8),dimension(3) :: L,cm,pr,vp,vrot,incr,v,pp
3802 integer :: iti,inres,i,j
3803 ! Calculate the angular momentum
3812 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3815 v(j)=incr(j)+0.5d0*d_t(j,i)
3818 incr(j)=incr(j)+d_t(j,i)
3820 call vecpr(pr(1),v(1),vp)
3826 pp(j)=0.5d0*d_t(j,i)
3828 call vecpr(pr(1),pp(1),vp)
3840 pr(j)=c(j,inres)-cm(j)
3842 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3844 v(j)=incr(j)+d_t(j,inres)
3851 call vecpr(pr(1),v(1),vp)
3852 ! write (iout,*) "i",i," iti",iti," pr",(pr(j),j=1,3),
3853 ! & " v",(v(j),j=1,3)," vp",(vp(j),j=1,3)
3855 L(j)=L(j)+msc(iabs(iti))*vp(j)
3857 ! write (iout,*) "L",(l(j),j=1,3)
3858 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3860 v(j)=incr(j)+d_t(j,inres)
3862 call vecpr(dc(1,inres),d_t(1,inres),vp)
3864 L(j)=L(j)+Isc(iti)*vp(j)
3868 incr(j)=incr(j)+d_t(j,i)
3872 end subroutine angmom
3873 !-----------------------------------------------------------------------------
3874 subroutine vcm_vel(vcm)
3877 ! implicit real*8 (a-h,o-z)
3878 ! include 'DIMENSIONS'
3879 ! include 'COMMON.VAR'
3880 ! include 'COMMON.MD'
3881 ! include 'COMMON.CHAIN'
3882 ! include 'COMMON.DERIV'
3883 ! include 'COMMON.GEO'
3884 ! include 'COMMON.LOCAL'
3885 ! include 'COMMON.INTERACT'
3886 ! include 'COMMON.IOUNITS'
3887 real(kind=8),dimension(3) :: vcm,vv
3888 real(kind=8) :: summas,amas
3900 vcm(j)=vcm(j)+mp*(vv(j)+0.5d0*d_t(j,i))
3903 amas=msc(iabs(itype(i)))
3905 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3907 vcm(j)=vcm(j)+amas*(vv(j)+d_t(j,i+nres))
3911 vcm(j)=vcm(j)+amas*vv(j)
3915 vv(j)=vv(j)+d_t(j,i)
3918 ! write (iout,*) "vcm",(vcm(j),j=1,3)," summas",summas
3920 vcm(j)=vcm(j)/summas
3923 end subroutine vcm_vel
3924 !-----------------------------------------------------------------------------
3926 !-----------------------------------------------------------------------------
3928 ! RATTLE algorithm for velocity Verlet - step 1, UNRES
3932 ! implicit real*8 (a-h,o-z)
3933 ! include 'DIMENSIONS'
3935 ! include 'COMMON.CONTROL'
3936 ! include 'COMMON.VAR'
3937 ! include 'COMMON.MD'
3939 ! include 'COMMON.LANGEVIN'
3941 ! include 'COMMON.LANGEVIN.lang0'
3943 ! include 'COMMON.CHAIN'
3944 ! include 'COMMON.DERIV'
3945 ! include 'COMMON.GEO'
3946 ! include 'COMMON.LOCAL'
3947 ! include 'COMMON.INTERACT'
3948 ! include 'COMMON.IOUNITS'
3949 ! include 'COMMON.NAMES'
3950 ! include 'COMMON.TIME1'
3951 !el real(kind=8) :: gginv(2*nres,2*nres),&
3952 !el gdc(3,2*nres,2*nres)
3953 real(kind=8) :: dC_uncor(3,2*nres) !,&
3954 !el real(kind=8) :: Cmat(2*nres,2*nres)
3955 real(kind=8) :: x(2*nres),xcorr(3,2*nres) !maxres2=2*maxres
3956 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
3957 !el common /przechowalnia/ nbond
3958 integer :: max_rattle = 5
3959 logical :: lprn = .false., lprn1 = .false., not_done
3960 real(kind=8) :: tol_rattle = 1.0d-5
3962 integer :: ii,i,j,jj,l,ind,ind1,nres2
3965 !el /common/ przechowalnia
3967 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
3968 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
3969 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
3971 if (lprn) write (iout,*) "RATTLE1"
3974 if (itype(i).ne.10) nbond=nbond+1
3976 ! Make a folded form of the Ginv-matrix
3989 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
3993 if (itype(k).ne.10) then
3997 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4004 if (itype(i).ne.10) then
4014 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4018 if (itype(k).ne.10) then
4022 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4030 write (iout,*) "Matrix GGinv"
4031 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4037 if (iter.gt.max_rattle) then
4038 write (iout,*) "Error - too many iterations in RATTLE."
4041 ! Calculate the matrix C = GG**(-1) dC_old o dC
4046 dC_uncor(j,ind1)=dC(j,i)
4050 if (itype(i).ne.10) then
4053 dC_uncor(j,ind1)=dC(j,i+nres)
4062 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4066 if (itype(k).ne.10) then
4069 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4074 ! Calculate deviations from standard virtual-bond lengths
4078 x(ind)=vbld(i+1)**2-vbl**2
4081 if (itype(i).ne.10) then
4083 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
4087 write (iout,*) "Coordinates and violations"
4089 write(iout,'(i5,3f10.5,5x,e15.5)') &
4090 i,(dC_uncor(j,i),j=1,3),x(i)
4092 write (iout,*) "Velocities and violations"
4096 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4097 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4100 if (itype(i).ne.10) then
4102 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4103 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4104 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4107 ! write (iout,*) "gdc"
4109 ! write (iout,*) "i",i
4111 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4117 if (dabs(x(i)).gt.xmax) then
4121 if (xmax.lt.tol_rattle) then
4125 ! Calculate the matrix of the system of equations
4130 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4135 write (iout,*) "Matrix Cmat"
4136 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4138 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4139 ! Add constraint term to positions
4146 xx = xx+x(ii)*gdc(j,ind,ii)
4150 d_t_new(j,i)=d_t_new(j,i)-xx/d_time
4154 if (itype(i).ne.10) then
4159 xx = xx+x(ii)*gdc(j,ind,ii)
4162 dC(j,i+nres)=dC(j,i+nres)-xx
4163 d_t_new(j,i+nres)=d_t_new(j,i+nres)-xx/d_time
4167 ! Rebuild the chain using the new coordinates
4168 call chainbuild_cart
4170 write (iout,*) "New coordinates, Lagrange multipliers,",&
4171 " and differences between actual and standard bond lengths"
4175 xx=vbld(i+1)**2-vbl**2
4176 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4177 i,(dC(j,i),j=1,3),x(ind),xx
4180 if (itype(i).ne.10) then
4182 xx=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
4183 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4184 i,(dC(j,i+nres),j=1,3),x(ind),xx
4187 write (iout,*) "Velocities and violations"
4191 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4192 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4195 if (itype(i).ne.10) then
4197 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4198 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4199 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4206 10 write (iout,*) "Error - singularity in solving the system",&
4207 " of equations for Lagrange multipliers."
4211 "RATTLE inactive; use -DRATTLE switch at compile time."
4214 end subroutine rattle1
4215 !-----------------------------------------------------------------------------
4217 ! RATTLE algorithm for velocity Verlet - step 2, UNRES
4221 ! implicit real*8 (a-h,o-z)
4222 ! include 'DIMENSIONS'
4224 ! include 'COMMON.CONTROL'
4225 ! include 'COMMON.VAR'
4226 ! include 'COMMON.MD'
4228 ! include 'COMMON.LANGEVIN'
4230 ! include 'COMMON.LANGEVIN.lang0'
4232 ! include 'COMMON.CHAIN'
4233 ! include 'COMMON.DERIV'
4234 ! include 'COMMON.GEO'
4235 ! include 'COMMON.LOCAL'
4236 ! include 'COMMON.INTERACT'
4237 ! include 'COMMON.IOUNITS'
4238 ! include 'COMMON.NAMES'
4239 ! include 'COMMON.TIME1'
4240 !el real(kind=8) :: gginv(2*nres,2*nres),&
4241 !el gdc(3,2*nres,2*nres)
4242 real(kind=8) :: dC_uncor(3,2*nres) !,&
4243 !el Cmat(2*nres,2*nres)
4244 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4245 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4246 !el common /przechowalnia/ nbond
4247 integer :: max_rattle = 5
4248 logical :: lprn = .false., lprn1 = .false., not_done
4249 real(kind=8) :: tol_rattle = 1.0d-5
4253 !el /common/ przechowalnia
4254 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4255 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4256 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4258 if (lprn) write (iout,*) "RATTLE2"
4259 if (lprn) write (iout,*) "Velocity correction"
4260 ! Calculate the matrix G dC
4266 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k)
4270 if (itype(k).ne.10) then
4273 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k+nres)
4279 ! write (iout,*) "gdc"
4281 ! write (iout,*) "i",i
4283 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4287 ! Calculate the matrix of the system of equations
4294 Cmat(ind,j)=Cmat(ind,j)+dC(k,i)*gdc(k,ind,j)
4299 if (itype(i).ne.10) then
4304 Cmat(ind,j)=Cmat(ind,j)+dC(k,i+nres)*gdc(k,ind,j)
4309 ! Calculate the scalar product dC o d_t_new
4313 x(ind)=scalar(d_t(1,i),dC(1,i))
4316 if (itype(i).ne.10) then
4318 x(ind)=scalar(d_t(1,i+nres),dC(1,i+nres))
4322 write (iout,*) "Velocities and violations"
4326 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4327 i,ind,(d_t(j,i),j=1,3),x(ind)
4330 if (itype(i).ne.10) then
4332 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4333 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind)
4339 if (dabs(x(i)).gt.xmax) then
4343 if (xmax.lt.tol_rattle) then
4348 write (iout,*) "Matrix Cmat"
4349 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4351 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4352 ! Add constraint term to velocities
4359 xx = xx+x(ii)*gdc(j,ind,ii)
4361 d_t(j,i)=d_t(j,i)-xx
4365 if (itype(i).ne.10) then
4370 xx = xx+x(ii)*gdc(j,ind,ii)
4372 d_t(j,i+nres)=d_t(j,i+nres)-xx
4378 "New velocities, Lagrange multipliers violations"
4382 if (lprn) write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4383 i,ind,(d_t(j,i),j=1,3),x(ind),scalar(d_t(1,i),dC(1,i))
4386 if (itype(i).ne.10) then
4388 write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4389 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind),&
4390 scalar(d_t(1,i+nres),dC(1,i+nres))
4396 10 write (iout,*) "Error - singularity in solving the system",&
4397 " of equations for Lagrange multipliers."
4401 "RATTLE inactive; use -DRATTLE option at compile time."
4404 end subroutine rattle2
4405 !-----------------------------------------------------------------------------
4406 subroutine rattle_brown
4407 ! RATTLE/LINCS algorithm for Brownian dynamics, UNRES
4411 ! implicit real*8 (a-h,o-z)
4412 ! include 'DIMENSIONS'
4414 ! include 'COMMON.CONTROL'
4415 ! include 'COMMON.VAR'
4416 ! include 'COMMON.MD'
4418 ! include 'COMMON.LANGEVIN'
4420 ! include 'COMMON.LANGEVIN.lang0'
4422 ! include 'COMMON.CHAIN'
4423 ! include 'COMMON.DERIV'
4424 ! include 'COMMON.GEO'
4425 ! include 'COMMON.LOCAL'
4426 ! include 'COMMON.INTERACT'
4427 ! include 'COMMON.IOUNITS'
4428 ! include 'COMMON.NAMES'
4429 ! include 'COMMON.TIME1'
4430 !el real(kind=8) :: gginv(2*nres,2*nres),&
4431 !el gdc(3,2*nres,2*nres)
4432 real(kind=8) :: dC_uncor(3,2*nres) !,&
4433 !el real(kind=8) :: Cmat(2*nres,2*nres)
4434 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4435 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4436 !el common /przechowalnia/ nbond
4437 integer :: max_rattle = 5
4438 logical :: lprn = .true., lprn1 = .true., not_done
4439 real(kind=8) :: tol_rattle = 1.0d-5
4443 !el /common/ przechowalnia
4444 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4445 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4446 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4449 if (lprn) write (iout,*) "RATTLE_BROWN"
4452 if (itype(i).ne.10) nbond=nbond+1
4454 ! Make a folded form of the Ginv-matrix
4467 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4471 if (itype(k).ne.10) then
4475 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4482 if (itype(i).ne.10) then
4492 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4496 if (itype(k).ne.10) then
4500 if (j.eq.1 .and. l.eq.1)GGinv(ii,jj)=fricmat(ind,ind1)
4508 write (iout,*) "Matrix GGinv"
4509 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4515 if (iter.gt.max_rattle) then
4516 write (iout,*) "Error - too many iterations in RATTLE."
4519 ! Calculate the matrix C = GG**(-1) dC_old o dC
4524 dC_uncor(j,ind1)=dC(j,i)
4528 if (itype(i).ne.10) then
4531 dC_uncor(j,ind1)=dC(j,i+nres)
4540 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4544 if (itype(k).ne.10) then
4547 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4552 ! Calculate deviations from standard virtual-bond lengths
4556 x(ind)=vbld(i+1)**2-vbl**2
4559 if (itype(i).ne.10) then
4561 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
4565 write (iout,*) "Coordinates and violations"
4567 write(iout,'(i5,3f10.5,5x,e15.5)') &
4568 i,(dC_uncor(j,i),j=1,3),x(i)
4570 write (iout,*) "Velocities and violations"
4574 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4575 i,ind,(d_t(j,i),j=1,3),scalar(d_t(1,i),dC_old(1,i))
4578 if (itype(i).ne.10) then
4580 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4581 i+nres,ind,(d_t(j,i+nres),j=1,3),&
4582 scalar(d_t(1,i+nres),dC_old(1,i+nres))
4585 write (iout,*) "gdc"
4587 write (iout,*) "i",i
4589 write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4595 if (dabs(x(i)).gt.xmax) then
4599 if (xmax.lt.tol_rattle) then
4603 ! Calculate the matrix of the system of equations
4608 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4613 write (iout,*) "Matrix Cmat"
4614 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4616 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4617 ! Add constraint term to positions
4624 xx = xx+x(ii)*gdc(j,ind,ii)
4627 d_t(j,i)=d_t(j,i)+xx/d_time
4632 if (itype(i).ne.10) then
4637 xx = xx+x(ii)*gdc(j,ind,ii)
4640 d_t(j,i+nres)=d_t(j,i+nres)+xx/d_time
4641 dC(j,i+nres)=dC(j,i+nres)+xx
4645 ! Rebuild the chain using the new coordinates
4646 call chainbuild_cart
4648 write (iout,*) "New coordinates, Lagrange multipliers,",&
4649 " and differences between actual and standard bond lengths"
4653 xx=vbld(i+1)**2-vbl**2
4654 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4655 i,(dC(j,i),j=1,3),x(ind),xx
4658 if (itype(i).ne.10) then
4660 xx=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
4661 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4662 i,(dC(j,i+nres),j=1,3),x(ind),xx
4665 write (iout,*) "Velocities and violations"
4669 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4670 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4673 if (itype(i).ne.10) then
4675 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4676 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4677 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4684 10 write (iout,*) "Error - singularity in solving the system",&
4685 " of equations for Lagrange multipliers."
4689 "RATTLE inactive; use -DRATTLE option at compile time"
4692 end subroutine rattle_brown
4693 !-----------------------------------------------------------------------------
4695 !-----------------------------------------------------------------------------
4696 subroutine friction_force
4701 ! implicit real*8 (a-h,o-z)
4702 ! include 'DIMENSIONS'
4703 ! include 'COMMON.VAR'
4704 ! include 'COMMON.CHAIN'
4705 ! include 'COMMON.DERIV'
4706 ! include 'COMMON.GEO'
4707 ! include 'COMMON.LOCAL'
4708 ! include 'COMMON.INTERACT'
4709 ! include 'COMMON.MD'
4711 ! include 'COMMON.LANGEVIN'
4713 ! include 'COMMON.LANGEVIN.lang0'
4715 ! include 'COMMON.IOUNITS'
4716 !el real(kind=8),dimension(6*nres) :: gamvec !(MAXRES6) maxres6=6*maxres
4717 !el common /syfek/ gamvec
4718 real(kind=8) :: vv(3),vvtot(3,nres),v_work(6*nres) !,&
4719 !el ginvfric(2*nres,2*nres) !maxres2=2*maxres
4720 !el common /przechowalnia/ ginvfric
4722 logical :: lprn = .false., checkmode = .false.
4723 integer :: i,j,ind,k,nres2,nres6
4727 if(.not.allocated(gamvec)) allocate(gamvec(nres6)) !(MAXRES6)
4728 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
4736 d_t_work(j)=d_t(j,0)
4741 d_t_work(ind+j)=d_t(j,i)
4746 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
4748 d_t_work(ind+j)=d_t(j,i+nres)
4754 call fricmat_mult(d_t_work,fric_work)
4756 if (.not.checkmode) return
4759 write (iout,*) "d_t_work and fric_work"
4761 write (iout,'(i3,2e15.5)') i,d_t_work(i),fric_work(i)
4765 friction(j,0)=fric_work(j)
4770 friction(j,i)=fric_work(ind+j)
4775 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
4777 friction(j,i+nres)=fric_work(ind+j)
4783 write(iout,*) "Friction backbone"
4785 write(iout,'(i5,3e15.5,5x,3e15.5)') &
4786 i,(friction(j,i),j=1,3),(d_t(j,i),j=1,3)
4788 write(iout,*) "Friction side chain"
4790 write(iout,'(i5,3e15.5,5x,3e15.5)') &
4791 i,(friction(j,i+nres),j=1,3),(d_t(j,i+nres),j=1,3)
4800 vvtot(j,i)=vv(j)+0.5d0*d_t(j,i)
4801 vvtot(j,i+nres)=vv(j)+d_t(j,i+nres)
4802 vv(j)=vv(j)+d_t(j,i)
4805 write (iout,*) "vvtot backbone and sidechain"
4807 write (iout,'(i5,3e15.5,5x,3e15.5)') i,(vvtot(j,i),j=1,3),&
4808 (vvtot(j,i+nres),j=1,3)
4813 v_work(ind+j)=vvtot(j,i)
4819 v_work(ind+j)=vvtot(j,i+nres)
4823 write (iout,*) "v_work gamvec and site-based friction forces"
4825 write (iout,'(i5,3e15.5)') i,v_work(i),gamvec(i),&
4829 ! fric_work1(i)=0.0d0
4831 ! fric_work1(i)=fric_work1(i)-A(j,i)*gamvec(j)*v_work(j)
4834 ! write (iout,*) "fric_work and fric_work1"
4836 ! write (iout,'(i5,2e15.5)') i,fric_work(i),fric_work1(i)
4842 ginvfric(i,j)=ginvfric(i,j)+ginv(i,k)*fricmat(k,j)
4846 write (iout,*) "ginvfric"
4848 write (iout,'(i5,100f8.3)') i,(ginvfric(i,j),j=1,dimen)
4850 write (iout,*) "symmetry check"
4853 write (iout,*) i,j,ginvfric(i,j)-ginvfric(j,i)
4858 end subroutine friction_force
4859 !-----------------------------------------------------------------------------
4860 subroutine setup_fricmat
4864 use control_data, only:time_Bcast
4865 use control, only:tcpu
4867 ! implicit real*8 (a-h,o-z)
4871 real(kind=8) :: time00
4873 ! include 'DIMENSIONS'
4874 ! include 'COMMON.VAR'
4875 ! include 'COMMON.CHAIN'
4876 ! include 'COMMON.DERIV'
4877 ! include 'COMMON.GEO'
4878 ! include 'COMMON.LOCAL'
4879 ! include 'COMMON.INTERACT'
4880 ! include 'COMMON.MD'
4881 ! include 'COMMON.SETUP'
4882 ! include 'COMMON.TIME1'
4883 ! integer licznik /0/
4886 ! include 'COMMON.LANGEVIN'
4888 ! include 'COMMON.LANGEVIN.lang0'
4890 ! include 'COMMON.IOUNITS'
4892 integer :: i,j,ind,ind1,m
4893 logical :: lprn = .false.
4894 real(kind=8) :: dtdi !el ,gamvec(2*nres)
4895 !el real(kind=8),dimension(2*nres,2*nres) :: ginvfric,fcopy
4896 real(kind=8),dimension(2*nres,2*nres) :: fcopy
4897 !el real(kind=8),dimension(2*nres*(2*nres+1)/2) :: Ghalf !(mmaxres2) (mmaxres2=(maxres2*(maxres2+1)/2))
4898 !el common /syfek/ gamvec
4899 real(kind=8) :: work(8*2*nres)
4900 integer :: iwork(2*nres)
4901 !el common /przechowalnia/ ginvfric,Ghalf,fcopy
4902 integer :: ii,iti,k,l,nzero,nres2,nres6,ierr
4904 if (fg_rank.ne.king) goto 10
4909 if(.not.allocated(gamvec)) allocate(gamvec(nres2)) !(MAXRES2)
4910 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
4911 !el if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
4912 !el allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
4913 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !maxres2=2*maxres
4915 !el if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
4916 ! Zeroing out fricmat
4922 ! Load the friction coefficients corresponding to peptide groups
4928 ! Load the friction coefficients corresponding to side chains
4936 gamvec(ii)=gamsc(iabs(iti))
4938 if (surfarea) call sdarea(gamvec)
4940 ! write (iout,*) "Matrix A and vector gamma"
4942 ! write (iout,'(i2,$)') i
4944 ! write (iout,'(f4.1,$)') A(i,j)
4946 ! write (iout,'(f8.3)') gamvec(i)
4950 write (iout,*) "Vector gamvec"
4952 write (iout,'(i5,f10.5)') i, gamvec(i)
4956 ! The friction matrix
4961 dtdi=dtdi+A(j,k)*A(j,i)*gamvec(j)
4968 write (iout,'(//a)') "Matrix fricmat"
4969 call matout2(dimen,dimen,nres2,nres2,fricmat)
4971 if (lang.eq.2 .or. lang.eq.3) then
4972 ! Mass-scale the friction matrix if non-direct integration will be performed
4978 Ginvfric(i,j)=Ginvfric(i,j)+ &
4979 Gsqrm(i,k)*Gsqrm(l,j)*fricmat(k,l)
4984 ! Diagonalize the friction matrix
4989 Ghalf(ind)=Ginvfric(i,j)
4992 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
4995 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
4996 " mass-scaled friction matrix"
4997 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
4999 ! Precompute matrices for tinker stochastic integrator
5006 mt1(i,j)=mt1(i,j)+fricvec(k,i)*gsqrm(k,j)
5007 mt2(i,j)=mt2(i,j)+fricvec(k,i)*gsqrp(k,j)
5013 else if (lang.eq.4) then
5014 ! Diagonalize the friction matrix
5019 Ghalf(ind)=fricmat(i,j)
5022 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5025 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5027 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5029 ! Determine the number of zero eigenvalues of the friction matrix
5030 nzero=max0(dimen-dimen1,0)
5031 ! do while (fricgam(nzero+1).le.1.0d-5 .and. nzero.lt.dimen)
5034 write (iout,*) "Number of zero eigenvalues:",nzero
5039 fricmat(i,j)=fricmat(i,j) &
5040 +fricvec(i,k)*fricvec(j,k)/fricgam(k)
5045 write (iout,'(//a)') "Generalized inverse of fricmat"
5046 call matout(dimen,dimen,nres6,nres6,fricmat)
5051 if (nfgtasks.gt.1) then
5052 if (fg_rank.eq.0) then
5053 ! The matching BROADCAST for fg processors is called in ERGASTULUM
5059 call MPI_Bcast(10,1,MPI_INTEGER,king,FG_COMM,IERROR)
5061 time_Bcast=time_Bcast+MPI_Wtime()-time00
5063 time_Bcast=time_Bcast+tcpu()-time00
5065 ! print *,"Processor",myrank,
5066 ! & " BROADCAST iorder in SETUP_FRICMAT"
5069 write (iout,*) "setup_fricmat licznik"!,licznik !sp
5075 ! Scatter the friction matrix
5076 call MPI_Scatterv(fricmat(1,1),nginv_counts(0),&
5077 nginv_start(0),MPI_DOUBLE_PRECISION,fcopy(1,1),&
5078 myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
5081 time_scatter=time_scatter+MPI_Wtime()-time00
5082 time_scatter_fmat=time_scatter_fmat+MPI_Wtime()-time00
5084 time_scatter=time_scatter+tcpu()-time00
5085 time_scatter_fmat=time_scatter_fmat+tcpu()-time00
5089 do j=1,2*my_ng_count
5090 fricmat(j,i)=fcopy(i,j)
5093 ! write (iout,*) "My chunk of fricmat"
5094 ! call MATOUT2(my_ng_count,dimen,maxres2,maxres2,fcopy)
5098 end subroutine setup_fricmat
5099 !-----------------------------------------------------------------------------
5100 subroutine stochastic_force(stochforcvec)
5103 use random, only:anorm_distr
5104 ! implicit real*8 (a-h,o-z)
5105 ! include 'DIMENSIONS'
5106 use control, only: tcpu
5111 ! include 'COMMON.VAR'
5112 ! include 'COMMON.CHAIN'
5113 ! include 'COMMON.DERIV'
5114 ! include 'COMMON.GEO'
5115 ! include 'COMMON.LOCAL'
5116 ! include 'COMMON.INTERACT'
5117 ! include 'COMMON.MD'
5118 ! include 'COMMON.TIME1'
5120 ! include 'COMMON.LANGEVIN'
5122 ! include 'COMMON.LANGEVIN.lang0'
5124 ! include 'COMMON.IOUNITS'
5126 real(kind=8) :: x,sig,lowb,highb
5127 real(kind=8) :: ff(3),force(3,0:2*nres),zeta2,lowb2
5128 real(kind=8) :: highb2,sig2,forcvec(6*nres),stochforcvec(6*nres)
5129 real(kind=8) :: time00
5130 logical :: lprn = .false.
5135 stochforc(j,i)=0.0d0
5145 ! Compute the stochastic forces acting on bodies. Store in force.
5151 force(j,i)=anorm_distr(x,sig,lowb,highb)
5159 force(j,i+nres)=anorm_distr(x,sig2,lowb2,highb2)
5163 time_fsample=time_fsample+MPI_Wtime()-time00
5165 time_fsample=time_fsample+tcpu()-time00
5167 ! Compute the stochastic forces acting on virtual-bond vectors.
5173 stochforc(j,i)=ff(j)+0.5d0*force(j,i)
5176 ff(j)=ff(j)+force(j,i)
5178 if (itype(i+1).ne.ntyp1) then
5180 stochforc(j,i)=stochforc(j,i)+force(j,i+nres+1)
5181 ff(j)=ff(j)+force(j,i+nres+1)
5186 stochforc(j,0)=ff(j)+force(j,nnt+nres)
5189 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
5191 stochforc(j,i+nres)=force(j,i+nres)
5197 stochforcvec(j)=stochforc(j,0)
5202 stochforcvec(ind+j)=stochforc(j,i)
5207 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
5209 stochforcvec(ind+j)=stochforc(j,i+nres)
5215 write (iout,*) "stochforcvec"
5217 write(iout,'(i5,e15.5)') i,stochforcvec(i)
5219 write(iout,*) "Stochastic forces backbone"
5221 write(iout,'(i5,3e15.5)') i,(stochforc(j,i),j=1,3)
5223 write(iout,*) "Stochastic forces side chain"
5225 write(iout,'(i5,3e15.5)') &
5226 i,(stochforc(j,i+nres),j=1,3)
5234 write (iout,*) i,ind
5236 forcvec(ind+j)=force(j,i)
5241 write (iout,*) i,ind
5243 forcvec(j+ind)=force(j,i+nres)
5248 write (iout,*) "forcvec"
5252 write (iout,'(2i3,2f10.5)') i,j,force(j,i),&
5259 write (iout,'(2i3,2f10.5)') i,j,force(j,i+nres),&
5268 end subroutine stochastic_force
5269 !-----------------------------------------------------------------------------
5270 subroutine sdarea(gamvec)
5272 ! Scale the friction coefficients according to solvent accessible surface areas
5273 ! Code adapted from TINKER
5277 ! implicit real*8 (a-h,o-z)
5278 ! include 'DIMENSIONS'
5279 ! include 'COMMON.CONTROL'
5280 ! include 'COMMON.VAR'
5281 ! include 'COMMON.MD'
5283 ! include 'COMMON.LANGEVIN'
5285 ! include 'COMMON.LANGEVIN.lang0'
5287 ! include 'COMMON.CHAIN'
5288 ! include 'COMMON.DERIV'
5289 ! include 'COMMON.GEO'
5290 ! include 'COMMON.LOCAL'
5291 ! include 'COMMON.INTERACT'
5292 ! include 'COMMON.IOUNITS'
5293 ! include 'COMMON.NAMES'
5294 real(kind=8),dimension(2*nres) :: radius,gamvec !(maxres2)
5295 real(kind=8),parameter :: twosix = 1.122462048309372981d0
5296 logical :: lprn = .false.
5297 real(kind=8) :: probe,area,ratio
5298 integer :: i,j,ind,iti
5300 ! determine new friction coefficients every few SD steps
5302 ! set the atomic radii to estimates of sigma values
5304 ! print *,"Entered sdarea"
5310 ! Load peptide group radii
5314 ! Load side chain radii
5317 radius(i+nres)=restok(iti)
5320 ! write (iout,*) "i",i," radius",radius(i)
5323 radius(i) = radius(i) / twosix
5324 if (radius(i) .ne. 0.0d0) radius(i) = radius(i) + probe
5327 ! scale atomic friction coefficients by accessible area
5329 if (lprn) write (iout,*) &
5330 "Original gammas, surface areas, scaling factors, new gammas, ",&
5331 "std's of stochastic forces"
5334 if (radius(i).gt.0.0d0) then
5335 call surfatom (i,area,radius)
5336 ratio = dmax1(area/(4.0d0*pi*radius(i)**2),1.0d-1)
5337 if (lprn) write (iout,'(i5,3f10.5,$)') &
5338 i,gamvec(ind+1),area,ratio
5341 gamvec(ind) = ratio * gamvec(ind)
5343 stdforcp(i)=stdfp*dsqrt(gamvec(ind))
5344 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcp(i)
5348 if (radius(i+nres).gt.0.0d0) then
5349 call surfatom (i+nres,area,radius)
5350 ratio = dmax1(area/(4.0d0*pi*radius(i+nres)**2),1.0d-1)
5351 if (lprn) write (iout,'(i5,3f10.5,$)') &
5352 i,gamvec(ind+1),area,ratio
5355 gamvec(ind) = ratio * gamvec(ind)
5357 stdforcsc(i)=stdfsc(itype(i))*dsqrt(gamvec(ind))
5358 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcsc(i)
5363 end subroutine sdarea
5364 !-----------------------------------------------------------------------------
5366 !-----------------------------------------------------------------------------
5369 ! ###################################################
5370 ! ## COPYRIGHT (C) 1996 by Jay William Ponder ##
5371 ! ## All Rights Reserved ##
5372 ! ###################################################
5374 ! ################################################################
5376 ! ## subroutine surfatom -- exposed surface area of an atom ##
5378 ! ################################################################
5381 ! "surfatom" performs an analytical computation of the surface
5382 ! area of a specified atom; a simplified version of "surface"
5384 ! literature references:
5386 ! T. J. Richmond, "Solvent Accessible Surface Area and
5387 ! Excluded Volume in Proteins", Journal of Molecular Biology,
5390 ! L. Wesson and D. Eisenberg, "Atomic Solvation Parameters
5391 ! Applied to Molecular Dynamics of Proteins in Solution",
5392 ! Protein Science, 1, 227-235 (1992)
5394 ! variables and parameters:
5396 ! ir number of atom for which area is desired
5397 ! area accessible surface area of the atom
5398 ! radius radii of each of the individual atoms
5401 subroutine surfatom(ir,area,radius)
5403 ! implicit real*8 (a-h,o-z)
5404 ! include 'DIMENSIONS'
5406 ! include 'COMMON.GEO'
5407 ! include 'COMMON.IOUNITS'
5409 integer :: nsup,nstart_sup
5410 ! double precision c,dc,dc_old,d_c_work,xloc,xrot,dc_norm
5411 ! common /chain/ c(3,maxres2+2),dc(3,0:maxres2),dc_old(3,0:maxres2),
5412 ! & xloc(3,maxres),xrot(3,maxres),dc_norm(3,0:maxres2),
5413 ! & dc_work(MAXRES6),nres,nres0
5414 integer,parameter :: maxarc=300
5418 integer :: mi,ni,narc
5419 integer :: key(maxarc)
5420 integer :: intag(maxarc)
5421 integer :: intag1(maxarc)
5422 real(kind=8) :: area,arcsum
5423 real(kind=8) :: arclen,exang
5424 real(kind=8) :: delta,delta2
5425 real(kind=8) :: eps,rmove
5426 real(kind=8) :: xr,yr,zr
5427 real(kind=8) :: rr,rrsq
5428 real(kind=8) :: rplus,rminus
5429 real(kind=8) :: axx,axy,axz
5430 real(kind=8) :: ayx,ayy
5431 real(kind=8) :: azx,azy,azz
5432 real(kind=8) :: uxj,uyj,uzj
5433 real(kind=8) :: tx,ty,tz
5434 real(kind=8) :: txb,tyb,td
5435 real(kind=8) :: tr2,tr,txr,tyr
5436 real(kind=8) :: tk1,tk2
5437 real(kind=8) :: thec,the,t,tb
5438 real(kind=8) :: txk,tyk,tzk
5439 real(kind=8) :: t1,ti,tf,tt
5440 real(kind=8) :: txj,tyj,tzj
5441 real(kind=8) :: ccsq,cc,xysq
5442 real(kind=8) :: bsqk,bk,cosine
5443 real(kind=8) :: dsqj,gi,pix2
5444 real(kind=8) :: therk,dk,gk
5445 real(kind=8) :: risqk,rik
5446 real(kind=8) :: radius(2*nres) !(maxatm) (maxatm=maxres2)
5447 real(kind=8) :: ri(maxarc),risq(maxarc)
5448 real(kind=8) :: ux(maxarc),uy(maxarc),uz(maxarc)
5449 real(kind=8) :: xc(maxarc),yc(maxarc),zc(maxarc)
5450 real(kind=8) :: xc1(maxarc),yc1(maxarc),zc1(maxarc)
5451 real(kind=8) :: dsq(maxarc),bsq(maxarc)
5452 real(kind=8) :: dsq1(maxarc),bsq1(maxarc)
5453 real(kind=8) :: arci(maxarc),arcf(maxarc)
5454 real(kind=8) :: ex(maxarc),lt(maxarc),gr(maxarc)
5455 real(kind=8) :: b(maxarc),b1(maxarc),bg(maxarc)
5456 real(kind=8) :: kent(maxarc),kout(maxarc)
5457 real(kind=8) :: ther(maxarc)
5458 logical :: moved,top
5459 logical :: omit(maxarc)
5462 maxatm = 2*nres !maxres2 maxres2=2*maxres
5468 ! zero out the surface area for the sphere of interest
5471 ! write (2,*) "ir",ir," radius",radius(ir)
5472 if (radius(ir) .eq. 0.0d0) return
5474 ! set the overlap significance and connectivity shift
5478 delta2 = delta * delta
5483 ! store coordinates and radius of the sphere of interest
5491 ! initialize values of some counters and summations
5500 ! test each sphere to see if it overlaps the sphere of interest
5503 if (i.eq.ir .or. radius(i).eq.0.0d0) goto 30
5504 rplus = rr + radius(i)
5506 if (abs(tx) .ge. rplus) goto 30
5508 if (abs(ty) .ge. rplus) goto 30
5510 if (abs(tz) .ge. rplus) goto 30
5512 ! check for sphere overlap by testing distance against radii
5514 xysq = tx*tx + ty*ty
5515 if (xysq .lt. delta2) then
5522 if (rplus-cc .le. delta) goto 30
5523 rminus = rr - radius(i)
5525 ! check to see if sphere of interest is completely buried
5527 if (cc-abs(rminus) .le. delta) then
5528 if (rminus .le. 0.0d0) goto 170
5532 ! check for too many overlaps with sphere of interest
5534 if (io .ge. maxarc) then
5536 20 format (/,' SURFATOM -- Increase the Value of MAXARC')
5540 ! get overlap between current sphere and sphere of interest
5549 gr(io) = (ccsq+rplus*rminus) / (2.0d0*rr*b1(io))
5555 ! case where no other spheres overlap the sphere of interest
5558 area = 4.0d0 * pi * rrsq
5562 ! case where only one sphere overlaps the sphere of interest
5565 area = pix2 * (1.0d0 + gr(1))
5566 area = mod(area,4.0d0*pi) * rrsq
5570 ! case where many spheres intersect the sphere of interest;
5571 ! sort the intersecting spheres by their degree of overlap
5573 call sort2 (io,gr,key)
5576 intag(i) = intag1(k)
5585 ! get radius of each overlap circle on surface of the sphere
5590 risq(i) = rrsq - gi*gi
5591 ri(i) = sqrt(risq(i))
5592 ther(i) = 0.5d0*pi - asin(min(1.0d0,max(-1.0d0,gr(i))))
5595 ! find boundary of inaccessible area on sphere of interest
5598 if (.not. omit(k)) then
5605 ! check to see if J circle is intersecting K circle;
5606 ! get distance between circle centers and sum of radii
5609 if (omit(j)) goto 60
5610 cc = (txk*xc(j)+tyk*yc(j)+tzk*zc(j))/(bk*b(j))
5611 cc = acos(min(1.0d0,max(-1.0d0,cc)))
5612 td = therk + ther(j)
5614 ! check to see if circles enclose separate regions
5616 if (cc .ge. td) goto 60
5618 ! check for circle J completely inside circle K
5620 if (cc+ther(j) .lt. therk) goto 40
5622 ! check for circles that are essentially parallel
5624 if (cc .gt. delta) goto 50
5629 ! check to see if sphere of interest is completely buried
5632 if (pix2-cc .le. td) goto 170
5638 ! find T value of circle intersections
5641 if (omit(k)) goto 110
5656 ! rotation matrix elements
5668 if (.not. omit(j)) then
5673 ! rotate spheres so K vector colinear with z-axis
5675 uxj = txj*axx + tyj*axy - tzj*axz
5676 uyj = tyj*ayy - txj*ayx
5677 uzj = txj*azx + tyj*azy + tzj*azz
5678 cosine = min(1.0d0,max(-1.0d0,uzj/b(j)))
5679 if (acos(cosine) .lt. therk+ther(j)) then
5680 dsqj = uxj*uxj + uyj*uyj
5685 tr2 = risqk*dsqj - tb*tb
5691 ! get T values of intersection for K circle
5694 tb = min(1.0d0,max(-1.0d0,tb))
5696 if (tyb-txr .lt. 0.0d0) tk1 = pix2 - tk1
5698 tb = min(1.0d0,max(-1.0d0,tb))
5700 if (tyb+txr .lt. 0.0d0) tk2 = pix2 - tk2
5701 thec = (rrsq*uzj-gk*bg(j)) / (rik*ri(j)*b(j))
5702 if (abs(thec) .lt. 1.0d0) then
5704 else if (thec .ge. 1.0d0) then
5706 else if (thec .le. -1.0d0) then
5710 ! see if "tk1" is entry or exit point; check t=0 point;
5711 ! "ti" is exit point, "tf" is entry point
5713 cosine = min(1.0d0,max(-1.0d0, &
5714 (uzj*gk-uxj*rik)/(b(j)*rr)))
5715 if ((acos(cosine)-ther(j))*(tk2-tk1) .le. 0.0d0) then
5723 if (narc .ge. maxarc) then
5725 70 format (/,' SURFATOM -- Increase the Value',&
5729 if (tf .le. ti) then
5750 ! special case; K circle without intersections
5752 if (narc .le. 0) goto 90
5754 ! general case; sum up arclength and set connectivity code
5756 call sort2 (narc,arci,key)
5761 if (narc .gt. 1) then
5764 if (t .lt. arci(j)) then
5765 arcsum = arcsum + arci(j) - t
5766 exang = exang + ex(ni)
5768 if (jb .ge. maxarc) then
5770 80 format (/,' SURFATOM -- Increase the Value',&
5775 kent(jb) = maxarc*i + k
5777 kout(jb) = maxarc*k + i
5786 arcsum = arcsum + pix2 - t
5788 exang = exang + ex(ni)
5791 kent(jb) = maxarc*i + k
5793 kout(jb) = maxarc*k + i
5800 arclen = arclen + gr(k)*arcsum
5803 if (arclen .eq. 0.0d0) goto 170
5804 if (jb .eq. 0) goto 150
5806 ! find number of independent boundaries and check connectivity
5810 if (kout(k) .ne. 0) then
5817 if (m .eq. kent(ii)) then
5820 if (j .eq. jb) goto 150
5832 ! attempt to fix connectivity error by moving atom slightly
5836 140 format (/,' SURFATOM -- Connectivity Error at Atom',i6)
5845 ! compute the exposed surface area for the sphere of interest
5848 area = ib*pix2 + exang + arclen
5849 area = mod(area,4.0d0*pi) * rrsq
5851 ! attempt to fix negative area by moving atom slightly
5853 if (area .lt. 0.0d0) then
5856 160 format (/,' SURFATOM -- Negative Area at Atom',i6)
5867 end subroutine surfatom
5868 !----------------------------------------------------------------
5869 !----------------------------------------------------------------
5870 subroutine alloc_MD_arrays
5871 !EL Allocation of arrays used by MD module
5873 integer :: nres2,nres6
5876 !----------------------
5880 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
5881 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
5882 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5883 allocate(fricvec(nres2,nres2))
5884 allocate(pfric_mat(nres2,nres2),vfric_mat(nres2,nres2))
5885 allocate(afric_mat(nres2,nres2),prand_mat(nres2,nres2))
5886 allocate(vrand_mat1(nres2,nres2),vrand_mat2(nres2,nres2)) !(MAXRES2,MAXRES2)
5887 allocate(pfric0_mat(nres2,nres2,0:maxflag_stoch))
5888 allocate(afric0_mat(nres2,nres2,0:maxflag_stoch))
5889 allocate(vfric0_mat(nres2,nres2,0:maxflag_stoch))
5890 allocate(prand0_mat(nres2,nres2,0:maxflag_stoch))
5891 allocate(vrand0_mat1(nres2,nres2,0:maxflag_stoch))
5892 allocate(vrand0_mat2(nres2,nres2,0:maxflag_stoch)) !(MAXRES2,MAXRES2,0:maxflag_stoch)
5893 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
5895 allocate(mt1(nres2,nres2),mt2(nres2,nres2),mt3(nres2,nres2)) !(maxres2,maxres2)
5896 !----------------------
5898 ! commom.langevin.lang0
5900 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
5901 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5902 allocate(fricvec(nres2,nres2)) !(MAXRES2,MAXRES2)
5903 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
5904 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
5907 !el if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2))
5908 !----------------------
5909 ! commom.hairpin in CSA module
5910 !----------------------
5911 ! common.mce in MCM_MD module
5912 !----------------------
5914 ! common /mdgrad/ in module.energy
5915 ! common /back_constr/ in module.energy
5916 ! common /qmeas/ in module.energy
5919 allocate(potEcomp(0:n_ene+4)) !(0:n_ene+4)
5921 allocate(d_t(3,0:nres2),d_a(3,0:nres2),d_t_old(3,0:nres2)) !(3,0:MAXRES2)
5922 allocate(d_a_work(nres6)) !(6*MAXRES)
5924 allocate(DM(nres2),DU1(nres2),DU2(nres2))
5925 allocate(DMorig(nres2),DU1orig(nres2),DU2orig(nres2))
5927 allocate(Gmat(nres2,nres2),A(nres2,nres2))
5928 if(.not.allocated(Ginv)) allocate(Ginv(nres2,nres2)) !in control: ergastulum
5929 allocate(Gsqrp(nres2,nres2),Gsqrm(nres2,nres2),Gvec(nres2,nres2)) !(maxres2,maxres2)
5931 allocate(Geigen(nres2)) !(maxres2)
5932 if(.not.allocated(vtot)) allocate(vtot(nres2)) !(maxres2)
5933 ! common /inertia/ in io_conf: parmread
5934 ! real(kind=8),dimension(:),allocatable :: ISC,msc !(ntyp+1)
5935 ! common /langevin/in io read_MDpar
5936 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
5937 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
5938 ! in io_conf: parmread
5939 ! real(kind=8),dimension(:),allocatable :: restok !(ntyp+1)
5940 ! common /mdpmpi/ in control: ergastulum
5941 if(.not.allocated(ng_start)) allocate(ng_start(0:nfgtasks-1))
5942 if(.not.allocated(ng_counts)) allocate(ng_counts(0:nfgtasks-1))
5943 if(.not.allocated(nginv_counts)) allocate(nginv_counts(0:nfgtasks-1)) !(0:MaxProcs-1)
5944 if(.not.allocated(nginv_start)) allocate(nginv_start(0:nfgtasks)) !(0:MaxProcs)
5945 !----------------------
5946 ! common.muca in read_muca
5947 ! common /double_muca/
5948 ! real(kind=8) :: elow,ehigh,factor,hbin,factor_min
5949 ! real(kind=8),dimension(:),allocatable :: emuca,nemuca,&
5950 ! nemuca2,hist !(4*maxres)
5951 ! common /integer_muca/
5952 ! integer :: nmuca,imtime,muca_smooth
5954 ! real(kind=8),dimension(:),allocatable :: elowi,ehighi !(maxprocs)
5955 !----------------------
5957 ! common /mdgrad/ in module.energy
5958 ! common /back_constr/ in module.energy
5959 ! common /qmeas/ in module.energy
5963 allocate(d_t_work(nres6),d_t_work_new(nres6),d_af_work(nres6))
5964 allocate(d_as_work(nres6),kinetic_force(nres6)) !(MAXRES6)
5965 allocate(d_t_new(3,0:nres2),d_a_old(3,0:nres2),d_a_short(3,0:nres2)) !,d_a !(3,0:MAXRES2)
5966 allocate(stdforcp(nres),stdforcsc(nres)) !(MAXRES)
5967 !----------------------
5969 allocate(D_ban(nres6)) !(MAXRES6) maxres6=6*maxres
5970 ! common /stochcalc/ stochforcvec
5971 allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
5972 !----------------------
5974 end subroutine alloc_MD_arrays
5975 !-----------------------------------------------------------------------------
5976 !-----------------------------------------------------------------------------