Changeset 5142


Ignore:
Timestamp:
Jan 14, 2022 2:33:02 PM (9 months ago)
Author:
toby
Message:

revise CIF output to include only unique su values

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r5127 r5142  
    14581458        self.G2frame.CheckNotebook()
    14591459        self.parmDict = {}
    1460         self.sigDict = {}
     1460        self.sigDict = {} # dict with s.u. values, currently used only for CIF exports
    14611461        rigidbodyDict = {}
    14621462        covDict = {}
     
    15321532        # and add their uncertainties into the esd dictionary (sigDict)
    15331533        if covDict.get('covMatrix') is not None:
    1534             self.sigDict.update(G2mv.ComputeDepESD(covDict['covMatrix'],covDict['varyList'],self.parmDict))
     1534            self.sigDict.update(G2mv.ComputeDepESD(covDict['covMatrix'],covDict['varyList'],allvars=False))
    15351535
    15361536    def loadTree(self):
     
    18061806
    18071807    # Tools to pull information out of the data arrays
    1808     def GetCell(self,phasenam):
     1808    def GetCell(self,phasenam,unique=False):
    18091809        """Gets the unit cell parameters and their s.u.'s for a selected phase
    18101810
    18111811        :param str phasenam: the name for the selected phase
     1812        :param bool unique: when True, only directly refined parameters
     1813          (a in cubic, a & alpha in rhombohedral cells) are assigned
     1814          positive s.u. values. Used as True for CIF generation.
    18121815        :returns: `cellList,cellSig` where each is a 7 element list corresponding
    18131816          to a, b, c, alpha, beta, gamma, volume where `cellList` has the
     
    18211824            A,sigA = G2stIO.cellFill(pfx,phasedict['General']['SGData'],self.parmDict,self.sigDict)
    18221825            cellSig = G2stIO.getCellEsd(pfx,phasedict['General']['SGData'],A,
    1823                 self.OverallParms['Covariance'])  # returns 7 vals, includes sigVol
     1826                self.OverallParms['Covariance'],unique=unique)  # returns 7 vals, includes sigVol
    18241827            cellList = G2lat.A2cell(A) + (G2lat.calc_V(A),)
    18251828            return cellList,cellSig
  • trunk/GSASIImapvars.py

    r5118 r5142  
    20762076    return False,msg,note
    20772077       
    2078 def ComputeDepESD(covMatrix,varyList,parmDict):
     2078def ComputeDepESD(covMatrix,varyList,allvars=True):
    20792079    '''Compute uncertainties for dependent parameters from independent ones
    20802080    returns a dictionary containing the esd values for dependent parameters
     2081   
     2082    :param np.array covMatrix: the full covariance matrix
     2083    :param list varyList: the names of the variables matching the columns
     2084      and rows in covMatrix
     2085    :param bool allvars: When True (default) s.u. values for all parameters
     2086      are placed in the returned dict. When False the number of s.u. values
     2087      attempts to match the number of refined degrees of freedom. The s.u.'s
     2088      for dependent params from equivalences are not computed and
     2089      the number of dependent params from new var and generated var
     2090      constraints matches the number of refined independent parameters.
    20812091    '''
    20822092    sigmaDict = {}
    2083     for varlist,mapvars,invmultarr in zip(dependentParmList,indParmList,invarrayList):
    2084         #if invmultarr is None: continue # probably not needed
    2085 #        try:
    2086 #            valuelist = [parmDict[var] for var in mapvars]
    2087 #        except KeyError:
    2088 #            continue
     2093    for varlist,mapvars,multarr,invmultarr in zip(dependentParmList,indParmList,arrayList,invarrayList):
     2094        if multarr is None and not allvars: continue # probably not needed
     2095        varied = 0
    20892096        # get the v-covar matrix for independent parameters
    20902097        vcov = np.zeros((len(mapvars),len(mapvars)))
    20912098        for i1,name1 in enumerate(mapvars):
    20922099            if name1 not in varyList: continue
     2100            varied += 1
    20932101            iv1 = varyList.index(name1)
    20942102            for i2,name2 in enumerate(mapvars):
     
    20972105                vcov[i1][i2] = covMatrix[iv1][iv2]
    20982106        # vec is the vector that multiplies each of the independent values
    2099         for v,vec in zip(varlist,invmultarr):
     2107        for i,(v,vec) in enumerate(zip(varlist,invmultarr)):
     2108            if i == varied: break
    21002109            sigmaDict[v] = np.sqrt(np.inner(vec.T,np.inner(vcov,vec)))
    21012110    return sigmaDict
  • trunk/GSASIIscriptable.py

    r5070 r5142  
    50165016
    50175017            if covDict.get('covMatrix') is not None:
    5018                 sigDict.update(G2mv.ComputeDepESD(covDict['covMatrix'],
    5019                                                   covDict['varyList'],
    5020                                                   parmDict))
     5018                sigDict.update(G2mv.ComputeDepESD(covDict['covMatrix'],covDict['varyList']))
    50215019
    50225020            A, sigA = G2stIO.cellFill(pfx, sgdata, parmDict, sigDict)
     
    50635061
    50645062        if covDict.get('covMatrix') is not None:
    5065             sigDict.update(G2mv.ComputeDepESD(covDict['covMatrix'],
    5066                                               covDict['varyList'],
    5067                                               parmDict))
     5063            sigDict.update(G2mv.ComputeDepESD(covDict['covMatrix'],covDict['varyList'],allvars=False))
    50685064
    50695065        with open(outputname, 'w') as fp:
  • trunk/GSASIIstrIO.py

    r5141 r5142  
    18321832                        pFile.write ('   %d %d %d  %d %8.3f %8.3f %8d   %s    %8.3f\n'%(hkl[0],hkl[1],hkl[2],grid,esd1,sum,num,str(ifesd2),esd2))
    18331833       
    1834 def getCellEsd(pfx,SGData,A,covData):
     1834def getCellEsd(pfx,SGData,A,covData,unique=False):
    18351835    '''Compute the standard uncertainty on cell parameters
    18361836   
     
    18391839    :param list A: Reciprocal cell Ai terms
    18401840    :param dict covData: covariance tree item
     1841    :param bool unique: when True, only directly refined parameters
     1842      (a in cubic, a & alpha in rhombohedral cells) are assigned
     1843      positive s.u. values. Used for CIF generation.
    18411844    '''
    18421845    rVsq = G2lat.calc_rVsq(A)
     
    18921895    if SGData['SGLaue'] in ['3', '3m1', '31m', '6/m', '6/mmm','m3','m3m','4/m','4/mmm']:
    18931896        CS[3:6] = 0.0
     1897    # show s.u. values only for the unique values
     1898    if not unique:
     1899        pass
     1900    elif SGData['SGLaue'] in ['3', '3m1', '31m', '6/m', '6/mmm','4/m', '4/mmm']:
     1901        CS[1] = -CS[1]
     1902    elif SGData['SGLaue'] in ['m3','m3m']:
     1903        CS[1] = -CS[1]
     1904        CS[2] = -CS[2]
     1905    elif SGData['SGLaue'] in ['3R','3mR']:
     1906        CS[1] = -CS[1]
     1907        CS[2] = -CS[2]
     1908        CS[4] = -CS[4]
     1909        CS[3] = -CS[3]
    18941910    return [CS[0],CS[1],CS[2],CS[5],CS[4],CS[3],sigVol]
    18951911
    18961912def getCellSU(pId,hId,SGData,parmDict,covData):
    18971913    '''Compute the unit cell parameters and standard uncertainties
    1898     where lattice parameters and Hstrain (Dij) may be refined
     1914    where lattice parameters and Hstrain (Dij) may be refined. This is
     1915    called only for generation of CIFs.
    18991916   
    19001917    :param pId: phase index
     
    19631980    if SGData['SGLaue'] in ['3', '3m1', '31m', '6/m', '6/mmm','m3','m3m','4/m','4/mmm']:
    19641981        CS[3:6] = 0.0
     1982    # show s.u. values only for the unique values
     1983    if SGData['SGLaue'] in ['3', '3m1', '31m', '6/m', '6/mmm','4/m', '4/mmm']:
     1984        CS[1] = -CS[1]
     1985    elif SGData['SGLaue'] in ['m3','m3m']:
     1986        CS[1] = -CS[1]
     1987        CS[2] = -CS[2]
     1988    elif SGData['SGLaue'] in ['3R','3mR']:
     1989        CS[1] = -CS[1]
     1990        CS[2] = -CS[2]
     1991        CS[4] = -CS[4]
     1992        CS[3] = -CS[3]
    19651993    return cell,[CS[0],CS[1],CS[2],CS[5],CS[4],CS[3],sigVol]
    19661994
     
    22062234        if cell[0]:
    22072235            A,sigA = cellFill(pfx,SGData,parmDict,sigDict)
    2208             cellSig = getCellEsd(pfx,SGData,A,covData)  #includes sigVol
     2236            cellSig = getCellEsd(pfx,SGData,A,covData,unique=True)  #includes sigVol
    22092237            if pFile: pFile.write(' Reciprocal metric tensor: \n')
    22102238            ptfmt = "%15.9f"
     
    22342262                namstr += '%12s'%(name)
    22352263                ptstr += fmt%(a)
    2236                 if siga:
     2264                if siga and siga > 0:
    22372265                    sigstr += fmt%(siga)
    22382266                else:
  • trunk/GSASIIstrMain.py

    r5135 r5142  
    407407                       'newCellDict':newCellDict,'freshCOV':True}
    408408            # add the uncertainties into the esd dictionary (sigDict)
    409             sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict))
     409            sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList))
    410410            # check for variables outside their allowed range, reset and freeze them
    411411            frozen = dropOOBvars(varyList,parmDict,sigDict,Controls,parmFrozenList)
     
    843843            sigDict = dict(zip(varyList,sig))
    844844            # the uncertainties for dependent constrained parms into the esd dict
    845             sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList,parmDict))
     845            sigDict.update(G2mv.ComputeDepESD(covMatrix,varyList))
    846846            # check for variables outside their allowed range, reset and freeze them
    847847            frozen = dropOOBvars(varyList,parmDict,sigDict,Controls,parmFrozenList)
  • trunk/exports/G2export_CIF.py

    r5136 r5142  
    103103        A,zeros = G2stIO.cellFill(pfx,phasedict['General']['SGData'],cellDict,zeroDict)
    104104        cell = list(G2lat.A2cell(A)) + [G2lat.calc_V(A)]
    105         cE = G2stIO.getCellEsd(pfx,phasedict['General']['SGData'],A,covData)
     105        cE = G2stIO.getCellEsd(pfx,phasedict['General']['SGData'],A,covData,unique=True)
    106106    except:
    107107        cell = 7*[None]
     
    279279                    c = G2lat.A2cell(A)
    280280                    vol = G2lat.calc_V(A)
    281                     cE = G2stIO.getCellEsd(pfx,SGdata[pId],A,covData)
     281                    cE = G2stIO.getCellEsd(pfx,SGdata[pId],A,covData,unique=True)
    282282                except:
    283283                    c = 6*[None]
     
    25132513            phasedict = self.Phases[phasenam] # pointer to current phase info
    25142514            WriteCIFitem(self.fp, '_pd_phase_name', phasenam)
    2515             cellList,cellSig = self.GetCell(phasenam)
     2515            cellList,cellSig = self.GetCell(phasenam,unique=True)
    25162516            if quick:  # leave temperature as unknown
    25172517                WriteCIFitem(self.fp,"_cell_measurement_temperature","?")
     
    26552655            phasedict = self.Phases[phasenam] # pointer to current phase info
    26562656            WriteCIFitem(self.fp, '_cell.entry_id', phasenam)
    2657             cellList,cellSig = self.GetCell(phasenam)
     2657            cellList,cellSig = self.GetCell(phasenam,unique=True)
    26582658            if oneblock:
    26592659                pass # temperature should be written when the histogram saved later
Note: See TracChangeset for help on using the changeset viewer.