Changeset 5075
- Timestamp:
- Nov 12, 2021 2:38:12 PM (7 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIphsGUI.py
r5072 r5075 4918 4918 RMCPdict['refinement'] = reftype.GetStringSelection() 4919 4919 wx.CallAfter(UpdateRMC) 4920 4921 def OnDataSel(event): 4922 RMCPdict['SeqDataType'] = dataType.GetStringSelection() 4920 4923 4921 4924 Indx = {} 4922 4925 topSizer = wx.BoxSizer(wx.HORIZONTAL) 4926 topSizer.Add(wx.StaticText(G2frame.FRMC,label=' Select data for processing: ')) 4923 4927 if G2frame.RMCchoice == 'PDFfit': 4924 4928 reftype = wx.RadioBox(G2frame.FRMC,label='PDFfit refinement type:',choices=['normal','sequential']) 4925 4929 reftype.SetStringSelection(RMCPdict.get('refinement','normal')) 4926 4930 reftype.Bind(wx.EVT_RADIOBOX,OnRefSel) 4927 topSizer.Add(reftype,0,WACV) 4928 topSizer.Add(wx.StaticText(G2frame.FRMC,label=' Select data for processing: '),0,WACV) 4931 topSizer.Add(reftype) 4932 if 'seq' in RMCPdict.get('refinement','normal'): 4933 dataType = wx.RadioBox(G2frame.FRMC,label='Seq data type:',choices=['X','N']) 4934 dataType.SetStringSelection(RMCPdict.get('SeqDataType','X')) 4935 dataType.Bind(wx.EVT_RADIOBOX,OnDataSel) 4936 topSizer.Add(dataType) 4929 4937 mainSizer.Add(topSizer) 4930 4938 if G2frame.RMCchoice == 'fullrmc': … … 5086 5094 RMCPdict['seqfiles'][r][1]['Fitrange'][c] = float(seqGrid.GetCellValue(r,c)) 5087 5095 5096 G2frame.GetStatusBar().SetStatusText('NB: All PDFs used in sequential PDFfit must be the same type ("X" or "N") - there is no check',1) 5088 5097 if 'seqfiles' not in RMCPdict: 5089 5098 RMCPdict['seqfiles'] = [] 5090 5099 topSizer = wx.BoxSizer(wx.HORIZONTAL) 5091 topSizer.Add(wx.StaticText(G2frame.FRMC,label=' Sequential filelist for PDFfit: '),0,WACV)5100 topSizer.Add(wx.StaticText(G2frame.FRMC,label=' Sequential data list for PDFfit: '),0,WACV) 5092 5101 addPDF = wx.Button(G2frame.FRMC,label='Add PDF G(r) data sets') 5093 5102 addPDF.Bind(wx.EVT_BUTTON,OnAddPDF) … … 6017 6026 if c > 0: 6018 6027 strval = atmGrid.GetCellValue(r,c).strip() 6019 if strval == '' or '@' in strval: 6020 RMCPdict['AtomConstr'][r][c+1] = strval 6021 else: 6022 print('ERROR - atom constraints must be blank or contain "@"') 6028 try: 6029 if strval == '' or ('@' in strval and int(strval.split('@')[-1]) >= 10): 6030 RMCPdict['AtomConstr'][r][c+1] = strval 6031 else: 6032 raise ValueError 6033 except ValueError: 6034 atmGrid.SetCellValue(r,c,RMCPdict['AtomConstr'][r][c+1]) 6035 wx.MessageBox('ERROR - atom constraints must be blank or have "@n" at end with n >= 10', 6036 style=wx.ICON_ERROR) 6023 6037 6024 6038 atmSizer = wx.BoxSizer(wx.VERTICAL) 6025 atmSizer.Add(wx.StaticText(G2frame.FRMC,label=' Atom Constraints; enter as e.g. "@n" or "0.5-@n"; n>=10 '))6039 atmSizer.Add(wx.StaticText(G2frame.FRMC,label=' Atom Constraints; enter as e.g. "@n" or "0.5-@n"; n>=10 && "@n" should be at end')) 6026 6040 6027 6041 table = [item[1:] for item in RMCPdict['AtomConstr']] … … 6036 6050 atmSizer.Add(atmGrid) 6037 6051 return atmSizer 6038 6052 6053 def AtomVarSizer(): 6054 atomVarSizer = wx.FlexGridSizer(0,8,5,5) 6055 for item in RMCPdict['AtomVar']: 6056 atomVarSizer.Add(wx.StaticText(G2frame.FRMC,label=item),0,WACV) 6057 atomVarSizer.Add(G2G.ValidatedTxtCtrl(G2frame.FRMC,RMCPdict['AtomVar'], 6058 item,xmin=-1.,xmax=1.,size=(70,25)),0,WACV) 6059 return atomVarSizer 6039 6060 6040 6061 subSizer = wx.BoxSizer(wx.HORIZONTAL) … … 6058 6079 'delta1':[0.,False],'delta2':[0.,False],'spdiameter':[0.,False],'refinement':'normal', 6059 6080 'sratio':[1.,False],'rcut':0.0,'stepcut':0.0,'shape':'sphere','SGData':SGData,'cellref':False, 6060 'AtomConstr':[], 6081 'AtomConstr':[],'AtomVar':{},'SeqDataType':'X', 6061 6082 'Xdata':{'dscale':[1.0,False],'Datarange':[0.,30.],'Fitrange':[0.,30.],'qdamp':[0.03,False],'qbroad':[0,False]}, 6062 6083 'Ndata':{'dscale':[1.0,False],'Datarange':[0.,30.],'Fitrange':[0.,30.],'qdamp':[0.03,False],'qbroad':[0,False]},} … … 6067 6088 RMCPdict['SGData'] = G2spc.SpcGroup('P 1')[1] 6068 6089 if 'refinement' not in RMCPdict: 6069 RMCPdict['refinement'] = ' combined'6090 RMCPdict['refinement'] = 'normal' 6070 6091 if 'cellref' not in RMCPdict: 6071 6092 RMCPdict['cellref'] = False … … 6074 6095 if 'metadata' not in RMCPdict: 6075 6096 RMCPdict['metadata'] = {'title':'none','date':str(time.ctime()),'temperature':'300K','doping':0} 6097 if 'SeqDataType' not in RMCPdict: 6098 RMCPdict['SeqDataType'] = 'X' 6099 if 'AtomVar' not in RMCPdict: 6100 RMCPdict['AtomVar'] = {} 6076 6101 #end patch 6077 6102 Atoms = data['Atoms'] … … 6104 6129 mainSizer.Add(wx.StaticText(G2frame.FRMC,label='PDFfit atom parameters:'),0,WACV) 6105 6130 mainSizer.Add(AtomSizer()) 6131 6132 G2G.HorizontalLine(mainSizer,G2frame.FRMC) 6133 mainSizer.Add(wx.StaticText(G2frame.FRMC,label='PDFfit starting atom variables:'),0,WACV) 6134 G2pwd.GetPDFfitAtomVar(data,RMCPdict) 6135 mainSizer.Add(AtomVarSizer()) 6106 6136 6107 6137 G2G.HorizontalLine(mainSizer,G2frame.FRMC) … … 6223 6253 RMCPdict = data['RMC']['PDFfit'] 6224 6254 G2pwd.MakePDFfitAtomsFile(data,RMCPdict) 6225 G2pwd.MakePDFfitRunFile(data,RMCPdict) 6255 fname = G2pwd.MakePDFfitRunFile(data,RMCPdict) 6256 print(fname+ ' written') 6257 print('PDFfit file build completed') 6226 6258 6227 6259 … … 6368 6400 elif G2frame.RMCchoice == 'PDFfit': 6369 6401 PDFfit_exec = G2pwd.findPDFfit() 6370 if PDFfit_exec is None:6371 G2G.G2MessageBox(G2frame,'PDFfit2 Python not found. How did we get here?')6372 return6402 # if PDFfit_exec is None: 6403 # G2G.G2MessageBox(G2frame,'PDFfit2 Python not found. How did we get here?') 6404 # return 6373 6405 pName = generalData['Name'].replace(' ','_') 6374 6406 rname = pName+'-PDFfit.py' 6375 if not os.path.exists(rname):6376 G2G.G2MessageBox(G2frame,6377 'The PDFfit script has not been created. Running setup.',6378 'Not setup')6379 OnSetupRMC(event)6407 # if not os.path.exists(rname): 6408 # G2G.G2MessageBox(G2frame, 6409 # 'The PDFfit script has not been created. Running setup.', 6410 # 'Not setup') 6411 # OnSetupRMC(event) 6380 6412 wx.MessageBox(''' For use of PDFfit2, please cite: 6381 6413 PDFfit2 and PDFgui: computer progerama for studying nanostructures in crystals, … … 6403 6435 subp.Popen(['/bin/bash','pdffit2.sh']) 6404 6436 #update choice? here? 6405 wx.MessageBox('PDFfit finished',caption='Updating results',style=wx.ICON_EXCLAMATION) 6406 RMCPdict = data['RMC']['PDFfit'] 6407 G2pwd.UpdatePDFfit(data,RMCPdict) 6437 dlg = wx.MessageDialog(G2frame,'Check PDFfit console for results; do you want to update?', 6438 'PDFfit run finished',wx.YES|wx.NO) 6439 try: 6440 dlg.CenterOnParent() 6441 result = dlg.ShowModal() 6442 finally: 6443 dlg.Destroy() 6444 if result == wx.ID_YES: 6445 RMCPdict = data['RMC']['PDFfit'] 6446 Error = G2pwd.UpdatePDFfit(data,RMCPdict) 6447 if Error: 6448 wx.MessageBox('PDFfit failed',caption='%s not found'%Error[0],style=wx.ICON_EXCLAMATION) 6408 6449 wx.CallAfter(UpdateRMC) 6409 6410 6411 6450 6412 6451 def OnStopRMC(event): -
trunk/GSASIIpwd.py
r5066 r5075 2960 2960 return None 2961 2961 2962 def GetPDFfitAtomVar(Phase,RMCPdict): 2963 ''' Find dict of independent "@n" variables for PDFfit in atom constraints 2964 ''' 2965 General = Phase['General'] 2966 Atoms = Phase['Atoms'] 2967 cx,ct,cs,cia = General['AtomPtrs'] 2968 AtomVar = RMCPdict['AtomVar'] 2969 for iat,atom in enumerate(RMCPdict['AtomConstr']): 2970 for it,item in enumerate(atom): 2971 if it > 1 and item: 2972 itnum = item.split('@')[1] 2973 if it < 6: 2974 if '@%s'%itnum not in AtomVar: 2975 AtomVar['@%s'%itnum] = 0.0 #put ISODISTORT mode displ here? 2976 else: 2977 for i in range(3): 2978 if '@%s'%itnum not in AtomVar: 2979 AtomVar['@%s'%itnum] = Atoms[iat][cia+i+2] 2980 2962 2981 def MakePDFfitAtomsFile(Phase,RMCPdict): 2963 2982 '''Make the PDFfit atoms file … … 2965 2984 General = Phase['General'] 2966 2985 fName = General['Name']+'-PDFfit.stru' 2967 fatm = open(fName.replace(' ','_'),'w') 2986 fName = fName.replace(' ','_') 2987 fatm = open(fName,'w') 2968 2988 fatm.write('title structure of '+General['Name']+'\n') 2969 2989 fatm.write('format pdffit\n') … … 3023 3043 3024 3044 General = Phase['General'] 3045 Cell = General['Cell'][1:7] 3025 3046 rundata = ''' 3026 3047 #!/usr/bin/env python … … 3032 3053 Np = 0 3033 3054 for file in RMCPdict['files']: 3055 if 'Select' in RMCPdict['files'][file][0]: 3056 continue 3034 3057 if 'Neutron' in file: 3035 3058 Nd += 1 … … 3038 3061 Nd += 1 3039 3062 dType = 'Xdata' 3040 rundata += "pf.read_data(%s, '%s', 30.0, %.4f)\n"%(dType[0],RMCPdict['files'][file][0],RMCPdict[dType]['qdamp'][0]) 3041 rundata += 'pf.pdfrange(%d, %6.2f, %6.2f\n'%(Nd,RMCPdict[dType]['Fitrange'][0],RMCPdict[dType]['Fitrange'][1]) 3063 rundata += "pf.read_data('%s', '%s', 30.0, %.4f)\n"%(RMCPdict['files'][file][0],dType[0],RMCPdict[dType]['qdamp'][0]) 3042 3064 rundata += 'pf.setdata(%d)\n'%Nd 3065 rundata += 'pf.pdfrange(%d, %6.2f, %6.2f)\n'%(Nd,RMCPdict[dType]['Fitrange'][0],RMCPdict[dType]['Fitrange'][1]) 3043 3066 for item in ['dscale','qdamp','qbroad']: 3044 rundata += "pf.setvar('%s', %.2f)\n"%(item,RMCPdict[dType][item][0])3045 3067 if RMCPdict[dType][item][1]: 3046 3068 Np += 1 3047 rundata += 'pf.constrain("%s","@%d")\n'%(item,Np) 3048 rundata += "pf.read_struct(%s)\n"%(General['Name']+'-PDFfit.stru') 3069 rundata += 'pf.constrain(pf.%s(),"@%d")\n'%(item,Np) 3070 rundata += "pf.setpar(%d, %.2f)\n"%(Np,RMCPdict[dType][item][0]) 3071 fName = General['Name']+'-PDFfit.stru' 3072 fName = fName.replace(' ','_') 3073 rundata += "pf.read_struct('%s')\n"%(fName) 3049 3074 for item in ['delta1','delta2','sratio']: 3050 3075 if RMCPdict[item][1]: 3051 3076 Np += 1 3052 3077 rundata += 'pf.constrain(pf.%s,"@%d")\n'%(item,Np) 3078 rundata += 'pf.setpar(%d,%.3f)\n'%(Np,RMCPdict[item][0]) 3053 3079 if 'sphere' in RMCPdict['shape'][0] and RMCPdict['spdiameter'][1]: 3054 3080 Np += 1 3055 3081 rundata += 'pf.constrain(pf.spdiameter,"@%d")\n'%Np 3056 3082 rundata += 'pf.setpar(%d,%.3f)\n'%(Np,RMCPdict['spdiameter'][0]) 3083 3057 3084 if RMCPdict['cellref']: 3058 3085 cellconst = GetCellConstr(RMCPdict['SGData']) 3086 used = [] 3059 3087 for ic in range(6): 3060 3088 if cellconst[ic]: 3061 3089 rundata += 'pf.constrain(pf.lat(%d), "@%d")\n'%(ic+1,Np+cellconst[ic]) 3062 #Atom constraints here ------------------------------------------------------- 3063 3064 3065 3090 if cellconst[ic] not in used: 3091 rundata += 'pf.setpar(%d,%.5f)\n'%(Np+cellconst[ic],Cell[ic]) 3092 used.append(cellconst[ic]) 3093 #Atom constraints here ------------------------------------------------------- 3094 AtomVar = RMCPdict['AtomVar'] 3095 used = [] 3096 for iat,atom in enumerate(RMCPdict['AtomConstr']): 3097 for it,item in enumerate(atom): 3098 names = ['pf.x(%d)'%(iat+1),'pf.y(%d)'%(iat+1),'pf.z(%d)'%(iat+1),'pf.occ(%d)'%(iat+1)] 3099 if it > 1 and item: 3100 itnum = item.split('@')[1] 3101 if it < 6: 3102 rundata += 'pf.constrain(%s,"%s")\n'%(names[it-2],item) 3103 if itnum not in used: 3104 rundata += 'pf.setpar(%s,%.6f)\n'%(itnum,AtomVar['@%s'%itnum]) 3105 used.append(itnum) 3106 else: 3107 uijs = ['pf.u11(%d)'%(iat+1),'pf.u22(%d)'%(iat+1),'pf.u33(%d)'%(iat+1)] 3108 for i in range(3): 3109 rundata += 'pf.constrain(%s,"%s")\n'%(uijs[i],item) 3110 if itnum not in used: 3111 rundata += 'pf.setpar(%s,%.5f)\n'%(itnum,AtomVar['@%s'%itnum]) 3112 used.append(itnum) 3113 3066 3114 # Refine & Save results --------------------------------------------------------------- 3067 3115 rundata += 'pf.refine()\n' … … 3069 3117 Nd = 0 3070 3118 for file in RMCPdict['files']: 3119 if 'Select' in RMCPdict['files'][file][0]: 3120 continue 3071 3121 Nd += 1 3072 rundata += 'pf.save_pdf(%d, %s)\n'%(Nd,fName+file[0]+'.fgr')3122 rundata += 'pf.save_pdf(%d, "%s")\n'%(Nd,fName+file[0]+'.fgr') 3073 3123 3074 rundata += 'pf.save_struct(1, %s)\n'%(fName+'.rstr') 3075 rundata += 'pf.save_res(%s)\n'%(fName+'.res') 3076 3077 3078 print(rundata) 3079 3080 3124 rundata += 'pf.save_struct(1, "%s")\n'%(fName+'.rstr') 3125 rundata += 'pf.save_res("%s")\n'%(fName+'.res') 3081 3126 3082 # rfile = open(fName+.py','w')3083 #rfile.writelines(rundata)3084 #rfile.close()3085 3086 3127 rfile = open(fName+'.py','w') 3128 rfile.writelines(rundata) 3129 rfile.close() 3130 3131 return fName+'.py' 3087 3132 3088 3133 def UpdatePDFfit(Phase,RMCPdict): 3134 ''' Updates various PDFfit parameters held in GSAS-II 3135 ''' 3089 3136 3090 3137 General = Phase['General'] 3091 3138 fName = General['Name']+'-PDFfit.rstr' 3092 rstr = open(fName.replace(' ','_'),'r') 3139 try: 3140 rstr = open(fName.replace(' ','_'),'r') 3141 except FileNotFoundError: 3142 return [fName,'Not found - PDFfit failed'] 3093 3143 lines = rstr.readlines() 3094 3144 rstr.close() … … 3118 3168 atom[ci+5:ci+8] = [float(Uijstr[0]),float(Uijstr[1]),float(Uijstr[2])] 3119 3169 atmBeg += 6 3170 3171 fName = General['Name']+'-PDFfit.res' 3172 try: 3173 res = open(fName.replace(' ','_'),'r') 3174 except FileNotFoundError: 3175 return [fName,'Not found - PDFfit failed'] 3176 lines = res.readlines() 3177 res.close() 3178 Ibeg = False 3179 resline = '' 3180 for iline,line in enumerate(lines): 3181 if 'Refinement parameters' in line: 3182 Ibeg = True 3183 continue 3184 if Ibeg: 3185 if '---------' in line: 3186 break 3187 resline += line[:-1] 3188 results = resline.replace('(','').split(')')[:-1] 3189 results = ['@'+result.lstrip() for result in results] 3190 results = [item.split()[:2] for item in results] 3191 results = dict([[item[0][:-1],float(item[1])] for item in results if item[0][:-1] in RMCPdict['AtomVar']]) 3192 RMCPdict['AtomVar'].update(results) 3193 return None 3120 3194 3121 3195 def MakefullrmcRun(pName,Phase,RMCPdict):
Note: See TracChangeset
for help on using the changeset viewer.