Changeset 812
- Timestamp:
- Dec 11, 2012 4:27:56 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 11 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r804 r812 288 288 else: 289 289 mode = style=wx.OPEN | wx.CHANGE_DIR 290 dlg = wx.FileDialog( 291 self, message="Choose "+label+" input file", 292 #defaultDir=os.getcwd(), 293 defaultFile="", 294 wildcard=choices, style=mode 295 ) 290 dlg = wx.FileDialog(self, message="Choose "+label+" input file", 291 defaultFile="",wildcard=choices, style=mode) 296 292 try: 297 293 if dlg.ShowModal() == wx.ID_OK: -
trunk/GSASIIlattice.py
r780 r812 641 641 H = [] 642 642 if CentCheck(SGLatt,[h,k,l]): H=[h,k,l] 643 rdsq = calc_rDsq(H,A) 644 if 0 < rdsq <= dminsq: 645 HKL.append([h,k,l,1/math.sqrt(rdsq)]) 643 if H: 644 rdsq = calc_rDsq(H,A) 645 if 0 < rdsq <= dminsq: 646 HKL.append([h,k,l,1/math.sqrt(rdsq)]) 646 647 elif SGLaue == '2/m': #monoclinic 647 648 axisnum = 1 + ['a','b','c'].index(SGUniq) -
trunk/GSASIIrestrGUI.py
r811 r812 44 44 if 'Chiral' not in restrData: 45 45 restrData['Chiral'] = {'wtFactor':1.0,'Volumes':[],'Use':True} 46 if 'Torsion' not in restrData: 47 restrData['Torsion'] = {'wtFactor':1.0,'Coeff':{},'Torsions':[],'Use':True} 48 if 'Rama' not in restrData: 49 restrData['Rama'] = {'wtFactor':1.0,'Coeff':{},'Ramas':[],'Use':True} 46 50 General = phasedata['General'] 47 51 Cell = General['Cell'][1:7] #skip flag & volume … … 51 55 Atoms = phasedata['Atoms'] 52 56 AtLookUp = G2mth.FillAtomLookUp(Atoms) 53 Names = ['all '+ name for name in General['AtomTypes']] 54 iBeg = len(Names) 55 Types = [name for name in General['AtomTypes']] 56 Coords = [ [] for type in Types] 57 Ids = [ 0 for type in Types] 58 Names += [atom[ct-1] for atom in Atoms] 57 if 'macro' in General['Type']: 58 Names = [atom[0]+atom[1]+atom[2]+' '+atom[3] for atom in Atoms] 59 Ids = [] 60 Coords = [] 61 Types = [] 62 else: 63 Names = ['all '+ name for name in General['AtomTypes']] 64 iBeg = len(Names) 65 Types = [name for name in General['AtomTypes']] 66 Coords = [ [] for type in Types] 67 Ids = [ 0 for type in Types] 68 Names += [atom[ct-1] for atom in Atoms] 59 69 Types += [atom[ct] for atom in Atoms] 60 70 Coords += [atom[cx:cx+3] for atom in Atoms] … … 70 80 dlg.Destroy() 71 81 82 def getMacroFile(macName): 83 defDir = os.path.join(os.path.split(__file__)[0],'GSASIImacros') 84 dlg = wx.FileDialog(G2frame,message='Choose '+macName+' restraint macro file', 85 defaultDir=defDir,defaultFile="",wildcard="GSAS-II macro file (*.mac)|*.mac", 86 style=wx.OPEN | wx.CHANGE_DIR) 87 try: 88 if dlg.ShowModal() == wx.ID_OK: 89 macfile = dlg.GetPath() 90 macro = open(macfile,'Ur') 91 head = macro.readline() 92 if macName not in head: 93 print head 94 print '**** ERROR - wrong restraint macro file selected, try again ****' 95 macro = [] 96 else: # cancel was pressed 97 macxro = [] 98 finally: 99 dlg.Destroy() 100 return macro #advanced past 1st line 101 72 102 def OnAddRestraint(event): 73 103 page = G2frame.dataDisplay.GetSelection() … … 82 112 elif 'Chiral' in G2frame.dataDisplay.GetPageText(page): 83 113 AddChiralRestraint() 114 elif 'Torsion' in G2frame.dataDisplay.GetPageText(page): 115 AddTorsionRestraint() 116 elif 'Rama' in G2frame.dataDisplay.GetPageText(page): 117 AddRamaRestraint() 84 118 85 119 def OnAddAARestraint(event): … … 95 129 elif 'Chiral' in G2frame.dataDisplay.GetPageText(page): 96 130 AddAAChiralRestraint() 131 elif 'Torsion' in G2frame.dataDisplay.GetPageText(page): 132 AddAATorsionRestraint() 133 elif 'Rama' in G2frame.dataDisplay.GetPageText(page): 134 AddAARamaRestraint() 97 135 98 136 def AddBondRestraint(bondRestData): … … 149 187 UpdateBondRestr(bondRestData) 150 188 189 def AddAABondRestraint(bondRestData): 190 Radii = dict(zip(General['AtomTypes'],General['BondRadii'])) 191 macro = getMacroFile('bond') 192 if not macro: 193 return 194 macStr = macro.readline() 195 atoms = zip(Names,Types,Coords,Ids) 196 197 Factor = .85 198 while macStr: 199 items = macStr.split() 200 if 'F' in items[0]: 201 restrData['Bond']['wtFactor'] = float(items[1]) 202 elif 'S' in items[0]: 203 oIds = [] 204 oTypes = [] 205 oCoords = [] 206 tIds = [] 207 tTypes = [] 208 tCoords = [] 209 res = items[1] 210 dist = float(items[2]) 211 esd = float(items[3]) 212 oAtm,tAtm = items[4:6] 213 for Name,Type,coords,Id in atoms: 214 names = Name.split() 215 if res == '*' or res in names[0]: 216 if oAtm == names[2]: 217 oIds.append(Id) 218 oTypes.append(Type) 219 oCoords.append(np.array(coords)) 220 if tAtm == names[2]: 221 tIds.append(Id) 222 tTypes.append(Type) 223 tCoords.append(np.array(coords)) 224 for oId,oType,oCoord in zip(oIds,oTypes,oCoords): 225 for tId,tType,tCoord in zip(tIds,tTypes,tCoords): 226 BsumR = (Radii[oType]+Radii[tType])*Factor 227 obsd = np.sqrt(np.sum(np.inner(Amat,tCoord-oCoord)**2)) 228 if 0.2 < obsd <= BsumR: 229 bondRestData['Bonds'].append([[oId,tId],['1','1'],obsd,dist,esd]) 230 macStr = macro.readline() 231 macro.close() 232 UpdateBondRestr(bondRestData) 233 151 234 def AddAngleRestraint(angleRestData): 152 235 Radii = dict(zip(General['AtomTypes'],zip(General['BondRadii'],General['AngleRadii']))) … … 209 292 UpdateAngleRestr(angleRestData) 210 293 294 def AddAAAngleRestraint(angleRestData): 295 macro = getMacroFile('angle') 296 if not macro: 297 return 298 macStr = macro.readline() 299 while macStr: 300 items = macStr.split() 301 print items 302 if 'F' in items[0]: 303 restrData['Angle']['wtFactor'] = float(items[1]) 304 elif 'S' in items[0]: 305 List = [] 306 res = items[1] 307 dist = items[2] 308 esd = items[3] 309 oAtm = items[4] 310 tAtm = items[5] 311 for name,Type,coords,id in zip(Names,Types,Coords,Ids): 312 if res == '*' or res in name: 313 if oAtm in name: 314 oCoord = coords 315 oId = id 316 oName = name 317 elif tAtm in name: 318 tCoord = coords 319 tId = id 320 tName = name 321 322 macStr = macro.readline() 323 macro.close() 324 UpdateAngleRestr(angleRestData) 325 211 326 def AddPlaneRestraint(): 212 327 origAtoms = [] … … 224 339 origAtoms.append([Ids[x],Types[x],Coords[x]]) 225 340 341 def AddAAPlaneRestraint(): 342 macro = getMacroFile('plane') 343 if not macro: 344 return 345 macStr = macro.readline() 346 while macStr: 347 items = macStr.split() 348 print items 349 if 'F' in items[0]: 350 restrData['Plane']['wtFactor'] = float(items[1]) 351 elif 'S' in items[0]: 352 List = [] 353 res = items[1] 354 dist = items[2] 355 esd = items[3] 356 oAtm = items[4] 357 tAtm = items[5] 358 for name,Type,coords,id in zip(Names,Types,Coords,Ids): 359 if res == '*' or res in name: 360 if oAtm in name: 361 oCoord = coords 362 oId = id 363 oName = name 364 elif tAtm in name: 365 tCoord = coords 366 tId = id 367 tName = name 368 369 macStr = macro.readline() 370 macro.close() 371 226 372 def AddChiralRestraint(): 227 373 print 'Chiral restraint' 228 374 229 def AddAABondRestraint(bondRestData):230 print 'Amino acid Bond restraint'231 232 def AddAAAngleRestraint(angleRestData):233 print 'Amino acid Angle restraint'234 235 def AddAAPlaneRestraint():236 print 'Amino acid Plane restraint'237 238 375 def AddAAChiralRestraint(): 239 print 'Amino acid Chiral restraint' 240 376 macro = getMacroFile('chiral') 377 if not macro: 378 return 379 macStr = macro.readline() 380 while macStr: 381 items = macStr.split() 382 print items 383 if 'F' in items[0]: 384 restrData['Chiral']['wtFactor'] = float(items[1]) 385 elif 'S' in items[0]: 386 List = [] 387 res = items[1] 388 dist = items[2] 389 esd = items[3] 390 oAtm = items[4] 391 tAtm = items[5] 392 for name,Type,coords,id in zip(Names,Types,Coords,Ids): 393 if res == '*' or res in name: 394 if oAtm in name: 395 oCoord = coords 396 oId = id 397 oName = name 398 elif tAtm in name: 399 tCoord = coords 400 tId = id 401 tName = name 402 403 macStr = macro.readline() 404 macro.close() 405 406 def AddTorsionRestraint(): 407 print 'Torsion restraint' 408 409 def AddAATorsionRestraint(): 410 print 'Add AA Torsion' 411 412 def AddRamaRestraint(): 413 print 'Ramachandran restraint' 414 415 def AddAARamaRestraint(): 416 print 'Add AA Ramachandran' 417 241 418 def WtBox(wind,restData): 242 419 … … 282 459 return 283 460 Bonds.ClearSelection() 284 val = bondList[rows[0]][ 4]461 val = bondList[rows[0]][3] 285 462 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new value for bond',val,[0.,5.],'%.4f') 286 463 if dlg.ShowModal() == wx.ID_OK: 287 464 parm = dlg.GetValue() 288 465 for r in rows: 289 bondList[r][ 4] = parm466 bondList[r][3] = parm 290 467 dlg.Destroy() 291 468 UpdateBondRestr(bondRestData) … … 296 473 return 297 474 Bonds.ClearSelection() 298 val = bondList[rows[0]][ 5]475 val = bondList[rows[0]][4] 299 476 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new esd for bond',val,[0.,1.],'%.4f') 300 477 if dlg.ShowModal() == wx.ID_OK: 301 478 parm = dlg.GetValue() 302 479 for r in rows: 303 bondList[r][ 5] = parm480 bondList[r][4] = parm 304 481 dlg.Destroy() 305 482 UpdateBondRestr(bondRestData) … … 386 563 return 387 564 Angles.ClearSelection() 388 val = angleList[rows[0]][ 4]565 val = angleList[rows[0]][3] 389 566 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new value for angle',val,[0.,360.],'%.2f') 390 567 if dlg.ShowModal() == wx.ID_OK: 391 568 parm = dlg.GetValue() 392 569 for r in rows: 393 angleList[r][ 4] = parm570 angleList[r][3] = parm 394 571 dlg.Destroy() 395 572 UpdateAngleRestr(angleRestData) … … 400 577 return 401 578 Angles.ClearSelection() 402 val = angleList[rows[0]][ 5]579 val = angleList[rows[0]][4] 403 580 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new esd for angle',val,[0.,5.],'%.2f') 404 581 if dlg.ShowModal() == wx.ID_OK: 405 582 parm = dlg.GetValue() 406 583 for r in rows: 407 angleList[r][ 5] = parm584 angleList[r][4] = parm 408 585 dlg.Destroy() 409 586 UpdateAngleRestr(angleRestData) … … 477 654 item.Enable(False) 478 655 656 def OnChangeEsd(event): 657 rows = Planes.GetSelectedRows() 658 if not rows: 659 return 660 Planes.ClearSelection() 661 val = planeList[rows[0]][4] 662 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new esd for plane',val,[0.,5.],'%.2f') 663 if dlg.ShowModal() == wx.ID_OK: 664 parm = dlg.GetValue() 665 for r in rows: 666 planeList[r][4] = parm 667 dlg.Destroy() 668 UpdatePlaneRestr(planeRestData) 669 479 670 def OnDeleteRestraint(event): 480 671 rows = Planes.GetSelectedRows() … … 530 721 Planes.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 531 722 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 723 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) 532 724 mainSizer.Add(Planes,0,) 533 725 else: … … 554 746 UpdateChiralRestr(chiralRestData) 555 747 748 def OnChangeValue(event): 749 rows = Volumes.GetSelectedRows() 750 if not rows: 751 return 752 Volumes.ClearSelection() 753 val = volumeList[rows[0]][3] 754 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new value for chiral volume',val,[0.,360.],'%.2f') 755 if dlg.ShowModal() == wx.ID_OK: 756 parm = dlg.GetValue() 757 for r in rows: 758 volumeList[r][3] = parm 759 dlg.Destroy() 760 UpdateChiralRestr(chiralRestData) 761 762 def OnChangeEsd(event): 763 rows = Volumes.GetSelectedRows() 764 if not rows: 765 return 766 Volumes.ClearSelection() 767 val = volumeList[rows[0]][4] 768 dlg = G2phG.SingleFloatDialog(G2frame,'New value','Enter new esd for chiral volume',val,[0.,5.],'%.2f') 769 if dlg.ShowModal() == wx.ID_OK: 770 parm = dlg.GetValue() 771 for r in rows: 772 volumeList[r][4] = parm 773 dlg.Destroy() 774 UpdateChiralRestr(chiralRestData) 775 556 776 ChiralRestr.DestroyChildren() 557 777 dataDisplay = wx.Panel(ChiralRestr) … … 572 792 for atom in atoms: 573 793 name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' ' 574 table.append([name [:-3],dcalc,dobs,esd])794 table.append([name,dcalc,dobs,esd]) 575 795 rowLabels.append(str(i)) 576 796 else: … … 590 810 Volumes.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 591 811 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 812 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeValue, id=G2gd.wxID_RESRCHANGEVAL) 813 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) 592 814 mainSizer.Add(Volumes,0,) 593 815 else: … … 602 824 G2frame.dataFrame.setSizePosLeft(Size) 603 825 826 def UpdateTorsionRestr(torsionRestData): 827 828 def OnDeleteRestraint(event): 829 rows = Torsions.GetSelectedRows() 830 if not rows: 831 return 832 rows.sort() 833 rows.reverse() 834 for row in rows: 835 torsionList.remove(torsionList[row]) 836 UpdateTorsionRestr(torsionRestData) 837 838 TorsionRestr.DestroyChildren() 839 dataDisplay = wx.Panel(TorsionRestr) 840 mainSizer = wx.BoxSizer(wx.VERTICAL) 841 mainSizer.Add((5,5),0) 842 mainSizer.Add(WtBox(TorsionRestr,torsionRestData),0,wx.ALIGN_CENTER_VERTICAL) 843 844 torsionList = torsionRestData['Torsions'] 845 if len(torsionList): 846 table = [] 847 rowLabels = [] 848 Types = 2*[wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,2',] 849 if 'macro' in General['Type']: 850 colLabels = ['(res) A (res) B (res) C (res) D','coef name','calc','obs','esd'] 851 for i,[indx,ops,cofName,dcalc,dobs,esd] in enumerate(torsionList): 852 atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4) 853 name = '' 854 for atom in atoms: 855 name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' ' 856 table.append([name,cofName,dcalc,dobs,esd]) 857 rowLabels.append(str(i)) 858 else: 859 colLabels = ['A+SymOp B+SymOp C+SymOp D+SymOp)','coef name','calc','obs','esd'] 860 for i,[indx,ops,cofName,dcalc,dobs,esd] in enumerate(torsionList): 861 atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1) 862 table.append([atoms[0]+'+('+ops[0]+') '+atoms[1]+'+('+ops[1]+') '+atoms[2]+ \ 863 '+('+ops[2]+') '+atoms[3]+'+('+ops[3]+')',cofName,dcalc,dobs,esd]) 864 rowLabels.append(str(i)) 865 torsionTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) 866 Torsions = G2gd.GSGrid(TorsionRestr) 867 Torsions.SetTable(torsionTable, True) 868 Torsions.AutoSizeColumns(False) 869 for r in range(len(torsionList)): 870 for c in range(2): 871 Torsions.SetReadOnly(r,c,True) 872 Torsions.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 873 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 874 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) 875 mainSizer.Add(Torsions,0,) 876 else: 877 mainSizer.Add(wx.StaticText(TorsionRestr,-1,'No torsion restraints for this phase'),0,) 878 879 TorsionRestr.SetSizer(mainSizer) 880 Size = mainSizer.Fit(G2frame.dataFrame) 881 Size[0] += 5 882 Size[1] += 50 #make room for tab 883 TorsionRestr.SetSize(Size) 884 TorsionRestr.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-1) 885 G2frame.dataFrame.setSizePosLeft(Size) 886 887 def UpdateRamaRestr(ramaRestData): 888 889 def OnDeleteRestraint(event): 890 rows = Volumes.GetSelectedRows() 891 if not rows: 892 return 893 rows.sort() 894 rows.reverse() 895 for row in rows: 896 ramaList.remove(ramaList[row]) 897 UpdateRamaRestr(ramaRestData) 898 899 RamaRestr.DestroyChildren() 900 dataDisplay = wx.Panel(RamaRestr) 901 mainSizer = wx.BoxSizer(wx.VERTICAL) 902 mainSizer.Add((5,5),0) 903 mainSizer.Add(WtBox(RamaRestr,ramaRestData),0,wx.ALIGN_CENTER_VERTICAL) 904 905 ramaList = ramaRestData['Ramas'] 906 if len(ramaList): 907 table = [] 908 rowLabels = [] 909 Types = 2*[wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,2',] 910 if 'macro' in General['Type']: 911 colLabels = ['(res) A (res) B (res) C (res) D (res) E','coef name','calc','obs','esd'] 912 for i,[indx,ops,cofName,dcalc,dobs,esd] in enumerate(ramaList): 913 atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,0,4) 914 name = '' 915 for atom in atoms: 916 name += '('+atom[1]+atom[0].strip()+atom[2]+') '+atom[3]+' ' 917 table.append([name,cofName,dcalc,dobs,esd]) 918 rowLabels.append(str(i)) 919 else: 920 colLabels = ['A+SymOp B+SymOp C+SymOp D+SymOp E+SymOp)','coef name','calc','obs','esd'] 921 for i,[indx,ops,cofName,dcalc,dobs,esd] in enumerate(ramaList): 922 atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1) 923 table.append([atoms[0]+'+('+ops[0]+') '+atoms[1]+'+('+ops[1]+') '+atoms[2]+ \ 924 '+('+ops[2]+') '+atoms[3]+'+('+ops[3]+')',cofName,dcalc,dobs,esd]) 925 rowLabels.append(str(i)) 926 ramaTable = G2gd.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) 927 Ramas = G2gd.GSGrid(RamaRestr) 928 Ramas.SetTable(ramaTable, True) 929 Ramas.AutoSizeColumns(False) 930 for r in range(len(ramaList)): 931 for c in range(2): 932 Ramas.SetReadOnly(r,c,True) 933 Ramas.SetCellStyle(r,c,VERY_LIGHT_GREY,True) 934 G2frame.dataFrame.Bind(wx.EVT_MENU, OnDeleteRestraint, id=G2gd.wxID_RESTDELETE) 935 G2frame.dataFrame.Bind(wx.EVT_MENU, OnChangeEsd, id=G2gd.wxID_RESTCHANGEESD) 936 mainSizer.Add(Ramas,0,) 937 else: 938 mainSizer.Add(wx.StaticText(RamaRestr,-1,'No Ramachandran restraints for this phase'),0,) 939 940 RamaRestr.SetSizer(mainSizer) 941 Size = mainSizer.Fit(G2frame.dataFrame) 942 Size[0] += 5 943 Size[1] += 50 #make room for tab 944 RamaRestr.SetSize(Size) 945 RamaRestr.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-1) 946 G2frame.dataFrame.setSizePosLeft(Size) 947 604 948 def OnPageChanged(event): 605 949 page = event.GetSelection() … … 621 965 chiralRestData = restrData['Chiral'] 622 966 UpdateChiralRestr(chiralRestData) 967 elif text == 'Torsion restraints': 968 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.RestraintMenu) 969 torsionRestData = restrData['Torsion'] 970 UpdateTorsionRestr(torsionRestData) 971 elif text == 'Ramachandran restraints': 972 G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.RestraintMenu) 973 ramaRestData = restrData['Rama'] 974 UpdateRamaRestr(ramaRestData) 623 975 event.Skip() 624 976 … … 653 1005 ChiralRestr = wx.ScrolledWindow(G2frame.dataDisplay) 654 1006 G2frame.dataDisplay.AddPage(ChiralRestr,'Chiral restraints') 1007 TorsionRestr = wx.ScrolledWindow(G2frame.dataDisplay) 1008 G2frame.dataDisplay.AddPage(TorsionRestr,'Torsion restraints') 1009 RamaRestr = wx.ScrolledWindow(G2frame.dataDisplay) 1010 G2frame.dataDisplay.AddPage(RamaRestr,'Ramachandran restraints') 1011 655 1012 UpdateBondRestr(restrData['Bond']) 656 1013
Note: See TracChangeset
for help on using the changeset viewer.