Changeset 2927 for branch


Ignore:
Timestamp:
Jul 11, 2017 4:29:11 PM (6 years ago)
Author:
vondreele
Message:

set up a local version of basinhopping.py in MCSA routine
implement frame position saving - NB: doesn't check if frame outside screen!
fix display of image controls after calibrate/recalibrate, etc.
occupancy --> site fraction in Afrac display
replace a bunch of TextCtrls? with ValidatedTxtCtrls? in phaseGUI

Location:
branch/2frame
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branch/2frame/GSASIIdataGUI.py

    r2920 r2927  
    465465            help='Exit from GSAS-II', id=wx.ID_ANY,
    466466            kind=wx.ITEM_NORMAL,text='&Exit')
    467         self.Bind(wx.EVT_MENU, self.OnFileExit, id=item.GetId())
     467        self.Bind(wx.EVT_MENU, self.ExitMain, id=item.GetId())
    468468       
    469469    def _Add_DataMenuItems(self,parent):
     
    28172817        wx.Frame.__init__(self, name='GSASII', parent=parent,
    28182818            size=wx.Size(700, 450),style=wx.DEFAULT_FRAME_STYLE, title='GSAS-II main window')
    2819             # BHT DEBUG
    2820             #size=wx.Size(400, 450),style=wx.DEFAULT_FRAME_STYLE, title='GSAS-II main window')
    2821         clientSize = wx.ClientDisplayRect()
    2822         Size = self.GetSize()
    2823         xPos = clientSize[2]-Size[0]
    2824         self.SetPosition(wx.Point(xPos,clientSize[1]))
    28252819        self._init_Imports()
    28262820        #initialize Menu item objects (these contain lists of menu items that are enabled or disabled)
     
    28352829        self.ExportCIF = []
    28362830        #
    2837         # Main menu now done in DataWindow._initMenus for consistency
    2838         #self.GSASIIMenu = wx.MenuBar()
    2839         #self.dataMenuBars = [self.GSASIIMenu] # list of all menus (added to in PrefillDataMenu)
    2840         #self.FillMainMenu(self.GSASIIMenu)
    2841         #self.SetMenuBar(self.GSASIIMenu)
    28422831        self.MacroStatusList = []  # logging
    28432832        self.Status = self.CreateStatusBar()
     
    28632852        self.GPXtree = G2G.G2TreeCtrl(id=G2G.wxID_GPXTREE,
    28642853            parent=self.treePanel, size=self.treePanel.GetClientSize(),style=wx.TR_DEFAULT_STYLE )
    2865 #        self.treeTitle = wx.StaticText(self.treePanel, wx.ID_ANY, "GSAS-II project: ",
    2866 #                                       )
    2867 #        self.treeTitle.SetBackgroundColour(wx.Colour(230,230,150)) # add some yellow to the title
    2868 #        treeSizer.Add(self.treeTitle,0,wx.EXPAND|wx.ALL,0)
    28692854        treeSizer.Add(self.GPXtree,1,wx.EXPAND|wx.ALL,0)
    28702855        self.GPXtree.Bind(wx.EVT_TREE_SEL_CHANGED,self.OnDataTreeSelChanged)
     
    28852870
    28862871        self.dataWindow.SetupScrolling()
    2887        
    2888         plotFrame = wx.Frame(None,-1,'GSASII Plots',size=wx.Size(700,600), \
     2872               
     2873        self.plotFrame = wx.Frame(None,-1,'GSASII Plots',size=wx.Size(700,600), \
    28892874            style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX)
    2890         self.G2plotNB = G2plt.G2PlotNoteBook(plotFrame,G2frame=self)
    2891         plotFrame.Show()
     2875        self.G2plotNB = G2plt.G2PlotNoteBook(self.plotFrame,G2frame=self)
     2876        self.plotFrame.Show()
     2877       
     2878        main_pos = eval(GSASIIpath.GetConfigValue('Main_Pos'))
     2879        self.SetPosition(main_pos)
     2880#        if not self.IsShownOnScreen():
     2881#            self.Centre()
     2882        plot_pos = eval(GSASIIpath.GetConfigValue('Plot_Pos'))
     2883        self.plotFrame.SetPosition(plot_pos)
     2884#        if not self.plotFrame.IsShownOnScreen():
     2885#            self.plotFrame.Centre()
    28922886       
    28932887    def __init__(self, parent):
     
    29942988                print('Ignoring Config Starting_directory value: '+
    29952989                      GSASIIpath.GetConfigValue('Starting_directory'))
     2990               
    29962991
    29972992    def GetTreeItemsList(self,item):
     
    37703765        File/Open Project menu button
    37713766        '''
    3772         result = wx.ID_OK
    3773         self.EnablePlot = False
    3774         if self.GPXtree.GetChildrenCount(self.root,False):
     3767        def SaveOld():
    37753768            if self.dataWindow:
    3776                 self.dataWindow.ClearData() 
     3769                self.dataWindow.ClearData()
    37773770            dlg = wx.MessageDialog(
    37783771                self,
     
    37833776                result = dlg.ShowModal()
    37843777                if result == wx.ID_OK:
     3778                    dlg.Destroy()
    37853779                    self.GPXtree.DeleteChildren(self.root)
    37863780                    self.GSASprojectfile = ''
     
    37893783                        self.G2plotNB.clear()
    37903784            finally:
    3791                 dlg.Destroy()
    3792         if result != wx.ID_OK: return
    3793 
    3794         if not filename:
     3785                pass
     3786            return result
     3787       
     3788        def GetGPX():
    37953789            if self.LastGPXdir:
    37963790                pth = self.LastGPXdir
     
    38063800            finally:
    38073801                dlg.Destroy()
     3802           
     3803        self.EnablePlot = False
     3804        result = wx.ID_OK
     3805        if self.GPXtree.GetChildrenCount(self.root,False):
     3806            result = SaveOld()
     3807        if result != wx.ID_OK: return
     3808
     3809        if not filename:
     3810            GetGPX()
    38083811        else:
    38093812            self.GSASprojectfile = os.path.splitext(filename)[0]+'.gpx'
     
    39653968    def ExitMain(self, event):
    39663969        '''Called if the main window is closed'''
     3970        FramePos = {'Main_Pos':tuple(self.GetPosition()),'Plot_Pos':tuple(self.plotFrame.GetPosition())}
     3971        GSASIIpath.SetConfigValue(FramePos)
     3972        print FramePos
     3973        config = G2G.GetConfigValsDocs()
     3974        G2G.SaveConfigVars(config)
    39673975        if self.G2plotNB:
    39683976            self.G2plotNB.Destroy()
     
    39713979        sys.exit()
    39723980       
    3973     def OnFileExit(self, event):
    3974         '''Called in response to the File/Quit menu button'''
    3975         if self.G2plotNB:
    3976             self.G2plotNB.Destroy()
    3977         self.Close()
    3978        
     3981#    def OnFileExit(self, event):
     3982#        '''Called in response to the File/Quit menu button'''
     3983#        if self.G2plotNB:
     3984#            self.G2plotNB.Destroy()
     3985#        self.Close()
     3986#       
    39793987    def OnExportPeakList(self,event):
    39803988        nptand = lambda x: np.tan(x*math.pi/180.)
  • branch/2frame/GSASIIimgGUI.py

    r2917 r2927  
    12251225    mainSizer.Add((5,5),0)
    12261226    mainSizer.Add(GonioSizer(),0,WACV)   
     1227    G2frame.dataWindow.SetDataSize()
    12271228   
    12281229################################################################################
     
    17141715        littleSizer.Add(frameDelete,0,WACV)
    17151716        mainSizer.Add(littleSizer,0,)
    1716     G2frame.SetDataSize()
     1717    G2frame.dataWindow.SetDataSize()
    17171718    if startScroll: # reset scroll to saved position
    17181719        G2frame.dataWindow.Scroll(0,startScroll) # set to saved scroll position
     
    21522153    mainSizer.Add((5,10),0)
    21532154    mainSizer.Add(DzeroSizer())
     2155    G2frame.dataWindow.SetDataSize()
    21542156   
    21552157###########################################################################
  • branch/2frame/GSASIImath.py

    r2871 r2927  
    43194319    '''
    43204320   
     4321    class RandomDisplacementBounds(object):
     4322        """random displacement with bounds"""
     4323        def __init__(self, xmin, xmax, stepsize=0.5):
     4324            self.xmin = xmin
     4325            self.xmax = xmax
     4326            self.stepsize = stepsize
     4327   
     4328        def __call__(self, x):
     4329            """take a random step but ensure the new position is within the bounds"""
     4330            while True:
     4331                # this could be done in a much more clever way, but it will work for example purposes
     4332                steps = self.xmax-self.xmin
     4333                xnew = x + np.random.uniform(-self.stepsize*steps, self.stepsize*steps, np.shape(x))
     4334                if np.all(xnew < self.xmax) and np.all(xnew > self.xmin):
     4335                    break
     4336            return xnew
     4337   
    43214338    global tsum
    43224339    tsum = 0.
     
    45134530        puts result F^2 in each ref[5] in refList
    45144531        returns:
    4515             delt-F*rcov*delt-F/sum(Fo^2)^2
    4516         '''       
     4532            delt-F*rcov*delt-F/sum(Fo^2)
     4533        '''   
     4534           
    45174535        global tsum
    45184536        t0 = time.time()
     
    45354553        tsum += (time.time()-t0)
    45364554        return M/np.sum(refList[4]**2)
     4555   
     4556    def MCSAcallback(x, f, fmin,accept):
     4557        return not pgbar.Update(min(100.,fmin*1000),
     4558            newmsg='%s%8.4f%s'%('MC/SA Residual:',fmin*1000,'%'))[0]
     4559           
    45374560
    45384561    sq8ln2 = np.sqrt(8*np.log(2))
     
    46694692    ifInv = SGData['SGInv']
    46704693    # consider replacing anneal with scipy.optimize.basinhopping
    4671     results = anneal(mcsaCalc,x0,args=(refs,rcov,cosTable,ifInv,allFF,RBdata,varyList,parmDict),
    4672         schedule=MCSA['Algorithm'], full_output=True,
    4673         T0=MCSA['Annealing'][0], Tf=MCSA['Annealing'][1],dwell=MCSA['Annealing'][2],
    4674         boltzmann=MCSA['boltzmann'], learn_rate=0.5, 
    4675         quench=MCSA['fast parms'][0], m=MCSA['fast parms'][1], n=MCSA['fast parms'][2],
    4676         lower=lower, upper=upper, slope=MCSA['log slope'],ranStart=MCSA.get('ranStart',False),
    4677         ranRange=MCSA.get('ranRange',0.10),autoRan=MCSA.get('autoRan',False),dlg=pgbar)
    4678     mcsaCalc(results[0],refs,rcov,cosTable,ifInv,allFF,RBdata,varyList,parmDict)
     4694    if MCSA['Algorithm'] == 'Basin Hopping':
     4695        import basinhopping as bs
     4696        bounds = np.array(zip(lower,upper))
     4697        take_step = RandomDisplacementBounds(np.array(lower), np.array(upper))
     4698        results = bs.basinhopping(mcsaCalc,x0,take_step=take_step,disp=True,T=MCSA['Annealing'][0],stepsize=0.1,
     4699                interval=20,niter=MCSA['Annealing'][2],minimizer_kwargs={'method':'L-BFGS-B','bounds':bounds,
     4700                'args':(refs,rcov,cosTable,ifInv,allFF,RBdata,varyList,parmDict)},callback=MCSAcallback)
     4701        mcsaCalc(results['x'],refs,rcov,cosTable,ifInv,allFF,RBdata,varyList,parmDict)
     4702        Result = [False,False,results['fun'],0.0,]+list(results['x'])
     4703    else:
     4704        results = anneal(mcsaCalc,x0,args=(refs,rcov,cosTable,ifInv,allFF,RBdata,varyList,parmDict),
     4705            schedule=MCSA['Algorithm'], full_output=True,
     4706            T0=MCSA['Annealing'][0], Tf=MCSA['Annealing'][1],dwell=MCSA['Annealing'][2],
     4707            boltzmann=MCSA['boltzmann'], learn_rate=0.5, 
     4708            quench=MCSA['fast parms'][0], m=MCSA['fast parms'][1], n=MCSA['fast parms'][2],
     4709            lower=lower, upper=upper, slope=MCSA['log slope'],ranStart=MCSA.get('ranStart',False),
     4710            ranRange=MCSA.get('ranRange',10.)/100.,autoRan=MCSA.get('autoRan',False),dlg=pgbar)
     4711        mcsaCalc(results[0],refs,rcov,cosTable,ifInv,allFF,RBdata,varyList,parmDict)
     4712        Result = [False,False,results[1],results[2],]+list(results[0])
    46794713#    for ref in refs.T:
    46804714#        print ' %4d %4d %4d %10.3f %10.3f %10.3f'%(int(ref[0]),int(ref[1]),int(ref[2]),ref[4],ref[5],ref[6])
    46814715#    print np.sqrt((np.sum(refs[6]**2)/np.sum(refs[4]**2)))
    4682     Result = [False,False,results[1],results[2],]+list(results[0])
    46834716    Result.append(varyList)
    46844717    return Result,tsum
  • branch/2frame/GSASIIobj.py

    r2911 r2927  
    14061406        'AUiso':'Atomic isotropic displacement parameter',
    14071407        'AU([123][123])':'Atomic anisotropic displacement parameter U\\1',
    1408         'Afrac': 'Atomic occupancy parameter',
     1408        'Afrac': 'Atomic site fraction parameter',
    14091409        'Amul': 'Atomic site multiplicity value',
    14101410        'AM([xyz])$' : 'Atomic magnetic moment parameter, \\1',
  • branch/2frame/GSASIIpath.py

    r2924 r2927  
    4747        if var in configDict:
    4848            del configDict[var]
    49         if parmdict[var][1] is None: continue
    50         if parmdict[var][1] == '': continue
    51         if parmdict[var][0] == parmdict[var][1]: continue
    52         configDict[var] = parmdict[var][1]
     49        if isinstance(parmdict[var],tuple):
     50            configDict[var] = parmdict[var]
     51        else:
     52            if parmdict[var][1] is None: continue
     53            if parmdict[var][1] == '': continue
     54            if parmdict[var][0] == parmdict[var][1]: continue
     55            configDict[var] = parmdict[var][1]
    5356
    5457# routines for looking a version numbers in files
  • branch/2frame/GSASIIphsGUI.py

    r2917 r2927  
    17311731                text[3] = ' The magnetic lattice point group is '+SGData['MagPtGp']
    17321732                SGMagSpinBox(General,msg,text,table,OprNames,SpnFlp).Show()
    1733                
    1734             def OnDminVal(event):
    1735                 event.Skip()
    1736                 try:
    1737                     val = float(dminVal.GetValue())
    1738                     if val > 0.7:
    1739                         generalData['MagDmin'] = val
    1740                 except ValueError:
    1741                     pass
    1742                 dminVal.SetValue("%.4f"%(generalData['MagDmin']))
    1743                
     1733                               
    17441734            SGData = generalData['SGData']           
    17451735            Indx = {}
     
    17721762            dminSizer = wx.BoxSizer(wx.HORIZONTAL)
    17731763            dminSizer.Add(wx.StaticText(General,label=' Magnetic reflection d-min: '),0,WACV)
    1774 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    1775             dminVal = wx.TextCtrl(General,value='%.4f'%(generalData['MagDmin']),style=wx.TE_PROCESS_ENTER)
    1776             dminVal.Bind(wx.EVT_TEXT_ENTER,OnDminVal)       
    1777             dminVal.Bind(wx.EVT_KILL_FOCUS,OnDminVal)
     1764            dminVal = G2G.ValidatedTxtCtrl(General,generalData,'MagDmin',nDig=(10,4),min=0.7)
    17781765            dminSizer.Add(dminVal,0,WACV)
    17791766            magSizer.Add(dminSizer,0,WACV)
     
    18241811                    wx.MessageBox(Text,caption=msg,style=Style)
    18251812                wx.CallAfter(UpdateGeneral)               
    1826            
    1827             def OnVec(event):
    1828                 event.Skip()
    1829                 Obj = event.GetEventObject()
    1830                 ind = Indx[Obj.GetId()]
    1831                 val = Obj.GetValue()
    1832                 try:
    1833                     val = min(2.0,max(-1.0,float(val)))
    1834                 except ValueError:
    1835                     val = generalData['SuperVec'][0][ind]
    1836                 generalData['SuperVec'][0][ind] = val
    1837                 Obj.SetValue('%.4f'%(generalData['SuperVec'][0][ind]))
    1838                
     1813                           
    18391814            def OnVecRef(event):
    18401815                generalData['SuperVec'][1] = Ref.GetValue()
     
    18711846            for i,[val,show] in enumerate(zip(generalData['SuperVec'][0],ifShow)):
    18721847                if show:
    1873 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    1874                     modVal = wx.TextCtrl(General,value=('%.4f'%(val)),
    1875                         size=wx.Size(50,20),style=wx.TE_PROCESS_ENTER)
    1876                     modVal.Bind(wx.EVT_TEXT_ENTER,OnVec)       
    1877                     modVal.Bind(wx.EVT_KILL_FOCUS,OnVec)
     1848                    modVal = G2G.ValidatedTxtCtrl(General,generalData['SuperVec'][0],i,nDig=(10,4),min=-1.,max=2.)
    18781849                    vecSizer.Add(modVal,0,WACV)
    18791850                    Indx[modVal.GetId()] = i
     
    19151886                wx.CallAfter(UpdateGeneral,General.GetScrollPos(wx.VERTICAL))               
    19161887               
    1917             def OnResVal(event):
    1918                 event.Skip()
    1919                 try:
    1920                     res = float(mapRes.GetValue())
    1921                     if 0.25 <= res <= 20.:
    1922                         Map['Resolution'] = res
    1923                 except ValueError:
    1924                     pass
    1925                 mapRes.SetValue("%.2f"%(Map['Resolution']))          #reset in case of error
    1926            
    19271888            def OnCutOff(event):
    19281889                event.Skip()
     
    19611922            line2Sizer = wx.BoxSizer(wx.HORIZONTAL)
    19621923            line2Sizer.Add(wx.StaticText(General,label=' Resolution: '),0,WACV)
    1963 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    1964             mapRes =  wx.TextCtrl(General,value='%.2f'%(Map['Resolution']),style=wx.TE_PROCESS_ENTER)
    1965             mapRes.Bind(wx.EVT_TEXT_ENTER,OnResVal)       
    1966             mapRes.Bind(wx.EVT_KILL_FOCUS,OnResVal)
     1924            mapRes = G2G.ValidatedTxtCtrl(General,Map,'Resolution',nDig=(10,2),min=0.25,max=20.)
    19671925            line2Sizer.Add(mapRes,0,WACV)
    19681926            line2Sizer.Add(wx.StaticText(General,label=' Peak cutoff %: '),0,WACV)
     
    20001958                    normElem.SetLabel(Flip['Norm element'])
    20011959                PE.Destroy()               
    2002                
    2003             def OnResVal(event):
    2004                 event.Skip()
    2005                 try:
    2006                     res = float(flipRes.GetValue())
    2007                     if 0.25 <= res <= 20.:
    2008                         Flip['Resolution'] = res
    2009                 except ValueError:
    2010                     pass
    2011                 flipRes.SetValue("%.2f"%(Flip['Resolution']))          #reset in case of error
    2012            
    2013             def OnkFactor(event):
    2014                 event.Skip()
    2015                 try:
    2016                     res = float(kFactor.GetValue())
    2017                     if 0.1 <= res <= 1.2:
    2018                         Flip['k-factor'] = res
    2019                 except ValueError:
    2020                     pass
    2021                 kFactor.SetValue("%.3f"%(Flip['k-factor']))          #reset in case of error
    2022            
    2023             def OnkMax(event):
    2024                 event.Skip()
    2025                 try:
    2026                     res = float(kMax.GetValue())
    2027                     if res >= 10.:
    2028                         Flip['k-Max'] = res
    2029                 except ValueError:
    2030                     pass
    2031                 kMax.SetValue("%.1f"%(Flip['k-Max']))          #reset in case of error
    2032                
     1960                                       
    20331961            def OnTestHKL(event):
    20341962                event.Skip()
     
    20621990            line2Sizer = wx.BoxSizer(wx.HORIZONTAL)
    20631991            line2Sizer.Add(wx.StaticText(General,label=' Resolution: '),0,WACV)
    2064 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    2065             flipRes =  wx.TextCtrl(General,value='%.2f'%(Flip['Resolution']),style=wx.TE_PROCESS_ENTER)
    2066             flipRes.Bind(wx.EVT_TEXT_ENTER,OnResVal)       
    2067             flipRes.Bind(wx.EVT_KILL_FOCUS,OnResVal)
     1992            flipRes = G2G.ValidatedTxtCtrl(General,Flip,'Resolution',nDig=(10,2),min=0.25,max=2.)
    20681993            line2Sizer.Add(flipRes,0,WACV)
    20691994            line2Sizer.Add(wx.StaticText(General,label=' k-Factor (0.1-1.2): '),0,WACV)
    2070 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    2071             kFactor =  wx.TextCtrl(General,value='%.3f'%(Flip['k-factor']),style=wx.TE_PROCESS_ENTER)
    2072             kFactor.Bind(wx.EVT_TEXT_ENTER,OnkFactor)       
    2073             kFactor.Bind(wx.EVT_KILL_FOCUS,OnkFactor)
     1995            kFactor = G2G.ValidatedTxtCtrl(General,Flip,'k-factor',nDig=(10,3),min=0.1,max=1.2)
    20741996            line2Sizer.Add(kFactor,0,WACV)
    20751997            line2Sizer.Add(wx.StaticText(General,label=' k-Max (>=10.0): '),0,WACV)
    2076 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    2077             kMax = wx.TextCtrl(General,value='%.1f'%(Flip['k-Max']),style=wx.TE_PROCESS_ENTER)
    2078             kMax.Bind(wx.EVT_TEXT_ENTER,OnkMax)       
    2079             kMax.Bind(wx.EVT_KILL_FOCUS,OnkMax)
     1998            kMax = G2G.ValidatedTxtCtrl(General,Flip,'k-Max',nDig=(10,1),min=10.)
    20801999            line2Sizer.Add(kMax,0,WACV)
    20812000            flipSizer.Add(line2Sizer,0,WACV)
     
    20992018                MCSAdata['Data source'] = refList.GetValue()
    21002019           
    2101             def OnDmin(event):
    2102                 event.Skip()
    2103                 try:
    2104                     val = float(dmin.GetValue())
    2105                     if 1.0 <= val < 5.0:
    2106                         MCSAdata['dmin'] = val
    2107                 except ValueError:
    2108                     pass
    2109                 dmin.SetValue("%.3f"%(MCSAdata['dmin']))          #reset in case of error
    2110                 MCSAdata['newDmin'] = True
    2111 
    21122020            def OnCycles(event):
    21132021                MCSAdata['Cycles'] = int(cycles.GetValue())
     
    21172025                wx.CallAfter(UpdateGeneral,General.GetScrollPos(wx.VERTICAL))
    21182026               
    2119             def OnSlope(event):
    2120                 event.Skip()
    2121                 try:
    2122                     val = float(slope.GetValue())
    2123                     if .25 <= val < 1.0:
    2124                         MCSAdata['log slope'] = val
    2125                 except ValueError:
    2126                     pass
    2127                 slope.SetValue("%.3f"%(MCSAdata['log slope']))          #reset in case of error               
    2128            
    2129             def OnAjump(event):
    2130                 event.Skip()
    2131                 Obj = event.GetEventObject()
    2132                 name,ind = Indx[Obj.GetId()]
    2133                 try:
    2134                     val = float(Obj.GetValue())
    2135                     if .0 <= val <= 1.0:
    2136                         MCSAdata[name][ind] = val
    2137                 except ValueError:
    2138                     pass
    2139                 Obj.SetValue("%.3f"%(MCSAdata[name][ind]))
    2140                
    21412027            def OnRanStart(event):
    21422028                MCSAdata['ranStart'] = ranStart.GetValue()
     
    21452031#                MCSAdata['autoRan'] = autoRan.GetValue()
    21462032               
    2147             def OnRanRange(event):
    2148                 event.Skip()
    2149                 try:
    2150                     val = float(ranRange.GetValue())/100
    2151                     if 0.01 <= val <= 0.99:
    2152                         MCSAdata['ranRange'] = val
    2153                 except ValueError:
    2154                     pass
    2155                 ranRange.SetValue('%.1f'%(MCSAdata['ranRange']*100.))
    2156            
    21572033            def OnAnneal(event):
    21582034                event.Skip()
     
    21902066            lineSizer.Add(refList,0,WACV)
    21912067            lineSizer.Add(wx.StaticText(General,label=' d-min: '),0,WACV)
    2192 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    2193             dmin = wx.TextCtrl(General,-1,value='%.3f'%(MCSAdata['dmin']),style=wx.TE_PROCESS_ENTER)
    2194             dmin.Bind(wx.EVT_TEXT_ENTER,OnDmin)       
    2195             dmin.Bind(wx.EVT_KILL_FOCUS,OnDmin)
     2068            dmin = G2G.ValidatedTxtCtrl(General,MCSAdata,'dmin',nDig=(10,3),min=1.,max=5.)
    21962069            lineSizer.Add(dmin,0,WACV)
    21972070            mcsaSizer.Add(lineSizer)
     
    22092082            ranStart.SetValue(MCSAdata.get('ranStart',False))
    22102083            line2Sizer.Add(ranStart,0,WACV)
    2211 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    2212             ranRange = wx.TextCtrl(General,-1,value='%.1f'%(MCSAdata.get('ranRange',0.10)*100),style=wx.TE_PROCESS_ENTER)
    2213             ranRange.Bind(wx.EVT_TEXT_ENTER,OnRanRange)       
    2214             ranRange.Bind(wx.EVT_KILL_FOCUS,OnRanRange)
     2084            MCSAdata['ranRange'] = MCSAdata.get('ranRange',10.)  #patch for old gpx files
     2085            ranRange = G2G.ValidatedTxtCtrl(General,MCSAdata,'ranRange',nDig=(10,1),min=1.,max=99.)
    22152086            line2Sizer.Add(ranRange,0,WACV)
    22162087            line2Sizer.Add(wx.StaticText(General,label='% of ranges. '),0,WACV)
     
    22222093            mcsaSizer.Add((5,5),)
    22232094            line3Sizer = wx.BoxSizer(wx.HORIZONTAL)
    2224             Achoice = ['log','fast']                #these work
     2095            Achoice = ['log','fast','Basin Hopping']                #these work
    22252096#            Achoice = ['log','fast','cauchy','boltzmann']
    22262097            line3Sizer.Add(wx.StaticText(General,label=' MC/SA schedule: '),0,WACV)
     
    22392110                for i,name in enumerate(Names):
    22402111                    line3Sizer.Add(wx.StaticText(General,label=name),0,WACV)
    2241 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    2242                     Ajump =  wx.TextCtrl(General,-1,value='%.3f'%(MCSAdata[parms][i]),style=wx.TE_PROCESS_ENTER)
    2243                     Ajump.Bind(wx.EVT_TEXT_ENTER,OnAjump)       
    2244                     Ajump.Bind(wx.EVT_KILL_FOCUS,OnAjump)
    2245                     Indx[Ajump.GetId()] = [parms,i]
     2112                    Ajump = G2G.ValidatedTxtCtrl(General,MCSAdata[parms],i,nDig=(10,2),min=0.,max=1.)
    22462113                    line3Sizer.Add(Ajump,0,WACV)
    22472114            elif 'log' in MCSAdata['Algorithm']:
    22482115                line3Sizer.Add(wx.StaticText(General,label=' slope: '),0,WACV)
    2249 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    2250                 slope =  wx.TextCtrl(General,-1,value='%.3f'%(MCSAdata['log slope']),style=wx.TE_PROCESS_ENTER)
    2251                 slope.Bind(wx.EVT_TEXT_ENTER,OnSlope)       
    2252                 slope.Bind(wx.EVT_KILL_FOCUS,OnSlope)
     2116                slope = G2G.ValidatedTxtCtrl(General,MCSAdata,'log slope',nDig=(10,3),min=0.25,max=1.0)
    22532117                line3Sizer.Add(slope,0,WACV)
     2118            elif 'Basin Hopping' in MCSAdata['Algorithm']:
     2119                pass        #TODO basinhopping controls here
    22542120            mcsaSizer.Add(line3Sizer)
    22552121            mcsaSizer.Add((5,5),)
     
    37663632            wx.CallAfter(UpdateLayerData)
    37673633       
    3768         def OnToler(event): #used when Laue = unknown
    3769             event.Skip()
    3770             try:
    3771                 val = float(toler.GetValue())
    3772             except ValueError:
    3773                 val = Layers['Toler']
    3774             Layers['Toler'] = val
    3775             toler.SetValue('%.3f'%(Layers['Toler']))
    3776            
    37773634        def OnSadpPlot(event):
    37783635            sadpPlot.SetValue(False)
     
    38683725        def WidthSizer():
    38693726           
    3870             def OnWidthChange(event):
    3871                 event.Skip()
    3872                 Obj = event.GetEventObject()
    3873                 id = Indx[Obj]
    3874                 try:
    3875                     Layers['Width'][0][id] = max(0.005,min(1.0,float(Obj.GetValue())))
    3876                 except ValueError:
    3877                     pass
    3878                 Obj.SetValue('%.3f'%(Layers['Width'][0][id]))
    3879                
    38803727            def OnRefWidth(event):
    38813728                id = Indx[event.GetEventObject()]
     
    38833730           
    38843731            Labels = ['a','b']
    3885             widths = Layers['Width'][0]
    38863732            flags = Layers['Width'][1]
    38873733            widthSizer = wx.BoxSizer(wx.HORIZONTAL)
    38883734            for i in range(2):
    38893735                widthSizer.Add(wx.StaticText(layerData,label=u' layer width(%s) (<= 1\xb5m): '%(Labels[i])),0,WACV)
    3890 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    3891                 widthVal = wx.TextCtrl(layerData,value='%.3f'%(widths[i]),style=wx.TE_PROCESS_ENTER)
    3892                 widthVal.Bind(wx.EVT_TEXT_ENTER,OnWidthChange)       
    3893                 widthVal.Bind(wx.EVT_KILL_FOCUS,OnWidthChange)
    3894                 Indx[widthVal] = i
     3736                widthVal = G2G.ValidatedTxtCtrl(layerData,Layers['Width'][0],i,nDig=(10,3),min=0.005,max=1.0)
    38953737                widthSizer.Add(widthVal,0,WACV)
    38963738                widthRef = wx.CheckBox(layerData,label='Refine?')
     
    42744116            if Layers['Stacking'][0] == 'recursive':
    42754117                topLine.Add(wx.StaticText(layerData,label=' number of layers (<1022 or "infinite"): '),0,WACV)
    4276 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
     4118#        numLayers = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    42774119                numLayers = wx.TextCtrl(layerData,value=data['Layers']['Stacking'][1],style=wx.TE_PROCESS_ENTER)
    42784120                numLayers.Bind(wx.EVT_TEXT_ENTER,OnNumLayers)       
     
    43404182        if Layers['Laue'] == 'unknown':
    43414183            laueSizer.Add(wx.StaticText(layerData,label=' Diffraction symmetry tolerance: '),0,WACV)
    4342 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    4343             toler = wx.TextCtrl(layerData,value='%.3f'%(Layers['Toler']),style=wx.TE_PROCESS_ENTER)
    4344             toler.Bind(wx.EVT_TEXT_ENTER,OnToler)       
    4345             toler.Bind(wx.EVT_KILL_FOCUS,OnToler)
     4184            toler = G2G.ValidatedTxtCtrl(layerData,Layers,'Toler',nDig=(10,3))
    43464185            laueSizer.Add(toler,0,WACV)
    43474186        topSizer.Add(laueSizer,0,WACV)
     
    57095548                G2plt.PlotStructure(G2frame,data)
    57105549               
    5711             def OnZstep(event):
    5712                 event.Skip()
    5713                 try:
    5714                     step = float(Zstep.GetValue())
    5715                     if not (0.01 <= step <= 1.0):
    5716                         raise ValueError
    5717                 except ValueError:
    5718                     step = drawingData['Zstep']
    5719                 drawingData['Zstep'] = step
    5720                 Zstep.SetValue('%.2fA'%(drawingData['Zstep']))
    5721                
    57225550            def OnMoveZ(event):
    57235551                move = MoveZ.GetValue()*drawingData['Zstep']
     
    57885616            ZstepSizer = wx.BoxSizer(wx.HORIZONTAL)
    57895617            ZstepSizer.Add(wx.StaticText(drawOptions,-1,' Z step:'),0,WACV)
    5790 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    5791             Zstep = wx.TextCtrl(drawOptions,value='%.2f'%(drawingData['Zstep']),
    5792                 style=wx.TE_PROCESS_ENTER)
    5793             Zstep.Bind(wx.EVT_TEXT_ENTER,OnZstep)
    5794             Zstep.Bind(wx.EVT_KILL_FOCUS,OnZstep)
     5618            Zstep = G2G.ValidatedTxtCtrl(drawOptions,drawingData,'Zstep',nDig=(10,2),min=0.01,max=1.0)
    57955619            ZstepSizer.Add(Zstep,0,WACV)
    57965620            slideSizer.Add(ZstepSizer)
     
    63166140                wx.CallLater(100,UpdateTexture)
    63176141               
    6318             def OnshToler(event):
    6319                 event.Skip()
    6320                 try:
    6321                     value = float(shToler.GetValue())
    6322                     Penalty[1] = value
    6323                 except ValueError:
    6324                     pass
    6325                 shToler.SetValue('%.2f'%(Penalty[1]))
    6326            
    63276142            A = G2lat.cell2A(generalData['Cell'][1:7])
    63286143            hkls = G2lat.GenPfHKLs(10,SGData,A)   
     
    63356150            shPenalty.Add(hklList,0,WACV)
    63366151            shPenalty.Add(wx.StaticText(Texture,wx.ID_ANY,' Zero MRD tolerance: '),0,WACV)
    6337 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    6338             shToler = wx.TextCtrl(Texture,wx.ID_ANY,'%.2f'%(Penalty[1]),style=wx.TE_PROCESS_ENTER)
    6339             shToler.Bind(wx.EVT_TEXT_ENTER,OnshToler)
    6340             shToler.Bind(wx.EVT_KILL_FOCUS,OnshToler)
     6152            shToler = G2G.ValidatedTxtCtrl(Texture,Penalty,1,nDig=(10,2),min=0.001)
    63416153            shPenalty.Add(shToler,0,WACV)
    63426154            return shPenalty   
     
    78737685                POData['Coef'][1] = poRef.GetValue()
    78747686               
    7875             def OnPOVal(event):
    7876                 event.Skip()
    7877                 try:
    7878                     mdVal = float(poVal.GetValue())
    7879                     if mdVal > 0:
    7880                         POData['Coef'][0] = mdVal
    7881                 except ValueError:
    7882                     pass
    7883                 poVal.SetValue("%.3f"%(POData['Coef'][0]))
    7884                
    78857687            def OnPORange(event):
    78867688                event.Skip()
     
    79157717            poRef.Bind(wx.EVT_CHECKBOX,OnPORef)
    79167718            poSizer.Add(poRef,0,WACV)
    7917 #        azmthOff = G2G.ValidatedTxtCtrl(G2frame.phaseDisplay,data,'azmthOff',nDig=(10,2),typeHint=float,OnLeave=OnAzmthOff)
    7918             poVal = wx.TextCtrl(G2frame.MCSA,-1,'%.3f'%(POData['Coef'][0]),style=wx.TE_PROCESS_ENTER)
    7919             poVal.Bind(wx.EVT_TEXT_ENTER,OnPOVal)
    7920             poVal.Bind(wx.EVT_KILL_FOCUS,OnPOVal)
     7719            poVal = G2G.ValidatedTxtCtrl(G2frame.MCSA,POData['Coef'],0,nDig=(10,3),min=0.)
    79217720            poSizer.Add(poVal,0,WACV)
    79227721            poSizer.Add(wx.StaticText(G2frame.MCSA,-1,' Range: '),0,WACV)
  • branch/2frame/GSASIIstrMath.py

    r2895 r2927  
    32413241    if hfx+'Back;0' in varylist: # for now assume that Back;x vars to not appear in constraints
    32423242        bBpos = varylist.index(hfx+'Back;0')
    3243         dMdv[bBpos:bBpos+len(dMdb)] += dMdb
     3243        dMdv[bBpos:bBpos+len(dMdb)] += dMdb     #TODO crash if bck parms tossed
    32443244    names = [hfx+'DebyeA',hfx+'DebyeR',hfx+'DebyeU']
    32453245    for name in varylist:
  • branch/2frame/basinhopping.py

    r2895 r2927  
    350350        used, for example, to forcefully escape from a local minimum that
    351351        ``basinhopping`` is trapped in.
    352     callback : callable, ``callback(x, f, accept)``, optional
     352    callback : callable, ``callback(x, f, fmin, accept)``, optional
    353353        A callback function which will be called for all minimum found.  ``x``
    354354        and ``f`` are the coordinates and function value of the trial minima,
    355         and ``accept`` is whether or not that minima was accepted.  This can be
    356         used, for example, to save the lowest N minima found.  Also,
     355        and ``accept`` is whether or not that minima was accepted.  'fmin' is the lowest f found.
     356        This can be used, for example, to save the lowest N minima found.  Also,
    357357        ``callback`` can be used to specify a user defined stop criterion by
    358358        optionally returning True to stop the ``basinhopping`` routine.
     
    614614        if isinstance(callback, collections.Callable):
    615615            # should we pass a copy of x?
    616             val = callback(bh.xtrial, bh.energy_trial, bh.accept)
     616            val = callback(bh.xtrial, bh.energy_trial, bh.storage.get_lowest()[1], bh.accept)
    617617            if val is not None:
    618618                if val:
  • branch/2frame/config_example.py

    r2863 r2927  
    133133'''
    134134
     135Main_Pos = (100,100)
     136'''Main window location - will be updated & saved when user moves
     137it. If position is outside screen then it will be repositioned to default
     138'''
     139Plot_Pos = (200,200)
     140'''Plot window location - will be updated & saved when user moves it
     141these widows. If position is outside screen then it will be repositioned to default
     142'''
     143
    135144Tick_length = 8.0
    136145'''Specifies the length of phase tick marks in pixels. Default is 8.'''
Note: See TracChangeset for help on using the changeset viewer.