Changeset 3371


Ignore:
Timestamp:
May 4, 2018 5:57:13 PM (3 years ago)
Author:
toby
Message:

constraint fixes: implement wild-card equivalences, fix use of all for phase selection in atom vars; prevent use of Edit Constr menu items for sym-generated equivalences

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIconstrGUI.py

    r3356 r3371  
    453453                elif l[3] == "all":
    454454                    for ph in phlist:
    455                         key = G2obj.LookupPhaseName(l[0])[0]
     455                        key = G2obj.LookupPhaseName(ph)[0]
    456456                        for hst in hstlist: # should be blank
    457457                            for iatm,at in enumerate(Phases[key]['Atoms']):
     
    461461                elif '=' in l[3]:
    462462                    for ph in phlist:
    463                         key = G2obj.LookupPhaseName(l[0])[0]
     463                        key = G2obj.LookupPhaseName(ph)[0]
    464464                        cx,ct,cs,cia = Phases[key]['General']['AtomPtrs']
    465465                        for hst in hstlist: # should be blank
     
    472472                else:
    473473                    for ph in phlist:
    474                         key = G2obj.LookupPhaseName(l[0])[0]
     474                        key = G2obj.LookupPhaseName(ph)[0]
    475475                        for hst in hstlist: # should be blank
    476476                            var = ph + ":" + hst + ":" + l[2] + ":" + l[3]
     
    606606        page = G2frame.Page
    607607        vartype,varList,constrDictEnt = PageSelection(page)
     608        if vartype is None: return
    608609        varList = G2obj.SortVariables(varList)
    609         if vartype is None: return
    610610        title1 = "Hold "+vartype+" variable"
    611611        if not varList:
     
    10811081        G2frame.dataWindow.ConstraintEdit.Enable(G2G.wxID_EQUIVALANCEATOMS,False)
    10821082#        G2frame.dataWindow.ConstraintEdit.Enable(G2G.wxID_ADDRIDING,False)
     1083        enableEditCons = True
    10831084        if text == 'Histogram/Phase':
    10841085            G2frame.Page = [page,'hap']
     
    11001101            UpdateConstraintPanel(GlobalConstr,'Global')
    11011102        else:
     1103            enableEditCons = False
    11021104            G2frame.Page = [page,'sym']
    1103             UpdateConstraintPanel(SymConstr,'Sym-Generated')           
     1105            UpdateConstraintPanel(SymConstr,'Sym-Generated')
     1106        # remove menu items when not allowed
     1107        for i in G2frame.dataWindow.ConstraintEdit.GetMenuItems():
     1108            i.Enable(enableEditCons)
    11041109        G2frame.dataWindow.SetDataSize()
    11051110
  • trunk/GSASIIdataGUI.py

    r3367 r3371  
    42714271            G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList,parmValDict)
    42724272            G2mv.Map2Dict(parmValDict,varyList)
    4273         except:
     4273        except G2mv.ConstraintException:
    42744274            pass
    42754275        wx.EndBusyCursor()
  • trunk/GSASIImapvars.py

    r3136 r3371  
    242242paramPrefix = "::constr"
    243243consNum = 0 # number of the next constraint to be created
     244
     245class ConstraintException(Exception):
     246    '''Defines an Exception that is used when an exception is raised processing constraints
     247    '''
     248    pass
    244249
    245250def InitVars():
     
    575580        if multarr is None: # true only if an equivalence
    576581            zeromult = False
    577             for mv in mapvars:
     582            for i,mv in enumerate(mapvars):
     583                if mv.split(':')[1] == '*' and SeqHist is not None:
     584                    # convert wildcard var to reference current histogram; save translation in table
     585                    sv = mv.split(':')
     586                    sv[1] = str(SeqHist)
     587                    mv = translateTable[mv] = ':'.join(sv)
     588                    mapvars[i] = mv
    578589                #s = ''
    579590                varied = 0
     
    589600                    #msg += "\nCannot equivalence to variable "+str(mv)+". Not defined in this refinement"
    590601                    #continue
    591             for v,m in zip(varlist,invmultarr):
     602            for i,(v,m) in enumerate(zip(varlist,invmultarr)):
     603                if v.split(':')[1] == '*' and SeqHist is not None:
     604                    # convert wildcard var to reference current histogram; save translation in table
     605                    sv = v.split(':')
     606                    sv[1] = str(SeqHist)
     607                    varlist[i] = v = translateTable[v] = ':'.join(sv)
    592608                if parmDict is not None and v not in parmDict:
    593609                    print ("Dropping equivalence for dep. variable "+str(v)+". Not defined in this refinement")
     
    661677            print (' *** ERROR in constraint definitions! ***')
    662678            print (msg)
    663             raise Exception
     679            raise ConstraintException
    664680        print ('*** Sequential refinement: ignoring constraint definition(s): ***')
    665681        print (shortmsg)
     
    670686        print (' *** ERROR in constraint definitions! ***')
    671687        print (msg)
    672         raise Exception
     688        raise ConstraintException
    673689               
    674690    # now process each group and create the relations that are needed to form
     
    762778        print (msg)
    763779        print (VarRemapShow(varyList))
    764         raise Exception
     780        raise ConstraintException
    765781    # setup dictionary containing the fixed values
    766782    global fixedDict
     
    821837    arrayList.append(None)
    822838    invarrayList.append(np.array(multlist))
    823     indParmList.append(tuple((independentVar,)))
     839    indParmList.append(list((independentVar,)))
    824840    dependentParmList.append(mapList)
    825841    symGenList.append(symGen)
     
    11621178            a[j] -= proj(a[i],a[j])
    11631179        if np.allclose(np.linalg.norm(a[j]),0.0):
    1164             raise Exception("Singular input to GramSchmidtOrtho")
     1180            raise ConstraintException("Singular input to GramSchmidtOrtho")
    11651181        a[j] /= np.linalg.norm(a[j])
    11661182    return a
     
    11971213            return
    11981214    else:
    1199         raise Exception('Singular input')
     1215        raise ConstraintException('Singular input')
    12001216
    12011217def _RowEchelon(m,arr,collist):
  • trunk/GSASIIstrMain.py

    r3369 r3371  
    204204        #print 'DependentVars',G2mv.GetDependentVars()
    205205        #print 'IndependentVars',G2mv.GetIndependentVars()
    206     except:
     206    except G2mv.ConstraintException:
    207207        print (' *** ERROR - your constraints are internally inconsistent ***')
    208208        #errmsg, warnmsg = G2mv.CheckConstraints(varyList,constrDict,fixedList)
     
    388388            groups,parmlist = G2mv.GroupConstraints(constrDict)
    389389            G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList,parmDict,SeqHist=ihst)
     390            #print (G2mv.VarRemapShow(varyList,True))
    390391            constraintInfo = (groups,parmlist,constrDict,fixedList,ihst)
    391         except:
     392        except G2mv.ConstraintException:
    392393            print (' *** ERROR - your constraints are internally inconsistent ***')
    393394            #errmsg, warnmsg = G2mv.CheckConstraints(varyList,constrDict,fixedList)
Note: See TracChangeset for help on using the changeset viewer.