3939from . import G2shapes
4040from . import SUBGROUPS as kSUB
4141from . import k_vector_search as kvs
42+ from GSASII .imports .G2phase_CIF import CIFPhaseReader as CIFpr
43+ from . import GSASIIscriptable as G2sc
44+ from . import GSASIImiscGUI as G2IO
4245try :
4346 VERY_LIGHT_GREY = wx .SystemSettings .GetColour (wx .SYS_COLOUR_BTNFACE )
4447 WACV = wx .ALIGN_CENTER_VERTICAL
@@ -5467,19 +5470,19 @@ def _get_opt_val(opt_name, out):
54675470
54685471 G2frame .OnFileSave (None )
54695472 orgFilName = G2frame .GSASprojectfile
5470- phsnam = phase_sel
5473+ phsnam = data ['General' ]['Name' ]
5474+ # get restraints & clear geometrical restraints
54715475 resId = G2gd .GetGPXtreeItemId (G2frame , G2frame .root , 'Restraints' )
54725476 Restraints = G2frame .GPXtree .GetItemPyData (resId )
54735477 resId = G2gd .GetGPXtreeItemId (G2frame , resId , phsnam )
5478+ savedRestraints = None
5479+ if phsnam in Restraints :
5480+ Restraints [phsnam ]['Bond' ]['Bonds' ] = []
5481+ Restraints [phsnam ]['Angle' ]['Angles' ] = []
5482+ savedRestraints = Restraints [phsnam ]
5483+ del Restraints [phsnam ]
54745484 orgData = copy .deepcopy (data )
54755485
5476- item , cookie = G2frame .GPXtree .GetFirstChild (phaseID )
5477- while item and G2frame .GPXtree .GetItemText (item ) != phase_sel :
5478- item , cookie = G2frame .GPXtree .GetNextChild (phaseID , cookie )
5479-
5480- # TODO: We can probably refer to the `OnDeletePhase` method defined in
5481- # `GSASIIdataGUI` to delete the phase.
5482-
54835486 for ir_opt , _ in ir_options :
54845487 print ("Processing irrep:" , ir_opt )
54855488 data ["input" ] = "irrep"
@@ -5499,6 +5502,8 @@ def _get_opt_val(opt_name, out):
54995502 iso_fn = _get_opt_val ('isofilename' , out4 ).strip ()
55005503 data ["isofilename" ] = iso_fn
55015504
5505+ phsnam = data ['General' ]['Name' ]
5506+
55025507 for radio_val in cleaned_radio_vals :
55035508 print ("Processing mode:" , radio_val )
55045509 data ["input" ] = "distort"
@@ -5515,11 +5520,28 @@ def _get_opt_val(opt_name, out):
55155520 with open (cif_fn , 'wb' ) as fl :
55165521 fl .write (out_cif .encode ("utf-8" ))
55175522
5518- # TODO: Load phase to the project and associate it with the
5519- # histogram attached to the original phase.
5520- # Q1: How to find out all the histograms associated with the
5521- # original phase?
5522- # Q2: How to load the phase to the project properly?
5523+ rdlist = G2sc .import_generic (
5524+ cif_fn , [CIFpr ()], fmthint = 'CIF'
5525+ )
5526+ rd = rdlist [0 ]
5527+
5528+ key_list = [
5529+ 'General' , 'Atoms' , 'Drawing' ,
5530+ 'Histograms' , 'Pawley ref' , 'RBModels'
5531+ ]
5532+ for key in key_list :
5533+ data [key ] = rd .Phase [key ]
5534+
5535+ newname = rd .Phase ['General' ]['Name' ]
5536+ data ['General' ]['Name' ] = phsnam
5537+ G2phsG .renamePhaseName (
5538+ G2frame .PickId , data ['General' ], newname
5539+ )
5540+
5541+ G2frame .GSASprojectfile = os .path .splitext (
5542+ orgFilName
5543+ )[0 ] + '_' f"{ phase_nam } _{ cif_fn_part1 } _{ cif_fn_part2 } .gpx"
5544+ G2IO .ProjFileSave (G2frame )
55235545
55245546 # restore the original saved project
55255547 G2frame .OnFileOpen (None , filename = orgFilName , askSave = False )
0 commit comments