[bd2278d] | 1 | !**************************************************************
|
---|
| 2 | !
|
---|
| 3 | ! This file contains the subroutines: partem_p
|
---|
| 4 | ! USE WITH main_p, NOT WITH main!!!!!!
|
---|
| 5 | !
|
---|
| 6 | ! Copyright 2003-2005 Frank Eisenmenger, U.H.E. Hansmann,
|
---|
| 7 | ! Shura Hayryan, Chin-Ku
|
---|
| 8 | ! Copyright 2007 Frank Eisenmenger, U.H.E. Hansmann,
|
---|
| 9 | ! Jan H. Meinke, Sandipan Mohanty
|
---|
| 10 | !
|
---|
| 11 | ! **************************************************************
|
---|
[e40e335] | 12 |
|
---|
| 13 | subroutine partem_p(num_rep, nequi, nswp, nmes, nsave, newsta,
|
---|
| 14 | & switch, rep_id, partem_comm)
|
---|
[bd2278d] | 15 | !
|
---|
| 16 | ! PURPOSE: SIMULATION OF PROTEINS BY PARALLEL TEMPERING ALGORITHM
|
---|
| 17 | ! ON PARALLEL COMPUTERS USING MPI
|
---|
| 18 | !
|
---|
| 19 | ! switch: Choses the starting configuration:
|
---|
| 20 | ! -1 - stretched configuration
|
---|
| 21 | ! 0 - don't change anything
|
---|
| 22 | ! 1 - random start configuration
|
---|
| 23 | !
|
---|
| 24 | ! CALLS: addang,contacts,energy,hbond,helix,iendst,metropolis,
|
---|
| 25 | ! outvar,(rand),rgyr
|
---|
| 26 | !
|
---|
[e40e335] | 27 | include 'INCL.H'
|
---|
| 28 | include 'INCP.H'
|
---|
| 29 | include 'mpif.h'
|
---|
| 30 |
|
---|
| 31 | logical newsta
|
---|
| 32 | integer switch, partem_comm, rep_id, nsave
|
---|
[bd2278d] | 33 | ! external rand
|
---|
[e40e335] | 34 | external can_weight
|
---|
| 35 |
|
---|
[bd2278d] | 36 | ! nequi: number of Monte Carlo sweeps for thermalization
|
---|
| 37 | ! nswp: number of Monte Carlo sweeps
|
---|
| 38 | ! nmes: number of Monte Carlo sweeps between measurments
|
---|
| 39 | ! newsta: .true. for new simulations, .false. for re-start
|
---|
[6650a56] | 40 | double precision temp, eavm, sph, geavm, gsph, dv, grnd, vr
|
---|
| 41 | double precision addang, dummy, eol, energy, acz, rmsv, rmsdfun
|
---|
| 42 | double precision rgy, ee, tmhb, dham, swp, wij, rd, e_final
|
---|
[e40e335] | 43 |
|
---|
[6650a56] | 44 | integer ifrrm, nmes, nswp, num_rep, i, j, nresi, iold, inode
|
---|
| 45 | integer intem, iv, jold, idum1, idum2, idum3, mpi_integer
|
---|
| 46 | integer mpi_comm_world, ierr, mpi_double_precision, nsw, nequi
|
---|
| 47 | integer nml, nhel, mhel, nbet, mbet, mhb, imhb, nctot, ncnat
|
---|
| 48 | integer mpi_comm_null, k1, k, nu, no1, in, jn
|
---|
| 49 |
|
---|
[e40e335] | 50 | dimension eavm(MAX_PROC),sph(MAX_PROC),intem(MAX_PROC),
|
---|
| 51 | & inode(MAX_PROC), geavm(MAX_PROC), gsph(MAX_PROC)
|
---|
| 52 | double precision pbe(MAX_PROC),yol(MAX_PROC),acy(MAX_PROC),
|
---|
| 53 | & acy1(MAX_PROC),acx1(MAX_PROC),
|
---|
[c021909] | 54 | & rgyrp(MAX_PROC),rmsdp(MAX_PROC), eol0,acz0
|
---|
[e40e335] | 55 |
|
---|
| 56 | double precision e_min, e_minp(MAX_PROC), e_minpt(MAX_PROC)
|
---|
| 57 | integer h_max, h_maxp(MAX_PROC)
|
---|
[bd2278d] | 58 | ! Order of replica exchange
|
---|
[e40e335] | 59 | integer odd
|
---|
| 60 | ! Counter to keep random number generators in sync
|
---|
| 61 | integer randomCount
|
---|
| 62 |
|
---|
[bd2278d] | 63 | ! Collect partial energies. Only the root writes to disk. We have to
|
---|
| 64 | ! collect the information from the different replicas and provide
|
---|
| 65 | ! arrays to store them.
|
---|
| 66 | ! eyslr storage array for solvent energy
|
---|
| 67 | ! eyelp - " - coulomb energy
|
---|
| 68 | ! eyvwp - " - van-der-Waals energy
|
---|
| 69 | ! eyhbp - " - hydrogen bonding energy
|
---|
| 70 | ! eysmi - " - intermolecular interaction energy
|
---|
| 71 | ! eyabp - " - Abagyan correction term
|
---|
[e40e335] | 72 | double precision eyslr(MAX_PROC)
|
---|
| 73 | double precision eyelp(MAX_PROC),eyvwp(MAX_PROC),eyhbp(MAX_PROC),
|
---|
| 74 | & eyvrp(MAX_PROC),eysmip(MAX_PROC), eyabp(MAX_PROC)
|
---|
[bd2278d] | 75 | ! Collect information about accessible surface and van-der-Waals volume
|
---|
| 76 | ! asap storage array for solvent accessible surface
|
---|
| 77 | ! vdvolp storage array for van-der-Waals volume
|
---|
[c021909] | 78 | double precision asa_p(MAX_PROC), vdvolp(MAX_PROC)
|
---|
[e40e335] | 79 |
|
---|
| 80 | integer nhelp(MAX_PROC),nbetp(MAX_PROC), mhbp(MAX_PROC),
|
---|
| 81 | & ncnatp(MAX_PROC),nctotp(MAX_PROC)
|
---|
| 82 | integer imhbp(MAX_PROC)
|
---|
| 83 | character*80 filebase, fileNameMP, tbase0,tbase1
|
---|
[bd2278d] | 84 | ! frame frame number for writing configurations
|
---|
| 85 | ! trackID configuration that should be tracked and written out
|
---|
| 86 | ! dir direction in random walk
|
---|
| 87 | ! -1 - visited highest temperature last
|
---|
| 88 | ! 1 - visited lowest temperature last
|
---|
| 89 | ! 0 - haven't visited the boundaries yet.
|
---|
| 90 | ! dirp storage array for directions.
|
---|
[e40e335] | 91 | integer frame, trackID, dir
|
---|
| 92 | integer dirp(MAX_PROC)
|
---|
| 93 |
|
---|
| 94 | frame = ifrrm
|
---|
| 95 | trackID = 1
|
---|
| 96 | odd = 1
|
---|
| 97 | write (*,*) 'Starting parallel tempering.'
|
---|
| 98 | write (*,*) 'parameters, ',switch,newsta,nmes,nswp,nmes,
|
---|
| 99 | & rep_id, num_rep, partem_comm, myrank
|
---|
| 100 | call flush(6)
|
---|
[bd2278d] | 101 | !
|
---|
| 102 | !
|
---|
| 103 | ! File with temperatures
|
---|
[e40e335] | 104 | open(11,file='temperatures',status='old')
|
---|
[bd2278d] | 105 | ! File with reference conformation
|
---|
[e40e335] | 106 | tbase0='trj_00000'
|
---|
| 107 | open(18,file=fileNameMP(tbase0,5,9,rep_id),status='unknown')
|
---|
| 108 | if (rep_id.eq.0.and.myrank.eq.0) then
|
---|
[bd2278d] | 109 | ! File with time series of simulation
|
---|
[e40e335] | 110 | open(14,file='ts.d',status='unknown')
|
---|
[bd2278d] | 111 | ! Track weights
|
---|
| 112 | ! open(16, file='weights.dat', status='unknown')
|
---|
[e40e335] | 113 | endif
|
---|
| 114 |
|
---|
[bd2278d] | 115 | ! READ IN TEMPERATURES
|
---|
[e40e335] | 116 | do i=1,num_rep
|
---|
| 117 | read(11,*) j,temp
|
---|
| 118 | pbe(j) = 1.0d0/( temp * 1.98773d-3 )
|
---|
| 119 | end do
|
---|
| 120 | close(11)
|
---|
| 121 |
|
---|
[bd2278d] | 122 | ! nresi: number of residues
|
---|
[e40e335] | 123 | nresi=irsml2(1)-irsml1(1)+1
|
---|
[bd2278d] | 124 | !
|
---|
| 125 | ! Initialize variables
|
---|
[e40e335] | 126 | do i=1,num_rep
|
---|
| 127 | acx1(i) = 0.0d0
|
---|
| 128 | acy(i) = 0.0d0
|
---|
| 129 | eavm(i) = 0.0d0
|
---|
| 130 | sph(i) = 0.0d0
|
---|
| 131 | geavm(i) =0.0d0
|
---|
| 132 | gsph(i) = 0.0d0
|
---|
| 133 | e_minp(i) = 1.0d15
|
---|
| 134 | h_maxp(i) = 0
|
---|
| 135 | dirp(i) = 0
|
---|
| 136 | end do
|
---|
| 137 | dirp(1) = 1
|
---|
| 138 | dirp(num_rep) = -1
|
---|
| 139 | e_min = 1.0d15
|
---|
| 140 | h_max = 0
|
---|
| 141 | dir = dirp(rep_id + 1)
|
---|
| 142 |
|
---|
[bd2278d] | 143 | ! _________________________________ Initialize Variables
|
---|
[e40e335] | 144 | if(newsta) then
|
---|
| 145 | iold=0
|
---|
| 146 | do i=1,num_rep
|
---|
| 147 | inode(i) = i
|
---|
| 148 | intem(i) = i
|
---|
| 149 | end do
|
---|
[bd2278d] | 150 | ! _________________________________ initialize starting configuration
|
---|
[e40e335] | 151 | if (switch.ne.0) then
|
---|
| 152 | do i=1,nvr
|
---|
| 153 | iv=idvr(i) ! provides index of non-fixed variable
|
---|
| 154 | if (switch.gt.0) then
|
---|
| 155 | dv=axvr(i)*(grnd()-0.5)
|
---|
| 156 | vr=addang(pi,dv)
|
---|
| 157 | else
|
---|
| 158 | vr = pi
|
---|
| 159 | endif
|
---|
| 160 | vlvr(iv)=vr
|
---|
| 161 | enddo
|
---|
| 162 | endif
|
---|
| 163 | else
|
---|
| 164 | if(rep_id.eq.0.and.myrank.eq.0) then
|
---|
| 165 | open(13,file='par_R.in', status='unknown')
|
---|
| 166 | read(13,*) iold
|
---|
| 167 | do i=1,num_rep
|
---|
| 168 | read(13,*) j,inode(i),intem(i),yol(i),e_minp(i),h_maxp(i)
|
---|
| 169 | write (*,*) "par_R.in:",i,j
|
---|
| 170 | end do
|
---|
| 171 | jold=(iold/nmes)*num_rep
|
---|
| 172 | rewind 14
|
---|
| 173 | do i=1,jold
|
---|
| 174 | read(14,*) idum1,idum2,idum3,dummy, dir
|
---|
| 175 | & ,dummy, dummy, dummy, dummy, dummy
|
---|
| 176 | & ,dummy, dummy, dummy, dummy
|
---|
| 177 | & ,dummy, idum1, idum2, idum3
|
---|
| 178 | & ,idum1, idum2, idum3, e_min
|
---|
| 179 | & ,dummy, dummy
|
---|
| 180 | write (*,*) i
|
---|
| 181 | call flush(6)
|
---|
| 182 | end do
|
---|
| 183 | close(13)
|
---|
| 184 | end if
|
---|
| 185 | CALL MPI_BCAST(IOLD,1,MPI_INTEGER,0,MPI_COMM_WORLD,IERR)
|
---|
| 186 | CALL MPI_BCAST(INTEM,num_rep,MPI_INTEGER,0,MPI_COMM_WORLD,IERR)
|
---|
| 187 | CALL MPI_BCAST(INODE,num_rep,MPI_INTEGER,0,MPI_COMM_WORLD,IERR)
|
---|
| 188 | CALL MPI_BCAST(YOL,num_rep,MPI_DOUBLE_PRECISION,0,
|
---|
[bd2278d] | 189 | & MPI_COMM_WORLD,IERR)
|
---|
[e40e335] | 190 | CALL MPI_BCAST(E_MINP, num_rep, MPI_DOUBLE_PRECISION, 0,
|
---|
[bd2278d] | 191 | & MPI_COMM_WORLD, IERR)
|
---|
[e40e335] | 192 | CALL MPI_BCAST(h_maxp,num_rep,MPI_INTEGER,0,MPI_COMM_WORLD,
|
---|
[bd2278d] | 193 | & IERR)
|
---|
[e40e335] | 194 | end if
|
---|
| 195 |
|
---|
| 196 | BETA = pbe(inode(rep_id+1))
|
---|
[31550cb] | 197 | e_min = e_minp(rep_id+1)
|
---|
| 198 | h_max = h_maxp(rep_id+1)
|
---|
| 199 | write (*,*) "E_min=",e_min," for ", rep_id + 1
|
---|
[e40e335] | 200 | eol=energy()
|
---|
| 201 | if(.not.newsta.and.abs(yol(rep_id + 1) - eol).gt.0.1) then
|
---|
| 202 | write(*,*) rep_id, ' Warning: yol(rep_id).ne.eol:'
|
---|
| 203 | write(*,*) rep_id, yol(rep_id + 1), eol
|
---|
| 204 | endif
|
---|
[bd2278d] | 205 | ! Start of simulation
|
---|
[e40e335] | 206 | write (*,*) '[',rep_id, myrank, beta, partem_comm,
|
---|
| 207 | & '] Energy before equilibration:', eol
|
---|
[bd2278d] | 208 | ! =====================Equilibration by canonical Metropolis
|
---|
[e40e335] | 209 | do nsw=1,nequi
|
---|
| 210 | call metropolis(eol,acz,can_weight)
|
---|
| 211 | end do
|
---|
| 212 | CALL MPI_BARRIER(MPI_COMM_WORLD,IERR)
|
---|
| 213 | write (*,*) '[',rep_id,'] Energy after equilibration:', eol
|
---|
| 214 | call flush(6)
|
---|
[bd2278d] | 215 | !
|
---|
| 216 | !======================Multiple Markov Chains
|
---|
[e40e335] | 217 | acz = 0
|
---|
| 218 | do nsw=1,nswp
|
---|
[bd2278d] | 219 | !------------First ordinary Metropolis
|
---|
[e40e335] | 220 | call metropolis(eol,acz,can_weight)
|
---|
| 221 | iold = iold + 1
|
---|
| 222 | eol0 = eol
|
---|
| 223 | if (myrank.eq.0.and.rep_id.eq.0) then
|
---|
| 224 | write (*,*) "Finished sweep", nsw
|
---|
| 225 | call flush(6)
|
---|
| 226 | endif
|
---|
| 227 | if(mod(iold,nmes).eq.0) then
|
---|
| 228 | if ((rep_id + 1).eq.trackID.and.myrank.eq.0) then
|
---|
| 229 | frame = iold /nmes
|
---|
| 230 | filebase = "frame_00000.pdb"
|
---|
| 231 | call outpdb(0, fileNameMP(filebase, 7, 11, frame))
|
---|
| 232 | endif
|
---|
| 233 | acz0 = acz
|
---|
[bd2278d] | 234 | ! Evaluate RMSD
|
---|
[e40e335] | 235 | nml = 1
|
---|
| 236 | rmsv = rmsdfun(nml,irsml1(nml),irsml2(nml),ixatp,xatp,yatp, &
|
---|
| 237 | & zatp,0)
|
---|
[bd2278d] | 238 | ! print *,myrank,'received RMSD,energy ',rmsv,eyab,beta
|
---|
| 239 | ! Measure global radius of gyration
|
---|
[e40e335] | 240 | call rgyr(0,rgy,ee)
|
---|
| 241 | rgyp = rgy
|
---|
[bd2278d] | 242 | ! Measure Helicity and Sheetness
|
---|
[e40e335] | 243 | call helix(nhel,mhel,nbet,mbet)
|
---|
[bd2278d] | 244 | ! Measure Number of hydrogen bonds
|
---|
[e40e335] | 245 | mhb = 0
|
---|
| 246 | do i = 1, ntlml
|
---|
| 247 | call hbond(i,tmhb,-1)
|
---|
| 248 | mhb = mhb + 1
|
---|
| 249 | enddo
|
---|
| 250 | call interhbond(imhb)
|
---|
[bd2278d] | 251 | ! Measure total number of contacts (NCTOT) and number of
|
---|
| 252 | ! native contacts (NCNAT)
|
---|
[e40e335] | 253 | call contacts(nctot,ncnat,dham)
|
---|
[bd2278d] | 254 | ! Add tracking of lowest energy configuration
|
---|
[e40e335] | 255 | if (eol.lt.e_min) then
|
---|
[bd2278d] | 256 | ! Write out configuration
|
---|
[e40e335] | 257 | i=rep_id+1
|
---|
| 258 | j=inode(i)
|
---|
| 259 | e_min = eol
|
---|
| 260 | filebase = "c_emin_0000.pdb"
|
---|
[31550cb] | 261 | call outpdb(0, fileNameMP(filebase, 8, 11, i))
|
---|
[e40e335] | 262 | filebase = "c_emin_0000.var"
|
---|
[31550cb] | 263 | call outvar(0, fileNameMP(filebase, 8, 11, i))
|
---|
[e40e335] | 264 | filebase = "c_emin_0000.dat"
|
---|
[31550cb] | 265 | open(15, file=fileNameMP(filebase, 8, 11, i),
|
---|
[e40e335] | 266 | & status="unknown")
|
---|
| 267 | ! write(15,'(i8,2i4,f6.2,2f8.2,5i8)') iold,i,j,pbe(i),
|
---|
[31550cb] | 268 | write(15,*) iold,j,i,beta,
|
---|
[e40e335] | 269 | & eol, eyab, eysl, eyel, eyvw, eyhb, eyvr, eysmi,asa,
|
---|
| 270 | & vdvol, rgy, nhel, nbet, mhb, imhb, nctot,ncnat
|
---|
| 271 | close(15)
|
---|
| 272 | endif
|
---|
[bd2278d] | 273 | ! Add tracking of configuration with larges hydrogen contents.
|
---|
[e40e335] | 274 | if ((mhb + imhb).gt.h_max) then
|
---|
[bd2278d] | 275 | ! Write out configuration
|
---|
[e40e335] | 276 | i = rep_id + 1
|
---|
| 277 | j = inode(i)
|
---|
| 278 | h_max = mhb + imhb
|
---|
| 279 | filebase = "c_hmax_0000.pdb"
|
---|
[31550cb] | 280 | call outpdb(0,fileNameMP(filebase,8,11,i))
|
---|
[e40e335] | 281 | filebase = "c_hmax_0000.var"
|
---|
[31550cb] | 282 | call outvar(0,fileNameMP(filebase,8,11,i))
|
---|
[e40e335] | 283 | filebase = "c_hmax_0000.dat"
|
---|
[31550cb] | 284 | open(15, file=fileNameMP(filebase, 8, 11, i),
|
---|
[e40e335] | 285 | & status="unknown")
|
---|
| 286 | ! write(15,'(i8,2i4,f6.2,2f8.2,5i8)') iold,i,j,pbe(i),
|
---|
[31550cb] | 287 | write(15,*) iold,j,i,beta,
|
---|
[e40e335] | 288 | & eol, eyab, eysl, eyel, eyvw, eyhb, eyvr, eysmi,asa,
|
---|
| 289 | & vdvol, rgy, nhel, nbet, mhb, imhb, nctot,ncnat
|
---|
| 290 | close(15)
|
---|
| 291 | endif
|
---|
| 292 |
|
---|
[bd2278d] | 293 | !
|
---|
| 294 | !--------------------Gather measurement data
|
---|
[e40e335] | 295 | ! I only use the master node of each replica for data collection. The
|
---|
| 296 | ! variable partem_comm provides the appropriate communicator.
|
---|
| 297 | if (partem_comm.ne.MPI_COMM_NULL) then
|
---|
| 298 | CALL MPI_GATHER(rmsv,1,MPI_DOUBLE_PRECISION,rmsdp,1,
|
---|
[bd2278d] | 299 | & MPI_DOUBLE_PRECISION, 0,partem_comm,IERR)
|
---|
[e40e335] | 300 | CALL MPI_GATHER(eyab,1,MPI_DOUBLE_PRECISION,eyabp,1,
|
---|
[bd2278d] | 301 | & MPI_DOUBLE_PRECISION, 0,partem_comm,IERR)
|
---|
[e40e335] | 302 | CALL MPI_GATHER(RGYP,1,MPI_DOUBLE_PRECISION,RGYRP,1,
|
---|
[bd2278d] | 303 | & MPI_DOUBLE_PRECISION, 0,partem_comm,IERR)
|
---|
[e40e335] | 304 | CALL MPI_GATHER(NHEL,1,MPI_INTEGER,NHELP,1,MPI_INTEGER,
|
---|
| 305 | & 0,partem_comm,IERR)
|
---|
| 306 | CALL MPI_GATHER(NBET,1,MPI_INTEGER,NBETP,1,MPI_INTEGER,
|
---|
| 307 | & 0,partem_comm,IERR)
|
---|
| 308 | CALL MPI_GATHER(MHB,1,MPI_INTEGER,MHBP,1,MPI_INTEGER,
|
---|
| 309 | & 0,partem_comm,IERR)
|
---|
| 310 | CALL MPI_GATHER(iMHB,1,MPI_INTEGER,iMHBP,1,MPI_INTEGER,
|
---|
| 311 | & 0,partem_comm,IERR)
|
---|
| 312 | CALL MPI_GATHER(NCTOT,1,MPI_INTEGER,NCTOTP,1,MPI_INTEGER,
|
---|
| 313 | & 0,partem_comm,IERR)
|
---|
| 314 | CALL MPI_GATHER(NCNAT,1,MPI_INTEGER,NCNATP,1,MPI_INTEGER,
|
---|
| 315 | & 0,partem_comm,IERR)
|
---|
| 316 | CALL MPI_GATHER(dir,1,MPI_INTEGER,dirp,1,MPI_INTEGER,
|
---|
| 317 | & 0,partem_comm,IERR)
|
---|
| 318 | CALL MPI_GATHER(acz0,1,MPI_DOUBLE_PRECISION,acy1,1,
|
---|
| 319 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
| 320 | CALL MPI_GATHER(e_min,1,MPI_DOUBLE_PRECISION,e_minp,1,
|
---|
| 321 | & MPI_DOUBLE_PRECISION,0, partem_comm,IERR)
|
---|
| 322 | CALL MPI_GATHER(EOL0,1,MPI_DOUBLE_PRECISION,YOL,1,
|
---|
| 323 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
| 324 | CALL MPI_GATHER(eysl,1,MPI_DOUBLE_PRECISION,eyslr,1,
|
---|
| 325 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
| 326 | CALL MPI_GATHER(eyel,1,MPI_DOUBLE_PRECISION,eyelp,1,
|
---|
| 327 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
| 328 | CALL MPI_GATHER(eyvw,1,MPI_DOUBLE_PRECISION,eyvwp,1,
|
---|
| 329 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
| 330 | CALL MPI_GATHER(eyhb,1,MPI_DOUBLE_PRECISION,eyhbp,1,
|
---|
| 331 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
| 332 | CALL MPI_GATHER(eyvr,1,MPI_DOUBLE_PRECISION,eyvrp,1,
|
---|
| 333 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
| 334 | CALL MPI_GATHER(eysmi,1,MPI_DOUBLE_PRECISION,eysmip,1,
|
---|
| 335 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
[c021909] | 336 | CALL MPI_GATHER(asa,1,MPI_DOUBLE_PRECISION,asa_p,1,
|
---|
[e40e335] | 337 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
| 338 | CALL MPI_GATHER(vdvol,1,MPI_DOUBLE_PRECISION,vdvolp,1,
|
---|
| 339 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
| 340 |
|
---|
| 341 | ! CALL MPI_GATHER(EOL0,1,MPI_DOUBLE_PRECISION,YOL,1,MPI_DOUBLE_PRECISION,
|
---|
| 342 | ! & 0,MPI_COMM_WORLD,IERR)
|
---|
| 343 | ! CALL MPI_GATHER(E_MIN, 1, MPI_DOUBLE_PRECISION, E_MINP, MPI_DOUBLE_PRECISION,
|
---|
| 344 | ! & 0,MPI_COMM_WORLD, IERR)
|
---|
| 345 |
|
---|
[bd2278d] | 346 | ! Write trajectory
|
---|
[e40e335] | 347 | write (18,*) '@@@',iold,inode(rep_id+1)
|
---|
| 348 | call outvbs(0,18)
|
---|
| 349 | write (18,*) '###'
|
---|
| 350 | ! call flush(18)
|
---|
[bd2278d] | 351 | ! Write current configuration
|
---|
[e40e335] | 352 | if ((mod(iold, nsave).eq.0)) then
|
---|
| 353 | filebase = "conf_0000.var"
|
---|
| 354 | call outvar(0, fileNameMP(filebase, 6, 9, rep_id+1))
|
---|
| 355 | endif
|
---|
| 356 | endif
|
---|
| 357 |
|
---|
| 358 | if(rep_id.eq.0.and.myrank.eq.0) then
|
---|
| 359 | randomCount = 0
|
---|
[bd2278d] | 360 | ! Update acceptance, temperature wise average of E and E^2 used to calculate
|
---|
| 361 | ! specific heat.
|
---|
[e40e335] | 362 | do i=1,num_rep
|
---|
| 363 | j=intem(i)
|
---|
| 364 | acy(i)=0.0
|
---|
[bd2278d] | 365 | ! Above: contents of acy1 are added to acy(i) a few lines down.
|
---|
| 366 | ! acy1(intem(i)) contains information received from the node at temperature
|
---|
| 367 | ! i, on how many updates have been accepted in node intem(i). Since acz
|
---|
| 368 | ! is not reset to 0 every cycle, acy(i) must be set to 0 here. Else, there
|
---|
| 369 | ! will be serious double counting and the values of acceptance printed
|
---|
| 370 | ! will be simply wrong.
|
---|
[e40e335] | 371 | end do
|
---|
| 372 | do i=1, num_rep
|
---|
| 373 | j=intem(i)
|
---|
| 374 | acy(i)=acy(i)+acy1(j)
|
---|
| 375 | eavm(i)= eavm(i)+yol(j)
|
---|
| 376 | sph(i) = sph(i)+yol(j)*yol(j)
|
---|
| 377 | enddo
|
---|
| 378 |
|
---|
| 379 |
|
---|
[bd2278d] | 380 | ! Write measurements to the time series file ts.d
|
---|
[e40e335] | 381 | do i=1,num_rep
|
---|
| 382 | j=intem(i)
|
---|
| 383 | write(14,*) iold,i,j,pbe(i), dirp(j),
|
---|
| 384 | & yol(j),eyslr(j), eyelp(j), eyvwp(j), eyhbp(j),
|
---|
[c021909] | 385 | & eyvrp(j),eysmip(j), asa_p(j), vdvolp(j),
|
---|
[e40e335] | 386 | & rgyrp(j),nhelp(j),nbetp(j),mhbp(j),
|
---|
[31550cb] | 387 | & imhbp(j), nctotp(j),ncnatp(j), e_minp(j),
|
---|
[e40e335] | 388 | & eyabp(j),rmsdp(j)
|
---|
| 389 | ! call flush(14)
|
---|
| 390 | end do
|
---|
[bd2278d] | 391 | ! Write the current parallel tempering information into par_R.in
|
---|
[e40e335] | 392 | ! timeLeft = llwrem(2) ! Time left till hard limit
|
---|
| 393 | ! if ((mod(iold, nsave).eq.0).or.(timeLeft.lt.minTimeLeft)
|
---|
| 394 | if ((mod(iold, nsave).eq.0))
|
---|
| 395 | & then
|
---|
| 396 | open(13,file='par_R.in', status='unknown')
|
---|
| 397 | write(13,*) iold
|
---|
| 398 | do i=1,num_rep
|
---|
| 399 | write(13,*) i,inode(i),intem(i),yol(i),e_minp(i),
|
---|
| 400 | & h_maxp(i)
|
---|
| 401 | end do
|
---|
[bd2278d] | 402 | ! -------------------------- Various statistics of current run
|
---|
| 403 | ! swp=nswp-nequi
|
---|
[e40e335] | 404 | swp=nsw
|
---|
| 405 | write(13,*) 'Acceptance rate for change of chains:'
|
---|
| 406 | do k1=1,num_rep
|
---|
| 407 | temp=1.0d0/pbe(k1)/0.00198773
|
---|
| 408 | write(13,*) temp, acx1(k1)*2.0d0*nmes/swp
|
---|
[bd2278d] | 409 | ! Above: it's the acceptance rate of exchange of replicas. Since a
|
---|
| 410 | ! replica exchange is attempted only once every nmes sweeps, the
|
---|
| 411 | ! rate should be normalized with (nmes/swp).
|
---|
[e40e335] | 412 | end do
|
---|
| 413 | write(13,*)
|
---|
| 414 | do k1=1,num_rep
|
---|
| 415 | k = intem(k1)
|
---|
| 416 | temp=1.0d0/pbe(k1)/0.00198773
|
---|
| 417 | beta = pbe(k1)
|
---|
| 418 | geavm(k1) = nmes*eavm(k1)/swp
|
---|
| 419 | gsph(k1) = (nmes*sph(k1)/swp-geavm(k1)**2)
|
---|
[bd2278d] | 420 | & *beta*beta/nresi
|
---|
[e40e335] | 421 | write(13,'(a,2f9.2,i4,f12.3)')
|
---|
| 422 | & 'Temperature, Node,local acceptance rate:',
|
---|
| 423 | & beta,temp,k,acy(k1)/dble(nsw*nvr)
|
---|
[bd2278d] | 424 | ! Above: Changed (nswp-nequi) in the denominator of acceptance as
|
---|
| 425 | ! acceptance values are initialized to 0 after equilibration cycles are
|
---|
| 426 | ! finished. Note also that since this is being written in the middle of
|
---|
| 427 | ! the simulation, it is normalized to nsw instead of nswp.
|
---|
[e40e335] | 428 | write(13,'(a,3f12.2)')
|
---|
| 429 | & 'Last Energy, Average Energy, Spec. Heat:',
|
---|
| 430 | & yol(k),geavm(k1),gsph(k1)
|
---|
| 431 | write(13,*)
|
---|
| 432 | end do
|
---|
| 433 | close(13)
|
---|
| 434 | ! Finally, flush the time series and trajectory files to ensure that we can do
|
---|
| 435 | ! a proper restart.
|
---|
| 436 | call flush(14)
|
---|
| 437 | call flush(18)
|
---|
| 438 | end if
|
---|
| 439 |
|
---|
[bd2278d] | 440 | !--------------------Parallel Tempering update
|
---|
| 441 | ! Swap with right neighbor (odd, even)
|
---|
[e40e335] | 442 | if(odd.eq.1) then
|
---|
| 443 | nu=1
|
---|
| 444 | no1 = num_rep-1
|
---|
[bd2278d] | 445 | ! Swap with left neighbor (even, odd)
|
---|
[e40e335] | 446 | else
|
---|
| 447 | nu = 2
|
---|
| 448 | no1 = num_rep
|
---|
| 449 | end if
|
---|
| 450 | do i=nu,no1,2
|
---|
| 451 | j=i+1
|
---|
[bd2278d] | 452 | ! Periodic bc for swaps
|
---|
[e40e335] | 453 | if(i.eq.num_rep) j=1
|
---|
| 454 | in=intem(i)
|
---|
| 455 | jn=intem(j)
|
---|
| 456 | wij=exp(-pbe(i)*yol(jn)-pbe(j)*yol(in)
|
---|
| 457 | & +pbe(i)*yol(in)+pbe(j)*yol(jn))
|
---|
[bd2278d] | 458 | ! The random number generator is getting out of sync here, because
|
---|
| 459 | ! the swap is only done on node 0!
|
---|
[e40e335] | 460 | ! Keep track of number of random numbers used.
|
---|
| 461 | rd=grnd()
|
---|
| 462 | randomCount = randomCount + 1
|
---|
[bd2278d] | 463 | ! write (16,*) '>', iold, i,j
|
---|
| 464 | ! & ,pbe(i),yol(in), pbe(j), yol(jn), wij, rd
|
---|
[e40e335] | 465 | if(wij.ge.rd) then
|
---|
[bd2278d] | 466 | ! Next line: Replica exchange only happens after equilibration,
|
---|
| 467 | ! which takes place outside this loop over nsw. So, I think nsw.gt.nequi
|
---|
| 468 | ! is irrelevant for the calculation of acceptance of replica exchanges.
|
---|
| 469 | ! /Sandipan
|
---|
| 470 | ! if(nsw.gt.nequi)
|
---|
[e40e335] | 471 | acx1(i) = acx1(i)+1
|
---|
| 472 | intem(i) = jn
|
---|
| 473 | intem(j) = in
|
---|
| 474 | inode(in)= j
|
---|
| 475 | inode(jn)= i
|
---|
| 476 | end if
|
---|
| 477 | end do
|
---|
[bd2278d] | 478 | ! ---------------- End Loop over nodes which creates a new temperature
|
---|
| 479 | ! map for all nodes, at the node with rank 0.
|
---|
| 480 | !
|
---|
[e40e335] | 481 | odd = 1 - odd
|
---|
| 482 | end if
|
---|
[bd2278d] | 483 | ! End of "if (myrank.eq.0) ...". The block above includes PT update and
|
---|
| 484 | ! writing of observables into the time series file etc.
|
---|
[e40e335] | 485 |
|
---|
[bd2278d] | 486 | ! Below: Communicate new temperature-node map to all nodes
|
---|
[e40e335] | 487 | CALL MPI_BCAST(INTEM,num_rep,MPI_INTEGER,0,MPI_COMM_WORLD,
|
---|
| 488 | & IERR)
|
---|
| 489 | CALL MPI_BCAST(INODE,num_rep,MPI_INTEGER,0,MPI_COMM_WORLD,
|
---|
| 490 | & IERR)
|
---|
[bd2278d] | 491 | ! Synchronize random number generators for replica 0
|
---|
[e40e335] | 492 | if (rep_id.eq.0) then
|
---|
| 493 | CALL MPI_BCAST(randomCount,1,MPI_INTEGER,0,my_mpi_comm,
|
---|
| 494 | & IERR)
|
---|
| 495 | if (myrank.ne.0) then
|
---|
| 496 | ! write (*,*) '[', myrank,'] Missed', randomCount,
|
---|
| 497 | ! & 'random numbers.'
|
---|
| 498 | do i = 1, randomCount
|
---|
| 499 | rd = grnd()
|
---|
| 500 | ! write (*,*) '[', myrank,'] rd=', rd
|
---|
| 501 | enddo
|
---|
| 502 | endif
|
---|
| 503 | endif
|
---|
| 504 |
|
---|
| 505 | BETA=PBE(INODE(rep_id+1))
|
---|
| 506 | if (INODE(rep_id + 1).eq.1) dir = 1
|
---|
| 507 | if (INODE(rep_id + 1).eq.num_rep) dir = -1
|
---|
| 508 |
|
---|
| 509 | endif
|
---|
[bd2278d] | 510 | ! End of "if (mod(iold,nmes).eq.0) ..."
|
---|
[e40e335] | 511 | end do
|
---|
[bd2278d] | 512 | !-----------End Loop over sweeps
|
---|
| 513 | !
|
---|
| 514 | ! OUTPUT:
|
---|
| 515 | !--------------------For Re-starts:
|
---|
[e40e335] | 516 | nu = rep_id + 1
|
---|
| 517 | filebase = "conf_0000.var"
|
---|
| 518 | call outvar(0, fileNameMP(filebase, 6, 9, nu))
|
---|
| 519 | e_final=energy()
|
---|
| 520 | if (partem_comm.ne.MPI_COMM_NULL) then
|
---|
| 521 | write (*,*) rep_id, ' E_final', e_final
|
---|
| 522 | endif
|
---|
| 523 | eol0 = eol
|
---|
| 524 | acz0 = acz
|
---|
| 525 | if (partem_comm.ne.MPI_COMM_NULL) then
|
---|
| 526 | CALL MPI_GATHER(EOL0,1,MPI_DOUBLE_PRECISION,YOL,1,
|
---|
[bd2278d] | 527 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
[e40e335] | 528 | CALL MPI_GATHER(acz0,1,MPI_DOUBLE_PRECISION,acy1,1,
|
---|
[bd2278d] | 529 | & MPI_DOUBLE_PRECISION,0,partem_comm,IERR)
|
---|
[e40e335] | 530 | endif
|
---|
| 531 |
|
---|
| 532 | if(rep_id.eq.0.and.myrank.eq.0) then
|
---|
| 533 | close(14)
|
---|
| 534 | open(13,file='par_R.in', status='unknown')
|
---|
| 535 | write(13,*) iold
|
---|
| 536 | do i=1,num_rep
|
---|
| 537 | write(13,*) i,inode(i),intem(i),yol(i),e_minp(i),h_maxp(i)
|
---|
| 538 | end do
|
---|
[bd2278d] | 539 | ! -------------------------- Various statistics of current run
|
---|
[e40e335] | 540 | swp=nswp
|
---|
| 541 | write(13,*) 'Acceptance rate for change of chains:'
|
---|
| 542 | do k1=1,num_rep
|
---|
| 543 | temp=1.0d0/pbe(k1)/0.00198773
|
---|
| 544 | write(13,*) temp, acx1(k1)*2.0d0*nmes/swp
|
---|
| 545 | end do
|
---|
| 546 | write(13,*)
|
---|
| 547 | do k1=1,num_rep
|
---|
| 548 | k = intem(k1)
|
---|
| 549 | temp=1.0d0/pbe(k1)/0.00198773
|
---|
| 550 | beta = pbe(k1)
|
---|
| 551 | geavm(k1) = nmes*eavm(k1)/swp
|
---|
| 552 | gsph(k1) = (nmes*sph(k1)/swp-geavm(k1)**2)*beta*beta/nresi
|
---|
| 553 | write(13,'(a,2f9.2,i4,f12.3)')
|
---|
| 554 | & 'Temperature, Node,local acceptance rate:',
|
---|
| 555 | & beta,temp,k,acy(k1)/dble((nswp)*nvr)
|
---|
| 556 | write(13,'(a,3f12.2)')
|
---|
| 557 | & 'Last Energy, Average Energy, Spec. Heat:',
|
---|
| 558 | & yol(k),geavm(k1),gsph(k1)
|
---|
| 559 | write(13,*)
|
---|
| 560 | end do
|
---|
| 561 | close(13)
|
---|
[bd2278d] | 562 | ! close(16)
|
---|
[e40e335] | 563 | end if
|
---|
| 564 | close(18)
|
---|
| 565 |
|
---|
[bd2278d] | 566 | ! =====================
|
---|
[e40e335] | 567 | CALL MPI_BARRIER(MPI_COMM_WORLD,IERR)
|
---|
| 568 |
|
---|
| 569 | return
|
---|
| 570 |
|
---|
| 571 | end
|
---|