Changeset 4822
- Timestamp:
- Feb 20, 2021 9:43:32 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIconstrGUI.py
r4812 r4822 353 353 return self.data 354 354 355 ################################################################################ 356 ##### Constraints 357 ################################################################################ 355 ##### Constraints ################################################################################ 358 356 def UpdateConstraints(G2frame,data): 359 357 '''Called when Constraints tree item is selected. … … 655 653 return constDictList,phaseDict,fixedList 656 654 657 def ConstraintsCheck(data,newcons=[] ):655 def ConstraintsCheck(data,newcons=[],reqVaryList=None): 658 656 '''Load constraints & check them for errors. Since error checking 659 657 can cause changes in constraints in case of repairable conflicts … … 661 659 This could probably be done more effectively, but only reloading when 662 660 needed, but the reload should be quick. 661 662 When reqVaryList is included (see WarnConstraintLimit) then 663 parameters with limits are checked against constraints and a 664 warning is shown. 663 665 ''' 664 666 constDictList,phaseDict,fixedList = ConstraintsLoad(data,newcons) … … 669 671 # reload constraints in case any were merged in MoveConfEquiv 670 672 ConstraintsLoad(data,newcons) 673 impossible = [] 674 if reqVaryList: 675 Controls = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls')) 676 for key in ('parmMinDict','parmMaxDict','parmFrozen'): 677 if key not in Controls: Controls[key] = {} 678 varyList = reqVaryList[:] 679 try: 680 G2mv.GenerateConstraints(varyList,constDictList,fixedList,phaseDict) 681 G2mv.Map2Dict(phaseDict,varyList) 682 # check for limits on dependent vars 683 consVars = [i for i in reqVaryList if i not in varyList] 684 impossible = set( 685 [str(i) for i in Controls['parmMinDict'] if i in consVars] + 686 [str(i) for i in Controls['parmMaxDict'] if i in consVars]) 687 except G2mv.ConstraintException: 688 pass 689 if impossible: 690 msg = '' 691 for i in sorted(impossible): 692 if msg: msg += ', ' 693 msg += i 694 msg = ' &'.join(msg.rsplit(',',1)) 695 msg = ('Note: limits on variable(s) '+msg+ 696 ' will be ignored because they are constrained.') 697 G2G.G2MessageBox(G2frame,msg,'Limits ignored for constrained vars') 671 698 return res 672 699 … … 695 722 print ('Unexpected contraint warning:\n'+warnmsg) 696 723 return True 724 725 def WarnConstraintLimit(): 726 '''Check if constraints reference variables with limits. 727 Displays a warning message, but does nothing 728 ''' 729 730 try: 731 parmDict,reqVaryList = G2frame.MakeLSParmDict() 732 errmsg,warnmsg = ConstraintsCheck(data,[],reqVaryList) 733 except: 734 print('Error retrieving parameters') 735 697 736 698 737 def CheckChangedConstraint(): … … 884 923 data[constrDictEnt] += newcons 885 924 dlg.Destroy() 925 WarnConstraintLimit() 886 926 wx.CallAfter(OnPageChanged,None) 887 927 … … 983 1023 if CheckAddedConstraint(newcons): 984 1024 data[constrDictEnt] += newcons 1025 WarnConstraintLimit() 985 1026 wx.CallAfter(OnPageChanged,None) 986 1027 … … 1306 1347 def SetStatusLine(text): 1307 1348 G2frame.GetStatusBar().SetStatusText(text,1) 1308 1309 # UpdateConstraints execution starts here 1349 1350 def OnShowISODISTORT(event): 1351 ShowIsoDistortCalc(G2frame) 1352 1353 #### UpdateConstraints execution starts here ############################## 1310 1354 if not data: 1311 1355 data.update({'Hist':[],'HAP':[],'Phase':[],'Global':[]}) #empty dict - fill it 1312 1356 if 'Global' not in data: #patch 1313 1357 data['Global'] = [] 1314 # DEBUG code # #######################################1358 # DEBUG code #===================================== 1315 1359 #import GSASIIconstrGUI 1316 1360 #reload(GSASIIconstrGUI) … … 1321 1365 #reload(G2mv) 1322 1366 #reload(G2gd) 1323 # ##################################################1367 #=================================================== 1324 1368 Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree() 1325 1369 if not len(Phases) or not len(Histograms): … … 1335 1379 G2frame.dataWindow.ConstraintEdit.Enable(G2G.wxID_SHOWISO,True) 1336 1380 break 1337 ################################################################################## 1338 # patch: convert old-style (str) variables in constraints to G2VarObj objects 1381 ###### patch: convert old-style (str) variables in constraints to G2VarObj objects ##### 1339 1382 for key,value in data.items(): 1340 1383 if key.startswith('_'): continue … … 1348 1391 if j: 1349 1392 print (str(key) + ': '+str(j)+' variable(s) as strings converted to objects') 1350 ##### #############################################################################1393 ##### end patch ############################################################################# 1351 1394 rigidbodyDict = G2frame.GPXtree.GetItemPyData( 1352 1395 G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Rigid bodies')) … … 1426 1469 G2frame.Bind(wx.EVT_MENU, OnAddAtomEquiv, id=G2G.wxID_EQUIVALANCEATOMS) 1427 1470 # G2frame.Bind(wx.EVT_MENU, OnAddRiding, id=G2G.wxID_ADDRIDING) 1428 def OnShowISODISTORT(event):1429 ShowIsoDistortCalc(G2frame)1430 1471 G2frame.Bind(wx.EVT_MENU, OnShowISODISTORT, id=G2G.wxID_SHOWISO) 1431 1472 # tab commands … … 1462 1503 print (errmsg) 1463 1504 print (G2mv.VarRemapShow([],True)) 1505 return 1464 1506 elif warnmsg: 1465 1507 print ('Unexpected contraint warning:\n'+warnmsg) 1508 WarnConstraintLimit() 1466 1509 1467 ################################################################################ 1468 # check scale & phase fractions, create constraint if needed 1469 ################################################################################ 1510 ###### check scale & phase fractions, create constraint if needed ############# 1470 1511 def CheckAllScalePhaseFractions(G2frame): 1471 1512 '''Check if scale factor and all phase fractions are refined without a constraint … … 1527 1568 Constraints['HAP'] += [constr] 1528 1569 1529 ################################################################################ 1530 #### Make nuclear/magnetic phase transition constraints - called by OnTransform in G2phsGUI 1531 ################################################################################ 1532 1570 #### Make nuclear/magnetic phase transition constraints - called by OnTransform in G2phsGUI ########## 1533 1571 def TransConstraints(G2frame,oldPhase,newPhase,Trans,Vec,atCodes): 1534 1572 '''Add constraints for new magnetic phase created via transformation of old … … 1752 1790 constraints['HAP'].append([IndpCon,DepCons,None,None,'e']) 1753 1791 1754 ################################################################################ 1755 #### Rigid bodies 1756 ################################################################################ 1792 #### Rigid bodies ############################################################# 1757 1793 resRBsel = None 1758 1794 def UpdateRigidBodies(G2frame,data): … … 3648 3684 G2frame.GetStatusBar().SetStatusText(text,1) 3649 3685 3650 # ==================UpdateRigidBodies starts here =========3686 #### UpdateRigidBodies starts here ========= 3651 3687 global resList,resRBsel 3652 3688 if not data.get('RBIds') or not data: -
trunk/GSASIIctrlGUI.py
r4819 r4822 4153 4153 self.SetItemCount(0) 4154 4154 4155 self.attr1 = wx.ListItemAttr() 4155 try: 4156 self.attr1 = wx.ItemAttr() 4157 except: 4158 self.attr1 = wx.ListItemAttr() # deprecated in wx4.1 4156 4159 self.attr1.SetBackgroundColour((255,255,150)) 4157 4160 … … 4321 4324 # draw min value widgets 4322 4325 mainSizer.Add((-1,10),0) 4323 n,val = G2obj.prmLookup(name,self.parmWin.Controls['parmMinDict']) # is this a wild-card? 4324 if val is None: 4325 addMbtn = wx.Button(dlg, wx.ID_ANY,'Add Lower limit') 4326 addMbtn.Bind(wx.EVT_BUTTON, AddM) 4327 mainSizer.Add(addMbtn,0) 4328 else: 4329 subSizer = wx.BoxSizer(wx.HORIZONTAL) 4330 subSizer.Add(wx.StaticText(dlg,wx.ID_ANY,'Minimum limit'),0,wx.CENTER) 4331 subSizer.Add(ValidatedTxtCtrl(dlg,self.parmWin.Controls['parmMinDict'],n,nDig=(10,2,'g')),0,WACV) 4332 delMbtn = wx.Button(dlg, wx.ID_ANY,'Delete',style=wx.BU_EXACTFIT) 4333 subSizer.Add((5,-1),0,WACV) 4334 subSizer.Add(delMbtn,0,WACV) 4335 delMbtn.Bind(wx.EVT_BUTTON, delM) 4336 if name.split(':')[1]: # is this using a histogram? 4326 if name not in self.parmWin.varyList and name in self.parmWin.fullVaryList: 4327 mainSizer.Add(wx.StaticText(dlg,wx.ID_ANY,'Limits not allowed on constrained variables'),0) 4328 for key in 'parmMinDict','parmMaxDict': 4329 d = self.parmWin.Controls[key] 4330 n,v = G2obj.prmLookup(name,d) 4331 if v is not None and str(n) == name: 4332 try: # strange hard to reproduce problem with this not working 4333 del d[n] 4334 except: 4335 if GSASIIpath.GetConfigValue('debug'): 4336 print('debug: failed to delete ',name,'in',key) 4337 4338 else: 4339 n,val = G2obj.prmLookup(name,self.parmWin.Controls['parmMinDict']) # is this a wild-card? 4340 if val is None: 4341 addMbtn = wx.Button(dlg, wx.ID_ANY,'Add Lower limit') 4342 addMbtn.Bind(wx.EVT_BUTTON, AddM) 4343 mainSizer.Add(addMbtn,0) 4344 else: 4345 subSizer = wx.BoxSizer(wx.HORIZONTAL) 4346 subSizer.Add(wx.StaticText(dlg,wx.ID_ANY,'Minimum limit'),0,wx.CENTER) 4347 subSizer.Add(ValidatedTxtCtrl(dlg,self.parmWin.Controls['parmMinDict'],n,nDig=(10,2,'g')),0,WACV) 4348 delMbtn = wx.Button(dlg, wx.ID_ANY,'Delete',style=wx.BU_EXACTFIT) 4337 4349 subSizer.Add((5,-1),0,WACV) 4338 wild = wx.CheckBox(dlg,wx.ID_ANY,label='Match all histograms ') 4339 wild.SetValue(str(n).split(':')[1] == '*') 4340 wild.Bind(wx.EVT_CHECKBOX,SetWild) 4341 wild.hist = True 4342 subSizer.Add(wild,0,WACV) 4343 elif len(name.split(':')) > 3: 4350 subSizer.Add(delMbtn,0,WACV) 4351 delMbtn.Bind(wx.EVT_BUTTON, delM) 4352 if name.split(':')[1]: # is this using a histogram? 4353 subSizer.Add((5,-1),0,WACV) 4354 wild = wx.CheckBox(dlg,wx.ID_ANY,label='Match all histograms ') 4355 wild.SetValue(str(n).split(':')[1] == '*') 4356 wild.Bind(wx.EVT_CHECKBOX,SetWild) 4357 wild.hist = True 4358 subSizer.Add(wild,0,WACV) 4359 elif len(name.split(':')) > 3: 4360 subSizer.Add((5,-1),0,WACV) 4361 wild = wx.CheckBox(dlg,wx.ID_ANY,label='Match all atoms ') 4362 wild.SetValue(str(n).split(':')[3] == '*') 4363 wild.Bind(wx.EVT_CHECKBOX,SetWild) 4364 subSizer.Add(wild,0,WACV) 4365 mainSizer.Add(subSizer,0) 4366 # draw max value widgets 4367 mainSizer.Add((-1,10),0) 4368 n,val = G2obj.prmLookup(name,self.parmWin.Controls['parmMaxDict']) # is this a wild-card? 4369 if val is None: 4370 addMbtn = wx.Button(dlg, wx.ID_ANY,'Add Upper limit') 4371 addMbtn.Bind(wx.EVT_BUTTON, AddM) 4372 addMbtn.max = True 4373 mainSizer.Add(addMbtn,0) 4374 else: 4375 subSizer = wx.BoxSizer(wx.HORIZONTAL) 4376 subSizer.Add(wx.StaticText(dlg,wx.ID_ANY,'Maximum limit'),0,wx.CENTER) 4377 subSizer.Add(ValidatedTxtCtrl(dlg,self.parmWin.Controls['parmMaxDict'],n,nDig=(10,2,'g')),0,WACV) 4378 delMbtn = wx.Button(dlg, wx.ID_ANY,'Delete',style=wx.BU_EXACTFIT) 4344 4379 subSizer.Add((5,-1),0,WACV) 4345 wild = wx.CheckBox(dlg,wx.ID_ANY,label='Match all atoms ') 4346 wild.SetValue(str(n).split(':')[3] == '*') 4347 wild.Bind(wx.EVT_CHECKBOX,SetWild) 4348 subSizer.Add(wild,0,WACV) 4349 mainSizer.Add(subSizer,0) 4350 # draw max value widgets 4351 mainSizer.Add((-1,10),0) 4352 n,val = G2obj.prmLookup(name,self.parmWin.Controls['parmMaxDict']) # is this a wild-card? 4353 if val is None: 4354 addMbtn = wx.Button(dlg, wx.ID_ANY,'Add Upper limit') 4355 addMbtn.Bind(wx.EVT_BUTTON, AddM) 4356 addMbtn.max = True 4357 mainSizer.Add(addMbtn,0) 4358 else: 4359 subSizer = wx.BoxSizer(wx.HORIZONTAL) 4360 subSizer.Add(wx.StaticText(dlg,wx.ID_ANY,'Maximum limit'),0,wx.CENTER) 4361 subSizer.Add(ValidatedTxtCtrl(dlg,self.parmWin.Controls['parmMaxDict'],n,nDig=(10,2,'g')),0,WACV) 4362 delMbtn = wx.Button(dlg, wx.ID_ANY,'Delete',style=wx.BU_EXACTFIT) 4363 subSizer.Add((5,-1),0,WACV) 4364 subSizer.Add(delMbtn,0,WACV) 4365 delMbtn.Bind(wx.EVT_BUTTON, delM) 4366 delMbtn.max = True 4367 if name.split(':')[1]: # is this using a histogram? 4368 subSizer.Add((5,-1),0,WACV) 4369 wild = wx.CheckBox(dlg,wx.ID_ANY,label='Match all histograms ') 4370 wild.SetValue(str(n).split(':')[1] == '*') 4371 wild.Bind(wx.EVT_CHECKBOX,SetWild) 4372 wild.max = True 4373 wild.hist = True 4374 subSizer.Add(wild,0,WACV) 4375 elif len(name.split(':')) > 3: 4376 subSizer.Add((5,-1),0,WACV) 4377 wild = wx.CheckBox(dlg,wx.ID_ANY,label='Match all atoms ') 4378 wild.SetValue(str(n).split(':')[3] == '*') 4379 wild.Bind(wx.EVT_CHECKBOX,SetWild) 4380 wild.max = True 4381 subSizer.Add(wild,0,WACV) 4382 mainSizer.Add(subSizer,0) 4380 subSizer.Add(delMbtn,0,WACV) 4381 delMbtn.Bind(wx.EVT_BUTTON, delM) 4382 delMbtn.max = True 4383 if name.split(':')[1]: # is this using a histogram? 4384 subSizer.Add((5,-1),0,WACV) 4385 wild = wx.CheckBox(dlg,wx.ID_ANY,label='Match all histograms ') 4386 wild.SetValue(str(n).split(':')[1] == '*') 4387 wild.Bind(wx.EVT_CHECKBOX,SetWild) 4388 wild.max = True 4389 wild.hist = True 4390 subSizer.Add(wild,0,WACV) 4391 elif len(name.split(':')) > 3: 4392 subSizer.Add((5,-1),0,WACV) 4393 wild = wx.CheckBox(dlg,wx.ID_ANY,label='Match all atoms ') 4394 wild.SetValue(str(n).split(':')[3] == '*') 4395 wild.Bind(wx.EVT_CHECKBOX,SetWild) 4396 wild.max = True 4397 subSizer.Add(wild,0,WACV) 4398 mainSizer.Add(subSizer,0) 4383 4399 4384 4400 btnsizer = wx.StdDialogButtonSizer() -
trunk/GSASIIdataGUI.py
r4819 r4822 5117 5117 if key not in Controls: Controls[key] = {} 5118 5118 wx.EndBusyCursor() 5119 # check for limits on dependent vars 5120 consVars = [i for i in reqVaryList if i not in varyList] 5121 impossible = set( 5122 [str(i) for i in Controls['parmMinDict'] if i in consVars] + 5123 [str(i) for i in Controls['parmMaxDict'] if i in consVars]) 5124 if impossible: 5125 msg = '' 5126 for i in sorted(impossible): 5127 if msg: msg += ', ' 5128 msg += i 5129 msg = ' &'.join(msg.rsplit(',',1)) 5130 msg = ('Note: limits on variable(s) '+msg+ 5131 ' will be ignored because they are constrained.') 5132 G2G.G2MessageBox(self,msg,'Limits ignored for constrained vars') 5119 5133 # debug stuff 5120 5134 #if GSASIIpath.GetConfigValue('debug'): … … 5122 5136 # import imp 5123 5137 # imp.reload(G2G) 5124 # end debug stuff 5138 # end debug stuff 5125 5139 dlg = G2G.ShowLSParms(self,'Least Squares Parameters',parmValDict, 5126 5140 varyList,reqVaryList,Controls) 5141 dlg.CenterOnParent() 5127 5142 dlg.ShowModal() 5128 5143 dlg.Destroy()
Note: See TracChangeset
for help on using the changeset viewer.