Changeset 4404 for trunk/GSASIIphsGUI.py
- Timestamp:
- Apr 19, 2020 11:52:51 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIphsGUI.py
r4401 r4404 4411 4411 atmChoice.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict['aTypes'],atId,min=0.,max=1.),0,WACV) 4412 4412 return atmChoice 4413 4414 4413 4414 def FileSizer(RMCdict): 4415 4416 def OnFitScale(event): 4417 RMCPdict['FitScale'] = not RMCPdict['FitScale'] 4418 4419 def OnFileSel(event): 4420 Obj = event.GetEventObject() 4421 fil = Indx[Obj.GetId()] 4422 dlg = wx.FileDialog(G2frame.FRMC, 'Choose '+fil,G2G.GetImportPath(G2frame), 4423 style=wx.FD_OPEN ,wildcard=fil+'(*.*)|*.*') 4424 if dlg.ShowModal() == wx.ID_OK: 4425 fpath,fName = os.path.split(dlg.GetPath()) 4426 if fpath != G2frame.LastGPXdir: 4427 disfile.copy_file(dlg.GetPath(),os.path.join(G2frame.LastGPXdir,fName)) 4428 if os.path.exists(fName): 4429 RMCPdict['files'][fil][0] = fName 4430 G2frame.LastImportDir = fpath #set so next file is found in same place 4431 dlg.Destroy() 4432 else: 4433 dlg.Destroy() 4434 return 4435 wx.CallAfter(UpdateRMC) 4436 4437 def OnFileFormat(event): 4438 Obj = event.GetEventObject() 4439 fil = Indx[Obj.GetId()] 4440 RMCPdict['files'][fil][3] = Obj.GetStringSelection() 4441 4442 def OnPlotBtn(event): 4443 Obj = event.GetEventObject() 4444 fil = Indx[Obj.GetId()] 4445 fileItem = RMCPdict['files'][fil] 4446 start = 0 4447 XY = np.empty((1,2)) 4448 while XY.shape[0] == 1: 4449 try: 4450 XY = np.loadtxt(fileItem[0],skiprows=start) 4451 except ValueError: 4452 start += 1 4453 Xlab = 'Q' 4454 if 'G(R)' in fileItem[2]: 4455 Xlab = 'R' 4456 G2plt.PlotXY(G2frame,[XY.T,],labelX=Xlab, 4457 labelY=fileItem[2],newPlot=True,Title=fileItem[0], 4458 lines=True) 4459 4460 Indx = {} 4461 titleSizer = wx.BoxSizer(wx.HORIZONTAL) 4462 titleSizer.Add(wx.StaticText(G2frame.FRMC,label=' Select data for processing: '),0,WACV) 4463 fitscale = wx.CheckBox(G2frame.FRMC,label=' Fit scale factors?') 4464 fitscale.SetValue(RMCPdict['FitScale']) 4465 fitscale.Bind(wx.EVT_CHECKBOX,OnFitScale) 4466 titleSizer.Add(fitscale,0,WACV) 4467 mainSizer.Add(titleSizer,0,WACV) 4468 ncol= 5 4469 Heads = ['Name','File','Format','Weight','Plot'] 4470 if G2frame.RMCchoice == 'fullrmc': 4471 mainSizer.Add(wx.StaticText(G2frame.FRMC, 4472 label=' NB: fullrmc data files must be 2 columns; all other lines preceeded by "#". Edit before use.'),0,WACV) 4473 ncol = 4 4474 Heads = ['Name','File','Weight','Plot'] 4475 fileSizer = wx.FlexGridSizer(ncol,5,5) 4476 Formats = ['RMC','GUDRUN','STOG'] 4477 for head in Heads: 4478 fileSizer.Add(wx.StaticText(G2frame.FRMC,label=head),0,WACV) 4479 for fil in RMCPdict['files']: 4480 fileSizer.Add(wx.StaticText(G2frame.FRMC,label=fil),0,WACV) 4481 Rfile = RMCPdict['files'][fil][0] 4482 filSel = wx.Button(G2frame.FRMC,label=Rfile) 4483 filSel.Bind(wx.EVT_BUTTON,OnFileSel) 4484 Indx[filSel.GetId()] = fil 4485 fileSizer.Add(filSel,0,WACV) 4486 if Rfile and os.path.exists(Rfile): #incase .gpx file is moved away from G(R), F(Q), etc. files 4487 if G2frame.RMCchoice == 'RMCProfile': 4488 nform = 3 4489 if 'Xray' in fil: nform = 1 4490 fileFormat = wx.ComboBox(G2frame.FRMC,choices=Formats[:nform],style=wx.CB_DROPDOWN|wx.TE_READONLY) 4491 fileFormat.SetStringSelection(RMCPdict['files'][fil][3]) 4492 Indx[fileFormat.GetId()] = fil 4493 fileFormat.Bind(wx.EVT_COMBOBOX,OnFileFormat) 4494 fileSizer.Add(fileFormat,0,WACV) 4495 fileSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict['files'][fil],1),0,WACV) 4496 plotBtn = wx.Button(G2frame.FRMC,label='Plot?') 4497 plotBtn.Bind(wx.EVT_BUTTON,OnPlotBtn) 4498 Indx[plotBtn.GetId()] = fil 4499 fileSizer.Add(plotBtn,0,WACV) 4500 else: 4501 RMCPdict['files'][fil][0] = 'Select' 4502 fileSizer.Add((5,5),0) 4503 fileSizer.Add((5,5),0) 4504 if G2frame.RMCchoice == 'RMCProfile': 4505 fileSizer.Add((5,5),0) 4506 return fileSizer 4507 4415 4508 G2frame.GetStatusBar().SetStatusText('',1) 4416 4509 if G2frame.RMCchoice == 'RMCProfile': … … 4447 4540 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True) 4448 4541 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_VIEWRMC,True) 4449 mainSizer.Add(wx.StaticText(G2frame.FRMC,label=' fullrmc run.pyfile preparation:'),0,WACV)4542 mainSizer.Add(wx.StaticText(G2frame.FRMC,label=' fullrmc big box starting pdb file preparation:'),0,WACV) 4450 4543 if not data['RMC']['fullrmc']: 4451 4544 Atypes = data['General']['AtomTypes'] … … 4457 4550 Pairs += pair 4458 4551 Pairs = {pairs:[0.0,0.0,0.0] for pairs in Pairs} 4459 files = {'Neutron real space data; G(r): ':['',0.05,'G(r)','RMC',], 4460 'Neutron reciprocal space data; F(Q): ':['',0.05,'F(Q)','RMC',], 4461 'Neutron reciprocal space data; S(Q): ':['',0.05,'S(Q)','RMC',], 4462 'Xray real space data; G(r): ':['',0.01,'G(r)','RMC',], 4463 'Xray reciprocal space data; F(Q): ':['',0.01,'F(Q)','RMC',],} 4464 data['RMC']['fullrmc'] = {'ifBox':True,'SuperCell':[1,1,1],'Box':[10.,10.,10.],'aTypes':aTypes, 4465 'atSeq':atSeq,'Pairs':Pairs,'files':files,'ReStart':[False,False],'Swaps':[],'useBVS':False, 4466 'AveCN':[],'FxCN':[],'moleculePdb':'Select','targetDensity':1.0,'maxRecursion':10000} 4552 files = {'Neutron real space data; G(r): ':['Select',0.05,'G(r)'], 4553 'Neutron reciprocal space data; F(Q): ':['Select',0.05,'F(Q)'], 4554 'Neutron reciprocal space data; S(Q): ':['Select',0.05,'S(Q)'], 4555 'Xray real space data; G(r): ':['Select',0.01,'G(r)'], 4556 'Xray reciprocal space data; F(Q): ':['Select',0.01,'F(Q)'],} 4557 data['RMC']['fullrmc'] = {'SuperCell':[1,1,1],'Box':[10.,10.,10.],'aTypes':aTypes,'byMolec':False, 4558 'Natoms':1,'atSeq':atSeq,'Pairs':Pairs,'files':files,'ReStart':[False,False], 4559 'Swaps':[],'useBVS':False,'FitScale':False,'AveCN':[],'FxCN':[], 4560 'moleculePdb':'Select','targetDensity':1.0,'maxRecursion':10000, 4561 'atomPDB':''} 4467 4562 RMCPdict = data['RMC']['fullrmc'] 4468 4563 … … 4485 4580 return boxSizer 4486 4581 4487 def OnBoxChoice(event): 4488 RMCPdict['ifBox'] = not RMCPdict['ifBox'] 4489 UpdateRMC() 4490 4582 def OnByMolec(event): 4583 RMCPdict['byMolec'] = bymolec.GetValue() 4584 4491 4585 def OnReStart(event): 4492 4586 RMCPdict['ReStart'][0] = not RMCPdict['ReStart'][0] … … 4501 4595 4502 4596 def OnMakePDB(event): 4597 if not ifBox: 4598 generalData = data['General'] 4599 pName = generalData['Name'].replace(' ','_') 4600 pdbname = G2pwd.MakefullrmcPDB(pName,data,RMCPdict) 4601 RMCPdict['atomPDB'] = pdbname 4602 print(pdbname+ ' written') 4603 return 4604 if RMCPdict['moleculePdb'] == 'Select': 4605 wx.MessageDialog(G2frame,' You must select a source pdb file first','PDB generation error', 4606 wx.ICON_EXCLAMATION).ShowModal() 4607 return 4503 4608 dlg = wx.MessageDialog(G2frame,''' 4504 4609 Warning - this step can take more than an hour; do you want to proceed? … … 4527 4632 if 'moleculePdb' not in RMCPdict: 4528 4633 RMCPdict.update({'moleculePdb':'Select','targetDensity':1.0,'maxRecursion':10000}) 4634 if 'byMolec' not in RMCPdict: 4635 RMCPdict['byMolec'] = False 4636 if 'Natoms' not in RMCPdict: 4637 RMCPdict['Natoms'] = 1 4638 if 'FitScale' not in RMCPdict: 4639 RMCPdict['FitScale'] = False 4640 if 'atomPDB' not in RMCPdict: 4641 RMCPdict['atomPDB'] = '' 4529 4642 #end patches 4530 restart = wx.CheckBox(G2frame.FRMC,label=' Restart fullrmc Engine? (will clear old result!) ') 4531 restart.SetValue(RMCPdict['ReStart'][0])4532 restart.Bind(wx.EVT_CHECKBOX,OnReStart)4533 mainSizer.Add(restart,0,WACV)4534 4643 4644 generalData = data['General'] 4645 ifBox = False 4646 if 'macromolecular' in generalData['Type']: 4647 ifBox = True 4535 4648 lineSizer = wx.BoxSizer(wx.HORIZONTAL) 4536 if RMCPdict['ifBox']:4649 if ifBox: 4537 4650 lineSizer.Add(wx.StaticText(G2frame.FRMC,label=' Big box dimensions, %s:'%Angstr),0,WACV) 4538 4651 lineSizer.Add(GetBoxSizer(),0,WACV) 4539 boxBtn = wx.Button(G2frame.FRMC,label='Use super lattice')4540 4652 else: 4541 4653 lineSizer.Add(wx.StaticText(G2frame.FRMC,label=' Lattice multipliers:'),0,WACV) 4542 4654 lineSizer.Add(GetSuperSizer(),0,WACV) 4543 boxBtn = wx.Button(G2frame.FRMC,label='Use big box dimensions') 4544 boxBtn.Bind(wx.EVT_BUTTON,OnBoxChoice) 4545 lineSizer.Add(boxBtn,0,WACV) 4655 bymolec = wx.CheckBox(G2frame.FRMC,label='Save in molecule order?') 4656 bymolec.SetValue(RMCPdict['byMolec']) 4657 bymolec.Bind(wx.EVT_CHECKBOX,OnByMolec) 4658 lineSizer.Add(bymolec,0,WACV) 4659 lineSizer.Add(wx.StaticText(G2frame.FRMC,label=' Num. atoms per molecule '),0,WACV) 4660 lineSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict,'Natoms',min=1,size=[40,25]),0,WACV) 4546 4661 mainSizer.Add(lineSizer,0,WACV) 4547 if RMCPdict['ifBox']:4662 if ifBox: 4548 4663 molecSizer = wx.BoxSizer(wx.HORIZONTAL) 4549 4664 molecSizer.Add(wx.StaticText(G2frame.FRMC,label=' Source molecule file '),0,WACV) … … 4559 4674 molecSizer.Add(makePDB,0,WACV) 4560 4675 mainSizer.Add(molecSizer,0,WACV) 4676 else: 4677 makePDB = wx.Button(G2frame.FRMC,label='Make big box PDB') 4678 makePDB.Bind(wx.EVT_BUTTON,OnMakePDB) 4679 mainSizer.Add(makePDB,0,WACV) 4680 4561 4681 G2G.HorizontalLine(mainSizer,G2frame.FRMC) 4562 4682 mainSizer.Add(wx.StaticText(G2frame.FRMC,label=' fullrmc run file preparation:'),0,WACV) 4683 restart = wx.CheckBox(G2frame.FRMC,label=' Restart fullrmc Engine? (will clear old result!) ') 4684 restart.SetValue(RMCPdict['ReStart'][0]) 4685 restart.Bind(wx.EVT_CHECKBOX,OnReStart) 4686 mainSizer.Add(restart,0,WACV) 4687 4688 G2G.HorizontalLine(mainSizer,G2frame.FRMC) 4563 4689 mainSizer.Add(GetAtmChoice(RMCPdict),0,WACV) 4564 4690 4565 4691 G2G.HorizontalLine(mainSizer,G2frame.FRMC) 4692 mainSizer.Add(FileSizer(RMCPdict),0,WACV) 4566 4693 4567 4694 elif G2frame.RMCchoice == 'RMCProfile': … … 4585 4712 BVSpairs += pair 4586 4713 BVS = {pairs:[0.0,0.0,0.0,0.0] for pairs in BVSpairs} 4587 files = {'Neutron real space data; G(r): ':[' ',0.05,'G(r)','RMC',],4588 'Neutron reciprocal space data; F(Q): ':[' ',0.05,'F(Q)','RMC',],4589 'Neutron reciprocal space data; S(Q): ':[' ',0.05,'S(Q)','RMC',],4590 # 'Xray real space data; G(r): ':[' ',0.01,'G(r)','RMC',],4591 'Xray reciprocal space data; F(Q): ':[' ',0.01,'F(Q)','RMC',],}4714 files = {'Neutron real space data; G(r): ':['Select',0.05,'G(r)','RMC',], 4715 'Neutron reciprocal space data; F(Q): ':['Select',0.05,'F(Q)','RMC',], 4716 'Neutron reciprocal space data; S(Q): ':['Select',0.05,'S(Q)','RMC',], 4717 # 'Xray real space data; G(r): ':['Select',0.01,'G(r)','RMC',], 4718 'Xray reciprocal space data; F(Q): ':['Select',0.01,'F(Q)','RMC',],} 4592 4719 runTimes = [10.,1.] 4593 4720 metadata = {'title':'none','owner':'no one','date':str(time.ctime()),'temperature':'300K', 4594 4721 'material':'nothing','phase':'vacuum','comment':'none ','source':'nowhere'} 4595 4722 data['RMC']['RMCProfile'] = {'SuperCell':[1,1,1],'UseSampBrd':[True,True],'aTypes':aTypes, 4596 'atSeq':atSeq,'Pairs':Pairs,'histogram':['',1.0],'files':files,'metadata':metadata, 4723 'atSeq':atSeq,'Pairs':Pairs,'histogram':['',1.0],'files':files,'metadata':metadata,'FitScale':False, 4597 4724 'runTimes':runTimes,'ReStart':[False,False],'BVS':BVS,'Oxid':atOxid,'useBVS':False,'Swaps':[], 4598 4725 'AveCN':[],'FxCN':[],'Potentials':{'Angles':[],'Angle search':10.,'Stretch':[], … … 4615 4742 def OnStrain(event): 4616 4743 RMCPdict['UseSampBrd'][1] = strain.GetValue() 4617 4618 def OnFileSel(event):4619 Obj = event.GetEventObject()4620 fil = Indx[Obj.GetId()]4621 dlg = wx.FileDialog(G2frame.FRMC, 'Choose '+fil,G2G.GetImportPath(G2frame),4622 style=wx.FD_OPEN ,wildcard=fil+'(*.*)|*.*')4623 if dlg.ShowModal() == wx.ID_OK:4624 fpath,fName = os.path.split(dlg.GetPath())4625 if fpath != G2frame.LastGPXdir:4626 disfile.copy_file(dlg.GetPath(),os.path.join(G2frame.LastGPXdir,fName))4627 if os.path.exists(fName):4628 RMCPdict['files'][fil][0] = fName4629 G2frame.LastImportDir = fpath #set so next file is found in same place4630 dlg.Destroy()4631 else:4632 dlg.Destroy()4633 return4634 wx.CallAfter(UpdateRMC)4635 4636 def OnFileFormat(event):4637 Obj = event.GetEventObject()4638 fil = Indx[Obj.GetId()]4639 RMCPdict['files'][fil][3] = Obj.GetStringSelection()4640 4744 4641 4745 def SetRestart(invalid,value,tc): … … 4922 5026 return swapSizer 4923 5027 4924 def OnFitScale(event):4925 RMCPdict['FitScale'] = not RMCPdict['FitScale']4926 4927 5028 Indx = {} 4928 5029 … … 5031 5132 samSizer.Add(strain,0,WACV) 5032 5133 mainSizer.Add(samSizer,0,WACV) 5033 titleSizer = wx.BoxSizer(wx.HORIZONTAL) 5034 titleSizer.Add(wx.StaticText(G2frame.FRMC,label=' Select data for processing: '),0,WACV) 5035 fitscale = wx.CheckBox(G2frame.FRMC,label=' Fit scale factors?') 5036 fitscale.SetValue(RMCPdict['FitScale']) 5037 fitscale.Bind(wx.EVT_CHECKBOX,OnFitScale) 5038 titleSizer.Add(fitscale,0,WACV) 5039 mainSizer.Add(titleSizer,0,WACV) 5040 fileSizer = wx.FlexGridSizer(4,5,5) 5041 Formats = ['RMC','GUDRUN','STOG'] 5042 Heads = [' ','Format','Weight','Name'] 5043 for head in Heads: 5044 fileSizer.Add(wx.StaticText(G2frame.FRMC,label=head),0,WACV) 5045 for fil in RMCPdict['files']: 5046 filSel = wx.Button(G2frame.FRMC,label='Select') 5047 filSel.Bind(wx.EVT_BUTTON,OnFileSel) 5048 Indx[filSel.GetId()] = fil 5049 fileSizer.Add(filSel,0,WACV) 5050 Rfile = RMCPdict['files'][fil][0] 5051 if Rfile and os.path.exists(Rfile): #incase .gpx file is moved away from G(R), F(Q), etc. files 5052 nform = 3 5053 if 'Xray' in fil: nform = 1 5054 fileFormat = wx.ComboBox(G2frame.FRMC,choices=Formats[:nform],style=wx.CB_DROPDOWN|wx.TE_READONLY) 5055 fileFormat.SetStringSelection(RMCPdict['files'][fil][3]) 5056 Indx[fileFormat.GetId()] = fil 5057 fileFormat.Bind(wx.EVT_COMBOBOX,OnFileFormat) 5058 fileSizer.Add(fileFormat,0,WACV) 5059 fileSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict['files'][fil],1),0,WACV) 5060 else: 5061 RMCPdict['files'][fil][0] = '' 5062 fileSizer.Add((5,5),0) 5063 fileSizer.Add((5,5),0) 5064 fileSizer.Add(wx.StaticText(G2frame.FRMC,label=fil+RMCPdict['files'][fil][0]),0,WACV) 5065 mainSizer.Add(fileSizer,0,WACV) 5134 5135 mainSizer.Add(FileSizer(RMCPdict),0,WACV) 5066 5136 5067 5137 SetPhaseWindow(G2frame.FRMC,mainSizer) … … 5075 5145 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True) 5076 5146 RMCPdict = data['RMC']['fullrmc'] 5077 if RMCPdict['ifBox']: 5078 print(G2pwd.MakepdparserPDB(pName,data,RMCPdict)+ ' written') 5079 else: 5080 print(G2pwd.MakefullrmcPDB(pName,data,RMCPdict)+ ' written') 5081 print('fullrmc file build completed') 5147 fname = G2pwd.MakefullrmcRun(pName,data,RMCPdict) 5148 print('fullrmc file %s build completed'%fname) 5082 5149 else: 5083 5150 G2frame.dataWindow.FRMCDataEdit.Enable(G2G.wxID_RUNRMC,True) … … 5129 5196 doi: https://doi.org/10.1002/jcc.24304''',caption='fullrmc',style=wx.ICON_INFORMATION) 5130 5197 rmcname = pName+'.rmc' 5131 while os.path.isdir(rmcname) and RMCPdict['ReStart'] :5198 while os.path.isdir(rmcname) and RMCPdict['ReStart'][0]: 5132 5199 msg = wx.MessageBox(''' fullrmc will fail to restart if %s exists. You must delete %s by hand now.'''%(rmcname,rmcname), 5133 5200 caption='fullrmc file error',style=wx.ICON_EXCLAMATION|wx.OK|wx.CANCEL) … … 5136 5203 ilog = 0 5137 5204 while True: 5138 logname = ' fullrmc_%d.log'%ilog5205 logname = '%s_%d.log'%(pName,ilog) 5139 5206 if os.path.isfile(logname): 5140 5207 os.remove(logname) … … 5143 5210 ilog += 1 5144 5211 # TBD - remove filedialog & use defined run.py file name here 5212 rname = pName+'-run.py' 5145 5213 dlg = wx.FileDialog(G2frame, 'Choose fullrmc python file to execute', G2G.GetImportPath(G2frame), 5146 5214 wildcard='fullrmc python file (*.py)|*.py',style=wx.FD_CHANGE_DIR) 5147 5215 try: 5148 5216 if dlg.ShowModal() == wx.ID_OK: 5149 import subprocess as sb 5150 batch = open('fullrmc.bat','w') 5151 batch.write('CALL '+sys.exec_prefix+'\\Scripts\\activate\n') 5152 batch.write(sys.exec_prefix+'\\python.exe '+dlg.GetPath()+'\n') 5153 batch.write('pause') 5154 batch.close() 5155 RMCPdict['pid'] = sb.Popen('fullrmc.bat',creationflags=sb.CREATE_NEW_CONSOLE).pid 5217 rname = dlg.GetPath() 5156 5218 else: 5157 5219 return 5158 5220 finally: 5159 5221 dlg.Destroy() 5222 import subprocess as sb 5223 batch = open('fullrmc.bat','w') 5224 batch.write('CALL '+sys.exec_prefix+'\\Scripts\\activate\n') 5225 batch.write(sys.exec_prefix+'\\python.exe '+rname+'\n') 5226 batch.write('pause') 5227 batch.close() 5228 RMCPdict['pid'] = sb.Popen('fullrmc.bat',creationflags=sb.CREATE_NEW_CONSOLE).pid 5160 5229 else: 5161 5230 RMCPdict = data['RMC']['RMCProfile'] … … 5348 5417 ilog = 0 5349 5418 while True: 5350 fname = ' fullrmc_%d.log'%ilog5419 fname = '%s_%d.log'%(pName,ilog) 5351 5420 try: 5352 5421 logfile = open(fname,'r')
Note: See TracChangeset
for help on using the changeset viewer.