def cleanup(self): repid = molrep.repindex(self.molid, self.gray_rep) if repid != -1: molrep.delrep(self.molid, repid) repid = molrep.repindex(self.molid, self.color_rep) if repid != -1: molrep.delrep(self.molid, repid) labels = label.listall(label.BOND) for l in labels: label.delete(label.BOND, l) if self.fig is not None: plt.close(self.fig) self.tk.unregister(self)
def changeMaterial(self, material): """ Change the material for the rep to 'material'.""" for id,name in self.molecules.items(): repid = molrep.repindex(id, name) if not molrep.modrep(id, repid, material=material): raise ValueError, "Invalid material'%s'" % material self.material = str(material)
def changeSelection(self, selection): """ Change the atom selection of the rep to 'selection'.""" for id,name in self.molecules.items(): repid = molrep.repindex(id, name) if not molrep.modrep(id, repid, sel=selection): raise ValueError, "Invalid selection '%s'" % selection self.selection = str(selection)
def changeColor(self, color): """ Change the coloring method the rep to 'color'.""" for id,name in self.molecules.items(): repid = molrep.repindex(id, name) if not molrep.modrep(id, repid, color=color): raise ValueError, "Invalid color '%s'" % color self.color = str(color)
def changeStyle(self, style): """ Change the draw style of the rep to 'style'.""" for id,name in self.molecules.items(): repid = molrep.repindex(id, name) if not molrep.modrep(id, repid, style=style): raise ValueError, "Invalid style '%s'" % style self.style = str(style)
def delRep(self, rep): """ Remove the given rep from the molecule.""" repname = rep.remove_molecule(self.id) if repname: repid = molrep.repindex(self.id, repname) if repid >= 0: molrep.delrep(self.id, repid)
def changeMaterial(self, material): """ Change the material for the rep to 'material'.""" for id, name in self.molecules.items(): repid = molrep.repindex(id, name) if not molrep.modrep(id, repid, material=material): raise ValueError, "Invalid material'%s'" % material self.material = str(material)
def changeSelection(self, selection): """ Change the atom selection of the rep to 'selection'.""" for id, name in self.molecules.items(): repid = molrep.repindex(id, name) if not molrep.modrep(id, repid, sel=selection): raise ValueError, "Invalid selection '%s'" % selection self.selection = str(selection)
def changeColor(self, color): """ Change the coloring method the rep to 'color'.""" for id, name in self.molecules.items(): repid = molrep.repindex(id, name) if not molrep.modrep(id, repid, color=color): raise ValueError, "Invalid color '%s'" % color self.color = str(color)
def changeStyle(self, style): """ Change the draw style of the rep to 'style'.""" for id, name in self.molecules.items(): repid = molrep.repindex(id, name) if not molrep.modrep(id, repid, style=style): raise ValueError, "Invalid style '%s'" % style self.style = str(style)
def autoUpdate(self, rep, onoff = None): """ Get/set whether this rep should be recalculated whenever the coordinate frame changes for this molecule. """ # Get the repid for this rep try: name = rep.molecules[self.id] except KeyError: raise ValueError, "This molecule does not contain this rep." repid = molrep.repindex(self.id, name) if onoff is None: return molrep.get_autoupdate(self.id, repid) molrep.set_autoupdate(self.id, repid, onoff) return self
def autoUpdate(self, rep, onoff=None): """ Get/set whether this rep should be recalculated whenever the coordinate frame changes for this molecule. """ # Get the repid for this rep try: name = rep.molecules[self.id] except KeyError: raise ValueError, "This molecule does not contain this rep." repid = molrep.repindex(self.id, name) if onoff is None: return molrep.get_autoupdate(self.id, repid) molrep.set_autoupdate(self.id, repid, onoff) return self
def showtime(self, frame, old_frame): if not self.loaded_frames: # Initialize display self.loaded_frames = True numframes = molecule.numframes(self.molid) self.pairs = [set() for i in range(numframes)] self.gray_res_sels = ['none' for i in range(numframes)] self.color_res_sels = ['none' for i in range(numframes)] first_frame = 0 for i, time in enumerate(self.change_times): while first_frame < numframes and first_frame < time: first_frame += 1 if first_frame > numframes - min(6, self.window + 1): break if first_frame < min(5, self.window): continue begin = max(first_frame - self.window, 0) for j in range(i-1,-1,-1): if self.change_times[j] <= begin: break if len(self.changes[self.change_times[j]] & self.changes[self.change_times[i]]) > 0: begin = 0 while begin < first_frame and begin < self.change_times[j]: begin += 1 break end = min(first_frame + self.window, numframes) for j in range(i+1, len(self.change_times)): if self.change_times[j] > end-1: break if len(self.changes[self.change_times[j]] & self.changes[self.change_times[i]]) > 0: end = numframes while end > first_frame and end-1 >= self.change_times[j]: end -= 1 break if begin >= first_frame or end <= first_frame + 1: continue all_changed = [] for pair in self.changes[time]: a0_all = self._info_to_ids(pair[0]) a1_all = self._info_to_ids(pair[1]) for a0 in a0_all: for a1 in a1_all: before_dists = [float(v) for v in vmd.VMDevaltcl( 'measure bond {%d %d} molid %d first %d last %d' % (a0, a1, self.molid, begin, first_frame-1)).split()] before_med = np.median(before_dists) after_dists = [float(v) for v in vmd.VMDevaltcl( 'measure bond {%d %d} molid %d first %d last %d' % (a0, a1, self.molid, first_frame, end-1)).split()] after_med = np.median(after_dists) if self.label_before_after is not None: label_before, label_after = \ self.label_before_after( before_med, after_med, a0, a1) else: label_before = False label_after = False if label_before: self.pairs[first_frame-1].add((a0,a1)) if label_after: self.pairs[first_frame].add((a0,a1)) all_changed += list(a0_all) + list(a1_all) for f in range(begin, end): sel = 'same residue as index' for changed_atom in all_changed: sel += ' %d' % changed_atom if self.disp_h: sel = ' or (%s)' % sel else: sel = ' or ((' + sel + ') and not (element H and' + \ ' withinbonds 1 of element C))' if f == first_frame - 1 or f == first_frame: self.color_res_sels[f] += sel else: self.gray_res_sels[f] += sel old_frame = None gray_repid = molrep.repindex(self.molid, self.gray_rep) if gray_repid == -1: # User deleted molrep to display residues--recreate this molrep molrep.addrep(self.molid, style='Licorice', color='ColorID 2', selection='none', material='Opaque') self.gray_rep = molrep.get_repname(self.molid, molrep.num(self.molid)-1) gray_repid = molrep.repindex(self.molid, self.gray_rep) old_frame = None color_repid = molrep.repindex(self.molid, self.color_rep) if color_repid == -1: # User deleted molrep to display residues--recreate this molrep molrep.addrep(self.molid, style='Licorice', color='Element', selection='none', material='Opaque') self.color_rep = molrep.get_repname(self.molid, molrep.num(self.molid)-1) color_repid = molrep.repindex(self.molid, self.color_rep) old_frame = None if old_frame is None \ or self.gray_res_sels[old_frame] != self.gray_res_sels[frame]: molrep.modrep(self.molid, gray_repid, sel=self.gray_res_sels[frame]) if old_frame is None or \ self.color_res_sels[old_frame] != self.color_res_sels[frame]: molrep.modrep(self.molid, color_repid, sel=self.color_res_sels[frame]) if old_frame is None or self.pairs[old_frame] != self.pairs[frame]: labels = label.listall(label.BOND) for l in labels: label.delete(label.BOND, l) os.environ['VMD_QUIET_STARTUP'] = '1' molid_pair = (self.molid, self.molid) for pair in self.pairs[frame]: label.add(label.BOND, molid_pair, pair) os.environ.pop('VMD_QUIET_STARTUP') # Update plot of indicator variable if self.fig is None or self.fig.canvas.window is None: # Figure has not been created or was closed by user--create new # figure self.fig = plt.figure() # Need to replot everything if the figure window is resized self.fig.canvas.mpl_connect('resize_event', lambda ev, s=self: s.replot()) self.fig.show() self.ax = self.fig.add_subplot(111) self.line = self.ax.axvline(0, animated=True, color='r', linewidth=2) self.replot() self.fig.canvas.restore_region(self.dataplot) self.line.set_xdata(frame) self.ax.draw_artist(self.line) self.fig.canvas.blit(self.ax.bbox)