Changeset 4451


Ignore:
Timestamp:
Jun 1, 2020 12:40:11 PM (16 months ago)
Author:
vondreele
Message:

Add Histogram distances & angles to Phase/Atom/Compute? menu
fix getAtomSelections for macromolecules & add getAtomPtrs

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIphsGUI.py

    r4450 r4451  
    10961096#### Phase editing routines
    10971097################################################################################
    1098 def getAtomSelections(AtmTbl,action='action'):
    1099     '''get selected atoms from table or ask user if none are selected'''
     1098def getAtomSelections(AtmTbl,cn=0,action='action'):
     1099    '''get selected atoms from table or ask user if none are selected
     1100   
     1101        param: AtmTbl list atom or draw atom table
     1102        param: int cn atom name position
     1103        action: str description
     1104        returns: list indx selected atoms fr tom indices in table
     1105    '''
    11001106    indx = AtmTbl.GetSelectedRows()
    11011107    indx += [row for row,col in AtmTbl.GetSelectedCells()]
     
    11071113    choices = []
    11081114    for i in range(AtmTbl.GetNumberRows()):
    1109         val = AtmTbl.GetCellValue(i,0)
     1115        val = AtmTbl.GetCellValue(i,cn)
    11101116        if val in choices:
    11111117            val += '_' + str(i)
     
    11181124    dlg.Destroy()
    11191125    return indx
     1126
     1127def getAtomPtrs(data,draw=False):
     1128    ''' get atom data pointers cx,ct,cs,cia in Atoms or Draw Atoms lists
     1129    NB:may not match column numbers in displayed table
     1130   
     1131        param: dict: data phase data structure
     1132        draw: boolean True if Draw Atoms list pointers are required
     1133        return: cx,ct,cs,cia pointers to atom xyz, type, site sym, uiso/aniso flag
     1134    '''
     1135    if draw:
     1136        return data['Drawing']['atomPtrs']
     1137    else:
     1138        return data['General']['AtomPtrs']
    11201139
    11211140def SetPhaseWindow(phasePage,mainSizer=None,Scroll=0):
     
    35323551        '''Inserts a new atom into list immediately before every selected atom
    35333552        '''
    3534         indx = getAtomSelections(Atoms)
     3553        cx,ct,cs,ci = getAtomPtrs(data)     
     3554        indx = getAtomSelections(Atoms,ct-1)
    35353555        for a in reversed(sorted(indx)):
    35363556            AtomInsert(a,0.,0.,0.)
     
    35523572        '''Adds H atoms to fill out coordination sphere for selected atoms
    35533573        '''
    3554         indx = getAtomSelections(Atoms)
     3574        cx,ct,cs,ci = getAtomPtrs(data)     
     3575        indx = getAtomSelections(Atoms,ct-1)
    35553576        if not indx: return
    35563577        DisAglCtls = {}
     
    35703591        dlg.Destroy()
    35713592        generalData['DisAglCtls'] = DisAglCtls
    3572         cx,ct,cs,cia = generalData['AtomPtrs']
    35733593        atomData = data['Atoms']
    35743594        AtNames = [atom[ct-1] for atom in atomData]
     
    36753695       
    36763696    def OnAtomMove(event):
     3697        cx,ct,cs,ci = getAtomPtrs(data)     
     3698        indx = getAtomSelections(Atoms,ct-1)
    36773699        drawData = data['Drawing']
    36783700        atomData = data['Atoms']
     
    36813703        cx = colLabels.index('x')
    36823704        ci = colLabels.index('I/A')
    3683         indx = getAtomSelections(Atoms)
    36843705        if len(indx) != 1:
    36853706            G2frame.ErrorDialog('Atom move error','Only one atom can be moved')
     
    37773798
    37783799    def AtomDelete(event):
     3800        cx,ct,cs,ci = getAtomPtrs(data,ct-1)     
     3801        indx = getAtomSelections(Atoms)
    37793802        colLabels = [Atoms.GetColLabelValue(c) for c in range(Atoms.GetNumberCols())]
    37803803        HydIds = data['General']['HydIds']
    37813804        ci = colLabels.index('I/A')
    3782         indx = getAtomSelections(Atoms)
    37833805        IDs = []
    37843806        if not indx: return
     
    38083830       
    38093831    def AtomRefine(event):
     3832        cx,ct,cs,ci = getAtomPtrs(data)     
     3833        indx = getAtomSelections(Atoms,ct-1)
     3834        if not indx: return
    38103835        colLabels = [Atoms.GetColLabelValue(c) for c in range(Atoms.GetNumberCols())]
    38113836        c = colLabels.index('refine')
    3812         indx = getAtomSelections(Atoms)
    3813         if not indx: return
    38143837        atomData = data['Atoms']
    38153838        generalData = data['General']
     
    38323855
    38333856    def AtomModify(event):
    3834         indx = getAtomSelections(Atoms)
     3857        cx,ct,cs,ci = getAtomPtrs(data)     
     3858        indx = getAtomSelections(Atoms,ct-1)
    38353859        if not indx: return
    38363860        atomData = data['Atoms']
     
    39423966
    39433967    def AtomTransform(event):
    3944         indx = getAtomSelections(Atoms)
     3968        cx,ct,cs,ci = getAtomPtrs(data)     
     3969        indx = getAtomSelections(Atoms,ct-1)
    39453970        if not indx: return
    39463971        generalData = data['General']
     
    40114036#            'yz':np.array([[0,i,j] for i in range(3) for j in range(3)])-np.array([1,1,0]),
    40124037#            'xyz':np.array([[i,j,k] for i in range(3) for j in range(3) for k in range(3)])-np.array([1,1,1])}
    4013 #        indx = getAtomSelections(Atoms)
     4038#        cx,ct,cs,ci = getAtomPtrs(data)     
     4039#        indx = getAtomSelections(Atoms,ct-1)
    40144040#        if indx:
    40154041#            generalData = data['General']
     
    40554081               
    40564082    def MakeMolecule(event):     
    4057         indx = getAtomSelections(Atoms)
     4083        cx,ct,cs,ci = getAtomPtrs(data)     
     4084        indx = getAtomSelections(Atoms,ct-1)
    40584085        DisAglCtls = {}
    40594086        if indx is not None and len(indx) == 1:
     
    41074134    def OnDistAngle(event,fp=None,hist=False):
    41084135        'Compute distances and angles'   
    4109         indx = getAtomSelections(Atoms)
     4136        cx,ct,cs,ci = getAtomPtrs(data)     
     4137        indx = getAtomSelections(Atoms,ct-1)
    41104138        Oxyz = []
    41114139        xyz = []
     
    41484176            try:
    41494177                if hist:
    4150                     AtomLabels,DistArray,AngArray = G2stMn.RetDistAngle(DisAglCtls,DisAglData)
     4178                    pgbar = wx.ProgressDialog('Distance Angle calculation','Atoms done=',len(Oxyz)+1,
     4179                        style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE)
     4180                    AtomLabels,DistArray,AngArray = G2stMn.RetDistAngle(DisAglCtls,DisAglData,pgbar)
     4181                    pgbar.Destroy()
    41514182                    Bonds = []
    41524183                    for dists in DistArray:
     
    41544185                    G2plt.PlotBarGraph(G2frame,Bonds,Xname=r'$\mathsf{Bonds,\AA}$',
    41554186                        Title='Bond distances for %s'%Atypes,PlotName='%s Bonds'%Atypes)
     4187                    print('Total number of bonds to %s is %d'%(Atypes,len(Bonds)))
    41564188                    Angles = []
    41574189                    for angles in AngArray:
     
    41594191                    G2plt.PlotBarGraph(G2frame,Angles,Xname='$\mathsf{Angles,{^o}}$',
    41604192                        Title='Bond angles about %s'%Atypes,PlotName='%s Angles'%Atypes)
     4193                    print('Total number of angles about %s is %d'%(Atypes,len(Angles)))
    41614194                   
    41624195                elif fp:
     
    72157248        drawingData['Atoms'].append(MakeDrawAtom(atom))
    72167249       
    7217     def OnRestraint(event):       
    7218         indx = getAtomSelections(drawAtoms)
     7250    def OnRestraint(event):
     7251        cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7252        indx = getAtomSelections(drawAtoms,ct-1)
    72197253        if not indx: return
    72207254        indx = drawAtoms.GetSelectedRows()
     
    72247258        generalData = data['General']
    72257259        Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])           
    7226         cx,ct,cs,ci = drawingData['atomPtrs']
    72277260        atomData = drawingData['Atoms']
    72287261        atXYZ = []
     
    72727305
    72737306    def OnDefineRB(event):
    7274         indx = getAtomSelections(drawAtoms)
     7307        cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7308        indx = getAtomSelections(drawAtoms,ct-1)
    72757309        if not indx: return
    72767310        indx.sort()
     
    72807314        generalData = data['General']
    72817315        Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])           
    7282         cx,ct,cs,ci = drawingData['atomPtrs']
    72837316        atomData = drawingData['Atoms']
    72847317        rbXYZ = []
     
    75177550
    75187551    def DrawAtomStyle(event):
    7519         indx = getAtomSelections(drawAtoms)
     7552        cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7553        indx = getAtomSelections(drawAtoms,ct-1)
    75207554        if not indx: return
    75217555        generalData = data['General']
    75227556        atomData = data['Drawing']['Atoms']
    7523         cx,ct,cs,ci = data['Drawing']['atomPtrs']
    75247557        styleChoice = [' ','lines','vdW balls','sticks','balls & sticks','ellipsoids','polyhedra']
    75257558        if generalData['Type'] == 'macromolecular':
     
    75397572
    75407573    def DrawAtomLabel(event):
    7541         indx = getAtomSelections(drawAtoms)
     7574        cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7575        indx = getAtomSelections(drawAtomsct-1)
    75427576        if not indx: return
    75437577        generalData = data['General']
    75447578        atomData = data['Drawing']['Atoms']
    7545         cx,ct,cs,ci = data['Drawing']['atomPtrs']
    75467579        styleChoice = [' ','type','name','number']
    75477580        if generalData['Type'] == 'macromolecular':
     
    75597592           
    75607593    def DrawAtomColor(event):
    7561         indx = getAtomSelections(drawAtoms)
     7594        cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7595        indx = getAtomSelections(drawAtoms,ct-1)
    75627596        if not indx: return
    75637597        if len(indx) > 1:
     
    75667600            G2frame.GetStatusBar().SetStatusText('Change color, Add to Custom Colors, then OK',1)
    75677601        atomData = data['Drawing']['Atoms']
    7568         cx,ct,cs,ci = data['Drawing']['atomPtrs']
    75697602        atmColors = []
    75707603        atmTypes = []
     
    76197652       
    76207653    def SetViewPoint(event):
    7621         indx = getAtomSelections(drawAtoms)
     7654        cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7655        indx = getAtomSelections(drawAtoms,ct-1)
    76227656        if not indx: return
    76237657        atomData = data['Drawing']['Atoms']
    7624         cx = data['Drawing']['atomPtrs'][0]
    76257658        data['Drawing']['viewPoint'] = [atomData[indx[0]][cx:cx+3],[indx[0],0]]
    76267659#            drawAtoms.ClearSelection()                                  #do I really want to do this?
     
    76357668               
    76367669    def AddSymEquiv(event):
    7637         indx = getAtomSelections(drawAtoms)
     7670        cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7671        indx = getAtomSelections(drawAtoms,ct-1)
    76387672        if not indx: return
    76397673        indx.sort()
    76407674        colLabels = [drawAtoms.GetColLabelValue(c) for c in range(drawAtoms.GetNumberCols())]
    7641         cx,ct,cs,cui = data['Drawing']['atomPtrs']
    76427675        cuij = cui+2
    76437676        cmx = 0
     
    76907723           
    76917724    def AddSphere(event):
    7692         indx = getAtomSelections(drawAtoms)
     7725        cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7726        indx = getAtomSelections(drawAtoms,ct-1)
    76937727        if not indx: return
    76947728        generalData = data['General']
     
    76967730        atomData = data['Drawing']['Atoms']
    76977731        numAtoms = len(atomData)
    7698         cx,ct,cs,ci = data['Drawing']['atomPtrs']
    76997732        cuij = cs+5
    77007733        colLabels = [drawAtoms.GetColLabelValue(c) for c in range(drawAtoms.GetNumberCols())]
  • trunk/GSASIIstrMain.py

    r4450 r4451  
    575575    return True,'Success'
    576576
    577 def RetDistAngle(DisAglCtls,DisAglData):
     577def RetDistAngle(DisAglCtls,DisAglData,dlg=None):
    578578    '''Compute and return distances and angles
    579579
     
    635635    DistArray = {}
    636636    AngArray = {}
    637     for Oatom in origAtoms:
     637    for iO,Oatom in enumerate(origAtoms):
    638638        DistArray[Oatom[0]] = []
    639639        AngArray[Oatom[0]] = []
     
    677677                                    Vect.append([0.,0.,0.])
    678678                                    VectA.append([])
     679            if dlg is not None:
     680                dlg.Update(iO,newmsg='Atoms done=%d'%(iO))
    679681        for D in Dist:
    680682            DistArray[Oatom[0]].append(D[1:])
Note: See TracChangeset for help on using the changeset viewer.