Changeset 4469


Ignore:
Timestamp:
Jun 6, 2020 8:28:26 PM (18 months ago)
Author:
toby
Message:

fix for TOF simulation scripting; improve peak selection status line display

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r4468 r4469  
    82068206                        SetSelectedAtoms(i,Add)
    82078207                        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)
    82098210            return
    82108211        elif G2frame.phaseDisplay.GetPageText(getSelection()) == 'Draw Atoms':
     
    82338234                        lbl += ' ' + atom[sympt]
    82348235                    G2frame.G2plotNB.status.SetStatusText(
    8235                             '  Selected atom: {}'.format(lbl),1)
     8236                            '    Selected atom: {}'.format(lbl),1)
    82368237        return
    82378238                                       
  • trunk/GSASIIscriptable.py

    r4421 r4469  
    720720    #gpx.save()  # gpx file is not written without this
    721721
    722 --------------------
     722-----------------------
    723723Pattern Simulation
    724 --------------------
    725 
    726 This shows an example where a structure is read from a CIF, a
     724-----------------------
     725
     726This shows two examples where a structure is read from a CIF, a
    727727pattern is computed using a instrument parameter file to specify the
    728728probe type (neutrons here) and wavelength.
    729 The pattern and reflection list are computed.
     729
     730The first example uses a CW neutron instrument parameter file.
     731The pattern is computed over a 2Ξ range of 5 to 120 degrees
     732with 1000 points.
     733The pattern and reflection list are written into files.
    730734Data files are found in the
    731735`Scripting Tutorial <https://subversion.xray.aps.anl.gov/pyGSAS/Tutorials/PythonScript/data/>`_.
     
    738742    datadir = "/Users/toby/software/G2/Tutorials/PythonScript/data"
    739743    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   
    742745    phase0 = gpx.add_phase(PathWrap("PbSO4-Wyckoff.cif"),
    743              phasename="PbSO4",fmthint='CIF')
     746             phasename="PbSO4",fmthint='CIF') # add a phase to the project
    744747    # add a simulated histogram and link it to the previous phase(s)
    745748    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
    753752    gpx.save()
    754753    # save results
    755754    gpx.histogram(0).Export('PbSO4data','.csv','hist') # data
    756755    gpx.histogram(0).Export('PbSO4refl','.csv','refl') # reflections
     756
     757This example uses bank#2 from a TOF neutron instrument parameter file.
     758The pattern is computed over a TOF range of 14 to 35 milliseconds with
     759the default of 2500 points.
     760This 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>`_
     762tutorial.
     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()
    757779
    758780----------------------
     
    21182140        return self.histogram(newhist)
    21192141       
    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.
    21232146
    21242147        Requires an instrument parameter file.
     
    21302153        :param str histname: A name for the histogram to be created.
    21312154        :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.
    21352159        :param float wavelength: Wavelength for CW instruments, overriding the value
    21362160           in the instrument parameters file if specified.
     
    21392163           small, the noise will mask the computed pattern. The scale
    21402164           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.
    21422167        :param list phases: Phases to link to the new histogram. Use proj.phases() to link to
    21432168           all defined phases.
    21442169        :param int ibank: provides a bank number for the instrument parameter file. The
    21452170           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.
    21462175
    21472176        :returns: A :class:`G2PwdrData` object representing the histogram
     
    21632192        if Tmax < Tmin:
    21642193            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:
    21672212                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'
    21702218        else:           
     2219            if Npoints:
     2220                N = Npoints
     2221            else:
    21712222                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'
    21742228        if N < 3:
    21752229            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))
    21762231        rd.powderdata = [
    21772232            np.array(x), # x-axis values
     
    21962251        elif pwdrdata['Instrument Parameters'][0]['Type'][0].startswith('PNC'):
    21972252            pwdrdata['Sample Parameters']['Scale'][0] = 10000.
     2253        elif pwdrdata['Instrument Parameters'][0]['Type'][0].startswith('PNT'):
     2254            pwdrdata['Sample Parameters']['Scale'][0] = 100000.
    21982255        self.data[histname] = pwdrdata
    21992256        self.update_ids()
     
    41504207        self.data['Instrument Parameters'][0] = G2fil.makeInstDict(newItems,newVals,len(newVals)*[False,])
    41514208
     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]]
    41524268       
    41534269class G2Phase(G2ObjectWrapper):
  • trunk/help/gsasII.html

    r4463 r4469  
    67066706atoms will be reset. If two atoms are overlapped in the
    67076707current view, then the top-most atom will usually be selected.
     6708Only 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>:   
     6711Holding down the shift key while clicking on an atom with the right
     6712mouse button causes the atom to be selected if previously unselected
     6713and unselected if previously selected. Any previously selected
     6714atoms will be continue to be selected so shift-right click can be used
     6715to add atoms to the selection list. If two atoms are overlapped in the
     6716current view, then the top-most atom will usually be selected.
     6717Only atoms in the asymmetric unit can be selected from the plot in this way.
    67086718</LI></BL>
    67096719
     
    73147324<hr size=2 width="100%" align=center>
    73157325
    7316 <!-- hhmts start -->Last modified: Thu Jun  4 15:21:22 CDT 2020 <!-- hhmts end -->
     7326<!-- hhmts start -->Last modified: Sat Jun  6 14:40:36 CDT 2020 <!-- hhmts end -->
    73177327
    73187328</div>
Note: See TracChangeset for help on using the changeset viewer.