Changeset 2147
- Timestamp:
- Feb 13, 2016 9:12:07 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r2141 r2147 952 952 return lines 953 953 954 def ReadPowderInstprm(self,instLines ):954 def ReadPowderInstprm(self,instLines,bank): 955 955 '''Read lines from a GSAS-II (new) instrument parameter file 956 similar to G2pwdGUI.OnLoad 957 If instprm file has multiple banks each with header #Bank n: ..., this 958 finds matching bank no. to load - rejects nonmatches. 956 959 957 960 :param list instLines: strings from GSAS-II parameter file; can be concatenated with ';' 961 :param int bank: bank number to check when instprm file has '#BANK n:...' strings 962 when bank = n then use parameters; otherwise skip that set. Ignored if BANK n: 963 not present. NB: this kind of instprm file made by a Save all profile command in Instrument Parameters 958 964 959 965 ''' … … 962 968 newItems = [] 963 969 newVals = [] 970 Found = False 964 971 for S in instLines: 965 972 if S[0] == '#': … … 1148 1155 s = Iparm['INS 1PRCF 2'].split() 1149 1156 data.extend([0.0,0.0,G2IO.sfloat(s[0]),G2IO.sfloat(s[1]),0.0,0.0,0.0,azm]) #beta-q, sig-0, sig-1, sig-2, sig-q, X, Y 1157 elif abs(pfType) == 2: 1158 data.extend([G2IO.sfloat(s[1]),0.0,1./G2IO.sfloat(s[3])]) #alpha, beta-0, beta-1 1159 data.extend([0.0,0.0,G2IO.sfloat(s[1]),0.0,0.0,0.0,0.0,azm]) #beta-q, sig-0, sig-1, sig-2, sig-q, X, Y 1150 1160 else: 1151 1161 s = Iparm['INS 1PRCF1 '].split() … … 1222 1232 instParmList = None 1223 1233 if Lines is not None: 1224 instParmList = self.ReadPowderInstprm(Lines )1234 instParmList = self.ReadPowderInstprm(Lines,bank) #know Bank - see above 1225 1235 if instParmList is not None: 1226 1236 rd.instfile = instfile … … 1244 1254 instParmList = None 1245 1255 if Lines is not None: 1246 instParmList = self.ReadPowderInstprm(Lines )1256 instParmList = self.ReadPowderInstprm(Lines,bank) #know Bank - see above 1247 1257 if instParmList is not None: 1248 1258 rd.instfile = instfile … … 1272 1282 instParmList = None 1273 1283 if Lines is not None: 1274 instParmList = self.ReadPowderInstprm(Lines )1284 instParmList = self.ReadPowderInstprm(Lines,bank) #know Bank - see above 1275 1285 if instParmList is not None: 1276 1286 rd.instfile = instfile … … 1306 1316 instParmList = None 1307 1317 if Lines is not None: 1308 instParmList = self.ReadPowderInstprm(Lines )1318 instParmList = self.ReadPowderInstprm(Lines,bank) #know Bank - see above 1309 1319 if instParmList is not None: 1310 1320 rd.instfile = instfile … … 1338 1348 rd.instfile = '' 1339 1349 rd.instmsg = 'default: '+dI.defaultIparm_lbl[res] 1340 return self.ReadPowderInstprm(dI.defaultIparms[res] )1350 return self.ReadPowderInstprm(dI.defaultIparms[res],bank) #know Bank - see above 1341 1351 1342 1352 def OnImportPowder(self,event): -
trunk/GSASIIgrid.py
r2146 r2147 107 107 108 108 [ wxID_INSTPRMRESET,wxID_CHANGEWAVETYPE,wxID_INSTCOPY, wxID_INSTFLAGCOPY, wxID_INSTLOAD, 109 wxID_INSTSAVE, wxID_INST1VAL, wxID_INSTCALIB, 110 ] = [wx.NewId() for item in range( 8)]109 wxID_INSTSAVE, wxID_INST1VAL, wxID_INSTCALIB,wxID_INSTSAVEALL, 110 ] = [wx.NewId() for item in range(9)] 111 111 112 112 [ wxID_UNDO,wxID_LSQPEAKFIT,wxID_LSQONECYCLE,wxID_RESETSIGGAM,wxID_CLEARPEAKS,wxID_AUTOSEARCH, … … 153 153 VERY_LIGHT_GREY = wx.Colour(235,235,235) 154 154 155 # Aliases for Classes/Functions moved to GSASIIctrls, all should be tracked down but leaving as a reminder 156 #SingleFloatDialog = G2G.SingleFloatDialog 157 #SingleStringDialog = G2G.SingleStringDialog 158 #MultiStringDialog = G2G.MultiStringDialog 159 #G2ColumnIDDialog = G2G.G2ColumnIDDialog 160 #ItemSelector = G2G.ItemSelector 161 #HorizontalLine = G2G.HorizontalLine 162 #G2LoggedButton = G2G.G2LoggedButton 163 #EnumSelector = G2G.EnumSelector 164 #G2ChoiceButton = G2G.G2ChoiceButton 165 #GSGrid = G2G.GSGrid 166 #Table = G2G.Table 167 #GridFractionEditor = G2G.GridFractionEditor 168 #GSNoteBook = G2G.GSNoteBook 155 commonTrans = {'abc':np.eye(3),'a-cb':np.array([[1,0,0],[0,0,-1],[0,1,0]]), 156 'ba-c':np.array([[0,1,0],[1,0,0],[0,0,-1]]),'-cba':np.array([[0,0,-1],[0,1,0],[1,0,0]]), 157 'bca':np.array([[0,1,0],[0,0,1],[1,0,0]]),'cab':np.array([[0,0,1],[1,0,0],[0,1,0]]), 158 'P->R':np.array([[1,-1,0],[0,1,-1],[1,1,1]]),'R->P':np.array([[2./3,1./3,1./3],[-1./3,1./3,1./3],[-1./3,-2./3,1./3]]), 159 'P->A':np.array([[-1,0,0],[0,-1,1],[0,1,1]]),'R->O':np.array([[-1,0,0],[0,-1,0],[0,0,1]]), 160 'P->B':np.array([[-1,0,1],[0,-1,0],[1,0,1]]),'B->P':np.array([[-.5,0,.5],[0,-1,0],[.5,0,.5]]), 161 'P->C':np.array([[1,1,0],[1,-1,0],[0,0,-1]]),'C->P':np.array([[.5,.5,0],[.5,-.5,0],[0,0,-1]]), 162 'P->F':np.array([[-1,1,1],[1,-1,1],[1,1,-1]]),'F->P':np.array([[0,.5,.5],[.5,0,.5],[.5,.5,0]]), 163 'P->I':np.array([[0,1,1],[1,0,1],[1,1,0]]),'I->P':np.array([[-.5,.5,.5],[.5,-.5,.5],[.5,.5,-.5]]), 164 'A->P':np.array([[-1,0,0],[0,-.5,.5],[0,.5,.5]]),'O->R':np.array([[-1,0,0],[0,-1,0],[0,0,1]]), } 165 commonNames = ['abc','bca','cab','a-cb','ba-c','-cba','P->A','A->P', 166 'P->B','B->P','P->C','C->P','P->I','I->P','P->F','F->P','P->R','R->P','R->O','O->R'] 169 167 170 168 # Should SGMessageBox, SymOpDialog, DisAglDialog be moved? … … 324 322 325 323 :param wx.Frame parent: reference to parent frame (or None) 326 :param data: HKLF data 324 :param data: HKLF data 325 326 #NB: commonNames & commonTrans defined at top of this file 327 327 328 328 ''' … … 340 340 self.Laue = '1' 341 341 self.Class = 'triclinic' 342 self.Common = 'abc' 342 343 self.Draw() 343 344 344 345 def Draw(self): 345 346 commonTrans = {'abc':np.eye(3),'a-cb':np.array([[1,0,0],[0,0,-1],[0,1,0]]),347 'ba-c':np.array([[0,1,0],[1,0,0],[0,0,-1]]),'-cba':np.array([[0,0,-1],[0,1,0],[1,0,0]]),348 'bca':np.array([[0,1,0],[0,0,1],[1,0,0]]),'cab':np.array([[0,0,1],[1,0,0],[0,1,0]]),349 'P->R':np.array([[1,-1,0],[0,1,-1],[1,1,1]]),'R->P':np.array([[2./3,1./3,1./3],[-1./3,1./3,1./3],[-1./3,-2./3,1./3]]),350 'P->A':np.array([[-1,0,0],[0,-1,1],[0,1,1]]),'R->O':np.array([[-1,0,0],[0,-1,0],[0,0,1]]),351 'P->B':np.array([[-1,0,1],[0,-1,0],[1,0,1]]),'B->P':np.array([[-.5,0,.5],[0,-1,0],[.5,0,.5]]),352 'P->C':np.array([[1,1,0],[1,-1,0],[0,0,-1]]),'C->P':np.array([[.5,.5,0],[.5,-.5,0],[0,0,-1]]),353 'P->F':np.array([[-1,1,1],[1,-1,1],[1,1,-1]]),'F->P':np.array([[0,.5,.5],[.5,0,.5],[.5,.5,0]]),354 'P->I':np.array([[0,1,1],[1,0,1],[1,1,0]]),'I->P':np.array([[-.5,.5,.5],[.5,-.5,.5],[.5,.5,-.5]]),355 'A->P':np.array([[-1,0,0],[0,-.5,.5],[0,.5,.5]]),'O->R':np.array([[-1,0,0],[0,-1,0],[0,0,1]]), }356 commonNames = ['abc','bca','cab','a-cb','ba-c','-cba','P->A','A->P',357 'P->B','B->P','P->C','C->P','P->I','I->P','P->F','F->P','P->R','R->P','R->O','O->R']358 346 359 347 def OnMatValue(event): … … 381 369 def OnCommon(event): 382 370 Obj = event.GetEventObject() 383 self.Trans = commonTrans[Obj.GetValue()] 371 self.Common = Obj.GetValue() 372 self.Trans = commonTrans[self.Common] 384 373 wx.CallAfter(self.Draw) 385 374 … … 396 385 commonSizer = wx.BoxSizer(wx.HORIZONTAL) 397 386 commonSizer.Add(wx.StaticText(self.panel,label=' Common transformations: '),0,WACV) 398 common = wx.ComboBox(self.panel,value= 'abc',choices=commonNames,387 common = wx.ComboBox(self.panel,value=self.Common,choices=commonNames, 399 388 style=wx.CB_READONLY|wx.CB_DROPDOWN) 400 389 common.Bind(wx.EVT_COMBOBOX,OnCommon) … … 1092 1081 self.InstEdit.Append(help='Load instrument profile parameters from file', 1093 1082 id=wxID_INSTLOAD, kind=wx.ITEM_NORMAL,text='Load profile...') 1083 self.InstEdit.Append(help='Save all instrument profile parameters to one file', 1084 id=wxID_INSTSAVE, kind=wx.ITEM_NORMAL,text='Save profile...') 1094 1085 self.InstEdit.Append(help='Save instrument profile parameters to file', 1095 id=wxID_INSTSAVE , kind=wx.ITEM_NORMAL,text='Saveprofile...')1086 id=wxID_INSTSAVEALL, kind=wx.ITEM_NORMAL,text='Save all profile...') 1096 1087 self.InstEdit.Append(help='Copy instrument profile parameters to other histograms', 1097 1088 id=wxID_INSTCOPY, kind=wx.ITEM_NORMAL,text='Copy') … … 3056 3047 dlg.Destroy() 3057 3048 Super = data[1]['Super'] 3058 refList = G2lat.transposeHKLF(Trans,Super,refList)3059 if not len(refList):3049 refList,badRefs = G2lat.transposeHKLF(Trans,Super,refList) 3050 if len(badRefs): #do I want to list badRefs? 3060 3051 G2frame.ErrorDialog('Failed transformation','Matrix yields fractional hkl indices') 3061 3052 return -
trunk/GSASIIlattice.py
r2146 r2147 525 525 526 526 def transposeHKLF(transMat,Super,refList): 527 ''' Apply transformation matrix to hkl(m) 528 param: transmat: 3x3 or 4x4 array 529 param: Super: 0 or 1 for extra index 530 param: refList list of h,k,l,.... 531 return: newRefs transformed list of h',k',l',,, 532 return: badRefs list of noninteger h',k',l'... 533 ''' 527 534 newRefs = np.copy(refList) 535 badRefs = [] 528 536 for H in newRefs: 529 537 newH = np.inner(transMat,H[:3+Super]) 530 538 H[:3+Super] = np.rint(newH) 531 539 if not np.allclose(newH,H[:3+Super],atol=0.01): 532 return []533 return newRefs 540 badRefs.append(newH) 541 return newRefs,badRefs 534 542 535 543 def sortHKLd(HKLd,ifreverse,ifdup,ifSS=False): … … 539 547 :param ifreverse: True for largest d first 540 548 :param ifdup: True if duplicate d-spacings allowed 549 :return sorted reflection list 541 550 ''' 542 551 T = [] -
trunk/GSASIIpwdGUI.py
r2137 r2147 1183 1183 ''' 1184 1184 #patch 1185 if 'Bank' not in data: 1186 data['Bank'] = [1,1,0] 1185 if 'Bank' not in data: #get it from name 1186 hst = G2frame.PatternTree.GetItemText(G2frame.PatternId) 1187 if 'Bank' in hst: 1188 bank = int(hst.split('Bank')[1]) 1189 data['Bank'] = [bank,bank,0] 1190 else: 1191 data['Bank'] = [1,1,0] 1187 1192 #end patch 1188 1193 def keycheck(keys): … … 1252 1257 '''Loads instrument parameters from a G2 .instprm file 1253 1258 in response to the Instrument Parameters-Operations/Load Profile menu 1259 If instprm file has multiple banks each with header #Bank n: ..., this 1260 finds matching bank no. to load - rejects nonmatches. 1254 1261 1255 1262 Note that similar code is found in ReadPowderInstprm (GSASII.py) 1256 1263 ''' 1264 data = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame, 1265 G2frame.PatternId,'Instrument Parameters'))[0] 1266 bank = data['Bank'][0] 1257 1267 pth = G2G.GetImportPath(G2frame) 1258 1268 if not pth: pth = '.' … … 1266 1276 newItems = [] 1267 1277 newVals = [] 1278 Found = False 1268 1279 while S: 1269 1280 if S[0] == '#': 1270 S = File.readline() 1271 continue 1281 if Found: 1282 break 1283 if 'Bank' in S: 1284 if bank == int(S.split(':')[0].split()[1]): 1285 S = File.readline() 1286 continue 1287 else: 1288 S = File.readline() 1289 while S and '#Bank' not in S: 1290 S = File.readline() 1291 continue 1292 else: #a non #Bank file 1293 S = File.readline() 1294 continue 1295 Found = True 1272 1296 [item,val] = S[:-1].split(':') 1273 1297 newItems.append(item) … … 1278 1302 S = File.readline() 1279 1303 File.close() 1280 Inst,Inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters')) 1281 if 'Bank' not in Inst: #patch for old .instprm files - may cause faults for TOF data 1282 Inst['Bank'] = [1,1,0] 1283 data = G2IO.makeInstDict(newItems,newVals,len(newVals)*[False,]) 1284 G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters'),[data,Inst2]) 1285 RefreshInstrumentGrid(event,doAnyway=True) #to get peaks updated 1304 if Found: 1305 Inst,Inst2 = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters')) 1306 if 'Bank' not in Inst: #patch for old .instprm files - may cause faults for TOF data 1307 Inst['Bank'] = [1,1,0] 1308 data = G2IO.makeInstDict(newItems,newVals,len(newVals)*[False,]) 1309 G2frame.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.PatternId,'Instrument Parameters'),[data,Inst2]) 1310 RefreshInstrumentGrid(event,doAnyway=True) #to get peaks updated 1311 else: 1312 G2frame.ErrorDialog('No match','Bank %d not in %s'%(bank,filename),G2frame.dataFrame) 1286 1313 UpdateInstrumentGrid(G2frame,data) 1287 1314 G2plt.PlotPeakWidths(G2frame) … … 1292 1319 '''Respond to the Instrument Parameters Operations/Save Profile menu 1293 1320 item: writes current parameters to a .instprm file 1321 It does not write Bank n: on # line & thus can be used any time w/o clash of bank nos. 1294 1322 ''' 1295 1323 pth = G2G.GetExportPath(G2frame) … … 1305 1333 for item in data: 1306 1334 File.write(item+':'+str(data[item][1])+'\n') 1335 File.close() 1336 finally: 1337 dlg.Destroy() 1338 1339 def OnSaveAll(event): 1340 '''Respond to the Instrument Parameters Operations/Save all Profile menu & writes 1341 selected inst parms. across multiple banks into a single file 1342 Each block starts with #Bank n: GSAS-II instrument... where n is bank no. 1343 item: writes parameters from selected PWDR entries to a .instprm file 1344 ''' 1345 hst = G2frame.PatternTree.GetItemText(G2frame.PatternId) 1346 histList = GetHistsLikeSelected(G2frame) 1347 histList.insert(0,hst) 1348 saveList = [] 1349 dlg = G2G.G2MultiChoiceDialog( 1350 G2frame.dataFrame, 1351 'Save instrument parameters from', 1352 'Save instrument parameters', histList) 1353 try: 1354 if dlg.ShowModal() == wx.ID_OK: 1355 for i in dlg.GetSelections(): 1356 saveList.append(histList[i]) 1357 finally: 1358 dlg.Destroy() 1359 pth = G2G.GetExportPath(G2frame) 1360 dlg = wx.FileDialog(G2frame, 'Choose GSAS-II instrument parameters file', pth, '', 1361 'instrument parameter files (*.instprm)|*.instprm',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) 1362 try: 1363 if dlg.ShowModal() == wx.ID_OK: 1364 filename = dlg.GetPath() 1365 # make sure extension is .instprm 1366 filename = os.path.splitext(filename)[0]+'.instprm' 1367 File = open(filename,'w') 1368 for hist in saveList: 1369 Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,hist) 1370 inst = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Instrument Parameters'))[0] 1371 if 'Bank' not in inst: #patch 1372 bank = 1 1373 if 'Bank' in hist: 1374 bank = int(hist.split('Bank')[1]) 1375 inst['Bank'] = [bank,bank,0] 1376 bank = inst['Bank'][0] 1377 File.write("#Bank %d: GSAS-II instrument parameter file; do not add/delete items!\n"%(bank)) 1378 for item in inst: 1379 File.write(item+':'+str(inst[item][1])+'\n') 1307 1380 File.close() 1308 1381 finally: … … 1727 1800 G2frame.Bind(wx.EVT_MENU,OnLoad,id=G2gd.wxID_INSTLOAD) 1728 1801 G2frame.Bind(wx.EVT_MENU,OnSave,id=G2gd.wxID_INSTSAVE) 1802 G2frame.Bind(wx.EVT_MENU,OnSaveAll,id=G2gd.wxID_INSTSAVEALL) 1729 1803 G2frame.Bind(wx.EVT_MENU,OnReset,id=G2gd.wxID_INSTPRMRESET) 1730 1804 G2frame.Bind(wx.EVT_MENU,OnInstCopy,id=G2gd.wxID_INSTCOPY) … … 1733 1807 G2frame.Bind(wx.EVT_MENU,OnCopy1Val,id=G2gd.wxID_INST1VAL) 1734 1808 elif 'L' in insVal['Type']: #SASD data menu commands 1735 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame. InstMenu)1809 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.SASDInstMenu) 1736 1810 if not G2frame.dataFrame.GetStatusBar(): 1737 1811 Status = G2frame.dataFrame.CreateStatusBar()
Note: See TracChangeset
for help on using the changeset viewer.