Changeset 3474 for trunk/GSASIIphsGUI.py


Ignore:
Timestamp:
Jul 16, 2018 4:07:12 PM (5 years ago)
Author:
vondreele
Message:

remove wx.Validator_IsSilent(): wx.Bell() from 2 places in G2ctrlGUI; doesn't exist in phoenix & not really needed.
add check of atom types for GetUnique? in G2lattice for transform of unit cell contents
modify OnTransform? & TransformDialog? to allow cancel & retry before committing to a new phase

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIphsGUI.py

    r3466 r3474  
    282282    #NB: commonNames & commonTrans defined in GSASIIdataGUI = G2gd
    283283    '''
    284     def __init__(self,parent,phase):
     284    def __init__(self,parent,phase,Trans=np.eye(3),Uvec=np.zeros(3),Vvec=np.zeros(3),ifMag=False,newSpGrp='',BNSlatt=''):
    285285        wx.Dialog.__init__(self,parent,wx.ID_ANY,'Setup phase transformation',
    286286            pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE)
     
    292292#            self.Vec = np.zeros(4)
    293293#        else:
    294         self.Trans = np.eye(3)
    295         self.Uvec = np.zeros(3)
    296         self.Vvec = np.zeros(3)
     294        self.Trans = Trans
     295        self.Uvec = Uvec
     296        self.Vvec = Vvec
    297297        self.oldSpGrp = phase['General']['SGData']['SpGrp']
    298298        self.oldSGdata = phase['General']['SGData']
    299         self.newSpGrp = self.Phase['General']['SGData']['SpGrp']
     299        if newSpGrp:
     300            self.newSpGrp = newSpGrp
     301        else:
     302            self.newSpGrp = self.Phase['General']['SGData']['SpGrp']
    300303        self.oldCell = phase['General']['Cell'][1:8]
    301304        self.newCell = self.Phase['General']['Cell'][1:8]
    302305        self.Common = 'abc'
    303         self.ifMag = False
     306        self.ifMag = ifMag
     307        if ifMag:
     308            self.BNSlatt = BNSlatt
    304309        self.ifConstr = True
     310        self.Mtrans = False
    305311        self.Draw()
    306312
     
    310316            Obj = event.GetEventObject()
    311317            self.Common = Obj.GetValue()
     318            self.Mtrans = False
    312319            if '*' in self.Common:
    313320                A,B = G2lat.cell2AB(self.oldCell[:6])
     
    366373
    367374        def OnTest(event):
    368             self.newCell = G2lat.TransformCell(self.oldCell[:6],self.Trans)
     375            if self.Mtrans:
     376                self.newCell = G2lat.TransformCell(self.oldCell[:6],self.Trans.T)
     377            else:
     378                self.newCell = G2lat.TransformCell(self.oldCell[:6],self.Trans)
    369379            wx.CallAfter(self.Draw)
    370380           
     
    386396            self.Trans = G2spc.ApplyBNSlatt(SGData,SGData['BNSlattsym'])
    387397            wx.CallAfter(self.Draw)
     398           
     399        def OnMtrans(event):
     400            Obj = event.GetEventObject()
     401            self.Mtrans = Obj.GetValue()
    388402
    389403        SGData = self.Phase['General']['SGData']
     
    391405        self.panel = wx.Panel(self)
    392406        mainSizer = wx.BoxSizer(wx.VERTICAL)
     407        if self.ifMag:
     408            if self.BNSlatt != SGData['SGLatt']:
     409                GenSym,GenFlg,BNSsym = G2spc.GetGenSym(SGData)
     410                SGData['BNSlattsym'] = [self.BNSlatt,BNSsym[self.BNSlatt]]
     411                SGData['SGSpin'] = [1,]*len(SGData['SGSpin'])
     412        else:
     413            mag = wx.Button(self.panel,label='Make new phase magnetic?')
     414            mag.Bind(wx.EVT_BUTTON,OnMag)
     415            mainSizer.Add(mag,0,WACV)           
    393416        MatSizer = wx.BoxSizer(wx.HORIZONTAL)
    394417        transSizer = wx.BoxSizer(wx.VERTICAL)
     
    431454        MatSizer.Add(transSizer)
    432455        mainSizer.Add(MatSizer)
     456        if self.ifMag:
     457            Mtrans = wx.CheckBox(self.panel,label=' M from Bilbao routine MAXMAGN? Use transform')
     458            Mtrans.SetValue(self.Mtrans)
     459            Mtrans.Bind(wx.EVT_CHECKBOX,OnMtrans)
     460            mainSizer.Add(Mtrans,0,WACV)
    433461        mainSizer.Add(wx.StaticText(self.panel,label=' Old lattice parameters:'),0,WACV)
    434462        mainSizer.Add(wx.StaticText(self.panel,label=
     
    444472        mainSizer.Add(wx.StaticText(self.panel,label=' volume = %.3f'%(self.newCell[6])),0,WACV)
    445473        sgSizer = wx.BoxSizer(wx.HORIZONTAL)
    446         sgSizer.Add(wx.StaticText(self.panel,label='  Space group: '),0,WACV)
     474        sgSizer.Add(wx.StaticText(self.panel,label=' Target space group: '),0,WACV)
    447475        SGTxt = wx.Button(self.panel,wx.ID_ANY,self.newSpGrp,size=(100,-1))
    448476        SGTxt.Bind(wx.EVT_BUTTON,OnSpaceGroup)
     
    460488                BNSizer.Add(BNS,0,WACV)
    461489                mainSizer.Add(BNSizer,0,WACV)
    462             else:
    463                 mag = wx.Button(self.panel,label='Make new phase magnetic?')
    464                 mag.Bind(wx.EVT_BUTTON,OnMag)
    465                 mainSizer.Add(mag,0,WACV)
    466             mainSizer.Add(wx.StaticText(self.panel, \
    467                 label=' NB: Nonmagnetic atoms will be deleted from new phase'),0,WACV)
     490                mainSizer.Add(wx.StaticText(self.panel, \
     491                    label=' NB: Nonmagnetic atoms will be deleted from new phase'),0,WACV)
    468492            constr = wx.CheckBox(self.panel,label=' Make constraints between phases?')
    469 #            mainSizer.Add(wx.StaticText(self.panel, \
    470 #                label=' Constraints not correct for non-diagonal transforms'),0,WACV)
    471493            constr.SetValue(self.ifConstr)
    472494            constr.Bind(wx.EVT_CHECKBOX,OnConstr)
     
    497519        else:
    498520            self.Phase['General']['Name'] += ' %s'%(self.Common)
    499         self.Phase['General']['Cell'][1:] = G2lat.TransformCell(self.oldCell[:6],self.Trans)           
    500         return self.Phase,self.Trans,self.Uvec,self.Vvec,self.ifMag,self.ifConstr,self.Common
     521        if self.Mtrans:
     522            self.Phase['General']['Cell'][1:] = G2lat.TransformCell(self.oldCell[:6],self.Trans.T)           
     523            return self.Phase,self.Trans.T,self.Uvec,self.Vvec,self.ifMag,self.ifConstr,self.Common
     524        else:
     525            self.Phase['General']['Cell'][1:] = G2lat.TransformCell(self.oldCell[:6],self.Trans)           
     526            return self.Phase,self.Trans,self.Uvec,self.Vvec,self.ifMag,self.ifConstr,self.Common
    501527
    502528    def OnOk(self,event):
     
    550576        OkBtn = wx.Button(self.panel,-1,"Ok")
    551577        OkBtn.Bind(wx.EVT_BUTTON, self.OnOk)
    552         cancelBtn = wx.Button(self.panel,-1,"Use All")
     578        cancelBtn = wx.Button(self.panel,-1,"Cancel")
    553579        cancelBtn.Bind(wx.EVT_BUTTON, self.OnCancel)
    554580        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
     
    10021028            Flds = dlg.GetValue().split()
    10031029            for fld in Flds: fld = fld.strip()
    1004             SpcGp = ' '.join(Flds)
     1030            SpcGp = ' '.join(Flds).capitalize()
    10051031        finally:
    10061032            dlg.Destroy()
     
    22942320       
    22952321    def OnTransform(event):
    2296         dlg = TransformDialog(G2frame,data)
    2297         try:
    2298             if dlg.ShowModal() == wx.ID_OK:
    2299                 newPhase,Trans,Uvec,Vvec,ifMag,ifConstr,Common = dlg.GetSelection()
     2322        Trans = np.eye(3)
     2323        Uvec = np.zeros(3)
     2324        Vvec = np.zeros(3)
     2325        ifMag = False
     2326        newSpGrp = ''
     2327        BNSlatt = ''
     2328        while True:
     2329            dlg = TransformDialog(G2frame,data,Trans,Uvec,Vvec,ifMag,newSpGrp,BNSlatt)
     2330            try:
     2331                if dlg.ShowModal() == wx.ID_OK:
     2332                    newPhase,Trans,Uvec,Vvec,ifMag,ifConstr,Common = dlg.GetSelection()
     2333                    newSpGrp = newPhase['General']['SGData']['SpGrp']
     2334                    if ifMag:
     2335                        BNSlatt = newPhase['General']['SGData']['BNSlattsym'][0]
     2336                else:
     2337                    return
     2338            finally:
     2339                dlg.Destroy()
     2340            if 'setting' in Common:         #don't make new phase, Just move atoms!
     2341                generalData = data['General']
     2342                cx,ct,cs,cia = generalData['AtomPtrs']
     2343                SGData = generalData['SGData']
     2344                if SGData['SpGrp'] in G2spc.spg2origins:
     2345                    T = G2spc.spg2origins[SGData['SpGrp']]
     2346                Atoms = data['Atoms']
     2347                for atom in Atoms:
     2348                    for i in [0,1,2]:
     2349                        atom[cx+i] += T[i]
     2350                data['Drawing'] = []
     2351                break
    23002352            else:
    2301                 return
    2302         finally:
    2303             dlg.Destroy()
    2304         if 'setting' in Common:         #don't make new phase, Just move atoms!
    2305             generalData = data['General']
    2306             cx,ct,cs,cia = generalData['AtomPtrs']
    2307             SGData = generalData['SGData']
    2308             if SGData['SpGrp'] in G2spc.spg2origins:
    2309                 T = G2spc.spg2origins[SGData['SpGrp']]
    2310             Atoms = data['Atoms']
    2311             for atom in Atoms:
    2312                 for i in [0,1,2]:
    2313                     atom[cx+i] += T[i]
    2314             data['Drawing'] = []
    2315         else:
    2316             phaseName = newPhase['General']['Name']
    2317             newPhase,atCodes = G2lat.TransformPhase(data,newPhase,Trans,Uvec,Vvec,ifMag)
    2318             detTrans = np.abs(nl.det(Trans))
    2319    
    2320             generalData = newPhase['General']
    2321             SGData = generalData['SGData']
    2322             SGData['fromParent'] = [Trans,Uvec,Vvec]        #save these
    2323             Atoms = newPhase['Atoms']
    2324             if ifMag:
    2325                 dlg = UseMagAtomDialog(G2frame,Atoms,atCodes)
    2326                 try:
    2327                     if dlg.ShowModal() == wx.ID_OK:
    2328                         newPhase['Atoms'],atCodes = dlg.GetSelection()
    2329                 finally:
    2330                     dlg.Destroy()
    2331                 SGData['GenSym'],SGData['GenFlg'],BNSsym = G2spc.GetGenSym(SGData)
    2332                 SGData['MagSpGrp'] = G2spc.MagSGSym(SGData)
    2333                 SGData['OprNames'],SGData['SpnFlp'] = G2spc.GenMagOps(SGData)
    2334                 generalData['Lande g'] = len(generalData['AtomTypes'])*[2.,]
     2353                phaseName = newPhase['General']['Name']
     2354                newPhase,atCodes = G2lat.TransformPhase(data,newPhase,Trans,Uvec,Vvec,ifMag)
     2355                detTrans = np.abs(nl.det(Trans))
     2356       
     2357                newPhase['ParentId'] = data['ranId']
     2358                generalData = newPhase['General']
     2359                SGData = generalData['SGData']
     2360                SGData['fromParent'] = [Trans,Uvec,Vvec]        #save these
     2361                Atoms = newPhase['Atoms']
     2362                if ifMag:
     2363                    dlg = UseMagAtomDialog(G2frame,Atoms,atCodes)
     2364                    try:
     2365                        if dlg.ShowModal() == wx.ID_OK:
     2366                            newPhase['Atoms'],atCodes = dlg.GetSelection()
     2367                            SGData['GenSym'],SGData['GenFlg'],BNSsym = G2spc.GetGenSym(SGData)
     2368                            SGData['MagSpGrp'] = G2spc.MagSGSym(SGData)
     2369                            SGData['OprNames'],SGData['SpnFlp'] = G2spc.GenMagOps(SGData)
     2370                            generalData['Lande g'] = len(generalData['AtomTypes'])*[2.,]
     2371                            break
     2372                    finally:
     2373                        dlg.Destroy()
     2374                else:
     2375                    break
    23352376               
    2336             NShkl = len(G2spc.MustrainNames(SGData))
    2337             NDij = len(G2spc.HStrainNames(SGData))
    2338             UseList = newPhase['Histograms']
    2339             for hist in UseList:
    2340                 UseList[hist]['Scale'] /= detTrans      #scale by 1/volume ratio
    2341                 UseList[hist]['Mustrain'][4:6] = [NShkl*[0.01,],NShkl*[False,]]
    2342                 UseList[hist]['HStrain'] = [NDij*[0.0,],NDij*[False,]]
    2343             newPhase['General']['Map'] = mapDefault.copy()
    2344             sub = G2frame.GPXtree.AppendItem(parent=
    2345                 G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Phases'),text=phaseName)
    2346             G2frame.GPXtree.SetItemPyData(sub,newPhase)
    2347             newPhase['Drawing'] = []
    2348            
    2349             if ifConstr:
    2350                 G2cnstG.TransConstraints(G2frame,data,newPhase,Trans,Vvec,atCodes)     #data is old phase
    2351             G2frame.GPXtree.SelectItem(sub)
     2377        NShkl = len(G2spc.MustrainNames(SGData))
     2378        NDij = len(G2spc.HStrainNames(SGData))
     2379        UseList = newPhase['Histograms']
     2380        for hist in UseList:
     2381            UseList[hist]['Scale'] /= detTrans      #scale by 1/volume ratio
     2382            UseList[hist]['Mustrain'][4:6] = [NShkl*[0.01,],NShkl*[False,]]
     2383            UseList[hist]['HStrain'] = [NDij*[0.0,],NDij*[False,]]
     2384        newPhase['General']['Map'] = mapDefault.copy()
     2385        sub = G2frame.GPXtree.AppendItem(parent=
     2386            G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Phases'),text=phaseName)
     2387        G2frame.GPXtree.SetItemPyData(sub,newPhase)
     2388        newPhase['Drawing'] = []
     2389       
     2390        if ifConstr:
     2391            G2cnstG.TransConstraints(G2frame,data,newPhase,Trans,Vvec,atCodes)     #data is old phase
     2392        G2frame.GPXtree.SelectItem(sub)
    23522393       
    23532394################################################################################
Note: See TracChangeset for help on using the changeset viewer.