Changeset 5278 for trunk


Ignore:
Timestamp:
May 16, 2022 2:05:08 PM (3 years ago)
Author:
toby
Message:

pdffit2 binary split from .py files; works on Mac

Location:
trunk
Files:
1 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIctrlGUI.py

    r5269 r5278  
    24892489def G2MessageBox(parent,msg,title='Error'):
    24902490    '''Simple code to display a error or warning message
     2491
     2492    TODO: replace wx.MessageDialog with one derived from wx.Dialog because
     2493    on most platforms wx.MessageDialog is a native widget and CentreOnParent
     2494    will not function.
    24912495    '''
    24922496    dlg = wx.MessageDialog(parent,StripIndents(msg), title, wx.OK|wx.CENTRE)
  • TabularUnified trunk/GSASIIphsGUI.py

    r5272 r5278  
    63506350            G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True)
    63516351            RMCPdict = data['RMC']['PDFfit']
    6352             G2pwd.MakePDFfitAtomsFile(data,RMCPdict)
     6352            msg = G2pwd.MakePDFfitAtomsFile(data,RMCPdict)
     6353            if msg:
     6354                G2G.G2MessageBox(G2frame,'ERROR: '+msg,'PDFfit setup failure')
     6355                return
    63536356            fname = G2pwd.MakePDFfitRunFile(data,RMCPdict)
    63546357            if fname is None:
     
    63616364        generalData = data['General']
    63626365        ISOdict = data['ISODISTORT']
    6363         PDFfit_exec = G2pwd.findPDFfit()  #returns location of python (not pdffit!)
     6366        PDFfit_exec,_ = G2pwd.findPDFfit()  #returns location of python with PDFfit installed and path(s) for  pdffit
    63646367        if not PDFfit_exec:
    63656368            wx.MessageBox(''' PDFfit2 is not currently installed for this platform.
  • TabularUnified trunk/GSASIIpwd.py

    r5273 r5278  
    7474sateln2 = np.sqrt(ateln2)
    7575nxs = np.newaxis
     76is_exe = lambda fpath: os.path.isfile(fpath) and os.access(fpath, os.X_OK)
    7677
    7778#### Powder utilities ################################################################################
     
    31643165      have fullrmc installed or None, if it was not found.
    31653166    '''
    3166     is_exe = lambda fpath: os.path.isfile(fpath) and os.access(fpath, os.X_OK)
    31673167    if GSASIIpath.GetConfigValue('fullrmc_exec') is not None and is_exe(
    31683168            GSASIIpath.GetConfigValue('fullrmc_exec')):
     
    31893189        if len(fl) > 0:
    31903190            return os.path.abspath(sorted(fl)[0])
    3191        
     3191
    31923192def findPDFfit():
    31933193    '''Find if PDFfit2 is installed (may be local to GSAS-II). Does the following:
    3194     :returns: the full path to a python executable or None, if it was not found.
     3194    :returns: two items: (1) the full path to a python executable or None, if
     3195    it was not found and (2) path(s) to the PDFfit2 location(s) as a list.
     3196   
    31953197    '''
    31963198    if GSASIIpath.GetConfigValue('pdffit2_exec') is not None and is_exe(
    31973199            GSASIIpath.GetConfigValue('pdffit2_exec')):
    3198         return GSASIIpath.GetConfigValue('pdffit2_exec')
     3200        return GSASIIpath.GetConfigValue('pdffit2_exec'),None
     3201    pdffitloc = os.path.join(GSASIIpath.path2GSAS2,'PDFfit2')
     3202    if not os.path.exists(pdffitloc):
     3203        print('PDFfit2 not found in GSAS-II \n\t(expected in '+pdffitloc+')')
     3204        return None,[]
     3205    if pdffitloc not in sys.path: sys.path.append(pdffitloc)
    31993206    try:
    3200         if GSASIIpath.path2GSAS2 not in sys.path:
    3201             sys.path.insert(0,GSASIIpath.path2GSAS2)
    32023207        from diffpy.pdffit2 import PdfFit
    3203         return sys.executable
     3208        import diffpy
     3209        import inspect
     3210        pdffitloc = [os.path.dirname(os.path.dirname(inspect.getfile(diffpy)))]
     3211        # is this the original version of diffpy (w/pdffit2.py)
     3212        try:
     3213            from diffpy.pdffit2 import pdffit2
     3214        except ImportError:
     3215            # or the GSAS-II version w/o; for this we need to find the binary's location
     3216            try:
     3217                import pdffit2     # added for GSAS-II to relocate binary file
     3218            except ImportError:
     3219                print('\nError: pdffit2 failed to load with this python\n')
     3220                return None,[]
     3221            except ModuleNotFoundError:
     3222                print('\nGSAS-II does not have a PDFfit2 module compatible\nwith this Python interpreter\n')
     3223                return None,[]
     3224            pdffitloc += [os.path.dirname(inspect.getfile(pdffit2))]
     3225        return sys.executable,pdffitloc
    32043226    except Exception as msg:
    3205         print('Error from PDFfit2 access:\n',msg)
    3206         return None
     3227        print('Error importing PDFfit2:\n',msg)
     3228        return None,[]
    32073229   
    32083230def GetPDFfitAtomVar(Phase,RMCPdict):
     
    32383260    '''
    32393261    General = Phase['General']
     3262    if General['SGData']['SpGrp'] != 'P 1':
     3263        return 'Space group symmetry must be lowered to P 1 for PDFfit'
    32403264    fName = General['Name']+'-PDFfit.stru'
    32413265    fName = fName.replace(' ','_')
     
    32983322    General = Phase['General']
    32993323    Cell = General['Cell'][1:7]
    3300     G2path = GSASIIpath.path2GSAS2
    3301     rundata = '''
    3302 #!/usr/bin/env python
     3324    rundata = '''#!/usr/bin/env python
    33033325# -*- coding: utf-8 -*-
    33043326import sys
    3305 sys.path.append('%s')
    3306 from diffpy.pdffit2 import PdfFit
    3307 pf = PdfFit()
    3308 '''%G2path
     3327'''
     3328    PDFfit_exe,PDFfit_path = findPDFfit()  # returns python loc and path(s) for pdffit
     3329    if not PDFfit_exe:
     3330        GSASIIpath.IPyBreak()
     3331        return None
     3332    for p in PDFfit_path:
     3333        rundata += "sys.path.append('{:}')\n".format(p)
     3334    rundata += 'from diffpy.pdffit2 import PdfFit\n'
     3335    rundata += 'pf = PdfFit()\n'
    33093336    Nd = 0
    33103337    Np = 0
     
    33153342        rundata += '#sequential data here\n'
    33163343    else:
    3317         for file in RMCPdict['files']:
    3318             if 'Select' in RMCPdict['files'][file][0]:
     3344        for fil in RMCPdict['files']:
     3345            filNam = RMCPdict['files'][fil][0]
     3346            if 'Select' in filNam:
    33193347                continue
    3320             if 'Neutron' in file:
     3348            if 'Neutron' in fil:
    33213349                Nd += 1
    33223350                dType = 'Ndata'
     
    33243352                Nd += 1
    33253353                dType = 'Xdata'
    3326             rundata += "pf.read_data('%s', '%s', 30.0, %.4f)\n"%(RMCPdict['files'][file][0],dType[0],RMCPdict[dType]['qdamp'][0])
     3354            filNam = os.path.abspath(filNam)
     3355            rundata += "pf.read_data('%s', '%s', 30.0, %.4f)\n"%(filNam,dType[0],RMCPdict[dType]['qdamp'][0])
    33273356            rundata += 'pf.setdata(%d)\n'%Nd
    33283357            rundata += 'pf.pdfrange(%d, %6.2f, %6.2f)\n'%(Nd,RMCPdict[dType]['Fitrange'][0],RMCPdict[dType]['Fitrange'][1])
     
    33383367        fName = 'Sequential_PDFfit.stru'
    33393368    Np = 9
    3340     rundata += "pf.read_struct('%s')\n"%(fName)
     3369    rundata += "pf.read_struct('{:}')\n".format(os.path.abspath(fName))
    33413370    for item in ['delta1','delta2','sratio']:
    33423371        if RMCPdict[item][1]:
  • TabularUnified trunk/PDFfit2/diffpy/pdffit2/pdffit.py

    r5096 r5278  
    2727# crash with AttributeError when executed during imports of
    2828# parent packages.
    29 from diffpy.pdffit2 import pdffit2
     29try:
     30    from diffpy.pdffit2 import pdffit2
     31except:
     32    import pdffit2     # added for GSAS-II to relocate binary file
    3033from diffpy.pdffit2 import output
    3134
Note: See TracChangeset for help on using the changeset viewer.