Skip to content

Commit 8598d46

Browse files
committed
Add replace phase functionality; comment out Index Cell import cell which seem incomplete
1 parent ddac99d commit 8598d46

File tree

3 files changed

+134
-61
lines changed

3 files changed

+134
-61
lines changed

GSASII/GSASIIdataGUI.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6812,8 +6812,9 @@ def _makemenu(): # routine to create menu when first used
68126812
'Copy selected unit cell from indexing to cell refinement fields')
68136813
self.LoadCell = self.IndexEdit.Append(G2G.wxID_LOADCELL,'Load Phase',
68146814
'Load unit cell from a phase tree entry')
6815-
self.ImportCell = self.IndexEdit.Append(G2G.wxID_IMPORTCELL,'Import Cell',
6816-
'Import unit cell from file')
6815+
# TODO: broken. Needs to be a cascade menu as per ReImportMenuId?
6816+
# self.ImportCell = self.IndexEdit.Append(G2G.wxID_IMPORTCELL,'Import Cell',
6817+
# 'Import unit cell from file')
68176818
self.TransposeCell = self.IndexEdit.Append(G2G.wxID_TRANSFORMCELL,'Transform Cell',
68186819
'Transform unit cell')
68196820
self.RefineCell = self.IndexEdit.Append(G2G.wxID_REFINECELL,'Refine Cell',
@@ -7093,6 +7094,17 @@ def _makemenu(): # routine to create menu when first used
70937094
G2G.Define_wxId('wxID_ISOSRCH')
70947095
self.GeneralCalc.Append(G2G.wxID_ISOSRCH,'ISOCIF Supergroup search','Search for settings of this phase in higher symmetry')
70957096
self.GeneralCalc.Append(G2G.wxID_VALIDPROTEIN,'Protein quality','Protein quality analysis')
7097+
7098+
submenu = wx.Menu()
7099+
self.GeneralCalc.AppendSubMenu(submenu,'Replace phase','Replace phase from file')
7100+
# setup a cascade menu for the formats that have been defined
7101+
self.ReplaceMenuId = {} # points to readers for each menu entry
7102+
for reader in self.parent.GetTopLevelParent().ImportPhaseReaderlist:
7103+
item = submenu.Append(wx.ID_ANY,'Replace phase from '+reader.formatName+' file',reader.longFormatName)
7104+
self.ReplaceMenuId[item.GetId()] = reader
7105+
item = submenu.Append(wx.ID_ANY,'guess format from file','Replace phase, try to determine format from file')
7106+
self.ReplaceMenuId[item.GetId()] = None # try all readers
7107+
70967108
self.PostfillDataMenu()
70977109
#self.DataGeneral = _makemenu
70987110

GSASII/GSASIIphsGUI.py

Lines changed: 91 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

GSASII/GSASIIpwdGUI.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4480,29 +4480,34 @@ def LoadUnitCell(event):
44804480
OnHklShow(None,indexFrom=' Indexing from loaded unit cell & symmetry settings')
44814481
wx.CallAfter(UpdateUnitCellsGrid,G2frame,data)
44824482

4483-
def ImportUnitCell(event):
4484-
controls,bravais,cells,dminx,ssopt = G2frame.GPXtree.GetItemPyData(UnitCellsId)[:5]
4485-
reqrdr = G2frame.dataWindow.ReImportMenuId.get(event.GetId())
4486-
rdlist = G2frame.OnImportGeneric(reqrdr,
4487-
G2frame.ImportPhaseReaderlist,'phase')
4488-
if len(rdlist) == 0: return
4489-
rd = rdlist[0]
4490-
Cell = rd.Phase['General']['Cell']
4491-
SGData = rd.Phase['General']['SGData']
4492-
if '1 1' in SGData['SpGrp']:
4493-
wx.MessageBox('Unusable space group',caption='Monoclinic '+SGData['SpGrp']+' not usable here',style=wx.ICON_EXCLAMATION)
4494-
return
4495-
controls[4] = 1
4496-
controls[5] = (SGData['SGLatt']+SGData['SGLaue']).replace('-','')
4497-
if controls[5][1:] == 'm3': controls[5] += 'm'
4498-
if 'P3' in controls[5] or 'P-3' in controls[5]: controls[5] = 'P6/mmm'
4499-
if 'R' in controls[5]: controls[5] = 'R3-H'
4500-
controls[6:13] = Cell[1:8]
4501-
controls[13] = SGData['SpGrp']
4502-
ssopt['SgResults'] = []
4503-
G2frame.dataWindow.RefineCell.Enable(True)
4504-
OnHklShow(None,indexFrom=' Indexing from imported unit cell & symmetry settings')
4505-
wx.CallAfter(UpdateUnitCellsGrid,G2frame,data)
4483+
# TODO: I think this used to work, but this needs to be revisited due to
4484+
# AttributeError: 'G2DataWindow' object has no attribute 'ReImportMenuId'
4485+
# from:
4486+
# reqrdr = G2frame.dataWindow.ReImportMenuId.get(event.GetId())
4487+
#
4488+
# def ImportUnitCell(event):
4489+
# controls,bravais,cells,dminx,ssopt = G2frame.GPXtree.GetItemPyData(UnitCellsId)[:5]
4490+
# reqrdr = G2frame.dataWindow.ReImportMenuId.get(event.GetId())
4491+
# rdlist = G2frame.OnImportGeneric(reqrdr,
4492+
# G2frame.ImportPhaseReaderlist,'phase')
4493+
# if len(rdlist) == 0: return
4494+
# rd = rdlist[0]
4495+
# Cell = rd.Phase['General']['Cell']
4496+
# SGData = rd.Phase['General']['SGData']
4497+
# if '1 1' in SGData['SpGrp']:
4498+
# wx.MessageBox('Unusable space group',caption='Monoclinic '+SGData['SpGrp']+' not usable here',style=wx.ICON_EXCLAMATION)
4499+
# return
4500+
# controls[4] = 1
4501+
# controls[5] = (SGData['SGLatt']+SGData['SGLaue']).replace('-','')
4502+
# if controls[5][1:] == 'm3': controls[5] += 'm'
4503+
# if 'P3' in controls[5] or 'P-3' in controls[5]: controls[5] = 'P6/mmm'
4504+
# if 'R' in controls[5]: controls[5] = 'R3-H'
4505+
# controls[6:13] = Cell[1:8]
4506+
# controls[13] = SGData['SpGrp']
4507+
# ssopt['SgResults'] = []
4508+
# G2frame.dataWindow.RefineCell.Enable(True)
4509+
# OnHklShow(None,indexFrom=' Indexing from imported unit cell & symmetry settings')
4510+
# wx.CallAfter(UpdateUnitCellsGrid,G2frame,data)
45064511

45074512
def onRefineCell(event):
45084513
data = RefineCell(G2frame)
@@ -6658,7 +6663,7 @@ def OnRefreshKeep(event):
66586663
G2frame.Bind(wx.EVT_MENU, OnNISTLatSym, id=G2G.wxID_NISTLATSYM)
66596664
G2frame.Bind(wx.EVT_MENU, CopyUnitCell, id=G2G.wxID_COPYCELL)
66606665
G2frame.Bind(wx.EVT_MENU, LoadUnitCell, id=G2G.wxID_LOADCELL)
6661-
G2frame.Bind(wx.EVT_MENU, ImportUnitCell, id=G2G.wxID_IMPORTCELL)
6666+
#G2frame.Bind(wx.EVT_MENU, ImportUnitCell, id=G2G.wxID_IMPORTCELL)
66626667
G2frame.Bind(wx.EVT_MENU, TransformUnitCell, id=G2G.wxID_TRANSFORMCELL)
66636668
G2frame.Bind(wx.EVT_MENU, onRefineCell, id=G2G.wxID_REFINECELL)
66646669
G2frame.Bind(wx.EVT_MENU, MakeNewPhase, id=G2G.wxID_MAKENEWPHASE)

0 commit comments

Comments
 (0)