import Pmw from MinrmsPlot import ActivePlot class ilmmPlotDialog(chimera.baseDialog.ModelessDialog): "ilmm Plot Window" name = "ilmm Plot Window" buttons = ("Add...", "Remove...", "Save...", "Close") help = ("ilmmPlotWindow.html", ilmm) title = "ilmm plot window" def fillInUI(self, parent): self.x0 = self.y0 = self.x1 = self.y1 = 0 parent.focus_set() self.graph = Pmw.Blt.Graph(parent) self.graph.pack(expand = 1, fill = "both") self.graph.bind(sequence = "", func = self.mouseDown) self.graph.bind(sequence = "", func = self.mouseUp ) self.datax = [] self.datay = [] self.LoadData() def LoadData(self): datagroups = [["Total Energy", "e.dat", "black"], ["Kinetic Energy", "ek.dat", "green"], ["Potential Energy", "ep.dat", "blue"], ["Seconds / ps", "secs.dat", "yellow"], ["Temperature", "t.dat", "red"]] dataset = 0 self.datax.append([]) self.datay.append([]) for group in datagroups: [name, filename, color] = group fullfilename = "/tmp/chimera-dev@cgl.ucsf.edu/" % filename file = open(fullfilename, 'r') for line in file.readlines(): [x, y] = string.split(line, ' ') self.datax[dataset].append(float(x)) self.datay[dataset].append(float(y)) file.close() self.graph.line_create(name, xdata = tuple(self.datax[dataset]), ydata = tuple(self.datay[dataset]), color = color, symbol = '') self.datax.append([]) self.datay.append([]) dataset = dataset + 1 def zoom(self, x0, y0, x1, y1): self.graph.xaxis_configure(min = x0, max = x1) self.graph.yaxis_configure(min = y0, max = y1) def mouseDrag(self, event): (self.x1, self.y1) = self.graph.invtransform(event.x, event.y) self.graph.marker_configure("marking rectangle", coords = (self.x0, self.y0, self.x1, self.y0, self.x1, self.y1, self.x0, self.y1, self.x0, self.y0)) def mouseUp(self, event): if self.dragging: self.graph.unbind(sequence="") self.graph.marker_delete("marking rectangle") if self.x0 <> self.x1 and self.y0 <> self.y1: # make sure the coordinates are sorted if self.x0 > self.x1: self.x0, self.x1 = self.x1, self.x0 if self.y0 > self.y1: self.y0, self.y1 = self.y1, self.y0 if event.num == 1: self.zoom(self.x0, self.y0, self.x1, self.y1) else: (X0, X1) = self.graph.xaxis_limits() k = (X1 - X0)/ (self.x1 - self.x0) self.x0 = X0 - (self.x0 - X0) * k self.x1 = X1 + (X1 - self.x1) * k (Y0, Y1) = self.graph.yaxis_limits() k = (Y1 - Y0) / (self.y1 - self.y0) self.y0 = Y0 - (self.y0 - Y0) * k self.y1 = Y1 + (Y1 - self.y1) * k self.zoom(self.x0, self.y0, self.x1, self.y1) def mouseDown(self, event): self.dragging = 0 if self.graph.inside(event.x, event.y): self.dragging = 1 (self.x0, self.y0) = self.graph.invtransform(event.x, event.y) self.graph.marker_create("line", name = "marking rectangle", dashes = (2, 2)) self.graph.bind(sequence = "", func = self.mouseDrag) def Add(self): pass def Remove(self): pass def Save(self): pass # register the dialog with chimera chimera.dialogs.register(ilmmPlotDialog.name, ilmmPlotDialog) # add its callback to the toolbar dir, file = os.path.split(__file__) icon = os.path.join(dir, 'plot.png') chimera.tkgui.app.toolbar.add(icon, lambda d=chimera.dialogs.display, n=ilmmPlotDialog.name: d(n), ilmmPlotDialog.title, None)