Changeset 1028


Ignore:
Timestamp:
Aug 12, 2013 11:44:25 AM (8 years ago)
Author:
toby
Message:

print/export distances & angles

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r1017 r1028  
    6969    wxID_ATOMSMODIFY, wxID_ATOMSTRANSFORM, wxID_ATOMSVIEWADD, wxID_ATOMVIEWINSERT,
    7070    wxID_RELOADDRAWATOMS,wxID_ATOMSDISAGL,wxID_ATOMMOVE,
    71     wxID_ASSIGNATMS2RB
    72 ] = [wx.NewId() for item in range(12)]
     71    wxID_ASSIGNATMS2RB,wxID_ATOMSPDISAGL
     72] = [wx.NewId() for item in range(13)]
    7373
    7474[ wxID_DRAWATOMSTYLE, wxID_DRAWATOMLABEL, wxID_DRAWATOMCOLOR, wxID_DRAWATOMRESETCOLOR,
     
    19301930        self.ReImportMenuId[item.GetId()] = None # try all readers
    19311931
    1932         self.AtomCompute.Append(id=wxID_ATOMSDISAGL, kind=wx.ITEM_NORMAL,text='Distances && Angles',
     1932        self.AtomCompute.Append(id=wxID_ATOMSDISAGL, kind=wx.ITEM_NORMAL,text='Show Distances && Angles',
     1933            help='Compute distances & angles for selected atoms')
     1934        self.AtomCompute.Append(id=wxID_ATOMSPDISAGL, kind=wx.ITEM_NORMAL,text='Save Distances && Angles',
    19331935            help='Compute distances & angles for selected atoms')
    19341936        self.PostfillDataMenu()
  • trunk/GSASIIphsGUI.py

    r1022 r1028  
    2121
    2222'''
     23import os.path
    2324import wx
    2425import wx.grid as wg
     
    15511552                Atoms.ForceRefresh()
    15521553
    1553     def OnDistAngle(event):
     1554    def OnDistAnglePrt(event):
     1555        fp = file(os.path.abspath(os.path.splitext(G2frame.GSASprojectfile
     1556                                                   )[0]+'.disagl'),'w')
     1557        OnDistAngle(event,fp=fp)
     1558        fp.close()
     1559   
     1560    def OnDistAngle(event,fp=None):
    15541561        indx = Atoms.GetSelectedRows()
    15551562        Oxyz = []
     
    15871594                DisAglData['covData'] = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Covariance'))
    15881595            try:
    1589                 G2stMn.DistAngle(DisAglCtls,DisAglData)
     1596                if fp:
     1597                    G2stMn.PrintDistAngle(DisAglCtls,DisAglData,fp)
     1598                else:   
     1599                    G2stMn.PrintDistAngle(DisAglCtls,DisAglData)
    15901600            except KeyError:        # inside DistAngle for missing atom types in DisAglCtls
    15911601                print '**** ERROR - try again but do "Reset" to fill in missing atom types ****'
     
    49995009            G2frame.dataFrame.Bind(wx.EVT_MENU, OnReloadDrawAtoms, id=G2gd.wxID_RELOADDRAWATOMS)
    50005010            G2frame.dataFrame.Bind(wx.EVT_MENU, OnDistAngle, id=G2gd.wxID_ATOMSDISAGL)
     5011            G2frame.dataFrame.Bind(wx.EVT_MENU, OnDistAnglePrt, id=G2gd.wxID_ATOMSPDISAGL)
    50015012            for id in G2frame.dataFrame.ReImportMenuId:     #loop over submenu items
    50025013                G2frame.dataFrame.Bind(wx.EVT_MENU, OnReImport, id=id)               
  • trunk/GSASIIpwdGUI.py

    r1021 r1028  
    960960                topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,'  Ka1/Ka2:'),
    961961                        0,wx.ALIGN_CENTER_VERTICAL)
    962                 topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,'  %8.6f/%8.6f'%(insVal['Lam1'],insVal['Lam2'])),
     962                topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,u'  %8.6f/%8.6f\xc5'%(insVal['Lam1'],insVal['Lam2'])),
    963963                        0,wx.ALIGN_CENTER_VERTICAL)
    964964                waveSizer = wx.BoxSizer(wx.HORIZONTAL)
     
    981981               
    982982            else:
    983                 topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Lam: (%10.6f)'%(insDef['Lam'])),
     983                topSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,u' Lam (\xc5): (%10.6f)'%(insDef['Lam'])),
    984984                    0,wx.ALIGN_CENTER_VERTICAL)
    985985                waveVal = wx.TextCtrl(G2frame.dataDisplay,wx.ID_ANY,'%10.6f'%(insVal['Lam']),style=wx.TE_PROCESS_ENTER)
     
    10641064    else:                       #single crystal data
    10651065        if 'C' in insVal['Type']:               #constant wavelength
    1066             instSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,' Lam: (%10.6f)'%(insDef['Lam'])),
     1066            instSizer.Add(wx.StaticText(G2frame.dataDisplay,-1,u' Lam (\xc5): (%10.6f)'%(insDef['Lam'])),
    10671067                0,wx.ALIGN_CENTER_VERTICAL)
    10681068            waveVal = wx.TextCtrl(G2frame.dataDisplay,wx.ID_ANY,'%10.6f'%(insVal['Lam']),style=wx.TE_PROCESS_ENTER)
  • trunk/GSASIIstrMain.py

    r1016 r1028  
    386386    print ' ***** Sequential refinement successful *****'
    387387
    388 def DistAngle(DisAglCtls,DisAglData):
    389     'Needs a doc string'
     388def RetDistAngle(DisAglCtls,DisAglData):
     389    '''Compute and return distances and angles
     390
     391    :param dict DisAglCtls: contains distance/angle radii usually defined using
     392       :func:`GSASIIgrid.DisAglDialog`
     393    :param dict DisAglData: contains phase data:
     394       Items 'OrigAtoms' and 'TargAtoms' contain the atoms to be used
     395       for distance/angle origins and atoms to be used as targets.
     396       Item 'SGData' has the space group information (see :ref:`Space Group object<SGData_table>`)
     397
     398    :returns: AtomLabels,DistArray,AngArray where:
     399
     400      **AtomLabels** is a dict of atom labels, keys are the atom number
     401
     402      **DistArray** is a dict keyed by the origin atom number where the value is a list
     403      of distance entries. The value for each distance is a list containing:
     404     
     405        0) the target atom number (int);
     406        1) the unit cell offsets added to x,y & z (tuple of int values)
     407        2) the symmetry operator number (which may be modified to indicate centering and center of symmetry)
     408        3) an interatomic distance in A (float)
     409        4) an uncertainty on the distance in A or 0.0 (float)
     410
     411      **AngArray** is a dict keyed by the origin (central) atom number where
     412      the value is a list of
     413      angle entries. The value for each angle entry consists of three values:
     414
     415        0) a distance item reference for one neighbor (int)
     416        1) a distance item reference for a second neighbor (int)
     417        2) a angle, uncertainty pair; the s.u. may be zero (tuple of two floats)
     418
     419      The AngArray distance reference items refer directly to the index of the items in the
     420      DistArray item for the list of distances for the central atom.
     421    '''
    390422    import numpy.ma as ma
    391423   
    392     def ShowBanner(name):
    393         print 80*'*'
    394         print '   Interatomic Distances and Angles for phase '+name
    395         print 80*'*','\n'
    396 
    397     ShowBanner(DisAglCtls['Name'])
    398424    SGData = DisAglData['SGData']
    399     SGtext = G2spc.SGPrint(SGData)
    400     for line in SGtext: print line
    401425    Cell = DisAglData['Cell']
    402426   
     
    412436        names = [' a = ',' b = ',' c = ',' alpha = ',' beta = ',' gamma = ',' Volume = ']
    413437        valEsd = [G2mth.ValEsd(Cell[i],cellSig[i],True) for i in range(7)]
    414         line = '\n Unit cell:'
    415         for name,vals in zip(names,valEsd):
    416             line += name+vals 
    417         print line
    418     else:
    419         print '\n Unit cell: a = ','%.5f'%(Cell[0]),' b = ','%.5f'%(Cell[1]),' c = ','%.5f'%(Cell[2]), \
    420             ' alpha = ','%.3f'%(Cell[3]),' beta = ','%.3f'%(Cell[4]),' gamma = ', \
    421             '%.3f'%(Cell[5]),' volume = ','%.3f'%(Cell[6])
     438
    422439    Factor = DisAglCtls['Factors']
    423440    Radii = dict(zip(DisAglCtls['AtomTypes'],zip(DisAglCtls['BondRadii'],DisAglCtls['AngleRadii'])))
     
    426443    origAtoms = DisAglData['OrigAtoms']
    427444    targAtoms = DisAglData['TargAtoms']
     445    AtomLabels = {}
    428446    for Oatom in origAtoms:
     447        AtomLabels[Oatom[0]] = Oatom[1]
     448    for Oatom in targAtoms:
     449        AtomLabels[Oatom[0]] = Oatom[1]
     450    DistArray = {}
     451    AngArray = {}
     452    for Oatom in origAtoms:
     453        DistArray[Oatom[0]] = []
     454        AngArray[Oatom[0]] = []
    429455        OxyzNames = ''
    430456        IndBlist = []
     
    454480                                IndBlist.append(str(dx.T[indb][i]))
    455481                                unit = Units[indb][i]
    456                                 tunit = '[%2d%2d%2d]'%(unit[0]+Tunit[0],unit[1]+Tunit[1],unit[2]+Tunit[2])
     482                                tunit = (unit[0]+Tunit[0],unit[1]+Tunit[1],unit[2]+Tunit[2])
    457483                                pdpx = G2mth.getDistDerv(Oatom[3:6],Tatom[3:6],Amat,unit,Top,SGData)
    458484                                sig = 0.0
    459485                                if len(Xvcov):
    460486                                    sig = np.sqrt(np.inner(pdpx,np.inner(Xvcov,pdpx)))
    461                                 Dist.append([Oatom[1],Tatom[1],tunit,Top,ma.getdata(dist[indb])[i],sig])
     487                                Dist.append([Oatom[0],Tatom[0],tunit,Top,ma.getdata(dist[indb])[i],sig])
    462488                                if (Dist[-1][-2]-AsumR) <= 0.:
    463489                                    Vect.append(dx.T[indb][i]/Dist[-1][-2])
     
    466492                                    Vect.append([0.,0.,0.])
    467493                                    VectA.append([])
     494        for D in Dist:
     495            DistArray[Oatom[0]].append(D[1:])
    468496        Vect = np.array(Vect)
    469497        angles = np.zeros((len(Vect),len(Vect)))
     
    474502                    if np.any(vecb):
    475503                        angles[i][j],angsig[i][j] = G2mth.getAngSig(VectA[i],VectA[j],Amat,SGData,covData)
     504                        if i <= j: continue
     505                        AngArray[Oatom[0]].append((i,j,
     506                                                   G2mth.getAngSig(VectA[i],VectA[j],Amat,SGData,covData)
     507                                                   ))
     508    return AtomLabels,DistArray,AngArray
     509
     510def PrintDistAngle(DisAglCtls,DisAglData,out=sys.stdout):
     511    '''Print distances and angles
     512
     513    :param dict DisAglCtls: contains distance/angle radii usually defined using
     514       :func:`GSASIIgrid.DisAglDialog`
     515    :param dict DisAglData: contains phase data:
     516       Items 'OrigAtoms' and 'TargAtoms' contain the atoms to be used
     517       for distance/angle origins and atoms to be used as targets.
     518       Item 'SGData' has the space group information (see :ref:`Space Group object<SGData_table>`)
     519    :param file out: file object for output. Defaults to sys.stdout.   
     520    '''
     521    import numpy.ma as ma
     522    def MyPrint(s):
     523        out.write(s+'\n')
     524        # print(s,file=out) # use in Python 3
     525   
     526    def ShowBanner(name):
     527        MyPrint(80*'*')
     528        MyPrint('   Interatomic Distances and Angles for phase '+name)
     529        MyPrint((80*'*')+'\n')
     530
     531    ShowBanner(DisAglCtls['Name'])
     532    SGData = DisAglData['SGData']
     533    SGtext = G2spc.SGPrint(SGData)
     534    for line in SGtext: MyPrint(line)
     535    Cell = DisAglData['Cell']
     536   
     537    Amat,Bmat = G2lat.cell2AB(Cell[:6])
     538    covData = {}
     539    if 'covData' in DisAglData:   
     540        covData = DisAglData['covData']
     541        covMatrix = covData['covMatrix']
     542        varyList = covData['varyList']
     543        pfx = str(DisAglData['pId'])+'::'
     544        A = G2lat.cell2A(Cell[:6])
     545        cellSig = G2stIO.getCellEsd(pfx,SGData,A,covData)
     546        names = [' a = ',' b = ',' c = ',' alpha = ',' beta = ',' gamma = ',' Volume = ']
     547        valEsd = [G2mth.ValEsd(Cell[i],cellSig[i],True) for i in range(7)]
     548        line = '\n Unit cell:'
     549        for name,vals in zip(names,valEsd):
     550            line += name+vals 
     551        MyPrint(line)
     552    else:
     553        MyPrint('\n Unit cell: a = '+('%.5f'%Cell[0])+' b = '+('%.5f'%Cell[1])+' c = '+('%.5f'%Cell[2])+
     554            ' alpha = '+('%.3f'%Cell[3])+' beta = '+('%.3f'%Cell[4])+' gamma = '+
     555            ('%.3f'%Cell[5])+' volume = '+('%.3f'%Cell[6]))
     556
     557    AtomLabels,DistArray,AngArray = RetDistAngle(DisAglCtls,DisAglData)
     558    origAtoms = DisAglData['OrigAtoms']
     559    targAtoms = DisAglData['TargAtoms']
     560    for Oatom in origAtoms:
     561        i = Oatom[0]
     562        Dist = DistArray[i]
     563        nDist = len(Dist)
     564        angles = np.zeros((nDist,nDist))
     565        angsig = np.zeros((nDist,nDist))
     566        for k,j,tup in AngArray[i]:
     567            angles[k][j],angsig[k][j] = angles[j][k],angsig[j][k] = tup
    476568        line = ''
    477569        for i,x in enumerate(Oatom[3:6]):
    478             if len(Xvcov):
    479                 line += '%12s'%(G2mth.ValEsd(x,np.sqrt(Xvcov[i][i]),True))
    480             else:
    481                 line += '%12.5f'%(x)
    482         print '\n Distances & angles for ',Oatom[1],' at ',line
    483         print 80*'*'
     570            line += ('%12.5f'%x).rstrip('0')
     571        MyPrint('\n Distances & angles for '+Oatom[1]+' at '+line.rstrip())
     572        MyPrint(80*'*')
    484573        line = ''
    485574        for dist in Dist[:-1]:
    486             line += '%12s'%(dist[1].center(12))
    487         print '  To       cell +(sym. op.)      dist.  ',line
     575            line += '%12s'%(AtomLabels[dist[0]].center(12))
     576        MyPrint('  To       cell +(sym. op.)      dist.  '+line.rstrip())
    488577        for i,dist in enumerate(Dist):
    489578            line = ''
     
    498587                else:
    499588                    line += 12*' '
    500             if dist[5]:            #sig exists!
    501                 val = G2mth.ValEsd(dist[4],dist[5])
     589            if dist[4]:            #sig exists!
     590                val = G2mth.ValEsd(dist[3],dist[4])
    502591            else:
    503                 val = '%8.4f'%(dist[4])
    504             print '  %8s%10s+(%4d) %12s'%(dist[1].ljust(8),dist[2].ljust(10),dist[3],val.center(12)),line
     592                val = '%8.4f'%(dist[3])
     593            tunit = '[%2d%2d%2d]'% dist[1]
     594            MyPrint(('  %8s%10s+(%4d) %12s'%(AtomLabels[dist[0]].ljust(8),tunit.ljust(10),dist[2],val.center(12)))+line.rstrip())
    505595
    506596def DisAglTor(DATData):
Note: See TracChangeset for help on using the changeset viewer.