def write_trajectory(universe, filename): '''A simplified method for writing trajectories ''' w = Writer(filename, universe.atoms.numberOfAtoms()) for ts in universe.trajectory: w.write(ts) w.close()
def write_trajectory(universe, filename, maximum_frames=0): '''A simplified method for writing trajectories ''' w = Writer(filename, universe.atoms.numberOfAtoms()) frame_count = 0 for ts in universe.trajectory: if(maximum_frames != 0 and frame_count == maximum_frames): break w.write(ts) frame_count += 1 w.close()
TRJ_LIST.append(sys.argv[2 + i]) outtrj = "traj.xtc" # create a writer instance for the output trajectory print "Reading trajectory %s" % TRJ_LIST[0] u = Universe(topol, TRJ_LIST[0]) w = Writer(outtrj, u.trajectory.numatoms) FRAME = 0 for j in range(len(TRJ_LIST)): if u.trajectory.dt == 0.0: print "No time step information found in the trajectoy file." DT = raw_input("Input a float number for the time step:") u.trajectory.dt = float(DT) else: print "Time step %6.4f was found and will be used in the new trajectory." % u.trajectory.dt for ts in u.trajectory: FRAME = FRAME + 1 ts.time = (FRAME - 1) * u.trajectory.dt w.write(ts) if FRAME % 100 == 0: echo("Converted frame %8d ,time %8.2f\r" % (ts.frame, FRAME * u.trajectory.dt)) if j < len(TRJ_LIST) - 1: print "" print "Reading trajectory %s" % TRJ_LIST[j + 1] u = Universe(topol, TRJ_LIST[j + 1]) w.close() print "Writing the result file traj.xtc finished."
outtrj = "traj.xtc" # create a writer instance for the output trajectory print "Reading trajectory %s" %TRJ_LIST[0] u = Universe(topol, TRJ_LIST[0]) w = Writer(outtrj, u.trajectory.numatoms) FRAME=0 for j in range(len(TRJ_LIST)): if u.trajectory.dt==0.0: print "No time step information found in the trajectoy file." DT=raw_input("Input a float number for the time step:") u.trajectory.dt=float(DT) else: print "Time step %6.4f was found and will be used in the new trajectory." %u.trajectory.dt for ts in u.trajectory: FRAME=FRAME+1 ts.time=(FRAME-1)*u.trajectory.dt w.write(ts) if FRAME %100==0: echo("Converted frame %8d ,time %8.2f\r" %(ts.frame,FRAME*u.trajectory.dt)) if j < len(TRJ_LIST)-1: print "" print "Reading trajectory %s" %TRJ_LIST[j+1] u = Universe(topol, TRJ_LIST[j+1]) w.close() print "Writing the result file traj.xtc finished."
Index[nst] = [n] else: print "Error: ", n, nst, N_str ifile.close() print 'number of clusters:', len(N_str) N_str.sort() N_str.reverse() N_write = int(raw_input('How many clusters you want to look at (eg. 8): ')) universe = Universe(pdbfile, pdbfile) writer = Writer(filename + '_.pdb', universe.atoms.numberOfAtoms()) k = 1 for each in N_str[:N_write]: if k > N_write: break percent = float(each) * 100 / sum(N_str) for i in Index[each]: print 'Writing cluster #' + str(i).ljust(3), universe.trajectory[i - 1] protein = universe.atoms writer.write(protein) print '%3i %5.0f%% %6.2f%%' % (k, percent, percent) k += 1 writer.close()