Changeset 4419
 Timestamp:
 May 14, 2020 8:25:30 PM (17 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/GSASIIplot.py
r4416 r4419 1434 1434 if not len(oldxy): oldxy = list(newxy) 1435 1435 dxy = newxyoldxy 1436 if dxy[0] == dxy[1] == 0: return # on Mac motion can be less than a full pixel! 1436 1437 drawingData['oldxy'] = list(newxy) 1437 1438 V = np.array([dxy[1],dxy[0],0.]) … … 1457 1458 if not len(oldxy): oldxy = list(newxy) 1458 1459 dxy = newxyoldxy 1460 if dxy[0] == dxy[1] == 0: return # on Mac motion can be less than a full pixel! 1459 1461 drawingData['oldxy'] = list(newxy) 1460 1462 V = drawingData['viewDir'] … … 7935 7937 Bonds[j].append(Dx[j]/2.) 7936 7938 return Bonds 7937 7938 # PlotStructure initialization here7939 global mcsaXYZ,mcsaTypes,mcsaBonds,txID,contourSet,Zslice7940 global cell, Vol, Amat, Bmat, A4mat, B4mat7941 txID = 07942 ForthirdPI = 4.0*math.pi/3.07943 generalData = data['General']7944 cell = generalData['Cell'][1:7]7945 ABC = np.array(cell[0:3])7946 Vol = generalData['Cell'][7:8][0]7947 Amat,Bmat = G2lat.cell2AB(cell) #Amat  crystal to cartesian, Bmat  inverse7948 Gmat,gmat = G2lat.cell2Gmat(cell)7949 A4mat = np.concatenate((np.concatenate((Amat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0)7950 B4mat = np.concatenate((np.concatenate((Bmat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0)7951 SGData = generalData['SGData']7952 SpnFlp = SGData.get('SpnFlp',[1,])7953 atomData = data['Atoms']7954 mapPeaks = []7955 contourSet = 07956 if generalData.get('DisAglCtrls',{}):7957 BondRadii = generalData['DisAglCtrls']['BondRadii']7958 else:7959 BondRadii = generalData['BondRadii']7960 drawingData = data['Drawing']7961 if not drawingData:7962 return #nothing setup, nothing to draw7963 G2phG.SetDrawingDefaults(drawingData)7964 if 'Map Peaks' in data:7965 mapPeaks = np.array(data['Map Peaks'])7966 peakMax = 100.7967 if len(mapPeaks):7968 peakMax = np.max(mapPeaks.T[0])7969 if 'Plane' not in drawingData:7970 drawingData['Plane'] = [[0,0,1],False,False,0.0,[255,255,0]]7971 resRBData = data['RBModels'].get('Residue',[])7972 vecRBData = data['RBModels'].get('Vector',[])7973 rbAtmDict = {}7974 for rbObj in resRBData+vecRBData:7975 exclList = ['X' for i in range(len(rbObj['Ids']))]7976 rbAtmDict.update(dict(zip(rbObj['Ids'],exclList)))7977 testRBObj = data.get('testRBObj',{})7978 rbObj = testRBObj.get('rbObj',{})7979 MCSA = data.get('MCSA',{})7980 mcsaModels = MCSA.get('Models',[])7981 if len(mcsaModels) > 1:7982 XYZs,Types = G2mth.UpdateMCSAxyz(Bmat,MCSA)7983 mcsaXYZ = []7984 mcsaTypes = []7985 neqv = 07986 for xyz,atyp in zip(XYZs,Types):7987 equiv = list(G2spc.GenAtom(xyz,SGData,All=True,Move=False))7988 neqv = max(neqv,len(equiv))7989 for item in equiv:7990 mcsaXYZ.append(item[0])7991 mcsaTypes.append(atyp)7992 mcsaXYZ = np.array(mcsaXYZ)7993 mcsaTypes = np.array(mcsaTypes)7994 nuniq = mcsaXYZ.shape[0]//neqv7995 mcsaXYZ = np.reshape(mcsaXYZ,(nuniq,neqv,3))7996 mcsaTypes = np.reshape(mcsaTypes,(nuniq,neqv))7997 cent = np.fix(np.sum(mcsaXYZ+2.,axis=0)/nuniq)27998 cent[0] = [0,0,0] #make sure 1st one isn't moved7999 mcsaXYZ = np.swapaxes(mcsaXYZ,0,1)cent[:,np.newaxis,:]8000 mcsaTypes = np.swapaxes(mcsaTypes,0,1)8001 mcsaXYZ = np.reshape(mcsaXYZ,(nuniq*neqv,3))8002 mcsaTypes = np.reshape(mcsaTypes,(nuniq*neqv))8003 mcsaBonds = FindPeaksBonds(mcsaXYZ)8004 drawAtoms = drawingData.get('Atoms',[])8005 mapData = {}8006 showBonds = False8007 if 'Map' in generalData:8008 mapData = generalData['Map']8009 showBonds = mapData.get('Show bonds',False)8010 Wt = np.array([255,255,255])8011 Rd = np.array([255,0,0])8012 Gr = np.array([0,255,0])8013 wxGreen = wx.Colour(0,255,0)8014 Bl = np.array([0,0,255])8015 Or = np.array([255,128,0])8016 wxOrange = wx.Colour(255,128,0)8017 uBox = np.array([[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]])8018 eBox = np.array([[0,1],[0,0],[1,0],[1,1],])8019 eplane = np.array([[1,1,0],[1,1,0],[1,1,0],[1,1,0]])8020 uEdges = np.array([8021 [uBox[0],uBox[1]],[uBox[0],uBox[3]],[uBox[0],uBox[4]],[uBox[1],uBox[2]],8022 [uBox[2],uBox[3]],[uBox[1],uBox[5]],[uBox[2],uBox[6]],[uBox[3],uBox[7]],8023 [uBox[4],uBox[5]],[uBox[5],uBox[6]],[uBox[6],uBox[7]],[uBox[7],uBox[4]]])8024 mD = 0.18025 mV = np.array([[[mD,0,0],[mD,0,0]],[[0,mD,0],[0,mD,0]],[[0,0,mD],[0,0,mD]]])8026 mapPeakVecs = np.inner(mV,Bmat)8027 8028 backColor = np.array(list(drawingData['backColor'])+[0,])8029 Bc = np.array(list(drawingData['backColor']))8030 uColors = [Rd,Gr,Bl,WtBc, WtBc,WtBc,WtBc,WtBc, WtBc,WtBc,WtBc,WtBc]8031 G2frame.tau = 0.8032 G2frame.seq = 08033 7939 8034 7940 def OnKeyBox(event): … … 8564 8470 if not len(oldxy): oldxy = list(newxy) 8565 8471 dxy = newxyoldxy 8472 if dxy[0] == dxy[1] == 0: return # on Mac motion can be less than a full pixel! 8566 8473 drawingData['oldxy'] = list(newxy) 8567 8474 V = np.array([dxy[1],dxy[0],0.]) … … 8588 8495 if not len(oldxy): oldxy = list(newxy) 8589 8496 dxy = newxyoldxy 8497 if dxy[0] == dxy[1] == 0: return # on Mac motion can be less than a full pixel! 8590 8498 drawingData['oldxy'] = list(newxy) 8591 8499 V = drawingData['viewDir'] … … 9221 9129 Draw('focus') 9222 9130 9223 # PlotStructure execution starts here (N.B. initialization above) 9131 # PlotStructure starts here 9132 global mcsaXYZ,mcsaTypes,mcsaBonds,txID,contourSet,Zslice 9133 global cell, Vol, Amat, Bmat, A4mat, B4mat 9134 txID = 0 9135 ForthirdPI = 4.0*math.pi/3.0 9136 generalData = data['General'] 9137 cell = generalData['Cell'][1:7] 9138 ABC = np.array(cell[0:3]) 9139 Vol = generalData['Cell'][7:8][0] 9140 Amat,Bmat = G2lat.cell2AB(cell) #Amat  crystal to cartesian, Bmat  inverse 9141 Gmat,gmat = G2lat.cell2Gmat(cell) 9142 A4mat = np.concatenate((np.concatenate((Amat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) 9143 B4mat = np.concatenate((np.concatenate((Bmat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0) 9144 SGData = generalData['SGData'] 9145 SpnFlp = SGData.get('SpnFlp',[1,]) 9146 atomData = data['Atoms'] 9147 mapPeaks = [] 9148 contourSet = 0 9149 if generalData.get('DisAglCtrls',{}): 9150 BondRadii = generalData['DisAglCtrls']['BondRadii'] 9151 else: 9152 BondRadii = generalData['BondRadii'] 9153 9154 drawingData = data['Drawing'] 9155 if not drawingData: 9156 return #nothing setup, nothing to draw 9157 9158 G2phG.SetDrawingDefaults(drawingData) 9159 if 'Map Peaks' in data: 9160 mapPeaks = np.array(data['Map Peaks']) 9161 peakMax = 100. 9162 if len(mapPeaks): 9163 peakMax = np.max(mapPeaks.T[0]) 9164 if 'Plane' not in drawingData: 9165 drawingData['Plane'] = [[0,0,1],False,False,0.0,[255,255,0]] 9166 resRBData = data['RBModels'].get('Residue',[]) 9167 vecRBData = data['RBModels'].get('Vector',[]) 9168 rbAtmDict = {} 9169 for rbObj in resRBData+vecRBData: 9170 exclList = ['X' for i in range(len(rbObj['Ids']))] 9171 rbAtmDict.update(dict(zip(rbObj['Ids'],exclList))) 9172 testRBObj = data.get('testRBObj',{}) 9173 rbObj = testRBObj.get('rbObj',{}) 9174 MCSA = data.get('MCSA',{}) 9175 mcsaModels = MCSA.get('Models',[]) 9176 if len(mcsaModels) > 1: 9177 XYZs,Types = G2mth.UpdateMCSAxyz(Bmat,MCSA) 9178 mcsaXYZ = [] 9179 mcsaTypes = [] 9180 neqv = 0 9181 for xyz,atyp in zip(XYZs,Types): 9182 equiv = list(G2spc.GenAtom(xyz,SGData,All=True,Move=False)) 9183 neqv = max(neqv,len(equiv)) 9184 for item in equiv: 9185 mcsaXYZ.append(item[0]) 9186 mcsaTypes.append(atyp) 9187 mcsaXYZ = np.array(mcsaXYZ) 9188 mcsaTypes = np.array(mcsaTypes) 9189 nuniq = mcsaXYZ.shape[0]//neqv 9190 mcsaXYZ = np.reshape(mcsaXYZ,(nuniq,neqv,3)) 9191 mcsaTypes = np.reshape(mcsaTypes,(nuniq,neqv)) 9192 cent = np.fix(np.sum(mcsaXYZ+2.,axis=0)/nuniq)2 9193 cent[0] = [0,0,0] #make sure 1st one isn't moved 9194 mcsaXYZ = np.swapaxes(mcsaXYZ,0,1)cent[:,np.newaxis,:] 9195 mcsaTypes = np.swapaxes(mcsaTypes,0,1) 9196 mcsaXYZ = np.reshape(mcsaXYZ,(nuniq*neqv,3)) 9197 mcsaTypes = np.reshape(mcsaTypes,(nuniq*neqv)) 9198 mcsaBonds = FindPeaksBonds(mcsaXYZ) 9199 drawAtoms = drawingData.get('Atoms',[]) 9200 9201 mapData = {'MapType':False, 'rho':[]} 9202 showBonds = False 9203 if 'Map' in generalData: 9204 mapData = generalData['Map'] 9205 showBonds = mapData.get('Show bonds',False) 9206 Wt = np.array([255,255,255]) 9207 Rd = np.array([255,0,0]) 9208 Gr = np.array([0,255,0]) 9209 wxGreen = wx.Colour(0,255,0) 9210 Bl = np.array([0,0,255]) 9211 Or = np.array([255,128,0]) 9212 wxOrange = wx.Colour(255,128,0) 9213 uBox = np.array([[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]]) 9214 eBox = np.array([[0,1],[0,0],[1,0],[1,1],]) 9215 eplane = np.array([[1,1,0],[1,1,0],[1,1,0],[1,1,0]]) 9216 uEdges = np.array([ 9217 [uBox[0],uBox[1]],[uBox[0],uBox[3]],[uBox[0],uBox[4]],[uBox[1],uBox[2]], 9218 [uBox[2],uBox[3]],[uBox[1],uBox[5]],[uBox[2],uBox[6]],[uBox[3],uBox[7]], 9219 [uBox[4],uBox[5]],[uBox[5],uBox[6]],[uBox[6],uBox[7]],[uBox[7],uBox[4]]]) 9220 mD = 0.1 9221 mV = np.array([[[mD,0,0],[mD,0,0]],[[0,mD,0],[0,mD,0]],[[0,0,mD],[0,0,mD]]]) 9222 mapPeakVecs = np.inner(mV,Bmat) 9223 9224 backColor = np.array(list(drawingData['backColor'])+[0,]) 9225 Bc = np.array(list(drawingData['backColor'])) 9226 uColors = [Rd,Gr,Bl,WtBc, WtBc,WtBc,WtBc,WtBc, WtBc,WtBc,WtBc,WtBc] 9227 G2frame.tau = 0. 9228 G2frame.seq = 0 9229 9224 9230 new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(generalData['Name'],'ogl') 9225 9231 if new: … … 9263 9269 # on Mac (& Linux?) the structure must be drawn twice the first time that graphics are displayed 9264 9270 if firstCall: Draw('main') # redraw 9271 return Draw,['main'] 9265 9272 9266 9273 ################################################################################ … … 9272 9279 ''' 9273 9280 9274 Mydir = G2frame.dirname9275 Rd = np.array([255,0,0])9276 Gr = np.array([0,255,0])9277 Bl = np.array([0,0,255])9278 uBox = np.array([[0,0,0],[50,0,0],[0,50,0],[0,0,50]])9279 uEdges = np.array([[uBox[0],uBox[1]],[uBox[0],uBox[2]],[uBox[0],uBox[3]]])9280 uColors = [Rd,Gr,Bl]9281 XYZ = np.array(Atoms[1:]).T #don't mess with original!9282 9283 # def SetRBOrigin():9284 # page = getSelection()9285 # if page:9286 # if G2frame.GetPageText(page) == 'Rigid bodies':9287 # G2frame.MapPeaksTable.SetData(mapPeaks)9288 # panel = G2frame.GetPage(page).GetChildren()9289 # names = [child.GetName() for child in panel]9290 # panel[names.index('grid window')].Refresh()9291 9292 9281 def OnMouseDown(event): 9293 9282 xy = event.GetPosition() … … 9335 9324 if not len(oldxy): oldxy = list(newxy) 9336 9325 dxy = newxyoldxy 9326 if dxy[0] == dxy[1] == 0: return # on Mac motion can be less than a full pixel! 9337 9327 defaults['oldxy'] = list(newxy) 9338 9328 V = np.array([dxy[1],dxy[0],0.]) … … 9355 9345 cent = [View[2]/2,View[3]/2] 9356 9346 oldxy = defaults['oldxy'] 9347 if dxy[0] == dxy[1] == 0: return # on Mac motion can be less than a full pixel! 9357 9348 if not len(oldxy): oldxy = list(newxy) 9358 9349 dxy = newxyoldxy … … 9474 9465 PDB.close() 9475 9466 G2frame.G2plotNB.status.SetStatusText('PDB model saved to: '+Fname,1) 9476 # PlotRigidBody execution starts here (N.B. initialization above) 9467 9468 # PlotBeadModel execution starts here 9469 Mydir = G2frame.dirname 9470 Rd = np.array([255,0,0]) 9471 Gr = np.array([0,255,0]) 9472 Bl = np.array([0,0,255]) 9473 uBox = np.array([[0,0,0],[50,0,0],[0,50,0],[0,0,50]]) 9474 uEdges = np.array([[uBox[0],uBox[1]],[uBox[0],uBox[2]],[uBox[0],uBox[3]]]) 9475 uColors = [Rd,Gr,Bl] 9476 XYZ = np.array(Atoms[1:]).T #don't mess with original! 9477 9477 new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Bead model','ogl') 9478 9478 if new: … … 9508 9508 '''RB plotting package. Can show rigid body structures as balls & sticks 9509 9509 ''' 9510 9511 9510 def FindBonds(XYZ): 9512 9511 rbTypes = rbData['rbTypes'] … … 9528 9527 return Bonds 9529 9528 9530 Mydir = G2frame.dirname9531 Rd = np.array([255,0,0])9532 Gr = np.array([0,255,0])9533 Bl = np.array([0,0,255])9534 uBox = np.array([[0,0,0],[1,0,0],[0,1,0],[0,0,1]])9535 uEdges = np.array([[uBox[0],uBox[1]],[uBox[0],uBox[2]],[uBox[0],uBox[3]]])9536 uColors = [Rd,Gr,Bl]9537 if rbType == 'Vector':9538 atNames = [str(i)+':'+Ty for i,Ty in enumerate(rbData['rbTypes'])]9539 XYZ = np.array([[0.,0.,0.] for Ty in rbData['rbTypes']])9540 for imag,mag in enumerate(rbData['VectMag']):9541 XYZ += mag*rbData['rbVect'][imag]9542 Bonds = FindBonds(XYZ)9543 elif rbType == 'Residue':9544 # atNames = [str(i)+':'+Ty for i,Ty in enumerate(rbData['atNames'])]9545 atNames = rbData['atNames']9546 XYZ = np.copy(rbData['rbXYZ']) #don't mess with original!9547 Seq = rbData['rbSeq']9548 for ia,ib,ang,mv in Seq:9549 va = XYZ[ia]XYZ[ib]9550 Q = G2mth.AVdeg2Q(ang,va)9551 for im in mv:9552 vb = XYZ[im]XYZ[ib]9553 vb = G2mth.prodQVQ(Q,vb)9554 XYZ[im] = XYZ[ib]+vb9555 Bonds = FindBonds(XYZ)9556 elif rbType == 'Zmatrix':9557 pass9558 9559 9529 # def SetRBOrigin(): 9560 9530 # page = getSelection() … … 9611 9581 if not len(oldxy): oldxy = list(newxy) 9612 9582 dxy = newxyoldxy 9583 if dxy[0] == dxy[1] == 0: return # on Mac motion can be less than a full pixel! 9613 9584 defaults['oldxy'] = list(newxy) 9614 9585 V = np.array([dxy[1],dxy[0],0.]) … … 9633 9604 if not len(oldxy): oldxy = list(newxy) 9634 9605 dxy = newxyoldxy 9606 if dxy[0] == dxy[1] == 0: return # on Mac motion can be less than a full pixel! 9635 9607 defaults['oldxy'] = list(newxy) 9636 9608 V = defaults['viewDir'] … … 9729 9701 RenderUnitVectors(0.,0.,0.) 9730 9702 radius = 0.2 9703 s = 1 9704 selected = rbData.get('Selection') 9731 9705 for iat,atom in enumerate(XYZ): 9706 if selected: 9707 if selected[iat]: 9708 s = 1 9709 else: 9710 s = 3 9732 9711 x,y,z = atom 9733 9712 CL = AtInfo[rbData['rbTypes'][iat]][1] 9734 color = np.array(CL)/ 255.9713 color = np.array(CL)/(s*255.) 9735 9714 RenderSphere(x,y,z,radius,color) 9736 9715 RenderBonds(x,y,z,Bonds[iat],0.05,color) … … 9775 9754 G2frame.G2plotNB.status.SetStatusText('Drawing saved to: '+Fname,1) 9776 9755 9777 # PlotRigidBody execution starts here (N.B. initialization above) 9756 def UpdateDraw(): 9757 '''This updates the drawing arrays in place''' 9758 for i,Ty in enumerate(rbData['rbTypes']): 9759 atNames[i] = str(i)+':'+Ty 9760 for i in range(len(XYZ)): 9761 XYZ[i].fill(0) 9762 for imag,mag in enumerate(rbData['VectMag']): 9763 XYZ[i] += mag*rbData['rbVect'][imag][i] 9764 # number of bonds should not change (=# of atoms) 9765 newBonds = FindBonds(XYZ) 9766 for i in range(len(Bonds)): 9767 Bonds[i] = newBonds[i] 9768 Draw() # drawing twice seems needed sometimes at least on mac 9769 Draw() 9770 9771 # PlotRigidBody execution starts here 9772 Mydir = G2frame.dirname 9773 Rd = np.array([255,0,0]) 9774 Gr = np.array([0,255,0]) 9775 Bl = np.array([0,80,255]) # blue on black is hard to see 9776 uBox = np.array([[0,0,0],[1,0,0],[0,1,0],[0,0,1]]) 9777 uEdges = np.array([[uBox[0],uBox[1]],[uBox[0],uBox[2]],[uBox[0],uBox[3]]]) 9778 uColors = [Rd,Gr,Bl] 9779 if rbType == 'Vector': 9780 atNames = [str(i)+':'+Ty for i,Ty in enumerate(rbData['rbTypes'])] 9781 XYZ = np.array([[0.,0.,0.] for Ty in rbData['rbTypes']]) 9782 for imag,mag in enumerate(rbData['VectMag']): 9783 XYZ += mag*rbData['rbVect'][imag] 9784 Bonds = FindBonds(XYZ) 9785 elif rbType == 'Residue': 9786 # atNames = [str(i)+':'+Ty for i,Ty in enumerate(rbData['atNames'])] 9787 atNames = rbData['atNames'] 9788 XYZ = np.copy(rbData['rbXYZ']) #don't mess with original! 9789 Seq = rbData['rbSeq'] 9790 for ia,ib,ang,mv in Seq: 9791 va = XYZ[ia]XYZ[ib] 9792 Q = G2mth.AVdeg2Q(ang,va) 9793 for im in mv: 9794 vb = XYZ[im]XYZ[ib] 9795 vb = G2mth.prodQVQ(Q,vb) 9796 XYZ[im] = XYZ[ib]+vb 9797 Bonds = FindBonds(XYZ) 9798 elif rbType == 'Zmatrix': 9799 pass 9800 else: 9801 print('rbType=', rbType) 9802 if GSASIIpath.GetConfigValue('debug'): raise Exception('Should not happen') 9803 9778 9804 new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Rigid body','ogl') 9779 9805 if new: … … 9802 9828 Draw('main') 9803 9829 Draw('main') #to fill both buffers so save works 9804 9830 if rbType == 'Vector': return UpdateDraw 9805 9831 ################################################################################ 9806 9832 #### Plot Layers … … 10032 10058 if not len(oldxy): oldxy = list(newxy) 10033 10059 dxy = newxyoldxy 10060 if dxy[0] == dxy[1] == 0: return # on Mac motion can be less than a full pixel! 10034 10061 defaults['oldxy'] = list(newxy) 10035 10062 V = np.array([dxy[1],dxy[0],0.]) … … 10052 10079 cent = [View[2]/2,View[3]/2] 10053 10080 oldxy = defaults['oldxy'] 10081 if dxy[0] == dxy[1] == 0: return # on Mac motion can be less than a full pixel! 10054 10082 if not len(oldxy): oldxy = list(newxy) 10055 10083 dxy = newxyoldxy
Note: See TracChangeset
for help on using the changeset viewer.