Changeset 4532 for trunk/GSASIIphsGUI.py
- Timestamp:
- Jul 22, 2020 8:50:13 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIphsGUI.py
r4525 r4532 4919 4919 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True) 4920 4920 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_VIEWRMC,True) 4921 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_STOPRMC,False) 4921 4922 elif G2frame.RMCchoice == 'fullrmc': 4922 4923 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_SETUPRMC,False) 4923 4924 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,False) 4924 4925 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_VIEWRMC,False) 4926 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_STOPRMC,True) 4925 4927 if G2frame.FRMC.GetSizer(): 4926 4928 G2frame.FRMC.GetSizer().Clear(True) … … 5020 5022 wx.CallAfter(UpdateRMC) 5021 5023 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) 5025 5027 5026 5028 def GetAngleSizer(): … … 5080 5082 return angleSizer 5081 5083 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) 5089 5091 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() 5094 5096 5095 def SetRestart1(invalid,value,tc):5096 RMCPdict['ReStart'][1] = True5097 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()] = ifx5108 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 torsionSizer5097 # 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 5118 5120 #patches 5119 5121 if 'useBVS' not in RMCPdict: … … 5131 5133 if 'min Contact' not in RMCPdict: 5132 5134 RMCPdict['min Contact'] = 1.5 5133 if 'periodicBound' not in RMCPdict:5134 RMCPdict['periodicBound'] = True5135 #if 'periodicBound' not in RMCPdict: 5136 # RMCPdict['periodicBound'] = True 5135 5137 #end patches 5136 5138 … … 5153 5155 lineSizer.Add(GetSuperSizer(),0,WACV) 5154 5156 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) 5161 5160 mainSizer.Add(lineSizer,0,WACV) 5162 5161 if ifBox: … … 5217 5216 mainSizer.Add(GetAngleSizer(),0,WACV) 5218 5217 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. 5220 5220 # torBox = wx.BoxSizer(wx.HORIZONTAL) 5221 5221 # torAdd = wx.Button(G2frame.FRMC,label='Add') … … 5638 5638 RMCPdict = data['RMC']['fullrmc'] 5639 5639 # 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) 5642 5644 # end debug stuff 5643 5645 rname = G2pwd.MakefullrmcRun(pName,data,RMCPdict) … … 5701 5703 OnSetupRMC(event) 5702 5704 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 existing5707 run as {}. You must manually delete this directory if5708 you wish to restart or change the restart checkbox to5709 continue from the previous results.5710 '''.format(rmcname),'Restart or Continue?')5711 # TODO: could do this for the user with:5712 #import shutil5713 #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) 5714 5716 G2G.G2MessageBox(G2frame,'''For use of fullrmc, please cite: 5715 5717 … … 5808 5810 sb.Popen('runrmc.bat',creationflags=sb.CREATE_NEW_CONSOLE) 5809 5811 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 5810 5830 def OnViewRMC(event): 5811 5831 if G2frame.RMCchoice == 'fullrmc': … … 5904 5924 print("Unexpected error reading from fullrmc engine\n ",msg) 5905 5925 return 5926 plotList.append('fullrmc residuals for '+pName) 5906 5927 if not found or len(plotList) == 0: 5907 5928 G2G.G2MessageBox(G2frame,'No saved information yet, wait until fullrmc does a Save', … … 6036 6057 if item.__class__.__name__+' pyplot' in selectedPlots: 6037 6058 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 6040 6077 #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) 6102 6084 else: 6103 6085 generalData = data['General'] … … 11868 11850 11869 11851 # beginning of FillMapPeaksGrid() 11870 #import imp # debug code11871 #imp.reload(G2plt) # debug code11872 11852 G2frame.GetStatusBar().SetStatusText('',1) 11873 11853 if 'Map Peaks' in data: … … 12360 12340 FillRigidBodyGrid() 12361 12341 elif text == 'Map peaks': 12362 #print('reimport GSASIIplot')12363 #import imp12364 #imp.reload(G2plt)12365 12342 G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.MapPeaksMenu) 12366 12343 G2plt.PlotStructure(G2frame,data,firstCall=True) … … 12506 12483 G2frame.Bind(wx.EVT_MENU, OnRunRMC, id=G2G.wxID_RUNRMC) 12507 12484 G2frame.Bind(wx.EVT_MENU, OnViewRMC, id=G2G.wxID_VIEWRMC) 12485 G2frame.Bind(wx.EVT_MENU, OnStopRMC, id=G2G.wxID_STOPRMC) 12508 12486 # MC/SA 12509 12487 FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.MCSAMenu)
Note: See TracChangeset
for help on using the changeset viewer.