Changeset 5085


Ignore:
Timestamp:
Nov 15, 2021 12:36:53 PM (2 years ago)
Author:
toby
Message:

more mmCIF fixes; combine Overall & Phase blocks where single-phase

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/exports/G2export_CIF.py

    r5081 r5085  
    742742    Amat = G2lat.cell2AB(General['Cell'][1:7])[0]
    743743    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:
    751747        WriteCIFitem(fp, '\n# PHASE HAS NO ATOMS!')
    752748        return
     
    791787
    792788    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
    793797    # loop over all atoms
    794798#    naniso = 0
     
    807811        s += PutInCol(at[ct-2],3) # _asym_id
    808812        s += PutInCol(at[ct-2],3) # _asym_id
    809         s += PutInCol(at[ct-4],3) # entity_id
    810         s += PutInCol('?',2) # _seq_id
    811         s += PutInCol('?',2) # _seq_id
     813        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
    812816        s += PutInCol('?',2) # pdbx_PDB_ins_code
    813817        s += PutInCol('?',2) # pdbx_formal_charge
    814818        s += PutInCol('1',2) # pdbx_PDB_model_num
    815819           
    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)
    818822#        if at[cia] == 'I':
    819823#            adp = 'Uiso '
     
    841845                sig = -abs(sig)
    842846            s += PutInCol(G2mth.ValEsd(val,sig),dig)
    843             # Cartesian coordinates
    844             for xyz in np.inner(Amat,at[cx:cx+3]):
    845                 s += PutInCol(G2mth.ValEsd(xyz,-0.009),8)
     847        # Cartesian coordinates
     848        for xyz in np.inner(Amat,at[cx:cx+3]):
     849            s += PutInCol(G2mth.ValEsd(xyz,-0.009),8)
    846850        WriteCIFitem(fp, s)
    847851    # save information about rigid bodies
     
    16841688            #WriteCIFitem(self.fp, '_refine_ls_matrix_type','userblocks')
    16851689
     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
    16861747        def writeCIFtemplate(G2dict,tmplate,defaultname=''):
    16871748            '''Write out the selected or edited CIF template
     
    16991760            templateDefName = 'template_'+tmplate+'.cif'
    17001761            if not CIFobj: # copying a template
     1762                lbl = 'Standard version'
    17011763                for pth in [os.getcwd()]+sys.path:
    17021764                    fil = os.path.join(pth,defaultname)
     
    17131775                fp.close()
    17141776            elif type(CIFobj) is not list and type(CIFobj) is not tuple:
     1777                lbl = 'Saved version'
    17151778                if not os.path.exists(CIFobj):
    17161779                    print("Error: requested template file has disappeared: "+CIFobj)
     
    17201783                fp.close()
    17211784            else:
     1785                lbl = 'Project-specific version'
    17221786                txt = dict2CIF(CIFobj[0],CIFobj[1]).WriteOut()
    17231787            # remove the PyCifRW header, if present
    17241788            #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:])
    17261794            #txt = txt.replace('data_','#')
    17271795            WriteCIFitem(self.fp, txt)
     
    39514019            WriteAudit()
    39524020            writeCIFtemplate(self.OverallParms['Controls'],'publ') # overall (publication) template
    3953             WriteOverall()
     4021            if MM:
     4022                WriteOverallMM()
     4023            else:
     4024                WriteOverall()
    39544025            writeCIFtemplate(self.Phases[phasenam]['General'],'phase',phasenam) # write phase template
    39554026            # report the phase info
     
    42174288                WriteCIFitem(self.fp, '_pd_block_id',
    42184289                             str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
    4219                              str(self.shortauthorname) + "|Overall")
     4290                             str(self.shortauthorname) + "|PubInfo")
    42204291                writeCIFtemplate(self.OverallParms['Controls'],'publ') #insert the publication template
    42214292                # ``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               
    42234297                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()
    42254305                #============================================================
    4226                 WriteCIFitem(self.fp, '# POINTERS TO PHASE AND HISTOGRAM BLOCKS')
     4306                WriteCIFitem(self.fp, '# POINTERS TO PHASE AND/OR HISTOGRAM BLOCKS')
    42274307                datablockidDict = {} # save block names here -- N.B. check for conflicts between phase & hist names (unlikely!)
    42284308                # loop over phase blocks
     
    42304310                    loopprefix = ''
    42314311                    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
    42374319                    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")
    42404321                # loop over data blocks
    42414322                if len(self.powderDict) + len(self.xtalDict) > 1:
     
    42704351                    dlg.Update(step,"Exporting phase "+phasenam+' (#'+str(j+1)+')')
    42714352                    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])
    42754358                    # report the phase
    42764359                    writeCIFtemplate(self.Phases[phasenam]['General'],'phase',phasenam) # write phase template
Note: See TracChangeset for help on using the changeset viewer.