Changeset 3016


Ignore:
Timestamp:
Aug 18, 2017 12:12:42 PM (4 years ago)
Author:
odonnell
Message:

WIP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIscriptable.py

    r3015 r3016  
    10971097
    10981098        WARNING it does not check the constraint is well-constructed"""
    1099         constrs = self['Constraints']['data']
     1099        constrs = self.data['Constraints']['data']
    11001100        if 'Global' not in constrs:
    11011101            constrs['Global'] = []
     
    11391139            phaseObj = phase
    11401140            phase = G2obj.PhaseRanIdLookup[phase.ranId]
    1141         elif phase in self['Phases']:
     1141        elif phase in self.data['Phases']:
    11421142            phaseObj = self.phase(phase)
    11431143            phaseRanId = phaseObj.ranId
     
    12541254    @property
    12551255    def name(self):
    1256         return self['data'][-1]
     1256        return self.data['data'][-1]
    12571257
    12581258    @property
    12591259    def ranId(self):
    1260         return self['data'][0]['ranId']
     1260        return self.data['data'][0]['ranId']
    12611261
    12621262    @property
    12631263    def residuals(self):
    1264         data = self['data'][0]
     1264        data = self.data['data'][0]
    12651265        return {key: data[key]
    12661266                for key in ['R', 'Rb', 'wR', 'wRb', 'wRmin']}
    12671267
    1268     # TODO Figure out G2obj.HistRanIdLookup reload
    12691268    @property
    12701269    def id(self):
    1271         return G2obj.HistRanIdLookup[self.ranId]
     1270        return self.data['data'][0]['hId']
    12721271
    12731272    def fit_fixed_points(self):
     
    12911290            return dataType, instDict, insVary
    12921291
    1293         bgrnd = self['Background']
     1292        bgrnd = self.data['Background']
    12941293
    12951294        # Need our fixed points in order
     
    12981297        Y = [y for x, y in bgrnd[1]['FixedPoints']]
    12991298
    1300         limits = self['Limits'][1]
     1299        limits = self.data['Limits'][1]
    13011300        if X[0] > limits[0]:
    13021301            X = [limits[0]] + X
     
    13081307        # Some simple lookups
    13091308        controls = self.proj['Controls']['data']
    1310         inst, inst2 = self['Instrument Parameters']
    1311         pwddata = self['data'][1]
     1309        inst, inst2 = self.data['Instrument Parameters']
     1310        pwddata = self.data['data'][1]
    13121311
    13131312        # Construct the data for background fitting
     
    13421341
    13431342    def y_calc(self):
    1344         return self['data'][1][3]
     1343        return self.data['data'][1][3]
    13451344
    13461345    def plot(self, Yobs=True, Ycalc=True, Background=True, Residual=True):
    13471346        try:
    13481347            import matplotlib.pyplot as plt
    1349             data = self['data'][1]
     1348            data = self.data['data'][1]
    13501349            if Yobs:
    13511350                plt.plot(data[0], data[1], label='Yobs')
     
    14241423        if do_fit_fixed_points:
    14251424            # Background won't be fit if refinement flag not set
    1426             orig = self['Background'][0][1]
    1427             self['Background'][0][1] = True
     1425            orig = self.data['Background'][0][1]
     1426            self.data['Background'][0][1] = True
    14281427            self.fit_fixed_points()
    14291428            # Restore the previous value
    1430             self['Background'][0][1] = orig
     1429            self.data['Background'][0][1] = orig
    14311430
    14321431    def clear_refinements(self, refs):
     
    15271526    @property
    15281527    def id(self):
    1529         return G2obj.PhaseRanIdLookup[self.ranId]
     1528        return self.data['pId']
    15301529
    15311530    def get_cell(self):
     
    15331532            'length_a', 'length_b', 'length_c', 'angle_alpha', 'angle_beta', 'angle_gamma', 'volume'
    15341533
    1535         :returns: a dict"""
    1536         cell = self['General']['Cell']
     1534        :returns: a dict
     1535
     1536        .. seealso::
     1537           :func:`~G2Phase.get_cell_and_esd`
     1538        """
     1539        cell = self.data['General']['Cell']
    15371540        return {'length_a': cell[1], 'length_b': cell[2], 'length_c': cell[3],
    15381541                'angle_alpha': cell[4], 'angle_beta': cell[5], 'angle_gamma': cell[6],
    15391542                'volume': cell[7]}
     1543
     1544    def get_cell_and_esd(self):
     1545        """
     1546        Returns a pair of dictionaries, the first representing the unit cell, the second
     1547        representing the estimated standard deviations of the unit cell.
     1548
     1549        :returns: a tuple of two dictionaries
     1550        .. seealso::
     1551           :func:`~G2Phase.get_cell`
     1552        """
     1553        # translated from GSASIIstrIO.ExportBaseclass.GetCell
     1554        import GSASIIstrIO as G2stIO
     1555        import GSASIIlattice as G2lat
     1556        import GSASIImapvars as G2mv
     1557        try:
     1558            pfx = str(self.id) + '::'
     1559            sgdata = self['General']['SGData']
     1560            covDict = self.proj['Covariance']['data']
     1561
     1562            parmDict = dict(zip(covDict.get('varyList',[]),
     1563                                covDict.get('variables',[])))
     1564            sigDict = dict(zip(covDict.get('varyList',[]),
     1565                               covDict.get('sig',[])))
     1566
     1567            if covDict.get('covMatrix') is not None:
     1568                sigDict.update(G2mv.ComputeDepESD(covDict['covMatrix'],
     1569                                                  covDict['varyList'],
     1570                                                  parmDict))
     1571
     1572            A, sigA = G2stIO.cellFill(pfx, sgdata, parmDict, sigDict)
     1573            cellSig = G2stIO.getCellEsd(pfx, sgdata, A, self.proj['Covariance']['data'])
     1574            cellList = G2lat.A2cell(A) + (G2lat.calc_V(A),)
     1575            cellDict, cellSigDict = {}, {}
     1576            for i, key in enumerate(['length_a', 'length_b', 'length_c',
     1577                                     'angle_alpha', 'angle_beta', 'angle_gamma',
     1578                                     'volume']):
     1579                cellDict[key] = cellList[i]
     1580                cellSigDict[key] = cellSig[i]
     1581            return cellDict, cellSigDict
     1582        except KeyError:
     1583            cell = self.get_cell()
     1584            return cell, {key: 0.0 for key in cell}
    15401585
    15411586    def export_CIF(self, outputname, quickmode=True):
     
    15561601                           for c in CIFname.replace(' ', '_')])
    15571602        try:
    1558             author = self.proj['Controls'].get('Author','').strip()
     1603            author = self.proj['Controls']['data'].get('Author','').strip()
    15591604        except KeyError:
    15601605            pass
    15611606        oneblock = True
    15621607
    1563         covDict = self.proj['Covariance']
     1608        covDict = self.proj['Covariance']['data']
    15641609        parmDict = dict(zip(covDict.get('varyList',[]),
    15651610                            covDict.get('variables',[])))
     
    15881633
    15891634            cif.WriteCIFitem(fp, '_symmetry_cell_setting',
    1590                          self['General']['SGData']['SGSys'])
    1591 
    1592             spacegroup = self['General']['SGData']['SpGrp'].strip()
     1635                         self.data['General']['SGData']['SGSys'])
     1636
     1637            spacegroup = self.data['General']['SGData']['SpGrp'].strip()
    15931638            # regularize capitalization and remove trailing H/R
    15941639            spacegroup = spacegroup[0].upper() + spacegroup[1:].lower().rstrip('rh ')
     
    15971642            # generate symmetry operations including centering and center of symmetry
    15981643            SymOpList, offsetList, symOpList, G2oprList, G2opcodes = G2spc.AllOps(
    1599                 self['General']['SGData'])
     1644                self.data['General']['SGData'])
    16001645            cif.WriteCIFitem(fp, 'loop_\n    _space_group_symop_id\n    _space_group_symop_operation_xyz')
    16011646            for i, op in enumerate(SymOpList,start=1):
     
    16051650
    16061651            # report atom params
    1607             if self['General']['Type'] in ['nuclear','macromolecular']:        #this needs macromolecular variant, etc!
     1652            if self.data['General']['Type'] in ['nuclear','macromolecular']:        #this needs macromolecular variant, etc!
    16081653                cif.WriteAtomsNuclear(fp, self.data, self.name, parmDict, sigDict, [])
    16091654                # self._WriteAtomsNuclear(fp, parmDict, sigDict)
    16101655            else:
    1611                 raise Exception,"no export for "+str(self['General']['Type'])+" coordinates implemented"
     1656                raise Exception,"no export for "+str(self.data['General']['Type'])+" coordinates implemented"
    16121657            # report cell contents
    16131658            cif.WriteComposition(fp, self.data, self.name, parmDict)
    1614             if not quickmode and self['General']['Type'] == 'nuclear':      # report distances and angles
     1659            if not quickmode and self.data['General']['Type'] == 'nuclear':      # report distances and angles
    16151660                # WriteDistances(fp,self.name,SymOpList,offsetList,symOpList,G2oprList)
    16161661                raise NotImplementedError("only quickmode currently supported")
    1617             if 'Map' in self['General'] and 'minmax' in self['General']['Map']:
     1662            if 'Map' in self.data['General'] and 'minmax' in self.data['General']['Map']:
    16181663                cif.WriteCIFitem(fp,'\n# Difference density results')
    1619                 MinMax = self['General']['Map']['minmax']
     1664                MinMax = self.data['General']['Map']['minmax']
    16201665                cif.WriteCIFitem(fp,'_refine_diff_density_max',G2mth.ValEsd(MinMax[0],-0.009))
    16211666                cif.WriteCIFitem(fp,'_refine_diff_density_min',G2mth.ValEsd(MinMax[1],-0.009))
     
    16851730        """
    16861731        if histograms == 'all':
    1687             histograms = self['Histograms'].values()
     1732            histograms = self.data['Histograms'].values()
    16881733        else:
    1689             histograms = [self['Histograms'][h.name] for h in histograms]
     1734            histograms = [self.data['Histograms'][h.name] for h in histograms]
    16901735
    16911736        for key, val in refs.items():
     
    17611806        """
    17621807        if histograms == 'all':
    1763             histograms = self['Histograms'].values()
     1808            histograms = self.data['Histograms'].values()
    17641809        else:
    1765             histograms = [self['Histograms'][h.name] for h in histograms]
     1810            histograms = [self.data['Histograms'][h.name] for h in histograms]
    17661811
    17671812        for key, val in refs.items():
Note: See TracChangeset for help on using the changeset viewer.