Beispiel #1
0
    def _build_disconnectivity_graph(self, show_minima=True, **params):
        #this should be somewhere else
        if self.database is None:
            graph = self.graph
        else:
            db = self.database
            graphwrapper = Graph(db)
            graph = graphwrapper.graph
        dg = DisconnectivityGraph(graph, **params)
        dg.calculate()
        
        ax = self.canvas.axes
        ax.clear()
        ax.hold(True)        

        #draw minima as points and make them interactive
        if show_minima:
            xpos, minima = dg.get_minima_layout()
            energies = [m.energy for m in minima]
            points = ax.scatter(xpos, energies, picker=5)        
            
            def on_pick(event):
                if event.artist != points:
    #                print "you clicked on something other than a node"
                    return True
                thispoint = event.artist
                ind = event.ind[0]
                min1 = minima[ind]
                print "you clicked on minimum with id", min1._id, "and energy", min1.energy
                self.minimum_selected(min1)
            self.canvas.mpl_connect('pick_event', on_pick)
        
        # plot the lines and set up the rest of the plot using the built in function 
        dg.plot(axes=ax, show_minima=False)
        self.canvas.draw()
Beispiel #2
0
    def show_disconnectivity_graph(self):
        import pylab as pl
        pl.ion()
        pl.clf()
        ax = pl.gca()
        fig = pl.gcf()

        graphwrapper = Graph(self.system.database)
        dg = DisconnectivityGraph(graphwrapper.graph, subgraph_size=2)
        dg.calculate()
        
        #draw minima as points
        xpos, minima = dg.get_minima_layout()
        energies = [m.energy for m in minima]
        points = ax.scatter(xpos, energies, picker=5)
        
        #draw line segments connecting minima
        line_segments = dg.line_segments
        for x, y in line_segments:
            ax.plot(x, y, 'k')
        
        
        #define what happens when a point is clicked on
        global pick_count
        pick_count = 0
        def on_pick(event):
            if event.artist != points:
#                print "you clicked on something other than a node"
                return True
            thispoint = event.artist
            ind = event.ind[0]
            min1 = minima[ind]
            print "you clicked on minimum with id", min1._id, "and energy", min1.energy
            global pick_count
            #print pick_count
            pick_count += 1
            if (pick_count % 2) == 0:
                self._SelectMinimum1(min1)
            else:
                self._SelectMinimum2(min1)
        fig = pl.gcf()
        cid = fig.canvas.mpl_connect('pick_event', on_pick)

        pl.show()