Changeset 1951
- Timestamp:
- Aug 7, 2015 11:54:12 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIImath.py
r1935 r1951 289 289 return newAtoms 290 290 291 def FindAtomIndexByIDs(atomData, IDs,Draw=True):291 def FindAtomIndexByIDs(atomData,loc,IDs,Draw=True): 292 292 '''finds the set of atom array indices for a list of atom IDs. Will search 293 293 either the Atom table or the drawAtom table. 294 294 295 295 :param list atomData: Atom or drawAtom table containting coordinates, etc. 296 :param int loc: location of atom id in atomData record 296 297 :param list IDs: atom IDs to be found 297 298 :param bool Draw: True if drawAtom table to be searched; False if Atom table … … 303 304 indx = [] 304 305 for i,atom in enumerate(atomData): 305 if Draw and atom[ -3] in IDs:306 if Draw and atom[loc] in IDs: 306 307 indx.append(i) 307 elif atom[ -1] in IDs:308 elif atom[loc] in IDs: 308 309 indx.append(i) 309 310 return indx … … 918 919 return Xanom 919 920 921 ################################################################################ 922 #### Modulation math 923 ################################################################################ 924 920 925 def Modulation(waveTypes,SSUniq,SSPhi,FSSdata,XSSdata,USSdata): 921 926 import scipy.special as sp … … 976 981 B = np.array([fc[:,np.newaxis]*np.cos(2.*np.pi*(i+1)*tau) for i,fc in enumerate(fcos)]) 977 982 return np.sum(A,axis=0)+np.sum(B,axis=0) 983 984 def ApplyModulation(data,tau): 985 '''Applies modulation to drawing atom positions & Uijs for given tau 986 ''' 987 generalData = data['General'] 988 SGData = generalData['SGData'] 989 cx,ct,cs,cia = generalData['AtomPtrs'] 990 drawingData = data['Drawing'] 991 dcx,dct,dcs,dci = drawingData['atomPtrs'] 992 atoms = data['Atoms'] 993 drawAtoms = drawingData['Atoms'] 994 for atom in atoms: 995 atxyz = np.array(atom[cx:cx+3]) 996 waveType = atom[-1]['SS1']['waveType'] 997 Spos = atom[-1]['SS1']['Spos'] 998 wave = np.zeros(3) 999 if len(Spos): 1000 scof = [] 1001 ccof = [] 1002 for i,spos in enumerate(Spos): 1003 if waveType in ['Sawtooth','ZigZag'] and not i: 1004 Toff = spos[0][0] 1005 slopes = np.array(spos[0][1:]) 1006 if waveType == 'Sawtooth': 1007 wave = posSawtooth(tau,Toff,slopes) 1008 elif waveType == 'ZigZag': 1009 wave = posZigZag(tau,Toff,slopes) 1010 else: 1011 scof.append(spos[0][:3]) 1012 ccof.append(spos[0][3:]) 1013 wave += np.sum(posFourier(tau,np.array(scof),np.array(ccof)),axis=1) 1014 indx = FindAtomIndexByIDs(drawAtoms,dci,[atom[cia+8],],True) 1015 for ind in indx: 1016 drawatom = drawAtoms[ind] 1017 opr = drawatom[dcs-1] 1018 if atom[cia] == 'A': 1019 X,U = G2spc.ApplyStringOps(opr,SGData,atxyz+wave,atom[cia+2:cia+8]) 1020 drawatom[dcx:dcx+3] = X 1021 # drawatom[dci-6:dci] = U 1022 else: 1023 X = G2spc.ApplyStringOps(opr,SGData,atxyz+wave) 1024 drawatom[dcx:dcx+3] = X 1025 return drawAtoms 1026 978 1027 979 1028 ################################################################################ -
trunk/GSASIIphsGUI.py
r1947 r1951 78 78 mainFrame.SendSizeEvent() 79 79 80 #def FindBondsToo(): #works but slow for large structures - keep as reference 81 # cx,ct,cs,ci = data['Drawing']['atomPtrs'] 82 # atomData = data['Drawing']['Atoms'] 83 # generalData = data['General'] 84 # Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7]) 85 # radii = generalData['BondRadii'] 86 # atomTypes = generalData['AtomTypes'] 87 # try: 88 # indH = atomTypes.index('H') 89 # radii[indH] = 0.5 90 # except: 91 # pass 92 # for atom in atomData: 93 # atom[-1] = [] 94 # Atoms = [] 95 # for i,atom in enumerate(atomData): 96 # Atoms.append([i,np.array(atom[cx:cx+3]),atom[cs],radii[atomTypes.index(atom[ct])]]) 97 # for atomA in Atoms: 98 # if atomA[2] in ['lines','sticks','ellipsoids','balls & sticks','polyhedra']: 99 # for atomB in Atoms: 100 # Dx = atomB[1]-atomA[1] 101 # DX = np.inner(Amat,Dx) 102 # dist = np.sqrt(np.sum(DX**2)) 103 # sumR = atomA[3]+atomB[3] 104 # if 0.5 < dist <= 0.85*sumR: 105 # i = atomA[0] 106 # if atomA[2] == 'polyhedra': 107 # atomData[i][-1].append(DX) 108 # elif atomB[1] != 'polyhedra': 109 # j = atomB[0] 110 # atomData[i][-1].append(Dx*atomA[3]/sumR) 111 # atomData[j][-1].append(-Dx*atomB[3]/sumR) 112 113 def FindBondsDraw(data): 114 '''uses numpy & masks - very fast even for proteins! 115 ''' 116 import numpy.ma as ma 117 cx,ct,cs,ci = data['Drawing']['atomPtrs'] 118 hydro = data['Drawing']['showHydrogen'] 119 atomData = data['Drawing']['Atoms'] 120 generalData = data['General'] 121 Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7]) 122 radii = generalData['BondRadii'] 123 atomTypes = generalData['AtomTypes'] 124 try: 125 indH = atomTypes.index('H') 126 radii[indH] = 0.5 127 except: 128 pass 129 for atom in atomData: 130 atom[-2] = [] #clear out old bonds/polyhedra 131 atom[-1] = [] 132 Indx = range(len(atomData)) 133 Atoms = [] 134 Styles = [] 135 Radii = [] 136 for atom in atomData: 137 Atoms.append(np.array(atom[cx:cx+3])) 138 Styles.append(atom[cs]) 139 try: 140 if not hydro and atom[ct] == 'H': 141 Radii.append(0.0) 142 else: 143 Radii.append(radii[atomTypes.index(atom[ct])]) 144 except ValueError: #changed atom type! 145 Radii.append(0.20) 146 Atoms = np.array(Atoms) 147 Radii = np.array(Radii) 148 IASR = zip(Indx,Atoms,Styles,Radii) 149 for atomA in IASR: 150 if atomA[2] in ['lines','sticks','ellipsoids','balls & sticks','polyhedra']: 151 Dx = Atoms-atomA[1] 152 dist = ma.masked_less(np.sqrt(np.sum(np.inner(Amat,Dx)**2,axis=0)),0.5) #gets rid of G2frame & disorder "bonds" < 0.5A 153 sumR = atomA[3]+Radii 154 IndB = ma.nonzero(ma.masked_greater(dist-data['Drawing']['radiusFactor']*sumR,0.)) #get indices of bonded atoms 155 i = atomA[0] 156 for j in IndB[0]: 157 if Styles[i] == 'polyhedra': 158 atomData[i][-2].append(np.inner(Amat,Dx[j])) 159 elif Styles[j] != 'polyhedra' and j > i: 160 atomData[i][-2].append(Dx[j]*Radii[i]/sumR[j]) 161 atomData[j][-2].append(-Dx[j]*Radii[j]/sumR[j]) 162 if Styles[i] == 'polyhedra': 163 Bonds = atomData[i][-2] 164 Faces = [] 165 if len(Bonds) > 2: 166 FaceGen = G2lat.uniqueCombinations(Bonds,3) #N.B. this is a generator 167 for face in FaceGen: 168 vol = nl.det(face) 169 if abs(vol) > 1. or len(Bonds) == 3: 170 if vol < 0.: 171 face = [face[0],face[2],face[1]] 172 face = np.array(face) 173 if not np.array([np.array(nl.det(face-bond))+0.0001 < 0 for bond in Bonds]).any(): 174 norm = np.cross(face[1]-face[0],face[2]-face[0]) 175 norm /= np.sqrt(np.sum(norm**2)) 176 Faces.append([face,norm]) 177 atomData[i][-1] = Faces 178 80 179 def UpdatePhaseData(G2frame,Item,data,oldPage): 81 180 '''Create the data display window contents when a phase is clicked on … … 98 197 def GetReflData(G2frame,phaseName,reflNames): 99 198 ReflData = {'RefList':[],'Type':''} 199 if '' in reflNames: 200 return None 100 201 for reflName in reflNames: 101 202 if 'PWDR' in reflName: … … 1209 1310 atomData[r][c] = parms 1210 1311 if 'Atoms' in data['Drawing']: 1211 DrawAtomsReplaceByID(data['Drawing'], atomData[r],ID)1312 DrawAtomsReplaceByID(data['Drawing'],ui+6,atomData[r],ID) 1212 1313 wx.CallAfter(Paint) 1213 1314 … … 1277 1378 atomData[r][c] = atomData[r][c].replace(rbAtmDict.get(atomData[r][ci+8],''),'') 1278 1379 if 'Atoms' in data['Drawing']: 1279 DrawAtomsReplaceByID(data['Drawing'], atomData[r],ID)1380 DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[r],ID) 1280 1381 wx.CallAfter(Paint) 1281 1382 … … 1300 1401 ID = atomData[r][ci+8] 1301 1402 if 'Atoms' in data['Drawing']: 1302 DrawAtomsReplaceByID(data['Drawing'], atomData[r],ID)1403 DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[r],ID) 1303 1404 SetupGeneral() 1304 1405 else: … … 1674 1775 FillAtomsGrid(Atoms) 1675 1776 ID = atomData[indx[0]][ci+8] 1676 DrawAtomsReplaceByID(data['Drawing'], atomData[indx[0]],ID)1777 DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[indx[0]],ID) 1677 1778 G2plt.PlotStructure(G2frame,data) 1678 1779 event.StopPropagation() 1679 1780 1680 def DrawAtomsReplaceByID(drawingData, atom,ID):1781 def DrawAtomsReplaceByID(drawingData,loc,atom,ID): 1681 1782 IDs = [ID,] 1682 1783 atomData = drawingData['Atoms'] 1683 indx = G2mth.FindAtomIndexByIDs(atomData, IDs)1784 indx = G2mth.FindAtomIndexByIDs(atomData,loc,IDs) 1684 1785 for ind in indx: 1685 1786 atomData[ind] = MakeDrawAtom(atom,atomData[ind]) … … 1818 1919 for r in indx: 1819 1920 ID = atomData[r][ci+8] 1820 DrawAtomsReplaceByID(data['Drawing'], atomData[r],ID)1921 DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[r],ID) 1821 1922 FillAtomsGrid(Atoms) 1822 1923 dlg.Destroy() … … 1904 2005 XYZ = XYZ+cent+Cell 1905 2006 if Force: 1906 XYZ = G2spc.MoveToUnitCell(XYZ) 2007 XYZ,cell = G2spc.MoveToUnitCell(XYZ) 2008 Cell += cell 1907 2009 if New: 1908 2010 atom = copy.copy(atomData[ind]) … … 2667 2769 atomData[r][c] = parms 2668 2770 drawAtoms.SetCellValue(r,c,parms) 2669 FindBondsDraw( )2771 FindBondsDraw(data) 2670 2772 G2plt.PlotStructure(G2frame,data) 2671 2773 dlg.Destroy() … … 2709 2811 if drawAtoms.GetColLabelValue(c) in ['Style','Label']: 2710 2812 atomData[r][c] = drawAtoms.GetCellValue(r,c) 2711 FindBondsDraw( )2813 FindBondsDraw(data) 2712 2814 elif drawAtoms.GetColLabelValue(c) == 'Color': 2713 2815 dlg = wx.ColourDialog(G2frame) … … 2773 2875 labelChoice = [' ','type','name','number','residue','1-letter','chain'] 2774 2876 Types[9] = wg.GRID_VALUE_CHOICE+": ,type,name,number,residue,1-letter,chain" 2775 # elif generalData['Type'] == 'modulated':2776 # Types += []2777 # colLabels += []2778 2877 table = [] 2779 2878 rowLabels = [] … … 2782 2881 rowLabels.append(str(i)) 2783 2882 2784 atomTable = G2G.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types)2785 drawAtoms.SetTable( atomTable, True)2883 G2frame.atomTable = G2G.Table(table,rowLabels=rowLabels,colLabels=colLabels,types=Types) 2884 drawAtoms.SetTable(G2frame.atomTable, True) 2786 2885 drawAtoms.SetMargins(0,0) 2787 2886 drawAtoms.AutoSizeColumns(True) … … 2811 2910 G2frame.dataFrame.setSizePosLeft([600,300]) 2812 2911 2813 FindBondsDraw( )2912 FindBondsDraw(data) 2814 2913 drawAtoms.ClearSelection() 2815 2914 # G2plt.PlotStructure(G2frame,data) … … 2833 2932 drawAtoms.SetCellValue(r,cs,parms) 2834 2933 dlg.Destroy() 2835 FindBondsDraw( )2934 FindBondsDraw(data) 2836 2935 drawAtoms.ClearSelection() 2837 2936 G2plt.PlotStructure(G2frame,data) … … 2992 3091 XYZ = XYZ+cent+Cell 2993 3092 if Force: 2994 XYZ = G2spc.MoveToUnitCell(XYZ) 3093 XYZ,cell = G2spc.MoveToUnitCell(XYZ) 3094 Cell += cell 2995 3095 atom = atomData[ind] 2996 3096 atom[cx:cx+3] = XYZ … … 3085 3185 atom[cuij:cuij+6] = item[1] 3086 3186 Opp = G2spc.Opposite(item[0]) 3087 for xyz in Opp: 3088 if noDuplicate(xyz,atomData): 3089 cell = np.asarray(np.rint(xyz-atom[cx:cx+3]),dtype=np.int32) 3090 cell = '1'+'+'+ \ 3091 str(cell[0])+','+str(cell[1])+','+str(cell[2]) 3092 atom[cx:cx+3] = xyz 3093 atom[cx+3] = G2spc.StringOpsProd(cell,atom[cx+3],SGData) 3187 for key in Opp: 3188 if noDuplicate(Opp[key],atomData): 3189 unit = np.array([eval(i) for i in key.split(',')])-item[3] 3190 cell = '%d+%d,%d,%d'%(item[2],unit[0],unit[1],unit[2]) 3191 atom[cx:cx+3] = Opp[key] 3192 atom[cx+3] = cell 3094 3193 atomData.append(atom[:]) 3095 3194 else: … … 3101 3200 +str(item[2][0])+','+str(item[2][1])+','+str(item[2][2]) 3102 3201 Opp = G2spc.Opposite(item[0]) 3103 for xyz in Opp: 3104 if noDuplicate(xyz,atomData): 3105 cell = np.asarray(np.rint(xyz-atom[cx:cx+3]),dtype=np.int32) 3106 cell = '1'+'+'+ \ 3107 str(cell[0])+','+str(cell[1])+','+str(cell[2]) 3108 atom[cx:cx+3] = xyz 3109 atom[cx+3] = G2spc.StringOpsProd(cell,atom[cx+3],SGData) 3202 for key in Opp: 3203 if noDuplicate(Opp[key],atomData): 3204 unit = np.array([eval(i) for i in key.split(',')])-item[2] 3205 cell = '%d+%d,%d,%d'%(item[1],unit[0],unit[1],unit[2]) 3206 atom[cx:cx+3] = Opp[key] 3207 atom[cx+3] = cell 3110 3208 atomData.append(atom[:]) 3111 3209 data['Drawing']['Atoms'] = atomData … … 3116 3214 G2plt.PlotStructure(G2frame,data) 3117 3215 3118 def FindBondsToo(): #works but slow for large structures - keep as reference3119 cx,ct,cs,ci = data['Drawing']['atomPtrs']3120 atomData = data['Drawing']['Atoms']3121 generalData = data['General']3122 Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])3123 radii = generalData['BondRadii']3124 atomTypes = generalData['AtomTypes']3125 try:3126 indH = atomTypes.index('H')3127 radii[indH] = 0.53128 except:3129 pass3130 for atom in atomData:3131 atom[-1] = []3132 Atoms = []3133 for i,atom in enumerate(atomData):3134 Atoms.append([i,np.array(atom[cx:cx+3]),atom[cs],radii[atomTypes.index(atom[ct])]])3135 for atomA in Atoms:3136 if atomA[2] in ['lines','sticks','ellipsoids','balls & sticks','polyhedra']:3137 for atomB in Atoms:3138 Dx = atomB[1]-atomA[1]3139 DX = np.inner(Amat,Dx)3140 dist = np.sqrt(np.sum(DX**2))3141 sumR = atomA[3]+atomB[3]3142 if 0.5 < dist <= 0.85*sumR:3143 i = atomA[0]3144 if atomA[2] == 'polyhedra':3145 atomData[i][-1].append(DX)3146 elif atomB[1] != 'polyhedra':3147 j = atomB[0]3148 atomData[i][-1].append(Dx*atomA[3]/sumR)3149 atomData[j][-1].append(-Dx*atomB[3]/sumR)3150 3151 def FindBondsDraw(): #uses numpy & masks - very fast even for proteins!3152 import numpy.ma as ma3153 cx,ct,cs,ci = data['Drawing']['atomPtrs']3154 hydro = data['Drawing']['showHydrogen']3155 atomData = data['Drawing']['Atoms']3156 generalData = data['General']3157 Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7])3158 radii = generalData['BondRadii']3159 atomTypes = generalData['AtomTypes']3160 try:3161 indH = atomTypes.index('H')3162 radii[indH] = 0.53163 except:3164 pass3165 for atom in atomData:3166 atom[-2] = [] #clear out old bonds/polyhedra3167 atom[-1] = []3168 Indx = range(len(atomData))3169 Atoms = []3170 Styles = []3171 Radii = []3172 for atom in atomData:3173 Atoms.append(np.array(atom[cx:cx+3]))3174 Styles.append(atom[cs])3175 try:3176 if not hydro and atom[ct] == 'H':3177 Radii.append(0.0)3178 else:3179 Radii.append(radii[atomTypes.index(atom[ct])])3180 except ValueError: #changed atom type!3181 Radii.append(0.20)3182 Atoms = np.array(Atoms)3183 Radii = np.array(Radii)3184 IASR = zip(Indx,Atoms,Styles,Radii)3185 for atomA in IASR:3186 if atomA[2] in ['lines','sticks','ellipsoids','balls & sticks','polyhedra']:3187 Dx = Atoms-atomA[1]3188 dist = ma.masked_less(np.sqrt(np.sum(np.inner(Amat,Dx)**2,axis=0)),0.5) #gets rid of G2frame & disorder "bonds" < 0.5A3189 sumR = atomA[3]+Radii3190 IndB = ma.nonzero(ma.masked_greater(dist-data['Drawing']['radiusFactor']*sumR,0.)) #get indices of bonded atoms3191 i = atomA[0]3192 for j in IndB[0]:3193 if Styles[i] == 'polyhedra':3194 atomData[i][-2].append(np.inner(Amat,Dx[j]))3195 elif Styles[j] != 'polyhedra' and j > i:3196 atomData[i][-2].append(Dx[j]*Radii[i]/sumR[j])3197 atomData[j][-2].append(-Dx[j]*Radii[j]/sumR[j])3198 if Styles[i] == 'polyhedra':3199 Bonds = atomData[i][-2]3200 Faces = []3201 if len(Bonds) > 2:3202 FaceGen = G2lat.uniqueCombinations(Bonds,3) #N.B. this is a generator3203 for face in FaceGen:3204 vol = nl.det(face)3205 if abs(vol) > 1. or len(Bonds) == 3:3206 if vol < 0.:3207 face = [face[0],face[2],face[1]]3208 face = np.array(face)3209 if not np.array([np.array(nl.det(face-bond))+0.0001 < 0 for bond in Bonds]).any():3210 norm = np.cross(face[1]-face[0],face[2]-face[0])3211 norm /= np.sqrt(np.sum(norm**2))3212 Faces.append([face,norm])3213 atomData[i][-1] = Faces3214 3215 3216 def DrawAtomsDelete(event): 3216 3217 indx = drawAtoms.GetSelectedRows() … … 3227 3228 3228 3229 def OnReloadDrawAtoms(event): 3229 data['Drawing']['Atoms'] = [] 3230 atomData = data['Atoms'] 3231 cx,ct,cs,ci = data['General']['AtomPtrs'] 3232 for atom in atomData: 3233 ID = atom[ci+8] 3234 DrawAtomsReplaceByID(data['Drawing'],ci+8,atom,ID) 3230 3235 UpdateDrawAtoms() 3231 3236 drawAtoms.ClearSelection() … … 3235 3240 def DrawAtomsDeleteByIDs(IDs): 3236 3241 atomData = data['Drawing']['Atoms'] 3237 indx = G2mth.FindAtomIndexByIDs(atomData,IDs) 3242 loc = data['Drawing']['atomPtrs'][3]+8 3243 indx = G2mth.FindAtomIndexByIDs(atomData,loc,IDs) 3238 3244 indx.reverse() 3239 3245 for ind in indx: … … 3249 3255 elif colName == 'I/A': 3250 3256 col = cs 3251 indx = G2mth.FindAtomIndexByIDs(atomData, IDs)3257 indx = G2mth.FindAtomIndexByIDs(atomData,ci+8,IDs) 3252 3258 for ind in indx: 3253 3259 atomData[ind][col] = value … … 3316 3322 atom = atomDData[i] 3317 3323 xyz.append([i,]+atom[cn:cn+2]+atom[cx:cx+4]) #also gets Sym Op 3318 id = G2mth.FindAtomIndexByIDs(atomData, [atom[cid],],False)[0]3324 id = G2mth.FindAtomIndexByIDs(atomData,cid,[atom[cid],],False)[0] 3319 3325 Oxyz.append([id,]+atomData[id][cx+1:cx+4]) 3320 3326 DATData['Datoms'] = xyz … … 3502 3508 def OnShowHyd(event): 3503 3509 drawingData['showHydrogen'] = showHydrogen.GetValue() 3504 FindBondsDraw( )3510 FindBondsDraw(data) 3505 3511 G2plt.PlotStructure(G2frame,data) 3506 3512 3507 3513 def OnShowRB(event): 3508 3514 drawingData['showRigidBodies'] = showRB.GetValue() 3509 FindBondsDraw( )3515 FindBondsDraw(data) 3510 3516 G2plt.PlotStructure(G2frame,data) 3511 3517 … … 3614 3620 drawingData['radiusFactor'] = value 3615 3621 radFactor.SetValue("%.2f"%(value)) 3616 FindBondsDraw( )3622 FindBondsDraw(data) 3617 3623 G2plt.PlotStructure(G2frame,data) 3618 3624 -
trunk/GSASIIplot.py
r1944 r1951 4227 4227 SSGData = generalData['SSGData'] 4228 4228 Mydir = generalData['Mydir'] 4229 Super = generalData.get('Super',0) 4229 4230 atomData = data['Atoms'] 4230 4231 mapPeaks = [] … … 4335 4336 4336 4337 def OnKey(event): #on key UP!! 4338 keyBox = False 4337 4339 try: 4338 4340 keyCode = event.GetKeyCode() … … 4341 4343 key = chr(keyCode) 4342 4344 except AttributeError: #if from OnKeyBox above 4345 keyBox = True 4343 4346 key = str(event.key).upper() 4344 4347 indx = drawingData['selectedAtoms'] … … 4409 4412 SetMapPeaksText(mapPeaks) 4410 4413 elif key in ['+','-','=','0'] and generalData['Type'] in ['modulated','magnetic']: 4414 if keyBox: 4415 OnKeyPressed(event) 4416 Draw('key') 4417 4418 def OnKeyPressed(event): #On key down for repeating operation - used to change tau... 4419 try: 4420 keyCode = event.GetKeyCode() 4421 if keyCode > 255: 4422 keyCode = 0 4423 key = chr(keyCode) 4424 except AttributeError: #if from OnKeyBox above 4425 key = str(event.key).upper() 4426 if key in ['+','-','=','0'] and generalData['Type'] in ['modulated','magnetic']: 4411 4427 if key == '0': 4412 4428 G2frame.tau = 0. … … 4416 4432 G2frame.tau -= 0.05 4417 4433 G2frame.tau %= 1. #force 0-1 range 4418 Draw('key') 4434 G2frame.G2plotNB.status.SetStatusText('Modulation tau = %.2f'%(G2frame.tau),1) 4435 data['Drawing']['Atoms'] = G2mth.ApplyModulation(data,G2frame.tau) #modifies drawing atom array! 4436 SetDrawAtomsText(data['Drawing']['Atoms']) 4437 G2phG.FindBondsDraw(data) #rebuild bonds & polygons 4438 Draw('key') 4419 4439 4420 4440 def GetTruePosition(xy,Add=False): … … 4560 4580 panel[names.index('grid window')].Refresh() 4561 4581 4582 def SetDrawAtomsText(drawAtoms): 4583 page = getSelection() 4584 if page: 4585 if G2frame.dataDisplay.GetPageText(page) == 'Draw Atoms': 4586 table = G2frame.atomTable.GetData() 4587 for i,atom in enumerate(drawAtoms): 4588 table[i][2:5] = atom[2:5] 4589 G2frame.atomTable.SetData(table) 4590 panel = G2frame.dataDisplay.GetPage(page).GetChildren() 4591 names = [child.GetName() for child in panel] 4592 try: 4593 panel[names.index('GridWindow')].Refresh() 4594 except ValueError: #different wx versions! 4595 panel[names.index('grid window')].Refresh() 4596 4562 4597 def ClearSelectedAtoms(): 4563 4598 page = getSelection() … … 4980 5015 VP = np.array(drawingData['viewPoint'][0])-np.array([.5,.5,.5]) 4981 5016 contLevel = drawingData['contourLevel']*mapData['rhoMax'] 4982 if 'delt-F' in mapData['MapType'] or 'N' in mapData ['Type']:5017 if 'delt-F' in mapData['MapType'] or 'N' in mapData.get('Type',''): 4983 5018 rho = ma.array(mapData['rho'],mask=(np.abs(mapData['rho'])<contLevel)) 4984 5019 else: … … 5214 5249 Page.canvas.Bind(wx.EVT_MIDDLE_DOWN, OnMouseDown) 5215 5250 Page.canvas.Bind(wx.EVT_KEY_UP, OnKey) 5251 Page.canvas.Bind(wx.EVT_KEY_DOWN,OnKeyPressed) 5216 5252 Page.canvas.Bind(wx.EVT_MOTION, OnMouseMove) 5217 5253 Page.canvas.Bind(wx.EVT_SIZE, OnSize) -
trunk/GSASIIspc.py
r1950 r1951 1061 1061 :returns: XYZ - numpy array of new coordinates now 0 or greater and less than 1 1062 1062 ''' 1063 XYZ = np.zeros(3) 1064 for i,x in enumerate(xyz): 1065 XYZ[i] = (x-int(x))%1.0 1066 return XYZ 1063 XYZ = np.array([(x-int(x))%1.0 for x in xyz]) 1064 cell = np.asarray(np.rint(xyz-XYZ),dtype=np.int32) 1065 return XYZ,cell 1067 1066 1068 1067 def Opposite(XYZ,toler=0.0002): … … 1074 1073 :param toler: unit cell fraction tolerance making opposite 1075 1074 :returns: 1076 XYZ: array of opposite positions;always contains XYZ1075 XYZ: dict of opposite positions; key=unit cell & always contains XYZ 1077 1076 ''' 1078 1077 perm3 = [[1,1,1],[0,1,1],[1,0,1],[1,1,0],[1,0,0],[0,1,0],[0,0,1],[0,0,0]] 1079 1078 TB = np.where(abs(XYZ-1)<toler,-1,0)+np.where(abs(XYZ)<toler,1,0) 1080 1079 perm = TB*perm3 1081 cperm = ['%d %d%d'%(i,j,k) for i,j,k in perm]1080 cperm = ['%d,%d,%d'%(i,j,k) for i,j,k in perm] 1082 1081 D = dict(zip(cperm,perm)) 1083 new = []1082 new = {} 1084 1083 for key in D: 1085 new .append(np.array(D[key])+np.array(XYZ))1084 new[key] = np.array(D[key])+np.array(XYZ) 1086 1085 return new 1087 1086 … … 1111 1110 Cell = [] 1112 1111 X = np.array(XYZ) 1112 celli = np.zeros(3) 1113 1113 if Move: 1114 X = MoveToUnitCell(X)1114 X,celli = MoveToUnitCell(X) 1115 1115 for ic,cen in enumerate(SGData['SGCen']): 1116 1116 C = np.array(cen) … … 1126 1126 XT = -XT 1127 1127 XT += C 1128 cell = np.zeros(3) 1129 cellj = np.zeros(3) 1128 1130 if Move: 1129 newX = MoveToUnitCell(XT)1131 newX,cellj = MoveToUnitCell(XT) 1130 1132 else: 1131 1133 newX = XT 1132 cell = np.asarray(np.rint(newX-XT),dtype=np.int32)1134 cell += (celli+cellj) 1133 1135 if All: 1134 1136 if np.allclose(newX,X,atol=0.0002): … … 2411 2413 else: 2412 2414 cellA = np.zeros(3) 2413 newX = (1-2*iC)*(Cen+np.inner(M,X)+T)+cellA2415 newX = Cen+(1-2*iC)*(np.inner(M,X)+T)+cellA 2414 2416 if len(Uij): 2415 2417 U = Uij2U(Uij) … … 3442 3444 for cen in spc['SGCen']: 3443 3445 noff = off + cen 3444 noff = MoveToUnitCell(noff) 3446 noff = MoveToUnitCell(noff)[0] 3445 3447 mult = tuple((op*inv).ravel().tolist()) 3446 3448 if debug: print "\n%s: %s + %s" % (spcname,mult,noff) … … 3452 3454 # check the translation 3453 3455 reftrans = list(refop[-3:]) 3454 reftrans = MoveToUnitCell(reftrans) 3456 reftrans = MoveToUnitCell(reftrans)[0] 3455 3457 if all(abs(noff - reftrans) < 1.e-5): 3456 3458 cctbx.remove(refop)
Note: See TracChangeset
for help on using the changeset viewer.