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)
29 real(kind=8),dimension(:),allocatable :: stdforcp,stdforcsc !(MAXRES)
30 !-----------------------------------------------------------------------------
34 ! ###################################################
35 ! ## COPYRIGHT (C) 1992 by Jay William Ponder ##
36 ! ## All Rights Reserved ##
37 ! ###################################################
39 ! #############################################################
41 ! ## sizes.i -- parameter values to set array dimensions ##
43 ! #############################################################
46 ! "sizes.i" sets values for critical array dimensions used
47 ! throughout the software; these parameters will fix the size
48 ! of the largest systems that can be handled; values too large
49 ! for the computer's memory and/or swap space to accomodate
50 ! will result in poor performance or outright failure
52 ! parameter: maximum allowed number of:
54 ! maxatm atoms in the molecular system
55 ! maxval atoms directly bonded to an atom
56 ! maxgrp ! user-defined groups of atoms
57 ! maxtyp force field atom type definitions
58 ! maxclass force field atom class definitions
59 ! maxkey lines in the keyword file
60 ! maxrot bonds for torsional rotation
61 ! maxvar optimization variables (vector storage)
62 ! maxopt optimization variables (matrix storage)
63 ! maxhess off-diagonal Hessian elements
64 ! maxlight sites for method of lights neighbors
65 ! maxvib vibrational frequencies
66 ! maxgeo distance geometry points
67 ! maxcell unit cells in replicated crystal
68 ! maxring 3-, 4-, or 5-membered rings
69 ! maxfix geometric restraints
70 ! maxbio biopolymer atom definitions
71 ! maxres residues in the macromolecule
72 ! maxamino amino acid residue types
73 ! maxnuc nucleic acid residue types
74 ! maxbnd covalent bonds in molecular system
75 ! maxang bond angles in molecular system
76 ! maxtors torsional angles in molecular system
77 ! maxpi atoms in conjugated pisystem
78 ! maxpib covalent bonds involving pisystem
79 ! maxpit torsional angles involving pisystem
82 !el integer maxatm,maxval,maxgrp
83 !el integer maxtyp,maxclass,maxkey
84 !el integer maxrot,maxopt
85 !el integer maxhess,maxlight,maxvib
86 !el integer maxgeo,maxcell,maxring
87 !el integer maxfix,maxbio
88 !el integer maxamino,maxnuc,maxbnd
89 !el integer maxang,maxtors,maxpi
90 !el integer maxpib,maxpit
91 integer :: maxatm !=2*nres !maxres2 maxres2=2*maxres
92 integer,parameter :: maxval=8
93 integer,parameter :: maxgrp=1000
94 integer,parameter :: maxtyp=3000
95 integer,parameter :: maxclass=500
96 integer,parameter :: maxkey=10000
97 integer,parameter :: maxrot=1000
98 integer,parameter :: maxopt=1000
99 integer,parameter :: maxhess=1000000
100 integer :: maxlight !=8*maxatm
101 integer,parameter :: maxvib=1000
102 integer,parameter :: maxgeo=1000
103 integer,parameter :: maxcell=10000
104 integer,parameter :: maxring=10000
105 integer,parameter :: maxfix=10000
106 integer,parameter :: maxbio=10000
107 integer,parameter :: maxamino=31
108 integer,parameter :: maxnuc=12
109 integer :: maxbnd !=2*maxatm
110 integer :: maxang !=3*maxatm
111 integer :: maxtors !=4*maxatm
112 integer,parameter :: maxpi=100
113 integer,parameter :: maxpib=2*maxpi
114 integer,parameter :: maxpit=4*maxpi
115 !-----------------------------------------------------------------------------
116 ! Maximum number of seed
117 integer,parameter :: max_seed=1
118 !-----------------------------------------------------------------------------
119 real(kind=8),dimension(:),allocatable :: stochforcvec !(MAXRES6) maxres6=6*maxres
120 ! common /stochcalc/ stochforcvec
121 !-----------------------------------------------------------------------------
122 ! common /przechowalnia/ subroutines: rattle1,rattle2,rattle_brown
123 real(kind=8),dimension(:,:),allocatable :: GGinv !(2*nres,2*nres) maxres2=2*maxres
124 real(kind=8),dimension(:,:,:),allocatable :: gdc !(3,2*nres,2*nres) maxres2=2*maxres
125 real(kind=8),dimension(:,:),allocatable :: Cmat !(2*nres,2*nres) maxres2=2*maxres
126 !-----------------------------------------------------------------------------
127 ! common /syfek/ subroutines: friction_force,setup_fricmat
128 !el real(kind=8),dimension(:),allocatable :: gamvec !(MAXRES6) or (MAXRES2)
129 !-----------------------------------------------------------------------------
130 ! common /przechowalnia/ subroutines: friction_force,setup_fricmat
131 real(kind=8),dimension(:,:),allocatable :: ginvfric !(2*nres,2*nres) !maxres2=2*maxres
132 !-----------------------------------------------------------------------------
133 ! common /przechowalnia/ subroutine: setup_fricmat
134 !el real(kind=8),dimension(:,:),allocatable :: fcopy !(2*nres,2*nres)
135 !-----------------------------------------------------------------------------
138 !-----------------------------------------------------------------------------
140 !-----------------------------------------------------------------------------
142 !-----------------------------------------------------------------------------
143 subroutine brown_step(itime)
144 !------------------------------------------------
145 ! Perform a single Euler integration step of Brownian dynamics
146 !------------------------------------------------
147 ! implicit real*8 (a-h,o-z)
149 use control, only: tcpu
152 ! include 'DIMENSIONS'
156 ! include 'COMMON.CONTROL'
157 ! include 'COMMON.VAR'
158 ! include 'COMMON.MD'
160 ! include 'COMMON.LANGEVIN'
162 ! include 'COMMON.LANGEVIN.lang0'
164 ! include 'COMMON.CHAIN'
165 ! include 'COMMON.DERIV'
166 ! include 'COMMON.GEO'
167 ! include 'COMMON.LOCAL'
168 ! include 'COMMON.INTERACT'
169 ! include 'COMMON.IOUNITS'
170 ! include 'COMMON.NAMES'
171 ! include 'COMMON.TIME1'
172 real(kind=8),dimension(6*nres) :: zapas !(MAXRES6) maxres6=6*maxres
173 integer :: rstcount !ilen,
175 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
176 real(kind=8),dimension(6*nres,2*nres) :: Bmat,GBmat,Tmat !(MAXRES6,MAXRES2) (maxres2=2*maxres,maxres6=6*maxres)
177 real(kind=8),dimension(2*nres,2*nres) :: Cmat_,Cinv !(maxres2,maxres2) maxres2=2*maxres
178 real(kind=8),dimension(6*nres,6*nres) :: Pmat !(maxres6,maxres6) maxres6=6*maxres
179 real(kind=8),dimension(6*nres) :: Td !(maxres6) maxres6=6*maxres
180 real(kind=8),dimension(2*nres) :: ppvec !(maxres2) maxres2=2*maxres
181 !el common /stochcalc/ stochforcvec
182 !el real(kind=8),dimension(3) :: cm !el
183 !el common /gucio/ cm
185 logical :: lprn = .false.,lprn1 = .false.
186 integer :: maxiter = 5
187 real(kind=8) :: difftol = 1.0d-5
188 real(kind=8) :: xx,diffmax,blen2,diffbond,tt0
189 integer :: i,j,nbond,k,ind,ind1,iter
190 integer :: nres2,nres6
195 if (.not.allocated(stochforcvec)) allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
199 if (itype(i).ne.10) nbond=nbond+1
203 write (iout,*) "Generalized inverse of fricmat"
204 call matout(dimen,dimen,nres6,nres6,fricmat)
216 Bmat(ind+j,ind1)=dC_norm(j,i)
221 if (itype(i).ne.10) then
224 Bmat(ind+j,ind1)=dC_norm(j,i+nres)
230 write (iout,*) "Matrix Bmat"
231 call MATOUT(nbond,dimen,nres6,nres6,Bmat)
237 GBmat(i,j)=GBmat(i,j)+fricmat(i,k)*Bmat(k,j)
242 write (iout,*) "Matrix GBmat"
243 call MATOUT(nbond,dimen,nres6,nres2,Gbmat)
249 Cmat_(i,j)=Cmat_(i,j)+Bmat(k,i)*GBmat(k,j)
254 write (iout,*) "Matrix Cmat"
255 call MATOUT(nbond,nbond,nres2,nres2,Cmat_)
257 call matinvert(nbond,nres2,Cmat_,Cinv,osob)
259 write (iout,*) "Matrix Cinv"
260 call MATOUT(nbond,nbond,nres2,nres2,Cinv)
266 Tmat(i,j)=Tmat(i,j)+GBmat(i,k)*Cinv(k,j)
271 write (iout,*) "Matrix Tmat"
272 call MATOUT(nbond,dimen,nres6,nres2,Tmat)
282 Pmat(i,j)=Pmat(i,j)-Tmat(i,k)*Bmat(j,k)
287 write (iout,*) "Matrix Pmat"
288 call MATOUT(dimen,dimen,nres6,nres6,Pmat)
295 Td(i)=Td(i)+vbl*Tmat(i,ind)
298 if (itype(k).ne.10) then
300 Td(i)=Td(i)+vbldsc0(1,itype(k))*Tmat(i,ind)
305 write (iout,*) "Vector Td"
307 write (iout,'(i5,f10.5)') i,Td(i)
310 call stochastic_force(stochforcvec)
312 write (iout,*) "stochforcvec"
314 write (iout,*) i,stochforcvec(i)
318 zapas(j)=-gcart(j,0)+stochforcvec(j)
320 dC_work(j)=dC_old(j,0)
326 zapas(ind)=-gcart(j,i)+stochforcvec(ind)
327 dC_work(ind)=dC_old(j,i)
331 if (itype(i).ne.10) then
334 zapas(ind)=-gxcart(j,i)+stochforcvec(ind)
335 dC_work(ind)=dC_old(j,i+nres)
341 write (iout,*) "Initial d_t_work"
343 write (iout,*) i,d_t_work(i)
350 d_t_work(i)=d_t_work(i)+fricmat(i,j)*zapas(j)
357 zapas(i)=zapas(i)+Pmat(i,j)*(dC_work(j)+d_t_work(j)*d_time)
361 write (iout,*) "Final d_t_work and zapas"
363 write (iout,*) i,d_t_work(i),zapas(i)
377 dc_work(ind+j)=dc(j,i)
383 d_t(j,i+nres)=d_t_work(ind+j)
384 dc(j,i+nres)=zapas(ind+j)
385 dc_work(ind+j)=dc(j,i+nres)
391 write (iout,*) "Before correction for rotational lengthening"
392 write (iout,*) "New coordinates",&
393 " and differences between actual and standard bond lengths"
398 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
402 if (itype(i).ne.10) then
404 xx=vbld(i+nres)-vbldsc0(1,itype(i))
405 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
406 i,(dC(j,i+nres),j=1,3),xx
410 ! Second correction (rotational lengthening)
416 blen2 = scalar(dc(1,i),dc(1,i))
417 ppvec(ind)=2*vbl**2-blen2
418 diffbond=dabs(vbl-dsqrt(blen2))
419 if (diffbond.gt.diffmax) diffmax=diffbond
420 if (ppvec(ind).gt.0.0d0) then
421 ppvec(ind)=dsqrt(ppvec(ind))
426 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
430 if (itype(i).ne.10) then
432 blen2 = scalar(dc(1,i+nres),dc(1,i+nres))
433 ppvec(ind)=2*vbldsc0(1,itype(i))**2-blen2
434 diffbond=dabs(vbldsc0(1,itype(i))-dsqrt(blen2))
435 if (diffbond.gt.diffmax) diffmax=diffbond
436 if (ppvec(ind).gt.0.0d0) then
437 ppvec(ind)=dsqrt(ppvec(ind))
442 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
446 if (lprn) write (iout,*) "iter",iter," diffmax",diffmax
447 if (diffmax.lt.difftol) goto 10
451 Td(i)=Td(i)+ppvec(j)*Tmat(i,j)
457 zapas(i)=zapas(i)+Pmat(i,j)*dc_work(j)
468 dc_work(ind+j)=zapas(ind+j)
473 if (itype(i).ne.10) then
475 dc(j,i+nres)=zapas(ind+j)
476 dc_work(ind+j)=zapas(ind+j)
481 ! Building the chain from the newly calculated coordinates
484 if (large.and. mod(itime,ntwe).eq.0) then
485 write (iout,*) "Cartesian and internal coordinates: step 1"
488 write (iout,'(a)') "Potential forces"
490 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(-gcart(j,i),j=1,3),&
493 write (iout,'(a)') "Stochastic forces"
495 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(stochforc(j,i),j=1,3),&
496 (stochforc(j,i+nres),j=1,3)
498 write (iout,'(a)') "Velocities"
500 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
501 (d_t(j,i+nres),j=1,3)
506 write (iout,*) "After correction for rotational lengthening"
507 write (iout,*) "New coordinates",&
508 " and differences between actual and standard bond lengths"
513 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
517 if (itype(i).ne.10) then
519 xx=vbld(i+nres)-vbldsc0(1,itype(i))
520 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
521 i,(dC(j,i+nres),j=1,3),xx
526 ! write (iout,*) "Too many attempts at correcting the bonds"
534 ! Calculate energy and forces
536 call etotal(potEcomp)
537 potE=potEcomp(0)-potEcomp(20)
540 ! Calculate the kinetic and total energy and the kinetic temperature
543 t_enegrad=t_enegrad+MPI_Wtime()-tt0
545 t_enegrad=t_enegrad+tcpu()-tt0
548 kinetic_T=2.0d0/(dimen*Rb)*EK
550 end subroutine brown_step
551 !-----------------------------------------------------------------------------
553 !-----------------------------------------------------------------------------
554 subroutine gauss(RO,AP,MT,M,N,*)
556 ! CALCULATES (RO**(-1))*AP BY GAUSS ELIMINATION
557 ! RO IS A SQUARE MATRIX
558 ! THE CALCULATED PRODUCT IS STORED IN AP
559 ! ABNORMAL EXIT IF RO IS SINGULAR
561 integer :: MT, M, N, M1,I,J,IM,&
563 real(kind=8) :: RO(MT,M),AP(MT,N),X,RM,PR,Y
569 if(dabs(X).le.1.0D-13) return 1
581 if(DABS(RO(J,I)).LE.RM) goto 2
595 if(dabs(X).le.1.0E-13) return 1
604 8 AP(J,K)=AP(J,K)-Y*AP(I,K)
606 9 RO(J,K)=RO(J,K)-Y*RO(I,K)
610 if(dabs(X).le.1.0E-13) return 1
620 15 X=X-AP(K,J)*RO(MI,K)
625 !-----------------------------------------------------------------------------
627 !-----------------------------------------------------------------------------
628 subroutine kinetic(KE_total)
629 !----------------------------------------------------------------
630 ! This subroutine calculates the total kinetic energy of the chain
631 !-----------------------------------------------------------------
633 ! implicit real*8 (a-h,o-z)
634 ! include 'DIMENSIONS'
635 ! include 'COMMON.VAR'
636 ! include 'COMMON.CHAIN'
637 ! include 'COMMON.DERIV'
638 ! include 'COMMON.GEO'
639 ! include 'COMMON.LOCAL'
640 ! include 'COMMON.INTERACT'
641 ! include 'COMMON.MD'
642 ! include 'COMMON.IOUNITS'
643 real(kind=8) :: KE_total
646 real(kind=8) :: KEt_p,KEt_sc,KEr_p,KEr_sc,incr(3),&
651 ! write (iout,*) "ISC",(isc(itype(i)),i=1,nres)
652 ! The translational part for peptide virtual bonds
657 ! write (iout,*) "Kinetic trp:",i,(incr(j),j=1,3)
659 v(j)=incr(j)+0.5d0*d_t(j,i)
661 vtot(i)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
662 KEt_p=KEt_p+(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))
664 incr(j)=incr(j)+d_t(j,i)
667 ! write(iout,*) 'KEt_p', KEt_p
668 ! The translational part for the side chain virtual bond
669 ! Only now we can initialize incr with zeros. It must be equal
670 ! to the velocities of the first Calpha.
676 if (itype(i).eq.10) then
682 v(j)=incr(j)+d_t(j,nres+i)
685 ! write (iout,*) "Kinetic trsc:",i,(incr(j),j=1,3)
686 ! write (iout,*) "i",i," msc",msc(iti)," v",(v(j),j=1,3)
687 KEt_sc=KEt_sc+msc(iti)*(v(1)*v(1)+v(2)*v(2)+v(3)*v(3))
688 vtot(i+nres)=v(1)*v(1)+v(2)*v(2)+v(3)*v(3)
690 incr(j)=incr(j)+d_t(j,i)
694 ! write(iout,*) 'KEt_sc', KEt_sc
695 ! The part due to stretching and rotation of the peptide groups
698 ! write (iout,*) "i",i
699 ! write (iout,*) "i",i," mag1",mag1," mag2",mag2
703 ! write (iout,*) "Kinetic rotp:",i,(incr(j),j=1,3)
704 KEr_p=KEr_p+(incr(1)*incr(1)+incr(2)*incr(2) &
708 ! write(iout,*) 'KEr_p', KEr_p
709 ! The rotational part of the side chain virtual bond
713 if (itype(i).ne.10) then
715 incr(j)=d_t(j,nres+i)
717 ! write (iout,*) "Kinetic rotsc:",i,(incr(j),j=1,3)
718 KEr_sc=KEr_sc+Isc(iti)*(incr(1)*incr(1)+incr(2)*incr(2)+ &
722 ! The total kinetic energy
724 ! write(iout,*) 'KEr_sc', KEr_sc
725 KE_total=0.5d0*(mp*KEt_p+KEt_sc+0.25d0*Ip*KEr_p+KEr_sc)
726 ! write (iout,*) "KE_total",KE_total
728 end subroutine kinetic
729 !-----------------------------------------------------------------------------
731 !-----------------------------------------------------------------------------
733 !------------------------------------------------
734 ! The driver for molecular dynamics subroutines
735 !------------------------------------------------
737 use control, only:tcpu,ovrtim
739 use compare, only:secondary2,hairpin
740 use io, only:cartout,statout
741 ! implicit real*8 (a-h,o-z)
742 ! include 'DIMENSIONS'
745 integer :: IERROR,ERRCODE
747 ! include 'COMMON.SETUP'
748 ! include 'COMMON.CONTROL'
749 ! include 'COMMON.VAR'
750 ! include 'COMMON.MD'
752 ! include 'COMMON.LANGEVIN'
754 ! include 'COMMON.LANGEVIN.lang0'
756 ! include 'COMMON.CHAIN'
757 ! include 'COMMON.DERIV'
758 ! include 'COMMON.GEO'
759 ! include 'COMMON.LOCAL'
760 ! include 'COMMON.INTERACT'
761 ! include 'COMMON.IOUNITS'
762 ! include 'COMMON.NAMES'
763 ! include 'COMMON.TIME1'
764 ! include 'COMMON.HAIRPIN'
765 real(kind=8),dimension(3) :: L,vcm
767 real(kind=8),dimension(6*nres) :: v_work,v_transf !(maxres6) maxres6=6*maxres
769 integer :: rstcount !ilen,
771 character(len=50) :: tytul
772 !el common /gucio/ cm
773 integer :: itime,i,j,nharp
774 integer,dimension(4,nres/3) :: iharp !(4,nres/3)(4,maxres/3)
776 real(kind=8) :: tt0,scalfac
781 if (ilen(tmpdir).gt.0) &
782 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_" &
783 //liczba(:ilen(liczba))//'.rst')
785 if (ilen(tmpdir).gt.0) &
786 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_"//'.rst')
793 write (iout,'(20(1h=),a20,20(1h=))') "MD calculation started"
799 ! Determine the inverse of the inertia matrix.
800 call setup_MD_matrices
804 t_MDsetup = MPI_Wtime()-tt0
806 t_MDsetup = tcpu()-tt0
809 ! Entering the MD loop
815 if (lang.eq.2 .or. lang.eq.3) then
819 call sd_verlet_p_setup
821 call sd_verlet_ciccotti_setup
825 pfric0_mat(i,j,0)=pfric_mat(i,j)
826 afric0_mat(i,j,0)=afric_mat(i,j)
827 vfric0_mat(i,j,0)=vfric_mat(i,j)
828 prand0_mat(i,j,0)=prand_mat(i,j)
829 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
830 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
835 flag_stoch(i)=.false.
839 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
841 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
845 else if (lang.eq.1 .or. lang.eq.4) then
849 t_langsetup=MPI_Wtime()-tt0
852 t_langsetup=tcpu()-tt0
855 do itime=1,n_timestep
857 if (large.and. mod(itime,ntwe).eq.0) &
858 write (iout,*) "itime",itime
860 if (lang.gt.0 .and. surfarea .and. &
861 mod(itime,reset_fricmat).eq.0) then
862 if (lang.eq.2 .or. lang.eq.3) then
866 call sd_verlet_p_setup
868 call sd_verlet_ciccotti_setup
872 pfric0_mat(i,j,0)=pfric_mat(i,j)
873 afric0_mat(i,j,0)=afric_mat(i,j)
874 vfric0_mat(i,j,0)=vfric_mat(i,j)
875 prand0_mat(i,j,0)=prand_mat(i,j)
876 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
877 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
882 flag_stoch(i)=.false.
885 else if (lang.eq.1 .or. lang.eq.4) then
888 write (iout,'(a,i10)') &
889 "Friction matrix reset based on surface area, itime",itime
891 if (reset_vel .and. tbf .and. lang.eq.0 &
892 .and. mod(itime,count_reset_vel).eq.0) then
894 write(iout,'(a,f20.2)') &
895 "Velocities reset to random values, time",totT
898 d_t_old(j,i)=d_t(j,i)
902 if (reset_moment .and. mod(itime,count_reset_moment).eq.0) then
906 d_t(j,0)=d_t(j,0)-vcm(j)
909 kinetic_T=2.0d0/(dimen3*Rb)*EK
910 scalfac=dsqrt(T_bath/kinetic_T)
911 write(iout,'(a,f20.2)') "Momenta zeroed out, time",totT
914 d_t_old(j,i)=scalfac*d_t(j,i)
920 ! Time-reversible RESPA algorithm
921 ! (Tuckerman et al., J. Chem. Phys., 97, 1990, 1992)
922 call RESPA_step(itime)
924 ! Variable time step algorithm.
925 call velverlet_step(itime)
929 call brown_step(itime)
931 print *,"Brown dynamics not here!"
933 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
939 if (mod(itime,ntwe).eq.0) call statout(itime)
952 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
955 v_work(ind)=d_t(j,i+nres)
960 write (66,'(80f10.5)') &
961 ((d_t(j,i),j=1,3),i=0,nres-1),((d_t(j,i+nres),j=1,3),i=1,nres)
965 v_transf(i)=v_transf(i)+gvec(j,i)*v_work(j)
967 v_transf(i)= v_transf(i)*dsqrt(geigen(i))
969 write (67,'(80f10.5)') (v_transf(i),i=1,ind)
972 if (mod(itime,ntwx).eq.0) then
973 write (tytul,'("time",f8.2)') totT
975 call hairpin(.true.,nharp,iharp)
976 call secondary2(.true.)
977 call pdbout(potE,tytul,ipdb)
982 if (rstcount.eq.1000.or.itime.eq.n_timestep) then
983 open(irest2,file=rest2name,status='unknown')
984 write(irest2,*) totT,EK,potE,totE,t_bath
986 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
989 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
1001 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))') &
1003 'MD calculations setup:',t_MDsetup,&
1004 'Energy & gradient evaluation:',t_enegrad,&
1005 'Stochastic MD setup:',t_langsetup,&
1006 'Stochastic MD step setup:',t_sdsetup,&
1008 write (iout,'(/28(1h=),a25,27(1h=))') &
1009 ' End of MD calculation '
1011 write (iout,*) "time for etotal",t_etotal," elong",t_elong,&
1013 write (iout,*) "time_fric",time_fric," time_stoch",time_stoch,&
1014 " time_fricmatmult",time_fricmatmult," time_fsample ",&
1019 !-----------------------------------------------------------------------------
1020 subroutine velverlet_step(itime)
1021 !-------------------------------------------------------------------------------
1022 ! Perform a single velocity Verlet step; the time step can be rescaled if
1023 ! increments in accelerations exceed the threshold
1024 !-------------------------------------------------------------------------------
1025 ! implicit real*8 (a-h,o-z)
1026 ! include 'DIMENSIONS'
1028 use control, only:tcpu
1032 integer :: ierror,ierrcode
1033 real(kind=8) :: errcode
1035 ! include 'COMMON.SETUP'
1036 ! include 'COMMON.VAR'
1037 ! include 'COMMON.MD'
1039 ! include 'COMMON.LANGEVIN'
1041 ! include 'COMMON.LANGEVIN.lang0'
1043 ! include 'COMMON.CHAIN'
1044 ! include 'COMMON.DERIV'
1045 ! include 'COMMON.GEO'
1046 ! include 'COMMON.LOCAL'
1047 ! include 'COMMON.INTERACT'
1048 ! include 'COMMON.IOUNITS'
1049 ! include 'COMMON.NAMES'
1050 ! include 'COMMON.TIME1'
1051 ! include 'COMMON.MUCA'
1052 real(kind=8),dimension(3) :: vcm,incr
1053 real(kind=8),dimension(3) :: L
1054 integer :: count,rstcount !ilen,
1056 character(len=50) :: tytul
1057 integer :: maxcount_scale = 20
1058 !el common /gucio/ cm
1059 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1060 !el common /stochcalc/ stochforcvec
1061 integer :: itime,icount_scale,itime_scal,i,j,ifac_time
1063 real(kind=8) :: epdrift,tt0,fac_time
1065 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1071 else if (lang.eq.2 .or. lang.eq.3) then
1073 call stochastic_force(stochforcvec)
1076 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1078 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1085 icount_scale=icount_scale+1
1086 if (icount_scale.gt.maxcount_scale) then
1088 "ERROR: too many attempts at scaling down the time step. ",&
1089 "amax=",amax,"epdrift=",epdrift,&
1090 "damax=",damax,"edriftmax=",edriftmax,&
1094 call MPI_Abort(MPI_COMM_WORLD,IERROR,IERRCODE)
1098 ! First step of the velocity Verlet algorithm
1103 else if (lang.eq.3) then
1105 call sd_verlet1_ciccotti
1107 else if (lang.eq.1) then
1112 ! Build the chain from the newly calculated coordinates
1113 call chainbuild_cart
1114 if (rattle) call rattle1
1116 if (large.and. mod(itime,ntwe).eq.0) then
1117 write (iout,*) "Cartesian and internal coordinates: step 1"
1122 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
1123 (dc(j,i+nres),j=1,3)
1125 write (iout,*) "Accelerations"
1127 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1128 (d_a(j,i+nres),j=1,3)
1130 write (iout,*) "Velocities, step 1"
1132 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1133 (d_t(j,i+nres),j=1,3)
1142 ! Calculate energy and forces
1144 call etotal(potEcomp)
1145 if (large.and. mod(itime,ntwe).eq.0) &
1146 call enerprint(potEcomp)
1149 t_etotal=t_etotal+MPI_Wtime()-tt0
1151 t_etotal=t_etotal+tcpu()-tt0
1154 potE=potEcomp(0)-potEcomp(20)
1156 ! Get the new accelerations
1159 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1161 t_enegrad=t_enegrad+tcpu()-tt0
1163 ! Determine maximum acceleration and scale down the timestep if needed
1165 amax=amax/(itime_scal+1)**2
1166 call predict_edrift(epdrift)
1167 if (amax/(itime_scal+1).gt.damax .or. epdrift.gt.edriftmax) then
1168 ! Maximum acceleration or maximum predicted energy drift exceeded, rescale the time step
1170 ifac_time=dmax1(dlog(amax/damax),dlog(epdrift/edriftmax)) &
1172 itime_scal=itime_scal+ifac_time
1173 ! fac_time=dmin1(damax/amax,0.5d0)
1174 fac_time=0.5d0**ifac_time
1175 d_time=d_time*fac_time
1176 if (lang.eq.2 .or. lang.eq.3) then
1178 ! write (iout,*) "Calling sd_verlet_setup: 1"
1179 ! Rescale the stochastic forces and recalculate or restore
1180 ! the matrices of tinker integrator
1181 if (itime_scal.gt.maxflag_stoch) then
1182 if (large) write (iout,'(a,i5,a)') &
1183 "Calculate matrices for stochastic step;",&
1184 " itime_scal ",itime_scal
1186 call sd_verlet_p_setup
1188 call sd_verlet_ciccotti_setup
1190 write (iout,'(2a,i3,a,i3,1h.)') &
1191 "Warning: cannot store matrices for stochastic",&
1192 " integration because the index",itime_scal,&
1193 " is greater than",maxflag_stoch
1194 write (iout,'(2a)')"Increase MAXFLAG_STOCH or use direct",&
1195 " integration Langevin algorithm for better efficiency."
1196 else if (flag_stoch(itime_scal)) then
1197 if (large) write (iout,'(a,i5,a,l1)') &
1198 "Restore matrices for stochastic step; itime_scal ",&
1199 itime_scal," flag ",flag_stoch(itime_scal)
1202 pfric_mat(i,j)=pfric0_mat(i,j,itime_scal)
1203 afric_mat(i,j)=afric0_mat(i,j,itime_scal)
1204 vfric_mat(i,j)=vfric0_mat(i,j,itime_scal)
1205 prand_mat(i,j)=prand0_mat(i,j,itime_scal)
1206 vrand_mat1(i,j)=vrand0_mat1(i,j,itime_scal)
1207 vrand_mat2(i,j)=vrand0_mat2(i,j,itime_scal)
1211 if (large) write (iout,'(2a,i5,a,l1)') &
1212 "Calculate & store matrices for stochastic step;",&
1213 " itime_scal ",itime_scal," flag ",flag_stoch(itime_scal)
1215 call sd_verlet_p_setup
1217 call sd_verlet_ciccotti_setup
1219 flag_stoch(ifac_time)=.true.
1222 pfric0_mat(i,j,itime_scal)=pfric_mat(i,j)
1223 afric0_mat(i,j,itime_scal)=afric_mat(i,j)
1224 vfric0_mat(i,j,itime_scal)=vfric_mat(i,j)
1225 prand0_mat(i,j,itime_scal)=prand_mat(i,j)
1226 vrand0_mat1(i,j,itime_scal)=vrand_mat1(i,j)
1227 vrand0_mat2(i,j,itime_scal)=vrand_mat2(i,j)
1231 fac_time=1.0d0/dsqrt(fac_time)
1233 stochforcvec(i)=fac_time*stochforcvec(i)
1236 else if (lang.eq.1) then
1237 ! Rescale the accelerations due to stochastic forces
1238 fac_time=1.0d0/dsqrt(fac_time)
1240 d_as_work(i)=d_as_work(i)*fac_time
1243 if (large) write (iout,'(a,i10,a,f8.6,a,i3,a,i3)') &
1244 "itime",itime," Timestep scaled down to ",&
1245 d_time," ifac_time",ifac_time," itime_scal",itime_scal
1247 ! Second step of the velocity Verlet algorithm
1252 else if (lang.eq.3) then
1254 call sd_verlet2_ciccotti
1256 else if (lang.eq.1) then
1261 if (rattle) call rattle2
1263 if (d_time.ne.d_time0) then
1266 if (lang.eq.2 .or. lang.eq.3) then
1267 if (large) write (iout,'(a)') &
1268 "Restore original matrices for stochastic step"
1269 ! write (iout,*) "Calling sd_verlet_setup: 2"
1270 ! Restore the matrices of tinker integrator if the time step has been restored
1273 pfric_mat(i,j)=pfric0_mat(i,j,0)
1274 afric_mat(i,j)=afric0_mat(i,j,0)
1275 vfric_mat(i,j)=vfric0_mat(i,j,0)
1276 prand_mat(i,j)=prand0_mat(i,j,0)
1277 vrand_mat1(i,j)=vrand0_mat1(i,j,0)
1278 vrand_mat2(i,j)=vrand0_mat2(i,j,0)
1287 ! Calculate the kinetic and the total energy and the kinetic temperature
1291 ! call kinetic1(EK1)
1292 ! write (iout,*) "step",itime," EK",EK," EK1",EK1
1294 ! Couple the system to Berendsen bath if needed
1295 if (tbf .and. lang.eq.0) then
1298 kinetic_T=2.0d0/(dimen3*Rb)*EK
1299 ! Backup the coordinates, velocities, and accelerations
1303 d_t_old(j,i)=d_t(j,i)
1304 d_a_old(j,i)=d_a(j,i)
1308 if (mod(itime,ntwe).eq.0 .and. large) then
1309 write (iout,*) "Velocities, step 2"
1311 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1312 (d_t(j,i+nres),j=1,3)
1317 end subroutine velverlet_step
1318 !-----------------------------------------------------------------------------
1319 subroutine RESPA_step(itime)
1320 !-------------------------------------------------------------------------------
1321 ! Perform a single RESPA step.
1322 !-------------------------------------------------------------------------------
1323 ! implicit real*8 (a-h,o-z)
1324 ! include 'DIMENSIONS'
1327 use control, only:tcpu
1331 integer :: IERROR,ERRCODE
1333 ! include 'COMMON.SETUP'
1334 ! include 'COMMON.CONTROL'
1335 ! include 'COMMON.VAR'
1336 ! include 'COMMON.MD'
1338 ! include 'COMMON.LANGEVIN'
1340 ! include 'COMMON.LANGEVIN.lang0'
1342 ! include 'COMMON.CHAIN'
1343 ! include 'COMMON.DERIV'
1344 ! include 'COMMON.GEO'
1345 ! include 'COMMON.LOCAL'
1346 ! include 'COMMON.INTERACT'
1347 ! include 'COMMON.IOUNITS'
1348 ! include 'COMMON.NAMES'
1349 ! include 'COMMON.TIME1'
1350 real(kind=8),dimension(0:n_ene) :: energia_short,energia_long
1351 real(kind=8),dimension(3) :: L,vcm,incr
1352 real(kind=8),dimension(3,0:2*nres) :: dc_old0,d_t_old0,d_a_old0 !(3,0:maxres2) maxres2=2*maxres
1353 logical :: PRINT_AMTS_MSG = .false.
1354 integer :: count,rstcount !ilen,
1356 character(len=50) :: tytul
1357 integer :: maxcount_scale = 10
1358 !el common /gucio/ cm
1359 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1360 !el common /stochcalc/ stochforcvec
1361 integer :: itime,itt,i,j,itsplit
1363 !el common /cipiszcze/ itt
1365 real(kind=8) :: epdrift,tt0,epdriftmax
1368 if (.not.allocated(stochforcvec)) allocate(stochforcvec(6*nres)) !(MAXRES6) maxres6=6*maxres
1372 if (large.and. mod(itime,ntwe).eq.0) then
1373 write (iout,*) "***************** RESPA itime",itime
1374 write (iout,*) "Cartesian and internal coordinates: step 0"
1376 call pdbout(0.0d0,"cipiszcze",iout)
1378 write (iout,*) "Accelerations from long-range forces"
1380 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1381 (d_a(j,i+nres),j=1,3)
1383 write (iout,*) "Velocities, step 0"
1385 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1386 (d_t(j,i+nres),j=1,3)
1391 ! Perform the initial RESPA step (increment velocities)
1392 ! write (iout,*) "*********************** RESPA ini"
1395 if (mod(itime,ntwe).eq.0 .and. large) then
1396 write (iout,*) "Velocities, end"
1398 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1399 (d_t(j,i+nres),j=1,3)
1403 ! Compute the short-range forces
1409 ! 7/2/2009 commented out
1411 ! call etotal_short(energia_short)
1414 ! 7/2/2009 Copy accelerations due to short-lange forces from previous MD step
1417 d_a(j,i)=d_a_short(j,i)
1421 if (large.and. mod(itime,ntwe).eq.0) then
1422 write (iout,*) "energia_short",energia_short(0)
1423 write (iout,*) "Accelerations from short-range forces"
1425 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1426 (d_a(j,i+nres),j=1,3)
1431 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1433 t_enegrad=t_enegrad+tcpu()-tt0
1438 d_t_old(j,i)=d_t(j,i)
1439 d_a_old(j,i)=d_a(j,i)
1442 ! 6/30/08 A-MTS: attempt at increasing the split number
1445 dc_old0(j,i)=dc_old(j,i)
1446 d_t_old0(j,i)=d_t_old(j,i)
1447 d_a_old0(j,i)=d_a_old(j,i)
1450 if (ntime_split.gt.ntime_split0) ntime_split=ntime_split/2
1451 if (ntime_split.lt.ntime_split0) ntime_split=ntime_split0
1458 ! write (iout,*) "itime",itime," ntime_split",ntime_split
1459 ! Split the time step
1460 d_time=d_time0/ntime_split
1461 ! Perform the short-range RESPA steps (velocity Verlet increments of
1462 ! positions and velocities using short-range forces)
1463 ! write (iout,*) "*********************** RESPA split"
1464 do itsplit=1,ntime_split
1467 else if (lang.eq.2 .or. lang.eq.3) then
1469 call stochastic_force(stochforcvec)
1472 "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
1474 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
1479 ! First step of the velocity Verlet algorithm
1484 else if (lang.eq.3) then
1486 call sd_verlet1_ciccotti
1488 else if (lang.eq.1) then
1493 ! Build the chain from the newly calculated coordinates
1494 call chainbuild_cart
1495 if (rattle) call rattle1
1497 if (large.and. mod(itime,ntwe).eq.0) then
1498 write (iout,*) "***** ITSPLIT",itsplit
1499 write (iout,*) "Cartesian and internal coordinates: step 1"
1500 call pdbout(0.0d0,"cipiszcze",iout)
1503 write (iout,*) "Velocities, step 1"
1505 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1506 (d_t(j,i+nres),j=1,3)
1515 ! Calculate energy and forces
1517 call etotal_short(energia_short)
1518 if (large.and. mod(itime,ntwe).eq.0) &
1519 call enerprint(energia_short)
1522 t_eshort=t_eshort+MPI_Wtime()-tt0
1524 t_eshort=t_eshort+tcpu()-tt0
1528 ! Get the new accelerations
1530 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
1533 d_a_short(j,i)=d_a(j,i)
1537 if (large.and. mod(itime,ntwe).eq.0) then
1538 write (iout,*)"energia_short",energia_short(0)
1539 write (iout,*) "Accelerations from short-range forces"
1541 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1542 (d_a(j,i+nres),j=1,3)
1547 ! Determine maximum acceleration and scale down the timestep if needed
1549 amax=amax/ntime_split**2
1550 call predict_edrift(epdrift)
1551 if (ntwe.gt.0 .and. large .and. mod(itime,ntwe).eq.0) &
1552 write (iout,*) "amax",amax," damax",damax,&
1553 " epdrift",epdrift," epdriftmax",epdriftmax
1554 ! Exit loop and try with increased split number if the change of
1555 ! acceleration is too big
1556 if (amax.gt.damax .or. epdrift.gt.edriftmax) then
1557 if (ntime_split.lt.maxtime_split) then
1559 ntime_split=ntime_split*2
1562 dc_old(j,i)=dc_old0(j,i)
1563 d_t_old(j,i)=d_t_old0(j,i)
1564 d_a_old(j,i)=d_a_old0(j,i)
1567 if (PRINT_AMTS_MSG) then
1568 write (iout,*) "acceleration/energy drift too large",amax,&
1569 epdrift," split increased to ",ntime_split," itime",itime,&
1575 "Uh-hu. Bumpy landscape. Maximum splitting number",&
1577 " already reached!!! Trying to carry on!"
1581 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1583 t_enegrad=t_enegrad+tcpu()-tt0
1585 ! Second step of the velocity Verlet algorithm
1590 else if (lang.eq.3) then
1592 call sd_verlet2_ciccotti
1594 else if (lang.eq.1) then
1599 if (rattle) call rattle2
1600 ! Backup the coordinates, velocities, and accelerations
1604 d_t_old(j,i)=d_t(j,i)
1605 d_a_old(j,i)=d_a(j,i)
1612 ! Restore the time step
1614 ! Compute long-range forces
1621 call etotal_long(energia_long)
1622 if (large.and. mod(itime,ntwe).eq.0) &
1623 call enerprint(energia_long)
1626 t_elong=t_elong+MPI_Wtime()-tt0
1628 t_elong=t_elong+tcpu()-tt0
1634 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1636 t_enegrad=t_enegrad+tcpu()-tt0
1638 ! Compute accelerations from long-range forces
1640 if (large.and. mod(itime,ntwe).eq.0) then
1641 write (iout,*) "energia_long",energia_long(0)
1642 write (iout,*) "Cartesian and internal coordinates: step 2"
1644 call pdbout(0.0d0,"cipiszcze",iout)
1646 write (iout,*) "Accelerations from long-range forces"
1648 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
1649 (d_a(j,i+nres),j=1,3)
1651 write (iout,*) "Velocities, step 2"
1653 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1654 (d_t(j,i+nres),j=1,3)
1658 ! Compute the final RESPA step (increment velocities)
1659 ! write (iout,*) "*********************** RESPA fin"
1661 ! Compute the complete potential energy
1663 potEcomp(i)=energia_short(i)+energia_long(i)
1665 potE=potEcomp(0)-potEcomp(20)
1666 ! potE=energia_short(0)+energia_long(0)
1668 ! Calculate the kinetic and the total energy and the kinetic temperature
1671 ! Couple the system to Berendsen bath if needed
1672 if (tbf .and. lang.eq.0) then
1675 kinetic_T=2.0d0/(dimen3*Rb)*EK
1676 ! Backup the coordinates, velocities, and accelerations
1678 if (mod(itime,ntwe).eq.0 .and. large) then
1679 write (iout,*) "Velocities, end"
1681 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
1682 (d_t(j,i+nres),j=1,3)
1687 end subroutine RESPA_step
1688 !-----------------------------------------------------------------------------
1689 subroutine RESPA_vel
1690 ! First and last RESPA step (incrementing velocities using long-range
1693 ! implicit real*8 (a-h,o-z)
1694 ! include 'DIMENSIONS'
1695 ! include 'COMMON.CONTROL'
1696 ! include 'COMMON.VAR'
1697 ! include 'COMMON.MD'
1698 ! include 'COMMON.CHAIN'
1699 ! include 'COMMON.DERIV'
1700 ! include 'COMMON.GEO'
1701 ! include 'COMMON.LOCAL'
1702 ! include 'COMMON.INTERACT'
1703 ! include 'COMMON.IOUNITS'
1704 ! include 'COMMON.NAMES'
1705 integer :: i,j,inres
1708 d_t(j,0)=d_t(j,0)+0.5d0*d_a(j,0)*d_time
1712 d_t(j,i)=d_t(j,i)+0.5d0*d_a(j,i)*d_time
1716 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1719 d_t(j,inres)=d_t(j,inres)+0.5d0*d_a(j,inres)*d_time
1724 end subroutine RESPA_vel
1725 !-----------------------------------------------------------------------------
1727 ! Applying velocity Verlet algorithm - step 1 to coordinates
1729 ! implicit real*8 (a-h,o-z)
1730 ! include 'DIMENSIONS'
1731 ! include 'COMMON.CONTROL'
1732 ! include 'COMMON.VAR'
1733 ! include 'COMMON.MD'
1734 ! include 'COMMON.CHAIN'
1735 ! include 'COMMON.DERIV'
1736 ! include 'COMMON.GEO'
1737 ! include 'COMMON.LOCAL'
1738 ! include 'COMMON.INTERACT'
1739 ! include 'COMMON.IOUNITS'
1740 ! include 'COMMON.NAMES'
1741 real(kind=8) :: adt,adt2
1742 integer :: i,j,inres
1745 write (iout,*) "VELVERLET1 START: DC"
1747 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1748 (dc(j,i+nres),j=1,3)
1752 adt=d_a_old(j,0)*d_time
1754 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1755 d_t_new(j,0)=d_t_old(j,0)+adt2
1756 d_t(j,0)=d_t_old(j,0)+adt
1760 adt=d_a_old(j,i)*d_time
1762 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1763 d_t_new(j,i)=d_t_old(j,i)+adt2
1764 d_t(j,i)=d_t_old(j,i)+adt
1768 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1771 adt=d_a_old(j,inres)*d_time
1773 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1774 d_t_new(j,inres)=d_t_old(j,inres)+adt2
1775 d_t(j,inres)=d_t_old(j,inres)+adt
1780 write (iout,*) "VELVERLET1 END: DC"
1782 write (iout,'(i3,3f10.5,5x,3f10.5)') i,(dc(j,i),j=1,3),&
1783 (dc(j,i+nres),j=1,3)
1787 end subroutine verlet1
1788 !-----------------------------------------------------------------------------
1790 ! Step 2 of the velocity Verlet algorithm: update velocities
1792 ! implicit real*8 (a-h,o-z)
1793 ! include 'DIMENSIONS'
1794 ! include 'COMMON.CONTROL'
1795 ! include 'COMMON.VAR'
1796 ! include 'COMMON.MD'
1797 ! include 'COMMON.CHAIN'
1798 ! include 'COMMON.DERIV'
1799 ! include 'COMMON.GEO'
1800 ! include 'COMMON.LOCAL'
1801 ! include 'COMMON.INTERACT'
1802 ! include 'COMMON.IOUNITS'
1803 ! include 'COMMON.NAMES'
1804 integer :: i,j,inres
1807 d_t(j,0)=d_t_new(j,0)+0.5d0*d_a(j,0)*d_time
1811 d_t(j,i)=d_t_new(j,i)+0.5d0*d_a(j,i)*d_time
1815 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1818 d_t(j,inres)=d_t_new(j,inres)+0.5d0*d_a(j,inres)*d_time
1823 end subroutine verlet2
1824 !-----------------------------------------------------------------------------
1825 subroutine sddir_precalc
1826 ! Applying velocity Verlet algorithm - step 1 to coordinates
1827 ! implicit real*8 (a-h,o-z)
1828 ! include 'DIMENSIONS'
1834 ! include 'COMMON.CONTROL'
1835 ! include 'COMMON.VAR'
1836 ! include 'COMMON.MD'
1838 ! include 'COMMON.LANGEVIN'
1840 ! include 'COMMON.LANGEVIN.lang0'
1842 ! include 'COMMON.CHAIN'
1843 ! include 'COMMON.DERIV'
1844 ! include 'COMMON.GEO'
1845 ! include 'COMMON.LOCAL'
1846 ! include 'COMMON.INTERACT'
1847 ! include 'COMMON.IOUNITS'
1848 ! include 'COMMON.NAMES'
1849 ! include 'COMMON.TIME1'
1850 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
1851 !el common /stochcalc/ stochforcvec
1852 real(kind=8) :: time00
1854 ! Compute friction and stochastic forces
1859 time_fric=time_fric+MPI_Wtime()-time00
1861 call stochastic_force(stochforcvec)
1862 time_stoch=time_stoch+MPI_Wtime()-time00
1865 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
1866 ! forces (d_as_work)
1868 call ginv_mult(fric_work, d_af_work)
1869 call ginv_mult(stochforcvec, d_as_work)
1871 end subroutine sddir_precalc
1872 !-----------------------------------------------------------------------------
1873 subroutine sddir_verlet1
1874 ! Applying velocity Verlet algorithm - step 1 to velocities
1877 ! implicit real*8 (a-h,o-z)
1878 ! include 'DIMENSIONS'
1879 ! include 'COMMON.CONTROL'
1880 ! include 'COMMON.VAR'
1881 ! include 'COMMON.MD'
1883 ! include 'COMMON.LANGEVIN'
1885 ! include 'COMMON.LANGEVIN.lang0'
1887 ! include 'COMMON.CHAIN'
1888 ! include 'COMMON.DERIV'
1889 ! include 'COMMON.GEO'
1890 ! include 'COMMON.LOCAL'
1891 ! include 'COMMON.INTERACT'
1892 ! include 'COMMON.IOUNITS'
1893 ! include 'COMMON.NAMES'
1894 ! Revised 3/31/05 AL: correlation between random contributions to
1895 ! position and velocity increments included.
1896 real(kind=8) :: sqrt13 = 0.57735026918962576451d0 ! 1/sqrt(3)
1897 real(kind=8) :: adt,adt2
1898 integer :: i,j,ind,inres
1900 ! Add the contribution from BOTH friction and stochastic force to the
1901 ! coordinates, but ONLY the contribution from the friction forces to velocities
1904 adt=(d_a_old(j,0)+d_af_work(j))*d_time
1905 adt2=0.5d0*adt+sqrt13*d_as_work(j)*d_time
1906 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1907 d_t_new(j,0)=d_t_old(j,0)+0.5d0*adt
1908 d_t(j,0)=d_t_old(j,0)+adt
1913 adt=(d_a_old(j,i)+d_af_work(ind+j))*d_time
1914 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
1915 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1916 d_t_new(j,i)=d_t_old(j,i)+0.5d0*adt
1917 d_t(j,i)=d_t_old(j,i)+adt
1922 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1925 adt=(d_a_old(j,inres)+d_af_work(ind+j))*d_time
1926 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
1927 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1928 d_t_new(j,inres)=d_t_old(j,inres)+0.5d0*adt
1929 d_t(j,inres)=d_t_old(j,inres)+adt
1935 end subroutine sddir_verlet1
1936 !-----------------------------------------------------------------------------
1937 subroutine sddir_verlet2
1938 ! Calculating the adjusted velocities for accelerations
1941 ! implicit real*8 (a-h,o-z)
1942 ! include 'DIMENSIONS'
1943 ! include 'COMMON.CONTROL'
1944 ! include 'COMMON.VAR'
1945 ! include 'COMMON.MD'
1947 ! include 'COMMON.LANGEVIN'
1949 ! include 'COMMON.LANGEVIN.lang0'
1951 ! include 'COMMON.CHAIN'
1952 ! include 'COMMON.DERIV'
1953 ! include 'COMMON.GEO'
1954 ! include 'COMMON.LOCAL'
1955 ! include 'COMMON.INTERACT'
1956 ! include 'COMMON.IOUNITS'
1957 ! include 'COMMON.NAMES'
1958 real(kind=8),dimension(6*nres) :: stochforcvec,d_as_work1 !(MAXRES6) maxres6=6*maxres
1959 real(kind=8) :: cos60 = 0.5d0, sin60 = 0.86602540378443864676d0
1960 integer :: i,j,ind,inres
1961 ! Revised 3/31/05 AL: correlation between random contributions to
1962 ! position and velocity increments included.
1963 ! The correlation coefficients are calculated at low-friction limit.
1964 ! Also, friction forces are now not calculated with new velocities.
1966 ! call friction_force
1967 call stochastic_force(stochforcvec)
1969 ! Compute the acceleration due to friction forces (d_af_work) and stochastic
1970 ! forces (d_as_work)
1972 call ginv_mult(stochforcvec, d_as_work1)
1978 d_t(j,0)=d_t_new(j,0)+(0.5d0*(d_a(j,0)+d_af_work(j)) &
1979 +sin60*d_as_work(j)+cos60*d_as_work1(j))*d_time
1984 d_t(j,i)=d_t_new(j,i)+(0.5d0*(d_a(j,i)+d_af_work(ind+j)) &
1985 +sin60*d_as_work(ind+j)+cos60*d_as_work1(ind+j))*d_time
1990 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1993 d_t(j,inres)=d_t_new(j,inres)+(0.5d0*(d_a(j,inres) &
1994 +d_af_work(ind+j))+sin60*d_as_work(ind+j) &
1995 +cos60*d_as_work1(ind+j))*d_time
2001 end subroutine sddir_verlet2
2002 !-----------------------------------------------------------------------------
2003 subroutine max_accel
2005 ! Find the maximum difference in the accelerations of the the sites
2006 ! at the beginning and the end of the time step.
2009 ! implicit real*8 (a-h,o-z)
2010 ! include 'DIMENSIONS'
2011 ! include 'COMMON.CONTROL'
2012 ! include 'COMMON.VAR'
2013 ! include 'COMMON.MD'
2014 ! include 'COMMON.CHAIN'
2015 ! include 'COMMON.DERIV'
2016 ! include 'COMMON.GEO'
2017 ! include 'COMMON.LOCAL'
2018 ! include 'COMMON.INTERACT'
2019 ! include 'COMMON.IOUNITS'
2020 real(kind=8),dimension(3) :: aux,accel,accel_old
2021 real(kind=8) :: dacc
2025 ! aux(j)=d_a(j,0)-d_a_old(j,0)
2026 accel_old(j)=d_a_old(j,0)
2033 ! 7/3/08 changed to asymmetric difference
2035 ! accel(j)=aux(j)+0.5d0*(d_a(j,i)-d_a_old(j,i))
2036 accel_old(j)=accel_old(j)+0.5d0*d_a_old(j,i)
2037 accel(j)=accel(j)+0.5d0*d_a(j,i)
2038 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2039 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2040 dacc=dabs(accel(j)-accel_old(j))
2041 ! write (iout,*) i,dacc
2042 if (dacc.gt.amax) amax=dacc
2050 accel_old(j)=d_a_old(j,0)
2055 accel_old(j)=accel_old(j)+d_a_old(j,1)
2056 accel(j)=accel(j)+d_a(j,1)
2060 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2062 ! accel(j)=accel(j)+d_a(j,i+nres)-d_a_old(j,i+nres)
2063 accel_old(j)=accel_old(j)+d_a_old(j,i+nres)
2064 accel(j)=accel(j)+d_a(j,i+nres)
2068 ! if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
2069 if (dabs(accel(j)).gt.dabs(accel_old(j))) then
2070 dacc=dabs(accel(j)-accel_old(j))
2071 ! write (iout,*) "side-chain",i,dacc
2072 if (dacc.gt.amax) amax=dacc
2076 accel_old(j)=accel_old(j)+d_a_old(j,i)
2077 accel(j)=accel(j)+d_a(j,i)
2078 ! aux(j)=aux(j)+d_a(j,i)-d_a_old(j,i)
2082 end subroutine max_accel
2083 !-----------------------------------------------------------------------------
2084 subroutine predict_edrift(epdrift)
2086 ! Predict the drift of the potential energy
2089 use control_data, only: lmuca
2090 ! implicit real*8 (a-h,o-z)
2091 ! include 'DIMENSIONS'
2092 ! include 'COMMON.CONTROL'
2093 ! include 'COMMON.VAR'
2094 ! include 'COMMON.MD'
2095 ! include 'COMMON.CHAIN'
2096 ! include 'COMMON.DERIV'
2097 ! include 'COMMON.GEO'
2098 ! include 'COMMON.LOCAL'
2099 ! include 'COMMON.INTERACT'
2100 ! include 'COMMON.IOUNITS'
2101 ! include 'COMMON.MUCA'
2102 real(kind=8) :: epdrift,epdriftij
2104 ! Drift of the potential energy
2110 epdriftij=dabs((d_a(j,i)-d_a_old(j,i))*gcart(j,i))
2111 if (lmuca) epdriftij=epdriftij*factor
2112 ! write (iout,*) "back",i,j,epdriftij
2113 if (epdriftij.gt.epdrift) epdrift=epdriftij
2117 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2120 dabs((d_a(j,i+nres)-d_a_old(j,i+nres))*gxcart(j,i))
2121 if (lmuca) epdriftij=epdriftij*factor
2122 ! write (iout,*) "side",i,j,epdriftij
2123 if (epdriftij.gt.epdrift) epdrift=epdriftij
2127 epdrift=0.5d0*epdrift*d_time*d_time
2128 ! write (iout,*) "epdrift",epdrift
2130 end subroutine predict_edrift
2131 !-----------------------------------------------------------------------------
2132 subroutine verlet_bath
2134 ! Coupling to the thermostat by using the Berendsen algorithm
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 ! include 'COMMON.NAMES'
2149 real(kind=8) :: T_half,fact
2150 integer :: i,j,inres
2152 T_half=2.0d0/(dimen3*Rb)*EK
2153 fact=dsqrt(1.0d0+(d_time/tau_bath)*(t_bath/T_half-1.0d0))
2154 ! write(iout,*) "T_half", T_half
2155 ! write(iout,*) "EK", EK
2156 ! write(iout,*) "fact", fact
2158 d_t(j,0)=fact*d_t(j,0)
2162 d_t(j,i)=fact*d_t(j,i)
2166 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2169 d_t(j,inres)=fact*d_t(j,inres)
2174 end subroutine verlet_bath
2175 !-----------------------------------------------------------------------------
2177 ! Set up the initial conditions of a MD simulation
2180 use control, only:tcpu
2181 !el use io_basic, only:ilen
2184 use minimm, only:minim_dc,minimize,sc_move
2185 use io_config, only:readrst
2186 use io, only:statout
2187 ! implicit real*8 (a-h,o-z)
2188 ! include 'DIMENSIONS'
2191 character(len=16) :: form
2192 integer :: IERROR,ERRCODE
2194 ! include 'COMMON.SETUP'
2195 ! include 'COMMON.CONTROL'
2196 ! include 'COMMON.VAR'
2197 ! include 'COMMON.MD'
2199 ! include 'COMMON.LANGEVIN'
2201 ! include 'COMMON.LANGEVIN.lang0'
2203 ! include 'COMMON.CHAIN'
2204 ! include 'COMMON.DERIV'
2205 ! include 'COMMON.GEO'
2206 ! include 'COMMON.LOCAL'
2207 ! include 'COMMON.INTERACT'
2208 ! include 'COMMON.IOUNITS'
2209 ! include 'COMMON.NAMES'
2210 ! include 'COMMON.REMD'
2211 real(kind=8),dimension(0:n_ene) :: energia_long,energia_short
2212 real(kind=8),dimension(3) :: vcm,incr,L
2213 real(kind=8) :: xv,sigv,lowb,highb
2214 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
2215 character(len=256) :: qstr
2218 character(len=50) :: tytul
2219 logical :: file_exist
2220 !el common /gucio/ cm
2221 integer :: i,j,ipos,iq,iw,nft_sc,iretcode,nfun,itime,ierr
2222 real(kind=8) :: etot,tt0
2226 ! write(iout,*) "d_time", d_time
2227 ! Compute the standard deviations of stochastic forces for Langevin dynamics
2228 ! if the friction coefficients do not depend on surface area
2229 if (lang.gt.0 .and. .not.surfarea) then
2231 stdforcp(i)=stdfp*dsqrt(gamp)
2234 stdforcsc(i)=stdfsc(iabs(itype(i))) &
2235 *dsqrt(gamsc(iabs(itype(i))))
2238 ! Open the pdb file for snapshotshots
2241 if (ilen(tmpdir).gt.0) &
2242 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2243 liczba(:ilen(liczba))//".pdb")
2245 file=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2249 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2250 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2251 liczba(:ilen(liczba))//".x")
2252 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2255 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file)) &
2256 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"// &
2257 liczba(:ilen(liczba))//".cx")
2258 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba)) &
2264 if (ilen(tmpdir).gt.0) &
2265 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.pdb")
2266 open(ipdb,file=prefix(:ilen(prefix))//"_MD.pdb")
2268 if (ilen(tmpdir).gt.0) &
2269 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.cx")
2270 cartname=prefix(:ilen(prefix))//"_MD.cx"
2274 write (qstr,'(256(1h ))')
2277 iq = qinfrag(i,iset)*10
2278 iw = wfrag(i,iset)/100
2280 if(me.eq.king.or..not.out1file) &
2281 write (iout,*) "Frag",qinfrag(i,iset),wfrag(i,iset),iq,iw
2282 write (qstr(ipos:ipos+6),'(2h_f,i1,1h_,i1,1h_,i1)') i,iq,iw
2287 iq = qinpair(i,iset)*10
2288 iw = wpair(i,iset)/100
2290 if(me.eq.king.or..not.out1file) &
2291 write (iout,*) "Pair",i,qinpair(i,iset),wpair(i,iset),iq,iw
2292 write (qstr(ipos:ipos+6),'(2h_p,i1,1h_,i1,1h_,i1)') i,iq,iw
2296 ! pdbname=pdbname(:ilen(pdbname)-4)//qstr(:ipos-1)//'.pdb'
2298 ! cartname=cartname(:ilen(cartname)-2)//qstr(:ipos-1)//'.x'
2300 ! cartname=cartname(:ilen(cartname)-3)//qstr(:ipos-1)//'.cx'
2302 ! statname=statname(:ilen(statname)-5)//qstr(:ipos-1)//'.stat'
2306 if (restart1file) then
2308 inquire(file=mremd_rst_name,exist=file_exist)
2309 write (*,*) me," Before broadcast: file_exist",file_exist
2311 call MPI_Bcast(file_exist,1,MPI_LOGICAL,king,CG_COMM,&
2314 write (*,*) me," After broadcast: file_exist",file_exist
2315 ! inquire(file=mremd_rst_name,exist=file_exist)
2316 if(me.eq.king.or..not.out1file) &
2317 write(iout,*) "Initial state read by master and distributed"
2319 if (ilen(tmpdir).gt.0) &
2320 call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_' &
2321 //liczba(:ilen(liczba))//'.rst')
2322 inquire(file=rest2name,exist=file_exist)
2325 if(.not.restart1file) then
2326 if(me.eq.king.or..not.out1file) &
2327 write(iout,*) "Initial state will be read from file ",&
2328 rest2name(:ilen(rest2name))
2331 call rescale_weights(t_bath)
2333 if(me.eq.king.or..not.out1file)then
2334 if (restart1file) then
2335 write(iout,*) "File ",mremd_rst_name(:ilen(mremd_rst_name)),&
2338 write(iout,*) "File ",rest2name(:ilen(rest2name)),&
2341 write(iout,*) "Initial velocities randomly generated"
2347 ! Generate initial velocities
2348 if(me.eq.king.or..not.out1file) &
2349 write(iout,*) "Initial velocities randomly generated"
2353 ! rest2name = prefix(:ilen(prefix))//'.rst'
2354 if(me.eq.king.or..not.out1file)then
2355 write (iout,*) "Initial velocities"
2357 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2358 (d_t(j,i+nres),j=1,3)
2360 ! Zeroing the total angular momentum of the system
2361 write(iout,*) "Calling the zero-angular momentum subroutine"
2364 ! Getting the potential energy and forces and velocities and accelerations
2366 ! write (iout,*) "velocity of the center of the mass:"
2367 ! write (iout,*) (vcm(j),j=1,3)
2369 d_t(j,0)=d_t(j,0)-vcm(j)
2371 ! Removing the velocity of the center of mass
2373 if(me.eq.king.or..not.out1file)then
2374 write (iout,*) "vcm right after adjustment:"
2375 write (iout,*) (vcm(j),j=1,3)
2379 if(iranconf.ne.0) then
2381 print *, 'Calling OVERLAP_SC'
2382 call overlap_sc(fail)
2385 call sc_move(2,nres-1,10,1d10,nft_sc,etot)
2386 print *,'SC_move',nft_sc,etot
2387 if(me.eq.king.or..not.out1file) &
2388 write(iout,*) 'SC_move',nft_sc,etot
2392 print *, 'Calling MINIM_DC'
2393 call minim_dc(etot,iretcode,nfun)
2395 call geom_to_var(nvar,varia)
2396 print *,'Calling MINIMIZE.'
2397 call minimize(etot,varia,iretcode,nfun)
2398 call var_to_geom(nvar,varia)
2400 if(me.eq.king.or..not.out1file) &
2401 write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
2404 call chainbuild_cart
2405 write(iout,*) "przed kinetic, EK=",EK
2410 write(iout,*) "dimen3",dimen3,"Rb",Rb,"EK",EK
2411 kinetic_T=2.0d0/(dimen3*Rb)*EK
2412 write(iout,*) "kinetic_T",kinetic_T
2413 if(me.eq.king.or..not.out1file)then
2423 call etotal(potEcomp)
2424 if (large) call enerprint(potEcomp)
2427 t_etotal=t_etotal+MPI_Wtime()-tt0
2429 t_etotal=t_etotal+tcpu()-tt0
2434 write(iout,*) "kinetic_T if large",kinetic_T
2436 write(iout,*) "kinetic_T if large",kinetic_T
2438 if (amax*d_time .gt. dvmax) then
2439 d_time=d_time*dvmax/amax
2440 if(me.eq.king.or..not.out1file) write (iout,*) &
2441 "Time step reduced to",d_time,&
2442 " because of too large initial acceleration."
2444 if(me.eq.king.or..not.out1file)then
2445 write(iout,*) "Potential energy and its components"
2446 call enerprint(potEcomp)
2447 ! write(iout,*) (potEcomp(i),i=0,n_ene)
2449 potE=potEcomp(0)-potEcomp(20)
2452 if (ntwe.ne.0) call statout(itime)
2453 if(me.eq.king.or..not.out1file) &
2454 write (iout,'(/a/3(a25,1pe14.5/))') "Initial:", &
2455 " Kinetic energy",EK," Potential energy",potE, &
2456 " Total energy",totE," Maximum acceleration ", &
2459 write (iout,*) "Initial coordinates"
2461 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(c(j,i),j=1,3),&
2464 write (iout,*) "Initial dC"
2466 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),&
2467 (dc(j,i+nres),j=1,3)
2469 write (iout,*) "Initial velocities"
2470 write (iout,"(13x,' backbone ',23x,' side chain')")
2472 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),&
2473 (d_t(j,i+nres),j=1,3)
2475 write (iout,*) "Initial accelerations"
2477 ! write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
2478 write (iout,'(i3,3f15.10,3x,3f15.10)') i,(d_a(j,i),j=1,3),&
2479 (d_a(j,i+nres),j=1,3)
2485 d_t_old(j,i)=d_t(j,i)
2486 d_a_old(j,i)=d_a(j,i)
2488 ! write (iout,*) "dc_old",i,(dc_old(j,i),j=1,3)
2497 call etotal_short(energia_short)
2498 if (large) call enerprint(potEcomp)
2501 t_eshort=t_eshort+MPI_Wtime()-tt0
2503 t_eshort=t_eshort+tcpu()-tt0
2507 write(iout,*) "przed lagrangian"
2509 write(iout,*) "po lagrangian"
2510 if(.not.out1file .and. large) then
2511 write (iout,*) "energia_long",energia_long(0),&
2512 " energia_short",energia_short(0),&
2513 " total",energia_long(0)+energia_short(0)
2514 write (iout,*) "Initial fast-force accelerations"
2516 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2517 (d_a(j,i+nres),j=1,3)
2520 ! 7/2/2009 Copy accelerations due to short-lange forces to an auxiliary array
2523 d_a_short(j,i)=d_a(j,i)
2532 call etotal_long(energia_long)
2533 if (large) call enerprint(potEcomp)
2536 t_elong=t_elong+MPI_Wtime()-tt0
2538 t_elong=t_elong+tcpu()-tt0
2542 write(iout,*) "przed lagrangian2"
2544 write(iout,*) "po lagrangian2"
2545 if(.not.out1file .and. large) then
2546 write (iout,*) "energia_long",energia_long(0)
2547 write (iout,*) "Initial slow-force accelerations"
2549 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),&
2550 (d_a(j,i+nres),j=1,3)
2554 t_enegrad=t_enegrad+MPI_Wtime()-tt0
2556 t_enegrad=t_enegrad+tcpu()-tt0
2559 write(iout,*) "end init MD"
2561 end subroutine init_MD
2562 !-----------------------------------------------------------------------------
2563 subroutine random_vel
2565 ! implicit real*8 (a-h,o-z)
2567 use random, only:anorm_distr
2568 ! include 'DIMENSIONS'
2569 ! include 'COMMON.CONTROL'
2570 ! include 'COMMON.VAR'
2571 ! include 'COMMON.MD'
2573 ! include 'COMMON.LANGEVIN'
2575 ! include 'COMMON.LANGEVIN.lang0'
2577 ! include 'COMMON.CHAIN'
2578 ! include 'COMMON.DERIV'
2579 ! include 'COMMON.GEO'
2580 ! include 'COMMON.LOCAL'
2581 ! include 'COMMON.INTERACT'
2582 ! include 'COMMON.IOUNITS'
2583 ! include 'COMMON.NAMES'
2584 ! include 'COMMON.TIME1'
2585 real(kind=8) :: xv,sigv,lowb,highb ,Ek1
2586 integer :: i,j,ii,k,ind
2587 ! Generate random velocities from Gaussian distribution of mean 0 and std of KT/m
2588 ! First generate velocities in the eigenspace of the G matrix
2589 ! write (iout,*) "Calling random_vel dimen dimen3",dimen,dimen3
2596 sigv=dsqrt((Rb*t_bath)/geigen(i))
2599 d_t_work_new(ii)=anorm_distr(xv,sigv,lowb,highb)
2600 ! write (iout,*) "i",i," ii",ii," geigen",geigen(i),&
2601 ! " d_t_work_new",d_t_work_new(ii)
2610 ! Ek1=Ek1+0.5d0*geigen(i)*d_t_work_new(ii)**2
2613 ! write (iout,*) "Ek from eigenvectors",Ek1
2615 ! Transform velocities to UNRES coordinate space
2621 d_t_work(ind)=d_t_work(ind) &
2622 +Gvec(i,j)*d_t_work_new((j-1)*3+k+1)
2624 ! write (iout,*) "i",i," ind",ind," d_t_work",d_t_work(ind)
2628 ! Transfer to the d_t vector
2630 d_t(j,0)=d_t_work(j)
2636 d_t(j,i)=d_t_work(ind)
2640 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2643 d_t(j,i+nres)=d_t_work(ind)
2648 ! write (iout,*) "Kinetic energy",Ek,EK1," kinetic temperature",&
2649 ! 2.0d0/(dimen3*Rb)*EK,2.0d0/(dimen3*Rb)*EK1
2652 end subroutine random_vel
2653 !-----------------------------------------------------------------------------
2655 subroutine sd_verlet_p_setup
2656 ! Sets up the parameters of stochastic Verlet algorithm
2657 ! implicit real*8 (a-h,o-z)
2658 ! include 'DIMENSIONS'
2659 use control, only: tcpu
2664 ! include 'COMMON.CONTROL'
2665 ! include 'COMMON.VAR'
2666 ! include 'COMMON.MD'
2668 ! include 'COMMON.LANGEVIN'
2670 ! include 'COMMON.LANGEVIN.lang0'
2672 ! include 'COMMON.CHAIN'
2673 ! include 'COMMON.DERIV'
2674 ! include 'COMMON.GEO'
2675 ! include 'COMMON.LOCAL'
2676 ! include 'COMMON.INTERACT'
2677 ! include 'COMMON.IOUNITS'
2678 ! include 'COMMON.NAMES'
2679 ! include 'COMMON.TIME1'
2680 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
2681 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
2682 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
2683 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
2684 logical :: lprn = .false.
2685 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
2686 real(kind=8) :: ktm,gdt,egdt,gdt2,gdt3,gdt4,gdt5,gdt6,gdt7,gdt8,&
2688 integer :: i,maxres2
2695 ! AL 8/17/04 Code adapted from tinker
2697 ! Get the frictional and random terms for stochastic dynamics in the
2698 ! eigenspace of mass-scaled UNRES friction matrix
2702 gdt = fricgam(i) * d_time
2704 ! Stochastic dynamics reduces to simple MD for zero friction
2706 if (gdt .le. zero) then
2707 pfric_vec(i) = 1.0d0
2708 vfric_vec(i) = d_time
2709 afric_vec(i) = 0.5d0 * d_time * d_time
2710 prand_vec(i) = 0.0d0
2711 vrand_vec1(i) = 0.0d0
2712 vrand_vec2(i) = 0.0d0
2714 ! Analytical expressions when friction coefficient is large
2717 if (gdt .ge. gdt_radius) then
2720 vfric_vec(i) = (1.0d0-egdt) / fricgam(i)
2721 afric_vec(i) = (d_time-vfric_vec(i)) / fricgam(i)
2722 pterm = 2.0d0*gdt - 3.0d0 + (4.0d0-egdt)*egdt
2723 vterm = 1.0d0 - egdt**2
2724 rho = (1.0d0-egdt)**2 / sqrt(pterm*vterm)
2726 ! Use series expansions when friction coefficient is small
2737 afric_vec(i) = (gdt2/2.0d0 - gdt3/6.0d0 + gdt4/24.0d0 &
2738 - gdt5/120.0d0 + gdt6/720.0d0 &
2739 - gdt7/5040.0d0 + gdt8/40320.0d0 &
2740 - gdt9/362880.0d0) / fricgam(i)**2
2741 vfric_vec(i) = d_time - fricgam(i)*afric_vec(i)
2742 pfric_vec(i) = 1.0d0 - fricgam(i)*vfric_vec(i)
2743 pterm = 2.0d0*gdt3/3.0d0 - gdt4/2.0d0 &
2744 + 7.0d0*gdt5/30.0d0 - gdt6/12.0d0 &
2745 + 31.0d0*gdt7/1260.0d0 - gdt8/160.0d0 &
2746 + 127.0d0*gdt9/90720.0d0
2747 vterm = 2.0d0*gdt - 2.0d0*gdt2 + 4.0d0*gdt3/3.0d0 &
2748 - 2.0d0*gdt4/3.0d0 + 4.0d0*gdt5/15.0d0 &
2749 - 4.0d0*gdt6/45.0d0 + 8.0d0*gdt7/315.0d0 &
2750 - 2.0d0*gdt8/315.0d0 + 4.0d0*gdt9/2835.0d0
2751 rho = sqrt(3.0d0) * (0.5d0 - 3.0d0*gdt/16.0d0 &
2752 - 17.0d0*gdt2/1280.0d0 &
2753 + 17.0d0*gdt3/6144.0d0 &
2754 + 40967.0d0*gdt4/34406400.0d0 &
2755 - 57203.0d0*gdt5/275251200.0d0 &
2756 - 1429487.0d0*gdt6/13212057600.0d0)
2759 ! Compute the scaling factors of random terms for the nonzero friction case
2761 ktm = 0.5d0*d_time/fricgam(i)
2762 psig = dsqrt(ktm*pterm) / fricgam(i)
2763 vsig = dsqrt(ktm*vterm)
2764 rhoc = dsqrt(1.0d0 - rho*rho)
2766 vrand_vec1(i) = vsig * rho
2767 vrand_vec2(i) = vsig * rhoc
2772 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
2775 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
2776 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
2780 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
2783 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
2784 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
2785 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
2786 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
2787 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec1,vrand_mat1)
2788 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
2791 t_sdsetup=t_sdsetup+MPI_Wtime()
2793 t_sdsetup=t_sdsetup+tcpu()-tt0
2796 end subroutine sd_verlet_p_setup
2797 !-----------------------------------------------------------------------------
2798 subroutine eigtransf1(n,ndim,ab,d,c)
2802 real(kind=8) :: ab(ndim,ndim,n),c(ndim,n),d(ndim)
2808 c(i,j)=c(i,j)+ab(k,j,i)*d(k)
2813 end subroutine eigtransf1
2814 !-----------------------------------------------------------------------------
2815 subroutine eigtransf(n,ndim,a,b,d,c)
2819 real(kind=8) :: a(ndim,n),b(ndim,n),c(ndim,n),d(ndim)
2825 c(i,j)=c(i,j)+a(i,k)*b(k,j)*d(k)
2830 end subroutine eigtransf
2831 !-----------------------------------------------------------------------------
2832 subroutine sd_verlet1
2834 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
2836 ! implicit real*8 (a-h,o-z)
2837 ! include 'DIMENSIONS'
2838 ! include 'COMMON.CONTROL'
2839 ! include 'COMMON.VAR'
2840 ! include 'COMMON.MD'
2842 ! include 'COMMON.LANGEVIN'
2844 ! include 'COMMON.LANGEVIN.lang0'
2846 ! include 'COMMON.CHAIN'
2847 ! include 'COMMON.DERIV'
2848 ! include 'COMMON.GEO'
2849 ! include 'COMMON.LOCAL'
2850 ! include 'COMMON.INTERACT'
2851 ! include 'COMMON.IOUNITS'
2852 ! include 'COMMON.NAMES'
2853 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
2854 !el common /stochcalc/ stochforcvec
2855 logical :: lprn = .false.
2856 real(kind=8) :: ddt1,ddt2
2857 integer :: i,j,ind,inres
2859 ! write (iout,*) "dc_old"
2861 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
2862 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
2865 dc_work(j)=dc_old(j,0)
2866 d_t_work(j)=d_t_old(j,0)
2867 d_a_work(j)=d_a_old(j,0)
2872 dc_work(ind+j)=dc_old(j,i)
2873 d_t_work(ind+j)=d_t_old(j,i)
2874 d_a_work(ind+j)=d_a_old(j,i)
2879 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2881 dc_work(ind+j)=dc_old(j,i+nres)
2882 d_t_work(ind+j)=d_t_old(j,i+nres)
2883 d_a_work(ind+j)=d_a_old(j,i+nres)
2891 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
2895 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
2896 vfric_mat(i,j),afric_mat(i,j),&
2897 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
2905 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
2906 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
2907 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
2908 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
2910 d_t_work_new(i)=ddt1+0.5d0*ddt2
2911 d_t_work(i)=ddt1+ddt2
2916 d_t(j,0)=d_t_work(j)
2921 dc(j,i)=dc_work(ind+j)
2922 d_t(j,i)=d_t_work(ind+j)
2927 if (itype(i).ne.10) then
2930 dc(j,inres)=dc_work(ind+j)
2931 d_t(j,inres)=d_t_work(ind+j)
2937 end subroutine sd_verlet1
2938 !-----------------------------------------------------------------------------
2939 subroutine sd_verlet2
2941 ! Calculating the adjusted velocities for accelerations
2943 ! implicit real*8 (a-h,o-z)
2944 ! include 'DIMENSIONS'
2945 ! include 'COMMON.CONTROL'
2946 ! include 'COMMON.VAR'
2947 ! include 'COMMON.MD'
2949 ! include 'COMMON.LANGEVIN'
2951 ! include 'COMMON.LANGEVIN.lang0'
2953 ! include 'COMMON.CHAIN'
2954 ! include 'COMMON.DERIV'
2955 ! include 'COMMON.GEO'
2956 ! include 'COMMON.LOCAL'
2957 ! include 'COMMON.INTERACT'
2958 ! include 'COMMON.IOUNITS'
2959 ! include 'COMMON.NAMES'
2960 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
2961 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
2962 !el common /stochcalc/ stochforcvec
2964 real(kind=8) :: ddt1,ddt2
2965 integer :: i,j,ind,inres
2966 ! Compute the stochastic forces which contribute to velocity change
2968 call stochastic_force(stochforcvecV)
2975 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
2976 ddt2=ddt2+vrand_mat1(i,j)*stochforcvec(j)+ &
2977 vrand_mat2(i,j)*stochforcvecV(j)
2979 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
2983 d_t(j,0)=d_t_work(j)
2988 d_t(j,i)=d_t_work(ind+j)
2993 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2996 d_t(j,inres)=d_t_work(ind+j)
3002 end subroutine sd_verlet2
3003 !-----------------------------------------------------------------------------
3004 subroutine sd_verlet_ciccotti_setup
3006 ! Sets up the parameters of stochastic velocity Verlet algorithmi; Ciccotti's
3008 ! implicit real*8 (a-h,o-z)
3009 ! include 'DIMENSIONS'
3010 use control, only: tcpu
3015 ! include 'COMMON.CONTROL'
3016 ! include 'COMMON.VAR'
3017 ! include 'COMMON.MD'
3019 ! include 'COMMON.LANGEVIN'
3021 ! include 'COMMON.LANGEVIN.lang0'
3023 ! include 'COMMON.CHAIN'
3024 ! include 'COMMON.DERIV'
3025 ! include 'COMMON.GEO'
3026 ! include 'COMMON.LOCAL'
3027 ! include 'COMMON.INTERACT'
3028 ! include 'COMMON.IOUNITS'
3029 ! include 'COMMON.NAMES'
3030 ! include 'COMMON.TIME1'
3031 real(kind=8),dimension(6*nres) :: emgdt !(MAXRES6) maxres6=6*maxres
3032 real(kind=8) :: pterm,vterm,rho,rhoc,vsig
3033 real(kind=8),dimension(6*nres) :: pfric_vec,vfric_vec,afric_vec,&
3034 prand_vec,vrand_vec1,vrand_vec2 !(MAXRES6) maxres6=6*maxres
3035 logical :: lprn = .false.
3036 real(kind=8) :: zero = 1.0d-8, gdt_radius = 0.05d0
3037 real(kind=8) :: ktm,gdt,egdt,tt0
3038 integer :: i,maxres2
3045 ! AL 8/17/04 Code adapted from tinker
3047 ! Get the frictional and random terms for stochastic dynamics in the
3048 ! eigenspace of mass-scaled UNRES friction matrix
3052 write (iout,*) "i",i," fricgam",fricgam(i)
3053 gdt = fricgam(i) * d_time
3055 ! Stochastic dynamics reduces to simple MD for zero friction
3057 if (gdt .le. zero) then
3058 pfric_vec(i) = 1.0d0
3059 vfric_vec(i) = d_time
3060 afric_vec(i) = 0.5d0*d_time*d_time
3061 prand_vec(i) = afric_vec(i)
3062 vrand_vec2(i) = vfric_vec(i)
3064 ! Analytical expressions when friction coefficient is large
3069 vfric_vec(i) = dexp(-0.5d0*gdt)*d_time
3070 afric_vec(i) = 0.5d0*dexp(-0.25d0*gdt)*d_time*d_time
3071 prand_vec(i) = afric_vec(i)
3072 vrand_vec2(i) = vfric_vec(i)
3074 ! Compute the scaling factors of random terms for the nonzero friction case
3076 ! ktm = 0.5d0*d_time/fricgam(i)
3077 ! psig = dsqrt(ktm*pterm) / fricgam(i)
3078 ! vsig = dsqrt(ktm*vterm)
3079 ! prand_vec(i) = psig*afric_vec(i)
3080 ! vrand_vec2(i) = vsig*vfric_vec(i)
3085 "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",&
3088 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),&
3089 afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
3093 ! Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
3095 call eigtransf(dimen,maxres2,mt3,mt2,pfric_vec,pfric_mat)
3096 call eigtransf(dimen,maxres2,mt3,mt2,vfric_vec,vfric_mat)
3097 call eigtransf(dimen,maxres2,mt3,mt2,afric_vec,afric_mat)
3098 call eigtransf(dimen,maxres2,mt3,mt1,prand_vec,prand_mat)
3099 call eigtransf(dimen,maxres2,mt3,mt1,vrand_vec2,vrand_mat2)
3101 t_sdsetup=t_sdsetup+MPI_Wtime()
3103 t_sdsetup=t_sdsetup+tcpu()-tt0
3106 end subroutine sd_verlet_ciccotti_setup
3107 !-----------------------------------------------------------------------------
3108 subroutine sd_verlet1_ciccotti
3110 ! Applying stochastic velocity Verlet algorithm - step 1 to velocities
3111 ! implicit real*8 (a-h,o-z)
3113 ! include 'DIMENSIONS'
3117 ! include 'COMMON.CONTROL'
3118 ! include 'COMMON.VAR'
3119 ! include 'COMMON.MD'
3121 ! include 'COMMON.LANGEVIN'
3123 ! include 'COMMON.LANGEVIN.lang0'
3125 ! include 'COMMON.CHAIN'
3126 ! include 'COMMON.DERIV'
3127 ! include 'COMMON.GEO'
3128 ! include 'COMMON.LOCAL'
3129 ! include 'COMMON.INTERACT'
3130 ! include 'COMMON.IOUNITS'
3131 ! include 'COMMON.NAMES'
3132 !el real(kind=8),dimension(6*nres) :: stochforcvec !(MAXRES6) maxres6=6*maxres
3133 !el common /stochcalc/ stochforcvec
3134 logical :: lprn = .false.
3135 real(kind=8) :: ddt1,ddt2
3136 integer :: i,j,ind,inres
3137 ! write (iout,*) "dc_old"
3139 ! write (iout,'(i5,3f10.5,5x,3f10.5)')
3140 ! & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
3143 dc_work(j)=dc_old(j,0)
3144 d_t_work(j)=d_t_old(j,0)
3145 d_a_work(j)=d_a_old(j,0)
3150 dc_work(ind+j)=dc_old(j,i)
3151 d_t_work(ind+j)=d_t_old(j,i)
3152 d_a_work(ind+j)=d_a_old(j,i)
3157 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3159 dc_work(ind+j)=dc_old(j,i+nres)
3160 d_t_work(ind+j)=d_t_old(j,i+nres)
3161 d_a_work(ind+j)=d_a_old(j,i+nres)
3170 "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",&
3174 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),&
3175 vfric_mat(i,j),afric_mat(i,j),&
3176 prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
3184 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j) &
3185 +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
3186 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
3187 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
3189 d_t_work_new(i)=ddt1+0.5d0*ddt2
3190 d_t_work(i)=ddt1+ddt2
3195 d_t(j,0)=d_t_work(j)
3200 dc(j,i)=dc_work(ind+j)
3201 d_t(j,i)=d_t_work(ind+j)
3206 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3209 dc(j,inres)=dc_work(ind+j)
3210 d_t(j,inres)=d_t_work(ind+j)
3216 end subroutine sd_verlet1_ciccotti
3217 !-----------------------------------------------------------------------------
3218 subroutine sd_verlet2_ciccotti
3220 ! Calculating the adjusted velocities for accelerations
3222 ! implicit real*8 (a-h,o-z)
3223 ! include 'DIMENSIONS'
3224 ! include 'COMMON.CONTROL'
3225 ! include 'COMMON.VAR'
3226 ! include 'COMMON.MD'
3228 ! include 'COMMON.LANGEVIN'
3230 ! include 'COMMON.LANGEVIN.lang0'
3232 ! include 'COMMON.CHAIN'
3233 ! include 'COMMON.DERIV'
3234 ! include 'COMMON.GEO'
3235 ! include 'COMMON.LOCAL'
3236 ! include 'COMMON.INTERACT'
3237 ! include 'COMMON.IOUNITS'
3238 ! include 'COMMON.NAMES'
3239 !el real(kind=8),dimension(6*nres) :: stochforcvec,stochforcvecV !(MAXRES6) maxres6=6*maxres
3240 real(kind=8),dimension(6*nres) :: stochforcvecV !(MAXRES6) maxres6=6*maxres
3241 !el common /stochcalc/ stochforcvec
3242 real(kind=8) :: ddt1,ddt2
3243 integer :: i,j,ind,inres
3245 ! Compute the stochastic forces which contribute to velocity change
3247 call stochastic_force(stochforcvecV)
3254 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
3255 ! ddt2=ddt2+vrand_mat2(i,j)*stochforcvecV(j)
3256 ddt2=ddt2+vrand_mat2(i,j)*stochforcvec(j)
3258 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
3262 d_t(j,0)=d_t_work(j)
3267 d_t(j,i)=d_t_work(ind+j)
3272 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3275 d_t(j,inres)=d_t_work(ind+j)
3281 end subroutine sd_verlet2_ciccotti
3283 !-----------------------------------------------------------------------------
3285 !-----------------------------------------------------------------------------
3286 subroutine inertia_tensor
3288 ! Calculating the intertia tensor for the entire protein in order to
3289 ! remove the perpendicular components of velocity matrix which cause
3290 ! the molecule to rotate.
3293 ! implicit real*8 (a-h,o-z)
3294 ! include 'DIMENSIONS'
3295 ! include 'COMMON.CONTROL'
3296 ! include 'COMMON.VAR'
3297 ! include 'COMMON.MD'
3298 ! include 'COMMON.CHAIN'
3299 ! include 'COMMON.DERIV'
3300 ! include 'COMMON.GEO'
3301 ! include 'COMMON.LOCAL'
3302 ! include 'COMMON.INTERACT'
3303 ! include 'COMMON.IOUNITS'
3304 ! include 'COMMON.NAMES'
3306 real(kind=8),dimension(3,3) :: Im,Imcp,eigvec,Id
3307 real(kind=8),dimension(3) :: pr,eigval,L,vp,vrot
3308 real(kind=8) :: M_SC,mag,mag2
3309 real(kind=8),dimension(3,0:nres) :: vpp !(3,0:MAXRES)
3310 real(kind=8),dimension(3) :: vs_p,pp,incr,v
3311 real(kind=8),dimension(3,3) :: pr1,pr2
3313 !el common /gucio/ cm
3314 integer :: iti,inres,i,j,k
3325 ! calculating the center of the mass of the protein
3328 cm(j)=cm(j)+c(j,i)+0.5d0*dc(j,i)
3337 M_SC=M_SC+msc(iabs(iti))
3340 cm(j)=cm(j)+msc(iabs(iti))*c(j,inres)
3344 cm(j)=cm(j)/(M_SC+(nct-nnt)*mp)
3349 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3351 Im(1,1)=Im(1,1)+mp*(pr(2)*pr(2)+pr(3)*pr(3))
3352 Im(1,2)=Im(1,2)-mp*pr(1)*pr(2)
3353 Im(1,3)=Im(1,3)-mp*pr(1)*pr(3)
3354 Im(2,3)=Im(2,3)-mp*pr(2)*pr(3)
3355 Im(2,2)=Im(2,2)+mp*(pr(3)*pr(3)+pr(1)*pr(1))
3356 Im(3,3)=Im(3,3)+mp*(pr(1)*pr(1)+pr(2)*pr(2))
3363 pr(j)=c(j,inres)-cm(j)
3365 Im(1,1)=Im(1,1)+msc(iabs(iti))*(pr(2)*pr(2)+pr(3)*pr(3))
3366 Im(1,2)=Im(1,2)-msc(iabs(iti))*pr(1)*pr(2)
3367 Im(1,3)=Im(1,3)-msc(iabs(iti))*pr(1)*pr(3)
3368 Im(2,3)=Im(2,3)-msc(iabs(iti))*pr(2)*pr(3)
3369 Im(2,2)=Im(2,2)+msc(iabs(iti))*(pr(3)*pr(3)+pr(1)*pr(1))
3370 Im(3,3)=Im(3,3)+msc(iabs(iti))*(pr(1)*pr(1)+pr(2)*pr(2))
3374 Im(1,1)=Im(1,1)+Ip*(1-dc_norm(1,i)*dc_norm(1,i))* &
3375 vbld(i+1)*vbld(i+1)*0.25d0
3376 Im(1,2)=Im(1,2)+Ip*(-dc_norm(1,i)*dc_norm(2,i))* &
3377 vbld(i+1)*vbld(i+1)*0.25d0
3378 Im(1,3)=Im(1,3)+Ip*(-dc_norm(1,i)*dc_norm(3,i))* &
3379 vbld(i+1)*vbld(i+1)*0.25d0
3380 Im(2,3)=Im(2,3)+Ip*(-dc_norm(2,i)*dc_norm(3,i))* &
3381 vbld(i+1)*vbld(i+1)*0.25d0
3382 Im(2,2)=Im(2,2)+Ip*(1-dc_norm(2,i)*dc_norm(2,i))* &
3383 vbld(i+1)*vbld(i+1)*0.25d0
3384 Im(3,3)=Im(3,3)+Ip*(1-dc_norm(3,i)*dc_norm(3,i))* &
3385 vbld(i+1)*vbld(i+1)*0.25d0
3390 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3393 Im(1,1)=Im(1,1)+Isc(iti)*(1-dc_norm(1,inres)* &
3394 dc_norm(1,inres))*vbld(inres)*vbld(inres)
3395 Im(1,2)=Im(1,2)-Isc(iti)*(dc_norm(1,inres)* &
3396 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3397 Im(1,3)=Im(1,3)-Isc(iti)*(dc_norm(1,inres)* &
3398 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3399 Im(2,3)=Im(2,3)-Isc(iti)*(dc_norm(2,inres)* &
3400 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3401 Im(2,2)=Im(2,2)+Isc(iti)*(1-dc_norm(2,inres)* &
3402 dc_norm(2,inres))*vbld(inres)*vbld(inres)
3403 Im(3,3)=Im(3,3)+Isc(iti)*(1-dc_norm(3,inres)* &
3404 dc_norm(3,inres))*vbld(inres)*vbld(inres)
3409 ! write(iout,*) "The angular momentum before adjustment:"
3410 ! write(iout,*) (L(j),j=1,3)
3416 ! Copying the Im matrix for the djacob subroutine
3424 ! Finding the eigenvectors and eignvalues of the inertia tensor
3425 call djacob(3,3,10000,1.0d-10,Imcp,eigvec,eigval)
3426 ! write (iout,*) "Eigenvalues & Eigenvectors"
3427 ! write (iout,'(5x,3f10.5)') (eigval(i),i=1,3)
3430 ! write (iout,'(i5,3f10.5)') i,(eigvec(i,j),j=1,3)
3432 ! Constructing the diagonalized matrix
3434 if (dabs(eigval(i)).gt.1.0d-15) then
3435 Id(i,i)=1.0d0/eigval(i)
3442 Imcp(i,j)=eigvec(j,i)
3448 pr1(i,j)=pr1(i,j)+Id(i,k)*Imcp(k,j)
3455 pr2(i,j)=pr2(i,j)+eigvec(i,k)*pr1(k,j)
3459 ! Calculating the total rotational velocity of the molecule
3462 vrot(i)=vrot(i)+pr2(i,j)*L(j)
3465 ! Resetting the velocities
3467 call vecpr(vrot(1),dc(1,i),vp)
3469 d_t(j,i)=d_t(j,i)-vp(j)
3473 if(itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3475 call vecpr(vrot(1),dc(1,inres),vp)
3477 d_t(j,inres)=d_t(j,inres)-vp(j)
3482 ! write(iout,*) "The angular momentum after adjustment:"
3483 ! write(iout,*) (L(j),j=1,3)
3486 end subroutine inertia_tensor
3487 !-----------------------------------------------------------------------------
3488 subroutine angmom(cm,L)
3491 ! implicit real*8 (a-h,o-z)
3492 ! include 'DIMENSIONS'
3493 ! include 'COMMON.CONTROL'
3494 ! include 'COMMON.VAR'
3495 ! include 'COMMON.MD'
3496 ! include 'COMMON.CHAIN'
3497 ! include 'COMMON.DERIV'
3498 ! include 'COMMON.GEO'
3499 ! include 'COMMON.LOCAL'
3500 ! include 'COMMON.INTERACT'
3501 ! include 'COMMON.IOUNITS'
3502 ! include 'COMMON.NAMES'
3504 real(kind=8),dimension(3) :: L,cm,pr,vp,vrot,incr,v,pp
3505 integer :: iti,inres,i,j
3506 ! Calculate the angular momentum
3515 pr(j)=c(j,i)+0.5d0*dc(j,i)-cm(j)
3518 v(j)=incr(j)+0.5d0*d_t(j,i)
3521 incr(j)=incr(j)+d_t(j,i)
3523 call vecpr(pr(1),v(1),vp)
3529 pp(j)=0.5d0*d_t(j,i)
3531 call vecpr(pr(1),pp(1),vp)
3543 pr(j)=c(j,inres)-cm(j)
3545 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3547 v(j)=incr(j)+d_t(j,inres)
3554 call vecpr(pr(1),v(1),vp)
3555 ! write (iout,*) "i",i," iti",iti," pr",(pr(j),j=1,3),
3556 ! & " v",(v(j),j=1,3)," vp",(vp(j),j=1,3)
3558 L(j)=L(j)+msc(iabs(iti))*vp(j)
3560 ! write (iout,*) "L",(l(j),j=1,3)
3561 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3563 v(j)=incr(j)+d_t(j,inres)
3565 call vecpr(dc(1,inres),d_t(1,inres),vp)
3567 L(j)=L(j)+Isc(iti)*vp(j)
3571 incr(j)=incr(j)+d_t(j,i)
3575 end subroutine angmom
3576 !-----------------------------------------------------------------------------
3577 subroutine vcm_vel(vcm)
3580 ! implicit real*8 (a-h,o-z)
3581 ! include 'DIMENSIONS'
3582 ! include 'COMMON.VAR'
3583 ! include 'COMMON.MD'
3584 ! include 'COMMON.CHAIN'
3585 ! include 'COMMON.DERIV'
3586 ! include 'COMMON.GEO'
3587 ! include 'COMMON.LOCAL'
3588 ! include 'COMMON.INTERACT'
3589 ! include 'COMMON.IOUNITS'
3590 real(kind=8),dimension(3) :: vcm,vv
3591 real(kind=8) :: summas,amas
3603 vcm(j)=vcm(j)+mp*(vv(j)+0.5d0*d_t(j,i))
3606 amas=msc(iabs(itype(i)))
3608 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
3610 vcm(j)=vcm(j)+amas*(vv(j)+d_t(j,i+nres))
3614 vcm(j)=vcm(j)+amas*vv(j)
3618 vv(j)=vv(j)+d_t(j,i)
3621 ! write (iout,*) "vcm",(vcm(j),j=1,3)," summas",summas
3623 vcm(j)=vcm(j)/summas
3626 end subroutine vcm_vel
3627 !-----------------------------------------------------------------------------
3629 !-----------------------------------------------------------------------------
3631 ! RATTLE algorithm for velocity Verlet - step 1, UNRES
3635 ! implicit real*8 (a-h,o-z)
3636 ! include 'DIMENSIONS'
3638 ! include 'COMMON.CONTROL'
3639 ! include 'COMMON.VAR'
3640 ! include 'COMMON.MD'
3642 ! include 'COMMON.LANGEVIN'
3644 ! include 'COMMON.LANGEVIN.lang0'
3646 ! include 'COMMON.CHAIN'
3647 ! include 'COMMON.DERIV'
3648 ! include 'COMMON.GEO'
3649 ! include 'COMMON.LOCAL'
3650 ! include 'COMMON.INTERACT'
3651 ! include 'COMMON.IOUNITS'
3652 ! include 'COMMON.NAMES'
3653 ! include 'COMMON.TIME1'
3654 !el real(kind=8) :: gginv(2*nres,2*nres),&
3655 !el gdc(3,2*nres,2*nres)
3656 real(kind=8) :: dC_uncor(3,2*nres) !,&
3657 !el real(kind=8) :: Cmat(2*nres,2*nres)
3658 real(kind=8) :: x(2*nres),xcorr(3,2*nres) !maxres2=2*maxres
3659 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
3660 !el common /przechowalnia/ nbond
3661 integer :: max_rattle = 5
3662 logical :: lprn = .false., lprn1 = .false., not_done
3663 real(kind=8) :: tol_rattle = 1.0d-5
3665 integer :: ii,i,j,jj,l,ind,ind1,nres2
3668 !el /common/ przechowalnia
3670 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
3671 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
3672 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
3674 if (lprn) write (iout,*) "RATTLE1"
3677 if (itype(i).ne.10) nbond=nbond+1
3679 ! Make a folded form of the Ginv-matrix
3692 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
3696 if (itype(k).ne.10) then
3700 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
3707 if (itype(i).ne.10) then
3717 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
3721 if (itype(k).ne.10) then
3725 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=Ginv(ind,ind1)
3733 write (iout,*) "Matrix GGinv"
3734 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
3740 if (iter.gt.max_rattle) then
3741 write (iout,*) "Error - too many iterations in RATTLE."
3744 ! Calculate the matrix C = GG**(-1) dC_old o dC
3749 dC_uncor(j,ind1)=dC(j,i)
3753 if (itype(i).ne.10) then
3756 dC_uncor(j,ind1)=dC(j,i+nres)
3765 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
3769 if (itype(k).ne.10) then
3772 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
3777 ! Calculate deviations from standard virtual-bond lengths
3781 x(ind)=vbld(i+1)**2-vbl**2
3784 if (itype(i).ne.10) then
3786 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
3790 write (iout,*) "Coordinates and violations"
3792 write(iout,'(i5,3f10.5,5x,e15.5)') &
3793 i,(dC_uncor(j,i),j=1,3),x(i)
3795 write (iout,*) "Velocities and violations"
3799 write (iout,'(2i5,3f10.5,5x,e15.5)') &
3800 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
3803 if (itype(i).ne.10) then
3805 write (iout,'(2i5,3f10.5,5x,e15.5)') &
3806 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
3807 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
3810 ! write (iout,*) "gdc"
3812 ! write (iout,*) "i",i
3814 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
3820 if (dabs(x(i)).gt.xmax) then
3824 if (xmax.lt.tol_rattle) then
3828 ! Calculate the matrix of the system of equations
3833 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
3838 write (iout,*) "Matrix Cmat"
3839 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
3841 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
3842 ! Add constraint term to positions
3849 xx = xx+x(ii)*gdc(j,ind,ii)
3853 d_t_new(j,i)=d_t_new(j,i)-xx/d_time
3857 if (itype(i).ne.10) then
3862 xx = xx+x(ii)*gdc(j,ind,ii)
3865 dC(j,i+nres)=dC(j,i+nres)-xx
3866 d_t_new(j,i+nres)=d_t_new(j,i+nres)-xx/d_time
3870 ! Rebuild the chain using the new coordinates
3871 call chainbuild_cart
3873 write (iout,*) "New coordinates, Lagrange multipliers,",&
3874 " and differences between actual and standard bond lengths"
3878 xx=vbld(i+1)**2-vbl**2
3879 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
3880 i,(dC(j,i),j=1,3),x(ind),xx
3883 if (itype(i).ne.10) then
3885 xx=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
3886 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
3887 i,(dC(j,i+nres),j=1,3),x(ind),xx
3890 write (iout,*) "Velocities and violations"
3894 write (iout,'(2i5,3f10.5,5x,e15.5)') &
3895 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
3898 if (itype(i).ne.10) then
3900 write (iout,'(2i5,3f10.5,5x,e15.5)') &
3901 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
3902 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
3909 10 write (iout,*) "Error - singularity in solving the system",&
3910 " of equations for Lagrange multipliers."
3914 "RATTLE inactive; use -DRATTLE switch at compile time."
3917 end subroutine rattle1
3918 !-----------------------------------------------------------------------------
3920 ! RATTLE algorithm for velocity Verlet - step 2, UNRES
3924 ! implicit real*8 (a-h,o-z)
3925 ! include 'DIMENSIONS'
3927 ! include 'COMMON.CONTROL'
3928 ! include 'COMMON.VAR'
3929 ! include 'COMMON.MD'
3931 ! include 'COMMON.LANGEVIN'
3933 ! include 'COMMON.LANGEVIN.lang0'
3935 ! include 'COMMON.CHAIN'
3936 ! include 'COMMON.DERIV'
3937 ! include 'COMMON.GEO'
3938 ! include 'COMMON.LOCAL'
3939 ! include 'COMMON.INTERACT'
3940 ! include 'COMMON.IOUNITS'
3941 ! include 'COMMON.NAMES'
3942 ! include 'COMMON.TIME1'
3943 !el real(kind=8) :: gginv(2*nres,2*nres),&
3944 !el gdc(3,2*nres,2*nres)
3945 real(kind=8) :: dC_uncor(3,2*nres) !,&
3946 !el Cmat(2*nres,2*nres)
3947 real(kind=8) :: x(2*nres) !maxres2=2*maxres
3948 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
3949 !el common /przechowalnia/ nbond
3950 integer :: max_rattle = 5
3951 logical :: lprn = .false., lprn1 = .false., not_done
3952 real(kind=8) :: tol_rattle = 1.0d-5
3956 !el /common/ przechowalnia
3957 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
3958 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
3959 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
3961 if (lprn) write (iout,*) "RATTLE2"
3962 if (lprn) write (iout,*) "Velocity correction"
3963 ! Calculate the matrix G dC
3969 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k)
3973 if (itype(k).ne.10) then
3976 gdc(j,i,ind)=GGinv(i,ind)*dC(j,k+nres)
3982 ! write (iout,*) "gdc"
3984 ! write (iout,*) "i",i
3986 ! write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
3990 ! Calculate the matrix of the system of equations
3997 Cmat(ind,j)=Cmat(ind,j)+dC(k,i)*gdc(k,ind,j)
4002 if (itype(i).ne.10) then
4007 Cmat(ind,j)=Cmat(ind,j)+dC(k,i+nres)*gdc(k,ind,j)
4012 ! Calculate the scalar product dC o d_t_new
4016 x(ind)=scalar(d_t(1,i),dC(1,i))
4019 if (itype(i).ne.10) then
4021 x(ind)=scalar(d_t(1,i+nres),dC(1,i+nres))
4025 write (iout,*) "Velocities and violations"
4029 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4030 i,ind,(d_t(j,i),j=1,3),x(ind)
4033 if (itype(i).ne.10) then
4035 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4036 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind)
4042 if (dabs(x(i)).gt.xmax) then
4046 if (xmax.lt.tol_rattle) then
4051 write (iout,*) "Matrix Cmat"
4052 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4054 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4055 ! Add constraint term to velocities
4062 xx = xx+x(ii)*gdc(j,ind,ii)
4064 d_t(j,i)=d_t(j,i)-xx
4068 if (itype(i).ne.10) then
4073 xx = xx+x(ii)*gdc(j,ind,ii)
4075 d_t(j,i+nres)=d_t(j,i+nres)-xx
4081 "New velocities, Lagrange multipliers violations"
4085 if (lprn) write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4086 i,ind,(d_t(j,i),j=1,3),x(ind),scalar(d_t(1,i),dC(1,i))
4089 if (itype(i).ne.10) then
4091 write (iout,'(2i5,3f10.5,5x,2e15.5)') &
4092 i+nres,ind,(d_t(j,i+nres),j=1,3),x(ind),&
4093 scalar(d_t(1,i+nres),dC(1,i+nres))
4099 10 write (iout,*) "Error - singularity in solving the system",&
4100 " of equations for Lagrange multipliers."
4104 "RATTLE inactive; use -DRATTLE option at compile time."
4107 end subroutine rattle2
4108 !-----------------------------------------------------------------------------
4109 subroutine rattle_brown
4110 ! RATTLE/LINCS algorithm for Brownian dynamics, UNRES
4114 ! implicit real*8 (a-h,o-z)
4115 ! include 'DIMENSIONS'
4117 ! include 'COMMON.CONTROL'
4118 ! include 'COMMON.VAR'
4119 ! include 'COMMON.MD'
4121 ! include 'COMMON.LANGEVIN'
4123 ! include 'COMMON.LANGEVIN.lang0'
4125 ! include 'COMMON.CHAIN'
4126 ! include 'COMMON.DERIV'
4127 ! include 'COMMON.GEO'
4128 ! include 'COMMON.LOCAL'
4129 ! include 'COMMON.INTERACT'
4130 ! include 'COMMON.IOUNITS'
4131 ! include 'COMMON.NAMES'
4132 ! include 'COMMON.TIME1'
4133 !el real(kind=8) :: gginv(2*nres,2*nres),&
4134 !el gdc(3,2*nres,2*nres)
4135 real(kind=8) :: dC_uncor(3,2*nres) !,&
4136 !el real(kind=8) :: Cmat(2*nres,2*nres)
4137 real(kind=8) :: x(2*nres) !maxres2=2*maxres
4138 !el common /przechowalnia/ GGinv,gdc,Cmat,nbond
4139 !el common /przechowalnia/ nbond
4140 integer :: max_rattle = 5
4141 logical :: lprn = .true., lprn1 = .true., not_done
4142 real(kind=8) :: tol_rattle = 1.0d-5
4146 !el /common/ przechowalnia
4147 if(.not.allocated(GGinv)) allocate(GGinv(nres2,nres2))
4148 if(.not.allocated(gdc)) allocate(gdc(3,nres2,nres2))
4149 if(.not.allocated(Cmat)) allocate(Cmat(nres2,nres2))
4152 if (lprn) write (iout,*) "RATTLE_BROWN"
4155 if (itype(i).ne.10) nbond=nbond+1
4157 ! Make a folded form of the Ginv-matrix
4170 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4174 if (itype(k).ne.10) then
4178 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4185 if (itype(i).ne.10) then
4195 if (j.eq.1 .and. l.eq.1) GGinv(ii,jj)=fricmat(ind,ind1)
4199 if (itype(k).ne.10) then
4203 if (j.eq.1 .and. l.eq.1)GGinv(ii,jj)=fricmat(ind,ind1)
4211 write (iout,*) "Matrix GGinv"
4212 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,GGinv)
4218 if (iter.gt.max_rattle) then
4219 write (iout,*) "Error - too many iterations in RATTLE."
4222 ! Calculate the matrix C = GG**(-1) dC_old o dC
4227 dC_uncor(j,ind1)=dC(j,i)
4231 if (itype(i).ne.10) then
4234 dC_uncor(j,ind1)=dC(j,i+nres)
4243 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k)
4247 if (itype(k).ne.10) then
4250 gdc(j,i,ind)=GGinv(i,ind)*dC_old(j,k+nres)
4255 ! Calculate deviations from standard virtual-bond lengths
4259 x(ind)=vbld(i+1)**2-vbl**2
4262 if (itype(i).ne.10) then
4264 x(ind)=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
4268 write (iout,*) "Coordinates and violations"
4270 write(iout,'(i5,3f10.5,5x,e15.5)') &
4271 i,(dC_uncor(j,i),j=1,3),x(i)
4273 write (iout,*) "Velocities and violations"
4277 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4278 i,ind,(d_t(j,i),j=1,3),scalar(d_t(1,i),dC_old(1,i))
4281 if (itype(i).ne.10) then
4283 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4284 i+nres,ind,(d_t(j,i+nres),j=1,3),&
4285 scalar(d_t(1,i+nres),dC_old(1,i+nres))
4288 write (iout,*) "gdc"
4290 write (iout,*) "i",i
4292 write (iout,'(i5,3f10.5)') j,(gdc(k,j,i),k=1,3)
4298 if (dabs(x(i)).gt.xmax) then
4302 if (xmax.lt.tol_rattle) then
4306 ! Calculate the matrix of the system of equations
4311 Cmat(i,j)=Cmat(i,j)+dC_uncor(k,i)*gdc(k,i,j)
4316 write (iout,*) "Matrix Cmat"
4317 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
4319 call gauss(Cmat,X,MAXRES2,nbond,1,*10)
4320 ! Add constraint term to positions
4327 xx = xx+x(ii)*gdc(j,ind,ii)
4330 d_t(j,i)=d_t(j,i)+xx/d_time
4335 if (itype(i).ne.10) then
4340 xx = xx+x(ii)*gdc(j,ind,ii)
4343 d_t(j,i+nres)=d_t(j,i+nres)+xx/d_time
4344 dC(j,i+nres)=dC(j,i+nres)+xx
4348 ! Rebuild the chain using the new coordinates
4349 call chainbuild_cart
4351 write (iout,*) "New coordinates, Lagrange multipliers,",&
4352 " and differences between actual and standard bond lengths"
4356 xx=vbld(i+1)**2-vbl**2
4357 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4358 i,(dC(j,i),j=1,3),x(ind),xx
4361 if (itype(i).ne.10) then
4363 xx=vbld(i+nres)**2-vbldsc0(1,itype(i))**2
4364 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)') &
4365 i,(dC(j,i+nres),j=1,3),x(ind),xx
4368 write (iout,*) "Velocities and violations"
4372 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4373 i,ind,(d_t_new(j,i),j=1,3),scalar(d_t_new(1,i),dC_old(1,i))
4376 if (itype(i).ne.10) then
4378 write (iout,'(2i5,3f10.5,5x,e15.5)') &
4379 i+nres,ind,(d_t_new(j,i+nres),j=1,3),&
4380 scalar(d_t_new(1,i+nres),dC_old(1,i+nres))
4387 10 write (iout,*) "Error - singularity in solving the system",&
4388 " of equations for Lagrange multipliers."
4392 "RATTLE inactive; use -DRATTLE option at compile time"
4395 end subroutine rattle_brown
4396 !-----------------------------------------------------------------------------
4398 !-----------------------------------------------------------------------------
4399 subroutine friction_force
4404 ! implicit real*8 (a-h,o-z)
4405 ! include 'DIMENSIONS'
4406 ! include 'COMMON.VAR'
4407 ! include 'COMMON.CHAIN'
4408 ! include 'COMMON.DERIV'
4409 ! include 'COMMON.GEO'
4410 ! include 'COMMON.LOCAL'
4411 ! include 'COMMON.INTERACT'
4412 ! include 'COMMON.MD'
4414 ! include 'COMMON.LANGEVIN'
4416 ! include 'COMMON.LANGEVIN.lang0'
4418 ! include 'COMMON.IOUNITS'
4419 !el real(kind=8),dimension(6*nres) :: gamvec !(MAXRES6) maxres6=6*maxres
4420 !el common /syfek/ gamvec
4421 real(kind=8) :: vv(3),vvtot(3,nres),v_work(6*nres) !,&
4422 !el ginvfric(2*nres,2*nres) !maxres2=2*maxres
4423 !el common /przechowalnia/ ginvfric
4425 logical :: lprn = .false., checkmode = .false.
4426 integer :: i,j,ind,k,nres2,nres6
4430 if(.not.allocated(gamvec)) allocate(gamvec(nres6)) !(MAXRES6)
4431 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
4439 d_t_work(j)=d_t(j,0)
4444 d_t_work(ind+j)=d_t(j,i)
4449 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
4451 d_t_work(ind+j)=d_t(j,i+nres)
4457 call fricmat_mult(d_t_work,fric_work)
4459 if (.not.checkmode) return
4462 write (iout,*) "d_t_work and fric_work"
4464 write (iout,'(i3,2e15.5)') i,d_t_work(i),fric_work(i)
4468 friction(j,0)=fric_work(j)
4473 friction(j,i)=fric_work(ind+j)
4478 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
4480 friction(j,i+nres)=fric_work(ind+j)
4486 write(iout,*) "Friction backbone"
4488 write(iout,'(i5,3e15.5,5x,3e15.5)') &
4489 i,(friction(j,i),j=1,3),(d_t(j,i),j=1,3)
4491 write(iout,*) "Friction side chain"
4493 write(iout,'(i5,3e15.5,5x,3e15.5)') &
4494 i,(friction(j,i+nres),j=1,3),(d_t(j,i+nres),j=1,3)
4503 vvtot(j,i)=vv(j)+0.5d0*d_t(j,i)
4504 vvtot(j,i+nres)=vv(j)+d_t(j,i+nres)
4505 vv(j)=vv(j)+d_t(j,i)
4508 write (iout,*) "vvtot backbone and sidechain"
4510 write (iout,'(i5,3e15.5,5x,3e15.5)') i,(vvtot(j,i),j=1,3),&
4511 (vvtot(j,i+nres),j=1,3)
4516 v_work(ind+j)=vvtot(j,i)
4522 v_work(ind+j)=vvtot(j,i+nres)
4526 write (iout,*) "v_work gamvec and site-based friction forces"
4528 write (iout,'(i5,3e15.5)') i,v_work(i),gamvec(i),&
4532 ! fric_work1(i)=0.0d0
4534 ! fric_work1(i)=fric_work1(i)-A(j,i)*gamvec(j)*v_work(j)
4537 ! write (iout,*) "fric_work and fric_work1"
4539 ! write (iout,'(i5,2e15.5)') i,fric_work(i),fric_work1(i)
4545 ginvfric(i,j)=ginvfric(i,j)+ginv(i,k)*fricmat(k,j)
4549 write (iout,*) "ginvfric"
4551 write (iout,'(i5,100f8.3)') i,(ginvfric(i,j),j=1,dimen)
4553 write (iout,*) "symmetry check"
4556 write (iout,*) i,j,ginvfric(i,j)-ginvfric(j,i)
4561 end subroutine friction_force
4562 !-----------------------------------------------------------------------------
4563 subroutine setup_fricmat
4566 use control_data, only:time_Bcast
4567 use control, only:tcpu
4569 ! implicit real*8 (a-h,o-z)
4573 real(kind=8) :: time00
4575 ! include 'DIMENSIONS'
4576 ! include 'COMMON.VAR'
4577 ! include 'COMMON.CHAIN'
4578 ! include 'COMMON.DERIV'
4579 ! include 'COMMON.GEO'
4580 ! include 'COMMON.LOCAL'
4581 ! include 'COMMON.INTERACT'
4582 ! include 'COMMON.MD'
4583 ! include 'COMMON.SETUP'
4584 ! include 'COMMON.TIME1'
4585 ! integer licznik /0/
4588 ! include 'COMMON.LANGEVIN'
4590 ! include 'COMMON.LANGEVIN.lang0'
4592 ! include 'COMMON.IOUNITS'
4594 integer :: i,j,ind,ind1,m
4595 logical :: lprn = .false.
4596 real(kind=8) :: dtdi !el ,gamvec(2*nres)
4597 !el real(kind=8),dimension(2*nres,2*nres) :: ginvfric,fcopy
4598 real(kind=8),dimension(2*nres,2*nres) :: fcopy
4599 !el real(kind=8),dimension(2*nres*(2*nres+1)/2) :: Ghalf !(mmaxres2) (mmaxres2=(maxres2*(maxres2+1)/2))
4600 !el common /syfek/ gamvec
4601 real(kind=8) :: work(8*2*nres)
4602 integer :: iwork(2*nres)
4603 !el common /przechowalnia/ ginvfric,Ghalf,fcopy
4604 integer :: ii,iti,k,l,nzero,nres2,nres6,ierr
4606 if (fg_rank.ne.king) goto 10
4611 if(.not.allocated(gamvec)) allocate(gamvec(nres2)) !(MAXRES2)
4612 if(.not.allocated(ginvfric)) allocate(ginvfric(nres2,nres2)) !maxres2=2*maxres
4613 !el if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
4614 !el allocate(fcopy(nres2,nres2)) !maxres2=2*maxres
4615 if(.not.allocated(Ghalf)) allocate(Ghalf(nres2*(nres2+1)/2)) !maxres2=2*maxres
4617 !el if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
4618 ! Zeroing out fricmat
4624 ! Load the friction coefficients corresponding to peptide groups
4630 ! Load the friction coefficients corresponding to side chains
4638 gamvec(ii)=gamsc(iabs(iti))
4640 if (surfarea) call sdarea(gamvec)
4642 ! write (iout,*) "Matrix A and vector gamma"
4644 ! write (iout,'(i2,$)') i
4646 ! write (iout,'(f4.1,$)') A(i,j)
4648 ! write (iout,'(f8.3)') gamvec(i)
4652 write (iout,*) "Vector gamvec"
4654 write (iout,'(i5,f10.5)') i, gamvec(i)
4658 ! The friction matrix
4663 dtdi=dtdi+A(j,k)*A(j,i)*gamvec(j)
4670 write (iout,'(//a)') "Matrix fricmat"
4671 call matout2(dimen,dimen,nres2,nres2,fricmat)
4673 if (lang.eq.2 .or. lang.eq.3) then
4674 ! Mass-scale the friction matrix if non-direct integration will be performed
4680 Ginvfric(i,j)=Ginvfric(i,j)+ &
4681 Gsqrm(i,k)*Gsqrm(l,j)*fricmat(k,l)
4686 ! Diagonalize the friction matrix
4691 Ghalf(ind)=Ginvfric(i,j)
4694 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
4697 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
4698 " mass-scaled friction matrix"
4699 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
4701 ! Precompute matrices for tinker stochastic integrator
4708 mt1(i,j)=mt1(i,j)+fricvec(k,i)*gsqrm(k,j)
4709 mt2(i,j)=mt2(i,j)+fricvec(k,i)*gsqrp(k,j)
4715 else if (lang.eq.4) then
4716 ! Diagonalize the friction matrix
4721 Ghalf(ind)=fricmat(i,j)
4724 call gldiag(nres2,dimen,dimen,Ghalf,work,fricgam,fricvec,&
4727 write (iout,'(//2a)') "Eigenvectors and eigenvalues of the",&
4729 call eigout(dimen,dimen,nres2,nres2,fricvec,fricgam)
4731 ! Determine the number of zero eigenvalues of the friction matrix
4732 nzero=max0(dimen-dimen1,0)
4733 ! do while (fricgam(nzero+1).le.1.0d-5 .and. nzero.lt.dimen)
4736 write (iout,*) "Number of zero eigenvalues:",nzero
4741 fricmat(i,j)=fricmat(i,j) &
4742 +fricvec(i,k)*fricvec(j,k)/fricgam(k)
4747 write (iout,'(//a)') "Generalized inverse of fricmat"
4748 call matout(dimen,dimen,nres6,nres6,fricmat)
4753 if (nfgtasks.gt.1) then
4754 if (fg_rank.eq.0) then
4755 ! The matching BROADCAST for fg processors is called in ERGASTULUM
4761 call MPI_Bcast(10,1,MPI_INTEGER,king,FG_COMM,IERROR)
4763 time_Bcast=time_Bcast+MPI_Wtime()-time00
4765 time_Bcast=time_Bcast+tcpu()-time00
4767 ! print *,"Processor",myrank,
4768 ! & " BROADCAST iorder in SETUP_FRICMAT"
4771 write (iout,*) "setup_fricmat licznik"!,licznik !sp
4777 write(iout,*)"przed MPI_Scatterv in fricmat"
4778 ! Scatter the friction matrix
4779 call MPI_Scatterv(fricmat(1,1),nginv_counts(0),&
4780 nginv_start(0),MPI_DOUBLE_PRECISION,fcopy(1,1),&
4781 myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERROR)
4782 write(iout,*)"po MPI_Scatterv in fricmat"
4785 time_scatter=time_scatter+MPI_Wtime()-time00
4786 time_scatter_fmat=time_scatter_fmat+MPI_Wtime()-time00
4788 time_scatter=time_scatter+tcpu()-time00
4789 time_scatter_fmat=time_scatter_fmat+tcpu()-time00
4792 write(iout,*)"po MPI_Scatterv in fricmat"
4794 do j=1,2*my_ng_count
4795 fricmat(j,i)=fcopy(i,j)
4798 write(iout,*)"po MPI_Scatterv in fricmat"
4799 ! write (iout,*) "My chunk of fricmat"
4800 ! call MATOUT2(my_ng_count,dimen,maxres2,maxres2,fcopy)
4804 end subroutine setup_fricmat
4805 !-----------------------------------------------------------------------------
4806 subroutine stochastic_force(stochforcvec)
4809 use random, only:anorm_distr
4810 ! implicit real*8 (a-h,o-z)
4811 ! include 'DIMENSIONS'
4812 use control, only: tcpu
4817 ! include 'COMMON.VAR'
4818 ! include 'COMMON.CHAIN'
4819 ! include 'COMMON.DERIV'
4820 ! include 'COMMON.GEO'
4821 ! include 'COMMON.LOCAL'
4822 ! include 'COMMON.INTERACT'
4823 ! include 'COMMON.MD'
4824 ! include 'COMMON.TIME1'
4826 ! include 'COMMON.LANGEVIN'
4828 ! include 'COMMON.LANGEVIN.lang0'
4830 ! include 'COMMON.IOUNITS'
4832 real(kind=8) :: x,sig,lowb,highb
4833 real(kind=8) :: ff(3),force(3,0:2*nres),zeta2,lowb2
4834 real(kind=8) :: highb2,sig2,forcvec(6*nres),stochforcvec(6*nres)
4835 real(kind=8) :: time00
4836 logical :: lprn = .false.
4841 stochforc(j,i)=0.0d0
4851 ! Compute the stochastic forces acting on bodies. Store in force.
4857 force(j,i)=anorm_distr(x,sig,lowb,highb)
4865 force(j,i+nres)=anorm_distr(x,sig2,lowb2,highb2)
4869 time_fsample=time_fsample+MPI_Wtime()-time00
4871 time_fsample=time_fsample+tcpu()-time00
4873 ! Compute the stochastic forces acting on virtual-bond vectors.
4879 stochforc(j,i)=ff(j)+0.5d0*force(j,i)
4882 ff(j)=ff(j)+force(j,i)
4884 if (itype(i+1).ne.ntyp1) then
4886 stochforc(j,i)=stochforc(j,i)+force(j,i+nres+1)
4887 ff(j)=ff(j)+force(j,i+nres+1)
4892 stochforc(j,0)=ff(j)+force(j,nnt+nres)
4895 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
4897 stochforc(j,i+nres)=force(j,i+nres)
4903 stochforcvec(j)=stochforc(j,0)
4908 stochforcvec(ind+j)=stochforc(j,i)
4913 if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
4915 stochforcvec(ind+j)=stochforc(j,i+nres)
4921 write (iout,*) "stochforcvec"
4923 write(iout,'(i5,e15.5)') i,stochforcvec(i)
4925 write(iout,*) "Stochastic forces backbone"
4927 write(iout,'(i5,3e15.5)') i,(stochforc(j,i),j=1,3)
4929 write(iout,*) "Stochastic forces side chain"
4931 write(iout,'(i5,3e15.5)') &
4932 i,(stochforc(j,i+nres),j=1,3)
4940 write (iout,*) i,ind
4942 forcvec(ind+j)=force(j,i)
4947 write (iout,*) i,ind
4949 forcvec(j+ind)=force(j,i+nres)
4954 write (iout,*) "forcvec"
4958 write (iout,'(2i3,2f10.5)') i,j,force(j,i),&
4965 write (iout,'(2i3,2f10.5)') i,j,force(j,i+nres),&
4974 end subroutine stochastic_force
4975 !-----------------------------------------------------------------------------
4976 subroutine sdarea(gamvec)
4978 ! Scale the friction coefficients according to solvent accessible surface areas
4979 ! Code adapted from TINKER
4983 ! implicit real*8 (a-h,o-z)
4984 ! include 'DIMENSIONS'
4985 ! include 'COMMON.CONTROL'
4986 ! include 'COMMON.VAR'
4987 ! include 'COMMON.MD'
4989 ! include 'COMMON.LANGEVIN'
4991 ! include 'COMMON.LANGEVIN.lang0'
4993 ! include 'COMMON.CHAIN'
4994 ! include 'COMMON.DERIV'
4995 ! include 'COMMON.GEO'
4996 ! include 'COMMON.LOCAL'
4997 ! include 'COMMON.INTERACT'
4998 ! include 'COMMON.IOUNITS'
4999 ! include 'COMMON.NAMES'
5000 real(kind=8),dimension(2*nres) :: radius,gamvec !(maxres2)
5001 real(kind=8),parameter :: twosix = 1.122462048309372981d0
5002 logical :: lprn = .false.
5003 real(kind=8) :: probe,area,ratio
5004 integer :: i,j,ind,iti
5006 ! determine new friction coefficients every few SD steps
5008 ! set the atomic radii to estimates of sigma values
5010 ! print *,"Entered sdarea"
5016 ! Load peptide group radii
5020 ! Load side chain radii
5023 radius(i+nres)=restok(iti)
5026 ! write (iout,*) "i",i," radius",radius(i)
5029 radius(i) = radius(i) / twosix
5030 if (radius(i) .ne. 0.0d0) radius(i) = radius(i) + probe
5033 ! scale atomic friction coefficients by accessible area
5035 if (lprn) write (iout,*) &
5036 "Original gammas, surface areas, scaling factors, new gammas, ",&
5037 "std's of stochastic forces"
5040 if (radius(i).gt.0.0d0) then
5041 call surfatom (i,area,radius)
5042 ratio = dmax1(area/(4.0d0*pi*radius(i)**2),1.0d-1)
5043 if (lprn) write (iout,'(i5,3f10.5,$)') &
5044 i,gamvec(ind+1),area,ratio
5047 gamvec(ind) = ratio * gamvec(ind)
5049 stdforcp(i)=stdfp*dsqrt(gamvec(ind))
5050 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcp(i)
5054 if (radius(i+nres).gt.0.0d0) then
5055 call surfatom (i+nres,area,radius)
5056 ratio = dmax1(area/(4.0d0*pi*radius(i+nres)**2),1.0d-1)
5057 if (lprn) write (iout,'(i5,3f10.5,$)') &
5058 i,gamvec(ind+1),area,ratio
5061 gamvec(ind) = ratio * gamvec(ind)
5063 stdforcsc(i)=stdfsc(itype(i))*dsqrt(gamvec(ind))
5064 if (lprn) write (iout,'(2f10.5)') gamvec(ind),stdforcsc(i)
5069 end subroutine sdarea
5070 !-----------------------------------------------------------------------------
5072 !-----------------------------------------------------------------------------
5075 ! ###################################################
5076 ! ## COPYRIGHT (C) 1996 by Jay William Ponder ##
5077 ! ## All Rights Reserved ##
5078 ! ###################################################
5080 ! ################################################################
5082 ! ## subroutine surfatom -- exposed surface area of an atom ##
5084 ! ################################################################
5087 ! "surfatom" performs an analytical computation of the surface
5088 ! area of a specified atom; a simplified version of "surface"
5090 ! literature references:
5092 ! T. J. Richmond, "Solvent Accessible Surface Area and
5093 ! Excluded Volume in Proteins", Journal of Molecular Biology,
5096 ! L. Wesson and D. Eisenberg, "Atomic Solvation Parameters
5097 ! Applied to Molecular Dynamics of Proteins in Solution",
5098 ! Protein Science, 1, 227-235 (1992)
5100 ! variables and parameters:
5102 ! ir number of atom for which area is desired
5103 ! area accessible surface area of the atom
5104 ! radius radii of each of the individual atoms
5107 subroutine surfatom(ir,area,radius)
5109 ! implicit real*8 (a-h,o-z)
5110 ! include 'DIMENSIONS'
5112 ! include 'COMMON.GEO'
5113 ! include 'COMMON.IOUNITS'
5115 integer :: nsup,nstart_sup
5116 ! double precision c,dc,dc_old,d_c_work,xloc,xrot,dc_norm
5117 ! common /chain/ c(3,maxres2+2),dc(3,0:maxres2),dc_old(3,0:maxres2),
5118 ! & xloc(3,maxres),xrot(3,maxres),dc_norm(3,0:maxres2),
5119 ! & dc_work(MAXRES6),nres,nres0
5120 integer,parameter :: maxarc=300
5124 integer :: mi,ni,narc
5125 integer :: key(maxarc)
5126 integer :: intag(maxarc)
5127 integer :: intag1(maxarc)
5128 real(kind=8) :: area,arcsum
5129 real(kind=8) :: arclen,exang
5130 real(kind=8) :: delta,delta2
5131 real(kind=8) :: eps,rmove
5132 real(kind=8) :: xr,yr,zr
5133 real(kind=8) :: rr,rrsq
5134 real(kind=8) :: rplus,rminus
5135 real(kind=8) :: axx,axy,axz
5136 real(kind=8) :: ayx,ayy
5137 real(kind=8) :: azx,azy,azz
5138 real(kind=8) :: uxj,uyj,uzj
5139 real(kind=8) :: tx,ty,tz
5140 real(kind=8) :: txb,tyb,td
5141 real(kind=8) :: tr2,tr,txr,tyr
5142 real(kind=8) :: tk1,tk2
5143 real(kind=8) :: thec,the,t,tb
5144 real(kind=8) :: txk,tyk,tzk
5145 real(kind=8) :: t1,ti,tf,tt
5146 real(kind=8) :: txj,tyj,tzj
5147 real(kind=8) :: ccsq,cc,xysq
5148 real(kind=8) :: bsqk,bk,cosine
5149 real(kind=8) :: dsqj,gi,pix2
5150 real(kind=8) :: therk,dk,gk
5151 real(kind=8) :: risqk,rik
5152 real(kind=8) :: radius(2*nres) !(maxatm) (maxatm=maxres2)
5153 real(kind=8) :: ri(maxarc),risq(maxarc)
5154 real(kind=8) :: ux(maxarc),uy(maxarc),uz(maxarc)
5155 real(kind=8) :: xc(maxarc),yc(maxarc),zc(maxarc)
5156 real(kind=8) :: xc1(maxarc),yc1(maxarc),zc1(maxarc)
5157 real(kind=8) :: dsq(maxarc),bsq(maxarc)
5158 real(kind=8) :: dsq1(maxarc),bsq1(maxarc)
5159 real(kind=8) :: arci(maxarc),arcf(maxarc)
5160 real(kind=8) :: ex(maxarc),lt(maxarc),gr(maxarc)
5161 real(kind=8) :: b(maxarc),b1(maxarc),bg(maxarc)
5162 real(kind=8) :: kent(maxarc),kout(maxarc)
5163 real(kind=8) :: ther(maxarc)
5164 logical :: moved,top
5165 logical :: omit(maxarc)
5168 maxatm = 2*nres !maxres2 maxres2=2*maxres
5174 ! zero out the surface area for the sphere of interest
5177 ! write (2,*) "ir",ir," radius",radius(ir)
5178 if (radius(ir) .eq. 0.0d0) return
5180 ! set the overlap significance and connectivity shift
5184 delta2 = delta * delta
5189 ! store coordinates and radius of the sphere of interest
5197 ! initialize values of some counters and summations
5206 ! test each sphere to see if it overlaps the sphere of interest
5209 if (i.eq.ir .or. radius(i).eq.0.0d0) goto 30
5210 rplus = rr + radius(i)
5212 if (abs(tx) .ge. rplus) goto 30
5214 if (abs(ty) .ge. rplus) goto 30
5216 if (abs(tz) .ge. rplus) goto 30
5218 ! check for sphere overlap by testing distance against radii
5220 xysq = tx*tx + ty*ty
5221 if (xysq .lt. delta2) then
5228 if (rplus-cc .le. delta) goto 30
5229 rminus = rr - radius(i)
5231 ! check to see if sphere of interest is completely buried
5233 if (cc-abs(rminus) .le. delta) then
5234 if (rminus .le. 0.0d0) goto 170
5238 ! check for too many overlaps with sphere of interest
5240 if (io .ge. maxarc) then
5242 20 format (/,' SURFATOM -- Increase the Value of MAXARC')
5246 ! get overlap between current sphere and sphere of interest
5255 gr(io) = (ccsq+rplus*rminus) / (2.0d0*rr*b1(io))
5261 ! case where no other spheres overlap the sphere of interest
5264 area = 4.0d0 * pi * rrsq
5268 ! case where only one sphere overlaps the sphere of interest
5271 area = pix2 * (1.0d0 + gr(1))
5272 area = mod(area,4.0d0*pi) * rrsq
5276 ! case where many spheres intersect the sphere of interest;
5277 ! sort the intersecting spheres by their degree of overlap
5279 call sort2 (io,gr,key)
5282 intag(i) = intag1(k)
5291 ! get radius of each overlap circle on surface of the sphere
5296 risq(i) = rrsq - gi*gi
5297 ri(i) = sqrt(risq(i))
5298 ther(i) = 0.5d0*pi - asin(min(1.0d0,max(-1.0d0,gr(i))))
5301 ! find boundary of inaccessible area on sphere of interest
5304 if (.not. omit(k)) then
5311 ! check to see if J circle is intersecting K circle;
5312 ! get distance between circle centers and sum of radii
5315 if (omit(j)) goto 60
5316 cc = (txk*xc(j)+tyk*yc(j)+tzk*zc(j))/(bk*b(j))
5317 cc = acos(min(1.0d0,max(-1.0d0,cc)))
5318 td = therk + ther(j)
5320 ! check to see if circles enclose separate regions
5322 if (cc .ge. td) goto 60
5324 ! check for circle J completely inside circle K
5326 if (cc+ther(j) .lt. therk) goto 40
5328 ! check for circles that are essentially parallel
5330 if (cc .gt. delta) goto 50
5335 ! check to see if sphere of interest is completely buried
5338 if (pix2-cc .le. td) goto 170
5344 ! find T value of circle intersections
5347 if (omit(k)) goto 110
5362 ! rotation matrix elements
5374 if (.not. omit(j)) then
5379 ! rotate spheres so K vector colinear with z-axis
5381 uxj = txj*axx + tyj*axy - tzj*axz
5382 uyj = tyj*ayy - txj*ayx
5383 uzj = txj*azx + tyj*azy + tzj*azz
5384 cosine = min(1.0d0,max(-1.0d0,uzj/b(j)))
5385 if (acos(cosine) .lt. therk+ther(j)) then
5386 dsqj = uxj*uxj + uyj*uyj
5391 tr2 = risqk*dsqj - tb*tb
5397 ! get T values of intersection for K circle
5400 tb = min(1.0d0,max(-1.0d0,tb))
5402 if (tyb-txr .lt. 0.0d0) tk1 = pix2 - tk1
5404 tb = min(1.0d0,max(-1.0d0,tb))
5406 if (tyb+txr .lt. 0.0d0) tk2 = pix2 - tk2
5407 thec = (rrsq*uzj-gk*bg(j)) / (rik*ri(j)*b(j))
5408 if (abs(thec) .lt. 1.0d0) then
5410 else if (thec .ge. 1.0d0) then
5412 else if (thec .le. -1.0d0) then
5416 ! see if "tk1" is entry or exit point; check t=0 point;
5417 ! "ti" is exit point, "tf" is entry point
5419 cosine = min(1.0d0,max(-1.0d0, &
5420 (uzj*gk-uxj*rik)/(b(j)*rr)))
5421 if ((acos(cosine)-ther(j))*(tk2-tk1) .le. 0.0d0) then
5429 if (narc .ge. maxarc) then
5431 70 format (/,' SURFATOM -- Increase the Value',&
5435 if (tf .le. ti) then
5456 ! special case; K circle without intersections
5458 if (narc .le. 0) goto 90
5460 ! general case; sum up arclength and set connectivity code
5462 call sort2 (narc,arci,key)
5467 if (narc .gt. 1) then
5470 if (t .lt. arci(j)) then
5471 arcsum = arcsum + arci(j) - t
5472 exang = exang + ex(ni)
5474 if (jb .ge. maxarc) then
5476 80 format (/,' SURFATOM -- Increase the Value',&
5481 kent(jb) = maxarc*i + k
5483 kout(jb) = maxarc*k + i
5492 arcsum = arcsum + pix2 - t
5494 exang = exang + ex(ni)
5497 kent(jb) = maxarc*i + k
5499 kout(jb) = maxarc*k + i
5506 arclen = arclen + gr(k)*arcsum
5509 if (arclen .eq. 0.0d0) goto 170
5510 if (jb .eq. 0) goto 150
5512 ! find number of independent boundaries and check connectivity
5516 if (kout(k) .ne. 0) then
5523 if (m .eq. kent(ii)) then
5526 if (j .eq. jb) goto 150
5538 ! attempt to fix connectivity error by moving atom slightly
5542 140 format (/,' SURFATOM -- Connectivity Error at Atom',i6)
5551 ! compute the exposed surface area for the sphere of interest
5554 area = ib*pix2 + exang + arclen
5555 area = mod(area,4.0d0*pi) * rrsq
5557 ! attempt to fix negative area by moving atom slightly
5559 if (area .lt. 0.0d0) then
5562 160 format (/,' SURFATOM -- Negative Area at Atom',i6)
5573 end subroutine surfatom
5574 !----------------------------------------------------------------
5575 !----------------------------------------------------------------
5576 subroutine alloc_MD_arrays
5577 !EL Allocation of arrays used by MD module
5579 integer :: nres2,nres6
5582 !----------------------
5586 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
5587 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
5588 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5589 allocate(fricvec(nres2,nres2))
5590 allocate(pfric_mat(nres2,nres2),vfric_mat(nres2,nres2))
5591 allocate(afric_mat(nres2,nres2),prand_mat(nres2,nres2))
5592 allocate(vrand_mat1(nres2,nres2),vrand_mat2(nres2,nres2)) !(MAXRES2,MAXRES2)
5593 allocate(pfric0_mat(nres2,nres2,0:maxflag_stoch))
5594 allocate(afric0_mat(nres2,nres2,0:maxflag_stoch))
5595 allocate(vfric0_mat(nres2,nres2,0:maxflag_stoch))
5596 allocate(prand0_mat(nres2,nres2,0:maxflag_stoch))
5597 allocate(vrand0_mat1(nres2,nres2,0:maxflag_stoch))
5598 allocate(vrand0_mat2(nres2,nres2,0:maxflag_stoch)) !(MAXRES2,MAXRES2,0:maxflag_stoch)
5599 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
5601 allocate(mt1(nres2,nres2),mt2(nres2,nres2),mt3(nres2,nres2)) !(maxres2,maxres2)
5602 !----------------------
5604 ! commom.langevin.lang0
5606 allocate(friction(3,0:nres2),stochforc(3,0:nres2)) !(3,0:MAXRES2)
5607 if(.not.allocated(fricmat)) allocate(fricmat(nres2,nres2))
5608 allocate(fricvec(nres2,nres2)) !(MAXRES2,MAXRES2)
5609 allocate(fric_work(nres6),stoch_work(nres6),fricgam(nres6)) !(MAXRES6)
5610 allocate(flag_stoch(0:maxflag_stoch)) !(0:maxflag_stoch)
5613 !el if(.not.allocated(fcopy)) allocate(fcopy(nres2,nres2))
5614 !----------------------
5615 ! commom.hairpin in CSA module
5616 !----------------------
5617 ! common.mce in MCM_MD module
5618 !----------------------
5620 ! common /mdgrad/ in module.energy
5621 ! common /back_constr/ in module.energy
5622 ! common /qmeas/ in module.energy
5625 allocate(potEcomp(0:n_ene+4)) !(0:n_ene+4)
5627 allocate(d_t(3,0:nres2),d_a(3,0:nres2),d_t_old(3,0:nres2)) !(3,0:MAXRES2)
5628 allocate(d_a_work(nres6)) !(6*MAXRES)
5629 allocate(Gmat(nres2,nres2),A(nres2,nres2))
5630 if(.not.allocated(Ginv)) allocate(Ginv(nres2,nres2)) !in control: ergastulum
5631 allocate(Gsqrp(nres2,nres2),Gsqrm(nres2,nres2),Gvec(nres2,nres2)) !(maxres2,maxres2)
5632 allocate(Geigen(nres2)) !(maxres2)
5633 if(.not.allocated(vtot)) allocate(vtot(nres2)) !(maxres2)
5634 ! common /inertia/ in io_conf: parmread
5635 ! real(kind=8),dimension(:),allocatable :: ISC,msc !(ntyp+1)
5636 ! common /langevin/in io read_MDpar
5637 ! real(kind=8),dimension(:),allocatable :: gamsc !(ntyp1)
5638 ! real(kind=8),dimension(:),allocatable :: stdfsc !(ntyp)
5639 ! in io_conf: parmread
5640 ! real(kind=8),dimension(:),allocatable :: restok !(ntyp+1)
5641 ! common /mdpmpi/ in control: ergastulum
5642 if(.not.allocated(ng_start)) allocate(ng_start(0:nfgtasks-1))
5643 if(.not.allocated(ng_counts)) allocate(ng_counts(0:nfgtasks-1))
5644 if(.not.allocated(nginv_counts)) allocate(nginv_counts(0:nfgtasks-1)) !(0:MaxProcs-1)
5645 if(.not.allocated(nginv_start)) allocate(nginv_start(0:nfgtasks)) !(0:MaxProcs)
5646 !----------------------
5647 ! common.muca in read_muca
5648 !----------------------
5650 ! common /mdgrad/ in module.energy
5651 ! common /back_constr/ in module.energy
5652 ! common /qmeas/ in module.energy
5656 allocate(d_t_work(nres6),d_t_work_new(nres6),d_af_work(nres6))
5657 allocate(d_as_work(nres6),kinetic_force(nres6)) !(MAXRES6)
5658 allocate(d_t_new(3,0:nres2),d_a_old(3,0:nres2),d_a_short(3,0:nres2)) !,d_a !(3,0:MAXRES2)
5659 allocate(stdforcp(nres),stdforcsc(nres)) !(MAXRES)
5660 !----------------------
5662 allocate(D_ban(nres6)) !(MAXRES6) maxres6=6*maxres
5663 ! common /stochcalc/ stochforcvec
5664 allocate(stochforcvec(nres6)) !(MAXRES6) maxres6=6*maxres
5665 !----------------------
5667 end subroutine alloc_MD_arrays
5668 !-----------------------------------------------------------------------------
5669 !-----------------------------------------------------------------------------