Ignore:
Timestamp:
Nov 27, 2020 8:48:26 PM (12 months ago)
Author:
toby
Message:

update CIF export: add rigid body, fix bug in single xtal ref tbl; picker bug on single xtal plot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/exports/G2export_CIF.py

    r4657 r4661  
    5757import GSASIIspc as G2spc
    5858import GSASIIstrMain as G2stMn
     59import GSASIIstrIO as G2strIO       
    5960import GSASIImapvars as G2mv
    6061import GSASIIElem as G2el
     
    8788        fp.write(name+'\n')
    8889
     90def RBheader(fp):
     91    WriteCIFitem(fp,'\n# RIGID BODY DETAILS')
     92    WriteCIFitem(fp,'loop_\n    _restr_rigid_body_class.class_id\n    _restr_rigid_body_class.details')
    8993
    9094# Refactored over here to allow access by GSASIIscriptable.py
    91 def WriteAtomsNuclear(fp, phasedict, phasenam, parmDict, sigDict, labellist):
     95def WriteAtomsNuclear(fp, phasedict, phasenam, parmDict, sigDict, labellist,
     96                          RBparms={}):
    9297    'Write atom positions to CIF'
    9398    # phasedict = self.Phases[phasenam] # pointer to current phase info
     
    174179        s += PutInCol(at[cs+1],3)
    175180        WriteCIFitem(fp, s)
    176     if naniso == 0: return
    177     # now loop over aniso atoms
    178     WriteCIFitem(fp, '\nloop_' + '\n   _atom_site_aniso_label' +
    179                  '\n   _atom_site_aniso_U_11' + '\n   _atom_site_aniso_U_22' +
    180                  '\n   _atom_site_aniso_U_33' + '\n   _atom_site_aniso_U_12' +
    181                  '\n   _atom_site_aniso_U_13' + '\n   _atom_site_aniso_U_23')
    182     for i,at in enumerate(Atoms):
    183         fval = parmDict.get(fpfx+str(i),at[cfrac])
    184         if fval == 0.0: continue # ignore any atoms that have a occupancy set to 0 (exact)
    185         if at[cia] == 'I': continue
    186         s = PutInCol(labellist[i],6) # label
    187         for j in (2,3,4,5,6,7):
    188             sigdig = -0.0009
    189             var = pfx+varnames[cia+j]+":"+str(i)
    190             val = parmDict.get(var,at[cia+j])
    191             sig = sigDict.get(var,sigdig)
    192             s += PutInCol(G2mth.ValEsd(val,sig),11)
    193         WriteCIFitem(fp, s)
    194 
     181    if naniso != 0:
     182        # now loop over aniso atoms
     183        WriteCIFitem(fp, '\nloop_' + '\n   _atom_site_aniso_label' +
     184                     '\n   _atom_site_aniso_U_11' + '\n   _atom_site_aniso_U_22' +
     185                     '\n   _atom_site_aniso_U_33' + '\n   _atom_site_aniso_U_12' +
     186                     '\n   _atom_site_aniso_U_13' + '\n   _atom_site_aniso_U_23')
     187        for i,at in enumerate(Atoms):
     188            fval = parmDict.get(fpfx+str(i),at[cfrac])
     189            if fval == 0.0: continue # ignore any atoms that have a occupancy set to 0 (exact)
     190            if at[cia] == 'I': continue
     191            s = PutInCol(labellist[i],6) # label
     192            for j in (2,3,4,5,6,7):
     193                sigdig = -0.0009
     194                var = pfx+varnames[cia+j]+":"+str(i)
     195                val = parmDict.get(var,at[cia+j])
     196                sig = sigDict.get(var,sigdig)
     197                s += PutInCol(G2mth.ValEsd(val,sig),11)
     198            WriteCIFitem(fp, s)
     199    # save information about rigid bodies
     200    header = False
     201    num = 0
     202    rbAtoms = []
     203    for irb,RBObj in enumerate(phasedict['RBModels'].get('Residue',[])):
     204        if not header:
     205            header = True
     206            RBheader(fp)
     207        jrb = RBparms['RBIds']['Residue'].index(RBObj['RBId'])
     208        rbsx = str(irb)+':'+str(jrb)
     209        num += 1
     210        WriteCIFitem(fp,'',str(num))
     211        RBModel = RBparms['Residue'][RBObj['RBId']]
     212        SGData = phasedict['General']['SGData']
     213        Sytsym,Mult = G2spc.SytSym(RBObj['Orig'][0],SGData)[:2]
     214        s = '''GSAS-II residue rigid body "{}" with {} atoms
     215  Site symmetry @ origin: {}, multiplicity: {}
     216'''.format(RBObj['RBname'],len(RBModel['rbTypes']),Sytsym,Mult)
     217        for i in G2strIO.WriteResRBModel(RBModel):
     218            s += i
     219        s += '\n Location:\n'
     220        for i in G2strIO.WriteRBObjPOAndSig(pfx,'RBR',rbsx,parmDict,sigDict):
     221            s += i+'\n'
     222        for i in G2strIO.WriteRBObjTLSAndSig(pfx,'RBR',rbsx,
     223                        RBObj['ThermalMotion'][0],parmDict,sigDict):
     224            s += i
     225        nTors = len(RBObj['Torsions'])
     226        if nTors:
     227            for i in G2strIO.WriteRBObjTorAndSig(pfx,rbsx,parmDict,sigDict,
     228                        nTors):
     229                s += i
     230        WriteCIFitem(fp,'',s.rstrip())
     231       
     232        pId = phasedict['pId']
     233        for i in RBObj['Ids']:
     234            lbl = G2obj.LookupAtomLabel(pId,G2obj.LookupAtomId(pId,i))[0]
     235            rbAtoms.append('{:7s} 1_555 {:3d} ?'.format(lbl,num))
     236        #GSASIIpath.IPyBreak()
     237
     238    for irb,RBObj in enumerate(phasedict['RBModels'].get('Vector',[])):
     239        if not header:
     240            header = True
     241            RBheader(fp)
     242        jrb = RBparms['RBIds']['Vector'].index(RBObj['RBId'])
     243        rbsx = str(irb)+':'+str(jrb)
     244        num += 1
     245        WriteCIFitem(fp,'',str(num))
     246        RBModel = RBparms['Vector'][RBObj['RBId']]
     247        SGData = phasedict['General']['SGData']
     248        Sytsym,Mult = G2spc.SytSym(RBObj['Orig'][0],SGData)[:2]
     249        s = '''GSAS-II vector rigid body "{}" with {} atoms
     250  Site symmetry @ origin: {}, multiplicity: {}
     251'''.format(RBObj['RBname'],len(RBModel['rbTypes']),Sytsym,Mult)
     252        for i in G2strIO.WriteVecRBModel(RBModel,sigDict,irb):
     253            s += i
     254        s += '\n Location:\n'
     255        for i in G2strIO.WriteRBObjPOAndSig(pfx,'RBV',rbsx,parmDict,sigDict):
     256            s += i+'\n'
     257        for i in G2strIO.WriteRBObjTLSAndSig(pfx,'RBV',rbsx,
     258                        RBObj['ThermalMotion'][0],parmDict,sigDict):
     259            s += i
     260        WriteCIFitem(fp,'',s.rstrip())
     261       
     262        pId = phasedict['pId']
     263        for i in RBObj['Ids']:
     264            lbl = G2obj.LookupAtomLabel(pId,G2obj.LookupAtomId(pId,i))[0]
     265            rbAtoms.append('{:7s} 1_555 {:3d} ?'.format(lbl,num))
     266
     267    if rbAtoms:
     268        WriteCIFitem(fp,'loop_\n    _restr_rigid_body.id'+
     269            '\n    _restr_rigid_body.atom_site_label\n    _restr_rigid_body.site_symmetry'+
     270            '\n    _restr_rigid_body.class_id\n    _restr_rigid_body.details')
     271        for i,l in enumerate(rbAtoms):
     272            WriteCIFitem(fp,'   {:5d} {}'.format(i+1,l))
     273           
    195274def WriteAtomsMagnetic(fp, phasedict, phasenam, parmDict, sigDict, labellist):
    196275    'Write atom positions to CIF'
     
    560639            if self.ifHKLF:
    561640                controls = self.OverallParms['Controls']
    562                 if controls['F**2']:
    563                     thresh = 'F**2>%.1fu(F**2)'%(controls['UsrReject']['minF/sig'])
    564                 else:
    565                     thresh = 'F>%.1fu(F)'%(controls['UsrReject']['minF/sig'])
    566                 WriteCIFitem(self.fp, '_reflns_threshold_expression', thresh)
     641                try:
     642                    if controls['F**2']:
     643                        thresh = 'F**2>%.1fu(F**2)'%(controls['UsrReject']['minF/sig'])
     644                    else:
     645                        thresh = 'F>%.1fu(F)'%(controls['UsrReject']['minF/sig'])
     646                    WriteCIFitem(self.fp, '_reflns_threshold_expression', thresh)
     647                except KeyError:
     648                    pass
    567649            try:
    568650                vars = str(len(self.OverallParms['Covariance']['varyList']))
     
    11431225                    self.labellist = []
    11441226                WriteAtomsNuclear(self.fp, self.Phases[phasenam], phasenam,
    1145                                   self.parmDict, self.sigDict, self.labellist)
     1227                                  self.parmDict, self.sigDict, self.labellist,
     1228                                      self.OverallParms['Rigid bodies'])
    11461229            else:
    11471230                try:
     
    15221605                    s += PutInCol('.',10)
    15231606                    s += PutInCol(G2mth.ValEsd(ref[9],0),12)
    1524                     s += PutInCol(G2mth.ValEsd(ref[10],-0.9),7)
    15251607                else:
    15261608                    sig = ref[6] * ref[8] / ref[5]
     
    19182000        # load saved CIF author name
    19192001        try:
    1920             self.author = self.OverallParms['Controls'].get("Author",'').strip()
     2002            self.author = self.OverallParms['Controls'].get("Author",'?').strip()
    19212003        except KeyError:
    19222004            pass
     
    21042186        # give the user a window to edit CIF contents
    21052187        if not self.author:
    2106             self.author = self.OverallParms['Controls']["Author"]
     2188            self.author = self.OverallParms['Controls'].get("Author",'?').strip()
    21072189            self.shortauthorname = self.author.replace(',','').replace(' ','')[:20]
    21082190        if not self.author:
Note: See TracChangeset for help on using the changeset viewer.