Index: prview/perspectives/pr/inversion_panel.py
===================================================================
--- prview/perspectives/pr/inversion_panel.py	(revision 32dffae4e1afdd03ed92e8646e5c3335bb00a7fb)
+++ prview/perspectives/pr/inversion_panel.py	(revision 634f1cf6c63e6c8c347746c746ab4dc929ec8540)
@@ -124,4 +124,7 @@
         self.file_radio = None
         self.plot_radio = None
+        self.label_sugg = None
+        self.qmin_ctl = None
+        self.qmax_ctl = None
         
         ## Estimates
@@ -145,4 +148,8 @@
         elif name=='chi2':
             self.chi2_ctl.SetValue("%-5.3g" % value)
+        elif name=='q_min':
+            self.qmin_ctl.SetValue("%-5.3g" % value)
+        elif name=='q_max':
+            self.qmax_ctl.SetValue("%-5.3g" % value)
         elif name=='elapsed':
             self.time_ctl.SetValue("%-5.2g" % value)
@@ -150,5 +157,9 @@
             self.osc_ctl.SetValue("%-5.2g" % value)
         elif name=='alpha_estimate':
-            self.alpha_estimate_ctl.SetValue("%-3.1g" % value)
+            self.alpha_estimate_ctl.SetToolTipString("Click to accept value.")
+            self.alpha_estimate_ctl.Enable(True)
+            self.alpha_estimate_ctl.SetLabel("%-3.1g" % value)
+            #self.alpha_estimate_ctl.Show()
+            #self.label_sugg.Show()
         elif name=='plotname':
             self.plot_data.SetValue(str(value))
@@ -170,4 +181,8 @@
         elif name=='chi2':
             self.chi2_ctl.GetValue()
+        elif name=='q_min':
+            self.qmin_ctl.GetValue()
+        elif name=='q_max':
+            self.qmax_ctl.GetValue()
         elif name=='elapsed':
             self.time_ctl.GetValue()
@@ -240,5 +255,6 @@
         label_alpha = wx.StaticText(self, -1, "Regularization constant")
         label_dmax  = wx.StaticText(self, -1, "Max distance [A]")
-        label_sugg  = wx.StaticText(self, -1, "Suggested value")
+        self.label_sugg  = wx.StaticText(self, -1, "Suggested value")
+        #self.label_sugg.Hide()
         
         self.nfunc_ctl = wx.TextCtrl(self, -1, size=(60,20))
@@ -248,11 +264,16 @@
         self.dmax_ctl  = wx.TextCtrl(self, -1, size=(60,20))
         self.dmax_ctl.SetToolTipString("Maximum distance between any two points in the system.")
-        self.alpha_estimate_ctl  = wx.TextCtrl(self, -1, size=(60,20))
+        id = wx.NewId()
+        self.alpha_estimate_ctl  = wx.Button(self, id, "")
+        #self.alpha_estimate_ctl.Hide()
+        self.Bind(wx.EVT_BUTTON, self._on_accept_alpha, id = id)   
         self.alpha_estimate_ctl.Enable(False)
-        self.alpha_estimate_ctl.SetToolTipString("Value of alpha below which P(r) may have multiple peaks.")
+        #self.alpha_estimate_ctl.SetBackgroundColour('#ffdf85')
+        #self.alpha_estimate_ctl.SetBackgroundColour(self.GetBackgroundColour())
+        self.alpha_estimate_ctl.SetToolTipString("Waiting for estimate...")
         
         # EVT_TEXT would trigger an event for each character entered
         self.nfunc_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed)
-        #self.alpha_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed)
+        self.alpha_ctl.Bind(wx.EVT_KILL_FOCUS, self._read_pars)
         self.dmax_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed)
         self.Bind(wx.EVT_TEXT_ENTER, self._on_pars_changed)
@@ -261,5 +282,5 @@
 
         iy = 0
-        sizer_params.Add(label_sugg,       (iy,2), (1,1), wx.LEFT, 15)
+        sizer_params.Add(self.label_sugg,       (iy,2), (1,1), wx.LEFT, 15)
         iy += 1
         sizer_params.Add(label_nfunc,      (iy,0), (1,1), wx.LEFT, 15)
@@ -274,5 +295,28 @@
 
         boxsizer2.Add(sizer_params, 0)
+        
         vbox.Add(boxsizer2)
+
+        # ----- Q range -----
+        qbox = wx.StaticBox(self, -1, "Q range")
+        qboxsizer = wx.StaticBoxSizer(qbox, wx.VERTICAL)
+        qboxsizer.SetMinSize((320,20))
+        
+        sizer_q = wx.GridBagSizer(5,5)
+
+        label_qmin = wx.StaticText(self, -1, "Q min")
+        label_qmax = wx.StaticText(self, -1, "Q max")
+        self.qmin_ctl = wx.TextCtrl(self, -1, size=(60,20))
+        self.qmax_ctl = wx.TextCtrl(self, -1, size=(60,20))
+        
+        iy = 0
+        sizer_q.Add(label_qmin, (iy,0), (1,1), wx.LEFT|wx.EXPAND, 15)
+        sizer_q.Add(self.qmin_ctl, (iy,1), (1,1), wx.LEFT|wx.EXPAND, 10)
+        sizer_q.Add(label_qmax, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 15)
+        sizer_q.Add(self.qmax_ctl, (iy,3), (1,1), wx.LEFT|wx.EXPAND, 10)
+        qboxsizer.Add(sizer_q, wx.TOP, 15)
+        vbox.Add(qboxsizer)
+        
+        
 
         # ----- Results -----
@@ -334,4 +378,22 @@
         self.SetSizer(vbox)
         
+
+        
+    def _on_accept_alpha(self, evt):
+        """
+            User has accepted the estimated alpha, 
+            set it as part of the input parameters
+        """
+        try:
+            alpha = self.alpha_estimate_ctl.GetLabel()
+            tmp = float(alpha)
+            self.alpha_ctl.SetValue(alpha)
+        except:
+            # No estimate or bad estimate, either do nothing
+            import sys
+            print "InversionControl._on_accept_alpha: %s" % sys.exc_value
+            pass
+        
+        
     def _on_pars_changed(self, evt):
         """
@@ -340,5 +402,5 @@
             scenes. 
         """
-        flag, alpha, dmax, nfunc = self._read_pars()
+        flag, alpha, dmax, nfunc, qmin, qmax = self._read_pars()
         
         # If the pars are valid, estimate alpha
@@ -347,12 +409,14 @@
                 dataset = self.plot_data.GetValue()
                 self.manager.estimate_plot_inversion(alpha=alpha, nfunc=nfunc, 
-                                                     d_max=dmax)
+                                                     d_max=dmax,
+                                                     q_min=qmin, q_max=qmax)
             else:
                 path = self.data_file.GetValue()
                 self.manager.estimate_file_inversion(alpha=alpha, nfunc=nfunc, 
-                                                     d_max=dmax, path=path)
-        
-        
-    def _read_pars(self):    
+                                                     d_max=dmax, path=path,
+                                                     q_min=qmin, q_max=qmax)
+        
+        
+    def _read_pars(self, evt=None):    
         alpha = 0
         nfunc = 5
@@ -391,5 +455,33 @@
             self.nfunc_ctl.Refresh()
         
-        return flag, alpha, dmax, nfunc
+        # Read qmin
+        try:
+            qmin_str = self.qmin_ctl.GetValue()
+            if len(qmin_str.lstrip().rstrip())==0:
+                qmin = None
+            else:
+                qmin = float(qmin_str)
+                self.qmin_ctl.SetBackgroundColour(wx.WHITE)
+                self.qmin_ctl.Refresh()
+        except:
+            flag = False
+            self.qmin_ctl.SetBackgroundColour("pink")
+            self.qmin_ctl.Refresh()
+        
+        # Read qmax
+        try:
+            qmax_str = self.qmax_ctl.GetValue()
+            if len(qmax_str.lstrip().rstrip())==0:
+                qmax = None
+            else:
+                qmax = float(qmax_str)
+                self.qmax_ctl.SetBackgroundColour(wx.WHITE)
+                self.qmax_ctl.Refresh()
+        except:
+            flag = False
+            self.qmax_ctl.SetBackgroundColour("pink")
+            self.qmax_ctl.Refresh()
+        
+        return flag, alpha, dmax, nfunc, qmin, qmax
     
     def _on_invert(self, evt):
@@ -401,5 +493,5 @@
         # Push it to the manager
         
-        flag, alpha, dmax, nfunc = self._read_pars()
+        flag, alpha, dmax, nfunc, qmin, qmax = self._read_pars()
         
         if flag:
@@ -407,9 +499,12 @@
                 dataset = self.plot_data.GetValue()
                 self.manager.setup_plot_inversion(alpha=alpha, nfunc=nfunc, 
-                                                  d_max=dmax)
+                                                  d_max=dmax,
+                                                  q_min=qmin, q_max=qmax)
             else:
                 path = self.data_file.GetValue()
                 self.manager.setup_file_inversion(alpha=alpha, nfunc=nfunc, 
-                                                  d_max=dmax, path=path)
+                                                  d_max=dmax, path=path,
+                                                  q_min=qmin, q_max=qmax
+                                                  )
                 
         else:
Index: prview/perspectives/pr/pr.py
===================================================================
--- prview/perspectives/pr/pr.py	(revision 32dffae4e1afdd03ed92e8646e5c3335bb00a7fb)
+++ prview/perspectives/pr/pr.py	(revision 634f1cf6c63e6c8c347746c746ab4dc929ec8540)
@@ -29,4 +29,6 @@
         self.nfunc      = 10
         self.max_length = 140.0
+        self.q_min      = None
+        self.q_max      = None
         ## Remember last plottable processed
         self.last_data  = "sphere_60_q0_2.txt"
@@ -158,5 +160,13 @@
                 maxq=q_i
                 
-        x = pylab.arange(0.001, maxq, maxq/301.0)
+        minq = 0.001
+        
+        # Check for user min/max
+        if not pr.q_min==None:
+            minq = pr.q_min
+        if not pr.q_max==None:
+            maxq = pr.q_max
+                
+        x = pylab.arange(minq, maxq, maxq/301.0)
         y = numpy.zeros(len(x))
         err = numpy.zeros(len(x))
@@ -349,16 +359,20 @@
         #result_panel = InversionResults(self.parent, -1, style=wx.RAISED_BORDER)
         
-    def setup_plot_inversion(self, alpha, nfunc, d_max):
+    def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None):
         self.alpha = alpha
         self.nfunc = nfunc
         self.max_length = d_max
+        self.q_min = q_min
+        self.q_max = q_max
         
         self._create_plot_pr()
         self.perform_inversion()
 
-    def estimate_plot_inversion(self, alpha, nfunc, d_max):
+    def estimate_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None):
         self.alpha = alpha
         self.nfunc = nfunc
         self.max_length = d_max
+        self.q_min = q_min
+        self.q_max = q_max
         
         self._create_plot_pr()
@@ -375,4 +389,6 @@
         pr.d_max = self.max_length
         pr.alpha = self.alpha
+        pr.q_min = self.q_min
+        pr.q_max = self.q_max
         pr.x = self.current_plottable.x
         pr.y = self.current_plottable.y
@@ -391,8 +407,10 @@
 
           
-    def setup_file_inversion(self, alpha, nfunc, d_max, path):
+    def setup_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None):
         self.alpha = alpha
         self.nfunc = nfunc
         self.max_length = d_max
+        self.q_min = q_min
+        self.q_max = q_max
         
         self._create_file_pr(path)
@@ -400,8 +418,10 @@
         self.perform_inversion()
           
-    def estimate_file_inversion(self, alpha, nfunc, d_max, path):
+    def estimate_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None):
         self.alpha = alpha
         self.nfunc = nfunc
         self.max_length = d_max
+        self.q_min = q_min
+        self.q_max = q_max
         
         if self._create_file_pr(path):
@@ -422,4 +442,6 @@
             pr.d_max = self.max_length
             pr.alpha = self.alpha
+            pr.q_min = self.q_min
+            pr.q_max = self.q_max
             pr.x = x
             pr.y = y
Index: prview/perspectives/pr/pr_thread.py
===================================================================
--- prview/perspectives/pr/pr_thread.py	(revision 32dffae4e1afdd03ed92e8646e5c3335bb00a7fb)
+++ prview/perspectives/pr/pr_thread.py	(revision 634f1cf6c63e6c8c347746c746ab4dc929ec8540)
@@ -78,68 +78,10 @@
         
     def compute(self):
-        import time
+        """
+            Calculates the estimate
+        """
         try:            
-            self.starttime = time.time()
-            # If the current alpha is zero, try
-            # another value
-            if self.pr.alpha<=0:
-                self.pr.alpha = 0.0001
-                 
-            # Perform inversion to find the largest alpha
-            out, cov = self.pr.lstsq(self.nfunc)
-            elapsed = time.time()-self.starttime
-            initial_alpha = self.pr.alpha
-            initial_peaks = self.pr.get_peaks(out)
-
-            # Try the inversion with the estimated alpha
-            self.pr.alpha = self.pr.suggested_alpha
-            out, cov = self.pr.lstsq(self.nfunc)
-
-            npeaks = self.pr.get_peaks(out)
-            # if more than one peak to start with
-            # just return the estimate
-            if npeaks>1:
-                message = "Your P(r) is not smooth, please check your inversion parameters"
-                self.complete(alpha=self.pr.suggested_alpha, message=message, elapsed=elapsed)
-            else:
-                
-                # Look at smaller values
-                # We assume that for the suggested alpha, we have 1 peak
-                # if not, send a message to change parameters
-                alpha = self.pr.suggested_alpha
-                best_alpha = self.pr.suggested_alpha
-                found = False
-                for i in range(10):
-                    self.pr.alpha = (0.33)**(i+1)*alpha
-                    out, cov = self.pr.lstsq(self.nfunc)
-                    #osc = self.pr.oscillations(out) 
-                    #print self.pr.alpha, osc
-                    
-                    peaks = self.pr.get_peaks(out)
-                    print self.pr.alpha, peaks
-                    if peaks>1:
-                        found = True
-                        break
-                    best_alpha = self.pr.alpha
-                    
-                # If we didn't find a turning point for alpha and
-                # the initial alpha already had only one peak,
-                # just return that
-                if not found and initial_peaks==1 and initial_alpha<best_alpha:
-                    best_alpha = initial_alpha
-                    
-                # Check whether the size makes sense
-                message=None
-                
-                if not found:
-                    message = "None"
-                elif best_alpha>=0.5*self.pr.suggested_alpha:
-                    # best alpha is too big, return a 
-                    # reasonable value
-                    message  = "The estimated alpha for your system is too large. "
-                    message += "Try increasing your maximum distance."
-                
-                self.complete(alpha=best_alpha, message=None, elapsed=elapsed)
-
+            alpha, message, elapsed = self.pr.estimate_alpha(self.nfunc)
+            self.complete(alpha=alpha, message=message, elapsed=elapsed)
         except:
             if not self.error_func==None:
Index: prview/perspectives/pr/requirements.txt
===================================================================
--- prview/perspectives/pr/requirements.txt	(revision 32dffae4e1afdd03ed92e8646e5c3335bb00a7fb)
+++ prview/perspectives/pr/requirements.txt	(revision 634f1cf6c63e6c8c347746c746ab4dc929ec8540)
@@ -1,6 +1,6 @@
 1. Thread
 2. Find good defaults. Automate the inversion.
-   -How do we estimate d_max?
-   -How do we estimate alpha?
+   -How do we estimate d_max? Guinier fit?
+   -How do we estimate alpha? [partially done]
    Compute the residuals once and choose a value that brings the reg term up to 
    a fraction of the residuals.
@@ -9,5 +9,5 @@
 5. Create handshake so that a plug-in can set context menu items to its own panels...
 6. Return figure of merit values and suggest the values for d_max and alpha.
-7. Show time estimate
+7. Show time estimate [done]
 8. Plot the reg term alone to see what it looks like
 9. Use data loader perspective/plug-in to load data/choose file
@@ -15,5 +15,5 @@
 11. Define limits of applicability
 12. Return figures of merit
-13. Errors on output constants
+13. Errors on output constants [done]
 14. Clean up the InversionDialog
 15. Add online help for inputs and outputs (especially figures of merit)
