@@ -5177,8 +5177,9 @@ def showWebtext(txt):
51775177 import tempfile
51785178 import re
51795179 import requests
5180- from exports import G2export_CIF
5180+ from GSASII . exports import G2export_CIF
51815181 from . import ISODISTORT as ISO
5182+ from fractions import Fraction
51825183 isoformsite = 'https://iso.byu.edu/iso/isodistortform.php'
51835184
51845185 if not G2frame .kvecSearch ['mode' ]:
@@ -5476,7 +5477,7 @@ def _get_opt_val(opt_name, out):
54765477
54775478 G2frame .OnFileSave (None )
54785479 orgFilName = G2frame .GSASprojectfile
5479- phsnam = data [ 'General' ][ 'Name' ]
5480+ phsnam = phase_sel
54805481 # get restraints & clear geometrical restraints
54815482 resId = G2gd .GetGPXtreeItemId (G2frame , G2frame .root , 'Restraints' )
54825483 Restraints = G2frame .GPXtree .GetItemPyData (resId )
@@ -5489,6 +5490,39 @@ def _get_opt_val(opt_name, out):
54895490 del Restraints [phsnam ]
54905491 orgData = copy .deepcopy (data )
54915492
5493+ def renamePhaseName (phaseItem ,generalData ,newName ):
5494+ '''Called to rename the phase. Updates the tree and items that
5495+ reference the file name.
5496+ '''
5497+ oldName = generalData ['Name' ]
5498+ phaseRIdList ,usedHistograms = G2frame .GetPhaseInfofromTree ()
5499+ phaseNameList = usedHistograms .keys () # phase names in use
5500+ if newName and newName != oldName :
5501+ newName = G2obj .MakeUniqueLabel (newName ,list (phaseNameList ))
5502+ generalData ['Name' ] = newName
5503+ G2frame .G2plotNB .Rename (oldName ,generalData ['Name' ])
5504+ G2frame .GPXtree .SetItemText (phaseItem ,generalData ['Name' ])
5505+ # change phase name key in Reflection Lists for each histogram
5506+ for hist in data ['Histograms' ]:
5507+ ht = G2gd .GetGPXtreeItemId (G2frame ,G2frame .root ,hist )
5508+ rt = G2gd .GetGPXtreeItemId (G2frame ,ht ,'Reflection Lists' )
5509+ if not rt : continue
5510+ RfList = G2frame .GPXtree .GetItemPyData (rt )
5511+ if oldName not in RfList :
5512+ print ('Warning: ' + oldName + ' not in Reflection List for ' +
5513+ hist )
5514+ continue
5515+ RfList [newName ] = RfList [oldName ]
5516+ del RfList [oldName ]
5517+ # rename Restraints
5518+ resId = G2gd .GetGPXtreeItemId (G2frame ,G2frame .root ,'Restraints' )
5519+ Restraints = G2frame .GPXtree .GetItemPyData (resId )
5520+ i = G2gd .GetGPXtreeItemId (G2frame ,resId ,oldName )
5521+ if i : G2frame .GPXtree .SetItemText (i ,newName )
5522+ if len (Restraints ) and oldName in Restraints :
5523+ Restraints [newName ] = Restraints [oldName ]
5524+ del Restraints [oldName ]
5525+
54925526 for ir_opt , _ in ir_options :
54935527 print ("Processing irrep:" , ir_opt )
54945528 data ["input" ] = "irrep"
@@ -5508,8 +5542,6 @@ def _get_opt_val(opt_name, out):
55085542 iso_fn = _get_opt_val ('isofilename' , out4 ).strip ()
55095543 data ["isofilename" ] = iso_fn
55105544
5511- phsnam = data ['General' ]['Name' ]
5512-
55135545 for radio_val in cleaned_radio_vals :
55145546 print ("Processing mode:" , radio_val )
55155547 data ["input" ] = "distort"
@@ -5526,9 +5558,13 @@ def _get_opt_val(opt_name, out):
55265558 with open (cif_fn , 'wb' ) as fl :
55275559 fl .write (out_cif .encode ("utf-8" ))
55285560
5529- rdlist = G2sc .import_generic (
5530- cif_fn , [CIFpr ()], fmthint = 'CIF'
5531- )
5561+ try :
5562+ rdlist = G2sc .import_generic (
5563+ cif_fn , [CIFpr ()], fmthint = 'CIF'
5564+ )
5565+ except Exception :
5566+ continue
5567+
55325568 rd = rdlist [0 ]
55335569
55345570 key_list = [
@@ -5539,10 +5575,7 @@ def _get_opt_val(opt_name, out):
55395575 data [key ] = rd .Phase [key ]
55405576
55415577 newname = rd .Phase ['General' ]['Name' ]
5542- data ['General' ]['Name' ] = phsnam
5543- G2phsG .renamePhaseName (
5544- G2frame .PickId , data ['General' ], newname
5545- )
5578+ data ['General' ]['Name' ] = newname
55465579
55475580 G2frame .GSASprojectfile = os .path .splitext (
55485581 orgFilName
0 commit comments