Changeset 5460


Ignore:
Timestamp:
Dec 31, 2022 12:58:26 PM (11 months ago)
Author:
vondreele
Message:

fix to SetupGeneral? for multiple shells
correct sph harm multiplier for m=0
Correct sphere harm plotting
correct G2strIO for input of multishelled RBs

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIElem.py

    r5454 r5460  
    728728                if len(landeg) < len(generalData['AtomTypes']):
    729729                    landeg.append(2.0)
    730         if 'Q' in atom[ct]:  #RBData must exist #TODO: need code here to add to atom count for atom type in spinrb
     730        if 'Q' in atom[ct]:
    731731            for Srb in RBModels.get('Spin',[]):
     732                if Srb['Ids'][0] != atom[cia+8]:
     733                    continue
    732734                nSh = len(Srb['RBId'])
    733735                for iSh in range(nSh):
    734                         Info = G2elem.GetAtomInfo(Srb['atType'][iSh])
    735                         if Info['Symbol'] not in generalData['AtomTypes']:
    736                             generalData['AtomTypes'].append(Info['Symbol'])
    737                             generalData['Z'] = Info['Z']
    738                             generalData['Isotopes'][Info['Symbol']] = Info['Isotopes']
    739                             generalData['BondRadii'].append(Info['Drad'])
    740                             generalData['AngleRadii'].append(Info['Arad'])
    741                             generalData['vdWRadii'].append(Info['Vdrad'])
    742                             if Info['Symbol'] in generalData['Isotope']:
    743                                 if generalData['Isotope'][Info['Symbol']] not in generalData['Isotopes'][Info['Symbol']]:
    744                                     isotope = list(generalData['Isotopes'][Info['Symbol']].keys())[-1]
    745                                     generalData['Isotope'][Info['Symbol']] = isotope
    746                                 generalData['AtomMass'].append(Info['Isotopes'][generalData['Isotope'][Info['Symbol']]]['Mass'])
    747                             else:
    748                                 generalData['Isotope'][Info['Symbol']] = 'Nat. Abund.'
    749                                 if 'Nat. Abund.' not in generalData['Isotopes'][Info['Symbol']]:
    750                                     isotope = list(generalData['Isotopes'][Info['Symbol']].keys())[-1]
    751                                     generalData['Isotope'][Info['Symbol']] = isotope
    752                                 generalData['AtomMass'].append(Info['Mass'])
    753                             generalData['NoAtoms'][Info['Symbol']] = atom[cx+3]*atom[cs+1]*Srb['Natoms'][iSh]
    754                             generalData['Color'].append(Info['Color'])
     736                    Info = G2elem.GetAtomInfo(Srb['atType'][iSh])
     737                    if Info['Symbol'] not in generalData['AtomTypes']:
     738                        generalData['AtomTypes'].append(Info['Symbol'])
     739                        generalData['Z'] = Info['Z']
     740                        generalData['Isotopes'][Info['Symbol']] = Info['Isotopes']
     741                        generalData['BondRadii'].append(Info['Drad'])
     742                        generalData['AngleRadii'].append(Info['Arad'])
     743                        generalData['vdWRadii'].append(Info['Vdrad'])
     744                        if Info['Symbol'] in generalData['Isotope']:
     745                            if generalData['Isotope'][Info['Symbol']] not in generalData['Isotopes'][Info['Symbol']]:
     746                                isotope = list(generalData['Isotopes'][Info['Symbol']].keys())[-1]
     747                                generalData['Isotope'][Info['Symbol']] = isotope
     748                            generalData['AtomMass'].append(Info['Isotopes'][generalData['Isotope'][Info['Symbol']]]['Mass'])
    755749                        else:
    756                             generalData['NoAtoms'][Info['Symbol']] += atom[cx+3]*atom[cs+1]*Srb['Natoms'][iSh]
    757 #                        break
    758                     # else:
    759                     #     break
     750                            generalData['Isotope'][Info['Symbol']] = 'Nat. Abund.'
     751                            if 'Nat. Abund.' not in generalData['Isotopes'][Info['Symbol']]:
     752                                isotope = list(generalData['Isotopes'][Info['Symbol']].keys())[-1]
     753                                generalData['Isotope'][Info['Symbol']] = isotope
     754                            generalData['AtomMass'].append(Info['Mass'])
     755                        generalData['NoAtoms'][Info['Symbol']] = atom[cx+3]*atom[cs+1]*Srb['Natoms'][iSh]
     756                        generalData['Color'].append(Info['Color'])
     757                    else:
     758                        generalData['NoAtoms'][Info['Symbol']] += atom[cx+3]*atom[cs+1]*Srb['Natoms'][iSh]
    760759           
    761760    if generalData['Type'] == 'magnetic':
  • trunk/GSASIIlattice.py

    r5453 r5460  
    26142614    return Th,Ph
    26152615
     2616def SHarmcal(SytSym,SHFln,psi,gam):
     2617    '''Perform a surface spherical harmonics computation.
     2618    Note that the the number of gam values must either be 1 or must match psi
     2619   
     2620    :param str SytSym: sit symmetry - only looking for cubics
     2621    :param dict SHFln: spherical harmonics coefficients; key has L & M
     2622    :param float/array psi: Azimuthal coordinate 0 <= Th <= 360
     2623    :param float/array gam: Polar coordinate 0<= Ph <= 180
     2624   
     2625    :returns array SHVal: spherical harmonics array for psi,gam values
     2626    '''
     2627    SHVal = np.ones_like(psi)
     2628    for term in SHFln:
     2629        if 'C(' in term[:2]:
     2630            l,m = eval(term.strip('C'))
     2631            if SytSym in ['m3m','m3','43m','432','23']:
     2632                Ksl = CubicSHarm(l,m,psi,gam)
     2633            else:
     2634                p = SHFln[term][2]
     2635                Ksl = SphHarmAng(l,m,p,psi,gam)
     2636            SHVal += SHFln[term][0]*Ksl
     2637    return SHVal
     2638   
    26162639def SphHarmAng(L,M,P,Th,Ph):
    26172640    ''' Compute spherical harmonics values using scipy.special.sph_harm
     
    26292652   
    26302653    if M == 0:
    2631         return np.real(ylmp)/4.
     2654        return np.real(ylmp)/SQ2
    26322655    if P>0:
    26332656        return np.real(ylmp)
     
    28182841    return PolVal
    28192842
    2820 def SHarmcal(SytSym,SHFln,psi,gam):
    2821     '''Perform a surface spherical harmonics computation.
    2822     Note that the the number of gam values must either be 1 or must match psi
    2823    
    2824     :param str SytSym: sit symmetry - only looking for cubics
    2825     :param dict SHFln: spherical harmonics coefficients; key has L & M
    2826     :param float/array psi: Azimuthal coordinate 0 <= Th <= 360
    2827     :param float/array gam: Polar coordinate 0<= Ph <= 180
    2828    
    2829     :returns array SHVal: spherical harmonics array for psi,gam values
    2830     '''
    2831     SHVal = np.ones_like(gam)
    2832     for term in SHFln:
    2833         if 'C(' in term[:2]:
    2834             l,m = eval(term.strip('C'))
    2835             if SytSym in ['m3m','m3','43m','432','23']:
    2836                 Ksl = CubicSHarm(l,m,psi,gam)
    2837             else:
    2838                 p = SHFln[term][2]
    2839                 Ksl = SphHarmAng(l,m,p,psi,gam)
    2840             SHVal += SHFln[term][0]*Ksl
    2841     return SHVal
    2842    
    28432843def invpolfcal(ODFln,SGData,phi,beta):
    28442844    'needs doc string'
  • trunk/GSASIIphsGUI.py

    r5454 r5460  
    1155411554                        data['RBModels']['Spin'][-1][name].append(rbData[name])
    1155511555                    wx.CallAfter(FillRigidBodyGrid,True,spnId=rbId)
    11556                        
    1155711556               
    1155811557            def SHsizer():
  • trunk/GSASIIplot.py

    r5453 r5460  
    97829782
    97839783    def RenderTextureSphere(x,y,z,radius,Qmat,color,shape=[20,10],Fade=None):
    9784         global spID
    97859784        SpFade = np.zeros(list(Fade.shape)+[4,],dtype=np.dtype('B'))
    97869785        SpFade[:,:,:3] = Fade[:,:,nxs]*list(color)
    97879786        SpFade[:,:,3] = 128
    9788         newSP = False
    97899787        spID = GL.glGenTextures(1)
    9790         # if not spID:
    9791         #     spID = GL.glGenTextures(1)
    9792         #     newSP = True
    97939788        GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
    97949789        GL.glEnable(GL.GL_BLEND)
     9790        GL.glFrontFace(GL.GL_CCW)       #shows outside
     9791        GL.glEnable(GL.GL_CULL_FACE)    #removes striping
    97959792        GL.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE_MINUS_SRC_ALPHA)
    97969793        GL.glEnable(GL.GL_TEXTURE_2D)
    97979794        GL.glBindTexture(GL.GL_TEXTURE_2D, spID)
    9798         GL.glFrontFace(GL.GL_CCW)       #shows outside
    9799         GL.glEnable(GL.GL_CULL_FACE)    #removes striping
    98009795        GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE)
    98019796        GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_ALPHA_SCALE, 1.0)
    9802         GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP)
    9803         GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP)
    9804         GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT)
    9805         GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT)
    98069797        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_BASE_LEVEL, 0)
    98079798        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_LEVEL, 0)
     
    98099800        GL.glTexParameter(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR)
    98109801        GL.glTexImage2D(GL.GL_TEXTURE_2D,0,GL.GL_RGBA,shape[0], shape[1],0,GL.GL_RGBA,GL.GL_UNSIGNED_BYTE,SpFade)
    9811         # if newSP:
    9812         #     GL.glTexImage2D(GL.GL_TEXTURE_2D,0,GL.GL_RGBA,shape[0], shape[1],0,GL.GL_RGBA,GL.GL_UNSIGNED_BYTE,SpFade)
    9813         # else:
    9814         #     GL.glTexSubImage2D(GL.GL_TEXTURE_2D,0,0,0,shape[0], shape[1],GL.GL_RGBA,GL.GL_UNSIGNED_BYTE,SpFade)
    98159802        q = GLU.gluNewQuadric()
    98169803        GLU.gluQuadricDrawStyle(q,GLU.GLU_FILL)
     
    1030910296                        QR,R = G2mth.make2Quat(V,np.array([0.,0.,1.0]))
    1031010297                        QA = G2mth.AVdeg2Q(A,np.array([0.,0.,1.0]))
    10311                         Q2 = G2mth.prodQQ(QA,QR)
     10298                        Q2 = G2mth.prodQQ(QA,QR)    #correct - rotates about V axis
    1031210299                        Qmat = G2mth.Q2Mat(Q2)
    10313                         Q4mat = np.concatenate((np.concatenate((Qmat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0)
     10300                        Q4mat = np.eye(4)
     10301                        Q4mat[:3,:3] = Qmat
     10302                        Npsi,Ngam = 120,60
     10303                        PSI,GAM = np.mgrid[0:Npsi,0:Ngam]   #[azm,pol]
     10304                        PSI = PSI.flatten()*360./Npsi  #azimuth 0-360 ncl
     10305                        GAM = GAM.flatten()*180./Ngam  #polar 0-180 incl
    1031410306                        for ish,nSH in enumerate(SpnData['nSH']):
    1031510307                            if nSH > 0:
    1031610308                                SHC = SpnData['SHC'][ish]
    10317                                 PSI,GAM = np.mgrid[0:120,0:60]   #[azm,pol]
    10318                                 PSI = PSI.flatten()*3.  #azimuth 0-360 ncl
    10319                                 GAM = GAM.flatten()*3.  #polar 0-180 incl
    10320                                 P = G2lat.SHarmcal(SytSym,SHC,GAM,PSI).reshape((120,60))
     10309                                P = G2lat.SHarmcal(SytSym,SHC,PSI,GAM).reshape((Npsi,Ngam))
    1032110310                                if np.min(P) < np.max(P):
    1032210311                                    P = (P-np.min(P))/(np.max(P)-np.min(P))
    10323                                 RenderTextureSphere(x,y,z,radius[ish][0],Q4mat,atColor[ish],shape=[120,60],Fade=P)
     10312                                RenderTextureSphere(x,y,z,radius[ish][0],Q4mat,atColor[ish],shape=[Npsi,Ngam],Fade=P.T)
    1032410313                        else:
    1032510314                            RenderSphere(x,y,z,radius[ish][0],atColor[ish],fade,shape=[60,30])
     
    1053510524       
    1053610525    #### PlotStructure starts here
    10537     global mcsaXYZ,mcsaTypes,mcsaBonds,txID,contourSet,spID
     10526    global mcsaXYZ,mcsaTypes,mcsaBonds,txID,contourSet
    1053810527    global cell, Vol, Amat, Bmat, A4mat, B4mat, BondRadii
    1053910528    txID = -1
    10540     spID = 0
    1054110529    ForthirdPI = 4.0*math.pi/3.0
    1054210530    RBId = G2gd.GetGPXtreeItemId(G2frame, G2frame.root, 'Rigid bodies')
  • trunk/GSASIIstrIO.py

    r5443 r5460  
    12971297                Angle = 2.0*acosd(Qrijk[0])
    12981298                pFile.write('\nRBObject %s at %10.4f %10.4f %10.4f Refine? %s\n'%
    1299                     (RB['RBname'],Oxyz[0],Oxyz[1],Oxyz[2],RB['Orig'][1]))
     1299                    (RB['RBname'][0],Oxyz[0],Oxyz[1],Oxyz[2],RB['Orig'][1]))
    13001300                pFile.write('Orientation angle,vector: %10.3f %10.4f %10.4f %10.4f Refine? %s\n'%
    13011301                    (Angle,Qrijk[1],Qrijk[2],Qrijk[3],RB['Orient'][1]))
    1302                 pFile.write('Bessel/Spherical Harmonics coefficients; symmetry required sign shown')
    1303                 SHC = RB['SHC']
    1304                 if len(SHC):
    1305                     SHkeys = list(SHC.keys())
    1306                     nCoeff = len(SHC)
    1307                     nBlock = nCoeff//6+1
    1308                     iBeg = 0
    1309                     iFin = min(iBeg+6,nCoeff)
    1310                     for block in range(nBlock):
    1311                         ptlbls = ' names :'
    1312                         ptstr =  ' values:'
    1313                         ptref =  ' refine:'
    1314                         for item in SHkeys[iBeg:iFin]:
    1315                             ptlbls += '%12s'%(item)
    1316                             ptstr += '%9.4f*%2.0f'%(SHC[item][0],SHC[item][1])
    1317                             ptref += '%12s'%(SHC[item][2])
    1318                         pFile.write(ptlbls+'\n')
    1319                         pFile.write(ptstr+'\n')
    1320                         pFile.write(ptref+'\n')
    1321                         iBeg += 6
     1302                pFile.write('Bessel/Spherical Harmonics coefficients; symmetry required sign shown\n')
     1303                for ish,SHC in enumerate(RB['SHC']):
     1304                    if len(SHC):
     1305                        pFile.write('Spin shell (%s) no: %d\n'%(RB['RBname'][ish],ish))
     1306                        SHkeys = list(SHC.keys())
     1307                        nCoeff = len(SHC)
     1308                        nBlock = nCoeff//6+1
     1309                        iBeg = 0
    13221310                        iFin = min(iBeg+6,nCoeff)
     1311                        for block in range(nBlock):
     1312                            ptlbls = ' names :'
     1313                            ptstr =  ' values:'
     1314                            ptref =  ' refine:'
     1315                            for item in SHkeys[iBeg:iFin]:
     1316                                ptlbls += '%12s'%(item)
     1317                                ptstr += '%9.4f*%2.0f'%(SHC[item][0],SHC[item][1])
     1318                                ptref += '%12s'%(SHC[item][2])
     1319                            pFile.write(ptlbls+'\n')
     1320                            pFile.write(ptstr+'\n')
     1321                            pFile.write(ptref+'\n')
     1322                            iBeg += 6
     1323                            iFin = min(iBeg+6,nCoeff)
    13231324               
    13241325    def PrintAtoms(General,Atoms):
     
    14401441        if 'AtomFrac' not in RB and rbKey != 'S': raise Exception('out of date RB: edit in RB Models')
    14411442        # end patch
    1442         rbid = str(rbids.index(RB['RBId']))
     1443        if rbKey == 'S':
     1444            rbid = str(rbids.index(RB['RBId'][0]))  #for spin RBs
     1445        else:
     1446            rbid = str(rbids.index(RB['RBId'])) #others
    14431447        pfxRB = pfx+'RB'+rbKey+'P'
    14441448        pstr = ['x','y','z']
     
    14851489            name = pfx+'RB'+rbKey+'AtNo:'+str(iRB)+':'+rbid
    14861490            phaseDict[name] = atomIndx[RB['Ids'][0]][1]
    1487             name = pfx+'RB'+rbKey+'AtType:'+str(iRB)+':'+rbid
    1488             phaseDict[name] = RB['atType']
    14891491            name = pfx+'RB'+rbKey+'SytSym:'+str(iRB)+':'+rbid
    14901492            phaseDict[name] = RB['SytSym']
     1493            for ish,atype in enumerate(RB['atType']):
     1494                name = '%sRBSAtType;%d:%d:%s'%(pfx,ish,iRB,rbid)
     1495                phaseDict[name] = RB['atType'][ish]
    14911496                               
    14921497    def MakeRBThermals(rbKey,phaseVary,phaseDict):
     
    15311536               
    15321537    def MakeRBSphHarm(rbKey,phaseVary,phaseDict):
    1533         rbid = str(rbids.index(RB['RBId']))
    1534         pfxRB = pfx+'RB'+rbKey+'Sh;'
    1535         for i,shcof in enumerate(RB['SHC']):
    1536             SHcof = RB['SHC'][shcof]
    1537             name = pfxRB+shcof+':'+str(iRB)+':'+rbid
    1538             phaseDict[name] = SHcof[0]*SHcof[1]
    1539             if SHcof[2]:
    1540                 phaseVary += [name,]
     1538        rbid = str(rbids.index(RB['RBId'][0]))
     1539        for ish,Shcof in enumerate(RB['SHC']):
     1540            pfxRB = '%sRBSSh;%d;'%(pfx,ish)
     1541            for i,shcof in enumerate(Shcof):
     1542                SHcof = Shcof[shcof]
     1543                name = pfxRB+shcof+':'+str(iRB)+':'+rbid
     1544                phaseDict[name] = SHcof[0]*SHcof[1]
     1545                if SHcof[2]:
     1546                    phaseVary += [name,]
    15411547                   
    15421548    if Print and pFile is None: raise Exception("specify pFile or Print=False")
Note: See TracChangeset for help on using the changeset viewer.