Changeset 3057
- Timestamp:
- Sep 8, 2017 5:56:57 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIconstrGUI.py
r3056 r3057 382 382 varList += [var] 383 383 choices.append([var,hlbl,meaning]) 384 elif page[1] == 'glb' :384 elif page[1] == 'glb' or page[1] == 'sym': 385 385 pass 386 386 else: … … 498 498 return [] 499 499 500 def CheckConstraints(constraintSet): 501 '''Check for errors in a set of constraints. Constraints based on symmetry (etc.) 502 are generated by running :func:`GSASIIstrIO.GetPhaseData`. 503 ''' 504 G2mv.InitVars() 505 constDictList,fixedList,ignored = G2stIO.ProcessConstraints(constraintSet) 506 # generate symmetry constraints to check for conflicts 507 rigidbodyDict = G2frame.GPXtree.GetItemPyData( 508 G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Rigid bodies')) 509 rbIds = rigidbodyDict.get('RBIds',{'Vector':[],'Residue':[]}) 510 rbVary,rbDict = G2stIO.GetRigidBodyModels(rigidbodyDict,Print=False) 511 Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables,MFtables,maxSSwave = G2stIO.GetPhaseData( 512 Phases,RestraintDict=None,rbIds=rbIds,Print=False) # generates atom symmetry constraints 513 return G2mv.CheckConstraints('',constDictList,fixedList) 514 500 515 def CheckAddedConstraint(newcons): 501 516 '''Check a new constraint that has just been input. 502 If there is an error display a message and give the user a 503 choice to keep or discard the last entry (why keep? -- they 504 may want to delete something else or edit multipliers). 517 If there is an error display a message and discard the last entry 518 505 519 Since the varylist is not available, no warning messages 506 should be generated .520 should be generated here 507 521 508 522 :returns: True if constraint should be added 509 523 ''' 510 allcons = []524 allcons1 = [] 511 525 for key in data: 512 526 if key.startswith('_'): continue 513 allcons += data[key] 527 allcons1 += data[key] 528 allcons = allcons1[:] 514 529 allcons += newcons 515 530 if not len(allcons): return True 516 G2mv.InitVars() 517 constDictList,fixedList,ignored = G2stIO.ProcessConstraints(allcons) 518 errmsg, warnmsg = G2mv.CheckConstraints('',constDictList,fixedList) 531 errmsg,warnmsg = CheckConstraints(allcons) 519 532 if errmsg: 520 533 res = G2frame.ErrorDialog('Constraint Error', 521 534 'Error with newly added constraint:\n'+errmsg+ 522 '\n\nDiscard newly added constraint?',parent=G2frame, 523 wtype=wx.YES_NO) 524 return res != wx.ID_YES 535 '\nIgnoring newly added constraint',parent=G2frame) 536 # reset error status 537 errmsg,warnmsg = CheckConstraints(allcons1) 538 if errmsg: 539 print errmsg 540 print G2mv.VarRemapShow([],True) 541 return False 525 542 elif warnmsg: 526 543 print 'Unexpected contraint warning:\n',warnmsg … … 529 546 def CheckChangedConstraint(): 530 547 '''Check all constraints after an edit has been made. 531 If there is an error display a message and give the user a532 choice to keep or discard the last edit. 548 If there is an error display a message and reject the change. 549 533 550 Since the varylist is not available, no warning messages 534 551 should be generated. … … 541 558 allcons += data[key] 542 559 if not len(allcons): return True 543 G2mv.InitVars() 544 constDictList,fixedList,ignored = G2stIO.ProcessConstraints(allcons) 545 errmsg, warnmsg = G2mv.CheckConstraints('',constDictList,fixedList) 560 errmsg,warnmsg = CheckConstraints(allcons) 546 561 if errmsg: 547 562 res = G2frame.ErrorDialog('Constraint Error', 548 563 'Error after editing constraint:\n'+errmsg+ 549 '\n\nDiscard last constraint edit?',parent=G2frame, 550 wtype=wx.YES_NO) 551 return res != wx.ID_YES 564 '\nDiscarding last constraint edit',parent=G2frame) 565 # reset error status 566 errmsg,warnmsg = CheckConstraints(allcons1) 567 if errmsg: 568 print errmsg 569 print G2mv.VarRemapShow([],True) 570 return False 552 571 elif warnmsg: 553 572 print 'Unexpected contraint warning:\n',warnmsg … … 572 591 varList = globalList 573 592 constrDictEnt = 'Global' 593 elif page[1] == "sym": 594 return None,None,None 574 595 else: 575 596 raise Exception,'Should not happen!' … … 584 605 page = G2frame.Page 585 606 vartype,varList,constrDictEnt = PageSelection(page) 607 if vartype is None: return 586 608 title1 = "Hold "+vartype+" variable" 587 609 if not varList: … … 615 637 page = G2frame.Page 616 638 vartype,varList,constrDictEnt = PageSelection(page) 639 if vartype is None: return 617 640 title1 = "Setup equivalent "+vartype+" variables" 618 641 title2 = "Select additional "+vartype+" variable(s) to be equivalent with " … … 628 651 page = G2frame.Page 629 652 vartype,varList,constrDictEnt = PageSelection(page) 653 if vartype is None: return 630 654 title1 = "Setup equivalent atom variables" 631 655 title2 = "Select additional atoms(s) to be equivalent with " … … 641 665 page = G2frame.Page 642 666 vartype,varList,constrDictEnt = PageSelection(page) 667 if vartype is None: return 643 668 title1 = "Setup riding atoms " 644 669 title2 = "Select additional atoms(s) to ride on " … … 654 679 page = G2frame.Page 655 680 vartype,varList,constrDictEnt = PageSelection(page) 681 if vartype is None: return 656 682 title1 = "Setup new variable based on "+vartype+" variables" 657 683 title2 = "Include additional "+vartype+" variable(s) to be included with " … … 667 693 page = G2frame.Page 668 694 vartype,varList,constrDictEnt = PageSelection(page) 695 if vartype is None: return 669 696 title1 = "Setup constraint on "+vartype+" variables" 670 697 title2 = "Select additional "+vartype+" variable(s) to include in constraint with " … … 687 714 l2 = max(l2,len(loc)) 688 715 fmt = "{:"+str(l1)+"s} {:"+str(l2)+"s} {:s}" 689 varListlbl = [fmt.format(i,*G2obj.VarDescr(i)) for i in varList] 716 if constType == 'equivalence': 717 omitVars = G2mv.GetDependentVars() 718 else: 719 omitVars = [] 720 varList = [i for i in varList if i not in omitVars] 721 varListlbl = [fmt.format(i,*G2obj.VarDescr(i)) for i in varList] 690 722 dlg = G2G.G2SingleChoiceDialog(G2frame,'Select 1st variable:', 691 723 title1,varListlbl,monoFont=True,size=(625,400)) 692 724 dlg.CenterOnParent() 693 725 if dlg.ShowModal() == wx.ID_OK: 726 if constType == 'equivalence': 727 omitVars = G2mv.GetDependentVars() + G2mv.GetIndependentVars() 694 728 sel = dlg.GetSelection() 695 729 FrstVarb = varList[sel] 696 730 VarObj = G2obj.G2VarObj(FrstVarb) 697 moreVarb = FindEquivVarb(FrstVarb, varList)731 moreVarb = FindEquivVarb(FrstVarb,[i for i in varList if i not in omitVars]) 698 732 newcons = SelectVarbs(page,VarObj,moreVarb,title2+FrstVarb,constType) 699 733 if len(newcons) > 0: … … 1073 1107 G2G.wxID_CONSHAP, 1074 1108 G2G.wxID_CONSHIST, 1075 G2G.wxID_CONSGLOBAL).index(event.GetId()) 1109 G2G.wxID_CONSGLOBAL, 1110 G2G.wxID_CONSSYM, 1111 ).index(event.GetId()) 1076 1112 G2frame.constr.SetSelection(i) 1077 1113 wx.CallAfter(OnPageChanged,None) … … 1097 1133 G2G.wxID_CONSHAP, 1098 1134 G2G.wxID_CONSHIST, 1099 G2G.wxID_CONSGLOBAL): 1135 G2G.wxID_CONSGLOBAL, 1136 G2G.wxID_CONSSYM, 1137 ): 1100 1138 G2frame.Bind(wx.EVT_MENU, RaisePage,id=id) 1101 1139 … … 1122 1160 allcons += data[key] 1123 1161 if not len(allcons): return 1124 #reload(G2mv) # TODO: for testing 1125 G2mv.InitVars() 1126 constDictList,fixedList,ignored = G2stIO.ProcessConstraints(allcons) 1127 # generate symmetry constraints to check for conflicts 1128 rigidbodyDict = G2frame.GPXtree.GetItemPyData( 1129 G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Rigid bodies')) 1130 rbIds = rigidbodyDict.get('RBIds',{'Vector':[],'Residue':[]}) 1131 rbVary,rbDict = G2stIO.GetRigidBodyModels(rigidbodyDict,Print=False) 1132 Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables,MFtables,maxSSwave = G2stIO.GetPhaseData( 1133 Phases,RestraintDict=None,rbIds=rbIds,Print=False) # generates atom symmetry constraints 1134 errmsg, warnmsg = G2mv.CheckConstraints('',constDictList,fixedList) 1162 errmsg,warnmsg = CheckConstraints(allcons) 1135 1163 if errmsg: 1136 1164 G2frame.ErrorDialog('Constraint Error', -
trunk/GSASIIdataGUI.py
r3046 r3057 4639 4639 4640 4640 # Constraints 4641 G2G.Define_wxId('wxID_CONSTRAINTADD', 'wxID_EQUIVADD', 'wxID_HOLDADD', 'wxID_FUNCTADD', 'wxID_ADDRIDING', 4642 'wxID_CONSPHASE', 'wxID_CONSHIST', 'wxID_CONSHAP', 'wxID_CONSGLOBAL', 'wxID_EQUIVALANCEATOMS',) 4641 G2G.Define_wxId('wxID_CONSTRAINTADD', 'wxID_EQUIVADD', 'wxID_HOLDADD', 'wxID_FUNCTADD', 4642 'wxID_ADDRIDING', 'wxID_CONSPHASE', 'wxID_CONSHIST', 'wxID_CONSHAP', 4643 'wxID_CONSGLOBAL', 'wxID_CONSSYM', 'wxID_EQUIVALANCEATOMS',) 4643 4644 self.ConstraintMenu = wx.MenuBar() 4644 4645 self.PrefillDataMenu(self.ConstraintMenu) … … 4646 4647 self.ConstraintMenu.Append(menu=self.ConstraintTab, title='Select tab') 4647 4648 for id,txt in ( 4648 (G2G.wxID_CONSPHASE,'Phase'), 4649 (G2G.wxID_CONSHAP,'Histogram/Phase'), 4650 (G2G.wxID_CONSHIST,'Histogram'), 4651 (G2G.wxID_CONSGLOBAL,'Global')): 4649 (G2G.wxID_CONSPHASE,'Phase'), 4650 (G2G.wxID_CONSHAP,'Histogram/Phase'), 4651 (G2G.wxID_CONSHIST,'Histogram'), 4652 (G2G.wxID_CONSGLOBAL,'Global'), 4653 (G2G.wxID_CONSSYM,'Sym-Generated'), 4654 ): 4652 4655 self.ConstraintTab.Append(id=id, kind=wx.ITEM_NORMAL,text=txt, 4653 4656 help='Select '+txt+' constraint editing tab') … … 7651 7654 elif G2frame.GPXtree.GetItemText(item) == 'Constraints': 7652 7655 data = G2frame.GPXtree.GetItemPyData(item) 7656 #reload(G2cnstG) # for testing changes to GSASIIconstrGUI 7653 7657 G2cnstG.UpdateConstraints(G2frame,data) 7654 7658 elif G2frame.GPXtree.GetItemText(item) == 'Rigid bodies': -
trunk/GSASIImapvars.py
r3056 r3057 235 235 symGenList = [] # Flag if constraint is generated by symmetry 236 236 problemVars = [] # variables causing errors 237 dependentVars = [] 238 independentVars = [] 237 239 238 240 # prefix for parameter names … … 520 522 errmsg += _FormatConstraint(constrDict[rel],fixedList[rel]) 521 523 errmsg += "\n" 524 _setVarLists([]) 522 525 return errmsg,warnmsg 523 526 … … 765 768 if fixedval: 766 769 fixedDict[fixedval] = float(fixedval) 767 768 # make list of dependent and independent variables (after dropping unused) 770 _setVarLists(dropVarList) 771 772 def _setVarLists(dropVarList): 773 '''Make list of dependent and independent variables (after dropping unused vars in dropVarList) 774 ''' 775 global dependentParmList,indParmList 769 776 global dependentVars 770 777 global independentVars
Note: See TracChangeset
for help on using the changeset viewer.