Changeset 2154


Ignore:
Timestamp:
Feb 19, 2016 3:58:52 PM (8 years ago)
Author:
vondreele
Message:

remove range restriction on LGmix - inhibited doing refinements
do wx.CallAfter? for size/strain plots in G2ddataGUI
Add TransformDialog?, prodMGMT, TransformCell?, TransformU6, TransformXYZ to G2lattice
A start on TransformAtoms? in G2math
fill in OnTransform?

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIddataGUI.py

    r2075 r2154  
    159159        try:
    160160            value = float(Obj.GetValue())
    161             if 0 <= value <= 1:
    162                 UseList[G2frame.hist][name][1][2] = value
    163             else:
    164                 raise ValueError
     161            UseList[G2frame.hist][name][1][2] = value
     162#            if 0 <= value <= 1:
     163#                UseList[G2frame.hist][name][1][2] = value
     164#            else:
     165#                raise ValueError
    165166        except ValueError:
    166167            pass
     
    202203                pass
    203204            Obj.SetValue("%.5f"%(UseList[G2frame.hist]['Size'][1][pid]))          #reset in case of error
    204         G2plt.PlotSizeStrainPO(G2frame,data,hist)
     205        wx.CallAfter(G2plt.PlotSizeStrainPO,G2frame,data,hist)
    205206       
    206207    def OnStrainType(event):
     
    238239        else:
    239240            Obj.SetValue("%.1f"%(UseList[G2frame.hist]['Mustrain'][1][pid]))          #reset in case of error
    240         G2plt.PlotSizeStrainPO(G2frame,data,hist)
     241        wx.CallAfter(G2plt.PlotSizeStrainPO,G2frame,data,hist)
    241242       
    242243    def OnStrainAxis(event):
  • trunk/GSASIIgrid.py

    r2147 r2154  
    318318       
    319319################################################################################
     320class TransformDialog(wx.Dialog):
     321    ''' Phaae transformation
     322   
     323    :param wx.Frame parent: reference to parent frame (or None)
     324    :param phase: phase data
     325   
     326    #NB: commonNames & commonTrans defined at top of this file
     327    '''
     328    def __init__(self,parent,phase):
     329        wx.Dialog.__init__(self,parent,wx.ID_ANY,'Setup phase transformation',
     330            pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE)
     331        self.panel = wx.Panel(self)         #just a dummy - gets destroyed in Draw!
     332        self.Phase = copy.deepcopy(phase)   #will be a new phase!
     333#        self.Super = phase['General']['Super']
     334#        if self.Super:
     335#            self.Trans = np.eye(4)
     336#            self.Vec = np.zeros(4)
     337#        else:
     338        self.Trans = np.eye(3)
     339        self.Vec = np.zeros(3)
     340        self.SpGrp = phase['General']['SGData']['SpGrp']
     341        self.oldCell = phase['General']['Cell'][1:8]
     342        self.newCell = copy.copy(self.oldCell)
     343        self.Common = 'abc'
     344        self.Draw()
     345
     346    def Draw(self):
     347               
     348        def OnMatValue(event):
     349            Obj = event.GetEventObject()
     350            ix,iy = Ind[Obj.GetId()]
     351            self.Trans[iy,ix] = float(Obj.GetValue())
     352            Obj.SetValue('%5.3f'%(self.Trans[iy,ix]))
     353           
     354        def OnVecValue(event):
     355            Obj = event.GetEventObject()
     356            iy = Ind[Obj.GetId()]
     357            self.Vec[iy] = float(Obj.GetValue())
     358            Obj.SetValue('%5.3f'%(self.Vec[iy]))
     359               
     360        def OnCommon(event):
     361            Obj = event.GetEventObject()
     362            self.Common = Obj.GetValue()
     363            self.Trans = commonTrans[self.Common]
     364            OnTest(event)
     365       
     366        def OnSpaceGroup(event):
     367            Flds = SGTxt.GetValue().split()
     368            #get rid of extra spaces between fields first
     369            for fld in Flds: fld = fld.strip()
     370            SpcGp = ' '.join(Flds)
     371            # try a lookup on the user-supplied name
     372            SpGrpNorm = G2spc.StandardizeSpcName(SpcGp)
     373            if SpGrpNorm:
     374                SGErr,SGData = G2spc.SpcGroup(SpGrpNorm)
     375            else:
     376                SGErr,SGData = G2spc.SpcGroup(SpcGp)
     377            if SGErr:
     378                text = [G2spc.SGErrors(SGErr)+'\nSpace Group set to previous']
     379                SGTxt.SetValue(self.SpGrp)
     380                msg = 'Space Group Error'
     381                Style = wx.ICON_EXCLAMATION
     382                Text = '\n'.join(text)
     383                wx.MessageBox(Text,caption=msg,style=Style)
     384            else:
     385                text,table = G2spc.SGPrint(SGData)
     386                self.Phase['General']['SGData'] = SGData
     387                self.SpGrp = SpGrp
     388                SGTxt.SetValue(self.Phase['General']['SGData']['SpGrp'])
     389                msg = 'Space Group Information'
     390                SGMessageBox(self.panel,msg,text,table).Show()
     391#            if self.Phase['General']['Type'] in ['modulated',]:
     392#                self.Phase['General']['SuperSg'] = SetDefaultSSsymbol()
     393#                self.Phase['General']['SSGData'] = G2spc.SSpcGroup(generalData['SGData'],generalData['SuperSg'])[1]
     394
     395        def OnTest(event):
     396            self.newCell = G2lat.TransformCell(self.oldCell[:6],self.Trans)
     397            wx.CallAfter(self.Draw)
     398
     399        self.panel.Destroy()
     400        self.panel = wx.Panel(self)
     401        Ind = {}
     402        mainSizer = wx.BoxSizer(wx.VERTICAL)
     403        MatSizer = wx.BoxSizer(wx.HORIZONTAL)
     404        transSizer = wx.BoxSizer(wx.VERTICAL)
     405        transSizer.Add(wx.StaticText(self.panel,label=" XYZ Transformation matrix & vector: M*X+V = X'"))
     406#        if self.Super:
     407#            Trmat = wx.FlexGridSizer(4,4,0,0)
     408#        else:
     409        commonSizer = wx.BoxSizer(wx.HORIZONTAL)
     410        commonSizer.Add(wx.StaticText(self.panel,label=' Common transformations: '),0,WACV)
     411        common = wx.ComboBox(self.panel,value=self.Common,choices=commonNames,
     412            style=wx.CB_READONLY|wx.CB_DROPDOWN)
     413        common.Bind(wx.EVT_COMBOBOX,OnCommon)
     414        commonSizer.Add(common,0,WACV)
     415        transSizer.Add(commonSizer)
     416        Trmat = wx.FlexGridSizer(3,5,0,0)
     417        for iy,line in enumerate(self.Trans):
     418            for ix,val in enumerate(line):
     419                item = wx.TextCtrl(self.panel,value='%5.3f'%(val),
     420                    size=(50,25),style=wx.TE_PROCESS_ENTER)
     421                Ind[item.GetId()] = [ix,iy]
     422                item.Bind(wx.EVT_TEXT_ENTER,OnMatValue)
     423                item.Bind(wx.EVT_KILL_FOCUS,OnMatValue)
     424                Trmat.Add(item)
     425            Trmat.Add((25,0),0)
     426            vec = wx.TextCtrl(self.panel,value='%5.3f'%(self.Vec[iy]),
     427                    size=(50,25),style=wx.TE_PROCESS_ENTER)
     428            Ind[vec.GetId()] = [iy]       
     429            vec.Bind(wx.EVT_TEXT_ENTER,OnVecValue)
     430            vec.Bind(wx.EVT_KILL_FOCUS,OnVecValue)
     431            Trmat.Add(vec)
     432        transSizer.Add(Trmat)
     433        MatSizer.Add((10,0),0)
     434        MatSizer.Add(transSizer)
     435        mainSizer.Add(MatSizer)
     436        mainSizer.Add(wx.StaticText(self.panel,label=' Old lattice parameters:'),0,WACV)
     437        mainSizer.Add(wx.StaticText(self.panel,label=
     438            ' a = %.5f       b = %.5f      c = %.5f'%(self.oldCell[0],self.oldCell[1],self.oldCell[2])),0,WACV)
     439        mainSizer.Add(wx.StaticText(self.panel,label=' alpha = %.3f beta = %.3f gamma = %.3f'%
     440            (self.oldCell[3],self.oldCell[4],self.oldCell[5])),0,WACV)
     441        mainSizer.Add(wx.StaticText(self.panel,label=' volume = %.3f'%(self.oldCell[6])),0,WACV)
     442        mainSizer.Add(wx.StaticText(self.panel,label=' New lattice parameters:'),0,WACV)
     443        mainSizer.Add(wx.StaticText(self.panel,label=
     444            ' a = %.5f       b = %.5f      c = %.5f'%(self.newCell[0],self.newCell[1],self.newCell[2])),0,WACV)
     445        mainSizer.Add(wx.StaticText(self.panel,label=' alpha = %.3f beta = %.3f gamma = %.3f'%
     446            (self.newCell[3],self.newCell[4],self.newCell[5])),0,WACV)
     447        mainSizer.Add(wx.StaticText(self.panel,label=' volume = %.3f'%(self.newCell[6])),0,WACV)
     448        sgSizer = wx.BoxSizer(wx.HORIZONTAL)
     449        sgSizer.Add(wx.StaticText(self.panel,label='  Space group: '),0,WACV)
     450        SGTxt = wx.TextCtrl(self.panel,value=self.SpGrp,style=wx.TE_PROCESS_ENTER)
     451        SGTxt.Bind(wx.EVT_TEXT_ENTER,OnSpaceGroup)
     452        sgSizer.Add(SGTxt,0,WACV)
     453        mainSizer.Add(sgSizer,0,WACV)
     454
     455        TestBtn = wx.Button(self.panel,-1,"Test")
     456        TestBtn.Bind(wx.EVT_BUTTON, OnTest)
     457        OkBtn = wx.Button(self.panel,-1,"Ok")
     458        OkBtn.Bind(wx.EVT_BUTTON, self.OnOk)
     459        cancelBtn = wx.Button(self.panel,-1,"Cancel")
     460        cancelBtn.Bind(wx.EVT_BUTTON, self.OnCancel)
     461        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
     462        btnSizer.Add((20,20),1)
     463        btnSizer.Add(TestBtn)
     464        btnSizer.Add((20,20),1)
     465        btnSizer.Add(OkBtn)
     466        btnSizer.Add((20,20),1)
     467        btnSizer.Add(cancelBtn)
     468        btnSizer.Add((20,20),1)
     469       
     470        mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10)
     471        self.panel.SetSizer(mainSizer)
     472        self.panel.Fit()
     473        self.Fit()
     474       
     475    def GetSelection(self):
     476        self.Phase['General']['Name'] += ' %s'%(self.SpGrp)
     477        self.Phase['General']['Cell'][1:] = G2lat.TransformCell(self.oldCell[:6],self.Trans)           
     478        return self.Phase,self.Trans,self.Vec
     479
     480    def OnOk(self,event):
     481        parent = self.GetParent()
     482        parent.Raise()
     483        self.EndModal(wx.ID_OK)
     484
     485    def OnCancel(self,event):
     486        parent = self.GetParent()
     487        parent.Raise()
     488        self.EndModal(wx.ID_CANCEL)       
     489       
     490################################################################################
    320491class MergeDialog(wx.Dialog):
    321492    ''' HKL transformation & merge dialog
     
    324495    :param data: HKLF data
    325496   
    326     #NB: commonNames & commonTrans defined at top of this file
    327    
     497    #NB: commonNames & commonTrans defined at top of this file     
    328498    '''       
    329499    def __init__(self,parent,data):
  • trunk/GSASIIlattice.py

    r2147 r2154  
    193193    g = nl.inv(G)
    194194    return G,g
    195        
     195   
     196def prodMGMT(G,Mat):
     197    '''Transform metric tensor by matrix
     198   
     199    :param G: array metric tensor
     200    :param Mat: array transformation matrix
     201    :return: array new metric tensor
     202   
     203    '''
     204    return np.inner(Mat,np.inner(G,Mat).T)
     205   
     206def TransformCell(cell,Trans):
     207    '''Transform lattice parameters by matrix
     208   
     209    :param cell: list a,b,c,alpha,beta,gamma,(volume)
     210    :param Trans: array transformation matrix
     211    :return: array transformed a,b,c,alpha,beta,gamma,volume
     212   
     213    '''
     214    newCell = np.zeros(7)
     215    g = cell2Gmat(cell)[1]
     216    newg = prodMGMT(g,Trans)
     217    newCell[:6] = Gmat2cell(newg)
     218    newCell[6] = calc_V(cell2A(newCell[:6]))
     219    return newCell
     220   
     221def TransformXYZ(XYZ,Trans,Vec):
     222    return np.inner(XYZ,Trans)+Vec
     223   
     224def TransformU6(U6,Trans):
     225    Uij = np.inner(Trans,np.inner(U6toUij(U6),Trans))
     226    return UijtoU6(Uij)
     227           
    196228def calc_rVsq(A):
    197229    """Compute the square of the reciprocal lattice volume (1/V**2) from A'
  • trunk/GSASIImath.py

    r2132 r2154  
    381381        XYZ.append([parmDict[name]+parmDict[dname] for name,dname in zip(names,dnames)])
    382382    return XYZ
     383   
     384def TransformAtoms(Atoms,cx,cia,Trans,Vec):
     385    for Atom in Atoms:
     386        XYZ = Atom[cx:cx+3]
     387        if 'A' in Atom[cia]:
     388            U6 = Atom[cia+2:cia+8]
     389   
    383390
    384391def FindNeighbors(phase,FrstName,AtNames,notName=''):
  • trunk/GSASIIphsGUI.py

    r2138 r2154  
    11821182        need to start with full unit cell contents, transform & then filter out symm. equiv.
    11831183        '''
    1184         print 'Transform crystal structure - TBD'
    1185        
    1186                    
     1184        dlg = G2gd.TransformDialog(G2frame,data)
     1185        try:
     1186            if dlg.ShowModal() == wx.ID_OK:
     1187                newPhase,Trans,Vec = dlg.GetSelection()
     1188            else:
     1189                return
     1190        finally:
     1191            dlg.Destroy()
     1192        phaseName = newPhase['General']['Name']
     1193        sub = G2frame.PatternTree.AppendItem(parent=
     1194            G2gd.GetPatternTreeItemId(G2frame,G2frame.root,'Phases'),text=PhaseName)
     1195        G2frame.PatternTree.SetItemPyData(sub,newPhase)
    11871196
    11881197################################################################################
     
    20412050            else:
    20422051                Atoms.ForceRefresh()
     2052        else:
     2053            print "select one or more rows of atoms"
     2054            G2frame.ErrorDialog('Select atom',"select one or more atoms then redo")           
    20432055               
    20442056    def MakeMolecule(event):     
  • trunk/GSASIIstrIO.py

    r2110 r2154  
    25462546                for item in ['Mustrain','Size']:
    25472547                    hapData[item][1][2] = parmDict[pfx+item+';mx']
    2548                     hapData[item][1][2] = min(1.,max(0.,hapData[item][1][2]))
     2548#                    hapData[item][1][2] = min(1.,max(0.,hapData[item][1][2]))
    25492549                    if pfx+item+';mx' in sigDict:
    25502550                        SizeMuStrSig[pfx+item][0][2] = sigDict[pfx+item+';mx']
Note: See TracChangeset for help on using the changeset viewer.