Ignore:
Timestamp:
Jan 5, 2014 9:22:22 AM (8 years ago)
Author:
toby
Message:

fixup number formatting; update produced doc files

File:
1 edited

Legend:

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

    r1168 r1183  
    5353<span class="c"># -*- coding: utf-8 -*-</span>
    5454<span class="c">########### SVN repository information ###################</span>
    55 <span class="c"># $Date: 2013-10-25 14:24:22 -0500 (Fri, 25 Oct 2013) $</span>
     55<span class="c"># $Date: 2013-12-16 10:43:01 -0600 (Mon, 16 Dec 2013) $</span>
    5656<span class="c"># $Author: toby $</span>
    57 <span class="c"># $Revision: 1123 $</span>
     57<span class="c"># $Revision: 1168 $</span>
    5858<span class="c"># $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/imports/G2phase.py $</span>
    59 <span class="c"># $Id: G2phase.py 1123 2013-10-25 19:24:22Z toby $</span>
     59<span class="c"># $Id: G2phase.py 1168 2013-12-16 16:43:01Z toby $</span>
    6060<span class="c">########### SVN repository information ###################</span>
    6161<span class="c">#</span>
     
    7070
    7171<span class="kn">import</span> <span class="nn">sys</span>
     72<span class="kn">import</span> <span class="nn">math</span>
     73<span class="kn">import</span> <span class="nn">random</span> <span class="kn">as</span> <span class="nn">ran</span>
    7274<span class="kn">import</span> <span class="nn">traceback</span>
     75<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
     76<span class="kn">import</span> <span class="nn">wx</span>
    7377<span class="kn">import</span> <span class="nn">GSASIIIO</span> <span class="kn">as</span> <span class="nn">G2IO</span>
     78<span class="kn">import</span> <span class="nn">GSASIIspc</span> <span class="kn">as</span> <span class="nn">G2spc</span>
     79<span class="kn">import</span> <span class="nn">GSASIIlattice</span> <span class="kn">as</span> <span class="nn">G2lat</span>
    7480<span class="kn">import</span> <span class="nn">GSASIIpath</span>
    75 <span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1123 $&quot;</span><span class="p">)</span>
     81<span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1168 $&quot;</span><span class="p">)</span>
    7682
    7783<div class="viewcode-block" id="PDB_ReaderClass"><a class="viewcode-back" href="../imports.html#G2phase.PDB_ReaderClass">[docs]</a><span class="k">class</span> <span class="nc">PDB_ReaderClass</span><span class="p">(</span><span class="n">G2IO</span><span class="o">.</span><span class="n">ImportPhase</span><span class="p">):</span>
     
    8490            <span class="n">longFormatName</span> <span class="o">=</span> <span class="s">&#39;Original Protein Data Bank (.pdb file) import&#39;</span>
    8591            <span class="p">)</span>
    86     <span class="c"># I don&#39;t know enough to validate the contents</span>
    87     <span class="c">#def ContentsValidator(self, filepointer):</span>
    88     <span class="c">#    filepointer.seek(0) # rewind the file pointer</span>
    89     <span class="c">#    return True</span>
    90 
     92<div class="viewcode-block" id="PDB_ReaderClass.ContentsValidator"><a class="viewcode-back" href="../imports.html#G2phase.PDB_ReaderClass.ContentsValidator">[docs]</a>    <span class="k">def</span> <span class="nf">ContentsValidator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filepointer</span><span class="p">):</span>
     93        <span class="sd">&#39;&#39;&#39;Taking a stab a validating a PDB file</span>
     94<span class="sd">        (look for cell &amp; at least one atom)</span>
     95<span class="sd">        &#39;&#39;&#39;</span>
     96        <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">l</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">filepointer</span><span class="p">):</span>
     97            <span class="k">if</span> <span class="n">l</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;CRYST1&#39;</span><span class="p">):</span>
     98                <span class="k">break</span>
     99        <span class="k">else</span><span class="p">:</span>
     100            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;no CRYST1 record found&#39;</span>
     101            <span class="k">return</span> <span class="bp">False</span>
     102        <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">l</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">filepointer</span><span class="p">):</span>
     103            <span class="k">if</span> <span class="n">l</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;ATOM&#39;</span><span class="p">):</span>
     104                <span class="k">return</span> <span class="bp">True</span>
     105        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;no ATOM records found after CRYST1 record&#39;</span>
     106        <span class="k">return</span> <span class="bp">False</span>
     107</div>
    91108<div class="viewcode-block" id="PDB_ReaderClass.Reader"><a class="viewcode-back" href="../imports.html#G2phase.PDB_ReaderClass.Reader">[docs]</a>    <span class="k">def</span> <span class="nf">Reader</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">filename</span><span class="p">,</span><span class="n">filepointer</span><span class="p">,</span> <span class="n">ParentFrame</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">unused</span><span class="p">):</span>
     109        <span class="s">&#39;Read a PDF file using :meth:`ReadPDBPhase`&#39;</span>
    92110        <span class="k">try</span><span class="p">:</span>
    93             <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span> <span class="o">=</span> <span class="n">G2IO</span><span class="o">.</span><span class="n">ReadPDBPhase</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
     111            <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ReadPDBPhase</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">ParentFrame</span><span class="p">)</span>
    94112            <span class="k">return</span> <span class="bp">True</span>
    95113        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">detail</span><span class="p">:</span>
     114            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">detail</span><span class="p">)</span>
    96115            <span class="k">print</span> <span class="s">&#39;PDB read error:&#39;</span><span class="p">,</span><span class="n">detail</span> <span class="c"># for testing</span>
    97116            <span class="n">traceback</span><span class="o">.</span><span class="n">print_exc</span><span class="p">(</span><span class="nb">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span>
    98117            <span class="k">return</span> <span class="bp">False</span>
     118        </div>
     119<div class="viewcode-block" id="PDB_ReaderClass.ReadPDBPhase"><a class="viewcode-back" href="../imports.html#G2phase.PDB_ReaderClass.ReadPDBPhase">[docs]</a>    <span class="k">def</span> <span class="nf">ReadPDBPhase</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">filename</span><span class="p">,</span><span class="n">parent</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
     120        <span class="sd">&#39;&#39;&#39;Read a phase from a PDB file.</span>
     121<span class="sd">        &#39;&#39;&#39;</span>
     122        <span class="n">EightPiSq</span> <span class="o">=</span> <span class="mf">8.</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="o">**</span><span class="mi">2</span>
     123        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error opening file&#39;</span>
     124        <span class="nb">file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s">&#39;Ur&#39;</span><span class="p">)</span>
     125        <span class="n">Phase</span> <span class="o">=</span> <span class="p">{}</span>
     126        <span class="n">Title</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
     127        <span class="n">Compnd</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
     128        <span class="n">Atoms</span> <span class="o">=</span> <span class="p">[]</span>
     129        <span class="n">A</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
     130        <span class="n">S</span> <span class="o">=</span> <span class="nb">file</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
     131        <span class="n">line</span> <span class="o">=</span> <span class="mi">1</span>
     132        <span class="n">SGData</span> <span class="o">=</span> <span class="bp">None</span>
     133        <span class="n">cell</span> <span class="o">=</span> <span class="bp">None</span>
     134        <span class="k">while</span> <span class="n">S</span><span class="p">:</span>
     135            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading at line &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
     136            <span class="n">Atom</span> <span class="o">=</span> <span class="p">[]</span>
     137            <span class="k">if</span> <span class="s">&#39;TITLE&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="p">[:</span><span class="mi">5</span><span class="p">]:</span>
     138                <span class="n">Title</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">10</span><span class="p">:</span><span class="mi">72</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
     139            <span class="k">elif</span> <span class="s">&#39;COMPND    &#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="p">[:</span><span class="mi">10</span><span class="p">]:</span>
     140                <span class="n">Compnd</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">10</span><span class="p">:</span><span class="mi">72</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
     141            <span class="k">elif</span> <span class="s">&#39;CRYST&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="p">[:</span><span class="mi">5</span><span class="p">]:</span>
     142                <span class="n">abc</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">7</span><span class="p">:</span><span class="mi">34</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
     143                <span class="n">angles</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">34</span><span class="p">:</span><span class="mi">55</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
     144                <span class="n">cell</span><span class="o">=</span><span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">abc</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">abc</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">abc</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
     145                    <span class="nb">float</span><span class="p">(</span><span class="n">angles</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">angles</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">angles</span><span class="p">[</span><span class="mi">2</span><span class="p">])]</span>
     146                <span class="n">Volume</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">calc_V</span><span class="p">(</span><span class="n">G2lat</span><span class="o">.</span><span class="n">cell2A</span><span class="p">(</span><span class="n">cell</span><span class="p">))</span>
     147                <span class="n">AA</span><span class="p">,</span><span class="n">AB</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">cell2AB</span><span class="p">(</span><span class="n">cell</span><span class="p">)</span>
     148                <span class="n">SpGrp</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">55</span><span class="p">:</span><span class="mi">65</span><span class="p">]</span>
     149                <span class="n">E</span><span class="p">,</span><span class="n">SGData</span> <span class="o">=</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">SpcGroup</span><span class="p">(</span><span class="n">SpGrp</span><span class="p">)</span>
     150                <span class="c"># space group processing failed, try to look up name in table</span>
     151                <span class="k">if</span> <span class="n">E</span><span class="p">:</span>
     152                    <span class="n">SpGrpNorm</span> <span class="o">=</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">StandardizeSpcName</span><span class="p">(</span><span class="n">SpGrp</span><span class="p">)</span>
     153                    <span class="k">if</span> <span class="n">SpGrpNorm</span><span class="p">:</span>
     154                        <span class="n">E</span><span class="p">,</span><span class="n">SGData</span> <span class="o">=</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">SpcGroup</span><span class="p">(</span><span class="n">SpGrpNorm</span><span class="p">)</span>
     155                <span class="k">while</span> <span class="n">E</span><span class="p">:</span>
     156                    <span class="k">print</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">SGErrors</span><span class="p">(</span><span class="n">E</span><span class="p">)</span>
     157                    <span class="n">dlg</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">TextEntryDialog</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span>
     158                        <span class="n">SpGrp</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="s">&#39; is invalid </span><span class="se">\n</span><span class="s">N.B.: make sure spaces separate axial fields in symbol&#39;</span><span class="p">,</span>
     159                        <span class="s">&#39;ERROR in space group symbol&#39;</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="n">style</span><span class="o">=</span><span class="n">wx</span><span class="o">.</span><span class="n">OK</span><span class="p">)</span>
     160                    <span class="k">if</span> <span class="n">dlg</span><span class="o">.</span><span class="n">ShowModal</span><span class="p">()</span> <span class="o">==</span> <span class="n">wx</span><span class="o">.</span><span class="n">ID_OK</span><span class="p">:</span>
     161                        <span class="n">SpGrp</span> <span class="o">=</span> <span class="n">dlg</span><span class="o">.</span><span class="n">GetValue</span><span class="p">()</span>
     162                        <span class="n">E</span><span class="p">,</span><span class="n">SGData</span> <span class="o">=</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">SpcGroup</span><span class="p">(</span><span class="n">SpGrp</span><span class="p">)</span>
     163                    <span class="k">else</span><span class="p">:</span>
     164                        <span class="n">SGData</span> <span class="o">=</span> <span class="n">G2IO</span><span class="o">.</span><span class="n">SGData</span> <span class="c"># P 1</span>
     165                        <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">The space group was not interpreted and has been set to &quot;P 1&quot;.&#39;</span>
     166                        <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&quot;Change this in phase&#39;s General tab.&quot;</span>           
     167                    <span class="n">dlg</span><span class="o">.</span><span class="n">Destroy</span><span class="p">()</span>
     168                <span class="n">SGlines</span> <span class="o">=</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">SGPrint</span><span class="p">(</span><span class="n">SGData</span><span class="p">)</span>
     169                <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">SGlines</span><span class="p">:</span> <span class="k">print</span> <span class="n">l</span>
     170            <span class="k">elif</span> <span class="s">&#39;SCALE&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="p">[:</span><span class="mi">5</span><span class="p">]:</span>
     171                <span class="n">V</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">10</span><span class="p">:</span><span class="mi">41</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
     172                <span class="n">A</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">5</span><span class="p">])</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">V</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">V</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">V</span><span class="p">[</span><span class="mi">2</span><span class="p">])]</span>
     173            <span class="k">elif</span> <span class="s">&#39;ATOM&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span> <span class="ow">or</span> <span class="s">&#39;HETATM&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="p">[:</span><span class="mi">6</span><span class="p">]:</span>
     174                <span class="k">if</span> <span class="ow">not</span> <span class="n">SGData</span><span class="p">:</span>
     175                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">The space group was not read before atoms and has been set to &quot;P 1&quot;. &#39;</span>
     176                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&quot;Change this in phase&#39;s General tab.&quot;</span>
     177                    <span class="n">SGData</span> <span class="o">=</span> <span class="n">G2IO</span><span class="o">.</span><span class="n">SGData</span> <span class="c"># P 1</span>
     178                <span class="n">XYZ</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">31</span><span class="p">:</span><span class="mi">39</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">39</span><span class="p">:</span><span class="mi">47</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">47</span><span class="p">:</span><span class="mi">55</span><span class="p">])]</span>
     179                <span class="n">XYZ</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">AB</span><span class="p">,</span><span class="n">XYZ</span><span class="p">)</span>
     180                <span class="n">XYZ</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="nb">abs</span><span class="p">(</span><span class="n">XYZ</span><span class="p">)</span><span class="o">&lt;</span><span class="mf">0.00001</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="n">XYZ</span><span class="p">)</span>
     181                <span class="n">SytSym</span><span class="p">,</span><span class="n">Mult</span> <span class="o">=</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">SytSym</span><span class="p">(</span><span class="n">XYZ</span><span class="p">,</span><span class="n">SGData</span><span class="p">)</span>
     182                <span class="n">Uiso</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">61</span><span class="p">:</span><span class="mi">67</span><span class="p">])</span><span class="o">/</span><span class="n">EightPiSq</span>
     183                <span class="n">Type</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="mi">14</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
     184                <span class="k">if</span> <span class="n">Type</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="s">&#39;123456789&#39;</span><span class="p">:</span>
     185                    <span class="n">Type</span> <span class="o">=</span> <span class="n">Type</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
     186                <span class="n">Atom</span> <span class="o">=</span> <span class="p">[</span><span class="n">S</span><span class="p">[</span><span class="mi">22</span><span class="p">:</span><span class="mi">27</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">(),</span><span class="n">S</span><span class="p">[</span><span class="mi">17</span><span class="p">:</span><span class="mi">20</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span><span class="n">S</span><span class="p">[</span><span class="mi">20</span><span class="p">:</span><span class="mi">22</span><span class="p">],</span>
     187                    <span class="n">S</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="mi">17</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">(),</span><span class="n">Type</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">capitalize</span><span class="p">(),</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="n">XYZ</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">XYZ</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">XYZ</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
     188                    <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">55</span><span class="p">:</span><span class="mi">61</span><span class="p">]),</span><span class="n">SytSym</span><span class="p">,</span><span class="n">Mult</span><span class="p">,</span><span class="s">&#39;I&#39;</span><span class="p">,</span><span class="n">Uiso</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">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
     189                <span class="n">S</span> <span class="o">=</span> <span class="nb">file</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
     190                <span class="n">line</span> <span class="o">+=</span> <span class="mi">1</span>
     191                <span class="k">if</span> <span class="s">&#39;ANISOU&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="p">[:</span><span class="mi">6</span><span class="p">]:</span>
     192                    <span class="n">Uij</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">30</span><span class="p">:</span><span class="mi">72</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
     193                    <span class="n">Uij</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">Uij</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">/</span><span class="mf">10000.</span><span class="p">,</span><span class="nb">float</span><span class="p">(</span><span class="n">Uij</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">/</span><span class="mf">10000.</span><span class="p">,</span><span class="nb">float</span><span class="p">(</span><span class="n">Uij</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span><span class="o">/</span><span class="mf">10000.</span><span class="p">,</span>
     194                        <span class="nb">float</span><span class="p">(</span><span class="n">Uij</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span><span class="o">/</span><span class="mf">10000.</span><span class="p">,</span><span class="nb">float</span><span class="p">(</span><span class="n">Uij</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span><span class="o">/</span><span class="mf">10000.</span><span class="p">,</span><span class="nb">float</span><span class="p">(</span><span class="n">Uij</span><span class="p">[</span><span class="mi">5</span><span class="p">])</span><span class="o">/</span><span class="mf">10000.</span><span class="p">]</span>
     195                    <span class="n">Atom</span> <span class="o">=</span> <span class="n">Atom</span><span class="p">[:</span><span class="mi">14</span><span class="p">]</span><span class="o">+</span><span class="n">Uij</span>
     196                    <span class="n">Atom</span><span class="p">[</span><span class="mi">12</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;A&#39;</span>
     197                <span class="n">Atom</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ran</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">sys</span><span class="o">.</span><span class="n">maxint</span><span class="p">))</span>
     198                <span class="n">Atoms</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Atom</span><span class="p">)</span>
     199            <span class="n">S</span> <span class="o">=</span> <span class="nb">file</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
     200            <span class="n">line</span> <span class="o">+=</span> <span class="mi">1</span>
     201        <span class="nb">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
     202        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error after read complete&#39;</span>
     203        <span class="k">if</span> <span class="n">Title</span><span class="p">:</span>
     204            <span class="n">PhaseName</span> <span class="o">=</span> <span class="n">Title</span>
     205        <span class="k">elif</span> <span class="n">Compnd</span><span class="p">:</span>
     206            <span class="n">PhaseName</span> <span class="o">=</span> <span class="n">Compnd</span>
     207        <span class="k">else</span><span class="p">:</span>
     208            <span class="n">PhaseName</span> <span class="o">=</span> <span class="s">&#39;None&#39;</span>
     209        <span class="k">if</span> <span class="ow">not</span> <span class="n">SGData</span><span class="p">:</span>
     210            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">ImportException</span><span class="p">(</span><span class="s">&quot;No space group (CRYST entry) found&quot;</span><span class="p">)</span>
     211        <span class="k">if</span> <span class="ow">not</span> <span class="n">cell</span><span class="p">:</span>
     212            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">ImportException</span><span class="p">(</span><span class="s">&quot;No cell (CRYST entry) found&quot;</span><span class="p">)</span>
     213        <span class="n">Phase</span> <span class="o">=</span> <span class="n">G2IO</span><span class="o">.</span><span class="n">SetNewPhase</span><span class="p">(</span><span class="n">Name</span><span class="o">=</span><span class="n">PhaseName</span><span class="p">,</span><span class="n">SGData</span><span class="o">=</span><span class="n">SGData</span><span class="p">,</span><span class="n">cell</span><span class="o">=</span><span class="n">cell</span><span class="o">+</span><span class="p">[</span><span class="n">Volume</span><span class="p">,])</span>
     214        <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="o">=</span> <span class="s">&#39;macromolecular&#39;</span>
     215        <span class="n">Phase</span><span class="p">[</span><span class="s">&#39;General&#39;</span><span class="p">][</span><span class="s">&#39;AtomPtrs&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">6</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">12</span><span class="p">]</span>
     216        <span class="n">Phase</span><span class="p">[</span><span class="s">&#39;Atoms&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Atoms</span>
     217        <span class="k">return</span> <span class="n">Phase</span>
    99218</div></div>
    100219<div class="viewcode-block" id="EXP_ReaderClass"><a class="viewcode-back" href="../imports.html#G2phase.EXP_ReaderClass">[docs]</a><span class="k">class</span> <span class="nc">EXP_ReaderClass</span><span class="p">(</span><span class="n">G2IO</span><span class="o">.</span><span class="n">ImportPhase</span><span class="p">):</span>
    101     <span class="s">&#39; Routine to import Phase information from GSAS .EXP files&#39;</span>
     220    <span class="s">&#39;Routine to import Phase information from GSAS .EXP files&#39;</span>
    102221    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    103222        <span class="nb">super</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span> <span class="c"># fancy way to say ImportPhase.__init__</span>
     
    107226            <span class="n">longFormatName</span> <span class="o">=</span> <span class="s">&#39;GSAS Experiment (.EXP file) import&#39;</span>
    108227            <span class="p">)</span>
     228       
    109229<div class="viewcode-block" id="EXP_ReaderClass.ContentsValidator"><a class="viewcode-back" href="../imports.html#G2phase.EXP_ReaderClass.ContentsValidator">[docs]</a>    <span class="k">def</span> <span class="nf">ContentsValidator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filepointer</span><span class="p">):</span>
    110         <span class="n">filepointer</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="c"># rewind the file pointer</span>
    111         <span class="c"># first 13 characters should be VERSION tag -- I think</span>
    112         <span class="k">try</span><span class="p">:</span>
    113             <span class="k">if</span> <span class="n">filepointer</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">13</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;     VERSION &#39;</span><span class="p">:</span>
    114                 <span class="k">return</span> <span class="bp">True</span>
    115         <span class="k">except</span><span class="p">:</span> <span class="k">pass</span>
     230        <span class="s">&#39;Look for a VERSION tag in 1st line&#39;</span>
     231        <span class="k">if</span> <span class="n">filepointer</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">13</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;     VERSION &#39;</span><span class="p">:</span>
     232            <span class="k">return</span> <span class="bp">True</span>
     233        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;File does not begin with VERSION tag&#39;</span>
    116234        <span class="k">return</span> <span class="bp">False</span>
    117235</div>
    118236<div class="viewcode-block" id="EXP_ReaderClass.Reader"><a class="viewcode-back" href="../imports.html#G2phase.EXP_ReaderClass.Reader">[docs]</a>    <span class="k">def</span> <span class="nf">Reader</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">filename</span><span class="p">,</span><span class="n">filepointer</span><span class="p">,</span> <span class="n">ParentFrame</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">unused</span><span class="p">):</span>
     237        <span class="s">&#39;Read a phase from a GSAS .EXP file using :meth:`ReadEXPPhase`&#39;</span>
    119238        <span class="k">try</span><span class="p">:</span>
    120             <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span> <span class="o">=</span> <span class="n">G2IO</span><span class="o">.</span><span class="n">ReadEXPPhase</span><span class="p">(</span><span class="n">ParentFrame</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
     239            <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ReadEXPPhase</span><span class="p">(</span><span class="n">ParentFrame</span><span class="p">,</span> <span class="n">filepointer</span><span class="p">)</span>
    121240            <span class="k">return</span> <span class="bp">True</span>
    122241        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">detail</span><span class="p">:</span>
     242            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">detail</span><span class="p">)</span>
    123243            <span class="k">print</span> <span class="s">&#39;GSAS .EXP read error:&#39;</span><span class="p">,</span><span class="n">detail</span> <span class="c"># for testing</span>
    124244            <span class="n">traceback</span><span class="o">.</span><span class="n">print_exc</span><span class="p">(</span><span class="nb">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span>
    125             <span class="k">return</span> <span class="bp">False</span></div></div>
     245            <span class="k">return</span> <span class="bp">False</span>
     246</div>
     247<div class="viewcode-block" id="EXP_ReaderClass.ReadEXPPhase"><a class="viewcode-back" href="../imports.html#G2phase.EXP_ReaderClass.ReadEXPPhase">[docs]</a>    <span class="k">def</span> <span class="nf">ReadEXPPhase</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">G2frame</span><span class="p">,</span><span class="n">filepointer</span><span class="p">):</span>
     248        <span class="sd">&#39;&#39;&#39;Read a phase from a GSAS .EXP file.</span>
     249<span class="sd">        &#39;&#39;&#39;</span>
     250        <span class="n">shModels</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;cylindrical&#39;</span><span class="p">,</span><span class="s">&#39;none&#39;</span><span class="p">,</span><span class="s">&#39;shear - 2/m&#39;</span><span class="p">,</span><span class="s">&#39;rolling - mmm&#39;</span><span class="p">]</span>
     251        <span class="n">textureData</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;Order&#39;</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="s">&#39;Model&#39;</span><span class="p">:</span><span class="s">&#39;cylindrical&#39;</span><span class="p">,</span><span class="s">&#39;Sample omega&#39;</span><span class="p">:[</span><span class="bp">False</span><span class="p">,</span><span class="mf">0.0</span><span class="p">],</span>
     252            <span class="s">&#39;Sample chi&#39;</span><span class="p">:[</span><span class="bp">False</span><span class="p">,</span><span class="mf">0.0</span><span class="p">],</span><span class="s">&#39;Sample phi&#39;</span><span class="p">:[</span><span class="bp">False</span><span class="p">,</span><span class="mf">0.0</span><span class="p">],</span><span class="s">&#39;SH Coeff&#39;</span><span class="p">:[</span><span class="bp">False</span><span class="p">,{}],</span>
     253            <span class="s">&#39;SHShow&#39;</span><span class="p">:</span><span class="bp">False</span><span class="p">,</span><span class="s">&#39;PFhkl&#39;</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="s">&#39;PFxyz&#39;</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="s">&#39;PlotType&#39;</span><span class="p">:</span><span class="s">&#39;Pole figure&#39;</span><span class="p">}</span>
     254        <span class="n">shNcof</span> <span class="o">=</span> <span class="mi">0</span>
     255        <span class="n">S</span> <span class="o">=</span> <span class="mi">1</span>
     256        <span class="n">NPhas</span> <span class="o">=</span> <span class="p">[]</span>
     257        <span class="n">Expr</span> <span class="o">=</span> <span class="p">[{},{},{},{},{},{},{},{},{}]</span> <span class="c"># GSAS can have at most 9 phases</span>
     258        <span class="k">for</span> <span class="n">line</span><span class="p">,</span><span class="n">S</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">filepointer</span><span class="p">):</span>
     259            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading at line &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">line</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
     260            <span class="k">if</span> <span class="s">&#39;EXPR NPHAS&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="p">[:</span><span class="mi">12</span><span class="p">]:</span>
     261                <span class="n">Num</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s">&#39;0&#39;</span><span class="p">)</span>
     262                <span class="n">NPhas</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
     263            <span class="k">if</span> <span class="s">&#39;CRS&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="p">[:</span><span class="mi">3</span><span class="p">]:</span>
     264                <span class="n">N</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">4</span><span class="p">])</span><span class="o">-</span><span class="mi">1</span>
     265                <span class="n">Expr</span><span class="p">[</span><span class="n">N</span><span class="p">][</span><span class="n">S</span><span class="p">[:</span><span class="mi">12</span><span class="p">]]</span> <span class="o">=</span> <span class="n">S</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
     266        <span class="n">PNames</span> <span class="o">=</span> <span class="p">[]</span>
     267        <span class="k">if</span> <span class="ow">not</span> <span class="n">NPhas</span><span class="p">:</span>
     268            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">ImportException</span><span class="p">(</span><span class="s">&quot;No EXPR NPHAS record found&quot;</span><span class="p">)</span>
     269        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error interpreting file&#39;</span>
     270        <span class="k">for</span> <span class="n">n</span><span class="p">,</span><span class="n">N</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">NPhas</span><span class="p">):</span>
     271            <span class="k">if</span> <span class="n">N</span> <span class="o">!=</span> <span class="s">&#39;0&#39;</span><span class="p">:</span>
     272                <span class="n">result</span> <span class="o">=</span> <span class="n">n</span>
     273                <span class="n">key</span> <span class="o">=</span> <span class="s">&#39;CRS&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="s">&#39;    PNAM&#39;</span>
     274                <span class="n">PNames</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Expr</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">key</span><span class="p">])</span>
     275        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">PNames</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
     276            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">ImportException</span><span class="p">(</span><span class="s">&quot;No phases found&quot;</span><span class="p">)</span>           
     277        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">PNames</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
     278            <span class="n">dlg</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">SingleChoiceDialog</span><span class="p">(</span><span class="n">G2frame</span><span class="p">,</span> <span class="s">&#39;Which phase to read?&#39;</span><span class="p">,</span> <span class="s">&#39;Read phase data&#39;</span><span class="p">,</span> <span class="n">PNames</span><span class="p">,</span> <span class="n">wx</span><span class="o">.</span><span class="n">CHOICEDLG_STYLE</span><span class="p">)</span>
     279            <span class="k">try</span><span class="p">:</span>
     280                <span class="k">if</span> <span class="n">dlg</span><span class="o">.</span><span class="n">ShowModal</span><span class="p">()</span> <span class="o">==</span> <span class="n">wx</span><span class="o">.</span><span class="n">ID_OK</span><span class="p">:</span>
     281                    <span class="n">result</span> <span class="o">=</span> <span class="n">dlg</span><span class="o">.</span><span class="n">GetSelection</span><span class="p">()</span> <span class="c"># I think this breaks is there are skipped phases. Cant this happen?</span>
     282            <span class="k">finally</span><span class="p">:</span>
     283                <span class="n">dlg</span><span class="o">.</span><span class="n">Destroy</span><span class="p">()</span>       
     284        <span class="n">EXPphase</span> <span class="o">=</span> <span class="n">Expr</span><span class="p">[</span><span class="n">result</span><span class="p">]</span>
     285        <span class="n">keyList</span> <span class="o">=</span> <span class="n">EXPphase</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
     286        <span class="n">keyList</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
     287        <span class="n">SGData</span> <span class="o">=</span> <span class="p">{}</span>
     288        <span class="k">if</span> <span class="n">NPhas</span><span class="p">[</span><span class="n">result</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;1&#39;</span><span class="p">:</span>
     289            <span class="n">Ptype</span> <span class="o">=</span> <span class="s">&#39;nuclear&#39;</span>
     290        <span class="k">elif</span> <span class="n">NPhas</span><span class="p">[</span><span class="n">result</span><span class="p">]</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;2&#39;</span><span class="p">,</span><span class="s">&#39;3&#39;</span><span class="p">]:</span>
     291            <span class="n">Ptype</span> <span class="o">=</span> <span class="s">&#39;magnetic&#39;</span>
     292        <span class="k">elif</span> <span class="n">NPhas</span><span class="p">[</span><span class="n">result</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;4&#39;</span><span class="p">:</span>
     293            <span class="n">Ptype</span> <span class="o">=</span> <span class="s">&#39;macromolecular&#39;</span>
     294        <span class="k">elif</span> <span class="n">NPhas</span><span class="p">[</span><span class="n">result</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;10&#39;</span><span class="p">:</span>
     295            <span class="n">Ptype</span> <span class="o">=</span> <span class="s">&#39;Pawley&#39;</span>
     296        <span class="k">else</span><span class="p">:</span>
     297            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">ImportException</span><span class="p">(</span><span class="s">&quot;Phase type not recognized&quot;</span><span class="p">)</span>           
     298        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">keyList</span><span class="p">:</span>
     299            <span class="k">if</span> <span class="s">&#39;PNAM&#39;</span> <span class="ow">in</span> <span class="n">key</span><span class="p">:</span>
     300               <span class="n">PhaseName</span> <span class="o">=</span> <span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
     301            <span class="k">elif</span> <span class="s">&#39;ABC   &#39;</span> <span class="ow">in</span> <span class="n">key</span><span class="p">:</span>
     302                <span class="n">abc</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">][:</span><span class="mi">10</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="mi">10</span><span class="p">:</span><span class="mi">20</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="mi">20</span><span class="p">:</span><span class="mi">30</span><span class="p">])]</span>                       
     303            <span class="k">elif</span> <span class="s">&#39;ANGLES&#39;</span> <span class="ow">in</span> <span class="n">key</span><span class="p">:</span>
     304                <span class="n">angles</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">][:</span><span class="mi">10</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="mi">10</span><span class="p">:</span><span class="mi">20</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="mi">20</span><span class="p">:</span><span class="mi">30</span><span class="p">])]</span>                                               
     305            <span class="k">elif</span> <span class="s">&#39;SG SYM&#39;</span> <span class="ow">in</span> <span class="n">key</span><span class="p">:</span>
     306                <span class="n">SpGrp</span> <span class="o">=</span> <span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">][:</span><span class="mi">15</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
     307                <span class="n">E</span><span class="p">,</span><span class="n">SGData</span> <span class="o">=</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">SpcGroup</span><span class="p">(</span><span class="n">SpGrp</span><span class="p">)</span>
     308                <span class="k">if</span> <span class="n">E</span><span class="p">:</span>
     309                    <span class="n">SGData</span> <span class="o">=</span> <span class="n">G2IO</span><span class="o">.</span><span class="n">SGData</span> <span class="c"># P 1 -- unlikely to need this!</span>
     310                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">The GSAS space group was not interpreted(!) and has been set to &quot;P 1&quot;.&#39;</span>
     311                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&quot;Change this in phase&#39;s General tab.&quot;</span>                       
     312            <span class="k">elif</span> <span class="s">&#39;OD    &#39;</span> <span class="ow">in</span> <span class="n">key</span><span class="p">:</span>
     313                <span class="n">SHdata</span> <span class="o">=</span> <span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span> <span class="c"># may not have all 9 values</span>
     314                <span class="n">SHvals</span> <span class="o">=</span> <span class="mi">9</span><span class="o">*</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
     315                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">):</span>
     316                    <span class="k">try</span><span class="p">:</span>
     317                        <span class="nb">float</span><span class="p">(</span><span class="n">SHdata</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
     318                        <span class="n">SHvals</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">SHdata</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
     319                    <span class="k">except</span><span class="p">:</span>
     320                        <span class="k">pass</span>
     321                <span class="n">textureData</span><span class="p">[</span><span class="s">&#39;Order&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">SHvals</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
     322                <span class="n">textureData</span><span class="p">[</span><span class="s">&#39;Model&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">shModels</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">SHvals</span><span class="p">[</span><span class="mi">2</span><span class="p">])]</span>
     323                <span class="n">textureData</span><span class="p">[</span><span class="s">&#39;Sample omega&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span><span class="p">,</span><span class="nb">float</span><span class="p">(</span><span class="n">SHvals</span><span class="p">[</span><span class="mi">6</span><span class="p">])]</span>
     324                <span class="n">textureData</span><span class="p">[</span><span class="s">&#39;Sample chi&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span><span class="p">,</span><span class="nb">float</span><span class="p">(</span><span class="n">SHvals</span><span class="p">[</span><span class="mi">7</span><span class="p">])]</span>
     325                <span class="n">textureData</span><span class="p">[</span><span class="s">&#39;Sample phi&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span><span class="p">,</span><span class="nb">float</span><span class="p">(</span><span class="n">SHvals</span><span class="p">[</span><span class="mi">8</span><span class="p">])]</span>
     326                <span class="n">shNcof</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">SHvals</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
     327        <span class="n">Atoms</span> <span class="o">=</span> <span class="p">[]</span>
     328        <span class="k">if</span> <span class="n">Ptype</span> <span class="o">==</span> <span class="s">&#39;nuclear&#39;</span><span class="p">:</span>
     329            <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">keyList</span><span class="p">:</span>
     330                <span class="k">if</span> <span class="s">&#39;AT&#39;</span> <span class="ow">in</span> <span class="n">key</span><span class="p">:</span>
     331                    <span class="k">if</span> <span class="n">key</span><span class="p">[</span><span class="mi">11</span><span class="p">:]</span> <span class="o">==</span> <span class="s">&#39;A&#39;</span><span class="p">:</span>
     332                        <span class="n">S</span> <span class="o">=</span> <span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
     333                    <span class="k">elif</span> <span class="n">key</span><span class="p">[</span><span class="mi">11</span><span class="p">:]</span> <span class="o">==</span> <span class="s">&#39;B&#39;</span><span class="p">:</span>
     334                        <span class="n">S</span> <span class="o">+=</span> <span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
     335                        <span class="n">Atom</span> <span class="o">=</span> <span class="p">[</span><span class="n">S</span><span class="p">[</span><span class="mi">50</span><span class="p">:</span><span class="mi">58</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">(),</span><span class="n">S</span><span class="p">[:</span><span class="mi">10</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">capitalize</span><span class="p">(),</span><span class="s">&#39;&#39;</span><span class="p">,</span>
     336                            <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">10</span><span class="p">:</span><span class="mi">20</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">20</span><span class="p">:</span><span class="mi">30</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">30</span><span class="p">:</span><span class="mi">40</span><span class="p">]),</span>
     337                            <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">40</span><span class="p">:</span><span class="mi">50</span><span class="p">]),</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="nb">int</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">60</span><span class="p">:</span><span class="mi">62</span><span class="p">]),</span><span class="n">S</span><span class="p">[</span><span class="mi">130</span><span class="p">:</span><span class="mi">131</span><span class="p">]]</span>
     338                        <span class="k">if</span> <span class="n">Atom</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;I&#39;</span><span class="p">:</span>
     339                            <span class="n">Atom</span> <span class="o">+=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">68</span><span class="p">:</span><span class="mi">78</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><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>
     340                        <span class="k">elif</span> <span class="n">Atom</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;A&#39;</span><span class="p">:</span>
     341                            <span class="n">Atom</span> <span class="o">+=</span> <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">68</span><span class="p">:</span><span class="mi">78</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">78</span><span class="p">:</span><span class="mi">88</span><span class="p">]),</span>
     342                                <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">88</span><span class="p">:</span><span class="mi">98</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">98</span><span class="p">:</span><span class="mi">108</span><span class="p">]),</span>
     343                                <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">108</span><span class="p">:</span><span class="mi">118</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">118</span><span class="p">:</span><span class="mi">128</span><span class="p">])]</span>
     344                        <span class="n">XYZ</span> <span class="o">=</span> <span class="n">Atom</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">6</span><span class="p">]</span>
     345                        <span class="n">Atom</span><span class="p">[</span><span class="mi">7</span><span class="p">],</span><span class="n">Atom</span><span class="p">[</span><span class="mi">8</span><span class="p">]</span> <span class="o">=</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">SytSym</span><span class="p">(</span><span class="n">XYZ</span><span class="p">,</span><span class="n">SGData</span><span class="p">)</span>
     346                        <span class="n">Atom</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ran</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">sys</span><span class="o">.</span><span class="n">maxint</span><span class="p">))</span>
     347                        <span class="n">Atoms</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Atom</span><span class="p">)</span>
     348        <span class="k">elif</span> <span class="n">Ptype</span> <span class="o">==</span> <span class="s">&#39;macromolecular&#39;</span><span class="p">:</span>
     349            <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">keyList</span><span class="p">:</span>
     350                <span class="k">if</span> <span class="s">&#39;AT&#39;</span> <span class="ow">in</span> <span class="n">key</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">8</span><span class="p">]:</span>
     351                    <span class="n">S</span> <span class="o">=</span> <span class="n">EXPphase</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
     352                    <span class="n">Atom</span> <span class="o">=</span> <span class="p">[</span><span class="n">S</span><span class="p">[</span><span class="mi">56</span><span class="p">:</span><span class="mi">60</span><span class="p">],</span><span class="n">S</span><span class="p">[</span><span class="mi">50</span><span class="p">:</span><span class="mi">54</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">upper</span><span class="p">(),</span><span class="n">S</span><span class="p">[</span><span class="mi">54</span><span class="p">:</span><span class="mi">56</span><span class="p">],</span>
     353                        <span class="n">S</span><span class="p">[</span><span class="mi">46</span><span class="p">:</span><span class="mi">51</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">(),</span><span class="n">S</span><span class="p">[:</span><span class="mi">8</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">capitalize</span><span class="p">(),</span><span class="s">&#39;&#39;</span><span class="p">,</span>
     354                        <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">16</span><span class="p">:</span><span class="mi">24</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">24</span><span class="p">:</span><span class="mi">32</span><span class="p">]),</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">32</span><span class="p">:</span><span class="mi">40</span><span class="p">]),</span>
     355                        <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">8</span><span class="p">:</span><span class="mi">16</span><span class="p">]),</span><span class="s">&#39;1&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="s">&#39;I&#39;</span><span class="p">,</span><span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="mi">40</span><span class="p">:</span><span class="mi">46</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">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
     356                    <span class="n">XYZ</span> <span class="o">=</span> <span class="n">Atom</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">9</span><span class="p">]</span>
     357                    <span class="n">Atom</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span><span class="n">Atom</span><span class="p">[</span><span class="mi">11</span><span class="p">]</span> <span class="o">=</span> <span class="n">G2spc</span><span class="o">.</span><span class="n">SytSym</span><span class="p">(</span><span class="n">XYZ</span><span class="p">,</span><span class="n">SGData</span><span class="p">)</span>
     358                    <span class="n">Atom</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ran</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">sys</span><span class="o">.</span><span class="n">maxint</span><span class="p">))</span>
     359                    <span class="n">Atoms</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Atom</span><span class="p">)</span>
     360        <span class="n">Volume</span> <span class="o">=</span> <span class="n">G2lat</span><span class="o">.</span><span class="n">calc_V</span><span class="p">(</span><span class="n">G2lat</span><span class="o">.</span><span class="n">cell2A</span><span class="p">(</span><span class="n">abc</span><span class="o">+</span><span class="n">angles</span><span class="p">))</span>
     361        <span class="k">if</span> <span class="n">shNcof</span><span class="p">:</span>
     362            <span class="n">shCoef</span> <span class="o">=</span> <span class="p">{}</span>
     363            <span class="n">nRec</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</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="n">shNcof</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">6</span><span class="o">+</span><span class="mi">1</span><span class="p">)]</span>
     364            <span class="k">for</span> <span class="n">irec</span> <span class="ow">in</span> <span class="n">nRec</span><span class="p">:</span>
     365                <span class="n">ODkey</span> <span class="o">=</span> <span class="n">keyList</span><span class="p">[</span><span class="mi">0</span><span class="p">][:</span><span class="mi">6</span><span class="p">]</span><span class="o">+</span><span class="s">&#39;OD&#39;</span><span class="o">+</span><span class="s">&#39;</span><span class="si">%3d</span><span class="s">A&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">irec</span><span class="p">)</span>
     366                <span class="n">indx</span> <span class="o">=</span> <span class="n">EXPphase</span><span class="p">[</span><span class="n">ODkey</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
     367                <span class="n">ODkey</span> <span class="o">=</span> <span class="n">ODkey</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="s">&#39;B&#39;</span>
     368                <span class="n">vals</span> <span class="o">=</span> <span class="n">EXPphase</span><span class="p">[</span><span class="n">ODkey</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
     369                <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">val</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">vals</span><span class="p">):</span>
     370                    <span class="n">key</span> <span class="o">=</span> <span class="s">&#39;C(</span><span class="si">%s</span><span class="s">,</span><span class="si">%s</span><span class="s">,</span><span class="si">%s</span><span class="s">)&#39;</span><span class="o">%</span><span class="p">(</span><span class="n">indx</span><span class="p">[</span><span class="mi">3</span><span class="o">*</span><span class="n">i</span><span class="p">],</span><span class="n">indx</span><span class="p">[</span><span class="mi">3</span><span class="o">*</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">],</span><span class="n">indx</span><span class="p">[</span><span class="mi">3</span><span class="o">*</span><span class="n">i</span><span class="o">+</span><span class="mi">2</span><span class="p">])</span>
     371                    <span class="n">shCoef</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
     372            <span class="n">textureData</span><span class="p">[</span><span class="s">&#39;SH Coeff&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span><span class="p">,</span><span class="n">shCoef</span><span class="p">]</span>
     373        <span class="k">if</span> <span class="ow">not</span> <span class="n">SGData</span><span class="p">:</span>
     374            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">ImportException</span><span class="p">(</span><span class="s">&quot;No space group found in phase&quot;</span><span class="p">)</span>
     375        <span class="k">if</span> <span class="ow">not</span> <span class="n">abc</span><span class="p">:</span>
     376            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">ImportException</span><span class="p">(</span><span class="s">&quot;No cell lengths found in phase&quot;</span><span class="p">)</span>
     377        <span class="k">if</span> <span class="ow">not</span> <span class="n">angles</span><span class="p">:</span>
     378            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">ImportException</span><span class="p">(</span><span class="s">&quot;No cell angles found in phase&quot;</span><span class="p">)</span>
     379        <span class="k">if</span> <span class="ow">not</span> <span class="n">Atoms</span><span class="p">:</span>
     380            <span class="k">raise</span> <span class="bp">self</span><span class="o">.</span><span class="n">ImportException</span><span class="p">(</span><span class="s">&quot;No atoms found in phase&quot;</span><span class="p">)</span>
     381        <span class="n">Phase</span> <span class="o">=</span> <span class="n">G2IO</span><span class="o">.</span><span class="n">SetNewPhase</span><span class="p">(</span><span class="n">Name</span><span class="o">=</span><span class="n">PhaseName</span><span class="p">,</span><span class="n">SGData</span><span class="o">=</span><span class="n">SGData</span><span class="p">,</span><span class="n">cell</span><span class="o">=</span><span class="n">abc</span><span class="o">+</span><span class="n">angles</span><span class="o">+</span><span class="p">[</span><span class="n">Volume</span><span class="p">,])</span>
     382        <span class="n">general</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>
     383        <span class="n">general</span><span class="p">[</span><span class="s">&#39;Type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Ptype</span>
     384        <span class="k">if</span> <span class="n">general</span><span class="p">[</span><span class="s">&#39;Type&#39;</span><span class="p">]</span> <span class="o">==</span><span class="s">&#39;macromolecular&#39;</span><span class="p">:</span>
     385            <span class="n">general</span><span class="p">[</span><span class="s">&#39;AtomPtrs&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">6</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">12</span><span class="p">]</span>
     386        <span class="k">else</span><span class="p">:</span>
     387            <span class="n">general</span><span class="p">[</span><span class="s">&#39;AtomPtrs&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">9</span><span class="p">]</span>   
     388        <span class="n">general</span><span class="p">[</span><span class="s">&#39;SH Texture&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">textureData</span>
     389        <span class="n">Phase</span><span class="p">[</span><span class="s">&#39;Atoms&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Atoms</span>
     390        <span class="k">return</span> <span class="n">Phase</span></div></div>
    126391</pre></div>
    127392
Note: See TracChangeset for help on using the changeset viewer.