Changeset 1243
- Timestamp:
- Mar 10, 2014 2:06:56 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r1236 r1243 3113 3113 constrDict,fixedList,ignored = G2stIO.ProcessConstraints(constList) 3114 3114 groups,parmlist = G2mv.GroupConstraints(constrDict) 3115 G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList )3115 G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList,parmValDict) 3116 3116 G2mv.Map2Dict(parmValDict,varyList) 3117 3117 except: -
trunk/GSASIIIO.py
r1236 r1243 2089 2089 try: 2090 2090 groups,parmlist = G2mv.GroupConstraints(constDict) 2091 G2mv.GenerateConstraints(groups,parmlist,varyList,constDict,fixedList )2091 G2mv.GenerateConstraints(groups,parmlist,varyList,constDict,fixedList,self.parmDict) 2092 2092 except: 2093 2093 # this really should not happen -
trunk/GSASIImapvars.py
r1160 r1243 85 85 parameter from being varied. Note that all parameters in a constraint relationship 86 86 must specified as varied (appear in varyList) or none can be varied. This is 87 checked in GenerateConstraints (as well as for generated relationships in SetVaryFlags). 87 checked in GenerateConstraints. Likewise, if all parameters in a constraint are 88 not referenced in a refinement, the constraint is ignored, but if some parameters 89 in a constraint group are not referenced in a refinement, but others are this 90 constitutes and error. 88 91 89 92 * When a new variable is created, the variable is assigned the name associated … … 508 511 return errmsg,warnmsg 509 512 510 def GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList ):513 def GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList,parmDict=None): 511 514 '''Takes a list of relationship entries comprising a group of 512 515 constraints and builds the relationship lists and their inverse … … 545 548 # process equivalences: make a list of dependent and independent vars 546 549 # and check for repeated uses (repetition of a parameter as an 547 # independent var is OK )550 # independent var is OK [A=B; A=C], but chaining: [A=B; B=C] is not good) 548 551 indepVarList = [] 549 552 depVarList = [] 550 553 multdepVarList = [] 551 for varlist,mapvars,multarr,invmultarr in zip( 554 for varlist,mapvars,multarr,invmultarr in zip( # process equivalences 552 555 dependentParmList,indParmList,arrayList,invarrayList): 553 if multarr is None: # doonly if an equivalence556 if multarr is None: # true only if an equivalence 554 557 zeromult = False 555 558 for mv in mapvars: … … 563 566 notvaried += mv 564 567 if mv not in indepVarList: indepVarList.append(mv) 568 if parmDict is not None and mv not in parmDict: 569 msg += "\nCannot equivalence to variable "+str(mv)+". Not defined in this refinement" 570 continue 565 571 for v,m in zip(varlist,invmultarr): 572 if parmDict is not None and v not in parmDict: 573 print "Dropping equivalence for variable "+str(v)+". Not defined in this refinement" 574 continue 566 575 if m == 0: zeromult = True 567 576 if v in varyList: … … 617 626 varied = 0 618 627 notvaried = '' 628 unused = 0 629 notused = '' 619 630 for var in constrDict[rel]: 620 631 if var.startswith('_'): continue 632 if parmDict is not None and var not in parmDict: 633 unused += 1 634 if notvaried: notused += ', ' 635 notused += var 621 636 if var in varyList: 622 637 varied += 1 … … 627 642 msg += '\nError: parameter '+var+" is Fixed and used in a constraint:\n\t" 628 643 msg += _FormatConstraint(constrDict[rel],fixedList[rel])+"\n" 644 #if unused > 0:# and unused != len(VarKeys(constrDict[rel])): 645 if unused > 0 and unused != len(VarKeys(constrDict[rel])): 646 msg += "\nSome (but not all) variables in constraint are not defined:\n\t" 647 msg += _FormatConstraint(constrDict[rel],fixedList[rel]) 648 msg += '\nNot used: ' + notused + '\n' 629 649 if varied > 0 and varied != len(VarKeys(constrDict[rel])): 630 650 msg += "\nNot all variables refined in constraint:\n\t" … … 651 671 for rel in group: 652 672 varied = 0 673 unused = 0 653 674 for var in VarKeys(constrDict[rel]): 675 if parmDict is not None and var not in parmDict: 676 unused += 1 654 677 if var not in varsList: varsList.append(var) 655 678 if var in varyList: varied += 1 … … 659 682 msg = 'too many relationships' 660 683 break 684 # Since we checked before, if any variables are unused, then all must be. 685 # If so, this set of relationships can be ignored 686 if unused: 687 if debug: print('Constraint ignored (all variables undefined)') 688 if debug: print (' '+_FormatConstraint(constrDict[rel],fixedList[rel])) 689 continue 661 690 # fill in additional degrees of freedom 662 691 try: … … 704 733 unused = False 705 734 mapvar.append(fixedval) 706 if unused: continue # skip over constraints that do not have a fixed value or a refined variable 735 if unused: # skip over constraints that don't matter (w/o fixed value or any refined variables) 736 if debug: print('Constraint ignored (all variables unrefined)') 737 if debug: print (' '+_FormatConstraint(constrDict[rel],fixedList[rel])) 738 continue 707 739 dependentParmList.append(varlist) 708 740 arrayList.append(constrArr) -
trunk/GSASIIstrMain.py
r1242 r1243 155 155 try: 156 156 groups,parmlist = G2mv.GroupConstraints(constrDict) 157 G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList )157 G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList,parmDict) 158 158 except: 159 159 print ' *** ERROR - your constraints are internally inconsistent ***' 160 errmsg, warnmsg = G2mv.CheckConstraints(varyList,constrDict,fixedList)161 print 'Errors',errmsg162 if warnmsg: print 'Warnings',warnmsg160 #errmsg, warnmsg = G2mv.CheckConstraints(varyList,constrDict,fixedList) 161 #print 'Errors',errmsg 162 #if warnmsg: print 'Warnings',warnmsg 163 163 raise Exception(' *** Refine aborted ***') 164 # # check to see which generated parameters are fully varied165 # msg = G2mv.SetVaryFlags(varyList)166 # if msg:167 # print ' *** ERROR - you have not set the refine flags for constraints consistently! ***'168 # print msg169 # raise Exception(' *** Refine aborted ***')170 164 #print G2mv.VarRemapShow(varyList) 171 165 … … 218 212 219 213 printFile = open(ospath.splitext(GPXfile)[0]+'.lst','w') 220 print ' Sequential Refinement'214 print 'Starting Sequential Refinement' 221 215 G2stIO.ShowBanner(printFile) 222 216 Controls = G2stIO.GetControls(GPXfile) … … 252 246 NewparmDict = {} 253 247 for ihst,histogram in enumerate(histNames): 248 print('Refining with '+str(histogram)) 254 249 ifPrint = False 255 250 if dlg: … … 260 255 calcControls['FFtables'] = FFtables 261 256 calcControls['BLtables'] = BLtables 262 varyList = []263 parmDict = {}264 257 Histo = {histogram:Histograms[histogram],} 265 258 hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,Histo,Print=False) … … 269 262 varyList = rbVary+phaseVary+hapVary+histVary 270 263 if not ihst: 264 # subsequent refinements 271 265 saveVaryList = varyList[:] 272 266 for i,item in enumerate(saveVaryList): … … 278 272 SeqResult['varyList'] = saveVaryList 279 273 else: 274 # first histogram to refine against 280 275 newVaryList = varyList[:] 281 276 for i,item in enumerate(newVaryList): … … 286 281 newVaryList[i] = item 287 282 if newVaryList != SeqResult['varyList']: 288 #print 'histogram',histogram,len(newVaryList),'variables' 289 #print newVaryList 290 #print 'previous',len(SeqResult['varyList']),'variables' 291 #print SeqResult['varyList'] 283 # variable lists are expected to match between sequential refinements 292 284 print '**** ERROR - variable list for this histogram does not match previous' 293 285 print '\ncurrent histogram',histogram,'has',len(newVaryList),'variables' … … 317 309 print line 318 310 raise Exception 311 parmDict = {} 319 312 parmDict.update(phaseDict) 320 313 parmDict.update(hapDict) … … 324 317 G2stIO.GetFprime(calcControls,Histo) 325 318 # do constraint processing 319 #reload(G2mv) # debug 326 320 G2mv.InitVars() 327 321 constrDict,fixedList = G2stIO.GetConstraints(GPXfile) … … 329 323 try: 330 324 groups,parmlist = G2mv.GroupConstraints(constrDict) 331 G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList )325 G2mv.GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList,parmDict) 332 326 except: 333 327 print ' *** ERROR - your constraints are internally inconsistent ***' 328 #errmsg, warnmsg = G2mv.CheckConstraints(varyList,constrDict,fixedList) 329 #print 'Errors',errmsg 330 #if warnmsg: print 'Warnings',warnmsg 334 331 raise Exception(' *** Refine aborted ***') 335 # check to see which generated parameters are fully varied336 # msg = G2mv.SetVaryFlags(varyList)337 # if msg:338 # print ' *** ERROR - you have not set the refine flags for constraints consistently! ***'339 # print msg340 # raise Exception(' *** Refine aborted ***')341 #print G2mv.VarRemapShow(varyList)342 332 343 333 ifPrint = False
Note: See TracChangeset
for help on using the changeset viewer.