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) then
998 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1.and.mnum.ne.5) then
1001 v_work(ind)=d_t(j,i+nres)
1006 write (66,'(80f10.5)') &
1007 ((d_t(j,i),j=1,3),i=0,nres-1),((d_t(j,i+nres),j=1,3),i=1,nres)
1011 v_transf(i)=v_transf(i)+gvec(j,i)*v_work(j)
1013 v_transf(i)= v_transf(i)*dsqrt(geigen(i))
1015 write (67,'(80f10.5)') (v_transf(i),i=1,ind)
1018 if (mod(itime,ntwx).eq.0) then
1020 write (tytul,'("time",f8.2)') totT
1022 call hairpin(.true.,nharp,iharp)
1023 call secondary2(.true.)
1024 call pdbout(potE,tytul,ipdb)
1029 if (rstcount.eq.1000.or.itime.eq.n_timestep) then
1030 open(irest2,file=rest2name,status='unknown')
1031 write(irest2,*) totT,EK,potE,totE,t_bath
1033 ! AL 4/17/17: Now writing d_t(0,:) too
1035 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
1037 ! AL 4/17/17: Now writing d_c(0,:) too
1039 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
1047 t_MD=MPI_Wtime()-tt0
1051 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))') &
1053 'MD calculations setup:',t_MDsetup,&
1054 'Energy & gradient evaluation:',t_enegrad,&
1055 'Stochastic MD setup:',t_langsetup,&
1056 'Stochastic MD step setup:',t_sdsetup,&
1058 write (iout,'(/28(1h=),a25,27(1h=))') &
1059 ' End of MD calculation '
1061 write (iout,*) "time for etotal",t_etotal," elong",t_elong,&
1063 write (iout,*) "time_fric",time_fric," time_stoch",time_stoch,&
1064 " time_fricmatmult",time_fricmatmult," time_fsample ",&
1069 !-----------------------------------------------------------------------------
1070 subroutine velverlet_step(itime)
1071 !-------------------------------------------------------------------------------
1072 ! Perform a single velocity Verlet step; the time step can be rescaled if
1073 ! increments in accelerations exceed the threshold
1074 !-------------------------------------------------------------------------------
1075 ! implicit real*8 (a-h,o-z)
1076 ! include 'DIMENSIONS'
1078 use control, only:tcpu
1082 integer :: ierror,ierrcode
1083 real(kind=8) :: errcode
1085 ! include 'COMMON.SETUP'
1086 ! include 'COMMON.VAR'
1087 ! include 'COMMON.MD'
1089 ! include 'COMMON.LANGEVIN'
1091 ! include 'COMMON.LANGEVIN.lang0'
1093 ! include 'COMMON.CHAIN'
1094 ! include 'COMMON.DERIV'
1095 ! include 'COMMON.GEO'
1096 ! include 'COMMON.LOCAL'
1097 ! include 'COMMON.INTERACT'
1098 ! include 'COMMON.IOUNITS'
1099 ! include 'COMMON.NAMES'
1100 ! include 'COMMON.TIME1'
1101 ! include 'COMMON.MUCA'
1102 real(kind=8),dimension(3) :: vcm,incr
1103 real(kind=8),dimension(3) :: L
1104 integer :: count,rstcount !ilen,
1106 character(len=50) :: tytul
1107 integer :: maxcount_scale = 20
1108 !el common /gucio/ cm
1109 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1110 !el common /stochcalc/ stochforcvec
1111 integer :: itime,icount_scale,itime_scal,i,j,ifac_time
1113 real(kind=8) :: epdrift,tt0,fac_time
1115 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1121 else if (lang.eq.2 .or. lang.eq.3) then
1123 call stochastic_force(stochforcvec)
1126 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1128 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1135 icount_scale=icount_scale+1
1136 if (icount_scale.gt.maxcount_scale) then
1138 "ERROR: too many attempts at scaling down the time step. ",&
1139 "amax=",amax,"epdrift=",epdrift,&
1140 "damax=",damax,"edriftmax=",edriftmax,&
1144 call MPI_Abort(MPI_COMM_WORLD,IERROR,IERRCODE)
1148 ! First step of the velocity Verlet algorithm
1153 else if (lang.eq.3) then
1155 call sd_verlet1_ciccotti
1157 else if (lang.eq.1) then
1162 ! Build the chain from the newly calculated coordinates
1163 call chainbuild_cart
1164 if (rattle) call rattle1
1166 if (large.and. mod(itime,ntwe).eq.0) then
1167 write (iout,*) "Cartesian and internal coordinates: step 1"
1172 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
1173 (dc(j,i+nres),j=1,3)
1175 write (iout,*) "Accelerations"
1177 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1178 (d_a(j,i+nres),j=1,3)
1180 write (iout,*) "Velocities, step 1"
1182 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1183 (d_t(j,i+nres),j=1,3)
1192 ! Calculate energy and forces
1194 call etotal(potEcomp)
1195 ! AL 4/17/17: Reduce the steps if NaNs occurred.
1196 if (potEcomp(0).gt.0.99e20 .or. isnan(potEcomp(0)).gt.0) then
1201 if (large.and. mod(itime,ntwe).eq.0) &
1202 call enerprint(potEcomp)
1205 t_etotal=t_etotal+MPI_Wtime()-tt0
1207 t_etotal=t_etotal+tcpu()-tt0
1210 potE=potEcomp(0)-potEcomp(20)
1212 ! Get the new accelerations
1215 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1217 t_enegrad=t_enegrad+tcpu()-tt0
1219 ! Determine maximum acceleration and scale down the timestep if needed
1221 amax=amax/(itime_scal+1)**2
1222 call predict_edrift(epdrift)
1223 if (amax/(itime_scal+1).gt.damax .or. epdrift.gt.edriftmax) then
1224 ! Maximum acceleration or maximum predicted energy drift exceeded, rescale the time step
1226 ifac_time=dmax1(dlog(amax/damax),dlog(epdrift/edriftmax)) &
1228 itime_scal=itime_scal+ifac_time
1229 ! fac_time=dmin1(damax/amax,0.5d0)
1230 fac_time=0.5d0**ifac_time
1231 d_time=d_time*fac_time
1232 if (lang.eq.2 .or. lang.eq.3) then
1234 ! write (iout,*) "Calling sd_verlet_setup: 1"
1235 ! Rescale the stochastic forces and recalculate or restore
1236 ! the matrices of tinker integrator
1237 if (itime_scal.gt.maxflag_stoch) then
1238 if (large) write (iout,'(a,i5,a)') &
1239 "Calculate matrices for stochastic step;",&
1240 " itime_scal ",itime_scal
1242 call sd_verlet_p_setup
1244 call sd_verlet_ciccotti_setup
1246 write (iout,'(2a,i3,a,i3,1h.)') &
1247 "Warning: cannot store matrices for stochastic",&
1248 " integration because the index",itime_scal,&
1249 " is greater than",maxflag_stoch
1250 write (iout,'(2a)')"Increase MAXFLAG_STOCH or use direct",&
1251 " integration Langevin algorithm for better efficiency."
1252 else if (flag_stoch(itime_scal)) then
1253 if (large) write (iout,'(a,i5,a,l1)') &
1254 "Restore matrices for stochastic step; itime_scal ",&
1255 itime_scal," flag ",flag_stoch(itime_scal)
1258 pfric_mat(i,j)=pfric0_mat(i,j,itime_scal)
1259 afric_mat(i,j)=afric0_mat(i,j,itime_scal)
1260 vfric_mat(i,j)=vfric0_mat(i,j,itime_scal)
1261 prand_mat(i,j)=prand0_mat(i,j,itime_scal)
1262 vrand_mat1(i,j)=vrand0_mat1(i,j,itime_scal)
1263 vrand_mat2(i,j)=vrand0_mat2(i,j,itime_scal)
1267 if (large) write (iout,'(2a,i5,a,l1)') &
1268 "Calculate & store matrices for stochastic step;",&
1269 " itime_scal ",itime_scal," flag ",flag_stoch(itime_scal)
1271 call sd_verlet_p_setup
1273 call sd_verlet_ciccotti_setup
1275 flag_stoch(ifac_time)=.true.
1278 pfric0_mat(i,j,itime_scal)=pfric_mat(i,j)
1279 afric0_mat(i,j,itime_scal)=afric_mat(i,j)
1280 vfric0_mat(i,j,itime_scal)=vfric_mat(i,j)
1281 prand0_mat(i,j,itime_scal)=prand_mat(i,j)
1282 vrand0_mat1(i,j,itime_scal)=vrand_mat1(i,j)
1283 vrand0_mat2(i,j,itime_scal)=vrand_mat2(i,j)
1287 fac_time=1.0d0/dsqrt(fac_time)
1289 stochforcvec(i)=fac_time*stochforcvec(i)
1292 else if (lang.eq.1) then
1293 ! Rescale the accelerations due to stochastic forces
1294 fac_time=1.0d0/dsqrt(fac_time)
1296 d_as_work(i)=d_as_work(i)*fac_time
1299 if (large) write (iout,'(a,i10,a,f8.6,a,i3,a,i3)') &
1300 "itime",itime," Timestep scaled down to ",&
1301 d_time," ifac_time",ifac_time," itime_scal",itime_scal
1303 ! Second step of the velocity Verlet algorithm
1308 else if (lang.eq.3) then
1310 call sd_verlet2_ciccotti
1312 else if (lang.eq.1) then
1317 if (rattle) call rattle2
1320 if (d_time.ne.d_time0) then
1323 if (lang.eq.2 .or. lang.eq.3) then
1324 if (large) write (iout,'(a)') &
1325 "Restore original matrices for stochastic step"
1326 ! write (iout,*) "Calling sd_verlet_setup: 2"
1327 ! Restore the matrices of tinker integrator if the time step has been restored
1330 pfric_mat(i,j)=pfric0_mat(i,j,0)
1331 afric_mat(i,j)=afric0_mat(i,j,0)
1332 vfric_mat(i,j)=vfric0_mat(i,j,0)
1333 prand_mat(i,j)=prand0_mat(i,j,0)
1334 vrand_mat1(i,j)=vrand0_mat1(i,j,0)
1335 vrand_mat2(i,j)=vrand0_mat2(i,j,0)
1344 ! Calculate the kinetic and the total energy and the kinetic temperature
1348 ! call kinetic1(EK1)
1349 ! write (iout,*) "step",itime," EK",EK," EK1",EK1
1351 ! Couple the system to Berendsen bath if needed
1352 if (tbf .and. lang.eq.0) then
1355 kinetic_T=2.0d0/(dimen3*Rb)*EK
1356 ! Backup the coordinates, velocities, and accelerations
1360 d_t_old(j,i)=d_t(j,i)
1361 d_a_old(j,i)=d_a(j,i)
1365 if (mod(itime,ntwe).eq.0 .and. large) then
1366 write (iout,*) "Velocities, step 2"
1368 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1369 (d_t(j,i+nres),j=1,3)
1374 end subroutine velverlet_step
1375 !-----------------------------------------------------------------------------
1376 subroutine RESPA_step(itime)
1377 !-------------------------------------------------------------------------------
1378 ! Perform a single RESPA step.
1379 !-------------------------------------------------------------------------------
1380 ! implicit real*8 (a-h,o-z)
1381 ! include 'DIMENSIONS'
1385 use control, only:tcpu
1387 ! use io_conf, only:cartprint
1390 integer :: IERROR,ERRCODE
1392 ! include 'COMMON.SETUP'
1393 ! include 'COMMON.CONTROL'
1394 ! include 'COMMON.VAR'
1395 ! include 'COMMON.MD'
1397 ! include 'COMMON.LANGEVIN'
1399 ! include 'COMMON.LANGEVIN.lang0'
1401 ! include 'COMMON.CHAIN'
1402 ! include 'COMMON.DERIV'
1403 ! include 'COMMON.GEO'
1404 ! include 'COMMON.LOCAL'
1405 ! include 'COMMON.INTERACT'
1406 ! include 'COMMON.IOUNITS'
1407 ! include 'COMMON.NAMES'
1408 ! include 'COMMON.TIME1'
1409 real(kind=8),dimension(0:n_ene) :: energia_short,energia_long
1410 real(kind=8),dimension(3) :: L,vcm,incr
1411 real(kind=8),dimension(3,0:2*nres) :: dc_old0,d_t_old0,d_a_old0 !(3,0:maxres2) maxres2=2*maxres
1412 logical :: PRINT_AMTS_MSG = .false.
1413 integer :: count,rstcount !ilen,
1415 character(len=50) :: tytul
1416 integer :: maxcount_scale = 10
1417 !el common /gucio/ cm
1418 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1419 !el common /stochcalc/ stochforcvec
1420 integer :: itime,itt,i,j,itsplit
1422 !el common /cipiszcze/ itt
1424 real(kind=8) :: epdrift,tt0,epdriftmax
1427 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1431 if (large.and. mod(itime,ntwe).eq.0) then
1432 write (iout,*) "***************** RESPA itime",itime
1433 write (iout,*) "Cartesian and internal coordinates: step 0"
1435 call pdbout(0.0d0,"cipiszcze",iout)
1437 write (iout,*) "Accelerations from long-range forces"
1439 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1440 (d_a(j,i+nres),j=1,3)
1442 write (iout,*) "Velocities, step 0"
1444 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1445 (d_t(j,i+nres),j=1,3)
1450 ! Perform the initial RESPA step (increment velocities)
1451 ! write (iout,*) "*********************** RESPA ini"
1454 if (mod(itime,ntwe).eq.0 .and. large) then
1455 write (iout,*) "Velocities, end"
1457 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1458 (d_t(j,i+nres),j=1,3)
1462 ! Compute the short-range forces
1468 ! 7/2/2009 commented out
1470 ! call etotal_short(energia_short)
1473 ! 7/2/2009 Copy accelerations due to short-lange forces from previous MD step
1476 d_a(j,i)=d_a_short(j,i)
1480 if (large.and. mod(itime,ntwe).eq.0) then
1481 write (iout,*) "energia_short",energia_short(0)
1482 write (iout,*) "Accelerations from short-range forces"
1484 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1485 (d_a(j,i+nres),j=1,3)
1490 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1492 t_enegrad=t_enegrad+tcpu()-tt0
1497 d_t_old(j,i)=d_t(j,i)
1498 d_a_old(j,i)=d_a(j,i)
1501 ! 6/30/08 A-MTS: attempt at increasing the split number
1504 dc_old0(j,i)=dc_old(j,i)
1505 d_t_old0(j,i)=d_t_old(j,i)
1506 d_a_old0(j,i)=d_a_old(j,i)
1509 if (ntime_split.gt.ntime_split0) ntime_split=ntime_split/2
1510 if (ntime_split.lt.ntime_split0) ntime_split=ntime_split0
1517 ! write (iout,*) "itime",itime," ntime_split",ntime_split
1518 ! Split the time step
1519 d_time=d_time0/ntime_split
1520 ! Perform the short-range RESPA steps (velocity Verlet increments of
1521 ! positions and velocities using short-range forces)
1522 ! write (iout,*) "*********************** RESPA split"
1523 do itsplit=1,ntime_split
1526 else if (lang.eq.2 .or. lang.eq.3) then
1528 call stochastic_force(stochforcvec)
1531 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1533 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1538 ! First step of the velocity Verlet algorithm
1543 else if (lang.eq.3) then
1545 call sd_verlet1_ciccotti
1547 else if (lang.eq.1) then
1552 ! Build the chain from the newly calculated coordinates
1553 call chainbuild_cart
1554 if (rattle) call rattle1
1556 if (large.and. mod(itime,ntwe).eq.0) then
1557 write (iout,*) "***** ITSPLIT",itsplit
1558 write (iout,*) "Cartesian and internal coordinates: step 1"
1559 call pdbout(0.0d0,"cipiszcze",iout)
1562 write (iout,*) "Velocities, step 1"
1564 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1565 (d_t(j,i+nres),j=1,3)
1574 ! Calculate energy and forces
1576 call etotal_short(energia_short)
1577 ! AL 4/17/17: Exit itime_split loop when energy goes infinite
1578 if (energia_short(0).gt.0.99e20 .or. isnan(energia_short(0)) ) then
1579 if (PRINT_AMTS_MSG) &
1580 write (iout,*) "Infinities/NaNs in energia_short",energia_short(0),"; increasing ntime_split to",ntime_split
1581 ntime_split=ntime_split*2
1582 if (ntime_split.gt.maxtime_split) then
1585 "Cannot rescue the run; aborting job. Retry with a smaller time step"
1587 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1590 "Cannot rescue the run; terminating. Retry with a smaller time step"
1596 if (large.and. mod(itime,ntwe).eq.0) &
1597 call enerprint(energia_short)
1600 t_eshort=t_eshort+MPI_Wtime()-tt0
1602 t_eshort=t_eshort+tcpu()-tt0
1606 ! Get the new accelerations
1608 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
1611 d_a_short(j,i)=d_a(j,i)
1615 if (large.and. mod(itime,ntwe).eq.0) then
1616 write (iout,*)"energia_short",energia_short(0)
1617 write (iout,*) "Accelerations from short-range forces"
1619 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1620 (d_a(j,i+nres),j=1,3)
1625 ! Determine maximum acceleration and scale down the timestep if needed
1627 amax=amax/ntime_split**2
1628 call predict_edrift(epdrift)
1629 if (ntwe.gt.0 .and. large .and. mod(itime,ntwe).eq.0) &
1630 write (iout,*) "amax",amax," damax",damax,&
1631 " epdrift",epdrift," epdriftmax",epdriftmax
1632 ! Exit loop and try with increased split number if the change of
1633 ! acceleration is too big
1634 if (amax.gt.damax .or. epdrift.gt.edriftmax) then
1635 if (ntime_split.lt.maxtime_split) then
1637 ntime_split=ntime_split*2
1638 ! AL 4/17/17: We should exit the itime_split loop when acceleration change is too big
1642 dc_old(j,i)=dc_old0(j,i)
1643 d_t_old(j,i)=d_t_old0(j,i)
1644 d_a_old(j,i)=d_a_old0(j,i)
1647 if (PRINT_AMTS_MSG) then
1648 write (iout,*) "acceleration/energy drift too large",amax,&
1649 epdrift," split increased to ",ntime_split," itime",itime,&
1655 "Uh-hu. Bumpy landscape. Maximum splitting number",&
1657 " already reached!!! Trying to carry on!"
1661 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1663 t_enegrad=t_enegrad+tcpu()-tt0
1665 ! Second step of the velocity Verlet algorithm
1670 else if (lang.eq.3) then
1672 call sd_verlet2_ciccotti
1674 else if (lang.eq.1) then
1679 if (rattle) call rattle2
1680 ! Backup the coordinates, velocities, and accelerations
1684 d_t_old(j,i)=d_t(j,i)
1685 d_a_old(j,i)=d_a(j,i)
1692 ! Restore the time step
1694 ! Compute long-range forces
1701 call etotal_long(energia_long)
1702 if (energia_long(0).gt.0.99e20 .or. isnan(energia_long(0))) then
1705 "Infinitied/NaNs in energia_long, Aborting MPI job."
1707 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1709 write (iout,*) "Infinitied/NaNs in energia_long, terminating."
1713 if (large.and. mod(itime,ntwe).eq.0) &
1714 call enerprint(energia_long)
1717 t_elong=t_elong+MPI_Wtime()-tt0
1719 t_elong=t_elong+tcpu()-tt0
1725 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1727 t_enegrad=t_enegrad+tcpu()-tt0
1729 ! Compute accelerations from long-range forces
1731 if (large.and. mod(itime,ntwe).eq.0) then
1732 write (iout,*) "energia_long",energia_long(0)
1733 write (iout,*) "Cartesian and internal coordinates: step 2"
1735 call pdbout(0.0d0,"cipiszcze",iout)
1737 write (iout,*) "Accelerations from long-range forces"
1739 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1740 (d_a(j,i+nres),j=1,3)
1742 write (iout,*) "Velocities, step 2"
1744 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1745 (d_t(j,i+nres),j=1,3)
1749 ! Compute the final RESPA step (increment velocities)
1750 ! write (iout,*) "*********************** RESPA fin"
1752 ! Compute the complete potential energy
1754 potEcomp(i)=energia_short(i)+energia_long(i)
1756 potE=potEcomp(0)-potEcomp(20)
1757 ! potE=energia_short(0)+energia_long(0)
1760 ! Calculate the kinetic and the total energy and the kinetic temperature
1763 ! Couple the system to Berendsen bath if needed
1764 if (tbf .and. lang.eq.0) then
1767 kinetic_T=2.0d0/(dimen3*Rb)*EK
1768 ! Backup the coordinates, velocities, and accelerations
1770 if (mod(itime,ntwe).eq.0 .and. large) then
1771 write (iout,*) "Velocities, end"
1773 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1774 (d_t(j,i+nres),j=1,3)
1779 end subroutine RESPA_step
1780 !-----------------------------------------------------------------------------
1781 subroutine RESPA_vel
1782 ! First and last RESPA step (incrementing velocities using long-range
1785 ! implicit real*8 (a-h,o-z)
1786 ! include 'DIMENSIONS'
1787 ! include 'COMMON.CONTROL'
1788 ! include 'COMMON.VAR'
1789 ! include 'COMMON.MD'
1790 ! include 'COMMON.CHAIN'
1791 ! include 'COMMON.DERIV'
1792 ! include 'COMMON.GEO'
1793 ! include 'COMMON.LOCAL'
1794 ! include 'COMMON.INTERACT'
1795 ! include 'COMMON.IOUNITS'
1796 ! include 'COMMON.NAMES'
1797 integer :: i,j,inres,mnum
1800 d_t(j,0)=d_t(j,0)+0.5d0*d_a(j,0)*d_time
1804 d_t(j,i)=d_t(j,i)+0.5d0*d_a(j,i)*d_time
1809 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1810 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1811 .and.(mnum.ne.5)) then
1814 d_t(j,inres)=d_t(j,inres)+0.5d0*d_a(j,inres)*d_time
1819 end subroutine RESPA_vel
1820 !-----------------------------------------------------------------------------
1822 ! Applying velocity Verlet algorithm - step 1 to coordinates
1824 ! implicit real*8 (a-h,o-z)
1825 ! include 'DIMENSIONS'
1826 ! include 'COMMON.CONTROL'
1827 ! include 'COMMON.VAR'
1828 ! include 'COMMON.MD'
1829 ! include 'COMMON.CHAIN'
1830 ! include 'COMMON.DERIV'
1831 ! include 'COMMON.GEO'
1832 ! include 'COMMON.LOCAL'
1833 ! include 'COMMON.INTERACT'
1834 ! include 'COMMON.IOUNITS'
1835 ! include 'COMMON.NAMES'
1836 real(kind=8) :: adt,adt2
1837 integer :: i,j,inres,mnum
1840 write (iout,*) "VELVERLET1 START: DC"
1842 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1843 (dc(j,i+nres),j=1,3)
1847 adt=d_a_old(j,0)*d_time
1849 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1850 d_t_new(j,0)=d_t_old(j,0)+adt2
1851 d_t(j,0)=d_t_old(j,0)+adt
1855 adt=d_a_old(j,i)*d_time
1857 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1858 d_t_new(j,i)=d_t_old(j,i)+adt2
1859 d_t(j,i)=d_t_old(j,i)+adt
1864 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1865 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1866 .and.(mnum.ne.5)) then
1869 adt=d_a_old(j,inres)*d_time
1871 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1872 d_t_new(j,inres)=d_t_old(j,inres)+adt2
1873 d_t(j,inres)=d_t_old(j,inres)+adt
1878 write (iout,*) "VELVERLET1 END: DC"
1880 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1881 (dc(j,i+nres),j=1,3)
1885 end subroutine verlet1
1886 !-----------------------------------------------------------------------------
1888 ! Step 2 of the velocity Verlet algorithm: update velocities
1890 ! implicit real*8 (a-h,o-z)
1891 ! include 'DIMENSIONS'
1892 ! include 'COMMON.CONTROL'
1893 ! include 'COMMON.VAR'
1894 ! include 'COMMON.MD'
1895 ! include 'COMMON.CHAIN'
1896 ! include 'COMMON.DERIV'
1897 ! include 'COMMON.GEO'
1898 ! include 'COMMON.LOCAL'
1899 ! include 'COMMON.INTERACT'
1900 ! include 'COMMON.IOUNITS'
1901 ! include 'COMMON.NAMES'
1902 integer :: i,j,inres,mnum
1905 d_t(j,0)=d_t_new(j,0)+0.5d0*d_a(j,0)*d_time
1909 d_t(j,i)=d_t_new(j,i)+0.5d0*d_a(j,i)*d_time
1914 ! iti=iabs(itype(i,mnum))
1915 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1916 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1917 .and.(mnum.ne.5)) then
1920 d_t(j,inres)=d_t_new(j,inres)+0.5d0*d_a(j,inres)*d_time
1925 end subroutine verlet2
1926 !-----------------------------------------------------------------------------
1927 subroutine sddir_precalc
1928 ! Applying velocity Verlet algorithm - step 1 to coordinates
1929 ! implicit real*8 (a-h,o-z)
1930 ! include 'DIMENSIONS'
1936 ! include 'COMMON.CONTROL'
1937 ! include 'COMMON.VAR'
1938 ! include 'COMMON.MD'
1940 ! include 'COMMON.LANGEVIN'
1942 ! include 'COMMON.LANGEVIN.lang0'
1944 ! include 'COMMON.CHAIN'
1945 ! include 'COMMON.DERIV'
1946 ! include 'COMMON.GEO'
1947 ! include 'COMMON.LOCAL'
1948 ! include 'COMMON.INTERACT'
1949 ! include 'COMMON.IOUNITS'
1950 ! include 'COMMON.NAMES'
1951 ! include 'COMMON.TIME1'
1952 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1953 !el common /stochcalc/ stochforcvec
1954 real(kind=8) :: time00
1956 ! Compute friction and stochastic forces
1961 time_fric=time_fric+MPI_Wtime()-time00
1963 call stochastic_force(stochforcvec)
1964 time_stoch=time_stoch+MPI_Wtime()-time00
1967 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
1968 ! forces (d_as_work)
1970 call ginv_mult(fric_work, d_af_work)
1971 call ginv_mult(stochforcvec, d_as_work)
1973 end subroutine sddir_precalc
1974 !-----------------------------------------------------------------------------
1975 subroutine sddir_verlet1
1976 ! Applying velocity Verlet algorithm - step 1 to velocities
1979 ! implicit real*8 (a-h,o-z)
1980 ! include 'DIMENSIONS'
1981 ! include 'COMMON.CONTROL'
1982 ! include 'COMMON.VAR'
1983 ! include 'COMMON.MD'
1985 ! include 'COMMON.LANGEVIN'
1987 ! include 'COMMON.LANGEVIN.lang0'
1989 ! include 'COMMON.CHAIN'
1990 ! include 'COMMON.DERIV'
1991 ! include 'COMMON.GEO'
1992 ! include 'COMMON.LOCAL'
1993 ! include 'COMMON.INTERACT'
1994 ! include 'COMMON.IOUNITS'
1995 ! include 'COMMON.NAMES'
1996 ! Revised 3/31/05 AL: correlation between random contributions to
1997 ! position and velocity increments included.
1998 real(kind=8) :: sqrt13 = 0.57735026918962576451d0 ! 1/sqrt(3)
1999 real(kind=8) :: adt,adt2
2000 integer :: i,j,ind,inres,mnum
2002 ! Add the contribution from BOTH friction and stochastic force to the
2003 ! coordinates, but ONLY the contribution from the friction forces to velocities
2006 adt=(d_a_old(j,0)+d_af_work(j))*d_time
2007 adt2=0.5d0*adt+sqrt13*d_as_work(j)*d_time
2008 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
2009 d_t_new(j,0)=d_t_old(j,0)+0.5d0*adt
2010 d_t(j,0)=d_t_old(j,0)+adt
2015 adt=(d_a_old(j,i)+d_af_work(ind+j))*d_time
2016 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
2017 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
2018 d_t_new(j,i)=d_t_old(j,i)+0.5d0*adt
2019 d_t(j,i)=d_t_old(j,i)+adt
2025 ! iti=iabs(itype(i,mnum))
2026 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2027 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2028 .and.(mnum.ne.5)) then
2031 adt=(d_a_old(j,inres)+d_af_work(ind+j))*d_time
2032 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
2033 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
2034 d_t_new(j,inres)=d_t_old(j,inres)+0.5d0*adt
2035 d_t(j,inres)=d_t_old(j,inres)+adt
2041 end subroutine sddir_verlet1
2042 !-----------------------------------------------------------------------------
2043 subroutine sddir_verlet2
2044 ! Calculating the adjusted velocities for accelerations
2047 ! implicit real*8 (a-h,o-z)
2048 ! include 'DIMENSIONS'
2049 ! include 'COMMON.CONTROL'
2050 ! include 'COMMON.VAR'
2051 ! include 'COMMON.MD'
2053 ! include 'COMMON.LANGEVIN'
2055 ! include 'COMMON.LANGEVIN.lang0'
2057 ! include 'COMMON.CHAIN'
2058 ! include 'COMMON.DERIV'
2059 ! include 'COMMON.GEO'
2060 ! include 'COMMON.LOCAL'
2061 ! include 'COMMON.INTERACT'
2062 ! include 'COMMON.IOUNITS'
2063 ! include 'COMMON.NAMES'
2064 real(kind=8),dimension(6*nres) :: stochforcvec,d_as_work1 !(MAXRES6) maxres6=6*maxres
2065 real(kind=8) :: cos60 = 0.5d0, sin60 = 0.86602540378443864676d0
2066 integer :: i,j,ind,inres,mnum
2067 ! Revised 3/31/05 AL: correlation between random contributions to
2068 ! position and velocity increments included.
2069 ! The correlation coefficients are calculated at low-friction limit.
2070 ! Also, friction forces are now not calculated with new velocities.
2072 ! call friction_force
2073 call stochastic_force(stochforcvec)
2075 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
2076 ! forces (d_as_work)
2078 call ginv_mult(stochforcvec, d_as_work1)
2084 d_t(j,0)=d_t_new(j,0)+(0.5d0*(d_a(j,0)+d_af_work(j)) &
2085 +sin60*d_as_work(j)+cos60*d_as_work1(j))*d_time
2090 d_t(j,i)=d_t_new(j,i)+(0.5d0*(d_a(j,i)+d_af_work(ind+j)) &
2091 +sin60*d_as_work(ind+j)+cos60*d_as_work1(ind+j))*d_time
2097 ! iti=iabs(itype(i,mnum))
2098 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2099 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2100 .and.(mnum.ne.5)) then
2103 d_t(j,inres)=d_t_new(j,inres)+(0.5d0*(d_a(j,inres) &
2104 +d_af_work(ind+j))+sin60*d_as_work(ind+j) &
2105 +cos60*d_as_work1(ind+j))*d_time
2111 end subroutine sddir_verlet2
2112 !-----------------------------------------------------------------------------
2113 subroutine max_accel
2115 ! Find the maximum difference in the accelerations of the the sites
2116 ! at the beginning and the end of the time step.
2119 ! implicit real*8 (a-h,o-z)
2120 ! include 'DIMENSIONS'
2121 ! include 'COMMON.CONTROL'
2122 ! include 'COMMON.VAR'
2123 ! include 'COMMON.MD'
2124 ! include 'COMMON.CHAIN'
2125 ! include 'COMMON.DERIV'
2126 ! include 'COMMON.GEO'
2127 ! include 'COMMON.LOCAL'
2128 ! include 'COMMON.INTERACT'
2129 ! include 'COMMON.IOUNITS'
2130 real(kind=8),dimension(3) :: aux,accel,accel_old
2131 real(kind=8) :: dacc
2135 ! aux(j)=d_a(j,0)-d_a_old(j,0)
2136 accel_old(j)=d_a_old(j,0)
2143 ! 7/3/08 changed to asymmetric difference
2145 ! accel(j)=aux(j)+0.5d0*(d_a(j,i)-d_a_old(j,i))
2146 accel_old(j)=accel_old(j)+0.5d0*d_a_old(j,i)
2147 accel(j)=accel(j)+0.5d0*d_a(j,i)
2148 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2149 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2150 dacc=dabs(accel(j)-accel_old(j))
2151 ! write (iout,*) i,dacc
2152 if (dacc.gt.amax) amax=dacc
2160 accel_old(j)=d_a_old(j,0)
2165 accel_old(j)=accel_old(j)+d_a_old(j,1)
2166 accel(j)=accel(j)+d_a(j,1)
2171 ! iti=iabs(itype(i,mnum))
2172 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2173 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2174 .and.(mnum.ne.5)) then
2176 ! accel(j)=accel(j)+d_a(j,i+nres)-d_a_old(j,i+nres)
2177 accel_old(j)=accel_old(j)+d_a_old(j,i+nres)
2178 accel(j)=accel(j)+d_a(j,i+nres)
2182 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2183 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2184 dacc=dabs(accel(j)-accel_old(j))
2185 ! write (iout,*) "side-chain",i,dacc
2186 if (dacc.gt.amax) amax=dacc
2190 accel_old(j)=accel_old(j)+d_a_old(j,i)
2191 accel(j)=accel(j)+d_a(j,i)
2192 ! aux(j)=aux(j)+d_a(j,i)-d_a_old(j,i)
2196 end subroutine max_accel
2197 !-----------------------------------------------------------------------------
2198 subroutine predict_edrift(epdrift)
2200 ! Predict the drift of the potential energy
2203 use control_data, only: lmuca
2204 ! implicit real*8 (a-h,o-z)
2205 ! include 'DIMENSIONS'
2206 ! include 'COMMON.CONTROL'
2207 ! include 'COMMON.VAR'
2208 ! include 'COMMON.MD'
2209 ! include 'COMMON.CHAIN'
2210 ! include 'COMMON.DERIV'
2211 ! include 'COMMON.GEO'
2212 ! include 'COMMON.LOCAL'
2213 ! include 'COMMON.INTERACT'
2214 ! include 'COMMON.IOUNITS'
2215 ! include 'COMMON.MUCA'
2216 real(kind=8) :: epdrift,epdriftij
2218 ! Drift of the potential energy
2224 epdriftij=dabs((d_a(j,i)-d_a_old(j,i))*gcart(j,i))
2225 if (lmuca) epdriftij=epdriftij*factor
2226 ! write (iout,*) "back",i,j,epdriftij
2227 if (epdriftij.gt.epdrift) epdrift=epdriftij
2231 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1.and.&
2232 molnum(i).ne.5) then
2235 dabs((d_a(j,i+nres)-d_a_old(j,i+nres))*gxcart(j,i))
2236 if (lmuca) epdriftij=epdriftij*factor
2237 ! write (iout,*) "side",i,j,epdriftij
2238 if (epdriftij.gt.epdrift) epdrift=epdriftij
2242 epdrift=0.5d0*epdrift*d_time*d_time
2243 ! write (iout,*) "epdrift",epdrift
2245 end subroutine predict_edrift
2246 !-----------------------------------------------------------------------------
2247 subroutine verlet_bath
2249 ! Coupling to the thermostat by using the Berendsen algorithm
2252 ! implicit real*8 (a-h,o-z)
2253 ! include 'DIMENSIONS'
2254 ! include 'COMMON.CONTROL'
2255 ! include 'COMMON.VAR'
2256 ! include 'COMMON.MD'
2257 ! include 'COMMON.CHAIN'
2258 ! include 'COMMON.DERIV'
2259 ! include 'COMMON.GEO'
2260 ! include 'COMMON.LOCAL'
2261 ! include 'COMMON.INTERACT'
2262 ! include 'COMMON.IOUNITS'
2263 ! include 'COMMON.NAMES'
2264 real(kind=8) :: T_half,fact
2265 integer :: i,j,inres,mnum
2267 T_half=2.0d0/(dimen3*Rb)*EK
2268 fact=dsqrt(1.0d0+(d_time/tau_bath)*(t_bath/T_half-1.0d0))
2269 ! write(iout,*) "T_half", T_half
2270 ! write(iout,*) "EK", EK
2271 ! write(iout,*) "fact", fact
2273 d_t(j,0)=fact*d_t(j,0)
2277 d_t(j,i)=fact*d_t(j,i)
2282 ! iti=iabs(itype(i,mnum))
2283 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2284 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2285 .and.(mnum.ne.5)) then
2288 d_t(j,inres)=fact*d_t(j,inres)
2293 end subroutine verlet_bath
2294 !-----------------------------------------------------------------------------
2296 ! Set up the initial conditions of a MD simulation
2299 use control, only:tcpu
2300 !el use io_basic, only:ilen
2303 use minimm, only:minim_dc,minimize,sc_move
2304 use io_config, only:readrst
2305 use io, only:statout
2306 ! implicit real*8 (a-h,o-z)
2307 ! include 'DIMENSIONS'
2310 character(len=16) :: form
2311 integer :: IERROR,ERRCODE
2313 ! include 'COMMON.SETUP'
2314 ! include 'COMMON.CONTROL'
2315 ! include 'COMMON.VAR'
2316 ! include 'COMMON.MD'
2318 ! include 'COMMON.LANGEVIN'
2320 ! include 'COMMON.LANGEVIN.lang0'
2322 ! include 'COMMON.CHAIN'
2323 ! include 'COMMON.DERIV'
2324 ! include 'COMMON.GEO'
2325 ! include 'COMMON.LOCAL'
2326 ! include 'COMMON.INTERACT'
2327 ! include 'COMMON.IOUNITS'
2328 ! include 'COMMON.NAMES'
2329 ! include 'COMMON.REMD'
2330 real(kind=8),dimension(0:n_ene) :: energia_long,energia_short
2331 real(kind=8),dimension(3) :: vcm,incr,L
2332 real(kind=8) :: xv,sigv,lowb,highb
2333 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
2334 character(len=256) :: qstr
2337 character(len=50) :: tytul
2338 logical :: file_exist
2339 !el common /gucio/ cm
2340 integer :: i,j,ipos,iq,iw,nft_sc,iretcode,nfun,itime,ierr,mnum
2341 real(kind=8) :: etot,tt0
2345 ! write(iout,*) "d_time", d_time
2346 ! Compute the standard deviations of stochastic forces for Langevin dynamics
2347 ! if the friction coefficients do not depend on surface area
2348 if (lang.gt.0 .and. .not.surfarea) then
2351 stdforcp(i)=stdfp(mnum)*dsqrt(gamp(mnum))
2355 stdforcsc(i)=stdfsc(iabs(itype(i,mnum)),mnum) &
2356 *dsqrt(gamsc(iabs(itype(i,mnum)),mnum))
2359 ! Open the pdb file for snapshotshots
2362 if (ilen(tmpdir).gt.0) &
2363 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2364 liczba(:ilen(liczba))//".pdb")
2366 file=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2370 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2371 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2372 liczba(:ilen(liczba))//".x")
2373 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2376 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2377 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2378 liczba(:ilen(liczba))//".cx")
2379 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2385 if (ilen(tmpdir).gt.0) &
2386 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.pdb")
2387 open(ipdb,file=prefix(:ilen(prefix))//"_MD.pdb")
2389 if (ilen(tmpdir).gt.0) &
2390 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.cx")
2391 cartname=prefix(:ilen(prefix))//"_MD.cx"
2395 write (qstr,'(256(1h ))')
2398 iq = qinfrag(i,iset)*10
2399 iw = wfrag(i,iset)/100
2401 if(me.eq.king.or..not.out1file) &
2402 write (iout,*) "Frag",qinfrag(i,iset),wfrag(i,iset),iq,iw
2403 write (qstr(ipos:ipos+6),'(2h_f,i1,1h_,i1,1h_,i1)') i,iq,iw
2408 iq = qinpair(i,iset)*10
2409 iw = wpair(i,iset)/100
2411 if(me.eq.king.or..not.out1file) &
2412 write (iout,*) "Pair",i,qinpair(i,iset),wpair(i,iset),iq,iw
2413 write (qstr(ipos:ipos+6),'(2h_p,i1,1h_,i1,1h_,i1)') i,iq,iw
2417 ! pdbname=pdbname(:ilen(pdbname)-4)//qstr(:ipos-1)//'.pdb'
2419 ! cartname=cartname(:ilen(cartname)-2)//qstr(:ipos-1)//'.x'
2421 ! cartname=cartname(:ilen(cartname)-3)//qstr(:ipos-1)//'.cx'
2423 ! statname=statname(:ilen(statname)-5)//qstr(:ipos-1)//'.stat'
2427 if (restart1file) then
2429 inquire(file=mremd_rst_name,exist=file_exist)
2430 write (*,*) me," Before broadcast: file_exist",file_exist
2432 call MPI_Bcast(file_exist,1,MPI_LOGICAL,king,CG_COMM,&
2435 write (*,*) me," After broadcast: file_exist",file_exist
2436 ! inquire(file=mremd_rst_name,exist=file_exist)
2437 if(me.eq.king.or..not.out1file) &
2438 write(iout,*) "Initial state read by master and distributed"
2440 if (ilen(tmpdir).gt.0) &
2441 call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_' &
2442 //liczba(:ilen(liczba))//'.rst')
2443 inquire(file=rest2name,exist=file_exist)
2446 if(.not.restart1file) then
2447 if(me.eq.king.or..not.out1file) &
2448 write(iout,*) "Initial state will be read from file ",&
2449 rest2name(:ilen(rest2name))
2452 call rescale_weights(t_bath)
2454 if(me.eq.king.or..not.out1file)then
2455 if (restart1file) then
2456 write(iout,*) "File ",mremd_rst_name(:ilen(mremd_rst_name)),&
2459 write(iout,*) "File ",rest2name(:ilen(rest2name)),&
2462 write(iout,*) "Initial velocities randomly generated"
2469 ! Generate initial velocities
2470 if(me.eq.king.or..not.out1file) &
2471 write(iout,*) "Initial velocities randomly generated"
2476 ! rest2name = prefix(:ilen(prefix))//'.rst'
2477 if(me.eq.king.or..not.out1file)then
2478 write (iout,*) "Initial velocities"
2480 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2481 (d_t(j,i+nres),j=1,3)
2483 ! Zeroing the total angular momentum of the system
2484 write(iout,*) "Calling the zero-angular momentum subroutine"
2487 ! Getting the potential energy and forces and velocities and accelerations
2489 ! write (iout,*) "velocity of the center of the mass:"
2490 ! write (iout,*) (vcm(j),j=1,3)
2492 d_t(j,0)=d_t(j,0)-vcm(j)
2494 ! Removing the velocity of the center of mass
2496 if(me.eq.king.or..not.out1file)then
2497 write (iout,*) "vcm right after adjustment:"
2498 write (iout,*) (vcm(j),j=1,3)
2500 if ((.not.rest).and.(indpdb.eq.0)) then
2502 if(iranconf.ne.0) then
2504 print *, 'Calling OVERLAP_SC'
2505 call overlap_sc(fail)
2508 call sc_move(2,nres-1,10,1d10,nft_sc,etot)
2509 print *,'SC_move',nft_sc,etot
2510 if(me.eq.king.or..not.out1file) &
2511 write(iout,*) 'SC_move',nft_sc,etot
2515 print *, 'Calling MINIM_DC'
2516 call minim_dc(etot,iretcode,nfun)
2518 call geom_to_var(nvar,varia)
2519 print *,'Calling MINIMIZE.'
2520 call minimize(etot,varia,iretcode,nfun)
2521 call var_to_geom(nvar,varia)
2523 if(me.eq.king.or..not.out1file) &
2524 write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
2527 call chainbuild_cart
2532 kinetic_T=2.0d0/(dimen3*Rb)*EK
2533 if(me.eq.king.or..not.out1file)then
2543 call etotal(potEcomp)
2544 if (large) call enerprint(potEcomp)
2547 t_etotal=t_etotal+MPI_Wtime()-tt0
2549 t_etotal=t_etotal+tcpu()-tt0
2556 if (amax*d_time .gt. dvmax) then
2557 d_time=d_time*dvmax/amax
2558 if(me.eq.king.or..not.out1file) write (iout,*) &
2559 "Time step reduced to",d_time,&
2560 " because of too large initial acceleration."
2562 if(me.eq.king.or..not.out1file)then
2563 write(iout,*) "Potential energy and its components"
2564 call enerprint(potEcomp)
2565 ! write(iout,*) (potEcomp(i),i=0,n_ene)
2567 potE=potEcomp(0)-potEcomp(20)
2570 if (ntwe.ne.0) call statout(itime)
2571 if(me.eq.king.or..not.out1file) &
2572 write (iout,'(/a/3(a25,1pe14.5/))') "Initial:", &
2573 " Kinetic energy",EK," Potential energy",potE, &
2574 " Total energy",totE," Maximum acceleration ", &
2577 write (iout,*) "Initial coordinates"
2579 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(c(j,i),j=1,3),&
2582 write (iout,*) "Initial dC"
2584 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
2585 (dc(j,i+nres),j=1,3)
2587 write (iout,*) "Initial velocities"
2588 write (iout,"(13x,' backbone ',23x,' side chain')")
2590 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2591 (d_t(j,i+nres),j=1,3)
2593 write (iout,*) "Initial accelerations"
2595 ! write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
2596 write (iout,'(i3,3f15.10,3x,3f15.10)') i,(d_a(j,i),j=1,3),&
2597 (d_a(j,i+nres),j=1,3)
2603 d_t_old(j,i)=d_t(j,i)
2604 d_a_old(j,i)=d_a(j,i)
2606 ! write (iout,*) "dc_old",i,(dc_old(j,i),j=1,3)
2615 call etotal_short(energia_short)
2616 if (large) call enerprint(potEcomp)
2619 t_eshort=t_eshort+MPI_Wtime()-tt0
2621 t_eshort=t_eshort+tcpu()-tt0
2626 if(.not.out1file .and. large) then
2627 write (iout,*) "energia_long",energia_long(0),&
2628 " energia_short",energia_short(0),&
2629 " total",energia_long(0)+energia_short(0)
2630 write (iout,*) "Initial fast-force accelerations"
2632 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2633 (d_a(j,i+nres),j=1,3)
2636 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
2639 d_a_short(j,i)=d_a(j,i)
2648 call etotal_long(energia_long)
2649 if (large) call enerprint(potEcomp)
2652 t_elong=t_elong+MPI_Wtime()-tt0
2654 t_elong=t_elong+tcpu()-tt0
2659 if(.not.out1file .and. large) then
2660 write (iout,*) "energia_long",energia_long(0)
2661 write (iout,*) "Initial slow-force accelerations"
2663 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2664 (d_a(j,i+nres),j=1,3)
2668 t_enegrad=t_enegrad+MPI_Wtime()-tt0
2670 t_enegrad=t_enegrad+tcpu()-tt0
2674 end subroutine init_MD
2675 !-----------------------------------------------------------------------------
2676 subroutine random_vel
2678 ! implicit real*8 (a-h,o-z)
2680 use random, only:anorm_distr
2682 ! include 'DIMENSIONS'
2683 ! include 'COMMON.CONTROL'
2684 ! include 'COMMON.VAR'
2685 ! include 'COMMON.MD'
2687 ! include 'COMMON.LANGEVIN'
2689 ! include 'COMMON.LANGEVIN.lang0'
2691 ! include 'COMMON.CHAIN'
2692 ! include 'COMMON.DERIV'
2693 ! include 'COMMON.GEO'
2694 ! include 'COMMON.LOCAL'
2695 ! include 'COMMON.INTERACT'
2696 ! include 'COMMON.IOUNITS'
2697 ! include 'COMMON.NAMES'
2698 ! include 'COMMON.TIME1'
2699 real(kind=8) :: xv,sigv,lowb,highb ,Ek1
2701 real(kind=8) ,allocatable, dimension(:) :: DDU1,DDU2,DL2,DL1,xsolv,DML,rs
2702 real(kind=8) :: sumx
2704 real(kind=8) ,allocatable, dimension(:) :: rsold
2705 real (kind=8),allocatable,dimension(:,:) :: matold
2708 integer :: i,j,ii,k,ind,mark,imark,mnum
2709 ! Generate random velocities from Gaussian distribution of mean 0 and std of KT/m
2710 ! First generate velocities in the eigenspace of the G matrix
2711 ! write (iout,*) "Calling random_vel dimen dimen3",dimen,dimen3
2718 sigv=dsqrt((Rb*t_bath)/geigen(i))
2721 d_t_work_new(ii)=anorm_distr(xv,sigv,lowb,highb)
2723 write (iout,*) "i",i," ii",ii," geigen",geigen(i),&
2724 " d_t_work_new",d_t_work_new(ii)
2735 Ek1=Ek1+0.5d0*geigen(i)*d_t_work_new(ii)**2
2738 write (iout,*) "Ek from eigenvectors",Ek1
2739 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2743 ! Transform velocities to UNRES coordinate space
2744 allocate (DL1(2*nres))
2745 allocate (DDU1(2*nres))
2746 allocate (DL2(2*nres))
2747 allocate (DDU2(2*nres))
2748 allocate (xsolv(2*nres))
2749 allocate (DML(2*nres))
2750 allocate (rs(2*nres))
2752 allocate (rsold(2*nres))
2753 allocate (matold(2*nres,2*nres))
2755 matold(1,1)=DMorig(1)
2756 matold(1,2)=DU1orig(1)
2757 matold(1,3)=DU2orig(1)
2758 write (*,*) DMorig(1),DU1orig(1),DU2orig(1)
2763 matold(i,j)=DMorig(i)
2764 matold(i,j-1)=DU1orig(i-1)
2766 matold(i,j-2)=DU2orig(i-2)
2774 matold(i,j+1)=DU1orig(i)
2780 matold(i,j+2)=DU2orig(i)
2784 matold(dimen,dimen)=DMorig(dimen)
2785 matold(dimen,dimen-1)=DU1orig(dimen-1)
2786 matold(dimen,dimen-2)=DU2orig(dimen-2)
2787 write(iout,*) "old gmatrix"
2788 call matout(dimen,dimen,2*nres,2*nres,matold)
2792 ! Find the ith eigenvector of the pentadiagonal inertiq matrix
2796 DML(j)=DMorig(j)-geigen(i)
2799 DML(j-1)=DMorig(j)-geigen(i)
2804 DDU1(imark-1)=DU2orig(imark-1)
2805 do j=imark+1,dimen-1
2806 DDU1(j-1)=DU1orig(j)
2814 DDU2(j)=DU2orig(j+1)
2823 write (iout,*) "DL2,DL1,DML,DDU1,DDU2"
2824 write(iout,'(10f10.5)') (DL2(k),k=3,dimen-1)
2825 write(iout,'(10f10.5)') (DL1(k),k=2,dimen-1)
2826 write(iout,'(10f10.5)') (DML(k),k=1,dimen-1)
2827 write(iout,'(10f10.5)') (DDU1(k),k=1,dimen-2)
2828 write(iout,'(10f10.5)') (DDU2(k),k=1,dimen-3)
2831 if (imark.gt.2) rs(imark-2)=-DU2orig(imark-2)
2832 if (imark.gt.1) rs(imark-1)=-DU1orig(imark-1)
2833 if (imark.lt.dimen) rs(imark)=-DU1orig(imark)
2834 if (imark.lt.dimen-1) rs(imark+1)=-DU2orig(imark)
2838 ! write (iout,*) "Vector rs"
2840 ! write (iout,*) j,rs(j)
2843 call FDIAG(dimen-1,DL2,DL1,DML,DDU1,DDU2,rs,xsolv,mark)
2850 sumx=-geigen(i)*xsolv(j)
2852 sumx=sumx+matold(j,k)*xsolv(k)
2855 sumx=sumx+matold(j,k)*xsolv(k-1)
2857 write(iout,'(i5,3f10.5)') j,sumx,rsold(j),sumx-rsold(j)
2860 sumx=-geigen(i)*xsolv(j-1)
2862 sumx=sumx+matold(j,k)*xsolv(k)
2865 sumx=sumx+matold(j,k)*xsolv(k-1)
2867 write(iout,'(i5,3f10.5)') j-1,sumx,rsold(j-1),sumx-rsold(j-1)
2871 "Solution of equations system",i," for eigenvalue",geigen(i)
2873 write(iout,'(i5,f10.5)') j,xsolv(j)
2876 do j=dimen-1,imark,-1
2881 write (iout,*) "Un-normalized eigenvector",i," for eigenvalue",geigen(i)
2883 write(iout,'(i5,f10.5)') j,xsolv(j)
2886 ! Normalize ith eigenvector
2889 sumx=sumx+xsolv(j)**2
2893 xsolv(j)=xsolv(j)/sumx
2896 write (iout,*) "Eigenvector",i," for eigenvalue",geigen(i)
2898 write(iout,'(i5,3f10.5)') j,xsolv(j)
2901 ! All done at this point for eigenvector i, exit loop
2909 write (iout,*) "Unable to find eigenvector",i
2912 ! write (iout,*) "i=",i
2914 ! write (iout,*) "k=",k
2917 ! write(iout,*) "ind",ind," ind1",3*(i-1)+k
2918 d_t_work(ind)=d_t_work(ind) &
2919 +xsolv(j)*d_t_work_new(3*(i-1)+k)
2922 enddo ! i (loop over the eigenvectors)
2925 write (iout,*) "d_t_work"
2927 write (iout,"(i5,f10.5)") i,d_t_work(i)
2932 ! if (itype(i,1).eq.10) then
2934 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
2935 iti=iabs(itype(i,mnum))
2936 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2937 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
2938 .or.(mnum.eq.5)) then
2945 ! write (iout,*) "k",k," ii+k",ii+k," ii+j+k",ii+j+k,"EK1",Ek1
2946 Ek1=Ek1+0.5d0*mp(mnum)*((d_t_work(ii+j+k)+d_t_work_new(ii+k))/2)**2+&
2947 0.5d0*0.25d0*IP(mnum)*(d_t_work(ii+j+k)-d_t_work_new(ii+k))**2
2950 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2951 .and.(mnum.ne.5)) ii=ii+3
2952 write (iout,*) "i",i," itype",itype(i,mnum)," mass",msc(itype(i,mnum),mnum)
2953 write (iout,*) "ii",ii
2956 write (iout,*) "k",k," ii",ii,"EK1",EK1
2957 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2959 Ek1=Ek1+0.5d0*Isc(iabs(itype(i,mnum),mnum))*(d_t_work(ii)-d_t_work(ii-3))**2
2960 Ek1=Ek1+0.5d0*msc(iabs(itype(i,mnum)),mnum)*d_t_work(ii)**2
2962 write (iout,*) "i",i," ii",ii
2964 write (iout,*) "Ek from d_t_work",Ek1
2965 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2981 d_t(k,j)=d_t_work(ind)
2985 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2988 d_t(k,j+nres)=d_t_work(ind)
2994 write (iout,*) "Random velocities in the Calpha,SC space"
2996 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
2999 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
3006 ! if (itype(i,1).eq.10) then
3008 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
3011 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
3015 d_t(j,i+nres)=d_t(j,i+nres)-d_t(j,i)
3016 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
3021 write (iout,*)"Random velocities in the virtual-bond-vector space"
3023 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
3026 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
3029 write (iout,*) "Ek from d_t_work",Ek1
3030 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
3038 d_t_work(ind)=d_t_work(ind) &
3039 +Gvec(i,j)*d_t_work_new((j-1)*3+k+1)
3041 ! write (iout,*) "i",i," ind",ind," d_t_work",d_t_work(ind)
3045 ! Transfer to the d_t vector
3047 d_t(j,0)=d_t_work(j)
3053 d_t(j,i)=d_t_work(ind)
3058 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3059 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3060 .and.(mnum.ne.5)) then
3063 d_t(j,i+nres)=d_t_work(ind)
3069 ! write (iout,*) "Kinetic energy",Ek,EK1," kinetic temperature",&
3070 ! 2.0d0/(dimen3*Rb)*EK,2.0d0/(dimen3*Rb)*EK1
3074 end subroutine random_vel
3075 !-----------------------------------------------------------------------------
3077 subroutine sd_verlet_p_setup
3078 ! Sets up the parameters of stochastic Verlet algorithm
3079 ! implicit real*8 (a-h,o-z)
3080 ! include 'DIMENSIONS'
3081 use control, only: tcpu
3086 ! include 'COMMON.CONTROL'
3087 ! include 'COMMON.VAR'
3088 ! include 'COMMON.MD'
3090 ! include 'COMMON.LANGEVIN'
3092 ! include 'COMMON.LANGEVIN.lang0'
3094 ! include 'COMMON.CHAIN'
3095 ! include 'COMMON.DERIV'
3096 ! include 'COMMON.GEO'
3097 ! include 'COMMON.LOCAL'
3098 ! include 'COMMON.INTERACT'
3099 ! include 'COMMON.IOUNITS'
3100 ! include 'COMMON.NAMES'
3101 ! include 'COMMON.TIME1'
3102 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3103 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3104 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3105 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3106 logical :: lprn = .false.
3107 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3108 real(kind=8) :: ktm,gdt,egdt,gdt2,gdt3,gdt4,gdt5,gdt6,gdt7,gdt8,&
3110 integer :: i,maxres2
3117 ! AL 8/17/04 Code adapted from tinker
3119 ! Get the frictional and random terms for stochastic dynamics in the
3120 ! eigenspace of mass-scaled UNRES friction matrix
3124 gdt = fricgam(i) * d_time
3126 ! Stochastic dynamics reduces to simple MD for zero friction
3128 if (gdt .le. zero) then
3129 pfric_vec(i) = 1.0d0
3130 vfric_vec(i) = d_time
3131 afric_vec(i) = 0.5d0 * d_time * d_time
3132 prand_vec(i) = 0.0d0
3133 vrand_vec1(i) = 0.0d0
3134 vrand_vec2(i) = 0.0d0
3136 ! Analytical expressions when friction coefficient is large
3139 if (gdt .ge. gdt_radius) then
3142 vfric_vec(i) = (1.0d0-egdt) / fricgam(i)
3143 afric_vec(i) = (d_time-vfric_vec(i)) / fricgam(i)
3144 pterm = 2.0d0*gdt - 3.0d0 + (4.0d0-egdt)*egdt
3145 vterm = 1.0d0 - egdt**2
3146 rho = (1.0d0-egdt)**2 / sqrt(pterm*vterm)
3148 ! Use series expansions when friction coefficient is small
3159 afric_vec(i) = (gdt2/2.0d0 - gdt3/6.0d0 + gdt4/24.0d0 &
3160 - gdt5/120.0d0 + gdt6/720.0d0 &
3161 - gdt7/5040.0d0 + gdt8/40320.0d0 &
3162 - gdt9/362880.0d0) / fricgam(i)**2
3163 vfric_vec(i) = d_time - fricgam(i)*afric_vec(i)
3164 pfric_vec(i) = 1.0d0 - fricgam(i)*vfric_vec(i)
3165 pterm = 2.0d0*gdt3/3.0d0 - gdt4/2.0d0 &
3166 + 7.0d0*gdt5/30.0d0 - gdt6/12.0d0 &
3167 + 31.0d0*gdt7/1260.0d0 - gdt8/160.0d0 &
3168 + 127.0d0*gdt9/90720.0d0
3169 vterm = 2.0d0*gdt - 2.0d0*gdt2 + 4.0d0*gdt3/3.0d0 &
3170 - 2.0d0*gdt4/3.0d0 + 4.0d0*gdt5/15.0d0 &
3171 - 4.0d0*gdt6/45.0d0 + 8.0d0*gdt7/315.0d0 &
3172 - 2.0d0*gdt8/315.0d0 + 4.0d0*gdt9/2835.0d0
3173 rho = sqrt(3.0d0) * (0.5d0 - 3.0d0*gdt/16.0d0 &
3174 - 17.0d0*gdt2/1280.0d0 &
3175 + 17.0d0*gdt3/6144.0d0 &
3176 + 40967.0d0*gdt4/34406400.0d0 &
3177 - 57203.0d0*gdt5/275251200.0d0 &
3178 - 1429487.0d0*gdt6/13212057600.0d0)
3181 ! Compute the scaling factors of random terms for the nonzero friction case
3183 ktm = 0.5d0*d_time/fricgam(i)
3184 psig = dsqrt(ktm*pterm) / fricgam(i)
3185 vsig = dsqrt(ktm*vterm)
3186 rhoc = dsqrt(1.0d0 - rho*rho)
3188 vrand_vec1(i) = vsig * rho
3189 vrand_vec2(i) = vsig * rhoc
3194 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3197 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3198 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3202 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3205 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3206 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3207 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3208 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3209 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec1,vrand_mat1)
3210 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3213 t_sdsetup=t_sdsetup+MPI_Wtime()
3215 t_sdsetup=t_sdsetup+tcpu()-tt0
3218 end subroutine sd_verlet_p_setup
3219 !-----------------------------------------------------------------------------
3220 subroutine eigtransf1(n,ndim,ab,d,c)
3224 real(kind=8) :: ab(ndim,ndim,n),c(ndim,n),d(ndim)
3230 c(i,j)=c(i,j)+ab(k,j,i)*d(k)
3235 end subroutine eigtransf1
3236 !-----------------------------------------------------------------------------
3237 subroutine eigtransf(n,ndim,a,b,d,c)
3241 real(kind=8) :: a(ndim,n),b(ndim,n),c(ndim,n),d(ndim)
3247 c(i,j)=c(i,j)+a(i,k)*b(k,j)*d(k)
3252 end subroutine eigtransf
3253 !-----------------------------------------------------------------------------
3254 subroutine sd_verlet1
3256 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3258 ! implicit real*8 (a-h,o-z)
3259 ! include 'DIMENSIONS'
3260 ! include 'COMMON.CONTROL'
3261 ! include 'COMMON.VAR'
3262 ! include 'COMMON.MD'
3264 ! include 'COMMON.LANGEVIN'
3266 ! include 'COMMON.LANGEVIN.lang0'
3268 ! include 'COMMON.CHAIN'
3269 ! include 'COMMON.DERIV'
3270 ! include 'COMMON.GEO'
3271 ! include 'COMMON.LOCAL'
3272 ! include 'COMMON.INTERACT'
3273 ! include 'COMMON.IOUNITS'
3274 ! include 'COMMON.NAMES'
3275 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3276 !el common /stochcalc/ stochforcvec
3277 logical :: lprn = .false.
3278 real(kind=8) :: ddt1,ddt2
3279 integer :: i,j,ind,inres
3281 ! write (iout,*) "dc_old"
3283 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3284 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3287 dc_work(j)=dc_old(j,0)
3288 d_t_work(j)=d_t_old(j,0)
3289 d_a_work(j)=d_a_old(j,0)
3294 dc_work(ind+j)=dc_old(j,i)
3295 d_t_work(ind+j)=d_t_old(j,i)
3296 d_a_work(ind+j)=d_a_old(j,i)
3302 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3303 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3304 .and.(mnum.ne.5)) then
3306 dc_work(ind+j)=dc_old(j,i+nres)
3307 d_t_work(ind+j)=d_t_old(j,i+nres)
3308 d_a_work(ind+j)=d_a_old(j,i+nres)
3316 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3320 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3321 vfric_mat(i,j),afric_mat(i,j),&
3322 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3330 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3331 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3332 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3333 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3335 d_t_work_new(i)=ddt1+0.5d0*ddt2
3336 d_t_work(i)=ddt1+ddt2
3341 d_t(j,0)=d_t_work(j)
3346 dc(j,i)=dc_work(ind+j)
3347 d_t(j,i)=d_t_work(ind+j)
3353 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3354 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3355 .and.(mnum.ne.5)) then
3358 dc(j,inres)=dc_work(ind+j)
3359 d_t(j,inres)=d_t_work(ind+j)
3365 end subroutine sd_verlet1
3366 !-----------------------------------------------------------------------------
3367 subroutine sd_verlet2
3369 ! Calculating the adjusted velocities for accelerations
3371 ! implicit real*8 (a-h,o-z)
3372 ! include 'DIMENSIONS'
3373 ! include 'COMMON.CONTROL'
3374 ! include 'COMMON.VAR'
3375 ! include 'COMMON.MD'
3377 ! include 'COMMON.LANGEVIN'
3379 ! include 'COMMON.LANGEVIN.lang0'
3381 ! include 'COMMON.CHAIN'
3382 ! include 'COMMON.DERIV'
3383 ! include 'COMMON.GEO'
3384 ! include 'COMMON.LOCAL'
3385 ! include 'COMMON.INTERACT'
3386 ! include 'COMMON.IOUNITS'
3387 ! include 'COMMON.NAMES'
3388 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3389 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3390 !el common /stochcalc/ stochforcvec
3392 real(kind=8) :: ddt1,ddt2
3393 integer :: i,j,ind,inres
3394 ! Compute the stochastic forces which contribute to velocity change
3396 call stochastic_force(stochforcvecV)
3403 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3404 ddt2=ddt2+vrand_mat1(i,j)*stochforcvec(j)+ &
3405 vrand_mat2(i,j)*stochforcvecV(j)
3407 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3411 d_t(j,0)=d_t_work(j)
3416 d_t(j,i)=d_t_work(ind+j)
3422 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3423 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3424 .and.(mnum.ne.5)) then
3427 d_t(j,inres)=d_t_work(ind+j)
3433 end subroutine sd_verlet2
3434 !-----------------------------------------------------------------------------
3435 subroutine sd_verlet_ciccotti_setup
3437 ! Sets up the parameters of stochastic velocity Verlet algorithmi; Ciccotti's
3439 ! implicit real*8 (a-h,o-z)
3440 ! include 'DIMENSIONS'
3441 use control, only: tcpu
3446 ! include 'COMMON.CONTROL'
3447 ! include 'COMMON.VAR'
3448 ! include 'COMMON.MD'
3450 ! include 'COMMON.LANGEVIN'
3452 ! include 'COMMON.LANGEVIN.lang0'
3454 ! include 'COMMON.CHAIN'
3455 ! include 'COMMON.DERIV'
3456 ! include 'COMMON.GEO'
3457 ! include 'COMMON.LOCAL'
3458 ! include 'COMMON.INTERACT'
3459 ! include 'COMMON.IOUNITS'
3460 ! include 'COMMON.NAMES'
3461 ! include 'COMMON.TIME1'
3462 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3463 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3464 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3465 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3466 logical :: lprn = .false.
3467 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3468 real(kind=8) :: ktm,gdt,egdt,tt0
3469 integer :: i,maxres2
3476 ! AL 8/17/04 Code adapted from tinker
3478 ! Get the frictional and random terms for stochastic dynamics in the
3479 ! eigenspace of mass-scaled UNRES friction matrix
3483 write (iout,*) "i",i," fricgam",fricgam(i)
3484 gdt = fricgam(i) * d_time
3486 ! Stochastic dynamics reduces to simple MD for zero friction
3488 if (gdt .le. zero) then
3489 pfric_vec(i) = 1.0d0
3490 vfric_vec(i) = d_time
3491 afric_vec(i) = 0.5d0*d_time*d_time
3492 prand_vec(i) = afric_vec(i)
3493 vrand_vec2(i) = vfric_vec(i)
3495 ! Analytical expressions when friction coefficient is large
3500 vfric_vec(i) = dexp(-0.5d0*gdt)*d_time
3501 afric_vec(i) = 0.5d0*dexp(-0.25d0*gdt)*d_time*d_time
3502 prand_vec(i) = afric_vec(i)
3503 vrand_vec2(i) = vfric_vec(i)
3505 ! Compute the scaling factors of random terms for the nonzero friction case
3507 ! ktm = 0.5d0*d_time/fricgam(i)
3508 ! psig = dsqrt(ktm*pterm) / fricgam(i)
3509 ! vsig = dsqrt(ktm*vterm)
3510 ! prand_vec(i) = psig*afric_vec(i)
3511 ! vrand_vec2(i) = vsig*vfric_vec(i)
3516 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3519 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3520 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3524 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3526 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3527 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3528 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3529 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3530 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3532 t_sdsetup=t_sdsetup+MPI_Wtime()
3534 t_sdsetup=t_sdsetup+tcpu()-tt0
3537 end subroutine sd_verlet_ciccotti_setup
3538 !-----------------------------------------------------------------------------
3539 subroutine sd_verlet1_ciccotti
3541 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3542 ! implicit real*8 (a-h,o-z)
3544 ! include 'DIMENSIONS'
3548 ! include 'COMMON.CONTROL'
3549 ! include 'COMMON.VAR'
3550 ! include 'COMMON.MD'
3552 ! include 'COMMON.LANGEVIN'
3554 ! include 'COMMON.LANGEVIN.lang0'
3556 ! include 'COMMON.CHAIN'
3557 ! include 'COMMON.DERIV'
3558 ! include 'COMMON.GEO'
3559 ! include 'COMMON.LOCAL'
3560 ! include 'COMMON.INTERACT'
3561 ! include 'COMMON.IOUNITS'
3562 ! include 'COMMON.NAMES'
3563 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3564 !el common /stochcalc/ stochforcvec
3565 logical :: lprn = .false.
3566 real(kind=8) :: ddt1,ddt2
3567 integer :: i,j,ind,inres
3568 ! write (iout,*) "dc_old"
3570 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3571 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3574 dc_work(j)=dc_old(j,0)
3575 d_t_work(j)=d_t_old(j,0)
3576 d_a_work(j)=d_a_old(j,0)
3581 dc_work(ind+j)=dc_old(j,i)
3582 d_t_work(ind+j)=d_t_old(j,i)
3583 d_a_work(ind+j)=d_a_old(j,i)
3588 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3590 dc_work(ind+j)=dc_old(j,i+nres)
3591 d_t_work(ind+j)=d_t_old(j,i+nres)
3592 d_a_work(ind+j)=d_a_old(j,i+nres)
3601 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3605 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3606 vfric_mat(i,j),afric_mat(i,j),&
3607 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3615 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3616 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3617 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3618 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3620 d_t_work_new(i)=ddt1+0.5d0*ddt2
3621 d_t_work(i)=ddt1+ddt2
3626 d_t(j,0)=d_t_work(j)
3631 dc(j,i)=dc_work(ind+j)
3632 d_t(j,i)=d_t_work(ind+j)
3638 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3639 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3640 .and.(mnum.ne.5)) then
3643 dc(j,inres)=dc_work(ind+j)
3644 d_t(j,inres)=d_t_work(ind+j)
3650 end subroutine sd_verlet1_ciccotti
3651 !-----------------------------------------------------------------------------
3652 subroutine sd_verlet2_ciccotti
3654 ! Calculating the adjusted velocities for accelerations
3656 ! implicit real*8 (a-h,o-z)
3657 ! include 'DIMENSIONS'
3658 ! include 'COMMON.CONTROL'
3659 ! include 'COMMON.VAR'
3660 ! include 'COMMON.MD'
3662 ! include 'COMMON.LANGEVIN'
3664 ! include 'COMMON.LANGEVIN.lang0'
3666 ! include 'COMMON.CHAIN'
3667 ! include 'COMMON.DERIV'
3668 ! include 'COMMON.GEO'
3669 ! include 'COMMON.LOCAL'
3670 ! include 'COMMON.INTERACT'
3671 ! include 'COMMON.IOUNITS'
3672 ! include 'COMMON.NAMES'
3673 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3674 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3675 !el common /stochcalc/ stochforcvec
3676 real(kind=8) :: ddt1,ddt2
3677 integer :: i,j,ind,inres
3679 ! Compute the stochastic forces which contribute to velocity change
3681 call stochastic_force(stochforcvecV)
3688 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3689 ! ddt2=ddt2+vrand_mat2(i,j)*stochforcvecV(j)
3690 ddt2=ddt2+vrand_mat2(i,j)*stochforcvec(j)
3692 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3696 d_t(j,0)=d_t_work(j)
3701 d_t(j,i)=d_t_work(ind+j)
3707 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3709 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3712 d_t(j,inres)=d_t_work(ind+j)
3718 end subroutine sd_verlet2_ciccotti
3720 !-----------------------------------------------------------------------------
3722 !-----------------------------------------------------------------------------
3723 subroutine inertia_tensor
3725 ! Calculating the intertia tensor for the entire protein in order to
3726 ! remove the perpendicular components of velocity matrix which cause
3727 ! the molecule to rotate.
3730 ! implicit real*8 (a-h,o-z)
3731 ! include 'DIMENSIONS'
3732 ! include 'COMMON.CONTROL'
3733 ! include 'COMMON.VAR'
3734 ! include 'COMMON.MD'
3735 ! include 'COMMON.CHAIN'
3736 ! include 'COMMON.DERIV'
3737 ! include 'COMMON.GEO'
3738 ! include 'COMMON.LOCAL'
3739 ! include 'COMMON.INTERACT'
3740 ! include 'COMMON.IOUNITS'
3741 ! include 'COMMON.NAMES'
3743 real(kind=8),dimension(3,3) :: Im,Imcp,eigvec,Id
3744 real(kind=8),dimension(3) :: pr,eigval,L,vp,vrot
3745 real(kind=8) :: M_SC,mag,mag2,M_PEP
3746 real(kind=8),dimension(3,0:nres) :: vpp !(3,0:MAXRES)
3747 real(kind=8),dimension(3) :: vs_p,pp,incr,v
3748 real(kind=8),dimension(3,3) :: pr1,pr2
3750 !el common /gucio/ cm
3751 integer :: iti,inres,i,j,k,mnum
3762 ! calculating the center of the mass of the protein
3766 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3767 if (itype(i,mnum).eq.ntyp1_molec(mnum)) cycle
3768 M_PEP=M_PEP+mp(mnum)
3770 cm(j)=cm(j)+(c(j,i)+0.5d0*dc(j,i))*mp(mnum)
3779 if (mnum.eq.5) cycle
3780 iti=iabs(itype(i,mnum))
3781 M_SC=M_SC+msc(iabs(iti),mnum)
3784 cm(j)=cm(j)+msc(iabs(iti),mnum)*c(j,inres)
3788 cm(j)=cm(j)/(M_SC+M_PEP)
3793 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3795 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3797 Im(1,1)=Im(1,1)+mp(mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
3798 Im(1,2)=Im(1,2)-mp(mnum)*pr(1)*pr(2)
3799 Im(1,3)=Im(1,3)-mp(mnum)*pr(1)*pr(3)
3800 Im(2,3)=Im(2,3)-mp(mnum)*pr(2)*pr(3)
3801 Im(2,2)=Im(2,2)+mp(mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
3802 Im(3,3)=Im(3,3)+mp(mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
3807 iti=iabs(itype(i,mnum))
3808 if (mnum.eq.5) cycle
3811 pr(j)=c(j,inres)-cm(j)
3813 Im(1,1)=Im(1,1)+msc(iabs(iti),mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
3814 Im(1,2)=Im(1,2)-msc(iabs(iti),mnum)*pr(1)*pr(2)
3815 Im(1,3)=Im(1,3)-msc(iabs(iti),mnum)*pr(1)*pr(3)
3816 Im(2,3)=Im(2,3)-msc(iabs(iti),mnum)*pr(2)*pr(3)
3817 Im(2,2)=Im(2,2)+msc(iabs(iti),mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
3818 Im(3,3)=Im(3,3)+msc(iabs(iti),mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
3823 Im(1,1)=Im(1,1)+Ip(mnum)*(1-dc_norm(1,i)*dc_norm(1,i))* &
3824 vbld(i+1)*vbld(i+1)*0.25d0
3825 Im(1,2)=Im(1,2)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(2,i))* &
3826 vbld(i+1)*vbld(i+1)*0.25d0
3827 Im(1,3)=Im(1,3)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(3,i))* &
3828 vbld(i+1)*vbld(i+1)*0.25d0
3829 Im(2,3)=Im(2,3)+Ip(mnum)*(-dc_norm(2,i)*dc_norm(3,i))* &
3830 vbld(i+1)*vbld(i+1)*0.25d0
3831 Im(2,2)=Im(2,2)+Ip(mnum)*(1-dc_norm(2,i)*dc_norm(2,i))* &
3832 vbld(i+1)*vbld(i+1)*0.25d0
3833 Im(3,3)=Im(3,3)+Ip(mnum)*(1-dc_norm(3,i)*dc_norm(3,i))* &
3834 vbld(i+1)*vbld(i+1)*0.25d0
3840 ! if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
3841 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3842 .and.(mnum.ne.5)) then
3843 iti=iabs(itype(i,mnum))
3845 Im(1,1)=Im(1,1)+Isc(iti,mnum)*(1-dc_norm(1,inres)* &
3846 dc_norm(1,inres))*vbld(inres)*vbld(inres)
3847 Im(1,2)=Im(1,2)-Isc(iti,mnum)*(dc_norm(1,inres)* &
3848 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3849 Im(1,3)=Im(1,3)-Isc(iti,mnum)*(dc_norm(1,inres)* &
3850 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3851 Im(2,3)=Im(2,3)-Isc(iti,mnum)*(dc_norm(2,inres)* &
3852 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3853 Im(2,2)=Im(2,2)+Isc(iti,mnum)*(1-dc_norm(2,inres)* &
3854 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3855 Im(3,3)=Im(3,3)+Isc(iti,mnum)*(1-dc_norm(3,inres)* &
3856 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3861 ! write(iout,*) "The angular momentum before adjustment:"
3862 ! write(iout,*) (L(j),j=1,3)
3868 ! Copying the Im matrix for the djacob subroutine
3876 ! Finding the eigenvectors and eignvalues of the inertia tensor
3877 call djacob(3,3,10000,1.0d-10,Imcp,eigvec,eigval)
3878 ! write (iout,*) "Eigenvalues & Eigenvectors"
3879 ! write (iout,'(5x,3f10.5)') (eigval(i),i=1,3)
3882 ! write (iout,'(i5,3f10.5)') i,(eigvec(i,j),j=1,3)
3884 ! Constructing the diagonalized matrix
3886 if (dabs(eigval(i)).gt.1.0d-15) then
3887 Id(i,i)=1.0d0/eigval(i)
3894 Imcp(i,j)=eigvec(j,i)
3900 pr1(i,j)=pr1(i,j)+Id(i,k)*Imcp(k,j)
3907 pr2(i,j)=pr2(i,j)+eigvec(i,k)*pr1(k,j)
3911 ! Calculating the total rotational velocity of the molecule
3914 vrot(i)=vrot(i)+pr2(i,j)*L(j)
3917 ! Resetting the velocities
3919 call vecpr(vrot(1),dc(1,i),vp)
3921 d_t(j,i)=d_t(j,i)-vp(j)
3926 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3927 .and.(mnum.ne.5)) then
3928 ! if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
3929 ! if(itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3931 call vecpr(vrot(1),dc(1,inres),vp)
3933 d_t(j,inres)=d_t(j,inres)-vp(j)
3938 ! write(iout,*) "The angular momentum after adjustment:"
3939 ! write(iout,*) (L(j),j=1,3)
3942 end subroutine inertia_tensor
3943 !-----------------------------------------------------------------------------
3944 subroutine angmom(cm,L)
3947 ! implicit real*8 (a-h,o-z)
3948 ! include 'DIMENSIONS'
3949 ! include 'COMMON.CONTROL'
3950 ! include 'COMMON.VAR'
3951 ! include 'COMMON.MD'
3952 ! include 'COMMON.CHAIN'
3953 ! include 'COMMON.DERIV'
3954 ! include 'COMMON.GEO'
3955 ! include 'COMMON.LOCAL'
3956 ! include 'COMMON.INTERACT'
3957 ! include 'COMMON.IOUNITS'
3958 ! include 'COMMON.NAMES'
3959 real(kind=8) :: mscab
3960 real(kind=8),dimension(3) :: L,cm,pr,vp,vrot,incr,v,pp
3961 integer :: iti,inres,i,j,mnum
3962 ! Calculate the angular momentum
3971 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3973 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3976 v(j)=incr(j)+0.5d0*d_t(j,i)
3979 incr(j)=incr(j)+d_t(j,i)
3981 call vecpr(pr(1),v(1),vp)
3983 L(j)=L(j)+mp(mnum)*vp(j)
3987 pp(j)=0.5d0*d_t(j,i)
3989 call vecpr(pr(1),pp(1),vp)
3991 L(j)=L(j)+Ip(mnum)*vp(j)
3999 iti=iabs(itype(i,mnum))
4007 pr(j)=c(j,inres)-cm(j)
4009 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4010 .and.(mnum.ne.5)) then
4012 v(j)=incr(j)+d_t(j,inres)
4019 call vecpr(pr(1),v(1),vp)
4020 ! write (iout,*) "i",i," iti",iti," pr",(pr(j),j=1,3),
4021 ! & " v",(v(j),j=1,3)," vp",(vp(j),j=1,3)
4023 L(j)=L(j)+mscab*vp(j)
4025 ! write (iout,*) "L",(l(j),j=1,3)
4026 if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4027 .and.(mnum.ne.5)) then
4029 v(j)=incr(j)+d_t(j,inres)
4031 call vecpr(dc(1,inres),d_t(1,inres),vp)
4033 L(j)=L(j)+Isc(iti,mnum)*vp(j)
4037 incr(j)=incr(j)+d_t(j,i)
4041 end subroutine angmom
4042 !-----------------------------------------------------------------------------
4043 subroutine vcm_vel(vcm)
4046 ! implicit real*8 (a-h,o-z)
4047 ! include 'DIMENSIONS'
4048 ! include 'COMMON.VAR'
4049 ! include 'COMMON.MD'
4050 ! include 'COMMON.CHAIN'
4051 ! include 'COMMON.DERIV'
4052 ! include 'COMMON.GEO'
4053 ! include 'COMMON.LOCAL'
4054 ! include 'COMMON.INTERACT'
4055 ! include 'COMMON.IOUNITS'
4056 real(kind=8),dimension(3) :: vcm,vv
4057 real(kind=8) :: summas,amas
4067 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
4069 summas=summas+mp(mnum)
4071 vcm(j)=vcm(j)+mp(mnum)*(vv(j)+0.5d0*d_t(j,i))
4075 amas=msc(iabs(itype(i,mnum)),mnum)
4080 if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4081 .and.(mnum.ne.5)) then
4083 vcm(j)=vcm(j)+amas*(vv(j)+d_t(j,i+nres))
4087 vcm(j)=vcm(j)+amas*vv(j)
4091 vv(j)=vv(j)+d_t(j,i)
4094 ! write (iout,*) "vcm",(vcm(j),j=1,3)," summas",summas
4096 vcm(j)=vcm(j)/summas
4099 end subroutine vcm_vel
4100 !-----------------------------------------------------------------------------
4102 !-----------------------------------------------------------------------------
4104 ! RATTLE algorithm for velocity Verlet - step 1, UNRES
4108 ! implicit real*8 (a-h,o-z)
4109 ! include 'DIMENSIONS'
4111 ! include 'COMMON.CONTROL'
4112 ! include 'COMMON.VAR'
4113 ! include 'COMMON.MD'
4115 ! include 'COMMON.LANGEVIN'
4117 ! include 'COMMON.LANGEVIN.lang0'
4119 ! include 'COMMON.CHAIN'
4120 ! include 'COMMON.DERIV'
4121 ! include 'COMMON.GEO'
4122 ! include 'COMMON.LOCAL'
4123 ! include 'COMMON.INTERACT'
4124 ! include 'COMMON.IOUNITS'
4125 ! include 'COMMON.NAMES'
4126 ! include 'COMMON.TIME1'
4127 !el real(kind=8) :: gginv(2*nres,2*nres),&
4128 !el gdc(3,2*nres,2*nres)
4129 real(kind=8) :: dC_uncor(3,2*nres) !,&
4130 !el real(kind=8) :: Cmat(2*nres,2*nres)
4131 real(kind=8) :: x(2*nres),xcorr(3,2*nres) !maxres2=2*maxres
4132 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4133 !el common /przechowalnia/ nbond
4134 integer :: max_rattle = 5
4135 logical :: lprn = .false., lprn1 = .false., not_done
4136 real(kind=8) :: tol_rattle = 1.0d-5
4138 integer :: ii,i,j,jj,l,ind,ind1,nres2
4141 !el /common/ przechowalnia
4143 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4144 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4145 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4147 if (lprn) write (iout,*) "RATTLE1"
4151 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4152 .and.(mnum.ne.5)) nbond=nbond+1
4154 ! Make a folded form of the Ginv-matrix
4167 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4172 if (itype(k,1).ne.10 .and. itype(k,mnum).ne.ntyp1_molec(mnum)&
4173 .and.(mnum.ne.5)) then
4177 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4185 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4196 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4200 if (itype(k,1).ne.10) then
4204 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4212 write (iout,*) "Matrix GGinv"
4213 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4219 if (iter.gt.max_rattle) then
4220 write (iout,*) "Error - too many iterations in RATTLE."
4223 ! Calculate the matrix C = GG**(-1) dC_old o dC
4228 dC_uncor(j,ind1)=dC(j,i)
4232 if (itype(i,1).ne.10) then
4235 dC_uncor(j,ind1)=dC(j,i+nres)
4244 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4248 if (itype(k,1).ne.10) then
4251 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4256 ! Calculate deviations from standard virtual-bond lengths
4260 x(ind)=vbld(i+1)**2-vbl**2
4263 if (itype(i,1).ne.10) then
4265 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4269 write (iout,*) "Coordinates and violations"
4271 write(iout,'(i5,3f10.5,5x,e15.5)') &
4272 i,(dC_uncor(j,i),j=1,3),x(i)
4274 write (iout,*) "Velocities and violations"
4278 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4279 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4283 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4284 .and.(mnum.ne.5)) then
4287 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4288 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4289 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4292 ! write (iout,*) "gdc"
4294 ! write (iout,*) "i",i
4296 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4302 if (dabs(x(i)).gt.xmax) then
4306 if (xmax.lt.tol_rattle) then
4310 ! Calculate the matrix of the system of equations
4315 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4320 write (iout,*) "Matrix Cmat"
4321 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4323 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4324 ! Add constraint term to positions
4331 xx = xx+x(ii)*gdc(j,ind,ii)
4335 d_t_new(j,i)=d_t_new(j,i)-xx/d_time
4339 if (itype(i,1).ne.10) then
4344 xx = xx+x(ii)*gdc(j,ind,ii)
4347 dC(j,i+nres)=dC(j,i+nres)-xx
4348 d_t_new(j,i+nres)=d_t_new(j,i+nres)-xx/d_time
4352 ! Rebuild the chain using the new coordinates
4353 call chainbuild_cart
4355 write (iout,*) "New coordinates, Lagrange multipliers,",&
4356 " and differences between actual and standard bond lengths"
4360 xx=vbld(i+1)**2-vbl**2
4361 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4362 i,(dC(j,i),j=1,3),x(ind),xx
4366 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4369 xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4370 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4371 i,(dC(j,i+nres),j=1,3),x(ind),xx
4374 write (iout,*) "Velocities and violations"
4378 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4379 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4382 if (itype(i,1).ne.10) then
4384 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4385 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4386 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4393 10 write (iout,*) "Error - singularity in solving the system",&
4394 " of equations for Lagrange multipliers."
4398 "RATTLE inactive; use -DRATTLE switch at compile time."
4401 end subroutine rattle1
4402 !-----------------------------------------------------------------------------
4404 ! RATTLE algorithm for velocity Verlet - step 2, UNRES
4408 ! implicit real*8 (a-h,o-z)
4409 ! include 'DIMENSIONS'
4411 ! include 'COMMON.CONTROL'
4412 ! include 'COMMON.VAR'
4413 ! include 'COMMON.MD'
4415 ! include 'COMMON.LANGEVIN'
4417 ! include 'COMMON.LANGEVIN.lang0'
4419 ! include 'COMMON.CHAIN'
4420 ! include 'COMMON.DERIV'
4421 ! include 'COMMON.GEO'
4422 ! include 'COMMON.LOCAL'
4423 ! include 'COMMON.INTERACT'
4424 ! include 'COMMON.IOUNITS'
4425 ! include 'COMMON.NAMES'
4426 ! include 'COMMON.TIME1'
4427 !el real(kind=8) :: gginv(2*nres,2*nres),&
4428 !el gdc(3,2*nres,2*nres)
4429 real(kind=8) :: dC_uncor(3,2*nres) !,&
4430 !el Cmat(2*nres,2*nres)
4431 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4432 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4433 !el common /przechowalnia/ nbond
4434 integer :: max_rattle = 5
4435 logical :: lprn = .false., lprn1 = .false., not_done
4436 real(kind=8) :: tol_rattle = 1.0d-5
4440 !el /common/ przechowalnia
4441 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4442 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4443 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4445 if (lprn) write (iout,*) "RATTLE2"
4446 if (lprn) write (iout,*) "Velocity correction"
4447 ! Calculate the matrix G dC
4453 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k)
4458 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4459 .and.(mnum.ne.5)) then
4462 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k+nres)
4468 ! write (iout,*) "gdc"
4470 ! write (iout,*) "i",i
4472 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4476 ! Calculate the matrix of the system of equations
4483 Cmat(ind,j)=Cmat(ind,j)+dC(k,i)*gdc(k,ind,j)
4489 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4490 .and.(mnum.ne.5)) then
4495 Cmat(ind,j)=Cmat(ind,j)+dC(k,i+nres)*gdc(k,ind,j)
4500 ! Calculate the scalar product dC o d_t_new
4504 x(ind)=scalar(d_t(1,i),dC(1,i))
4508 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4509 .and.(mnum.ne.5)) then
4511 x(ind)=scalar(d_t(1,i+nres),dC(1,i+nres))
4515 write (iout,*) "Velocities and violations"
4519 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4520 i,ind,(d_t(j,i),j=1,3),x(ind)
4524 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4525 .and.(mnum.ne.5)) then
4527 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4528 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind)
4534 if (dabs(x(i)).gt.xmax) then
4538 if (xmax.lt.tol_rattle) then
4543 write (iout,*) "Matrix Cmat"
4544 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4546 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4547 ! Add constraint term to velocities
4554 xx = xx+x(ii)*gdc(j,ind,ii)
4556 d_t(j,i)=d_t(j,i)-xx
4561 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4562 .and.(mnum.ne.5)) then
4567 xx = xx+x(ii)*gdc(j,ind,ii)
4569 d_t(j,i+nres)=d_t(j,i+nres)-xx
4575 "New velocities, Lagrange multipliers violations"
4579 if (lprn) write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4580 i,ind,(d_t(j,i),j=1,3),x(ind),scalar(d_t(1,i),dC(1,i))
4584 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4587 write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4588 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind),&
4589 scalar(d_t(1,i+nres),dC(1,i+nres))
4595 10 write (iout,*) "Error - singularity in solving the system",&
4596 " of equations for Lagrange multipliers."
4600 "RATTLE inactive; use -DRATTLE option at compile time."
4603 end subroutine rattle2
4604 !-----------------------------------------------------------------------------
4605 subroutine rattle_brown
4606 ! RATTLE/LINCS algorithm for Brownian dynamics, UNRES
4610 ! implicit real*8 (a-h,o-z)
4611 ! include 'DIMENSIONS'
4613 ! include 'COMMON.CONTROL'
4614 ! include 'COMMON.VAR'
4615 ! include 'COMMON.MD'
4617 ! include 'COMMON.LANGEVIN'
4619 ! include 'COMMON.LANGEVIN.lang0'
4621 ! include 'COMMON.CHAIN'
4622 ! include 'COMMON.DERIV'
4623 ! include 'COMMON.GEO'
4624 ! include 'COMMON.LOCAL'
4625 ! include 'COMMON.INTERACT'
4626 ! include 'COMMON.IOUNITS'
4627 ! include 'COMMON.NAMES'
4628 ! include 'COMMON.TIME1'
4629 !el real(kind=8) :: gginv(2*nres,2*nres),&
4630 !el gdc(3,2*nres,2*nres)
4631 real(kind=8) :: dC_uncor(3,2*nres) !,&
4632 !el real(kind=8) :: Cmat(2*nres,2*nres)
4633 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4634 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4635 !el common /przechowalnia/ nbond
4636 integer :: max_rattle = 5
4637 logical :: lprn = .false., lprn1 = .false., not_done
4638 real(kind=8) :: tol_rattle = 1.0d-5
4642 !el /common/ przechowalnia
4643 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4644 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4645 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4648 if (lprn) write (iout,*) "RATTLE_BROWN"
4651 if (itype(i,1).ne.10) nbond=nbond+1
4653 ! Make a folded form of the Ginv-matrix
4666 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4670 if (itype(k,1).ne.10) then
4674 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4681 if (itype(i,1).ne.10) then
4691 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4695 if (itype(k,1).ne.10) then
4699 if (j.eq.1 .and. l.eq.1)GGinv(ii,jj)=fricmat(ind,ind1)
4707 write (iout,*) "Matrix GGinv"
4708 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4714 if (iter.gt.max_rattle) then
4715 write (iout,*) "Error - too many iterations in RATTLE."
4718 ! Calculate the matrix C = GG**(-1) dC_old o dC
4723 dC_uncor(j,ind1)=dC(j,i)
4727 if (itype(i,1).ne.10) then
4730 dC_uncor(j,ind1)=dC(j,i+nres)
4739 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4743 if (itype(k,1).ne.10) then
4746 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4751 ! Calculate deviations from standard virtual-bond lengths
4755 x(ind)=vbld(i+1)**2-vbl**2
4758 if (itype(i,1).ne.10) then
4760 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4764 write (iout,*) "Coordinates and violations"
4766 write(iout,'(i5,3f10.5,5x,e15.5)') &
4767 i,(dC_uncor(j,i),j=1,3),x(i)
4769 write (iout,*) "Velocities and violations"
4773 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4774 i,ind,(d_t(j,i),j=1,3),scalar(d_t(1,i),dC_old(1,i))
4777 if (itype(i,1).ne.10) then
4779 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4780 i+nres,ind,(d_t(j,i+nres),j=1,3),&
4781 scalar(d_t(1,i+nres),dC_old(1,i+nres))
4784 write (iout,*) "gdc"
4786 write (iout,*) "i",i
4788 write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4794 if (dabs(x(i)).gt.xmax) then
4798 if (xmax.lt.tol_rattle) then
4802 ! Calculate the matrix of the system of equations
4807 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4812 write (iout,*) "Matrix Cmat"
4813 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4815 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4816 ! Add constraint term to positions
4823 xx = xx+x(ii)*gdc(j,ind,ii)
4826 d_t(j,i)=d_t(j,i)+xx/d_time
4831 if (itype(i,1).ne.10) then
4836 xx = xx+x(ii)*gdc(j,ind,ii)
4839 d_t(j,i+nres)=d_t(j,i+nres)+xx/d_time
4840 dC(j,i+nres)=dC(j,i+nres)+xx
4844 ! Rebuild the chain using the new coordinates
4845 call chainbuild_cart
4847 write (iout,*) "New coordinates, Lagrange multipliers,",&
4848 " and differences between actual and standard bond lengths"
4852 xx=vbld(i+1)**2-vbl**2
4853 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4854 i,(dC(j,i),j=1,3),x(ind),xx
4857 if (itype(i,1).ne.10) then
4859 xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4860 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4861 i,(dC(j,i+nres),j=1,3),x(ind),xx
4864 write (iout,*) "Velocities and violations"
4868 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4869 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4872 if (itype(i,1).ne.10) then
4874 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4875 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4876 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4883 10 write (iout,*) "Error - singularity in solving the system",&
4884 " of equations for Lagrange multipliers."
4888 "RATTLE inactive; use -DRATTLE option at compile time"
4891 end subroutine rattle_brown
4892 !-----------------------------------------------------------------------------
4894 !-----------------------------------------------------------------------------
4895 subroutine friction_force
4900 ! implicit real*8 (a-h,o-z)
4901 ! include 'DIMENSIONS'
4902 ! include 'COMMON.VAR'
4903 ! include 'COMMON.CHAIN'
4904 ! include 'COMMON.DERIV'
4905 ! include 'COMMON.GEO'
4906 ! include 'COMMON.LOCAL'
4907 ! include 'COMMON.INTERACT'
4908 ! include 'COMMON.MD'
4910 ! include 'COMMON.LANGEVIN'
4912 ! include 'COMMON.LANGEVIN.lang0'
4914 ! include 'COMMON.IOUNITS'
4915 !el real(kind=8),dimension(6*nres) :: gamvec !(MAXRES6) maxres6=6*maxres
4916 !el common /syfek/ gamvec
4917 real(kind=8) :: vv(3),vvtot(3,nres),v_work(6*nres) !,&
4918 !el ginvfric(2*nres,2*nres) !maxres2=2*maxres
4919 !el common /przechowalnia/ ginvfric
4921 logical :: lprn = .false., checkmode = .false.
4922 integer :: i,j,ind,k,nres2,nres6,mnum
4926 if(.not.allocated(gamvec)) allocate(gamvec(nres6)) !(MAXRES6)
4927 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
4935 d_t_work(j)=d_t(j,0)
4940 d_t_work(ind+j)=d_t(j,i)
4946 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
4947 .and.(mnum.ne.5)) then
4949 d_t_work(ind+j)=d_t(j,i+nres)
4955 call fricmat_mult(d_t_work,fric_work)
4957 if (.not.checkmode) return
4960 write (iout,*) "d_t_work and fric_work"
4962 write (iout,'(i3,2e15.5)') i,d_t_work(i),fric_work(i)
4966 friction(j,0)=fric_work(j)
4971 friction(j,i)=fric_work(ind+j)
4977 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
4978 .and.(mnum.ne.5)) then
4979 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
4981 friction(j,i+nres)=fric_work(ind+j)
4987 write(iout,*) "Friction backbone"
4989 write(iout,'(i5,3e15.5,5x,3e15.5)') &
4990 i,(friction(j,i),j=1,3),(d_t(j,i),j=1,3)
4992 write(iout,*) "Friction side chain"
4994 write(iout,'(i5,3e15.5,5x,3e15.5)') &
4995 i,(friction(j,i+nres),j=1,3),(d_t(j,i+nres),j=1,3)
5004 vvtot(j,i)=vv(j)+0.5d0*d_t(j,i)
5005 vvtot(j,i+nres)=vv(j)+d_t(j,i+nres)
5006 vv(j)=vv(j)+d_t(j,i)
5009 write (iout,*) "vvtot backbone and sidechain"
5011 write (iout,'(i5,3e15.5,5x,3e15.5)') i,(vvtot(j,i),j=1,3),&
5012 (vvtot(j,i+nres),j=1,3)
5017 v_work(ind+j)=vvtot(j,i)
5023 v_work(ind+j)=vvtot(j,i+nres)
5027 write (iout,*) "v_work gamvec and site-based friction forces"
5029 write (iout,'(i5,3e15.5)') i,v_work(i),gamvec(i),&
5033 ! fric_work1(i)=0.0d0
5035 ! fric_work1(i)=fric_work1(i)-A(j,i)*gamvec(j)*v_work(j)
5038 ! write (iout,*) "fric_work and fric_work1"
5040 ! write (iout,'(i5,2e15.5)') i,fric_work(i),fric_work1(i)
5046 ginvfric(i,j)=ginvfric(i,j)+ginv(i,k)*fricmat(k,j)
5050 write (iout,*) "ginvfric"
5052 write (iout,'(i5,100f8.3)') i,(ginvfric(i,j),j=1,dimen)
5054 write (iout,*) "symmetry check"
5057 write (iout,*) i,j,ginvfric(i,j)-ginvfric(j,i)
5062 end subroutine friction_force
5063 !-----------------------------------------------------------------------------
5064 subroutine setup_fricmat
5068 use control_data, only:time_Bcast
5069 use control, only:tcpu
5071 ! implicit real*8 (a-h,o-z)
5075 real(kind=8) :: time00
5077 ! include 'DIMENSIONS'
5078 ! include 'COMMON.VAR'
5079 ! include 'COMMON.CHAIN'
5080 ! include 'COMMON.DERIV'
5081 ! include 'COMMON.GEO'
5082 ! include 'COMMON.LOCAL'
5083 ! include 'COMMON.INTERACT'
5084 ! include 'COMMON.MD'
5085 ! include 'COMMON.SETUP'
5086 ! include 'COMMON.TIME1'
5087 ! integer licznik /0/
5090 ! include 'COMMON.LANGEVIN'
5092 ! include 'COMMON.LANGEVIN.lang0'
5094 ! include 'COMMON.IOUNITS'
5096 integer :: i,j,ind,ind1,m
5097 logical :: lprn = .false.
5098 real(kind=8) :: dtdi !el ,gamvec(2*nres)
5099 !el real(kind=8),dimension(2*nres,2*nres) :: ginvfric,fcopy
5100 ! real(kind=8),allocatable,dimension(:,:) :: fcopy
5101 !el real(kind=8),dimension(2*nres*(2*nres+1)/2) :: Ghalf !(mmaxres2) (mmaxres2=(maxres2*(maxres2+1)/2))
5102 !el common /syfek/ gamvec
5103 real(kind=8) :: work(8*2*nres)
5104 integer :: iwork(2*nres)
5105 !el common /przechowalnia/ ginvfric,Ghalf,fcopy
5106 integer :: ii,iti,k,l,nzero,nres2,nres6,ierr,mnum
5110 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5111 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5112 if (fg_rank.ne.king) goto 10
5117 if(.not.allocated(gamvec)) allocate(gamvec(nres2)) !(MAXRES2)
5118 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
5119 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5120 !el allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5121 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !maxres2=2*maxres
5123 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5124 ! Zeroing out fricmat
5130 ! Load the friction coefficients corresponding to peptide groups
5135 gamvec(ind1)=gamp(mnum)
5137 ! Load the friction coefficients corresponding to side chains
5141 gamsc(ntyp1_molec(j),j)=1.0d0
5148 gamvec(ii)=gamsc(iabs(iti),mnum)
5150 if (surfarea) call sdarea(gamvec)
5152 ! write (iout,*) "Matrix A and vector gamma"
5154 ! write (iout,'(i2,$)') i
5156 ! write (iout,'(f4.1,$)') A(i,j)
5158 ! write (iout,'(f8.3)') gamvec(i)
5162 write (iout,*) "Vector gamvec"
5164 write (iout,'(i5,f10.5)') i, gamvec(i)
5168 ! The friction matrix
5173 dtdi=dtdi+A(j,k)*A(j,i)*gamvec(j)
5180 write (iout,'(//a)') "Matrix fricmat"
5181 call matout2(dimen,dimen,nres2,nres2,fricmat)
5183 if (lang.eq.2 .or. lang.eq.3) then
5184 ! Mass-scale the friction matrix if non-direct integration will be performed
5190 Ginvfric(i,j)=Ginvfric(i,j)+ &
5191 Gsqrm(i,k)*Gsqrm(l,j)*fricmat(k,l)
5196 ! Diagonalize the friction matrix
5201 Ghalf(ind)=Ginvfric(i,j)
5204 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5207 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5208 " mass-scaled friction matrix"
5209 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5211 ! Precompute matrices for tinker stochastic integrator
5218 mt1(i,j)=mt1(i,j)+fricvec(k,i)*gsqrm(k,j)
5219 mt2(i,j)=mt2(i,j)+fricvec(k,i)*gsqrp(k,j)
5225 else if (lang.eq.4) then
5226 ! Diagonalize the friction matrix
5231 Ghalf(ind)=fricmat(i,j)
5234 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5237 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5239 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5241 ! Determine the number of zero eigenvalues of the friction matrix
5242 nzero=max0(dimen-dimen1,0)
5243 ! do while (fricgam(nzero+1).le.1.0d-5 .and. nzero.lt.dimen)
5246 write (iout,*) "Number of zero eigenvalues:",nzero
5251 fricmat(i,j)=fricmat(i,j) &
5252 +fricvec(i,k)*fricvec(j,k)/fricgam(k)
5257 write (iout,'(//a)') "Generalized inverse of fricmat"
5258 call matout(dimen,dimen,nres6,nres6,fricmat)
5263 if (nfgtasks.gt.1) then
5264 if (fg_rank.eq.0) then
5265 ! The matching BROADCAST for fg processors is called in ERGASTULUM
5271 call MPI_Bcast(10,1,MPI_INTEGER,king,FG_COMM,IERROR)
5273 time_Bcast=time_Bcast+MPI_Wtime()-time00
5275 time_Bcast=time_Bcast+tcpu()-time00
5277 ! print *,"Processor",myrank,
5278 ! & " BROADCAST iorder in SETUP_FRICMAT"
5281 write (iout,*) "setup_fricmat licznik"!,licznik !sp
5287 ! Scatter the friction matrix
5288 call MPI_Scatterv(fricmat(1,1),nginv_counts(0),&
5289 nginv_start(0),MPI_DOUBLE_PRECISION,fcopy(1,1),&
5290 myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
5293 time_scatter=time_scatter+MPI_Wtime()-time00
5294 time_scatter_fmat=time_scatter_fmat+MPI_Wtime()-time00
5296 time_scatter=time_scatter+tcpu()-time00
5297 time_scatter_fmat=time_scatter_fmat+tcpu()-time00
5301 do j=1,2*my_ng_count
5302 fricmat(j,i)=fcopy(i,j)
5305 ! write (iout,*) "My chunk of fricmat"
5306 ! call MATOUT2(my_ng_count,dimen,maxres2,maxres2,fcopy)
5310 end subroutine setup_fricmat
5311 !-----------------------------------------------------------------------------
5312 subroutine stochastic_force(stochforcvec)
5315 use random, only:anorm_distr
5316 ! implicit real*8 (a-h,o-z)
5317 ! include 'DIMENSIONS'
5318 use control, only: tcpu
5323 ! include 'COMMON.VAR'
5324 ! include 'COMMON.CHAIN'
5325 ! include 'COMMON.DERIV'
5326 ! include 'COMMON.GEO'
5327 ! include 'COMMON.LOCAL'
5328 ! include 'COMMON.INTERACT'
5329 ! include 'COMMON.MD'
5330 ! include 'COMMON.TIME1'
5332 ! include 'COMMON.LANGEVIN'
5334 ! include 'COMMON.LANGEVIN.lang0'
5336 ! include 'COMMON.IOUNITS'
5338 real(kind=8) :: x,sig,lowb,highb
5339 real(kind=8) :: ff(3),force(3,0:2*nres),zeta2,lowb2
5340 real(kind=8) :: highb2,sig2,forcvec(6*nres),stochforcvec(6*nres)
5341 real(kind=8) :: time00
5342 logical :: lprn = .false.
5343 integer :: i,j,ind,mnum
5347 stochforc(j,i)=0.0d0
5357 ! Compute the stochastic forces acting on bodies. Store in force.
5363 force(j,i)=anorm_distr(x,sig,lowb,highb)
5371 force(j,i+nres)=anorm_distr(x,sig2,lowb2,highb2)
5375 time_fsample=time_fsample+MPI_Wtime()-time00
5377 time_fsample=time_fsample+tcpu()-time00
5379 ! Compute the stochastic forces acting on virtual-bond vectors.
5385 stochforc(j,i)=ff(j)+0.5d0*force(j,i)
5388 ff(j)=ff(j)+force(j,i)
5390 ! if (itype(i+1,1).ne.ntyp1) then
5392 if (itype(i+1,mnum).ne.ntyp1_molec(mnum)) then
5394 stochforc(j,i)=stochforc(j,i)+force(j,i+nres+1)
5395 ff(j)=ff(j)+force(j,i+nres+1)
5400 stochforc(j,0)=ff(j)+force(j,nnt+nres)
5404 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5405 .and.(mnum.ne.5)) then
5406 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5408 stochforc(j,i+nres)=force(j,i+nres)
5414 stochforcvec(j)=stochforc(j,0)
5419 stochforcvec(ind+j)=stochforc(j,i)
5425 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5426 .and.(mnum.ne.5)) then
5427 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5429 stochforcvec(ind+j)=stochforc(j,i+nres)
5435 write (iout,*) "stochforcvec"
5437 write(iout,'(i5,e15.5)') i,stochforcvec(i)
5439 write(iout,*) "Stochastic forces backbone"
5441 write(iout,'(i5,3e15.5)') i,(stochforc(j,i),j=1,3)
5443 write(iout,*) "Stochastic forces side chain"
5445 write(iout,'(i5,3e15.5)') &
5446 i,(stochforc(j,i+nres),j=1,3)
5454 write (iout,*) i,ind
5456 forcvec(ind+j)=force(j,i)
5461 write (iout,*) i,ind
5463 forcvec(j+ind)=force(j,i+nres)
5468 write (iout,*) "forcvec"
5472 write (iout,'(2i3,2f10.5)') i,j,force(j,i),&
5479 write (iout,'(2i3,2f10.5)') i,j,force(j,i+nres),&
5488 end subroutine stochastic_force
5489 !-----------------------------------------------------------------------------
5490 subroutine sdarea(gamvec)
5492 ! Scale the friction coefficients according to solvent accessible surface areas
5493 ! Code adapted from TINKER
5497 ! implicit real*8 (a-h,o-z)
5498 ! include 'DIMENSIONS'
5499 ! include 'COMMON.CONTROL'
5500 ! include 'COMMON.VAR'
5501 ! include 'COMMON.MD'
5503 ! include 'COMMON.LANGEVIN'
5505 ! include 'COMMON.LANGEVIN.lang0'
5507 ! include 'COMMON.CHAIN'
5508 ! include 'COMMON.DERIV'
5509 ! include 'COMMON.GEO'
5510 ! include 'COMMON.LOCAL'
5511 ! include 'COMMON.INTERACT'
5512 ! include 'COMMON.IOUNITS'
5513 ! include 'COMMON.NAMES'
5514 real(kind=8),dimension(2*nres) :: radius,gamvec !(maxres2)
5515 real(kind=8),parameter :: twosix = 1.122462048309372981d0
5516 logical :: lprn = .false.
5517 real(kind=8) :: probe,area,ratio
5518 integer :: i,j,ind,iti,mnum
5520 ! determine new friction coefficients every few SD steps
5522 ! set the atomic radii to estimates of sigma values
5524 ! print *,"Entered sdarea"
5530 ! Load peptide group radii
5533 radius(i)=pstok(mnum)
5535 ! Load side chain radii
5539 radius(i+nres)=restok(iti,mnum)
5542 ! write (iout,*) "i",i," radius",radius(i)
5545 radius(i) = radius(i) / twosix
5546 if (radius(i) .ne. 0.0d0) radius(i) = radius(i) + probe
5549 ! scale atomic friction coefficients by accessible area
5551 if (lprn) write (iout,*) &
5552 "Original gammas, surface areas, scaling factors, new gammas, ",&
5553 "std's of stochastic forces"
5556 if (radius(i).gt.0.0d0) then
5557 call surfatom (i,area,radius)
5558 ratio = dmax1(area/(4.0d0*pi*radius(i)**2),1.0d-1)
5559 if (lprn) write (iout,'(i5,3f10.5,$)') &
5560 i,gamvec(ind+1),area,ratio
5563 gamvec(ind) = ratio * gamvec(ind)
5566 stdforcp(i)=stdfp(mnum)*dsqrt(gamvec(ind))
5567 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcp(i)
5571 if (radius(i+nres).gt.0.0d0) then
5572 call surfatom (i+nres,area,radius)
5573 ratio = dmax1(area/(4.0d0*pi*radius(i+nres)**2),1.0d-1)
5574 if (lprn) write (iout,'(i5,3f10.5,$)') &
5575 i,gamvec(ind+1),area,ratio
5578 gamvec(ind) = ratio * gamvec(ind)
5581 stdforcsc(i)=stdfsc(itype(i,mnum),mnum)*dsqrt(gamvec(ind))
5582 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcsc(i)
5587 end subroutine sdarea
5588 !-----------------------------------------------------------------------------
5590 !-----------------------------------------------------------------------------
5593 ! ###################################################
5594 ! ## COPYRIGHT (C) 1996 by Jay William Ponder ##
5595 ! ## All Rights Reserved ##
5596 ! ###################################################
5598 ! ################################################################
5600 ! ## subroutine surfatom -- exposed surface area of an atom ##
5602 ! ################################################################
5605 ! "surfatom" performs an analytical computation of the surface
5606 ! area of a specified atom; a simplified version of "surface"
5608 ! literature references:
5610 ! T. J. Richmond, "Solvent Accessible Surface Area and
5611 ! Excluded Volume in Proteins", Journal of Molecular Biology,
5614 ! L. Wesson and D. Eisenberg, "Atomic Solvation Parameters
5615 ! Applied to Molecular Dynamics of Proteins in Solution",
5616 ! Protein Science, 1, 227-235 (1992)
5618 ! variables and parameters:
5620 ! ir number of atom for which area is desired
5621 ! area accessible surface area of the atom
5622 ! radius radii of each of the individual atoms
5625 subroutine surfatom(ir,area,radius)
5627 ! implicit real*8 (a-h,o-z)
5628 ! include 'DIMENSIONS'
5630 ! include 'COMMON.GEO'
5631 ! include 'COMMON.IOUNITS'
5633 integer :: nsup,nstart_sup
5634 ! double precision c,dc,dc_old,d_c_work,xloc,xrot,dc_norm
5635 ! common /chain/ c(3,maxres2+2),dc(3,0:maxres2),dc_old(3,0:maxres2),
5636 ! & xloc(3,maxres),xrot(3,maxres),dc_norm(3,0:maxres2),
5637 ! & dc_work(MAXRES6),nres,nres0
5638 integer,parameter :: maxarc=300
5642 integer :: mi,ni,narc
5643 integer :: key(maxarc)
5644 integer :: intag(maxarc)
5645 integer :: intag1(maxarc)
5646 real(kind=8) :: area,arcsum
5647 real(kind=8) :: arclen,exang
5648 real(kind=8) :: delta,delta2
5649 real(kind=8) :: eps,rmove
5650 real(kind=8) :: xr,yr,zr
5651 real(kind=8) :: rr,rrsq
5652 real(kind=8) :: rplus,rminus
5653 real(kind=8) :: axx,axy,axz
5654 real(kind=8) :: ayx,ayy
5655 real(kind=8) :: azx,azy,azz
5656 real(kind=8) :: uxj,uyj,uzj
5657 real(kind=8) :: tx,ty,tz
5658 real(kind=8) :: txb,tyb,td
5659 real(kind=8) :: tr2,tr,txr,tyr
5660 real(kind=8) :: tk1,tk2
5661 real(kind=8) :: thec,the,t,tb
5662 real(kind=8) :: txk,tyk,tzk
5663 real(kind=8) :: t1,ti,tf,tt
5664 real(kind=8) :: txj,tyj,tzj
5665 real(kind=8) :: ccsq,cc,xysq
5666 real(kind=8) :: bsqk,bk,cosine
5667 real(kind=8) :: dsqj,gi,pix2
5668 real(kind=8) :: therk,dk,gk
5669 real(kind=8) :: risqk,rik
5670 real(kind=8) :: radius(2*nres) !(maxatm) (maxatm=maxres2)
5671 real(kind=8) :: ri(maxarc),risq(maxarc)
5672 real(kind=8) :: ux(maxarc),uy(maxarc),uz(maxarc)
5673 real(kind=8) :: xc(maxarc),yc(maxarc),zc(maxarc)
5674 real(kind=8) :: xc1(maxarc),yc1(maxarc),zc1(maxarc)
5675 real(kind=8) :: dsq(maxarc),bsq(maxarc)
5676 real(kind=8) :: dsq1(maxarc),bsq1(maxarc)
5677 real(kind=8) :: arci(maxarc),arcf(maxarc)
5678 real(kind=8) :: ex(maxarc),lt(maxarc),gr(maxarc)
5679 real(kind=8) :: b(maxarc),b1(maxarc),bg(maxarc)
5680 real(kind=8) :: kent(maxarc),kout(maxarc)
5681 real(kind=8) :: ther(maxarc)
5682 logical :: moved,top
5683 logical :: omit(maxarc)
5686 ! maxatm = 2*nres !maxres2 maxres2=2*maxres
5687 ! maxlight = 8*maxatm
5690 ! maxtors = 4*maxatm
5692 ! zero out the surface area for the sphere of interest
5695 ! write (2,*) "ir",ir," radius",radius(ir)
5696 if (radius(ir) .eq. 0.0d0) return
5698 ! set the overlap significance and connectivity shift
5702 delta2 = delta * delta
5707 ! store coordinates and radius of the sphere of interest
5715 ! initialize values of some counters and summations
5724 ! test each sphere to see if it overlaps the sphere of interest
5727 if (i.eq.ir .or. radius(i).eq.0.0d0) goto 30
5728 rplus = rr + radius(i)
5730 if (abs(tx) .ge. rplus) goto 30
5732 if (abs(ty) .ge. rplus) goto 30
5734 if (abs(tz) .ge. rplus) goto 30
5736 ! check for sphere overlap by testing distance against radii
5738 xysq = tx*tx + ty*ty
5739 if (xysq .lt. delta2) then
5746 if (rplus-cc .le. delta) goto 30
5747 rminus = rr - radius(i)
5749 ! check to see if sphere of interest is completely buried
5751 if (cc-abs(rminus) .le. delta) then
5752 if (rminus .le. 0.0d0) goto 170
5756 ! check for too many overlaps with sphere of interest
5758 if (io .ge. maxarc) then
5760 20 format (/,' SURFATOM -- Increase the Value of MAXARC')
5764 ! get overlap between current sphere and sphere of interest
5773 gr(io) = (ccsq+rplus*rminus) / (2.0d0*rr*b1(io))
5779 ! case where no other spheres overlap the sphere of interest
5782 area = 4.0d0 * pi * rrsq
5786 ! case where only one sphere overlaps the sphere of interest
5789 area = pix2 * (1.0d0 + gr(1))
5790 area = mod(area,4.0d0*pi) * rrsq
5794 ! case where many spheres intersect the sphere of interest;
5795 ! sort the intersecting spheres by their degree of overlap
5797 call sort2 (io,gr,key)
5800 intag(i) = intag1(k)
5809 ! get radius of each overlap circle on surface of the sphere
5814 risq(i) = rrsq - gi*gi
5815 ri(i) = sqrt(risq(i))
5816 ther(i) = 0.5d0*pi - asin(min(1.0d0,max(-1.0d0,gr(i))))
5819 ! find boundary of inaccessible area on sphere of interest
5822 if (.not. omit(k)) then
5829 ! check to see if J circle is intersecting K circle;
5830 ! get distance between circle centers and sum of radii
5833 if (omit(j)) goto 60
5834 cc = (txk*xc(j)+tyk*yc(j)+tzk*zc(j))/(bk*b(j))
5835 cc = acos(min(1.0d0,max(-1.0d0,cc)))
5836 td = therk + ther(j)
5838 ! check to see if circles enclose separate regions
5840 if (cc .ge. td) goto 60
5842 ! check for circle J completely inside circle K
5844 if (cc+ther(j) .lt. therk) goto 40
5846 ! check for circles that are essentially parallel
5848 if (cc .gt. delta) goto 50
5853 ! check to see if sphere of interest is completely buried
5856 if (pix2-cc .le. td) goto 170
5862 ! find T value of circle intersections
5865 if (omit(k)) goto 110
5880 ! rotation matrix elements
5892 if (.not. omit(j)) then
5897 ! rotate spheres so K vector colinear with z-axis
5899 uxj = txj*axx + tyj*axy - tzj*axz
5900 uyj = tyj*ayy - txj*ayx
5901 uzj = txj*azx + tyj*azy + tzj*azz
5902 cosine = min(1.0d0,max(-1.0d0,uzj/b(j)))
5903 if (acos(cosine) .lt. therk+ther(j)) then
5904 dsqj = uxj*uxj + uyj*uyj
5909 tr2 = risqk*dsqj - tb*tb
5915 ! get T values of intersection for K circle
5918 tb = min(1.0d0,max(-1.0d0,tb))
5920 if (tyb-txr .lt. 0.0d0) tk1 = pix2 - tk1
5922 tb = min(1.0d0,max(-1.0d0,tb))
5924 if (tyb+txr .lt. 0.0d0) tk2 = pix2 - tk2
5925 thec = (rrsq*uzj-gk*bg(j)) / (rik*ri(j)*b(j))
5926 if (abs(thec) .lt. 1.0d0) then
5928 else if (thec .ge. 1.0d0) then
5930 else if (thec .le. -1.0d0) then
5934 ! see if "tk1" is entry or exit point; check t=0 point;
5935 ! "ti" is exit point, "tf" is entry point
5937 cosine = min(1.0d0,max(-1.0d0, &
5938 (uzj*gk-uxj*rik)/(b(j)*rr)))
5939 if ((acos(cosine)-ther(j))*(tk2-tk1) .le. 0.0d0) then
5947 if (narc .ge. maxarc) then
5949 70 format (/,' SURFATOM -- Increase the Value',&
5953 if (tf .le. ti) then
5974 ! special case; K circle without intersections
5976 if (narc .le. 0) goto 90
5978 ! general case; sum up arclength and set connectivity code
5980 call sort2 (narc,arci,key)
5985 if (narc .gt. 1) then
5988 if (t .lt. arci(j)) then
5989 arcsum = arcsum + arci(j) - t
5990 exang = exang + ex(ni)
5992 if (jb .ge. maxarc) then
5994 80 format (/,' SURFATOM -- Increase the Value',&
5999 kent(jb) = maxarc*i + k
6001 kout(jb) = maxarc*k + i
6010 arcsum = arcsum + pix2 - t
6012 exang = exang + ex(ni)
6015 kent(jb) = maxarc*i + k
6017 kout(jb) = maxarc*k + i
6024 arclen = arclen + gr(k)*arcsum
6027 if (arclen .eq. 0.0d0) goto 170
6028 if (jb .eq. 0) goto 150
6030 ! find number of independent boundaries and check connectivity
6034 if (kout(k) .ne. 0) then
6041 if (m .eq. kent(ii)) then
6044 if (j .eq. jb) goto 150
6056 ! attempt to fix connectivity error by moving atom slightly
6060 140 format (/,' SURFATOM -- Connectivity Error at Atom',i6)
6069 ! compute the exposed surface area for the sphere of interest
6072 area = ib*pix2 + exang + arclen
6073 area = mod(area,4.0d0*pi) * rrsq
6075 ! attempt to fix negative area by moving atom slightly
6077 if (area .lt. 0.0d0) then
6080 160 format (/,' SURFATOM -- Negative Area at Atom',i6)
6091 end subroutine surfatom
6092 !----------------------------------------------------------------
6093 !----------------------------------------------------------------
6094 subroutine alloc_MD_arrays
6095 !EL Allocation of arrays used by MD module
6097 integer :: nres2,nres6
6100 !----------------------
6104 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
6105 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
6106 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
6107 allocate(fricvec(nres2,nres2))
6108 allocate(pfric_mat(nres2,nres2),vfric_mat(nres2,nres2))
6109 allocate(afric_mat(nres2,nres2),prand_mat(nres2,nres2))
6110 allocate(vrand_mat1(nres2,nres2),vrand_mat2(nres2,nres2)) !(MAXRES2,MAXRES2)
6111 allocate(pfric0_mat(nres2,nres2,0:maxflag_stoch))
6112 allocate(afric0_mat(nres2,nres2,0:maxflag_stoch))
6113 allocate(vfric0_mat(nres2,nres2,0:maxflag_stoch))
6114 allocate(prand0_mat(nres2,nres2,0:maxflag_stoch))
6115 allocate(vrand0_mat1(nres2,nres2,0:maxflag_stoch))
6116 allocate(vrand0_mat2(nres2,nres2,0:maxflag_stoch)) !(MAXRES2,MAXRES2,0:maxflag_stoch)
6117 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
6119 allocate(mt1(nres2,nres2),mt2(nres2,nres2),mt3(nres2,nres2)) !(maxres2,maxres2)
6120 !----------------------
6122 ! commom.langevin.lang0
6124 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
6125 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
6126 allocate(fricvec(nres2,nres2)) !(MAXRES2,MAXRES2)
6127 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
6128 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
6131 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2))
6132 !----------------------
6133 ! commom.hairpin in CSA module
6134 !----------------------
6135 ! common.mce in MCM_MD module
6136 !----------------------
6138 ! common /mdgrad/ in module.energy
6139 ! common /back_constr/ in module.energy
6140 ! common /qmeas/ in module.energy
6143 allocate(potEcomp(0:n_ene+4)) !(0:n_ene+4)
6145 allocate(d_t(3,0:nres2),d_a(3,0:nres2),d_t_old(3,0:nres2)) !(3,0:MAXRES2)
6146 allocate(d_a_work(nres6)) !(6*MAXRES)
6148 allocate(DM(nres2),DU1(nres2),DU2(nres2))
6149 allocate(DMorig(nres2),DU1orig(nres2),DU2orig(nres2))
6151 allocate(Gmat(nres2,nres2),A(nres2,nres2))
6152 if(.not.allocated(Ginv)) allocate(Ginv(nres2,nres2)) !in control: ergastulum
6153 allocate(Gsqrp(nres2,nres2),Gsqrm(nres2,nres2),Gvec(nres2,nres2)) !(maxres2,maxres2)
6155 allocate(Geigen(nres2)) !(maxres2)
6156 if(.not.allocated(vtot)) allocate(vtot(nres2)) !(maxres2)
6157 ! common /inertia/ in io_conf: parmread
6158 ! real(kind=8),dimension(:),allocatable :: ISC,msc !(ntyp+1)
6159 ! common /langevin/in io read_MDpar
6160 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
6161 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
6162 ! in io_conf: parmread
6163 ! real(kind=8),dimension(:),allocatable :: restok !(ntyp+1)
6164 ! common /mdpmpi/ in control: ergastulum
6165 if(.not.allocated(ng_start)) allocate(ng_start(0:nfgtasks-1))
6166 if(.not.allocated(ng_counts)) allocate(ng_counts(0:nfgtasks-1))
6167 if(.not.allocated(nginv_counts)) allocate(nginv_counts(0:nfgtasks-1)) !(0:MaxProcs-1)
6168 if(.not.allocated(nginv_start)) allocate(nginv_start(0:nfgtasks)) !(0:MaxProcs)
6169 !----------------------
6170 ! common.muca in read_muca
6171 ! common /double_muca/
6172 ! real(kind=8) :: elow,ehigh,factor,hbin,factor_min
6173 ! real(kind=8),dimension(:),allocatable :: emuca,nemuca,&
6174 ! nemuca2,hist !(4*maxres)
6175 ! common /integer_muca/
6176 ! integer :: nmuca,imtime,muca_smooth
6178 ! real(kind=8),dimension(:),allocatable :: elowi,ehighi !(maxprocs)
6179 !----------------------
6181 ! common /mdgrad/ in module.energy
6182 ! common /back_constr/ in module.energy
6183 ! common /qmeas/ in module.energy
6187 allocate(d_t_work(nres6),d_t_work_new(nres6),d_af_work(nres6))
6188 allocate(d_as_work(nres6),kinetic_force(nres6)) !(MAXRES6)
6189 allocate(d_t_new(3,0:nres2),d_a_old(3,0:nres2),d_a_short(3,0:nres2)) !,d_a !(3,0:MAXRES2)
6190 allocate(stdforcp(nres),stdforcsc(nres)) !(MAXRES)
6191 !----------------------
6193 allocate(D_ban(nres6)) !(MAXRES6) maxres6=6*maxres
6194 ! common /stochcalc/ stochforcvec
6195 allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
6196 !----------------------
6198 end subroutine alloc_MD_arrays
6199 !-----------------------------------------------------------------------------
6200 !-----------------------------------------------------------------------------