@@ -1696,37 +1696,11 @@ def SetDefaultSSsymbol():
16961696 return '(00g)'
16971697
16981698 def OnPhaseName(event):
1699+ 'called when the phase name is changed in "General"'
16991700 event.Skip()
1700- oldName = generalData['Name']
1701- phaseRIdList,usedHistograms = G2frame.GetPhaseInfofromTree()
1702- phaseNameList = usedHistograms.keys() # phase names in use
17031701 newName = NameTxt.GetValue().strip()
1704- if newName and newName != oldName:
1705- newName = G2obj.MakeUniqueLabel(newName,list(phaseNameList))
1706- generalData['Name'] = newName
1707- G2frame.G2plotNB.Rename(oldName,generalData['Name'])
1708- G2frame.GPXtree.SetItemText(Item,generalData['Name'])
1709- # change phase name key in Reflection Lists for each histogram
1710- for hist in data['Histograms']:
1711- ht = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,hist)
1712- rt = G2gd.GetGPXtreeItemId(G2frame,ht,'Reflection Lists')
1713- if not rt: continue
1714- RfList = G2frame.GPXtree.GetItemPyData(rt)
1715- if oldName not in RfList:
1716- print('Warning: '+oldName+' not in Reflection List for '+
1717- hist)
1718- continue
1719- RfList[newName] = RfList[oldName]
1720- del RfList[oldName]
1721- NameTxt.SetValue(newName)
1722- # rename Restraints
1723- resId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Restraints')
1724- Restraints = G2frame.GPXtree.GetItemPyData(resId)
1725- i = G2gd.GetGPXtreeItemId(G2frame,resId,oldName)
1726- if i: G2frame.GPXtree.SetItemText(i,newName)
1727- if len(Restraints):
1728- Restraints[newName] = Restraints[oldName]
1729- del Restraints[oldName]
1702+ renamePhaseName(Item,generalData,newName)
1703+ NameTxt.SetValue(newName)
17301704
17311705 def OnPhaseType(event):
17321706 if not len(generalData['AtomTypes']): #can change only if no atoms!
@@ -4188,11 +4162,13 @@ def OnApplySubgroups(event):
41884162 resId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Restraints')
41894163 Restraints = G2frame.GPXtree.GetItemPyData(resId)
41904164 resId = G2gd.GetGPXtreeItemId(G2frame,resId,phsnam)
4191- Restraints[phsnam]['Bond']['Bonds'] = []
4192- Restraints[phsnam]['Angle']['Angles'] = []
4193- savedRestraints = Restraints[phsnam]
4165+ savedRestraints = None
4166+ if phsnam in Restraints:
4167+ Restraints[phsnam]['Bond']['Bonds'] = []
4168+ Restraints[phsnam]['Angle']['Angles'] = []
4169+ savedRestraints = Restraints[phsnam]
4170+ del Restraints[phsnam]
41944171 orgData = copy.deepcopy(data)
4195- del Restraints[phsnam]
41964172 for sel in sels:
41974173 data.update(copy.deepcopy(orgData)) # get rid of prev phase
41984174 magchoice = subKeep[sel]
@@ -4248,8 +4224,8 @@ def OnApplySubgroups(event):
42484224 RfList[newName] = []
42494225 if phsnam in RfList:
42504226 del RfList[phsnam]
4251- # copy cleared restraints
4252- Restraints[generalData['Name']] = savedRestraints
4227+ if savedRestraints: # restore cleared restraints
4228+ Restraints[generalData['Name']] = savedRestraints
42534229 if resId: G2frame.GPXtree.SetItemText(resId,newName)
42544230 data.update(newPhase)
42554231 #clear away prev subgroup choices
@@ -5651,7 +5627,52 @@ def OnShowIsoModes(event):
56515627 #imp.reload(G2cnstG)
56525628 G2cnstG.ShowIsoModes(G2frame,data['General']['Name'])
56535629
5630+ def OnReplacePhase(event):
5631+ 'Called to replace the current phase with a new phase from a file'
5632+ reqrdr = G2frame.dataWindow.ReplaceMenuId.get(event.GetId())
5633+ rdlist = G2frame.OnImportGeneric(reqrdr,
5634+ G2frame.ImportPhaseReaderlist,'phase')
5635+ if len(rdlist) == 0: return
5636+ # rdlist is only expected to have one entry
5637+ rd = rdlist[0]
5638+ # Strict = True
5639+ # if 'rmc6f' in rd.readfilename:
5640+ # Strict = False
5641+ # idx = -1
5642+ phsnam = data['General']['Name']
5643+ # clear out stuff that in general should not be
5644+ # transferred from one phase to another
5645+ resId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Restraints')
5646+ Restraints = G2frame.GPXtree.GetItemPyData(resId)
5647+ # resId = G2gd.GetGPXtreeItemId(G2frame,resId,phsnam)
5648+ if phsnam in Restraints:
5649+ del Restraints[phsnam]
5650+ consId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Constraints')
5651+ Constraints = G2frame.GPXtree.GetItemPyData(consId)
5652+ # TODO: would be cleaner to just delete constraints w/phase data['pId']
5653+ Constraints['Phase'] = []
5654+ del data['magPhases']
5655+ data['MCSA'] = {'Models':
5656+ [{'Type': 'MD', 'Coef': [1.0, False, [0.8, 1.2]], 'axis': [0, 0, 1]}],
5657+ 'Results': [], 'AtInfo': {}}
5658+ data['RMC'] = {'RMCProfile': {}, 'fullrmc': {}, 'PDFfit': {}}
5659+ data['ISODISTORT'] = {}
5660+ data['Deformations'] = {}
5661+ # copy over most of the data from the reader object
5662+ # but keep original name, pId & ranId
5663+ for key in ['General', 'Atoms', 'Drawing', 'Histograms', 'Pawley ref', 'RBModels']:
5664+ data[key] = rd.Phase[key]
5665+ # restore existing phase name
5666+ newname = rd.Phase['General']['Name']
5667+ data['General']['Name'] = phsnam
5668+ # rename phase to new name from file
5669+ renamePhaseName(G2frame.PickId, data['General'],newname)
5670+ # force a reload of current tree item
5671+ G2frame.PickIdText = []
5672+ wx.CallAfter(G2gd.SelectDataTreeItem,G2frame,G2frame.PickId)
5673+
56545674 def OnReImport(event):
5675+ 'Called to replace the coordinates with "original" values from a file'
56555676 generalData = data['General']
56565677 cx,ct,cs,cia = generalData['AtomPtrs']
56575678 reqrdr = G2frame.dataWindow.ReImportMenuId.get(event.GetId())
@@ -16698,6 +16719,8 @@ def FillMenus():
1669816719 G2frame.Bind(wx.EVT_MENU, OnUseBilbao, id=G2G.wxID_USEBILBAOMAG)
1669916720 G2frame.Bind(wx.EVT_MENU, OnApplySubgroups, id=G2G.wxID_USEBILBAOSUB)
1670016721 G2frame.Bind(wx.EVT_MENU, OnValidProtein, id=G2G.wxID_VALIDPROTEIN)
16722+ for Id in G2frame.dataWindow.ReplaceMenuId: #loop over submenu items
16723+ G2frame.Bind(wx.EVT_MENU, OnReplacePhase, id=Id)
1670116724 # Data (unless Hist/Phase tree entry shown)
1670216725 if not GSASIIpath.GetConfigValue('SeparateHistPhaseTreeItem',False):
1670316726 FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.DataMenu)
@@ -16904,6 +16927,39 @@ def rbKeyPress(event):
1690416927 G2frame.Raise()
1690516928 return
1690616929
16930+ def renamePhaseName(phaseItem,generalData,newName):
16931+ '''Called to rename the phase. Updates the tree and items that
16932+ reference the file name.
16933+ '''
16934+ oldName = generalData['Name']
16935+ phaseRIdList,usedHistograms = G2frame.GetPhaseInfofromTree()
16936+ phaseNameList = usedHistograms.keys() # phase names in use
16937+ if newName and newName != oldName:
16938+ newName = G2obj.MakeUniqueLabel(newName,list(phaseNameList))
16939+ generalData['Name'] = newName
16940+ G2frame.G2plotNB.Rename(oldName,generalData['Name'])
16941+ G2frame.GPXtree.SetItemText(phaseItem,generalData['Name'])
16942+ # change phase name key in Reflection Lists for each histogram
16943+ for hist in data['Histograms']:
16944+ ht = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,hist)
16945+ rt = G2gd.GetGPXtreeItemId(G2frame,ht,'Reflection Lists')
16946+ if not rt: continue
16947+ RfList = G2frame.GPXtree.GetItemPyData(rt)
16948+ if oldName not in RfList:
16949+ print('Warning: '+oldName+' not in Reflection List for '+
16950+ hist)
16951+ continue
16952+ RfList[newName] = RfList[oldName]
16953+ del RfList[oldName]
16954+ # rename Restraints
16955+ resId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Restraints')
16956+ Restraints = G2frame.GPXtree.GetItemPyData(resId)
16957+ i = G2gd.GetGPXtreeItemId(G2frame,resId,oldName)
16958+ if i: G2frame.GPXtree.SetItemText(i,newName)
16959+ if len(Restraints) and oldName in Restraints:
16960+ Restraints[newName] = Restraints[oldName]
16961+ del Restraints[oldName]
16962+
1690716963 #### UpdatePhaseData execution starts here
1690816964 # make sure that the phase menu bars get created before selecting
1690916965 # any (this will only be true on the first call to UpdatePhaseData)
0 commit comments