Changeset 989


Ignore:
Timestamp:
Jul 13, 2013 10:21:12 PM (10 years ago)
Author:
toby
Message:

add constraint derivs for single xtal; allow cellFill to work without esds; update docs; fix controls copy bug

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimgGUI.py

    r923 r989  
    182182                            Data['range'] = oldData['range']
    183183                            Data['size'] = oldData['size']
    184                             Data['GonioAngles'] = oldData['GonioAngles']
     184                            Data['GonioAngles'] = oldData.get('GonioAngles', [0.,0.,0.])
    185185                            Data['ring'] = []
    186186                            Data['rings'] = []
  • trunk/GSASIIlattice.py

    r961 r989  
    44---------------------------
    55
    6 Perform lattice-related computations'''
     6Perform lattice-related computations
     7
     8Note that *g* is the reciprocal lattice tensor, and *G* is its inverse,
     9:math:`G = g^{-1}`, where
     10
     11  .. math::
     12
     13   G = \\left( \\begin{matrix}
     14   a^2 & a b\\cos\gamma & a c\\cos\\beta \\\\
     15   a b\\cos\\gamma & b^2 & b c \cos\\alpha \\\\
     16   a c\\cos\\beta &  b c \\cos\\alpha & c^2
     17   \\end{matrix}\\right)
     18
     19The "*A* tensor" terms are defined as
     20:math:`A = (\\begin{matrix} G_{11} & G_{22} & G_{33} & 2G_{12} & 2G_{13} & 2G_{23}\\end{matrix})` and *A* can be used in this fashion:
     21:math:`d^* = \sqrt {A_1 h^2 + A_2 k^2 + A_3 l^2 + A_4 hk + A_5 hl + A_6 kl}`, where
     22*d* is the d-spacing, and :math:`d^*` is the reciprocal lattice spacing,
     23:math:`Q = 2 \\pi d^* = 2 \\pi / d`
     24'''
    725########### SVN repository information ###################
    826# $Date$
     
    90108
    91109def A2Gmat(A,inverse=True):
    92     """Fill real & reciprocal metric tensor (G) from A
     110    """Fill real & reciprocal metric tensor (G) from A.
    93111
    94112    :param A: reciprocal metric tensor elements as [G11,G22,G33,2*G12,2*G13,2*G23]
  • trunk/GSASIImapvars.py

    r903 r989  
    906906      parameter names.
    907907
    908     :param dict dMdv: a dict containing derivatives for dependent parameter computed from
    909       derivDict
     908    :param list dMdv: a Jacobian, as a list of np.array containing derivatives for dependent
     909      parameter computed from derivDict
    910910
    911911    '''
  • trunk/GSASIImath.py

    r984 r989  
    12711271    '''
    12721272    # Note: this routine is Python 3 compatible -- I think
    1273     if esd != 0:
     1273    if math.isnan(value): # invalid value, bail out
     1274        return '?'
     1275    if math.isnan(esd): # invalid esd, treat as zero
     1276        esd = 0
     1277        esdoff = 5
     1278    elif esd != 0:
    12741279        # transform the esd to a one or two digit integer
    12751280        l = math.log10(abs(esd)) % 1
     
    13001305        extra = -math.log10(abs(value))
    13011306        if extra > 0: extra += 1
    1302         print 'fmt=',"{:."+str(max(0,esdoff+int(extra)))+"f}"
    13031307        out = ("{:."+str(max(0,esdoff+int(extra)))+"f}").format(value) # format the value
    13041308    if esd > 0:
  • trunk/GSASIIpath.py

    r981 r989  
    8181
    8282    :returns: None if svn is not found or an absolute path to the subversion
    83     executable file .
     83      executable file.
    8484    '''
    8585    def is_exe(fpath):
     
    196196    '''This performs an update of the files in a local directory from a server.
    197197
    198     :param fpath: path to repository dictionary, defaults to directory where
     198    :param str fpath: path to repository dictionary, defaults to directory where
    199199       the current file is located
    200 
     200    :param version: the number of the version to be loaded. Used only
     201       cast as a string, but should be an integer or something that corresponds to a
     202       string representation of an integer value when cast. A value of None (default)
     203       causes the latest version on the server to be used.
    201204    :returns: A dictionary with the files that have been changed/added and
    202           a code describing how they have been updated (see changetype) ro
     205          a code describing how they have been updated (see changetype) or
    203206          None if there is a subversion error (likely because the path is
    204207          not a repository or svn is not found)
    205 
    206208    '''
    207209    import subprocess
  • trunk/GSASIIstrIO.py

    r981 r989  
    10191019   
    10201020def cellFill(pfx,SGData,parmDict,sigDict):
    1021     'needs a doc string'
     1021    '''Returns the filled-out reciprocal cell (A) terms and their uncertainties
     1022    from the parameter and sig dictionaries.
     1023
     1024    :param str pfx: parameter prefix ("n::", where n is a phase number)
     1025    :param dict SGdata: a symmetry object
     1026    :param dict parmDict: a dictionary of parameters
     1027    :param dict sigDict:  a dictionary of uncertainties on parameters
     1028
     1029    :returns: A,sigA where each is a list of six terms with the A terms
     1030    '''
    10221031    if SGData['SGLaue'] in ['-1',]:
    10231032        A = [parmDict[pfx+'A0'],parmDict[pfx+'A1'],parmDict[pfx+'A2'],
    10241033            parmDict[pfx+'A3'],parmDict[pfx+'A4'],parmDict[pfx+'A5']]
    1025         sigA = [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],
    1026             sigDict[pfx+'A3'],sigDict[pfx+'A4'],sigDict[pfx+'A5']]
    10271034    elif SGData['SGLaue'] in ['2/m',]:
    10281035        if SGData['SGUniq'] == 'a':
    10291036            A = [parmDict[pfx+'A0'],parmDict[pfx+'A1'],parmDict[pfx+'A2'],
    10301037                parmDict[pfx+'A3'],0,0]
    1031             sigA = [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],
    1032                 sigDict[pfx+'A3'],0,0]
    10331038        elif SGData['SGUniq'] == 'b':
    10341039            A = [parmDict[pfx+'A0'],parmDict[pfx+'A1'],parmDict[pfx+'A2'],
    10351040                0,parmDict[pfx+'A4'],0]
    1036             sigA = [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],
    1037                 0,sigDict[pfx+'A4'],0]
    10381041        else:
    10391042            A = [parmDict[pfx+'A0'],parmDict[pfx+'A1'],parmDict[pfx+'A2'],
    10401043                0,0,parmDict[pfx+'A5']]
    1041             sigA = [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],
    1042                 0,0,sigDict[pfx+'A5']]
    10431044    elif SGData['SGLaue'] in ['mmm',]:
    10441045        A = [parmDict[pfx+'A0'],parmDict[pfx+'A1'],parmDict[pfx+'A2'],0,0,0]
    1045         sigA = [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],0,0,0]
    10461046    elif SGData['SGLaue'] in ['4/m','4/mmm']:
    10471047        A = [parmDict[pfx+'A0'],parmDict[pfx+'A0'],parmDict[pfx+'A2'],0,0,0]
    1048         sigA = [sigDict[pfx+'A0'],0,sigDict[pfx+'A2'],0,0,0]
    10491048    elif SGData['SGLaue'] in ['6/m','6/mmm','3m1', '31m', '3']:
    10501049        A = [parmDict[pfx+'A0'],parmDict[pfx+'A0'],parmDict[pfx+'A2'],
    10511050            parmDict[pfx+'A0'],0,0]
    1052         sigA = [sigDict[pfx+'A0'],0,sigDict[pfx+'A2'],0,0,0]
    10531051    elif SGData['SGLaue'] in ['3R', '3mR']:
    10541052        A = [parmDict[pfx+'A0'],parmDict[pfx+'A0'],parmDict[pfx+'A0'],
    10551053            parmDict[pfx+'A3'],parmDict[pfx+'A3'],parmDict[pfx+'A3']]
    1056         sigA = [sigDict[pfx+'A0'],0,0,sigDict[pfx+'A3'],0,0]
    10571054    elif SGData['SGLaue'] in ['m3m','m3']:
    10581055        A = [parmDict[pfx+'A0'],parmDict[pfx+'A0'],parmDict[pfx+'A0'],0,0,0]
    1059         sigA = [sigDict[pfx+'A0'],0,0,0,0,0]
     1056
     1057    try:
     1058        if SGData['SGLaue'] in ['-1',]:
     1059            sigA = [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],
     1060                sigDict[pfx+'A3'],sigDict[pfx+'A4'],sigDict[pfx+'A5']]
     1061        elif SGData['SGLaue'] in ['2/m',]:
     1062            if SGData['SGUniq'] == 'a':
     1063                sigA = [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],
     1064                    sigDict[pfx+'A3'],0,0]
     1065            elif SGData['SGUniq'] == 'b':
     1066                sigA = [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],
     1067                    0,sigDict[pfx+'A4'],0]
     1068            else:
     1069                sigA = [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],
     1070                    0,0,sigDict[pfx+'A5']]
     1071        elif SGData['SGLaue'] in ['mmm',]:
     1072            sigA = [sigDict[pfx+'A0'],sigDict[pfx+'A1'],sigDict[pfx+'A2'],0,0,0]
     1073        elif SGData['SGLaue'] in ['4/m','4/mmm']:
     1074            sigA = [sigDict[pfx+'A0'],0,sigDict[pfx+'A2'],0,0,0]
     1075        elif SGData['SGLaue'] in ['6/m','6/mmm','3m1', '31m', '3']:
     1076            sigA = [sigDict[pfx+'A0'],0,sigDict[pfx+'A2'],0,0,0]
     1077        elif SGData['SGLaue'] in ['3R', '3mR']:
     1078            sigA = [sigDict[pfx+'A0'],0,0,sigDict[pfx+'A3'],0,0]
     1079        elif SGData['SGLaue'] in ['m3m','m3']:
     1080            sigA = [sigDict[pfx+'A0'],0,0,0,0,0]
     1081    except KeyError:
     1082        sigA = [0,0,0,0,0,0]
     1083
    10601084    return A,sigA
    10611085       
  • trunk/GSASIIstrMath.py

    r961 r989  
    16231623            ApplyRBModelDervs(dFdvDict,parmDict,rigidbodyDict,Phase)
    16241624            dMdvh = np.zeros((len(varylist),len(refList)))
     1625            dependentVars = G2mv.GetDependentVars()
     1626            depDerivDict = {}
     1627            for j in dependentVars:
     1628                depDerivDict[j] = np.zeros(shape=(len(refList)))
    16251629            if calcControls['F**2']:
    16261630                for iref,ref in enumerate(refList):
     
    16321636                                if var in dFdvDict:
    16331637                                    dMdvh[j][iref] = w*dFdvDict[var][iref]*parmDict[phfx+'Scale']*dervCor
     1638                            for var in dependentVars:
     1639                                if var in dFdvDict:
     1640                                    depDerivDict[var][iref] = w*dFdvDict[var][iref]*parmDict[phfx+'Scale']*dervCor
    16341641                            if phfx+'Scale' in varylist:
    16351642                                dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor
     1643                            elif phfx+'Scale' in dependentVars:
     1644                                depDerivDict[phfx+'Scale'][iref] = w*ref[9]*dervCor
    16361645                            for item in ['Ep','Es','Eg']:
    16371646                                if phfx+item in varylist:
    16381647                                    dMdvh[varylist.index(phfx+item)][iref] = w*dervDict[phfx+item]*parmDict[phfx+'Scale']
     1648                                elif phfx+item in dependentVars:
     1649                                    depDerivDict[phfx+item][iref] = w*dervDict[phfx+item]*parmDict[phfx+'Scale']
    16391650                            for item in ['BabA','BabU']:
    16401651                                if phfx+item in varylist:
    16411652                                    dMdvh[varylist.index(phfx+item)][iref] = w*dervCor*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']
     1653                                elif phfx+item in dependentVars:
     1654                                    depDerivDict[phfx+item][iref] = w*dervCor*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']
    16421655            else:
    16431656                for iref,ref in enumerate(refList):
     
    16511664                                if var in dFdvDict:
    16521665                                    dMdvh[j][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale']
     1666                            for var in dependentVars:
     1667                                if var in dFdvDict:
     1668                                    depDerivDict[var][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale']
    16531669                            if phfx+'Scale' in varylist:
    1654                                 dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor                           
     1670                                dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor
     1671                            elif phfx+'Scale' in dependentVars:
     1672                                depDerivDict[phfx+'Scale'][iref] = w*ref[9]*dervCor                           
    16551673                            for item in ['Ep','Es','Eg']:
    16561674                                if phfx+item in varylist:
    16571675                                    dMdvh[varylist.index(phfx+item)][iref] = w*dervDict[phfx+item]*parmDict[phfx+'Scale']
     1676                                elif phfx+item in dependentVars:
     1677                                    depDerivDict[phfx+item][iref] = w*dervDict[phfx+item]*parmDict[phfx+'Scale']
    16581678                            for item in ['BabA','BabU']:
    16591679                                if phfx+item in varylist:
    16601680                                    dMdvh[varylist.index(phfx+item)][iref] = w*dervCor*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']
     1681                                elif phfx+item in dependentVars:
     1682                                    depDerivDict[phfx+item][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor
     1683            # now process derivatives in constraints
     1684            G2mv.Dict2Deriv(varylist,depDerivDict,dMdvh)
    16611685        else:
    16621686            continue        #skip non-histogram entries
     
    17281752            ApplyRBModelDervs(dFdvDict,parmDict,rigidbodyDict,Phase)
    17291753            dMdvh = np.zeros((len(varylist),len(refList)))
     1754            dependentVars = G2mv.GetDependentVars()
     1755            depDerivDict = {}
     1756            for j in dependentVars:
     1757                depDerivDict[j] = np.zeros(shape=(len(refList)))
    17301758            wdf = np.zeros(len(refList))
    17311759            if calcControls['F**2']:
     
    17391767                                if var in dFdvDict:
    17401768                                    dMdvh[j][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale']
     1769                            for var in dependentVars:
     1770                                if var in dFdvDict:
     1771                                    depDerivDict[var][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale']
    17411772                            if phfx+'Scale' in varylist:
    17421773                                dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor
     1774                            elif phfx+'Scale' in dependentVars:
     1775                                depDerivDict[phfx+'Scale'][iref] = w*ref[9]*dervCor
    17431776                            for item in ['Ep','Es','Eg']:
    17441777                                if phfx+item in varylist:
    17451778                                    dMdvh[varylist.index(phfx+item)][iref] = w*dervDict[phfx+item]*parmDict[phfx+'Scale']
     1779                                elif phfx+item in dependentVars:
     1780                                    depDerivDict[phfx+item][iref] = w*dervDict[phfx+item]*parmDict[phfx+'Scale']
    17461781                            for item in ['BabA','BabU']:
    17471782                                if phfx+item in varylist:
    17481783                                    dMdvh[varylist.index(phfx+item)][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor
     1784                                elif phfx+item in dependentVars:
     1785                                    depDerivDict[phfx+item][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor
    17491786            else:
    17501787                for iref,ref in enumerate(refList):
     
    17591796                                if var in dFdvDict:
    17601797                                    dMdvh[j][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale']
     1798                            for var in dependentVars:
     1799                                if var in dFdvDict:
     1800                                    depDerivDict[var][iref] = w*dFdvDict[var][iref]*dervCor*parmDict[phfx+'Scale']
    17611801                            if phfx+'Scale' in varylist:
    1762                                 dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor                           
     1802                                dMdvh[varylist.index(phfx+'Scale')][iref] = w*ref[9]*dervCor
     1803                            elif phfx+'Scale' in dependentVars:
     1804                                depDerivDict[phfx+'Scale'][iref] = w*ref[9]*dervCor                           
    17631805                            for item in ['Ep','Es','Eg']:
    17641806                                if phfx+item in varylist:
    17651807                                    dMdvh[varylist.index(phfx+item)][iref] = w*dervDict[phfx+item]*parmDict[phfx+'Scale']
     1808                                elif phfx+item in dependentVars:
     1809                                    depDerivDict[phfx+item][iref] = w*dervDict[phfx+item]*parmDict[phfx+'Scale']
    17661810                            for item in ['BabA','BabU']:
    17671811                                if phfx+item in varylist:
    17681812                                    dMdvh[varylist.index(phfx+item)][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor
    1769                        
     1813                                elif phfx+item in dependentVars:
     1814                                    depDerivDict[phfx+item][iref] = w*dFdvDict[pfx+item][iref]*parmDict[phfx+'Scale']*dervCor
     1815            # now process derivatives in constraints
     1816            G2mv.Dict2Deriv(varylist,depDerivDict,dMdvh)
     1817
    17701818            if dlg:
    17711819                dlg.Update(Histogram['wR'],newmsg='Hessian for histogram %d Rw=%8.3f%s'%(hId,Histogram['wR'],'%'))[0]
  • trunk/exports/G2cif.py

    r981 r989  
    99import GSASIIgrid as G2gd
    1010import GSASIIstrIO as G2stIO
     11#reload(G2stIO)
    1112#import GSASIImapvars as G2mv
    1213import GSASIImath as G2mth
     14reload(G2mth)
    1315import GSASIIlattice as G2lat
    1416import GSASIIspc as G2spg
    1517#reload(G2spg)
    16 reload(G2mth)
    1718
    1819def getCallerDocString(): # for development
     
    585586            refprx = '_refln_' # normal
    586587
    587             print histblk.keys()
    588             #            for key in histblk:
    589             #                print key
    590             print inst
    591             print self.parmDict.keys()
    592             print self.sigDict.keys()
    593588            WriteCIFitem('\n# SCATTERING FACTOR INFO')
    594589            if 'Lam1' in inst:
     
    618613                WriteCIFitem('_diffrn_radiation_wavelength',G2mth.ValEsd(lam1,slam1))
    619614
    620             raise Exception, "testing"
    621615
    622616            if not oneblock:
     
    629623                                 '\n\t_pd_phase_block_id' +
    630624                                 '\n\t_pd_phase_mass_%')
     625                    wtFrSum = 0.
    631626                    for phasenam in phasebyhistDict.get(histlbl):
    632                         pass
    633 
    634             WriteCIFitem('_pd_proc_ls_prof_R_factor','?')
    635             WriteCIFitem('_pd_proc_ls_prof_wR_factor','?')
    636             WriteCIFitem('_pd_proc_ls_prof_wR_expected','?')
    637             WriteCIFitem('_refine_ls_R_Fsqd_factor','?')
     627                        hapData = self.Phases[phasenam]['Histograms'][histlbl]
     628                        General = self.Phases[phasenam]['General']
     629                        wtFrSum += hapData['Scale'][0]*General['Mass']
     630
     631                    for phasenam in phasebyhistDict.get(histlbl):
     632                        hapData = self.Phases[phasenam]['Histograms'][histlbl]
     633                        General = self.Phases[phasenam]['General']
     634                        wtFr = hapData['Scale'][0]*General['Mass']/wtFrSum
     635                        pfx = str(self.Phases[phasenam]['pId'])+':'+str(hId)+':'
     636                        if pfx+'Scale' in self.sigDict:
     637                            sig = self.sigDict[pfx+'Scale']*wtFr/hapData['Scale'][0]
     638                        else:
     639                            sig = -0.0001
     640                        WriteCIFitem(
     641                            '  '+
     642                            str(self.Phases[phasenam]['pId']) +
     643                            '  '+datablockidDict[phasenam]+
     644                            '  '+G2mth.ValEsd(wtFr,sig)
     645                            )
     646
     647            # this will need help from Bob
     648            # WriteCIFitem('_pd_proc_ls_prof_R_factor','?')
     649            # WriteCIFitem('_pd_proc_ls_prof_wR_factor','?')
     650            # WriteCIFitem('_pd_proc_ls_prof_wR_expected','?')
     651            # WriteCIFitem('_refine_ls_R_Fsqd_factor','?')
     652
     653            phasenam = self.Phases.keys()[0]
     654            for key in self.Phases[phasenam]['Histograms']:
     655                print key
     656                print '------------'
     657                print self.Phases[phasenam]['Histograms'][key]
     658            raise Exception, "testing"
     659            print histblk.keys()
     660            for key in histblk:
     661                print key,histblk[key]
     662            print inst
     663            #print self.parmDict.keys()
     664            #print self.sigDict.keys()
    638665           
    639666            #WriteCIFitem('_pd_meas_2theta_fixed',text)
     
    10501077                    WriteCIFitem('_pd_block_id',datablockidDict[hist])
    10511078                    WritePowderTemplate()
    1052                     WritePowderData(key1)
     1079                    WritePowderData(hist)
    10531080                elif hist.startswith("HKLF"):
    10541081                    WriteCIFitem('\ndata_'+self.CIFname+"_sx_"+str(i))
     
    10581085                    WriteCIFitem('_pd_block_id',datablockidDict[hist])
    10591086                    WriteSnglXtalTemplate()
    1060                     WriteSingleXtalData(key1)
     1087                    WriteSingleXtalData(hist)
    10611088
    10621089        WriteCIFitem('#--' + 15*'eof--' + '#')
Note: See TracChangeset for help on using the changeset viewer.