Changeset 4763


Ignore:
Timestamp:
Jan 13, 2021 4:34:34 PM (3 years ago)
Author:
vondreele
Message:

cleanup tif import for PIL use - remove commented lines
move getAtomPtrs from G2phsGUI to G2math & correct all ses; add a few new ones as well
Add new Atoms/Edit? Atoms/Collect? atoms - it moves atoms to equivalents closest to x, y, z axes, origin or cell center

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r4761 r4763  
    62296229            'wxID_ATOMSPDISAGL', 'wxID_ISODISP', 'wxID_ADDHATOM', 'wxID_UPDATEHATOM',
    62306230            'wxID_ATOMSROTATE', 'wxID_ATOMSDENSITY','wxID_ATOMSBNDANGLHIST',
    6231             'wxID_ATOMSSETALL', 'wxID_ATOMSSETSEL','wxID_ATOMFRACSPLIT',)
     6231            'wxID_ATOMSSETALL', 'wxID_ATOMSSETSEL','wxID_ATOMFRACSPLIT','wxID_COLLECTATOMS')
    62326232        self.AtomsMenu = wx.MenuBar()
    62336233        self.PrefillDataMenu(self.AtomsMenu)
     
    62536253        self.AtomEdit.Append(G2G.wxID_ATOMMOVE,'Move selected atom to view point','Select a single atom to be moved to view point in plot')
    62546254        self.AtomEdit.Append(G2G.wxID_MAKEMOLECULE,'Assemble molecule','Select a single atom to assemble as a molecule from scattered atom positions')
     6255        self.AtomEdit.Append(G2G.wxID_COLLECTATOMS,'Collect atoms','Collect selected atoms to specified unit cell location')
    62556256        self.AtomEdit.Append(G2G.wxID_RELOADDRAWATOMS,'Reload draw atoms','Reload atom drawing list')
    62566257        submenu = wx.Menu()
  • trunk/GSASIImath.py

    r4761 r4763  
    558558################################################################################
    559559
     560def getAtomPtrs(data,draw=False):
     561    ''' get atom data pointers cx,ct,cs,cia in Atoms or Draw Atoms lists
     562    NB:may not match column numbers in displayed table
     563   
     564        param: dict: data phase data structure
     565        draw: boolean True if Draw Atoms list pointers are required
     566        return: cx,ct,cs,cia pointers to atom xyz, type, site sym, uiso/aniso flag
     567    '''
     568    if draw:
     569        return data['Drawing']['atomPtrs']
     570    else:
     571        return data['General']['AtomPtrs']
     572
    560573def FindMolecule(ind,generalData,atomData):                    #uses numpy & masks - very fast even for proteins!
    561574
     
    752765    generalData = data['General']
    753766    SGData = generalData['SGData']
    754     cx,ct,cs,cia = generalData['AtomPtrs']
     767    cx,ct,cs,cia = getAtomPtrs(data)
    755768    drawingData = data['Drawing']
    756     dcx,dct,dcs,dci = drawingData['atomPtrs']
     769    dcx,dct,dcs,dci = getAtomPtrs(data,True)
    757770    atoms = data['Atoms']
    758771    drawAtoms = drawingData['Atoms']
     
    785798def FindNeighbors(phase,FrstName,AtNames,notName=''):
    786799    General = phase['General']
    787     cx,ct,cs,cia = General['AtomPtrs']
     800    cx,ct,cs,cia = getAtomPtrs(phase)
    788801    Atoms = phase['Atoms']
    789802    atNames = [atom[ct-1] for atom in Atoms]
     
    873886def FindAllNeighbors(phase,FrstName,AtNames,notName='',Orig=None,Short=False):
    874887    General = phase['General']
    875     cx,ct,cs,cia = General['AtomPtrs']
     888    cx,ct,cs,cia = getAtomPtrs(phase)
    876889    Atoms = phase['Atoms']
    877890    atNames = [atom[ct-1] for atom in Atoms]
     
    18851898    SGData = generalData['SGData']
    18861899    SSGData = generalData['SSGData']
    1887     cx,ct,cs,cia = generalData['AtomPtrs']
     1900    cx,ct,cs,cia = getAtomPtrs(data)
    18881901    drawingData = data['Drawing']
    18891902    modul = generalData['SuperVec'][0]
    1890     dcx,dct,dcs,dci = drawingData['atomPtrs']
     1903    dcx,dct,dcs,dci = getAtomPtrs(data,True)
    18911904    atoms = data['Atoms']
    18921905    drawAtoms = drawingData['Atoms']
     
    29432956    General = Phase['General']
    29442957    Amat,Bmat = G2lat.cell2AB(General['Cell'][1:7])
    2945     cx,ct,cs,cia = General['AtomPtrs']
     2958    cx,ct,cs,cia = getAtomPtrs(data)
    29462959    Atoms = Phase['Atoms']
    29472960    cartAtoms = []
     
    41474160            Unique.append(icntr)
    41484161    return Unique
     4162
     4163def AtomsCollect(data,Ind,Sel):
     4164    '''Finds the symmetry set of atoms for those selected. Selects
     4165    the one closest to the selected part of the unit cell.
     4166    Works on the contents of data['Map Peaks']. Called from OnPeaksUnique in
     4167    GSASIIphsGUI.py,
     4168
     4169    :param data: the phase data structure
     4170    :param list Ind: list of selected peak indices
     4171    :param int Sel: selected part of unit to find atoms closest to
     4172
     4173    :returns: the list of symmetry unique peaks from among those given in Ind
     4174    '''       
     4175    cx,ct,cs,ci = getAtomPtrs(data)
     4176    cent = np.ones(3)*.5     
     4177    generalData = data['General']
     4178    Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])
     4179    SGData = generalData['SGData']
     4180    Atoms = copy.deepcopy(data['Atoms'])
     4181    Indx = [True for ind in Ind]
     4182    # scan through peaks, finding all peaks equivalent to peak ind
     4183    for ind in Ind:
     4184        if Indx[ind]:
     4185            xyz = Atoms[ind][cx:cx+3]
     4186            uij = Atoms[ind][ci+2:ci+8]
     4187            if Atoms[ind][ci] == 'A':
     4188                Equiv = list(G2spc.GenAtom(xyz,SGData,Uij=uij))
     4189                Uijs = np.array([x[1] for x in Equiv])
     4190            else:
     4191                Equiv = G2spc.GenAtom(xyz,SGData)
     4192            xyzs = np.array([x[0] for x in Equiv])
     4193            dzeros = np.sqrt(np.sum(np.inner(Amat,xyzs)**2,axis=0))
     4194            dcent = np.sqrt(np.sum(np.inner(Amat,xyzs-cent)**2,axis=0))
     4195            xyzs = np.hstack((xyzs,dzeros[:,nxs],dcent[:,nxs]))
     4196            cind = np.argmin(xyzs.T[Sel-1])
     4197            Atoms[ind][cx:cx+3] = xyzs[cind][:3]
     4198            if Atoms[ind][ci] == 'A':
     4199                Atoms[ind][ci+2:ci+8] = Uijs[cind]
     4200    return Atoms
    41494201
    41504202################################################################################
     
    50615113    SGT = np.array([SGData['SGOps'][i][1] for i in range(len(SGData['SGOps']))])
    50625114    fixAtoms = data['Atoms']                       #if any
    5063     cx,ct,cs = generalData['AtomPtrs'][:3]
     5115    cx,ct,cs = getAtomPtrs(data)[:3]
    50645116    aTypes = set([])
    50655117    parmDict = {'Bmat':Bmat,'Gmat':Gmat}
  • trunk/GSASIIphsGUI.py

    r4759 r4763  
    11981198    dlg.Destroy()
    11991199    return indx
    1200 
    1201 def getAtomPtrs(data,draw=False):
    1202     ''' get atom data pointers cx,ct,cs,cia in Atoms or Draw Atoms lists
    1203     NB:may not match column numbers in displayed table
    1204    
    1205         param: dict: data phase data structure
    1206         draw: boolean True if Draw Atoms list pointers are required
    1207         return: cx,ct,cs,cia pointers to atom xyz, type, site sym, uiso/aniso flag
    1208     '''
    1209     if draw:
    1210         return data['Drawing']['atomPtrs']
    1211     else:
    1212         return data['General']['AtomPtrs']
    12131200
    12141201def SetPhaseWindow(phasePage,mainSizer=None,Scroll=0):
     
    36503637        '''Inserts a new atom into list immediately before every selected atom
    36513638        '''
    3652         cx,ct,cs,ci = getAtomPtrs(data)     
     3639        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    36533640        indx = getAtomSelections(Atoms,ct-1)
    36543641        for a in reversed(sorted(indx)):
     
    36713658        '''Adds H atoms to fill out coordination sphere for selected atoms
    36723659        '''
    3673         cx,ct,cs,cia = getAtomPtrs(data)     
     3660        cx,ct,cs,cia = G2mth.getAtomPtrs(data)     
    36743661        indx = getAtomSelections(Atoms,ct-1)
    36753662        if not indx: return
     
    37943781       
    37953782    def OnAtomMove(event):
    3796         cx,ct,cs,ci = getAtomPtrs(data)     
     3783        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    37973784        indx = getAtomSelections(Atoms,ct-1)
    37983785        drawData = data['Drawing']
     
    38413828
    38423829    def AtomDelete(event):
    3843         cx,ct,cs,ci = getAtomPtrs(data)     
     3830        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    38443831        indx = getAtomSelections(Atoms)
    38453832        colLabels = [Atoms.GetColLabelValue(c) for c in range(Atoms.GetNumberCols())]
     
    38773864       
    38783865    def AtomRefine(event):
    3879         cx,ct,cs,ci = getAtomPtrs(data)     
     3866        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    38803867        indx = getAtomSelections(Atoms,ct-1)
    38813868        if not indx: return
     
    39023889
    39033890    def AtomModify(event):
    3904         cx,ct,cs,ci = getAtomPtrs(data)     
     3891        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    39053892        indx = getAtomSelections(Atoms,ct-1)
    39063893        if not indx: return
     
    40134000
    40144001    def AtomTransform(event):
    4015         cx,ct,cs,ci = getAtomPtrs(data)     
     4002        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    40164003        indx = getAtomSelections(Atoms,ct-1)
    40174004        if not indx: return
     
    40834070#            'yz':np.array([[0,i,j] for i in range(3) for j in range(3)])-np.array([1,1,0]),
    40844071#            '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])}
    4085 #        cx,ct,cs,ci = getAtomPtrs(data)     
     4072#        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    40864073#        indx = getAtomSelections(Atoms,ct-1)
    40874074#        if indx:
     
    41264113#            print "select one or more rows of atoms"
    41274114#            G2frame.ErrorDialog('Select atom',"select one or more atoms then redo")
     4115
     4116    def CollectAtoms(event):
     4117        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
     4118        Ind = getAtomSelections(Atoms,ct-1)
     4119        if Ind:
     4120            choice = ['x=0','y=0','z=0','origin','center']
     4121            dlg = wx.SingleChoiceDialog(G2frame,'Atoms closest to:','Select',choice)
     4122            if dlg.ShowModal() == wx.ID_OK:
     4123                sel = dlg.GetSelection()+1
     4124                dlg.Destroy()
     4125            else:
     4126                dlg.Destroy()
     4127                return
     4128            wx.BeginBusyCursor()
     4129            data['Atoms'] = G2mth.AtomsCollect(data,Ind,sel)
     4130            wx.EndBusyCursor()
     4131            Atoms.ClearSelection()
     4132            data['Drawing']['Atoms'] = []
     4133            OnReloadDrawAtoms(event)           
     4134            FillAtomsGrid(Atoms)
    41284135               
    41294136    def MakeMolecule(event):     
    4130         cx,ct,cs,ci = getAtomPtrs(data)     
     4137        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    41314138        indx = getAtomSelections(Atoms,ct-1)
    41324139        DisAglCtls = {}
     
    41814188    def OnDistAngle(event,fp=None,hist=False):
    41824189        'Compute distances and angles'   
    4183         cx,ct,cs,ci = getAtomPtrs(data)     
     4190        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    41844191        indx = getAtomSelections(Atoms,ct-1)
    41854192        Oxyz = []
     
    42524259    def OnFracSplit(event):
    42534260        'Split atom frac accordintg to atom type & refined site fraction'   
    4254         cx,ct,cs,ci = getAtomPtrs(data)     
     4261        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    42554262        indx = getAtomSelections(Atoms,ct-1)
    42564263        if indx:
     
    74447451       
    74457452    def OnRestraint(event):
    7446         cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7453        cx,ct,cs,ci = G2mth.getAtomPtrs(data,draw=True)     
    74477454        indx = getAtomSelections(drawAtoms,ct-1)
    74487455        if not indx: return
     
    75007507
    75017508    def OnDefineRB(event):
    7502         cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7509        cx,ct,cs,ci = G2mth.getAtomPtrs(data,draw=True)     
    75037510        indx = getAtomSelections(drawAtoms,ct-1)
    75047511        if not indx: return
     
    77637770
    77647771    def DrawAtomStyle(event):
    7765         cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7772        cx,ct,cs,ci = G2mth.getAtomPtrs(data,draw=True)     
    77667773        indx = getAtomSelections(drawAtoms,ct-1)
    77677774        if not indx: return
     
    77857792
    77867793    def DrawAtomLabel(event):
    7787         cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7794        cx,ct,cs,ci = G2mth.getAtomPtrs(data,draw=True)     
    77887795        indx = getAtomSelections(drawAtoms,ct-1)
    77897796        if not indx: return
     
    78057812           
    78067813    def DrawAtomColor(event):
    7807         cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7814        cx,ct,cs,ci = G2mth.getAtomPtrs(data,draw=True)     
    78087815        indx = getAtomSelections(drawAtoms,ct-1)
    78097816        if not indx: return
     
    78657872       
    78667873    def SetViewPoint(event):
    7867         cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7874        cx,ct,cs,ci = G2mth.getAtomPtrs(data,draw=True)     
    78687875        indx = getAtomSelections(drawAtoms,ct-1)
    78697876        if not indx: return
     
    78817888               
    78827889    def AddSymEquiv(event):
    7883         cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7890        cx,ct,cs,ci = G2mth.getAtomPtrs(data,draw=True)     
    78847891        indx = getAtomSelections(drawAtoms,ct-1)
    78857892        if not indx: return
     
    79367943           
    79377944    def AddSphere(event):
    7938         cx,ct,cs,ci = getAtomPtrs(data,draw=True)     
     7945        cx,ct,cs,ci = G2mth.getAtomPtrs(data,draw=True)     
    79397946        indx = getAtomSelections(drawAtoms,ct-1,'as center of sphere addition',
    79407947                                     includeView=True)
     
    81358142        added = 0
    81368143        targets = [item for item in atomTypes if params[item]]
    8137         cx,ct,cs,ci = getAtomPtrs(data,draw=True)
     8144        cx,ct,cs,ci = G2mth.getAtomPtrs(data,draw=True)
    81388145        rep = 0
    81398146        allrep = 0
     
    1268212689        G2frame.Bind(wx.EVT_MENU, OnAtomMove, id=G2G.wxID_ATOMMOVE)
    1268312690        G2frame.Bind(wx.EVT_MENU, MakeMolecule, id=G2G.wxID_MAKEMOLECULE)
     12691        G2frame.Bind(wx.EVT_MENU, CollectAtoms, id=G2G.wxID_COLLECTATOMS)
    1268412692        G2frame.Bind(wx.EVT_MENU, OnReloadDrawAtoms, id=G2G.wxID_RELOADDRAWATOMS)
    1268512693        G2frame.Bind(wx.EVT_MENU, OnDistAngle, id=G2G.wxID_ATOMSDISAGL)
  • trunk/GSASIIplot.py

    r4759 r4763  
    84528452        elif G2frame.phaseDisplay.GetPageText(getSelection()) == 'Draw Atoms':
    84538453            atomList = drawAtoms
    8454             cx,ct,cs,cia = G2phG.getAtomPtrs(data,True)
     8454            cx,ct,cs,cia = G2mth.getAtomPtrs(data,True)
    84558455            cs -= 1  #cs points at style for drawings; want sytsym         
    84568456        else:
    84578457            atomList = data['Atoms']
    8458             cx,ct,cs,ciax = G2phG.getAtomPtrs(data)
     8458            cx,ct,cs,ciax = G2mth.getAtomPtrs(data)
    84598459        for i,atom in enumerate(atomList):
    84608460            x,y,z = atom[cx:cx+3]
     
    92159215        ballScale = drawingData['ballScale']
    92169216        xyzA = np.array((x,y,z))
    9217         cx,ct,cs,ci = G2phG.getAtomPtrs(data)     
     9217        cx,ct,cs,ci = G2mth.getAtomPtrs(data)     
    92189218        cellArray = G2lat.CellBlock(1)
    92199219        radDict = dict(zip(*G2phG.getAtomRadii(data)))
  • trunk/imports/G2img_1TIF.py

    r4762 r4763  
    6969        if self.Npix == 0:
    7070            G2fil.G2Print("GetTifData failed to read "+str(filename)+" Trying PIL")
    71 #            import scipy.misc
    72 #            self.Image = scipy.misc.imread(filename,flatten=True)
    7371            import PIL.Image as PI
    7472            self.Image = PI.open(filename,mode='r')
    75 #            self.Image.shape = self.Image.size
    76             # for scipy 1.2 & later  scipy.misc.imread will be removed
    77             # with note to use imageio.imread instead
    78             # (N.B. scipy.misc.imread uses PIL/pillow perhaps better to just use pillow)
    7973            self.Npix = self.Image.size
    8074            if ParentFrame:
     
    8276                self.Comments = ['no metadata']
    8377                self.Data = {'wavelength': 0.1, 'pixelSize': [200., 200.], 'distance': 100.0}
    84                 # try:        #as suggested by Adam Creuziger 1/12/2021
    85                 #     self.Data['size'] = list(self.Image.shape)
    86                 # except:
    87                 #     self.Data['size'] = list(self.Image.size)
    88                 # try:
    89                 #     self.Data['center'] = [int(i/2) for i in self.Image.shape]
    90                 # except:
    91                 #     self.Data['center'] = [int(i/2) for i in self.Image.size] 
    9278                self.Data['size'] = list(self.Image.size)
    9379                self.Data['center'] = [int(i/2) for i in self.Image.size]
Note: See TracChangeset for help on using the changeset viewer.