def setup(self, args): protsel = self.processor.universe.select_atoms(args.pmask) self.uselib = args.uselib if self.uselib == "no": self.atm2 = protsel.select_atoms("name " + args.atoms[1]) self.atm1 = protsel.select_atoms("name " + args.atoms[0] + " and byres name " + args.atoms[1]) elif self.uselib in resanallib: lib = resanallib[self.uselib] atm1 = [] atm2 = [] for res in self.processor.universe.select_atoms( "protein").residues: if res.name not in lib: continue for atompairs in lib[res.name]: atm1.append(res[atompairs[0]]) atm2.append(res[atompairs[1]]) self.atm2 = AtomGroup.AtomGroup(atm2) self.atm1 = AtomGroup.AtomGroup(atm1) self.mat = np.zeros([len(self.atm1), len(self.atm1)]) self.s2list = [] self.outname = args.out self.dosubsample = True self.resoffset = args.resoffset
def test_merge_without_topology(self): # This shouldn't have topology as we merged single atoms ag1 = AtomGroup([self.u.atoms[1]]) ag2 = AtomGroup([self.u.atoms[10]]) u2 = MDAnalysis.Merge(ag1, ag2) assert_(len(u2.atoms) == 2) assert_(len(u2.bonds) == 0) assert_(len(u2.angles) == 0) assert_(len(u2.dihedrals) == 0) assert_(len(u2.impropers) == 0)
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
def test_emptyAG_ValueError(self): a = AtomGroup([]) b = AtomGroup([]) assert_raises(ValueError, Merge, a, b)
def test_pickle_unpickle_empty(self): """Test that an empty AtomGroup can be pickled/unpickled (Issue 293)""" ag = AtomGroup([]) pickle_str = cPickle.dumps(ag, protocol=cPickle.HIGHEST_PROTOCOL) newag = cPickle.loads(pickle_str) assert_equal(len(newag), 0)