Ignore:
Timestamp:
Dec 16, 2013 10:43:01 AM (9 years ago)
Author:
toby
Message:

update imports to provide error messages

File:
1 edited

Legend:

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

    r1129 r1168  
    5757<span class="sd">&#39;&#39;&#39;</span>
    5858<span class="c">########### SVN repository information ###################</span>
    59 <span class="c"># $Date: 2013-10-15 15:01:21 -0500 (Tue, 15 Oct 2013) $</span>
     59<span class="c"># $Date: 2013-11-07 12:47:17 -0600 (Thu, 07 Nov 2013) $</span>
    6060<span class="c"># $Author: vondreele $</span>
    61 <span class="c"># $Revision: 1107 $</span>
    62 <span class="c"># $URL: https://subversion.xray.aps.anl.gov/pyGSAS/trunk/GSASIIstrMath.py $</span>
    63 <span class="c"># $Id: GSASIIstrMath.py 1107 2013-10-15 20:01:21Z vondreele $</span>
     61<span class="c"># $Revision: 1140 $</span>
     62<span class="c"># $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/GSASIIstrMath.py $</span>
     63<span class="c"># $Id: GSASIIstrMath.py 1140 2013-11-07 18:47:17Z vondreele $</span>
    6464<span class="c">########### SVN repository information ###################</span>
    6565<span class="kn">import</span> <span class="nn">time</span>
     
    7272<span class="kn">import</span> <span class="nn">scipy.stats</span> <span class="kn">as</span> <span class="nn">st</span>
    7373<span class="kn">import</span> <span class="nn">GSASIIpath</span>
    74 <span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1107 $&quot;</span><span class="p">)</span>
     74<span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1140 $&quot;</span><span class="p">)</span>
    7575<span class="kn">import</span> <span class="nn">GSASIIElem</span> <span class="kn">as</span> <span class="nn">G2el</span>
    7676<span class="kn">import</span> <span class="nn">GSASIIlattice</span> <span class="kn">as</span> <span class="nn">G2lat</span>
     
    587587<span class="sd">    :param dict refDict: where</span>
    588588<span class="sd">        &#39;RefList&#39; list where each ref = h,k,l,m,d,...</span>
    589 <span class="sd">        &#39;Uniq&#39; list of [equiv h,k,l]</span>
    590 <span class="sd">        &#39;Phi&#39; list of phase[equiv]</span>
    591589<span class="sd">        &#39;FF&#39; dict of form factors - filed in below</span>
    592590<span class="sd">    :param np.array G:      reciprocal metric tensor</span>
     
    602600    <span class="n">ast</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">diag</span><span class="p">(</span><span class="n">G</span><span class="p">))</span>
    603601    <span class="n">Mast</span> <span class="o">=</span> <span class="n">twopisq</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">multiply</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">ast</span><span class="p">,</span><span class="n">ast</span><span class="p">)</span>
     602    <span class="n">SGMT</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">ops</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">T</span> <span class="k">for</span> <span class="n">ops</span> <span class="ow">in</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGOps&#39;</span><span class="p">]])</span>
     603    <span class="n">SGT</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">ops</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">ops</span> <span class="ow">in</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGOps&#39;</span><span class="p">]])</span>
    604604    <span class="n">FFtables</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;FFtables&#39;</span><span class="p">]</span>
    605605    <span class="n">BLtables</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;BLtables&#39;</span><span class="p">]</span>
     
    613613    <span class="n">Uij</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">G2lat</span><span class="o">.</span><span class="n">U6toUij</span><span class="p">(</span><span class="n">Uijdata</span><span class="p">))</span>
    614614    <span class="n">bij</span> <span class="o">=</span> <span class="n">Mast</span><span class="o">*</span><span class="n">Uij</span><span class="o">.</span><span class="n">T</span>
     615    <span class="k">if</span> <span class="ow">not</span> <span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">]):</span>
     616        <span class="k">if</span> <span class="s">&#39;N&#39;</span> <span class="ow">in</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;histType&#39;</span><span class="p">]:</span>
     617            <span class="n">dat</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getBLvalues</span><span class="p">(</span><span class="n">BLtables</span><span class="p">)</span>
     618        <span class="k">else</span><span class="p">:</span>
     619            <span class="n">dat</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getFFvalues</span><span class="p">(</span><span class="n">FFtables</span><span class="p">,</span><span class="mf">0.</span><span class="p">)</span>       
     620        <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;El&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dat</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
     621        <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;FF&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]),</span><span class="nb">len</span><span class="p">(</span><span class="n">dat</span><span class="p">)))</span>   
    615622    <span class="k">for</span> <span class="n">iref</span><span class="p">,</span><span class="n">refl</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]):</span>
    616623        <span class="n">fbs</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="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
     
    619626        <span class="n">SQfactor</span> <span class="o">=</span> <span class="mf">4.0</span><span class="o">*</span><span class="n">SQ</span><span class="o">*</span><span class="n">twopisq</span>
    620627        <span class="n">Bab</span> <span class="o">=</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabA&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabU&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">SQfactor</span><span class="p">)</span>
    621         <span class="k">if</span> <span class="ow">not</span> <span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]):</span>                <span class="c">#no form factors</span>
     628        <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]):</span>                <span class="c">#no form factors - 1st time thru StructureFactor</span>
    622629            <span class="k">if</span> <span class="s">&#39;N&#39;</span> <span class="ow">in</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;histType&#39;</span><span class="p">]:</span>
    623                 <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getBLvalues</span><span class="p">(</span><span class="n">BLtables</span><span class="p">)</span>
     630                <span class="n">dat</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getBLvalues</span><span class="p">(</span><span class="n">BLtables</span><span class="p">)</span>
     631                <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">dat</span><span class="o">.</span><span class="n">values</span><span class="p">()</span>
    624632            <span class="k">else</span><span class="p">:</span>       <span class="c">#&#39;X&#39;</span>
    625                 <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getFFvalues</span><span class="p">(</span><span class="n">FFtables</span><span class="p">,</span><span class="n">SQ</span><span class="p">)</span>
    626         <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">El</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">Tdata</span><span class="p">):</span>
    627             <span class="n">FF</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">][</span><span class="n">El</span><span class="p">]</span>           
    628         <span class="n">phase</span> <span class="o">=</span> <span class="n">twopi</span><span class="o">*</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">],(</span><span class="n">dXdata</span><span class="o">.</span><span class="n">T</span><span class="o">+</span><span class="n">Xdata</span><span class="o">.</span><span class="n">T</span><span class="p">))</span><span class="o">+</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Phi&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">][:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">])</span>
     633                <span class="n">dat</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getFFvalues</span><span class="p">(</span><span class="n">FFtables</span><span class="p">,</span><span class="n">SQ</span><span class="p">)</span>
     634                <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">dat</span><span class="o">.</span><span class="n">values</span><span class="p">()</span>
     635        <span class="n">Tindx</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">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;El&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">El</span><span class="p">)</span> <span class="k">for</span> <span class="n">El</span> <span class="ow">in</span> <span class="n">Tdata</span><span class="p">])</span>
     636        <span class="n">FF</span> <span class="o">=</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">][</span><span class="n">Tindx</span><span class="p">]</span>
     637        <span class="n">Uniq</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">SGMT</span><span class="p">)</span>
     638        <span class="n">Phi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">SGT</span><span class="p">)</span>
     639        <span class="n">phase</span> <span class="o">=</span> <span class="n">twopi</span><span class="o">*</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">Uniq</span><span class="p">,(</span><span class="n">dXdata</span><span class="o">.</span><span class="n">T</span><span class="o">+</span><span class="n">Xdata</span><span class="o">.</span><span class="n">T</span><span class="p">))</span><span class="o">+</span><span class="n">Phi</span><span class="p">[:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">])</span>
    629640        <span class="n">sinp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">phase</span><span class="p">)</span>
    630641        <span class="n">cosp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">phase</span><span class="p">)</span>
    631         <span class="n">occ</span> <span class="o">=</span> <span class="n">Mdata</span><span class="o">*</span><span class="n">Fdata</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">])</span>
    632642        <span class="n">biso</span> <span class="o">=</span> <span class="o">-</span><span class="n">SQfactor</span><span class="o">*</span><span class="n">Uisodata</span>
    633643        <span class="n">Tiso</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">biso</span><span class="o">&lt;</span><span class="mf">1.</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">biso</span><span class="p">),</span><span class="mf">1.0</span><span class="p">)</span>
    634         <span class="n">HbH</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="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">bij</span><span class="p">,</span><span class="n">h</span><span class="p">))</span> <span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]])</span>
     644        <span class="n">HbH</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="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">bij</span><span class="p">,</span><span class="n">h</span><span class="p">))</span> <span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">Uniq</span><span class="p">])</span>
    635645        <span class="n">Tuij</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">HbH</span><span class="o">&lt;</span><span class="mf">1.</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">HbH</span><span class="p">),</span><span class="mf">1.0</span><span class="p">)</span>
    636         <span class="n">Tcorr</span> <span class="o">=</span> <span class="n">Tiso</span><span class="o">*</span><span class="n">Tuij</span>
    637         <span class="n">fa</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">FF</span><span class="o">+</span><span class="n">FP</span><span class="o">-</span><span class="n">Bab</span><span class="p">)</span><span class="o">*</span><span class="n">occ</span><span class="o">*</span><span class="n">cosp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">,</span><span class="o">-</span><span class="n">FPP</span><span class="o">*</span><span class="n">occ</span><span class="o">*</span><span class="n">sinp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">])</span>
     646        <span class="n">Tcorr</span> <span class="o">=</span> <span class="n">Tiso</span><span class="o">*</span><span class="n">Tuij</span><span class="o">*</span><span class="n">Mdata</span><span class="o">*</span><span class="n">Fdata</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">Uniq</span><span class="p">)</span>
     647        <span class="n">fa</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">FF</span><span class="o">+</span><span class="n">FP</span><span class="o">-</span><span class="n">Bab</span><span class="p">)</span><span class="o">*</span><span class="n">cosp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">,</span><span class="o">-</span><span class="n">FPP</span><span class="o">*</span><span class="n">sinp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">])</span>
    638648        <span class="n">fas</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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">fa</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>        <span class="c">#real</span>
    639649        <span class="k">if</span> <span class="ow">not</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGInv&#39;</span><span class="p">]:</span>
    640             <span class="n">fb</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">FF</span><span class="o">+</span><span class="n">FP</span><span class="o">-</span><span class="n">Bab</span><span class="p">)</span><span class="o">*</span><span class="n">occ</span><span class="o">*</span><span class="n">sinp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">,</span><span class="n">FPP</span><span class="o">*</span><span class="n">occ</span><span class="o">*</span><span class="n">cosp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">])</span>
     650            <span class="n">fb</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">FF</span><span class="o">+</span><span class="n">FP</span><span class="o">-</span><span class="n">Bab</span><span class="p">)</span><span class="o">*</span><span class="n">sinp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">,</span><span class="n">FPP</span><span class="o">*</span><span class="n">cosp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">])</span>
    641651            <span class="n">fbs</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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">fb</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
    642652        <span class="n">fasq</span> <span class="o">=</span> <span class="n">fas</span><span class="o">**</span><span class="mi">2</span>
     
    652662<span class="sd">    :param dict refDict: where</span>
    653663<span class="sd">        &#39;RefList&#39; list where each ref = h,k,l,m,d,...</span>
    654 <span class="sd">        &#39;Uniq&#39; list of [equiv h,k,l]</span>
    655 <span class="sd">        &#39;Phi&#39; list of phase[equiv]</span>
    656664<span class="sd">        &#39;FF&#39; dict of form factors - filed in below</span>
    657665<span class="sd">    :param np.array G:      reciprocal metric tensor</span>
     
    667675    <span class="n">ast</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">diag</span><span class="p">(</span><span class="n">G</span><span class="p">))</span>
    668676    <span class="n">Mast</span> <span class="o">=</span> <span class="n">twopisq</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">multiply</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">ast</span><span class="p">,</span><span class="n">ast</span><span class="p">)</span>
     677    <span class="n">SGMT</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">ops</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">T</span> <span class="k">for</span> <span class="n">ops</span> <span class="ow">in</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGOps&#39;</span><span class="p">]])</span>
     678    <span class="n">SGT</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">ops</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">ops</span> <span class="ow">in</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGOps&#39;</span><span class="p">]])</span>
    669679    <span class="n">FFtables</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;FFtables&#39;</span><span class="p">]</span>
    670680    <span class="n">BLtables</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;BLtables&#39;</span><span class="p">]</span>
     
    678688    <span class="n">Uij</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">G2lat</span><span class="o">.</span><span class="n">U6toUij</span><span class="p">(</span><span class="n">Uijdata</span><span class="p">))</span>
    679689    <span class="n">bij</span> <span class="o">=</span> <span class="n">Mast</span><span class="o">*</span><span class="n">Uij</span><span class="o">.</span><span class="n">T</span>
    680     <span class="k">for</span> <span class="n">iref</span><span class="p">,</span><span class="n">refl</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]):</span>
    681         <span class="n">fbs</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="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
    682         <span class="n">H</span> <span class="o">=</span> <span class="n">refl</span><span class="p">[:</span><span class="mi">3</span><span class="p">]</span>
    683         <span class="n">SQ</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="p">(</span><span class="mf">2.</span><span class="o">*</span><span class="n">refl</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>
     690    <span class="n">blkSize</span> <span class="o">=</span> <span class="mi">100</span>       <span class="c">#no. of reflections in a block</span>
     691    <span class="n">nRef</span> <span class="o">=</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
     692    <span class="k">if</span> <span class="ow">not</span> <span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">]):</span>                <span class="c">#no form factors - 1st time thru StructureFactor</span>
     693        <span class="k">if</span> <span class="s">&#39;N&#39;</span> <span class="ow">in</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;histType&#39;</span><span class="p">]:</span>
     694            <span class="n">dat</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getBLvalues</span><span class="p">(</span><span class="n">BLtables</span><span class="p">)</span>
     695            <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;El&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dat</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
     696            <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;FF&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="n">nRef</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">dat</span><span class="p">)))</span><span class="o">*</span><span class="n">dat</span><span class="o">.</span><span class="n">values</span><span class="p">()</span>           
     697        <span class="k">else</span><span class="p">:</span>       <span class="c">#&#39;X&#39;</span>
     698            <span class="n">dat</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getFFvalues</span><span class="p">(</span><span class="n">FFtables</span><span class="p">,</span><span class="mf">0.</span><span class="p">)</span>
     699            <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;El&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dat</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
     700            <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;FF&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="n">nRef</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">dat</span><span class="p">)))</span>
     701            <span class="k">for</span> <span class="n">iref</span><span class="p">,</span><span class="n">ref</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]):</span>
     702                <span class="n">SQ</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="p">(</span><span class="mf">2.</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>
     703                <span class="n">dat</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getFFvalues</span><span class="p">(</span><span class="n">FFtables</span><span class="p">,</span><span class="n">SQ</span><span class="p">)</span>
     704                <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">*=</span> <span class="n">dat</span><span class="o">.</span><span class="n">values</span><span class="p">()</span>
     705<span class="c">#reflection processing begins here - big arrays!</span>
     706    <span class="n">iBeg</span> <span class="o">=</span> <span class="mi">0</span>           
     707    <span class="k">while</span> <span class="n">iBeg</span> <span class="o">&lt;</span> <span class="n">nRef</span><span class="p">:</span>
     708        <span class="n">iFin</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">iBeg</span><span class="o">+</span><span class="n">blkSize</span><span class="p">,</span><span class="n">nRef</span><span class="p">)</span>
     709        <span class="n">refl</span> <span class="o">=</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">][</span><span class="n">iBeg</span><span class="p">:</span><span class="n">iFin</span><span class="p">]</span>
     710        <span class="n">H</span> <span class="o">=</span> <span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[:</span><span class="mi">3</span><span class="p">]</span>
     711        <span class="n">SQ</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="p">(</span><span class="mf">2.</span><span class="o">*</span><span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>
    684712        <span class="n">SQfactor</span> <span class="o">=</span> <span class="mf">4.0</span><span class="o">*</span><span class="n">SQ</span><span class="o">*</span><span class="n">twopisq</span>
    685         <span class="n">Bab</span> <span class="o">=</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabA&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabU&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">SQfactor</span><span class="p">)</span>
    686         <span class="k">if</span> <span class="ow">not</span> <span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]):</span>                <span class="c">#no form factors</span>
    687             <span class="k">if</span> <span class="s">&#39;N&#39;</span> <span class="ow">in</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;histType&#39;</span><span class="p">]:</span>
    688                 <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getBLvalues</span><span class="p">(</span><span class="n">BLtables</span><span class="p">)</span>
    689             <span class="k">else</span><span class="p">:</span>       <span class="c">#&#39;X&#39;</span>
    690                 <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">getFFvalues</span><span class="p">(</span><span class="n">FFtables</span><span class="p">,</span><span class="n">SQ</span><span class="p">)</span>
    691         <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">El</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">Tdata</span><span class="p">):</span>
    692             <span class="n">FF</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">][</span><span class="n">El</span><span class="p">]</span>           
    693         <span class="n">phase</span> <span class="o">=</span> <span class="n">twopi</span><span class="o">*</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">],(</span><span class="n">dXdata</span><span class="o">.</span><span class="n">T</span><span class="o">+</span><span class="n">Xdata</span><span class="o">.</span><span class="n">T</span><span class="p">))</span><span class="o">+</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Phi&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">][:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">])</span>
     713        <span class="n">Bab</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabA&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabU&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">SQfactor</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">SGT</span><span class="p">))</span>
     714        <span class="n">Tindx</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">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;El&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">El</span><span class="p">)</span> <span class="k">for</span> <span class="n">El</span> <span class="ow">in</span> <span class="n">Tdata</span><span class="p">])</span>
     715        <span class="n">FF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iBeg</span><span class="p">:</span><span class="n">iFin</span><span class="p">]</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="n">Tindx</span><span class="p">]</span><span class="o">.</span><span class="n">T</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">SGT</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
     716        <span class="n">Uniq</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">H</span><span class="o">.</span><span class="n">T</span><span class="p">,</span><span class="n">SGMT</span><span class="p">),(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
     717        <span class="n">Phi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">H</span><span class="o">.</span><span class="n">T</span><span class="p">,</span><span class="n">SGT</span><span class="p">)</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
     718        <span class="n">phase</span> <span class="o">=</span> <span class="n">twopi</span><span class="o">*</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">Uniq</span><span class="p">,(</span><span class="n">dXdata</span><span class="o">+</span><span class="n">Xdata</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="p">)</span><span class="o">+</span><span class="n">Phi</span><span class="p">[:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">])</span>
    694719        <span class="n">sinp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">phase</span><span class="p">)</span>
    695720        <span class="n">cosp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">phase</span><span class="p">)</span>
    696         <span class="n">occ</span> <span class="o">=</span> <span class="n">Mdata</span><span class="o">*</span><span class="n">Fdata</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">])</span>
    697         <span class="n">biso</span> <span class="o">=</span> <span class="o">-</span><span class="n">SQfactor</span><span class="o">*</span><span class="n">Uisodata</span>
    698         <span class="n">Tiso</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">biso</span><span class="o">&lt;</span><span class="mf">1.</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">biso</span><span class="p">),</span><span class="mf">1.0</span><span class="p">)</span>
    699         <span class="n">HbH</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="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">bij</span><span class="p">,</span><span class="n">h</span><span class="p">))</span> <span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]])</span>
    700         <span class="n">Tuij</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">HbH</span><span class="o">&lt;</span><span class="mf">1.</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">HbH</span><span class="p">),</span><span class="mf">1.0</span><span class="p">)</span>
    701         <span class="n">Tcorr</span> <span class="o">=</span> <span class="n">Tiso</span><span class="o">*</span><span class="n">Tuij</span>
    702         <span class="n">fa</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">FF</span><span class="o">+</span><span class="n">FP</span><span class="o">-</span><span class="n">Bab</span><span class="p">)</span><span class="o">*</span><span class="n">occ</span><span class="o">*</span><span class="n">cosp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">,</span><span class="o">-</span><span class="n">FPP</span><span class="o">*</span><span class="n">occ</span><span class="o">*</span><span class="n">sinp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">])</span>
    703         <span class="n">fas</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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">fa</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>        <span class="c">#real</span>
     721        <span class="n">biso</span> <span class="o">=</span> <span class="o">-</span><span class="n">SQfactor</span><span class="o">*</span><span class="n">Uisodata</span><span class="p">[:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">]</span>
     722        <span class="n">Tiso</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">biso</span><span class="o">&lt;</span><span class="mf">1.</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">biso</span><span class="p">),</span><span class="mf">1.0</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">SGT</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
     723        <span class="n">HbH</span> <span class="o">=</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">Uniq</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">bij</span><span class="p">,</span><span class="n">Uniq</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     724        <span class="n">Tuij</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">HbH</span><span class="o">&lt;</span><span class="mf">1.</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">HbH</span><span class="p">),</span><span class="mf">1.0</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
     725        <span class="n">Tcorr</span> <span class="o">=</span> <span class="n">Tiso</span><span class="o">*</span><span class="n">Tuij</span><span class="o">*</span><span class="n">Mdata</span><span class="o">*</span><span class="n">Fdata</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">SGMT</span><span class="p">)</span>
     726        <span class="n">fa</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">FF</span><span class="o">+</span><span class="n">FP</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="o">-</span><span class="n">Bab</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">cosp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">,</span><span class="o">-</span><span class="n">FPP</span><span class="o">*</span><span class="n">sinp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">])</span>
     727        <span class="n">fa</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">fa</span><span class="p">,(</span><span class="mi">2</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">refl</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">SGT</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">Mdata</span><span class="p">)))</span>
     728        <span class="n">fas</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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">fa</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>        <span class="c">#real</span>
     729        <span class="n">fbs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros_like</span><span class="p">(</span><span class="n">fas</span><span class="p">)</span>
    704730        <span class="k">if</span> <span class="ow">not</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGInv&#39;</span><span class="p">]:</span>
    705             <span class="n">fb</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">FF</span><span class="o">+</span><span class="n">FP</span><span class="o">-</span><span class="n">Bab</span><span class="p">)</span><span class="o">*</span><span class="n">occ</span><span class="o">*</span><span class="n">sinp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">,</span><span class="n">FPP</span><span class="o">*</span><span class="n">occ</span><span class="o">*</span><span class="n">cosp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">])</span>
    706             <span class="n">fbs</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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">fb</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     731            <span class="n">fb</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">FF</span><span class="o">+</span><span class="n">FP</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="o">-</span><span class="n">Bab</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">sinp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">,</span><span class="n">FPP</span><span class="o">*</span><span class="n">cosp</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">])</span>
     732            <span class="n">fb</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">fb</span><span class="p">,(</span><span class="mi">2</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">refl</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">SGT</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">Mdata</span><span class="p">)))</span>
     733            <span class="n">fbs</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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">fb</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    707734        <span class="n">fasq</span> <span class="o">=</span> <span class="n">fas</span><span class="o">**</span><span class="mi">2</span>
    708735        <span class="n">fbsq</span> <span class="o">=</span> <span class="n">fbs</span><span class="o">**</span><span class="mi">2</span>        <span class="c">#imaginary</span>
    709         <span class="n">refl</span><span class="p">[</span><span class="mi">9</span><span class="p">]</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">fasq</span><span class="p">)</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">fbsq</span><span class="p">)</span>
    710         <span class="n">refl</span><span class="p">[</span><span class="mi">10</span><span class="p">]</span> <span class="o">=</span> <span class="n">atan2d</span><span class="p">(</span><span class="n">fbs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fas</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
     736        <span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">9</span><span class="p">]</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">fasq</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</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">fbsq</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
     737        <span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">10</span><span class="p">]</span> <span class="o">=</span> <span class="n">atan2d</span><span class="p">(</span><span class="n">fbs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fas</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
     738        <span class="n">iBeg</span> <span class="o">+=</span> <span class="n">blkSize</span>
    711739    </div>
    712740<div class="viewcode-block" id="StructureFactorDerv"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.StructureFactorDerv">[docs]</a><span class="k">def</span> <span class="nf">StructureFactorDerv</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">):</span>
     
    717745    <span class="n">ast</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">diag</span><span class="p">(</span><span class="n">G</span><span class="p">))</span>
    718746    <span class="n">Mast</span> <span class="o">=</span> <span class="n">twopisq</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">multiply</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">ast</span><span class="p">,</span><span class="n">ast</span><span class="p">)</span>
     747    <span class="n">SGMT</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">ops</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">T</span> <span class="k">for</span> <span class="n">ops</span> <span class="ow">in</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGOps&#39;</span><span class="p">]])</span>
     748    <span class="n">SGT</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">ops</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">ops</span> <span class="ow">in</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGOps&#39;</span><span class="p">]])</span>
    719749    <span class="n">FFtables</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;FFtables&#39;</span><span class="p">]</span>
    720750    <span class="n">BLtables</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;BLtables&#39;</span><span class="p">]</span>
     751    <span class="n">nRef</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">])</span>
    721752    <span class="n">Tdata</span><span class="p">,</span><span class="n">Mdata</span><span class="p">,</span><span class="n">Fdata</span><span class="p">,</span><span class="n">Xdata</span><span class="p">,</span><span class="n">dXdata</span><span class="p">,</span><span class="n">IAdata</span><span class="p">,</span><span class="n">Uisodata</span><span class="p">,</span><span class="n">Uijdata</span> <span class="o">=</span> <span class="n">GetAtomFXU</span><span class="p">(</span><span class="n">pfx</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
     753    <span class="n">mSize</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">Mdata</span><span class="p">)</span>
    722754    <span class="n">FF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">Tdata</span><span class="p">))</span>
    723755    <span class="k">if</span> <span class="s">&#39;N&#39;</span> <span class="ow">in</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;histType&#39;</span><span class="p">]:</span>
    724         <span class="n">FP</span> <span class="o">=</span> <span class="mf">0.</span>
    725         <span class="n">FPP</span> <span class="o">=</span> <span class="mf">0.</span>
     756        <span class="n">FP</span><span class="p">,</span><span class="n">FPP</span> <span class="o">=</span> <span class="n">G2el</span><span class="o">.</span><span class="n">BlenRes</span><span class="p">(</span><span class="n">Tdata</span><span class="p">,</span><span class="n">BLtables</span><span class="p">,</span><span class="n">parmDict</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;Lam&#39;</span><span class="p">])</span>
    726757    <span class="k">else</span><span class="p">:</span>
    727758        <span class="n">FP</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">FFtables</span><span class="p">[</span><span class="n">El</span><span class="p">][</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;FP&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">El</span> <span class="ow">in</span> <span class="n">Tdata</span><span class="p">])</span>
     
    730761    <span class="n">bij</span> <span class="o">=</span> <span class="n">Mast</span><span class="o">*</span><span class="n">Uij</span><span class="o">.</span><span class="n">T</span>
    731762    <span class="n">dFdvDict</span> <span class="o">=</span> <span class="p">{}</span>
    732     <span class="n">dFdfr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]),</span><span class="nb">len</span><span class="p">(</span><span class="n">Mdata</span><span class="p">)))</span>
    733     <span class="n">dFdx</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]),</span><span class="nb">len</span><span class="p">(</span><span class="n">Mdata</span><span class="p">),</span><span class="mi">3</span><span class="p">))</span>
    734     <span class="n">dFdui</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]),</span><span class="nb">len</span><span class="p">(</span><span class="n">Mdata</span><span class="p">)))</span>
    735     <span class="n">dFdua</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]),</span><span class="nb">len</span><span class="p">(</span><span class="n">Mdata</span><span class="p">),</span><span class="mi">6</span><span class="p">))</span>
    736     <span class="n">dFdbab</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]),</span><span class="mi">2</span><span class="p">))</span>
     763    <span class="n">dFdfr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nRef</span><span class="p">,</span><span class="n">mSize</span><span class="p">))</span>
     764    <span class="n">dFdx</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nRef</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
     765    <span class="n">dFdui</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nRef</span><span class="p">,</span><span class="n">mSize</span><span class="p">))</span>
     766    <span class="n">dFdua</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nRef</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span>
     767    <span class="n">dFdbab</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nRef</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>
    737768    <span class="k">for</span> <span class="n">iref</span><span class="p">,</span><span class="n">refl</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]):</span>
    738769        <span class="n">H</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">refl</span><span class="p">[:</span><span class="mi">3</span><span class="p">])</span>
     
    741772        <span class="n">dBabdA</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabU&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">SQfactor</span><span class="p">)</span>
    742773        <span class="n">Bab</span> <span class="o">=</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabA&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">dBabdA</span>
    743         <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">El</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">Tdata</span><span class="p">):</span>           
    744             <span class="n">FF</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">][</span><span class="n">El</span><span class="p">]</span>           
    745         <span class="n">phase</span> <span class="o">=</span> <span class="n">twopi</span><span class="o">*</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">((</span><span class="n">dXdata</span><span class="o">.</span><span class="n">T</span><span class="o">+</span><span class="n">Xdata</span><span class="o">.</span><span class="n">T</span><span class="p">),</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">])</span><span class="o">+</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Phi&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">][</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">,:])</span>
     774        <span class="n">Tindx</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">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;El&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">El</span><span class="p">)</span> <span class="k">for</span> <span class="n">El</span> <span class="ow">in</span> <span class="n">Tdata</span><span class="p">])</span>
     775        <span class="n">FF</span> <span class="o">=</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="s">&#39;FF&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="n">Tindx</span><span class="p">]</span>
     776<span class="c">#        FF = [refDict[&#39;FF&#39;][iref][El] for El in Tdata]          </span>
     777        <span class="n">Uniq</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">SGMT</span><span class="p">)</span>
     778        <span class="n">Phi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">SGT</span><span class="p">)</span>
     779        <span class="n">phase</span> <span class="o">=</span> <span class="n">twopi</span><span class="o">*</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">((</span><span class="n">dXdata</span><span class="o">.</span><span class="n">T</span><span class="o">+</span><span class="n">Xdata</span><span class="o">.</span><span class="n">T</span><span class="p">),</span><span class="n">Uniq</span><span class="p">)</span><span class="o">+</span><span class="n">Phi</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">,:])</span>
    746780        <span class="n">sinp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">phase</span><span class="p">)</span>
    747781        <span class="n">cosp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">phase</span><span class="p">)</span>
    748         <span class="n">occ</span> <span class="o">=</span> <span class="n">Mdata</span><span class="o">*</span><span class="n">Fdata</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">])</span>
     782        <span class="n">occ</span> <span class="o">=</span> <span class="n">Mdata</span><span class="o">*</span><span class="n">Fdata</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">Uniq</span><span class="p">)</span>
    749783        <span class="n">biso</span> <span class="o">=</span> <span class="o">-</span><span class="n">SQfactor</span><span class="o">*</span><span class="n">Uisodata</span>
    750784        <span class="n">Tiso</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">biso</span><span class="o">&lt;</span><span class="mf">1.</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">biso</span><span class="p">),</span><span class="mf">1.0</span><span class="p">)</span>
    751785        <span class="n">HbH</span> <span class="o">=</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">bij</span><span class="p">,</span><span class="n">H</span><span class="p">))</span>
    752         <span class="n">Hij</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">Mast</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">multiply</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">U</span><span class="p">,</span><span class="n">U</span><span class="p">)</span> <span class="k">for</span> <span class="n">U</span> <span class="ow">in</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]])</span>
     786        <span class="n">Hij</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">Mast</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">multiply</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">U</span><span class="p">,</span><span class="n">U</span><span class="p">)</span> <span class="k">for</span> <span class="n">U</span> <span class="ow">in</span> <span class="n">Uniq</span><span class="p">])</span>
    753787        <span class="n">Hij</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">G2lat</span><span class="o">.</span><span class="n">UijtoU6</span><span class="p">(</span><span class="n">Uij</span><span class="p">)</span> <span class="k">for</span> <span class="n">Uij</span> <span class="ow">in</span> <span class="n">Hij</span><span class="p">])</span>
    754788        <span class="n">Tuij</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">HbH</span><span class="o">&lt;</span><span class="mf">1.</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">HbH</span><span class="p">),</span><span class="mf">1.0</span><span class="p">)</span>
     
    765799        <span class="c">#sum below is over Uniq</span>
    766800        <span class="n">dfadfr</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">fa</span><span class="o">/</span><span class="n">occ</span><span class="p">[:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    767         <span class="n">dfadx</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">twopi</span><span class="o">*</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">fax</span><span class="p">[:,:,:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
     801        <span class="n">dfadx</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">twopi</span><span class="o">*</span><span class="n">Uniq</span><span class="o">*</span><span class="n">fax</span><span class="p">[:,:,:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    768802        <span class="n">dfadui</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="o">-</span><span class="n">SQfactor</span><span class="o">*</span><span class="n">fa</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    769803        <span class="n">dfadua</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="o">-</span><span class="n">Hij</span><span class="o">*</span><span class="n">fa</span><span class="p">[:,:,:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    770804        <span class="n">dfadba</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="o">-</span><span class="n">cosp</span><span class="o">*</span><span class="p">(</span><span class="n">occ</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">)[:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
    771805        <span class="c">#NB: the above have been checked against PA(1:10,1:2) in strfctr.for      </span>
    772         <span class="n">dFdfr</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="mf">2.</span><span class="o">*</span><span class="p">(</span><span class="n">fas</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">dfadfr</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">fas</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">dfadfr</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">*</span><span class="n">Mdata</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">])</span>
     806        <span class="n">dFdfr</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="mf">2.</span><span class="o">*</span><span class="p">(</span><span class="n">fas</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">dfadfr</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">fas</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">dfadfr</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">*</span><span class="n">Mdata</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">Uniq</span><span class="p">)</span>
    773807        <span class="n">dFdx</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="mf">2.</span><span class="o">*</span><span class="p">(</span><span class="n">fas</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">dfadx</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">fas</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">dfadx</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
    774808        <span class="n">dFdui</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="mf">2.</span><span class="o">*</span><span class="p">(</span><span class="n">fas</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">dfadui</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">fas</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">dfadui</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
    775809        <span class="n">dFdua</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="mf">2.</span><span class="o">*</span><span class="p">(</span><span class="n">fas</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">dfadua</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">fas</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">dfadua</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
    776         <span class="n">dFdbab</span><span class="p">[</span><span class="n">iref</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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dfadba</span><span class="o">*</span><span class="n">dBabdA</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="o">-</span><span class="n">dfadba</span><span class="o">*</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabA&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">SQfactor</span><span class="o">*</span><span class="n">dBabdA</span><span class="p">)])</span><span class="o">.</span><span class="n">T</span>
     810        <span class="n">dFdbab</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="mf">2.</span><span class="o">*</span><span class="n">fas</span><span class="p">[</span><span class="mi">0</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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dfadba</span><span class="o">*</span><span class="n">dBabdA</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="o">-</span><span class="n">dfadba</span><span class="o">*</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabA&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">SQfactor</span><span class="o">*</span><span class="n">dBabdA</span><span class="p">)])</span><span class="o">.</span><span class="n">T</span>
    777811        <span class="k">if</span> <span class="ow">not</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGInv&#39;</span><span class="p">]:</span>
    778812            <span class="n">dfbdfr</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">fb</span><span class="o">/</span><span class="n">occ</span><span class="p">[:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>        <span class="c">#problem here if occ=0 for some atom</span>
    779             <span class="n">dfbdx</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">twopi</span><span class="o">*</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">fbx</span><span class="p">[:,:,:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>         
     813            <span class="n">dfbdx</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">twopi</span><span class="o">*</span><span class="n">Uniq</span><span class="o">*</span><span class="n">fbx</span><span class="p">[:,:,:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>         
    780814            <span class="n">dfbdui</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="o">-</span><span class="n">SQfactor</span><span class="o">*</span><span class="n">fb</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    781815            <span class="n">dfbdua</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="o">-</span><span class="n">Hij</span><span class="o">*</span><span class="n">fb</span><span class="p">[:,:,:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    782816            <span class="n">dfbdba</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="o">-</span><span class="n">sinp</span><span class="o">*</span><span class="p">(</span><span class="n">occ</span><span class="o">*</span><span class="n">Tcorr</span><span class="p">)[:,</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
    783             <span class="n">dFdfr</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">+=</span> <span class="mf">2.</span><span class="o">*</span><span class="p">(</span><span class="n">fbs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">dfbdfr</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">fbs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">dfbdfr</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">*</span><span class="n">Mdata</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">])</span>
     817            <span class="n">dFdfr</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">+=</span> <span class="mf">2.</span><span class="o">*</span><span class="p">(</span><span class="n">fbs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">dfbdfr</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">fbs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">dfbdfr</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">*</span><span class="n">Mdata</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">Uniq</span><span class="p">)</span>
    784818            <span class="n">dFdx</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">+=</span> <span class="mf">2.</span><span class="o">*</span><span class="p">(</span><span class="n">fbs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">dfbdx</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">fbs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">dfbdx</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
    785819            <span class="n">dFdui</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">+=</span> <span class="mf">2.</span><span class="o">*</span><span class="p">(</span><span class="n">fbs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">dfbdui</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">fbs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">dfbdui</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
    786820            <span class="n">dFdua</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">+=</span> <span class="mf">2.</span><span class="o">*</span><span class="p">(</span><span class="n">fbs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="n">dfbdua</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">fbs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">dfbdua</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
    787             <span class="n">dFdbab</span><span class="p">[</span><span class="n">iref</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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dfbdba</span><span class="o">*</span><span class="n">dBabdA</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="o">-</span><span class="n">dfbdba</span><span class="o">*</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabA&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">SQfactor</span><span class="o">*</span><span class="n">dBabdA</span><span class="p">)])</span><span class="o">.</span><span class="n">T</span>
     821            <span class="n">dFdbab</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">+=</span> <span class="mf">2.</span><span class="o">*</span><span class="n">fbs</span><span class="p">[</span><span class="mi">0</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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dfbdba</span><span class="o">*</span><span class="n">dBabdA</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="o">-</span><span class="n">dfbdba</span><span class="o">*</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;BabA&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">SQfactor</span><span class="o">*</span><span class="n">dBabdA</span><span class="p">)])</span><span class="o">.</span><span class="n">T</span>
    788822        <span class="c">#loop over atoms - each dict entry is list of derivatives for all the reflections</span>
    789823    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">Mdata</span><span class="p">)):</span>     
     
    799833        <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU13:&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span> <span class="o">=</span> <span class="mf">2.</span><span class="o">*</span><span class="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">4</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    800834        <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU23:&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span> <span class="o">=</span> <span class="mf">2.</span><span class="o">*</span><span class="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">5</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    801         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;BabA&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dFdbab</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    802         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;BabU&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dFdbab</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     835    <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;BabA&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dFdbab</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
     836    <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;BabU&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dFdbab</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    803837    <span class="k">return</span> <span class="n">dFdvDict</span>
    804838    </div>
     
    14131447        <span class="n">hfx</span> <span class="o">=</span> <span class="s">&#39;:</span><span class="si">%d</span><span class="s">:&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">hId</span><span class="p">)</span>
    14141448        <span class="n">SGData</span> <span class="o">=</span> <span class="n">Phase</span><span class="p">[</span><span class="s">&#39;General&#39;</span><span class="p">][</span><span class="s">&#39;SGData&#39;</span><span class="p">]</span>
     1449        <span class="n">SGMT</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">ops</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">T</span> <span class="k">for</span> <span class="n">ops</span> <span class="ow">in</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGOps&#39;</span><span class="p">]])</span>
    14151450        <span class="n">A</span> <span class="o">=</span> <span class="p">[</span><span class="n">parmDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;A</span><span class="si">%d</span><span class="s">&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">)]</span>
    14161451        <span class="n">G</span><span class="p">,</span><span class="n">g</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">A2Gmat</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>       <span class="c">#recip &amp; real metric tensors</span>
     
    14191454        <span class="k">if</span> <span class="ow">not</span> <span class="n">Phase</span><span class="p">[</span><span class="s">&#39;General&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;doPawley&#39;</span><span class="p">):</span>
    14201455            <span class="n">time0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    1421             <span class="n">StructureFactor</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
     1456            <span class="n">StructureFactor2</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
    14221457            <span class="k">print</span> <span class="s">&#39;sf calc time: </span><span class="si">%.3f</span><span class="s">s&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">time0</span><span class="p">)</span>
    14231458        <span class="n">time0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    1424         <span class="n">Uniq</span> <span class="o">=</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">]</span>
    14251459        <span class="k">for</span> <span class="n">iref</span><span class="p">,</span><span class="n">refl</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]):</span>
    14261460            <span class="k">if</span> <span class="s">&#39;C&#39;</span> <span class="ow">in</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;histType&#39;</span><span class="p">]:</span>
    14271461                <span class="n">h</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">l</span> <span class="o">=</span> <span class="n">refl</span><span class="p">[:</span><span class="mi">3</span><span class="p">]</span>
     1462                <span class="n">Uniq</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">refl</span><span class="p">[:</span><span class="mi">3</span><span class="p">],</span><span class="n">SGMT</span><span class="p">)</span>
    14281463                <span class="n">refl</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span> <span class="o">=</span> <span class="n">GetReflPos</span><span class="p">(</span><span class="n">refl</span><span class="p">,</span><span class="n">wave</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>         <span class="c">#corrected reflection position</span>
    14291464                <span class="n">Lorenz</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="p">(</span><span class="mf">2.</span><span class="o">*</span><span class="n">sind</span><span class="p">(</span><span class="n">refl</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="o">/</span><span class="mf">2.</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">cosd</span><span class="p">(</span><span class="n">refl</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="o">/</span><span class="mf">2.</span><span class="p">))</span>           <span class="c">#Lorentz correction</span>
    14301465                <span class="n">refl</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span> <span class="o">+=</span> <span class="n">GetHStrainShift</span><span class="p">(</span><span class="n">refl</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">phfx</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>               <span class="c">#apply hydrostatic strain shift</span>
    14311466                <span class="n">refl</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">8</span><span class="p">]</span> <span class="o">=</span> <span class="n">GetReflSigGam</span><span class="p">(</span><span class="n">refl</span><span class="p">,</span><span class="n">wave</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">GB</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">phfx</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>    <span class="c">#peak sig &amp; gam</span>
    1432                 <span class="n">GetIntensityCorr</span><span class="p">(</span><span class="n">refl</span><span class="p">,</span><span class="n">Uniq</span><span class="p">[</span><span class="n">iref</span><span class="p">],</span><span class="n">G</span><span class="p">,</span><span class="n">g</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">phfx</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>    <span class="c">#puts corrections in refl[11]</span>
     1467                <span class="n">GetIntensityCorr</span><span class="p">(</span><span class="n">refl</span><span class="p">,</span><span class="n">Uniq</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">g</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">phfx</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>    <span class="c">#puts corrections in refl[11]</span>
    14331468                <span class="n">refl</span><span class="p">[</span><span class="mi">11</span><span class="p">]</span> <span class="o">*=</span> <span class="n">Vst</span><span class="o">*</span><span class="n">Lorenz</span>
    14341469                <span class="k">if</span> <span class="n">Phase</span><span class="p">[</span><span class="s">&#39;General&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;doPawley&#39;</span><span class="p">):</span>
     
    15361571        <span class="n">Phase</span> <span class="o">=</span> <span class="n">Phases</span><span class="p">[</span><span class="n">phase</span><span class="p">]</span>
    15371572        <span class="n">SGData</span> <span class="o">=</span> <span class="n">Phase</span><span class="p">[</span><span class="s">&#39;General&#39;</span><span class="p">][</span><span class="s">&#39;SGData&#39;</span><span class="p">]</span>
     1573        <span class="n">SGMT</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">ops</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">T</span> <span class="k">for</span> <span class="n">ops</span> <span class="ow">in</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGOps&#39;</span><span class="p">]])</span>
    15381574        <span class="n">pId</span> <span class="o">=</span> <span class="n">Phase</span><span class="p">[</span><span class="s">&#39;pId&#39;</span><span class="p">]</span>
    15391575        <span class="n">pfx</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%d</span><span class="s">::&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">pId</span><span class="p">)</span>
     
    15481584            <span class="n">ApplyRBModelDervs</span><span class="p">(</span><span class="n">dFdvDict</span><span class="p">,</span><span class="n">parmDict</span><span class="p">,</span><span class="n">rigidbodyDict</span><span class="p">,</span><span class="n">Phase</span><span class="p">)</span>
    15491585        <span class="n">time0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    1550         <span class="n">Uniq</span> <span class="o">=</span> <span class="n">refDict</span><span class="p">[</span><span class="s">&#39;Uniq&#39;</span><span class="p">]</span>
    15511586        <span class="k">for</span> <span class="n">iref</span><span class="p">,</span><span class="n">refl</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]):</span>
    15521587            <span class="k">if</span> <span class="s">&#39;C&#39;</span> <span class="ow">in</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;histType&#39;</span><span class="p">]:</span>        <span class="c">#CW powder</span>
    15531588                <span class="n">h</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">l</span> <span class="o">=</span> <span class="n">refl</span><span class="p">[:</span><span class="mi">3</span><span class="p">]</span>
    1554                 <span class="n">dIdsh</span><span class="p">,</span><span class="n">dIdsp</span><span class="p">,</span><span class="n">dIdpola</span><span class="p">,</span><span class="n">dIdPO</span><span class="p">,</span><span class="n">dFdODF</span><span class="p">,</span><span class="n">dFdSA</span><span class="p">,</span><span class="n">dFdAb</span> <span class="o">=</span> <span class="n">GetIntensityDerv</span><span class="p">(</span><span class="n">refl</span><span class="p">,</span><span class="n">Uniq</span><span class="p">[</span><span class="n">iref</span><span class="p">],</span><span class="n">G</span><span class="p">,</span><span class="n">g</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">phfx</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
     1589                <span class="n">Uniq</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">refl</span><span class="p">[:</span><span class="mi">3</span><span class="p">],</span><span class="n">SGMT</span><span class="p">)</span>
     1590                <span class="n">dIdsh</span><span class="p">,</span><span class="n">dIdsp</span><span class="p">,</span><span class="n">dIdpola</span><span class="p">,</span><span class="n">dIdPO</span><span class="p">,</span><span class="n">dFdODF</span><span class="p">,</span><span class="n">dFdSA</span><span class="p">,</span><span class="n">dFdAb</span> <span class="o">=</span> <span class="n">GetIntensityDerv</span><span class="p">(</span><span class="n">refl</span><span class="p">,</span><span class="n">Uniq</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">g</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">phfx</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
    15551591                <span class="n">Wd</span><span class="p">,</span><span class="n">fmin</span><span class="p">,</span><span class="n">fmax</span> <span class="o">=</span> <span class="n">G2pwd</span><span class="o">.</span><span class="n">getWidthsCW</span><span class="p">(</span><span class="n">refl</span><span class="p">[</span><span class="mi">5</span><span class="p">],</span><span class="n">refl</span><span class="p">[</span><span class="mi">6</span><span class="p">],</span><span class="n">refl</span><span class="p">[</span><span class="mi">7</span><span class="p">],</span><span class="n">shl</span><span class="p">)</span>
    15561592                <span class="n">iBeg</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">searchsorted</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">refl</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="o">-</span><span class="n">fmin</span><span class="p">)</span>
     
    16771713                            <span class="n">depDerivDict</span><span class="p">[</span><span class="n">name</span><span class="p">][</span><span class="n">iBeg2</span><span class="p">:</span><span class="n">iFin2</span><span class="p">]</span> <span class="o">+=</span> <span class="n">sigDict</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">*</span><span class="n">dervDict2</span><span class="p">[</span><span class="s">&#39;sig&#39;</span><span class="p">]</span>
    16781714                <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;BabA&#39;</span><span class="p">,</span><span class="s">&#39;BabU&#39;</span><span class="p">]:</span>
    1679                     <span class="k">if</span> <span class="n">phfx</span><span class="o">+</span><span class="n">name</span> <span class="ow">in</span> <span class="n">varylist</span><span class="p">:</span>
    1680                         <span class="n">dMdv</span><span class="p">[</span><span class="n">varylist</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">phfx</span><span class="o">+</span><span class="n">name</span><span class="p">)][</span><span class="n">iBeg</span><span class="p">:</span><span class="n">iFin</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">dervDict</span><span class="p">[</span><span class="s">&#39;int&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">cw</span><span class="p">[</span><span class="n">iBeg</span><span class="p">:</span><span class="n">iFin</span><span class="p">]</span>
    1681                         <span class="k">if</span> <span class="n">Ka2</span><span class="p">:</span>
    1682                             <span class="n">dMdv</span><span class="p">[</span><span class="n">varylist</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">phfx</span><span class="o">+</span><span class="n">name</span><span class="p">)][</span><span class="n">iBeg2</span><span class="p">:</span><span class="n">iFin2</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">dervDict2</span><span class="p">[</span><span class="s">&#39;int&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">cw</span><span class="p">[</span><span class="n">iBeg2</span><span class="p">:</span><span class="n">iFin2</span><span class="p">]</span>
    1683                     <span class="k">elif</span> <span class="n">phfx</span><span class="o">+</span><span class="n">name</span> <span class="ow">in</span> <span class="n">dependentVars</span><span class="p">:</span>                   
    1684                         <span class="n">depDerivDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iBeg</span><span class="p">:</span><span class="n">iFin</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">dervDict</span><span class="p">[</span><span class="s">&#39;int&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">cw</span><span class="p">[</span><span class="n">iBeg</span><span class="p">:</span><span class="n">iFin</span><span class="p">]</span>
    1685                         <span class="k">if</span> <span class="n">Ka2</span><span class="p">:</span>
    1686                             <span class="n">depDerivDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iBeg2</span><span class="p">:</span><span class="n">iFin2</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">dervDict2</span><span class="p">[</span><span class="s">&#39;int&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">cw</span><span class="p">[</span><span class="n">iBeg2</span><span class="p">:</span><span class="n">iFin2</span><span class="p">]</span>                 
     1715                    <span class="k">if</span> <span class="n">refl</span><span class="p">[</span><span class="mi">9</span><span class="p">]:</span>
     1716                        <span class="k">if</span> <span class="n">phfx</span><span class="o">+</span><span class="n">name</span> <span class="ow">in</span> <span class="n">varylist</span><span class="p">:</span>
     1717                            <span class="n">dMdv</span><span class="p">[</span><span class="n">varylist</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">phfx</span><span class="o">+</span><span class="n">name</span><span class="p">)][</span><span class="n">iBeg</span><span class="p">:</span><span class="n">iFin</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">dervDict</span><span class="p">[</span><span class="s">&#39;int&#39;</span><span class="p">]</span><span class="o">/</span><span class="n">refl</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span>
     1718                            <span class="k">if</span> <span class="n">Ka2</span><span class="p">:</span>
     1719                                <span class="n">dMdv</span><span class="p">[</span><span class="n">varylist</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">phfx</span><span class="o">+</span><span class="n">name</span><span class="p">)][</span><span class="n">iBeg2</span><span class="p">:</span><span class="n">iFin2</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">dervDict2</span><span class="p">[</span><span class="s">&#39;int&#39;</span><span class="p">]</span><span class="o">/</span><span class="n">refl</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span>
     1720                        <span class="k">elif</span> <span class="n">phfx</span><span class="o">+</span><span class="n">name</span> <span class="ow">in</span> <span class="n">dependentVars</span><span class="p">:</span>                   
     1721                            <span class="n">depDerivDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iBeg</span><span class="p">:</span><span class="n">iFin</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">dervDict</span><span class="p">[</span><span class="s">&#39;int&#39;</span><span class="p">]</span><span class="o">/</span><span class="n">refl</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span>
     1722                            <span class="k">if</span> <span class="n">Ka2</span><span class="p">:</span>
     1723                                <span class="n">depDerivDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iBeg2</span><span class="p">:</span><span class="n">iFin2</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="n">name</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span><span class="o">*</span><span class="n">dervDict2</span><span class="p">[</span><span class="s">&#39;int&#39;</span><span class="p">]</span><span class="o">/</span><span class="n">refl</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span>                 
    16871724            <span class="k">elif</span> <span class="s">&#39;T&#39;</span> <span class="ow">in</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">hfx</span><span class="o">+</span><span class="s">&#39;histType&#39;</span><span class="p">]:</span>
    16881725                <span class="k">print</span> <span class="s">&#39;TOF Undefined at present&#39;</span>
     
    18981935            <span class="n">refDict</span> <span class="o">=</span> <span class="n">Histogram</span><span class="p">[</span><span class="s">&#39;Data&#39;</span><span class="p">]</span>
    18991936            <span class="n">time0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    1900             <span class="n">dFdvDict</span> <span class="o">=</span> <span class="n">StructureFactorDerv</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>  <span class="c">#accurate for powders!</span>
     1937            <span class="n">dFdvDict</span> <span class="o">=</span> <span class="n">StructureFactorDerv</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
     1938            <span class="k">print</span> <span class="s">&#39;sf-deriv time: </span><span class="si">%.3f</span><span class="s">&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">time0</span><span class="p">)</span>
    19011939            <span class="n">ApplyRBModelDervs</span><span class="p">(</span><span class="n">dFdvDict</span><span class="p">,</span><span class="n">parmDict</span><span class="p">,</span><span class="n">rigidbodyDict</span><span class="p">,</span><span class="n">Phase</span><span class="p">)</span>
    19021940            <span class="n">dMdvh</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">varylist</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">])))</span>
     
    19061944                <span class="n">depDerivDict</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">])))</span>
    19071945            <span class="n">wdf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]))</span>
     1946            <span class="n">time0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    19081947            <span class="k">if</span> <span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;F**2&#39;</span><span class="p">]:</span>
    19091948                <span class="k">for</span> <span class="n">iref</span><span class="p">,</span><span class="n">ref</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]):</span>
     
    19642003            <span class="c"># now process derivatives in constraints</span>
    19652004            <span class="n">G2mv</span><span class="o">.</span><span class="n">Dict2Deriv</span><span class="p">(</span><span class="n">varylist</span><span class="p">,</span><span class="n">depDerivDict</span><span class="p">,</span><span class="n">dMdvh</span><span class="p">)</span>
     2005            <span class="k">print</span> <span class="s">&#39;matrix build time: </span><span class="si">%.3f</span><span class="s">&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">time0</span><span class="p">)</span>
    19662006
    19672007            <span class="k">if</span> <span class="n">dlg</span><span class="p">:</span>
     
    20522092            <span class="n">refDict</span> <span class="o">=</span> <span class="n">Histogram</span><span class="p">[</span><span class="s">&#39;Data&#39;</span><span class="p">]</span>
    20532093            <span class="n">time0</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
    2054             <span class="n">StructureFactor</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
    2055 <span class="c">#            print &#39;sf-calc time: %.3f&#39;%(time.time()-time0)</span>
     2094            <span class="n">StructureFactor2</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">G</span><span class="p">,</span><span class="n">hfx</span><span class="p">,</span><span class="n">pfx</span><span class="p">,</span><span class="n">SGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
     2095            <span class="k">print</span> <span class="s">&#39;sf-calc time: </span><span class="si">%.3f</span><span class="s">&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">time0</span><span class="p">)</span>
    20562096            <span class="n">df</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">refDict</span><span class="p">[</span><span class="s">&#39;RefList&#39;</span><span class="p">]))</span>
    20572097            <span class="n">sumwYo</span> <span class="o">=</span> <span class="mi">0</span>
Note: See TracChangeset for help on using the changeset viewer.