Changeset 570 for trunk/GSASIIstruct.py


Ignore:
Timestamp:
Apr 24, 2012 12:19:19 PM (10 years ago)
Author:
toby
Message:

Add checks on constraints: if problems display error window when displayed, added/edited & on Refine; handle GPX w/o doPawley flag

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIstruct.py

    r567 r570  
    7171                constList += constDict[item]
    7272    fl.close()
     73    constDict,fixedList,ignored = ProcessConstraints(constList)
     74    if ignored:
     75        print ignored,'old-style Constraints were rejected'
     76    return constDict,fixedList
     77   
     78def ProcessConstraints(constList):
     79    "interpret constraints"
    7380    constDict = []
    7481    fixedList = []
     
    106113        else:
    107114            ignored += 1
    108     if ignored:
    109         print ignored,'old-style Constraints were rejected'
    110     return constDict,fixedList
     115    return constDict,fixedList,ignored
     116
     117def CheckConstraints(GPXfile):
     118    '''Load constraints and related info and return any error or warning messages'''
     119    # get variables
     120    Histograms,Phases = GetUsedHistogramsAndPhases(GPXfile)
     121    if not Phases:
     122        return 'Error: No Phases!',''
     123    if not Histograms:
     124        return 'Error: no diffraction data',''
     125    Natoms,phaseVary,phaseDict,pawleyLookup,FFtables,BLtables = GetPhaseData(Phases)
     126    hapVary,hapDict,controlDict = GetHistogramPhaseData(Phases,Histograms)
     127    histVary,histDict,controlDict = GetHistogramData(Histograms)
     128    varyList = phaseVary+hapVary+histVary
     129    # setup constraints
     130    G2mv.InitVars()   
     131    constrDict,fixedList = GetConstraints(GPXfile)
     132    return G2mv.CheckConstraints(varyList,constrDict,fixedList)
    111133   
    112134def GetPhaseNames(GPXfile):
     
    628650            phaseVary += cellVary(pfx,SGData)
    629651        Natoms[pfx] = 0
    630         if Atoms and not General['doPawley']:
     652        if Atoms and not General.get('doPawley'):
    631653            if General['Type'] == 'nuclear':
    632654                Natoms[pfx] = len(Atoms)
     
    932954            print sigstr
    933955           
    934         if Phase['General']['doPawley']:
     956        if Phase['General'].get('doPawley'):
    935957            pawleyRef = Phase['Pawley ref']
    936958            for i,refl in enumerate(pawleyRef):
     
    24192441        GA,GB = G2lat.Gmat2AB(G)    #Orthogonalization matricies
    24202442        Vst = np.sqrt(nl.det(G))    #V*
    2421         if not Phase['General']['doPawley']:
     2443        if not Phase['General'].get('doPawley'):
    24222444            refList = StructureFactor(refList,G,hfx,pfx,SGData,calcControls,parmDict)
    24232445        for refl in refList:
     
    24302452                GetIntensityCorr(refl,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict)    #puts corrections in refl[13]
    24312453                refl[13] *= Vst*Lorenz
    2432                 if Phase['General']['doPawley']:
     2454                if Phase['General'].get('doPawley'):
    24332455                    try:
    24342456                        refl[9] = abs(parmDict[pfx+'PWLref:%d'%(pawleyLookup[pfx+'%d,%d,%d'%(h,k,l)])])
     
    25312553        G,g = G2lat.A2Gmat(A)       #recip & real metric tensors
    25322554        GA,GB = G2lat.Gmat2AB(G)    #Orthogonalization matricies
    2533         if not Phase['General']['doPawley']:
     2555        if not Phase['General'].get('doPawley'):
    25342556            dFdvDict = StructureFactorDerv(refList,G,hfx,pfx,SGData,calcControls,parmDict)
    25352557        for iref,refl in enumerate(refList):
     
    25372559                h,k,l = refl[:3]
    25382560                dIdsh,dIdsp,dIdpola,dIdPO,dFdODF,dFdSA = GetIntensityDerv(refl,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict)
    2539                 if Phase['General']['doPawley']:
     2561                if Phase['General'].get('doPawley'):
    25402562                    try:
    25412563                        refl[9] = abs(parmDict[pfx+'PWLref:%d'%(pawleyLookup[pfx+'%d,%d,%d'%(h,k,l)])])
     
    25742596                        dMdpk2[5] = 100.*dx*refl[13]*dMdipk2[0]
    25752597                        dervDict2 = {'int':dMdpk2[0],'pos':dMdpk2[1],'sig':dMdpk2[2],'gam':dMdpk2[3],'shl':dMdpk2[4],'L1/L2':dMdpk2[5]*refl[9]}
    2576                 if Phase['General']['doPawley']:
     2598                if Phase['General'].get('doPawley'):
    25772599                    try:
    25782600                        idx = varylist.index(pfx+'PWLref:'+str(pawleyLookup[pfx+'%d,%d,%d'%(h,k,l)]))
     
    28372859    Histograms,Phases = GetUsedHistogramsAndPhases(GPXfile)
    28382860    if not Phases:
    2839         print ' *** ERROR - you have no histograms to refine! ***'
     2861        print ' *** ERROR - you have no phases! ***'
    28402862        print ' *** Refine aborted ***'
    28412863        raise Exception
     
    28642886        print ' *** ERROR - your constraints are internally inconsistent ***'
    28652887        # traceback for debug
     2888        #print 'varyList',varyList
     2889        #print 'constrDict',constrDict
     2890        #print 'fixedList',fixedList
    28662891        #import traceback
    28672892        #print traceback.format_exc()
Note: See TracChangeset for help on using the changeset viewer.