Changeset 4471


Ignore:
Timestamp:
Jun 8, 2020 10:57:13 AM (3 years ago)
Author:
vondreele
Message:

restore FillCoordSphere? from G2 version #4379

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIphsGUI.py

    r4470 r4471  
    12611261    return neighborArray
    12621262   
    1263 def FindCoordination2(ind,data,cmx=0,targets=None):
    1264     'Find atoms coordinating atom ind, somewhat faster version'
    1265     time1 = time.time()
    1266     generalData = data['General']
    1267     Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])
    1268     atomTypes,radii = getAtomRadii(data)
    1269     atomData = data['Drawing']['Atoms']
    1270     numAtoms = len(atomData)
    1271     cx,ct,cs,ci = data['Drawing']['atomPtrs']
    1272     cij = ci+2
    1273     SGData = generalData['SGData']
    1274     cellArray = G2lat.CellBlock(1)
    1275    
    1276     newAtomList = []
    1277     atomA = atomData[ind]
    1278     xyzA = np.array(atomA[cx:cx+3])
    1279     indA = atomTypes.index(atomA[ct])
    1280     for atomB in atomData:
    1281         if targets and atomB[ct] not in targets:
    1282             continue
    1283         indB = atomTypes.index(atomB[ct])
    1284         sumR = radii[indA]+radii[indB]
    1285         xyzB = np.array(atomB[cx:cx+3])
    1286         Uij = atomB[cs+5:cs+5+6]
    1287         for item in G2spc.GenAtom(xyzB,SGData,False,Uij,True):
    1288             atom = copy.copy(atomB)
    1289             atom[cx:cx+3] = item[0]
    1290             Opr = abs(item[2])%100
    1291             M = SGData['SGOps'][Opr-1][0]
    1292             if cmx:
    1293                 opNum = G2spc.GetOpNum(item[2],SGData)
    1294                 mom = np.array(atom[cmx:cmx+3])
    1295                 if SGData['SGGray']:
    1296                     atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)
    1297                 else:   
    1298                     atom[cmx:cmx+3] = np.inner(mom,M)*nl.det(M)*SpnFlp[opNum-1]
    1299             atom[cs-1] = str(item[2])+'+'
    1300             atom[cs+5:cs+5+6] = item[1]
    1301             posInAllCells = cellArray+np.array(atom[cx:cx+3])
    1302             dists = np.sqrt(np.sum(np.inner(Amat,posInAllCells-xyzA)**2,axis=0))
    1303             bonded = np.logical_and(dists < data['Drawing']['radiusFactor']*sumR, dists !=0)
    1304             for xyz in posInAllCells[bonded]:
    1305                 if True in [np.allclose(np.array(xyz),np.array(atom[cx:cx+3]),atol=0.0002) for atom in atomData]: continue
    1306                 C = xyz-atom[cx:cx+3]+item[3]
    1307                 newAtom = atom[:]
    1308                 newAtom[cx:cx+3] = xyz
    1309                 newAtom[cs-1] += str(int(round(C[0])))+','+str(int(round(C[1])))+','+str(int(round(C[2])))
    1310                 newAtomList.append(newAtom)
    1311     print ('Search time: %.2fs'%(time.time()-time1))
    1312     return newAtomList
    1313 
    13141263def FindCoordination(ind,data,neighborArray,coordsArray,cmx=0,targets=None):
    13151264    'Find atoms coordinating atom ind, speed-up version'
     
    80668015       
    80678016    def FillCoordSphere(event):
     8017        time0 = time.time()
     8018        generalData = data['General']
     8019        Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])
     8020        radii = generalData['BondRadii']
     8021        atomTypes = generalData['AtomTypes']
     8022        try:
     8023            indH = atomTypes.index('H')
     8024            radii[indH] = 0.5
     8025        except:
     8026            pass           
     8027        indx = drawAtoms.GetSelectedRows()
     8028        if indx:
     8029            indx.sort()
     8030            atomData = data['Drawing']['Atoms']
     8031            numAtoms = len(atomData)
     8032            cx,ct,cs,ci = data['Drawing']['atomPtrs']
     8033            cij = ci+2
     8034            SGData = generalData['SGData']
     8035            cellArray = G2lat.CellBlock(1)
     8036            nind = len(indx)
     8037            pgbar = wx.ProgressDialog('Fill CN sphere for %d atoms'%nind,'Atoms done=',nind+1,
     8038                style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT)
     8039            screenSize = wx.ClientDisplayRect()
     8040            Size = pgbar.GetSize()
     8041            if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0
     8042                pgbar.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x
     8043                pgbar.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
     8044            for Ind,ind in enumerate(indx):
     8045                atomA = atomData[ind]
     8046                xyzA = np.array(atomA[cx:cx+3])
     8047                indA = atomTypes.index(atomA[ct])
     8048                for atomB in atomData[:numAtoms]:
     8049                    indB = atomTypes.index(atomB[ct])
     8050                    sumR = radii[indA]+radii[indB]
     8051                    xyzB = np.array(atomB[cx:cx+3])
     8052                    for xyz in cellArray+xyzB:
     8053                        dist = np.sqrt(np.sum(np.inner(Amat,xyz-xyzA)**2))
     8054                        if 0 < dist <= data['Drawing']['radiusFactor']*sumR:
     8055                            if noDuplicate(xyz,atomData):
     8056                                oprB = atomB[cs-1]
     8057                                C = xyz-xyzB
     8058                                newOp = '1+'+str(int(round(C[0])))+','+str(int(round(C[1])))+','+str(int(round(C[2])))
     8059                                newAtom = atomB[:]
     8060                                newAtom[cx:cx+3] = xyz
     8061                                newAtom[cs-1] = G2spc.StringOpsProd(oprB,newOp,SGData)
     8062                                atomData.append(newAtom[:cij+9])  #not SS stuff
     8063                GoOn = pgbar.Update(Ind,newmsg='Atoms done=%d'%(Ind))
     8064                if not GoOn[0]:
     8065                    break
     8066            pgbar.Destroy()   
     8067            data['Drawing']['Atoms'] = atomData
     8068            print('search time: %.3f'%(time.time()-time0))
     8069            UpdateDrawAtoms()
     8070            drawAtoms.ClearSelection()
     8071            G2plt.PlotStructure(G2frame,data)
     8072        else:
     8073            G2G.G2MessageBox(G2frame,'Select atoms first')
     8074           
     8075    def FillCoordSphereNew(event):
     8076        time0 = time.time()
    80688077        indx = getAtomSelections(drawAtoms)
    80698078        if not indx: return
     
    80808089        cx,ct,cs,ci = data['Drawing']['atomPtrs']
    80818090        colLabels = [drawAtoms.GetColLabelValue(c) for c in range(drawAtoms.GetNumberCols())]
     8091        neighborArray = FindCoordinationByLabel(data)
     8092        coordsArray = np.array([a[cx:cx+3] for a in data['Drawing']['Atoms']])
    80828093        cmx = 0
    80838094        if 'Mx' in colLabels:
     
    80928103            pgbar.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5))
    80938104        for Ind,ind in enumerate(indx):
    8094             atomData += FindCoordination2(ind,data,cmx)
     8105            atomData += FindCoordination(ind,data,neighborArray,coordsArray,cmx,atomTypes)
    80958106            GoOn = pgbar.Update(Ind,newmsg='Atoms done=%d'%(Ind))
    80968107            if not GoOn[0]: break
    80978108        pgbar.Destroy()   
    80988109        data['Drawing']['Atoms'] = atomData
     8110        print('search time: %.3f'%(time.time()-time0))
    80998111        UpdateDrawAtoms()
    81008112        drawAtoms.ClearSelection()
Note: See TracChangeset for help on using the changeset viewer.