Changeset 4532 for trunk/GSASIIphsGUI.py


Ignore:
Timestamp:
Jul 22, 2020 8:50:13 PM (3 years ago)
Author:
toby
Message:

refactor ViewLSparms; more fullrmc work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIphsGUI.py

    r4525 r4532  
    49194919            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True)
    49204920            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_VIEWRMC,True)
     4921            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_STOPRMC,False)
    49214922        elif G2frame.RMCchoice == 'fullrmc':
    49224923            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_SETUPRMC,False)
    49234924            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,False)
    49244925            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_VIEWRMC,False)
     4926            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_STOPRMC,True)
    49254927        if G2frame.FRMC.GetSizer():
    49264928            G2frame.FRMC.GetSizer().Clear(True)
     
    50205022                wx.CallAfter(UpdateRMC)
    50215023               
    5022             def OnAddTorsion(event):
    5023                 RMCPdict['Torsions'].append(['','','','',0.,0.,0.,0.,0.,0.])
    5024                 wx.CallAfter(UpdateRMC)
     5024            # def OnAddTorsion(event):
     5025            #     RMCPdict['Torsions'].append(['','','','',0.,0.,0.,0.,0.,0.])
     5026            #     wx.CallAfter(UpdateRMC)
    50255027               
    50265028            def GetAngleSizer():
     
    50805082                return angleSizer
    50815083           
    5082             def GetTorsionSizer():
    5083                
    5084                 def OnDelTorsion(event):
    5085                     Obj = event.GetEventObject()
    5086                     angle = Indx[Obj.GetId()]
    5087                     del RMCPdict['Torsions'][angle]
    5088                     wx.CallAfter(UpdateRMC)
     5084            # def GetTorsionSizer():
     5085               
     5086            #     def OnDelTorsion(event):
     5087            #         Obj = event.GetEventObject()
     5088            #         angle = Indx[Obj.GetId()]
     5089            #         del RMCPdict['Torsions'][angle]
     5090            #         wx.CallAfter(UpdateRMC)
    50895091                   
    5090                 def OnTorsionAtSel(event):
    5091                     Obj = event.GetEventObject()
    5092                     torsion,i = Indx[Obj.GetId()]
    5093                     RMCPdict['Torsions'][torsion][i] = Obj.GetStringSelection()
     5092            #     def OnTorsionAtSel(event):
     5093            #         Obj = event.GetEventObject()
     5094            #         torsion,i = Indx[Obj.GetId()]
     5095            #         RMCPdict['Torsions'][torsion][i] = Obj.GetStringSelection()
    50945096                                           
    5095                 def SetRestart1(invalid,value,tc):
    5096                     RMCPdict['ReStart'][1] = True
    5097                
    5098                 Indx = {}
    5099                 atChoice = [atm for atm in RMCPdict['atSeq'] if 'Va' not in atm]
    5100                 torsionSizer = wx.FlexGridSizer(11,5,5)
    5101                 fxcnLabels = [' ','Atom-A','Atom-B','Atom-C','Atom-D',' min angle1',' max angle1',' min angle2',' max angle2',' min angle3',' max angle3']
    5102                 for lab in fxcnLabels:
    5103                     torsionSizer.Add(wx.StaticText(G2frame.FRMC,label=lab),0,WACV)
    5104                 for ifx,torsion in enumerate(RMCPdict['Torsions']):
    5105                     delBtn = wx.Button(G2frame.FRMC,label='Delete')
    5106                     delBtn.Bind(wx.EVT_BUTTON,OnDelTorsion)
    5107                     Indx[delBtn.GetId()] = ifx
    5108                     torsionSizer.Add(delBtn,0,WACV)
    5109                     for i in [0,1,2,3]:
    5110                         atmSel = wx.ComboBox(G2frame.FRMC,choices=atChoice,style=wx.CB_DROPDOWN|wx.TE_READONLY)
    5111                         atmSel.SetStringSelection(torsion[i])
    5112                         atmSel.Bind(wx.EVT_COMBOBOX,OnTorsionAtSel)
    5113                         Indx[atmSel.GetId()] = [ifx,i]
    5114                         torsionSizer.Add(atmSel,0,WACV)
    5115                     for i in  [4,5,6,7,8,9]:
    5116                         torsionSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,torsion,i,xmin=0.,xmax=360.,OnLeave=SetRestart1,size=(50,25)),0,WACV)
    5117                 return torsionSizer
     5097            #     def SetRestart1(invalid,value,tc):
     5098            #         RMCPdict['ReStart'][1] = True
     5099               
     5100            #     Indx = {}
     5101            #     atChoice = [atm for atm in RMCPdict['atSeq'] if 'Va' not in atm]
     5102            #     torsionSizer = wx.FlexGridSizer(11,5,5)
     5103            #     fxcnLabels = [' ','Atom-A','Atom-B','Atom-C','Atom-D',' min angle1',' max angle1',' min angle2',' max angle2',' min angle3',' max angle3']
     5104            #     for lab in fxcnLabels:
     5105            #         torsionSizer.Add(wx.StaticText(G2frame.FRMC,label=lab),0,WACV)
     5106            #     for ifx,torsion in enumerate(RMCPdict['Torsions']):
     5107            #         delBtn = wx.Button(G2frame.FRMC,label='Delete')
     5108            #         delBtn.Bind(wx.EVT_BUTTON,OnDelTorsion)
     5109            #         Indx[delBtn.GetId()] = ifx
     5110            #         torsionSizer.Add(delBtn,0,WACV)
     5111            #         for i in [0,1,2,3]:
     5112            #             atmSel = wx.ComboBox(G2frame.FRMC,choices=atChoice,style=wx.CB_DROPDOWN|wx.TE_READONLY)
     5113            #             atmSel.SetStringSelection(torsion[i])
     5114            #             atmSel.Bind(wx.EVT_COMBOBOX,OnTorsionAtSel)
     5115            #             Indx[atmSel.GetId()] = [ifx,i]
     5116            #             torsionSizer.Add(atmSel,0,WACV)
     5117            #         for i in  [4,5,6,7,8,9]:
     5118            #             torsionSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,torsion,i,xmin=0.,xmax=360.,OnLeave=SetRestart1,size=(50,25)),0,WACV)
     5119            #     return torsionSizer
    51185120#patches
    51195121            if 'useBVS' not in RMCPdict:
     
    51315133            if 'min Contact' not in RMCPdict:
    51325134                RMCPdict['min Contact'] = 1.5
    5133             if 'periodicBound' not in RMCPdict:
    5134                 RMCPdict['periodicBound'] = True
     5135            #if 'periodicBound' not in RMCPdict:
     5136            #    RMCPdict['periodicBound'] = True
    51355137#end patches
    51365138
     
    51535155            lineSizer.Add(GetSuperSizer(),0,WACV)
    51545156            lineSizer.Add((5,-1))
    5155 #            lineSizer.Add(G2G.G2CheckBox(G2frame.FRMC,'Impose periodic boundaries',RMCPdict,'periodicBound'),
    5156 #                              0,WACV)
    5157 #            lineSizer.Add(wx.StaticText(G2frame.FRMC,label=' Num. atoms per group '),0,WACV)
    5158 #            lineSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict,'Natoms',xmin=1,size=[40,25]),0,WACV)
    5159 #            else:
    5160 #                lineSizer.Add(wx.StaticText(G2frame.FRMC,label=' Starting phase symmetry must be P 1; transform structure first'))
     5157            # Bachir suggests that w/o periodic boundaries, users are likely to use fullrmc wrong
     5158            #lineSizer.Add(G2G.G2CheckBox(G2frame.FRMC,'Impose periodic boundaries',RMCPdict,'periodicBound'),
     5159            #                  0,WACV)
    51615160            mainSizer.Add(lineSizer,0,WACV)
    51625161            if ifBox:
     
    52175216                mainSizer.Add(GetAngleSizer(),0,WACV)
    52185217
    5219             # Torsions are probably not implemented correctly, hide them for now
     5218            # Torsions are difficult to implement. Need to be internal to a unit cell & named with fullrmc
     5219            # atom labels. Leave this out, at least for now.
    52205220            # torBox = wx.BoxSizer(wx.HORIZONTAL)
    52215221            # torAdd = wx.Button(G2frame.FRMC,label='Add')
     
    56385638            RMCPdict = data['RMC']['fullrmc']
    56395639            # debug stuff
    5640             import imp
    5641             imp.reload(G2pwd)
     5640            if GSASIIpath.GetConfigValue('debug'):
     5641                print('reloading',G2pwd)
     5642                import imp
     5643                imp.reload(G2pwd)
    56425644            # end debug stuff           
    56435645            rname = G2pwd.MakefullrmcRun(pName,data,RMCPdict)
     
    57015703                OnSetupRMC(event)
    57025704            RMCPdict = data['RMC']['fullrmc']
    5703             rmcname = pName+'.rmc'
    5704             if os.path.isdir(rmcname) and RMCPdict['ReStart'][0]:
    5705                 G2G.G2MessageBox(G2frame,
    5706                     '''You have asked to restart fullrmc but have an existing
    5707                     run as {}. You must manually delete this directory if
    5708                     you wish to restart or change the restart checkbox to
    5709                     continue from the previous results.
    5710                     '''.format(rmcname),'Restart or Continue?')
    5711                 # TODO: could do this for the user with:
    5712                 #import shutil
    5713                 #shutil.rmtree(rmcname)
     5705            #rmcname = pName+'.rmc'
     5706            # if os.path.isdir(rmcname) and RMCPdict['ReStart'][0]:
     5707            #     G2G.G2MessageBox(G2frame,
     5708            #         '''You have asked to restart fullrmc but have an existing
     5709            #         run as {}. You must manually delete this directory if
     5710            #         you wish to restart or change the restart checkbox to
     5711            #         continue from the previous results.
     5712            #         '''.format(rmcname),'Restart or Continue?')
     5713            #     # TODO: could do this for the user with:
     5714            #     #import shutil
     5715            #     #shutil.rmtree(rmcname)
    57145716            G2G.G2MessageBox(G2frame,'''For use of fullrmc, please cite:
    57155717
     
    58085810            sb.Popen('runrmc.bat',creationflags=sb.CREATE_NEW_CONSOLE)
    58095811           
     5812    def OnStopRMC(event):
     5813        if G2frame.RMCchoice == 'fullrmc':
     5814            RMCPdict = data['RMC']['fullrmc']
     5815            generalData = data['General']
     5816            pName = G2frame.GSASprojectfile.split('.')[0] + '-' + generalData['Name']
     5817            pName = pName.replace(' ','_')
     5818            engineFilePath = pName+'.rmc'
     5819            if not os.path.exists(engineFilePath):
     5820                print('fullrmc repository {} not found'.format(engineFilePath))
     5821                return
     5822            try:
     5823                from fullrmc import InterceptHook
     5824                hook = InterceptHook(path=engineFilePath)
     5825                hook.stop_engine()
     5826                print('hook.stop_engine() sent to {}'.format(engineFilePath))
     5827            except Exception as msg:
     5828                print('failed, msg=',msg)
     5829     
    58105830    def OnViewRMC(event):
    58115831        if G2frame.RMCchoice == 'fullrmc':
     
    59045924                 print("Unexpected error reading from fullrmc engine\n  ",msg)
    59055925                 return
     5926            plotList.append('fullrmc residuals for '+pName)
    59065927            if not found or len(plotList) == 0:
    59075928                G2G.G2MessageBox(G2frame,'No saved information yet, wait until fullrmc does a Save',
     
    60366057                    if item.__class__.__name__+' pyplot' in selectedPlots:
    60376058                        item.plot(show=True)
    6038 
    6039             # how to get std err vs steps?
     6059                       
     6060            # read log files to get std err vs steps
     6061            ilog = 0
     6062            Gen = []
     6063            Err = []
     6064            while True:
     6065                fname = '{}_{}.log'.format(pName,ilog)
     6066                try:
     6067                    logfile = open(fname,'r')
     6068                    for line in logfile.readlines():
     6069                        if "fullrmc <STEP>" not in line: continue
     6070                        Gen.append(float(int(line.split('Gen:')[1].split()[0])))
     6071                        Err.append(float(line.split('Err:')[1].strip()))
     6072                    logfile.close()
     6073                except FileNotFoundError:
     6074                    break
     6075                ilog += 1
     6076            title = 'fullrmc residuals for '+pName
    60406077            #GSASIIpath.IPyBreak()
    6041             # loglines = []
    6042             # ilog = 0
    6043             # while True:
    6044             #     fname = '%s_%d.log'%(pName,ilog)
    6045             #     try:
    6046             #         logfile = open(fname,'r')
    6047             #         loglines += logfile.readlines()
    6048             #         logfile.close()
    6049             #     except FileNotFoundError:
    6050             #         break
    6051             #     ilog += 1
    6052             # if not len(loglines):
    6053             #     print('no log file found')
    6054             #     return
    6055             # start = 0
    6056             # while True:
    6057             #     if start == len(loglines):
    6058             #         print('No log info to plot')
    6059             #         return
    6060             #     line = loglines[start]               
    6061             #     if 'Err:' in line:
    6062             #         break
    6063             #     else:
    6064             #         start += 1
    6065             # Gen = []
    6066             # Err = []
    6067             # start -= 1
    6068             # while True:
    6069             #     start += 1
    6070             #     try:
    6071             #         line = loglines[start]
    6072             #     except:
    6073             #         break
    6074             #     if 'Err' not in line:
    6075             #         continue
    6076             #     items = line.split(' - ')
    6077             #     try:    # could be a trashed line at end
    6078             #         errStr = items[5][:-1].split('Err:')[1]
    6079             #         Err.append([float(val) for val in errStr.split(',')])
    6080             #     except ValueError:
    6081             #         break
    6082             #     Gen.append(int(items[1].split('Gen:')[1]))
    6083            
    6084             # Gen = np.array(Gen)
    6085             # Err = np.array(Err)
    6086             # nObs = np.array(nObs)
    6087             # if np.any(nObs):
    6088             #     Err /= nObs[:Err.shape[1]]
    6089             #     ptstr1 = ''
    6090             #     ptstr2 = ''
    6091             #     for it,item in enumerate(eNames):
    6092             #         ptstr1 += ' %s obs: %d'%(item,nObs[it])
    6093             #         ptstr2 += ' %s reduced chi^2: %.5f'%(item,Err[-1][it])
    6094             #     print(ptstr1)
    6095             #     print(ptstr2)
    6096             #     Err = np.log10(Err)
    6097             #     XY = [[Gen,Erri] for Erri in Err.T]
    6098             #     G2plt.PlotXY(G2frame,XY,labelX='no. generated',
    6099             #         labelY=r'$log_{10}$ (reduced $\mathsf{\chi^2})$',newPlot=True,Title='fullrmc residuals for '+pName,
    6100             #         lines=True,names=eNames)
    6101                      
     6078            if len(Gen) > 0 and title in selectedPlots:
     6079                Gen = np.array(Gen)
     6080                Err = np.log10(Err)
     6081                G2plt.PlotXY(G2frame,[[Gen,Err]],labelX='generated steps',
     6082                               labelY=r'$log_{10}$ ($\mathsf{\chi^2})$',newPlot=True,Title=title,
     6083                               lines=True,names=eNames)
    61026084        else:
    61036085            generalData = data['General']
     
    1186811850           
    1186911851        # beginning of FillMapPeaksGrid()
    11870         #import imp   # debug code
    11871         #imp.reload(G2plt) # debug code
    1187211852        G2frame.GetStatusBar().SetStatusText('',1)
    1187311853        if 'Map Peaks' in data:
     
    1236012340            FillRigidBodyGrid()
    1236112341        elif text == 'Map peaks':
    12362             #print('reimport GSASIIplot')
    12363             #import imp
    12364             #imp.reload(G2plt)
    1236512342            G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.MapPeaksMenu)
    1236612343            G2plt.PlotStructure(G2frame,data,firstCall=True)
     
    1250612483        G2frame.Bind(wx.EVT_MENU, OnRunRMC, id=G2G.wxID_RUNRMC)
    1250712484        G2frame.Bind(wx.EVT_MENU, OnViewRMC, id=G2G.wxID_VIEWRMC)
     12485        G2frame.Bind(wx.EVT_MENU, OnStopRMC, id=G2G.wxID_STOPRMC)
    1250812486        # MC/SA
    1250912487        FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.MCSAMenu)
Note: See TracChangeset for help on using the changeset viewer.