2 !-----------------------------------------------------------------------------
15 !-----------------------------------------------------------------------------
17 ! common /mdgrad/ in module.energy
18 ! common /back_constr/ in module.energy
19 ! common /qmeas/ in module.energy
23 real(kind=8),dimension(:),allocatable :: d_t_work,&
24 d_t_work_new,d_af_work,d_as_work,kinetic_force !(MAXRES6)
25 real(kind=8),dimension(:,:),allocatable :: d_t_new,&
26 d_a_old,d_a_short!,d_a !(3,0:MAXRES2)
27 ! real(kind=8),dimension(:),allocatable :: d_a_work !(6*MAXRES)
28 ! real(kind=8),dimension(:,:),allocatable :: Gmat,Ginv,A,&
29 ! Gsqrp,Gsqrm,Gvec !(maxres2,maxres2)
30 ! real(kind=8),dimension(:),allocatable :: Geigen !(maxres2)
31 ! integer :: dimen,dimen1,dimen3
32 ! integer :: lang,count_reset_moment,count_reset_vel
33 ! logical :: reset_moment,reset_vel,rattle,RESPA
36 ! real(kind=8) :: rwat,etawat,stdfp,cPoise
37 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
38 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
39 real(kind=8),dimension(:),allocatable :: stdforcp,stdforcsc !(MAXRES)
40 !-----------------------------------------------------------------------------
44 ! ###################################################
45 ! ## COPYRIGHT (C) 1992 by Jay William Ponder ##
46 ! ## All Rights Reserved ##
47 ! ###################################################
49 ! #############################################################
51 ! ## sizes.i -- parameter values to set array dimensions ##
53 ! #############################################################
56 ! "sizes.i" sets values for critical array dimensions used
57 ! throughout the software; these parameters will fix the size
58 ! of the largest systems that can be handled; values too large
59 ! for the computer's memory and/or swap space to accomodate
60 ! will result in poor performance or outright failure
62 ! parameter: maximum allowed number of:
64 ! maxatm atoms in the molecular system
65 ! maxval atoms directly bonded to an atom
66 ! maxgrp ! user-defined groups of atoms
67 ! maxtyp force field atom type definitions
68 ! maxclass force field atom class definitions
69 ! maxkey lines in the keyword file
70 ! maxrot bonds for torsional rotation
71 ! maxvar optimization variables (vector storage)
72 ! maxopt optimization variables (matrix storage)
73 ! maxhess off-diagonal Hessian elements
74 ! maxlight sites for method of lights neighbors
75 ! maxvib vibrational frequencies
76 ! maxgeo distance geometry points
77 ! maxcell unit cells in replicated crystal
78 ! maxring 3-, 4-, or 5-membered rings
79 ! maxfix geometric restraints
80 ! maxbio biopolymer atom definitions
81 ! maxres residues in the macromolecule
82 ! maxamino amino acid residue types
83 ! maxnuc nucleic acid residue types
84 ! maxbnd covalent bonds in molecular system
85 ! maxang bond angles in molecular system
86 ! maxtors torsional angles in molecular system
87 ! maxpi atoms in conjugated pisystem
88 ! maxpib covalent bonds involving pisystem
89 ! maxpit torsional angles involving pisystem
92 !el integer maxatm,maxval,maxgrp
93 !el integer maxtyp,maxclass,maxkey
94 !el integer maxrot,maxopt
95 !el integer maxhess,maxlight,maxvib
96 !el integer maxgeo,maxcell,maxring
97 !el integer maxfix,maxbio
98 !el integer maxamino,maxnuc,maxbnd
99 !el integer maxang,maxtors,maxpi
100 !el integer maxpib,maxpit
101 ! integer :: maxatm !=2*nres !maxres2 maxres2=2*maxres
102 ! integer,parameter :: maxval=8
103 ! integer,parameter :: maxgrp=1000
104 ! integer,parameter :: maxtyp=3000
105 ! integer,parameter :: maxclass=500
106 ! integer,parameter :: maxkey=10000
107 ! integer,parameter :: maxrot=1000
108 ! integer,parameter :: maxopt=1000
109 ! integer,parameter :: maxhess=1000000
110 ! integer :: maxlight !=8*maxatm
111 ! integer,parameter :: maxvib=1000
112 ! integer,parameter :: maxgeo=1000
113 ! integer,parameter :: maxcell=10000
114 ! integer,parameter :: maxring=10000
115 ! integer,parameter :: maxfix=10000
116 ! integer,parameter :: maxbio=10000
117 ! integer,parameter :: maxamino=31
118 ! integer,parameter :: maxnuc=12
119 ! integer :: maxbnd !=2*maxatm
120 ! integer :: maxang !=3*maxatm
121 ! integer :: maxtors !=4*maxatm
122 ! integer,parameter :: maxpi=100
123 ! integer,parameter :: maxpib=2*maxpi
124 ! integer,parameter :: maxpit=4*maxpi
125 !-----------------------------------------------------------------------------
126 ! Maximum number of seed
127 ! integer,parameter :: max_seed=1
128 !-----------------------------------------------------------------------------
129 real(kind=8),dimension(:),allocatable :: stochforcvec !(MAXRES6) maxres6=6*maxres
130 ! common /stochcalc/ stochforcvec
131 !-----------------------------------------------------------------------------
132 ! common /przechowalnia/ subroutines: rattle1,rattle2,rattle_brown
133 real(kind=8),dimension(:,:),allocatable :: GGinv !(2*nres,2*nres) maxres2=2*maxres
134 real(kind=8),dimension(:,:,:),allocatable :: gdc !(3,2*nres,2*nres) maxres2=2*maxres
135 real(kind=8),dimension(:,:),allocatable :: Cmat !(2*nres,2*nres) maxres2=2*maxres
136 !-----------------------------------------------------------------------------
137 ! common /syfek/ subroutines: friction_force,setup_fricmat
138 !el real(kind=8),dimension(:),allocatable :: gamvec !(MAXRES6) or (MAXRES2)
139 !-----------------------------------------------------------------------------
140 ! common /przechowalnia/ subroutines: friction_force,setup_fricmat
141 real(kind=8),dimension(:,:),allocatable :: ginvfric !(2*nres,2*nres) !maxres2=2*maxres
142 !-----------------------------------------------------------------------------
143 ! common /przechowalnia/ subroutine: setup_fricmat
144 !el real(kind=8),dimension(:,:),allocatable :: fcopy !(2*nres,2*nres)
145 !-----------------------------------------------------------------------------
148 !-----------------------------------------------------------------------------
150 !-----------------------------------------------------------------------------
152 !-----------------------------------------------------------------------------
153 subroutine brown_step(itime)
154 !------------------------------------------------
155 ! Perform a single Euler integration step of Brownian dynamics
156 !------------------------------------------------
157 ! implicit real*8 (a-h,o-z)
159 use control, only: tcpu
162 ! use io_conf, only:cartprint
163 ! include 'DIMENSIONS'
167 ! include 'COMMON.CONTROL'
168 ! include 'COMMON.VAR'
169 ! include 'COMMON.MD'
171 ! include 'COMMON.LANGEVIN'
173 ! include 'COMMON.LANGEVIN.lang0'
175 ! include 'COMMON.CHAIN'
176 ! include 'COMMON.DERIV'
177 ! include 'COMMON.GEO'
178 ! include 'COMMON.LOCAL'
179 ! include 'COMMON.INTERACT'
180 ! include 'COMMON.IOUNITS'
181 ! include 'COMMON.NAMES'
182 ! include 'COMMON.TIME1'
183 real(kind=8),dimension(6*nres) :: zapas !(MAXRES6) maxres6=6*maxres
184 integer :: rstcount !ilen,
186 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
187 real(kind=8),dimension(6*nres,2*nres) :: Bmat,GBmat,Tmat !(MAXRES6,MAXRES2) (maxres2=2*maxres,maxres6=6*maxres)
188 real(kind=8),dimension(2*nres,2*nres) :: Cmat_,Cinv !(maxres2,maxres2) maxres2=2*maxres
189 real(kind=8),dimension(6*nres,6*nres) :: Pmat !(maxres6,maxres6) maxres6=6*maxres
190 real(kind=8),dimension(6*nres) :: Td !(maxres6) maxres6=6*maxres
191 real(kind=8),dimension(2*nres) :: ppvec !(maxres2) maxres2=2*maxres
192 !el common /stochcalc/ stochforcvec
193 !el real(kind=8),dimension(3) :: cm !el
194 !el common /gucio/ cm
196 logical :: lprn = .false.,lprn1 = .false.
197 integer :: maxiter = 5
198 real(kind=8) :: difftol = 1.0d-5
199 real(kind=8) :: xx,diffmax,blen2,diffbond,tt0
200 integer :: i,j,nbond,k,ind,ind1,iter
201 integer :: nres2,nres6
206 if (.not.allocated(stochforcvec)) allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
210 if (itype(i,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"
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
889 t_langsetup=MPI_Wtime()-tt0
892 t_langsetup=tcpu()-tt0
895 do itime=1,n_timestep
897 if (large.and. mod(itime,ntwe).eq.0) &
898 write (iout,*) "itime",itime
900 if (lang.gt.0 .and. surfarea .and. &
901 mod(itime,reset_fricmat).eq.0) then
902 if (lang.eq.2 .or. lang.eq.3) then
906 call sd_verlet_p_setup
908 call sd_verlet_ciccotti_setup
912 pfric0_mat(i,j,0)=pfric_mat(i,j)
913 afric0_mat(i,j,0)=afric_mat(i,j)
914 vfric0_mat(i,j,0)=vfric_mat(i,j)
915 prand0_mat(i,j,0)=prand_mat(i,j)
916 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
917 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
922 flag_stoch(i)=.false.
925 else if (lang.eq.1 .or. lang.eq.4) then
928 write (iout,'(a,i10)') &
929 "Friction matrix reset based on surface area, itime",itime
931 if (reset_vel .and. tbf .and. lang.eq.0 &
932 .and. mod(itime,count_reset_vel).eq.0) then
934 write(iout,'(a,f20.2)') &
935 "Velocities reset to random values, time",totT
938 d_t_old(j,i)=d_t(j,i)
942 if (reset_moment .and. mod(itime,count_reset_moment).eq.0) then
946 d_t(j,0)=d_t(j,0)-vcm(j)
949 kinetic_T=2.0d0/(dimen3*Rb)*EK
950 scalfac=dsqrt(T_bath/kinetic_T)
951 write(iout,'(a,f20.2)') "Momenta zeroed out, time",totT
954 d_t_old(j,i)=scalfac*d_t(j,i)
960 ! Time-reversible RESPA algorithm
961 ! (Tuckerman et al., J. Chem. Phys., 97, 1990, 1992)
962 call RESPA_step(itime)
964 ! Variable time step algorithm.
965 call velverlet_step(itime)
969 call brown_step(itime)
971 print *,"Brown dynamics not here!"
973 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
979 if (mod(itime,ntwe).eq.0) call statout(itime)
993 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1.and.mnum.ne.5) then
996 v_work(ind)=d_t(j,i+nres)
1001 write (66,'(80f10.5)') &
1002 ((d_t(j,i),j=1,3),i=0,nres-1),((d_t(j,i+nres),j=1,3),i=1,nres)
1006 v_transf(i)=v_transf(i)+gvec(j,i)*v_work(j)
1008 v_transf(i)= v_transf(i)*dsqrt(geigen(i))
1010 write (67,'(80f10.5)') (v_transf(i),i=1,ind)
1013 if (mod(itime,ntwx).eq.0) then
1014 write (tytul,'("time",f8.2)') totT
1016 call hairpin(.true.,nharp,iharp)
1017 call secondary2(.true.)
1018 call pdbout(potE,tytul,ipdb)
1023 if (rstcount.eq.1000.or.itime.eq.n_timestep) then
1024 open(irest2,file=rest2name,status='unknown')
1025 write(irest2,*) totT,EK,potE,totE,t_bath
1027 ! AL 4/17/17: Now writing d_t(0,:) too
1029 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
1031 ! AL 4/17/17: Now writing d_c(0,:) too
1033 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
1041 t_MD=MPI_Wtime()-tt0
1045 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))') &
1047 'MD calculations setup:',t_MDsetup,&
1048 'Energy & gradient evaluation:',t_enegrad,&
1049 'Stochastic MD setup:',t_langsetup,&
1050 'Stochastic MD step setup:',t_sdsetup,&
1052 write (iout,'(/28(1h=),a25,27(1h=))') &
1053 ' End of MD calculation '
1055 write (iout,*) "time for etotal",t_etotal," elong",t_elong,&
1057 write (iout,*) "time_fric",time_fric," time_stoch",time_stoch,&
1058 " time_fricmatmult",time_fricmatmult," time_fsample ",&
1063 !-----------------------------------------------------------------------------
1064 subroutine velverlet_step(itime)
1065 !-------------------------------------------------------------------------------
1066 ! Perform a single velocity Verlet step; the time step can be rescaled if
1067 ! increments in accelerations exceed the threshold
1068 !-------------------------------------------------------------------------------
1069 ! implicit real*8 (a-h,o-z)
1070 ! include 'DIMENSIONS'
1072 use control, only:tcpu
1076 integer :: ierror,ierrcode
1077 real(kind=8) :: errcode
1079 ! include 'COMMON.SETUP'
1080 ! include 'COMMON.VAR'
1081 ! include 'COMMON.MD'
1083 ! include 'COMMON.LANGEVIN'
1085 ! include 'COMMON.LANGEVIN.lang0'
1087 ! include 'COMMON.CHAIN'
1088 ! include 'COMMON.DERIV'
1089 ! include 'COMMON.GEO'
1090 ! include 'COMMON.LOCAL'
1091 ! include 'COMMON.INTERACT'
1092 ! include 'COMMON.IOUNITS'
1093 ! include 'COMMON.NAMES'
1094 ! include 'COMMON.TIME1'
1095 ! include 'COMMON.MUCA'
1096 real(kind=8),dimension(3) :: vcm,incr
1097 real(kind=8),dimension(3) :: L
1098 integer :: count,rstcount !ilen,
1100 character(len=50) :: tytul
1101 integer :: maxcount_scale = 20
1102 !el common /gucio/ cm
1103 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1104 !el common /stochcalc/ stochforcvec
1105 integer :: itime,icount_scale,itime_scal,i,j,ifac_time
1107 real(kind=8) :: epdrift,tt0,fac_time
1109 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1115 else if (lang.eq.2 .or. lang.eq.3) then
1117 call stochastic_force(stochforcvec)
1120 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1122 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1129 icount_scale=icount_scale+1
1130 if (icount_scale.gt.maxcount_scale) then
1132 "ERROR: too many attempts at scaling down the time step. ",&
1133 "amax=",amax,"epdrift=",epdrift,&
1134 "damax=",damax,"edriftmax=",edriftmax,&
1138 call MPI_Abort(MPI_COMM_WORLD,IERROR,IERRCODE)
1142 ! First step of the velocity Verlet algorithm
1147 else if (lang.eq.3) then
1149 call sd_verlet1_ciccotti
1151 else if (lang.eq.1) then
1156 ! Build the chain from the newly calculated coordinates
1157 call chainbuild_cart
1158 if (rattle) call rattle1
1160 if (large.and. mod(itime,ntwe).eq.0) then
1161 write (iout,*) "Cartesian and internal coordinates: step 1"
1166 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
1167 (dc(j,i+nres),j=1,3)
1169 write (iout,*) "Accelerations"
1171 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1172 (d_a(j,i+nres),j=1,3)
1174 write (iout,*) "Velocities, step 1"
1176 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1177 (d_t(j,i+nres),j=1,3)
1186 ! Calculate energy and forces
1188 call etotal(potEcomp)
1189 ! AL 4/17/17: Reduce the steps if NaNs occurred.
1190 if (potEcomp(0).gt.0.99e20 .or. isnan(potEcomp(0)).gt.0) then
1195 if (large.and. mod(itime,ntwe).eq.0) &
1196 call enerprint(potEcomp)
1199 t_etotal=t_etotal+MPI_Wtime()-tt0
1201 t_etotal=t_etotal+tcpu()-tt0
1204 potE=potEcomp(0)-potEcomp(20)
1206 ! Get the new accelerations
1209 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1211 t_enegrad=t_enegrad+tcpu()-tt0
1213 ! Determine maximum acceleration and scale down the timestep if needed
1215 amax=amax/(itime_scal+1)**2
1216 call predict_edrift(epdrift)
1217 if (amax/(itime_scal+1).gt.damax .or. epdrift.gt.edriftmax) then
1218 ! Maximum acceleration or maximum predicted energy drift exceeded, rescale the time step
1220 ifac_time=dmax1(dlog(amax/damax),dlog(epdrift/edriftmax)) &
1222 itime_scal=itime_scal+ifac_time
1223 ! fac_time=dmin1(damax/amax,0.5d0)
1224 fac_time=0.5d0**ifac_time
1225 d_time=d_time*fac_time
1226 if (lang.eq.2 .or. lang.eq.3) then
1228 ! write (iout,*) "Calling sd_verlet_setup: 1"
1229 ! Rescale the stochastic forces and recalculate or restore
1230 ! the matrices of tinker integrator
1231 if (itime_scal.gt.maxflag_stoch) then
1232 if (large) write (iout,'(a,i5,a)') &
1233 "Calculate matrices for stochastic step;",&
1234 " itime_scal ",itime_scal
1236 call sd_verlet_p_setup
1238 call sd_verlet_ciccotti_setup
1240 write (iout,'(2a,i3,a,i3,1h.)') &
1241 "Warning: cannot store matrices for stochastic",&
1242 " integration because the index",itime_scal,&
1243 " is greater than",maxflag_stoch
1244 write (iout,'(2a)')"Increase MAXFLAG_STOCH or use direct",&
1245 " integration Langevin algorithm for better efficiency."
1246 else if (flag_stoch(itime_scal)) then
1247 if (large) write (iout,'(a,i5,a,l1)') &
1248 "Restore matrices for stochastic step; itime_scal ",&
1249 itime_scal," flag ",flag_stoch(itime_scal)
1252 pfric_mat(i,j)=pfric0_mat(i,j,itime_scal)
1253 afric_mat(i,j)=afric0_mat(i,j,itime_scal)
1254 vfric_mat(i,j)=vfric0_mat(i,j,itime_scal)
1255 prand_mat(i,j)=prand0_mat(i,j,itime_scal)
1256 vrand_mat1(i,j)=vrand0_mat1(i,j,itime_scal)
1257 vrand_mat2(i,j)=vrand0_mat2(i,j,itime_scal)
1261 if (large) write (iout,'(2a,i5,a,l1)') &
1262 "Calculate & store matrices for stochastic step;",&
1263 " itime_scal ",itime_scal," flag ",flag_stoch(itime_scal)
1265 call sd_verlet_p_setup
1267 call sd_verlet_ciccotti_setup
1269 flag_stoch(ifac_time)=.true.
1272 pfric0_mat(i,j,itime_scal)=pfric_mat(i,j)
1273 afric0_mat(i,j,itime_scal)=afric_mat(i,j)
1274 vfric0_mat(i,j,itime_scal)=vfric_mat(i,j)
1275 prand0_mat(i,j,itime_scal)=prand_mat(i,j)
1276 vrand0_mat1(i,j,itime_scal)=vrand_mat1(i,j)
1277 vrand0_mat2(i,j,itime_scal)=vrand_mat2(i,j)
1281 fac_time=1.0d0/dsqrt(fac_time)
1283 stochforcvec(i)=fac_time*stochforcvec(i)
1286 else if (lang.eq.1) then
1287 ! Rescale the accelerations due to stochastic forces
1288 fac_time=1.0d0/dsqrt(fac_time)
1290 d_as_work(i)=d_as_work(i)*fac_time
1293 if (large) write (iout,'(a,i10,a,f8.6,a,i3,a,i3)') &
1294 "itime",itime," Timestep scaled down to ",&
1295 d_time," ifac_time",ifac_time," itime_scal",itime_scal
1297 ! Second step of the velocity Verlet algorithm
1302 else if (lang.eq.3) then
1304 call sd_verlet2_ciccotti
1306 else if (lang.eq.1) then
1311 if (rattle) call rattle2
1314 if (d_time.ne.d_time0) then
1317 if (lang.eq.2 .or. lang.eq.3) then
1318 if (large) write (iout,'(a)') &
1319 "Restore original matrices for stochastic step"
1320 ! write (iout,*) "Calling sd_verlet_setup: 2"
1321 ! Restore the matrices of tinker integrator if the time step has been restored
1324 pfric_mat(i,j)=pfric0_mat(i,j,0)
1325 afric_mat(i,j)=afric0_mat(i,j,0)
1326 vfric_mat(i,j)=vfric0_mat(i,j,0)
1327 prand_mat(i,j)=prand0_mat(i,j,0)
1328 vrand_mat1(i,j)=vrand0_mat1(i,j,0)
1329 vrand_mat2(i,j)=vrand0_mat2(i,j,0)
1338 ! Calculate the kinetic and the total energy and the kinetic temperature
1342 ! call kinetic1(EK1)
1343 ! write (iout,*) "step",itime," EK",EK," EK1",EK1
1345 ! Couple the system to Berendsen bath if needed
1346 if (tbf .and. lang.eq.0) then
1349 kinetic_T=2.0d0/(dimen3*Rb)*EK
1350 ! Backup the coordinates, velocities, and accelerations
1354 d_t_old(j,i)=d_t(j,i)
1355 d_a_old(j,i)=d_a(j,i)
1359 if (mod(itime,ntwe).eq.0 .and. large) then
1360 write (iout,*) "Velocities, step 2"
1362 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1363 (d_t(j,i+nres),j=1,3)
1368 end subroutine velverlet_step
1369 !-----------------------------------------------------------------------------
1370 subroutine RESPA_step(itime)
1371 !-------------------------------------------------------------------------------
1372 ! Perform a single RESPA step.
1373 !-------------------------------------------------------------------------------
1374 ! implicit real*8 (a-h,o-z)
1375 ! include 'DIMENSIONS'
1379 use control, only:tcpu
1381 ! use io_conf, only:cartprint
1384 integer :: IERROR,ERRCODE
1386 ! include 'COMMON.SETUP'
1387 ! include 'COMMON.CONTROL'
1388 ! include 'COMMON.VAR'
1389 ! include 'COMMON.MD'
1391 ! include 'COMMON.LANGEVIN'
1393 ! include 'COMMON.LANGEVIN.lang0'
1395 ! include 'COMMON.CHAIN'
1396 ! include 'COMMON.DERIV'
1397 ! include 'COMMON.GEO'
1398 ! include 'COMMON.LOCAL'
1399 ! include 'COMMON.INTERACT'
1400 ! include 'COMMON.IOUNITS'
1401 ! include 'COMMON.NAMES'
1402 ! include 'COMMON.TIME1'
1403 real(kind=8),dimension(0:n_ene) :: energia_short,energia_long
1404 real(kind=8),dimension(3) :: L,vcm,incr
1405 real(kind=8),dimension(3,0:2*nres) :: dc_old0,d_t_old0,d_a_old0 !(3,0:maxres2) maxres2=2*maxres
1406 logical :: PRINT_AMTS_MSG = .false.
1407 integer :: count,rstcount !ilen,
1409 character(len=50) :: tytul
1410 integer :: maxcount_scale = 10
1411 !el common /gucio/ cm
1412 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1413 !el common /stochcalc/ stochforcvec
1414 integer :: itime,itt,i,j,itsplit
1416 !el common /cipiszcze/ itt
1418 real(kind=8) :: epdrift,tt0,epdriftmax
1421 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1425 if (large.and. mod(itime,ntwe).eq.0) then
1426 write (iout,*) "***************** RESPA itime",itime
1427 write (iout,*) "Cartesian and internal coordinates: step 0"
1429 call pdbout(0.0d0,"cipiszcze",iout)
1431 write (iout,*) "Accelerations from long-range forces"
1433 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1434 (d_a(j,i+nres),j=1,3)
1436 write (iout,*) "Velocities, step 0"
1438 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1439 (d_t(j,i+nres),j=1,3)
1444 ! Perform the initial RESPA step (increment velocities)
1445 ! write (iout,*) "*********************** RESPA ini"
1448 if (mod(itime,ntwe).eq.0 .and. large) then
1449 write (iout,*) "Velocities, end"
1451 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1452 (d_t(j,i+nres),j=1,3)
1456 ! Compute the short-range forces
1462 ! 7/2/2009 commented out
1464 ! call etotal_short(energia_short)
1467 ! 7/2/2009 Copy accelerations due to short-lange forces from previous MD step
1470 d_a(j,i)=d_a_short(j,i)
1474 if (large.and. mod(itime,ntwe).eq.0) then
1475 write (iout,*) "energia_short",energia_short(0)
1476 write (iout,*) "Accelerations from short-range forces"
1478 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1479 (d_a(j,i+nres),j=1,3)
1484 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1486 t_enegrad=t_enegrad+tcpu()-tt0
1491 d_t_old(j,i)=d_t(j,i)
1492 d_a_old(j,i)=d_a(j,i)
1495 ! 6/30/08 A-MTS: attempt at increasing the split number
1498 dc_old0(j,i)=dc_old(j,i)
1499 d_t_old0(j,i)=d_t_old(j,i)
1500 d_a_old0(j,i)=d_a_old(j,i)
1503 if (ntime_split.gt.ntime_split0) ntime_split=ntime_split/2
1504 if (ntime_split.lt.ntime_split0) ntime_split=ntime_split0
1511 ! write (iout,*) "itime",itime," ntime_split",ntime_split
1512 ! Split the time step
1513 d_time=d_time0/ntime_split
1514 ! Perform the short-range RESPA steps (velocity Verlet increments of
1515 ! positions and velocities using short-range forces)
1516 ! write (iout,*) "*********************** RESPA split"
1517 do itsplit=1,ntime_split
1520 else if (lang.eq.2 .or. lang.eq.3) then
1522 call stochastic_force(stochforcvec)
1525 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1527 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1532 ! First step of the velocity Verlet algorithm
1537 else if (lang.eq.3) then
1539 call sd_verlet1_ciccotti
1541 else if (lang.eq.1) then
1546 ! Build the chain from the newly calculated coordinates
1547 call chainbuild_cart
1548 if (rattle) call rattle1
1550 if (large.and. mod(itime,ntwe).eq.0) then
1551 write (iout,*) "***** ITSPLIT",itsplit
1552 write (iout,*) "Cartesian and internal coordinates: step 1"
1553 call pdbout(0.0d0,"cipiszcze",iout)
1556 write (iout,*) "Velocities, step 1"
1558 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1559 (d_t(j,i+nres),j=1,3)
1568 ! Calculate energy and forces
1570 call etotal_short(energia_short)
1571 ! AL 4/17/17: Exit itime_split loop when energy goes infinite
1572 if (energia_short(0).gt.0.99e20 .or. isnan(energia_short(0)) ) then
1573 if (PRINT_AMTS_MSG) &
1574 write (iout,*) "Infinities/NaNs in energia_short",energia_short(0),"; increasing ntime_split to",ntime_split
1575 ntime_split=ntime_split*2
1576 if (ntime_split.gt.maxtime_split) then
1579 "Cannot rescue the run; aborting job. Retry with a smaller time step"
1581 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1584 "Cannot rescue the run; terminating. Retry with a smaller time step"
1590 if (large.and. mod(itime,ntwe).eq.0) &
1591 call enerprint(energia_short)
1594 t_eshort=t_eshort+MPI_Wtime()-tt0
1596 t_eshort=t_eshort+tcpu()-tt0
1600 ! Get the new accelerations
1602 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
1605 d_a_short(j,i)=d_a(j,i)
1609 if (large.and. mod(itime,ntwe).eq.0) then
1610 write (iout,*)"energia_short",energia_short(0)
1611 write (iout,*) "Accelerations from short-range forces"
1613 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1614 (d_a(j,i+nres),j=1,3)
1619 ! Determine maximum acceleration and scale down the timestep if needed
1621 amax=amax/ntime_split**2
1622 call predict_edrift(epdrift)
1623 if (ntwe.gt.0 .and. large .and. mod(itime,ntwe).eq.0) &
1624 write (iout,*) "amax",amax," damax",damax,&
1625 " epdrift",epdrift," epdriftmax",epdriftmax
1626 ! Exit loop and try with increased split number if the change of
1627 ! acceleration is too big
1628 if (amax.gt.damax .or. epdrift.gt.edriftmax) then
1629 if (ntime_split.lt.maxtime_split) then
1631 ntime_split=ntime_split*2
1632 ! AL 4/17/17: We should exit the itime_split loop when acceleration change is too big
1636 dc_old(j,i)=dc_old0(j,i)
1637 d_t_old(j,i)=d_t_old0(j,i)
1638 d_a_old(j,i)=d_a_old0(j,i)
1641 if (PRINT_AMTS_MSG) then
1642 write (iout,*) "acceleration/energy drift too large",amax,&
1643 epdrift," split increased to ",ntime_split," itime",itime,&
1649 "Uh-hu. Bumpy landscape. Maximum splitting number",&
1651 " already reached!!! Trying to carry on!"
1655 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1657 t_enegrad=t_enegrad+tcpu()-tt0
1659 ! Second step of the velocity Verlet algorithm
1664 else if (lang.eq.3) then
1666 call sd_verlet2_ciccotti
1668 else if (lang.eq.1) then
1673 if (rattle) call rattle2
1674 ! Backup the coordinates, velocities, and accelerations
1678 d_t_old(j,i)=d_t(j,i)
1679 d_a_old(j,i)=d_a(j,i)
1686 ! Restore the time step
1688 ! Compute long-range forces
1695 call etotal_long(energia_long)
1696 if (energia_long(0).gt.0.99e20 .or. isnan(energia_long(0))) then
1699 "Infinitied/NaNs in energia_long, Aborting MPI job."
1701 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1703 write (iout,*) "Infinitied/NaNs in energia_long, terminating."
1707 if (large.and. mod(itime,ntwe).eq.0) &
1708 call enerprint(energia_long)
1711 t_elong=t_elong+MPI_Wtime()-tt0
1713 t_elong=t_elong+tcpu()-tt0
1719 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1721 t_enegrad=t_enegrad+tcpu()-tt0
1723 ! Compute accelerations from long-range forces
1725 if (large.and. mod(itime,ntwe).eq.0) then
1726 write (iout,*) "energia_long",energia_long(0)
1727 write (iout,*) "Cartesian and internal coordinates: step 2"
1729 call pdbout(0.0d0,"cipiszcze",iout)
1731 write (iout,*) "Accelerations from long-range forces"
1733 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1734 (d_a(j,i+nres),j=1,3)
1736 write (iout,*) "Velocities, step 2"
1738 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1739 (d_t(j,i+nres),j=1,3)
1743 ! Compute the final RESPA step (increment velocities)
1744 ! write (iout,*) "*********************** RESPA fin"
1746 ! Compute the complete potential energy
1748 potEcomp(i)=energia_short(i)+energia_long(i)
1750 potE=potEcomp(0)-potEcomp(20)
1751 ! potE=energia_short(0)+energia_long(0)
1754 ! Calculate the kinetic and the total energy and the kinetic temperature
1757 ! Couple the system to Berendsen bath if needed
1758 if (tbf .and. lang.eq.0) then
1761 kinetic_T=2.0d0/(dimen3*Rb)*EK
1762 ! Backup the coordinates, velocities, and accelerations
1764 if (mod(itime,ntwe).eq.0 .and. large) then
1765 write (iout,*) "Velocities, end"
1767 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1768 (d_t(j,i+nres),j=1,3)
1773 end subroutine RESPA_step
1774 !-----------------------------------------------------------------------------
1775 subroutine RESPA_vel
1776 ! First and last RESPA step (incrementing velocities using long-range
1779 ! implicit real*8 (a-h,o-z)
1780 ! include 'DIMENSIONS'
1781 ! include 'COMMON.CONTROL'
1782 ! include 'COMMON.VAR'
1783 ! include 'COMMON.MD'
1784 ! include 'COMMON.CHAIN'
1785 ! include 'COMMON.DERIV'
1786 ! include 'COMMON.GEO'
1787 ! include 'COMMON.LOCAL'
1788 ! include 'COMMON.INTERACT'
1789 ! include 'COMMON.IOUNITS'
1790 ! include 'COMMON.NAMES'
1791 integer :: i,j,inres,mnum
1794 d_t(j,0)=d_t(j,0)+0.5d0*d_a(j,0)*d_time
1798 d_t(j,i)=d_t(j,i)+0.5d0*d_a(j,i)*d_time
1803 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1804 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1805 .and.(mnum.ne.5)) then
1808 d_t(j,inres)=d_t(j,inres)+0.5d0*d_a(j,inres)*d_time
1813 end subroutine RESPA_vel
1814 !-----------------------------------------------------------------------------
1816 ! Applying velocity Verlet algorithm - step 1 to coordinates
1818 ! implicit real*8 (a-h,o-z)
1819 ! include 'DIMENSIONS'
1820 ! include 'COMMON.CONTROL'
1821 ! include 'COMMON.VAR'
1822 ! include 'COMMON.MD'
1823 ! include 'COMMON.CHAIN'
1824 ! include 'COMMON.DERIV'
1825 ! include 'COMMON.GEO'
1826 ! include 'COMMON.LOCAL'
1827 ! include 'COMMON.INTERACT'
1828 ! include 'COMMON.IOUNITS'
1829 ! include 'COMMON.NAMES'
1830 real(kind=8) :: adt,adt2
1831 integer :: i,j,inres,mnum
1834 write (iout,*) "VELVERLET1 START: DC"
1836 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1837 (dc(j,i+nres),j=1,3)
1841 adt=d_a_old(j,0)*d_time
1843 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1844 d_t_new(j,0)=d_t_old(j,0)+adt2
1845 d_t(j,0)=d_t_old(j,0)+adt
1849 adt=d_a_old(j,i)*d_time
1851 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1852 d_t_new(j,i)=d_t_old(j,i)+adt2
1853 d_t(j,i)=d_t_old(j,i)+adt
1858 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1859 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1860 .and.(mnum.ne.5)) then
1863 adt=d_a_old(j,inres)*d_time
1865 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1866 d_t_new(j,inres)=d_t_old(j,inres)+adt2
1867 d_t(j,inres)=d_t_old(j,inres)+adt
1872 write (iout,*) "VELVERLET1 END: DC"
1874 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1875 (dc(j,i+nres),j=1,3)
1879 end subroutine verlet1
1880 !-----------------------------------------------------------------------------
1882 ! Step 2 of the velocity Verlet algorithm: update velocities
1884 ! implicit real*8 (a-h,o-z)
1885 ! include 'DIMENSIONS'
1886 ! include 'COMMON.CONTROL'
1887 ! include 'COMMON.VAR'
1888 ! include 'COMMON.MD'
1889 ! include 'COMMON.CHAIN'
1890 ! include 'COMMON.DERIV'
1891 ! include 'COMMON.GEO'
1892 ! include 'COMMON.LOCAL'
1893 ! include 'COMMON.INTERACT'
1894 ! include 'COMMON.IOUNITS'
1895 ! include 'COMMON.NAMES'
1896 integer :: i,j,inres,mnum
1899 d_t(j,0)=d_t_new(j,0)+0.5d0*d_a(j,0)*d_time
1903 d_t(j,i)=d_t_new(j,i)+0.5d0*d_a(j,i)*d_time
1908 ! iti=iabs(itype(i,mnum))
1909 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1910 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1911 .and.(mnum.ne.5)) then
1914 d_t(j,inres)=d_t_new(j,inres)+0.5d0*d_a(j,inres)*d_time
1919 end subroutine verlet2
1920 !-----------------------------------------------------------------------------
1921 subroutine sddir_precalc
1922 ! Applying velocity Verlet algorithm - step 1 to coordinates
1923 ! implicit real*8 (a-h,o-z)
1924 ! include 'DIMENSIONS'
1930 ! include 'COMMON.CONTROL'
1931 ! include 'COMMON.VAR'
1932 ! include 'COMMON.MD'
1934 ! include 'COMMON.LANGEVIN'
1936 ! include 'COMMON.LANGEVIN.lang0'
1938 ! include 'COMMON.CHAIN'
1939 ! include 'COMMON.DERIV'
1940 ! include 'COMMON.GEO'
1941 ! include 'COMMON.LOCAL'
1942 ! include 'COMMON.INTERACT'
1943 ! include 'COMMON.IOUNITS'
1944 ! include 'COMMON.NAMES'
1945 ! include 'COMMON.TIME1'
1946 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1947 !el common /stochcalc/ stochforcvec
1948 real(kind=8) :: time00
1950 ! Compute friction and stochastic forces
1955 time_fric=time_fric+MPI_Wtime()-time00
1957 call stochastic_force(stochforcvec)
1958 time_stoch=time_stoch+MPI_Wtime()-time00
1961 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
1962 ! forces (d_as_work)
1964 call ginv_mult(fric_work, d_af_work)
1965 call ginv_mult(stochforcvec, d_as_work)
1967 end subroutine sddir_precalc
1968 !-----------------------------------------------------------------------------
1969 subroutine sddir_verlet1
1970 ! Applying velocity Verlet algorithm - step 1 to velocities
1973 ! implicit real*8 (a-h,o-z)
1974 ! include 'DIMENSIONS'
1975 ! include 'COMMON.CONTROL'
1976 ! include 'COMMON.VAR'
1977 ! include 'COMMON.MD'
1979 ! include 'COMMON.LANGEVIN'
1981 ! include 'COMMON.LANGEVIN.lang0'
1983 ! include 'COMMON.CHAIN'
1984 ! include 'COMMON.DERIV'
1985 ! include 'COMMON.GEO'
1986 ! include 'COMMON.LOCAL'
1987 ! include 'COMMON.INTERACT'
1988 ! include 'COMMON.IOUNITS'
1989 ! include 'COMMON.NAMES'
1990 ! Revised 3/31/05 AL: correlation between random contributions to
1991 ! position and velocity increments included.
1992 real(kind=8) :: sqrt13 = 0.57735026918962576451d0 ! 1/sqrt(3)
1993 real(kind=8) :: adt,adt2
1994 integer :: i,j,ind,inres,mnum
1996 ! Add the contribution from BOTH friction and stochastic force to the
1997 ! coordinates, but ONLY the contribution from the friction forces to velocities
2000 adt=(d_a_old(j,0)+d_af_work(j))*d_time
2001 adt2=0.5d0*adt+sqrt13*d_as_work(j)*d_time
2002 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
2003 d_t_new(j,0)=d_t_old(j,0)+0.5d0*adt
2004 d_t(j,0)=d_t_old(j,0)+adt
2009 adt=(d_a_old(j,i)+d_af_work(ind+j))*d_time
2010 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
2011 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
2012 d_t_new(j,i)=d_t_old(j,i)+0.5d0*adt
2013 d_t(j,i)=d_t_old(j,i)+adt
2019 ! iti=iabs(itype(i,mnum))
2020 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2021 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2022 .and.(mnum.ne.5)) then
2025 adt=(d_a_old(j,inres)+d_af_work(ind+j))*d_time
2026 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
2027 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
2028 d_t_new(j,inres)=d_t_old(j,inres)+0.5d0*adt
2029 d_t(j,inres)=d_t_old(j,inres)+adt
2035 end subroutine sddir_verlet1
2036 !-----------------------------------------------------------------------------
2037 subroutine sddir_verlet2
2038 ! Calculating the adjusted velocities for accelerations
2041 ! implicit real*8 (a-h,o-z)
2042 ! include 'DIMENSIONS'
2043 ! include 'COMMON.CONTROL'
2044 ! include 'COMMON.VAR'
2045 ! include 'COMMON.MD'
2047 ! include 'COMMON.LANGEVIN'
2049 ! include 'COMMON.LANGEVIN.lang0'
2051 ! include 'COMMON.CHAIN'
2052 ! include 'COMMON.DERIV'
2053 ! include 'COMMON.GEO'
2054 ! include 'COMMON.LOCAL'
2055 ! include 'COMMON.INTERACT'
2056 ! include 'COMMON.IOUNITS'
2057 ! include 'COMMON.NAMES'
2058 real(kind=8),dimension(6*nres) :: stochforcvec,d_as_work1 !(MAXRES6) maxres6=6*maxres
2059 real(kind=8) :: cos60 = 0.5d0, sin60 = 0.86602540378443864676d0
2060 integer :: i,j,ind,inres,mnum
2061 ! Revised 3/31/05 AL: correlation between random contributions to
2062 ! position and velocity increments included.
2063 ! The correlation coefficients are calculated at low-friction limit.
2064 ! Also, friction forces are now not calculated with new velocities.
2066 ! call friction_force
2067 call stochastic_force(stochforcvec)
2069 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
2070 ! forces (d_as_work)
2072 call ginv_mult(stochforcvec, d_as_work1)
2078 d_t(j,0)=d_t_new(j,0)+(0.5d0*(d_a(j,0)+d_af_work(j)) &
2079 +sin60*d_as_work(j)+cos60*d_as_work1(j))*d_time
2084 d_t(j,i)=d_t_new(j,i)+(0.5d0*(d_a(j,i)+d_af_work(ind+j)) &
2085 +sin60*d_as_work(ind+j)+cos60*d_as_work1(ind+j))*d_time
2091 ! iti=iabs(itype(i,mnum))
2092 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2093 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2094 .and.(mnum.ne.5)) then
2097 d_t(j,inres)=d_t_new(j,inres)+(0.5d0*(d_a(j,inres) &
2098 +d_af_work(ind+j))+sin60*d_as_work(ind+j) &
2099 +cos60*d_as_work1(ind+j))*d_time
2105 end subroutine sddir_verlet2
2106 !-----------------------------------------------------------------------------
2107 subroutine max_accel
2109 ! Find the maximum difference in the accelerations of the the sites
2110 ! at the beginning and the end of the time step.
2113 ! implicit real*8 (a-h,o-z)
2114 ! include 'DIMENSIONS'
2115 ! include 'COMMON.CONTROL'
2116 ! include 'COMMON.VAR'
2117 ! include 'COMMON.MD'
2118 ! include 'COMMON.CHAIN'
2119 ! include 'COMMON.DERIV'
2120 ! include 'COMMON.GEO'
2121 ! include 'COMMON.LOCAL'
2122 ! include 'COMMON.INTERACT'
2123 ! include 'COMMON.IOUNITS'
2124 real(kind=8),dimension(3) :: aux,accel,accel_old
2125 real(kind=8) :: dacc
2129 ! aux(j)=d_a(j,0)-d_a_old(j,0)
2130 accel_old(j)=d_a_old(j,0)
2137 ! 7/3/08 changed to asymmetric difference
2139 ! accel(j)=aux(j)+0.5d0*(d_a(j,i)-d_a_old(j,i))
2140 accel_old(j)=accel_old(j)+0.5d0*d_a_old(j,i)
2141 accel(j)=accel(j)+0.5d0*d_a(j,i)
2142 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2143 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2144 dacc=dabs(accel(j)-accel_old(j))
2145 ! write (iout,*) i,dacc
2146 if (dacc.gt.amax) amax=dacc
2154 accel_old(j)=d_a_old(j,0)
2159 accel_old(j)=accel_old(j)+d_a_old(j,1)
2160 accel(j)=accel(j)+d_a(j,1)
2165 ! iti=iabs(itype(i,mnum))
2166 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2167 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2168 .and.(mnum.ne.5)) then
2170 ! accel(j)=accel(j)+d_a(j,i+nres)-d_a_old(j,i+nres)
2171 accel_old(j)=accel_old(j)+d_a_old(j,i+nres)
2172 accel(j)=accel(j)+d_a(j,i+nres)
2176 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2177 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2178 dacc=dabs(accel(j)-accel_old(j))
2179 ! write (iout,*) "side-chain",i,dacc
2180 if (dacc.gt.amax) amax=dacc
2184 accel_old(j)=accel_old(j)+d_a_old(j,i)
2185 accel(j)=accel(j)+d_a(j,i)
2186 ! aux(j)=aux(j)+d_a(j,i)-d_a_old(j,i)
2190 end subroutine max_accel
2191 !-----------------------------------------------------------------------------
2192 subroutine predict_edrift(epdrift)
2194 ! Predict the drift of the potential energy
2197 use control_data, only: lmuca
2198 ! implicit real*8 (a-h,o-z)
2199 ! include 'DIMENSIONS'
2200 ! include 'COMMON.CONTROL'
2201 ! include 'COMMON.VAR'
2202 ! include 'COMMON.MD'
2203 ! include 'COMMON.CHAIN'
2204 ! include 'COMMON.DERIV'
2205 ! include 'COMMON.GEO'
2206 ! include 'COMMON.LOCAL'
2207 ! include 'COMMON.INTERACT'
2208 ! include 'COMMON.IOUNITS'
2209 ! include 'COMMON.MUCA'
2210 real(kind=8) :: epdrift,epdriftij
2212 ! Drift of the potential energy
2218 epdriftij=dabs((d_a(j,i)-d_a_old(j,i))*gcart(j,i))
2219 if (lmuca) epdriftij=epdriftij*factor
2220 ! write (iout,*) "back",i,j,epdriftij
2221 if (epdriftij.gt.epdrift) epdrift=epdriftij
2225 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1.and.&
2226 molnum(i).ne.5) then
2229 dabs((d_a(j,i+nres)-d_a_old(j,i+nres))*gxcart(j,i))
2230 if (lmuca) epdriftij=epdriftij*factor
2231 ! write (iout,*) "side",i,j,epdriftij
2232 if (epdriftij.gt.epdrift) epdrift=epdriftij
2236 epdrift=0.5d0*epdrift*d_time*d_time
2237 ! write (iout,*) "epdrift",epdrift
2239 end subroutine predict_edrift
2240 !-----------------------------------------------------------------------------
2241 subroutine verlet_bath
2243 ! Coupling to the thermostat by using the Berendsen algorithm
2246 ! implicit real*8 (a-h,o-z)
2247 ! include 'DIMENSIONS'
2248 ! include 'COMMON.CONTROL'
2249 ! include 'COMMON.VAR'
2250 ! include 'COMMON.MD'
2251 ! include 'COMMON.CHAIN'
2252 ! include 'COMMON.DERIV'
2253 ! include 'COMMON.GEO'
2254 ! include 'COMMON.LOCAL'
2255 ! include 'COMMON.INTERACT'
2256 ! include 'COMMON.IOUNITS'
2257 ! include 'COMMON.NAMES'
2258 real(kind=8) :: T_half,fact
2259 integer :: i,j,inres,mnum
2261 T_half=2.0d0/(dimen3*Rb)*EK
2262 fact=dsqrt(1.0d0+(d_time/tau_bath)*(t_bath/T_half-1.0d0))
2263 ! write(iout,*) "T_half", T_half
2264 ! write(iout,*) "EK", EK
2265 ! write(iout,*) "fact", fact
2267 d_t(j,0)=fact*d_t(j,0)
2271 d_t(j,i)=fact*d_t(j,i)
2276 ! iti=iabs(itype(i,mnum))
2277 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2278 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2279 .and.(mnum.ne.5)) then
2282 d_t(j,inres)=fact*d_t(j,inres)
2287 end subroutine verlet_bath
2288 !-----------------------------------------------------------------------------
2290 ! Set up the initial conditions of a MD simulation
2293 use control, only:tcpu
2294 !el use io_basic, only:ilen
2297 use minimm, only:minim_dc,minimize,sc_move
2298 use io_config, only:readrst
2299 use io, only:statout
2300 ! implicit real*8 (a-h,o-z)
2301 ! include 'DIMENSIONS'
2304 character(len=16) :: form
2305 integer :: IERROR,ERRCODE
2307 ! include 'COMMON.SETUP'
2308 ! include 'COMMON.CONTROL'
2309 ! include 'COMMON.VAR'
2310 ! include 'COMMON.MD'
2312 ! include 'COMMON.LANGEVIN'
2314 ! include 'COMMON.LANGEVIN.lang0'
2316 ! include 'COMMON.CHAIN'
2317 ! include 'COMMON.DERIV'
2318 ! include 'COMMON.GEO'
2319 ! include 'COMMON.LOCAL'
2320 ! include 'COMMON.INTERACT'
2321 ! include 'COMMON.IOUNITS'
2322 ! include 'COMMON.NAMES'
2323 ! include 'COMMON.REMD'
2324 real(kind=8),dimension(0:n_ene) :: energia_long,energia_short
2325 real(kind=8),dimension(3) :: vcm,incr,L
2326 real(kind=8) :: xv,sigv,lowb,highb
2327 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
2328 character(len=256) :: qstr
2331 character(len=50) :: tytul
2332 logical :: file_exist
2333 !el common /gucio/ cm
2334 integer :: i,j,ipos,iq,iw,nft_sc,iretcode,nfun,itime,ierr,mnum
2335 real(kind=8) :: etot,tt0
2339 ! write(iout,*) "d_time", d_time
2340 ! Compute the standard deviations of stochastic forces for Langevin dynamics
2341 ! if the friction coefficients do not depend on surface area
2342 if (lang.gt.0 .and. .not.surfarea) then
2345 stdforcp(i)=stdfp(mnum)*dsqrt(gamp(mnum))
2349 stdforcsc(i)=stdfsc(iabs(itype(i,mnum)),mnum) &
2350 *dsqrt(gamsc(iabs(itype(i,mnum)),mnum))
2353 ! Open the pdb file for snapshotshots
2356 if (ilen(tmpdir).gt.0) &
2357 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2358 liczba(:ilen(liczba))//".pdb")
2360 file=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2364 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2365 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2366 liczba(:ilen(liczba))//".x")
2367 cartname=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))//".cx")
2373 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2379 if (ilen(tmpdir).gt.0) &
2380 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.pdb")
2381 open(ipdb,file=prefix(:ilen(prefix))//"_MD.pdb")
2383 if (ilen(tmpdir).gt.0) &
2384 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.cx")
2385 cartname=prefix(:ilen(prefix))//"_MD.cx"
2389 write (qstr,'(256(1h ))')
2392 iq = qinfrag(i,iset)*10
2393 iw = wfrag(i,iset)/100
2395 if(me.eq.king.or..not.out1file) &
2396 write (iout,*) "Frag",qinfrag(i,iset),wfrag(i,iset),iq,iw
2397 write (qstr(ipos:ipos+6),'(2h_f,i1,1h_,i1,1h_,i1)') i,iq,iw
2402 iq = qinpair(i,iset)*10
2403 iw = wpair(i,iset)/100
2405 if(me.eq.king.or..not.out1file) &
2406 write (iout,*) "Pair",i,qinpair(i,iset),wpair(i,iset),iq,iw
2407 write (qstr(ipos:ipos+6),'(2h_p,i1,1h_,i1,1h_,i1)') i,iq,iw
2411 ! pdbname=pdbname(:ilen(pdbname)-4)//qstr(:ipos-1)//'.pdb'
2413 ! cartname=cartname(:ilen(cartname)-2)//qstr(:ipos-1)//'.x'
2415 ! cartname=cartname(:ilen(cartname)-3)//qstr(:ipos-1)//'.cx'
2417 ! statname=statname(:ilen(statname)-5)//qstr(:ipos-1)//'.stat'
2421 if (restart1file) then
2423 inquire(file=mremd_rst_name,exist=file_exist)
2424 write (*,*) me," Before broadcast: file_exist",file_exist
2426 call MPI_Bcast(file_exist,1,MPI_LOGICAL,king,CG_COMM,&
2429 write (*,*) me," After broadcast: file_exist",file_exist
2430 ! inquire(file=mremd_rst_name,exist=file_exist)
2431 if(me.eq.king.or..not.out1file) &
2432 write(iout,*) "Initial state read by master and distributed"
2434 if (ilen(tmpdir).gt.0) &
2435 call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_' &
2436 //liczba(:ilen(liczba))//'.rst')
2437 inquire(file=rest2name,exist=file_exist)
2440 if(.not.restart1file) then
2441 if(me.eq.king.or..not.out1file) &
2442 write(iout,*) "Initial state will be read from file ",&
2443 rest2name(:ilen(rest2name))
2446 call rescale_weights(t_bath)
2448 if(me.eq.king.or..not.out1file)then
2449 if (restart1file) then
2450 write(iout,*) "File ",mremd_rst_name(:ilen(mremd_rst_name)),&
2453 write(iout,*) "File ",rest2name(:ilen(rest2name)),&
2456 write(iout,*) "Initial velocities randomly generated"
2463 ! Generate initial velocities
2464 if(me.eq.king.or..not.out1file) &
2465 write(iout,*) "Initial velocities randomly generated"
2470 ! rest2name = prefix(:ilen(prefix))//'.rst'
2471 if(me.eq.king.or..not.out1file)then
2472 write (iout,*) "Initial velocities"
2474 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2475 (d_t(j,i+nres),j=1,3)
2477 ! Zeroing the total angular momentum of the system
2478 write(iout,*) "Calling the zero-angular momentum subroutine"
2481 ! Getting the potential energy and forces and velocities and accelerations
2483 ! write (iout,*) "velocity of the center of the mass:"
2484 ! write (iout,*) (vcm(j),j=1,3)
2486 d_t(j,0)=d_t(j,0)-vcm(j)
2488 ! Removing the velocity of the center of mass
2490 if(me.eq.king.or..not.out1file)then
2491 write (iout,*) "vcm right after adjustment:"
2492 write (iout,*) (vcm(j),j=1,3)
2494 if ((.not.rest).and.(indpdb.eq.0)) then
2496 if(iranconf.ne.0) then
2498 print *, 'Calling OVERLAP_SC'
2499 call overlap_sc(fail)
2502 call sc_move(2,nres-1,10,1d10,nft_sc,etot)
2503 print *,'SC_move',nft_sc,etot
2504 if(me.eq.king.or..not.out1file) &
2505 write(iout,*) 'SC_move',nft_sc,etot
2509 print *, 'Calling MINIM_DC'
2510 call minim_dc(etot,iretcode,nfun)
2512 call geom_to_var(nvar,varia)
2513 print *,'Calling MINIMIZE.'
2514 call minimize(etot,varia,iretcode,nfun)
2515 call var_to_geom(nvar,varia)
2517 if(me.eq.king.or..not.out1file) &
2518 write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
2521 call chainbuild_cart
2526 kinetic_T=2.0d0/(dimen3*Rb)*EK
2527 if(me.eq.king.or..not.out1file)then
2537 call etotal(potEcomp)
2538 if (large) call enerprint(potEcomp)
2541 t_etotal=t_etotal+MPI_Wtime()-tt0
2543 t_etotal=t_etotal+tcpu()-tt0
2550 if (amax*d_time .gt. dvmax) then
2551 d_time=d_time*dvmax/amax
2552 if(me.eq.king.or..not.out1file) write (iout,*) &
2553 "Time step reduced to",d_time,&
2554 " because of too large initial acceleration."
2556 if(me.eq.king.or..not.out1file)then
2557 write(iout,*) "Potential energy and its components"
2558 call enerprint(potEcomp)
2559 ! write(iout,*) (potEcomp(i),i=0,n_ene)
2561 potE=potEcomp(0)-potEcomp(20)
2564 if (ntwe.ne.0) call statout(itime)
2565 if(me.eq.king.or..not.out1file) &
2566 write (iout,'(/a/3(a25,1pe14.5/))') "Initial:", &
2567 " Kinetic energy",EK," Potential energy",potE, &
2568 " Total energy",totE," Maximum acceleration ", &
2571 write (iout,*) "Initial coordinates"
2573 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(c(j,i),j=1,3),&
2576 write (iout,*) "Initial dC"
2578 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
2579 (dc(j,i+nres),j=1,3)
2581 write (iout,*) "Initial velocities"
2582 write (iout,"(13x,' backbone ',23x,' side chain')")
2584 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2585 (d_t(j,i+nres),j=1,3)
2587 write (iout,*) "Initial accelerations"
2589 ! write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
2590 write (iout,'(i3,3f15.10,3x,3f15.10)') i,(d_a(j,i),j=1,3),&
2591 (d_a(j,i+nres),j=1,3)
2597 d_t_old(j,i)=d_t(j,i)
2598 d_a_old(j,i)=d_a(j,i)
2600 ! write (iout,*) "dc_old",i,(dc_old(j,i),j=1,3)
2609 call etotal_short(energia_short)
2610 if (large) call enerprint(potEcomp)
2613 t_eshort=t_eshort+MPI_Wtime()-tt0
2615 t_eshort=t_eshort+tcpu()-tt0
2620 if(.not.out1file .and. large) then
2621 write (iout,*) "energia_long",energia_long(0),&
2622 " energia_short",energia_short(0),&
2623 " total",energia_long(0)+energia_short(0)
2624 write (iout,*) "Initial fast-force accelerations"
2626 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2627 (d_a(j,i+nres),j=1,3)
2630 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
2633 d_a_short(j,i)=d_a(j,i)
2642 call etotal_long(energia_long)
2643 if (large) call enerprint(potEcomp)
2646 t_elong=t_elong+MPI_Wtime()-tt0
2648 t_elong=t_elong+tcpu()-tt0
2653 if(.not.out1file .and. large) then
2654 write (iout,*) "energia_long",energia_long(0)
2655 write (iout,*) "Initial slow-force accelerations"
2657 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2658 (d_a(j,i+nres),j=1,3)
2662 t_enegrad=t_enegrad+MPI_Wtime()-tt0
2664 t_enegrad=t_enegrad+tcpu()-tt0
2668 end subroutine init_MD
2669 !-----------------------------------------------------------------------------
2670 subroutine random_vel
2672 ! implicit real*8 (a-h,o-z)
2674 use random, only:anorm_distr
2676 ! include 'DIMENSIONS'
2677 ! include 'COMMON.CONTROL'
2678 ! include 'COMMON.VAR'
2679 ! include 'COMMON.MD'
2681 ! include 'COMMON.LANGEVIN'
2683 ! include 'COMMON.LANGEVIN.lang0'
2685 ! include 'COMMON.CHAIN'
2686 ! include 'COMMON.DERIV'
2687 ! include 'COMMON.GEO'
2688 ! include 'COMMON.LOCAL'
2689 ! include 'COMMON.INTERACT'
2690 ! include 'COMMON.IOUNITS'
2691 ! include 'COMMON.NAMES'
2692 ! include 'COMMON.TIME1'
2693 real(kind=8) :: xv,sigv,lowb,highb ,Ek1
2695 real(kind=8) ,allocatable, dimension(:) :: DDU1,DDU2,DL2,DL1,xsolv,DML,rs
2696 real(kind=8) :: sumx
2698 real(kind=8) ,allocatable, dimension(:) :: rsold
2699 real (kind=8),allocatable,dimension(:,:) :: matold
2702 integer :: i,j,ii,k,ind,mark,imark,mnum
2703 ! Generate random velocities from Gaussian distribution of mean 0 and std of KT/m
2704 ! First generate velocities in the eigenspace of the G matrix
2705 ! write (iout,*) "Calling random_vel dimen dimen3",dimen,dimen3
2712 sigv=dsqrt((Rb*t_bath)/geigen(i))
2715 d_t_work_new(ii)=anorm_distr(xv,sigv,lowb,highb)
2717 write (iout,*) "i",i," ii",ii," geigen",geigen(i),&
2718 " d_t_work_new",d_t_work_new(ii)
2729 Ek1=Ek1+0.5d0*geigen(i)*d_t_work_new(ii)**2
2732 write (iout,*) "Ek from eigenvectors",Ek1
2733 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2737 ! Transform velocities to UNRES coordinate space
2738 allocate (DL1(2*nres))
2739 allocate (DDU1(2*nres))
2740 allocate (DL2(2*nres))
2741 allocate (DDU2(2*nres))
2742 allocate (xsolv(2*nres))
2743 allocate (DML(2*nres))
2744 allocate (rs(2*nres))
2746 allocate (rsold(2*nres))
2747 allocate (matold(2*nres,2*nres))
2749 matold(1,1)=DMorig(1)
2750 matold(1,2)=DU1orig(1)
2751 matold(1,3)=DU2orig(1)
2752 write (*,*) DMorig(1),DU1orig(1),DU2orig(1)
2757 matold(i,j)=DMorig(i)
2758 matold(i,j-1)=DU1orig(i-1)
2760 matold(i,j-2)=DU2orig(i-2)
2768 matold(i,j+1)=DU1orig(i)
2774 matold(i,j+2)=DU2orig(i)
2778 matold(dimen,dimen)=DMorig(dimen)
2779 matold(dimen,dimen-1)=DU1orig(dimen-1)
2780 matold(dimen,dimen-2)=DU2orig(dimen-2)
2781 write(iout,*) "old gmatrix"
2782 call matout(dimen,dimen,2*nres,2*nres,matold)
2786 ! Find the ith eigenvector of the pentadiagonal inertiq matrix
2790 DML(j)=DMorig(j)-geigen(i)
2793 DML(j-1)=DMorig(j)-geigen(i)
2798 DDU1(imark-1)=DU2orig(imark-1)
2799 do j=imark+1,dimen-1
2800 DDU1(j-1)=DU1orig(j)
2808 DDU2(j)=DU2orig(j+1)
2817 write (iout,*) "DL2,DL1,DML,DDU1,DDU2"
2818 write(iout,'(10f10.5)') (DL2(k),k=3,dimen-1)
2819 write(iout,'(10f10.5)') (DL1(k),k=2,dimen-1)
2820 write(iout,'(10f10.5)') (DML(k),k=1,dimen-1)
2821 write(iout,'(10f10.5)') (DDU1(k),k=1,dimen-2)
2822 write(iout,'(10f10.5)') (DDU2(k),k=1,dimen-3)
2825 if (imark.gt.2) rs(imark-2)=-DU2orig(imark-2)
2826 if (imark.gt.1) rs(imark-1)=-DU1orig(imark-1)
2827 if (imark.lt.dimen) rs(imark)=-DU1orig(imark)
2828 if (imark.lt.dimen-1) rs(imark+1)=-DU2orig(imark)
2832 ! write (iout,*) "Vector rs"
2834 ! write (iout,*) j,rs(j)
2837 call FDIAG(dimen-1,DL2,DL1,DML,DDU1,DDU2,rs,xsolv,mark)
2844 sumx=-geigen(i)*xsolv(j)
2846 sumx=sumx+matold(j,k)*xsolv(k)
2849 sumx=sumx+matold(j,k)*xsolv(k-1)
2851 write(iout,'(i5,3f10.5)') j,sumx,rsold(j),sumx-rsold(j)
2854 sumx=-geigen(i)*xsolv(j-1)
2856 sumx=sumx+matold(j,k)*xsolv(k)
2859 sumx=sumx+matold(j,k)*xsolv(k-1)
2861 write(iout,'(i5,3f10.5)') j-1,sumx,rsold(j-1),sumx-rsold(j-1)
2865 "Solution of equations system",i," for eigenvalue",geigen(i)
2867 write(iout,'(i5,f10.5)') j,xsolv(j)
2870 do j=dimen-1,imark,-1
2875 write (iout,*) "Un-normalized eigenvector",i," for eigenvalue",geigen(i)
2877 write(iout,'(i5,f10.5)') j,xsolv(j)
2880 ! Normalize ith eigenvector
2883 sumx=sumx+xsolv(j)**2
2887 xsolv(j)=xsolv(j)/sumx
2890 write (iout,*) "Eigenvector",i," for eigenvalue",geigen(i)
2892 write(iout,'(i5,3f10.5)') j,xsolv(j)
2895 ! All done at this point for eigenvector i, exit loop
2903 write (iout,*) "Unable to find eigenvector",i
2906 ! write (iout,*) "i=",i
2908 ! write (iout,*) "k=",k
2911 ! write(iout,*) "ind",ind," ind1",3*(i-1)+k
2912 d_t_work(ind)=d_t_work(ind) &
2913 +xsolv(j)*d_t_work_new(3*(i-1)+k)
2916 enddo ! i (loop over the eigenvectors)
2919 write (iout,*) "d_t_work"
2921 write (iout,"(i5,f10.5)") i,d_t_work(i)
2926 ! if (itype(i,1).eq.10) then
2928 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
2929 iti=iabs(itype(i,mnum))
2930 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2931 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
2932 .or.(mnum.eq.5)) then
2939 ! write (iout,*) "k",k," ii+k",ii+k," ii+j+k",ii+j+k,"EK1",Ek1
2940 Ek1=Ek1+0.5d0*mp(mnum)*((d_t_work(ii+j+k)+d_t_work_new(ii+k))/2)**2+&
2941 0.5d0*0.25d0*IP(mnum)*(d_t_work(ii+j+k)-d_t_work_new(ii+k))**2
2944 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2945 .and.(mnum.ne.5)) ii=ii+3
2946 write (iout,*) "i",i," itype",itype(i,mnum)," mass",msc(itype(i,mnum),mnum)
2947 write (iout,*) "ii",ii
2950 write (iout,*) "k",k," ii",ii,"EK1",EK1
2951 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2953 Ek1=Ek1+0.5d0*Isc(iabs(itype(i,mnum),mnum))*(d_t_work(ii)-d_t_work(ii-3))**2
2954 Ek1=Ek1+0.5d0*msc(iabs(itype(i,mnum)),mnum)*d_t_work(ii)**2
2956 write (iout,*) "i",i," ii",ii
2958 write (iout,*) "Ek from d_t_work",Ek1
2959 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2975 d_t(k,j)=d_t_work(ind)
2979 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2982 d_t(k,j+nres)=d_t_work(ind)
2988 write (iout,*) "Random velocities in the Calpha,SC space"
2990 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
2993 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
3000 ! if (itype(i,1).eq.10) then
3002 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
3005 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
3009 d_t(j,i+nres)=d_t(j,i+nres)-d_t(j,i)
3010 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
3015 write (iout,*)"Random velocities in the virtual-bond-vector space"
3017 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
3020 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
3023 write (iout,*) "Ek from d_t_work",Ek1
3024 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
3032 d_t_work(ind)=d_t_work(ind) &
3033 +Gvec(i,j)*d_t_work_new((j-1)*3+k+1)
3035 ! write (iout,*) "i",i," ind",ind," d_t_work",d_t_work(ind)
3039 ! Transfer to the d_t vector
3041 d_t(j,0)=d_t_work(j)
3047 d_t(j,i)=d_t_work(ind)
3052 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3053 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3054 .and.(mnum.ne.5)) then
3057 d_t(j,i+nres)=d_t_work(ind)
3063 ! write (iout,*) "Kinetic energy",Ek,EK1," kinetic temperature",&
3064 ! 2.0d0/(dimen3*Rb)*EK,2.0d0/(dimen3*Rb)*EK1
3068 end subroutine random_vel
3069 !-----------------------------------------------------------------------------
3071 subroutine sd_verlet_p_setup
3072 ! Sets up the parameters of stochastic Verlet algorithm
3073 ! implicit real*8 (a-h,o-z)
3074 ! include 'DIMENSIONS'
3075 use control, only: tcpu
3080 ! include 'COMMON.CONTROL'
3081 ! include 'COMMON.VAR'
3082 ! include 'COMMON.MD'
3084 ! include 'COMMON.LANGEVIN'
3086 ! include 'COMMON.LANGEVIN.lang0'
3088 ! include 'COMMON.CHAIN'
3089 ! include 'COMMON.DERIV'
3090 ! include 'COMMON.GEO'
3091 ! include 'COMMON.LOCAL'
3092 ! include 'COMMON.INTERACT'
3093 ! include 'COMMON.IOUNITS'
3094 ! include 'COMMON.NAMES'
3095 ! include 'COMMON.TIME1'
3096 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3097 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3098 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3099 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3100 logical :: lprn = .false.
3101 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3102 real(kind=8) :: ktm,gdt,egdt,gdt2,gdt3,gdt4,gdt5,gdt6,gdt7,gdt8,&
3104 integer :: i,maxres2
3111 ! AL 8/17/04 Code adapted from tinker
3113 ! Get the frictional and random terms for stochastic dynamics in the
3114 ! eigenspace of mass-scaled UNRES friction matrix
3118 gdt = fricgam(i) * d_time
3120 ! Stochastic dynamics reduces to simple MD for zero friction
3122 if (gdt .le. zero) then
3123 pfric_vec(i) = 1.0d0
3124 vfric_vec(i) = d_time
3125 afric_vec(i) = 0.5d0 * d_time * d_time
3126 prand_vec(i) = 0.0d0
3127 vrand_vec1(i) = 0.0d0
3128 vrand_vec2(i) = 0.0d0
3130 ! Analytical expressions when friction coefficient is large
3133 if (gdt .ge. gdt_radius) then
3136 vfric_vec(i) = (1.0d0-egdt) / fricgam(i)
3137 afric_vec(i) = (d_time-vfric_vec(i)) / fricgam(i)
3138 pterm = 2.0d0*gdt - 3.0d0 + (4.0d0-egdt)*egdt
3139 vterm = 1.0d0 - egdt**2
3140 rho = (1.0d0-egdt)**2 / sqrt(pterm*vterm)
3142 ! Use series expansions when friction coefficient is small
3153 afric_vec(i) = (gdt2/2.0d0 - gdt3/6.0d0 + gdt4/24.0d0 &
3154 - gdt5/120.0d0 + gdt6/720.0d0 &
3155 - gdt7/5040.0d0 + gdt8/40320.0d0 &
3156 - gdt9/362880.0d0) / fricgam(i)**2
3157 vfric_vec(i) = d_time - fricgam(i)*afric_vec(i)
3158 pfric_vec(i) = 1.0d0 - fricgam(i)*vfric_vec(i)
3159 pterm = 2.0d0*gdt3/3.0d0 - gdt4/2.0d0 &
3160 + 7.0d0*gdt5/30.0d0 - gdt6/12.0d0 &
3161 + 31.0d0*gdt7/1260.0d0 - gdt8/160.0d0 &
3162 + 127.0d0*gdt9/90720.0d0
3163 vterm = 2.0d0*gdt - 2.0d0*gdt2 + 4.0d0*gdt3/3.0d0 &
3164 - 2.0d0*gdt4/3.0d0 + 4.0d0*gdt5/15.0d0 &
3165 - 4.0d0*gdt6/45.0d0 + 8.0d0*gdt7/315.0d0 &
3166 - 2.0d0*gdt8/315.0d0 + 4.0d0*gdt9/2835.0d0
3167 rho = sqrt(3.0d0) * (0.5d0 - 3.0d0*gdt/16.0d0 &
3168 - 17.0d0*gdt2/1280.0d0 &
3169 + 17.0d0*gdt3/6144.0d0 &
3170 + 40967.0d0*gdt4/34406400.0d0 &
3171 - 57203.0d0*gdt5/275251200.0d0 &
3172 - 1429487.0d0*gdt6/13212057600.0d0)
3175 ! Compute the scaling factors of random terms for the nonzero friction case
3177 ktm = 0.5d0*d_time/fricgam(i)
3178 psig = dsqrt(ktm*pterm) / fricgam(i)
3179 vsig = dsqrt(ktm*vterm)
3180 rhoc = dsqrt(1.0d0 - rho*rho)
3182 vrand_vec1(i) = vsig * rho
3183 vrand_vec2(i) = vsig * rhoc
3188 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3191 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3192 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3196 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3199 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3200 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3201 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3202 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3203 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec1,vrand_mat1)
3204 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3207 t_sdsetup=t_sdsetup+MPI_Wtime()
3209 t_sdsetup=t_sdsetup+tcpu()-tt0
3212 end subroutine sd_verlet_p_setup
3213 !-----------------------------------------------------------------------------
3214 subroutine eigtransf1(n,ndim,ab,d,c)
3218 real(kind=8) :: ab(ndim,ndim,n),c(ndim,n),d(ndim)
3224 c(i,j)=c(i,j)+ab(k,j,i)*d(k)
3229 end subroutine eigtransf1
3230 !-----------------------------------------------------------------------------
3231 subroutine eigtransf(n,ndim,a,b,d,c)
3235 real(kind=8) :: a(ndim,n),b(ndim,n),c(ndim,n),d(ndim)
3241 c(i,j)=c(i,j)+a(i,k)*b(k,j)*d(k)
3246 end subroutine eigtransf
3247 !-----------------------------------------------------------------------------
3248 subroutine sd_verlet1
3250 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3252 ! implicit real*8 (a-h,o-z)
3253 ! include 'DIMENSIONS'
3254 ! include 'COMMON.CONTROL'
3255 ! include 'COMMON.VAR'
3256 ! include 'COMMON.MD'
3258 ! include 'COMMON.LANGEVIN'
3260 ! include 'COMMON.LANGEVIN.lang0'
3262 ! include 'COMMON.CHAIN'
3263 ! include 'COMMON.DERIV'
3264 ! include 'COMMON.GEO'
3265 ! include 'COMMON.LOCAL'
3266 ! include 'COMMON.INTERACT'
3267 ! include 'COMMON.IOUNITS'
3268 ! include 'COMMON.NAMES'
3269 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3270 !el common /stochcalc/ stochforcvec
3271 logical :: lprn = .false.
3272 real(kind=8) :: ddt1,ddt2
3273 integer :: i,j,ind,inres
3275 ! write (iout,*) "dc_old"
3277 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3278 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3281 dc_work(j)=dc_old(j,0)
3282 d_t_work(j)=d_t_old(j,0)
3283 d_a_work(j)=d_a_old(j,0)
3288 dc_work(ind+j)=dc_old(j,i)
3289 d_t_work(ind+j)=d_t_old(j,i)
3290 d_a_work(ind+j)=d_a_old(j,i)
3296 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3297 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3298 .and.(mnum.ne.5)) then
3300 dc_work(ind+j)=dc_old(j,i+nres)
3301 d_t_work(ind+j)=d_t_old(j,i+nres)
3302 d_a_work(ind+j)=d_a_old(j,i+nres)
3310 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3314 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3315 vfric_mat(i,j),afric_mat(i,j),&
3316 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3324 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3325 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3326 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3327 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3329 d_t_work_new(i)=ddt1+0.5d0*ddt2
3330 d_t_work(i)=ddt1+ddt2
3335 d_t(j,0)=d_t_work(j)
3340 dc(j,i)=dc_work(ind+j)
3341 d_t(j,i)=d_t_work(ind+j)
3347 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3348 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3349 .and.(mnum.ne.5)) then
3352 dc(j,inres)=dc_work(ind+j)
3353 d_t(j,inres)=d_t_work(ind+j)
3359 end subroutine sd_verlet1
3360 !-----------------------------------------------------------------------------
3361 subroutine sd_verlet2
3363 ! Calculating the adjusted velocities for accelerations
3365 ! implicit real*8 (a-h,o-z)
3366 ! include 'DIMENSIONS'
3367 ! include 'COMMON.CONTROL'
3368 ! include 'COMMON.VAR'
3369 ! include 'COMMON.MD'
3371 ! include 'COMMON.LANGEVIN'
3373 ! include 'COMMON.LANGEVIN.lang0'
3375 ! include 'COMMON.CHAIN'
3376 ! include 'COMMON.DERIV'
3377 ! include 'COMMON.GEO'
3378 ! include 'COMMON.LOCAL'
3379 ! include 'COMMON.INTERACT'
3380 ! include 'COMMON.IOUNITS'
3381 ! include 'COMMON.NAMES'
3382 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3383 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3384 !el common /stochcalc/ stochforcvec
3386 real(kind=8) :: ddt1,ddt2
3387 integer :: i,j,ind,inres
3388 ! Compute the stochastic forces which contribute to velocity change
3390 call stochastic_force(stochforcvecV)
3397 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3398 ddt2=ddt2+vrand_mat1(i,j)*stochforcvec(j)+ &
3399 vrand_mat2(i,j)*stochforcvecV(j)
3401 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3405 d_t(j,0)=d_t_work(j)
3410 d_t(j,i)=d_t_work(ind+j)
3416 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3417 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3418 .and.(mnum.ne.5)) then
3421 d_t(j,inres)=d_t_work(ind+j)
3427 end subroutine sd_verlet2
3428 !-----------------------------------------------------------------------------
3429 subroutine sd_verlet_ciccotti_setup
3431 ! Sets up the parameters of stochastic velocity Verlet algorithmi; Ciccotti's
3433 ! implicit real*8 (a-h,o-z)
3434 ! include 'DIMENSIONS'
3435 use control, only: tcpu
3440 ! include 'COMMON.CONTROL'
3441 ! include 'COMMON.VAR'
3442 ! include 'COMMON.MD'
3444 ! include 'COMMON.LANGEVIN'
3446 ! include 'COMMON.LANGEVIN.lang0'
3448 ! include 'COMMON.CHAIN'
3449 ! include 'COMMON.DERIV'
3450 ! include 'COMMON.GEO'
3451 ! include 'COMMON.LOCAL'
3452 ! include 'COMMON.INTERACT'
3453 ! include 'COMMON.IOUNITS'
3454 ! include 'COMMON.NAMES'
3455 ! include 'COMMON.TIME1'
3456 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3457 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3458 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3459 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3460 logical :: lprn = .false.
3461 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3462 real(kind=8) :: ktm,gdt,egdt,tt0
3463 integer :: i,maxres2
3470 ! AL 8/17/04 Code adapted from tinker
3472 ! Get the frictional and random terms for stochastic dynamics in the
3473 ! eigenspace of mass-scaled UNRES friction matrix
3477 write (iout,*) "i",i," fricgam",fricgam(i)
3478 gdt = fricgam(i) * d_time
3480 ! Stochastic dynamics reduces to simple MD for zero friction
3482 if (gdt .le. zero) then
3483 pfric_vec(i) = 1.0d0
3484 vfric_vec(i) = d_time
3485 afric_vec(i) = 0.5d0*d_time*d_time
3486 prand_vec(i) = afric_vec(i)
3487 vrand_vec2(i) = vfric_vec(i)
3489 ! Analytical expressions when friction coefficient is large
3494 vfric_vec(i) = dexp(-0.5d0*gdt)*d_time
3495 afric_vec(i) = 0.5d0*dexp(-0.25d0*gdt)*d_time*d_time
3496 prand_vec(i) = afric_vec(i)
3497 vrand_vec2(i) = vfric_vec(i)
3499 ! Compute the scaling factors of random terms for the nonzero friction case
3501 ! ktm = 0.5d0*d_time/fricgam(i)
3502 ! psig = dsqrt(ktm*pterm) / fricgam(i)
3503 ! vsig = dsqrt(ktm*vterm)
3504 ! prand_vec(i) = psig*afric_vec(i)
3505 ! vrand_vec2(i) = vsig*vfric_vec(i)
3510 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3513 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3514 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3518 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3520 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3521 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3522 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3523 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3524 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3526 t_sdsetup=t_sdsetup+MPI_Wtime()
3528 t_sdsetup=t_sdsetup+tcpu()-tt0
3531 end subroutine sd_verlet_ciccotti_setup
3532 !-----------------------------------------------------------------------------
3533 subroutine sd_verlet1_ciccotti
3535 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3536 ! implicit real*8 (a-h,o-z)
3538 ! include 'DIMENSIONS'
3542 ! include 'COMMON.CONTROL'
3543 ! include 'COMMON.VAR'
3544 ! include 'COMMON.MD'
3546 ! include 'COMMON.LANGEVIN'
3548 ! include 'COMMON.LANGEVIN.lang0'
3550 ! include 'COMMON.CHAIN'
3551 ! include 'COMMON.DERIV'
3552 ! include 'COMMON.GEO'
3553 ! include 'COMMON.LOCAL'
3554 ! include 'COMMON.INTERACT'
3555 ! include 'COMMON.IOUNITS'
3556 ! include 'COMMON.NAMES'
3557 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3558 !el common /stochcalc/ stochforcvec
3559 logical :: lprn = .false.
3560 real(kind=8) :: ddt1,ddt2
3561 integer :: i,j,ind,inres
3562 ! write (iout,*) "dc_old"
3564 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3565 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3568 dc_work(j)=dc_old(j,0)
3569 d_t_work(j)=d_t_old(j,0)
3570 d_a_work(j)=d_a_old(j,0)
3575 dc_work(ind+j)=dc_old(j,i)
3576 d_t_work(ind+j)=d_t_old(j,i)
3577 d_a_work(ind+j)=d_a_old(j,i)
3582 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3584 dc_work(ind+j)=dc_old(j,i+nres)
3585 d_t_work(ind+j)=d_t_old(j,i+nres)
3586 d_a_work(ind+j)=d_a_old(j,i+nres)
3595 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3599 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3600 vfric_mat(i,j),afric_mat(i,j),&
3601 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3609 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3610 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3611 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3612 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3614 d_t_work_new(i)=ddt1+0.5d0*ddt2
3615 d_t_work(i)=ddt1+ddt2
3620 d_t(j,0)=d_t_work(j)
3625 dc(j,i)=dc_work(ind+j)
3626 d_t(j,i)=d_t_work(ind+j)
3632 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3633 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3634 .and.(mnum.ne.5)) then
3637 dc(j,inres)=dc_work(ind+j)
3638 d_t(j,inres)=d_t_work(ind+j)
3644 end subroutine sd_verlet1_ciccotti
3645 !-----------------------------------------------------------------------------
3646 subroutine sd_verlet2_ciccotti
3648 ! Calculating the adjusted velocities for accelerations
3650 ! implicit real*8 (a-h,o-z)
3651 ! include 'DIMENSIONS'
3652 ! include 'COMMON.CONTROL'
3653 ! include 'COMMON.VAR'
3654 ! include 'COMMON.MD'
3656 ! include 'COMMON.LANGEVIN'
3658 ! include 'COMMON.LANGEVIN.lang0'
3660 ! include 'COMMON.CHAIN'
3661 ! include 'COMMON.DERIV'
3662 ! include 'COMMON.GEO'
3663 ! include 'COMMON.LOCAL'
3664 ! include 'COMMON.INTERACT'
3665 ! include 'COMMON.IOUNITS'
3666 ! include 'COMMON.NAMES'
3667 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3668 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3669 !el common /stochcalc/ stochforcvec
3670 real(kind=8) :: ddt1,ddt2
3671 integer :: i,j,ind,inres
3673 ! Compute the stochastic forces which contribute to velocity change
3675 call stochastic_force(stochforcvecV)
3682 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3683 ! ddt2=ddt2+vrand_mat2(i,j)*stochforcvecV(j)
3684 ddt2=ddt2+vrand_mat2(i,j)*stochforcvec(j)
3686 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3690 d_t(j,0)=d_t_work(j)
3695 d_t(j,i)=d_t_work(ind+j)
3701 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3703 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3706 d_t(j,inres)=d_t_work(ind+j)
3712 end subroutine sd_verlet2_ciccotti
3714 !-----------------------------------------------------------------------------
3716 !-----------------------------------------------------------------------------
3717 subroutine inertia_tensor
3719 ! Calculating the intertia tensor for the entire protein in order to
3720 ! remove the perpendicular components of velocity matrix which cause
3721 ! the molecule to rotate.
3724 ! implicit real*8 (a-h,o-z)
3725 ! include 'DIMENSIONS'
3726 ! include 'COMMON.CONTROL'
3727 ! include 'COMMON.VAR'
3728 ! include 'COMMON.MD'
3729 ! include 'COMMON.CHAIN'
3730 ! include 'COMMON.DERIV'
3731 ! include 'COMMON.GEO'
3732 ! include 'COMMON.LOCAL'
3733 ! include 'COMMON.INTERACT'
3734 ! include 'COMMON.IOUNITS'
3735 ! include 'COMMON.NAMES'
3737 real(kind=8),dimension(3,3) :: Im,Imcp,eigvec,Id
3738 real(kind=8),dimension(3) :: pr,eigval,L,vp,vrot
3739 real(kind=8) :: M_SC,mag,mag2,M_PEP
3740 real(kind=8),dimension(3,0:nres) :: vpp !(3,0:MAXRES)
3741 real(kind=8),dimension(3) :: vs_p,pp,incr,v
3742 real(kind=8),dimension(3,3) :: pr1,pr2
3744 !el common /gucio/ cm
3745 integer :: iti,inres,i,j,k,mnum
3756 ! calculating the center of the mass of the protein
3760 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3761 if (itype(i,mnum).eq.ntyp1_molec(mnum)) cycle
3762 M_PEP=M_PEP+mp(mnum)
3764 cm(j)=cm(j)+(c(j,i)+0.5d0*dc(j,i))*mp(mnum)
3773 if (mnum.eq.5) cycle
3774 iti=iabs(itype(i,mnum))
3775 M_SC=M_SC+msc(iabs(iti),mnum)
3778 cm(j)=cm(j)+msc(iabs(iti),mnum)*c(j,inres)
3782 cm(j)=cm(j)/(M_SC+M_PEP)
3787 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3789 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3791 Im(1,1)=Im(1,1)+mp(mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
3792 Im(1,2)=Im(1,2)-mp(mnum)*pr(1)*pr(2)
3793 Im(1,3)=Im(1,3)-mp(mnum)*pr(1)*pr(3)
3794 Im(2,3)=Im(2,3)-mp(mnum)*pr(2)*pr(3)
3795 Im(2,2)=Im(2,2)+mp(mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
3796 Im(3,3)=Im(3,3)+mp(mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
3801 iti=iabs(itype(i,mnum))
3802 if (mnum.eq.5) cycle
3805 pr(j)=c(j,inres)-cm(j)
3807 Im(1,1)=Im(1,1)+msc(iabs(iti),mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
3808 Im(1,2)=Im(1,2)-msc(iabs(iti),mnum)*pr(1)*pr(2)
3809 Im(1,3)=Im(1,3)-msc(iabs(iti),mnum)*pr(1)*pr(3)
3810 Im(2,3)=Im(2,3)-msc(iabs(iti),mnum)*pr(2)*pr(3)
3811 Im(2,2)=Im(2,2)+msc(iabs(iti),mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
3812 Im(3,3)=Im(3,3)+msc(iabs(iti),mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
3817 Im(1,1)=Im(1,1)+Ip(mnum)*(1-dc_norm(1,i)*dc_norm(1,i))* &
3818 vbld(i+1)*vbld(i+1)*0.25d0
3819 Im(1,2)=Im(1,2)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(2,i))* &
3820 vbld(i+1)*vbld(i+1)*0.25d0
3821 Im(1,3)=Im(1,3)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(3,i))* &
3822 vbld(i+1)*vbld(i+1)*0.25d0
3823 Im(2,3)=Im(2,3)+Ip(mnum)*(-dc_norm(2,i)*dc_norm(3,i))* &
3824 vbld(i+1)*vbld(i+1)*0.25d0
3825 Im(2,2)=Im(2,2)+Ip(mnum)*(1-dc_norm(2,i)*dc_norm(2,i))* &
3826 vbld(i+1)*vbld(i+1)*0.25d0
3827 Im(3,3)=Im(3,3)+Ip(mnum)*(1-dc_norm(3,i)*dc_norm(3,i))* &
3828 vbld(i+1)*vbld(i+1)*0.25d0
3834 ! if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
3835 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3836 .and.(mnum.ne.5)) then
3837 iti=iabs(itype(i,mnum))
3839 Im(1,1)=Im(1,1)+Isc(iti,mnum)*(1-dc_norm(1,inres)* &
3840 dc_norm(1,inres))*vbld(inres)*vbld(inres)
3841 Im(1,2)=Im(1,2)-Isc(iti,mnum)*(dc_norm(1,inres)* &
3842 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3843 Im(1,3)=Im(1,3)-Isc(iti,mnum)*(dc_norm(1,inres)* &
3844 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3845 Im(2,3)=Im(2,3)-Isc(iti,mnum)*(dc_norm(2,inres)* &
3846 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3847 Im(2,2)=Im(2,2)+Isc(iti,mnum)*(1-dc_norm(2,inres)* &
3848 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3849 Im(3,3)=Im(3,3)+Isc(iti,mnum)*(1-dc_norm(3,inres)* &
3850 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3855 ! write(iout,*) "The angular momentum before adjustment:"
3856 ! write(iout,*) (L(j),j=1,3)
3862 ! Copying the Im matrix for the djacob subroutine
3870 ! Finding the eigenvectors and eignvalues of the inertia tensor
3871 call djacob(3,3,10000,1.0d-10,Imcp,eigvec,eigval)
3872 ! write (iout,*) "Eigenvalues & Eigenvectors"
3873 ! write (iout,'(5x,3f10.5)') (eigval(i),i=1,3)
3876 ! write (iout,'(i5,3f10.5)') i,(eigvec(i,j),j=1,3)
3878 ! Constructing the diagonalized matrix
3880 if (dabs(eigval(i)).gt.1.0d-15) then
3881 Id(i,i)=1.0d0/eigval(i)
3888 Imcp(i,j)=eigvec(j,i)
3894 pr1(i,j)=pr1(i,j)+Id(i,k)*Imcp(k,j)
3901 pr2(i,j)=pr2(i,j)+eigvec(i,k)*pr1(k,j)
3905 ! Calculating the total rotational velocity of the molecule
3908 vrot(i)=vrot(i)+pr2(i,j)*L(j)
3911 ! Resetting the velocities
3913 call vecpr(vrot(1),dc(1,i),vp)
3915 d_t(j,i)=d_t(j,i)-vp(j)
3920 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3921 .and.(mnum.ne.5)) then
3922 ! if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
3923 ! if(itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3925 call vecpr(vrot(1),dc(1,inres),vp)
3927 d_t(j,inres)=d_t(j,inres)-vp(j)
3932 ! write(iout,*) "The angular momentum after adjustment:"
3933 ! write(iout,*) (L(j),j=1,3)
3936 end subroutine inertia_tensor
3937 !-----------------------------------------------------------------------------
3938 subroutine angmom(cm,L)
3941 ! implicit real*8 (a-h,o-z)
3942 ! include 'DIMENSIONS'
3943 ! include 'COMMON.CONTROL'
3944 ! include 'COMMON.VAR'
3945 ! include 'COMMON.MD'
3946 ! include 'COMMON.CHAIN'
3947 ! include 'COMMON.DERIV'
3948 ! include 'COMMON.GEO'
3949 ! include 'COMMON.LOCAL'
3950 ! include 'COMMON.INTERACT'
3951 ! include 'COMMON.IOUNITS'
3952 ! include 'COMMON.NAMES'
3953 real(kind=8) :: mscab
3954 real(kind=8),dimension(3) :: L,cm,pr,vp,vrot,incr,v,pp
3955 integer :: iti,inres,i,j,mnum
3956 ! Calculate the angular momentum
3965 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3967 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3970 v(j)=incr(j)+0.5d0*d_t(j,i)
3973 incr(j)=incr(j)+d_t(j,i)
3975 call vecpr(pr(1),v(1),vp)
3977 L(j)=L(j)+mp(mnum)*vp(j)
3981 pp(j)=0.5d0*d_t(j,i)
3983 call vecpr(pr(1),pp(1),vp)
3985 L(j)=L(j)+Ip(mnum)*vp(j)
3993 iti=iabs(itype(i,mnum))
4001 pr(j)=c(j,inres)-cm(j)
4003 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4004 .and.(mnum.ne.5)) then
4006 v(j)=incr(j)+d_t(j,inres)
4013 call vecpr(pr(1),v(1),vp)
4014 ! write (iout,*) "i",i," iti",iti," pr",(pr(j),j=1,3),
4015 ! & " v",(v(j),j=1,3)," vp",(vp(j),j=1,3)
4017 L(j)=L(j)+mscab*vp(j)
4019 ! write (iout,*) "L",(l(j),j=1,3)
4020 if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4021 .and.(mnum.ne.5)) then
4023 v(j)=incr(j)+d_t(j,inres)
4025 call vecpr(dc(1,inres),d_t(1,inres),vp)
4027 L(j)=L(j)+Isc(iti,mnum)*vp(j)
4031 incr(j)=incr(j)+d_t(j,i)
4035 end subroutine angmom
4036 !-----------------------------------------------------------------------------
4037 subroutine vcm_vel(vcm)
4040 ! implicit real*8 (a-h,o-z)
4041 ! include 'DIMENSIONS'
4042 ! include 'COMMON.VAR'
4043 ! include 'COMMON.MD'
4044 ! include 'COMMON.CHAIN'
4045 ! include 'COMMON.DERIV'
4046 ! include 'COMMON.GEO'
4047 ! include 'COMMON.LOCAL'
4048 ! include 'COMMON.INTERACT'
4049 ! include 'COMMON.IOUNITS'
4050 real(kind=8),dimension(3) :: vcm,vv
4051 real(kind=8) :: summas,amas
4061 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
4063 summas=summas+mp(mnum)
4065 vcm(j)=vcm(j)+mp(mnum)*(vv(j)+0.5d0*d_t(j,i))
4069 amas=msc(iabs(itype(i,mnum)),mnum)
4074 if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4075 .and.(mnum.ne.5)) then
4077 vcm(j)=vcm(j)+amas*(vv(j)+d_t(j,i+nres))
4081 vcm(j)=vcm(j)+amas*vv(j)
4085 vv(j)=vv(j)+d_t(j,i)
4088 ! write (iout,*) "vcm",(vcm(j),j=1,3)," summas",summas
4090 vcm(j)=vcm(j)/summas
4093 end subroutine vcm_vel
4094 !-----------------------------------------------------------------------------
4096 !-----------------------------------------------------------------------------
4098 ! RATTLE algorithm for velocity Verlet - step 1, UNRES
4102 ! implicit real*8 (a-h,o-z)
4103 ! include 'DIMENSIONS'
4105 ! include 'COMMON.CONTROL'
4106 ! include 'COMMON.VAR'
4107 ! include 'COMMON.MD'
4109 ! include 'COMMON.LANGEVIN'
4111 ! include 'COMMON.LANGEVIN.lang0'
4113 ! include 'COMMON.CHAIN'
4114 ! include 'COMMON.DERIV'
4115 ! include 'COMMON.GEO'
4116 ! include 'COMMON.LOCAL'
4117 ! include 'COMMON.INTERACT'
4118 ! include 'COMMON.IOUNITS'
4119 ! include 'COMMON.NAMES'
4120 ! include 'COMMON.TIME1'
4121 !el real(kind=8) :: gginv(2*nres,2*nres),&
4122 !el gdc(3,2*nres,2*nres)
4123 real(kind=8) :: dC_uncor(3,2*nres) !,&
4124 !el real(kind=8) :: Cmat(2*nres,2*nres)
4125 real(kind=8) :: x(2*nres),xcorr(3,2*nres) !maxres2=2*maxres
4126 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4127 !el common /przechowalnia/ nbond
4128 integer :: max_rattle = 5
4129 logical :: lprn = .false., lprn1 = .false., not_done
4130 real(kind=8) :: tol_rattle = 1.0d-5
4132 integer :: ii,i,j,jj,l,ind,ind1,nres2
4135 !el /common/ przechowalnia
4137 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4138 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4139 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4141 if (lprn) write (iout,*) "RATTLE1"
4145 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4146 .and.(mnum.ne.5)) nbond=nbond+1
4148 ! Make a folded form of the Ginv-matrix
4161 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4166 if (itype(k,1).ne.10 .and. itype(k,mnum).ne.ntyp1_molec(mnum)&
4167 .and.(mnum.ne.5)) then
4171 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4179 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4190 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4194 if (itype(k,1).ne.10) then
4198 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4206 write (iout,*) "Matrix GGinv"
4207 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4213 if (iter.gt.max_rattle) then
4214 write (iout,*) "Error - too many iterations in RATTLE."
4217 ! Calculate the matrix C = GG**(-1) dC_old o dC
4222 dC_uncor(j,ind1)=dC(j,i)
4226 if (itype(i,1).ne.10) then
4229 dC_uncor(j,ind1)=dC(j,i+nres)
4238 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4242 if (itype(k,1).ne.10) then
4245 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4250 ! Calculate deviations from standard virtual-bond lengths
4254 x(ind)=vbld(i+1)**2-vbl**2
4257 if (itype(i,1).ne.10) then
4259 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4263 write (iout,*) "Coordinates and violations"
4265 write(iout,'(i5,3f10.5,5x,e15.5)') &
4266 i,(dC_uncor(j,i),j=1,3),x(i)
4268 write (iout,*) "Velocities and violations"
4272 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4273 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4277 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4278 .and.(mnum.ne.5)) then
4281 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4282 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4283 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4286 ! write (iout,*) "gdc"
4288 ! write (iout,*) "i",i
4290 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4296 if (dabs(x(i)).gt.xmax) then
4300 if (xmax.lt.tol_rattle) then
4304 ! Calculate the matrix of the system of equations
4309 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4314 write (iout,*) "Matrix Cmat"
4315 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4317 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4318 ! Add constraint term to positions
4325 xx = xx+x(ii)*gdc(j,ind,ii)
4329 d_t_new(j,i)=d_t_new(j,i)-xx/d_time
4333 if (itype(i,1).ne.10) then
4338 xx = xx+x(ii)*gdc(j,ind,ii)
4341 dC(j,i+nres)=dC(j,i+nres)-xx
4342 d_t_new(j,i+nres)=d_t_new(j,i+nres)-xx/d_time
4346 ! Rebuild the chain using the new coordinates
4347 call chainbuild_cart
4349 write (iout,*) "New coordinates, Lagrange multipliers,",&
4350 " and differences between actual and standard bond lengths"
4354 xx=vbld(i+1)**2-vbl**2
4355 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4356 i,(dC(j,i),j=1,3),x(ind),xx
4360 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4363 xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4364 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4365 i,(dC(j,i+nres),j=1,3),x(ind),xx
4368 write (iout,*) "Velocities and violations"
4372 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4373 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4376 if (itype(i,1).ne.10) then
4378 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4379 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4380 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4387 10 write (iout,*) "Error - singularity in solving the system",&
4388 " of equations for Lagrange multipliers."
4392 "RATTLE inactive; use -DRATTLE switch at compile time."
4395 end subroutine rattle1
4396 !-----------------------------------------------------------------------------
4398 ! RATTLE algorithm for velocity Verlet - step 2, UNRES
4402 ! implicit real*8 (a-h,o-z)
4403 ! include 'DIMENSIONS'
4405 ! include 'COMMON.CONTROL'
4406 ! include 'COMMON.VAR'
4407 ! include 'COMMON.MD'
4409 ! include 'COMMON.LANGEVIN'
4411 ! include 'COMMON.LANGEVIN.lang0'
4413 ! include 'COMMON.CHAIN'
4414 ! include 'COMMON.DERIV'
4415 ! include 'COMMON.GEO'
4416 ! include 'COMMON.LOCAL'
4417 ! include 'COMMON.INTERACT'
4418 ! include 'COMMON.IOUNITS'
4419 ! include 'COMMON.NAMES'
4420 ! include 'COMMON.TIME1'
4421 !el real(kind=8) :: gginv(2*nres,2*nres),&
4422 !el gdc(3,2*nres,2*nres)
4423 real(kind=8) :: dC_uncor(3,2*nres) !,&
4424 !el Cmat(2*nres,2*nres)
4425 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4426 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4427 !el common /przechowalnia/ nbond
4428 integer :: max_rattle = 5
4429 logical :: lprn = .false., lprn1 = .false., not_done
4430 real(kind=8) :: tol_rattle = 1.0d-5
4434 !el /common/ przechowalnia
4435 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4436 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4437 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4439 if (lprn) write (iout,*) "RATTLE2"
4440 if (lprn) write (iout,*) "Velocity correction"
4441 ! Calculate the matrix G dC
4447 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k)
4452 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4453 .and.(mnum.ne.5)) then
4456 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k+nres)
4462 ! write (iout,*) "gdc"
4464 ! write (iout,*) "i",i
4466 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4470 ! Calculate the matrix of the system of equations
4477 Cmat(ind,j)=Cmat(ind,j)+dC(k,i)*gdc(k,ind,j)
4483 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4484 .and.(mnum.ne.5)) then
4489 Cmat(ind,j)=Cmat(ind,j)+dC(k,i+nres)*gdc(k,ind,j)
4494 ! Calculate the scalar product dC o d_t_new
4498 x(ind)=scalar(d_t(1,i),dC(1,i))
4502 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4503 .and.(mnum.ne.5)) then
4505 x(ind)=scalar(d_t(1,i+nres),dC(1,i+nres))
4509 write (iout,*) "Velocities and violations"
4513 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4514 i,ind,(d_t(j,i),j=1,3),x(ind)
4518 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4519 .and.(mnum.ne.5)) then
4521 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4522 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind)
4528 if (dabs(x(i)).gt.xmax) then
4532 if (xmax.lt.tol_rattle) then
4537 write (iout,*) "Matrix Cmat"
4538 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4540 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4541 ! Add constraint term to velocities
4548 xx = xx+x(ii)*gdc(j,ind,ii)
4550 d_t(j,i)=d_t(j,i)-xx
4555 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4556 .and.(mnum.ne.5)) then
4561 xx = xx+x(ii)*gdc(j,ind,ii)
4563 d_t(j,i+nres)=d_t(j,i+nres)-xx
4569 "New velocities, Lagrange multipliers violations"
4573 if (lprn) write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4574 i,ind,(d_t(j,i),j=1,3),x(ind),scalar(d_t(1,i),dC(1,i))
4578 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4581 write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4582 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind),&
4583 scalar(d_t(1,i+nres),dC(1,i+nres))
4589 10 write (iout,*) "Error - singularity in solving the system",&
4590 " of equations for Lagrange multipliers."
4594 "RATTLE inactive; use -DRATTLE option at compile time."
4597 end subroutine rattle2
4598 !-----------------------------------------------------------------------------
4599 subroutine rattle_brown
4600 ! RATTLE/LINCS algorithm for Brownian dynamics, UNRES
4604 ! implicit real*8 (a-h,o-z)
4605 ! include 'DIMENSIONS'
4607 ! include 'COMMON.CONTROL'
4608 ! include 'COMMON.VAR'
4609 ! include 'COMMON.MD'
4611 ! include 'COMMON.LANGEVIN'
4613 ! include 'COMMON.LANGEVIN.lang0'
4615 ! include 'COMMON.CHAIN'
4616 ! include 'COMMON.DERIV'
4617 ! include 'COMMON.GEO'
4618 ! include 'COMMON.LOCAL'
4619 ! include 'COMMON.INTERACT'
4620 ! include 'COMMON.IOUNITS'
4621 ! include 'COMMON.NAMES'
4622 ! include 'COMMON.TIME1'
4623 !el real(kind=8) :: gginv(2*nres,2*nres),&
4624 !el gdc(3,2*nres,2*nres)
4625 real(kind=8) :: dC_uncor(3,2*nres) !,&
4626 !el real(kind=8) :: Cmat(2*nres,2*nres)
4627 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4628 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4629 !el common /przechowalnia/ nbond
4630 integer :: max_rattle = 5
4631 logical :: lprn = .false., lprn1 = .false., not_done
4632 real(kind=8) :: tol_rattle = 1.0d-5
4636 !el /common/ przechowalnia
4637 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4638 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4639 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4642 if (lprn) write (iout,*) "RATTLE_BROWN"
4645 if (itype(i,1).ne.10) nbond=nbond+1
4647 ! Make a folded form of the Ginv-matrix
4660 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4664 if (itype(k,1).ne.10) then
4668 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4675 if (itype(i,1).ne.10) then
4685 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4689 if (itype(k,1).ne.10) then
4693 if (j.eq.1 .and. l.eq.1)GGinv(ii,jj)=fricmat(ind,ind1)
4701 write (iout,*) "Matrix GGinv"
4702 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4708 if (iter.gt.max_rattle) then
4709 write (iout,*) "Error - too many iterations in RATTLE."
4712 ! Calculate the matrix C = GG**(-1) dC_old o dC
4717 dC_uncor(j,ind1)=dC(j,i)
4721 if (itype(i,1).ne.10) then
4724 dC_uncor(j,ind1)=dC(j,i+nres)
4733 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4737 if (itype(k,1).ne.10) then
4740 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4745 ! Calculate deviations from standard virtual-bond lengths
4749 x(ind)=vbld(i+1)**2-vbl**2
4752 if (itype(i,1).ne.10) then
4754 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4758 write (iout,*) "Coordinates and violations"
4760 write(iout,'(i5,3f10.5,5x,e15.5)') &
4761 i,(dC_uncor(j,i),j=1,3),x(i)
4763 write (iout,*) "Velocities and violations"
4767 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4768 i,ind,(d_t(j,i),j=1,3),scalar(d_t(1,i),dC_old(1,i))
4771 if (itype(i,1).ne.10) then
4773 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4774 i+nres,ind,(d_t(j,i+nres),j=1,3),&
4775 scalar(d_t(1,i+nres),dC_old(1,i+nres))
4778 write (iout,*) "gdc"
4780 write (iout,*) "i",i
4782 write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4788 if (dabs(x(i)).gt.xmax) then
4792 if (xmax.lt.tol_rattle) then
4796 ! Calculate the matrix of the system of equations
4801 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4806 write (iout,*) "Matrix Cmat"
4807 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4809 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4810 ! Add constraint term to positions
4817 xx = xx+x(ii)*gdc(j,ind,ii)
4820 d_t(j,i)=d_t(j,i)+xx/d_time
4825 if (itype(i,1).ne.10) then
4830 xx = xx+x(ii)*gdc(j,ind,ii)
4833 d_t(j,i+nres)=d_t(j,i+nres)+xx/d_time
4834 dC(j,i+nres)=dC(j,i+nres)+xx
4838 ! Rebuild the chain using the new coordinates
4839 call chainbuild_cart
4841 write (iout,*) "New coordinates, Lagrange multipliers,",&
4842 " and differences between actual and standard bond lengths"
4846 xx=vbld(i+1)**2-vbl**2
4847 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4848 i,(dC(j,i),j=1,3),x(ind),xx
4851 if (itype(i,1).ne.10) then
4853 xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4854 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4855 i,(dC(j,i+nres),j=1,3),x(ind),xx
4858 write (iout,*) "Velocities and violations"
4862 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4863 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4866 if (itype(i,1).ne.10) then
4868 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4869 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4870 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4877 10 write (iout,*) "Error - singularity in solving the system",&
4878 " of equations for Lagrange multipliers."
4882 "RATTLE inactive; use -DRATTLE option at compile time"
4885 end subroutine rattle_brown
4886 !-----------------------------------------------------------------------------
4888 !-----------------------------------------------------------------------------
4889 subroutine friction_force
4894 ! implicit real*8 (a-h,o-z)
4895 ! include 'DIMENSIONS'
4896 ! include 'COMMON.VAR'
4897 ! include 'COMMON.CHAIN'
4898 ! include 'COMMON.DERIV'
4899 ! include 'COMMON.GEO'
4900 ! include 'COMMON.LOCAL'
4901 ! include 'COMMON.INTERACT'
4902 ! include 'COMMON.MD'
4904 ! include 'COMMON.LANGEVIN'
4906 ! include 'COMMON.LANGEVIN.lang0'
4908 ! include 'COMMON.IOUNITS'
4909 !el real(kind=8),dimension(6*nres) :: gamvec !(MAXRES6) maxres6=6*maxres
4910 !el common /syfek/ gamvec
4911 real(kind=8) :: vv(3),vvtot(3,nres),v_work(6*nres) !,&
4912 !el ginvfric(2*nres,2*nres) !maxres2=2*maxres
4913 !el common /przechowalnia/ ginvfric
4915 logical :: lprn = .false., checkmode = .false.
4916 integer :: i,j,ind,k,nres2,nres6,mnum
4920 if(.not.allocated(gamvec)) allocate(gamvec(nres6)) !(MAXRES6)
4921 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
4929 d_t_work(j)=d_t(j,0)
4934 d_t_work(ind+j)=d_t(j,i)
4940 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
4941 .and.(mnum.ne.5)) then
4943 d_t_work(ind+j)=d_t(j,i+nres)
4949 call fricmat_mult(d_t_work,fric_work)
4951 if (.not.checkmode) return
4954 write (iout,*) "d_t_work and fric_work"
4956 write (iout,'(i3,2e15.5)') i,d_t_work(i),fric_work(i)
4960 friction(j,0)=fric_work(j)
4965 friction(j,i)=fric_work(ind+j)
4971 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
4972 .and.(mnum.ne.5)) then
4973 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
4975 friction(j,i+nres)=fric_work(ind+j)
4981 write(iout,*) "Friction backbone"
4983 write(iout,'(i5,3e15.5,5x,3e15.5)') &
4984 i,(friction(j,i),j=1,3),(d_t(j,i),j=1,3)
4986 write(iout,*) "Friction side chain"
4988 write(iout,'(i5,3e15.5,5x,3e15.5)') &
4989 i,(friction(j,i+nres),j=1,3),(d_t(j,i+nres),j=1,3)
4998 vvtot(j,i)=vv(j)+0.5d0*d_t(j,i)
4999 vvtot(j,i+nres)=vv(j)+d_t(j,i+nres)
5000 vv(j)=vv(j)+d_t(j,i)
5003 write (iout,*) "vvtot backbone and sidechain"
5005 write (iout,'(i5,3e15.5,5x,3e15.5)') i,(vvtot(j,i),j=1,3),&
5006 (vvtot(j,i+nres),j=1,3)
5011 v_work(ind+j)=vvtot(j,i)
5017 v_work(ind+j)=vvtot(j,i+nres)
5021 write (iout,*) "v_work gamvec and site-based friction forces"
5023 write (iout,'(i5,3e15.5)') i,v_work(i),gamvec(i),&
5027 ! fric_work1(i)=0.0d0
5029 ! fric_work1(i)=fric_work1(i)-A(j,i)*gamvec(j)*v_work(j)
5032 ! write (iout,*) "fric_work and fric_work1"
5034 ! write (iout,'(i5,2e15.5)') i,fric_work(i),fric_work1(i)
5040 ginvfric(i,j)=ginvfric(i,j)+ginv(i,k)*fricmat(k,j)
5044 write (iout,*) "ginvfric"
5046 write (iout,'(i5,100f8.3)') i,(ginvfric(i,j),j=1,dimen)
5048 write (iout,*) "symmetry check"
5051 write (iout,*) i,j,ginvfric(i,j)-ginvfric(j,i)
5056 end subroutine friction_force
5057 !-----------------------------------------------------------------------------
5058 subroutine setup_fricmat
5062 use control_data, only:time_Bcast
5063 use control, only:tcpu
5065 ! implicit real*8 (a-h,o-z)
5069 real(kind=8) :: time00
5071 ! include 'DIMENSIONS'
5072 ! include 'COMMON.VAR'
5073 ! include 'COMMON.CHAIN'
5074 ! include 'COMMON.DERIV'
5075 ! include 'COMMON.GEO'
5076 ! include 'COMMON.LOCAL'
5077 ! include 'COMMON.INTERACT'
5078 ! include 'COMMON.MD'
5079 ! include 'COMMON.SETUP'
5080 ! include 'COMMON.TIME1'
5081 ! integer licznik /0/
5084 ! include 'COMMON.LANGEVIN'
5086 ! include 'COMMON.LANGEVIN.lang0'
5088 ! include 'COMMON.IOUNITS'
5090 integer :: i,j,ind,ind1,m
5091 logical :: lprn = .false.
5092 real(kind=8) :: dtdi !el ,gamvec(2*nres)
5093 !el real(kind=8),dimension(2*nres,2*nres) :: ginvfric,fcopy
5094 real(kind=8),dimension(2*nres,2*nres) :: fcopy
5095 !el real(kind=8),dimension(2*nres*(2*nres+1)/2) :: Ghalf !(mmaxres2) (mmaxres2=(maxres2*(maxres2+1)/2))
5096 !el common /syfek/ gamvec
5097 real(kind=8) :: work(8*2*nres)
5098 integer :: iwork(2*nres)
5099 !el common /przechowalnia/ ginvfric,Ghalf,fcopy
5100 integer :: ii,iti,k,l,nzero,nres2,nres6,ierr,mnum
5102 if (fg_rank.ne.king) goto 10
5107 if(.not.allocated(gamvec)) allocate(gamvec(nres2)) !(MAXRES2)
5108 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
5109 !el if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5110 !el allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5111 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !maxres2=2*maxres
5113 !el if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5114 ! Zeroing out fricmat
5120 ! Load the friction coefficients corresponding to peptide groups
5125 gamvec(ind1)=gamp(mnum)
5127 ! Load the friction coefficients corresponding to side chains
5131 gamsc(ntyp1_molec(j),j)=1.0d0
5138 gamvec(ii)=gamsc(iabs(iti),mnum)
5140 if (surfarea) call sdarea(gamvec)
5142 ! write (iout,*) "Matrix A and vector gamma"
5144 ! write (iout,'(i2,$)') i
5146 ! write (iout,'(f4.1,$)') A(i,j)
5148 ! write (iout,'(f8.3)') gamvec(i)
5152 write (iout,*) "Vector gamvec"
5154 write (iout,'(i5,f10.5)') i, gamvec(i)
5158 ! The friction matrix
5163 dtdi=dtdi+A(j,k)*A(j,i)*gamvec(j)
5170 write (iout,'(//a)') "Matrix fricmat"
5171 call matout2(dimen,dimen,nres2,nres2,fricmat)
5173 if (lang.eq.2 .or. lang.eq.3) then
5174 ! Mass-scale the friction matrix if non-direct integration will be performed
5180 Ginvfric(i,j)=Ginvfric(i,j)+ &
5181 Gsqrm(i,k)*Gsqrm(l,j)*fricmat(k,l)
5186 ! Diagonalize the friction matrix
5191 Ghalf(ind)=Ginvfric(i,j)
5194 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5197 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5198 " mass-scaled friction matrix"
5199 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5201 ! Precompute matrices for tinker stochastic integrator
5208 mt1(i,j)=mt1(i,j)+fricvec(k,i)*gsqrm(k,j)
5209 mt2(i,j)=mt2(i,j)+fricvec(k,i)*gsqrp(k,j)
5215 else if (lang.eq.4) then
5216 ! Diagonalize the friction matrix
5221 Ghalf(ind)=fricmat(i,j)
5224 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5227 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5229 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5231 ! Determine the number of zero eigenvalues of the friction matrix
5232 nzero=max0(dimen-dimen1,0)
5233 ! do while (fricgam(nzero+1).le.1.0d-5 .and. nzero.lt.dimen)
5236 write (iout,*) "Number of zero eigenvalues:",nzero
5241 fricmat(i,j)=fricmat(i,j) &
5242 +fricvec(i,k)*fricvec(j,k)/fricgam(k)
5247 write (iout,'(//a)') "Generalized inverse of fricmat"
5248 call matout(dimen,dimen,nres6,nres6,fricmat)
5253 if (nfgtasks.gt.1) then
5254 if (fg_rank.eq.0) then
5255 ! The matching BROADCAST for fg processors is called in ERGASTULUM
5261 call MPI_Bcast(10,1,MPI_INTEGER,king,FG_COMM,IERROR)
5263 time_Bcast=time_Bcast+MPI_Wtime()-time00
5265 time_Bcast=time_Bcast+tcpu()-time00
5267 ! print *,"Processor",myrank,
5268 ! & " BROADCAST iorder in SETUP_FRICMAT"
5271 write (iout,*) "setup_fricmat licznik"!,licznik !sp
5277 ! Scatter the friction matrix
5278 call MPI_Scatterv(fricmat(1,1),nginv_counts(0),&
5279 nginv_start(0),MPI_DOUBLE_PRECISION,fcopy(1,1),&
5280 myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
5283 time_scatter=time_scatter+MPI_Wtime()-time00
5284 time_scatter_fmat=time_scatter_fmat+MPI_Wtime()-time00
5286 time_scatter=time_scatter+tcpu()-time00
5287 time_scatter_fmat=time_scatter_fmat+tcpu()-time00
5291 do j=1,2*my_ng_count
5292 fricmat(j,i)=fcopy(i,j)
5295 ! write (iout,*) "My chunk of fricmat"
5296 ! call MATOUT2(my_ng_count,dimen,maxres2,maxres2,fcopy)
5300 end subroutine setup_fricmat
5301 !-----------------------------------------------------------------------------
5302 subroutine stochastic_force(stochforcvec)
5305 use random, only:anorm_distr
5306 ! implicit real*8 (a-h,o-z)
5307 ! include 'DIMENSIONS'
5308 use control, only: tcpu
5313 ! include 'COMMON.VAR'
5314 ! include 'COMMON.CHAIN'
5315 ! include 'COMMON.DERIV'
5316 ! include 'COMMON.GEO'
5317 ! include 'COMMON.LOCAL'
5318 ! include 'COMMON.INTERACT'
5319 ! include 'COMMON.MD'
5320 ! include 'COMMON.TIME1'
5322 ! include 'COMMON.LANGEVIN'
5324 ! include 'COMMON.LANGEVIN.lang0'
5326 ! include 'COMMON.IOUNITS'
5328 real(kind=8) :: x,sig,lowb,highb
5329 real(kind=8) :: ff(3),force(3,0:2*nres),zeta2,lowb2
5330 real(kind=8) :: highb2,sig2,forcvec(6*nres),stochforcvec(6*nres)
5331 real(kind=8) :: time00
5332 logical :: lprn = .false.
5333 integer :: i,j,ind,mnum
5337 stochforc(j,i)=0.0d0
5347 ! Compute the stochastic forces acting on bodies. Store in force.
5353 force(j,i)=anorm_distr(x,sig,lowb,highb)
5361 force(j,i+nres)=anorm_distr(x,sig2,lowb2,highb2)
5365 time_fsample=time_fsample+MPI_Wtime()-time00
5367 time_fsample=time_fsample+tcpu()-time00
5369 ! Compute the stochastic forces acting on virtual-bond vectors.
5375 stochforc(j,i)=ff(j)+0.5d0*force(j,i)
5378 ff(j)=ff(j)+force(j,i)
5380 ! if (itype(i+1,1).ne.ntyp1) then
5382 if (itype(i+1,mnum).ne.ntyp1_molec(mnum)) then
5384 stochforc(j,i)=stochforc(j,i)+force(j,i+nres+1)
5385 ff(j)=ff(j)+force(j,i+nres+1)
5390 stochforc(j,0)=ff(j)+force(j,nnt+nres)
5394 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5395 .and.(mnum.ne.5)) then
5396 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5398 stochforc(j,i+nres)=force(j,i+nres)
5404 stochforcvec(j)=stochforc(j,0)
5409 stochforcvec(ind+j)=stochforc(j,i)
5415 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5416 .and.(mnum.ne.5)) then
5417 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5419 stochforcvec(ind+j)=stochforc(j,i+nres)
5425 write (iout,*) "stochforcvec"
5427 write(iout,'(i5,e15.5)') i,stochforcvec(i)
5429 write(iout,*) "Stochastic forces backbone"
5431 write(iout,'(i5,3e15.5)') i,(stochforc(j,i),j=1,3)
5433 write(iout,*) "Stochastic forces side chain"
5435 write(iout,'(i5,3e15.5)') &
5436 i,(stochforc(j,i+nres),j=1,3)
5444 write (iout,*) i,ind
5446 forcvec(ind+j)=force(j,i)
5451 write (iout,*) i,ind
5453 forcvec(j+ind)=force(j,i+nres)
5458 write (iout,*) "forcvec"
5462 write (iout,'(2i3,2f10.5)') i,j,force(j,i),&
5469 write (iout,'(2i3,2f10.5)') i,j,force(j,i+nres),&
5478 end subroutine stochastic_force
5479 !-----------------------------------------------------------------------------
5480 subroutine sdarea(gamvec)
5482 ! Scale the friction coefficients according to solvent accessible surface areas
5483 ! Code adapted from TINKER
5487 ! implicit real*8 (a-h,o-z)
5488 ! include 'DIMENSIONS'
5489 ! include 'COMMON.CONTROL'
5490 ! include 'COMMON.VAR'
5491 ! include 'COMMON.MD'
5493 ! include 'COMMON.LANGEVIN'
5495 ! include 'COMMON.LANGEVIN.lang0'
5497 ! include 'COMMON.CHAIN'
5498 ! include 'COMMON.DERIV'
5499 ! include 'COMMON.GEO'
5500 ! include 'COMMON.LOCAL'
5501 ! include 'COMMON.INTERACT'
5502 ! include 'COMMON.IOUNITS'
5503 ! include 'COMMON.NAMES'
5504 real(kind=8),dimension(2*nres) :: radius,gamvec !(maxres2)
5505 real(kind=8),parameter :: twosix = 1.122462048309372981d0
5506 logical :: lprn = .false.
5507 real(kind=8) :: probe,area,ratio
5508 integer :: i,j,ind,iti,mnum
5510 ! determine new friction coefficients every few SD steps
5512 ! set the atomic radii to estimates of sigma values
5514 ! print *,"Entered sdarea"
5520 ! Load peptide group radii
5523 radius(i)=pstok(mnum)
5525 ! Load side chain radii
5529 radius(i+nres)=restok(iti,mnum)
5532 ! write (iout,*) "i",i," radius",radius(i)
5535 radius(i) = radius(i) / twosix
5536 if (radius(i) .ne. 0.0d0) radius(i) = radius(i) + probe
5539 ! scale atomic friction coefficients by accessible area
5541 if (lprn) write (iout,*) &
5542 "Original gammas, surface areas, scaling factors, new gammas, ",&
5543 "std's of stochastic forces"
5546 if (radius(i).gt.0.0d0) then
5547 call surfatom (i,area,radius)
5548 ratio = dmax1(area/(4.0d0*pi*radius(i)**2),1.0d-1)
5549 if (lprn) write (iout,'(i5,3f10.5,$)') &
5550 i,gamvec(ind+1),area,ratio
5553 gamvec(ind) = ratio * gamvec(ind)
5556 stdforcp(i)=stdfp(mnum)*dsqrt(gamvec(ind))
5557 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcp(i)
5561 if (radius(i+nres).gt.0.0d0) then
5562 call surfatom (i+nres,area,radius)
5563 ratio = dmax1(area/(4.0d0*pi*radius(i+nres)**2),1.0d-1)
5564 if (lprn) write (iout,'(i5,3f10.5,$)') &
5565 i,gamvec(ind+1),area,ratio
5568 gamvec(ind) = ratio * gamvec(ind)
5571 stdforcsc(i)=stdfsc(itype(i,mnum),mnum)*dsqrt(gamvec(ind))
5572 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcsc(i)
5577 end subroutine sdarea
5578 !-----------------------------------------------------------------------------
5580 !-----------------------------------------------------------------------------
5583 ! ###################################################
5584 ! ## COPYRIGHT (C) 1996 by Jay William Ponder ##
5585 ! ## All Rights Reserved ##
5586 ! ###################################################
5588 ! ################################################################
5590 ! ## subroutine surfatom -- exposed surface area of an atom ##
5592 ! ################################################################
5595 ! "surfatom" performs an analytical computation of the surface
5596 ! area of a specified atom; a simplified version of "surface"
5598 ! literature references:
5600 ! T. J. Richmond, "Solvent Accessible Surface Area and
5601 ! Excluded Volume in Proteins", Journal of Molecular Biology,
5604 ! L. Wesson and D. Eisenberg, "Atomic Solvation Parameters
5605 ! Applied to Molecular Dynamics of Proteins in Solution",
5606 ! Protein Science, 1, 227-235 (1992)
5608 ! variables and parameters:
5610 ! ir number of atom for which area is desired
5611 ! area accessible surface area of the atom
5612 ! radius radii of each of the individual atoms
5615 subroutine surfatom(ir,area,radius)
5617 ! implicit real*8 (a-h,o-z)
5618 ! include 'DIMENSIONS'
5620 ! include 'COMMON.GEO'
5621 ! include 'COMMON.IOUNITS'
5623 integer :: nsup,nstart_sup
5624 ! double precision c,dc,dc_old,d_c_work,xloc,xrot,dc_norm
5625 ! common /chain/ c(3,maxres2+2),dc(3,0:maxres2),dc_old(3,0:maxres2),
5626 ! & xloc(3,maxres),xrot(3,maxres),dc_norm(3,0:maxres2),
5627 ! & dc_work(MAXRES6),nres,nres0
5628 integer,parameter :: maxarc=300
5632 integer :: mi,ni,narc
5633 integer :: key(maxarc)
5634 integer :: intag(maxarc)
5635 integer :: intag1(maxarc)
5636 real(kind=8) :: area,arcsum
5637 real(kind=8) :: arclen,exang
5638 real(kind=8) :: delta,delta2
5639 real(kind=8) :: eps,rmove
5640 real(kind=8) :: xr,yr,zr
5641 real(kind=8) :: rr,rrsq
5642 real(kind=8) :: rplus,rminus
5643 real(kind=8) :: axx,axy,axz
5644 real(kind=8) :: ayx,ayy
5645 real(kind=8) :: azx,azy,azz
5646 real(kind=8) :: uxj,uyj,uzj
5647 real(kind=8) :: tx,ty,tz
5648 real(kind=8) :: txb,tyb,td
5649 real(kind=8) :: tr2,tr,txr,tyr
5650 real(kind=8) :: tk1,tk2
5651 real(kind=8) :: thec,the,t,tb
5652 real(kind=8) :: txk,tyk,tzk
5653 real(kind=8) :: t1,ti,tf,tt
5654 real(kind=8) :: txj,tyj,tzj
5655 real(kind=8) :: ccsq,cc,xysq
5656 real(kind=8) :: bsqk,bk,cosine
5657 real(kind=8) :: dsqj,gi,pix2
5658 real(kind=8) :: therk,dk,gk
5659 real(kind=8) :: risqk,rik
5660 real(kind=8) :: radius(2*nres) !(maxatm) (maxatm=maxres2)
5661 real(kind=8) :: ri(maxarc),risq(maxarc)
5662 real(kind=8) :: ux(maxarc),uy(maxarc),uz(maxarc)
5663 real(kind=8) :: xc(maxarc),yc(maxarc),zc(maxarc)
5664 real(kind=8) :: xc1(maxarc),yc1(maxarc),zc1(maxarc)
5665 real(kind=8) :: dsq(maxarc),bsq(maxarc)
5666 real(kind=8) :: dsq1(maxarc),bsq1(maxarc)
5667 real(kind=8) :: arci(maxarc),arcf(maxarc)
5668 real(kind=8) :: ex(maxarc),lt(maxarc),gr(maxarc)
5669 real(kind=8) :: b(maxarc),b1(maxarc),bg(maxarc)
5670 real(kind=8) :: kent(maxarc),kout(maxarc)
5671 real(kind=8) :: ther(maxarc)
5672 logical :: moved,top
5673 logical :: omit(maxarc)
5676 ! maxatm = 2*nres !maxres2 maxres2=2*maxres
5677 ! maxlight = 8*maxatm
5680 ! maxtors = 4*maxatm
5682 ! zero out the surface area for the sphere of interest
5685 ! write (2,*) "ir",ir," radius",radius(ir)
5686 if (radius(ir) .eq. 0.0d0) return
5688 ! set the overlap significance and connectivity shift
5692 delta2 = delta * delta
5697 ! store coordinates and radius of the sphere of interest
5705 ! initialize values of some counters and summations
5714 ! test each sphere to see if it overlaps the sphere of interest
5717 if (i.eq.ir .or. radius(i).eq.0.0d0) goto 30
5718 rplus = rr + radius(i)
5720 if (abs(tx) .ge. rplus) goto 30
5722 if (abs(ty) .ge. rplus) goto 30
5724 if (abs(tz) .ge. rplus) goto 30
5726 ! check for sphere overlap by testing distance against radii
5728 xysq = tx*tx + ty*ty
5729 if (xysq .lt. delta2) then
5736 if (rplus-cc .le. delta) goto 30
5737 rminus = rr - radius(i)
5739 ! check to see if sphere of interest is completely buried
5741 if (cc-abs(rminus) .le. delta) then
5742 if (rminus .le. 0.0d0) goto 170
5746 ! check for too many overlaps with sphere of interest
5748 if (io .ge. maxarc) then
5750 20 format (/,' SURFATOM -- Increase the Value of MAXARC')
5754 ! get overlap between current sphere and sphere of interest
5763 gr(io) = (ccsq+rplus*rminus) / (2.0d0*rr*b1(io))
5769 ! case where no other spheres overlap the sphere of interest
5772 area = 4.0d0 * pi * rrsq
5776 ! case where only one sphere overlaps the sphere of interest
5779 area = pix2 * (1.0d0 + gr(1))
5780 area = mod(area,4.0d0*pi) * rrsq
5784 ! case where many spheres intersect the sphere of interest;
5785 ! sort the intersecting spheres by their degree of overlap
5787 call sort2 (io,gr,key)
5790 intag(i) = intag1(k)
5799 ! get radius of each overlap circle on surface of the sphere
5804 risq(i) = rrsq - gi*gi
5805 ri(i) = sqrt(risq(i))
5806 ther(i) = 0.5d0*pi - asin(min(1.0d0,max(-1.0d0,gr(i))))
5809 ! find boundary of inaccessible area on sphere of interest
5812 if (.not. omit(k)) then
5819 ! check to see if J circle is intersecting K circle;
5820 ! get distance between circle centers and sum of radii
5823 if (omit(j)) goto 60
5824 cc = (txk*xc(j)+tyk*yc(j)+tzk*zc(j))/(bk*b(j))
5825 cc = acos(min(1.0d0,max(-1.0d0,cc)))
5826 td = therk + ther(j)
5828 ! check to see if circles enclose separate regions
5830 if (cc .ge. td) goto 60
5832 ! check for circle J completely inside circle K
5834 if (cc+ther(j) .lt. therk) goto 40
5836 ! check for circles that are essentially parallel
5838 if (cc .gt. delta) goto 50
5843 ! check to see if sphere of interest is completely buried
5846 if (pix2-cc .le. td) goto 170
5852 ! find T value of circle intersections
5855 if (omit(k)) goto 110
5870 ! rotation matrix elements
5882 if (.not. omit(j)) then
5887 ! rotate spheres so K vector colinear with z-axis
5889 uxj = txj*axx + tyj*axy - tzj*axz
5890 uyj = tyj*ayy - txj*ayx
5891 uzj = txj*azx + tyj*azy + tzj*azz
5892 cosine = min(1.0d0,max(-1.0d0,uzj/b(j)))
5893 if (acos(cosine) .lt. therk+ther(j)) then
5894 dsqj = uxj*uxj + uyj*uyj
5899 tr2 = risqk*dsqj - tb*tb
5905 ! get T values of intersection for K circle
5908 tb = min(1.0d0,max(-1.0d0,tb))
5910 if (tyb-txr .lt. 0.0d0) tk1 = pix2 - tk1
5912 tb = min(1.0d0,max(-1.0d0,tb))
5914 if (tyb+txr .lt. 0.0d0) tk2 = pix2 - tk2
5915 thec = (rrsq*uzj-gk*bg(j)) / (rik*ri(j)*b(j))
5916 if (abs(thec) .lt. 1.0d0) then
5918 else if (thec .ge. 1.0d0) then
5920 else if (thec .le. -1.0d0) then
5924 ! see if "tk1" is entry or exit point; check t=0 point;
5925 ! "ti" is exit point, "tf" is entry point
5927 cosine = min(1.0d0,max(-1.0d0, &
5928 (uzj*gk-uxj*rik)/(b(j)*rr)))
5929 if ((acos(cosine)-ther(j))*(tk2-tk1) .le. 0.0d0) then
5937 if (narc .ge. maxarc) then
5939 70 format (/,' SURFATOM -- Increase the Value',&
5943 if (tf .le. ti) then
5964 ! special case; K circle without intersections
5966 if (narc .le. 0) goto 90
5968 ! general case; sum up arclength and set connectivity code
5970 call sort2 (narc,arci,key)
5975 if (narc .gt. 1) then
5978 if (t .lt. arci(j)) then
5979 arcsum = arcsum + arci(j) - t
5980 exang = exang + ex(ni)
5982 if (jb .ge. maxarc) then
5984 80 format (/,' SURFATOM -- Increase the Value',&
5989 kent(jb) = maxarc*i + k
5991 kout(jb) = maxarc*k + i
6000 arcsum = arcsum + pix2 - t
6002 exang = exang + ex(ni)
6005 kent(jb) = maxarc*i + k
6007 kout(jb) = maxarc*k + i
6014 arclen = arclen + gr(k)*arcsum
6017 if (arclen .eq. 0.0d0) goto 170
6018 if (jb .eq. 0) goto 150
6020 ! find number of independent boundaries and check connectivity
6024 if (kout(k) .ne. 0) then
6031 if (m .eq. kent(ii)) then
6034 if (j .eq. jb) goto 150
6046 ! attempt to fix connectivity error by moving atom slightly
6050 140 format (/,' SURFATOM -- Connectivity Error at Atom',i6)
6059 ! compute the exposed surface area for the sphere of interest
6062 area = ib*pix2 + exang + arclen
6063 area = mod(area,4.0d0*pi) * rrsq
6065 ! attempt to fix negative area by moving atom slightly
6067 if (area .lt. 0.0d0) then
6070 160 format (/,' SURFATOM -- Negative Area at Atom',i6)
6081 end subroutine surfatom
6082 !----------------------------------------------------------------
6083 !----------------------------------------------------------------
6084 subroutine alloc_MD_arrays
6085 !EL Allocation of arrays used by MD module
6087 integer :: nres2,nres6
6090 !----------------------
6094 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
6095 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
6096 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
6097 allocate(fricvec(nres2,nres2))
6098 allocate(pfric_mat(nres2,nres2),vfric_mat(nres2,nres2))
6099 allocate(afric_mat(nres2,nres2),prand_mat(nres2,nres2))
6100 allocate(vrand_mat1(nres2,nres2),vrand_mat2(nres2,nres2)) !(MAXRES2,MAXRES2)
6101 allocate(pfric0_mat(nres2,nres2,0:maxflag_stoch))
6102 allocate(afric0_mat(nres2,nres2,0:maxflag_stoch))
6103 allocate(vfric0_mat(nres2,nres2,0:maxflag_stoch))
6104 allocate(prand0_mat(nres2,nres2,0:maxflag_stoch))
6105 allocate(vrand0_mat1(nres2,nres2,0:maxflag_stoch))
6106 allocate(vrand0_mat2(nres2,nres2,0:maxflag_stoch)) !(MAXRES2,MAXRES2,0:maxflag_stoch)
6107 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
6109 allocate(mt1(nres2,nres2),mt2(nres2,nres2),mt3(nres2,nres2)) !(maxres2,maxres2)
6110 !----------------------
6112 ! commom.langevin.lang0
6114 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
6115 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
6116 allocate(fricvec(nres2,nres2)) !(MAXRES2,MAXRES2)
6117 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
6118 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
6121 !el if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2))
6122 !----------------------
6123 ! commom.hairpin in CSA module
6124 !----------------------
6125 ! common.mce in MCM_MD module
6126 !----------------------
6128 ! common /mdgrad/ in module.energy
6129 ! common /back_constr/ in module.energy
6130 ! common /qmeas/ in module.energy
6133 allocate(potEcomp(0:n_ene+4)) !(0:n_ene+4)
6135 allocate(d_t(3,0:nres2),d_a(3,0:nres2),d_t_old(3,0:nres2)) !(3,0:MAXRES2)
6136 allocate(d_a_work(nres6)) !(6*MAXRES)
6138 allocate(DM(nres2),DU1(nres2),DU2(nres2))
6139 allocate(DMorig(nres2),DU1orig(nres2),DU2orig(nres2))
6141 allocate(Gmat(nres2,nres2),A(nres2,nres2))
6142 if(.not.allocated(Ginv)) allocate(Ginv(nres2,nres2)) !in control: ergastulum
6143 allocate(Gsqrp(nres2,nres2),Gsqrm(nres2,nres2),Gvec(nres2,nres2)) !(maxres2,maxres2)
6145 allocate(Geigen(nres2)) !(maxres2)
6146 if(.not.allocated(vtot)) allocate(vtot(nres2)) !(maxres2)
6147 ! common /inertia/ in io_conf: parmread
6148 ! real(kind=8),dimension(:),allocatable :: ISC,msc !(ntyp+1)
6149 ! common /langevin/in io read_MDpar
6150 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
6151 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
6152 ! in io_conf: parmread
6153 ! real(kind=8),dimension(:),allocatable :: restok !(ntyp+1)
6154 ! common /mdpmpi/ in control: ergastulum
6155 if(.not.allocated(ng_start)) allocate(ng_start(0:nfgtasks-1))
6156 if(.not.allocated(ng_counts)) allocate(ng_counts(0:nfgtasks-1))
6157 if(.not.allocated(nginv_counts)) allocate(nginv_counts(0:nfgtasks-1)) !(0:MaxProcs-1)
6158 if(.not.allocated(nginv_start)) allocate(nginv_start(0:nfgtasks)) !(0:MaxProcs)
6159 !----------------------
6160 ! common.muca in read_muca
6161 ! common /double_muca/
6162 ! real(kind=8) :: elow,ehigh,factor,hbin,factor_min
6163 ! real(kind=8),dimension(:),allocatable :: emuca,nemuca,&
6164 ! nemuca2,hist !(4*maxres)
6165 ! common /integer_muca/
6166 ! integer :: nmuca,imtime,muca_smooth
6168 ! real(kind=8),dimension(:),allocatable :: elowi,ehighi !(maxprocs)
6169 !----------------------
6171 ! common /mdgrad/ in module.energy
6172 ! common /back_constr/ in module.energy
6173 ! common /qmeas/ in module.energy
6177 allocate(d_t_work(nres6),d_t_work_new(nres6),d_af_work(nres6))
6178 allocate(d_as_work(nres6),kinetic_force(nres6)) !(MAXRES6)
6179 allocate(d_t_new(3,0:nres2),d_a_old(3,0:nres2),d_a_short(3,0:nres2)) !,d_a !(3,0:MAXRES2)
6180 allocate(stdforcp(nres),stdforcsc(nres)) !(MAXRES)
6181 !----------------------
6183 allocate(D_ban(nres6)) !(MAXRES6) maxres6=6*maxres
6184 ! common /stochcalc/ stochforcvec
6185 allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
6186 !----------------------
6188 end subroutine alloc_MD_arrays
6189 !-----------------------------------------------------------------------------
6190 !-----------------------------------------------------------------------------