def main(): args = read_traj_vmd() psffile = os.path.splitext(args.psffile)[0] u = Universe(psffile + '.psf', 'trajectory_nve.dcd') Nres = len(u.residues) frame = [] g2 = [] res_g2 = 0. fig = plt.figure() plt.ylim(0, 1) ims = [] for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]: all_g2 = 0. k = 0 frame.append(ts.frame) for res in u.residues: chords = get_bondlist_coords(res) res_g2 = get_chain_crystallinity(chords, 4) all_g2 += res_g2 print("frame %d , g2 = %f" % (ts.frame, all_g2 / float(Nres))) g2.append(all_g2 / float(Nres)) frame = np.array(frame) g2 = np.array(g2) # os.system("convert -delay ") save_plot(frame, g2, psffile)
def main(): """ the main function""" args = read_traj_vmd() psffile = os.path.splitext(args.psffile)[0] # calc_rdf(args) plot_rdf(psffile)
def main(): args = read_traj_vmd() psffile = os.path.splitext(args.psffile)[0] u = Universe(psffile+'.psf', 'trajectory_nve.dcd') Nres = len(u.residues) frame = [] g2 = [] res_g2 = 0. fig = plt.figure() plt.ylim(0,1) ims = [] for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]: all_g2 = 0. k = 0 frame.append(ts.frame) for res in u.residues: chords = get_bondlist_coords(res) res_g2 = get_chain_crystallinity(chords,4) all_g2 += res_g2 print ("frame %d , g2 = %f" %(ts.frame, all_g2 / float(Nres))) g2.append(all_g2 / float(Nres)) frame = np.array(frame) g2 = np.array(g2) # os.system("convert -delay ") save_plot(frame,g2,psffile)
def main(): """ analyze equilibration of melt """ args = read_traj_vmd() print " " print " ====================== " print " done inputing the trajectory" print args print "" print " ====================== " print " " calc_r2n(args) print " " print " ====================== " print " done r2(n)/n" print "" print " ====================== " print " " calc_rgre(args) print " " print " ====================== " print " done rgre" print "" print " ====================== " print " " calc_rmsd(args) print " " print " ====================== " print " done rmsd" print "" print " ====================== " print " " calc_rdf(args) plot_rdf(args) print " " print " ====================== " print " done rdf" print "" print " ====================== " print " " # logargs = read_log() # print " " # print " ====================== " # print " done inputing the log" # print logargs # print "" # print " ====================== " # print " " # analyze_log(logargs) return None
def main(): args = read_parameters.read_traj_vmd() u = Universe(args.psffile+'.psf',args.traj) trajskip = args.trajskip box = u.universe.dimensions[:3] L = box[0] print (L) for ts in u.trajectory[1:-1:trajskip]: atoms,angles = get_angles(u) g2 = 0.0 # print (atoms,angles) g2 = Calcg2(atoms,angles,L) print ("frame %d , g2 = %f" %(ts.frame, g2))
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(): """main programm""" args = read_traj_vmd() psffile = os.path.splitext(args.psffile)[0] u = Universe(psffile + '.psf', args.traj) # u.trajectory[-1] angles = u.angles.angles() ymax = len(angles) / 10 xmax = angles.max() * 1.1 for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]: print " frame = %d " % ts.frame angles = u.angles.angles() plt.cla() plt.ylim(0., ymax) plt.xlim(0., xmax) plt.title("frame = %d" % ts.frame) plt.hist(angles, bins=100, alpha=0.75) plt.savefig("angles_hist_%.5d.png" % ts.frame) os.system("convert -delay 60 angles_*.png anim_angles.gif") os.system("rm angles*.png")
def main(): args = read_traj_vmd() psffile = os.path.splitext(args.psffile)[0] u = Universe(psffile+'.psf', 'trajectory_nve.dcd') Nres = len(u.residues) frame = [] g2 = [] chainlengths = [] chaing2s = [] res_g2 = 0. fig = plt.figure() plt.ylim(0,1) ims = [] for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]: all_g2 = 0. k = 0 chainlengths = [] chaing2s = [] frame.append(ts.frame) for res in u.residues: chords = get_bondlist_coords(res) res_g2 = get_chain_crystallinity(chords,4) all_g2 += res_g2 chainlengths.append(len(res)) chaing2s.append(res_g2) chainlengths = np.array(chainlengths) chaing2s = np.array(chaing2s) bins, histogram = create_hist_chainlength(chainlengths,chaing2s) plt.ylim(0,1) im = plt.bar(bins,histogram,10.0) ims.append([im]) plt.savefig('hist'+str(ts.frame)+'.png') plt.cla() print ("frame %d , g2 = %f" %(ts.frame, all_g2 / float(Nres))) g2.append(all_g2 / float(Nres)) frame = np.array(frame) g2 = np.array(g2)
def main(): args = read_traj_vmd() psffile = os.path.splitext(args.psffile)[0] u = Universe(psffile+'.psf', args.traj) time, g2 = [], [] box = u.universe.dimensions[:3] L = box[0] print (L) for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]: # bonds, atoms = get_bondlist_coords(u) atoms,angles = get_angles(u) # bonds, atoms = get_bonds(u) N=atoms.shape[0] g = 0.0 # print (atoms,angles) g = Calcg2(atoms,angles,L) # result = ft.sparam(natoms=N,bonds=bonds,atoms=atoms,around=2.0,s=s) print "frame is " , ts.frame, " order = ", g time.append(ts.frame) g2.append(g) # Rgyr = np.sum(np.array([myres.atoms.radiusOfGyration(pbc=True) for myres in u.residues])) # Rgyr /= len(u.residues) # gyr.append(Rgyr*Rgyr) # R2 = np.sum(np.array([distance_sq_coords(myres.atoms[0].pos,myres.atoms[-1].pos) for myres in u.residues])) # R2 /= len(u.residues) # gr2.append(R2) time = np.array(time) g2 = np.array(g2) save_plot_cryst_cos(time,g2,psffile)
def main(): args = read_traj_vmd() psffile = os.path.splitext(args.psffile)[0] u = Universe(psffile+'.psf', 'trajectory_nve.dcd') ref_atoms = u.selectAtoms("all") traj_atoms = u.selectAtoms("all") natoms = traj_atoms.numberOfAtoms() # 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) # 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 " , diff
def main(): args = read_traj_vmd() analyze_chain_hist(args)
def main(): """main programm""" args = read_parameters.read_traj_vmd() calc_cryst(args)
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
def main(): args = read_traj_vmd() calc_rgre(args) calc_rmsd(args)
def main(): args = read_traj_vmd() psffile = os.path.splitext(args.psffile)[0] PSF = psffile + '.psf' DCD = args.traj u = Universe(PSF, DCD) userdata = "tmp_viz.txt" vmdscript = "viz_dat.vmd" timeseries = [] len_cryst_array = np.zeros(len(u.atoms)) for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]: for res in u.residues: len_cryst_array[res.atoms.indices] = len(res) timeseries.append(len_cryst_array) print "frame %d" % ts.frame print "result ", np.average(len_cryst_array) # serialize: add a marker 'END' after each frame marker = 'END' with open(userdata, 'w') as data: for len_cryst_array in timeseries: data.write("\n".join([str(x) for x in len_cryst_array])) data.write("\n{0}\n".format(marker)) # write VMD loader script parameters = { 'vmdfile': vmdscript, 'datafile': userdata, 'topology': PSF, 'trajectory': DCD, 'startframe': args.startframe, 'endframe': args.endframe, 'trajskip': int(args.trajskip) } script = """\ proc loaduserdata { fname } { set all [atomselect top all] set frame 0 set data [open $fname r] while { [gets $data line] != -1 } { set value [string trim $line] switch -- [string range $value 0 2] { END { $all frame $frame $all set user $beta # $all set vx $beta set beta {} incr frame } default { lappend beta $line } } } } """ + """ mol new "{0[topology]}" animate read dcd "{0[trajectory]}" skip {0[trajskip]} waitfor all # mol addfile "{0[trajectory]}" type {{dcd}} first 0 last -2 step 1 waitfor # mol addfile "{0[trajectory]}" waitfor all animate goto 0 loaduserdata "{0[datafile]}" color change rgb 0 0.1 0.2 0.7 ;# blue color change rgb 1 0.7 0.2 0.1 ;# red color change rgb 3 0.7 0.4 0.0 ;# orange color change rgb 4 0.8 0.7 0.1 ;# yellow color change rgb 7 0.1 0.7 0.2 ;# green color change rgb 10 0.1 0.7 0.8 ;# cyan color change rgb 11 0.6 0.1 0.6 ;# purple # color Display Background white #black color Display Background white # mol selupdate 0 0 1 # mol colupdate 0 0 1 mol modcolor 0 top User mol material AOChalky mol addrep 0 mol modselect 0 0 user > 150 mol modselect 1 0 user < 50 mol modcolor 1 0 ColorID 0 # mol modstyle 1 0 CPK 1.000000 0.300000 12.000000 12.000000 mol modstyle 1 0 Licorice 0.300000 12.000000 12.000000 mol modmaterial 1 0 Diffuse # mol modcolor 0 0 ColorID 0 # mol modcolor 0 0 ColorID 1 # # mol modstyle 0 0 Licorice 0.500000 46.000000 58.000000 # # mol material 0 0 AOChalky # mol modmaterial 0 0 AOChalky # mol modstyle 0 0 Licorice 0.600000 48.000000 58.000000 # mol modcolor 1 0 ColorID 7 # # mol modstyle 1 0 VDW 0.600000 27.000000 # mol modselect 0 0 user > 0.6 # mol modstyle 0 top Lines # mol modstyle 0 top VDW # mol modmaterial 0 0 AOChalky # box_molecule top """.format(parameters) with open(vmdscript, 'w') as tcl: tcl.write(script + '\n') print("Wrote data trajectory {0} with len_cryst_array".format(userdata)) print("Wrote VMD script {0}: 'source {0}' to load everything ".format( vmdscript))
def main(): args = read_traj_vmd() calc_r2n(args)
def main(): args = read_traj_vmd() calc_sq(args)
def main(): args = read_parameters.read_traj_vmd() calc_bondacf(args)
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}}') # print "number of lammelae in the chain 1 is = %f" % float(L/Nres) if __name__ == '__main__': args = read_parameters.read_traj_vmd() main(args)
def main(): """creates wraped trajectory""" args = read_traj_vmd() # psffile = os.path.splitext(args.psffile)[0] create_wrapdcd(args)
# Purpose: Cuts Trajectory for download (in future will wrap it as well) # Author: Triandafilidi Vasiliy , MSc student at CHBE UBC, Vancouver # e-mail: vtriandafilidi(at)chbe(dot)ubc(dot)ca # Syntax: python CreateCutTraj.py -h for help, # Requires: read_parameters.py # Copyright (c) 2014 Vasiliy Triandafilidi # Released under the GNU Public Licence, v2 or any higher version # todo: add wrapping feature, make function look nice from read_parameters import read_traj_vmd import os from termcolor import colored args = read_traj_vmd() psffile = os.path.splitext(args.psffile)[0] PSF = psffile + '.psf' DCD = os.path.splitext(args.traj)[0] + '.dcd' DATA = os.path.splitext(args.datafile)[0] + '.data' vmdfile = "create_cuttraj.vmd" bashfile = "create_cuttraj.sh" resfolder = psffile + '_results' # write VMD loader script parameters = { 'vmdfile': vmdfile, 'topology': PSF, 'datafile': DATA, 'trajectory': os.path.basename(DCD), 'trajskip': args.trajskip,
def main(): args = read_parameters.read_traj_vmd()
def main(): args = read_parameters.read_traj_vmd() calc_clusters(args)
def main(): args = read_traj_vmd() # calc_sq_rdf(args) # print "doing sq direct" calc_sq(args)