Changeset 3982


Ignore:
Timestamp:
May 17, 2019 2:19:25 PM (2 years ago)
Author:
vondreele
Message:

begin work on MEM interface to Dysnomia
Change fourier/cf "Resolution" to "GridStep?"; GridStep? now the real step size (Resolution was 2X th estep size)

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r3980 r3982  
    55795579        self.WavesData.Append(menu=self.WavesDataEdit, title='Edit Wave')
    55805580        self.WavesDataEdit.Append(G2G.wxID_WAVEVARY,'Global wave vary','Global setting of wave vary flags')
     5581        self.PostfillDataMenu()
     5582       
     5583        #Phase / Dysnomia (Maximum Entropy Method) tab
     5584        G2G.Define_wxId('wxID_LOADDYSNOMIA', 'wxID_SAVEDYSNOMIA', 'wxID_RUNDYSNOMIA', )       
     5585        self.MEMData = wx.MenuBar()
     5586        self.PrefillDataMenu(self.MEMData)
     5587        self.MEMData.Append(menu=wx.Menu(title=''),title='Select tab')
     5588        self.MEMDataEdit = wx.Menu(title='')
     5589        self.MEMData.Append(menu=self.MEMDataEdit, title='Operations')
     5590        self.MEMDataEdit.Append(G2G.wxID_LOADDYSNOMIA,'Load from Dysnomia file','Load MEM info from Dysnomia file')
     5591        self.MEMDataEdit.Append(G2G.wxID_SAVEDYSNOMIA,'Save Dysnomia file','Save MEM info in Dysnomia file')
     5592        self.MEMDataEdit.Append(G2G.wxID_RUNDYSNOMIA,'Run Dysonmia','Run Dysnomia to make new Fobs map')
    55815593        self.PostfillDataMenu()
    55825594       
  • trunk/GSASIIddataGUI.py

    r3961 r3982  
    3333WHITE = wx.Colour(255,255,255)
    3434BLACK = wx.Colour(0,0,0)
    35 mapDefault = {'MapType':'','RefList':'','Resolution':0.5,'Show bonds':True,
     35mapDefault = {'MapType':'','RefList':'','GridStep':0.25,'Show bonds':True,
    3636                'rho':[],'rhoMax':0.,'mapSize':10.0,'cutOff':50.,'Flip':False}
    3737
  • trunk/GSASIImath.py

    r3964 r3982  
    30683068        return
    30693069    mapData = generalData['Map']
    3070     dmin = mapData['Resolution']
     3070    dmin = mapData['GridStep']*2.
    30713071    SGData = generalData['SGData']
    30723072    SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
     
    31193119    mapData['rhoMax'] = max(np.max(mapData['rho']),-np.min(mapData['rho']))
    31203120    mapData['minmax'] = [np.max(mapData['rho']),np.min(mapData['rho'])]
    3121     print ('Omit map time: %.4f no. elements: %d'%(time.time()-time0,Fhkl.size))
     3121    print ('Omit map time: %.4f no. elements: %d dimensions: %s'%(time.time()-time0,Fhkl.size,str(Fhkl.shape)))
    31223122    return mapData
    31233123   
     
    31323132    generalData = data['General']
    31333133    mapData = generalData['Map']
    3134     dmin = mapData['Resolution']
     3134    dmin = mapData['GridStep']*2.
    31353135    SGData = generalData['SGData']
    31363136    SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
     
    31853185                    Fhkl[h,k,l] = complex(Fosq,0.)
    31863186    rho = fft.fftn(fft.fftshift(Fhkl))/cell[6]
    3187     print ('Fourier map time: %.4f'%(time.time()-time0),'no. elements: %d'%(Fhkl.size))
     3187    print ('Fourier map time: %.4f no. elements: %d dimensions: %s'%(time.time()-time0,Fhkl.size,str(Fhkl.shape)))
    31883188    mapData['Type'] = reflDict['Type']
    31893189    mapData['rho'] = np.real(rho)
     
    32023202    map4DData = generalData['4DmapData']
    32033203    mapData = generalData['Map']
    3204     dmin = mapData['Resolution']
     3204    dmin = mapData['GridStep']*2.
    32053205    SGData = generalData['SGData']
    32063206    SSGData = generalData['SSGData']
     
    32563256    mapData['rhoMax'] = max(np.max(mapData['rho']),-np.min(mapData['rho']))
    32573257    mapData['minmax'] = [np.max(mapData['rho']),np.min(mapData['rho'])]
    3258     print ('Fourier map time: %.4f'%(time.time()-time0),'no. elements: %d'%(Fhkl.size))
     3258    print ('Fourier map time: %.4f no. elements: %d dimensions: %s'%(time.time()-time0,Fhkl.sizestr(Fhkl.shape)))
    32593259
    32603260# map printing for testing purposes
     
    33733373            if ff['Symbol'] == normElem:
    33743374                FFtable.update(ff)
    3375     dmin = flipData['Resolution']
     3375    dmin = flipData['GridStep']*2.
    33763376    SGData = generalData['SGData']
    33773377    SGMT = np.array([ops[0].T for ops in SGData['SGOps']])
     
    35403540            if ff['Symbol'] == normElem:
    35413541                FFtable.update(ff)
    3542     dmin = flipData['Resolution']
     3542    dmin = flipData['GridStep']*2.
    35433543    SGData = generalData['SGData']
    35443544    SSGData = generalData['SSGData']
     
    37733773            rho = copy.copy(mapData['rho'])     #don't mess up original
    37743774        mapHalf = np.array(rho.shape)/2
    3775         res = mapData['Resolution']
     3775        res = mapData['GridStep']*2.
    37763776        incre = np.array(rho.shape,dtype=np.float)
    37773777        step = max(1.0,1./res)+1
     
    39013901            Ind.append(ind)
    39023902    return Ind
     3903
     3904################################################################################
     3905##### Dysnomia setup & return stuff
     3906################################################################################
     3907   
     3908
    39033909   
    39043910################################################################################
  • trunk/GSASIIphsGUI.py

    r3970 r3982  
    7171BLACK = wx.Colour(0,0,0)
    7272WACV = wx.ALIGN_CENTER_VERTICAL
    73 mapDefault = {'MapType':'','RefList':'','Resolution':0.5,'Show bonds':True,
     73mapDefault = {'MapType':'','RefList':'','GridStep':0.25,'Show bonds':True,
    7474                'rho':[],'rhoMax':0.,'mapSize':10.0,'cutOff':50.,'Flip':False}
    7575TabSelectionIdDict = {}
     
    13021302            generalData['Map'] = mapDefault.copy()
    13031303        if 'Flip' not in generalData:
    1304             generalData['Flip'] = {'RefList':'','Resolution':0.5,'Norm element':'None',
     1304            generalData['Flip'] = {'RefList':'','GridStep':0.25,'Norm element':'None',
    13051305                'k-factor':0.1,'k-Max':20.,}
    13061306        if 'testHKL' not in generalData['Flip']:
     
    13161316        if '3Dproj' not in generalData:
    13171317            generalData['3Dproj'] = ''
     1318        if 'doDysnomia' not in generalData:
     1319            generalData['doDysnomia'] = False
    13181320        if 'Algolrithm' in generalData.get('MCSA controls',{}) or \
    13191321            'MCSA controls' not in generalData:
     
    13611363            if 'SGGray' not in generalData['SGData']:
    13621364                generalData['SGData']['SGGray'] = False
     1365        if 'Resolution' in generalData['Map']:
     1366            generalData['Map']['GridStep'] = generalData['Map']['Resolution']/2.
     1367            generalData['Flip']['GridStep'] = generalData['Flip']['Resolution']/2.
     1368            del generalData['Map']['Resolution']
     1369            del generalData['Flip']['Resolution']
    13631370               
    13641371# end of patches
     
    21762183                finally:
    21772184                    dlg.Destroy()
    2178                 wx.CallAfter(UpdateGeneral,General.GetScrollPos(wx.VERTICAL))               
     2185                wx.CallAfter(UpdateGeneral,General.GetScrollPos(wx.VERTICAL))
     2186
     2187            def OnDysnomia(event):
     2188                generalData['doDysnomia'] = not generalData['doDysnomia']
     2189                pages = [G2frame.phaseDisplay.GetPageText(PageNum) for PageNum in range(G2frame.phaseDisplay.GetPageCount())]
     2190                if generalData['doDysnomia']:
     2191                    if 'Dysnomia' not in pages:
     2192                        G2frame.MEMData = wx.ScrolledWindow(G2frame.phaseDisplay)
     2193                        G2frame.phaseDisplay.InsertPage(7,G2frame.MEMData,'Dysnomia')
     2194                        Id = wx.NewId()
     2195                        TabSelectionIdDict[Id] = 'Dysnomia'
     2196                        if 'Dysnomia' not in data:  #set defaults here
     2197                            data['Dysnomia'] = {'DenStart':'uniform','Optimize':'ZSPA','Lagrange':['user',0.001,0.05],
     2198                                'wt pwr':0,'E_factor':1.,'Ncyc':5000,'prior':'uniform','Lam frac':[1,0,0,0,0,0,0,0]}
     2199                else:
     2200                    if 'Dysnomia' in pages:
     2201                        G2frame.phaseDisplay.DeletePage(pages.index('Dysnomia'))
    21792202                           
    21802203            #patch
     
    22032226            mapSizer.Add(lineSizer,0,WACV)
    22042227            line2Sizer = wx.BoxSizer(wx.HORIZONTAL)
    2205             line2Sizer.Add(wx.StaticText(General,label=' Resolution: '),0,WACV)
    2206             mapRes = G2G.ValidatedTxtCtrl(General,Map,'Resolution',nDig=(10,2),min=0.20,max=20.)
     2228            line2Sizer.Add(wx.StaticText(General,label=' Map grid step: '),0,WACV)
     2229            mapRes = G2G.ValidatedTxtCtrl(General,Map,'GridStep',nDig=(10,2),min=0.1,max=2.)
    22072230            line2Sizer.Add(mapRes,0,WACV)
    22082231            line2Sizer.Add(wx.StaticText(General,label=' Peak cutoff %: '),0,WACV)
    22092232            cutOff = G2G.ValidatedTxtCtrl(General,Map,'cutOff',nDig=(10,1),min=1.0,max=100.)
    22102233            line2Sizer.Add(cutOff,0,WACV)
     2234            if len(Map['RefList']) and not generalData['Modulated']:
     2235                Dysno = wx.CheckBox(General,-1,label=' Use Dysnomia (Max. Ent. Method)?')
     2236                Dysno.SetValue(generalData['doDysnomia'])
     2237                Dysno.Bind(wx.EVT_CHECKBOX,OnDysnomia)
     2238                line2Sizer.Add(Dysno,0,WACV)
    22112239            mapSizer.Add(line2Sizer,0,WACV)
    22122240            return mapSizer
     
    22682296            flipSizer.Add(lineSizer,0,WACV)
    22692297            line2Sizer = wx.BoxSizer(wx.HORIZONTAL)
    2270             line2Sizer.Add(wx.StaticText(General,label=' Resolution: '),0,WACV)
    2271             flipRes = G2G.ValidatedTxtCtrl(General,Flip,'Resolution',nDig=(10,2),min=0.25,max=2.)
     2298            line2Sizer.Add(wx.StaticText(General,label=' Map grid step: '),0,WACV)
     2299            flipRes = G2G.ValidatedTxtCtrl(General,Flip,'GridStep',nDig=(10,2),min=0.10,max=2.)
    22722300            line2Sizer.Add(flipRes,0,WACV)
    22732301            line2Sizer.Add(wx.StaticText(General,label=' k-Factor (0.1-1.2): '),0,WACV)
     
    40914119       
    40924120################################################################################
     4121#### Dysnomia (MEM) Data page
     4122################################################################################
     4123       
     4124    def UpdateDysnomia():
     4125        ''' Present the controls for running Dysnomia
     4126        '''
     4127#data['Dysonmia'] = {'DenStart':'uniform','Optimize':'ZSPA','Lagrange':['user',0.001,0.05],
     4128#    'wt pwr':0,'E_factor':1.,'Ncyc':5000,'prior':'uniform','Lam frac':[1,0,0,0,0,0,0,0]}
     4129        def OnOptMeth(event):
     4130            DysData['Optimize'] = OptMeth.GetValue()
     4131            wx.CallAfter(UpdateDysnomia)
     4132           
     4133        def OnZmult(event):
     4134            DysData['Lagrange'][0] = Zmult.GetValue()
     4135            wx.CallAfter(UpdateDysnomia)
     4136           
     4137        def OnStart(event):
     4138            DysData['DenStart'] = Start.GetValue()
     4139           
     4140        def OnPrior(event):
     4141            DysData['prior'] = Prior.GetValue()
     4142       
     4143        MEMData = G2frame.MEMData
     4144        if MEMData.GetSizer():
     4145            MEMData.GetSizer().Clear(True)
     4146        DysData = data['Dysnomia']
     4147        mainSizer = wx.BoxSizer(wx.VERTICAL)
     4148        mainSizer.Add(wx.StaticText(MEMData,label=' Maximum Entropy Method (Dysnomia) controls:'))
     4149        lineSizer = wx.BoxSizer(wx.HORIZONTAL)
     4150        lineSizer.Add(wx.StaticText(MEMData,label=' MEM Optimization method: '),0,WACV)
     4151        OptMeth = wx.ComboBox(MEMData,-1,value=DysData['Optimize'],choices=['ZSPA','L-BFGS'],
     4152            style=wx.CB_READONLY|wx.CB_DROPDOWN)
     4153        OptMeth.Bind(wx.EVT_COMBOBOX,OnOptMeth)
     4154        lineSizer.Add(OptMeth,0,WACV)
     4155        mainSizer.Add(lineSizer)
     4156        if DysData['Optimize'] == 'ZSPA':
     4157            Zsizer = wx.BoxSizer(wx.HORIZONTAL)
     4158            Zsizer.Add(wx.StaticText(MEMData,label=' Initial Lagrangian multiplier: from '),0,WACV)
     4159            Zmult = wx.ComboBox(MEMData,value=DysData['Lagrange'][0],choices=['user','Dysnomia'],
     4160                style=wx.CB_READONLY|wx.CB_DROPDOWN)
     4161            Zmult.Bind(wx.EVT_COMBOBOX,OnZmult)
     4162            Zsizer.Add(Zmult,0,WACV)
     4163            if DysData['Lagrange'][0] == 'user':
     4164                Zsizer.Add(wx.StaticText(MEMData,label=' value: '),0,WACV)
     4165                lamb = G2G.ValidatedTxtCtrl(MEMData,DysData['Lagrange'],1,nDig=(10,4),min=0.0001,max=1.)
     4166                Zsizer.Add(lamb,0,WACV)
     4167            Zsizer.Add(wx.StaticText(MEMData,label=' Adjust by: '),0,WACV)
     4168            dlamb = G2G.ValidatedTxtCtrl(MEMData,DysData['Lagrange'],2,nDig=(8,2),min=0.05,max=0.1)
     4169            Zsizer.Add(dlamb,0,WACV)
     4170            mainSizer.Add(Zsizer)
     4171        Esizer = wx.BoxSizer(wx.HORIZONTAL)
     4172        Esizer.Add(wx.StaticText(MEMData,label=' Weight by d-spacing**'),0,WACV)
     4173        Efact = G2G.ValidatedTxtCtrl(MEMData,DysData,'wt pwr',min=0,max=4,size=(50,20))
     4174        Esizer.Add(Efact,0,WACV)
     4175        mainSizer.Add(Esizer)
     4176        PriorSizer = wx.BoxSizer(wx.HORIZONTAL)
     4177        PriorSizer.Add(wx.StaticText(MEMData,label=' Start from densities: '),0,WACV)
     4178        Start = wx.ComboBox(MEMData,-1,value=DysData['DenStart'],choices=['uniform','last run'],
     4179            style=wx.CB_READONLY|wx.CB_DROPDOWN)
     4180        Start.Bind(wx.EVT_COMBOBOX,OnStart)
     4181        PriorSizer.Add(Start,0,WACV)
     4182        PriorSizer.Add(wx.StaticText(MEMData,label=' Use as prior: '),0,WACV)
     4183        Prior = wx.ComboBox(MEMData,-1,value=DysData['prior'],choices=['uniform','last run'],
     4184            style=wx.CB_READONLY|wx.CB_DROPDOWN)
     4185        Prior.Bind(wx.EVT_COMBOBOX,OnPrior)
     4186        PriorSizer.Add(Prior,0,WACV)
     4187        mainSizer.Add(PriorSizer)       
     4188        Csizer = wx.BoxSizer(wx.HORIZONTAL)
     4189        Csizer.Add(wx.StaticText(MEMData,label=' Maximum number of cycles: '),0,WACV)
     4190        Cyc = G2G.ValidatedTxtCtrl(MEMData,DysData,'Ncyc',min=0,max=10000,size=(50,20))
     4191        Csizer.Add(Cyc,0,WACV)
     4192        mainSizer.Add(Csizer)
     4193       
     4194       
     4195       
     4196       
     4197       
     4198        SetPhaseWindow(G2frame.MEMData,mainSizer)
     4199
     4200    def OnLoadDysnomia(event):
     4201        print('Load MEM')
     4202       
     4203    def OnSaveDysnomia(event):
     4204        print('Save MEM')
     4205
     4206    def OnRunDysnomia(event):
     4207       
     4208       
     4209        generalData = data['General']
     4210        Map = generalData['Map']
     4211        Phase = generalData['Name'].replace(' ','_')
     4212        DysData = data['Dysnomia']
     4213        prf = open(Phase+'.prf','w')
     4214        prf.write(Phase+'.mem\n') #or .fos?
     4215        prf.write(Phase+'.out\n')
     4216        prf.write(Phase+'.pgrid\n')
     4217        prf.write(Phase+'.fba\n')
     4218        prf.write(Phase+'_eps.raw\n')
     4219       
     4220       
     4221
     4222       
     4223        prf.close()
     4224
     4225        wx.MessageBox(''' For use of Dysnomia, please cite:
     4226      Dysnomia, a computer program for maximum-entropy method (MEM)
     4227      analysis and its performance in the MEM-based pattern fitting,
     4228      K. Moma, T. Ikeda, A.A. Belik & F. Izumi, Powder Diffr. 2013, 28, 184-193.
     4229      doi:10.1017/S088571561300002X''',caption='Dysnomia (MEM)',style=wx.ICON_INFORMATION)
     4230           
     4231       
     4232       
     4233       
     4234################################################################################
    40934235#### Layer Data page
    40944236################################################################################
     
    94869628            UpdateWavesData()
    94879629            wx.CallAfter(G2plt.PlotStructure,G2frame,data,firstCall=True)
     9630        elif text == 'Dysnomia':
     9631            G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.MEMData)
     9632            UpdateDysnomia()
    94889633        elif text == 'Draw Options':
    94899634            G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.DataDrawOptions)
     
    95729717            FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.WavesData)
    95739718            G2frame.Bind(wx.EVT_MENU, OnWaveVary, id=G2G.wxID_WAVEVARY)
     9719        # Dysnomia (MEM)
     9720        if data['General']['doDysnomia']:
     9721            FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.MEMData)
     9722            G2frame.Bind(wx.EVT_MENU, OnLoadDysnomia, id=G2G.wxID_LOADDYSNOMIA)
     9723            G2frame.Bind(wx.EVT_MENU, OnSaveDysnomia, id=G2G.wxID_SAVEDYSNOMIA)
     9724            G2frame.Bind(wx.EVT_MENU, OnRunDysnomia, id=G2G.wxID_RUNDYSNOMIA)
    95749725        # Stacking faults
    95759726        FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.LayerData)
     
    96569807    if 'Modulated' not in data['General']:
    96579808        data['General']['Modulated'] = False
     9809    if 'doDysnomia' not in data['General']:
     9810        data['General']['doDysnomia'] = False
    96589811    if 'modulated' in data['General']['Type']:
    96599812        data['General']['Modulated'] = True
     
    96659818    PhaseName = G2frame.GPXtree.GetItemText(Item)
    96669819    G2gd.SetDataMenuBar(G2frame)
    9667     # Bob: why do this differently in debug mode? Is this code to test if tabs can be moved around? #TODO - yup, flaky tho.
    9668 #    if GSASIIpath.GetConfigValue('debug'):
    9669 #        G2frame.phaseDisplay = G2G.GSNoteBook(parent=G2frame.dataWindow,size=G2frame.dataWindow.GetClientSize(),
    9670 #            style=wx.aui.AUI_NB_TOP | wx.aui.AUI_NB_TAB_SPLIT | wx.aui.AUI_NB_TAB_MOVE)
    9671 #    else:
    9672 #        G2frame.phaseDisplay = G2G.GSNoteBook(parent=G2frame.dataWindow,size=G2frame.dataWindow.GetClientSize())
    96739820    G2frame.phaseDisplay = G2G.GSNoteBook(parent=G2frame.dataWindow)
    96749821    G2frame.dataWindow.GetSizer().Add(G2frame.phaseDisplay,1,wx.ALL|wx.EXPAND,1)
     
    97109857    G2frame.phaseDisplay.gridList.append(MapPeaks)   
    97119858    G2frame.phaseDisplay.AddPage(MapPeaks,'Map peaks')
     9859    if data['General']['doDysnomia']:
     9860        G2frame.Dysnomia = wx.ScrolledWindow(G2frame.phaseDisplay)
     9861        G2frame.phaseDisplay.AddPage(G2frame.Dysnomia,'Dysnomia')
     9862        Pages.append('Dysnomia')       
    97129863    Pages.append('Map peaks')
    97139864    if data['General']['Type'] not in ['faulted',] and not data['General']['Modulated']:
  • trunk/GSASIIplot.py

    r3972 r3982  
    89208920            invModel = nl.inv(Model)
    89218921            msize = 5.      #-5A - 5A slice
    8922             mRes = generalData['Map']['Resolution']/2.
     8922            mRes = generalData['Map']['GridStep']
    89238923            npts = int(2*msize/mRes)
    89248924            VP = np.array(drawingData['viewPoint'][0])
Note: See TracChangeset for help on using the changeset viewer.