Changeset 492
- Timestamp:
- Feb 23, 2012 11:48:19 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r482 r492 1342 1342 dlg.Destroy() 1343 1343 1344 ''' replaced -- delete soon1345 def OnImportPhase(self,event):1346 dlg = wx.FileDialog(self, 'Choose GSAS EXP file', '.', '',1347 'EXP file (*.EXP)|*.EXP',wx.OPEN|wx.CHANGE_DIR)1348 try:1349 Phase = {}1350 if dlg.ShowModal() == wx.ID_OK:1351 EXPfile = dlg.GetPath()1352 Phase = G2IO.ReadEXPPhase(self,EXPfile)1353 finally:1354 dlg.Destroy()1355 if Phase:1356 PhaseName = Phase['General']['Name']1357 if not G2gd.GetPatternTreeItemId(self,self.root,'Phases'):1358 sub = self.PatternTree.AppendItem(parent=self.root,text='Phases')1359 else:1360 sub = G2gd.GetPatternTreeItemId(self,self.root,'Phases')1361 sub = self.PatternTree.AppendItem(parent=sub,text=PhaseName)1362 self.PatternTree.SetItemPyData(sub,Phase)1363 1364 def OnImportPDB(self,event):1365 dlg = wx.FileDialog(self, 'Choose PDB file', '.', '',1366 'PDB file (*.pdb,*.ent)|*.pdb;*.ent|All files (*.*)|*.*',wx.OPEN|wx.CHANGE_DIR)1367 try:1368 if dlg.ShowModal() == wx.ID_OK:1369 PDBfile = dlg.GetPath()1370 Phase = G2IO.ReadPDBPhase(PDBfile)1371 finally:1372 dlg.Destroy()1373 if Phase:1374 PhaseName = Phase['General']['Name']1375 if not G2gd.GetPatternTreeItemId(self,self.root,'Phases'):1376 sub = self.PatternTree.AppendItem(parent=self.root,text='Phases')1377 else:1378 sub = G2gd.GetPatternTreeItemId(self,self.root,'Phases')1379 sub = self.PatternTree.AppendItem(parent=sub,text=PhaseName)1380 self.PatternTree.SetItemPyData(sub,Phase)1381 1382 def OnImportCIF(self,event):1383 def ReadCIFPhase(filename):1384 import random as ran1385 import GSASIIlattice as G2lat1386 anisoNames = ['aniso_u_11','aniso_u_22','aniso_u_33','aniso_u_12','aniso_u_13','aniso_u_23']1387 file = open(filename, 'Ur')1388 Phase = {}1389 Title = ospath.split(filename)[-1]1390 print '\n Reading cif file: ',Title1391 Compnd = ''1392 Atoms = []1393 A = np.zeros(shape=(3,3))1394 S = file.readline()1395 while S:1396 if '_symmetry_space_group_name_H-M' in S:1397 SpGrp = S.split("_symmetry_space_group_name_H-M")[1].strip().strip('"').strip("'")1398 E,SGData = G2spc.SpcGroup(SpGrp)1399 if E:1400 print ' ERROR in space group symbol ',SpGrp,' in file ',filename1401 print ' N.B.: make sure spaces separate axial fields in symbol'1402 print G2spc.SGErrors(E)1403 return None1404 S = file.readline()1405 elif '_cell' in S:1406 if '_cell_length_a' in S:1407 a = S.split('_cell_length_a')[1].strip().strip('"').strip("'").split('(')[0]1408 elif '_cell_length_b' in S:1409 b = S.split('_cell_length_b')[1].strip().strip('"').strip("'").split('(')[0]1410 elif '_cell_length_c' in S:1411 c = S.split('_cell_length_c')[1].strip().strip('"').strip("'").split('(')[0]1412 elif '_cell_angle_alpha' in S:1413 alp = S.split('_cell_angle_alpha')[1].strip().strip('"').strip("'").split('(')[0]1414 elif '_cell_angle_beta' in S:1415 bet = S.split('_cell_angle_beta')[1].strip().strip('"').strip("'").split('(')[0]1416 elif '_cell_angle_gamma' in S:1417 gam = S.split('_cell_angle_gamma')[1].strip().strip('"').strip("'").split('(')[0]1418 S = file.readline()1419 elif 'loop_' in S:1420 labels = {}1421 i = 01422 while S:1423 S = file.readline()1424 if '_atom_site' in S.strip()[:10]:1425 labels[S.strip().split('_atom_site_')[1].lower()] = i1426 i += 11427 else:1428 break1429 if labels:1430 if 'aniso_label' not in labels:1431 while S:1432 atom = ['','','',0,0,0,1.0,'','','I',0.01,0,0,0,0,0,0]1433 S.strip()1434 if len(S.split()) != len(labels):1435 if 'loop_' in S:1436 break1437 S += file.readline().strip()1438 data = S.split()1439 if len(data) != len(labels):1440 break1441 for key in labels:1442 if key == 'type_symbol':1443 atom[1] = data[labels[key]]1444 elif key == 'label':1445 atom[0] = data[labels[key]]1446 elif key == 'fract_x':1447 atom[3] = float(data[labels[key]].split('(')[0])1448 elif key == 'fract_y':1449 atom[4] = float(data[labels[key]].split('(')[0])1450 elif key == 'fract_z':1451 atom[5] = float(data[labels[key]].split('(')[0])1452 elif key == 'occupancy':1453 atom[6] = float(data[labels[key]].split('(')[0])1454 elif key == 'thermal_displace_type':1455 if data[labels[key]].lower() == 'uiso':1456 atom[9] = 'I'1457 atom[10] = float(data[labels['u_iso_or_equiv']].split('(')[0])1458 else:1459 atom[9] = 'A'1460 atom[10] = 0.01461 1462 atom[7],atom[8] = G2spc.SytSym(atom[3:6],SGData)1463 atom.append(ran.randint(0,sys.maxint))1464 Atoms.append(atom)1465 S = file.readline()1466 else:1467 while S:1468 S.strip()1469 data = S.split()1470 if len(data) != len(labels):1471 break1472 name = data[labels['aniso_label']]1473 for atom in Atoms:1474 if name == atom[0]:1475 for i,uname in enumerate(anisoNames):1476 atom[i+11] = float(data[labels[uname]].split('(')[0])1477 S = file.readline()1478 1479 else:1480 S = file.readline()1481 file.close()1482 if Title:1483 PhaseName = Title1484 else:1485 PhaseName = 'None'1486 SGlines = G2spc.SGPrint(SGData)1487 for line in SGlines: print line1488 cell = [float(a),float(b),float(c),float(alp),float(bet),float(gam)]1489 Volume = G2lat.calc_V(G2lat.cell2A(cell))1490 Phase['General'] = {'Name':PhaseName,'Type':'nuclear','SGData':SGData,1491 'Cell':[False,]+cell+[Volume,]}1492 Phase['Atoms'] = Atoms1493 Phase['Drawing'] = {}1494 Phase['Histograms'] = {}1495 1496 return Phase1497 1498 dlg = wx.FileDialog(self, 'Choose CIF file', '.', '',1499 'CIF file (*.cif)|*.cif',wx.OPEN|wx.CHANGE_DIR)1500 try:1501 if dlg.ShowModal() == wx.ID_OK:1502 CIFfile = dlg.GetPath()1503 Phase = ReadCIFPhase(CIFfile)1504 finally:1505 dlg.Destroy()1506 if Phase:1507 PhaseName = Phase['General']['Name']1508 if not G2gd.GetPatternTreeItemId(self,self.root,'Phases'):1509 sub = self.PatternTree.AppendItem(parent=self.root,text='Phases')1510 else:1511 sub = G2gd.GetPatternTreeItemId(self,self.root,'Phases')1512 sub = self.PatternTree.AppendItem(parent=sub,text=PhaseName)1513 self.PatternTree.SetItemPyData(sub,Phase)1514 print Phase1515 '''1516 1517 1344 def OnExportPatterns(self,event): 1518 1345 names = ['All']
Note: See TracChangeset
for help on using the changeset viewer.