Changeset 4534 for trunk/GSASIIstrMain.py
- Timestamp:
- Jul 27, 2020 10:42:49 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIstrMain.py
r4456 r4534 253 253 # print G2mv.VarRemapShow(varyList) 254 254 255 # remove frozen vars from refinement 256 if 'parmFrozen' not in Controls: 257 Controls['parmFrozen'] = {} 258 if 'FrozenList' not in Controls['parmFrozen']: 259 Controls['parmFrozen']['FrozenList'] = [] 260 parmFrozenList = Controls['parmFrozen']['FrozenList'] 261 frozenList = [i for i in varyList if i in parmFrozenList] 262 if len(frozenList) != 0: 263 varyList = [i for i in varyList if i not in parmFrozenList] 264 G2fil.G2Print( 265 'Frozen refined variables (due to exceeding limits)\n\t:{}' 266 .format(frozenList)) 267 255 268 ifSeq = False 256 269 printFile.write('\n Refinement results:\n') … … 271 284 # add the uncertainties into the esd dictionary (sigDict) 272 285 sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict)) 286 # check for variables outside their allowed range, reset and freeze them 287 frozen = dropOOBvars(varyList,parmDict,sigDict,Controls,parmFrozenList) 273 288 G2mv.PrintIndependentVars(parmDict,varyList,sigDict,pFile=printFile) 274 289 G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True) … … 278 293 G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,calcControls['FFtables'],pFile=printFile) 279 294 G2stIO.SetHistogramData(parmDict,sigDict,Histograms,calcControls['FFtables'],pFile=printFile) 280 G2stIO.SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,rigidbodyDict,covData,makeBack) 295 if len(frozen) > 0: 296 G2fil.G2Print( 297 ' {} variables were outside limits and were frozen (now {} frozen total)\n' 298 .format(len(frozen),len(parmFrozenList))) 299 G2stIO.SetUsedHistogramsAndPhases(GPXfile,Histograms,Phases,rigidbodyDict,covData,parmFrozenList,makeBack) 281 300 printFile.close() 282 301 G2fil.G2Print (' Refinement results are in file: '+ospath.splitext(GPXfile)[0]+'.lst') … … 507 526 printFile.write('\n Refinement results for histogram: %s\n'%histogram) 508 527 printFile.write(135*'-'+'\n') 528 # remove frozen vars 529 if 'parmFrozen' not in Controls: 530 Controls['parmFrozen'] = {} 531 if histogram not in Controls['parmFrozen']: 532 Controls['parmFrozen'][histogram] = [] 533 parmFrozenList = Controls['parmFrozen'][histogram] 534 frozenList = [i for i in varyList if i in parmFrozenList] 535 if len(frozenList) != 0: 536 varyList = [i for i in varyList if i not in parmFrozenList] 537 printFile.write( 538 ' The following refined variables have previously been frozen due to exceeding limits\n\t:{}\n' 539 .format(frozenList)) 509 540 try: 510 541 IfOK,Rvals,result,covMatrix,sig = RefineCore(Controls,Histo,Phases,restraintDict, … … 520 551 # the uncertainties for dependent constrained parms into the esd dict 521 552 sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict)) 522 553 # check for variables outside their allowed range, reset and freeze them 554 frozen = dropOOBvars(varyList,parmDict,sigDict,Controls,parmFrozenList) 555 if len(frozen) > 0: 556 msg = ('Hist {}: {} variables were outside limits and were frozen (now {} frozen total)' 557 .format(ihst,len(frozen),len(parmFrozenList))) 558 G2fil.G2Print(msg) 559 printFile.write(msg+'\n') 560 for p in frozen: 561 if p not in varyList: 562 print('Frozen Warning: {} not in varyList. This should not happen!'.format(p)) 563 continue 564 i = varyList.index(p) 565 result[0][i] = parmDict[p] 566 sig[i] = -0.1 523 567 # a dict with values & esds for dependent (constrained) parameters - avoid extraneous holds 524 568 depParmDict = {i:(parmDict[i],sigDict[i]) for i in varyListStart if i in sigDict and i not in varyList} … … 531 575 'newCellDict':newCellDict,'depParmDict':depParmDict, 532 576 'constraintInfo':constraintInfo, 533 'parmDict':parmDict} 577 'parmDict':parmDict, 578 } 534 579 SeqResult[histogram] = histRefData 535 580 G2stMth.ApplyRBModels(parmDict,Phases,rigidbodyDict,True) … … 537 582 G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histo,None,ifPrint,printFile) 538 583 G2stIO.SetHistogramData(parmDict,sigDict,Histo,None,ifPrint,printFile) 539 G2stIO.SaveUpdatedHistogramsAndPhases(GPXfile,Histo,Phases,rigidbodyDict,histRefData )584 G2stIO.SaveUpdatedHistogramsAndPhases(GPXfile,Histo,Phases,rigidbodyDict,histRefData,Controls['parmFrozen']) 540 585 NewparmDict = {} 541 586 # make dict of varied parameters in current histogram, renamed to … … 569 614 t1 = t2 570 615 SeqResult['histNames'] = [itm for itm in G2stIO.GetHistogramNames(GPXfile,['PWDR',]) if itm in SeqResult.keys()] 571 G2stIO.SetSeqResult(GPXfile,Histograms,SeqResult) 616 try: 617 G2stIO.SetSeqResult(GPXfile,Histograms,SeqResult) 618 except Exception as msg: 619 print('Error reading Sequential results') 620 if GSASIIpath.GetConfigValue('debug'): 621 import traceback 622 print(traceback.format_exc()) 572 623 printFile.close() 573 624 G2fil.G2Print (' Sequential refinement results are in file: '+ospath.splitext(GPXfile)[0]+'.lst') 574 625 G2fil.G2Print (' ***** Sequential refinement successful *****') 575 626 return True,'Success' 627 628 def dropOOBvars(varyList,parmDict,sigDict,Controls,parmFrozenList): 629 '''Find variables in the parameters dict that are outside the ranges 630 (in parmMinDict and parmMaxDict) and set them to the limits values. 631 Add any such variables into the list of frozen variable 632 (parmFrozenList). Returns a list of newly frozen variables, if any. 633 ''' 634 parmMinDict = Controls.get('parmMinDict',{}) 635 parmMaxDict = Controls.get('parmMaxDict',{}) 636 freeze = [] 637 if parmMinDict or parmMaxDict: 638 for name in varyList: 639 if name not in parmDict: continue 640 n,val = G2obj.prmLookup(name,parmMinDict) 641 if n is not None: 642 if parmDict[name] < parmMinDict[n]: 643 parmDict[name] = parmMinDict[n] 644 sigDict[name] = 0.0 645 freeze.append(name) 646 continue 647 n,val = G2obj.prmLookup(name,parmMaxDict) 648 if n is not None: 649 if parmDict[name] > parmMaxDict[n]: 650 parmDict[name] = parmMaxDict[n] 651 sigDict[name] = 0.0 652 freeze.append(name) 653 continue 654 for v in freeze: 655 if v not in parmFrozenList: 656 parmFrozenList.append(v) 657 return freeze 576 658 577 659 def RetDistAngle(DisAglCtls,DisAglData,dlg=None):
Note: See TracChangeset
for help on using the changeset viewer.