Changeset 4532
- Timestamp:
- Jul 22, 2020 8:50:13 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIctrlGUI.py
r4499 r4532 3855 3855 ''' 3856 3856 def __init__(self,parent,title,parmDict,varyList,fullVaryList, 3857 size=(375,430)): 3857 parmMinDict={}, parmMaxDict={}, frozenList=[], 3858 size=(650,430)): 3858 3859 3859 3860 wx.Dialog.__init__(self,parent,wx.ID_ANY,title,size=size, … … 3863 3864 self.varyList = varyList 3864 3865 self.fullVaryList = fullVaryList 3866 self.parmMinDict = parmMinDict 3867 self.parmMaxDict = parmMaxDict 3868 self.frozenList = frozenList 3865 3869 self.choiceDict = {} 3870 # if GSASIIpath.GetConfigValue('debug'): 3871 # print('dummy settings for frozenList etc') 3872 # self.parmMinDict['0::Afrac:26'] = 0.0 3873 # self.frozenList = ['0::Afrac:26'] 3866 3874 3867 3875 # make lists of variables of different types along with lists of parameter names, histogram #s, phase #s,... … … 3879 3887 self.choiceDict['Histogram'] = G2obj.SortVariables(hisNames) 3880 3888 self.hisNums = sorted(list(set([int(item.split(':')[1]) for item in hisNames]))) 3881 self.hisNums = [' 3889 self.hisNums = ['*',]+[str(item) for item in self.hisNums] 3882 3890 self.hisVars = sorted(list(set([' ',]+[item[2] for item in splitNames if not item[0]]))) 3883 3891 phasNames = [':'.join(item) for item in splitNames if not item[1] and 'is' not in item[2]] 3884 3892 self.choiceDict['Phase'] = G2obj.SortVariables(phasNames) 3885 self.phasNums = sorted([' 3893 self.phasNums = sorted(['*',]+list(set([item.split(':')[0] for item in phasNames]))) 3886 3894 if '' in self.phasNums: self.phasNums.remove('') 3887 3895 self.phasVars = sorted(list(set([' ',]+[item[2] for item in splitNames if not item[1] and 'is' not in item[2]]))) … … 3890 3898 self.hapVars = sorted(list(set([' ',]+[item[2] for item in splitNames if item[0] and item[1]]))) 3891 3899 3892 self.hisNum = ' 3893 self.phasNum = ' 3900 self.hisNum = '*' 3901 self.phasNum = '*' 3894 3902 self.varName = ' ' 3895 3903 self.listSel = 'Refined' … … 3897 3905 3898 3906 def repaintScrollTbl(self): 3899 '''Shows the selected variables 3900 3901 This routine is pretty slow when lots of variables are selected. Why? 3907 '''Shows the selected variables in a ListCtrl 3902 3908 ''' 3903 self.countSizer.Clear(True) 3904 self.headSizer.Clear(True) 3905 self.scrolledSizer.Clear(True) 3906 self.explainSizer.Clear(True) 3907 3908 explainRefine = False 3909 count = 0 3910 for name in self.choiceDict[self.parmChoice]: 3911 if '2' in platform.python_version_tuple()[0]: 3912 basestr = basestring 3913 else: 3914 basestr = str 3915 if isinstance(self.parmDict[name],basestr): continue 3916 if 'Refined' in self.listSel and (name not in self.fullVaryList 3917 ) and (name not in self.varyList): 3918 continue 3919 if 'Phase' in self.parmChoice: 3920 if self.phasNum != ' ' and name.split(':')[0] != self.phasNum: continue 3921 if 'Histo' in self.parmChoice: 3922 if self.hisNum != ' ' and name.split(':')[1] != self.hisNum: continue 3923 if (self.varName != ' ') and (self.varName not in name): continue 3924 try: 3925 value = G2py3.FormatSigFigs(self.parmDict[name]) 3926 except TypeError: 3927 value = str(self.parmDict[name])+' -?' # unexpected 3928 #continue 3929 v = G2obj.getVarDescr(name) 3930 if v is None or v[-1] is None: 3931 self.scrolledSizer.Add((-1,-1)) 3932 else: 3933 ch = HelpButton(self.panel,G2obj.fmtVarDescr(name)) 3934 self.scrolledSizer.Add(ch,0,wx.LEFT|wx.RIGHT|WACV|wx.ALIGN_CENTER,1) 3935 self.scrolledSizer.Add(wx.StaticText(self.panel,wx.ID_ANY,str(name))) 3936 if name in self.varyList: 3937 self.scrolledSizer.Add(wx.StaticText(self.panel,label='R',size=(50,-1))) #TODO? maybe a checkbox for one stop refinement flag setting? 3938 elif name in self.fullVaryList: 3939 self.scrolledSizer.Add(wx.StaticText(self.panel,label='C',size=(50,-1))) 3940 explainRefine = True 3941 else: 3942 self.scrolledSizer.Add((50,-1)) 3943 self.scrolledSizer.Add(wx.StaticText(self.panel,label=value),0,wx.ALIGN_RIGHT) 3944 count += 1 3945 if count > 200: 3946 msg = wx.StaticText(self,label='Too many parameters selected. Showing first 200') 3947 msg.SetBackgroundColour(wx.YELLOW) 3948 self.countSizer.Add(msg,0,wx.ALIGN_LEFT) 3949 self.countSizer.Add((-1,10)) 3950 break 3951 3952 if explainRefine: 3953 self.explainSizer.Add( 3954 wx.StaticText(self,label='"R" indicates a refined variable\n'+ 3955 '"C" indicates generated from a constraint'),0, wx.ALL,0) 3956 self.panel.SetAutoLayout(1) 3957 self.panel.SetupScrolling() 3958 self.SetMinSize(self.GetSize()) # Allow window to be enlarged but not made smaller 3959 for txt,wid,loc in zip(['','Parameter name','refine?','value'],self.scrolledSizer.GetColWidths(), 3960 [wx.ALIGN_LEFT,wx.ALIGN_LEFT,wx.ALIGN_LEFT,wx.ALIGN_RIGHT]): 3961 self.headSizer.Add(wx.StaticText(self,wx.ID_ANY,txt,size=(wid,-1),style=loc),0,loc) 3909 start = time.time() 3910 self.varBox.SetContents(self) 3962 3911 self.SendSizeEvent() 3963 3912 if GSASIIpath.GetConfigValue('debug'): 3913 print('repaintScrollTbl',time.time()-start) 3914 3964 3915 def DrawPanel(self): 3965 3916 '''Draws the contents of the entire dialog. Called initially & when radio buttons are pressed … … 3987 3938 event.Skip() 3988 3939 self.varName = varSel.GetValue() 3989 self.phasNum = ' 3940 self.phasNum = '*' 3990 3941 if phasSel: phasSel.SetSelection(0) 3991 self.hisNum = ' 3942 self.hisNum = '*' 3992 3943 if histSel: histSel.SetSelection(0) 3993 3944 wx.CallAfter(self.repaintScrollTbl) … … 4027 3978 varSelSizer.Add(varSpin,0) 4028 3979 varSizer.Add(varSelSizer,0) 4029 3980 4030 3981 if self.GetSizer(): self.GetSizer().Clear(True) 4031 3982 self.SpinDict = {} 4032 3983 mainSizer = wx.BoxSizer(wx.VERTICAL) 4033 3984 num = len(self.varyList) 4034 mainSizer.Add(wx.StaticText(self,label=' Number of refined variables: '+str(num)),0,wx.ALIGN_CENTER) 3985 mainSizer.Add(wx.StaticText(self,label='View Parameters in Project'),0,wx.ALIGN_CENTER) 3986 parmSizer = wx.BoxSizer(wx.HORIZONTAL) 3987 parmSizer.Add(wx.StaticText(self,label=' Number of refined variables: {}'.format(num)),0,wx.ALIGN_LEFT) 4035 3988 if len(self.varyList) != len(self.fullVaryList): 4036 3989 num = len(self.fullVaryList) - len(self.varyList) 4037 mainSizer.Add(wx.StaticText(self,label=' + '+str(num)+' parameters are varied via constraints')) 3990 parmSizer.Add(wx.StaticText(self,label= 3991 ' + {} parameters are varied via constraints'.format( 3992 len(self.fullVaryList) - len(self.varyList)) 3993 )) 3994 mainSizer.Add(parmSizer) 4038 3995 choice = ['Phase','Phase/Histo','Histogram'] 4039 3996 if 'Global' in self.choiceDict: … … 4067 4024 numSizer = wx.BoxSizer(wx.VERTICAL) 4068 4025 phasSel = wx.ComboBox(self,choices=self.phasNums,value=self.phasNum, 4069 style=wx.CB_READONLY|wx.CB_DROPDOWN )4026 style=wx.CB_READONLY|wx.CB_DROPDOWN,size=(50,-1)) 4070 4027 AddSpinner(numSizer,'Phase',phasSel,OnPhasSel) 4071 4028 varSizer.Add(numSizer) … … 4075 4032 numSizer = wx.BoxSizer(wx.VERTICAL) 4076 4033 histSel = wx.ComboBox(self,choices=self.hisNums,value=self.hisNum, 4077 style=wx.CB_READONLY|wx.CB_DROPDOWN )4034 style=wx.CB_READONLY|wx.CB_DROPDOWN,size=(50,-1)) 4078 4035 AddSpinner(numSizer,'Histogram',histSel,OnHistSel) 4079 4036 varSizer.Add(numSizer) 4080 4037 selectionsSizer.Add(varSizer,0) 4081 4038 parmSizer.Add(selectionsSizer,0) 4082 mainSizer.Add(parmSizer,0)4083 4084 4039 listSel = wx.RadioBox(self,wx.ID_ANY,'Parameter type:', 4085 4040 choices=['All','Refined'], … … 4087 4042 listSel.SetStringSelection(self.listSel) 4088 4043 listSel.Bind(wx.EVT_RADIOBOX,OnListSel) 4089 mainSizer.Add(listSel,0) 4044 parmSizer.Add(listSel,0,wx.CENTER|wx.ALL,15) 4045 mainSizer.Add(parmSizer,0) 4046 4090 4047 4091 4048 self.countSizer = wx.BoxSizer(wx.VERTICAL) … … 4093 4050 self.headSizer = wx.BoxSizer(wx.HORIZONTAL) # non-scrolling header 4094 4051 mainSizer.Add(self.headSizer,0) 4095 self.panel = wxscroll.ScrolledPanel(self) 4096 self.scrolledSizer = wx.FlexGridSizer(cols=4,hgap=2,vgap=2) 4097 self.panel.SetSizer(self.scrolledSizer) 4098 mainSizer.Add(self.panel,1,wx.ALL|wx.EXPAND,1) 4099 self.explainSizer = wx.BoxSizer(wx.VERTICAL) 4100 mainSizer.Add(self.explainSizer) 4101 # make OK button 4102 btnsizer = wx.BoxSizer(wx.HORIZONTAL) 4052 self.varBox = VirtualVarBox(self) 4053 mainSizer.Add(self.varBox,1,wx.ALL|wx.EXPAND,1) 4054 4055 txt = ('"R" indicates a refined variable\n'+ 4056 '"C" indicates generated from a constraint') 4057 # if GSASIIpath.GetConfigValue('debug'): 4058 # txt += '\n"F" indicates a variable that is Frozen due to exceeding min/max' 4059 mainSizer.Add( 4060 wx.StaticText(self,label=txt),0, wx.ALL,0) 4061 4062 btnsizer = wx.BoxSizer(wx.HORIZONTAL) # make Close button 4103 4063 btn = wx.Button(self, wx.ID_CLOSE,"Close") 4104 4064 btn.Bind(wx.EVT_BUTTON,self._onClose) … … 4110 4070 def _onClose(self,event): 4111 4071 self.EndModal(wx.ID_CANCEL) 4072 4073 class VirtualVarBox(wx.ListCtrl): 4074 def __init__(self, parent): 4075 self.parmWin = parent 4076 wx.ListCtrl.__init__( 4077 self, parent, -1, 4078 style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES 4079 ) 4080 4081 # if GSASIIpath.GetConfigValue('debug'): 4082 # for i,(lbl,wid) in enumerate(zip( 4083 # ('#', "Parameter", "Ref?", "Value", "Min", "Max", "Explanation"), 4084 # (40 , 100 , 35 , 100 , 75 , 75 , 700),)): 4085 # self.InsertColumn(i, lbl) 4086 # self.SetColumnWidth(i, wid) 4087 # else: 4088 if True: 4089 for i,(lbl,wid) in enumerate(zip( 4090 ('#', "Parameter", "Ref?", "Value", "", "", "Explanation"), 4091 (40 , 100 , 35 , 100 , 5 , 5 , 700),)): 4092 self.InsertColumn(i, lbl) 4093 self.SetColumnWidth(i, wid) 4094 4095 self.SetItemCount(0) 4096 4097 self.attr1 = wx.ListItemAttr() 4098 self.attr1.SetBackgroundColour((255,255,150)) 4099 4100 if GSASIIpath.GetConfigValue('debug'): 4101 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected) 4102 #self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColSelected) 4103 4104 def SetContents(self,parent): 4105 self.varList = [] 4106 for name in parent.choiceDict[parent.parmChoice]: 4107 if '2' in platform.python_version_tuple()[0]: 4108 basestr = basestring 4109 else: 4110 basestr = str 4111 if isinstance(parent.parmDict[name],basestr): continue 4112 if 'Refined' in parent.listSel and (name not in parent.fullVaryList 4113 ) and (name not in parent.varyList): 4114 continue 4115 if 'Phase' in parent.parmChoice: 4116 if parent.phasNum != '*' and name.split(':')[0] != parent.phasNum: continue 4117 if 'Histo' in parent.parmChoice: 4118 if parent.hisNum != '*' and name.split(':')[1] != parent.hisNum: continue 4119 if (parent.varName != ' ') and (parent.varName not in name): continue 4120 self.varList.append(name) 4121 oldlen = self.GetItemCount() 4122 self.SetItemCount(len(self.varList)) 4123 4124 def OnItemSelected(self, event): 4125 print('OnItemSelected: "%s"\n' % (event.Index)) 4126 #def OnColSelected(self, event): 4127 # print('Column selected:',event.Column) 4128 # #G2p.IPyBreak_base() 4129 #----------------------------------------------------------------- 4130 # Callbacks to set info in table 4131 def OnGetItemText(self, item, col): 4132 name = self.varList[item] 4133 if col == 0: 4134 return str(item) 4135 elif col == 1: 4136 return name 4137 elif col == 2: 4138 if name in self.parmWin.varyList: 4139 if name in self.parmWin.frozenList: 4140 return "F" 4141 return "R" 4142 elif name in self.parmWin.fullVaryList: 4143 return "C" 4144 return "" 4145 elif col == 3: 4146 try: 4147 value = G2py3.FormatSigFigs(self.parmWin.parmDict[name]) 4148 except TypeError: 4149 value = str(self.parmWin.parmDict[name])+' -?' # unexpected 4150 return value 4151 #continue 4152 elif col == 4: 4153 if name in self.parmWin.parmMinDict: 4154 return G2py3.FormatSigFigs(self.parmWin.parmMinDict[name],8) 4155 return "" # min value 4156 elif col == 5: 4157 if name in self.parmWin.parmMaxDict: 4158 return G2py3.FormatSigFigs(self.parmWin.parmMaxDict[name],8) 4159 return "" # max value 4160 elif col == 6: 4161 v = G2obj.getVarDescr(name) 4162 if v is not None and v[-1] is not None: 4163 txt = G2obj.fmtVarDescr(name) 4164 if txt: return txt 4165 return "" 4166 else: 4167 return "?" 4168 4169 def OnGetItemAttr(self, item): 4170 name = self.varList[item] 4171 if name in self.parmWin.varyList and name in self.parmWin.frozenList: 4172 return self.attr1 4173 else: 4174 return None 4112 4175 4113 4176 ################################################################################ -
trunk/GSASIIdataGUI.py
r4531 r4532 24 24 import sys 25 25 import os 26 #import glob27 #import imp28 26 import inspect 29 27 if '2' in platform.python_version_tuple()[0]: … … 624 622 self.Bind(wx.EVT_MENU, self.OnMakePDFs, id=item.GetId()) 625 623 626 item = parent.Append(wx.ID_ANY,'&View LS parms ','View least squares parameters')624 item = parent.Append(wx.ID_ANY,'&View LS parms\tCTRL+L','View least squares parameters') 627 625 self.Bind(wx.EVT_MENU, self.OnShowLSParms, id=item.GetId()) 628 626 … … 1335 1333 item = submenu.Append(wx.ID_ANY,'Auto Import','Import data files as found') 1336 1334 def OnAutoImport(event): 1337 #import imp1338 #imp.reload(G2G)1339 1335 G2G.AutoLoadFiles(self,FileTyp='pwd') 1340 1336 self.Bind(wx.EVT_MENU, OnAutoImport, id=item.GetId()) … … 2527 2523 item = submenu.Append(wx.ID_ANY,'Auto Import','Import PDF files as found') 2528 2524 def OnAutoImport(event): 2529 #import imp2530 #imp.reload(G2G)2531 2525 G2G.AutoLoadFiles(self,FileTyp='gr') 2532 2526 self.Bind(wx.EVT_MENU, OnAutoImport, id=item.GetId()) … … 4973 4967 pass 4974 4968 wx.EndBusyCursor() 4975 dlg = G2G.ShowLSParms(self,'Least Squares Parameters',parmValDict,varyList,reqVaryList) 4969 # debug stuff 4970 if GSASIIpath.GetConfigValue('debug'): 4971 print('reloading',G2G) 4972 import imp 4973 imp.reload(G2G) 4974 # end debug stuff 4975 dlg = G2G.ShowLSParms(self,'Least Squares Parameters',parmValDict, 4976 varyList,reqVaryList) 4976 4977 dlg.ShowModal() 4977 4978 dlg.Destroy() … … 6063 6064 6064 6065 #Phase / fullrmc & RMCprofile (Reverse Monte Carlo method) tab 6065 G2G.Define_wxId('wxID_SETUPRMC','wxID_RUNRMC','wxID_VIEWRMC' ) 6066 G2G.Define_wxId('wxID_SETUPRMC','wxID_RUNRMC','wxID_VIEWRMC', 6067 'wxID_STOPRMC') 6066 6068 self.FRMCMenu = wx.MenuBar() 6067 6069 self.PrefillDataMenu(self.FRMCMenu) … … 6071 6073 self.FRMCDataEdit.Append(G2G.wxID_SETUPRMC,'Setup RMC','Setup new fullrmc or RMCprofile file') 6072 6074 self.FRMCDataEdit.Append(G2G.wxID_RUNRMC,'Execute','Run fullrmc or RMCprofile file') 6073 self.FRMCDataEdit.Append(G2G.wxID_VIEWRMC,'View','View fullrmc or RMCprofile results') 6075 self.FRMCDataEdit.Append(G2G.wxID_STOPRMC,'Stop run','Stop fullrmc run') 6076 self.FRMCDataEdit.Append(G2G.wxID_VIEWRMC,'Plot','View fullrmc or RMCprofile results') 6074 6077 self.PostfillDataMenu() 6075 6078 -
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) -
trunk/GSASIIpwd.py
r4527 r4532 2796 2796 rundata += ''' 2797 2797 # fullrmc imports (all that are potentially useful) 2798 import os,glob 2799 import time 2798 2800 #import matplotlib.pyplot as plt 2799 2801 import numpy as np 2800 import time2801 2802 from fullrmc.Core import Collection 2802 2803 from fullrmc.Engine import Engine … … 2900 2901 '("element","{1}","{0}","{2}",{5},{6},{5},{6},{3},{4}),\n'.format(*item)) 2901 2902 rundata += ' ])\n' 2903 rundata += ' for f in glob.glob("{}_*.log"): os.remove(f)\n'.format(pName) 2902 2904 rundata += ''' 2903 2905 ENGINE.save() 2904 2906 else: 2905 2907 ENGINE = ENGINE.load(path=engineFileName) 2906 ''' 2907 # if RMCPdict['Swaps']: 2908 # rundata += '#set up for site swaps\n' 2909 # rundata += 'aN = ENGINE.allNames\n' 2910 # rundata += 'SwapGen = {}\n' 2911 # for swap in RMCPdict['Swaps']: 2912 # rundata += 'SwapA = [[idx] for idx in range(len(aN)) if aN[idx]=="%s"]\n'%swap[0] 2913 # rundata += 'SwapB = [[idx] for idx in range(len(aN)) if aN[idx]=="%s"]\n'%swap[1] 2914 # rundata += 'SwapGen["%s-%s"] = [SwapPositionsGenerator(swapList=SwapA),SwapPositionsGenerator(swapList=SwapB),%.2f]\n'%(swap[0],swap[1],swap[2]) 2908 ''' 2909 rundata += 'ENGINE.set_log_file("{}")\n'.format(pName) 2910 if RMCPdict['Swaps']: 2911 rundata += '\n#set up for site swaps\n' 2912 rundata += 'aN = ENGINE.allNames\n' 2913 rundata += 'SwapGen = {}\n' 2914 for swap in RMCPdict['Swaps']: 2915 rundata += 'SwapA = [[idx] for idx in range(len(aN)) if aN[idx]=="%s"]\n'%swap[0] 2916 rundata += 'SwapB = [[idx] for idx in range(len(aN)) if aN[idx]=="%s"]\n'%swap[1] 2917 rundata += 'SwapGen["%s-%s"] = [SwapPositionsGenerator(swapList=SwapA),SwapPositionsGenerator(swapList=SwapB),%.2f]\n'%(swap[0],swap[1],swap[2]) 2918 rundata += ' for swaps in SwapGen:\n' 2919 rundata += ' AB = swaps.split("-")\n' 2920 rundata += ' ENGINE.set_groups_as_atoms()\n' 2921 rundata += ' for g in ENGINE.groups:\n' 2922 rundata += ' if aN[g.indexes[0]]==AB[0]:\n' 2923 rundata += ' g.set_move_generator(SwapGen[swaps][0])\n' 2924 rundata += ' elif aN[g.indexes[0]]==AB[1]:\n' 2925 rundata += ' g.set_move_generator(SwapGen[swaps][1])\n' 2926 rundata += ' sProb = SwapGen[swaps][2]\n' 2915 2927 rundata += '\n# set weights -- do this now so values can be changed without a restart\n' 2916 2928 rundata += 'wtDict = {}\n' … … 2937 2949 if RMCPdict['FitScale']: 2938 2950 rundata += ' c.set_adjust_scale_factor((10, 0.01, 100.))\n' 2951 # torsions difficult to implement, must be internal to cell & named with 2952 # fullrmc atom names 2939 2953 # if len(RMCPdict['Torsions']): # Torsions currently commented out in GUI 2940 2954 # rundata += 'for c in ENGINE.constraints: # look for Dihedral Angle Constraints\n' … … 2947 2961 rundata += '\n# setup runs for fullrmc\n' 2948 2962 2949 rundata += 'for _ in range(%d):\n'%RMCPdict['Cycles'] 2950 if BondList and RMCPdict['Swaps']: rundata += setBondConstraints(' ') 2951 if AngleList and RMCPdict['Swaps']: rundata += setAngleConstraints(' ') 2963 rundata += 'steps = 10000\n' 2964 rundata += 'for _ in range({}):\n'.format(RMCPdict['Cycles']) 2952 2965 rundata += ' ENGINE.set_groups_as_atoms()\n' 2953 rundata += ' ENGINE.run(restartPdb="%s",numberOfSteps=10000, saveFrequency=1000)\n'%restart 2954 if RMCPdict['Swaps']: 2955 if BondList: rundata += setBondConstraints(' ',clear=True) 2956 if AngleList: rundata += setAngleConstraints(' ',clear=True) 2957 rundata += ' for swaps in SwapGen:\n' 2958 rundata += ' AB = swaps.split("-")\n' 2959 rundata += ' ENGINE.set_groups_as_atoms()\n' 2960 rundata += ' for g in ENGINE.groups:\n' 2961 rundata += ' if aN[g.indexes[0]]==AB[0]:\n' 2962 rundata += ' g.set_move_generator(SwapGen[swaps][0])\n' 2963 rundata += ' elif aN[g.indexes[0]]==AB[1]:\n' 2964 rundata += ' g.set_move_generator(SwapGen[swaps][1])\n' 2965 rundata += ' sProb = SwapGen[swaps][2]\n' 2966 rundata += ' ENGINE.run(restartPdb="%s",numberOfSteps=10000*sProb, saveFrequency=1000)\n'%restart 2967 rundata += ' ENGINE.set_groups_as_atoms()\n' 2968 rundata += ' ENGINE.run(restartPdb="%s",numberOfSteps=10000*(1.-sProb), saveFrequency=1000)\n'%restart 2969 #rundata += 'ENGINE.close()\n' 2966 rundata += ' expected = ENGINE.generated+steps\n' 2967 2968 rundata += ' ENGINE.run(restartPdb="%s",numberOfSteps=steps, saveFrequency=1000)\n'%restart 2969 rundata += ' if ENGINE.generated != expected: break # run was stopped\n' 2970 2970 rundata += 'print("ENGINE run time %.2f s"%(time.time()-time0))\n' 2971 2971 rfile = open(rname,'w')
Note: See TracChangeset
for help on using the changeset viewer.