def read_xtc_coarse(grofile, xtcfile, keep_atomistic=False, cutoff=0, cm_map=False): global sugar_atom_nums, verbose t_start = time.clock() u = AtomGroup.Universe(grofile, xtcfile) sel = u.selectAtoms("not resname SOL") res_name = sel.resnames()[0] if verbose: print(sel) print(res_name) print(sel.names()) for name in sel.names(): sugar_atom_nums[name] = list(sel.names()).index(name) if cutoff: #if a cutoff is specified it means we want to calculate solvent RDF sel = u.selectAtoms("resname " + res_name + " or around " + str(cutoff) + " resname " + res_name) if verbose: print(sel.resnames()) print(sel.names()) if keep_atomistic: frames = [] cg_frames = [] i = 0 num_frames = len(u.trajectory) print(num_frames) for ts in u.trajectory: perc = i * 100. / num_frames if (i % 100 == 0): sys.stdout.write("\r{:2.0f}% ".format(perc) + "X" * int(0.2 * perc) + "-" * int(0.2 * (100 - perc))) sys.stdout.flush() frame = Frame(i) for atomname, coords, mass in zip(sel.names(), sel.get_positions(ts), sel.masses()): if not cm_map: mass = 1 frame.atoms.append( Atom(atomname, coords, atomic_charges[atomname], mass=mass)) cg_frames.append(map_cg_solvent_within_loop(i, frame)) if keep_atomistic: frames.append(frame) i += 1 t_end = time.clock() print("\rRead {0} frames in {1}s".format(num_frames, (t_end - t_start))) if verbose: cg_frames[0].show_atoms() print("-" * 20) #for atom in cg_frames[0].atoms: #print(atom) if keep_atomistic: return frames, cg_frames else: return [], cg_frames
def read_xtc_setup(grofile, xtcfile, cutoff=0, cm_map=False): """ setup Frame object for reading trajectory into select atoms in sugar and set atom numbers """ global sugar_atom_nums, verbose u = AtomGroup.Universe(grofile, xtcfile) sel = u.selectAtoms("not resname SOL") res_name = sel.resnames()[0] if verbose: print(sel) print(res_name) print(sel.names()) for name in sel.names(): sugar_atom_nums[name] = list(sel.names()).index(name) # if a cutoff is specified it means we want to calculate solvent RDF if cutoff: # select the first residue and anything within 'cutoff' nm sel = u.selectAtoms("resname " + res_name + " or around " + str(cutoff) + " resname " + res_name) if verbose: print(sel.resnames()) print(sel.names()) num_frames = len(u.trajectory) frame = Frame(0) ts_init = u.trajectory[0] for pack in zip(sel.names(), sel.get_positions(ts_init), sel.masses()): atomname, coords, mass = pack if not cm_map: mass = 1 try: atomic_charges[atomname] except KeyError: pass else: frame.atoms.append( Atom(atomname, coords, atomic_charges[atomname], mass=mass)) print(num_frames) print(sugar_atom_nums) cg_frame = map_cg_solvent_within_loop(0, frame) print("Done xtc setup\n" + "-" * 20) # return the total number of frames in trajectory # placeholders for the two Frame objects # and the two internal trajectory pieces return num_frames, frame, cg_frame, sel, u