def refine_transition_state(self, nebindex=None):
        print("refining ts")
        if nebindex is None:
            #figure out which image to start from
            if self.oglview != "neb":
                print("choose which NEB image to start from")
                return
    #            raise Exception("choose which NEB image to start from")
            nebindex = self.oglwgt.get_slider_index()
            
        self.highlight_frame(-1)
        coords = self.nebrunner.path[nebindex].copy()
        self.ui.wgt_neb.highlight_point(nebindex)
        self.app.processEvents()
    
        tsdata = []
        tscoordslist = []
        
        self.local_connect = self.nebrunner.local_connect
        #setup the callback function for findTransitionState
        def findTS_callback(coords=None, energy=None, rms=None, eigenval=None, **kwargs):
            tscoordslist.append(coords.copy())
            tsdata.append((energy, rms, eigenval))
            
        tsSearchParams = self.local_connect.tsSearchParams.copy()
        tsSearchParams["event"] = findTS_callback
        
        #setup the callback function for the pushoff
        pdata = []
        pcoordslist = []
        def pushoff_callback(coords=None, energy=None, rms=None, **kwargs):
            pcoordslist.append(coords)
            pdata.append((energy, rms))
        pushoff_params = self.local_connect.pushoff_params.copy()
        quencher = self.system.get_minimizer(events=[pushoff_callback])
        pushoff_params["quench"] = quencher

        
        success, tsret, min1ret, min2ret = _refineTS(self.system.get_potential(), coords,
                    tsSearchParams=tsSearchParams, pushoff_params=pushoff_params)
        
        #process the results of the transition state search
        self.ts_coordspath = np.array(tscoordslist)
        self.ts_labels = ["TS path: energy=%g, rms=%g, eigenval=%g"% vals for vals in tsdata]
#        print "tscoords shape", self.ts_coords.shape, len(coordslist)
        self.show_TS_path()
        
        if success:
            #process the results from the pushoff and quenches
            ret1 = min1ret[4]
            ret2 = min2ret[4]

            #the paths from falling off both sides are in pcoordslist.  try to split them up
            i = ret1.nsteps
            pushoff_coordspath1 = [tsret.coords.copy()] + pcoordslist[:i]
            pushoff_coordspath2 = [tsret.coords.copy()] + pcoordslist[i:]
            data1 = [(tsret.energy, tsret.rms)] + pdata[:i]
            data2 = [(tsret.energy, tsret.rms)] + pdata[i:]
            pushoff_labels1 = ["Pushoff left: energy=%g, rms=%g"% vals for vals in data1]
            pushoff_labels2 = ["Pushoff right: energy=%g, rms=%g"% vals for vals in data2]
            #combine them together with one in reversed order.
            self.pushoff_coordspath = list(reversed(pushoff_coordspath1)) + pushoff_coordspath2
            self.pushoff_labels = list(reversed(pushoff_labels1)) + pushoff_labels2
            self.pushoff_coordspath = np.array(self.pushoff_coordspath)
            
            #make a
            tsitem = _TSListItem(nebindex, self.ts_coordspath, self.ts_labels, self.pushoff_coordspath, self.pushoff_labels)
            self.ts_list.addItem(tsitem)
    def refine_transition_state(self, nebindex=None):
        print "refining ts"
        if nebindex is None:
            #figure out which image to start from
            if self.oglview != "neb":
                print "choose which NEB image to start from"
                return
    #            raise Exception("choose which NEB image to start from")
            nebindex = self.oglwgt.get_slider_index()
            
        self.highlight_frame(-1)
        coords = self.nebrunner.path[nebindex].copy()
        self.ui.wgt_neb.highlight_point(nebindex)
        self.app.processEvents()
    
        tsdata = []
        tscoordslist = []
        
        self.local_connect = self.nebrunner.local_connect
        #setup the callback function for findTransitionState
        def findTS_callback(coords=None, energy=None, rms=None, eigenval=None, **kwargs):
            tscoordslist.append(coords.copy())
            tsdata.append((energy, rms, eigenval))
            
        tsSearchParams = self.local_connect.tsSearchParams.copy()
        tsSearchParams["event"] = findTS_callback
        
        #setup the callback function for the pushoff
        pdata = []
        pcoordslist = []
        def pushoff_callback(coords=None, energy=None, rms=None, **kwargs):
            pcoordslist.append(coords)
            pdata.append((energy, rms))
        pushoff_params = self.local_connect.pushoff_params.copy()
        quencher = self.system.get_minimizer(events=[pushoff_callback])
        pushoff_params["quench"] = quencher

        
        success, tsret, min1ret, min2ret = _refineTS(self.system.get_potential(), coords,
                    tsSearchParams=tsSearchParams, pushoff_params=pushoff_params)
        
        #process the results of the transition state search
        self.ts_coordspath = np.array(tscoordslist)
        self.ts_labels = ["TS path: energy=%g, rms=%g, eigenval=%g"% vals for vals in tsdata]
#        print "tscoords shape", self.ts_coords.shape, len(coordslist)
        self.show_TS_path()
        
        if success:
            #process the results from the pushoff and quenches
            ret1 = min1ret[4]
            ret2 = min2ret[4]

            #the paths from falling off both sides are in pcoordslist.  try to split them up
            i = ret1.nsteps
            pushoff_coordspath1 = [tsret.coords.copy()] + pcoordslist[:i]
            pushoff_coordspath2 = [tsret.coords.copy()] + pcoordslist[i:]
            data1 = [(tsret.energy, tsret.rms)] + pdata[:i]
            data2 = [(tsret.energy, tsret.rms)] + pdata[i:]
            pushoff_labels1 = ["Pushoff left: energy=%g, rms=%g"% vals for vals in data1]
            pushoff_labels2 = ["Pushoff right: energy=%g, rms=%g"% vals for vals in data2]
            #combine them together with one in reversed order.
            self.pushoff_coordspath = list(reversed(pushoff_coordspath1)) + pushoff_coordspath2
            self.pushoff_labels = list(reversed(pushoff_labels1)) + pushoff_labels2
            self.pushoff_coordspath = np.array(self.pushoff_coordspath)
            
            #make a
            tsitem = _TSListItem(nebindex, self.ts_coordspath, self.ts_labels, self.pushoff_coordspath, self.pushoff_labels)
            self.ts_list.addItem(tsitem)
def _refineTSWrapper(inputs):
    """
    a stupid wrapper to allow _refineTS to be used with Pool.map which only supports one argument
    """
    return _refineTS(inputs[0], inputs[1], **inputs[2])