Changeset 570
- Timestamp:
- Apr 24, 2012 12:19:19 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r569 r570 304 304 primaryReaders.append(reader) 305 305 if len(secondaryReaders) + len(primaryReaders) == 0: 306 self.ErrorDialog('No matching format for file '+file,'No Format')306 self.ErrorDialog('No Format','No matching format for file '+file) 307 307 return 308 308 … … 321 321 import traceback 322 322 print traceback.format_exc() 323 self.ErrorDialog('Error reading file '+file 324 +' with format '+ rd.formatName,'Read Error') 323 self.ErrorDialog('Read Error', 324 'Error reading file '+file 325 +' with format '+ rd.formatName) 325 326 continue 326 327 if not flag: continue … … 348 349 import traceback 349 350 print traceback.format_exc() 350 self.ErrorDialog('Error on open of file '+file,'Open Error') 351 self.ErrorDialog('Open Error', 352 'Error on open of file '+file) 351 353 finally: 352 354 if fp: fp.close() … … 1636 1638 def OnRefine(self,event): 1637 1639 self.OnFileSave(event) 1640 # check that constraints are OK here 1641 errmsg, warnmsg = G2str.CheckConstraints(self.GSASprojectfile) 1642 if errmsg: 1643 print('Error in constraints:\n'+errmsg+ 1644 '\nRefinement not possible') 1645 self.ErrorDialog('Constraint Error', 1646 'Error in constraints:\n'+errmsg+ 1647 '\nRefinement not possible') 1648 return 1649 if warnmsg: 1650 print('Conflict between refinment flag settings and constraints:\n'+ 1651 warnmsg+'\nRefinement not possible') 1652 self.ErrorDialog('Refinement Flag Error', 1653 'Conflict between refinment flag settings and constraints:\n'+ 1654 warnmsg+ 1655 '\nRefinement not possible') 1656 return 1638 1657 #works - but it'd be better if it could restore plots 1639 1658 dlg = wx.ProgressDialog('Residual','Powder profile Rwp =',101.0, … … 1675 1694 self.PatternTree.SetItemPyData(Id,{}) 1676 1695 self.OnFileSave(event) 1696 # check that constraints are OK here 1697 errmsg, warnmsg = G2str.CheckConstraints(self.GSASprojectfile) 1698 if errmsg: 1699 print('Error in constraints:\n'+errmsg+ 1700 '\nRefinement not possible') 1701 self.ErrorDialog('Constraint Error', 1702 'Error in constraints:\n'+errmsg+ 1703 '\nRefinement not possible') 1704 return 1705 if warnmsg: 1706 print('Conflict between refinment flag settings and constraints:\n'+ 1707 warnmsg+'\nRefinement not possible') 1708 self.ErrorDialog('Refinement Flag Error', 1709 'Conflict between refinment flag settings and constraints:\n'+ 1710 warnmsg+'\nRefinement not possible') 1711 return 1677 1712 dlg = wx.ProgressDialog('Residual for histogram 0','Powder profile Rwp =',101.0, 1678 1713 style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT) … … 1706 1741 dlg.Destroy() 1707 1742 1708 def ErrorDialog(self,title,message): 1709 dlg = wx.MessageDialog(self, message, title, wx.OK) 1743 def ErrorDialog(self,title,message,parent=None, wtype=wx.OK): 1744 result = None 1745 if parent is None: 1746 dlg = wx.MessageDialog(self, message, title, wtype) 1747 else: 1748 dlg = wx.MessageDialog(parent, message, title, wtype) 1749 dlg.CenterOnParent() # not working on Mac 1710 1750 try: 1711 1751 result = dlg.ShowModal() 1712 1752 finally: 1713 1753 dlg.Destroy() 1754 return result 1714 1755 1715 1756 class GSASIImain(wx.App): -
trunk/GSASIIgrid.py
r568 r570 23 23 import GSASIIphsGUI as G2phG 24 24 import GSASIIstruct as G2str 25 #import GSASIImapvars as G2mv25 import GSASIImapvars as G2mv 26 26 27 27 # globals we will use later … … 1144 1144 return [constr+[1.0,None,'c']] #just one constraint - default sum to one 1145 1145 return [] 1146 1147 def CheckAddedConstraint(newcons): 1148 '''Check a new constraint that has just been input. 1149 If there is an error display a message and give the user a 1150 choice to keep or discard the last entry (why keep? -- they 1151 may want to delete something else or edit multipliers). 1152 Since the varylist is not available, no warning messages 1153 should be generated. 1154 Returns True if constraint should be added 1155 ''' 1156 allcons = [] 1157 for key in 'Hist','HAP','Phase': 1158 allcons += data[key] 1159 allcons += newcons 1160 if not len(allcons): return True 1161 G2mv.InitVars() 1162 constDictList,fixedList,ignored = G2str.ProcessConstraints(allcons) 1163 errmsg, warnmsg = G2mv.CheckConstraints('',constDictList,fixedList) 1164 if errmsg: 1165 res = G2frame.ErrorDialog('Constraint Error', 1166 'Error with newly added constraint:\n'+errmsg+ 1167 '\n\nDiscard newly added constraint?', 1168 parent=G2frame.dataFrame, 1169 wtype=wx.YES_NO) 1170 return res != wx.ID_YES 1171 elif warnmsg: 1172 print 'Unexpected contraint warning:\n',warnmsg 1173 return True 1174 1175 def CheckChangedConstraint(): 1176 '''Check all constraints after an edit has been made. 1177 If there is an error display a message and give the user a 1178 choice to keep or discard the last edit. 1179 Since the varylist is not available, no warning messages 1180 should be generated. 1181 Returns True if the edit should be retained 1182 ''' 1183 allcons = [] 1184 for key in 'Hist','HAP','Phase': 1185 allcons += data[key] 1186 if not len(allcons): return True 1187 G2mv.InitVars() 1188 constDictList,fixedList,ignored = G2str.ProcessConstraints(allcons) 1189 errmsg, warnmsg = G2mv.CheckConstraints('',constDictList,fixedList) 1190 if errmsg: 1191 res = G2frame.ErrorDialog('Constraint Error', 1192 'Error after editing constraint:\n'+errmsg+ 1193 '\n\nDiscard last constraint edit?', 1194 parent=G2frame.dataFrame, 1195 wtype=wx.YES_NO) 1196 return res != wx.ID_YES 1197 elif warnmsg: 1198 print 'Unexpected contraint warning:\n',warnmsg 1199 return True 1146 1200 1147 1201 def OnAddHold(event): … … 1161 1215 sel = dlg.GetSelection() 1162 1216 FrstVarb = choice[2][sel] 1163 data[choice[3]] += [[[0.0,FrstVarb],None,None,'h'],] 1217 newcons = [[[0.0,FrstVarb],None,None,'h']] 1218 if CheckAddedConstraint(newcons): 1219 data[choice[3]] += newcons 1164 1220 dlg.Destroy() 1165 1221 choice[4]() … … 1179 1235 FrstVarb = choice[2][sel] 1180 1236 moreVarb = FindEquivVarb(FrstVarb,choice[2]) 1181 constr = SelectVarbs(page,FrstVarb,moreVarb,choice[1],'equivalence') 1182 if len(constr) > 0: 1183 data[choice[3]] += constr 1237 newcons = SelectVarbs(page,FrstVarb,moreVarb,choice[1],'equivalence') 1238 if len(newcons) > 0: 1239 if CheckAddedConstraint(newcons): 1240 data[choice[3]] += newcons 1184 1241 dlg.Destroy() 1185 1242 choice[4]() … … 1199 1256 FrstVarb = choice[2][sel] 1200 1257 moreVarb = FindEquivVarb(FrstVarb,choice[2]) 1201 constr = SelectVarbs(page,FrstVarb,moreVarb,choice[1],'function') 1202 if len(constr) > 0: 1203 data[choice[3]] += constr 1258 newcons = SelectVarbs(page,FrstVarb,moreVarb,choice[1],'function') 1259 if len(newcons) > 0: 1260 if CheckAddedConstraint(newcons): 1261 data[choice[3]] += newcons 1204 1262 dlg.Destroy() 1205 1263 choice[4]() … … 1219 1277 FrstVarb = choice[2][sel] 1220 1278 moreVarb = FindEquivVarb(FrstVarb,choice[2]) 1221 constr = SelectVarbs(page,FrstVarb,moreVarb,choice[1],'constraint') 1222 if len(constr) > 0: 1223 data[choice[3]] += constr 1279 newcons = SelectVarbs(page,FrstVarb,moreVarb,choice[1],'constraint') 1280 if len(newcons) > 0: 1281 if CheckAddedConstraint(newcons): 1282 data[choice[3]] += newcons 1224 1283 dlg.Destroy() 1225 1284 choice[4]() … … 1337 1396 try: 1338 1397 if dlg.ShowModal() == wx.ID_OK: 1398 prev = data[name][Id] 1339 1399 result = dlg.GetData() 1340 1400 if data[name][Id][-1] == 'c': … … 1343 1403 else: 1344 1404 data[name][Id][:-3] = result[:-1] 1405 if not CheckChangedConstraint(): 1406 data[name][Id] = prev 1345 1407 except: 1346 1408 import traceback … … 1450 1512 1451 1513 G2frame.dataDisplay.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, OnPageChanged) 1452 1453 1514 # validate all the constrants -- should not see any errors here normally 1515 allcons = [] 1516 for key in 'Hist','HAP','Phase': 1517 allcons += data[key] 1518 if not len(allcons): return 1519 G2mv.InitVars() 1520 constDictList,fixedList,ignored = G2str.ProcessConstraints(allcons) 1521 errmsg, warnmsg = G2mv.CheckConstraints('',constDictList,fixedList) 1522 if errmsg: 1523 G2frame.ErrorDialog('Constraint Error', 1524 'Error in constraints:\n'+errmsg, 1525 parent=G2frame.dataFrame) 1526 1527 elif warnmsg: 1528 print 'Unexpected contraint warning:\n',warnmsg 1529 1454 1530 def UpdateRestraints(G2frame,data): 1455 1531 -
trunk/GSASIImapvars.py
r567 r570 58 58 parameters, there must exist N-C new parameters, where C is the number 59 59 of contraint equations in the group. Routine GenerateConstraints takes 60 the output from InputParse and GroupConstraintsgenerates the60 the output from GroupConstraints and generates the 61 61 "missing" relationships and saves that information in the module's 62 62 global variables. Each generated parameter is named sequentially using paramPrefix. … … 76 76 External Routines: 77 77 To define a set of constrained and unconstrained relations, one 78 calls In putParse, GroupConstraints and GenerateConstraints. It78 calls InitVars, GroupConstraints and GenerateConstraints. It 79 79 is best to supply all relations/equations in one call to these 80 80 routines so that grouping is done correctly. … … 88 88 (though StoreEquivalence('x',('y','z')) will run more 89 89 efficiently) but mixing independent and dependent variables is 90 problematic. This may not work properly:90 problematic. This is not allowed: 91 91 StoreEquivalence('x',('y',)) 92 92 StoreEquivalence('y',('z',)) 93 Use StoreEquivalence before calling GenerateConstraints or 94 CheckConstraints 95 96 To check that input in internally consistent, use CheckConstraints 93 97 94 98 To show a summary of the parameter remapping, one calls … … 100 104 To take values from the new independent parameters and constraints, 101 105 one calls Dict2Map. This will apply contraints. 106 107 Use Dict2Deriv to determine derivatives on independent parameters 108 from those on dependent ones 109 110 Use ComputeDepESD to compute uncertainties on dependent variables 102 111 103 112 Global Variables: … … 159 168 Input 160 169 constrDict: a list of dicts defining relationships/constraints 161 (see InputParse) 170 constrDict = [{<constr1>}, {<constr2>}, ...] 171 where {<constr1>} is {'param1': mult1, 'param2': mult2,...} 162 172 Returns two lists of lists: 163 a list of relationship list indices for each group and 173 a list of relationship list indices for each group pointing to 174 elements in constrDict and 164 175 a list containing the parameters used in each group 165 176 """ … … 189 200 return groups,ParmList 190 201 202 def CheckConstraints(varyList,constrDict,fixedList): 203 '''Takes a list of relationship entries comprising a group of 204 constraints and checks for inconsistencies such as conflicts in 205 parameter/variable definitions and or inconsistently varied parameters. 206 Input: see GenerateConstraints 207 Output: returns two strings 208 the first lists conflicts internal to the specified constraints 209 the second lists conflicts where the varyList specifies some 210 parameters in a constraint, but not all 211 If there are no errors, both strings will be empty 212 ''' 213 global dependentParmList,arrayList,invarrayList,indParmList,consNum 214 errmsg = '' 215 warnmsg = '' 216 fixVlist = [] 217 # process fixed (held) variables 218 for cdict in constrDict: 219 if len(cdict) == 1: 220 fixVlist.append(cdict.keys()[0]) 221 222 # process equivalences: make a list of dependent and independent vars 223 # and check for repeated uses (repetition of a parameter as an 224 # independent var is OK) 225 indepVarList = [] 226 depVarList = [] 227 multdepVarList = [] 228 for varlist,mapvars,multarr,invmultarr in zip( 229 dependentParmList,indParmList,arrayList,invarrayList): 230 if multarr is None: # an equivalence 231 zeromult = False 232 for mv in mapvars: 233 varied = 0 234 notvaried = '' 235 if mv in varyList: 236 varied += 1 237 else: 238 if notvaried: notvaried += ', ' 239 notvaried += mv 240 if mv not in indepVarList: indepVarList.append(mv) 241 for v,m in zip(varlist,invmultarr): 242 if m == 0: zeromult = True 243 if v in varyList: 244 varied += 1 245 else: 246 if notvaried: notvaried += ', ' 247 notvaried += v 248 if v in depVarList: 249 multdepVarList.append(v) 250 else: 251 depVarList.append(v) 252 if varied > 0 and varied != len(varlist)+1: 253 warnmsg += "\nNot all variables refined in equivalence:\n\t" 254 s = "" 255 for v in varlist: 256 if s != "": s+= " & " 257 s += str(v) 258 warnmsg += str(mv) + " => " + s 259 warnmsg += '\nNot refined: ' + notvaried + '\n' 260 if zeromult: 261 errmsg += "\nZero multiplier is invalid in equivalence:\n\t" 262 s = "" 263 for v in varlist: 264 if s != "": s+= " & " 265 s += str(v) 266 errmsg += str(mv) + " => " + s + '\n' 267 268 #print 'indepVarList',indepVarList 269 #print 'depVarList',depVarList 270 # check for errors: 271 inboth = set(indepVarList).intersection(set(depVarList)) 272 if len(inboth) > 0: 273 errmsg += "\nThe following parameters(s) are used as both dependent and independent variables in Equivalence relations:\n" 274 s = '' 275 for var in inboth: 276 if s != "": s+= ", " 277 s += str(v) 278 errmsg += '\t'+ s + '\n' 279 if len(multdepVarList) > 0: 280 errmsg += "\nThe following parameters(s) are used in multiple Equivalence relations as dependent variables:\n" 281 s = '' 282 for var in multdepVarList: 283 if s != "": s+= ", " 284 s += str(v) 285 errmsg += '\t'+ s + '\n' 286 equivVarList = list(set(indepVarList).union(set(depVarList))) 287 #print 'equivVarList',equivVarList 288 inboth = set(fixVlist).intersection(set(equivVarList)) 289 if len(inboth) > 0: 290 errmsg += "\nThe following parameter(s) are used in both Equivalence and Fixed constraints:\n" 291 s = '' 292 for var in inboth: 293 if s != "": s+= ", " 294 s += str(v) 295 errmsg += '\t'+ s + '\n' 296 297 groups,parmlist = GroupConstraints(constrDict) 298 # scan through parameters in each relationship. Are all varied? If only some are 299 # varied, create a warning message. 300 for group,varlist in zip(groups,parmlist): 301 if len(varlist) == 1: continue 302 VaryFree = False 303 for rel in group: 304 varied = 0 305 notvaried = '' 306 for var in constrDict[rel]: 307 if var in varyList: 308 varied += 1 309 else: 310 if notvaried: notvaried += ', ' 311 notvaried += var 312 if var in fixVlist: 313 errmsg += '\nParameter '+var+" is Fixed and used in a constraint:\n\t" 314 errmsg += FormatConstraint(constrDict[rel],fixedList[rel])+"\n" 315 if var in equivVarList: 316 errmsg += '\nParameter '+var+" is Equivalenced and used in a constraint:\n\t" 317 errmsg += FormatConstraint(constrDict[rel],fixedList[rel])+"\n" 318 if varied > 0 and varied != len(constrDict[rel]): 319 warnmsg += "\nNot all variables refined in constraint:\n\t" 320 warnmsg += FormatConstraint(constrDict[rel],fixedList[rel]) 321 warnmsg += '\nNot refined: ' + notvaried + '\n' 322 if errmsg or warnmsg: return errmsg,warnmsg 323 324 # now look for process each group and create the relations that are needed to form 325 # non-singular square matrix 326 for group,varlist in zip(groups,parmlist): 327 if len(varlist) == 1: continue 328 try: 329 arr = MakeArray(constrDict, group, varlist) 330 except: 331 errmsg += "\nOver-constrained input. " 332 errmsg += "There are more constraints" + str(len(group)) 333 errmsg += "\n\tthan variables" + str(len(varlist)) + "\n" 334 for rel in group: 335 errmsg += FormatConstraint(constrDict[rel],fixedList[rel]) 336 errmsg += "\n" 337 try: 338 constrArr = FillInMissingRelations(arr,len(group)) 339 except Exception,msg: 340 if msg.message.startswith('VectorProduct'): 341 errmsg += "\nSingular input. " 342 errmsg += "This set of constraints is not linearly independent:\n\n" 343 else: 344 errmsg += "\nInconsistent input. " 345 errmsg += "Cound not generate a set of non-singular constraints" 346 errmsg += "\n\tfor this set of input:\n\n" 347 for rel in group: 348 errmsg += FormatConstraint(constrDict[rel],fixedList[rel]) 349 errmsg += "\n" 350 #import traceback 351 #print traceback.format_exc() 352 continue 353 354 mapvar = [] 355 group = group[:] 356 # scan through all generated and input variables 357 # Check again for inconsistent variable use 358 # for new variables -- where varied and unvaried parameters get grouped 359 # together. I don't think this can happen when not flagged before, but 360 # it does not hurt to check again. 361 for i in range(len(varlist)): 362 varied = 0 363 notvaried = '' 364 if len(group) > 0: 365 rel = group.pop(0) 366 fixedval = fixedList[rel] 367 for var in constrDict[rel]: 368 if var in varyList: 369 varied += 1 370 else: 371 if notvaried: notvaried += ', ' 372 notvaried += var 373 else: 374 fixedval = None 375 if fixedval is None: 376 varname = paramPrefix + str(consNum) 377 mapvar.append(varname) 378 consNum += 1 379 if VaryFree or varied > 0: 380 varyList.append(varname) 381 else: 382 mapvar.append(fixedval) 383 if varied > 0 and notvaried != '': 384 warnmsg += "\nNot all variables refined in generated constraint" 385 warnmsg += '\nPlease report this unexpected error\n' 386 for rel in group: 387 warnmsg += FormatConstraint(constrDict[rel],fixedList[rel]) 388 warnmsg += "\n" 389 warnmsg += '\n\tNot refined: ' + notvaried + '\n' 390 try: 391 np.linalg.inv(constrArr) 392 except: 393 errmsg += "\nSingular input. " 394 errmsg += "The following constraints are not " 395 errmsg += "linearly independent\n\tor do not " 396 errmsg += "allow for generation of a non-singular set\n" 397 errmsg += 'Please report this unexpected error\n' 398 for rel in group: 399 errmsg += FormatConstraint(constrDict[rel],fixedList[rel]) 400 errmsg += "\n" 401 return errmsg,warnmsg 402 191 403 def GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList): 192 404 '''Takes a list of relationship entries comprising a group of … … 194 406 and stores them in global variables Also checks for internal 195 407 conflicts or inconsistencies in parameter/variable definitions. 408 Input: 409 groups,parmlist: see GroupConstraints 410 varyList: a list of parameters that will be varied 411 constrDict: a list of dicts defining relationships/constraints 412 constrDict = [{<constr1>}, {<constr2>}, ...] 413 where {<constr1>} is {'param1': mult1, 'param2': mult2,...} 414 fixedList: a list of values for each constraint/variable in 415 constrDict, value is either a float (contraint) or None (for 416 a new variable). 196 417 ''' 197 418 global dependentParmList,arrayList,invarrayList,indParmList,consNum … … 413 634 return 414 635 415 # def SetVaryFlags(varyList,fixedList):416 # '''Adds independent variables to the varyList provided that all417 # dependent variables are being varied.418 # Ignores independent variables where no dependent variables are419 # being varied.420 # Returns a non-empty text message where some but not all dependent421 # variables are being varied.422 # '''423 # global dependentParmList,arrayList,invarrayList,indParmList,fixedDict424 # msg = ""425 # for varlist,mapvars,multarr in zip(dependentParmList,indParmList,arrayList):426 # for mv in mapvars:427 # varied = []428 # notvaried = []429 # if mv in fixedDict: continue430 # if multarr is None:431 # if mv in varyList:432 # varied.append(mv)433 # else:434 # notvaried.append(mv)435 # for v in varlist:436 # if v in varyList:437 # varied.append(v)438 # else:439 # notvaried.append(v)440 # if len(varied) > 0 and len(notvaried) > 0:441 # if msg != "": msg += "\n"442 # msg += "Error: inconsistent use of parameter " + mv443 # msg += "\n varied: "444 # for v in varied: msg += v445 # msg += "\n not varied: "446 # for v in notvaried: msg += v447 # #elif len(varied) > 0 and multarr is not None:448 # # varyList.append(mv)449 # return msg450 451 636 def GetDependentVars(): 452 637 '''Return a list of dependent variables: e.g. variables that are … … 460 645 def GetIndependentVars(): 461 646 '''Return a list of independent variables: e.g. variables that are 462 created by constrain s of other variables'''647 created by constraints of other variables''' 463 648 independentVars = [] 464 649 global indParmList,fixedDict … … 507 692 returns a dictionary containing the esd values for dependent parameters 508 693 ''' 509 # I think this fails for equivalencies: the ESD for the master (independent variable)510 # needs to be adjusted.511 694 sigmaDict = {} 512 695 for varlist,mapvars,invmultarr in zip(dependentParmList,indParmList,invarrayList): … … 529 712 def FormatConstraint(RelDict,RelVal): 530 713 '''Formats a Constraint or Function for use in a convenient way''' 714 linelen = 45 531 715 s = [""] 532 716 for var,val in RelDict.items(): 533 if len(s[-1]) > 60: s.append(' ')717 if len(s[-1]) > linelen: s.append(' ') 534 718 m = val 535 719 if s[-1] != "" and m >= 0: … … 539 723 m = abs(m) 540 724 s[-1] += '%.3f*%s '%(m,var) 541 if len(s[-1]) > 60: s.append(' ')725 if len(s[-1]) > linelen: s.append(' ') 542 726 if RelVal is None: 543 727 s[-1] += ' = New variable' … … 856 1040 '2::atomy:3', '2::atomz:3', 857 1041 '0:12:Scale', '0:11:Scale', '0:14:Scale', '0:13:Scale', '0:0:Scale'] 1042 varyList = ['0::A0', '0::AUiso:0', '0::Afrac:1', '0::Afrac:2', '0::Afrac:3', '0::Afrac:4', '0::dAx:5', '0::dAy:5', '0::dAz:5', '0::AUiso:5', ':0:Back:0', ':0:Back:1', ':0:Back:2', ':0:Back:3', ':0:Back:4', ':0:Back:5', ':0:Back:6', ':0:Back:7', ':0:Back:8', ':0:Back:9', ':0:Back:10', ':0:Back:11', ':0:U', ':0:V', ':0:W', ':0:X', ':0:Y', ':0:Scale', ':0:DisplaceX', ':0:DisplaceY'] 1043 constrDict = [ 1044 {'0::Afrac:4': 24.0, '0::Afrac:1': 16.0, '0::Afrac:3': 24.0, '0::Afrac:2': 16.0}, 1045 {'0::Afrac:1': 1.0, '0::Afrac:2': 1.0}, 1046 {'0::Afrac:4': 1.0, '0::Afrac:3': 1.0}] 1047 fixedList = ['40.0', '1.0', '1.0'] 1048 1049 errmsg, warnmsg = CheckConstraints(varylist,constrDict,fixedList) 1050 if errmsg: 1051 print "*** Error ********************" 1052 print errmsg 1053 if warnmsg: 1054 print "*** Warning ********************" 1055 print warnmsg 1056 if errmsg or warnmsg: 1057 sys.exit() 858 1058 groups,parmlist = GroupConstraints(constrDict) 859 1059 GenerateConstraints(groups,parmlist,varylist,constrDict,fixedList) -
trunk/GSASIIstruct.py
r567 r570 71 71 constList += constDict[item] 72 72 fl.close() 73 constDict,fixedList,ignored = ProcessConstraints(constList) 74 if ignored: 75 print ignored,'old-style Constraints were rejected' 76 return constDict,fixedList 77 78 def ProcessConstraints(constList): 79 "interpret constraints" 73 80 constDict = [] 74 81 fixedList = [] … … 106 113 else: 107 114 ignored += 1 108 if ignored: 109 print ignored,'old-style Constraints were rejected' 110 return constDict,fixedList 115 return constDict,fixedList,ignored 116 117 def 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) 111 133 112 134 def GetPhaseNames(GPXfile): … … 628 650 phaseVary += cellVary(pfx,SGData) 629 651 Natoms[pfx] = 0 630 if Atoms and not General ['doPawley']:652 if Atoms and not General.get('doPawley'): 631 653 if General['Type'] == 'nuclear': 632 654 Natoms[pfx] = len(Atoms) … … 932 954 print sigstr 933 955 934 if Phase['General'] ['doPawley']:956 if Phase['General'].get('doPawley'): 935 957 pawleyRef = Phase['Pawley ref'] 936 958 for i,refl in enumerate(pawleyRef): … … 2419 2441 GA,GB = G2lat.Gmat2AB(G) #Orthogonalization matricies 2420 2442 Vst = np.sqrt(nl.det(G)) #V* 2421 if not Phase['General'] ['doPawley']:2443 if not Phase['General'].get('doPawley'): 2422 2444 refList = StructureFactor(refList,G,hfx,pfx,SGData,calcControls,parmDict) 2423 2445 for refl in refList: … … 2430 2452 GetIntensityCorr(refl,G,g,pfx,phfx,hfx,SGData,calcControls,parmDict) #puts corrections in refl[13] 2431 2453 refl[13] *= Vst*Lorenz 2432 if Phase['General'] ['doPawley']:2454 if Phase['General'].get('doPawley'): 2433 2455 try: 2434 2456 refl[9] = abs(parmDict[pfx+'PWLref:%d'%(pawleyLookup[pfx+'%d,%d,%d'%(h,k,l)])]) … … 2531 2553 G,g = G2lat.A2Gmat(A) #recip & real metric tensors 2532 2554 GA,GB = G2lat.Gmat2AB(G) #Orthogonalization matricies 2533 if not Phase['General'] ['doPawley']:2555 if not Phase['General'].get('doPawley'): 2534 2556 dFdvDict = StructureFactorDerv(refList,G,hfx,pfx,SGData,calcControls,parmDict) 2535 2557 for iref,refl in enumerate(refList): … … 2537 2559 h,k,l = refl[:3] 2538 2560 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'): 2540 2562 try: 2541 2563 refl[9] = abs(parmDict[pfx+'PWLref:%d'%(pawleyLookup[pfx+'%d,%d,%d'%(h,k,l)])]) … … 2574 2596 dMdpk2[5] = 100.*dx*refl[13]*dMdipk2[0] 2575 2597 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'): 2577 2599 try: 2578 2600 idx = varylist.index(pfx+'PWLref:'+str(pawleyLookup[pfx+'%d,%d,%d'%(h,k,l)])) … … 2837 2859 Histograms,Phases = GetUsedHistogramsAndPhases(GPXfile) 2838 2860 if not Phases: 2839 print ' *** ERROR - you have no histograms to refine! ***'2861 print ' *** ERROR - you have no phases! ***' 2840 2862 print ' *** Refine aborted ***' 2841 2863 raise Exception … … 2864 2886 print ' *** ERROR - your constraints are internally inconsistent ***' 2865 2887 # traceback for debug 2888 #print 'varyList',varyList 2889 #print 'constrDict',constrDict 2890 #print 'fixedList',fixedList 2866 2891 #import traceback 2867 2892 #print traceback.format_exc()
Note: See TracChangeset
for help on using the changeset viewer.