2 !-----------------------------------------------------------------------------
15 !-----------------------------------------------------------------------------
17 ! common /mdgrad/ in module.energy
18 ! common /back_constr/ in module.energy
19 ! common /qmeas/ in module.energy
23 real(kind=8),dimension(:),allocatable :: d_t_work,&
24 d_t_work_new,d_af_work,d_as_work,kinetic_force !(MAXRES6)
25 real(kind=8),dimension(:,:),allocatable :: d_t_new,&
26 d_a_old,d_a_short!,d_a !(3,0:MAXRES2)
27 ! real(kind=8),dimension(:),allocatable :: d_a_work !(6*MAXRES)
28 ! real(kind=8),dimension(:,:),allocatable :: Gmat,Ginv,A,&
29 ! Gsqrp,Gsqrm,Gvec !(maxres2,maxres2)
30 ! real(kind=8),dimension(:),allocatable :: Geigen !(maxres2)
31 ! integer :: dimen,dimen1,dimen3
32 ! integer :: lang,count_reset_moment,count_reset_vel
33 ! logical :: reset_moment,reset_vel,rattle,RESPA
36 ! real(kind=8) :: rwat,etawat,stdfp,cPoise
37 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
38 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
39 real(kind=8),dimension(:),allocatable :: stdforcp,stdforcsc !(MAXRES)
40 !-----------------------------------------------------------------------------
44 ! ###################################################
45 ! ## COPYRIGHT (C) 1992 by Jay William Ponder ##
46 ! ## All Rights Reserved ##
47 ! ###################################################
49 ! #############################################################
51 ! ## sizes.i -- parameter values to set array dimensions ##
53 ! #############################################################
56 ! "sizes.i" sets values for critical array dimensions used
57 ! throughout the software; these parameters will fix the size
58 ! of the largest systems that can be handled; values too large
59 ! for the computer's memory and/or swap space to accomodate
60 ! will result in poor performance or outright failure
62 ! parameter: maximum allowed number of:
64 ! maxatm atoms in the molecular system
65 ! maxval atoms directly bonded to an atom
66 ! maxgrp ! user-defined groups of atoms
67 ! maxtyp force field atom type definitions
68 ! maxclass force field atom class definitions
69 ! maxkey lines in the keyword file
70 ! maxrot bonds for torsional rotation
71 ! maxvar optimization variables (vector storage)
72 ! maxopt optimization variables (matrix storage)
73 ! maxhess off-diagonal Hessian elements
74 ! maxlight sites for method of lights neighbors
75 ! maxvib vibrational frequencies
76 ! maxgeo distance geometry points
77 ! maxcell unit cells in replicated crystal
78 ! maxring 3-, 4-, or 5-membered rings
79 ! maxfix geometric restraints
80 ! maxbio biopolymer atom definitions
81 ! maxres residues in the macromolecule
82 ! maxamino amino acid residue types
83 ! maxnuc nucleic acid residue types
84 ! maxbnd covalent bonds in molecular system
85 ! maxang bond angles in molecular system
86 ! maxtors torsional angles in molecular system
87 ! maxpi atoms in conjugated pisystem
88 ! maxpib covalent bonds involving pisystem
89 ! maxpit torsional angles involving pisystem
92 !el integer maxatm,maxval,maxgrp
93 !el integer maxtyp,maxclass,maxkey
94 !el integer maxrot,maxopt
95 !el integer maxhess,maxlight,maxvib
96 !el integer maxgeo,maxcell,maxring
97 !el integer maxfix,maxbio
98 !el integer maxamino,maxnuc,maxbnd
99 !el integer maxang,maxtors,maxpi
100 !el integer maxpib,maxpit
101 ! integer :: maxatm !=2*nres !maxres2 maxres2=2*maxres
102 ! integer,parameter :: maxval=8
103 ! integer,parameter :: maxgrp=1000
104 ! integer,parameter :: maxtyp=3000
105 ! integer,parameter :: maxclass=500
106 ! integer,parameter :: maxkey=10000
107 ! integer,parameter :: maxrot=1000
108 ! integer,parameter :: maxopt=1000
109 ! integer,parameter :: maxhess=1000000
110 ! integer :: maxlight !=8*maxatm
111 ! integer,parameter :: maxvib=1000
112 ! integer,parameter :: maxgeo=1000
113 ! integer,parameter :: maxcell=10000
114 ! integer,parameter :: maxring=10000
115 ! integer,parameter :: maxfix=10000
116 ! integer,parameter :: maxbio=10000
117 ! integer,parameter :: maxamino=31
118 ! integer,parameter :: maxnuc=12
119 ! integer :: maxbnd !=2*maxatm
120 ! integer :: maxang !=3*maxatm
121 ! integer :: maxtors !=4*maxatm
122 ! integer,parameter :: maxpi=100
123 ! integer,parameter :: maxpib=2*maxpi
124 ! integer,parameter :: maxpit=4*maxpi
125 !-----------------------------------------------------------------------------
126 ! Maximum number of seed
127 ! integer,parameter :: max_seed=1
128 !-----------------------------------------------------------------------------
129 real(kind=8),dimension(:),allocatable :: stochforcvec !(MAXRES6) maxres6=6*maxres
130 ! common /stochcalc/ stochforcvec
131 !-----------------------------------------------------------------------------
132 ! common /przechowalnia/ subroutines: rattle1,rattle2,rattle_brown
133 real(kind=8),dimension(:,:),allocatable :: GGinv !(2*nres,2*nres) maxres2=2*maxres
134 real(kind=8),dimension(:,:,:),allocatable :: gdc !(3,2*nres,2*nres) maxres2=2*maxres
135 real(kind=8),dimension(:,:),allocatable :: Cmat !(2*nres,2*nres) maxres2=2*maxres
136 !-----------------------------------------------------------------------------
137 ! common /syfek/ subroutines: friction_force,setup_fricmat
138 !el real(kind=8),dimension(:),allocatable :: gamvec !(MAXRES6) or (MAXRES2)
139 !-----------------------------------------------------------------------------
140 ! common /przechowalnia/ subroutines: friction_force,setup_fricmat
141 real(kind=8),dimension(:,:),allocatable :: ginvfric !(2*nres,2*nres) !maxres2=2*maxres
142 !-----------------------------------------------------------------------------
143 ! common /przechowalnia/ subroutine: setup_fricmat
144 real(kind=8),dimension(:,:),allocatable :: fcopy !(2*nres,2*nres)
145 !-----------------------------------------------------------------------------
148 !-----------------------------------------------------------------------------
150 !-----------------------------------------------------------------------------
152 !-----------------------------------------------------------------------------
153 subroutine brown_step(itime)
154 !------------------------------------------------
155 ! Perform a single Euler integration step of Brownian dynamics
156 !------------------------------------------------
157 ! implicit real*8 (a-h,o-z)
159 use control, only: tcpu
162 ! use io_conf, only:cartprint
163 ! include 'DIMENSIONS'
167 ! include 'COMMON.CONTROL'
168 ! include 'COMMON.VAR'
169 ! include 'COMMON.MD'
171 ! include 'COMMON.LANGEVIN'
173 ! include 'COMMON.LANGEVIN.lang0'
175 ! include 'COMMON.CHAIN'
176 ! include 'COMMON.DERIV'
177 ! include 'COMMON.GEO'
178 ! include 'COMMON.LOCAL'
179 ! include 'COMMON.INTERACT'
180 ! include 'COMMON.IOUNITS'
181 ! include 'COMMON.NAMES'
182 ! include 'COMMON.TIME1'
183 real(kind=8),dimension(6*nres) :: zapas !(MAXRES6) maxres6=6*maxres
184 integer :: rstcount !ilen,
186 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
187 real(kind=8),dimension(6*nres,2*nres) :: Bmat,GBmat,Tmat !(MAXRES6,MAXRES2) (maxres2=2*maxres,maxres6=6*maxres)
188 real(kind=8),dimension(2*nres,2*nres) :: Cmat_,Cinv !(maxres2,maxres2) maxres2=2*maxres
189 real(kind=8),dimension(6*nres,6*nres) :: Pmat !(maxres6,maxres6) maxres6=6*maxres
190 ! real(kind=8),dimension(:,:),allocatable :: Bmat,GBmat,Tmat !(MAXRES6,MAXRES2) (maxres2=2*maxres,maxres6=6*maxres)
191 ! real(kind=8),dimension(:,:),allocatable :: Cmat_,Cinv !(maxres2,maxres2) maxres2=2*maxres
192 ! real(kind=8),dimension(:,:),allocatable :: Pmat !(maxres6,maxres6) maxres6=6*maxres
193 real(kind=8),dimension(6*nres) :: Td !(maxres6) maxres6=6*maxres
194 real(kind=8),dimension(2*nres) :: ppvec !(maxres2) maxres2=2*maxres
195 !el common /stochcalc/ stochforcvec
196 !el real(kind=8),dimension(3) :: cm !el
197 !el common /gucio/ cm
199 logical :: lprn = .false.,lprn1 = .false.
200 integer :: maxiter = 5
201 real(kind=8) :: difftol = 1.0d-5
202 real(kind=8) :: xx,diffmax,blen2,diffbond,tt0
203 integer :: i,j,nbond,k,ind,ind1,iter
204 integer :: nres2,nres6
208 ! if (.not.allocated(Bmat)) allocate(Bmat(nres6,nres2))
209 ! if (.not.allocated(GBmat)) allocate (GBmat(nres6,nres2))
210 ! if (.not.allocated(Tmat)) allocate (Tmat(nres6,nres2))
211 ! if (.not.allocated(Cmat_)) allocate(Cmat_(nres2,nres2))
212 ! if (.not.allocated(Cinv)) allocate (Cinv(nres2,nres2))
213 ! if (.not.allocated(Pmat)) allocate(Pmat(6*nres,6*nres))
215 if (.not.allocated(stochforcvec)) allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
219 if (itype(i,1).ne.10) nbond=nbond+1
223 write (iout,*) "Generalized inverse of fricmat"
224 call matout(dimen,dimen,nres6,nres6,fricmat)
236 Bmat(ind+j,ind1)=dC_norm(j,i)
241 if (itype(i,1).ne.10) then
244 Bmat(ind+j,ind1)=dC_norm(j,i+nres)
250 write (iout,*) "Matrix Bmat"
251 call MATOUT(nbond,dimen,nres6,nres6,Bmat)
257 GBmat(i,j)=GBmat(i,j)+fricmat(i,k)*Bmat(k,j)
262 write (iout,*) "Matrix GBmat"
263 call MATOUT(nbond,dimen,nres6,nres2,Gbmat)
269 Cmat_(i,j)=Cmat_(i,j)+Bmat(k,i)*GBmat(k,j)
274 write (iout,*) "Matrix Cmat"
275 call MATOUT(nbond,nbond,nres2,nres2,Cmat_)
277 call matinvert(nbond,nres2,Cmat_,Cinv,osob)
279 write (iout,*) "Matrix Cinv"
280 call MATOUT(nbond,nbond,nres2,nres2,Cinv)
286 Tmat(i,j)=Tmat(i,j)+GBmat(i,k)*Cinv(k,j)
291 write (iout,*) "Matrix Tmat"
292 call MATOUT(nbond,dimen,nres6,nres2,Tmat)
302 Pmat(i,j)=Pmat(i,j)-Tmat(i,k)*Bmat(j,k)
307 write (iout,*) "Matrix Pmat"
308 call MATOUT(dimen,dimen,nres6,nres6,Pmat)
315 Td(i)=Td(i)+vbl*Tmat(i,ind)
318 if (itype(k,1).ne.10) then
320 Td(i)=Td(i)+vbldsc0(1,itype(k,1))*Tmat(i,ind)
325 write (iout,*) "Vector Td"
327 write (iout,'(i5,f10.5)') i,Td(i)
330 call stochastic_force(stochforcvec)
332 write (iout,*) "stochforcvec"
334 write (iout,*) i,stochforcvec(i)
338 zapas(j)=-gcart(j,0)+stochforcvec(j)
340 dC_work(j)=dC_old(j,0)
346 zapas(ind)=-gcart(j,i)+stochforcvec(ind)
347 dC_work(ind)=dC_old(j,i)
351 if (itype(i,1).ne.10) then
354 zapas(ind)=-gxcart(j,i)+stochforcvec(ind)
355 dC_work(ind)=dC_old(j,i+nres)
361 write (iout,*) "Initial d_t_work"
363 write (iout,*) i,d_t_work(i)
370 d_t_work(i)=d_t_work(i)+fricmat(i,j)*zapas(j)
377 zapas(i)=zapas(i)+Pmat(i,j)*(dC_work(j)+d_t_work(j)*d_time)
381 write (iout,*) "Final d_t_work and zapas"
383 write (iout,*) i,d_t_work(i),zapas(i)
397 dc_work(ind+j)=dc(j,i)
403 d_t(j,i+nres)=d_t_work(ind+j)
404 dc(j,i+nres)=zapas(ind+j)
405 dc_work(ind+j)=dc(j,i+nres)
411 write (iout,*) "Before correction for rotational lengthening"
412 write (iout,*) "New coordinates",&
413 " and differences between actual and standard bond lengths"
418 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
422 if (itype(i,1).ne.10) then
424 xx=vbld(i+nres)-vbldsc0(1,itype(i,1))
425 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
426 i,(dC(j,i+nres),j=1,3),xx
430 ! Second correction (rotational lengthening)
436 blen2 = scalar(dc(1,i),dc(1,i))
437 ppvec(ind)=2*vbl**2-blen2
438 diffbond=dabs(vbl-dsqrt(blen2))
439 if (diffbond.gt.diffmax) diffmax=diffbond
440 if (ppvec(ind).gt.0.0d0) then
441 ppvec(ind)=dsqrt(ppvec(ind))
446 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
450 if (itype(i,1).ne.10) then
452 blen2 = scalar(dc(1,i+nres),dc(1,i+nres))
453 ppvec(ind)=2*vbldsc0(1,itype(i,1))**2-blen2
454 diffbond=dabs(vbldsc0(1,itype(i,1))-dsqrt(blen2))
455 if (diffbond.gt.diffmax) diffmax=diffbond
456 if (ppvec(ind).gt.0.0d0) then
457 ppvec(ind)=dsqrt(ppvec(ind))
462 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
466 if (lprn) write (iout,*) "iter",iter," diffmax",diffmax
467 if (diffmax.lt.difftol) goto 10
471 Td(i)=Td(i)+ppvec(j)*Tmat(i,j)
477 zapas(i)=zapas(i)+Pmat(i,j)*dc_work(j)
488 dc_work(ind+j)=zapas(ind+j)
493 if (itype(i,1).ne.10) then
495 dc(j,i+nres)=zapas(ind+j)
496 dc_work(ind+j)=zapas(ind+j)
501 ! Building the chain from the newly calculated coordinates
504 if (large.and. mod(itime,ntwe).eq.0) then
505 write (iout,*) "Cartesian and internal coordinates: step 1"
508 write (iout,'(a)') "Potential forces"
510 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(-gcart(j,i),j=1,3),&
513 write (iout,'(a)') "Stochastic forces"
515 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(stochforc(j,i),j=1,3),&
516 (stochforc(j,i+nres),j=1,3)
518 write (iout,'(a)') "Velocities"
520 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
521 (d_t(j,i+nres),j=1,3)
526 write (iout,*) "After correction for rotational lengthening"
527 write (iout,*) "New coordinates",&
528 " and differences between actual and standard bond lengths"
533 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
537 if (itype(i,1).ne.10) then
539 xx=vbld(i+nres)-vbldsc0(1,itype(i,1))
540 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
541 i,(dC(j,i+nres),j=1,3),xx
546 ! write (iout,*) "Too many attempts at correcting the bonds"
554 ! Calculate energy and forces
556 call etotal(potEcomp)
557 potE=potEcomp(0)-potEcomp(20)
561 ! Calculate the kinetic and total energy and the kinetic temperature
564 t_enegrad=t_enegrad+MPI_Wtime()-tt0
566 t_enegrad=t_enegrad+tcpu()-tt0
569 kinetic_T=2.0d0/(dimen*Rb)*EK
571 end subroutine brown_step
572 !-----------------------------------------------------------------------------
574 !-----------------------------------------------------------------------------
575 subroutine gauss(RO,AP,MT,M,N,*)
577 ! CALCULATES (RO**(-1))*AP BY GAUSS ELIMINATION
578 ! RO IS A SQUARE MATRIX
579 ! THE CALCULATED PRODUCT IS STORED IN AP
580 ! ABNORMAL EXIT IF RO IS SINGULAR
582 integer :: MT, M, N, M1,I,J,IM,&
584 real(kind=8) :: RO(MT,M),AP(MT,N),X,RM,PR,Y
590 if(dabs(X).le.1.0D-13) return 1
602 if(DABS(RO(J,I)).LE.RM) goto 2
616 if(dabs(X).le.1.0E-13) return 1
625 8 AP(J,K)=AP(J,K)-Y*AP(I,K)
627 9 RO(J,K)=RO(J,K)-Y*RO(I,K)
631 if(dabs(X).le.1.0E-13) return 1
641 15 X=X-AP(K,J)*RO(MI,K)
646 !-----------------------------------------------------------------------------
648 !-----------------------------------------------------------------------------
649 subroutine kinetic(KE_total)
650 !----------------------------------------------------------------
651 ! This subroutine calculates the total kinetic energy of the chain
652 !-----------------------------------------------------------------
654 ! implicit real*8 (a-h,o-z)
655 ! include 'DIMENSIONS'
656 ! include 'COMMON.VAR'
657 ! include 'COMMON.CHAIN'
658 ! include 'COMMON.DERIV'
659 ! include 'COMMON.GEO'
660 ! include 'COMMON.LOCAL'
661 ! include 'COMMON.INTERACT'
662 ! include 'COMMON.MD'
663 ! include 'COMMON.IOUNITS'
664 real(kind=8) :: KE_total,mscab
666 integer :: i,j,k,iti,mnum
667 real(kind=8) :: KEt_p,KEt_sc,KEr_p,KEr_sc,incr(3),&
670 write (iout,*) "Velocities, kietic"
672 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
673 (d_t(j,i+nres),j=1,3)
678 ! write (iout,*) "ISC",(isc(itype(i,1)),i=1,nres)
679 ! The translational part for peptide virtual bonds
685 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
686 ! write (iout,*) "Kinetic trp:",i,(incr(j),j=1,3)
688 v(j)=incr(j)+0.5d0*d_t(j,i)
690 vtot(i)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
691 KEt_p=KEt_p+mp(mnum)*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))
693 incr(j)=incr(j)+d_t(j,i)
696 ! write(iout,*) 'KEt_p', KEt_p
697 ! The translational part for the side chain virtual bond
698 ! Only now we can initialize incr with zeros. It must be equal
699 ! to the velocities of the first Calpha.
705 iti=iabs(itype(i,mnum))
711 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
712 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
713 .or.(mnum.eq.5)) then
719 v(j)=incr(j)+d_t(j,nres+i)
722 ! write (iout,*) "Kinetic trsc:",i,(incr(j),j=1,3)
723 ! write (iout,*) "i",i," msc",msc(iti)," v",(v(j),j=1,3)
724 KEt_sc=KEt_sc+mscab*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))
725 vtot(i+nres)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
727 incr(j)=incr(j)+d_t(j,i)
731 ! write(iout,*) 'KEt_sc', KEt_sc
732 ! The part due to stretching and rotation of the peptide groups
736 ! write (iout,*) "i",i
737 ! write (iout,*) "i",i," mag1",mag1," mag2",mag2
741 ! write (iout,*) "Kinetic rotp:",i,(incr(j),j=1,3)
742 KEr_p=KEr_p+Ip(mnum)*(incr(1)*incr(1)+incr(2)*incr(2) &
746 ! write(iout,*) 'KEr_p', KEr_p
747 ! The rotational part of the side chain virtual bond
751 iti=iabs(itype(i,mnum))
752 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
753 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
754 .and.(mnum.ne.5)) then
756 incr(j)=d_t(j,nres+i)
758 ! write (iout,*) "Kinetic rotsc:",i,(incr(j),j=1,3)
759 KEr_sc=KEr_sc+Isc(iti,mnum)*(incr(1)*incr(1)+incr(2)*incr(2)+ &
763 ! The total kinetic energy
765 ! write(iout,*) 'KEr_sc', KEr_sc
766 KE_total=0.5d0*(KEt_p+KEt_sc+0.25d0*KEr_p+KEr_sc)
767 ! write (iout,*) "KE_total",KE_total
769 end subroutine kinetic
770 !-----------------------------------------------------------------------------
772 !-----------------------------------------------------------------------------
774 !------------------------------------------------
775 ! The driver for molecular dynamics subroutines
776 !------------------------------------------------
779 use control, only:tcpu,ovrtim
780 ! use io_comm, only:ilen
782 use compare, only:secondary2,hairpin
783 use io, only:cartout,statout
784 ! implicit real*8 (a-h,o-z)
785 ! include 'DIMENSIONS'
788 integer :: IERROR,ERRCODE
790 ! include 'COMMON.SETUP'
791 ! include 'COMMON.CONTROL'
792 ! include 'COMMON.VAR'
793 ! include 'COMMON.MD'
795 ! include 'COMMON.LANGEVIN'
797 ! include 'COMMON.LANGEVIN.lang0'
799 ! include 'COMMON.CHAIN'
800 ! include 'COMMON.DERIV'
801 ! include 'COMMON.GEO'
802 ! include 'COMMON.LOCAL'
803 ! include 'COMMON.INTERACT'
804 ! include 'COMMON.IOUNITS'
805 ! include 'COMMON.NAMES'
806 ! include 'COMMON.TIME1'
807 ! include 'COMMON.HAIRPIN'
808 real(kind=8),dimension(3) :: L,vcm
810 real(kind=8),dimension(6*nres) :: v_work,v_transf !(maxres6) maxres6=6*maxres
812 integer :: rstcount !ilen,
814 character(len=50) :: tytul
815 !el common /gucio/ cm
816 integer :: itime,i,j,nharp
817 integer,dimension(4,nres/3) :: iharp !(4,nres/3)(4,maxres/3)
819 real(kind=8) :: tt0,scalfac
825 print *,"MY tmpdir",tmpdir,ilen(tmpdir)
826 if (ilen(tmpdir).gt.0) &
827 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_" &
828 //liczba(:ilen(liczba))//'.rst')
830 if (ilen(tmpdir).gt.0) &
831 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_"//'.rst')
838 write (iout,'(20(1h=),a20,20(1h=))') "MD calculation started"
844 print *,"just befor setup matix",nres
845 ! Determine the inverse of the inertia matrix.
846 call setup_MD_matrices
848 print *,"AFTER SETUP MATRICES"
850 print *,"AFTER INIT MD"
853 t_MDsetup = MPI_Wtime()-tt0
855 t_MDsetup = tcpu()-tt0
858 ! Entering the MD loop
864 if (lang.eq.2 .or. lang.eq.3) then
868 call sd_verlet_p_setup
870 call sd_verlet_ciccotti_setup
874 pfric0_mat(i,j,0)=pfric_mat(i,j)
875 afric0_mat(i,j,0)=afric_mat(i,j)
876 vfric0_mat(i,j,0)=vfric_mat(i,j)
877 prand0_mat(i,j,0)=prand_mat(i,j)
878 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
879 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
884 flag_stoch(i)=.false.
888 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
890 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
894 else if (lang.eq.1 .or. lang.eq.4) then
895 print *,"before setup_fricmat"
897 print *,"after setup_fricmat"
900 t_langsetup=MPI_Wtime()-tt0
903 t_langsetup=tcpu()-tt0
906 do itime=1,n_timestep
908 if (large.and. mod(itime,ntwe).eq.0) &
909 write (iout,*) "itime",itime
911 if (lang.gt.0 .and. surfarea .and. &
912 mod(itime,reset_fricmat).eq.0) then
913 if (lang.eq.2 .or. lang.eq.3) then
917 call sd_verlet_p_setup
919 call sd_verlet_ciccotti_setup
923 pfric0_mat(i,j,0)=pfric_mat(i,j)
924 afric0_mat(i,j,0)=afric_mat(i,j)
925 vfric0_mat(i,j,0)=vfric_mat(i,j)
926 prand0_mat(i,j,0)=prand_mat(i,j)
927 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
928 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
933 flag_stoch(i)=.false.
936 else if (lang.eq.1 .or. lang.eq.4) then
939 write (iout,'(a,i10)') &
940 "Friction matrix reset based on surface area, itime",itime
942 if (reset_vel .and. tbf .and. lang.eq.0 &
943 .and. mod(itime,count_reset_vel).eq.0) then
945 write(iout,'(a,f20.2)') &
946 "Velocities reset to random values, time",totT
949 d_t_old(j,i)=d_t(j,i)
953 if (reset_moment .and. mod(itime,count_reset_moment).eq.0) then
957 d_t(j,0)=d_t(j,0)-vcm(j)
960 kinetic_T=2.0d0/(dimen3*Rb)*EK
961 scalfac=dsqrt(T_bath/kinetic_T)
962 write(iout,'(a,f20.2)') "Momenta zeroed out, time",totT
965 d_t_old(j,i)=scalfac*d_t(j,i)
971 ! Time-reversible RESPA algorithm
972 ! (Tuckerman et al., J. Chem. Phys., 97, 1990, 1992)
973 call RESPA_step(itime)
975 ! Variable time step algorithm.
976 call velverlet_step(itime)
980 call brown_step(itime)
982 print *,"Brown dynamics not here!"
984 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
990 if (mod(itime,ntwe).eq.0) then
993 ! call check_ecartint
1003 v_work(ind)=d_t(j,i)
1008 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1.and.mnum.ne.5) then
1011 v_work(ind)=d_t(j,i+nres)
1016 write (66,'(80f10.5)') &
1017 ((d_t(j,i),j=1,3),i=0,nres-1),((d_t(j,i+nres),j=1,3),i=1,nres)
1021 v_transf(i)=v_transf(i)+gvec(j,i)*v_work(j)
1023 v_transf(i)= v_transf(i)*dsqrt(geigen(i))
1025 write (67,'(80f10.5)') (v_transf(i),i=1,ind)
1028 if (mod(itime,ntwx).eq.0) then
1030 write (tytul,'("time",f8.2)') totT
1032 call hairpin(.true.,nharp,iharp)
1033 call secondary2(.true.)
1034 call pdbout(potE,tytul,ipdb)
1039 if (rstcount.eq.1000.or.itime.eq.n_timestep) then
1040 open(irest2,file=rest2name,status='unknown')
1041 write(irest2,*) totT,EK,potE,totE,t_bath
1043 ! AL 4/17/17: Now writing d_t(0,:) too
1045 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
1047 ! AL 4/17/17: Now writing d_c(0,:) too
1049 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
1057 t_MD=MPI_Wtime()-tt0
1061 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))') &
1063 'MD calculations setup:',t_MDsetup,&
1064 'Energy & gradient evaluation:',t_enegrad,&
1065 'Stochastic MD setup:',t_langsetup,&
1066 'Stochastic MD step setup:',t_sdsetup,&
1068 write (iout,'(/28(1h=),a25,27(1h=))') &
1069 ' End of MD calculation '
1071 write (iout,*) "time for etotal",t_etotal," elong",t_elong,&
1073 write (iout,*) "time_fric",time_fric," time_stoch",time_stoch,&
1074 " time_fricmatmult",time_fricmatmult," time_fsample ",&
1079 !-----------------------------------------------------------------------------
1080 subroutine velverlet_step(itime)
1081 !-------------------------------------------------------------------------------
1082 ! Perform a single velocity Verlet step; the time step can be rescaled if
1083 ! increments in accelerations exceed the threshold
1084 !-------------------------------------------------------------------------------
1085 ! implicit real*8 (a-h,o-z)
1086 ! include 'DIMENSIONS'
1088 use control, only:tcpu
1092 integer :: ierror,ierrcode
1093 real(kind=8) :: errcode
1095 ! include 'COMMON.SETUP'
1096 ! include 'COMMON.VAR'
1097 ! include 'COMMON.MD'
1099 ! include 'COMMON.LANGEVIN'
1101 ! include 'COMMON.LANGEVIN.lang0'
1103 ! include 'COMMON.CHAIN'
1104 ! include 'COMMON.DERIV'
1105 ! include 'COMMON.GEO'
1106 ! include 'COMMON.LOCAL'
1107 ! include 'COMMON.INTERACT'
1108 ! include 'COMMON.IOUNITS'
1109 ! include 'COMMON.NAMES'
1110 ! include 'COMMON.TIME1'
1111 ! include 'COMMON.MUCA'
1112 real(kind=8),dimension(3) :: vcm,incr
1113 real(kind=8),dimension(3) :: L
1114 integer :: count,rstcount !ilen,
1116 character(len=50) :: tytul
1117 integer :: maxcount_scale = 30
1118 !el common /gucio/ cm
1119 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1120 !el common /stochcalc/ stochforcvec
1121 integer :: itime,icount_scale,itime_scal,i,j,ifac_time
1123 real(kind=8) :: epdrift,tt0,fac_time
1125 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1131 else if (lang.eq.2 .or. lang.eq.3) then
1133 call stochastic_force(stochforcvec)
1136 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1138 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1145 icount_scale=icount_scale+1
1146 ! write(iout,*) "icount_scale",icount_scale,scalel
1147 if (icount_scale.gt.maxcount_scale) then
1149 "ERROR: too many attempts at scaling down the time step. ",&
1150 "amax=",amax,"epdrift=",epdrift,&
1151 "damax=",damax,"edriftmax=",edriftmax,&
1155 call MPI_Abort(MPI_COMM_WORLD,IERROR,IERRCODE)
1159 ! First step of the velocity Verlet algorithm
1164 else if (lang.eq.3) then
1166 call sd_verlet1_ciccotti
1168 else if (lang.eq.1) then
1173 ! Build the chain from the newly calculated coordinates
1174 call chainbuild_cart
1175 if (rattle) call rattle1
1177 if (large.and. mod(itime,ntwe).eq.0) then
1178 write (iout,*) "Cartesian and internal coordinates: step 1"
1183 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
1184 (dc(j,i+nres),j=1,3)
1186 write (iout,*) "Accelerations"
1188 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1189 (d_a(j,i+nres),j=1,3)
1191 write (iout,*) "Velocities, step 1"
1193 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1194 (d_t(j,i+nres),j=1,3)
1203 ! Calculate energy and forces
1205 call etotal(potEcomp)
1206 ! AL 4/17/17: Reduce the steps if NaNs occurred.
1207 if (potEcomp(0).gt.0.99e18 .or. isnan(potEcomp(0)).gt.0) then
1209 ! write (iout,*) "Tu jest problem",potEcomp(0),d_time
1210 call gen_rand_conf(1,*335)
1212 335 write(iout,*) "Failed genrand"
1216 if (large.and. mod(itime,ntwe).eq.0) &
1217 call enerprint(potEcomp)
1220 t_etotal=t_etotal+MPI_Wtime()-tt0
1222 t_etotal=t_etotal+tcpu()-tt0
1225 potE=potEcomp(0)-potEcomp(20)
1227 ! Get the new accelerations
1230 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1232 t_enegrad=t_enegrad+tcpu()-tt0
1234 ! Determine maximum acceleration and scale down the timestep if needed
1236 amax=amax/(itime_scal+1)**2
1237 call predict_edrift(epdrift)
1238 ! write(iout,*) "amax=",amax,damax,epdrift,edriftmax,amax/(itime_scal+1)
1240 ! write (iout,*) "before enter if",scalel,icount_scale
1241 if (amax/(itime_scal+1).gt.damax .or. epdrift.gt.edriftmax) then
1242 ! write(iout,*) "I enter if"
1243 ! Maximum acceleration or maximum predicted energy drift exceeded, rescale the time step
1245 ifac_time=dmax1(dlog(amax/damax),dlog(epdrift/edriftmax)) &
1247 itime_scal=itime_scal+ifac_time
1248 ! fac_time=dmin1(damax/amax,0.5d0)
1249 fac_time=0.5d0**ifac_time
1250 d_time=d_time*fac_time
1251 if (lang.eq.2 .or. lang.eq.3) then
1253 ! write (iout,*) "Calling sd_verlet_setup: 1"
1254 ! Rescale the stochastic forces and recalculate or restore
1255 ! the matrices of tinker integrator
1256 if (itime_scal.gt.maxflag_stoch) then
1257 if (large) write (iout,'(a,i5,a)') &
1258 "Calculate matrices for stochastic step;",&
1259 " itime_scal ",itime_scal
1261 call sd_verlet_p_setup
1263 call sd_verlet_ciccotti_setup
1265 write (iout,'(2a,i3,a,i3,1h.)') &
1266 "Warning: cannot store matrices for stochastic",&
1267 " integration because the index",itime_scal,&
1268 " is greater than",maxflag_stoch
1269 write (iout,'(2a)')"Increase MAXFLAG_STOCH or use direct",&
1270 " integration Langevin algorithm for better efficiency."
1271 else if (flag_stoch(itime_scal)) then
1272 if (large) write (iout,'(a,i5,a,l1)') &
1273 "Restore matrices for stochastic step; itime_scal ",&
1274 itime_scal," flag ",flag_stoch(itime_scal)
1277 pfric_mat(i,j)=pfric0_mat(i,j,itime_scal)
1278 afric_mat(i,j)=afric0_mat(i,j,itime_scal)
1279 vfric_mat(i,j)=vfric0_mat(i,j,itime_scal)
1280 prand_mat(i,j)=prand0_mat(i,j,itime_scal)
1281 vrand_mat1(i,j)=vrand0_mat1(i,j,itime_scal)
1282 vrand_mat2(i,j)=vrand0_mat2(i,j,itime_scal)
1286 if (large) write (iout,'(2a,i5,a,l1)') &
1287 "Calculate & store matrices for stochastic step;",&
1288 " itime_scal ",itime_scal," flag ",flag_stoch(itime_scal)
1290 call sd_verlet_p_setup
1292 call sd_verlet_ciccotti_setup
1294 flag_stoch(ifac_time)=.true.
1297 pfric0_mat(i,j,itime_scal)=pfric_mat(i,j)
1298 afric0_mat(i,j,itime_scal)=afric_mat(i,j)
1299 vfric0_mat(i,j,itime_scal)=vfric_mat(i,j)
1300 prand0_mat(i,j,itime_scal)=prand_mat(i,j)
1301 vrand0_mat1(i,j,itime_scal)=vrand_mat1(i,j)
1302 vrand0_mat2(i,j,itime_scal)=vrand_mat2(i,j)
1306 fac_time=1.0d0/dsqrt(fac_time)
1308 stochforcvec(i)=fac_time*stochforcvec(i)
1311 else if (lang.eq.1) then
1312 ! Rescale the accelerations due to stochastic forces
1313 fac_time=1.0d0/dsqrt(fac_time)
1315 d_as_work(i)=d_as_work(i)*fac_time
1318 if (large) write (iout,'(a,i10,a,f8.6,a,i3,a,i3)') &
1319 "itime",itime," Timestep scaled down to ",&
1320 d_time," ifac_time",ifac_time," itime_scal",itime_scal
1322 ! Second step of the velocity Verlet algorithm
1327 else if (lang.eq.3) then
1329 call sd_verlet2_ciccotti
1331 else if (lang.eq.1) then
1336 if (rattle) call rattle2
1339 if (d_time.ne.d_time0) then
1342 if (lang.eq.2 .or. lang.eq.3) then
1343 if (large) write (iout,'(a)') &
1344 "Restore original matrices for stochastic step"
1345 ! write (iout,*) "Calling sd_verlet_setup: 2"
1346 ! Restore the matrices of tinker integrator if the time step has been restored
1349 pfric_mat(i,j)=pfric0_mat(i,j,0)
1350 afric_mat(i,j)=afric0_mat(i,j,0)
1351 vfric_mat(i,j)=vfric0_mat(i,j,0)
1352 prand_mat(i,j)=prand0_mat(i,j,0)
1353 vrand_mat1(i,j)=vrand0_mat1(i,j,0)
1354 vrand_mat2(i,j)=vrand0_mat2(i,j,0)
1362 ! Calculate the kinetic and the total energy and the kinetic temperature
1366 ! call kinetic1(EK1)
1367 ! write (iout,*) "step",itime," EK",EK," EK1",EK1
1369 ! Couple the system to Berendsen bath if needed
1370 if (tbf .and. lang.eq.0) then
1373 kinetic_T=2.0d0/(dimen3*Rb)*EK
1374 ! Backup the coordinates, velocities, and accelerations
1378 d_t_old(j,i)=d_t(j,i)
1379 d_a_old(j,i)=d_a(j,i)
1383 if (mod(itime,ntwe).eq.0 .and. large) then
1384 write (iout,*) "Velocities, step 2"
1386 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1387 (d_t(j,i+nres),j=1,3)
1392 end subroutine velverlet_step
1393 !-----------------------------------------------------------------------------
1394 subroutine RESPA_step(itime)
1395 !-------------------------------------------------------------------------------
1396 ! Perform a single RESPA step.
1397 !-------------------------------------------------------------------------------
1398 ! implicit real*8 (a-h,o-z)
1399 ! include 'DIMENSIONS'
1403 use control, only:tcpu
1405 ! use io_conf, only:cartprint
1408 integer :: IERROR,ERRCODE
1410 ! include 'COMMON.SETUP'
1411 ! include 'COMMON.CONTROL'
1412 ! include 'COMMON.VAR'
1413 ! include 'COMMON.MD'
1415 ! include 'COMMON.LANGEVIN'
1417 ! include 'COMMON.LANGEVIN.lang0'
1419 ! include 'COMMON.CHAIN'
1420 ! include 'COMMON.DERIV'
1421 ! include 'COMMON.GEO'
1422 ! include 'COMMON.LOCAL'
1423 ! include 'COMMON.INTERACT'
1424 ! include 'COMMON.IOUNITS'
1425 ! include 'COMMON.NAMES'
1426 ! include 'COMMON.TIME1'
1427 real(kind=8),dimension(0:n_ene) :: energia_short,energia_long
1428 real(kind=8),dimension(3) :: L,vcm,incr
1429 real(kind=8),dimension(3,0:2*nres) :: dc_old0,d_t_old0,d_a_old0 !(3,0:maxres2) maxres2=2*maxres
1430 logical :: PRINT_AMTS_MSG = .false.
1431 integer :: count,rstcount !ilen,
1433 character(len=50) :: tytul
1434 integer :: maxcount_scale = 10
1435 !el common /gucio/ cm
1436 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1437 !el common /stochcalc/ stochforcvec
1438 integer :: itime,itt,i,j,itsplit
1440 !el common /cipiszcze/ itt
1442 real(kind=8) :: epdrift,tt0,epdriftmax
1445 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1449 if (large.and. mod(itime,ntwe).eq.0) then
1450 write (iout,*) "***************** RESPA itime",itime
1451 write (iout,*) "Cartesian and internal coordinates: step 0"
1453 call pdbout(0.0d0,"cipiszcze",iout)
1455 write (iout,*) "Accelerations from long-range forces"
1457 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1458 (d_a(j,i+nres),j=1,3)
1460 write (iout,*) "Velocities, step 0"
1462 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1463 (d_t(j,i+nres),j=1,3)
1468 ! Perform the initial RESPA step (increment velocities)
1469 ! write (iout,*) "*********************** RESPA ini"
1472 if (mod(itime,ntwe).eq.0 .and. large) then
1473 write (iout,*) "Velocities, end"
1475 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1476 (d_t(j,i+nres),j=1,3)
1480 ! Compute the short-range forces
1486 ! 7/2/2009 commented out
1488 ! call etotal_short(energia_short)
1491 ! 7/2/2009 Copy accelerations due to short-lange forces from previous MD step
1494 d_a(j,i)=d_a_short(j,i)
1498 if (large.and. mod(itime,ntwe).eq.0) then
1499 write (iout,*) "energia_short",energia_short(0)
1500 write (iout,*) "Accelerations from short-range forces"
1502 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1503 (d_a(j,i+nres),j=1,3)
1508 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1510 t_enegrad=t_enegrad+tcpu()-tt0
1515 d_t_old(j,i)=d_t(j,i)
1516 d_a_old(j,i)=d_a(j,i)
1519 ! 6/30/08 A-MTS: attempt at increasing the split number
1522 dc_old0(j,i)=dc_old(j,i)
1523 d_t_old0(j,i)=d_t_old(j,i)
1524 d_a_old0(j,i)=d_a_old(j,i)
1527 if (ntime_split.gt.ntime_split0) ntime_split=ntime_split/2
1528 if (ntime_split.lt.ntime_split0) ntime_split=ntime_split0
1535 ! write (iout,*) "itime",itime," ntime_split",ntime_split
1536 ! Split the time step
1537 d_time=d_time0/ntime_split
1538 ! Perform the short-range RESPA steps (velocity Verlet increments of
1539 ! positions and velocities using short-range forces)
1540 ! write (iout,*) "*********************** RESPA split"
1541 do itsplit=1,ntime_split
1544 else if (lang.eq.2 .or. lang.eq.3) then
1546 call stochastic_force(stochforcvec)
1549 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1551 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1556 ! First step of the velocity Verlet algorithm
1561 else if (lang.eq.3) then
1563 call sd_verlet1_ciccotti
1565 else if (lang.eq.1) then
1570 ! Build the chain from the newly calculated coordinates
1571 call chainbuild_cart
1572 if (rattle) call rattle1
1574 if (large.and. mod(itime,ntwe).eq.0) then
1575 write (iout,*) "***** ITSPLIT",itsplit
1576 write (iout,*) "Cartesian and internal coordinates: step 1"
1577 call pdbout(0.0d0,"cipiszcze",iout)
1580 write (iout,*) "Velocities, step 1"
1582 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1583 (d_t(j,i+nres),j=1,3)
1592 ! Calculate energy and forces
1594 call etotal_short(energia_short)
1595 ! AL 4/17/17: Exit itime_split loop when energy goes infinite
1596 if (energia_short(0).gt.0.99e20 .or. isnan(energia_short(0)) ) then
1597 if (PRINT_AMTS_MSG) &
1598 write (iout,*) "Infinities/NaNs in energia_short",energia_short(0),"; increasing ntime_split to",ntime_split
1599 ntime_split=ntime_split*2
1600 if (ntime_split.gt.maxtime_split) then
1603 "Cannot rescue the run; aborting job. Retry with a smaller time step"
1605 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1608 "Cannot rescue the run; terminating. Retry with a smaller time step"
1614 if (large.and. mod(itime,ntwe).eq.0) &
1615 call enerprint(energia_short)
1618 t_eshort=t_eshort+MPI_Wtime()-tt0
1620 t_eshort=t_eshort+tcpu()-tt0
1624 ! Get the new accelerations
1626 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
1629 d_a_short(j,i)=d_a(j,i)
1633 if (large.and. mod(itime,ntwe).eq.0) then
1634 write (iout,*)"energia_short",energia_short(0)
1635 write (iout,*) "Accelerations from short-range forces"
1637 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1638 (d_a(j,i+nres),j=1,3)
1643 ! Determine maximum acceleration and scale down the timestep if needed
1645 amax=amax/ntime_split**2
1646 call predict_edrift(epdrift)
1647 if (ntwe.gt.0 .and. large .and. mod(itime,ntwe).eq.0) &
1648 write (iout,*) "amax",amax," damax",damax,&
1649 " epdrift",epdrift," epdriftmax",epdriftmax
1650 ! Exit loop and try with increased split number if the change of
1651 ! acceleration is too big
1652 if (amax.gt.damax .or. epdrift.gt.edriftmax) then
1653 if (ntime_split.lt.maxtime_split) then
1655 ntime_split=ntime_split*2
1656 ! AL 4/17/17: We should exit the itime_split loop when acceleration change is too big
1660 dc_old(j,i)=dc_old0(j,i)
1661 d_t_old(j,i)=d_t_old0(j,i)
1662 d_a_old(j,i)=d_a_old0(j,i)
1665 if (PRINT_AMTS_MSG) then
1666 write (iout,*) "acceleration/energy drift too large",amax,&
1667 epdrift," split increased to ",ntime_split," itime",itime,&
1673 "Uh-hu. Bumpy landscape. Maximum splitting number",&
1675 " already reached!!! Trying to carry on!"
1679 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1681 t_enegrad=t_enegrad+tcpu()-tt0
1683 ! Second step of the velocity Verlet algorithm
1688 else if (lang.eq.3) then
1690 call sd_verlet2_ciccotti
1692 else if (lang.eq.1) then
1697 if (rattle) call rattle2
1698 ! Backup the coordinates, velocities, and accelerations
1702 d_t_old(j,i)=d_t(j,i)
1703 d_a_old(j,i)=d_a(j,i)
1710 ! Restore the time step
1712 ! Compute long-range forces
1719 call etotal_long(energia_long)
1720 if (energia_long(0).gt.0.99e20 .or. isnan(energia_long(0))) then
1723 "Infinitied/NaNs in energia_long, Aborting MPI job."
1725 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1727 write (iout,*) "Infinitied/NaNs in energia_long, terminating."
1731 if (large.and. mod(itime,ntwe).eq.0) &
1732 call enerprint(energia_long)
1735 t_elong=t_elong+MPI_Wtime()-tt0
1737 t_elong=t_elong+tcpu()-tt0
1743 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1745 t_enegrad=t_enegrad+tcpu()-tt0
1747 ! Compute accelerations from long-range forces
1749 if (large.and. mod(itime,ntwe).eq.0) then
1750 write (iout,*) "energia_long",energia_long(0)
1751 write (iout,*) "Cartesian and internal coordinates: step 2"
1753 call pdbout(0.0d0,"cipiszcze",iout)
1755 write (iout,*) "Accelerations from long-range forces"
1757 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1758 (d_a(j,i+nres),j=1,3)
1760 write (iout,*) "Velocities, step 2"
1762 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1763 (d_t(j,i+nres),j=1,3)
1767 ! Compute the final RESPA step (increment velocities)
1768 ! write (iout,*) "*********************** RESPA fin"
1770 ! Compute the complete potential energy
1772 potEcomp(i)=energia_short(i)+energia_long(i)
1774 potE=potEcomp(0)-potEcomp(20)
1775 ! potE=energia_short(0)+energia_long(0)
1778 ! Calculate the kinetic and the total energy and the kinetic temperature
1781 ! Couple the system to Berendsen bath if needed
1782 if (tbf .and. lang.eq.0) then
1785 kinetic_T=2.0d0/(dimen3*Rb)*EK
1786 ! Backup the coordinates, velocities, and accelerations
1788 if (mod(itime,ntwe).eq.0 .and. large) then
1789 write (iout,*) "Velocities, end"
1791 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1792 (d_t(j,i+nres),j=1,3)
1797 end subroutine RESPA_step
1798 !-----------------------------------------------------------------------------
1799 subroutine RESPA_vel
1800 ! First and last RESPA step (incrementing velocities using long-range
1803 ! implicit real*8 (a-h,o-z)
1804 ! include 'DIMENSIONS'
1805 ! include 'COMMON.CONTROL'
1806 ! include 'COMMON.VAR'
1807 ! include 'COMMON.MD'
1808 ! include 'COMMON.CHAIN'
1809 ! include 'COMMON.DERIV'
1810 ! include 'COMMON.GEO'
1811 ! include 'COMMON.LOCAL'
1812 ! include 'COMMON.INTERACT'
1813 ! include 'COMMON.IOUNITS'
1814 ! include 'COMMON.NAMES'
1815 integer :: i,j,inres,mnum
1818 d_t(j,0)=d_t(j,0)+0.5d0*d_a(j,0)*d_time
1822 d_t(j,i)=d_t(j,i)+0.5d0*d_a(j,i)*d_time
1827 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1828 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1829 .and.(mnum.ne.5)) then
1832 d_t(j,inres)=d_t(j,inres)+0.5d0*d_a(j,inres)*d_time
1837 end subroutine RESPA_vel
1838 !-----------------------------------------------------------------------------
1840 ! Applying velocity Verlet algorithm - step 1 to coordinates
1842 ! implicit real*8 (a-h,o-z)
1843 ! include 'DIMENSIONS'
1844 ! include 'COMMON.CONTROL'
1845 ! include 'COMMON.VAR'
1846 ! include 'COMMON.MD'
1847 ! include 'COMMON.CHAIN'
1848 ! include 'COMMON.DERIV'
1849 ! include 'COMMON.GEO'
1850 ! include 'COMMON.LOCAL'
1851 ! include 'COMMON.INTERACT'
1852 ! include 'COMMON.IOUNITS'
1853 ! include 'COMMON.NAMES'
1854 real(kind=8) :: adt,adt2
1855 integer :: i,j,inres,mnum
1858 write (iout,*) "VELVERLET1 START: DC"
1860 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1861 (dc(j,i+nres),j=1,3)
1865 adt=d_a_old(j,0)*d_time
1867 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1868 d_t_new(j,0)=d_t_old(j,0)+adt2
1869 d_t(j,0)=d_t_old(j,0)+adt
1873 adt=d_a_old(j,i)*d_time
1875 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1876 d_t_new(j,i)=d_t_old(j,i)+adt2
1877 d_t(j,i)=d_t_old(j,i)+adt
1882 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1883 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1884 .and.(mnum.ne.5)) then
1887 adt=d_a_old(j,inres)*d_time
1889 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1890 d_t_new(j,inres)=d_t_old(j,inres)+adt2
1891 d_t(j,inres)=d_t_old(j,inres)+adt
1896 write (iout,*) "VELVERLET1 END: DC"
1898 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1899 (dc(j,i+nres),j=1,3)
1903 end subroutine verlet1
1904 !-----------------------------------------------------------------------------
1906 ! Step 2 of the velocity Verlet algorithm: update velocities
1908 ! implicit real*8 (a-h,o-z)
1909 ! include 'DIMENSIONS'
1910 ! include 'COMMON.CONTROL'
1911 ! include 'COMMON.VAR'
1912 ! include 'COMMON.MD'
1913 ! include 'COMMON.CHAIN'
1914 ! include 'COMMON.DERIV'
1915 ! include 'COMMON.GEO'
1916 ! include 'COMMON.LOCAL'
1917 ! include 'COMMON.INTERACT'
1918 ! include 'COMMON.IOUNITS'
1919 ! include 'COMMON.NAMES'
1920 integer :: i,j,inres,mnum
1923 d_t(j,0)=d_t_new(j,0)+0.5d0*d_a(j,0)*d_time
1927 d_t(j,i)=d_t_new(j,i)+0.5d0*d_a(j,i)*d_time
1932 ! iti=iabs(itype(i,mnum))
1933 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1934 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
1935 .and.(mnum.ne.5)) then
1938 d_t(j,inres)=d_t_new(j,inres)+0.5d0*d_a(j,inres)*d_time
1943 end subroutine verlet2
1944 !-----------------------------------------------------------------------------
1945 subroutine sddir_precalc
1946 ! Applying velocity Verlet algorithm - step 1 to coordinates
1947 ! implicit real*8 (a-h,o-z)
1948 ! include 'DIMENSIONS'
1954 ! include 'COMMON.CONTROL'
1955 ! include 'COMMON.VAR'
1956 ! include 'COMMON.MD'
1958 ! include 'COMMON.LANGEVIN'
1960 ! include 'COMMON.LANGEVIN.lang0'
1962 ! include 'COMMON.CHAIN'
1963 ! include 'COMMON.DERIV'
1964 ! include 'COMMON.GEO'
1965 ! include 'COMMON.LOCAL'
1966 ! include 'COMMON.INTERACT'
1967 ! include 'COMMON.IOUNITS'
1968 ! include 'COMMON.NAMES'
1969 ! include 'COMMON.TIME1'
1970 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1971 !el common /stochcalc/ stochforcvec
1972 real(kind=8) :: time00
1974 ! Compute friction and stochastic forces
1979 time_fric=time_fric+MPI_Wtime()-time00
1981 call stochastic_force(stochforcvec)
1982 time_stoch=time_stoch+MPI_Wtime()-time00
1985 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
1986 ! forces (d_as_work)
1988 call ginv_mult(fric_work, d_af_work)
1989 call ginv_mult(stochforcvec, d_as_work)
1991 end subroutine sddir_precalc
1992 !-----------------------------------------------------------------------------
1993 subroutine sddir_verlet1
1994 ! Applying velocity Verlet algorithm - step 1 to velocities
1997 ! implicit real*8 (a-h,o-z)
1998 ! include 'DIMENSIONS'
1999 ! include 'COMMON.CONTROL'
2000 ! include 'COMMON.VAR'
2001 ! include 'COMMON.MD'
2003 ! include 'COMMON.LANGEVIN'
2005 ! include 'COMMON.LANGEVIN.lang0'
2007 ! include 'COMMON.CHAIN'
2008 ! include 'COMMON.DERIV'
2009 ! include 'COMMON.GEO'
2010 ! include 'COMMON.LOCAL'
2011 ! include 'COMMON.INTERACT'
2012 ! include 'COMMON.IOUNITS'
2013 ! include 'COMMON.NAMES'
2014 ! Revised 3/31/05 AL: correlation between random contributions to
2015 ! position and velocity increments included.
2016 real(kind=8) :: sqrt13 = 0.57735026918962576451d0 ! 1/sqrt(3)
2017 real(kind=8) :: adt,adt2
2018 integer :: i,j,ind,inres,mnum
2020 ! Add the contribution from BOTH friction and stochastic force to the
2021 ! coordinates, but ONLY the contribution from the friction forces to velocities
2024 adt=(d_a_old(j,0)+d_af_work(j))*d_time
2025 adt2=0.5d0*adt+sqrt13*d_as_work(j)*d_time
2026 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
2027 d_t_new(j,0)=d_t_old(j,0)+0.5d0*adt
2028 d_t(j,0)=d_t_old(j,0)+adt
2033 adt=(d_a_old(j,i)+d_af_work(ind+j))*d_time
2034 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
2035 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
2036 d_t_new(j,i)=d_t_old(j,i)+0.5d0*adt
2037 d_t(j,i)=d_t_old(j,i)+adt
2043 ! iti=iabs(itype(i,mnum))
2044 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2045 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2046 .and.(mnum.ne.5)) then
2049 adt=(d_a_old(j,inres)+d_af_work(ind+j))*d_time
2050 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
2051 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
2052 d_t_new(j,inres)=d_t_old(j,inres)+0.5d0*adt
2053 d_t(j,inres)=d_t_old(j,inres)+adt
2059 end subroutine sddir_verlet1
2060 !-----------------------------------------------------------------------------
2061 subroutine sddir_verlet2
2062 ! Calculating the adjusted velocities for accelerations
2065 ! implicit real*8 (a-h,o-z)
2066 ! include 'DIMENSIONS'
2067 ! include 'COMMON.CONTROL'
2068 ! include 'COMMON.VAR'
2069 ! include 'COMMON.MD'
2071 ! include 'COMMON.LANGEVIN'
2073 ! include 'COMMON.LANGEVIN.lang0'
2075 ! include 'COMMON.CHAIN'
2076 ! include 'COMMON.DERIV'
2077 ! include 'COMMON.GEO'
2078 ! include 'COMMON.LOCAL'
2079 ! include 'COMMON.INTERACT'
2080 ! include 'COMMON.IOUNITS'
2081 ! include 'COMMON.NAMES'
2082 real(kind=8),dimension(6*nres) :: stochforcvec,d_as_work1 !(MAXRES6) maxres6=6*maxres
2083 real(kind=8) :: cos60 = 0.5d0, sin60 = 0.86602540378443864676d0
2084 integer :: i,j,ind,inres,mnum
2085 ! Revised 3/31/05 AL: correlation between random contributions to
2086 ! position and velocity increments included.
2087 ! The correlation coefficients are calculated at low-friction limit.
2088 ! Also, friction forces are now not calculated with new velocities.
2090 ! call friction_force
2091 call stochastic_force(stochforcvec)
2093 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
2094 ! forces (d_as_work)
2096 call ginv_mult(stochforcvec, d_as_work1)
2102 d_t(j,0)=d_t_new(j,0)+(0.5d0*(d_a(j,0)+d_af_work(j)) &
2103 +sin60*d_as_work(j)+cos60*d_as_work1(j))*d_time
2108 d_t(j,i)=d_t_new(j,i)+(0.5d0*(d_a(j,i)+d_af_work(ind+j)) &
2109 +sin60*d_as_work(ind+j)+cos60*d_as_work1(ind+j))*d_time
2115 ! iti=iabs(itype(i,mnum))
2116 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2117 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2118 .and.(mnum.ne.5)) then
2121 d_t(j,inres)=d_t_new(j,inres)+(0.5d0*(d_a(j,inres) &
2122 +d_af_work(ind+j))+sin60*d_as_work(ind+j) &
2123 +cos60*d_as_work1(ind+j))*d_time
2129 end subroutine sddir_verlet2
2130 !-----------------------------------------------------------------------------
2131 subroutine max_accel
2133 ! Find the maximum difference in the accelerations of the the sites
2134 ! at the beginning and the end of the time step.
2137 ! implicit real*8 (a-h,o-z)
2138 ! include 'DIMENSIONS'
2139 ! include 'COMMON.CONTROL'
2140 ! include 'COMMON.VAR'
2141 ! include 'COMMON.MD'
2142 ! include 'COMMON.CHAIN'
2143 ! include 'COMMON.DERIV'
2144 ! include 'COMMON.GEO'
2145 ! include 'COMMON.LOCAL'
2146 ! include 'COMMON.INTERACT'
2147 ! include 'COMMON.IOUNITS'
2148 real(kind=8),dimension(3) :: aux,accel,accel_old
2149 real(kind=8) :: dacc
2153 ! aux(j)=d_a(j,0)-d_a_old(j,0)
2154 accel_old(j)=d_a_old(j,0)
2161 ! 7/3/08 changed to asymmetric difference
2163 ! accel(j)=aux(j)+0.5d0*(d_a(j,i)-d_a_old(j,i))
2164 accel_old(j)=accel_old(j)+0.5d0*d_a_old(j,i)
2165 accel(j)=accel(j)+0.5d0*d_a(j,i)
2166 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2167 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2168 dacc=dabs(accel(j)-accel_old(j))
2169 ! write (iout,*) i,dacc
2170 if (dacc.gt.amax) amax=dacc
2178 accel_old(j)=d_a_old(j,0)
2183 accel_old(j)=accel_old(j)+d_a_old(j,1)
2184 accel(j)=accel(j)+d_a(j,1)
2189 ! iti=iabs(itype(i,mnum))
2190 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2191 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2192 .and.(mnum.ne.5)) then
2194 ! accel(j)=accel(j)+d_a(j,i+nres)-d_a_old(j,i+nres)
2195 accel_old(j)=accel_old(j)+d_a_old(j,i+nres)
2196 accel(j)=accel(j)+d_a(j,i+nres)
2200 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2201 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2202 dacc=dabs(accel(j)-accel_old(j))
2203 ! write (iout,*) "side-chain",i,dacc
2204 if (dacc.gt.amax) amax=dacc
2208 accel_old(j)=accel_old(j)+d_a_old(j,i)
2209 accel(j)=accel(j)+d_a(j,i)
2210 ! aux(j)=aux(j)+d_a(j,i)-d_a_old(j,i)
2214 end subroutine max_accel
2215 !-----------------------------------------------------------------------------
2216 subroutine predict_edrift(epdrift)
2218 ! Predict the drift of the potential energy
2221 use control_data, only: lmuca
2222 ! implicit real*8 (a-h,o-z)
2223 ! include 'DIMENSIONS'
2224 ! include 'COMMON.CONTROL'
2225 ! include 'COMMON.VAR'
2226 ! include 'COMMON.MD'
2227 ! include 'COMMON.CHAIN'
2228 ! include 'COMMON.DERIV'
2229 ! include 'COMMON.GEO'
2230 ! include 'COMMON.LOCAL'
2231 ! include 'COMMON.INTERACT'
2232 ! include 'COMMON.IOUNITS'
2233 ! include 'COMMON.MUCA'
2234 real(kind=8) :: epdrift,epdriftij
2236 ! Drift of the potential energy
2242 epdriftij=dabs((d_a(j,i)-d_a_old(j,i))*gcart(j,i))
2243 if (lmuca) epdriftij=epdriftij*factor
2244 ! write (iout,*) "back",i,j,epdriftij
2245 if (epdriftij.gt.epdrift) epdrift=epdriftij
2249 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1.and.&
2250 molnum(i).ne.5) then
2253 dabs((d_a(j,i+nres)-d_a_old(j,i+nres))*gxcart(j,i))
2254 if (lmuca) epdriftij=epdriftij*factor
2255 ! write (iout,*) "side",i,j,epdriftij
2256 if (epdriftij.gt.epdrift) epdrift=epdriftij
2260 epdrift=0.5d0*epdrift*d_time*d_time
2261 ! write (iout,*) "epdrift",epdrift
2263 end subroutine predict_edrift
2264 !-----------------------------------------------------------------------------
2265 subroutine verlet_bath
2267 ! Coupling to the thermostat by using the Berendsen algorithm
2270 ! implicit real*8 (a-h,o-z)
2271 ! include 'DIMENSIONS'
2272 ! include 'COMMON.CONTROL'
2273 ! include 'COMMON.VAR'
2274 ! include 'COMMON.MD'
2275 ! include 'COMMON.CHAIN'
2276 ! include 'COMMON.DERIV'
2277 ! include 'COMMON.GEO'
2278 ! include 'COMMON.LOCAL'
2279 ! include 'COMMON.INTERACT'
2280 ! include 'COMMON.IOUNITS'
2281 ! include 'COMMON.NAMES'
2282 real(kind=8) :: T_half,fact
2283 integer :: i,j,inres,mnum
2285 T_half=2.0d0/(dimen3*Rb)*EK
2286 fact=dsqrt(1.0d0+(d_time/tau_bath)*(t_bath/T_half-1.0d0))
2287 ! write(iout,*) "T_half", T_half
2288 ! write(iout,*) "EK", EK
2289 ! write(iout,*) "fact", fact
2291 d_t(j,0)=fact*d_t(j,0)
2295 d_t(j,i)=fact*d_t(j,i)
2300 ! iti=iabs(itype(i,mnum))
2301 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
2302 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
2303 .and.(mnum.ne.5)) then
2306 d_t(j,inres)=fact*d_t(j,inres)
2311 end subroutine verlet_bath
2312 !-----------------------------------------------------------------------------
2314 ! Set up the initial conditions of a MD simulation
2317 use control, only:tcpu
2318 !el use io_basic, only:ilen
2321 use minimm, only:minim_dc,minimize,sc_move
2322 use io_config, only:readrst
2323 use io, only:statout
2324 ! implicit real*8 (a-h,o-z)
2325 ! include 'DIMENSIONS'
2328 character(len=16) :: form
2329 integer :: IERROR,ERRCODE
2331 integer :: iranmin,itrial,itmp
2332 ! include 'COMMON.SETUP'
2333 ! include 'COMMON.CONTROL'
2334 ! include 'COMMON.VAR'
2335 ! include 'COMMON.MD'
2337 ! include 'COMMON.LANGEVIN'
2339 ! include 'COMMON.LANGEVIN.lang0'
2341 ! include 'COMMON.CHAIN'
2342 ! include 'COMMON.DERIV'
2343 ! include 'COMMON.GEO'
2344 ! include 'COMMON.LOCAL'
2345 ! include 'COMMON.INTERACT'
2346 ! include 'COMMON.IOUNITS'
2347 ! include 'COMMON.NAMES'
2348 ! include 'COMMON.REMD'
2349 real(kind=8),dimension(0:n_ene) :: energia_long,energia_short
2350 real(kind=8),dimension(3) :: vcm,incr,L
2351 real(kind=8) :: xv,sigv,lowb,highb
2352 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
2353 character(len=256) :: qstr
2356 character(len=50) :: tytul
2357 logical :: file_exist
2358 !el common /gucio/ cm
2359 integer :: i,j,ipos,iq,iw,nft_sc,iretcode,nfun,itime,ierr,mnum
2360 real(kind=8) :: etot,tt0
2364 ! write(iout,*) "d_time", d_time
2365 ! Compute the standard deviations of stochastic forces for Langevin dynamics
2366 ! if the friction coefficients do not depend on surface area
2367 if (lang.gt.0 .and. .not.surfarea) then
2370 stdforcp(i)=stdfp(mnum)*dsqrt(gamp(mnum))
2374 stdforcsc(i)=stdfsc(iabs(itype(i,mnum)),mnum) &
2375 *dsqrt(gamsc(iabs(itype(i,mnum)),mnum))
2378 ! Open the pdb file for snapshotshots
2381 if (ilen(tmpdir).gt.0) &
2382 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2383 liczba(:ilen(liczba))//".pdb")
2385 file=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2389 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2390 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2391 liczba(:ilen(liczba))//".x")
2392 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2395 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2396 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2397 liczba(:ilen(liczba))//".cx")
2398 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2404 if (ilen(tmpdir).gt.0) &
2405 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.pdb")
2406 open(ipdb,file=prefix(:ilen(prefix))//"_MD.pdb")
2408 if (ilen(tmpdir).gt.0) &
2409 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.cx")
2410 cartname=prefix(:ilen(prefix))//"_MD.cx"
2414 write (qstr,'(256(1h ))')
2417 iq = qinfrag(i,iset)*10
2418 iw = wfrag(i,iset)/100
2420 if(me.eq.king.or..not.out1file) &
2421 write (iout,*) "Frag",qinfrag(i,iset),wfrag(i,iset),iq,iw
2422 write (qstr(ipos:ipos+6),'(2h_f,i1,1h_,i1,1h_,i1)') i,iq,iw
2427 iq = qinpair(i,iset)*10
2428 iw = wpair(i,iset)/100
2430 if(me.eq.king.or..not.out1file) &
2431 write (iout,*) "Pair",i,qinpair(i,iset),wpair(i,iset),iq,iw
2432 write (qstr(ipos:ipos+6),'(2h_p,i1,1h_,i1,1h_,i1)') i,iq,iw
2436 ! pdbname=pdbname(:ilen(pdbname)-4)//qstr(:ipos-1)//'.pdb'
2438 ! cartname=cartname(:ilen(cartname)-2)//qstr(:ipos-1)//'.x'
2440 ! cartname=cartname(:ilen(cartname)-3)//qstr(:ipos-1)//'.cx'
2442 ! statname=statname(:ilen(statname)-5)//qstr(:ipos-1)//'.stat'
2446 if (restart1file) then
2448 inquire(file=mremd_rst_name,exist=file_exist)
2449 write (*,*) me," Before broadcast: file_exist",file_exist
2451 call MPI_Bcast(file_exist,1,MPI_LOGICAL,king,CG_COMM,&
2454 write (*,*) me," After broadcast: file_exist",file_exist
2455 ! inquire(file=mremd_rst_name,exist=file_exist)
2456 if(me.eq.king.or..not.out1file) &
2457 write(iout,*) "Initial state read by master and distributed"
2459 if (ilen(tmpdir).gt.0) &
2460 call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_' &
2461 //liczba(:ilen(liczba))//'.rst')
2462 inquire(file=rest2name,exist=file_exist)
2465 if(.not.restart1file) then
2466 if(me.eq.king.or..not.out1file) &
2467 write(iout,*) "Initial state will be read from file ",&
2468 rest2name(:ilen(rest2name))
2471 call rescale_weights(t_bath)
2473 if(me.eq.king.or..not.out1file)then
2474 if (restart1file) then
2475 write(iout,*) "File ",mremd_rst_name(:ilen(mremd_rst_name)),&
2478 write(iout,*) "File ",rest2name(:ilen(rest2name)),&
2481 write(iout,*) "Initial velocities randomly generated"
2488 ! Generate initial velocities
2489 if(me.eq.king.or..not.out1file) &
2490 write(iout,*) "Initial velocities randomly generated"
2495 ! rest2name = prefix(:ilen(prefix))//'.rst'
2496 if(me.eq.king.or..not.out1file)then
2497 write (iout,*) "Initial velocities"
2499 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2500 (d_t(j,i+nres),j=1,3)
2502 ! Zeroing the total angular momentum of the system
2503 write(iout,*) "Calling the zero-angular momentum subroutine"
2506 ! Getting the potential energy and forces and velocities and accelerations
2508 ! write (iout,*) "velocity of the center of the mass:"
2509 ! write (iout,*) (vcm(j),j=1,3)
2511 d_t(j,0)=d_t(j,0)-vcm(j)
2513 ! Removing the velocity of the center of mass
2515 if(me.eq.king.or..not.out1file)then
2516 write (iout,*) "vcm right after adjustment:"
2517 write (iout,*) (vcm(j),j=1,3)
2521 if(iranconf.ne.0 .or.indpdb.gt.0.and..not.unres_pdb .or.preminim) then
2523 print *, 'Calling OVERLAP_SC'
2524 call overlap_sc(fail)
2525 print *,'after OVERLAP'
2528 print *,'call SC_MOVE'
2529 call sc_move(2,nres-1,10,1d10,nft_sc,etot)
2530 print *,'SC_move',nft_sc,etot
2531 if(me.eq.king.or..not.out1file) &
2532 write(iout,*) 'SC_move',nft_sc,etot
2536 print *, 'Calling MINIM_DC'
2537 call minim_dc(etot,iretcode,nfun)
2539 call geom_to_var(nvar,varia)
2540 print *,'Calling MINIMIZE.'
2541 call minimize(etot,varia,iretcode,nfun)
2542 call var_to_geom(nvar,varia)
2544 if(me.eq.king.or..not.out1file) &
2545 write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
2547 if(iranconf.ne.0) then
2548 !c 8/22/17 AL Loop to produce a low-energy random conformation
2551 if(me.eq.king.or..not.out1file) &
2552 write (iout,*) 'Calling OVERLAP_SC'
2553 call overlap_sc(fail)
2554 endif !endif overlap
2557 call sc_move(2,nres-1,10,1d10,nft_sc,etot)
2558 print *,'SC_move',nft_sc,etot
2559 if(me.eq.king.or..not.out1file) &
2560 write(iout,*) 'SC_move',nft_sc,etot
2564 print *, 'Calling MINIM_DC'
2565 call minim_dc(etot,iretcode,nfun)
2566 call int_from_cart1(.false.)
2568 call geom_to_var(nvar,varia)
2569 print *,'Calling MINIMIZE.'
2570 call minimize(etot,varia,iretcode,nfun)
2571 call var_to_geom(nvar,varia)
2573 if(me.eq.king.or..not.out1file) &
2574 write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
2576 if (isnan(etot) .or. etot.gt.4.0d6) then
2577 write (iout,*) "Energy too large",etot, &
2578 " trying another random conformation"
2581 call gen_rand_conf(itmp,*30)
2583 30 write (iout,*) 'Failed to generate random conformation', &
2585 write (*,*) 'Processor:',me, &
2586 ' Failed to generate random conformation',&
2595 write (iout,'(a,i3,a)') 'Processor:',me, &
2596 ' error in generating random conformation.'
2597 write (*,'(a,i3,a)') 'Processor:',me, &
2598 ' error in generating random conformation.'
2601 ! call MPI_Abort(mpi_comm_world,error_msg,ierrcode)
2602 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
2612 write (iout,'(a,i3,a)') 'Processor:',me, &
2613 ' failed to generate a low-energy random conformation.'
2614 write (*,'(a,i3,a,f10.3)') 'Processor:',me, &
2615 ' failed to generate a low-energy random conformation.',etot
2619 ! call MPI_Abort(mpi_comm_world,error_msg,ierrcode)
2620 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
2627 call chainbuild_cart
2632 kinetic_T=2.0d0/(dimen3*Rb)*EK
2633 if(me.eq.king.or..not.out1file)then
2643 write(iout,*) "before ETOTAL"
2644 call etotal(potEcomp)
2645 if (large) call enerprint(potEcomp)
2648 t_etotal=t_etotal+MPI_Wtime()-tt0
2650 t_etotal=t_etotal+tcpu()-tt0
2657 if (amax*d_time .gt. dvmax) then
2658 d_time=d_time*dvmax/amax
2659 if(me.eq.king.or..not.out1file) write (iout,*) &
2660 "Time step reduced to",d_time,&
2661 " because of too large initial acceleration."
2663 if(me.eq.king.or..not.out1file)then
2664 write(iout,*) "Potential energy and its components"
2665 call enerprint(potEcomp)
2666 ! write(iout,*) (potEcomp(i),i=0,n_ene)
2668 potE=potEcomp(0)-potEcomp(20)
2671 if (ntwe.ne.0) call statout(itime)
2672 if(me.eq.king.or..not.out1file) &
2673 write (iout,'(/a/3(a25,1pe14.5/))') "Initial:", &
2674 " Kinetic energy",EK," Potential energy",potE, &
2675 " Total energy",totE," Maximum acceleration ", &
2678 write (iout,*) "Initial coordinates"
2680 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(c(j,i),j=1,3),&
2683 write (iout,*) "Initial dC"
2685 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
2686 (dc(j,i+nres),j=1,3)
2688 write (iout,*) "Initial velocities"
2689 write (iout,"(13x,' backbone ',23x,' side chain')")
2691 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2692 (d_t(j,i+nres),j=1,3)
2694 write (iout,*) "Initial accelerations"
2696 ! write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
2697 write (iout,'(i3,3f15.10,3x,3f15.10)') i,(d_a(j,i),j=1,3),&
2698 (d_a(j,i+nres),j=1,3)
2704 d_t_old(j,i)=d_t(j,i)
2705 d_a_old(j,i)=d_a(j,i)
2707 ! write (iout,*) "dc_old",i,(dc_old(j,i),j=1,3)
2716 call etotal_short(energia_short)
2717 if (large) call enerprint(potEcomp)
2720 t_eshort=t_eshort+MPI_Wtime()-tt0
2722 t_eshort=t_eshort+tcpu()-tt0
2727 if(.not.out1file .and. large) then
2728 write (iout,*) "energia_long",energia_long(0),&
2729 " energia_short",energia_short(0),&
2730 " total",energia_long(0)+energia_short(0)
2731 write (iout,*) "Initial fast-force accelerations"
2733 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2734 (d_a(j,i+nres),j=1,3)
2737 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
2740 d_a_short(j,i)=d_a(j,i)
2749 call etotal_long(energia_long)
2750 if (large) call enerprint(potEcomp)
2753 t_elong=t_elong+MPI_Wtime()-tt0
2755 t_elong=t_elong+tcpu()-tt0
2760 if(.not.out1file .and. large) then
2761 write (iout,*) "energia_long",energia_long(0)
2762 write (iout,*) "Initial slow-force accelerations"
2764 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2765 (d_a(j,i+nres),j=1,3)
2769 t_enegrad=t_enegrad+MPI_Wtime()-tt0
2771 t_enegrad=t_enegrad+tcpu()-tt0
2775 end subroutine init_MD
2776 !-----------------------------------------------------------------------------
2777 subroutine random_vel
2779 ! implicit real*8 (a-h,o-z)
2781 use random, only:anorm_distr
2783 ! include 'DIMENSIONS'
2784 ! include 'COMMON.CONTROL'
2785 ! include 'COMMON.VAR'
2786 ! include 'COMMON.MD'
2788 ! include 'COMMON.LANGEVIN'
2790 ! include 'COMMON.LANGEVIN.lang0'
2792 ! include 'COMMON.CHAIN'
2793 ! include 'COMMON.DERIV'
2794 ! include 'COMMON.GEO'
2795 ! include 'COMMON.LOCAL'
2796 ! include 'COMMON.INTERACT'
2797 ! include 'COMMON.IOUNITS'
2798 ! include 'COMMON.NAMES'
2799 ! include 'COMMON.TIME1'
2800 real(kind=8) :: xv,sigv,lowb,highb ,Ek1
2803 real(kind=8) ,allocatable, dimension(:) :: DDU1,DDU2,DL2,DL1,xsolv,DML,rs
2804 real(kind=8) :: sumx
2806 real(kind=8) ,allocatable, dimension(:) :: rsold
2807 real (kind=8),allocatable,dimension(:,:) :: matold
2811 integer :: i,j,ii,k,ind,mark,imark,mnum
2812 ! Generate random velocities from Gaussian distribution of mean 0 and std of KT/m
2813 ! First generate velocities in the eigenspace of the G matrix
2814 ! write (iout,*) "Calling random_vel dimen dimen3",dimen,dimen3
2821 sigv=dsqrt((Rb*t_bath)/geigen(i))
2824 d_t_work_new(ii)=anorm_distr(xv,sigv,lowb,highb)
2826 write (iout,*) "i",i," ii",ii," geigen",geigen(i),&
2827 " d_t_work_new",d_t_work_new(ii)
2838 Ek1=Ek1+0.5d0*geigen(i)*d_t_work_new(ii)**2
2841 write (iout,*) "Ek from eigenvectors",Ek1
2842 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
2846 ! Transform velocities to UNRES coordinate space
2847 allocate (DL1(2*nres))
2848 allocate (DDU1(2*nres))
2849 allocate (DL2(2*nres))
2850 allocate (DDU2(2*nres))
2851 allocate (xsolv(2*nres))
2852 allocate (DML(2*nres))
2853 allocate (rs(2*nres))
2855 allocate (rsold(2*nres))
2856 allocate (matold(2*nres,2*nres))
2858 matold(1,1)=DMorig(1)
2859 matold(1,2)=DU1orig(1)
2860 matold(1,3)=DU2orig(1)
2861 write (*,*) DMorig(1),DU1orig(1),DU2orig(1)
2866 matold(i,j)=DMorig(i)
2867 matold(i,j-1)=DU1orig(i-1)
2869 matold(i,j-2)=DU2orig(i-2)
2877 matold(i,j+1)=DU1orig(i)
2883 matold(i,j+2)=DU2orig(i)
2887 matold(dimen,dimen)=DMorig(dimen)
2888 matold(dimen,dimen-1)=DU1orig(dimen-1)
2889 matold(dimen,dimen-2)=DU2orig(dimen-2)
2890 write(iout,*) "old gmatrix"
2891 call matout(dimen,dimen,2*nres,2*nres,matold)
2895 ! Find the ith eigenvector of the pentadiagonal inertiq matrix
2899 DML(j)=DMorig(j)-geigen(i)
2902 DML(j-1)=DMorig(j)-geigen(i)
2907 DDU1(imark-1)=DU2orig(imark-1)
2908 do j=imark+1,dimen-1
2909 DDU1(j-1)=DU1orig(j)
2917 DDU2(j)=DU2orig(j+1)
2926 write (iout,*) "DL2,DL1,DML,DDU1,DDU2"
2927 write(iout,'(10f10.5)') (DL2(k),k=3,dimen-1)
2928 write(iout,'(10f10.5)') (DL1(k),k=2,dimen-1)
2929 write(iout,'(10f10.5)') (DML(k),k=1,dimen-1)
2930 write(iout,'(10f10.5)') (DDU1(k),k=1,dimen-2)
2931 write(iout,'(10f10.5)') (DDU2(k),k=1,dimen-3)
2934 if (imark.gt.2) rs(imark-2)=-DU2orig(imark-2)
2935 if (imark.gt.1) rs(imark-1)=-DU1orig(imark-1)
2936 if (imark.lt.dimen) rs(imark)=-DU1orig(imark)
2937 if (imark.lt.dimen-1) rs(imark+1)=-DU2orig(imark)
2941 ! write (iout,*) "Vector rs"
2943 ! write (iout,*) j,rs(j)
2946 call FDIAG(dimen-1,DL2,DL1,DML,DDU1,DDU2,rs,xsolv,mark)
2953 sumx=-geigen(i)*xsolv(j)
2955 sumx=sumx+matold(j,k)*xsolv(k)
2958 sumx=sumx+matold(j,k)*xsolv(k-1)
2960 write(iout,'(i5,3f10.5)') j,sumx,rsold(j),sumx-rsold(j)
2963 sumx=-geigen(i)*xsolv(j-1)
2965 sumx=sumx+matold(j,k)*xsolv(k)
2968 sumx=sumx+matold(j,k)*xsolv(k-1)
2970 write(iout,'(i5,3f10.5)') j-1,sumx,rsold(j-1),sumx-rsold(j-1)
2974 "Solution of equations system",i," for eigenvalue",geigen(i)
2976 write(iout,'(i5,f10.5)') j,xsolv(j)
2979 do j=dimen-1,imark,-1
2984 write (iout,*) "Un-normalized eigenvector",i," for eigenvalue",geigen(i)
2986 write(iout,'(i5,f10.5)') j,xsolv(j)
2989 ! Normalize ith eigenvector
2992 sumx=sumx+xsolv(j)**2
2996 xsolv(j)=xsolv(j)/sumx
2999 write (iout,*) "Eigenvector",i," for eigenvalue",geigen(i)
3001 write(iout,'(i5,3f10.5)') j,xsolv(j)
3004 ! All done at this point for eigenvector i, exit loop
3012 write (iout,*) "Unable to find eigenvector",i
3015 ! write (iout,*) "i=",i
3017 ! write (iout,*) "k=",k
3020 ! write(iout,*) "ind",ind," ind1",3*(i-1)+k
3021 d_t_work(ind)=d_t_work(ind) &
3022 +xsolv(j)*d_t_work_new(3*(i-1)+k)
3025 enddo ! i (loop over the eigenvectors)
3028 write (iout,*) "d_t_work"
3030 write (iout,"(i5,f10.5)") i,d_t_work(i)
3035 ! if (itype(i,1).eq.10) then
3037 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3038 iti=iabs(itype(i,mnum))
3039 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3040 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
3041 .or.(mnum.eq.5)) then
3048 ! write (iout,*) "k",k," ii+k",ii+k," ii+j+k",ii+j+k,"EK1",Ek1
3049 Ek1=Ek1+0.5d0*mp(mnum)*((d_t_work(ii+j+k)+d_t_work_new(ii+k))/2)**2+&
3050 0.5d0*0.25d0*IP(mnum)*(d_t_work(ii+j+k)-d_t_work_new(ii+k))**2
3053 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3054 .and.(mnum.ne.5)) ii=ii+3
3055 write (iout,*) "i",i," itype",itype(i,mnum)," mass",msc(itype(i,mnum),mnum)
3056 write (iout,*) "ii",ii
3059 write (iout,*) "k",k," ii",ii,"EK1",EK1
3060 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3062 Ek1=Ek1+0.5d0*Isc(iabs(itype(i,mnum)),mnum)*(d_t_work(ii)-d_t_work(ii-3))**2
3063 Ek1=Ek1+0.5d0*msc(iabs(itype(i,mnum)),mnum)*d_t_work(ii)**2
3065 write (iout,*) "i",i," ii",ii
3067 write (iout,*) "Ek from d_t_work",Ek1
3068 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
3070 if(allocated(DDU1)) deallocate(DDU1)
3071 if(allocated(DDU2)) deallocate(DDU2)
3072 if(allocated(DL2)) deallocate(DL2)
3073 if(allocated(DL1)) deallocate(DL1)
3074 if(allocated(xsolv)) deallocate(xsolv)
3075 if(allocated(DML)) deallocate(DML)
3076 if(allocated(rs)) deallocate(rs)
3078 if(allocated(matold)) deallocate(matold)
3079 if(allocated(rsold)) deallocate(rsold)
3084 d_t(k,j)=d_t_work(ind)
3088 if (itype(j,1).ne.10 .and. itype(j,mnum).ne.ntyp1_molec(mnum)&
3089 .and.(mnum.ne.5)) then
3091 d_t(k,j+nres)=d_t_work(ind)
3097 write (iout,*) "Random velocities in the Calpha,SC space"
3099 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
3102 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
3109 ! if (itype(i,1).eq.10) then
3111 if (itype(i,1).eq.10 .or. itype(i,mnum).eq.ntyp1_molec(mnum)&
3112 .or.(mnum.eq.5)) then
3114 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
3118 d_t(j,i+nres)=d_t(j,i+nres)-d_t(j,i)
3119 d_t(j,i)=d_t(j,i+1)-d_t(j,i)
3124 write (iout,*)"Random velocities in the virtual-bond-vector space"
3126 write (iout,'(i3,3f10.5)') i,(d_t(j,i),j=1,3)
3129 write (iout,'(i3,3f10.5)') i,(d_t(j,i+nres),j=1,3)
3132 write (iout,*) "Ek from d_t_work",Ek1
3133 write (iout,*) "Kinetic temperatures",2*Ek1/(3*dimen*Rb)
3141 d_t_work(ind)=d_t_work(ind) &
3142 +Gvec(i,j)*d_t_work_new((j-1)*3+k+1)
3144 ! write (iout,*) "i",i," ind",ind," d_t_work",d_t_work(ind)
3148 ! Transfer to the d_t vector
3150 d_t(j,0)=d_t_work(j)
3156 d_t(j,i)=d_t_work(ind)
3161 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3162 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3163 .and.(mnum.ne.5)) then
3166 d_t(j,i+nres)=d_t_work(ind)
3172 ! write (iout,*) "Kinetic energy",Ek,EK1," kinetic temperature",&
3173 ! 2.0d0/(dimen3*Rb)*EK,2.0d0/(dimen3*Rb)*EK1
3175 ! write(iout,*) "end init MD"
3177 end subroutine random_vel
3178 !-----------------------------------------------------------------------------
3180 subroutine sd_verlet_p_setup
3181 ! Sets up the parameters of stochastic Verlet algorithm
3182 ! implicit real*8 (a-h,o-z)
3183 ! include 'DIMENSIONS'
3184 use control, only: tcpu
3189 ! include 'COMMON.CONTROL'
3190 ! include 'COMMON.VAR'
3191 ! include 'COMMON.MD'
3193 ! include 'COMMON.LANGEVIN'
3195 ! include 'COMMON.LANGEVIN.lang0'
3197 ! include 'COMMON.CHAIN'
3198 ! include 'COMMON.DERIV'
3199 ! include 'COMMON.GEO'
3200 ! include 'COMMON.LOCAL'
3201 ! include 'COMMON.INTERACT'
3202 ! include 'COMMON.IOUNITS'
3203 ! include 'COMMON.NAMES'
3204 ! include 'COMMON.TIME1'
3205 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3206 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3207 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3208 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3209 logical :: lprn = .false.
3210 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3211 real(kind=8) :: ktm,gdt,egdt,gdt2,gdt3,gdt4,gdt5,gdt6,gdt7,gdt8,&
3213 integer :: i,maxres2
3220 ! AL 8/17/04 Code adapted from tinker
3222 ! Get the frictional and random terms for stochastic dynamics in the
3223 ! eigenspace of mass-scaled UNRES friction matrix
3227 gdt = fricgam(i) * d_time
3229 ! Stochastic dynamics reduces to simple MD for zero friction
3231 if (gdt .le. zero) then
3232 pfric_vec(i) = 1.0d0
3233 vfric_vec(i) = d_time
3234 afric_vec(i) = 0.5d0 * d_time * d_time
3235 prand_vec(i) = 0.0d0
3236 vrand_vec1(i) = 0.0d0
3237 vrand_vec2(i) = 0.0d0
3239 ! Analytical expressions when friction coefficient is large
3242 if (gdt .ge. gdt_radius) then
3245 vfric_vec(i) = (1.0d0-egdt) / fricgam(i)
3246 afric_vec(i) = (d_time-vfric_vec(i)) / fricgam(i)
3247 pterm = 2.0d0*gdt - 3.0d0 + (4.0d0-egdt)*egdt
3248 vterm = 1.0d0 - egdt**2
3249 rho = (1.0d0-egdt)**2 / sqrt(pterm*vterm)
3251 ! Use series expansions when friction coefficient is small
3262 afric_vec(i) = (gdt2/2.0d0 - gdt3/6.0d0 + gdt4/24.0d0 &
3263 - gdt5/120.0d0 + gdt6/720.0d0 &
3264 - gdt7/5040.0d0 + gdt8/40320.0d0 &
3265 - gdt9/362880.0d0) / fricgam(i)**2
3266 vfric_vec(i) = d_time - fricgam(i)*afric_vec(i)
3267 pfric_vec(i) = 1.0d0 - fricgam(i)*vfric_vec(i)
3268 pterm = 2.0d0*gdt3/3.0d0 - gdt4/2.0d0 &
3269 + 7.0d0*gdt5/30.0d0 - gdt6/12.0d0 &
3270 + 31.0d0*gdt7/1260.0d0 - gdt8/160.0d0 &
3271 + 127.0d0*gdt9/90720.0d0
3272 vterm = 2.0d0*gdt - 2.0d0*gdt2 + 4.0d0*gdt3/3.0d0 &
3273 - 2.0d0*gdt4/3.0d0 + 4.0d0*gdt5/15.0d0 &
3274 - 4.0d0*gdt6/45.0d0 + 8.0d0*gdt7/315.0d0 &
3275 - 2.0d0*gdt8/315.0d0 + 4.0d0*gdt9/2835.0d0
3276 rho = sqrt(3.0d0) * (0.5d0 - 3.0d0*gdt/16.0d0 &
3277 - 17.0d0*gdt2/1280.0d0 &
3278 + 17.0d0*gdt3/6144.0d0 &
3279 + 40967.0d0*gdt4/34406400.0d0 &
3280 - 57203.0d0*gdt5/275251200.0d0 &
3281 - 1429487.0d0*gdt6/13212057600.0d0)
3284 ! Compute the scaling factors of random terms for the nonzero friction case
3286 ktm = 0.5d0*d_time/fricgam(i)
3287 psig = dsqrt(ktm*pterm) / fricgam(i)
3288 vsig = dsqrt(ktm*vterm)
3289 rhoc = dsqrt(1.0d0 - rho*rho)
3291 vrand_vec1(i) = vsig * rho
3292 vrand_vec2(i) = vsig * rhoc
3297 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3300 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3301 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3305 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3308 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3309 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3310 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3311 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3312 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec1,vrand_mat1)
3313 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3316 t_sdsetup=t_sdsetup+MPI_Wtime()
3318 t_sdsetup=t_sdsetup+tcpu()-tt0
3321 end subroutine sd_verlet_p_setup
3322 !-----------------------------------------------------------------------------
3323 subroutine eigtransf1(n,ndim,ab,d,c)
3327 real(kind=8) :: ab(ndim,ndim,n),c(ndim,n),d(ndim)
3333 c(i,j)=c(i,j)+ab(k,j,i)*d(k)
3338 end subroutine eigtransf1
3339 !-----------------------------------------------------------------------------
3340 subroutine eigtransf(n,ndim,a,b,d,c)
3344 real(kind=8) :: a(ndim,n),b(ndim,n),c(ndim,n),d(ndim)
3350 c(i,j)=c(i,j)+a(i,k)*b(k,j)*d(k)
3355 end subroutine eigtransf
3356 !-----------------------------------------------------------------------------
3357 subroutine sd_verlet1
3359 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3361 ! implicit real*8 (a-h,o-z)
3362 ! include 'DIMENSIONS'
3363 ! include 'COMMON.CONTROL'
3364 ! include 'COMMON.VAR'
3365 ! include 'COMMON.MD'
3367 ! include 'COMMON.LANGEVIN'
3369 ! include 'COMMON.LANGEVIN.lang0'
3371 ! include 'COMMON.CHAIN'
3372 ! include 'COMMON.DERIV'
3373 ! include 'COMMON.GEO'
3374 ! include 'COMMON.LOCAL'
3375 ! include 'COMMON.INTERACT'
3376 ! include 'COMMON.IOUNITS'
3377 ! include 'COMMON.NAMES'
3378 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3379 !el common /stochcalc/ stochforcvec
3380 logical :: lprn = .false.
3381 real(kind=8) :: ddt1,ddt2
3382 integer :: i,j,ind,inres
3384 ! write (iout,*) "dc_old"
3386 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3387 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3390 dc_work(j)=dc_old(j,0)
3391 d_t_work(j)=d_t_old(j,0)
3392 d_a_work(j)=d_a_old(j,0)
3397 dc_work(ind+j)=dc_old(j,i)
3398 d_t_work(ind+j)=d_t_old(j,i)
3399 d_a_work(ind+j)=d_a_old(j,i)
3405 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3406 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3407 .and.(mnum.ne.5)) then
3409 dc_work(ind+j)=dc_old(j,i+nres)
3410 d_t_work(ind+j)=d_t_old(j,i+nres)
3411 d_a_work(ind+j)=d_a_old(j,i+nres)
3419 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3423 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3424 vfric_mat(i,j),afric_mat(i,j),&
3425 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3433 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3434 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3435 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3436 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3438 d_t_work_new(i)=ddt1+0.5d0*ddt2
3439 d_t_work(i)=ddt1+ddt2
3444 d_t(j,0)=d_t_work(j)
3449 dc(j,i)=dc_work(ind+j)
3450 d_t(j,i)=d_t_work(ind+j)
3456 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3457 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3458 .and.(mnum.ne.5)) then
3461 dc(j,inres)=dc_work(ind+j)
3462 d_t(j,inres)=d_t_work(ind+j)
3468 end subroutine sd_verlet1
3469 !-----------------------------------------------------------------------------
3470 subroutine sd_verlet2
3472 ! Calculating the adjusted velocities for accelerations
3474 ! implicit real*8 (a-h,o-z)
3475 ! include 'DIMENSIONS'
3476 ! include 'COMMON.CONTROL'
3477 ! include 'COMMON.VAR'
3478 ! include 'COMMON.MD'
3480 ! include 'COMMON.LANGEVIN'
3482 ! include 'COMMON.LANGEVIN.lang0'
3484 ! include 'COMMON.CHAIN'
3485 ! include 'COMMON.DERIV'
3486 ! include 'COMMON.GEO'
3487 ! include 'COMMON.LOCAL'
3488 ! include 'COMMON.INTERACT'
3489 ! include 'COMMON.IOUNITS'
3490 ! include 'COMMON.NAMES'
3491 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3492 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3493 !el common /stochcalc/ stochforcvec
3495 real(kind=8) :: ddt1,ddt2
3496 integer :: i,j,ind,inres
3497 ! Compute the stochastic forces which contribute to velocity change
3499 call stochastic_force(stochforcvecV)
3506 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3507 ddt2=ddt2+vrand_mat1(i,j)*stochforcvec(j)+ &
3508 vrand_mat2(i,j)*stochforcvecV(j)
3510 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3514 d_t(j,0)=d_t_work(j)
3519 d_t(j,i)=d_t_work(ind+j)
3525 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3526 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3527 .and.(mnum.ne.5)) then
3530 d_t(j,inres)=d_t_work(ind+j)
3536 end subroutine sd_verlet2
3537 !-----------------------------------------------------------------------------
3538 subroutine sd_verlet_ciccotti_setup
3540 ! Sets up the parameters of stochastic velocity Verlet algorithmi; Ciccotti's
3542 ! implicit real*8 (a-h,o-z)
3543 ! include 'DIMENSIONS'
3544 use control, only: tcpu
3549 ! include 'COMMON.CONTROL'
3550 ! include 'COMMON.VAR'
3551 ! include 'COMMON.MD'
3553 ! include 'COMMON.LANGEVIN'
3555 ! include 'COMMON.LANGEVIN.lang0'
3557 ! include 'COMMON.CHAIN'
3558 ! include 'COMMON.DERIV'
3559 ! include 'COMMON.GEO'
3560 ! include 'COMMON.LOCAL'
3561 ! include 'COMMON.INTERACT'
3562 ! include 'COMMON.IOUNITS'
3563 ! include 'COMMON.NAMES'
3564 ! include 'COMMON.TIME1'
3565 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3566 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3567 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3568 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3569 logical :: lprn = .false.
3570 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3571 real(kind=8) :: ktm,gdt,egdt,tt0
3572 integer :: i,maxres2
3579 ! AL 8/17/04 Code adapted from tinker
3581 ! Get the frictional and random terms for stochastic dynamics in the
3582 ! eigenspace of mass-scaled UNRES friction matrix
3586 write (iout,*) "i",i," fricgam",fricgam(i)
3587 gdt = fricgam(i) * d_time
3589 ! Stochastic dynamics reduces to simple MD for zero friction
3591 if (gdt .le. zero) then
3592 pfric_vec(i) = 1.0d0
3593 vfric_vec(i) = d_time
3594 afric_vec(i) = 0.5d0*d_time*d_time
3595 prand_vec(i) = afric_vec(i)
3596 vrand_vec2(i) = vfric_vec(i)
3598 ! Analytical expressions when friction coefficient is large
3603 vfric_vec(i) = dexp(-0.5d0*gdt)*d_time
3604 afric_vec(i) = 0.5d0*dexp(-0.25d0*gdt)*d_time*d_time
3605 prand_vec(i) = afric_vec(i)
3606 vrand_vec2(i) = vfric_vec(i)
3608 ! Compute the scaling factors of random terms for the nonzero friction case
3610 ! ktm = 0.5d0*d_time/fricgam(i)
3611 ! psig = dsqrt(ktm*pterm) / fricgam(i)
3612 ! vsig = dsqrt(ktm*vterm)
3613 ! prand_vec(i) = psig*afric_vec(i)
3614 ! vrand_vec2(i) = vsig*vfric_vec(i)
3619 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3622 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3623 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3627 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3629 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3630 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3631 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3632 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3633 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3635 t_sdsetup=t_sdsetup+MPI_Wtime()
3637 t_sdsetup=t_sdsetup+tcpu()-tt0
3640 end subroutine sd_verlet_ciccotti_setup
3641 !-----------------------------------------------------------------------------
3642 subroutine sd_verlet1_ciccotti
3644 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3645 ! implicit real*8 (a-h,o-z)
3647 ! include 'DIMENSIONS'
3651 ! include 'COMMON.CONTROL'
3652 ! include 'COMMON.VAR'
3653 ! include 'COMMON.MD'
3655 ! include 'COMMON.LANGEVIN'
3657 ! include 'COMMON.LANGEVIN.lang0'
3659 ! include 'COMMON.CHAIN'
3660 ! include 'COMMON.DERIV'
3661 ! include 'COMMON.GEO'
3662 ! include 'COMMON.LOCAL'
3663 ! include 'COMMON.INTERACT'
3664 ! include 'COMMON.IOUNITS'
3665 ! include 'COMMON.NAMES'
3666 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3667 !el common /stochcalc/ stochforcvec
3668 logical :: lprn = .false.
3669 real(kind=8) :: ddt1,ddt2
3670 integer :: i,j,ind,inres
3671 ! write (iout,*) "dc_old"
3673 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3674 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3677 dc_work(j)=dc_old(j,0)
3678 d_t_work(j)=d_t_old(j,0)
3679 d_a_work(j)=d_a_old(j,0)
3684 dc_work(ind+j)=dc_old(j,i)
3685 d_t_work(ind+j)=d_t_old(j,i)
3686 d_a_work(ind+j)=d_a_old(j,i)
3691 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3693 dc_work(ind+j)=dc_old(j,i+nres)
3694 d_t_work(ind+j)=d_t_old(j,i+nres)
3695 d_a_work(ind+j)=d_a_old(j,i+nres)
3704 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3708 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3709 vfric_mat(i,j),afric_mat(i,j),&
3710 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3718 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3719 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3720 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3721 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3723 d_t_work_new(i)=ddt1+0.5d0*ddt2
3724 d_t_work(i)=ddt1+ddt2
3729 d_t(j,0)=d_t_work(j)
3734 dc(j,i)=dc_work(ind+j)
3735 d_t(j,i)=d_t_work(ind+j)
3741 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3742 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3743 .and.(mnum.ne.5)) then
3746 dc(j,inres)=dc_work(ind+j)
3747 d_t(j,inres)=d_t_work(ind+j)
3753 end subroutine sd_verlet1_ciccotti
3754 !-----------------------------------------------------------------------------
3755 subroutine sd_verlet2_ciccotti
3757 ! Calculating the adjusted velocities for accelerations
3759 ! implicit real*8 (a-h,o-z)
3760 ! include 'DIMENSIONS'
3761 ! include 'COMMON.CONTROL'
3762 ! include 'COMMON.VAR'
3763 ! include 'COMMON.MD'
3765 ! include 'COMMON.LANGEVIN'
3767 ! include 'COMMON.LANGEVIN.lang0'
3769 ! include 'COMMON.CHAIN'
3770 ! include 'COMMON.DERIV'
3771 ! include 'COMMON.GEO'
3772 ! include 'COMMON.LOCAL'
3773 ! include 'COMMON.INTERACT'
3774 ! include 'COMMON.IOUNITS'
3775 ! include 'COMMON.NAMES'
3776 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3777 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3778 !el common /stochcalc/ stochforcvec
3779 real(kind=8) :: ddt1,ddt2
3780 integer :: i,j,ind,inres
3782 ! Compute the stochastic forces which contribute to velocity change
3784 call stochastic_force(stochforcvecV)
3791 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3792 ! ddt2=ddt2+vrand_mat2(i,j)*stochforcvecV(j)
3793 ddt2=ddt2+vrand_mat2(i,j)*stochforcvec(j)
3795 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3799 d_t(j,0)=d_t_work(j)
3804 d_t(j,i)=d_t_work(ind+j)
3810 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3812 ! if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
3815 d_t(j,inres)=d_t_work(ind+j)
3821 end subroutine sd_verlet2_ciccotti
3823 !-----------------------------------------------------------------------------
3825 !-----------------------------------------------------------------------------
3826 subroutine inertia_tensor
3828 ! Calculating the intertia tensor for the entire protein in order to
3829 ! remove the perpendicular components of velocity matrix which cause
3830 ! the molecule to rotate.
3833 ! implicit real*8 (a-h,o-z)
3834 ! include 'DIMENSIONS'
3835 ! include 'COMMON.CONTROL'
3836 ! include 'COMMON.VAR'
3837 ! include 'COMMON.MD'
3838 ! include 'COMMON.CHAIN'
3839 ! include 'COMMON.DERIV'
3840 ! include 'COMMON.GEO'
3841 ! include 'COMMON.LOCAL'
3842 ! include 'COMMON.INTERACT'
3843 ! include 'COMMON.IOUNITS'
3844 ! include 'COMMON.NAMES'
3846 real(kind=8),dimension(3,3) :: Im,Imcp,eigvec,Id
3847 real(kind=8),dimension(3) :: pr,eigval,L,vp,vrot
3848 real(kind=8) :: M_SC,mag,mag2,M_PEP
3849 real(kind=8),dimension(3,0:nres) :: vpp !(3,0:MAXRES)
3850 real(kind=8),dimension(3) :: vs_p,pp,incr,v
3851 real(kind=8),dimension(3,3) :: pr1,pr2
3853 !el common /gucio/ cm
3854 integer :: iti,inres,i,j,k,mnum
3865 ! calculating the center of the mass of the protein
3869 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3870 if (itype(i,mnum).eq.ntyp1_molec(mnum)) cycle
3871 M_PEP=M_PEP+mp(mnum)
3873 cm(j)=cm(j)+(c(j,i)+0.5d0*dc(j,i))*mp(mnum)
3882 if (mnum.eq.5) cycle
3883 iti=iabs(itype(i,mnum))
3884 M_SC=M_SC+msc(iabs(iti),mnum)
3887 cm(j)=cm(j)+msc(iabs(iti),mnum)*c(j,inres)
3891 cm(j)=cm(j)/(M_SC+M_PEP)
3896 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
3898 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3900 Im(1,1)=Im(1,1)+mp(mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
3901 Im(1,2)=Im(1,2)-mp(mnum)*pr(1)*pr(2)
3902 Im(1,3)=Im(1,3)-mp(mnum)*pr(1)*pr(3)
3903 Im(2,3)=Im(2,3)-mp(mnum)*pr(2)*pr(3)
3904 Im(2,2)=Im(2,2)+mp(mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
3905 Im(3,3)=Im(3,3)+mp(mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
3910 iti=iabs(itype(i,mnum))
3911 if (mnum.eq.5) cycle
3914 pr(j)=c(j,inres)-cm(j)
3916 Im(1,1)=Im(1,1)+msc(iabs(iti),mnum)*(pr(2)*pr(2)+pr(3)*pr(3))
3917 Im(1,2)=Im(1,2)-msc(iabs(iti),mnum)*pr(1)*pr(2)
3918 Im(1,3)=Im(1,3)-msc(iabs(iti),mnum)*pr(1)*pr(3)
3919 Im(2,3)=Im(2,3)-msc(iabs(iti),mnum)*pr(2)*pr(3)
3920 Im(2,2)=Im(2,2)+msc(iabs(iti),mnum)*(pr(3)*pr(3)+pr(1)*pr(1))
3921 Im(3,3)=Im(3,3)+msc(iabs(iti),mnum)*(pr(1)*pr(1)+pr(2)*pr(2))
3926 Im(1,1)=Im(1,1)+Ip(mnum)*(1-dc_norm(1,i)*dc_norm(1,i))* &
3927 vbld(i+1)*vbld(i+1)*0.25d0
3928 Im(1,2)=Im(1,2)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(2,i))* &
3929 vbld(i+1)*vbld(i+1)*0.25d0
3930 Im(1,3)=Im(1,3)+Ip(mnum)*(-dc_norm(1,i)*dc_norm(3,i))* &
3931 vbld(i+1)*vbld(i+1)*0.25d0
3932 Im(2,3)=Im(2,3)+Ip(mnum)*(-dc_norm(2,i)*dc_norm(3,i))* &
3933 vbld(i+1)*vbld(i+1)*0.25d0
3934 Im(2,2)=Im(2,2)+Ip(mnum)*(1-dc_norm(2,i)*dc_norm(2,i))* &
3935 vbld(i+1)*vbld(i+1)*0.25d0
3936 Im(3,3)=Im(3,3)+Ip(mnum)*(1-dc_norm(3,i)*dc_norm(3,i))* &
3937 vbld(i+1)*vbld(i+1)*0.25d0
3943 ! if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
3944 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
3945 .and.(mnum.ne.5)) then
3946 iti=iabs(itype(i,mnum))
3948 Im(1,1)=Im(1,1)+Isc(iti,mnum)*(1-dc_norm(1,inres)* &
3949 dc_norm(1,inres))*vbld(inres)*vbld(inres)
3950 Im(1,2)=Im(1,2)-Isc(iti,mnum)*(dc_norm(1,inres)* &
3951 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3952 Im(1,3)=Im(1,3)-Isc(iti,mnum)*(dc_norm(1,inres)* &
3953 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3954 Im(2,3)=Im(2,3)-Isc(iti,mnum)*(dc_norm(2,inres)* &
3955 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3956 Im(2,2)=Im(2,2)+Isc(iti,mnum)*(1-dc_norm(2,inres)* &
3957 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3958 Im(3,3)=Im(3,3)+Isc(iti,mnum)*(1-dc_norm(3,inres)* &
3959 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3964 ! write(iout,*) "The angular momentum before adjustment:"
3965 ! write(iout,*) (L(j),j=1,3)
3971 ! Copying the Im matrix for the djacob subroutine
3979 ! Finding the eigenvectors and eignvalues of the inertia tensor
3980 call djacob(3,3,10000,1.0d-10,Imcp,eigvec,eigval)
3981 ! write (iout,*) "Eigenvalues & Eigenvectors"
3982 ! write (iout,'(5x,3f10.5)') (eigval(i),i=1,3)
3985 ! write (iout,'(i5,3f10.5)') i,(eigvec(i,j),j=1,3)
3987 ! Constructing the diagonalized matrix
3989 if (dabs(eigval(i)).gt.1.0d-15) then
3990 Id(i,i)=1.0d0/eigval(i)
3997 Imcp(i,j)=eigvec(j,i)
4003 pr1(i,j)=pr1(i,j)+Id(i,k)*Imcp(k,j)
4010 pr2(i,j)=pr2(i,j)+eigvec(i,k)*pr1(k,j)
4014 ! Calculating the total rotational velocity of the molecule
4017 vrot(i)=vrot(i)+pr2(i,j)*L(j)
4020 ! Resetting the velocities
4022 call vecpr(vrot(1),dc(1,i),vp)
4024 d_t(j,i)=d_t(j,i)-vp(j)
4029 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4030 .and.(mnum.ne.5)) then
4031 ! if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)) then
4032 ! if(itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
4034 call vecpr(vrot(1),dc(1,inres),vp)
4036 d_t(j,inres)=d_t(j,inres)-vp(j)
4041 ! write(iout,*) "The angular momentum after adjustment:"
4042 ! write(iout,*) (L(j),j=1,3)
4045 end subroutine inertia_tensor
4046 !-----------------------------------------------------------------------------
4047 subroutine angmom(cm,L)
4050 ! implicit real*8 (a-h,o-z)
4051 ! include 'DIMENSIONS'
4052 ! include 'COMMON.CONTROL'
4053 ! include 'COMMON.VAR'
4054 ! include 'COMMON.MD'
4055 ! include 'COMMON.CHAIN'
4056 ! include 'COMMON.DERIV'
4057 ! include 'COMMON.GEO'
4058 ! include 'COMMON.LOCAL'
4059 ! include 'COMMON.INTERACT'
4060 ! include 'COMMON.IOUNITS'
4061 ! include 'COMMON.NAMES'
4062 real(kind=8) :: mscab
4063 real(kind=8),dimension(3) :: L,cm,pr,vp,vrot,incr,v,pp
4064 integer :: iti,inres,i,j,mnum
4065 ! Calculate the angular momentum
4074 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
4076 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
4079 v(j)=incr(j)+0.5d0*d_t(j,i)
4082 incr(j)=incr(j)+d_t(j,i)
4084 call vecpr(pr(1),v(1),vp)
4086 L(j)=L(j)+mp(mnum)*vp(j)
4090 pp(j)=0.5d0*d_t(j,i)
4092 call vecpr(pr(1),pp(1),vp)
4094 L(j)=L(j)+Ip(mnum)*vp(j)
4102 iti=iabs(itype(i,mnum))
4110 pr(j)=c(j,inres)-cm(j)
4112 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4113 .and.(mnum.ne.5)) then
4115 v(j)=incr(j)+d_t(j,inres)
4122 call vecpr(pr(1),v(1),vp)
4123 ! write (iout,*) "i",i," iti",iti," pr",(pr(j),j=1,3),&
4124 ! " v",(v(j),j=1,3)," vp",(vp(j),j=1,3)
4126 L(j)=L(j)+mscab*vp(j)
4128 ! write (iout,*) "L",(l(j),j=1,3)
4129 if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4130 .and.(mnum.ne.5)) then
4132 v(j)=incr(j)+d_t(j,inres)
4134 call vecpr(dc(1,inres),d_t(1,inres),vp)
4136 L(j)=L(j)+Isc(iti,mnum)*vp(j)
4140 incr(j)=incr(j)+d_t(j,i)
4144 end subroutine angmom
4145 !-----------------------------------------------------------------------------
4146 subroutine vcm_vel(vcm)
4149 ! implicit real*8 (a-h,o-z)
4150 ! include 'DIMENSIONS'
4151 ! include 'COMMON.VAR'
4152 ! include 'COMMON.MD'
4153 ! include 'COMMON.CHAIN'
4154 ! include 'COMMON.DERIV'
4155 ! include 'COMMON.GEO'
4156 ! include 'COMMON.LOCAL'
4157 ! include 'COMMON.INTERACT'
4158 ! include 'COMMON.IOUNITS'
4159 real(kind=8),dimension(3) :: vcm,vv
4160 real(kind=8) :: summas,amas
4170 if (mnum.eq.5) mp(mnum)=msc(itype(i,mnum),mnum)
4172 summas=summas+mp(mnum)
4174 vcm(j)=vcm(j)+mp(mnum)*(vv(j)+0.5d0*d_t(j,i))
4178 amas=msc(iabs(itype(i,mnum)),mnum)
4183 if (itype(i,mnum).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4184 .and.(mnum.ne.5)) then
4186 vcm(j)=vcm(j)+amas*(vv(j)+d_t(j,i+nres))
4190 vcm(j)=vcm(j)+amas*vv(j)
4194 vv(j)=vv(j)+d_t(j,i)
4197 ! write (iout,*) "vcm",(vcm(j),j=1,3)," summas",summas
4199 vcm(j)=vcm(j)/summas
4202 end subroutine vcm_vel
4203 !-----------------------------------------------------------------------------
4205 !-----------------------------------------------------------------------------
4207 ! RATTLE algorithm for velocity Verlet - step 1, UNRES
4211 ! implicit real*8 (a-h,o-z)
4212 ! include 'DIMENSIONS'
4214 ! include 'COMMON.CONTROL'
4215 ! include 'COMMON.VAR'
4216 ! include 'COMMON.MD'
4218 ! include 'COMMON.LANGEVIN'
4220 ! include 'COMMON.LANGEVIN.lang0'
4222 ! include 'COMMON.CHAIN'
4223 ! include 'COMMON.DERIV'
4224 ! include 'COMMON.GEO'
4225 ! include 'COMMON.LOCAL'
4226 ! include 'COMMON.INTERACT'
4227 ! include 'COMMON.IOUNITS'
4228 ! include 'COMMON.NAMES'
4229 ! include 'COMMON.TIME1'
4230 !el real(kind=8) :: gginv(2*nres,2*nres),&
4231 !el gdc(3,2*nres,2*nres)
4232 real(kind=8) :: dC_uncor(3,2*nres) !,&
4233 !el real(kind=8) :: Cmat(2*nres,2*nres)
4234 real(kind=8) :: x(2*nres),xcorr(3,2*nres) !maxres2=2*maxres
4235 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4236 !el common /przechowalnia/ nbond
4237 integer :: max_rattle = 5
4238 logical :: lprn = .false., lprn1 = .false., not_done
4239 real(kind=8) :: tol_rattle = 1.0d-5
4241 integer :: ii,i,j,jj,l,ind,ind1,nres2
4244 !el /common/ przechowalnia
4246 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4247 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4248 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4250 if (lprn) write (iout,*) "RATTLE1"
4254 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4255 .and.(mnum.ne.5)) nbond=nbond+1
4257 ! Make a folded form of the Ginv-matrix
4270 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4275 if (itype(k,1).ne.10 .and. itype(k,mnum).ne.ntyp1_molec(mnum)&
4276 .and.(mnum.ne.5)) then
4280 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4288 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4299 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4303 if (itype(k,1).ne.10) then
4307 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
4315 write (iout,*) "Matrix GGinv"
4316 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4322 if (iter.gt.max_rattle) then
4323 write (iout,*) "Error - too many iterations in RATTLE."
4326 ! Calculate the matrix C = GG**(-1) dC_old o dC
4331 dC_uncor(j,ind1)=dC(j,i)
4335 if (itype(i,1).ne.10) then
4338 dC_uncor(j,ind1)=dC(j,i+nres)
4347 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4351 if (itype(k,1).ne.10) then
4354 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4359 ! Calculate deviations from standard virtual-bond lengths
4363 x(ind)=vbld(i+1)**2-vbl**2
4366 if (itype(i,1).ne.10) then
4368 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4372 write (iout,*) "Coordinates and violations"
4374 write(iout,'(i5,3f10.5,5x,e15.5)') &
4375 i,(dC_uncor(j,i),j=1,3),x(i)
4377 write (iout,*) "Velocities and violations"
4381 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4382 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4386 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4387 .and.(mnum.ne.5)) then
4390 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4391 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4392 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4395 ! write (iout,*) "gdc"
4397 ! write (iout,*) "i",i
4399 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4405 if (dabs(x(i)).gt.xmax) then
4409 if (xmax.lt.tol_rattle) then
4413 ! Calculate the matrix of the system of equations
4418 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4423 write (iout,*) "Matrix Cmat"
4424 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4426 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4427 ! Add constraint term to positions
4434 xx = xx+x(ii)*gdc(j,ind,ii)
4438 d_t_new(j,i)=d_t_new(j,i)-xx/d_time
4442 if (itype(i,1).ne.10) then
4447 xx = xx+x(ii)*gdc(j,ind,ii)
4450 dC(j,i+nres)=dC(j,i+nres)-xx
4451 d_t_new(j,i+nres)=d_t_new(j,i+nres)-xx/d_time
4455 ! Rebuild the chain using the new coordinates
4456 call chainbuild_cart
4458 write (iout,*) "New coordinates, Lagrange multipliers,",&
4459 " and differences between actual and standard bond lengths"
4463 xx=vbld(i+1)**2-vbl**2
4464 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4465 i,(dC(j,i),j=1,3),x(ind),xx
4469 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4472 xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4473 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4474 i,(dC(j,i+nres),j=1,3),x(ind),xx
4477 write (iout,*) "Velocities and violations"
4481 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4482 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4485 if (itype(i,1).ne.10) then
4487 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4488 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4489 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4496 10 write (iout,*) "Error - singularity in solving the system",&
4497 " of equations for Lagrange multipliers."
4501 "RATTLE inactive; use -DRATTLE switch at compile time."
4504 end subroutine rattle1
4505 !-----------------------------------------------------------------------------
4507 ! RATTLE algorithm for velocity Verlet - step 2, UNRES
4511 ! implicit real*8 (a-h,o-z)
4512 ! include 'DIMENSIONS'
4514 ! include 'COMMON.CONTROL'
4515 ! include 'COMMON.VAR'
4516 ! include 'COMMON.MD'
4518 ! include 'COMMON.LANGEVIN'
4520 ! include 'COMMON.LANGEVIN.lang0'
4522 ! include 'COMMON.CHAIN'
4523 ! include 'COMMON.DERIV'
4524 ! include 'COMMON.GEO'
4525 ! include 'COMMON.LOCAL'
4526 ! include 'COMMON.INTERACT'
4527 ! include 'COMMON.IOUNITS'
4528 ! include 'COMMON.NAMES'
4529 ! include 'COMMON.TIME1'
4530 !el real(kind=8) :: gginv(2*nres,2*nres),&
4531 !el gdc(3,2*nres,2*nres)
4532 real(kind=8) :: dC_uncor(3,2*nres) !,&
4533 !el Cmat(2*nres,2*nres)
4534 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4535 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4536 !el common /przechowalnia/ nbond
4537 integer :: max_rattle = 5
4538 logical :: lprn = .false., lprn1 = .false., not_done
4539 real(kind=8) :: tol_rattle = 1.0d-5
4543 !el /common/ przechowalnia
4544 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4545 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4546 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4548 if (lprn) write (iout,*) "RATTLE2"
4549 if (lprn) write (iout,*) "Velocity correction"
4550 ! Calculate the matrix G dC
4556 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k)
4561 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4562 .and.(mnum.ne.5)) then
4565 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k+nres)
4571 ! write (iout,*) "gdc"
4573 ! write (iout,*) "i",i
4575 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4579 ! Calculate the matrix of the system of equations
4586 Cmat(ind,j)=Cmat(ind,j)+dC(k,i)*gdc(k,ind,j)
4592 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4593 .and.(mnum.ne.5)) then
4598 Cmat(ind,j)=Cmat(ind,j)+dC(k,i+nres)*gdc(k,ind,j)
4603 ! Calculate the scalar product dC o d_t_new
4607 x(ind)=scalar(d_t(1,i),dC(1,i))
4611 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4612 .and.(mnum.ne.5)) then
4614 x(ind)=scalar(d_t(1,i+nres),dC(1,i+nres))
4618 write (iout,*) "Velocities and violations"
4622 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4623 i,ind,(d_t(j,i),j=1,3),x(ind)
4627 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4628 .and.(mnum.ne.5)) then
4630 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4631 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind)
4637 if (dabs(x(i)).gt.xmax) then
4641 if (xmax.lt.tol_rattle) then
4646 write (iout,*) "Matrix Cmat"
4647 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4649 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4650 ! Add constraint term to velocities
4657 xx = xx+x(ii)*gdc(j,ind,ii)
4659 d_t(j,i)=d_t(j,i)-xx
4664 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4665 .and.(mnum.ne.5)) then
4670 xx = xx+x(ii)*gdc(j,ind,ii)
4672 d_t(j,i+nres)=d_t(j,i+nres)-xx
4678 "New velocities, Lagrange multipliers violations"
4682 if (lprn) write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4683 i,ind,(d_t(j,i),j=1,3),x(ind),scalar(d_t(1,i),dC(1,i))
4687 if (itype(i,1).ne.10 .and. itype(i,mnum).ne.ntyp1_molec(mnum)&
4690 write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4691 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind),&
4692 scalar(d_t(1,i+nres),dC(1,i+nres))
4698 10 write (iout,*) "Error - singularity in solving the system",&
4699 " of equations for Lagrange multipliers."
4703 "RATTLE inactive; use -DRATTLE option at compile time."
4706 end subroutine rattle2
4707 !-----------------------------------------------------------------------------
4708 subroutine rattle_brown
4709 ! RATTLE/LINCS algorithm for Brownian dynamics, UNRES
4713 ! implicit real*8 (a-h,o-z)
4714 ! include 'DIMENSIONS'
4716 ! include 'COMMON.CONTROL'
4717 ! include 'COMMON.VAR'
4718 ! include 'COMMON.MD'
4720 ! include 'COMMON.LANGEVIN'
4722 ! include 'COMMON.LANGEVIN.lang0'
4724 ! include 'COMMON.CHAIN'
4725 ! include 'COMMON.DERIV'
4726 ! include 'COMMON.GEO'
4727 ! include 'COMMON.LOCAL'
4728 ! include 'COMMON.INTERACT'
4729 ! include 'COMMON.IOUNITS'
4730 ! include 'COMMON.NAMES'
4731 ! include 'COMMON.TIME1'
4732 !el real(kind=8) :: gginv(2*nres,2*nres),&
4733 !el gdc(3,2*nres,2*nres)
4734 real(kind=8) :: dC_uncor(3,2*nres) !,&
4735 !el real(kind=8) :: Cmat(2*nres,2*nres)
4736 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4737 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4738 !el common /przechowalnia/ nbond
4739 integer :: max_rattle = 5
4740 logical :: lprn = .false., lprn1 = .false., not_done
4741 real(kind=8) :: tol_rattle = 1.0d-5
4745 !el /common/ przechowalnia
4746 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4747 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4748 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4751 if (lprn) write (iout,*) "RATTLE_BROWN"
4754 if (itype(i,1).ne.10) nbond=nbond+1
4756 ! Make a folded form of the Ginv-matrix
4769 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4773 if (itype(k,1).ne.10) then
4777 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4784 if (itype(i,1).ne.10) then
4794 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4798 if (itype(k,1).ne.10) then
4802 if (j.eq.1 .and. l.eq.1)GGinv(ii,jj)=fricmat(ind,ind1)
4810 write (iout,*) "Matrix GGinv"
4811 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4817 if (iter.gt.max_rattle) then
4818 write (iout,*) "Error - too many iterations in RATTLE."
4821 ! Calculate the matrix C = GG**(-1) dC_old o dC
4826 dC_uncor(j,ind1)=dC(j,i)
4830 if (itype(i,1).ne.10) then
4833 dC_uncor(j,ind1)=dC(j,i+nres)
4842 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4846 if (itype(k,1).ne.10) then
4849 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4854 ! Calculate deviations from standard virtual-bond lengths
4858 x(ind)=vbld(i+1)**2-vbl**2
4861 if (itype(i,1).ne.10) then
4863 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4867 write (iout,*) "Coordinates and violations"
4869 write(iout,'(i5,3f10.5,5x,e15.5)') &
4870 i,(dC_uncor(j,i),j=1,3),x(i)
4872 write (iout,*) "Velocities and violations"
4876 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4877 i,ind,(d_t(j,i),j=1,3),scalar(d_t(1,i),dC_old(1,i))
4880 if (itype(i,1).ne.10) then
4882 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4883 i+nres,ind,(d_t(j,i+nres),j=1,3),&
4884 scalar(d_t(1,i+nres),dC_old(1,i+nres))
4887 write (iout,*) "gdc"
4889 write (iout,*) "i",i
4891 write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4897 if (dabs(x(i)).gt.xmax) then
4901 if (xmax.lt.tol_rattle) then
4905 ! Calculate the matrix of the system of equations
4910 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4915 write (iout,*) "Matrix Cmat"
4916 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4918 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4919 ! Add constraint term to positions
4926 xx = xx+x(ii)*gdc(j,ind,ii)
4929 d_t(j,i)=d_t(j,i)+xx/d_time
4934 if (itype(i,1).ne.10) then
4939 xx = xx+x(ii)*gdc(j,ind,ii)
4942 d_t(j,i+nres)=d_t(j,i+nres)+xx/d_time
4943 dC(j,i+nres)=dC(j,i+nres)+xx
4947 ! Rebuild the chain using the new coordinates
4948 call chainbuild_cart
4950 write (iout,*) "New coordinates, Lagrange multipliers,",&
4951 " and differences between actual and standard bond lengths"
4955 xx=vbld(i+1)**2-vbl**2
4956 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4957 i,(dC(j,i),j=1,3),x(ind),xx
4960 if (itype(i,1).ne.10) then
4962 xx=vbld(i+nres)**2-vbldsc0(1,itype(i,1))**2
4963 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4964 i,(dC(j,i+nres),j=1,3),x(ind),xx
4967 write (iout,*) "Velocities and violations"
4971 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4972 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4975 if (itype(i,1).ne.10) then
4977 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4978 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4979 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4986 10 write (iout,*) "Error - singularity in solving the system",&
4987 " of equations for Lagrange multipliers."
4991 "RATTLE inactive; use -DRATTLE option at compile time"
4994 end subroutine rattle_brown
4995 !-----------------------------------------------------------------------------
4997 !-----------------------------------------------------------------------------
4998 subroutine friction_force
5003 ! implicit real*8 (a-h,o-z)
5004 ! include 'DIMENSIONS'
5005 ! include 'COMMON.VAR'
5006 ! include 'COMMON.CHAIN'
5007 ! include 'COMMON.DERIV'
5008 ! include 'COMMON.GEO'
5009 ! include 'COMMON.LOCAL'
5010 ! include 'COMMON.INTERACT'
5011 ! include 'COMMON.MD'
5013 ! include 'COMMON.LANGEVIN'
5015 ! include 'COMMON.LANGEVIN.lang0'
5017 ! include 'COMMON.IOUNITS'
5018 !el real(kind=8),dimension(6*nres) :: gamvec !(MAXRES6) maxres6=6*maxres
5019 !el common /syfek/ gamvec
5020 real(kind=8) :: vv(3),vvtot(3,nres),v_work(6*nres) !,&
5021 !el ginvfric(2*nres,2*nres) !maxres2=2*maxres
5022 !el common /przechowalnia/ ginvfric
5024 logical :: lprn = .false., checkmode = .false.
5025 integer :: i,j,ind,k,nres2,nres6,mnum
5029 if(.not.allocated(gamvec)) allocate(gamvec(nres6)) !(MAXRES6)
5030 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
5038 d_t_work(j)=d_t(j,0)
5043 d_t_work(ind+j)=d_t(j,i)
5049 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5050 .and.(mnum.ne.5)) then
5052 d_t_work(ind+j)=d_t(j,i+nres)
5058 call fricmat_mult(d_t_work,fric_work)
5060 if (.not.checkmode) return
5063 write (iout,*) "d_t_work and fric_work"
5065 write (iout,'(i3,2e15.5)') i,d_t_work(i),fric_work(i)
5069 friction(j,0)=fric_work(j)
5074 friction(j,i)=fric_work(ind+j)
5080 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5081 .and.(mnum.ne.5)) then
5082 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5084 friction(j,i+nres)=fric_work(ind+j)
5090 write(iout,*) "Friction backbone"
5092 write(iout,'(i5,3e15.5,5x,3e15.5)') &
5093 i,(friction(j,i),j=1,3),(d_t(j,i),j=1,3)
5095 write(iout,*) "Friction side chain"
5097 write(iout,'(i5,3e15.5,5x,3e15.5)') &
5098 i,(friction(j,i+nres),j=1,3),(d_t(j,i+nres),j=1,3)
5107 vvtot(j,i)=vv(j)+0.5d0*d_t(j,i)
5108 vvtot(j,i+nres)=vv(j)+d_t(j,i+nres)
5109 vv(j)=vv(j)+d_t(j,i)
5112 write (iout,*) "vvtot backbone and sidechain"
5114 write (iout,'(i5,3e15.5,5x,3e15.5)') i,(vvtot(j,i),j=1,3),&
5115 (vvtot(j,i+nres),j=1,3)
5120 v_work(ind+j)=vvtot(j,i)
5126 v_work(ind+j)=vvtot(j,i+nres)
5130 write (iout,*) "v_work gamvec and site-based friction forces"
5132 write (iout,'(i5,3e15.5)') i,v_work(i),gamvec(i),&
5136 ! fric_work1(i)=0.0d0
5138 ! fric_work1(i)=fric_work1(i)-A(j,i)*gamvec(j)*v_work(j)
5141 ! write (iout,*) "fric_work and fric_work1"
5143 ! write (iout,'(i5,2e15.5)') i,fric_work(i),fric_work1(i)
5149 ginvfric(i,j)=ginvfric(i,j)+ginv(i,k)*fricmat(k,j)
5153 write (iout,*) "ginvfric"
5155 write (iout,'(i5,100f8.3)') i,(ginvfric(i,j),j=1,dimen)
5157 write (iout,*) "symmetry check"
5160 write (iout,*) i,j,ginvfric(i,j)-ginvfric(j,i)
5165 end subroutine friction_force
5166 !-----------------------------------------------------------------------------
5167 subroutine setup_fricmat
5171 use control_data, only:time_Bcast
5172 use control, only:tcpu
5174 ! implicit real*8 (a-h,o-z)
5178 real(kind=8) :: time00
5180 ! include 'DIMENSIONS'
5181 ! include 'COMMON.VAR'
5182 ! include 'COMMON.CHAIN'
5183 ! include 'COMMON.DERIV'
5184 ! include 'COMMON.GEO'
5185 ! include 'COMMON.LOCAL'
5186 ! include 'COMMON.INTERACT'
5187 ! include 'COMMON.MD'
5188 ! include 'COMMON.SETUP'
5189 ! include 'COMMON.TIME1'
5190 ! integer licznik /0/
5193 ! include 'COMMON.LANGEVIN'
5195 ! include 'COMMON.LANGEVIN.lang0'
5197 ! include 'COMMON.IOUNITS'
5199 integer :: i,j,ind,ind1,m
5200 logical :: lprn = .false.
5201 real(kind=8) :: dtdi !el ,gamvec(2*nres)
5202 !el real(kind=8),dimension(2*nres,2*nres) :: ginvfric,fcopy
5203 ! real(kind=8),allocatable,dimension(:,:) :: fcopy
5204 !el real(kind=8),dimension(2*nres*(2*nres+1)/2) :: Ghalf !(mmaxres2) (mmaxres2=(maxres2*(maxres2+1)/2))
5205 !el common /syfek/ gamvec
5206 real(kind=8) :: work(8*2*nres)
5207 integer :: iwork(2*nres)
5208 !el common /przechowalnia/ ginvfric,Ghalf,fcopy
5209 integer :: ii,iti,k,l,nzero,nres2,nres6,ierr,mnum
5213 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5214 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5215 if (fg_rank.ne.king) goto 10
5220 if(.not.allocated(gamvec)) allocate(gamvec(nres2)) !(MAXRES2)
5221 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
5222 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5223 !el allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
5224 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !maxres2=2*maxres
5226 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5227 ! Zeroing out fricmat
5233 ! Load the friction coefficients corresponding to peptide groups
5238 gamvec(ind1)=gamp(mnum)
5240 ! Load the friction coefficients corresponding to side chains
5244 gamsc(ntyp1_molec(j),j)=1.0d0
5251 gamvec(ii)=gamsc(iabs(iti),mnum)
5253 if (surfarea) call sdarea(gamvec)
5255 ! write (iout,*) "Matrix A and vector gamma"
5257 ! write (iout,'(i2,$)') i
5259 ! write (iout,'(f4.1,$)') A(i,j)
5261 ! write (iout,'(f8.3)') gamvec(i)
5265 write (iout,*) "Vector gamvec"
5267 write (iout,'(i5,f10.5)') i, gamvec(i)
5271 ! The friction matrix
5276 dtdi=dtdi+A(j,k)*A(j,i)*gamvec(j)
5283 write (iout,'(//a)') "Matrix fricmat"
5284 call matout2(dimen,dimen,nres2,nres2,fricmat)
5286 if (lang.eq.2 .or. lang.eq.3) then
5287 ! Mass-scale the friction matrix if non-direct integration will be performed
5293 Ginvfric(i,j)=Ginvfric(i,j)+ &
5294 Gsqrm(i,k)*Gsqrm(l,j)*fricmat(k,l)
5299 ! Diagonalize the friction matrix
5304 Ghalf(ind)=Ginvfric(i,j)
5307 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5310 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5311 " mass-scaled friction matrix"
5312 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5314 ! Precompute matrices for tinker stochastic integrator
5321 mt1(i,j)=mt1(i,j)+fricvec(k,i)*gsqrm(k,j)
5322 mt2(i,j)=mt2(i,j)+fricvec(k,i)*gsqrp(k,j)
5328 else if (lang.eq.4) then
5329 ! Diagonalize the friction matrix
5334 Ghalf(ind)=fricmat(i,j)
5337 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
5340 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
5342 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
5344 ! Determine the number of zero eigenvalues of the friction matrix
5345 nzero=max0(dimen-dimen1,0)
5346 ! do while (fricgam(nzero+1).le.1.0d-5 .and. nzero.lt.dimen)
5349 write (iout,*) "Number of zero eigenvalues:",nzero
5354 fricmat(i,j)=fricmat(i,j) &
5355 +fricvec(i,k)*fricvec(j,k)/fricgam(k)
5360 write (iout,'(//a)') "Generalized inverse of fricmat"
5361 call matout(dimen,dimen,nres6,nres6,fricmat)
5366 if (nfgtasks.gt.1) then
5367 if (fg_rank.eq.0) then
5368 ! The matching BROADCAST for fg processors is called in ERGASTULUM
5374 call MPI_Bcast(10,1,MPI_INTEGER,king,FG_COMM,IERROR)
5376 time_Bcast=time_Bcast+MPI_Wtime()-time00
5378 time_Bcast=time_Bcast+tcpu()-time00
5380 ! print *,"Processor",myrank,
5381 ! & " BROADCAST iorder in SETUP_FRICMAT"
5384 write (iout,*) "setup_fricmat licznik"!,licznik !sp
5390 ! Scatter the friction matrix
5391 call MPI_Scatterv(fricmat(1,1),nginv_counts(0),&
5392 nginv_start(0),MPI_DOUBLE_PRECISION,fcopy(1,1),&
5393 myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
5396 time_scatter=time_scatter+MPI_Wtime()-time00
5397 time_scatter_fmat=time_scatter_fmat+MPI_Wtime()-time00
5399 time_scatter=time_scatter+tcpu()-time00
5400 time_scatter_fmat=time_scatter_fmat+tcpu()-time00
5404 do j=1,2*my_ng_count
5405 fricmat(j,i)=fcopy(i,j)
5408 ! write (iout,*) "My chunk of fricmat"
5409 ! call MATOUT2(my_ng_count,dimen,maxres2,maxres2,fcopy)
5413 end subroutine setup_fricmat
5414 !-----------------------------------------------------------------------------
5415 subroutine stochastic_force(stochforcvec)
5418 use random, only:anorm_distr
5419 ! implicit real*8 (a-h,o-z)
5420 ! include 'DIMENSIONS'
5421 use control, only: tcpu
5426 ! include 'COMMON.VAR'
5427 ! include 'COMMON.CHAIN'
5428 ! include 'COMMON.DERIV'
5429 ! include 'COMMON.GEO'
5430 ! include 'COMMON.LOCAL'
5431 ! include 'COMMON.INTERACT'
5432 ! include 'COMMON.MD'
5433 ! include 'COMMON.TIME1'
5435 ! include 'COMMON.LANGEVIN'
5437 ! include 'COMMON.LANGEVIN.lang0'
5439 ! include 'COMMON.IOUNITS'
5441 real(kind=8) :: x,sig,lowb,highb
5442 real(kind=8) :: ff(3),force(3,0:2*nres),zeta2,lowb2
5443 real(kind=8) :: highb2,sig2,forcvec(6*nres),stochforcvec(6*nres)
5444 real(kind=8) :: time00
5445 logical :: lprn = .false.
5446 integer :: i,j,ind,mnum
5450 stochforc(j,i)=0.0d0
5460 ! Compute the stochastic forces acting on bodies. Store in force.
5466 force(j,i)=anorm_distr(x,sig,lowb,highb)
5474 force(j,i+nres)=anorm_distr(x,sig2,lowb2,highb2)
5478 time_fsample=time_fsample+MPI_Wtime()-time00
5480 time_fsample=time_fsample+tcpu()-time00
5482 ! Compute the stochastic forces acting on virtual-bond vectors.
5488 stochforc(j,i)=ff(j)+0.5d0*force(j,i)
5491 ff(j)=ff(j)+force(j,i)
5493 ! if (itype(i+1,1).ne.ntyp1) then
5495 if (itype(i+1,mnum).ne.ntyp1_molec(mnum)) then
5497 stochforc(j,i)=stochforc(j,i)+force(j,i+nres+1)
5498 ff(j)=ff(j)+force(j,i+nres+1)
5503 stochforc(j,0)=ff(j)+force(j,nnt+nres)
5507 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5508 .and.(mnum.ne.5)) then
5509 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5511 stochforc(j,i+nres)=force(j,i+nres)
5517 stochforcvec(j)=stochforc(j,0)
5522 stochforcvec(ind+j)=stochforc(j,i)
5528 if ((itype(i,1).ne.10).and.(itype(i,mnum).ne.ntyp1_molec(mnum))&
5529 .and.(mnum.ne.5)) then
5530 ! if ((itype(i,1).ne.10).and.(itype(i,1).ne.ntyp1)) then
5532 stochforcvec(ind+j)=stochforc(j,i+nres)
5538 write (iout,*) "stochforcvec"
5540 write(iout,'(i5,e15.5)') i,stochforcvec(i)
5542 write(iout,*) "Stochastic forces backbone"
5544 write(iout,'(i5,3e15.5)') i,(stochforc(j,i),j=1,3)
5546 write(iout,*) "Stochastic forces side chain"
5548 write(iout,'(i5,3e15.5)') &
5549 i,(stochforc(j,i+nres),j=1,3)
5557 write (iout,*) i,ind
5559 forcvec(ind+j)=force(j,i)
5564 write (iout,*) i,ind
5566 forcvec(j+ind)=force(j,i+nres)
5571 write (iout,*) "forcvec"
5575 write (iout,'(2i3,2f10.5)') i,j,force(j,i),&
5582 write (iout,'(2i3,2f10.5)') i,j,force(j,i+nres),&
5591 end subroutine stochastic_force
5592 !-----------------------------------------------------------------------------
5593 subroutine sdarea(gamvec)
5595 ! Scale the friction coefficients according to solvent accessible surface areas
5596 ! Code adapted from TINKER
5600 ! implicit real*8 (a-h,o-z)
5601 ! include 'DIMENSIONS'
5602 ! include 'COMMON.CONTROL'
5603 ! include 'COMMON.VAR'
5604 ! include 'COMMON.MD'
5606 ! include 'COMMON.LANGEVIN'
5608 ! include 'COMMON.LANGEVIN.lang0'
5610 ! include 'COMMON.CHAIN'
5611 ! include 'COMMON.DERIV'
5612 ! include 'COMMON.GEO'
5613 ! include 'COMMON.LOCAL'
5614 ! include 'COMMON.INTERACT'
5615 ! include 'COMMON.IOUNITS'
5616 ! include 'COMMON.NAMES'
5617 real(kind=8),dimension(2*nres) :: radius,gamvec !(maxres2)
5618 real(kind=8),parameter :: twosix = 1.122462048309372981d0
5619 logical :: lprn = .false.
5620 real(kind=8) :: probe,area,ratio
5621 integer :: i,j,ind,iti,mnum
5623 ! determine new friction coefficients every few SD steps
5625 ! set the atomic radii to estimates of sigma values
5627 ! print *,"Entered sdarea"
5633 ! Load peptide group radii
5636 radius(i)=pstok(mnum)
5638 ! Load side chain radii
5642 radius(i+nres)=restok(iti,mnum)
5645 ! write (iout,*) "i",i," radius",radius(i)
5648 radius(i) = radius(i) / twosix
5649 if (radius(i) .ne. 0.0d0) radius(i) = radius(i) + probe
5652 ! scale atomic friction coefficients by accessible area
5654 if (lprn) write (iout,*) &
5655 "Original gammas, surface areas, scaling factors, new gammas, ",&
5656 "std's of stochastic forces"
5659 if (radius(i).gt.0.0d0) then
5660 call surfatom (i,area,radius)
5661 ratio = dmax1(area/(4.0d0*pi*radius(i)**2),1.0d-1)
5662 if (lprn) write (iout,'(i5,3f10.5,$)') &
5663 i,gamvec(ind+1),area,ratio
5666 gamvec(ind) = ratio * gamvec(ind)
5669 stdforcp(i)=stdfp(mnum)*dsqrt(gamvec(ind))
5670 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcp(i)
5674 if (radius(i+nres).gt.0.0d0) then
5675 call surfatom (i+nres,area,radius)
5676 ratio = dmax1(area/(4.0d0*pi*radius(i+nres)**2),1.0d-1)
5677 if (lprn) write (iout,'(i5,3f10.5,$)') &
5678 i,gamvec(ind+1),area,ratio
5681 gamvec(ind) = ratio * gamvec(ind)
5684 stdforcsc(i)=stdfsc(itype(i,mnum),mnum)*dsqrt(gamvec(ind))
5685 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcsc(i)
5690 end subroutine sdarea
5691 !-----------------------------------------------------------------------------
5693 !-----------------------------------------------------------------------------
5696 ! ###################################################
5697 ! ## COPYRIGHT (C) 1996 by Jay William Ponder ##
5698 ! ## All Rights Reserved ##
5699 ! ###################################################
5701 ! ################################################################
5703 ! ## subroutine surfatom -- exposed surface area of an atom ##
5705 ! ################################################################
5708 ! "surfatom" performs an analytical computation of the surface
5709 ! area of a specified atom; a simplified version of "surface"
5711 ! literature references:
5713 ! T. J. Richmond, "Solvent Accessible Surface Area and
5714 ! Excluded Volume in Proteins", Journal of Molecular Biology,
5717 ! L. Wesson and D. Eisenberg, "Atomic Solvation Parameters
5718 ! Applied to Molecular Dynamics of Proteins in Solution",
5719 ! Protein Science, 1, 227-235 (1992)
5721 ! variables and parameters:
5723 ! ir number of atom for which area is desired
5724 ! area accessible surface area of the atom
5725 ! radius radii of each of the individual atoms
5728 subroutine surfatom(ir,area,radius)
5730 ! implicit real*8 (a-h,o-z)
5731 ! include 'DIMENSIONS'
5733 ! include 'COMMON.GEO'
5734 ! include 'COMMON.IOUNITS'
5736 integer :: nsup,nstart_sup
5737 ! double precision c,dc,dc_old,d_c_work,xloc,xrot,dc_norm
5738 ! common /chain/ c(3,maxres2+2),dc(3,0:maxres2),dc_old(3,0:maxres2),
5739 ! & xloc(3,maxres),xrot(3,maxres),dc_norm(3,0:maxres2),
5740 ! & dc_work(MAXRES6),nres,nres0
5741 integer,parameter :: maxarc=300
5745 integer :: mi,ni,narc
5746 integer :: key(maxarc)
5747 integer :: intag(maxarc)
5748 integer :: intag1(maxarc)
5749 real(kind=8) :: area,arcsum
5750 real(kind=8) :: arclen,exang
5751 real(kind=8) :: delta,delta2
5752 real(kind=8) :: eps,rmove
5753 real(kind=8) :: xr,yr,zr
5754 real(kind=8) :: rr,rrsq
5755 real(kind=8) :: rplus,rminus
5756 real(kind=8) :: axx,axy,axz
5757 real(kind=8) :: ayx,ayy
5758 real(kind=8) :: azx,azy,azz
5759 real(kind=8) :: uxj,uyj,uzj
5760 real(kind=8) :: tx,ty,tz
5761 real(kind=8) :: txb,tyb,td
5762 real(kind=8) :: tr2,tr,txr,tyr
5763 real(kind=8) :: tk1,tk2
5764 real(kind=8) :: thec,the,t,tb
5765 real(kind=8) :: txk,tyk,tzk
5766 real(kind=8) :: t1,ti,tf,tt
5767 real(kind=8) :: txj,tyj,tzj
5768 real(kind=8) :: ccsq,cc,xysq
5769 real(kind=8) :: bsqk,bk,cosine
5770 real(kind=8) :: dsqj,gi,pix2
5771 real(kind=8) :: therk,dk,gk
5772 real(kind=8) :: risqk,rik
5773 real(kind=8) :: radius(2*nres) !(maxatm) (maxatm=maxres2)
5774 real(kind=8) :: ri(maxarc),risq(maxarc)
5775 real(kind=8) :: ux(maxarc),uy(maxarc),uz(maxarc)
5776 real(kind=8) :: xc(maxarc),yc(maxarc),zc(maxarc)
5777 real(kind=8) :: xc1(maxarc),yc1(maxarc),zc1(maxarc)
5778 real(kind=8) :: dsq(maxarc),bsq(maxarc)
5779 real(kind=8) :: dsq1(maxarc),bsq1(maxarc)
5780 real(kind=8) :: arci(maxarc),arcf(maxarc)
5781 real(kind=8) :: ex(maxarc),lt(maxarc),gr(maxarc)
5782 real(kind=8) :: b(maxarc),b1(maxarc),bg(maxarc)
5783 real(kind=8) :: kent(maxarc),kout(maxarc)
5784 real(kind=8) :: ther(maxarc)
5785 logical :: moved,top
5786 logical :: omit(maxarc)
5789 ! maxatm = 2*nres !maxres2 maxres2=2*maxres
5790 ! maxlight = 8*maxatm
5793 ! maxtors = 4*maxatm
5795 ! zero out the surface area for the sphere of interest
5798 ! write (2,*) "ir",ir," radius",radius(ir)
5799 if (radius(ir) .eq. 0.0d0) return
5801 ! set the overlap significance and connectivity shift
5805 delta2 = delta * delta
5810 ! store coordinates and radius of the sphere of interest
5818 ! initialize values of some counters and summations
5827 ! test each sphere to see if it overlaps the sphere of interest
5830 if (i.eq.ir .or. radius(i).eq.0.0d0) goto 30
5831 rplus = rr + radius(i)
5833 if (abs(tx) .ge. rplus) goto 30
5835 if (abs(ty) .ge. rplus) goto 30
5837 if (abs(tz) .ge. rplus) goto 30
5839 ! check for sphere overlap by testing distance against radii
5841 xysq = tx*tx + ty*ty
5842 if (xysq .lt. delta2) then
5849 if (rplus-cc .le. delta) goto 30
5850 rminus = rr - radius(i)
5852 ! check to see if sphere of interest is completely buried
5854 if (cc-abs(rminus) .le. delta) then
5855 if (rminus .le. 0.0d0) goto 170
5859 ! check for too many overlaps with sphere of interest
5861 if (io .ge. maxarc) then
5863 20 format (/,' SURFATOM -- Increase the Value of MAXARC')
5867 ! get overlap between current sphere and sphere of interest
5876 gr(io) = (ccsq+rplus*rminus) / (2.0d0*rr*b1(io))
5882 ! case where no other spheres overlap the sphere of interest
5885 area = 4.0d0 * pi * rrsq
5889 ! case where only one sphere overlaps the sphere of interest
5892 area = pix2 * (1.0d0 + gr(1))
5893 area = mod(area,4.0d0*pi) * rrsq
5897 ! case where many spheres intersect the sphere of interest;
5898 ! sort the intersecting spheres by their degree of overlap
5900 call sort2 (io,gr,key)
5903 intag(i) = intag1(k)
5912 ! get radius of each overlap circle on surface of the sphere
5917 risq(i) = rrsq - gi*gi
5918 ri(i) = sqrt(risq(i))
5919 ther(i) = 0.5d0*pi - asin(min(1.0d0,max(-1.0d0,gr(i))))
5922 ! find boundary of inaccessible area on sphere of interest
5925 if (.not. omit(k)) then
5932 ! check to see if J circle is intersecting K circle;
5933 ! get distance between circle centers and sum of radii
5936 if (omit(j)) goto 60
5937 cc = (txk*xc(j)+tyk*yc(j)+tzk*zc(j))/(bk*b(j))
5938 cc = acos(min(1.0d0,max(-1.0d0,cc)))
5939 td = therk + ther(j)
5941 ! check to see if circles enclose separate regions
5943 if (cc .ge. td) goto 60
5945 ! check for circle J completely inside circle K
5947 if (cc+ther(j) .lt. therk) goto 40
5949 ! check for circles that are essentially parallel
5951 if (cc .gt. delta) goto 50
5956 ! check to see if sphere of interest is completely buried
5959 if (pix2-cc .le. td) goto 170
5965 ! find T value of circle intersections
5968 if (omit(k)) goto 110
5983 ! rotation matrix elements
5995 if (.not. omit(j)) then
6000 ! rotate spheres so K vector colinear with z-axis
6002 uxj = txj*axx + tyj*axy - tzj*axz
6003 uyj = tyj*ayy - txj*ayx
6004 uzj = txj*azx + tyj*azy + tzj*azz
6005 cosine = min(1.0d0,max(-1.0d0,uzj/b(j)))
6006 if (acos(cosine) .lt. therk+ther(j)) then
6007 dsqj = uxj*uxj + uyj*uyj
6012 tr2 = risqk*dsqj - tb*tb
6018 ! get T values of intersection for K circle
6021 tb = min(1.0d0,max(-1.0d0,tb))
6023 if (tyb-txr .lt. 0.0d0) tk1 = pix2 - tk1
6025 tb = min(1.0d0,max(-1.0d0,tb))
6027 if (tyb+txr .lt. 0.0d0) tk2 = pix2 - tk2
6028 thec = (rrsq*uzj-gk*bg(j)) / (rik*ri(j)*b(j))
6029 if (abs(thec) .lt. 1.0d0) then
6031 else if (thec .ge. 1.0d0) then
6033 else if (thec .le. -1.0d0) then
6037 ! see if "tk1" is entry or exit point; check t=0 point;
6038 ! "ti" is exit point, "tf" is entry point
6040 cosine = min(1.0d0,max(-1.0d0, &
6041 (uzj*gk-uxj*rik)/(b(j)*rr)))
6042 if ((acos(cosine)-ther(j))*(tk2-tk1) .le. 0.0d0) then
6050 if (narc .ge. maxarc) then
6052 70 format (/,' SURFATOM -- Increase the Value',&
6056 if (tf .le. ti) then
6077 ! special case; K circle without intersections
6079 if (narc .le. 0) goto 90
6081 ! general case; sum up arclength and set connectivity code
6083 call sort2 (narc,arci,key)
6088 if (narc .gt. 1) then
6091 if (t .lt. arci(j)) then
6092 arcsum = arcsum + arci(j) - t
6093 exang = exang + ex(ni)
6095 if (jb .ge. maxarc) then
6097 80 format (/,' SURFATOM -- Increase the Value',&
6102 kent(jb) = maxarc*i + k
6104 kout(jb) = maxarc*k + i
6113 arcsum = arcsum + pix2 - t
6115 exang = exang + ex(ni)
6118 kent(jb) = maxarc*i + k
6120 kout(jb) = maxarc*k + i
6127 arclen = arclen + gr(k)*arcsum
6130 if (arclen .eq. 0.0d0) goto 170
6131 if (jb .eq. 0) goto 150
6133 ! find number of independent boundaries and check connectivity
6137 if (kout(k) .ne. 0) then
6144 if (m .eq. kent(ii)) then
6147 if (j .eq. jb) goto 150
6159 ! attempt to fix connectivity error by moving atom slightly
6163 140 format (/,' SURFATOM -- Connectivity Error at Atom',i6)
6172 ! compute the exposed surface area for the sphere of interest
6175 area = ib*pix2 + exang + arclen
6176 area = mod(area,4.0d0*pi) * rrsq
6178 ! attempt to fix negative area by moving atom slightly
6180 if (area .lt. 0.0d0) then
6183 160 format (/,' SURFATOM -- Negative Area at Atom',i6)
6194 end subroutine surfatom
6195 !----------------------------------------------------------------
6196 !----------------------------------------------------------------
6197 subroutine alloc_MD_arrays
6198 !EL Allocation of arrays used by MD module
6200 integer :: nres2,nres6
6203 !----------------------
6207 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
6208 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
6209 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
6210 allocate(fricvec(nres2,nres2))
6211 allocate(pfric_mat(nres2,nres2),vfric_mat(nres2,nres2))
6212 allocate(afric_mat(nres2,nres2),prand_mat(nres2,nres2))
6213 allocate(vrand_mat1(nres2,nres2),vrand_mat2(nres2,nres2)) !(MAXRES2,MAXRES2)
6214 allocate(pfric0_mat(nres2,nres2,0:maxflag_stoch))
6215 allocate(afric0_mat(nres2,nres2,0:maxflag_stoch))
6216 allocate(vfric0_mat(nres2,nres2,0:maxflag_stoch))
6217 allocate(prand0_mat(nres2,nres2,0:maxflag_stoch))
6218 allocate(vrand0_mat1(nres2,nres2,0:maxflag_stoch))
6219 allocate(vrand0_mat2(nres2,nres2,0:maxflag_stoch)) !(MAXRES2,MAXRES2,0:maxflag_stoch)
6220 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
6222 allocate(mt1(nres2,nres2),mt2(nres2,nres2),mt3(nres2,nres2)) !(maxres2,maxres2)
6223 !----------------------
6225 ! commom.langevin.lang0
6227 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
6228 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
6229 allocate(fricvec(nres2,nres2)) !(MAXRES2,MAXRES2)
6230 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
6231 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
6234 if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2))
6235 !----------------------
6236 ! commom.hairpin in CSA module
6237 !----------------------
6238 ! common.mce in MCM_MD module
6239 !----------------------
6241 ! common /mdgrad/ in module.energy
6242 ! common /back_constr/ in module.energy
6243 ! common /qmeas/ in module.energy
6246 allocate(potEcomp(0:n_ene+4)) !(0:n_ene+4)
6248 allocate(d_t(3,0:nres2),d_a(3,0:nres2),d_t_old(3,0:nres2)) !(3,0:MAXRES2)
6249 allocate(d_a_work(nres6)) !(6*MAXRES)
6251 allocate(DM(nres2),DU1(nres2),DU2(nres2))
6252 allocate(DMorig(nres2),DU1orig(nres2),DU2orig(nres2))
6254 write (iout,*) "Before A Allocation",nfgtasks-1
6256 allocate(Gmat(nres2,nres2),A(nres2,nres2))
6257 if(.not.allocated(Ginv)) allocate(Ginv(nres2,nres2)) !in control: ergastulum
6258 allocate(Gsqrp(nres2,nres2),Gsqrm(nres2,nres2),Gvec(nres2,nres2)) !(maxres2,maxres2)
6260 allocate(Geigen(nres2)) !(maxres2)
6261 if(.not.allocated(vtot)) allocate(vtot(nres2)) !(maxres2)
6262 ! common /inertia/ in io_conf: parmread
6263 ! real(kind=8),dimension(:),allocatable :: ISC,msc !(ntyp+1)
6264 ! common /langevin/in io read_MDpar
6265 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
6266 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
6267 ! in io_conf: parmread
6268 ! real(kind=8),dimension(:),allocatable :: restok !(ntyp+1)
6269 ! common /mdpmpi/ in control: ergastulum
6270 if(.not.allocated(ng_start)) allocate(ng_start(0:nfgtasks-1))
6271 if(.not.allocated(ng_counts)) allocate(ng_counts(0:nfgtasks-1))
6272 if(.not.allocated(nginv_counts)) allocate(nginv_counts(0:nfgtasks-1)) !(0:MaxProcs-1)
6273 if(.not.allocated(nginv_start)) allocate(nginv_start(0:nfgtasks)) !(0:MaxProcs)
6274 !----------------------
6275 ! common.muca in read_muca
6276 ! common /double_muca/
6277 ! real(kind=8) :: elow,ehigh,factor,hbin,factor_min
6278 ! real(kind=8),dimension(:),allocatable :: emuca,nemuca,&
6279 ! nemuca2,hist !(4*maxres)
6280 ! common /integer_muca/
6281 ! integer :: nmuca,imtime,muca_smooth
6283 ! real(kind=8),dimension(:),allocatable :: elowi,ehighi !(maxprocs)
6284 !----------------------
6286 ! common /mdgrad/ in module.energy
6287 ! common /back_constr/ in module.energy
6288 ! common /qmeas/ in module.energy
6292 allocate(d_t_work(nres6),d_t_work_new(nres6),d_af_work(nres6))
6293 allocate(d_as_work(nres6),kinetic_force(nres6)) !(MAXRES6)
6294 allocate(d_t_new(3,0:nres2),d_a_old(3,0:nres2),d_a_short(3,0:nres2)) !,d_a !(3,0:MAXRES2)
6295 allocate(stdforcp(nres),stdforcsc(nres)) !(MAXRES)
6296 !----------------------
6298 allocate(D_ban(nres6)) !(MAXRES6) maxres6=6*maxres
6299 ! common /stochcalc/ stochforcvec
6300 allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
6301 !----------------------
6303 end subroutine alloc_MD_arrays
6304 !-----------------------------------------------------------------------------
6305 !-----------------------------------------------------------------------------