2 !-----------------------------------------------------------------------------
15 !-----------------------------------------------------------------------------
17 ! common /mdgrad/ in module.energy
18 ! common /back_constr/ in module.energy
19 ! common /qmeas/ in module.energy
23 real(kind=8),dimension(:),allocatable :: d_t_work,&
24 d_t_work_new,d_af_work,d_as_work,kinetic_force !(MAXRES6)
25 real(kind=8),dimension(:,:),allocatable :: d_t_new,&
26 d_a_old,d_a_short!,d_a !(3,0:MAXRES2)
27 ! real(kind=8),dimension(:),allocatable :: d_a_work !(6*MAXRES)
28 ! real(kind=8),dimension(:,:),allocatable :: Gmat,Ginv,A,&
29 ! Gsqrp,Gsqrm,Gvec !(maxres2,maxres2)
30 ! real(kind=8),dimension(:),allocatable :: Geigen !(maxres2)
31 ! integer :: dimen,dimen1,dimen3
32 ! integer :: lang,count_reset_moment,count_reset_vel
33 ! logical :: reset_moment,reset_vel,rattle,RESPA
36 ! real(kind=8) :: rwat,etawat,stdfp,cPoise
37 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
38 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
39 real(kind=8),dimension(:),allocatable :: stdforcp,stdforcsc !(MAXRES)
40 !-----------------------------------------------------------------------------
44 ! ###################################################
45 ! ## COPYRIGHT (C) 1992 by Jay William Ponder ##
46 ! ## All Rights Reserved ##
47 ! ###################################################
49 ! #############################################################
51 ! ## sizes.i -- parameter values to set array dimensions ##
53 ! #############################################################
56 ! "sizes.i" sets values for critical array dimensions used
57 ! throughout the software; these parameters will fix the size
58 ! of the largest systems that can be handled; values too large
59 ! for the computer's memory and/or swap space to accomodate
60 ! will result in poor performance or outright failure
62 ! parameter: maximum allowed number of:
64 ! maxatm atoms in the molecular system
65 ! maxval atoms directly bonded to an atom
66 ! maxgrp ! user-defined groups of atoms
67 ! maxtyp force field atom type definitions
68 ! maxclass force field atom class definitions
69 ! maxkey lines in the keyword file
70 ! maxrot bonds for torsional rotation
71 ! maxvar optimization variables (vector storage)
72 ! maxopt optimization variables (matrix storage)
73 ! maxhess off-diagonal Hessian elements
74 ! maxlight sites for method of lights neighbors
75 ! maxvib vibrational frequencies
76 ! maxgeo distance geometry points
77 ! maxcell unit cells in replicated crystal
78 ! maxring 3-, 4-, or 5-membered rings
79 ! maxfix geometric restraints
80 ! maxbio biopolymer atom definitions
81 ! maxres residues in the macromolecule
82 ! maxamino amino acid residue types
83 ! maxnuc nucleic acid residue types
84 ! maxbnd covalent bonds in molecular system
85 ! maxang bond angles in molecular system
86 ! maxtors torsional angles in molecular system
87 ! maxpi atoms in conjugated pisystem
88 ! maxpib covalent bonds involving pisystem
89 ! maxpit torsional angles involving pisystem
92 !el integer maxatm,maxval,maxgrp
93 !el integer maxtyp,maxclass,maxkey
94 !el integer maxrot,maxopt
95 !el integer maxhess,maxlight,maxvib
96 !el integer maxgeo,maxcell,maxring
97 !el integer maxfix,maxbio
98 !el integer maxamino,maxnuc,maxbnd
99 !el integer maxang,maxtors,maxpi
100 !el integer maxpib,maxpit
101 ! integer :: maxatm !=2*nres !maxres2 maxres2=2*maxres
102 ! integer,parameter :: maxval=8
103 ! integer,parameter :: maxgrp=1000
104 ! integer,parameter :: maxtyp=3000
105 ! integer,parameter :: maxclass=500
106 ! integer,parameter :: maxkey=10000
107 ! integer,parameter :: maxrot=1000
108 ! integer,parameter :: maxopt=1000
109 ! integer,parameter :: maxhess=1000000
110 ! integer :: maxlight !=8*maxatm
111 ! integer,parameter :: maxvib=1000
112 ! integer,parameter :: maxgeo=1000
113 ! integer,parameter :: maxcell=10000
114 ! integer,parameter :: maxring=10000
115 ! integer,parameter :: maxfix=10000
116 ! integer,parameter :: maxbio=10000
117 ! integer,parameter :: maxamino=31
118 ! integer,parameter :: maxnuc=12
119 ! integer :: maxbnd !=2*maxatm
120 ! integer :: maxang !=3*maxatm
121 ! integer :: maxtors !=4*maxatm
122 ! integer,parameter :: maxpi=100
123 ! integer,parameter :: maxpib=2*maxpi
124 ! integer,parameter :: maxpit=4*maxpi
125 !-----------------------------------------------------------------------------
126 ! Maximum number of seed
127 ! integer,parameter :: max_seed=1
128 !-----------------------------------------------------------------------------
129 real(kind=8),dimension(:),allocatable :: stochforcvec !(MAXRES6) maxres6=6*maxres
130 ! common /stochcalc/ stochforcvec
131 !-----------------------------------------------------------------------------
132 ! common /przechowalnia/ subroutines: rattle1,rattle2,rattle_brown
133 real(kind=8),dimension(:,:),allocatable :: GGinv !(2*nres,2*nres) maxres2=2*maxres
134 real(kind=8),dimension(:,:,:),allocatable :: gdc !(3,2*nres,2*nres) maxres2=2*maxres
135 real(kind=8),dimension(:,:),allocatable :: Cmat !(2*nres,2*nres) maxres2=2*maxres
136 !-----------------------------------------------------------------------------
137 ! common /syfek/ subroutines: friction_force,setup_fricmat
138 !el real(kind=8),dimension(:),allocatable :: gamvec !(MAXRES6) or (MAXRES2)
139 !-----------------------------------------------------------------------------
140 ! common /przechowalnia/ subroutines: friction_force,setup_fricmat
141 real(kind=8),dimension(:,:),allocatable :: ginvfric !(2*nres,2*nres) !maxres2=2*maxres
142 !-----------------------------------------------------------------------------
143 ! common /przechowalnia/ subroutine: setup_fricmat
144 real(kind=8),dimension(:,:),allocatable :: fcopy !(2*nres,2*nres)
145 !-----------------------------------------------------------------------------
148 !-----------------------------------------------------------------------------
150 !-----------------------------------------------------------------------------
152 !-----------------------------------------------------------------------------
153 subroutine brown_step(itime)
154 !------------------------------------------------
155 ! Perform a single Euler integration step of Brownian dynamics
156 !------------------------------------------------
157 ! implicit real*8 (a-h,o-z)
159 use control, only: tcpu
162 ! use io_conf, only:cartprint
163 ! include 'DIMENSIONS'
167 ! include 'COMMON.CONTROL'
168 ! include 'COMMON.VAR'
169 ! include 'COMMON.MD'
171 ! include 'COMMON.LANGEVIN'
173 ! include 'COMMON.LANGEVIN.lang0'
175 ! include 'COMMON.CHAIN'
176 ! include 'COMMON.DERIV'
177 ! include 'COMMON.GEO'
178 ! include 'COMMON.LOCAL'
179 ! include 'COMMON.INTERACT'
180 ! include 'COMMON.IOUNITS'
181 ! include 'COMMON.NAMES'
182 ! include 'COMMON.TIME1'
183 real(kind=8),dimension(6*nres) :: zapas !(MAXRES6) maxres6=6*maxres
184 integer :: rstcount !ilen,
186 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
187 real(kind=8),dimension(6*nres,2*nres) :: Bmat,GBmat,Tmat !(MAXRES6,MAXRES2) (maxres2=2*maxres,maxres6=6*maxres)
188 real(kind=8),dimension(2*nres,2*nres) :: Cmat_,Cinv !(maxres2,maxres2) maxres2=2*maxres
189 real(kind=8),dimension(6*nres,6*nres) :: Pmat !(maxres6,maxres6) maxres6=6*maxres
190 real(kind=8),dimension(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,1).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,1).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,1).ne.10) then
311 Td(i)=Td(i)+vbldsc0(1,itype(k,1))*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,1).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,1).ne.10) then
415 xx=vbld(i+nres)-vbldsc0(1,itype(i,1))
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,1).ne.10) then
443 blen2 = scalar(dc(1,i+nres),dc(1,i+nres))
444 ppvec(ind)=2*vbldsc0(1,itype(i,1))**2-blen2
445 diffbond=dabs(vbldsc0(1,itype(i,1))-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,1).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,1).ne.10) then
530 xx=vbld(i+nres)-vbldsc0(1,itype(i,1))
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)
552 ! Calculate the kinetic and total energy and the kinetic temperature
555 t_enegrad=t_enegrad+MPI_Wtime()-tt0
557 t_enegrad=t_enegrad+tcpu()-tt0
560 kinetic_T=2.0d0/(dimen*Rb)*EK
562 end subroutine brown_step
563 !-----------------------------------------------------------------------------
565 !-----------------------------------------------------------------------------
566 subroutine gauss(RO,AP,MT,M,N,*)
568 ! CALCULATES (RO**(-1))*AP BY GAUSS ELIMINATION
569 ! RO IS A SQUARE MATRIX
570 ! THE CALCULATED PRODUCT IS STORED IN AP
571 ! ABNORMAL EXIT IF RO IS SINGULAR
573 integer :: MT, M, N, M1,I,J,IM,&
575 real(kind=8) :: RO(MT,M),AP(MT,N),X,RM,PR,Y
581 if(dabs(X).le.1.0D-13) return 1
593 if(DABS(RO(J,I)).LE.RM) goto 2
607 if(dabs(X).le.1.0E-13) return 1
616 8 AP(J,K)=AP(J,K)-Y*AP(I,K)
618 9 RO(J,K)=RO(J,K)-Y*RO(I,K)
622 if(dabs(X).le.1.0E-13) return 1
632 15 X=X-AP(K,J)*RO(MI,K)
637 !-----------------------------------------------------------------------------
639 !-----------------------------------------------------------------------------
640 subroutine kinetic(KE_total)
641 !----------------------------------------------------------------
642 ! This subroutine calculates the total kinetic energy of the chain
643 !-----------------------------------------------------------------
645 ! implicit real*8 (a-h,o-z)
646 ! include 'DIMENSIONS'
647 ! include 'COMMON.VAR'
648 ! include 'COMMON.CHAIN'
649 ! include 'COMMON.DERIV'
650 ! include 'COMMON.GEO'
651 ! include 'COMMON.LOCAL'
652 ! include 'COMMON.INTERACT'
653 ! include 'COMMON.MD'
654 ! include 'COMMON.IOUNITS'
655 real(kind=8) :: KE_total,mscab
657 integer :: i,j,k,iti,mnum
658 real(kind=8) :: KEt_p,KEt_sc,KEr_p,KEr_sc,incr(3),&
661 write (iout,*) "Velocities, kietic"
663 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
664 (d_t(j,i+nres),j=1,3)
669 ! write (iout,*) "ISC",(isc(itype(i,1)),i=1,nres)
670 ! The translational part for peptide virtual bonds
676 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
677 ! write (iout,*) "Kinetic trp:",i,(incr(j),j=1,3)
679 v(j)=incr(j)+0.5d0*d_t(j,i)
681 vtot(i)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
682 KEt_p=KEt_p+mp(mnum)*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))
684 incr(j)=incr(j)+d_t(j,i)
687 ! write(iout,*) 'KEt_p', KEt_p
688 ! The translational part for the side chain virtual bond
689 ! Only now we can initialize incr with zeros. It must be equal
690 ! to the velocities of the first Calpha.
696 iti=iabs(itype(i,mnum))
702 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
703 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
704 .or.(mnum.eq.5)) then
710 v(j)=incr(j)+d_t(j,nres+i)
713 ! write (iout,*) "Kinetic trsc:",i,(incr(j),j=1,3)
714 ! write (iout,*) "i",i," msc",msc(iti)," v",(v(j),j=1,3)
715 KEt_sc=KEt_sc+mscab*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))
716 vtot(i+nres)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
718 incr(j)=incr(j)+d_t(j,i)
722 ! write(iout,*) 'KEt_sc', KEt_sc
723 ! The part due to stretching and rotation of the peptide groups
727 ! write (iout,*) "i",i
728 ! write (iout,*) "i",i," mag1",mag1," mag2",mag2
732 ! write (iout,*) "Kinetic rotp:",i,(incr(j),j=1,3)
733 KEr_p=KEr_p+Ip(mnum)*(incr(1)*incr(1)+incr(2)*incr(2) &
737 ! write(iout,*) 'KEr_p', KEr_p
738 ! The rotational part of the side chain virtual bond
742 iti=iabs(itype(i,mnum))
743 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
744 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
745 .and.(mnum.ne.5)) then
747 incr(j)=d_t(j,nres+i)
749 ! write (iout,*) "Kinetic rotsc:",i,(incr(j),j=1,3)
750 KEr_sc=KEr_sc+Isc(iti,mnum)*(incr(1)*incr(1)+incr(2)*incr(2)+ &
754 ! The total kinetic energy
756 ! write(iout,*) 'KEr_sc', KEr_sc
757 KE_total=0.5d0*(KEt_p+KEt_sc+0.25d0*KEr_p+KEr_sc)
758 ! write (iout,*) "KE_total",KE_total
760 end subroutine kinetic
761 !-----------------------------------------------------------------------------
763 !-----------------------------------------------------------------------------
765 !------------------------------------------------
766 ! The driver for molecular dynamics subroutines
767 !------------------------------------------------
770 use control, only:tcpu,ovrtim
771 ! use io_comm, only:ilen
773 use compare, only:secondary2,hairpin
774 use io, only:cartout,statout
775 ! implicit real*8 (a-h,o-z)
776 ! include 'DIMENSIONS'
779 integer :: IERROR,ERRCODE
781 ! include 'COMMON.SETUP'
782 ! include 'COMMON.CONTROL'
783 ! include 'COMMON.VAR'
784 ! include 'COMMON.MD'
786 ! include 'COMMON.LANGEVIN'
788 ! include 'COMMON.LANGEVIN.lang0'
790 ! include 'COMMON.CHAIN'
791 ! include 'COMMON.DERIV'
792 ! include 'COMMON.GEO'
793 ! include 'COMMON.LOCAL'
794 ! include 'COMMON.INTERACT'
795 ! include 'COMMON.IOUNITS'
796 ! include 'COMMON.NAMES'
797 ! include 'COMMON.TIME1'
798 ! include 'COMMON.HAIRPIN'
799 real(kind=8),dimension(3) :: L,vcm
801 real(kind=8),dimension(6*nres) :: v_work,v_transf !(maxres6) maxres6=6*maxres
803 integer :: rstcount !ilen,
805 character(len=50) :: tytul
806 !el common /gucio/ cm
807 integer :: itime,i,j,nharp
808 integer,dimension(4,nres/3) :: iharp !(4,nres/3)(4,maxres/3)
810 real(kind=8) :: tt0,scalfac
816 print *,"MY tmpdir",tmpdir,ilen(tmpdir)
817 if (ilen(tmpdir).gt.0) &
818 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_" &
819 //liczba(:ilen(liczba))//'.rst')
821 if (ilen(tmpdir).gt.0) &
822 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_"//'.rst')
829 write (iout,'(20(1h=),a20,20(1h=))') "MD calculation started"
835 print *,"just befor setup matix",nres
836 ! Determine the inverse of the inertia matrix.
837 call setup_MD_matrices
839 print *,"AFTER SETUP MATRICES"
841 print *,"AFTER INIT MD"
844 t_MDsetup = MPI_Wtime()-tt0
846 t_MDsetup = tcpu()-tt0
849 ! Entering the MD loop
855 if (lang.eq.2 .or. lang.eq.3) then
859 call sd_verlet_p_setup
861 call sd_verlet_ciccotti_setup
865 pfric0_mat(i,j,0)=pfric_mat(i,j)
866 afric0_mat(i,j,0)=afric_mat(i,j)
867 vfric0_mat(i,j,0)=vfric_mat(i,j)
868 prand0_mat(i,j,0)=prand_mat(i,j)
869 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
870 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
875 flag_stoch(i)=.false.
879 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
881 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
885 else if (lang.eq.1 .or. lang.eq.4) then
886 print *,"before setup_fricmat"
888 print *,"after setup_fricmat"
891 t_langsetup=MPI_Wtime()-tt0
894 t_langsetup=tcpu()-tt0
897 do itime=1,n_timestep
899 if (large.and. mod(itime,ntwe).eq.0) &
900 write (iout,*) "itime",itime
902 if (lang.gt.0 .and. surfarea .and. &
903 mod(itime,reset_fricmat).eq.0) then
904 if (lang.eq.2 .or. lang.eq.3) then
908 call sd_verlet_p_setup
910 call sd_verlet_ciccotti_setup
914 pfric0_mat(i,j,0)=pfric_mat(i,j)
915 afric0_mat(i,j,0)=afric_mat(i,j)
916 vfric0_mat(i,j,0)=vfric_mat(i,j)
917 prand0_mat(i,j,0)=prand_mat(i,j)
918 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
919 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
924 flag_stoch(i)=.false.
927 else if (lang.eq.1 .or. lang.eq.4) then
930 write (iout,'(a,i10)') &
931 "Friction matrix reset based on surface area, itime",itime
933 if (reset_vel .and. tbf .and. lang.eq.0 &
934 .and. mod(itime,count_reset_vel).eq.0) then
936 write(iout,'(a,f20.2)') &
937 "Velocities reset to random values, time",totT
940 d_t_old(j,i)=d_t(j,i)
944 if (reset_moment .and. mod(itime,count_reset_moment).eq.0) then
948 d_t(j,0)=d_t(j,0)-vcm(j)
951 kinetic_T=2.0d0/(dimen3*Rb)*EK
952 scalfac=dsqrt(T_bath/kinetic_T)
953 write(iout,'(a,f20.2)') "Momenta zeroed out, time",totT
956 d_t_old(j,i)=scalfac*d_t(j,i)
962 ! Time-reversible RESPA algorithm
963 ! (Tuckerman et al., J. Chem. Phys., 97, 1990, 1992)
964 call RESPA_step(itime)
966 ! Variable time step algorithm.
967 call velverlet_step(itime)
971 call brown_step(itime)
973 print *,"Brown dynamics not here!"
975 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
981 if (mod(itime,ntwe).eq.0) call statout(itime)
995 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1.and.mnum.ne.5) then
998 v_work(ind)=d_t(j,i+nres)
1003 write (66,'(80f10.5)') &
1004 ((d_t(j,i),j=1,3),i=0,nres-1),((d_t(j,i+nres),j=1,3),i=1,nres)
1008 v_transf(i)=v_transf(i)+gvec(j,i)*v_work(j)
1010 v_transf(i)= v_transf(i)*dsqrt(geigen(i))
1012 write (67,'(80f10.5)') (v_transf(i),i=1,ind)
1015 if (mod(itime,ntwx).eq.0) then
1016 write (tytul,'("time",f8.2)') totT
1018 call hairpin(.true.,nharp,iharp)
1019 call secondary2(.true.)
1020 call pdbout(potE,tytul,ipdb)
1025 if (rstcount.eq.1000.or.itime.eq.n_timestep) then
1026 open(irest2,file=rest2name,status='unknown')
1027 write(irest2,*) totT,EK,potE,totE,t_bath
1029 ! AL 4/17/17: Now writing d_t(0,:) too
1031 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
1033 ! AL 4/17/17: Now writing d_c(0,:) too
1035 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
1043 t_MD=MPI_Wtime()-tt0
1047 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))') &
1049 'MD calculations setup:',t_MDsetup,&
1050 'Energy & gradient evaluation:',t_enegrad,&
1051 'Stochastic MD setup:',t_langsetup,&
1052 'Stochastic MD step setup:',t_sdsetup,&
1054 write (iout,'(/28(1h=),a25,27(1h=))') &
1055 ' End of MD calculation '
1057 write (iout,*) "time for etotal",t_etotal," elong",t_elong,&
1059 write (iout,*) "time_fric",time_fric," time_stoch",time_stoch,&
1060 " time_fricmatmult",time_fricmatmult," time_fsample ",&
1065 !-----------------------------------------------------------------------------
1066 subroutine velverlet_step(itime)
1067 !-------------------------------------------------------------------------------
1068 ! Perform a single velocity Verlet step; the time step can be rescaled if
1069 ! increments in accelerations exceed the threshold
1070 !-------------------------------------------------------------------------------
1071 ! implicit real*8 (a-h,o-z)
1072 ! include 'DIMENSIONS'
1074 use control, only:tcpu
1078 integer :: ierror,ierrcode
1079 real(kind=8) :: errcode
1081 ! include 'COMMON.SETUP'
1082 ! include 'COMMON.VAR'
1083 ! include 'COMMON.MD'
1085 ! include 'COMMON.LANGEVIN'
1087 ! include 'COMMON.LANGEVIN.lang0'
1089 ! include 'COMMON.CHAIN'
1090 ! include 'COMMON.DERIV'
1091 ! include 'COMMON.GEO'
1092 ! include 'COMMON.LOCAL'
1093 ! include 'COMMON.INTERACT'
1094 ! include 'COMMON.IOUNITS'
1095 ! include 'COMMON.NAMES'
1096 ! include 'COMMON.TIME1'
1097 ! include 'COMMON.MUCA'
1098 real(kind=8),dimension(3) :: vcm,incr
1099 real(kind=8),dimension(3) :: L
1100 integer :: count,rstcount !ilen,
1102 character(len=50) :: tytul
1103 integer :: maxcount_scale = 20
1104 !el common /gucio/ cm
1105 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1106 !el common /stochcalc/ stochforcvec
1107 integer :: itime,icount_scale,itime_scal,i,j,ifac_time
1109 real(kind=8) :: epdrift,tt0,fac_time
1111 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1117 else if (lang.eq.2 .or. lang.eq.3) then
1119 call stochastic_force(stochforcvec)
1122 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1124 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1131 icount_scale=icount_scale+1
1132 if (icount_scale.gt.maxcount_scale) then
1134 "ERROR: too many attempts at scaling down the time step. ",&
1135 "amax=",amax,"epdrift=",epdrift,&
1136 "damax=",damax,"edriftmax=",edriftmax,&
1140 call MPI_Abort(MPI_COMM_WORLD,IERROR,IERRCODE)
1144 ! First step of the velocity Verlet algorithm
1149 else if (lang.eq.3) then
1151 call sd_verlet1_ciccotti
1153 else if (lang.eq.1) then
1158 ! Build the chain from the newly calculated coordinates
1159 call chainbuild_cart
1160 if (rattle) call rattle1
1162 if (large.and. mod(itime,ntwe).eq.0) then
1163 write (iout,*) "Cartesian and internal coordinates: step 1"
1168 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
1169 (dc(j,i+nres),j=1,3)
1171 write (iout,*) "Accelerations"
1173 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1174 (d_a(j,i+nres),j=1,3)
1176 write (iout,*) "Velocities, step 1"
1178 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1179 (d_t(j,i+nres),j=1,3)
1188 ! Calculate energy and forces
1190 call etotal(potEcomp)
1191 ! AL 4/17/17: Reduce the steps if NaNs occurred.
1192 if (potEcomp(0).gt.0.99e20 .or. isnan(potEcomp(0)).gt.0) then
1197 if (large.and. mod(itime,ntwe).eq.0) &
1198 call enerprint(potEcomp)
1201 t_etotal=t_etotal+MPI_Wtime()-tt0
1203 t_etotal=t_etotal+tcpu()-tt0
1206 potE=potEcomp(0)-potEcomp(20)
1208 ! Get the new accelerations
1211 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1213 t_enegrad=t_enegrad+tcpu()-tt0
1215 ! Determine maximum acceleration and scale down the timestep if needed
1217 amax=amax/(itime_scal+1)**2
1218 call predict_edrift(epdrift)
1219 if (amax/(itime_scal+1).gt.damax .or. epdrift.gt.edriftmax) then
1220 ! Maximum acceleration or maximum predicted energy drift exceeded, rescale the time step
1222 ifac_time=dmax1(dlog(amax/damax),dlog(epdrift/edriftmax)) &
1224 itime_scal=itime_scal+ifac_time
1225 ! fac_time=dmin1(damax/amax,0.5d0)
1226 fac_time=0.5d0**ifac_time
1227 d_time=d_time*fac_time
1228 if (lang.eq.2 .or. lang.eq.3) then
1230 ! write (iout,*) "Calling sd_verlet_setup: 1"
1231 ! Rescale the stochastic forces and recalculate or restore
1232 ! the matrices of tinker integrator
1233 if (itime_scal.gt.maxflag_stoch) then
1234 if (large) write (iout,'(a,i5,a)') &
1235 "Calculate matrices for stochastic step;",&
1236 " itime_scal ",itime_scal
1238 call sd_verlet_p_setup
1240 call sd_verlet_ciccotti_setup
1242 write (iout,'(2a,i3,a,i3,1h.)') &
1243 "Warning: cannot store matrices for stochastic",&
1244 " integration because the index",itime_scal,&
1245 " is greater than",maxflag_stoch
1246 write (iout,'(2a)')"Increase MAXFLAG_STOCH or use direct",&
1247 " integration Langevin algorithm for better efficiency."
1248 else if (flag_stoch(itime_scal)) then
1249 if (large) write (iout,'(a,i5,a,l1)') &
1250 "Restore matrices for stochastic step; itime_scal ",&
1251 itime_scal," flag ",flag_stoch(itime_scal)
1254 pfric_mat(i,j)=pfric0_mat(i,j,itime_scal)
1255 afric_mat(i,j)=afric0_mat(i,j,itime_scal)
1256 vfric_mat(i,j)=vfric0_mat(i,j,itime_scal)
1257 prand_mat(i,j)=prand0_mat(i,j,itime_scal)
1258 vrand_mat1(i,j)=vrand0_mat1(i,j,itime_scal)
1259 vrand_mat2(i,j)=vrand0_mat2(i,j,itime_scal)
1263 if (large) write (iout,'(2a,i5,a,l1)') &
1264 "Calculate & store matrices for stochastic step;",&
1265 " itime_scal ",itime_scal," flag ",flag_stoch(itime_scal)
1267 call sd_verlet_p_setup
1269 call sd_verlet_ciccotti_setup
1271 flag_stoch(ifac_time)=.true.
1274 pfric0_mat(i,j,itime_scal)=pfric_mat(i,j)
1275 afric0_mat(i,j,itime_scal)=afric_mat(i,j)
1276 vfric0_mat(i,j,itime_scal)=vfric_mat(i,j)
1277 prand0_mat(i,j,itime_scal)=prand_mat(i,j)
1278 vrand0_mat1(i,j,itime_scal)=vrand_mat1(i,j)
1279 vrand0_mat2(i,j,itime_scal)=vrand_mat2(i,j)
1283 fac_time=1.0d0/dsqrt(fac_time)
1285 stochforcvec(i)=fac_time*stochforcvec(i)
1288 else if (lang.eq.1) then
1289 ! Rescale the accelerations due to stochastic forces
1290 fac_time=1.0d0/dsqrt(fac_time)
1292 d_as_work(i)=d_as_work(i)*fac_time
1295 if (large) write (iout,'(a,i10,a,f8.6,a,i3,a,i3)') &
1296 "itime",itime," Timestep scaled down to ",&
1297 d_time," ifac_time",ifac_time," itime_scal",itime_scal
1299 ! Second step of the velocity Verlet algorithm
1304 else if (lang.eq.3) then
1306 call sd_verlet2_ciccotti
1308 else if (lang.eq.1) then
1313 if (rattle) call rattle2
1316 if (d_time.ne.d_time0) then
1319 if (lang.eq.2 .or. lang.eq.3) then
1320 if (large) write (iout,'(a)') &
1321 "Restore original matrices for stochastic step"
1322 ! write (iout,*) "Calling sd_verlet_setup: 2"
1323 ! Restore the matrices of tinker integrator if the time step has been restored
1326 pfric_mat(i,j)=pfric0_mat(i,j,0)
1327 afric_mat(i,j)=afric0_mat(i,j,0)
1328 vfric_mat(i,j)=vfric0_mat(i,j,0)
1329 prand_mat(i,j)=prand0_mat(i,j,0)
1330 vrand_mat1(i,j)=vrand0_mat1(i,j,0)
1331 vrand_mat2(i,j)=vrand0_mat2(i,j,0)
1340 ! Calculate the kinetic and the total energy and the kinetic temperature
1344 ! call kinetic1(EK1)
1345 ! write (iout,*) "step",itime," EK",EK," EK1",EK1
1347 ! Couple the system to Berendsen bath if needed
1348 if (tbf .and. lang.eq.0) then
1351 kinetic_T=2.0d0/(dimen3*Rb)*EK
1352 ! Backup the coordinates, velocities, and accelerations
1356 d_t_old(j,i)=d_t(j,i)
1357 d_a_old(j,i)=d_a(j,i)
1361 if (mod(itime,ntwe).eq.0 .and. large) then
1362 write (iout,*) "Velocities, step 2"
1364 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1365 (d_t(j,i+nres),j=1,3)
1370 end subroutine velverlet_step
1371 !-----------------------------------------------------------------------------
1372 subroutine RESPA_step(itime)
1373 !-------------------------------------------------------------------------------
1374 ! Perform a single RESPA step.
1375 !-------------------------------------------------------------------------------
1376 ! implicit real*8 (a-h,o-z)
1377 ! include 'DIMENSIONS'
1381 use control, only:tcpu
1383 ! use io_conf, only:cartprint
1386 integer :: IERROR,ERRCODE
1388 ! include 'COMMON.SETUP'
1389 ! include 'COMMON.CONTROL'
1390 ! include 'COMMON.VAR'
1391 ! include 'COMMON.MD'
1393 ! include 'COMMON.LANGEVIN'
1395 ! include 'COMMON.LANGEVIN.lang0'
1397 ! include 'COMMON.CHAIN'
1398 ! include 'COMMON.DERIV'
1399 ! include 'COMMON.GEO'
1400 ! include 'COMMON.LOCAL'
1401 ! include 'COMMON.INTERACT'
1402 ! include 'COMMON.IOUNITS'
1403 ! include 'COMMON.NAMES'
1404 ! include 'COMMON.TIME1'
1405 real(kind=8),dimension(0:n_ene) :: energia_short,energia_long
1406 real(kind=8),dimension(3) :: L,vcm,incr
1407 real(kind=8),dimension(3,0:2*nres) :: dc_old0,d_t_old0,d_a_old0 !(3,0:maxres2) maxres2=2*maxres
1408 logical :: PRINT_AMTS_MSG = .false.
1409 integer :: count,rstcount !ilen,
1411 character(len=50) :: tytul
1412 integer :: maxcount_scale = 10
1413 !el common /gucio/ cm
1414 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1415 !el common /stochcalc/ stochforcvec
1416 integer :: itime,itt,i,j,itsplit
1418 !el common /cipiszcze/ itt
1420 real(kind=8) :: epdrift,tt0,epdriftmax
1423 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1427 if (large.and. mod(itime,ntwe).eq.0) then
1428 write (iout,*) "***************** RESPA itime",itime
1429 write (iout,*) "Cartesian and internal coordinates: step 0"
1431 call pdbout(0.0d0,"cipiszcze",iout)
1433 write (iout,*) "Accelerations from long-range forces"
1435 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1436 (d_a(j,i+nres),j=1,3)
1438 write (iout,*) "Velocities, step 0"
1440 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1441 (d_t(j,i+nres),j=1,3)
1446 ! Perform the initial RESPA step (increment velocities)
1447 ! write (iout,*) "*********************** RESPA ini"
1450 if (mod(itime,ntwe).eq.0 .and. large) then
1451 write (iout,*) "Velocities, end"
1453 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1454 (d_t(j,i+nres),j=1,3)
1458 ! Compute the short-range forces
1464 ! 7/2/2009 commented out
1466 ! call etotal_short(energia_short)
1469 ! 7/2/2009 Copy accelerations due to short-lange forces from previous MD step
1472 d_a(j,i)=d_a_short(j,i)
1476 if (large.and. mod(itime,ntwe).eq.0) then
1477 write (iout,*) "energia_short",energia_short(0)
1478 write (iout,*) "Accelerations from short-range forces"
1480 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1481 (d_a(j,i+nres),j=1,3)
1486 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1488 t_enegrad=t_enegrad+tcpu()-tt0
1493 d_t_old(j,i)=d_t(j,i)
1494 d_a_old(j,i)=d_a(j,i)
1497 ! 6/30/08 A-MTS: attempt at increasing the split number
1500 dc_old0(j,i)=dc_old(j,i)
1501 d_t_old0(j,i)=d_t_old(j,i)
1502 d_a_old0(j,i)=d_a_old(j,i)
1505 if (ntime_split.gt.ntime_split0) ntime_split=ntime_split/2
1506 if (ntime_split.lt.ntime_split0) ntime_split=ntime_split0
1513 ! write (iout,*) "itime",itime," ntime_split",ntime_split
1514 ! Split the time step
1515 d_time=d_time0/ntime_split
1516 ! Perform the short-range RESPA steps (velocity Verlet increments of
1517 ! positions and velocities using short-range forces)
1518 ! write (iout,*) "*********************** RESPA split"
1519 do itsplit=1,ntime_split
1522 else if (lang.eq.2 .or. lang.eq.3) then
1524 call stochastic_force(stochforcvec)
1527 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1529 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1534 ! First step of the velocity Verlet algorithm
1539 else if (lang.eq.3) then
1541 call sd_verlet1_ciccotti
1543 else if (lang.eq.1) then
1548 ! Build the chain from the newly calculated coordinates
1549 call chainbuild_cart
1550 if (rattle) call rattle1
1552 if (large.and. mod(itime,ntwe).eq.0) then
1553 write (iout,*) "***** ITSPLIT",itsplit
1554 write (iout,*) "Cartesian and internal coordinates: step 1"
1555 call pdbout(0.0d0,"cipiszcze",iout)
1558 write (iout,*) "Velocities, step 1"
1560 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1561 (d_t(j,i+nres),j=1,3)
1570 ! Calculate energy and forces
1572 call etotal_short(energia_short)
1573 ! AL 4/17/17: Exit itime_split loop when energy goes infinite
1574 if (energia_short(0).gt.0.99e20 .or. isnan(energia_short(0)) ) then
1575 if (PRINT_AMTS_MSG) &
1576 write (iout,*) "Infinities/NaNs in energia_short",energia_short(0),"; increasing ntime_split to",ntime_split
1577 ntime_split=ntime_split*2
1578 if (ntime_split.gt.maxtime_split) then
1581 "Cannot rescue the run; aborting job. Retry with a smaller time step"
1583 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1586 "Cannot rescue the run; terminating. Retry with a smaller time step"
1592 if (large.and. mod(itime,ntwe).eq.0) &
1593 call enerprint(energia_short)
1596 t_eshort=t_eshort+MPI_Wtime()-tt0
1598 t_eshort=t_eshort+tcpu()-tt0
1602 ! Get the new accelerations
1604 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
1607 d_a_short(j,i)=d_a(j,i)
1611 if (large.and. mod(itime,ntwe).eq.0) then
1612 write (iout,*)"energia_short",energia_short(0)
1613 write (iout,*) "Accelerations from short-range forces"
1615 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1616 (d_a(j,i+nres),j=1,3)
1621 ! Determine maximum acceleration and scale down the timestep if needed
1623 amax=amax/ntime_split**2
1624 call predict_edrift(epdrift)
1625 if (ntwe.gt.0 .and. large .and. mod(itime,ntwe).eq.0) &
1626 write (iout,*) "amax",amax," damax",damax,&
1627 " epdrift",epdrift," epdriftmax",epdriftmax
1628 ! Exit loop and try with increased split number if the change of
1629 ! acceleration is too big
1630 if (amax.gt.damax .or. epdrift.gt.edriftmax) then
1631 if (ntime_split.lt.maxtime_split) then
1633 ntime_split=ntime_split*2
1634 ! AL 4/17/17: We should exit the itime_split loop when acceleration change is too big
1638 dc_old(j,i)=dc_old0(j,i)
1639 d_t_old(j,i)=d_t_old0(j,i)
1640 d_a_old(j,i)=d_a_old0(j,i)
1643 if (PRINT_AMTS_MSG) then
1644 write (iout,*) "acceleration/energy drift too large",amax,&
1645 epdrift," split increased to ",ntime_split," itime",itime,&
1651 "Uh-hu. Bumpy landscape. Maximum splitting number",&
1653 " already reached!!! Trying to carry on!"
1657 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1659 t_enegrad=t_enegrad+tcpu()-tt0
1661 ! Second step of the velocity Verlet algorithm
1666 else if (lang.eq.3) then
1668 call sd_verlet2_ciccotti
1670 else if (lang.eq.1) then
1675 if (rattle) call rattle2
1676 ! Backup the coordinates, velocities, and accelerations
1680 d_t_old(j,i)=d_t(j,i)
1681 d_a_old(j,i)=d_a(j,i)
1688 ! Restore the time step
1690 ! Compute long-range forces
1697 call etotal_long(energia_long)
1698 if (energia_long(0).gt.0.99e20 .or. isnan(energia_long(0))) then
1701 "Infinitied/NaNs in energia_long, Aborting MPI job."
1703 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1705 write (iout,*) "Infinitied/NaNs in energia_long, terminating."
1709 if (large.and. mod(itime,ntwe).eq.0) &
1710 call enerprint(energia_long)
1713 t_elong=t_elong+MPI_Wtime()-tt0
1715 t_elong=t_elong+tcpu()-tt0
1721 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1723 t_enegrad=t_enegrad+tcpu()-tt0
1725 ! Compute accelerations from long-range forces
1727 if (large.and. mod(itime,ntwe).eq.0) then
1728 write (iout,*) "energia_long",energia_long(0)
1729 write (iout,*) "Cartesian and internal coordinates: step 2"
1731 call pdbout(0.0d0,"cipiszcze",iout)
1733 write (iout,*) "Accelerations from long-range forces"
1735 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1736 (d_a(j,i+nres),j=1,3)
1738 write (iout,*) "Velocities, step 2"
1740 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1741 (d_t(j,i+nres),j=1,3)
1745 ! Compute the final RESPA step (increment velocities)
1746 ! write (iout,*) "*********************** RESPA fin"
1748 ! Compute the complete potential energy
1750 potEcomp(i)=energia_short(i)+energia_long(i)
1752 potE=potEcomp(0)-potEcomp(20)
1753 ! potE=energia_short(0)+energia_long(0)
1756 ! Calculate the kinetic and the total energy and the kinetic temperature
1759 ! Couple the system to Berendsen bath if needed
1760 if (tbf .and. lang.eq.0) then
1763 kinetic_T=2.0d0/(dimen3*Rb)*EK
1764 ! Backup the coordinates, velocities, and accelerations
1766 if (mod(itime,ntwe).eq.0 .and. large) then
1767 write (iout,*) "Velocities, end"
1769 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1770 (d_t(j,i+nres),j=1,3)
1775 end subroutine RESPA_step
1776 !-----------------------------------------------------------------------------
1777 subroutine RESPA_vel
1778 ! First and last RESPA step (incrementing velocities using long-range
1781 ! implicit real*8 (a-h,o-z)
1782 ! include 'DIMENSIONS'
1783 ! include 'COMMON.CONTROL'
1784 ! include 'COMMON.VAR'
1785 ! include 'COMMON.MD'
1786 ! include 'COMMON.CHAIN'
1787 ! include 'COMMON.DERIV'
1788 ! include 'COMMON.GEO'
1789 ! include 'COMMON.LOCAL'
1790 ! include 'COMMON.INTERACT'
1791 ! include 'COMMON.IOUNITS'
1792 ! include 'COMMON.NAMES'
1793 integer :: i,j,inres,mnum
1796 d_t(j,0)=d_t(j,0)+0.5d0*d_a(j,0)*d_time
1800 d_t(j,i)=d_t(j,i)+0.5d0*d_a(j,i)*d_time
1805 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1806 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1807 .and.(mnum.ne.5)) then
1810 d_t(j,inres)=d_t(j,inres)+0.5d0*d_a(j,inres)*d_time
1815 end subroutine RESPA_vel
1816 !-----------------------------------------------------------------------------
1818 ! Applying velocity Verlet algorithm - step 1 to coordinates
1820 ! implicit real*8 (a-h,o-z)
1821 ! include 'DIMENSIONS'
1822 ! include 'COMMON.CONTROL'
1823 ! include 'COMMON.VAR'
1824 ! include 'COMMON.MD'
1825 ! include 'COMMON.CHAIN'
1826 ! include 'COMMON.DERIV'
1827 ! include 'COMMON.GEO'
1828 ! include 'COMMON.LOCAL'
1829 ! include 'COMMON.INTERACT'
1830 ! include 'COMMON.IOUNITS'
1831 ! include 'COMMON.NAMES'
1832 real(kind=8) :: adt,adt2
1833 integer :: i,j,inres,mnum
1836 write (iout,*) "VELVERLET1 START: DC"
1838 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1839 (dc(j,i+nres),j=1,3)
1843 adt=d_a_old(j,0)*d_time
1845 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1846 d_t_new(j,0)=d_t_old(j,0)+adt2
1847 d_t(j,0)=d_t_old(j,0)+adt
1851 adt=d_a_old(j,i)*d_time
1853 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1854 d_t_new(j,i)=d_t_old(j,i)+adt2
1855 d_t(j,i)=d_t_old(j,i)+adt
1860 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1861 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1862 .and.(mnum.ne.5)) then
1865 adt=d_a_old(j,inres)*d_time
1867 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1868 d_t_new(j,inres)=d_t_old(j,inres)+adt2
1869 d_t(j,inres)=d_t_old(j,inres)+adt
1874 write (iout,*) "VELVERLET1 END: DC"
1876 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1877 (dc(j,i+nres),j=1,3)
1881 end subroutine verlet1
1882 !-----------------------------------------------------------------------------
1884 ! Step 2 of the velocity Verlet algorithm: update velocities
1886 ! implicit real*8 (a-h,o-z)
1887 ! include 'DIMENSIONS'
1888 ! include 'COMMON.CONTROL'
1889 ! include 'COMMON.VAR'
1890 ! include 'COMMON.MD'
1891 ! include 'COMMON.CHAIN'
1892 ! include 'COMMON.DERIV'
1893 ! include 'COMMON.GEO'
1894 ! include 'COMMON.LOCAL'
1895 ! include 'COMMON.INTERACT'
1896 ! include 'COMMON.IOUNITS'
1897 ! include 'COMMON.NAMES'
1898 integer :: i,j,inres,mnum
1901 d_t(j,0)=d_t_new(j,0)+0.5d0*d_a(j,0)*d_time
1905 d_t(j,i)=d_t_new(j,i)+0.5d0*d_a(j,i)*d_time
1910 ! iti=iabs(itype(i,mnum))
1911 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1912 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1913 .and.(mnum.ne.5)) then
1916 d_t(j,inres)=d_t_new(j,inres)+0.5d0*d_a(j,inres)*d_time
1921 end subroutine verlet2
1922 !-----------------------------------------------------------------------------
1923 subroutine sddir_precalc
1924 ! Applying velocity Verlet algorithm - step 1 to coordinates
1925 ! implicit real*8 (a-h,o-z)
1926 ! include 'DIMENSIONS'
1932 ! include 'COMMON.CONTROL'
1933 ! include 'COMMON.VAR'
1934 ! include 'COMMON.MD'
1936 ! include 'COMMON.LANGEVIN'
1938 ! include 'COMMON.LANGEVIN.lang0'
1940 ! include 'COMMON.CHAIN'
1941 ! include 'COMMON.DERIV'
1942 ! include 'COMMON.GEO'
1943 ! include 'COMMON.LOCAL'
1944 ! include 'COMMON.INTERACT'
1945 ! include 'COMMON.IOUNITS'
1946 ! include 'COMMON.NAMES'
1947 ! include 'COMMON.TIME1'
1948 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1949 !el common /stochcalc/ stochforcvec
1950 real(kind=8) :: time00
1952 ! Compute friction and stochastic forces
1957 time_fric=time_fric+MPI_Wtime()-time00
1959 call stochastic_force(stochforcvec)
1960 time_stoch=time_stoch+MPI_Wtime()-time00
1963 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
1964 ! forces (d_as_work)
1966 call ginv_mult(fric_work, d_af_work)
1967 call ginv_mult(stochforcvec, d_as_work)
1969 end subroutine sddir_precalc
1970 !-----------------------------------------------------------------------------
1971 subroutine sddir_verlet1
1972 ! Applying velocity Verlet algorithm - step 1 to velocities
1975 ! implicit real*8 (a-h,o-z)
1976 ! include 'DIMENSIONS'
1977 ! include 'COMMON.CONTROL'
1978 ! include 'COMMON.VAR'
1979 ! include 'COMMON.MD'
1981 ! include 'COMMON.LANGEVIN'
1983 ! include 'COMMON.LANGEVIN.lang0'
1985 ! include 'COMMON.CHAIN'
1986 ! include 'COMMON.DERIV'
1987 ! include 'COMMON.GEO'
1988 ! include 'COMMON.LOCAL'
1989 ! include 'COMMON.INTERACT'
1990 ! include 'COMMON.IOUNITS'
1991 ! include 'COMMON.NAMES'
1992 ! Revised 3/31/05 AL: correlation between random contributions to
1993 ! position and velocity increments included.
1994 real(kind=8) :: sqrt13 = 0.57735026918962576451d0 ! 1/sqrt(3)
1995 real(kind=8) :: adt,adt2
1996 integer :: i,j,ind,inres,mnum
1998 ! Add the contribution from BOTH friction and stochastic force to the
1999 ! coordinates, but ONLY the contribution from the friction forces to velocities
2002 adt=(d_a_old(j,0)+d_af_work(j))*d_time
2003 adt2=0.5d0*adt+sqrt13*d_as_work(j)*d_time
2004 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
2005 d_t_new(j,0)=d_t_old(j,0)+0.5d0*adt
2006 d_t(j,0)=d_t_old(j,0)+adt
2011 adt=(d_a_old(j,i)+d_af_work(ind+j))*d_time
2012 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
2013 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
2014 d_t_new(j,i)=d_t_old(j,i)+0.5d0*adt
2015 d_t(j,i)=d_t_old(j,i)+adt
2021 ! iti=iabs(itype(i,mnum))
2022 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2023 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2024 .and.(mnum.ne.5)) then
2027 adt=(d_a_old(j,inres)+d_af_work(ind+j))*d_time
2028 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
2029 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
2030 d_t_new(j,inres)=d_t_old(j,inres)+0.5d0*adt
2031 d_t(j,inres)=d_t_old(j,inres)+adt
2037 end subroutine sddir_verlet1
2038 !-----------------------------------------------------------------------------
2039 subroutine sddir_verlet2
2040 ! Calculating the adjusted velocities for accelerations
2043 ! implicit real*8 (a-h,o-z)
2044 ! include 'DIMENSIONS'
2045 ! include 'COMMON.CONTROL'
2046 ! include 'COMMON.VAR'
2047 ! include 'COMMON.MD'
2049 ! include 'COMMON.LANGEVIN'
2051 ! include 'COMMON.LANGEVIN.lang0'
2053 ! include 'COMMON.CHAIN'
2054 ! include 'COMMON.DERIV'
2055 ! include 'COMMON.GEO'
2056 ! include 'COMMON.LOCAL'
2057 ! include 'COMMON.INTERACT'
2058 ! include 'COMMON.IOUNITS'
2059 ! include 'COMMON.NAMES'
2060 real(kind=8),dimension(6*nres) :: stochforcvec,d_as_work1 !(MAXRES6) maxres6=6*maxres
2061 real(kind=8) :: cos60 = 0.5d0, sin60 = 0.86602540378443864676d0
2062 integer :: i,j,ind,inres,mnum
2063 ! Revised 3/31/05 AL: correlation between random contributions to
2064 ! position and velocity increments included.
2065 ! The correlation coefficients are calculated at low-friction limit.
2066 ! Also, friction forces are now not calculated with new velocities.
2068 ! call friction_force
2069 call stochastic_force(stochforcvec)
2071 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
2072 ! forces (d_as_work)
2074 call ginv_mult(stochforcvec, d_as_work1)
2080 d_t(j,0)=d_t_new(j,0)+(0.5d0*(d_a(j,0)+d_af_work(j)) &
2081 +sin60*d_as_work(j)+cos60*d_as_work1(j))*d_time
2086 d_t(j,i)=d_t_new(j,i)+(0.5d0*(d_a(j,i)+d_af_work(ind+j)) &
2087 +sin60*d_as_work(ind+j)+cos60*d_as_work1(ind+j))*d_time
2093 ! iti=iabs(itype(i,mnum))
2094 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2095 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2096 .and.(mnum.ne.5)) then
2099 d_t(j,inres)=d_t_new(j,inres)+(0.5d0*(d_a(j,inres) &
2100 +d_af_work(ind+j))+sin60*d_as_work(ind+j) &
2101 +cos60*d_as_work1(ind+j))*d_time
2107 end subroutine sddir_verlet2
2108 !-----------------------------------------------------------------------------
2109 subroutine max_accel
2111 ! Find the maximum difference in the accelerations of the the sites
2112 ! at the beginning and the end of the time step.
2115 ! implicit real*8 (a-h,o-z)
2116 ! include 'DIMENSIONS'
2117 ! include 'COMMON.CONTROL'
2118 ! include 'COMMON.VAR'
2119 ! include 'COMMON.MD'
2120 ! include 'COMMON.CHAIN'
2121 ! include 'COMMON.DERIV'
2122 ! include 'COMMON.GEO'
2123 ! include 'COMMON.LOCAL'
2124 ! include 'COMMON.INTERACT'
2125 ! include 'COMMON.IOUNITS'
2126 real(kind=8),dimension(3) :: aux,accel,accel_old
2127 real(kind=8) :: dacc
2131 ! aux(j)=d_a(j,0)-d_a_old(j,0)
2132 accel_old(j)=d_a_old(j,0)
2139 ! 7/3/08 changed to asymmetric difference
2141 ! accel(j)=aux(j)+0.5d0*(d_a(j,i)-d_a_old(j,i))
2142 accel_old(j)=accel_old(j)+0.5d0*d_a_old(j,i)
2143 accel(j)=accel(j)+0.5d0*d_a(j,i)
2144 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2145 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2146 dacc=dabs(accel(j)-accel_old(j))
2147 ! write (iout,*) i,dacc
2148 if (dacc.gt.amax) amax=dacc
2156 accel_old(j)=d_a_old(j,0)
2161 accel_old(j)=accel_old(j)+d_a_old(j,1)
2162 accel(j)=accel(j)+d_a(j,1)
2167 ! iti=iabs(itype(i,mnum))
2168 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2169 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2170 .and.(mnum.ne.5)) then
2172 ! accel(j)=accel(j)+d_a(j,i+nres)-d_a_old(j,i+nres)
2173 accel_old(j)=accel_old(j)+d_a_old(j,i+nres)
2174 accel(j)=accel(j)+d_a(j,i+nres)
2178 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2179 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2180 dacc=dabs(accel(j)-accel_old(j))
2181 ! write (iout,*) "side-chain",i,dacc
2182 if (dacc.gt.amax) amax=dacc
2186 accel_old(j)=accel_old(j)+d_a_old(j,i)
2187 accel(j)=accel(j)+d_a(j,i)
2188 ! aux(j)=aux(j)+d_a(j,i)-d_a_old(j,i)
2192 end subroutine max_accel
2193 !-----------------------------------------------------------------------------
2194 subroutine predict_edrift(epdrift)
2196 ! Predict the drift of the potential energy
2199 use control_data, only: lmuca
2200 ! implicit real*8 (a-h,o-z)
2201 ! include 'DIMENSIONS'
2202 ! include 'COMMON.CONTROL'
2203 ! include 'COMMON.VAR'
2204 ! include 'COMMON.MD'
2205 ! include 'COMMON.CHAIN'
2206 ! include 'COMMON.DERIV'
2207 ! include 'COMMON.GEO'
2208 ! include 'COMMON.LOCAL'
2209 ! include 'COMMON.INTERACT'
2210 ! include 'COMMON.IOUNITS'
2211 ! include 'COMMON.MUCA'
2212 real(kind=8) :: epdrift,epdriftij
2214 ! Drift of the potential energy
2220 epdriftij=dabs((d_a(j,i)-d_a_old(j,i))*gcart(j,i))
2221 if (lmuca) epdriftij=epdriftij*factor
2222 ! write (iout,*) "back",i,j,epdriftij
2223 if (epdriftij.gt.epdrift) epdrift=epdriftij
2227 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1.and.&
2228 molnum(i).ne.5) then
2231 dabs((d_a(j,i+nres)-d_a_old(j,i+nres))*gxcart(j,i))
2232 if (lmuca) epdriftij=epdriftij*factor
2233 ! write (iout,*) "side",i,j,epdriftij
2234 if (epdriftij.gt.epdrift) epdrift=epdriftij
2238 epdrift=0.5d0*epdrift*d_time*d_time
2239 ! write (iout,*) "epdrift",epdrift
2241 end subroutine predict_edrift
2242 !-----------------------------------------------------------------------------
2243 subroutine verlet_bath
2245 ! Coupling to the thermostat by using the Berendsen algorithm
2248 ! implicit real*8 (a-h,o-z)
2249 ! include 'DIMENSIONS'
2250 ! include 'COMMON.CONTROL'
2251 ! include 'COMMON.VAR'
2252 ! include 'COMMON.MD'
2253 ! include 'COMMON.CHAIN'
2254 ! include 'COMMON.DERIV'
2255 ! include 'COMMON.GEO'
2256 ! include 'COMMON.LOCAL'
2257 ! include 'COMMON.INTERACT'
2258 ! include 'COMMON.IOUNITS'
2259 ! include 'COMMON.NAMES'
2260 real(kind=8) :: T_half,fact
2261 integer :: i,j,inres,mnum
2263 T_half=2.0d0/(dimen3*Rb)*EK
2264 fact=dsqrt(1.0d0+(d_time/tau_bath)*(t_bath/T_half-1.0d0))
2265 ! write(iout,*) "T_half", T_half
2266 ! write(iout,*) "EK", EK
2267 ! write(iout,*) "fact", fact
2269 d_t(j,0)=fact*d_t(j,0)
2273 d_t(j,i)=fact*d_t(j,i)
2278 ! iti=iabs(itype(i,mnum))
2279 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2280 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2281 .and.(mnum.ne.5)) then
2284 d_t(j,inres)=fact*d_t(j,inres)
2289 end subroutine verlet_bath
2290 !-----------------------------------------------------------------------------
2292 ! Set up the initial conditions of a MD simulation
2295 use control, only:tcpu
2296 !el use io_basic, only:ilen
2299 use minimm, only:minim_dc,minimize,sc_move
2300 use io_config, only:readrst
2301 use io, only:statout
2302 ! implicit real*8 (a-h,o-z)
2303 ! include 'DIMENSIONS'
2306 character(len=16) :: form
2307 integer :: IERROR,ERRCODE
2309 ! include 'COMMON.SETUP'
2310 ! include 'COMMON.CONTROL'
2311 ! include 'COMMON.VAR'
2312 ! include 'COMMON.MD'
2314 ! include 'COMMON.LANGEVIN'
2316 ! include 'COMMON.LANGEVIN.lang0'
2318 ! include 'COMMON.CHAIN'
2319 ! include 'COMMON.DERIV'
2320 ! include 'COMMON.GEO'
2321 ! include 'COMMON.LOCAL'
2322 ! include 'COMMON.INTERACT'
2323 ! include 'COMMON.IOUNITS'
2324 ! include 'COMMON.NAMES'
2325 ! include 'COMMON.REMD'
2326 real(kind=8),dimension(0:n_ene) :: energia_long,energia_short
2327 real(kind=8),dimension(3) :: vcm,incr,L
2328 real(kind=8) :: xv,sigv,lowb,highb
2329 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
2330 character(len=256) :: qstr
2333 character(len=50) :: tytul
2334 logical :: file_exist
2335 !el common /gucio/ cm
2336 integer :: i,j,ipos,iq,iw,nft_sc,iretcode,nfun,itime,ierr,mnum
2337 real(kind=8) :: etot,tt0
2341 ! write(iout,*) "d_time", d_time
2342 ! Compute the standard deviations of stochastic forces for Langevin dynamics
2343 ! if the friction coefficients do not depend on surface area
2344 if (lang.gt.0 .and. .not.surfarea) then
2347 stdforcp(i)=stdfp(mnum)*dsqrt(gamp(mnum))
2351 stdforcsc(i)=stdfsc(iabs(itype(i,mnum)),mnum) &
2352 *dsqrt(gamsc(iabs(itype(i,mnum)),mnum))
2355 ! Open the pdb file for snapshotshots
2358 if (ilen(tmpdir).gt.0) &
2359 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2360 liczba(:ilen(liczba))//".pdb")
2362 file=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2366 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2367 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2368 liczba(:ilen(liczba))//".x")
2369 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2372 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2373 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2374 liczba(:ilen(liczba))//".cx")
2375 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2381 if (ilen(tmpdir).gt.0) &
2382 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.pdb")
2383 open(ipdb,file=prefix(:ilen(prefix))//"_MD.pdb")
2385 if (ilen(tmpdir).gt.0) &
2386 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.cx")
2387 cartname=prefix(:ilen(prefix))//"_MD.cx"
2391 write (qstr,'(256(1h ))')
2394 iq = qinfrag(i,iset)*10
2395 iw = wfrag(i,iset)/100
2397 if(me.eq.king.or..not.out1file) &
2398 write (iout,*) "Frag",qinfrag(i,iset),wfrag(i,iset),iq,iw
2399 write (qstr(ipos:ipos+6),'(2h_f,i1,1h_,i1,1h_,i1)') i,iq,iw
2404 iq = qinpair(i,iset)*10
2405 iw = wpair(i,iset)/100
2407 if(me.eq.king.or..not.out1file) &
2408 write (iout,*) "Pair",i,qinpair(i,iset),wpair(i,iset),iq,iw
2409 write (qstr(ipos:ipos+6),'(2h_p,i1,1h_,i1,1h_,i1)') i,iq,iw
2413 ! pdbname=pdbname(:ilen(pdbname)-4)//qstr(:ipos-1)//'.pdb'
2415 ! cartname=cartname(:ilen(cartname)-2)//qstr(:ipos-1)//'.x'
2417 ! cartname=cartname(:ilen(cartname)-3)//qstr(:ipos-1)//'.cx'
2419 ! statname=statname(:ilen(statname)-5)//qstr(:ipos-1)//'.stat'
2423 if (restart1file) then
2425 inquire(file=mremd_rst_name,exist=file_exist)
2426 write (*,*) me," Before broadcast: file_exist",file_exist
2428 call MPI_Bcast(file_exist,1,MPI_LOGICAL,king,CG_COMM,&
2431 write (*,*) me," After broadcast: file_exist",file_exist
2432 ! inquire(file=mremd_rst_name,exist=file_exist)
2433 if(me.eq.king.or..not.out1file) &
2434 write(iout,*) "Initial state read by master and distributed"
2436 if (ilen(tmpdir).gt.0) &
2437 call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_' &
2438 //liczba(:ilen(liczba))//'.rst')
2439 inquire(file=rest2name,exist=file_exist)
2442 if(.not.restart1file) then
2443 if(me.eq.king.or..not.out1file) &
2444 write(iout,*) "Initial state will be read from file ",&
2445 rest2name(:ilen(rest2name))
2448 call rescale_weights(t_bath)
2450 if(me.eq.king.or..not.out1file)then
2451 if (restart1file) then
2452 write(iout,*) "File ",mremd_rst_name(:ilen(mremd_rst_name)),&
2455 write(iout,*) "File ",rest2name(:ilen(rest2name)),&
2458 write(iout,*) "Initial velocities randomly generated"
2465 ! Generate initial velocities
2466 if(me.eq.king.or..not.out1file) &
2467 write(iout,*) "Initial velocities randomly generated"
2472 ! rest2name = prefix(:ilen(prefix))//'.rst'
2473 if(me.eq.king.or..not.out1file)then
2474 write (iout,*) "Initial velocities"
2476 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2477 (d_t(j,i+nres),j=1,3)
2479 ! Zeroing the total angular momentum of the system
2480 write(iout,*) "Calling the zero-angular momentum subroutine"
2483 ! Getting the potential energy and forces and velocities and accelerations
2485 ! write (iout,*) "velocity of the center of the mass:"
2486 ! write (iout,*) (vcm(j),j=1,3)
2488 d_t(j,0)=d_t(j,0)-vcm(j)
2490 ! Removing the velocity of the center of mass
2492 if(me.eq.king.or..not.out1file)then
2493 write (iout,*) "vcm right after adjustment:"
2494 write (iout,*) (vcm(j),j=1,3)
2496 if ((.not.rest).and.(indpdb.eq.0)) then
2498 if(iranconf.ne.0) then
2500 print *, 'Calling OVERLAP_SC'
2501 call overlap_sc(fail)
2504 call sc_move(2,nres-1,10,1d10,nft_sc,etot)
2505 print *,'SC_move',nft_sc,etot
2506 if(me.eq.king.or..not.out1file) &
2507 write(iout,*) 'SC_move',nft_sc,etot
2511 print *, 'Calling MINIM_DC'
2512 call minim_dc(etot,iretcode,nfun)
2514 call geom_to_var(nvar,varia)
2515 print *,'Calling MINIMIZE.'
2516 call minimize(etot,varia,iretcode,nfun)
2517 call var_to_geom(nvar,varia)
2519 if(me.eq.king.or..not.out1file) &
2520 write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
2523 call chainbuild_cart
2528 kinetic_T=2.0d0/(dimen3*Rb)*EK
2529 if(me.eq.king.or..not.out1file)then
2539 call etotal(potEcomp)
2540 if (large) call enerprint(potEcomp)
2543 t_etotal=t_etotal+MPI_Wtime()-tt0
2545 t_etotal=t_etotal+tcpu()-tt0
2552 if (amax*d_time .gt. dvmax) then
2553 d_time=d_time*dvmax/amax
2554 if(me.eq.king.or..not.out1file) write (iout,*) &
2555 "Time step reduced to",d_time,&
2556 " because of too large initial acceleration."
2558 if(me.eq.king.or..not.out1file)then
2559 write(iout,*) "Potential energy and its components"
2560 call enerprint(potEcomp)
2561 ! write(iout,*) (potEcomp(i),i=0,n_ene)
2563 potE=potEcomp(0)-potEcomp(20)
2566 if (ntwe.ne.0) call statout(itime)
2567 if(me.eq.king.or..not.out1file) &
2568 write (iout,'(/a/3(a25,1pe14.5/))') "Initial:", &
2569 " Kinetic energy",EK," Potential energy",potE, &
2570 " Total energy",totE," Maximum acceleration ", &
2573 write (iout,*) "Initial coordinates"
2575 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(c(j,i),j=1,3),&
2578 write (iout,*) "Initial dC"
2580 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
2581 (dc(j,i+nres),j=1,3)
2583 write (iout,*) "Initial velocities"
2584 write (iout,"(13x,' backbone ',23x,' side chain')")
2586 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2587 (d_t(j,i+nres),j=1,3)
2589 write (iout,*) "Initial accelerations"
2591 ! write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
2592 write (iout,'(i3,3f15.10,3x,3f15.10)') i,(d_a(j,i),j=1,3),&
2593 (d_a(j,i+nres),j=1,3)
2599 d_t_old(j,i)=d_t(j,i)
2600 d_a_old(j,i)=d_a(j,i)
2602 ! write (iout,*) "dc_old",i,(dc_old(j,i),j=1,3)
2611 call etotal_short(energia_short)
2612 if (large) call enerprint(potEcomp)
2615 t_eshort=t_eshort+MPI_Wtime()-tt0
2617 t_eshort=t_eshort+tcpu()-tt0
2622 if(.not.out1file .and. large) then
2623 write (iout,*) "energia_long",energia_long(0),&
2624 " energia_short",energia_short(0),&
2625 " total",energia_long(0)+energia_short(0)
2626 write (iout,*) "Initial fast-force accelerations"
2628 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2629 (d_a(j,i+nres),j=1,3)
2632 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
2635 d_a_short(j,i)=d_a(j,i)
2644 call etotal_long(energia_long)
2645 if (large) call enerprint(potEcomp)
2648 t_elong=t_elong+MPI_Wtime()-tt0
2650 t_elong=t_elong+tcpu()-tt0
2655 if(.not.out1file .and. large) then
2656 write (iout,*) "energia_long",energia_long(0)
2657 write (iout,*) "Initial slow-force accelerations"
2659 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2660 (d_a(j,i+nres),j=1,3)
2664 t_enegrad=t_enegrad+MPI_Wtime()-tt0
2666 t_enegrad=t_enegrad+tcpu()-tt0
2670 end subroutine init_MD
2671 !-----------------------------------------------------------------------------
2672 subroutine random_vel
2674 ! implicit real*8 (a-h,o-z)
2676 use random, only:anorm_distr
2678 ! include 'DIMENSIONS'
2679 ! include 'COMMON.CONTROL'
2680 ! include 'COMMON.VAR'
2681 ! include 'COMMON.MD'
2683 ! include 'COMMON.LANGEVIN'
2685 ! include 'COMMON.LANGEVIN.lang0'
2687 ! include 'COMMON.CHAIN'
2688 ! include 'COMMON.DERIV'
2689 ! include 'COMMON.GEO'
2690 ! include 'COMMON.LOCAL'
2691 ! include 'COMMON.INTERACT'
2692 ! include 'COMMON.IOUNITS'
2693 ! include 'COMMON.NAMES'
2694 ! include 'COMMON.TIME1'
2695 real(kind=8) :: xv,sigv,lowb,highb ,Ek1
2697 real(kind=8) ,allocatable, dimension(:) :: DDU1,DDU2,DL2,DL1,xsolv,DML,rs
2698 real(kind=8) :: sumx
2700 real(kind=8) ,allocatable, dimension(:) :: rsold
2701 real (kind=8),allocatable,dimension(:,:) :: matold
2704 integer :: i,j,ii,k,ind,mark,imark,mnum
2705 ! Generate random velocities from Gaussian distribution of mean 0 and std of KT/m
2706 ! First generate velocities in the eigenspace of the G matrix
2707 ! write (iout,*) "Calling random_vel dimen dimen3",dimen,dimen3
2714 sigv=dsqrt((Rb*t_bath)/geigen(i))
2717 d_t_work_new(ii)=anorm_distr(xv,sigv,lowb,highb)
2719 write (iout,*) "i",i," ii",ii," geigen",geigen(i),&
2720 " d_t_work_new",d_t_work_new(ii)
2731 Ek1=Ek1+0.5d0*geigen(i)*d_t_work_new(ii)**2
2734 write (iout,*) "Ek from eigenvectors",Ek1
2735 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2739 ! Transform velocities to UNRES coordinate space
2740 allocate (DL1(2*nres))
2741 allocate (DDU1(2*nres))
2742 allocate (DL2(2*nres))
2743 allocate (DDU2(2*nres))
2744 allocate (xsolv(2*nres))
2745 allocate (DML(2*nres))
2746 allocate (rs(2*nres))
2748 allocate (rsold(2*nres))
2749 allocate (matold(2*nres,2*nres))
2751 matold(1,1)=DMorig(1)
2752 matold(1,2)=DU1orig(1)
2753 matold(1,3)=DU2orig(1)
2754 write (*,*) DMorig(1),DU1orig(1),DU2orig(1)
2759 matold(i,j)=DMorig(i)
2760 matold(i,j-1)=DU1orig(i-1)
2762 matold(i,j-2)=DU2orig(i-2)
2770 matold(i,j+1)=DU1orig(i)
2776 matold(i,j+2)=DU2orig(i)
2780 matold(dimen,dimen)=DMorig(dimen)
2781 matold(dimen,dimen-1)=DU1orig(dimen-1)
2782 matold(dimen,dimen-2)=DU2orig(dimen-2)
2783 write(iout,*) "old gmatrix"
2784 call matout(dimen,dimen,2*nres,2*nres,matold)
2788 ! Find the ith eigenvector of the pentadiagonal inertiq matrix
2792 DML(j)=DMorig(j)-geigen(i)
2795 DML(j-1)=DMorig(j)-geigen(i)
2800 DDU1(imark-1)=DU2orig(imark-1)
2801 do j=imark+1,dimen-1
2802 DDU1(j-1)=DU1orig(j)
2810 DDU2(j)=DU2orig(j+1)
2819 write (iout,*) "DL2,DL1,DML,DDU1,DDU2"
2820 write(iout,'(10f10.5)') (DL2(k),k=3,dimen-1)
2821 write(iout,'(10f10.5)') (DL1(k),k=2,dimen-1)
2822 write(iout,'(10f10.5)') (DML(k),k=1,dimen-1)
2823 write(iout,'(10f10.5)') (DDU1(k),k=1,dimen-2)
2824 write(iout,'(10f10.5)') (DDU2(k),k=1,dimen-3)
2827 if (imark.gt.2) rs(imark-2)=-DU2orig(imark-2)
2828 if (imark.gt.1) rs(imark-1)=-DU1orig(imark-1)
2829 if (imark.lt.dimen) rs(imark)=-DU1orig(imark)
2830 if (imark.lt.dimen-1) rs(imark+1)=-DU2orig(imark)
2834 ! write (iout,*) "Vector rs"
2836 ! write (iout,*) j,rs(j)
2839 call FDIAG(dimen-1,DL2,DL1,DML,DDU1,DDU2,rs,xsolv,mark)
2846 sumx=-geigen(i)*xsolv(j)
2848 sumx=sumx+matold(j,k)*xsolv(k)
2851 sumx=sumx+matold(j,k)*xsolv(k-1)
2853 write(iout,'(i5,3f10.5)') j,sumx,rsold(j),sumx-rsold(j)
2856 sumx=-geigen(i)*xsolv(j-1)
2858 sumx=sumx+matold(j,k)*xsolv(k)
2861 sumx=sumx+matold(j,k)*xsolv(k-1)
2863 write(iout,'(i5,3f10.5)') j-1,sumx,rsold(j-1),sumx-rsold(j-1)
2867 "Solution of equations system",i," for eigenvalue",geigen(i)
2869 write(iout,'(i5,f10.5)') j,xsolv(j)
2872 do j=dimen-1,imark,-1
2877 write (iout,*) "Un-normalized eigenvector",i," for eigenvalue",geigen(i)
2879 write(iout,'(i5,f10.5)') j,xsolv(j)
2882 ! Normalize ith eigenvector
2885 sumx=sumx+xsolv(j)**2
2889 xsolv(j)=xsolv(j)/sumx
2892 write (iout,*) "Eigenvector",i," for eigenvalue",geigen(i)
2894 write(iout,'(i5,3f10.5)') j,xsolv(j)
2897 ! All done at this point for eigenvector i, exit loop
2905 write (iout,*) "Unable to find eigenvector",i
2908 ! write (iout,*) "i=",i
2910 ! write (iout,*) "k=",k
2913 ! write(iout,*) "ind",ind," ind1",3*(i-1)+k
2914 d_t_work(ind)=d_t_work(ind) &
2915 +xsolv(j)*d_t_work_new(3*(i-1)+k)
2918 enddo ! i (loop over the eigenvectors)
2921 write (iout,*) "d_t_work"
2923 write (iout,"(i5,f10.5)") i,d_t_work(i)
2928 ! if (itype(i,1).eq.10) then
2930 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
2931 iti=iabs(itype(i,mnum))
2932 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2933 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
2934 .or.(mnum.eq.5)) then
2941 ! write (iout,*) "k",k," ii+k",ii+k," ii+j+k",ii+j+k,"EK1",Ek1
2942 Ek1=Ek1+0.5d0*mp(mnum)*((d_t_work(ii+j+k)+d_t_work_new(ii+k))/2)**2+&
2943 0.5d0*0.25d0*IP(mnum)*(d_t_work(ii+j+k)-d_t_work_new(ii+k))**2
2946 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2947 .and.(mnum.ne.5)) ii=ii+3
2948 write (iout,*) "i",i," itype",itype(i,mnum)," mass",msc(itype(i,mnum),mnum)
2949 write (iout,*) "ii",ii
2952 write (iout,*) "k",k," ii",ii,"EK1",EK1
2953 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2955 Ek1=Ek1+0.5d0*Isc(iabs(itype(i,mnum),mnum))*(d_t_work(ii)-d_t_work(ii-3))**2
2956 Ek1=Ek1+0.5d0*msc(iabs(itype(i,mnum)),mnum)*d_t_work(ii)**2
2958 write (iout,*) "i",i," ii",ii
2960 write (iout,*) "Ek from d_t_work",Ek1
2961 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2977 d_t(k,j)=d_t_work(ind)
2981 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2984 d_t(k,j+nres)=d_t_work(ind)
2990 write (iout,*) "Random velocities in the Calpha,SC space"
2992 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
2995 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
3002 ! if (itype(i,1).eq.10) then
3004 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
3007 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
3011 d_t(j,i+nres)=d_t(j,i+nres)-d_t(j,i)
3012 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
3017 write (iout,*)"Random velocities in the virtual-bond-vector space"
3019 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
3022 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
3025 write (iout,*) "Ek from d_t_work",Ek1
3026 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
3034 d_t_work(ind)=d_t_work(ind) &
3035 +Gvec(i,j)*d_t_work_new((j-1)*3+k+1)
3037 ! write (iout,*) "i",i," ind",ind," d_t_work",d_t_work(ind)
3041 ! Transfer to the d_t vector
3043 d_t(j,0)=d_t_work(j)
3049 d_t(j,i)=d_t_work(ind)
3054 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3055 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3056 .and.(mnum.ne.5)) then
3059 d_t(j,i+nres)=d_t_work(ind)
3065 ! write (iout,*) "Kinetic energy",Ek,EK1," kinetic temperature",&
3066 ! 2.0d0/(dimen3*Rb)*EK,2.0d0/(dimen3*Rb)*EK1
3070 end subroutine random_vel
3071 !-----------------------------------------------------------------------------
3073 subroutine sd_verlet_p_setup
3074 ! Sets up the parameters of stochastic Verlet algorithm
3075 ! implicit real*8 (a-h,o-z)
3076 ! include 'DIMENSIONS'
3077 use control, only: tcpu
3082 ! include 'COMMON.CONTROL'
3083 ! include 'COMMON.VAR'
3084 ! include 'COMMON.MD'
3086 ! include 'COMMON.LANGEVIN'
3088 ! include 'COMMON.LANGEVIN.lang0'
3090 ! include 'COMMON.CHAIN'
3091 ! include 'COMMON.DERIV'
3092 ! include 'COMMON.GEO'
3093 ! include 'COMMON.LOCAL'
3094 ! include 'COMMON.INTERACT'
3095 ! include 'COMMON.IOUNITS'
3096 ! include 'COMMON.NAMES'
3097 ! include 'COMMON.TIME1'
3098 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3099 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3100 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3101 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3102 logical :: lprn = .false.
3103 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3104 real(kind=8) :: ktm,gdt,egdt,gdt2,gdt3,gdt4,gdt5,gdt6,gdt7,gdt8,&
3106 integer :: i,maxres2
3113 ! AL 8/17/04 Code adapted from tinker
3115 ! Get the frictional and random terms for stochastic dynamics in the
3116 ! eigenspace of mass-scaled UNRES friction matrix
3120 gdt = fricgam(i) * d_time
3122 ! Stochastic dynamics reduces to simple MD for zero friction
3124 if (gdt .le. zero) then
3125 pfric_vec(i) = 1.0d0
3126 vfric_vec(i) = d_time
3127 afric_vec(i) = 0.5d0 * d_time * d_time
3128 prand_vec(i) = 0.0d0
3129 vrand_vec1(i) = 0.0d0
3130 vrand_vec2(i) = 0.0d0
3132 ! Analytical expressions when friction coefficient is large
3135 if (gdt .ge. gdt_radius) then
3138 vfric_vec(i) = (1.0d0-egdt) / fricgam(i)
3139 afric_vec(i) = (d_time-vfric_vec(i)) / fricgam(i)
3140 pterm = 2.0d0*gdt - 3.0d0 + (4.0d0-egdt)*egdt
3141 vterm = 1.0d0 - egdt**2
3142 rho = (1.0d0-egdt)**2 / sqrt(pterm*vterm)
3144 ! Use series expansions when friction coefficient is small
3155 afric_vec(i) = (gdt2/2.0d0 - gdt3/6.0d0 + gdt4/24.0d0 &
3156 - gdt5/120.0d0 + gdt6/720.0d0 &
3157 - gdt7/5040.0d0 + gdt8/40320.0d0 &
3158 - gdt9/362880.0d0) / fricgam(i)**2
3159 vfric_vec(i) = d_time - fricgam(i)*afric_vec(i)
3160 pfric_vec(i) = 1.0d0 - fricgam(i)*vfric_vec(i)
3161 pterm = 2.0d0*gdt3/3.0d0 - gdt4/2.0d0 &
3162 + 7.0d0*gdt5/30.0d0 - gdt6/12.0d0 &
3163 + 31.0d0*gdt7/1260.0d0 - gdt8/160.0d0 &
3164 + 127.0d0*gdt9/90720.0d0
3165 vterm = 2.0d0*gdt - 2.0d0*gdt2 + 4.0d0*gdt3/3.0d0 &
3166 - 2.0d0*gdt4/3.0d0 + 4.0d0*gdt5/15.0d0 &
3167 - 4.0d0*gdt6/45.0d0 + 8.0d0*gdt7/315.0d0 &
3168 - 2.0d0*gdt8/315.0d0 + 4.0d0*gdt9/2835.0d0
3169 rho = sqrt(3.0d0) * (0.5d0 - 3.0d0*gdt/16.0d0 &
3170 - 17.0d0*gdt2/1280.0d0 &
3171 + 17.0d0*gdt3/6144.0d0 &
3172 + 40967.0d0*gdt4/34406400.0d0 &
3173 - 57203.0d0*gdt5/275251200.0d0 &
3174 - 1429487.0d0*gdt6/13212057600.0d0)
3177 ! Compute the scaling factors of random terms for the nonzero friction case
3179 ktm = 0.5d0*d_time/fricgam(i)
3180 psig = dsqrt(ktm*pterm) / fricgam(i)
3181 vsig = dsqrt(ktm*vterm)
3182 rhoc = dsqrt(1.0d0 - rho*rho)
3184 vrand_vec1(i) = vsig * rho
3185 vrand_vec2(i) = vsig * rhoc
3190 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3193 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3194 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3198 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3201 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3202 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3203 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3204 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3205 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec1,vrand_mat1)
3206 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3209 t_sdsetup=t_sdsetup+MPI_Wtime()
3211 t_sdsetup=t_sdsetup+tcpu()-tt0
3214 end subroutine sd_verlet_p_setup
3215 !-----------------------------------------------------------------------------
3216 subroutine eigtransf1(n,ndim,ab,d,c)
3220 real(kind=8) :: ab(ndim,ndim,n),c(ndim,n),d(ndim)
3226 c(i,j)=c(i,j)+ab(k,j,i)*d(k)
3231 end subroutine eigtransf1
3232 !-----------------------------------------------------------------------------
3233 subroutine eigtransf(n,ndim,a,b,d,c)
3237 real(kind=8) :: a(ndim,n),b(ndim,n),c(ndim,n),d(ndim)
3243 c(i,j)=c(i,j)+a(i,k)*b(k,j)*d(k)
3248 end subroutine eigtransf
3249 !-----------------------------------------------------------------------------
3250 subroutine sd_verlet1
3252 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3254 ! implicit real*8 (a-h,o-z)
3255 ! include 'DIMENSIONS'
3256 ! include 'COMMON.CONTROL'
3257 ! include 'COMMON.VAR'
3258 ! include 'COMMON.MD'
3260 ! include 'COMMON.LANGEVIN'
3262 ! include 'COMMON.LANGEVIN.lang0'
3264 ! include 'COMMON.CHAIN'
3265 ! include 'COMMON.DERIV'
3266 ! include 'COMMON.GEO'
3267 ! include 'COMMON.LOCAL'
3268 ! include 'COMMON.INTERACT'
3269 ! include 'COMMON.IOUNITS'
3270 ! include 'COMMON.NAMES'
3271 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3272 !el common /stochcalc/ stochforcvec
3273 logical :: lprn = .false.
3274 real(kind=8) :: ddt1,ddt2
3275 integer :: i,j,ind,inres
3277 ! write (iout,*) "dc_old"
3279 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3280 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3283 dc_work(j)=dc_old(j,0)
3284 d_t_work(j)=d_t_old(j,0)
3285 d_a_work(j)=d_a_old(j,0)
3290 dc_work(ind+j)=dc_old(j,i)
3291 d_t_work(ind+j)=d_t_old(j,i)
3292 d_a_work(ind+j)=d_a_old(j,i)
3298 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3299 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3300 .and.(mnum.ne.5)) then
3302 dc_work(ind+j)=dc_old(j,i+nres)
3303 d_t_work(ind+j)=d_t_old(j,i+nres)
3304 d_a_work(ind+j)=d_a_old(j,i+nres)
3312 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3316 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3317 vfric_mat(i,j),afric_mat(i,j),&
3318 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3326 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3327 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3328 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3329 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3331 d_t_work_new(i)=ddt1+0.5d0*ddt2
3332 d_t_work(i)=ddt1+ddt2
3337 d_t(j,0)=d_t_work(j)
3342 dc(j,i)=dc_work(ind+j)
3343 d_t(j,i)=d_t_work(ind+j)
3349 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3350 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3351 .and.(mnum.ne.5)) then
3354 dc(j,inres)=dc_work(ind+j)
3355 d_t(j,inres)=d_t_work(ind+j)
3361 end subroutine sd_verlet1
3362 !-----------------------------------------------------------------------------
3363 subroutine sd_verlet2
3365 ! Calculating the adjusted velocities for accelerations
3367 ! implicit real*8 (a-h,o-z)
3368 ! include 'DIMENSIONS'
3369 ! include 'COMMON.CONTROL'
3370 ! include 'COMMON.VAR'
3371 ! include 'COMMON.MD'
3373 ! include 'COMMON.LANGEVIN'
3375 ! include 'COMMON.LANGEVIN.lang0'
3377 ! include 'COMMON.CHAIN'
3378 ! include 'COMMON.DERIV'
3379 ! include 'COMMON.GEO'
3380 ! include 'COMMON.LOCAL'
3381 ! include 'COMMON.INTERACT'
3382 ! include 'COMMON.IOUNITS'
3383 ! include 'COMMON.NAMES'
3384 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3385 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3386 !el common /stochcalc/ stochforcvec
3388 real(kind=8) :: ddt1,ddt2
3389 integer :: i,j,ind,inres
3390 ! Compute the stochastic forces which contribute to velocity change
3392 call stochastic_force(stochforcvecV)
3399 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3400 ddt2=ddt2+vrand_mat1(i,j)*stochforcvec(j)+ &
3401 vrand_mat2(i,j)*stochforcvecV(j)
3403 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3407 d_t(j,0)=d_t_work(j)
3412 d_t(j,i)=d_t_work(ind+j)
3418 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3419 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3420 .and.(mnum.ne.5)) then
3423 d_t(j,inres)=d_t_work(ind+j)
3429 end subroutine sd_verlet2
3430 !-----------------------------------------------------------------------------
3431 subroutine sd_verlet_ciccotti_setup
3433 ! Sets up the parameters of stochastic velocity Verlet algorithmi; Ciccotti's
3435 ! implicit real*8 (a-h,o-z)
3436 ! include 'DIMENSIONS'
3437 use control, only: tcpu
3442 ! include 'COMMON.CONTROL'
3443 ! include 'COMMON.VAR'
3444 ! include 'COMMON.MD'
3446 ! include 'COMMON.LANGEVIN'
3448 ! include 'COMMON.LANGEVIN.lang0'
3450 ! include 'COMMON.CHAIN'
3451 ! include 'COMMON.DERIV'
3452 ! include 'COMMON.GEO'
3453 ! include 'COMMON.LOCAL'
3454 ! include 'COMMON.INTERACT'
3455 ! include 'COMMON.IOUNITS'
3456 ! include 'COMMON.NAMES'
3457 ! include 'COMMON.TIME1'
3458 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3459 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3460 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3461 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3462 logical :: lprn = .false.
3463 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3464 real(kind=8) :: ktm,gdt,egdt,tt0
3465 integer :: i,maxres2
3472 ! AL 8/17/04 Code adapted from tinker
3474 ! Get the frictional and random terms for stochastic dynamics in the
3475 ! eigenspace of mass-scaled UNRES friction matrix
3479 write (iout,*) "i",i," fricgam",fricgam(i)
3480 gdt = fricgam(i) * d_time
3482 ! Stochastic dynamics reduces to simple MD for zero friction
3484 if (gdt .le. zero) then
3485 pfric_vec(i) = 1.0d0
3486 vfric_vec(i) = d_time
3487 afric_vec(i) = 0.5d0*d_time*d_time
3488 prand_vec(i) = afric_vec(i)
3489 vrand_vec2(i) = vfric_vec(i)
3491 ! Analytical expressions when friction coefficient is large
3496 vfric_vec(i) = dexp(-0.5d0*gdt)*d_time
3497 afric_vec(i) = 0.5d0*dexp(-0.25d0*gdt)*d_time*d_time
3498 prand_vec(i) = afric_vec(i)
3499 vrand_vec2(i) = vfric_vec(i)
3501 ! Compute the scaling factors of random terms for the nonzero friction case
3503 ! ktm = 0.5d0*d_time/fricgam(i)
3504 ! psig = dsqrt(ktm*pterm) / fricgam(i)
3505 ! vsig = dsqrt(ktm*vterm)
3506 ! prand_vec(i) = psig*afric_vec(i)
3507 ! vrand_vec2(i) = vsig*vfric_vec(i)
3512 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3515 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3516 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3520 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3522 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3523 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3524 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3525 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3526 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3528 t_sdsetup=t_sdsetup+MPI_Wtime()
3530 t_sdsetup=t_sdsetup+tcpu()-tt0
3533 end subroutine sd_verlet_ciccotti_setup
3534 !-----------------------------------------------------------------------------
3535 subroutine sd_verlet1_ciccotti
3537 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3538 ! implicit real*8 (a-h,o-z)
3540 ! include 'DIMENSIONS'
3544 ! include 'COMMON.CONTROL'
3545 ! include 'COMMON.VAR'
3546 ! include 'COMMON.MD'
3548 ! include 'COMMON.LANGEVIN'
3550 ! include 'COMMON.LANGEVIN.lang0'
3552 ! include 'COMMON.CHAIN'
3553 ! include 'COMMON.DERIV'
3554 ! include 'COMMON.GEO'
3555 ! include 'COMMON.LOCAL'
3556 ! include 'COMMON.INTERACT'
3557 ! include 'COMMON.IOUNITS'
3558 ! include 'COMMON.NAMES'
3559 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3560 !el common /stochcalc/ stochforcvec
3561 logical :: lprn = .false.
3562 real(kind=8) :: ddt1,ddt2
3563 integer :: i,j,ind,inres
3564 ! write (iout,*) "dc_old"
3566 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3567 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3570 dc_work(j)=dc_old(j,0)
3571 d_t_work(j)=d_t_old(j,0)
3572 d_a_work(j)=d_a_old(j,0)
3577 dc_work(ind+j)=dc_old(j,i)
3578 d_t_work(ind+j)=d_t_old(j,i)
3579 d_a_work(ind+j)=d_a_old(j,i)
3584 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3586 dc_work(ind+j)=dc_old(j,i+nres)
3587 d_t_work(ind+j)=d_t_old(j,i+nres)
3588 d_a_work(ind+j)=d_a_old(j,i+nres)
3597 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3601 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3602 vfric_mat(i,j),afric_mat(i,j),&
3603 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3611 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3612 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3613 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3614 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3616 d_t_work_new(i)=ddt1+0.5d0*ddt2
3617 d_t_work(i)=ddt1+ddt2
3622 d_t(j,0)=d_t_work(j)
3627 dc(j,i)=dc_work(ind+j)
3628 d_t(j,i)=d_t_work(ind+j)
3634 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3635 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3636 .and.(mnum.ne.5)) then
3639 dc(j,inres)=dc_work(ind+j)
3640 d_t(j,inres)=d_t_work(ind+j)
3646 end subroutine sd_verlet1_ciccotti
3647 !-----------------------------------------------------------------------------
3648 subroutine sd_verlet2_ciccotti
3650 ! Calculating the adjusted velocities for accelerations
3652 ! implicit real*8 (a-h,o-z)
3653 ! include 'DIMENSIONS'
3654 ! include 'COMMON.CONTROL'
3655 ! include 'COMMON.VAR'
3656 ! include 'COMMON.MD'
3658 ! include 'COMMON.LANGEVIN'
3660 ! include 'COMMON.LANGEVIN.lang0'
3662 ! include 'COMMON.CHAIN'
3663 ! include 'COMMON.DERIV'
3664 ! include 'COMMON.GEO'
3665 ! include 'COMMON.LOCAL'
3666 ! include 'COMMON.INTERACT'
3667 ! include 'COMMON.IOUNITS'
3668 ! include 'COMMON.NAMES'
3669 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3670 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3671 !el common /stochcalc/ stochforcvec
3672 real(kind=8) :: ddt1,ddt2
3673 integer :: i,j,ind,inres
3675 ! Compute the stochastic forces which contribute to velocity change
3677 call stochastic_force(stochforcvecV)
3684 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3685 ! ddt2=ddt2+vrand_mat2(i,j)*stochforcvecV(j)
3686 ddt2=ddt2+vrand_mat2(i,j)*stochforcvec(j)
3688 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3692 d_t(j,0)=d_t_work(j)
3697 d_t(j,i)=d_t_work(ind+j)
3703 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3705 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3708 d_t(j,inres)=d_t_work(ind+j)
3714 end subroutine sd_verlet2_ciccotti
3716 !-----------------------------------------------------------------------------
3718 !-----------------------------------------------------------------------------
3719 subroutine inertia_tensor
3721 ! Calculating the intertia tensor for the entire protein in order to
3722 ! remove the perpendicular components of velocity matrix which cause
3723 ! the molecule to rotate.
3726 ! implicit real*8 (a-h,o-z)
3727 ! include 'DIMENSIONS'
3728 ! include 'COMMON.CONTROL'
3729 ! include 'COMMON.VAR'
3730 ! include 'COMMON.MD'
3731 ! include 'COMMON.CHAIN'
3732 ! include 'COMMON.DERIV'
3733 ! include 'COMMON.GEO'
3734 ! include 'COMMON.LOCAL'
3735 ! include 'COMMON.INTERACT'
3736 ! include 'COMMON.IOUNITS'
3737 ! include 'COMMON.NAMES'
3739 real(kind=8),dimension(3,3) :: Im,Imcp,eigvec,Id
3740 real(kind=8),dimension(3) :: pr,eigval,L,vp,vrot
3741 real(kind=8) :: M_SC,mag,mag2,M_PEP
3742 real(kind=8),dimension(3,0:nres) :: vpp !(3,0:MAXRES)
3743 real(kind=8),dimension(3) :: vs_p,pp,incr,v
3744 real(kind=8),dimension(3,3) :: pr1,pr2
3746 !el common /gucio/ cm
3747 integer :: iti,inres,i,j,k,mnum
3758 ! calculating the center of the mass of the protein
3762 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3763 if (itype(i,mnum).eq.ntyp1_molec(mnum)) cycle
3764 M_PEP=M_PEP+mp(mnum)
3766 cm(j)=cm(j)+(c(j,i)+0.5d0*dc(j,i))*mp(mnum)
3775 if (mnum.eq.5) cycle
3776 iti=iabs(itype(i,mnum))
3777 M_SC=M_SC+msc(iabs(iti),mnum)
3780 cm(j)=cm(j)+msc(iabs(iti),mnum)*c(j,inres)
3784 cm(j)=cm(j)/(M_SC+M_PEP)
3789 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3791 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3793 Im(1,1)=Im(1,1)+mp(mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
3794 Im(1,2)=Im(1,2)-mp(mnum)*pr(1)*pr(2)
3795 Im(1,3)=Im(1,3)-mp(mnum)*pr(1)*pr(3)
3796 Im(2,3)=Im(2,3)-mp(mnum)*pr(2)*pr(3)
3797 Im(2,2)=Im(2,2)+mp(mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
3798 Im(3,3)=Im(3,3)+mp(mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
3803 iti=iabs(itype(i,mnum))
3804 if (mnum.eq.5) cycle
3807 pr(j)=c(j,inres)-cm(j)
3809 Im(1,1)=Im(1,1)+msc(iabs(iti),mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
3810 Im(1,2)=Im(1,2)-msc(iabs(iti),mnum)*pr(1)*pr(2)
3811 Im(1,3)=Im(1,3)-msc(iabs(iti),mnum)*pr(1)*pr(3)
3812 Im(2,3)=Im(2,3)-msc(iabs(iti),mnum)*pr(2)*pr(3)
3813 Im(2,2)=Im(2,2)+msc(iabs(iti),mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
3814 Im(3,3)=Im(3,3)+msc(iabs(iti),mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
3819 Im(1,1)=Im(1,1)+Ip(mnum)*(1-dc_norm(1,i)*dc_norm(1,i))* &
3820 vbld(i+1)*vbld(i+1)*0.25d0
3821 Im(1,2)=Im(1,2)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(2,i))* &
3822 vbld(i+1)*vbld(i+1)*0.25d0
3823 Im(1,3)=Im(1,3)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(3,i))* &
3824 vbld(i+1)*vbld(i+1)*0.25d0
3825 Im(2,3)=Im(2,3)+Ip(mnum)*(-dc_norm(2,i)*dc_norm(3,i))* &
3826 vbld(i+1)*vbld(i+1)*0.25d0
3827 Im(2,2)=Im(2,2)+Ip(mnum)*(1-dc_norm(2,i)*dc_norm(2,i))* &
3828 vbld(i+1)*vbld(i+1)*0.25d0
3829 Im(3,3)=Im(3,3)+Ip(mnum)*(1-dc_norm(3,i)*dc_norm(3,i))* &
3830 vbld(i+1)*vbld(i+1)*0.25d0
3836 ! if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
3837 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3838 .and.(mnum.ne.5)) then
3839 iti=iabs(itype(i,mnum))
3841 Im(1,1)=Im(1,1)+Isc(iti,mnum)*(1-dc_norm(1,inres)* &
3842 dc_norm(1,inres))*vbld(inres)*vbld(inres)
3843 Im(1,2)=Im(1,2)-Isc(iti,mnum)*(dc_norm(1,inres)* &
3844 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3845 Im(1,3)=Im(1,3)-Isc(iti,mnum)*(dc_norm(1,inres)* &
3846 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3847 Im(2,3)=Im(2,3)-Isc(iti,mnum)*(dc_norm(2,inres)* &
3848 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3849 Im(2,2)=Im(2,2)+Isc(iti,mnum)*(1-dc_norm(2,inres)* &
3850 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3851 Im(3,3)=Im(3,3)+Isc(iti,mnum)*(1-dc_norm(3,inres)* &
3852 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3857 ! write(iout,*) "The angular momentum before adjustment:"
3858 ! write(iout,*) (L(j),j=1,3)
3864 ! Copying the Im matrix for the djacob subroutine
3872 ! Finding the eigenvectors and eignvalues of the inertia tensor
3873 call djacob(3,3,10000,1.0d-10,Imcp,eigvec,eigval)
3874 ! write (iout,*) "Eigenvalues & Eigenvectors"
3875 ! write (iout,'(5x,3f10.5)') (eigval(i),i=1,3)
3878 ! write (iout,'(i5,3f10.5)') i,(eigvec(i,j),j=1,3)
3880 ! Constructing the diagonalized matrix
3882 if (dabs(eigval(i)).gt.1.0d-15) then
3883 Id(i,i)=1.0d0/eigval(i)
3890 Imcp(i,j)=eigvec(j,i)
3896 pr1(i,j)=pr1(i,j)+Id(i,k)*Imcp(k,j)
3903 pr2(i,j)=pr2(i,j)+eigvec(i,k)*pr1(k,j)
3907 ! Calculating the total rotational velocity of the molecule
3910 vrot(i)=vrot(i)+pr2(i,j)*L(j)
3913 ! Resetting the velocities
3915 call vecpr(vrot(1),dc(1,i),vp)
3917 d_t(j,i)=d_t(j,i)-vp(j)
3922 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3923 .and.(mnum.ne.5)) then
3924 ! if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
3925 ! if(itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3927 call vecpr(vrot(1),dc(1,inres),vp)
3929 d_t(j,inres)=d_t(j,inres)-vp(j)
3934 ! write(iout,*) "The angular momentum after adjustment:"
3935 ! write(iout,*) (L(j),j=1,3)
3938 end subroutine inertia_tensor
3939 !-----------------------------------------------------------------------------
3940 subroutine angmom(cm,L)
3943 ! implicit real*8 (a-h,o-z)
3944 ! include 'DIMENSIONS'
3945 ! include 'COMMON.CONTROL'
3946 ! include 'COMMON.VAR'
3947 ! include 'COMMON.MD'
3948 ! include 'COMMON.CHAIN'
3949 ! include 'COMMON.DERIV'
3950 ! include 'COMMON.GEO'
3951 ! include 'COMMON.LOCAL'
3952 ! include 'COMMON.INTERACT'
3953 ! include 'COMMON.IOUNITS'
3954 ! include 'COMMON.NAMES'
3955 real(kind=8) :: mscab
3956 real(kind=8),dimension(3) :: L,cm,pr,vp,vrot,incr,v,pp
3957 integer :: iti,inres,i,j,mnum
3958 ! Calculate the angular momentum
3967 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3969 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3972 v(j)=incr(j)+0.5d0*d_t(j,i)
3975 incr(j)=incr(j)+d_t(j,i)
3977 call vecpr(pr(1),v(1),vp)
3979 L(j)=L(j)+mp(mnum)*vp(j)
3983 pp(j)=0.5d0*d_t(j,i)
3985 call vecpr(pr(1),pp(1),vp)
3987 L(j)=L(j)+Ip(mnum)*vp(j)
3995 iti=iabs(itype(i,mnum))
4003 pr(j)=c(j,inres)-cm(j)
4005 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4006 .and.(mnum.ne.5)) then
4008 v(j)=incr(j)+d_t(j,inres)
4015 call vecpr(pr(1),v(1),vp)
4016 ! write (iout,*) "i",i," iti",iti," pr",(pr(j),j=1,3),
4017 ! & " v",(v(j),j=1,3)," vp",(vp(j),j=1,3)
4019 L(j)=L(j)+mscab*vp(j)
4021 ! write (iout,*) "L",(l(j),j=1,3)
4022 if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4023 .and.(mnum.ne.5)) then
4025 v(j)=incr(j)+d_t(j,inres)
4027 call vecpr(dc(1,inres),d_t(1,inres),vp)
4029 L(j)=L(j)+Isc(iti,mnum)*vp(j)
4033 incr(j)=incr(j)+d_t(j,i)
4037 end subroutine angmom
4038 !-----------------------------------------------------------------------------
4039 subroutine vcm_vel(vcm)
4042 ! implicit real*8 (a-h,o-z)
4043 ! include 'DIMENSIONS'
4044 ! include 'COMMON.VAR'
4045 ! include 'COMMON.MD'
4046 ! include 'COMMON.CHAIN'
4047 ! include 'COMMON.DERIV'
4048 ! include 'COMMON.GEO'
4049 ! include 'COMMON.LOCAL'
4050 ! include 'COMMON.INTERACT'
4051 ! include 'COMMON.IOUNITS'
4052 real(kind=8),dimension(3) :: vcm,vv
4053 real(kind=8) :: summas,amas
4063 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
4065 summas=summas+mp(mnum)
4067 vcm(j)=vcm(j)+mp(mnum)*(vv(j)+0.5d0*d_t(j,i))
4071 amas=msc(iabs(itype(i,mnum)),mnum)
4076 if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4077 .and.(mnum.ne.5)) then
4079 vcm(j)=vcm(j)+amas*(vv(j)+d_t(j,i+nres))
4083 vcm(j)=vcm(j)+amas*vv(j)
4087 vv(j)=vv(j)+d_t(j,i)
4090 ! write (iout,*) "vcm",(vcm(j),j=1,3)," summas",summas
4092 vcm(j)=vcm(j)/summas
4095 end subroutine vcm_vel
4096 !-----------------------------------------------------------------------------
4098 !-----------------------------------------------------------------------------
4100 ! RATTLE algorithm for velocity Verlet - step 1, UNRES
4104 ! implicit real*8 (a-h,o-z)
4105 ! include 'DIMENSIONS'
4107 ! include 'COMMON.CONTROL'
4108 ! include 'COMMON.VAR'
4109 ! include 'COMMON.MD'
4111 ! include 'COMMON.LANGEVIN'
4113 ! include 'COMMON.LANGEVIN.lang0'
4115 ! include 'COMMON.CHAIN'
4116 ! include 'COMMON.DERIV'
4117 ! include 'COMMON.GEO'
4118 ! include 'COMMON.LOCAL'
4119 ! include 'COMMON.INTERACT'
4120 ! include 'COMMON.IOUNITS'
4121 ! include 'COMMON.NAMES'
4122 ! include 'COMMON.TIME1'
4123 !el real(kind=8) :: gginv(2*nres,2*nres),&
4124 !el gdc(3,2*nres,2*nres)
4125 real(kind=8) :: dC_uncor(3,2*nres) !,&
4126 !el real(kind=8) :: Cmat(2*nres,2*nres)
4127 real(kind=8) :: x(2*nres),xcorr(3,2*nres) !maxres2=2*maxres
4128 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4129 !el common /przechowalnia/ nbond
4130 integer :: max_rattle = 5
4131 logical :: lprn = .false., lprn1 = .false., not_done
4132 real(kind=8) :: tol_rattle = 1.0d-5
4134 integer :: ii,i,j,jj,l,ind,ind1,nres2
4137 !el /common/ przechowalnia
4139 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4140 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4141 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4143 if (lprn) write (iout,*) "RATTLE1"
4147 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4148 .and.(mnum.ne.5)) nbond=nbond+1
4150 ! Make a folded form of the Ginv-matrix
4163 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4168 if (itype(k,1).ne.10 .and. itype(k,mnum).ne.ntyp1_molec(mnum)&
4169 .and.(mnum.ne.5)) then
4173 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4181 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4192 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4196 if (itype(k,1).ne.10) then
4200 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4208 write (iout,*) "Matrix GGinv"
4209 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4215 if (iter.gt.max_rattle) then
4216 write (iout,*) "Error - too many iterations in RATTLE."
4219 ! Calculate the matrix C = GG**(-1) dC_old o dC
4224 dC_uncor(j,ind1)=dC(j,i)
4228 if (itype(i,1).ne.10) then
4231 dC_uncor(j,ind1)=dC(j,i+nres)
4240 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4244 if (itype(k,1).ne.10) then
4247 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4252 ! Calculate deviations from standard virtual-bond lengths
4256 x(ind)=vbld(i+1)**2-vbl**2
4259 if (itype(i,1).ne.10) then
4261 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4265 write (iout,*) "Coordinates and violations"
4267 write(iout,'(i5,3f10.5,5x,e15.5)') &
4268 i,(dC_uncor(j,i),j=1,3),x(i)
4270 write (iout,*) "Velocities and violations"
4274 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4275 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4279 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4280 .and.(mnum.ne.5)) then
4283 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4284 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4285 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4288 ! write (iout,*) "gdc"
4290 ! write (iout,*) "i",i
4292 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4298 if (dabs(x(i)).gt.xmax) then
4302 if (xmax.lt.tol_rattle) then
4306 ! Calculate the matrix of the system of equations
4311 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4316 write (iout,*) "Matrix Cmat"
4317 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4319 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4320 ! Add constraint term to positions
4327 xx = xx+x(ii)*gdc(j,ind,ii)
4331 d_t_new(j,i)=d_t_new(j,i)-xx/d_time
4335 if (itype(i,1).ne.10) then
4340 xx = xx+x(ii)*gdc(j,ind,ii)
4343 dC(j,i+nres)=dC(j,i+nres)-xx
4344 d_t_new(j,i+nres)=d_t_new(j,i+nres)-xx/d_time
4348 ! Rebuild the chain using the new coordinates
4349 call chainbuild_cart
4351 write (iout,*) "New coordinates, Lagrange multipliers,",&
4352 " and differences between actual and standard bond lengths"
4356 xx=vbld(i+1)**2-vbl**2
4357 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4358 i,(dC(j,i),j=1,3),x(ind),xx
4362 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4365 xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4366 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4367 i,(dC(j,i+nres),j=1,3),x(ind),xx
4370 write (iout,*) "Velocities and violations"
4374 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4375 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4378 if (itype(i,1).ne.10) then
4380 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4381 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4382 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4389 10 write (iout,*) "Error - singularity in solving the system",&
4390 " of equations for Lagrange multipliers."
4394 "RATTLE inactive; use -DRATTLE switch at compile time."
4397 end subroutine rattle1
4398 !-----------------------------------------------------------------------------
4400 ! RATTLE algorithm for velocity Verlet - step 2, UNRES
4404 ! implicit real*8 (a-h,o-z)
4405 ! include 'DIMENSIONS'
4407 ! include 'COMMON.CONTROL'
4408 ! include 'COMMON.VAR'
4409 ! include 'COMMON.MD'
4411 ! include 'COMMON.LANGEVIN'
4413 ! include 'COMMON.LANGEVIN.lang0'
4415 ! include 'COMMON.CHAIN'
4416 ! include 'COMMON.DERIV'
4417 ! include 'COMMON.GEO'
4418 ! include 'COMMON.LOCAL'
4419 ! include 'COMMON.INTERACT'
4420 ! include 'COMMON.IOUNITS'
4421 ! include 'COMMON.NAMES'
4422 ! include 'COMMON.TIME1'
4423 !el real(kind=8) :: gginv(2*nres,2*nres),&
4424 !el gdc(3,2*nres,2*nres)
4425 real(kind=8) :: dC_uncor(3,2*nres) !,&
4426 !el Cmat(2*nres,2*nres)
4427 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4428 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4429 !el common /przechowalnia/ nbond
4430 integer :: max_rattle = 5
4431 logical :: lprn = .false., lprn1 = .false., not_done
4432 real(kind=8) :: tol_rattle = 1.0d-5
4436 !el /common/ przechowalnia
4437 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4438 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4439 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4441 if (lprn) write (iout,*) "RATTLE2"
4442 if (lprn) write (iout,*) "Velocity correction"
4443 ! Calculate the matrix G dC
4449 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k)
4454 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4455 .and.(mnum.ne.5)) then
4458 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k+nres)
4464 ! write (iout,*) "gdc"
4466 ! write (iout,*) "i",i
4468 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4472 ! Calculate the matrix of the system of equations
4479 Cmat(ind,j)=Cmat(ind,j)+dC(k,i)*gdc(k,ind,j)
4485 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4486 .and.(mnum.ne.5)) then
4491 Cmat(ind,j)=Cmat(ind,j)+dC(k,i+nres)*gdc(k,ind,j)
4496 ! Calculate the scalar product dC o d_t_new
4500 x(ind)=scalar(d_t(1,i),dC(1,i))
4504 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4505 .and.(mnum.ne.5)) then
4507 x(ind)=scalar(d_t(1,i+nres),dC(1,i+nres))
4511 write (iout,*) "Velocities and violations"
4515 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4516 i,ind,(d_t(j,i),j=1,3),x(ind)
4520 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4521 .and.(mnum.ne.5)) then
4523 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4524 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind)
4530 if (dabs(x(i)).gt.xmax) then
4534 if (xmax.lt.tol_rattle) then
4539 write (iout,*) "Matrix Cmat"
4540 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4542 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4543 ! Add constraint term to velocities
4550 xx = xx+x(ii)*gdc(j,ind,ii)
4552 d_t(j,i)=d_t(j,i)-xx
4557 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4558 .and.(mnum.ne.5)) then
4563 xx = xx+x(ii)*gdc(j,ind,ii)
4565 d_t(j,i+nres)=d_t(j,i+nres)-xx
4571 "New velocities, Lagrange multipliers violations"
4575 if (lprn) write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4576 i,ind,(d_t(j,i),j=1,3),x(ind),scalar(d_t(1,i),dC(1,i))
4580 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4583 write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4584 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind),&
4585 scalar(d_t(1,i+nres),dC(1,i+nres))
4591 10 write (iout,*) "Error - singularity in solving the system",&
4592 " of equations for Lagrange multipliers."
4596 "RATTLE inactive; use -DRATTLE option at compile time."
4599 end subroutine rattle2
4600 !-----------------------------------------------------------------------------
4601 subroutine rattle_brown
4602 ! RATTLE/LINCS algorithm for Brownian dynamics, UNRES
4606 ! implicit real*8 (a-h,o-z)
4607 ! include 'DIMENSIONS'
4609 ! include 'COMMON.CONTROL'
4610 ! include 'COMMON.VAR'
4611 ! include 'COMMON.MD'
4613 ! include 'COMMON.LANGEVIN'
4615 ! include 'COMMON.LANGEVIN.lang0'
4617 ! include 'COMMON.CHAIN'
4618 ! include 'COMMON.DERIV'
4619 ! include 'COMMON.GEO'
4620 ! include 'COMMON.LOCAL'
4621 ! include 'COMMON.INTERACT'
4622 ! include 'COMMON.IOUNITS'
4623 ! include 'COMMON.NAMES'
4624 ! include 'COMMON.TIME1'
4625 !el real(kind=8) :: gginv(2*nres,2*nres),&
4626 !el gdc(3,2*nres,2*nres)
4627 real(kind=8) :: dC_uncor(3,2*nres) !,&
4628 !el real(kind=8) :: Cmat(2*nres,2*nres)
4629 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4630 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4631 !el common /przechowalnia/ nbond
4632 integer :: max_rattle = 5
4633 logical :: lprn = .false., lprn1 = .false., not_done
4634 real(kind=8) :: tol_rattle = 1.0d-5
4638 !el /common/ przechowalnia
4639 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4640 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4641 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4644 if (lprn) write (iout,*) "RATTLE_BROWN"
4647 if (itype(i,1).ne.10) nbond=nbond+1
4649 ! Make a folded form of the Ginv-matrix
4662 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4666 if (itype(k,1).ne.10) then
4670 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4677 if (itype(i,1).ne.10) then
4687 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4691 if (itype(k,1).ne.10) then
4695 if (j.eq.1 .and. l.eq.1)GGinv(ii,jj)=fricmat(ind,ind1)
4703 write (iout,*) "Matrix GGinv"
4704 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4710 if (iter.gt.max_rattle) then
4711 write (iout,*) "Error - too many iterations in RATTLE."
4714 ! Calculate the matrix C = GG**(-1) dC_old o dC
4719 dC_uncor(j,ind1)=dC(j,i)
4723 if (itype(i,1).ne.10) then
4726 dC_uncor(j,ind1)=dC(j,i+nres)
4735 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4739 if (itype(k,1).ne.10) then
4742 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4747 ! Calculate deviations from standard virtual-bond lengths
4751 x(ind)=vbld(i+1)**2-vbl**2
4754 if (itype(i,1).ne.10) then
4756 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4760 write (iout,*) "Coordinates and violations"
4762 write(iout,'(i5,3f10.5,5x,e15.5)') &
4763 i,(dC_uncor(j,i),j=1,3),x(i)
4765 write (iout,*) "Velocities and violations"
4769 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4770 i,ind,(d_t(j,i),j=1,3),scalar(d_t(1,i),dC_old(1,i))
4773 if (itype(i,1).ne.10) then
4775 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4776 i+nres,ind,(d_t(j,i+nres),j=1,3),&
4777 scalar(d_t(1,i+nres),dC_old(1,i+nres))
4780 write (iout,*) "gdc"
4782 write (iout,*) "i",i
4784 write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4790 if (dabs(x(i)).gt.xmax) then
4794 if (xmax.lt.tol_rattle) then
4798 ! Calculate the matrix of the system of equations
4803 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4808 write (iout,*) "Matrix Cmat"
4809 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4811 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4812 ! Add constraint term to positions
4819 xx = xx+x(ii)*gdc(j,ind,ii)
4822 d_t(j,i)=d_t(j,i)+xx/d_time
4827 if (itype(i,1).ne.10) then
4832 xx = xx+x(ii)*gdc(j,ind,ii)
4835 d_t(j,i+nres)=d_t(j,i+nres)+xx/d_time
4836 dC(j,i+nres)=dC(j,i+nres)+xx
4840 ! Rebuild the chain using the new coordinates
4841 call chainbuild_cart
4843 write (iout,*) "New coordinates, Lagrange multipliers,",&
4844 " and differences between actual and standard bond lengths"
4848 xx=vbld(i+1)**2-vbl**2
4849 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4850 i,(dC(j,i),j=1,3),x(ind),xx
4853 if (itype(i,1).ne.10) then
4855 xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4856 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4857 i,(dC(j,i+nres),j=1,3),x(ind),xx
4860 write (iout,*) "Velocities and violations"
4864 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4865 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4868 if (itype(i,1).ne.10) then
4870 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4871 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4872 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4879 10 write (iout,*) "Error - singularity in solving the system",&
4880 " of equations for Lagrange multipliers."
4884 "RATTLE inactive; use -DRATTLE option at compile time"
4887 end subroutine rattle_brown
4888 !-----------------------------------------------------------------------------
4890 !-----------------------------------------------------------------------------
4891 subroutine friction_force
4896 ! implicit real*8 (a-h,o-z)
4897 ! include 'DIMENSIONS'
4898 ! include 'COMMON.VAR'
4899 ! include 'COMMON.CHAIN'
4900 ! include 'COMMON.DERIV'
4901 ! include 'COMMON.GEO'
4902 ! include 'COMMON.LOCAL'
4903 ! include 'COMMON.INTERACT'
4904 ! include 'COMMON.MD'
4906 ! include 'COMMON.LANGEVIN'
4908 ! include 'COMMON.LANGEVIN.lang0'
4910 ! include 'COMMON.IOUNITS'
4911 !el real(kind=8),dimension(6*nres) :: gamvec !(MAXRES6) maxres6=6*maxres
4912 !el common /syfek/ gamvec
4913 real(kind=8) :: vv(3),vvtot(3,nres),v_work(6*nres) !,&
4914 !el ginvfric(2*nres,2*nres) !maxres2=2*maxres
4915 !el common /przechowalnia/ ginvfric
4917 logical :: lprn = .false., checkmode = .false.
4918 integer :: i,j,ind,k,nres2,nres6,mnum
4922 if(.not.allocated(gamvec)) allocate(gamvec(nres6)) !(MAXRES6)
4923 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
4931 d_t_work(j)=d_t(j,0)
4936 d_t_work(ind+j)=d_t(j,i)
4942 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
4943 .and.(mnum.ne.5)) then
4945 d_t_work(ind+j)=d_t(j,i+nres)
4951 call fricmat_mult(d_t_work,fric_work)
4953 if (.not.checkmode) return
4956 write (iout,*) "d_t_work and fric_work"
4958 write (iout,'(i3,2e15.5)') i,d_t_work(i),fric_work(i)
4962 friction(j,0)=fric_work(j)
4967 friction(j,i)=fric_work(ind+j)
4973 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
4974 .and.(mnum.ne.5)) then
4975 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
4977 friction(j,i+nres)=fric_work(ind+j)
4983 write(iout,*) "Friction backbone"
4985 write(iout,'(i5,3e15.5,5x,3e15.5)') &
4986 i,(friction(j,i),j=1,3),(d_t(j,i),j=1,3)
4988 write(iout,*) "Friction side chain"
4990 write(iout,'(i5,3e15.5,5x,3e15.5)') &
4991 i,(friction(j,i+nres),j=1,3),(d_t(j,i+nres),j=1,3)
5000 vvtot(j,i)=vv(j)+0.5d0*d_t(j,i)
5001 vvtot(j,i+nres)=vv(j)+d_t(j,i+nres)
5002 vv(j)=vv(j)+d_t(j,i)
5005 write (iout,*) "vvtot backbone and sidechain"
5007 write (iout,'(i5,3e15.5,5x,3e15.5)') i,(vvtot(j,i),j=1,3),&
5008 (vvtot(j,i+nres),j=1,3)
5013 v_work(ind+j)=vvtot(j,i)
5019 v_work(ind+j)=vvtot(j,i+nres)
5023 write (iout,*) "v_work gamvec and site-based friction forces"
5025 write (iout,'(i5,3e15.5)') i,v_work(i),gamvec(i),&
5029 ! fric_work1(i)=0.0d0
5031 ! fric_work1(i)=fric_work1(i)-A(j,i)*gamvec(j)*v_work(j)
5034 ! write (iout,*) "fric_work and fric_work1"
5036 ! write (iout,'(i5,2e15.5)') i,fric_work(i),fric_work1(i)
5042 ginvfric(i,j)=ginvfric(i,j)+ginv(i,k)*fricmat(k,j)
5046 write (iout,*) "ginvfric"
5048 write (iout,'(i5,100f8.3)') i,(ginvfric(i,j),j=1,dimen)
5050 write (iout,*) "symmetry check"
5053 write (iout,*) i,j,ginvfric(i,j)-ginvfric(j,i)
5058 end subroutine friction_force
5059 !-----------------------------------------------------------------------------
5060 subroutine setup_fricmat
5064 use control_data, only:time_Bcast
5065 use control, only:tcpu
5067 ! implicit real*8 (a-h,o-z)
5071 real(kind=8) :: time00
5073 ! include 'DIMENSIONS'
5074 ! include 'COMMON.VAR'
5075 ! include 'COMMON.CHAIN'
5076 ! include 'COMMON.DERIV'
5077 ! include 'COMMON.GEO'
5078 ! include 'COMMON.LOCAL'
5079 ! include 'COMMON.INTERACT'
5080 ! include 'COMMON.MD'
5081 ! include 'COMMON.SETUP'
5082 ! include 'COMMON.TIME1'
5083 ! integer licznik /0/
5086 ! include 'COMMON.LANGEVIN'
5088 ! include 'COMMON.LANGEVIN.lang0'
5090 ! include 'COMMON.IOUNITS'
5092 integer :: i,j,ind,ind1,m
5093 logical :: lprn = .false.
5094 real(kind=8) :: dtdi !el ,gamvec(2*nres)
5095 !el real(kind=8),dimension(2*nres,2*nres) :: ginvfric,fcopy
5096 ! real(kind=8),allocatable,dimension(:,:) :: fcopy
5097 !el real(kind=8),dimension(2*nres*(2*nres+1)/2) :: Ghalf !(mmaxres2) (mmaxres2=(maxres2*(maxres2+1)/2))
5098 !el common /syfek/ gamvec
5099 real(kind=8) :: work(8*2*nres)
5100 integer :: iwork(2*nres)
5101 !el common /przechowalnia/ ginvfric,Ghalf,fcopy
5102 integer :: ii,iti,k,l,nzero,nres2,nres6,ierr,mnum
5106 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5107 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5108 if (fg_rank.ne.king) goto 10
5113 if(.not.allocated(gamvec)) allocate(gamvec(nres2)) !(MAXRES2)
5114 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
5115 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5116 !el allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5117 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !maxres2=2*maxres
5119 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5120 ! Zeroing out fricmat
5126 ! Load the friction coefficients corresponding to peptide groups
5131 gamvec(ind1)=gamp(mnum)
5133 ! Load the friction coefficients corresponding to side chains
5137 gamsc(ntyp1_molec(j),j)=1.0d0
5144 gamvec(ii)=gamsc(iabs(iti),mnum)
5146 if (surfarea) call sdarea(gamvec)
5148 ! write (iout,*) "Matrix A and vector gamma"
5150 ! write (iout,'(i2,$)') i
5152 ! write (iout,'(f4.1,$)') A(i,j)
5154 ! write (iout,'(f8.3)') gamvec(i)
5158 write (iout,*) "Vector gamvec"
5160 write (iout,'(i5,f10.5)') i, gamvec(i)
5164 ! The friction matrix
5169 dtdi=dtdi+A(j,k)*A(j,i)*gamvec(j)
5176 write (iout,'(//a)') "Matrix fricmat"
5177 call matout2(dimen,dimen,nres2,nres2,fricmat)
5179 if (lang.eq.2 .or. lang.eq.3) then
5180 ! Mass-scale the friction matrix if non-direct integration will be performed
5186 Ginvfric(i,j)=Ginvfric(i,j)+ &
5187 Gsqrm(i,k)*Gsqrm(l,j)*fricmat(k,l)
5192 ! Diagonalize the friction matrix
5197 Ghalf(ind)=Ginvfric(i,j)
5200 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5203 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5204 " mass-scaled friction matrix"
5205 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5207 ! Precompute matrices for tinker stochastic integrator
5214 mt1(i,j)=mt1(i,j)+fricvec(k,i)*gsqrm(k,j)
5215 mt2(i,j)=mt2(i,j)+fricvec(k,i)*gsqrp(k,j)
5221 else if (lang.eq.4) then
5222 ! Diagonalize the friction matrix
5227 Ghalf(ind)=fricmat(i,j)
5230 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5233 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5235 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5237 ! Determine the number of zero eigenvalues of the friction matrix
5238 nzero=max0(dimen-dimen1,0)
5239 ! do while (fricgam(nzero+1).le.1.0d-5 .and. nzero.lt.dimen)
5242 write (iout,*) "Number of zero eigenvalues:",nzero
5247 fricmat(i,j)=fricmat(i,j) &
5248 +fricvec(i,k)*fricvec(j,k)/fricgam(k)
5253 write (iout,'(//a)') "Generalized inverse of fricmat"
5254 call matout(dimen,dimen,nres6,nres6,fricmat)
5259 if (nfgtasks.gt.1) then
5260 if (fg_rank.eq.0) then
5261 ! The matching BROADCAST for fg processors is called in ERGASTULUM
5267 call MPI_Bcast(10,1,MPI_INTEGER,king,FG_COMM,IERROR)
5269 time_Bcast=time_Bcast+MPI_Wtime()-time00
5271 time_Bcast=time_Bcast+tcpu()-time00
5273 ! print *,"Processor",myrank,
5274 ! & " BROADCAST iorder in SETUP_FRICMAT"
5277 write (iout,*) "setup_fricmat licznik"!,licznik !sp
5283 ! Scatter the friction matrix
5284 call MPI_Scatterv(fricmat(1,1),nginv_counts(0),&
5285 nginv_start(0),MPI_DOUBLE_PRECISION,fcopy(1,1),&
5286 myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
5289 time_scatter=time_scatter+MPI_Wtime()-time00
5290 time_scatter_fmat=time_scatter_fmat+MPI_Wtime()-time00
5292 time_scatter=time_scatter+tcpu()-time00
5293 time_scatter_fmat=time_scatter_fmat+tcpu()-time00
5297 do j=1,2*my_ng_count
5298 fricmat(j,i)=fcopy(i,j)
5301 ! write (iout,*) "My chunk of fricmat"
5302 ! call MATOUT2(my_ng_count,dimen,maxres2,maxres2,fcopy)
5306 end subroutine setup_fricmat
5307 !-----------------------------------------------------------------------------
5308 subroutine stochastic_force(stochforcvec)
5311 use random, only:anorm_distr
5312 ! implicit real*8 (a-h,o-z)
5313 ! include 'DIMENSIONS'
5314 use control, only: tcpu
5319 ! include 'COMMON.VAR'
5320 ! include 'COMMON.CHAIN'
5321 ! include 'COMMON.DERIV'
5322 ! include 'COMMON.GEO'
5323 ! include 'COMMON.LOCAL'
5324 ! include 'COMMON.INTERACT'
5325 ! include 'COMMON.MD'
5326 ! include 'COMMON.TIME1'
5328 ! include 'COMMON.LANGEVIN'
5330 ! include 'COMMON.LANGEVIN.lang0'
5332 ! include 'COMMON.IOUNITS'
5334 real(kind=8) :: x,sig,lowb,highb
5335 real(kind=8) :: ff(3),force(3,0:2*nres),zeta2,lowb2
5336 real(kind=8) :: highb2,sig2,forcvec(6*nres),stochforcvec(6*nres)
5337 real(kind=8) :: time00
5338 logical :: lprn = .false.
5339 integer :: i,j,ind,mnum
5343 stochforc(j,i)=0.0d0
5353 ! Compute the stochastic forces acting on bodies. Store in force.
5359 force(j,i)=anorm_distr(x,sig,lowb,highb)
5367 force(j,i+nres)=anorm_distr(x,sig2,lowb2,highb2)
5371 time_fsample=time_fsample+MPI_Wtime()-time00
5373 time_fsample=time_fsample+tcpu()-time00
5375 ! Compute the stochastic forces acting on virtual-bond vectors.
5381 stochforc(j,i)=ff(j)+0.5d0*force(j,i)
5384 ff(j)=ff(j)+force(j,i)
5386 ! if (itype(i+1,1).ne.ntyp1) then
5388 if (itype(i+1,mnum).ne.ntyp1_molec(mnum)) then
5390 stochforc(j,i)=stochforc(j,i)+force(j,i+nres+1)
5391 ff(j)=ff(j)+force(j,i+nres+1)
5396 stochforc(j,0)=ff(j)+force(j,nnt+nres)
5400 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5401 .and.(mnum.ne.5)) then
5402 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5404 stochforc(j,i+nres)=force(j,i+nres)
5410 stochforcvec(j)=stochforc(j,0)
5415 stochforcvec(ind+j)=stochforc(j,i)
5421 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5422 .and.(mnum.ne.5)) then
5423 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5425 stochforcvec(ind+j)=stochforc(j,i+nres)
5431 write (iout,*) "stochforcvec"
5433 write(iout,'(i5,e15.5)') i,stochforcvec(i)
5435 write(iout,*) "Stochastic forces backbone"
5437 write(iout,'(i5,3e15.5)') i,(stochforc(j,i),j=1,3)
5439 write(iout,*) "Stochastic forces side chain"
5441 write(iout,'(i5,3e15.5)') &
5442 i,(stochforc(j,i+nres),j=1,3)
5450 write (iout,*) i,ind
5452 forcvec(ind+j)=force(j,i)
5457 write (iout,*) i,ind
5459 forcvec(j+ind)=force(j,i+nres)
5464 write (iout,*) "forcvec"
5468 write (iout,'(2i3,2f10.5)') i,j,force(j,i),&
5475 write (iout,'(2i3,2f10.5)') i,j,force(j,i+nres),&
5484 end subroutine stochastic_force
5485 !-----------------------------------------------------------------------------
5486 subroutine sdarea(gamvec)
5488 ! Scale the friction coefficients according to solvent accessible surface areas
5489 ! Code adapted from TINKER
5493 ! implicit real*8 (a-h,o-z)
5494 ! include 'DIMENSIONS'
5495 ! include 'COMMON.CONTROL'
5496 ! include 'COMMON.VAR'
5497 ! include 'COMMON.MD'
5499 ! include 'COMMON.LANGEVIN'
5501 ! include 'COMMON.LANGEVIN.lang0'
5503 ! include 'COMMON.CHAIN'
5504 ! include 'COMMON.DERIV'
5505 ! include 'COMMON.GEO'
5506 ! include 'COMMON.LOCAL'
5507 ! include 'COMMON.INTERACT'
5508 ! include 'COMMON.IOUNITS'
5509 ! include 'COMMON.NAMES'
5510 real(kind=8),dimension(2*nres) :: radius,gamvec !(maxres2)
5511 real(kind=8),parameter :: twosix = 1.122462048309372981d0
5512 logical :: lprn = .false.
5513 real(kind=8) :: probe,area,ratio
5514 integer :: i,j,ind,iti,mnum
5516 ! determine new friction coefficients every few SD steps
5518 ! set the atomic radii to estimates of sigma values
5520 ! print *,"Entered sdarea"
5526 ! Load peptide group radii
5529 radius(i)=pstok(mnum)
5531 ! Load side chain radii
5535 radius(i+nres)=restok(iti,mnum)
5538 ! write (iout,*) "i",i," radius",radius(i)
5541 radius(i) = radius(i) / twosix
5542 if (radius(i) .ne. 0.0d0) radius(i) = radius(i) + probe
5545 ! scale atomic friction coefficients by accessible area
5547 if (lprn) write (iout,*) &
5548 "Original gammas, surface areas, scaling factors, new gammas, ",&
5549 "std's of stochastic forces"
5552 if (radius(i).gt.0.0d0) then
5553 call surfatom (i,area,radius)
5554 ratio = dmax1(area/(4.0d0*pi*radius(i)**2),1.0d-1)
5555 if (lprn) write (iout,'(i5,3f10.5,$)') &
5556 i,gamvec(ind+1),area,ratio
5559 gamvec(ind) = ratio * gamvec(ind)
5562 stdforcp(i)=stdfp(mnum)*dsqrt(gamvec(ind))
5563 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcp(i)
5567 if (radius(i+nres).gt.0.0d0) then
5568 call surfatom (i+nres,area,radius)
5569 ratio = dmax1(area/(4.0d0*pi*radius(i+nres)**2),1.0d-1)
5570 if (lprn) write (iout,'(i5,3f10.5,$)') &
5571 i,gamvec(ind+1),area,ratio
5574 gamvec(ind) = ratio * gamvec(ind)
5577 stdforcsc(i)=stdfsc(itype(i,mnum),mnum)*dsqrt(gamvec(ind))
5578 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcsc(i)
5583 end subroutine sdarea
5584 !-----------------------------------------------------------------------------
5586 !-----------------------------------------------------------------------------
5589 ! ###################################################
5590 ! ## COPYRIGHT (C) 1996 by Jay William Ponder ##
5591 ! ## All Rights Reserved ##
5592 ! ###################################################
5594 ! ################################################################
5596 ! ## subroutine surfatom -- exposed surface area of an atom ##
5598 ! ################################################################
5601 ! "surfatom" performs an analytical computation of the surface
5602 ! area of a specified atom; a simplified version of "surface"
5604 ! literature references:
5606 ! T. J. Richmond, "Solvent Accessible Surface Area and
5607 ! Excluded Volume in Proteins", Journal of Molecular Biology,
5610 ! L. Wesson and D. Eisenberg, "Atomic Solvation Parameters
5611 ! Applied to Molecular Dynamics of Proteins in Solution",
5612 ! Protein Science, 1, 227-235 (1992)
5614 ! variables and parameters:
5616 ! ir number of atom for which area is desired
5617 ! area accessible surface area of the atom
5618 ! radius radii of each of the individual atoms
5621 subroutine surfatom(ir,area,radius)
5623 ! implicit real*8 (a-h,o-z)
5624 ! include 'DIMENSIONS'
5626 ! include 'COMMON.GEO'
5627 ! include 'COMMON.IOUNITS'
5629 integer :: nsup,nstart_sup
5630 ! double precision c,dc,dc_old,d_c_work,xloc,xrot,dc_norm
5631 ! common /chain/ c(3,maxres2+2),dc(3,0:maxres2),dc_old(3,0:maxres2),
5632 ! & xloc(3,maxres),xrot(3,maxres),dc_norm(3,0:maxres2),
5633 ! & dc_work(MAXRES6),nres,nres0
5634 integer,parameter :: maxarc=300
5638 integer :: mi,ni,narc
5639 integer :: key(maxarc)
5640 integer :: intag(maxarc)
5641 integer :: intag1(maxarc)
5642 real(kind=8) :: area,arcsum
5643 real(kind=8) :: arclen,exang
5644 real(kind=8) :: delta,delta2
5645 real(kind=8) :: eps,rmove
5646 real(kind=8) :: xr,yr,zr
5647 real(kind=8) :: rr,rrsq
5648 real(kind=8) :: rplus,rminus
5649 real(kind=8) :: axx,axy,axz
5650 real(kind=8) :: ayx,ayy
5651 real(kind=8) :: azx,azy,azz
5652 real(kind=8) :: uxj,uyj,uzj
5653 real(kind=8) :: tx,ty,tz
5654 real(kind=8) :: txb,tyb,td
5655 real(kind=8) :: tr2,tr,txr,tyr
5656 real(kind=8) :: tk1,tk2
5657 real(kind=8) :: thec,the,t,tb
5658 real(kind=8) :: txk,tyk,tzk
5659 real(kind=8) :: t1,ti,tf,tt
5660 real(kind=8) :: txj,tyj,tzj
5661 real(kind=8) :: ccsq,cc,xysq
5662 real(kind=8) :: bsqk,bk,cosine
5663 real(kind=8) :: dsqj,gi,pix2
5664 real(kind=8) :: therk,dk,gk
5665 real(kind=8) :: risqk,rik
5666 real(kind=8) :: radius(2*nres) !(maxatm) (maxatm=maxres2)
5667 real(kind=8) :: ri(maxarc),risq(maxarc)
5668 real(kind=8) :: ux(maxarc),uy(maxarc),uz(maxarc)
5669 real(kind=8) :: xc(maxarc),yc(maxarc),zc(maxarc)
5670 real(kind=8) :: xc1(maxarc),yc1(maxarc),zc1(maxarc)
5671 real(kind=8) :: dsq(maxarc),bsq(maxarc)
5672 real(kind=8) :: dsq1(maxarc),bsq1(maxarc)
5673 real(kind=8) :: arci(maxarc),arcf(maxarc)
5674 real(kind=8) :: ex(maxarc),lt(maxarc),gr(maxarc)
5675 real(kind=8) :: b(maxarc),b1(maxarc),bg(maxarc)
5676 real(kind=8) :: kent(maxarc),kout(maxarc)
5677 real(kind=8) :: ther(maxarc)
5678 logical :: moved,top
5679 logical :: omit(maxarc)
5682 ! maxatm = 2*nres !maxres2 maxres2=2*maxres
5683 ! maxlight = 8*maxatm
5686 ! maxtors = 4*maxatm
5688 ! zero out the surface area for the sphere of interest
5691 ! write (2,*) "ir",ir," radius",radius(ir)
5692 if (radius(ir) .eq. 0.0d0) return
5694 ! set the overlap significance and connectivity shift
5698 delta2 = delta * delta
5703 ! store coordinates and radius of the sphere of interest
5711 ! initialize values of some counters and summations
5720 ! test each sphere to see if it overlaps the sphere of interest
5723 if (i.eq.ir .or. radius(i).eq.0.0d0) goto 30
5724 rplus = rr + radius(i)
5726 if (abs(tx) .ge. rplus) goto 30
5728 if (abs(ty) .ge. rplus) goto 30
5730 if (abs(tz) .ge. rplus) goto 30
5732 ! check for sphere overlap by testing distance against radii
5734 xysq = tx*tx + ty*ty
5735 if (xysq .lt. delta2) then
5742 if (rplus-cc .le. delta) goto 30
5743 rminus = rr - radius(i)
5745 ! check to see if sphere of interest is completely buried
5747 if (cc-abs(rminus) .le. delta) then
5748 if (rminus .le. 0.0d0) goto 170
5752 ! check for too many overlaps with sphere of interest
5754 if (io .ge. maxarc) then
5756 20 format (/,' SURFATOM -- Increase the Value of MAXARC')
5760 ! get overlap between current sphere and sphere of interest
5769 gr(io) = (ccsq+rplus*rminus) / (2.0d0*rr*b1(io))
5775 ! case where no other spheres overlap the sphere of interest
5778 area = 4.0d0 * pi * rrsq
5782 ! case where only one sphere overlaps the sphere of interest
5785 area = pix2 * (1.0d0 + gr(1))
5786 area = mod(area,4.0d0*pi) * rrsq
5790 ! case where many spheres intersect the sphere of interest;
5791 ! sort the intersecting spheres by their degree of overlap
5793 call sort2 (io,gr,key)
5796 intag(i) = intag1(k)
5805 ! get radius of each overlap circle on surface of the sphere
5810 risq(i) = rrsq - gi*gi
5811 ri(i) = sqrt(risq(i))
5812 ther(i) = 0.5d0*pi - asin(min(1.0d0,max(-1.0d0,gr(i))))
5815 ! find boundary of inaccessible area on sphere of interest
5818 if (.not. omit(k)) then
5825 ! check to see if J circle is intersecting K circle;
5826 ! get distance between circle centers and sum of radii
5829 if (omit(j)) goto 60
5830 cc = (txk*xc(j)+tyk*yc(j)+tzk*zc(j))/(bk*b(j))
5831 cc = acos(min(1.0d0,max(-1.0d0,cc)))
5832 td = therk + ther(j)
5834 ! check to see if circles enclose separate regions
5836 if (cc .ge. td) goto 60
5838 ! check for circle J completely inside circle K
5840 if (cc+ther(j) .lt. therk) goto 40
5842 ! check for circles that are essentially parallel
5844 if (cc .gt. delta) goto 50
5849 ! check to see if sphere of interest is completely buried
5852 if (pix2-cc .le. td) goto 170
5858 ! find T value of circle intersections
5861 if (omit(k)) goto 110
5876 ! rotation matrix elements
5888 if (.not. omit(j)) then
5893 ! rotate spheres so K vector colinear with z-axis
5895 uxj = txj*axx + tyj*axy - tzj*axz
5896 uyj = tyj*ayy - txj*ayx
5897 uzj = txj*azx + tyj*azy + tzj*azz
5898 cosine = min(1.0d0,max(-1.0d0,uzj/b(j)))
5899 if (acos(cosine) .lt. therk+ther(j)) then
5900 dsqj = uxj*uxj + uyj*uyj
5905 tr2 = risqk*dsqj - tb*tb
5911 ! get T values of intersection for K circle
5914 tb = min(1.0d0,max(-1.0d0,tb))
5916 if (tyb-txr .lt. 0.0d0) tk1 = pix2 - tk1
5918 tb = min(1.0d0,max(-1.0d0,tb))
5920 if (tyb+txr .lt. 0.0d0) tk2 = pix2 - tk2
5921 thec = (rrsq*uzj-gk*bg(j)) / (rik*ri(j)*b(j))
5922 if (abs(thec) .lt. 1.0d0) then
5924 else if (thec .ge. 1.0d0) then
5926 else if (thec .le. -1.0d0) then
5930 ! see if "tk1" is entry or exit point; check t=0 point;
5931 ! "ti" is exit point, "tf" is entry point
5933 cosine = min(1.0d0,max(-1.0d0, &
5934 (uzj*gk-uxj*rik)/(b(j)*rr)))
5935 if ((acos(cosine)-ther(j))*(tk2-tk1) .le. 0.0d0) then
5943 if (narc .ge. maxarc) then
5945 70 format (/,' SURFATOM -- Increase the Value',&
5949 if (tf .le. ti) then
5970 ! special case; K circle without intersections
5972 if (narc .le. 0) goto 90
5974 ! general case; sum up arclength and set connectivity code
5976 call sort2 (narc,arci,key)
5981 if (narc .gt. 1) then
5984 if (t .lt. arci(j)) then
5985 arcsum = arcsum + arci(j) - t
5986 exang = exang + ex(ni)
5988 if (jb .ge. maxarc) then
5990 80 format (/,' SURFATOM -- Increase the Value',&
5995 kent(jb) = maxarc*i + k
5997 kout(jb) = maxarc*k + i
6006 arcsum = arcsum + pix2 - t
6008 exang = exang + ex(ni)
6011 kent(jb) = maxarc*i + k
6013 kout(jb) = maxarc*k + i
6020 arclen = arclen + gr(k)*arcsum
6023 if (arclen .eq. 0.0d0) goto 170
6024 if (jb .eq. 0) goto 150
6026 ! find number of independent boundaries and check connectivity
6030 if (kout(k) .ne. 0) then
6037 if (m .eq. kent(ii)) then
6040 if (j .eq. jb) goto 150
6052 ! attempt to fix connectivity error by moving atom slightly
6056 140 format (/,' SURFATOM -- Connectivity Error at Atom',i6)
6065 ! compute the exposed surface area for the sphere of interest
6068 area = ib*pix2 + exang + arclen
6069 area = mod(area,4.0d0*pi) * rrsq
6071 ! attempt to fix negative area by moving atom slightly
6073 if (area .lt. 0.0d0) then
6076 160 format (/,' SURFATOM -- Negative Area at Atom',i6)
6087 end subroutine surfatom
6088 !----------------------------------------------------------------
6089 !----------------------------------------------------------------
6090 subroutine alloc_MD_arrays
6091 !EL Allocation of arrays used by MD module
6093 integer :: nres2,nres6
6096 !----------------------
6100 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
6101 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
6102 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
6103 allocate(fricvec(nres2,nres2))
6104 allocate(pfric_mat(nres2,nres2),vfric_mat(nres2,nres2))
6105 allocate(afric_mat(nres2,nres2),prand_mat(nres2,nres2))
6106 allocate(vrand_mat1(nres2,nres2),vrand_mat2(nres2,nres2)) !(MAXRES2,MAXRES2)
6107 allocate(pfric0_mat(nres2,nres2,0:maxflag_stoch))
6108 allocate(afric0_mat(nres2,nres2,0:maxflag_stoch))
6109 allocate(vfric0_mat(nres2,nres2,0:maxflag_stoch))
6110 allocate(prand0_mat(nres2,nres2,0:maxflag_stoch))
6111 allocate(vrand0_mat1(nres2,nres2,0:maxflag_stoch))
6112 allocate(vrand0_mat2(nres2,nres2,0:maxflag_stoch)) !(MAXRES2,MAXRES2,0:maxflag_stoch)
6113 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
6115 allocate(mt1(nres2,nres2),mt2(nres2,nres2),mt3(nres2,nres2)) !(maxres2,maxres2)
6116 !----------------------
6118 ! commom.langevin.lang0
6120 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
6121 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
6122 allocate(fricvec(nres2,nres2)) !(MAXRES2,MAXRES2)
6123 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
6124 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
6127 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2))
6128 !----------------------
6129 ! commom.hairpin in CSA module
6130 !----------------------
6131 ! common.mce in MCM_MD module
6132 !----------------------
6134 ! common /mdgrad/ in module.energy
6135 ! common /back_constr/ in module.energy
6136 ! common /qmeas/ in module.energy
6139 allocate(potEcomp(0:n_ene+4)) !(0:n_ene+4)
6141 allocate(d_t(3,0:nres2),d_a(3,0:nres2),d_t_old(3,0:nres2)) !(3,0:MAXRES2)
6142 allocate(d_a_work(nres6)) !(6*MAXRES)
6144 allocate(DM(nres2),DU1(nres2),DU2(nres2))
6145 allocate(DMorig(nres2),DU1orig(nres2),DU2orig(nres2))
6147 allocate(Gmat(nres2,nres2),A(nres2,nres2))
6148 if(.not.allocated(Ginv)) allocate(Ginv(nres2,nres2)) !in control: ergastulum
6149 allocate(Gsqrp(nres2,nres2),Gsqrm(nres2,nres2),Gvec(nres2,nres2)) !(maxres2,maxres2)
6151 allocate(Geigen(nres2)) !(maxres2)
6152 if(.not.allocated(vtot)) allocate(vtot(nres2)) !(maxres2)
6153 ! common /inertia/ in io_conf: parmread
6154 ! real(kind=8),dimension(:),allocatable :: ISC,msc !(ntyp+1)
6155 ! common /langevin/in io read_MDpar
6156 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
6157 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
6158 ! in io_conf: parmread
6159 ! real(kind=8),dimension(:),allocatable :: restok !(ntyp+1)
6160 ! common /mdpmpi/ in control: ergastulum
6161 if(.not.allocated(ng_start)) allocate(ng_start(0:nfgtasks-1))
6162 if(.not.allocated(ng_counts)) allocate(ng_counts(0:nfgtasks-1))
6163 if(.not.allocated(nginv_counts)) allocate(nginv_counts(0:nfgtasks-1)) !(0:MaxProcs-1)
6164 if(.not.allocated(nginv_start)) allocate(nginv_start(0:nfgtasks)) !(0:MaxProcs)
6165 !----------------------
6166 ! common.muca in read_muca
6167 ! common /double_muca/
6168 ! real(kind=8) :: elow,ehigh,factor,hbin,factor_min
6169 ! real(kind=8),dimension(:),allocatable :: emuca,nemuca,&
6170 ! nemuca2,hist !(4*maxres)
6171 ! common /integer_muca/
6172 ! integer :: nmuca,imtime,muca_smooth
6174 ! real(kind=8),dimension(:),allocatable :: elowi,ehighi !(maxprocs)
6175 !----------------------
6177 ! common /mdgrad/ in module.energy
6178 ! common /back_constr/ in module.energy
6179 ! common /qmeas/ in module.energy
6183 allocate(d_t_work(nres6),d_t_work_new(nres6),d_af_work(nres6))
6184 allocate(d_as_work(nres6),kinetic_force(nres6)) !(MAXRES6)
6185 allocate(d_t_new(3,0:nres2),d_a_old(3,0:nres2),d_a_short(3,0:nres2)) !,d_a !(3,0:MAXRES2)
6186 allocate(stdforcp(nres),stdforcsc(nres)) !(MAXRES)
6187 !----------------------
6189 allocate(D_ban(nres6)) !(MAXRES6) maxres6=6*maxres
6190 ! common /stochcalc/ stochforcvec
6191 allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
6192 !----------------------
6194 end subroutine alloc_MD_arrays
6195 !-----------------------------------------------------------------------------
6196 !-----------------------------------------------------------------------------