Changeset 5085
- Timestamp:
- Nov 15, 2021 12:36:53 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exports/G2export_CIF.py
r5081 r5085 742 742 Amat = G2lat.cell2AB(General['Cell'][1:7])[0] 743 743 Atoms = phasedict['Atoms'] 744 cfrac = cx+3 745 fpfx = str(phasedict['pId'])+'::Afrac:' 746 for i,at in enumerate(Atoms): 747 fval = parmDict.get(fpfx+str(i),at[cfrac]) 748 if fval != 0.0: 749 break 750 else: 744 #cfrac = cx+3 745 #fpfx = str(phasedict['pId'])+'::Afrac:' 746 if len(Atoms) == 0: 751 747 WriteCIFitem(fp, '\n# PHASE HAS NO ATOMS!') 752 748 return … … 791 787 792 788 pfx = str(phasedict['pId'])+'::' 789 num = 0 790 # uniquely index the side chains 791 entity_id = {} 792 for i,at in enumerate(Atoms): 793 if at[ct-2] not in entity_id: 794 num += 1 795 entity_id[at[ct-2]] = num 796 793 797 # loop over all atoms 794 798 # naniso = 0 … … 807 811 s += PutInCol(at[ct-2],3) # _asym_id 808 812 s += PutInCol(at[ct-2],3) # _asym_id 809 s += PutInCol( at[ct-4],3) # entity_id810 s += PutInCol( '?',2) # _seq_id811 s += PutInCol( '?',2) # _seq_id813 s += PutInCol(str(entity_id[at[ct-2]]),3) # entity_id 814 s += PutInCol(at[ct-4],2) # _seq_id 815 s += PutInCol(at[ct-4],2) # _seq_id 812 816 s += PutInCol('?',2) # pdbx_PDB_ins_code 813 817 s += PutInCol('?',2) # pdbx_formal_charge 814 818 s += PutInCol('1',2) # pdbx_PDB_model_num 815 819 816 fval = parmDict.get(fpfx+str(i),at[cfrac])817 if fval == 0.0: continue # ignore any atoms that have a occupancy set to 0 (exact)820 # fval = parmDict.get(fpfx+str(i),at[cfrac]) 821 # if fval == 0.0: continue # ignore any atoms that have a occupancy set to 0 (exact) 818 822 # if at[cia] == 'I': 819 823 # adp = 'Uiso ' … … 841 845 sig = -abs(sig) 842 846 s += PutInCol(G2mth.ValEsd(val,sig),dig) 843 844 845 847 # Cartesian coordinates 848 for xyz in np.inner(Amat,at[cx:cx+3]): 849 s += PutInCol(G2mth.ValEsd(xyz,-0.009),8) 846 850 WriteCIFitem(fp, s) 847 851 # save information about rigid bodies … … 1684 1688 #WriteCIFitem(self.fp, '_refine_ls_matrix_type','userblocks') 1685 1689 1690 def WriteOverallMM(mode=None): 1691 '''Write out overall refinement information. 1692 1693 More could be done here, but this is a good start. 1694 ''' 1695 if self.ifPWDR: 1696 WriteCIFitem(self.fp, '_pd_proc_info_datetime', self.CIFdate) 1697 WriteCIFitem(self.fp, '_pd_calc_method', 'Rietveld Refinement') 1698 1699 #WriteCIFitem(self.fp, '_refine.ls_shift_over_su_mean',DAT2) 1700 WriteCIFitem(self.fp, '_computing_structure_refinement','GSAS-II (Toby & Von Dreele, J. Appl. Cryst. 46, 544-549, 2013)') 1701 if self.ifHKLF: 1702 controls = self.OverallParms['Controls'] 1703 try: 1704 if controls['F**2']: 1705 thresh = 'F**2>%.1fu(F**2)'%(controls['UsrReject']['minF/sig']) 1706 else: 1707 thresh = 'F>%.1fu(F)'%(controls['UsrReject']['minF/sig']) 1708 WriteCIFitem(self.fp, '_reflns.threshold_expression', thresh) 1709 except KeyError: 1710 pass 1711 WriteCIFitem(self.fp, '_refine.ls_matrix_type','full') 1712 1713 if mode == 'seq': return 1714 try: 1715 vars = str(len(self.OverallParms['Covariance']['varyList'])) 1716 except: 1717 vars = '?' 1718 WriteCIFitem(self.fp, '_refine.ls_number_parameters',vars) 1719 try: 1720 GOF = G2mth.ValEsd(self.OverallParms['Covariance']['Rvals']['GOF'],-0.009) 1721 except: 1722 GOF = '?' 1723 WriteCIFitem(self.fp, '_refine.ls_goodness_of_fit_all',GOF) 1724 DAT1 = self.OverallParms['Covariance']['Rvals'].get('Max shft/sig',0.0) 1725 if DAT1: 1726 WriteCIFitem(self.fp, '_refine.ls_shift_over_su_max','%.4f'%DAT1) 1727 1728 # get restraint info 1729 # restraintDict = self.OverallParms.get('Restraints',{}) 1730 # for i in self.OverallParms['Constraints']: 1731 # print i 1732 # for j in self.OverallParms['Constraints'][i]: 1733 # print j 1734 #WriteCIFitem(self.fp, '_refine_ls_number_restraints',TEXT) 1735 # other things to consider reporting 1736 # _refine_ls_number_reflns 1737 # _refine_ls_goodness_of_fit_obs 1738 # _refine_ls_wR_factor_obs 1739 # _refine_ls_restrained_S_all 1740 # _refine_ls_restrained_S_obs 1741 1742 # include an overall profile r-factor, if there is more than one powder histogram 1743 R = '%.5f'%(self.OverallParms['Covariance']['Rvals']['Rwp']/100.) 1744 WriteCIFitem(self.fp, '\n# OVERALL WEIGHTED R-FACTOR') 1745 WriteCIFitem(self.fp, '_refine.ls_wR_factor_obs',R) 1746 1686 1747 def writeCIFtemplate(G2dict,tmplate,defaultname=''): 1687 1748 '''Write out the selected or edited CIF template … … 1699 1760 templateDefName = 'template_'+tmplate+'.cif' 1700 1761 if not CIFobj: # copying a template 1762 lbl = 'Standard version' 1701 1763 for pth in [os.getcwd()]+sys.path: 1702 1764 fil = os.path.join(pth,defaultname) … … 1713 1775 fp.close() 1714 1776 elif type(CIFobj) is not list and type(CIFobj) is not tuple: 1777 lbl = 'Saved version' 1715 1778 if not os.path.exists(CIFobj): 1716 1779 print("Error: requested template file has disappeared: "+CIFobj) … … 1720 1783 fp.close() 1721 1784 else: 1785 lbl = 'Project-specific version' 1722 1786 txt = dict2CIF(CIFobj[0],CIFobj[1]).WriteOut() 1723 1787 # remove the PyCifRW header, if present 1724 1788 #if txt.find('PyCifRW') > -1 and txt.find('data_') > -1: 1725 txt = "# GSAS-II edited template follows "+txt[txt.index("data_")+5:] 1789 pre = txt.index("data_") 1790 restofline = txt.index("\n",pre) 1791 name = txt[pre+5:restofline] 1792 txt = "\n# {} of {} template follows{}".format( 1793 lbl, name, txt[restofline:]) 1726 1794 #txt = txt.replace('data_','#') 1727 1795 WriteCIFitem(self.fp, txt) … … 3951 4019 WriteAudit() 3952 4020 writeCIFtemplate(self.OverallParms['Controls'],'publ') # overall (publication) template 3953 WriteOverall() 4021 if MM: 4022 WriteOverallMM() 4023 else: 4024 WriteOverall() 3954 4025 writeCIFtemplate(self.Phases[phasenam]['General'],'phase',phasenam) # write phase template 3955 4026 # report the phase info … … 4217 4288 WriteCIFitem(self.fp, '_pd_block_id', 4218 4289 str(self.CIFdate) + "|" + str(self.CIFname) + "|" + 4219 str(self.shortauthorname) + "| Overall")4290 str(self.shortauthorname) + "|PubInfo") 4220 4291 writeCIFtemplate(self.OverallParms['Controls'],'publ') #insert the publication template 4221 4292 # ``template_publ.cif`` or a modified version 4222 # overall info 4293 4294 # overall info -- it is not strictly necessary to separate this from the previous 4295 # publication block, but I think this makes sense 4296 4223 4297 WriteCIFitem(self.fp, 'data_'+str(self.CIFname)+'_overall') 4224 WriteOverall() 4298 WriteCIFitem(self.fp, '_pd_block_id', 4299 str(self.CIFdate) + "|" + str(self.CIFname) + "|" + 4300 str(self.shortauthorname) + "|Overall") 4301 if MM: 4302 WriteOverallMM() 4303 else: 4304 WriteOverall() 4225 4305 #============================================================ 4226 WriteCIFitem(self.fp, '# POINTERS TO PHASE AND HISTOGRAM BLOCKS')4306 WriteCIFitem(self.fp, '# POINTERS TO PHASE AND/OR HISTOGRAM BLOCKS') 4227 4307 datablockidDict = {} # save block names here -- N.B. check for conflicts between phase & hist names (unlikely!) 4228 4308 # loop over phase blocks … … 4230 4310 loopprefix = '' 4231 4311 WriteCIFitem(self.fp, 'loop_ _pd_phase_block_id') 4232 else: 4233 loopprefix = '_pd_phase_block_id' 4234 4235 for phasenam in sorted(self.Phases.keys()): 4236 i = self.Phases[phasenam]['pId'] 4312 for phasenam in sorted(self.Phases.keys()): 4313 i = self.Phases[phasenam]['pId'] 4314 datablockidDict[phasenam] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" + 4315 'phase_'+ str(i) + '|' + str(self.shortauthorname)) 4316 WriteCIFitem(self.fp, loopprefix,datablockidDict[phasenam]) 4317 else: # phase in overall block 4318 for phasenam in sorted(self.Phases.keys()): break 4237 4319 datablockidDict[phasenam] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" + 4238 'phase_'+ str(i) + '|' + str(self.shortauthorname)) 4239 WriteCIFitem(self.fp, loopprefix,datablockidDict[phasenam]) 4320 str(self.shortauthorname) + "|Overall") 4240 4321 # loop over data blocks 4241 4322 if len(self.powderDict) + len(self.xtalDict) > 1: … … 4270 4351 dlg.Update(step,"Exporting phase "+phasenam+' (#'+str(j+1)+')') 4271 4352 i = self.Phases[phasenam]['pId'] 4272 WriteCIFitem(self.fp, '\ndata_'+self.CIFname+"_phase_"+str(i)) 4273 WriteCIFitem(self.fp, '# Information for phase '+str(i)) 4274 WriteCIFitem(self.fp, '_pd_block_id',datablockidDict[phasenam]) 4353 if len(self.Phases) > 1: # in a single-phase CIF the overall and phase block can be combined 4354 WriteCIFitem(self.fp, '\ndata_'+self.CIFname+"_phase_"+str(i)) 4355 WriteCIFitem(self.fp, '\n# Information for phase '+str(i)) 4356 if len(self.Phases) > 1: # in a single-phase CIF the overall and phase block can be combined 4357 WriteCIFitem(self.fp, '_pd_block_id',datablockidDict[phasenam]) 4275 4358 # report the phase 4276 4359 writeCIFtemplate(self.Phases[phasenam]['General'],'phase',phasenam) # write phase template
Note: See TracChangeset
for help on using the changeset viewer.