msd = numpy.zeros(args.span-1) #we substract 1 because cpptraj diffusion command does not calculate MSD(0), which is zero by definition template='''trajin _trajfile_ _t0_ _t0+t_ 1 _rms_ diffusion _dt_ _prefix_ _mask_ average ''' handle,tmp_prefix = mkstemp(prefix='junk', dir='/tmp') jump = max(1, int((args.nframe - args.span - 1) / args.nt0)) # consecutive chunks start at positions that differ by 'jump' for it0 in range(args.nt0): t0 = 1 + it0*jump # first frame of the chunk te = t0 + args.span -1 # last frame of the chunk script = template.replace('_trajfile_', args.trajfile) script = script.replace('_t0_', '{0}'.format(t0)) script = script.replace('_t0+t_', '{0}'.format(te)) script = script.replace('_mask_', args.mask) script = script.replace('_dt_', '{0}'.format(args.dt)) script = script.replace('_prefix_', tmp_prefix) if args.rms2t0 == 'y': script = script.replace('_rms_', 'rms first') else: script = script.replace('_rms_', '#') #print script exec_cpptraj(args.topfile, script) file2mem = numpy.transpose(numpy.loadtxt('{0}_r.xmgr'.format(tmp_prefix))) #read MSD(t) for the chunk and store msd += file2mem[1] msd /= args.nt0 # average for all the chunks buf = '# time MSD\n' for it in range(1,args.span): buf += '{0:5f} {1:8f}\n'.format( it*args.dt, msd[it-1] ) open(args.outf, 'w').write(buf)
args=parser.parse_args() handle, tmpfile = mkstemp(prefix='junk', dir='/tmp') nsty = nsty_per_polymer * args.npol solvmask = '(!:1-{0})&(@{1})'.format(nsty, args.tol) solmask = '(:1-{0})&(@{1})'.format(nsty, args.sty) lower = args.minimum upper = lower + args.spacing buf='# distance number_of_tol/sty\n' while upper < args.maximum: script='''trajin {0} center {1} watershell {2} {3} lower {4} upper {5} {6}'''.format(args.dcd, solmask, solmask, tmpfile, lower, upper, solvmask) exec_cpptraj(args.top, script) #tr() avgn1=0 avgn2=0 for line in open(tmpfile).readlines()[1:]: frame, n1, n2 = [float(x) for x in line.split()] avgn1 += n1 avgn2 += n2 avgn1 /= (frame*nsty) avgn2 /= (frame*nsty) buf += '{0:5.2f} {1:6.2f}\n{2:5.2f} {3:6.2f}\n'.format(lower, avgn1, upper, avgn2) lower = upper + args.spacing upper = lower + args.spacing open(args.outf,'w').write(buf)