Changeset 407
- Timestamp:
- Nov 5, 2011 5:30:24 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIgrid.py
r406 r407 61 61 ] = [wx.NewId() for _init_coll_Sample_Items in range(1)] 62 62 63 [ wxID_CONSTRAINTADD, 64 ] = [wx.NewId() for _init_coll_Constraint_Items in range( 1)]63 [ wxID_CONSTRAINTADD,wxID_EQUIVADD,wxID_HOLDADD, 64 ] = [wx.NewId() for _init_coll_Constraint_Items in range(3)] 65 65 66 66 [ wxID_RESTRAINTADD, … … 156 156 def _init_coll_Constraint_Items(self,parent): 157 157 parent.Append(id=wxID_CONSTRAINTADD, kind=wx.ITEM_NORMAL,text='Add constraint', 158 help='constraint dummy menu item') 158 help='Add constraint on parameter values') 159 parent.Append(id=wxID_EQUIVADD, kind=wx.ITEM_NORMAL,text='Add equivalence', 160 help='Add equivalence between parameter values') 161 parent.Append(id=wxID_HOLDADD, kind=wx.ITEM_NORMAL,text='Add hold', 162 help='Add hold on a parameter value') 159 163 160 164 def _init_coll_Restraint_Items(self,parent): … … 757 761 self.dataDisplay.AutoSizeColumns(True) 758 762 self.dataFrame.setSizePosLeft([700,350]) 759 760 def UpdateConstraints(self,data): 763 764 def UpdateConstraints(self,data): 765 # data.update({'Hist':[],'HAP':[],'Phase':[]}) #empty dict - fill it 761 766 if not data: 762 767 data.update({'Hist':[],'HAP':[],'Phase':[]}) #empty dict - fill it 763 768 Histograms,Phases = self.GetUsedHistogramsAndPhasesfromTree() 764 Natoms,phaseVary,phaseDict,pawleyLookup,FFtable = G2str.GetPhaseData(Phases,Print=False) 769 Natoms,phaseVary,phaseDict,pawleyLookup,FFtable = G2str.GetPhaseData(Phases,Print=False) 770 phaseList = [] 771 for item in phaseDict: 772 if item.split(':')[2] not in ['Ax','Ay','Az','Amul','AI/A','Atype','SHorder']: 773 phaseList.append(item) 774 phaseList.sort() 765 775 hapVary,hapDict,controlDict = G2str.GetHistogramPhaseData(Phases,Histograms,Print=False) 776 hapList = hapDict.keys() 777 hapList.sort() 766 778 histVary,histDict,controlDict = G2str.GetHistogramData(Histograms,Print=False) 779 histList = [] 780 for item in histDict: 781 if item.split(':')[2] not in ['Omega','Type','Chi','Phi','Azimuth','Gonio. radius','Lam1','Lam2']: 782 histList.append(item) 783 histList.sort() 767 784 Indx = {} 768 self.Page = 0 769 785 scope = {} #filled out later 786 self.Page = [0,'phs'] 787 788 def GetPHlegends(Phases,Histograms): 789 plegend = '\n In p::name' 790 hlegend = '\n In :h:name' 791 phlegend = '\n In p:h:name' 792 for phase in Phases: 793 plegend += '\n p:: = '+str(Phases[phase]['pId'])+':: for '+phase 794 for histogram in Phases[phase]['Histograms']: 795 phlegend += '\n p:h: = '+str(Phases[phase]['pId'])+':'+str(Histograms[histogram]['hId'])+': for '+phase+' in '+histogram 796 for histogram in Histograms: 797 hlegend += '\n :h: = :'+str(Histograms[histogram]['hId'])+': for '+histogram 798 return plegend,hlegend,phlegend 799 770 800 def FindEquivVarb(name,nameList): 771 801 outList = [] 802 namelist = [name.split(':')[2],] 803 if 'dA' in name: 804 namelist = ['dAx','dAy','dAz'] 805 elif 'AU' in name: 806 namelist = ['AUiso','AU11','AU22','AU33','AU12','AU13','AU23'] 772 807 for item in nameList: 773 808 key = item.split(':')[2] 774 if key in name and item != name:809 if key in namelist and item != name: 775 810 outList.append(item) 776 811 return outList 777 812 778 def SelectVarbs(FrstVarb,varList,legend ):813 def SelectVarbs(FrstVarb,varList,legend,constType): 779 814 #future - add 'all:all:name', '0:all:name', etc. to the varList 780 815 dlg = wx.MultiChoiceDialog(self,'Select more variables:'+legend,FrstVarb+' and:',varList) … … 786 821 dlg.Destroy() 787 822 if len(varbs) > 1: 788 return map(list,zip([1.0 for i in range(len(varbs))],varbs)) 789 else: 790 return [[0.0,FrstVarb],] #setup for "fix" of variable 791 823 if 'equivalents' in constType: 824 constr = [] 825 for item in varbs[1:]: 826 # constr += [[{FrstVarb:1.0},{item:-1.0},0.0,False],] 827 constr += [[[1.0,FrstVarb],[-1.0,item],None,None],] 828 return constr 829 else: 830 constr = map(list,zip([1.0 for i in range(len(varbs))],varbs)) 831 # constr = map(dict,zip(varbs,[1.0 for i in range(len(varbs))])) 832 return [constr+[0.0,False]] 833 return [] 834 835 def OnAddEquivalence(event): 836 constr = [] 837 page = self.Page 838 choice = scope[page[1]] 839 dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],choice[2]) 840 if dlg.ShowModal() == wx.ID_OK: 841 sel = dlg.GetSelection() 842 FrstVarb = choice[2][sel] 843 moreVarb = FindEquivVarb(FrstVarb,choice[2]) 844 constr = SelectVarbs(FrstVarb,moreVarb,choice[1],'equivalents') 845 if len(constr) > 0: 846 data[choice[3]] += constr 847 dlg.Destroy() 848 choice[4]() 849 850 def OnAddHold(event): 851 for phase in Phases: 852 Phase = Phases[phase] 853 Atoms = Phase['Atoms'] 854 constr = [] 855 page = self.Page 856 choice = scope[page[1]] 857 dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],choice[2]) 858 if dlg.ShowModal() == wx.ID_OK: 859 sel = dlg.GetSelection() 860 FrstVarb = choice[2][sel] 861 data[choice[3]] += [[[0.0,FrstVarb],0.0,False],] 862 dlg.Destroy() 863 choice[4]() 864 792 865 def OnAddConstraint(event): 793 866 constr = [] 794 plegend = '\n In p::name'795 hlegend = '\n In :h:name'796 phlegend = '\n In p:h:name'797 for phase in Phases:798 plegend += '\n p:: = '+str(Phases[phase]['pId'])+':: for '+phase799 for histogram in Phases[phase]['Histograms']:800 phlegend += '\n p:h: = '+str(Phases[phase]['pId'])+':'+str(Histograms[histogram]['hId'])+': for '+phase+' in '+histogram801 for histogram in Histograms:802 hlegend += '\n :h: = :'+str(Histograms[histogram]['hId'])+': for '+histogram803 867 page = self.Page 804 if 'Histogram ' in self.dataDisplay.GetPageText(page): 805 dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+hlegend,'Histogram variables:',histVary) 806 if dlg.ShowModal() == wx.ID_OK: 807 sel = dlg.GetSelection() 808 FrstVarb = histVary[sel] 809 moreVarb = FindEquivVarb(FrstVarb,histVary) 810 constr = SelectVarbs(FrstVarb,moreVarb,hlegend) 811 constr += [0.0,True] #constant & refine flag 812 data['Hist'].append(constr) 813 dlg.Destroy() 814 UpdateHistConstr() 815 elif '/Phase' in self.dataDisplay.GetPageText(page): 816 legend = 'Select 1st variable: \n ' 817 dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+phlegend,'HAP variables:',hapVary) 818 if dlg.ShowModal() == wx.ID_OK: 819 sel = dlg.GetSelection() 820 FrstVarb = hapVary[sel] 821 moreVarb = FindEquivVarb(FrstVarb,hapVary) 822 constr = SelectVarbs(FrstVarb,moreVarb,phlegend) 823 constr += [0.0,True] #constant & refine flag 824 data['HAP'].append(constr) 825 dlg.Destroy() 826 UpdateHAPConstr() 827 elif 'Phase' in self.dataDisplay.GetPageText(page): 828 #maybe get atom name in phaseVary items? 829 for phase in Phases: 830 Phase = Phases[phase] 831 Atoms = Phase['Atoms'] 832 dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+plegend,'Phase variables:',phaseVary) 833 if dlg.ShowModal() == wx.ID_OK: 834 sel = dlg.GetSelection() 835 FrstVarb = phaseVary[sel] 836 moreVarb = FindEquivVarb(FrstVarb,phaseVary) 837 constr = SelectVarbs(FrstVarb,moreVarb,plegend+'\nIf none selected then '+FrstVarb+' is held fixed') 838 constr += [0.0,True] #constant & refine flag 839 data['Phase'].append(constr) 840 dlg.Destroy() 841 UpdatePhaseConstr() 842 868 choice = scope[page[1]] 869 dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],choice[2]) 870 if dlg.ShowModal() == wx.ID_OK: 871 sel = dlg.GetSelection() 872 FrstVarb = choice[2][sel] 873 moreVarb = FindEquivVarb(FrstVarb,choice[2]) 874 constr = SelectVarbs(FrstVarb,moreVarb,choice[1],'') 875 if len(constr) > 0: 876 data[choice[3]] += constr 877 dlg.Destroy() 878 choice[4]() 879 843 880 def ConstSizer(name,pageDisplay): 844 881 constSizer = wx.FlexGridSizer(1,4,0,0) 845 882 for Id,item in enumerate(data[name]): 883 constDel = wx.Button(pageDisplay,-1,'Delete',style=wx.BU_EXACTFIT) 884 constDel.Bind(wx.EVT_BUTTON,OnConstDel) 885 Indx[constDel.GetId()] = [Id,name] 846 886 if len(item) < 4: 847 constSizer.Add((5,0),0) 848 eqString = ' FIXED '+item[0][1] 887 constSizer.Add((5,5),0) 888 constSizer.Add(constDel) 889 eqString = ' FIXED '+item[0][1]+' ' 849 890 constSizer.Add((5,0),0) 850 891 else: … … 853 894 Indx[constEdit.GetId()] = [Id,name] 854 895 constSizer.Add(constEdit) 855 constRef = wx.CheckBox(pageDisplay,-1,label=' Refine?') 856 constRef.SetValue(item[-1]) 857 constRef.Bind(wx.EVT_CHECKBOX,OnConstRef) 858 Indx[constRef.GetId()] = item 859 constSizer.Add(constRef,0,wx.ALIGN_CENTER_VERTICAL) 860 eqString = '' 896 constSizer.Add(constDel) 897 if isinstance(item[-1],bool): 898 constRef = wx.CheckBox(pageDisplay,-1,label=' Refine?') 899 constRef.SetValue(item[-1]) 900 constRef.Bind(wx.EVT_CHECKBOX,OnConstRef) 901 Indx[constRef.GetId()] = item 902 constSizer.Add(constRef,0,wx.ALIGN_CENTER_VERTICAL) 903 eqString = ' CONSTR ' 904 else: 905 constSizer.Add((5,5),0) 906 eqString = ' EQUIV ' 861 907 for term in item[:-2]: 862 908 eqString += '%+.3f*%s '%(term[0],term[1]) 863 eqString += ' = %.3f'%(item[-2]) 909 if isinstance(item[-2],float): 910 eqString += ' = %.3f'%(item[-2])+' ' 911 else: 912 eqString += ' = 0 ' 864 913 constSizer.Add(wx.StaticText(pageDisplay,-1,eqString),0,wx.ALIGN_CENTER_VERTICAL) 865 constDel = wx.Button(pageDisplay,-1,'Delete',style=wx.BU_EXACTFIT)866 constDel.Bind(wx.EVT_BUTTON,OnConstDel)867 Indx[constDel.GetId()] = [Id,name]868 constSizer.Add(constDel)869 914 return constSizer 870 915 … … 877 922 Id,name = Indx[Obj.GetId()] 878 923 del(data[name][Id]) 879 OnPageChanged( event)924 OnPageChanged(None) 880 925 881 926 def OnConstEdit(event): … … 883 928 Id,name = Indx[Obj.GetId()] 884 929 const = data[name][Id][-2] 885 items = data[name][Id][:-2]+[[const,'= constant'],[]] 886 print items 930 if isinstance(data[name][Id][-2],float): 931 items = data[name][Id][:-2]+[[const,'= constant'],[]] 932 else: 933 items = data[name][Id][:-2]+[[],] 887 934 dlg = self.SumDialog(self,'Constraint','Enter value for each term in constraint','',items) 888 935 try: 889 936 if dlg.ShowModal() == wx.ID_OK: 890 937 result = dlg.GetData() 891 print result 892 data[name][Id][:-2] = result[:-1] 893 data[name][Id][-2] = result[-2][0] 938 if isinstance(data[name][Id][-2],float): 939 data[name][Id][:-2] = result[:-2] 940 data[name][Id][-2] = result[-2][0] 941 else: 942 data[name][Id][:-2] = result[:-1] 894 943 finally: 895 944 dlg.Destroy() 896 OnPageChanged(event) 897 945 OnPageChanged(None) 898 946 899 947 def UpdateHAPConstr(): 900 948 HAPConstr.DestroyChildren() 901 pageDisplay = wx.Panel(HAPConstr) 902 mainSizer = wx.BoxSizer(wx.VERTICAL) 903 mainSizer.Add((5,5),0) 904 mainSizer.Add(ConstSizer('HAP',pageDisplay)) 905 pageDisplay.SetSizer(mainSizer) 906 Size = mainSizer.Fit(self.dataFrame) 949 HAPDisplay = wx.Panel(HAPConstr) 950 HAPSizer = wx.BoxSizer(wx.VERTICAL) 951 HAPSizer.Add((5,5),0) 952 HAPSizer.Add(ConstSizer('HAP',HAPDisplay)) 953 HAPSizer.Layout() 954 HAPDisplay.SetSizer(HAPSizer) 955 Size = HAPSizer.Fit(self.dataFrame) 956 Size[0] = max(450,Size[0]) 907 957 Size[1] += 26 #compensate for status bar 908 pageDisplay.SetSize(Size)958 HAPDisplay.SetSize(Size) 909 959 self.dataFrame.setSizePosLeft(Size) 910 960 911 961 def UpdateHistConstr(): 912 962 HistConstr.DestroyChildren() 913 pageDisplay = wx.Panel(HistConstr) 914 mainSizer = wx.BoxSizer(wx.VERTICAL) 915 mainSizer.Add((5,5),0) 916 mainSizer.Add(ConstSizer('Hist',pageDisplay)) 917 pageDisplay.SetSizer(mainSizer) 918 Size = mainSizer.Fit(self.dataFrame) 963 HistDisplay = wx.Panel(HistConstr) 964 HistSizer = wx.BoxSizer(wx.VERTICAL) 965 HistSizer.Add((5,5),0) 966 HistSizer.Add(ConstSizer('Hist',HistDisplay)) 967 HistSizer.Layout() 968 HistDisplay.SetSizer(HistSizer) 969 Size = HistSizer.Fit(self.dataFrame) 970 Size[0] = max(450,Size[0]) 919 971 Size[1] += 26 #compensate for status bar 920 pageDisplay.SetSize(Size)972 HistDisplay.SetSize(Size) 921 973 self.dataFrame.setSizePosLeft(Size) 922 974 923 975 def UpdatePhaseConstr(): 924 976 PhaseConstr.DestroyChildren() 925 pageDisplay = wx.Panel(PhaseConstr) 926 mainSizer = wx.BoxSizer(wx.VERTICAL) 927 mainSizer.Add((5,5),0) 928 mainSizer.Add(ConstSizer('Phase',pageDisplay)) 929 pageDisplay.SetSizer(mainSizer) 930 Size = mainSizer.Fit(self.dataFrame) 977 PhaseDisplay = wx.Panel(PhaseConstr) 978 PhaseSizer = wx.BoxSizer(wx.VERTICAL) 979 PhaseSizer.Add((5,5),0) 980 PhaseSizer.Add(ConstSizer('Phase',PhaseDisplay)) 981 PhaseSizer.Layout() 982 PhaseDisplay.SetSizer(PhaseSizer) 983 Size = PhaseSizer.Fit(self.dataFrame) 931 984 Size[1] += 26 #compensate for status bar 932 pageDisplay.SetSize(Size) 985 Size[0] = max(450,Size[0]) 986 PhaseDisplay.SetSize(Size) 933 987 self.dataFrame.setSizePosLeft(Size) 934 988 935 989 def OnPageChanged(event): 936 page = event.GetSelection() 937 self.Page = page 990 if event: #page change event! 991 page = event.GetSelection() 992 else: 993 page = self.dataDisplay.GetSelection() 994 oldPage = self.dataDisplay.ChangeSelection(page) 938 995 text = self.dataDisplay.GetPageText(page) 939 996 if text == 'Histogram/Phase constraints': 997 self.Page = [page,'hap'] 940 998 UpdateHAPConstr() 941 999 elif text == 'Histogram constraints': 1000 self.Page = [page,'hst'] 942 1001 UpdateHistConstr() 943 1002 elif text == 'Phase constraints': 1003 self.Page = [page,'phs'] 944 1004 UpdatePhaseConstr() 945 1005 1006 def SetStatusLine(text): 1007 Status.SetStatusText(text) 1008 1009 plegend,hlegend,phlegend = GetPHlegends(Phases,Histograms) 1010 scope = {'hst':['Histogram variables:',hlegend,histList,'Hist',UpdateHistConstr], 1011 'hap':['HAP variables:',phlegend,hapList,'HAP',UpdateHAPConstr], 1012 'phs':['Phase variables:',plegend,phaseList,'Phase',UpdatePhaseConstr]} 946 1013 if self.dataDisplay: 947 1014 self.dataDisplay.Destroy() 948 1015 self.dataFrame.SetMenuBar(self.dataFrame.ConstraintMenu) 949 1016 self.dataFrame.SetLabel('Constraints') 950 self.dataFrame.CreateStatusBar() 1017 if not self.dataFrame.GetStatusBar(): 1018 Status = self.dataFrame.CreateStatusBar() 1019 SetStatusLine('NB: Set parameters to be varied first') 1020 951 1021 self.dataFrame.SetMenuBar(self.dataFrame.ConstraintMenu) 952 1022 self.dataFrame.Bind(wx.EVT_MENU, OnAddConstraint, id=wxID_CONSTRAINTADD) 1023 self.dataFrame.Bind(wx.EVT_MENU, OnAddEquivalence, id=wxID_EQUIVADD) 1024 self.dataFrame.Bind(wx.EVT_MENU, OnAddHold, id=wxID_HOLDADD) 953 1025 self.dataDisplay = GSNoteBook(parent=self.dataFrame,size=self.dataFrame.GetClientSize()) 954 1026 -
trunk/GSASIImapvars.py
r342 r407 127 127 128 128 # prefix for parameter names 129 paramPrefix = "::constr "129 paramPrefix = "::constr:" 130 130 consNum = 0 # number of the next constraint to be created 131 131 … … 655 655 ] 656 656 constrDict,constrFlag,fixedList = InputParse(mapList) 657 print constrDict 658 print constrFlag 659 print fixedList 657 660 groups,parmlist = GroupConstraints(constrDict) 658 661 GenerateConstraints(groups,parmlist,constrDict,constrFlag,fixedList) … … 665 668 #print 'parmdict start',parmdict 666 669 before = parmdict.copy() 667 Map2Dict(parmdict )670 Map2Dict(parmdict,[]) 668 671 print 'parmdict before and after Map2Dict' 669 672 print ' key / before / after' -
trunk/GSASIIphsGUI.py
r406 r407 2398 2398 parms = zip(['S11','S22','S33','S12','S13','S23'],UseList[item]['Size'][4], 2399 2399 UseList[item]['Size'][5],range(6)) 2400 dataSizer = wx.FlexGridSizer( 2,6,5,5)2400 dataSizer = wx.FlexGridSizer(1,6,5,5) 2401 2401 for Pa,val,ref,id in parms: 2402 2402 sizeRef = wx.CheckBox(dataDisplay,-1,label=Pa) -
trunk/GSASIIstruct.py
r406 r407 63 63 print ' Minimum delta-M/M for convergence: ','%.2g'%(Controls['min dM/M']) 64 64 print ' Initial shift factor: ','%.3f'%(Controls['shift factor']) 65 66 def GetConstraints(GPXfile): 67 constrList = [] 68 file = open(GPXfile,'rb') 69 while True: 70 try: 71 data = cPickle.load(file) 72 except EOFError: 73 break 74 datum = data[0] 75 if datum[0] == 'Constraints': 76 constDict = datum[1] 77 for item in constDict: 78 constrList += constDict[item] 79 file.close() 80 return constrList 65 81 66 82 def GetPhaseNames(GPXfile): … … 2348 2364 Controls = GetControls(GPXfile) 2349 2365 ShowControls(Controls) 2366 constrList = GetConstraints(GPXfile) 2350 2367 Histograms,Phases = GetUsedHistogramsAndPhases(GPXfile) 2351 2368 if not Phases: … … 2369 2386 parmDict.update(histDict) 2370 2387 GetFprime(calcControls,Histograms) 2388 for item in constrList: print item 2371 2389 constrDict,constrFlag,fixedList = G2mv.InputParse([]) #constraints go here? 2372 2390 groups,parmlist = G2mv.GroupConstraints(constrDict) … … 2456 2474 Controls = GetControls(GPXfile) 2457 2475 ShowControls(Controls) 2476 constrList = GetConstraints(GPXfile) 2458 2477 Histograms,Phases = GetUsedHistogramsAndPhases(GPXfile) 2459 2478 if not Phases:
Note: See TracChangeset
for help on using the changeset viewer.