Changeset 3194
- Timestamp:
- Dec 15, 2017 1:19:06 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CifFile/CifFile.py
r3137 r3194 2817 2817 return lambda a:a #can't do anything numeric 2818 2818 2819 def convert_list_values(structure,dimension):2820 """Convert the values according to the element2821 structure given in [[structure]]"""2822 if isinstance(structure,(unicode,str)): #simple repetition2823 func_def = "element_convert = convert_single_value('%s')" % structure2824 else:2825 func_def = "def element_convert(element):\n"2826 func_def += " final_val = []\n"2827 for pos_no in range(len(structure)):2828 func_def += " final_val.append("2829 type_spec = structure[pos_no]2830 if type_spec == 'Real':2831 cf = "float_with_esd("2832 elif type_spec in ('Count','Integer','Index','Binary','Hexadecimal','Octal'):2833 cf = 'int('2834 elif type_spec == 'Complex':2835 cf = 'complex('2836 elif type_spec == 'Imag':2837 cf = 'complex(0,'2838 elif type_spec in ('Code','Name','Tag'):2839 cf = '('2840 else: cf = ''2841 func_def += cf2842 func_def += "element[%d]" % pos_no2843 if "(" in cf: func_def +=")"2844 if type_spec in ('Code','Name','Tag'):2845 func_def +=".lower()"2846 func_def +=")\n" # close append2847 func_def += " return final_val\n"2848 print(func_def)2849 exec(func_def, globals()) #(re)defines element_convert in global namespace2850 if len(dimension)> 0 and int(dimension[0]) != 1:2851 return lambda a: list(map(element_convert,a))2852 else: return element_convert2853 2854 def convert_matrix_values(valtype):2855 """Convert a dREL String or Float valued List structure to a numpy matrix structure"""2856 # first convert to numpy array, then let numpy do the work2857 try: import numpy2858 except:2859 return lambda a:a #cannot do it2860 func_def = "def matrix_convert(a):\n"2861 func_def += " import numpy\n"2862 func_def += " p = numpy.array(a)\n"2863 if valtype == 'Real':2864 func_def+= " return p.astype('float')\n"2865 elif valtype == 'Integer':2866 func_def +=" return p.astype('int')\n"2867 elif valtype == 'Complex':2868 func_def +=" return p.astype('complex')\n"2869 else:2870 raise ValueError('Unknown matrix value type')2871 exec(func_def,globals()) #matrix convert is defined2872 return matrix_convert2819 #def convert_list_values(structure,dimension): 2820 # """Convert the values according to the element 2821 # structure given in [[structure]]""" 2822 # if isinstance(structure,(unicode,str)): #simple repetition 2823 # func_def = "element_convert = convert_single_value('%s')" % structure 2824 # else: 2825 # func_def = "def element_convert(element):\n" 2826 # func_def += " final_val = []\n" 2827 # for pos_no in range(len(structure)): 2828 # func_def += " final_val.append(" 2829 # type_spec = structure[pos_no] 2830 # if type_spec == 'Real': 2831 # cf = "float_with_esd(" 2832 # elif type_spec in ('Count','Integer','Index','Binary','Hexadecimal','Octal'): 2833 # cf = 'int(' 2834 # elif type_spec == 'Complex': 2835 # cf = 'complex(' 2836 # elif type_spec == 'Imag': 2837 # cf = 'complex(0,' 2838 # elif type_spec in ('Code','Name','Tag'): 2839 # cf = '(' 2840 # else: cf = '' 2841 # func_def += cf 2842 # func_def += "element[%d]" % pos_no 2843 # if "(" in cf: func_def +=")" 2844 # if type_spec in ('Code','Name','Tag'): 2845 # func_def +=".lower()" 2846 # func_def +=")\n" # close append 2847 # func_def += " return final_val\n" 2848 # print(func_def) 2849 # exec(func_def, globals()) #(re)defines element_convert in global namespace 2850 # if len(dimension)> 0 and int(dimension[0]) != 1: 2851 # return lambda a: list(map(element_convert,a)) 2852 # else: return element_convert 2853 # 2854 #def convert_matrix_values(valtype): 2855 # """Convert a dREL String or Float valued List structure to a numpy matrix structure""" 2856 # # first convert to numpy array, then let numpy do the work 2857 # try: import numpy 2858 # except: 2859 # return lambda a:a #cannot do it 2860 # func_def = "def matrix_convert(a):\n" 2861 # func_def += " import numpy\n" 2862 # func_def += " p = numpy.array(a)\n" 2863 # if valtype == 'Real': 2864 # func_def+= " return p.astype('float')\n" 2865 # elif valtype == 'Integer': 2866 # func_def +=" return p.astype('int')\n" 2867 # elif valtype == 'Complex': 2868 # func_def +=" return p.astype('complex')\n" 2869 # else: 2870 # raise ValueError('Unknown matrix value type') 2871 # exec(func_def,globals()) #matrix convert is defined 2872 # return matrix_convert 2873 2873 2874 2874 def interpret_structure(struc_spec): -
trunk/GSASIIphsGUI.py
r3171 r3194 2455 2455 ci = colLabels.index('I/A') 2456 2456 DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[r],ID) 2457 G2plt.PlotStructure(G2frame,data) 2457 2458 wx.CallAfter(Paint) 2458 2459 … … 2478 2479 if 'Atoms' in data['Drawing']: 2479 2480 DrawAtomsReplaceByID(data['Drawing'],ci+8,atomData[r],ID) 2481 G2plt.PlotStructure(G2frame,data) 2480 2482 SetupGeneral() 2481 2483 else: … … 2612 2614 SytSym,Mul,Nop,dupDir = G2spc.SytSym(atomData[row][colX:colX+3],SGData) 2613 2615 CSI = G2spc.GetCSpqinel(SytSym,SpnFlp,dupDir) 2614 # print SytSym,Nop,SpnFlp[Nop],CSI,dupDir 2616 print (SytSym,Nop,SpnFlp[Nop],CSI,dupDir) 2615 2617 for i in range(3): 2616 2618 ci = i+colM … … 2932 2934 'L','K','M','F','P','S','T','W','Y','V','M',' ',' ',' '] 2933 2935 generalData = data['General'] 2936 Amat,Bmat = G2lat.cell2AB(generalData['Cell'][1:7]) 2934 2937 SGData = generalData['SGData'] 2935 2938 if generalData['Type'] in ['nuclear','faulted',]: … … 2947 2950 ct,cs = [1,8] #type & color 2948 2951 elif generalData['Type'] == 'magnetic': 2949 atomInfo = [atom[:2]+atom[3:6]+atom[7:10]+['1',]+['vdW balls',]+ 2950 ['',]+[[255,255,255],]+atom[12:]+[[],[]]][0] 2952 if oldatom: 2953 opr = oldatom[8] 2954 mom = np.inner(np.array(atom[7:10]),Bmat) 2955 Mom = np.inner(G2spc.ApplyStringOpsMom(opr,SGData,mom),Amat) 2956 atomInfo = oldatom[:5]+list(Mom)+oldatom[8:] 2957 else: 2958 atomInfo = [atom[:2]+atom[3:6]+atom[7:10]+['1',]+['vdW balls',]+ 2959 ['',]+[[255,255,255],]+atom[12:]+[[],[]]][0] 2951 2960 ct,cs = [1,11] #type & color 2952 2961 elif generalData['Type'] == 'macromolecular': … … 5390 5399 SGData = generalData['SGData'] 5391 5400 SpnFlp = SGData.get('SpnFlp',[]) 5392 # MagMom = SGData.get('MagMom',[])5393 5401 wx.BeginBusyCursor() 5394 5402 try: -
trunk/GSASIIspc.py
r3191 r3194 931 931 return ' '.join(magSym) 932 932 933 def MagSGSpin(MagSym,SGData): 934 print(MagSym) 935 SGLaue = SGData['SGLaue'] 936 SpnFlp = SGData['SGSpin'] 937 GenSym = SGData['GenSym'] 938 SGPtGrp = SGData['SGPtGrp'] 939 magSym = MagSym.split() 940 if SGLaue in ['-1',]: 941 SGData['MagPtGp'] = SGPtGrp 942 if "'" in magSym[1]: 943 SpnFlp[0] = -1 944 SGData['MagPtGp'] += "'" 945 if magSym[0] in ['A','B','C','I'] and SGData['SpGrp'] != 'I 41/a': 946 if SpnFlp[1] < 0: 947 magSym[0] += '(P)' 948 elif SGPtGrp in ['mmm','mm2','m2m','2mm','222']: 949 SGData['MagPtGp'] = '' 950 for i in [0,1,2]: 951 SGData['MagPtGp'] += SGPtGrp[i] 952 if "'" in magSym[i+1]: 953 SpnFlp[i] = -1 954 SGData['MagPtGp'] += "'" 955 if len(GenSym) > 3: 956 if 'F' in magSym[0]: 957 if 'A' in magSym[0]: 958 SpnFlp[3] = 1 959 elif 'B' in magSym[0]: 960 SpnFlp[4] = 1 961 elif 'C' in magSym[0]: 962 SpnFlp[5] = 1 963 elif 'P' in magSym[0]: 964 SpnFlp[3] = -1 965 elif SGLaue == '6/mmm': #ok 966 SGData['MagPtGp'] = '' 967 if len(GenSym) == 2: 968 for i in [0,1]: 969 SGData['MagPtGp'] += SGPtGrp[i] 970 if "'" in magSym[i+2]: 971 SpnFlp[i] = -1 972 SGData['MagPtGp'] += "'" 973 else: 974 for i in [0,1,2]: 975 SGData['MagPtGp'] += SGPtGrp[i] 976 if "'" in magSym[i+1]: 977 SpnFlp[i] = -1 978 SGData['MagPtGp'] += "'" 979 elif SGLaue == '4/mmm': 980 if len(GenSym) == 2: 981 for i in [0,1]: 982 SGData['MagPtGp'] += SGPtGrp[i] 983 if "'" in magSym[i+2]: 984 SpnFlp[i] = -1 985 SGData['MagPtGp'] += "'" 986 # else: 987 # if '/' in magSym[1]: #P 4/m m m, etc. 988 # sym = magSym[1].split('/') 989 # Ptsym = ['4','m'] 990 # magPtGp = ['','m','m'] 991 # for i in [0,1,2]: 992 # if SpnFlp[i] < 0: 993 # if i: 994 # magSym[i+1] += "'" 995 # magPtGp[i] += "'" 996 # else: 997 # sym[1] += "'" 998 # Ptsym[1] += "'" 999 # if SpnFlp[1]*SpnFlp[2] < 0: 1000 # sym[0] += "'" 1001 # Ptsym[0] += "'" 1002 # magSym[1] = '/'.join(sym) 1003 # magPtGp[0] = '/'.join(Ptsym) 1004 # if SpnFlp[3] < 0: 1005 # magSym[0] += '(P)' 1006 # else: 1007 # for i in [0,1]: 1008 # if SpnFlp[i] < 0: 1009 # magSym[i+2] += "'" 1010 # if SpnFlp[0]*SpnFlp[1] < 0: 1011 # magSym[1] += "'" 1012 # if SpnFlp[2] < 0: 1013 # magSym[0] += '(P)' 1014 # SGData['MagPtGp'] = ''.join(magPtGp) 1015 elif SGLaue in ['2/m','4/m','6/m']: #all ok 1016 Uniq = {'a':1,'b':2,'c':3,'':1} 1017 SGData['MagPtGp'] = '' 1018 Ptsym = SGLaue.split('/') 1019 if len(GenSym) == 3: 1020 MPtSym = magSym[1].split('/') 1021 for i in [0,1,2]: 1022 if i == 2 and 'P' in magSym[0]: 1023 SpnFlp[i] = -1 1024 elif i < 2: 1025 SGData['MagPtGp'] += Ptsym[i] 1026 if "'" in MPtSym[i]: 1027 SpnFlp[i] = -1 1028 SGData['MagPtGp'] += "'" 1029 else: 1030 for i in range(len(GenSym)): 1031 if i and magSym[0] in ['A','B','C','I'] and SGData['SpGrp'] != 'I 41/a': 1032 if 'P' in magSym[0]: 1033 SpnFlp[i] = -1 1034 else: 1035 SGData['MagPtGp'] += Ptsym[i] 1036 if "'" in magSym[i+1]: 1037 SpnFlp[i] = -1 1038 SGData['MagPtGp'] += "'" 1039 # elif SGLaue in ['3','3m1','31m']: #ok 1040 ## GSASIIpath.IPyBreak() 1041 # Ptsym = list(SGLaue) 1042 # if len(GenSym) == 1: #all ok 1043 # id = 2 1044 # if (len(magSym) == 4) and (magSym[2] == '1'): 1045 # id = 3 1046 # if '3' in GenSym[0]: 1047 # id = 1 1048 # magSym[id].strip("'") 1049 # if SpnFlp[0] < 0: 1050 # magSym[id] += "'" 1051 # Ptsym[id-1] += "'" 1052 # elif len(GenSym) == 2: 1053 # if 'R' in GenSym[1]: 1054 # magSym[-1].strip("'") 1055 # if SpnFlp[0] < 0: 1056 # magSym[-1] += "'" 1057 # Ptsym[-1] += "'" 1058 # else: 1059 # i,j = [1,2] 1060 # if magSym[2] == '1': 1061 # i,j = [1,3] 1062 # magSym[i].strip("'") 1063 # Ptsym[i-1].strip("'") 1064 # magSym[j].strip("'") 1065 # Ptsym[j-1].strip("'") 1066 # if SpnFlp[:2] == [1,-1]: 1067 # magSym[i] += "'" 1068 # Ptsym[i-1] += "'" 1069 # elif SpnFlp[:2] == [-1,-1]: 1070 # magSym[j] += "'" 1071 # Ptsym[j-1] += "'" 1072 # elif SpnFlp[:2] == [-1,1]: 1073 # magSym[i] += "'" 1074 # Ptsym[i-1] += "'" 1075 # magSym[j] += "'" 1076 # Ptsym[j-1] += "'" 1077 # else: 1078 # if 'c' not in magSym[2]: 1079 # i,j = [1,2] 1080 # magSym[i].strip("'") 1081 # Ptsym[i-1].strip("'") 1082 # magSym[j].strip("'") 1083 # Ptsym[j-1].strip("'") 1084 # if SpnFlp[:2] == [1,-1]: 1085 # magSym[i] += "'" 1086 # Ptsym[i-1] += "'" 1087 # elif SpnFlp[:2] == [-1,-1]: 1088 # magSym[j] += "'" 1089 # Ptsym[j-1] += "'" 1090 # elif SpnFlp[:2] == [-1,1]: 1091 # magSym[i] += "'" 1092 # Ptsym[i-1] += "'" 1093 # magSym[j] += "'" 1094 # Ptsym[j-1] += "'" 1095 # SGData['MagPtGp'] = ''.join(Ptsym) 1096 # elif SGData['SGPtGrp'] == '23' and len(magSym): 1097 # SGData['MagPtGp'] = '23' 1098 # if SpnFlp[0] < 0: 1099 # magSym[0] += '(P)' 1100 # elif SGData['SGPtGrp'] == 'm3': 1101 # SGData['MagPtGp'] = "m3" 1102 # if SpnFlp[0] < 0: 1103 # magSym[1] += "'" 1104 # magSym[2] += "'" 1105 # SGData['MagPtGp'] = "m'3'" 1106 # if SpnFlp[1] < 0: 1107 # magSym[0] += '(P)' 1108 # if not 'm' in magSym[1]: #only Ia3 1109 # magSym[1].strip("'") 1110 # SGData['MagPtGp'] = "m3'" 1111 # elif SGData['SGPtGrp'] in ['432','-43m']: 1112 # Ptsym = SGData['SGPtGrp'].split('3') 1113 # if SpnFlp[0] < 0: 1114 # magSym[1] += "'" 1115 # Ptsym[0] += "'" 1116 # magSym[3] += "'" 1117 # Ptsym[1] += "'" 1118 # if SpnFlp[1] < 0: 1119 # magSym[0] += '(P)' 1120 # SGData['MagPtGp'] = '3'.join(Ptsym) 1121 # elif SGData['SGPtGrp'] == 'm-3m': 1122 # Ptsym = ['m','3','m'] 1123 # if SpnFlp[:2] == [-1,1]: 1124 # magSym[1] += "'" 1125 # Ptsym[0] += "'" 1126 # magSym[2] += "'" 1127 # Ptsym[1] += "'" 1128 # elif SpnFlp[:2] == [1,-1]: 1129 # magSym[3] += "'" 1130 # Ptsym[2] += "'" 1131 # elif SpnFlp[:2] == [-1,-1]: 1132 # magSym[1] += "'" 1133 # Ptsym[0] += "'" 1134 # magSym[2] += "'" 1135 # Ptsym[1] += "'" 1136 # magSym[3] += "'" 1137 # Ptsym[2] += "'" 1138 # if SpnFlp[2] < 0: 1139 # magSym[0] += '(P)' 1140 # SGData['MagPtGp'] = ''.join(Ptsym) 1141 print( SpnFlp) 1142 return SpnFlp 1143 933 1144 def GenMagOps(SGData): 934 1145 FlpSpn = SGData['SGSpin'] … … 2046 2257 CSI = [[1,2,3],[1.0,1.0,1.0]] 2047 2258 for opr in dupDir: 2048 if '-1' in siteSym and SpnFlp[len(SpnFlp)//2 -1] < 0:2259 if '-1' in siteSym and SpnFlp[len(SpnFlp)//2] < 0: 2049 2260 return [[0,0,0],[0.,0.,0.]] 2050 2261 indx = GetNXUPQsym(opr) … … 2774 2985 else: 2775 2986 return newX 2987 2988 def ApplyStringOpsMom(A,SGData,Mom): 2989 'Needs a doc string' 2990 SGOps = SGData['SGOps'] 2991 Ax = A.split('+') 2992 Ax[0] = int(Ax[0]) 2993 Ax[0] = abs(Ax[0]) 2994 nA = Ax[0]%100-1 2995 M,T = SGOps[nA] 2996 if len(Ax)>1: 2997 cellA = Ax[1].split(',') 2998 cellA = np.array([int(a) for a in cellA]) 2999 else: 3000 cellA = np.zeros(3) 3001 newMom = -(np.inner(Mom,M).T)*SGData['SpnFlp'][nA-1]*nl.det(M) #why -? 3002 return newMom 2776 3003 2777 3004 def StringOpsProd(A,B,SGData): -
trunk/imports/G2img_1TIF.py
r3176 r3194 210 210 File.seek(4096) 211 211 print ('Read Pilatus tiff file: '+filename) 212 image = ar.array('I',File.read(4*Npix)) 213 image = np.array(np.asarray(image),dtype=np.int32) 212 image = np.array(np.frombuffer(File.read(4*Npix),dtype=np.int32),dtype=np.int32) 214 213 else: 215 214 if IFD[258][2][0] == 16: … … 224 223 File.seek(8) 225 224 image = np.array(np.frombuffer(File.read(2*Npix),dtype=np.uint16),dtype=np.int32) 226 # image = np.fromfile(File,dtype=np.int16,count=2*Npix)[:Npix]227 # image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)228 225 elif IFD[258][2][0] == 32: 229 226 # includes CHESS & Pilatus files from Area Detector … … 261 258 print ('Read DND SAX/WAX-detector tiff file: '+filename) 262 259 image = np.array(np.frombuffer(File.read(2*Npix),dtype=np.uint16),dtype=np.int32) 263 # image = np.fromfile(File,dtype=np.int16,count=2*Npix)[:Npix]264 # image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)265 260 elif sizexy == [1536,1536]: 266 261 tifType = 'APS Gold' … … 269 264 print ('Read Gold tiff file:'+filename) 270 265 image = np.array(np.frombuffer(File.read(2*Npix),dtype=np.uint16),dtype=np.int32) 271 # image = np.fromfile(File,dtype=np.int16,count=2*Npix)[:Npix]272 # image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)273 266 elif sizexy == [2048,2048] or sizexy == [1024,1024] or sizexy == [3072,3072]: 274 267 if IFD[273][2][0] == 8: … … 280 273 if dataType == 5: 281 274 image = np.array(np.frombuffer(File.read(4*Npix),dtype=np.float32),dtype=np.int32) #fastest 282 # image = np.fromfile(File,dtype=np.float32,count=4*Npix)[:Npix]283 # image = np.array(ar.array('f',File.read(4*Npix)),dtype=np.int32)284 275 else: 285 276 image = np.array(np.frombuffer(File.read(4*Npix),dtype=np.int32),dtype=np.int32) 286 # image = np.fromfile(File,dtype=np.int,count=4*Npix)[:Npix]287 # image = np.array(ar.array('I',File.read(4*Npix)),dtype=np.int32)288 277 elif IFD[258][2][0] == 16: 289 278 tifType = 'MedOptics D1' … … 292 281 print ('Read MedOptics D1 tiff file: '+filename) 293 282 image = np.array(np.frombuffer(File.read(2*Npix),dtype=np.uint16),dtype=np.int32) 294 # image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)295 283 296 284 elif IFD[273][2][0] == 4096: … … 304 292 print ('Read MAR CCD tiff file: '+filename) 305 293 image = np.array(np.frombuffer(File.read(2*Npix),dtype=np.uint16),dtype=np.int32) 306 # image = np.fromfile(File,dtype=np.int16,count=2*Npix)[:Npix]307 # image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)308 294 elif IFD[273][2][0] == 512: 309 295 tifType = '11-ID-C' … … 312 298 print ('Read 11-ID-C tiff file: '+filename) 313 299 image = np.array(np.frombuffer(File.read(2*Npix),dtype=np.uint16),dtype=np.int32) 314 # image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)315 300 316 301 elif sizexy == [4096,4096]: -
trunk/imports/G2img_CBF.py
r3144 r3194 54 54 File = open(filename,'rb') 55 55 sizexy = [0,0] 56 pixSize = [1 54,154] #Pixium4700?56 pixSize = [172,172] #Pixium4700? 57 57 cent = [0,0] 58 58 wave = 1.54187 #default <CuKa> -
trunk/imports/G2phase_CIF.py
r3192 r3194 208 208 self.Phase['General']['SGData'] = SGData 209 209 if magnetic: 210 self.MPhase['General']['SGData'] = SGData 210 self.MPhase['General']['SGData'] = SGData 211 GenSym,GenFlg = G2spc.GetGenSym(SGData) 212 self.MPhase['General']['SGData']['GenSym'] = GenSym 213 self.MPhase['General']['SGData']['GenFlg'] = GenFlg 214 self.MPhase['General']['SGData']['SGSpin'] = G2spc.MagSGSpin(MSpGrp,SGData) 211 215 if Super: 212 216 E,SSGData = G2spc.SSpcGroup(SGData,SuperSg)
Note: See TracChangeset
for help on using the changeset viewer.