Ignore:
Timestamp:
Oct 10, 2015 9:59:34 PM (7 years ago)
Author:
toby
Message:

rebuild docs

File:
1 edited

Legend:

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

    r1832 r1998  
    5555<span class="sd">&#39;&#39;&#39;</span>
    5656<span class="c">########### SVN repository information ###################</span>
    57 <span class="c"># $Date: 2015-04-28 12:33:47 -0500 (Tue, 28 Apr 2015) $</span>
     57<span class="c"># $Date: 2015-10-09 14:57:18 -0500 (Fri, 09 Oct 2015) $</span>
    5858<span class="c"># $Author: vondreele $</span>
    59 <span class="c"># $Revision: 1816 $</span>
     59<span class="c"># $Revision: 1996 $</span>
    6060<span class="c"># $URL: https://subversion.xray.aps.anl.gov/pyGSAS/trunk/GSASIIstrMath.py $</span>
    61 <span class="c"># $Id: GSASIIstrMath.py 1816 2015-04-28 17:33:47Z vondreele $</span>
     61<span class="c"># $Id: GSASIIstrMath.py 1996 2015-10-09 19:57:18Z vondreele $</span>
    6262<span class="c">########### SVN repository information ###################</span>
    6363<span class="kn">import</span> <span class="nn">time</span>
    64 <span class="kn">import</span> <span class="nn">math</span>
    6564<span class="kn">import</span> <span class="nn">copy</span>
    6665<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
     
    7069<span class="kn">import</span> <span class="nn">scipy.stats</span> <span class="kn">as</span> <span class="nn">st</span>
    7170<span class="kn">import</span> <span class="nn">GSASIIpath</span>
    72 <span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1816 $&quot;</span><span class="p">)</span>
     71<span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1996 $&quot;</span><span class="p">)</span>
    7372<span class="kn">import</span> <span class="nn">GSASIIElem</span> <span class="kn">as</span> <span class="nn">G2el</span>
    7473<span class="kn">import</span> <span class="nn">GSASIIlattice</span> <span class="kn">as</span> <span class="nn">G2lat</span>
     
    8685<span class="n">atan2d</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">:</span> <span class="mf">180.</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">arctan2</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">)</span><span class="o">/</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span>
    8786   
    88 <span class="n">ateln2</span> <span class="o">=</span> <span class="mf">8.0</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="mf">2.0</span><span class="p">)</span>
     87<span class="n">ateln2</span> <span class="o">=</span> <span class="mf">8.0</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="mf">2.0</span><span class="p">)</span>
    8988<span class="n">twopi</span> <span class="o">=</span> <span class="mf">2.0</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span>
    9089<span class="n">twopisq</span> <span class="o">=</span> <span class="mf">2.0</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">**</span><span class="mi">2</span>
     
    653652            <span class="k">if</span> <span class="n">parm</span> <span class="ow">in</span> <span class="n">parmDict</span><span class="p">:</span>
    654653                <span class="n">keys</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="n">iatm</span><span class="p">]</span> <span class="o">=</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">parm</span><span class="p">]</span>
    655     <span class="n">Fdata</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">Fdata</span><span class="p">,</span><span class="n">Fdata</span><span class="p">,</span><span class="mf">1.e-8</span><span class="p">)</span>         <span class="c">#avoid divide by zero in derivative calc.?</span>
     654    <span class="n">Fdata</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">Fdata</span><span class="p">,</span><span class="n">Fdata</span><span class="p">,</span><span class="mf">1.e-8</span><span class="p">)</span>         <span class="c">#avoid divide by zero in derivative calc.</span>
    656655    <span class="k">return</span> <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>
    657656    </div>
     
    680679                <span class="k">if</span> <span class="n">parm</span> <span class="ow">in</span> <span class="n">parmDict</span><span class="p">:</span>
    681680                    <span class="n">keys</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="n">m</span><span class="p">][</span><span class="n">iatm</span><span class="p">]</span> <span class="o">=</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">parm</span><span class="p">]</span>
    682     <span class="k">return</span> <span class="n">waveTypes</span><span class="p">,</span><span class="n">FSSdata</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(),</span><span class="n">XSSdata</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(),</span><span class="n">USSdata</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(),</span><span class="n">MSSdata</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span>   
     681    <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">waveTypes</span><span class="p">),</span><span class="n">FSSdata</span><span class="p">,</span><span class="n">XSSdata</span><span class="p">,</span><span class="n">USSdata</span><span class="p">,</span><span class="n">MSSdata</span>
    683682    </div>
    684 <div class="viewcode-block" id="StructureFactor"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.StructureFactor">[docs]</a><span class="k">def</span> <span class="nf">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>
    685     <span class="sd">&#39;&#39;&#39; Not Used: here only for comparison the StructureFactor2 - faster version</span>
    686 <span class="sd">    Compute structure factors for all h,k,l for phase</span>
    687 <span class="sd">    puts the result, F^2, in each ref[8] in refList</span>
    688 <span class="sd">    input:</span>
    689 <span class="sd">    </span>
    690 <span class="sd">    :param dict refDict: where</span>
    691 <span class="sd">        &#39;RefList&#39; list where each ref = h,k,l,m,d,...</span>
    692 <span class="sd">        &#39;FF&#39; dict of form factors - filed in below</span>
    693 <span class="sd">    :param np.array G:      reciprocal metric tensor</span>
    694 <span class="sd">    :param str pfx:    phase id string</span>
    695 <span class="sd">    :param dict SGData: space group info. dictionary output from SpcGroup</span>
    696 <span class="sd">    :param dict calcControls:</span>
    697 <span class="sd">    :param dict ParmDict:</span>
    698 
    699 <span class="sd">    &#39;&#39;&#39;</span>       
    700     <span class="n">phfx</span> <span class="o">=</span> <span class="n">pfx</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">hfx</span>
    701     <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>
    702     <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>
    703     <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>
    704     <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>
    705     <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>
    706     <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>
    707     <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>
    708     <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>
    709     <span class="k">if</span> <span class="s">&#39;NC&#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>
    710         <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">BlenResCW</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>
    711     <span class="k">else</span><span class="p">:</span>
    712         <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>
    713         <span class="n">FPP</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;FPP&#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>
    714     <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>
    715     <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>
    716     <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>
    717         <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>
    718             <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>        <span class="c">#will need wave here for anom. neutron b&#39;s</span>
    719         <span class="k">else</span><span class="p">:</span>
    720             <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>       
    721         <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>
    722         <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>   
    723     <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>
    724         <span class="k">if</span> <span class="s">&#39;NT&#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>
    725             <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">BlenResCW</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">refl</span><span class="p">[</span><span class="mi">14</span><span class="p">])</span>
    726         <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>
    727         <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>
    728         <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>
    729         <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>
    730         <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>
    731         <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>
    732             <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>
    733                 <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>
    734                 <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>
    735             <span class="k">else</span><span class="p">:</span>       <span class="c">#&#39;X&#39;</span>
    736                 <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>
    737                 <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>
    738         <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>
    739         <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>
    740         <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>
    741         <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>
    742         <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>
    743         <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>
    744         <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>
    745         <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>
    746         <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>
    747         <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>
    748         <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>
    749         <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>
    750         <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>
    751         <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>
    752         <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>
    753             <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>
    754             <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>
    755         <span class="n">fasq</span> <span class="o">=</span> <span class="n">fas</span><span class="o">**</span><span class="mi">2</span>
    756         <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>
    757         <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>
    758         <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>
    759     </div>
    760 <div class="viewcode-block" id="SStructureFactor"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.SStructureFactor">[docs]</a><span class="k">def</span> <span class="nf">SStructureFactor</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">im</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">SSGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">):</span>
    761     <span class="sd">&#39;&#39;&#39; </span>
    762 <span class="sd">    Compute super structure factors for all h,k,l,m for phase</span>
    763 <span class="sd">    puts the result, F^2, in each ref[8+im] in refList</span>
    764 <span class="sd">    input:</span>
    765 <span class="sd">    </span>
    766 <span class="sd">    :param dict refDict: where</span>
    767 <span class="sd">        &#39;RefList&#39; list where each ref = h,k,l,m,d,...</span>
    768 <span class="sd">        &#39;FF&#39; dict of form factors - filed in below</span>
    769 <span class="sd">    :param np.array G:      reciprocal metric tensor</span>
    770 <span class="sd">    :param str pfx:    phase id string</span>
    771 <span class="sd">    :param dict SGData: space group info. dictionary output from SpcGroup</span>
    772 <span class="sd">    :param dict calcControls:</span>
    773 <span class="sd">    :param dict ParmDict:</span>
    774 
    775 <span class="sd">    &#39;&#39;&#39;</span>       
    776     <span class="n">phfx</span> <span class="o">=</span> <span class="n">pfx</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">hfx</span>
    777     <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>
    778     <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>
    779     <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>
    780     <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>
    781     <span class="n">SSGMT</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">SSGData</span><span class="p">[</span><span class="s">&#39;SSGOps&#39;</span><span class="p">]])</span>
    782     <span class="n">SSGT</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">SSGData</span><span class="p">[</span><span class="s">&#39;SSGOps&#39;</span><span class="p">]])</span>
    783     <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>
    784     <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>
    785     <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>
    786     <span class="n">waveTypes</span><span class="p">,</span><span class="n">FSSdata</span><span class="p">,</span><span class="n">XSSdata</span><span class="p">,</span><span class="n">USSdata</span><span class="p">,</span><span class="n">MSSdata</span> <span class="o">=</span> <span class="n">GetAtomSSFXU</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>
    787     <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>
    788     <span class="k">if</span> <span class="s">&#39;NC&#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>
    789         <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">BlenResCW</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>
    790     <span class="k">else</span><span class="p">:</span>
    791         <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>
    792         <span class="n">FPP</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;FPP&#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>
    793     <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>
    794     <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>
    795     <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>
    796         <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>
    797             <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>        <span class="c">#will need wave here for anom. neutron b&#39;s</span>
    798         <span class="k">else</span><span class="p">:</span>
    799             <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>       
    800         <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>
    801         <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>   
    802     <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>
    803         <span class="k">if</span> <span class="s">&#39;NT&#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>
    804             <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">BlenResCW</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">refl</span><span class="p">[</span><span class="mi">14</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
    805         <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>
    806         <span class="n">H</span> <span class="o">=</span> <span class="n">refl</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span>
    807         <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="o">+</span><span class="n">im</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>
    808         <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>
    809         <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>
    810         <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>
    811             <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>
    812                 <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>
    813                 <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>
    814             <span class="k">else</span><span class="p">:</span>       <span class="c">#&#39;X&#39;</span>
    815                 <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>
    816                 <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>
    817         <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>
    818         <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>
    819         <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="mi">3</span><span class="p">],</span><span class="n">SGMT</span><span class="p">)</span>
    820         <span class="n">SSUniq</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">SSGMT</span><span class="p">)</span>
    821         <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="mi">3</span><span class="p">],</span><span class="n">SGT</span><span class="p">)</span>
    822         <span class="n">SSPhi</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">SSGT</span><span class="p">)</span>
    823         <span class="n">GfpuA</span><span class="p">,</span><span class="n">GfpuB</span> <span class="o">=</span> <span class="n">G2mth</span><span class="o">.</span><span class="n">Modulation</span><span class="p">(</span><span class="n">waveTypes</span><span class="p">,</span><span class="n">SSUniq</span><span class="p">,</span><span class="n">SSPhi</span><span class="p">,</span><span class="n">FSSdata</span><span class="p">,</span><span class="n">XSSdata</span><span class="p">,</span><span class="n">USSdata</span><span class="p">)</span>       
    824         <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>
    825         <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>
    826         <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>
    827         <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>
    828         <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>
    829         <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>
    830         <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>
    831         <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>
    832         <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>
    833         <span class="n">fb</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">fa</span><span class="p">)</span>
    834         <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>
    835             <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>
    836         <span class="n">fa</span> <span class="o">=</span> <span class="n">fa</span><span class="o">*</span><span class="n">GfpuA</span><span class="o">-</span><span class="n">fb</span><span class="o">*</span><span class="n">GfpuB</span>
    837         <span class="n">fb</span> <span class="o">=</span> <span class="n">fb</span><span class="o">*</span><span class="n">GfpuA</span><span class="o">+</span><span class="n">fa</span><span class="o">*</span><span class="n">GfpuB</span>
    838         <span class="n">fas</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">real</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">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>
    839         <span class="n">fbs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">real</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">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>
    840            
    841         <span class="n">fasq</span> <span class="o">=</span> <span class="n">fas</span><span class="o">**</span><span class="mi">2</span>
    842         <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>
    843         <span class="n">refl</span><span class="p">[</span><span class="mi">9</span><span class="o">+</span><span class="n">im</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>
    844         <span class="n">refl</span><span class="p">[</span><span class="mi">10</span><span class="o">+</span><span class="n">im</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>
    845     </div>
     683<span class="k">def</span> <span class="nf">GetSSTauM</span><span class="p">(</span><span class="n">SGOps</span><span class="p">,</span><span class="n">SSOps</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">XData</span><span class="p">):</span>
     684   
     685    <span class="n">Natoms</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;Natoms&#39;</span><span class="p">][</span><span class="n">pfx</span><span class="p">]</span>
     686    <span class="n">maxSSwave</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;maxSSwave&#39;</span><span class="p">][</span><span class="n">pfx</span><span class="p">]</span>
     687    <span class="n">Smult</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">Natoms</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">SGOps</span><span class="p">)))</span>
     688    <span class="n">TauT</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">Natoms</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">SGOps</span><span class="p">)))</span>
     689    <span class="k">for</span> <span class="n">ix</span><span class="p">,</span><span class="n">xyz</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">XData</span><span class="o">.</span><span class="n">T</span><span class="p">):</span>
     690        <span class="k">for</span> <span class="n">isym</span><span class="p">,(</span><span class="n">sop</span><span class="p">,</span><span class="n">ssop</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">SGOps</span><span class="p">,</span><span class="n">SSOps</span><span class="p">)):</span>
     691            <span class="n">sdet</span><span class="p">,</span><span class="n">ssdet</span><span class="p">,</span><span class="n">dtau</span><span class="p">,</span><span class="n">dT</span><span class="p">,</span><span class="n">tauT</span> <span class="o">=</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">getTauT</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">sop</span><span class="p">,</span><span class="n">ssop</span><span class="p">,</span><span class="n">xyz</span><span class="p">)</span>
     692            <span class="n">Smult</span><span class="p">[</span><span class="n">ix</span><span class="p">][</span><span class="n">isym</span><span class="p">]</span> <span class="o">=</span> <span class="n">sdet</span>
     693            <span class="n">TauT</span><span class="p">[</span><span class="n">ix</span><span class="p">][</span><span class="n">isym</span><span class="p">]</span> <span class="o">=</span> <span class="n">tauT</span>
     694    <span class="k">return</span> <span class="n">Smult</span><span class="p">,</span><span class="n">TauT</span>
     695   
    846696<div class="viewcode-block" id="StructureFactor2"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.StructureFactor2">[docs]</a><span class="k">def</span> <span class="nf">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>
    847697    <span class="sd">&#39;&#39;&#39; Compute structure factors for all h,k,l for phase</span>
     
    866716    <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>
    867717    <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>
     718    <span class="n">Flack</span> <span class="o">=</span> <span class="mf">1.0</span>
     719    <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> <span class="ow">and</span> <span class="s">&#39;S&#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="ow">and</span> <span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Flack&#39;</span> <span class="ow">in</span> <span class="n">parmDict</span><span class="p">:</span>
     720        <span class="n">Flack</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">-</span><span class="mf">2.</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;Flack&#39;</span><span class="p">]</span>
     721    <span class="n">TwinLaw</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">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]],])</span>
     722    <span class="n">TwDict</span> <span class="o">=</span> <span class="n">refDict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;TwDict&#39;</span><span class="p">,{})</span>           
     723    <span class="k">if</span> <span class="s">&#39;S&#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">NTL</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;NTL&#39;</span><span class="p">]</span>
     725        <span class="n">NM</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinNMN&#39;</span><span class="p">]</span><span class="o">+</span><span class="mi">1</span>
     726        <span class="n">TwinLaw</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinLaw&#39;</span><span class="p">]</span>
     727        <span class="n">TwinFr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinFr:&#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="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">TwinLaw</span><span class="p">))])</span>
     728        <span class="n">TwinInv</span> <span class="o">=</span> <span class="nb">list</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">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinInv&#39;</span><span class="p">],</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">))</span>
    868729    <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>
    869730    <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>
     
    891752                <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>
    892753<span class="c">#reflection processing begins here - big arrays!</span>
    893     <span class="n">iBeg</span> <span class="o">=</span> <span class="mi">0</span>           
     754    <span class="n">iBeg</span> <span class="o">=</span> <span class="mi">0</span>
    894755    <span class="k">while</span> <span class="n">iBeg</span> <span class="o">&lt;</span> <span class="n">nRef</span><span class="p">:</span>
    895756        <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>
    896         <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>
    897         <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>
    898         <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>
    899         <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>
     757        <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>    <span class="c">#array(blkSize,nItems)</span>
     758        <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>                          <span class="c">#array(blkSize,3)</span>
     759        <span class="n">H</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">squeeze</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">TwinLaw</span><span class="p">))</span>   <span class="c">#maybe array(blkSize,nTwins,3) or (blkSize,3)</span>
     760        <span class="n">TwMask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
     761        <span class="k">if</span> <span class="n">TwinLaw</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">TwDict</span><span class="p">:</span> <span class="c">#need np.inner(TwinLaw[?],TwDict[iref][i])*TwinInv[i]</span>
     762            <span class="k">for</span> <span class="n">ir</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">blkSize</span><span class="p">):</span>
     763                <span class="n">iref</span> <span class="o">=</span> <span class="n">ir</span><span class="o">+</span><span class="n">iBeg</span>
     764                <span class="k">if</span> <span class="n">iref</span> <span class="ow">in</span> <span class="n">TwDict</span><span class="p">:</span>
     765                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">TwDict</span><span class="p">[</span><span class="n">iref</span><span class="p">]:</span>
     766                        <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">NTL</span><span class="p">):</span>
     767                            <span class="n">H</span><span class="p">[</span><span class="n">ir</span><span class="p">][</span><span class="n">i</span><span class="o">+</span><span class="n">n</span><span class="o">*</span><span class="n">NM</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">TwinLaw</span><span class="p">[</span><span class="n">n</span><span class="o">*</span><span class="n">NM</span><span class="p">],</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">TwDict</span><span class="p">[</span><span class="n">iref</span><span class="p">][</span><span class="n">i</span><span class="p">])</span><span class="o">*</span><span class="n">TwinInv</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">n</span><span class="o">*</span><span class="n">NM</span><span class="p">])</span>
     768            <span class="n">TwMask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
     769        <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>               <span class="c">#array(blkSize)</span>
     770        <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>               <span class="c">#ditto prev.</span>
    900771        <span class="k">if</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>
    901772            <span class="k">if</span> <span class="s">&#39;P&#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>
     
    903774            <span class="k">else</span><span class="p">:</span>
    904775                <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">BlenResTOF</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">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">12</span><span class="p">])</span>
    905             <span class="n">FP</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">FP</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>
    906             <span class="n">FPP</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">FPP</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>
    907         <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>
     776            <span class="n">FP</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">FP</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="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
     777            <span class="n">FPP</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">FPP</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="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
     778        <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><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">))</span>
    908779        <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>
    909         <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>
    910         <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>
    911         <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>
    912         <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>
     780        <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="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
     781        <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>
     782        <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>
     783        <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">T</span><span class="o">+</span><span class="n">Phi</span><span class="o">.</span><span class="n">T</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
    913784        <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>
    914785        <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>
    915786        <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>
    916         <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>
    917         <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>
     787        <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="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</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>
     788        <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">swapaxes</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">Uniq</span><span class="p">),</span><span class="mi">2</span><span class="p">,</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>
    918789        <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>
    919         <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>
    920         <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>
    921         <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>   <span class="c">#real A,-b</span>
    922         <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 sum over atoms &amp; unique hkl</span>
    923         <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>
    924         <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>   <span class="c">#imag -B,+a</span>
    925         <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>  <span class="c">#imag sum over atoms &amp; uniq hkl</span>
     790        <span class="n">Tcorr</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">Tiso</span><span class="p">,</span><span class="n">Tuij</span><span class="o">.</span><span class="n">shape</span><span class="p">)</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>
     791        <span class="k">if</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>
     792            <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">np</span><span class="o">.</span><span class="n">reshape</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="p">,</span><span class="n">cosp</span><span class="o">.</span><span class="n">shape</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">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">Flack</span><span class="o">*</span><span class="n">FPP</span><span class="p">,</span><span class="n">sinp</span><span class="o">.</span><span class="n">shape</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>
     793            <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">np</span><span class="o">.</span><span class="n">reshape</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="p">,</span><span class="n">sinp</span><span class="o">.</span><span class="n">shape</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">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">Flack</span><span class="o">*</span><span class="n">FPP</span><span class="p">,</span><span class="n">cosp</span><span class="o">.</span><span class="n">shape</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>
     794        <span class="k">else</span><span class="p">:</span>
     795            <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">np</span><span class="o">.</span><span class="n">reshape</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="p">,</span><span class="n">cosp</span><span class="o">.</span><span class="n">shape</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">Flack</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>
     796            <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">np</span><span class="o">.</span><span class="n">reshape</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="p">,</span><span class="n">sinp</span><span class="o">.</span><span class="n">shape</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">Flack</span><span class="o">*</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>
     797        <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 sum over atoms &amp; unique hkl</span>
     798        <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>  <span class="c">#imag sum over atoms &amp; uniq hkl</span>
    926799        <span class="k">if</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGInv&#39;</span><span class="p">]:</span> <span class="c">#centrosymmetric; B=0</span>
    927800            <span class="n">fbs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*=</span> <span class="mf">0.</span>
    928801        <span class="k">if</span> <span class="s">&#39;P&#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>
    929802            <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">fas</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">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">fbs</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">0</span><span class="p">)</span>
     803            <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>  <span class="c">#ignore f&#39; &amp; f&quot;</span>
    930804        <span class="k">else</span><span class="p">:</span>
    931             <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">fas</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="mi">2</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">fbs</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="mi">2</span>
    932         <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>  <span class="c">#ignore f&#39; &amp; f&quot;?</span>
     805            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     806                <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">fas</span><span class="p">[:,:,</span><span class="mi">0</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="mi">2</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">fbs</span><span class="p">[:,:,</span><span class="mi">0</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="mi">2</span>   <span class="c">#FcT from primary twin element</span>
     807                <span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">7</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">TwinFr</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">TwMask</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="o">*</span><span class="n">fas</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="mi">2</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>   \
     808                    <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">TwinFr</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">TwMask</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="o">*</span><span class="n">fbs</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="mi">2</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">#Fc sum over twins</span>
     809                <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="o">.</span><span class="n">T</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><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>  <span class="c">#ignore f&#39; &amp; f&quot;</span>
     810            <span class="k">else</span><span class="p">:</span>
     811                <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">fas</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="mi">2</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">fbs</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="mi">2</span>
     812                <span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">7</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><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>               
     813                <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>  <span class="c">#ignore f&#39; &amp; f&quot;</span>
    933814<span class="c">#        refl.T[10] = atan2d(np.sum(fbs,axis=0),np.sum(fas,axis=0)) #include f&#39; &amp; f&quot;</span>
    934815        <span class="n">iBeg</span> <span class="o">+=</span> <span class="n">blkSize</span>
     
    943824    <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>
    944825    <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>
     826    <span class="n">TwinLaw</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">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]],])</span>
     827    <span class="n">TwDict</span> <span class="o">=</span> <span class="n">refDict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;TwDict&#39;</span><span class="p">,{})</span>           
     828    <span class="k">if</span> <span class="s">&#39;S&#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>
     829        <span class="n">NTL</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;NTL&#39;</span><span class="p">]</span>
     830        <span class="n">NM</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinNMN&#39;</span><span class="p">]</span><span class="o">+</span><span class="mi">1</span>
     831        <span class="n">TwinLaw</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinLaw&#39;</span><span class="p">]</span>
     832        <span class="n">TwinFr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinFr:&#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="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">TwinLaw</span><span class="p">))])</span>
     833        <span class="n">TwinInv</span> <span class="o">=</span> <span class="nb">list</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">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinInv&#39;</span><span class="p">],</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">))</span>
     834    <span class="n">nTwin</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">)</span>       
    945835    <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>
    946836    <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>
     
    955845    <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>
    956846    <span class="n">dFdvDict</span> <span class="o">=</span> <span class="p">{}</span>
    957     <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>
    958     <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>
    959     <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>
    960     <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>
    961     <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>
     847    <span class="k">if</span> <span class="n">nTwin</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     848        <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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">))</span>
     849        <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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
     850        <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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">))</span>
     851        <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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span>
     852        <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="n">nTwin</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>
     853        <span class="n">dFdfl</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">nTwin</span><span class="p">))</span>
     854        <span class="n">dFdtw</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">nTwin</span><span class="p">))</span>
     855    <span class="k">else</span><span class="p">:</span>
     856        <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>
     857        <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>
     858        <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>
     859        <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>
     860        <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>
     861        <span class="n">dFdfl</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>
     862        <span class="n">dFdtw</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>
     863    <span class="n">Flack</span> <span class="o">=</span> <span class="mf">1.0</span>
     864    <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> <span class="ow">and</span> <span class="s">&#39;S&#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="ow">and</span> <span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Flack&#39;</span> <span class="ow">in</span> <span class="n">parmDict</span><span class="p">:</span>
     865        <span class="n">Flack</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">-</span><span class="mf">2.</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;Flack&#39;</span><span class="p">]</span>
     866    <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>
     867    <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><span class="o">/</span><span class="mi">100</span>   
    962868    <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>
    963869        <span class="k">if</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>
    964870            <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">BlenResCW</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">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">12</span><span class="p">])</span>
    965871        <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>
     872        <span class="n">H</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">squeeze</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">TwinLaw</span><span class="p">))</span>   <span class="c">#maybe array(3,nTwins) or (3)</span>
     873        <span class="n">TwMask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
     874        <span class="k">if</span> <span class="n">TwinLaw</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">TwDict</span><span class="p">:</span>
     875            <span class="k">if</span> <span class="n">iref</span> <span class="ow">in</span> <span class="n">TwDict</span><span class="p">:</span>
     876                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">TwDict</span><span class="p">[</span><span class="n">iref</span><span class="p">]:</span>
     877                    <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">NTL</span><span class="p">):</span>
     878                        <span class="n">H</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">n</span><span class="o">*</span><span class="n">NM</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">TwinLaw</span><span class="p">[</span><span class="n">n</span><span class="o">*</span><span class="n">NM</span><span class="p">],</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">TwDict</span><span class="p">[</span><span class="n">iref</span><span class="p">][</span><span class="n">i</span><span class="p">])</span><span class="o">*</span><span class="n">TwinInv</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">n</span><span class="o">*</span><span class="n">NM</span><span class="p">])</span>
     879            <span class="n">TwMask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
    966880        <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>             <span class="c"># or (sin(theta)/lambda)**2</span>
    967881        <span class="n">SQfactor</span> <span class="o">=</span> <span class="mf">8.0</span><span class="o">*</span><span class="n">SQ</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">**</span><span class="mi">2</span>
     
    969883        <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>
    970884        <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>
    971         <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>
    972         <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>
     885        <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><span class="o">.</span><span class="n">T</span>
     886        <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>             <span class="c"># array(nSGOp,3) or (nTwin,nSGOp,3)</span>
    973887        <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>
    974         <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>
     888        <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">T</span><span class="o">+</span><span class="n">Phi</span><span class="o">.</span><span class="n">T</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
    975889        <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>
    976890        <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>
    977         <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>
    978         <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>
    979         <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>
    980         <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>
    981         <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>
    982         <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>
     891        <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">SGT</span><span class="p">)</span>
     892        <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>
     893        <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="o">*</span><span class="n">nTwin</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     894        <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">swapaxes</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">Uniq</span><span class="p">),</span><span class="mi">2</span><span class="p">,</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>
     895        <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">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">Uniq</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>
     896        <span class="n">Hij</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</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">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><span class="n">nTwin</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">6</span><span class="p">)))</span>
    983897        <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>
    984         <span class="n">Tcorr</span> <span class="o">=</span> <span class="n">Tiso</span><span class="o">*</span><span class="n">Tuij</span>
    985         <span class="n">fot</span> <span class="o">=</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">Tcorr</span>
    986         <span class="n">fotp</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">Tcorr</span>
    987         <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">fot</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="o">*</span><span class="n">cosp</span><span class="p">,</span><span class="n">fotp</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="o">*</span><span class="n">cosp</span><span class="p">])</span>       <span class="c">#non positions</span>
    988         <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">fot</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="o">*</span><span class="n">sinp</span><span class="p">,</span><span class="o">-</span><span class="n">fotp</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="o">*</span><span class="n">sinp</span><span class="p">])</span>
     898        <span class="n">Tcorr</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">Tiso</span><span class="p">,</span><span class="n">Tuij</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span><span class="o">*</span><span class="n">Tuij</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="o">*</span><span class="n">occ</span>
     899        <span class="n">fot</span> <span class="o">=</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">Tcorr</span>
     900        <span class="n">fotp</span> <span class="o">=</span> <span class="n">FPP</span><span class="o">*</span><span class="n">Tcorr</span>       
     901        <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">Flack</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> <span class="c"># array(2,nTwin,nEqv,nAtoms)</span>
     902        <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">Flack</span><span class="o">*</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>
     903        <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 sum over atoms &amp; unique hkl array(2,nTwins)</span>
     904        <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>      <span class="c">#imag sum over atoms &amp; uniq hkl</span>
     905        <span class="n">fax</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">fot</span><span class="o">*</span><span class="n">sinp</span><span class="p">,</span><span class="o">-</span><span class="n">fotp</span><span class="o">*</span><span class="n">cosp</span><span class="p">])</span>   <span class="c">#positions array(2,ntwi,nEqv,nAtoms)</span>
     906        <span class="n">fbx</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">fot</span><span class="o">*</span><span class="n">cosp</span><span class="p">,</span><span class="o">-</span><span class="n">fotp</span><span class="o">*</span><span class="n">sinp</span><span class="p">])</span>
     907        <span class="c">#sum below is over Uniq </span>
     908        <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">axis</span><span class="o">=-</span><span class="mi">2</span><span class="p">)</span>        <span class="c">#array(2,ntwin,nAtom) Fdata != 0 avoids /0. problem </span>
     909        <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="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>
     910        <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>
     911        <span class="k">if</span> <span class="n">nTwin</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     912            <span class="n">dfadx</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">twopi</span><span class="o">*</span><span class="n">Uniq</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fax</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,</span><span class="n">it</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="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)])</span>
     913            <span class="n">dfadua</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="o">-</span><span class="n">Hij</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fa</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,</span><span class="n">it</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="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)])</span>
     914            <span class="c"># array(nTwin,2,nAtom,3) &amp; array(nTwin,2,nAtom,6)</span>
     915        <span class="k">else</span><span class="p">:</span>
     916            <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">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fax</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</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>
     917            <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">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fa</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</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>
     918            <span class="c"># array(2,nAtom,3) &amp; array(2,nAtom,6)</span>
     919        <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>
     920            <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">axis</span><span class="o">=-</span><span class="mi">2</span><span class="p">)</span>        <span class="c">#Fdata != 0 avoids /0. problem</span>
     921            <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="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>
     922            <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>
     923            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     924                <span class="n">dfbdx</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">twopi</span><span class="o">*</span><span class="n">Uniq</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fbx</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,</span><span class="n">it</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="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)])</span>           
     925                <span class="n">dfbdua</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="o">-</span><span class="n">Hij</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fb</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,</span><span class="n">it</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="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)])</span>
     926            <span class="k">else</span><span class="p">:</span>
     927                <span class="n">dfadfl</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">FPP</span><span class="o">*</span><span class="n">Tcorr</span><span class="o">*</span><span class="n">sinp</span><span class="p">)</span>
     928                <span class="n">dfbdfl</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">FPP</span><span class="o">*</span><span class="n">Tcorr</span><span class="o">*</span><span class="n">cosp</span><span class="p">)</span>
     929                <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">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fbx</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</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>           
     930                <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">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fb</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</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>
     931        <span class="k">else</span><span class="p">:</span>
     932            <span class="n">dfbdfr</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">dfadfr</span><span class="p">)</span>
     933            <span class="n">dfbdx</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">dfadx</span><span class="p">)</span>
     934            <span class="n">dfbdui</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">dfadui</span><span class="p">)</span>
     935            <span class="n">dfbdua</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">dfadua</span><span class="p">)</span>
     936            <span class="n">dfbdba</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">dfadba</span><span class="p">)</span>
     937            <span class="n">dfadfl</span> <span class="o">=</span> <span class="mf">0.0</span>
     938            <span class="n">dfbdfl</span> <span class="o">=</span> <span class="mf">0.0</span>
     939        <span class="c">#NB: the above have been checked against PA(1:10,1:2) in strfctr.for for Al2O3!    </span>
     940        <span class="k">if</span> <span class="s">&#39;P&#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">#checked perfect for centro &amp; noncentro</span>
     941            <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><span class="o">+</span>   \
     942                <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>
     943            <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><span class="o">+</span>  \
     944                <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>
     945            <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><span class="o">+</span>   \
     946                <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>
     947            <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><span class="o">+</span>   \
     948                <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>
     949        <span class="k">else</span><span class="p">:</span>
     950            <span class="n">SA</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">fbs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     951            <span class="n">SB</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">fas</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     952            <span class="k">if</span> <span class="n">nTwin</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     953                <span class="n">dFdfr</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SA</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfadfr</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">it</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="n">it</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><span class="n">it</span><span class="p">])</span><span class="o">+</span> \
     954                    <span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SB</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfbdfr</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">it</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="n">it</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><span class="n">it</span><span class="p">])</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)]</span>
     955                <span class="n">dFdx</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SA</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfadx</span><span class="p">[</span><span class="n">it</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="n">it</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SB</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfbdx</span><span class="p">[</span><span class="n">it</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="n">it</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)]</span>
     956                <span class="n">dFdui</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SA</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfadui</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">it</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><span class="n">it</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SB</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfbdui</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">it</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><span class="n">it</span><span class="p">])</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)]</span>
     957                <span class="n">dFdua</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SA</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfadua</span><span class="p">[</span><span class="n">it</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="n">it</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SB</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfbdua</span><span class="p">[</span><span class="n">it</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="n">it</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)]</span>
     958                <span class="n">dFdtw</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">sum</span><span class="p">(</span><span class="n">TwMask</span><span class="o">*</span><span class="n">fas</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="mi">2</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">TwMask</span><span class="o">*</span><span class="n">fbs</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="mi">2</span>
     959               
     960            <span class="k">else</span><span class="p">:</span>   <span class="c">#these are good for no twin single crystals</span>
     961                <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="n">SA</span><span class="o">*</span><span class="p">(</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">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><span class="o">+</span> \
     962                    <span class="mf">2.</span><span class="o">*</span><span class="n">SB</span><span class="o">*</span><span class="p">(</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">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> <span class="c">#array(nRef,nAtom)</span>
     963                <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="n">SA</span><span class="o">*</span><span class="p">(</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">dfbdx</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">SB</span><span class="o">*</span><span class="p">(</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">dfadx</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>    <span class="c">#array(nRef,nAtom,3)</span>
     964                <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="n">SA</span><span class="o">*</span><span class="p">(</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">dfbdui</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">SB</span><span class="o">*</span><span class="p">(</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">dfadui</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>   <span class="c">#array(nRef,nAtom)</span>
     965                <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="n">SA</span><span class="o">*</span><span class="p">(</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">dfbdua</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">SB</span><span class="o">*</span><span class="p">(</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">dfadua</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>    <span class="c">#array(nRef,nAtom,6)</span>
     966                <span class="n">dFdfl</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">SA</span><span class="o">*</span><span class="n">dfadfl</span><span class="o">-</span><span class="n">SB</span><span class="o">*</span><span class="n">dfbdfl</span>  <span class="c">#array(nRef,)</span>
     967        <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><span class="o">+</span> \
     968            <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>
     969<span class="c">#        GSASIIpath.IPyBreak()</span>
     970    <span class="k">print</span> <span class="s">&#39; derivative time </span><span class="si">%.4f</span><span class="se">\r</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>
     971        <span class="c">#loop over atoms - each dict entry is list of derivatives for all the reflections</span>
     972    <span class="k">if</span> <span class="n">nTwin</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     973        <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>     <span class="c">#these all OK?</span>
     974            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;Afrac:&#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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dFdfr</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     975            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;dAx:&#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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dFdx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     976            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;dAy:&#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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dFdx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     977            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;dAz:&#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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dFdx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     978            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AUiso:&#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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dFdui</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     979            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU11:&#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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     980            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU22:&#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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     981            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU33:&#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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     982            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU12:&#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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="mf">0.5</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">3</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     983            <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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="mf">0.5</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><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     984            <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="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="mf">0.5</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><span class="o">*</span><span class="n">TwinFr</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">0</span><span class="p">)</span>
     985    <span class="k">else</span><span class="p">:</span>
     986        <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>
     987            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;Afrac:&#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="n">dFdfr</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
     988            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;dAx:&#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="n">dFdx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     989            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;dAy:&#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="n">dFdx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     990            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;dAz:&#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="n">dFdx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     991            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AUiso:&#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="n">dFdui</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
     992            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU11:&#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="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     993            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU22:&#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="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     994            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU33:&#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="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     995            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU12:&#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">0.5</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">3</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     996            <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">0.5</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>
     997            <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">0.5</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>
     998        <span class="n">dFdvDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Flack&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">4.</span><span class="o">*</span><span class="n">dFdfl</span><span class="o">.</span><span class="n">T</span>
     999    <span class="n">dFdvDict</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">dFdbab</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
     1000    <span class="n">dFdvDict</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">dFdbab</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     1001    <span class="k">if</span> <span class="n">nTwin</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     1002        <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="n">nTwin</span><span class="p">):</span>
     1003            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinFr:&#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="n">dFdtw</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
     1004    <span class="k">return</span> <span class="n">dFdvDict</span>
     1005    </div>
     1006<div class="viewcode-block" id="SStructureFactor2"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.SStructureFactor2">[docs]</a><span class="k">def</span> <span class="nf">SStructureFactor2</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">im</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">SSGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">):</span>
     1007    <span class="sd">&#39;&#39;&#39; </span>
     1008<span class="sd">    Compute super structure factors for all h,k,l,m for phase</span>
     1009<span class="sd">    puts the result, F^2, in each ref[8+im] in refList</span>
     1010<span class="sd">    input:</span>
     1011<span class="sd">    </span>
     1012<span class="sd">    :param dict refDict: where</span>
     1013<span class="sd">        &#39;RefList&#39; list where each ref = h,k,l,m,d,...</span>
     1014<span class="sd">        &#39;FF&#39; dict of form factors - filed in below</span>
     1015<span class="sd">    :param np.array G:      reciprocal metric tensor</span>
     1016<span class="sd">    :param str pfx:    phase id string</span>
     1017<span class="sd">    :param dict SGData: space group info. dictionary output from SpcGroup</span>
     1018<span class="sd">    :param dict calcControls:</span>
     1019<span class="sd">    :param dict ParmDict:</span>
     1020
     1021<span class="sd">    &#39;&#39;&#39;</span>
     1022    <span class="n">nxs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">newaxis</span>       
     1023    <span class="n">phfx</span> <span class="o">=</span> <span class="n">pfx</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">hfx</span>
     1024    <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>
     1025    <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>   
     1026    <span class="n">SGInv</span> <span class="o">=</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGInv&#39;</span><span class="p">]</span>
     1027    <span class="n">SSGMT</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">SSGData</span><span class="p">[</span><span class="s">&#39;SSGOps&#39;</span><span class="p">]])</span>
     1028    <span class="n">SSGT</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">SSGData</span><span class="p">[</span><span class="s">&#39;SSGOps&#39;</span><span class="p">]])</span>
     1029    <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>
     1030    <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>
     1031    <span class="n">Flack</span> <span class="o">=</span> <span class="mf">1.0</span>
     1032    <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> <span class="ow">and</span> <span class="s">&#39;S&#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="ow">and</span> <span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Flack&#39;</span> <span class="ow">in</span> <span class="n">parmDict</span><span class="p">:</span>
     1033        <span class="n">Flack</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">-</span><span class="mf">2.</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;Flack&#39;</span><span class="p">]</span>
     1034    <span class="n">TwinLaw</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">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]],])</span>    <span class="c">#4D?</span>
     1035    <span class="n">TwDict</span> <span class="o">=</span> <span class="n">refDict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;TwDict&#39;</span><span class="p">,{})</span>           
     1036    <span class="k">if</span> <span class="s">&#39;S&#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>
     1037        <span class="n">NTL</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;NTL&#39;</span><span class="p">]</span>
     1038        <span class="n">NM</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinNMN&#39;</span><span class="p">]</span><span class="o">+</span><span class="mi">1</span>
     1039        <span class="n">TwinLaw</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinLaw&#39;</span><span class="p">]</span>  <span class="c">#this&#39;ll have to be 4D also...</span>
     1040        <span class="n">TwinFr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinFr:&#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="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">TwinLaw</span><span class="p">))])</span>
     1041        <span class="n">TwinInv</span> <span class="o">=</span> <span class="nb">list</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">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinInv&#39;</span><span class="p">],</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">))</span>
     1042    <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>
     1043    <span class="n">waveTypes</span><span class="p">,</span><span class="n">FSSdata</span><span class="p">,</span><span class="n">XSSdata</span><span class="p">,</span><span class="n">USSdata</span><span class="p">,</span><span class="n">MSSdata</span> <span class="o">=</span> <span class="n">GetAtomSSFXU</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>
     1044    <span class="n">modQ</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">parmDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;mV0&#39;</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;mV1&#39;</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;mV2&#39;</span><span class="p">]])</span>
     1045    <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>
     1046    <span class="k">if</span> <span class="s">&#39;NC&#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>
     1047        <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">BlenResCW</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>
     1048    <span class="k">else</span><span class="p">:</span>
     1049        <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>
     1050        <span class="n">FPP</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;FPP&#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>
     1051    <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>
     1052    <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>
     1053    <span class="n">blkSize</span> <span class="o">=</span> <span class="mi">100</span>       <span class="c">#no. of reflections in a block</span>
     1054    <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>
     1055    <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>
     1056        <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>
     1057            <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>        <span class="c">#will need wave here for anom. neutron b&#39;s</span>
     1058            <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>
     1059            <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>           
     1060        <span class="k">else</span><span class="p">:</span>
     1061            <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>       
     1062            <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>
     1063            <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>
     1064            <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>
     1065                <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">5</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>
     1066                <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>
     1067                <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>
     1068    <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>
     1069<span class="c">#reflection processing begins here - big arrays!</span>
     1070    <span class="n">iBeg</span> <span class="o">=</span> <span class="mi">0</span>
     1071    <span class="k">while</span> <span class="n">iBeg</span> <span class="o">&lt;</span> <span class="n">nRef</span><span class="p">:</span>
     1072        <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>
     1073        <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>    <span class="c">#array(blkSize,nItems)</span>
     1074        <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">4</span><span class="p">]</span>                          <span class="c">#array(blkSize,4)</span>
     1075<span class="c">#        H = np.squeeze(np.inner(H.T,TwinLaw))   #maybe array(blkSize,nTwins,4) or (blkSize,4)</span>
     1076<span class="c">#        TwMask = np.any(H,axis=-1)</span>
     1077<span class="c">#        if TwinLaw.shape[0] &gt; 1 and TwDict: #need np.inner(TwinLaw[?],TwDict[iref][i])*TwinInv[i]</span>
     1078<span class="c">#            for ir in range(blkSize):</span>
     1079<span class="c">#                iref = ir+iBeg</span>
     1080<span class="c">#                if iref in TwDict:</span>
     1081<span class="c">#                    for i in TwDict[iref]:</span>
     1082<span class="c">#                        for n in range(NTL):</span>
     1083<span class="c">#                            H[ir][i+n*NM] = np.inner(TwinLaw[n*NM],np.array(TwDict[iref][i])*TwinInv[i+n*NM])</span>
     1084<span class="c">#            TwMask = np.any(H,axis=-1)</span>
     1085        <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">5</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>               <span class="c">#array(blkSize)</span>
     1086        <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>               <span class="c">#ditto prev.</span>
     1087        <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="o">.</span><span class="n">T</span><span class="p">,</span><span class="n">SSGMT</span><span class="p">)</span>
     1088        <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">SSGT</span><span class="p">)</span>
     1089        <span class="k">if</span> <span class="n">SGInv</span><span class="p">:</span>   <span class="c">#if centro - expand HKL sets</span>
     1090            <span class="n">Uniq</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">Uniq</span><span class="p">,</span><span class="o">-</span><span class="n">Uniq</span><span class="p">))</span>
     1091            <span class="n">Phi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">Phi</span><span class="p">,</span><span class="o">-</span><span class="n">Phi</span><span class="p">))</span>
     1092        <span class="k">if</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>
     1093            <span class="k">if</span> <span class="s">&#39;P&#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>
     1094                <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">BlenResTOF</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">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">14</span><span class="p">])</span>
     1095            <span class="k">else</span><span class="p">:</span>
     1096                <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">BlenResTOF</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">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">12</span><span class="p">])</span>
     1097            <span class="n">FP</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">FP</span><span class="o">.</span><span class="n">T</span><span class="p">,</span><span class="n">Uniq</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
     1098            <span class="n">FPP</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">FPP</span><span class="o">.</span><span class="n">T</span><span class="p">,</span><span class="n">Uniq</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
     1099        <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="n">Uniq</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">))</span>
     1100        <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>
     1101        <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="n">Uniq</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">),</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
     1102        <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="mi">3</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">nxs</span><span class="p">])</span>
     1103        <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>
     1104        <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>
     1105        <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">nxs</span><span class="p">]</span>
     1106        <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="n">Uniq</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</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>
     1107        <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="p">[:,:,</span><span class="n">nxs</span><span class="p">,:</span><span class="mi">3</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">Uniq</span><span class="p">[:,:,:</span><span class="mi">3</span><span class="p">],</span><span class="n">bij</span><span class="p">),</span><span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
     1108        <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>
     1109        <span class="n">Tcorr</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">Tiso</span><span class="p">,</span><span class="n">Tuij</span><span class="o">.</span><span class="n">shape</span><span class="p">)</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="n">Uniq</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     1110        <span class="k">if</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>
     1111            <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">np</span><span class="o">.</span><span class="n">reshape</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="p">,</span><span class="n">cosp</span><span class="o">.</span><span class="n">shape</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">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">Flack</span><span class="o">*</span><span class="n">FPP</span><span class="p">,</span><span class="n">sinp</span><span class="o">.</span><span class="n">shape</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>
     1112            <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">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">Flack</span><span class="o">*</span><span class="n">FPP</span><span class="p">,</span><span class="n">cosp</span><span class="o">.</span><span class="n">shape</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="n">np</span><span class="o">.</span><span class="n">reshape</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="p">,</span><span class="n">sinp</span><span class="o">.</span><span class="n">shape</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>
     1113        <span class="k">else</span><span class="p">:</span>
     1114            <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">np</span><span class="o">.</span><span class="n">reshape</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="p">,</span><span class="n">cosp</span><span class="o">.</span><span class="n">shape</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">Flack</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>
     1115            <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">Flack</span><span class="o">*</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><span class="n">np</span><span class="o">.</span><span class="n">reshape</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="p">,</span><span class="n">sinp</span><span class="o">.</span><span class="n">shape</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>
     1116        <span class="n">GfpuA</span> <span class="o">=</span> <span class="n">G2mth</span><span class="o">.</span><span class="n">Modulation</span><span class="p">(</span><span class="n">waveTypes</span><span class="p">,</span><span class="n">Uniq</span><span class="p">,</span><span class="n">FSSdata</span><span class="p">,</span><span class="n">XSSdata</span><span class="p">,</span><span class="n">USSdata</span><span class="p">,</span><span class="n">Mast</span><span class="p">)</span> <span class="c">#2 x refBlk x sym X atoms</span>
     1117        <span class="n">fag</span> <span class="o">=</span> <span class="n">fa</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">fb</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     1118        <span class="n">fbg</span> <span class="o">=</span> <span class="n">fb</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">fa</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     1119        <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">fag</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>
     1120        <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">fbg</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>
     1121<span class="c">#        GSASIIpath.IPyBreak()</span>
     1122        <span class="k">if</span> <span class="s">&#39;P&#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>
     1123            <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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">fas</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">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">fbs</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">0</span><span class="p">)</span>
     1124            <span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">11</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>  <span class="c">#ignore f&#39; &amp; f&quot;</span>
     1125        <span class="k">else</span><span class="p">:</span>
     1126            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     1127                <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">np</span><span class="o">.</span><span class="n">sum</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="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span><span class="o">**</span><span class="mi">2</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">fbs</span><span class="p">[:,:,</span><span class="mi">0</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="mi">2</span>   <span class="c">#FcT from primary twin element</span>
     1128                <span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">8</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">TwinFr</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">TwMask</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="o">*</span><span class="n">fas</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="mi">2</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>   \
     1129                    <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">TwinFr</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">TwMask</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="o">*</span><span class="n">fbs</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="mi">2</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">#Fc sum over twins</span>
     1130                <span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">11</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="o">.</span><span class="n">T</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><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>  <span class="c">#ignore f&#39; &amp; f&quot;</span>
     1131            <span class="k">else</span><span class="p">:</span>
     1132                <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">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">fas</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="mi">2</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">fbs</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="mi">2</span>
     1133                <span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">8</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><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>               
     1134                <span class="n">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">11</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>  <span class="c">#ignore f&#39; &amp; f&quot;</span>
     1135        <span class="n">iBeg</span> <span class="o">+=</span> <span class="n">blkSize</span>
     1136    <span class="k">print</span> <span class="s">&#39;nRef </span><span class="si">%d</span><span class="s"> time </span><span class="si">%.4f</span><span class="se">\r</span><span class="s">&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">nRef</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>
     1137</div>
     1138<div class="viewcode-block" id="SStructureFactorDerv"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.SStructureFactorDerv">[docs]</a><span class="k">def</span> <span class="nf">SStructureFactorDerv</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">im</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">SSGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">):</span>
     1139    <span class="s">&#39;Needs a doc string&#39;</span>
     1140    <span class="n">nxs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">newaxis</span>       
     1141    <span class="n">phfx</span> <span class="o">=</span> <span class="n">pfx</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">hfx</span>
     1142    <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>
     1143    <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>
     1144    <span class="n">SGInv</span> <span class="o">=</span> <span class="n">SGData</span><span class="p">[</span><span class="s">&#39;SGInv&#39;</span><span class="p">]</span>
     1145    <span class="n">SSGMT</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">SSGData</span><span class="p">[</span><span class="s">&#39;SSGOps&#39;</span><span class="p">]])</span>
     1146    <span class="n">SSGT</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">SSGData</span><span class="p">[</span><span class="s">&#39;SSGOps&#39;</span><span class="p">]])</span>
     1147    <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>
     1148    <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>
     1149    <span class="n">TwinLaw</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">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]],])</span>
     1150    <span class="n">TwDict</span> <span class="o">=</span> <span class="n">refDict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;TwDict&#39;</span><span class="p">,{})</span>           
     1151    <span class="k">if</span> <span class="s">&#39;S&#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>
     1152        <span class="n">NTL</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;NTL&#39;</span><span class="p">]</span>
     1153        <span class="n">NM</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinNMN&#39;</span><span class="p">]</span><span class="o">+</span><span class="mi">1</span>
     1154        <span class="n">TwinLaw</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinLaw&#39;</span><span class="p">]</span>
     1155        <span class="n">TwinFr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinFr:&#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="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">TwinLaw</span><span class="p">))])</span>
     1156        <span class="n">TwinInv</span> <span class="o">=</span> <span class="nb">list</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">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;TwinInv&#39;</span><span class="p">],</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">))</span>
     1157    <span class="n">nTwin</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">)</span>       
     1158    <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>
     1159    <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>
     1160    <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>  <span class="c">#no. atoms</span>
     1161    <span class="n">waveTypes</span><span class="p">,</span><span class="n">FSSdata</span><span class="p">,</span><span class="n">XSSdata</span><span class="p">,</span><span class="n">USSdata</span><span class="p">,</span><span class="n">MSSdata</span> <span class="o">=</span> <span class="n">GetAtomSSFXU</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>
     1162    <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>
     1163    <span class="k">if</span> <span class="s">&#39;NC&#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>
     1164        <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">BlenResCW</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>
     1165    <span class="k">elif</span> <span class="s">&#39;X&#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>
     1166        <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>
     1167        <span class="n">FPP</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;FPP&#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>
     1168    <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>
     1169    <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>
     1170    <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>
     1171        <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>
     1172            <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>        <span class="c">#will need wave here for anom. neutron b&#39;s</span>
     1173        <span class="k">else</span><span class="p">:</span>
     1174            <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>       
     1175        <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>
     1176        <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>
     1177    <span class="n">dFdvDict</span> <span class="o">=</span> <span class="p">{}</span>
     1178    <span class="k">if</span> <span class="n">nTwin</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     1179        <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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">))</span>
     1180        <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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
     1181        <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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">))</span>
     1182        <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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span>
     1183        <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="n">nTwin</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>
     1184        <span class="n">dFdfl</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">nTwin</span><span class="p">))</span>
     1185        <span class="n">dFdtw</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">nTwin</span><span class="p">))</span>
     1186        <span class="n">dFdGfA</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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="n">FSSdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
     1187        <span class="n">dFdGfB</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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="n">FSSdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
     1188        <span class="n">dFdGxA</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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="n">XSSdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">3</span><span class="p">))</span>
     1189        <span class="n">dFdGxB</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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="n">XSSdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">3</span><span class="p">))</span>
     1190        <span class="n">dFdGuA</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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="n">USSdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">6</span><span class="p">))</span>
     1191        <span class="n">dFdGuB</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">nTwin</span><span class="p">,</span><span class="n">mSize</span><span class="p">,</span><span class="n">USSdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">6</span><span class="p">))</span>
     1192    <span class="k">else</span><span class="p">:</span>
     1193        <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>
     1194        <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>
     1195        <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>
     1196        <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>
     1197        <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>
     1198        <span class="n">dFdfl</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>
     1199        <span class="n">dFdtw</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>
     1200        <span class="n">dFdGf</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="n">FSSdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">2</span><span class="p">))</span>
     1201        <span class="n">dFdGx</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="n">XSSdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">6</span><span class="p">))</span>
     1202        <span class="n">dFdGu</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="n">USSdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">12</span><span class="p">))</span>
     1203    <span class="n">Flack</span> <span class="o">=</span> <span class="mf">1.0</span>
     1204    <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> <span class="ow">and</span> <span class="s">&#39;S&#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="ow">and</span> <span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Flack&#39;</span> <span class="ow">in</span> <span class="n">parmDict</span><span class="p">:</span>
     1205        <span class="n">Flack</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">-</span><span class="mf">2.</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;Flack&#39;</span><span class="p">]</span>
     1206    <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>
     1207    <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><span class="o">/</span><span class="mi">100</span>
     1208    <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>
     1209        <span class="k">if</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>
     1210            <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">BlenResCW</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">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">12</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
     1211        <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">4</span><span class="p">])</span>
     1212<span class="c">#        H = np.squeeze(np.inner(H.T,TwinLaw))   #maybe array(4,nTwins) or (4)</span>
     1213<span class="c">#        TwMask = np.any(H,axis=-1)</span>
     1214<span class="c">#        if TwinLaw.shape[0] &gt; 1 and TwDict:</span>
     1215<span class="c">#            if iref in TwDict:</span>
     1216<span class="c">#                for i in TwDict[iref]:</span>
     1217<span class="c">#                    for n in range(NTL):</span>
     1218<span class="c">#                        H[i+n*NM] = np.inner(TwinLaw[n*NM],np.array(TwDict[iref][i])*TwinInv[i+n*NM])</span>
     1219<span class="c">#            TwMask = np.any(H,axis=-1)</span>
     1220        <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="o">+</span><span class="n">im</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>             <span class="c"># or (sin(theta)/lambda)**2</span>
     1221        <span class="n">SQfactor</span> <span class="o">=</span> <span class="mf">8.0</span><span class="o">*</span><span class="n">SQ</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">**</span><span class="mi">2</span>
     1222        <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>
     1223        <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>
     1224        <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>
     1225        <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>
     1226        <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">SSGMT</span><span class="p">)</span>
     1227        <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">SSGT</span><span class="p">)</span>
     1228        <span class="k">if</span> <span class="n">SGInv</span><span class="p">:</span>   <span class="c">#if centro - expand HKL sets</span>
     1229            <span class="n">Uniq</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">Uniq</span><span class="p">,</span><span class="o">-</span><span class="n">Uniq</span><span class="p">))</span>
     1230            <span class="n">Phi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">Phi</span><span class="p">,</span><span class="o">-</span><span class="n">Phi</span><span class="p">))</span>
     1231        <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="mi">3</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">nxs</span><span class="p">])</span>
     1232        <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>
     1233        <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>
     1234        <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="n">Uniq</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
     1235        <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">nxs</span><span class="p">]</span>
     1236        <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="n">Uniq</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</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>    <span class="c">#ops x atoms</span>
     1237        <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="p">[:,</span><span class="n">nxs</span><span class="p">,:</span><span class="mi">3</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">Uniq</span><span class="p">[:,:</span><span class="mi">3</span><span class="p">],</span><span class="n">bij</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">#ops x atoms</span>
     1238        <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="mi">3</span><span class="p">],</span><span class="n">U</span><span class="p">[:</span><span class="mi">3</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> <span class="c">#atoms x 3x3</span>
     1239        <span class="n">Hij</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</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">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><span class="n">nTwin</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">6</span><span class="p">)))</span>
     1240        <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="c">#ops x atoms</span>
     1241        <span class="n">Tcorr</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">Tiso</span><span class="p">,</span><span class="n">Tuij</span><span class="o">.</span><span class="n">shape</span><span class="p">)</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="n">Uniq</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>  <span class="c">#ops x atoms</span>
     1242        <span class="n">fot</span> <span class="o">=</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">Tcorr</span>     <span class="c">#ops x atoms</span>
     1243        <span class="n">fotp</span> <span class="o">=</span> <span class="n">FPP</span><span class="o">*</span><span class="n">Tcorr</span>            <span class="c">#ops x atoms</span>
     1244        <span class="n">GfpuA</span><span class="p">,</span><span class="n">dGdf</span><span class="p">,</span><span class="n">dGdx</span><span class="p">,</span><span class="n">dGdu</span> <span class="o">=</span> <span class="n">G2mth</span><span class="o">.</span><span class="n">ModulationDerv</span><span class="p">(</span><span class="n">waveTypes</span><span class="p">,</span><span class="n">Uniq</span><span class="p">,</span><span class="n">FSSdata</span><span class="p">,</span><span class="n">XSSdata</span><span class="p">,</span><span class="n">USSdata</span><span class="p">,</span><span class="n">Mast</span><span class="p">)</span>
     1245        <span class="c"># derivs are: ops x atoms x waves x 1,3,or 6 parms as [real,imag] parts</span>
     1246        <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">Flack</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> <span class="c"># array(2,nTwin,nEqv,nAtoms)</span>
     1247        <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">Flack</span><span class="o">*</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>
     1248        <span class="n">fag</span> <span class="o">=</span> <span class="n">fa</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">fb</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     1249        <span class="n">fbg</span> <span class="o">=</span> <span class="n">fb</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">fa</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    9891250       
    990         <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>
    991         <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>
    992         <span class="n">fax</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">fot</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="o">*</span><span class="n">sinp</span><span class="p">,</span><span class="o">-</span><span class="n">fotp</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="o">*</span><span class="n">sinp</span><span class="p">])</span>   <span class="c">#positions</span>
    993         <span class="n">fbx</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">fot</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="o">*</span><span class="n">cosp</span><span class="p">,</span><span class="o">-</span><span class="n">fot</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="o">*</span><span class="n">cosp</span><span class="p">])</span>
     1251        <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">fag</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>
     1252        <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">fbg</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>
     1253        <span class="n">fax</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">fot</span><span class="o">*</span><span class="n">sinp</span><span class="p">,</span><span class="o">-</span><span class="n">fotp</span><span class="o">*</span><span class="n">cosp</span><span class="p">])</span>   <span class="c">#positions; 2 x twin x ops x atoms</span>
     1254        <span class="n">fbx</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">fot</span><span class="o">*</span><span class="n">cosp</span><span class="p">,</span><span class="o">-</span><span class="n">fotp</span><span class="o">*</span><span class="n">sinp</span><span class="p">])</span>
     1255        <span class="n">fax</span> <span class="o">=</span> <span class="n">fax</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">fbx</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     1256        <span class="n">fbx</span> <span class="o">=</span> <span class="n">fbx</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">fax</span><span class="o">*</span><span class="n">GfpuA</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    9941257        <span class="c">#sum below is over Uniq</span>
    995         <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>        <span class="c">#Fdata != 0 ever avoids /0. problem</span>
    996         <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>
    997         <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>
    998         <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>
    999         <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>
     1258        <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">fag</span><span class="o">/</span><span class="n">occ</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">#Fdata != 0 ever avoids /0. problem</span>
     1259        <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">fbg</span><span class="o">/</span><span class="n">occ</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">#Fdata != 0 avoids /0. problem</span>
     1260        <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="n">Tcorr</span><span class="p">[:,</span><span class="n">nxs</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     1261        <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="n">Tcorr</span><span class="p">[:,</span><span class="n">nxs</span><span class="p">],</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     1262        <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">fag</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     1263        <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">fbg</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     1264<span class="c">#        GSASIIpath.IPyBreak()                  </span>
     1265        <span class="k">if</span> <span class="n">nTwin</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     1266            <span class="n">dfadx</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">twopi</span><span class="o">*</span><span class="n">Uniq</span><span class="p">[</span><span class="n">it</span><span class="p">,:,:</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fax</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,</span><span class="n">it</span><span class="p">,:,:,</span><span class="n">nxs</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="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)])</span>
     1267            <span class="n">dfbdx</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">twopi</span><span class="o">*</span><span class="n">Uniq</span><span class="p">[</span><span class="n">it</span><span class="p">,:,:</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fbx</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,</span><span class="n">it</span><span class="p">,:,:,</span><span class="n">nxs</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="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)])</span>           
     1268            <span class="n">dfadua</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="o">-</span><span class="n">Hij</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fag</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,</span><span class="n">it</span><span class="p">,:,:,</span><span class="n">nxs</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="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)])</span>
     1269            <span class="n">dfbdua</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="o">-</span><span class="n">Hij</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fbg</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,</span><span class="n">it</span><span class="p">,:,:,</span><span class="n">nxs</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="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)])</span>
     1270            <span class="c"># array(nTwin,2,nAtom,3) &amp; array(2,nTwin,nAtom,6)</span>
     1271            <span class="n">dfadGx</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="p">[:,</span><span class="n">it</span><span class="p">,:,:,</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">]</span><span class="o">*</span><span class="n">dGdx</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">,:,:,:,:]</span><span class="o">-</span><span class="n">fb</span><span class="p">[:,</span><span class="n">it</span><span class="p">,:,:,</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">]</span><span class="o">*</span><span class="n">dGdx</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">,:,:,:,:],</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     1272            <span class="n">dfbdGx</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="p">[:,</span><span class="n">it</span><span class="p">,:,:,</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">]</span><span class="o">*</span><span class="n">dGdx</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">,:,:,:,:]</span><span class="o">+</span><span class="n">fa</span><span class="p">[:,</span><span class="n">it</span><span class="p">,:,:,</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">]</span><span class="o">*</span><span class="n">dGdx</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">,:,:,:,:],</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     1273            <span class="c"># array (2,nAtom,wave,3)</span>
     1274        <span class="k">else</span><span class="p">:</span>
     1275            <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="p">[:,:</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fax</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,:,:,</span><span class="n">nxs</span><span class="p">],</span><span class="n">axis</span><span class="o">=-</span><span class="mi">2</span><span class="p">)</span>
     1276            <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="p">[:,:</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fbx</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,:,:,</span><span class="n">nxs</span><span class="p">],</span><span class="n">axis</span><span class="o">=-</span><span class="mi">2</span><span class="p">)</span>           
     1277            <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">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fag</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,:,:,</span><span class="n">nxs</span><span class="p">],</span><span class="n">axis</span><span class="o">=-</span><span class="mi">2</span><span class="p">)</span>
     1278            <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">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">fbg</span><span class="p">,</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">)[:,:,:,</span><span class="n">nxs</span><span class="p">],</span><span class="n">axis</span><span class="o">=-</span><span class="mi">2</span><span class="p">)</span>
     1279            <span class="c"># array(2,nAtom,3) &amp; array(2,nAtom,6)</span>
     1280            <span class="n">dfadGx</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="p">[:,:,:,</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">]</span><span class="o">*</span><span class="n">dGdx</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">nxs</span><span class="p">,:,:,:,:]</span><span class="o">-</span><span class="n">fb</span><span class="p">[:,:,:,</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">]</span><span class="o">*</span><span class="n">dGdx</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">nxs</span><span class="p">,:,:,:,:],</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     1281            <span class="n">dfbdGx</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="p">[:,:,:,</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">]</span><span class="o">*</span><span class="n">dGdx</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">nxs</span><span class="p">,:,:,:,:]</span><span class="o">+</span><span class="n">fa</span><span class="p">[:,:,:,</span><span class="n">nxs</span><span class="p">,</span><span class="n">nxs</span><span class="p">]</span><span class="o">*</span><span class="n">dGdx</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">nxs</span><span class="p">,:,:,:,:],</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
     1282            <span class="c"># array (2,nAtom,wave,3)</span>
    10001283        <span class="c">#NB: the above have been checked against PA(1:10,1:2) in strfctr.for for al2O3!    </span>
    1001         <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>
    1002         <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>
    1003         <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>
    1004         <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>
    1005         <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>
    1006         <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>
    1007             <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">#Fdata != 0 ever avoids /0. problem</span>
    1008             <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>           
    1009             <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>
    1010             <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>
    1011             <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>
    1012             <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>
    1013             <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>
    1014             <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>
    1015             <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>
    1016             <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>
     1284<span class="c">#        GSASIIpath.IPyBreak()</span>
     1285        <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> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">TwinLaw</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>   <span class="c">#Flack derivative</span>
     1286            <span class="n">dfadfl</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">FPP</span><span class="o">*</span><span class="n">Tcorr</span><span class="o">*</span><span class="n">sinp</span><span class="p">)</span>
     1287            <span class="n">dfbdfl</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">FPP</span><span class="o">*</span><span class="n">Tcorr</span><span class="o">*</span><span class="n">cosp</span><span class="p">)</span>
     1288        <span class="k">else</span><span class="p">:</span>
     1289            <span class="n">dfadfl</span> <span class="o">=</span> <span class="mf">1.0</span>
     1290            <span class="n">dfbdfl</span> <span class="o">=</span> <span class="mf">1.0</span>
     1291        <span class="c">#NB: the above have been checked against PA(1:10,1:2) in strfctr.for for Al2O3!    </span>
     1292        <span class="k">if</span> <span class="s">&#39;P&#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">#checked perfect for centro &amp; noncentro</span>
     1293            <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><span class="o">+</span>   \
     1294                <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>
     1295            <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><span class="o">+</span>  \
     1296                <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>
     1297            <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><span class="o">+</span>   \
     1298                <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>
     1299            <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><span class="o">+</span>   \
     1300                <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>
     1301        <span class="k">else</span><span class="p">:</span>
     1302            <span class="n">SA</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">fbs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     1303            <span class="n">SB</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">fas</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
     1304            <span class="k">if</span> <span class="n">nTwin</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     1305                <span class="n">dFdfr</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SA</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfadfr</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">it</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="n">it</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><span class="n">it</span><span class="p">])</span><span class="o">+</span> \
     1306                    <span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SB</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfbdfr</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">it</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="n">it</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><span class="n">it</span><span class="p">])</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)]</span>
     1307                <span class="n">dFdx</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SA</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfadx</span><span class="p">[</span><span class="n">it</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="n">it</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SB</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfbdx</span><span class="p">[</span><span class="n">it</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="n">it</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)]</span>
     1308                <span class="n">dFdui</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SA</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfadui</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">it</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><span class="n">it</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SB</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfbdui</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">it</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><span class="n">it</span><span class="p">])</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)]</span>
     1309                <span class="n">dFdua</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SA</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfadua</span><span class="p">[</span><span class="n">it</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="n">it</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">TwMask</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="n">SB</span><span class="p">[</span><span class="n">it</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">dfbdua</span><span class="p">[</span><span class="n">it</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="n">it</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nTwin</span><span class="p">)]</span>
     1310                <span class="n">dFdtw</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">sum</span><span class="p">(</span><span class="n">TwMask</span><span class="o">*</span><span class="n">fas</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="mi">2</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">TwMask</span><span class="o">*</span><span class="n">fbs</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="mi">2</span>
     1311               
     1312            <span class="k">else</span><span class="p">:</span>   <span class="c">#these are good for no twin single crystals</span>
     1313                <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="n">SA</span><span class="o">*</span><span class="p">(</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">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><span class="o">+</span> \
     1314                    <span class="mf">2.</span><span class="o">*</span><span class="n">SB</span><span class="o">*</span><span class="p">(</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">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> <span class="c">#array(nRef,nAtom)</span>
     1315                <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="n">SA</span><span class="o">*</span><span class="p">(</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">dfbdx</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">SB</span><span class="o">*</span><span class="p">(</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">dfadx</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>    <span class="c">#array(nRef,nAtom,3)</span>
     1316                <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="n">SA</span><span class="o">*</span><span class="p">(</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">dfbdui</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">SB</span><span class="o">*</span><span class="p">(</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">dfadui</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>   <span class="c">#array(nRef,nAtom)</span>
     1317                <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="n">SA</span><span class="o">*</span><span class="p">(</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">dfbdua</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">SB</span><span class="o">*</span><span class="p">(</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">dfadua</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>    <span class="c">#array(nRef,nAtom,6)</span>
     1318                <span class="n">dFdfl</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">SA</span><span class="o">*</span><span class="n">dfadfl</span><span class="o">-</span><span class="n">SB</span><span class="o">*</span><span class="n">dfbdfl</span>                  <span class="c">#array(nRef,)</span>
     1319                <span class="n">dFdGx</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">SA</span><span class="o">*</span><span class="p">(</span><span class="n">dfadGx</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">dfbdGx</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">SB</span><span class="o">*</span><span class="p">(</span><span class="n">dfadGx</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">dfbdGx</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>      <span class="c">#array(nRef,natom,nwave,6)</span>
     1320        <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><span class="o">+</span> \
     1321            <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>
    10171322        <span class="c">#loop over atoms - each dict entry is list of derivatives for all the reflections</span>
    1018     <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>     
     1323    <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>     <span class="c">#loop over atoms  </span>
    10191324        <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;Afrac:&#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="n">dFdfr</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
    10201325        <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;dAx:&#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="n">dFdx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     
    10251330        <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU22:&#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="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    10261331        <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU33:&#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="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    1027         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU12:&#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">3</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    1028         <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>
    1029         <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>
    1030     <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>
    1031     <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>
    1032     <span class="k">return</span> <span class="n">dFdvDict</span>
    1033     </div>
    1034 <div class="viewcode-block" id="SStructureFactorDerv"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.SStructureFactorDerv">[docs]</a><span class="k">def</span> <span class="nf">SStructureFactorDerv</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">im</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">SSGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">):</span>
    1035     <span class="s">&#39;Needs a doc string&#39;</span>
    1036     <span class="n">phfx</span> <span class="o">=</span> <span class="n">pfx</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">hfx</span>
    1037     <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>
    1038     <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>
    1039     <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>
    1040     <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>
    1041     <span class="n">SSGMT</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">SSGData</span><span class="p">[</span><span class="s">&#39;SSGOps&#39;</span><span class="p">]])</span>
    1042     <span class="n">SSGT</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">SSGData</span><span class="p">[</span><span class="s">&#39;SSGOps&#39;</span><span class="p">]])</span>
    1043     <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>
    1044     <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>
    1045     <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>
    1046     <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>
    1047     <span class="n">waveTypes</span><span class="p">,</span><span class="n">FSSdata</span><span class="p">,</span><span class="n">XSSdata</span><span class="p">,</span><span class="n">USSdata</span><span class="p">,</span><span class="n">MSSdata</span> <span class="o">=</span> <span class="n">GetAtomSSFXU</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>
    1048     <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>
    1049     <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>
    1050     <span class="k">if</span> <span class="s">&#39;NC&#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>
    1051         <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">BlenResCW</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>
    1052     <span class="k">elif</span> <span class="s">&#39;X&#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>
    1053         <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>
    1054         <span class="n">FPP</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;FPP&#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>
    1055     <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>
    1056     <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>
    1057     <span class="n">dFdvDict</span> <span class="o">=</span> <span class="p">{}</span>
    1058     <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>
    1059     <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>
    1060     <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>
    1061     <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>
    1062     <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>
    1063     <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>
    1064         <span class="k">if</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>
    1065             <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">BlenResCW</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">refl</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">12</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
    1066         <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">4</span><span class="p">])</span>
    1067         <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="o">+</span><span class="n">im</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>             <span class="c"># or (sin(theta)/lambda)**2</span>
    1068         <span class="n">SQfactor</span> <span class="o">=</span> <span class="mf">8.0</span><span class="o">*</span><span class="n">SQ</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">**</span><span class="mi">2</span>
    1069         <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>
    1070         <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>
    1071         <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>
    1072         <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>
    1073         <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="mi">3</span><span class="p">],</span><span class="n">SGMT</span><span class="p">)</span>
    1074         <span class="n">SSUniq</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">SSGMT</span><span class="p">)</span>
    1075         <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="mi">3</span><span class="p">],</span><span class="n">SGT</span><span class="p">)</span>
    1076         <span class="n">SSPhi</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">SSGT</span><span class="p">)</span>
    1077         <span class="n">GfpuA</span><span class="p">,</span><span class="n">GfpuB</span> <span class="o">=</span> <span class="n">G2mth</span><span class="o">.</span><span class="n">Modulation</span><span class="p">(</span><span class="n">waveTypes</span><span class="p">,</span><span class="n">SSUniq</span><span class="p">,</span><span class="n">SSPhi</span><span class="p">,</span><span class="n">FSSdata</span><span class="p">,</span><span class="n">XSSdata</span><span class="p">,</span><span class="n">USSdata</span><span class="p">)</span>
    1078         <span class="n">dGAdk</span><span class="p">,</span><span class="n">dGBdk</span> <span class="o">=</span> <span class="n">G2mth</span><span class="o">.</span><span class="n">ModulationDerv</span><span class="p">(</span><span class="n">waveTypes</span><span class="p">,</span><span class="n">SSUniq</span><span class="p">,</span><span class="n">SSPhi</span><span class="p">,</span><span class="n">FSSdata</span><span class="p">,</span><span class="n">XSSdata</span><span class="p">,</span><span class="n">USSdata</span><span class="p">)</span>
    1079         <span class="c">#need ModulationDerv here dGAdXsin, etc  </span>
    1080         <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>
    1081         <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>
    1082         <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>
    1083         <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>
    1084         <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>
    1085         <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>
    1086         <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="mi">3</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="mi">3</span><span class="p">]))</span>
    1087         <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>
    1088         <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>
    1089         <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>
    1090         <span class="n">Tcorr</span> <span class="o">=</span> <span class="n">Tiso</span><span class="o">*</span><span class="n">Tuij</span>
    1091         <span class="n">fot</span> <span class="o">=</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">Tcorr</span>
    1092         <span class="n">fotp</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">Tcorr</span>
    1093         <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">fot</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="o">*</span><span class="n">cosp</span><span class="p">,</span><span class="n">fotp</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="o">*</span><span class="n">cosp</span><span class="p">])</span>       <span class="c">#non positions</span>
    1094         <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">fot</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="o">*</span><span class="n">sinp</span><span class="p">,</span><span class="o">-</span><span class="n">fotp</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="o">*</span><span class="n">sinp</span><span class="p">])</span>
    1095         <span class="n">GfpuA</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">GfpuA</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
    1096         <span class="n">GfpuB</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">GfpuB</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
    1097         <span class="n">fa</span> <span class="o">=</span> <span class="n">fa</span><span class="o">*</span><span class="n">GfpuA</span><span class="o">-</span><span class="n">fb</span><span class="o">*</span><span class="n">GfpuB</span>
    1098         <span class="n">fb</span> <span class="o">=</span> <span class="n">fb</span><span class="o">*</span><span class="n">GfpuA</span><span class="o">+</span><span class="n">fa</span><span class="o">*</span><span class="n">GfpuB</span>
    1099        
    1100         <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>
    1101         <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>
    1102         <span class="n">fax</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">fot</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="o">*</span><span class="n">sinp</span><span class="p">,</span><span class="o">-</span><span class="n">fotp</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="o">*</span><span class="n">sinp</span><span class="p">])</span>   <span class="c">#positions</span>
    1103         <span class="n">fbx</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">fot</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="o">*</span><span class="n">cosp</span><span class="p">,</span><span class="o">-</span><span class="n">fot</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="o">*</span><span class="n">cosp</span><span class="p">])</span>
    1104         <span class="n">fax</span> <span class="o">=</span> <span class="n">fax</span><span class="o">*</span><span class="n">GfpuA</span><span class="o">-</span><span class="n">fbx</span><span class="o">*</span><span class="n">GfpuB</span>
    1105         <span class="n">fbx</span> <span class="o">=</span> <span class="n">fbx</span><span class="o">*</span><span class="n">GfpuA</span><span class="o">+</span><span class="n">fax</span><span class="o">*</span><span class="n">GfpuB</span>
    1106         <span class="c">#sum below is over Uniq</span>
    1107         <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>        <span class="c">#Fdata != 0 ever avoids /0. problem</span>
    1108         <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>
    1109         <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>
    1110         <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>
    1111         <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>
    1112         <span class="c">#NB: the above have been checked against PA(1:10,1:2) in strfctr.for for al2O3!    </span>
    1113         <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>
    1114         <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>
    1115         <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>
    1116         <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>
    1117         <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>
    1118         <span class="c">#need dFdXsin, etc for modulations...</span>
    1119         <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>
    1120             <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">#Fdata != 0 ever avoids /0. problem</span>
    1121             <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>           
    1122             <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>
    1123             <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>
    1124             <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>
    1125             <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>
    1126             <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>
    1127             <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>
    1128             <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>
    1129             <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>
    1130         <span class="c">#need dFdXsin, etc for modulations...</span>
    1131         <span class="c">#loop over atoms - each dict entry is list of derivatives for all the reflections</span>
    1132     <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>     
    1133         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;Afrac:&#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="n">dFdfr</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
    1134         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;dAx:&#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="n">dFdx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    1135         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;dAy:&#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="n">dFdx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    1136         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;dAz:&#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="n">dFdx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    1137         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AUiso:&#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="n">dFdui</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
    1138         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU11:&#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="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    1139         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU22:&#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="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    1140         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU33:&#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="n">dFdua</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    1141         <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU12:&#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">3</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
    1142         <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>
    1143         <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>
    1144         <span class="c">#need dFdvDict[pfx+&#39;Xsin:&#39;+str[i]:str(m)], etc for modulations...</span>
    1145     <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>
    1146     <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>
     1332        <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;AU12:&#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="o">.</span><span class="mi">5</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">3</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     1333        <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="o">.</span><span class="mi">5</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>
     1334        <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="o">.</span><span class="mi">5</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>
     1335        <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">XSSdata</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
     1336            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;Xsin:&#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="s">&#39;:&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">j</span><span class="p">)]</span> <span class="o">=</span> <span class="n">dFdGx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     1337            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;Ysin:&#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="s">&#39;:&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">j</span><span class="p">)]</span> <span class="o">=</span> <span class="n">dFdGx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     1338            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;Zsin:&#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="s">&#39;:&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">j</span><span class="p">)]</span> <span class="o">=</span> <span class="n">dFdGx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     1339            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;Xcos:&#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="s">&#39;:&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">j</span><span class="p">)]</span> <span class="o">=</span> <span class="n">dFdGx</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">3</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     1340            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;Ycos:&#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="s">&#39;:&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">j</span><span class="p">)]</span> <span class="o">=</span> <span class="n">dFdGx</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">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     1341            <span class="n">dFdvDict</span><span class="p">[</span><span class="n">pfx</span><span class="o">+</span><span class="s">&#39;Zcos:&#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="s">&#39;:&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">j</span><span class="p">)]</span> <span class="o">=</span> <span class="n">dFdGx</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">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
     1342    <span class="n">dFdvDict</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">dFdbab</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
     1343    <span class="n">dFdvDict</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">dFdbab</span><span class="o">.</span><span class="n">T</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    11471344    <span class="k">return</span> <span class="n">dFdvDict</span>
    11481345    </div>
     
    11521349    <span class="n">extCor</span> <span class="o">=</span> <span class="mf">1.0</span>
    11531350    <span class="n">dervDict</span> <span class="o">=</span> <span class="p">{}</span>
     1351    <span class="n">dervCor</span> <span class="o">=</span> <span class="mf">1.0</span>
    11541352    <span class="k">if</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;EType&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="s">&#39;None&#39;</span><span class="p">:</span>
    11551353        <span class="n">SQ</span> <span class="o">=</span> <span class="mi">1</span><span class="o">/</span><span class="p">(</span><span class="mf">4.</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">4</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
     
    12081406            <span class="n">PF3</span> <span class="o">=</span> <span class="mf">0.5</span><span class="o">*</span><span class="p">(</span><span class="n">CL</span><span class="o">+</span><span class="mf">2.</span><span class="o">*</span><span class="n">AL</span><span class="o">*</span><span class="n">PF</span><span class="o">/</span><span class="p">(</span><span class="mf">1.</span><span class="o">+</span><span class="n">BL</span><span class="o">*</span><span class="n">PF</span><span class="p">)</span><span class="o">-</span><span class="n">AL</span><span class="o">*</span><span class="n">PF</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">BL</span><span class="o">/</span><span class="p">(</span><span class="mf">1.</span><span class="o">+</span><span class="n">BL</span><span class="o">*</span><span class="n">PF</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">PF4</span><span class="o">*</span><span class="n">extCor</span><span class="p">)</span>
    12091407
     1408        <span class="n">dervCor</span> <span class="o">=</span> <span class="p">(</span><span class="mf">1.</span><span class="o">+</span><span class="n">PF</span><span class="p">)</span><span class="o">*</span><span class="n">PF3</span>   <span class="c">#extinction corr for other derivatives</span>
    12101409        <span class="k">if</span> <span class="s">&#39;Primary&#39;</span> <span class="ow">in</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;EType&#39;</span><span class="p">]</span> <span class="ow">and</span> <span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Ep&#39;</span> <span class="ow">in</span> <span class="n">varyList</span><span class="p">:</span>
    12111410            <span class="n">dervDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Ep&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">PLZ</span><span class="o">*</span><span class="n">PF3</span>
     
    12151414            <span class="n">dervDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Eg&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">PLZ</span><span class="o">*</span><span class="n">PF3</span><span class="o">*</span><span class="p">(</span><span class="n">PSIG</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;Eg&#39;</span><span class="p">])</span><span class="o">**</span><span class="mi">3</span><span class="o">*</span><span class="n">PL</span><span class="o">**</span><span class="mi">2</span>
    12161415               
    1217     <span class="k">return</span> <span class="mf">1.</span><span class="o">/</span><span class="n">extCor</span><span class="p">,</span><span class="n">dervDict</span>
     1416    <span class="k">return</span> <span class="mf">1.</span><span class="o">/</span><span class="n">extCor</span><span class="p">,</span><span class="n">dervDict</span><span class="p">,</span><span class="n">dervCor</span>
    12181417    </div>
    12191418<div class="viewcode-block" id="Dict2Values"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.Dict2Values">[docs]</a><span class="k">def</span> <span class="nf">Dict2Values</span><span class="p">(</span><span class="n">parmdict</span><span class="p">,</span> <span class="n">varylist</span><span class="p">):</span>
     
    13171516    <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>
    13181517    <span class="n">cell</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">Gmat2cell</span><span class="p">(</span><span class="n">g</span><span class="p">)</span>
    1319     <span class="n">Sangl</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.</span><span class="p">,</span><span class="mf">0.</span><span class="p">,</span><span class="mf">0.</span><span class="p">]</span>
     1518    <span class="n">Sangls</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.</span><span class="p">,</span><span class="mf">0.</span><span class="p">,</span><span class="mf">0.</span><span class="p">]</span>
    13201519    <span class="k">if</span> <span class="s">&#39;Bragg&#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;instType&#39;</span><span class="p">]:</span>
    13211520        <span class="n">Gangls</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.</span><span class="p">,</span><span class="mf">90.</span><span class="p">,</span><span class="mf">0.</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;Azimuth&#39;</span><span class="p">]]</span>
     
    13251524        <span class="n">IFCoup</span> <span class="o">=</span> <span class="bp">False</span>
    13261525    <span class="n">phi</span><span class="p">,</span><span class="n">beta</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">CrsAng</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">cell</span><span class="p">,</span><span class="n">SGData</span><span class="p">)</span>
    1327     <span class="n">psi</span><span class="p">,</span><span class="n">gam</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">x</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">SamAng</span><span class="p">(</span><span class="n">tth</span><span class="o">/</span><span class="mf">2.</span><span class="p">,</span><span class="n">Gangls</span><span class="p">,</span><span class="n">Sangl</span><span class="p">,</span><span class="n">IFCoup</span><span class="p">)</span> <span class="c">#ignore 2 sets of angle derivs.</span>
     1526    <span class="n">psi</span><span class="p">,</span><span class="n">gam</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">x</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">SamAng</span><span class="p">(</span><span class="n">tth</span><span class="o">/</span><span class="mf">2.</span><span class="p">,</span><span class="n">Gangls</span><span class="p">,</span><span class="n">Sangls</span><span class="p">,</span><span class="n">IFCoup</span><span class="p">)</span> <span class="c">#ignore 2 sets of angle derivs.</span>
    13281527    <span class="n">SHnames</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;SHnames&#39;</span><span class="p">]</span>
    13291528    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">SHnames</span><span class="p">:</span>
     
    13331532        <span class="n">Lnorm</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">Lnorm</span><span class="p">(</span><span class="n">L</span><span class="p">)</span>
    13341533        <span class="n">odfCor</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="n">item</span><span class="p">]</span><span class="o">*</span><span class="n">Lnorm</span><span class="o">*</span><span class="n">Kcl</span><span class="o">*</span><span class="n">Ksl</span>
    1335 <span class="c">#        Kcsl,Lnorm = G2lat.GetKclKsl(L,N,SGData[&#39;SGLaue&#39;],psi,phi,beta)</span>
    1336 <span class="c">#        odfCor += parmDict[phfx+item]*Lnorm*Kcsl</span>
    13371534    <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="n">odfCor</span><span class="p">)</span>
    13381535    </div>
     
    13471544    <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>
    13481545    <span class="n">cell</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">Gmat2cell</span><span class="p">(</span><span class="n">g</span><span class="p">)</span>
    1349     <span class="n">Sangl</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.</span><span class="p">,</span><span class="mf">0.</span><span class="p">,</span><span class="mf">0.</span><span class="p">]</span>
     1546    <span class="n">Sangls</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.</span><span class="p">,</span><span class="mf">0.</span><span class="p">,</span><span class="mf">0.</span><span class="p">]</span>
    13501547    <span class="k">if</span> <span class="s">&#39;Bragg&#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;instType&#39;</span><span class="p">]:</span>
    13511548        <span class="n">Gangls</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.</span><span class="p">,</span><span class="mf">90.</span><span class="p">,</span><span class="mf">0.</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;Azimuth&#39;</span><span class="p">]]</span>
     
    13551552        <span class="n">IFCoup</span> <span class="o">=</span> <span class="bp">False</span>
    13561553    <span class="n">phi</span><span class="p">,</span><span class="n">beta</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">CrsAng</span><span class="p">(</span><span class="n">H</span><span class="p">,</span><span class="n">cell</span><span class="p">,</span><span class="n">SGData</span><span class="p">)</span>
    1357     <span class="n">psi</span><span class="p">,</span><span class="n">gam</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">x</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">SamAng</span><span class="p">(</span><span class="n">tth</span><span class="o">/</span><span class="mf">2.</span><span class="p">,</span><span class="n">Gangls</span><span class="p">,</span><span class="n">Sangl</span><span class="p">,</span><span class="n">IFCoup</span><span class="p">)</span> <span class="c">#ignore 2 sets of angle derivs.</span>
     1554    <span class="n">psi</span><span class="p">,</span><span class="n">gam</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">x</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">SamAng</span><span class="p">(</span><span class="n">tth</span><span class="o">/</span><span class="mf">2.</span><span class="p">,</span><span class="n">Gangls</span><span class="p">,</span><span class="n">Sangls</span><span class="p">,</span><span class="n">IFCoup</span><span class="p">)</span> <span class="c">#ignore 2 sets of angle derivs.</span>
    13581555    <span class="n">SHnames</span> <span class="o">=</span> <span class="n">calcControls</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;SHnames&#39;</span><span class="p">]</span>
    13591556    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">SHnames</span><span class="p">:</span>
     
    13641561        <span class="n">odfCor</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="n">item</span><span class="p">]</span><span class="o">*</span><span class="n">Lnorm</span><span class="o">*</span><span class="n">Kcl</span><span class="o">*</span><span class="n">Ksl</span>
    13651562        <span class="n">dFdODF</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="n">item</span><span class="p">]</span> <span class="o">=</span> <span class="n">Kcl</span><span class="o">*</span><span class="n">Ksl</span><span class="o">*</span><span class="n">Lnorm</span>
    1366 <span class="c">#        Kcsl,Lnorm = G2lat.GetKclKsl(L,N,SGData[&#39;SGLaue&#39;],psi,phi,beta) </span>
    1367 <span class="c">#        odfCor += parmDict[phfx+item]*Lnorm*Kcsl</span>
    1368 <span class="c">#        dFdODF[phfx+item] = Kcsl*Lnorm</span>
    13691563    <span class="k">return</span> <span class="n">odfCor</span><span class="p">,</span><span class="n">dFdODF</span>
    13701564    </div>
     
    14411635    <span class="n">exb</span> <span class="o">=</span> <span class="mf">1.0</span>
    14421636    <span class="k">if</span> <span class="n">xfac</span> <span class="o">&gt;</span> <span class="o">-</span><span class="mf">1.</span><span class="p">:</span>
    1443         <span class="n">exb</span> <span class="o">=</span> <span class="mf">1.</span><span class="o">/</span><span class="p">(</span><span class="mf">1.</span><span class="o">+</span><span class="n">xfac</span><span class="p">)</span>
     1637        <span class="n">exb</span> <span class="o">=</span> <span class="mf">1.</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="mf">1.</span><span class="o">+</span><span class="n">xfac</span><span class="p">)</span>
    14441638    <span class="n">exl</span> <span class="o">=</span> <span class="mf">1.0</span>
    14451639    <span class="k">if</span> <span class="mi">0</span> <span class="o">&lt;</span> <span class="n">xfac</span> <span class="o">&lt;=</span> <span class="mf">1.</span><span class="p">:</span>
     
    14681662    <span class="n">dbde</span> <span class="o">=</span> <span class="o">-</span><span class="mf">500.</span><span class="o">*</span><span class="n">flv2</span>
    14691663    <span class="k">if</span> <span class="n">xfac</span> <span class="o">&gt;</span> <span class="o">-</span><span class="mf">1.</span><span class="p">:</span>
    1470         <span class="n">dbde</span> <span class="o">=</span> <span class="o">-</span><span class="n">flv2</span><span class="o">/</span><span class="p">(</span><span class="mf">1.</span><span class="o">+</span><span class="n">xfac</span><span class="p">)</span><span class="o">**</span><span class="mi">3</span>
     1664        <span class="n">dbde</span> <span class="o">=</span> <span class="o">-</span><span class="mf">0.5</span><span class="o">*</span><span class="n">flv2</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="mf">1.</span><span class="o">+</span><span class="n">xfac</span><span class="p">)</span><span class="o">**</span><span class="mi">3</span>
    14711665    <span class="n">dlde</span> <span class="o">=</span> <span class="mf">0.</span>
    14721666    <span class="k">if</span> <span class="mi">0</span> <span class="o">&lt;</span> <span class="n">xfac</span> <span class="o">&lt;=</span> <span class="mf">1.</span><span class="p">:</span>
     
    14781672       
    14791673    <span class="k">return</span> <span class="n">dbde</span><span class="o">*</span><span class="n">sth2</span><span class="o">+</span><span class="n">dlde</span><span class="o">*</span><span class="p">(</span><span class="mf">1.</span><span class="o">-</span><span class="n">sth2</span><span class="p">)</span>
    1480 
    1481 
    1482 <span class="c">#    delt = 0.01</span>
    1483 <span class="c">#    parmDict[phfx+&#39;Extinction&#39;] += delt</span>
    1484 <span class="c">#    plus = GetPwdrExt(refl,im,pfx,phfx,hfx,calcControls,parmDict)</span>
    1485 <span class="c">#    parmDict[phfx+&#39;Extinction&#39;] -= 2.*delt</span>
    1486 <span class="c">#    minus = GetPwdrExt(refl,im,pfx,phfx,hfx,calcControls,parmDict)</span>
    1487 <span class="c">#    parmDict[phfx+&#39;Extinction&#39;] += delt</span>
    1488 <span class="c">#    return (plus-minus)/(2.*delt)    </span>
    14891674    </div>
    14901675<div class="viewcode-block" id="GetIntensityCorr"><a class="viewcode-back" href="../GSASIIstruc.html#GSASIIstrMath.GetIntensityCorr">[docs]</a><span class="k">def</span> <span class="nf">GetIntensityCorr</span><span class="p">(</span><span class="n">refl</span><span class="p">,</span><span class="n">im</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>
     
    24182603                <span class="k">if</span> <span class="n">refl</span><span class="p">[</span><span class="mi">9</span><span class="o">+</span><span class="n">im</span><span class="p">]:</span>
    24192604                    <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>
    2420                         <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="o">+</span><span class="n">im</span><span class="p">]</span>
     2605                        <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">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">dFdvDict</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">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="o">+</span><span class="n">im</span><span class="p">]</span>
    24212606                        <span class="k">if</span> <span class="n">Ka2</span> <span class="ow">and</span> <span class="n">iFin2</span><span class="o">-</span><span class="n">iBeg2</span><span class="p">:</span>
    2422                             <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="o">+</span><span class="n">im</span><span class="p">]</span>
     2607                            <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">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">dFdvDict</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">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="o">+</span><span class="n">im</span><span class="p">]</span>
    24232608                    <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>                   
    2424                         <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="o">+</span><span class="n">im</span><span class="p">]</span>
     2609                        <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">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">dFdvDict</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">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="o">+</span><span class="n">im</span><span class="p">]</span>
    24252610                        <span class="k">if</span> <span class="n">Ka2</span> <span class="ow">and</span> <span class="n">iFin2</span><span class="o">-</span><span class="n">iBeg2</span><span class="p">:</span>
    2426                             <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="o">+</span><span class="n">im</span><span class="p">]</span>                 
     2611                            <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">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">dFdvDict</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">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="o">+</span><span class="n">im</span><span class="p">]</span>                 
    24272612            <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>
    24282613                <span class="c">#do atom derivatives -  for RB,F,X &amp; U so far              </span>
     
    24842669    <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>
    24852670    <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>
     2671    <span class="k">if</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mf">0.</span><span class="p">:</span>
     2672        <span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="o">.</span><span class="mo">001</span>
    24862673    <span class="k">if</span> <span class="n">im</span><span class="p">:</span>
    24872674        <span class="n">dFdvDict</span> <span class="o">=</span> <span class="n">SStructureFactorDerv</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">im</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">SSGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
     
    24982685        <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>
    24992686            <span class="k">if</span> <span class="n">ref</span><span class="p">[</span><span class="mi">6</span><span class="o">+</span><span class="n">im</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
    2500                 <span class="n">dervDict</span> <span class="o">=</span> <span class="n">SCExtinction</span><span class="p">(</span><span class="n">ref</span><span class="p">,</span><span class="n">im</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">pfx</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="n">varylist</span><span class="o">+</span><span class="n">dependentVars</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
     2687                <span class="n">dervDict</span><span class="p">,</span><span class="n">dervCor</span> <span class="o">=</span> <span class="n">SCExtinction</span><span class="p">(</span><span class="n">ref</span><span class="p">,</span><span class="n">im</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">pfx</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="n">varylist</span><span class="o">+</span><span class="n">dependentVars</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]</span>
    25012688                <span class="n">w</span> <span class="o">=</span> <span class="mf">1.0</span><span class="o">/</span><span class="n">ref</span><span class="p">[</span><span class="mi">6</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
    25022689                <span class="k">if</span> <span class="n">ref</span><span class="p">[</span><span class="mi">3</span><span class="o">+</span><span class="n">im</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
     
    25092696                            <span class="n">depDerivDict</span><span class="p">[</span><span class="n">var</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">dFdvDict</span><span class="p">[</span><span class="n">var</span><span class="p">][</span><span class="n">iref</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;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
    25102697                    <span class="k">if</span> <span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span> <span class="ow">in</span> <span class="n">varylist</span><span class="p">:</span>
    2511                         <span class="n">dMdvh</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="s">&#39;Scale&#39;</span><span class="p">)][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">9</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
     2698                        <span class="n">dMdvh</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="s">&#39;Scale&#39;</span><span class="p">)][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</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;Scale&#39;</span><span class="p">]</span>  <span class="c">#OK</span>
    25122699                    <span class="k">elif</span> <span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span> <span class="ow">in</span> <span class="n">dependentVars</span><span class="p">:</span>
    2513                         <span class="n">depDerivDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">9</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
     2700                        <span class="n">depDerivDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</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;Scale&#39;</span><span class="p">]</span>   <span class="c">#OK</span>
    25142701                    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;Ep&#39;</span><span class="p">,</span><span class="s">&#39;Es&#39;</span><span class="p">,</span><span class="s">&#39;Eg&#39;</span><span class="p">]:</span>
    25152702                        <span class="k">if</span> <span class="n">phfx</span><span class="o">+</span><span class="n">item</span> <span class="ow">in</span> <span class="n">varylist</span> <span class="ow">and</span> <span class="n">phfx</span><span class="o">+</span><span class="n">item</span> <span class="ow">in</span> <span class="n">dervDict</span><span class="p">:</span>
     
    25222709                        <span class="k">elif</span> <span class="n">phfx</span><span class="o">+</span><span class="n">item</span> <span class="ow">in</span> <span class="n">dependentVars</span><span class="p">:</span>
    25232710                            <span class="n">depDerivDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="n">item</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</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">item</span><span class="p">][</span><span class="n">iref</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;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
    2524     <span class="k">else</span><span class="p">:</span>
     2711    <span class="k">else</span><span class="p">:</span>   <span class="c">#F refinement</span>
    25252712        <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>
    25262713            <span class="k">if</span> <span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mf">0.</span><span class="p">:</span>
    2527                 <span class="n">dervDict</span> <span class="o">=</span> <span class="n">SCExtinction</span><span class="p">(</span><span class="n">ref</span><span class="p">,</span><span class="n">im</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">pfx</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="n">varylist</span><span class="o">+</span><span class="n">dependentVars</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
     2714                <span class="n">dervDict</span><span class="p">,</span><span class="n">dervCor</span> <span class="o">=</span> <span class="n">SCExtinction</span><span class="p">(</span><span class="n">ref</span><span class="p">,</span><span class="n">im</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">pfx</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="n">varylist</span><span class="o">+</span><span class="n">dependentVars</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]</span>
    25282715                <span class="n">Fo</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">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
    25292716                <span class="n">Fc</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">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
    25302717                <span class="n">w</span> <span class="o">=</span> <span class="mf">1.0</span><span class="o">/</span><span class="n">ref</span><span class="p">[</span><span class="mi">6</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
    25312718                <span class="k">if</span> <span class="n">ref</span><span class="p">[</span><span class="mi">3</span><span class="o">+</span><span class="n">im</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
    2532                     <span class="n">wdf</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="mf">2.0</span><span class="o">*</span><span class="n">Fo</span><span class="o">*</span><span class="n">w</span><span class="o">*</span><span class="p">(</span><span class="n">Fo</span><span class="o">-</span><span class="n">Fc</span><span class="p">)</span>
     2719                    <span class="n">wdf</span><span class="p">[</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="mf">2.0</span><span class="o">*</span><span class="n">Fc</span><span class="o">*</span><span class="n">w</span><span class="o">*</span><span class="p">(</span><span class="n">Fo</span><span class="o">-</span><span class="n">Fc</span><span class="p">)</span>
    25332720                    <span class="k">for</span> <span class="n">j</span><span class="p">,</span><span class="n">var</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">varylist</span><span class="p">):</span>
    25342721                        <span class="k">if</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">dFdvDict</span><span class="p">:</span>
     
    25382725                            <span class="n">depDerivDict</span><span class="p">[</span><span class="n">var</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">dFdvDict</span><span class="p">[</span><span class="n">var</span><span class="p">][</span><span class="n">iref</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;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
    25392726                    <span class="k">if</span> <span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span> <span class="ow">in</span> <span class="n">varylist</span><span class="p">:</span>
    2540                         <span class="n">dMdvh</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="s">&#39;Scale&#39;</span><span class="p">)][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">9</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
     2727                        <span class="n">dMdvh</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="s">&#39;Scale&#39;</span><span class="p">)][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</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;Scale&#39;</span><span class="p">]</span>  <span class="c">#OK</span>
    25412728                    <span class="k">elif</span> <span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span> <span class="ow">in</span> <span class="n">dependentVars</span><span class="p">:</span>
    2542                         <span class="n">depDerivDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">9</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>                           
    2543                     <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;Ep&#39;</span><span class="p">,</span><span class="s">&#39;Es&#39;</span><span class="p">,</span><span class="s">&#39;Eg&#39;</span><span class="p">]:</span>
     2729                        <span class="n">depDerivDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</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;Scale&#39;</span><span class="p">]</span>   <span class="c">#OK                    </span>
     2730                    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;Ep&#39;</span><span class="p">,</span><span class="s">&#39;Es&#39;</span><span class="p">,</span><span class="s">&#39;Eg&#39;</span><span class="p">]:</span>   <span class="c">#OK!</span>
    25442731                        <span class="k">if</span> <span class="n">phfx</span><span class="o">+</span><span class="n">item</span> <span class="ow">in</span> <span class="n">varylist</span> <span class="ow">and</span> <span class="n">phfx</span><span class="o">+</span><span class="n">item</span> <span class="ow">in</span> <span class="n">dervDict</span><span class="p">:</span>
    2545                             <span class="n">dMdvh</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">item</span><span class="p">)][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">dervDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="n">item</span><span class="p">]</span><span class="o">/</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>  <span class="c">#correct</span>
     2732                            <span class="n">dMdvh</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">item</span><span class="p">)][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">dervDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="n">item</span><span class="p">]</span><span class="o">/</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
    25462733                        <span class="k">elif</span> <span class="n">phfx</span><span class="o">+</span><span class="n">item</span> <span class="ow">in</span> <span class="n">dependentVars</span> <span class="ow">and</span> <span class="n">phfx</span><span class="o">+</span><span class="n">item</span> <span class="ow">in</span> <span class="n">dervDict</span><span class="p">:</span>
    25472734                            <span class="n">depDerivDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="n">item</span><span class="p">][</span><span class="n">iref</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="o">*</span><span class="n">dervDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="n">item</span><span class="p">]</span><span class="o">/</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
     
    26212808    <span class="n">G2mv</span><span class="o">.</span><span class="n">Dict2Map</span><span class="p">(</span><span class="n">parmDict</span><span class="p">,</span><span class="n">varylist</span><span class="p">)</span>
    26222809    <span class="n">Histograms</span><span class="p">,</span><span class="n">Phases</span><span class="p">,</span><span class="n">restraintDict</span><span class="p">,</span><span class="n">rigidbodyDict</span> <span class="o">=</span> <span class="n">HistoPhases</span>
     2810    <span class="c">#fixup H atom positions here?</span>
    26232811    <span class="n">ApplyRBModels</span><span class="p">(</span><span class="n">parmDict</span><span class="p">,</span><span class="n">Phases</span><span class="p">,</span><span class="n">rigidbodyDict</span><span class="p">)</span>        <span class="c">#,Update=True??</span>
    26242812    <span class="n">nvar</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">varylist</span><span class="p">)</span>
     
    26972885    <span class="n">Next</span> <span class="o">=</span> <span class="mi">0</span>
    26982886    <span class="n">ApplyRBModels</span><span class="p">(</span><span class="n">parmDict</span><span class="p">,</span><span class="n">Phases</span><span class="p">,</span><span class="n">rigidbodyDict</span><span class="p">)</span>
     2887    <span class="c">#fixup Hatom positions here....</span>
    26992888    <span class="n">histoList</span> <span class="o">=</span> <span class="n">Histograms</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
    27002889    <span class="n">histoList</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
     
    27542943            <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>
    27552944            <span class="n">im</span> <span class="o">=</span> <span class="mi">0</span>
     2945            <span class="k">if</span> <span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mf">0.</span><span class="p">:</span>
     2946                <span class="n">parmDict</span><span class="p">[</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Scale&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="o">.</span><span class="mo">001</span>               
    27562947            <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="s">&#39;Type&#39;</span><span class="p">]</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;modulated&#39;</span><span class="p">,</span><span class="s">&#39;magnetic&#39;</span><span class="p">]:</span>
    27572948                <span class="n">SSGData</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;SSGData&#39;</span><span class="p">]</span>
     
    27632954            <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>
    27642955            <span class="k">if</span> <span class="n">im</span><span class="p">:</span>
    2765                 <span class="n">SStructureFactor</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">im</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">SSGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
     2956                <span class="n">SStructureFactor2</span><span class="p">(</span><span class="n">refDict</span><span class="p">,</span><span class="n">im</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">SSGData</span><span class="p">,</span><span class="n">calcControls</span><span class="p">,</span><span class="n">parmDict</span><span class="p">)</span>
    27662957            <span class="k">else</span><span class="p">:</span>
    27672958                <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>
     
    27732964            <span class="n">sumdF</span> <span class="o">=</span> <span class="mi">0</span>
    27742965            <span class="n">sumdF2</span> <span class="o">=</span> <span class="mi">0</span>
     2966            <span class="k">if</span> <span class="n">im</span><span class="p">:</span>
     2967                <span class="n">sumSSFo</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="mi">10</span><span class="p">)</span>
     2968                <span class="n">sumSSFo2</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="mi">10</span><span class="p">)</span>
     2969                <span class="n">sumSSdF</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="mi">10</span><span class="p">)</span>
     2970                <span class="n">sumSSdF2</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="mi">10</span><span class="p">)</span>
     2971                <span class="n">sumSSwYo</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="mi">10</span><span class="p">)</span>
     2972                <span class="n">sumSSwdf2</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="mi">10</span><span class="p">)</span>
     2973                <span class="n">SSnobs</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="mi">10</span><span class="p">)</span>
    27752974            <span class="n">nobs</span> <span class="o">=</span> <span class="mi">0</span>
    27762975            <span class="n">nrej</span> <span class="o">=</span> <span class="mi">0</span>
    27772976            <span class="nb">next</span> <span class="o">=</span> <span class="mi">0</span>
     2977            <span class="n">maxH</span> <span class="o">=</span> <span class="mi">0</span>
    27782978            <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>
    27792979                <span class="k">for</span> <span class="n">i</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>
     
    27812981                        <span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span> <span class="o">=</span> <span class="n">SCExtinction</span><span class="p">(</span><span class="n">ref</span><span class="p">,</span><span class="n">im</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">pfx</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="n">varylist</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
    27822982                        <span class="n">w</span> <span class="o">=</span> <span class="mf">1.0</span><span class="o">/</span><span class="n">ref</span><span class="p">[</span><span class="mi">6</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>   <span class="c"># 1/sig(F^2)</span>
    2783                         <span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</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;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">9</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>  <span class="c">#correct Fc^2 for extinction</span>
     2983                        <span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</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;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>  <span class="c">#correct Fc^2 for extinction</span>
    27842984                        <span class="n">ref</span><span class="p">[</span><span class="mi">8</span><span class="o">+</span><span class="n">im</span><span class="p">]</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">/</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;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
    27852985                        <span class="k">if</span> <span class="n">UserRejectHKL</span><span class="p">(</span><span class="n">ref</span><span class="p">,</span><span class="n">im</span><span class="p">,</span><span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;UsrReject&#39;</span><span class="p">])</span> <span class="ow">and</span> <span class="n">ref</span><span class="p">[</span><span class="mi">3</span><span class="o">+</span><span class="n">im</span><span class="p">]:</span>    <span class="c">#skip sp.gp. absences (mul=0)</span>
     
    27932993                            <span class="n">df</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">w</span><span class="o">*</span><span class="p">(</span><span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">-</span><span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
    27942994                            <span class="n">sumwYo</span> <span class="o">+=</span> <span class="p">(</span><span class="n">w</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>      <span class="c">#w*Fo^2</span>
     2995                            <span class="k">if</span> <span class="n">im</span><span class="p">:</span>  <span class="c">#accumulate super lattice sums</span>
     2996                                <span class="n">ind</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">ref</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span>
     2997                                <span class="n">sumSSFo</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="n">Fo</span>
     2998                                <span class="n">sumSSFo2</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
     2999                                <span class="n">sumSSdF</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">Fo</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">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">]))</span>
     3000                                <span class="n">sumSSdF2</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">-</span><span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
     3001                                <span class="n">sumSSwYo</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="p">(</span><span class="n">w</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>      <span class="c">#w*Fo^2</span>
     3002                                <span class="n">sumSSwdf2</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span>  <span class="n">df</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span>
     3003                                <span class="n">SSnobs</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
     3004                                <span class="n">maxH</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">maxH</span><span class="p">,</span><span class="n">ind</span><span class="p">)</span>                           
    27953005                        <span class="k">else</span><span class="p">:</span>
    27963006                            <span class="k">if</span> <span class="n">ref</span><span class="p">[</span><span class="mi">3</span><span class="o">+</span><span class="n">im</span><span class="p">]:</span>
     
    28033013                    <span class="k">if</span> <span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mf">0.</span><span class="p">:</span>
    28043014                        <span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span> <span class="o">=</span> <span class="n">SCExtinction</span><span class="p">(</span><span class="n">ref</span><span class="p">,</span><span class="n">im</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">pfx</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="n">varylist</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
    2805                         <span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</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;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">9</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>    <span class="c">#correct Fc^2 for extinction</span>
     3015                        <span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</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;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>    <span class="c">#correct Fc^2 for extinction</span>
    28063016                        <span class="n">ref</span><span class="p">[</span><span class="mi">8</span><span class="o">+</span><span class="n">im</span><span class="p">]</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">/</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;Scale&#39;</span><span class="p">]</span><span class="o">*</span><span class="n">ref</span><span class="p">[</span><span class="mi">11</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
    28073017                        <span class="n">Fo</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">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
    28083018                        <span class="n">Fc</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">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
    2809                         <span class="n">w</span> <span class="o">=</span> <span class="mf">2.0</span><span class="o">*</span><span class="p">(</span><span class="n">Fo</span><span class="o">/</span><span class="n">ref</span><span class="p">[</span><span class="mi">6</span><span class="o">+</span><span class="n">im</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span>    <span class="c"># 1/sig(F)?</span>
     3019                        <span class="n">w</span> <span class="o">=</span> <span class="mf">2.0</span><span class="o">*</span><span class="n">Fo</span><span class="o">/</span><span class="n">ref</span><span class="p">[</span><span class="mi">6</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>    <span class="c"># 1/sig(F)?</span>
    28103020                        <span class="k">if</span> <span class="n">UserRejectHKL</span><span class="p">(</span><span class="n">ref</span><span class="p">,</span><span class="n">im</span><span class="p">,</span><span class="n">calcControls</span><span class="p">[</span><span class="s">&#39;UsrReject&#39;</span><span class="p">])</span> <span class="ow">and</span> <span class="n">ref</span><span class="p">[</span><span class="mi">3</span><span class="o">+</span><span class="n">im</span><span class="p">]:</span>    <span class="c">#skip sp.gp. absences (mul=0)</span>
    28113021                            <span class="n">ref</span><span class="p">[</span><span class="mi">3</span><span class="o">+</span><span class="n">im</span><span class="p">]</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">ref</span><span class="p">[</span><span class="mi">3</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>      <span class="c">#mark as allowed</span>
     
    28173027                            <span class="n">df</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">w</span><span class="o">*</span><span class="p">(</span><span class="n">Fo</span><span class="o">-</span><span class="n">Fc</span><span class="p">)</span>
    28183028                            <span class="n">sumwYo</span> <span class="o">+=</span> <span class="p">(</span><span class="n">w</span><span class="o">*</span><span class="n">Fo</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
     3029                            <span class="k">if</span> <span class="n">im</span><span class="p">:</span>
     3030                                <span class="n">ind</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">ref</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span>
     3031                                <span class="n">sumSSFo</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="n">Fo</span>
     3032                                <span class="n">sumSSFo2</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">]</span>
     3033                                <span class="n">sumSSdF</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">Fo</span><span class="o">-</span><span class="n">Fc</span><span class="p">)</span>
     3034                                <span class="n">sumSSdF2</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">ref</span><span class="p">[</span><span class="mi">5</span><span class="o">+</span><span class="n">im</span><span class="p">]</span><span class="o">-</span><span class="n">ref</span><span class="p">[</span><span class="mi">7</span><span class="o">+</span><span class="n">im</span><span class="p">])</span>
     3035                                <span class="n">sumSSwYo</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="p">(</span><span class="n">w</span><span class="o">*</span><span class="n">Fo</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>                                                           
     3036                                <span class="n">sumSSwdf2</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span>  <span class="n">df</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span>
     3037                                <span class="n">SSnobs</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>                           
     3038                                <span class="n">maxH</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">maxH</span><span class="p">,</span><span class="n">ind</span><span class="p">)</span>                           
    28193039                        <span class="k">else</span><span class="p">:</span>
    28203040                            <span class="k">if</span> <span class="n">ref</span><span class="p">[</span><span class="mi">3</span><span class="o">+</span><span class="n">im</span><span class="p">]:</span>
     
    28323052            <span class="n">Histogram</span><span class="p">[</span><span class="s">&#39;Residuals&#39;</span><span class="p">][</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Nrej&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">nrej</span>
    28333053            <span class="n">Histogram</span><span class="p">[</span><span class="s">&#39;Residuals&#39;</span><span class="p">][</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;Next&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">next</span>
     3054            <span class="k">if</span> <span class="n">im</span><span class="p">:</span>
     3055                <span class="n">Histogram</span><span class="p">[</span><span class="s">&#39;Residuals&#39;</span><span class="p">][</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;SSRf&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">100.</span><span class="o">*</span><span class="n">sumSSdF</span><span class="p">[:</span><span class="n">maxH</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="n">sumSSFo</span><span class="p">[:</span><span class="n">maxH</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span>
     3056                <span class="n">Histogram</span><span class="p">[</span><span class="s">&#39;Residuals&#39;</span><span class="p">][</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;SSRf^2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">100.</span><span class="o">*</span><span class="n">sumSSdF2</span><span class="p">[:</span><span class="n">maxH</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="n">sumSSFo2</span><span class="p">[:</span><span class="n">maxH</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span>
     3057                <span class="n">Histogram</span><span class="p">[</span><span class="s">&#39;Residuals&#39;</span><span class="p">][</span><span class="n">phfx</span><span class="o">+</span><span class="s">&#39;SSNref&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">SSnobs</span><span class="p">[:</span><span class="n">maxH</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span>
     3058                <span class="n">Histogram</span><span class="p">[</span><span class="s">&#39;Residuals&#39;</span><span class="p">][</span><span class="s">&#39;SSwR&#39;</span><span class="p">]</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">sumSSwdf2</span><span class="p">[:</span><span class="n">maxH</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="n">sumSSwYo</span><span class="p">[:</span><span class="n">maxH</span><span class="o">+</span><span class="mi">1</span><span class="p">])</span><span class="o">*</span><span class="mf">100.</span>               
    28343059            <span class="n">Nobs</span> <span class="o">+=</span> <span class="n">nobs</span>
    28353060            <span class="n">Nrej</span> <span class="o">+=</span> <span class="n">nrej</span>
Note: See TracChangeset for help on using the changeset viewer.