Changeset 4192
- Timestamp:
- Nov 22, 2019 1:28:42 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIdataGUI.py
r4191 r4192 2905 2905 self.newGPXfile = '' 2906 2906 self.lastSelectedPhaseTab = None # track the last tab pressed on a phase window 2907 self.testRBObjSizers = {} #rigid body sizer data 2907 self.testRBObjSizers = {} #rigid body sizer datafile contents 2908 self.RMCchoice = 'fullrmc' 2908 2909 2909 2910 def __init__(self, parent): … … 3817 3818 dlg.Destroy() 3818 3819 return 3819 f = files[sel] 3820 filroot,dirname = sellist[sel].split(' from ') 3821 f = os.path.join(dirname,filroot) 3820 3822 if os.path.exists(f): 3821 3823 self.OnFileOpen(event, filename=f) … … 5705 5707 self.PostfillDataMenu() 5706 5708 5707 #Phase / fullrmc (Reverse Monte Carlo method) tab5708 G2G.Define_wxId('wxID_SETUP FULLRMC','wxID_LOADFULLRMC','wxID_SAVEFULLRMC','wxID_EDITFULLRMC','wxID_RUNFULLRMC', )5709 #Phase / fullrmc & RMCprofile (Reverse Monte Carlo method) tab 5710 G2G.Define_wxId('wxID_SETUPRMC','wxID_LOADRMC','wxID_SAVERMC','wxID_RUNRMC', ) 5709 5711 self.FRMCMenu = wx.MenuBar() 5710 5712 self.PrefillDataMenu(self.FRMCMenu) … … 5712 5714 self.FRMCDataEdit = wx.Menu(title='') 5713 5715 self.FRMCMenu.Append(menu=self.FRMCDataEdit, title='Operations') 5714 self.FRMCDataEdit.Append(G2G.wxID_SETUPFULLRMC,'Setup run.py','Setup new fullrmc run.py file') 5715 self.FRMCDataEdit.Append(G2G.wxID_LOADFULLRMC,'Load run.py','Load fullrmc run.py file') 5716 self.FRMCDataEdit.Append(G2G.wxID_SAVEFULLRMC,'Save run.py','Save fullrmc run.py file') 5717 self.FRMCDataEdit.Append(G2G.wxID_EDITFULLRMC,'Edit run.py','Edit fullrmc run.py file') 5718 self.FRMCDataEdit.Append(G2G.wxID_RUNFULLRMC,'Execute run.py','Run fullrmc run.py file') 5716 self.FRMCDataEdit.Append(G2G.wxID_SETUPRMC,'Setup RMC','Setup new fullrmc or RMCprofile file') 5717 self.FRMCDataEdit.Append(G2G.wxID_LOADRMC,'Load','Load fullrmc or RMCprofile file') 5718 self.FRMCDataEdit.Append(G2G.wxID_SAVERMC,'Save','Save fullrmc or RMCprofile file') 5719 self.FRMCDataEdit.Append(G2G.wxID_RUNRMC,'Execute','Run fullrmc or RMCprofile file') 5719 5720 self.PostfillDataMenu() 5720 5721 -
trunk/GSASIIphsGUI.py
r4191 r4192 30 30 ''' 31 31 from __future__ import division, print_function 32 import os 32 33 import os.path 33 34 import wx … … 1080 1081 parent.Raise() 1081 1082 self.EndModal(wx.ID_CANCEL) 1083 1084 ################################################################################ 1085 class SetUpRMCProfileDialog(wx.Dialog): 1086 ''' Get from user the super cell size & selected histogram to make various files 1087 ''' 1088 def __init__(self,parent,Name,Phase): 1089 title = 'RMCProfile setup' 1090 wx.Dialog.__init__(self,parent,wx.ID_ANY,title, 1091 pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) 1092 self.panel = wxscroll.ScrolledPanel(self) #just a dummy - gets destroyed in Draw! 1093 self.Name = Name 1094 self.Phase = Phase 1095 self.SuperCell = [1,1,1] 1096 self.histogram = '' 1097 self.metadata = {'title':'none','owner':'no one','date':str(time.ctime()), 1098 'material':'nothing','comment':'none ','source':'nowhere'} 1099 self.Draw() 1100 1101 def Draw(self): 1102 1103 def OnHisto(event): 1104 self.histogram = histo.GetStringSelection() 1105 1106 self.panel.Destroy() 1107 self.panel = wxscroll.ScrolledPanel(self,style = wx.DEFAULT_DIALOG_STYLE) 1108 mainSizer = wx.BoxSizer(wx.VERTICAL) 1109 mainSizer.Add(wx.StaticText(self.panel,label=' Setup for: %s'%self.Name),0,WACV) 1110 superSizer = wx.BoxSizer(wx.HORIZONTAL) 1111 axes = ['X','Y','Z'] 1112 for i,ax in enumerate(axes): 1113 superSizer.Add(wx.StaticText(self.panel,label=' %s-axis: '%ax),0,WACV) 1114 superSizer.Add(G2G.ValidatedTxtCtrl(self.panel,self.SuperCell,i,min=1,max=10,size=(50,25)),0,WACV) 1115 mainSizer.Add(superSizer,0,WACV) 1116 histograms = self.Phase['Histograms'] 1117 histNames = list(histograms.keys()) 1118 mainSizer.Add(wx.StaticText(self.panel,label=' Select one histogram for processing:'),0,WACV) 1119 histo = wx.ComboBox(self.panel,choices=histNames,style=wx.CB_DROPDOWN|wx.TE_READONLY) 1120 histo.Bind(wx.EVT_COMBOBOX,OnHisto) 1121 mainSizer.Add(histo,0,WACV) 1122 metalist = ['title','owner','material','comment','source'] 1123 metaSizer = wx.FlexGridSizer(0,2,5,5) 1124 for item in metalist: 1125 metaSizer.Add(wx.StaticText(self.panel,label=' Metadata item: '+item+' '),0,WACV) 1126 metaSizer.Add(G2G.ValidatedTxtCtrl(self.panel,self.metadata,item),0,WACV) 1127 mainSizer.Add(metaSizer,0,WACV) 1128 btnSizer = wx.BoxSizer(wx.HORIZONTAL) 1129 OKBtn = wx.Button(self.panel,-1,"OK") 1130 OKBtn.Bind(wx.EVT_BUTTON, self.OnOK) 1131 btnSizer.Add(OKBtn) 1132 1133 mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 1134 self.panel.SetSizer(mainSizer) 1135 size = np.array(self.GetSize()) 1136 self.panel.SetupScrolling() 1137 self.panel.SetAutoLayout(1) 1138 size = [size[0]-5,size[1]-20] #this fiddling is needed for older wx! 1139 self.panel.SetSize(size) 1140 1141 def GetData(self): 1142 'Returns the values from the dialog' 1143 return self.SuperCell,self.histogram,self.metadata 1144 1145 def OnOK(self,event): 1146 parent = self.GetParent() 1147 parent.Raise() 1148 self.EndModal(wx.ID_OK) 1149 1082 1150 1083 1151 ################################################################################ … … 4331 4399 ################################################################################ 4332 4400 4333 def Update FullRMC():4334 ''' Present the controls for running fullrmc 4401 def UpdateRMC(): 4402 ''' Present the controls for running fullrmc or RMCprofile 4335 4403 ''' 4404 global runFile 4405 def OnRMCselect(event): 4406 G2frame.RMCchoice = RMCsel.GetStringSelection() 4407 G2frame.runtext.SetValue('') 4408 UpdateRMC() 4409 4410 G2frame.GetStatusBar().SetStatusText('',1) 4411 mainSizer = wx.BoxSizer(wx.VERTICAL) 4412 runFile = ' ' 4413 choice = ['fullrmc','RMCProfile'] 4414 RMCsel = wx.RadioBox(G2frame.FRMC,-1,' Select RMC method:',choices=choice) 4415 RMCsel.SetStringSelection(G2frame.RMCchoice) 4416 RMCsel.Bind(wx.EVT_RADIOBOX, OnRMCselect) 4417 mainSizer.Add(RMCsel,0,WACV) 4418 if G2frame.RMCchoice == 'fullrmc': 4419 mainSizer.Add(wx.StaticText(G2frame.FRMC,label=' fullrmc run.py file preparation:'),0,WACV) 4420 # font1 = wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Consolas') 4421 G2frame.runtext = wx.TextCtrl(G2frame.FRMC,style=wx.TE_MULTILINE|wx.TE_DONTWRAP,size=(850,450)) 4422 # G2frame.runtext.SetFont(font1) 4423 else: 4424 mainSizer.Add(wx.StaticText(G2frame.FRMC,label=' RMCProfile input file preparation:'),0,WACV) 4425 4426 4427 mainSizer.Add((5,5),0,WACV) 4428 mainSizer.Add(G2frame.runtext) 4429 SetPhaseWindow(G2frame.FRMC,mainSizer) 4430 4431 def OnSetupRMC(event): 4336 4432 generalData = data['General'] 4337 4433 pName = generalData['Name'].replace(' ','_') 4338 4339 def OnSetupFullRMC(event): 4340 print('Setup new run.py - not yet implemented') 4341 4342 def OnLoadFullRMC(event): 4343 print('Load run.py - not yet implemented') 4344 4345 def OnSaveFullRMC(event): 4346 print('Save run.py - not yet implemented') 4347 4348 def OnEditFullRMC(event): 4349 print('Edit run.py - not yet implemented') 4350 4351 def OnRunFullRMC(event): 4352 print('Run run.py - not yet implemented') 4434 if G2frame.RMCchoice == 'fullrmc': 4435 rundata = ''' 4436 ########################################################################################## 4437 ############################## IMPORTING USEFUL DEFINITIONS ############################ 4438 # standard libraries imports 4439 import os 4440 4441 # external libraries imports 4442 import numpy as np 4443 4444 # fullrmc library imports - these are some examples; others may be needed for your problem 4445 from fullrmc.Globals import LOGGER, FLOAT_TYPE 4446 from fullrmc.Engine import Engine 4447 from fullrmc.Constraints.PairDistributionConstraints import PairDistributionConstraint 4448 from fullrmc.Constraints.PairCorrelationConstraints import PairCorrelationConstraint 4449 from fullrmc.Constraints.DistanceConstraints import InterMolecularDistanceConstraint 4450 from fullrmc.Constraints.BondConstraints import BondConstraint 4451 from fullrmc.Constraints.AngleConstraints import BondsAngleConstraint 4452 from fullrmc.Constraints.ImproperAngleConstraints import ImproperAngleConstraint 4453 from fullrmc.Core.Collection import convert_Gr_to_gr 4454 from fullrmc.Core.MoveGenerator import MoveGeneratorCollector 4455 from fullrmc.Core.GroupSelector import RecursiveGroupSelector 4456 from fullrmc.Selectors.RandomSelectors import RandomSelector 4457 from fullrmc.Selectors.OrderedSelectors import DefinedOrderSelector 4458 from fullrmc.Generators.Translations import TranslationGenerator, TranslationAlongSymmetryAxisGenerator 4459 from fullrmc.Generators.Rotations import RotationGenerator, RotationAboutSymmetryAxisGenerator 4460 from fullrmc.Generators.Agitations import DistanceAgitationGenerator, AngleAgitationGenerator 4461 4462 4463 ########################################################################################## 4464 ##################################### CREATE ENGINE #################################### 4465 # dirname 4466 DIR_PATH = os.path.dirname( os.path.realpath(__file__) ) 4467 4468 # engine file names - replace name with phase name 4469 engineFileName = "name_engine.rmc" 4470 expFileName = "name_pdf.exp" 4471 pdbFileName = "nme.pdb" 4472 freshStart = False #make TRUE for a restart 4473 4474 ''' 4475 G2frame.runtext.SetValue(rundata) 4476 else: 4477 dlg = SetUpRMCProfileDialog(G2frame,Name=pName,Phase=data) 4478 if dlg.ShowModal() == wx.ID_OK: 4479 superCell,histoName,meta = dlg.GetData() 4480 PWId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,histoName) 4481 if PWId: 4482 print(G2pwd.MakeInst(G2frame,pName,PWId)+ ' written') 4483 backfile = G2pwd.MakeBack(G2frame,pName,PWId) 4484 if backfile is None: 4485 print(' Chebyschev background not used; no .back file written') 4486 else: 4487 print(backfile+ ' written') 4488 print(G2pwd.MakeBragg(G2frame,pName,data,PWId)+ ' written') 4489 print(G2pwd.MakeRMC6f(G2frame,pName,data,meta,superCell,PWId)+ ' written') 4490 print('RMCProfile file build completed') 4491 else: 4492 print('RMCProfile file build failed - no histogram selected') 4493 else: 4494 pass 4495 dlg.Destroy() 4496 4497 def OnLoadRMC(event): 4498 global runFile 4499 if G2frame.RMCchoice == 'fullrmc': 4500 dlg = wx.FileDialog(G2frame, 'Choose fullrmc run file to open', '.', runFile, 4501 wildcard='fullrmc run.py file (*.py)|*.py',style=wx.FD_OPEN| wx.FD_CHANGE_DIR) 4502 else: 4503 dlg = wx.FileDialog(G2frame, 'Choose RMCProfile control file to open', '.', runFile, 4504 wildcard='RMCProfile control file (*.dat)|*.dat|All files (*.*)|*.*',style=wx.FD_OPEN| wx.FD_CHANGE_DIR) 4505 try: 4506 if dlg.ShowModal() == wx.ID_OK: 4507 runFile = dlg.GetPath() 4508 runpy = open(runFile,'r') 4509 G2frame.runtext.SetValue(runpy.read()) 4510 runpy.close() 4511 else: 4512 return 4513 finally: 4514 dlg.Destroy() 4515 4516 def OnSaveRMC(event): 4517 global runFile 4518 if G2frame.RMCchoice == 'fullrmc': 4519 dlg = wx.FileDialog(G2frame, 'Choose fullrmc run.py file to save', '.', runFile, 4520 wildcard='fullrmc run.py file (*.py)|*.py',style=wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) 4521 else: 4522 dlg = wx.FileDialog(G2frame, 'Choose RMCProfile control file to save', '.', runFile, 4523 wildcard='RMCProfile control file (*.dat)|*.dat|All files (*.*)|*.*',style=wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) 4524 try: 4525 if dlg.ShowModal() == wx.ID_OK: 4526 runFile = dlg.GetPath() 4527 runpy = open(runFile,'w') 4528 runpy.write(G2frame.runtext.GetValue()) 4529 runpy.close() 4530 else: 4531 return 4532 finally: 4533 dlg.Destroy() 4534 4535 def OnRunRMC(event): 4536 4537 if G2frame.RMCchoice == 'fullrmc': 4538 wx.MessageBox(''' For use of fullrmc, please cite: 4539 Fullrmc, a Rigid Body Reverse Monte Carlo Modeling Package Enabled with 4540 Machine Learning and Artificial Intelligence, 4541 B. Aoun, Jour. Comp. Chem. 2016, 37, 1102-1111. 4542 doi: https://doi.org/10.1002/jcc.24304''',caption='fullrmc',style=wx.ICON_INFORMATION) 4543 dlg = wx.FileDialog(G2frame, 'Choose fullrmc python file to execute', 4544 wildcard='fullrmc python file (*.py)|*.py',style=wx.FD_CHANGE_DIR) 4545 else: 4546 wx.MessageBox(''' For use of RMCProfile, please cite: 4547 RMCProfile: Reverse Monte Carlo for polycrystalline materials, 4548 M.G. Tucker, D.A. keen, M.T. Dove, A.L. Goodwin and Q. Hui, 4549 Jour. Phys.: Cond. matter 2007, 19, 335218. 4550 doi: https://doi.org/10.1088/0953-8984/19/33/335218''',caption='RMCProfile',style=wx.ICON_INFORMATION) 4551 return 4552 try: 4553 if dlg.ShowModal() == wx.ID_OK: 4554 import subprocess as sb 4555 batch = open('fullrmc.bat','w') 4556 batch.write(sys.exec_prefix+'\\activate\n') 4557 batch.write(sys.exec_prefix+'\\python.exe '+dlg.GetPath()+'\n') 4558 batch.write('pause') 4559 batch.close() 4560 sb.Popen('fullrmc.bat',creationflags=sb.CREATE_NEW_CONSOLE) 4561 else: 4562 return 4563 finally: 4564 dlg.Destroy() 4565 4353 4566 4354 4567 … … 9773 9986 G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.MEMMenu) 9774 9987 UpdateDysnomia() 9775 elif text == ' fullrmc':9988 elif text == 'RMC': 9776 9989 G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.FRMCMenu) 9777 Update FullRMC()9990 UpdateRMC() 9778 9991 elif text == 'Draw Options': 9779 9992 G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.DataDrawOptions) … … 9921 10134 G2frame.Bind(wx.EVT_MENU, OnPeaksClear, id=G2G.wxID_PEAKSCLEAR) 9922 10135 # fullrmc 9923 FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.FRMCMenu) 9924 G2frame.Bind(wx.EVT_MENU, OnSetupFullRMC, id=G2G.wxID_SETUPFULLRMC) 9925 G2frame.Bind(wx.EVT_MENU, OnLoadFullRMC, id=G2G.wxID_LOADFULLRMC) 9926 G2frame.Bind(wx.EVT_MENU, OnSaveFullRMC, id=G2G.wxID_SAVEFULLRMC) 9927 G2frame.Bind(wx.EVT_MENU, OnEditFullRMC, id=G2G.wxID_EDITFULLRMC) 9928 G2frame.Bind(wx.EVT_MENU, OnRunFullRMC, id=G2G.wxID_RUNFULLRMC) 10136 try: 10137 import fullrmc 10138 FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.FRMCMenu) 10139 G2frame.Bind(wx.EVT_MENU, OnSetupRMC, id=G2G.wxID_SETUPRMC) 10140 G2frame.Bind(wx.EVT_MENU, OnLoadRMC, id=G2G.wxID_LOADRMC) 10141 G2frame.Bind(wx.EVT_MENU, OnSaveRMC, id=G2G.wxID_SAVERMC) 10142 G2frame.Bind(wx.EVT_MENU, OnRunRMC, id=G2G.wxID_RUNRMC) 10143 except: 10144 pass 9929 10145 # MC/SA 9930 10146 FillSelectPageMenu(TabSelectionIdDict, G2frame.dataWindow.MCSAMenu) … … 10018 10234 G2frame.phaseDisplay.AddPage(G2frame.MCSA,'MC/SA') 10019 10235 Pages.append('MC/SA') 10020 G2frame.FRMC = wx.ScrolledWindow(G2frame.phaseDisplay) 10021 G2frame.phaseDisplay.AddPage(G2frame.FRMC,'fullrmc') 10022 Pages.append('fullrmc') 10236 try: 10237 import fullrmc 10238 G2frame.FRMC = wx.ScrolledWindow(G2frame.phaseDisplay) 10239 G2frame.phaseDisplay.AddPage(G2frame.FRMC,'RMC') 10240 Pages.append('RMC') 10241 except: 10242 pass 10023 10243 Texture = wx.ScrolledWindow(G2frame.phaseDisplay) 10024 10244 G2frame.phaseDisplay.AddPage(Texture,'Texture') -
trunk/GSASIIpwd.py
r4191 r4192 2066 2066 WYI = np.where(WYI>0.,WYI,0.) 2067 2067 return YI,WYI 2068 2069 ################################################################################ 2070 #### RMCutilities 2071 ################################################################################ 2072 2073 def MakeInst(G2frame,Name,PWId): 2074 PWDdata = G2frame.GetPWDRdatafromTree(PWId) 2075 inst = PWDdata['Instrument Parameters'][0] 2076 prms = ['Bank', 2077 'difC','difA','Zero','2-theta', 2078 'alpha','beta-0','beta-1','sig-0', 2079 'sig-1','sig-2','X','Y'] 2080 fname = Name+'.inst' 2081 fl = open(fname,'w') 2082 fl.write(' 1\n') 2083 fl.write('%10d\n'%int(inst[prms[0]][1])) 2084 fl.write('%10.3f%10.3f%10.3f%10.3f\n'%(inst[prms[1]][1],inst[prms[2]][1],inst[prms[3]][1],inst[prms[4]][1])) 2085 fl.write('%10.3f%10.6f%10.6f%10.3f\n'%(inst[prms[5]][1],inst[prms[6]][1],inst[prms[7]][1],inst[prms[8]][1])) 2086 fl.write('%10.3f%10.3f%10.3f%10.4f\n'%(inst[prms[9]][1],inst[prms[10]][1],0.0,inst[prms[12]][1])) 2087 fl.write('%10.4f%10.3f%10.3f%10.3f\n'%(inst[prms[11]][1],0.0,0.0,0.0)) 2088 fl.close() 2089 return fname 2090 2091 def MakeBack(G2frame,Name,PWId): 2092 PWDdata = G2frame.GetPWDRdatafromTree(PWId) 2093 Back = PWDdata['Background'][0] 2094 if 'chebyschev' not in Back[0]: 2095 return None 2096 Nback = Back[2] 2097 BackVals = Back[3:] 2098 fname = Name+'.back' 2099 fl = open(fname,'w') 2100 fl.write('%10d\n'%Nback) 2101 for val in BackVals: 2102 fl.write('%12.6g\n'%val) 2103 fl.close() 2104 return fname 2105 2106 def MakeRMC6f(G2frame,Name,Phase,Meta,Supercell,PWId): 2107 PWDdata = G2frame.GetPWDRdatafromTree(PWId) 2108 generalData = Phase['General'] 2109 Sample = PWDdata['Sample Parameters'] 2110 Meta['temperature'] = Sample['Temperature'] 2111 Meta['pressure'] = Sample['Pressure'] 2112 Cell = generalData['Cell'][1:7] 2113 Trans = np.eye(3)*np.array(Supercell) 2114 newPhase = copy.deepcopy(Phase) 2115 newPhase['General']['SGData'] = G2spc.SpcGroup('P 1')[1] 2116 newPhase['General']['Cell'][1:] = G2lat.TransformCell(Cell,Trans.T) 2117 newPhase,Atcodes = G2lat.TransformPhase(Phase,newPhase,Trans,np.zeros(3),np.zeros(3),ifMag=False) 2118 Atoms = newPhase['Atoms'] 2119 Cell = newPhase['General']['Cell'][1:7] 2120 fname = Name+'.rmc6f' 2121 fl = open(fname,'w') 2122 fl.write('(Version 6f format configuration file)\n') 2123 for item in Meta: 2124 fl.write('%-20s: %s\n'%('Metadata '+item,Meta[item])) 2125 fl.write('Supercell dimensions: %d %d %d\n'%(Supercell[0],Supercell[1],Supercell[2])) 2126 fl.write('Cell (Ang/deg): %f %f %f %f %f %f\n'%( 2127 Cell[0],Cell[1],Cell[2],Cell[3],Cell[4],Cell[5])) 2128 fl.write('Atoms (fractional coordinates):\n') 2129 for iat,atom in enumerate(Atoms): 2130 atcode = Atcodes[iat].split(':') 2131 cell = [0,0,0] 2132 if '+' in atcode[1]: 2133 cell = eval(atcode[1].split('+')[1]) 2134 fl.write('%6d%6s [%s]%10.6f%10.6f%10.6f%5d%5d%5d%5d\n'%( 2135 iat,atom[1],atcode[0],atom[3],atom[4],atom[5],0,cell[0],cell[1],cell[2])) 2136 fl.close() 2137 return fname 2138 2139 def MakeBragg(G2frame,Name,Phase,PWId): 2140 PWDdata = G2frame.GetPWDRdatafromTree(PWId) 2141 generalData = Phase['General'] 2142 Vol = generalData['Cell'][7] 2143 Data = PWDdata['Data'] 2144 Inst = PWDdata['Instrument Parameters'][0] 2145 Bank = int(Inst['Bank'][1]) 2146 Sample = PWDdata['Sample Parameters'] 2147 Scale = Sample['Scale'][0] 2148 Limits = PWDdata['Limits'][1] 2149 Ibeg = np.searchsorted(Data[0],Limits[0]) 2150 Ifin = np.searchsorted(Data[0],Limits[1])+1 2151 fname = Name+'.bragg' 2152 fl = open(fname,'w') 2153 fl.write('%10d%10d%12.4f%12.4f\n'%(Ifin-Ibeg,Bank,Scale,Vol)) 2154 fl.write('%12s%12s\n'%(' TOF,ms',' I(obs)')) 2155 for i in range(Ibeg,Ifin-1): 2156 fl.write('%12.8f%12.6f\n'%(Data[0][i]/1000.,Data[1][i])) 2157 fl.close() 2158 return fname 2068 2159 2069 2160 ################################################################################ -
trunk/GSASIIpwdGUI.py
r4191 r4192 50 50 import GSASIIphsGUI as G2phsG 51 51 import GSASIIctrlGUI as G2G 52 import GSASIIIO as G2IO 52 53 import GSASIIElemGUI as G2elemGUI 53 54 import GSASIIElem as G2elem … … 1852 1853 finds matching bank no. to load - rejects nonmatches. 1853 1854 1854 Note that similar code is found in ReadPowderInstprm (GSASII .py)1855 Note that similar code is found in ReadPowderInstprm (GSASIIdataGUI.py) 1855 1856 ''' 1857 1858 def GetDefaultParms(rd): 1859 '''Solicits from user a default set of parameters & returns Inst parm dict 1860 param: self: refers to the GSASII main class 1861 param: rd: importer data structure 1862 returns: dict: Instrument parameter dictionary 1863 ''' 1864 import defaultIparms as dI 1865 sind = lambda x: math.sin(x*math.pi/180.) 1866 tand = lambda x: math.tan(x*math.pi/180.) 1867 while True: # loop until we get a choice 1868 choices = [] 1869 head = 'Select from default instrument parameters' 1870 1871 for l in dI.defaultIparm_lbl: 1872 choices.append('Defaults for '+l) 1873 res = G2IO.BlockSelector(choices,ParentFrame=G2frame,title=head, 1874 header='Select default inst parms',useCancel=True) 1875 if res is None: return None 1876 if 'Generic' in choices[res]: 1877 dlg = G2G.MultiDataDialog(G2frame,title='Generic TOF detector bank', 1878 prompts=['Total FP','2-theta',],values=[25.0,150.,], 1879 limits=[[6.,200.],[5.,175.],],formats=['%6.2f','%6.1f',]) 1880 if dlg.ShowModal() == wx.ID_OK: #strictly empirical approx. 1881 FP,tth = dlg.GetValues() 1882 difC = 505.632*FP*sind(tth/2.) 1883 sig1 = 50.+2.5e-6*(difC/tand(tth/2.))**2 1884 bet1 = .00226+7.76e+11/difC**4 1885 Inst = G2frame.ReadPowderInstprm(dI.defaultIparms[res],bank,1,rd) 1886 Inst[0]['difC'] = [difC,difC,0] 1887 Inst[0]['sig-1'] = [sig1,sig1,0] 1888 Inst[0]['beta-1'] = [bet1,bet1,0] 1889 return Inst #this is [Inst1,Inst2] a pair of dicts 1890 dlg.Destroy() 1891 else: 1892 inst1,inst2 = G2frame.ReadPowderInstprm(dI.defaultIparms[res],bank,1,rd) 1893 return [inst1,inst2] 1894 if 'lab data' in choices[res]: 1895 rd.Sample.update({'Type':'Bragg-Brentano','Shift':[0.,False],'Transparency':[0.,False], 1896 'SurfRoughA':[0.,False],'SurfRoughB':[0.,False]}) 1897 else: 1898 rd.Sample.update({'Type':'Debye-Scherrer','Absorption':[0.,False],'DisplaceX':[0.,False], 1899 'DisplaceY':[0.,False]}) 1900 1856 1901 data = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame, 1857 1902 G2frame.PatternId,'Instrument Parameters'))[0] … … 1903 1948 else: 1904 1949 G2frame.ErrorDialog('No match','Bank %d not in %s'%(bank,filename),G2frame) 1950 else: 1951 rd = G2frame 1952 rd.Sample = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Sample Parameters')) 1953 data = GetDefaultParms(rd)[0] 1905 1954 UpdateInstrumentGrid(G2frame,data) 1906 1955 G2plt.PlotPeakWidths(G2frame) 1907 1956 finally: 1908 1957 dlg.Destroy() -
trunk/imports/G2pdf_gr.py
r4015 r4192 57 57 58 58 def Reader(self,filename,ParentFrame=None, **unused): 59 print ('Read a q-step text file')59 print ('Read a r-step text file') 60 60 x = [] 61 61 y = [] … … 90 90 return True 91 91 92 class txt_PDFReaderClassG(G2obj.ImportPDFData): 93 'Routines to import PDF G(R) data from a .dat file' 94 def __init__(self): 95 super(self.__class__,self).__init__( # fancy way to self-reference 96 extensionlist=('.dat',), 97 strictExtension=False, 98 formatName = 'gudrun r (A) step G(r) data', 99 longFormatName = 'r (A) stepped G(r) PDF data from gudrun' 100 ) 101 102 # Validate the contents -- make sure we only have valid lines 103 def ContentsValidator(self, filename): 104 'Look through the file for expected types of lines in a valid r-step file' 105 filepointer = open(filename,'r') 106 Ndata = 0 107 for i,S in enumerate(filepointer): 108 if i < 2: 109 continue 110 vals = S.split() 111 if len(vals) >= 2: 112 try: 113 data = [float(val) for val in vals] 114 Ndata += 1 115 except ValueError: 116 pass 117 if not Ndata: 118 self.errors = 'No 2 or more column numeric data found' 119 filepointer.close() 120 return False 121 filepointer.close() 122 return True # no errors encountered 123 124 def Reader(self,filename,ParentFrame=None, **unused): 125 print ('Read a r-step text file') 126 x = [] 127 y = [] 128 filepointer = open(filename,'r') 129 for i,S in enumerate(filepointer): 130 if i < 2: 131 continue 132 vals = S.split() 133 if len(vals) >= 2: 134 try: 135 data = [float(val) for val in vals] 136 x.append(float(data[0])) 137 y.append(float(data[1])) 138 except ValueError: 139 msg = 'Error in line '+str(i+1) 140 print (msg) 141 continue 142 else: 143 break 144 self.pdfdata = np.array([ 145 np.array(x), # x-axis values r 146 np.array(y), # pdf g(r) 147 ]) 148 self.pdfentry[0] = filename 149 self.pdfentry[2] = 1 # xy file only has one bank 150 self.idstring = ospath.basename(filename) 151 152 return True 153 -
trunk/imports/G2pwd_fxye.py
r3742 r4192 26 26 def __init__(self): 27 27 super(self.__class__,self).__init__( # fancy way to self-reference 28 extensionlist=('.fxye','.raw','.gsas','.gda','.gsa','.gss','.RAW','.GSAS','.GDA','.GSA' ),28 extensionlist=('.fxye','.raw','.gsas','.gda','.gsa','.gss','.RAW','.GSAS','.GDA','.GSA','.dat'), 29 29 strictExtension=False, 30 30 formatName = 'GSAS powder data',
Note: See TracChangeset
for help on using the changeset viewer.