1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14  """ 
 15  This package contains the Phase class in SrRietveld, which is an script interface 
 16  to access the structure information 
 17  """ 
 18   
 19  __id__ = "$Id: phase.py 6726 2011-08-25 09:36:23Z yshang $" 
 20   
 21  from diffpy.refinementdata.structure import Structure 
 22  from diffpy.srrietveld.paramnames import PARAMNAMES 
 23  import diffpy.srrietveld.utility as UTILS  
 24   
 26      """A Phase object saves the structure to be refined. It contains the  
 27      a list of variables to represent a structure. such as a, b, c, alpha, beta,  
 28      gamma and so on.  
 29       
 30      data member: 
 31          spacegroup: space group of the structure 
 32          a,b,c:  the lattice constant 
 33          alpha,beta,gamma: the lattice angle 
 34       
 35      This class is also an interface for the Structure class in  
 36      diffpy.refinementdata.structure package, to provide convenient access functions 
 37      to the structure data  
 38      """ 
 39 -    def __init__(self, owner, name=None, handle=None, shape=None): 
  40          """ 
 41          Constructor. The construction of a Phase object is taken care of by the 
 42          Project. Users do not have to call this function directly.  
 43           
 44          @type owner:    a data object 
 45          @param owner:    the owner, which is usually a Refinement object. 
 46          @type name:    string 
 47          @param name:    the node name. 
 48          @type handle:    a HDF5Handle object 
 49          @param handle:    a HDF5Handle pointing to the underlying HDF5 node.  
 50          @type shape:    tuple 
 51          @param shape:    the shape of the data object. Each element denotes  
 52                          the number of elements in each dimension 
 53           
 54          A name is passed to the initialization method when creating a node. 
 55           
 56          A handle is passed to the inialization method in two cases: 
 57              1.  when loading from a HDF5 file; 
 58              2.  when creating a HDF5 file but the object is a hard link to  
 59                  a preexisiting one. 
 60                   
 61          In the case when both name and handle are given, name will be simply ignored. 
 62          In the case when neither name nor handle is given, an exception will be raised. 
 63          """ 
 64          Structure.__init__(self, owner, name, handle, shape) 
 65          return 
  66       
 68          ''' 
 69          Get the atom by its name 
 70           
 71          @type name: string 
 72          @param name: the atom name 
 73           
 74          @return: the atom object with the name if exists. None if no such  
 75                  phase object. The program will emit a warning if duplicate  
 76                  atom names exist, and the first atom obj with the same name 
 77                  will be returned 
 78          ''' 
 79   
 80          rv = [None] 
 81          rv = [obj for obj in self.listAtoms() if obj.name == name] 
 82          if len(rv) > 1: 
 83              __msg = 'Duplicate phase names, the first refinement is returned' 
 84              UTILS.printWarning(__msg) 
 85               
 86          return rv[0] 
  87           
 89          """ 
 90          Get the space group of the phase 
 91           
 92          @return:    return the space group string list 
 93          """ 
 94          return self.getByPath(PARAMNAMES[self.getEngineType()]["space_group"]) 
  95       
 97          """ 
 98          Get the lattice parameter a in angstroms 
 99           
100          @return:        the lattice a values 
101          """ 
102          return self.getByPath(PARAMNAMES[self.getEngineType()]["a"]) 
 103       
105          """ 
106          Get the standard deviation of lattice parameter a in angstroms 
107           
108          @return:        the lattice a values 
109          """ 
110          return self.getSigmaByPath(PARAMNAMES[self.getEngineType()]["a"]) 
 111       
112       
114          """ 
115          Get the lattice parameter b in anstrom 
116           
117          @return:     the lattice b values 
118          """ 
119          return self.getByPath(PARAMNAMES[self.getEngineType()][ "b"]) 
 120       
122          """ 
123          Get the standard deviation of lattice parameter b in anstrom 
124           
125          @return:     the lattice b standard deviations 
126          """ 
127          return self.getSigmaByPath(PARAMNAMES[self.getEngineType()][ "b"]) 
 128       
130          """ 
131          Get the lattice parameter c in anstrom 
132           
133          @return:   the lattice c values 
134          """ 
135          return self.getByPath(PARAMNAMES[self.getEngineType()]["c"]) 
 136       
138          """ 
139          Get the standard deviation of lattice parameter c in anstrom 
140           
141          @return:   the lattice c standard deviations 
142          """ 
143          return self.getSigmaByPath(PARAMNAMES[self.getEngineType()]["c"]) 
 144       
145       
147          """ 
148          Get the alpha value in degree 
149           
150          @return:    if index is None, return the alpha value list in a Dataset 
151                      if index is a number or tuple, return the a value as a float 
152          """ 
153          return self.getByPath(PARAMNAMES[self.getEngineType()]["alpha"]) 
 154   
156          """ 
157          Get the alpha value in degree 
158           
159          @return:    if index is None, return the alpha value list in a Dataset 
160                      if index is a number or tuple, return the a value as a float 
161          """ 
162          return self.getSigmaByPath(PARAMNAMES[self.getEngineType()]["alpha"]) 
 163   
164   
166          """ 
167          Get the beta value in degree 
168           
169          @return:    if index is None, return the beta value list in a Dataset 
170                      if index is a number or tuple, return the a value as a float 
171          """ 
172          return self.getByPath(PARAMNAMES[self.getEngineType()]["beta"]) 
 173   
175          """ 
176          Get the standard deviation beta value in degree 
177           
178          @return:   the beta standard deviations 
179          """ 
180          return self.getSigmaByPath(PARAMNAMES[self.getEngineType()]["beta"]) 
 181       
183          '''Get the engine type for this refinement 
184           
185          @return:    the string of the engine type, for example I{"gsas"} or I{"fullprof"}''' 
186           
187          return self.owner.owner.getEngineType() 
 188   
190          """ 
191          Get the gamma value in degree 
192           
193          @return:  return the gamma values 
194          """ 
195          return self.getByPath(PARAMNAMES[self.getEngineType()]["gamma"]) 
 196   
198          """ 
199          Get the standard deviation gamma value in degree 
200           
201          @return:  return the gamma standard deviations 
202          """ 
203          return self.getSigmaByPath(PARAMNAMES[self.getEngineType()]["gamma"]) 
 204       
206          ''' 
207          Get the phase name 
208           
209          @return: string 
210          ''' 
211          return self.get('Name').first() 
 212       
214          """ 
215          Get number of atoms in the phase 
216           
217          @return: number of atoms 
218          """ 
219          return len(self.listAtoms()) 
 220       
222          """ 
223          List the atoms  
224           
225          @return: a list of Atom objects 
226          """ 
227          return [obj for obj in self.listObjects(recursively = True) if obj.name.startswith('Atom[')] 
 228       
230          ''' 
231          List the atom names 
232           
233          @return: a list of atom names in this phase 
234          ''' 
235          return[atom.getName() for atom in self.listAtoms()] 
  236