def combineFrames(file, nCombine): time, atoms = readFrame(file) l = len(atoms) combined = np.zeros((l*nCombine,4)) combined[0:l] = atoms for n in range(nCombine-1): _, atoms = readFrame(file) combined[l*(n+1):l*(n+2)] = atoms return time, combined
def main(): trajFile, outFile, nFrames = getArgs(argv) atomtype = 1 particles = 3 nSkip = 1 # nFrames / 100 nMon = 5 with open(outFile+'_unwrapped.xyz', 'w') as otp: otp.write('') with open(trajFile,'r') as inp: for n in range(nFrames/nSkip): ### lammmpstrj ### # # read and filter data # for s in range(nSkip): # time, box, frame = readTrj(inp) # zero = frame[frame[:,1] == particles][:,4].min() # frame = frame[np.argsort(frame[:,0])] # frame = frame[frame[:,1] == atomtype][:,2:] # Lxy = box[:,1] - box[:,0] # frame = frame * Lxy + box[:,0] ### xyz ### # read and filter data for s in range(nSkip): time, frame = readFrame(inp) zero = frame[frame[:,0] == particles][:,3].min() frame = frame[frame[:,0] == atomtype][:,1:] frame[:,2] -= zero # build box box = np.zeros((2,2)) box[:,0] = frame[:,:2].min(0) box[:,1] = frame[:,:2].max(0) Lxy = box[:,1] - box[:,0] frame = unwrap(frame.reshape((-1,nMon,3)), box).reshape((-1,3)) if n == 0: periods = np.zeros_like(frame[:,:2]) move = np.zeros_like(frame[:,:2]) elif n > 0: move = frame[:,:2] + periods * Lxy[:2] - oldFrame[:,:2] periods += (move < box[:2,0]) periods -= (move >= box[:2,1]) frame[:,:2] += periods * Lxy[:2] # if differences are greater than L/2 in any frame, add 1 oldFrame = np.copy(frame) with open(outFile+'_unwrapped.xyz', 'a') as otp: otp.write('%d\n' % len(frame)) otp.write('Atoms. Timestep: %d\n' % time) np.savetxt(otp,frame,'1 %.5f %.5f %.5f') print 'Finished analyzing trajectory'
def main(): filename, outFile, nFrames = getArgs(argv) # Generate multiple MSDs based on the locations of the polymers # 1. Exclude polymers in the bulk # 2. Exclude polymers NOT in the bulk # 3. Look at polymers in the packing exclusively # # The point is to find a reasonable time-scale for polymer relaxation # Polymers in the packing have z coordinate > 0 and those near the surface are less than # 5 sigma from the surface (most negative polymer value) MSD = np.zeros((nFrames-1,5)) #MSD[:,0] = np.arange(1,nFrames) # Calculate atomic and molecular MSD chainLength = 25 pos = 0 for m in range(nFrames-1): with open(filename, 'r') as file: file.seek(pos) time_m, atoms_m = readFrame(file) # add a condition to restrict the polymers based on location (make a mask) # mask = np.logical_and(atoms_m[:,2] < 0, atoms_m[:,2] > 5*(atoms_m[:,2].min())) atoms_m = atoms_m[:,1:]#[mask] pos = file.tell() for n in range(m+1,nFrames): time_n, atoms_n = readFrame(file) atoms_n = atoms_n[:,1:]#[mask] # handle function calls here MSD[n-m-1,1:] += diffusion(atoms_m, atoms_n, chainLength) if m == 0: MSD[n-m-1,0] = time_n - time_m # average MSD array MSD[:,1:] /= range(nFrames-1,0,-1) # write MSD array to file with open(outFile, 'w') as otp: otp.write('# lagtime MSD\n') np.savetxt(otp,MSD,'%0.5f')
def main(): trajFile, outFile, nSteps = getArgs(argv) nBins = 180 pcf = np.zeros((nBins,2)) with open(trajFile,'r') as inp: for n in range(nSteps): for k in range(50): t, frame = readFrame(inp) mask = lambda i: (frame[:,0] == i) poly = frame[mask(1)][:,1:] surf = frame[mask(2)][:,1:] # Find the center of mass in the xy direction and center droplet # poly, center = centerAtoms(poly) # make box box = np.ones((3,2)) box[:,0] = frame[:,1:].min(0) #-0.01 box[:,1] = frame[:,1:].max(0) #+0.01 # box[1,:] += [-7,7] # atoms[:,2] -= box[2,0] # box[2,:] -= box[2,0] # find interfacial atoms # interface = findCylinderInterface(atoms, box) # calculate volume per horizontal 'slice' # calculate pair correlation function pcf += calcPCF(surf, poly, box, nBins) plt.plot(pcf[:,0], pcf[:,1]) plt.show() print 'Finished analyzing trajectory'