Changeset 1022
- Timestamp:
- Aug 7, 2013 11:57:15 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIphsGUI.py
r1020 r1022 1237 1237 FillAtomsGrid(Atoms) 1238 1238 event.StopPropagation() 1239 G2plt.PlotStructure(G2frame,data) 1239 if data['Drawing']: 1240 G2plt.PlotStructure(G2frame,data) 1240 1241 1241 1242 def OnAtomViewAdd(event): -
trunk/exports/G2cif.py
r1014 r1022 18 18 import os.path 19 19 import numpy as np 20 import wx 20 21 import GSASIIpath 21 22 GSASIIpath.SetVersionNumber("$Revision: 1006 $") … … 27 28 #import GSASIImapvars as G2mv 28 29 import GSASIImath as G2mth 29 reload(G2mth)30 #reload(G2mth) 30 31 import GSASIIlattice as G2lat 31 32 import GSASIIspc as G2spc 32 33 #reload(G2spc) 33 34 DEBUG = True #True to skip printing of reflection/powder profile lists 34 import GSASIIphsGUI as G2pg 35 #reload(G2pg) 36 import GSASIIstrMain as G2stMn 37 38 DEBUG = False 39 #DEBUG = True #True to skip printing of reflection/powder profile lists 35 40 36 41 def getCallerDocString(): # for development … … 48 53 G2frame=G2frame, 49 54 formatName = 'full CIF', 50 longFormatName = 'Export project as complete CIF' 55 extension='.cif', 56 longFormatName = 'Export project as CIF' 51 57 ) 52 58 self.author = '' … … 59 65 ''' 60 66 67 def openCIF(filnam): 68 self.fp = open(filnam,'w') 69 70 def closeCIF(): 71 self.fp.close() 72 61 73 def WriteCIFitem(name,value=''): 62 74 if value: 63 75 if "\n" in value or len(value)> 70: 64 if name.strip(): print name65 print '; '+value66 print '; '76 if name.strip(): self.fp.write(name+'\n') 77 self.fp.write('; '+value+'\n') 78 self.fp.write('; '+'\n') 67 79 elif " " in value: 68 80 if len(name)+len(value) > 65: 69 print name,'\n ','"' + str(value) + '"'81 self.fp.write(name + '\n ' + '"' + str(value) + '"'+'\n') 70 82 else: 71 print name,' ','"' + str(value) + '"'83 self.fp.write(name + ' ' + '"' + str(value) + '"'+'\n') 72 84 else: 73 85 if len(name)+len(value) > 65: 74 print name,'\n ',value86 self.fp.write(name+'\n ' + value+'\n') 75 87 else: 76 print name,' ',value88 self.fp.write(name+' ' + value+'\n') 77 89 else: 78 print name90 self.fp.write(name+'\n') 79 91 80 92 def WriteAudit(): … … 237 249 238 250 TODO: this needs to be expanded to show the diffuse peak and 239 Debye term information as well. 251 Debye term information as well. (Bob) 240 252 241 253 :returns: the text description (str) … … 625 637 phasedict = self.Phases[phasenam] # pointer to current phase info 626 638 Atoms = phasedict['Atoms'] 639 generalData = phasedict['General'] 627 640 cx,ct,cs,cia = phasedict['General']['AtomPtrs'] 641 cn = ct-1 628 642 fpfx = str(phasedict['pId'])+'::Afrac:' 629 643 cfrac = cx+3 644 DisAglData = {} 645 DisAglCtls = {} 646 xyz = [] 647 for i,atom in enumerate(Atoms): 648 xyz.append([i,]+atom[cn:cn+2]+atom[cx:cx+3]) 649 if 'DisAglCtls' in generalData: 650 DisAglCtls = generalData['DisAglCtls'] 651 else: 652 dlg = G2gd.DisAglDialog(self.G2frame,DisAglCtls,generalData) 653 if dlg.ShowModal() == wx.ID_OK: 654 DisAglCtls = dlg.GetData() 655 generalData['DisAglCtls'] = DisAglCtls 656 else: 657 dlg.Destroy() 658 return 659 dlg.Destroy() 660 DisAglData['OrigAtoms'] = xyz 661 DisAglData['TargAtoms'] = xyz 662 DisAglData['SGData'] = generalData['SGData'] 663 SymOpList,offsetList,symOpList,G2oprList = G2spc.AllOps( 664 generalData['SGData']) 665 666 # print len(SymOpList),len(offsetList),len(symOpList),len(G2oprList) 667 # raise Exception 668 669 670 DisAglData['Cell'] = generalData['Cell'][1:] #+ volume 671 if 'pId' in phasedict: 672 DisAglData['pId'] = phasedict['pId'] 673 DisAglData['covData'] = self.OverallParms['Covariance'] 674 try: 675 G2stMn.DistAngle(DisAglCtls,DisAglData) 676 except KeyError: # inside DistAngle for missing atom types in DisAglCtls 677 print '**** ERROR - try again but do "Reset" to fill in missing atom types ****' 678 679 680 raise Exception 681 630 682 # loop over interatomic distances for this phase 631 683 WriteCIFitem('\n# MOLECULAR GEOMETRY') … … 729 781 if not self.quickmode: # report distances and angles 730 782 WriteDistances(phasenam,SymOpList,offsetList,symOpList,G2oprList) 783 784 def Yfmt(ndec,val): 785 'Format intensity values' 786 out = ("{:."+str(ndec)+"f}").format(val) 787 out = out.rstrip('0') # strip zeros to right of decimal 788 return out.rstrip('.') # and decimal place when not needed 731 789 732 790 def WritePowderData(histlbl): 733 text = '?'734 791 histblk = self.Histograms[histlbl] 735 792 inst = histblk['Instrument Parameters'][0] 736 793 hId = histblk['hId'] 737 794 pfx = ':' + str(hId) + ':' 738 print 'TODO: powder here data for',histblk["Sample Parameters"]['InstrName']739 # see wrpowdhist.for & wrreflist.for740 795 741 796 if 'Lam1' in inst: … … 833 888 WriteCIFitem('_pd_proc_ls_background_function',FormatBackground(histblk['Background'],histblk['hId'])) 834 889 890 # TODO: this will need help from Bob 835 891 #WriteCIFitem('_exptl_absorpt_process_details','?') 836 892 #WriteCIFitem('_exptl_absorpt_correction_T_min','?') … … 863 919 '\n\t' + refprx + 'index_k' + 864 920 '\n\t' + refprx + 'index_l' + 865 # '\n\t_pd_refln_wavelength_id' +866 # '\n\t' + refprx + 'status' +867 921 '\n\t' + refprx + 'F_squared_meas' + 868 # '\n\t' + refprx + 'F_squared_sigma' +869 922 '\n\t' + refprx + 'F_squared_calc' + 870 923 '\n\t' + refprx + 'phase_calc' + … … 938 991 if zerolst: zero = zerolst[1] 939 992 zero = self.parmDict.get('Zero',zero) 940 # TODO: Bob is zero added or subtracted?941 993 if zero: 942 994 WriteCIFitem('_pd_proc_2theta_range_min', G2mth.ValEsd(histblk['Data'][0][0]-zero,-0.00009)) … … 955 1007 else: 956 1008 WriteCIFitem('\t_pd_meas_2theta_scan') 957 # at least for now, always report weights. TODO: Should they be multiplied by weights?1009 # at least for now, always report weights. 958 1010 #if countsdata: 959 1011 # WriteCIFitem('\t_pd_meas_counts_total') … … 963 1015 WriteCIFitem('\t_pd_proc_intensity_bkg_calc') 964 1016 WriteCIFitem('\t_pd_proc_ls_weight') 965 # TODO: are data excluded? 1017 maxY = max(histblk['Data'][1].max(),histblk['Data'][3].max()) 1018 if maxY < 0: maxY *= -10 # this should never happen, but... 1019 ndec = max(0,10-int(np.log10(maxY))-1) # 10 sig figs should be enough 1020 maxSU = histblk['Data'][2].max() 1021 if maxSU < 0: maxSU *= -1 # this should never happen, but... 1022 ndecSU = max(0,8-int(np.log10(maxSU))-1) # 8 sig figs should be enough 1023 lowlim,highlim = histblk['Limits'][1] 1024 966 1025 for x,yobs,yw,ycalc,ybkg in zip(histblk['Data'][0], 967 1026 histblk['Data'][1], … … 969 1028 histblk['Data'][3], 970 1029 histblk['Data'][4]): 971 if DEBUG: 972 print 'DEBUG: skip reflection list' 973 break 1030 if lowlim <= x <= highlim: 1031 pass 1032 else: 1033 yw = 0.0 # show the point is not in use 1034 974 1035 if fixedstep: 975 1036 s = "" 976 1037 else: 977 1038 s = PutInCol(G2mth.ValEsd(x-zero,-0.00009),10) 978 s += PutInCol( G2mth.ValEsd(yobs,-0.00009),14)979 s += PutInCol( G2mth.ValEsd(ycalc,-0.00009),14)980 s += PutInCol( G2mth.ValEsd(ybkg,-0.00009),14)981 s += PutInCol( G2mth.ValEsd(yw,-0.000009),14)1039 s += PutInCol(Yfmt(ndec,yobs),12) 1040 s += PutInCol(Yfmt(ndec,ycalc),12) 1041 s += PutInCol(Yfmt(ndec,ybkg),11) 1042 s += PutInCol(Yfmt(ndecSU,yw),9) 982 1043 WriteCIFitem(" "+s) 983 1044 984 1045 def WriteSingleXtalData(histlbl): 985 1046 histblk = self.Histograms[histlbl] 986 print 'TODO: single xtal here data for',histblk["Instrument Parameters"][0]['InstrName']987 988 1047 #refprx = '_refln.' # mm 989 1048 refprx = '_refln_' # normal 990 1049 991 print histblk.keys()992 993 1050 WriteCIFitem('\n# STRUCTURE FACTOR TABLE') 994 1051 WriteCIFitem('loop_' + … … 1040 1097 #============================================================ 1041 1098 # the export process starts here 1042 # alsoload all of the tree into a set of dicts1099 # load all of the tree into a set of dicts 1043 1100 self.loadTree() 1044 #self.dumpTree()1045 1101 # create a dict with refined values and their uncertainties 1046 1102 self.loadParmDict() 1047 # 1048 1049 # get restraint info 1103 1104 # Someday: get restraint & constraint info 1050 1105 #restraintDict = self.OverallParms.get('Restraints',{}) 1051 1106 #for i in self.OverallParms['Constraints']: … … 1053 1108 # for j in self.OverallParms['Constraints'][i]: 1054 1109 # print j 1055 #return1056 1110 1057 1111 self.CIFdate = dt.datetime.strftime(dt.datetime.now(),"%Y-%m-%dT%H:%M") 1058 # count phases, powder and single crystal histograms 1059 self.nphase = len(self.Phases) 1112 # index powder and single crystal histograms 1060 1113 self.powderDict = {} 1061 1114 self.xtalDict = {} … … 1067 1120 self.xtalDict[i] = hist 1068 1121 # is there anything to export? 1069 if self.nphase+ len(self.powderDict) + len(self.xtalDict) == 0:1122 if len(self.Phases) + len(self.powderDict) + len(self.xtalDict) == 0: 1070 1123 self.G2frame.ErrorDialog( 1071 1124 'Empty project', … … 1088 1141 self.quickmode = True 1089 1142 oneblock = True 1090 if self.nphase== 0:1143 if len(self.Phases) == 0: 1091 1144 self.G2frame.ErrorDialog( 1092 1145 'No phase present', 1093 1146 'Cannot create a coordinates CIF with no phases') 1094 1147 return 1095 elif self.nphase> 1: # quick mode: choose one phase1148 elif len(self.Phases) > 1: # quick mode: choose one phase 1096 1149 choices = sorted(self.Phases.keys()) 1097 1150 phasenum = G2gd.ItemSelector(choices,self.G2frame) … … 1099 1152 phasenam = choices[phasenum] 1100 1153 # will this require a multiblock CIF? 1101 elif self.nphase> 1:1154 elif len(self.Phases) > 1: 1102 1155 oneblock = False 1103 1156 elif len(self.powderDict) + len(self.xtalDict) > 1: … … 1173 1226 instnam = histblk["Instrument Parameters"][0]['InstrName'] 1174 1227 break # ignore all but 1st data histogram 1228 if self.quickmode: 1229 fil = self.askSaveFile() 1230 else: 1231 fil = self.defSaveFile() 1232 if not fil: return 1233 openCIF(fil) 1175 1234 #====================================================================== 1176 1235 # Start writing the CIF - single block … … 1230 1289 datablockidDict = {} # save block names here -- N.B. check for conflicts between phase & hist names (unlikely!) 1231 1290 # loop over phase blocks 1232 if self.nphase> 1:1291 if len(self.Phases) > 1: 1233 1292 loopprefix = '' 1234 1293 WriteCIFitem('loop_ _pd_phase_block_id') … … 1320 1379 1321 1380 WriteCIFitem('#--' + 15*'eof--' + '#') 1322 1381 closeCIF()
Note: See TracChangeset
for help on using the changeset viewer.