def calc_bondacf(args): """ calculates persitence length using bond correlation function bondacf: bond correlation function analysis for L_p, when this parameter is provided, then program analyzes first points and fits them, to understand persistance length. C(n) = <u_0 u_n > method: create an array C, loop trajectory: loop residues: loop bonds: analyze angle between first bond vector and i average results plot using save_plots """ psffile = get_path_names.get_filename(args.psffile) u = MDAnalysis.Universe(psffile + '.psf', args.traj) Nbonds = len(u.residues[0]) - 1 Nres = len(u.residues) print "Nres = %r" % Nres print "Nbonds = %r" % Nbonds bonds = np.array((Nbonds, 3)) C = np.zeros(Nbonds) k = 0 for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]: print "time = %r" % ts.frame for res in u.residues: bonds = AnalyzeChain.get_bondlist_coords(res) k += 1 for ui in range(0, Nbonds): C[ui] += np.dot(bonds[0], bonds[ui]) C /= float(k) ui_array = np.arange(Nbonds) save_plots.save_plot(ui_array, C, plotname='bondacf')
def calc_sq(args): """ input: args obtained from read_traj_vmd calculates sq static parameter to analyze trajectories output: """ # psffile = os.path.splitext(args.psffile)[0] u = Universe(args.psffile, args.traj) psffile = get_path_names.get_filename(u.filename) # Ndiv = args.nsub Natoms = len(u.atoms) # Ndiv = int(Natoms**1/3.) Ndiv = 201 # create arrays of positions, get the box dimenstions u.trajectory[args.startframe] u.SYSTEM.packIntoBox() X = u.atoms.positions box = u.trajectory.ts.dimensions[:-3] length_x = box[-1] # be careful here # x = np.arange(-length_x,length_x,dx) x = np.linspace(-length_x, length_x, Ndiv+1, endpoint=True) f, edges = np.histogramdd(X, bins=(Ndiv, Ndiv, Ndiv)) delta = x[1]-x[0] # fast fourier transform, go to reciporal space ftk = (fftshift(fftn(fftshift(f))*delta)) # sk = np.abs(ftk**2) / float(Natoms) sk = np.abs(ftk**2) / float(Natoms) # / float(ndata) probably number of atoms # plt.cla() # basis in reciporal space omega = 2*np.pi*np.arange(Ndiv-1) / (length_x) omega -= omega[int(Ndiv/2)-1] k1, k2, k3 = np.meshgrid(omega, omega, omega) kmax = np.sqrt(3.)*omega[-1] # print "dk =" , dk, " kmax = ", kmax C = norm_sq(sk, k1, k2, k3, Ndiv, kmax) # we are interested in spherically symmetric case, # i.e only the module of [k1,k2,k3] = normk is important # print C[:,1] # plt.plot(C[:,1], C[:,2]) Nfirst = 10 save_plots.save_plot(C[Nfirst:-Nfirst, 1], C[Nfirst:-Nfirst, 2], xlabel='q, 1/sigma', ylabel='sq', title='static structure factor', plotname='sq', name=psffile+'f'+str(args.startframe), ymax=1.0, ymin=0.) return None
def calc_cryst(args): """ Analyzes crystallinity """ u = MDAnalysis.Universe(args.psffile, args.traj) psffile = get_path_names.get_filename(args.psffile) Nres = len(u.residues) frame = [] g2 = [] res_g2 = 0. # key parameter is the parameter used for parsing the files # keyparameter = get_path_names.get_filename(args.traj) keyparameter = args.keyparameter if args.filedumpskip: dumpskip = AnalyzeLog.get_dumpskip(filename='dumpskip.txt', keyparameter="dump" + keyparameter + "skip") timestep = AnalyzeLog.get_timestep(filename='dumpskip.txt', keyparameter="time" + keyparameter + "step") else: print "using given parameters" dumpskip = args.dumpskip timestep = args.timestep for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]: all_g2 = 0. frame.append(ts.frame) for res in u.residues: chords = get_bondlist_coords(res) res_g2 = get_chain_crystallinity(chords, threshold=args.threshold, neigh=args.neigh) all_g2 += res_g2 print('frame {frame} , g2 = {cryst}'.format(frame=ts.frame, cryst=all_g2 / float(Nres))) g2.append(all_g2 / float(Nres)) frame = np.array(frame) g2 = np.array(g2) save_plots.save_plot(frame, g2, plotname='ICC', name=psffile, logplot=args.logplot, dumpskip=dumpskip, timestep=timestep, duplicate=False) # save_plots.save_plot_cryst(frame, g2, psffile, # logplot=args.logplot, # dumpskip=dumpskip, # timestep=timestep) return None
def main(): args = read_traj_vmd() psffile = os.path.splitext(args.psffile)[0] u = Universe(psffile + '.psf', args.traj) ref_atoms = u.selectAtoms("all") traj_atoms = u.selectAtoms("all") natoms = traj_atoms.numberOfAtoms() frame = [] g2 = [] # if performing a mass-weighted alignment/rmsd calculation #masses = ref_atoms.masses() #weight = masses/numpy.mean(masses) # reference centre of mass system ref_com = ref_atoms.centerOfMass() ref_coordinates = ref_atoms.coordinates() - ref_com # diff_coordinates = ref_atoms.coordinates().copy # allocate the array for selection atom coords traj_coordinates = traj_atoms.coordinates().copy() for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]: # shift coordinates for rotation fitting # selection is updated with the time frame x_com = traj_atoms.centerOfMass() traj_coordinates[:] = traj_atoms.coordinates() - x_com # diff = calc_rmsd(traj_coordinates,ref_coordinates) diff = traj_coordinates - ref_coordinates norm = np.linalg.norm(diff, axis=1) norm *= norm # rms = sqrt(mean_squared_error(traj_coordinates, ref_coordinates )) # diff_coordinates = traj_coordinates - ref_coordinates # mean = np.mean(LA.norm(diff_coordinates,axis=0)) # difference = # print diff_coordinates # print "%5d %8.3f A" % (k, rmsd[k]) print "frame ", ts.frame, " diff ", np.average(norm) # print "frame " , ts.frame, " n " , rms frame.append(ts.frame) g2.append(np.average(norm)) frame = np.array(frame) g2 = np.array(g2) # os.system("convert -delay ") save_plot(frame, g2, psffile)
def main(args): """main func""" psffile = get_path_names.get_filename(args.psffile) u = MDAnalysis.Universe(psffile + '.psf', args.traj) bonds = AnalyzeChain.get_bondlist_coords(u.residues[0]) L = 0. # number of lamellae # the skip on the left and on the right, nleft, nright = int(args.neigh) / 2, int(args.neigh) / 2 Nbonds = len(bonds) Nres = len(u.residues) timeframes, L_array = [], [] if args.filedumpskip: dumpskip = AnalyzeLog.get_dumpskip(filename='dumpskip.txt', keyparameter="dump" + args.keyparameter + "skip") timestep = AnalyzeLog.get_timestep(filename='dumpskip.txt', keyparameter="time" + args.keyparameter + "step") else: print "using given parameters" dumpskip = args.dumpskip timestep = args.timestep for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]: print "frame = {frame}, percent of lamellae={num_of_lam}"\ .format(frame=ts.frame, num_of_lam=L/float(Nres)) timeframes.append(ts.frame) L = 0. for myres in u.residues: bonds = AnalyzeChain.get_bondlist_coords(myres) Flag = True # assume we hit the straight segment of the chain atom_indices = [] # indices of atoms in the current lamellae for i in xrange(nleft, Nbonds - nright - 1): if not Flag: # if we ended a straight segment, check the len Nlam = len(atom_indices) if Nlam > 9: L += 1. # print colored( 'lamellae size is %d ' % Nlam, 'green') # start looking for a new lamellae atom_indices = [] Flag = True else: # if we still are hitting straight segments ci = get_seg_cryst(i, bonds, threshold=args.threshold, neigh=args.neigh) if ci > args.threshold: # print "segment = %d, | ci = %4.3f" % (i,ci) Flag = True atom_indices.append(i) elif ci > 0.0: # print "segment = %d, > ci = %4.3f" % (i,ci) Flag = False else: ValueError("crystallinity is negative") L_array.append(L / float(Nres)) timeframes = np.array(timeframes) L_array = np.array(L_array) save_plots.save_plot(timeframes, L_array, plotname='lamellae', name=psffile, logplot=args.logplot, dumpskip=dumpskip, timestep=timestep, ylabel='frac{N_{stems}}{N_{chains}}')
def main(): args = read_parameters.read_traj_vmd() print args u = MDAnalysis.Universe(args.psffile, args.traj) psffile = get_path_names.get_filename(u.filename) n_atoms_per_box = args.nAtomsPerBox Natoms = u.trajectory.numatoms Nx_atoms = Natoms**(1./3.) # how many atoms in a line Nsub = int(Nx_atoms / float(n_atoms_per_box)) # how many segements of 3 atoms cryst_all = 0.0 # box = u.trajectory.ts.dimensions[:-3] # length_x = box[-1] u.SYSTEM.packIntoBox() a = u.selectAtoms("all") c = a.coordinates() print c length_x = a.bbox().max() grid_1d = np.linspace(0.0, length_x, Nsub+1, endpoint=True) delta = grid_1d[1] - grid_1d[0] frame = [] g2 = [] if args.filedumpskip: dumpskip = AnalyzeLog.get_dumpskip(filename='dumpskip.txt', keyparameter="dump" + args.keyparameter+"skip") # dumpskip = args.dumpskip timestep = AnalyzeLog.get_timestep(filename='dumpskip.txt', keyparameter="time" + args.keyparameter + "step") else: print "using given parameters" dumpskip = args.dumpskip timestep = args.timestep # decide the skipping information if args.auto_traj_skip: trajskip = int(u.trajectory.numframes/120.) if trajskip < 1: trajskip = 1 elif args.auto_traj_skip: trajskip = args.trajskip else: raise ValueError("trajskip needs to be provided") for ts in u.trajectory[args.startframe:args.endframe:trajskip]: # ar_z is a planar selection u.SYSTEM.packIntoBox() for i, z in enumerate(grid_1d[0:-1]): ar_z = u.selectAtoms("prop z >= " + str(z) + " and prop z < " + str(z+delta)) # print " I am in z ", z # print len(ar_z) # ater this step ar_y is a line for j, y in enumerate(grid_1d[0:-1]): ar_y = ar_z.selectAtoms("prop y >= " + str(y) + " and prop y < " + str(y+delta)) # print " I am in y ", y # print len(ar_y) # ater this step ar_x is a dot for k, x in enumerate(grid_1d[0:-1]): ar_x = ar_y.selectAtoms("prop x >= " + str(x) + " and prop x < " + str(x+delta)) # print " I am in x ", x # print len(ar_x) bonds = AnalyzeChain.get_bondlist_coords(ar_x) cryst_all += get_cryst(bonds, get_eigvec(bonds), threshold=args.threshold) frame.append(ts.frame) cryst_all /= float(Nsub**3.0) g2.append(cryst_all) print "frame ", ts.frame, " cryst = ", cryst_all frame = np.array(frame) g2 = np.array(g2) # os.system("convert -delay ") save_plots.save_plot(frame, g2, plotname='YC', name=psffile, logplot=args.logplot, dumpskip=dumpskip, timestep=timestep) return None