Changeset 4471
 Timestamp:
 Jun 8, 2020 10:57:13 AM (2 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/GSASIIphsGUI.py
r4470 r4471 1261 1261 return neighborArray 1262 1262 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+21273 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 continue1283 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])%1001291 M = SGData['SGOps'][Opr1][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[opNum1]1299 atom[cs1] = 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,posInAllCellsxyzA)**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]: continue1306 C = xyzatom[cx:cx+3]+item[3]1307 newAtom = atom[:]1308 newAtom[cx:cx+3] = xyz1309 newAtom[cs1] += 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 newAtomList1313 1314 1263 def FindCoordination(ind,data,neighborArray,coordsArray,cmx=0,targets=None): 1315 1264 'Find atoms coordinating atom ind, speedup version' … … 8066 8015 8067 8016 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_TIMEwx.PD_AUTO_HIDEwx.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,xyzxyzA)**2)) 8054 if 0 < dist <= data['Drawing']['radiusFactor']*sumR: 8055 if noDuplicate(xyz,atomData): 8056 oprB = atomB[cs1] 8057 C = xyzxyzB 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[cs1] = 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() 8068 8077 indx = getAtomSelections(drawAtoms) 8069 8078 if not indx: return … … 8080 8089 cx,ct,cs,ci = data['Drawing']['atomPtrs'] 8081 8090 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']]) 8082 8093 cmx = 0 8083 8094 if 'Mx' in colLabels: … … 8092 8103 pgbar.SetPosition(wx.Point(screenSize[2]Size[0]305,screenSize[1]+5)) 8093 8104 for Ind,ind in enumerate(indx): 8094 atomData += FindCoordination 2(ind,data,cmx)8105 atomData += FindCoordination(ind,data,neighborArray,coordsArray,cmx,atomTypes) 8095 8106 GoOn = pgbar.Update(Ind,newmsg='Atoms done=%d'%(Ind)) 8096 8107 if not GoOn[0]: break 8097 8108 pgbar.Destroy() 8098 8109 data['Drawing']['Atoms'] = atomData 8110 print('search time: %.3f'%(time.time()time0)) 8099 8111 UpdateDrawAtoms() 8100 8112 drawAtoms.ClearSelection()
Note: See TracChangeset
for help on using the changeset viewer.