Changeset 5285 for trunk/GSASIIphsGUI.py


Ignore:
Timestamp:
May 20, 2022 12:35:20 PM (19 months ago)
Author:
toby
Message:

multiple PDFfit2 changes; seems to work well on Windows w/3.7, 3.8 & 3.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIphsGUI.py

    r5278 r5285  
    103103    Angstr = chr(0x00c5)   
    104104
     105RMCmisc = {}
    105106#### phase class definitions ################################################################################
    106107class SymOpDialog(wx.Dialog):
     
    49414942            def OnSeqReverse(event):
    49424943                RMCPdict['SeqReverse'] = not RMCPdict['SeqReverse']
    4943 
     4944               
     4945            # --- FileSizer starts here
    49444946            Indx = {}
    49454947            mainSizer = wx.BoxSizer(wx.VERTICAL)
     
    62416243        RMCsel.Bind(wx.EVT_RADIOBOX, OnRMCselect)
    62426244        mainSizer.Add(RMCsel,0)
     6245        RMCmisc['RMCnote'] = wx.StaticText(G2frame.FRMC)
     6246        mainSizer.Add(RMCmisc['RMCnote'])
    62436247        G2G.HorizontalLine(mainSizer,G2frame.FRMC)
    62446248        mainSizer.Add(wx.StaticText(G2frame.FRMC,
     
    62596263        bigSizer.Add(G2G.HelpButton(G2frame.FRMC,helpIndex=G2frame.dataWindow.helpKey))
    62606264        SetPhaseWindow(G2frame.FRMC,bigSizer)
    6261         if G2frame.RMCchoice == 'fullrmc' and G2pwd.findfullrmc() is None:
     6265        if G2frame.RMCchoice == 'PDFfit' and not checkPDFfit(G2frame):
     6266            RMCmisc['RMCnote'].SetLabel('PDFfit may not be installed or operational')
     6267        elif G2frame.RMCchoice == 'fullrmc' and G2pwd.findfullrmc() is None:
    62626268            dlg = wx.MessageDialog(G2frame,
    62636269                    'The fullrmc code is not installed or could not be'
     
    63856391        if sys.platform.lower().startswith('win'):
    63866392            batch = open('pdffit2.bat','w')
     6393            # TODO: should probably include an activate command here
    63876394            batch.write(PDFfit_exec+' '+rname+'\n')
    63886395            # batch.write('pause')
     
    63936400            batch = open('pdffit2.sh','w')
    63946401            batch.write('#!/bin/bash\n')
     6402            # TODO: should probably include an activate command here
    63956403            batch.write('cd ' + os.path.split(os.path.abspath(rname))[0] + '\n')
    63966404            batch.write(PDFfit_exec + ' ' + os.path.abspath(rname) + '\n')
     
    1456514573            return
    1456614574    ChangePage(0)
     14575
     14576def checkPDFfit(G2frame):
     14577    '''Checks to see if PDFfit2 is available and can be imported. PDFfit2 can be installed
     14578    in a separate Python interpreter (saved in the pdffit2_exec config variable). If this is
     14579    defined, no attempt is made to check that it actually runs.
     14580    Otherwise, if diffpy.PDFfit has been installed with conda/pip, it is checked if the
     14581    install command. The fallback is to check if a .so/.pyd file has been supplied with
     14582    GSAS-II. This requires that GSL (GNU Scientific Library) be installed. If the current
     14583    Python is being run from conda, this will be loaded.
     14584
     14585    :returns: False if PDFfit2 cannot be run/accessed. True if it appears it can be run.
     14586    '''
     14587    # if a separate Python interpreter has been specified, just use it, no checking
     14588    if GSASIIpath.GetConfigValue('pdffit2_exec') is not None and is_exe(
     14589            GSASIIpath.GetConfigValue('pdffit2_exec')):
     14590        return True
     14591
     14592    # see if diffpy has been installed directly
     14593    try:
     14594        from diffpy.pdffit2 import PdfFit
     14595        return True
     14596    except:
     14597        pass
     14598
     14599    # See if if we can import the GSAS-II supplied PDFfit
     14600    pdffitloc = os.path.join(GSASIIpath.path2GSAS2,'PDFfit2')
     14601    if pdffitloc not in sys.path: sys.path.append(pdffitloc)
     14602    try:
     14603        from diffpy.pdffit2 import PdfFit
     14604        #pf = PdfFit()
     14605        return True
     14606    except Exception as err:
     14607        pass
     14608        #print('Failed to import PDFfit2 with error\n:'+str(err))
     14609   
     14610    if not os.path.exists(pdffitloc):
     14611        print('PDFfit2 not found in GSAS-II \n\t(expected in '+pdffitloc+')')
     14612        return False
     14613    import glob
     14614    if not glob.glob(os.path.join(GSASIIpath.binaryPath,'pdffit*')):
     14615        msg = 'GSAS-II does not supply PDFfit2 for the version of Python that you are using'
     14616        G2G.G2MessageBox(G2frame,msg,'Need PDFfit2')
     14617        return False
     14618
     14619    # see if we can fix things so the GSAS-II version can be used
     14620    if not GSASIIpath.condaTest():
     14621        msg = ('PDFfit2 is not running with this Python installation. '+
     14622        'Since Python was not installed under conda you need to install this yourself. '+
     14623        'pip install diffpy.pdffit2" may do this for you. You will likely need to '+
     14624        'install the GSL (GNU Software Library).')
     14625        G2G.G2MessageBox(G2frame,msg,'No conda')
     14626        return False
     14627    # can we access conda?
     14628    try:
     14629        import conda.cli.python_api
     14630    except:
     14631        msg = ('You do not have the conda package installed in this '+
     14632                'environment so nothing can be installed.',
     14633                '\n\nConsider using the "conda install conda" command')
     14634        G2G.G2MessageBox(G2frame,msg,'conda import error')
     14635        return False
     14636   
     14637    if 'gsl' not in conda.cli.python_api.run_command(conda.cli.python_api.Commands.LIST,'gsl')[0].lower():
     14638        msg = ('The gsl (GNU Software Library), needed by PDFfit2, '+
     14639                   ' is not installed in this Python. Do you want to have this installed?')
     14640        dlg = wx.MessageDialog(G2frame,msg,caption='Install?',
     14641                                   style=wx.YES_NO|wx.ICON_QUESTION)
     14642        if dlg.ShowModal() != wx.ID_YES:
     14643            dlg.Destroy()
     14644            return False
     14645        dlg.Destroy()
     14646        wx.BeginBusyCursor()
     14647        print('Preparing to install gsl. This may take a few minutes...')
     14648        res = GSASIIpath.condaInstall(['gsl'])
     14649        wx.EndBusyCursor()
     14650        if res:
     14651            msg = 'Installation of the GSL package failed with error:\n' + str(res)
     14652            G2G.G2MessageBox(G2frame,msg,'Install GSL Error')
     14653           
     14654    # GSAS-II supplied version for PDFfit now runs?
     14655    if pdffitloc not in sys.path: sys.path.append(pdffitloc)
     14656    try:
     14657        from diffpy.pdffit2 import PdfFit
     14658        #pf = PdfFit()
     14659    except Exception as err:
     14660        msg = 'Failed to import PDFfit2 with error\n:'+str(err)
     14661        G2G.G2MessageBox(G2frame,msg,'PDFfit2 import error')
     14662        return False
     14663    return True
Note: See TracChangeset for help on using the changeset viewer.