Changeset 5070


Ignore:
Timestamp:
Nov 6, 2021 9:19:32 PM (2 years ago)
Author:
toby
Message:

ISO: add show mode defs; create CIF for ISO calc; remove ISO calc from General menu

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIconstrGUI.py

    r5067 r5070  
    37793779    G2frame.rbBook.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, OnPageChanged)
    37803780    wx.CallAfter(OnPageChanged,None)
    3781 
     3781   
    37823782def ShowIsoDistortCalc(G2frame,phase=None):
    37833783    '''Compute the ISODISTORT mode values from the current coordinates.
     
    37883788    def _onClose(event):
    37893789        dlg.EndModal(wx.ID_CANCEL)
    3790     def fmtHelp(item,fullname):
    3791         helptext = "A new variable"
    3792         if item[-3]:
    3793             helptext += " named "+str(item[-3])
    3794         helptext += " is a linear combination of the following parameters:\n"
    3795         first = True
    3796         for term in item[:-3]:
    3797             line = ''
    3798             var = str(term[1])
    3799             m = term[0]
    3800             if first:
    3801                 first = False
    3802                 line += ' = '
    3803             else:
    3804                 if m >= 0:
    3805                     line += ' + '
    3806                 else:
    3807                     line += ' - '
    3808                 m = abs(m)
    3809             line += '%.3f*%s '%(m,var)
    3810             varMean = G2obj.fmtVarDescr(var)
    3811             helptext += "\n" + line + " ("+ varMean + ")"
    3812         helptext += '\n\nISODISTORT full name: '+str(fullname)
    3813         return helptext
    38143790
    38153791    Phases = G2frame.GetPhaseData()
     
    39623938    mainSizer.Fit(dlg)
    39633939    dlg.SetMinSize(dlg.GetSize())
     3940    dlg.CenterOnParent()
    39643941    dlg.ShowModal()
    39653942    dlg.Destroy()
     3943
     3944def ShowIsoModes(G2frame,phase):
     3945    '''Show details about the ISODISTORT mode and the displacements they
     3946    translate to.
     3947    '''
     3948    def _onClose(event):
     3949        dlg.EndModal(wx.ID_CANCEL)
     3950
     3951    # make a lookup table for named NewVar Phase constraints
     3952    sub = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,'Constraints')
     3953    Constraints = G2frame.GPXtree.GetItemPyData(sub)
     3954    constrDict = {}
     3955    for c in Constraints['Phase']:
     3956        if c[-1] != 'f' or not c[-3]: continue
     3957        constrDict[str(c[-3])] = c
     3958       
     3959    Phases = G2frame.GetPhaseData()
     3960    data = Phases[phase]
     3961    ISO = data['ISODISTORT']
     3962    if 'IsoVarList' in ISO:
     3963        modeExp = {}
     3964        for i,row in enumerate(ISO['Var2ModeMatrix']):
     3965            line = '('
     3966            for j,k in enumerate(row):
     3967                var = ISO['IsoVarList'][j]
     3968                if np.isclose(k,0): continue
     3969                if k < 0 and j > 0:
     3970                    line += ' - '
     3971                    k = -k
     3972                elif j > 0:
     3973                    line += ' + '
     3974                if np.isclose(k,1):
     3975                    line += '%s ' % str(var)
     3976                else:
     3977                    line += '%.3f * %s' % (k,str(var))
     3978            line += ')/{:.3g}'.format(ISO['NormList'][i])
     3979            modeExp[str(ISO['G2ModeList'][i])] = line
     3980               
     3981        crdExp = {}
     3982        for i,(lbl,row) in enumerate(zip(ISO['IsoVarList'],ISO['Mode2VarMatrix'])):
     3983            l = ''
     3984            for j,(k,n) in enumerate(zip(row,ISO['NormList'])):
     3985                if np.isclose(k,0): continue
     3986                l1 = ''
     3987                if j > 0 and k < 0:
     3988                    k = -k
     3989                    l1 = ' -'
     3990                elif j > 0:
     3991                    l1 += ' +'
     3992                if np.isclose(k,1):
     3993                    l += '{:} {:4g} * {:}'.format(
     3994                        l1, n, ISO['G2ModeList'][j])
     3995                else:
     3996                    l += '{:} {:3g} * {:4g} * {:}'.format(
     3997                        l1, k, n, ISO['G2ModeList'][j])               
     3998            crdExp[lbl] = l
     3999
     4000    dlg = wx.Dialog(G2frame,wx.ID_ANY,'ISODISTORT modes and displacements',#size=(630,400),
     4001        style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
     4002    mainSizer = wx.BoxSizer(wx.VERTICAL)
     4003    mainSizer.Add(wx.StaticText(dlg,wx.ID_ANY,
     4004        'ISODISTORT modes and displacements in phase '+str(data['General'].get('Name','?'))))
     4005    # ISODISTORT displacive modes
     4006    if 'G2VarList' in ISO:
     4007        panel1 = wxscroll.ScrolledPanel(
     4008            dlg, wx.ID_ANY,#size=(100,200),
     4009            style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
     4010        subSizer1 = wx.FlexGridSizer(cols=3,hgap=5,vgap=2)
     4011        panel2 = wxscroll.ScrolledPanel(
     4012            dlg, wx.ID_ANY,#size=(100,200),
     4013            style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
     4014        subSizer2 = wx.FlexGridSizer(cols=4,hgap=5,vgap=2)
     4015        subSizer1.Add(wx.StaticText(panel1,wx.ID_ANY,'GSAS-II\nequiv.'))
     4016        subSizer1.Add(wx.StaticText(panel1,wx.ID_ANY,' expression'),0,wx.ALIGN_CENTER)
     4017        subSizer1.Add(wx.StaticText(panel1,wx.ID_ANY,'ISODISTORT\nname'))
     4018        for i in range(3): subSizer1.Add((-1,5)) # spacer
     4019        subSizer2.Add((-1,-1))
     4020        subSizer2.Add(wx.StaticText(panel2,wx.ID_ANY,'GSAS-II\nMode Name'))
     4021        subSizer2.Add(wx.StaticText(panel2,wx.ID_ANY,' expression'),0,wx.ALIGN_CENTER)
     4022        subSizer2.Add(wx.StaticText(panel2,wx.ID_ANY,'ISODISTORT\nMode name'))
     4023        for i in range(4): subSizer2.Add((-1,5))
     4024        for i,lbl in enumerate(ISO['IsoVarList']):
     4025            if np.isclose(ISO['G2coordOffset'][i],0):
     4026                G2var = '{:}'.format(str(ISO['G2VarList'][i]).replace('::dA','::A'))
     4027            elif ISO['G2coordOffset'][i] < 0:
     4028                G2var = '({:} + {:.3g})'.format(
     4029                    str(ISO['G2VarList'][i]).replace('::dA','::A'),
     4030                    -ISO['G2coordOffset'][i])
     4031            else:
     4032                G2var = '({:} - {:.3g})'.format(
     4033                    str(ISO['G2VarList'][i]).replace('::dA','::A'),
     4034                    ISO['G2coordOffset'][i])
     4035            subSizer1.Add(wx.StaticText(panel1,wx.ID_ANY,str(G2var)))
     4036            subSizer1.Add(wx.StaticText(panel1,wx.ID_ANY,crdExp[lbl]))
     4037            subSizer1.Add(wx.StaticText(panel1,wx.ID_ANY,str(lbl)))
     4038           
     4039        for (isomode,G2mode) in zip(ISO['IsoModeList'],ISO['G2ModeList']):
     4040            if str(G2mode) in constrDict:
     4041                ch = G2G.HelpButton(panel2,fmtHelp(constrDict[str(G2mode)],isomode))
     4042                subSizer2.Add(ch,0,wx.LEFT|wx.RIGHT|WACV|wx.ALIGN_CENTER,1)
     4043            else:
     4044                subSizer2.Add((-1,-1))
     4045            subSizer2.Add(wx.StaticText(panel2,wx.ID_ANY,str(G2mode)))
     4046            subSizer2.Add(wx.StaticText(panel2,wx.ID_ANY,modeExp[str(G2mode)]))
     4047            subSizer2.Add(wx.StaticText(panel2,wx.ID_ANY,str(isomode)))
     4048           
     4049        # finish up ScrolledPanel
     4050        panel1.SetSizer(subSizer1)
     4051        panel2.SetSizer(subSizer2)
     4052        panel1.SetAutoLayout(1)
     4053        panel1.SetupScrolling()
     4054        panel2.SetAutoLayout(1)
     4055        panel2.SetupScrolling()
     4056        # Allow window to be enlarged but not made smaller
     4057        w1,l1 = subSizer1.GetSize()
     4058        w2,l2 = subSizer2.GetSize()
     4059        panel1.SetMinSize((min(700,w1+20),max(50,l1)))
     4060        panel2.SetMinSize((min(700,w2+20),max(50,l2)))
     4061        mainSizer.Add(panel1,1, wx.ALL|wx.EXPAND,1)
     4062        mainSizer.Add(panel2,1, wx.ALL|wx.EXPAND,1)
     4063
     4064    # make OK button
     4065    btnsizer = wx.BoxSizer(wx.HORIZONTAL)
     4066    btn = wx.Button(dlg, wx.ID_CLOSE)
     4067    btn.Bind(wx.EVT_BUTTON,_onClose)
     4068    btnsizer.Add(btn)
     4069    mainSizer.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
     4070
     4071    dlg.SetSizer(mainSizer)
     4072    mainSizer.Fit(dlg)
     4073    dlg.SetMinSize(dlg.GetSize())
     4074    dlg.CenterOnParent()
     4075    dlg.ShowModal()
     4076    dlg.Destroy()
     4077
     4078def fmtHelp(item,fullname):
     4079    helptext = "A new variable"
     4080    if item[-3]:
     4081        helptext += " named "+str(item[-3])
     4082    helptext += " is a linear combination of the following parameters:\n"
     4083    first = True
     4084    for term in item[:-3]:
     4085        line = ''
     4086        var = str(term[1])
     4087        m = term[0]
     4088        if first:
     4089            first = False
     4090            line += ' = '
     4091        else:
     4092            if m >= 0:
     4093                line += ' + '
     4094            else:
     4095                line += ' - '
     4096            m = abs(m)
     4097        line += '%.3f*%s '%(m,var)
     4098        varMean = G2obj.fmtVarDescr(var)
     4099        helptext += "\n" + line + " ("+ varMean + ")"
     4100    helptext += '\n\nISODISTORT full name: '+str(fullname)
     4101    return helptext
  • trunk/GSASIIdataGUI.py

    r5068 r5070  
    63096309        G2G.Define_wxId('wxID_FOURCALC', 'wxID_FOURSEARCH', 'wxID_FOURCLEAR','wxID_CHARGEFLIP','wxID_VALIDPROTEIN',
    63106310            'wxID_MULTIMCSA','wxID_SINGLEMCSA', 'wxID_4DCHARGEFLIP', 'wxID_TRANSFORMSTRUCTURE','wxID_USEBILBAOMAG',
    6311             'wxID_COMPARESTRUCTURE','wxID_ISODISTORT')
     6311            'wxID_COMPARESTRUCTURE')
    63126312        self.DataGeneral = wx.MenuBar()
    63136313        self.PrefillDataMenu(self.DataGeneral)
     
    63246324        self.GeneralCalc.Append(G2G.wxID_MULTIMCSA,'Multi MC/SA','Run Monte Carlo - Simulated Annealing on multiprocessors')
    63256325        self.GeneralCalc.Append(G2G.wxID_TRANSFORMSTRUCTURE,'Transform','Transform crystal structure')
    6326         self.GeneralCalc.Append(G2G.wxID_ISODISTORT,'Run ISODISTORT','Run ISODISTORT for PDFfit constraints')
    63276326        self.GeneralCalc.Append(G2G.wxID_COMPARESTRUCTURE,'Compare','Compare polyhedra to ideal octahedra/tetrahedra')
    63286327        self.GeneralCalc.Enable(G2G.wxID_COMPARESTRUCTURE,False)   
     
    64456444        self.ISODDataEdit = wx.Menu(title='')
    64466445        self.ISODData.Append(menu=self.ISODDataEdit, title='Operations')
    6447         G2G.Define_wxId('wxID_ISODISTORT1')
    6448         self.ISODDataEdit.Append(G2G.wxID_ISODISTORT1,'Run ISODISTORT','Run ISODISTORT to find displacement modes')
     6446        G2G.Define_wxId('wxID_ISODISTORT')
     6447        self.ISODDataEdit.Append(G2G.wxID_ISODISTORT,'Run ISODISTORT','Run ISODISTORT to find displacement modes')
    64496448        G2G.Define_wxId('wxID_ISODNEWPHASE')
    64506449        self.ISODDataEdit.Append(G2G.wxID_ISODNEWPHASE,'Make CIF file','From ISODISTORT selection')
    64516450        G2G.Define_wxId('wxID_SHOWISO1')
    64526451        self.ISODDataEdit.Append(G2G.wxID_SHOWISO1,'Show ISODISTORT modes',
    6453                 'Show ISODISTORT mode values for all phases')
     6452                'Show ISODISTORT mode values for current phase')
     6453        G2G.Define_wxId('wxID_SHOWISOMODES')
     6454        self.ISODDataEdit.Append(G2G.wxID_SHOWISOMODES,'Show ISODISTORT relationships',
     6455                'Show how ISODISTORT modes are defined in current phase')
    64546456        self.PostfillDataMenu()
    64556457
  • trunk/GSASIImath.py

    r5067 r5070  
    21302130    Uncertainties are computed if covdata is supplied.
    21312131
     2132    :param dict Phase: contents of tree entry for selected phase
     2133    :param dict parmDict: a dict with values for the modes; note that in the
     2134       parmDict from refinements the mode values are not normalized,
     2135       but this assumes they are.
     2136    :param dict Phase: full covariance information from tree
     2137
    21322138    :returns: modeDict,posDict where modeDict contains pairs of mode values
    21332139    and mode s.u. values; posDict contains pairs of displacement values
  • trunk/GSASIIphsGUI.py

    r5068 r5070  
    29202920        '''
    29212921        import ISODISTORT as ISO
    2922         dlg = wx.FileDialog(General, 'Choose parent cif file for ISODISTORT',G2G.GetImportPath(G2frame),
    2923             style=wx.FD_OPEN ,wildcard='(*.cif)|*.cif')
    2924         if dlg.ShowModal() == wx.ID_OK:
    2925             fpath,parentcif = os.path.split(dlg.GetPath())
    2926             wx.BeginBusyCursor()
    2927             radio,rundata = ISO.GetISODISTORT(data,parentcif)
    2928             wx.EndBusyCursor()
    2929             if radio and rundata:
    2930                 data['ISODISTORT']['radio'] = radio
    2931                 data['ISODISTORT']['rundata'] = rundata
    2932                 data['ISODISTORT']['SGselect'] =  {'Tric':True,'Mono':True,'Orth':True,'Tetr':True,'Trig':True,'Hexa':True,'Cubi':True}
    2933                 data['ISODISTORT']['selection'] = None
    2934                 print('ISODISTORT run complete')
    2935                 UpdateISODISTORT()
    2936             else:
    2937                 G2G.G2MessageBox(G2frame,'ISODISTORT run failed - see page opened in web browser')
     2922        # Use GSAS2Scriptable to make a CIF for the current phase in a
     2923        # scratch directory
     2924        data['pId'] = data.get('pId',0) # needs a pId
     2925        import GSASIIscriptable as G2sc
     2926        import tempfile
     2927        wx.BeginBusyCursor()
     2928        proj = G2sc.G2Project(newgpx='tmp4cif.gpx')
     2929        ph = G2sc.G2Phase(data,data['General']['Name'],proj)
     2930        tmpdir = tempfile.TemporaryDirectory()
     2931        parentcif = os.path.join(tmpdir.name,'ISOin.cif')
     2932        ph.export_CIF(parentcif)
     2933        radio,rundata = ISO.GetISODISTORT(data,parentcif)
     2934        wx.EndBusyCursor()
     2935        tmpdir.cleanup()
     2936        if radio and rundata:
     2937            data['ISODISTORT']['radio'] = radio
     2938            data['ISODISTORT']['rundata'] = rundata
     2939            data['ISODISTORT']['SGselect'] =  {'Tric':True,'Mono':True,'Orth':True,'Tetr':True,'Trig':True,'Hexa':True,'Cubi':True}
     2940            data['ISODISTORT']['selection'] = None
     2941            print('ISODISTORT run complete')
     2942            wx.CallAfter(UpdateISODISTORT)
    29382943        else:
    2939             G2G.G2MessageBox(G2frame,'ISODISTORT run cancelled')       
     2944            G2G.G2MessageBox(G2frame,'ISODISTORT run failed - see page opened in web browser')
    29402945               
    29412946    def OnCompare(event):
     
    44334438            G2obj.IndexAllIds(Histograms,Phases)
    44344439        G2cnstG.ShowIsoDistortCalc(G2frame,data['General']['Name'])
    4435            
     4440
     4441    def OnShowIsoModes(event):
     4442        Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
     4443        if Histograms and Phases:
     4444            G2obj.IndexAllIds(Histograms,Phases)
     4445        #import imp
     4446        #imp.reload(G2cnstG)
     4447        G2cnstG.ShowIsoModes(G2frame,data['General']['Name'])
     4448       
    44364449    def OnReImport(event):
    44374450        generalData = data['General']
     
    68136826                    ('G2VarList' in data['ISODISTORT']) or
    68146827                    ('G2OccVarList' in data['ISODISTORT']))
     6828        G2frame.dataWindow.ISODDataEdit.Enable(G2G.wxID_SHOWISOMODES,
     6829                    ('G2VarList' in data['ISODISTORT'])
     6830#                    or ('G2OccVarList' in data['ISODISTORT'])
     6831                                                   )
    68156832        if 'radio' not in data['ISODISTORT']:
    68166833            if not data['ISODISTORT']:
    68176834                mainSizer = wx.BoxSizer(wx.VERTICAL)
    6818                 mainSizer.Add(wx.StaticText(ISODIST,label='No ISODISTORT information found for this phase'))
     6835                mainSizer.Add(wx.StaticText(ISODIST,
     6836                        label='No ISODISTORT information found for this phase\n'
     6837                            +'  (use Operations->Run ISODISTORT to generate)'))
    68196838                SetPhaseWindow(ISODIST,mainSizer,Scroll=Scroll)               
    68206839                return
     
    1353513554        G2frame.Bind(wx.EVT_MENU, OnRunMultiMCSA, id=G2G.wxID_MULTIMCSA)
    1353613555        G2frame.Bind(wx.EVT_MENU, OnTransform, id=G2G.wxID_TRANSFORMSTRUCTURE)
    13537         G2frame.Bind(wx.EVT_MENU, OnRunISODISTORT, id=G2G.wxID_ISODISTORT)
    1353813556        G2frame.Bind(wx.EVT_MENU, OnCompare, id=G2G.wxID_COMPARESTRUCTURE)
    1353913557        G2frame.Bind(wx.EVT_MENU, OnUseBilbao, id=G2G.wxID_USEBILBAOMAG)
     
    1366013678        # ISODISTORT
    1366113679        FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.ISODData)
    13662         G2frame.Bind(wx.EVT_MENU, OnRunISODISTORT, id=G2G.wxID_ISODISTORT1)
     13680        G2frame.Bind(wx.EVT_MENU, OnRunISODISTORT, id=G2G.wxID_ISODISTORT)
    1366313681        G2frame.Bind(wx.EVT_MENU, OnNewISOPhase, id=G2G.wxID_ISODNEWPHASE)
    1366413682        G2frame.Bind(wx.EVT_MENU, OnShowIsoDistortCalc, id=G2G.wxID_SHOWISO1)
     13683        G2frame.Bind(wx.EVT_MENU, OnShowIsoModes, id=G2G.wxID_SHOWISOMODES)
    1366513684        # MC/SA
    1366613685        FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.MCSAMenu)
  • trunk/GSASIIscriptable.py

    r5042 r5070  
    12741274import GSASIIimage as G2img
    12751275import GSASIIlattice as G2lat
     1276import GSASIImapvars as G2mv
    12761277
    12771278# Delay imports to not slow down small scripts that don't need them
     
    23962397
    23972398        data = self.data['Phases'][phasename]
    2398         generalData = data['General']
    2399         SGData = generalData['SGData']
    2400         NShkl = len(G2spc.MustrainNames(SGData))
    2401         NDij = len(G2spc.HStrainNames(SGData))
    2402         Super = generalData.get('Super', 0)
    2403         if Super:
    2404             SuperVec = np.array(generalData['SuperVec'][0])
    2405         else:
    2406             SuperVec = []
    2407         UseList = data['Histograms']
     2399#        generalData = data['General']
     2400#        SGData = generalData['SGData']
     2401#        NShkl = len(G2spc.MustrainNames(SGData))
     2402#        NDij = len(G2spc.HStrainNames(SGData))
     2403#        Super = generalData.get('Super', 0)
     2404#        if Super:
     2405#            SuperVec = np.array(generalData['SuperVec'][0])
     2406#        else:
     2407#            SuperVec = []
     2408#        UseList = data['Histograms']
    24082409
    24092410        for hist in histograms:
     
    50745075            # TODO get esds
    50755076            cellDict = self.get_cell()
    5076             defsigL = 3*[-0.00001] + 3*[-0.001] + [-0.01] # significance to use when no sigma
    5077             names = ['length_a','length_b','length_c',
    5078                      'angle_alpha','angle_beta ','angle_gamma',
    5079                      'volume']
     5077#            defsigL = 3*[-0.00001] + 3*[-0.001] + [-0.01] # significance to use when no sigma
     5078#            names = ['length_a','length_b','length_c',
     5079#                     'angle_alpha','angle_beta ','angle_gamma',
     5080#                     'volume']
    50805081            for key, val in cellDict.items():
    50815082                cif.WriteCIFitem(fp, '_cell_' + key, G2mth.ValEsd(val))
  • trunk/ISODISTORT.py

    r5065 r5070  
    22"""
    33*ISODISTORT: Interface to BYU ISODISTORT web pages*
    4 -------------------------------
     4------------------------------------------------------
    55
    66
  • trunk/imports/G2phase_CIF.py

    r5067 r5070  
    984984        def fmtEqn(i,head,l,var,k):
    985985            'format a section of a row of variables and multipliers'
    986             if k == 0: return head,l
     986            if np.isclose(k,0): return head,l
    987987            if len(head) + len(l) > 65:
    988988                print(head+l)
Note: See TracChangeset for help on using the changeset viewer.