Changeset 5520


Ignore:
Timestamp:
Mar 23, 2023 1:03:34 PM (2 years ago)
Author:
vondreele
Message:

New version of spinning RBs - radius is now a parameter of each shell. all appear to work

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIconstrGUI.py

    r5502 r5520  
    30273027       
    30283028        rbid = ran.randint(0,sys.maxsize)
    3029         radius = 1.0
    30303029        atType = 'C'
    30313030        rbType = 'Q'
     
    30353034        name = G2obj.MakeUniqueLabel(name,namelist)
    30363035        atColor = G2elem.GetAtomInfo(atType)['Color']
    3037         data['Spin'][rbid] = {'RBname':name,'Natoms':Natoms,'radius':[radius,False],'atType':atType,'rbType':rbType,
    3038             'useCount':0,'nSH':0,'SHC':[{},],'Matrix':np.eye(3),'rbPos':np.zeros(3),'atColor':atColor}
     3036        data['Spin'][rbid] = {'RBname':name,'Natoms':Natoms,'atType':atType,'rbType':rbType,
     3037            'useCount':0,'nSH':0,'SHC':[{},],'Radius':[1.0,False],'Matrix':np.eye(3),'rbPos':np.zeros(3),'atColor':atColor}
    30393038        data['RBIds']['Spin'].append(rbid)
    30403039        UpdateSpinRB()
     
    34043403                    Obj.ChangeValue(El)
    34053404                   
    3406         def OnRefSel(event):
    3407             ObjId = event.GetId()
    3408             data['Spin'][Indx[ObjId]]['radius'][1] = not data['Spin'][Indx[ObjId]]['radius'][1]
    3409 
    34103405        def OnSymSel(event):
    34113406            ObjId = event.GetId()
     
    34343429        Indx = {}
    34353430        SpinRBSizer.Add(wx.StaticText(SpinRBDisplay,label=' Spinning rigid body shells/nonspherical atoms (radius=0):'),0,WACV)
    3436         bodSizer = wx.FlexGridSizer(0,7,5,5)
    3437         for item in ['Name','Type','RB sym','Atom','Number','radius','refine']:
     3431        bodSizer = wx.FlexGridSizer(0,5,5,5)
     3432        for item in ['Name','Type','RB sym','Atom','Number']:
    34383433            bodSizer.Add(wx.StaticText(SpinRBDisplay,label=item))
    34393434        for ibod,spinID in enumerate(data['Spin']):
     
    34533448            bodSizer.Add(atSel,0)
    34543449            bodSizer.Add(G2G.ValidatedTxtCtrl(SpinRBDisplay,data['Spin'][spinID],'Natoms'))
    3455             bodSizer.Add(G2G.ValidatedTxtCtrl(SpinRBDisplay,data['Spin'][spinID]['radius'],0))
    3456             refSel = wx.CheckBox(SpinRBDisplay)
    3457             refSel.SetValue(data['Spin'][spinID]['radius'][1])
    3458             Indx[refSel.GetId()] = spinID
    3459             refSel.Bind(wx.EVT_CHECKBOX,OnRefSel)
    3460             bodSizer.Add(refSel,0)
    34613450       
    34623451        SpinRBSizer.Add(bodSizer)
  • TabularUnified trunk/GSASIIlattice.py

    r5513 r5520  
    27062706def SHarmcal(SytSym,SHFln,psi,gam):
    27072707    '''Perform a surface spherical harmonics computation.
     2708    Presently only used for plotting
    27082709    Note that the the number of gam values must either be 1 or must match psi
    27092710   
  • TabularUnified trunk/GSASIIobj.py

    r5443 r5520  
    20412041        'RBSO([aijk])' : 'Spinning rigid body orientation parameter \\1',
    20422042        'RBSP([xyz])' : 'Spinning rigid body \\1 position parameter',
     2043        'RBSShRadius' : 'Spinning rigid body radius',
    20432044        'RBSShC([1-20,1-20])'  : 'Spinning rigid body sph. harmonics term',
    20442045        'constr([0-9]*)' : 'Generated degree of freedom from constraint',
  • TabularUnified trunk/GSASIIphsGUI.py

    r5517 r5520  
    1158111581                RBObj['RBId'].append(rbIds[selection])
    1158211582                RBObj['SHC'].append({})
    11583                 for name in ['atColor','atType','Natoms','nSH','radius','RBname','RBsym']:
     11583                for name in ['atColor','atType','Natoms','nSH','RBname','RBsym','Radius']:
    1158411584                    RBObj[name].append(rbData[name])
    1158511585                RBObj['hide'].append(False)
     
    1161211612                    iSh,name = Indx[Obj.GetId()]
    1161311613                    RBObj['SHC'][iSh][name][2] = not RBObj['SHC'][iSh][name][2]
     11614                   
     11615                def OnRadRef(event):
     11616                    Obj = event.GetEventObject()
     11617                    iSh = Indx[Obj.GetId()]
     11618                    RBObj['Radius'][iSh][1] = not RBObj['Radius'][iSh][1]
    1161411619               
    1161511620                def NewSHC(invalid,value,tc):
    1161611621                    G2plt.PlotStructure(G2frame,data)
    11617                    
     11622                                       
    1161811623                def OnDelShell(event):
    1161911624                    Obj = event.GetEventObject()
     
    1162211627                    RBData['Spin'][rbId]['useCount'] -= 1
    1162311628                    RBData['Spin'][rbId]['useCount'] = max(0,RBData['Spin'][rbId]['useCount'])
    11624                     for name in ['atColor','atType','Natoms','nSH','radius','RBId','RBname','RBsym','SHC']:
     11629                    for name in ['atColor','atType','Natoms','nSH','RBId','RBname','RBsym','SHC']:
    1162511630                        del RBObj[name][iSh]
    1162611631                    G2plt.PlotStructure(G2frame,data)
     
    1163011635                shSizer = wx.BoxSizer(wx.VERTICAL)
    1163111636                for iSh,nSh in enumerate(RBObj['nSH']):
     11637                    #patch
     11638                    if 'Radius' not in RBObj:
     11639                        RBObj['Radius'] = [[1.0,False] for i in range(len(RBObj['nSH']))]
     11640                    #end patch
    1163211641                    rbId = RBObj['RBId'][iSh]
    1163311642                    RBObj['atType'][iSh] = RBData['Spin'][rbId]['atType']
     
    1165411663                    shoSizer.Add(shOrder,0,WACV)
    1165511664                    if RBObj['nSH'][iSh]>0:
    11656                         shoSizer.Add(wx.StaticText(RigidBodies,label=" 'c' for cubic harmonic term"),0,WACV)
     11665                        shoSizer.Add(wx.StaticText(RigidBodies,label=" 'c' for cubic harmonic term. "),0,WACV)
     11666                    shoSizer.Add(wx.StaticText(RigidBodies,label=' Radius: '),0,WACV)
     11667                    shoSizer.Add(G2G.ValidatedTxtCtrl(RigidBodies,RBObj['Radius'][iSh],0,nDig=(8,5),xmin=0.0,xmax=5.0,
     11668                        typeHint=float,size=(70,-1),OnLeave=NewSHC),0,WACV)
     11669                    radref = wx.CheckBox(RigidBodies,label=' refine? ')
     11670                    radref.SetValue(RBObj['Radius'][iSh][1])
     11671                    radref.Bind(wx.EVT_CHECKBOX,OnRadRef)
     11672                    Indx[radref.GetId()] = iSh
     11673                    shoSizer.Add(radref,0,WACV)
    1165711674                    shSizer.Add(shoSizer)
    1165811675                    if not RBObj['nSH'][iSh]:
     
    1228712304                    data['RBModels'][rbType] = []
    1228812305                if rbType == 'Spin':    #convert items to lists of shells
    12289                     for name in ['atColor','atType','Natoms','nSH','radius','RBId','RBname','RBsym']:
     12306                    for name in ['atColor','atType','Natoms','nSH','Radius','RBId','RBname','RBsym']:
    1229012307                        item = rbObj[name]                       
    1229112308                        rbObj[name] = [item,]
     
    1294212959        if rbType == 'Spin':
    1294312960            data['testRBObj']['rbAtTypes'] = [RBData[rbType][rbId]['rbType'],]
    12944             data['testRBObj']['AtInfo'] = {RBData[rbType][rbId]['rbType']:[RBData[rbType][rbId]['radius'],(128, 128, 255)],}
     12961            data['testRBObj']['AtInfo'] = {RBData[rbType][rbId]['rbType']:[RBData[rbType][rbId]['Radius'],(128, 128, 255)],}
    1294512962            data['testRBObj']['rbType'] = rbType
    1294612963            data['testRBObj']['rbData'] = RBData
     
    1297512992                    'Orient':[[0.,0.,0.,1.],' '],'Ids':[],'RBId':rbId,'Torsions':[],
    1297612993                    'numChain':'','RBname':RBData[rbType][rbId]['RBname']}
     12994        # if rbType == 'Spin':
     12995        #     data['testRBObj']['rbObj']['Radius'] = [1.0,False]
    1297712996        data['testRBObj']['torAtms'] = []               
    1297812997        for item in RBData[rbType][rbId].get('rbSeq',[]):
  • TabularUnified trunk/GSASIIplot.py

    r5516 r5520  
    1034910349                    if SpnData is not None:
    1035010350                        SytSym = G2spc.SytSym(atom[cx:cx+3],SGData)[0]
    10351                         radius = SpnData['radius']
     10351                        radius = SpnData['Radius']
    1035210352                        atColor = SpnData['atColor']
    1035310353                        symAxis = np.array(SpnData.get('symAxis',[0,0,1]))
  • TabularUnified trunk/GSASIIstrIO.py

    r5513 r5520  
    10591059        pFile.write('Spinning RB name: %s atom type: %s, no.atoms: %d, No. times used: %d\n'%
    10601060            (RBModel['RBname'],RBModel['atType'],RBModel['Natoms'],RBModel['useCount']))
    1061         for i in WriteSpnRBModel(RBModel):
    1062             pFile.write(i)
    10631061
    10641062    def PrintResRBModel(RBModel):
     
    10831081        for irb,item in enumerate(rbIds['Spin']):
    10841082            if rigidbodyDict['Spin'][item]['useCount']:
    1085                 RBradius = rigidbodyDict['Spin'][item]['radius']
    1086                 pid = '::RBS;0:'+str(irb)
    1087                 rbDict[pid] = RBradius[0]
    1088                 if RBradius[1]:
    1089                     rbVary.append(pid)
    10901083                if Print:
    10911084                    pFile.write('\nSpinning rigid body model:\n')
     
    11321125        pFile.write(sigstr+'\n')
    11331126
    1134     def PrintRBSpnandSig(SpinRB,SpinSig):
    1135         pFile.write('\n Spinning radius for %s:\n'%SpinRB['RBname'])
    1136         namstr = '  names :'
    1137         valstr = '  values:'
    1138         sigstr = '  esds  :'
    1139         for i,[val,sig] in enumerate(zip(SpinRB['radius'],SpinSig)):
    1140             namstr += '%12s'%('Spin '+str(i))
    1141             valstr += '%12.4f'%(val)
    1142             if sig:
    1143                 sigstr += '%12.4f'%(sig)
    1144             else:
    1145                 sigstr += 12*' '
    1146         pFile.write(namstr+'\n')
    1147         pFile.write(valstr+'\n')
    1148         pFile.write(sigstr+'\n')       
    1149        
    11501127    RBIds = rigidbodyDict.get('RBIds',{'Vector':[],'Residue':[],'Spin':[]})  #these are lists of rbIds
    1151     if not RBIds['Vector'] and not RBIds['Spin']:
     1128    if not RBIds['Vector']:
    11521129        return
    11531130    for irb,item in enumerate(RBIds['Vector']):
     
    11601137                    VectSig.append(sigDict[name])
    11611138            PrintRBVectandSig(rigidbodyDict['Vector'][item],VectSig)   
    1162     for irb,item in enumerate(RBIds['Spin']):
    1163         if rigidbodyDict['Spin'][item]['useCount']:
    1164             SpinSig = []
    1165             name = '::RBS;'+str(0)+':'+str(irb)
    1166             if name in sigDict:
    1167                 SpinSig.append(sigDict[name])
    1168                
    1169            
    1170             PrintRBSpnandSig(rigidbodyDict['Spin'][item],SpinSig)   
    11711139       
    11721140################################################################################
     
    13431311                        iFin = min(iBeg+6,nCoeff)
    13441312                        for block in range(nBlock):
    1345                             ptlbls = ' names :'
    1346                             ptstr =  ' values:'
    1347                             ptref =  ' refine:'
     1313                            if not block:
     1314                                ptlbls = ' names :%12s'%'Radius'
     1315                                ptstr =  ' values:%12.4f'%RB['Radius'][ish][0]
     1316                                ptref =  ' refine:%12s'%RB['Radius'][ish][1]                               
     1317                            else:
     1318                                ptlbls = ' names :'
     1319                                ptstr =  ' values:'
     1320                                ptref =  ' refine:'
    13481321                            for item in SHkeys[iBeg:iFin]:
    13491322                                ptlbls += '%12s'%(item)
     
    15921565                continue
    15931566            rbid = str(rbids.index(RB['RBId'][ish]))
     1567            name = '%sRBSSh;%d;Radius:%s:%s'%(pfx,ish,iAt,rbid)
     1568            phaseDict[name] = RB['Radius'][ish][0]
     1569            if RB['Radius'][ish][1]:
     1570                phaseVary += [name,]
    15941571            pfxRB = '%sRBSSh;%d;'%(pfx,ish)
    15951572            for i,shcof in enumerate(Shcof):
     
    25692546                        jrb = SRBIds.index(RBObj['RBId'][ish])  #spin rb no.
    25702547                        rbsx = ':%d:%d'%(iAt,jrb)
    2571                         pFile.write(' Spin rigid body parameters:\n')
    2572                         PrintRBObjPOAndSig('RBS',rbsx)
     2548                        pFile.write(' Spin rigid body parameters for at. no. %d; shell %d:\n'%(iAt,ish))
     2549                        if not ish:
     2550                            PrintRBObjPOAndSig('RBS',rbsx[1:])  #skip leading ':'
    25732551                        PrintRBObjSHCAndSig('RBSSh;%d;'%ish,RBObj['SHC'][ish],rbsx)
    25742552            atomsSig = {}
     
    42024180        if name in sigDict:
    42034181            sigstr += '%12.4f'%(sigDict[name])
     4182        else:
     4183            sigstr += 12*' '
    42044184    out.append(namstr+'\n')
    42054185    out.append(valstr+'\n')
     
    42124192    '''
    42134193    out = []
    4214     namstr = '  names :'
    4215     valstr = '  values:'
     4194    name = pfx+rbfx+'Radius'+rbsx
     4195    namstr = '  names :%12s'%'Radius'
     4196    valstr = '  values:%12.4f'%parmDict[name]
    42164197    sigstr = '  esds  :'
     4198    if name in sigDict:
     4199        sigstr += '%12.4f'%sigDict[name]
     4200        [name]
     4201    else:
     4202        sigstr += 12*' '
    42174203    out.append(' Sp.harm.:\n')
    42184204    for item in SHC:
     
    42224208        if name in sigDict:
    42234209            sigstr += '%12.4f'%(sigDict[name])
     4210        else:
     4211            sigstr += 12*' '
    42244212    out.append(namstr+'\n')
    42254213    out.append(valstr+'\n')
    42264214    out.append(sigstr+'\n')
    4227     return out
    4228 
    4229 def WriteSpnRBModel(RBModel,sigDict={},irb=None):
    4230     '''Write description of a spinning rigid body. Code here to make usable from G2export_CIF
    4231     '''
    4232     out = ' Radius: %10.3f refine? %s\n'%(RBModel['radius'][0],RBModel['radius'][1])   
    42334215    return out
    42344216
  • TabularUnified trunk/GSASIIstrMain.py

    r5498 r5520  
    423423                G2stIO.SetISOmodes(parmDict,sigDict,Phases,printFile)
    424424                G2stIO.SetHistogramPhaseData(parmDict,sigDict,Phases,Histograms,calcControls,
    425                                              pFile=printFile,covMatrix=covMatrix,varyList=varyList)
     425                    pFile=printFile,covMatrix=covMatrix,varyList=varyList)
    426426                G2stIO.SetHistogramData(parmDict,sigDict,Histograms,calcControls,pFile=printFile)
    427427                # check for variables outside their allowed range, reset and freeze them
  • TabularUnified trunk/GSASIIstrMath.py

    r5518 r5520  
    7676                    name = '::RBV;'+str(j)+':'+str(i)
    7777                    VRBData[rbId]['VectMag'][j] = parmDict[name]
    78     if RBIds['Spin']:
    79         SRBData = RBData['Spin']
    80         for i,rbId in enumerate(SRBIds):
    81             if SRBData[rbId]['useCount']:
    82                 name = '::RBS;0:'+str(i)
    83                 SRBData[rbId]['radius'][0] = parmDict[name]
    8478       
    8579    for phase in Phases:
     
    171165            jrb = SRBIds.index(RBObj['RBId'][0])
    172166            name = pfx+'RBSOa:%d:%d'%(iAt,jrb)
    173             RBObj['Orient'][0][0] = parmDict[name]
     167            for i,po in enumerate(['RBSOa:','RBSOi:','RBSOj:','RBSOk:']):
     168                name = pfx+'%s%d:%d'%(po,iAt,jrb)
     169                RBObj['Orient'][0][i] = parmDict[name]               
    174170            for ish in range(len(RBObj['RBId'])):
    175171                jrb = SRBIds.index(RBObj['RBId'][ish])
     
    205201    RBModels =  Phase['RBModels']
    206202   
    207     for irb,RBObj in enumerate(RBModels.get('Spin',[])):
    208         name = '::RBS;0:%d'%irb
    209         if name in dFdvDict:
    210             dFdvDict[name] += dFdvDict[pfx+'RBS;0:%d'%irb]
    211         else:           
    212             dFdvDict[name] = dFdvDict[pfx+'RBS;0:%d'%irb]
     203    # for irb,RBObj in enumerate(RBModels.get('Spin',[])):
     204    #     name = '::RBS;0:%d'%irb
     205    #     if name in dFdvDict:
     206    #         dFdvDict[name] += dFdvDict[pfx+'RBS;0:%d'%irb]
     207    #     else:           
     208    #         dFdvDict[name] = dFdvDict[pfx+'RBS;0:%d'%irb]
    213209                   
    214210    for irb,RBObj in enumerate(RBModels.get('Vector',[])):
     
    399395                    break
    400396                Shell = SHdat[shl]
    401                 R = Shell['R']
     397                R = Shell['Radius']
    402398                Atm = Shell['AtType']
    403399                Nat = Shell['Natoms']
     
    409405                    dat = G2el.getBLvalues(BLtables)
    410406                    SFF = dat[Atm]
    411                 Rname = ';0:%s'%Irb
     407                Rname = 'Sh;%s;Radius:%d:%s'%(shl,iAt,Irb)
    412408                R0 = sp.spherical_jn(0,QR*R)/(4.*np.pi)
    413409                R0P = sp.spherical_jn(0,QR*(R+0.01))/(4.*np.pi)
     
    440436                        name = 'Sh;%s;%s:%d:%s'%(shl,item,iAt,Irb)
    441437                        dFFdS[name] = Nat*SFF*BS*SH
    442                         #fill derivatives here wrt iAt,ishl,item or l,m
     438                dFFdS[Rname] = dBSdR
    443439                ishl += 1
    444                 dFFdS[Rname] = dBSdR
    445440            dFFdS[Oname] = dSHdO
    446441            dFFdS[Oiname] = dSHdOi
     
    468463            shno = bits[1]
    469464            if shno not in SHCdict[atid]:
    470                 SHCdict[atid][shno] = {'R':parmDict['::RBS;0:%s'%shno]}
     465                SHCdict[atid][shno] = {}
    471466            if 'AtType' in bits[0] or 'Natoms' in bits[0] or 'ShR' in bits[0]:
    472467                SHCdict[atid][shno][bits[0]] = parmDict[parm]
     
    10671062    Tdata,Mdata,Fdata,Xdata,dXdata,IAdata,Uisodata,Uijdata,Gdata = \
    10681063        GetAtomFXU(pfx,calcControls,parmDict)
    1069     atFlg = np.zeros(len(Tdata))
     1064    atFlg = np.zeros(len(Tdata)) #non zero for Q type atoms - see below
    10701065    if not Xdata.size:          #no atoms in phase!
    10711066        return {}
Note: See TracChangeset for help on using the changeset viewer.