Skip to content

Commit 7bec472

Browse files
committed
get phase tree item so that phase gets renamed ; misc cleanup
1 parent f7b8c0e commit 7bec472

2 files changed

Lines changed: 99 additions & 107 deletions

File tree

GSASII/GSASIIphsGUI.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ def OnPhaseName(event):
17021702
'called when the phase name is changed in "General"'
17031703
event.Skip()
17041704
newName = NameTxt.GetValue().strip()
1705-
renamePhaseNameTop(G2frame,data,Item,generalData,newName)
1705+
renamePhaseName(G2frame,data,Item,generalData,newName)
17061706
NameTxt.SetValue(newName)
17071707

17081708
def OnPhaseType(event):
@@ -5706,7 +5706,7 @@ def OnReplacePhase(event):
57065706
newname = rd.Phase['General']['Name']
57075707
data['General']['Name'] = phsnam
57085708
# rename phase to new name from file
5709-
renamePhaseNameTop(G2frame,data,G2frame.PickId, data['General'],newname)
5709+
renamePhaseName(G2frame,data,G2frame.PickId, data['General'],newname)
57105710
# force a reload of current tree item
57115711
G2frame.PickIdText = []
57125712
wx.CallAfter(G2gd.SelectDataTreeItem,G2frame,G2frame.PickId)
@@ -17368,7 +17368,7 @@ def saveIsoNewPhase(G2frame,phData,newPhase,orgFilName):
1736817368
G2IO.ProjFileSave(G2frame)
1736917369
return G2frame.GSASprojectfile
1737017370

17371-
def renamePhaseNameTop(G2frame,data,phaseItem,generalData,newName):
17371+
def renamePhaseName(G2frame,data,phaseItem,generalData,newName):
1737217372
'''Called to rename the phase. Updates the tree and items that
1737317373
reference the file name.
1737417374
'''

GSASII/GSASIIpwdGUI.py

Lines changed: 96 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -5174,104 +5174,12 @@ def showWebtext(txt):
51745174
fileList.append(tmp.name)
51755175
G2G.ShowWebPage('file://'+tmp.name,G2frame)
51765176

5177-
import tempfile
5178-
import re
5179-
import requests
5180-
from GSASII.exports import G2export_CIF
5181-
from . import ISODISTORT as ISO
5182-
from fractions import Fraction
5183-
isoformsite = 'https://iso.byu.edu/iso/isodistortform.php'
5184-
5185-
if not G2frame.kvecSearch['mode']:
5186-
return
5187-
5188-
k_table = G2frame.GPXtree.GetItemPyData(UnitCellsId)
5189-
k_cells, _ = k_table[2:4]
5190-
kpoint = None
5191-
for row in range(len(k_cells)):
5192-
if UnitCellsTable.GetValue(row, 0):
5193-
kpoint = cells[row][3:6]
5194-
break
5195-
5196-
if kpoint is None:
5197-
wx.MessageBox(
5198-
"Please select a k-vector from the table.",
5199-
style=wx.ICON_INFORMATION,
5200-
caption='Isotropic Subgroup Generation'
5201-
)
5202-
5203-
return
5204-
5205-
#isoscript='isocifform.php'
5206-
isoCite = '''For use of this please cite
5207-
H. T. Stokes, D. M. Hatch, and B. J. Campbell, ISODISTORT, ISOTROPY
5208-
Software Suite, iso.byu.edu. B. J. Campbell, H. T. Stokes,
5209-
D. E. Tanner, and D. M. Hatch, "ISODISPLACE: An Internet Tool for
5210-
Exploring Structural Distortions." J. Appl. Cryst.
5211-
39, 607-614 (2006).
5212-
'''
5213-
info_str = '''CIF files of the isotropic subgroups associated with the
5214-
selected k-vector will be created.
5215-
Generated CIF files will be saved in the same directory as the
5216-
current project file.
5217-
This can take up to a few minutes. Check the terminal for progress.
5218-
'''
5219-
wx.MessageBox(
5220-
f"{isoCite}\n\n{info_str}",
5221-
style=wx.ICON_INFORMATION,
5222-
caption='Isotropic Subgroup Generation'
5223-
)
5224-
5225-
wx.GetApp().Yield()
5226-
5227-
info_msg = "Processing IRREPs for the selected k-vector. "
5228-
info_msg += "This can take up to a few minutes."
5229-
print(info_msg)
5230-
5231-
phaseID = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Phases')
5232-
phase_nam = G2frame.kvecSearch['phase']
5233-
Phase = G2frame.GPXtree.GetItemPyData(
5234-
G2gd.GetGPXtreeItemId(
5235-
G2frame, phaseID, phase_nam
5236-
)
5237-
)
5238-
# data = Phase
5239-
#oacomp,occomp = G2mth.phaseContents(data)
5240-
#ophsnam = data['General']['Name']
5241-
fileList = []
5242-
# write a CIF as a scratch file
5243-
obj = G2export_CIF.ExportPhaseCIF(G2frame)
5244-
obj.InitExport(None)
5245-
obj.currentExportType='phase'
5246-
obj.loadTree()
5247-
tmp = tempfile.NamedTemporaryFile(suffix='.cif', delete=False)
5248-
obj.dirname,obj.filename = os.path.split(tmp.name)
5249-
obj.phasenam = Phase['General']['Name']
5250-
obj.Writer('', Phase['General']['Name'])
5251-
parentcif = tmp.name
5252-
ISOparentcif = ISO.UploadCIF(parentcif)
5253-
up2 = {'filename': ISOparentcif, 'input': 'uploadparentcif'}
5254-
out2 = requests.post(isoformsite, up2).text
5255-
try:
5256-
pos = out2.index('<p><FORM')
5257-
except ValueError:
5258-
ISO.HandleError(out2)
5259-
return [], []
5260-
data = {}
5261-
while True:
5262-
try:
5263-
posB = out2[pos:].index('INPUT TYPE') + pos
5264-
posF = out2[posB:].index('>') + posB
5265-
items = out2[posB:posF].split('=',3)
5266-
name = items[2].split()[0].replace('"', '')
5267-
if 'isosystem' in name:
5268-
break
5269-
vals = items[3].replace('"', '')
5270-
data[name] = vals
5271-
pos = posF
5272-
except ValueError:
5273-
break
5177+
def _get_opt_val(opt_name, out):
5178+
opt_pattern = rf'NAME="{opt_name}" VALUE="(.*?)"'
5179+
opt_match = re.search(opt_pattern, out)
52745180

5181+
return opt_match.group(1)
5182+
52755183
def setup_kvec_input(k_vec):
52765184
"""Set up the input for isodistort post request
52775185
@@ -5382,6 +5290,95 @@ def match_vector_pattern(k_vec, k_vec_dict):
53825290

53835291
return data_update
53845292

5293+
# start of OnISODISTORT_kvec computations
5294+
import tempfile
5295+
import re
5296+
import requests
5297+
from fractions import Fraction
5298+
from GSASII.exports import G2export_CIF
5299+
from . import ISODISTORT as ISO
5300+
isoformsite = 'https://iso.byu.edu/iso/isodistortform.php'
5301+
5302+
if not G2frame.kvecSearch['mode']:
5303+
return
5304+
5305+
k_table = G2frame.GPXtree.GetItemPyData(UnitCellsId)
5306+
k_cells, _ = k_table[2:4]
5307+
kpoint = None
5308+
for row in range(len(k_cells)):
5309+
if UnitCellsTable.GetValue(row, 0):
5310+
kpoint = cells[row][3:6]
5311+
break
5312+
5313+
if kpoint is None:
5314+
wx.MessageBox(
5315+
"Please select a k-vector from the table.",
5316+
style=wx.ICON_INFORMATION,
5317+
caption='Isotropic Subgroup Generation'
5318+
)
5319+
5320+
return
5321+
5322+
isoCite = G2G.GetCite('ISOTROPY, ISODISTORT, ISOCIF...',wrap=60,indent=5) # reuse saved citation
5323+
5324+
info_str = '''CIF files of the isotropic subgroups associated with the
5325+
selected k-vector will be created.
5326+
Generated CIF files will be saved in the same directory as the
5327+
current project file.
5328+
This can take up to a few minutes. Check the terminal for progress.
5329+
'''
5330+
wx.MessageBox(
5331+
f"{isoCite}\n\n{info_str}",
5332+
style=wx.ICON_INFORMATION,
5333+
caption='Isotropic Subgroup Generation'
5334+
)
5335+
5336+
wx.GetApp().Yield()
5337+
5338+
info_msg = "Processing IRREPs for the selected k-vector. "
5339+
info_msg += "This can take up to a few minutes."
5340+
print(info_msg)
5341+
5342+
# find tree item for current phase
5343+
phaseID = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Phases')
5344+
phase_nam = G2frame.kvecSearch['phase']
5345+
phaseTreeId = G2gd.GetGPXtreeItemId(G2frame, phaseID, phase_nam) # save reference
5346+
Phase = G2frame.GPXtree.GetItemPyData(phaseTreeId)
5347+
fileList = []
5348+
# write a CIF as a scratch file
5349+
obj = G2export_CIF.ExportPhaseCIF(G2frame)
5350+
obj.InitExport(None)
5351+
obj.currentExportType='phase'
5352+
obj.loadTree()
5353+
tmp = tempfile.NamedTemporaryFile(suffix='.cif', delete=False)
5354+
obj.dirname,obj.filename = os.path.split(tmp.name)
5355+
obj.phasenam = Phase['General']['Name']
5356+
obj.Writer('', Phase['General']['Name'])
5357+
parentcif = tmp.name
5358+
ISOparentcif = ISO.UploadCIF(parentcif)
5359+
up2 = {'filename': ISOparentcif, 'input': 'uploadparentcif'}
5360+
out2 = requests.post(isoformsite, up2).text
5361+
try:
5362+
pos = out2.index('<p><FORM')
5363+
except ValueError:
5364+
ISO.HandleError(out2)
5365+
return [], []
5366+
data = {}
5367+
while True:
5368+
try:
5369+
posB = out2[pos:].index('INPUT TYPE') + pos
5370+
posF = out2[posB:].index('>') + posB
5371+
items = out2[posB:posF].split('=',3)
5372+
name = items[2].split()[0].replace('"', '')
5373+
if 'isosystem' in name:
5374+
break
5375+
vals = items[3].replace('"', '')
5376+
data[name] = vals
5377+
pos = posF
5378+
except ValueError:
5379+
break
5380+
5381+
53855382
# The following chunk of code is for converting the k-vector from the
53865383
# conventional setting to the primitive setting.
53875384
phase_sel = G2frame.kvecSearch['phase']
@@ -5453,12 +5450,6 @@ def match_vector_pattern(k_vec, k_vec_dict):
54535450
ISO.HandleError(out3)
54545451
return [],[]
54555452

5456-
def _get_opt_val(opt_name, out):
5457-
opt_pattern = rf'NAME="{opt_name}" VALUE="(.*?)"'
5458-
opt_match = re.search(opt_pattern, out)
5459-
5460-
return opt_match.group(1)
5461-
54625453
kvec1 = _get_opt_val('kvec1', out3)
54635454
kvecnumber1 = _get_opt_val('kvecnumber1', out3)
54645455
kparam1 = _get_opt_val('kparam1', out3)
@@ -5544,7 +5535,8 @@ def _get_opt_val(opt_name, out):
55445535
newname = rd.Phase['General']['Name']
55455536
Phase['General']['Name'] = newname
55465537

5547-
G2phsG.renamePhaseNameTop(G2frame,Phase,G2frame.PickId,Phase['General'],newname)
5538+
# rename the phase in the data tree
5539+
G2phsG.renamePhaseName(G2frame,Phase,phaseTreeId,Phase['General'],newname)
55485540

55495541
G2frame.GSASprojectfile = os.path.splitext(
55505542
orgFilName

0 commit comments

Comments
 (0)