source: trunk/sphinxdocs/build/html/_modules/G2phase_CIF.html @ 1183

Last change on this file since 1183 was 1183, checked in by toby, 8 years ago

fixup number formatting; update produced doc files

  • Property svn:mime-type set to text/html
File size: 97.7 KB
Line 
1
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6
7<html xmlns="http://www.w3.org/1999/xhtml">
8  <head>
9    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10   
11    <title>G2phase_CIF &mdash; GSAS-II 0.2.0 documentation</title>
12   
13    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
14    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
15   
16    <script type="text/javascript">
17      var DOCUMENTATION_OPTIONS = {
18        URL_ROOT:    '../',
19        VERSION:     '0.2.0',
20        COLLAPSE_INDEX: false,
21        FILE_SUFFIX: '.html',
22        HAS_SOURCE:  true
23      };
24    </script>
25    <script type="text/javascript" src="../_static/jquery.js"></script>
26    <script type="text/javascript" src="../_static/underscore.js"></script>
27    <script type="text/javascript" src="../_static/doctools.js"></script>
28    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
29    <link rel="top" title="GSAS-II 0.2.0 documentation" href="../index.html" />
30    <link rel="up" title="Module code" href="index.html" /> 
31  </head>
32  <body>
33    <div class="related">
34      <h3>Navigation</h3>
35      <ul>
36        <li class="right" style="margin-right: 10px">
37          <a href="../genindex.html" title="General Index"
38             accesskey="I">index</a></li>
39        <li class="right" >
40          <a href="../py-modindex.html" title="Python Module Index"
41             >modules</a> |</li>
42        <li><a href="../index.html">GSAS-II 0.2.0 documentation</a> &raquo;</li>
43          <li><a href="index.html" accesskey="U">Module code</a> &raquo;</li> 
44      </ul>
45    </div> 
46
47    <div class="document">
48      <div class="documentwrapper">
49        <div class="bodywrapper">
50          <div class="body">
51           
52  <h1>Source code for G2phase_CIF</h1><div class="highlight"><pre>
53<span class="c"># -*- coding: utf-8 -*-</span>
54<span class="c">########### SVN repository information ###################</span>
55<span class="c"># $Date: 2013-12-16 10:43:01 -0600 (Mon, 16 Dec 2013) $</span>
56<span class="c"># $Author: toby $</span>
57<span class="c"># $Revision: 1168 $</span>
58<span class="c"># $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/imports/G2phase_CIF.py $</span>
59<span class="c"># $Id: G2phase_CIF.py 1168 2013-12-16 16:43:01Z toby $</span>
60<span class="c">########### SVN repository information ###################</span>
61<span class="sd">&#39;&#39;&#39;</span>
62<span class="sd">*Module G2phase_CIF: Coordinates from CIF*</span>
63<span class="sd">------------------------------------------</span>
64
65<span class="sd">Parses a CIF using  PyCifRW from James Hester and pulls out the</span>
66<span class="sd">structural information.</span>
67
68<span class="sd">If a CIF generated by ISODISTORT is encountered, extra information is</span>
69<span class="sd">added to the phase entry and constraints are generated. </span>
70
71<span class="sd">&#39;&#39;&#39;</span>
72<span class="c"># Routines to import Phase information from CIF files</span>
73<span class="kn">import</span> <span class="nn">sys</span>
74<span class="kn">import</span> <span class="nn">random</span> <span class="kn">as</span> <span class="nn">ran</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">re</span>
77<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">GSASIIobj</span> <span class="kn">as</span> <span class="nn">G2obj</span>
79<span class="kn">import</span> <span class="nn">GSASIIspc</span> <span class="kn">as</span> <span class="nn">G2spc</span>
80<span class="kn">import</span> <span class="nn">GSASIIElem</span> <span class="kn">as</span> <span class="nn">G2elem</span>
81<span class="kn">import</span> <span class="nn">GSASIIlattice</span> <span class="kn">as</span> <span class="nn">G2lat</span>
82<span class="kn">import</span> <span class="nn">GSASIIpy3</span> <span class="kn">as</span> <span class="nn">G2p3</span>
83<span class="kn">import</span> <span class="nn">GSASIIpath</span>
84<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>
85<span class="kn">import</span> <span class="nn">CifFile</span> <span class="kn">as</span> <span class="nn">cif</span> <span class="c"># PyCifRW from James Hester</span>
86
87<div class="viewcode-block" id="CIFPhaseReader"><a class="viewcode-back" href="../imports.html#G2phase_CIF.CIFPhaseReader">[docs]</a><span class="k">class</span> <span class="nc">CIFPhaseReader</span><span class="p">(</span><span class="n">G2IO</span><span class="o">.</span><span class="n">ImportPhase</span><span class="p">):</span>
88    <span class="s">&#39;Implements a phase importer from a possibly multi-block CIF file&#39;</span>
89    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
90        <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>
91            <span class="n">extensionlist</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;.CIF&#39;</span><span class="p">,</span><span class="s">&#39;.cif&#39;</span><span class="p">,</span><span class="s">&#39;.txt&#39;</span><span class="p">),</span>
92            <span class="n">strictExtension</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
93            <span class="n">formatName</span> <span class="o">=</span> <span class="s">&#39;CIF&#39;</span><span class="p">,</span>
94            <span class="n">longFormatName</span> <span class="o">=</span> <span class="s">&#39;Crystallographic Information File import&#39;</span>
95            <span class="p">)</span>
96       
97    <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>
98        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">CIFValidator</span><span class="p">(</span><span class="n">filepointer</span><span class="p">)</span>
99
100    <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="n">usedRanIdList</span><span class="o">=</span><span class="p">[],</span> <span class="o">**</span><span class="n">unused</span><span class="p">):</span>
101        <span class="bp">self</span><span class="o">.</span><span class="n">isodistort_warnings</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
102        <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">SetNewPhase</span><span class="p">(</span><span class="n">Name</span><span class="o">=</span><span class="s">&#39;new phase&#39;</span><span class="p">,</span><span class="n">SGData</span><span class="o">=</span><span class="n">G2IO</span><span class="o">.</span><span class="n">P1SGData</span><span class="p">)</span> <span class="c"># create a new empty phase dict</span>
103        <span class="c"># make sure the ranId is really unique!</span>
104        <span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;ranId&#39;</span><span class="p">]</span> <span class="ow">in</span> <span class="n">usedRanIdList</span><span class="p">:</span>
105            <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;ranId&#39;</span><span class="p">]</span> <span class="o">=</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>
106        <span class="n">returnstat</span> <span class="o">=</span> <span class="bp">False</span>
107        <span class="n">cellitems</span> <span class="o">=</span> <span class="p">(</span>
108            <span class="s">&#39;_cell_length_a&#39;</span><span class="p">,</span><span class="s">&#39;_cell_length_b&#39;</span><span class="p">,</span><span class="s">&#39;_cell_length_c&#39;</span><span class="p">,</span>
109            <span class="s">&#39;_cell_angle_alpha&#39;</span><span class="p">,</span><span class="s">&#39;_cell_angle_beta&#39;</span><span class="p">,</span><span class="s">&#39;_cell_angle_gamma&#39;</span><span class="p">,)</span>
110        <span class="n">reqitems</span> <span class="o">=</span> <span class="p">(</span>
111             <span class="s">&#39;_atom_site_fract_x&#39;</span><span class="p">,</span>
112             <span class="s">&#39;_atom_site_fract_y&#39;</span><span class="p">,</span>
113             <span class="s">&#39;_atom_site_fract_z&#39;</span><span class="p">,</span>
114            <span class="p">)</span>
115        <span class="n">phasenamefields</span> <span class="o">=</span> <span class="p">(</span>
116            <span class="s">&#39;_chemical_name_common&#39;</span><span class="p">,</span>
117            <span class="s">&#39;_pd_phase_name&#39;</span><span class="p">,</span>
118            <span class="s">&#39;_chemical_formula_sum&#39;</span>
119            <span class="p">)</span>
120        <span class="k">try</span><span class="p">:</span>
121            <span class="bp">self</span><span class="o">.</span><span class="n">ShowBusy</span><span class="p">()</span> <span class="c"># this can take a while</span>
122            <span class="k">try</span><span class="p">:</span>
123                <span class="n">cf</span> <span class="o">=</span> <span class="n">G2IO</span><span class="o">.</span><span class="n">ReadCIF</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
124            <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">detail</span><span class="p">:</span>
125                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&quot;Parse or reading of file failed in pyCifRW; check syntax of file in enCIFer or CheckCIF&quot;</span>
126                <span class="k">return</span> <span class="bp">False</span>
127            <span class="k">finally</span><span class="p">:</span>
128                <span class="bp">self</span><span class="o">.</span><span class="n">DoneBusy</span><span class="p">()</span>
129            <span class="c"># scan blocks for structural info</span>
130            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error during scan of blocks for datasets&#39;</span>
131            <span class="n">str_blklist</span> <span class="o">=</span> <span class="p">[]</span>
132            <span class="k">for</span> <span class="n">blk</span> <span class="ow">in</span> <span class="n">cf</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
133                <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">reqitems</span><span class="o">+</span><span class="n">cellitems</span><span class="p">:</span>
134                    <span class="k">if</span> <span class="n">r</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">cf</span><span class="p">[</span><span class="n">blk</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
135                        <span class="k">break</span>
136                <span class="k">else</span><span class="p">:</span>
137                    <span class="n">str_blklist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">blk</span><span class="p">)</span>
138            <span class="k">if</span> <span class="ow">not</span> <span class="n">str_blklist</span><span class="p">:</span>
139                <span class="n">selblk</span> <span class="o">=</span> <span class="bp">None</span> <span class="c"># no block to choose</span>
140            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">str_blklist</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="c"># only one choice</span>
141                <span class="n">selblk</span> <span class="o">=</span> <span class="mi">0</span>
142            <span class="k">else</span><span class="p">:</span>                       <span class="c"># choose from options</span>
143                <span class="n">choice</span> <span class="o">=</span> <span class="p">[]</span>
144                <span class="k">for</span> <span class="n">blknm</span> <span class="ow">in</span> <span class="n">str_blklist</span><span class="p">:</span>
145                    <span class="n">choice</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">)</span>
146                    <span class="c"># accumumlate some info about this phase</span>
147                    <span class="n">choice</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">blknm</span> <span class="o">+</span> <span class="s">&#39;: &#39;</span>
148                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">phasenamefields</span><span class="p">:</span> <span class="c"># get a name for the phase</span>
149                        <span class="n">name</span> <span class="o">=</span> <span class="n">cf</span><span class="p">[</span><span class="n">blknm</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
150                        <span class="k">if</span> <span class="n">name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;?&#39;</span> <span class="ow">or</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;.&#39;</span><span class="p">:</span>
151                            <span class="k">continue</span>
152                        <span class="k">else</span><span class="p">:</span>
153                            <span class="n">choice</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">name</span><span class="o">.</span><span class="n">strip</span><span class="p">()[:</span><span class="mi">20</span><span class="p">]</span> <span class="o">+</span> <span class="s">&#39;, &#39;</span>
154                            <span class="k">break</span>
155                    <span class="n">na</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">cf</span><span class="p">[</span><span class="n">blknm</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&quot;_atom_site_fract_x&quot;</span><span class="p">))</span>
156                    <span class="k">if</span> <span class="n">na</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
157                        <span class="n">choice</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;1 atom&#39;</span>
158                    <span class="k">else</span><span class="p">:</span>
159                        <span class="n">choice</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="s">&#39;</span><span class="si">%d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">nd</span><span class="p">)</span> <span class="o">+</span> <span class="s">&#39; atoms&#39;</span>
160                    <span class="n">choice</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;, cell: &#39;</span>
161                    <span class="n">fmt</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%.2f</span><span class="s">,&quot;</span>
162                    <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">key</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">cellitems</span><span class="p">):</span>
163                        <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span> <span class="n">fmt</span> <span class="o">=</span> <span class="s">&quot;%.f,&quot;</span>
164                        <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span> <span class="n">fmt</span> <span class="o">=</span> <span class="s">&quot;%.f&quot;</span>
165                        <span class="n">choice</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">fmt</span> <span class="o">%</span> <span class="n">cif</span><span class="o">.</span><span class="n">get_number_with_esd</span><span class="p">(</span>
166                            <span class="n">cf</span><span class="p">[</span><span class="n">blknm</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>
167                    <span class="n">sg</span> <span class="o">=</span> <span class="n">cf</span><span class="p">[</span><span class="n">blknm</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&quot;_symmetry_space_group_name_H-M&quot;</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">)</span>
168                    <span class="k">if</span> <span class="ow">not</span> <span class="n">sg</span><span class="p">:</span> <span class="n">sg</span> <span class="o">=</span> <span class="n">cf</span><span class="p">[</span><span class="n">blknm</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&quot;_space_group_name_H-M_alt&quot;</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">)</span>
169                    <span class="k">if</span> <span class="n">sg</span><span class="p">:</span> <span class="n">choice</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="s">&#39;, (&#39;</span> <span class="o">+</span> <span class="n">sg</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="o">+</span> <span class="s">&#39;)&#39;</span>
170                <span class="n">selblk</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">PhaseSelector</span><span class="p">(</span>
171                    <span class="n">choice</span><span class="p">,</span>
172                    <span class="n">ParentFrame</span><span class="o">=</span><span class="n">ParentFrame</span><span class="p">,</span>
173                    <span class="n">title</span><span class="o">=</span> <span class="s">&#39;Select a phase from one the CIF data_ blocks below&#39;</span><span class="p">,</span>
174                    <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">600</span><span class="p">,</span><span class="mi">100</span><span class="p">)</span>
175                    <span class="p">)</span>
176            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error during reading of selected block&#39;</span>
177            <span class="k">if</span> <span class="n">selblk</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
178                <span class="n">returnstat</span> <span class="o">=</span> <span class="bp">False</span> <span class="c"># no block selected or available</span>
179            <span class="k">else</span><span class="p">:</span>
180                <span class="n">blknm</span> <span class="o">=</span> <span class="n">str_blklist</span><span class="p">[</span><span class="n">selblk</span><span class="p">]</span>
181                <span class="n">blk</span> <span class="o">=</span> <span class="n">cf</span><span class="p">[</span><span class="n">str_blklist</span><span class="p">[</span><span class="n">selblk</span><span class="p">]]</span>
182                <span class="n">E</span> <span class="o">=</span> <span class="bp">True</span>
183                <span class="n">SpGrp</span> <span class="o">=</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&quot;_symmetry_space_group_name_H-M&quot;</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">)</span>
184                <span class="k">if</span> <span class="ow">not</span> <span class="n">SpGrp</span><span class="p">:</span>
185                    <span class="n">SpGrp</span> <span class="o">=</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&quot;_space_group_name_H-M_alt&quot;</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">)</span>
186                <span class="c"># try normalizing the space group, to see if we can pick the space group out of a table</span>
187                <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>
188                <span class="k">if</span> <span class="n">SpGrpNorm</span><span class="p">:</span>
189                    <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>
190                <span class="c"># nope, try the space group &quot;out of the Box&quot;</span>
191                <span class="k">if</span> <span class="n">E</span> <span class="ow">and</span> <span class="n">SpGrp</span><span class="p">:</span>
192                    <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>
193                <span class="k">if</span> <span class="n">E</span><span class="p">:</span>
194                    <span class="k">if</span> <span class="ow">not</span> <span class="n">SpGrp</span><span class="p">:</span>
195                        <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39;No space group name was found in the CIF.&#39;</span>
196                        <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 has been set to &quot;P 1&quot;. &#39;</span>
197                        <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>
198                    <span class="k">else</span><span class="p">:</span>
199                        <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39;ERROR in space group symbol &#39;</span><span class="o">+</span><span class="n">SpGrp</span>
200                        <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 has been set to &quot;P 1&quot;. &#39;</span>
201                        <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>
202                        <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">Are there spaces separating axial fields?</span><span class="se">\n\n</span><span class="s">Error msg: &#39;</span>
203                        <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</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>
204                    <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>
205                <span class="bp">self</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> <span class="o">=</span> <span class="n">SGData</span>
206                <span class="c"># cell parameters</span>
207                <span class="n">cell</span> <span class="o">=</span> <span class="p">[]</span>
208                <span class="k">for</span> <span class="n">lbl</span> <span class="ow">in</span> <span class="n">cellitems</span><span class="p">:</span>
209                    <span class="n">cell</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cif</span><span class="o">.</span><span class="n">get_number_with_esd</span><span class="p">(</span><span class="n">blk</span><span class="p">[</span><span class="n">lbl</span><span class="p">])[</span><span class="mi">0</span><span class="p">])</span>
210                <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>
211                <span class="bp">self</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;Cell&#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="o">+</span><span class="n">cell</span><span class="o">+</span><span class="p">[</span><span class="n">Volume</span><span class="p">,]</span>
212                <span class="c"># read in atoms</span>
213                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error during reading of atoms&#39;</span>
214                <span class="n">atomlbllist</span> <span class="o">=</span> <span class="p">[]</span> <span class="c"># table to look up atom IDs</span>
215                <span class="n">atomloop</span> <span class="o">=</span> <span class="n">blk</span><span class="o">.</span><span class="n">GetLoop</span><span class="p">(</span><span class="s">&#39;_atom_site_label&#39;</span><span class="p">)</span>
216                <span class="n">atomkeys</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">atomloop</span><span class="o">.</span><span class="n">keys</span><span class="p">()]</span>
217                <span class="k">if</span> <span class="ow">not</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_atom_site_type_symbol&#39;</span><span class="p">):</span>
218                    <span class="bp">self</span><span class="o">.</span><span class="n">isodistort_warnings</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">lack of atom types prevents ISODISTORT processing&#39;</span>
219                <span class="k">if</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_atom_site_aniso_label&#39;</span><span class="p">):</span>
220                    <span class="n">anisoloop</span> <span class="o">=</span> <span class="n">blk</span><span class="o">.</span><span class="n">GetLoop</span><span class="p">(</span><span class="s">&#39;_atom_site_aniso_label&#39;</span><span class="p">)</span>
221                    <span class="n">anisokeys</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">anisoloop</span><span class="o">.</span><span class="n">keys</span><span class="p">()]</span>
222                <span class="k">else</span><span class="p">:</span>
223                    <span class="n">anisoloop</span> <span class="o">=</span> <span class="bp">None</span>
224                    <span class="n">anisokeys</span> <span class="o">=</span> <span class="p">[]</span>
225                <span class="bp">self</span><span class="o">.</span><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="p">[]</span>
226                <span class="n">G2AtomDict</span> <span class="o">=</span> <span class="p">{</span>  <span class="s">&#39;_atom_site_type_symbol&#39;</span> <span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
227                                <span class="s">&#39;_atom_site_label&#39;</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
228                                <span class="s">&#39;_atom_site_fract_x&#39;</span> <span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
229                                <span class="s">&#39;_atom_site_fract_y&#39;</span> <span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
230                                <span class="s">&#39;_atom_site_fract_z&#39;</span> <span class="p">:</span> <span class="mi">5</span><span class="p">,</span>
231                                <span class="s">&#39;_atom_site_occupancy&#39;</span> <span class="p">:</span> <span class="mi">6</span><span class="p">,</span>
232                                <span class="s">&#39;_atom_site_aniso_u_11&#39;</span> <span class="p">:</span> <span class="mi">11</span><span class="p">,</span>
233                                <span class="s">&#39;_atom_site_aniso_u_22&#39;</span> <span class="p">:</span> <span class="mi">12</span><span class="p">,</span>
234                                <span class="s">&#39;_atom_site_aniso_u_33&#39;</span> <span class="p">:</span> <span class="mi">13</span><span class="p">,</span>
235                                <span class="s">&#39;_atom_site_aniso_u_12&#39;</span> <span class="p">:</span> <span class="mi">14</span><span class="p">,</span>
236                                <span class="s">&#39;_atom_site_aniso_u_13&#39;</span> <span class="p">:</span> <span class="mi">15</span><span class="p">,</span>
237                                <span class="s">&#39;_atom_site_aniso_u_23&#39;</span> <span class="p">:</span> <span class="mi">16</span><span class="p">,</span> <span class="p">}</span>
238                <span class="n">ranIdlookup</span> <span class="o">=</span> <span class="p">{}</span>
239                <span class="k">for</span> <span class="n">aitem</span> <span class="ow">in</span> <span class="n">atomloop</span><span class="p">:</span>
240                    <span class="n">atomlist</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="s">&#39;&#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">0</span><span class="p">,</span><span class="mf">1.0</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="s">&#39;I&#39;</span><span class="p">,</span><span class="mf">0.01</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><span class="mi">0</span><span class="p">]</span>
241                    <span class="n">atomlist</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">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> <span class="c"># add a random Id</span>
242                    <span class="k">while</span> <span class="n">atomlist</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="ow">in</span> <span class="n">ranIdlookup</span><span class="p">:</span>
243                        <span class="n">atomlist</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">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> <span class="c"># make it unique</span>
244                    <span class="k">for</span> <span class="n">val</span><span class="p">,</span><span class="n">key</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">aitem</span><span class="p">,</span><span class="n">atomkeys</span><span class="p">):</span>
245                        <span class="n">col</span> <span class="o">=</span> <span class="n">G2AtomDict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
246                        <span class="k">if</span> <span class="n">col</span> <span class="o">&gt;=</span> <span class="mi">3</span><span class="p">:</span>
247                            <span class="n">atomlist</span><span class="p">[</span><span class="n">col</span><span class="p">]</span> <span class="o">=</span> <span class="n">cif</span><span class="o">.</span><span class="n">get_number_with_esd</span><span class="p">(</span><span class="n">val</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
248                        <span class="k">elif</span> <span class="n">col</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
249                            <span class="n">atomlist</span><span class="p">[</span><span class="n">col</span><span class="p">]</span> <span class="o">=</span> <span class="n">val</span>
250                        <span class="k">elif</span> <span class="n">key</span> <span class="ow">in</span> <span class="p">(</span><span class="s">&#39;_atom_site_thermal_displace_type&#39;</span><span class="p">,</span>
251                                   <span class="s">&#39;_atom_site_adp_type&#39;</span><span class="p">):</span>   <span class="c">#Iso or Aniso?</span>
252                            <span class="k">if</span> <span class="n">val</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;uani&#39;</span><span class="p">:</span>
253                                <span class="n">atomlist</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>
254                        <span class="k">elif</span> <span class="n">key</span> <span class="o">==</span> <span class="s">&#39;_atom_site_u_iso_or_equiv&#39;</span><span class="p">:</span>
255                            <span class="n">atomlist</span><span class="p">[</span><span class="mi">10</span><span class="p">]</span> <span class="o">=</span><span class="n">cif</span><span class="o">.</span><span class="n">get_number_with_esd</span><span class="p">(</span><span class="n">val</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
256                    <span class="k">if</span> <span class="ow">not</span> <span class="n">atomlist</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">and</span> <span class="n">atomlist</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
257                        <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">2</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">):</span>
258                            <span class="n">typ</span> <span class="o">=</span> <span class="n">atomlist</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()[:</span><span class="n">i</span><span class="p">]</span>
259                            <span class="k">if</span> <span class="n">G2elem</span><span class="o">.</span><span class="n">CheckElement</span><span class="p">(</span><span class="n">typ</span><span class="p">):</span>
260                                <span class="n">atomlist</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">typ</span>
261                            <span class="k">if</span> <span class="ow">not</span> <span class="n">atomlist</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span> <span class="n">atomlist</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;Xe&#39;</span>
262                    <span class="n">ulbl</span> <span class="o">=</span> <span class="s">&#39;_atom_site_aniso_label&#39;</span>
263                    <span class="k">if</span>  <span class="n">atomlist</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="ow">and</span> <span class="n">atomlist</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ulbl</span><span class="p">):</span>
264                        <span class="k">for</span> <span class="n">val</span><span class="p">,</span><span class="n">key</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">anisoloop</span><span class="o">.</span><span class="n">GetKeyedPacket</span><span class="p">(</span><span class="n">ulbl</span><span class="p">,</span><span class="n">atomlist</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
265                                           <span class="n">anisokeys</span><span class="p">):</span>
266                            <span class="n">col</span> <span class="o">=</span> <span class="n">G2AtomDict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
267                            <span class="k">if</span> <span class="n">col</span><span class="p">:</span>
268                                <span class="n">atomlist</span><span class="p">[</span><span class="n">col</span><span class="p">]</span> <span class="o">=</span> <span class="n">cif</span><span class="o">.</span><span class="n">get_number_with_esd</span><span class="p">(</span><span class="n">val</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
269                    <span class="n">atomlist</span><span class="p">[</span><span class="mi">7</span><span class="p">],</span><span class="n">atomlist</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">atomlist</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">6</span><span class="p">],</span><span class="n">SGData</span><span class="p">)</span>
270                    <span class="n">atomlist</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">G2elem</span><span class="o">.</span><span class="n">FixValence</span><span class="p">(</span><span class="n">atomlist</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
271                    <span class="bp">self</span><span class="o">.</span><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">append</span><span class="p">(</span><span class="n">atomlist</span><span class="p">)</span>
272                    <span class="n">ranIdlookup</span><span class="p">[</span><span class="n">atomlist</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">atomlist</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
273                    <span class="k">if</span> <span class="n">atomlist</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="n">atomlbllist</span><span class="p">:</span>
274                        <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: repeated atom label: &#39;</span><span class="o">+</span><span class="n">atomlist</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
275                    <span class="k">else</span><span class="p">:</span>
276                        <span class="n">atomlbllist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">atomlist</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
277                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">atomlbllist</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;Atoms&#39;</span><span class="p">]):</span>
278                    <span class="bp">self</span><span class="o">.</span><span class="n">isodistort_warnings</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">Repeated atom labels prevents ISODISTORT decode&#39;</span>
279                <span class="k">for</span> <span class="n">lbl</span> <span class="ow">in</span> <span class="n">phasenamefields</span><span class="p">:</span> <span class="c"># get a name for the phase</span>
280                    <span class="n">name</span> <span class="o">=</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span>
281                    <span class="k">if</span> <span class="n">name</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
282                        <span class="k">continue</span>
283                    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
284                    <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;?&#39;</span> <span class="ow">or</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;.&#39;</span><span class="p">:</span>
285                        <span class="k">continue</span>
286                    <span class="k">else</span><span class="p">:</span>
287                        <span class="k">break</span>
288                <span class="k">else</span><span class="p">:</span> <span class="c"># no name found, use block name for lack of a better choice</span>
289                    <span class="n">name</span> <span class="o">=</span> <span class="n">blknm</span>
290                <span class="bp">self</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;Name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">strip</span><span class="p">()[:</span><span class="mi">20</span><span class="p">]</span>
291                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">isodistort_warnings</span><span class="p">:</span>
292                    <span class="k">if</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_displacivemode_label&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_occupancymode_label&#39;</span><span class="p">):</span>
293                        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&quot;Error while processing ISODISTORT constraints&quot;</span>
294                        <span class="bp">self</span><span class="o">.</span><span class="n">ISODISTORT_proc</span><span class="p">(</span><span class="n">blk</span><span class="p">,</span><span class="n">atomlbllist</span><span class="p">,</span><span class="n">ranIdlookup</span><span class="p">)</span>
295                <span class="k">else</span><span class="p">:</span>
296                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">isodistort_warnings</span>
297                <span class="n">returnstat</span> <span class="o">=</span> <span class="bp">True</span>
298        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">detail</span><span class="p">:</span>
299            <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>
300            <span class="k">print</span> <span class="s">&#39;CIF error:&#39;</span><span class="p">,</span><span class="n">detail</span> <span class="c"># for testing</span>
301            <span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="c"># for testing</span>
302            <span class="kn">import</span> <span class="nn">traceback</span>
303            <span class="k">print</span> <span class="n">traceback</span><span class="o">.</span><span class="n">format_exc</span><span class="p">()</span>
304            <span class="n">returnstat</span> <span class="o">=</span> <span class="bp">False</span>
305        <span class="k">return</span> <span class="n">returnstat</span>
306
307<div class="viewcode-block" id="CIFPhaseReader.ISODISTORT_proc"><a class="viewcode-back" href="../imports.html#G2phase_CIF.CIFPhaseReader.ISODISTORT_proc">[docs]</a>    <span class="k">def</span> <span class="nf">ISODISTORT_proc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">blk</span><span class="p">,</span><span class="n">atomlbllist</span><span class="p">,</span><span class="n">ranIdlookup</span><span class="p">):</span>
308        <span class="s">&#39;Process ISODISTORT items to create constraints etc.&#39;</span>
309        <span class="n">varLookup</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;dx&#39;</span><span class="p">:</span><span class="s">&#39;dAx&#39;</span><span class="p">,</span><span class="s">&#39;dy&#39;</span><span class="p">:</span><span class="s">&#39;dAy&#39;</span><span class="p">,</span><span class="s">&#39;dz&#39;</span><span class="p">:</span><span class="s">&#39;dAz&#39;</span><span class="p">,</span><span class="s">&#39;do&#39;</span><span class="p">:</span><span class="s">&#39;Afrac&#39;</span><span class="p">}</span>
310        <span class="s">&#39;Maps ISODISTORT parm names to GSAS-II names&#39;</span>
311        <span class="c">#----------------------------------------------------------------------</span>
312        <span class="c"># read in the ISODISTORT displacement modes</span>
313        <span class="c">#----------------------------------------------------------------------</span>
314        <span class="bp">self</span><span class="o">.</span><span class="n">Constraints</span> <span class="o">=</span> <span class="p">[]</span>
315        <span class="n">explaination</span> <span class="o">=</span> <span class="p">{}</span>
316        <span class="k">if</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_displacivemode_label&#39;</span><span class="p">):</span>
317            <span class="n">modelist</span> <span class="o">=</span> <span class="p">[]</span>
318            <span class="n">shortmodelist</span> <span class="o">=</span> <span class="p">[]</span>
319            <span class="k">for</span> <span class="n">lbl</span> <span class="ow">in</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_displacivemode_label&#39;</span><span class="p">):</span>
320                <span class="n">modelist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span>
321                <span class="c"># assume lbl is of form SSSSS[x,y,z]AAAA(a,b,...)BBBBB</span>
322                <span class="c"># where SSSSS is the parent spacegroup, [x,y,z] is a location </span>
323                <span class="n">regexp</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s">r&#39;.*?\[.*?\](.*?)\(.*?\)(.*)&#39;</span><span class="p">,</span><span class="n">lbl</span><span class="p">)</span>
324                <span class="c"># this extracts the AAAAA and BBBBB parts of the string</span>
325                <span class="k">if</span> <span class="n">regexp</span><span class="p">:</span>
326                    <span class="n">lbl</span> <span class="o">=</span> <span class="n">regexp</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="s">r&#39;\1\2&#39;</span><span class="p">)</span> <span class="c"># parse succeeded, make a short version</span>
327                <span class="n">G2obj</span><span class="o">.</span><span class="n">MakeUniqueLabel</span><span class="p">(</span><span class="n">lbl</span><span class="p">,</span><span class="n">shortmodelist</span><span class="p">)</span> <span class="c"># make unique and add to list</span>
328            <span class="c"># read in the coordinate offset variables names and map them to G2 names/objects</span>
329            <span class="n">coordVarLbl</span> <span class="o">=</span> <span class="p">[]</span>
330            <span class="n">G2varLbl</span> <span class="o">=</span> <span class="p">[]</span>
331            <span class="n">G2varObj</span> <span class="o">=</span> <span class="p">[]</span>
332            <span class="n">error</span> <span class="o">=</span> <span class="bp">False</span>
333            <span class="k">for</span> <span class="n">lbl</span> <span class="ow">in</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_deltacoordinate_label&#39;</span><span class="p">):</span>
334                <span class="n">coordVarLbl</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span>
335                <span class="k">if</span> <span class="s">&#39;_&#39;</span> <span class="ow">in</span> <span class="n">lbl</span><span class="p">:</span>
336                    <span class="n">albl</span> <span class="o">=</span> <span class="n">lbl</span><span class="p">[:</span><span class="n">lbl</span><span class="o">.</span><span class="n">rfind</span><span class="p">(</span><span class="s">&#39;_&#39;</span><span class="p">)]</span>
337                    <span class="n">vlbl</span> <span class="o">=</span> <span class="n">lbl</span><span class="p">[</span><span class="n">lbl</span><span class="o">.</span><span class="n">rfind</span><span class="p">(</span><span class="s">&#39;_&#39;</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">:]</span>
338                <span class="k">else</span><span class="p">:</span>
339                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_deltacoordinate_label not parsed: &#39;</span><span class="o">+</span><span class="n">lbl</span>
340                    <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
341                    <span class="k">continue</span>
342                <span class="k">if</span> <span class="n">albl</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">atomlbllist</span><span class="p">:</span>
343                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_deltacoordinate_label atom not found: &#39;</span><span class="o">+</span><span class="n">lbl</span>
344                    <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
345                    <span class="k">continue</span>
346                <span class="k">else</span><span class="p">:</span>
347                    <span class="n">anum</span> <span class="o">=</span> <span class="n">atomlbllist</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">albl</span><span class="p">)</span>
348                <span class="n">var</span> <span class="o">=</span> <span class="n">varLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">vlbl</span><span class="p">)</span>
349                <span class="k">if</span> <span class="ow">not</span> <span class="n">var</span><span class="p">:</span>
350                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_deltacoordinate_label variable not found: &#39;</span><span class="o">+</span><span class="n">lbl</span>
351                    <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
352                    <span class="k">continue</span>
353                <span class="n">G2varLbl</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;::&#39;</span><span class="o">+</span><span class="n">var</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">anum</span><span class="p">))</span> <span class="c"># variable name, less phase ID</span>
354                <span class="n">G2varObj</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">G2obj</span><span class="o">.</span><span class="n">G2VarObj</span><span class="p">(</span>
355                    <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;ranId&#39;</span><span class="p">],</span><span class="bp">None</span><span class="p">,</span><span class="n">var</span><span class="p">,</span><span class="n">ranIdlookup</span><span class="p">[</span><span class="n">albl</span><span class="p">])</span>
356                    <span class="p">))</span>
357            <span class="k">if</span> <span class="n">error</span><span class="p">:</span>
358                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;Error decoding variable labels&quot;</span>
359
360            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">G2varObj</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">modelist</span><span class="p">):</span>
361                <span class="k">print</span> <span class="s">&quot;non-square input&quot;</span>
362                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;Rank of _iso_displacivemode != _iso_deltacoordinate&quot;</span>
363
364            <span class="n">error</span> <span class="o">=</span> <span class="bp">False</span>
365            <span class="n">ParentCoordinates</span> <span class="o">=</span> <span class="p">{}</span>
366            <span class="k">for</span> <span class="n">lbl</span><span class="p">,</span><span class="n">exp</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span>
367                <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_coordinate_label&#39;</span><span class="p">),</span>
368                <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_coordinate_formula&#39;</span><span class="p">),</span>
369                <span class="p">):</span>
370                <span class="k">if</span> <span class="s">&#39;_&#39;</span> <span class="ow">in</span> <span class="n">lbl</span><span class="p">:</span>
371                    <span class="n">albl</span> <span class="o">=</span> <span class="n">lbl</span><span class="p">[:</span><span class="n">lbl</span><span class="o">.</span><span class="n">rfind</span><span class="p">(</span><span class="s">&#39;_&#39;</span><span class="p">)]</span>
372                    <span class="n">vlbl</span> <span class="o">=</span> <span class="n">lbl</span><span class="p">[</span><span class="n">lbl</span><span class="o">.</span><span class="n">rfind</span><span class="p">(</span><span class="s">&#39;_&#39;</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">:]</span>
373                <span class="k">else</span><span class="p">:</span>
374                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_coordinate_label not parsed: &#39;</span><span class="o">+</span><span class="n">lbl</span>
375                    <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
376                    <span class="k">continue</span>
377                <span class="k">if</span> <span class="n">vlbl</span> <span class="ow">not</span> <span class="ow">in</span> <span class="s">&#39;xyz&#39;</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">vlbl</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
378                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_coordinate_label coordinate not parsed: &#39;</span><span class="o">+</span><span class="n">lbl</span>
379                    <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
380                    <span class="k">continue</span>
381                <span class="n">i</span> <span class="o">=</span> <span class="s">&#39;xyz&#39;</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">vlbl</span><span class="p">)</span>
382                <span class="k">if</span> <span class="ow">not</span> <span class="n">ParentCoordinates</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">albl</span><span class="p">):</span>
383                    <span class="n">ParentCoordinates</span><span class="p">[</span><span class="n">albl</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">]</span>
384                <span class="k">if</span> <span class="s">&#39;+&#39;</span> <span class="ow">in</span> <span class="n">exp</span><span class="p">:</span>
385                    <span class="n">val</span> <span class="o">=</span> <span class="n">exp</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">strip</span><span class="p">()</span>
386                    <span class="n">val</span> <span class="o">=</span> <span class="n">G2p3</span><span class="o">.</span><span class="n">FormulaEval</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
387                    <span class="k">if</span> <span class="n">val</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
388                        <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_coordinate_formula coordinate not interpreted: &#39;</span><span class="o">+</span><span class="n">lbl</span>
389                        <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
390                        <span class="k">continue</span>
391                    <span class="n">ParentCoordinates</span><span class="p">[</span><span class="n">albl</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">val</span>
392                <span class="k">else</span><span class="p">:</span>
393                    <span class="n">ParentCoordinates</span><span class="p">[</span><span class="n">albl</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">G2p3</span><span class="o">.</span><span class="n">FormulaEval</span><span class="p">(</span><span class="n">exp</span><span class="p">)</span>
394            <span class="k">if</span> <span class="n">error</span><span class="p">:</span>
395                <span class="k">print</span> <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span>
396                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;Error decoding variable labels&quot;</span>
397            <span class="c"># get mapping of modes to atomic coordinate displacements</span>
398            <span class="n">displacivemodematrix</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">G2varObj</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">G2varObj</span><span class="p">)))</span>
399            <span class="k">for</span> <span class="n">row</span><span class="p">,</span><span class="n">col</span><span class="p">,</span><span class="n">val</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span>
400                <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_displacivemodematrix_row&#39;</span><span class="p">),</span>
401                <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_displacivemodematrix_col&#39;</span><span class="p">),</span>
402                <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_displacivemodematrix_value&#39;</span><span class="p">),):</span>
403                <span class="n">displacivemodematrix</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">row</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="nb">int</span><span class="p">(</span><span class="n">col</span><span class="p">)</span><span class="o">-</span><span class="mi">1</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>
404            <span class="c"># Invert to get mapping of atom displacements to modes</span>
405            <span class="n">displacivemodeInvmatrix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">displacivemodematrix</span><span class="p">)</span>
406            <span class="c"># create the constraints</span>
407            <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">row</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">displacivemodeInvmatrix</span><span class="p">):</span>
408                <span class="n">constraint</span> <span class="o">=</span> <span class="p">[]</span>
409                <span class="k">for</span> <span class="n">j</span><span class="p">,(</span><span class="n">lbl</span><span class="p">,</span><span class="n">k</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">coordVarLbl</span><span class="p">,</span><span class="n">row</span><span class="p">)):</span>
410                    <span class="k">if</span> <span class="n">k</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="k">continue</span>
411                    <span class="n">constraint</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">k</span><span class="p">,</span><span class="n">G2varObj</span><span class="p">[</span><span class="n">j</span><span class="p">]])</span>
412                <span class="n">constraint</span> <span class="o">+=</span> <span class="p">[</span><span class="n">shortmodelist</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="bp">False</span><span class="p">,</span><span class="s">&#39;f&#39;</span><span class="p">]</span>
413                <span class="bp">self</span><span class="o">.</span><span class="n">Constraints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">constraint</span><span class="p">)</span>
414            <span class="c">#----------------------------------------------------------------------</span>
415            <span class="c"># save the ISODISTORT info for &quot;mode analysis&quot;</span>
416            <span class="k">if</span> <span class="s">&#39;ISODISTORT&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;ISODISTORT&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
417            <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;ISODISTORT&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
418                <span class="s">&#39;IsoModeList&#39;</span> <span class="p">:</span> <span class="n">modelist</span><span class="p">,</span>
419                <span class="s">&#39;G2ModeList&#39;</span> <span class="p">:</span> <span class="n">shortmodelist</span><span class="p">,</span>
420                <span class="s">&#39;IsoVarList&#39;</span> <span class="p">:</span> <span class="n">coordVarLbl</span><span class="p">,</span>
421                <span class="s">&#39;G2VarList&#39;</span> <span class="p">:</span> <span class="n">G2varObj</span><span class="p">,</span>
422                <span class="s">&#39;ParentStructure&#39;</span> <span class="p">:</span> <span class="n">ParentCoordinates</span><span class="p">,</span>
423                <span class="s">&#39;Var2ModeMatrix&#39;</span> <span class="p">:</span> <span class="n">displacivemodeInvmatrix</span><span class="p">,</span>
424                <span class="s">&#39;Mode2VarMatrix&#39;</span> <span class="p">:</span> <span class="n">displacivemodematrix</span><span class="p">,</span>
425                <span class="p">})</span>
426            <span class="c"># make explaination dictionary</span>
427            <span class="k">for</span> <span class="n">mode</span><span class="p">,</span><span class="n">shortmode</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">modelist</span><span class="p">,</span><span class="n">shortmodelist</span><span class="p">):</span>
428                <span class="n">explaination</span><span class="p">[</span><span class="n">shortmode</span><span class="p">]</span> <span class="o">=</span> <span class="s">&quot;ISODISTORT full name &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">mode</span><span class="p">)</span>
429        <span class="c">#----------------------------------------------------------------------</span>
430        <span class="c"># now read in the ISODISTORT occupancy modes</span>
431        <span class="c">#----------------------------------------------------------------------</span>
432        <span class="k">if</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_occupancymode_label&#39;</span><span class="p">):</span>
433            <span class="n">modelist</span> <span class="o">=</span> <span class="p">[]</span>
434            <span class="n">shortmodelist</span> <span class="o">=</span> <span class="p">[]</span>
435            <span class="k">for</span> <span class="n">lbl</span> <span class="ow">in</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_occupancymode_label&#39;</span><span class="p">):</span>
436                <span class="n">modelist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span>
437                <span class="c"># assume lbl is of form SSSSS[x,y,z]AAAA(a,b,...)BBBBB</span>
438                <span class="c"># where SSSSS is the parent spacegroup, [x,y,z] is a location </span>
439                <span class="n">regexp</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s">r&#39;.*?\[.*?\](.*?)\(.*?\)(.*)&#39;</span><span class="p">,</span><span class="n">lbl</span><span class="p">)</span>
440                <span class="c"># this extracts the AAAAA and BBBBB parts of the string</span>
441                <span class="k">if</span> <span class="n">regexp</span><span class="p">:</span>
442                    <span class="n">lbl</span> <span class="o">=</span> <span class="n">regexp</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span><span class="s">r&#39;\1\2&#39;</span><span class="p">)</span> <span class="c"># parse succeeded, make a short version</span>
443                <span class="n">lbl</span> <span class="o">=</span> <span class="n">lbl</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;order&#39;</span><span class="p">,</span><span class="s">&#39;o&#39;</span><span class="p">)</span>
444                <span class="n">G2obj</span><span class="o">.</span><span class="n">MakeUniqueLabel</span><span class="p">(</span><span class="n">lbl</span><span class="p">,</span><span class="n">shortmodelist</span><span class="p">)</span> <span class="c"># make unique and add to list</span>
445            <span class="c"># read in the coordinate offset variables names and map them to G2 names/objects</span>
446            <span class="n">occVarLbl</span> <span class="o">=</span> <span class="p">[]</span>
447            <span class="n">G2varLbl</span> <span class="o">=</span> <span class="p">[]</span>
448            <span class="n">G2varObj</span> <span class="o">=</span> <span class="p">[]</span>
449            <span class="n">error</span> <span class="o">=</span> <span class="bp">False</span>
450            <span class="k">for</span> <span class="n">lbl</span> <span class="ow">in</span> <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_deltaoccupancy_label&#39;</span><span class="p">):</span>
451                <span class="n">occVarLbl</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lbl</span><span class="p">)</span>
452                <span class="k">if</span> <span class="s">&#39;_&#39;</span> <span class="ow">in</span> <span class="n">lbl</span><span class="p">:</span>
453                    <span class="n">albl</span> <span class="o">=</span> <span class="n">lbl</span><span class="p">[:</span><span class="n">lbl</span><span class="o">.</span><span class="n">rfind</span><span class="p">(</span><span class="s">&#39;_&#39;</span><span class="p">)]</span>
454                    <span class="n">vlbl</span> <span class="o">=</span> <span class="n">lbl</span><span class="p">[</span><span class="n">lbl</span><span class="o">.</span><span class="n">rfind</span><span class="p">(</span><span class="s">&#39;_&#39;</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">:]</span>
455                <span class="k">else</span><span class="p">:</span>
456                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_deltaoccupancy_label not parsed: &#39;</span><span class="o">+</span><span class="n">lbl</span>
457                    <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
458                    <span class="k">continue</span>
459                <span class="k">if</span> <span class="n">albl</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">atomlbllist</span><span class="p">:</span>
460                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_deltaoccupancy_label atom not found: &#39;</span><span class="o">+</span><span class="n">lbl</span>
461                    <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
462                    <span class="k">continue</span>
463                <span class="k">else</span><span class="p">:</span>
464                    <span class="n">anum</span> <span class="o">=</span> <span class="n">atomlbllist</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">albl</span><span class="p">)</span>
465                <span class="n">var</span> <span class="o">=</span> <span class="n">varLookup</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">vlbl</span><span class="p">)</span>
466                <span class="k">if</span> <span class="ow">not</span> <span class="n">var</span><span class="p">:</span>
467                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_deltaoccupancy_label variable not found: &#39;</span><span class="o">+</span><span class="n">lbl</span>
468                    <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
469                    <span class="k">continue</span>
470                <span class="n">G2varLbl</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;::&#39;</span><span class="o">+</span><span class="n">var</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">anum</span><span class="p">))</span> <span class="c"># variable name, less phase ID</span>
471                <span class="n">G2varObj</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">G2obj</span><span class="o">.</span><span class="n">G2VarObj</span><span class="p">(</span>
472                    <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;ranId&#39;</span><span class="p">],</span><span class="bp">None</span><span class="p">,</span><span class="n">var</span><span class="p">,</span><span class="n">ranIdlookup</span><span class="p">[</span><span class="n">albl</span><span class="p">])</span>
473                    <span class="p">))</span>
474            <span class="k">if</span> <span class="n">error</span><span class="p">:</span>
475                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;Error decoding variable labels&quot;</span>
476
477            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">G2varObj</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">modelist</span><span class="p">):</span>
478                <span class="k">print</span> <span class="s">&quot;non-square input&quot;</span>
479                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;Rank of _iso_occupancymode != _iso_deltaoccupancy&quot;</span>
480
481            <span class="n">error</span> <span class="o">=</span> <span class="bp">False</span>
482            <span class="n">ParentCoordinates</span> <span class="o">=</span> <span class="p">{}</span>
483            <span class="k">for</span> <span class="n">lbl</span><span class="p">,</span><span class="n">exp</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span>
484                <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_occupancy_label&#39;</span><span class="p">),</span>
485                <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_occupancy_formula&#39;</span><span class="p">),</span>
486                <span class="p">):</span>
487                <span class="k">if</span> <span class="s">&#39;_&#39;</span> <span class="ow">in</span> <span class="n">lbl</span><span class="p">:</span>
488                    <span class="n">albl</span> <span class="o">=</span> <span class="n">lbl</span><span class="p">[:</span><span class="n">lbl</span><span class="o">.</span><span class="n">rfind</span><span class="p">(</span><span class="s">&#39;_&#39;</span><span class="p">)]</span>
489                    <span class="n">vlbl</span> <span class="o">=</span> <span class="n">lbl</span><span class="p">[</span><span class="n">lbl</span><span class="o">.</span><span class="n">rfind</span><span class="p">(</span><span class="s">&#39;_&#39;</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">:]</span>
490                <span class="k">else</span><span class="p">:</span>
491                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_occupancy_label not parsed: &#39;</span><span class="o">+</span><span class="n">lbl</span>
492                    <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
493                    <span class="k">continue</span>
494                <span class="k">if</span> <span class="n">vlbl</span> <span class="o">!=</span> <span class="s">&#39;occ&#39;</span><span class="p">:</span>
495                    <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_occupancy_label coordinate not parsed: &#39;</span><span class="o">+</span><span class="n">lbl</span>
496                    <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
497                    <span class="k">continue</span>
498                <span class="k">if</span> <span class="s">&#39;+&#39;</span> <span class="ow">in</span> <span class="n">exp</span><span class="p">:</span>
499                    <span class="n">val</span> <span class="o">=</span> <span class="n">exp</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">strip</span><span class="p">()</span>
500                    <span class="n">val</span> <span class="o">=</span> <span class="n">G2p3</span><span class="o">.</span><span class="n">FormulaEval</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
501                    <span class="k">if</span> <span class="n">val</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
502                        <span class="bp">self</span><span class="o">.</span><span class="n">warnings</span> <span class="o">+=</span> <span class="s">&#39; ERROR: _iso_occupancy_formula coordinate not interpreted: &#39;</span><span class="o">+</span><span class="n">lbl</span>
503                        <span class="n">error</span> <span class="o">=</span> <span class="bp">True</span>
504                        <span class="k">continue</span>
505                    <span class="n">ParentCoordinates</span><span class="p">[</span><span class="n">albl</span><span class="p">]</span> <span class="o">=</span> <span class="n">val</span>
506            <span class="k">if</span> <span class="n">error</span><span class="p">:</span>
507                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">,</span><span class="s">&quot;Error decoding occupancy labels&quot;</span>
508            <span class="c"># get mapping of modes to atomic coordinate displacements</span>
509            <span class="n">occupancymodematrix</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">G2varObj</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">G2varObj</span><span class="p">)))</span>
510            <span class="k">for</span> <span class="n">row</span><span class="p">,</span><span class="n">col</span><span class="p">,</span><span class="n">val</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span>
511                <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_occupancymodematrix_row&#39;</span><span class="p">),</span>
512                <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_occupancymodematrix_col&#39;</span><span class="p">),</span>
513                <span class="n">blk</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;_iso_occupancymodematrix_value&#39;</span><span class="p">),):</span>
514                <span class="n">occupancymodematrix</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">row</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="nb">int</span><span class="p">(</span><span class="n">col</span><span class="p">)</span><span class="o">-</span><span class="mi">1</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>
515            <span class="c"># Invert to get mapping of atom displacements to modes</span>
516            <span class="n">occupancymodeInvmatrix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="n">occupancymodematrix</span><span class="p">)</span>
517            <span class="c"># create the constraints</span>
518            <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">row</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">occupancymodeInvmatrix</span><span class="p">):</span>
519                <span class="n">constraint</span> <span class="o">=</span> <span class="p">[]</span>
520                <span class="k">for</span> <span class="n">j</span><span class="p">,(</span><span class="n">lbl</span><span class="p">,</span><span class="n">k</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">occVarLbl</span><span class="p">,</span><span class="n">row</span><span class="p">)):</span>
521                    <span class="k">if</span> <span class="n">k</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="k">continue</span>
522                    <span class="n">constraint</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">k</span><span class="p">,</span><span class="n">G2varObj</span><span class="p">[</span><span class="n">j</span><span class="p">]])</span>
523                <span class="n">constraint</span> <span class="o">+=</span> <span class="p">[</span><span class="n">shortmodelist</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="bp">False</span><span class="p">,</span><span class="s">&#39;f&#39;</span><span class="p">]</span>
524                <span class="bp">self</span><span class="o">.</span><span class="n">Constraints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">constraint</span><span class="p">)</span>
525            <span class="c">#----------------------------------------------------------------------</span>
526            <span class="c"># save the ISODISTORT info for &quot;mode analysis&quot;</span>
527            <span class="k">if</span> <span class="s">&#39;ISODISTORT&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;ISODISTORT&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
528            <span class="bp">self</span><span class="o">.</span><span class="n">Phase</span><span class="p">[</span><span class="s">&#39;ISODISTORT&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
529                <span class="s">&#39;OccModeList&#39;</span> <span class="p">:</span> <span class="n">modelist</span><span class="p">,</span>
530                <span class="s">&#39;G2OccModeList&#39;</span> <span class="p">:</span> <span class="n">shortmodelist</span><span class="p">,</span>
531                <span class="s">&#39;OccVarList&#39;</span> <span class="p">:</span> <span class="n">occVarLbl</span><span class="p">,</span>
532                <span class="s">&#39;G2OccVarList&#39;</span> <span class="p">:</span> <span class="n">G2varObj</span><span class="p">,</span>
533                <span class="s">&#39;BaseOcc&#39;</span> <span class="p">:</span> <span class="n">ParentCoordinates</span><span class="p">,</span>
534                <span class="s">&#39;Var2OccMatrix&#39;</span> <span class="p">:</span> <span class="n">occupancymodeInvmatrix</span><span class="p">,</span>
535                <span class="s">&#39;Occ2VarMatrix&#39;</span> <span class="p">:</span> <span class="n">occupancymodematrix</span><span class="p">,</span>
536                <span class="p">})</span>
537            <span class="c"># make explaination dictionary</span>
538            <span class="k">for</span> <span class="n">mode</span><span class="p">,</span><span class="n">shortmode</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">modelist</span><span class="p">,</span><span class="n">shortmodelist</span><span class="p">):</span>
539                <span class="n">explaination</span><span class="p">[</span><span class="n">shortmode</span><span class="p">]</span> <span class="o">=</span> <span class="s">&quot;ISODISTORT full name &quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">mode</span><span class="p">)</span>
540        <span class="c">#----------------------------------------------------------------------</span>
541        <span class="c"># done with read</span>
542        <span class="c">#----------------------------------------------------------------------</span>
543        <span class="k">if</span> <span class="n">explaination</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">Constraints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">explaination</span><span class="p">)</span>
544
545        <span class="c"># # debug: show the mode var to mode relations</span>
546        <span class="c"># for i,row in enumerate(displacivemodeInvmatrix):</span>
547        <span class="c">#     l = &#39;&#39;</span>
548        <span class="c">#     for j,(lbl,k) in enumerate(zip(coordVarLbl,row)):</span>
549        <span class="c">#         if k == 0: continue</span>
550        <span class="c">#         if l: l += &#39; + &#39;</span>
551        <span class="c">#         #l += lbl+&#39; * &#39;+str(k)</span>
552        <span class="c">#         l += G2varLbl[j]+&#39; * &#39;+str(k)</span>
553        <span class="c">#     print str(i) + &#39;: &#39;+shortmodelist[i]+&#39; = &#39;+l</span>
554        <span class="c"># print 70*&#39;=&#39;</span>
555
556        <span class="c"># # debug: Get the ISODISTORT offset values</span>
557        <span class="c"># coordVarDelta = {}</span>
558        <span class="c"># for lbl,val in zip(</span>
559        <span class="c">#     blk.get(&#39;_iso_deltacoordinate_label&#39;),</span>
560        <span class="c">#     blk.get(&#39;_iso_deltacoordinate_value&#39;),):</span>
561        <span class="c">#     coordVarDelta[lbl] = float(val)</span>
562        <span class="c"># modeVarDelta = {}</span>
563        <span class="c"># for lbl,val in zip(</span>
564        <span class="c">#     blk.get(&#39;_iso_displacivemode_label&#39;),</span>
565        <span class="c">#     blk.get(&#39;_iso_displacivemode_value&#39;),):</span>
566        <span class="c">#     modeVarDelta[lbl] = cif.get_number_with_esd(val)[0]</span>
567
568        <span class="c"># print 70*&#39;=&#39;</span>
569        <span class="c"># # compute the mode values from the reported coordinate deltas</span>
570        <span class="c"># for i,row in enumerate(displacivemodeInvmatrix):</span>
571        <span class="c">#     l = &#39;&#39;</span>
572        <span class="c">#     sl = &#39;&#39;</span>
573        <span class="c">#     s = 0.</span>
574        <span class="c">#     for lbl,k in zip(coordVarLbl,row):</span>
575        <span class="c">#         if k == 0: continue</span>
576        <span class="c">#         if l: l += &#39; + &#39;</span>
577        <span class="c">#         l += lbl+&#39; * &#39;+str(k)</span>
578        <span class="c">#         if sl: sl += &#39; + &#39;</span>
579        <span class="c">#         sl += str(coordVarDelta[lbl])+&#39; * &#39;+str(k)</span>
580        <span class="c">#         s += coordVarDelta[lbl] * k</span>
581        <span class="c">#     print &#39;a&#39;+str(i)+&#39; = &#39;+l</span>
582        <span class="c">#     print &#39;\t= &#39;+sl</span>
583        <span class="c">#     print  modelist[i],shortmodelist[i],modeVarDelta[modelist[i]],s</span>
584        <span class="c">#     print</span>
585
586        <span class="c"># print 70*&#39;=&#39;</span>
587        <span class="c"># # compute the coordinate displacements from the reported mode values</span>
588        <span class="c"># for i,lbl,row in zip(range(len(coordVarLbl)),coordVarLbl,displacivemodematrix):</span>
589        <span class="c">#     l = &#39;&#39;</span>
590        <span class="c">#     sl = &#39;&#39;</span>
591        <span class="c">#     s = 0.0</span>
592        <span class="c">#     for j,k in enumerate(row):</span>
593        <span class="c">#         if k == 0: continue</span>
594        <span class="c">#         if l: l += &#39; + &#39;</span>
595        <span class="c">#         l += &#39;a&#39;+str(j+1)+&#39; * &#39;+str(k)</span>
596        <span class="c">#         if sl: sl += &#39; + &#39;</span>
597        <span class="c">#         sl += str(shortmodelist[j]) +&#39; = &#39;+ str(modeVarDelta[modelist[j]]) + &#39; * &#39;+str(k)</span>
598        <span class="c">#         s += modeVarDelta[modelist[j]] * k</span>
599        <span class="c">#     print lbl+&#39; = &#39;+l</span>
600        <span class="c">#     print &#39;\t= &#39;+sl</span>
601        <span class="c">#     print lbl,G2varLbl[i],coordVarDelta[lbl],s</span>
602        <span class="c">#     print</span>
603
604        <span class="c"># determine the coordinate delta values from deviations from the parent structure</span>
605        <span class="c"># for atmline in self.Phase[&#39;Atoms&#39;]:</span>
606        <span class="c">#     lbl = atmline[0]</span>
607        <span class="c">#     x,y,z = atmline[3:6]</span>
608        <span class="c">#     if lbl not in ParentCoordinates:</span>
609        <span class="c">#         print lbl,x,y,z</span>
610        <span class="c">#         continue</span>
611        <span class="c">#     px,py,pz = ParentCoordinates[lbl]</span>
612        <span class="c">#     print lbl,x,y,z,x-px,y-py,z-pz</span></div></div>
613</pre></div>
614
615          </div>
616        </div>
617      </div>
618      <div class="sphinxsidebar">
619        <div class="sphinxsidebarwrapper">
620            <p class="logo"><a href="../index.html">
621              <img class="logo" src="../_static/G2_html_logo.png" alt="Logo"/>
622            </a></p>
623<div id="searchbox" style="display: none">
624  <h3>Quick search</h3>
625    <form class="search" action="../search.html" method="get">
626      <input type="text" name="q" />
627      <input type="submit" value="Go" />
628      <input type="hidden" name="check_keywords" value="yes" />
629      <input type="hidden" name="area" value="default" />
630    </form>
631    <p class="searchtip" style="font-size: 90%">
632    Enter search terms or a module, class or function name.
633    </p>
634</div>
635<script type="text/javascript">$('#searchbox').show(0);</script>
636        </div>
637      </div>
638      <div class="clearer"></div>
639    </div>
640    <div class="related">
641      <h3>Navigation</h3>
642      <ul>
643        <li class="right" style="margin-right: 10px">
644          <a href="../genindex.html" title="General Index"
645             >index</a></li>
646        <li class="right" >
647          <a href="../py-modindex.html" title="Python Module Index"
648             >modules</a> |</li>
649        <li><a href="../index.html">GSAS-II 0.2.0 documentation</a> &raquo;</li>
650          <li><a href="index.html" >Module code</a> &raquo;</li> 
651      </ul>
652    </div>
653    <div class="footer">
654        &copy; Copyright 2013, Von Dreele and Toby for Argonne National Laboratory.
655      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
656    </div>
657  </body>
658</html>
Note: See TracBrowser for help on using the repository browser.