Changeset 4822 for trunk/GSASIIconstrGUI.py
- Timestamp:
- Feb 20, 2021 9:43:32 AM (2 years ago)
- File:
-
- 1 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:
Note: See TracChangeset
for help on using the changeset viewer.