Changeset 453


Ignore:
Timestamp:
Jan 19, 2012 4:56:20 PM (10 years ago)
Author:
vondreele
Message:

refactor GSASIIgrid
new Hessian based least squares
new GSASIImath.py
work on focus issues

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r451 r453  
    246246        self.PatternTree.Bind(wx.EVT_TREE_DELETE_ITEM,
    247247            self.OnPatternTreeItemDelete, id=wxID_PATTERNTREE)
     248        self.PatternTree.Bind(wx.EVT_TREE_KEY_DOWN,
     249            self.OnPatternTreeKeyDown, id=wxID_PATTERNTREE)
    248250        self.root = self.PatternTree.AddRoot('Loaded Data: ')
    249251       
     
    259261        self.Bind(wx.EVT_CLOSE, self.ExitMain)
    260262        # various defaults
     263        self.oldFocus = None
    261264        self.GSASprojectfile = ''
    262265        self.dirname = ''
     
    333336    def OnPatternTreeItemActivated(self, event):
    334337        event.Skip()
     338       
     339    def OnPatternTreeKeyDown(self,event):
     340        key = event.GetKeyCode()
     341        item = self.PickId
     342        if key == wx.WXK_UP:
     343            self.oldFocus = self.mainPanel
     344            next = self.PatternTree.GetPrevSibling(item)
     345        elif key == wx.WXK_DOWN:
     346            self.oldFocus = self.mainPanel
     347            self.PatternTree.SelectItem(item)
    335348               
    336349    def OnPwdrRead(self, event):
  • trunk/GSASIIgrid.py

    r449 r453  
    3838[ wxID_ATOMSEDITADD, wxID_ATOMSEDITINSERT, wxID_ATOMSEDITDELETE, wxID_ATOMSREFINE,
    3939    wxID_ATOMSMODIFY, wxID_ATOMSTRANSFORM, wxID_ATOMSTESTADD, wxID_ATONTESTINSERT,
    40     wxID_RELOADDRAWATOMS,
    41 ] = [wx.NewId() for _init_coll_Atom_Items in range(9)]
     40    wxID_RELOADDRAWATOMS,wxID_ATOMSDISAGL,
     41] = [wx.NewId() for _init_coll_Atom_Items in range(10)]
    4242
    4343[ wxID_PWDRADD, wxID_HKLFADD, wxID_DATADELETE,
     
    224224
    225225class DataFrame(wx.Frame):
    226     #def _init_coll_BlankMenu(self,parent):
    227     #    parent.Append(menu=self.Blank,title='')
    228                
    229     def _init_coll_ConstraintMenu(self,parent):
    230         parent.Append(menu=self.ConstraintEdit, title='Edit')
    231         parent.Append(menu=MyHelp(self,helpType='Constraints'),title='&Help')
    232        
    233     def _init_coll_RestraintMenu(self,parent):
    234         parent.Append(menu=self.RestraintEdit, title='Edit')
    235         parent.Append(menu=MyHelp(self,helpType='Restraints'),title='&Help')
    236        
    237     def _init_coll_DataMenu(self,parent):
    238         parent.Append(menu=self.DataEdit, title='Edit')
    239         parent.Append(menu=MyHelp(self,helpType='Data'),title='&Help')
    240        
    241     def _init_coll_PawleyMenu(self,parent):
    242         parent.Append(menu=self.PawleyEdit,title='Operations')
    243         parent.Append(menu=MyHelp(self,helpType='Pawley'),title='&Help')
    244      
    245     def _init_coll_IndPeaksMenu(self,parent):
    246         parent.Append(menu=self.IndPeaksEdit,title='Operations')
    247         parent.Append(menu=MyHelp(self,helpType='Index Peaks'),title='&Help')
    248                    
    249     def _init_coll_ImageMenu(self,parent):
    250         parent.Append(menu=self.ImageEdit, title='Operations')
    251         parent.Append(menu=MyHelp(self,helpType='Images'),title='&Help')
    252        
    253     def _init_coll_BackMenu(self,parent):
    254         parent.Append(menu=self.BackEdit, title='File')
    255         parent.Append(menu=MyHelp(self,helpType='Background'),title='&Help')
    256        
    257     def _init_coll_LimitMenu(self,parent):
    258         parent.Append(menu=self.LimitEdit, title='File')
    259         parent.Append(menu=MyHelp(self,helpType='Limits'),title='&Help')
    260        
    261     def _init_coll_InstMenu(self,parent):
    262         parent.Append(menu=self.InstEdit, title='Operations')
    263         parent.Append(menu=MyHelp(self,helpType='Instrument Parameters'),title='&Help')
    264        
    265     def _init_coll_MaskMenu(self,parent):
    266         parent.Append(menu=self.MaskEdit, title='Operations')
    267         parent.Append(menu=MyHelp(self,helpType='Image Masks'),title='&Help')
    268        
    269     def _init_coll_SampleMenu(self,parent):
    270         parent.Append(menu=self.SampleEdit, title='File')
    271         parent.Append(menu=MyHelp(self,helpType='Sample Parameters'),title='&Help')
    272        
    273     def _init_coll_PeakMenu(self,parent):
    274         parent.Append(menu=self.PeakEdit, title='Peak Fitting')
    275         parent.Append(menu=MyHelp(self,helpType='Powder Peaks'),title='&Help')
    276 
    277     def _init_coll_IndexMenu(self,parent):
    278         parent.Append(menu=self.IndexEdit, title='Cell Index/Refine')
    279         parent.Append(menu=MyHelp(self,helpType='Cell Indexing Refine'),title='&Help')
    280        
    281     def _init_coll_ReflMenu(self,parent):
    282         parent.Append(menu=self.ReflEdit, title='Reflection List')
    283         parent.Append(menu=MyHelp(self,helpType='Reflection List'),title='&Help')
    284 
    285     def _init_coll_TextureMenu(self,parent):
    286         parent.Append(menu=self.TextureEdit, title='Texture')
    287         parent.Append(menu=MyHelp(self,helpType='Texture'),title='&Help')
    288 
    289     def _init_coll_PDFMenu(self,parent):
    290         parent.Append(menu=self.PDFEdit, title='PDF Controls')
    291         parent.Append(menu=MyHelp(self,helpType='PDF Controls'),title='&Help')
    292            
    293     def _init_coll_Constraint_Items(self,parent):
    294         parent.Append(id=wxID_HOLDADD, kind=wx.ITEM_NORMAL,text='Add hold',
     226
     227    def _init_menus(self):
     228       
     229# define all GSAS-II menus       
     230       
     231        self.BlankMenu = wx.MenuBar()
     232       
     233# Controls
     234        self.ControlsMenu = wx.MenuBar()
     235        self.ControlsMenu.Append(menu=MyHelp(self,helpType='Controls'),title='&Help')
     236       
     237# Notebook
     238        self.DataNotebookMenu = wx.MenuBar()
     239        self.DataNotebookMenu.Append(menu=MyHelp(self,helpType='Notebook'),title='&Help')
     240       
     241# Comments
     242        self.DataCommentsMenu = wx.MenuBar()
     243        self.DataCommentsMenu.Append(menu=MyHelp(self,helpType='Comments'),title='&Help')
     244       
     245# Constraints
     246        self.ConstraintMenu = wx.MenuBar()
     247        self.ConstraintEdit = wx.Menu(title='')
     248        self.ConstraintMenu.Append(menu=self.ConstraintEdit, title='Edit')
     249        self.ConstraintMenu.Append(menu=MyHelp(self,helpType='Constraints'),title='&Help')
     250        self.ConstraintEdit.Append(id=wxID_HOLDADD, kind=wx.ITEM_NORMAL,text='Add hold',
    295251            help='Add hold on a parameter value')
    296         parent.Append(id=wxID_EQUIVADD, kind=wx.ITEM_NORMAL,text='Add equivalence',
     252        self.ConstraintEdit.Append(id=wxID_EQUIVADD, kind=wx.ITEM_NORMAL,text='Add equivalence',
    297253            help='Add equivalence between parameter values')
    298         parent.Append(id=wxID_CONSTRAINTADD, kind=wx.ITEM_NORMAL,text='Add constraint',
     254        self.ConstraintEdit.Append(id=wxID_CONSTRAINTADD, kind=wx.ITEM_NORMAL,text='Add constraint',
    299255            help='Add constraint on parameter values')
    300         parent.Append(id=wxID_FUNCTADD, kind=wx.ITEM_NORMAL,text='Add function',
     256        self.ConstraintEdit.Append(id=wxID_FUNCTADD, kind=wx.ITEM_NORMAL,text='Add function',
    301257            help='Add function of parameter values')
    302        
    303     def _init_coll_Restraint_Items(self,parent):
    304         parent.Append(id=wxID_RESTRAINTADD, kind=wx.ITEM_NORMAL,text='Add restraint',
     258           
     259# Restraints
     260        self.RestraintMenu = wx.MenuBar()
     261        self.RestraintEdit = wx.Menu(title='')
     262        self.RestraintMenu.Append(menu=self.RestraintEdit, title='Edit')
     263        self.RestraintMenu.Append(menu=MyHelp(self,helpType='Restraints'),title='&Help')
     264        self.RestraintEdit.Append(id=wxID_RESTRAINTADD, kind=wx.ITEM_NORMAL,text='Add restraint',
    305265            help='restraint dummy menu item')
    306                    
    307     def _init_coll_Sample_Items(self,parent):
    308         parent.Append(id=wxID_SAMPLECOPY, kind=wx.ITEM_NORMAL,text='Copy',
     266           
     267# PDR / Limits
     268        self.LimitMenu = wx.MenuBar()
     269        self.LimitEdit = wx.Menu(title='')
     270        self.LimitMenu.Append(menu=self.LimitEdit, title='File')
     271        self.LimitMenu.Append(menu=MyHelp(self,helpType='Limits'),title='&Help')
     272        self.LimitEdit.Append(id=wxID_LIMITCOPY, kind=wx.ITEM_NORMAL,text='Copy',
     273            help='Copy limits to other histograms')
     274           
     275# PDR / Background
     276        self.BackMenu = wx.MenuBar()
     277        self.BackEdit = wx.Menu(title='')
     278        self.BackMenu.Append(menu=self.BackEdit, title='File')
     279        self.BackMenu.Append(menu=MyHelp(self,helpType='Background'),title='&Help')
     280        self.BackEdit.Append(id=wxID_BACKCOPY, kind=wx.ITEM_NORMAL,text='Copy',
     281            help='Copy background parameters to other histograms')
     282           
     283# PDR / Instrument Parameters
     284        self.InstMenu = wx.MenuBar()
     285        self.InstEdit = wx.Menu(title='')
     286        self.InstMenu.Append(menu=self.InstEdit, title='Operations')
     287        self.InstMenu.Append(menu=MyHelp(self,helpType='Instrument Parameters'),title='&Help')
     288        self.InstEdit.Append(help='Reset instrument profile parameters to default',
     289            id=wxID_INSTPRMRESET, kind=wx.ITEM_NORMAL,text='Reset profile')
     290        self.InstEdit.Append(help='Copy instrument profile parameters to other histograms',
     291            id=wxID_INSTCOPY, kind=wx.ITEM_NORMAL,text='Copy')
     292        self.InstEdit.Append(help='Change radiation type (Ka12 - synch)',
     293            id=wxID_CHANGEWAVETYPE, kind=wx.ITEM_NORMAL,text='Change radiation')
     294       
     295# PDR / Sample Parameters
     296        self.SampleMenu = wx.MenuBar()
     297        self.SampleEdit = wx.Menu(title='')
     298        self.SampleMenu.Append(menu=self.SampleEdit, title='File')
     299        self.SampleMenu.Append(menu=MyHelp(self,helpType='Sample Parameters'),title='&Help')
     300        self.SampleEdit.Append(id=wxID_SAMPLECOPY, kind=wx.ITEM_NORMAL,text='Copy',
    309301            help='Copy refinable sample parameters to other histograms')
    310                    
    311     def _init_coll_Back_Items(self,parent):
    312         parent.Append(id=wxID_BACKCOPY, kind=wx.ITEM_NORMAL,text='Copy',
    313             help='Copy background parameters to other histograms')
    314                    
    315     def _init_coll_Limit_Items(self,parent):
    316         parent.Append(id=wxID_LIMITCOPY, kind=wx.ITEM_NORMAL,text='Copy',
    317             help='Copy limits to other histograms')
    318                    
    319     def _init_coll_Data_Items(self,parent):
    320         parent.Append(id=wxID_PWDRADD, kind=wx.ITEM_NORMAL,text='Add powder histograms',
    321             help='Select new powder histograms to be used for this phase')
    322         parent.Append(id=wxID_HKLFADD, kind=wx.ITEM_NORMAL,text='Add single crystal histograms',
    323             help='Select new single crystal histograms to be used for this phase')
    324         parent.Append(id=wxID_DATADELETE, kind=wx.ITEM_NORMAL,text='Delete histograms',
    325             help='Delete histograms from use for this phase')
    326 
    327     def _init_coll_Texture_Items(self,parent):
    328         self.RefineTexture = parent.Append(id=wxID_REFINETEXTURE, kind=wx.ITEM_NORMAL,text='Refine texture',
    329             help='Refine the texture coefficients from sequential Pawley results')
    330         self.ClearTexture = parent.Append(id=wxID_CLEARTEXTURE, kind=wx.ITEM_NORMAL,text='Clear texture',
    331             help='Clear the texture coefficients' )
    332            
    333     def _init_coll_Pawley_Items(self,parent):
    334         parent.Append(id=wxID_PAWLEYLOAD, kind=wx.ITEM_NORMAL,text='Pawley create',
    335             help='Initialize Pawley reflection list')
    336 #        parent.Append(id=wxID_PAWLEYIMPORT, kind=wx.ITEM_NORMAL,text='Pawley import',
    337 #            help='Import Pawley reflection list')
    338         parent.Append(id=wxID_PAWLEYESTIMATE, kind=wx.ITEM_NORMAL,text='Pawley estimate',
    339             help='Estimate initial Pawley intensities')
    340         parent.Append(id=wxID_PAWLEYDELETE, kind=wx.ITEM_NORMAL,text='Pawley delete',
    341             help='Delete Pawley reflection list')
    342 
    343     def _init_coll_IndPeaks_Items(self,parent):
    344         parent.Append(help='Load/Reload index peaks from peak list',id=wxID_INDXRELOAD,
    345             kind=wx.ITEM_NORMAL,text='Load/Reload')
    346            
    347     def _init_coll_Refl_Items(self,parent):
    348         self.SelectPhase = parent.Append(help='Select phase for reflection list',id=wxID_SELECTPHASE,
    349             kind=wx.ITEM_NORMAL,text='Select phase')
    350            
    351     def _init_coll_Image_Items(self,parent):
    352         parent.Append(help='Calibrate detector by fitting to calibrant lines',
    353             id=wxID_IMCALIBRATE, kind=wx.ITEM_NORMAL,text='Calibrate')
    354         parent.Append(help='Recalibrate detector by fitting to calibrant lines',
    355             id=wxID_IMRECALIBRATE, kind=wx.ITEM_NORMAL,text='Realibrate')
    356         parent.Append(help='Clear calibration data points and rings',id=wxID_IMCLEARCALIB,
    357             kind=wx.ITEM_NORMAL,text='Clear calibration')
    358         parent.Append(help='Integrate selected image',id=wxID_IMINTEGRATE,
    359             kind=wx.ITEM_NORMAL,text='Integrate')
    360         parent.Append(help='Integrate all images selected from list',id=wxID_INTEGRATEALL,
    361             kind=wx.ITEM_NORMAL,text='Integrate all')
    362         parent.Append(help='Copy image controls to other images',
    363             id=wxID_IMCOPYCONTROLS, kind=wx.ITEM_NORMAL,text='Copy Controls')
    364         parent.Append(help='Save image controls to file',
    365             id=wxID_IMSAVECONTROLS, kind=wx.ITEM_NORMAL,text='Save Controls')
    366         parent.Append(help='Load image controls from file',
    367             id=wxID_IMLOADCONTROLS, kind=wx.ITEM_NORMAL,text='Load Controls')
    368                    
    369     def _init_coll_Mask_Items(self,parent):
    370         parent.Append(help='Copy mask to other images',
    371             id=wxID_MASKCOPY, kind=wx.ITEM_NORMAL,text='Copy mask')
    372         parent.Append(help='Save mask to file',
    373             id=wxID_MASKSAVE, kind=wx.ITEM_NORMAL,text='Save mask')
    374         parent.Append(help='Load mask from file',
    375             id=wxID_MASKLOAD, kind=wx.ITEM_NORMAL,text='Load mask')
    376 
    377     def _init_coll_Inst_Items(self,parent):
    378         parent.Append(help='Reset instrument profile parameters to default',
    379             id=wxID_INSTPRMRESET, kind=wx.ITEM_NORMAL,text='Reset profile')
    380         parent.Append(help='Copy instrument profile parameters to other histograms',
    381             id=wxID_INSTCOPY, kind=wx.ITEM_NORMAL,text='Copy')       
    382         parent.Append(help='Change radiation type (Ka12 - synch)',
    383             id=wxID_CHANGEWAVETYPE, kind=wx.ITEM_NORMAL,text='Change radiation')
    384 
    385     def _init_coll_Peak_Items(self,parent):
    386         self.UnDo = parent.Append(help='Undo last least squares refinement',
     302
     303# PDR / Peak List
     304        self.PeakMenu = wx.MenuBar()
     305        self.PeakEdit = wx.Menu(title='')
     306        self.PeakMenu.Append(menu=self.PeakEdit, title='Peak Fitting')
     307        self.PeakMenu.Append(menu=MyHelp(self,helpType='Powder Peaks'),title='&Help')
     308        self.UnDo = self.PeakEdit.Append(help='Undo last least squares refinement',
    387309            id=wxID_UNDO, kind=wx.ITEM_NORMAL,text='UnDo')
    388         self.PeakFit = parent.Append(id=wxID_LSQPEAKFIT, kind=wx.ITEM_NORMAL,text='LSQ PeakFit',
     310        self.PeakFit = self.PeakEdit.Append(id=wxID_LSQPEAKFIT, kind=wx.ITEM_NORMAL,text='LSQ PeakFit',
    389311            help='Peak fitting via least-squares' )
    390         self.PFOneCycle = parent.Append(id=wxID_LSQONECYCLE, kind=wx.ITEM_NORMAL,text='LSQ one cycle',
     312        self.PFOneCycle = self.PeakEdit.Append(id=wxID_LSQONECYCLE, kind=wx.ITEM_NORMAL,text='LSQ one cycle',
    391313            help='One cycle of Peak fitting via least-squares' )
    392         self.ResetSigGam = parent.Append(id=wxID_RESETSIGGAM, kind=wx.ITEM_NORMAL,
     314        self.PeakEdit.Append(id=wxID_RESETSIGGAM, kind=wx.ITEM_NORMAL,
    393315            text='Reset sig and gam',help='Reset sigma and gamma to global fit' )
    394         self.ClearPeaks = parent.Append(id=wxID_CLEARPEAKS, kind=wx.ITEM_NORMAL,text='Clear peaks',
     316        self.PeakEdit.Append(id=wxID_CLEARPEAKS, kind=wx.ITEM_NORMAL,text='Clear peaks',
    395317            help='Clear the peak list' )
    396            
    397     def _init_coll_Index_Items(self,parent):
    398         self.IndexPeaks = parent.Append(help='', id=wxID_INDEXPEAKS, kind=wx.ITEM_NORMAL,
    399             text='Index Cell')
    400         self.CopyCell = parent.Append( id=wxID_COPYCELL, kind=wx.ITEM_NORMAL,text='Copy Cell',
    401             help='Copy selected unit cell from indexing to cell refinement fields')
    402         self.RefineCell = parent.Append( id=wxID_REFINECELL, kind=wx.ITEM_NORMAL,
    403             text='Refine Cell',help='Refine unit cell parameters from indexed peaks')
    404         self.MakeNewPhase = parent.Append( id=wxID_MAKENEWPHASE, kind=wx.ITEM_NORMAL,
    405             text='Make new phase',help='Make new phase from selected unit cell')
    406            
    407     def _init_coll_PDF_Items(self,parent):
    408         parent.Append(help='Add element to sample composition',id=wxID_PDFADDELEMENT, kind=wx.ITEM_NORMAL,
    409             text='Add element')
    410         parent.Append(help='Delete element from sample composition',id=wxID_PDFDELELEMENT, kind=wx.ITEM_NORMAL,
    411             text='Delete element')
    412         parent.Append(help='Copy PDF controls', id=wxID_PDFCOPYCONTROLS, kind=wx.ITEM_NORMAL,
    413             text='Copy controls')
    414 #        parent.Append(help='Load PDF controls from file',id=wxID_PDFLOADCONTROLS, kind=wx.ITEM_NORMAL,
    415 #            text='Load Controls')
    416 #        parent.Append(help='Save PDF controls to file', id=wxID_PDFSAVECONTROLS, kind=wx.ITEM_NORMAL,
    417 #            text='Save controls')
    418         self.PDFCompute = parent.Append(help='Compute PDF', id=wxID_PDFCOMPUTE, kind=wx.ITEM_NORMAL,
    419             text='Compute PDF')
    420         self.PDFCompute = parent.Append(help='Compute all PDFs', id=wxID_PDFCOMPUTEALL, kind=wx.ITEM_NORMAL,
    421             text='Compute all PDFs')
    422            
    423     def _init_utils(self):
    424         self.BlankMenu = wx.MenuBar()
    425        
    426         self.ConstraintMenu = wx.MenuBar()
    427         self.RestraintMenu = wx.MenuBar()
    428         self.DataMenu = wx.MenuBar()
    429         self.TextureMenu = wx.MenuBar()
    430         self.PawleyMenu = wx.MenuBar()
    431         self.ImageMenu = wx.MenuBar()
    432         self.MaskMenu = wx.MenuBar()
    433         self.BackMenu = wx.MenuBar()
    434         self.LimitMenu = wx.MenuBar()
    435         self.InstMenu = wx.MenuBar()
    436         self.SampleMenu = wx.MenuBar()
    437         self.PeakMenu = wx.MenuBar()
    438         self.IndPeaksMenu = wx.MenuBar()
    439         self.IndexMenu = wx.MenuBar()
    440         self.ReflMenu = wx.MenuBar()
    441         self.PDFMenu = wx.MenuBar()
    442         self.ConstraintEdit = wx.Menu(title='')
    443         self.RestraintEdit = wx.Menu(title='')
    444         self.DataEdit = wx.Menu(title='')
    445         self.TextureEdit = wx.Menu(title='')
    446         self.PawleyEdit = wx.Menu(title='')
    447         self.ImageEdit = wx.Menu(title='')
    448         self.MaskEdit = wx.Menu(title='')
    449         self.BackEdit = wx.Menu(title='')
    450         self.LimitEdit = wx.Menu(title='')
    451         self.InstEdit = wx.Menu(title='')
    452         self.SampleEdit = wx.Menu(title='')
    453         self.PeakEdit = wx.Menu(title='')
    454         self.IndPeaksEdit = wx.Menu(title='')
    455         self.IndexEdit = wx.Menu(title='')
    456         self.ReflEdit = wx.Menu(title='')
    457         self.PDFEdit = wx.Menu(title='')
    458 
    459         self._init_coll_ConstraintMenu(self.ConstraintMenu)
    460         self._init_coll_Constraint_Items(self.ConstraintEdit)
    461         self._init_coll_RestraintMenu(self.RestraintMenu)
    462         self._init_coll_Restraint_Items(self.RestraintEdit)
    463         self._init_coll_DataMenu(self.DataMenu)
    464         self._init_coll_Data_Items(self.DataEdit)
    465         self._init_coll_TextureMenu(self.TextureMenu)
    466         self._init_coll_Texture_Items(self.TextureEdit)
    467         self._init_coll_PawleyMenu(self.PawleyMenu)
    468         self._init_coll_Pawley_Items(self.PawleyEdit)
    469         self._init_coll_ImageMenu(self.ImageMenu)
    470         self._init_coll_Image_Items(self.ImageEdit)
    471         self._init_coll_MaskMenu(self.MaskMenu)
    472         self._init_coll_Mask_Items(self.MaskEdit)
    473         self._init_coll_BackMenu(self.BackMenu)
    474         self._init_coll_Back_Items(self.BackEdit)
    475         self._init_coll_LimitMenu(self.LimitMenu)
    476         self._init_coll_Limit_Items(self.LimitEdit)
    477         self._init_coll_InstMenu(self.InstMenu)
    478         self._init_coll_Inst_Items(self.InstEdit)
    479         self._init_coll_SampleMenu(self.SampleMenu)
    480         self._init_coll_Sample_Items(self.SampleEdit)
    481         self._init_coll_PeakMenu(self.PeakMenu)
    482         self._init_coll_Peak_Items(self.PeakEdit)
    483         self._init_coll_IndPeaksMenu(self.IndPeaksMenu)
    484         self._init_coll_IndPeaks_Items(self.IndPeaksEdit)
    485         self._init_coll_IndexMenu(self.IndexMenu)
    486         self._init_coll_Index_Items(self.IndexEdit)
    487         self._init_coll_ReflMenu(self.ReflMenu)
    488         self._init_coll_Refl_Items(self.ReflEdit)
    489         self._init_coll_PDFMenu(self.PDFMenu)
    490         self._init_coll_PDF_Items(self.PDFEdit)
    491318        self.UnDo.Enable(False)
    492319        self.PeakFit.Enable(False)
    493320        self.PFOneCycle.Enable(False)
     321       
     322# PDR / Index Peak List
     323        self.IndPeaksMenu = wx.MenuBar()
     324        self.IndPeaksEdit = wx.Menu(title='')
     325        self.IndPeaksMenu.Append(menu=self.IndPeaksEdit,title='Operations')
     326        self.IndPeaksMenu.Append(menu=MyHelp(self,helpType='Index Peaks'),title='&Help')
     327        self.IndPeaksEdit.Append(help='Load/Reload index peaks from peak list',id=wxID_INDXRELOAD,
     328            kind=wx.ITEM_NORMAL,text='Load/Reload')
     329       
     330# PDR / Unit Cells List
     331        self.IndexMenu = wx.MenuBar()
     332        self.IndexEdit = wx.Menu(title='')
     333        self.IndexMenu.Append(menu=self.IndexEdit, title='Cell Index/Refine')
     334        self.IndexMenu.Append(menu=MyHelp(self,helpType='Cell Indexing Refine'),title='&Help')
     335        self.IndexPeaks = self.IndexEdit.Append(help='', id=wxID_INDEXPEAKS, kind=wx.ITEM_NORMAL,
     336            text='Index Cell')
     337        self.CopyCell = self.IndexEdit.Append( id=wxID_COPYCELL, kind=wx.ITEM_NORMAL,text='Copy Cell',
     338            help='Copy selected unit cell from indexing to cell refinement fields')
     339        self.RefineCell = self.IndexEdit.Append( id=wxID_REFINECELL, kind=wx.ITEM_NORMAL,
     340            text='Refine Cell',help='Refine unit cell parameters from indexed peaks')
     341        self.MakeNewPhase = self.IndexEdit.Append( id=wxID_MAKENEWPHASE, kind=wx.ITEM_NORMAL,
     342            text='Make new phase',help='Make new phase from selected unit cell')
    494343        self.IndexPeaks.Enable(False)
    495344        self.CopyCell.Enable(False)
    496345        self.RefineCell.Enable(False)
    497346        self.MakeNewPhase.Enable(False)
    498         self.RefineTexture.Enable(False)
    499         self.ClearTexture.Enable(False)             #doesn't do anything!
    500         ############################################################
    501         # refactored Menu creation
    502         ############################################################
    503         # menu for Data Editing Window / Controls
    504         self.ControlsMenu = wx.MenuBar()
    505         self.ControlsMenu.Append(menu=MyHelp(self,helpType='Controls'),title='&Help')
    506         # menu for Data Editing Window / Notebook
    507         self.DataNotebookMenu = wx.MenuBar()
    508         self.DataNotebookMenu.Append(menu=MyHelp(self,helpType='Notebook'),title='&Help')
    509         # menu for Data Editing Window / Comments
    510         self.DataCommentsMenu = wx.MenuBar()
    511         self.DataCommentsMenu.Append(menu=MyHelp(self,helpType='Comments'),title='&Help')
    512         # menu for Data Editing Window / Controls
    513         self.ControlsMenu = wx.MenuBar()
    514         self.ControlsMenu.Append(menu=MyHelp(self,helpType='Controls'),title='&Help')
    515         # menu for Data Editing Window / Phase / Atoms tab
     347       
     348# PDR / Reflection Lists
     349        self.ReflMenu = wx.MenuBar()
     350        self.ReflEdit = wx.Menu(title='')
     351        self.ReflMenu.Append(menu=self.ReflEdit, title='Reflection List')
     352        self.ReflMenu.Append(menu=MyHelp(self,helpType='Reflection List'),title='&Help')
     353        self.SelectPhase = self.ReflEdit.Append(help='Select phase for reflection list',id=wxID_SELECTPHASE,
     354            kind=wx.ITEM_NORMAL,text='Select phase')
     355       
     356# IMG / Image Controls
     357        self.ImageMenu = wx.MenuBar()
     358        self.ImageEdit = wx.Menu(title='')
     359        self.ImageMenu.Append(menu=self.ImageEdit, title='Operations')
     360        self.ImageMenu.Append(menu=MyHelp(self,helpType='Images'),title='&Help')
     361        self.ImageEdit.Append(help='Calibrate detector by fitting to calibrant lines',
     362            id=wxID_IMCALIBRATE, kind=wx.ITEM_NORMAL,text='Calibrate')
     363        self.ImageEdit.Append(help='Recalibrate detector by fitting to calibrant lines',
     364            id=wxID_IMRECALIBRATE, kind=wx.ITEM_NORMAL,text='Realibrate')
     365        self.ImageEdit.Append(help='Clear calibration data points and rings',id=wxID_IMCLEARCALIB,
     366            kind=wx.ITEM_NORMAL,text='Clear calibration')
     367        self.ImageEdit.Append(help='Integrate selected image',id=wxID_IMINTEGRATE,
     368            kind=wx.ITEM_NORMAL,text='Integrate')
     369        self.ImageEdit.Append(help='Integrate all images selected from list',id=wxID_INTEGRATEALL,
     370            kind=wx.ITEM_NORMAL,text='Integrate all')
     371        self.ImageEdit.Append(help='Copy image controls to other images',
     372            id=wxID_IMCOPYCONTROLS, kind=wx.ITEM_NORMAL,text='Copy Controls')
     373        self.ImageEdit.Append(help='Save image controls to file',
     374            id=wxID_IMSAVECONTROLS, kind=wx.ITEM_NORMAL,text='Save Controls')
     375        self.ImageEdit.Append(help='Load image controls from file',
     376            id=wxID_IMLOADCONTROLS, kind=wx.ITEM_NORMAL,text='Load Controls')
     377           
     378# IMG / Masks
     379        self.MaskMenu = wx.MenuBar()
     380        self.MaskEdit = wx.Menu(title='')
     381        self.MaskMenu.Append(menu=self.MaskEdit, title='Operations')
     382        self.MaskMenu.Append(menu=MyHelp(self,helpType='Image Masks'),title='&Help')
     383        self.MaskEdit.Append(help='Copy mask to other images',
     384            id=wxID_MASKCOPY, kind=wx.ITEM_NORMAL,text='Copy mask')
     385        self.MaskEdit.Append(help='Save mask to file',
     386            id=wxID_MASKSAVE, kind=wx.ITEM_NORMAL,text='Save mask')
     387        self.MaskEdit.Append(help='Load mask from file',
     388            id=wxID_MASKLOAD, kind=wx.ITEM_NORMAL,text='Load mask')
     389           
     390# PDF / PDF Controls
     391        self.PDFMenu = wx.MenuBar()
     392        self.PDFEdit = wx.Menu(title='')
     393        self.PDFMenu.Append(menu=self.PDFEdit, title='PDF Controls')
     394        self.PDFMenu.Append(menu=MyHelp(self,helpType='PDF Controls'),title='&Help')
     395        self.PDFEdit.Append(help='Add element to sample composition',id=wxID_PDFADDELEMENT, kind=wx.ITEM_NORMAL,
     396            text='Add element')
     397        self.PDFEdit.Append(help='Delete element from sample composition',id=wxID_PDFDELELEMENT, kind=wx.ITEM_NORMAL,
     398            text='Delete element')
     399        self.PDFEdit.Append(help='Copy PDF controls', id=wxID_PDFCOPYCONTROLS, kind=wx.ITEM_NORMAL,
     400            text='Copy controls')
     401#        self.PDFEdit.Append(help='Load PDF controls from file',id=wxID_PDFLOADCONTROLS, kind=wx.ITEM_NORMAL,
     402#            text='Load Controls')
     403#        self.PDFEdit.Append(help='Save PDF controls to file', id=wxID_PDFSAVECONTROLS, kind=wx.ITEM_NORMAL,
     404#            text='Save controls')
     405        self.PDFEdit.Append(help='Compute PDF', id=wxID_PDFCOMPUTE, kind=wx.ITEM_NORMAL,
     406            text='Compute PDF')
     407        self.PDFEdit.Append(help='Compute all PDFs', id=wxID_PDFCOMPUTEALL, kind=wx.ITEM_NORMAL,
     408            text='Compute all PDFs')
     409           
     410# Phase / General tab
     411        self.DataGeneral = wx.MenuBar()
     412        self.DataGeneral.Append(menu=MyHelp(self,helpType='General'),title='&Help')
     413       
     414# Phase / Atoms tab
    516415        self.AtomsMenu = wx.MenuBar()
    517416        self.AtomEdit = wx.Menu(title='')
     417        self.AtomCompute = wx.Menu(title='')
    518418        self.AtomsMenu.Append(menu=self.AtomEdit, title='Edit')
     419        self.AtomsMenu.Append(menu=self.AtomCompute, title='Compute')
    519420        self.AtomsMenu.Append(menu=MyHelp(self,helpType='Atoms'),title='&Help')
    520421        self.AtomEdit.Append(id=wxID_ATOMSEDITADD, kind=wx.ITEM_NORMAL,text='Append atom',
     
    536437        self.AtomEdit.Append(id=wxID_RELOADDRAWATOMS, kind=wx.ITEM_NORMAL,text='Reload draw atoms',
    537438            help='Reload atom drawing list')
    538         # menu for Data Editing Window / Phase / General tab
    539         self.DataGeneral = wx.MenuBar()
    540         self.DataGeneral.Append(menu=MyHelp(self,helpType='General'),title='&Help')
    541         # menu for Data Editing Window / Phase / Draw Options tab
     439        self.AtomCompute.Append(id=wxID_ATOMSDISAGL, kind=wx.ITEM_NORMAL,text='Distances & Angles',
     440            help='Compute distances & angles for selected atoms')   
     441                 
     442# Phase / Data tab
     443        self.DataMenu = wx.MenuBar()
     444        self.DataEdit = wx.Menu(title='')
     445        self.DataMenu.Append(menu=self.DataEdit, title='Edit')
     446        self.DataMenu.Append(menu=MyHelp(self,helpType='Data'),title='&Help')
     447        self.DataEdit.Append(id=wxID_PWDRADD, kind=wx.ITEM_NORMAL,text='Add powder histograms',
     448            help='Select new powder histograms to be used for this phase')
     449        self.DataEdit.Append(id=wxID_HKLFADD, kind=wx.ITEM_NORMAL,text='Add single crystal histograms',
     450            help='Select new single crystal histograms to be used for this phase')
     451        self.DataEdit.Append(id=wxID_DATADELETE, kind=wx.ITEM_NORMAL,text='Delete histograms',
     452            help='Delete histograms from use for this phase')
     453           
     454# Phase / Texture tab
     455        self.TextureMenu = wx.MenuBar()
     456        self.TextureEdit = wx.Menu(title='')
     457        self.TextureMenu.Append(menu=self.TextureEdit, title='Texture')
     458        self.TextureMenu.Append(menu=MyHelp(self,helpType='Texture'),title='&Help')
     459        self.TextureEdit.Append(id=wxID_REFINETEXTURE, kind=wx.ITEM_NORMAL,text='Refine texture',
     460            help='Refine the texture coefficients from sequential Pawley results')
     461        self.TextureEdit.Append(id=wxID_CLEARTEXTURE, kind=wx.ITEM_NORMAL,text='Clear texture',
     462            help='Clear the texture coefficients' )
     463           
     464# Phase / Pawley tab
     465        self.PawleyMenu = wx.MenuBar()
     466        self.PawleyEdit = wx.Menu(title='')
     467        self.PawleyMenu.Append(menu=self.PawleyEdit,title='Operations')
     468        self.PawleyMenu.Append(menu=MyHelp(self,helpType='Pawley'),title='&Help')
     469        self.PawleyEdit.Append(id=wxID_PAWLEYLOAD, kind=wx.ITEM_NORMAL,text='Pawley create',
     470            help='Initialize Pawley reflection list')
     471        self.PawleyEdit.Append(id=wxID_PAWLEYESTIMATE, kind=wx.ITEM_NORMAL,text='Pawley estimate',
     472            help='Estimate initial Pawley intensities')
     473        self.PawleyEdit.Append(id=wxID_PAWLEYDELETE, kind=wx.ITEM_NORMAL,text='Pawley delete',
     474            help='Delete Pawley reflection list')
     475#        self.PawleyEdit.Append(id=wxID_PAWLEYIMPORT, kind=wx.ITEM_NORMAL,text='Pawley import',
     476#            help='Import Pawley reflection list')
     477
     478# Phase / Draw Options tab
    542479        self.DataDrawOptions = wx.MenuBar()
    543480        self.DataDrawOptions.Append(menu=MyHelp(self,helpType='Draw Options'),title='&Help')
    544         # menu for Data Editing Window / Phase / Draw Atoms tab
     481       
     482# Phase / Draw Atoms tab
    545483        self.DrawAtomsMenu = wx.MenuBar()
    546484        self.DrawAtomEdit = wx.Menu(title='')
     
    567505        self.DrawAtomEdit.Append(id=wxID_DRAWDELETE, kind=wx.ITEM_NORMAL,text='Delete atoms',
    568506            help='Delete atoms from drawing set')
    569 
     507           
     508# end of GSAS-II menu definitions
    570509       
    571510    def _init_ctrls(self, parent,name=None,size=None,pos=None):
    572511        wx.Frame.__init__(self,parent=parent,style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX,
    573512            size=size,pos=pos,title='GSAS-II data display')
    574         self._init_utils()
     513        self._init_menus()
    575514        if name:
    576515            self.SetLabel(name)
     
    775714    if 'deriv type' not in data:
    776715        data = {}
    777         data['deriv type'] = 'analytical'
     716        data['deriv type'] = 'analytic Jacobian'
    778717        data['min dM/M'] = 0.0001
    779718        data['shift factor'] = 1.
    780719    if 'shift factor' not in data:
    781         data['shift factor'] = 1.       
     720        data['shift factor'] = 1.
     721    if 'max cyc' not in data:
     722        data['max cyc'] = 3       
    782723    #end patch
    783724    '''
     
    788729    'distMax':0.0,'angleMax':0.0,'useMapPeaks':False}
    789730    '''
    790        
    791     def SetStatusLine(text):
    792         Status.SetStatusText(text)                                     
    793        
    794     def OnConvergence(event):
    795         try:
    796             value = max(1.e-9,min(1.0,float(Cnvrg.GetValue())))
    797         except ValueError:
    798             value = 0.0001
    799         data['min dM/M'] = value
    800         Cnvrg.SetValue('%.2g'%(value))
    801        
    802     def OnDerivType(event):
    803         data['deriv type'] = derivSel.GetValue()
     731    def SeqSizer():
     732       
     733        def OnSelectData(event):
     734            choices = ['All',]+GetPatternTreeDataNames(self,['PWDR',])
     735            sel = []
     736            if 'Seq Data' in data:
     737                for item in data['Seq Data']:
     738                    sel.append(choices.index(item))
     739            names = []
     740            dlg = wx.MultiChoiceDialog(self,'Select data:','Sequential refinement',choices)
     741            dlg.SetSelections(sel)
     742            if dlg.ShowModal() == wx.ID_OK:
     743                sel = dlg.GetSelections()
     744                for i in sel: names.append(choices[i])
     745                if 'All' in names:
     746                    names = choices[1:]
     747                data['Seq Data'] = names               
     748            dlg.Destroy()
     749            reverseSel.Enable(True)
     750           
     751        def OnReverse(event):
     752            data['Reverse Seq'] = reverseSel.GetValue()
     753                   
     754        seqSizer = wx.BoxSizer(wx.HORIZONTAL)
     755        seqSizer.Add(wx.StaticText(self.dataDisplay,label=' Sequential Refinement Powder Data: '),0,wx.ALIGN_CENTER_VERTICAL)
     756        selSeqData = wx.Button(self.dataDisplay,-1,label=' Select data')
     757        selSeqData.Bind(wx.EVT_BUTTON,OnSelectData)
     758        seqSizer.Add(selSeqData,0,wx.ALIGN_CENTER_VERTICAL)
     759        seqSizer.Add((5,0),0)
     760        reverseSel = wx.CheckBox(self.dataDisplay,-1,label=' Reverse order?')
     761        reverseSel.Bind(wx.EVT_CHECKBOX,OnReverse)
     762        if 'Seq Data' not in data:
     763            reverseSel.Enable(False)
     764        if 'Reverse Seq' in data:
     765            reverseSel.SetValue(data['Reverse Seq'])
     766        seqSizer.Add(reverseSel,0,wx.ALIGN_CENTER_VERTICAL)
     767        return seqSizer
     768       
     769    def LSSizer():       
     770       
     771        def OnDerivType(event):
     772            data['deriv type'] = derivSel.GetValue()
     773            derivSel.SetValue(data['deriv type'])
     774            wx.CallAfter(UpdateControls,self,data)
     775           
     776        def OnConvergence(event):
     777            try:
     778                value = max(1.e-9,min(1.0,float(Cnvrg.GetValue())))
     779            except ValueError:
     780                value = 0.0001
     781            data['min dM/M'] = value
     782            Cnvrg.SetValue('%.2g'%(value))
     783           
     784        def OnMaxCycles(event):
     785            data['max cyc'] = int(maxCyc.GetValue())
     786            maxCyc.SetValue(str(data['max cyc']))
     787                       
     788        def OnFactor(event):
     789            try:
     790                value = min(max(float(Factr.GetValue()),0.00001),100.)
     791            except ValueError:
     792                value = 1.0
     793            data['shift factor'] = value
     794            Factr.SetValue('%.5f'%(value))
     795       
     796        LSSizer = wx.FlexGridSizer(cols=6,vgap=5,hgap=5)
     797        LSSizer.Add(wx.StaticText(self.dataDisplay,label=' Refinement derivatives: '),0,wx.ALIGN_CENTER_VERTICAL)
     798        Choice=['analytic Jacobian','numeric','analytic Hessian']
     799        derivSel = wx.ComboBox(parent=self.dataDisplay,value=data['deriv type'],choices=Choice,
     800            style=wx.CB_READONLY|wx.CB_DROPDOWN)
    804801        derivSel.SetValue(data['deriv type'])
    805        
    806     def OnFactor(event):
    807         try:
    808             value = min(max(float(Factr.GetValue()),0.00001),100.)
    809         except ValueError:
    810             value = 1.0
    811         data['shift factor'] = value
    812         Factr.SetValue('%.5f'%(value))
    813        
    814     def OnSelectData(event):
    815         choices = ['All',]+GetPatternTreeDataNames(self,['PWDR',])
    816         sel = []
    817         if 'Seq Data' in data:
    818             for item in data['Seq Data']:
    819                 sel.append(choices.index(item))
    820         names = []
    821         dlg = wx.MultiChoiceDialog(self,'Select data:','Sequential refinement',choices)
    822         dlg.SetSelections(sel)
    823         if dlg.ShowModal() == wx.ID_OK:
    824             sel = dlg.GetSelections()
    825             for i in sel: names.append(choices[i])
    826             if 'All' in names:
    827                 names = choices[1:]
    828             data['Seq Data'] = names               
    829         dlg.Destroy()
    830         reverseSel.Enable(True)
    831        
    832     def OnReverse(event):
    833         data['Reverse Seq'] = reverseSel.GetValue()
     802        derivSel.Bind(wx.EVT_COMBOBOX, OnDerivType)
     803           
     804        LSSizer.Add(derivSel,0,wx.ALIGN_CENTER_VERTICAL)
     805        LSSizer.Add(wx.StaticText(self.dataDisplay,label=' Min delta-M/M: '),0,wx.ALIGN_CENTER_VERTICAL)
     806        Cnvrg = wx.TextCtrl(self.dataDisplay,-1,value='%.2g'%(data['min dM/M']),style=wx.TE_PROCESS_ENTER)
     807        Cnvrg.Bind(wx.EVT_TEXT_ENTER,OnConvergence)
     808        Cnvrg.Bind(wx.EVT_KILL_FOCUS,OnConvergence)
     809        LSSizer.Add(Cnvrg,0,wx.ALIGN_CENTER_VERTICAL)
     810        if 'Hessian' in data['deriv type']:
     811            LSSizer.Add(wx.StaticText(self.dataDisplay,label=' Max cycles: '),0,wx.ALIGN_CENTER_VERTICAL)
     812            Choice = ['0','1','2','3','5','10','15','20']
     813            maxCyc = wx.ComboBox(parent=self.dataDisplay,value=str(data['max cyc']),choices=Choice,
     814                style=wx.CB_READONLY|wx.CB_DROPDOWN)
     815            maxCyc.SetValue(str(data['max cyc']))
     816            maxCyc.Bind(wx.EVT_COMBOBOX, OnMaxCycles)
     817            LSSizer.Add(maxCyc,0,wx.ALIGN_CENTER_VERTICAL)
     818        else:
     819            LSSizer.Add(wx.StaticText(self.dataDisplay,label=' Initial shift factor: '),0,wx.ALIGN_CENTER_VERTICAL)
     820            Factr = wx.TextCtrl(self.dataDisplay,-1,value='%.5f'%(data['shift factor']),style=wx.TE_PROCESS_ENTER)
     821            Factr.Bind(wx.EVT_TEXT_ENTER,OnFactor)
     822            Factr.Bind(wx.EVT_KILL_FOCUS,OnFactor)
     823            LSSizer.Add(Factr,0,wx.ALIGN_CENTER_VERTICAL)
     824        return LSSizer
    834825       
    835826    if self.dataDisplay:
     
    837828    if not self.dataFrame.GetStatusBar():
    838829        Status = self.dataFrame.CreateStatusBar()
    839     SetStatusLine('')
     830        Status.SetStatusText('')
    840831    self.dataFrame.SetLabel('Controls')
    841832    self.dataDisplay = wx.Panel(self.dataFrame)
     
    843834    mainSizer = wx.BoxSizer(wx.VERTICAL)
    844835    mainSizer.Add((5,5),0)
    845     mainSizer.Add(wx.StaticText(self.dataDisplay,label=' Refinement Controls:'),0,wx.ALIGN_CENTER_VERTICAL)
    846     LSSizer = wx.FlexGridSizer(cols=6,vgap=5,hgap=5)
    847     LSSizer.Add(wx.StaticText(self.dataDisplay,label=' Refinement derivatives: '),0,wx.ALIGN_CENTER_VERTICAL)
    848     Choice=['analytic','numeric']
    849     derivSel = wx.ComboBox(parent=self.dataDisplay,value=data['deriv type'],choices=Choice,
    850         style=wx.CB_READONLY|wx.CB_DROPDOWN)
    851     derivSel.SetValue(data['deriv type'])
    852     derivSel.Bind(wx.EVT_COMBOBOX, OnDerivType)   
    853     LSSizer.Add(derivSel,0,wx.ALIGN_CENTER_VERTICAL)
    854     LSSizer.Add(wx.StaticText(self.dataDisplay,label=' Min delta-M/M: '),0,wx.ALIGN_CENTER_VERTICAL)
    855     Cnvrg = wx.TextCtrl(self.dataDisplay,-1,value='%.2g'%(data['min dM/M']),style=wx.TE_PROCESS_ENTER)
    856     Cnvrg.Bind(wx.EVT_TEXT_ENTER,OnConvergence)
    857     Cnvrg.Bind(wx.EVT_KILL_FOCUS,OnConvergence)
    858     LSSizer.Add(Cnvrg,0,wx.ALIGN_CENTER_VERTICAL)
    859     LSSizer.Add(wx.StaticText(self.dataDisplay,label=' Initial shift factor: '),0,wx.ALIGN_CENTER_VERTICAL)
    860     Factr = wx.TextCtrl(self.dataDisplay,-1,value='%.5f'%(data['shift factor']),style=wx.TE_PROCESS_ENTER)
    861     Factr.Bind(wx.EVT_TEXT_ENTER,OnFactor)
    862     Factr.Bind(wx.EVT_KILL_FOCUS,OnFactor)
    863     LSSizer.Add(Factr,0,wx.ALIGN_CENTER_VERTICAL)
    864     mainSizer.Add(LSSizer)
     836    mainSizer.Add(wx.StaticText(self.dataDisplay,label=' Refinement Controls:'),0,wx.ALIGN_CENTER_VERTICAL)   
     837    mainSizer.Add(LSSizer())
    865838    mainSizer.Add((5,5),0)
    866    
    867     SeqSizer = wx.BoxSizer(wx.HORIZONTAL)
    868     SeqSizer.Add(wx.StaticText(self.dataDisplay,label=' Sequential Refinement Powder Data: '),0,wx.ALIGN_CENTER_VERTICAL)
    869     selSeqData = wx.Button(self.dataDisplay,-1,label=' Select data')
    870     selSeqData.Bind(wx.EVT_BUTTON,OnSelectData)
    871     SeqSizer.Add(selSeqData,0,wx.ALIGN_CENTER_VERTICAL)
    872     SeqSizer.Add((5,0),0)
    873     reverseSel = wx.CheckBox(self.dataDisplay,-1,label=' Reverse order?')
    874     reverseSel.Bind(wx.EVT_CHECKBOX,OnReverse)
    875     if 'Seq Data' not in data:
    876         reverseSel.Enable(False)
    877     if 'Reverse Seq' in data:
    878         reverseSel.SetValue(data['Reverse Seq'])
    879     SeqSizer.Add(reverseSel,0,wx.ALIGN_CENTER_VERTICAL)
    880    
    881    
    882     mainSizer.Add(SeqSizer)
     839    mainSizer.Add(SeqSizer())
    883840    mainSizer.Add((5,5),0)
    884841       
     
    15461503    parentID = self.root
    15471504    self.ExportPattern.Enable(False)
     1505    defWid = [250,150]
    15481506    if item != self.root:
    15491507        parentID = self.PatternTree.GetItemParent(item)
     
    15641522                data = {
    15651523                    #least squares controls
    1566                     'deriv type':'analytic','min dM/M':0.0001,'shift factor':1.0,
     1524                    'deriv type':'analytic Jacobian','min dM/M':0.0001,'shift factor':1.0,'max cyc':3,
    15671525                    #Fourier controls
    15681526                    'mapType':'Fobs','d-max':100.,'d-min':0.2,'histograms':[],
     
    15791537        elif self.PatternTree.GetItemText(item) == 'Covariance':
    15801538            data = self.PatternTree.GetItemPyData(item)
     1539            self.dataFrame.setSizePosLeft(defWid)
    15811540            wx.TextCtrl(parent=self.dataFrame,size=self.dataFrame.GetClientSize(),
    15821541                        value='See plot window for covariance display')
     
    15951554        elif 'PWDR' in self.PatternTree.GetItemText(item):
    15961555            self.ExportPattern.Enable(True)
     1556            self.dataFrame.setSizePosLeft(defWid)
    15971557            wx.TextCtrl(parent=self.dataFrame,size=self.dataFrame.GetClientSize(),
    1598                         style=wx.TE_MULTILINE,
    1599                         value='See plot window for powder data display\nor select a data item in histogram')
     1558                style=wx.TE_MULTILINE,
     1559                value='See plot window for powder data display\nor select a data item in histogram')
    16001560            G2plt.PlotPatterns(self,newPlot=True)
    16011561        elif 'HKLF' in self.PatternTree.GetItemText(item):
     
    16071567            G2plt.PlotISFG(self,type='S(Q)')
    16081568        elif self.PatternTree.GetItemText(item) == 'Phases':
     1569            self.dataFrame.setSizePosLeft(defWid)
    16091570            wx.TextCtrl(parent=self.dataFrame,size=self.dataFrame.GetClientSize(),
    1610                         value='Select one phase to see its parameters')
    1611            
     1571                value='Select one phase to see its parameters')           
    16121572    elif 'I(Q)' in self.PatternTree.GetItemText(item):
    16131573        self.PickId = item
  • trunk/GSASIIplot.py

    r450 r453  
    747747        Page.canvas.draw()
    748748    self.Pwdr = True
     749    if self.oldFocus:
     750        self.SetFocus()
    749751   
    750752def PlotISFG(self,newPlot=False,type=''):
  • trunk/GSASIIpwd.py

    r447 r453  
    12061206            dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
    12071207            try:
    1208                 if derivType == 'analytic':
    1209                     result = so.leastsq(errPeakProfile,values,Dfun=devPeakProfile,full_output=True,ftol=Ftol,col_deriv=True,
    1210                         args=(x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],parmDict,varyList,bakType,dlg))
    1211                     ncyc = int(result[2]['nfev']/2)
    1212                 else:
    1213                     result = so.leastsq(errPeakProfile,values,full_output=True,ftol=Ftol,epsfcn=1.e-8,
    1214                         args=(x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],parmDict,varyList,bakType,dlg))
    1215                     ncyc = int(result[2]['nfev']/len(varyList))
     1208                result = so.leastsq(errPeakProfile,values,Dfun=devPeakProfile,full_output=True,ftol=Ftol,col_deriv=True,
     1209                    args=(x[xBeg:xFin],y[xBeg:xFin],w[xBeg:xFin],parmDict,varyList,bakType,dlg))
     1210                ncyc = int(result[2]['nfev']/2)
    12161211            finally:
    12171212                dlg.Destroy()
  • trunk/GSASIIstruct.py

    r451 r453  
    2121import GSASIIpwd as G2pwd
    2222import GSASIImapvars as G2mv
     23import GSASIImath as G2mth
    2324import scipy.optimize as so
    2425
     
    10241025        A = G2lat.cell2A(cell)
    10251026        pId = Phases[phase]['pId']
    1026         for histogram in HistoPhase:
     1027        histoList = HistoPhase.keys()
     1028        histoList.sort()
     1029        for histogram in histoList:
    10271030            try:
    10281031                Histogram = Histograms[histogram]
     
    11231126    def PrintSizeAndSig(hapData,sizeSig):
    11241127        line = '\n Size model:     %9s'%(hapData[0])
     1128        refine = False
    11251129        if hapData[0] in ['isotropic','uniaxial']:
    11261130            line += ' equatorial:%12.3f'%(hapData[1][0])
    11271131            if sizeSig[0][0]:
    11281132                line += ', sig: %8.3f'%(sizeSig[0][0])
     1133                refine = True
    11291134            if hapData[0] == 'uniaxial':
    11301135                line += ' axial:%12.3f'%(hapData[1][1])
    11311136                if sizeSig[0][1]:
     1137                    refine = True
    11321138                    line += ', sig: %8.3f'%(sizeSig[0][1])
    1133             print line
     1139            if refine:
     1140                print line
    11341141        else:
    1135             print line
    11361142            Snames = ['S11','S22','S33','S12','S13','S23']
    11371143            ptlbls = ' name  :'
     
    11421148                ptstr += '%12.6f' % (hapData[4][i])
    11431149                if sizeSig[1][i]:
     1150                    refine = True
    11441151                    sigstr += '%12.6f' % (sizeSig[1][i])
    11451152                else:
    11461153                    sigstr += 12*' '
    1147             print ptlbls
    1148             print ptstr
    1149             print sigstr
     1154            if refine:
     1155                print line
     1156                print ptlbls
     1157                print ptstr
     1158                print sigstr
    11501159       
    11511160    def PrintMuStrainAndSig(hapData,mustrainSig,SGData):
    11521161        line = '\n Mustrain model: %9s'%(hapData[0])
     1162        refine = False
    11531163        if hapData[0] in ['isotropic','uniaxial']:
    11541164            line += ' equatorial:%12.1f'%(hapData[1][0])
    11551165            if mustrainSig[0][0]:
    11561166                line += ', sig: %8.1f'%(mustrainSig[0][0])
     1167                refine = True
    11571168            if hapData[0] == 'uniaxial':
    11581169                line += ' axial:%12.1f'%(hapData[1][1])
    11591170                if mustrainSig[0][1]:
    11601171                     line += ', sig: %8.1f'%(mustrainSig[0][1])
    1161             print line
     1172            if refine:
     1173                print line
    11621174        else:
    1163             print line
    11641175            Snames = G2spc.MustrainNames(SGData)
    11651176            ptlbls = ' name  :'
     
    11701181                ptstr += '%12.6f' % (hapData[4][i])
    11711182                if mustrainSig[1][i]:
     1183                    refine = True
    11721184                    sigstr += '%12.6f' % (mustrainSig[1][i])
    11731185                else:
    11741186                    sigstr += 12*' '
    1175             print ptlbls
    1176             print ptstr
    1177             print sigstr
     1187            if refine:
     1188                print line
     1189                print ptlbls
     1190                print ptstr
     1191                print sigstr
    11781192           
    11791193    def PrintHStrainAndSig(hapData,strainSig,SGData):
    1180         print '\n Hydrostatic/elastic strain: '
    11811194        Hsnames = G2spc.HStrainNames(SGData)
    11821195        ptlbls = ' name  :'
    11831196        ptstr =  ' value :'
    11841197        sigstr = ' sig   :'
     1198        refine = False
    11851199        for i,name in enumerate(Hsnames):
    11861200            ptlbls += '%12s' % (name)
    11871201            ptstr += '%12.6g' % (hapData[0][i])
    11881202            if name in strainSig:
     1203                refine = True
    11891204                sigstr += '%12.6g' % (strainSig[name])
    11901205            else:
    11911206                sigstr += 12*' '
    1192         print ptlbls
    1193         print ptstr
    1194         print sigstr
     1207        if refine:
     1208            print '\n Hydrostatic/elastic strain: '
     1209            print ptlbls
     1210            print ptstr
     1211            print sigstr
    11951212       
    11961213    def PrintSHPOAndSig(hapData,POsig):
     
    12141231        SGData = Phases[phase]['General']['SGData']
    12151232        pId = Phases[phase]['pId']
    1216         for histogram in HistoPhase:
     1233        histoList = HistoPhase.keys()
     1234        histoList.sort()
     1235        for histogram in histoList:
    12171236            try:
    12181237                Histogram = Histograms[histogram]
     
    14121431    histVary = []
    14131432    controlDict = {}
    1414     for histogram in Histograms:
     1433    histoList = Histograms.keys()
     1434    histoList.sort()
     1435    for histogram in histoList:
    14151436        Histogram = Histograms[histogram]
    14161437        hId = Histogram['hId']
     
    15031524        Debye = Background[1]
    15041525        lenBack = len(Back[3:])
    1505         print '\n Background function: ',Back[0]
    15061526        valstr = ' value : '
    15071527        sigstr = ' sig   : '
     1528        refine = False
    15081529        for i,back in enumerate(Back[3:]):
    15091530            valstr += '%10.4g'%(back)
    15101531            if Back[1]:
     1532                refine = True
    15111533                sigstr += '%10.4g'%(backSig[i])
    15121534            else:
    15131535                sigstr += 10*' '
    1514         print valstr
    1515         print sigstr
     1536        if refine:
     1537            print '\n Background function: ',Back[0]
     1538            print valstr
     1539            print sigstr
    15161540        if Debye['nDebye']:
    15171541            ifAny = False
     
    15331557       
    15341558    def PrintInstParmsSig(Inst,instSig):
    1535         print '\n Instrument Parameters:'
    15361559        ptlbls = ' names :'
    15371560        ptstr =  ' value :'
    15381561        sigstr = ' sig   :'
    15391562        instNames = Inst[3][1:]
     1563        refine = False
    15401564        for i,name in enumerate(instNames):
    15411565            ptlbls += '%12s' % (name)
    15421566            ptstr += '%12.6f' % (Inst[1][i+1])
    15431567            if instSig[i+1]:
     1568                refine = True
    15441569                sigstr += '%12.6f' % (instSig[i+1])
    15451570            else:
    15461571                sigstr += 12*' '
    1547         print ptlbls
    1548         print ptstr
    1549         print sigstr
     1572        if refine:
     1573            print '\n Instrument Parameters:'
     1574            print ptlbls
     1575            print ptstr
     1576            print sigstr
    15501577       
    15511578    def PrintSampleParmsSig(Sample,sampleSig):
    1552         print '\n Sample Parameters:'
    15531579        ptlbls = ' names :'
    15541580        ptstr =  ' values:'
    15551581        sigstr = ' sig   :'
     1582        refine = False
    15561583        if 'Bragg' in Sample['Type']:
    15571584            for i,item in enumerate(['Scale','Shift','Transparency']):
     
    15591586                ptstr += '%14.4f'%(Sample[item][0])
    15601587                if sampleSig[i]:
     1588                    refine = True
    15611589                    sigstr += '%14.4f'%(sampleSig[i])
    15621590                else:
     
    15681596                ptstr += '%14.4f'%(Sample[item][0])
    15691597                if sampleSig[i]:
     1598                    refine = True
    15701599                    sigstr += '%14.4f'%(sampleSig[i])
    15711600                else:
    15721601                    sigstr += 14*' '
    15731602
    1574         print ptlbls
    1575         print ptstr
    1576         print sigstr
    1577        
    1578     for histogram in Histograms:
     1603        if refine:
     1604            print '\n Sample Parameters:'
     1605            print ptlbls
     1606            print ptstr
     1607            print sigstr
     1608       
     1609    histoList = Histograms.keys()
     1610    histoList.sort()
     1611    for histogram in histoList:
    15791612        if 'PWDR' in histogram:
    15801613            Histogram = Histograms[histogram]
     
    21332166    if not FFtables:
    21342167        return
    2135     for histogram in Histograms:
     2168    histoList = Histograms.keys()
     2169    histoList.sort()
     2170    for histogram in histoList:
    21362171        if 'PWDR' in histogram[:4]:
    21372172            Histogram = Histograms[histogram]
     
    22322267   
    22332268def GetFobsSq(Histograms,Phases,parmDict,calcControls):
    2234     for histogram in Histograms:
     2269    histoList = Histograms.keys()
     2270    histoList.sort()
     2271    for histogram in histoList:
    22352272        if 'PWDR' in histogram[:4]:
    22362273            Histogram = Histograms[histogram]
     
    24832520    nvar = len(varylist)
    24842521    dMdv = np.empty(0)
    2485     for histogram in Histograms:
     2522    histoList = Histograms.keys()
     2523    histoList.sort()
     2524    for histogram in histoList:
    24862525        if 'PWDR' in histogram[:4]:
    24872526            Histogram = Histograms[histogram]
     
    25002539    return dMdv
    25012540
     2541def HessRefine(values,HistoPhases,parmdict,varylist,calcControls,pawleyLookup,dlg):
     2542    parmdict.update(zip(varylist,values))
     2543    G2mv.Dict2Map(parmdict,varylist)
     2544    Histograms,Phases = HistoPhases
     2545    nvar = len(varylist)
     2546    Hess = np.empty(0)
     2547    histoList = Histograms.keys()
     2548    histoList.sort()
     2549    for histogram in histoList:
     2550        if 'PWDR' in histogram[:4]:
     2551            Histogram = Histograms[histogram]
     2552            hId = Histogram['hId']
     2553            hfx = ':%d:'%(hId)
     2554            Limits = calcControls[hfx+'Limits']
     2555            x,y,w,yc,yb,yd = Histogram['Data']
     2556            dy = y-yc
     2557            xB = np.searchsorted(x,Limits[0])
     2558            xF = np.searchsorted(x,Limits[1])
     2559            dMdvh = np.sqrt(w[xB:xF])*getPowderProfileDerv(parmdict,x[xB:xF],
     2560                varylist,Histogram,Phases,calcControls,pawleyLookup)
     2561            if dlg:
     2562                dlg.Update(Histogram['wRp'],newmsg='Hessian for histogram %d Rwp=%8.3f%s'%(hId,Histogram['wRp'],'%'))[0]
     2563            if len(Hess):
     2564                Vec += np.sum(dMdvh*np.sqrt(w[xB:xF])*dy[xB:xF],axis=1)
     2565                Hess += np.inner(dMdvh,dMdvh)
     2566            else:
     2567                Vec = np.sum(dMdvh*np.sqrt(w[xB:xF])*dy[xB:xF],axis=1)
     2568                Hess = np.inner(dMdvh,dMdvh)
     2569    return Vec,Hess
     2570
    25022571def errRefine(values,HistoPhases,parmdict,varylist,calcControls,pawleyLookup,dlg):       
    25032572    parmdict.update(zip(varylist,values))
     
    25082577    sumwYo = 0
    25092578    Nobs = 0
    2510     for histogram in Histograms:
     2579    histoList = Histograms.keys()
     2580    histoList.sort()
     2581    for histogram in histoList:
    25112582        if 'PWDR' in histogram[:4]:
    25122583            Histogram = Histograms[histogram]
     
    25312602            wdy = -np.sqrt(w[xB:xF])*(yd[xB:xF])
    25322603            Histogram['wRp'] = min(100.,np.sqrt(np.sum(wdy**2)/Histogram['sumwYo'])*100.)
     2604            if dlg:
     2605                dlg.Update(Histogram['wRp'],newmsg='For histogram %d Rwp=%8.3f%s'%(hId,Histogram['wRp'],'%'))[0]
    25332606            M = np.concatenate((M,wdy))
    25342607    Histograms['sumwYo'] = sumwYo
     
    25842657    except:
    25852658        print ' *** ERROR - your constraints are internally inconsistent ***'
    2586         print ' *** Refine aborted ***'
    2587         raise Exception
     2659        raise Exception(' *** Refine aborted ***')
    25882660    # check to see which generated parameters are fully varied
    25892661    msg = G2mv.SetVaryFlags(varyList)
     
    25912663        print ' *** ERROR - you have not set the refine flags for constraints consistently! ***'
    25922664        print msg
    2593         print ' *** Refine aborted ***'
    2594         raise Exception       
     2665        raise Exception(' *** Refine aborted ***')
    25952666    G2mv.Map2Dict(parmDict,varyList)
    25962667#    print G2mv.VarRemapShow(varyList)
     
    26012672        Ftol = Controls['min dM/M']
    26022673        Factor = Controls['shift factor']
    2603         if Controls['deriv type'] == 'analytic':
     2674        maxCyc = Controls['max cyc']
     2675        if 'Jacobian' in Controls['deriv type']:           
    26042676            result = so.leastsq(errRefine,values,Dfun=dervRefine,full_output=True,
    26052677                ftol=Ftol,col_deriv=True,factor=Factor,
    26062678                args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    2607             ncyc = int(result[2]['nfev']/2)               
     2679            ncyc = int(result[2]['nfev']/2)
     2680        elif 'Hessian' in Controls['deriv type']:
     2681            result = G2mth.HessianLSQ(errRefine,values,Hess=HessRefine,ftol=Ftol,maxcyc=maxCyc,
     2682                args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
     2683            ncyc = result[2]['num cyc']+1                           
    26082684        else:           #'numeric'
    26092685            result = so.leastsq(errRefine,values,full_output=True,ftol=Ftol,epsfcn=1.e-8,factor=Factor,
     
    26222698        print 135*'-'
    26232699        print ' Number of function calls:',result[2]['nfev'],' Number of observations: ',Histograms['Nobs'],' Number of parameters: ',len(varyList)
    2624         print ' Refinement time = %8.3fs, %8.3fs/cycle'%(runtime,runtime/ncyc)
     2700        print ' Refinement time = %8.3fs, %8.3fs/cycle, for %d cycles'%(runtime,runtime/ncyc,ncyc)
    26252701        print ' wRp = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rwp,chisq,GOF)
    26262702        try:
     
    26342710        except TypeError:          #result[1] is None on singular matrix
    26352711            print '**** Refinement failed - singular matrix ****'
    2636             Ipvt = result[2]['ipvt']
    2637             for i,ipvt in enumerate(Ipvt):
    2638                 if not np.sum(result[2]['fjac'],axis=1)[i]:
    2639                     print 'Removing parameter: ',varyList[ipvt-1]
    2640                     del(varyList[ipvt-1])
    2641                     break
     2712            if 'Hessian' in Controls['deriv type']:
     2713                for i in result[2]['psing'].reverse():
     2714                        print 'Removing parameter: ',varyList[i]
     2715                        del(varyList[i])                   
     2716            else:
     2717                Ipvt = result[2]['ipvt']
     2718                for i,ipvt in enumerate(Ipvt):
     2719                    if not np.sum(result[2]['fjac'],axis=1)[i]:
     2720                        print 'Removing parameter: ',varyList[ipvt-1]
     2721                        del(varyList[ipvt-1])
     2722                        break
    26422723
    26432724#    print 'dependentParmList: ',G2mv.dependentParmList
     
    26732754#    cPickle.dump(pawleyLookup,file,1)
    26742755#    file.close()
    2675     return Rwp
     2756    if dlg:
     2757        return Rwp
    26762758
    26772759def SeqRefine(GPXfile,dlg):
     
    27572839            Ftol = Controls['min dM/M']
    27582840            Factor = Controls['shift factor']
    2759             if Controls['deriv type'] == 'analytic':
     2841            maxCyc = Controls['max cyc']
     2842
     2843            if 'Jacobian' in Controls['deriv type']:           
    27602844                result = so.leastsq(errRefine,values,Dfun=dervRefine,full_output=True,
    27612845                    ftol=Ftol,col_deriv=True,factor=Factor,
    2762                     args=([Histo,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    2763                 ncyc = int(result[2]['nfev']/2)               
     2846                    args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
     2847                ncyc = int(result[2]['nfev']/2)
     2848            elif 'Hessian' in Controls['deriv type']:
     2849                result = G2mth.HessianLSQ(errRefine,values,Hess=HessRefine,ftol=Ftol,maxcyc=maxCyc,
     2850                    args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
     2851                ncyc = result[2]['num cyc']+1                           
    27642852            else:           #'numeric'
    27652853                result = so.leastsq(errRefine,values,full_output=True,ftol=Ftol,epsfcn=1.e-8,factor=Factor,
    2766                     args=([Histo,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
     2854                    args=([Histograms,Phases],parmDict,varyList,calcControls,pawleyLookup,dlg))
    27672855                ncyc = int(result[2]['nfev']/len(varyList))
     2856
     2857
     2858
    27682859            runtime = time.time()-begin
    27692860            chisq = np.sum(result[2]['fvec']**2)
     
    27762867            print 135*'-'
    27772868            print ' Number of function calls:',result[2]['nfev'],' Number of observations: ',Histo['Nobs'],' Number of parameters: ',len(varyList)
    2778             print ' Refinement time = %8.3fs, %8.3fs/cycle'%(runtime,runtime/ncyc)
     2869            print ' Refinement time = %8.3fs, %8.3fs/cycle, for %d cycles'%(runtime,runtime/ncyc,ncyc)
    27792870            print ' wRp = %7.2f%%, chi**2 = %12.6g, reduced chi**2 = %6.2f'%(Rwp,chisq,GOF)
    27802871            try:
     
    27872878            except TypeError:          #result[1] is None on singular matrix
    27882879                print '**** Refinement failed - singular matrix ****'
    2789                 Ipvt = result[2]['ipvt']
    2790                 for i,ipvt in enumerate(Ipvt):
    2791                     if not np.sum(result[2]['fjac'],axis=1)[i]:
    2792                         print 'Removing parameter: ',varyList[ipvt-1]
    2793                         del(varyList[ipvt-1])
    2794                         break
     2880                if 'Hessian' in Controls['deriv type']:
     2881                    for i in result[2]['psing'].reverse():
     2882                            print 'Removing parameter: ',varyList[i]
     2883                            del(varyList[i])                   
     2884                else:
     2885                    Ipvt = result[2]['ipvt']
     2886                    for i,ipvt in enumerate(Ipvt):
     2887                        if not np.sum(result[2]['fjac'],axis=1)[i]:
     2888                            print 'Removing parameter: ',varyList[ipvt-1]
     2889                            del(varyList[ipvt-1])
     2890                            break
    27952891   
    27962892        GetFobsSq(Histo,Phases,parmDict,calcControls)
Note: See TracChangeset for help on using the changeset viewer.