- Timestamp:
- Jun 6, 2020 8:28:26 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r4468 r4469 8206 8206 SetSelectedAtoms(i,Add) 8207 8207 G2frame.G2plotNB.status.SetStatusText( 8208 ' Selected peak/atom: {}'.format(peak[0]),1) 8208 ' Selected peak: {:.3f} @ ({:.3f},{:.3f},{:.3f})' 8209 .format(*peak[0:4]),1) 8209 8210 return 8210 8211 elif G2frame.phaseDisplay.GetPageText(getSelection()) == 'Draw Atoms': … … 8233 8234 lbl += ' ' + atom[sympt] 8234 8235 G2frame.G2plotNB.status.SetStatusText( 8235 ' Selected atom: {}'.format(lbl),1)8236 ' Selected atom: {}'.format(lbl),1) 8236 8237 return 8237 8238 -
trunk/GSASIIscriptable.py
r4421 r4469 720 720 #gpx.save() # gpx file is not written without this 721 721 722 -------------------- 722 ----------------------- 723 723 Pattern Simulation 724 -------------------- 725 726 This shows an examplewhere a structure is read from a CIF, a724 ----------------------- 725 726 This shows two examples where a structure is read from a CIF, a 727 727 pattern is computed using a instrument parameter file to specify the 728 728 probe type (neutrons here) and wavelength. 729 The pattern and reflection list are computed. 729 730 The first example uses a CW neutron instrument parameter file. 731 The pattern is computed over a 2Ξ range of 5 to 120 degrees 732 with 1000 points. 733 The pattern and reflection list are written into files. 730 734 Data files are found in the 731 735 `Scripting Tutorial <https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/PythonScript/data/>`_. … … 738 742 datadir = "/Users/toby/software/G2/Tutorials/PythonScript/data" 739 743 PathWrap = lambda fil: os.path.join(datadir,fil) 740 gpx = G2sc.G2Project(filename='PbSO4sim.gpx') # create a project 741 # add a phase to the project 744 gpx = G2sc.G2Project(filename='PbSO4sim.gpx') # create a project 742 745 phase0 = gpx.add_phase(PathWrap("PbSO4-Wyckoff.cif"), 743 phasename="PbSO4",fmthint='CIF') 746 phasename="PbSO4",fmthint='CIF') # add a phase to the project 744 747 # add a simulated histogram and link it to the previous phase(s) 745 748 hist1 = gpx.add_simulated_powder_histogram("PbSO4 simulation", 746 PathWrap("inst_d1a.prm"),5.,120.,0.01, 747 phases=gpx.phases()) 748 # Set the scale factor to adjust the y scale 749 hist1.SampleParameters['Scale'][0] = 1000000. 750 # parameter optimization and calculate pattern 751 gpx.data['Controls']['data']['max cyc'] = 0 # refinement not needed 752 gpx.do_refinements([{}]) 749 PathWrap("inst_d1a.prm"),5.,120.,Npoints=1000, 750 phases=gpx.phases(),scale=500000.) 751 gpx.do_refinements([{}]) # calculate pattern 753 752 gpx.save() 754 753 # save results 755 754 gpx.histogram(0).Export('PbSO4data','.csv','hist') # data 756 755 gpx.histogram(0).Export('PbSO4refl','.csv','refl') # reflections 756 757 This example uses bank#2 from a TOF neutron instrument parameter file. 758 The pattern is computed over a TOF range of 14 to 35 milliseconds with 759 the default of 2500 points. 760 This uses the same CIF as in the example before, but the instrument is found in the 761 `TOF-CW Joint Refinement Tutorial <https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/TOF-CW Joint Refinement/data>`_ 762 tutorial. 763 764 .. code-block:: python 765 766 import os,sys 767 sys.path.insert(0,'/Users/toby/software/G2/GSASII') 768 import GSASIIscriptable as G2sc 769 cifdir = "/Users/toby/software/G2/Tutorials/PythonScript/data" 770 datadir = "/Users/toby/software/G2/Tutorials/TOF-CW Joint Refinement/data" 771 gpx = G2sc.G2Project(filename='/tmp/PbSO4simT.gpx') # create a project 772 phase0 = gpx.add_phase(os.path.join(cifdir,"PbSO4-Wyckoff.cif"), 773 phasename="PbSO4",fmthint='CIF') # add a phase to the project 774 hist1 = gpx.add_simulated_powder_histogram("PbSO4 simulation", 775 os.path.join(datadir,"POWGEN_1066.instprm"),14.,35., 776 phases=gpx.phases(),ibank=2) 777 gpx.do_refinements([{}]) 778 gpx.save() 757 779 758 780 ---------------------- … … 2118 2140 return self.histogram(newhist) 2119 2141 2120 def add_simulated_powder_histogram(self, histname, iparams, Tmin, Tmax, Tstep, 2121 wavelength=None, scale=None, phases=[], ibank=None): 2122 """Loads a powder data histogram into the project. 2142 def add_simulated_powder_histogram(self, histname, iparams, Tmin, Tmax, Tstep=None, 2143 wavelength=None, scale=None, phases=[], ibank=None, 2144 Npoints=None): 2145 """Create a simulated powder data histogram for the project. 2123 2146 2124 2147 Requires an instrument parameter file. … … 2130 2153 :param str histname: A name for the histogram to be created. 2131 2154 :param str iparams: The instrument parameters file, a filename. 2132 :param float Tmin: Minimum 2theta or TOF (microsec) for dataset to be simulated 2133 :param float Tmax: Maximum 2theta or TOF (usec) for dataset to be simulated 2134 :param float Tstep: Step size in 2theta or TOF (usec) for dataset to be simulated 2155 :param float Tmin: Minimum 2theta or TOF (millisec) for dataset to be simulated 2156 :param float Tmax: Maximum 2theta or TOF (millisec) for dataset to be simulated 2157 :param float Tstep: Step size in 2theta or deltaT/T (TOF) for simulated dataset. 2158 Default is to compute this from Npoints. 2135 2159 :param float wavelength: Wavelength for CW instruments, overriding the value 2136 2160 in the instrument parameters file if specified. … … 2139 2163 small, the noise will mask the computed pattern. The scale 2140 2164 needs to be a large number for CW neutrons. 2141 The default, None, provides a scale of 1 for x-rays and TOF; 10,000 for CW neutrons. 2165 The default, None, provides a scale of 1 for x-rays and TOF; 10,000 for CW neutrons 2166 and 100,000 for TOF. 2142 2167 :param list phases: Phases to link to the new histogram. Use proj.phases() to link to 2143 2168 all defined phases. 2144 2169 :param int ibank: provides a bank number for the instrument parameter file. The 2145 2170 default is None, corresponding to load the first bank. 2171 :param int Îpoints: the number of data points to be used for computing the 2172 diffraction pattern. Defaults as None, which sets this to 2500. Do not specify 2173 both Npoints and Tstep. Due to roundoff the actual nuber of points used may differ 2174 by +-1 from Npoints. Must be below 25,000. 2146 2175 2147 2176 :returns: A :class:`G2PwdrData` object representing the histogram … … 2163 2192 if Tmax < Tmin: 2164 2193 Tmin,Tmax = Tmax,Tmin 2165 Tstep = abs(Tstep) 2166 if 'TOF' in rd.idstring: 2194 if Tstep is not None and Npoints is not None: 2195 raise G2ScriptException("Error: Tstep and Npoints both specified") 2196 elif Tstep is not None: 2197 Tstep = abs(Tstep) 2198 elif Npoints is None: 2199 Npoints = 2500 2200 Iparm1, Iparm2 = load_iprms(iparams, rd, bank=ibank) 2201 #G2fil.G2Print('Instrument parameters read:',reader.instmsg) 2202 if 'T' in Iparm1['Type'][0]: 2203 # patch -- anticipate TOF values in microsec from buggy version 2204 if Tmax > 200.: 2205 print('Error: Tmax is too large. Note that input for TOF Tmin & Tmax has changed.') 2206 print(' Tmin & Tmax are now in milliseconds not microsec. Step is now deltaT/T.') 2207 raise G2ScriptException("Error: Tmax is too large") 2208 if Npoints: 2209 N = Npoints 2210 Tstep = (np.log(Tmax)-np.log(Tmin))/N 2211 else: 2167 2212 N = (np.log(Tmax)-np.log(Tmin))/Tstep 2168 x = np.exp((np.arange(0,N))*Tstep+np.log(Tmin*1000.)) 2169 N = len(x) 2213 if N > 25000: 2214 raise G2ScriptException("Error: Tstep is too small. Would need "+str(N)+" points.") 2215 x = np.exp((np.arange(0,N))*Tstep+np.log(Tmin*1000.)) 2216 N = len(x) 2217 unit = 'millisec' 2170 2218 else: 2219 if Npoints: 2220 N = Npoints 2221 else: 2171 2222 N = int((Tmax-Tmin)/Tstep)+1 2172 x = np.linspace(Tmin,Tmax,N,True) 2173 N = len(x) 2223 if N > 25000: 2224 raise G2ScriptException("Error: Tstep is too small. Would need "+str(N)+" points.") 2225 x = np.linspace(Tmin,Tmax,N,True) 2226 N = len(x) 2227 unit = 'degrees 2theta' 2174 2228 if N < 3: 2175 2229 raise G2ScriptException("Error: Range is too small or step is too large, <3 points") 2230 G2fil.G2Print('Simulating {} points from {} to {} {}'.format(N,Tmin,Tmax,unit)) 2176 2231 rd.powderdata = [ 2177 2232 np.array(x), # x-axis values … … 2196 2251 elif pwdrdata['Instrument Parameters'][0]['Type'][0].startswith('PNC'): 2197 2252 pwdrdata['Sample Parameters']['Scale'][0] = 10000. 2253 elif pwdrdata['Instrument Parameters'][0]['Type'][0].startswith('PNT'): 2254 pwdrdata['Sample Parameters']['Scale'][0] = 100000. 2198 2255 self.data[histname] = pwdrdata 2199 2256 self.update_ids() … … 4150 4207 self.data['Instrument Parameters'][0] = G2fil.makeInstDict(newItems,newVals,len(newVals)*[False,]) 4151 4208 4209 def EditSimulated(self,Tmin, Tmax, Tstep=None, Npoints=None): 4210 '''Change the parameters for an existing simulated powder histogram. 4211 This will reset the previously computed "observed" pattern. 4212 4213 :param float Tmin: Minimum 2theta or TOF (microsec) for dataset to be simulated 4214 :param float Tmax: Maximum 2theta or TOF (usec) for dataset to be simulated 4215 :param float Tstep: Step size in 2theta or TOF (usec) for dataset to be simulated 4216 Default is to compute this from Npoints. 4217 :param int Îpoints: the number of data points to be used for computing the 4218 diffraction pattern. Defaults as None, which sets this to 2500. Do not specify 4219 both Npoints and Tstep. Due to roundoff the actual nuber of points used may differ 4220 by +-1 from Npoints. Must be below 25,000. 4221 ''' 4222 if not self.data['data'][0]['Dummy']: 4223 raise G2ScriptException("Error: histogram for G2PwdrData.EditSimulated is not simulated") 4224 if Tmax < Tmin: 4225 Tmin,Tmax = Tmax,Tmin 4226 if Tstep is not None and Npoints is not None: 4227 raise G2ScriptException("Error: Tstep and Npoints both specified") 4228 elif Tstep is not None: 4229 Tstep = abs(Tstep) 4230 elif Npoints is None: 4231 Npoints = 2500 4232 4233 if 'T' in self.data['Instrument Parameters'][0]['Type'][0]: 4234 if Tmax > 200.: 4235 raise G2ScriptException("Error: Tmax is too large") 4236 if Npoints: 4237 N = Npoints 4238 Tstep = (np.log(Tmax)-np.log(Tmin))/N 4239 else: 4240 N = (np.log(Tmax)-np.log(Tmin))/Tstep 4241 if N > 25000: 4242 raise G2ScriptException("Error: Tstep is too small. Would need "+str(N)+" points.") 4243 x = np.exp((np.arange(0,N))*Tstep+np.log(Tmin*1000.)) 4244 N = len(x) 4245 unit = 'millisec' 4246 else: 4247 if Npoints: 4248 N = Npoints 4249 else: 4250 N = int((Tmax-Tmin)/Tstep)+1 4251 if N > 25000: 4252 raise G2ScriptException("Error: Tstep is too small. Would need "+str(N)+" points.") 4253 x = np.linspace(Tmin,Tmax,N,True) 4254 N = len(x) 4255 unit = 'degrees 2theta' 4256 if N < 3: 4257 raise G2ScriptException("Error: Range is too small or step is too large, <3 points") 4258 G2fil.G2Print('Simulating {} points from {} to {} {}'.format(N,Tmin,Tmax,unit)) 4259 self.data['data'][1] = [ 4260 np.array(x), # x-axis values 4261 np.zeros_like(x), # powder pattern intensities 4262 np.ones_like(x), # 1/sig(intensity)^2 values (weights) 4263 np.zeros_like(x), # calc. intensities (zero) 4264 np.zeros_like(x), # calc. background (zero) 4265 np.zeros_like(x), # obs-calc profiles 4266 ] 4267 self.data['Limits'] = [(1000*Tmin, 1000*Tmax), [1000*Tmin, 1000*Tmax]] 4152 4268 4153 4269 class G2Phase(G2ObjectWrapper): -
trunk/help/gsasII.html
r4463 r4469 6706 6706 atoms will be reset. If two atoms are overlapped in the 6707 6707 current view, then the top-most atom will usually be selected. 6708 Only atoms in the asymmetric unit can be selected from the plot in this way. 6709 </LI><LI style='margin-left:1.4in; text-indent:-.2in'> 6710 <B>Shift+Right click</B>: 6711 Holding down the shift key while clicking on an atom with the right 6712 mouse button causes the atom to be selected if previously unselected 6713 and unselected if previously selected. Any previously selected 6714 atoms will be continue to be selected so shift-right click can be used 6715 to add atoms to the selection list. If two atoms are overlapped in the 6716 current view, then the top-most atom will usually be selected. 6717 Only atoms in the asymmetric unit can be selected from the plot in this way. 6708 6718 </LI></BL> 6709 6719 … … 7314 7324 <hr size=2 width="100%" align=center> 7315 7325 7316 <!-- hhmts start -->Last modified: Thu Jun 4 15:21:22CDT 2020 <!-- hhmts end -->7326 <!-- hhmts start -->Last modified: Sat Jun 6 14:40:36 CDT 2020 <!-- hhmts end --> 7317 7327 7318 7328 </div>
Note: See TracChangeset
for help on using the changeset viewer.