Ignore:
Timestamp:
Apr 23, 2014 5:11:13 PM (8 years ago)
Author:
toby
Message:

Start on parametric fitting; Time for new manual; fix minor formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sphinxdocs/build/html/_modules/GSASIIobj.html

    r1183 r1298  
    5454<span class="c">#GSASIIobj - data objects for GSAS-II</span>
    5555<span class="c">########### SVN repository information ###################</span>
    56 <span class="c"># $Date: 2014-01-02 14:18:25 -0600 (Thu, 02 Jan 2014) $</span>
     56<span class="c"># $Date: 2014-04-21 15:38:39 -0500 (Mon, 21 Apr 2014) $</span>
    5757<span class="c"># $Author: toby $</span>
    58 <span class="c"># $Revision: 1181 $</span>
     58<span class="c"># $Revision: 1294 $</span>
    5959<span class="c"># $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/GSASIIobj.py $</span>
    60 <span class="c"># $Id: GSASIIobj.py 1181 2014-01-02 20:18:25Z toby $</span>
     60<span class="c"># $Id: GSASIIobj.py 1294 2014-04-21 20:38:39Z toby $</span>
    6161<span class="c">########### SVN repository information ###################</span>
    6262
     
    611611<span class="sd">                                          containing in order:</span>
    612612
    613 <span class="sd">                                           1. the x-postions (two-theta in degrees),</span>
    614 <span class="sd">                                           2. the intensity values (Yobs),</span>
    615 <span class="sd">                                           3. the weights for each Yobs value</span>
    616 <span class="sd">                                           4. the computed intensity values (Ycalc)</span>
    617 <span class="sd">                                           5. the background values</span>
    618 <span class="sd">                                           6. Yobs-Ycalc</span>
     613<span class="sd">                                           0. the x-postions (two-theta in degrees),</span>
     614<span class="sd">                                           1. the intensity values (Yobs),</span>
     615<span class="sd">                                           2. the weights for each Yobs value</span>
     616<span class="sd">                                           3. the computed intensity values (Ycalc)</span>
     617<span class="sd">                                           4. the background values</span>
     618<span class="sd">                                           5. Yobs-Ycalc</span>
    619619<span class="sd">======================  ===============  ====================================================</span>
    620620
     
    846846<span class="sd">Stress/Strain               Sample phi          (float) Sample rotation about vertical axis.</span>
    847847<span class="sd">\                           Sample z            (float) Sample translation from the calibration sample position (for Sample phi = 0)</span>
    848 <span class="sd">\                           strain              (list: 3x3 array of float) The strain tensor coefficients [[&#39; e11&#39;,&#39;e12&#39;,&#39;e13&#39;],[&#39; e21&#39;,&#39;e22&#39;,&#39;e23&#39;],[&#39; e31&#39;,&#39;e32&#39;,&#39;e33&#39;]].</span>
    849848<span class="sd">                                                These will be restricted by space group symmetry; result of strain fit refinement.</span>
    850849<span class="sd">\                           Type                (str) &#39;True&#39; or &#39;Conventional&#39;: The strain model used for the calculation.</span>
    851 <span class="sd">\                           d-zero              (list:dict) Each item is for a diffraction ring on the image; all items are from the same phase and are used to determine the strain tensor.</span>
     850<span class="sd">\                           d-zero              (list:dict) Each item is for a diffraction ring on the image; all items are from the same phase </span>
     851<span class="sd">                                                and are used to determine the strain tensor.</span>
    852852<span class="sd">                                                The dictionary items are:</span>
    853853<span class="sd">                                                &#39;Dset&#39;: (float) True d-spacing for the diffraction ring; entered by the user.</span>
    854 <span class="sd">                                                &#39;Dcalc&#39;: (float) d-spacing...</span>
     854<span class="sd">                                                &#39;Dcalc&#39;: (float) Average calculated d-spacing determined from strain coeff.</span>
     855<span class="sd">                                                &#39;Emat&#39;: (list: float) The strain tensor elements e11, e12 &amp; e22 (e21=e12, rest are 0)</span>
     856<span class="sd">                                                &#39;Esig&#39;: (list: float) Esds for Emat from fitting.</span>
    855857<span class="sd">                                                &#39;pixLimit&#39;: (int) Search range to find highest point on ring for each data point</span>
    856858<span class="sd">                                                &#39;cutoff&#39;: (float) I/Ib cutoff for searching.</span>
    857 <span class="sd">                                                &#39;ImxyObs&#39;: (list:lists) [[X],[Y]] observed points to be used for strain calculations.</span>
    858 <span class="sd">                                                &#39;ImxyCalc&#39;:(list:lists) [[X],[Y]] calculated points based on refined strain.                                           </span>
     859<span class="sd">                                                &#39;ImxyObs&#39;: (list: lists) [[X],[Y]] observed points to be used for strain calculations.</span>
     860<span class="sd">                                                &#39;ImtaObs&#39;: (list: lists) [[d],[azm]] transformed via detector calibration from ImxyObs.</span>
     861<span class="sd">                                                &#39;ImtaCalc&#39;: (list: lists [[d],[azm]] calculated d-spacing &amp; azimuth from fit.</span>
    859862<span class="sd">                                                </span>
    860863<span class="sd">======================  ======================  ====================================================</span>
     
    885888
    886889<span class="sd">&#39;&#39;&#39;</span>
     890<span class="kn">import</span> <span class="nn">re</span>
     891<span class="kn">import</span> <span class="nn">imp</span>
    887892<span class="kn">import</span> <span class="nn">random</span> <span class="kn">as</span> <span class="nn">ran</span>
    888893<span class="kn">import</span> <span class="nn">sys</span>
    889894<span class="kn">import</span> <span class="nn">GSASIIpath</span>
    890895<span class="kn">import</span> <span class="nn">GSASIImath</span> <span class="kn">as</span> <span class="nn">G2mth</span>
    891 
    892 <span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1181 $&quot;</span><span class="p">)</span>
     896<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
     897
     898<span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1294 $&quot;</span><span class="p">)</span>
    893899
    894900<span class="n">DefaultControls</span> <span class="o">=</span> <span class="p">{</span>
     
    11471153    <span class="sd">&#39;&#39;&#39;Return a string with a more complete description for a GSAS-II variable </span>
    11481154
    1149 <span class="sd">    TODO: This will not handle rigid body parameters yet</span>
    1150 
    1151 <span class="sd">    :param str name: A full G2 variable name with 2 or 3</span>
    1152 <span class="sd">       colons (&lt;p&gt;:&lt;h&gt;:name[:&lt;a&gt;])</span>
     1155<span class="sd">    :param str varname: A full G2 variable name with 2 or 3 or 4</span>
     1156<span class="sd">       colons (&lt;p&gt;:&lt;h&gt;:name[:&lt;a&gt;] or &lt;p&gt;::RBname:&lt;r&gt;:&lt;t&gt;])</span>
    11531157<span class="sd">       </span>
    11541158<span class="sd">    :returns: a string with the description</span>
    11551159<span class="sd">    &#39;&#39;&#39;</span>
     1160    <span class="n">s</span><span class="p">,</span><span class="n">l</span> <span class="o">=</span> <span class="n">VarDescr</span><span class="p">(</span><span class="n">varname</span><span class="p">)</span>
     1161    <span class="k">return</span> <span class="n">s</span><span class="o">+</span><span class="s">&quot;: &quot;</span><span class="o">+</span><span class="n">l</span>
     1162</div>
     1163<div class="viewcode-block" id="VarDescr"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.VarDescr">[docs]</a><span class="k">def</span> <span class="nf">VarDescr</span><span class="p">(</span><span class="n">varname</span><span class="p">):</span>
     1164    <span class="sd">&#39;&#39;&#39;Return two strings with a more complete description for a GSAS-II variable </span>
     1165
     1166<span class="sd">    :param str name: A full G2 variable name with 2 or 3 or 4</span>
     1167<span class="sd">       colons (&lt;p&gt;:&lt;h&gt;:name[:&lt;a&gt;] or &lt;p&gt;::RBname:&lt;r&gt;:&lt;t&gt;])</span>
     1168<span class="sd">       </span>
     1169<span class="sd">    :returns: (loc,meaning) where loc describes what item the variable is mapped</span>
     1170<span class="sd">      (phase, histogram, etc.) and meaning describes what the variable does.</span>
     1171<span class="sd">    &#39;&#39;&#39;</span>
    11561172   
     1173    <span class="c"># special handling for parameter names without a colons</span>
     1174    <span class="c"># for now, assume self-defining</span>
     1175    <span class="k">if</span> <span class="n">varname</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
     1176        <span class="k">return</span> <span class="s">&quot;Global&quot;</span><span class="p">,</span><span class="n">varname</span>
     1177       
    11571178    <span class="n">l</span> <span class="o">=</span> <span class="n">getVarDescr</span><span class="p">(</span><span class="n">varname</span><span class="p">)</span>
    11581179    <span class="k">if</span> <span class="ow">not</span> <span class="n">l</span><span class="p">:</span>
    1159         <span class="k">return</span> <span class="s">&quot;invalid variable name (&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">varname</span><span class="p">)</span><span class="o">+</span><span class="s">&quot;)!&quot;</span>
    1160 
    1161     <span class="k">if</span> <span class="ow">not</span> <span class="n">l</span><span class="p">[</span><span class="mi">4</span><span class="p">]:</span>
    1162         <span class="n">l</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="o">=</span> <span class="s">&quot;(variable needs a definition!)&quot;</span>
     1180        <span class="c">#return (&quot;invalid variable name (&quot;+str(varname)+&quot;)!&quot;),&quot;&quot;</span>
     1181        <span class="k">return</span> <span class="s">&quot;invalid variable name!&quot;</span><span class="p">,</span><span class="s">&quot;&quot;</span>
     1182
     1183    <span class="k">if</span> <span class="ow">not</span> <span class="n">l</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span>
     1184        <span class="n">l</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="s">&quot;(variable needs a definition!)&quot;</span>
    11631185
    11641186    <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
    11651187    <span class="k">if</span> <span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> <span class="c"># HAP: keep short</span>
    1166         <span class="n">lbl</span> <span class="o">=</span> <span class="n">ShortPhaseNames</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="s">&#39;? #&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
    1167         <span class="n">hlbl</span> <span class="o">=</span> <span class="n">ShortHistNames</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="s">&#39;? #&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
     1188        <span class="k">if</span> <span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1189            <span class="n">lbl</span> <span class="o">=</span> <span class="s">&#39;all&#39;</span>
     1190        <span class="k">else</span><span class="p">:</span>
     1191            <span class="n">lbl</span> <span class="o">=</span> <span class="n">ShortPhaseNames</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="s">&#39;? #&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
     1192        <span class="k">if</span> <span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1193            <span class="n">hlbl</span> <span class="o">=</span> <span class="s">&#39;all&#39;</span>
     1194        <span class="k">else</span><span class="p">:</span>
     1195            <span class="n">hlbl</span> <span class="o">=</span> <span class="n">ShortHistNames</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="s">&#39;? #&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
    11681196        <span class="k">if</span> <span class="n">hlbl</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;HKLF&#39;</span><span class="p">:</span>
    11691197            <span class="n">hlbl</span> <span class="o">=</span> <span class="s">&#39;Xtl=&#39;</span><span class="o">+</span><span class="n">hlbl</span><span class="p">[</span><span class="mi">5</span><span class="p">:]</span>
     
    11721200        <span class="k">else</span><span class="p">:</span>
    11731201            <span class="n">hlbl</span> <span class="o">=</span> <span class="s">&#39;Hist=&#39;</span><span class="o">+</span><span class="n">hlbl</span>
    1174         <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;Ph=&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; * &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">hlbl</span><span class="p">)</span><span class="o">+</span><span class="s">&quot;: &quot;</span>
     1202        <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;Ph=&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; * &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">hlbl</span><span class="p">)</span>
     1203    <span class="k">elif</span> <span class="n">l</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;Back&#39;</span><span class="p">:</span> <span class="c"># background parameters are &quot;special&quot;, alas</span>
     1204        <span class="n">s</span> <span class="o">=</span> <span class="s">&#39;Hist=&#39;</span><span class="o">+</span><span class="n">ShortHistNames</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="s">&#39;? #&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
     1205        <span class="n">l</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="s">&#39; #&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
     1206    <span class="k">elif</span> <span class="n">l</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> <span class="c"># rigid body parameter</span>
     1207        <span class="n">lbl</span> <span class="o">=</span> <span class="n">ShortPhaseNames</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="s">&#39;phase?&#39;</span><span class="p">)</span>
     1208        <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;Res #&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span><span class="o">+</span><span class="s">&quot; body #&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span>
    11751209    <span class="k">elif</span> <span class="n">l</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> <span class="c"># atom parameter, </span>
    11761210        <span class="n">lbl</span> <span class="o">=</span> <span class="n">ShortPhaseNames</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="s">&#39;phase?&#39;</span><span class="p">)</span>
     
    11791213        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
    11801214            <span class="n">albl</span> <span class="o">=</span> <span class="s">&#39;Atom?&#39;</span>
    1181         <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;Atom &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">albl</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span><span class="o">+</span><span class="s">&quot;: &quot;</span>
     1215        <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;Atom &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">albl</span><span class="p">)</span><span class="o">+</span><span class="s">&quot; in &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span>
     1216    <span class="k">elif</span> <span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1217        <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;All phases &quot;</span>
    11821218    <span class="k">elif</span> <span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
    11831219        <span class="n">lbl</span> <span class="o">=</span> <span class="n">ShortPhaseNames</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="s">&#39;phase?&#39;</span><span class="p">)</span>
    1184         <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;Phase &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span><span class="o">+</span><span class="s">&quot;: &quot;</span>
     1220        <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;Phase &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span>
     1221    <span class="k">elif</span> <span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1222        <span class="n">s</span> <span class="o">=</span> <span class="s">&#39;All hists&#39;</span>
    11851223    <span class="k">elif</span> <span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
    11861224        <span class="n">hlbl</span> <span class="o">=</span> <span class="n">ShortHistNames</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="s">&#39;? #&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
     
    11911229        <span class="k">else</span><span class="p">:</span>
    11921230            <span class="n">hlbl</span> <span class="o">=</span> <span class="s">&#39;Hist=&#39;</span><span class="o">+</span><span class="n">hlbl</span>
    1193         <span class="n">s</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">hlbl</span><span class="p">)</span><span class="o">+</span><span class="s">&quot;: &quot;</span>   
     1231        <span class="n">s</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">hlbl</span><span class="p">)</span>
    11941232    <span class="k">if</span> <span class="ow">not</span> <span class="n">s</span><span class="p">:</span>
    1195         <span class="n">s</span> <span class="o">=</span> <span class="s">&#39;Global: &#39;</span>
    1196     <span class="n">s</span> <span class="o">+=</span> <span class="n">l</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span>
    1197     <span class="k">return</span> <span class="n">s</span>
     1233        <span class="n">s</span> <span class="o">=</span> <span class="s">&#39;Global&#39;</span>
     1234    <span class="k">return</span> <span class="n">s</span><span class="p">,</span><span class="n">l</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
    11981235</div>
    11991236<div class="viewcode-block" id="getVarDescr"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.getVarDescr">[docs]</a><span class="k">def</span> <span class="nf">getVarDescr</span><span class="p">(</span><span class="n">varname</span><span class="p">):</span>
    12001237    <span class="sd">&#39;&#39;&#39;Return a short description for a GSAS-II variable </span>
    12011238
    1202 <span class="sd">    :param str name: A full G2 variable name with 2 or 3</span>
    1203 <span class="sd">       colons (&lt;p&gt;:&lt;h&gt;:name[:&lt;a&gt;])</span>
     1239<span class="sd">    :param str name: A full G2 variable name with 2 or 3 or 4</span>
     1240<span class="sd">       colons (&lt;p&gt;:&lt;h&gt;:name[:&lt;a1&gt;][:&lt;a2&gt;])</span>
    12041241<span class="sd">      </span>
    1205 <span class="sd">    :returns: a five element list as [`p`,`h`,`name`,`a`,`description`],</span>
    1206 <span class="sd">      where `p`, `h`, `a` are str values or `None`, for the phase number,</span>
     1242<span class="sd">    :returns: a six element list as [`p`,`h`,`name`,`a1`,`a2`,`description`],</span>
     1243<span class="sd">      where `p`, `h`, `a1`, `a2` are str values or `None`, for the phase number,</span>
    12071244<span class="sd">      the histogram number and the atom number; `name` will always be</span>
    12081245<span class="sd">      an str; and `description` is str or `None`.</span>
     
    12121249    <span class="n">l</span> <span class="o">=</span> <span class="n">varname</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
    12131250    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
     1251        <span class="n">l</span> <span class="o">+=</span> <span class="p">[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">]</span>
     1252    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
    12141253        <span class="n">l</span> <span class="o">+=</span> <span class="p">[</span><span class="bp">None</span><span class="p">]</span>
    1215     <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">4</span><span class="p">:</span>
     1254    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">5</span><span class="p">:</span>
    12161255        <span class="k">return</span> <span class="bp">None</span>
    1217     <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">):</span>
     1256    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">):</span>
    12181257        <span class="k">if</span> <span class="n">l</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;&quot;</span><span class="p">:</span>
    12191258            <span class="n">l</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="bp">None</span>
     
    12421281<span class="sd">    </span>
    12431282<span class="sd">    &#39;&#39;&#39;</span>
    1244     <span class="kn">import</span> <span class="nn">re</span>
    12451283    <span class="k">if</span> <span class="n">reVarDesc</span><span class="p">:</span> <span class="k">return</span> <span class="c"># already done</span>
    12461284    <span class="k">for</span> <span class="n">key</span><span class="p">,</span><span class="n">value</span> <span class="ow">in</span> <span class="p">{</span>
     1285        <span class="c"># derived or other sequential vars</span>
     1286        <span class="s">&#39;([abc])$&#39;</span> <span class="p">:</span> <span class="s">&#39;Lattice parameter, </span><span class="se">\\</span><span class="s">1, from Ai and Djk&#39;</span><span class="p">,</span> <span class="c"># N.B. &#39;$&#39; prevents match if any characters follow</span>
     1287        <span class="s">u&#39;</span><span class="se">\u03B1</span><span class="s">&#39;</span> <span class="p">:</span> <span class="s">u&#39;Lattice parameter, </span><span class="se">\u03B1</span><span class="s">, from Ai and Djk&#39;</span><span class="p">,</span>
     1288        <span class="s">u&#39;</span><span class="se">\u03B2</span><span class="s">&#39;</span> <span class="p">:</span> <span class="s">u&#39;Lattice parameter, </span><span class="se">\u03B2</span><span class="s">, from Ai and Djk&#39;</span><span class="p">,</span>
     1289        <span class="s">u&#39;</span><span class="se">\u03B3</span><span class="s">&#39;</span> <span class="p">:</span> <span class="s">u&#39;Lattice parameter, </span><span class="se">\u03B3</span><span class="s">, from Ai and Djk&#39;</span><span class="p">,</span>
     1290        <span class="c"># ambiguous, alas:</span>
     1291        <span class="s">&#39;Scale&#39;</span> <span class="p">:</span> <span class="s">&#39;Phase or Histogram scale factor&#39;</span><span class="p">,</span>
    12471292        <span class="c"># Phase vars (p::&lt;var&gt;)</span>
    12481293        <span class="s">&#39;A([0-5])&#39;</span> <span class="p">:</span> <span class="s">&#39;Reciprocal metric tensor component </span><span class="se">\\</span><span class="s">1&#39;</span><span class="p">,</span>
    1249         <span class="s">&#39;Vol&#39;</span> <span class="p">:</span> <span class="s">&#39;Unit cell volume????&#39;</span><span class="p">,</span>
     1294        <span class="s">&#39;Vol&#39;</span> <span class="p">:</span> <span class="s">&#39;Unit cell volume&#39;</span><span class="p">,</span>
    12501295        <span class="c"># Atom vars (p::&lt;var&gt;:a)</span>
    12511296        <span class="s">&#39;dA([xyz])&#39;</span> <span class="p">:</span> <span class="s">&#39;change to atomic position </span><span class="se">\\</span><span class="s">1&#39;</span><span class="p">,</span>
     
    12541299        <span class="s">&#39;Afrac&#39;</span><span class="p">:</span> <span class="s">&#39;Atomic occupancy parameter&#39;</span><span class="p">,</span>
    12551300        <span class="c"># Hist &amp; Phase (HAP) vars (p:h:&lt;var&gt;)</span>
     1301        <span class="s">&#39;Back&#39;</span><span class="p">:</span> <span class="s">&#39;Background term&#39;</span><span class="p">,</span>
     1302        <span class="s">&#39;BkPkint;(.*)&#39;</span><span class="p">:</span><span class="s">&#39;Background peak #</span><span class="se">\\</span><span class="s">1 intensity&#39;</span><span class="p">,</span>
     1303        <span class="s">&#39;BkPkpos;(.*)&#39;</span><span class="p">:</span><span class="s">&#39;Background peak #</span><span class="se">\\</span><span class="s">1 position&#39;</span><span class="p">,</span>
     1304        <span class="s">&#39;BkPksig;(.*)&#39;</span><span class="p">:</span><span class="s">&#39;Background peak #</span><span class="se">\\</span><span class="s">1 Gaussian width&#39;</span><span class="p">,</span>
     1305        <span class="s">&#39;BkPkgam;(.*)&#39;</span><span class="p">:</span><span class="s">&#39;Background peak #</span><span class="se">\\</span><span class="s">1 Cauchy width&#39;</span><span class="p">,</span>
    12561306        <span class="s">&#39;Bab([AU])&#39;</span><span class="p">:</span> <span class="s">&#39;Babinet solvent scattering coef. </span><span class="se">\\</span><span class="s">1&#39;</span><span class="p">,</span>
    12571307        <span class="s">&#39;D([123][123])&#39;</span> <span class="p">:</span> <span class="s">&#39;Anisotropic strain coef. </span><span class="se">\\</span><span class="s">1&#39;</span><span class="p">,</span>
     
    12591309        <span class="s">&#39;MD&#39;</span> <span class="p">:</span> <span class="s">&#39;March-Dollase coef.&#39;</span><span class="p">,</span>
    12601310        <span class="s">&#39;Mustrain;.*&#39;</span> <span class="p">:</span> <span class="s">&#39;Microstrain coef.&#39;</span><span class="p">,</span>
    1261         <span class="s">&#39;Scale&#39;</span> <span class="p">:</span> <span class="s">&#39;Phase scale factor&#39;</span><span class="p">,</span>
    12621311        <span class="s">&#39;Size;.*&#39;</span> <span class="p">:</span> <span class="s">&#39;Crystallite size value&#39;</span><span class="p">,</span>
    12631312        <span class="s">&#39;eA&#39;</span> <span class="p">:</span> <span class="s">&#39;?&#39;</span><span class="p">,</span>
     
    12681317        <span class="s">&#39;Polariz\.&#39;</span> <span class="p">:</span> <span class="s">&#39;Polarization correction&#39;</span><span class="p">,</span>
    12691318        <span class="s">&#39;SH/L&#39;</span> <span class="p">:</span> <span class="s">&#39;FCJ peak asymmetry correction&#39;</span><span class="p">,</span>
    1270         <span class="s">&#39;Scale&#39;</span> <span class="p">:</span> <span class="s">&#39;Histogram scale factor&#39;</span><span class="p">,</span>
    12711319        <span class="s">&#39;([UVW])&#39;</span> <span class="p">:</span> <span class="s">&#39;Gaussian instrument broadening </span><span class="se">\\</span><span class="s">1&#39;</span><span class="p">,</span>
    12721320        <span class="s">&#39;([XY])&#39;</span> <span class="p">:</span> <span class="s">&#39;Cauchy instrument broadening </span><span class="se">\\</span><span class="s">1&#39;</span><span class="p">,</span>
     
    12741322        <span class="s">&#39;nDebye&#39;</span> <span class="p">:</span> <span class="s">&#39;Debye model background corr. terms&#39;</span><span class="p">,</span>
    12751323        <span class="s">&#39;nPeaks&#39;</span> <span class="p">:</span> <span class="s">&#39;Fixed peak background corr. terms&#39;</span><span class="p">,</span>
     1324        <span class="s">&#39;RBV.*&#39;</span> <span class="p">:</span> <span class="s">&#39;Vector rigid body parameter&#39;</span><span class="p">,</span>
     1325        <span class="s">&#39;RBR.*&#39;</span> <span class="p">:</span> <span class="s">&#39;Residue rigid body parameter&#39;</span><span class="p">,</span>
     1326        <span class="s">&#39;RBRO([aijk])&#39;</span> <span class="p">:</span> <span class="s">&#39;Residue rigid body orientation parameter&#39;</span><span class="p">,</span>
     1327        <span class="s">&#39;RBRP([xyz])&#39;</span> <span class="p">:</span> <span class="s">&#39;Residue rigid body position parameter&#39;</span><span class="p">,</span>
     1328        <span class="s">&#39;RBRTr;.*&#39;</span> <span class="p">:</span> <span class="s">&#39;Residue rigid body torsion parameter&#39;</span><span class="p">,</span>
     1329        <span class="s">&#39;RBR([TLS])([123AB][123AB])&#39;</span> <span class="p">:</span> <span class="s">&#39;Residue rigid body group disp. param.&#39;</span><span class="p">,</span>
    12761330        <span class="c"># Global vars (::&lt;var&gt;)</span>
     1331        <span class="s">&#39;constr([0-9]*)&#39;</span> <span class="p">:</span> <span class="s">&#39;Parameter from constraint&#39;</span><span class="p">,</span>
    12771332        <span class="p">}</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
    12781333        <span class="n">VarDesc</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
     
    12941349    <span class="k">return</span> <span class="bp">None</span>
    12951350</div>
     1351<div class="viewcode-block" id="GenWildCard"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.GenWildCard">[docs]</a><span class="k">def</span> <span class="nf">GenWildCard</span><span class="p">(</span><span class="n">varlist</span><span class="p">):</span>
     1352    <span class="sd">&#39;&#39;&#39;Generate wildcard versions of G2 variables. These introduce &#39;*&#39;</span>
     1353<span class="sd">    for a phase, histogram or atom number (but only for one of these</span>
     1354<span class="sd">    fields) but only when there is more than one matching variable in the</span>
     1355<span class="sd">    input variable list. So if the input is this::</span>
     1356<span class="sd">    </span>
     1357<span class="sd">      varlist = [&#39;0::AUiso:0&#39;, &#39;0::AUiso:1&#39;, &#39;1::AUiso:0&#39;]</span>
     1358
     1359<span class="sd">    then the output will be this::</span>
     1360<span class="sd">    </span>
     1361<span class="sd">       wildList = [&#39;*::AUiso:0&#39;, &#39;0::AUiso:*&#39;]</span>
     1362
     1363<span class="sd">    :param list varlist: an input list of GSAS-II variable names</span>
     1364<span class="sd">      (such as 0::AUiso:0)</span>
     1365
     1366<span class="sd">    :returns: wildList, the generated list of wild card variable names.</span>
     1367<span class="sd">    &#39;&#39;&#39;</span>
     1368    <span class="n">wild</span> <span class="o">=</span> <span class="p">[]</span>
     1369    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">):</span>
     1370        <span class="n">currentL</span> <span class="o">=</span> <span class="n">varlist</span><span class="p">[:]</span>
     1371        <span class="k">while</span> <span class="n">currentL</span><span class="p">:</span>
     1372            <span class="n">item1</span> <span class="o">=</span> <span class="n">currentL</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
     1373            <span class="n">i1splt</span> <span class="o">=</span> <span class="n">item1</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
     1374            <span class="k">if</span> <span class="n">i</span> <span class="o">&gt;=</span> <span class="nb">len</span><span class="p">(</span><span class="n">i1splt</span><span class="p">):</span> <span class="k">continue</span>
     1375            <span class="k">if</span> <span class="n">i1splt</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
     1376                <span class="n">nextL</span> <span class="o">=</span> <span class="p">[]</span>
     1377                <span class="n">i1splt</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;[0-9]+&#39;</span>
     1378                <span class="n">rexp</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">i1splt</span><span class="p">))</span>
     1379                <span class="n">matchlist</span> <span class="o">=</span> <span class="p">[</span><span class="n">item1</span><span class="p">]</span>
     1380                <span class="k">for</span> <span class="n">nxtitem</span> <span class="ow">in</span> <span class="n">currentL</span><span class="p">:</span>
     1381                    <span class="k">if</span> <span class="n">rexp</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">nxtitem</span><span class="p">):</span>
     1382                        <span class="n">matchlist</span> <span class="o">+=</span> <span class="p">[</span><span class="n">nxtitem</span><span class="p">]</span>
     1383                    <span class="k">else</span><span class="p">:</span>
     1384                        <span class="n">nextL</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nxtitem</span><span class="p">)</span>
     1385                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">matchlist</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     1386                    <span class="n">i1splt</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;*&#39;</span>
     1387                    <span class="n">wild</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">i1splt</span><span class="p">))</span>
     1388                <span class="n">currentL</span> <span class="o">=</span> <span class="n">nextL</span>
     1389    <span class="k">return</span> <span class="n">wild</span>
     1390</div>
     1391<div class="viewcode-block" id="LookupWildCard"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.LookupWildCard">[docs]</a><span class="k">def</span> <span class="nf">LookupWildCard</span><span class="p">(</span><span class="n">varname</span><span class="p">,</span><span class="n">varlist</span><span class="p">):</span>
     1392    <span class="sd">&#39;&#39;&#39;returns a list of variable names from list varname</span>
     1393<span class="sd">    that match wildcard name in varname</span>
     1394<span class="sd">    </span>
     1395<span class="sd">    :param str varname: a G2 variable name containing a wildcard</span>
     1396<span class="sd">      (such as \*::var)</span>
     1397<span class="sd">    :param list varlist: the list of all variable names used in</span>
     1398<span class="sd">      the current project</span>
     1399<span class="sd">    :returns: a list of matching GSAS-II variables (may be empty)  </span>
     1400<span class="sd">    &#39;&#39;&#39;</span>
     1401    <span class="n">rexp</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">varname</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;*&#39;</span><span class="p">,</span><span class="s">&#39;[0-9]+&#39;</span><span class="p">))</span>
     1402    <span class="k">return</span> <span class="nb">sorted</span><span class="p">([</span><span class="n">var</span> <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">varlist</span> <span class="k">if</span> <span class="n">rexp</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">var</span><span class="p">)])</span>
     1403
     1404</div>
    12961405<span class="k">def</span> <span class="nf">_lookup</span><span class="p">(</span><span class="n">dic</span><span class="p">,</span><span class="n">key</span><span class="p">):</span>
    12971406    <span class="sd">&#39;&#39;&#39;Lookup a key in a dictionary, where None returns an empty string</span>
     
    13001409    <span class="k">if</span> <span class="n">key</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
    13011410        <span class="k">return</span> <span class="s">&quot;&quot;</span>
     1411    <span class="k">elif</span> <span class="n">key</span> <span class="o">==</span> <span class="s">&quot;*&quot;</span><span class="p">:</span>
     1412        <span class="k">return</span> <span class="s">&quot;*&quot;</span>
    13021413    <span class="k">else</span><span class="p">:</span>
    13031414        <span class="k">return</span> <span class="n">dic</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">,</span><span class="s">&#39;?&#39;</span><span class="p">)</span>
     
    13101421<span class="sd">    before creating or later using the G2VarObj object.</span>
    13111422
     1423<span class="sd">    This can store rigid body variables, but does not translate the residue # and</span>
     1424<span class="sd">    body # to/from random Ids</span>
     1425
    13121426<span class="sd">    A :class:`G2VarObj` object can be created with a single parameter:</span>
    13131427<span class="sd">    </span>
     
    13151429<span class="sd">      object. If a string, it must be of form &quot;p:h:var&quot; or &quot;p:h:var:a&quot;, where</span>
    13161430
    1317 <span class="sd">     * p is the phase number (which may be left blank); </span>
    1318 <span class="sd">     * h is the histogram number (which may be left blank); </span>
     1431<span class="sd">     * p is the phase number (which may be left blank or may be &#39;*&#39; to indicate all phases); </span>
     1432<span class="sd">     * h is the histogram number (which may be left blank or may be &#39;*&#39; to indicate all histograms); </span>
    13191433<span class="sd">     * a is the atom number (which may be left blank in which case the third colon is omitted).</span>
     1434<span class="sd">       The atom number can be specified as &#39;*&#39; if a phase number is specified (not as &#39;*&#39;).</span>
     1435<span class="sd">       For rigid body variables, specify a will be a string of form &quot;residue:body#&quot;</span>
    13201436
    13211437<span class="sd">      Alternately a single tuple of form (Phase,Histogram,VarName,AtomID) can be used, where</span>
    1322 <span class="sd">      Phase, Histogram, and AtomID are None or are ranId values and VarName is a string.     </span>
     1438<span class="sd">      Phase, Histogram, and AtomID are None or are ranId values (or one can be &#39;*&#39;)</span>
     1439<span class="sd">      and VarName is a string. Note that if Phase is &#39;*&#39; then the AtomID is an atom number.</span>
     1440<span class="sd">      For a rigid body variables, AtomID is a string of form &quot;residue:body#&quot;.</span>
    13231441
    13241442<span class="sd">    If four positional arguments are supplied, they are:</span>
    13251443
    1326 <span class="sd">    :param str/int phasenum: The number for the phase</span>
    1327 <span class="sd">    :param str/int histnum: The number for the histogram</span>
     1444<span class="sd">    :param str/int phasenum: The number for the phase (or None or &#39;*&#39;)</span>
     1445<span class="sd">    :param str/int histnum: The number for the histogram (or None or &#39;*&#39;)</span>
    13281446<span class="sd">    :param str varname: a single value can be used to create a :class:`G2VarObj`</span>
    1329 <span class="sd">    :param str/int atomnum: The number for the atom</span>
     1447<span class="sd">    :param str/int atomnum: The number for the atom (or None or &#39;*&#39;)</span>
    13301448<span class="sd">    </span>
    13311449<span class="sd">    &#39;&#39;&#39;</span>
     
    13401458        <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="bp">None</span>
    13411459        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="ow">is</span> <span class="nb">list</span> <span class="ow">or</span> <span class="nb">type</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="ow">is</span> <span class="nb">tuple</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
     1460            <span class="c"># single arg with 4 values</span>
    13421461            <span class="bp">self</span><span class="o">.</span><span class="n">phase</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">histogram</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    1343         <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="s">&#39;:&#39;</span> <span class="ow">in</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>           
     1462        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="s">&#39;:&#39;</span> <span class="ow">in</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
     1463            <span class="c">#parse a string </span>
    13441464            <span class="n">lst</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
    1345             <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="o">=</span> <span class="n">PhaseIdLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">lst</span><span class="p">[</span><span class="mi">0</span><span class="p">],[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
    1346             <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="o">=</span> <span class="n">HistIdLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">lst</span><span class="p">[</span><span class="mi">1</span><span class="p">],[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
     1465            <span class="k">if</span> <span class="n">lst</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1466                <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="o">=</span> <span class="s">&#39;*&#39;</span>
     1467                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">:</span>
     1468                    <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="n">lst</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
     1469                <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="o">=</span> <span class="n">HistIdLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">lst</span><span class="p">[</span><span class="mi">1</span><span class="p">],[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
     1470            <span class="k">elif</span> <span class="n">lst</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>           
     1471                <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="o">=</span> <span class="s">&#39;*&#39;</span>
     1472                <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="o">=</span> <span class="n">PhaseIdLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">lst</span><span class="p">[</span><span class="mi">0</span><span class="p">],[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
     1473            <span class="k">else</span><span class="p">:</span>
     1474                <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="o">=</span> <span class="n">HistIdLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">lst</span><span class="p">[</span><span class="mi">1</span><span class="p">],[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
     1475                <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="o">=</span> <span class="n">PhaseIdLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">lst</span><span class="p">[</span><span class="mi">0</span><span class="p">],[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
     1476                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
     1477                    <span class="k">if</span> <span class="n">lst</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1478                        <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="s">&#39;*&#39;</span>
     1479                    <span class="k">else</span><span class="p">:</span>
     1480                        <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="n">AtomIdLookup</span><span class="p">[</span><span class="n">lst</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">lst</span><span class="p">[</span><span class="mi">3</span><span class="p">],[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
     1481                <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>
     1482                    <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="n">lst</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">+</span><span class="s">&quot;:&quot;</span><span class="o">+</span><span class="n">lst</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span>
     1483                <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
     1484                    <span class="k">pass</span>
     1485                <span class="k">else</span><span class="p">:</span>
     1486                    <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;Too many colons in var name &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
    13471487            <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">lst</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
    1348             <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">:</span>
    1349                 <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="n">AtomIdLookup</span><span class="p">[</span><span class="n">lst</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">lst</span><span class="p">[</span><span class="mi">3</span><span class="p">],[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
    13501488        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
    1351             <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="o">=</span> <span class="n">PhaseIdLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]),[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
    1352             <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="o">=</span> <span class="n">HistIdLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]),[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
     1489            <span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1490                <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="o">=</span> <span class="s">&#39;*&#39;</span>
     1491                <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
     1492            <span class="k">else</span><span class="p">:</span>
     1493                <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="o">=</span> <span class="n">PhaseIdLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]),[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
     1494                <span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1495                    <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="s">&#39;*&#39;</span>
     1496                <span class="k">elif</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
     1497                    <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="n">AtomIdLookup</span><span class="p">[</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">3</span><span class="p">]),[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
     1498            <span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1499                <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="o">=</span> <span class="s">&#39;*&#39;</span>
     1500            <span class="k">else</span><span class="p">:</span>
     1501                <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="o">=</span> <span class="n">HistIdLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]),[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
    13531502            <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
    1354             <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">=</span> <span class="n">AtomIdLookup</span><span class="p">[</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">3</span><span class="p">]),[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span>
    13551503        <span class="k">else</span><span class="p">:</span>
    13561504            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;Incorrectly called GSAS-II parameter name&quot;</span>
     
    13671515<span class="sd">        :returns: the variable name as a str</span>
    13681516<span class="sd">        &#39;&#39;&#39;</span>
    1369         <span class="n">ph</span> <span class="o">=</span> <span class="n">_lookup</span><span class="p">(</span><span class="n">PhaseRanIdLookup</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">phase</span><span class="p">)</span>
    1370         <span class="n">hist</span> <span class="o">=</span> <span class="n">_lookup</span><span class="p">(</span><span class="n">HistRanIdLookup</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">histogram</span><span class="p">)</span>
    1371         <span class="n">s</span> <span class="o">=</span> <span class="p">(</span><span class="n">ph</span> <span class="o">+</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span> <span class="n">hist</span> <span class="o">+</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span>
    1372              <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
    1373         <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">:</span>
    1374             <span class="k">if</span> <span class="n">ph</span> <span class="ow">in</span> <span class="n">AtomRanIdLookup</span><span class="p">:</span>
    1375                 <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span> <span class="n">AtomRanIdLookup</span><span class="p">[</span><span class="n">ph</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">,</span><span class="s">&#39;?&#39;</span><span class="p">)</span>
    1376             <span class="k">else</span><span class="p">:</span>
    1377                 <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;:?&quot;</span>
     1517        <span class="n">a</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
     1518        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="o">==</span> <span class="s">&quot;*&quot;</span><span class="p">:</span>
     1519            <span class="n">ph</span> <span class="o">=</span> <span class="s">&quot;*&quot;</span>
     1520            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">:</span>
     1521                <span class="n">a</span> <span class="o">=</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">)</span>
     1522        <span class="k">else</span><span class="p">:</span>
     1523            <span class="n">ph</span> <span class="o">=</span> <span class="n">_lookup</span><span class="p">(</span><span class="n">PhaseRanIdLookup</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">phase</span><span class="p">)</span>
     1524            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1525                <span class="n">a</span> <span class="o">=</span> <span class="s">&#39;:*&#39;</span>
     1526            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">:</span>
     1527                <span class="k">if</span> <span class="s">&quot;:&quot;</span> <span class="ow">in</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">):</span>
     1528                    <span class="n">a</span> <span class="o">=</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">)</span>
     1529                <span class="k">elif</span> <span class="n">ph</span> <span class="ow">in</span> <span class="n">AtomRanIdLookup</span><span class="p">:</span>
     1530                    <span class="n">a</span> <span class="o">=</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span> <span class="n">AtomRanIdLookup</span><span class="p">[</span><span class="n">ph</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">,</span><span class="s">&#39;?&#39;</span><span class="p">)</span>
     1531                <span class="k">else</span><span class="p">:</span>
     1532                    <span class="n">a</span> <span class="o">=</span> <span class="s">&quot;:?&quot;</span>
     1533        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="o">==</span> <span class="s">&quot;*&quot;</span><span class="p">:</span>
     1534            <span class="n">hist</span> <span class="o">=</span> <span class="s">&quot;*&quot;</span>
     1535        <span class="k">else</span><span class="p">:</span>
     1536            <span class="n">hist</span> <span class="o">=</span> <span class="n">_lookup</span><span class="p">(</span><span class="n">HistRanIdLookup</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">histogram</span><span class="p">)</span>
     1537        <span class="n">s</span> <span class="o">=</span> <span class="p">(</span><span class="n">ph</span> <span class="o">+</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span> <span class="n">hist</span> <span class="o">+</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> <span class="o">+</span> <span class="n">a</span>
    13781538        <span class="k">return</span> <span class="n">s</span>
    13791539    </div>
     
    13821542<span class="sd">        &#39;&#39;&#39;</span>
    13831543        <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;&lt;&quot;</span>
    1384         <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
     1544        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1545            <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;Phases: all; &quot;</span>
     1546            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
     1547                <span class="k">if</span> <span class="s">&quot;:&quot;</span> <span class="ow">in</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">):</span>
     1548                    <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;Rigid body&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;; &quot;</span>
     1549                <span class="k">else</span><span class="p">:</span>
     1550                    <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;Atom #&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;; &quot;</span>
     1551        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">phase</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
    13851552            <span class="n">ph</span> <span class="o">=</span>  <span class="n">_lookup</span><span class="p">(</span><span class="n">PhaseRanIdLookup</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">phase</span><span class="p">)</span>
    13861553            <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;Phase: rId=&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">phase</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot; (#&quot;</span><span class="o">+</span> <span class="n">ph</span> <span class="o">+</span> <span class="s">&quot;); &quot;</span>
    1387         <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
     1554            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1555                <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;Atoms: all; &quot;</span>
     1556            <span class="k">elif</span> <span class="s">&quot;:&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">):</span>
     1557                <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;Rigid body&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;; &quot;</span>
     1558            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
     1559                <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;Atom rId=&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">)</span>
     1560                <span class="k">if</span> <span class="n">ph</span> <span class="ow">in</span> <span class="n">AtomRanIdLookup</span><span class="p">:</span>
     1561                    <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot; (#&quot;</span> <span class="o">+</span> <span class="n">AtomRanIdLookup</span><span class="p">[</span><span class="n">ph</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">,</span><span class="s">&#39;?&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;); &quot;</span>
     1562                <span class="k">else</span><span class="p">:</span>
     1563                    <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot; (#? -- not found!); &quot;</span>
     1564        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="o">==</span> <span class="s">&#39;*&#39;</span><span class="p">:</span>
     1565            <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;Histograms: all; &quot;</span>
     1566        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">histogram</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
    13881567            <span class="n">hist</span> <span class="o">=</span> <span class="n">_lookup</span><span class="p">(</span><span class="n">HistRanIdLookup</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">histogram</span><span class="p">)</span>
    13891568            <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;Histogram: rId=&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">histogram</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot; (#&quot;</span><span class="o">+</span> <span class="n">hist</span> <span class="o">+</span> <span class="s">&quot;); &quot;</span>
    1390         <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">atom</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
    1391             <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;Atom rId=&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">)</span>
    1392             <span class="k">if</span> <span class="n">ph</span> <span class="ow">in</span> <span class="n">AtomRanIdLookup</span><span class="p">:</span>
    1393                 <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot; (#&quot;</span> <span class="o">+</span> <span class="n">AtomRanIdLookup</span><span class="p">[</span><span class="n">ph</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom</span><span class="p">,</span><span class="s">&#39;?&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;); &quot;</span>
    1394             <span class="k">else</span><span class="p">:</span>
    1395                 <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot; (#? -- not found!); &quot;</span>
    13961569        <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;Variable name=&quot;&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span> <span class="o">+</span> <span class="s">&#39;&quot;&gt;&#39;</span>
    1397         <span class="k">return</span> <span class="n">s</span><span class="o">+</span><span class="s">&quot;(&quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">()</span><span class="o">+</span><span class="s">&quot;)&quot;</span>
     1570        <span class="k">return</span> <span class="n">s</span><span class="o">+</span><span class="s">&quot; (&quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">varname</span><span class="p">()</span><span class="o">+</span><span class="s">&quot;)&quot;</span>
    13981571
    13991572    <span class="k">def</span> <span class="nf">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
     
    14101583        <span class="k">print</span> <span class="s">&#39;hists&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">IDdict</span><span class="p">[</span><span class="s">&#39;hists&#39;</span><span class="p">]</span>
    14111584        <span class="k">print</span> <span class="s">&#39;atomDict&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">IDdict</span><span class="p">[</span><span class="s">&#39;atoms&#39;</span><span class="p">]</span>
    1412 </pre></div></div>
     1585
     1586<span class="c">#==========================================================================</span>
     1587<span class="c"># shortcut routines</span></div>
     1588<span class="n">exp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span>
     1589<span class="n">sind</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="mf">180.</span><span class="p">)</span>
     1590<span class="n">tand</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">tan</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="mf">180.</span><span class="p">)</span>
     1591<span class="n">cosd</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="mf">180.</span><span class="p">)</span>
     1592<span class="n">sind</span> <span class="o">=</span> <span class="n">sin</span> <span class="o">=</span> <span class="n">s</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="mf">180.</span><span class="p">)</span>
     1593<span class="n">cosd</span> <span class="o">=</span> <span class="n">cos</span> <span class="o">=</span> <span class="n">c</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="mf">180.</span><span class="p">)</span>
     1594<span class="n">tand</span> <span class="o">=</span> <span class="n">tan</span> <span class="o">=</span> <span class="n">t</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">tan</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="mf">180.</span><span class="p">)</span>
     1595<span class="n">sqrt</span> <span class="o">=</span> <span class="n">sq</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
     1596<span class="n">pi</span> <span class="o">=</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span>
     1597<div class="viewcode-block" id="ExpressionObj"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.ExpressionObj">[docs]</a><span class="k">class</span> <span class="nc">ExpressionObj</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
     1598    <span class="sd">&#39;&#39;&#39;Defines an object with a user-defined expression, to be used for</span>
     1599<span class="sd">    secondary fits or restraints. Object is created null, but is changed</span>
     1600<span class="sd">    using :meth:`LoadExpression`. This contains only the minimum</span>
     1601<span class="sd">    information that needs to be stored to save and load the expression</span>
     1602<span class="sd">    and how it is mapped to GSAS-II variables. </span>
     1603<span class="sd">    &#39;&#39;&#39;</span>
     1604    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
     1605        <span class="bp">self</span><span class="o">.</span><span class="n">expression</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
     1606        <span class="s">&#39;The expression as a text string&#39;</span>
     1607        <span class="bp">self</span><span class="o">.</span><span class="n">assgnVars</span> <span class="o">=</span> <span class="p">{}</span>
     1608        <span class="sd">&#39;&#39;&#39;A dict where keys are label names in the expression mapping to a GSAS-II</span>
     1609<span class="sd">        variable. The value is a list with a G2 variable name and derivative step size.</span>
     1610<span class="sd">        Note that the G2 variable name may contain a wild-card and correspond to</span>
     1611<span class="sd">        multiple values.</span>
     1612<span class="sd">        &#39;&#39;&#39;</span>
     1613        <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span> <span class="o">=</span> <span class="p">{}</span>
     1614        <span class="sd">&#39;&#39;&#39;A dict where keys are label names in the expression mapping to a free</span>
     1615<span class="sd">        parameter. The value is a list with:</span>
     1616
     1617<span class="sd">         * a name assigned to the parameter</span>
     1618<span class="sd">         * a value for to the parameter</span>
     1619<span class="sd">         * a derivative step size and</span>
     1620<span class="sd">         * a flag to determine if the variable is refined.</span>
     1621<span class="sd">        &#39;&#39;&#39;</span>
     1622
     1623        <span class="bp">self</span><span class="o">.</span><span class="n">lastError</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">)</span>
     1624        <span class="sd">&#39;&#39;&#39;Shows last encountered error in processing expression</span>
     1625<span class="sd">        (list of 1-3 str values)&#39;&#39;&#39;</span>
     1626
     1627<div class="viewcode-block" id="ExpressionObj.LoadExpression"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.ExpressionObj.LoadExpression">[docs]</a>    <span class="k">def</span> <span class="nf">LoadExpression</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">expr</span><span class="p">,</span><span class="n">exprVarLst</span><span class="p">,</span><span class="n">varSelect</span><span class="p">,</span><span class="n">varName</span><span class="p">,</span><span class="n">varValue</span><span class="p">,</span><span class="n">varStep</span><span class="p">,</span><span class="n">varRefflag</span><span class="p">):</span>
     1628        <span class="sd">&#39;&#39;&#39;Load the expression and associated settings into the object. Raises</span>
     1629<span class="sd">        an exception if the expression is not parsed, if not all functions</span>
     1630<span class="sd">        are defined or if not all needed parameter labels in the expression</span>
     1631<span class="sd">        are defined.</span>
     1632
     1633<span class="sd">        This will not test if the variable referenced in these definitions</span>
     1634<span class="sd">        are actually in the parameter dictionary. This is checked when the</span>
     1635<span class="sd">        computation for the expression is done in :meth:`SetupCalc`.</span>
     1636<span class="sd">        </span>
     1637<span class="sd">        :param str expr: the expression</span>
     1638<span class="sd">        :param list exprVarLst: parameter labels found in the expression</span>
     1639<span class="sd">        :param dict varSelect: this will be 0 for Free parameters</span>
     1640<span class="sd">          and non-zero for expression labels linked to G2 variables.</span>
     1641<span class="sd">        :param dict varName: Defines a name (str) associated with each free parameter</span>
     1642<span class="sd">        :param dict varValue: Defines a value (float) associated with each free parameter</span>
     1643<span class="sd">        :param dict varStep: Defines a derivative step size (float) for each</span>
     1644<span class="sd">          parameter labels found in the expression</span>
     1645<span class="sd">        :param dict varRefflag: Defines a refinement flag (bool)</span>
     1646<span class="sd">          associated with each free parameter</span>
     1647<span class="sd">        &#39;&#39;&#39;</span>
     1648        <span class="bp">self</span><span class="o">.</span><span class="n">expression</span> <span class="o">=</span> <span class="n">expr</span>
     1649        <span class="bp">self</span><span class="o">.</span><span class="n">compiledExpr</span> <span class="o">=</span> <span class="bp">None</span>
     1650        <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span> <span class="o">=</span> <span class="p">{}</span>
     1651        <span class="bp">self</span><span class="o">.</span><span class="n">assgnVars</span> <span class="o">=</span> <span class="p">{}</span>
     1652        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">exprVarLst</span><span class="p">:</span>
     1653            <span class="k">if</span> <span class="n">varSelect</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
     1654                <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span>
     1655                    <span class="n">varName</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">v</span><span class="p">),</span>
     1656                    <span class="n">varValue</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">v</span><span class="p">),</span>
     1657                    <span class="n">varStep</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">v</span><span class="p">),</span>
     1658                    <span class="n">varRefflag</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">v</span><span class="p">),</span>
     1659                    <span class="p">]</span>
     1660            <span class="k">else</span><span class="p">:</span>
     1661                <span class="bp">self</span><span class="o">.</span><span class="n">assgnVars</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span>
     1662                    <span class="n">varName</span><span class="p">[</span><span class="n">v</span><span class="p">],</span>
     1663                    <span class="n">varStep</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">v</span><span class="p">),</span>
     1664                    <span class="p">]</span>
     1665        <span class="bp">self</span><span class="o">.</span><span class="n">CheckVars</span><span class="p">()</span>
     1666</div>
     1667<div class="viewcode-block" id="ExpressionObj.EditExpression"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.ExpressionObj.EditExpression">[docs]</a>    <span class="k">def</span> <span class="nf">EditExpression</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">exprVarLst</span><span class="p">,</span><span class="n">varSelect</span><span class="p">,</span><span class="n">varName</span><span class="p">,</span><span class="n">varValue</span><span class="p">,</span><span class="n">varStep</span><span class="p">,</span><span class="n">varRefflag</span><span class="p">):</span>
     1668        <span class="sd">&#39;&#39;&#39;Load the expression and associated settings from the object into</span>
     1669<span class="sd">        arrays used for editing.</span>
     1670
     1671<span class="sd">        :param list exprVarLst: parameter labels found in the expression</span>
     1672<span class="sd">        :param dict varSelect: this will be 0 for Free parameters</span>
     1673<span class="sd">          and non-zero for expression labels linked to G2 variables.</span>
     1674<span class="sd">        :param dict varName: Defines a name (str) associated with each free parameter</span>
     1675<span class="sd">        :param dict varValue: Defines a value (float) associated with each free parameter</span>
     1676<span class="sd">        :param dict varStep: Defines a derivative step size (float) for each</span>
     1677<span class="sd">          parameter labels found in the expression</span>
     1678<span class="sd">        :param dict varRefflag: Defines a refinement flag (bool)</span>
     1679<span class="sd">          associated with each free parameter</span>
     1680
     1681<span class="sd">        :returns: the expression as a str</span>
     1682<span class="sd">        &#39;&#39;&#39;</span>
     1683        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span><span class="p">:</span>
     1684            <span class="n">varSelect</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
     1685            <span class="n">varName</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
     1686            <span class="n">varValue</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
     1687            <span class="n">varStep</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>
     1688            <span class="n">varRefflag</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span>
     1689        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">assgnVars</span><span class="p">:</span>
     1690            <span class="n">varSelect</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
     1691            <span class="n">varName</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">assgnVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
     1692            <span class="n">varStep</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">assgnVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
     1693        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span>
     1694</div>
     1695<div class="viewcode-block" id="ExpressionObj.GetVaried"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.ExpressionObj.GetVaried">[docs]</a>    <span class="k">def</span> <span class="nf">GetVaried</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
     1696        <span class="s">&#39;Returns the names of the free parameters that will be refined&#39;</span>
     1697        <span class="k">return</span> <span class="p">[</span><span class="s">&quot;::&quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">3</span><span class="p">]]</span>
     1698</div>
     1699<div class="viewcode-block" id="ExpressionObj.CheckVars"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.ExpressionObj.CheckVars">[docs]</a>    <span class="k">def</span> <span class="nf">CheckVars</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
     1700        <span class="sd">&#39;&#39;&#39;Check that the expression can be parsed, all functions are</span>
     1701<span class="sd">        defined and that input loaded into the object is internally</span>
     1702<span class="sd">        consistent. If not an Exception is raised.</span>
     1703
     1704<span class="sd">        :returns: a dict with references to packages needed to</span>
     1705<span class="sd">          find functions referenced in the expression.</span>
     1706<span class="sd">        &#39;&#39;&#39;</span>
     1707        <span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ParseExpression</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span>
     1708        <span class="k">if</span> <span class="ow">not</span> <span class="n">ret</span><span class="p">:</span>
     1709            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&quot;Expression parse error&quot;</span><span class="p">)</span>
     1710        <span class="n">exprLblList</span><span class="p">,</span><span class="n">fxnpkgdict</span> <span class="o">=</span> <span class="n">ret</span>
     1711        <span class="c"># check each var used in expression is defined</span>
     1712        <span class="n">defined</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">assgnVars</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">freeVars</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
     1713        <span class="n">notfound</span> <span class="o">=</span> <span class="p">[]</span>
     1714        <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">exprLblList</span><span class="p">:</span>
     1715            <span class="k">if</span> <span class="n">var</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">defined</span><span class="p">:</span>
     1716                <span class="n">notfound</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">var</span><span class="p">)</span>
     1717        <span class="k">if</span> <span class="n">notfound</span><span class="p">:</span>
     1718            <span class="n">msg</span> <span class="o">=</span> <span class="s">&#39;Not all variables defined&#39;</span>
     1719            <span class="n">msg1</span> <span class="o">=</span> <span class="s">&#39;The following variables were not defined: &#39;</span>
     1720            <span class="n">msg2</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
     1721            <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">notfound</span><span class="p">:</span>
     1722                <span class="k">if</span> <span class="n">msg</span><span class="p">:</span> <span class="n">msg</span> <span class="o">+=</span> <span class="s">&#39;, &#39;</span>
     1723                <span class="n">msg</span> <span class="o">+=</span> <span class="n">var</span>
     1724            <span class="bp">self</span><span class="o">.</span><span class="n">lastError</span> <span class="o">=</span> <span class="p">(</span><span class="n">msg1</span><span class="p">,</span><span class="s">&#39;  &#39;</span><span class="o">+</span><span class="n">msg2</span><span class="p">)</span>
     1725            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
     1726        <span class="k">return</span> <span class="n">fxnpkgdict</span>
     1727</div>
     1728<div class="viewcode-block" id="ExpressionObj.ParseExpression"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.ExpressionObj.ParseExpression">[docs]</a>    <span class="k">def</span> <span class="nf">ParseExpression</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">expr</span><span class="p">):</span>
     1729        <span class="sd">&#39;&#39;&#39;Parse an expression and return a dict of called functions and</span>
     1730<span class="sd">        the variables used in the expression. Returns None in case an error</span>
     1731<span class="sd">        is encountered. If packages are referenced in functions, they are loaded </span>
     1732<span class="sd">        and the functions are looked up into the modules global</span>
     1733<span class="sd">        workspace. </span>
     1734<span class="sd">        </span>
     1735<span class="sd">        Note that no changes are made to the object other than</span>
     1736<span class="sd">        saving an error message, so that this can be used for testing prior</span>
     1737<span class="sd">        to the save. </span>
     1738
     1739<span class="sd">        :returns: a list of variables used variables</span>
     1740<span class="sd">        &#39;&#39;&#39;</span>
     1741        <span class="bp">self</span><span class="o">.</span><span class="n">lastError</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">)</span>
     1742        <span class="kn">import</span> <span class="nn">ast</span>
     1743        <span class="k">def</span> <span class="nf">FindFunction</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
     1744            <span class="sd">&#39;&#39;&#39;Find the object corresponding to function f</span>
     1745<span class="sd">            :param str f: a function name such as &#39;numpy.exp&#39;</span>
     1746<span class="sd">            :returns: (pkgdict,pkgobj) where pkgdict contains a dict</span>
     1747<span class="sd">              that defines the package location(s) and where pkgobj</span>
     1748<span class="sd">              defines the object associated with the function.</span>
     1749<span class="sd">              If the function is not found, pkgobj is None.</span>
     1750<span class="sd">            &#39;&#39;&#39;</span>
     1751            <span class="n">df</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span>
     1752            <span class="n">pkgdict</span> <span class="o">=</span> <span class="p">{}</span>
     1753            <span class="c"># no listed package, try in current namespace</span>
     1754            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">df</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
     1755                <span class="k">try</span><span class="p">:</span>
     1756                    <span class="n">fxnobj</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
     1757                    <span class="k">return</span> <span class="n">pkgdict</span><span class="p">,</span><span class="n">fxnobj</span>
     1758                <span class="k">except</span> <span class="p">(</span><span class="ne">AttributeError</span><span class="p">,</span> <span class="ne">NameError</span><span class="p">):</span>
     1759                    <span class="k">return</span> <span class="bp">None</span>
     1760            <span class="k">else</span><span class="p">:</span>
     1761                <span class="k">try</span><span class="p">:</span>
     1762                    <span class="n">fxnobj</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
     1763                    <span class="n">pkgdict</span><span class="p">[</span><span class="n">df</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
     1764                    <span class="k">return</span> <span class="n">pkgdict</span><span class="p">,</span><span class="n">fxnobj</span>
     1765                <span class="k">except</span> <span class="p">(</span><span class="ne">AttributeError</span><span class="p">,</span> <span class="ne">NameError</span><span class="p">):</span>
     1766                    <span class="k">pass</span>
     1767            <span class="c"># includes a package, lets try to load the packages</span>
     1768            <span class="n">pkgname</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
     1769            <span class="n">path</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">path</span>
     1770            <span class="k">for</span> <span class="n">pkg</span> <span class="ow">in</span> <span class="n">f</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span> <span class="c"># if needed, descend down the tree</span>
     1771                <span class="k">if</span> <span class="n">pkgname</span><span class="p">:</span>
     1772                    <span class="n">pkgname</span> <span class="o">+=</span> <span class="s">&#39;.&#39;</span> <span class="o">+</span> <span class="n">pkg</span>
     1773                <span class="k">else</span><span class="p">:</span>
     1774                    <span class="n">pkgname</span> <span class="o">=</span> <span class="n">pkg</span>
     1775                <span class="n">fp</span> <span class="o">=</span> <span class="bp">None</span>
     1776                <span class="k">try</span><span class="p">:</span>
     1777                    <span class="n">fp</span><span class="p">,</span> <span class="n">fppath</span><span class="p">,</span><span class="n">desc</span> <span class="o">=</span> <span class="n">imp</span><span class="o">.</span><span class="n">find_module</span><span class="p">(</span><span class="n">pkg</span><span class="p">,</span><span class="n">path</span><span class="p">)</span>
     1778                    <span class="n">pkgobj</span> <span class="o">=</span> <span class="n">imp</span><span class="o">.</span><span class="n">load_module</span><span class="p">(</span><span class="n">pkg</span><span class="p">,</span><span class="n">fp</span><span class="p">,</span><span class="n">fppath</span><span class="p">,</span><span class="n">desc</span><span class="p">)</span>
     1779                    <span class="n">pkgdict</span><span class="p">[</span><span class="n">pkgname</span><span class="p">]</span> <span class="o">=</span> <span class="n">pkgobj</span>
     1780                    <span class="n">path</span> <span class="o">=</span> <span class="p">[</span><span class="n">fppath</span><span class="p">]</span>
     1781                <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">msg</span><span class="p">:</span>
     1782                    <span class="k">print</span><span class="p">(</span><span class="s">&#39;load of &#39;</span><span class="o">+</span><span class="n">pkgname</span><span class="o">+</span><span class="s">&#39; failed with error=&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">msg</span><span class="p">))</span>
     1783                    <span class="k">return</span> <span class="p">{},</span><span class="bp">None</span>
     1784                <span class="k">finally</span><span class="p">:</span>
     1785                    <span class="k">if</span> <span class="n">fp</span><span class="p">:</span> <span class="n">fp</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
     1786                <span class="k">try</span><span class="p">:</span>
     1787                    <span class="c">#print &#39;before&#39;,pkgdict.keys()</span>
     1788                    <span class="n">fxnobj</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="nb">globals</span><span class="p">(),</span><span class="n">pkgdict</span><span class="p">)</span>
     1789                    <span class="c">#print &#39;after 1&#39;,pkgdict.keys()</span>
     1790                    <span class="c">#fxnobj = eval(f,pkgdict)</span>
     1791                    <span class="c">#print &#39;after 2&#39;,pkgdict.keys()</span>
     1792                    <span class="k">return</span> <span class="n">pkgdict</span><span class="p">,</span><span class="n">fxnobj</span>
     1793                <span class="k">except</span><span class="p">:</span>
     1794                    <span class="k">continue</span>
     1795            <span class="k">return</span> <span class="bp">None</span> <span class="c"># not found</span>
     1796        <span class="k">def</span> <span class="nf">ASTtransverse</span><span class="p">(</span><span class="n">node</span><span class="p">,</span><span class="n">fxn</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
     1797            <span class="sd">&#39;&#39;&#39;Transverse a AST-parsed expresson, compiling a list of variables</span>
     1798<span class="sd">            referenced in the expression. This routine is used recursively.</span>
     1799
     1800<span class="sd">            :returns: varlist,fxnlist where</span>
     1801<span class="sd">              varlist is a list of referenced variable names and</span>
     1802<span class="sd">              fxnlist is a list of used functions</span>
     1803<span class="sd">            &#39;&#39;&#39;</span>
     1804            <span class="n">varlist</span> <span class="o">=</span> <span class="p">[]</span>
     1805            <span class="n">fxnlist</span> <span class="o">=</span> <span class="p">[]</span>
     1806            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
     1807                <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">node</span><span class="p">:</span>
     1808                    <span class="n">v</span><span class="p">,</span><span class="n">f</span> <span class="o">=</span> <span class="n">ASTtransverse</span><span class="p">(</span><span class="n">b</span><span class="p">,</span><span class="n">fxn</span><span class="p">)</span>
     1809                    <span class="n">varlist</span> <span class="o">+=</span> <span class="n">v</span>
     1810                    <span class="n">fxnlist</span> <span class="o">+=</span> <span class="n">f</span>
     1811            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">ast</span><span class="o">.</span><span class="n">AST</span><span class="p">):</span>
     1812                <span class="k">for</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">ast</span><span class="o">.</span><span class="n">iter_fields</span><span class="p">(</span><span class="n">node</span><span class="p">):</span>
     1813                    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">ast</span><span class="o">.</span><span class="n">AST</span><span class="p">):</span>
     1814                        <span class="k">if</span> <span class="n">a</span> <span class="o">==</span> <span class="s">&#39;func&#39;</span><span class="p">:</span>
     1815                            <span class="n">fxnlist</span> <span class="o">+=</span> <span class="p">[</span><span class="s">&#39;.&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ASTtransverse</span><span class="p">(</span><span class="n">b</span><span class="p">,</span><span class="bp">True</span><span class="p">)[</span><span class="mi">0</span><span class="p">])]</span>
     1816                            <span class="k">continue</span>
     1817                        <span class="n">v</span><span class="p">,</span><span class="n">f</span> <span class="o">=</span> <span class="n">ASTtransverse</span><span class="p">(</span><span class="n">b</span><span class="p">,</span><span class="n">fxn</span><span class="p">)</span>
     1818                        <span class="n">varlist</span> <span class="o">+=</span> <span class="n">v</span>
     1819                        <span class="n">fxnlist</span> <span class="o">+=</span> <span class="n">f</span>
     1820                    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
     1821                        <span class="n">v</span><span class="p">,</span><span class="n">f</span> <span class="o">=</span> <span class="n">ASTtransverse</span><span class="p">(</span><span class="n">b</span><span class="p">,</span><span class="n">fxn</span><span class="p">)</span>
     1822                        <span class="n">varlist</span> <span class="o">+=</span> <span class="n">v</span>
     1823                        <span class="n">fxnlist</span> <span class="o">+=</span> <span class="n">f</span>
     1824                    <span class="k">elif</span> <span class="n">node</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;Name&quot;</span><span class="p">:</span>
     1825                        <span class="n">varlist</span> <span class="o">+=</span> <span class="p">[</span><span class="n">b</span><span class="p">]</span>
     1826                    <span class="k">elif</span> <span class="n">fxn</span> <span class="ow">and</span> <span class="n">node</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;Attribute&quot;</span><span class="p">:</span>
     1827                        <span class="n">varlist</span> <span class="o">+=</span> <span class="p">[</span><span class="n">b</span><span class="p">]</span>
     1828            <span class="k">return</span> <span class="n">varlist</span><span class="p">,</span><span class="n">fxnlist</span>
     1829        <span class="k">try</span><span class="p">:</span>
     1830            <span class="n">exprast</span> <span class="o">=</span> <span class="n">ast</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>
     1831        <span class="k">except</span> <span class="ne">SyntaxError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span>
     1832            <span class="n">s</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
     1833            <span class="kn">import</span> <span class="nn">traceback</span>
     1834            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">traceback</span><span class="o">.</span><span class="n">format_exc</span><span class="p">()</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()[</span><span class="o">-</span><span class="mi">3</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span>
     1835                <span class="k">if</span> <span class="n">s</span><span class="p">:</span> <span class="n">s</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span>
     1836                <span class="n">s</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
     1837            <span class="bp">self</span><span class="o">.</span><span class="n">lastError</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;Error parsing expression:&quot;</span><span class="p">,</span><span class="n">s</span><span class="p">)</span>
     1838            <span class="k">return</span>
     1839        <span class="c"># find the variables &amp; functions</span>
     1840        <span class="n">v</span><span class="p">,</span><span class="n">f</span> <span class="o">=</span> <span class="n">ASTtransverse</span><span class="p">(</span><span class="n">exprast</span><span class="p">)</span>
     1841        <span class="n">varlist</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">v</span><span class="p">)))</span>
     1842        <span class="n">fxnlist</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">f</span><span class="p">))</span>
     1843        <span class="n">pkgdict</span> <span class="o">=</span> <span class="p">{}</span>
     1844        <span class="c"># check the functions are defined</span>
     1845        <span class="k">for</span> <span class="n">fxn</span> <span class="ow">in</span> <span class="n">fxnlist</span><span class="p">:</span>
     1846            <span class="n">fxndict</span><span class="p">,</span><span class="n">fxnobj</span> <span class="o">=</span> <span class="n">FindFunction</span><span class="p">(</span><span class="n">fxn</span><span class="p">)</span>
     1847            <span class="k">if</span> <span class="ow">not</span> <span class="n">fxnobj</span><span class="p">:</span>
     1848                <span class="bp">self</span><span class="o">.</span><span class="n">lastError</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;Error: Invalid function&quot;</span><span class="p">,</span><span class="n">fxn</span><span class="p">,</span>
     1849                                  <span class="s">&quot;is not defined&quot;</span><span class="p">)</span>
     1850                <span class="k">return</span>
     1851            <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">fxnobj</span><span class="p">,</span><span class="s">&#39;__call__&#39;</span><span class="p">):</span>
     1852                <span class="bp">self</span><span class="o">.</span><span class="n">lastError</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;Error: Not a function.&quot;</span><span class="p">,</span><span class="n">fxn</span><span class="p">,</span>
     1853                                  <span class="s">&quot;cannot be called as a function&quot;</span><span class="p">)</span>
     1854                <span class="k">return</span>
     1855            <span class="n">pkgdict</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">fxndict</span><span class="p">)</span>
     1856        <span class="k">return</span> <span class="n">varlist</span><span class="p">,</span><span class="n">pkgdict</span>
     1857
     1858<span class="c">#==========================================================================</span></div></div>
     1859<div class="viewcode-block" id="ExpressionCalcObj"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.ExpressionCalcObj">[docs]</a><span class="k">class</span> <span class="nc">ExpressionCalcObj</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
     1860    <span class="sd">&#39;&#39;&#39;An object used to evaluate an expression from a :class:`ExpressionObj`</span>
     1861<span class="sd">    object.</span>
     1862<span class="sd">    </span>
     1863<span class="sd">    :param ExpressionObj exprObj: a :class:`~ExpressionObj` expression object with</span>
     1864<span class="sd">      an expression string and mappings for the parameter labels in that object.</span>
     1865<span class="sd">    &#39;&#39;&#39;</span>
     1866    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">exprObj</span><span class="p">):</span>
     1867        <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span> <span class="o">=</span> <span class="n">exprObj</span>
     1868        <span class="s">&#39;The expression and mappings; a :class:`ExpressionObj` object&#39;</span>
     1869        <span class="bp">self</span><span class="o">.</span><span class="n">compiledExpr</span> <span class="o">=</span> <span class="bp">None</span>
     1870        <span class="s">&#39;The expression as compiled byte-code&#39;</span>
     1871        <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span> <span class="o">=</span> <span class="p">{}</span>
     1872        <span class="sd">&#39;&#39;&#39;dict that defines values for labels used in expression and packages</span>
     1873<span class="sd">        referenced by functions</span>
     1874<span class="sd">        &#39;&#39;&#39;</span>
     1875        <span class="bp">self</span><span class="o">.</span><span class="n">derivStep</span> <span class="o">=</span> <span class="p">{}</span>
     1876        <span class="sd">&#39;&#39;&#39;Contains step sizes for derivatives for variables used in the expression;</span>
     1877<span class="sd">        if a variable is not included in this the derivatives will be computed as zero</span>
     1878<span class="sd">        &#39;&#39;&#39;</span>
     1879        <span class="bp">self</span><span class="o">.</span><span class="n">lblLookup</span> <span class="o">=</span> <span class="p">{}</span>
     1880        <span class="sd">&#39;&#39;&#39;Lookup table that specifies the expression label name that is</span>
     1881<span class="sd">        tied to a particular GSAS-II parameters in the parmDict.</span>
     1882<span class="sd">        &#39;&#39;&#39;</span>
     1883        <span class="bp">self</span><span class="o">.</span><span class="n">fxnpkgdict</span> <span class="o">=</span> <span class="p">{}</span>
     1884        <span class="sd">&#39;&#39;&#39;a dict with references to packages needed to</span>
     1885<span class="sd">        find functions referenced in the expression.</span>
     1886<span class="sd">        &#39;&#39;&#39;</span>
     1887        <span class="bp">self</span><span class="o">.</span><span class="n">varLookup</span> <span class="o">=</span> <span class="p">{}</span>
     1888        <span class="sd">&#39;&#39;&#39;Lookup table that specifies the GSAS-II variable(s)</span>
     1889<span class="sd">        indexed by the expression label name. (Used for only for diagnostics</span>
     1890<span class="sd">        not evaluation of expression.)</span>
     1891<span class="sd">        &#39;&#39;&#39;</span>
     1892       
     1893<div class="viewcode-block" id="ExpressionCalcObj.SetupCalc"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.ExpressionCalcObj.SetupCalc">[docs]</a>    <span class="k">def</span> <span class="nf">SetupCalc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">parmDict</span><span class="p">):</span>
     1894        <span class="sd">&#39;&#39;&#39;Do all preparations to use the expression for computation.</span>
     1895<span class="sd">        Adds the free parameter values to the parameter dict (parmDict).</span>
     1896<span class="sd">        &#39;&#39;&#39;</span>
     1897        <span class="bp">self</span><span class="o">.</span><span class="n">fxnpkgdict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">CheckVars</span><span class="p">()</span>
     1898        <span class="c"># all is OK, compile the expression</span>
     1899        <span class="bp">self</span><span class="o">.</span><span class="n">compiledExpr</span> <span class="o">=</span> <span class="nb">compile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="s">&#39;eval&#39;</span><span class="p">)</span>
     1900
     1901        <span class="c"># look at first value in parmDict to determine its type</span>
     1902        <span class="n">parmsInList</span> <span class="o">=</span> <span class="bp">True</span>
     1903        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">parmDict</span><span class="p">:</span>
     1904            <span class="n">val</span> <span class="o">=</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
     1905            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
     1906                <span class="n">parmsInList</span> <span class="o">=</span> <span class="bp">False</span>
     1907                <span class="k">break</span>
     1908            <span class="k">try</span><span class="p">:</span> <span class="c"># check if values are in lists</span>
     1909                <span class="n">val</span> <span class="o">=</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
     1910            <span class="k">except</span> <span class="p">(</span><span class="ne">TypeError</span><span class="p">,</span><span class="ne">IndexError</span><span class="p">):</span>
     1911                <span class="n">parmsInList</span> <span class="o">=</span> <span class="bp">False</span>
     1912            <span class="k">break</span>
     1913           
     1914        <span class="c"># set up the dicts needed to speed computations</span>
     1915        <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span> <span class="o">=</span> <span class="p">{}</span>
     1916        <span class="bp">self</span><span class="o">.</span><span class="n">derivStep</span> <span class="o">=</span> <span class="p">{}</span>
     1917        <span class="bp">self</span><span class="o">.</span><span class="n">lblLookup</span> <span class="o">=</span> <span class="p">{}</span>
     1918        <span class="bp">self</span><span class="o">.</span><span class="n">varLookup</span> <span class="o">=</span> <span class="p">{}</span>
     1919        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">freeVars</span><span class="p">:</span>
     1920            <span class="n">varname</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
     1921            <span class="n">varname</span> <span class="o">=</span> <span class="s">&quot;::&quot;</span> <span class="o">+</span> <span class="n">varname</span><span class="o">.</span><span class="n">lstrip</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">,</span><span class="s">&#39;_&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">,</span><span class="s">&#39;;&#39;</span><span class="p">)</span>
     1922            <span class="bp">self</span><span class="o">.</span><span class="n">lblLookup</span><span class="p">[</span><span class="n">varname</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>
     1923            <span class="bp">self</span><span class="o">.</span><span class="n">varLookup</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="n">varname</span>
     1924            <span class="k">if</span> <span class="n">parmsInList</span><span class="p">:</span>
     1925                <span class="n">parmDict</span><span class="p">[</span><span class="n">varname</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span><span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">3</span><span class="p">]]</span>
     1926            <span class="k">else</span><span class="p">:</span>
     1927                <span class="n">parmDict</span><span class="p">[</span><span class="n">varname</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
     1928            <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
     1929            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">3</span><span class="p">]:</span>
     1930                <span class="bp">self</span><span class="o">.</span><span class="n">derivStep</span><span class="p">[</span><span class="n">varname</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">freeVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>
     1931        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">assgnVars</span><span class="p">:</span>
     1932            <span class="n">step</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">assgnVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
     1933            <span class="n">varname</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">assgnVars</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
     1934            <span class="k">if</span> <span class="s">&#39;*&#39;</span> <span class="ow">in</span> <span class="n">varname</span><span class="p">:</span>
     1935                <span class="n">varlist</span> <span class="o">=</span> <span class="n">LookupWildCard</span><span class="p">(</span><span class="n">varname</span><span class="p">,</span><span class="n">parmDict</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
     1936                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">varlist</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
     1937                    <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;No variables match &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
     1938                <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">varlist</span><span class="p">:</span>
     1939                    <span class="bp">self</span><span class="o">.</span><span class="n">lblLookup</span><span class="p">[</span><span class="n">var</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>
     1940                    <span class="bp">self</span><span class="o">.</span><span class="n">derivStep</span><span class="p">[</span><span class="n">var</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
     1941                        <span class="p">[</span><span class="n">step</span> <span class="k">if</span> <span class="n">var1</span> <span class="o">==</span> <span class="n">var</span> <span class="k">else</span> <span class="mi">0</span> <span class="k">for</span> <span class="n">var1</span> <span class="ow">in</span> <span class="n">varlist</span><span class="p">]</span>
     1942                        <span class="p">)</span>
     1943                <span class="k">if</span> <span class="n">parmsInList</span><span class="p">:</span>
     1944                    <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">parmDict</span><span class="p">[</span><span class="n">var</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">varlist</span><span class="p">])</span>
     1945                <span class="k">else</span><span class="p">:</span>
     1946                    <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">parmDict</span><span class="p">[</span><span class="n">var</span><span class="p">]</span> <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">varlist</span><span class="p">])</span>
     1947                <span class="bp">self</span><span class="o">.</span><span class="n">varLookup</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">var</span> <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">varlist</span><span class="p">]</span>
     1948            <span class="k">elif</span> <span class="n">varname</span> <span class="ow">in</span> <span class="n">parmDict</span><span class="p">:</span>
     1949                <span class="bp">self</span><span class="o">.</span><span class="n">lblLookup</span><span class="p">[</span><span class="n">varname</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>
     1950                <span class="bp">self</span><span class="o">.</span><span class="n">varLookup</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="n">varname</span>
     1951                <span class="k">if</span> <span class="n">parmsInList</span><span class="p">:</span>
     1952                    <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">varname</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
     1953                <span class="k">else</span><span class="p">:</span>
     1954                    <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">varname</span><span class="p">]</span>
     1955                <span class="bp">self</span><span class="o">.</span><span class="n">derivStep</span><span class="p">[</span><span class="n">varname</span><span class="p">]</span> <span class="o">=</span> <span class="n">step</span>
     1956            <span class="k">else</span><span class="p">:</span>
     1957                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;No value for variable &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
     1958        <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fxnpkgdict</span><span class="p">)</span>
     1959</div>
     1960<div class="viewcode-block" id="ExpressionCalcObj.EvalExpression"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.ExpressionCalcObj.EvalExpression">[docs]</a>    <span class="k">def</span> <span class="nf">EvalExpression</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
     1961        <span class="sd">&#39;&#39;&#39;Evaluate an expression. Note that the expression</span>
     1962<span class="sd">        and mapping are taken from the :class:`ExpressionObj` expression object</span>
     1963<span class="sd">        and the parameter values were specified in :meth:`SetupCalc`.</span>
     1964<span class="sd">        :returns: a single value for the expression. If parameter</span>
     1965<span class="sd">        values are arrays (for example, from wild-carded variable names),</span>
     1966<span class="sd">        the sum of the resulting expression is return.</span>
     1967
     1968<span class="sd">        For example, if the expression is ``&#39;A*B&#39;``,</span>
     1969<span class="sd">        where A is 2.0 and B maps to ``&#39;1::Afrac:*&#39;``, which evaluates to::</span>
     1970
     1971<span class="sd">        [0.5, 1, 0.5]</span>
     1972
     1973<span class="sd">        then the result will be ``4.0``.</span>
     1974<span class="sd">        &#39;&#39;&#39;</span>
     1975        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">compiledExpr</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
     1976            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;EvalExpression called before SetupCalc&quot;</span>
     1977        <span class="n">val</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">compiledExpr</span><span class="p">,</span><span class="nb">globals</span><span class="p">(),</span><span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">)</span>
     1978        <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">isscalar</span><span class="p">(</span><span class="n">val</span><span class="p">):</span>
     1979            <span class="n">val</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
     1980        <span class="k">return</span> <span class="n">val</span>
     1981</div>
     1982<div class="viewcode-block" id="ExpressionCalcObj.EvalDeriv"><a class="viewcode-back" href="../GSASIIobj.html#GSASIIobj.ExpressionCalcObj.EvalDeriv">[docs]</a>    <span class="k">def</span> <span class="nf">EvalDeriv</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">varname</span><span class="p">):</span>
     1983        <span class="sd">&#39;&#39;&#39;Evaluate the expression derivative with respect to a</span>
     1984<span class="sd">        GSAS-II variable name. </span>
     1985
     1986<span class="sd">        :param str varname: a G2 variable name (will not have a wild-card)</span>
     1987<span class="sd">        :returns: the derivative</span>
     1988<span class="sd">        &#39;&#39;&#39;</span>
     1989        <span class="k">if</span> <span class="n">varname</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">derivStep</span><span class="p">:</span> <span class="k">return</span> <span class="mf">0.0</span>
     1990        <span class="k">if</span> <span class="n">varname</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">lblLookup</span><span class="p">:</span> <span class="k">return</span> <span class="mf">0.0</span>
     1991        <span class="n">step</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">derivStep</span><span class="p">[</span><span class="n">varname</span><span class="p">]</span>
     1992        <span class="n">lbl</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lblLookup</span><span class="p">[</span><span class="n">varname</span><span class="p">]</span> <span class="c"># what label does this map to in expression?</span>
     1993        <span class="n">origval</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">[</span><span class="n">lbl</span><span class="p">]</span>
     1994
     1995        <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">[</span><span class="n">lbl</span><span class="p">]</span> <span class="o">=</span> <span class="n">origval</span> <span class="o">+</span> <span class="n">step</span>
     1996        <span class="n">val1</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">compiledExpr</span><span class="p">,</span><span class="nb">globals</span><span class="p">(),</span><span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">)</span>
     1997
     1998        <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">[</span><span class="n">lbl</span><span class="p">]</span> <span class="o">=</span> <span class="n">origval</span> <span class="o">-</span> <span class="n">step</span>
     1999        <span class="n">val2</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">compiledExpr</span><span class="p">,</span><span class="nb">globals</span><span class="p">(),</span><span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">)</span>
     2000
     2001        <span class="bp">self</span><span class="o">.</span><span class="n">exprDict</span><span class="p">[</span><span class="n">lbl</span><span class="p">]</span> <span class="o">=</span> <span class="n">origval</span> <span class="c"># reset back to central value</span>
     2002
     2003        <span class="n">val</span> <span class="o">=</span> <span class="p">(</span><span class="n">val1</span> <span class="o">-</span> <span class="n">val2</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="mf">2.</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">step</span><span class="p">))</span>
     2004        <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">isscalar</span><span class="p">(</span><span class="n">val</span><span class="p">):</span>
     2005            <span class="n">val</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
     2006        <span class="k">return</span> <span class="n">val</span>
     2007</div></div>
     2008<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;__main__&quot;</span><span class="p">:</span>
     2009    <span class="c"># test equation evaluation</span>
     2010    <span class="k">def</span> <span class="nf">showEQ</span><span class="p">(</span><span class="n">calcobj</span><span class="p">):</span>
     2011        <span class="k">print</span> <span class="mi">50</span><span class="o">*</span><span class="s">&#39;=&#39;</span>
     2012        <span class="k">print</span> <span class="n">calcobj</span><span class="o">.</span><span class="n">eObj</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span><span class="s">&#39;=&#39;</span><span class="p">,</span><span class="n">calcobj</span><span class="o">.</span><span class="n">EvalExpression</span><span class="p">()</span>
     2013        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">calcobj</span><span class="o">.</span><span class="n">varLookup</span><span class="p">):</span>
     2014            <span class="k">print</span> <span class="s">&quot;  &quot;</span><span class="p">,</span><span class="n">v</span><span class="p">,</span><span class="s">&#39;=&#39;</span><span class="p">,</span><span class="n">calcobj</span><span class="o">.</span><span class="n">exprDict</span><span class="p">[</span><span class="n">v</span><span class="p">],</span><span class="s">&#39;=&#39;</span><span class="p">,</span><span class="n">calcobj</span><span class="o">.</span><span class="n">varLookup</span><span class="p">[</span><span class="n">v</span><span class="p">]</span>
     2015        <span class="k">print</span> <span class="s">&#39;  Derivatives&#39;</span>
     2016        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">calcobj</span><span class="o">.</span><span class="n">derivStep</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
     2017            <span class="k">print</span> <span class="s">&#39;    d(Expr)/d(&#39;</span><span class="o">+</span><span class="n">v</span><span class="o">+</span><span class="s">&#39;) =&#39;</span><span class="p">,</span><span class="n">calcobj</span><span class="o">.</span><span class="n">EvalDeriv</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
     2018
     2019    <span class="n">obj</span> <span class="o">=</span> <span class="n">ExpressionObj</span><span class="p">()</span>
     2020
     2021    <span class="n">obj</span><span class="o">.</span><span class="n">expression</span> <span class="o">=</span> <span class="s">&quot;A*np.exp(B)&quot;</span>
     2022    <span class="n">obj</span><span class="o">.</span><span class="n">assgnVars</span> <span class="o">=</span>  <span class="p">{</span><span class="s">&#39;B&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">&#39;0::Afrac:1&#39;</span><span class="p">,</span> <span class="mf">0.0001</span><span class="p">]}</span>
     2023    <span class="n">obj</span><span class="o">.</span><span class="n">freeVars</span> <span class="o">=</span>  <span class="p">{</span><span class="s">&#39;A&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">u&#39;A&#39;</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.0001</span><span class="p">,</span> <span class="bp">True</span><span class="p">]}</span>
     2024    <span class="c">#obj.CheckVars()</span>
     2025    <span class="n">parmDict2</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;0::Afrac:0&#39;</span><span class="p">:[</span><span class="mf">0.0</span><span class="p">,</span><span class="bp">True</span><span class="p">],</span> <span class="s">&#39;0::Afrac:1&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span><span class="bp">False</span><span class="p">]}</span>
     2026    <span class="n">calcobj</span> <span class="o">=</span> <span class="n">ExpressionCalcObj</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
     2027    <span class="n">calcobj</span><span class="o">.</span><span class="n">SetupCalc</span><span class="p">(</span><span class="n">parmDict2</span><span class="p">)</span>
     2028    <span class="n">showEQ</span><span class="p">(</span><span class="n">calcobj</span><span class="p">)</span>
     2029
     2030    <span class="n">obj</span><span class="o">.</span><span class="n">expression</span> <span class="o">=</span> <span class="s">&quot;A*np.exp(B)&quot;</span>
     2031    <span class="n">obj</span><span class="o">.</span><span class="n">assgnVars</span> <span class="o">=</span>  <span class="p">{</span><span class="s">&#39;B&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">&#39;0::Afrac:*&#39;</span><span class="p">,</span> <span class="mf">0.0001</span><span class="p">]}</span>
     2032    <span class="n">obj</span><span class="o">.</span><span class="n">freeVars</span> <span class="o">=</span>  <span class="p">{</span><span class="s">&#39;A&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">u&#39;Free Prm A&#39;</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.0001</span><span class="p">,</span> <span class="bp">True</span><span class="p">]}</span>
     2033    <span class="c">#obj.CheckVars()</span>
     2034    <span class="n">parmDict1</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;0::Afrac:0&#39;</span><span class="p">:</span><span class="mf">1.0</span><span class="p">,</span> <span class="s">&#39;0::Afrac:1&#39;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">}</span>
     2035    <span class="n">calcobj</span> <span class="o">=</span> <span class="n">ExpressionCalcObj</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
     2036    <span class="n">calcobj</span><span class="o">.</span><span class="n">SetupCalc</span><span class="p">(</span><span class="n">parmDict1</span><span class="p">)</span>
     2037    <span class="n">showEQ</span><span class="p">(</span><span class="n">calcobj</span><span class="p">)</span>
     2038
     2039    <span class="n">calcobj</span><span class="o">.</span><span class="n">SetupCalc</span><span class="p">(</span><span class="n">parmDict2</span><span class="p">)</span>
     2040    <span class="n">showEQ</span><span class="p">(</span><span class="n">calcobj</span><span class="p">)</span>
     2041</pre></div>
    14132042
    14142043          </div>
Note: See TracChangeset for help on using the changeset viewer.