Changeset 5164


Ignore:
Timestamp:
Jan 28, 2022 8:39:44 AM (5 months ago)
Author:
toby
Message:

some PWD cleanups from Laue Fringe work & fullrmc

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwd.py

    r5161 r5164  
    20622062    return True
    20632063
     2064def getHeaderInfo(FitPgm,dataType):
     2065    '''Provide parameter name, label name and formatting information for the
     2066    contents of the peak table and where used in DoPeakFit
     2067    '''
     2068    names = ['pos','int']
     2069    lnames = ['position','intensity']
     2070    if FitPgm == 'LaueFringe':
     2071        names += ['sig','gam','cells']
     2072        lnames += ['sigma','gamma','cells']
     2073        fmt = ["%10.5f","%10.3f","%10.3f","%10.3f","%10.3f"]
     2074    elif 'C' in dataType:
     2075        names += ['sig','gam']
     2076        lnames += ['sigma','gamma']
     2077        fmt = ["%10.5f","%10.1f","%10.3f","%10.3f"]
     2078    elif 'T' in dataType:
     2079        names += ['alp','bet','sig','gam']
     2080        lnames += ['alpha','beta','sigma','gamma']
     2081        fmt = ["%10.2f","%10.4f","%8.3f","%8.5f","%10.3f","%10.3f"]
     2082    elif 'E' in dataType:
     2083        names += ['sig']
     2084        lnames += ['sigma']
     2085        fmt = ["%10.5f","%10.1f","%8.3f"]
     2086    else: # 'B'
     2087        names += ['alp','bet','sig','gam']
     2088        lnames += ['alpha','beta','sigma','gamma']
     2089        fmt = ["%10.5f","%10.1f","%8.2f","%8.4f","%10.3f","%10.3f"]
     2090    return names, fmt, lnames
     2091
    20642092def DoPeakFit(FitPgm,Peaks,Background,Limits,Inst,Inst2,data,fixback=None,prevVaryList=[],oneCycle=False,controls=None,wtFactor=1.0,dlg=None,noFit=False):
    20652093    '''Called to perform a peak fit, refining the selected items in the peak
     
    22492277        peakVary = []
    22502278        peakVals = []
    2251         if 'C' in dataType:
    2252             names = ['pos','int','sig','gam']
    2253         elif 'E' in dataType:
    2254             names = ['pos','int','sig']
    2255         else:   #'T' and 'B'
    2256             names = ['pos','int','alp','bet','sig','gam']
     2279        names,_,_ = getHeaderInfo(FitPgm,dataType)
    22572280        for i,peak in enumerate(Peaks):
    22582281            for j,name in enumerate(names):
     
    22652288               
    22662289    def GetPeaksParms(Inst,parmDict,Peaks,varyList):
    2267         if 'C' in Inst['Type'][0]:
    2268             names = ['pos','int','sig','gam']
    2269         elif 'E' in Inst['Type'][0]:
    2270             names = ['pos','int','sig']
    2271         else:   #'T' & 'B'
    2272             names = ['pos','int','alp','bet','sig','gam']
     2290        names,_,_ = getHeaderInfo(FitPgm,Inst['Type'][0])
    22732291        for i,peak in enumerate(Peaks):
    22742292            pos = parmDict['pos'+str(i)]
     
    23042322    def PeaksPrint(dataType,parmDict,sigDict,varyList,ptsperFW):
    23052323        print ('Peak coefficients:')
    2306         if 'C' in dataType:
    2307             names = ['pos','int','sig','gam']
    2308         elif 'E' in dataType:
    2309             names = ['pos','int','sig']
    2310         else:   #'T' & 'B'
    2311             names = ['pos','int','alp','bet','sig','gam']           
     2324        names,fmt,_ = getHeaderInfo(FitPgm,dataType)
    23122325        head = 13*' '
    23132326        for name in names:
     
    23182331        head += 'bins'.center(8)
    23192332        print (head)
    2320         if 'C' in dataType:
    2321             ptfmt = {'pos':"%10.5f",'int':"%10.1f",'sig':"%10.3f",'gam':"%10.3f"}
    2322         elif 'E' in dataType:
    2323             ptfmt = {'pos':"%10.5f",'int':"%10.1f",'sig':"%10.3f"}
    2324         elif 'T' in dataType:
    2325             ptfmt = {'pos':"%10.2f",'int':"%10.4f",'alp':"%8.3f",'bet':"%8.5f",'sig':"%10.3f",'gam':"%10.3f"}
    2326         else: #'B'
    2327             ptfmt = {'pos':"%10.5f",'int':"%10.1f",'alp':"%8.2f",'bet':"%8.4f",'sig':"%10.3f",'gam':"%10.3f"}
     2333        ptfmt = dict(zip(names,fmt))
    23282334        for i,peak in enumerate(Peaks):
    23292335            ptstr =  ':'
     
    34703476
    34713477def calcRmax(ENGINE):
    3472     'from Bachir, works for non-othorhombic'
     3478    'from Bachir, works for non-orthorhombic cells'
    34733479    a,b,c = ENGINE.basisVectors
    34743480    lens = []
     
    35653571        else:
    35663572            print('What is this?')
    3567     rundata += '    ENGINE.add_constraints(DistanceConstraint(defaultLowerDistance={}))\n'.format(RMCPdict['min Contact'])
     3573    minDists = ''
    35683574    if BondList:
    35693575        rundata += '''    B_CONSTRAINT   = BondConstraint()
     
    35763582            if d1 == 0: continue
    35773583            if d2 == 0:
    3578                 print('Ignoring min distance without maximum')
    3579                 #rundata += '            ("element","{}","{}",{}),\n'.format(
    3580                 #                        e1.strip(),e2.strip(),d1)
     3584                minDists += '("element","{}","{}",{}),'.format(e1.strip(),e2.strip(),d1)
    35813585            else:
    35823586                rundata += '            ("element","{}","{}",{},{}),\n'.format(
    35833587                                        e1.strip(),e2.strip(),d1,d2)
    35843588        rundata += '             ])\n'
     3589    rundata += '    D_CONSTRAINT = DistanceConstraint(defaultLowerDistance={})\n'.format(RMCPdict['min Contact'])
     3590    if minDists:
     3591        rundata += "    D_CONSTRAINT.set_pairs_definition( {'inter':[" + minDists + "]})\n"
     3592    rundata += '    ENGINE.add_constraints(D_CONSTRAINT)\n'
     3593   
    35853594    if AngleList:
    35863595        rundata += '''    A_CONSTRAINT   = BondsAngleConstraint()
  • trunk/GSASIIpwdGUI.py

    r5140 r5164  
    431431    else:
    432432        hLam = 0
    433     sample = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Sample Parameters'))
     433#    sample = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Sample Parameters'))
    434434#    hGeom = sample.get('Type')
    435435    hstName = G2frame.GPXtree.GetItemText(G2frame.PatternId)
     
    440440        name = G2frame.GPXtree.GetItemText(item)
    441441        if name.startswith(hPrefix) and name != hstName:
    442             cGeom,cType,cLam, = '?','?',-1
     442            cType,cLam, = '?',-1
    443443            subitem, subcookie = G2frame.GPXtree.GetFirstChild(item)
    444444            while subitem:
    445445                subname = G2frame.GPXtree.GetItemText(subitem)
    446446                if subname == 'Sample Parameters':
    447                     sample = G2frame.GPXtree.GetItemPyData(subitem)
    448 #                    cGeom = sample.get('Type')
     447                    # sample = G2frame.GPXtree.GetItemPyData(subitem)
     448                    # cGeom = sample.get('Type')
     449                    pass
    449450                elif subname == 'Instrument Parameters':
    450451                    inst,inst2 = G2frame.GPXtree.GetItemPyData(subitem)
     
    948949           for c in range(reflGrid.GetNumberCols()):
    949950               if reflGrid.GetColLabelValue(c) in ['position','intensity','alpha','beta','sigma','gamma']:
    950                    if float(reflGrid.GetCellValue(r,c)) < 0.:
    951                        reflGrid.SetCellBackgroundColour(r,c,wx.RED)
    952                    else:
    953                        reflGrid.SetCellBackgroundColour(r,c,wx.WHITE)
    954                                                  
     951                   try:
     952                       if float(reflGrid.GetCellValue(r,c)) < 0.:
     953                           reflGrid.SetCellBackgroundColour(r,c,wx.RED)
     954                       else:
     955                           reflGrid.SetCellBackgroundColour(r,c,wx.WHITE)
     956                   except:
     957                        pass
     958                   
    955959    def KeyEditPeakGrid(event):
    956960        '''Respond to pressing a key to act on selection of a row, column or cell
     
    10841088        'Redraw the peak listings after the mode changes'
    10851089        wx.CallAfter(UpdatePeakGrid,G2frame,data)
     1090#        wx.CallLater(100,RefreshPeakGrid,None)
    10861091
    10871092    def RefreshPeakGrid(event):
     
    10931098       
    10941099    #======================================================================
    1095     # beginning of UpdatePeakGrid init
     1100    #### beginning of UpdatePeakGrid
    10961101    #======================================================================
    10971102#    data['FitPgm'] = data.get('FitPgm',0)
     
    11271132    Inst = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId, 'Instrument Parameters'))[0]
    11281133    for i in range(len(data['peaks'])): rowLabels.append(str(i+1))
    1129 #    if data.get('FitPgm',0) == 1:
    1130 #        colLabels = ['position','refine','intensity','refine','cells','refine']
    1131 #        Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL,
    1132 #            wg.GRID_VALUE_FLOAT+':10,3',wg.GRID_VALUE_BOOL,
    1133 #            wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL]
    1134 #        # TODO: note gamma values can still be set as refined
    1135 #    elif 'C' in Inst['Type'][0]:
    1136     if 'C' in Inst['Type'][0]:
    1137         colLabels = ['position','refine','intensity','refine','sigma','refine','gamma','refine']
    1138         Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL,
    1139             wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL,
    1140             wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL,
    1141             wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL]
    1142     elif 'E' in Inst['Type'][0]:
    1143         colLabels = ['position','refine','intensity','refine','sigma','refine']
    1144         Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL,
    1145             wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL,
    1146             wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL]
    1147     else:
    1148         colLabels = ['position','refine','intensity','refine','alpha','refine',
    1149             'beta','refine','sigma','refine','gamma','refine']
    1150         if 'T' in Inst['Type'][0]:
    1151             Types = [wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL,
    1152                 wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL,
    1153                 wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL,
    1154                 wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL,
    1155                 wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL,
    1156                 wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL]
    1157         else:  #'B'
    1158             Types = [wg.GRID_VALUE_FLOAT+':10,4',wg.GRID_VALUE_BOOL,
    1159                 wg.GRID_VALUE_FLOAT+':10,1',wg.GRID_VALUE_BOOL,
    1160                 wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL,
    1161                 wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL,
    1162                 wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL,
    1163                 wg.GRID_VALUE_FLOAT+':10,5',wg.GRID_VALUE_BOOL]
     1134    colLabels = []
     1135    Types = []
     1136    for _,f,l in zip(*G2pwd.getHeaderInfo(
     1137        ('LSQ','LaueFringe')[data.get('FitPgm',0)],Inst['Type'][0])):
     1138        colLabels.append(l)
     1139        colLabels.append('refine')
     1140        Types.append(wg.GRID_VALUE_FLOAT +
     1141                         f.replace('%',':').replace('f','').replace('.',','))
     1142        Types.append(wg.GRID_VALUE_BOOL)
    11641143    T = []
    11651144    for peak in data['peaks']:
     
    11721151    for key in T: X.append(D[key])
    11731152    data['peaks'] = X
     1153    # pad peak table, if needed
     1154    for j in range(len(data['peaks'])):
     1155        for i in range(len(data['peaks'][j]),len(colLabels)):
     1156            if colLabels[i] == 'refine':
     1157                data['peaks'][j].append(False)
     1158            else:
     1159                data['peaks'][j].append(1.0)
    11741160    G2frame.dataWindow.ClearData()
    11751161    mainSizer = wx.BoxSizer(wx.VERTICAL)
Note: See TracChangeset for help on using the changeset viewer.